Novemberborn, Straight lines circle sometime

TextPattern and HTML 4.01

Because James Bennett bugged me about using TextPattern to output HTML 4.01 code, here’s how I did it.

First of all, make sure the pages and forms use valid HTML 4.01 markup. Then add the following code to publish.php:

$html = preg_replace("/<(.+)\s?\/>/", "<$1>", $html);

after this line:

$html = ($prefs['allow_page_php_scripting']) ? evalString($html) : $html;

This will change all occurences of <tag/> and <tag /> to <tag>. Note that it does not replace any namespaced attributes or other XHTML specific stuff, but to my knowledge TextPattern does not use this anyway.

As for my reasoning, as I wrote before:

(…) for compatibility, XHTML needs to be sent as HTML. Which means browsers see it as invalid HTML, no matter how valid the XHTML is. Furthermore, you can write just as clean code in HTML as in XHTML, so I don’t see a reason to use XHTML.

link | textpattern | 13 November 2005, 21:55


Comments

  1. While I do “get” the whole “what’s wrong with pain old HTML 4.01?” argument, I don’t quite understand why you would want to add code to back-hack the valid XHTML code that Textpattern delivers. XHTML 1.0 transitional is “allowed” to be served as text/html (although Strict is not, according to my understanding), so there isn’t a problem there.

    Why not keep your legacy stuff valid HTML 4.01, and just let your code generator (Textpattern) do what it wants to do, and spit out valid XHTML for the newer stuff?

    From my outside perspective, it seems like a solution in search of a problem. Could you give me more insight as to why you’d want to go this route, rather than leaving the Textpattern output “stock”?

    Thanks!

    CM Harrington | 16 November 2005, 21:02 | link

  2. I don’t like the idea of sending out XHTML, but having it treated as if it’s invalid HTML (because of the content type). I don’t quite see the point in that, which is why I choose to send out valid HTML. Whether TextPattern produces valid XHTML or not is not the point: it’s about how the user agent treats my documents.

    Also, since TextPatterns XHTML generation is still string-based, there is no 100% guarantee that the produced XHTML is indeed valid XHTML.

    This whole discussion is pretty moot though: I’d like to see more clean and semantic code out there, in the end, that’s what matters most.

    Mark Wubben | 16 November 2005, 22:01 | link

  3. @Cm Harrington: putting newer stuff on an older doctype is very abd for accesibility, you dont add new technology to old things it wont work it’s unsupported, and browser will render everything incorrectly.

    Fabian | 5 December 2005, 12:21 | link


Novemberborn: Extra

About the author

Mark Wubben is a European Dutchman and web hacker, based in Copenhagen, Denmark. Supercollider is Mark's freelance alter-ego.

Read more about Mark...

Go to

Jobs (NL)

Xopus zoekt programmeurs! Verbeter de code en win!

Subscribe