emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 5088a6165bf00bcbdb1b94626207e547c16818da 15992 bytes (raw)
name: contrib/lisp/ox-s5.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
 
;;; ox-s5.el --- S5 Presentation Back-End for Org Export Engine

;; Copyright (C) 2011-2014  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.

;; TODOs
;; ------
;; The title page is formatted using format-spec.  This is error prone
;; when details are missing and may insert empty tags, like <h2></h2>,
;; for missing values.

(require 'ox-html)
(eval-when-compile (require 'cl-lib))

(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)
    (:s5-postamble "S5_POSTAMBLE" nil org-s5-postamble newline)
    (:s5-preamble "S5_PREAMBLE" nil org-s5-preamble newline)
    (: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 to
s5 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 overridden with the
S5_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 generated
relative to `org-s5-ui-url'.
The links for all other required stylesheets and scripts will be
generated 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\" subdirectory
and the \"s5-notes.html\" file.
Can be overridden 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)))

(defvar org-s5--divs
  '((preamble  "div" "header")
    (content   "div" "content")
    (postamble "div" "footer"))
  "Alist of the three section elements for HTML export.
The car of each entry is one of 'preamble, 'content or 'postamble.
The cdrs of each entry are the ELEMENT_TYPE and ID for each
section of the exported document.

If you set `org-html-container-element' to \"li\", \"ol\" will be
uses as the content ELEMENT_TYPE, generating an XOXO format
slideshow.

Note that changing the preamble or postamble will break the
core S5 stylesheets.")

(defcustom org-s5-postamble "<h1>%a - %t</h1>"
  "Preamble inserted into the S5 layout section.
When set to a string, use this string as the postamble.

When set to a function, apply this function and insert the
returned string.  The function takes the property list of export
options as its only argument.

Setting the S5_POSTAMBLE option -- or the :s5-postamble in publishing
projects -- will take precedence over this variable.

Note that the default css styling will break if this is set to nil
or an empty string."
  :group 'org-export-s5
  :type '(choice (const :tag "No postamble" "&#x20;")
		 (string :tag "Custom formatting string")
		 (function :tag "Function (must return a string)")))

(defcustom org-s5-preamble "&#x20;"
  "Peamble inserted into the S5 layout section.

When set to a string, use this string as the preamble.

When set to a function, apply this function and insert the
returned string.  The function takes the property list of export
options as its only argument.

Setting S5_PREAMBLE option -- or the :s5-preamble in publishing
projects -- will take precedence over this variable.

Note that the default css styling will break if this is set to nil
or an empty string."
  :group 'org-export-s5
  :type '(choice (const :tag "No preamble" "&#x20;")
		 (string :tag "Custom formatting string")
		 (function :tag "Function (must return a string)")))

(defcustom org-s5-title-slide-template
  "<h1>%t</h1>
<h2>%s</h2>
<h2>%a</h2>
<h3>%e</h3>
<h4>%d</h4>"
  "Format template to specify title page section.
See `org-html-postamble-format' for the valid elements which
can be included.

It will be wrapped in the element defined in the :html-container
property, and defaults to the value of `org-html-container-element',
and have the id \"title-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 "&nbsp;&nbsp;&nbsp;") (org-html--tags tags info))))

(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
       (format "<%s id='table-of-contents' class='slide'>\n"
               (plist-get info :html-container))
       (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"
       (format "</%s>\n" (plist-get info :html-container))))))

(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 holding
contextual 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
	    (format "</%s>" tag))))

(defun org-s5-inner-template (contents info)
  "Return body of document string after HTML conversion.
CONTENTS is the transcoded contents string.  INFO is a plist
holding 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 plist
holding export options."
  (let ((info (plist-put
	       (plist-put
		(plist-put info :html-preamble (plist-get info :s5-preamble))
		:html-postamble
		(plist-get info :s5-postamble))
	       :html-divs
	       (if (equal "li" (plist-get info :html-container))
		   (cons '(content "ol" "content") org-s5--divs)
		 org-s5--divs))))
    (mapconcat
     'identity
     (list
      (org-html-doctype info)
      (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-html--build-pre/postamble 'preamble info)
      (org-html--build-pre/postamble 'postamble info)
      "</div>"
      (format "<%s id=\"%s\" class=\"presentation\">"
	      (nth 1 (assq 'content org-html-divs))
	      (nth 2 (assq 'content org-html-divs)))
      ;; title page
      (format "<%s id='title-slide' class='slide'>"
	      (plist-get info :html-container))
      (format-spec org-s5-title-slide-template (org-html-format-spec info))
      (format "</%s>" (plist-get info :html-container))
      ;; table of contents.
      (let ((depth (plist-get info :with-toc)))
	(when depth (org-s5-toc depth info)))
      contents
      (format "</%s>" (nth 1 (assq 'content org-html-divs)))
      "</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 its
narrowed part.

If a region is active, export that region.

A non-nil optional argument ASYNC means the process should happen
asynchronously.  The resulting buffer should be accessible
through the `org-export-stack' interface.

When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.

When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.

When optional argument BODY-ONLY is non-nil, only write code
between \"<body>\" and \"</body>\" tags.

EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-local settings.

Export is done in a buffer named \"*Org S5 Export*\", which
will be displayed when `org-export-show-temporary-export-buffer'
is non-nil."
  (interactive)
  (org-export-to-buffer 's5 "*Org S5 Export*"
    async subtreep visible-only body-only ext-plist (lambda () (nxml-mode))))

(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 its
narrowed part.

If a region is active, export that region.

A non-nil optional argument ASYNC means the process should happen
asynchronously.  The resulting file should be accessible through
the `org-export-stack' interface.

When optional argument SUBTREEP is non-nil, export the sub-tree
at point, extracting information from the headline properties
first.

When optional argument VISIBLE-ONLY is non-nil, don't export
contents of hidden elements.

When optional argument BODY-ONLY is non-nil, only write code
between \"<body>\" and \"</body>\" tags.

EXT-PLIST, when provided, is a property list with external
parameters overriding Org default settings, but still inferior to
file-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))
    (org-export-to-file 's5 file
      async 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.  PLIST
is the property list for the given project.  PUB-DIR is the
publishing directory.

Return output file name."
  (org-publish-org-to 's5 filename ".html" plist pub-dir))

(provide 'ox-s5)

;;; ox-s5.el ends here

debug log:

solving 5088a6165 ...
found 5088a6165 in https://list.orgmode.org/orgmode/CAFq8O8v=x0PQKQBRsac81YiZoBb42HED_a=1F7Dzv2Dae-HZvg@mail.gmail.com/
found 243332519 in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 2433325199e73647f3c5e68b49c085c330def270	contrib/lisp/ox-s5.el

applying [1/1] https://list.orgmode.org/orgmode/CAFq8O8v=x0PQKQBRsac81YiZoBb42HED_a=1F7Dzv2Dae-HZvg@mail.gmail.com/
diff --git a/contrib/lisp/ox-s5.el b/contrib/lisp/ox-s5.el
index 243332519..5088a6165 100644

Checking patch contrib/lisp/ox-s5.el...
Applied patch contrib/lisp/ox-s5.el cleanly.

index at:
100644 5088a6165bf00bcbdb1b94626207e547c16818da	contrib/lisp/ox-s5.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).