Windows Live Writer 实现代码高亮
程序员文章站
2022-06-16 19:39:08
为了实现代码高亮,之前找了很多插件,但是效果都不是很理想。经过研究终于找到一个完美的解决方案,这个解决方案具有如下优点:
代码简洁,用
标签...
为了实现代码高亮,之前找了很多插件,但是效果都不是很理想。经过研究终于找到一个完美的解决方案,这个解决方案具有如下优点:
<script type="text/javascript" src="scripts/shcore.js"></script>
02.<script type="text/javascript" src="scripts/shbrushbash.js"></script>
03.<script type="text/javascript" src="scripts/shbrushcpp.js"></script>
04.<script type="text/javascript" src="scripts/shbrushcsharp.js"></script>
05.<script type="text/javascript" src="scripts/shbrushcss.js"></script>
06.<script type="text/javascript" src="scripts/shbrushdelphi.js"></script>
07.<script type="text/javascript" src="scripts/shbrushdiff.js"></script>
08.<script type="text/javascript" src="scripts/shbrushgroovy.js"></script>
09.<script type="text/javascript" src="scripts/shbrushjava.js"></script>
10.<script type="text/javascript" src="scripts/shbrushjscript.js"></script>
11.<script type="text/javascript" src="scripts/shbrushphp.js"></script>
12.<script type="text/javascript" src="scripts/shbrushplain.js"></script>
13.<script type="text/javascript" src="scripts/shbrushpython.js"></script>
14.<script type="text/javascript" src="scripts/shbrushruby.js"></script>
15.<script type="text/javascript" src="scripts/shbrushscala.js"></script>
16.<script type="text/javascript" src="scripts/shbrushsql.js"></script>
17.<script type="text/javascript" src="scripts/shbrushvb.js"></script>
18.<script type="text/javascript" src="scripts/shbrushxml.js"></script>
19.<link href="styles/shcore.css" type="text/css" rel="stylesheet" />
20.<link href="styles/shthemeemacs.css" type="text/css" rel="stylesheet" />
21.<script type="text/javascript">syntaxhighlighter.config.clipboardswf = 'scripts/clipboard.swf';syntaxhighlighter.all();</script>
如此配置之后,通过windows live writer插入的代码,在wordpress中可以十分优雅的显示出来。
- 代码简洁,用<pre>标签实现代码高亮,不会生成太多html标签。
- 支持多种语言,包括c#,c++,php,python等10多种语言。
- 扩充方便,可以通过简单二次开发实现对其它语言的支持。
- 使用方便,把代码复制到代码高亮转换窗口即可。
下面一步步介绍如何配置wlw+wordpress的代码高亮解决方案:
1.准备工作:
下载 precode code snippet manager
下载成功后得到一个名为precodeplugin_4.0.2.msi的文件
下载成功后得到一个名为syntaxhighlighter_2.0.296.zip文件。
2.安装:
关闭windows live writer,安装precodeplugin_4.0.2.msi。安装成功后启动wlw,此时在插件列表里应该出现一项名为precode snippet的插件。
将syntaxhighlighter_2.0.296.zip解压缩至wordpress的活动主题目录,例如:\www\wp\wp-content\themes\lutuzhi\syntaxhighlighter
3.在header.php 中,在<meta http-equiv="content-type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />下方添加:
复制代码 代码如下:
<script type="text/javascript" src="scripts/shcore.js"></script>
02.<script type="text/javascript" src="scripts/shbrushbash.js"></script>
03.<script type="text/javascript" src="scripts/shbrushcpp.js"></script>
04.<script type="text/javascript" src="scripts/shbrushcsharp.js"></script>
05.<script type="text/javascript" src="scripts/shbrushcss.js"></script>
06.<script type="text/javascript" src="scripts/shbrushdelphi.js"></script>
07.<script type="text/javascript" src="scripts/shbrushdiff.js"></script>
08.<script type="text/javascript" src="scripts/shbrushgroovy.js"></script>
09.<script type="text/javascript" src="scripts/shbrushjava.js"></script>
10.<script type="text/javascript" src="scripts/shbrushjscript.js"></script>
11.<script type="text/javascript" src="scripts/shbrushphp.js"></script>
12.<script type="text/javascript" src="scripts/shbrushplain.js"></script>
13.<script type="text/javascript" src="scripts/shbrushpython.js"></script>
14.<script type="text/javascript" src="scripts/shbrushruby.js"></script>
15.<script type="text/javascript" src="scripts/shbrushscala.js"></script>
16.<script type="text/javascript" src="scripts/shbrushsql.js"></script>
17.<script type="text/javascript" src="scripts/shbrushvb.js"></script>
18.<script type="text/javascript" src="scripts/shbrushxml.js"></script>
19.<link href="styles/shcore.css" type="text/css" rel="stylesheet" />
20.<link href="styles/shthemeemacs.css" type="text/css" rel="stylesheet" />
21.<script type="text/javascript">syntaxhighlighter.config.clipboardswf = 'scripts/clipboard.swf';syntaxhighlighter.all();</script>
如此配置之后,通过windows live writer插入的代码,在wordpress中可以十分优雅的显示出来。