ox-s5.el 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. ;;; ox-s5.el --- S5 Presentation Back-End for Org Export Engine
  2. ;; Copyright (C) 2011-2013 Rick Frankel
  3. ;; Author: Rick Frankel <emacs at rickster dot com>
  4. ;; Keywords: outlines, hypermedia, S5, wp
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; This library implements an S5 Presentation back-end for the Org
  17. ;; generic exporter.
  18. ;; Installation
  19. ;; ------------
  20. ;; Get the s5 scripts from
  21. ;; http://meyerweb.com/eric/tools/s5/
  22. ;; (Note that the default s5 version is set for using the alpha, 1.2a2.
  23. ;; Copy the ui dir to somewhere reachable from your published presentation
  24. ;; The default (`org-s5-ui-url') is set to "ui" (e.g., in the
  25. ;; same directory as the html file).
  26. ;; Usage
  27. ;; -----
  28. ;; Follow the general instructions at the above website. To generate
  29. ;; incremental builds, you can set the HTML_CONTAINER_CLASS on an
  30. ;; object to "incremental" to make it build. If you want an outline to
  31. ;; build, set the :INCREMENTAL property on the parent headline.
  32. ;; To test it, run:
  33. ;;
  34. ;; M-x org-s5-export-as-html
  35. ;;
  36. ;; in an Org mode buffer. See ox.el and ox-html.el for more details
  37. ;; on how this exporter works.
  38. (require 'ox-html)
  39. (org-export-define-derived-backend s5 html
  40. :menu-entry
  41. (?s "Export to S5 HTML Presentation"
  42. ((?H "To temporary buffer" org-s5-export-as-html)
  43. (?h "To file" org-s5-export-to-html)
  44. (?o "To file and open"
  45. (lambda (a s v b)
  46. (if a (org-s5-export-to-html t s v b)
  47. (org-open-file (org-s5-export-to-html nil s v b)))))))
  48. :options-alist
  49. ((:html-link-home "HTML_LINK_HOME" nil nil)
  50. (:html-link-up "HTML_LINK_UP" nil nil)
  51. (:html-mathjax "HTML_MATHJAX" nil "" space)
  52. (:html-postamble nil "html-postamble" nil t)
  53. (:html-preamble nil "html-preamble" nil t)
  54. (:html-style-extra "HTML_STYLE" nil org-html-style-extra newline)
  55. (:html-style-include-default "HTML_INCLUDE_DEFAULT" nil nil)
  56. (:html-style-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 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. (defcustom org-s5-footer-template
  102. "<div id=\"footer\">
  103. <h1>%author - %title</h1>
  104. </div>"
  105. "Format template to specify footer div. Completed using
  106. `org-fill-template'.
  107. Optional keys include %author, %email, %file, %title and %date.
  108. Note that the div id must be \"footer\"."
  109. :group 'org-export-s5
  110. :type 'string)
  111. (defcustom org-s5-header-template "<div id=\"header\"></div>"
  112. "Format template to specify footer div. Completed using
  113. `org-fill-template'.
  114. Optional keys include %author, %email, %file, %title and %date.
  115. Note that the div id must be \"header\"."
  116. :group 'org-export-s5
  117. :type 'string)
  118. (defcustom org-s5-title-page-template
  119. "<div class=\"slide title-page\">
  120. <h1>%title</h1>
  121. <h1>%author</h1>
  122. <h1>%email</h1>
  123. <h1>%date</h1>
  124. </div>"
  125. "Format template to specify title page div. Completed using
  126. `org-fill-template'.
  127. Optional keys include %author, %email, %file, %title and %date.
  128. Note that the wrapper div must include the class \"slide\"."
  129. :group 'org-export-s5
  130. :type 'string)
  131. (defun org-s5--format-toc-headline (headline info)
  132. "Return an appropriate table of contents entry for HEADLINE.
  133. Note that (currently) the S5 exporter does not support deep links,
  134. so the table of contents is not \"active\".
  135. INFO is a plist used as a communication channel."
  136. (let* ((headline-number (org-export-get-headline-number headline info))
  137. (section-number
  138. (and (not (org-export-low-level-p headline info))
  139. (org-export-numbered-headline-p headline info)
  140. (concat (mapconcat 'number-to-string headline-number ".") ". ")))
  141. (tags (and (eq (plist-get info :with-tags) t)
  142. (org-export-get-tags headline info))))
  143. (concat section-number
  144. (org-export-data
  145. (org-export-get-alt-title headline info) info)
  146. (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags))))
  147. (defun org-s5-toc (depth info)
  148. (let* ((headlines (org-export-collect-headlines info depth))
  149. (toc-entries
  150. (mapcar (lambda (headline)
  151. (cons (org-s5--format-toc-headline headline info)
  152. (org-export-get-relative-level headline info)))
  153. (org-export-collect-headlines info depth))))
  154. (when toc-entries
  155. (concat
  156. "<div id=\"table-of-contents\" class=\"slide\">\n"
  157. (format "<h1>%s</h1>\n"
  158. (org-html--translate "Table of Contents" info))
  159. "<div id=\"text-table-of-contents\">"
  160. (org-html--toc-text toc-entries)
  161. "</div>\n"
  162. "</div>\n"))))
  163. (defun org-s5--build-style (info)
  164. (let* ((dir (plist-get info :s5-ui-url))
  165. (theme (or (plist-get info :s5-theme-file) "default/slides.css")))
  166. (mapconcat
  167. 'identity
  168. (list
  169. "<!-- style sheet links -->"
  170. (mapconcat
  171. (lambda (list)
  172. (format
  173. (concat
  174. "<link rel='stylesheet' href='%s/default/%s' type='text/css'"
  175. " media='%s' id='%s' />")
  176. dir (nth 0 list) (nth 1 list) (nth 2 list)))
  177. (list
  178. '("outline.css" "screen" "outlineStyle")
  179. '("print.css" "print" "slidePrint")
  180. '("opera.css" "projection" "operaFix")) "\n")
  181. (format (concat
  182. "<link rel='stylesheet' href='%s' type='text/css'"
  183. " media='screen' id='slideProj' />")
  184. (if (string-match-p "^\\(http\\|/\\)" theme) theme
  185. (concat dir "/" theme)))
  186. "<!-- S5 JS -->"
  187. (concat
  188. "<script src='" dir
  189. "/default/slides.js' type='text/javascript'></script>")) "\n")))
  190. (defun org-s5--build-meta-info (info)
  191. (concat
  192. (org-html--build-meta-info info)
  193. (format "<meta name=\"version\" content=\"S5 %s\" />\n"
  194. (plist-get info :s5-version))
  195. (format "<meta name='defaultView' content='%s' />\n"
  196. (plist-get info :s5-default-view))
  197. (format "<meta name='controlVis' content='%s' />"
  198. (plist-get info :s5-control-visibility))))
  199. (defun org-s5-headline (headline contents info)
  200. (let ((org-html-toplevel-hlevel 1)
  201. (class (or (org-element-property :HTML_CONTAINER_CLASS headline) ""))
  202. (level (org-export-get-relative-level headline info)))
  203. (when (and (= 1 level) (not (string-match-p "\\<slide\\>" class)))
  204. (org-element-put-property headline :HTML_CONTAINER_CLASS (concat class " slide")))
  205. (org-html-headline headline contents info)))
  206. (defun org-s5-plain-list (plain-list contents info)
  207. "Transcode a PLAIN-LIST element from Org to HTML.
  208. CONTENTS is the contents of the list. INFO is a plist holding
  209. contextual information.
  210. If a containing headline has the property :INCREMENTAL,
  211. then the \"incremental\" class will be added to the to the list,
  212. which will make the list into a \"build\"."
  213. (let* ((type (org-element-property :type plain-list))
  214. (tag (case type
  215. (ordered "ol")
  216. (unordered "ul")
  217. (descriptive "dl"))))
  218. (format "%s\n%s%s"
  219. (format
  220. "<%s class='org-%s%s'>" tag tag
  221. (if (org-export-get-node-property :INCREMENTAL plain-list t)
  222. " incremental" ""))
  223. contents (org-html-end-plain-list type))))
  224. (defun org-s5-template-alist (info)
  225. `(
  226. ("title" . ,(car (plist-get info :title)))
  227. ("author" . ,(car (plist-get info :author)))
  228. ("email" . ,(plist-get info :email))
  229. ("date" . ,(nth 0 (plist-get info :date)))
  230. ("file" . ,(plist-get info :input-file))))
  231. (defun org-s5-inner-template (contents info)
  232. "Return body of document string after HTML conversion.
  233. CONTENTS is the transcoded contents string. INFO is a plist
  234. holding export options."
  235. (concat contents "\n"))
  236. (defun org-s5-template (contents info)
  237. "Return complete document string after HTML conversion.
  238. CONTENTS is the transcoded contents string. INFO is a plist
  239. holding export options."
  240. (mapconcat
  241. 'identity
  242. (list
  243. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  244. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  245. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">"
  246. (plist-get info :language) (plist-get info :language))
  247. "<head>"
  248. (org-s5--build-meta-info info)
  249. (org-s5--build-style info)
  250. (org-html--build-style info)
  251. (org-html--build-mathjax-config info)
  252. "</head>"
  253. "<body>"
  254. "<div class=\"layout\">"
  255. "<div id=\"controls\"><!-- no edit --></div>"
  256. "<div id=\"currentSlide\"><!-- no edit --></div>"
  257. (org-fill-template
  258. org-s5-header-template (org-s5-template-alist info))
  259. (org-fill-template
  260. org-s5-footer-template (org-s5-template-alist info))
  261. "</div>"
  262. (format "<div id=\"%s\" class=\"presentation\">" (nth 1 org-html-divs))
  263. ;; title page
  264. (org-fill-template
  265. org-s5-title-page-template (org-s5-template-alist info))
  266. ;; table of contents.
  267. (let ((depth (plist-get info :with-toc)))
  268. (when depth (org-s5-toc depth info)))
  269. contents
  270. "</div>"
  271. "</body>"
  272. "</html>\n") "\n"))
  273. (defun org-s5-export-as-html
  274. (&optional async subtreep visible-only body-only ext-plist)
  275. "Export current buffer to an HTML buffer.
  276. If narrowing is active in the current buffer, only export its
  277. narrowed part.
  278. If a region is active, export that region.
  279. A non-nil optional argument ASYNC means the process should happen
  280. asynchronously. The resulting buffer should be accessible
  281. through the `org-export-stack' interface.
  282. When optional argument SUBTREEP is non-nil, export the sub-tree
  283. at point, extracting information from the headline properties
  284. first.
  285. When optional argument VISIBLE-ONLY is non-nil, don't export
  286. contents of hidden elements.
  287. When optional argument BODY-ONLY is non-nil, only write code
  288. between \"<body>\" and \"</body>\" tags.
  289. EXT-PLIST, when provided, is a property list with external
  290. parameters overriding Org default settings, but still inferior to
  291. file-local settings.
  292. Export is done in a buffer named \"*Org S5 Export*\", which
  293. will be displayed when `org-export-show-temporary-export-buffer'
  294. is non-nil."
  295. (interactive)
  296. (if async
  297. (org-export-async-start
  298. (lambda (output)
  299. (with-current-buffer (get-buffer-create "*Org S5 Export*")
  300. (erase-buffer)
  301. (insert output)
  302. (goto-char (point-min))
  303. (nxml-mode)
  304. (org-export-add-to-stack (current-buffer) 's5)))
  305. `(org-export-as 's5 ,subtreep ,visible-only ,body-only ',ext-plist))
  306. (let ((outbuf (org-export-to-buffer
  307. 's5 "*Org S5 Export*"
  308. subtreep visible-only body-only ext-plist)))
  309. ;; Set major mode.
  310. (with-current-buffer outbuf (nxml-mode))
  311. (when org-export-show-temporary-export-buffer
  312. (switch-to-buffer-other-window outbuf)))))
  313. (defun org-s5-export-to-html
  314. (&optional async subtreep visible-only body-only ext-plist)
  315. "Export current buffer to a S5 HTML file.
  316. If narrowing is active in the current buffer, only export its
  317. narrowed part.
  318. If a region is active, export that region.
  319. A non-nil optional argument ASYNC means the process should happen
  320. asynchronously. The resulting file should be accessible through
  321. the `org-export-stack' interface.
  322. When optional argument SUBTREEP is non-nil, export the sub-tree
  323. at point, extracting information from the headline properties
  324. first.
  325. When optional argument VISIBLE-ONLY is non-nil, don't export
  326. contents of hidden elements.
  327. When optional argument BODY-ONLY is non-nil, only write code
  328. between \"<body>\" and \"</body>\" tags.
  329. EXT-PLIST, when provided, is a property list with external
  330. parameters overriding Org default settings, but still inferior to
  331. file-local settings.
  332. Return output file's name."
  333. (interactive)
  334. (let* ((extension (concat "." org-html-extension))
  335. (file (org-export-output-file-name extension subtreep))
  336. (org-export-coding-system org-html-coding-system))
  337. (if async
  338. (org-export-async-start
  339. (lambda (f) (org-export-add-to-stack f 's5))
  340. (let ((org-export-coding-system org-html-coding-system))
  341. `(expand-file-name
  342. (org-export-to-file
  343. 's5 ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
  344. (let ((org-export-coding-system org-html-coding-system))
  345. (org-export-to-file
  346. 's5 file subtreep visible-only body-only ext-plist)))))
  347. (defun org-s5-publish-to-html (plist filename pub-dir)
  348. "Publish an org file to S5 HTML Presentation.
  349. FILENAME is the filename of the Org file to be published. PLIST
  350. is the property list for the given project. PUB-DIR is the
  351. publishing directory.
  352. Return output file name."
  353. (org-publish-org-to 's5 filename ".html" plist pub-dir))
  354. (provide 'ox-s5)