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 閱讀(905) 評論(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  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 禄劝| 长汀县| 潮州市| 青冈县| 金阳县| 琼海市| 双辽市| 辽中县| 瑞丽市| 南昌县| 德昌县| 乌拉特后旗| 井冈山市| 莎车县| 临西县| 靖江市| 张家界市| 武山县| 襄樊市| 栾川县| 江北区| 延津县| 汶上县| 宜城市| 舞钢市| 永修县| 滕州市| 昌图县| 河津市| 曲松县| 溆浦县| 永泰县| 泽州县| 息烽县| 县级市| 太保市| 德安县| 崇州市| 张掖市| 汾西县| 淮滨县|