Merge pull request #228 from kaushalmodi/default-background-support-and-split-slide-fix

Support setting default slide properties
This commit is contained in:
Yujie Wen 2016-09-28 16:42:43 +08:00 committed by GitHub
commit ce6b9c3e4e
1 changed files with 83 additions and 57 deletions

View File

@ -69,6 +69,11 @@
(:reveal-title-slide-background-position "REVEAL_TITLE_SLIDE_BACKGROUND_POSITION" nil nil t) (:reveal-title-slide-background-position "REVEAL_TITLE_SLIDE_BACKGROUND_POSITION" nil nil t)
(:reveal-title-slide-background-repeat "REVEAL_TITLE_SLIDE_BACKGROUND_REPEAT" nil nil t) (:reveal-title-slide-background-repeat "REVEAL_TITLE_SLIDE_BACKGROUND_REPEAT" nil nil t)
(:reveal-title-slide-background-transition "REVEAL_TITLE_SLIDE_BACKGROUND_TRANSITION" nil nil t) (:reveal-title-slide-background-transition "REVEAL_TITLE_SLIDE_BACKGROUND_TRANSITION" nil nil t)
(:reveal-default-slide-background "REVEAL_DEFAULT_SLIDE_BACKGROUND" nil nil t)
(:reveal-default-slide-background-size "REVEAL_DEFAULT_SLIDE_BACKGROUND_SIZE" nil nil t)
(:reveal-default-slide-background-position "REVEAL_DEFAULT_SLIDE_BACKGROUND_POSITION" nil nil t)
(:reveal-default-slide-background-repeat "REVEAL_DEFAULT_SLIDE_BACKGROUND_REPEAT" nil nil t)
(:reveal-default-slide-background-transition "REVEAL_DEFAULT_SLIDE_BACKGROUND_TRANSITION" nil nil t)
(:reveal-mathjax-url "REVEAL_MATHJAX_URL" nil org-reveal-mathjax-url t) (:reveal-mathjax-url "REVEAL_MATHJAX_URL" nil org-reveal-mathjax-url t)
(:reveal-preamble "REVEAL_PREAMBLE" nil org-reveal-preamble t) (:reveal-preamble "REVEAL_PREAMBLE" nil org-reveal-preamble t)
(:reveal-head-preamble "REVEAL_HEAD_PREAMBLE" nil org-reveal-head-preamble newline) (:reveal-head-preamble "REVEAL_HEAD_PREAMBLE" nil org-reveal-head-preamble newline)
@ -343,6 +348,9 @@ content."
:group 'org-export-reveal :group 'org-export-reveal
:type 'string) :type 'string)
(defvar org-reveal--last-slide-section-tag ""
"Variable to cache the section tag from the last slide. ")
(defun if-format (fmt val) (defun if-format (fmt val)
(if val (format fmt val) "")) (if val (format fmt val) ""))
@ -398,61 +406,78 @@ holding contextual information."
(footer (plist-get info :reveal-slide-footer)) (footer (plist-get info :reveal-slide-footer))
(footer-div (when footer (format "<div class=\"slide-footer\">%s</div>\n" footer))) (footer-div (when footer (format "<div class=\"slide-footer\">%s</div>\n" footer)))
(first-sibling (org-export-first-sibling-p headline info)) (first-sibling (org-export-first-sibling-p headline info))
(last-sibling (org-export-last-sibling-p headline info))) (last-sibling (org-export-last-sibling-p headline info))
(concat (default-slide-background (plist-get info :reveal-default-slide-background))
(if (or (/= level 1) (not first-sibling)) (default-slide-background-size (plist-get info :reveal-default-slide-background-size))
;; Not the first heading. Close previou slide. (default-slide-background-position (plist-get info :reveal-default-slide-background-position))
(concat (default-slide-background-repeat (plist-get info :reveal-default-slide-background-repeat))
;; Slide footer if any (default-slide-background-transition (plist-get info :reveal-default-slide-background-transition))
footer-div (slide-section-tag (format "<section %s%s>\n"
;; Close previous slide (org-html--make-attribute-string
"</section>\n" `(:id ,(format "slide-%s" preferred-id)
(if (<= level hlevel) :data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline)
;; Close previous vertical slide group. :data-state ,(org-element-property :REVEAL_DATA_STATE headline)
"</section>\n"))) :data-background ,(or (org-element-property :REVEAL_BACKGROUND headline)
(if (<= level hlevel) default-slide-background)
;; Add an extra "<section>" to group following slides :data-background-size ,(or (org-element-property :REVEAL_BACKGROUND_SIZE headline)
;; into vertical slide group. Transition override default-slide-background-size)
;; attributes are attached at this level, too. :data-background-position ,(or (org-element-property :REVEAL_BACKGROUND_POSITION headline)
(let ((attrs default-slide-background-position)
(org-html--make-attribute-string :data-background-repeat ,(or (org-element-property :REVEAL_BACKGROUND_REPEAT headline)
`(:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline))))) default-slide-background-repeat)
(if (string= attrs "") :data-background-transition ,(or (org-element-property :REVEAL_BACKGROUND_TRANS headline)
"<section>\n" default-slide-background-transition)))
(format "<section %s>\n" attrs)))) (let ((extra-attrs (org-element-property :REVEAL_EXTRA_ATTR headline)))
;; Start a new slide. (if extra-attrs (format " %s" extra-attrs) ""))))
(format "<section %s%s>\n" (ret (concat
(org-html--make-attribute-string (if (or (/= level 1) (not first-sibling))
`(:id ,(format "slide-%s" preferred-id) ;; Not the first heading. Close previou slide.
:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline) (concat
:data-state ,(org-element-property :REVEAL_DATA_STATE headline) ;; Slide footer if any
:data-background ,(org-element-property :REVEAL_BACKGROUND headline) footer-div
:data-background-size ,(org-element-property :REVEAL_BACKGROUND_SIZE headline) ;; Close previous slide
:data-background-position ,(org-element-property :REVEAL_BACKGROUND_POSITION headline) "</section>\n"
:data-background-repeat ,(org-element-property :REVEAL_BACKGROUND_REPEAT headline) (if (<= level hlevel)
:data-background-transition ,(org-element-property :REVEAL_BACKGROUND_TRANS headline))) ;; Close previous vertical slide group.
(let ((extra-attrs (org-element-property :REVEAL_EXTRA_ATTR headline))) "</section>\n")))
(if extra-attrs (format " %s" extra-attrs) ""))) (if (<= level hlevel)
;; Slide header if any. ;; Add an extra "<section>" to group following slides
header-div ;; into vertical slide group. Transition override
;; The HTML content of the headline ;; attributes are attached at this level, too.
;; Strip the <div> tags, if any (let ((attrs
(let ((html (org-html-headline headline contents info))) (org-html--make-attribute-string
(if (string-prefix-p "<div" html) `(:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline)))))
;; Remove the first <div> and the last </div> tags from html (if (string= attrs "")
(concat "<" "<section>\n"
(mapconcat 'identity (format "<section %s>\n" attrs))))
(butlast (cdr (split-string html "<" t))) ;; Start a new slide.
"<")) (prog1
;; Return the HTML content unchanged slide-section-tag
html)) ;; Cache the current slide's section tag, except the id attr
(if (and (= level 1) (setq org-reveal--last-slide-section-tag
(org-export-last-sibling-p headline info)) (replace-regexp-in-string "id\\s-*=\\s-*[\][\"].*?[\][\"]"
;; Last head 1. Close all slides. "" slide-section-tag)))
(concat ;; Slide header if any.
;; Slide footer if any header-div
footer-div ;; The HTML content of the headline
"</section>\n</section>\n"))))))) ;; Strip the <div> tags, if any
(let ((html (org-html-headline headline contents info)))
(if (string-prefix-p "<div" html)
;; Remove the first <div> and the last </div> tags from html
(concat "<"
(mapconcat 'identity
(butlast (cdr (split-string html "<" t)))
"<"))
;; Return the HTML content unchanged
html))
(if (and (= level 1)
(org-export-last-sibling-p headline info))
;; Last head 1. Close all slides.
(concat
;; Slide footer if any
footer-div
"</section>\n</section>\n")))))
ret))))
(defgroup org-export-reveal nil (defgroup org-export-reveal nil
"Options for exporting Orgmode files to reveal.js HTML pressentations." "Options for exporting Orgmode files to reveal.js HTML pressentations."
@ -713,9 +738,10 @@ holding export options."
contents)) contents))
(defun org-reveal-parse-token (key &optional value) (defun org-reveal-parse-token (key &optional value)
"Return HTML tags or perform SIDE EFFECT according to key" "Return HTML tags or perform SIDE EFFECT according to key.
Use the previous section tag as the tag of the split section. "
(case (intern key) (case (intern key)
(split "</section>\n<section>"))) (split (format "</section>\n%s" org-reveal--last-slide-section-tag ""))))
(defun org-reveal-parse-keyword-value (value) (defun org-reveal-parse-keyword-value (value)
"According to the value content, return HTML tags to split slides." "According to the value content, return HTML tags to split slides."