Skip to content

Instantly share code, notes, and snippets.

@mattcassinelli
Created October 27, 2014 00:35
Show Gist options
  • Save mattcassinelli/8c88561e7b7ab46d14cf to your computer and use it in GitHub Desktop.
Save mattcassinelli/8c88561e7b7ab46d14cf to your computer and use it in GitHub Desktop.
Re-number a list in Drafts 4
function renumber(s) {
var rgx=/^\d+\. /m,
list=s.split(rgx),
count;
list.shift();
count = list.length;
for(var i=0; i<count; i++) {
list[i] = (i+1).toString() + '. ' + list[i];
}
return list.join('');
}
var rngLines = getSelectedLineRange(),
iFrom=rngLines[0],
iTo=rngLines[1];
setTextInRange(iFrom, iTo, renumber(getTextInRange(iFrom, iTo)));
@mattcassinelli
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment