forked from mirrors/org-mode
ox: Fix export of uninterpreted elements
* lisp/ox.el (org-export-data): Do not check for uninterpreted elements or objects. These are removed from parse tree anyway. (org-export--remove-uninterpreted): New function. (org-export--interpret-p): Removed function. (org-export-as): Handle uninterpreted elements and objects.
This commit is contained in:
parent
b44fbb920c
commit
86eb0afe05
93
lisp/ox.el
93
lisp/ox.el
|
@ -2170,10 +2170,8 @@ a tree with a select tag."
|
||||||
;; Internally, three functions handle the filtering of objects and
|
;; Internally, three functions handle the filtering of objects and
|
||||||
;; elements during the export. In particular,
|
;; elements during the export. In particular,
|
||||||
;; `org-export-ignore-element' marks an element or object so future
|
;; `org-export-ignore-element' marks an element or object so future
|
||||||
;; parse tree traversals skip it, `org-export--interpret-p' tells which
|
;; parse tree traversals skip it and `org-export-expand' transforms
|
||||||
;; elements or objects should be seen as real Org syntax and
|
;; the others back into their original shape.
|
||||||
;; `org-export-expand' transforms the others back into their original
|
|
||||||
;; shape
|
|
||||||
;;
|
;;
|
||||||
;; `org-export-transcoder' is an accessor returning appropriate
|
;; `org-export-transcoder' is an accessor returning appropriate
|
||||||
;; translator function for a given element or object.
|
;; translator function for a given element or object.
|
||||||
|
@ -2208,16 +2206,6 @@ Return transcoded string."
|
||||||
(let ((transcoder (org-export-transcoder data info)))
|
(let ((transcoder (org-export-transcoder data info)))
|
||||||
(if transcoder (funcall transcoder data info) data))
|
(if transcoder (funcall transcoder data info) data))
|
||||||
info))
|
info))
|
||||||
;; Uninterpreted element/object: change it back to Org
|
|
||||||
;; syntax and export again resulting raw string.
|
|
||||||
((not (org-export--interpret-p data info))
|
|
||||||
(org-export-data
|
|
||||||
(org-export-expand
|
|
||||||
data
|
|
||||||
(mapconcat (lambda (blob) (org-export-data blob info))
|
|
||||||
(org-element-contents data)
|
|
||||||
""))
|
|
||||||
info))
|
|
||||||
;; Secondary string.
|
;; Secondary string.
|
||||||
((not type)
|
((not type)
|
||||||
(mapconcat (lambda (obj) (org-export-data obj info)) data ""))
|
(mapconcat (lambda (obj) (org-export-data obj info)) data ""))
|
||||||
|
@ -2315,31 +2303,67 @@ recursively convert DATA using BACKEND translation table."
|
||||||
;; will probably be used on small trees.
|
;; will probably be used on small trees.
|
||||||
:exported-data (make-hash-table :test 'eq :size 401)))))
|
:exported-data (make-hash-table :test 'eq :size 401)))))
|
||||||
|
|
||||||
(defun org-export--interpret-p (blob info)
|
(defun org-export--remove-uninterpreted (data info)
|
||||||
"Non-nil if element or object BLOB should be interpreted during export.
|
"Change uninterpreted elements back into Org syntax.
|
||||||
If nil, BLOB will appear as raw Org syntax. Check is done
|
DATA is the parse tree. INFO is a plist containing export
|
||||||
according to export options INFO, stored as a plist."
|
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-element-map data
|
||||||
|
'(entity bold italic latex-environment latex-fragment strike-through
|
||||||
|
subscript superscript underline)
|
||||||
|
#'(lambda (blob)
|
||||||
|
(let ((new
|
||||||
(case (org-element-type blob)
|
(case (org-element-type blob)
|
||||||
;; ... entities...
|
;; ... entities...
|
||||||
(entity (plist-get info :with-entities))
|
(entity (and (not (plist-get info :with-entities))
|
||||||
|
(list (org-export-expand blob nil))))
|
||||||
;; ... emphasis...
|
;; ... emphasis...
|
||||||
((bold italic strike-through underline)
|
((bold italic strike-through underline)
|
||||||
(plist-get info :with-emphasize))
|
(and (not (plist-get info :with-emphasize))
|
||||||
;; ... fixed-width areas.
|
(let ((marker (case (org-element-type blob)
|
||||||
(fixed-width (plist-get info :with-fixed-width))
|
(bold "*")
|
||||||
|
(italic "/")
|
||||||
|
(strike-through "+")
|
||||||
|
(underline "_"))))
|
||||||
|
(append
|
||||||
|
(list marker)
|
||||||
|
(org-element-contents blob)
|
||||||
|
(list (concat
|
||||||
|
marker
|
||||||
|
(make-string
|
||||||
|
(or (org-element-property :post-blank blob)
|
||||||
|
0)
|
||||||
|
?\s)))))))
|
||||||
;; ... LaTeX environments and fragments...
|
;; ... LaTeX environments and fragments...
|
||||||
((latex-environment latex-fragment)
|
((latex-environment latex-fragment)
|
||||||
(let ((with-latex-p (plist-get info :with-latex)))
|
(and (eq (plist-get info :with-latex) 'verbatim)
|
||||||
(and with-latex-p (not (eq with-latex-p 'verbatim)))))
|
(list (org-export-expand blob nil))))
|
||||||
;; ... sub/superscripts...
|
;; ... sub/superscripts...
|
||||||
((subscript superscript)
|
((subscript superscript)
|
||||||
(let ((sub/super-p (plist-get info :with-sub-superscript)))
|
(let ((sub/super-p (plist-get info :with-sub-superscript))
|
||||||
(if (eq sub/super-p '{})
|
(bracketp (org-element-property :use-brackets-p blob)))
|
||||||
(org-element-property :use-brackets-p blob)
|
(and (or (not sub/super-p)
|
||||||
sub/super-p)))
|
(and (eq sub/super-p '{}) bracketp))
|
||||||
;; ... tables...
|
(append
|
||||||
(table (plist-get info :with-tables))
|
(list (concat
|
||||||
(otherwise t)))
|
(if (eq (org-element-type blob) 'subscript)
|
||||||
|
"_"
|
||||||
|
"^")
|
||||||
|
(and bracketp "{")))
|
||||||
|
(org-element-contents blob)
|
||||||
|
(list (concat
|
||||||
|
(and bracketp "}")
|
||||||
|
(make-string
|
||||||
|
(or (org-element-property :post-blank blob) 0)
|
||||||
|
?\s))))))))))
|
||||||
|
(when new
|
||||||
|
;; Splice NEW at BLOB location in parse tree.
|
||||||
|
(dolist (e new) (org-element-insert-before e blob))
|
||||||
|
(org-element-extract-element blob))))
|
||||||
|
info)
|
||||||
|
;; Return modified parse tree.
|
||||||
|
data)
|
||||||
|
|
||||||
(defun org-export-expand (blob contents &optional with-affiliated)
|
(defun org-export-expand (blob contents &optional with-affiliated)
|
||||||
"Expand a parsed element or object to its original state.
|
"Expand a parsed element or object to its original state.
|
||||||
|
@ -3082,11 +3106,14 @@ Return code as a string."
|
||||||
(dolist (filter (plist-get info :filter-options))
|
(dolist (filter (plist-get info :filter-options))
|
||||||
(let ((result (funcall filter info backend-name)))
|
(let ((result (funcall filter info backend-name)))
|
||||||
(when result (setq info result)))))
|
(when result (setq info result)))))
|
||||||
;; Parse buffer and call parse-tree filter on it.
|
;; Parse buffer, handle uninterpreted elements or objects,
|
||||||
|
;; then call parse-tree filters.
|
||||||
(setq tree
|
(setq tree
|
||||||
(org-export-filter-apply-functions
|
(org-export-filter-apply-functions
|
||||||
(plist-get info :filter-parse-tree)
|
(plist-get info :filter-parse-tree)
|
||||||
(org-element-parse-buffer nil visible-only) info))
|
(org-export--remove-uninterpreted
|
||||||
|
(org-element-parse-buffer nil visible-only) info)
|
||||||
|
info))
|
||||||
;; Now tree is complete, compute its properties and add them
|
;; Now tree is complete, compute its properties and add them
|
||||||
;; to communication channel.
|
;; to communication channel.
|
||||||
(setq info
|
(setq info
|
||||||
|
|
Loading…
Reference in New Issue