forked from mirrors/org-mode
ox: Factorize export properties
* lisp/ox.el (org-export-get-environment): Do not handle :back-end and :translate-alist. (org-export--collect-tree-properties): Do not handle :exported-data. (org-export--get-export-attributes): New function. (org-export-as): Use new function. * testing/lisp/test-ox.el (org-test-with-parsed-data): Use new function.
This commit is contained in:
parent
f329279757
commit
b414b85a7c
58
lisp/ox.el
58
lisp/ox.el
|
@ -1336,10 +1336,7 @@ inferior to file-local settings."
|
||||||
;; ... from in-buffer settings...
|
;; ... from in-buffer settings...
|
||||||
(org-export--get-inbuffer-options backend)
|
(org-export--get-inbuffer-options backend)
|
||||||
;; ... and from subtree, when appropriate.
|
;; ... and from subtree, when appropriate.
|
||||||
(and subtreep (org-export--get-subtree-options backend))
|
(and subtreep (org-export--get-subtree-options backend))))
|
||||||
;; Eventually add misc. properties.
|
|
||||||
(list :back-end backend
|
|
||||||
:translate-alist (org-export-get-all-transcoders backend))))
|
|
||||||
|
|
||||||
(defun org-export--parse-option-keyword (options &optional backend)
|
(defun org-export--parse-option-keyword (options &optional backend)
|
||||||
"Parse an OPTIONS line and return values as a plist.
|
"Parse an OPTIONS line and return values as a plist.
|
||||||
|
@ -1537,6 +1534,20 @@ Assume buffer is in Org mode. Narrowing, if any, is ignored."
|
||||||
s (replace-regexp-in-string "\n" " " s))))
|
s (replace-regexp-in-string "\n" " " s))))
|
||||||
(setq plist (plist-put plist p value)))))))
|
(setq plist (plist-put plist p value)))))))
|
||||||
|
|
||||||
|
(defun org-export--get-export-attributes
|
||||||
|
(&optional backend subtreep visible-only body-only)
|
||||||
|
"Return properties related to export process, as a plist.
|
||||||
|
Optional arguments BACKEND, SUBTREEP, VISIBLE-ONLY and BODY-ONLY
|
||||||
|
are like the arguments with the same names of function
|
||||||
|
`org-export-as'."
|
||||||
|
(list :export-options (delq nil
|
||||||
|
(list (and subtreep 'subtree)
|
||||||
|
(and visible-only 'visible-only)
|
||||||
|
(and body-only 'body-only)))
|
||||||
|
:back-end backend
|
||||||
|
:translate-alist (org-export-get-all-transcoders backend)
|
||||||
|
:exported-data (make-hash-table :test #'eq :size 4001)))
|
||||||
|
|
||||||
(defun org-export--get-buffer-attributes ()
|
(defun org-export--get-buffer-attributes ()
|
||||||
"Return properties related to buffer attributes, as a plist."
|
"Return properties related to buffer attributes, as a plist."
|
||||||
(list :input-buffer (buffer-name (buffer-base-buffer))
|
(list :input-buffer (buffer-name (buffer-base-buffer))
|
||||||
|
@ -1636,9 +1647,6 @@ is a list holding export options.
|
||||||
|
|
||||||
Following tree properties are set or updated:
|
Following tree properties are set or updated:
|
||||||
|
|
||||||
`:exported-data' Hash table used to memoize results from
|
|
||||||
`org-export-data'.
|
|
||||||
|
|
||||||
`:headline-offset' Offset between true level of headlines and
|
`:headline-offset' Offset between true level of headlines and
|
||||||
local level. An offset of -1 means a headline
|
local level. An offset of -1 means a headline
|
||||||
of level 2 should be considered as a level
|
of level 2 should be considered as a level
|
||||||
|
@ -1659,24 +1667,18 @@ Return updated plist."
|
||||||
(plist-put info
|
(plist-put info
|
||||||
:headline-offset
|
:headline-offset
|
||||||
(- 1 (org-export--get-min-level data info))))
|
(- 1 (org-export--get-min-level data info))))
|
||||||
;; Properties order doesn't matter: get the rest of the tree
|
;; From now on, properties order doesn't matter: get the rest of the
|
||||||
;; properties.
|
;; tree properties.
|
||||||
(setq info
|
(org-combine-plists
|
||||||
(plist-put info
|
info
|
||||||
:headline-numbering
|
(list :headline-numbering (org-export--collect-headline-numbering data info)
|
||||||
(org-export--collect-headline-numbering data info)))
|
:id-alist
|
||||||
(setq info
|
(org-element-map data 'link
|
||||||
(plist-put info
|
(lambda (l)
|
||||||
:exported-data (make-hash-table :test #'eq :size 4001)))
|
(and (string= (org-element-property :type l) "id")
|
||||||
(plist-put info
|
(let* ((id (org-element-property :path l))
|
||||||
:id-alist
|
(file (car (org-id-find id))))
|
||||||
;; Collect id references.
|
(and file (cons id (file-relative-name file))))))))))
|
||||||
(org-element-map data 'link
|
|
||||||
(lambda (l)
|
|
||||||
(and (string= (org-element-property :type l) "id")
|
|
||||||
(let* ((id (org-element-property :path l))
|
|
||||||
(file (car (org-id-find id))))
|
|
||||||
(and file (cons id (file-relative-name file)))))))))
|
|
||||||
|
|
||||||
(defun org-export--get-min-level (data options)
|
(defun org-export--get-min-level (data options)
|
||||||
"Return minimum exportable headline's level in DATA.
|
"Return minimum exportable headline's level in DATA.
|
||||||
|
@ -2948,11 +2950,7 @@ Return code as a string."
|
||||||
;; attributes, unavailable in its copy.
|
;; attributes, unavailable in its copy.
|
||||||
(let* ((org-export-current-backend (org-export-backend-name backend))
|
(let* ((org-export-current-backend (org-export-backend-name backend))
|
||||||
(info (org-combine-plists
|
(info (org-combine-plists
|
||||||
(list :export-options
|
(org-export--get-export-attributes)
|
||||||
(delq nil
|
|
||||||
(list (and subtreep 'subtree)
|
|
||||||
(and visible-only 'visible-only)
|
|
||||||
(and body-only 'body-only))))
|
|
||||||
(org-export--get-buffer-attributes)))
|
(org-export--get-buffer-attributes)))
|
||||||
(parsed-keywords
|
(parsed-keywords
|
||||||
(delq nil
|
(delq nil
|
||||||
|
|
|
@ -46,7 +46,9 @@ variable, and communication channel under `info'."
|
||||||
`(org-test-with-temp-text ,data
|
`(org-test-with-temp-text ,data
|
||||||
(org-export--delete-comments)
|
(org-export--delete-comments)
|
||||||
(let* ((tree (org-element-parse-buffer))
|
(let* ((tree (org-element-parse-buffer))
|
||||||
(info (org-export-get-environment)))
|
(info (org-combine-plists
|
||||||
|
(org-export--get-export-attributes)
|
||||||
|
(org-export-get-environment))))
|
||||||
(org-export--prune-tree tree info)
|
(org-export--prune-tree tree info)
|
||||||
(org-export--remove-uninterpreted-data tree info)
|
(org-export--remove-uninterpreted-data tree info)
|
||||||
(let ((info (org-combine-plists
|
(let ((info (org-combine-plists
|
||||||
|
|
Loading…
Reference in New Issue