Last active
September 9, 2016 21:20
-
-
Save cbarraco/6237762bfb6cdfc8b69b5b23edec8881 to your computer and use it in GitHub Desktop.
Adds line numbers to code on stackoverflow.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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