2012年5月14日 星期一

如何在blogger上加上syntax highlight


<script type="text/javascript">
alert(1);
alert(2);

var Bear = {};
</script>
http://jimchung1221.pixnet.net/blog/post/9425133-如何在blogger上加上syntax-highlight

如果網站的不知援外部運算
那就土法煉鋼
連上下面那個網站

http://www.tohtml.com/html/

 
把你的source code貼上後
按下"Highlight"
再把產生對應的HTML貼到網頁即可

How to Add Syntax Highlighter(v3) to Blogger Blogs
http://www.way2blogging.org/2011/03/how-to-add-syntax-highlighterv3-to.html 
http://www.way2blogging.org/widget-generators/syntax-highlighter-scripts-generator (checkbox在字的右邊)


SyntaxHighlighter Configuration
http://alexgorbatchev.com/SyntaxHighlighter/manual/configuration/
 
<pre class='brush:[brushname];'>
 

 
</pre>
 
 
<pre class="brush: js; ruler: true; first-line: 10; highlight: [2, 4, 6]">...</pre>
 
12345
各個語言的brush對照表
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/

Brush nameBrush aliasesFile name
ActionScript3as3, actionscript3shBrushAS3.js
Bash/shellbash, shellshBrushBash.js
ColdFusioncf, coldfusionshBrushColdFusion.js
C#c-sharp, csharpshBrushCSharp.js
C++cpp, cshBrushCpp.js
CSScssshBrushCss.js
Delphidelphi, pas, pascalshBrushDelphi.js
Diffdiff, patchshBrushDiff.js
Erlangerl, erlangshBrushErlang.js
GroovygroovyshBrushGroovy.js
JavaScriptjs, jscript, javascriptshBrushJScript.js
JavajavashBrushJava.js
JavaFXjfx, javafxshBrushJavaFX.js
Perlperl, plshBrushPerl.js
PHPphpshBrushPhp.js
Plain Textplain, textshBrushPlain.js
PowerShellps, powershellshBrushPowerShell.js
Pythonpy, pythonshBrushPython.js
Rubyrails, ror, rubyshBrushRuby.js
ScalascalashBrushScala.js
SQLsqlshBrushSql.js
Visual Basicvb, vbnetshBrushVb.js
XMLxml, xhtml, xslt, html, xhtmlshBrushXml.js

上面那個表格製作方法:
複製網址內的表格到sublime,用正規搜尋\t把第一、二、三行切開分別複製到Excel上,
然後複製整個表格到blog上即自動對齊


20200415 修正https時syntax highlight 失效問題

找出當時這些外連資源在哪加入的
https://support.google.com/blogger/answer/176245?hl=zh-Hant
主題 => 「網誌即時狀態(...)」之下,按一下 [編輯 HTML]
將 http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js 改成  https://agorbatchev.typepad.com/pub/sh/3_0_83/scripts/shCore.js
其他亦同
避免 http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js 轉跳到 https://agorbatchev.typepad.com/pub/sh/3_0_83/scripts/shCore.js 時瀏覽器報mixed content 的錯誤

20220811 換成 cloudflare CDN

因為 https://agorbatchev.typepad.com/pub/sh/3_0_83/scripts/shBrushPhp.js  404 ,所以換成 https://cdnjs.cloudflare.com/ajax/libs/SyntaxHighlighter/3.0.83/scripts/shBrushPhp.js

參考資料: