Default fragment style.

This commit is contained in:
Yujie Wen 2015-04-02 18:15:04 +08:00
parent d77969eda7
commit 87238c7917
2 changed files with 47 additions and 24 deletions

View File

@ -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.

View File

@ -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 "<pre %s%s>\n%s</pre>"
(or (frag-class frag) " class=\"example\"")
(or (frag-class frag info) " class=\"example\"")
label
code)
(format
@ -725,7 +736,7 @@ contextual information."
(format "<label class=\"org-src-name\">%s</label>"
(org-export-data caption info)))
(format "\n<pre %s%s>%s</pre>"
(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 "<blockquote %s>\n%s</blockquote>"
(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))