ox-s5.el 14 KB

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