Over a million developers have joined DZone.

ToStandard //JavaScript Function

DZone's Guide to

ToStandard //JavaScript Function

Free Resource
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.


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; }) + ">"; }); };

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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


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

{{ parent.tldr }}

{{ parent.urlSource.name }}