放出个 JavaScript 代码语法高亮类, 是根据 Unnamed Blog 上的修改的(原文提供的下载后有不少错误…), 效率比我原来写的高了不少. 当然, 我自己最后估计还是拿 Lex 来做…

主要修改的地方首先是让整个 js 可运行(-_-!)…然后完善了一些功能, 比如对 & 和 < 的处理, 还有把其它语言的支持分离开来.

首先是 cpp 高亮的支持 js 文件

sh.Brushes.Cpp = function() {}

sh.Brushes.Cpp.aliases = ‘cpp’;

sh.Brushes.Cpp.regexList = [
{regex: new RegExp('//.*$', 'gm'), css: 'comment'}, // one line comments
{regex: new RegExp('/\\*[\\s\\S]*?\\*/’, ‘g’), css: ‘comment’}, // multi line comments
{regex: new RegExp(“\’(?:[^\\\\']|\\\\.)*\’|” +
“\”(?:[^\\\\\"]|\\\\.)*\”", ‘g’), css: ’string’}, // string literals
{regex: new RegExp(‘^\\s*#.*’, ‘gm’), css: ‘preprocessor’}, // preprocessor directives
{regex: new RegExp(‘\\b(?:auto|break|case|char|const|continue|default|do’ +
‘double|else|enum|extern|float|for|goto|if|int|long|register’ +
‘return|short|signed|sizeof|static|struct|switch|typedef|union’ +
‘unsigned|void|volatile|while)\\b’, ‘gm’), css: ‘keyword’} // keyword
];

Read the rest of this entry »

Tags: ,