Turn org-mode into Org or Org mode
[org-mode.git] / lisp / ox-html.el
blobd92e6201f3c464bc1aa39dc8a676696c1fdb6258
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-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
124 (:html-postamble nil "html-postamble" org-html-postamble)
125 (:html-preamble nil "html-preamble" org-html-preamble)
126 (:html-head "HTML_HEAD" nil org-html-head newline)
127 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
128 (:subtitle "SUBTITLE" nil nil parse)
129 (:html-head-include-default-style
130 nil "html-style" org-html-head-include-default-style)
131 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
132 (:html-allow-name-attribute-in-anchors
133 nil nil org-html-allow-name-attribute-in-anchors)
134 (:html-divs nil nil org-html-divs)
135 (:html-checkbox-type nil nil org-html-checkbox-type)
136 (:html-extension nil nil org-html-extension)
137 (:html-footnote-format nil nil org-html-footnote-format)
138 (:html-footnote-separator nil nil org-html-footnote-separator)
139 (:html-footnotes-section nil nil org-html-footnotes-section)
140 (:html-format-drawer-function nil nil org-html-format-drawer-function)
141 (:html-format-headline-function nil nil org-html-format-headline-function)
142 (:html-format-inlinetask-function
143 nil nil org-html-format-inlinetask-function)
144 (:html-home/up-format nil nil org-html-home/up-format)
145 (:html-indent nil nil org-html-indent)
146 (:html-infojs-options nil nil org-html-infojs-options)
147 (:html-infojs-template nil nil org-html-infojs-template)
148 (:html-inline-image-rules nil nil org-html-inline-image-rules)
149 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
150 (:html-mathjax-options nil nil org-html-mathjax-options)
151 (:html-mathjax-template nil nil org-html-mathjax-template)
152 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
153 (:html-postamble-format nil nil org-html-postamble-format)
154 (:html-preamble-format nil nil org-html-preamble-format)
155 (:html-table-align-individual-fields
156 nil nil org-html-table-align-individual-fields)
157 (:html-table-caption-above nil nil org-html-table-caption-above)
158 (:html-table-data-tags nil nil org-html-table-data-tags)
159 (:html-table-header-tags nil nil org-html-table-header-tags)
160 (:html-table-use-header-tags-for-first-column
161 nil nil org-html-table-use-header-tags-for-first-column)
162 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
163 (:html-text-markup-alist nil nil org-html-text-markup-alist)
164 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
165 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
166 (:html-use-infojs nil nil org-html-use-infojs)
167 (:html-validation-link nil nil org-html-validation-link)
168 (:html-viewport nil nil org-html-viewport)
169 (:html-inline-images nil nil org-html-inline-images)
170 (:html-table-attributes nil nil org-html-table-default-attributes)
171 (:html-table-row-open-tag nil nil org-html-table-row-open-tag)
172 (:html-table-row-close-tag nil nil org-html-table-row-close-tag)
173 (:html-xml-declaration nil nil org-html-xml-declaration)
174 (:infojs-opt "INFOJS_OPT" nil nil)
175 ;; Redefine regular options.
176 (:creator "CREATOR" nil org-html-creator-string)
177 (:with-latex nil "tex" org-html-with-latex)
178 ;; Retrieve LaTeX header for fragments.
179 (:latex-header "LATEX_HEADER" nil nil newline)))
182 ;;; Internal Variables
184 (defvar org-html-format-table-no-css)
185 (defvar htmlize-buffer-places) ; from htmlize.el
187 (defvar org-html--pre/postamble-class "status"
188 "CSS class used for pre/postamble")
190 (defconst org-html-doctype-alist
191 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
192 \"http://www.w3.org/TR/html4/strict.dtd\">")
193 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
194 \"http://www.w3.org/TR/html4/loose.dtd\">")
195 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
196 \"http://www.w3.org/TR/html4/frameset.dtd\">")
198 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
199 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
200 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
201 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
202 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
203 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
204 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
205 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
207 ("html5" . "<!DOCTYPE html>")
208 ("xhtml5" . "<!DOCTYPE html>"))
209 "An alist mapping (x)html flavors to specific doctypes.")
211 (defconst org-html-html5-elements
212 '("article" "aside" "audio" "canvas" "details" "figcaption"
213 "figure" "footer" "header" "menu" "meter" "nav" "output"
214 "progress" "section" "video")
215 "New elements in html5.
217 For blocks that should contain headlines, use the HTML_CONTAINER
218 property on the headline itself.")
220 (defconst org-html-special-string-regexps
221 '(("\\\\-" . "&#x00ad;") ; shy
222 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
223 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
224 ("\\.\\.\\." . "&#x2026;")) ; hellip
225 "Regular expressions for special string conversion.")
227 (defconst org-html-scripts
228 "<script type=\"text/javascript\">
230 @licstart The following is the entire license notice for the
231 JavaScript code in this tag.
233 Copyright (C) 2012-2013 Free Software Foundation, Inc.
235 The JavaScript code in this tag is free software: you can
236 redistribute it and/or modify it under the terms of the GNU
237 General Public License (GNU GPL) as published by the Free Software
238 Foundation, either version 3 of the License, or (at your option)
239 any later version. The code is distributed WITHOUT ANY WARRANTY;
240 without even the implied warranty of MERCHANTABILITY or FITNESS
241 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
243 As additional permission under GNU GPL version 3 section 7, you
244 may distribute non-source (e.g., minimized or compacted) forms of
245 that code without the copy of the GNU GPL normally required by
246 section 4, provided you include this license notice and a URL
247 through which recipients can access the Corresponding Source.
250 @licend The above is the entire license notice
251 for the JavaScript code in this tag.
253 <!--/*--><![CDATA[/*><!--*/
254 function CodeHighlightOn(elem, id)
256 var target = document.getElementById(id);
257 if(null != target) {
258 elem.cacheClassElem = elem.className;
259 elem.cacheClassTarget = target.className;
260 target.className = \"code-highlighted\";
261 elem.className = \"code-highlighted\";
264 function CodeHighlightOff(elem, id)
266 var target = document.getElementById(id);
267 if(elem.cacheClassElem)
268 elem.className = elem.cacheClassElem;
269 if(elem.cacheClassTarget)
270 target.className = elem.cacheClassTarget;
272 /*]]>*///-->
273 </script>"
274 "Basic JavaScript that is needed by HTML files produced by Org mode.")
276 (defconst org-html-style-default
277 "<style type=\"text/css\">
278 <!--/*--><![CDATA[/*><!--*/
279 .title { text-align: center;
280 margin-bottom: .2em; }
281 .subtitle { text-align: center;
282 font-size: medium;
283 font-weight: bold;
284 margin-top:0; }
285 .todo { font-family: monospace; color: red; }
286 .done { font-family: monospace; color: green; }
287 .priority { font-family: monospace; color: orange; }
288 .tag { background-color: #eee; font-family: monospace;
289 padding: 2px; font-size: 80%; font-weight: normal; }
290 .timestamp { color: #bebebe; }
291 .timestamp-kwd { color: #5f9ea0; }
292 .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
293 .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
294 .org-center { margin-left: auto; margin-right: auto; text-align: center; }
295 .underline { text-decoration: underline; }
296 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
297 p.verse { margin-left: 3%; }
298 pre {
299 border: 1px solid #ccc;
300 box-shadow: 3px 3px 3px #eee;
301 padding: 8pt;
302 font-family: monospace;
303 overflow: auto;
304 margin: 1.2em;
306 pre.src {
307 position: relative;
308 overflow: visible;
309 padding-top: 1.2em;
311 pre.src:before {
312 display: none;
313 position: absolute;
314 background-color: white;
315 top: -10px;
316 right: 10px;
317 padding: 3px;
318 border: 1px solid black;
320 pre.src:hover:before { display: inline;}
321 /* Languages per Org manual */
322 pre.src-asymptote:before { content: 'Asymptote'; }
323 pre.src-awk:before { content: 'Awk'; }
324 pre.src-C:before { content: 'C'; }
325 /* pre.src-C++ doesn't work in CSS */
326 pre.src-clojure:before { content: 'Clojure'; }
327 pre.src-css:before { content: 'CSS'; }
328 pre.src-D:before { content: 'D'; }
329 pre.src-ditaa:before { content: 'ditaa'; }
330 pre.src-dot:before { content: 'Graphviz'; }
331 pre.src-calc:before { content: 'Emacs Calc'; }
332 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
333 pre.src-fortran:before { content: 'Fortran'; }
334 pre.src-gnuplot:before { content: 'gnuplot'; }
335 pre.src-haskell:before { content: 'Haskell'; }
336 pre.src-java:before { content: 'Java'; }
337 pre.src-js:before { content: 'Javascript'; }
338 pre.src-latex:before { content: 'LaTeX'; }
339 pre.src-ledger:before { content: 'Ledger'; }
340 pre.src-lisp:before { content: 'Lisp'; }
341 pre.src-lilypond:before { content: 'Lilypond'; }
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.1"
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.1"
804 :package-version '(Org . "8.3")
805 :type 'function)
807 ;;;; LaTeX
809 (defcustom org-html-with-latex org-export-with-latex
810 "Non-nil means process LaTeX math snippets.
812 When set, the exporter will process LaTeX environments and
813 fragments.
815 This option can also be set with the +OPTIONS line,
816 e.g. \"tex:mathjax\". Allowed values are:
818 nil Ignore math snippets.
819 `verbatim' Keep everything in verbatim
820 `mathjax', t Do MathJax preprocessing and arrange for MathJax.js to
821 be loaded.
822 SYMBOL Any symbol defined in `org-preview-latex-process-alist',
823 e.g., `dvipng'."
824 :group 'org-export-html
825 :version "24.4"
826 :package-version '(Org . "8.0")
827 :type '(choice
828 (const :tag "Do not process math in any way" nil)
829 (const :tag "Leave math verbatim" verbatim)
830 (const :tag "Use MathJax to display math" mathjax)
831 (symbol :tag "Convert to image to display math" :value dvipng)))
833 ;;;; Links :: Generic
835 (defcustom org-html-link-org-files-as-html t
836 "Non-nil means make file links to `file.org' point to `file.html'.
837 When `org-mode' is exporting an `org-mode' file to HTML, links to
838 non-html files are directly put into a href tag in HTML.
839 However, links to other Org files (recognized by the extension
840 \".org\") should become links to the corresponding HTML
841 file, assuming that the linked `org-mode' file will also be
842 converted to HTML.
843 When nil, the links still point to the plain \".org\" file."
844 :group 'org-export-html
845 :type 'boolean)
847 ;;;; Links :: Inline images
849 (defcustom org-html-inline-images t
850 "Non-nil means inline images into exported HTML pages.
851 This is done using an <img> tag. When nil, an anchor with href is used to
852 link to the image."
853 :group 'org-export-html
854 :version "24.4"
855 :package-version '(Org . "8.1")
856 :type 'boolean)
858 (defcustom org-html-inline-image-rules
859 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
860 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
861 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
862 "Rules characterizing image files that can be inlined into HTML.
863 A rule consists in an association whose key is the type of link
864 to consider, and value is a regexp that will be matched against
865 link's path."
866 :group 'org-export-html
867 :version "24.4"
868 :package-version '(Org . "8.0")
869 :type '(alist :key-type (string :tag "Type")
870 :value-type (regexp :tag "Path")))
872 ;;;; Plain Text
874 (defvar org-html-protect-char-alist
875 '(("&" . "&amp;")
876 ("<" . "&lt;")
877 (">" . "&gt;"))
878 "Alist of characters to be converted by `org-html-encode-plain-text'.")
880 ;;;; Src Block
882 (defcustom org-html-htmlize-output-type 'inline-css
883 "Output type to be used by htmlize when formatting code snippets.
884 Choices are `css' to export the CSS selectors only,`inline-css'
885 to export the CSS attribute values inline in the HTML or `nil' to
886 export plain text. We use as default `inline-css', in order to
887 make the resulting HTML self-containing.
889 However, this will fail when using Emacs in batch mode for export, because
890 then no rich font definitions are in place. It will also not be good if
891 people with different Emacs setup contribute HTML files to a website,
892 because the fonts will represent the individual setups. In these cases,
893 it is much better to let Org/Htmlize assign classes only, and to use
894 a style file to define the look of these classes.
895 To get a start for your css file, start Emacs session and make sure that
896 all the faces you are interested in are defined, for example by loading files
897 in all modes you want. Then, use the command
898 \\[org-html-htmlize-generate-css] to extract class definitions."
899 :group 'org-export-html
900 :type '(choice (const css) (const inline-css) (const nil)))
902 (defcustom org-html-htmlize-font-prefix "org-"
903 "The prefix for CSS class names for htmlize font specifications."
904 :group 'org-export-html
905 :type 'string)
907 ;;;; Table
909 (defcustom org-html-table-default-attributes
910 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
911 "Default attributes and values which will be used in table tags.
912 This is a plist where attributes are symbols, starting with
913 colons, and values are strings.
915 When exporting to HTML5, these values will be disregarded."
916 :group 'org-export-html
917 :version "24.4"
918 :package-version '(Org . "8.0")
919 :type '(plist :key-type (symbol :tag "Property")
920 :value-type (string :tag "Value")))
922 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
923 "The opening and ending tags for table header fields.
924 This is customizable so that alignment options can be specified.
925 The first %s will be filled with the scope of the field, either row or col.
926 The second %s will be replaced by a style entry to align the field.
927 See also the variable `org-html-table-use-header-tags-for-first-column'.
928 See also the variable `org-html-table-align-individual-fields'."
929 :group 'org-export-html
930 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
932 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
933 "The opening and ending tags for table data fields.
934 This is customizable so that alignment options can be specified.
935 The first %s will be filled with the scope of the field, either row or col.
936 The second %s will be replaced by a style entry to align the field.
937 See also the variable `org-html-table-align-individual-fields'."
938 :group 'org-export-html
939 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
941 (defcustom org-html-table-row-open-tag "<tr>"
942 "The opening tag for table rows.
943 This is customizable so that alignment options can be specified.
944 Instead of strings, these can be a Lisp function that will be
945 evaluated for each row in order to construct the table row tags.
947 The function will be called with these arguments:
949 `number': row number (0 is the first row)
950 `group-number': group number of current row
951 `start-group-p': non-nil means the row starts a group
952 `end-group-p': non-nil means the row ends a group
953 `topp': non-nil means this is the top row
954 `bottomp': non-nil means this is the bottom row
956 For example:
958 \(setq org-html-table-row-open-tag
959 \(lambda (number group-number start-group-p end-group-p topp bottomp)
960 \(cond (topp \"<tr class=\\\"tr-top\\\">\")
961 \(bottomp \"<tr class=\\\"tr-bottom\\\">\")
962 \(t (if (= (mod number 2) 1)
963 \"<tr class=\\\"tr-odd\\\">\"
964 \"<tr class=\\\"tr-even\\\">\")))))
966 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
967 and the bottom row, and otherwise alternate between \"tr-odd\" and
968 \"tr-even\" for odd and even rows."
969 :group 'org-export-html
970 :type '(choice :tag "Opening tag"
971 (string :tag "Specify")
972 (function)))
974 (defcustom org-html-table-row-close-tag "</tr>"
975 "The closing tag for table rows.
976 This is customizable so that alignment options can be specified.
977 Instead of strings, this can be a Lisp function that will be
978 evaluated for each row in order to construct the table row tags.
980 See documentation of `org-html-table-row-open-tag'."
981 :group 'org-export-html
982 :type '(choice :tag "Closing tag"
983 (string :tag "Specify")
984 (function)))
986 (defcustom org-html-table-align-individual-fields t
987 "Non-nil means attach style attributes for alignment to each table field.
988 When nil, alignment will only be specified in the column tags, but this
989 is ignored by some browsers (like Firefox, Safari). Opera does it right
990 though."
991 :group 'org-export-html
992 :type 'boolean)
994 (defcustom org-html-table-use-header-tags-for-first-column nil
995 "Non-nil means format column one in tables with header tags.
996 When nil, also column one will use data tags."
997 :group 'org-export-html
998 :type 'boolean)
1000 (defcustom org-html-table-caption-above t
1001 "When non-nil, place caption string at the beginning of the table.
1002 Otherwise, place it near the end."
1003 :group 'org-export-html
1004 :type 'boolean)
1006 ;;;; Tags
1008 (defcustom org-html-tag-class-prefix ""
1009 "Prefix to class names for TODO keywords.
1010 Each tag gets a class given by the tag itself, with this prefix.
1011 The default prefix is empty because it is nice to just use the keyword
1012 as a class name. But if you get into conflicts with other, existing
1013 CSS classes, then this prefix can be very useful."
1014 :group 'org-export-html
1015 :type 'string)
1017 ;;;; Template :: Generic
1019 (defcustom org-html-extension "html"
1020 "The extension for exported HTML files."
1021 :group 'org-export-html
1022 :type 'string)
1024 (defcustom org-html-xml-declaration
1025 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
1026 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
1027 "The extension for exported HTML files.
1028 %s will be replaced with the charset of the exported file.
1029 This may be a string, or an alist with export extensions
1030 and corresponding declarations.
1032 This declaration only applies when exporting to XHTML."
1033 :group 'org-export-html
1034 :type '(choice
1035 (string :tag "Single declaration")
1036 (repeat :tag "Dependent on extension"
1037 (cons (string :tag "Extension")
1038 (string :tag "Declaration")))))
1040 (defcustom org-html-coding-system 'utf-8
1041 "Coding system for HTML export.
1042 Use utf-8 as the default value."
1043 :group 'org-export-html
1044 :version "24.4"
1045 :package-version '(Org . "8.0")
1046 :type 'coding-system)
1048 (defcustom org-html-doctype "xhtml-strict"
1049 "Document type definition to use for exported HTML files.
1050 Can be set with the in-buffer HTML_DOCTYPE property or for
1051 publishing, with :html-doctype."
1052 :group 'org-export-html
1053 :version "24.4"
1054 :package-version '(Org . "8.0")
1055 :type (append
1056 '(choice)
1057 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
1058 '((string :tag "Custom doctype" ))))
1060 (defcustom org-html-html5-fancy nil
1061 "Non-nil means using new HTML5 elements.
1062 This variable is ignored for anything other than HTML5 export.
1064 For compatibility with Internet Explorer, it's probably a good
1065 idea to download some form of the html5shiv (for instance
1066 https://code.google.com/p/html5shiv/) and add it to your
1067 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
1068 versions 8 and below."
1069 :group 'org-export-html
1070 :version "24.4"
1071 :package-version '(Org . "8.0")
1072 :type 'boolean)
1074 (defcustom org-html-container-element "div"
1075 "HTML element to use for wrapping top level sections.
1076 Can be set with the in-buffer HTML_CONTAINER property or for
1077 publishing, with :html-container.
1079 Note that changing the default will prevent you from using
1080 org-info.js for your website."
1081 :group 'org-export-html
1082 :version "24.4"
1083 :package-version '(Org . "8.0")
1084 :type 'string)
1086 (defcustom org-html-divs
1087 '((preamble "div" "preamble")
1088 (content "div" "content")
1089 (postamble "div" "postamble"))
1090 "Alist of the three section elements for HTML export.
1091 The car of each entry is one of `preamble', `content' or `postamble'.
1092 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1093 section of the exported document.
1095 Note that changing the default will prevent you from using
1096 org-info.js for your website."
1097 :group 'org-export-html
1098 :version "24.4"
1099 :package-version '(Org . "8.0")
1100 :type '(list :greedy t
1101 (list :tag "Preamble"
1102 (const :format "" preamble)
1103 (string :tag "element") (string :tag " id"))
1104 (list :tag "Content"
1105 (const :format "" content)
1106 (string :tag "element") (string :tag " id"))
1107 (list :tag "Postamble" (const :format "" postamble)
1108 (string :tag " id") (string :tag "element"))))
1110 (defconst org-html-checkbox-types
1111 '((unicode .
1112 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1113 (ascii .
1114 ((on . "<code>[X]</code>")
1115 (off . "<code>[&#xa0;]</code>")
1116 (trans . "<code>[-]</code>")))
1117 (html .
1118 ((on . "<input type='checkbox' checked='checked' />")
1119 (off . "<input type='checkbox' />")
1120 (trans . "<input type='checkbox' />"))))
1121 "Alist of checkbox types.
1122 The cdr of each entry is an alist list three checkbox types for
1123 HTML export: `on', `off' and `trans'.
1125 The choices are:
1126 `unicode' Unicode characters (HTML entities)
1127 `ascii' ASCII characters
1128 `html' HTML checkboxes
1130 Note that only the ascii characters implement tri-state
1131 checkboxes. The other two use the `off' checkbox for `trans'.")
1133 (defcustom org-html-checkbox-type 'ascii
1134 "The type of checkboxes to use for HTML export.
1135 See `org-html-checkbox-types' for for the values used for each
1136 option."
1137 :group 'org-export-html
1138 :version "24.4"
1139 :package-version '(Org . "8.0")
1140 :type '(choice
1141 (const :tag "ASCII characters" ascii)
1142 (const :tag "Unicode characters" unicode)
1143 (const :tag "HTML checkboxes" html)))
1145 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1146 "Format used for timestamps in preamble, postamble and metadata.
1147 See `format-time-string' for more information on its components."
1148 :group 'org-export-html
1149 :version "24.4"
1150 :package-version '(Org . "8.0")
1151 :type 'string)
1153 ;;;; Template :: Mathjax
1155 (defcustom org-html-mathjax-options
1156 '((path "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" )
1157 (scale "100")
1158 (align "center")
1159 (font "TeX")
1160 (linebreaks "false")
1161 (autonumber "AMS")
1162 (indent "0em")
1163 (multlinewidth "85%")
1164 (tagindent ".8em")
1165 (tagside "right"))
1166 "Options for MathJax setup.
1168 Alist of the following elements. All values are strings.
1170 path The path to MathJax.
1171 scale Scaling with HTML-CSS, MathML and SVG output engines.
1172 align How to align display math: left, center, or right.
1173 font The font to use with HTML-CSS and SVG output. As of MathJax 2.5
1174 the following values are understood: \"TeX\", \"STIX-Web\",
1175 \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\",
1176 \"Gyre-Termes\", and \"Latin-Modern\".
1177 linebreaks Let MathJax perform automatic linebreaks. Valid values
1178 are \"true\" and \"false\".
1179 indent If align is not center, how far from the left/right side?
1180 Valid values are \"left\" and \"right\"
1181 multlinewidth The width of the multline environment.
1182 autonumber How to number equations. Valid values are \"None\",
1183 \"all\" and \"AMS Math\".
1184 tagindent The amount tags are indented.
1185 tagside Which side to show tags/labels on. Valid values are
1186 \"left\" and \"right\"
1188 You can also customize this for each buffer, using something like
1190 #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler
1192 For further information about MathJax options, see the MathJax documentation:
1194 http://docs.mathjax.org/
1196 Please note that by using the default CDN one must agree with
1197 MathJax CDN Terms of Service.
1199 http://www.mathjax.org/mathjax-cdn-terms-of-service.html"
1200 :group 'org-export-html
1201 :package-version '(Org . "8.3")
1202 :type '(list :greedy t
1203 (list :tag "path (the path from where to load MathJax.js)"
1204 (const :format " " path) (string))
1205 (list :tag "scale (scaling for the displayed math)"
1206 (const :format " " scale) (string))
1207 (list :tag "align (alignment of displayed equations)"
1208 (const :format " " align) (string))
1209 (list :tag "font (used to display math)"
1210 (const :format " " font)
1211 (choice (const "TeX")
1212 (const "STIX-Web")
1213 (const "Asana-Math")
1214 (const "Neo-Euler")
1215 (const "Gyre-Pagella")
1216 (const "Gyre-Termes")
1217 (const "Latin-Modern")))
1218 (list :tag "linebreaks (automatic line-breaking)"
1219 (const :format " " linebreaks)
1220 (choice (const "true")
1221 (const "false")))
1222 (list :tag "autonumber (when should equations be numbered)"
1223 (const :format " " autonumber)
1224 (choice (const "AMS")
1225 (const "None")
1226 (const "All")))
1227 (list :tag "indent (indentation with left or right alignment)"
1228 (const :format " " indent) (string))
1229 (list :tag "multlinewidth (width to use for the multline environment)"
1230 (const :format " " multlinewidth) (string))
1231 (list :tag "tagindent (the indentation of tags from left or right)"
1232 (const :format " " tagindent) (string))
1233 (list :tag "tagside (location of tags)"
1234 (const :format " " tagside)
1235 (choice (const "left")
1236 (const "right")))))
1238 (defcustom org-html-mathjax-template
1239 "<script type=\"text/x-mathjax-config\">
1240 MathJax.Hub.Config({
1241 displayAlign: \"%ALIGN\",
1242 displayIndent: \"%INDENT\",
1244 \"HTML-CSS\": { scale: %SCALE,
1245 linebreaks: { automatic: \"%LINEBREAKS\" },
1246 webFont: \"%FONT\"
1248 SVG: {scale: %SCALE,
1249 linebreaks: { automatic: \"%LINEBREAKS\" },
1250 font: \"%FONT\"},
1251 NativeMML: {scale: %SCALE},
1252 TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
1253 MultLineWidth: \"%MULTLINEWIDTH\",
1254 TagSide: \"%TAGSIDE\",
1255 TagIndent: \"%TAGINDENT\"
1258 </script>
1259 <script type=\"text/javascript\"
1260 src=\"%PATH\"></script>"
1261 "The MathJax template. See also `org-html-mathjax-options'."
1262 :group 'org-export-html
1263 :type 'string)
1265 ;;;; Template :: Postamble
1267 (defcustom org-html-postamble 'auto
1268 "Non-nil means insert a postamble in HTML export.
1270 When set to `auto', check against the
1271 `org-export-with-author/email/creator/date' variables to set the
1272 content of the postamble. When set to a string, use this string
1273 as the postamble. When t, insert a string as defined by the
1274 formatting string in `org-html-postamble-format'.
1276 When set to a function, apply this function and insert the
1277 returned string. The function takes the property list of export
1278 options as its only argument.
1280 Setting :html-postamble in publishing projects will take
1281 precedence over this variable."
1282 :group 'org-export-html
1283 :type '(choice (const :tag "No postamble" nil)
1284 (const :tag "Auto postamble" auto)
1285 (const :tag "Default formatting string" t)
1286 (string :tag "Custom formatting string")
1287 (function :tag "Function (must return a string)")))
1289 (defcustom org-html-postamble-format
1290 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1291 <p class=\"date\">Date: %d</p>
1292 <p class=\"creator\">%c</p>
1293 <p class=\"validation\">%v</p>"))
1294 "Alist of languages and format strings for the HTML postamble.
1296 The first element of each list is the language code, as used for
1297 the LANGUAGE keyword. See `org-export-default-language'.
1299 The second element of each list is a format string to format the
1300 postamble itself. This format string can contain these elements:
1302 %t stands for the title.
1303 %s stands for the subtitle.
1304 %a stands for the author's name.
1305 %e stands for the author's email.
1306 %d stands for the date.
1307 %c will be replaced by `org-html-creator-string'.
1308 %v will be replaced by `org-html-validation-link'.
1309 %T will be replaced by the export time.
1310 %C will be replaced by the last modification time.
1312 If you need to use a \"%\" character, you need to escape it
1313 like that: \"%%\"."
1314 :group 'org-export-html
1315 :type '(repeat
1316 (list (string :tag "Language")
1317 (string :tag "Format string"))))
1319 (defcustom org-html-validation-link
1320 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1321 "Link to HTML validation service."
1322 :group 'org-export-html
1323 :type 'string)
1325 (defcustom org-html-creator-string
1326 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1327 emacs-version
1328 (if (fboundp 'org-version) (org-version) "unknown version"))
1329 "Information about the creator of the HTML document.
1330 This option can also be set on with the CREATOR keyword."
1331 :group 'org-export-html
1332 :version "24.4"
1333 :package-version '(Org . "8.0")
1334 :type '(string :tag "Creator string"))
1336 ;;;; Template :: Preamble
1338 (defcustom org-html-preamble t
1339 "Non-nil means insert a preamble in HTML export.
1341 When t, insert a string as defined by the formatting string in
1342 `org-html-preamble-format'. When set to a string, use this
1343 formatting string instead (see `org-html-postamble-format' for an
1344 example of such a formatting string).
1346 When set to a function, apply this function and insert the
1347 returned string. The function takes the property list of export
1348 options as its only argument.
1350 Setting :html-preamble in publishing projects will take
1351 precedence over this variable."
1352 :group 'org-export-html
1353 :type '(choice (const :tag "No preamble" nil)
1354 (const :tag "Default preamble" t)
1355 (string :tag "Custom formatting string")
1356 (function :tag "Function (must return a string)")))
1358 (defcustom org-html-preamble-format '(("en" ""))
1359 "Alist of languages and format strings for the HTML preamble.
1361 The first element of each list is the language code, as used for
1362 the LANGUAGE keyword. See `org-export-default-language'.
1364 The second element of each list is a format string to format the
1365 preamble itself. This format string can contain these elements:
1367 %t stands for the title.
1368 %s stands for the subtitle.
1369 %a stands for the author's name.
1370 %e stands for the author's email.
1371 %d stands for the date.
1372 %c will be replaced by `org-html-creator-string'.
1373 %v will be replaced by `org-html-validation-link'.
1374 %T will be replaced by the export time.
1375 %C will be replaced by the last modification time.
1377 If you need to use a \"%\" character, you need to escape it
1378 like that: \"%%\".
1380 See the default value of `org-html-postamble-format' for an
1381 example."
1382 :group 'org-export-html
1383 :type '(repeat
1384 (list (string :tag "Language")
1385 (string :tag "Format string"))))
1387 (defcustom org-html-link-up ""
1388 "Where should the \"UP\" link of exported HTML pages lead?"
1389 :group 'org-export-html
1390 :type '(string :tag "File or URL"))
1392 (defcustom org-html-link-home ""
1393 "Where should the \"HOME\" link of exported HTML pages lead?"
1394 :group 'org-export-html
1395 :type '(string :tag "File or URL"))
1397 (defcustom org-html-link-use-abs-url nil
1398 "Should we prepend relative links with HTML_LINK_HOME?"
1399 :group 'org-export-html
1400 :version "24.4"
1401 :package-version '(Org . "8.1")
1402 :type 'boolean)
1404 (defcustom org-html-home/up-format
1405 "<div id=\"org-div-home-and-up\">
1406 <a accesskey=\"h\" href=\"%s\"> UP </a>
1408 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1409 </div>"
1410 "Snippet used to insert the HOME and UP links.
1411 This is a format string, the first %s will receive the UP link,
1412 the second the HOME link. If both `org-html-link-up' and
1413 `org-html-link-home' are empty, the entire snippet will be
1414 ignored."
1415 :group 'org-export-html
1416 :type 'string)
1418 ;;;; Template :: Scripts
1420 (defcustom org-html-head-include-scripts t
1421 "Non-nil means include the JavaScript snippets in exported HTML files.
1422 The actual script is defined in `org-html-scripts' and should
1423 not be modified."
1424 :group 'org-export-html
1425 :version "24.4"
1426 :package-version '(Org . "8.0")
1427 :type 'boolean)
1429 ;;;; Template :: Styles
1431 (defcustom org-html-head-include-default-style t
1432 "Non-nil means include the default style in exported HTML files.
1433 The actual style is defined in `org-html-style-default' and
1434 should not be modified. Use `org-html-head' to use your own
1435 style information."
1436 :group 'org-export-html
1437 :version "24.4"
1438 :package-version '(Org . "8.0")
1439 :type 'boolean)
1440 ;;;###autoload
1441 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1443 (defcustom org-html-head ""
1444 "Org-wide head definitions for exported HTML files.
1446 This variable can contain the full HTML structure to provide a
1447 style, including the surrounding HTML tags. You can consider
1448 including definitions for the following classes: title, todo,
1449 done, timestamp, timestamp-kwd, tag, target.
1451 For example, a valid value would be:
1453 <style type=\"text/css\">
1454 <![CDATA[
1455 p { font-weight: normal; color: gray; }
1456 h1 { color: black; }
1457 .title { text-align: center; }
1458 .todo, .timestamp-kwd { color: red; }
1459 .done { color: green; }
1461 </style>
1463 If you want to refer to an external style, use something like
1465 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1467 As the value of this option simply gets inserted into the HTML
1468 <head> header, you can use it to add any arbitrary text to the
1469 header.
1471 You can set this on a per-file basis using #+HTML_HEAD:,
1472 or for publication projects using the :html-head property."
1473 :group 'org-export-html
1474 :version "24.4"
1475 :package-version '(Org . "8.0")
1476 :type 'string)
1477 ;;;###autoload
1478 (put 'org-html-head 'safe-local-variable 'stringp)
1480 (defcustom org-html-head-extra ""
1481 "More head information to add in the HTML output.
1483 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1484 or for publication projects using the :html-head-extra property."
1485 :group 'org-export-html
1486 :version "24.4"
1487 :package-version '(Org . "8.0")
1488 :type 'string)
1489 ;;;###autoload
1490 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1492 ;;;; Template :: Viewport
1494 (defcustom org-html-viewport '((width "device-width")
1495 (initial-scale "1")
1496 (minimum-scale "")
1497 (maximum-scale "")
1498 (user-scalable ""))
1499 "Viewport options for mobile-optimized sites.
1501 The following values are recognized
1503 width Size of the viewport.
1504 initial-scale Zoom level when the page is first loaded.
1505 minimum-scale Minimum allowed zoom level.
1506 maximum-scale Maximum allowed zoom level.
1507 user-scalable Whether zoom can be changed.
1509 The viewport meta tag is inserted if this variable is non-nil.
1511 See the following site for a reference:
1512 https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag"
1513 :group 'org-export-html
1514 :version "25.1"
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 (save-match-data
1729 (while (string-match "[^a-zA-Z0-9_]" kwd)
1730 (setq kwd (replace-match "_" t t kwd))))
1731 kwd)
1733 (defun org-html-footnote-section (info)
1734 "Format the footnote section.
1735 INFO is a plist used as a communication channel."
1736 (let* ((fn-alist (org-export-collect-footnote-definitions info))
1737 (fn-alist
1738 (cl-loop for (n _type raw) in fn-alist collect
1739 (cons n (if (eq (org-element-type raw) 'org-data)
1740 (org-trim (org-export-data raw info))
1741 (format "<div class=\"footpara\">%s</div>"
1742 (org-trim (org-export-data raw info))))))))
1743 (when fn-alist
1744 (format
1745 (plist-get info :html-footnotes-section)
1746 (org-html--translate "Footnotes" info)
1747 (format
1748 "\n%s\n"
1749 (mapconcat
1750 (lambda (fn)
1751 (let ((n (car fn)) (def (cdr fn)))
1752 (format
1753 "<div class=\"footdef\">%s %s</div>\n"
1754 (format
1755 (plist-get info :html-footnote-format)
1756 (org-html--anchor
1757 (format "fn.%d" n)
1759 (format " class=\"footnum\" href=\"#fnr.%d\"" n)
1760 info))
1761 def)))
1762 fn-alist
1763 "\n"))))))
1766 ;;; Template
1768 (defun org-html--build-meta-info (info)
1769 "Return meta tags for exported document.
1770 INFO is a plist used as a communication channel."
1771 (let ((protect-string
1772 (lambda (str)
1773 (replace-regexp-in-string
1774 "\"" "&quot;" (org-html-encode-plain-text str))))
1775 (title (org-export-data (plist-get info :title) info))
1776 (author (and (plist-get info :with-author)
1777 (let ((auth (plist-get info :author)))
1778 (and auth
1779 ;; Return raw Org syntax, skipping non
1780 ;; exportable objects.
1781 (org-element-interpret-data
1782 (org-element-map auth
1783 (cons 'plain-text org-element-all-objects)
1784 'identity info))))))
1785 (description (plist-get info :description))
1786 (keywords (plist-get info :keywords))
1787 (charset (or (and org-html-coding-system
1788 (fboundp 'coding-system-get)
1789 (coding-system-get org-html-coding-system
1790 'mime-charset))
1791 "iso-8859-1")))
1792 (concat
1793 (when (plist-get info :time-stamp-file)
1794 (format-time-string
1795 (concat "<!-- "
1796 (plist-get info :html-metadata-timestamp-format)
1797 " -->\n")))
1798 (format
1799 (if (org-html-html5-p info)
1800 (org-html-close-tag "meta" "charset=\"%s\"" info)
1801 (org-html-close-tag
1802 "meta" "http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1803 info))
1804 charset) "\n"
1805 (let ((viewport-options
1806 (cl-remove-if-not (lambda (cell) (org-string-nw-p (cadr cell)))
1807 (plist-get info :html-viewport))))
1808 (and viewport-options
1809 (concat
1810 (org-html-close-tag
1811 "meta"
1812 (format "name=\"viewport\" content=\"%s\""
1813 (mapconcat
1814 (lambda (elm) (format "%s=%s" (car elm) (cadr elm)))
1815 viewport-options ", "))
1816 info)
1817 "\n")))
1818 (format "<title>%s</title>\n" title)
1819 (org-html-close-tag "meta" "name=\"generator\" content=\"Org-mode\"" info)
1820 "\n"
1821 (and (org-string-nw-p author)
1822 (concat
1823 (org-html-close-tag "meta"
1824 (format "name=\"author\" content=\"%s\""
1825 (funcall protect-string author))
1826 info)
1827 "\n"))
1828 (and (org-string-nw-p description)
1829 (concat
1830 (org-html-close-tag "meta"
1831 (format "name=\"description\" content=\"%s\"\n"
1832 (funcall protect-string description))
1833 info)
1834 "\n"))
1835 (and (org-string-nw-p keywords)
1836 (concat
1837 (org-html-close-tag "meta"
1838 (format "name=\"keywords\" content=\"%s\""
1839 (funcall protect-string keywords))
1840 info)
1841 "\n")))))
1843 (defun org-html--build-head (info)
1844 "Return information for the <head>..</head> of the HTML output.
1845 INFO is a plist used as a communication channel."
1846 (org-element-normalize-string
1847 (concat
1848 (when (plist-get info :html-head-include-default-style)
1849 (org-element-normalize-string org-html-style-default))
1850 (org-element-normalize-string (plist-get info :html-head))
1851 (org-element-normalize-string (plist-get info :html-head-extra))
1852 (when (and (plist-get info :html-htmlized-css-url)
1853 (eq org-html-htmlize-output-type 'css))
1854 (org-html-close-tag "link"
1855 (format "rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1856 (plist-get info :html-htmlized-css-url))
1857 info))
1858 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1860 (defun org-html--build-mathjax-config (info)
1861 "Insert the user setup into the mathjax template.
1862 INFO is a plist used as a communication channel."
1863 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1864 (org-element-map (plist-get info :parse-tree)
1865 '(latex-fragment latex-environment) 'identity info t))
1866 (let ((template (plist-get info :html-mathjax-template))
1867 (options (plist-get info :html-mathjax-options))
1868 (in-buffer (or (plist-get info :html-mathjax) "")))
1869 (dolist (e options (org-element-normalize-string template))
1870 (let ((name (car e))
1871 (val (nth 1 e)))
1872 (when (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1873 (setq val
1874 (car (read-from-string (substring in-buffer (match-end 0))))))
1875 (unless (stringp val) (setq val (format "%s" val)))
1876 (while (string-match (concat "%" (upcase (symbol-name name)))
1877 template)
1878 (setq template (replace-match val t t template))))))))
1880 (defun org-html-format-spec (info)
1881 "Return format specification for elements that can be
1882 used in the preamble or postamble."
1883 `((?t . ,(org-export-data (plist-get info :title) info))
1884 (?s . ,(org-export-data (plist-get info :subtitle) info))
1885 (?d . ,(org-export-data (org-export-get-date info) info))
1886 (?T . ,(format-time-string
1887 (plist-get info :html-metadata-timestamp-format)))
1888 (?a . ,(org-export-data (plist-get info :author) info))
1889 (?e . ,(mapconcat
1890 (lambda (e)
1891 (format "<a href=\"mailto:%s\">%s</a>" e e))
1892 (split-string (plist-get info :email) ",+ *")
1893 ", "))
1894 (?c . ,(plist-get info :creator))
1895 (?C . ,(let ((file (plist-get info :input-file)))
1896 (format-time-string
1897 (plist-get info :html-metadata-timestamp-format)
1898 (when file (nth 5 (file-attributes file))))))
1899 (?v . ,(or (plist-get info :html-validation-link) ""))))
1901 (defun org-html--build-pre/postamble (type info)
1902 "Return document preamble or postamble as a string, or nil.
1903 TYPE is either `preamble' or `postamble', INFO is a plist used as a
1904 communication channel."
1905 (let ((section (plist-get info (intern (format ":html-%s" type))))
1906 (spec (org-html-format-spec info)))
1907 (when section
1908 (let ((section-contents
1909 (if (functionp section) (funcall section info)
1910 (cond
1911 ((stringp section) (format-spec section spec))
1912 ((eq section 'auto)
1913 (let ((date (cdr (assq ?d spec)))
1914 (author (cdr (assq ?a spec)))
1915 (email (cdr (assq ?e spec)))
1916 (creator (cdr (assq ?c spec)))
1917 (validation-link (cdr (assq ?v spec))))
1918 (concat
1919 (when (and (plist-get info :with-date)
1920 (org-string-nw-p date))
1921 (format "<p class=\"date\">%s: %s</p>\n"
1922 (org-html--translate "Date" info)
1923 date))
1924 (when (and (plist-get info :with-author)
1925 (org-string-nw-p author))
1926 (format "<p class=\"author\">%s: %s</p>\n"
1927 (org-html--translate "Author" info)
1928 author))
1929 (when (and (plist-get info :with-email)
1930 (org-string-nw-p email))
1931 (format "<p class=\"email\">%s: %s</p>\n"
1932 (org-html--translate "Email" info)
1933 email))
1934 (when (plist-get info :time-stamp-file)
1935 (format
1936 "<p class=\"date\">%s: %s</p>\n"
1937 (org-html--translate "Created" info)
1938 (format-time-string
1939 (plist-get info :html-metadata-timestamp-format))))
1940 (when (plist-get info :with-creator)
1941 (format "<p class=\"creator\">%s</p>\n" creator))
1942 (format "<p class=\"validation\">%s</p>\n"
1943 validation-link))))
1944 (t (format-spec
1945 (or (cadr (assoc-string
1946 (plist-get info :language)
1947 (eval (intern
1948 (format "org-html-%s-format" type)))
1950 (cadr
1951 (assoc-string
1952 "en"
1953 (eval
1954 (intern (format "org-html-%s-format" type)))
1955 t)))
1956 spec))))))
1957 (let ((div (assq type (plist-get info :html-divs))))
1958 (when (org-string-nw-p section-contents)
1959 (concat
1960 (format "<%s id=\"%s\" class=\"%s\">\n"
1961 (nth 1 div)
1962 (nth 2 div)
1963 org-html--pre/postamble-class)
1964 (org-element-normalize-string section-contents)
1965 (format "</%s>\n" (nth 1 div)))))))))
1967 (defun org-html-inner-template (contents info)
1968 "Return body of document string after HTML conversion.
1969 CONTENTS is the transcoded contents string. INFO is a plist
1970 holding export options."
1971 (concat
1972 ;; Table of contents.
1973 (let ((depth (plist-get info :with-toc)))
1974 (when depth (org-html-toc depth info)))
1975 ;; Document contents.
1976 contents
1977 ;; Footnotes section.
1978 (org-html-footnote-section info)))
1980 (defun org-html-template (contents info)
1981 "Return complete document string after HTML conversion.
1982 CONTENTS is the transcoded contents string. INFO is a plist
1983 holding export options."
1984 (concat
1985 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1986 (let* ((xml-declaration (plist-get info :html-xml-declaration))
1987 (decl (or (and (stringp xml-declaration) xml-declaration)
1988 (cdr (assoc (plist-get info :html-extension)
1989 xml-declaration))
1990 (cdr (assoc "html" xml-declaration))
1991 "")))
1992 (when (not (or (not decl) (string= "" decl)))
1993 (format "%s\n"
1994 (format decl
1995 (or (and org-html-coding-system
1996 (fboundp 'coding-system-get)
1997 (coding-system-get org-html-coding-system 'mime-charset))
1998 "iso-8859-1"))))))
1999 (org-html-doctype info)
2000 "\n"
2001 (concat "<html"
2002 (cond ((org-html-xhtml-p info)
2003 (format
2004 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
2005 (plist-get info :language) (plist-get info :language)))
2006 ((org-html-html5-p info)
2007 (format " lang=\"%s\"" (plist-get info :language))))
2008 ">\n")
2009 "<head>\n"
2010 (org-html--build-meta-info info)
2011 (org-html--build-head info)
2012 (org-html--build-mathjax-config info)
2013 "</head>\n"
2014 "<body>\n"
2015 (let ((link-up (org-trim (plist-get info :html-link-up)))
2016 (link-home (org-trim (plist-get info :html-link-home))))
2017 (unless (and (string= link-up "") (string= link-home ""))
2018 (format (plist-get info :html-home/up-format)
2019 (or link-up link-home)
2020 (or link-home link-up))))
2021 ;; Preamble.
2022 (org-html--build-pre/postamble 'preamble info)
2023 ;; Document contents.
2024 (let ((div (assq 'content (plist-get info :html-divs))))
2025 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
2026 ;; Document title.
2027 (when (plist-get info :with-title)
2028 (let ((title (plist-get info :title))
2029 (subtitle (plist-get info :subtitle))
2030 (html5-fancy (org-html--html5-fancy-p info)))
2031 (when title
2032 (format
2033 (if html5-fancy
2034 "<header>\n<h1 class=\"title\">%s</h1>\n%s</header>"
2035 "<h1 class=\"title\">%s%s</h1>\n")
2036 (org-export-data title info)
2037 (if subtitle
2038 (format
2039 (if html5-fancy
2040 "<p class=\"subtitle\">%s</p>\n"
2041 "\n<br>\n<span class=\"subtitle\">%s</span>\n")
2042 (org-export-data subtitle info))
2043 "")))))
2044 contents
2045 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
2046 ;; Postamble.
2047 (org-html--build-pre/postamble 'postamble info)
2048 ;; Closing document.
2049 "</body>\n</html>"))
2051 (defun org-html--translate (s info)
2052 "Translate string S according to specified language.
2053 INFO is a plist used as a communication channel."
2054 (org-export-translate s :html info))
2056 ;;;; Anchor
2058 (defun org-html--anchor (id desc attributes info)
2059 "Format a HTML anchor."
2060 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
2061 (attributes (concat (and id (format " id=\"%s\"" id))
2062 (and name (format " name=\"%s\"" name))
2063 attributes)))
2064 (format "<a%s>%s</a>" attributes (or desc ""))))
2066 ;;;; Todo
2068 (defun org-html--todo (todo info)
2069 "Format TODO keywords into HTML."
2070 (when todo
2071 (format "<span class=\"%s %s%s\">%s</span>"
2072 (if (member todo org-done-keywords) "done" "todo")
2073 (or (plist-get info :html-todo-kwd-class-prefix) "")
2074 (org-html-fix-class-name todo)
2075 todo)))
2077 ;;;; Priority
2079 (defun org-html--priority (priority _info)
2080 "Format a priority into HTML.
2081 PRIORITY is the character code of the priority or nil. INFO is
2082 a plist containing export options."
2083 (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
2085 ;;;; Tags
2087 (defun org-html--tags (tags info)
2088 "Format TAGS into HTML.
2089 INFO is a plist containing export options."
2090 (when tags
2091 (format "<span class=\"tag\">%s</span>"
2092 (mapconcat
2093 (lambda (tag)
2094 (format "<span class=\"%s\">%s</span>"
2095 (concat (plist-get info :html-tag-class-prefix)
2096 (org-html-fix-class-name tag))
2097 tag))
2098 tags "&#xa0;"))))
2100 ;;;; Src Code
2102 (defun org-html-fontify-code (code lang)
2103 "Color CODE with htmlize library.
2104 CODE is a string representing the source code to colorize. LANG
2105 is the language used for CODE, as a string, or nil."
2106 (when code
2107 (cond
2108 ;; Case 1: No lang. Possibly an example block.
2109 ((not lang)
2110 ;; Simple transcoding.
2111 (org-html-encode-plain-text code))
2112 ;; Case 2: No htmlize or an inferior version of htmlize
2113 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
2114 ;; Emit a warning.
2115 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
2116 ;; Simple transcoding.
2117 (org-html-encode-plain-text code))
2118 ;; Case 3: plain text explicitly set
2119 ((not org-html-htmlize-output-type)
2120 ;; Simple transcoding.
2121 (org-html-encode-plain-text code))
2123 ;; Map language
2124 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
2125 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
2126 (cond
2127 ;; Case 1: Language is not associated with any Emacs mode
2128 ((not (functionp lang-mode))
2129 ;; Simple transcoding.
2130 (org-html-encode-plain-text code))
2131 ;; Case 2: Default. Fontify code.
2133 ;; htmlize
2134 (setq code
2135 (let ((output-type org-html-htmlize-output-type)
2136 (font-prefix org-html-htmlize-font-prefix))
2137 (with-temp-buffer
2138 ;; Switch to language-specific mode.
2139 (funcall lang-mode)
2140 (insert code)
2141 ;; Fontify buffer.
2142 (org-font-lock-ensure)
2143 ;; Remove formatting on newline characters.
2144 (save-excursion
2145 (let ((beg (point-min))
2146 (end (point-max)))
2147 (goto-char beg)
2148 (while (progn (end-of-line) (< (point) end))
2149 (put-text-property (point) (1+ (point)) 'face nil)
2150 (forward-char 1))))
2151 (org-src-mode)
2152 (set-buffer-modified-p nil)
2153 ;; Htmlize region.
2154 (let ((org-html-htmlize-output-type output-type)
2155 (org-html-htmlize-font-prefix font-prefix))
2156 (org-html-htmlize-region-for-paste
2157 (point-min) (point-max))))))
2158 ;; Strip any enclosing <pre></pre> tags.
2159 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
2160 (end (and beg (string-match "</pre>\\'" code))))
2161 (if (and beg end) (substring code beg end) code)))))))))
2163 (defun org-html-do-format-code
2164 (code &optional lang refs retain-labels num-start)
2165 "Format CODE string as source code.
2166 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
2167 respectively, the language of the source code, as a string, an
2168 alist between line numbers and references (as returned by
2169 `org-export-unravel-code'), a boolean specifying if labels should
2170 appear in the source code, and the number associated to the first
2171 line of code."
2172 (let* ((code-lines (org-split-string code "\n"))
2173 (code-length (length code-lines))
2174 (num-fmt
2175 (and num-start
2176 (format "%%%ds: "
2177 (length (number-to-string (+ code-length num-start))))))
2178 (code (org-html-fontify-code code lang)))
2179 (org-export-format-code
2180 code
2181 (lambda (loc line-num ref)
2182 (setq loc
2183 (concat
2184 ;; Add line number, if needed.
2185 (when num-start
2186 (format "<span class=\"linenr\">%s</span>"
2187 (format num-fmt line-num)))
2188 ;; Transcoded src line.
2190 ;; Add label, if needed.
2191 (when (and ref retain-labels) (format " (%s)" ref))))
2192 ;; Mark transcoded line as an anchor, if needed.
2193 (if (not ref) loc
2194 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2195 ref loc)))
2196 num-start refs)))
2198 (defun org-html-format-code (element info)
2199 "Format contents of ELEMENT as source code.
2200 ELEMENT is either an example block or a src block. INFO is
2201 a plist used as a communication channel."
2202 (let* ((lang (org-element-property :language element))
2203 ;; Extract code and references.
2204 (code-info (org-export-unravel-code element))
2205 (code (car code-info))
2206 (refs (cdr code-info))
2207 ;; Does the src block contain labels?
2208 (retain-labels (org-element-property :retain-labels element))
2209 ;; Does it have line numbers?
2210 (num-start (org-export-get-loc element info)))
2211 (org-html-do-format-code code lang refs retain-labels num-start)))
2214 ;;; Tables of Contents
2216 (defun org-html-toc (depth info &optional scope)
2217 "Build a table of contents.
2218 DEPTH is an integer specifying the depth of the table. INFO is
2219 a plist used as a communication channel. Optional argument SCOPE
2220 is an element defining the scope of the table. Return the table
2221 of contents as a string, or nil if it is empty."
2222 (let ((toc-entries
2223 (mapcar (lambda (headline)
2224 (cons (org-html--format-toc-headline headline info)
2225 (org-export-get-relative-level headline info)))
2226 (org-export-collect-headlines info depth scope))))
2227 (when toc-entries
2228 (let ((toc (concat "<div id=\"text-table-of-contents\">"
2229 (org-html--toc-text toc-entries)
2230 "</div>\n")))
2231 (if scope toc
2232 (let ((outer-tag (if (org-html--html5-fancy-p info)
2233 "nav"
2234 "div")))
2235 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2236 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2237 (format "<h%d>%s</h%d>\n"
2238 top-level
2239 (org-html--translate "Table of Contents" info)
2240 top-level))
2242 (format "</%s>\n" outer-tag))))))))
2244 (defun org-html--toc-text (toc-entries)
2245 "Return innards of a table of contents, as a string.
2246 TOC-ENTRIES is an alist where key is an entry title, as a string,
2247 and value is its relative level, as an integer."
2248 (let* ((prev-level (1- (cdar toc-entries)))
2249 (start-level prev-level))
2250 (concat
2251 (mapconcat
2252 (lambda (entry)
2253 (let ((headline (car entry))
2254 (level (cdr entry)))
2255 (concat
2256 (let* ((cnt (- level prev-level))
2257 (times (if (> cnt 0) (1- cnt) (- cnt))))
2258 (setq prev-level level)
2259 (concat
2260 (org-html--make-string
2261 times (cond ((> cnt 0) "\n<ul>\n<li>")
2262 ((< cnt 0) "</li>\n</ul>\n")))
2263 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2264 headline)))
2265 toc-entries "")
2266 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2268 (defun org-html--format-toc-headline (headline info)
2269 "Return an appropriate table of contents entry for HEADLINE.
2270 INFO is a plist used as a communication channel."
2271 (let* ((headline-number (org-export-get-headline-number headline info))
2272 (todo (and (plist-get info :with-todo-keywords)
2273 (let ((todo (org-element-property :todo-keyword headline)))
2274 (and todo (org-export-data todo info)))))
2275 (todo-type (and todo (org-element-property :todo-type headline)))
2276 (priority (and (plist-get info :with-priority)
2277 (org-element-property :priority headline)))
2278 (text (org-export-data-with-backend
2279 (org-export-get-alt-title headline info)
2280 ;; Create an anonymous back-end that will ignore any
2281 ;; footnote-reference, link, radio-target and target
2282 ;; in table of contents.
2283 (org-export-create-backend
2284 :parent 'html
2285 :transcoders '((footnote-reference . ignore)
2286 (link . (lambda (object c i) c))
2287 (radio-target . (lambda (object c i) c))
2288 (target . ignore)))
2289 info))
2290 (tags (and (eq (plist-get info :with-tags) t)
2291 (org-export-get-tags headline info))))
2292 (format "<a href=\"#%s\">%s</a>"
2293 ;; Label.
2294 (or (org-element-property :CUSTOM_ID headline)
2295 (org-export-get-reference headline info))
2296 ;; Body.
2297 (concat
2298 (and (not (org-export-low-level-p headline info))
2299 (org-export-numbered-headline-p headline info)
2300 (concat (mapconcat #'number-to-string headline-number ".")
2301 ". "))
2302 (apply (plist-get info :html-format-headline-function)
2303 todo todo-type priority text tags :section-number nil)))))
2305 (defun org-html-list-of-listings (info)
2306 "Build a list of listings.
2307 INFO is a plist used as a communication channel. Return the list
2308 of listings as a string, or nil if it is empty."
2309 (let ((lol-entries (org-export-collect-listings info)))
2310 (when lol-entries
2311 (concat "<div id=\"list-of-listings\">\n"
2312 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2313 (format "<h%d>%s</h%d>\n"
2314 top-level
2315 (org-html--translate "List of Listings" info)
2316 top-level))
2317 "<div id=\"text-list-of-listings\">\n<ul>\n"
2318 (let ((count 0)
2319 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2320 (org-html--translate "Listing %d:" info))))
2321 (mapconcat
2322 (lambda (entry)
2323 (let ((label (and (org-element-property :name entry)
2324 (org-export-get-reference entry info)))
2325 (title (org-trim
2326 (org-export-data
2327 (or (org-export-get-caption entry t)
2328 (org-export-get-caption entry))
2329 info))))
2330 (concat
2331 "<li>"
2332 (if (not label)
2333 (concat (format initial-fmt (cl-incf count))
2335 title)
2336 (format "<a href=\"#%s\">%s %s</a>"
2337 label
2338 (format initial-fmt (cl-incf count))
2339 title))
2340 "</li>")))
2341 lol-entries "\n"))
2342 "\n</ul>\n</div>\n</div>"))))
2344 (defun org-html-list-of-tables (info)
2345 "Build a list of tables.
2346 INFO is a plist used as a communication channel. Return the list
2347 of tables as a string, or nil if it is empty."
2348 (let ((lol-entries (org-export-collect-tables info)))
2349 (when lol-entries
2350 (concat "<div id=\"list-of-tables\">\n"
2351 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2352 (format "<h%d>%s</h%d>\n"
2353 top-level
2354 (org-html--translate "List of Tables" info)
2355 top-level))
2356 "<div id=\"text-list-of-tables\">\n<ul>\n"
2357 (let ((count 0)
2358 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2359 (org-html--translate "Table %d:" info))))
2360 (mapconcat
2361 (lambda (entry)
2362 (let ((label (and (org-element-property :name entry)
2363 (org-export-get-reference entry info)))
2364 (title (org-trim
2365 (org-export-data
2366 (or (org-export-get-caption entry t)
2367 (org-export-get-caption entry))
2368 info))))
2369 (concat
2370 "<li>"
2371 (if (not label)
2372 (concat (format initial-fmt (cl-incf count))
2374 title)
2375 (format "<a href=\"#%s\">%s %s</a>"
2376 label
2377 (format initial-fmt (cl-incf count))
2378 title))
2379 "</li>")))
2380 lol-entries "\n"))
2381 "\n</ul>\n</div>\n</div>"))))
2384 ;;; Transcode Functions
2386 ;;;; Bold
2388 (defun org-html-bold (_bold contents info)
2389 "Transcode BOLD from Org to HTML.
2390 CONTENTS is the text with bold markup. INFO is a plist holding
2391 contextual information."
2392 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2393 contents))
2395 ;;;; Center Block
2397 (defun org-html-center-block (_center-block contents _info)
2398 "Transcode a CENTER-BLOCK element from Org to HTML.
2399 CONTENTS holds the contents of the block. INFO is a plist
2400 holding contextual information."
2401 (format "<div class=\"org-center\">\n%s</div>" contents))
2403 ;;;; Clock
2405 (defun org-html-clock (clock _contents _info)
2406 "Transcode a CLOCK element from Org to HTML.
2407 CONTENTS is nil. INFO is a plist used as a communication
2408 channel."
2409 (format "<p>
2410 <span class=\"timestamp-wrapper\">
2411 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2412 </span>
2413 </p>"
2414 org-clock-string
2415 (org-timestamp-translate (org-element-property :value clock))
2416 (let ((time (org-element-property :duration clock)))
2417 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2419 ;;;; Code
2421 (defun org-html-code (code _contents info)
2422 "Transcode CODE from Org to HTML.
2423 CONTENTS is nil. INFO is a plist holding contextual
2424 information."
2425 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2426 (org-html-encode-plain-text (org-element-property :value code))))
2428 ;;;; Drawer
2430 (defun org-html-drawer (drawer contents info)
2431 "Transcode a DRAWER element from Org to HTML.
2432 CONTENTS holds the contents of the block. INFO is a plist
2433 holding contextual information."
2434 (funcall (plist-get info :html-format-drawer-function)
2435 (org-element-property :drawer-name drawer)
2436 contents))
2438 ;;;; Dynamic Block
2440 (defun org-html-dynamic-block (_dynamic-block contents _info)
2441 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2442 CONTENTS holds the contents of the block. INFO is a plist
2443 holding contextual information. See `org-export-data'."
2444 contents)
2446 ;;;; Entity
2448 (defun org-html-entity (entity _contents _info)
2449 "Transcode an ENTITY object from Org to HTML.
2450 CONTENTS are the definition itself. INFO is a plist holding
2451 contextual information."
2452 (org-element-property :html entity))
2454 ;;;; Example Block
2456 (defun org-html-example-block (example-block _contents info)
2457 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2458 CONTENTS is nil. INFO is a plist holding contextual
2459 information."
2460 (let ((attributes (org-export-read-attribute :attr_html example-block)))
2461 (if (plist-get attributes :textarea)
2462 (org-html--textarea-block example-block)
2463 (format "<pre class=\"example\"%s>\n%s</pre>"
2464 (let* ((name (org-element-property :name example-block))
2465 (a (org-html--make-attribute-string
2466 (if (or (not name) (plist-member attributes :id))
2467 attributes
2468 (plist-put attributes :id name)))))
2469 (if (org-string-nw-p a) (concat " " a) ""))
2470 (org-html-format-code example-block info)))))
2472 ;;;; Export Snippet
2474 (defun org-html-export-snippet (export-snippet _contents _info)
2475 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2476 CONTENTS is nil. INFO is a plist holding contextual
2477 information."
2478 (when (eq (org-export-snippet-backend export-snippet) 'html)
2479 (org-element-property :value export-snippet)))
2481 ;;;; Export Block
2483 (defun org-html-export-block (export-block _contents _info)
2484 "Transcode a EXPORT-BLOCK element from Org to HTML.
2485 CONTENTS is nil. INFO is a plist holding contextual information."
2486 (when (string= (org-element-property :type export-block) "HTML")
2487 (org-remove-indentation (org-element-property :value export-block))))
2489 ;;;; Fixed Width
2491 (defun org-html-fixed-width (fixed-width _contents _info)
2492 "Transcode a FIXED-WIDTH element from Org to HTML.
2493 CONTENTS is nil. INFO is a plist holding contextual information."
2494 (format "<pre class=\"example\">\n%s</pre>"
2495 (org-html-do-format-code
2496 (org-remove-indentation
2497 (org-element-property :value fixed-width)))))
2499 ;;;; Footnote Reference
2501 (defun org-html-footnote-reference (footnote-reference _contents info)
2502 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2503 CONTENTS is nil. INFO is a plist holding contextual information."
2504 (concat
2505 ;; Insert separator between two footnotes in a row.
2506 (let ((prev (org-export-get-previous-element footnote-reference info)))
2507 (when (eq (org-element-type prev) 'footnote-reference)
2508 (plist-get info :html-footnote-separator)))
2509 (let* ((n (org-export-get-footnote-number footnote-reference info))
2510 (id (format "fnr.%d%s"
2512 (if (org-export-footnote-first-reference-p
2513 footnote-reference info)
2515 ".100"))))
2516 (format
2517 (plist-get info :html-footnote-format)
2518 (org-html--anchor
2519 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2521 ;;;; Headline
2523 (defun org-html-headline (headline contents info)
2524 "Transcode a HEADLINE element from Org to HTML.
2525 CONTENTS holds the contents of the headline. INFO is a plist
2526 holding contextual information."
2527 (unless (org-element-property :footnote-section-p headline)
2528 (let* ((numberedp (org-export-numbered-headline-p headline info))
2529 (numbers (org-export-get-headline-number headline info))
2530 (level (+ (org-export-get-relative-level headline info)
2531 (1- (plist-get info :html-toplevel-hlevel))))
2532 (todo (and (plist-get info :with-todo-keywords)
2533 (let ((todo (org-element-property :todo-keyword headline)))
2534 (and todo (org-export-data todo info)))))
2535 (todo-type (and todo (org-element-property :todo-type headline)))
2536 (priority (and (plist-get info :with-priority)
2537 (org-element-property :priority headline)))
2538 (text (org-export-data (org-element-property :title headline) info))
2539 (tags (and (plist-get info :with-tags)
2540 (org-export-get-tags headline info)))
2541 (full-text (funcall (plist-get info :html-format-headline-function)
2542 todo todo-type priority text tags info))
2543 (contents (or contents ""))
2544 (ids (delq nil
2545 (list (org-element-property :CUSTOM_ID headline)
2546 (org-export-get-reference headline info)
2547 (org-element-property :ID headline))))
2548 (preferred-id (car ids))
2549 (extra-ids
2550 (mapconcat
2551 (lambda (id)
2552 (org-html--anchor
2553 (if (org-uuidgen-p id) (concat "ID-" id) id)
2554 nil nil info))
2555 (cdr ids) "")))
2556 (if (org-export-low-level-p headline info)
2557 ;; This is a deep sub-tree: export it as a list item.
2558 (let* ((type (if numberedp 'ordered 'unordered))
2559 (itemized-body
2560 (org-html-format-list-item
2561 contents type nil info nil
2562 (concat (org-html--anchor preferred-id nil nil info)
2563 extra-ids
2564 full-text))))
2565 (concat (and (org-export-first-sibling-p headline info)
2566 (org-html-begin-plain-list type))
2567 itemized-body
2568 (and (org-export-last-sibling-p headline info)
2569 (org-html-end-plain-list type))))
2570 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2571 (first-content (car (org-element-contents headline))))
2572 ;; Standard headline. Export it as a section.
2573 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2574 (org-html--container headline info)
2575 (concat "outline-container-"
2576 (org-export-get-reference headline info))
2577 (concat (format "outline-%d" level)
2578 (and extra-class " ")
2579 extra-class)
2580 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2581 level
2582 preferred-id
2583 extra-ids
2584 (concat
2585 (and numberedp
2586 (format
2587 "<span class=\"section-number-%d\">%s</span> "
2588 level
2589 (mapconcat #'number-to-string numbers ".")))
2590 full-text)
2591 level)
2592 ;; When there is no section, pretend there is an
2593 ;; empty one to get the correct <div
2594 ;; class="outline-...> which is needed by
2595 ;; `org-info.js'.
2596 (if (eq (org-element-type first-content) 'section) contents
2597 (concat (org-html-section first-content "" info) contents))
2598 (org-html--container headline info)))))))
2600 (defun org-html-format-headline-default-function
2601 (todo _todo-type priority text tags info)
2602 "Default format function for a headline.
2603 See `org-html-format-headline-function' for details."
2604 (let ((todo (org-html--todo todo info))
2605 (priority (org-html--priority priority info))
2606 (tags (org-html--tags tags info)))
2607 (concat todo (and todo " ")
2608 priority (and priority " ")
2609 text
2610 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2612 (defun org-html--container (headline info)
2613 (or (org-element-property :HTML_CONTAINER headline)
2614 (if (= 1 (org-export-get-relative-level headline info))
2615 (plist-get info :html-container)
2616 "div")))
2618 ;;;; Horizontal Rule
2620 (defun org-html-horizontal-rule (_horizontal-rule _contents info)
2621 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2622 CONTENTS is nil. INFO is a plist holding contextual information."
2623 (org-html-close-tag "hr" nil info))
2625 ;;;; Inline Src Block
2627 (defun org-html-inline-src-block (inline-src-block _contents info)
2628 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2629 CONTENTS holds the contents of the item. INFO is a plist holding
2630 contextual information."
2631 (let ((lang (org-element-property :language inline-src-block))
2632 (code (org-html-format-code inline-src-block info))
2633 (label
2634 (let ((lbl (and (org-element-property :name inline-src-block)
2635 (org-export-get-reference inline-src-block info))))
2636 (if (not lbl) "" (format " id=\"%s\"" lbl)))))
2637 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
2639 ;;;; Inlinetask
2641 (defun org-html-inlinetask (inlinetask contents info)
2642 "Transcode an INLINETASK element from Org to HTML.
2643 CONTENTS holds the contents of the block. INFO is a plist
2644 holding contextual information."
2645 (let* ((todo (and (plist-get info :with-todo-keywords)
2646 (let ((todo (org-element-property :todo-keyword inlinetask)))
2647 (and todo (org-export-data todo info)))))
2648 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2649 (priority (and (plist-get info :with-priority)
2650 (org-element-property :priority inlinetask)))
2651 (text (org-export-data (org-element-property :title inlinetask) info))
2652 (tags (and (plist-get info :with-tags)
2653 (org-export-get-tags inlinetask info))))
2654 (funcall (plist-get info :html-format-inlinetask-function)
2655 todo todo-type priority text tags contents info)))
2657 (defun org-html-format-inlinetask-default-function
2658 (todo todo-type priority text tags contents info)
2659 "Default format function for a inlinetasks.
2660 See `org-html-format-inlinetask-function' for details."
2661 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2662 (org-html-format-headline-default-function
2663 todo todo-type priority text tags info)
2664 (org-html-close-tag "br" nil info)
2665 contents))
2667 ;;;; Italic
2669 (defun org-html-italic (_italic contents info)
2670 "Transcode ITALIC from Org to HTML.
2671 CONTENTS is the text with italic markup. INFO is a plist holding
2672 contextual information."
2673 (format
2674 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2675 contents))
2677 ;;;; Item
2679 (defun org-html-checkbox (checkbox info)
2680 "Format CHECKBOX into HTML.
2681 INFO is a plist holding contextual information. See
2682 `org-html-checkbox-type' for customization options."
2683 (cdr (assq checkbox
2684 (cdr (assq (plist-get info :html-checkbox-type)
2685 org-html-checkbox-types)))))
2687 (defun org-html-format-list-item (contents type checkbox info
2688 &optional term-counter-id
2689 headline)
2690 "Format a list item into HTML."
2691 (let ((class (if checkbox
2692 (format " class=\"%s\""
2693 (symbol-name checkbox)) ""))
2694 (checkbox (concat (org-html-checkbox checkbox info)
2695 (and checkbox " ")))
2696 (br (org-html-close-tag "br" nil info)))
2697 (concat
2698 (pcase type
2699 (`ordered
2700 (let* ((counter term-counter-id)
2701 (extra (if counter (format " value=\"%s\"" counter) "")))
2702 (concat
2703 (format "<li%s%s>" class extra)
2704 (when headline (concat headline br)))))
2705 (`unordered
2706 (let* ((id term-counter-id)
2707 (extra (if id (format " id=\"%s\"" id) "")))
2708 (concat
2709 (format "<li%s%s>" class extra)
2710 (when headline (concat headline br)))))
2711 (`descriptive
2712 (let* ((term term-counter-id))
2713 (setq term (or term "(no term)"))
2714 ;; Check-boxes in descriptive lists are associated to tag.
2715 (concat (format "<dt%s>%s</dt>"
2716 class (concat checkbox term))
2717 "<dd>"))))
2718 (unless (eq type 'descriptive) checkbox)
2719 (and contents (org-trim contents))
2720 (pcase type
2721 (`ordered "</li>")
2722 (`unordered "</li>")
2723 (`descriptive "</dd>")))))
2725 (defun org-html-item (item contents info)
2726 "Transcode an ITEM element from Org to HTML.
2727 CONTENTS holds the contents of the item. INFO is a plist holding
2728 contextual information."
2729 (let* ((plain-list (org-export-get-parent item))
2730 (type (org-element-property :type plain-list))
2731 (counter (org-element-property :counter item))
2732 (checkbox (org-element-property :checkbox item))
2733 (tag (let ((tag (org-element-property :tag item)))
2734 (and tag (org-export-data tag info)))))
2735 (org-html-format-list-item
2736 contents type checkbox info (or tag counter))))
2738 ;;;; Keyword
2740 (defun org-html-keyword (keyword _contents info)
2741 "Transcode a KEYWORD element from Org to HTML.
2742 CONTENTS is nil. INFO is a plist holding contextual information."
2743 (let ((key (org-element-property :key keyword))
2744 (value (org-element-property :value keyword)))
2745 (cond
2746 ((string= key "HTML") value)
2747 ((string= key "TOC")
2748 (let ((case-fold-search t))
2749 (cond
2750 ((string-match "\\<headlines\\>" value)
2751 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2752 (string-to-number (match-string 0 value))))
2753 (localp (string-match-p "\\<local\\>" value)))
2754 (org-html-toc depth info (and localp keyword))))
2755 ((string= "listings" value) (org-html-list-of-listings info))
2756 ((string= "tables" value) (org-html-list-of-tables info))))))))
2758 ;;;; Latex Environment
2760 (defun org-html-format-latex (latex-frag processing-type info)
2761 "Format a LaTeX fragment LATEX-FRAG into HTML.
2762 PROCESSING-TYPE designates the tool used for conversion. It can
2763 be `mathjax', `verbatim', nil, t or symbols in
2764 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
2765 `imagemagick'. See `org-html-with-latex' for more information.
2766 INFO is a plist containing export properties."
2767 (let ((cache-relpath "") (cache-dir ""))
2768 (unless (eq processing-type 'mathjax)
2769 (let ((bfn (or (buffer-file-name)
2770 (make-temp-name
2771 (expand-file-name "latex" temporary-file-directory))))
2772 (latex-header
2773 (let ((header (plist-get info :latex-header)))
2774 (and header
2775 (concat (mapconcat
2776 (lambda (line) (concat "#+LATEX_HEADER: " line))
2777 (org-split-string header "\n")
2778 "\n")
2779 "\n")))))
2780 (setq cache-relpath
2781 (concat (file-name-as-directory org-preview-latex-image-directory)
2782 (file-name-sans-extension
2783 (file-name-nondirectory bfn)))
2784 cache-dir (file-name-directory bfn))
2785 ;; Re-create LaTeX environment from original buffer in
2786 ;; temporary buffer so that dvipng/imagemagick can properly
2787 ;; turn the fragment into an image.
2788 (setq latex-frag (concat latex-header latex-frag))))
2789 (with-temp-buffer
2790 (insert latex-frag)
2791 (org-format-latex cache-relpath nil nil cache-dir nil
2792 "Creating LaTeX Image..." nil processing-type)
2793 (buffer-string))))
2795 (defun org-html-latex-environment (latex-environment _contents info)
2796 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2797 CONTENTS is nil. INFO is a plist holding contextual information."
2798 (let ((processing-type (plist-get info :with-latex))
2799 (latex-frag (org-remove-indentation
2800 (org-element-property :value latex-environment)))
2801 (attributes (org-export-read-attribute :attr_html latex-environment)))
2802 (cond
2803 ((memq processing-type '(t mathjax))
2804 (org-html-format-latex latex-frag 'mathjax info))
2805 ((assq processing-type org-preview-latex-process-alist)
2806 (let ((formula-link
2807 (org-html-format-latex latex-frag processing-type info)))
2808 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2809 ;; Do not provide a caption or a name to be consistent with
2810 ;; `mathjax' handling.
2811 (org-html--wrap-image
2812 (org-html--format-image
2813 (match-string 1 formula-link) attributes info) info))))
2814 (t latex-frag))))
2816 ;;;; Latex Fragment
2818 (defun org-html-latex-fragment (latex-fragment _contents info)
2819 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2820 CONTENTS is nil. INFO is a plist holding contextual information."
2821 (let ((latex-frag (org-element-property :value latex-fragment))
2822 (processing-type (plist-get info :with-latex)))
2823 (cond
2824 ((memq processing-type '(t mathjax))
2825 (org-html-format-latex latex-frag 'mathjax info))
2826 ((assq processing-type org-preview-latex-process-alist)
2827 (let ((formula-link
2828 (org-html-format-latex latex-frag processing-type info)))
2829 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2830 (org-html--format-image (match-string 1 formula-link) nil info))))
2831 (t latex-frag))))
2833 ;;;; Line Break
2835 (defun org-html-line-break (_line-break _contents info)
2836 "Transcode a LINE-BREAK object from Org to HTML.
2837 CONTENTS is nil. INFO is a plist holding contextual information."
2838 (concat (org-html-close-tag "br" nil info) "\n"))
2840 ;;;; Link
2842 (defun org-html-inline-image-p (link info)
2843 "Non-nil when LINK is meant to appear as an image.
2844 INFO is a plist used as a communication channel. LINK is an
2845 inline image when it has no description and targets an image
2846 file (see `org-html-inline-image-rules' for more information), or
2847 if its description is a single link targeting an image file."
2848 (if (not (org-element-contents link))
2849 (org-export-inline-image-p
2850 link (plist-get info :html-inline-image-rules))
2851 (not
2852 (let ((link-count 0))
2853 (org-element-map (org-element-contents link)
2854 (cons 'plain-text org-element-all-objects)
2855 (lambda (obj)
2856 (pcase (org-element-type obj)
2857 (`plain-text (org-string-nw-p obj))
2858 (`link (if (= link-count 1) t
2859 (cl-incf link-count)
2860 (not (org-export-inline-image-p
2861 obj (plist-get info :html-inline-image-rules)))))
2862 (_ t)))
2863 info t)))))
2865 (defvar org-html-standalone-image-predicate)
2866 (defun org-html-standalone-image-p (element info)
2867 "Non-nil if ELEMENT is a standalone image.
2869 INFO is a plist holding contextual information.
2871 An element or object is a standalone image when
2873 - its type is `paragraph' and its sole content, save for white
2874 spaces, is a link that qualifies as an inline image;
2876 - its type is `link' and its containing paragraph has no other
2877 content save white spaces.
2879 Bind `org-html-standalone-image-predicate' to constrain paragraph
2880 further. For example, to check for only captioned standalone
2881 images, set it to:
2883 (lambda (paragraph) (org-element-property :caption paragraph))"
2884 (let ((paragraph (pcase (org-element-type element)
2885 (`paragraph element)
2886 (`link (org-export-get-parent element)))))
2887 (and (eq (org-element-type paragraph) 'paragraph)
2888 (or (not (fboundp 'org-html-standalone-image-predicate))
2889 (funcall org-html-standalone-image-predicate paragraph))
2890 (catch 'exit
2891 (let ((link-count 0))
2892 (org-element-map (org-element-contents paragraph)
2893 (cons 'plain-text org-element-all-objects)
2894 (lambda (obj)
2895 (when (pcase (org-element-type obj)
2896 (`plain-text (org-string-nw-p obj))
2897 (`link (or (> (cl-incf link-count) 1)
2898 (not (org-html-inline-image-p obj info))))
2899 (_ t))
2900 (throw 'exit nil)))
2901 info nil 'link)
2902 (= link-count 1))))))
2904 (defun org-html-link (link desc info)
2905 "Transcode a LINK object from Org to HTML.
2906 DESC is the description part of the link, or the empty string.
2907 INFO is a plist holding contextual information. See
2908 `org-export-data'."
2909 (let* ((home (when (plist-get info :html-link-home)
2910 (org-trim (plist-get info :html-link-home))))
2911 (use-abs-url (plist-get info :html-link-use-abs-url))
2912 (link-org-files-as-html-maybe
2913 (lambda (raw-path info)
2914 ;; Treat links to `file.org' as links to `file.html', if
2915 ;; needed. See `org-html-link-org-files-as-html'.
2916 (cond
2917 ((and (plist-get info :html-link-org-files-as-html)
2918 (string= ".org"
2919 (downcase (file-name-extension raw-path "."))))
2920 (concat (file-name-sans-extension raw-path) "."
2921 (plist-get info :html-extension)))
2922 (t raw-path))))
2923 (type (org-element-property :type link))
2924 (raw-path (org-element-property :path link))
2925 ;; Ensure DESC really exists, or set it to nil.
2926 (desc (org-string-nw-p desc))
2927 (path
2928 (cond
2929 ((member type '("http" "https" "ftp" "mailto" "news"))
2930 (url-encode-url (org-link-unescape (concat type ":" raw-path))))
2931 ((string= type "file")
2932 ;; Treat links to ".org" files as ".html", if needed.
2933 (setq raw-path
2934 (funcall link-org-files-as-html-maybe raw-path info))
2935 ;; If file path is absolute, prepend it with protocol
2936 ;; component - "file://".
2937 (cond
2938 ((file-name-absolute-p raw-path)
2939 (setq raw-path (org-export-file-uri raw-path)))
2940 ((and home use-abs-url)
2941 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2942 ;; Add search option, if any. A search option can be
2943 ;; relative to a custom-id, a headline title, a name or
2944 ;; a target.
2945 (let ((option (org-element-property :search-option link)))
2946 (cond ((not option) raw-path)
2947 ;; Since HTML back-end use custom-id value as-is,
2948 ;; resolving is them is trivial.
2949 ((eq (string-to-char option) ?#) (concat raw-path option))
2951 (concat raw-path
2953 (org-publish-resolve-external-link
2954 option
2955 (org-element-property :path link)))))))
2956 (t raw-path)))
2957 ;; Extract attributes from parent's paragraph. HACK: Only do
2958 ;; this for the first link in parent (inner image link for
2959 ;; inline images). This is needed as long as attributes
2960 ;; cannot be set on a per link basis.
2961 (attributes-plist
2962 (let* ((parent (org-export-get-parent-element link))
2963 (link (let ((container (org-export-get-parent link)))
2964 (if (and (eq (org-element-type container) 'link)
2965 (org-html-inline-image-p link info))
2966 container
2967 link))))
2968 (and (eq (org-element-map parent 'link 'identity info t) link)
2969 (org-export-read-attribute :attr_html parent))))
2970 (attributes
2971 (let ((attr (org-html--make-attribute-string attributes-plist)))
2972 (if (org-string-nw-p attr) (concat " " attr) ""))))
2973 (cond
2974 ;; Link type is handled by a special function.
2975 ((org-export-custom-protocol-maybe link desc 'html))
2976 ;; Image file.
2977 ((and (plist-get info :html-inline-images)
2978 (org-export-inline-image-p
2979 link (plist-get info :html-inline-image-rules)))
2980 (org-html--format-image path attributes-plist info))
2981 ;; Radio target: Transcode target's contents and use them as
2982 ;; link's description.
2983 ((string= type "radio")
2984 (let ((destination (org-export-resolve-radio-link link info)))
2985 (if (not destination) desc
2986 (format "<a href=\"#%s\"%s>%s</a>"
2987 (org-export-get-reference destination info)
2988 attributes
2989 desc))))
2990 ;; Links pointing to a headline: Find destination and build
2991 ;; appropriate referencing command.
2992 ((member type '("custom-id" "fuzzy" "id"))
2993 (let ((destination (if (string= type "fuzzy")
2994 (org-export-resolve-fuzzy-link link info)
2995 (org-export-resolve-id-link link info))))
2996 (pcase (org-element-type destination)
2997 ;; ID link points to an external file.
2998 (`plain-text
2999 (let ((fragment (concat "ID-" path))
3000 ;; Treat links to ".org" files as ".html", if needed.
3001 (path (funcall link-org-files-as-html-maybe
3002 destination info)))
3003 (format "<a href=\"%s#%s\"%s>%s</a>"
3004 path fragment attributes (or desc destination))))
3005 ;; Fuzzy link points nowhere.
3006 (`nil
3007 (format "<i>%s</i>"
3008 (or desc
3009 (org-export-data
3010 (org-element-property :raw-link link) info))))
3011 ;; Link points to a headline.
3012 (`headline
3013 (let ((href (or (org-element-property :CUSTOM_ID destination)
3014 (org-export-get-reference destination info)))
3015 ;; What description to use?
3016 (desc
3017 ;; Case 1: Headline is numbered and LINK has no
3018 ;; description. Display section number.
3019 (if (and (org-export-numbered-headline-p destination info)
3020 (not desc))
3021 (mapconcat #'number-to-string
3022 (org-export-get-headline-number
3023 destination info) ".")
3024 ;; Case 2: Either the headline is un-numbered or
3025 ;; LINK has a custom description. Display LINK's
3026 ;; description or headline's title.
3027 (or desc
3028 (org-export-data
3029 (org-element-property :title destination) info)))))
3030 (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
3031 ;; Fuzzy link points to a target or an element.
3033 (let* ((ref (org-export-get-reference destination info))
3034 (org-html-standalone-image-predicate
3035 #'org-html--has-caption-p)
3036 (number (cond
3037 (desc nil)
3038 ((org-html-standalone-image-p destination info)
3039 (org-export-get-ordinal
3040 (org-element-map destination 'link
3041 #'identity info t)
3042 info 'link 'org-html-standalone-image-p))
3043 (t (org-export-get-ordinal
3044 destination info nil 'org-html--has-caption-p))))
3045 (desc (cond (desc)
3046 ((not number) "No description for this link")
3047 ((numberp number) (number-to-string number))
3048 (t (mapconcat #'number-to-string number ".")))))
3049 (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc))))))
3050 ;; Coderef: replace link with the reference name or the
3051 ;; equivalent line number.
3052 ((string= type "coderef")
3053 (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
3054 (format "<a href=\"#%s\"%s%s>%s</a>"
3055 fragment
3056 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
3057 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
3058 fragment fragment)
3059 attributes
3060 (format (org-export-get-coderef-format path desc)
3061 (org-export-resolve-coderef path info)))))
3062 ;; External link with a description part.
3063 ((and path desc) (format "<a href=\"%s\"%s>%s</a>"
3064 (org-html-encode-plain-text path)
3065 attributes
3066 desc))
3067 ;; External link without a description part.
3068 (path (let ((path (org-html-encode-plain-text path)))
3069 (format "<a href=\"%s\"%s>%s</a>"
3070 path
3071 attributes
3072 (org-link-unescape path))))
3073 ;; No path, only description. Try to do something useful.
3074 (t (format "<i>%s</i>" desc)))))
3076 ;;;; Node Property
3078 (defun org-html-node-property (node-property _contents _info)
3079 "Transcode a NODE-PROPERTY element from Org to HTML.
3080 CONTENTS is nil. INFO is a plist holding contextual
3081 information."
3082 (format "%s:%s"
3083 (org-element-property :key node-property)
3084 (let ((value (org-element-property :value node-property)))
3085 (if value (concat " " value) ""))))
3087 ;;;; Paragraph
3089 (defun org-html-paragraph (paragraph contents info)
3090 "Transcode a PARAGRAPH element from Org to HTML.
3091 CONTENTS is the contents of the paragraph, as a string. INFO is
3092 the plist used as a communication channel."
3093 (let* ((parent (org-export-get-parent paragraph))
3094 (parent-type (org-element-type parent))
3095 (style '((footnote-definition " class=\"footpara\"")
3096 (org-data " class=\"footpara\"")))
3097 (attributes (org-html--make-attribute-string
3098 (org-export-read-attribute :attr_html paragraph)))
3099 (extra (or (cadr (assq parent-type style)) "")))
3100 (cond
3101 ((and (eq parent-type 'item)
3102 (not (org-export-get-previous-element paragraph info))
3103 (let ((followers (org-export-get-next-element paragraph info 2)))
3104 (and (not (cdr followers))
3105 (memq (org-element-type (car followers)) '(nil plain-list)))))
3106 ;; First paragraph in an item has no tag if it is alone or
3107 ;; followed, at most, by a sub-list.
3108 contents)
3109 ((org-html-standalone-image-p paragraph info)
3110 ;; Standalone image.
3111 (let ((caption
3112 (let ((raw (org-export-data
3113 (org-export-get-caption paragraph) info))
3114 (org-html-standalone-image-predicate
3115 #'org-html--has-caption-p))
3116 (if (not (org-string-nw-p raw)) raw
3117 (concat "<span class=\"figure-number\">"
3118 (format (org-html--translate "Figure %d:" info)
3119 (org-export-get-ordinal
3120 (org-element-map paragraph 'link
3121 #'identity info t)
3122 info nil #'org-html-standalone-image-p))
3123 " </span>"
3124 raw))))
3125 (label (and (org-element-property :name paragraph)
3126 (org-export-get-reference paragraph info))))
3127 (org-html--wrap-image contents info caption label)))
3128 ;; Regular paragraph.
3129 (t (format "<p%s%s>\n%s</p>"
3130 (if (org-string-nw-p attributes)
3131 (concat " " attributes) "")
3132 extra contents)))))
3134 ;;;; Plain List
3136 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
3137 ;; the correct value for the item counter
3138 (defun org-html-begin-plain-list (type &optional arg1)
3139 "Insert the beginning of the HTML list depending on TYPE.
3140 When ARG1 is a string, use it as the start parameter for ordered
3141 lists."
3142 (pcase type
3143 (`ordered
3144 (format "<ol class=\"org-ol\"%s>"
3145 (if arg1 (format " start=\"%d\"" arg1) "")))
3146 (`unordered "<ul class=\"org-ul\">")
3147 (`descriptive "<dl class=\"org-dl\">")))
3149 (defun org-html-end-plain-list (type)
3150 "Insert the end of the HTML list depending on TYPE."
3151 (pcase type
3152 (`ordered "</ol>")
3153 (`unordered "</ul>")
3154 (`descriptive "</dl>")))
3156 (defun org-html-plain-list (plain-list contents _info)
3157 "Transcode a PLAIN-LIST element from Org to HTML.
3158 CONTENTS is the contents of the list. INFO is a plist holding
3159 contextual information."
3160 (let ((type (org-element-property :type plain-list)))
3161 (format "%s\n%s%s"
3162 (org-html-begin-plain-list type)
3163 contents (org-html-end-plain-list type))))
3165 ;;;; Plain Text
3167 (defun org-html-convert-special-strings (string)
3168 "Convert special characters in STRING to HTML."
3169 (dolist (a org-html-special-string-regexps string)
3170 (let ((re (car a))
3171 (rpl (cdr a)))
3172 (setq string (replace-regexp-in-string re rpl string t)))))
3174 (defun org-html-encode-plain-text (text)
3175 "Convert plain text characters from TEXT to HTML equivalent.
3176 Possible conversions are set in `org-html-protect-char-alist'."
3177 (dolist (pair org-html-protect-char-alist text)
3178 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3180 (defun org-html-plain-text (text info)
3181 "Transcode a TEXT string from Org to HTML.
3182 TEXT is the string to transcode. INFO is a plist holding
3183 contextual information."
3184 (let ((output text))
3185 ;; Protect following characters: <, >, &.
3186 (setq output (org-html-encode-plain-text output))
3187 ;; Handle smart quotes. Be sure to provide original string since
3188 ;; OUTPUT may have been modified.
3189 (when (plist-get info :with-smart-quotes)
3190 (setq output (org-export-activate-smart-quotes output :html info text)))
3191 ;; Handle special strings.
3192 (when (plist-get info :with-special-strings)
3193 (setq output (org-html-convert-special-strings output)))
3194 ;; Handle break preservation if required.
3195 (when (plist-get info :preserve-breaks)
3196 (setq output
3197 (replace-regexp-in-string
3198 "\\(\\\\\\\\\\)?[ \t]*\n"
3199 (concat (org-html-close-tag "br" nil info) "\n") output)))
3200 ;; Return value.
3201 output))
3204 ;; Planning
3206 (defun org-html-planning (planning _contents info)
3207 "Transcode a PLANNING element from Org to HTML.
3208 CONTENTS is nil. INFO is a plist used as a communication
3209 channel."
3210 (format
3211 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3212 (org-trim
3213 (mapconcat
3214 (lambda (pair)
3215 (let ((timestamp (cdr pair)))
3216 (when timestamp
3217 (let ((string (car pair)))
3218 (format "<span class=\"timestamp-kwd\">%s</span> \
3219 <span class=\"timestamp\">%s</span> "
3220 string
3221 (org-html-plain-text (org-timestamp-translate timestamp)
3222 info))))))
3223 `((,org-closed-string . ,(org-element-property :closed planning))
3224 (,org-deadline-string . ,(org-element-property :deadline planning))
3225 (,org-scheduled-string . ,(org-element-property :scheduled planning)))
3226 ""))))
3228 ;;;; Property Drawer
3230 (defun org-html-property-drawer (_property-drawer contents _info)
3231 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3232 CONTENTS holds the contents of the drawer. INFO is a plist
3233 holding contextual information."
3234 (and (org-string-nw-p contents)
3235 (format "<pre class=\"example\">\n%s</pre>" contents)))
3237 ;;;; Quote Block
3239 (defun org-html-quote-block (quote-block contents _info)
3240 "Transcode a QUOTE-BLOCK element from Org to HTML.
3241 CONTENTS holds the contents of the block. INFO is a plist
3242 holding contextual information."
3243 (format "<blockquote%s>\n%s</blockquote>"
3244 (let* ((name (org-element-property :name quote-block))
3245 (attributes (org-export-read-attribute :attr_html quote-block))
3246 (a (org-html--make-attribute-string
3247 (if (or (not name) (plist-member attributes :id))
3248 attributes
3249 (plist-put attributes :id name)))))
3250 (if (org-string-nw-p a) (concat " " a) ""))
3251 contents))
3253 ;;;; Section
3255 (defun org-html-section (section contents info)
3256 "Transcode a SECTION element from Org to HTML.
3257 CONTENTS holds the contents of the section. INFO is a plist
3258 holding contextual information."
3259 (let ((parent (org-export-get-parent-headline section)))
3260 ;; Before first headline: no container, just return CONTENTS.
3261 (if (not parent) contents
3262 ;; Get div's class and id references.
3263 (let* ((class-num (+ (org-export-get-relative-level parent info)
3264 (1- (plist-get info :html-toplevel-hlevel))))
3265 (section-number
3266 (and (org-export-numbered-headline-p parent info)
3267 (mapconcat
3268 #'number-to-string
3269 (org-export-get-headline-number parent info) "-"))))
3270 ;; Build return value.
3271 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3272 class-num
3273 (or (org-element-property :CUSTOM_ID parent)
3274 section-number
3275 (org-export-get-reference parent info))
3276 (or contents ""))))))
3278 ;;;; Radio Target
3280 (defun org-html-radio-target (radio-target text info)
3281 "Transcode a RADIO-TARGET object from Org to HTML.
3282 TEXT is the text of the target. INFO is a plist holding
3283 contextual information."
3284 (let ((ref (org-export-get-reference radio-target info)))
3285 (org-html--anchor ref text nil info)))
3287 ;;;; Special Block
3289 (defun org-html-special-block (special-block contents info)
3290 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3291 CONTENTS holds the contents of the block. INFO is a plist
3292 holding contextual information."
3293 (let* ((block-type (org-element-property :type special-block))
3294 (html5-fancy (and (org-html--html5-fancy-p info)
3295 (member block-type org-html-html5-elements)))
3296 (attributes (org-export-read-attribute :attr_html special-block)))
3297 (unless html5-fancy
3298 (let ((class (plist-get attributes :class)))
3299 (setq attributes (plist-put attributes :class
3300 (if class (concat class " " block-type)
3301 block-type)))))
3302 (let* ((contents (or contents ""))
3303 (name (org-element-property :name special-block))
3304 (a (org-html--make-attribute-string
3305 (if (or (not name) (plist-member attributes :id))
3306 attributes
3307 (plist-put attributes :id name))))
3308 (str (if (org-string-nw-p a) (concat " " a) "")))
3309 (if html5-fancy
3310 (format "<%s%s>\n%s</%s>" block-type str contents block-type)
3311 (format "<div%s>\n%s\n</div>" str contents)))))
3313 ;;;; Src Block
3315 (defun org-html-src-block (src-block _contents info)
3316 "Transcode a SRC-BLOCK element from Org to HTML.
3317 CONTENTS holds the contents of the item. INFO is a plist holding
3318 contextual information."
3319 (if (org-export-read-attribute :attr_html src-block :textarea)
3320 (org-html--textarea-block src-block)
3321 (let ((lang (org-element-property :language src-block))
3322 (code (org-html-format-code src-block info))
3323 (label (let ((lbl (and (org-element-property :name src-block)
3324 (org-export-get-reference src-block info))))
3325 (if lbl (format " id=\"%s\"" lbl) ""))))
3326 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3327 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
3328 ;; Build caption.
3329 (let ((caption (org-export-get-caption src-block)))
3330 (if (not caption) ""
3331 (let ((listing-number
3332 (format
3333 "<span class=\"listing-number\">%s </span>"
3334 (format
3335 (org-html--translate "Listing %d:" info)
3336 (org-export-get-ordinal
3337 src-block info nil #'org-html--has-caption-p)))))
3338 (format "<label class=\"org-src-name\">%s%s</label>"
3339 listing-number
3340 (org-trim (org-export-data caption info))))))
3341 ;; Contents.
3342 (format "<pre class=\"src src-%s\"%s>%s</pre>"
3343 lang label code))))))
3345 ;;;; Statistics Cookie
3347 (defun org-html-statistics-cookie (statistics-cookie _contents _info)
3348 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3349 CONTENTS is nil. INFO is a plist holding contextual information."
3350 (let ((cookie-value (org-element-property :value statistics-cookie)))
3351 (format "<code>%s</code>" cookie-value)))
3353 ;;;; Strike-Through
3355 (defun org-html-strike-through (_strike-through contents info)
3356 "Transcode STRIKE-THROUGH from Org to HTML.
3357 CONTENTS is the text with strike-through markup. INFO is a plist
3358 holding contextual information."
3359 (format
3360 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3361 "%s")
3362 contents))
3364 ;;;; Subscript
3366 (defun org-html-subscript (_subscript contents _info)
3367 "Transcode a SUBSCRIPT object from Org to HTML.
3368 CONTENTS is the contents of the object. INFO is a plist holding
3369 contextual information."
3370 (format "<sub>%s</sub>" contents))
3372 ;;;; Superscript
3374 (defun org-html-superscript (_superscript contents _info)
3375 "Transcode a SUPERSCRIPT object from Org to HTML.
3376 CONTENTS is the contents of the object. INFO is a plist holding
3377 contextual information."
3378 (format "<sup>%s</sup>" contents))
3380 ;;;; Table Cell
3382 (defun org-html-table-cell (table-cell contents info)
3383 "Transcode a TABLE-CELL element from Org to HTML.
3384 CONTENTS is nil. INFO is a plist used as a communication
3385 channel."
3386 (let* ((table-row (org-export-get-parent table-cell))
3387 (table (org-export-get-parent-table table-cell))
3388 (cell-attrs
3389 (if (not (plist-get info :html-table-align-individual-fields)) ""
3390 (format (if (and (boundp 'org-html-format-table-no-css)
3391 org-html-format-table-no-css)
3392 " align=\"%s\"" " class=\"org-%s\"")
3393 (org-export-table-cell-alignment table-cell info)))))
3394 (when (or (not contents) (string= "" (org-trim contents)))
3395 (setq contents "&#xa0;"))
3396 (cond
3397 ((and (org-export-table-has-header-p table info)
3398 (= 1 (org-export-table-row-group table-row info)))
3399 (let ((header-tags (plist-get info :html-table-header-tags)))
3400 (concat "\n" (format (car header-tags) "col" cell-attrs)
3401 contents
3402 (cdr header-tags))))
3403 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3404 (zerop (cdr (org-export-table-cell-address table-cell info))))
3405 (let ((header-tags (plist-get info :html-table-header-tags)))
3406 (concat "\n" (format (car header-tags) "row" cell-attrs)
3407 contents
3408 (cdr header-tags))))
3409 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3410 (concat "\n" (format (car data-tags) cell-attrs)
3411 contents
3412 (cdr data-tags)))))))
3414 ;;;; Table Row
3416 (defun org-html-table-row (table-row contents info)
3417 "Transcode a TABLE-ROW element from Org to HTML.
3418 CONTENTS is the contents of the row. INFO is a plist used as a
3419 communication channel."
3420 ;; Rules are ignored since table separators are deduced from
3421 ;; borders of the current row.
3422 (when (eq (org-element-property :type table-row) 'standard)
3423 (let* ((group (org-export-table-row-group table-row info))
3424 (number (org-export-table-row-number table-row info))
3425 (start-group-p
3426 (org-export-table-row-starts-rowgroup-p table-row info))
3427 (end-group-p
3428 (org-export-table-row-ends-rowgroup-p table-row info))
3429 (topp (and (equal start-group-p '(top))
3430 (equal end-group-p '(below top))))
3431 (bottomp (and (equal start-group-p '(above))
3432 (equal end-group-p '(bottom above))))
3433 (row-open-tag
3434 (pcase (plist-get info :html-table-row-open-tag)
3435 ((and accessor (pred functionp))
3436 (funcall accessor
3437 number group start-group-p end-group-p topp bottomp))
3438 (accessor accessor)))
3439 (row-close-tag
3440 (pcase (plist-get info :html-table-row-close-tag)
3441 ((and accessor (pred functionp))
3442 (funcall accessor
3443 number group start-group-p end-group-p topp bottomp))
3444 (accessor accessor)))
3445 (group-tags
3446 (cond
3447 ;; Row belongs to second or subsequent groups.
3448 ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
3449 ;; Row is from first group. Table has >=1 groups.
3450 ((org-export-table-has-header-p
3451 (org-export-get-parent-table table-row) info)
3452 '("<thead>" . "\n</thead>"))
3453 ;; Row is from first and only group.
3454 (t '("<tbody>" . "\n</tbody>")))))
3455 (concat (and start-group-p (car group-tags))
3456 (concat "\n"
3457 row-open-tag
3458 contents
3459 "\n"
3460 row-close-tag)
3461 (and end-group-p (cdr group-tags))))))
3463 ;;;; Table
3465 (defun org-html-table-first-row-data-cells (table info)
3466 "Transcode the first row of TABLE.
3467 INFO is a plist used as a communication channel."
3468 (let ((table-row
3469 (org-element-map table 'table-row
3470 (lambda (row)
3471 (unless (eq (org-element-property :type row) 'rule) row))
3472 info 'first-match))
3473 (special-column-p (org-export-table-has-special-column-p table)))
3474 (if (not special-column-p) (org-element-contents table-row)
3475 (cdr (org-element-contents table-row)))))
3477 (defun org-html-table--table.el-table (table _info)
3478 "Format table.el tables into HTML.
3479 INFO is a plist used as a communication channel."
3480 (when (eq (org-element-property :type table) 'table.el)
3481 (require 'table)
3482 (let ((outbuf (with-current-buffer
3483 (get-buffer-create "*org-export-table*")
3484 (erase-buffer) (current-buffer))))
3485 (with-temp-buffer
3486 (insert (org-element-property :value table))
3487 (goto-char 1)
3488 (re-search-forward "^[ \t]*|[^|]" nil t)
3489 (table-generate-source 'html outbuf))
3490 (with-current-buffer outbuf
3491 (prog1 (org-trim (buffer-string))
3492 (kill-buffer) )))))
3494 (defun org-html-table (table contents info)
3495 "Transcode a TABLE element from Org to HTML.
3496 CONTENTS is the contents of the table. INFO is a plist holding
3497 contextual information."
3498 (if (eq (org-element-property :type table) 'table.el)
3499 ;; "table.el" table. Convert it using appropriate tools.
3500 (org-html-table--table.el-table table info)
3501 ;; Standard table.
3502 (let* ((caption (org-export-get-caption table))
3503 (number (org-export-get-ordinal
3504 table info nil #'org-html--has-caption-p))
3505 (attributes
3506 (org-html--make-attribute-string
3507 (org-combine-plists
3508 (and (org-element-property :name table)
3509 (list :id (org-export-get-reference table info)))
3510 (and (not (org-html-html5-p info))
3511 (plist-get info :html-table-attributes))
3512 (org-export-read-attribute :attr_html table))))
3513 (alignspec
3514 (if (bound-and-true-p org-html-format-table-no-css)
3515 "align=\"%s\""
3516 "class=\"org-%s\""))
3517 (table-column-specs
3518 (lambda (table info)
3519 (mapconcat
3520 (lambda (table-cell)
3521 (let ((alignment (org-export-table-cell-alignment
3522 table-cell info)))
3523 (concat
3524 ;; Begin a colgroup?
3525 (when (org-export-table-cell-starts-colgroup-p
3526 table-cell info)
3527 "\n<colgroup>")
3528 ;; Add a column. Also specify its alignment.
3529 (format "\n%s"
3530 (org-html-close-tag
3531 "col" (concat " " (format alignspec alignment)) info))
3532 ;; End a colgroup?
3533 (when (org-export-table-cell-ends-colgroup-p
3534 table-cell info)
3535 "\n</colgroup>"))))
3536 (org-html-table-first-row-data-cells table info) "\n"))))
3537 (format "<table%s>\n%s\n%s\n%s</table>"
3538 (if (equal attributes "") "" (concat " " attributes))
3539 (if (not caption) ""
3540 (format (if (plist-get info :html-table-caption-above)
3541 "<caption class=\"t-above\">%s</caption>"
3542 "<caption class=\"t-bottom\">%s</caption>")
3543 (concat
3544 "<span class=\"table-number\">"
3545 (format (org-html--translate "Table %d:" info) number)
3546 "</span> " (org-export-data caption info))))
3547 (funcall table-column-specs table info)
3548 contents))))
3550 ;;;; Target
3552 (defun org-html-target (target _contents info)
3553 "Transcode a TARGET object from Org to HTML.
3554 CONTENTS is nil. INFO is a plist holding contextual
3555 information."
3556 (let ((ref (org-export-get-reference target info)))
3557 (org-html--anchor ref nil nil info)))
3559 ;;;; Timestamp
3561 (defun org-html-timestamp (timestamp _contents info)
3562 "Transcode a TIMESTAMP object from Org to HTML.
3563 CONTENTS is nil. INFO is a plist holding contextual
3564 information."
3565 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3566 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3567 (replace-regexp-in-string "--" "&#x2013;" value))))
3569 ;;;; Underline
3571 (defun org-html-underline (_underline contents info)
3572 "Transcode UNDERLINE from Org to HTML.
3573 CONTENTS is the text with underline markup. INFO is a plist
3574 holding contextual information."
3575 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3576 "%s")
3577 contents))
3579 ;;;; Verbatim
3581 (defun org-html-verbatim (verbatim _contents info)
3582 "Transcode VERBATIM from Org to HTML.
3583 CONTENTS is nil. INFO is a plist holding contextual
3584 information."
3585 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3586 (org-html-encode-plain-text (org-element-property :value verbatim))))
3588 ;;;; Verse Block
3590 (defun org-html-verse-block (_verse-block contents info)
3591 "Transcode a VERSE-BLOCK element from Org to HTML.
3592 CONTENTS is verse block contents. INFO is a plist holding
3593 contextual information."
3594 ;; Replace each newline character with line break. Also replace
3595 ;; each blank line with a line break.
3596 (setq contents (replace-regexp-in-string
3597 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3598 (replace-regexp-in-string
3599 "\\(\\\\\\\\\\)?[ \t]*\n"
3600 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3601 ;; Replace each white space at beginning of a line with a
3602 ;; non-breaking space.
3603 (while (string-match "^[ \t]+" contents)
3604 (let* ((num-ws (length (match-string 0 contents)))
3605 (ws (org-html--make-string num-ws "&#xa0;")))
3606 (setq contents (replace-match ws nil t contents))))
3607 (format "<p class=\"verse\">\n%s</p>" contents))
3610 ;;; Filter Functions
3612 (defun org-html-final-function (contents _backend info)
3613 "Filter to indent the HTML and convert HTML entities."
3614 (with-temp-buffer
3615 (insert contents)
3616 (set-auto-mode t)
3617 (if (plist-get info :html-indent)
3618 (indent-region (point-min) (point-max)))
3619 (buffer-substring-no-properties (point-min) (point-max))))
3622 ;;; End-user functions
3624 ;;;###autoload
3625 (defun org-html-export-as-html
3626 (&optional async subtreep visible-only body-only ext-plist)
3627 "Export current buffer to an HTML buffer.
3629 If narrowing is active in the current buffer, only export its
3630 narrowed part.
3632 If a region is active, export that region.
3634 A non-nil optional argument ASYNC means the process should happen
3635 asynchronously. The resulting buffer should be accessible
3636 through the `org-export-stack' interface.
3638 When optional argument SUBTREEP is non-nil, export the sub-tree
3639 at point, extracting information from the headline properties
3640 first.
3642 When optional argument VISIBLE-ONLY is non-nil, don't export
3643 contents of hidden elements.
3645 When optional argument BODY-ONLY is non-nil, only write code
3646 between \"<body>\" and \"</body>\" tags.
3648 EXT-PLIST, when provided, is a property list with external
3649 parameters overriding Org default settings, but still inferior to
3650 file-local settings.
3652 Export is done in a buffer named \"*Org HTML Export*\", which
3653 will be displayed when `org-export-show-temporary-export-buffer'
3654 is non-nil."
3655 (interactive)
3656 (org-export-to-buffer 'html "*Org HTML Export*"
3657 async subtreep visible-only body-only ext-plist
3658 (lambda () (set-auto-mode t))))
3660 ;;;###autoload
3661 (defun org-html-convert-region-to-html ()
3662 "Assume the current region has Org syntax, and convert it to HTML.
3663 This can be used in any buffer. For example, you can write an
3664 itemized list in Org syntax in an HTML buffer and use this command
3665 to convert it."
3666 (interactive)
3667 (org-export-replace-region-by 'html))
3669 ;;;###autoload
3670 (defun org-html-export-to-html
3671 (&optional async subtreep visible-only body-only ext-plist)
3672 "Export current buffer to a HTML file.
3674 If narrowing is active in the current buffer, only export its
3675 narrowed part.
3677 If a region is active, export that region.
3679 A non-nil optional argument ASYNC means the process should happen
3680 asynchronously. The resulting file should be accessible through
3681 the `org-export-stack' interface.
3683 When optional argument SUBTREEP is non-nil, export the sub-tree
3684 at point, extracting information from the headline properties
3685 first.
3687 When optional argument VISIBLE-ONLY is non-nil, don't export
3688 contents of hidden elements.
3690 When optional argument BODY-ONLY is non-nil, only write code
3691 between \"<body>\" and \"</body>\" tags.
3693 EXT-PLIST, when provided, is a property list with external
3694 parameters overriding Org default settings, but still inferior to
3695 file-local settings.
3697 Return output file's name."
3698 (interactive)
3699 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3700 org-html-extension
3701 "html")))
3702 (file (org-export-output-file-name extension subtreep))
3703 (org-export-coding-system org-html-coding-system))
3704 (org-export-to-file 'html file
3705 async subtreep visible-only body-only ext-plist)))
3707 ;;;###autoload
3708 (defun org-html-publish-to-html (plist filename pub-dir)
3709 "Publish an org file to HTML.
3711 FILENAME is the filename of the Org file to be published. PLIST
3712 is the property list for the given project. PUB-DIR is the
3713 publishing directory.
3715 Return output file name."
3716 (org-publish-org-to 'html filename
3717 (concat "." (or (plist-get plist :html-extension)
3718 org-html-extension
3719 "html"))
3720 plist pub-dir))
3723 (provide 'ox-html)
3725 ;; Local variables:
3726 ;; generated-autoload-file: "org-loaddefs.el"
3727 ;; End:
3729 ;;; ox-html.el ends here