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 #+ATTR_REVEAL: :frag roll-in
Pictures, tables and many other HTML elements can be fragmented. Pictures, tables and many other HTML elements can be fragmented.
Use default fragment style by setting ":frag t".
*** Fragment Styles *** Fragment Styles
Availabe fragment styles are: Available fragment styles are:
#+ATTR_REVEAL: :frag t #+ATTR_REVEAL: :frag t
* grow * grow
* shrink * shrink
@ -321,6 +319,10 @@ $ git clone https://github.com/yjwen/org-reveal.git
* highlight-green * highlight-green
* highlight-blue * 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 Index
Fragment sequence can be changed by assigning adding ~:frag_idx~ Fragment sequence can be changed by assigning adding ~:frag_idx~
property to each fragmented element. property to each fragmented element.

View File

@ -34,14 +34,6 @@
(require 'ox-html) (require 'ox-html)
(eval-when-compile (require 'cl)) (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 (org-export-define-derived-backend 'reveal 'html
:menu-entry :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-header "REVEAL_SLIDE_HEADER" nil org-reveal-slide-header t)
(:reveal-slide-footer "REVEAL_SLIDE_FOOTER" nil org-reveal-slide-footer t) (:reveal-slide-footer "REVEAL_SLIDE_FOOTER" nil org-reveal-slide-footer t)
(:reveal-plugins "REVEAL_PLUGINS" nil nil 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 :translate-alist
@ -288,6 +281,11 @@ can be include."
:group 'org-export-reveal :group 'org-export-reveal
:type 'string) :type 'string)
(defcustom org-reveal-default-frag-style nil
"Default fragment style."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-plugins (defcustom org-reveal-plugins
'(classList markdown highlight zoom notes) '(classList markdown highlight zoom notes)
"Default builtin plugins" "Default builtin plugins"
@ -315,10 +313,23 @@ a '\\n'"
(if attrs (org-html--make-attribute-string attrs) "") (if attrs (org-html--make-attribute-string attrs) "")
sep_ content sep_ tagname))) sep_ content sep_ tagname)))
(defun frag-class (frag) (defun frag-style (frag info)
;; Return proper HTML string description of fragment style. "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 (and frag
(format " class=\"%s\"" (frag-style frag)))) (format " class=\"%s\"" (frag-style frag info))))
(defun org-reveal-export-block (export-block contents info) (defun org-reveal-export-block (export-block contents info)
"Transocde a EXPORT-BLOCK element from Org to Reveal. "Transocde a EXPORT-BLOCK element from Org to Reveal.
@ -716,7 +727,7 @@ contextual information."
(org-export-solidify-link-text lbl)))))) (org-export-solidify-link-text lbl))))))
(if (not lang) (if (not lang)
(format "<pre %s%s>\n%s</pre>" (format "<pre %s%s>\n%s</pre>"
(or (frag-class frag) " class=\"example\"") (or (frag-class frag info) " class=\"example\"")
label label
code) code)
(format (format
@ -725,7 +736,7 @@ contextual information."
(format "<label class=\"org-src-name\">%s</label>" (format "<label class=\"org-src-name\">%s</label>"
(org-export-data caption info))) (org-export-data caption info)))
(format "\n<pre %s%s>%s</pre>" (format "\n<pre %s%s>%s</pre>"
(or (frag-class frag) (or (frag-class frag info)
(format " class=\"src src-%s\"" lang)) (format " class=\"src src-%s\"" lang))
label code)))))) label code))))))
@ -734,7 +745,7 @@ contextual information."
CONTENTS holds the contents of the block INFO is a plist holding CONTENTS holds the contents of the block INFO is a plist holding
contextual information." contextual information."
(format "<blockquote %s>\n%s</blockquote>" (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)) contents))
@ -791,8 +802,9 @@ Assuming BACKEND is `reveal'.
Each `attr_reveal' attribute is mapped to corresponding Each `attr_reveal' attribute is mapped to corresponding
`attr_html' attributes." `attr_html' attributes."
(org-element-map tree (remq 'item org-element-all-elements) (let ((default-frag-style (plist-get info :reveal-default-frag-style)))
'org-reveal-append-frag) (org-element-map tree (remq 'item org-element-all-elements)
(lambda (elem) (org-reveal-append-frag elem default-frag-style))))
;; Return the updated tree. ;; Return the updated tree.
tree) tree)
@ -808,7 +820,7 @@ fragment attributes."
(push (format ":data-fragment-index %s" frag-index) attr-html))) (push (format ":data-fragment-index %s" frag-index) attr-html)))
(org-element-put-property elem :attr_html 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 "Read org-reveal's fragment attribute from ELEM and append
transformed fragment attribute to ELEM's attr_html plist." transformed fragment attribute to ELEM's attr_html plist."
(let ((frag (org-export-read-attribute :attr_reveal elem :frag)) (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 (if frag
(cond ((and (string= (org-element-type elem) 'plain-list) (cond ((and (string= (org-element-type elem) 'plain-list)
(char-equal (string-to-char frag) ?\()) (char-equal (string-to-char frag) ?\())
(let ((frag-list (car (read-from-string frag))) (let* ((frag-list (car (read-from-string frag)))
(items (org-element-contents elem))) (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 (if frag-index
(mapcar* 'org-reveal--update-attr-html (mapcar* 'org-reveal--update-attr-html
items frag-list (car (read-from-string frag-index))) items frag-list-mapped (car (read-from-string frag-index)))
(mapcar* 'org-reveal--update-attr-html items frag-list)))) (mapcar* 'org-reveal--update-attr-html items frag-list-mapped))))
(t (org-reveal--update-attr-html elem frag frag-index)))) (t (org-reveal--update-attr-html elem frag frag-index))))
elem)) elem))