88250

          Java

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            82 隨筆 :: 0 文章 :: 5 評(píng)論 :: 0 Trackbacks

          使用 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ā)布的
          原文地址:http://b3log-88250.appspot.com/articles/2010/10/27/1288167868710.html
          posted on 2010-10-27 16:24 88250 閱讀(905) 評(píng)論(1)  編輯  收藏

          評(píng)論

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

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

          詳見(jiàn)我的博文:http://msdxblog.sinaapp.com/?p=437  回復(fù)  更多評(píng)論
            


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 南宁市| 自贡市| 昆明市| 开鲁县| 博白县| 宝应县| 察雅县| 嘉荫县| 江西省| 江津市| 平乐县| 新乡市| 潞西市| 安龙县| 榕江县| 江津市| 绥滨县| 东乡族自治县| 禹州市| 阜阳市| 江源县| 上杭县| 芮城县| 邻水| 新丰县| 克山县| 黔西县| 拜泉县| 南澳县| 泽库县| 五大连池市| 华亭县| 灵宝市| 双流县| 西昌市| 蒙自县| 沙雅县| 夏河县| 建水县| 西充县| 德阳市|