ox-s5.el 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. ;;; ox-s5.el --- S5 Presentation Back-End for Org Export Engine
  2. ;; Copyright (C) 2011-2014 Rick Frankel
  3. ;; Author: Rick Frankel <emacs at rickster dot com>
  4. ;; Keywords: outlines, hypermedia, S5, wp
  5. ;; This file is not part of GNU Emacs.
  6. ;; This program is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This library implements an S5 Presentation back-end for the Org
  18. ;; generic exporter.
  19. ;; Installation
  20. ;; ------------
  21. ;; Get the s5 scripts from
  22. ;; http://meyerweb.com/eric/tools/s5/
  23. ;; (Note that the default s5 version is set for using the alpha, 1.2a2.
  24. ;; Copy the ui dir to somewhere reachable from your published presentation
  25. ;; The default (`org-s5-ui-url') is set to "ui" (e.g., in the
  26. ;; same directory as the html file).
  27. ;; Usage
  28. ;; -----
  29. ;; Follow the general instructions at the above website. To generate
  30. ;; incremental builds, you can set the HTML_CONTAINER_CLASS on an
  31. ;; object to "incremental" to make it build. If you want an outline to
  32. ;; build, set the :INCREMENTAL property on the parent headline.
  33. ;; To test it, run:
  34. ;;
  35. ;; M-x org-s5-export-as-html
  36. ;;
  37. ;; in an Org mode buffer. See ox.el and ox-html.el for more details
  38. ;; on how this exporter works.
  39. ;; TODOs
  40. ;; ------
  41. ;; The title page is formatted using format-spec. This is error prone
  42. ;; when details are missing and may insert empty tags, like <h2></h2>,
  43. ;; for missing values.
  44. (require 'ox-html)
  45. (eval-when-compile (require 'cl))
  46. (org-export-define-derived-backend 's5 'html
  47. :menu-entry
  48. '(?s "Export to S5 HTML Presentation"
  49. ((?H "To temporary buffer" org-s5-export-as-html)
  50. (?h "To file" org-s5-export-to-html)
  51. (?o "To file and open"
  52. (lambda (a s v b)
  53. (if a (org-s5-export-to-html t s v b)
  54. (org-open-file (org-s5-export-to-html nil s v b)))))))
  55. :options-alist
  56. '((:html-link-home "HTML_LINK_HOME" nil nil)
  57. (:html-link-up "HTML_LINK_UP" nil nil)
  58. (:s5-postamble "S5_POSTAMBLE" nil org-s5-postamble newline)
  59. (:s5-preamble "S5_PREAMBLE" nil org-s5-preamble newline)
  60. (:html-head-include-default-style "HTML_INCLUDE_DEFAULT_STYLE" nil nil)
  61. (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil nil)
  62. (:s5-version "S5_VERSION" nil org-s5-version)
  63. (:s5-theme-file "S5_THEME_FILE" nil org-s5-theme-file)
  64. (:s5-ui-url "S5_UI_URL" nil org-s5-ui-url)
  65. (:s5-default-view "S5_DEFAULT_VIEW" nil org-s5-default-view)
  66. (:s5-control-visibility "S5_CONTROL_VISIBILITY" nil
  67. org-s5-control-visibility))
  68. :translate-alist
  69. '((headline . org-s5-headline)
  70. (plain-list . org-s5-plain-list)
  71. (inner-template . org-s5-inner-template)
  72. (template . org-s5-template)))
  73. (defgroup org-export-s5 nil
  74. "Options for exporting Org mode files to S5 HTML Presentations."
  75. :tag "Org Export S5"
  76. :group 'org-export-html)
  77. (defcustom org-s5-version "1.2a2"
  78. "Version of s5 being used (for version metadata.) Defaults to
  79. s5 v2 alpha 2.
  80. Can be overridden with S5_VERSION."
  81. :group 'org-export-s5
  82. :type 'string)
  83. (defcustom org-s5-theme-file nil
  84. "Url to S5 theme (slides.css) file. Can be overridden with the
  85. S5_THEME_FILE property. If nil, defaults to
  86. `org-s5-ui-url'/default/slides.css. If it starts with anything but
  87. \"http\" or \"/\", it is used as-is. Otherwise the link in generated
  88. relative to `org-s5-ui-url'.
  89. The links for all other required stylesheets and scripts will be
  90. generated relative to `org-s5-ui-url'/default."
  91. :group 'org-export-s5
  92. :type 'string)
  93. (defcustom org-s5-ui-url "ui"
  94. "Base url to directory containing S5 \"default\" subdirectory
  95. and the \"s5-notes.html\" file.
  96. Can be overridden with the S5_UI_URL property."
  97. :group 'org-export-s5
  98. :type 'string)
  99. (defcustom org-s5-default-view 'slideshow
  100. "Setting for \"defaultView\" meta info."
  101. :group 'org-export-s5
  102. :type '(choice (const slideshow) (const outline)))
  103. (defcustom org-s5-control-visibility 'hidden
  104. "Setting for \"controlVis\" meta info."
  105. :group 'org-export-s5
  106. :type '(choice (const hidden) (const visibile)))
  107. (defvar org-s5--divs
  108. '((preamble "div" "header")
  109. (content "div" "content")
  110. (postamble "div" "footer"))
  111. "Alist of the three section elements for HTML export.
  112. The car of each entry is one of 'preamble, 'content or 'postamble.
  113. The cdrs of each entry are the ELEMENT_TYPE and ID for each
  114. section of the exported document.
  115. If you set `org-html-container-element' to \"li\", \"ol\" will be
  116. uses as the content ELEMENT_TYPE, generating an XOXO format
  117. slideshow.
  118. Note that changing the preamble or postamble will break the
  119. core S5 stylesheets.")
  120. (defcustom org-s5-postamble "<h1>%a - %t</h1>"
  121. "Preamble inserted into the S5 layout section.
  122. When set to a string, use this string as the postamble.
  123. When set to a function, apply this function and insert the
  124. returned string. The function takes the property list of export
  125. options as its only argument.
  126. Setting the S5_POSTAMBLE option -- or the :s5-postamble in publishing
  127. projects -- will take precedence over this variable.
  128. Note that the default css styling will break if this is set to nil
  129. or an empty string."
  130. :group 'org-export-s5
  131. :type '(choice (const :tag "No postamble" "&#x20;")
  132. (string :tag "Custom formatting string")
  133. (function :tag "Function (must return a string)")))
  134. (defcustom org-s5-preamble "&#x20;"
  135. "Peamble inserted into the S5 layout section.
  136. When set to a string, use this string as the preamble.
  137. When set to a function, apply this function and insert the
  138. returned string. The function takes the property list of export
  139. options as its only argument.
  140. Setting S5_PREAMBLE option -- or the :s5-preamble in publishing
  141. projects -- will take precedence over this variable.
  142. Note that the default css styling will break if this is set to nil
  143. or an empty string."
  144. :group 'org-export-s5
  145. :type '(choice (const :tag "No preamble" "&#x20;")
  146. (string :tag "Custom formatting string")
  147. (function :tag "Function (must return a string)")))
  148. (defcustom org-s5-title-slide-template
  149. "<h1>%t</h1>
  150. <h2>%s</h2>
  151. <h2>%a</h2>
  152. <h3>%e</h3>
  153. <h4>%d</h4>"
  154. "Format template to specify title page section.
  155. See `org-html-postamble-format' for the valid elements which
  156. can be included.
  157. It will be wrapped in the element defined in the :html-container
  158. property, and defaults to the value of `org-html-container-element',
  159. and have the id \"title-slide\"."
  160. :group 'org-export-s5
  161. :type 'string)
  162. (defun org-s5--format-toc-headline (headline info)
  163. "Return an appropriate table of contents entry for HEADLINE.
  164. Note that (currently) the S5 exporter does not support deep links,
  165. so the table of contents is not \"active\".
  166. INFO is a plist used as a communication channel."
  167. (let* ((headline-number (org-export-get-headline-number headline info))
  168. (section-number
  169. (and (not (org-export-low-level-p headline info))
  170. (org-export-numbered-headline-p headline info)
  171. (concat (mapconcat 'number-to-string headline-number ".") ". ")))
  172. (tags (and (eq (plist-get info :with-tags) t)
  173. (org-export-get-tags headline info))))
  174. (concat section-number
  175. (org-export-data
  176. (org-export-get-alt-title headline info) info)
  177. (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags info))))
  178. (defun org-s5-toc (depth info)
  179. (let* ((headlines (org-export-collect-headlines info depth))
  180. (toc-entries
  181. (mapcar (lambda (headline)
  182. (cons (org-s5--format-toc-headline headline info)
  183. (org-export-get-relative-level headline info)))
  184. (org-export-collect-headlines info depth))))
  185. (when toc-entries
  186. (concat
  187. (format "<%s id='table-of-contents' class='slide'>\n"
  188. (plist-get info :html-container))
  189. (format "<h1>%s</h1>\n"
  190. (org-html--translate "Table of Contents" info))
  191. "<div id=\"text-table-of-contents\">"
  192. (org-html--toc-text toc-entries)
  193. "</div>\n"
  194. (format "</%s>\n" (plist-get info :html-container))))))
  195. (defun org-s5--build-head (info)
  196. (let* ((dir (plist-get info :s5-ui-url))
  197. (theme (or (plist-get info :s5-theme-file) "default/slides.css")))
  198. (mapconcat
  199. 'identity
  200. (list
  201. "<!-- style sheet links -->"
  202. (mapconcat
  203. (lambda (list)
  204. (format
  205. (concat
  206. "<link rel='stylesheet' href='%s/default/%s' type='text/css'"
  207. " media='%s' id='%s' />")
  208. dir (nth 0 list) (nth 1 list) (nth 2 list)))
  209. (list
  210. '("outline.css" "screen" "outlineStyle")
  211. '("print.css" "print" "slidePrint")
  212. '("opera.css" "projection" "operaFix")) "\n")
  213. (format (concat
  214. "<link rel='stylesheet' href='%s' type='text/css'"
  215. " media='screen' id='slideProj' />")
  216. (if (string-match-p "^\\(http\\|/\\)" theme) theme
  217. (concat dir "/" theme)))
  218. "<!-- S5 JS -->"
  219. (concat
  220. "<script src='" dir
  221. "/default/slides.js' type='text/javascript'></script>")) "\n")))
  222. (defun org-s5--build-meta-info (info)
  223. (concat
  224. (org-html--build-meta-info info)
  225. (format "<meta name=\"version\" content=\"S5 %s\" />\n"
  226. (plist-get info :s5-version))
  227. (format "<meta name='defaultView' content='%s' />\n"
  228. (plist-get info :s5-default-view))
  229. (format "<meta name='controlVis' content='%s' />"
  230. (plist-get info :s5-control-visibility))))
  231. (defun org-s5-headline (headline contents info)
  232. (let ((org-html-toplevel-hlevel 1)
  233. (class (or (org-element-property :HTML_CONTAINER_CLASS headline) ""))
  234. (level (org-export-get-relative-level headline info)))
  235. (when (and (= 1 level) (not (string-match-p "\\<slide\\>" class)))
  236. (org-element-put-property headline :HTML_CONTAINER_CLASS (concat class " slide")))
  237. (org-html-headline headline contents info)))
  238. (defun org-s5-plain-list (plain-list contents info)
  239. "Transcode a PLAIN-LIST element from Org to HTML.
  240. CONTENTS is the contents of the list. INFO is a plist holding
  241. contextual information.
  242. If a containing headline has the property :INCREMENTAL,
  243. then the \"incremental\" class will be added to the to the list,
  244. which will make the list into a \"build\"."
  245. (let* ((type (org-element-property :type plain-list))
  246. (tag (case type
  247. (ordered "ol")
  248. (unordered "ul")
  249. (descriptive "dl"))))
  250. (format "%s\n%s%s"
  251. (format
  252. "<%s class='org-%s%s'>" tag tag
  253. (if (org-export-get-node-property :INCREMENTAL plain-list t)
  254. " incremental" ""))
  255. contents
  256. (format "</%s>" tag))))
  257. (defun org-s5-inner-template (contents info)
  258. "Return body of document string after HTML conversion.
  259. CONTENTS is the transcoded contents string. INFO is a plist
  260. holding export options."
  261. (concat contents "\n"))
  262. (defun org-s5-template (contents info)
  263. "Return complete document string after HTML conversion.
  264. CONTENTS is the transcoded contents string. INFO is a plist
  265. holding export options."
  266. (let ((info (plist-put
  267. (plist-put
  268. (plist-put info :html-preamble (plist-get info :s5-preamble))
  269. :html-postamble
  270. (plist-get info :s5-postamble))
  271. :html-divs
  272. (if (equal "li" (plist-get info :html-container))
  273. (cons '(content "ol" "content") org-s5--divs)
  274. org-s5--divs))))
  275. (mapconcat
  276. 'identity
  277. (list
  278. (org-html-doctype info)
  279. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">"
  280. (plist-get info :language) (plist-get info :language))
  281. "<head>"
  282. (org-s5--build-meta-info info)
  283. (org-s5--build-head info)
  284. (org-html--build-head info)
  285. (org-html--build-mathjax-config info)
  286. "</head>"
  287. "<body>"
  288. "<div class=\"layout\">"
  289. "<div id=\"controls\"><!-- no edit --></div>"
  290. "<div id=\"currentSlide\"><!-- no edit --></div>"
  291. (org-html--build-pre/postamble 'preamble info)
  292. (org-html--build-pre/postamble 'postamble info)
  293. "</div>"
  294. (format "<%s id=\"%s\" class=\"presentation\">"
  295. (nth 1 (assq 'content org-html-divs))
  296. (nth 2 (assq 'content org-html-divs)))
  297. ;; title page
  298. (format "<%s id='title-slide' class='slide'>"
  299. (plist-get info :html-container))
  300. (format-spec org-s5-title-slide-template (org-html-format-spec info))
  301. (format "</%s>" (plist-get info :html-container))
  302. ;; table of contents.
  303. (let ((depth (plist-get info :with-toc)))
  304. (when depth (org-s5-toc depth info)))
  305. contents
  306. (format "</%s>" (nth 1 (assq 'content org-html-divs)))
  307. "</body>"
  308. "</html>\n") "\n")))
  309. (defun org-s5-export-as-html
  310. (&optional async subtreep visible-only body-only ext-plist)
  311. "Export current buffer to an HTML buffer.
  312. If narrowing is active in the current buffer, only export its
  313. narrowed part.
  314. If a region is active, export that region.
  315. A non-nil optional argument ASYNC means the process should happen
  316. asynchronously. The resulting buffer should be accessible
  317. through the `org-export-stack' interface.
  318. When optional argument SUBTREEP is non-nil, export the sub-tree
  319. at point, extracting information from the headline properties
  320. first.
  321. When optional argument VISIBLE-ONLY is non-nil, don't export
  322. contents of hidden elements.
  323. When optional argument BODY-ONLY is non-nil, only write code
  324. between \"<body>\" and \"</body>\" tags.
  325. EXT-PLIST, when provided, is a property list with external
  326. parameters overriding Org default settings, but still inferior to
  327. file-local settings.
  328. Export is done in a buffer named \"*Org S5 Export*\", which
  329. will be displayed when `org-export-show-temporary-export-buffer'
  330. is non-nil."
  331. (interactive)
  332. (org-export-to-buffer 's5 "*Org S5 Export*"
  333. async subtreep visible-only body-only ext-plist (lambda () (nxml-mode))))
  334. (defun org-s5-export-to-html
  335. (&optional async subtreep visible-only body-only ext-plist)
  336. "Export current buffer to a S5 HTML file.
  337. If narrowing is active in the current buffer, only export its
  338. narrowed part.
  339. If a region is active, export that region.
  340. A non-nil optional argument ASYNC means the process should happen
  341. asynchronously. The resulting file should be accessible through
  342. the `org-export-stack' interface.
  343. When optional argument SUBTREEP is non-nil, export the sub-tree
  344. at point, extracting information from the headline properties
  345. first.
  346. When optional argument VISIBLE-ONLY is non-nil, don't export
  347. contents of hidden elements.
  348. When optional argument BODY-ONLY is non-nil, only write code
  349. between \"<body>\" and \"</body>\" tags.
  350. EXT-PLIST, when provided, is a property list with external
  351. parameters overriding Org default settings, but still inferior to
  352. file-local settings.
  353. Return output file's name."
  354. (interactive)
  355. (let* ((extension (concat "." org-html-extension))
  356. (file (org-export-output-file-name extension subtreep))
  357. (org-export-coding-system org-html-coding-system))
  358. (org-export-to-file 's5 file
  359. async subtreep visible-only body-only ext-plist)))
  360. (defun org-s5-publish-to-html (plist filename pub-dir)
  361. "Publish an org file to S5 HTML Presentation.
  362. FILENAME is the filename of the Org file to be published. PLIST
  363. is the property list for the given project. PUB-DIR is the
  364. publishing directory.
  365. Return output file name."
  366. (org-publish-org-to 's5 filename ".html" plist pub-dir))
  367. (provide 'ox-s5)
  368. ;;; ox-s5.el ends here