1、下载
SyntaxHighlighter 3.0.83 : http://alexgorbatchev.com/SyntaxHighlighter
2、配置
(1) SyntaxHighlighter解析的默认标签,默认为pre
SyntaxHighlighter.config.tagName="div";
(2) 去除HTML换行标记
如果您的软件会在每行末尾添加 标记,此选项允许您忽略这些标记。
shCore.js中实现代码为:
if (sh.config.stripBrs == true)
str = str.replace(br, '');
SyntaxHighlighter.config.stripBrs=true;
(3) 不显示工具条
SyntaxHighlighter.defaults['toolbar'] = false;
3、代码中使用
3.1 brush为必选项,其余为可选:
brush取值:java/xml/sql/c/js/css等,详见:http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/
3.2 着色调用:
SyntaxHighlighter.highlight();
或
SyntaxHighlighter.all();
all()与highlight()区别在于all()是注册到onload()事件中的。
4、在博客园中使用
博客园默认支持SyntaxHighlighter。代码修改默认值(因为jQuery不支持设置!important的样式所以需要设置cssText):
var sh = $(".syntaxhighlighter");
var code = sh.find("code");
var line = sh.find(".line");
var caption = sh.find("table caption");
sh.css("cssText", "width: auto !important");
code.add(line)
.add(caption)
.css("cssText", "font-size: 20px !important;white-space: nowrap !important;line-height: 1.5em !important;");
以上就是本文的全部内容了,小伙伴们对SyntaxHighlighter的使用方法是否有了新的认识呢,希望大家能够喜欢本文。
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn