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