88250

Java

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  82 随笔 :: 0 文章 :: 5 评论 :: 0 Trackbacks

使用 SyntaxHighlighter 3.0.83 对包含多行注释(/* .... */) 的 Java 代码进行语法着色时会将其后的所有代码当成多行注释进行着色。
修改 shBrushJava.js 可以解决这个问题。


找到:

this.regexList = [
	{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },		// one line comments
	{ regex: /\/\*([^\*][\s\S]*)?\*\//gm,				css: 'comments' },	 	// multiline comments
	{ regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm,			css: 'preprocessor' },	 	// documentation comments
	{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,	css: 'string' },		 	// strings
	{ regex: SyntaxHighlighter.regexLib.singleQuotedString,	css: 'string' },		 	// strings
	{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi,			css: 'value' },			// numbers
	{ regex: /(?!\@interface\b)\@[\$\w]+\b/g,			css: 'color1' },		// annotation @anno
	{ regex: /\@interface\b/g,					css: 'color2' },		// @interface keyword
	{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' }		// java keyword
];

修改为:

this.regexList = [
	{ regex: SyntaxHighlighter.regexLib.singleLineCComments,	css: 'comments' },	// one line comments
	{ regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm,			css: 'preprocessor' },  // documentation comments
        { regex: SyntaxHighlighter.regexLib.multiLineCComments,	css: 'comments' },		// multiline comments
	{ regex: SyntaxHighlighter.regexLib.doubleQuotedString,	css: 'string' },		// strings
	{ regex: SyntaxHighlighter.regexLib.singleQuotedString,	css: 'string' },		// strings
	{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi,			css: 'value' },		// numbers
	{ regex: /(?!\@interface\b)\@[\$\w]+\b/g,			css: 'color1' },	// annotation @anno
	{ regex: /\@interface\b/g,					css: 'color2' },	// @interface keyword
	{ regex: new RegExp(this.getKeywords(keywords), 'gm'),		css: 'keyword' }	// java keyword
];
注意把处理文档注释的正则式放到处理多行注释的正则式前。


本文是使用 B3log Solo简约设计の艺术 进行同步发布的
原文地址:http://b3log-88250.appspot.com/articles/2010/10/27/1288167868710.html
posted on 2010-10-27 16:24 88250 阅读(890) 评论(1)  编辑  收藏

评论

# re: 修复 SyntaxHighlighter 3.0.83 Java 代码多行注释 Bug 2012-05-07 14:37 Geek_Soledad
用了这个插件后也发现了这个问题,是正则表达式的错误。我也修改了一下,修改如下:
找到shBrushJava.js文件,将第34行,即对多行注释的正则表达式修改如下:

帮助
1
{ regex: /\/\*[^\*][\s\S]*?\*\//gm, css: 'comments' }, // multiline comments

详见我的博文:http://msdxblog.sinaapp.com/?p=437  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: