SyntaxHighlighter插件代码高亮显示使用方法
方法一:
1. head部分引用
<link type=”text/css” rel=”stylesheet” href=”SyntaxHighlighter/Styles/SyntaxHighlighter.css”>
2. 在网页要显示程序源代码的地方插入以下代码,若是HTML类型的话,用XML(其它的如class="js"表示以js语法显示源代码,其他可设定的 class值分别为c#、css、c、elphi、java、js、php、python、ruby、sql、vb、xml):
<textarea name="code" class="js"rows="15" cols="100">
程序源代码放在这儿
</textarea>
3. 在网页尾部的</body>之前插入
<script class="javascript" src=" SyntaxHighlighter/Scripts/shCore.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushPhp.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushJava.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushVb.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushSql.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushDelphi.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushPython.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushRuby.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushCss.js"></script>
<script class="javascript" src=" SyntaxHighlighter/Scripts/shBrushCpp.js"></script>
<script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
方法二:
1. <link type="text/css" rel="stylesheet" href="SyntaxHighlighter/Styles/SyntaxHighlighter.css"></link>
<script language="javascript" src="SyntaxHighlighter/Scripts/shCore.js"></script>
<script language="javascript" src="SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
<script language="javascript" src="SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<scriptlanguage="javascript">
window.onload = function () {
dp.SyntaxHighlighter.ClipboardSwf = 'SyntaxHighlighter/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
}
</script>
2. 显示代码部分,两种方式
(1) <pre name=”code” class=”c-sharp”>
显示代码部分
</pre>
<textareaname="code" class="c#" cols="60"rows="10">
... 显示代码部分 ...
</textarea>
描述:代码高亮显示插件
附件: SyntaxHighlighter.rar