Markdown Fenced Code Block

Posted by toniwonkanobi, Last update almost 6 years ago

This Action wraps selected text in Markdown fenced code blocks (“`).

If there is no selected text, it creates the fenced code block and inserts the cursor in the middle of the blocks—ready for preformatted text entry.


  • script

    // Apply Markdown fenced code block to selection, or insert ``` if no selection
    var sel = editor.getSelectedText();
    var selRange = editor.getSelectedRange();
    if (!sel || sel.length == 0) {
      // Two ticks because [read next comment]
      editor.setSelectedText("```" + "\n" + "\n" + "```");
      // ... this will position the cursor in betweetn the two tick marks
    else {
      editor.setSelectedText("```" + "\n" + sel + "\n" + "```");
      editor.setSelectedRange(selRange[0] + 4,0);


  • After Success Default
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.