ox-html: Fix %d placeholder in pre/postamble string
[org-mode.git] / lisp / ox-html.el
blob63a8c847afc3139f83a3fd8bde1aa236cc0a0514
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?': non-nil means the row starts a group
952 `end-group?': non-nil means the row ends a group
953 `top?': non-nil means this is the top row
954 `bottom?': 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? end-group-p top? bottom?)
960 (cond (top? \"<tr class=\\\"tr-top\\\">\")
961 (bottom? \"<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 preamble and postamble.
1879 INFO is a plist used as a communication channel."
1880 (let ((timestamp-format (plist-get info :html-metadata-timestamp-format)))
1881 `((?t . ,(org-export-data (plist-get info :title) info))
1882 (?s . ,(org-export-data (plist-get info :subtitle) info))
1883 (?d . ,(org-export-data (org-export-get-date info timestamp-format)
1884 info))
1885 (?T . ,(format-time-string timestamp-format))
1886 (?a . ,(org-export-data (plist-get info :author) info))
1887 (?e . ,(mapconcat
1888 (lambda (e) (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 timestamp-format
1894 (and file (nth 5 (file-attributes file))))))
1895 (?v . ,(or (plist-get info :html-validation-link) "")))))
1897 (defun org-html--build-pre/postamble (type info)
1898 "Return document preamble or postamble as a string, or nil.
1899 TYPE is either `preamble' or `postamble', INFO is a plist used as a
1900 communication channel."
1901 (let ((section (plist-get info (intern (format ":html-%s" type))))
1902 (spec (org-html-format-spec info)))
1903 (when section
1904 (let ((section-contents
1905 (if (functionp section) (funcall section info)
1906 (cond
1907 ((stringp section) (format-spec section spec))
1908 ((eq section 'auto)
1909 (let ((date (cdr (assq ?d spec)))
1910 (author (cdr (assq ?a spec)))
1911 (email (cdr (assq ?e spec)))
1912 (creator (cdr (assq ?c spec)))
1913 (validation-link (cdr (assq ?v spec))))
1914 (concat
1915 (when (and (plist-get info :with-date)
1916 (org-string-nw-p date))
1917 (format "<p class=\"date\">%s: %s</p>\n"
1918 (org-html--translate "Date" info)
1919 date))
1920 (when (and (plist-get info :with-author)
1921 (org-string-nw-p author))
1922 (format "<p class=\"author\">%s: %s</p>\n"
1923 (org-html--translate "Author" info)
1924 author))
1925 (when (and (plist-get info :with-email)
1926 (org-string-nw-p email))
1927 (format "<p class=\"email\">%s: %s</p>\n"
1928 (org-html--translate "Email" info)
1929 email))
1930 (when (plist-get info :time-stamp-file)
1931 (format
1932 "<p class=\"date\">%s: %s</p>\n"
1933 (org-html--translate "Created" info)
1934 (format-time-string
1935 (plist-get info :html-metadata-timestamp-format))))
1936 (when (plist-get info :with-creator)
1937 (format "<p class=\"creator\">%s</p>\n" creator))
1938 (format "<p class=\"validation\">%s</p>\n"
1939 validation-link))))
1940 (t (format-spec
1941 (or (cadr (assoc-string
1942 (plist-get info :language)
1943 (eval (intern
1944 (format "org-html-%s-format" type)))
1946 (cadr
1947 (assoc-string
1948 "en"
1949 (eval
1950 (intern (format "org-html-%s-format" type)))
1951 t)))
1952 spec))))))
1953 (let ((div (assq type (plist-get info :html-divs))))
1954 (when (org-string-nw-p section-contents)
1955 (concat
1956 (format "<%s id=\"%s\" class=\"%s\">\n"
1957 (nth 1 div)
1958 (nth 2 div)
1959 org-html--pre/postamble-class)
1960 (org-element-normalize-string section-contents)
1961 (format "</%s>\n" (nth 1 div)))))))))
1963 (defun org-html-inner-template (contents info)
1964 "Return body of document string after HTML conversion.
1965 CONTENTS is the transcoded contents string. INFO is a plist
1966 holding export options."
1967 (concat
1968 ;; Table of contents.
1969 (let ((depth (plist-get info :with-toc)))
1970 (when depth (org-html-toc depth info)))
1971 ;; Document contents.
1972 contents
1973 ;; Footnotes section.
1974 (org-html-footnote-section info)))
1976 (defun org-html-template (contents info)
1977 "Return complete document string after HTML conversion.
1978 CONTENTS is the transcoded contents string. INFO is a plist
1979 holding export options."
1980 (concat
1981 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1982 (let* ((xml-declaration (plist-get info :html-xml-declaration))
1983 (decl (or (and (stringp xml-declaration) xml-declaration)
1984 (cdr (assoc (plist-get info :html-extension)
1985 xml-declaration))
1986 (cdr (assoc "html" xml-declaration))
1987 "")))
1988 (when (not (or (not decl) (string= "" decl)))
1989 (format "%s\n"
1990 (format decl
1991 (or (and org-html-coding-system
1992 (fboundp 'coding-system-get)
1993 (coding-system-get org-html-coding-system 'mime-charset))
1994 "iso-8859-1"))))))
1995 (org-html-doctype info)
1996 "\n"
1997 (concat "<html"
1998 (cond ((org-html-xhtml-p info)
1999 (format
2000 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
2001 (plist-get info :language) (plist-get info :language)))
2002 ((org-html-html5-p info)
2003 (format " lang=\"%s\"" (plist-get info :language))))
2004 ">\n")
2005 "<head>\n"
2006 (org-html--build-meta-info info)
2007 (org-html--build-head info)
2008 (org-html--build-mathjax-config info)
2009 "</head>\n"
2010 "<body>\n"
2011 (let ((link-up (org-trim (plist-get info :html-link-up)))
2012 (link-home (org-trim (plist-get info :html-link-home))))
2013 (unless (and (string= link-up "") (string= link-home ""))
2014 (format (plist-get info :html-home/up-format)
2015 (or link-up link-home)
2016 (or link-home link-up))))
2017 ;; Preamble.
2018 (org-html--build-pre/postamble 'preamble info)
2019 ;; Document contents.
2020 (let ((div (assq 'content (plist-get info :html-divs))))
2021 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
2022 ;; Document title.
2023 (when (plist-get info :with-title)
2024 (let ((title (plist-get info :title))
2025 (subtitle (plist-get info :subtitle))
2026 (html5-fancy (org-html--html5-fancy-p info)))
2027 (when title
2028 (format
2029 (if html5-fancy
2030 "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
2031 "<h1 class=\"title\">%s%s</h1>\n")
2032 (org-export-data title info)
2033 (if subtitle
2034 (format
2035 (if html5-fancy
2036 "<p class=\"subtitle\">%s</p>\n"
2037 "\n<br>\n<span class=\"subtitle\">%s</span>\n")
2038 (org-export-data subtitle info))
2039 "")))))
2040 contents
2041 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
2042 ;; Postamble.
2043 (org-html--build-pre/postamble 'postamble info)
2044 ;; Closing document.
2045 "</body>\n</html>"))
2047 (defun org-html--translate (s info)
2048 "Translate string S according to specified language.
2049 INFO is a plist used as a communication channel."
2050 (org-export-translate s :html info))
2052 ;;;; Anchor
2054 (defun org-html--anchor (id desc attributes info)
2055 "Format a HTML anchor."
2056 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
2057 (attributes (concat (and id (format " id=\"%s\"" id))
2058 (and name (format " name=\"%s\"" name))
2059 attributes)))
2060 (format "<a%s>%s</a>" attributes (or desc ""))))
2062 ;;;; Todo
2064 (defun org-html--todo (todo info)
2065 "Format TODO keywords into HTML."
2066 (when todo
2067 (format "<span class=\"%s %s%s\">%s</span>"
2068 (if (member todo org-done-keywords) "done" "todo")
2069 (or (plist-get info :html-todo-kwd-class-prefix) "")
2070 (org-html-fix-class-name todo)
2071 todo)))
2073 ;;;; Priority
2075 (defun org-html--priority (priority _info)
2076 "Format a priority into HTML.
2077 PRIORITY is the character code of the priority or nil. INFO is
2078 a plist containing export options."
2079 (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
2081 ;;;; Tags
2083 (defun org-html--tags (tags info)
2084 "Format TAGS into HTML.
2085 INFO is a plist containing export options."
2086 (when tags
2087 (format "<span class=\"tag\">%s</span>"
2088 (mapconcat
2089 (lambda (tag)
2090 (format "<span class=\"%s\">%s</span>"
2091 (concat (plist-get info :html-tag-class-prefix)
2092 (org-html-fix-class-name tag))
2093 tag))
2094 tags "&#xa0;"))))
2096 ;;;; Src Code
2098 (defun org-html-fontify-code (code lang)
2099 "Color CODE with htmlize library.
2100 CODE is a string representing the source code to colorize. LANG
2101 is the language used for CODE, as a string, or nil."
2102 (when code
2103 (cond
2104 ;; Case 1: No lang. Possibly an example block.
2105 ((not lang)
2106 ;; Simple transcoding.
2107 (org-html-encode-plain-text code))
2108 ;; Case 2: No htmlize or an inferior version of htmlize
2109 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
2110 ;; Emit a warning.
2111 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
2112 ;; Simple transcoding.
2113 (org-html-encode-plain-text code))
2114 ;; Case 3: plain text explicitly set
2115 ((not org-html-htmlize-output-type)
2116 ;; Simple transcoding.
2117 (org-html-encode-plain-text code))
2119 ;; Map language
2120 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
2121 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
2122 (cond
2123 ;; Case 1: Language is not associated with any Emacs mode
2124 ((not (functionp lang-mode))
2125 ;; Simple transcoding.
2126 (org-html-encode-plain-text code))
2127 ;; Case 2: Default. Fontify code.
2129 ;; htmlize
2130 (setq code
2131 (let ((output-type org-html-htmlize-output-type)
2132 (font-prefix org-html-htmlize-font-prefix))
2133 (with-temp-buffer
2134 ;; Switch to language-specific mode.
2135 (funcall lang-mode)
2136 (insert code)
2137 ;; Fontify buffer.
2138 (org-font-lock-ensure)
2139 ;; Remove formatting on newline characters.
2140 (save-excursion
2141 (let ((beg (point-min))
2142 (end (point-max)))
2143 (goto-char beg)
2144 (while (progn (end-of-line) (< (point) end))
2145 (put-text-property (point) (1+ (point)) 'face nil)
2146 (forward-char 1))))
2147 (org-src-mode)
2148 (set-buffer-modified-p nil)
2149 ;; Htmlize region.
2150 (let ((org-html-htmlize-output-type output-type)
2151 (org-html-htmlize-font-prefix font-prefix))
2152 (org-html-htmlize-region-for-paste
2153 (point-min) (point-max))))))
2154 ;; Strip any enclosing <pre></pre> tags.
2155 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
2156 (end (and beg (string-match "</pre>\\'" code))))
2157 (if (and beg end) (substring code beg end) code)))))))))
2159 (defun org-html-do-format-code
2160 (code &optional lang refs retain-labels num-start)
2161 "Format CODE string as source code.
2162 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
2163 respectively, the language of the source code, as a string, an
2164 alist between line numbers and references (as returned by
2165 `org-export-unravel-code'), a boolean specifying if labels should
2166 appear in the source code, and the number associated to the first
2167 line of code."
2168 (let* ((code-lines (org-split-string code "\n"))
2169 (code-length (length code-lines))
2170 (num-fmt
2171 (and num-start
2172 (format "%%%ds: "
2173 (length (number-to-string (+ code-length num-start))))))
2174 (code (org-html-fontify-code code lang)))
2175 (org-export-format-code
2176 code
2177 (lambda (loc line-num ref)
2178 (setq loc
2179 (concat
2180 ;; Add line number, if needed.
2181 (when num-start
2182 (format "<span class=\"linenr\">%s</span>"
2183 (format num-fmt line-num)))
2184 ;; Transcoded src line.
2186 ;; Add label, if needed.
2187 (when (and ref retain-labels) (format " (%s)" ref))))
2188 ;; Mark transcoded line as an anchor, if needed.
2189 (if (not ref) loc
2190 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2191 ref loc)))
2192 num-start refs)))
2194 (defun org-html-format-code (element info)
2195 "Format contents of ELEMENT as source code.
2196 ELEMENT is either an example block or a src block. INFO is
2197 a plist used as a communication channel."
2198 (let* ((lang (org-element-property :language element))
2199 ;; Extract code and references.
2200 (code-info (org-export-unravel-code element))
2201 (code (car code-info))
2202 (refs (cdr code-info))
2203 ;; Does the src block contain labels?
2204 (retain-labels (org-element-property :retain-labels element))
2205 ;; Does it have line numbers?
2206 (num-start (org-export-get-loc element info)))
2207 (org-html-do-format-code code lang refs retain-labels num-start)))
2210 ;;; Tables of Contents
2212 (defun org-html-toc (depth info &optional scope)
2213 "Build a table of contents.
2214 DEPTH is an integer specifying the depth of the table. INFO is
2215 a plist used as a communication channel. Optional argument SCOPE
2216 is an element defining the scope of the table. Return the table
2217 of contents as a string, or nil if it is empty."
2218 (let ((toc-entries
2219 (mapcar (lambda (headline)
2220 (cons (org-html--format-toc-headline headline info)
2221 (org-export-get-relative-level headline info)))
2222 (org-export-collect-headlines info depth scope))))
2223 (when toc-entries
2224 (let ((toc (concat "<div id=\"text-table-of-contents\">"
2225 (org-html--toc-text toc-entries)
2226 "</div>\n")))
2227 (if scope toc
2228 (let ((outer-tag (if (org-html--html5-fancy-p info)
2229 "nav"
2230 "div")))
2231 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2232 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2233 (format "<h%d>%s</h%d>\n"
2234 top-level
2235 (org-html--translate "Table of Contents" info)
2236 top-level))
2238 (format "</%s>\n" outer-tag))))))))
2240 (defun org-html--toc-text (toc-entries)
2241 "Return innards of a table of contents, as a string.
2242 TOC-ENTRIES is an alist where key is an entry title, as a string,
2243 and value is its relative level, as an integer."
2244 (let* ((prev-level (1- (cdar toc-entries)))
2245 (start-level prev-level))
2246 (concat
2247 (mapconcat
2248 (lambda (entry)
2249 (let ((headline (car entry))
2250 (level (cdr entry)))
2251 (concat
2252 (let* ((cnt (- level prev-level))
2253 (times (if (> cnt 0) (1- cnt) (- cnt))))
2254 (setq prev-level level)
2255 (concat
2256 (org-html--make-string
2257 times (cond ((> cnt 0) "\n<ul>\n<li>")
2258 ((< cnt 0) "</li>\n</ul>\n")))
2259 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2260 headline)))
2261 toc-entries "")
2262 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2264 (defun org-html--format-toc-headline (headline info)
2265 "Return an appropriate table of contents entry for HEADLINE.
2266 INFO is a plist used as a communication channel."
2267 (let* ((headline-number (org-export-get-headline-number headline info))
2268 (todo (and (plist-get info :with-todo-keywords)
2269 (let ((todo (org-element-property :todo-keyword headline)))
2270 (and todo (org-export-data todo info)))))
2271 (todo-type (and todo (org-element-property :todo-type headline)))
2272 (priority (and (plist-get info :with-priority)
2273 (org-element-property :priority headline)))
2274 (text (org-export-data-with-backend
2275 (org-export-get-alt-title headline info)
2276 ;; Create an anonymous back-end that will ignore any
2277 ;; footnote-reference, link, radio-target and target
2278 ;; in table of contents.
2279 (org-export-create-backend
2280 :parent 'html
2281 :transcoders '((footnote-reference . ignore)
2282 (link . (lambda (object c i) c))
2283 (radio-target . (lambda (object c i) c))
2284 (target . ignore)))
2285 info))
2286 (tags (and (eq (plist-get info :with-tags) t)
2287 (org-export-get-tags headline info))))
2288 (format "<a href=\"#%s\">%s</a>"
2289 ;; Label.
2290 (or (org-element-property :CUSTOM_ID headline)
2291 (org-export-get-reference headline info))
2292 ;; Body.
2293 (concat
2294 (and (not (org-export-low-level-p headline info))
2295 (org-export-numbered-headline-p headline info)
2296 (concat (mapconcat #'number-to-string headline-number ".")
2297 ". "))
2298 (apply (plist-get info :html-format-headline-function)
2299 todo todo-type priority text tags :section-number nil)))))
2301 (defun org-html-list-of-listings (info)
2302 "Build a list of listings.
2303 INFO is a plist used as a communication channel. Return the list
2304 of listings as a string, or nil if it is empty."
2305 (let ((lol-entries (org-export-collect-listings info)))
2306 (when lol-entries
2307 (concat "<div id=\"list-of-listings\">\n"
2308 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2309 (format "<h%d>%s</h%d>\n"
2310 top-level
2311 (org-html--translate "List of Listings" info)
2312 top-level))
2313 "<div id=\"text-list-of-listings\">\n<ul>\n"
2314 (let ((count 0)
2315 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2316 (org-html--translate "Listing %d:" info))))
2317 (mapconcat
2318 (lambda (entry)
2319 (let ((label (and (org-element-property :name entry)
2320 (org-export-get-reference entry info)))
2321 (title (org-trim
2322 (org-export-data
2323 (or (org-export-get-caption entry t)
2324 (org-export-get-caption entry))
2325 info))))
2326 (concat
2327 "<li>"
2328 (if (not label)
2329 (concat (format initial-fmt (cl-incf count))
2331 title)
2332 (format "<a href=\"#%s\">%s %s</a>"
2333 label
2334 (format initial-fmt (cl-incf count))
2335 title))
2336 "</li>")))
2337 lol-entries "\n"))
2338 "\n</ul>\n</div>\n</div>"))))
2340 (defun org-html-list-of-tables (info)
2341 "Build a list of tables.
2342 INFO is a plist used as a communication channel. Return the list
2343 of tables as a string, or nil if it is empty."
2344 (let ((lol-entries (org-export-collect-tables info)))
2345 (when lol-entries
2346 (concat "<div id=\"list-of-tables\">\n"
2347 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2348 (format "<h%d>%s</h%d>\n"
2349 top-level
2350 (org-html--translate "List of Tables" info)
2351 top-level))
2352 "<div id=\"text-list-of-tables\">\n<ul>\n"
2353 (let ((count 0)
2354 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2355 (org-html--translate "Table %d:" info))))
2356 (mapconcat
2357 (lambda (entry)
2358 (let ((label (and (org-element-property :name entry)
2359 (org-export-get-reference entry info)))
2360 (title (org-trim
2361 (org-export-data
2362 (or (org-export-get-caption entry t)
2363 (org-export-get-caption entry))
2364 info))))
2365 (concat
2366 "<li>"
2367 (if (not label)
2368 (concat (format initial-fmt (cl-incf count))
2370 title)
2371 (format "<a href=\"#%s\">%s %s</a>"
2372 label
2373 (format initial-fmt (cl-incf count))
2374 title))
2375 "</li>")))
2376 lol-entries "\n"))
2377 "\n</ul>\n</div>\n</div>"))))
2380 ;;; Transcode Functions
2382 ;;;; Bold
2384 (defun org-html-bold (_bold contents info)
2385 "Transcode BOLD from Org to HTML.
2386 CONTENTS is the text with bold markup. INFO is a plist holding
2387 contextual information."
2388 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2389 contents))
2391 ;;;; Center Block
2393 (defun org-html-center-block (_center-block contents _info)
2394 "Transcode a CENTER-BLOCK element from Org to HTML.
2395 CONTENTS holds the contents of the block. INFO is a plist
2396 holding contextual information."
2397 (format "<div class=\"org-center\">\n%s</div>" contents))
2399 ;;;; Clock
2401 (defun org-html-clock (clock _contents _info)
2402 "Transcode a CLOCK element from Org to HTML.
2403 CONTENTS is nil. INFO is a plist used as a communication
2404 channel."
2405 (format "<p>
2406 <span class=\"timestamp-wrapper\">
2407 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2408 </span>
2409 </p>"
2410 org-clock-string
2411 (org-timestamp-translate (org-element-property :value clock))
2412 (let ((time (org-element-property :duration clock)))
2413 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2415 ;;;; Code
2417 (defun org-html-code (code _contents info)
2418 "Transcode CODE from Org to HTML.
2419 CONTENTS is nil. INFO is a plist holding contextual
2420 information."
2421 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2422 (org-html-encode-plain-text (org-element-property :value code))))
2424 ;;;; Drawer
2426 (defun org-html-drawer (drawer contents info)
2427 "Transcode a DRAWER element from Org to HTML.
2428 CONTENTS holds the contents of the block. INFO is a plist
2429 holding contextual information."
2430 (funcall (plist-get info :html-format-drawer-function)
2431 (org-element-property :drawer-name drawer)
2432 contents))
2434 ;;;; Dynamic Block
2436 (defun org-html-dynamic-block (_dynamic-block contents _info)
2437 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2438 CONTENTS holds the contents of the block. INFO is a plist
2439 holding contextual information. See `org-export-data'."
2440 contents)
2442 ;;;; Entity
2444 (defun org-html-entity (entity _contents _info)
2445 "Transcode an ENTITY object from Org to HTML.
2446 CONTENTS are the definition itself. INFO is a plist holding
2447 contextual information."
2448 (org-element-property :html entity))
2450 ;;;; Example Block
2452 (defun org-html-example-block (example-block _contents info)
2453 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2454 CONTENTS is nil. INFO is a plist holding contextual
2455 information."
2456 (let ((attributes (org-export-read-attribute :attr_html example-block)))
2457 (if (plist-get attributes :textarea)
2458 (org-html--textarea-block example-block)
2459 (format "<pre class=\"example\"%s>\n%s</pre>"
2460 (let* ((name (org-element-property :name example-block))
2461 (a (org-html--make-attribute-string
2462 (if (or (not name) (plist-member attributes :id))
2463 attributes
2464 (plist-put attributes :id name)))))
2465 (if (org-string-nw-p a) (concat " " a) ""))
2466 (org-html-format-code example-block info)))))
2468 ;;;; Export Snippet
2470 (defun org-html-export-snippet (export-snippet _contents _info)
2471 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2472 CONTENTS is nil. INFO is a plist holding contextual
2473 information."
2474 (when (eq (org-export-snippet-backend export-snippet) 'html)
2475 (org-element-property :value export-snippet)))
2477 ;;;; Export Block
2479 (defun org-html-export-block (export-block _contents _info)
2480 "Transcode a EXPORT-BLOCK element from Org to HTML.
2481 CONTENTS is nil. INFO is a plist holding contextual information."
2482 (when (string= (org-element-property :type export-block) "HTML")
2483 (org-remove-indentation (org-element-property :value export-block))))
2485 ;;;; Fixed Width
2487 (defun org-html-fixed-width (fixed-width _contents _info)
2488 "Transcode a FIXED-WIDTH element from Org to HTML.
2489 CONTENTS is nil. INFO is a plist holding contextual information."
2490 (format "<pre class=\"example\">\n%s</pre>"
2491 (org-html-do-format-code
2492 (org-remove-indentation
2493 (org-element-property :value fixed-width)))))
2495 ;;;; Footnote Reference
2497 (defun org-html-footnote-reference (footnote-reference _contents info)
2498 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2499 CONTENTS is nil. INFO is a plist holding contextual information."
2500 (concat
2501 ;; Insert separator between two footnotes in a row.
2502 (let ((prev (org-export-get-previous-element footnote-reference info)))
2503 (when (eq (org-element-type prev) 'footnote-reference)
2504 (plist-get info :html-footnote-separator)))
2505 (let* ((n (org-export-get-footnote-number footnote-reference info))
2506 (id (format "fnr.%d%s"
2508 (if (org-export-footnote-first-reference-p
2509 footnote-reference info)
2511 ".100"))))
2512 (format
2513 (plist-get info :html-footnote-format)
2514 (org-html--anchor
2515 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2517 ;;;; Headline
2519 (defun org-html-headline (headline contents info)
2520 "Transcode a HEADLINE element from Org to HTML.
2521 CONTENTS holds the contents of the headline. INFO is a plist
2522 holding contextual information."
2523 (unless (org-element-property :footnote-section-p headline)
2524 (let* ((numberedp (org-export-numbered-headline-p headline info))
2525 (numbers (org-export-get-headline-number headline info))
2526 (level (+ (org-export-get-relative-level headline info)
2527 (1- (plist-get info :html-toplevel-hlevel))))
2528 (todo (and (plist-get info :with-todo-keywords)
2529 (let ((todo (org-element-property :todo-keyword headline)))
2530 (and todo (org-export-data todo info)))))
2531 (todo-type (and todo (org-element-property :todo-type headline)))
2532 (priority (and (plist-get info :with-priority)
2533 (org-element-property :priority headline)))
2534 (text (org-export-data (org-element-property :title headline) info))
2535 (tags (and (plist-get info :with-tags)
2536 (org-export-get-tags headline info)))
2537 (full-text (funcall (plist-get info :html-format-headline-function)
2538 todo todo-type priority text tags info))
2539 (contents (or contents ""))
2540 (ids (delq nil
2541 (list (org-element-property :CUSTOM_ID headline)
2542 (org-export-get-reference headline info)
2543 (org-element-property :ID headline))))
2544 (preferred-id (car ids))
2545 (extra-ids
2546 (mapconcat
2547 (lambda (id)
2548 (org-html--anchor
2549 (if (org-uuidgen-p id) (concat "ID-" id) id)
2550 nil nil info))
2551 (cdr ids) "")))
2552 (if (org-export-low-level-p headline info)
2553 ;; This is a deep sub-tree: export it as a list item.
2554 (let* ((type (if numberedp 'ordered 'unordered))
2555 (itemized-body
2556 (org-html-format-list-item
2557 contents type nil info nil
2558 (concat (org-html--anchor preferred-id nil nil info)
2559 extra-ids
2560 full-text))))
2561 (concat (and (org-export-first-sibling-p headline info)
2562 (org-html-begin-plain-list type))
2563 itemized-body
2564 (and (org-export-last-sibling-p headline info)
2565 (org-html-end-plain-list type))))
2566 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2567 (first-content (car (org-element-contents headline))))
2568 ;; Standard headline. Export it as a section.
2569 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2570 (org-html--container headline info)
2571 (concat "outline-container-"
2572 (org-export-get-reference headline info))
2573 (concat (format "outline-%d" level)
2574 (and extra-class " ")
2575 extra-class)
2576 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2577 level
2578 preferred-id
2579 extra-ids
2580 (concat
2581 (and numberedp
2582 (format
2583 "<span class=\"section-number-%d\">%s</span> "
2584 level
2585 (mapconcat #'number-to-string numbers ".")))
2586 full-text)
2587 level)
2588 ;; When there is no section, pretend there is an
2589 ;; empty one to get the correct <div
2590 ;; class="outline-...> which is needed by
2591 ;; `org-info.js'.
2592 (if (eq (org-element-type first-content) 'section) contents
2593 (concat (org-html-section first-content "" info) contents))
2594 (org-html--container headline info)))))))
2596 (defun org-html-format-headline-default-function
2597 (todo _todo-type priority text tags info)
2598 "Default format function for a headline.
2599 See `org-html-format-headline-function' for details."
2600 (let ((todo (org-html--todo todo info))
2601 (priority (org-html--priority priority info))
2602 (tags (org-html--tags tags info)))
2603 (concat todo (and todo " ")
2604 priority (and priority " ")
2605 text
2606 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2608 (defun org-html--container (headline info)
2609 (or (org-element-property :HTML_CONTAINER headline)
2610 (if (= 1 (org-export-get-relative-level headline info))
2611 (plist-get info :html-container)
2612 "div")))
2614 ;;;; Horizontal Rule
2616 (defun org-html-horizontal-rule (_horizontal-rule _contents info)
2617 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2618 CONTENTS is nil. INFO is a plist holding contextual information."
2619 (org-html-close-tag "hr" nil info))
2621 ;;;; Inline Src Block
2623 (defun org-html-inline-src-block (inline-src-block _contents info)
2624 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2625 CONTENTS holds the contents of the item. INFO is a plist holding
2626 contextual information."
2627 (let ((lang (org-element-property :language inline-src-block))
2628 (code (org-element-property :value inline-src-block))
2629 (label
2630 (let ((lbl (and (org-element-property :name inline-src-block)
2631 (org-export-get-reference inline-src-block info))))
2632 (if (not lbl) "" (format " id=\"%s\"" lbl)))))
2633 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
2635 ;;;; Inlinetask
2637 (defun org-html-inlinetask (inlinetask contents info)
2638 "Transcode an INLINETASK element from Org to HTML.
2639 CONTENTS holds the contents of the block. INFO is a plist
2640 holding contextual information."
2641 (let* ((todo (and (plist-get info :with-todo-keywords)
2642 (let ((todo (org-element-property :todo-keyword inlinetask)))
2643 (and todo (org-export-data todo info)))))
2644 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2645 (priority (and (plist-get info :with-priority)
2646 (org-element-property :priority inlinetask)))
2647 (text (org-export-data (org-element-property :title inlinetask) info))
2648 (tags (and (plist-get info :with-tags)
2649 (org-export-get-tags inlinetask info))))
2650 (funcall (plist-get info :html-format-inlinetask-function)
2651 todo todo-type priority text tags contents info)))
2653 (defun org-html-format-inlinetask-default-function
2654 (todo todo-type priority text tags contents info)
2655 "Default format function for a inlinetasks.
2656 See `org-html-format-inlinetask-function' for details."
2657 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2658 (org-html-format-headline-default-function
2659 todo todo-type priority text tags info)
2660 (org-html-close-tag "br" nil info)
2661 contents))
2663 ;;;; Italic
2665 (defun org-html-italic (_italic contents info)
2666 "Transcode ITALIC from Org to HTML.
2667 CONTENTS is the text with italic markup. INFO is a plist holding
2668 contextual information."
2669 (format
2670 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2671 contents))
2673 ;;;; Item
2675 (defun org-html-checkbox (checkbox info)
2676 "Format CHECKBOX into HTML.
2677 INFO is a plist holding contextual information. See
2678 `org-html-checkbox-type' for customization options."
2679 (cdr (assq checkbox
2680 (cdr (assq (plist-get info :html-checkbox-type)
2681 org-html-checkbox-types)))))
2683 (defun org-html-format-list-item (contents type checkbox info
2684 &optional term-counter-id
2685 headline)
2686 "Format a list item into HTML."
2687 (let ((class (if checkbox
2688 (format " class=\"%s\""
2689 (symbol-name checkbox)) ""))
2690 (checkbox (concat (org-html-checkbox checkbox info)
2691 (and checkbox " ")))
2692 (br (org-html-close-tag "br" nil info)))
2693 (concat
2694 (pcase type
2695 (`ordered
2696 (let* ((counter term-counter-id)
2697 (extra (if counter (format " value=\"%s\"" counter) "")))
2698 (concat
2699 (format "<li%s%s>" class extra)
2700 (when headline (concat headline br)))))
2701 (`unordered
2702 (let* ((id term-counter-id)
2703 (extra (if id (format " id=\"%s\"" id) "")))
2704 (concat
2705 (format "<li%s%s>" class extra)
2706 (when headline (concat headline br)))))
2707 (`descriptive
2708 (let* ((term term-counter-id))
2709 (setq term (or term "(no term)"))
2710 ;; Check-boxes in descriptive lists are associated to tag.
2711 (concat (format "<dt%s>%s</dt>"
2712 class (concat checkbox term))
2713 "<dd>"))))
2714 (unless (eq type 'descriptive) checkbox)
2715 (and contents (org-trim contents))
2716 (pcase type
2717 (`ordered "</li>")
2718 (`unordered "</li>")
2719 (`descriptive "</dd>")))))
2721 (defun org-html-item (item contents info)
2722 "Transcode an ITEM element from Org to HTML.
2723 CONTENTS holds the contents of the item. INFO is a plist holding
2724 contextual information."
2725 (let* ((plain-list (org-export-get-parent item))
2726 (type (org-element-property :type plain-list))
2727 (counter (org-element-property :counter item))
2728 (checkbox (org-element-property :checkbox item))
2729 (tag (let ((tag (org-element-property :tag item)))
2730 (and tag (org-export-data tag info)))))
2731 (org-html-format-list-item
2732 contents type checkbox info (or tag counter))))
2734 ;;;; Keyword
2736 (defun org-html-keyword (keyword _contents info)
2737 "Transcode a KEYWORD element from Org to HTML.
2738 CONTENTS is nil. INFO is a plist holding contextual information."
2739 (let ((key (org-element-property :key keyword))
2740 (value (org-element-property :value keyword)))
2741 (cond
2742 ((string= key "HTML") value)
2743 ((string= key "TOC")
2744 (let ((case-fold-search t))
2745 (cond
2746 ((string-match "\\<headlines\\>" value)
2747 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2748 (string-to-number (match-string 0 value))))
2749 (localp (string-match-p "\\<local\\>" value)))
2750 (org-html-toc depth info (and localp keyword))))
2751 ((string= "listings" value) (org-html-list-of-listings info))
2752 ((string= "tables" value) (org-html-list-of-tables info))))))))
2754 ;;;; Latex Environment
2756 (defun org-html-format-latex (latex-frag processing-type info)
2757 "Format a LaTeX fragment LATEX-FRAG into HTML.
2758 PROCESSING-TYPE designates the tool used for conversion. It can
2759 be `mathjax', `verbatim', nil, t or symbols in
2760 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
2761 `imagemagick'. See `org-html-with-latex' for more information.
2762 INFO is a plist containing export properties."
2763 (let ((cache-relpath "") (cache-dir ""))
2764 (unless (eq processing-type 'mathjax)
2765 (let ((bfn (or (buffer-file-name)
2766 (make-temp-name
2767 (expand-file-name "latex" temporary-file-directory))))
2768 (latex-header
2769 (let ((header (plist-get info :latex-header)))
2770 (and header
2771 (concat (mapconcat
2772 (lambda (line) (concat "#+LATEX_HEADER: " line))
2773 (org-split-string header "\n")
2774 "\n")
2775 "\n")))))
2776 (setq cache-relpath
2777 (concat (file-name-as-directory org-preview-latex-image-directory)
2778 (file-name-sans-extension
2779 (file-name-nondirectory bfn)))
2780 cache-dir (file-name-directory bfn))
2781 ;; Re-create LaTeX environment from original buffer in
2782 ;; temporary buffer so that dvipng/imagemagick can properly
2783 ;; turn the fragment into an image.
2784 (setq latex-frag (concat latex-header latex-frag))))
2785 (with-temp-buffer
2786 (insert latex-frag)
2787 (org-format-latex cache-relpath nil nil cache-dir nil
2788 "Creating LaTeX Image..." nil processing-type)
2789 (buffer-string))))
2791 (defun org-html-latex-environment (latex-environment _contents info)
2792 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2793 CONTENTS is nil. INFO is a plist holding contextual information."
2794 (let ((processing-type (plist-get info :with-latex))
2795 (latex-frag (org-remove-indentation
2796 (org-element-property :value latex-environment)))
2797 (attributes (org-export-read-attribute :attr_html latex-environment)))
2798 (cond
2799 ((memq processing-type '(t mathjax))
2800 (org-html-format-latex latex-frag 'mathjax info))
2801 ((assq processing-type org-preview-latex-process-alist)
2802 (let ((formula-link
2803 (org-html-format-latex latex-frag processing-type info)))
2804 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2805 ;; Do not provide a caption or a name to be consistent with
2806 ;; `mathjax' handling.
2807 (org-html--wrap-image
2808 (org-html--format-image
2809 (match-string 1 formula-link) attributes info) info))))
2810 (t latex-frag))))
2812 ;;;; Latex Fragment
2814 (defun org-html-latex-fragment (latex-fragment _contents info)
2815 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2816 CONTENTS is nil. INFO is a plist holding contextual information."
2817 (let ((latex-frag (org-element-property :value latex-fragment))
2818 (processing-type (plist-get info :with-latex)))
2819 (cond
2820 ((memq processing-type '(t mathjax))
2821 (org-html-format-latex latex-frag 'mathjax info))
2822 ((assq processing-type org-preview-latex-process-alist)
2823 (let ((formula-link
2824 (org-html-format-latex latex-frag processing-type info)))
2825 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2826 (org-html--format-image (match-string 1 formula-link) nil info))))
2827 (t latex-frag))))
2829 ;;;; Line Break
2831 (defun org-html-line-break (_line-break _contents info)
2832 "Transcode a LINE-BREAK object from Org to HTML.
2833 CONTENTS is nil. INFO is a plist holding contextual information."
2834 (concat (org-html-close-tag "br" nil info) "\n"))
2836 ;;;; Link
2838 (defun org-html-inline-image-p (link info)
2839 "Non-nil when LINK is meant to appear as an image.
2840 INFO is a plist used as a communication channel. LINK is an
2841 inline image when it has no description and targets an image
2842 file (see `org-html-inline-image-rules' for more information), or
2843 if its description is a single link targeting an image file."
2844 (if (not (org-element-contents link))
2845 (org-export-inline-image-p
2846 link (plist-get info :html-inline-image-rules))
2847 (not
2848 (let ((link-count 0))
2849 (org-element-map (org-element-contents link)
2850 (cons 'plain-text org-element-all-objects)
2851 (lambda (obj)
2852 (pcase (org-element-type obj)
2853 (`plain-text (org-string-nw-p obj))
2854 (`link (if (= link-count 1) t
2855 (cl-incf link-count)
2856 (not (org-export-inline-image-p
2857 obj (plist-get info :html-inline-image-rules)))))
2858 (_ t)))
2859 info t)))))
2861 (defvar org-html-standalone-image-predicate)
2862 (defun org-html-standalone-image-p (element info)
2863 "Non-nil if ELEMENT is a standalone image.
2865 INFO is a plist holding contextual information.
2867 An element or object is a standalone image when
2869 - its type is `paragraph' and its sole content, save for white
2870 spaces, is a link that qualifies as an inline image;
2872 - its type is `link' and its containing paragraph has no other
2873 content save white spaces.
2875 Bind `org-html-standalone-image-predicate' to constrain paragraph
2876 further. For example, to check for only captioned standalone
2877 images, set it to:
2879 (lambda (paragraph) (org-element-property :caption paragraph))"
2880 (let ((paragraph (pcase (org-element-type element)
2881 (`paragraph element)
2882 (`link (org-export-get-parent element)))))
2883 (and (eq (org-element-type paragraph) 'paragraph)
2884 (or (not (fboundp 'org-html-standalone-image-predicate))
2885 (funcall org-html-standalone-image-predicate paragraph))
2886 (catch 'exit
2887 (let ((link-count 0))
2888 (org-element-map (org-element-contents paragraph)
2889 (cons 'plain-text org-element-all-objects)
2890 (lambda (obj)
2891 (when (pcase (org-element-type obj)
2892 (`plain-text (org-string-nw-p obj))
2893 (`link (or (> (cl-incf link-count) 1)
2894 (not (org-html-inline-image-p obj info))))
2895 (_ t))
2896 (throw 'exit nil)))
2897 info nil 'link)
2898 (= link-count 1))))))
2900 (defun org-html-link (link desc info)
2901 "Transcode a LINK object from Org to HTML.
2902 DESC is the description part of the link, or the empty string.
2903 INFO is a plist holding contextual information. See
2904 `org-export-data'."
2905 (let* ((home (when (plist-get info :html-link-home)
2906 (org-trim (plist-get info :html-link-home))))
2907 (use-abs-url (plist-get info :html-link-use-abs-url))
2908 (link-org-files-as-html-maybe
2909 (lambda (raw-path info)
2910 ;; Treat links to `file.org' as links to `file.html', if
2911 ;; needed. See `org-html-link-org-files-as-html'.
2912 (cond
2913 ((and (plist-get info :html-link-org-files-as-html)
2914 (string= ".org"
2915 (downcase (file-name-extension raw-path "."))))
2916 (concat (file-name-sans-extension raw-path) "."
2917 (plist-get info :html-extension)))
2918 (t raw-path))))
2919 (type (org-element-property :type link))
2920 (raw-path (org-element-property :path link))
2921 ;; Ensure DESC really exists, or set it to nil.
2922 (desc (org-string-nw-p desc))
2923 (path
2924 (cond
2925 ((member type '("http" "https" "ftp" "mailto" "news"))
2926 (url-encode-url (org-link-unescape (concat type ":" raw-path))))
2927 ((string= type "file")
2928 ;; Treat links to ".org" files as ".html", if needed.
2929 (setq raw-path
2930 (funcall link-org-files-as-html-maybe raw-path info))
2931 ;; If file path is absolute, prepend it with protocol
2932 ;; component - "file://".
2933 (cond
2934 ((file-name-absolute-p raw-path)
2935 (setq raw-path (org-export-file-uri raw-path)))
2936 ((and home use-abs-url)
2937 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2938 ;; Add search option, if any. A search option can be
2939 ;; relative to a custom-id, a headline title, a name or
2940 ;; a target.
2941 (let ((option (org-element-property :search-option link)))
2942 (cond ((not option) raw-path)
2943 ;; Since HTML back-end use custom-id value as-is,
2944 ;; resolving is them is trivial.
2945 ((eq (string-to-char option) ?#) (concat raw-path option))
2947 (concat raw-path
2949 (org-publish-resolve-external-link
2950 option
2951 (org-element-property :path link)))))))
2952 (t raw-path)))
2953 ;; Extract attributes from parent's paragraph. HACK: Only do
2954 ;; this for the first link in parent (inner image link for
2955 ;; inline images). This is needed as long as attributes
2956 ;; cannot be set on a per link basis.
2957 (attributes-plist
2958 (let* ((parent (org-export-get-parent-element link))
2959 (link (let ((container (org-export-get-parent link)))
2960 (if (and (eq (org-element-type container) 'link)
2961 (org-html-inline-image-p link info))
2962 container
2963 link))))
2964 (and (eq (org-element-map parent 'link 'identity info t) link)
2965 (org-export-read-attribute :attr_html parent))))
2966 (attributes
2967 (let ((attr (org-html--make-attribute-string attributes-plist)))
2968 (if (org-string-nw-p attr) (concat " " attr) ""))))
2969 (cond
2970 ;; Link type is handled by a special function.
2971 ((org-export-custom-protocol-maybe link desc 'html))
2972 ;; Image file.
2973 ((and (plist-get info :html-inline-images)
2974 (org-export-inline-image-p
2975 link (plist-get info :html-inline-image-rules)))
2976 (org-html--format-image path attributes-plist info))
2977 ;; Radio target: Transcode target's contents and use them as
2978 ;; link's description.
2979 ((string= type "radio")
2980 (let ((destination (org-export-resolve-radio-link link info)))
2981 (if (not destination) desc
2982 (format "<a href=\"#%s\"%s>%s</a>"
2983 (org-export-get-reference destination info)
2984 attributes
2985 desc))))
2986 ;; Links pointing to a headline: Find destination and build
2987 ;; appropriate referencing command.
2988 ((member type '("custom-id" "fuzzy" "id"))
2989 (let ((destination (if (string= type "fuzzy")
2990 (org-export-resolve-fuzzy-link link info)
2991 (org-export-resolve-id-link link info))))
2992 (pcase (org-element-type destination)
2993 ;; ID link points to an external file.
2994 (`plain-text
2995 (let ((fragment (concat "ID-" path))
2996 ;; Treat links to ".org" files as ".html", if needed.
2997 (path (funcall link-org-files-as-html-maybe
2998 destination info)))
2999 (format "<a href=\"%s#%s\"%s>%s</a>"
3000 path fragment attributes (or desc destination))))
3001 ;; Fuzzy link points nowhere.
3002 (`nil
3003 (format "<i>%s</i>"
3004 (or desc
3005 (org-export-data
3006 (org-element-property :raw-link link) info))))
3007 ;; Link points to a headline.
3008 (`headline
3009 (let ((href (or (org-element-property :CUSTOM_ID destination)
3010 (org-export-get-reference destination info)))
3011 ;; What description to use?
3012 (desc
3013 ;; Case 1: Headline is numbered and LINK has no
3014 ;; description. Display section number.
3015 (if (and (org-export-numbered-headline-p destination info)
3016 (not desc))
3017 (mapconcat #'number-to-string
3018 (org-export-get-headline-number
3019 destination info) ".")
3020 ;; Case 2: Either the headline is un-numbered or
3021 ;; LINK has a custom description. Display LINK's
3022 ;; description or headline's title.
3023 (or desc
3024 (org-export-data
3025 (org-element-property :title destination) info)))))
3026 (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
3027 ;; Fuzzy link points to a target or an element.
3029 (let* ((ref (org-export-get-reference destination info))
3030 (org-html-standalone-image-predicate
3031 #'org-html--has-caption-p)
3032 (number (cond
3033 (desc nil)
3034 ((org-html-standalone-image-p destination info)
3035 (org-export-get-ordinal
3036 (org-element-map destination 'link
3037 #'identity info t)
3038 info 'link 'org-html-standalone-image-p))
3039 (t (org-export-get-ordinal
3040 destination info nil 'org-html--has-caption-p))))
3041 (desc (cond (desc)
3042 ((not number) "No description for this link")
3043 ((numberp number) (number-to-string number))
3044 (t (mapconcat #'number-to-string number ".")))))
3045 (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc))))))
3046 ;; Coderef: replace link with the reference name or the
3047 ;; equivalent line number.
3048 ((string= type "coderef")
3049 (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
3050 (format "<a href=\"#%s\"%s%s>%s</a>"
3051 fragment
3052 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
3053 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
3054 fragment fragment)
3055 attributes
3056 (format (org-export-get-coderef-format path desc)
3057 (org-export-resolve-coderef path info)))))
3058 ;; External link with a description part.
3059 ((and path desc) (format "<a href=\"%s\"%s>%s</a>"
3060 (org-html-encode-plain-text path)
3061 attributes
3062 desc))
3063 ;; External link without a description part.
3064 (path (let ((path (org-html-encode-plain-text path)))
3065 (format "<a href=\"%s\"%s>%s</a>"
3066 path
3067 attributes
3068 (org-link-unescape path))))
3069 ;; No path, only description. Try to do something useful.
3070 (t (format "<i>%s</i>" desc)))))
3072 ;;;; Node Property
3074 (defun org-html-node-property (node-property _contents _info)
3075 "Transcode a NODE-PROPERTY element from Org to HTML.
3076 CONTENTS is nil. INFO is a plist holding contextual
3077 information."
3078 (format "%s:%s"
3079 (org-element-property :key node-property)
3080 (let ((value (org-element-property :value node-property)))
3081 (if value (concat " " value) ""))))
3083 ;;;; Paragraph
3085 (defun org-html-paragraph (paragraph contents info)
3086 "Transcode a PARAGRAPH element from Org to HTML.
3087 CONTENTS is the contents of the paragraph, as a string. INFO is
3088 the plist used as a communication channel."
3089 (let* ((parent (org-export-get-parent paragraph))
3090 (parent-type (org-element-type parent))
3091 (style '((footnote-definition " class=\"footpara\"")
3092 (org-data " class=\"footpara\"")))
3093 (attributes (org-html--make-attribute-string
3094 (org-export-read-attribute :attr_html paragraph)))
3095 (extra (or (cadr (assq parent-type style)) "")))
3096 (cond
3097 ((and (eq parent-type 'item)
3098 (not (org-export-get-previous-element paragraph info))
3099 (let ((followers (org-export-get-next-element paragraph info 2)))
3100 (and (not (cdr followers))
3101 (memq (org-element-type (car followers)) '(nil plain-list)))))
3102 ;; First paragraph in an item has no tag if it is alone or
3103 ;; followed, at most, by a sub-list.
3104 contents)
3105 ((org-html-standalone-image-p paragraph info)
3106 ;; Standalone image.
3107 (let ((caption
3108 (let ((raw (org-export-data
3109 (org-export-get-caption paragraph) info))
3110 (org-html-standalone-image-predicate
3111 #'org-html--has-caption-p))
3112 (if (not (org-string-nw-p raw)) raw
3113 (concat "<span class=\"figure-number\">"
3114 (format (org-html--translate "Figure %d:" info)
3115 (org-export-get-ordinal
3116 (org-element-map paragraph 'link
3117 #'identity info t)
3118 info nil #'org-html-standalone-image-p))
3119 " </span>"
3120 raw))))
3121 (label (and (org-element-property :name paragraph)
3122 (org-export-get-reference paragraph info))))
3123 (org-html--wrap-image contents info caption label)))
3124 ;; Regular paragraph.
3125 (t (format "<p%s%s>\n%s</p>"
3126 (if (org-string-nw-p attributes)
3127 (concat " " attributes) "")
3128 extra contents)))))
3130 ;;;; Plain List
3132 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
3133 ;; the correct value for the item counter
3134 (defun org-html-begin-plain-list (type &optional arg1)
3135 "Insert the beginning of the HTML list depending on TYPE.
3136 When ARG1 is a string, use it as the start parameter for ordered
3137 lists."
3138 (pcase type
3139 (`ordered
3140 (format "<ol class=\"org-ol\"%s>"
3141 (if arg1 (format " start=\"%d\"" arg1) "")))
3142 (`unordered "<ul class=\"org-ul\">")
3143 (`descriptive "<dl class=\"org-dl\">")))
3145 (defun org-html-end-plain-list (type)
3146 "Insert the end of the HTML list depending on TYPE."
3147 (pcase type
3148 (`ordered "</ol>")
3149 (`unordered "</ul>")
3150 (`descriptive "</dl>")))
3152 (defun org-html-plain-list (plain-list contents _info)
3153 "Transcode a PLAIN-LIST element from Org to HTML.
3154 CONTENTS is the contents of the list. INFO is a plist holding
3155 contextual information."
3156 (let ((type (org-element-property :type plain-list)))
3157 (format "%s\n%s%s"
3158 (org-html-begin-plain-list type)
3159 contents (org-html-end-plain-list type))))
3161 ;;;; Plain Text
3163 (defun org-html-convert-special-strings (string)
3164 "Convert special characters in STRING to HTML."
3165 (dolist (a org-html-special-string-regexps string)
3166 (let ((re (car a))
3167 (rpl (cdr a)))
3168 (setq string (replace-regexp-in-string re rpl string t)))))
3170 (defun org-html-encode-plain-text (text)
3171 "Convert plain text characters from TEXT to HTML equivalent.
3172 Possible conversions are set in `org-html-protect-char-alist'."
3173 (dolist (pair org-html-protect-char-alist text)
3174 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3176 (defun org-html-plain-text (text info)
3177 "Transcode a TEXT string from Org to HTML.
3178 TEXT is the string to transcode. INFO is a plist holding
3179 contextual information."
3180 (let ((output text))
3181 ;; Protect following characters: <, >, &.
3182 (setq output (org-html-encode-plain-text output))
3183 ;; Handle smart quotes. Be sure to provide original string since
3184 ;; OUTPUT may have been modified.
3185 (when (plist-get info :with-smart-quotes)
3186 (setq output (org-export-activate-smart-quotes output :html info text)))
3187 ;; Handle special strings.
3188 (when (plist-get info :with-special-strings)
3189 (setq output (org-html-convert-special-strings output)))
3190 ;; Handle break preservation if required.
3191 (when (plist-get info :preserve-breaks)
3192 (setq output
3193 (replace-regexp-in-string
3194 "\\(\\\\\\\\\\)?[ \t]*\n"
3195 (concat (org-html-close-tag "br" nil info) "\n") output)))
3196 ;; Return value.
3197 output))
3200 ;; Planning
3202 (defun org-html-planning (planning _contents info)
3203 "Transcode a PLANNING element from Org to HTML.
3204 CONTENTS is nil. INFO is a plist used as a communication
3205 channel."
3206 (format
3207 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3208 (org-trim
3209 (mapconcat
3210 (lambda (pair)
3211 (let ((timestamp (cdr pair)))
3212 (when timestamp
3213 (let ((string (car pair)))
3214 (format "<span class=\"timestamp-kwd\">%s</span> \
3215 <span class=\"timestamp\">%s</span> "
3216 string
3217 (org-html-plain-text (org-timestamp-translate timestamp)
3218 info))))))
3219 `((,org-closed-string . ,(org-element-property :closed planning))
3220 (,org-deadline-string . ,(org-element-property :deadline planning))
3221 (,org-scheduled-string . ,(org-element-property :scheduled planning)))
3222 ""))))
3224 ;;;; Property Drawer
3226 (defun org-html-property-drawer (_property-drawer contents _info)
3227 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3228 CONTENTS holds the contents of the drawer. INFO is a plist
3229 holding contextual information."
3230 (and (org-string-nw-p contents)
3231 (format "<pre class=\"example\">\n%s</pre>" contents)))
3233 ;;;; Quote Block
3235 (defun org-html-quote-block (quote-block contents _info)
3236 "Transcode a QUOTE-BLOCK element from Org to HTML.
3237 CONTENTS holds the contents of the block. INFO is a plist
3238 holding contextual information."
3239 (format "<blockquote%s>\n%s</blockquote>"
3240 (let* ((name (org-element-property :name quote-block))
3241 (attributes (org-export-read-attribute :attr_html quote-block))
3242 (a (org-html--make-attribute-string
3243 (if (or (not name) (plist-member attributes :id))
3244 attributes
3245 (plist-put attributes :id name)))))
3246 (if (org-string-nw-p a) (concat " " a) ""))
3247 contents))
3249 ;;;; Section
3251 (defun org-html-section (section contents info)
3252 "Transcode a SECTION element from Org to HTML.
3253 CONTENTS holds the contents of the section. INFO is a plist
3254 holding contextual information."
3255 (let ((parent (org-export-get-parent-headline section)))
3256 ;; Before first headline: no container, just return CONTENTS.
3257 (if (not parent) contents
3258 ;; Get div's class and id references.
3259 (let* ((class-num (+ (org-export-get-relative-level parent info)
3260 (1- (plist-get info :html-toplevel-hlevel))))
3261 (section-number
3262 (and (org-export-numbered-headline-p parent info)
3263 (mapconcat
3264 #'number-to-string
3265 (org-export-get-headline-number parent info) "-"))))
3266 ;; Build return value.
3267 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3268 class-num
3269 (or (org-element-property :CUSTOM_ID parent)
3270 section-number
3271 (org-export-get-reference parent info))
3272 (or contents ""))))))
3274 ;;;; Radio Target
3276 (defun org-html-radio-target (radio-target text info)
3277 "Transcode a RADIO-TARGET object from Org to HTML.
3278 TEXT is the text of the target. INFO is a plist holding
3279 contextual information."
3280 (let ((ref (org-export-get-reference radio-target info)))
3281 (org-html--anchor ref text nil info)))
3283 ;;;; Special Block
3285 (defun org-html-special-block (special-block contents info)
3286 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3287 CONTENTS holds the contents of the block. INFO is a plist
3288 holding contextual information."
3289 (let* ((block-type (org-element-property :type special-block))
3290 (html5-fancy (and (org-html--html5-fancy-p info)
3291 (member block-type org-html-html5-elements)))
3292 (attributes (org-export-read-attribute :attr_html special-block)))
3293 (unless html5-fancy
3294 (let ((class (plist-get attributes :class)))
3295 (setq attributes (plist-put attributes :class
3296 (if class (concat class " " block-type)
3297 block-type)))))
3298 (let* ((contents (or contents ""))
3299 (name (org-element-property :name special-block))
3300 (a (org-html--make-attribute-string
3301 (if (or (not name) (plist-member attributes :id))
3302 attributes
3303 (plist-put attributes :id name))))
3304 (str (if (org-string-nw-p a) (concat " " a) "")))
3305 (if html5-fancy
3306 (format "<%s%s>\n%s</%s>" block-type str contents block-type)
3307 (format "<div%s>\n%s\n</div>" str contents)))))
3309 ;;;; Src Block
3311 (defun org-html-src-block (src-block _contents info)
3312 "Transcode a SRC-BLOCK element from Org to HTML.
3313 CONTENTS holds the contents of the item. INFO is a plist holding
3314 contextual information."
3315 (if (org-export-read-attribute :attr_html src-block :textarea)
3316 (org-html--textarea-block src-block)
3317 (let ((lang (org-element-property :language src-block))
3318 (code (org-html-format-code src-block info))
3319 (label (let ((lbl (and (org-element-property :name src-block)
3320 (org-export-get-reference src-block info))))
3321 (if lbl (format " id=\"%s\"" lbl) ""))))
3322 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3323 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
3324 ;; Build caption.
3325 (let ((caption (org-export-get-caption src-block)))
3326 (if (not caption) ""
3327 (let ((listing-number
3328 (format
3329 "<span class=\"listing-number\">%s </span>"
3330 (format
3331 (org-html--translate "Listing %d:" info)
3332 (org-export-get-ordinal
3333 src-block info nil #'org-html--has-caption-p)))))
3334 (format "<label class=\"org-src-name\">%s%s</label>"
3335 listing-number
3336 (org-trim (org-export-data caption info))))))
3337 ;; Contents.
3338 (format "<pre class=\"src src-%s\"%s>%s</pre>"
3339 lang label code))))))
3341 ;;;; Statistics Cookie
3343 (defun org-html-statistics-cookie (statistics-cookie _contents _info)
3344 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3345 CONTENTS is nil. INFO is a plist holding contextual information."
3346 (let ((cookie-value (org-element-property :value statistics-cookie)))
3347 (format "<code>%s</code>" cookie-value)))
3349 ;;;; Strike-Through
3351 (defun org-html-strike-through (_strike-through contents info)
3352 "Transcode STRIKE-THROUGH from Org to HTML.
3353 CONTENTS is the text with strike-through markup. INFO is a plist
3354 holding contextual information."
3355 (format
3356 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3357 "%s")
3358 contents))
3360 ;;;; Subscript
3362 (defun org-html-subscript (_subscript contents _info)
3363 "Transcode a SUBSCRIPT object from Org to HTML.
3364 CONTENTS is the contents of the object. INFO is a plist holding
3365 contextual information."
3366 (format "<sub>%s</sub>" contents))
3368 ;;;; Superscript
3370 (defun org-html-superscript (_superscript contents _info)
3371 "Transcode a SUPERSCRIPT object from Org to HTML.
3372 CONTENTS is the contents of the object. INFO is a plist holding
3373 contextual information."
3374 (format "<sup>%s</sup>" contents))
3376 ;;;; Table Cell
3378 (defun org-html-table-cell (table-cell contents info)
3379 "Transcode a TABLE-CELL element from Org to HTML.
3380 CONTENTS is nil. INFO is a plist used as a communication
3381 channel."
3382 (let* ((table-row (org-export-get-parent table-cell))
3383 (table (org-export-get-parent-table table-cell))
3384 (cell-attrs
3385 (if (not (plist-get info :html-table-align-individual-fields)) ""
3386 (format (if (and (boundp 'org-html-format-table-no-css)
3387 org-html-format-table-no-css)
3388 " align=\"%s\"" " class=\"org-%s\"")
3389 (org-export-table-cell-alignment table-cell info)))))
3390 (when (or (not contents) (string= "" (org-trim contents)))
3391 (setq contents "&#xa0;"))
3392 (cond
3393 ((and (org-export-table-has-header-p table info)
3394 (= 1 (org-export-table-row-group table-row info)))
3395 (let ((header-tags (plist-get info :html-table-header-tags)))
3396 (concat "\n" (format (car header-tags) "col" cell-attrs)
3397 contents
3398 (cdr header-tags))))
3399 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3400 (zerop (cdr (org-export-table-cell-address table-cell info))))
3401 (let ((header-tags (plist-get info :html-table-header-tags)))
3402 (concat "\n" (format (car header-tags) "row" cell-attrs)
3403 contents
3404 (cdr header-tags))))
3405 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3406 (concat "\n" (format (car data-tags) cell-attrs)
3407 contents
3408 (cdr data-tags)))))))
3410 ;;;; Table Row
3412 (defun org-html-table-row (table-row contents info)
3413 "Transcode a TABLE-ROW element from Org to HTML.
3414 CONTENTS is the contents of the row. INFO is a plist used as a
3415 communication channel."
3416 ;; Rules are ignored since table separators are deduced from
3417 ;; borders of the current row.
3418 (when (eq (org-element-property :type table-row) 'standard)
3419 (let* ((group (org-export-table-row-group table-row info))
3420 (number (org-export-table-row-number table-row info))
3421 (start-group-p
3422 (org-export-table-row-starts-rowgroup-p table-row info))
3423 (end-group-p
3424 (org-export-table-row-ends-rowgroup-p table-row info))
3425 (topp (and (equal start-group-p '(top))
3426 (equal end-group-p '(below top))))
3427 (bottomp (and (equal start-group-p '(above))
3428 (equal end-group-p '(bottom above))))
3429 (row-open-tag
3430 (pcase (plist-get info :html-table-row-open-tag)
3431 ((and accessor (pred functionp))
3432 (funcall accessor
3433 number group start-group-p end-group-p topp bottomp))
3434 (accessor accessor)))
3435 (row-close-tag
3436 (pcase (plist-get info :html-table-row-close-tag)
3437 ((and accessor (pred functionp))
3438 (funcall accessor
3439 number group start-group-p end-group-p topp bottomp))
3440 (accessor accessor)))
3441 (group-tags
3442 (cond
3443 ;; Row belongs to second or subsequent groups.
3444 ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
3445 ;; Row is from first group. Table has >=1 groups.
3446 ((org-export-table-has-header-p
3447 (org-export-get-parent-table table-row) info)
3448 '("<thead>" . "\n</thead>"))
3449 ;; Row is from first and only group.
3450 (t '("<tbody>" . "\n</tbody>")))))
3451 (concat (and start-group-p (car group-tags))
3452 (concat "\n"
3453 row-open-tag
3454 contents
3455 "\n"
3456 row-close-tag)
3457 (and end-group-p (cdr group-tags))))))
3459 ;;;; Table
3461 (defun org-html-table-first-row-data-cells (table info)
3462 "Transcode the first row of TABLE.
3463 INFO is a plist used as a communication channel."
3464 (let ((table-row
3465 (org-element-map table 'table-row
3466 (lambda (row)
3467 (unless (eq (org-element-property :type row) 'rule) row))
3468 info 'first-match))
3469 (special-column-p (org-export-table-has-special-column-p table)))
3470 (if (not special-column-p) (org-element-contents table-row)
3471 (cdr (org-element-contents table-row)))))
3473 (defun org-html-table--table.el-table (table _info)
3474 "Format table.el tables into HTML.
3475 INFO is a plist used as a communication channel."
3476 (when (eq (org-element-property :type table) 'table.el)
3477 (require 'table)
3478 (let ((outbuf (with-current-buffer
3479 (get-buffer-create "*org-export-table*")
3480 (erase-buffer) (current-buffer))))
3481 (with-temp-buffer
3482 (insert (org-element-property :value table))
3483 (goto-char 1)
3484 (re-search-forward "^[ \t]*|[^|]" nil t)
3485 (table-generate-source 'html outbuf))
3486 (with-current-buffer outbuf
3487 (prog1 (org-trim (buffer-string))
3488 (kill-buffer) )))))
3490 (defun org-html-table (table contents info)
3491 "Transcode a TABLE element from Org to HTML.
3492 CONTENTS is the contents of the table. INFO is a plist holding
3493 contextual information."
3494 (if (eq (org-element-property :type table) 'table.el)
3495 ;; "table.el" table. Convert it using appropriate tools.
3496 (org-html-table--table.el-table table info)
3497 ;; Standard table.
3498 (let* ((caption (org-export-get-caption table))
3499 (number (org-export-get-ordinal
3500 table info nil #'org-html--has-caption-p))
3501 (attributes
3502 (org-html--make-attribute-string
3503 (org-combine-plists
3504 (and (org-element-property :name table)
3505 (list :id (org-export-get-reference table info)))
3506 (and (not (org-html-html5-p info))
3507 (plist-get info :html-table-attributes))
3508 (org-export-read-attribute :attr_html table))))
3509 (alignspec
3510 (if (bound-and-true-p org-html-format-table-no-css)
3511 "align=\"%s\""
3512 "class=\"org-%s\""))
3513 (table-column-specs
3514 (lambda (table info)
3515 (mapconcat
3516 (lambda (table-cell)
3517 (let ((alignment (org-export-table-cell-alignment
3518 table-cell info)))
3519 (concat
3520 ;; Begin a colgroup?
3521 (when (org-export-table-cell-starts-colgroup-p
3522 table-cell info)
3523 "\n<colgroup>")
3524 ;; Add a column. Also specify its alignment.
3525 (format "\n%s"
3526 (org-html-close-tag
3527 "col" (concat " " (format alignspec alignment)) info))
3528 ;; End a colgroup?
3529 (when (org-export-table-cell-ends-colgroup-p
3530 table-cell info)
3531 "\n</colgroup>"))))
3532 (org-html-table-first-row-data-cells table info) "\n"))))
3533 (format "<table%s>\n%s\n%s\n%s</table>"
3534 (if (equal attributes "") "" (concat " " attributes))
3535 (if (not caption) ""
3536 (format (if (plist-get info :html-table-caption-above)
3537 "<caption class=\"t-above\">%s</caption>"
3538 "<caption class=\"t-bottom\">%s</caption>")
3539 (concat
3540 "<span class=\"table-number\">"
3541 (format (org-html--translate "Table %d:" info) number)
3542 "</span> " (org-export-data caption info))))
3543 (funcall table-column-specs table info)
3544 contents))))
3546 ;;;; Target
3548 (defun org-html-target (target _contents info)
3549 "Transcode a TARGET object from Org to HTML.
3550 CONTENTS is nil. INFO is a plist holding contextual
3551 information."
3552 (let ((ref (org-export-get-reference target info)))
3553 (org-html--anchor ref nil nil info)))
3555 ;;;; Timestamp
3557 (defun org-html-timestamp (timestamp _contents info)
3558 "Transcode a TIMESTAMP object from Org to HTML.
3559 CONTENTS is nil. INFO is a plist holding contextual
3560 information."
3561 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3562 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3563 (replace-regexp-in-string "--" "&#x2013;" value))))
3565 ;;;; Underline
3567 (defun org-html-underline (_underline contents info)
3568 "Transcode UNDERLINE from Org to HTML.
3569 CONTENTS is the text with underline markup. INFO is a plist
3570 holding contextual information."
3571 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3572 "%s")
3573 contents))
3575 ;;;; Verbatim
3577 (defun org-html-verbatim (verbatim _contents info)
3578 "Transcode VERBATIM from Org to HTML.
3579 CONTENTS is nil. INFO is a plist holding contextual
3580 information."
3581 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3582 (org-html-encode-plain-text (org-element-property :value verbatim))))
3584 ;;;; Verse Block
3586 (defun org-html-verse-block (_verse-block contents info)
3587 "Transcode a VERSE-BLOCK element from Org to HTML.
3588 CONTENTS is verse block contents. INFO is a plist holding
3589 contextual information."
3590 ;; Replace each newline character with line break. Also replace
3591 ;; each blank line with a line break.
3592 (setq contents (replace-regexp-in-string
3593 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3594 (replace-regexp-in-string
3595 "\\(\\\\\\\\\\)?[ \t]*\n"
3596 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3597 ;; Replace each white space at beginning of a line with a
3598 ;; non-breaking space.
3599 (while (string-match "^[ \t]+" contents)
3600 (let* ((num-ws (length (match-string 0 contents)))
3601 (ws (org-html--make-string num-ws "&#xa0;")))
3602 (setq contents (replace-match ws nil t contents))))
3603 (format "<p class=\"verse\">\n%s</p>" contents))
3606 ;;; Filter Functions
3608 (defun org-html-final-function (contents _backend info)
3609 "Filter to indent the HTML and convert HTML entities."
3610 (with-temp-buffer
3611 (insert contents)
3612 (set-auto-mode t)
3613 (if (plist-get info :html-indent)
3614 (indent-region (point-min) (point-max)))
3615 (buffer-substring-no-properties (point-min) (point-max))))
3618 ;;; End-user functions
3620 ;;;###autoload
3621 (defun org-html-export-as-html
3622 (&optional async subtreep visible-only body-only ext-plist)
3623 "Export current buffer to an HTML buffer.
3625 If narrowing is active in the current buffer, only export its
3626 narrowed part.
3628 If a region is active, export that region.
3630 A non-nil optional argument ASYNC means the process should happen
3631 asynchronously. The resulting buffer should be accessible
3632 through the `org-export-stack' interface.
3634 When optional argument SUBTREEP is non-nil, export the sub-tree
3635 at point, extracting information from the headline properties
3636 first.
3638 When optional argument VISIBLE-ONLY is non-nil, don't export
3639 contents of hidden elements.
3641 When optional argument BODY-ONLY is non-nil, only write code
3642 between \"<body>\" and \"</body>\" tags.
3644 EXT-PLIST, when provided, is a property list with external
3645 parameters overriding Org default settings, but still inferior to
3646 file-local settings.
3648 Export is done in a buffer named \"*Org HTML Export*\", which
3649 will be displayed when `org-export-show-temporary-export-buffer'
3650 is non-nil."
3651 (interactive)
3652 (org-export-to-buffer 'html "*Org HTML Export*"
3653 async subtreep visible-only body-only ext-plist
3654 (lambda () (set-auto-mode t))))
3656 ;;;###autoload
3657 (defun org-html-convert-region-to-html ()
3658 "Assume the current region has Org syntax, and convert it to HTML.
3659 This can be used in any buffer. For example, you can write an
3660 itemized list in Org syntax in an HTML buffer and use this command
3661 to convert it."
3662 (interactive)
3663 (org-export-replace-region-by 'html))
3665 ;;;###autoload
3666 (defun org-html-export-to-html
3667 (&optional async subtreep visible-only body-only ext-plist)
3668 "Export current buffer to a HTML file.
3670 If narrowing is active in the current buffer, only export its
3671 narrowed part.
3673 If a region is active, export that region.
3675 A non-nil optional argument ASYNC means the process should happen
3676 asynchronously. The resulting file should be accessible through
3677 the `org-export-stack' interface.
3679 When optional argument SUBTREEP is non-nil, export the sub-tree
3680 at point, extracting information from the headline properties
3681 first.
3683 When optional argument VISIBLE-ONLY is non-nil, don't export
3684 contents of hidden elements.
3686 When optional argument BODY-ONLY is non-nil, only write code
3687 between \"<body>\" and \"</body>\" tags.
3689 EXT-PLIST, when provided, is a property list with external
3690 parameters overriding Org default settings, but still inferior to
3691 file-local settings.
3693 Return output file's name."
3694 (interactive)
3695 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3696 org-html-extension
3697 "html")))
3698 (file (org-export-output-file-name extension subtreep))
3699 (org-export-coding-system org-html-coding-system))
3700 (org-export-to-file 'html file
3701 async subtreep visible-only body-only ext-plist)))
3703 ;;;###autoload
3704 (defun org-html-publish-to-html (plist filename pub-dir)
3705 "Publish an org file to HTML.
3707 FILENAME is the filename of the Org file to be published. PLIST
3708 is the property list for the given project. PUB-DIR is the
3709 publishing directory.
3711 Return output file name."
3712 (org-publish-org-to 'html filename
3713 (concat "." (or (plist-get plist :html-extension)
3714 org-html-extension
3715 "html"))
3716 plist pub-dir))
3719 (provide 'ox-html)
3721 ;; Local variables:
3722 ;; generated-autoload-file: "org-loaddefs.el"
3723 ;; End:
3725 ;;; ox-html.el ends here