From 4d3890dfafc1ae7385c0a0799bfa8c669e7d2baf Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 21 Jan 2020 16:26:23 -0500 Subject: [PATCH] Do not insert spaces when unwrapping footnote text for CJK langs --- ox-blackfriday.el | 14 +++++++++++--- ox-hugo.el | 2 +- test/site/content-org/all-posts.org | 9 +++++++++ .../content/posts/multi-line-footnote-japanese.md | 9 +++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/site/content/posts/multi-line-footnote-japanese.md diff --git a/ox-blackfriday.el b/ox-blackfriday.el index 633de7e2..e21703de 100644 --- a/ox-blackfriday.el +++ b/ox-blackfriday.el @@ -121,9 +121,12 @@ INFO is a plist used as a communication channel." (concat indent "- [" title "]" "(#" anchor ")"))) ;;;; Footnote section -(defun org-blackfriday-footnote-section (info) +(defun org-blackfriday-footnote-section (info &optional is-cjk) "Format the footnote section. -INFO is a plist used as a communication channel." + +INFO is a plist used as a communication channel. +IS-CJK should be set to non-nil if the language is Chinese, +Japanese or Korean." (let ((fn-alist (org-export-collect-footnote-definitions info)) ;; Fri Jul 21 14:33:25 EDT 2017 - kmodi ;; TODO: Need to learn using cl-loop @@ -142,7 +145,12 @@ INFO is a plist used as a communication channel." ;; Support multi-line footnote definitions by folding all ;; footnote definition lines into a single line as Blackfriday ;; does not support that. - (setq def (replace-regexp-in-string "\n" " " def)) + (setq def (replace-regexp-in-string + "\n" + ;; Do not insert spaces when joining newlines for + ;; CJK languages. + (if is-cjk "" " ") + def)) ;; Replace multiple consecutive spaces with a single space. (setq def (replace-regexp-in-string "[[:blank:]]+" " " def)) (push (cons n def) fn-alist-stripped) diff --git a/ox-hugo.el b/ox-hugo.el index 4ce3fd70..e4b13ef1 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -1975,7 +1975,7 @@ holding export options." ;; Make sure CONTENTS is separated from table of contents ;; and footnotes with at least a blank line. "\n" - (org-blackfriday-footnote-section info))))) + (org-blackfriday-footnote-section info (org-hugo--lang-cjk-p info)))))) ;;;; Keyword (defun org-hugo-keyword (keyword contents info) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index fad3d00f..49f130e1 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -2600,6 +2600,12 @@ This is some text[fn:1]. :EXPORT_FILE_NAME: multi-line-footnote :END: This is some text[fn:3]. +** Multi-line footnote Japanese +:PROPERTIES: +:EXPORT_FILE_NAME: multi-line-footnote-japanese +:EXPORT_HUGO_LOCALE: ja +:END: +This is some text[fn:6]. ** Bind footnotes to the preceding word :PROPERTIES: :EXPORT_FILE_NAME: footnotes-bind-to-preceding-word @@ -7528,6 +7534,9 @@ Results from static site search implemented using /Fusejs/, /jquery/ and /mark.js/. -- [[https://gist.github.com/eddiewebb/735feb48f50f0ddd65ae5606a1cb41ae][Source]] * Footnotes +[fn:6] これは +テストです. + [fn:5] See [@thompson2016]. [fn:4] Even if the user has set the =HUGO_CODE_FENCE= value to =t= (via variable, keyword or subtree property), the Hugo =highlight= diff --git a/test/site/content/posts/multi-line-footnote-japanese.md b/test/site/content/posts/multi-line-footnote-japanese.md new file mode 100644 index 00000000..654c69cd --- /dev/null +++ b/test/site/content/posts/multi-line-footnote-japanese.md @@ -0,0 +1,9 @@ ++++ +title = "Multi-line footnote Japanese" +tags = ["footnote"] +draft = false ++++ + +This is some text[^fn:1]. + +[^fn:1]: これはテストです.