From 87238c7917741938f237367e623f014d147cc91c Mon Sep 17 00:00:00 2001 From: Yujie Wen Date: Thu, 2 Apr 2015 18:15:04 +0800 Subject: [PATCH] Default fragment style. --- Readme.org | 8 ++++--- ox-reveal.el | 63 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Readme.org b/Readme.org index 4c711f9..2fa1fed 100755 --- a/Readme.org +++ b/Readme.org @@ -308,10 +308,8 @@ $ git clone https://github.com/yjwen/org-reveal.git #+ATTR_REVEAL: :frag roll-in Pictures, tables and many other HTML elements can be fragmented. - Use default fragment style by setting ":frag t". - *** Fragment Styles - Availabe fragment styles are: + Available fragment styles are: #+ATTR_REVEAL: :frag t * grow * shrink @@ -321,6 +319,10 @@ $ git clone https://github.com/yjwen/org-reveal.git * highlight-green * highlight-blue + Setting ~:frag t~ will use Reveal.js default fragment style, which + can be overriden by local option ~#+REVEAL_DEFAULT_FRAG_STYLE~ or + global variable ~org-reveal-default-frag-style~. + *** Fragment Index Fragment sequence can be changed by assigning adding ~:frag_idx~ property to each fragmented element. diff --git a/ox-reveal.el b/ox-reveal.el index d71a6c1..1f88e1a 100755 --- a/ox-reveal.el +++ b/ox-reveal.el @@ -34,14 +34,6 @@ (require 'ox-html) (eval-when-compile (require 'cl)) -(defun frag-style (frag) - "Return \"fragment\" if frag is t, which indicates to use -default fragment style, otherwise return \"fragment style\"." - (cond - ((string= frag t) "fragment") - (t (format "fragment %s" frag)))) - - (org-export-define-derived-backend 'reveal 'html :menu-entry @@ -88,6 +80,7 @@ default fragment style, otherwise return \"fragment style\"." (: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-default-frag-style "REVEAL_DEFAULT_FRAG_STYLE" nil org-reveal-default-frag-style t) ) :translate-alist @@ -288,6 +281,11 @@ can be include." :group 'org-export-reveal :type 'string) +(defcustom org-reveal-default-frag-style nil + "Default fragment style." + :group 'org-export-reveal + :type 'string) + (defcustom org-reveal-plugins '(classList markdown highlight zoom notes) "Default builtin plugins" @@ -315,10 +313,23 @@ a '\\n'" (if attrs (org-html--make-attribute-string attrs) "") sep_ content sep_ tagname))) -(defun frag-class (frag) - ;; Return proper HTML string description of fragment style. +(defun frag-style (frag info) + "Return proper fragment string according to FRAG and the default fragment style. +FRAG is the fragment style set on element, INFO is a plist +holding contextual information." + (cond + ((string= frag t) + (let ((default-frag-style (plist-get info :reveal-default-frag-style))) + (if default-frag-style (format "fragment %s" default-frag-style) + "fragment"))) + (t (format "fragment %s" frag)))) + +(defun frag-class (frag info) + "Return proper HTML string description of fragment style. +FRAG is the fragment style set on element, INFO is a plist +holding contextual information." (and frag - (format " class=\"%s\"" (frag-style frag)))) + (format " class=\"%s\"" (frag-style frag info)))) (defun org-reveal-export-block (export-block contents info) "Transocde a EXPORT-BLOCK element from Org to Reveal. @@ -716,7 +727,7 @@ contextual information." (org-export-solidify-link-text lbl)))))) (if (not lang) (format "
\n%s
" - (or (frag-class frag) " class=\"example\"") + (or (frag-class frag info) " class=\"example\"") label code) (format @@ -725,7 +736,7 @@ contextual information." (format "" (org-export-data caption info))) (format "\n
%s
" - (or (frag-class frag) + (or (frag-class frag info) (format " class=\"src src-%s\"" lang)) label code)))))) @@ -734,7 +745,7 @@ contextual information." CONTENTS holds the contents of the block INFO is a plist holding contextual information." (format "
\n%s
" - (frag-class (org-export-read-attribute :attr_reveal quote-block :frag)) + (frag-class (org-export-read-attribute :attr_reveal quote-block :frag) info) contents)) @@ -791,8 +802,9 @@ Assuming BACKEND is `reveal'. Each `attr_reveal' attribute is mapped to corresponding `attr_html' attributes." - (org-element-map tree (remq 'item org-element-all-elements) - 'org-reveal-append-frag) + (let ((default-frag-style (plist-get info :reveal-default-frag-style))) + (org-element-map tree (remq 'item org-element-all-elements) + (lambda (elem) (org-reveal-append-frag elem default-frag-style)))) ;; Return the updated tree. tree) @@ -808,7 +820,7 @@ fragment attributes." (push (format ":data-fragment-index %s" frag-index) attr-html))) (org-element-put-property elem :attr_html attr-html))) -(defun org-reveal-append-frag (elem) +(defun org-reveal-append-frag (elem default-style) "Read org-reveal's fragment attribute from ELEM and append transformed fragment attribute to ELEM's attr_html plist." (let ((frag (org-export-read-attribute :attr_reveal elem :frag)) @@ -816,12 +828,21 @@ transformed fragment attribute to ELEM's attr_html plist." (if frag (cond ((and (string= (org-element-type elem) 'plain-list) (char-equal (string-to-char frag) ?\()) - (let ((frag-list (car (read-from-string frag))) - (items (org-element-contents elem))) + (let* ((frag-list (car (read-from-string frag))) + (frag-list-mapped (if default-style + (mapcar (lambda (s) + "Replace t with default-style" + (if (string= s t) default-style + s)) + frag-list) + frag-list)) + (items (org-element-contents elem))) + (message "default-style: %s" default-style) + (message "frag-list-mapped: %s" frag-list-mapped) (if frag-index (mapcar* 'org-reveal--update-attr-html - items frag-list (car (read-from-string frag-index))) - (mapcar* 'org-reveal--update-attr-html items frag-list)))) + items frag-list-mapped (car (read-from-string frag-index))) + (mapcar* 'org-reveal--update-attr-html items frag-list-mapped)))) (t (org-reveal--update-attr-html elem frag frag-index)))) elem))