ox-s5.el 15 KB

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