∀ ≣
Convert selection or whole draft to an ordered list

Script key: Convert selection or whole draft to an ordered list

Posted by scutifer

Install

Details

Label ∀ ≣
Voice Over Convert selection or whole draft to an ordered list
Script
var isSelectionEmpty = getSelectedText() == "";
var draft = isSelectionEmpty ? getText() : getSelectedText();
var removeStarIndex = function(line) { return line.replace(/\**/,'').trim(); }
var removeNumIndex = function(line) { return line.replace(/[0-9]*\.?/,'').trim(); }
var newText = draft.split('\n')
     .map(function(x,i) { return (i + 1) + ". " + removeStarIndex(removeNumIndex(x)); })
     .join('\n');

if(isSelectionEmpty)
    setText(newText);
else
    setSelectedText(newText);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus