0

Is there any open source library that can turn malform HTML into well formatted (not just pretty printed) HTML , like what firebug does?

For example,

<tr class=row><td>content</tr>

may become

<tr class="row"><td>content</td></tr>
powerboy
  • 10,523
  • 20
  • 63
  • 93
  • In which language do you want this lib ? From where do you want to call ? Is this could answer some part of your question : http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php ? – JMax Jun 20 '11 at 07:36
  • Do you actually want to create valid HTML from a malformed file or just view the source in a more beautified manner? – Scott Jun 20 '11 at 07:41

1 Answers1

0

You can't use javascript to fix a broken DOM, because javascript is dependant on the DOM being valid in the first place. You really need to be looking into the server-side portion of your system instead, if that's outputting invalid HTML then that's the part of the system you need to fix.

If you actually mean that you want your markup to be pretty-printed, and assuming you're using PHP, you could install the Tidy extension (http://php.net/manual/en/book.tidy.php). If you can't or don't want to install extensions, or aren't running PHP but are using a scripting language that can run shell commands, then you could use an external shell command such as htmltidy (http://en.wikipedia.org/wiki/HTML_Tidy)

GordonM
  • 31,179
  • 15
  • 87
  • 129
  • So what technology does firebug use to fix HTML? Not javascript? – powerboy Jun 20 '11 at 08:42
  • I don't know the details of FireBug's inner workings, so I couldn't comment. Extensions can be written in JS, but they can also be written in other languages such as C – GordonM Jun 20 '11 at 08:53
  • Looks like PHP has the best implementation of HTML tidy library. Couldn't find a good Java implementation. – powerboy Jun 20 '11 at 09:10