From d6f0e9e105009fd197f52dc5b755d59748d6f986 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 3 Oct 2021 23:51:43 +0200 Subject: [PATCH] oc: Be stricter when introducing spaces before citations * lisp/oc.el (org-cite-process-citations): Add a space before citation only if it is preceded by a quotation mark. * testing/lisp/test-oc.el (test-org-cite/export-capability): Add tests. Reported-by: Denis Maier --- lisp/oc.el | 10 ++++++---- testing/lisp/test-oc.el | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lisp/oc.el b/lisp/oc.el index fd80ba9dc..ac8cafb96 100644 --- a/lisp/oc.el +++ b/lisp/oc.el @@ -1274,11 +1274,13 @@ by side-effect." ;; Before removing the citation, transfer its `:post-blank' ;; property to the object before, if any. (org-cite--set-previous-post-blank cite blanks info) - ;; We want to be sure any non-note citation is preceded by - ;; a space. This is particularly important when using + ;; Make sure there is a space between a quotation mark and + ;; a citation. This is particularly important when using ;; `adaptive' note rule. See `org-cite-note-rules'. - (unless (org-cite-inside-footnote-p cite t) - (org-cite--set-previous-post-blank cite 1 info)) + (let ((previous (org-export-get-previous-element cite info))) + (when (and (org-string-nw-p previous) + (string-suffix-p "\"" previous)) + (org-cite--set-previous-post-blank cite 1 info))) (pcase replacement ;; String. ((pred stringp) diff --git a/testing/lisp/test-oc.el b/testing/lisp/test-oc.el index fc90a2146..995559b9c 100644 --- a/testing/lisp/test-oc.el +++ b/testing/lisp/test-oc.el @@ -1273,7 +1273,7 @@ arguments. Replace citation with \"@\" character in the output." (list "b" (org-element-create 'bold nil "c"))) " "))))) -;;; TEST capabilities. +;;; Test capabilities. (ert-deftest test-org-cite/activate-capability () "Test \"activate\" capability." ;; Standard test. @@ -1393,6 +1393,29 @@ arguments. Replace citation with \"@\" character in the output." '((section . (lambda (_ c _) c)) (paragraph . (lambda (_ c _) c)) (bold . (lambda (&rest _) "bold"))))))))) + ;; Make sure to have a space between a quote and a citation. + (should + (equal "\"quotation\" citation\n" + (org-test-with-temp-text "\"quotation\"[cite:@key]" + (let ((org-cite--processors nil) + (org-cite-export-processors '((t . (foo nil nil))))) + (org-cite-register-processor 'foo + :export-citation (lambda (&rest _) "citation")) + (org-export-as (org-export-create-backend + :transcoders + '((section . (lambda (_ c _) c)) + (paragraph . (lambda (_ c _) c))))))))) + (should + (equal "\"quotation\" citation\n" + (org-test-with-temp-text "\"quotation\" [cite:@key]" + (let ((org-cite--processors nil) + (org-cite-export-processors '((t . (foo nil nil))))) + (org-cite-register-processor 'foo + :export-citation (lambda (&rest _) "citation")) + (org-export-as (org-export-create-backend + :transcoders + '((section . (lambda (_ c _) c)) + (paragraph . (lambda (_ c _) c))))))))) ;; Regular bibliography export. (should (eq 'success