ox: Fix uninterpreted objects in TITLE property

* lisp/ox.el (org-export-remove-uninterpreted-data): Renamed from
  `org-export--remove-uninterpreted'.
(org-export--remove-uninterpreted-data-1): New function.
(org-export-as): Use new function.
* testing/lisp/test-ox.el (test-org-export/uninterpreted): Add test.
This commit is contained in:
Nicolas Goaziou 2013-12-26 12:23:27 +01:00
parent 39c936584a
commit c0aa83bf41
2 changed files with 44 additions and 11 deletions

View File

@ -2303,12 +2303,25 @@ recursively convert DATA using BACKEND translation table."
;; will probably be used on small trees.
:exported-data (make-hash-table :test 'eq :size 401)))))
(defun org-export--remove-uninterpreted (data info)
(defun org-export-remove-uninterpreted-data (data info)
"Change uninterpreted elements back into Org syntax.
DATA is the parse tree. INFO is a plist containing export
options. Each uninterpreted element or object is changed back
into a string. Contents, if any, are not modified. The parse
tree is modified by side effect and returned by the function."
(org-export--remove-uninterpreted-data-1 data info)
(dolist (prop '(:author :date :title))
(plist-put info
prop
(org-export--remove-uninterpreted-data-1
(plist-get info prop)
info))))
(defun org-export--remove-uninterpreted-data-1 (data info)
"Change uninterpreted elements back into Org syntax.
DATA is a parse tree or a secondary string. INFO is a plist
containing export options. It is modified by side effect and
returned by the function."
(org-element-map data
'(entity bold italic latex-environment latex-fragment strike-through
subscript superscript underline)
@ -2316,8 +2329,13 @@ tree is modified by side effect and returned by the function."
(let ((new
(case (org-element-type blob)
;; ... entities...
(entity (and (not (plist-get info :with-entities))
(list (org-export-expand blob nil))))
(entity
(and (not (plist-get info :with-entities))
(list (concat
(org-export-expand blob nil)
(make-string
(or (org-element-property :post-blank blob) 0)
?\s)))))
;; ... emphasis...
((bold italic strike-through underline)
(and (not (plist-get info :with-emphasize))
@ -2354,9 +2372,10 @@ tree is modified by side effect and returned by the function."
(org-element-contents blob)
(list (concat
(and bracketp "}")
(make-string
(or (org-element-property :post-blank blob) 0)
?\s))))))))))
(and (org-element-property :post-blank blob)
(make-string
(org-element-property :post-blank blob)
?\s)))))))))))
(when new
;; Splice NEW at BLOB location in parse tree.
(dolist (e new) (org-element-insert-before e blob))
@ -3099,6 +3118,11 @@ Return code as a string."
(cons "email" (or (plist-get info :email) ""))
(cons "title"
(org-element-interpret-data (plist-get info :title)))))
;; Parse buffer.
(setq tree (org-element-parse-buffer nil visible-only))
;; Handle left-over uninterpreted elements or objects in
;; parse tree and communication channel.
(org-export-remove-uninterpreted-data tree info)
;; Call options filters and update export options. We do not
;; use `org-export-filter-apply-functions' here since the
;; arity of such filters is different.
@ -3110,10 +3134,7 @@ Return code as a string."
;; then call parse-tree filters.
(setq tree
(org-export-filter-apply-functions
(plist-get info :filter-parse-tree)
(org-export--remove-uninterpreted
(org-element-parse-buffer nil visible-only) info)
info))
(plist-get info :filter-parse-tree) tree info))
;; Now tree is complete, compute its properties and add them
;; to communication channel.
(setq info

View File

@ -656,7 +656,19 @@ Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
:transcoders '((subscript . (lambda (s c i) "dummy"))
(paragraph . (lambda (p c i) c))
(section . (lambda (s c i) c))))
nil nil nil '(:with-sub-superscript {}))))))
nil nil nil '(:with-sub-superscript {})))))
;; Also handle uninterpreted objects in title.
(should
(equal "a_b"
(org-test-with-temp-text "#+TITLE: a_b"
(org-export-as
(org-export-create-backend
:transcoders
'((subscript . (lambda (s c i) "dummy"))
(template . (lambda (c i) (org-export-data
(plist-get i :title) i)))
(section . (lambda (s c i) c))))
nil nil nil '(:with-sub-superscript nil))))))
(ert-deftest test-org-export/export-scope ()
"Test all export scopes."