-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite-config.el
1193 lines (1153 loc) · 49 KB
/
site-config.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
(use-package dash :straight t)
(use-package modus-themes
:straight (modus-themes :type git :host github :repo "protesilaos/modus-themes"))
(require 'ox-publish)
(require 'dash)
(require 'htmlize)
;; (load-theme 'lab-light)
(require 'modus-themes)
(load-theme 'modus-operandi t)
;;;; Quick Build keybind
(defun replace-killed-buffer-in-file (filename)
"Replace all instances of #<killed buffer> with '\"killed buffer\"' in the given FILENAME and save the file."
(interactive "fEnter filename: ")
(with-temp-buffer
(insert-file-contents filename)
(goto-char (point-min))
(while (search-forward "#<killed buffer>" nil t)
(replace-match "\"killed buffer\""))
(write-region (point-min) (point-max) filename)))
(defun build-project ()
(interactive)
(save-window-excursion
(let ((current-themes custom-enabled-themes)
(cache-file
(concat
(expand-file-name org-publish-timestamp-directory)
"pages" ".cache")))
(loop for theme in current-themes do
(disable-theme theme))
(when (file-exists-p cache-file)
(delete-file cache-file))
(enable-theme 'modus-operandi)
(save-buffer)
(org-publish-file (buffer-file-name (buffer-base-buffer)) nil t)
(disable-theme 'modus-operandi)
(loop for theme in current-themes do
(enable-theme theme))
)))
(defun build-project-all ()
(interactive)
(save-window-excursion
(let ((current-themes custom-enabled-themes)
(cache-file
(concat
(expand-file-name org-publish-timestamp-directory)
"pages" ".cache")))
(loop for theme in current-themes do
(disable-theme theme))
(when (file-exists-p cache-file)
(delete-file cache-file))
(enable-theme 'modus-operandi)
(org-publish "kirancodes.me" t)
(disable-theme 'modus-operandi)
(loop for theme in current-themes do
(enable-theme theme))
)))
(bind-key (kbd "C-c C-c") #'build-project)
(bind-key (kbd "C-c C-c") #'build-project 'org-mode-map)
;;;; Better Useful ids
(defun org-export-get-reference (datum info)
"Like `org-export-get-reference', except uses heading titles instead of random numbers."
(let ((cache (plist-get info :internal-references)))
(or (car (rassq datum cache))
(let* ((crossrefs (plist-get info :crossrefs))
(cells (org-export-search-cells datum))
;; Preserve any pre-existing association between
;; a search cell and a reference, i.e., when some
;; previously published document referenced a location
;; within current file (see
;; `org-publish-resolve-external-link').
;;
;; However, there is no guarantee that search cells are
;; unique, e.g., there might be duplicate custom ID or
;; two headings with the same title in the file.
;;
;; As a consequence, before re-using any reference to
;; an element or object, we check that it doesn't refer
;; to a previous element or object.
(new (or (cl-some
(lambda (cell)
(let ((stored (cdr (assoc cell crossrefs))))
(when stored
(let ((old (if (numberp stored)
(org-export-format-reference stored)
stored)))
(and (not (assoc old cache)) stored)))))
cells)
(when (org-element-property :raw-value datum)
;; Heading with a title
(org-export-new-title-reference datum cache))
;; NOTE: This probably breaks some Org Export
;; feature, but if it does what I need, fine.
(org-export-format-reference
(org-export-new-reference cache))))
(reference-string new))
;; Cache contains both data already associated to
;; a reference and in-use internal references, so as to make
;; unique references.
(dolist (cell cells) (push (cons cell new) cache))
;; Retain a direct association between reference string and
;; DATUM since (1) not every object or element can be given
;; a search cell (2) it permits quick lookup.
(push (cons reference-string datum) cache)
(plist-put info :internal-references cache)
reference-string))))
(defun org-export-new-title-reference (datum cache)
"Return new reference for DATUM that is unique in CACHE."
(cl-macrolet ((inc-suffixf (place)
`(progn
(string-match (rx bos
(minimal-match (group (1+ anything)))
(optional "--" (group (1+ digit)))
eos)
,place)
;; HACK: `s1' instead of a gensym.
(-let* (((s1 suffix) (list (match-string 1 ,place)
(match-string 2 ,place)))
(suffix (if suffix
(string-to-number suffix)
0)))
(setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
(let* ((title (org-element-property :raw-value datum))
(ref (url-hexify-string (substring-no-properties title)))
(parent (org-element-property :parent datum)))
(while (--any (equal ref (car it))
cache)
;; Title not unique: make it so.
(if parent
;; Append ancestor title.
(setf title (concat (org-element-property :raw-value parent)
"--" title)
ref (url-hexify-string (substring-no-properties title))
parent (org-element-property :parent parent))
;; No more ancestors: add and increment a number.
(inc-suffixf ref)))
ref)))
;;;; Variables
(defun html-dir (&rest segments)
(apply #'concat
;; (file-name-as-directory org-directory)
;; "html-new/"
(if (buffer-file-name)
(file-name-directory (buffer-file-name))
(expand-file-name "./"))
(mapcar #'file-name-as-directory segments))
)
(defvar build-dir
(expand-file-name "~/Documents/kirancodes.me/")
;; (concat (file-name-as-directory org-directory) "build/")
)
(setq org-html-preamble-format
`(("en"
"<header>
<div class=\"header-container border-trans-pink width-container\">
<div class=\"header-logo-container\">
<a href=\"/\">
<img class=\"header-img\" src=\"/images/banner.svg\" height=\"40\" width=\"280\"/>
</a>
</div>
<div class=\"header-motto-container\">
<span>To Proof Maintenance & Beyond!</span>
</div>
</div>
</header>")))
(setq org-html-postamble-format
`(("en"
" <footer class=\"footer\">
<div class=\"width-container\">
<div class=\"footer-block\">
<div class=\"footer-block-item footer-block-item-grow mx-2.5 mb-2.5\">
<img src=\"/images/public-domain.svg\" height=\"30\" width=\"148\"/>
<span>All content is available under the <a class=\"footer-link\" href=\"https://creativecommons.org/publicdomain/zero/1.0/\">Creative Commons Zero License v1.0</a>, except where otherwise stated</span>
</div>
<div class=\"footer-block-item\">
<a class=\"footer-logo footer-link\">Abolish Copyright ©</a>
</div>
</div>
</div>
</footer>")))
(setq org-html-footnotes-section "<div id=\"footnotes\" class=\"grid-row\">
<div class=\"grid-column-full\">
<h2 class=\"heading-m footnotes\">%s</h2>
<div id=\"text-footnotes\">
%s
</div>
</div>
</div>"
)
(setq org-html-footnote-format "<sup>%s</sup>")
(setq org-html-htmlize-output-type 'inline-css)
(setq org-html-table-header-tags '("<th class=\"table-header\" scope=\"%s\"%s>" . "</th>"))
(setq org-html-table-data-tags '("<td class=\"table-cell\" scope=\"%s\">" . "</td>"))
(setq org-html-table-row-open-tag "<tr class=\"table-row\">")
(setq org-html-link-home "127.0.0.1:36573")
;;;; Helpers
;;;;; Quoted Snippet
(defun org-html-is-quoted-snippet (node)
(--any? (equal (org-element-property :back-end it) "html") (org-element-contents node)))
;;;;; Level to Headings
(defun org-html-level-to-heading-class (level)
"Converts a heading level to a class"
(message "org-html-level-to-heading-class %S" level)
(format "heading-%s"
(pcase level
(1 "xl")
(2 "l")
(3 "m")
(_ "s"))))
;;;;; Level to Caption's
(defun org-html-level-to-caption-class (level)
"Converts a heading level to a class"
(message "org-html-level-to-caption-class %S" level)
(format "caption-%s"
(pcase level
(1 "xl")
(2 "l")
(3 "m")
(_ "s"))))
;;;;; Navigation bar
(defun org-html--build-navigation-bar (info)
(message "org-html--build-nav-bar %S" (plist-get info :nav-section))
(cond
((and (plist-get info :nav-section)
(plist-get info :nav-sections)
(listp (plist-get info :nav-sections)))
(let ((curr-section (plist-get info :nav-section))
(sections (plist-get info :nav-sections)))
(message "org-html--build-navigation-bar %S" curr-section)
(apply #'concat
(append
'("<nav class=\"navigation\">
<ul class=\"navigation-list width-container\">")
(mapcar (lambda (section)
(concat
"<li class=\"navigation-list-item"
(if (equal (car (org-element-contents section)) curr-section)
" navigation-list-item--current"
"")
"\">"
(org-html-link section (car (org-element-contents section)) info)
"</li>")
) sections)
'(" </ul>
</nav>")
))))
(t "")))
(defun org-html--build-breadcrumbs (info)
(cond
((plist-get info :nav-sections) "")
(t
(let ((breadcrumbs (org-publish-generate-navigation-breadcrumbs info)))
(apply
#'concat
(append
'("<nav class=\"breadcrumbs\">
<ol class=\"breadcrumbs-list\">")
(mapcar (lambda (pair)
(format "
<li class=\"breadcrumbs-list-item\">
<a class=\"breadcrumbs-link\" href=\"%s\">
%s
</a>
</li>" (cdr pair) (car pair))) breadcrumbs)
'("
</ol>
</nav>")
))
))))
;;;;; Nav Breadcrumbs
(defun org-publish-generate-navigation-breadcrumbs (info)
"Generate a navigation breadcrumbs list based on INFO plist.
INFO should contain:
- :input-file - Full path of the current input Org file.
- :base-directory - The base directory of the Org files.
The function searches parent directories for .org files to build navigation links."
(let* ((input-file (plist-get info :input-file))
(base-directory (plist-get info :base-directory))
(home-link '("Home" . "/index.html")) ;; Always include Home
(links (list home-link)) ;; Initialize with Home
(current-dir (file-name-directory input-file)))
;; Traverse up the directory tree
(while (and current-dir
(not (string= (expand-file-name current-dir)
(expand-file-name base-directory))))
(let* ((parent-file (concat (directory-file-name current-dir) ".org"))
(file-title (when (file-exists-p parent-file)
(capitalize (file-name-base parent-file))
;; (org-html-get-file-property parent-file :title)
)))
(when file-title
;; Create the navigation link
(let* ((relative-path (file-relative-name parent-file base-directory))
(html-path (concat "/" (file-name-sans-extension relative-path) ".html")))
(push (cons file-title html-path) links))))
;; Move up one directory
(setq current-dir (file-name-directory (directory-file-name current-dir))))
(nreverse links)))
(defun org-html-get-file-property (file property)
"Extract the title from the Org FILE. If no title is found, use the file name."
(let* ((org-inhibit-startup t))
(plist-get (org-with-file-buffer file
(if (not org-file-buffer-created)
(org-export-get-environment 'html)
;; Protect local variables in open buffers.
(org-export-with-buffer-copy
(org-export-get-environment 'html))))
property))) ;; Fallback to file name
;;;;; Custom sitemap
(defun org-list-filter-empty-strings (ls)
(cond
((null ls) ls)
((consp ls)
(let ((head (org-list-filter-empty-strings (car ls)))
(tail (org-list-filter-empty-strings (cdr ls))))
(if head (cons head tail) tail)))
((stringp ls)
(if (string-empty-p ls) nil ls))
(t ls)))
(defun org-publish-sitemap-custom (title list)
(concat
"#+TITLE: " title "\n"
"#+NAV_SECTIONS: [[file:index.org][About Me]] [[file:index.org::*Publications][Publications]] [[file:art.org][Artwork]] [[file:posts.org][Posts]]\n"
"#+NAV_SECTION: Posts\n\n"
"* Kiran's Blog Posts\n"
":PROPERTIES:\n"
":subtitle: My Ramblings on Life, Software, Games and Everything\n"
":END:\n"
(org-list-to-org (org-list-filter-empty-strings list))))
(defun org-publish-sitemap-custom-entry (entry style project)
"Default format for site map ENTRY, as a string.
ENTRY is a file name. STYLE is the style of the sitemap.
PROJECT is the current project."
(cond ((not (directory-name-p entry))
(if (equal (org-publish-find-property entry :hidden project 'html) "true") ""
(format "[[file:%s][%s - %s]]"
entry
(format-time-string
"%d %b, %Y"
(org-publish-find-date entry project))
(org-publish-find-title entry project))))
((eq style 'tree)
;; Return only last subdir.
(file-name-nondirectory (directory-file-name entry)))
(t entry)))
;;;;; Custom Headlines
(defun org-html--custom-tags (tags info)
"Format TAGS into HTML.
INFO is a plist containing export options."
(when tags
(mapconcat
(lambda (tag)
(format "<span class=\"tag\"><span class=\"%s\">%s</span></span>"
(concat (plist-get info :html-tag-class-prefix)
(org-html-fix-class-name tag))
tag))
tags " ")))
(defun org-html-format-headline-custom-function
(todo _todo-type priority text tags info)
"Default format function for a headline.
See `org-html-format-headline-function' for details and the
description of TODO, PRIORITY, TEXT, TAGS, and INFO arguments."
(let ((todo (org-html--todo todo info))
(priority (org-html--priority priority info))
(tags (org-html--custom-tags tags info))
(date (and
(plist-get info :date)
(car (plist-get info :date))
(org-format-timestamp (car (plist-get info :date)) "%d %b, %Y")))
(date-machine
(and
(plist-get info :date)
(car (plist-get info :date))
(org-format-timestamp (car (plist-get info :date)) "%Y-%m-%d"))))
(concat todo (and todo " ")
priority (and priority " ")
text
"<br/>"
(if (and date tags)
(format "<span class=\"date\"><time datetime=\"%s\">%s</time></span>" date-machine date)
"")
(and tags "   ") tags)))
;;;;; Custom warnings
(defun org-html--build-warning (text)
(format "<div class=\"grid-row\">
<div class=\"grid-full-column\">
<div class=\"phase-banner inset-text\">
<div class=\"phase-banner-content\">
<span class=\"tag phase-banner-content-tag\">Warning</span>
<span class=\"phase-banner-text\">
%s
</span>
</div>
</div>
</div>
</div>" text))
;;;; Overrides
;;;;; Backend
(org-export-define-backend 'html
'((bold . org-html-bold)
(center-block . org-html-center-block)
(clock . org-html-clock)
(code . org-html-code)
(drawer . org-html-drawer)
(dynamic-block . org-html-dynamic-block)
(entity . org-html-entity)
(example-block . org-html-example-block)
(export-block . org-html-export-block)
(export-snippet . org-html-export-snippet)
(fixed-width . org-html-fixed-width)
(footnote-reference . org-html-footnote-reference)
(headline . org-html-headline)
(horizontal-rule . org-html-horizontal-rule)
(inline-src-block . org-html-inline-src-block)
(inlinetask . org-html-inlinetask)
(inner-template . org-html-inner-template)
(italic . org-html-italic)
(item . org-html-item)
(keyword . org-html-keyword)
(latex-environment . org-html-latex-environment)
(latex-fragment . org-html-latex-fragment)
(line-break . org-html-line-break)
(link . org-html-link)
(node-property . org-html-node-property)
(paragraph . org-html-paragraph)
(plain-list . org-html-plain-list)
(plain-text . org-html-plain-text)
(planning . org-html-planning)
(property-drawer . org-html-property-drawer)
(quote-block . org-html-quote-block)
(radio-target . org-html-radio-target)
(section . org-html-section)
(special-block . org-html-special-block)
(src-block . org-html-src-block)
(statistics-cookie . org-html-statistics-cookie)
(strike-through . org-html-strike-through)
(subscript . org-html-subscript)
(superscript . org-html-superscript)
(table . org-html-table)
(table-cell . org-html-table-cell)
(table-row . org-html-table-row)
(target . org-html-target)
(template . org-html-template)
(timestamp . org-html-timestamp)
(underline . org-html-underline)
(verbatim . org-html-verbatim)
(verse-block . org-html-verse-block))
:filters-alist '((:filter-options . org-html-infojs-install-script)
(:filter-parse-tree . org-html-image-link-filter)
(:filter-final-output . org-html-final-function))
:menu-entry
'(?h "Export to HTML"
((?H "As HTML buffer" org-html-export-as-html)
(?h "As HTML file" org-html-export-to-html)
(?o "As HTML file and open"
(lambda (a s v b)
(if a (org-html-export-to-html t s v b)
(org-open-file (org-html-export-to-html nil s v b)))))))
:options-alist
'((:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
(:html-container "HTML_CONTAINER" nil org-html-container-element)
(:html-content-class "HTML_CONTENT_CLASS" nil org-html-content-class)
(:description "DESCRIPTION" nil nil newline)
(:keywords "KEYWORDS" nil nil space)
(:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
(:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
(:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
(:html-link-up "HTML_LINK_UP" nil org-html-link-up)
(:html-mathjax "HTML_MATHJAX" nil "" space)
(:html-equation-reference-format "HTML_EQUATION_REFERENCE_FORMAT" nil org-html-equation-reference-format t)
(:html-postamble nil "html-postamble" org-html-postamble)
(:html-preamble nil "html-preamble" org-html-preamble)
(:html-head "HTML_HEAD" nil org-html-head newline)
(:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
(:subtitle "SUBTITLE" nil nil parse)
(:html-head-include-default-style
nil "html-style" org-html-head-include-default-style)
(:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
(:html-allow-name-attribute-in-anchors
nil nil org-html-allow-name-attribute-in-anchors)
(:html-divs nil nil org-html-divs)
(:html-checkbox-type nil nil org-html-checkbox-type)
(:html-extension nil nil org-html-extension)
(:html-footnote-format nil nil org-html-footnote-format)
(:html-footnote-separator nil nil org-html-footnote-separator)
(:html-footnotes-section nil nil org-html-footnotes-section)
(:html-format-drawer-function nil nil org-html-format-drawer-function)
(:html-format-headline-function nil nil org-html-format-headline-function)
(:html-format-inlinetask-function
nil nil org-html-format-inlinetask-function)
(:html-home/up-format nil nil org-html-home/up-format)
(:html-indent nil nil org-html-indent)
(:html-infojs-options nil nil org-html-infojs-options)
(:html-infojs-template nil nil org-html-infojs-template)
(:html-inline-image-rules nil nil org-html-inline-image-rules)
(:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
(:html-mathjax-options nil nil org-html-mathjax-options)
(:html-mathjax-template nil nil org-html-mathjax-template)
(:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
(:html-postamble-format nil nil org-html-postamble-format)
(:html-preamble-format nil nil org-html-preamble-format)
(:html-prefer-user-labels nil nil org-html-prefer-user-labels)
(:html-self-link-headlines nil nil org-html-self-link-headlines)
(:html-table-align-individual-fields
nil nil org-html-table-align-individual-fields)
(:html-table-caption-above nil nil org-html-table-caption-above)
(:html-table-data-tags nil nil org-html-table-data-tags)
(:html-table-header-tags nil nil org-html-table-header-tags)
(:html-table-use-header-tags-for-first-column
nil nil org-html-table-use-header-tags-for-first-column)
(:html-tag-class-prefix nil nil org-html-tag-class-prefix)
(:html-text-markup-alist nil nil org-html-text-markup-alist)
(:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
(:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
(:html-use-infojs nil nil org-html-use-infojs)
(:html-validation-link nil nil org-html-validation-link)
(:html-viewport nil nil org-html-viewport)
(:html-inline-images nil nil org-html-inline-images)
(:html-table-attributes nil nil org-html-table-default-attributes)
(:html-table-row-open-tag nil nil org-html-table-row-open-tag)
(:html-table-row-close-tag nil nil org-html-table-row-close-tag)
(:html-xml-declaration nil nil org-html-xml-declaration)
(:html-wrap-src-lines nil nil org-html-wrap-src-lines)
(:html-klipsify-src nil nil org-html-klipsify-src)
(:html-klipse-css nil nil org-html-klipse-css)
(:html-klipse-js nil nil org-html-klipse-js)
(:html-klipse-selection-script nil nil org-html-klipse-selection-script)
(:infojs-opt "INFOJS_OPT" nil nil)
;; Redefine regular options.
(:creator "CREATOR" nil org-html-creator-string)
(:with-latex nil "tex" org-html-with-latex)
;; Retrieve LaTeX header for fragments.
(:latex-header "LATEX_HEADER" nil nil newline)
;; Custom options for custom html
(:nav-sections "NAV_SECTIONS" nil nil parse)
(:nav-section "NAV_SECTION" nil nil newline)
(:hidden "HIDDEN" nil nil newline)
(:warning "WARNING" nil nil newline)
))
;; I wish there was a better way
;;;;; Get Reference
(defun org-export-format-reference (reference)
"Format REFERENCE into a string.
REFERENCE is a number representing a reference, as returned by
`org-export-new-reference', which see."
(if (numberp reference)
(format "org%07x" reference)
reference))
;;;;; Link
(defun org-html-link (link desc info)
"Transcode a LINK object from Org to HTML.
DESC is the description part of the link, or the empty string.
INFO is a plist holding contextual information. See
`org-export-data'."
(let* ((html-ext (plist-get info :html-extension))
(dot (when (> (length html-ext) 0) "."))
(link-org-files-as-html-maybe
(lambda (raw-path info)
;; Treat links to `file.org' as links to `file.html', if
;; needed. See `org-html-link-org-files-as-html'.
(save-match-data
(cond
((and (plist-get info :html-link-org-files-as-html)
(let ((case-fold-search t))
(string-match "\\(.+\\)\\.org\\(?:\\.gpg\\)?$" raw-path)))
(concat (match-string 1 raw-path) dot html-ext))
(t raw-path)))))
(type (org-element-property :type link))
(raw-path (org-element-property :path link))
;; Ensure DESC really exists, or set it to nil.
(desc (org-string-nw-p desc))
(path
(cond
((string= "file" type)
;; During publishing, turn absolute file names belonging
;; to base directory into relative file names. Otherwise,
;; append "file" protocol to absolute file name.
(setq raw-path
(org-export-file-uri
(org-publish-file-relative-name raw-path info)))
;; Possibly append `:html-link-home' to relative file
;; name.
(let ((home (and (plist-get info :html-link-home)
(org-trim (plist-get info :html-link-home)))))
(when (and home
(plist-get info :html-link-use-abs-url)
(not (file-name-absolute-p raw-path)))
(setq raw-path (concat (file-name-as-directory home) raw-path))))
;; Maybe turn ".org" into ".html".
(setq raw-path (funcall link-org-files-as-html-maybe raw-path info))
;; Add search option, if any. A search option can be
;; relative to a custom-id, a headline title, a name or
;; a target.
(let ((option (org-element-property :search-option link)))
(if (not option) raw-path
(let ((path (org-element-property :path link)))
(concat raw-path
"#"
(org-publish-resolve-external-link option path t))))))
(t (url-encode-url (concat type ":" raw-path)))))
(attributes-plist
(org-combine-plists
;; Extract attributes from parent's paragraph. HACK: Only
;; do this for the first link in parent (inner image link
;; for inline images). This is needed as long as
;; attributes cannot be set on a per link basis.
(let* ((parent (org-element-parent-element link))
(link (let ((container (org-element-parent link)))
(if (and (org-element-type-p container 'link)
(org-html-inline-image-p link info))
container
link))))
(and (eq link (org-element-map parent 'link #'identity info t))
(org-export-read-attribute :attr_html parent)))
;; Also add attributes from link itself. Currently, those
;; need to be added programmatically before `org-html-link'
;; is invoked, for example, by backends building upon HTML
;; export.
(org-export-read-attribute :attr_html link)))
(attributes
(let ((attr (org-html--make-attribute-string attributes-plist)))
(if (org-string-nw-p attr) (concat " " attr) ""))))
(cond
;; Link type is handled by a special function.
((org-export-custom-protocol-maybe link desc 'html info))
;; Image file.
((and (plist-get info :html-inline-images)
(org-export-inline-image-p
link (plist-get info :html-inline-image-rules)))
(org-html--format-image path attributes-plist info))
;; Radio target: Transcode target's contents and use them as
;; link's description.
((string= type "radio")
(let ((destination (org-export-resolve-radio-link link info)))
(if (not destination) desc
(format "<a class=\"link\" href=\"#%s\"%s>%s</a>"
(org-export-get-reference destination info)
attributes
desc))))
;; Links pointing to a headline: Find destination and build
;; appropriate referencing command.
((member type '("custom-id" "fuzzy" "id"))
(let ((destination (if (string= type "fuzzy")
(org-export-resolve-fuzzy-link link info)
(org-export-resolve-id-link link info))))
(pcase (org-element-type destination)
;; ID link points to an external file.
(`plain-text
(let ((fragment (concat org-html--id-attr-prefix raw-path))
;; Treat links to ".org" files as ".html", if needed.
(path (funcall link-org-files-as-html-maybe
destination info)))
(format "<a class=\"link\" href=\"%s#%s\"%s>%s</a>"
path fragment attributes (or desc destination))))
;; Fuzzy link points nowhere.
(`nil
(format "<i>%s</i>"
(or desc
(org-export-data
(org-element-property :raw-link link) info))))
;; Link points to a headline.
(`headline
(let ((href (org-html--reference destination info))
;; What description to use?
(desc
;; Case 1: Headline is numbered and LINK has no
;; description. Display section number.
(if (and (org-export-numbered-headline-p destination info)
(not desc))
(mapconcat #'number-to-string
(org-export-get-headline-number
destination info) ".")
;; Case 2: Either the headline is un-numbered or
;; LINK has a custom description. Display LINK's
;; description or headline's title.
(or desc
(org-export-data
(org-element-property :title destination) info)))))
(format "<a class=\"link\" href=\"#%s\"%s>%s</a>" href attributes desc)))
;; Fuzzy link points to a target or an element.
(_
(if (and destination
(memq (plist-get info :with-latex) '(mathjax t))
(org-element-type-p destination 'latex-environment)
(eq 'math (org-latex--environment-type destination)))
;; Caption and labels are introduced within LaTeX
;; environment. Use "ref" or "eqref" macro, depending on user
;; preference to refer to those in the document.
(format (plist-get info :html-equation-reference-format)
(org-html--reference destination info))
(let* ((ref (org-html--reference destination info))
(org-html-standalone-image-predicate
#'org-html--has-caption-p)
(counter-predicate
(if (org-element-type-p destination 'latex-environment)
#'org-html--math-environment-p
#'org-html--has-caption-p))
(number
(cond
(desc nil)
((org-html-standalone-image-p destination info)
(org-export-get-ordinal
(org-element-map destination 'link #'identity info t)
info '(link) 'org-html-standalone-image-p))
(t (org-export-get-ordinal
destination info nil counter-predicate))))
(desc
(cond (desc)
((not number) "No description for this link")
((numberp number) (number-to-string number))
(t (mapconcat #'number-to-string number ".")))))
(format "<a class=\"link\" href=\"#%s\"%s>%s</a>" ref attributes desc)))))))
;; Coderef: replace link with the reference name or the
;; equivalent line number.
((string= type "coderef")
(let ((fragment (concat "coderef-" (org-html-encode-plain-text raw-path))))
(format "<a class=\"link\" href=\"#%s\" %s%s>%s</a>"
fragment
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
'%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
fragment fragment)
attributes
(format (org-export-get-coderef-format raw-path desc)
(org-export-resolve-coderef raw-path info)))))
;; External link with a description part.
((and path desc)
(format "<a class=\"link\" href=\"%s\"%s>%s</a>"
(org-html-encode-plain-text path)
attributes
desc))
;; External link without a description part.
(path
(let ((path (org-html-encode-plain-text path)))
(format "<a class=\"link\" href=\"%s\"%s>%s</a>" path attributes path)))
;; No path, only description. Try to do something useful.
(t
(format "<i>%s</i>" desc)))))
;;;;; List
(defun org-html-plain-list (plain-list contents _info)
"Transcode a PLAIN-LIST element from Org to HTML.
CONTENTS is the contents of the list. INFO is a plist holding
contextual information."
(let* ((type (pcase (org-element-property :type plain-list)
(`ordered "ol")
(`unordered "ul")
(`descriptive "dl")
(other (error "Unknown HTML list type: %s" other))))
(attributes (org-export-read-attribute :attr_html plain-list))
(list-class
(if (not (and (plist-get attributes :class)
(or
(s-contains? "list--number" (plist-get attributes :class))
(s-contains? "list--bullet" (plist-get attributes :class)))))
(pcase (org-element-property :type plain-list)
(`ordered "list--number")
(`unordered "list--bullet")
(`descriptive "")
(other (error "Unknown HTML list type: %s" other)))
""))
(class (format "org-%s %s list--spaced" type list-class))
)
(format "<%s %s>\n%s</%s>"
type
(org-html--make-attribute-string
(plist-put attributes :class
(org-trim
(mapconcat #'identity
(list class (plist-get attributes :class))
" "))))
contents
type)))
;;;;; Quote
(defun org-html-quote-block (quote-block contents info)
"Transcode a QUOTE-BLOCK element from Org to HTML.
CONTENTS holds the contents of the block. INFO is a plist
holding contextual information."
(format "<blockquote class=\"inset-text\" %s>\n%s</blockquote>"
(let* ((reference (org-html--reference quote-block info t))
(attributes (org-export-read-attribute :attr_html quote-block))
(a (org-html--make-attribute-string
(if (or (not reference) (plist-member attributes :id))
attributes
(plist-put attributes :id reference)))))
(if (org-string-nw-p a) (concat " " a) ""))
contents))
;;;;; Table
(defun org-html-table (table contents info)
"Transcode a TABLE element from Org to HTML.
CONTENTS is the contents of the table. INFO is a plist holding
contextual information."
(if (eq (org-element-property :type table) 'table.el)
;; "table.el" table. Convert it using appropriate tools.
(org-html-table--table.el-table table info)
;; Standard table.
(let* ((caption (org-export-get-caption table))
(number (org-export-get-ordinal
table info nil #'org-html--has-caption-p))
(attributes
(org-html--make-attribute-string
(org-combine-plists
(list :id (org-html--reference table info t))
(and (not (org-html-html5-p info))
(plist-get info :html-table-attributes))
(org-export-read-attribute :attr_html table))))
(alignspec
(if (bound-and-true-p org-html-format-table-no-css)
"align=\"%s\""
"class=\"org-%s\""))
(table-column-specs
(lambda (table info)
(mapconcat
(lambda (table-cell)
(let ((alignment (org-export-table-cell-alignment
table-cell info)))
(concat
;; Begin a colgroup?
(when (org-export-table-cell-starts-colgroup-p
table-cell info)
"\n<colgroup>")
;; Add a column. Also specify its alignment.
(format "\n%s"
(org-html-close-tag
"col" (concat " " (format alignspec alignment)) info))
;; End a colgroup?
(when (org-export-table-cell-ends-colgroup-p
table-cell info)
"\n</colgroup>"))))
(org-html-table-first-row-data-cells table info) "\n"))))
(format "<table class=\"table\" %s>\n%s\n%s\n%s</table>"
(if (equal attributes "") "" (concat " " attributes))
(if (not caption) ""
(format (if (plist-get info :html-table-caption-above)
"<caption class=\"t-above\">%s</caption>"
"<caption class=\"t-bottom\">%s</caption>")
(concat
"<span class=\"table-number\">"
(format (org-html--translate "Table %d:" info) number)
"</span> " (org-export-data caption info))))
(funcall table-column-specs table info)
contents))))
;;;;; Paragraph
(defun org-html-paragraph (paragraph contents info)
"Transcode a PARAGRAPH element from Org to HTML.
CONTENTS is the contents of the paragraph, as a string. INFO is
the plist used as a communication channel."
(let* ((parent (org-export-get-parent paragraph))
(parent-type (org-element-type parent))
(style '((footnote-definition " class=\"footpara\"")
(org-data " class=\"footpara\"")))
(attributes (org-html--make-attribute-string
(org-export-read-attribute :attr_html paragraph)))
(extra (or (cadr (assq parent-type style)) "")))
(cond
((string-empty-p (string-trim contents)) "")
((and (eq parent-type 'item)
(not (org-export-get-previous-element paragraph info))
(let ((followers (org-export-get-next-element paragraph info 2)))
(and (not (cdr followers))
(memq (org-element-type (car followers)) '(nil plain-list)))))
;; First paragraph in an item has no tag if it is alone or
;; followed, at most, by a sub-list.
contents)
((org-html-standalone-image-p paragraph info)
;; Standalone image.
(let ((caption
(let ((raw (org-export-data
(org-export-get-caption paragraph) info))
(org-html-standalone-image-predicate
#'org-html--has-caption-p))
(if (not (org-string-nw-p raw)) raw
(concat "<span class=\"figure-number\">"
(format (org-html--translate "Figure %d:" info)
(org-export-get-ordinal
(org-element-map paragraph 'link
#'identity info t)
info nil #'org-html-standalone-image-p))
" </span>"
raw))))
(label (org-html--reference paragraph info)))
(org-html--wrap-image contents info caption label)))
;; if a quoted html snippet, don't wrap in p, might break structure
((org-html-is-quoted-snippet paragraph)
contents)
;; Regular paragraph.
(t
(format "<p class=\"body\" %s%s>\n%s</p>"
(if (org-string-nw-p attributes)
(concat " " attributes) "")
extra contents)))))
;;;;; Code
(defun org-html-src-block (src-block _contents info)
"Transcode a SRC-BLOCK element from Org to HTML.
CONTENTS holds the contents of the item. INFO is a plist holding
contextual information."
(if (org-export-read-attribute :attr_html src-block :textarea)
(org-html--textarea-block src-block)
(let* ((lang (org-element-property :language src-block))
(code ;; (car (org-export-unravel-code src-block))
(org-html-format-code src-block info)
)
(label (let ((lbl (org-html--reference src-block info t)))
(if lbl (format " id=\"%s\"" lbl) ""))))
(format "<div class=\"body org-src-container\">\n%s%s\n</div>"
;; Build caption.
(let ((caption (org-export-get-caption src-block)))
(if (not caption) ""
(let ((listing-number
(format
"<span class=\"listing-number\">%s </span>"
(format
(org-html--translate "Listing %d:" info)
(org-export-get-ordinal
src-block info nil #'org-html--has-caption-p)))))
(format "<label class=\"org-src-name\">%s%s</label>"
listing-number
(org-trim (org-export-data caption info))))))
;; Contents.
(format "<pre class=\"src src-%s lang-%s\"%s><code>%s</code></pre>"
;; Lang being nil is OK.
lang lang label code)))))
;;;;; Section
(defun org-html-section (section contents info)
"Transcode a SECTION element from Org to HTML.
CONTENTS holds the contents of the section. INFO is a plist
holding contextual information."
(let ((parent (org-export-get-parent-headline section)))
;; Before first headline: no container, just return CONTENTS.
(if (not parent) contents
;; Get div's class and id references.
(let* ((class-num (+ (org-export-get-relative-level parent info)
(1- (plist-get info :html-toplevel-hlevel))))
(section-number
(and (org-export-numbered-headline-p parent info)
(mapconcat
#'number-to-string
(org-export-get-headline-number parent info) "-")))
(manual-row (org-element-property :MANUAL-ROW parent))
(row-reverse (org-element-property :ROW-REVERSE parent)))
;; Build return value.
(format "<div class=\"grid-row %s outline-text-%d\" id=\"text-%s\">\n%s%s%s</div>\n"
(if row-reverse "grid-row-reverse" "")
class-num
(or (org-element-property :CUSTOM_ID parent)
section-number
(org-export-get-reference parent info))
(if manual-row "" "<div class=\"grid-column-full\">\n")
(or contents "")
(if manual-row "" "</div>\n"))))))
;;;;; Headline
(defun org-html-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)
(let* ((numberedp (org-export-numbered-headline-p headline info))
(numbers (org-export-get-headline-number headline info))
(level (+ (org-export-get-relative-level headline info)
(1- (plist-get info :html-toplevel-hlevel))))
(todo (and (plist-get info :with-todo-keywords)
(let ((todo (org-element-property :todo-keyword headline)))
(and todo (org-export-data todo info)))))
(todo-type (and todo (org-element-property :todo-type headline)))
(priority (and (plist-get info :with-priority)
(org-element-property :priority headline)))
(text (org-export-data (org-element-property :title headline) info))
(tags (and (plist-get info :with-tags)
(org-export-get-tags headline info)))