-‸
Markdown Bullet Point (also working on an empty line)

Script key: Markdown Bullet Point (also working on an empty line)

Posted by @sky_y

Install

Details

Label -‸
Voice Over Markdown Bullet Point (also working on an empty line)
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;
    }
  } else {
    var prefix = "- ";
    lines[ix] = prefix;
    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