Use Emacs, Org2blog to Publish WordPress Blogs with Crayon Highlight Support

Posted by:

The WORKING version for the new version of org2blog with Emacs 26

Preamble

Org2blog is THE best tool to publish from org-mode to WordPress. There is a very good blog in Chinese in addition to the official site.

Dependencies

org2blog is depending on the following:

  1. xml-rpc, metaweblog and htmlize.
  2. Org mode version should be 7 8 or higher. And I just updated to org-mode 9 with Emacs 26.

My setting for org2blog

Syntax Highlight

org2blog 有两种方式实现代码高亮:

  1. Set org2blog/wp-use-sourcecode-shortcode to nil, org-mode exports the sourcecode with <pre> with the help of htmlize.el and uploads the html to WordPress.
  2. Set org2blog/wp-use-sourcecode-shortcode to non-nil, org-mode exports the sourcecode with [sourcecode] with the help of htmlize.el and uploads the html to WordPress.
  3. UPDATE: The sourcecode prefix only works with SyntaxHighlighter Evolved – WordPress plugin, but it does not serve my need due to its poor babel language support. Also, all my post was using Crayon Syntax Highlighter (working with pre prefix), so I managed to modified the code to this direction.
  4. Possible conflict with htmlizer EmacsWiki: Htmlize.

    htmlize.el has some conflicts with rainbow-delimiters-mode, functions such as htmlize-buffer will report an error: htmlize-make-face-map: Wrong type argument: listp, “rainbow-delimiters-depth-1-face”, so I do a small hack to overcome this by using the elisp’s defadvice utility.

    Here’s the code:

To make it work with Crayon Syntax Highlighter

UPDATE: The following is invalid no more. See the next section for solution. 代码显示设置,如果设置成nil,就会把org-mode的SRC代码块用pre标签包括起 来,设置成t的话,就会用sourcecode标签来包括起来。默认是nil,也就是使 用pre标签,使用pre标签的话,可能会额外添加一些html标签,严重影响显示效 果, sourcecode标签又不被crayon支持,为了使二者结合起来,我这边修改了 一下org2blog的源文件: 在 ox-wp.el中修改 sourcecode标签为对应的crayon 格式的 <pre>标签即可. Also Mentioned here.

from:

to (close up with < before /pre>):

The code from this site did NOT work with crayon highlight for me.

The WORKING version for the new version of org2blog with Emacs 26

All I need to do is to copy the code here into my dot-emacs init file, of course on top of general setting for org2blog. I removed figure tag.

You may need to play with the crayon highlight setting in WordPress. Here is what I have.

crayon-highlight.png

0
  Related Posts

Add a Comment