Syntax Highlighter does not format XML text

Help 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 a tutorial link

+6
source share
1 answer

If you look at the source, you will notice that you are extracting XML twice, since @ already encodes the text, and @Html.Encode(..) does it again. Therefore, you do not get the correct conclusion that SyntaxHighlighter is undestand as code.

Just try 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> 
0
source

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


All Articles