Toggle Bold / Italic / Etc?

On IOS whenever I hit command B or use the bold button on the toolbar it puts two asterisks around my text, which is to be expected and what I want. However, when I want to make that text plain / un-bold again, when I hit the bold key it adds two more asterisks around the word, rather than clearing the word of the asterisks. The same is true for italicized text. Is there a way I can fix this with a new action? Thanks.

It is certainly possible to create an action, but the existing actions are all focussed on adding/inserting Markdown - for the two examples you gave; there are Markdown list actions that do toggle the markup on and off.

The principle is certainly straight forward enough to build such a reversal action, but you would need to define and build some logic into it for a variety fo circumstances.

For example, let’s say I have text containing some bold markers like this:

a **b c** d

Those characters would have a horizontal indicies as follows

1 2 3 4 5 6 7 8 9 10 11
a * * b c * * d

If the highlighted selection is 5 to 7, or 3 to 9, I imagine you would want to remove characters 3, 4, 8, and 9.

But, there are a number of other circumstances where I would argue that the desired behaviour is less clear. What should happen in the following circumstances?

  • The selection is 1 to 11.
  • The selection is 3 to 7.
  • The selection is 4 to 6.
  • The selection is of zero length and after character 3.
  • The selection is of zero length and after character 4.
  • The selection is of zero length and after character 5.
  • The selection is of zero length and after character 6.
  • The selection is of zero length and after character 7.

I imagine that in most cases that reproducing the effects seen in a rich text/WYSIWYG editor might be a good starting point, but even then, those behaviours might not match what you would want in a non-rich editor like Drafts.

Please note, I am not suggesting that you provide answers here to the questions above. I’m just highlighting the sorts of things you would need to consider as the removal of the markup is potentially much more involved than wrapping and replacing an existing selection - as is the algorithm for the insertion.

Hope that helps.

Thanks for this. What if to keep it simple, there’s an action that removes all formatting markup from selected text? Does that exist?

If you were going to deal with all Markdown individually, then that would be even more complicated. However, there is a trick that can be used. In fact it’s one I’ve used before that involves the system clipboard.

Last year I posted an action in this thread that worked for an entire draft.

Here’s an enhanced version that I think works for the entire draft, or just a text selection when there is one.

It creates a draft version each time it is run, so you should not lose any content - but, please do reassure yourself on this. Give it a try, and let us know if that gives you a workable solution.

That works thanks. One question: I also use {== and ==} to highlight text. How do I add that to your script? I am clueless about scripts

That’s critic markup.

I have now added a setting to account for that.

Download the action again to get the updateand give it a try.

That works perfectly thank you.