Tofu
Tofu is the best food all around the world!


Syntax Highlighter

前些日子搬家都時候把語法高亮插件從 Google Syntax Highlighter 換成了 Syntax Highlighter,主要是因爲前者對特殊符號的轉義處理不甚完美,且早已不再更新。不過後者也帶來了新問題:

悲伤的采购 @ 2011/08/15, 16:58:59, UTC+8 Says:
话说,复制代码时行号也一并复制了。。。

看了下源碼,用的是 table 來排版,簡單的換爲 ol 應當能避免複製行號,但會失去行號開關的功能,不過只是個小問題,可以無視了。

修改 Scripts/shCore.js 文件,找到

  1.             code +=
  2.                 '<div class="line ' + lineClass + '">'
  3.                     + '<table>'
  4.                         + '<tr>'
  5.                             + (hasGutter ? '<td class="number"><code>' + lineNumber + '</code></td>' : '')
  6.                             + '<td class="content">'
  7.                                 + (spaces != null ? '<code class="spaces">' + spaces.replace(' ', ' ') + '</code>' : '')
  8.                                 + line
  9.                             + '</td>'
  10.                         + '</tr>'
  11.                     + '</table>'
  12.                 + '</div>'
  13.                 ;
  14.         }
  15.  
  16.         return code;

替換爲

  1.             code +=
  2.                             '<li class="line ' + lineClass + ' content">'
  3.                                 + (spaces != null ? '<code class="spaces">' + spaces.replace(' ', ' ') + '</code>' : '')
  4.                                 + line
  5.                             + '</li>'
  6.                 ;
  7.         }
  8.  
  9.         return '<ol class="line">' + code + '</ol>';

修改 Style/shCore.css 文件,加入

  1. .syntaxhighlighter {
  2.     background-color: #e7e5dc !important;
  3.     padding-left: 20px !important;
  4. }
  5.  
  6. .syntaxhighlighter ol li {
  7.     margin-bottom: 0 !important;
  8.     list-style-type: decimal-leading-zero !important;
  9.     line-height: 1.5em !important;
  10. }

修改 Sytle/shThemeDefault.css 文件,移除

  1. .syntaxhighlighter {
  2.     background-color: #fff !important;
  3. }

OK,搞定,收工。


Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).