Open Live Writer中写博客,如何代码语法高亮

记得从前还是Windows Live Writer的时候,有很多插件,可以直接美化代码的。现在这些插件都找不到了。只好尝试用点别的办法。


先打开这个网站,把自己想要放到博客里的代码段放进去,生成带有语法高亮的HTML片段。

http://hilite.me/


比如,我想放下面的一段Python代码:

public class HelloWorld {
     public static void main(String[] args) {
         System.out.println("Hello World");
     }
}


生成了下面的一段HTML。

<pre class="java" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorld <span style="color: #009900;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">    <span style="color: #009900;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span></div></li></ol></pre>


打开Source的显示面板,粘贴进去,效果如下:


  1. public class HelloWorld {
  2. public static void main(String[] args) {
  3. System.out.println("Hello World");
  4. }
  5. }

效果不错!

posted on 2025-06-23 15:45  中道学友  阅读(7)  评论(0)    收藏  举报

导航

技术追求准确,态度积极向上