修复 SyntaxHighlighter 3.0.83 Java 代码多行注释 Bug

使用 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简约设计の艺术 进行同步发布的
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值