Action

Markdown Quote

Posted by drdrang, Last update almost 4 years ago - Unlisted

Format the selected lines as a Markdown quote. If no lines are selected, format the entire draft that way.

Steps

  • script

    // Add Markdown blockquote formatting to the
    // selected lines (or all lines).
    
    // Define the text that's going to be edited.
    var [oldStart, oldLen] = editor.getSelectedRange();
    if (oldLen == 0) { // use full draft
    	var [start, len] = [0, editor.getText().length];
    }
    else {
    	var [start, len] = editor.getSelectedLineRange();
    }
    var lineText = editor.getTextInRange(start, len);
    if (lineText.endsWith("\n")) { // trailing LF doesn't count
    	lineText = lineText.slice(0, -1);
    	len -= 1;
    }
    
    // Split into lines and add the quotation formatting.
    var lines = lineText.split('\n');
    lines.forEach((line, i) => lines[i] = "> " + line);
    	
    // Replace the text in the editor and select it.
    var replacement = lines.join('\n')
    editor.setTextInRange(start, len, replacement);
    editor.setSelectedRange(start, replacement.length);
    editor.activate();
    

Options

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