开发者

InlineScript helper does not always embed scripts in CDATA

开发者 https://www.devze.com 2023-02-21 01:02 出处:网络
I have found out that:开发者_Go百科 $actionController->view->inlineScript()->appendScript(\"\\n\".\'// script here\'.\"\\n\");

I have found out that:

开发者_Go百科
$actionController->view->inlineScript()->appendScript("\n".'// script here'."\n");

Will not always embed the script in CDATA.

With an XHTML doctype you will get this output:

<script type="text/javascript">
    //<![CDATA[

// script here

    //]]>
</script>

With a HTML doctype you will get:

<script type="text/javascript">
    //<!--

// script here

    //-->
</script>

Is that actually correct? Shouldn't CDATA be used also in HTML?


Shouldn't CDATA be used also in HTML?

I was about to answer with a big fat "No!" ... but I'd have been wrong.

HTML 4 is actually an SGML "application" (think "dialect"). SGML is the predecessor to XML. SGML does have the <![CDATA[ ... ]]> "marked section", but things get a little complex when you try and define what it actually means.

HTML 5 keeps the CDATA section syntax. This surprised me a bit, as they'd gone out of their way to divorce the HTML syntax from SGML. HTML 5 can be represented either as it's own markup, or as XML.

Now, all of this being said, you totally don't need to use CDATA sections in regular HTML documents, while you'll find yourself open to parse errors if you forget it in an XML document.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号