summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2021-04-18 19:32:27 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2021-07-09 08:47:14 +0200
commit4c646a6bdeba1a5a55fdb78991c009e46853618b (patch)
tree45b1748ec7d6b7f077aab499951ae2c32c5b49d7
parentfed07be5b81afe07b00c61768c82cbfec7b0fe03 (diff)
downloadorg-mode-4c646a6bdeba1a5a55fdb78991c009e46853618b.tar.gz
ox: Introduce "raw" pseudo objects
* lisp/ox.el (org-export-raw-string): New function (org-export-data): (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.
-rw-r--r--lisp/ox.el18
-rw-r--r--testing/lisp/test-ox.el11
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."
(cond
;; 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)
(org-export-filter-apply-functions
@@ -1947,7 +1949,7 @@ Return a string."
data
(cond
((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.
(t
@@ -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 available"))
+ (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 ()