[Typo3-dev] fyi: script and style tags for html and xhtml

Martin Kutschker Martin.T.Kutschker at blackbox.net
Mon Dec 8 12:06:10 CET 2003


Hi!

I didn't know that it was possible at all, but you can use a syntax that allows the same content used in a html *and* a xhtml context:

<script> and <style> elements in XHTML sent as text/html have to be
escaped using ridiculously complicated strings.

This is because in XHTML, <script> and <style> elements are #PCDATA
blocks, not #CDATA blocks, and therefore <!-- and --> really _are_
comments tags, and are not ignored by the XHTML parser. To escape
script in an XHTML document which may be handled as either HTML4 or
XHTML, you have to use:

<script type="text/javascript"><!--/*--><![CDATA[//><!--
...
//--><!]]></script>

To embed CSS in an XHTML document which may be handled as either
HTML4 or XHTML, you have to use:

<style type="text/css"><!--/*--><![CDATA[/*><!--*/
...
/*]]>*/--></style>

Yes, it's pretty ridiculous. If documents _aren't_ escaped like
this, then the contents of <script> and <style> elements get
dropped on the floor when parsed as true XHTML.

I've found thie here http://www.hixie.ch/advocacy/xhtml.

What's this about? Well, if you do like this in xthml

<style><!--
...
--></style>

then the xml processor will treat your style as comment. OTOH

<style><![CDATA[
...
]]></style>

doesn't look too good in a html context.

As an alternative code creating output must know in advance if they are in an HTML/SGML or an XHTML context (global flag?) to create the proper code.

Interestingly there is also a problem with the endig / for non-netsting tags. If found it there http://www.hixie.ch/advocacy/xhtml and it is probably true since HTML is a SGML application. OTOH, I have never seen a browser treating HTML correctly, as a SGML. So no real problem.

The "/>" empty tag syntax actually has totally different meaning in
HTML4. (It's the SHORTTAG minimisation feature known as NET, if I
recall the name correctly.) Specifically, the XHTML

<p> Hello <br /> World </p>

...is, if interpreted as HTML4, exactly equivalent to:

<p> Hello <br>&gt; World </p>

...and should really be rendered as:

Hello
> World

IMHO this can be ignored.

Masi 





More information about the TYPO3-dev mailing list