
內容簡介
這個外掛擴展了 WordPress 核心的程式碼塊,以添加在伺服器上呈現的語法突顯。現有的網站上的程式碼塊會自動擴展,以包含語法突顯。使用伺服器端的語法突顯消除了前端需要引用任何 JavaScript(例如 Highlight.js 或 Prism.js),這確保沒有未突出顯示的程式碼閃爍問題(FOUC?)。減少前端的腳本可以提高前端性能,並且使語法突顯的程式碼在由官方 AMP 外掛(參見ampproject/amp-wp#972)或在瀏覽器中關閉 JavaScript 時正確顯示在 AMP 頁面中。
除了不在前端添加任何 JavaScript 外,用於樣式設計程式碼塊所需的樣式表只有在存在程式碼塊時才會添加到頁面中。當渲染代碼塊時,樣式表是在內部添加的,確保它們不會阻止較高的內容呈現。如果樣式表因任何原因無法加載,則該塊只會呈現而沒有樣式,但有一個關鍵例外:高亮顯示的行將標記在mark元素中,因此它們將會被突顯顯示,包括在 RSS 源和通過電子郵件同步的帖子中(只要客戶端支援mark元素)。
這個擴展的程式碼塊使用語言自動檢測來添加語法突顯,但你可以在塊的設置側邊欄中覆蓋語言(當前編輯器不支持在程式碼塊中突顯語法)。該外掛支持highlight.php支持的所有程式語言(作為highlight.js的一個端口)。代碼塊還擴展以支持指定上述高亮顯示的行。也有一個選框用於在前端顯示行號(數字不可選擇)。最後,由於主題中的程式碼塊是否應包含在內的不一致性,此外掛會添加樣式來強制使它們默認為不包裝,而當需要包裝時則可以選擇此選框。
有關進階使用,請參閱外掛的Wiki頁面。
此外掛在GitHub上進行開發。請參閱外掛的目前問題列表。請隨時提交任何其他問題或請求。欲提交拉取請求,歡迎你的參與。
致謝
這是Code Syntax Block的分支,由Marcus Kazmierczak(mkaz)開發。版權所有(c)2018 Marcus Kazmierczak。根據 GPL 2.0 或更高版本許可。
highlight.php的發布根據 BSD 3-Clause 許可,版權所有 ©2006-2013、Ivan Sagalaev([email protected])、highlight.js(原始作者)。版權所有 ©2013、Geert Bergman([email protected])、highlight.php。
外掛標籤
開發者團隊
② 後台搜尋「Syntax-highlighting Code Block (with Server-side Rendering)」→ 直接安裝(推薦)
📦 歷史版本下載
原文外掛簡介
This plugin extends the Code block in WordPress core to add syntax highlighting which is rendered on the server. Pre-existing Code blocks on a site are automatically extended to include syntax highlighting. Doing server-side syntax highlighting eliminates the need to enqueue any JavaScript on the frontend (e.g. Highlight.js or Prism.js) and this ensures there is no flash of unhighlighted code (FOUC?). Reducing script on the frontend improves frontend performance, and it also allows for the syntax highlighted code to appear properly in AMP pages as rendered by the official AMP plugin (see also ampproject/amp-wp#972) or when JavaScript is turned off in the browser.
This extended Code block uses language auto-detection to add syntax highlighting, but you can override the language in the block’s settings sidebar. (There is currently no syntax highlighting of the Code block in the editor, but see #8.) The plugin supports all programming languages that highlight.php supports (being a port of highlight.js). The Code block also is extended to support specifying lines to highlight which get marked up with mark elements (including in RSS feeds). There is also a checkbox for whether to show line numbers on the frontend (with the numbers being non-selectable). Lastly, given inconsistencies across themes regarding whether lines in a Code block should be wrapped, this plugin adds styling to force them to no-wrap by default, with a checkbox to opt in to wrapping when desired.
For advanced usage, please see the plugin wiki.
This plugin is developed on GitHub. See list of current issues with the plugin. Please feel free to file any additional issues or requests that you may come across. Pull requests are welcome. See contributing information.
Credits
This is a fork of Code Syntax Block by Marcus Kazmierczak (mkaz), which is also available on WordPress.org. Copyright (c) 2018 Marcus Kazmierczak. Licensed under GPL 2.0 or later.
highlight.php is released under the BSD 3-Clause License. Copyright © 2006-2013, Ivan Sagalaev ([email protected]), highlight.js (original author). Copyright © 2013, Geert Bergman ([email protected]), highlight.php
