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

Javascript
javascript下操作css的float属性的特殊写法
javascript之DIV拖动类 支持在FF下拖动,调用简单
Expandable "Detail" Table Rows
用javascript实现给出的盒子的序列是否可连为一矩型
PNGHandler-借助JS让PNG图在IE下实现透明(包括背景图)
JS创建优美的页面滑动块效果 - Glider.js
发一个比较漂亮的选项卡动态增删的效果
可多次使用的仿126邮箱选项卡的源码
javascript仿XP关机效果的弹出窗口功能
JS控制CSS样式的方法
非常漂亮的JS代码经典广告
推荐自用 Javascript 缩图函数 (onDOMLoaded)……
几个不错的自动收缩菜单导航效果
iframe src为图片时的高度自适应的代码
论坛转贴工具中用到的正则表达式学习正则的好例子
用javascript实现的不错的一款网页选项卡
摘自百度的图片轮换效果代码
用javascript实现旋转图片效果的代码
javascript 制作坦克大战游戏初步 图片与代码
比较简单的jquery教程 Easy Ajax with jQuery 中文版全集

Javascript 中的 syntaxhighlighter 使用方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 59 ::
收藏到网摘: 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