From 3f5ae4df8ab3b54283b2f119eef4631101b6d752 Mon Sep 17 00:00:00 2001 From: Yujie Wen Date: Sun, 13 Feb 2022 22:00:35 +0800 Subject: [PATCH] Fixed #472. Read plugin scripts in single file mode --- ox-reveal.el | 114 +++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 59 deletions(-) diff --git a/ox-reveal.el b/ox-reveal.el index c3d4ce1..879e030 100644 --- a/ox-reveal.el +++ b/ox-reveal.el @@ -740,6 +740,43 @@ dependencies: [ (if (string= "" extra-codes) all-plugins (append (list extra-codes) all-plugins)))) (mapconcat 'identity total-codes ",\n")) "]\n")) + +(defun org-reveal--script-tag-by-file-name (fname in-single-file) + "Create a \n") + ;; Cannot read fname, just error out + (error (concat "Cannot generate single file presentation due to " + fname + " is not readable"))) + (format "\n" fname))) + +(defun org-reveal--script-tags-by-auto-file-names (fnames in-single-file) + "Create multiple ") - ;; Fall-back to extern script links - (if in-single-file - ;; Tried to embed scripts but failed. Print a message about possible errors. - (error (concat "Cannot read " - (mapconcat 'identity - (delq nil (mapcar (lambda (file) (if (not (file-readable-p file)) file)) - (list local-reveal-js))) - ", ")))) - (concat - "\n")) + (org-reveal--script-tag-by-file-name local-reveal-js in-single-file) ;; plugin headings (if-format "%s\n" (car reveal-4-plugin)) ;; Extra tags before the call to Reveal.initialize() - (let ((before-src-list (let ((l (plist-get info :reveal-extra-script-before-src))) - ;; map to a single string to a list. - (if (stringp l) - (list l) - l)))) - (and before-src-list - (mapconcat (lambda (src) (format "" src)) - before-src-list - "\n"))) - + (org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-before-src) + in-single-file) ;; Reveal.initialize (let ((reveal-4-plugin-statement (cdr reveal-4-plugin)) @@ -838,15 +852,8 @@ Reveal.initialize({ ;; Extra initialization scripts (or (plist-get info :reveal-extra-script) ""))) ;; Extra tags - (let ((src-list (let ((l (plist-get info :reveal-extra-script-src))) - ;; map to a single string to a list. - (if (stringp l) - (list l) - l)))) - (and src-list - (mapconcat (lambda (src) (format "" src)) - src-list - "\n")))))) + (org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-src) + in-single-file)))) (defun org-reveal--read-sexps-from-string (s) (let ((s (string-trim s))) @@ -891,12 +898,11 @@ Reveal.initialize({ ;; nil, no %s or %% found fmt))) -(defun org-reveal-plugin-scripts-4 (plugins info) - "Return scripts for initializing reveal.js 4.x builtin scripts" - ;; Return a tuple (represented as a list), the first value is a list of script - ;; tags that are going to be inlined to the final HTML output, the second - ;; value is a list of import statements that are going to be embedded in the - ;; Reveal.initialize call +(defun org-reveal-plugin-scripts-4 (plugins info in-single-file) + "Return scripts for initializing reveal.js 4.x builtin scripts." + ;; Return a pair whose first value is the HTML contents for the + ;; plugin scripts, the second value is a list of import statements + ;; to be embedded in the Reveal.initialize call (if (not (null plugins)) ;; Generate plugin scripts (let* ((plugins (mapcar @@ -931,23 +937,13 @@ Reveal.initialize({ plugins)))) (if (not (null plugin-js)) (cons - ;; First value of the tuple, a list of scripts HTML tags + ;; First value of the pair, a list of script file names (let ((root-path (org-reveal-root-path info))) - (mapconcat + (org-reveal--multi-level-mapconcat (lambda (p) - ;; when it is a list, create a script tag for every entry - (cond - ((listp p) - (mapconcat (lambda (pi) - (format "\n" - (org-reveal--replace-first-%s pi root-path))) - p - "")) - ;; when it is a single string, create a single script tag - (t (format "\n" - (org-reveal--replace-first-%s p root-path))))) - plugin-js - "")) + (org-reveal--script-tag-by-file-name (org-reveal--replace-first-%s p root-path) + in-single-file)) + plugin-js "")) ;; Second value of the tuple, a list of Reveal plugin ;; initialization statements (format "plugins: [%s]"