✪ ≣
Markdown list

Script key: Markdown list

Posted by agiletortoise

Install

Details

Label ✪ ≣
Voice Over Markdown list
Script
// Markdown list to current line

var lnRange = getSelectedLineRange();
var ln = getTextInRange(lnRange[0],lnRange[1]);
var selRange = getSelectedRange();

var lines = ln.split('\n');
var charsAdded = 0;

for (var ix=0; ix < lines.length; ix++) {
  if (lines[ix].length > 0) {
    if (lines[ix][0] != "*") {
     var prefix = "*";
      if (lines[ix][0] != " ") {
        prefix = "* ";
      }
      lines[ix] = prefix + lines[ix];
      charsAdded = charsAdded + prefix.length;
    }
  }
}

setTextInRange(lnRange[0],lnRange[1],lines.join("\n"));
if (lines.length > 2) {
  setSelectedRange(lnRange[0]+lnRange[1]+charsAdded, 0);
}
else {
  setSelectedRange(selRange[0]+charsAdded,selRange[1]);
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus