| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 | ;;; ox-s5.el --- S5 Presentation Back-End for Org Export Engine;; Copyright (C) 2011-2013  Rick Frankel;; Author: Rick Frankel <emacs at rickster dot com>;; Keywords: outlines, hypermedia, S5, wp;; This file is not part of GNU Emacs.;; This program is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation, either version 3 of the License, or;; (at your option) any later version.;; This program is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with this program.  If not, see <http://www.gnu.org/licenses/>.;;; Commentary:;; This library implements an S5 Presentation back-end for the Org;; generic exporter.;; Installation;; ------------;; Get the s5 scripts from;;    http://meyerweb.com/eric/tools/s5/;; (Note that the default s5 version is set for using the alpha, 1.2a2.;; Copy the ui dir to somewhere reachable from your published presentation;; The default (`org-s5-ui-url') is set to "ui" (e.g., in the;; same directory as the html file).;; Usage;; -----;; Follow the general instructions at the above website. To generate;; incremental builds, you can set the HTML_CONTAINER_CLASS on an;; object to "incremental" to make it build. If you want an outline to;; build, set the :INCREMENTAL property on the parent headline.;; To test it, run:;;;;   M-x org-s5-export-as-html;;;; in an Org mode buffer.  See ox.el and ox-html.el for more details;; on how this exporter works.(require 'ox-html)(org-export-define-derived-backend s5 html  :menu-entry  (?s "Export to S5 HTML Presentation"      ((?H "To temporary buffer" org-s5-export-as-html)       (?h "To file" org-s5-export-to-html)       (?o "To file and open"	   (lambda (a s v b)	     (if a (org-s5-export-to-html t s v b)	       (org-open-file (org-s5-export-to-html nil s v b)))))))  :options-alist  ((:html-link-home "HTML_LINK_HOME" nil nil)   (:html-link-up "HTML_LINK_UP" nil nil)   (:html-postamble nil "html-postamble" nil t)   (:html-preamble nil "html-preamble" nil t)   (:html-head-include-default-style "HTML_INCLUDE_DEFAULT_STYLE" nil nil)   (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil nil)   (:s5-version "S5_VERSION" nil org-s5-version)   (:s5-theme-file "S5_THEME_FILE" nil org-s5-theme-file)   (:s5-ui-url "S5_UI_URL" nil org-s5-ui-url)   (:s5-default-view "S5_DEFAULT_VIEW" nil org-s5-default-view)   (:s5-control-visibility "S5_CONTROL_VISIBILITY" nil org-s5-control-visibility))  :translate-alist  ((headline . org-s5-headline)   (plain-list . org-s5-plain-list)   (inner-template . org-s5-inner-template)   (template . org-s5-template)))(defgroup org-export-s5 nil  "Options for exporting Org mode files to S5 HTML Presentations."  :tag "Org Export S5"  :group 'org-export-html)(defcustom org-s5-version "1.2a2"  "Version of s5 being used (for version metadata.) Defaults tos5 v2 alpha 2.Can be overridden with S5_VERSION."  :group 'org-export-s5  :type 'string)(defcustom org-s5-theme-file nil"Url to S5 theme (slides.css) file. Can be overriden with theS5_THEME_FILE property. If nil, defaults to`org-s5-ui-url'/default/slides.css. If it starts with anything but\"http\" or \"/\", it is used as-is. Otherwise the link in generatedrelative to `org-s5-ui-url'.The links for all other required stylesheets and scripts will begenerated relative to `org-s5-ui-url'/default."  :group 'org-export-s5  :type 'string)(defcustom org-s5-ui-url "ui"  "Base url to directory containing S5 \"default\" subdirectoryand the \"s5-notes.html\" file.Can be overriden with the S5_UI_URL property."  :group 'org-export-s5  :type 'string)(defcustom org-s5-default-view 'slideshow  "Setting for \"defaultView\" meta info."  :group 'org-export-s5  :type '(choice (const slideshow) (const outline)))(defcustom org-s5-control-visibility 'hidden  "Setting for \"controlVis\" meta info."  :group 'org-export-s5  :type '(choice (const hidden) (const visibile)))(defcustom org-s5-footer-template  "<div id=\"footer\"><h1>%author - %title</h1></div>"  "Format template to specify footer div. Completed using`org-fill-template'.Optional keys include %author, %email, %file, %title and %date.Note that the div id must be \"footer\"."  :group 'org-export-s5  :type 'string)(defcustom org-s5-header-template "<div id=\"header\"></div>"  "Format template to specify footer div. Completed using`org-fill-template'.Optional keys include %author, %email, %file, %title and %date.Note that the div id must be \"header\"."  :group 'org-export-s5  :type 'string)(defcustom org-s5-title-page-template  "<div class=\"slide title-page\"><h1>%title</h1><h1>%author</h1><h1>%email</h1><h1>%date</h1></div>"  "Format template to specify title page div. Completed using`org-fill-template'.Optional keys include %author, %email, %file, %title and %date.Note that the wrapper div must include the class \"slide\"."  :group 'org-export-s5  :type 'string)(defun org-s5--format-toc-headline (headline info)  "Return an appropriate table of contents entry for HEADLINE.Note that (currently) the S5 exporter does not support deep links,so the table of contents is not \"active\".INFO is a plist used as a communication channel."  (let* ((headline-number (org-export-get-headline-number headline info))	 (section-number	  (and (not (org-export-low-level-p headline info))	       (org-export-numbered-headline-p headline info)	       (concat (mapconcat 'number-to-string headline-number ".") ". ")))	 (tags (and (eq (plist-get info :with-tags) t)		    (org-export-get-tags headline info))))    (concat section-number	    (org-export-data	     (org-export-get-alt-title headline info) info)	    (and tags "   ") (org-html--tags tags))))(defun org-s5-toc (depth info)  (let* ((headlines (org-export-collect-headlines info depth))	 (toc-entries	  (mapcar (lambda (headline)		    (cons (org-s5--format-toc-headline headline info)			  (org-export-get-relative-level headline info)))		  (org-export-collect-headlines info depth))))    (when toc-entries      (concat       "<div id=\"table-of-contents\" class=\"slide\">\n"       (format "<h1>%s</h1>\n"	       (org-html--translate "Table of Contents" info))       "<div id=\"text-table-of-contents\">"       (org-html--toc-text toc-entries)       "</div>\n"       "</div>\n"))))(defun org-s5--build-head (info)  (let* ((dir (plist-get info :s5-ui-url))	 (theme (or (plist-get info :s5-theme-file) "default/slides.css")))    (mapconcat     'identity     (list      "<!-- style sheet links -->"      (mapconcat       (lambda (list)	 (format	  (concat	   "<link rel='stylesheet' href='%s/default/%s' type='text/css'"	   " media='%s' id='%s' />")	  dir (nth 0 list) (nth 1 list) (nth 2 list)))       (list	'("outline.css" "screen" "outlineStyle")	'("print.css" "print" "slidePrint")	'("opera.css" "projection" "operaFix")) "\n")      (format (concat	       "<link rel='stylesheet' href='%s' type='text/css'"	       " media='screen' id='slideProj' />")	      (if (string-match-p "^\\(http\\|/\\)" theme) theme		(concat dir "/" theme)))      "<!-- S5 JS -->"      (concat       "<script src='" dir       "/default/slides.js' type='text/javascript'></script>")) "\n")))(defun org-s5--build-meta-info (info)  (concat   (org-html--build-meta-info info)   (format "<meta name=\"version\" content=\"S5 %s\" />\n"	   (plist-get info :s5-version))   (format "<meta name='defaultView' content='%s' />\n"           (plist-get info :s5-default-view))   (format "<meta name='controlVis' content='%s' />"           (plist-get info :s5-control-visibility))))(defun org-s5-headline (headline contents info)  (let ((org-html-toplevel-hlevel 1)        (class (or (org-element-property :HTML_CONTAINER_CLASS headline) ""))        (level (org-export-get-relative-level headline info)))    (when (and (= 1 level) (not (string-match-p "\\<slide\\>" class)))      (org-element-put-property headline :HTML_CONTAINER_CLASS (concat class " slide")))    (org-html-headline headline contents info)))(defun org-s5-plain-list (plain-list contents info)  "Transcode a PLAIN-LIST element from Org to HTML.CONTENTS is the contents of the list.  INFO is a plist holdingcontextual information.If a containing headline has the property :INCREMENTAL,then the \"incremental\" class will be added to the to the list,which will make the list into a \"build\"."  (let* ((type (org-element-property :type plain-list))	(tag (case type	       (ordered "ol")	       (unordered "ul")	       (descriptive "dl"))))    (format "%s\n%s%s"	    (format	     "<%s class='org-%s%s'>" tag tag	     (if (org-export-get-node-property :INCREMENTAL plain-list t)		 " incremental" ""))	    contents (org-html-end-plain-list type))))(defun org-s5-template-alist (info)  `(   ("title"  . ,(car (plist-get info :title)))   ("author" . ,(car (plist-get info :author)))   ("email"  . ,(plist-get info :email))   ("date"   . ,(nth 0 (plist-get info :date)))   ("file"   . ,(plist-get info :input-file))))(defun org-s5-inner-template (contents info)  "Return body of document string after HTML conversion.CONTENTS is the transcoded contents string.  INFO is a plistholding export options."  (concat contents "\n"))(defun org-s5-template (contents info)  "Return complete document string after HTML conversion.CONTENTS is the transcoded contents string.  INFO is a plistholding export options."  (mapconcat   'identity   (list    "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"	\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"    (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">"	    (plist-get info :language) (plist-get info :language))    "<head>"    (org-s5--build-meta-info info)    (org-s5--build-head info)    (org-html--build-head info)    (org-html--build-mathjax-config info)    "</head>"    "<body>"    "<div class=\"layout\">"    "<div id=\"controls\"><!-- no edit --></div>"    "<div id=\"currentSlide\"><!-- no edit --></div>"    (org-fill-template     org-s5-header-template (org-s5-template-alist info))    (org-fill-template     org-s5-footer-template (org-s5-template-alist info))    "</div>"    (format "<div id=\"%s\" class=\"presentation\">" (nth 1 org-html-divs))    ;; title page    (org-fill-template     org-s5-title-page-template (org-s5-template-alist info))    ;; table of contents.    (let ((depth (plist-get info :with-toc)))      (when depth (org-s5-toc depth info)))    contents    "</div>"    "</body>"    "</html>\n") "\n"))(defun org-s5-export-as-html  (&optional async subtreep visible-only body-only ext-plist)  "Export current buffer to an HTML buffer.If narrowing is active in the current buffer, only export itsnarrowed part.If a region is active, export that region.A non-nil optional argument ASYNC means the process should happenasynchronously.  The resulting buffer should be accessiblethrough the `org-export-stack' interface.When optional argument SUBTREEP is non-nil, export the sub-treeat point, extracting information from the headline propertiesfirst.When optional argument VISIBLE-ONLY is non-nil, don't exportcontents of hidden elements.When optional argument BODY-ONLY is non-nil, only write codebetween \"<body>\" and \"</body>\" tags.EXT-PLIST, when provided, is a property list with externalparameters overriding Org default settings, but still inferior tofile-local settings.Export is done in a buffer named \"*Org S5 Export*\", whichwill be displayed when `org-export-show-temporary-export-buffer'is non-nil."  (interactive)  (if async      (org-export-async-start	  (lambda (output)	    (with-current-buffer (get-buffer-create "*Org S5 Export*")	      (erase-buffer)	      (insert output)	      (goto-char (point-min))	      (nxml-mode)	      (org-export-add-to-stack (current-buffer) 's5)))	`(org-export-as 's5 ,subtreep ,visible-only ,body-only ',ext-plist))    (let ((outbuf (org-export-to-buffer		   's5 "*Org S5 Export*"		   subtreep visible-only body-only ext-plist)))      ;; Set major mode.      (with-current-buffer outbuf (nxml-mode))      (when org-export-show-temporary-export-buffer	(switch-to-buffer-other-window outbuf)))))(defun org-s5-export-to-html  (&optional async subtreep visible-only body-only ext-plist)  "Export current buffer to a S5 HTML file.If narrowing is active in the current buffer, only export itsnarrowed part.If a region is active, export that region.A non-nil optional argument ASYNC means the process should happenasynchronously.  The resulting file should be accessible throughthe `org-export-stack' interface.When optional argument SUBTREEP is non-nil, export the sub-treeat point, extracting information from the headline propertiesfirst.When optional argument VISIBLE-ONLY is non-nil, don't exportcontents of hidden elements.When optional argument BODY-ONLY is non-nil, only write codebetween \"<body>\" and \"</body>\" tags.EXT-PLIST, when provided, is a property list with externalparameters overriding Org default settings, but still inferior tofile-local settings.Return output file's name."  (interactive)  (let* ((extension (concat "." org-html-extension))	 (file (org-export-output-file-name extension subtreep))	 (org-export-coding-system org-html-coding-system))    (if async	(org-export-async-start	    (lambda (f) (org-export-add-to-stack f 's5))	  (let ((org-export-coding-system org-html-coding-system))	    `(expand-file-name	      (org-export-to-file	       's5 ,file ,subtreep ,visible-only ,body-only ',ext-plist))))      (let ((org-export-coding-system org-html-coding-system))	(org-export-to-file	 's5 file subtreep visible-only body-only ext-plist)))))(defun org-s5-publish-to-html (plist filename pub-dir)  "Publish an org file to S5 HTML Presentation.FILENAME is the filename of the Org file to be published.  PLISTis the property list for the given project.  PUB-DIR is thepublishing directory.Return output file name."  (org-publish-org-to 's5 filename ".html" plist pub-dir))(provide 'ox-s5);;; ox-s5.el ends here
 |