用emacs orgmode写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
原文地址:https://www.cnblogs.com/csophys/p/2773812.html