Action

Obsidian Markdown Comments

Posted by pseudometa, Last update 3 months ago

Apply Obsidian-Markdown comments (%% %%) around selection, or insert %%%% if there is no selection.

Steps

  • script

    const markup = "%%";
    
    const sel = editor.getSelectedText();
    const [st, len] = editor.getSelectedRange();
    
    if (!sel || sel.length == 0) {
      editor.setSelectedText(markup + markup);
      editor.setSelectedRange(st + markup.length,0);
    }
    else {
    	//fixes Markdown issue with lists 
      markupText = markup + sel + markup;
      markupText  = markupText.replaceAll (markup + "- ","- " + markup);   
      
      editor.setSelectedText(markupText);
      editor.setSelectedRange(st + len + (markup.length*2),0);
    }
    

Options

  • 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.