在Blog顯示程式碼區塊的方法–使用Google Code Prettify

參考 https://github.com/google/code-prettify 的說明,實作後簡單紀錄如下 :

1. 設定
點選 [版面配置] >> [新增小工具] >> 新增 [HTML/JavaScrip] >> 輸入以下script代碼 >> [儲存]
(這個小工具可置於版面任何位置,都不影響其功能)
如圖 :


設定[HTML/javaScript] 的代碼如下 :
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?"></script>

2. 使用
進入文章或網頁的HTML頁籤,在程式碼前後放入pre,如下 :
<pre class="prettyprint">
<!--這裡就可以放程式碼了...-->
</pre>

3. 範例展示
private voiddataGridView1_RowPostPaint(object sender,DataGridViewRowPostPaintEventArgs e)
{
    if((dataGridView1.Rows[e.RowIndex].Cells["mySeq"].Value).ToString() == "")
        dataGridView1.Rows[e.RowIndex].Cells["mySeq"].Value = e.RowIndex + 1;
    else
        return;
}

參考資料: https://github.com/google/code-prettify

Read More »
>