From 414ccf16260f28c9310ccfa130c9787584203331 Mon Sep 17 00:00:00 2001 From: yujie Date: Tue, 12 Apr 2016 17:14:44 +0800 Subject: [PATCH] Fixed #202: Embed extra CSS when in reveal_single_file --- ox-reveal.el | 54 +++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/ox-reveal.el b/ox-reveal.el index 62a3fef..48dbbf5 100644 --- a/ox-reveal.el +++ b/ox-reveal.el @@ -474,6 +474,25 @@ holding contextual information." (if (string-equal system-type "windows-nt") "^file:///" "^file://") "" url)) +(defun org-reveal--css-label (in-single-file file-name style-id) + "Generate an HTML label for including a CSS file, if + IN-SINGLE-FILE is t, the content of FILE-NAME is embedded, + otherwise, a `' label is generated." + (when (and file-name (not (string= file-name ""))) + (if in-single-file + ;; Single-file + (let ((local-file-name (org-reveal--file-url-to-path file-name))) + (if (file-readable-p local-file-name) + (concat "\n") + ;; But file is not readable. + (error "Cannot read %s" file-name))) + ;; Not in-single-file + (concat "\n")))) + (defun org-reveal-stylesheets (info) "Return the HTML contents for declaring reveal stylesheets using custom variable `org-reveal-root'." @@ -481,10 +500,7 @@ using custom variable `org-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 (org-reveal--file-url-to-path root-path)) - (local-reveal-css (concat local-root "css/reveal.css")) - (local-theme-css (concat local-root "css/theme/" theme ".css")) + (extra-css (plist-get info :reveal-extra-css)) (in-single-file (plist-get info :reveal-single-file))) (concat ;; Default embedded style sheets @@ -493,30 +509,12 @@ using custom variable `org-reveal-root'." " ;; stylesheets - (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 (string= extra-css "") "" - (format "\n" extra-css))) + (mapconcat (lambda (elem) (org-reveal--css-label in-single-file (car elem) (cdr elem))) + (list (cons reveal-css nil) + (cons theme-css "theme") + (cons extra-css nil)) + "\n") + ;; Include CSS for highlight.js if necessary (if (org-reveal--using-highlight.js info) (format ""