[WordPress] 外掛分享: WP-Syntax

WordPress 外掛 WP-Syntax 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「WP-Syntax」是 2007-01-20 上架。
  • 目前有 4000 個安裝啟用數。
  • 上一次更新是 2023-12-01,距離現在已有 169 天。
  • 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.6.20 以上。
  • 有 15 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

shazahm1hotmailcom |

外掛標籤

code | syntax | Highlight | formatting | syntax highlighting |

內容簡介

WP-Syntax 提供乾淨的語法突顯,使用 GeSHi,支援多種流行的語言,包括有或沒有行號的語法突顯,可以在從瀏覽器中複製程式碼片段時保持格式。
它通過運行早期的前置過濾器和後期的後置過濾器來避免與其他第三方外掛程序的衝突,先替換和提取代碼片段,然後在最後推回並加上突顯。結果是源代碼的格式和突顯方式都和預期的一樣。
使用、支援的語言、樣式指南和版本信息都可以在「其他說明」部分中獲得。
想貢獻?WP-Syntax 可以在 GitHub 上找到,現在就派生並提交拉取請求吧!
基本用法
將代碼區塊用 <pre lang="LANGUAGE" line="1"> 和 </pre> 包裹起來,其中 LANGUAGE 為 GeSHi 支持的語言語法。
line 屬性是可選的。欲知更多用法範例,請參閱其他說明。
用法
將代碼區塊用 <pre lang="LANGUAGE" line="1"> 和 </pre> 包裹起來,其中 LANGUAGE 為 GeSHi 支持的語言語法。下面是支援的語言列表。
line 屬性是可選的。
範例 1: PHP,無行號
<pre lang="php">
<div id="foo">
<?php
function foo() {
echo "Hello World!\\n";
}
?>
</div>
</pre>

範例 2: Java,行號
<pre lang="java" line="1">
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</pre>

範例 3: Ruby,從第 18 行開始顯示行號
<pre lang="ruby" line="18">
class Example
def example(arg1)
return "Hello: " + arg1.to_s
end
end
</pre>

範例 4: 如果你的代碼已經轉義了 HTML 實體,請使用 escaped="true" 作為選項
<pre lang="xml" escaped="true">
&lt;xml&gt;Hello&lt;/xml&gt;
</pre>

範例 5: PHP,帶行號和突顯特定行
<pre lang="php" line="1" highlight="3">
<div id="foo">
<?php
function foo() {
echo "Hello World!\\n";
}
?>
</div>
</pre>

範例 6: PHP,帶標題(源文件或源文件的文件路徑)
<pre lang="php" src"https://github.com/shazahm1/Connections/blob/master/connections.php">
<div id="foo">
<?php
function foo() {
echo "Hello World!\\n";
}
?>
</div>
</pre><h3>支援的語言</h3>

以下是 lang 屬性中支援的主要語言列表:
abap、actionscript、actionscript3、ada、apache、applescript、apt_sources、asm、asp、autoit、avisynth、bash、bf、bibtex、blitzbasic、bnf、boo、c、c_mac、ca...

原文外掛簡介

WP-Syntax provides clean syntax highlighting using
GeSHi — supporting a wide range of popular
languages. It supports highlighting with or without line numbers and maintains formatting while copying snippets of code
from the browser.
It avoids conflicts with other 3rd party plugins by running an early
pre-filter and a late post-filter that substitutes and pulls the code snippets
out first and then pushes them back in with highlighting at the end. The
result is source code formatted and highlighted the way you intended.
Usage, Supported Languages, Styling Guidelines, and Release Notes are available
in the Other Notes section.
Want to contribute? WP-Syntax can be found on GitHub. Fork and submit your pull requests today!
Basic Usage
Wrap code blocks with

 and 

where “LANGUAGE”
is a GeSHi supported language syntax.
The line attribute is optional. More usage examples
Usage
Wrap code blocks with

 and 

where “LANGUAGE” is a GeSHi supported
language syntax. See below for a full list of supported languages.
The line attribute is optional.
Example 1: PHP, no line numbers

Example 2: Java, with line numbers

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}

Example 3: Ruby, with line numbers starting at 18

class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end

Example 4: If your code already has html entities escaped, use escaped="true" as an option

<xml>Hello</xml>

Example 5: PHP, with line numbers and highlighting a specific line

Example 6: PHP, with a caption (file and/or file path of the source file)

Supported Languages

The following languages are most supported in the lang attribute:
abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm,
asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c,
c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp,
csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang,
fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell,
hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5,
javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode
lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc,
modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml,
oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl,
php-brief, php, plsql, povray, powershell, progress, prolog, properties,
providex, python, qbasic, rails, rebol, reg, robots, ruby, sas,
scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm,
text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim,
visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf,
xpp, z80
See the GeSHi Documentation
for a full list of supported languages.
(Bold languages just highlight the more popular ones.)
Styling Guidelines
WP-Syntax colors code using the default GeSHi colors. It also uses inline
styling to make sure that code highlights still work in RSS feeds. It uses a
default wp-syntax.css stylesheet for basic layout. To customize your styling,
copy the default wp-content/plugins/wp-syntax/wp-syntax.css to your theme’s
template directory and modify it. If a file named wp-syntax.css exists in
your theme’s template directory, this stylesheet is used instead of the default.
This allows theme authors to add their own customizations as they see fit.
Advanced Customization
WP-Syntax supports a wp_syntax_init_geshi action hook to customize GeSHi
initialization settings. Blog owners can handle the hook in a hand-made plugin
or somewhere else like this:
set_brackets_style('color: #000;');
$geshi->set_keyword_group_style(1, 'color: #22f;');
}
?>

This allows for a great possibility of different customizations. Be sure to
review the GeSHi Documentation.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「WP-Syntax」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 0.5.1 | 0.5.2 | 0.5.3 | 0.5.4 | 0.6.1 | 0.9.1 | 0.9.2 | 0.9.3 | 0.9.4 | 0.9.5 | 0.9.6 | 0.9.7 | 0.9.8 | 0.9.9 | trunk | 0.9.10 | 0.9.11 | 0.9.12 | 0.9.13 |

延伸相關外掛(你可能也想知道)

  • WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager 》插入標頭和頁腳 + 完整的 WordPress 代碼片段外掛, WPCode (前稱为 WPBeginner 的 "插入標頭和頁腳")是使用率超过 100 万个网站的 WordPress 代码片段外掛中...。
  • Code Snippets 》Code Snippets 是在您的網站上運行程式碼片段的簡單,清潔和簡單的方法。它消除了將自定義片段添加到您的佈景主題的 functions.php 檔案的需求。, 現在提供 C...。
  • Simple Custom CSS Plugin 》無需麻煩地將自訂 CSS 新增到 WordPress 網站中。, 這是一個易於使用的 WordPress 外掛,可以添加自訂 CSS 樣式以覆寫外掛和佈景主題的預設樣式。該外掛旨在...。
  • Scripts n Styles 》這個外掛讓管理員用戶能夠將自訂的 CSS 和 JavaScript 直接添加到個別文章、頁面或任何註冊的自訂文章類型中,也可以將類別添加到 body 標籤和文章容器中。還...。
  • SyntaxHighlighter Evolved 》現在支援 WordPress 5.0 中的新區塊編輯器!, SyntaxHighlighter Evolved 讓您可以輕鬆地在網站上張貼帶有語法加亮功能的程式碼,而不會失去格式或做任何手動...。
  • Code Embed 》注意: WordPress 5.0 及以上版本的使用者請查看常見問題以了解如何在區塊編輯器中使用此外掛。, Code Embed 外掛允許您在文章中嵌入程式碼(JavaScript 和 H...。
  • PHP Everywhere 》注意:此外掛更新至 3.0.0 版本是一項重大變更,將移除 [php_everywhere] 短代碼和小工具。請透過外掛設定頁面中的升級嚮導,將原本的代碼轉換為 Gutenberg ...。
  • WP Coder – Powerful HTML, CSS, JS and PHP Injection 》WP Coder 是一個用於在網站添加自定義代碼的外掛程式。您可以輕鬆地將 HTML、CSS 和 JS 代碼添加到網站頁面中。此外掛程式非常適合連接各種腳本或樣式,使網...。
  • Highlighting Code Block 》「Highlighting Code Block」外掛可讓你以一個點擊的方式添加一個有語法突顯的程式碼區塊。, 它支援「區塊編輯器」和「傳統編輯器」。, (不過,我們建議在「...。
  • Code Syntax Block 》代碼語法區塊(Code Syntax Block)擴充了 WordPress 區塊編輯器,使用 Prism 語法高亮工具為核心代碼區塊添加了語法高亮支持。, Prism 語法高亮工具在前端執...。
  • Advanced CSS Editor 》Advanced CSS Editor 是一個輕量級的外掛,它讓你可以在即時編輯器中為不同設備(桌面、平板、手機)撰寫不同的 CSS 代碼,並且可以即時查看結果。, 因此,只...。
  • Machete 》Machete是一個簡單的工具套件,可以盡可能節省資源來解決常見的WordPress煩惱。Machete並不適用於每一種使用情況,但若您使用Machete,會需要較少的外掛程式...。
  • Code Widget 》Code Widget 是一個簡單的小工具,允許您插入任意的文字/HTML,執行 PHP 程式碼或 Short Code。此小工具解析 PHP 程式碼為簡單文字等等。, 只有擁有未過濾的 ...。
  • Code Block Pro – Beautiful Syntax Highlighting 》展示你美麗的程式碼,不僅僅是顯示它!這個版塊外掛提供編輯程式碼塊的功能,直接運行你的程式碼,使用與受歡迎的 VS Code 編輯器相同的渲染引擎。此外掛提供...。
  • Advance Custom HTML – Code editor block for WordPress 》這是一款用來專業編寫 HTML 代碼的高級 HTML 編輯器,提供不同的樣式、縮排與更多功能。, Advance Custom HTML 是一款功能強大、彈性十足的區塊外掛,讓您可...。

文章
Filter
Apply Filters