lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / lisp / ox-html.el
blob9d9de62ed1b73dab9dc183b039dd031d368951f5
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2011-2019 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; See Org manual for more information.
29 ;;; Code:
31 ;;; Dependencies
33 (require 'cl-lib)
34 (require 'format-spec)
35 (require 'ox)
36 (require 'ox-publish)
37 (require 'table)
40 ;;; Function Declarations
42 (declare-function org-id-find-id-file "org-id" (id))
43 (declare-function htmlize-region "ext:htmlize" (beg end))
44 (declare-function mm-url-decode-entities "mm-url" ())
46 (defvar htmlize-css-name-prefix)
47 (defvar htmlize-output-type)
48 (defvar htmlize-output-type)
49 (defvar htmlize-css-name-prefix)
51 ;;; Define Back-End
53 (org-export-define-backend 'html
54 '((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (node-property . org-html-node-property)
80 (paragraph . org-html-paragraph)
81 (plain-list . org-html-plain-list)
82 (plain-text . org-html-plain-text)
83 (planning . org-html-planning)
84 (property-drawer . org-html-property-drawer)
85 (quote-block . org-html-quote-block)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :filters-alist '((:filter-options . org-html-infojs-install-script)
104 (:filter-parse-tree . org-html-image-link-filter)
105 (:filter-final-output . org-html-final-function))
106 :menu-entry
107 '(?h "Export to HTML"
108 ((?H "As HTML buffer" org-html-export-as-html)
109 (?h "As HTML file" org-html-export-to-html)
110 (?o "As HTML file and open"
111 (lambda (a s v b)
112 (if a (org-html-export-to-html t s v b)
113 (org-open-file (org-html-export-to-html nil s v b)))))))
114 :options-alist
115 '((:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
116 (:html-container "HTML_CONTAINER" nil org-html-container-element)
117 (:description "DESCRIPTION" nil nil newline)
118 (:keywords "KEYWORDS" nil nil space)
119 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
120 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
121 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
122 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
123 (:html-mathjax "HTML_MATHJAX" nil "" space)
124 (:html-postamble nil "html-postamble" org-html-postamble)
125 (:html-preamble nil "html-preamble" org-html-preamble)
126 (:html-head "HTML_HEAD" nil org-html-head newline)
127 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
128 (:subtitle "SUBTITLE" nil nil parse)
129 (:html-head-include-default-style
130 nil "html-style" org-html-head-include-default-style)
131 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
132 (:html-allow-name-attribute-in-anchors
133 nil nil org-html-allow-name-attribute-in-anchors)
134 (:html-divs nil nil org-html-divs)
135 (:html-checkbox-type nil nil org-html-checkbox-type)
136 (:html-extension nil nil org-html-extension)
137 (:html-footnote-format nil nil org-html-footnote-format)
138 (:html-footnote-separator nil nil org-html-footnote-separator)
139 (:html-footnotes-section nil nil org-html-footnotes-section)
140 (:html-format-drawer-function nil nil org-html-format-drawer-function)
141 (:html-format-headline-function nil nil org-html-format-headline-function)
142 (:html-format-inlinetask-function
143 nil nil org-html-format-inlinetask-function)
144 (:html-home/up-format nil nil org-html-home/up-format)
145 (:html-indent nil nil org-html-indent)
146 (:html-infojs-options nil nil org-html-infojs-options)
147 (:html-infojs-template nil nil org-html-infojs-template)
148 (:html-inline-image-rules nil nil org-html-inline-image-rules)
149 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
150 (:html-mathjax-options nil nil org-html-mathjax-options)
151 (:html-mathjax-template nil nil org-html-mathjax-template)
152 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
153 (:html-postamble-format nil nil org-html-postamble-format)
154 (:html-preamble-format nil nil org-html-preamble-format)
155 (:html-self-link-headlines nil nil org-html-self-link-headlines)
156 (:html-table-align-individual-fields
157 nil nil org-html-table-align-individual-fields)
158 (:html-table-caption-above nil nil org-html-table-caption-above)
159 (:html-table-data-tags nil nil org-html-table-data-tags)
160 (:html-table-header-tags nil nil org-html-table-header-tags)
161 (:html-table-use-header-tags-for-first-column
162 nil nil org-html-table-use-header-tags-for-first-column)
163 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
164 (:html-text-markup-alist nil nil org-html-text-markup-alist)
165 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
166 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
167 (:html-use-infojs nil nil org-html-use-infojs)
168 (:html-validation-link nil nil org-html-validation-link)
169 (:html-viewport nil nil org-html-viewport)
170 (:html-inline-images nil nil org-html-inline-images)
171 (:html-table-attributes nil nil org-html-table-default-attributes)
172 (:html-table-row-open-tag nil nil org-html-table-row-open-tag)
173 (:html-table-row-close-tag nil nil org-html-table-row-close-tag)
174 (:html-xml-declaration nil nil org-html-xml-declaration)
175 (:html-klipsify-src nil nil org-html-klipsify-src)
176 (:html-klipse-css nil nil org-html-klipse-css)
177 (:html-klipse-js nil nil org-html-klipse-js)
178 (:html-klipse-selection-script nil nil org-html-klipse-selection-script)
179 (:infojs-opt "INFOJS_OPT" nil nil)
180 ;; Redefine regular options.
181 (:creator "CREATOR" nil org-html-creator-string)
182 (:with-latex nil "tex" org-html-with-latex)
183 ;; Retrieve LaTeX header for fragments.
184 (:latex-header "LATEX_HEADER" nil nil newline)))
187 ;;; Internal Variables
189 (defvar org-html-format-table-no-css)
190 (defvar htmlize-buffer-places) ; from htmlize.el
192 (defvar org-html--pre/postamble-class "status"
193 "CSS class used for pre/postamble")
195 (defconst org-html-doctype-alist
196 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
197 \"http://www.w3.org/TR/html4/strict.dtd\">")
198 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
199 \"http://www.w3.org/TR/html4/loose.dtd\">")
200 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
201 \"http://www.w3.org/TR/html4/frameset.dtd\">")
203 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
204 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
205 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
206 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
207 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
208 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
209 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
210 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
212 ("html5" . "<!DOCTYPE html>")
213 ("xhtml5" . "<!DOCTYPE html>"))
214 "An alist mapping (x)html flavors to specific doctypes.")
216 (defconst org-html-html5-elements
217 '("article" "aside" "audio" "canvas" "details" "figcaption"
218 "figure" "footer" "header" "menu" "meter" "nav" "output"
219 "progress" "section" "summary" "video")
220 "New elements in html5.
222 For blocks that should contain headlines, use the HTML_CONTAINER
223 property on the headline itself.")
225 (defconst org-html-special-string-regexps
226 '(("\\\\-" . "&#x00ad;") ; shy
227 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
228 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
229 ("\\.\\.\\." . "&#x2026;")) ; hellip
230 "Regular expressions for special string conversion.")
232 (defconst org-html-scripts
233 "<script type=\"text/javascript\">
235 @licstart The following is the entire license notice for the
236 JavaScript code in this tag.
238 Copyright (C) 2012-2019 Free Software Foundation, Inc.
240 The JavaScript code in this tag is free software: you can
241 redistribute it and/or modify it under the terms of the GNU
242 General Public License (GNU GPL) as published by the Free Software
243 Foundation, either version 3 of the License, or (at your option)
244 any later version. The code is distributed WITHOUT ANY WARRANTY;
245 without even the implied warranty of MERCHANTABILITY or FITNESS
246 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
248 As additional permission under GNU GPL version 3 section 7, you
249 may distribute non-source (e.g., minimized or compacted) forms of
250 that code without the copy of the GNU GPL normally required by
251 section 4, provided you include this license notice and a URL
252 through which recipients can access the Corresponding Source.
255 @licend The above is the entire license notice
256 for the JavaScript code in this tag.
258 <!--/*--><![CDATA[/*><!--*/
259 function CodeHighlightOn(elem, id)
261 var target = document.getElementById(id);
262 if(null != target) {
263 elem.cacheClassElem = elem.className;
264 elem.cacheClassTarget = target.className;
265 target.className = \"code-highlighted\";
266 elem.className = \"code-highlighted\";
269 function CodeHighlightOff(elem, id)
271 var target = document.getElementById(id);
272 if(elem.cacheClassElem)
273 elem.className = elem.cacheClassElem;
274 if(elem.cacheClassTarget)
275 target.className = elem.cacheClassTarget;
277 /*]]>*///-->
278 </script>"
279 "Basic JavaScript that is needed by HTML files produced by Org mode.")
281 (defconst org-html-style-default
282 "<style type=\"text/css\">
283 <!--/*--><![CDATA[/*><!--*/
284 .title { text-align: center;
285 margin-bottom: .2em; }
286 .subtitle { text-align: center;
287 font-size: medium;
288 font-weight: bold;
289 margin-top:0; }
290 .todo { font-family: monospace; color: red; }
291 .done { font-family: monospace; color: green; }
292 .priority { font-family: monospace; color: orange; }
293 .tag { background-color: #eee; font-family: monospace;
294 padding: 2px; font-size: 80%; font-weight: normal; }
295 .timestamp { color: #bebebe; }
296 .timestamp-kwd { color: #5f9ea0; }
297 .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
298 .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
299 .org-center { margin-left: auto; margin-right: auto; text-align: center; }
300 .underline { text-decoration: underline; }
301 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
302 p.verse { margin-left: 3%; }
303 pre {
304 border: 1px solid #ccc;
305 box-shadow: 3px 3px 3px #eee;
306 padding: 8pt;
307 font-family: monospace;
308 overflow: auto;
309 margin: 1.2em;
311 pre.src {
312 position: relative;
313 overflow: visible;
314 padding-top: 1.2em;
316 pre.src:before {
317 display: none;
318 position: absolute;
319 background-color: white;
320 top: -10px;
321 right: 10px;
322 padding: 3px;
323 border: 1px solid black;
325 pre.src:hover:before { display: inline;}
326 /* Languages per Org manual */
327 pre.src-asymptote:before { content: 'Asymptote'; }
328 pre.src-awk:before { content: 'Awk'; }
329 pre.src-C:before { content: 'C'; }
330 /* pre.src-C++ doesn't work in CSS */
331 pre.src-clojure:before { content: 'Clojure'; }
332 pre.src-css:before { content: 'CSS'; }
333 pre.src-D:before { content: 'D'; }
334 pre.src-ditaa:before { content: 'ditaa'; }
335 pre.src-dot:before { content: 'Graphviz'; }
336 pre.src-calc:before { content: 'Emacs Calc'; }
337 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
338 pre.src-fortran:before { content: 'Fortran'; }
339 pre.src-gnuplot:before { content: 'gnuplot'; }
340 pre.src-haskell:before { content: 'Haskell'; }
341 pre.src-hledger:before { content: 'hledger'; }
342 pre.src-java:before { content: 'Java'; }
343 pre.src-js:before { content: 'Javascript'; }
344 pre.src-latex:before { content: 'LaTeX'; }
345 pre.src-ledger:before { content: 'Ledger'; }
346 pre.src-lisp:before { content: 'Lisp'; }
347 pre.src-lilypond:before { content: 'Lilypond'; }
348 pre.src-lua:before { content: 'Lua'; }
349 pre.src-matlab:before { content: 'MATLAB'; }
350 pre.src-mscgen:before { content: 'Mscgen'; }
351 pre.src-ocaml:before { content: 'Objective Caml'; }
352 pre.src-octave:before { content: 'Octave'; }
353 pre.src-org:before { content: 'Org mode'; }
354 pre.src-oz:before { content: 'OZ'; }
355 pre.src-plantuml:before { content: 'Plantuml'; }
356 pre.src-processing:before { content: 'Processing.js'; }
357 pre.src-python:before { content: 'Python'; }
358 pre.src-R:before { content: 'R'; }
359 pre.src-ruby:before { content: 'Ruby'; }
360 pre.src-sass:before { content: 'Sass'; }
361 pre.src-scheme:before { content: 'Scheme'; }
362 pre.src-screen:before { content: 'Gnu Screen'; }
363 pre.src-sed:before { content: 'Sed'; }
364 pre.src-sh:before { content: 'shell'; }
365 pre.src-sql:before { content: 'SQL'; }
366 pre.src-sqlite:before { content: 'SQLite'; }
367 /* additional languages in org.el's org-babel-load-languages alist */
368 pre.src-forth:before { content: 'Forth'; }
369 pre.src-io:before { content: 'IO'; }
370 pre.src-J:before { content: 'J'; }
371 pre.src-makefile:before { content: 'Makefile'; }
372 pre.src-maxima:before { content: 'Maxima'; }
373 pre.src-perl:before { content: 'Perl'; }
374 pre.src-picolisp:before { content: 'Pico Lisp'; }
375 pre.src-scala:before { content: 'Scala'; }
376 pre.src-shell:before { content: 'Shell Script'; }
377 pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
378 /* additional language identifiers per \"defun org-babel-execute\"
379 in ob-*.el */
380 pre.src-cpp:before { content: 'C++'; }
381 pre.src-abc:before { content: 'ABC'; }
382 pre.src-coq:before { content: 'Coq'; }
383 pre.src-groovy:before { content: 'Groovy'; }
384 /* additional language identifiers from org-babel-shell-names in
385 ob-shell.el: ob-shell is the only babel language using a lambda to put
386 the execution function name together. */
387 pre.src-bash:before { content: 'bash'; }
388 pre.src-csh:before { content: 'csh'; }
389 pre.src-ash:before { content: 'ash'; }
390 pre.src-dash:before { content: 'dash'; }
391 pre.src-ksh:before { content: 'ksh'; }
392 pre.src-mksh:before { content: 'mksh'; }
393 pre.src-posh:before { content: 'posh'; }
394 /* Additional Emacs modes also supported by the LaTeX listings package */
395 pre.src-ada:before { content: 'Ada'; }
396 pre.src-asm:before { content: 'Assembler'; }
397 pre.src-caml:before { content: 'Caml'; }
398 pre.src-delphi:before { content: 'Delphi'; }
399 pre.src-html:before { content: 'HTML'; }
400 pre.src-idl:before { content: 'IDL'; }
401 pre.src-mercury:before { content: 'Mercury'; }
402 pre.src-metapost:before { content: 'MetaPost'; }
403 pre.src-modula-2:before { content: 'Modula-2'; }
404 pre.src-pascal:before { content: 'Pascal'; }
405 pre.src-ps:before { content: 'PostScript'; }
406 pre.src-prolog:before { content: 'Prolog'; }
407 pre.src-simula:before { content: 'Simula'; }
408 pre.src-tcl:before { content: 'tcl'; }
409 pre.src-tex:before { content: 'TeX'; }
410 pre.src-plain-tex:before { content: 'Plain TeX'; }
411 pre.src-verilog:before { content: 'Verilog'; }
412 pre.src-vhdl:before { content: 'VHDL'; }
413 pre.src-xml:before { content: 'XML'; }
414 pre.src-nxml:before { content: 'XML'; }
415 /* add a generic configuration mode; LaTeX export needs an additional
416 (add-to-list 'org-latex-listings-langs '(conf \" \")) in .emacs */
417 pre.src-conf:before { content: 'Configuration File'; }
419 table { border-collapse:collapse; }
420 caption.t-above { caption-side: top; }
421 caption.t-bottom { caption-side: bottom; }
422 td, th { vertical-align:top; }
423 th.org-right { text-align: center; }
424 th.org-left { text-align: center; }
425 th.org-center { text-align: center; }
426 td.org-right { text-align: right; }
427 td.org-left { text-align: left; }
428 td.org-center { text-align: center; }
429 dt { font-weight: bold; }
430 .footpara { display: inline; }
431 .footdef { margin-bottom: 1em; }
432 .figure { padding: 1em; }
433 .figure p { text-align: center; }
434 .equation-container {
435 display: table;
436 text-align: center;
437 width: 100%;
439 .equation {
440 vertical-align: middle;
442 .equation-label {
443 display: table-cell;
444 text-align: right;
445 vertical-align: middle;
447 .inlinetask {
448 padding: 10px;
449 border: 2px solid gray;
450 margin: 10px;
451 background: #ffffcc;
453 #org-div-home-and-up
454 { text-align: right; font-size: 70%; white-space: nowrap; }
455 textarea { overflow-x: auto; }
456 .linenr { font-size: smaller }
457 .code-highlighted { background-color: #ffff00; }
458 .org-info-js_info-navigation { border-style: none; }
459 #org-info-js_console-label
460 { font-size: 10px; font-weight: bold; white-space: nowrap; }
461 .org-info-js_search-highlight
462 { background-color: #ffff00; color: #000000; font-weight: bold; }
463 .org-svg { width: 90%; }
464 /*]]>*/-->
465 </style>"
466 "The default style specification for exported HTML files.
467 You can use `org-html-head' and `org-html-head-extra' to add to
468 this style. If you don't want to include this default style,
469 customize `org-html-head-include-default-style'.")
472 ;;; User Configuration Variables
474 (defgroup org-export-html nil
475 "Options for exporting Org mode files to HTML."
476 :tag "Org Export HTML"
477 :group 'org-export)
479 ;;;; Handle infojs
481 (defvar org-html-infojs-opts-table
482 '((path PATH "https://orgmode.org/org-info.js")
483 (view VIEW "info")
484 (toc TOC :with-toc)
485 (ftoc FIXED_TOC "0")
486 (tdepth TOC_DEPTH "max")
487 (sdepth SECTION_DEPTH "max")
488 (mouse MOUSE_HINT "underline")
489 (buttons VIEW_BUTTONS "0")
490 (ltoc LOCAL_TOC "1")
491 (up LINK_UP :html-link-up)
492 (home LINK_HOME :html-link-home))
493 "JavaScript options, long form for script, default values.")
495 (defcustom org-html-use-infojs 'when-configured
496 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
497 This option can be nil or t to never or always use the script.
498 It can also be the symbol `when-configured', meaning that the
499 script will be linked into the export file if and only if there
500 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
501 `org-html-infojs-options'."
502 :group 'org-export-html
503 :version "24.4"
504 :package-version '(Org . "8.0")
505 :type '(choice
506 (const :tag "Never" nil)
507 (const :tag "When configured in buffer" when-configured)
508 (const :tag "Always" t)))
510 (defcustom org-html-infojs-options
511 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
512 "Options settings for the INFOJS JavaScript.
513 Each of the options must have an entry in `org-html-infojs-opts-table'.
514 The value can either be a string that will be passed to the script, or
515 a property. This property is then assumed to be a property that is defined
516 by the Export/Publishing setup of Org.
517 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
518 means to use the maximum value consistent with other options."
519 :group 'org-export-html
520 :version "24.4"
521 :package-version '(Org . "8.0")
522 :type
523 `(set :greedy t :inline t
524 ,@(mapcar
525 (lambda (x)
526 (list 'cons (list 'const (car x))
527 '(choice
528 (symbol :tag "Publishing/Export property")
529 (string :tag "Value"))))
530 org-html-infojs-opts-table)))
532 (defcustom org-html-infojs-template
533 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
536 * @source: %SCRIPT_PATH
538 * @licstart The following is the entire license notice for the
539 * JavaScript code in %SCRIPT_PATH.
541 * Copyright (C) 2012-2019 Free Software Foundation, Inc.
544 * The JavaScript code in this tag is free software: you can
545 * redistribute it and/or modify it under the terms of the GNU
546 * General Public License (GNU GPL) as published by the Free Software
547 * Foundation, either version 3 of the License, or (at your option)
548 * any later version. The code is distributed WITHOUT ANY WARRANTY;
549 * without even the implied warranty of MERCHANTABILITY or FITNESS
550 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
552 * As additional permission under GNU GPL version 3 section 7, you
553 * may distribute non-source (e.g., minimized or compacted) forms of
554 * that code without the copy of the GNU GPL normally required by
555 * section 4, provided you include this license notice and a URL
556 * through which recipients can access the Corresponding Source.
558 * @licend The above is the entire license notice
559 * for the JavaScript code in %SCRIPT_PATH.
562 </script>
564 <script type=\"text/javascript\">
567 @licstart The following is the entire license notice for the
568 JavaScript code in this tag.
570 Copyright (C) 2012-2019 Free Software Foundation, Inc.
572 The JavaScript code in this tag is free software: you can
573 redistribute it and/or modify it under the terms of the GNU
574 General Public License (GNU GPL) as published by the Free Software
575 Foundation, either version 3 of the License, or (at your option)
576 any later version. The code is distributed WITHOUT ANY WARRANTY;
577 without even the implied warranty of MERCHANTABILITY or FITNESS
578 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
580 As additional permission under GNU GPL version 3 section 7, you
581 may distribute non-source (e.g., minimized or compacted) forms of
582 that code without the copy of the GNU GPL normally required by
583 section 4, provided you include this license notice and a URL
584 through which recipients can access the Corresponding Source.
587 @licend The above is the entire license notice
588 for the JavaScript code in this tag.
591 <!--/*--><![CDATA[/*><!--*/
592 %MANAGER_OPTIONS
593 org_html_manager.setup(); // activate after the parameters are set
594 /*]]>*///-->
595 </script>"
596 "The template for the export style additions when org-info.js is used.
597 Option settings will replace the %MANAGER-OPTIONS cookie."
598 :group 'org-export-html
599 :version "24.4"
600 :package-version '(Org . "8.0")
601 :type 'string)
603 (defun org-html-infojs-install-script (exp-plist _backend)
604 "Install script in export options when appropriate.
605 EXP-PLIST is a plist containing export options. BACKEND is the
606 export back-end currently used."
607 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
608 (not (plist-get exp-plist :html-use-infojs))
609 (and (eq (plist-get exp-plist :html-use-infojs) 'when-configured)
610 (let ((opt (plist-get exp-plist :infojs-opt)))
611 (or (not opt)
612 (string= "" opt)
613 (string-match "\\<view:nil\\>" opt)))))
614 (let* ((template (plist-get exp-plist :html-infojs-template))
615 (ptoc (plist-get exp-plist :with-toc))
616 (hlevels (plist-get exp-plist :headline-levels))
617 (sdepth hlevels)
618 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
619 (options (plist-get exp-plist :infojs-opt))
620 (infojs-opt (plist-get exp-plist :html-infojs-options))
621 (table org-html-infojs-opts-table)
622 style)
623 (dolist (entry table)
624 (let* ((opt (car entry))
625 (var (nth 1 entry))
626 ;; Compute default values for script option OPT from
627 ;; `org-html-infojs-options' variable.
628 (default
629 (let ((default (cdr (assq opt infojs-opt))))
630 (if (and (symbolp default) (not (memq default '(t nil))))
631 (plist-get exp-plist default)
632 default)))
633 ;; Value set through INFOJS_OPT keyword has precedence
634 ;; over the default one.
635 (val (if (and options
636 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
637 options))
638 (match-string 1 options)
639 default)))
640 (pcase opt
641 (`path (setq template
642 (replace-regexp-in-string
643 "%SCRIPT_PATH" val template t t)))
644 (`sdepth (when (integerp (read val))
645 (setq sdepth (min (read val) sdepth))))
646 (`tdepth (when (integerp (read val))
647 (setq tdepth (min (read val) tdepth))))
648 (_ (setq val
649 (cond
650 ((or (eq val t) (equal val "t")) "1")
651 ((or (eq val nil) (equal val "nil")) "0")
652 ((stringp val) val)
653 (t (format "%s" val))))
654 (push (cons var val) style)))))
655 ;; Now we set the depth of the *generated* TOC to SDEPTH,
656 ;; because the toc will actually determine the splitting. How
657 ;; much of the toc will actually be displayed is governed by the
658 ;; TDEPTH option.
659 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
660 ;; The table of contents should not show more sections than we
661 ;; generate.
662 (setq tdepth (min tdepth sdepth))
663 (push (cons "TOC_DEPTH" tdepth) style)
664 ;; Build style string.
665 (setq style (mapconcat
666 (lambda (x)
667 (format "org_html_manager.set(\"%s\", \"%s\");"
668 (car x) (cdr x)))
669 style "\n"))
670 (when (and style (> (length style) 0))
671 (and (string-match "%MANAGER_OPTIONS" template)
672 (setq style (replace-match style t t template))
673 (setq exp-plist
674 (plist-put
675 exp-plist :html-head-extra
676 (concat (or (plist-get exp-plist :html-head-extra) "")
677 "\n"
678 style)))))
679 ;; This script absolutely needs the table of contents, so we
680 ;; change that setting.
681 (unless (plist-get exp-plist :with-toc)
682 (setq exp-plist (plist-put exp-plist :with-toc t)))
683 ;; Return the modified property list.
684 exp-plist)))
686 ;;;; Bold, etc.
688 (defcustom org-html-text-markup-alist
689 '((bold . "<b>%s</b>")
690 (code . "<code>%s</code>")
691 (italic . "<i>%s</i>")
692 (strike-through . "<del>%s</del>")
693 (underline . "<span class=\"underline\">%s</span>")
694 (verbatim . "<code>%s</code>"))
695 "Alist of HTML expressions to convert text markup.
697 The key must be a symbol among `bold', `code', `italic',
698 `strike-through', `underline' and `verbatim'. The value is
699 a formatting string to wrap fontified text with.
701 If no association can be found for a given markup, text will be
702 returned as-is."
703 :group 'org-export-html
704 :version "24.4"
705 :package-version '(Org . "8.0")
706 :type '(alist :key-type (symbol :tag "Markup type")
707 :value-type (string :tag "Format string"))
708 :options '(bold code italic strike-through underline verbatim))
710 (defcustom org-html-indent nil
711 "Non-nil means to indent the generated HTML.
712 Warning: non-nil may break indentation of source code blocks."
713 :group 'org-export-html
714 :version "24.4"
715 :package-version '(Org . "8.0")
716 :type 'boolean)
718 ;;;; Drawers
720 (defcustom org-html-format-drawer-function (lambda (_name contents) contents)
721 "Function called to format a drawer in HTML code.
723 The function must accept two parameters:
724 NAME the drawer name, like \"LOGBOOK\"
725 CONTENTS the contents of the drawer.
727 The function should return the string to be exported.
729 For example, the variable could be set to the following function
730 in order to mimic default behavior:
732 The default value simply returns the value of CONTENTS."
733 :group 'org-export-html
734 :version "24.4"
735 :package-version '(Org . "8.0")
736 :type 'function)
738 ;;;; Footnotes
740 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
741 <h2 class=\"footnotes\">%s: </h2>
742 <div id=\"text-footnotes\">
744 </div>
745 </div>"
746 "Format for the footnotes section.
747 Should contain a two instances of %s. The first will be replaced with the
748 language-specific word for \"Footnotes\", the second one will be replaced
749 by the footnotes themselves."
750 :group 'org-export-html
751 :type 'string)
753 (defcustom org-html-footnote-format "<sup>%s</sup>"
754 "The format for the footnote reference.
755 %s will be replaced by the footnote reference itself."
756 :group 'org-export-html
757 :type 'string)
759 (defcustom org-html-footnote-separator "<sup>, </sup>"
760 "Text used to separate footnotes."
761 :group 'org-export-html
762 :type 'string)
764 ;;;; Headline
766 (defcustom org-html-toplevel-hlevel 2
767 "The <H> level for level 1 headings in HTML export.
768 This is also important for the classes that will be wrapped around headlines
769 and outline structure. If this variable is 1, the top-level headlines will
770 be <h1>, and the corresponding classes will be outline-1, section-number-1,
771 and outline-text-1. If this is 2, all of these will get a 2 instead.
772 The default for this variable is 2, because we use <h1> for formatting the
773 document title."
774 :group 'org-export-html
775 :type 'integer)
777 (defcustom org-html-format-headline-function
778 'org-html-format-headline-default-function
779 "Function to format headline text.
781 This function will be called with six arguments:
782 TODO the todo keyword (string or nil).
783 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
784 PRIORITY the priority of the headline (integer or nil)
785 TEXT the main headline text (string).
786 TAGS the tags (string or nil).
787 INFO the export options (plist).
789 The function result will be used in the section format string."
790 :group 'org-export-html
791 :version "26.1"
792 :package-version '(Org . "8.3")
793 :type 'function)
795 ;;;; HTML-specific
797 (defcustom org-html-allow-name-attribute-in-anchors nil
798 "When nil, do not set \"name\" attribute in anchors.
799 By default, when appropriate, anchors are formatted with \"id\"
800 but without \"name\" attribute."
801 :group 'org-export-html
802 :version "24.4"
803 :package-version '(Org . "8.0")
804 :type 'boolean)
806 (defcustom org-html-self-link-headlines nil
807 "When non-nil, the headlines contain a hyperlink to themselves."
808 :group 'org-export-html
809 :package-version '(Org . "9.3")
810 :type 'boolean
811 :safe #'booleanp)
813 ;;;; Inlinetasks
815 (defcustom org-html-format-inlinetask-function
816 'org-html-format-inlinetask-default-function
817 "Function called to format an inlinetask in HTML code.
819 The function must accept seven parameters:
820 TODO the todo keyword, as a string
821 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
822 PRIORITY the inlinetask priority, as a string
823 NAME the inlinetask name, as a string.
824 TAGS the inlinetask tags, as a list of strings.
825 CONTENTS the contents of the inlinetask, as a string.
826 INFO the export options, as a plist
828 The function should return the string to be exported."
829 :group 'org-export-html
830 :version "26.1"
831 :package-version '(Org . "8.3")
832 :type 'function)
834 ;;;; LaTeX
836 (defcustom org-html-with-latex org-export-with-latex
837 "Non-nil means process LaTeX math snippets.
839 When set, the exporter will process LaTeX environments and
840 fragments.
842 This option can also be set with the +OPTIONS line,
843 e.g. \"tex:mathjax\". Allowed values are:
845 nil Ignore math snippets.
846 `verbatim' Keep everything in verbatim
847 `mathjax', t Do MathJax preprocessing and arrange for MathJax.js to
848 be loaded.
849 SYMBOL Any symbol defined in `org-preview-latex-process-alist',
850 e.g., `dvipng'."
851 :group 'org-export-html
852 :version "24.4"
853 :package-version '(Org . "8.0")
854 :type '(choice
855 (const :tag "Do not process math in any way" nil)
856 (const :tag "Leave math verbatim" verbatim)
857 (const :tag "Use MathJax to display math" mathjax)
858 (symbol :tag "Convert to image to display math" :value dvipng)))
860 ;;;; Links :: Generic
862 (defcustom org-html-link-org-files-as-html t
863 "Non-nil means make file links to `file.org' point to `file.html'.
864 When `org-mode' is exporting an `org-mode' file to HTML, links to
865 non-html files are directly put into a href tag in HTML.
866 However, links to other Org files (recognized by the extension
867 \".org\") should become links to the corresponding HTML
868 file, assuming that the linked `org-mode' file will also be
869 converted to HTML.
870 When nil, the links still point to the plain \".org\" file."
871 :group 'org-export-html
872 :type 'boolean)
874 ;;;; Links :: Inline images
876 (defcustom org-html-inline-images t
877 "Non-nil means inline images into exported HTML pages.
878 This is done using an <img> tag. When nil, an anchor with href is used to
879 link to the image."
880 :group 'org-export-html
881 :version "24.4"
882 :package-version '(Org . "8.1")
883 :type 'boolean)
885 (defcustom org-html-inline-image-rules
886 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
887 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
888 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
889 "Rules characterizing image files that can be inlined into HTML.
890 A rule consists in an association whose key is the type of link
891 to consider, and value is a regexp that will be matched against
892 link's path."
893 :group 'org-export-html
894 :version "24.4"
895 :package-version '(Org . "8.0")
896 :type '(alist :key-type (string :tag "Type")
897 :value-type (regexp :tag "Path")))
899 ;;;; Plain Text
901 (defvar org-html-protect-char-alist
902 '(("&" . "&amp;")
903 ("<" . "&lt;")
904 (">" . "&gt;"))
905 "Alist of characters to be converted by `org-html-encode-plain-text'.")
907 ;;;; Src Block
909 (defcustom org-html-htmlize-output-type 'inline-css
910 "Output type to be used by htmlize when formatting code snippets.
911 Choices are `css' to export the CSS selectors only,`inline-css'
912 to export the CSS attribute values inline in the HTML or `nil' to
913 export plain text. We use as default `inline-css', in order to
914 make the resulting HTML self-containing.
916 However, this will fail when using Emacs in batch mode for export, because
917 then no rich font definitions are in place. It will also not be good if
918 people with different Emacs setup contribute HTML files to a website,
919 because the fonts will represent the individual setups. In these cases,
920 it is much better to let Org/Htmlize assign classes only, and to use
921 a style file to define the look of these classes.
922 To get a start for your css file, start Emacs session and make sure that
923 all the faces you are interested in are defined, for example by loading files
924 in all modes you want. Then, use the command
925 `\\[org-html-htmlize-generate-css]' to extract class definitions."
926 :group 'org-export-html
927 :type '(choice (const css) (const inline-css) (const nil)))
929 (defcustom org-html-htmlize-font-prefix "org-"
930 "The prefix for CSS class names for htmlize font specifications."
931 :group 'org-export-html
932 :type 'string)
934 ;;;; Table
936 (defcustom org-html-table-default-attributes
937 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
938 "Default attributes and values which will be used in table tags.
939 This is a plist where attributes are symbols, starting with
940 colons, and values are strings.
942 When exporting to HTML5, these values will be disregarded."
943 :group 'org-export-html
944 :version "24.4"
945 :package-version '(Org . "8.0")
946 :type '(plist :key-type (symbol :tag "Property")
947 :value-type (string :tag "Value")))
949 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
950 "The opening and ending tags for table header fields.
951 This is customizable so that alignment options can be specified.
952 The first %s will be filled with the scope of the field, either row or col.
953 The second %s will be replaced by a style entry to align the field.
954 See also the variable `org-html-table-use-header-tags-for-first-column'.
955 See also the variable `org-html-table-align-individual-fields'."
956 :group 'org-export-html
957 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
959 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
960 "The opening and ending tags for table data fields.
961 This is customizable so that alignment options can be specified.
962 The first %s will be filled with the scope of the field, either row or col.
963 The second %s will be replaced by a style entry to align the field.
964 See also the variable `org-html-table-align-individual-fields'."
965 :group 'org-export-html
966 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
968 (defcustom org-html-table-row-open-tag "<tr>"
969 "The opening tag for table rows.
970 This is customizable so that alignment options can be specified.
971 Instead of strings, these can be a Lisp function that will be
972 evaluated for each row in order to construct the table row tags.
974 The function will be called with these arguments:
976 `number': row number (0 is the first row)
977 `group-number': group number of current row
978 `start-group?': non-nil means the row starts a group
979 `end-group?': non-nil means the row ends a group
980 `top?': non-nil means this is the top row
981 `bottom?': non-nil means this is the bottom row
983 For example:
985 (setq org-html-table-row-open-tag
986 (lambda (number group-number start-group? end-group-p top? bottom?)
987 (cond (top? \"<tr class=\\\"tr-top\\\">\")
988 (bottom? \"<tr class=\\\"tr-bottom\\\">\")
989 (t (if (= (mod number 2) 1)
990 \"<tr class=\\\"tr-odd\\\">\"
991 \"<tr class=\\\"tr-even\\\">\")))))
993 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
994 and the bottom row, and otherwise alternate between \"tr-odd\" and
995 \"tr-even\" for odd and even rows."
996 :group 'org-export-html
997 :type '(choice :tag "Opening tag"
998 (string :tag "Specify")
999 (function)))
1001 (defcustom org-html-table-row-close-tag "</tr>"
1002 "The closing tag for table rows.
1003 This is customizable so that alignment options can be specified.
1004 Instead of strings, this can be a Lisp function that will be
1005 evaluated for each row in order to construct the table row tags.
1007 See documentation of `org-html-table-row-open-tag'."
1008 :group 'org-export-html
1009 :type '(choice :tag "Closing tag"
1010 (string :tag "Specify")
1011 (function)))
1013 (defcustom org-html-table-align-individual-fields t
1014 "Non-nil means attach style attributes for alignment to each table field.
1015 When nil, alignment will only be specified in the column tags, but this
1016 is ignored by some browsers (like Firefox, Safari). Opera does it right
1017 though."
1018 :group 'org-export-html
1019 :type 'boolean)
1021 (defcustom org-html-table-use-header-tags-for-first-column nil
1022 "Non-nil means format column one in tables with header tags.
1023 When nil, also column one will use data tags."
1024 :group 'org-export-html
1025 :type 'boolean)
1027 (defcustom org-html-table-caption-above t
1028 "When non-nil, place caption string at the beginning of the table.
1029 Otherwise, place it near the end."
1030 :group 'org-export-html
1031 :type 'boolean)
1033 ;;;; Tags
1035 (defcustom org-html-tag-class-prefix ""
1036 "Prefix to class names for TODO keywords.
1037 Each tag gets a class given by the tag itself, with this prefix.
1038 The default prefix is empty because it is nice to just use the keyword
1039 as a class name. But if you get into conflicts with other, existing
1040 CSS classes, then this prefix can be very useful."
1041 :group 'org-export-html
1042 :type 'string)
1044 ;;;; Template :: Generic
1046 (defcustom org-html-extension "html"
1047 "The extension for exported HTML files."
1048 :group 'org-export-html
1049 :type 'string)
1051 (defcustom org-html-xml-declaration
1052 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
1053 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
1054 "The extension for exported HTML files.
1055 %s will be replaced with the charset of the exported file.
1056 This may be a string, or an alist with export extensions
1057 and corresponding declarations.
1059 This declaration only applies when exporting to XHTML."
1060 :group 'org-export-html
1061 :type '(choice
1062 (string :tag "Single declaration")
1063 (repeat :tag "Dependent on extension"
1064 (cons (string :tag "Extension")
1065 (string :tag "Declaration")))))
1067 (defcustom org-html-coding-system 'utf-8
1068 "Coding system for HTML export.
1069 Use utf-8 as the default value."
1070 :group 'org-export-html
1071 :version "24.4"
1072 :package-version '(Org . "8.0")
1073 :type 'coding-system)
1075 (defcustom org-html-doctype "xhtml-strict"
1076 "Document type definition to use for exported HTML files.
1077 Can be set with the in-buffer HTML_DOCTYPE property or for
1078 publishing, with :html-doctype."
1079 :group 'org-export-html
1080 :version "24.4"
1081 :package-version '(Org . "8.0")
1082 :type (append
1083 '(choice)
1084 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
1085 '((string :tag "Custom doctype" ))))
1087 (defcustom org-html-html5-fancy nil
1088 "Non-nil means using new HTML5 elements.
1089 This variable is ignored for anything other than HTML5 export.
1091 For compatibility with Internet Explorer, it's probably a good
1092 idea to download some form of the html5shiv (for instance
1093 https://code.google.com/p/html5shiv/) and add it to your
1094 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
1095 versions 8 and below."
1096 :group 'org-export-html
1097 :version "24.4"
1098 :package-version '(Org . "8.0")
1099 :type 'boolean)
1101 (defcustom org-html-container-element "div"
1102 "HTML element to use for wrapping top level sections.
1103 Can be set with the in-buffer HTML_CONTAINER property or for
1104 publishing, with :html-container.
1106 Note that changing the default will prevent you from using
1107 org-info.js for your website."
1108 :group 'org-export-html
1109 :version "24.4"
1110 :package-version '(Org . "8.0")
1111 :type 'string)
1113 (defcustom org-html-divs
1114 '((preamble "div" "preamble")
1115 (content "div" "content")
1116 (postamble "div" "postamble"))
1117 "Alist of the three section elements for HTML export.
1118 The car of each entry is one of `preamble', `content' or `postamble'.
1119 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1120 section of the exported document.
1122 Note that changing the default will prevent you from using
1123 org-info.js for your website."
1124 :group 'org-export-html
1125 :version "24.4"
1126 :package-version '(Org . "8.0")
1127 :type '(list :greedy t
1128 (list :tag "Preamble"
1129 (const :format "" preamble)
1130 (string :tag "element") (string :tag " id"))
1131 (list :tag "Content"
1132 (const :format "" content)
1133 (string :tag "element") (string :tag " id"))
1134 (list :tag "Postamble" (const :format "" postamble)
1135 (string :tag " id") (string :tag "element"))))
1137 (defconst org-html-checkbox-types
1138 '((unicode .
1139 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1140 (ascii .
1141 ((on . "<code>[X]</code>")
1142 (off . "<code>[&#xa0;]</code>")
1143 (trans . "<code>[-]</code>")))
1144 (html .
1145 ((on . "<input type='checkbox' checked='checked' />")
1146 (off . "<input type='checkbox' />")
1147 (trans . "<input type='checkbox' />"))))
1148 "Alist of checkbox types.
1149 The cdr of each entry is an alist list three checkbox types for
1150 HTML export: `on', `off' and `trans'.
1152 The choices are:
1153 `unicode' Unicode characters (HTML entities)
1154 `ascii' ASCII characters
1155 `html' HTML checkboxes
1157 Note that only the ascii characters implement tri-state
1158 checkboxes. The other two use the `off' checkbox for `trans'.")
1160 (defcustom org-html-checkbox-type 'ascii
1161 "The type of checkboxes to use for HTML export.
1162 See `org-html-checkbox-types' for for the values used for each
1163 option."
1164 :group 'org-export-html
1165 :version "24.4"
1166 :package-version '(Org . "8.0")
1167 :type '(choice
1168 (const :tag "ASCII characters" ascii)
1169 (const :tag "Unicode characters" unicode)
1170 (const :tag "HTML checkboxes" html)))
1172 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1173 "Format used for timestamps in preamble, postamble and metadata.
1174 See `format-time-string' for more information on its components."
1175 :group 'org-export-html
1176 :version "24.4"
1177 :package-version '(Org . "8.0")
1178 :type 'string)
1180 ;;;; Template :: Mathjax
1182 (defcustom org-html-mathjax-options
1183 '((path "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML" )
1184 (scale "100")
1185 (align "center")
1186 (font "TeX")
1187 (linebreaks "false")
1188 (autonumber "AMS")
1189 (indent "0em")
1190 (multlinewidth "85%")
1191 (tagindent ".8em")
1192 (tagside "right"))
1193 "Options for MathJax setup.
1195 Alist of the following elements. All values are strings.
1197 path The path to MathJax.
1198 scale Scaling with HTML-CSS, MathML and SVG output engines.
1199 align How to align display math: left, center, or right.
1200 font The font to use with HTML-CSS and SVG output. As of MathJax 2.5
1201 the following values are understood: \"TeX\", \"STIX-Web\",
1202 \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\",
1203 \"Gyre-Termes\", and \"Latin-Modern\".
1204 linebreaks Let MathJax perform automatic linebreaks. Valid values
1205 are \"true\" and \"false\".
1206 indent If align is not center, how far from the left/right side?
1207 Valid values are \"left\" and \"right\"
1208 multlinewidth The width of the multline environment.
1209 autonumber How to number equations. Valid values are \"None\",
1210 \"all\" and \"AMS Math\".
1211 tagindent The amount tags are indented.
1212 tagside Which side to show tags/labels on. Valid values are
1213 \"left\" and \"right\"
1215 You can also customize this for each buffer, using something like
1217 #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler
1219 For further information about MathJax options, see the MathJax documentation:
1221 http://docs.mathjax.org/"
1222 :group 'org-export-html
1223 :package-version '(Org . "8.3")
1224 :type '(list :greedy t
1225 (list :tag "path (the path from where to load MathJax.js)"
1226 (const :format " " path) (string))
1227 (list :tag "scale (scaling for the displayed math)"
1228 (const :format " " scale) (string))
1229 (list :tag "align (alignment of displayed equations)"
1230 (const :format " " align) (string))
1231 (list :tag "font (used to display math)"
1232 (const :format " " font)
1233 (choice (const "TeX")
1234 (const "STIX-Web")
1235 (const "Asana-Math")
1236 (const "Neo-Euler")
1237 (const "Gyre-Pagella")
1238 (const "Gyre-Termes")
1239 (const "Latin-Modern")))
1240 (list :tag "linebreaks (automatic line-breaking)"
1241 (const :format " " linebreaks)
1242 (choice (const "true")
1243 (const "false")))
1244 (list :tag "autonumber (when should equations be numbered)"
1245 (const :format " " autonumber)
1246 (choice (const "AMS")
1247 (const "None")
1248 (const "All")))
1249 (list :tag "indent (indentation with left or right alignment)"
1250 (const :format " " indent) (string))
1251 (list :tag "multlinewidth (width to use for the multline environment)"
1252 (const :format " " multlinewidth) (string))
1253 (list :tag "tagindent (the indentation of tags from left or right)"
1254 (const :format " " tagindent) (string))
1255 (list :tag "tagside (location of tags)"
1256 (const :format " " tagside)
1257 (choice (const "left")
1258 (const "right")))))
1260 (defcustom org-html-mathjax-template
1261 "<script type=\"text/x-mathjax-config\">
1262 MathJax.Hub.Config({
1263 displayAlign: \"%ALIGN\",
1264 displayIndent: \"%INDENT\",
1266 \"HTML-CSS\": { scale: %SCALE,
1267 linebreaks: { automatic: \"%LINEBREAKS\" },
1268 webFont: \"%FONT\"
1270 SVG: {scale: %SCALE,
1271 linebreaks: { automatic: \"%LINEBREAKS\" },
1272 font: \"%FONT\"},
1273 NativeMML: {scale: %SCALE},
1274 TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
1275 MultLineWidth: \"%MULTLINEWIDTH\",
1276 TagSide: \"%TAGSIDE\",
1277 TagIndent: \"%TAGINDENT\"
1280 </script>
1281 <script type=\"text/javascript\"
1282 src=\"%PATH\"></script>"
1283 "The MathJax template. See also `org-html-mathjax-options'."
1284 :group 'org-export-html
1285 :type 'string)
1287 ;;;; Template :: Postamble
1289 (defcustom org-html-postamble 'auto
1290 "Non-nil means insert a postamble in HTML export.
1292 When set to `auto', check against the
1293 `org-export-with-author/email/creator/date' variables to set the
1294 content of the postamble. When set to a string, use this string
1295 as the postamble. When t, insert a string as defined by the
1296 formatting string in `org-html-postamble-format'.
1298 When set to a function, apply this function and insert the
1299 returned string. The function takes the property list of export
1300 options as its only argument.
1302 Setting :html-postamble in publishing projects will take
1303 precedence over this variable."
1304 :group 'org-export-html
1305 :type '(choice (const :tag "No postamble" nil)
1306 (const :tag "Auto postamble" auto)
1307 (const :tag "Default formatting string" t)
1308 (string :tag "Custom formatting string")
1309 (function :tag "Function (must return a string)")))
1311 (defcustom org-html-postamble-format
1312 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1313 <p class=\"date\">Date: %d</p>
1314 <p class=\"creator\">%c</p>
1315 <p class=\"validation\">%v</p>"))
1316 "Alist of languages and format strings for the HTML postamble.
1318 The first element of each list is the language code, as used for
1319 the LANGUAGE keyword. See `org-export-default-language'.
1321 The second element of each list is a format string to format the
1322 postamble itself. This format string can contain these elements:
1324 %t stands for the title.
1325 %s stands for the subtitle.
1326 %a stands for the author's name.
1327 %e stands for the author's email.
1328 %d stands for the date.
1329 %c will be replaced by `org-html-creator-string'.
1330 %v will be replaced by `org-html-validation-link'.
1331 %T will be replaced by the export time.
1332 %C will be replaced by the last modification time.
1334 If you need to use a \"%\" character, you need to escape it
1335 like that: \"%%\"."
1336 :group 'org-export-html
1337 :type '(repeat
1338 (list (string :tag "Language")
1339 (string :tag "Format string"))))
1341 (defcustom org-html-validation-link
1342 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1343 "Link to HTML validation service."
1344 :group 'org-export-html
1345 :type 'string)
1347 (defcustom org-html-creator-string
1348 (format "<a href=\"https://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"https://orgmode.org\">Org</a> mode %s)"
1349 emacs-version
1350 (if (fboundp 'org-version) (org-version) "unknown version"))
1351 "Information about the creator of the HTML document.
1352 This option can also be set on with the CREATOR keyword."
1353 :group 'org-export-html
1354 :version "24.4"
1355 :package-version '(Org . "8.0")
1356 :type '(string :tag "Creator string"))
1358 ;;;; Template :: Preamble
1360 (defcustom org-html-preamble t
1361 "Non-nil means insert a preamble in HTML export.
1363 When t, insert a string as defined by the formatting string in
1364 `org-html-preamble-format'. When set to a string, use this
1365 formatting string instead (see `org-html-postamble-format' for an
1366 example of such a formatting string).
1368 When set to a function, apply this function and insert the
1369 returned string. The function takes the property list of export
1370 options as its only argument.
1372 Setting :html-preamble in publishing projects will take
1373 precedence over this variable."
1374 :group 'org-export-html
1375 :type '(choice (const :tag "No preamble" nil)
1376 (const :tag "Default preamble" t)
1377 (string :tag "Custom formatting string")
1378 (function :tag "Function (must return a string)")))
1380 (defcustom org-html-preamble-format '(("en" ""))
1381 "Alist of languages and format strings for the HTML preamble.
1383 The first element of each list is the language code, as used for
1384 the LANGUAGE keyword. See `org-export-default-language'.
1386 The second element of each list is a format string to format the
1387 preamble itself. This format string can contain these elements:
1389 %t stands for the title.
1390 %s stands for the subtitle.
1391 %a stands for the author's name.
1392 %e stands for the author's email.
1393 %d stands for the date.
1394 %c will be replaced by `org-html-creator-string'.
1395 %v will be replaced by `org-html-validation-link'.
1396 %T will be replaced by the export time.
1397 %C will be replaced by the last modification time.
1399 If you need to use a \"%\" character, you need to escape it
1400 like that: \"%%\".
1402 See the default value of `org-html-postamble-format' for an
1403 example."
1404 :group 'org-export-html
1405 :type '(repeat
1406 (list (string :tag "Language")
1407 (string :tag "Format string"))))
1409 (defcustom org-html-link-up ""
1410 "Where should the \"UP\" link of exported HTML pages lead?"
1411 :group 'org-export-html
1412 :type '(string :tag "File or URL"))
1414 (defcustom org-html-link-home ""
1415 "Where should the \"HOME\" link of exported HTML pages lead?"
1416 :group 'org-export-html
1417 :type '(string :tag "File or URL"))
1419 (defcustom org-html-link-use-abs-url nil
1420 "Should we prepend relative links with HTML_LINK_HOME?"
1421 :group 'org-export-html
1422 :version "24.4"
1423 :package-version '(Org . "8.1")
1424 :type 'boolean)
1426 (defcustom org-html-home/up-format
1427 "<div id=\"org-div-home-and-up\">
1428 <a accesskey=\"h\" href=\"%s\"> UP </a>
1430 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1431 </div>"
1432 "Snippet used to insert the HOME and UP links.
1433 This is a format string, the first %s will receive the UP link,
1434 the second the HOME link. If both `org-html-link-up' and
1435 `org-html-link-home' are empty, the entire snippet will be
1436 ignored."
1437 :group 'org-export-html
1438 :type 'string)
1440 ;;;; Template :: Scripts
1442 (defcustom org-html-head-include-scripts t
1443 "Non-nil means include the JavaScript snippets in exported HTML files.
1444 The actual script is defined in `org-html-scripts' and should
1445 not be modified."
1446 :group 'org-export-html
1447 :version "24.4"
1448 :package-version '(Org . "8.0")
1449 :type 'boolean)
1451 ;;;; Template :: Styles
1453 (defcustom org-html-head-include-default-style t
1454 "Non-nil means include the default style in exported HTML files.
1455 The actual style is defined in `org-html-style-default' and
1456 should not be modified. Use `org-html-head' to use your own
1457 style information."
1458 :group 'org-export-html
1459 :version "24.4"
1460 :package-version '(Org . "8.0")
1461 :type 'boolean)
1462 ;;;###autoload
1463 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1465 (defcustom org-html-head ""
1466 "Org-wide head definitions for exported HTML files.
1468 This variable can contain the full HTML structure to provide a
1469 style, including the surrounding HTML tags. You can consider
1470 including definitions for the following classes: title, todo,
1471 done, timestamp, timestamp-kwd, tag, target.
1473 For example, a valid value would be:
1475 <style type=\"text/css\">
1476 /*<![CDATA[*/
1477 p { font-weight: normal; color: gray; }
1478 h1 { color: black; }
1479 .title { text-align: center; }
1480 .todo, .timestamp-kwd { color: red; }
1481 .done { color: green; }
1482 /*]]>*/
1483 </style>
1485 If you want to refer to an external style, use something like
1487 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1489 As the value of this option simply gets inserted into the HTML
1490 <head> header, you can use it to add any arbitrary text to the
1491 header.
1493 You can set this on a per-file basis using #+HTML_HEAD:,
1494 or for publication projects using the :html-head property."
1495 :group 'org-export-html
1496 :version "24.4"
1497 :package-version '(Org . "8.0")
1498 :type 'string)
1499 ;;;###autoload
1500 (put 'org-html-head 'safe-local-variable 'stringp)
1502 (defcustom org-html-head-extra ""
1503 "More head information to add in the HTML output.
1505 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1506 or for publication projects using the :html-head-extra property."
1507 :group 'org-export-html
1508 :version "24.4"
1509 :package-version '(Org . "8.0")
1510 :type 'string)
1511 ;;;###autoload
1512 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1514 ;;;; Template :: Viewport
1516 (defcustom org-html-viewport '((width "device-width")
1517 (initial-scale "1")
1518 (minimum-scale "")
1519 (maximum-scale "")
1520 (user-scalable ""))
1521 "Viewport options for mobile-optimized sites.
1523 The following values are recognized
1525 width Size of the viewport.
1526 initial-scale Zoom level when the page is first loaded.
1527 minimum-scale Minimum allowed zoom level.
1528 maximum-scale Maximum allowed zoom level.
1529 user-scalable Whether zoom can be changed.
1531 The viewport meta tag is inserted if this variable is non-nil.
1533 See the following site for a reference:
1534 https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag"
1535 :group 'org-export-html
1536 :version "26.1"
1537 :package-version '(Org . "8.3")
1538 :type '(choice (const :tag "Disable" nil)
1539 (list :tag "Enable"
1540 (list :tag "Width of viewport"
1541 (const :format " " width)
1542 (choice (const :tag "unset" "")
1543 (string)))
1544 (list :tag "Initial scale"
1545 (const :format " " initial-scale)
1546 (choice (const :tag "unset" "")
1547 (string)))
1548 (list :tag "Minimum scale/zoom"
1549 (const :format " " minimum-scale)
1550 (choice (const :tag "unset" "")
1551 (string)))
1552 (list :tag "Maximum scale/zoom"
1553 (const :format " " maximum-scale)
1554 (choice (const :tag "unset" "")
1555 (string)))
1556 (list :tag "User scalable/zoomable"
1557 (const :format " " user-scalable)
1558 (choice (const :tag "unset" "")
1559 (const "true")
1560 (const "false"))))))
1562 ;; Handle source code blocks with Klipse
1564 (defcustom org-html-klipsify-src nil
1565 "When non-nil, source code blocks are editable in exported presentation."
1566 :group 'org-export-html
1567 :package-version '(Org . "9.1")
1568 :type 'boolean)
1570 (defcustom org-html-klipse-css
1571 "https://storage.googleapis.com/app.klipse.tech/css/codemirror.css"
1572 "Location of the codemirror CSS file for use with klipse."
1573 :group 'org-export-html
1574 :package-version '(Org . "9.1")
1575 :type 'string)
1577 (defcustom org-html-klipse-js
1578 "https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"
1579 "Location of the klipse javascript file."
1580 :group 'org-export-html
1581 :type 'string)
1583 (defcustom org-html-klipse-selection-script
1584 "window.klipse_settings = {selector_eval_html: '.src-html',
1585 selector_eval_js: '.src-js',
1586 selector_eval_python_client: '.src-python',
1587 selector_eval_scheme: '.src-scheme',
1588 selector: '.src-clojure',
1589 selector_eval_ruby: '.src-ruby'};"
1590 "Javascript snippet to activate klipse."
1591 :group 'org-export-html
1592 :package-version '(Org . "9.1")
1593 :type 'string)
1596 ;;;; Todos
1598 (defcustom org-html-todo-kwd-class-prefix ""
1599 "Prefix to class names for TODO keywords.
1600 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1601 The default prefix is empty because it is nice to just use the keyword
1602 as a class name. But if you get into conflicts with other, existing
1603 CSS classes, then this prefix can be very useful."
1604 :group 'org-export-html
1605 :type 'string)
1608 ;;; Internal Functions
1610 (defun org-html-xhtml-p (info)
1611 (let ((dt (downcase (plist-get info :html-doctype))))
1612 (string-match-p "xhtml" dt)))
1614 (defun org-html-html5-p (info)
1615 (let ((dt (downcase (plist-get info :html-doctype))))
1616 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1618 (defun org-html--html5-fancy-p (info)
1619 "Non-nil when exporting to HTML5 with fancy elements.
1620 INFO is the current state of the export process, as a plist."
1621 (and (plist-get info :html-html5-fancy)
1622 (org-html-html5-p info)))
1624 (defun org-html-close-tag (tag attr info)
1625 "Return close-tag for string TAG.
1626 ATTR specifies additional attributes. INFO is a property list
1627 containing current export state."
1628 (concat "<" tag
1629 (org-string-nw-p (concat " " attr))
1630 (if (org-html-xhtml-p info) " />" ">")))
1632 (defun org-html-doctype (info)
1633 "Return correct HTML doctype tag.
1634 INFO is a plist used as a communication channel. Doctype tag is
1635 extracted from `org-html-doctype-alist', or the literal value
1636 of :html-doctype from INFO if :html-doctype is not found in the
1637 alist."
1638 (let ((dt (plist-get info :html-doctype)))
1639 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1641 (defun org-html--make-attribute-string (attributes)
1642 "Return a list of attributes, as a string.
1643 ATTRIBUTES is a plist where values are either strings or nil. An
1644 attribute with a nil value will be omitted from the result."
1645 (let (output)
1646 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1647 (cond ((null item) (pop output))
1648 ((symbolp item) (push (substring (symbol-name item) 1) output))
1649 (t (let ((key (car output))
1650 (value (replace-regexp-in-string
1651 "\"" "&quot;" (org-html-encode-plain-text item))))
1652 (setcar output (format "%s=\"%s\"" key value))))))))
1654 (defun org-html--wrap-image (contents info &optional caption label)
1655 "Wrap CONTENTS string within an appropriate environment for images.
1656 INFO is a plist used as a communication channel. When optional
1657 arguments CAPTION and LABEL are given, use them for caption and
1658 \"id\" attribute."
1659 (let ((html5-fancy (org-html--html5-fancy-p info)))
1660 (format (if html5-fancy "\n<figure%s>\n%s%s\n</figure>"
1661 "\n<div%s class=\"figure\">\n%s%s\n</div>")
1662 ;; ID.
1663 (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
1664 ;; Contents.
1665 (if html5-fancy contents (format "<p>%s</p>" contents))
1666 ;; Caption.
1667 (if (not (org-string-nw-p caption)) ""
1668 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1669 "\n<p>%s</p>")
1670 caption)))))
1672 (defun org-html--format-image (source attributes info)
1673 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1674 SOURCE is a string specifying the location of the image.
1675 ATTRIBUTES is a plist, as returned by
1676 `org-export-read-attribute'. INFO is a plist used as
1677 a communication channel."
1678 (if (string= "svg" (file-name-extension source))
1679 (org-html--svg-image source attributes info)
1680 (org-html-close-tag
1681 "img"
1682 (org-html--make-attribute-string
1683 (org-combine-plists
1684 (list :src source
1685 :alt (if (string-match-p "^ltxpng/" source)
1686 (org-html-encode-plain-text
1687 (org-find-text-property-in-string 'org-latex-src source))
1688 (file-name-nondirectory source)))
1689 attributes))
1690 info)))
1692 (defun org-html--svg-image (source attributes info)
1693 "Return \"object\" embedding svg file SOURCE with given ATTRIBUTES.
1694 INFO is a plist used as a communication channel.
1696 The special attribute \"fallback\" can be used to specify a
1697 fallback image file to use if the object embedding is not
1698 supported. CSS class \"org-svg\" is assigned as the class of the
1699 object unless a different class is specified with an attribute."
1700 (let ((fallback (plist-get attributes :fallback))
1701 (attrs (org-html--make-attribute-string
1702 (org-combine-plists
1703 ;; Remove fallback attribute, which is not meant to
1704 ;; appear directly in the attributes string, and
1705 ;; provide a default class if none is set.
1706 '(:class "org-svg") attributes '(:fallback nil)))))
1707 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1708 source
1709 attrs
1710 (if fallback
1711 (org-html-close-tag
1712 "img" (format "src=\"%s\" %s" fallback attrs) info)
1713 "Sorry, your browser does not support SVG."))))
1715 (defun org-html--textarea-block (element)
1716 "Transcode ELEMENT into a textarea block.
1717 ELEMENT is either a source or an example block."
1718 (let* ((code (car (org-export-unravel-code element)))
1719 (attr (org-export-read-attribute :attr_html element)))
1720 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1721 (or (plist-get attr :width) 80)
1722 (or (plist-get attr :height) (org-count-lines code))
1723 code)))
1725 (defun org-html--has-caption-p (element &optional _info)
1726 "Non-nil when ELEMENT has a caption affiliated keyword.
1727 INFO is a plist used as a communication channel. This function
1728 is meant to be used as a predicate for `org-export-get-ordinal' or
1729 a value to `org-html-standalone-image-predicate'."
1730 (org-element-property :caption element))
1732 ;;;; Table
1734 (defun org-html-htmlize-region-for-paste (beg end)
1735 "Convert the region between BEG and END to HTML, using htmlize.el.
1736 This is much like `htmlize-region-for-paste', only that it uses
1737 the settings define in the org-... variables."
1738 (let* ((htmlize-output-type org-html-htmlize-output-type)
1739 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1740 (htmlbuf (htmlize-region beg end)))
1741 (unwind-protect
1742 (with-current-buffer htmlbuf
1743 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1744 (plist-get htmlize-buffer-places 'content-end)))
1745 (kill-buffer htmlbuf))))
1747 ;;;###autoload
1748 (defun org-html-htmlize-generate-css ()
1749 "Create the CSS for all font definitions in the current Emacs session.
1750 Use this to create face definitions in your CSS style file that can then
1751 be used by code snippets transformed by htmlize.
1752 This command just produces a buffer that contains class definitions for all
1753 faces used in the current Emacs session. You can copy and paste the ones you
1754 need into your CSS file.
1756 If you then set `org-html-htmlize-output-type' to `css', calls
1757 to the function `org-html-htmlize-region-for-paste' will
1758 produce code that uses these same face definitions."
1759 (interactive)
1760 (unless (require 'htmlize nil t)
1761 (error "htmlize library missing. Aborting"))
1762 (and (get-buffer "*html*") (kill-buffer "*html*"))
1763 (with-temp-buffer
1764 (let ((fl (face-list))
1765 (htmlize-css-name-prefix "org-")
1766 (htmlize-output-type 'css)
1767 f i)
1768 (while (setq f (pop fl)
1769 i (and f (face-attribute f :inherit)))
1770 (when (and (symbolp f) (or (not i) (not (listp i))))
1771 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1772 (htmlize-region (point-min) (point-max))))
1773 (pop-to-buffer-same-window "*html*")
1774 (goto-char (point-min))
1775 (when (re-search-forward "<style" nil t)
1776 (delete-region (point-min) (match-beginning 0)))
1777 (when (re-search-forward "</style>" nil t)
1778 (delete-region (1+ (match-end 0)) (point-max)))
1779 (beginning-of-line 1)
1780 (when (looking-at " +") (replace-match ""))
1781 (goto-char (point-min)))
1783 (defun org-html--make-string (n string)
1784 "Build a string by concatenating N times STRING."
1785 (let (out) (dotimes (_ n out) (setq out (concat string out)))))
1787 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1788 "Turn todo keyword KWD into a valid class name.
1789 Replaces invalid characters with \"_\"."
1790 (replace-regexp-in-string "[^a-zA-Z0-9_]" "_" kwd nil t))
1792 (defun org-html-footnote-section (info)
1793 "Format the footnote section.
1794 INFO is a plist used as a communication channel."
1795 (pcase (org-export-collect-footnote-definitions info)
1796 (`nil nil)
1797 (definitions
1798 (format
1799 (plist-get info :html-footnotes-section)
1800 (org-html--translate "Footnotes" info)
1801 (format
1802 "\n%s\n"
1803 (mapconcat
1804 (lambda (definition)
1805 (pcase definition
1806 (`(,n ,_ ,def)
1807 ;; `org-export-collect-footnote-definitions' can return
1808 ;; two kinds of footnote definitions: inline and blocks.
1809 ;; Since this should not make any difference in the HTML
1810 ;; output, we wrap the inline definitions within
1811 ;; a "footpara" class paragraph.
1812 (let ((inline? (not (org-element-map def org-element-all-elements
1813 #'identity nil t)))
1814 (anchor (org-html--anchor
1815 (format "fn.%d" n)
1817 (format " class=\"footnum\" href=\"#fnr.%d\"" n)
1818 info))
1819 (contents (org-trim (org-export-data def info))))
1820 (format "<div class=\"footdef\">%s %s</div>\n"
1821 (format (plist-get info :html-footnote-format) anchor)
1822 (format "<div class=\"footpara\">%s</div>"
1823 (if (not inline?) contents
1824 (format "<p class=\"footpara\">%s</p>"
1825 contents))))))))
1826 definitions
1827 "\n"))))))
1830 ;;; Template
1832 (defun org-html--build-meta-info (info)
1833 "Return meta tags for exported document.
1834 INFO is a plist used as a communication channel."
1835 (let* ((protect-string
1836 (lambda (str)
1837 (replace-regexp-in-string
1838 "\"" "&quot;" (org-html-encode-plain-text str))))
1839 (title (org-export-data (plist-get info :title) info))
1840 ;; Set title to an invisible character instead of leaving it
1841 ;; empty, which is invalid.
1842 (title (if (org-string-nw-p title) title "&lrm;"))
1843 (author (and (plist-get info :with-author)
1844 (let ((auth (plist-get info :author)))
1845 (and auth
1846 ;; Return raw Org syntax, skipping non
1847 ;; exportable objects.
1848 (org-element-interpret-data
1849 (org-element-map auth
1850 (cons 'plain-text org-element-all-objects)
1851 'identity info))))))
1852 (description (plist-get info :description))
1853 (keywords (plist-get info :keywords))
1854 (charset (or (and org-html-coding-system
1855 (fboundp 'coding-system-get)
1856 (coding-system-get org-html-coding-system
1857 'mime-charset))
1858 "iso-8859-1")))
1859 (concat
1860 (when (plist-get info :time-stamp-file)
1861 (format-time-string
1862 (concat "<!-- "
1863 (plist-get info :html-metadata-timestamp-format)
1864 " -->\n")))
1865 (format
1866 (if (org-html-html5-p info)
1867 (org-html-close-tag "meta" "charset=\"%s\"" info)
1868 (org-html-close-tag
1869 "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1870 info))
1871 charset) "\n"
1872 (let ((viewport-options
1873 (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell)))
1874 (plist-get info :html-viewport))))
1875 (and viewport-options
1876 (concat
1877 (org-html-close-tag
1878 "meta"
1879 (format "name=\"viewport\" content=\"%s\""
1880 (mapconcat
1881 (lambda (elm) (format "%s=%s" (car elm) (cadr elm)))
1882 viewport-options ", "))
1883 info)
1884 "\n")))
1885 (format "<title>%s</title>\n" title)
1886 (org-html-close-tag "meta" "name=\"generator\" content=\"Org mode\"" info)
1887 "\n"
1888 (and (org-string-nw-p author)
1889 (concat
1890 (org-html-close-tag "meta"
1891 (format "name=\"author\" content=\"%s\""
1892 (funcall protect-string author))
1893 info)
1894 "\n"))
1895 (and (org-string-nw-p description)
1896 (concat
1897 (org-html-close-tag "meta"
1898 (format "name=\"description\" content=\"%s\"\n"
1899 (funcall protect-string description))
1900 info)
1901 "\n"))
1902 (and (org-string-nw-p keywords)
1903 (concat
1904 (org-html-close-tag "meta"
1905 (format "name=\"keywords\" content=\"%s\""
1906 (funcall protect-string keywords))
1907 info)
1908 "\n")))))
1910 (defun org-html--build-head (info)
1911 "Return information for the <head>..</head> of the HTML output.
1912 INFO is a plist used as a communication channel."
1913 (org-element-normalize-string
1914 (concat
1915 (when (plist-get info :html-head-include-default-style)
1916 (org-element-normalize-string org-html-style-default))
1917 (org-element-normalize-string (plist-get info :html-head))
1918 (org-element-normalize-string (plist-get info :html-head-extra))
1919 (when (and (plist-get info :html-htmlized-css-url)
1920 (eq org-html-htmlize-output-type 'css))
1921 (org-html-close-tag "link"
1922 (format "rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1923 (plist-get info :html-htmlized-css-url))
1924 info))
1925 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1927 (defun org-html--build-mathjax-config (info)
1928 "Insert the user setup into the mathjax template.
1929 INFO is a plist used as a communication channel."
1930 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1931 (org-element-map (plist-get info :parse-tree)
1932 '(latex-fragment latex-environment) #'identity info t nil t))
1933 (let ((template (plist-get info :html-mathjax-template))
1934 (options (plist-get info :html-mathjax-options))
1935 (in-buffer (or (plist-get info :html-mathjax) "")))
1936 (dolist (e options (org-element-normalize-string template))
1937 (let ((name (car e))
1938 (val (nth 1 e)))
1939 (when (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1940 (setq val
1941 (car (read-from-string (substring in-buffer (match-end 0))))))
1942 (unless (stringp val) (setq val (format "%s" val)))
1943 (while (string-match (concat "%" (upcase (symbol-name name)))
1944 template)
1945 (setq template (replace-match val t t template))))))))
1947 (defun org-html-format-spec (info)
1948 "Return format specification for preamble and postamble.
1949 INFO is a plist used as a communication channel."
1950 (let ((timestamp-format (plist-get info :html-metadata-timestamp-format)))
1951 `((?t . ,(org-export-data (plist-get info :title) info))
1952 (?s . ,(org-export-data (plist-get info :subtitle) info))
1953 (?d . ,(org-export-data (org-export-get-date info timestamp-format)
1954 info))
1955 (?T . ,(format-time-string timestamp-format))
1956 (?a . ,(org-export-data (plist-get info :author) info))
1957 (?e . ,(mapconcat
1958 (lambda (e) (format "<a href=\"mailto:%s\">%s</a>" e e))
1959 (split-string (plist-get info :email) ",+ *")
1960 ", "))
1961 (?c . ,(plist-get info :creator))
1962 (?C . ,(let ((file (plist-get info :input-file)))
1963 (format-time-string timestamp-format
1964 (and file (file-attribute-modification-time
1965 (file-attributes file))))))
1966 (?v . ,(or (plist-get info :html-validation-link) "")))))
1968 (defun org-html--build-pre/postamble (type info)
1969 "Return document preamble or postamble as a string, or nil.
1970 TYPE is either `preamble' or `postamble', INFO is a plist used as a
1971 communication channel."
1972 (let ((section (plist-get info (intern (format ":html-%s" type))))
1973 (spec (org-html-format-spec info)))
1974 (when section
1975 (let ((section-contents
1976 (if (functionp section) (funcall section info)
1977 (cond
1978 ((stringp section) (format-spec section spec))
1979 ((eq section 'auto)
1980 (let ((date (cdr (assq ?d spec)))
1981 (author (cdr (assq ?a spec)))
1982 (email (cdr (assq ?e spec)))
1983 (creator (cdr (assq ?c spec)))
1984 (validation-link (cdr (assq ?v spec))))
1985 (concat
1986 (and (plist-get info :with-date)
1987 (org-string-nw-p date)
1988 (format "<p class=\"date\">%s: %s</p>\n"
1989 (org-html--translate "Date" info)
1990 date))
1991 (and (plist-get info :with-author)
1992 (org-string-nw-p author)
1993 (format "<p class=\"author\">%s: %s</p>\n"
1994 (org-html--translate "Author" info)
1995 author))
1996 (and (plist-get info :with-email)
1997 (org-string-nw-p email)
1998 (format "<p class=\"email\">%s: %s</p>\n"
1999 (org-html--translate "Email" info)
2000 email))
2001 (and (plist-get info :time-stamp-file)
2002 (format
2003 "<p class=\"date\">%s: %s</p>\n"
2004 (org-html--translate "Created" info)
2005 (format-time-string
2006 (plist-get info :html-metadata-timestamp-format))))
2007 (and (plist-get info :with-creator)
2008 (org-string-nw-p creator)
2009 (format "<p class=\"creator\">%s</p>\n" creator))
2010 (and (org-string-nw-p validation-link)
2011 (format "<p class=\"validation\">%s</p>\n"
2012 validation-link)))))
2014 (let ((formats (plist-get info (if (eq type 'preamble)
2015 :html-preamble-format
2016 :html-postamble-format)))
2017 (language (plist-get info :language)))
2018 (format-spec
2019 (cadr (or (assoc-string language formats t)
2020 (assoc-string "en" formats t)))
2021 spec)))))))
2022 (let ((div (assq type (plist-get info :html-divs))))
2023 (when (org-string-nw-p section-contents)
2024 (concat
2025 (format "<%s id=\"%s\" class=\"%s\">\n"
2026 (nth 1 div)
2027 (nth 2 div)
2028 org-html--pre/postamble-class)
2029 (org-element-normalize-string section-contents)
2030 (format "</%s>\n" (nth 1 div)))))))))
2032 (defun org-html-inner-template (contents info)
2033 "Return body of document string after HTML conversion.
2034 CONTENTS is the transcoded contents string. INFO is a plist
2035 holding export options."
2036 (concat
2037 ;; Table of contents.
2038 (let ((depth (plist-get info :with-toc)))
2039 (when depth (org-html-toc depth info)))
2040 ;; Document contents.
2041 contents
2042 ;; Footnotes section.
2043 (org-html-footnote-section info)))
2045 (defun org-html-template (contents info)
2046 "Return complete document string after HTML conversion.
2047 CONTENTS is the transcoded contents string. INFO is a plist
2048 holding export options."
2049 (concat
2050 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
2051 (let* ((xml-declaration (plist-get info :html-xml-declaration))
2052 (decl (or (and (stringp xml-declaration) xml-declaration)
2053 (cdr (assoc (plist-get info :html-extension)
2054 xml-declaration))
2055 (cdr (assoc "html" xml-declaration))
2056 "")))
2057 (when (not (or (not decl) (string= "" decl)))
2058 (format "%s\n"
2059 (format decl
2060 (or (and org-html-coding-system
2061 (fboundp 'coding-system-get)
2062 (coding-system-get org-html-coding-system 'mime-charset))
2063 "iso-8859-1"))))))
2064 (org-html-doctype info)
2065 "\n"
2066 (concat "<html"
2067 (cond ((org-html-xhtml-p info)
2068 (format
2069 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
2070 (plist-get info :language) (plist-get info :language)))
2071 ((org-html-html5-p info)
2072 (format " lang=\"%s\"" (plist-get info :language))))
2073 ">\n")
2074 "<head>\n"
2075 (org-html--build-meta-info info)
2076 (org-html--build-head info)
2077 (org-html--build-mathjax-config info)
2078 "</head>\n"
2079 "<body>\n"
2080 (let ((link-up (org-trim (plist-get info :html-link-up)))
2081 (link-home (org-trim (plist-get info :html-link-home))))
2082 (unless (and (string= link-up "") (string= link-home ""))
2083 (format (plist-get info :html-home/up-format)
2084 (or link-up link-home)
2085 (or link-home link-up))))
2086 ;; Preamble.
2087 (org-html--build-pre/postamble 'preamble info)
2088 ;; Document contents.
2089 (let ((div (assq 'content (plist-get info :html-divs))))
2090 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
2091 ;; Document title.
2092 (when (plist-get info :with-title)
2093 (let ((title (and (plist-get info :with-title)
2094 (plist-get info :title)))
2095 (subtitle (plist-get info :subtitle))
2096 (html5-fancy (org-html--html5-fancy-p info)))
2097 (when title
2098 (format
2099 (if html5-fancy
2100 "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
2101 "<h1 class=\"title\">%s%s</h1>\n")
2102 (org-export-data title info)
2103 (if subtitle
2104 (format
2105 (if html5-fancy
2106 "<p class=\"subtitle\">%s</p>\n"
2107 (concat "\n" (org-html-close-tag "br" nil info) "\n"
2108 "<span class=\"subtitle\">%s</span>\n"))
2109 (org-export-data subtitle info))
2110 "")))))
2111 contents
2112 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
2113 ;; Postamble.
2114 (org-html--build-pre/postamble 'postamble info)
2115 ;; Possibly use the Klipse library live code blocks.
2116 (when (plist-get info :html-klipsify-src)
2117 (concat "<script>" (plist-get info :html-klipse-selection-script)
2118 "</script><script src=\""
2119 org-html-klipse-js
2120 "\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
2121 org-html-klipse-css "\"/>"))
2122 ;; Closing document.
2123 "</body>\n</html>"))
2125 (defun org-html--translate (s info)
2126 "Translate string S according to specified language.
2127 INFO is a plist used as a communication channel."
2128 (org-export-translate s :html info))
2130 ;;;; Anchor
2132 (defun org-html--anchor (id desc attributes info)
2133 "Format a HTML anchor."
2134 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
2135 (attributes (concat (and id (format " id=\"%s\"" id))
2136 (and name (format " name=\"%s\"" name))
2137 attributes)))
2138 (format "<a%s>%s</a>" attributes (or desc ""))))
2140 ;;;; Todo
2142 (defun org-html--todo (todo info)
2143 "Format TODO keywords into HTML."
2144 (when todo
2145 (format "<span class=\"%s %s%s\">%s</span>"
2146 (if (member todo org-done-keywords) "done" "todo")
2147 (or (plist-get info :html-todo-kwd-class-prefix) "")
2148 (org-html-fix-class-name todo)
2149 todo)))
2151 ;;;; Priority
2153 (defun org-html--priority (priority _info)
2154 "Format a priority into HTML.
2155 PRIORITY is the character code of the priority or nil. INFO is
2156 a plist containing export options."
2157 (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
2159 ;;;; Tags
2161 (defun org-html--tags (tags info)
2162 "Format TAGS into HTML.
2163 INFO is a plist containing export options."
2164 (when tags
2165 (format "<span class=\"tag\">%s</span>"
2166 (mapconcat
2167 (lambda (tag)
2168 (format "<span class=\"%s\">%s</span>"
2169 (concat (plist-get info :html-tag-class-prefix)
2170 (org-html-fix-class-name tag))
2171 tag))
2172 tags "&#xa0;"))))
2174 ;;;; Src Code
2176 (defun org-html-fontify-code (code lang)
2177 "Color CODE with htmlize library.
2178 CODE is a string representing the source code to colorize. LANG
2179 is the language used for CODE, as a string, or nil."
2180 (when code
2181 (cond
2182 ;; No language. Possibly an example block.
2183 ((not lang) (org-html-encode-plain-text code))
2184 ;; Plain text explicitly set.
2185 ((not org-html-htmlize-output-type) (org-html-encode-plain-text code))
2186 ;; No htmlize library or an inferior version of htmlize.
2187 ((not (progn (require 'htmlize nil t)
2188 (fboundp 'htmlize-region-for-paste)))
2189 ;; Emit a warning.
2190 (message "Cannot fontify source block (htmlize.el >= 1.34 required)")
2191 (org-html-encode-plain-text code))
2193 ;; Map language
2194 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
2195 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
2196 (cond
2197 ;; Case 1: Language is not associated with any Emacs mode
2198 ((not (functionp lang-mode))
2199 (org-html-encode-plain-text code))
2200 ;; Case 2: Default. Fontify code.
2202 ;; htmlize
2203 (setq code
2204 (let ((output-type org-html-htmlize-output-type)
2205 (font-prefix org-html-htmlize-font-prefix))
2206 (with-temp-buffer
2207 ;; Switch to language-specific mode.
2208 (funcall lang-mode)
2209 (insert code)
2210 ;; Fontify buffer.
2211 (org-font-lock-ensure)
2212 ;; Remove formatting on newline characters.
2213 (save-excursion
2214 (let ((beg (point-min))
2215 (end (point-max)))
2216 (goto-char beg)
2217 (while (progn (end-of-line) (< (point) end))
2218 (put-text-property (point) (1+ (point)) 'face nil)
2219 (forward-char 1))))
2220 (org-src-mode)
2221 (set-buffer-modified-p nil)
2222 ;; Htmlize region.
2223 (let ((org-html-htmlize-output-type output-type)
2224 (org-html-htmlize-font-prefix font-prefix))
2225 (org-html-htmlize-region-for-paste
2226 (point-min) (point-max))))))
2227 ;; Strip any enclosing <pre></pre> tags.
2228 (let* ((beg (and (string-match "\\`<pre[^>]*>\n?" code) (match-end 0)))
2229 (end (and beg (string-match "</pre>\\'" code))))
2230 (if (and beg end) (substring code beg end) code)))))))))
2232 (defun org-html-do-format-code
2233 (code &optional lang refs retain-labels num-start)
2234 "Format CODE string as source code.
2235 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
2236 respectively, the language of the source code, as a string, an
2237 alist between line numbers and references (as returned by
2238 `org-export-unravel-code'), a boolean specifying if labels should
2239 appear in the source code, and the number associated to the first
2240 line of code."
2241 (let* ((code-lines (split-string code "\n"))
2242 (code-length (length code-lines))
2243 (num-fmt
2244 (and num-start
2245 (format "%%%ds: "
2246 (length (number-to-string (+ code-length num-start))))))
2247 (code (org-html-fontify-code code lang)))
2248 (org-export-format-code
2249 code
2250 (lambda (loc line-num ref)
2251 (setq loc
2252 (concat
2253 ;; Add line number, if needed.
2254 (when num-start
2255 (format "<span class=\"linenr\">%s</span>"
2256 (format num-fmt line-num)))
2257 ;; Transcoded src line.
2259 ;; Add label, if needed.
2260 (when (and ref retain-labels) (format " (%s)" ref))))
2261 ;; Mark transcoded line as an anchor, if needed.
2262 (if (not ref) loc
2263 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2264 ref loc)))
2265 num-start refs)))
2267 (defun org-html-format-code (element info)
2268 "Format contents of ELEMENT as source code.
2269 ELEMENT is either an example or a source block. INFO is a plist
2270 used as a communication channel."
2271 (let* ((lang (org-element-property :language element))
2272 ;; Extract code and references.
2273 (code-info (org-export-unravel-code element))
2274 (code (car code-info))
2275 (refs (cdr code-info))
2276 ;; Does the source block contain labels?
2277 (retain-labels (org-element-property :retain-labels element))
2278 ;; Does it have line numbers?
2279 (num-start (org-export-get-loc element info)))
2280 (org-html-do-format-code code lang refs retain-labels num-start)))
2283 ;;; Tables of Contents
2285 (defun org-html-toc (depth info &optional scope)
2286 "Build a table of contents.
2287 DEPTH is an integer specifying the depth of the table. INFO is
2288 a plist used as a communication channel. Optional argument SCOPE
2289 is an element defining the scope of the table. Return the table
2290 of contents as a string, or nil if it is empty."
2291 (let ((toc-entries
2292 (mapcar (lambda (headline)
2293 (cons (org-html--format-toc-headline headline info)
2294 (org-export-get-relative-level headline info)))
2295 (org-export-collect-headlines info depth scope))))
2296 (when toc-entries
2297 (let ((toc (concat "<div id=\"text-table-of-contents\">"
2298 (org-html--toc-text toc-entries)
2299 "</div>\n")))
2300 (if scope toc
2301 (let ((outer-tag (if (org-html--html5-fancy-p info)
2302 "nav"
2303 "div")))
2304 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2305 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2306 (format "<h%d>%s</h%d>\n"
2307 top-level
2308 (org-html--translate "Table of Contents" info)
2309 top-level))
2311 (format "</%s>\n" outer-tag))))))))
2313 (defun org-html--toc-text (toc-entries)
2314 "Return innards of a table of contents, as a string.
2315 TOC-ENTRIES is an alist where key is an entry title, as a string,
2316 and value is its relative level, as an integer."
2317 (let* ((prev-level (1- (cdar toc-entries)))
2318 (start-level prev-level))
2319 (concat
2320 (mapconcat
2321 (lambda (entry)
2322 (let ((headline (car entry))
2323 (level (cdr entry)))
2324 (concat
2325 (let* ((cnt (- level prev-level))
2326 (times (if (> cnt 0) (1- cnt) (- cnt))))
2327 (setq prev-level level)
2328 (concat
2329 (org-html--make-string
2330 times (cond ((> cnt 0) "\n<ul>\n<li>")
2331 ((< cnt 0) "</li>\n</ul>\n")))
2332 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2333 headline)))
2334 toc-entries "")
2335 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2337 (defun org-html--format-toc-headline (headline info)
2338 "Return an appropriate table of contents entry for HEADLINE.
2339 INFO is a plist used as a communication channel."
2340 (let* ((headline-number (org-export-get-headline-number headline info))
2341 (todo (and (plist-get info :with-todo-keywords)
2342 (let ((todo (org-element-property :todo-keyword headline)))
2343 (and todo (org-export-data todo info)))))
2344 (todo-type (and todo (org-element-property :todo-type headline)))
2345 (priority (and (plist-get info :with-priority)
2346 (org-element-property :priority headline)))
2347 (text (org-export-data-with-backend
2348 (org-export-get-alt-title headline info)
2349 (org-export-toc-entry-backend 'html)
2350 info))
2351 (tags (and (eq (plist-get info :with-tags) t)
2352 (org-export-get-tags headline info))))
2353 (format "<a href=\"#%s\">%s</a>"
2354 ;; Label.
2355 (or (org-element-property :CUSTOM_ID headline)
2356 (org-export-get-reference headline info))
2357 ;; Body.
2358 (concat
2359 (and (not (org-export-low-level-p headline info))
2360 (org-export-numbered-headline-p headline info)
2361 (concat (mapconcat #'number-to-string headline-number ".")
2362 ". "))
2363 (apply (plist-get info :html-format-headline-function)
2364 todo todo-type priority text tags :section-number nil)))))
2366 (defun org-html-list-of-listings (info)
2367 "Build a list of listings.
2368 INFO is a plist used as a communication channel. Return the list
2369 of listings as a string, or nil if it is empty."
2370 (let ((lol-entries (org-export-collect-listings info)))
2371 (when lol-entries
2372 (concat "<div id=\"list-of-listings\">\n"
2373 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2374 (format "<h%d>%s</h%d>\n"
2375 top-level
2376 (org-html--translate "List of Listings" info)
2377 top-level))
2378 "<div id=\"text-list-of-listings\">\n<ul>\n"
2379 (let ((count 0)
2380 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2381 (org-html--translate "Listing %d:" info))))
2382 (mapconcat
2383 (lambda (entry)
2384 (let ((label (and (org-element-property :name entry)
2385 (org-export-get-reference entry info)))
2386 (title (org-trim
2387 (org-export-data
2388 (or (org-export-get-caption entry t)
2389 (org-export-get-caption entry))
2390 info))))
2391 (concat
2392 "<li>"
2393 (if (not label)
2394 (concat (format initial-fmt (cl-incf count))
2396 title)
2397 (format "<a href=\"#%s\">%s %s</a>"
2398 label
2399 (format initial-fmt (cl-incf count))
2400 title))
2401 "</li>")))
2402 lol-entries "\n"))
2403 "\n</ul>\n</div>\n</div>"))))
2405 (defun org-html-list-of-tables (info)
2406 "Build a list of tables.
2407 INFO is a plist used as a communication channel. Return the list
2408 of tables as a string, or nil if it is empty."
2409 (let ((lol-entries (org-export-collect-tables info)))
2410 (when lol-entries
2411 (concat "<div id=\"list-of-tables\">\n"
2412 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2413 (format "<h%d>%s</h%d>\n"
2414 top-level
2415 (org-html--translate "List of Tables" info)
2416 top-level))
2417 "<div id=\"text-list-of-tables\">\n<ul>\n"
2418 (let ((count 0)
2419 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2420 (org-html--translate "Table %d:" info))))
2421 (mapconcat
2422 (lambda (entry)
2423 (let ((label (and (org-element-property :name entry)
2424 (org-export-get-reference entry info)))
2425 (title (org-trim
2426 (org-export-data
2427 (or (org-export-get-caption entry t)
2428 (org-export-get-caption entry))
2429 info))))
2430 (concat
2431 "<li>"
2432 (if (not label)
2433 (concat (format initial-fmt (cl-incf count))
2435 title)
2436 (format "<a href=\"#%s\">%s %s</a>"
2437 label
2438 (format initial-fmt (cl-incf count))
2439 title))
2440 "</li>")))
2441 lol-entries "\n"))
2442 "\n</ul>\n</div>\n</div>"))))
2445 ;;; Transcode Functions
2447 ;;;; Bold
2449 (defun org-html-bold (_bold contents info)
2450 "Transcode BOLD from Org to HTML.
2451 CONTENTS is the text with bold markup. INFO is a plist holding
2452 contextual information."
2453 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2454 contents))
2456 ;;;; Center Block
2458 (defun org-html-center-block (_center-block contents _info)
2459 "Transcode a CENTER-BLOCK element from Org to HTML.
2460 CONTENTS holds the contents of the block. INFO is a plist
2461 holding contextual information."
2462 (format "<div class=\"org-center\">\n%s</div>" contents))
2464 ;;;; Clock
2466 (defun org-html-clock (clock _contents _info)
2467 "Transcode a CLOCK element from Org to HTML.
2468 CONTENTS is nil. INFO is a plist used as a communication
2469 channel."
2470 (format "<p>
2471 <span class=\"timestamp-wrapper\">
2472 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2473 </span>
2474 </p>"
2475 org-clock-string
2476 (org-timestamp-translate (org-element-property :value clock))
2477 (let ((time (org-element-property :duration clock)))
2478 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2480 ;;;; Code
2482 (defun org-html-code (code _contents info)
2483 "Transcode CODE from Org to HTML.
2484 CONTENTS is nil. INFO is a plist holding contextual
2485 information."
2486 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2487 (org-html-encode-plain-text (org-element-property :value code))))
2489 ;;;; Drawer
2491 (defun org-html-drawer (drawer contents info)
2492 "Transcode a DRAWER element from Org to HTML.
2493 CONTENTS holds the contents of the block. INFO is a plist
2494 holding contextual information."
2495 (funcall (plist-get info :html-format-drawer-function)
2496 (org-element-property :drawer-name drawer)
2497 contents))
2499 ;;;; Dynamic Block
2501 (defun org-html-dynamic-block (_dynamic-block contents _info)
2502 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2503 CONTENTS holds the contents of the block. INFO is a plist
2504 holding contextual information. See `org-export-data'."
2505 contents)
2507 ;;;; Entity
2509 (defun org-html-entity (entity _contents _info)
2510 "Transcode an ENTITY object from Org to HTML.
2511 CONTENTS are the definition itself. INFO is a plist holding
2512 contextual information."
2513 (org-element-property :html entity))
2515 ;;;; Example Block
2517 (defun org-html-example-block (example-block _contents info)
2518 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2519 CONTENTS is nil. INFO is a plist holding contextual
2520 information."
2521 (let ((attributes (org-export-read-attribute :attr_html example-block)))
2522 (if (plist-get attributes :textarea)
2523 (org-html--textarea-block example-block)
2524 (format "<pre class=\"example\"%s>\n%s</pre>"
2525 (let* ((name (org-element-property :name example-block))
2526 (a (org-html--make-attribute-string
2527 (if (or (not name) (plist-member attributes :id))
2528 attributes
2529 (plist-put attributes :id name)))))
2530 (if (org-string-nw-p a) (concat " " a) ""))
2531 (org-html-format-code example-block info)))))
2533 ;;;; Export Snippet
2535 (defun org-html-export-snippet (export-snippet _contents _info)
2536 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2537 CONTENTS is nil. INFO is a plist holding contextual
2538 information."
2539 (when (eq (org-export-snippet-backend export-snippet) 'html)
2540 (org-element-property :value export-snippet)))
2542 ;;;; Export Block
2544 (defun org-html-export-block (export-block _contents _info)
2545 "Transcode a EXPORT-BLOCK element from Org to HTML.
2546 CONTENTS is nil. INFO is a plist holding contextual information."
2547 (when (string= (org-element-property :type export-block) "HTML")
2548 (org-remove-indentation (org-element-property :value export-block))))
2550 ;;;; Fixed Width
2552 (defun org-html-fixed-width (fixed-width _contents _info)
2553 "Transcode a FIXED-WIDTH element from Org to HTML.
2554 CONTENTS is nil. INFO is a plist holding contextual information."
2555 (format "<pre class=\"example\">\n%s</pre>"
2556 (org-html-do-format-code
2557 (org-remove-indentation
2558 (org-element-property :value fixed-width)))))
2560 ;;;; Footnote Reference
2562 (defun org-html-footnote-reference (footnote-reference _contents info)
2563 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2564 CONTENTS is nil. INFO is a plist holding contextual information."
2565 (concat
2566 ;; Insert separator between two footnotes in a row.
2567 (let ((prev (org-export-get-previous-element footnote-reference info)))
2568 (when (eq (org-element-type prev) 'footnote-reference)
2569 (plist-get info :html-footnote-separator)))
2570 (let* ((n (org-export-get-footnote-number footnote-reference info))
2571 (id (format "fnr.%d%s"
2573 (if (org-export-footnote-first-reference-p
2574 footnote-reference info)
2576 ".100"))))
2577 (format
2578 (plist-get info :html-footnote-format)
2579 (org-html--anchor
2580 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2582 ;;;; Headline
2584 (defun org-html-headline (headline contents info)
2585 "Transcode a HEADLINE element from Org to HTML.
2586 CONTENTS holds the contents of the headline. INFO is a plist
2587 holding contextual information."
2588 (unless (org-element-property :footnote-section-p headline)
2589 (let* ((numberedp (org-export-numbered-headline-p headline info))
2590 (numbers (org-export-get-headline-number headline info))
2591 (level (+ (org-export-get-relative-level headline info)
2592 (1- (plist-get info :html-toplevel-hlevel))))
2593 (todo (and (plist-get info :with-todo-keywords)
2594 (let ((todo (org-element-property :todo-keyword headline)))
2595 (and todo (org-export-data todo info)))))
2596 (todo-type (and todo (org-element-property :todo-type headline)))
2597 (priority (and (plist-get info :with-priority)
2598 (org-element-property :priority headline)))
2599 (text (org-export-data (org-element-property :title headline) info))
2600 (tags (and (plist-get info :with-tags)
2601 (org-export-get-tags headline info)))
2602 (full-text (funcall (plist-get info :html-format-headline-function)
2603 todo todo-type priority text tags info))
2604 (contents (or contents ""))
2605 (id (or (org-element-property :CUSTOM_ID headline)
2606 (org-export-get-reference headline info)))
2607 (formatted-text
2608 (if (plist-get info :html-self-link-headlines)
2609 (format "<a href=\"#%s\">%s</a>" id full-text)
2610 full-text)))
2611 (if (org-export-low-level-p headline info)
2612 ;; This is a deep sub-tree: export it as a list item.
2613 (let* ((html-type (if numberedp "ol" "ul")))
2614 (concat
2615 (and (org-export-first-sibling-p headline info)
2616 (apply #'format "<%s class=\"org-%s\">\n"
2617 (make-list 2 html-type)))
2618 (org-html-format-list-item
2619 contents (if numberedp 'ordered 'unordered)
2620 nil info nil
2621 (concat (org-html--anchor id nil nil info) formatted-text)) "\n"
2622 (and (org-export-last-sibling-p headline info)
2623 (format "</%s>\n" html-type))))
2624 ;; Standard headline. Export it as a section.
2625 (let ((extra-class
2626 (org-element-property :HTML_CONTAINER_CLASS headline))
2627 (headline-class
2628 (org-element-property :HTML_HEADLINE_CLASS headline))
2629 (first-content (car (org-element-contents headline))))
2630 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2631 (org-html--container headline info)
2632 (concat "outline-container-"
2633 (org-export-get-reference headline info))
2634 (concat (format "outline-%d" level)
2635 (and extra-class " ")
2636 extra-class)
2637 (format "\n<h%d id=\"%s\"%s>%s</h%d>\n"
2638 level
2640 (if (not headline-class) ""
2641 (format " class=\"%s\"" headline-class))
2642 (concat
2643 (and numberedp
2644 (format
2645 "<span class=\"section-number-%d\">%s</span> "
2646 level
2647 (mapconcat #'number-to-string numbers ".")))
2648 formatted-text)
2649 level)
2650 ;; When there is no section, pretend there is an
2651 ;; empty one to get the correct <div
2652 ;; class="outline-...> which is needed by
2653 ;; `org-info.js'.
2654 (if (eq (org-element-type first-content) 'section) contents
2655 (concat (org-html-section first-content "" info) contents))
2656 (org-html--container headline info)))))))
2658 (defun org-html-format-headline-default-function
2659 (todo _todo-type priority text tags info)
2660 "Default format function for a headline.
2661 See `org-html-format-headline-function' for details."
2662 (let ((todo (org-html--todo todo info))
2663 (priority (org-html--priority priority info))
2664 (tags (org-html--tags tags info)))
2665 (concat todo (and todo " ")
2666 priority (and priority " ")
2667 text
2668 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2670 (defun org-html--container (headline info)
2671 (or (org-element-property :HTML_CONTAINER headline)
2672 (if (= 1 (org-export-get-relative-level headline info))
2673 (plist-get info :html-container)
2674 "div")))
2676 ;;;; Horizontal Rule
2678 (defun org-html-horizontal-rule (_horizontal-rule _contents info)
2679 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2680 CONTENTS is nil. INFO is a plist holding contextual information."
2681 (org-html-close-tag "hr" nil info))
2683 ;;;; Inline Src Block
2685 (defun org-html-inline-src-block (inline-src-block _contents info)
2686 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2687 CONTENTS holds the contents of the item. INFO is a plist holding
2688 contextual information."
2689 (let* ((lang (org-element-property :language inline-src-block))
2690 (code (org-html-fontify-code
2691 (org-element-property :value inline-src-block)
2692 lang))
2693 (label
2694 (let ((lbl (and (org-element-property :name inline-src-block)
2695 (org-export-get-reference inline-src-block info))))
2696 (if (not lbl) "" (format " id=\"%s\"" lbl)))))
2697 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
2699 ;;;; Inlinetask
2701 (defun org-html-inlinetask (inlinetask contents info)
2702 "Transcode an INLINETASK element from Org to HTML.
2703 CONTENTS holds the contents of the block. INFO is a plist
2704 holding contextual information."
2705 (let* ((todo (and (plist-get info :with-todo-keywords)
2706 (let ((todo (org-element-property :todo-keyword inlinetask)))
2707 (and todo (org-export-data todo info)))))
2708 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2709 (priority (and (plist-get info :with-priority)
2710 (org-element-property :priority inlinetask)))
2711 (text (org-export-data (org-element-property :title inlinetask) info))
2712 (tags (and (plist-get info :with-tags)
2713 (org-export-get-tags inlinetask info))))
2714 (funcall (plist-get info :html-format-inlinetask-function)
2715 todo todo-type priority text tags contents info)))
2717 (defun org-html-format-inlinetask-default-function
2718 (todo todo-type priority text tags contents info)
2719 "Default format function for inlinetasks.
2720 See `org-html-format-inlinetask-function' for details."
2721 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2722 (org-html-format-headline-default-function
2723 todo todo-type priority text tags info)
2724 (org-html-close-tag "br" nil info)
2725 contents))
2727 ;;;; Italic
2729 (defun org-html-italic (_italic contents info)
2730 "Transcode ITALIC from Org to HTML.
2731 CONTENTS is the text with italic markup. INFO is a plist holding
2732 contextual information."
2733 (format
2734 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2735 contents))
2737 ;;;; Item
2739 (defun org-html-checkbox (checkbox info)
2740 "Format CHECKBOX into HTML.
2741 INFO is a plist holding contextual information. See
2742 `org-html-checkbox-type' for customization options."
2743 (cdr (assq checkbox
2744 (cdr (assq (plist-get info :html-checkbox-type)
2745 org-html-checkbox-types)))))
2747 (defun org-html-format-list-item (contents type checkbox info
2748 &optional term-counter-id
2749 headline)
2750 "Format a list item into HTML."
2751 (let ((class (if checkbox
2752 (format " class=\"%s\""
2753 (symbol-name checkbox)) ""))
2754 (checkbox (concat (org-html-checkbox checkbox info)
2755 (and checkbox " ")))
2756 (br (org-html-close-tag "br" nil info))
2757 (extra-newline (if (and (org-string-nw-p contents) headline) "\n" "")))
2758 (concat
2759 (pcase type
2760 (`ordered
2761 (let* ((counter term-counter-id)
2762 (extra (if counter (format " value=\"%s\"" counter) "")))
2763 (concat
2764 (format "<li%s%s>" class extra)
2765 (when headline (concat headline br)))))
2766 (`unordered
2767 (let* ((id term-counter-id)
2768 (extra (if id (format " id=\"%s\"" id) "")))
2769 (concat
2770 (format "<li%s%s>" class extra)
2771 (when headline (concat headline br)))))
2772 (`descriptive
2773 (let* ((term term-counter-id))
2774 (setq term (or term "(no term)"))
2775 ;; Check-boxes in descriptive lists are associated to tag.
2776 (concat (format "<dt%s>%s</dt>"
2777 class (concat checkbox term))
2778 "<dd>"))))
2779 (unless (eq type 'descriptive) checkbox)
2780 extra-newline
2781 (and (org-string-nw-p contents) (org-trim contents))
2782 extra-newline
2783 (pcase type
2784 (`ordered "</li>")
2785 (`unordered "</li>")
2786 (`descriptive "</dd>")))))
2788 (defun org-html-item (item contents info)
2789 "Transcode an ITEM element from Org to HTML.
2790 CONTENTS holds the contents of the item. INFO is a plist holding
2791 contextual information."
2792 (let* ((plain-list (org-export-get-parent item))
2793 (type (org-element-property :type plain-list))
2794 (counter (org-element-property :counter item))
2795 (checkbox (org-element-property :checkbox item))
2796 (tag (let ((tag (org-element-property :tag item)))
2797 (and tag (org-export-data tag info)))))
2798 (org-html-format-list-item
2799 contents type checkbox info (or tag counter))))
2801 ;;;; Keyword
2803 (defun org-html-keyword (keyword _contents info)
2804 "Transcode a KEYWORD element from Org to HTML.
2805 CONTENTS is nil. INFO is a plist holding contextual information."
2806 (let ((key (org-element-property :key keyword))
2807 (value (org-element-property :value keyword)))
2808 (cond
2809 ((string= key "HTML") value)
2810 ((string= key "TOC")
2811 (let ((case-fold-search t))
2812 (cond
2813 ((string-match "\\<headlines\\>" value)
2814 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2815 (string-to-number (match-string 0 value))))
2816 (localp (string-match-p "\\<local\\>" value)))
2817 (org-html-toc depth info (and localp keyword))))
2818 ((string= "listings" value) (org-html-list-of-listings info))
2819 ((string= "tables" value) (org-html-list-of-tables info))))))))
2821 ;;;; Latex Environment
2823 (defun org-html-format-latex (latex-frag processing-type info)
2824 "Format a LaTeX fragment LATEX-FRAG into HTML.
2825 PROCESSING-TYPE designates the tool used for conversion. It can
2826 be `mathjax', `verbatim', nil, t or symbols in
2827 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
2828 `imagemagick'. See `org-html-with-latex' for more information.
2829 INFO is a plist containing export properties."
2830 (let ((cache-relpath "") (cache-dir ""))
2831 (unless (eq processing-type 'mathjax)
2832 (let ((bfn (or (buffer-file-name)
2833 (make-temp-name
2834 (expand-file-name "latex" temporary-file-directory))))
2835 (latex-header
2836 (let ((header (plist-get info :latex-header)))
2837 (and header
2838 (concat (mapconcat
2839 (lambda (line) (concat "#+LATEX_HEADER: " line))
2840 (org-split-string header "\n")
2841 "\n")
2842 "\n")))))
2843 (setq cache-relpath
2844 (concat (file-name-as-directory org-preview-latex-image-directory)
2845 (file-name-sans-extension
2846 (file-name-nondirectory bfn)))
2847 cache-dir (file-name-directory bfn))
2848 ;; Re-create LaTeX environment from original buffer in
2849 ;; temporary buffer so that dvipng/imagemagick can properly
2850 ;; turn the fragment into an image.
2851 (setq latex-frag (concat latex-header latex-frag))))
2852 (with-temp-buffer
2853 (insert latex-frag)
2854 (org-format-latex cache-relpath nil nil cache-dir nil
2855 "Creating LaTeX Image..." nil processing-type)
2856 (buffer-string))))
2858 (defun org-html--wrap-latex-environment (contents _ &optional caption label)
2859 "Wrap CONTENTS string within appropriate environment for equations.
2860 When optional arguments CAPTION and LABEL are given, use them for
2861 caption and \"id\" attribute."
2862 (format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
2863 ;; ID.
2864 (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
2865 ;; Contents.
2866 (format "<span class=\"equation\">\n%s\n</span>" contents)
2867 ;; Caption.
2868 (if (not (org-string-nw-p caption)) ""
2869 (format "\n<span class=\"equation-label\">\n%s\n</span>"
2870 caption))))
2872 (defun org-html--math-environment-p (element &optional _)
2873 "Non-nil when ELEMENT is a LaTeX math environment.
2874 Math environments match the regular expression defined in
2875 `org-latex-math-environments-re'. This function is meant to be
2876 used as a predicate for `org-export-get-ordinal' or a value to
2877 `org-html-standalone-image-predicate'."
2878 (string-match-p org-latex-math-environments-re
2879 (org-element-property :value element)))
2881 (defun org-html--unlabel-latex-environment (latex-frag)
2882 "Change environment in LATEX-FRAG string to an unnumbered one.
2883 For instance, change an 'equation' environment to 'equation*'."
2884 (replace-regexp-in-string
2885 "\\`[ \t]*\\\\begin{\\([^*]+?\\)}"
2886 "\\1*"
2887 (replace-regexp-in-string "^[ \t]*\\\\end{\\([^*]+?\\)}[ \r\t\n]*\\'"
2888 "\\1*"
2889 latex-frag nil nil 1)
2890 nil nil 1))
2892 (defun org-html-latex-environment (latex-environment _contents info)
2893 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2894 CONTENTS is nil. INFO is a plist holding contextual information."
2895 (let ((processing-type (plist-get info :with-latex))
2896 (latex-frag (org-remove-indentation
2897 (org-element-property :value latex-environment)))
2898 (attributes (org-export-read-attribute :attr_html latex-environment))
2899 (label (and (org-element-property :name latex-environment)
2900 (org-export-get-reference latex-environment info)))
2901 (caption (number-to-string
2902 (org-export-get-ordinal
2903 latex-environment info nil
2904 #'org-html--math-environment-p))))
2905 (cond
2906 ((memq processing-type '(t mathjax))
2907 (org-html-format-latex
2908 (if (org-string-nw-p label)
2909 (replace-regexp-in-string "\\`.*"
2910 (format "\\&\n\\\\label{%s}" label)
2911 latex-frag)
2912 latex-frag)
2913 'mathjax info))
2914 ((assq processing-type org-preview-latex-process-alist)
2915 (let ((formula-link
2916 (org-html-format-latex
2917 (org-html--unlabel-latex-environment latex-frag)
2918 processing-type info)))
2919 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2920 (org-html--wrap-latex-environment
2921 (org-html--format-image
2922 (match-string 1 formula-link) attributes info)
2923 info caption label))))
2924 (t (org-html--wrap-latex-environment latex-frag info caption label)))))
2926 ;;;; Latex Fragment
2928 (defun org-html-latex-fragment (latex-fragment _contents info)
2929 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2930 CONTENTS is nil. INFO is a plist holding contextual information."
2931 (let ((latex-frag (org-element-property :value latex-fragment))
2932 (processing-type (plist-get info :with-latex)))
2933 (cond
2934 ((memq processing-type '(t mathjax))
2935 (org-html-format-latex latex-frag 'mathjax info))
2936 ((assq processing-type org-preview-latex-process-alist)
2937 (let ((formula-link
2938 (org-html-format-latex latex-frag processing-type info)))
2939 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2940 (org-html--format-image (match-string 1 formula-link) nil info))))
2941 (t latex-frag))))
2943 ;;;; Line Break
2945 (defun org-html-line-break (_line-break _contents info)
2946 "Transcode a LINE-BREAK object from Org to HTML.
2947 CONTENTS is nil. INFO is a plist holding contextual information."
2948 (concat (org-html-close-tag "br" nil info) "\n"))
2950 ;;;; Link
2952 (defun org-html-image-link-filter (data _backend info)
2953 (org-export-insert-image-links data info org-html-inline-image-rules))
2955 (defun org-html-inline-image-p (link info)
2956 "Non-nil when LINK is meant to appear as an image.
2957 INFO is a plist used as a communication channel. LINK is an
2958 inline image when it has no description and targets an image
2959 file (see `org-html-inline-image-rules' for more information), or
2960 if its description is a single link targeting an image file."
2961 (if (not (org-element-contents link))
2962 (org-export-inline-image-p
2963 link (plist-get info :html-inline-image-rules))
2964 (not
2965 (let ((link-count 0))
2966 (org-element-map (org-element-contents link)
2967 (cons 'plain-text org-element-all-objects)
2968 (lambda (obj)
2969 (pcase (org-element-type obj)
2970 (`plain-text (org-string-nw-p obj))
2971 (`link (if (= link-count 1) t
2972 (cl-incf link-count)
2973 (not (org-export-inline-image-p
2974 obj (plist-get info :html-inline-image-rules)))))
2975 (_ t)))
2976 info t)))))
2978 (defvar org-html-standalone-image-predicate)
2979 (defun org-html-standalone-image-p (element info)
2980 "Non-nil if ELEMENT is a standalone image.
2982 INFO is a plist holding contextual information.
2984 An element or object is a standalone image when
2986 - its type is `paragraph' and its sole content, save for white
2987 spaces, is a link that qualifies as an inline image;
2989 - its type is `link' and its containing paragraph has no other
2990 content save white spaces.
2992 Bind `org-html-standalone-image-predicate' to constrain paragraph
2993 further. For example, to check for only captioned standalone
2994 images, set it to:
2996 (lambda (paragraph) (org-element-property :caption paragraph))"
2997 (let ((paragraph (pcase (org-element-type element)
2998 (`paragraph element)
2999 (`link (org-export-get-parent element)))))
3000 (and (eq (org-element-type paragraph) 'paragraph)
3001 (or (not (fboundp 'org-html-standalone-image-predicate))
3002 (funcall org-html-standalone-image-predicate paragraph))
3003 (catch 'exit
3004 (let ((link-count 0))
3005 (org-element-map (org-element-contents paragraph)
3006 (cons 'plain-text org-element-all-objects)
3007 (lambda (obj)
3008 (when (pcase (org-element-type obj)
3009 (`plain-text (org-string-nw-p obj))
3010 (`link (or (> (cl-incf link-count) 1)
3011 (not (org-html-inline-image-p obj info))))
3012 (_ t))
3013 (throw 'exit nil)))
3014 info nil 'link)
3015 (= link-count 1))))))
3017 (defun org-html-link (link desc info)
3018 "Transcode a LINK object from Org to HTML.
3019 DESC is the description part of the link, or the empty string.
3020 INFO is a plist holding contextual information. See
3021 `org-export-data'."
3022 (let* ((link-org-files-as-html-maybe
3023 (lambda (raw-path info)
3024 ;; Treat links to `file.org' as links to `file.html', if
3025 ;; needed. See `org-html-link-org-files-as-html'.
3026 (cond
3027 ((and (plist-get info :html-link-org-files-as-html)
3028 (string= ".org"
3029 (downcase (file-name-extension raw-path "."))))
3030 (concat (file-name-sans-extension raw-path) "."
3031 (plist-get info :html-extension)))
3032 (t raw-path))))
3033 (type (org-element-property :type link))
3034 (raw-path (org-element-property :path link))
3035 ;; Ensure DESC really exists, or set it to nil.
3036 (desc (org-string-nw-p desc))
3037 (path
3038 (cond
3039 ((member type '("http" "https" "ftp" "mailto" "news"))
3040 (url-encode-url (concat type ":" raw-path)))
3041 ((string= type "file")
3042 ;; During publishing, turn absolute file names belonging
3043 ;; to base directory into relative file names. Otherwise,
3044 ;; append "file" protocol to absolute file name.
3045 (setq raw-path
3046 (org-export-file-uri
3047 (org-publish-file-relative-name raw-path info)))
3048 ;; Possibly append `:html-link-home' to relative file
3049 ;; name.
3050 (let ((home (and (plist-get info :html-link-home)
3051 (org-trim (plist-get info :html-link-home)))))
3052 (when (and home
3053 (plist-get info :html-link-use-abs-url)
3054 (file-name-absolute-p raw-path))
3055 (setq raw-path (concat (file-name-as-directory home) raw-path))))
3056 ;; Maybe turn ".org" into ".html".
3057 (setq raw-path (funcall link-org-files-as-html-maybe raw-path info))
3058 ;; Add search option, if any. A search option can be
3059 ;; relative to a custom-id, a headline title, a name or
3060 ;; a target.
3061 (let ((option (org-element-property :search-option link)))
3062 (if (not option) raw-path
3063 (let ((path (org-element-property :path link)))
3064 (concat raw-path
3066 (org-publish-resolve-external-link option path t))))))
3067 (t raw-path)))
3068 (attributes-plist
3069 (org-combine-plists
3070 ;; Extract attributes from parent's paragraph. HACK: Only
3071 ;; do this for the first link in parent (inner image link
3072 ;; for inline images). This is needed as long as
3073 ;; attributes cannot be set on a per link basis.
3074 (let* ((parent (org-export-get-parent-element link))
3075 (link (let ((container (org-export-get-parent link)))
3076 (if (and (eq 'link (org-element-type container))
3077 (org-html-inline-image-p link info))
3078 container
3079 link))))
3080 (and (eq link (org-element-map parent 'link #'identity info t))
3081 (org-export-read-attribute :attr_html parent)))
3082 ;; Also add attributes from link itself. Currently, those
3083 ;; need to be added programmatically before `org-html-link'
3084 ;; is invoked, for example, by backends building upon HTML
3085 ;; export.
3086 (org-export-read-attribute :attr_html link)))
3087 (attributes
3088 (let ((attr (org-html--make-attribute-string attributes-plist)))
3089 (if (org-string-nw-p attr) (concat " " attr) ""))))
3090 (cond
3091 ;; Link type is handled by a special function.
3092 ((org-export-custom-protocol-maybe link desc 'html))
3093 ;; Image file.
3094 ((and (plist-get info :html-inline-images)
3095 (org-export-inline-image-p
3096 link (plist-get info :html-inline-image-rules)))
3097 (org-html--format-image path attributes-plist info))
3098 ;; Radio target: Transcode target's contents and use them as
3099 ;; link's description.
3100 ((string= type "radio")
3101 (let ((destination (org-export-resolve-radio-link link info)))
3102 (if (not destination) desc
3103 (format "<a href=\"#%s\"%s>%s</a>"
3104 (org-export-get-reference destination info)
3105 attributes
3106 desc))))
3107 ;; Links pointing to a headline: Find destination and build
3108 ;; appropriate referencing command.
3109 ((member type '("custom-id" "fuzzy" "id"))
3110 (let ((destination (if (string= type "fuzzy")
3111 (org-export-resolve-fuzzy-link link info)
3112 (org-export-resolve-id-link link info))))
3113 (pcase (org-element-type destination)
3114 ;; ID link points to an external file.
3115 (`plain-text
3116 (let ((fragment (concat "ID-" path))
3117 ;; Treat links to ".org" files as ".html", if needed.
3118 (path (funcall link-org-files-as-html-maybe
3119 destination info)))
3120 (format "<a href=\"%s#%s\"%s>%s</a>"
3121 path fragment attributes (or desc destination))))
3122 ;; Fuzzy link points nowhere.
3123 (`nil
3124 (format "<i>%s</i>"
3125 (or desc
3126 (org-export-data
3127 (org-element-property :raw-link link) info))))
3128 ;; Link points to a headline.
3129 (`headline
3130 (let ((href (or (org-element-property :CUSTOM_ID destination)
3131 (org-export-get-reference destination info)))
3132 ;; What description to use?
3133 (desc
3134 ;; Case 1: Headline is numbered and LINK has no
3135 ;; description. Display section number.
3136 (if (and (org-export-numbered-headline-p destination info)
3137 (not desc))
3138 (mapconcat #'number-to-string
3139 (org-export-get-headline-number
3140 destination info) ".")
3141 ;; Case 2: Either the headline is un-numbered or
3142 ;; LINK has a custom description. Display LINK's
3143 ;; description or headline's title.
3144 (or desc
3145 (org-export-data
3146 (org-element-property :title destination) info)))))
3147 (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
3148 ;; Fuzzy link points to a target or an element.
3150 (if (and destination
3151 (memq (plist-get info :with-latex) '(mathjax t))
3152 (eq 'latex-environment (org-element-type destination))
3153 (eq 'math (org-latex--environment-type destination)))
3154 ;; Caption and labels are introduced within LaTeX
3155 ;; environment. Use "eqref" macro to refer to those in
3156 ;; the document.
3157 (format "\\eqref{%s}"
3158 (org-export-get-reference destination info))
3159 (let* ((ref (org-export-get-reference destination info))
3160 (org-html-standalone-image-predicate
3161 #'org-html--has-caption-p)
3162 (counter-predicate
3163 (if (eq 'latex-environment (org-element-type destination))
3164 #'org-html--math-environment-p
3165 #'org-html--has-caption-p))
3166 (number
3167 (cond
3168 (desc nil)
3169 ((org-html-standalone-image-p destination info)
3170 (org-export-get-ordinal
3171 (org-element-map destination 'link #'identity info t)
3172 info 'link 'org-html-standalone-image-p))
3173 (t (org-export-get-ordinal
3174 destination info nil counter-predicate))))
3175 (desc
3176 (cond (desc)
3177 ((not number) "No description for this link")
3178 ((numberp number) (number-to-string number))
3179 (t (mapconcat #'number-to-string number ".")))))
3180 (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc)))))))
3181 ;; Coderef: replace link with the reference name or the
3182 ;; equivalent line number.
3183 ((string= type "coderef")
3184 (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
3185 (format "<a href=\"#%s\" %s%s>%s</a>"
3186 fragment
3187 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
3188 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
3189 fragment fragment)
3190 attributes
3191 (format (org-export-get-coderef-format path desc)
3192 (org-export-resolve-coderef path info)))))
3193 ;; External link with a description part.
3194 ((and path desc)
3195 (format "<a href=\"%s\"%s>%s</a>"
3196 (org-html-encode-plain-text path)
3197 attributes
3198 desc))
3199 ;; External link without a description part.
3200 (path
3201 (let ((path (org-html-encode-plain-text path)))
3202 (format "<a href=\"%s\"%s>%s</a>" path attributes path)))
3203 ;; No path, only description. Try to do something useful.
3205 (format "<i>%s</i>" desc)))))
3207 ;;;; Node Property
3209 (defun org-html-node-property (node-property _contents _info)
3210 "Transcode a NODE-PROPERTY element from Org to HTML.
3211 CONTENTS is nil. INFO is a plist holding contextual
3212 information."
3213 (format "%s:%s"
3214 (org-element-property :key node-property)
3215 (let ((value (org-element-property :value node-property)))
3216 (if value (concat " " value) ""))))
3218 ;;;; Paragraph
3220 (defun org-html-paragraph (paragraph contents info)
3221 "Transcode a PARAGRAPH element from Org to HTML.
3222 CONTENTS is the contents of the paragraph, as a string. INFO is
3223 the plist used as a communication channel."
3224 (let* ((parent (org-export-get-parent paragraph))
3225 (parent-type (org-element-type parent))
3226 (style '((footnote-definition " class=\"footpara\"")
3227 (org-data " class=\"footpara\"")))
3228 (attributes (org-html--make-attribute-string
3229 (org-export-read-attribute :attr_html paragraph)))
3230 (extra (or (cadr (assq parent-type style)) "")))
3231 (cond
3232 ((and (eq parent-type 'item)
3233 (not (org-export-get-previous-element paragraph info))
3234 (let ((followers (org-export-get-next-element paragraph info 2)))
3235 (and (not (cdr followers))
3236 (memq (org-element-type (car followers)) '(nil plain-list)))))
3237 ;; First paragraph in an item has no tag if it is alone or
3238 ;; followed, at most, by a sub-list.
3239 contents)
3240 ((org-html-standalone-image-p paragraph info)
3241 ;; Standalone image.
3242 (let ((caption
3243 (let ((raw (org-export-data
3244 (org-export-get-caption paragraph) info))
3245 (org-html-standalone-image-predicate
3246 #'org-html--has-caption-p))
3247 (if (not (org-string-nw-p raw)) raw
3248 (concat "<span class=\"figure-number\">"
3249 (format (org-html--translate "Figure %d:" info)
3250 (org-export-get-ordinal
3251 (org-element-map paragraph 'link
3252 #'identity info t)
3253 info nil #'org-html-standalone-image-p))
3254 " </span>"
3255 raw))))
3256 (label (and (org-element-property :name paragraph)
3257 (org-export-get-reference paragraph info))))
3258 (org-html--wrap-image contents info caption label)))
3259 ;; Regular paragraph.
3260 (t (format "<p%s%s>\n%s</p>"
3261 (if (org-string-nw-p attributes)
3262 (concat " " attributes) "")
3263 extra contents)))))
3265 ;;;; Plain List
3267 (defun org-html-plain-list (plain-list contents _info)
3268 "Transcode a PLAIN-LIST element from Org to HTML.
3269 CONTENTS is the contents of the list. INFO is a plist holding
3270 contextual information."
3271 (let* ((type (pcase (org-element-property :type plain-list)
3272 (`ordered "ol")
3273 (`unordered "ul")
3274 (`descriptive "dl")
3275 (other (error "Unknown HTML list type: %s" other))))
3276 (class (format "org-%s" type))
3277 (attributes (org-export-read-attribute :attr_html plain-list)))
3278 (format "<%s %s>\n%s</%s>"
3279 type
3280 (org-html--make-attribute-string
3281 (plist-put attributes :class
3282 (org-trim
3283 (mapconcat #'identity
3284 (list class (plist-get attributes :class))
3285 " "))))
3286 contents
3287 type)))
3289 ;;;; Plain Text
3291 (defun org-html-convert-special-strings (string)
3292 "Convert special characters in STRING to HTML."
3293 (dolist (a org-html-special-string-regexps string)
3294 (let ((re (car a))
3295 (rpl (cdr a)))
3296 (setq string (replace-regexp-in-string re rpl string t)))))
3298 (defun org-html-encode-plain-text (text)
3299 "Convert plain text characters from TEXT to HTML equivalent.
3300 Possible conversions are set in `org-html-protect-char-alist'."
3301 (dolist (pair org-html-protect-char-alist text)
3302 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3304 (defun org-html-plain-text (text info)
3305 "Transcode a TEXT string from Org to HTML.
3306 TEXT is the string to transcode. INFO is a plist holding
3307 contextual information."
3308 (let ((output text))
3309 ;; Protect following characters: <, >, &.
3310 (setq output (org-html-encode-plain-text output))
3311 ;; Handle smart quotes. Be sure to provide original string since
3312 ;; OUTPUT may have been modified.
3313 (when (plist-get info :with-smart-quotes)
3314 (setq output (org-export-activate-smart-quotes output :html info text)))
3315 ;; Handle special strings.
3316 (when (plist-get info :with-special-strings)
3317 (setq output (org-html-convert-special-strings output)))
3318 ;; Handle break preservation if required.
3319 (when (plist-get info :preserve-breaks)
3320 (setq output
3321 (replace-regexp-in-string
3322 "\\(\\\\\\\\\\)?[ \t]*\n"
3323 (concat (org-html-close-tag "br" nil info) "\n") output)))
3324 ;; Return value.
3325 output))
3328 ;; Planning
3330 (defun org-html-planning (planning _contents info)
3331 "Transcode a PLANNING element from Org to HTML.
3332 CONTENTS is nil. INFO is a plist used as a communication
3333 channel."
3334 (format
3335 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3336 (org-trim
3337 (mapconcat
3338 (lambda (pair)
3339 (let ((timestamp (cdr pair)))
3340 (when timestamp
3341 (let ((string (car pair)))
3342 (format "<span class=\"timestamp-kwd\">%s</span> \
3343 <span class=\"timestamp\">%s</span> "
3344 string
3345 (org-html-plain-text (org-timestamp-translate timestamp)
3346 info))))))
3347 `((,org-closed-string . ,(org-element-property :closed planning))
3348 (,org-deadline-string . ,(org-element-property :deadline planning))
3349 (,org-scheduled-string . ,(org-element-property :scheduled planning)))
3350 ""))))
3352 ;;;; Property Drawer
3354 (defun org-html-property-drawer (_property-drawer contents _info)
3355 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3356 CONTENTS holds the contents of the drawer. INFO is a plist
3357 holding contextual information."
3358 (and (org-string-nw-p contents)
3359 (format "<pre class=\"example\">\n%s</pre>" contents)))
3361 ;;;; Quote Block
3363 (defun org-html-quote-block (quote-block contents _info)
3364 "Transcode a QUOTE-BLOCK element from Org to HTML.
3365 CONTENTS holds the contents of the block. INFO is a plist
3366 holding contextual information."
3367 (format "<blockquote%s>\n%s</blockquote>"
3368 (let* ((name (org-element-property :name quote-block))
3369 (attributes (org-export-read-attribute :attr_html quote-block))
3370 (a (org-html--make-attribute-string
3371 (if (or (not name) (plist-member attributes :id))
3372 attributes
3373 (plist-put attributes :id name)))))
3374 (if (org-string-nw-p a) (concat " " a) ""))
3375 contents))
3377 ;;;; Section
3379 (defun org-html-section (section contents info)
3380 "Transcode a SECTION element from Org to HTML.
3381 CONTENTS holds the contents of the section. INFO is a plist
3382 holding contextual information."
3383 (let ((parent (org-export-get-parent-headline section)))
3384 ;; Before first headline: no container, just return CONTENTS.
3385 (if (not parent) contents
3386 ;; Get div's class and id references.
3387 (let* ((class-num (+ (org-export-get-relative-level parent info)
3388 (1- (plist-get info :html-toplevel-hlevel))))
3389 (section-number
3390 (and (org-export-numbered-headline-p parent info)
3391 (mapconcat
3392 #'number-to-string
3393 (org-export-get-headline-number parent info) "-"))))
3394 ;; Build return value.
3395 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>\n"
3396 class-num
3397 (or (org-element-property :CUSTOM_ID parent)
3398 section-number
3399 (org-export-get-reference parent info))
3400 (or contents ""))))))
3402 ;;;; Radio Target
3404 (defun org-html-radio-target (radio-target text info)
3405 "Transcode a RADIO-TARGET object from Org to HTML.
3406 TEXT is the text of the target. INFO is a plist holding
3407 contextual information."
3408 (let ((ref (org-export-get-reference radio-target info)))
3409 (org-html--anchor ref text nil info)))
3411 ;;;; Special Block
3413 (defun org-html-special-block (special-block contents info)
3414 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3415 CONTENTS holds the contents of the block. INFO is a plist
3416 holding contextual information."
3417 (let* ((block-type (org-element-property :type special-block))
3418 (html5-fancy (and (org-html--html5-fancy-p info)
3419 (member block-type org-html-html5-elements)))
3420 (attributes (org-export-read-attribute :attr_html special-block)))
3421 (unless html5-fancy
3422 (let ((class (plist-get attributes :class)))
3423 (setq attributes (plist-put attributes :class
3424 (if class (concat class " " block-type)
3425 block-type)))))
3426 (let* ((contents (or contents ""))
3427 (name (org-element-property :name special-block))
3428 (a (org-html--make-attribute-string
3429 (if (or (not name) (plist-member attributes :id))
3430 attributes
3431 (plist-put attributes :id name))))
3432 (str (if (org-string-nw-p a) (concat " " a) "")))
3433 (if html5-fancy
3434 (format "<%s%s>\n%s</%s>" block-type str contents block-type)
3435 (format "<div%s>\n%s\n</div>" str contents)))))
3437 ;;;; Src Block
3439 (defun org-html-src-block (src-block _contents info)
3440 "Transcode a SRC-BLOCK element from Org to HTML.
3441 CONTENTS holds the contents of the item. INFO is a plist holding
3442 contextual information."
3443 (if (org-export-read-attribute :attr_html src-block :textarea)
3444 (org-html--textarea-block src-block)
3445 (let* ((lang (org-element-property :language src-block))
3446 (code (org-html-format-code src-block info))
3447 (label (let ((lbl (and (org-element-property :name src-block)
3448 (org-export-get-reference src-block info))))
3449 (if lbl (format " id=\"%s\"" lbl) "")))
3450 (klipsify (and (plist-get info :html-klipsify-src)
3451 (member lang '("javascript" "js"
3452 "ruby" "scheme" "clojure" "php" "html")))))
3453 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3454 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
3455 ;; Build caption.
3456 (let ((caption (org-export-get-caption src-block)))
3457 (if (not caption) ""
3458 (let ((listing-number
3459 (format
3460 "<span class=\"listing-number\">%s </span>"
3461 (format
3462 (org-html--translate "Listing %d:" info)
3463 (org-export-get-ordinal
3464 src-block info nil #'org-html--has-caption-p)))))
3465 (format "<label class=\"org-src-name\">%s%s</label>"
3466 listing-number
3467 (org-trim (org-export-data caption info))))))
3468 ;; Contents.
3469 (if klipsify
3470 (format "<pre><code class=\"src src-%s\"%s%s>%s</code></pre>"
3471 lang
3472 label
3473 (if (string= lang "html")
3474 " data-editor-type=\"html\""
3476 code)
3477 (format "<pre class=\"src src-%s\"%s>%s</pre>"
3478 lang label code)))))))
3480 ;;;; Statistics Cookie
3482 (defun org-html-statistics-cookie (statistics-cookie _contents _info)
3483 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3484 CONTENTS is nil. INFO is a plist holding contextual information."
3485 (let ((cookie-value (org-element-property :value statistics-cookie)))
3486 (format "<code>%s</code>" cookie-value)))
3488 ;;;; Strike-Through
3490 (defun org-html-strike-through (_strike-through contents info)
3491 "Transcode STRIKE-THROUGH from Org to HTML.
3492 CONTENTS is the text with strike-through markup. INFO is a plist
3493 holding contextual information."
3494 (format
3495 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3496 "%s")
3497 contents))
3499 ;;;; Subscript
3501 (defun org-html-subscript (_subscript contents _info)
3502 "Transcode a SUBSCRIPT object from Org to HTML.
3503 CONTENTS is the contents of the object. INFO is a plist holding
3504 contextual information."
3505 (format "<sub>%s</sub>" contents))
3507 ;;;; Superscript
3509 (defun org-html-superscript (_superscript contents _info)
3510 "Transcode a SUPERSCRIPT object from Org to HTML.
3511 CONTENTS is the contents of the object. INFO is a plist holding
3512 contextual information."
3513 (format "<sup>%s</sup>" contents))
3515 ;;;; Table Cell
3517 (defun org-html-table-cell (table-cell contents info)
3518 "Transcode a TABLE-CELL element from Org to HTML.
3519 CONTENTS is nil. INFO is a plist used as a communication
3520 channel."
3521 (let* ((table-row (org-export-get-parent table-cell))
3522 (table (org-export-get-parent-table table-cell))
3523 (cell-attrs
3524 (if (not (plist-get info :html-table-align-individual-fields)) ""
3525 (format (if (and (boundp 'org-html-format-table-no-css)
3526 org-html-format-table-no-css)
3527 " align=\"%s\"" " class=\"org-%s\"")
3528 (org-export-table-cell-alignment table-cell info)))))
3529 (when (or (not contents) (string= "" (org-trim contents)))
3530 (setq contents "&#xa0;"))
3531 (cond
3532 ((and (org-export-table-has-header-p table info)
3533 (= 1 (org-export-table-row-group table-row info)))
3534 (let ((header-tags (plist-get info :html-table-header-tags)))
3535 (concat "\n" (format (car header-tags) "col" cell-attrs)
3536 contents
3537 (cdr header-tags))))
3538 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3539 (zerop (cdr (org-export-table-cell-address table-cell info))))
3540 (let ((header-tags (plist-get info :html-table-header-tags)))
3541 (concat "\n" (format (car header-tags) "row" cell-attrs)
3542 contents
3543 (cdr header-tags))))
3544 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3545 (concat "\n" (format (car data-tags) cell-attrs)
3546 contents
3547 (cdr data-tags)))))))
3549 ;;;; Table Row
3551 (defun org-html-table-row (table-row contents info)
3552 "Transcode a TABLE-ROW element from Org to HTML.
3553 CONTENTS is the contents of the row. INFO is a plist used as a
3554 communication channel."
3555 ;; Rules are ignored since table separators are deduced from
3556 ;; borders of the current row.
3557 (when (eq (org-element-property :type table-row) 'standard)
3558 (let* ((group (org-export-table-row-group table-row info))
3559 (number (org-export-table-row-number table-row info))
3560 (start-group-p
3561 (org-export-table-row-starts-rowgroup-p table-row info))
3562 (end-group-p
3563 (org-export-table-row-ends-rowgroup-p table-row info))
3564 (topp (and (equal start-group-p '(top))
3565 (equal end-group-p '(below top))))
3566 (bottomp (and (equal start-group-p '(above))
3567 (equal end-group-p '(bottom above))))
3568 (row-open-tag
3569 (pcase (plist-get info :html-table-row-open-tag)
3570 ((and accessor (pred functionp))
3571 (funcall accessor
3572 number group start-group-p end-group-p topp bottomp))
3573 (accessor accessor)))
3574 (row-close-tag
3575 (pcase (plist-get info :html-table-row-close-tag)
3576 ((and accessor (pred functionp))
3577 (funcall accessor
3578 number group start-group-p end-group-p topp bottomp))
3579 (accessor accessor)))
3580 (group-tags
3581 (cond
3582 ;; Row belongs to second or subsequent groups.
3583 ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
3584 ;; Row is from first group. Table has >=1 groups.
3585 ((org-export-table-has-header-p
3586 (org-export-get-parent-table table-row) info)
3587 '("<thead>" . "\n</thead>"))
3588 ;; Row is from first and only group.
3589 (t '("<tbody>" . "\n</tbody>")))))
3590 (concat (and start-group-p (car group-tags))
3591 (concat "\n"
3592 row-open-tag
3593 contents
3594 "\n"
3595 row-close-tag)
3596 (and end-group-p (cdr group-tags))))))
3598 ;;;; Table
3600 (defun org-html-table-first-row-data-cells (table info)
3601 "Transcode the first row of TABLE.
3602 INFO is a plist used as a communication channel."
3603 (let ((table-row
3604 (org-element-map table 'table-row
3605 (lambda (row)
3606 (unless (eq (org-element-property :type row) 'rule) row))
3607 info 'first-match))
3608 (special-column-p (org-export-table-has-special-column-p table)))
3609 (if (not special-column-p) (org-element-contents table-row)
3610 (cdr (org-element-contents table-row)))))
3612 (defun org-html-table--table.el-table (table _info)
3613 "Format table.el tables into HTML.
3614 INFO is a plist used as a communication channel."
3615 (when (eq (org-element-property :type table) 'table.el)
3616 (require 'table)
3617 (let ((outbuf (with-current-buffer
3618 (get-buffer-create "*org-export-table*")
3619 (erase-buffer) (current-buffer))))
3620 (with-temp-buffer
3621 (insert (org-element-property :value table))
3622 (goto-char 1)
3623 (re-search-forward "^[ \t]*|[^|]" nil t)
3624 (table-generate-source 'html outbuf))
3625 (with-current-buffer outbuf
3626 (prog1 (org-trim (buffer-string))
3627 (kill-buffer) )))))
3629 (defun org-html-table (table contents info)
3630 "Transcode a TABLE element from Org to HTML.
3631 CONTENTS is the contents of the table. INFO is a plist holding
3632 contextual information."
3633 (if (eq (org-element-property :type table) 'table.el)
3634 ;; "table.el" table. Convert it using appropriate tools.
3635 (org-html-table--table.el-table table info)
3636 ;; Standard table.
3637 (let* ((caption (org-export-get-caption table))
3638 (number (org-export-get-ordinal
3639 table info nil #'org-html--has-caption-p))
3640 (attributes
3641 (org-html--make-attribute-string
3642 (org-combine-plists
3643 (and (org-element-property :name table)
3644 (list :id (org-export-get-reference table info)))
3645 (and (not (org-html-html5-p info))
3646 (plist-get info :html-table-attributes))
3647 (org-export-read-attribute :attr_html table))))
3648 (alignspec
3649 (if (bound-and-true-p org-html-format-table-no-css)
3650 "align=\"%s\""
3651 "class=\"org-%s\""))
3652 (table-column-specs
3653 (lambda (table info)
3654 (mapconcat
3655 (lambda (table-cell)
3656 (let ((alignment (org-export-table-cell-alignment
3657 table-cell info)))
3658 (concat
3659 ;; Begin a colgroup?
3660 (when (org-export-table-cell-starts-colgroup-p
3661 table-cell info)
3662 "\n<colgroup>")
3663 ;; Add a column. Also specify its alignment.
3664 (format "\n%s"
3665 (org-html-close-tag
3666 "col" (concat " " (format alignspec alignment)) info))
3667 ;; End a colgroup?
3668 (when (org-export-table-cell-ends-colgroup-p
3669 table-cell info)
3670 "\n</colgroup>"))))
3671 (org-html-table-first-row-data-cells table info) "\n"))))
3672 (format "<table%s>\n%s\n%s\n%s</table>"
3673 (if (equal attributes "") "" (concat " " attributes))
3674 (if (not caption) ""
3675 (format (if (plist-get info :html-table-caption-above)
3676 "<caption class=\"t-above\">%s</caption>"
3677 "<caption class=\"t-bottom\">%s</caption>")
3678 (concat
3679 "<span class=\"table-number\">"
3680 (format (org-html--translate "Table %d:" info) number)
3681 "</span> " (org-export-data caption info))))
3682 (funcall table-column-specs table info)
3683 contents))))
3685 ;;;; Target
3687 (defun org-html-target (target _contents info)
3688 "Transcode a TARGET object from Org to HTML.
3689 CONTENTS is nil. INFO is a plist holding contextual
3690 information."
3691 (let ((ref (org-export-get-reference target info)))
3692 (org-html--anchor ref nil nil info)))
3694 ;;;; Timestamp
3696 (defun org-html-timestamp (timestamp _contents info)
3697 "Transcode a TIMESTAMP object from Org to HTML.
3698 CONTENTS is nil. INFO is a plist holding contextual
3699 information."
3700 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3701 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3702 (replace-regexp-in-string "--" "&#x2013;" value))))
3704 ;;;; Underline
3706 (defun org-html-underline (_underline contents info)
3707 "Transcode UNDERLINE from Org to HTML.
3708 CONTENTS is the text with underline markup. INFO is a plist
3709 holding contextual information."
3710 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3711 "%s")
3712 contents))
3714 ;;;; Verbatim
3716 (defun org-html-verbatim (verbatim _contents info)
3717 "Transcode VERBATIM from Org to HTML.
3718 CONTENTS is nil. INFO is a plist holding contextual
3719 information."
3720 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3721 (org-html-encode-plain-text (org-element-property :value verbatim))))
3723 ;;;; Verse Block
3725 (defun org-html-verse-block (_verse-block contents info)
3726 "Transcode a VERSE-BLOCK element from Org to HTML.
3727 CONTENTS is verse block contents. INFO is a plist holding
3728 contextual information."
3729 (format "<p class=\"verse\">\n%s</p>"
3730 ;; Replace leading white spaces with non-breaking spaces.
3731 (replace-regexp-in-string
3732 "^[ \t]+" (lambda (m) (org-html--make-string (length m) "&#xa0;"))
3733 ;; Replace each newline character with line break. Also
3734 ;; remove any trailing "br" close-tag so as to avoid
3735 ;; duplicates.
3736 (let* ((br (org-html-close-tag "br" nil info))
3737 (re (format "\\(?:%s\\)?[ \t]*\n" (regexp-quote br))))
3738 (replace-regexp-in-string re (concat br "\n") contents)))))
3741 ;;; Filter Functions
3743 (defun org-html-final-function (contents _backend info)
3744 "Filter to indent the HTML and convert HTML entities."
3745 (with-temp-buffer
3746 (insert contents)
3747 (set-auto-mode t)
3748 (when (plist-get info :html-indent)
3749 (indent-region (point-min) (point-max)))
3750 (buffer-substring-no-properties (point-min) (point-max))))
3753 ;;; End-user functions
3755 ;;;###autoload
3756 (defun org-html-export-as-html
3757 (&optional async subtreep visible-only body-only ext-plist)
3758 "Export current buffer to an HTML buffer.
3760 If narrowing is active in the current buffer, only export its
3761 narrowed part.
3763 If a region is active, export that region.
3765 A non-nil optional argument ASYNC means the process should happen
3766 asynchronously. The resulting buffer should be accessible
3767 through the `org-export-stack' interface.
3769 When optional argument SUBTREEP is non-nil, export the sub-tree
3770 at point, extracting information from the headline properties
3771 first.
3773 When optional argument VISIBLE-ONLY is non-nil, don't export
3774 contents of hidden elements.
3776 When optional argument BODY-ONLY is non-nil, only write code
3777 between \"<body>\" and \"</body>\" tags.
3779 EXT-PLIST, when provided, is a property list with external
3780 parameters overriding Org default settings, but still inferior to
3781 file-local settings.
3783 Export is done in a buffer named \"*Org HTML Export*\", which
3784 will be displayed when `org-export-show-temporary-export-buffer'
3785 is non-nil."
3786 (interactive)
3787 (org-export-to-buffer 'html "*Org HTML Export*"
3788 async subtreep visible-only body-only ext-plist
3789 (lambda () (set-auto-mode t))))
3791 ;;;###autoload
3792 (defun org-html-convert-region-to-html ()
3793 "Assume the current region has Org syntax, and convert it to HTML.
3794 This can be used in any buffer. For example, you can write an
3795 itemized list in Org syntax in an HTML buffer and use this command
3796 to convert it."
3797 (interactive)
3798 (org-export-replace-region-by 'html))
3800 ;;;###autoload
3801 (defun org-html-export-to-html
3802 (&optional async subtreep visible-only body-only ext-plist)
3803 "Export current buffer to a HTML file.
3805 If narrowing is active in the current buffer, only export its
3806 narrowed part.
3808 If a region is active, export that region.
3810 A non-nil optional argument ASYNC means the process should happen
3811 asynchronously. The resulting file should be accessible through
3812 the `org-export-stack' interface.
3814 When optional argument SUBTREEP is non-nil, export the sub-tree
3815 at point, extracting information from the headline properties
3816 first.
3818 When optional argument VISIBLE-ONLY is non-nil, don't export
3819 contents of hidden elements.
3821 When optional argument BODY-ONLY is non-nil, only write code
3822 between \"<body>\" and \"</body>\" tags.
3824 EXT-PLIST, when provided, is a property list with external
3825 parameters overriding Org default settings, but still inferior to
3826 file-local settings.
3828 Return output file's name."
3829 (interactive)
3830 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3831 org-html-extension
3832 "html")))
3833 (file (org-export-output-file-name extension subtreep))
3834 (org-export-coding-system org-html-coding-system))
3835 (org-export-to-file 'html file
3836 async subtreep visible-only body-only ext-plist)))
3838 ;;;###autoload
3839 (defun org-html-publish-to-html (plist filename pub-dir)
3840 "Publish an org file to HTML.
3842 FILENAME is the filename of the Org file to be published. PLIST
3843 is the property list for the given project. PUB-DIR is the
3844 publishing directory.
3846 Return output file name."
3847 (org-publish-org-to 'html filename
3848 (concat "." (or (plist-get plist :html-extension)
3849 org-html-extension
3850 "html"))
3851 plist pub-dir))
3854 (provide 'ox-html)
3856 ;; Local variables:
3857 ;; generated-autoload-file: "org-loaddefs.el"
3858 ;; End:
3860 ;;; ox-html.el ends here