org-export: Fix footnotes bug in ODT export
* contrib/lisp/org-export.el (org-export-as): Reorder actions taken to fix footnotes bug in ODT export.
This commit is contained in:
parent
8453ac1bf3
commit
2ff3da0f1a
|
@ -2078,58 +2078,67 @@ to be expanded and Babel code to be executed.
|
||||||
Return code as a string."
|
Return code as a string."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(save-restriction
|
(save-restriction
|
||||||
;; Narrow buffer to an appropriate region for parsing.
|
(let (info tree)
|
||||||
(cond ((org-region-active-p)
|
;; Narrow buffer to an appropriate region or subtree for
|
||||||
(narrow-to-region (region-beginning) (region-end)))
|
;; parsing. If parsing subtree, be sure to remove main
|
||||||
(subtreep (org-narrow-to-subtree)))
|
;; headline too.
|
||||||
;; Retrieve export options (INFO) and parsed tree (RAW-DATA),
|
(cond ((org-region-active-p)
|
||||||
;; Then options can be completed with tree properties. Note:
|
(narrow-to-region (region-beginning) (region-end)))
|
||||||
;; Buffer isn't parsed directly. Instead, a temporary copy is
|
(subtreep
|
||||||
;; created, where include keywords are expanded and code blocks
|
(org-narrow-to-subtree)
|
||||||
;; are evaluated. RAW-DATA is the parsed tree of the buffer
|
(goto-char (point-min))
|
||||||
;; resulting from that process. Eventually call
|
(forward-line)
|
||||||
;; `org-export-filter-parse-tree-functions'.
|
(narrow-to-region (point) (point-max))))
|
||||||
(goto-char (point-min))
|
;; 1. Get export environment and tree. Environment is
|
||||||
(let ((info (org-export-get-environment backend subtreep ext-plist))
|
;; relative to the buffer being parsed, which isn't always
|
||||||
;; Save original file name or buffer in order to properly
|
;; the original one, depending on the NOEXPAND value.
|
||||||
;; resolve babel block expansion when body is outside
|
(if noexpand
|
||||||
;; scope.
|
;; If NOEXPAND is non-nil, simply parse current visible
|
||||||
(buf (or (buffer-file-name (buffer-base-buffer)) (current-buffer))))
|
;; part of buffer and retrieve environment from original
|
||||||
;; Remove subtree's headline from contents if subtree mode is
|
;; buffer.
|
||||||
;; activated.
|
(setq info (org-export-get-environment backend subtreep ext-plist)
|
||||||
(when subtreep (forward-line) (narrow-to-region (point) (point-max)))
|
tree (org-element-parse-buffer nil visible-only))
|
||||||
;; Install filters in communication channel.
|
;; Otherwise, buffer isn't parsed directly. Instead,
|
||||||
|
;; a temporary copy is created, where include keywords are
|
||||||
|
;; expanded and code blocks are evaluated. Environment is
|
||||||
|
;; retrieved from that buffer. Moreover, save original file
|
||||||
|
;; name or buffer in order to properly resolve babel block
|
||||||
|
;; expansion when body is outside scope.
|
||||||
|
(let ((buf (or (buffer-file-name (buffer-base-buffer))
|
||||||
|
(current-buffer))))
|
||||||
|
(org-export-with-current-buffer-copy
|
||||||
|
(org-export-expand-include-keyword)
|
||||||
|
(let ((org-current-export-file buf))
|
||||||
|
(org-export-blocks-preprocess))
|
||||||
|
(setq info (org-export-get-environment backend subtreep ext-plist)
|
||||||
|
tree (org-element-parse-buffer nil visible-only)))))
|
||||||
|
;; 2. Install user's and developer's filters in communication
|
||||||
|
;; channel. Then call parse-tree filters to get the final
|
||||||
|
;; tree.
|
||||||
(setq info (org-export-install-filters backend info))
|
(setq info (org-export-install-filters backend info))
|
||||||
(let ((raw-data
|
(setq tree
|
||||||
(org-export-filter-apply-functions
|
(org-export-filter-apply-functions
|
||||||
(plist-get info :filter-parse-tree)
|
(plist-get info :filter-parse-tree) tree backend info))
|
||||||
;; If NOEXPAND is non-nil, simply parse current
|
;; 3. Now tree is complete, compute its properties and add
|
||||||
;; visible part of buffer.
|
;; them to communication channel.
|
||||||
(if noexpand (org-element-parse-buffer nil visible-only)
|
(setq info
|
||||||
(org-export-with-current-buffer-copy
|
(org-combine-plists
|
||||||
(org-export-expand-include-keyword)
|
info
|
||||||
(let ((org-current-export-file buf))
|
(org-export-collect-tree-properties tree info backend)))
|
||||||
(org-export-blocks-preprocess))
|
;; 4. Eventually transcode TREE. Wrap the resulting string
|
||||||
(org-element-parse-buffer nil visible-only)))
|
;; into a template, if required. Eventually call
|
||||||
backend info)))
|
;; final-output filter.
|
||||||
;; Complete communication channel with tree properties.
|
(let* ((body (org-element-normalize-string
|
||||||
(setq info
|
(org-export-data tree backend info)))
|
||||||
(org-combine-plists
|
(template (intern (format "org-%s-template" backend)))
|
||||||
info
|
(output (org-export-filter-apply-functions
|
||||||
(org-export-collect-tree-properties raw-data info backend)))
|
(plist-get info :filter-final-output)
|
||||||
;; Transcode RAW-DATA. Also call
|
(if (or (not (fboundp template)) body-only) body
|
||||||
;; `org-export-filter-final-output-functions'.
|
(funcall template body info))
|
||||||
(let* ((body (org-element-normalize-string
|
backend info)))
|
||||||
(org-export-data raw-data backend info)))
|
;; Maybe add final OUTPUT to kill ring, then return it.
|
||||||
(template (intern (format "org-%s-template" backend)))
|
(when org-export-copy-to-kill-ring (org-kill-new output))
|
||||||
(output (org-export-filter-apply-functions
|
output)))))
|
||||||
(plist-get info :filter-final-output)
|
|
||||||
(if (or (not (fboundp template)) body-only) body
|
|
||||||
(funcall template body info))
|
|
||||||
backend info)))
|
|
||||||
;; Maybe add final OUTPUT to kill ring, then return it.
|
|
||||||
(when org-export-copy-to-kill-ring (org-kill-new output))
|
|
||||||
output))))))
|
|
||||||
|
|
||||||
(defun org-export-to-buffer
|
(defun org-export-to-buffer
|
||||||
(backend buffer &optional subtreep visible-only body-only ext-plist noexpand)
|
(backend buffer &optional subtreep visible-only body-only ext-plist noexpand)
|
||||||
|
|
Loading…
Reference in New Issue