forked from vascoferreira25/ox-tailwind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathox-tailwind.el
1871 lines (1588 loc) · 62.6 KB
/
ox-tailwind.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-tailwind.el --- Tailwind.css Back-End for Org Export Engine -*- lexical-binding: t -*-
;; Author: Vasco Ferreira <[email protected]>
;; Maintainer: Vasco Ferreira <[email protected]>
;; Created: 07 Mar 2020
;; Version: 0.41
;; Keywords: tailwind.css org-mode html-export
;; Homepage: https://github.com/vascoferreira25/ox-tailwind
;; Package-Requires: ((org) (dash) (s))
;; This file is not part of GNU Emacs.
;;; Commentary:
;;
;; This html export backend uses tailwind.css classes to export all the
;; org-mode elements. This way you will be able to quickly and effortlessly
;; change the layout, colors and look of the website.
;;
;; The html document has the following default layout:
;;
;; ---------------------------------------------------
;; | Header |
;; ---------------------------------------------------
;; |Table of Contents| |
;; | | |
;; | Sidebar | Body |
;; | | |
;; | | |
;; ---------------------------------------------------
;; | Footer |
;; ---------------------------------------------------
;;
;; You can change the look of the exported HTML by redefining the values of the
;; classes. All the classes start with `org-tailwind-class-', for example:
;;
;; - org-tailwind-class-h1
;; - org-tailwind-class-h2
;; - org-tailwind-class-header
;; - org-tailwind-class-footer
;; - org-tailwind-class-verbatim
;; - org-tailwind-class-video
;; - etc...
;;
;; Check this file to know more tailwind.css classes and change them any way
;; you want.
;;
;; Source code blocks use Prism.js. The Prism.js files included in this repo
;; use all the available languages and the following plugins:
;;
;; - line highlight
;; - line numbers
;; - autolinker
;; - file highlight
;; - show language
;; - jsonp highlight
;; - inline color
;; - previewers
;; - autoloader
;; - keep markup
;; - command-line
;; - unescaped markup
;; - normalize whitespace
;; - data-uri highlight
;; - toolbar
;; - copy to clipboard button
;; - download button
;; - match braces
;; - diff highlight
;; - filter highlight all
;; - treeview
;;; Dependencies:
(require 'org)
(require 'ox-html)
(require 's)
(require 'dash)
;;; tailwind group
(defgroup org-tailwind nil
"Classes for the html elements."
:group 'classes)
;;; Element Classes
;; Headings
(defcustom org-tailwind-class-title
"mt-12 mb-12 text-4xl text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for the Title."
:type '(string))
(defcustom org-tailwind-class-h1
"mt-24 mb-6 text-3xl text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 1."
:type '(string))
(defcustom org-tailwind-class-h2
"mt-20 mb-6 text-2xl text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 2."
:type '(string))
(defcustom org-tailwind-class-h3
"mt-16 mb-6 text-xl text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 3."
:type '(string))
(defcustom org-tailwind-class-h4
"mt-14 mb-6 text-lg text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 4."
:type '(string))
(defcustom org-tailwind-class-h5
"mt-12 mb-6 text-lg text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 5."
:type '(string))
(defcustom org-tailwind-class-h6
"mt-10 mb-6 text-base text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 6."
:type '(string))
(defcustom org-tailwind-class-h7
"mt-8 mb-6 text-base text-gray-700 dark:text-gray-400 border-b \
hover:text-blue-400 dark:hover:text-blue-500 border-gray-500"
"Tailwind.css classes for Heading 7."
:type '(string))
;; Text elements
(defcustom org-tailwind-class-bold
"font-bold"
"Tailwind.css classes for the HTML BOLD attribute."
:type '(string))
(defcustom org-tailwind-class-italic
"italic"
"Tailwind.css classes for the HTML ITALIC attribute."
:type '(string))
(defcustom org-tailwind-class-underlined
"underline"
"Tailwind.css classes for the HTML UNDERLINE attribute."
:type '(string))
(defcustom org-tailwind-class-code
"px-2 rounded text-green-500 bg-gray-200 dark:bg-gray-600 \
dark:text-yellow-500"
"Tailwind.css classes for the HTML UNDERLINE attribute."
:type '(string))
(defcustom org-tailwind-class-verbatim
"px-2 rounded text-red-400 bg-gray-200 dark:bg-gray-600 \
dark:text-red-500"
"Tailwind.css classes for the HTML VERBATIM attribute."
:type '(string))
(defcustom org-tailwind-class-link
"text-blue-500 hover:underline dark:text-blue-400"
"Tailwind.css classes for the HTML LINK attribute."
:type '(string))
(defcustom org-tailwind-class-paragraph
"my-2"
"Tailwind.css classes for the HTML PARAGRAPH."
:type '(string))
(defcustom org-tailwind-class-image-div
"mx-8 my-12 max-w-full max-h-full"
"Tailwind.css classes for the HTML image DIV."
:type '(string))
(defcustom org-tailwind-class-image
"mx-auto mb-2 max-w-full max-h-full rounded border \
border-gray-500"
"Tailwind.css classes for the HTML IMAGE."
:type '(string))
(defcustom org-tailwind-class-image-description
"italic border-t border-gray-500"
"Tailwind.css classes for the HTML image DESCRIPTION."
:type '(string))
(defcustom org-tailwind-class-video-div
"mx-8 my-12 max-w-full max-h-full"
"Tailwind.css classes for the HTML video DIV."
:type '(string))
(defcustom org-tailwind-class-video
"mx-auto mb-2 rounded border border-gray-500"
"Tailwind.css classes for the HTML VIDEO."
:type '(string))
(defcustom org-tailwind-class-video-description
"italic border-t border-gray-500"
"Tailwind.css classes for the HTML video DESCRIPTION."
:type '(string))
(defcustom org-tailwind-class-toc-title
"text-md my-2 hover:bg-gray-300 dark:hover:bg-gray-600 \
block dark:border-gray-500"
"Tailwind.css classes for the HTML Table of Contents title.
Use a single `\\' if you have line breaks in the string."
:type '(string))
(defcustom org-tailwind-class-toc-items
"text-md my-1 p-1 hover:bg-gray-100 dark:hover:bg-gray-600 \
dark:border-gray-500"
"Tailwind.css classes for the HTML Table of Contents items.
Use a single `\\' if you have line breaks in the string."
:type '(string))
(defcustom org-tailwind-class-current-toc
"border-l-4 border-blue-400 dark:border-blue-500 bg-gray-100 \
dark:bg-gray-600"
"Tailwind.css classes for the CURRENT HTML Table of Contents item."
:type '(string))
(defcustom org-tailwind-class-horizontal-rule
"border-b-2 border-gray-300 dark:border-gray-700"
"Tailwind.css classes for the HTML horizontal rule."
:type '(string))
;; Lists
(defcustom org-tailwind-class-ordered-list
"list-decimal my-2"
"Tailwind.css classes for the HTML ORDERED list."
:type '(string))
(defcustom org-tailwind-class-ordered-list-item
"ml-10"
"Tailwind.css classes for the HTML ordered list ITEM."
:type '(string))
(defcustom org-tailwind-class-unordered-list
"list-disc my-2"
"Tailwind.css classes for the HTML UNORDERED list."
:type '(string))
(defcustom org-tailwind-class-unordered-list-item
"ml-10"
"Tailwind.css classes for the HTML unordered list ITEM."
:type '(string))
(defcustom org-tailwind-class-description-list
"my-2 ml-8"
"Tailwind.css classes for the HTML DESCRIPTION list."
:type '(string))
(defcustom org-tailwind-class-description-list-title
"font-bold border-b mr-72 dark:border-gray-700"
"Tailwind.css classes for the HTML DESCRIPTION title."
:type '(string))
(defcustom org-tailwind-class-description-list-item
"ml-10"
"Tailwind.css classes for the HTML description list ITEM."
:type '(string))
;; Table
(defcustom org-tailwind-class-table-container
"overflow-x-auto my-12"
"Tailwind.css classes for the HTML table NAME."
:type '(string))
(defcustom org-tailwind-class-table
"table-auto m-auto my-2"
"Tailwind.css classes for the HTML TABLE."
:type '(string))
(defcustom org-tailwind-class-table-description
"mx-48 text-center italic border-t border-gray-500"
"Tailwind.css classes for the HTML table NAME."
:type '(string))
(defcustom org-tailwind-class-table-header-row
"text-gray-600 border-b-2 border-gray-400 bg-gray-100 \
dark:text-gray-400 dark:bg-gray-600"
"Tailwind.css classes for the HTML table HEADER-ROW."
:type '(string))
(defcustom org-tailwind-class-table-header-cell
"px-4 py-2 font-bold text-center"
"Tailwind.css classes for the HTML table HEADER-CELL."
:type '(string))
(defcustom org-tailwind-class-table-body-row
"hover:bg-blue-100 dark:hover:bg-gray-600"
"Tailwind.css classes for the HTML table BODY-ROW."
:type '(string))
(defcustom org-tailwind-class-table-last-body-row
"border-b-2 border-gray-400 hover:bg-blue-100 dark:hover:bg-gray-600"
"Tailwind.css classes for the HTML table BODY-ROW."
:type '(string))
(defcustom org-tailwind-class-table-body-cell
"px-4 py-2"
"Tailwind.css classes for the HTML table BODY-CELL."
:type '(string))
(defcustom org-tailwind-class-table-empty-body-cell
"px-2 py-2"
"Tailwind.css classes for the HTML table EMPTY BODY-CELL."
:type '(string))
;; Footnotes
(defcustom org-tailwind-class-footnotes-section
"<div id=\"footnotes\">
<h2 class=\"mt-20 mb-6 text-2xl text-gray-700 dark:text-gray-400 border-b \
hover:text-green-500 dark:hover:text-blue-500 border-gray-500\">%s</h2> \
<div id=\"text-footnotes\">
%s
</div>
</div>"
"Tailwind.css classes for the HTML footnotes section."
:type '(string))
(defcustom org-tailwind-class-footnotes-format
"<sup>%s</sup>"
"Tailwind.css classes for the HTML footnotes format."
:type '(string))
(defcustom org-tailwind-class-footnotes-separator
"<sup>, </sup>"
"Tailwind.css classes for the HTML footnotes separator."
:type '(string))
;; Blocks
(defcustom org-tailwind-class-example-container
"my-12 rounded border border-gray-800 shadow-xl"
"Tailwind.css classes for the HTML EXAMPLE-BLOCK CONTAINER."
:type '(string))
(defcustom org-tailwind-class-example
"rounded rainbow-braces"
"Tailwind.css classes for the HTML EXAMPLE-BLOCK."
:type '(string))
(defcustom org-tailwind-class-src-container
"my-12 shadow-xl"
"Tailwind.css classes for the HTML SRC-BLOCK CONTAINER."
:type '(string))
(defcustom org-tailwind-class-src-window
"bg-gray-300"
"Tailwind.css classes for the HTML SRC-BLOCK WINDOW.
This makes it look like the code is in an editor on mac OS."
:type '(string))
(defcustom org-tailwind-class-pre
"rainbow-braces match-braces rounded-b"
"Tailwind.css classes for the HTML SRC-BLOCK."
:type '(string))
(defcustom org-tailwind-class-blockquote-container
"my-12"
"Tailwind.css classes for the HTML BLOCKQUOTE container."
:type '(string))
(defcustom org-tailwind-class-blockquote
"mx-8 my-2 px-4 border-l-8 rounded border border-gray-500 \
bg-gray-300 dark:bg-gray-600 dark:text-gray-300"
"Tailwind.css classes for the HTML BLOCKQUOTE block."
:type '(string))
(defcustom org-tailwind-class-blockquote-author
"mx-8 italic border-t border-gray-500"
"Tailwind.css classes for the HTML blockquote AUTHOR."
:type '(string))
;; Special Blocks
(defcustom org-tailwind-class-mermaid-container
"mx-8 my-12"
"Tailwind.css classes for the HTML MERMAID container."
:type '(string))
(defcustom org-tailwind-class-mermaid-block
"mx-auto my-2 max-w-full max-h-full bg-white rounded border \
border-gray-500"
"Tailwind.css classes for the HTML MERMAID block."
:type '(string))
(defcustom org-tailwind-class-mermaid-block-title
"italic border-t border-gray-500"
"Tailwind.css classes for the HTML MERMAID block."
:type '(string))
(defcustom org-tailwind-class-details-block
"my-4 py-2 px-8 rounded border-l-8 border border-gray-300 \
dark:border-gray-600"
"Tailwind.css classes for the HTML DETAILS block."
:type '(string))
(defcustom org-tailwind-class-details-title
"text-gray-500 font-bold"
"Tailwind.css classes for the HTML details block TITLE."
:type '(string))
(defcustom org-tailwind-class-anki-block
"mb-2 px-10 text-xs"
"Tailwind.css classes for the HTML DETAILS block."
:type '(string))
(defcustom org-tailwind-class-anki-title
"text-gray-300 dark:text-gray-600"
"Tailwind.css classes for the HTML details block TITLE."
:type '(string))
(defcustom org-tailwind-class-tip-block
"my-12 p-8 rounded border-l-8 border border-blue-500 \
shadow-xl"
"Tailwind.css classes for the HTML TIP block."
:type '(string))
(defcustom org-tailwind-class-tip-title
"text-blue-500 font-bold"
"Tailwind.css classes for the HTML tip block TITLE."
:type '(string))
(defcustom org-tailwind-class-warning-block
"my-12 p-8 rounded border-l-8 border border-yellow-500 \
shadow-xl"
"Tailwind.css classes for the HTML WARNING block."
:type '(string))
(defcustom org-tailwind-class-warning-title
"text-yellow-500 font-bold"
"Tailwind.css classes for the HTML warning block TITLE."
:type '(string))
(defcustom org-tailwind-class-danger-block
"my-12 p-8 rounded border-l-8 border border-red-500 \
shadow-xl"
"Tailwind.css classes for the HTML DANGER block."
:type '(string))
(defcustom org-tailwind-class-danger-title
"text-red-500 font-bold"
"Tailwind.css classes for the HTML danger block TITLE."
:type '(string))
;; Page Divs
(defcustom org-tailwind-class-body
"flex flex-col h-screen text-gray-700 dark:bg-darkgray \
dark:text-gray-400"
"Tailwind.css classes for the HTML BODY."
:type '(string))
(defcustom org-tailwind-class-header
"w-full border-b border-gray-500
shadow-md items-center h-16"
"Tailwind.css classes for the HTML HEADER."
:type '(string))
(defcustom org-tailwind-class-sidebar
"mx-12 md:mx-16 shadow-2xl rounded mt-12 p-12 md:p-16 lg:m-0 \
lg:border-r lg:border-gray-500 lg:fixed lg:pt-2 lg:w-80 lg:px-2 \
lg:overflow-y-auto lg:inset-y-0 lg:mt-16"
"Tailwind.css classes for the HTML SIDEBAR."
:type '(string))
(defcustom org-tailwind-class-content
"flex flex-col lg:flex-row overflow-y-auto"
"Tailwind.css classes for the HTML CONTENT."
:type '(string))
(defcustom org-tailwind-class-content-container
"flex-grow px-8 py-12 sm:px-12 md:px-16 lg:ml-80 lg:px-20 \
lg:overflow-x-auto xl:px-32 2xl:px-48"
"Tailwind.css classes for the HTML contents CONTAINER."
:type '(string))
(defcustom org-tailwind-class-inner-container
"relative -top-16 p-16 pb-32 mb-12 shadow-2xl rounded \
xl:p-24"
"Tailwind.css classes for the HTML inner container."
:type '(string))
(defcustom org-tailwind-class-footer
"hidden fixed bottom-0 w-full border-t border-solid \
border-gray-500 h-8 text-center bg-white"
"Tailwind.css classes for the HTML FOOTER."
:type '(string))
(defcustom org-tailwind-class-toggle-button
"float-right rounded px-4 py-1 border bg-black bg-gray-100 \
dark:bg-gray-300 dark:text-gray-700"
"Tailwind.css classes for the HTML go to Toggle dark-mode button.
There are already some prefixed classes:
- p-2
- block
- mt-2
- ml-0"
:type '(string))
(defcustom org-tailwind-class-top-button
"absolute right-0 bottom-0 mb-2 mr-8 z-50 bg-gray-500 \
bg-opacity-80 hover:bg-gray-700 text-white font-bold rounded \
h-10 w-16 flex items-center justify-center"
"Tailwind.css classes for the HTML go to TOP button.
There are already some prefixed classes:
- p-2
- block
- mt-2
- ml-0"
:type '(string))
(defcustom org-tailwind-class-search-bar
"float-right mx-4 w-1/6 rounded px-4 py-1 border-solid \
border border-gray-700 dark:border-gray-500 text-gray-400 \
dark:text-gray-900 focus:border-green-500 \
dark:focus:border-blue-500 focus:text-gray-500 \
dark:focus:text-gray-500 dark:bg-midgray"
"Tailwind.css classes for the HTML SEARCH BAR."
:type '(string))
(defcustom org-tailwind-class-search-bar-results-list
"z-50 absolute w-5/6 sm:w-4/6 md:w-3/6 lg:w-2/6 xl:w-1/6
right-0 mt-12 mr-20 bg-white dark:bg-midgray p-4 shadow-lg border
border-solid border-gray-500 rounded"
"Tailwind.css classes for the HTML RESULTS LIST."
:type '(string))
(defcustom org-tailwind-class-search-bar-results-item
"p-2 block rounded hover:bg-gray-300 dark:hover:bg-darkgray"
"Tailwind.css classes for the HTML RESULTS ITEM.
Do not break the line with while inserting a `newline'. Use `\' at
the end."
:type '(string))
;; Other elements
(defcustom org-tailwind-class-checkbox
"form-tick appearance-none h-6 w-6 mr-2 border border-gray-300 \
rounded checked:bg-blue-600 checked:border-transparent \
focus:outline-none align-text-bottom"
"Tailwind.css classes for Checkbox."
:type '(string))
(defcustom org-tailwind-class-file-name
"relative top-10 flex rounded-t py-4 px-16 text-sm xl:px-24 z-10"
"Tailwind.css classes for File Name."
:type '(string))
;;; Templates
(defcustom org-tailwind-file-name-use-link t
"Whether to use a link or a paragraph for the file-name field."
:type '(boolean))
(defcustom org-tailwind-file-name-link
"<a class=\"%s\" href=\"org-protocol://open-file?file=%s\">%s</a>"
"The link to open the file in Emacs - preferably with org-protocol."
:type '(string))
(defcustom org-tailwind-head-files
"<!-- Tailwind CSS -->
<link href=\"./css/tailwind.css\" rel=\"stylesheet\"/>
<!-- Prism Css -->
<link href=\"./css/prism.css\" rel=\"stylesheet\" />
<!-- Mathjax -->
<script>
MathJax = {
tex: {
processEscapes: true
}
}
</script>
<script type=\"text/javascript\" async
src=\"./mathjax/tex-mml-chtml.js\">
</script>
<!-- Your CSS file should come here -->
<link href=\"./css/style.css\" rel=\"stylesheet\" />
<!-- Toc tree file -->
<script src=\"./js/toc_tree.js\"></script>
"
"Links to be imported on the head of the HTML file."
:type '(string))
(defcustom org-tailwind-header
"<nav class=\"flex items-center justify-between flex-wrap p-4\">
<div class=\"flex items-center flex-no-shrink mr-6\">
<span class=\"font-semibold text-xl tracking-tight\">
<a href=\"./index.html\">Notes</a>
</span>
</div>
<div class=\"block flex-grow lg:flex lg:items-center lg:w-auto\">
<div class=\"text-sm lg:flex-grow\">
<a href=\"#top\" class=\"%s\">
Top
</a>
<input id=\"search-bar\" onkeyup=\"search()\"
onfocusin='showResults()'
class=\"%s\" placeholder=\"Search...\"/>
<ul id=\"search-bar-results\"
class=\"%s\" style=\"display: none;\"></ul>
<button type=\"button\" class=\"%s\" onclick=\"toggleLight()\">Toggle dark-mode</button>
</div>
</div>
</nav>"
"Contents of header in HTML."
:type '(string))
(defcustom org-tailwind-sidebar
"<div id=\"toc\"></div>"
"Contents of sidebar in HTML."
:type '(string))
(defcustom org-tailwind-footer
"<p>Exported with org-tailwind</p>"
"Contents of footer in HTML."
:type '(string))
(defcustom org-tailwind-bottom-files
"<script src=\"./js/prism.js\"></script>
<script src=\"./js/mermaid.min.js\"></script>
<script>mermaid.initialize({startOnLoad:true});</script>"
"Javascript files to be imported at the bottom of the HTML file."
:type '(string))
(defcustom org-tailwind-headlines
"h1,h2,h3,h4"
"The level of the headlines to be included in the toc."
:type '(string))
(defcustom org-tailwind-javascript
"function getElementsByTagNames(list,obj) {
if (!obj) var obj = document;
var tagNames = list.split(',');
var resultArray = new Array();
for (var i=0;i < tagNames.length;i++) {
var tags = obj.getElementsByTagName(tagNames[i]);
for (var j=0;j < tags.length;j++) {
resultArray.push(tags[j]);
}
}
var testNode = resultArray[0];
if (!testNode) return [];
if (testNode.sourceIndex) {
resultArray.sort(function (a,b) {
return a.sourceIndex - b.sourceIndex;
});
}
else if (testNode.compareDocumentPosition) {
resultArray.sort(function (a,b) {
return 3 - (a.compareDocumentPosition(b) & 6);
});
}
return resultArray;
}
function createTOC() {
// Add go to top button
let top = document.createElement('a');
top.innerHTML = 'Top';
top.href = '#top';
top.className += 'top %s';
// The tags with the headlines
let headlines = getElementsByTagNames('%s');
if (headlines.length < 2) return false;
// Populate the #toc div
let toc = document.getElementById('toc');
// The title
// let title = document.getElementById('toc-link-title');
// let tocTitle = document.createElement('a');
// tocTitle.className = 'px-2 py-1 ';
// Set the classes to be used by the title
let title_classes = ' %s %s';
// Header counts for numbering
let header_2 = 0;
let header_3 = 0;
let header_4 = 0;
let header_5 = 0;
let header_6 = 0;
for (var i=0;i < headlines.length;i++) {
let tocHeader = document.createElement('a');
// Tailwind.css classes
tocHeader.className = 'px-2 py-1';
tocHeader.className += ' %s';
// Add the header to the table of contents
toc.appendChild(tocHeader);
switch (headlines[i].nodeName) {
case 'H1':
tocHeader.className += title_classes;
break;
case 'H2':
tocHeader.className += ' block mt-2 ml-0';
header_2 += 1;
header_3 = 0;
header_4 = 0;
header_5 = 0;
header_6 = 0;
header_7 = 0;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.</b> ';
break;
case 'H3':
tocHeader.className += ' block ml-5';
header_3 += 1;
header_4 = 0;
header_5 = 0;
header_6 = 0;
header_7 = 0;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.' + header_3 + '.</b> ';
break;
case 'H4':
tocHeader.className += ' block ml-12';
header_4 += 1;
header_5 = 0;
header_6 = 0;
header_7 = 0;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.' + header_3 + '.' + header_4 + '.</b> ';
break;
case 'H5':
tocHeader.className += ' block ml-20';
header_5 += 1;
header_6 = 0;
header_7 = 0;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.' + header_3 + '.' + header_4 + '.' + header_5 + '.</b> ';
break;
case 'H6':
tocHeader.className += ' block ml-32';
header_6 += 1;
header_7 = 0;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.' + header_3 + '.' + header_4 + '.' + header_5 + '.' + header_6 + '.</b> ';
break;
case 'H7':
tocHeader.className += ' block ml-48';
header_7 += 1;
// Numbering
tocHeader.innerHTML += '<b>' + header_2 + '.' + header_3 + '.' + header_4 + '.' + header_5 + '.' + header_6 + '.' + header_7 + '.</b> ';
break;
}
// Header title
tocHeader.innerHTML += headlines[i].innerHTML;
// Add a link to the header
let headerId = headlines[i].id || 'toc-link-' + i;
headlines[i].id = headerId;
tocHeader.id = \"goto-\" + headerId;
tocHeader.href = '#' + headerId;
}
}
createTOC();
// Populate search bar
let searchBar = document.getElementById('search-bar')
let searchBarResults = document.getElementById('search-bar-results')
for(let i = 0; i < tocTree.length; i++) {
let heading = tocTree[i]
let item = document.createElement('li')
let link = document.createElement('a')
link.href = heading.file + '#toc-link-' + heading.index
link.className = \"%s\"
link.style.display = 'none'
if (heading.name === heading.parent) {
link.innerText = heading.name
} else {
link.innerText = heading.name + ' > ' + heading.parent
}
item.appendChild(link)
searchBarResults.appendChild(item)
}
// Show results on search bar focus
function showResults(){
searchBarResults.style.display = ''
}
function hideResults(){
searchBarResults.style.display = 'none'
searchBar.value = ''
}
// Search Bar
function search(){
let searchBar = document.getElementById('search-bar')
let filter = searchBar.value.toUpperCase()
let count = 0
let searchResults = searchBarResults.getElementsByTagName('li')
for(let i = 0; i < searchResults.length; i++) {
let link = searchResults[i].getElementsByTagName('a')[0]
let txtValue = link.textContent || link.innerText
if (txtValue.toUpperCase().indexOf(filter) > -1 && count < 10) {
link.style.display = ''
count += 1
} else {
link.style.display = 'none'
}
}
}
// Check if an element is visible
function isElementVisible (el, parent) {
let rect = el.getBoundingClientRect();
return (
rect.top >= parent.getBoundingClientRect().top &&
rect.left >= 0 &&
rect.bottom <= (parent.clientHeight + parent.getBoundingClientRect().top) &&
rect.right <= (parent.clientWidth)
);
}
DOMTokenList.prototype.addMany = function(classes) {
var array = classes.split(' ');
for (var i = 0, length = array.length; i < length; i++) {
this.add(array[i]);
}
}
DOMTokenList.prototype.removeMany = function(classes) {
var array = classes.split(' ');
for (var i = 0, length = array.length; i < length; i++) {
this.remove(array[i]);
}
}
// Scroll Spy
// Everything is run inside the function because offsets
// are created due to tailwind.css classes as it changes
// the height/position of the elements after the page is loaded
function scrollSpy () {
let headings = document.querySelectorAll('[id^=\"toc-link-\"]');
let headingsTopOffsets = {};
let i = 0;
let selectedClassName = \"%s\";
Array.prototype.forEach.call(headings, function(s) {
headingsTopOffsets[s.id] = s.offsetTop;
});
let scrollEl = document.getElementById(\"content-container\");
let scrollPosition = scrollEl.scrollTop + 150;
let sidebar = document.getElementById('sidebar');
for (i in headingsTopOffsets) {
if (headingsTopOffsets[i] <= scrollPosition) {
document.getElementsByClassName(selectedClassName)[0].classList.removeMany(selectedClassName);
document.querySelector(`a[id^=\"goto-${i}\"]`).classList.addMany(selectedClassName);
// Scroll the sidebar to the current heading if not visible
let tocItem = document.getElementById(`goto-${i}`);
if (!isElementVisible(tocItem, sidebar)) {
tocItem.scrollIntoView();
}
}
}
};
// Manage dark theme
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
if (localStorage.theme === 'dark' || (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark')
} else {
document.documentElement.classList.remove('dark')
}
function toggleLight() {
if (localStorage.theme === 'light') {
//localStorage.setItem('theme', 'dark');
localStorage.theme = 'dark'
} else {
//localStorage.setItem('theme', 'light');
localStorage.theme = 'light'
}
location.reload();
return false;
}
"
"Javascript code needed in the HTML file."
:type '(string))
(defcustom org-tailwind-html-template
"<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<title>%s</title>
%s
</head>
<body class=\"%s\">
<div id=\"header\" class=\"%s\">
%s
</div>
<div id=\"content\" class=\"top %s\" onclick=\"hideResults()\">
<div id=\"sidebar\" class=\"%s\">
%s
</div>
<div id=\"content-container\" class=\"%s\" onscroll=\"scrollSpy()\">
<div id=\"top\"></div>
<div id=\"file-name\" class=\"%s\">
<img class=\"hidden w-6 h-6 mr-2\" src=\"./icons/file_icon.png\">
%s
</div>
<div id=\"inner-container\" class=\"%s\">
<h1 id=\"toc-link-title\" class=\"%s\">
%s
</h1>
%s
</div>
</div>
</div>
<div id=\"footer\" class=\"%s\">
%s
</div>
<script>
%s
</script>
%s
</body>
</html>
"
"Default HTML template.
The default template needs the format place for the following
values, in this order:
- page title
- head files