Action to add "==" around selected text

I use highlights often, and would love to be able to select pre-written text, hit a hotkey, and execute an action that wraps the selected text with == to create the highlight (iA Markdown syntax).

I’ve searched the forum and the action library with no luck. Unless I missed a pre-existing action, is someone able to help me with the code?

Thank you in advance.

1 Like

Try this:

If there’s nothing that covers my need exactly, I’ve found it really useful to look for actions that do something close and then adapt that. In this case, it sounds like what you’re looking for is close to the standard Markdown bold or emphasis actions. I grabbed the Markdown bold action and swapped out the “**” with “==“. This one also allows you to select a previously highlighted phrase and remove the highlight syntax.

1 Like

This is what I use:

Neat! Wouldn’t have thought of doing it like that. Does make me wish i*OS had a clipboard history, though…

1 Like

You could bypass the whole clipboard business in the first script step by just using this Drafts template tag:

{==[[selection_only]]==}

What that doesn’t account for is cursor positioning for no selected text (i.e. placing between the markup), or undoing existing markup. There’s nothing in the Mustache templates to allow for this either from what I could see.

Here’s another take on this. The intention was to make something that was flexible and easy to modify, and I’ve popped it into the directory.

  • Uses three template tags, only one or two of which are enabled at a time.
    • WRAP is the default and defines text to include before AND after any selection.
    • PREFIX is used if WRAP is not defined as a non-empty string (including disabled) as the text to prefix to the selection.
    • SUFFIX is used if WRAP is not defined as a non-empty string (including disabled) as the text to append to the selection.
  • This allows the action to be swapped between ==selection== and {==selection==} formats; and makes it easy to reuse for other markup markers - i.e. you don’t need to mess around with any script steps. You can even have just prefixes or just have suffixes as well as options for matching and mismatching delimiters.
  • If there is a selection, on running, the cursor will be placed after the suffix. If there is no selection, on running, the cursor will be placed after the prefix.
  • If text is selected and it is already marked up, then the markup will be removed and the cursor placed after the selection.
  • If the text plus the markup is selected, then the markup will once again be removed and the cursor will be placed after the now unmarked text.
2 Likes

I’m certain I did what you suggested above - find something similar and swap the desired symbols.

1 Like

Wow, you all are amazing! Many great solutions here, and some good tips for helping me figure out future actions. Thank you!

2 Likes