Merge branch 'bugfix'

This commit is contained in:
Nicolas Goaziou 2021-11-03 16:29:59 +01:00
commit 498a76857b
3 changed files with 58 additions and 5 deletions

View File

@ -119,11 +119,7 @@ If \"natbib\" package is already required in the document, e.g., through
(defun org-cite-natbib--build-optional-arguments (citation info) (defun org-cite-natbib--build-optional-arguments (citation info)
"Build optional arguments for citation command. "Build optional arguments for citation command.
CITATION is the citation object. INFO is the export state, as a property list." CITATION is the citation object. INFO is the export state, as a property list."
(let* ((origin (pcase (org-cite-get-references citation) (pcase-let ((`(,prefix . ,suffix) (org-cite-main-affixes citation)))
(`(,reference) reference)
(_ citation)))
(suffix (org-element-property :suffix origin))
(prefix (org-element-property :prefix origin)))
(concat (and prefix (format "[%s]" (org-trim (org-export-data prefix info)))) (concat (and prefix (format "[%s]" (org-trim (org-export-data prefix info))))
(cond (cond
(suffix (format "[%s]" (org-trim (org-export-data suffix info)))) (suffix (format "[%s]" (org-trim (org-export-data suffix info))))

View File

@ -638,6 +638,24 @@ in the current buffer. Positions include leading \"@\" character."
(re-search-forward org-element-citation-key-re end t) (re-search-forward org-element-citation-key-re end t)
(cons (match-beginning 0) (match-end 0))))) (cons (match-beginning 0) (match-end 0)))))
(defun org-cite-main-affixes (citation)
"Return main affixes for CITATION object.
Some export back-ends only support a single pair of affixes per
citation, even if it contains multiple keys. This function
decides what affixes are the most appropriate.
Return a pair (PREFIX . SUFFIX) where PREFIX and SUFFIX are
parsed data."
(let ((source
;; When there are multiple references, use global affixes.
;; Otherwise, local affixes have priority.
(pcase (org-cite-get-references citation)
(`(,reference) reference)
(_ citation))))
(cons (org-element-property :prefix source)
(org-element-property :suffix source))))
(defun org-cite-supported-styles (&optional processors) (defun org-cite-supported-styles (&optional processors)
"List of supported citation styles and variants. "List of supported citation styles and variants.

View File

@ -251,6 +251,45 @@
(car boundaries) (car boundaries)
(cdr boundaries))))))) (cdr boundaries)))))))
(ert-deftest test-org-cite/main-affixes ()
"Test`org-cite-main-affixes'."
(should
(equal '(nil . nil)
(org-test-with-temp-text "[cite:@key]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(nil . nil)
(org-test-with-temp-text "[cite:@key1;@key2]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(("pre ") . nil)
(org-test-with-temp-text "[cite:pre @key]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(("pre ") . (" post"))
(org-test-with-temp-text "[cite:pre @key post]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(("pre ") . nil)
(org-test-with-temp-text "[cite:global pre;pre @key]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(nil . (" post"))
(org-test-with-temp-text "[cite:@key post;global post]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(("global pre") . ("global post"))
(org-test-with-temp-text "[cite:global pre;@key1;@key2;global post]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(("global pre") . nil)
(org-test-with-temp-text "[cite:global pre;pre1 @key1;pre2 @key2]"
(org-cite-main-affixes (org-element-context)))))
(should
(equal '(nil . ("global post"))
(org-test-with-temp-text "[cite:@key1 post1;@key2 post2; global post]"
(org-cite-main-affixes (org-element-context))))))
(ert-deftest test-org-cite/supported-styles () (ert-deftest test-org-cite/supported-styles ()
"Test `org-cite-supported-styles'." "Test `org-cite-supported-styles'."
;; Default behavior is to use export processors. ;; Default behavior is to use export processors.