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