manual: Fix compilation error
[org-mode/org-tableheadings.git] / lisp / ox-html.el
blobe1606c4f3f08acaa833cb27d3cf1cebc053939e4
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" "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 (if (re-search-forward "<style" nil t)
1768 (delete-region (point-min) (match-beginning 0)))
1769 (if (re-search-forward "</style>" nil t)
1770 (delete-region (1+ (match-end 0)) (point-max)))
1771 (beginning-of-line 1)
1772 (if (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))))
1997 (t (format-spec
1998 (or (cadr (assoc-string
1999 (plist-get info :language)
2000 (eval (intern
2001 (format "org-html-%s-format" type)))
2003 (cadr
2004 (assoc-string
2005 "en"
2006 (eval
2007 (intern (format "org-html-%s-format" type)))
2008 t)))
2009 spec))))))
2010 (let ((div (assq type (plist-get info :html-divs))))
2011 (when (org-string-nw-p section-contents)
2012 (concat
2013 (format "<%s id=\"%s\" class=\"%s\">\n"
2014 (nth 1 div)
2015 (nth 2 div)
2016 org-html--pre/postamble-class)
2017 (org-element-normalize-string section-contents)
2018 (format "</%s>\n" (nth 1 div)))))))))
2020 (defun org-html-inner-template (contents info)
2021 "Return body of document string after HTML conversion.
2022 CONTENTS is the transcoded contents string. INFO is a plist
2023 holding export options."
2024 (concat
2025 ;; Table of contents.
2026 (let ((depth (plist-get info :with-toc)))
2027 (when depth (org-html-toc depth info)))
2028 ;; Document contents.
2029 contents
2030 ;; Footnotes section.
2031 (org-html-footnote-section info)))
2033 (defun org-html-template (contents info)
2034 "Return complete document string after HTML conversion.
2035 CONTENTS is the transcoded contents string. INFO is a plist
2036 holding export options."
2037 (concat
2038 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
2039 (let* ((xml-declaration (plist-get info :html-xml-declaration))
2040 (decl (or (and (stringp xml-declaration) xml-declaration)
2041 (cdr (assoc (plist-get info :html-extension)
2042 xml-declaration))
2043 (cdr (assoc "html" xml-declaration))
2044 "")))
2045 (when (not (or (not decl) (string= "" decl)))
2046 (format "%s\n"
2047 (format decl
2048 (or (and org-html-coding-system
2049 (fboundp 'coding-system-get)
2050 (coding-system-get org-html-coding-system 'mime-charset))
2051 "iso-8859-1"))))))
2052 (org-html-doctype info)
2053 "\n"
2054 (concat "<html"
2055 (cond ((org-html-xhtml-p info)
2056 (format
2057 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
2058 (plist-get info :language) (plist-get info :language)))
2059 ((org-html-html5-p info)
2060 (format " lang=\"%s\"" (plist-get info :language))))
2061 ">\n")
2062 "<head>\n"
2063 (org-html--build-meta-info info)
2064 (org-html--build-head info)
2065 (org-html--build-mathjax-config info)
2066 "</head>\n"
2067 "<body>\n"
2068 (let ((link-up (org-trim (plist-get info :html-link-up)))
2069 (link-home (org-trim (plist-get info :html-link-home))))
2070 (unless (and (string= link-up "") (string= link-home ""))
2071 (format (plist-get info :html-home/up-format)
2072 (or link-up link-home)
2073 (or link-home link-up))))
2074 ;; Preamble.
2075 (org-html--build-pre/postamble 'preamble info)
2076 ;; Document contents.
2077 (let ((div (assq 'content (plist-get info :html-divs))))
2078 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
2079 ;; Document title.
2080 (when (plist-get info :with-title)
2081 (let ((title (and (plist-get info :with-title)
2082 (plist-get info :title)))
2083 (subtitle (plist-get info :subtitle))
2084 (html5-fancy (org-html--html5-fancy-p info)))
2085 (when title
2086 (format
2087 (if html5-fancy
2088 "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
2089 "<h1 class=\"title\">%s%s</h1>\n")
2090 (org-export-data title info)
2091 (if subtitle
2092 (format
2093 (if html5-fancy
2094 "<p class=\"subtitle\">%s</p>\n"
2095 (concat "\n" (org-html-close-tag "br" nil info) "\n"
2096 "<span class=\"subtitle\">%s</span>\n"))
2097 (org-export-data subtitle info))
2098 "")))))
2099 contents
2100 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
2101 ;; Postamble.
2102 (org-html--build-pre/postamble 'postamble info)
2103 ;; Possibly use the Klipse library live code blocks.
2104 (if (plist-get info :html-klipsify-src)
2105 (concat "<script>" (plist-get info :html-klipse-selection-script)
2106 "</script><script src=\""
2107 org-html-klipse-js
2108 "\"></script><link rel=\"stylesheet\" type=\"text/css\" href=\""
2109 org-html-klipse-css "\"/>"))
2110 ;; Closing document.
2111 "</body>\n</html>"))
2113 (defun org-html--translate (s info)
2114 "Translate string S according to specified language.
2115 INFO is a plist used as a communication channel."
2116 (org-export-translate s :html info))
2118 ;;;; Anchor
2120 (defun org-html--anchor (id desc attributes info)
2121 "Format a HTML anchor."
2122 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
2123 (attributes (concat (and id (format " id=\"%s\"" id))
2124 (and name (format " name=\"%s\"" name))
2125 attributes)))
2126 (format "<a%s>%s</a>" attributes (or desc ""))))
2128 ;;;; Todo
2130 (defun org-html--todo (todo info)
2131 "Format TODO keywords into HTML."
2132 (when todo
2133 (format "<span class=\"%s %s%s\">%s</span>"
2134 (if (member todo org-done-keywords) "done" "todo")
2135 (or (plist-get info :html-todo-kwd-class-prefix) "")
2136 (org-html-fix-class-name todo)
2137 todo)))
2139 ;;;; Priority
2141 (defun org-html--priority (priority _info)
2142 "Format a priority into HTML.
2143 PRIORITY is the character code of the priority or nil. INFO is
2144 a plist containing export options."
2145 (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
2147 ;;;; Tags
2149 (defun org-html--tags (tags info)
2150 "Format TAGS into HTML.
2151 INFO is a plist containing export options."
2152 (when tags
2153 (format "<span class=\"tag\">%s</span>"
2154 (mapconcat
2155 (lambda (tag)
2156 (format "<span class=\"%s\">%s</span>"
2157 (concat (plist-get info :html-tag-class-prefix)
2158 (org-html-fix-class-name tag))
2159 tag))
2160 tags "&#xa0;"))))
2162 ;;;; Src Code
2164 (defun org-html-fontify-code (code lang)
2165 "Color CODE with htmlize library.
2166 CODE is a string representing the source code to colorize. LANG
2167 is the language used for CODE, as a string, or nil."
2168 (when code
2169 (cond
2170 ;; No language. Possibly an example block.
2171 ((not lang) (org-html-encode-plain-text code))
2172 ;; Plain text explicitly set.
2173 ((not org-html-htmlize-output-type) (org-html-encode-plain-text code))
2174 ;; No htmlize library or an inferior version of htmlize.
2175 ((not (and (or (require 'htmlize nil t)
2176 (error "Please install htmlize from \
2177 https://github.com/hniksic/emacs-htmlize"))
2178 (fboundp 'htmlize-region-for-paste)))
2179 ;; Emit a warning.
2180 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
2181 (org-html-encode-plain-text code))
2183 ;; Map language
2184 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
2185 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
2186 (cond
2187 ;; Case 1: Language is not associated with any Emacs mode
2188 ((not (functionp lang-mode))
2189 (org-html-encode-plain-text code))
2190 ;; Case 2: Default. Fontify code.
2192 ;; htmlize
2193 (setq code
2194 (let ((output-type org-html-htmlize-output-type)
2195 (font-prefix org-html-htmlize-font-prefix))
2196 (with-temp-buffer
2197 ;; Switch to language-specific mode.
2198 (funcall lang-mode)
2199 (insert code)
2200 ;; Fontify buffer.
2201 (org-font-lock-ensure)
2202 ;; Remove formatting on newline characters.
2203 (save-excursion
2204 (let ((beg (point-min))
2205 (end (point-max)))
2206 (goto-char beg)
2207 (while (progn (end-of-line) (< (point) end))
2208 (put-text-property (point) (1+ (point)) 'face nil)
2209 (forward-char 1))))
2210 (org-src-mode)
2211 (set-buffer-modified-p nil)
2212 ;; Htmlize region.
2213 (let ((org-html-htmlize-output-type output-type)
2214 (org-html-htmlize-font-prefix font-prefix))
2215 (org-html-htmlize-region-for-paste
2216 (point-min) (point-max))))))
2217 ;; Strip any enclosing <pre></pre> tags.
2218 (let* ((beg (and (string-match "\\`<pre[^>]*>\n?" code) (match-end 0)))
2219 (end (and beg (string-match "</pre>\\'" code))))
2220 (if (and beg end) (substring code beg end) code)))))))))
2222 (defun org-html-do-format-code
2223 (code &optional lang refs retain-labels num-start)
2224 "Format CODE string as source code.
2225 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
2226 respectively, the language of the source code, as a string, an
2227 alist between line numbers and references (as returned by
2228 `org-export-unravel-code'), a boolean specifying if labels should
2229 appear in the source code, and the number associated to the first
2230 line of code."
2231 (let* ((code-lines (split-string code "\n"))
2232 (code-length (length code-lines))
2233 (num-fmt
2234 (and num-start
2235 (format "%%%ds: "
2236 (length (number-to-string (+ code-length num-start))))))
2237 (code (org-html-fontify-code code lang)))
2238 (org-export-format-code
2239 code
2240 (lambda (loc line-num ref)
2241 (setq loc
2242 (concat
2243 ;; Add line number, if needed.
2244 (when num-start
2245 (format "<span class=\"linenr\">%s</span>"
2246 (format num-fmt line-num)))
2247 ;; Transcoded src line.
2249 ;; Add label, if needed.
2250 (when (and ref retain-labels) (format " (%s)" ref))))
2251 ;; Mark transcoded line as an anchor, if needed.
2252 (if (not ref) loc
2253 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2254 ref loc)))
2255 num-start refs)))
2257 (defun org-html-format-code (element info)
2258 "Format contents of ELEMENT as source code.
2259 ELEMENT is either an example block or a src block. INFO is
2260 a plist used as a communication channel."
2261 (let* ((lang (org-element-property :language element))
2262 ;; Extract code and references.
2263 (code-info (org-export-unravel-code element))
2264 (code (car code-info))
2265 (refs (cdr code-info))
2266 ;; Does the src block contain labels?
2267 (retain-labels (org-element-property :retain-labels element))
2268 ;; Does it have line numbers?
2269 (num-start (org-export-get-loc element info)))
2270 (org-html-do-format-code code lang refs retain-labels num-start)))
2273 ;;; Tables of Contents
2275 (defun org-html-toc (depth info &optional scope)
2276 "Build a table of contents.
2277 DEPTH is an integer specifying the depth of the table. INFO is
2278 a plist used as a communication channel. Optional argument SCOPE
2279 is an element defining the scope of the table. Return the table
2280 of contents as a string, or nil if it is empty."
2281 (let ((toc-entries
2282 (mapcar (lambda (headline)
2283 (cons (org-html--format-toc-headline headline info)
2284 (org-export-get-relative-level headline info)))
2285 (org-export-collect-headlines info depth scope))))
2286 (when toc-entries
2287 (let ((toc (concat "<div id=\"text-table-of-contents\">"
2288 (org-html--toc-text toc-entries)
2289 "</div>\n")))
2290 (if scope toc
2291 (let ((outer-tag (if (org-html--html5-fancy-p info)
2292 "nav"
2293 "div")))
2294 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2295 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2296 (format "<h%d>%s</h%d>\n"
2297 top-level
2298 (org-html--translate "Table of Contents" info)
2299 top-level))
2301 (format "</%s>\n" outer-tag))))))))
2303 (defun org-html--toc-text (toc-entries)
2304 "Return innards of a table of contents, as a string.
2305 TOC-ENTRIES is an alist where key is an entry title, as a string,
2306 and value is its relative level, as an integer."
2307 (let* ((prev-level (1- (cdar toc-entries)))
2308 (start-level prev-level))
2309 (concat
2310 (mapconcat
2311 (lambda (entry)
2312 (let ((headline (car entry))
2313 (level (cdr entry)))
2314 (concat
2315 (let* ((cnt (- level prev-level))
2316 (times (if (> cnt 0) (1- cnt) (- cnt))))
2317 (setq prev-level level)
2318 (concat
2319 (org-html--make-string
2320 times (cond ((> cnt 0) "\n<ul>\n<li>")
2321 ((< cnt 0) "</li>\n</ul>\n")))
2322 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2323 headline)))
2324 toc-entries "")
2325 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2327 (defun org-html--format-toc-headline (headline info)
2328 "Return an appropriate table of contents entry for HEADLINE.
2329 INFO is a plist used as a communication channel."
2330 (let* ((headline-number (org-export-get-headline-number headline info))
2331 (todo (and (plist-get info :with-todo-keywords)
2332 (let ((todo (org-element-property :todo-keyword headline)))
2333 (and todo (org-export-data todo info)))))
2334 (todo-type (and todo (org-element-property :todo-type headline)))
2335 (priority (and (plist-get info :with-priority)
2336 (org-element-property :priority headline)))
2337 (text (org-export-data-with-backend
2338 (org-export-get-alt-title headline info)
2339 (org-export-toc-entry-backend 'html)
2340 info))
2341 (tags (and (eq (plist-get info :with-tags) t)
2342 (org-export-get-tags headline info))))
2343 (format "<a href=\"#%s\">%s</a>"
2344 ;; Label.
2345 (or (org-element-property :CUSTOM_ID headline)
2346 (org-export-get-reference headline info))
2347 ;; Body.
2348 (concat
2349 (and (not (org-export-low-level-p headline info))
2350 (org-export-numbered-headline-p headline info)
2351 (concat (mapconcat #'number-to-string headline-number ".")
2352 ". "))
2353 (apply (plist-get info :html-format-headline-function)
2354 todo todo-type priority text tags :section-number nil)))))
2356 (defun org-html-list-of-listings (info)
2357 "Build a list of listings.
2358 INFO is a plist used as a communication channel. Return the list
2359 of listings as a string, or nil if it is empty."
2360 (let ((lol-entries (org-export-collect-listings info)))
2361 (when lol-entries
2362 (concat "<div id=\"list-of-listings\">\n"
2363 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2364 (format "<h%d>%s</h%d>\n"
2365 top-level
2366 (org-html--translate "List of Listings" info)
2367 top-level))
2368 "<div id=\"text-list-of-listings\">\n<ul>\n"
2369 (let ((count 0)
2370 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2371 (org-html--translate "Listing %d:" info))))
2372 (mapconcat
2373 (lambda (entry)
2374 (let ((label (and (org-element-property :name entry)
2375 (org-export-get-reference entry info)))
2376 (title (org-trim
2377 (org-export-data
2378 (or (org-export-get-caption entry t)
2379 (org-export-get-caption entry))
2380 info))))
2381 (concat
2382 "<li>"
2383 (if (not label)
2384 (concat (format initial-fmt (cl-incf count))
2386 title)
2387 (format "<a href=\"#%s\">%s %s</a>"
2388 label
2389 (format initial-fmt (cl-incf count))
2390 title))
2391 "</li>")))
2392 lol-entries "\n"))
2393 "\n</ul>\n</div>\n</div>"))))
2395 (defun org-html-list-of-tables (info)
2396 "Build a list of tables.
2397 INFO is a plist used as a communication channel. Return the list
2398 of tables as a string, or nil if it is empty."
2399 (let ((lol-entries (org-export-collect-tables info)))
2400 (when lol-entries
2401 (concat "<div id=\"list-of-tables\">\n"
2402 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2403 (format "<h%d>%s</h%d>\n"
2404 top-level
2405 (org-html--translate "List of Tables" info)
2406 top-level))
2407 "<div id=\"text-list-of-tables\">\n<ul>\n"
2408 (let ((count 0)
2409 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2410 (org-html--translate "Table %d:" info))))
2411 (mapconcat
2412 (lambda (entry)
2413 (let ((label (and (org-element-property :name entry)
2414 (org-export-get-reference entry info)))
2415 (title (org-trim
2416 (org-export-data
2417 (or (org-export-get-caption entry t)
2418 (org-export-get-caption entry))
2419 info))))
2420 (concat
2421 "<li>"
2422 (if (not label)
2423 (concat (format initial-fmt (cl-incf count))
2425 title)
2426 (format "<a href=\"#%s\">%s %s</a>"
2427 label
2428 (format initial-fmt (cl-incf count))
2429 title))
2430 "</li>")))
2431 lol-entries "\n"))
2432 "\n</ul>\n</div>\n</div>"))))
2435 ;;; Transcode Functions
2437 ;;;; Bold
2439 (defun org-html-bold (_bold contents info)
2440 "Transcode BOLD from Org to HTML.
2441 CONTENTS is the text with bold markup. INFO is a plist holding
2442 contextual information."
2443 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2444 contents))
2446 ;;;; Center Block
2448 (defun org-html-center-block (_center-block contents _info)
2449 "Transcode a CENTER-BLOCK element from Org to HTML.
2450 CONTENTS holds the contents of the block. INFO is a plist
2451 holding contextual information."
2452 (format "<div class=\"org-center\">\n%s</div>" contents))
2454 ;;;; Clock
2456 (defun org-html-clock (clock _contents _info)
2457 "Transcode a CLOCK element from Org to HTML.
2458 CONTENTS is nil. INFO is a plist used as a communication
2459 channel."
2460 (format "<p>
2461 <span class=\"timestamp-wrapper\">
2462 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2463 </span>
2464 </p>"
2465 org-clock-string
2466 (org-timestamp-translate (org-element-property :value clock))
2467 (let ((time (org-element-property :duration clock)))
2468 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2470 ;;;; Code
2472 (defun org-html-code (code _contents info)
2473 "Transcode CODE from Org to HTML.
2474 CONTENTS is nil. INFO is a plist holding contextual
2475 information."
2476 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2477 (org-html-encode-plain-text (org-element-property :value code))))
2479 ;;;; Drawer
2481 (defun org-html-drawer (drawer contents info)
2482 "Transcode a DRAWER element from Org to HTML.
2483 CONTENTS holds the contents of the block. INFO is a plist
2484 holding contextual information."
2485 (funcall (plist-get info :html-format-drawer-function)
2486 (org-element-property :drawer-name drawer)
2487 contents))
2489 ;;;; Dynamic Block
2491 (defun org-html-dynamic-block (_dynamic-block contents _info)
2492 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2493 CONTENTS holds the contents of the block. INFO is a plist
2494 holding contextual information. See `org-export-data'."
2495 contents)
2497 ;;;; Entity
2499 (defun org-html-entity (entity _contents _info)
2500 "Transcode an ENTITY object from Org to HTML.
2501 CONTENTS are the definition itself. INFO is a plist holding
2502 contextual information."
2503 (org-element-property :html entity))
2505 ;;;; Example Block
2507 (defun org-html-example-block (example-block _contents info)
2508 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2509 CONTENTS is nil. INFO is a plist holding contextual
2510 information."
2511 (let ((attributes (org-export-read-attribute :attr_html example-block)))
2512 (if (plist-get attributes :textarea)
2513 (org-html--textarea-block example-block)
2514 (format "<pre class=\"example\"%s>\n%s</pre>"
2515 (let* ((name (org-element-property :name example-block))
2516 (a (org-html--make-attribute-string
2517 (if (or (not name) (plist-member attributes :id))
2518 attributes
2519 (plist-put attributes :id name)))))
2520 (if (org-string-nw-p a) (concat " " a) ""))
2521 (org-html-format-code example-block info)))))
2523 ;;;; Export Snippet
2525 (defun org-html-export-snippet (export-snippet _contents _info)
2526 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2527 CONTENTS is nil. INFO is a plist holding contextual
2528 information."
2529 (when (eq (org-export-snippet-backend export-snippet) 'html)
2530 (org-element-property :value export-snippet)))
2532 ;;;; Export Block
2534 (defun org-html-export-block (export-block _contents _info)
2535 "Transcode a EXPORT-BLOCK element from Org to HTML.
2536 CONTENTS is nil. INFO is a plist holding contextual information."
2537 (when (string= (org-element-property :type export-block) "HTML")
2538 (org-remove-indentation (org-element-property :value export-block))))
2540 ;;;; Fixed Width
2542 (defun org-html-fixed-width (fixed-width _contents _info)
2543 "Transcode a FIXED-WIDTH element from Org to HTML.
2544 CONTENTS is nil. INFO is a plist holding contextual information."
2545 (format "<pre class=\"example\">\n%s</pre>"
2546 (org-html-do-format-code
2547 (org-remove-indentation
2548 (org-element-property :value fixed-width)))))
2550 ;;;; Footnote Reference
2552 (defun org-html-footnote-reference (footnote-reference _contents info)
2553 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2554 CONTENTS is nil. INFO is a plist holding contextual information."
2555 (concat
2556 ;; Insert separator between two footnotes in a row.
2557 (let ((prev (org-export-get-previous-element footnote-reference info)))
2558 (when (eq (org-element-type prev) 'footnote-reference)
2559 (plist-get info :html-footnote-separator)))
2560 (let* ((n (org-export-get-footnote-number footnote-reference info))
2561 (id (format "fnr.%d%s"
2563 (if (org-export-footnote-first-reference-p
2564 footnote-reference info)
2566 ".100"))))
2567 (format
2568 (plist-get info :html-footnote-format)
2569 (org-html--anchor
2570 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2572 ;;;; Headline
2574 (defun org-html-headline (headline contents info)
2575 "Transcode a HEADLINE element from Org to HTML.
2576 CONTENTS holds the contents of the headline. INFO is a plist
2577 holding contextual information."
2578 (unless (org-element-property :footnote-section-p headline)
2579 (let* ((numberedp (org-export-numbered-headline-p headline info))
2580 (numbers (org-export-get-headline-number headline info))
2581 (level (+ (org-export-get-relative-level headline info)
2582 (1- (plist-get info :html-toplevel-hlevel))))
2583 (todo (and (plist-get info :with-todo-keywords)
2584 (let ((todo (org-element-property :todo-keyword headline)))
2585 (and todo (org-export-data todo info)))))
2586 (todo-type (and todo (org-element-property :todo-type headline)))
2587 (priority (and (plist-get info :with-priority)
2588 (org-element-property :priority headline)))
2589 (text (org-export-data (org-element-property :title headline) info))
2590 (tags (and (plist-get info :with-tags)
2591 (org-export-get-tags headline info)))
2592 (full-text (funcall (plist-get info :html-format-headline-function)
2593 todo todo-type priority text tags info))
2594 (contents (or contents ""))
2595 (id (or (org-element-property :CUSTOM_ID headline)
2596 (org-export-get-reference headline info))))
2597 (if (org-export-low-level-p headline info)
2598 ;; This is a deep sub-tree: export it as a list item.
2599 (let* ((html-type (if numberedp "ol" "ul")))
2600 (concat
2601 (and (org-export-first-sibling-p headline info)
2602 (apply #'format "<%s class=\"org-%s\">\n"
2603 (make-list 2 html-type)))
2604 (org-html-format-list-item
2605 contents (if numberedp 'ordered 'unordered)
2606 nil info nil
2607 (concat (org-html--anchor id nil nil info) full-text)) "\n"
2608 (and (org-export-last-sibling-p headline info)
2609 (format "</%s>\n" html-type))))
2610 ;; Standard headline. Export it as a section.
2611 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2612 (first-content (car (org-element-contents headline))))
2613 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2614 (org-html--container headline info)
2615 (concat "outline-container-"
2616 (org-export-get-reference headline info))
2617 (concat (format "outline-%d" level)
2618 (and extra-class " ")
2619 extra-class)
2620 (format "\n<h%d id=\"%s\">%s</h%d>\n"
2621 level
2623 (concat
2624 (and numberedp
2625 (format
2626 "<span class=\"section-number-%d\">%s</span> "
2627 level
2628 (mapconcat #'number-to-string numbers ".")))
2629 full-text)
2630 level)
2631 ;; When there is no section, pretend there is an
2632 ;; empty one to get the correct <div
2633 ;; class="outline-...> which is needed by
2634 ;; `org-info.js'.
2635 (if (eq (org-element-type first-content) 'section) contents
2636 (concat (org-html-section first-content "" info) contents))
2637 (org-html--container headline info)))))))
2639 (defun org-html-format-headline-default-function
2640 (todo _todo-type priority text tags info)
2641 "Default format function for a headline.
2642 See `org-html-format-headline-function' for details."
2643 (let ((todo (org-html--todo todo info))
2644 (priority (org-html--priority priority info))
2645 (tags (org-html--tags tags info)))
2646 (concat todo (and todo " ")
2647 priority (and priority " ")
2648 text
2649 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2651 (defun org-html--container (headline info)
2652 (or (org-element-property :HTML_CONTAINER headline)
2653 (if (= 1 (org-export-get-relative-level headline info))
2654 (plist-get info :html-container)
2655 "div")))
2657 ;;;; Horizontal Rule
2659 (defun org-html-horizontal-rule (_horizontal-rule _contents info)
2660 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2661 CONTENTS is nil. INFO is a plist holding contextual information."
2662 (org-html-close-tag "hr" nil info))
2664 ;;;; Inline Src Block
2666 (defun org-html-inline-src-block (inline-src-block _contents info)
2667 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2668 CONTENTS holds the contents of the item. INFO is a plist holding
2669 contextual information."
2670 (let* ((lang (org-element-property :language inline-src-block))
2671 (code (org-html-fontify-code
2672 (org-element-property :value inline-src-block)
2673 lang))
2674 (label
2675 (let ((lbl (and (org-element-property :name inline-src-block)
2676 (org-export-get-reference inline-src-block info))))
2677 (if (not lbl) "" (format " id=\"%s\"" lbl)))))
2678 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
2680 ;;;; Inlinetask
2682 (defun org-html-inlinetask (inlinetask contents info)
2683 "Transcode an INLINETASK element from Org to HTML.
2684 CONTENTS holds the contents of the block. INFO is a plist
2685 holding contextual information."
2686 (let* ((todo (and (plist-get info :with-todo-keywords)
2687 (let ((todo (org-element-property :todo-keyword inlinetask)))
2688 (and todo (org-export-data todo info)))))
2689 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2690 (priority (and (plist-get info :with-priority)
2691 (org-element-property :priority inlinetask)))
2692 (text (org-export-data (org-element-property :title inlinetask) info))
2693 (tags (and (plist-get info :with-tags)
2694 (org-export-get-tags inlinetask info))))
2695 (funcall (plist-get info :html-format-inlinetask-function)
2696 todo todo-type priority text tags contents info)))
2698 (defun org-html-format-inlinetask-default-function
2699 (todo todo-type priority text tags contents info)
2700 "Default format function for a inlinetasks.
2701 See `org-html-format-inlinetask-function' for details."
2702 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2703 (org-html-format-headline-default-function
2704 todo todo-type priority text tags info)
2705 (org-html-close-tag "br" nil info)
2706 contents))
2708 ;;;; Italic
2710 (defun org-html-italic (_italic contents info)
2711 "Transcode ITALIC from Org to HTML.
2712 CONTENTS is the text with italic markup. INFO is a plist holding
2713 contextual information."
2714 (format
2715 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2716 contents))
2718 ;;;; Item
2720 (defun org-html-checkbox (checkbox info)
2721 "Format CHECKBOX into HTML.
2722 INFO is a plist holding contextual information. See
2723 `org-html-checkbox-type' for customization options."
2724 (cdr (assq checkbox
2725 (cdr (assq (plist-get info :html-checkbox-type)
2726 org-html-checkbox-types)))))
2728 (defun org-html-format-list-item (contents type checkbox info
2729 &optional term-counter-id
2730 headline)
2731 "Format a list item into HTML."
2732 (let ((class (if checkbox
2733 (format " class=\"%s\""
2734 (symbol-name checkbox)) ""))
2735 (checkbox (concat (org-html-checkbox checkbox info)
2736 (and checkbox " ")))
2737 (br (org-html-close-tag "br" nil info))
2738 (extra-newline (if (and (org-string-nw-p contents) headline) "\n" "")))
2739 (concat
2740 (pcase type
2741 (`ordered
2742 (let* ((counter term-counter-id)
2743 (extra (if counter (format " value=\"%s\"" counter) "")))
2744 (concat
2745 (format "<li%s%s>" class extra)
2746 (when headline (concat headline br)))))
2747 (`unordered
2748 (let* ((id term-counter-id)
2749 (extra (if id (format " id=\"%s\"" id) "")))
2750 (concat
2751 (format "<li%s%s>" class extra)
2752 (when headline (concat headline br)))))
2753 (`descriptive
2754 (let* ((term term-counter-id))
2755 (setq term (or term "(no term)"))
2756 ;; Check-boxes in descriptive lists are associated to tag.
2757 (concat (format "<dt%s>%s</dt>"
2758 class (concat checkbox term))
2759 "<dd>"))))
2760 (unless (eq type 'descriptive) checkbox)
2761 extra-newline
2762 (and (org-string-nw-p contents) (org-trim contents))
2763 extra-newline
2764 (pcase type
2765 (`ordered "</li>")
2766 (`unordered "</li>")
2767 (`descriptive "</dd>")))))
2769 (defun org-html-item (item contents info)
2770 "Transcode an ITEM element from Org to HTML.
2771 CONTENTS holds the contents of the item. INFO is a plist holding
2772 contextual information."
2773 (let* ((plain-list (org-export-get-parent item))
2774 (type (org-element-property :type plain-list))
2775 (counter (org-element-property :counter item))
2776 (checkbox (org-element-property :checkbox item))
2777 (tag (let ((tag (org-element-property :tag item)))
2778 (and tag (org-export-data tag info)))))
2779 (org-html-format-list-item
2780 contents type checkbox info (or tag counter))))
2782 ;;;; Keyword
2784 (defun org-html-keyword (keyword _contents info)
2785 "Transcode a KEYWORD element from Org to HTML.
2786 CONTENTS is nil. INFO is a plist holding contextual information."
2787 (let ((key (org-element-property :key keyword))
2788 (value (org-element-property :value keyword)))
2789 (cond
2790 ((string= key "HTML") value)
2791 ((string= key "TOC")
2792 (let ((case-fold-search t))
2793 (cond
2794 ((string-match "\\<headlines\\>" value)
2795 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2796 (string-to-number (match-string 0 value))))
2797 (localp (string-match-p "\\<local\\>" value)))
2798 (org-html-toc depth info (and localp keyword))))
2799 ((string= "listings" value) (org-html-list-of-listings info))
2800 ((string= "tables" value) (org-html-list-of-tables info))))))))
2802 ;;;; Latex Environment
2804 (defun org-html-format-latex (latex-frag processing-type info)
2805 "Format a LaTeX fragment LATEX-FRAG into HTML.
2806 PROCESSING-TYPE designates the tool used for conversion. It can
2807 be `mathjax', `verbatim', nil, t or symbols in
2808 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
2809 `imagemagick'. See `org-html-with-latex' for more information.
2810 INFO is a plist containing export properties."
2811 (let ((cache-relpath "") (cache-dir ""))
2812 (unless (eq processing-type 'mathjax)
2813 (let ((bfn (or (buffer-file-name)
2814 (make-temp-name
2815 (expand-file-name "latex" temporary-file-directory))))
2816 (latex-header
2817 (let ((header (plist-get info :latex-header)))
2818 (and header
2819 (concat (mapconcat
2820 (lambda (line) (concat "#+LATEX_HEADER: " line))
2821 (org-split-string header "\n")
2822 "\n")
2823 "\n")))))
2824 (setq cache-relpath
2825 (concat (file-name-as-directory org-preview-latex-image-directory)
2826 (file-name-sans-extension
2827 (file-name-nondirectory bfn)))
2828 cache-dir (file-name-directory bfn))
2829 ;; Re-create LaTeX environment from original buffer in
2830 ;; temporary buffer so that dvipng/imagemagick can properly
2831 ;; turn the fragment into an image.
2832 (setq latex-frag (concat latex-header latex-frag))))
2833 (with-temp-buffer
2834 (insert latex-frag)
2835 (org-format-latex cache-relpath nil nil cache-dir nil
2836 "Creating LaTeX Image..." nil processing-type)
2837 (buffer-string))))
2839 (defun org-html--wrap-latex-environment (contents _ &optional caption label)
2840 "Wrap CONTENTS string within appropriate environment for equations.
2841 When optional arguments CAPTION and LABEL are given, use them for
2842 caption and \"id\" attribute."
2843 (format "\n<div%s class=\"equation-container\">\n%s%s\n</div>"
2844 ;; ID.
2845 (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
2846 ;; Contents.
2847 (format "<span class=\"equation\">\n%s\n</span>" contents)
2848 ;; Caption.
2849 (if (not (org-string-nw-p caption)) ""
2850 (format "\n<span class=\"equation-label\">\n%s\n</span>"
2851 caption))))
2853 (defun org-html--math-environment-p (element &optional _)
2854 "Non-nil when ELEMENT is a LaTeX math environment.
2855 Math environments match the regular expression defined in
2856 `org-latex-math-environments-re'. This function is meant to be
2857 used as a predicate for `org-export-get-ordinal' or a value to
2858 `org-html-standalone-image-predicate'."
2859 (string-match-p org-latex-math-environments-re
2860 (org-element-property :value element)))
2862 (defun org-html--unlabel-latex-environment (latex-frag)
2863 "Change environment in LATEX-FRAG string to an unnumbered one.
2864 For instance, change an 'equation' environment to 'equation*'."
2865 (replace-regexp-in-string
2866 "\\`[ \t]*\\\\begin{\\([^*]+?\\)}"
2867 "\\1*"
2868 (replace-regexp-in-string "^[ \t]*\\\\end{\\([^*]+?\\)}[ \r\t\n]*\\'"
2869 "\\1*"
2870 latex-frag nil nil 1)
2871 nil nil 1))
2873 (defun org-html-latex-environment (latex-environment _contents info)
2874 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2875 CONTENTS is nil. INFO is a plist holding contextual information."
2876 (let ((processing-type (plist-get info :with-latex))
2877 (latex-frag (org-remove-indentation
2878 (org-element-property :value latex-environment)))
2879 (attributes (org-export-read-attribute :attr_html latex-environment))
2880 (label (and (org-element-property :name latex-environment)
2881 (org-export-get-reference latex-environment info)))
2882 (caption (number-to-string
2883 (org-export-get-ordinal
2884 latex-environment info nil
2885 #'org-html--math-environment-p))))
2886 (cond
2887 ((memq processing-type '(t mathjax))
2888 (org-html-format-latex
2889 (if (org-string-nw-p label)
2890 (replace-regexp-in-string "\\`.*"
2891 (format "\\&\n\\\\label{%s}" label)
2892 latex-frag)
2893 latex-frag)
2894 'mathjax info))
2895 ((assq processing-type org-preview-latex-process-alist)
2896 (let ((formula-link
2897 (org-html-format-latex
2898 (org-html--unlabel-latex-environment latex-frag)
2899 processing-type info)))
2900 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2901 (org-html--wrap-latex-environment
2902 (org-html--format-image
2903 (match-string 1 formula-link) attributes info)
2904 info caption label))))
2905 (t (org-html--wrap-latex-environment latex-frag info caption label)))))
2907 ;;;; Latex Fragment
2909 (defun org-html-latex-fragment (latex-fragment _contents info)
2910 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2911 CONTENTS is nil. INFO is a plist holding contextual information."
2912 (let ((latex-frag (org-element-property :value latex-fragment))
2913 (processing-type (plist-get info :with-latex)))
2914 (cond
2915 ((memq processing-type '(t mathjax))
2916 (org-html-format-latex latex-frag 'mathjax info))
2917 ((assq processing-type org-preview-latex-process-alist)
2918 (let ((formula-link
2919 (org-html-format-latex latex-frag processing-type info)))
2920 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2921 (org-html--format-image (match-string 1 formula-link) nil info))))
2922 (t latex-frag))))
2924 ;;;; Line Break
2926 (defun org-html-line-break (_line-break _contents info)
2927 "Transcode a LINE-BREAK object from Org to HTML.
2928 CONTENTS is nil. INFO is a plist holding contextual information."
2929 (concat (org-html-close-tag "br" nil info) "\n"))
2931 ;;;; Link
2933 (defun org-html-image-link-filter (data _backend info)
2934 (org-export-insert-image-links data info org-html-inline-image-rules))
2936 (defun org-html-inline-image-p (link info)
2937 "Non-nil when LINK is meant to appear as an image.
2938 INFO is a plist used as a communication channel. LINK is an
2939 inline image when it has no description and targets an image
2940 file (see `org-html-inline-image-rules' for more information), or
2941 if its description is a single link targeting an image file."
2942 (if (not (org-element-contents link))
2943 (org-export-inline-image-p
2944 link (plist-get info :html-inline-image-rules))
2945 (not
2946 (let ((link-count 0))
2947 (org-element-map (org-element-contents link)
2948 (cons 'plain-text org-element-all-objects)
2949 (lambda (obj)
2950 (pcase (org-element-type obj)
2951 (`plain-text (org-string-nw-p obj))
2952 (`link (if (= link-count 1) t
2953 (cl-incf link-count)
2954 (not (org-export-inline-image-p
2955 obj (plist-get info :html-inline-image-rules)))))
2956 (_ t)))
2957 info t)))))
2959 (defvar org-html-standalone-image-predicate)
2960 (defun org-html-standalone-image-p (element info)
2961 "Non-nil if ELEMENT is a standalone image.
2963 INFO is a plist holding contextual information.
2965 An element or object is a standalone image when
2967 - its type is `paragraph' and its sole content, save for white
2968 spaces, is a link that qualifies as an inline image;
2970 - its type is `link' and its containing paragraph has no other
2971 content save white spaces.
2973 Bind `org-html-standalone-image-predicate' to constrain paragraph
2974 further. For example, to check for only captioned standalone
2975 images, set it to:
2977 (lambda (paragraph) (org-element-property :caption paragraph))"
2978 (let ((paragraph (pcase (org-element-type element)
2979 (`paragraph element)
2980 (`link (org-export-get-parent element)))))
2981 (and (eq (org-element-type paragraph) 'paragraph)
2982 (or (not (fboundp 'org-html-standalone-image-predicate))
2983 (funcall org-html-standalone-image-predicate paragraph))
2984 (catch 'exit
2985 (let ((link-count 0))
2986 (org-element-map (org-element-contents paragraph)
2987 (cons 'plain-text org-element-all-objects)
2988 (lambda (obj)
2989 (when (pcase (org-element-type obj)
2990 (`plain-text (org-string-nw-p obj))
2991 (`link (or (> (cl-incf link-count) 1)
2992 (not (org-html-inline-image-p obj info))))
2993 (_ t))
2994 (throw 'exit nil)))
2995 info nil 'link)
2996 (= link-count 1))))))
2998 (defun org-html-link (link desc info)
2999 "Transcode a LINK object from Org to HTML.
3000 DESC is the description part of the link, or the empty string.
3001 INFO is a plist holding contextual information. See
3002 `org-export-data'."
3003 (let* ((link-org-files-as-html-maybe
3004 (lambda (raw-path info)
3005 ;; Treat links to `file.org' as links to `file.html', if
3006 ;; needed. See `org-html-link-org-files-as-html'.
3007 (cond
3008 ((and (plist-get info :html-link-org-files-as-html)
3009 (string= ".org"
3010 (downcase (file-name-extension raw-path "."))))
3011 (concat (file-name-sans-extension raw-path) "."
3012 (plist-get info :html-extension)))
3013 (t raw-path))))
3014 (type (org-element-property :type link))
3015 (raw-path (org-element-property :path link))
3016 ;; Ensure DESC really exists, or set it to nil.
3017 (desc (org-string-nw-p desc))
3018 (path
3019 (cond
3020 ((member type '("http" "https" "ftp" "mailto" "news"))
3021 (url-encode-url (org-link-unescape (concat type ":" raw-path))))
3022 ((string= type "file")
3023 ;; During publishing, turn absolute file names belonging
3024 ;; to base directory into relative file names. Otherwise,
3025 ;; append "file" protocol to absolute file name.
3026 (setq raw-path
3027 (org-export-file-uri
3028 (org-publish-file-relative-name raw-path info)))
3029 ;; Possibly append `:html-link-home' to relative file
3030 ;; name.
3031 (let ((home (and (plist-get info :html-link-home)
3032 (org-trim (plist-get info :html-link-home)))))
3033 (when (and home
3034 (plist-get info :html-link-use-abs-url)
3035 (file-name-absolute-p raw-path))
3036 (setq raw-path (concat (file-name-as-directory home) raw-path))))
3037 ;; Maybe turn ".org" into ".html".
3038 (setq raw-path (funcall link-org-files-as-html-maybe raw-path info))
3039 ;; Add search option, if any. A search option can be
3040 ;; relative to a custom-id, a headline title, a name or
3041 ;; a target.
3042 (let ((option (org-element-property :search-option link)))
3043 (if (not option) raw-path
3044 (let ((path (org-element-property :path link)))
3045 (concat raw-path
3047 (org-publish-resolve-external-link option path t))))))
3048 (t raw-path)))
3049 ;; Extract attributes from parent's paragraph. HACK: Only do
3050 ;; this for the first link in parent (inner image link for
3051 ;; inline images). This is needed as long as attributes
3052 ;; cannot be set on a per link basis.
3053 (attributes-plist
3054 (let* ((parent (org-export-get-parent-element link))
3055 (link (let ((container (org-export-get-parent link)))
3056 (if (and (eq (org-element-type container) 'link)
3057 (org-html-inline-image-p link info))
3058 container
3059 link))))
3060 (and (eq (org-element-map parent 'link 'identity info t) link)
3061 (org-export-read-attribute :attr_html parent))))
3062 (attributes
3063 (let ((attr (org-html--make-attribute-string attributes-plist)))
3064 (if (org-string-nw-p attr) (concat " " attr) ""))))
3065 (cond
3066 ;; Link type is handled by a special function.
3067 ((org-export-custom-protocol-maybe link desc 'html))
3068 ;; Image file.
3069 ((and (plist-get info :html-inline-images)
3070 (org-export-inline-image-p
3071 link (plist-get info :html-inline-image-rules)))
3072 (org-html--format-image path attributes-plist info))
3073 ;; Radio target: Transcode target's contents and use them as
3074 ;; link's description.
3075 ((string= type "radio")
3076 (let ((destination (org-export-resolve-radio-link link info)))
3077 (if (not destination) desc
3078 (format "<a href=\"#%s\"%s>%s</a>"
3079 (org-export-get-reference destination info)
3080 attributes
3081 desc))))
3082 ;; Links pointing to a headline: Find destination and build
3083 ;; appropriate referencing command.
3084 ((member type '("custom-id" "fuzzy" "id"))
3085 (let ((destination (if (string= type "fuzzy")
3086 (org-export-resolve-fuzzy-link link info)
3087 (org-export-resolve-id-link link info))))
3088 (pcase (org-element-type destination)
3089 ;; ID link points to an external file.
3090 (`plain-text
3091 (let ((fragment (concat "ID-" path))
3092 ;; Treat links to ".org" files as ".html", if needed.
3093 (path (funcall link-org-files-as-html-maybe
3094 destination info)))
3095 (format "<a href=\"%s#%s\"%s>%s</a>"
3096 path fragment attributes (or desc destination))))
3097 ;; Fuzzy link points nowhere.
3098 (`nil
3099 (format "<i>%s</i>"
3100 (or desc
3101 (org-export-data
3102 (org-element-property :raw-link link) info))))
3103 ;; Link points to a headline.
3104 (`headline
3105 (let ((href (or (org-element-property :CUSTOM_ID destination)
3106 (org-export-get-reference destination info)))
3107 ;; What description to use?
3108 (desc
3109 ;; Case 1: Headline is numbered and LINK has no
3110 ;; description. Display section number.
3111 (if (and (org-export-numbered-headline-p destination info)
3112 (not desc))
3113 (mapconcat #'number-to-string
3114 (org-export-get-headline-number
3115 destination info) ".")
3116 ;; Case 2: Either the headline is un-numbered or
3117 ;; LINK has a custom description. Display LINK's
3118 ;; description or headline's title.
3119 (or desc
3120 (org-export-data
3121 (org-element-property :title destination) info)))))
3122 (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
3123 ;; Fuzzy link points to a target or an element.
3125 (if (and destination
3126 (memq (plist-get info :with-latex) '(mathjax t))
3127 (eq 'latex-environment (org-element-type destination))
3128 (eq 'math (org-latex--environment-type destination)))
3129 ;; Caption and labels are introduced within LaTeX
3130 ;; environment. Use "eqref" macro to refer to those in
3131 ;; the document.
3132 (format "\\eqref{%s}"
3133 (org-export-get-reference destination info))
3134 (let* ((ref (org-export-get-reference destination info))
3135 (org-html-standalone-image-predicate
3136 #'org-html--has-caption-p)
3137 (counter-predicate
3138 (if (eq 'latex-environment (org-element-type destination))
3139 #'org-html--math-environment-p
3140 #'org-html--has-caption-p))
3141 (number
3142 (cond
3143 (desc nil)
3144 ((org-html-standalone-image-p destination info)
3145 (org-export-get-ordinal
3146 (org-element-map destination 'link #'identity info t)
3147 info 'link 'org-html-standalone-image-p))
3148 (t (org-export-get-ordinal
3149 destination info nil counter-predicate))))
3150 (desc
3151 (cond (desc)
3152 ((not number) "No description for this link")
3153 ((numberp number) (number-to-string number))
3154 (t (mapconcat #'number-to-string number ".")))))
3155 (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc)))))))
3156 ;; Coderef: replace link with the reference name or the
3157 ;; equivalent line number.
3158 ((string= type "coderef")
3159 (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
3160 (format "<a href=\"#%s\" %s%s>%s</a>"
3161 fragment
3162 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
3163 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
3164 fragment fragment)
3165 attributes
3166 (format (org-export-get-coderef-format path desc)
3167 (org-export-resolve-coderef path info)))))
3168 ;; External link with a description part.
3169 ((and path desc) (format "<a href=\"%s\"%s>%s</a>"
3170 (org-html-encode-plain-text path)
3171 attributes
3172 desc))
3173 ;; External link without a description part.
3174 (path (let ((path (org-html-encode-plain-text path)))
3175 (format "<a href=\"%s\"%s>%s</a>"
3176 path
3177 attributes
3178 (org-link-unescape path))))
3179 ;; No path, only description. Try to do something useful.
3180 (t (format "<i>%s</i>" desc)))))
3182 ;;;; Node Property
3184 (defun org-html-node-property (node-property _contents _info)
3185 "Transcode a NODE-PROPERTY element from Org to HTML.
3186 CONTENTS is nil. INFO is a plist holding contextual
3187 information."
3188 (format "%s:%s"
3189 (org-element-property :key node-property)
3190 (let ((value (org-element-property :value node-property)))
3191 (if value (concat " " value) ""))))
3193 ;;;; Paragraph
3195 (defun org-html-paragraph (paragraph contents info)
3196 "Transcode a PARAGRAPH element from Org to HTML.
3197 CONTENTS is the contents of the paragraph, as a string. INFO is
3198 the plist used as a communication channel."
3199 (let* ((parent (org-export-get-parent paragraph))
3200 (parent-type (org-element-type parent))
3201 (style '((footnote-definition " class=\"footpara\"")
3202 (org-data " class=\"footpara\"")))
3203 (attributes (org-html--make-attribute-string
3204 (org-export-read-attribute :attr_html paragraph)))
3205 (extra (or (cadr (assq parent-type style)) "")))
3206 (cond
3207 ((and (eq parent-type 'item)
3208 (not (org-export-get-previous-element paragraph info))
3209 (let ((followers (org-export-get-next-element paragraph info 2)))
3210 (and (not (cdr followers))
3211 (memq (org-element-type (car followers)) '(nil plain-list)))))
3212 ;; First paragraph in an item has no tag if it is alone or
3213 ;; followed, at most, by a sub-list.
3214 contents)
3215 ((org-html-standalone-image-p paragraph info)
3216 ;; Standalone image.
3217 (let ((caption
3218 (let ((raw (org-export-data
3219 (org-export-get-caption paragraph) info))
3220 (org-html-standalone-image-predicate
3221 #'org-html--has-caption-p))
3222 (if (not (org-string-nw-p raw)) raw
3223 (concat "<span class=\"figure-number\">"
3224 (format (org-html--translate "Figure %d:" info)
3225 (org-export-get-ordinal
3226 (org-element-map paragraph 'link
3227 #'identity info t)
3228 info nil #'org-html-standalone-image-p))
3229 " </span>"
3230 raw))))
3231 (label (and (org-element-property :name paragraph)
3232 (org-export-get-reference paragraph info))))
3233 (org-html--wrap-image contents info caption label)))
3234 ;; Regular paragraph.
3235 (t (format "<p%s%s>\n%s</p>"
3236 (if (org-string-nw-p attributes)
3237 (concat " " attributes) "")
3238 extra contents)))))
3240 ;;;; Plain List
3242 (defun org-html-plain-list (plain-list contents _info)
3243 "Transcode a PLAIN-LIST element from Org to HTML.
3244 CONTENTS is the contents of the list. INFO is a plist holding
3245 contextual information."
3246 (let* ((type (pcase (org-element-property :type plain-list)
3247 (`ordered "ol")
3248 (`unordered "ul")
3249 (`descriptive "dl")
3250 (other (error "Unknown HTML list type: %s" other))))
3251 (class (format "org-%s" type))
3252 (attributes (org-export-read-attribute :attr_html plain-list)))
3253 (format "<%s %s>\n%s</%s>"
3254 type
3255 (org-html--make-attribute-string
3256 (plist-put attributes :class
3257 (org-trim
3258 (mapconcat #'identity
3259 (list class (plist-get attributes :class))
3260 " "))))
3261 contents
3262 type)))
3264 ;;;; Plain Text
3266 (defun org-html-convert-special-strings (string)
3267 "Convert special characters in STRING to HTML."
3268 (dolist (a org-html-special-string-regexps string)
3269 (let ((re (car a))
3270 (rpl (cdr a)))
3271 (setq string (replace-regexp-in-string re rpl string t)))))
3273 (defun org-html-encode-plain-text (text)
3274 "Convert plain text characters from TEXT to HTML equivalent.
3275 Possible conversions are set in `org-html-protect-char-alist'."
3276 (dolist (pair org-html-protect-char-alist text)
3277 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3279 (defun org-html-plain-text (text info)
3280 "Transcode a TEXT string from Org to HTML.
3281 TEXT is the string to transcode. INFO is a plist holding
3282 contextual information."
3283 (let ((output text))
3284 ;; Protect following characters: <, >, &.
3285 (setq output (org-html-encode-plain-text output))
3286 ;; Handle smart quotes. Be sure to provide original string since
3287 ;; OUTPUT may have been modified.
3288 (when (plist-get info :with-smart-quotes)
3289 (setq output (org-export-activate-smart-quotes output :html info text)))
3290 ;; Handle special strings.
3291 (when (plist-get info :with-special-strings)
3292 (setq output (org-html-convert-special-strings output)))
3293 ;; Handle break preservation if required.
3294 (when (plist-get info :preserve-breaks)
3295 (setq output
3296 (replace-regexp-in-string
3297 "\\(\\\\\\\\\\)?[ \t]*\n"
3298 (concat (org-html-close-tag "br" nil info) "\n") output)))
3299 ;; Return value.
3300 output))
3303 ;; Planning
3305 (defun org-html-planning (planning _contents info)
3306 "Transcode a PLANNING element from Org to HTML.
3307 CONTENTS is nil. INFO is a plist used as a communication
3308 channel."
3309 (format
3310 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3311 (org-trim
3312 (mapconcat
3313 (lambda (pair)
3314 (let ((timestamp (cdr pair)))
3315 (when timestamp
3316 (let ((string (car pair)))
3317 (format "<span class=\"timestamp-kwd\">%s</span> \
3318 <span class=\"timestamp\">%s</span> "
3319 string
3320 (org-html-plain-text (org-timestamp-translate timestamp)
3321 info))))))
3322 `((,org-closed-string . ,(org-element-property :closed planning))
3323 (,org-deadline-string . ,(org-element-property :deadline planning))
3324 (,org-scheduled-string . ,(org-element-property :scheduled planning)))
3325 ""))))
3327 ;;;; Property Drawer
3329 (defun org-html-property-drawer (_property-drawer contents _info)
3330 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3331 CONTENTS holds the contents of the drawer. INFO is a plist
3332 holding contextual information."
3333 (and (org-string-nw-p contents)
3334 (format "<pre class=\"example\">\n%s</pre>" contents)))
3336 ;;;; Quote Block
3338 (defun org-html-quote-block (quote-block contents _info)
3339 "Transcode a QUOTE-BLOCK element from Org to HTML.
3340 CONTENTS holds the contents of the block. INFO is a plist
3341 holding contextual information."
3342 (format "<blockquote%s>\n%s</blockquote>"
3343 (let* ((name (org-element-property :name quote-block))
3344 (attributes (org-export-read-attribute :attr_html quote-block))
3345 (a (org-html--make-attribute-string
3346 (if (or (not name) (plist-member attributes :id))
3347 attributes
3348 (plist-put attributes :id name)))))
3349 (if (org-string-nw-p a) (concat " " a) ""))
3350 contents))
3352 ;;;; Section
3354 (defun org-html-section (section contents info)
3355 "Transcode a SECTION element from Org to HTML.
3356 CONTENTS holds the contents of the section. INFO is a plist
3357 holding contextual information."
3358 (let ((parent (org-export-get-parent-headline section)))
3359 ;; Before first headline: no container, just return CONTENTS.
3360 (if (not parent) contents
3361 ;; Get div's class and id references.
3362 (let* ((class-num (+ (org-export-get-relative-level parent info)
3363 (1- (plist-get info :html-toplevel-hlevel))))
3364 (section-number
3365 (and (org-export-numbered-headline-p parent info)
3366 (mapconcat
3367 #'number-to-string
3368 (org-export-get-headline-number parent info) "-"))))
3369 ;; Build return value.
3370 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>\n"
3371 class-num
3372 (or (org-element-property :CUSTOM_ID parent)
3373 section-number
3374 (org-export-get-reference parent info))
3375 (or contents ""))))))
3377 ;;;; Radio Target
3379 (defun org-html-radio-target (radio-target text info)
3380 "Transcode a RADIO-TARGET object from Org to HTML.
3381 TEXT is the text of the target. INFO is a plist holding
3382 contextual information."
3383 (let ((ref (org-export-get-reference radio-target info)))
3384 (org-html--anchor ref text nil info)))
3386 ;;;; Special Block
3388 (defun org-html-special-block (special-block contents info)
3389 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3390 CONTENTS holds the contents of the block. INFO is a plist
3391 holding contextual information."
3392 (let* ((block-type (org-element-property :type special-block))
3393 (html5-fancy (and (org-html--html5-fancy-p info)
3394 (member block-type org-html-html5-elements)))
3395 (attributes (org-export-read-attribute :attr_html special-block)))
3396 (unless html5-fancy
3397 (let ((class (plist-get attributes :class)))
3398 (setq attributes (plist-put attributes :class
3399 (if class (concat class " " block-type)
3400 block-type)))))
3401 (let* ((contents (or contents ""))
3402 (name (org-element-property :name special-block))
3403 (a (org-html--make-attribute-string
3404 (if (or (not name) (plist-member attributes :id))
3405 attributes
3406 (plist-put attributes :id name))))
3407 (str (if (org-string-nw-p a) (concat " " a) "")))
3408 (if html5-fancy
3409 (format "<%s%s>\n%s</%s>" block-type str contents block-type)
3410 (format "<div%s>\n%s\n</div>" str contents)))))
3412 ;;;; Src Block
3414 (defun org-html-src-block (src-block _contents info)
3415 "Transcode a SRC-BLOCK element from Org to HTML.
3416 CONTENTS holds the contents of the item. INFO is a plist holding
3417 contextual information."
3418 (if (org-export-read-attribute :attr_html src-block :textarea)
3419 (org-html--textarea-block src-block)
3420 (let* ((lang (org-element-property :language src-block))
3421 (code (org-html-format-code src-block info))
3422 (label (let ((lbl (and (org-element-property :name src-block)
3423 (org-export-get-reference src-block info))))
3424 (if lbl (format " id=\"%s\"" lbl) "")))
3425 (klipsify (and (plist-get info :html-klipsify-src)
3426 (member lang '("javascript" "js"
3427 "ruby" "scheme" "clojure" "php" "html")))))
3428 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3429 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
3430 ;; Build caption.
3431 (let ((caption (org-export-get-caption src-block)))
3432 (if (not caption) ""
3433 (let ((listing-number
3434 (format
3435 "<span class=\"listing-number\">%s </span>"
3436 (format
3437 (org-html--translate "Listing %d:" info)
3438 (org-export-get-ordinal
3439 src-block info nil #'org-html--has-caption-p)))))
3440 (format "<label class=\"org-src-name\">%s%s</label>"
3441 listing-number
3442 (org-trim (org-export-data caption info))))))
3443 ;; Contents.
3444 (if klipsify
3445 (format "<pre><code class=\"src src-%s\"%s%s>%s</code></pre>"
3446 lang
3447 label
3448 (if (string= lang "html")
3449 " data-editor-type=\"html\""
3451 code)
3452 (format "<pre class=\"src src-%s\"%s>%s</pre>"
3453 lang label code)))))))
3455 ;;;; Statistics Cookie
3457 (defun org-html-statistics-cookie (statistics-cookie _contents _info)
3458 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3459 CONTENTS is nil. INFO is a plist holding contextual information."
3460 (let ((cookie-value (org-element-property :value statistics-cookie)))
3461 (format "<code>%s</code>" cookie-value)))
3463 ;;;; Strike-Through
3465 (defun org-html-strike-through (_strike-through contents info)
3466 "Transcode STRIKE-THROUGH from Org to HTML.
3467 CONTENTS is the text with strike-through markup. INFO is a plist
3468 holding contextual information."
3469 (format
3470 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3471 "%s")
3472 contents))
3474 ;;;; Subscript
3476 (defun org-html-subscript (_subscript contents _info)
3477 "Transcode a SUBSCRIPT object from Org to HTML.
3478 CONTENTS is the contents of the object. INFO is a plist holding
3479 contextual information."
3480 (format "<sub>%s</sub>" contents))
3482 ;;;; Superscript
3484 (defun org-html-superscript (_superscript contents _info)
3485 "Transcode a SUPERSCRIPT object from Org to HTML.
3486 CONTENTS is the contents of the object. INFO is a plist holding
3487 contextual information."
3488 (format "<sup>%s</sup>" contents))
3490 ;;;; Table Cell
3492 (defun org-html-table-cell (table-cell contents info)
3493 "Transcode a TABLE-CELL element from Org to HTML.
3494 CONTENTS is nil. INFO is a plist used as a communication
3495 channel."
3496 (let* ((table-row (org-export-get-parent table-cell))
3497 (table (org-export-get-parent-table table-cell))
3498 (cell-attrs
3499 (if (not (plist-get info :html-table-align-individual-fields)) ""
3500 (format (if (and (boundp 'org-html-format-table-no-css)
3501 org-html-format-table-no-css)
3502 " align=\"%s\"" " class=\"org-%s\"")
3503 (org-export-table-cell-alignment table-cell info)))))
3504 (when (or (not contents) (string= "" (org-trim contents)))
3505 (setq contents "&#xa0;"))
3506 (cond
3507 ((and (org-export-table-has-header-p table info)
3508 (= 1 (org-export-table-row-group table-row info)))
3509 (let ((header-tags (plist-get info :html-table-header-tags)))
3510 (concat "\n" (format (car header-tags) "col" cell-attrs)
3511 contents
3512 (cdr header-tags))))
3513 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3514 (zerop (cdr (org-export-table-cell-address table-cell info))))
3515 (let ((header-tags (plist-get info :html-table-header-tags)))
3516 (concat "\n" (format (car header-tags) "row" cell-attrs)
3517 contents
3518 (cdr header-tags))))
3519 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3520 (concat "\n" (format (car data-tags) cell-attrs)
3521 contents
3522 (cdr data-tags)))))))
3524 ;;;; Table Row
3526 (defun org-html-table-row (table-row contents info)
3527 "Transcode a TABLE-ROW element from Org to HTML.
3528 CONTENTS is the contents of the row. INFO is a plist used as a
3529 communication channel."
3530 ;; Rules are ignored since table separators are deduced from
3531 ;; borders of the current row.
3532 (when (eq (org-element-property :type table-row) 'standard)
3533 (let* ((group (org-export-table-row-group table-row info))
3534 (number (org-export-table-row-number table-row info))
3535 (start-group-p
3536 (org-export-table-row-starts-rowgroup-p table-row info))
3537 (end-group-p
3538 (org-export-table-row-ends-rowgroup-p table-row info))
3539 (topp (and (equal start-group-p '(top))
3540 (equal end-group-p '(below top))))
3541 (bottomp (and (equal start-group-p '(above))
3542 (equal end-group-p '(bottom above))))
3543 (row-open-tag
3544 (pcase (plist-get info :html-table-row-open-tag)
3545 ((and accessor (pred functionp))
3546 (funcall accessor
3547 number group start-group-p end-group-p topp bottomp))
3548 (accessor accessor)))
3549 (row-close-tag
3550 (pcase (plist-get info :html-table-row-close-tag)
3551 ((and accessor (pred functionp))
3552 (funcall accessor
3553 number group start-group-p end-group-p topp bottomp))
3554 (accessor accessor)))
3555 (group-tags
3556 (cond
3557 ;; Row belongs to second or subsequent groups.
3558 ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
3559 ;; Row is from first group. Table has >=1 groups.
3560 ((org-export-table-has-header-p
3561 (org-export-get-parent-table table-row) info)
3562 '("<thead>" . "\n</thead>"))
3563 ;; Row is from first and only group.
3564 (t '("<tbody>" . "\n</tbody>")))))
3565 (concat (and start-group-p (car group-tags))
3566 (concat "\n"
3567 row-open-tag
3568 contents
3569 "\n"
3570 row-close-tag)
3571 (and end-group-p (cdr group-tags))))))
3573 ;;;; Table
3575 (defun org-html-table-first-row-data-cells (table info)
3576 "Transcode the first row of TABLE.
3577 INFO is a plist used as a communication channel."
3578 (let ((table-row
3579 (org-element-map table 'table-row
3580 (lambda (row)
3581 (unless (eq (org-element-property :type row) 'rule) row))
3582 info 'first-match))
3583 (special-column-p (org-export-table-has-special-column-p table)))
3584 (if (not special-column-p) (org-element-contents table-row)
3585 (cdr (org-element-contents table-row)))))
3587 (defun org-html-table--table.el-table (table _info)
3588 "Format table.el tables into HTML.
3589 INFO is a plist used as a communication channel."
3590 (when (eq (org-element-property :type table) 'table.el)
3591 (require 'table)
3592 (let ((outbuf (with-current-buffer
3593 (get-buffer-create "*org-export-table*")
3594 (erase-buffer) (current-buffer))))
3595 (with-temp-buffer
3596 (insert (org-element-property :value table))
3597 (goto-char 1)
3598 (re-search-forward "^[ \t]*|[^|]" nil t)
3599 (table-generate-source 'html outbuf))
3600 (with-current-buffer outbuf
3601 (prog1 (org-trim (buffer-string))
3602 (kill-buffer) )))))
3604 (defun org-html-table (table contents info)
3605 "Transcode a TABLE element from Org to HTML.
3606 CONTENTS is the contents of the table. INFO is a plist holding
3607 contextual information."
3608 (if (eq (org-element-property :type table) 'table.el)
3609 ;; "table.el" table. Convert it using appropriate tools.
3610 (org-html-table--table.el-table table info)
3611 ;; Standard table.
3612 (let* ((caption (org-export-get-caption table))
3613 (number (org-export-get-ordinal
3614 table info nil #'org-html--has-caption-p))
3615 (attributes
3616 (org-html--make-attribute-string
3617 (org-combine-plists
3618 (and (org-element-property :name table)
3619 (list :id (org-export-get-reference table info)))
3620 (and (not (org-html-html5-p info))
3621 (plist-get info :html-table-attributes))
3622 (org-export-read-attribute :attr_html table))))
3623 (alignspec
3624 (if (bound-and-true-p org-html-format-table-no-css)
3625 "align=\"%s\""
3626 "class=\"org-%s\""))
3627 (table-column-specs
3628 (lambda (table info)
3629 (mapconcat
3630 (lambda (table-cell)
3631 (let ((alignment (org-export-table-cell-alignment
3632 table-cell info)))
3633 (concat
3634 ;; Begin a colgroup?
3635 (when (org-export-table-cell-starts-colgroup-p
3636 table-cell info)
3637 "\n<colgroup>")
3638 ;; Add a column. Also specify its alignment.
3639 (format "\n%s"
3640 (org-html-close-tag
3641 "col" (concat " " (format alignspec alignment)) info))
3642 ;; End a colgroup?
3643 (when (org-export-table-cell-ends-colgroup-p
3644 table-cell info)
3645 "\n</colgroup>"))))
3646 (org-html-table-first-row-data-cells table info) "\n"))))
3647 (format "<table%s>\n%s\n%s\n%s</table>"
3648 (if (equal attributes "") "" (concat " " attributes))
3649 (if (not caption) ""
3650 (format (if (plist-get info :html-table-caption-above)
3651 "<caption class=\"t-above\">%s</caption>"
3652 "<caption class=\"t-bottom\">%s</caption>")
3653 (concat
3654 "<span class=\"table-number\">"
3655 (format (org-html--translate "Table %d:" info) number)
3656 "</span> " (org-export-data caption info))))
3657 (funcall table-column-specs table info)
3658 contents))))
3660 ;;;; Target
3662 (defun org-html-target (target _contents info)
3663 "Transcode a TARGET object from Org to HTML.
3664 CONTENTS is nil. INFO is a plist holding contextual
3665 information."
3666 (let ((ref (org-export-get-reference target info)))
3667 (org-html--anchor ref nil nil info)))
3669 ;;;; Timestamp
3671 (defun org-html-timestamp (timestamp _contents info)
3672 "Transcode a TIMESTAMP object from Org to HTML.
3673 CONTENTS is nil. INFO is a plist holding contextual
3674 information."
3675 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3676 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3677 (replace-regexp-in-string "--" "&#x2013;" value))))
3679 ;;;; Underline
3681 (defun org-html-underline (_underline contents info)
3682 "Transcode UNDERLINE from Org to HTML.
3683 CONTENTS is the text with underline markup. INFO is a plist
3684 holding contextual information."
3685 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3686 "%s")
3687 contents))
3689 ;;;; Verbatim
3691 (defun org-html-verbatim (verbatim _contents info)
3692 "Transcode VERBATIM from Org to HTML.
3693 CONTENTS is nil. INFO is a plist holding contextual
3694 information."
3695 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3696 (org-html-encode-plain-text (org-element-property :value verbatim))))
3698 ;;;; Verse Block
3700 (defun org-html-verse-block (_verse-block contents info)
3701 "Transcode a VERSE-BLOCK element from Org to HTML.
3702 CONTENTS is verse block contents. INFO is a plist holding
3703 contextual information."
3704 (format "<p class=\"verse\">\n%s</p>"
3705 ;; Replace leading white spaces with non-breaking spaces.
3706 (replace-regexp-in-string
3707 "^[ \t]+" (lambda (m) (org-html--make-string (length m) "&#xa0;"))
3708 ;; Replace each newline character with line break. Also
3709 ;; remove any trailing "br" close-tag so as to avoid
3710 ;; duplicates.
3711 (let* ((br (org-html-close-tag "br" nil info))
3712 (re (format "\\(?:%s\\)?[ \t]*\n" (regexp-quote br))))
3713 (replace-regexp-in-string re (concat br "\n") contents)))))
3716 ;;; Filter Functions
3718 (defun org-html-final-function (contents _backend info)
3719 "Filter to indent the HTML and convert HTML entities."
3720 (with-temp-buffer
3721 (insert contents)
3722 (set-auto-mode t)
3723 (if (plist-get info :html-indent)
3724 (indent-region (point-min) (point-max)))
3725 (buffer-substring-no-properties (point-min) (point-max))))
3728 ;;; End-user functions
3730 ;;;###autoload
3731 (defun org-html-export-as-html
3732 (&optional async subtreep visible-only body-only ext-plist)
3733 "Export current buffer to an HTML buffer.
3735 If narrowing is active in the current buffer, only export its
3736 narrowed part.
3738 If a region is active, export that region.
3740 A non-nil optional argument ASYNC means the process should happen
3741 asynchronously. The resulting buffer should be accessible
3742 through the `org-export-stack' interface.
3744 When optional argument SUBTREEP is non-nil, export the sub-tree
3745 at point, extracting information from the headline properties
3746 first.
3748 When optional argument VISIBLE-ONLY is non-nil, don't export
3749 contents of hidden elements.
3751 When optional argument BODY-ONLY is non-nil, only write code
3752 between \"<body>\" and \"</body>\" tags.
3754 EXT-PLIST, when provided, is a property list with external
3755 parameters overriding Org default settings, but still inferior to
3756 file-local settings.
3758 Export is done in a buffer named \"*Org HTML Export*\", which
3759 will be displayed when `org-export-show-temporary-export-buffer'
3760 is non-nil."
3761 (interactive)
3762 (org-export-to-buffer 'html "*Org HTML Export*"
3763 async subtreep visible-only body-only ext-plist
3764 (lambda () (set-auto-mode t))))
3766 ;;;###autoload
3767 (defun org-html-convert-region-to-html ()
3768 "Assume the current region has Org syntax, and convert it to HTML.
3769 This can be used in any buffer. For example, you can write an
3770 itemized list in Org syntax in an HTML buffer and use this command
3771 to convert it."
3772 (interactive)
3773 (org-export-replace-region-by 'html))
3775 ;;;###autoload
3776 (defun org-html-export-to-html
3777 (&optional async subtreep visible-only body-only ext-plist)
3778 "Export current buffer to a HTML file.
3780 If narrowing is active in the current buffer, only export its
3781 narrowed part.
3783 If a region is active, export that region.
3785 A non-nil optional argument ASYNC means the process should happen
3786 asynchronously. The resulting file should be accessible through
3787 the `org-export-stack' interface.
3789 When optional argument SUBTREEP is non-nil, export the sub-tree
3790 at point, extracting information from the headline properties
3791 first.
3793 When optional argument VISIBLE-ONLY is non-nil, don't export
3794 contents of hidden elements.
3796 When optional argument BODY-ONLY is non-nil, only write code
3797 between \"<body>\" and \"</body>\" tags.
3799 EXT-PLIST, when provided, is a property list with external
3800 parameters overriding Org default settings, but still inferior to
3801 file-local settings.
3803 Return output file's name."
3804 (interactive)
3805 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3806 org-html-extension
3807 "html")))
3808 (file (org-export-output-file-name extension subtreep))
3809 (org-export-coding-system org-html-coding-system))
3810 (org-export-to-file 'html file
3811 async subtreep visible-only body-only ext-plist)))
3813 ;;;###autoload
3814 (defun org-html-publish-to-html (plist filename pub-dir)
3815 "Publish an org file to HTML.
3817 FILENAME is the filename of the Org file to be published. PLIST
3818 is the property list for the given project. PUB-DIR is the
3819 publishing directory.
3821 Return output file name."
3822 (org-publish-org-to 'html filename
3823 (concat "." (or (plist-get plist :html-extension)
3824 org-html-extension
3825 "html"))
3826 plist pub-dir))
3829 (provide 'ox-html)
3831 ;; Local variables:
3832 ;; generated-autoload-file: "org-loaddefs.el"
3833 ;; End:
3835 ;;; ox-html.el ends here