当前位置: 首页 > 图文教程 > 网络编程 > Javascript > syntaxhighlighter 使用方法

Javascript
滚动条代码生成器
NiftyCube:轻松实现圆角边框
懒就要懒到底:鼠标自动点击(含时间判断)
简单form标准化实例:语义结构
超清晰的document对象详解
用正则获取指定路径文件的名称
整理的比较不错的JavaScript的方法和技巧
求得div 下 img的src地址的js代码
js+css实现的仿office2003界面
一个不错的应用,用于提交获取文章内容,不推荐用
插件:检测javascript的内存泄漏
得到文本框选中的文字,动态插入文字的js代码
翻译整理的jQuery使用查询手册
一个的简易文本编辑器源码
HTML中不支持静态Expando的元素的问题
用CSS打造多彩文字链接
一个不错的用JavaScript实现的UBB编码函数
js实现的非常棒的绿色下拉透明菜单
优秀js开源框架-jQuery使用手册(1)
学习YUI.Ext第七日-View&JSONView Part Two-一个画室网站的案例

Javascript 中的 syntaxhighlighter 使用方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 89 ::
收藏到网摘: n/a

Placing the code

Place your code on the page and surround it with <pre> tag. Set name attribute to code and class attribute to one of the language aliases you wish to use.

<pre name="code" class="c-sharp">
... some code here ...
</pre>

NOTE: One important thing to watch out for is opening triangular bracket <. It must be replaced with an HTML equivalent of < in all cases. Failure to do won't break the page, but might break the source code displayed.

An alternative to <pre> is to use <textarea> tag. There are no problems with < character in that case. The main problem is that it doesn't look as good as <pre> tag if for some reason JavaScript didn't work (in RSS feed for example).

<textarea name="code" class="c#" cols="60" rows="10">
... some code here ...
</textarea>

Extended configuration

There's a way to pass a few configuration options to the code block. It's done via colon separated arguments.

<pre name="code" class="html:collapse">
... some code here ...
</pre>

Making it work

Finally, to get the whole thing to render properly on the page, you have to add JavaScript to the page.

<link type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"></link>
<script language="javascript" src="js/shCore.js"></script>
<script language="javascript" src="js/shBrushCSharp.js"></script>
<script language="javascript" src="js/shBrushXml.js"></script>
<script language="javascript">
dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script>

For optimal result, place this code at the very end of your page. Check HighlightAll for more details about the function.
下载地址:SyntaxHighlighter_1.5.0.zip