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  回復  更多評論
            


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


          網站導航:
           
          主站蜘蛛池模板: 甘泉县| 舞钢市| 华宁县| 元阳县| 富民县| 麻栗坡县| 绥阳县| 黄浦区| 大渡口区| 读书| 福州市| 望都县| 金门县| 丹凤县| 沙雅县| 永安市| 无为县| 原阳县| 浦江县| 耒阳市| 荆州市| 禹城市| 龙井市| 嵊州市| 普洱| 山丹县| 普定县| 安图县| 苗栗县| 佛冈县| 凌海市| 定日县| 通城县| 天津市| 邵阳市| 旺苍县| 左云县| 徐汇区| 云霄县| 崇阳县| 德保县|