[WordPress] 外掛分享: Prism Syntax Highlighter (detached)

首頁外掛目錄 › Prism Syntax Highlighter (detached)
WordPress 外掛 Prism Syntax Highlighter (detached) 的封面圖片
10+
安裝啟用
★★★★
4.3/5 分(4 則評價)
4615 天前
最後更新
問題解決
WordPress 3.4.0+ v1.5 上架:2012-09-03

內容簡介

將Prism Syntax Highlighting Library整合至 WordPress。

這個外掛是被稱為「分離式」,因為程式碼範例不會和所有的其他文字和內容混在一起裝在所見即所得編輯器中,而是被分獨地加入為自訂欄位,然後只是透過短代碼(就像腳註)來引用。

使用方式請參考其他注意事項。

官方開發存儲庫位於Github上。

使用方法

基本步驟如下:

建立自訂欄位,並將程式碼貼上其中。
在您要顯示程式碼塊的位置插入[prism ...]短代碼。

短代碼
[prism key=".." language=".." line=".." line_offset=".." post=".."]

key:包含代碼的自訂欄位的名稱(必填)
language:要加亮的語言
line:高亮行數(請參考官方說明文件)
line_offset:行號起始的偏移值
post:如果您想要包含另一篇文章的代碼,可以在此明確指定文章的 ID

快取資源載入程式

該外掛包含有快取資源載入程式(自 v1.3 開始),以便所有所需的資源可以連接成一個 JS 檔案和一個 CSS 檔案,以最小化 HTTP 請求。
要使用快取資源載入程式,只需在您的外掛目錄內建立一個 /cache/ 目錄並為 PHP 設置可寫權限即可。

支援的語言

僅支援 PrismJS 官方支援的語言:

bash(Unix Shell)
c
clike
coffeescript
cpp(C++)
css
groovy
java
javascript
markup(如:xHTML、MathML、SVG、LaTeX、RSS、XML、OWL 等)
php
python
scss(Sassy CSS)
sql

建立自訂擴充功能

請閱讀 Wiki 頁面:Creating A Custom Extension。

外掛標籤

開發者團隊

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

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

原文外掛簡介

Integrates the Prism Syntax Highlighting Library in WordPress.
It is called detached, since the code examples are not stuffed into the rich text editor, together with all the
other texts and content, but they are added separately as custom fields and just referenced via short tags (like footnotes).
Check Other Notes for usage documentation.
The official development repository is hosted on Github.
Usage
The basic procedure is:

Create a custom field and paste the code into it.
Insert the [prism ...] shorttag in your code, where you want the code block to appear.

Shorttag
[prism key=".." language=".." line=".." line_offset=".." post=".."]

key: the name of the custom field, which contains the code (required)
language: the language to highlight
line: highlighted lines (for syntax, check the offical docs)
line_offset: the offset, with which the line numbering should start
post: if you want to include a code piece of another post, you can explicitly specify the post id here

Cached Assets loader
The plugin includes (from v1.3 on) a cached assets loader, so that all needed assets are concatenated into
one js and one css file to minimize the HTTP requests.
To make use of the cached assets loader, just create a directory /cache/ inside your plugin directory and make it writable for PHP.
Supported languages
Only the ones from the official PrismJS repository

bash (Bash Unix Shell)
c
clike
coffeescript
cpp (C++)
css
groovy
java
javascript
markup (like: xHTML, MathML, SVG, LaTeX, RSS, XML, OWL, etc.)
php
python
scss (Sassy CSS)
sql

Creating Custom Extensions
Please read the wiki page: Creating A Custom Extension.

延伸相關外掛

文章
Filter
Mastodon