Drafts Action Directory

Markdown Header (#)

Posted by agiletortoise, Last updated: 2018-07-03 17:15:53 UTC

Add “#” at beginning of line to create Markdown header.

Install

Steps

  • script

    // Apply Markdown Header to current line
    
    var lnRange = editor.getSelectedLineRange();
    var ln = editor.getTextInRange(lnRange[0],lnRange[1]);
    var selRange = editor.getSelectedRange();
    
    var prefix = "#";
    if (ln.length == 0 || (ln && ln[0] != " " && ln[0] != "#")) {
      prefix = "# ";
    }
    
    editor.setTextInRange(lnRange[0],lnRange[1],prefix+ln);
    editor.setSelectedRange(selRange[0]+prefix.length,selRange[1]);
    

Comments

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