-
Notifications
You must be signed in to change notification settings - Fork 0
/
org-html5presentation.el
executable file
·2678 lines (2464 loc) · 95.6 KB
/
org-html5presentation.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
;;; org-html5presentation.el --- HTML5 Presentation export for Org-mode
;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;; Free Software Foundation, Inc.
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.5
;;
;; GNU Emacs 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.
;; GNU Emacs 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/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;; About HTML5 presentation, see http://www.html5rocks.com/
;; Modifications: Takumi KINJO <takumi.kinjo@gmail.com>,
;; Tikhon Jelvis <tikhon@jelv.is>
;; Before requiring this, please make sure that your org-mode
;; version is 7.5(M-x org-version).
;; A simple tutorial of org-html5presentation.el is here.
;;
;; 1. Install org-mode 7.5. See http://orgmode.org/manual/Installation.html
;;
;; 2. Download latest version of org-html5presentation.el corresponds to
;; org-mode 7.5 from https://gist.github.com/509761 and put it in
;; your .emacs.d directory.
;;
;; 3. Add the following to your ~/.emacs and restart Emacs.
;;
;; (require 'org-html5presentation)
;;
;; 4. Edit your org-mode file. For example, ~/foo.org is
;;
;; BEGIN ------------------------------
;; #+TITLE: First
;; #+AUTHOR: Author's name
;;
;; * Heading
;;
;; - item
;; - sub item
;;
;; * Table
;;
;; | col | col |
;; |-----+-----|
;; | col | col |
;; END --------------------------------
;;
;; 5. To generate a HTML5 file from ~/foo.org, type following in your Emacs.
;;
;; M-x org-export-as-html5presentation
;;
;; or
;;
;; M-x org-export-as-html5presentation-and-open
;;
;; Enjoy!
;;; Code:
(require 'org-exp)
(require 'format-spec)
(eval-when-compile (require 'cl))
(declare-function org-id-find-id-file "org-id" (id))
(declare-function htmlize-region "ext:htmlize" (beg end))
(defgroup org-export-html5presentation nil
"Options specific for HTML5 Presentation export of Org-mode files."
:tag "Org Export HTML5"
:group 'org-export)
(defcustom org-export-html5presentation-footnotes-section "<div id=\"footnotes\">
<h2 class=\"footnotes\">%s: </h2>
<div id=\"text-footnotes\">
%s
</div>
</div>"
"Format for the footnotes section.
Should contain a two instances of %s. The first will be replaced with the
language-specific word for \"Footnotes\", the second one will be replaced
by the footnotes themselves."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-footnote-format "<sup>%s</sup>"
"The format for the footnote reference.
%s will be replaced by the footnote reference itself."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-coding-system nil
"Coding system for HTML export, defaults to `buffer-file-coding-system'."
:group 'org-export-html5presentation
:type 'coding-system)
(defcustom org-export-html5presentation-extension "html"
"The extension for exported HTML files."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-xml-declaration
'(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
"The extension for exported HTML files.
%s will be replaced with the charset of the exported file.
This may be a string, or an alist with export extensions
and corresponding declarations."
:group 'org-export-html5presentation
:type '(choice
(string :tag "Single declaration")
(repeat :tag "Dependent on extension"
(cons (string :tag "Extension")
(string :tag "Declaration")))))
(defcustom org-export-html5presentation-style-include-scripts t
"Non-nil means include the JavaScript snippets in exported HTML files.
The actual script is defined in `org-export-html5presentation-scripts' and should
not be modified."
:group 'org-export-html5presentation
:type 'boolean)
(defconst org-export-html5presentation-scripts
"<script type=\"text/javascript\">
<!--/*--><![CDATA[/*><!--*/
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = \"code-highlighted\";
elem.className = \"code-highlighted\";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
</script>"
"Basic JavaScript that is needed by HTML files produced by Org-mode.")
(defconst org-export-html5presentation-style-default
"<style type=\"text/css\">
<!--/*--><![CDATA[/*><!--*/
html { font-family: Times, serif; font-size: 12pt; }
.title { text-align: center; }
.todo { color: red; }
.done { color: green; }
.tag { background-color: #add8e6; font-weight:normal }
.target { }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.right {margin-left:auto; margin-right:0px; text-align:right;}
.left {margin-left:0px; margin-right:auto; text-align:left;}
.center {margin-left:auto; margin-right:auto; text-align:center;}
p.verse { margin-left: 3% }
pre {
border: 1pt solid #AEBDCC;
background-color: #F3F5F7;
padding: 5pt;
font-family: courier, monospace;
font-size: 90%;
overflow:auto;
}
table { border-collapse: collapse; }
td, th { vertical-align: top; font-size: 30px; }
th.right { text-align:center; }
th.left { text-align:center; }
th.center { text-align:center; }
td.right { text-align:right; }
td.left { text-align:left; }
td.center { text-align:center; }
dt { font-weight: bold; }
div.figure { padding: 0.5em; }
div.figure p { text-align: center; }
textarea { overflow-x: auto; }
.linenr { font-size:smaller }
.code-highlighted {background-color:#ffff00;}
.org-info-js_info-navigation { border-style:none; }
#org-info-js_console-label { font-size:10px; font-weight:bold;
white-space:nowrap; }
.org-info-js_search-highlight {background-color:#ffff00; color:#000000;
font-weight:bold; }
/*]]>*/-->
</style>"
"The default style specification for exported HTML files.
Please use the variables `org-export-html5presentation-style' and
`org-export-html5presentation-style-extra' to add to this style. If you wish to not
have the default style included, customize the variable
`org-export-html5presentation-style-include-default'.")
(defcustom org-export-html5presentation-style-include-default t
"Non-nil means include the default style in exported HTML files.
The actual style is defined in `org-export-html5presentation-style-default' and should
not be modified. Use the variables `org-export-html5presentation-style' to add
your own style information."
:group 'org-export-html5presentation
:type 'boolean)
;;;###autoload
(put 'org-export-html5presentation-style-include-default 'safe-local-variable 'booleanp)
(defcustom org-export-html5presentation-style ""
"Org-wide style definitions for exported HTML files.
This variable needs to contain the full HTML structure to provide a style,
including the surrounding HTML tags. If you set the value of this variable,
you should consider to include definitions for the following classes:
title, todo, done, timestamp, timestamp-kwd, tag, target.
For example, a valid value would be:
<style type=\"text/css\">
<![CDATA[
p { font-weight: normal; color: gray; }
h1 { color: black; }
.title { text-align: center; }
.todo, .timestamp-kwd { color: red; }
.done { color: green; }
]]>
</style>
If you'd like to refer to en external style file, use something like
<link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
As the value of this option simply gets inserted into the HTML <head> header,
you can \"misuse\" it to add arbitrary text to the header.
See also the variable `org-export-html5presentation-style-extra'."
:group 'org-export-html5presentation
:type 'string)
;;;###autoload
(put 'org-export-html5presentation-style 'safe-local-variable 'stringp)
(defcustom org-export-html5presentation-style-extra ""
"Additional style information for HTML export.
The value of this variable is inserted into the HTML buffer right after
the value of `org-export-html5presentation-style'. Use this variable for per-file
settings of style information, and do not forget to surround the style
settings with <style>...</style> tags."
:group 'org-export-html5presentation
:type 'string)
;;;###autoload
(put 'org-export-html5presentation-style-extra 'safe-local-variable 'stringp)
(defcustom org-export-html5presentation-mathjax-options
'((path "http://orgmode.org/mathjax/MathJax.js")
(scale "100")
(align "center")
(indent "2em")
(mathml nil))
"Options for MathJax setup.
path The path where to find MathJax
scale Scaling for the HTML-CSS backend, usually between 100 and 133
align How to align display math: left, center, or right
indent If align is not center, how far from the left/right side?
mathml Should a MathML player be used if available?
This is faster and reduces bandwidth use, but currently
sometimes has lower spacing quality. Therefore, the default is
nil. When browsers get better, this switch can be flipped.
You can also customize this for each buffer, using something like
#+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
:group 'org-export-html5presentation
:type '(list :greedy t
(list :tag "path (the path from where to load MathJax.js)"
(const :format " " path) (string))
(list :tag "scale (scaling for the displayed math)"
(const :format " " scale) (string))
(list :tag "align (alignment of displayed equations)"
(const :format " " align) (string))
(list :tag "indent (indentation with left or right alignment)"
(const :format " " indent) (string))
(list :tag "mathml (should MathML display be used is possible)"
(const :format " " mathml) (boolean))))
(defun org-export-html5presentation-mathjax-config (template options in-buffer)
"Insert the user setup into the matchjax template."
(let (name val (yes " ") (no "// ") x)
(mapc
(lambda (e)
(setq name (car e) val (nth 1 e))
(if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
(setq val (car (read-from-string
(substring in-buffer (match-end 0))))))
(if (not (stringp val)) (setq val (format "%s" val)))
(if (string-match (concat "%" (upcase (symbol-name name))) template)
(setq template (replace-match val t t template))))
options)
(setq val (nth 1 (assq 'mathml options)))
(if (string-match (concat "\\<mathml:") in-buffer)
(setq val (car (read-from-string
(substring in-buffer (match-end 0))))))
;; Exchange prefixes depending on mathml setting
(if (not val) (setq x yes yes no no x))
;; Replace cookies to turn on or off the config/jax lines
(if (string-match ":MMLYES:" template)
(setq template (replace-match yes t t template)))
(if (string-match ":MMLNO:" template)
(setq template (replace-match no t t template)))
;; Return the modified template
template))
(defcustom org-export-html5presentation-mathjax-template
"<script type=\"text/javascript\" src=\"%PATH\">
<!--/*--><![CDATA[/*><!--*/
MathJax.Hub.Config({
// Only one of the two following lines, depending on user settings
// First allows browser-native MathML display, second forces HTML/CSS
:MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
:MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
\"TeX/noUndefined.js\"],
tex2jax: {
inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
ignoreClass: \"tex2jax_ignore\",
processEscapes: false,
processEnvironments: true,
preview: \"TeX\"
},
showProcessingMessages: true,
displayAlign: \"%ALIGN\",
displayIndent: \"%INDENT\",
\"HTML-CSS\": {
scale: %SCALE,
availableFonts: [\"STIX\",\"TeX\"],
preferredFont: \"TeX\",
webFont: \"TeX\",
imageFont: \"TeX\",
showMathMenu: true,
},
MMLorHTML: {
prefer: {
MSIE: \"MML\",
Firefox: \"MML\",
Opera: \"HTML\",
other: \"HTML\"
}
}
});
/*]]>*///-->
</script>"
"The MathJax setup for XHTML files."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-tag-class-prefix ""
"Prefix to class names for TODO keywords.
Each tag gets a class given by the tag itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name. But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-todo-kwd-class-prefix ""
"Prefix to class names for TODO keywords.
Each TODO keyword gets a class given by the keyword itself, with this prefix.
The default prefix is empty because it is nice to just use the keyword
as a class name. But if you get into conflicts with other, existing
CSS classes, then this prefix can be very useful."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-preamble t
"Non-nil means insert a preamble in HTML export.
When `t', insert a string as defined by one of the formatting
strings in `org-export-html5presentation-preamble-format'. When set to a
string, this string overrides `org-export-html5presentation-preamble-format'.
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 :html-preamble in publishing projects will take
precedence over this variable."
:group 'org-export-html5presentation
:type '(choice (const :tag "No preamble" nil)
(const :tag "Default preamble" t)
(string :tag "Custom formatting string")
(function :tag "Function (must return a string)")))
(defcustom org-export-html5presentation-preamble-format
'(("en" "<h1 class=\"title\">%t</h1>"))
"The format for the HTML preamble.
%t stands for the title.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-postamble 'auto
"Non-nil means insert a postamble in HTML export.
When `t', insert a string as defined by the formatting string in
`org-export-html5presentation-postamble-format'. When set to a string, this
string overrides `org-export-html5presentation-postamble-format'. When set to
'auto, discard `org-export-html5presentation-postamble-format' and honor
`org-export-author/email/creator-info' variables. 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 :html-postamble in publishing projects will take
precedence over this variable."
:group 'org-export-html5presentation
:type '(choice (const :tag "No postamble" nil)
(const :tag "Auto preamble" 'auto)
(const :tag "Default formatting string" t)
(string :tag "Custom formatting string")
(function :tag "Function (must return a string)")))
(defcustom org-export-html5presentation-postamble-format
'(("en" "<p class=\"author\">Author: %a (%e)</p>
<p class=\"date\">Date: %d</p>
<p class=\"creator\">Generated by %c</p>
<p class=\"xhtml-validation\">%v</p>
"))
"The format for the HTML postamble.
%a stands for the author.
%e stands for the email(s).
%d stands for the date.
%c will be replaced by information about Org/Emacs.
%v will be replaced by `org-export-html5presentation-validation-link'.
If you need to use a \"%\" character, you need to escape it
like that: \"%%\"."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-home/up-format
"<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
<a accesskey=\"h\" href=\"%s\"> UP </a>
|
<a accesskey=\"H\" href=\"%s\"> HOME </a>
</div>"
"Snippet used to insert the HOME and UP links.
This is a format string, the first %s will receive the UP link,
the second the HOME link. If both `org-export-html-link-up' and
`org-export-html-link-home' are empty, the entire snippet will be
ignored."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-toplevel-hlevel 2
"The <H> level for level 1 headings in HTML export.
This is also important for the classes that will be wrapped around headlines
and outline structure. If this variable is 1, the top-level headlines will
be <h1>, and the corresponding classes will be outline-1, section-number-1,
and outline-text-1. If this is 2, all of these will get a 2 instead.
The default for this variable is 2, because we use <h1> for formatting the
document title."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-link-org-files-as-html t
"Non-nil means make file links to `file.org' point to `file.html'.
When org-mode is exporting an org-mode file to HTML, links to
non-html files are directly put into a href tag in HTML.
However, links to other Org-mode files (recognized by the
extension `.org.) should become links to the corresponding html
file, assuming that the linked org-mode file will also be
converted to HTML.
When nil, the links still point to the plain `.org' file."
:group 'org-export-html5presentation
:type 'boolean)
(defcustom org-export-html5presentation-inline-images 'maybe
"Non-nil means inline images into exported HTML pages.
This is done using an <img> tag. When nil, an anchor with href is used to
link to the image. If this option is `maybe', then images in links with
an empty description will be inlined, while images with a description will
be linked only."
:group 'org-export-html5presentation
:type '(choice (const :tag "Never" nil)
(const :tag "Always" t)
(const :tag "When there is no description" maybe)))
(defcustom org-export-html5presentation-inline-image-extensions
'("png" "jpeg" "jpg" "gif" "svg")
"Extensions of image files that can be inlined into HTML."
:group 'org-export-html5presentation
:type '(repeat (string :tag "Extension")))
(defcustom org-export-html5presentation-table-tag
"<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
"The HTML tag that is used to start a table.
This must be a <table> tag, but you may change the options like
borders and spacing."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-html5presentation-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
"The opening tag for table header fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-export-html5presentation-table-use-header-tags-for-first-column'.
See also the variable `org-export-html5presentation-table-align-individual-fields'."
:group 'org-export-tables
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-html5presentation-export-table-data-tags '("<td%s>" . "</td>")
"The opening tag for table data fields.
This is customizable so that alignment options can be specified.
The first %s will be filled with the scope of the field, either row or col.
The second %s will be replaced by a style entry to align the field.
See also the variable `org-export-html5presentation-table-align-individual-fields'."
:group 'org-export-tables
:type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
(defcustom org-html5presentation-export-table-row-tags '("<tr>" . "</tr>")
"The opening tag for table data fields.
This is customizable so that alignment options can be specified.
Instead of strings, these can be Lisp forms that will be evaluated
for each row in order to construct the table row tags. During evaluation,
the variable `head' will be true when this is a header line, nil when this
is a body line. And the variable `nline' will contain the line number,
starting from 1 in the first header line. For example
(setq org-html5presentation-export-table-row-tags
(cons '(if head
\"<tr>\"
(if (= (mod nline 2) 1)
\"<tr class=\\\"tr-odd\\\">\"
\"<tr class=\\\"tr-even\\\">\"))
\"</tr>\"))
will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
:group 'org-export-tables
:type '(cons
(choice :tag "Opening tag"
(string :tag "Specify")
(sexp))
(choice :tag "Closing tag"
(string :tag "Specify")
(sexp))))
(defcustom org-export-html5presentation-table-align-individual-fields t
"Non-nil means attach style attributes for alignment to each table field.
When nil, alignment will only be specified in the column tags, but this
is ignored by some browsers (like Firefox, Safari). Opera does it right
though."
:group 'org-export-tables
:type 'boolean)
(defcustom org-export-html5presentation-table-use-header-tags-for-first-column nil
"Non-nil means format column one in tables with header tags.
When nil, also column one will use data tags."
:group 'org-export-tables
:type 'boolean)
(defcustom org-export-html5presentation-validation-link
"<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
"Link to HTML validation service."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-with-timestamp nil
"If non-nil, write timestamp into the exported HTML text.
If non-nil, write `org-export-html5presentation-html-helper-timestamp' into the
exported HTML text. Otherwise, the buffer will just be saved to
a file."
:group 'org-export-html5presentation
:type 'boolean)
(defcustom org-export-html5presentation-html-helper-timestamp
"<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
"The HTML tag used as timestamp delimiter for HTML-helper-mode."
:group 'org-export-html5presentation
:type 'string)
(defcustom org-export-html5presentation-protect-char-alist
'(("&" . "&")
("<" . "<")
(">" . ">"))
"Alist of characters to be converted by `org-html5presentation-protect'."
:type '(repeat (cons (string :tag "Character")
(string :tag "HTML equivalent"))))
(defgroup org-export-html5presentationize nil
"Options for processing examples with htmlize.el."
:tag "Org Export Htmlize"
:group 'org-export-html5presentation)
(defcustom org-export-html5presentationize-output-type 'inline-css
"Output type to be used by htmlize when formatting code snippets.
Choices are `css', to export the CSS selectors only, or `inline-css', to
export the CSS attribute values inline in the HTML. We use as default
`inline-css', in order to make the resulting HTML self-containing.
However, this will fail when using Emacs in batch mode for export, because
then no rich font definitions are in place. It will also not be good if
people with different Emacs setup contribute HTML files to a website,
because the fonts will represent the individual setups. In these cases,
it is much better to let Org/Htmlize assign classes only, and to use
a style file to define the look of these classes.
To get a start for your css file, start Emacs session and make sure that
all the faces you are interested in are defined, for example by loading files
in all modes you want. Then, use the command
\\[org-export-html5presentationize-generate-css] to extract class definitions."
:group 'org-export-html5presentationize
:type '(choice (const css) (const inline-css)))
(defcustom org-export-html5presentationize-css-font-prefix "org-"
"The prefix for CSS class names for htmlize font specifications."
:group 'org-export-html5presentationize
:type 'string)
(defcustom org-export-html5presentationized-org-css-url nil
"URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
Normally when creating an htmlized version of an Org buffer, htmlize will
create CSS to define the font colors. However, this does not work when
converting in batch mode, and it also can look bad if different people
with different fontification setup work on the same website.
When this variable is non-nil, creating an htmlized version of an Org buffer
using `org-export-as-org' will remove the internal CSS section and replace it
with a link to this URL."
:group 'org-export-html5presentationize
:type '(choice
(const :tag "Keep internal css" nil)
(string :tag "URL or local href")))
;;; Hooks
(defvar org-export-html5presentation-after-blockquotes-hook nil
"Hook run during HTML export, after blockquote, verse, center are done.")
(defvar org-export-html5presentation-final-hook nil
"Hook run at the end of HTML export, in the new buffer.")
;;; HTML export
(defun org-export-html5presentation-preprocess (parameters)
"Convert LaTeX fragments to images."
(when (and org-current-export-file
(plist-get parameters :LaTeX-fragments))
(org-format-latex
(concat "ltxpng/" (file-name-sans-extension
(file-name-nondirectory
org-current-export-file)))
org-current-export-dir nil "Creating LaTeX image %s"
nil nil
(cond
((eq (plist-get parameters :LaTeX-fragments) 'verbatim) 'verbatim)
((eq (plist-get parameters :LaTeX-fragments) 'mathjax ) 'mathjax)
((eq (plist-get parameters :LaTeX-fragments) t ) 'mathjax)
((eq (plist-get parameters :LaTeX-fragments) 'dvipng ) 'dvipng)
(t nil))))
(goto-char (point-min))
(let (label l1)
(while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
(org-if-unprotected-at (match-beginning 1)
(setq label (match-string 1))
(save-match-data
(if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
(setq l1 (substring label (match-beginning 1)))
(setq l1 label)))
(replace-match (format "[[#%s][%s]]" label l1) t t)))))
;;;###autoload
(defun org-export-as-html5presentation-and-open (arg)
"Export the outline as HTML and immediately open it with a browser.
If there is an active region, export only the region.
The prefix ARG specifies how many levels of the outline should become
headlines. The default is 3. Lower levels will become bulleted lists."
(interactive "P")
(org-export-as-html5presentation arg 'hidden)
(org-open-file buffer-file-name)
(when org-export-kill-product-buffer-when-displayed
(kill-buffer (current-buffer))))
;;;###autoload
(defun org-export-as-html5presentation-batch ()
"Call the function `org-export-as-html5presentation'.
This function can be used in batch processing as:
emacs --batch
--load=$HOME/lib/emacs/org.el
--eval \"(setq org-export-headline-levels 2)\"
--visit=MyFile --funcall org-export-as-html5presentation-batch"
(org-export-as-html5presentation org-export-headline-levels 'hidden))
;;;###autoload
(defun org-export-as-html5presentation-to-buffer (arg)
"Call `org-export-as-html5presentation` with output to a temporary buffer.
No file is created. The prefix ARG is passed through to `org-export-as-html5presentation'."
(interactive "P")
(org-export-as-html5presentation arg nil nil "*Org HTML Export*")
(when org-export-show-temporary-export-buffer
(switch-to-buffer-other-window "*Org HTML Export*")))
;;;###autoload
(defun org-replace-region-by-html5presentation (beg end)
"Assume the current region has org-mode syntax, and convert it to HTML.
This can be used in any buffer. For example, you could write an
itemized list in org-mode syntax in an HTML buffer and then use this
command to convert it."
(interactive "r")
(let (reg html buf pop-up-frames)
(save-window-excursion
(if (org-mode-p)
(setq html (org-export-region-as-html5presentation
beg end t 'string))
(setq reg (buffer-substring beg end)
buf (get-buffer-create "*Org tmp*"))
(with-current-buffer buf
(erase-buffer)
(insert reg)
(org-mode)
(setq html (org-export-region-as-html5presentation
(point-min) (point-max) t 'string)))
(kill-buffer buf)))
(delete-region beg end)
(insert html)))
;;;###autoload
(defun org-export-region-as-html5presentation (beg end &optional org-html5presentation-body-only buffer)
"Convert region from BEG to END in org-mode buffer to HTML.
If prefix arg BODY-ONLY is set, omit file header, footer, and table of
contents, and only produce the region of converted text, useful for
cut-and-paste operations.
If BUFFER is a buffer or a string, use/create that buffer as a target
of the converted HTML. If BUFFER is the symbol `string', return the
produced HTML as a string and leave not buffer behind. For example,
a Lisp program could call this function in the following way:
(setq html (org-export-region-as-html5presentation beg end t 'string))
When called interactively, the output buffer is selected, and shown
in a window. A non-interactive call will only return the buffer."
(interactive "r\nP")
(when (interactive-p)
(setq buffer "*Org HTML Export*"))
(let ((transient-mark-mode t) (zmacs-regions t)
ext-plist rtn)
(setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
(goto-char end)
(set-mark (point)) ;; to activate the region
(goto-char beg)
(setq rtn (org-export-as-html5presentation
nil nil ext-plist
buffer org-html5presentation-body-only))
(if (fboundp 'deactivate-mark) (deactivate-mark))
(if (and (interactive-p) (bufferp rtn))
(switch-to-buffer-other-window rtn)
rtn)))
(defvar html5presentation-table-tag nil) ; dynamically scoped into this.
(defvar org-html5presentation-par-open nil)
;;; org-html5presentation-cvt-link-fn
(defconst org-html5presentation-cvt-link-fn
nil
"Function to convert link URLs to exportable URLs.
Takes two arguments, TYPE and PATH.
Returns exportable url as (TYPE PATH), or nil to signal that it
didn't handle this case.
Intended to be locally bound around a call to `org-export-as-html5presentation'." )
(defun org-html5presentation-cvt-org-as-html (opt-plist type path)
"Convert an org filename to an equivalent html filename.
If TYPE is not file, just return `nil'.
See variable `org-export-html5presentation-link-org-files-as-html'"
(save-match-data
(and
org-export-html5presentation-link-org-files-as-html
(string= type "file")
(string-match "\\.org$" path)
(progn
(list
"file"
(concat
(substring path 0 (match-beginning 0))
"."
(plist-get opt-plist :html-extension)))))))
;;; org-html5presentation-should-inline-p
(defun org-html5presentation-should-inline-p (filename descp)
"Return non-nil if link FILENAME should be inlined.
The decision to inline the FILENAME link is based on the current
settings. DESCP is the boolean of whether there was a link
description. See variables `org-export-html5presentation-inline-images' and
`org-export-html5presentation-inline-image-extensions'."
(declare (special
org-export-html5presentation-inline-images
org-export-html5presentation-inline-image-extensions))
(and (or (eq t org-export-html5presentation-inline-images)
(and org-export-html5presentation-inline-images (not descp)))
(org-file-image-p
filename org-export-html5presentation-inline-image-extensions)))
;;; org-html5presentation-make-link
(defun org-html5presentation-make-link (opt-plist type path fragment desc attr
may-inline-p)
"Make an HTML link.
OPT-PLIST is an options list.
TYPE is the device-type of the link (THIS://foo.html)
PATH is the path of the link (http://THIS#locationx)
FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
DESC is the link description, if any.
ATTR is a string of other attributes of the a element.
MAY-INLINE-P allows inlining it as an image."
(declare (special org-html5presentation-par-open))
(save-match-data
(let* ((filename path)
;;First pass. Just sanity stuff.
(components-1
(cond
((string= type "file")
(list
type
;;Substitute just if original path was absolute.
;;(Otherwise path must remain relative)
(if (file-name-absolute-p path)
(concat
"file://"
(let ((keep (text-properties-at 0 path)))
(setq path (expand-file-name path))
(apply 'propertize path keep)))
path)))
((string= type "")
(list nil path))
(t (list type path))))
;;Second pass. Components converted so they can refer
;;to a remote site.
(components-2
(or
(and org-html5presentation-cvt-link-fn
(apply org-html5presentation-cvt-link-fn
opt-plist components-1))
(apply #'org-html5presentation-cvt-org-as-html
opt-plist components-1)
components-1))
(type (first components-2))
(thefile (second components-2)))
;;Third pass. Build final link except for leading type
;;spec.
(cond
((or
(not type)
(string= type "http")
(string= type "https")
(string= type "file")
(string= type "coderef"))
(if fragment
(setq thefile (concat thefile "#" fragment))))
(t))
;;Final URL-build, for all types.
(setq thefile
(let
((str (org-export-html5presentation-format-href thefile)))
(if (and type (not (or (string= "file" type)
(string= "coderef" type))))
(concat type ":" str)
str)))
(if (and
may-inline-p
;;Can't inline a URL with a fragment.
(not fragment))
(progn
(message "image %s %s" thefile org-html5presentation-par-open)
(org-export-html5presentation-format-image thefile org-html5presentation-par-open))
(concat
"<a href=\"" thefile "\"" (if attr (concat " " attr)) ">"
(org-export-html5presentation-format-desc desc)
"</a>")))))
(defun org-html5presentation-handle-links (line opt-plist)
"Return LINE with markup of Org mode links.
OPT-PLIST is the export options list."
(let ((start 0)
(current-dir (if buffer-file-name
(file-name-directory buffer-file-name)
default-directory))
(link-validate (plist-get opt-plist :link-validation-function))
type id-file fnc
rpl path attr desc descp desc1 desc2 link)
(while (string-match org-bracket-link-analytic-regexp++ line start)
(setq start (match-beginning 0))
(setq path (save-match-data (org-link-unescape
(match-string 3 line))))
(setq type (cond
((match-end 2) (match-string 2 line))
((save-match-data
(or (file-name-absolute-p path)
(string-match "^\\.\\.?/" path)))
"file")
(t "internal")))
(setq path (org-extract-attributes (org-link-unescape path)))
(setq attr (get-text-property 0 'org-attributes path))
(setq desc1 (if (match-end 5) (match-string 5 line))
desc2 (if (match-end 2) (concat type ":" path) path)
descp (and desc1 (not (equal desc1 desc2)))
desc (or desc1 desc2))
;; Make an image out of the description if that is so wanted
(when (and descp (org-file-image-p
desc org-export-html5presentation-inline-image-extensions))
(save-match-data
(if (string-match "^file:" desc)
(setq desc (substring desc (match-end 0)))))
(setq desc (org-add-props
(concat "<img src=\"" desc "\" alt=\""
(file-name-nondirectory desc) "\"/>")
'(org-protected t))))
(cond
((equal type "internal")
(let
((frag-0
(if (= (string-to-char path) ?#)
(substring path 1)
path)))
(setq rpl
(org-html5presentation-make-link
opt-plist
""
""
(org-solidify-link-text
(save-match-data (org-link-unescape frag-0))
nil)
desc attr nil))))
((and (equal type "id")
(setq id-file (org-id-find-id-file path)))
;; This is an id: link to another file (if it was the same file,
;; it would have become an internal link...)
(save-match-data
(setq id-file (file-relative-name
id-file
(file-name-directory org-current-export-file)))
(setq rpl
(org-html5presentation-make-link opt-plist
"file" id-file
(concat (if (org-uuidgen-p path) "ID-") path)
desc
attr
nil))))
((member type '("http" "https"))
;; standard URL, can inline as image
(setq rpl
(org-html5presentation-make-link opt-plist
type path nil
desc
attr
(org-html5presentation-should-inline-p path descp))))
((member type '("ftp" "mailto" "news"))
;; standard URL, can't inline as image
(setq rpl
(org-html5presentation-make-link opt-plist
type path nil
desc
attr
nil)))
((string= type "coderef")
(let*
((coderef-str (format "coderef-%s" path))
(attr-1
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
coderef-str coderef-str)))
(setq rpl
(org-html5presentation-make-link opt-plist
type "" coderef-str