syntaxhighlighter 使用方法


Posted in Javascript onJuly 02, 2007

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

Javascript 相关文章推荐
JavaScript 学习笔记二 字符串拼接
Mar 28 Javascript
jQuery判断密码强度实现思路及代码
Apr 24 Javascript
javascript 处理null及null值示例
Jun 09 Javascript
Javascript核心读书有感之类型、值和变量
Feb 11 Javascript
AngularJS基础学习笔记之指令
May 10 Javascript
jQuery版本升级踩坑大全
Jan 12 Javascript
jQuery代码实现对话框右上角菜单带关闭×
May 03 Javascript
JS拉起或下载app的实现代码
Feb 22 Javascript
如何快速解决JS或Jquery ajax异步跨域的问题
Jan 08 jQuery
js中split()方法得到的数组长度问题
Jul 19 Javascript
vue模仿网易云音乐的单页面应用
Apr 24 Javascript
微信小程序如何使用canvas二维码保存至手机相册
Jul 15 Javascript
javascript之dhDataGrid Ver2.0.0代码
Jul 01 #Javascript
javascript事件模型代码
Jul 01 #Javascript
如何快速的呈现我们的网页的技巧整理
Jul 01 #Javascript
IE autocomplete internet explorer's autocomplete
Jun 30 #Javascript
用javascript实现的激活输入框后隐藏初始内容
Jun 29 #Javascript
javascritp实现input输入框相关限制用法
Jun 29 #Javascript
优化网页之快速的呈现我们的网页
Jun 29 #Javascript
You might like
php5新改动之短标记启用方法
2008/09/11 PHP
用PHP查询搜索引擎排名位置的代码
2010/01/05 PHP
Prototype RegExp对象 学习
2009/07/19 Javascript
JavaScript Konami Code 实现代码
2009/07/29 Javascript
从零开始学习jQuery (十) jQueryUI常用功能实战
2011/02/23 Javascript
jQuery获得内容和属性方法及示例
2013/12/02 Javascript
location.href用法总结(最主要的)
2013/12/27 Javascript
javascript弹性运动效果简单实现方法
2016/01/08 Javascript
jQuery头像裁剪工具jcrop用法实例(附演示与demo源码下载)
2016/01/22 Javascript
jQuery设置Easyui校验规则(推荐)
2016/11/21 Javascript
javascript基于原型链的继承及call和apply函数用法分析
2016/12/15 Javascript
socket.io与pm2(cluster)集群搭配的解决方案
2017/06/02 Javascript
浅谈vue,angular,react数据双向绑定原理分析
2017/11/28 Javascript
实时监控input框,实现输入框与下拉框联动的实例
2018/01/23 Javascript
iview通过Dropdown(下拉菜单)实现的右键菜单
2018/10/26 Javascript
微信小程序实现简单评论功能
2018/11/28 Javascript
详解小程序如何避免多次点击,重复触发事件
2019/04/08 Javascript
layui原生表单验证的实例
2019/09/09 Javascript
JS判断数组四种实现方法详解
2020/06/29 Javascript
[46:47]完美世界DOTA2联赛PWL S2 FTD vs Magma 第二场 11.20
2020/11/23 DOTA
Python程序设计入门(2)变量类型简介
2014/06/16 Python
Python使用 Beanstalkd 做异步任务处理的方法
2018/04/24 Python
Flask入门之上传文件到服务器的方法示例
2018/07/18 Python
3个用于数据科学的顶级Python库
2018/09/29 Python
django多文件上传,form提交,多对多外键保存的实例
2019/08/06 Python
在Python中os.fork()产生子进程的例子
2019/08/08 Python
python GUI库图形界面开发之PyQt5窗口控件QWidget详细使用方法
2020/02/26 Python
Pytorch转onnx、torchscript方式
2020/05/25 Python
Python常用base64 md5 aes des crc32加密解密方法汇总
2020/11/06 Python
Viking Direct爱尔兰:办公用品和家具
2019/11/21 全球购物
Super-Pharm波兰:药房和香水在一个地方
2020/08/18 全球购物
大专学生推荐信范文
2013/11/19 职场文书
企业委托书范本
2014/09/13 职场文书
2014年小学教研工作总结
2014/12/06 职场文书
孝老爱亲事迹材料
2014/12/24 职场文书
2016暑期政治学习心得体会
2016/01/23 职场文书