ox-s5.el 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. :translate-alist
  61. ((headline . org-s5-headline)
  62. (plain-list . org-s5-plain-list)
  63. (template . org-s5-template)))
  64. (defgroup org-export-s5 nil
  65. "Options for exporting Org mode files to S5 HTML Presentations."
  66. :tag "Org Export S5"
  67. :group 'org-export-html)
  68. (defcustom org-s5-version "1.2a2"
  69. "Version of s5 being used (for version metadata.) Defaults to
  70. s5 v2 alpha 2.
  71. Can be overridden with S5_VERSION."
  72. :group 'org-export-s5
  73. :type 'string)
  74. (defcustom org-s5-theme-file nil
  75. "Url to S5 theme (slides.css) file. Can be overriden with the
  76. S5_THEME_FILE property. If nil, defaults to
  77. `org-s5-ui-url'/default/slides.css. If it starts with anything but
  78. \"http\" or \"/\", it is used as-is. Otherwise the link in generated
  79. relative to `org-s5-ui-url'.
  80. The links for all other required stylesheets and scripts will be
  81. generated relative to `org-s5-ui-url'/default."
  82. :group 'org-export-s5
  83. :type 'string)
  84. (defcustom org-s5-ui-url "ui"
  85. "Base url to directory containing S5 \"default\" subdirectory
  86. and the \"s5-notes.html\" file.
  87. Can be overriden with the S5_UI_URL property."
  88. :group 'org-export-s5
  89. :type 'string)
  90. (defcustom org-s5-default-view 'slideshow
  91. "Setting for \"defaultView\" meta info."
  92. :group 'org-export-s5
  93. :type '(choice (const slideshow) (const outline)))
  94. (defcustom org-s5-control-visibility 'hidden
  95. "Setting for \"controlVis\" meta info."
  96. :group 'org-export-s5
  97. :type '(choice (const hidden) (const visibile)))
  98. (defcustom org-s5-footer-template
  99. "<div id=\"footer\">
  100. <h1>%author - %title</h1>
  101. </div>"
  102. "Format template to specify footer div. Completed using
  103. `org-fill-template'.
  104. Optional keys include %author, %email, %file, %title and %date.
  105. Note that the div id must be \"footer\"."
  106. :group 'org-export-s5
  107. :type 'string)
  108. (defcustom org-s5-header-template "<div id=\"header\"></div>"
  109. "Format template to specify footer div. Completed using
  110. `org-fill-template'.
  111. Optional keys include %author, %email, %file, %title and %date.
  112. Note that the div id must be \"header\"."
  113. :group 'org-export-s5
  114. :type 'string)
  115. (defcustom org-s5-title-page-template
  116. "<div class=\"slide title-page\">
  117. <h1>%title</h1>
  118. <h1>%author</h1>
  119. <h1>%email</h1>
  120. <h1>%date</h1>
  121. </div>"
  122. "Format template to specify title page div. Completed using
  123. `org-fill-template'.
  124. Optional keys include %author, %email, %file, %title and %date.
  125. Note that the wrapper div must include the class \"slide\"."
  126. :group 'org-export-s5
  127. :type 'string)
  128. (defun org-s5-toc (depth info)
  129. (let* ((headlines (org-export-collect-headlines info depth))
  130. (toc-entries
  131. (loop for headline in headlines collect
  132. (list (org-html-format-headline--wrap
  133. headline info 'org-html-format-toc-headline)
  134. (org-export-get-relative-level headline info)))))
  135. (when toc-entries
  136. (concat
  137. "<div id=\"table-of-contents\" class=\"slide\">\n"
  138. (format "<h1>%s</h1>\n"
  139. (org-html--translate "Table of Contents" info))
  140. "<div id=\"text-table-of-contents\">"
  141. (org-html-toc-text toc-entries)
  142. "</div>\n"
  143. "</div>\n"))))
  144. (defun org-s5--build-style (info)
  145. (let* ((dir (plist-get info :s5-ui-url))
  146. (theme (or (plist-get info :s5-theme-file) "default/slides.css")))
  147. (mapconcat
  148. 'identity
  149. (list
  150. "<!-- style sheet links -->"
  151. (mapconcat
  152. (lambda (list)
  153. (format
  154. (concat
  155. "<link rel='stylesheet' href='%s/default/%s' type='text/css'"
  156. " media='%s' id='%s' />")
  157. dir (nth 0 list) (nth 1 list) (nth 2 list)))
  158. (list
  159. '("outline.css" "screen" "outlineStyle")
  160. '("print.css" "print" "slidePrint")
  161. '("opera.css" "projection" "operaFix")) "\n")
  162. (format (concat
  163. "<link rel='stylesheet' href='%s' type='text/css'"
  164. " media='screen' id='slideProj' />")
  165. (if (string-match-p "^\\(http\\|/\\)" theme) theme
  166. (concat dir "/" theme)))
  167. "<!-- S5 JS -->"
  168. (concat
  169. "<script src='" dir
  170. "/default/slides.js' type='text/javascript'></script>")) "\n")))
  171. (defun org-s5--build-meta-info (info)
  172. (concat
  173. (org-html--build-meta-info info)
  174. (format "<meta name=\"version\" content=\"S5 %s\" />"
  175. (plist-get info :s5-version))
  176. "<meta name='defaultView' content='slideshow' />\n"
  177. "<meta name='controlVis' content='hidden' />"))
  178. (defun org-s5-headline (headline contents info)
  179. (let ((org-html-toplevel-hlevel 1))
  180. (org-html-headline
  181. (if (= 1 (+ (org-element-property :level headline)
  182. (plist-get info :headline-offset)))
  183. (org-element-put-property
  184. headline :html-container-class
  185. (mapconcat 'identity
  186. (list
  187. (org-element-property
  188. :html-container-class headline)
  189. "slide") " "))
  190. headline) contents info)))
  191. (defun org-s5-plain-list (plain-list contents info)
  192. "Transcode a PLAIN-LIST element from Org to HTML.
  193. CONTENTS is the contents of the list. INFO is a plist holding
  194. contextual information.
  195. If a containing headline has the property :incremental,
  196. then the \"incremental\" class will be added to the to the list,
  197. which will make the list into a \"build\"."
  198. (let* ((type (org-element-property :type plain-list))
  199. (tag (case type
  200. (ordered "ol")
  201. (unordered "ul")
  202. (descriptive "dl"))))
  203. (format "%s\n%s%s"
  204. (format
  205. "<%s class='org-%s%s'>" tag tag
  206. (if (org-export-get-node-property :incremental plain-list t)
  207. " incremental" ""))
  208. contents (org-html-end-plain-list type))))
  209. (defun org-s5-template-alist (info)
  210. `(
  211. ("title" . ,(car (plist-get info :title)))
  212. ("author" . ,(car (plist-get info :author)))
  213. ("email" . ,(plist-get info :email))
  214. ("date" . ,(substring (nth 0 (plist-get info :date)) 0 10))
  215. ("file" . ,(plist-get info :input-file))))
  216. (defun org-s5-template (contents info)
  217. "Return complete document string after HTML conversion.
  218. CONTENTS is the transcoded contents string. INFO is a plist
  219. holding export options."
  220. (mapconcat
  221. 'identity
  222. (list
  223. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  224. \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
  225. (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">"
  226. (plist-get info :language) (plist-get info :language))
  227. "<head>"
  228. (org-s5--build-meta-info info)
  229. (org-s5--build-style info)
  230. (org-html--build-style info)
  231. (org-html--build-mathjax-config info)
  232. "</head>"
  233. "<body>"
  234. "<div class=\"layout\">"
  235. "<div id=\"controls\"><!-- no edit --></div>"
  236. "<div id=\"currentSlide\"><!-- no edit --></div>"
  237. (org-fill-template
  238. org-s5-header-template (org-s5-template-alist info))
  239. (org-fill-template
  240. org-s5-footer-template (org-s5-template-alist info))
  241. "</div>"
  242. (format "<div id=\"%s\" class=\"presentation\">" (nth 1 org-html-divs))
  243. ;; title page
  244. (org-fill-template
  245. org-s5-title-page-template (org-s5-template-alist info))
  246. (let ((depth (plist-get info :with-toc)))
  247. (when depth (org-s5-toc depth info)))
  248. contents
  249. "</div>"
  250. "</body>"
  251. "</html>\n") "\n"))
  252. (defun org-s5-export-as-html
  253. (&optional async subtreep visible-only body-only ext-plist)
  254. "Export current buffer to an HTML buffer.
  255. If narrowing is active in the current buffer, only export its
  256. narrowed part.
  257. If a region is active, export that region.
  258. A non-nil optional argument ASYNC means the process should happen
  259. asynchronously. The resulting buffer should be accessible
  260. through the `org-export-stack' interface.
  261. When optional argument SUBTREEP is non-nil, export the sub-tree
  262. at point, extracting information from the headline properties
  263. first.
  264. When optional argument VISIBLE-ONLY is non-nil, don't export
  265. contents of hidden elements.
  266. When optional argument BODY-ONLY is non-nil, only write code
  267. between \"<body>\" and \"</body>\" tags.
  268. EXT-PLIST, when provided, is a property list with external
  269. parameters overriding Org default settings, but still inferior to
  270. file-local settings.
  271. Export is done in a buffer named \"*Org S5 Export*\", which
  272. will be displayed when `org-export-show-temporary-export-buffer'
  273. is non-nil."
  274. (interactive)
  275. (if async
  276. (org-export-async-start
  277. (lambda (output)
  278. (with-current-buffer (get-buffer-create "*Org S5 Export*")
  279. (erase-buffer)
  280. (insert output)
  281. (goto-char (point-min))
  282. (nxml-mode)
  283. (org-export-add-to-stack (current-buffer) 's5)))
  284. `(org-export-as 's5 ,subtreep ,visible-only ,body-only ',ext-plist))
  285. (let ((outbuf (org-export-to-buffer
  286. 's5 "*Org S5 Export*"
  287. subtreep visible-only body-only ext-plist)))
  288. ;; Set major mode.
  289. (with-current-buffer outbuf (nxml-mode))
  290. (when org-export-show-temporary-export-buffer
  291. (switch-to-buffer-other-window outbuf)))))
  292. (defun org-s5-export-to-html
  293. (&optional async subtreep visible-only body-only ext-plist)
  294. "Export current buffer to a S5 HTML file.
  295. If narrowing is active in the current buffer, only export its
  296. narrowed part.
  297. If a region is active, export that region.
  298. A non-nil optional argument ASYNC means the process should happen
  299. asynchronously. The resulting file should be accessible through
  300. the `org-export-stack' interface.
  301. When optional argument SUBTREEP is non-nil, export the sub-tree
  302. at point, extracting information from the headline properties
  303. first.
  304. When optional argument VISIBLE-ONLY is non-nil, don't export
  305. contents of hidden elements.
  306. When optional argument BODY-ONLY is non-nil, only write code
  307. between \"<body>\" and \"</body>\" tags.
  308. EXT-PLIST, when provided, is a property list with external
  309. parameters overriding Org default settings, but still inferior to
  310. file-local settings.
  311. Return output file's name."
  312. (interactive)
  313. (let* ((extension (concat "." org-html-extension))
  314. (file (org-export-output-file-name extension subtreep))
  315. (org-export-coding-system org-html-coding-system))
  316. (if async
  317. (org-export-async-start
  318. (lambda (f) (org-export-add-to-stack f 's5))
  319. (let ((org-export-coding-system org-html-coding-system))
  320. `(expand-file-name
  321. (org-export-to-file
  322. 's5 ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
  323. (let ((org-export-coding-system org-html-coding-system))
  324. (org-export-to-file
  325. 's5 file subtreep visible-only body-only ext-plist)))))
  326. (defun org-s5-publish-to-html (plist filename pub-dir)
  327. "Publish an org file to S5 HTML Presentation.
  328. FILENAME is the filename of the Org file to be published. PLIST
  329. is the property list for the given project. PUB-DIR is the
  330. publishing directory.
  331. Return output file name."
  332. (org-publish-org-to 's5 filename ".html" plist pub-dir))
  333. (provide 'ox-s5)