syntaxhighlighter从3.8开始需要自己编译。
它的编译依赖于nodejs即npm。
我在linux系统上编译它。
首先从官网下载 node-v6.9.4-linux-x64.tar.gz
(其他版本可能会有编译问题。)
解压到 /usr/local/node/
设置环境变量
cd /etc/profile.d
vi node.sh
插入如下内容
export NODE_HOME=/usr/local/node export PATH=$PATH:$NODE_HOME/bin export NODE_PATH=$NODE_HOME/lib/node_modules
使环境变量生效
source profile # 测试 nodejs -version npm -version
下载 syntaxhighlighter4.0.1 (4.0依赖有问题)
解压
unzip syntaxhighlighter-4.0.1.zip cd syntaxhighlighter-4.0.1 npm install # 需要你设置ssh key, 并将生成的id-rsa.pub的内容添加的github ssh key. # 需要设置git全局变量 git config --global user.name "xxxxxx" # git config --global user.email "xxxxxx" ./node_modules/gulp/bin/gulp.js setup-project
#如果报permission问题,则你的git设置有问题
执行build
./node_modules/gulp/bin/gulp.js build –brushes=all –theme=default
出现 TypeError: loadReposFromCache(…).error is not a function
修改 node_modules/songbird/lib/songbird.js
Promise = global.Promise || require(“bluebird”);
为
Promise = require(“bluebird”);
最后在 dist文件夹中有生成的文件
-syntaxhighlighter.js
-theme.css
-index.html
使用
function foo() { }
两种方法都可以