Over a million developers have joined DZone.

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:

s = 'blabla
'; prompt("", toStandard(s));
code: //+ Jonas Raoni Soares Silva //@ http://jsfromhell.com function toStandard(s){ return s.replace(/<(\/?\w+)([^>]*)>/g, function(s, t, c, d){ return "<" + t.toLowerCase() + c.replace(/\b(\w+)(?:=((?:(?=(["'])).((?!\3)(?:.|\n))*\3)|\S*))?/g, function(s, p, v, a){ return (p = p.toLowerCase()) + "=" + (a = a ? "" : '"') + (v || p) + a; }) + ">"; }); };
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}