Skip to content

Instantly share code, notes, and snippets.

@rmarscher
Created February 22, 2012 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmarscher/1886489 to your computer and use it in GitHub Desktop.
Save rmarscher/1886489 to your computer and use it in GitHub Desktop.
Bookmarklet for Markdown Code Indenting
(function(){var a=document.activeElement,b=document.getSelection().toString(),c="",d=b.split("\n");indent=" ",i=0,total=d.length;if(b==""){return}for(i=0;i<total;i++){c+=indent+d[i]+"\n"}a.value=a.value.split(b).join(c)}())
(function() {
var el = document.activeElement,
selection = document.getSelection().toString(),
result = "",
lines = selection.split("\n");
indent = " ",
i = 0, total = lines.length;
if (selection == "") {
return;
}
for (i = 0; i < total; i++) {
result += indent + lines[i] + "\n";
}
el.value = el.value.split(selection).join(result);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment