Bookmarklet to wrap the ill-formatted mails in W3C mailing list archives

Hi,

I've just finished writing a bookmarklet that allows to wrap the content
of the <pre> elements in a Weg page, effectively allowing to wrap for
instance ill-formatted emails in the mailing lists archives (of W3C, but
others too probably). The code is as follows:
javascript:max_width=80; function add_newline(node,chars) { if (node.nodeType==node.ELEMENT_NODE) { cursor = chars ; for (i=0 ; i < node.childNodes.length; i++) { if (node.childNodes[i].nodeType==node.TEXT_NODE) { cursor = add_newline(node.childNodes[i],cursor) ; } } return cursor ; } else if (node.nodeType==node.TEXT_NODE) { text = node.data; text_new=''; cursor = chars; while (text.length > (max_width - cursor)) { if (text.indexOf('\n') <= (max_width - cursor) && text.indexOf('\n') >= 0) { cut = text.indexOf('\n'); } else { cut = text.substr(0,max_width-cursor).lastIndexOf(' '); } if (cut==-1) { cut = max_width - cursor ; } text_new += text.substr(0,cut) + '\n'; cursor = 0; text = text.substr(cut+1); } text_new += text; node.data = text_new; return (text.length); } else { return chars ; } } add_newline(document.getElementsByTagName('pre')[0],0)

It could probably be shorted to become usable in IE, but it works as is
in Mozilla an derivative... You can test it for instance on the
following archived message:
http://lists.w3.org/Archives/Public/www-tag/2003Dec/0124.html

Dom
-- 
Dominique Hazaël-Massieux - http://www.w3.org/People/Dom/
W3C/ERCIM
mailto:dom@w3.org

Received on Monday, 8 December 2003 12:09:38 UTC