用emacs org-mode写cnblogs博客(续)

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
""
  "The default style specification for exported HTML files.
Please use the variables </span><span>org-export-html-style</span><span>&apos; and</span>
<span>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>

Original: https://www.cnblogs.com/csophys/archive/2012/11/16/2773812.html
Author: csophys
Title: 用emacs org-mode写cnblogs博客(续)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/715297/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球