May 16, 2012

txt to html v7

Here's the latest version of the JavaScript bookmarklet I wrote that changes an unformatted, unwordwrapped page into an html page with word wrap. (For better ways to deal with word wrap, see my old post word wrap for Firefox bookmarklet, which I just updated because I noticed it was getting traffic for that.)

txt to html v7

javascript:{var%20x;x=document.body.innerHTML;if(x.substr(0,5)+x.substr(x.length-6,6)=='<pre></pre>'){document.write('<HTML><BODY>\n');x=x.substr(5,x.length-11);var%20textline=x.split('\n'),c;for(c=0;c<textline.length;c++){document.write(textline[c]+'<br>\n');}document.write('</BODY></HTML>');document.close();}}

It's hardly different from txt to html v6. It's still non-standard and not the right way to do it. But it's funny that a program that short that runs from a bookmark can seem to do the work of an HTML editor, turning a plain text file into a local webpage.