You can try the below config :-)




(defun eh-org-wash-text (text backend _info)
  "导出 org file 时,删除中文之间不必要的空格。"
  (when (or (org-export-derived-backend-p backend 'html)
            (org-export-derived-backend-p backend 'odt))
    (let ((regexp "[[:multibyte:]]")
          (string text))
      ;; org-mode 默认将一个换行符转换为空格,但中文不需要这个空格,删除。
      (setq string
            (replace-regexp-in-string
             (format "\\(%s\\) *\n *\\(%s\\)" regexp regexp)
             "\\1\\2" string))
      ;; 删除粗体之后的空格
      (dolist (str '("</b>" "</code>" "</del>" "</i>"))
        (setq string
              (replace-regexp-in-string
               (format "\\(%s\\)\\(%s\\)[ ]+\\(%s\\)" regexp str regexp)
               "\\1\\2\\3" string)))
      ;; 删除粗体之前的空格
      (dolist (str '("<b>" "<code>" "<del>" "<i>" "<span class=\"underline\">"))
        (setq string
              (replace-regexp-in-string
               (format "\\(%s\\)[ ]+\\(%s\\)\\(%s\\)" regexp str regexp)
               "\\1\\2\\3" string)))
      string)))

(add-hook 'org-export-filter-headline-functions #'eh-org-wash-text)
(add-hook 'org-export-filter-paragraph-functions #'eh-org-wash-text)













在 2021-06-29 11:47:06,"James Harkins" <jamshar...@zoho.com> 写道:
>Consider the following org document.
>
>* Test
>1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证
>书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关
>要求办理离校手续,领取相关证书后离校;
>
>This was produced by pasting in a single, long line, and then using alt-Q (a 
>normal thing to do, and good for readability, because org-mode doesn't wrap 
>lines by default).
>
>Exporting to ODT produces the following (body text, omitting titles, headers 
>and such).
>
>1本人不想亲自拿到学历学位证书、急于离校者,可书面委托他人代领学历学位证 书,29日起即可离校;2本人想亲自领取学历学位证书者,按学校规定的程序及有关 
>要求办理离校手续,领取相关证书后离校;
>
>Between 证 and 书, and between 关 and 要, there is a space. Chinese typography 
>does not allow for spaces mid-sentence.
>
>So, it would make sense to add a rule to the exporter: if one of the 
>characters before or after a source-text line break is a Chinese, Japanese or 
>Korean character, do not add a space. (The space is valid, of course, if the 
>characters on either side of the line breaks are Roman or [I would guess] 
>Cyrillic as well.)
>
>(Side note: Exporting to a LaTeX buffer shows that the line breaks have been 
>copied into the .tex document as is -- but, provided that you have a 
>`usepackage{xeCJK}` in the preamble, LaTeX produces correct, space-free 
>output. So -- Org "gets away with it" because of LaTeX's handling of CJK text. 
>It seems for ODT, Org needs to handle the spacing within its own logic.)
>
>This is org 9.1.9... bit old, I know, but I'm gonna take a wild guess that 
>this has not been a high-visibility issue.
>
>hjh

Reply via email to