內容簡介
這個外掛程式開發的主要原因是缺乏支援 HTML5 建議的選項,其中代碼片段應該被標記為 pre 之後是 code ,並且可以使用以 language- 開頭的類別,然後是我們的語言。
你可以像這樣使用這個外掛程式:
<pre class="prettyprint"><code class="language-php">
// my code
</code></pre>
非常重要的是,儘管此外掛程式根據你的配置加載不同的文件,但它完全支援緩存腳本 (W3 Total Cache)以連接和壓縮所有 css 和 js,因此性能影響將最小化。
語言
這個語法加亮工具基於Google Code Prettify,應該支援多種語言,包括 C 和衍生語言、Java、Python、Bash、SQL、HTML、XML、JavaScript、Makefiles 和 Rust。在Ruby、PHP、VB 和 Awk上它可以正常運作,在Perl 和 Ruby 的一個不錯的子集上也可以正常運作,但由於註釋慣例的影響,它在Smalltalk上無法運作。
可以通過擴充支援其他語言(外掛程式選項):CSS、SQL、YAML、Visual Basic、Clojure、Scala、Latek(TeX、LaTeX)、WikiText、Erlang、Go、Haskell、Lua、OCAML、SML、F#、Nemerle、Protocol Buffers、CHDL(VHDL)、XQ(XQuery)、Lisp、Scheme、Dart、Llvm、Mumps、Pascal、R、S、RD、TCL。
樣式
提供四種不同的樣式,可以在外掛程式的選項中預覽。這些樣式被修改,以確保它們不會與你的佈景主題中的任何樣式產生衝突。
你還可以選擇包含自己的自訂樣式。
如果你有想要在選項列表中看到的樣式,請聯繫我或者fork我。
注意事項
外掛程式選項在「設定」> 「語法加亮」。查看「截圖」選項卡以查看它的外觀。
如果你不太在意 HTML5 的建議,可以跳過 language- 類別。代碼總是會被自動檢測到。
如果你只使用 pre 標籤而沒有使用 code 標籤 (但是長行將被換行而不是水平捲軸),或者僅使用具有 prettyprint 類別的 code 標籤(但如果不使用 pre,你的空格和換行符將不會維持)。
使用業面編輯標籤時,要小心插入代碼,因為有些 HTML 標籤將被修改或刪除。
使用類似 W3 Total Cache 的快取外掛程式是非常推薦的。
演示
在這裡找到前端演示。
外掛標籤
開發者團隊
原文外掛簡介
The main reason for the development of this plugin was the lack of options supporting the HTML5 recommendation, where the code snippets should be tagged with pre followed by code, and optionally a class starting with language- and then our language.
You can use the plugin like this:
// my code
Also very important is that although this plugin loads different files depending on your configuration, it fully supports caching scripts (W3 Total Cache) to concatenate and compress all the css and js, so the impact in performance will be minimum.
Languages
This syntax highlighter is based on Google Code Prettify and should work on a number of languages including C and friends, Java, Python, Bash, SQL, HTML, XML, Javascript, Makefiles, and Rust. It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl and Ruby, but, because of commenting conventions, doesn’t work on Smalltalk.
Other languages are supported via an extension (plugin options): CSS, SQL, YAML, Visual Basic, Clojure, Scala, Latek (TeX, LaTeX), WikiText, Erlang, Go, Haskell, Lua, OCAML, SML, F#, Nemerle, Protocol Buffers, CHDL (VHDL), XQ (XQuery), Lisp, Scheme, Dart, Llvm, Mumps, Pascal, R, S, RD, TCL
Styles
Four different styles are provided, and they can be previewed in the plugin options. They are modified to make sure they don’t clash with any other styles in your theme.
You have also the option to include your custom style.
If you have a style that would like to see included in the option list, just contact me, or fork me.
Notes
Plugin options are at Settings > Prettify Code Syntax. Have a look at the Screenshots tab to see how it looks like.
If you don’t care too much about the HTML5 recommendation, you can skip the language- class. The code always gets detected automatically.
It will also work if you only use a pre tag without the code tag (but long lines will be wrapped instead of get horizontal scroll), or if you only use a code tag with the prettyprint class (but if you don’t use pre your spaces/returns won’t be maintained.)
Be careful using the Visual Editor tab when inserting code, as some HTML tags will be modified or removed.
Using a chaching plugin like W3 Total Cache is highly recommended.
Demo
You can find a front end demo here a the bottom.
