[WordPress] 外掛分享: Preserve Code Formatting

首頁外掛目錄 › Preserve Code Formatting
WordPress 外掛 Preserve Code Formatting 的封面圖片
500+
安裝啟用
★★★★
4.7/5 分(3 則評價)
214 天前
最後更新
問題解決
WordPress 5.5+ v5.0 上架:2005-04-13

內容簡介

這個外掛可以保留程式碼的格式並防止 WordPress 及其他外掛修改程式碼,同時保留空格。

注意:使用視覺文字編輯器可能會有問題,因為它可能會改變您在 code 標籤方面的意圖。我強烈建議您不要在使用此外掛時使用視覺編輯器,因為我沒有努力使這兩者兼容。

注意事項:

基本上,您只需將代碼貼到 code、pre 和/或您額外指定的其他標籤中,此外掛將會:

防止 WordPress 對文本進行 HTML 編碼(單引號和雙引號不會變成彎曲形式; “–” 和 “—” 不會成為連字號和破折號, “…” 不會成為水平省略號,等等)
防止大多數其他外掛修改保留的代碼
防止處理短代碼
選擇性地保留空格(以多種方法)
選擇性地保留在評論中添加的代碼

請記住以下事項:

所有嵌入的 HTML 標籤和 HTML 實體將會以文本形式呈現,正如您編寫它們的方式一樣(包括任何 br 標籤)。
默認情況下,此外掛會過濾 ‘the_content’(文章內容)、‘the_excerpt’(文章摘要)和 ‘get_comment_text (評論內容)’。

範例:

使用 code 標籤包含以下內容的文章:

$wpdb->query("
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
");

啟用此外掛後,該文章在瀏覽器中的顯示與上述相同,而不是像下面這樣:

$wpdb->query(—
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
―);

連結: 外掛首頁 | 外掛目錄頁面 | GitHub | 作者首頁

外掛標籤

開發者團隊

⬇ 下載最新版 (v5.0) 或搜尋安裝

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

原文外掛簡介

This plugin preserves formatting of code for display by preventing its modification by WordPress and other plugins while also retaining whitespace.
NOTE: This plugin does NOT handle posts containing blocks. For such posts, use the built-in code or preformatted blocks to format your code for display. However, this plugin would still be needed if you have text-based posts from before using the blocks-based editor.
NOTE: Use of the visual text editor will pose problems as it can mangle your intent in terms of code tags. I strongly suggest you not use the visual editor in conjunction with this plugin as I have taken no effort to make the two compatible.
Notes:
Basically, you can just paste code into code, pre, and/or other tags you additionally specify and this plugin will:

Prevent WordPress from HTML-encoding text (i.e. single- and double-quotes will not become curly; “–” and “—” will not become en dash and em dash, respectively; “…” will not become a horizontal ellipsis, etc)
Prevent most other plugins from modifying preserved code
Prevent shortcodes from being processed
Optionally preserve whitespace (in a variety of methods)
Optionally preserve code added in comments

Keep these things in mind:

ALL embedded HTML tags and HTML entities will be rendered as text to browsers, appearing exactly as you wrote them (including any br tags).
By default this plugin filters ‘the_content’ (post content), ‘the_excerpt’ (post excerpt), and ‘get_comment_text (comment content)’.

Example:
A post containing this within code tags:
$wpdb->query("
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
");

Would, with this plugin enabled, look in a browser pretty much how it does above, instead of like:
$wpdb->query(—
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
―);

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

延伸相關外掛

文章
Filter
Apply Filters
Mastodon