发现 org2blog 发布时调用 doom-emacs 里 chinese 模块的过滤器出错

今天发文一直发不出去,百思不得其解,打开 debug 跟踪一下,发现是调用了 doom-emacs 里 chinese 模块的过滤器出错,改用 spacemacs chinese layer 里的代码可以修复此问题(需要禁用 doom-emacs 里的 chinese module)。当然只禁用掉 chinese module 也可以,不过这段代码是在转换为网页时,把自动换行的空白符去掉,这样发布后的网页不会多一些莫名奇妙的空格。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(defadvice org-html-paragraph (before 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* ((origin-contents (ad-get-arg 1))
         (fix-regexp "[[:multibyte:]]")
         (fixed-contents
          (replace-regexp-in-string
           (concat
            "\\(" fix-regexp "\\) *\n *\\(" fix-regexp "\\)") "\\1\\2" origin-contents)))
    (ad-set-arg 1 fixed-contents)))

**8 月 8 日更新** 使用如下代码彻底解决此问题:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
(defadvice! +chinese--org-html-paragraph-a (args)
  "Join consecutive Chinese lines into a single long line without
unwanted space when exporting org-mode to html."
  :filter-args #'org-html-paragraph
  (cl-destructuring-bind (paragraph content info) args
    (let* ((fix-regexp "[[:multibyte:]a-zA-Z0-9]")
           (origin-contents content)
           (fixed-contents
            (replace-regexp-in-string
             (concat "\\("
                     fix-regexp
                     "\\) *\\(<[Bb][Rr] */>\\)?\n *\\("
                     fix-regexp
                     "\\)")
             "\\1\\3"
             origin-contents)))
      (list paragraph fixed-contents info))))

**8 月 31 日更新** 上述代码也有 Bug,也就是两边全是英文字符时有不能替换,更新 advice 代码(同时也向 doom-emacs 提交 PR):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
(defadvice! +chinese--org-html-paragraph-a (args)
  "Join consecutive Chinese lines into a single long line without
unwanted space when exporting org-mode to html."
  :filter-args #'org-html-paragraph
  (cl-destructuring-bind (paragraph content info) args
    (let* ((fix-regexp "[[:multibyte:]]")
           (origin-contents
            (replace-regexp-in-string
             "<[Bb][Rr] */>"
             ""
             content))
           (fixed-contents
            (replace-regexp-in-string
             (concat "\\(" fix-regexp "\\) *\n *\\(" fix-regexp "\\)")
             "\\1\\2"
             origin-contents)))
      (list paragraph fixed-contents info))))
Licensed under CC BY-NC-SA 4.0
最后更新于 Sep 08, 2019 03:25 +0800
comments powered by Disqus
墩墩家的幸福生活
Built with Hugo
主题 StackJimmy 设计