Drafts Action Directory

Markdown Code

Posted by toniwonkanobi, Last updated: 2018-07-04 02:13:41 UTC

This is a modified version of someone else’s code syntax. This Action creates the Markdown code ticks around selected text, or, if there is no selected text, it creates two tick marks with the cursor in between them.

Install

Steps

  • script

    // Apply Markdown code to selection, or insert ` if no selection
    
    var sel = editor.getSelectedText();
    var selRange = editor.getSelectedRange();
    
    if (!sel || sel.length == 0) {
      // editor.setSelectedText("`");
      // Let's try putting two ticks
      editor.setSelectedText("``");
      // editor.setSelectedRange(selRange[0]+1,0);
      // Let's try making the cursor be in the middle of the two tick marks
      editor.setSelectedRange(selRange[0]+1,0)
    }
    else {
      editor.setSelectedText("`"+sel+"`");
      editor.setSelectedRange(selRange[0]+selRange[1]+2,0);
    }

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.