From 0fa24209cf2f2e1443f856c958a8b858c3e8a8f6 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 23 Feb 2012 18:10:14 +0100 Subject: [PATCH] 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. --- EXPERIMENTAL/org-e-ascii.el | 3 ++- EXPERIMENTAL/org-e-html.el | 3 ++- EXPERIMENTAL/org-e-latex.el | 3 ++- EXPERIMENTAL/org-e-odt.el | 3 ++- contrib/lisp/org-export.el | 28 +++++++++++++++++-------- testing/contrib/lisp/test-org-export.el | 16 +++++++++++--- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/EXPERIMENTAL/org-e-ascii.el b/EXPERIMENTAL/org-e-ascii.el index aa4be5fdc..fbf8bd80a 100644 --- a/EXPERIMENTAL/org-e-ascii.el +++ b/EXPERIMENTAL/org-e-ascii.el @@ -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 diff --git a/EXPERIMENTAL/org-e-html.el b/EXPERIMENTAL/org-e-html.el index 2cfb8280e..8f5544fb2 100644 --- a/EXPERIMENTAL/org-e-html.el +++ b/EXPERIMENTAL/org-e-html.el @@ -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 diff --git a/EXPERIMENTAL/org-e-latex.el b/EXPERIMENTAL/org-e-latex.el index 35561cfb5..86bf71c31 100644 --- a/EXPERIMENTAL/org-e-latex.el +++ b/EXPERIMENTAL/org-e-latex.el @@ -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 diff --git a/EXPERIMENTAL/org-e-odt.el b/EXPERIMENTAL/org-e-odt.el index 3437a5e8c..81e2a9b05 100644 --- a/EXPERIMENTAL/org-e-odt.el +++ b/EXPERIMENTAL/org-e-odt.el @@ -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 diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index e857af048..6937bf284 100644 --- a/contrib/lisp/org-export.el +++ b/contrib/lisp/org-export.el @@ -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 diff --git a/testing/contrib/lisp/test-org-export.el b/testing/contrib/lisp/test-org-export.el index 20640d1f9..8e878002e 100644 --- a/testing/contrib/lisp/test-org-export.el +++ b/testing/contrib/lisp/test-org-export.el @@ -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")))))))