Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Jonas Raoni Soares Silva http://jsfromhell.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

toStandard //JavaScript Function

This function tries to parse bad html and transform into xhtml, by lower-casing the tags, properties and duplicating single properties (readonly becomes readonly="readonly"), my function is very generic.

example:
   1  
   2  s = '<INPUT type=text value="a b c" readonly x="123">blabla<DIV></DIV>';
   3  prompt("", toStandard(s));


code:
   1  
   2  //+ Jonas Raoni Soares Silva
   3  //@ http://jsfromhell.com
   4  
   5  function toStandard(s){
   6  	return s.replace(/<(\/?\w+)([^>]*)>/g, function(s, t, c, d){
   7  		return "<" + t.toLowerCase() + c.replace(/\b(\w+)(?:=((?:(?=(["'])).((?!\3)(?:.|\n))*\3)|\S*))?/g, function(s, p, v, a){
   8  			return (p = p.toLowerCase()) + "=" + (a = a ? "" : '"') + (v || p) + a;
   9  		}) + ">";
  10  	});
  11  };
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS