[WordPress] 外掛分享: Prettify GC Syntax Highlighter

首頁外掛目錄 › Prettify GC Syntax Highlighter
20+
安裝啟用
★★★★
4.3/5 分(3 則評價)
4947 天前
最後更新
問題解決
WordPress 3.0.5+ v1.6.0 上架:2011-02-15

內容簡介

此外掛直接複製了美化程式庫 prettify.js 從 google-code source browser。如此您的程式碼將會長得和在 google-code 上一模一樣。
CSS 被稍微修改了,以加粗關鍵詞和型別。

授權

授權詳情請見 prettify.js(Apache License 2.0)。其他檔案採用 GPLv2 授權。

使用方式

<pre class="prettyprint">
// 在這裡加入你的程式碼。
</pre>

或使用短碼:

[code]
// 在這裡加入你的程式碼。
[/code]

保護程式碼中的 HTML 標籤

這個外掛能自動使你的程式碼被 HTML 安全地保護:

<pre class="prettyprint">
任何出現在這裡的文字都會不經修改地顯示在頁面上。
例如:<head></head><body></body>
</pre>

若要避免你的程式碼被修改,請把 "dontquote" 加在第一個類別上。

<pre class="dontquote prettyprint">
請留意需要自行修改 HTML 語法。
例如:&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;
</pre>

編號行

以下方法可以啟用編號行:

<pre class="prettyprint linenums">
// 在這裡加入你的程式碼。
</pre>

如果你想要從第 42 行開始編號,請加入以下參數:

<pre class="prettyprint linenums:42">
// 在這裡加入你的程式碼。
</pre>

將某些行文字標示

當編號行被啟用時,你可以使用 highlight 類別來將一或多個行標示出來:

<pre class="prettyprint lang-YOURLANG linenums highlight:2,4">
// 第 2 行
// 第 3 行
// 第 4 行
</pre>

你也可以標示出一或多個程式碼區塊:

<pre class="prettyprint lang-YOURLANG linenums highlight:1-3,5-6">
// 第 2 行
// 第 3 行
// 第 4 行
// 第 5 行
</pre>

注意:當編號行未啟用時無法使用這個功能。

指定語言

大部分時候這個採用高亮字的功能會自動猜測程式碼的語言。但是,為了取得最好的效果,請明確指定語言:

<pre class="prettyprint lang-YOURLANG">
// 在這裡加入你的程式碼。
</pre>

把 YOURLANG 換成以下之一:

aea
agc
apollo
bsh
c
cc
cl
cpp
cs
csh
css-str
cv
cxx
cyc
default-markup
el
fs
go
hs
htm
html
java
js
json
lisp
lua
m
ml
mxml
perl
pl
pm
proto
py
rb
scala
scm
sh
sql
vhd
vhdl
wiki
xhtml
xml
xsl
yaml
yml

短碼

以下是一個快速範例。所有參數都是可選的。

[code lang=”scala” start=”1″ highlight=”1-3,6,10-14″ background=”#C0FFB3″]
// 在這裡加入你的程式碼。
[

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.6.0) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Prettify GC Syntax Highlighter」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin has prettify.js copied directly from google-code source browser. So your code will look exactly like it does on google-code.
CSS is slightly modified to embolden keywords and types.
License
See prettify.js for license details (Apache License 2.0). Other files are available under GPLv2.
Usage

  // Put your code here.

Or with shortcode:
[code]
// Put your code here.
[/code]
Making Code HTML Safe
The plugin automatically makes highlighted code html-safe:

  Anything that goes here will be quoted to appear on the page as-is.
  For example: 

To avoid quoting your code, add dontquote as the first class.

  Remember to quote manually.
  For example: <head></head><body></body>

Line Numbering
Line numbdering can be enabled as follows:

  // Put your code here.

If you want to start with a line number 42, you can do the following:

  // Put your code here.

Highlighting Lines
When line numbering is enabled you can highlight one or several lines of code using the highlight class:

  // line 2
  // line 3
  // line 4

Alternatively you can highlight one or several code segments:

  // line 2
  // line 3
  // line 4
  // line 5

Note: This feature is not available when line numbering is disabled.
Specifying Language
Most of the time the highlighter will do a good job guessing how to highlight the code. However, to achieve the best result, you should specify the language:

  // Put your code here.

Replace YOURLANG with one of the following:

aea
agc
apollo
bsh
c
cc
cl
cpp
cs
csh
css-str
cv
cxx
cyc
default-markup
el
fs
go
hs
htm
html
java
js
json
lisp
lua
m
ml
mxml
perl
pl
pm
proto
py
rb
scala
scm
sh
sql
vhd
vhdl
wiki
xhtml
xml
xsl
yaml
yml

Shortcode
Here is a quick example. All the parameters are optional.
[code lang=”scala” start=”1″ highlight=”1-3,6,10-14″ background=”#C0FFB3″]
// Put your code here.
[/code]
Html quoting can be disabled as follows:
[code quote=”false”]
// Put your code here.
[/code]
The contents of shortcodes is auto-formatted by WP. As a result

and
tags along
with some formatting will be lost. If you need to preseve the original formatting use
html notation instead of the shortcode.
Please Support
If you like Prettify GC Syntax Highlighter plugin, please donate a minute of your time and vote for it. Thank you!

延伸相關外掛

文章
Filter
Apply Filters
Mastodon