使用SyntaxHighlighter实现HTML高亮显示代码的方法
人气:0
https://m.qb5200.com/www.qb5200.com/jiaoben/15599.html
syntaxhighlighter是一个小开源项目,它可以在网页中对各种程序源代码语法进行加亮显示。支持当前流行的各种编程语言:
C#、CSS、C++、Delphi、Java、JavaScript、PHP、Python、Ruby、SQL、Visual Basic、XML / HTML
使用方法:
1、假设网页文件test.htm存放在一个目录,则将dp.SyntaxHighlighter解压缩到该目录下的子目录,假设为images
2、在网页的<head></head>之间插入以下代码:
<link type="text/css" rel="stylesheet" href="images/Styles/SyntaxHighlighter.css"></link>
3、在网页要显示程序源代码的地方插入以下代码(其中的class="js"表示以js语法显示源代码,其他可设定的class值分别为
c#、css、c、delphi、java、js、php、python、ruby、sql、vb、xml):
<textarea name="code" class="js" rows="15" cols="100">
//程序源代码放在这儿
</textarea>
4、在网页尾部的</body>之前插入以下代码:
<script class="javascript" src="images/Scripts/shCore.js"></script>
<script class="javascript" src="images/Scripts/shBrushCSharp.js"></script>
<script class="javascript" src="images/Scripts/shBrushPhp.js"></script>
<script class="javascript" src="images/Scripts/shBrushJScript.js"></script>
<script class="javascript" src="images/Scripts/shBrushJava.js"></script>
<script class="javascript" src="images/Scripts/shBrushVb.js"></script>
<script class="javascript" src="images/Scripts/shBrushSql.js"></script>
<script class="javascript" src="images/Scripts/shBrushXml.js"></script>
<script class="javascript" src="images/Scripts/shBrushDelphi.js"></script>
<script class="javascript" src="images/Scripts/shBrushPython.js"></script>
<script class="javascript" src="images/Scripts/shBrushRuby.js"></script>
<script class="javascript" src="images/Scripts/shBrushCss.js"></script>
<script class="javascript" src="images/Scripts/shBrushCpp.js"></script>
<script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
syntaxhighlighter是一个小开源项目,它可以在网页中对各种程序源代码语法进行加亮显示。支持当前流行的各种编程语言:
C#、CSS、C++、Delphi、Java、JavaScript、PHP、Python、Ruby、SQL、Visual Basic、XML / HTML
使用方法:
1、假设网页文件test.htm存放在一个目录,则将dp.SyntaxHighlighter解压缩到该目录下的子目录,假设为images
2、在网页的<head></head>之间插入以下代码:
复制代码 代码如下:
<link type="text/css" rel="stylesheet" href="images/Styles/SyntaxHighlighter.css"></link>
3、在网页要显示程序源代码的地方插入以下代码(其中的class="js"表示以js语法显示源代码,其他可设定的class值分别为
c#、css、c、delphi、java、js、php、python、ruby、sql、vb、xml):
复制代码 代码如下:
<textarea name="code" class="js" rows="15" cols="100">
//程序源代码放在这儿
</textarea>
4、在网页尾部的</body>之前插入以下代码:
复制代码 代码如下:
<script class="javascript" src="images/Scripts/shCore.js"></script>
<script class="javascript" src="images/Scripts/shBrushCSharp.js"></script>
<script class="javascript" src="images/Scripts/shBrushPhp.js"></script>
<script class="javascript" src="images/Scripts/shBrushJScript.js"></script>
<script class="javascript" src="images/Scripts/shBrushJava.js"></script>
<script class="javascript" src="images/Scripts/shBrushVb.js"></script>
<script class="javascript" src="images/Scripts/shBrushSql.js"></script>
<script class="javascript" src="images/Scripts/shBrushXml.js"></script>
<script class="javascript" src="images/Scripts/shBrushDelphi.js"></script>
<script class="javascript" src="images/Scripts/shBrushPython.js"></script>
<script class="javascript" src="images/Scripts/shBrushRuby.js"></script>
<script class="javascript" src="images/Scripts/shBrushCss.js"></script>
<script class="javascript" src="images/Scripts/shBrushCpp.js"></script>
<script class="javascript">
dp.SyntaxHighlighter.HighlightAll('code');
</script>
加载全部内容