ox-s5.el 14 KB

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