本文介绍了SyntaxHighlighter - 调用SyntaxHighlighter.all()以突出显示动态生成的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有生成XML的javascript代码,并调用
解决方案是使用 highlight()而不是 all()。
这里有一个JSFiddle,note使用外部资源:
I have javascript code that generates XML, and calls the SyntaxHighlighter.all() method to highlight the added XML. I do not receive errors in the console but neither does highlighting take place.
javascript:
<script type="text/javascript" src="js/syntaxhighlighter_3.0.83/scripts/shCore.js"></script> <script type="text/javascript" src="js/syntaxhighlighter_3.0.83/scripts/shBrushXml.js"></script> <link type="text/css" rel="stylesheet" href="js/syntaxhighlighter_3.0.83/styles/shCoreDefault.css" <script> function generateXML() { var result="<test>WHATEVA</test>"; alert(result); var regex1 = new RegExp('<', 'g'); var regex2 = new RegExp('>', 'g'); result = "<pre class='brush: xml'>" + result.replace(regex1,'<').replace(regex2,'>')+"</pre>"; document.getElementById("generatedXML").innerHTML = result; } </script>
HTML
<input id="addOUTPUTButton" type="button" value="Generate XML" onclick="generateXML()"/> <input id="test" type="button" value="Test" onclick="SyntaxHighlighter.all();"/> <div id="generatedXML"> </div>
解决方案
The solution is to use highlight() instead of all().
Here is a JSFiddle, note that external resources are used: http://jsfiddle.net/menelaosbgr/TXzZH/
这篇关于SyntaxHighlighter - 调用SyntaxHighlighter.all()以突出显示动态生成的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!