Drafts Action Directory

Markdown Quotation (>)

Posted by agiletortoise, Last update about 1 year ago

Apply Markdown Quote (“> “) at beginning of selected lines.

Install

Steps

  • script

    // make selected lines into Markdown quotation
    
    // grab values
    var lnRange = editor.getSelectedLineRange();
    var lnText = editor.getTextInRange(lnRange[0], lnRange[1]);
    var selRange = editor.getSelectedRange();
    
    // setup vars
    var lines = lnText.split("\n");
    var quoteString = "> ";
    var isFirst = true;
    var newLines = [];
    var startAdjust = 0;
    var lengthAdjust = 0;
    
    // loop over lines
    for (var ix=0; ix<lines.length; ix++) {
      var line = lines[ix];
      if (line.startsWith(quoteString)) {
         newLines.push(quoteString + line);
         if (isFirst) {
           startAdjust += quoteString.length;
         }
         else {
           lengthAdjust += quoteString.length;
         }
      }
      else {
        newLines.push(quoteString + line);
        if (isFirst) {
          startAdjust += quoteString.length;
        }
        else {
          lengthAdjust += quoteString.length;
        }
      }
      isFirst = false;
    }
    
    // update text 
    editor.setTextInRange(lnRange[0], lnRange[1], newLines.join("\n"));
    
    // update selection
    editor.setSelectedRange(selRange[0] + startAdjust, selRange[1] + lengthAdjust);
    

Options

  • After Success Nothing
    Notification Error
    Log Level Error

Comments

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