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

Re: 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:18:04 +0100
To: www-archive@w3.org
Message-Id: <1070903885.2091.675.camel@stratustier>
Le lun 08/12/2003 ŗ 18:08, Dominique HazaŽl-Massieux a ťcrit :
> 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)

And with the proper bookmarklet wrapping:
(function(){ 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) })()

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

Received on Monday, 8 December 2003 12:21:17 GMT

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