
內容簡介
在您的內容中以時尚的方式顯示您的程式碼片段。此外,該外掛程式還使用短代碼和直觀的 TinyMCE 介面。
Code Snippet DM 受到專案 Carbon 的啟發。
我們創建了一種簡單的方式來顯示您的程式碼片段,同時也可以控制其外觀,從而使其更時尚。
此外,在前端的右上角,您會發現一個「複製程式碼」按鈕,可讓您複製整個程式碼片段到剪貼板。
該外掛程式提供了一個 TinyMCE 按鈕,允許您顯示代碼或使用短代碼的選項。
您可以開啟短代碼 [dm_code_snippet],在內容中加入程式碼,並關閉它 [/dm_code_snippet]。
從版本2.0.1開始,該外掛程式提供支援用於自定義的 Gutenberg 區塊。它將繼續支援通過短代碼添加程式碼片段的默認方式。
Gutenberg 區塊
該區塊名稱為「Code Snippet DM」,可在 Gutenberg 區塊的嵌入區找到。可用於搜尋的關鍵字:code、snippet、dm。
一旦在 Gutenberg 編輯器中添加了該區塊,就可以通過出現在每個區塊旁邊的側邊欄設置進行自定義。側邊欄將包括所有可用於短代碼的設置。其中一些設置將實時應用於您的編輯器中。
代碼樣式(語法突顯)僅在前端可用,在編輯器中,您將無法預覽代碼的正確顏色。
短代碼選項
您可以在短代碼中使用許多選項:
背景,帶有「yes」或「no」選項,將啟用/禁用顏色背景(默認「yes」)
background-mobile,帶有「yes」或「no」選項,將啟用/禁用移動設備的顏色背景(默認「yes」)
bg-color,接受任何 HEX、RGB 或 RGBA 值來更改背景顏色(默認為 #abb8c3)
主題,帶有「light」或「dark」選項,可更改代碼編輯器主題(默認「dark」)
瘦身,帶有「yes」或「no」選項,可將代碼編輯器從默認設置更改為精簡版本,非常適合單行程式碼(默認為「no」)
行數,帶有「yes」或「no」選項,將為列啟用左側行數(默認「no」)
語言,帶有「clike」、「css」、「javascript」、「markup」、「perl」、「php」、「python」、「ruby」、「sql」、「typescript」和「shell」選項,將基於您為代碼選擇的內容突顯語法(默認為「php」)
包裹,帶有「yes」或「no」選項,將包裝程式碼或添加水平捲動條以顯示它的格式(默認為「no」)
高度,允許您輸入任何值,並將代碼片段高度設置為該值。例如:500px。(默認為空白)
copy-text,這用於複製按鈕上顯示的文本。如果未添加,它將使用默認選項。(默認為「Copy Code」)
copy-confirmed,這用於單擊複製按鈕後顯示的文本。如果未添加,它將使用默認選項。(默認為「Copied」)
短代碼的示例:
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="light" language="css" wrapped="no" height="500px" copy-text="Get the Code!" copy-confirmed="You have it!"]<pre>
.dm-code-snippet.dark {
background: $default-bg;
padding: 40px 35px 45px 35px;
margin: 30px 0;
}</pre>
[/dm_code_snippet]
重要提示:
* 如果您直接使用短代碼,請確保像上面的示例一樣在程式碼中包裝 <pre></pre>。
* 如果您想使用短代碼添加 HTML,請確保在您的程式碼中使用實體字符(例如:<、>),以避免短代碼被解析。
外掛標籤
開發者團隊
原文外掛簡介
Supports: Gutenberg, Elementor, TinyMCE and shortcode
Display your code snippets in a stylish way inside your content. The plugin uses shortcodes and also very intuitive TinyMCE interface.
Starting with v2.0.3, the plugin offers support to be used via a custom Elementor Widget.
Starting with v2.0.1, the plugin offers support to be used via a custom Gutenberg block.
It will continue to support the default way of adding the code snippet via shotcodes.
Code Snippet DM was inspired by the Carbon project.
We created a simple way to display your code snippets but also have control over the way it appears, thus making it more stylish.
Also, on the front end in the top right you will find a Copy Code button that allows you to copy to clipboard the entired code snippet.
The plugin provides you with a TinyMCE button that will allow you to display the code or an option to use a shortcode.
You can open the shorcode [dm_code_snippet] and in the content inside and close it [/dm_code_snippet].
Elementor widget
The Widget is called “Code Snippet DM” and can be found on the Basic list of Elementor Widget after you activate the plugin. Keywords that can be used to find it: code, snippet, dm.
Once the widget is added in the Elementor editor, it can be customized via the sidebar settings that will appear for each widget. The sidebar will include all the settings that are available for the shortcode. Some of the settings will be applied in real time in your editor.
The code styling (syntax highlight) and line numbers are only available on the front-end, in the editor you will not be able to preview the correct colors for the code or the line numbers.
Gutenberg block
The block is called “Code Snippet DM” and can be found in the embed section of Gutenberg blocks. Keywords that can be used to find it: code, snippet, dm.
Once the block is added in the Gutenberg editor, it can be customized via the sidebar settings that will appear for each block. The sidebar will include all the settings that are available for the shortcode. Some of the settings will be applied in real time in your editor.
The code styling (syntax highlight) and line numbers are only available on the front-end, in the editor you will not be able to preview the correct colors for the code or the line numbers.
Shortcode Options
There are a number of options that you can use in the shortcode:
background with options yes or no will enable/disable the color background (Default yes)
background-mobile with options yes or no will enable/disable the color background for mobile devices (Default yes)
bg-color accepts any HEX, RGB or RGBA value to change the background color (Default #abb8c3)
theme with options light or dark that changes the code editor theme (Default dark)
slim with options yes or no that changes the code editor from default to a slim version, ideal for one-line code (Default no)
line-numbers with options yes or no that will enable a left side line number for columns (Default no)
language with options clike, css, javascript, markup, perl, php, python, ruby, sql, typescript, shell will highlight the syntaxes based on what you select for your code (Default php)
wrap with options yes or no will wrap the code or add a horizontal scroll bar to display it as it is (Default no)
height allows you to input any value and will set the code snippet height to that value. Example: 500px. (Default is empty)
copy-text this is used for the text shown on the copy button. If it’s not added it will use the default option. (Default Copy Code)
copy-confirmed this is used for the text shown after you click the copy button. If it’s not added it will use the default option. (Default Copied)
Example of shortcode:
[dm_code_snippet background="yes" background-mobile="yes" slim="no" line-numbers="no" bg-color="#abb8c3" theme="light" language="css" wrapped="no" height="500px" copy-text="Get the Code!" copy-confirmed="You have it!"]
.dm-code-snippet.dark {
background: $default-bg;
padding: 40px 35px 45px 35px;
margin: 30px 0;
}
[/dm_code_snippet]
Important:
* If you use the shortcode directly, make sure to wrap the code in
as in the example above.
* If you want to add HTML using the shortcode, you’ll need to escape the HTML before pasting it in the shortcode. (You can easily find an escape tool online to convert the code)
* If you have code (not HTML) that uses ‘’ and you add it with the shortcode and not the and the TinyMCE button, you will need to escape ‘’ from your code in order to properly display it.
Use the TinyMCE button if you don’t want to add the shortcode yourself. (see Screenshots)
