內容簡介
WP Markdown Syntax Sugar 可與外掛程式,例如 wp-markdown
和 wp-highlight.js 一起使用。Markdown 是一種極好的標記語言,可讓您輕鬆地撰寫部落格內容,而 highlight.js 則可輕鬆突顯程式碼範例。大多數情況下,highlight.js 會自動偵測程式碼區塊的正確語言。在某些情況下,主要是若您的程式碼範例過短,highlight.js 可能會錯誤偵測您正在使用的語言;這就是這個外掛的用途所在。透過在您的程式碼區塊加上一行,您可以明確設定您所使用的語言,從而讓 highlight.js 正確地格式化您的程式碼。
這個概念受到了 wp-markdown-syntax-highlight 外掛的啟發。
使用方法非常簡單。只需在您的程式碼範例的第一行加上 shebang,並設定您使用的語言。
#!ruby
class Foo < Bar
def hello
puts "Hello World!"
end
end
shebang 會被移除,程式碼會輸出為:
<pre><code class="language-ruby">class Foo < Bar
def hello
puts "Hello World!"
end
end</code></pre>
現在,程式碼區塊已經正確格式化,可讓 highlight.js 發揮其魔力,並正確地突顯您的程式碼片段。
外掛標籤
開發者團隊
原文外掛簡介
WP Markdown Syntax Sugar work in conjunction with plugins such as wp-markdown
and wp-highlight.js. Markdown is fantastic markup for easily
writing blogs, and highlight.js is an extremely easy way to highlight
code examples. In most cases, highlight.js automatically detects the proper language for a block of code. In certain
cases, primarily if your code example is short, highlight.js could improperly detect the language that you are using;
that is where this plugin comes into play. By adding one line to your code blocks, you can explicitly set the language
that you are using, allowing highlight.js to properly format your code.
The concept is inspired by the wp-markdown-syntax-highlight
plugin.
The usage is extremely simple. Just add a shebang as the first line of your code example with the language you are using.
#!ruby
class Foo < Bar
def hello
puts "Hello World!"
end
end
The shebang is removed, and the code is outputted as:
class Foo < Bar
def hello
puts "Hello World!"
end
end
Now the code block is properly formatted for highlight.js to do its magic, and the code snippet will be properly
highlighted.
