当前位置: 代码迷 >> Web前端 >> SyntaxHighlighter插件代码高亮展示使用方法
  详细解决方案

SyntaxHighlighter插件代码高亮展示使用方法

热度:285   发布时间:2013-02-24 17:58:56.0
SyntaxHighlighter插件代码高亮显示使用方法
使用领域:
此插件会对做个人技术博客之类的开发者有用处哦~

它可以在网页中对各种程序源代码语法进行加亮显示。支持当前流行的各种编程语言:C#、CSS、C++、Delphi、Java、JavaScript、PHP、Python、Ruby、SQL、Visual Basic、XML / HTML
下载地址:
http://www.dreamprojections.com/syntaxhighlighter/

http://code.google.com/p/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