Skip to content

Instantly share code, notes, and snippets.

@cbarraco
Last active September 9, 2016 21:20
Show Gist options
  • Save cbarraco/6237762bfb6cdfc8b69b5b23edec8881 to your computer and use it in GitHub Desktop.
Save cbarraco/6237762bfb6cdfc8b69b5b23edec8881 to your computer and use it in GitHub Desktop.
Adds line numbers to code on stackoverflow.com
var code_blocks = $("pre > code");
code_blocks.prepend("1\t");
for (var b = 0; b < code_blocks.length;b++) {
var newlines = $(code_blocks[b]).find("span.pln");
var c = 1;
for (var i=0;i < newlines.length;i++) {
newlines[i].innerHTML = newlines[i].innerHTML.replace(/(?:\r\n|\r|\n)/g, function(x) {
return "\n" + ++c + "\t";
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment