Can I include a CDATA section in a VS 2010 code snippet?

When using the HTML snippet "script" in VS 2010, I get:

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

I would like the snippet to display the following result:

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

//]]>
</script>

I looked at the .snippet file for this and found the following "Code" element:

    <Code Language="html"><![CDATA[<script type="text/javascript">$selected$$end$</script>]]></Code>

and I realized that it can be a little difficult to make it work, i.e. this does not happen:

<Code Language="html"><![CDATA[<script type="text/javascript">
//<![CDATA[
$selected$$end$
//]]>
</script>]]></Code>

Does anyone know a little more knowledge of XML than I know if this is doable?

+3
source share
3 answers

I found the solution you were looking for in your snippet, just do it.

<Code Language = "html">

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

& ;! [CDATA [
   $ $]] $$ >
</script> ]] >

</ >

+2

w3schools: Nested CDATA sections are not allowed.

.

Edit: xml (snippet), , :

<Code Language="html"><![CDATA[<script type="text/javascript">
    //<![CDATA[
        $selected$$end$
    //]]/>
</script>]]></Code>

( )

:

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

//]]/>
</script>

-, ; , , .

0

CDATA VS, CDATA , . , CDATA .

In your case, the fragment code element should look like this (if you have the $ script $ parameter set):

<Code Language="html">
    &lt;script type=&quot;text/javascript&quot;&gt;
    //&lt;![CDATA[
      $script$
    //]]&gt;
    &lt;/script&gt;
</Code>

This will result in the following result:

<script type="text/javascript">
    //<![CDATA[
        script goes here
    //]]>
</script>
0
source

Source: https://habr.com/ru/post/1780705/


All Articles