Action

Markdown Bold (**) [no selection]

Posted by @MyGeekDaddy, Last update over 1 year ago

UPDATES

over 1 year ago

2022-10-07: Fixed formatting of action description.

Update to @agiletortoise original Markdown Bold (**) action. Actio will apply Markdown bold (**) around selection, or insert ** on both ends of an entire line if no selection is made.

Steps

  • script

    // Apply Markdown bold to selection 
    // OR 
    // insert ** on both ends of a line  if no selection is made
    // Original by @Agiletortoise
    // Update by @MyGeekDaddy
    // Rev Date: 2022-10-07
    
    const markup = "**";
    const sel = editor.getSelectedText();
    const [st, len] = editor.getSelectedRange();
    const [start, end] = editor.getLineRange();
    
    if (!sel || sel.length == 0) {
       
       var [lnStart, lnLen] = editor.getSelectedLineRange();
       var lnText = editor.getTextInRange(lnStart, lnLen);
       // scrub the invisible newline character from the text selection
       lnText = lnText.replace(/\n$/, "");
       lnLen = lnText.length
       editor.setTextInRange(lnStart, lnLen, markup + lnText+ markup);
    }
    else {
      editor.setSelectedText(markup + sel + markup);
      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.