使用 SyntaxHighlighter 3.0.83 對(duì)包含多行注釋(/* .... */) 的 Java 代碼進(jìn)行語(yǔ)法著色時(shí)會(huì)將其后的所有代碼當(dāng)成多行注釋進(jìn)行著色。
修改 shBrushJava.js 可以解決這個(gè)問(wèn)題。
找到:
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 從 簡(jiǎn)約設(shè)計(jì)の藝術(shù) 進(jìn)行同步發(fā)布的