diff --git a/ox-reveal.el b/ox-reveal.el index c61c463..917b14f 100755 --- a/ox-reveal.el +++ b/ox-reveal.el @@ -427,23 +427,52 @@ holding contextual information." :tag "Org Export Reveal" :group 'org-export) +(defun org-reveal--read-file (file) + "Return the content of file" + (with-temp-buffer + (insert-file-contents-literally file) + (buffer-string))) + (defun org-reveal-stylesheets (info) "Return the HTML contents for declaring reveal stylesheets using custom variable `org-reveal-root'." - (let ((root-path (file-name-as-directory (plist-get info :reveal-root)))) + (let* ((root-path (file-name-as-directory (plist-get info :reveal-root))) + (reveal-css (concat root-path "css/reveal.css")) + (theme (plist-get info :reveal-theme)) + (theme-css (concat root-path "css/theme/" theme ".css")) + ;; Local file names. + (local-root (replace-regexp-in-string "^file:///" "" root-path)) + (local-reveal-css (concat local-root "css/reveal.css")) + (local-theme-css (concat local-root "css/theme/" theme ".css")) + (in-single-file (plist-get info :reveal-single-file))) (concat ;; stylesheets - (format " - - -" - root-path root-path - (plist-get info :reveal-theme)) + (if (and in-single-file + (file-readable-p local-reveal-css) + (file-readable-p local-theme-css)) + ;; CSS files exist and are readable. Embed them. + (concat "\n") + ;; Fall-back to external CSS links. + (if in-single-file + ;; Tried to embed CSS files 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-css local-theme-css))) + ", ")))) + ;; Create links to CSS files. + (concat "\n" + "\n")) ;; extra css (let ((extra-css (plist-get info :reveal-extra-css))) (if extra-css (format "" extra-css) "")) ;; print-pdf - (format " + (if in-single-file "" + (format " " - root-path)))) + root-path))))) (defun org-reveal-mathjax-scripts (info) "Return the HTML contents for declaring MathJax scripts" @@ -467,15 +496,37 @@ using custom variable `org-reveal-root'." (defun org-reveal-scripts (info) "Return the necessary scripts for initializing reveal.js using custom variable `org-reveal-root'." - (let* ((root-path (file-name-as-directory (plist-get info :reveal-root)))) + (let* ((root-path (file-name-as-directory (plist-get info :reveal-root))) + (head-min-js (concat root-path "lib/js/head.min.js")) + (reveal-js (concat root-path "js/reveal.js")) + ;; Local files + (local-root-path (replace-regexp-in-string "^file:///" "" root-path)) + (local-head-min-js (concat local-root-path "lib/js/head.min.js")) + (local-reveal-js (concat local-root-path "js/reveal.js")) + (in-single-file (plist-get info :reveal-single-file))) (concat ;; reveal.js/lib/js/head.min.js ;; reveal.js/js/reveal.js - (format " - - -" - root-path root-path) + (if (and in-single-file + (file-readable-p local-head-min-js) + (file-readable-p local-reveal-js)) + ;; Embed scripts into HTML + (concat "") + ;; 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-head-min-js local-reveal-js))) + ", ")))) + (concat + "\n" + "\n")) ;; plugin headings " \n"))) + highlight (format " { src: '%splugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }" root-path) + zoom (format " { src: '%splugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }" root-path) + notes (format " { src: '%splugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }" root-path) + search (format " { src: '%splugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }" root-path) + remotes (format " { src: '%splugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }" root-path) + multiplex (format " { src: '%s', async: true },\n%s" + (plist-get info :reveal-multiplex-socketio-url) + ; following ensures that either client.js or master.js is included depending on defva client-multiplex value state + (if (not client-multiplex) + (progn + (if (plist-get info :reveal-multiplex-secret) + (setq client-multiplex t)) + (format " { src: '%splugin/multiplex/master.js', async: true }" root-path)) + (format " { src: '%splugin/multiplex/client.js', async: true }" root-path))))) + (builtin-codes + (mapcar + (lambda (p) + (eval (plist-get builtins p))) + (let ((buffer-plugins (plist-get info :reveal-plugins))) + (cond + ((string= buffer-plugins "") ()) + (buffer-plugins (car (read-from-string buffer-plugins))) + (t org-reveal-plugins))))) + (extra-codes (plist-get info :reveal-extra-js)) + (total-codes + (if (string= "" extra-codes) builtin-codes + (append (list extra-codes) builtin-codes)))) + (mapconcat 'identity total-codes ",\n")) + "]\n" + ) + "\n") + "});\n\n"))) (defun org-reveal-toc (depth info) "Build a slide of table of contents."