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编程起步(第六课)
Jan 10 Javascript
JavaScript DOM学习第六章 表单实例
Feb 19 Javascript
javascript判断iphone/android手机横竖屏模式的函数
Dec 20 Javascript
JS正则表达式获取分组内容的方法详解
Nov 15 Javascript
JavaScript原生对象之String对象的属性和方法详解
Mar 13 Javascript
jquery文字填写自动高度的实现方法
Nov 07 Javascript
实例讲解javascript实现异步图片上传方法
Dec 05 Javascript
laravel5.3 vue 实现收藏夹功能实例详解
Jan 21 Javascript
vue axios封装及API统一管理的方法
Apr 18 Javascript
详解vue-cli+es6引入es5写的js(两种方法)
Apr 19 Javascript
vue框架制作购物车小球动画效果实例代码
Sep 26 Javascript
vue2.0 获取从http接口中获取数据,组件开发,路由配置方式
Nov 04 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
PHP3 safe_mode 失效漏洞
2006/10/09 PHP
php使用curl打开https网站的方法
2015/06/17 PHP
PHPStrom中实用的功能和快捷键大全
2015/09/23 PHP
php封装的单文件(图片)上传类完整实例
2016/10/18 PHP
微信公众号实现会员卡领取功能
2017/06/08 PHP
PHP基于redis计数器类定义与用法示例
2018/02/08 PHP
PHP判断是否是微信打开还是浏览器打开的方法
2019/02/27 PHP
js cookies实现简单统计访问次数
2009/11/24 Javascript
基于JQuery的动态删除Table表格的行和列的代码
2011/05/12 Javascript
可恶的ie8提示缺少id未定义
2014/03/20 Javascript
jQuery Ajax调用WCF服务详细教程
2015/03/31 Javascript
JavaScript操作选择对象的简单实例
2016/05/16 Javascript
jQuery如何防止Ajax重复提交
2016/10/14 Javascript
浅谈Vue的基本应用
2016/12/27 Javascript
jQuery表单设置值的方法
2017/06/30 jQuery
vue2 前端搜索实现示例
2018/02/26 Javascript
jQuery替换节点元素的操作方法
2018/03/18 jQuery
小程序点赞收藏功能的实现代码示例
2018/09/07 Javascript
详解React 服务端渲染方案完美的解决方案
2018/12/14 Javascript
基于Nuxt.js项目的服务端性能优化与错误检测(容错处理)
2019/10/23 Javascript
vue el-table实现行内编辑功能
2019/12/11 Javascript
js实现点赞效果
2020/03/16 Javascript
vuex中store存储store.commit和store.dispatch的用法
2020/07/24 Javascript
[53:36]Liquid vs VP Supermajor决赛 BO 第三场 6.10
2018/07/05 DOTA
[01:03:27]Optic vs VGJ.S 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/20 DOTA
[30:55]完美世界DOTA2联赛PWL S2 Magma vs LBZS 第二场 11.18
2020/11/18 DOTA
python通过scapy获取局域网所有主机mac地址示例
2014/05/04 Python
Python 2.7.x 和 3.x 版本的重要区别小结
2014/11/28 Python
python 数据提取及拆分的实现代码
2019/08/26 Python
python通过SSH登陆linux并操作的实现
2019/10/10 Python
如何使用Python脚本实现文件拷贝
2019/11/20 Python
jupyter notebook 实现matplotlib图动态刷新
2020/04/22 Python
谈谈python垃圾回收机制
2020/09/27 Python
CSS3 旋转立方体问题详解
2020/01/09 HTML / CSS
详解HTML5 Canvas标签及基本使用
2020/01/10 HTML / CSS
入党后的感想
2015/08/10 职场文书