forked from mirrors/org-mode
org-export: Export snippets are not skipped automatically: back-ends decide
* contrib/lisp/org-export.el (org-export-snippet-backend): New function. (org-export--skip-p): Remove automatic skip of export snippets. * EXPERIMENTAL/org-e-ascii.el (org-e-ascii-export-snippet): Use new function. * EXPERIMENTAL/org-e-html.el (org-e-html-export-snippet): Use new function. * EXPERIMENTAL/org-e-latex.el (org-e-latex-export-snippet): Use new function. * EXPERIMENTAL/org-e-odt.el (org-e-odt-export-snippet): Use new function. * testing/contrib/lisp/test-org-export.el: Add test. The idea behind this change is that a given back-end may decide to keep an export snippet not directly targetted at it (i.e. a beamer back-end that would want to keep latex snippets). Hence, filtering snippets is on back-ends side, and a new function is added to help them in that task.
This commit is contained in:
parent
8714fba308
commit
0fa24209cf
|
@ -1101,7 +1101,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
|||
(defun org-e-ascii-export-snippet (export-snippet contents info)
|
||||
"Transcode a EXPORT-SNIPPET object from Org to ASCII.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(org-element-property :value export-snippet))
|
||||
(when (eq (org-export-snippet-backend export-snippet) 'e-ascii)
|
||||
(org-element-property :value export-snippet)))
|
||||
|
||||
|
||||
;;;; Export Block
|
||||
|
|
|
@ -2187,7 +2187,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
|||
(defun org-e-html-export-snippet (export-snippet contents info)
|
||||
"Transcode a EXPORT-SNIPPET object from Org to HTML.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(org-element-property :value export-snippet))
|
||||
(when (eq (org-export-snippet-backend export-snippet) 'e-html)
|
||||
(org-element-property :value export-snippet)))
|
||||
|
||||
|
||||
;;;; Export Block
|
||||
|
|
|
@ -972,7 +972,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
|||
(defun org-e-latex-export-snippet (export-snippet contents info)
|
||||
"Transcode a EXPORT-SNIPPET object from Org to LaTeX.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(org-element-property :value export-snippet))
|
||||
(when (eq (org-export-snippet-backend export-snippet) 'e-latex)
|
||||
(org-element-property :value export-snippet)))
|
||||
|
||||
|
||||
;;;; Export Block
|
||||
|
|
|
@ -3911,7 +3911,8 @@ CONTENTS is nil. INFO is a plist holding contextual information."
|
|||
(defun org-e-odt-export-snippet (export-snippet contents info)
|
||||
"Transcode a EXPORT-SNIPPET object from Org to HTML.
|
||||
CONTENTS is nil. INFO is a plist holding contextual information."
|
||||
(org-element-property :value export-snippet))
|
||||
(when (eq (org-export-snippet-backend export-snippet) 'e-odt)
|
||||
(org-element-property :value export-snippet)))
|
||||
|
||||
|
||||
;;;; Export Block
|
||||
|
|
|
@ -1433,15 +1433,7 @@ OPTIONS is the plist holding export options."
|
|||
(or (not (plist-get options :with-drawers))
|
||||
(and (consp (plist-get options :with-drawers))
|
||||
(not (member (org-element-property :drawer-name blob)
|
||||
(plist-get options :with-drawers))))))
|
||||
;; Check export snippet.
|
||||
(export-snippet
|
||||
(let* ((raw-back-end (org-element-property :back-end blob))
|
||||
(true-back-end
|
||||
(or (cdr (assoc raw-back-end org-export-snippet-translation-alist))
|
||||
raw-back-end)))
|
||||
(not (string= (symbol-name (plist-get options :back-end))
|
||||
true-back-end))))))
|
||||
(plist-get options :with-drawers))))))))
|
||||
|
||||
|
||||
|
||||
|
@ -2421,6 +2413,24 @@ file should have."
|
|||
;; macros, references, src-blocks, tables and tables of contents are
|
||||
;; implemented.
|
||||
|
||||
;;;; For Export Snippets
|
||||
|
||||
;; Every export snippet is transmitted to the back-end. Though, the
|
||||
;; latter will only retain one type of export-snippet, ignoring
|
||||
;; others, based on the former's target back-end. The function
|
||||
;; `org-export-snippet-backend' returns that back-end for a given
|
||||
;; export-snippet.
|
||||
|
||||
(defun org-export-snippet-backend (export-snippet)
|
||||
"Return EXPORT-SNIPPET targeted back-end as a symbol.
|
||||
Translation, with `org-export-snippet-translation-alist', is
|
||||
applied."
|
||||
(let ((back-end (org-element-property :back-end export-snippet)))
|
||||
(intern
|
||||
(or (cdr (assoc back-end org-export-snippet-translation-alist))
|
||||
back-end))))
|
||||
|
||||
|
||||
;;;; For Footnotes
|
||||
|
||||
;; `org-export-collect-footnote-definitions' is a tool to list
|
||||
|
|
|
@ -24,9 +24,6 @@
|
|||
|
||||
;;; Tests
|
||||
|
||||
(require 'org-test)
|
||||
(require 'org-export)
|
||||
|
||||
(defmacro org-test-with-backend (backend &rest body)
|
||||
"Execute body with an export back-end defined.
|
||||
|
||||
|
@ -237,3 +234,16 @@ text
|
|||
(forward-line 3)
|
||||
(mark-paragraph)
|
||||
(should (equal (org-export-as 'test) "text\n")))))
|
||||
|
||||
(ert-deftest test-org-export/export-snippet ()
|
||||
"Test export snippets transcoding."
|
||||
(org-test-with-temp-text "@test{A}@t{B}"
|
||||
(org-test-with-backend "test"
|
||||
(flet ((org-test-export-snippet
|
||||
(snippet contents info)
|
||||
(when (eq (org-export-snippet-backend snippet) 'test)
|
||||
(org-element-property :value snippet))))
|
||||
(let ((org-export-snippet-translation-alist nil))
|
||||
(should (equal (org-export-as 'test) "A\n")))
|
||||
(let ((org-export-snippet-translation-alist '(("t" . "test"))))
|
||||
(should (equal (org-export-as 'test) "AB\n")))))))
|
||||
|
|
Loading…
Reference in New Issue