Sure. Just make sure you encode your string and use it to split the text with a simple replacement.
Sample text:
The quick brown fox jumped over the lazy dog
for this, the actual line will be as follows:
The quick\r\nbrown fox\r\njumped over\r\nthe lazy dog
I think something like this will work (without document.write, and there may be performance improvements):
var input = '\r\nThe quick\r\nbrown fox\r\njumped over\r\nthe lazy dog'; input = input.replace(/\r\n/g, '<div class=\'index\'></div>'); document.write(input); var idx = 0; $('.index').each(function(){ $(this).text(idx++); });
If I am not mistaken, this should write out the index number on each line. I can use some checks / debugs though :)
An example of how this is done, check out the Github diff pages.
source share