-
Notifications
You must be signed in to change notification settings - Fork 247
/
ox-reveal.el
1664 lines (1530 loc) · 73 KB
/
ox-reveal.el
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; ox-reveal.el --- reveal.js Presentation Back-End for Org Export Engine
;; Copyright (C) 2013 Yujie Wen
;; Author: Yujie Wen <yjwen.ty at gmail dot com>
;; Created: 2013-04-27
;; Version: 1.0
;; Package-Requires: ((org "8.3"))
;; Keywords: outlines, hypermedia, slideshow, presentation
;; This file is not part of GNU Emacs.
;;; Copyright Notice:
;; 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;; Please see "Readme.org" for detail introductions.
;; Pull request: Multiplex Support - Stephen Barrett <Stephen dot Barrewtt at scss dot tcd dot ie
;;; Code:
(require 'ox-html)
(require 'cl-lib)
(org-export-define-derived-backend 'reveal 'html
:menu-entry
'(?R "Export to reveal.js HTML Presentation"
((?R "To file" org-reveal-export-to-html)
(?B "To file and browse" org-reveal-export-to-html-and-browse)
(?S "Current subtree to file" org-reveal-export-current-subtree)))
:options-alist
'((:reveal-control nil "reveal_control" nil t)
(:reveal-progress nil "reveal_progress" nil t)
(:reveal-history nil "reveal_history" nil t)
(:reveal-center nil "reveal_center" nil t)
(:reveal-rolling-links nil "reveal_rolling_links" nil t)
(:reveal-slide-number nil "reveal_slide_number" nil t)
(:reveal-keyboard nil "reveal_keyboard" nil t)
(:reveal-overview nil "reveal_overview" nil t)
(:reveal-width nil "reveal_width" nil t)
(:reveal-height nil "reveal_height" nil t)
(:reveal-margin "REVEAL_MARGIN" nil nil t)
(:reveal-min-scale "REVEAL_MIN_SCALE" nil nil t)
(:reveal-max-scale "REVEAL_MAX_SCALE" nil nil t)
(:reveal-root "REVEAL_ROOT" nil org-reveal-root t)
(:reveal-trans "REVEAL_TRANS" nil nil t)
(:reveal-speed "REVEAL_SPEED" nil nil t)
(:reveal-theme "REVEAL_THEME" nil org-reveal-theme t)
(:reveal-extra-css "REVEAL_EXTRA_CSS" nil org-reveal-extra-css newline)
(:reveal-extra-js "REVEAL_EXTRA_JS" nil org-reveal-extra-js nil)
(:reveal-extra-initial-js "REVEAL_EXTRA_INITIAL_JS" nil org-reveal-extra-initial-js newline)
(:reveal-hlevel "REVEAL_HLEVEL" nil nil t)
(:reveal-title-slide "REVEAL_TITLE_SLIDE" "reveal_title_slide" org-reveal-title-slide newline)
(:reveal-slide-global-header nil "reveal_global_header" org-reveal-global-header t)
(:reveal-slide-global-footer nil "reveal_global_footer" org-reveal-global-footer t)
(:reveal-title-slide-background "REVEAL_TITLE_SLIDE_BACKGROUND" nil nil t)
(:reveal-title-slide-background-size "REVEAL_TITLE_SLIDE_BACKGROUND_SIZE" nil nil t)
(:reveal-title-slide-background-position "REVEAL_TITLE_SLIDE_BACKGROUND_POSITION" nil nil t)
(:reveal-title-slide-background-repeat "REVEAL_TITLE_SLIDE_BACKGROUND_REPEAT" nil nil t)
(:reveal-title-slide-background-transition "REVEAL_TITLE_SLIDE_BACKGROUND_TRANSITION" nil nil t)
(:reveal-title-slide-background-opacity "REVEAL_TITLE_SLIDE_BACKGROUND_OPACITY" nil nil t)
(:reveal-title-slide-state "REVEAL_TITLE_SLIDE_STATE" nil nil t)
(:reveal-toc-slide-background "REVEAL_TOC_SLIDE_BACKGROUND" nil nil t)
(:reveal-toc-slide-background-size "REVEAL_TOC_SLIDE_BACKGROUND_SIZE" nil nil t)
(:reveal-toc-slide-background-position "REVEAL_TOC_SLIDE_BACKGROUND_POSITION" nil nil t)
(:reveal-toc-slide-background-repeat "REVEAL_TOC_SLIDE_BACKGROUND_REPEAT" nil nil t)
(:reveal-toc-slide-background-transition "REVEAL_TOC_SLIDE_BACKGROUND_TRANSITION" nil nil t)
(:reveal-toc-slide-background-opacity "REVEAL_TOC_SLIDE_BACKGROUND_OPACITY" nil nil t)
(:reveal-default-slide-background "REVEAL_DEFAULT_SLIDE_BACKGROUND" nil nil t)
(:reveal-default-slide-background-size "REVEAL_DEFAULT_SLIDE_BACKGROUND_SIZE" nil nil t)
(:reveal-default-slide-background-position "REVEAL_DEFAULT_SLIDE_BACKGROUND_POSITION" nil nil t)
(:reveal-default-slide-background-repeat "REVEAL_DEFAULT_SLIDE_BACKGROUND_REPEAT" nil nil t)
(:reveal-default-slide-background-opacity "REVEAL_DEFAULT_SLIDE_BACKGROUND_OPACITY" nil nil t)
(:reveal-default-slide-background-transition "REVEAL_DEFAULT_SLIDE_BACKGROUND_TRANSITION" nil nil t)
(:reveal-mathjax-url "REVEAL_MATHJAX_URL" nil org-reveal-mathjax-url t)
(:reveal-preamble "REVEAL_PREAMBLE" nil org-reveal-preamble t)
(:reveal-head-preamble "REVEAL_HEAD_PREAMBLE" nil org-reveal-head-preamble newline)
(:reveal-postamble "REVEAL_POSTAMBLE" nil org-reveal-postamble t)
(:reveal-prologue "REVEAL_PROLOGUE" nil org-reveal-prologue t)
(:reveal-epilogue "REVEAL_EPILOGUE" nil org-reveal-epilogue t)
(:reveal-multiplex-id "REVEAL_MULTIPLEX_ID" nil org-reveal-multiplex-id nil)
(:reveal-multiplex-secret "REVEAL_MULTIPLEX_SECRET" nil org-reveal-multiplex-secret nil)
(:reveal-multiplex-url "REVEAL_MULTIPLEX_URL" nil org-reveal-multiplex-url nil)
(:reveal-multiplex-socketio-url "REVEAL_MULTIPLEX_SOCKETIO_URL" nil org-reveal-multiplex-socketio-url nil)
(:reveal-slide-header "REVEAL_SLIDE_HEADER" nil org-reveal-slide-header t)
(:reveal-slide-footer "REVEAL_SLIDE_FOOTER" nil org-reveal-slide-footer t)
(:reveal-plugins "REVEAL_PLUGINS" nil nil t)
(:reveal-external-plugins "REVEAL_EXTERNAL_PLUGINS" nil nil space)
(:reveal-default-frag-style "REVEAL_DEFAULT_FRAG_STYLE" nil org-reveal-default-frag-style t)
(:reveal-single-file nil "reveal_single_file" org-reveal-single-file t)
(:reveal-extra-script "REVEAL_EXTRA_SCRIPT" nil org-reveal-extra-script space)
(:reveal-extra-script-src "REVEAL_EXTRA_SCRIPT_SRC" nil org-reveal-extra-script-src split)
(:reveal-extra-script-before-src "REVEAL_EXTRA_SCRIPT_BEFORE_SRC" nil org-reveal-extra-script-before-src split)
(:reveal-init-options "REVEAL_INIT_OPTIONS" nil org-reveal-init-options newline)
(:reveal-highlight-css "REVEAL_HIGHLIGHT_CSS" nil org-reveal-highlight-css nil)
(:reveal-reveal-js-version "REVEAL_REVEAL_JS_VERSION" nil nil t)
)
:translate-alist
'((headline . org-reveal-headline)
(inner-template . org-reveal-inner-template)
(item . org-reveal-item)
(keyword . org-reveal-keyword)
(link . org-reveal-link)
(latex-environment . org-reveal-latex-environment)
(latex-fragment . (lambda (frag contents info)
(setq info (plist-put info :reveal-mathjax t))
(org-html-latex-fragment frag contents info)))
(plain-list . org-reveal-plain-list)
(quote-block . org-reveal-quote-block)
(section . org-reveal-section)
(src-block . org-reveal-src-block)
(special-block . org-reveal-special-block)
(template . org-reveal-template))
:filters-alist '((:filter-parse-tree . org-reveal-filter-parse-tree))
)
(defcustom org-reveal-root "./reveal.js"
"The root directory of reveal.js packages. It is the directory
within which js/reveal.js is."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-hlevel 1
"The minimum level of headings that should be grouped into
vertical slides."
:group 'org-export-reveal
:type 'integer)
(defun org-reveal--get-hlevel (info)
"Get HLevel value safely.
If option \"REVEAL_HLEVEL\" is set, retrieve integer value from it,
else get value from custom variable `org-reveal-hlevel'."
(let ((hlevel-str (plist-get info :reveal-hlevel)))
(if hlevel-str (string-to-number hlevel-str)
org-reveal-hlevel)))
(defcustom org-reveal-title-slide 'auto
"Non-nil means insert a title slide.
When set to `auto', an automatic title slide is generated. When
set to a string, use this string as a format string for title
slide, where the following escaping elements are allowed:
%t stands for the title
%a stands for the author's name.
%e stands for the author's email.
%d stands for the date.
%% stands for a literal %."
:group 'org-export-reveal
:type '(choice (const :tag "No title slide" nil)
(const :tag "Auto title slide" 'auto)
(string :tag "Custom title slide")))
(defcustom org-reveal-init-options
""
"Reveal.js initialization options, JS code snippet to be
embedded into Reveal.initialize()."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-transition
"default"
"Reveal transition style."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-theme
"moon"
"Reveal theme."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-extra-js
""
"URL to extra JS file."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-extra-initial-js
""
"Scripts to be embedded into reveal.js initialization."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-extra-css
""
"URL to extra css file."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-multiplex-id ""
"The ID to use for multiplexing."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-multiplex-secret ""
"The secret to use for master slide."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-multiplex-url ""
"The url of the socketio server."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-multiplex-socketio-url
""
"the url of the socketio.js library"
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-mathjax-url
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
"Default MathJax URL."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-preamble nil
"Preamble contents."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-head-preamble nil
"Preamble contents for head part."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-postamble nil
"Postamble contents."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-prologue nil
"Prologue contents to be inserted between opening <div reveal> and <div slides>."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-epilogue nil
"Prologue contents to be inserted between closing <div reveal> and <div slides>."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-slide-header nil
"HTML content used as Reveal.js slide header"
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-global-header nil
"If non nil, slide header defined in org-reveal-slide-header
is displayed also on title and toc slide"
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-global-footer nil
"If non nil, slide footer defined in org-reveal-slide-footer
is displayed also on title and toc slide"
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-slide-footer nil
"HTML content used as Reveal.js slide footer"
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-default-frag-style nil
"Default fragment style."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-plugins
'(markdown zoom notes)
"Default builtin plugins"
:group 'org-export-reveal
:type '(set
(const markdown)
(const highlight)
(const zoom)
(const notes)
(const search)
(const remotes)
(const multiplex)))
(defcustom org-reveal-external-plugins nil
"Additional third-party Plugins to load with reveal.
* When \"REVEAL_REVEAL_JS_VERSION\" is lower than 4
Each entry should contain a name and an expression of the form
\"{src: '%srelative/path/from/reveal/root', async:true/false,condition: jscallbackfunction(){}}\"
Note that some plugins have dependencies such as jquery; these must be included here as well,
BEFORE the plugins that depend on them.
* When \"REVEAL_REVEAL_JS_VERSION\" is 4 or higher
The value should be an association list where the key of an entry
is the name of the RevealJS plugin (e.g. RevealHighlight), and
the value is either a string or a list of strings. Each string is
going to be translated to an <script> tag in the output HTML.
Example:
(setq org-reveal-external-plugins
'((CopyCode .
(\"https://cdn.jsdelivr.net/npm/[email protected]/plugin/copycode/copycode.js\"
\"https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js\"))))
"
:group 'org-export-reveal
:type 'alist)
(defcustom org-reveal-single-file nil
"Export presentation into one single HTML file, which embedded
JS scripts and pictures."
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-extra-script nil
"Custom script that will be passed added to the script block, after Reveal.initialize."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-extra-script-src '()
"Custom script source that will be embedded in a <script src> tag, after the call to Reveal.initialize()."
:group 'org-export-reveal
:type 'list)
(defcustom org-reveal-extra-script-before-src '()
"Custom script source that will be embedded in a <script src> tag, before the call to Reveal.initialize()."
:group 'org-export-reveal
:type 'list)
(defcustom org-reveal-highlight-css "%r/plugin/highlight/zenburn.css"
"Highlight.js CSS file."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-klipsify-src nil
"Set to non-nil if you would like to make source code blocks editable in exported presentation."
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-klipse-css "https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"
"Location of the codemirror css file for use with klipse."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-klipse-js "https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"
"location of the klipse js source code."
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-slide-id-head "slide-"
"The heading string for slide ID"
:group 'org-export-reveal
:type 'string)
(defcustom org-reveal-ignore-speaker-notes nil
"Ignore speaker notes."
:group 'org-export-reveal
:type 'boolean)
(defcustom org-reveal-reveal-js-version nil
"Reveal.js version. Determine the locations of reveal.js scripts, CSS and the"
:group 'org-export-reveal
:type '(radio (const :tag "Reveal.js 4.0 and later" 4)
(const :tag "Reveal.js 3.x and before" 3)
(const :tag "Automatic" nil)))
(defun org-reveal--get-reveal-js-version (info)
"Get reveal.js version value safely.
If option \"REVEAL_REVEAL_JS_VERSION\" is set, retrieve integer
value from it, else get value from custom variable
`org-reveal-reveal-js-version'."
(let ((version-str (plist-get info :reveal-reveal-js-version)))
(if version-str (string-to-number version-str)
org-reveal-reveal-js-version)))
(defun if-format (fmt val)
(if val (format fmt val) ""))
(defun frag-style (frag info)
"Return proper fragment string according to FRAG and the default fragment style.
FRAG is the fragment style set on element, INFO is a plist
holding contextual information."
(cond
((string= frag t)
(let ((default-frag-style (plist-get info :reveal-default-frag-style)))
(if default-frag-style (format "fragment %s" default-frag-style)
"fragment")))
(t (format "fragment %s" frag))))
(defun frag-class (elem info)
"Return proper HTML string description of fragment style.
BLOCK is the element, INFO is a plist holding contextual
information."
(let ((frag (org-export-read-attribute :attr_reveal elem :frag)))
(and frag
(format " class=\"%s\"%s"
(frag-style frag info)
(let ((frag-index (org-export-read-attribute :attr_reveal elem :frag_idx)))
(if frag-index
(format " data-fragment-index=\"%s\"" frag-index)
""))))))
(defun org-reveal-special-block (special-block contents info)
"Transcode a SPECIAL-BLOCK element from Org to Reveal.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information.
If the block type is 'NOTES', transcode the block into a
Reveal.js slide note. Otherwise, export the block as by the HTML
exporter."
(let ((block-type (org-element-property :type special-block)))
(if (string= (upcase block-type) "NOTES")
(if org-reveal-ignore-speaker-notes
""
(format "<aside class=\"notes\">\n%s\n</aside>\n" contents))
(org-html-special-block special-block contents info))))
(defun org-reveal-is-background-img (info)
"Check if a background string is an image format or not."
(and info
(string-match-p
"\\(\\(^\\(http\\|https\\|file\\)://\\)\\|\\(\\\.\\(svg\\|png\\|jpg\\|jpeg\\|gif\\|bmp\\)\\([?#\\\s]\\|$\\)\\)\\)"
info)))
(defun org-reveal-slide-section-tag (headline info for-split)
"Generate the <section> tag for a slide."
(let* ((preferred-id (or (org-element-property :CUSTOM_ID headline)
(org-export-get-reference headline info)))
(default-slide-background (plist-get info :reveal-default-slide-background))
(default-slide-background-size (plist-get info :reveal-default-slide-background-size))
(default-slide-background-position (plist-get info :reveal-default-slide-background-position))
(default-slide-background-repeat (plist-get info :reveal-default-slide-background-repeat))
(default-slide-background-transition (plist-get info :reveal-default-slide-background-transition))
(slide-background-iframe (org-element-property :REVEAL_BACKGROUND_IFRAME headline))
)
(if slide-background-iframe
;; for iframe, we will wrap the slide in a new div
;; all the background configuration of the original slide will be used for this new div
(format "<section %s data-background-interactive>\n<div %s>\n"
(org-html--make-attribute-string
`(:id ,(concat org-reveal-slide-id-head
preferred-id
(if for-split "-split" ""))
:class ,(org-element-property :HTML_CONTAINER_CLASS headline)
:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline)
:data-state ,(org-element-property :REVEAL_DATA_STATE headline) ;; 3.9 legacy
:data-background-iframe ,slide-background-iframe))
(concat
"style=\""
(let ((attr (or (org-element-property :REVEAL_BACKGROUND headline)
default-slide-background)))
(if (org-reveal-is-background-img attr)
(format "background-image: url('%s'); " attr)
(if-format "background: %s; " attr)))
(let ((attr (or (org-element-property :REVEAL_BACKGROUND_REPEAT headline)
default-slide-background-repeat)))
(if-format "background-repeat: %s; " attr))
(let ((attr (or (org-element-property :REVEAL_BACKGROUND_SIZE headline)
default-slide-background)))
(if-format "background-size: %s; " attr))
(let ((attr (or (org-element-property :REVEAL_BACKGROUND_POSITION headline)
default-slide-background)))
(if-format "position: %s; " attr))
(let ((attr (or (org-element-property :REVEAL_BACKGROUND_OPACITY headline)
default-slide-background)))
(if-format "opacity: %s; " attr))
(let ((extra-attrs (org-element-property :REVEAL_EXTRA_ATTR headline)))
(if-format "%s;" extra-attrs))
"\""))
(format "<section %s%s>\n"
(org-html--make-attribute-string
`(:id ,(concat org-reveal-slide-id-head
preferred-id
(if for-split "-split" ""))
:class ,(org-element-property :HTML_CONTAINER_CLASS headline)
:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline)
:data-state ,(org-element-property :REVEAL_DATA_STATE headline) ;; 3.9 legacy
:data-background ,(or (org-element-property :REVEAL_BACKGROUND headline)
default-slide-background)
:data-background-size ,(or (org-element-property :REVEAL_BACKGROUND_SIZE headline)
default-slide-background-size)
:data-background-position ,(or (org-element-property :REVEAL_BACKGROUND_POSITION headline)
default-slide-background-position)
:data-background-repeat ,(or (org-element-property :REVEAL_BACKGROUND_REPEAT headline)
default-slide-background-repeat)
:data-background-transition ,(or (org-element-property :REVEAL_BACKGROUND_TRANS headline)
default-slide-background-transition)
:data-background-opacity
,(or (org-element-property :REVEAL_BACKGROUND_OPACITY headline)
(plist-get info :reveal-default-slide-background-opacity))))
(let ((extra-attrs (org-element-property :REVEAL_EXTRA_ATTR headline)))
(if-format " %s" extra-attrs))))))
;; Copied from org-html-headline and modified to embed org-reveal
;; specific attributes.
(defun org-reveal-headline (headline contents info)
"Transcode a HEADLINE element from Org to HTML.
CONTENTS holds the contents of the headline. INFO is a plist
holding contextual information."
(unless (org-element-property :footnote-section-p headline)
(if (org-export-low-level-p headline info)
;; This is a deep sub-tree: export it as in ox-html.
(org-html-headline headline contents info)
;; Standard headline. Export it as a slide
(let* ((level (org-export-get-relative-level headline info))
(section-number (mapconcat #'number-to-string
(org-export-get-headline-number headline info)
"-"))
(hlevel (org-reveal--get-hlevel info))
(header (plist-get info :reveal-slide-header))
(header-div (when header (format "<div class=\"slide-header\">%s</div>\n" header)))
(footer (plist-get info :reveal-slide-footer))
(footer-div (when footer (format "<div class=\"slide-footer\">%s</div>\n" footer)))
(first-sibling (org-export-first-sibling-p headline info))
(last-sibling (org-export-last-sibling-p headline info)))
(concat
(if (or (/= level 1) (not first-sibling))
;; Not the first heading. Close previous slide.
(concat
;; Slide footer if any
footer-div
;; Close previous slide
"</section>\n"
(if (<= level hlevel)
;; Close previous vertical slide group.
"</section>\n")))
(if (<= level hlevel)
;; Add an extra "<section>" to group following slides
;; into vertical slide group. Transition override
;; attributes are attached at this level, too.
(let ((attrs
(org-html--make-attribute-string
`(:data-transition ,(org-element-property :REVEAL_DATA_TRANSITION headline)))))
(if (string= attrs "")
"<section>\n"
(format "<section %s>\n" attrs))))
;; Start a new slide.
(org-reveal-slide-section-tag headline info nil)
;; Slide header if any.
header-div
;; The HTML content of the headline
;; Strip the <div> tags, if any
(let ((html (org-html-headline headline contents info)))
(if (string-prefix-p "<div" html)
;; Remove the first <div> and the last </div> tags from html
(concat "<"
(mapconcat 'identity
(butlast (cdr (split-string html "<" t)))
"<"))
;; Return the HTML content unchanged
html))
(if (and (= level 1)
(org-export-last-sibling-p headline info))
;; Last head 1. Close all slides.
(concat
;; Slide footer if any
footer-div
(if (org-element-property :REVEAL_BACKGROUND_IFRAME headline)
"</div>")
"</section>\n</section>\n")
(if (org-element-property :REVEAL_BACKGROUND_IFRAME headline)
"</div>")))))))
(defgroup org-export-reveal nil
"Options for exporting Orgmode files to reveal.js HTML pressentations."
:tag "Org Export Reveal"
:group 'org-export)
(defun org-reveal--read-file (file)
"Return the content of file"
(with-temp-buffer
(insert-file-contents-literally file)
(buffer-string)))
(defun org-reveal--file-url-to-path (url)
"Convert URL that points to local files to file path."
(replace-regexp-in-string
(if (string-equal system-type "windows-nt") "^file:///" "^file://")
"" url))
(defun org-reveal--css-label (in-single-file file-name style-id)
"Generate an HTML label for including a CSS file, if
IN-SINGLE-FILE is t, the content of FILE-NAME is embedded,
otherwise, a `<link>' label is generated."
(when (and file-name (not (string= file-name "")))
(if in-single-file
;; Single-file
(let ((local-file-name (org-reveal--file-url-to-path file-name)))
(if (file-readable-p local-file-name)
(concat "<style type=\"text/css\">\n"
(org-reveal--read-file local-file-name)
"\n</style>\n")
;; But file is not readable.
(error "Cannot read %s" file-name)))
;; Not in-single-file
(concat "<link rel=\"stylesheet\" href=\"" file-name "\""
(if style-id (format " id=\"%s\"" style-id))
"/>\n"))))
;; Choose path by reveal.js version
;;
;; Side-effect: When org-reveal-reveal-js-version is nil, updated it
;; to determined version if possible
(defun org-reveal--choose-path (root-path version file-path-0 file-path-1)
(if (or (eq version 4) ;; Explict reveal.js 4.0
(and (not version)
;; Automatic location. Choose an existing path
(let ((root-file-path
;; root-path could be a local file path or a URL. Try to
;; extract the local root path from root-path
(cond ((string-prefix-p "file://" root-path)
;; A local file URL
(substring root-path 7))
((or (string-prefix-p "http://" root-path)
(string-prefix-p "https://" root-path))
;; A remote URL
nil)
;; Otherwise, assuming it is a local file path
(t root-path))))
(or (not root-file-path) ;; Not a local URL, assuming file-path-0 exists
(when (file-exists-p (concat root-file-path file-path-0))
(setq org-reveal-reveal-js-version 4)
t)))))
(concat root-path file-path-0)
(concat root-path file-path-1)))
(defun org-reveal-root-path (info)
(file-name-as-directory (plist-get info :reveal-root)))
(defun org-reveal-stylesheets (info)
"Return the HTML contents for declaring reveal stylesheets
using custom variable `org-reveal-root'."
(let* ((root-path (org-reveal-root-path info))
(version (org-reveal--get-reveal-js-version info))
(reveal-css (org-reveal--choose-path root-path version "dist/reveal.css" "css/reveal.css"))
(theme (plist-get info :reveal-theme))
(theme-css (if (or (string-prefix-p "http://" theme)
(string-prefix-p "https://" theme)
(string-prefix-p "file://" theme))
;; theme is just the URL to a custom theme CSS
theme
(org-reveal--choose-path root-path
version
(concat "dist/theme/" theme ".css")
(concat "css/theme/" theme ".css"))))
(extra-css (plist-get info :reveal-extra-css))
(in-single-file (plist-get info :reveal-single-file)))
(concat
;; Default embedded style sheets
"<style type=\"text/css\">
.underline { text-decoration: underline; }
</style>
"
;; stylesheets
(mapconcat (lambda (elem) (org-reveal--css-label in-single-file (car elem) (cdr elem)))
(append (list (cons reveal-css nil)
(cons theme-css "theme"))
(mapcar (lambda (a) (cons a nil))
(split-string extra-css "\n")))
"\n")
;; Include CSS for highlight.js if necessary
(if (org-reveal--using-highlight.js info)
(format "<link rel=\"stylesheet\" href=\"%s\"/>"
(format-spec (plist-get info :reveal-highlight-css)
`((?r . ,(directory-file-name root-path))))))
;; print-pdf
(if (or in-single-file (eq version 4)) ""
(format "
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '%scss/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
"
root-path)))))
(defun org-reveal-mathjax-scripts (info)
"Return the HTML contents for declaring MathJax scripts"
(if (plist-get info :reveal-mathjax)
;; MathJax enabled.
(format "<script type=\"text/javascript\" src=\"%s\"></script>\n"
(plist-get info :reveal-mathjax-url))))
(defun org-reveal--get-plugins (info)
(let ((buffer-plugins (condition-case e
(car (read-from-string (plist-get info :reveal-plugins)))
(end-of-file nil)
(wrong-type-argument nil))))
(or (and buffer-plugins (listp buffer-plugins) buffer-plugins)
org-reveal-plugins)))
(defun org-reveal--legacy-dependency (root-path plugins info)
(concat
"
// Optional libraries used to extend on reveal.js
dependencies: [
"
;; JS libraries
(let* ((builtins
'(
classList (format " { src: '%slib/js/classList.js', condition: function() { return !document.body.classList; } }" root-path)
markdown (format " { src: '%splugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: '%splugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }" root-path root-path)
highlight (format " { src: '%splugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }" root-path)
zoom (format " { src: '%splugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }" root-path)
notes (format " { src: '%splugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }" root-path)
search (format " { src: '%splugin/search/search.js', async: true, condition: function() { return !!document.body.classList; } }" root-path)
remotes (format " { src: '%splugin/remotes/remotes.js', async: true, condition: function() { return !!document.body.classList; } }" root-path)
;; multiplex setup for reveal.js 3.x
multiplex (format " { src: '%s', async: true },\n%s"
(plist-get info :reveal-multiplex-socketio-url)
; following ensures that either client.js or master.js is included depending on defva client-multiplex value state
(if (not client-multiplex)
(progn
(if (plist-get info :reveal-multiplex-secret)
(setq client-multiplex t))
(format " { src: '%splugin/multiplex/master.js', async: true }" root-path))
(format " { src: '%splugin/multiplex/client.js', async: true }" root-path)))))
(builtin-codes
(mapcar (lambda (p)
(eval (plist-get builtins p)))
plugins))
(external-plugins
(append
;; Global setting
(cl-loop for (key . value) in org-reveal-external-plugins
collect (org-reveal--replace-first-%s value root-path ))
;; Local settings
(let ((local-plugins (plist-get info :reveal-external-plugins)))
(and local-plugins
(list (org-reveal--replace-first-%s local-plugins root-path))))))
(all-plugins (if external-plugins (append external-plugins builtin-codes) builtin-codes))
(extra-codes (plist-get info :reveal-extra-js))
(total-codes
(if (string= "" extra-codes) all-plugins (append (list extra-codes) all-plugins))))
(mapconcat 'identity total-codes ",\n"))
"]\n"))
(defun org-reveal--script-tag-by-file-name (fname in-single-file)
"Create a <script> tag for including scripts from the given
file name. If in single file mode, the <script> tag encloses the
contents of the file, otherwise it is a tag pointing to the file"
(if in-single-file
(let ((local-fname (org-reveal--file-url-to-path fname)))
(if (file-readable-p local-fname)
;; Embed script into HTML
(concat "<script>\n"
(org-reveal--read-file local-fname)
"\n</script>\n")
;; Cannot read fname, just error out
(error (concat "Cannot generate single file presentation due to "
local-fname
" is not readable"))))
(format "<script src=\"%s\"></script>\n" fname)))
(defun org-reveal--script-tags-by-auto-file-names (fnames in-single-file)
"Create multiple <script> tags for multiple file names, but
also accept single file name and create only one tag."
(if (stringp fnames)
(org-reveal--script-tag-by-file-name fnames in-single-file)
(mapconcat (lambda (fname)
(org-reveal--script-tag-by-file-name fname in-single-file))
fnames
"")))
(defun org-reveal--multi-level-mapconcat (func sequence seperator)
"Multilevel mapconcat. FUNC is applied to each element of seq
unless the element itself is a list, in which case func is
lifted and applied."
(mapconcat (lambda (e)
(if (listp e)
(org-reveal--multi-level-mapconcat func e seperator)
(funcall func e)))
sequence seperator))
(defun org-reveal-scripts (info)
"Return the necessary scripts for initializing reveal.js using
custom variable `org-reveal-root'."
(let* ((root-path (org-reveal-root-path info))
(version (org-reveal--get-reveal-js-version info))
(reveal-js (org-reveal--choose-path root-path version "dist/reveal.js" "js/reveal.js"))
;; Local files
(local-root-path (org-reveal--file-url-to-path root-path))
(local-reveal-js (org-reveal--choose-path local-root-path version "dist/reveal.js" "js/reveal.js"))
(plugins (org-reveal--get-plugins info))
(in-single-file (plist-get info :reveal-single-file))
(reveal-4-plugin (if (eq 4 version)
(org-reveal-plugin-scripts-4 plugins info in-single-file)
(cons nil nil))))
(concat
;; reveal.js/js/reveal.js
(org-reveal--script-tag-by-file-name local-reveal-js in-single-file)
;; plugin headings
(if-format "%s\n" (car reveal-4-plugin))
;; Extra <script src="..."></script> tags before the call to Reveal.initialize()
(org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-before-src)
in-single-file)
;; Reveal.initialize
(let ((reveal-4-plugin-statement (cdr reveal-4-plugin))
(init-options (plist-get info :reveal-init-options))
(multiplex-statement
;; multiplexing - depends on defvar 'client-multiplex'
(let ((multiplex-id (plist-get info :reveal-multiplex-id)))
(when (not (string-empty-p multiplex-id)) ;Multiplex setup found
(concat
(format "multiplex: {
secret: %s, // null if client
id: '%s', // id, obtained from socket.io server
url: '%s' // Location of socket.io server
},\n"
(if (eq client-multiplex nil)
(format "'%s'" (plist-get info :reveal-multiplex-secret))
(format "null"))
multiplex-id
(plist-get info :reveal-multiplex-url))
(let ((url (plist-get info :reveal-multiplex-url)))
(format "dependencies: [ { src: '%s/socket.io/socket.io.js', async: true }, { src: '%s/%s', async: true } ]"
url url
(if client-multiplex "client.js"
(progn
(setq client-multiplex t)
"master.js")))))
)))
(extra-initial-js-statement (plist-get info :reveal-extra-initial-js))
(legacy-dependency-statement
(unless (or in-single-file (eq version 4))
(org-reveal--legacy-dependency root-path plugins info))))
(format "
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
%s
});
%s
</script>
"
(mapconcat 'identity
(seq-filter (lambda (x) ;; Remove nil and ""
(and x (not (string= x ""))))
(list reveal-4-plugin-statement
init-options
multiplex-statement
(org-reveal--replace-first-%s extra-initial-js-statement root-path)
legacy-dependency-statement))
",\n")
;; Extra initialization scripts
(or (plist-get info :reveal-extra-script) "")))
;; Extra <script src="..."></script> tags
(org-reveal--script-tags-by-auto-file-names (plist-get info :reveal-extra-script-src)
in-single-file))))
(defun org-reveal--read-sexps-from-string (s)
(let ((s (string-trim s)))
(and (not (string-empty-p s))
(let ((r (read-from-string s)))
(let ((obj (car r))
(remain-index (cdr r)))
(and obj
(cons obj (org-reveal--read-sexps-from-string (substring s remain-index)))))))))
(defun org-reveal--search-first-%s-or-%% (s start)
"Search the first appearance of '%s' or '%%' in fmt from
start. Return the location (of the '%') if found, nil
otherwise"
(when (< start (length s))
(if (eq (aref s start) ?%)
(let ((next (1+ start)))
(when (< next (length s))
;; Only when % is not the last character
(let ((next-c (aref s next)))
(if (or (eq next-c ?s) (eq next-c ?%))
;; ^ Found the first %s or %%. Return the index
start
;; Not a %s or %%. Keep searching
(org-reveal--search-first-%s-or-%% s (1+ next))))))
;; Not a %. Keep search
(org-reveal--search-first-%s-or-%% s (1+ start)))))
(defun org-reveal--replace-first-%s (fmt str)
(let ((idx (org-reveal--search-first-%s-or-%% fmt 0)))
(if idx
(concat
;; Pre
(substring fmt 0 idx)
;; To be replaced
(if (eq ?% (aref fmt (1+ idx)))
"%" ;; %% -> %
str ;; %s -> str
)
;; Post
(substring fmt (+ 2 idx) nil))
;; nil, no %s or %% found
fmt)))
(defun org-reveal-plugin-scripts-4 (plugins info in-single-file)
"Return scripts for initializing reveal.js 4.x builtin scripts."
;; Return a pair whose first value is the HTML contents for the
;; plugin scripts, the second value is a list of import statements
;; to be embedded in the Reveal.initialize call
(if (not (null plugins))
;; Generate plugin scripts
(let* ((plugins (mapcar
(lambda (p)
;; Convert legacy
;; plugin names into
;; reveal.js 4.0 ones
(cond
((eq p 'highlight) 'RevealHighlight)
((eq p 'markdown) 'RevealMarkdown)
((eq p 'search) 'RevealSearch)
((eq p 'notes) 'RevealNotes)
((eq p 'math) 'RevealMath)
((eq p 'zoom) 'RevealZoom)
(t p)))
plugins))
(available-plugins
(append '((RevealHighlight . "%splugin/highlight/highlight.js")
(RevealMarkdown . "%splugin/markdown/markdown.js")
(RevealSearch . "%splugin/search/search.js")
(RevealNotes . "%splugin/notes/notes.js")
(RevealMath . "%splugin/math/math.js")
(RevealZoom . "%splugin/zoom/zoom.js"))
org-reveal-external-plugins
;; Buffer local plugins
(let ((local-plugins (plist-get info :reveal-external-plugins)))
(and local-plugins
(org-reveal--read-sexps-from-string local-plugins)))))
(plugin-js (seq-filter 'identity ;; Filter out nil
(mapcar (lambda (p)
(cdr (assoc p available-plugins)))
plugins))))
(if (not (null plugin-js))
(cons
;; First value of the pair, a list of script file names
(let ((root-path (org-reveal-root-path info)))
(org-reveal--multi-level-mapconcat
(lambda (p)
(org-reveal--script-tag-by-file-name (org-reveal--replace-first-%s p root-path)
in-single-file))
plugin-js ""))
;; Second value of the tuple, a list of Reveal plugin
;; initialization statements
(format "plugins: [%s]"
(mapconcat 'symbol-name
;; Remove multiplex from plugins, as
;; the multiplex plugin has been moved
;; out of reveal.js.
(seq-filter (lambda (p) (not (eq p 'multiplex))) plugins) ", ")))
;; No available plugin info found. Perhaps wrong plugin
;; names are given
(cons nil nil)))
;; No plugins, return empty string
(cons nil nil)))
(defun org-reveal-toc (depth info)
"Build a slide of table of contents."
(let ((toc (org-html-toc depth info)))
(when toc
(let ((toc-slide-background (plist-get info :reveal-toc-slide-background))
(toc-slide-background-size (plist-get info :reveal-toc-slide-background-size))
(toc-slide-background-position (plist-get info :reveal-toc-slide-background-position))
(toc-slide-background-repeat (plist-get info :reveal-toc-slide-background-repeat))
(toc-slide-background-transition (plist-get info :reveal-toc-slide-background-transition))
(toc-slide-background-opacity (plist-get info :reveal-toc-slide-background-opacity))
(toc-slide-with-header (plist-get info :reveal-slide-global-header))
(toc-slide-with-footer (plist-get info :reveal-slide-global-footer)))
(concat "<section id=\"sec-table-of-contents\""
(when toc-slide-background
(concat " data-background=\"" toc-slide-background "\""))
(when toc-slide-background-size
(concat " data-background-size=\"" toc-slide-background-size "\""))
(when toc-slide-background-position
(concat " data-background-position=\"" toc-slide-background-position "\""))
(when toc-slide-background-repeat
(concat " data-background-repeat=\"" toc-slide-background-repeat "\""))