2021年2月4日 星期四

code prettify 在blogger中加入code block

code prettify test
ref: https://github.com/googlearchive/code-prettify
the service side has been updated, need to change some code in 






sample coode:
<span class="tag">&lt;pre</span><span class="pln"> </span><span class="atn">class</span><span class="pun">=</span><span class="atv">"prettyprint linenums lang-sh"</span><span class="tag">&gt;</span><span class="pln">$ sudo apt install smbclient
$ sudo smbclient -L $IP -W $domainName -U $userName
</span><span class="tag">&lt;/pre&gt;</span>
  • use <xmp> </xmp> to escape html code
  • lang-* is optional, may auto detect
  • linenums:x shows the line numbers, x is the starting line
  1. class Voila {
  2. public:
  3. // Voila
  4. static const string VOILA = "Voila";
  5.  
  6. // will not interfere with embedded tags.
  7. }
by <pre> ...</pre>
  1. int main()
  2. {
  3. int a = 0;
  4. return 0;
  5. }
by <code> .... </code>
  1. int main()
  2. {
  3.     int a = 0;
  4.     return 0;
  5. }

用法
<pre class="prettyprint lang-cpp linenums">...</pre>
<code class="prettyprint">...</code>
用 <pre> 在html中直接換行輸出的結果就會有換行的效果,在<code>中則需要用<br />之類的方式換行
如果再compose mode中打好了code, 可以切到HTMLmode後直接加上 <code></code>較容易

支援的語言
lang-*: "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java","js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml","xsl".

1 則留言: