在众多的Druapl语法高亮插件中,syntax highlighter是最好用的插件,因此,Drupal7+CKEditor+syntax highlighter环境也是最好的。 下面将是讲述如何安装CKEditor+syntax highlighter。 最终安装效果: 
- 下载 Ckeditor 和 Syntax highlighter 模块。
- 下载 Syntax highlighter library 解压到 sites/all/libraries
- 下载 CKeditor library 解压到 ../Ckeditor/Ckeditor (一般是 sites/all/modules/Ckeditor/Ckeditor)
- 下载 ckeditor-syntaxhighlight 插件,解压到 ../Ckeditor /Ckeditor/plugins(一般是 "sites/all/modules/Ckeditor/Ckeditor/plugins" ,务必确认解压的目标文件夹为 Ckeditor/Ckeditor,而不是 Ckeditor/plugins)。
- 在文件 /sites/all/modules/ckeditor/includes/ckeditor.lib.inc 314行左右,'plugins section' 后添加以下代码:
if (file_exists($editor_path . 'plugins/syntaxhighlight/plugin.js')) {9 E# \) K, H- {* j% C/ \
$arr['syntaxhighlight'] = array(
3 G9 ~% A: h! L, F 'name' => 'syntaxhighlight',
2 Y9 \! a# [+ }, i% P 'desc' => t('Syntaxhighlight plugin'),; p6 X8 q1 n: v" |/ T
'path' => base_path() . $editor_path . 'plugins/syntaxhighlight/',
; K- f+ C) d! d9 b4 J/ H 'default' => 'f'+ U1 [/ q4 f8 O6 O2 Y3 g, H" v. `
);, o B# l6 g/ a$ X- ?
} 接下来去管理页面安装模块,配置模块吧。 - 启动语法高亮模块。 admin/config/content/syntaxhighlighter
 - 调整相应的HTML 过滤顺序。admin/config/content/formats
 - 设置 CKeditor 模块。 admin/config/content/ckeditor
1# 开启语法高亮。
 2# 开启<pre>标签
 3# 在CKEditor 工具栏中 添加 {code} 按钮。
 4# 开启 语法高亮 插件
 - 大公告成。
*注:要谨慎选择 “ Inject js/css code on specific pages ”,在不需要开启代码高亮的页面应该关闭它,否则会因为JS或CSS叠加而引起错误。 |