mirror of https://github.com/yjwen/org-reveal.git
Fixed #472. Read plugin scripts in single file mode
This commit is contained in:
parent
2f1509cc14
commit
3f5ae4df8a
114
ox-reveal.el
114
ox-reveal.el
|
@ -740,6 +740,43 @@ dependencies: [
|
||||||
(if (string= "" extra-codes) all-plugins (append (list extra-codes) all-plugins))))
|
(if (string= "" extra-codes) all-plugins (append (list extra-codes) all-plugins))))
|
||||||
(mapconcat 'identity total-codes ",\n"))
|
(mapconcat 'identity total-codes ",\n"))
|
||||||
"]\n"))
|
"]\n"))
|
||||||
|
|
||||||
|
(defun org-reveal--script-tag-by-file-name (fname in-single-file)
|
||||||
|
"Create a <script> tag for including scripts from the given
|
||||||
|
file name. If in single file mode, the <script> tag encloses the
|
||||||
|
contents of the file, otherwise it is a tag pointing to the file"
|
||||||
|
(if in-single-file
|
||||||
|
(if (file-readable-p fname)
|
||||||
|
;; Embed script into HTML
|
||||||
|
(concat "<script>\n"
|
||||||
|
(org-reveal--read-file fname)
|
||||||
|
"\n</script>\n")
|
||||||
|
;; Cannot read fname, just error out
|
||||||
|
(error (concat "Cannot generate single file presentation due to "
|
||||||
|
fname
|
||||||
|
" is not readable")))
|
||||||
|
(format "<script src=\"%s\"></script>\n" fname)))
|
||||||
|
|
||||||
|
(defun org-reveal--script-tags-by-auto-file-names (fnames in-single-file)
|
||||||
|
"Create multiple <script> tags for multiple file names, but
|
||||||
|
also accept single file name and create only one tag."
|
||||||
|
(if (stringp fnames)
|
||||||
|
(org-reveal--script-tag-by-file-name fnames in-single-file)
|
||||||
|
(mapconcat (lambda (fname)
|
||||||
|
(org-reveal--script-tag-by-file-name fname in-single-file))
|
||||||
|
fnames
|
||||||
|
"")))
|
||||||
|
|
||||||
|
(defun org-reveal--multi-level-mapconcat (func sequence seperator)
|
||||||
|
"Multilevel mapconcat. FUNC is applied to each element of seq
|
||||||
|
unless the element itself is a list, in which case func is
|
||||||
|
lifted and applied."
|
||||||
|
(mapconcat (lambda (e)
|
||||||
|
(if (listp e)
|
||||||
|
(org-reveal--multi-level-mapconcat func e seperator)
|
||||||
|
(funcall func e)))
|
||||||
|
sequence seperator))
|
||||||
|
|
||||||
(defun org-reveal-scripts (info)
|
(defun org-reveal-scripts (info)
|
||||||
"Return the necessary scripts for initializing reveal.js using
|
"Return the necessary scripts for initializing reveal.js using
|
||||||
custom variable `org-reveal-root'."
|
custom variable `org-reveal-root'."
|
||||||
|
@ -750,42 +787,19 @@ custom variable `org-reveal-root'."
|
||||||
(local-root-path (org-reveal--file-url-to-path root-path))
|
(local-root-path (org-reveal--file-url-to-path root-path))
|
||||||
(local-reveal-js (org-reveal--choose-path local-root-path version "dist/reveal.js" "js/reveal.js"))
|
(local-reveal-js (org-reveal--choose-path local-root-path version "dist/reveal.js" "js/reveal.js"))
|
||||||
(plugins (org-reveal--get-plugins info))
|
(plugins (org-reveal--get-plugins info))
|
||||||
|
(in-single-file (plist-get info :reveal-single-file))
|
||||||
(reveal-4-plugin (if (eq 4 version)
|
(reveal-4-plugin (if (eq 4 version)
|
||||||
(org-reveal-plugin-scripts-4 plugins info)
|
(org-reveal-plugin-scripts-4 plugins info in-single-file)
|
||||||
(cons nil nil)))
|
(cons nil nil))))
|
||||||
(in-single-file (plist-get info :reveal-single-file)))
|
|
||||||
(concat
|
(concat
|
||||||
;; reveal.js/js/reveal.js
|
;; reveal.js/js/reveal.js
|
||||||
(if (and in-single-file
|
(org-reveal--script-tag-by-file-name local-reveal-js in-single-file)
|
||||||
(file-readable-p local-reveal-js))
|
|
||||||
;; Embed scripts into HTML
|
|
||||||
(concat "<script>\n"
|
|
||||||
(org-reveal--read-file local-reveal-js)
|
|
||||||
"\n</script>")
|
|
||||||
;; 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
|
|
||||||
"<script src=\"" reveal-js "\"></script>\n"))
|
|
||||||
;; plugin headings
|
;; plugin headings
|
||||||
(if-format "%s\n" (car reveal-4-plugin))
|
(if-format "%s\n" (car reveal-4-plugin))
|
||||||
|
|
||||||
;; Extra <script src="..."></script> tags before the call to Reveal.initialize()
|
;; Extra <script src="..."></script> tags before the call to Reveal.initialize()
|
||||||
(let ((before-src-list (let ((l (plist-get info :reveal-extra-script-before-src)))
|
(org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-before-src)
|
||||||
;; map to a single string to a list.
|
in-single-file)
|
||||||
(if (stringp l)
|
|
||||||
(list l)
|
|
||||||
l))))
|
|
||||||
(and before-src-list
|
|
||||||
(mapconcat (lambda (src) (format "<script src=\"%s\"></script>" src))
|
|
||||||
before-src-list
|
|
||||||
"\n")))
|
|
||||||
|
|
||||||
|
|
||||||
;; Reveal.initialize
|
;; Reveal.initialize
|
||||||
(let ((reveal-4-plugin-statement (cdr reveal-4-plugin))
|
(let ((reveal-4-plugin-statement (cdr reveal-4-plugin))
|
||||||
|
@ -838,15 +852,8 @@ Reveal.initialize({
|
||||||
;; Extra initialization scripts
|
;; Extra initialization scripts
|
||||||
(or (plist-get info :reveal-extra-script) "")))
|
(or (plist-get info :reveal-extra-script) "")))
|
||||||
;; Extra <script src="..."></script> tags
|
;; Extra <script src="..."></script> tags
|
||||||
(let ((src-list (let ((l (plist-get info :reveal-extra-script-src)))
|
(org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-src)
|
||||||
;; map to a single string to a list.
|
in-single-file))))
|
||||||
(if (stringp l)
|
|
||||||
(list l)
|
|
||||||
l))))
|
|
||||||
(and src-list
|
|
||||||
(mapconcat (lambda (src) (format "<script src=\"%s\"></script>" src))
|
|
||||||
src-list
|
|
||||||
"\n"))))))
|
|
||||||
|
|
||||||
(defun org-reveal--read-sexps-from-string (s)
|
(defun org-reveal--read-sexps-from-string (s)
|
||||||
(let ((s (string-trim s)))
|
(let ((s (string-trim s)))
|
||||||
|
@ -891,12 +898,11 @@ Reveal.initialize({
|
||||||
;; nil, no %s or %% found
|
;; nil, no %s or %% found
|
||||||
fmt)))
|
fmt)))
|
||||||
|
|
||||||
(defun org-reveal-plugin-scripts-4 (plugins info)
|
(defun org-reveal-plugin-scripts-4 (plugins info in-single-file)
|
||||||
"Return scripts for initializing reveal.js 4.x builtin scripts"
|
"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
|
;; Return a pair whose first value is the HTML contents for the
|
||||||
;; tags that are going to be inlined to the final HTML output, the second
|
;; plugin scripts, the second value is a list of import statements
|
||||||
;; value is a list of import statements that are going to be embedded in the
|
;; to be embedded in the Reveal.initialize call
|
||||||
;; Reveal.initialize call
|
|
||||||
(if (not (null plugins))
|
(if (not (null plugins))
|
||||||
;; Generate plugin scripts
|
;; Generate plugin scripts
|
||||||
(let* ((plugins (mapcar
|
(let* ((plugins (mapcar
|
||||||
|
@ -931,23 +937,13 @@ Reveal.initialize({
|
||||||
plugins))))
|
plugins))))
|
||||||
(if (not (null plugin-js))
|
(if (not (null plugin-js))
|
||||||
(cons
|
(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)))
|
(let ((root-path (org-reveal-root-path info)))
|
||||||
(mapconcat
|
(org-reveal--multi-level-mapconcat
|
||||||
(lambda (p)
|
(lambda (p)
|
||||||
;; when it is a list, create a script tag for every entry
|
(org-reveal--script-tag-by-file-name (org-reveal--replace-first-%s p root-path)
|
||||||
(cond
|
in-single-file))
|
||||||
((listp p)
|
plugin-js ""))
|
||||||
(mapconcat (lambda (pi)
|
|
||||||
(format "<script src=\"%s\"></script>\n"
|
|
||||||
(org-reveal--replace-first-%s pi root-path)))
|
|
||||||
p
|
|
||||||
""))
|
|
||||||
;; when it is a single string, create a single script tag
|
|
||||||
(t (format "<script src=\"%s\"></script>\n"
|
|
||||||
(org-reveal--replace-first-%s p root-path)))))
|
|
||||||
plugin-js
|
|
||||||
""))
|
|
||||||
;; Second value of the tuple, a list of Reveal plugin
|
;; Second value of the tuple, a list of Reveal plugin
|
||||||
;; initialization statements
|
;; initialization statements
|
||||||
(format "plugins: [%s]"
|
(format "plugins: [%s]"
|
||||||
|
|
Loading…
Reference in New Issue