Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxHighlighter does not format xml text

Reference files:

<script src="../../Content/dp.SyntaxHighlighter/Scripts/shCore.js" type="text/javascript"></script>
<script src="../../Content/dp.SyntaxHighlighter/Scripts/shBrushXml.js" type="text/javascript"></script>
<link href="../../Content/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" rel="stylesheet" type="text/css" />

html Code:

<pre class="brush:xml;">
@Html.Encode("<?xml version='1.0'?><response value='ok' xml:lang='en'>  <text>Ok</text>  <comment html_allowed='true'/>  <ns1:description>  descriptin.  </ns1:description>  <a></a> <a/></response>")
</pre>

JavaScript Code:

<script type="text/javascript">
    SyntaxHighlighter.all()
</script

here is got reference tutorial

like image 820
Xulfee Avatar asked Aug 05 '11 05:08

Xulfee


1 Answers

If you take a look at the source you'll notice that you're excaping the XML two times since @ already encodes the text while @Html.Encode(..) does it again. Therefore you're not getting correct output that SyntaxHighlighter undestand as code.

Just test using this example and everything will work fine:

<!DOCTYPE html>
<html>
    <head>
        <link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" 
            rel="stylesheet" type="text/css" />
        <link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"
            rel="stylesheet" type="text/css" />
    </head>
    <body>
        @{
            var xml = @"
                <?xml version='1.0'?>
                <response value='ok' xml:lang='en'>
                    <text>Ok</text>
                    <comment html_allowed='true'/>
                    <ns1:description>  descriptin.  </ns1:description>
                    <a></a>
                    <a/>
                </response>";
        }
        <pre class="brush: xml">
        @xml
        </pre>

        <script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"
            type="text/javascript"></script>
        <script src="http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js"
            type="text/javascript"></script>
        <script type="text/javascript">
            SyntaxHighlighter.autoloader(
                    'xml xhtml xslt html            http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js'
                );
            SyntaxHighlighter.all();
        </script>
    </body>
</html>
like image 170
Maksymilian Majer Avatar answered Oct 05 '22 21:10

Maksymilian Majer