[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 4c646a6 03/14: ox: Introduce "raw" pseudo objects

From: ELPA Syncer
Subject: [elpa] externals/org 4c646a6 03/14: ox: Introduce "raw" pseudo objects
Date: Fri, 9 Jul 2021 02:57:16 -0400 (EDT)

branch: externals/org
commit 4c646a6bdeba1a5a55fdb78991c009e46853618b
Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Commit: Nicolas Goaziou <mail@nicolasgoaziou.fr>

    ox: Introduce "raw" pseudo objects
    * lisp/ox.el (org-export-raw-string): New function
    (org-export-with-backend): React to raw objects.
    * testing/lisp/test-ox.el (test-org-export/raw-string): New test.
    A raw object is a pseudo-object (i.e., special object type that exists
    only during export) with the property of being exported as-is, with no
    processing from an export back-end.
    It is particularly useful to add contents to, or pre-process objects
    from, a parse tree.
 lisp/ox.el              | 18 ++++++++++++++++--
 testing/lisp/test-ox.el | 11 +++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 6ec9b62..af7626b 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1881,6 +1881,8 @@ Return a string."
                 ;; Ignored element/object.
                 ((memq data (plist-get info :ignore-list)) nil)
+                 ;; Raw code.
+                 ((eq type 'raw) (car (org-element-contents data)))
                 ;; Plain text.
                 ((eq type 'plain-text)
@@ -1947,7 +1949,7 @@ Return a string."
            ((not results) "")
-           ((memq type '(org-data plain-text nil)) results)
+           ((memq type '(nil org-data plain-text raw)) results)
            ;; Append the same white space between elements or objects
            ;; as in the original buffer, and call appropriate filters.
@@ -3668,7 +3670,8 @@ the communication channel used for export, as a plist."
   (when (symbolp backend) (setq backend (org-export-get-backend backend)))
   (org-export-barf-if-invalid-backend backend)
   (let ((type (org-element-type data)))
-    (when (memq type '(nil org-data)) (error "No foreign transcoder 
+    (when (memq type '(nil org-data raw))
+      (error "No foreign transcoder available"))
     (let* ((all-transcoders (org-export-get-all-transcoders backend))
           (transcoder (cdr (assq type all-transcoders))))
       (unless (functionp transcoder) (error "No foreign transcoder available"))
@@ -4562,6 +4565,17 @@ objects of the same type."
            ((funcall predicate el info) (cl-incf counter) nil)))
         info 'first-match)))))
+;;;; For Raw objects
+;; `org-export-raw-string' builds a pseudo-object out of a string
+;; that any export back-end returns as-is.
+(defun org-export-raw-string (s)
+  "Return a raw object containing string S.
+A raw string is exported as-is, with no additional processing
+from the export back-end."
+  (unless (stringp s) (error "Wrong raw contents type: %S" s))
+  (org-element-create 'raw nil s))
 ;;;; For Src-Blocks
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index 34b2d20..3f39645 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -3812,6 +3812,17 @@ Another text. (ref:text)
            (org-export-data-with-backend paragraph backend nil)))))
+;;; Raw objects
+(ert-deftest test-org-export/raw-strings ()
+  "Test exporting raw objects."
+  (should
+   (equal "foo"
+          (let ((backend (org-export-create-backend))
+                (object (org-export-raw-string "foo")))
+            (org-export-data-with-backend object backend nil)))))
 ;;; Src-block and example-block
 (ert-deftest test-org-export/unravel-code ()

reply via email to

[Prev in Thread] Current Thread [Next in Thread]