ox-s5.el 15 KB

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