XTH – the XHTML to HTML converter for wordpress

Download XTH (v2.01) here

By popular demand here it is – version 2.01 of the original XHTML-to-HTML wordpress plugin. Now called XTH (bit catchier, no?), it is a complete rewrite of the original version and aims to fix the Javascript CDATA and RSS feed issues that the original suffered.

Caveats

OK, this version seems to successfully avoid parsing inline Javascripts and external Javascript libraries. This is necessary because the XHTML closing sequence is a valid pattern in javascript regex, and removing it from those places would mess up those libraries.
The downside to that is that it’s then up to you to make sure that any JS you use doesn’t output any XHTML, as XTH no longer ‘fixes’ it for you.

Same goes for any other external libs that you or your plugins load.

Note that XTH doesn’t address javascript URLs of the form <a href=”javascript:foo()”>. This is for efficiency – and also because I haven’t ever seen a regex used in that context, but who knows, someone might try it. I might add this as an option in a future

Don’t forget!

A single XHTML closer anywhere in the output will fail HTML 4.01 validation Resulting in tag soup and defeating the object of the whole exercise.

XTH also avoids RSS feeds.

Problems, bugs and comments below please. This is a complete rewrite of the plugin so we’re back to square one with the list of problems and required tweaks.

Thanks to all those people who gave feedback and whose time and knowledge helped to make this new version possible.

Updated October 2010

11 Comments  (sorry, comments are closed now)

  1. John Kilroy says:

    Fixed the weird Atom feed error. Bizarrely the conditional WP is_feed() function doesn’t work when tested outside XTH’s main routine. Placed inside it does now work – your Atom feeds are safe once more :)

  2. Steven Vachon says:

    Great work. This plugin will really come in handy for those transitioning to HTML 5. Myself, I’m waiting for it to become a final spec. And when it does and WordPress hasn’t yet caught up, this plugin will become very popular.

  3. Fabio says:

    Thanks for the plugin that makes it easier.

    ObrigadoFabio / Brazil / Sao Paulo.

  4. Jonathan says:

    Awesome plugin; thanks for writing it.

  5. David says:

    This plugin has preserved my sanity. I had 52 errors but now, thanks to XTH, they are gone. Thanks again!

  6. Jacob says:

    Great plugin.. I hate XHTML and that I can’t get my page validated when I use WordPress as CMS.

  7. Jon W says:

    Brilliant, thank you ever so much.

    Just building my new site and, having recently converted from XHTML to HTML 4.01 I was a little dismayed to find WP ruining everything ;)

    Not any more though!

  8. Nate says:

    DLed and installed. Hate XHTML, stoked to use HTML 5.0, now I just need to take the time to make my themes actually validate…. hahah

  9. Daniel B says:

    Great plugin, however I think there may be a bug in the XTH code. On my wordpress site, even in the default theme in the head section, there are 1 line javascript lines like:

    I am very new to PHP but it looks like in your code, it will detect if a line contain and if so safe_to_replace = 0 for that line. ELSEIF it will detect if a script is ending () and set safe_to_replace = 1; (since script has ended).
    BUT, in the case of these 1 line javascript: , it simply sets safe_to_replace = 0 & then DOESNT set it back to =1, since it wont detects as it has already matched on that line (Elseif was used) and then every line afterwards will still have safe_to_replace = 0 and wont do any replacement.

    Hope I explained that OK – I could be wrong (very new to PHP lol) but I noticed none of the /> lines in my code were being replaced after lines and that looked like the problem to be when I checked.

    - Dan.

  10. Andrew says:

    Thanks. Why don’t you add this nice plugin to wp plugin repository?

  11. Jordan says:

    This could be so useful! Thanks so much. Wondering if I could use this with HTML5