2014年1月28日 星期二

[C/C++]如何在網頁上顯示程式碼及在Ubuntu上編譯C語言

在google的blog左側邊欄找到 "範本" 點進去
找到 "編輯HTML" 點進去
然後會看到一堆HTML的code
找到</head>
在</head>之前插入以下的程式碼

<!-- begin syntax hightlight -->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeEmacs.css' rel='stylesheet' type='text/css'/>

<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js"></script>
<script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script>
<script src='http://www.undermyhat.org/blog/wp-content/uploads/2009/09/shBrushMatlabSimple.js' type='text/javascript'></script>

<script language='javascript'>
    SyntaxHighlighter.config.bloggerMode = false;
    SyntaxHighlighter.config.stripBrs = true;
    SyntaxHighlighter.defaults['wrap-lines'] = false;
    SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
    SyntaxHighlighter.all();
</script>
<!-- end syntax hightlight -->


改好以後儲存
之後再利用這個網頁
http://www.opinionatedgeek.com/DotNet/Tools/HTMLEncode/Encode.aspx
把你想要的程式碼透過這個網頁去encode
再貼回自己的blog
再切到HTML編輯模式
把<pre class="brush:c">放在最前面
把<\pre>放在最後面
就OK了


如果想要測試自己的C code寫的對不對,可以利用Ubuntu去編譯
只要有安裝gcc
在指令列輸入如下
gcc -o test test.c
就可以產生test執行檔去看輸出結果了

reference:
http://blog.lupopi.com/2013/02/blogger-source-code-syntax-highlight.html

沒有留言:

張貼留言