From f71a12a04d5b2e3d72501ee2bf524157f0fc2d02 Mon Sep 17 00:00:00 2001 From: Yujie Wen Date: Sat, 23 Oct 2021 22:24:29 +0800 Subject: [PATCH] Fixed #461. Support for in-buffer external plugin specification --- Readme.org | 20 +++++++++++++++----- ox-reveal.el | 21 +++++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Readme.org b/Readme.org index bee265f..b5476ab 100644 --- a/Readme.org +++ b/Readme.org @@ -55,8 +55,6 @@ #+REVEAL: split:t - [[Initialization options][Initialization options]]([[https://github.com/yjwen/org-reveal#initialization-options][gh]]) - [[Third-Party Plugins][Third-Party Plugins]]([[https://github.com/yjwen/org-reveal#third-party-plugins][gh]]) - - [[By Defining Variable][By Defining Variable]]([[https://github.com/yjwen/org-reveal#by-defining-variable][gh]]) - - [[By Local Option Line][By Local Option Line]]([[https://github.com/yjwen/org-reveal#by-local-option-line][gh]]) - [[Highlight Source Code][Highlight Source Code]]([[https://github.com/yjwen/org-reveal#highlight-source-code][gh]]) - [[Using highlight.js][Using highlight.js]]([[https://github.com/yjwen/org-reveal#using-highlightjs][gh]]) - [[Auto-Animate]] ([[https://github.com/yjwen/org-reveal#auto-animate][gh]]) @@ -67,7 +65,6 @@ - [[Generating Pre/Postamble by Emacs-Lisp Functions][Generating Pre/Postamble by Emacs-Lisp Functions]]([[https://github.com/yjwen/org-reveal#generating-pre/postamble-by-emacs-lisp-functions][gh]]) - [[Raw HTML in Slides][Raw HTML in Slides]]([[https://github.com/yjwen/org-reveal#raw-html-in-slides][gh]]) - [[Speaker Notes][Speaker Notes]]([[https://github.com/yjwen/org-reveal#speaker-notes][gh]]) - - [[Easy-Template for Speaker Notes][Easy-Template for Speaker Notes]]([[https://github.com/yjwen/org-reveal#easy-template-for-speaker-notes][gh]]) - [[Multiplexing][Multiplexing]]([[https://github.com/yjwen/org-reveal#multiplexing][gh]]) - [[Extra Stylesheets][Extra Stylesheets]]([[https://github.com/yjwen/org-reveal#extra-stylesheets][gh]]) - [[Select Built-In Scripts][Select Built-In Scripts]]([[https://github.com/yjwen/org-reveal#select-built-in-scripts][gh]]) @@ -573,14 +570,27 @@ Reveal.js is also extensible through third-party plugins. Org-reveal provides a customizable variable ~org-reveal-external-plugins~ for defining available third-party plugins. This variable is an associative list. The first element of each Assoc cell is a symbol -same as the name of the plugin and the second is a string specifying -the location of the plugin script. The string can have ONE optional +same as the name of the plugin and the second is either a string +specifying the location of the plugin script or a list of string in +case of multiple scripts. Each script string can have ONE optional ~%s~, which will be replaced by `reveal-root`. Code below is an example. #+begin_src lisp (setq org-reveal-external-plugins '((RevealMenu . "path/to/reveal.js-menu/menu.js")) #+end_src +#+REVEAL: split:t + +Plugins can be specified in buffer by one or more +~#+REVEAL_EXTERNAL_PLUGINS~ options. Each option can have one or more +plugin specifications of the same format as in +~org-reveal-external-plugins~. Below is an example. + +#+begin_src org + ,#+REVEAL_EXTERNAL_PLUGINS: (plugin1 . "ex/plugin1.js") (plugin2 . "ex/plugin2.js") + ,#+REVEAL_EXTERNAL_PLUGINS: (plugin3 "ex/plugin3-1.js" "ex/plugin3-2.js") +#+end_src + ** Highlight Source Code There are two ways to highlight source code. diff --git a/ox-reveal.el b/ox-reveal.el index 46b6bc9..8a36d5b 100644 --- a/ox-reveal.el +++ b/ox-reveal.el @@ -96,7 +96,7 @@ (:reveal-slide-header "REVEAL_SLIDE_HEADER" nil org-reveal-slide-header t) (:reveal-slide-footer "REVEAL_SLIDE_FOOTER" nil org-reveal-slide-footer t) (:reveal-plugins "REVEAL_PLUGINS" nil nil t) - (:reveal-external-plugins "REVEAL_EXTERNAL_PLUGINS" nil nil newline) + (:reveal-external-plugins "REVEAL_EXTERNAL_PLUGINS" nil nil space) (:reveal-default-frag-style "REVEAL_DEFAULT_FRAG_STYLE" nil org-reveal-default-frag-style t) (:reveal-single-file nil "reveal_single_file" org-reveal-single-file t) (:reveal-init-script "REVEAL_INIT_SCRIPT" nil org-reveal-init-script space) @@ -820,6 +820,15 @@ Reveal.initialize({ (or (plist-get info :reveal-extra-script) ""))) ))) +(defun org-reveal--read-sexps-from-string (s) + (let ((s (string-trim s))) + (and (not (string-empty-p s)) + (let ((r (read-from-string s))) + (let ((obj (car r)) + (remain-index (cdr r))) + (and obj + (cons obj (read-sexps-from-string (substring s remain-index))))))))) + (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 @@ -849,7 +858,11 @@ Reveal.initialize({ (RevealNotes . "%splugin/notes/notes.js") (RevealMath . "%splugin/math/math.js") (RevealZoom . "%splugin/zoom/zoom.js")) - org-reveal-external-plugins)) + org-reveal-external-plugins + ;; Buffer local plugins + (let ((local-plugins (plist-get info :reveal-external-plugins))) + (and local-plugins + (org-reveal--read-sexps-from-string local-plugins))))) (plugin-js (seq-filter 'identity ;; Filter out nil (mapcar (lambda (p) (cdr (assoc p available-plugins))) @@ -864,10 +877,10 @@ Reveal.initialize({ (cond ((listp p) (mapconcat (lambda (pi) - (format "" + (format "\n" (format pi root-path))) p - "\n")) + "")) ;; when it is a single string, create a single script tag (t (format "\n" (format p root-path)))))