用emacs org-mode寫cnblogs博客(續)


 

用emacs org-mode寫cnblogs博客(續)

1 前言

前面在博文《用emacs org-mode寫cnblogs博客》中已經提到了可以使用org-mode寫完博客,然后用org-export-as-html導出網頁代碼,粘貼到博客園后台可以實現,但是還是比較麻煩的。也提到了有人使用webblogger來寫cnblogs,但是由於cnblogs使用metaweblog api,導致在使用中遇到很多問題,如博文《(未解決)使用emacs寫cnblogs1所述。不過非常非常感謝 open source,在自學elisp后寫了一個插件能夠很方便使用emacs來實現cnblogs的博文發布,更新,刪除等。真心非常感動,開源世界就是因為有你們這類人存在,才使得問題不斷地被解決,相關博文可以移步《用Emacs管理博客園博客2。下面我主要講下在使用這個插件中遇到的一些問題。

2 博客發文

首先下載了插件以后(下載鏈接) ,安裝好,填寫博客地址,賬號密碼信息。然后打開一個需要發文的org文件,打開cnblogs插件的minor模式(M-x cnblogs-minor-mode)。然后使用快捷鍵C-c c p 就發送成功了,相當的方便。刪除,更新博文也是同樣類似的操作。

3 發文中的博客代碼格式背景的問題

在書寫博客時,可以使用org自帶的 {#+BEGIN_CENTER #+END_CENTER}功能調整文字,圖片居中。使用{#+BEGIN_SRC #+END_SRC}插入代碼。但是org中的代碼顏色是使用htmlize來着色的,它可以根據當前主題背景來選擇代碼着色方案的。比如我的emacs主題是color-theme-gnome2,背景是相對偏暗的。org中的着色效果如下:

class Color_Theme extends Parent implements Interface {
    public static void main(String[] args) {
        System.out.println("這是我的代碼着色效果");
    }
    }

但是,使用cnblogs插件發文的時候其實是調用了org的一個html導出函數:org-export-as-html.在沒有任何html導出style設置的時候,他會使用org-export-html-style-default的css樣式直接嵌入導出的html中,樣式代碼如下。

(defconst org-export-html-style-default
"<style type=\"text/css\">
 <!--/*--><![CDATA[/*><!--*/
  html { font-family: Times, serif; font-size: 12pt; }
  .title  { text-align: center; }
  .todo   { color: red; }
  .done   { color: green; }
  .tag    { background-color: #add8e6; font-weight:normal }
  .target { }
  .timestamp { color: #bebebe; }
  .timestamp-kwd { color: #5f9ea0; }
  .right  {margin-left:auto; margin-right:0px;  text-align:right;}
  .left   {margin-left:0px;  margin-right:auto; text-align:left;}
  .center {margin-left:auto; margin-right:auto; text-align:center;}
  p.verse { margin-left: 3% }
  pre {
    border: 1pt solid #AEBDCC;
    background-color: #F3F5F7;
    padding: 5pt;
    font-family: courier, monospace;
        font-size: 90%;
        overflow:auto;
  }
  table { border-collapse: collapse; }
  td, th { vertical-align: top;  }
  th.right  { text-align:center;  }
  th.left   { text-align:center;   }
  th.center { text-align:center; }
  td.right  { text-align:right;  }
  td.left   { text-align:left;   }
  td.center { text-align:center; }
  dt { font-weight: bold; }
  div.figure { padding: 0.5em; }
  div.figure p { text-align: center; }
  div.inlinetask {
    padding:10px;
    border:2px solid gray;
    margin:10px;
    background: #ffffcc;
  }
  textarea { overflow-x: auto; }
  .linenr { font-size:smaller }
  .code-highlighted {background-color:#ffff00;}
  .org-info-js_info-navigation { border-style:none; }
  #org-info-js_console-label { font-size:10px; font-weight:bold;
                               white-space:nowrap; }
  .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
                                 font-weight:bold; }
  /*]]>*/-->
</style>"
  "The default style specification for exported HTML files.
Please use the variables `org-export-html-style' and
`org-export-html-style-extra' to add to this style.  If you wish to not
have the default style included, customize the variable
`org-export-html-style-include-default'.")

這段代碼可以在emacs的主目錄/lisp/org/org-html.el中找到,可以看到其中對於代碼着色的背景pre塊是設置死了的。而這個背景是偏淡色的,這樣就導致了最終導出的博文代碼着色效果非常糟糕,看不清楚。 解決方法原理: org中的代碼導出是有變量org-export-html-style-default,org-export-html-style-include-default,org-export-html-style等控制的,其中后面兩個變量可以customize.如果org-export-html-style-include-default變量為真(默認為真),那么org就會使用default-style,再疊加上org-export-html-style成為最終的css樣式。(cnblogs中還要加上網頁中的css設置)。 所以我的方案是設置org-export-html-style的值為:

<style type="text/css">
  pre {
    background-color: #2f4f4f;line-height: 1.6;
  FONT: 10.5pt Consola,"Bitstream Vera Sans", Courier New, helvetica;
  color:wheat;
  }
</style>

4 結束語

OK~。emacs寫到這里就C-c c p推送了,網頁立馬更新。。。非常流暢,再次感謝Open_Source博友所做的貢獻(PS.才剛研究,還不知道怎么讓博文推送到指定的分類以及博文的置頂,置首頁操作)

Date: 2012-11-16 19:29:29 中國標准時間

Author: csophys

Org version 7.8.11 with Emacs version 24

Validate XHTML 1.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM