88250

          Java

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            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簡約設計の藝術(shù) 進行同步發(fā)布的
          原文地址:http://b3log-88250.appspot.com/articles/2010/10/27/1288167868710.html
          posted on 2010-10-27 16:24 88250 閱讀(904) 評論(1)  編輯  收藏

          評論

          # re: 修復 SyntaxHighlighter 3.0.83 Java 代碼多行注釋 Bug 2012-05-07 14:37 Geek_Soledad
          用了這個插件后也發(fā)現(xiàn)了這個問題,是正則表達式的錯誤。我也修改了一下,修改如下:
          找到shBrushJava.js文件,將第34行,即對多行注釋的正則表達式修改如下:

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

          詳見我的博文:http://msdxblog.sinaapp.com/?p=437  回復  更多評論
            


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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 当阳市| 平舆县| 易门县| 克什克腾旗| 长沙市| 瑞昌市| 上林县| 西平县| 屏东县| 木里| 乐陵市| 甘南县| 德钦县| 东海县| 南宁市| 安顺市| 彭水| 建昌县| 德阳市| 玉树县| 北海市| 游戏| 吴忠市| 基隆市| 阿克苏市| 宜兰市| 邛崃市| 江北区| 潜山县| 宜昌市| 乌拉特后旗| 丹江口市| 东台市| 西盟| 栖霞市| 外汇| 交城县| 临洮县| 云霄县| 郁南县| 温宿县|