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