summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-31 11:28:21 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-10-31 12:21:16 (GMT)
commit32c34560209bd03e955b44a4b9c1d5feccdaebf9 (patch)
tree66cc476a20a4224c5b545e854330168961e498a0
parent32a6bae7c0ff83ec0f30e7c89886701dfa3f015b (diff)
downloadorg-mode-32c34560209bd03e955b44a4b9c1d5feccdaebf9.zip
org-mode-32c34560209bd03e955b44a4b9c1d5feccdaebf9.tar.gz
org-export: Fix previous/next element finding in secondary strings
* contrib/lisp/org-export.el (org-export-get-previous-element, org-export-get-next-element): Correctly retrieve previous and next object, if any, in secondary strings. * testing/lisp/test-org-export.el: Add tests.
-rw-r--r--contrib/lisp/org-export.el27
-rw-r--r--testing/lisp/test-org-export.el77
2 files changed, 99 insertions, 5 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index f70aa28..2e28c0d 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -4463,7 +4463,19 @@ object, a string, or nil."
(cond ((eq obj blob) (throw 'exit prev))
((memq obj (plist-get info :ignore-list)))
(t (setq prev obj))))
- (org-element-contents (org-export-get-parent blob))))))
+ ;; An object can belong to the contents of its parent or
+ ;; to a secondary string. We check the latter option
+ ;; first.
+ (let ((parent (org-export-get-parent blob)))
+ (or (and (not (memq (org-element-type blob)
+ org-element-all-elements))
+ (let ((sec-value
+ (org-element-property
+ (cdr (assq (org-element-type parent)
+ org-element-secondary-value-alist))
+ parent)))
+ (and (memq blob sec-value) sec-value)))
+ (org-element-contents parent)))))))
(defun org-export-get-next-element (blob info)
"Return next element or object.
@@ -4474,7 +4486,18 @@ object, a string, or nil."
(mapc (lambda (obj)
(unless (memq obj (plist-get info :ignore-list))
(throw 'found obj)))
- (cdr (memq blob (org-element-contents (org-export-get-parent blob)))))
+ ;; An object can belong to the contents of its parent or to
+ ;; a secondary string. We check the latter option first.
+ (let ((parent (org-export-get-parent blob)))
+ (or (and (not (memq (org-element-type blob)
+ org-element-all-objects))
+ (let ((sec-value
+ (org-element-property
+ (cdr (assq (org-element-type parent)
+ org-element-secondary-value-alist))
+ parent)))
+ (cdr (memq blob sec-value))))
+ (cdr (memq blob (org-element-contents parent))))))
nil))
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index f938dff..719548f 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -1251,7 +1251,34 @@ Another text. (ref:text)
(org-element-map
tree 'plain-text
(lambda (s) (org-export-activate-smart-quotes s :html info))
- info))))))
+ info)))))
+ ;; Smart quotes in secondary strings.
+ (should
+ (equal '("&ldquo;" "&rdquo;")
+ (let ((org-export-default-language "en"))
+ (org-test-with-parsed-data "* \"$x$\""
+ (org-element-map
+ tree 'plain-text
+ (lambda (s) (org-export-activate-smart-quotes s :html info))
+ info)))))
+ ;; Smart quotes in document keywords.
+ (should
+ (equal '("&ldquo;" "&rdquo;")
+ (let ((org-export-default-language "en"))
+ (org-test-with-parsed-data "#+TITLE: \"$x$\""
+ (org-element-map
+ (plist-get info :title) 'plain-text
+ (lambda (s) (org-export-activate-smart-quotes s :html info))
+ info)))))
+ ;; Smart quotes in parsed affiliated keywords.
+ (should
+ (equal '("&ldquo;" "&rdquo;" "Paragraph")
+ (let ((org-export-default-language "en"))
+ (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
+ (org-element-map
+ tree 'plain-text
+ (lambda (s) (org-export-activate-smart-quotes s :html info))
+ info nil nil t))))))
@@ -1817,7 +1844,29 @@ Another text. (ref:text)
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
(org-export-get-next-element
- (org-element-map tree 'entity 'identity info t) info)))))
+ (org-element-map tree 'entity 'identity info t) info))))
+ ;; Find next element in secondary strings.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "* a =verb="
+ (org-element-type
+ (org-export-get-next-element
+ (org-element-map tree 'plain-text 'identity info t) info)))))
+ ;; Find next element in document keywords.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "#+TITLE: a =verb="
+ (org-element-type
+ (org-export-get-next-element
+ (org-element-map
+ (plist-get info :title) 'plain-text 'identity info t) info)))))
+ ;; Find next element in parsed affiliated keywords.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
+ (org-element-type
+ (org-export-get-next-element
+ (org-element-map tree 'plain-text 'identity info t nil t) info))))))
(ert-deftest test-org-export/get-previous-element ()
"Test `org-export-get-previous-element' specifications."
@@ -1837,7 +1886,29 @@ Another text. (ref:text)
(let ((org-export-with-timestamps nil))
(org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
(org-export-get-previous-element
- (org-element-map tree 'entity 'identity info t) info)))))
+ (org-element-map tree 'entity 'identity info t) info))))
+ ;; Find previous element in secondary strings.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "* =verb= a"
+ (org-element-type
+ (org-export-get-previous-element
+ (org-element-map tree 'plain-text 'identity info t) info)))))
+ ;; Find previous element in document keywords.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "#+TITLE: =verb= a"
+ (org-element-type
+ (org-export-get-previous-element
+ (org-element-map
+ (plist-get info :title) 'plain-text 'identity info t) info)))))
+ ;; Find previous element in parsed affiliated keywords.
+ (should
+ (eq 'verbatim
+ (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
+ (org-element-type
+ (org-export-get-previous-element
+ (org-element-map tree 'plain-text 'identity info t nil t) info))))))
(provide 'test-org-export)