W3C home > Mailing lists > Public > www-archive@w3.org > December 2003

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

From: Dominique HazaŽl-Massieux <dom@w3.org>
Date: 08 Dec 2003 18:08:52 +0100
To: www-archive@w3.org
Message-Id: <1070903333.2414.661.camel@stratustier>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 7 November 2012 14:17:37 GMT