最近开始使用 org-mode 写博客,发现导出为 html 后中文之间掺杂着不少多余 的空格,对阅读有一定影响,搜索后发现该问题与 w3c 标准有关12, 属于历史遗留问题,短时间内应不会解决。
后通过学习 ox-html 源码,找到一种临时解决方法3,通过给函数
org-html-paragraph 添加 defadvice,使得导出 html 前自动将段落中的多行中文
合并为一行,且不会影响源文件,个人认为还算实用,可供参考(org-mode 8.x
下工作正常):
(defadvice org-html-paragraph (before fsh-org-html-paragraph-advice
(paragraph contents info) activate)
"Join consecutive Chinese lines into a single long line without
unwanted space when exporting org-mode to html."
(let ((fixed-contents)
(orig-contents (ad-get-arg 1))
(reg-han "[[:multibyte:]]"))
(setq fixed-contents (replace-regexp-in-string
(concat "\\(" reg-han "\\) *\n *\\(" reg-han "\\)")
"\\1\\2" orig-contents))
(ad-set-arg 1 fixed-contents)
))