Merge branch 'maint'
[org-mode/org-tableheadings.git] / lisp / ox-html.el
blob3f5802a2f7c6f5cbd13c66c1501b03947e925966
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 'ox)
34 (require 'ox-publish)
35 (require 'format-spec)
36 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
37 (require 'cl-lib)
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 org-pop-to-buffer-same-window
45 "org-compat" (&optional buffer-or-name norecord label))
46 (declare-function mm-url-decode-entities "mm-url" ())
48 (defvar htmlize-css-name-prefix)
49 (defvar htmlize-output-type)
50 (defvar htmlize-output-type)
51 (defvar htmlize-css-name-prefix)
53 ;;; Define Back-End
55 (org-export-define-backend 'html
56 '((bold . org-html-bold)
57 (center-block . org-html-center-block)
58 (clock . org-html-clock)
59 (code . org-html-code)
60 (drawer . org-html-drawer)
61 (dynamic-block . org-html-dynamic-block)
62 (entity . org-html-entity)
63 (example-block . org-html-example-block)
64 (export-block . org-html-export-block)
65 (export-snippet . org-html-export-snippet)
66 (fixed-width . org-html-fixed-width)
67 (footnote-definition . org-html-footnote-definition)
68 (footnote-reference . org-html-footnote-reference)
69 (headline . org-html-headline)
70 (horizontal-rule . org-html-horizontal-rule)
71 (inline-src-block . org-html-inline-src-block)
72 (inlinetask . org-html-inlinetask)
73 (inner-template . org-html-inner-template)
74 (italic . org-html-italic)
75 (item . org-html-item)
76 (keyword . org-html-keyword)
77 (latex-environment . org-html-latex-environment)
78 (latex-fragment . org-html-latex-fragment)
79 (line-break . org-html-line-break)
80 (link . org-html-link)
81 (node-property . org-html-node-property)
82 (paragraph . org-html-paragraph)
83 (plain-list . org-html-plain-list)
84 (plain-text . org-html-plain-text)
85 (planning . org-html-planning)
86 (property-drawer . org-html-property-drawer)
87 (quote-block . org-html-quote-block)
88 (radio-target . org-html-radio-target)
89 (section . org-html-section)
90 (special-block . org-html-special-block)
91 (src-block . org-html-src-block)
92 (statistics-cookie . org-html-statistics-cookie)
93 (strike-through . org-html-strike-through)
94 (subscript . org-html-subscript)
95 (superscript . org-html-superscript)
96 (table . org-html-table)
97 (table-cell . org-html-table-cell)
98 (table-row . org-html-table-row)
99 (target . org-html-target)
100 (template . org-html-template)
101 (timestamp . org-html-timestamp)
102 (underline . org-html-underline)
103 (verbatim . org-html-verbatim)
104 (verse-block . org-html-verse-block))
105 :filters-alist '((:filter-options . org-html-infojs-install-script)
106 (:filter-final-output . org-html-final-function))
107 :menu-entry
108 '(?h "Export to HTML"
109 ((?H "As HTML buffer" org-html-export-as-html)
110 (?h "As HTML file" org-html-export-to-html)
111 (?o "As HTML file and open"
112 (lambda (a s v b)
113 (if a (org-html-export-to-html t s v b)
114 (org-open-file (org-html-export-to-html nil s v b)))))))
115 :options-alist
116 '((:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
117 (:html-container "HTML_CONTAINER" nil org-html-container-element)
118 (:description "DESCRIPTION" nil nil newline)
119 (:keywords "KEYWORDS" nil nil space)
120 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
121 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
122 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
123 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
124 (:html-mathjax "HTML_MATHJAX" nil "" space)
125 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
126 (:html-postamble nil "html-postamble" org-html-postamble)
127 (:html-preamble nil "html-preamble" org-html-preamble)
128 (:html-head "HTML_HEAD" nil org-html-head newline)
129 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
130 (:subtitle "SUBTITLE" nil nil parse)
131 (:html-head-include-default-style
132 nil "html-style" org-html-head-include-default-style)
133 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
134 (:html-allow-name-attribute-in-anchors
135 nil nil org-html-allow-name-attribute-in-anchors)
136 (:html-divs nil nil org-html-divs)
137 (:html-checkbox-type nil nil org-html-checkbox-type)
138 (:html-extension nil nil org-html-extension)
139 (:html-footnote-format nil nil org-html-footnote-format)
140 (:html-footnote-separator nil nil org-html-footnote-separator)
141 (:html-footnotes-section nil nil org-html-footnotes-section)
142 (:html-format-drawer-function nil nil org-html-format-drawer-function)
143 (:html-format-headline-function nil nil org-html-format-headline-function)
144 (:html-format-inlinetask-function
145 nil nil org-html-format-inlinetask-function)
146 (:html-home/up-format nil nil org-html-home/up-format)
147 (:html-indent nil nil org-html-indent)
148 (:html-infojs-options nil nil org-html-infojs-options)
149 (:html-infojs-template nil nil org-html-infojs-template)
150 (:html-inline-image-rules nil nil org-html-inline-image-rules)
151 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
152 (:html-mathjax-options nil nil org-html-mathjax-options)
153 (:html-mathjax-template nil nil org-html-mathjax-template)
154 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
155 (:html-postamble-format nil nil org-html-postamble-format)
156 (:html-preamble-format nil nil org-html-preamble-format)
157 (:html-table-align-individual-fields
158 nil nil org-html-table-align-individual-fields)
159 (:html-table-caption-above nil nil org-html-table-caption-above)
160 (:html-table-data-tags nil nil org-html-table-data-tags)
161 (:html-table-header-tags nil nil org-html-table-header-tags)
162 (:html-table-use-header-tags-for-first-column
163 nil nil org-html-table-use-header-tags-for-first-column)
164 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
165 (:html-text-markup-alist nil nil org-html-text-markup-alist)
166 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
167 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
168 (:html-use-infojs nil nil org-html-use-infojs)
169 (:html-validation-link nil nil org-html-validation-link)
170 (:html-viewport nil nil org-html-viewport)
171 (:html-inline-images nil nil org-html-inline-images)
172 (:html-table-attributes nil nil org-html-table-default-attributes)
173 (:html-table-row-open-tag nil nil org-html-table-row-open-tag)
174 (:html-table-row-close-tag nil nil org-html-table-row-close-tag)
175 (:html-xml-declaration nil nil org-html-xml-declaration)
176 (:infojs-opt "INFOJS_OPT" nil nil)
177 ;; Redefine regular options.
178 (:creator "CREATOR" nil org-html-creator-string)
179 (:with-latex nil "tex" org-html-with-latex)
180 ;; Retrieve LaTeX header for fragments.
181 (:latex-header "LATEX_HEADER" nil nil newline)))
184 ;;; Internal Variables
186 (defvar org-html-format-table-no-css)
187 (defvar htmlize-buffer-places) ; from htmlize.el
189 (defvar org-html--pre/postamble-class "status"
190 "CSS class used for pre/postamble")
192 (defconst org-html-doctype-alist
193 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
194 \"http://www.w3.org/TR/html4/strict.dtd\">")
195 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
196 \"http://www.w3.org/TR/html4/loose.dtd\">")
197 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
198 \"http://www.w3.org/TR/html4/frameset.dtd\">")
200 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
201 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
202 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
203 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
204 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
205 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
206 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
207 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
209 ("html5" . "<!DOCTYPE html>")
210 ("xhtml5" . "<!DOCTYPE html>"))
211 "An alist mapping (x)html flavors to specific doctypes.")
213 (defconst org-html-html5-elements
214 '("article" "aside" "audio" "canvas" "details" "figcaption"
215 "figure" "footer" "header" "menu" "meter" "nav" "output"
216 "progress" "section" "video")
217 "New elements in html5.
219 For blocks that should contain headlines, use the HTML_CONTAINER
220 property on the headline itself.")
222 (defconst org-html-special-string-regexps
223 '(("\\\\-" . "&#x00ad;") ; shy
224 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
225 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
226 ("\\.\\.\\." . "&#x2026;")) ; hellip
227 "Regular expressions for special string conversion.")
229 (defconst org-html-scripts
230 "<script type=\"text/javascript\">
232 @licstart The following is the entire license notice for the
233 JavaScript code in this tag.
235 Copyright (C) 2012-2013 Free Software Foundation, Inc.
237 The JavaScript code in this tag is free software: you can
238 redistribute it and/or modify it under the terms of the GNU
239 General Public License (GNU GPL) as published by the Free Software
240 Foundation, either version 3 of the License, or (at your option)
241 any later version. The code is distributed WITHOUT ANY WARRANTY;
242 without even the implied warranty of MERCHANTABILITY or FITNESS
243 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
245 As additional permission under GNU GPL version 3 section 7, you
246 may distribute non-source (e.g., minimized or compacted) forms of
247 that code without the copy of the GNU GPL normally required by
248 section 4, provided you include this license notice and a URL
249 through which recipients can access the Corresponding Source.
252 @licend The above is the entire license notice
253 for the JavaScript code in this tag.
255 <!--/*--><![CDATA[/*><!--*/
256 function CodeHighlightOn(elem, id)
258 var target = document.getElementById(id);
259 if(null != target) {
260 elem.cacheClassElem = elem.className;
261 elem.cacheClassTarget = target.className;
262 target.className = \"code-highlighted\";
263 elem.className = \"code-highlighted\";
266 function CodeHighlightOff(elem, id)
268 var target = document.getElementById(id);
269 if(elem.cacheClassElem)
270 elem.className = elem.cacheClassElem;
271 if(elem.cacheClassTarget)
272 target.className = elem.cacheClassTarget;
274 /*]]>*///-->
275 </script>"
276 "Basic JavaScript that is needed by HTML files produced by Org mode.")
278 (defconst org-html-style-default
279 "<style type=\"text/css\">
280 <!--/*--><![CDATA[/*><!--*/
281 .title { text-align: center;
282 margin-bottom: .2em; }
283 .subtitle { text-align: center;
284 font-size: medium;
285 font-weight: bold;
286 margin-top:0; }
287 .todo { font-family: monospace; color: red; }
288 .done { font-family: monospace; color: green; }
289 .priority { font-family: monospace; color: orange; }
290 .tag { background-color: #eee; font-family: monospace;
291 padding: 2px; font-size: 80%; font-weight: normal; }
292 .timestamp { color: #bebebe; }
293 .timestamp-kwd { color: #5f9ea0; }
294 .org-right { margin-left: auto; margin-right: 0px; text-align: right; }
295 .org-left { margin-left: 0px; margin-right: auto; text-align: left; }
296 .org-center { margin-left: auto; margin-right: auto; text-align: center; }
297 .underline { text-decoration: underline; }
298 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
299 p.verse { margin-left: 3%; }
300 pre {
301 border: 1px solid #ccc;
302 box-shadow: 3px 3px 3px #eee;
303 padding: 8pt;
304 font-family: monospace;
305 overflow: auto;
306 margin: 1.2em;
308 pre.src {
309 position: relative;
310 overflow: visible;
311 padding-top: 1.2em;
313 pre.src:before {
314 display: none;
315 position: absolute;
316 background-color: white;
317 top: -10px;
318 right: 10px;
319 padding: 3px;
320 border: 1px solid black;
322 pre.src:hover:before { display: inline;}
323 /* Languages per Org manual */
324 pre.src-asymptote:before { content: 'Asymptote'; }
325 pre.src-awk:before { content: 'Awk'; }
326 pre.src-C:before { content: 'C'; }
327 /* pre.src-C++ doesn't work in CSS */
328 pre.src-clojure:before { content: 'Clojure'; }
329 pre.src-css:before { content: 'CSS'; }
330 pre.src-D:before { content: 'D'; }
331 pre.src-ditaa:before { content: 'ditaa'; }
332 pre.src-dot:before { content: 'Graphviz'; }
333 pre.src-calc:before { content: 'Emacs Calc'; }
334 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
335 pre.src-fortran:before { content: 'Fortran'; }
336 pre.src-gnuplot:before { content: 'gnuplot'; }
337 pre.src-haskell:before { content: 'Haskell'; }
338 pre.src-java:before { content: 'Java'; }
339 pre.src-js:before { content: 'Javascript'; }
340 pre.src-latex:before { content: 'LaTeX'; }
341 pre.src-ledger:before { content: 'Ledger'; }
342 pre.src-lisp:before { content: 'Lisp'; }
343 pre.src-lilypond:before { content: 'Lilypond'; }
344 pre.src-matlab:before { content: 'MATLAB'; }
345 pre.src-mscgen:before { content: 'Mscgen'; }
346 pre.src-ocaml:before { content: 'Objective Caml'; }
347 pre.src-octave:before { content: 'Octave'; }
348 pre.src-org:before { content: 'Org mode'; }
349 pre.src-oz:before { content: 'OZ'; }
350 pre.src-plantuml:before { content: 'Plantuml'; }
351 pre.src-processing:before { content: 'Processing.js'; }
352 pre.src-python:before { content: 'Python'; }
353 pre.src-R:before { content: 'R'; }
354 pre.src-ruby:before { content: 'Ruby'; }
355 pre.src-sass:before { content: 'Sass'; }
356 pre.src-scheme:before { content: 'Scheme'; }
357 pre.src-screen:before { content: 'Gnu Screen'; }
358 pre.src-sed:before { content: 'Sed'; }
359 pre.src-sh:before { content: 'shell'; }
360 pre.src-sql:before { content: 'SQL'; }
361 pre.src-sqlite:before { content: 'SQLite'; }
362 /* additional languages in org.el's org-babel-load-languages alist */
363 pre.src-forth:before { content: 'Forth'; }
364 pre.src-io:before { content: 'IO'; }
365 pre.src-J:before { content: 'J'; }
366 pre.src-makefile:before { content: 'Makefile'; }
367 pre.src-maxima:before { content: 'Maxima'; }
368 pre.src-perl:before { content: 'Perl'; }
369 pre.src-picolisp:before { content: 'Pico Lisp'; }
370 pre.src-scala:before { content: 'Scala'; }
371 pre.src-shell:before { content: 'Shell Script'; }
372 pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
373 /* additional language identifiers per \"defun org-babel-execute\"
374 in ob-*.el */
375 pre.src-cpp:before { content: 'C++'; }
376 pre.src-abc:before { content: 'ABC'; }
377 pre.src-coq:before { content: 'Coq'; }
378 pre.src-groovy:before { content: 'Groovy'; }
379 /* additional language identifiers from org-babel-shell-names in
380 ob-shell.el: ob-shell is the only babel language using a lambda to put
381 the execution function name together. */
382 pre.src-bash:before { content: 'bash'; }
383 pre.src-csh:before { content: 'csh'; }
384 pre.src-ash:before { content: 'ash'; }
385 pre.src-dash:before { content: 'dash'; }
386 pre.src-ksh:before { content: 'ksh'; }
387 pre.src-mksh:before { content: 'mksh'; }
388 pre.src-posh:before { content: 'posh'; }
389 /* Additional Emacs modes also supported by the LaTeX listings package */
390 pre.src-ada:before { content: 'Ada'; }
391 pre.src-asm:before { content: 'Assembler'; }
392 pre.src-caml:before { content: 'Caml'; }
393 pre.src-delphi:before { content: 'Delphi'; }
394 pre.src-html:before { content: 'HTML'; }
395 pre.src-idl:before { content: 'IDL'; }
396 pre.src-mercury:before { content: 'Mercury'; }
397 pre.src-metapost:before { content: 'MetaPost'; }
398 pre.src-modula-2:before { content: 'Modula-2'; }
399 pre.src-pascal:before { content: 'Pascal'; }
400 pre.src-ps:before { content: 'PostScript'; }
401 pre.src-prolog:before { content: 'Prolog'; }
402 pre.src-simula:before { content: 'Simula'; }
403 pre.src-tcl:before { content: 'tcl'; }
404 pre.src-tex:before { content: 'TeX'; }
405 pre.src-plain-tex:before { content: 'Plain TeX'; }
406 pre.src-verilog:before { content: 'Verilog'; }
407 pre.src-vhdl:before { content: 'VHDL'; }
408 pre.src-xml:before { content: 'XML'; }
409 pre.src-nxml:before { content: 'XML'; }
410 /* add a generic configuration mode; LaTeX export needs an additional
411 (add-to-list 'org-latex-listings-langs '(conf \" \")) in .emacs */
412 pre.src-conf:before { content: 'Configuration File'; }
414 table { border-collapse:collapse; }
415 caption.t-above { caption-side: top; }
416 caption.t-bottom { caption-side: bottom; }
417 td, th { vertical-align:top; }
418 th.org-right { text-align: center; }
419 th.org-left { text-align: center; }
420 th.org-center { text-align: center; }
421 td.org-right { text-align: right; }
422 td.org-left { text-align: left; }
423 td.org-center { text-align: center; }
424 dt { font-weight: bold; }
425 .footpara { display: inline; }
426 .footdef { margin-bottom: 1em; }
427 .figure { padding: 1em; }
428 .figure p { text-align: center; }
429 .inlinetask {
430 padding: 10px;
431 border: 2px solid gray;
432 margin: 10px;
433 background: #ffffcc;
435 #org-div-home-and-up
436 { text-align: right; font-size: 70%; white-space: nowrap; }
437 textarea { overflow-x: auto; }
438 .linenr { font-size: smaller }
439 .code-highlighted { background-color: #ffff00; }
440 .org-info-js_info-navigation { border-style: none; }
441 #org-info-js_console-label
442 { font-size: 10px; font-weight: bold; white-space: nowrap; }
443 .org-info-js_search-highlight
444 { background-color: #ffff00; color: #000000; font-weight: bold; }
445 /*]]>*/-->
446 </style>"
447 "The default style specification for exported HTML files.
448 You can use `org-html-head' and `org-html-head-extra' to add to
449 this style. If you don't want to include this default style,
450 customize `org-html-head-include-default-style'.")
453 ;;; User Configuration Variables
455 (defgroup org-export-html nil
456 "Options for exporting Org mode files to HTML."
457 :tag "Org Export HTML"
458 :group 'org-export)
460 ;;;; Handle infojs
462 (defvar org-html-infojs-opts-table
463 '((path PATH "http://orgmode.org/org-info.js")
464 (view VIEW "info")
465 (toc TOC :with-toc)
466 (ftoc FIXED_TOC "0")
467 (tdepth TOC_DEPTH "max")
468 (sdepth SECTION_DEPTH "max")
469 (mouse MOUSE_HINT "underline")
470 (buttons VIEW_BUTTONS "0")
471 (ltoc LOCAL_TOC "1")
472 (up LINK_UP :html-link-up)
473 (home LINK_HOME :html-link-home))
474 "JavaScript options, long form for script, default values.")
476 (defcustom org-html-use-infojs 'when-configured
477 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
478 This option can be nil or t to never or always use the script.
479 It can also be the symbol `when-configured', meaning that the
480 script will be linked into the export file if and only if there
481 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
482 `org-html-infojs-options'."
483 :group 'org-export-html
484 :version "24.4"
485 :package-version '(Org . "8.0")
486 :type '(choice
487 (const :tag "Never" nil)
488 (const :tag "When configured in buffer" when-configured)
489 (const :tag "Always" t)))
491 (defcustom org-html-infojs-options
492 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
493 "Options settings for the INFOJS JavaScript.
494 Each of the options must have an entry in `org-html-infojs-opts-table'.
495 The value can either be a string that will be passed to the script, or
496 a property. This property is then assumed to be a property that is defined
497 by the Export/Publishing setup of Org.
498 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
499 means to use the maximum value consistent with other options."
500 :group 'org-export-html
501 :version "24.4"
502 :package-version '(Org . "8.0")
503 :type
504 `(set :greedy t :inline t
505 ,@(mapcar
506 (lambda (x)
507 (list 'cons (list 'const (car x))
508 '(choice
509 (symbol :tag "Publishing/Export property")
510 (string :tag "Value"))))
511 org-html-infojs-opts-table)))
513 (defcustom org-html-infojs-template
514 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
517 * @source: %SCRIPT_PATH
519 * @licstart The following is the entire license notice for the
520 * JavaScript code in %SCRIPT_PATH.
522 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
525 * The JavaScript code in this tag is free software: you can
526 * redistribute it and/or modify it under the terms of the GNU
527 * General Public License (GNU GPL) as published by the Free Software
528 * Foundation, either version 3 of the License, or (at your option)
529 * any later version. The code is distributed WITHOUT ANY WARRANTY;
530 * without even the implied warranty of MERCHANTABILITY or FITNESS
531 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
533 * As additional permission under GNU GPL version 3 section 7, you
534 * may distribute non-source (e.g., minimized or compacted) forms of
535 * that code without the copy of the GNU GPL normally required by
536 * section 4, provided you include this license notice and a URL
537 * through which recipients can access the Corresponding Source.
539 * @licend The above is the entire license notice
540 * for the JavaScript code in %SCRIPT_PATH.
543 </script>
545 <script type=\"text/javascript\">
548 @licstart The following is the entire license notice for the
549 JavaScript code in this tag.
551 Copyright (C) 2012-2013 Free Software Foundation, Inc.
553 The JavaScript code in this tag is free software: you can
554 redistribute it and/or modify it under the terms of the GNU
555 General Public License (GNU GPL) as published by the Free Software
556 Foundation, either version 3 of the License, or (at your option)
557 any later version. The code is distributed WITHOUT ANY WARRANTY;
558 without even the implied warranty of MERCHANTABILITY or FITNESS
559 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
561 As additional permission under GNU GPL version 3 section 7, you
562 may distribute non-source (e.g., minimized or compacted) forms of
563 that code without the copy of the GNU GPL normally required by
564 section 4, provided you include this license notice and a URL
565 through which recipients can access the Corresponding Source.
568 @licend The above is the entire license notice
569 for the JavaScript code in this tag.
572 <!--/*--><![CDATA[/*><!--*/
573 %MANAGER_OPTIONS
574 org_html_manager.setup(); // activate after the parameters are set
575 /*]]>*///-->
576 </script>"
577 "The template for the export style additions when org-info.js is used.
578 Option settings will replace the %MANAGER-OPTIONS cookie."
579 :group 'org-export-html
580 :version "24.4"
581 :package-version '(Org . "8.0")
582 :type 'string)
584 (defun org-html-infojs-install-script (exp-plist _backend)
585 "Install script in export options when appropriate.
586 EXP-PLIST is a plist containing export options. BACKEND is the
587 export back-end currently used."
588 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
589 (not (plist-get exp-plist :html-use-infojs))
590 (and (eq (plist-get exp-plist :html-use-infojs) 'when-configured)
591 (let ((opt (plist-get exp-plist :infojs-opt)))
592 (or (not opt)
593 (string= "" opt)
594 (string-match "\\<view:nil\\>" opt)))))
595 (let* ((template (plist-get exp-plist :html-infojs-template))
596 (ptoc (plist-get exp-plist :with-toc))
597 (hlevels (plist-get exp-plist :headline-levels))
598 (sdepth hlevels)
599 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
600 (options (plist-get exp-plist :infojs-opt))
601 (infojs-opt (plist-get exp-plist :html-infojs-options))
602 (table org-html-infojs-opts-table)
603 style)
604 (dolist (entry table)
605 (let* ((opt (car entry))
606 (var (nth 1 entry))
607 ;; Compute default values for script option OPT from
608 ;; `org-html-infojs-options' variable.
609 (default
610 (let ((default (cdr (assq opt infojs-opt))))
611 (if (and (symbolp default) (not (memq default '(t nil))))
612 (plist-get exp-plist default)
613 default)))
614 ;; Value set through INFOJS_OPT keyword has precedence
615 ;; over the default one.
616 (val (if (and options
617 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
618 options))
619 (match-string 1 options)
620 default)))
621 (case opt
622 (path (setq template
623 (replace-regexp-in-string
624 "%SCRIPT_PATH" val template t t)))
625 (sdepth (when (integerp (read val))
626 (setq sdepth (min (read val) sdepth))))
627 (tdepth (when (integerp (read val))
628 (setq tdepth (min (read val) tdepth))))
629 (otherwise (setq val
630 (cond
631 ((or (eq val t) (equal val "t")) "1")
632 ((or (eq val nil) (equal val "nil")) "0")
633 ((stringp val) val)
634 (t (format "%s" val))))
635 (push (cons var val) style)))))
636 ;; Now we set the depth of the *generated* TOC to SDEPTH,
637 ;; because the toc will actually determine the splitting. How
638 ;; much of the toc will actually be displayed is governed by the
639 ;; TDEPTH option.
640 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
641 ;; The table of contents should not show more sections than we
642 ;; generate.
643 (setq tdepth (min tdepth sdepth))
644 (push (cons "TOC_DEPTH" tdepth) style)
645 ;; Build style string.
646 (setq style (mapconcat
647 (lambda (x)
648 (format "org_html_manager.set(\"%s\", \"%s\");"
649 (car x) (cdr x)))
650 style "\n"))
651 (when (and style (> (length style) 0))
652 (and (string-match "%MANAGER_OPTIONS" template)
653 (setq style (replace-match style t t template))
654 (setq exp-plist
655 (plist-put
656 exp-plist :html-head-extra
657 (concat (or (plist-get exp-plist :html-head-extra) "")
658 "\n"
659 style)))))
660 ;; This script absolutely needs the table of contents, so we
661 ;; change that setting.
662 (unless (plist-get exp-plist :with-toc)
663 (setq exp-plist (plist-put exp-plist :with-toc t)))
664 ;; Return the modified property list.
665 exp-plist)))
667 ;;;; Bold, etc.
669 (defcustom org-html-text-markup-alist
670 '((bold . "<b>%s</b>")
671 (code . "<code>%s</code>")
672 (italic . "<i>%s</i>")
673 (strike-through . "<del>%s</del>")
674 (underline . "<span class=\"underline\">%s</span>")
675 (verbatim . "<code>%s</code>"))
676 "Alist of HTML expressions to convert text markup.
678 The key must be a symbol among `bold', `code', `italic',
679 `strike-through', `underline' and `verbatim'. The value is
680 a formatting string to wrap fontified text with.
682 If no association can be found for a given markup, text will be
683 returned as-is."
684 :group 'org-export-html
685 :version "24.4"
686 :package-version '(Org . "8.0")
687 :type '(alist :key-type (symbol :tag "Markup type")
688 :value-type (string :tag "Format string"))
689 :options '(bold code italic strike-through underline verbatim))
691 (defcustom org-html-indent nil
692 "Non-nil means to indent the generated HTML.
693 Warning: non-nil may break indentation of source code blocks."
694 :group 'org-export-html
695 :version "24.4"
696 :package-version '(Org . "8.0")
697 :type 'boolean)
699 ;;;; Drawers
701 (defcustom org-html-format-drawer-function (lambda (_name contents) contents)
702 "Function called to format a drawer in HTML code.
704 The function must accept two parameters:
705 NAME the drawer name, like \"LOGBOOK\"
706 CONTENTS the contents of the drawer.
708 The function should return the string to be exported.
710 For example, the variable could be set to the following function
711 in order to mimic default behavior:
713 The default value simply returns the value of CONTENTS."
714 :group 'org-export-html
715 :version "24.4"
716 :package-version '(Org . "8.0")
717 :type 'function)
719 ;;;; Footnotes
721 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
722 <h2 class=\"footnotes\">%s: </h2>
723 <div id=\"text-footnotes\">
725 </div>
726 </div>"
727 "Format for the footnotes section.
728 Should contain a two instances of %s. The first will be replaced with the
729 language-specific word for \"Footnotes\", the second one will be replaced
730 by the footnotes themselves."
731 :group 'org-export-html
732 :type 'string)
734 (defcustom org-html-footnote-format "<sup>%s</sup>"
735 "The format for the footnote reference.
736 %s will be replaced by the footnote reference itself."
737 :group 'org-export-html
738 :type 'string)
740 (defcustom org-html-footnote-separator "<sup>, </sup>"
741 "Text used to separate footnotes."
742 :group 'org-export-html
743 :type 'string)
745 ;;;; Headline
747 (defcustom org-html-toplevel-hlevel 2
748 "The <H> level for level 1 headings in HTML export.
749 This is also important for the classes that will be wrapped around headlines
750 and outline structure. If this variable is 1, the top-level headlines will
751 be <h1>, and the corresponding classes will be outline-1, section-number-1,
752 and outline-text-1. If this is 2, all of these will get a 2 instead.
753 The default for this variable is 2, because we use <h1> for formatting the
754 document title."
755 :group 'org-export-html
756 :type 'integer)
758 (defcustom org-html-format-headline-function
759 'org-html-format-headline-default-function
760 "Function to format headline text.
762 This function will be called with six arguments:
763 TODO the todo keyword (string or nil).
764 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
765 PRIORITY the priority of the headline (integer or nil)
766 TEXT the main headline text (string).
767 TAGS the tags (string or nil).
768 INFO the export options (plist).
770 The function result will be used in the section format string."
771 :group 'org-export-html
772 :version "25.1"
773 :package-version '(Org . "8.3")
774 :type 'function)
776 ;;;; HTML-specific
778 (defcustom org-html-allow-name-attribute-in-anchors nil
779 "When nil, do not set \"name\" attribute in anchors.
780 By default, when appropriate, anchors are formatted with \"id\"
781 but without \"name\" attribute."
782 :group 'org-export-html
783 :version "24.4"
784 :package-version '(Org . "8.0")
785 :type 'boolean)
787 ;;;; Inlinetasks
789 (defcustom org-html-format-inlinetask-function
790 'org-html-format-inlinetask-default-function
791 "Function called to format an inlinetask in HTML code.
793 The function must accept seven parameters:
794 TODO the todo keyword, as a string
795 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
796 PRIORITY the inlinetask priority, as a string
797 NAME the inlinetask name, as a string.
798 TAGS the inlinetask tags, as a list of strings.
799 CONTENTS the contents of the inlinetask, as a string.
800 INFO the export options, as a plist
802 The function should return the string to be exported."
803 :group 'org-export-html
804 :version "25.1"
805 :package-version '(Org . "8.3")
806 :type 'function)
808 ;;;; LaTeX
810 (defcustom org-html-with-latex org-export-with-latex
811 "Non-nil means process LaTeX math snippets.
813 When set, the exporter will process LaTeX environments and
814 fragments.
816 This option can also be set with the +OPTIONS line,
817 e.g. \"tex:mathjax\". Allowed values are:
819 nil Ignore math snippets.
820 `verbatim' Keep everything in verbatim
821 `mathjax', t Do MathJax preprocessing and arrange for MathJax.js to
822 be loaded.
823 SYMBOL Any symbol defined in `org-preview-latex-process-alist',
824 e.g., `dvipng'."
825 :group 'org-export-html
826 :version "24.4"
827 :package-version '(Org . "8.0")
828 :type '(choice
829 (const :tag "Do not process math in any way" nil)
830 (const :tag "Leave math verbatim" verbatim)
831 (const :tag "Use MathJax to display math" mathjax)
832 (symbol :tag "Convert to image to display math" :value dvipng)))
834 ;;;; Links :: Generic
836 (defcustom org-html-link-org-files-as-html t
837 "Non-nil means make file links to `file.org' point to `file.html'.
838 When `org-mode' is exporting an `org-mode' file to HTML, links to
839 non-html files are directly put into a href tag in HTML.
840 However, links to other Org-mode files (recognized by the
841 extension `.org') should become links to the corresponding html
842 file, assuming that the linked `org-mode' file will also be
843 converted to HTML.
844 When nil, the links still point to the plain `.org' file."
845 :group 'org-export-html
846 :type 'boolean)
848 ;;;; Links :: Inline images
850 (defcustom org-html-inline-images t
851 "Non-nil means inline images into exported HTML pages.
852 This is done using an <img> tag. When nil, an anchor with href is used to
853 link to the image."
854 :group 'org-export-html
855 :version "24.4"
856 :package-version '(Org . "8.1")
857 :type 'boolean)
859 (defcustom org-html-inline-image-rules
860 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
861 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
862 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
863 "Rules characterizing image files that can be inlined into HTML.
864 A rule consists in an association whose key is the type of link
865 to consider, and value is a regexp that will be matched against
866 link's path."
867 :group 'org-export-html
868 :version "24.4"
869 :package-version '(Org . "8.0")
870 :type '(alist :key-type (string :tag "Type")
871 :value-type (regexp :tag "Path")))
873 ;;;; Plain Text
875 (defvar org-html-protect-char-alist
876 '(("&" . "&amp;")
877 ("<" . "&lt;")
878 (">" . "&gt;"))
879 "Alist of characters to be converted by `org-html-encode-plain-text'.")
881 ;;;; Src Block
883 (defcustom org-html-htmlize-output-type 'inline-css
884 "Output type to be used by htmlize when formatting code snippets.
885 Choices are `css' to export the CSS selectors only,`inline-css'
886 to export the CSS attribute values inline in the HTML or `nil' to
887 export plain text. We use as default `inline-css', in order to
888 make the resulting HTML self-containing.
890 However, this will fail when using Emacs in batch mode for export, because
891 then no rich font definitions are in place. It will also not be good if
892 people with different Emacs setup contribute HTML files to a website,
893 because the fonts will represent the individual setups. In these cases,
894 it is much better to let Org/Htmlize assign classes only, and to use
895 a style file to define the look of these classes.
896 To get a start for your css file, start Emacs session and make sure that
897 all the faces you are interested in are defined, for example by loading files
898 in all modes you want. Then, use the command
899 \\[org-html-htmlize-generate-css] to extract class definitions."
900 :group 'org-export-html
901 :type '(choice (const css) (const inline-css) (const nil)))
903 (defcustom org-html-htmlize-font-prefix "org-"
904 "The prefix for CSS class names for htmlize font specifications."
905 :group 'org-export-html
906 :type 'string)
908 ;;;; Table
910 (defcustom org-html-table-default-attributes
911 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
912 "Default attributes and values which will be used in table tags.
913 This is a plist where attributes are symbols, starting with
914 colons, and values are strings.
916 When exporting to HTML5, these values will be disregarded."
917 :group 'org-export-html
918 :version "24.4"
919 :package-version '(Org . "8.0")
920 :type '(plist :key-type (symbol :tag "Property")
921 :value-type (string :tag "Value")))
923 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
924 "The opening and ending tags for table header fields.
925 This is customizable so that alignment options can be specified.
926 The first %s will be filled with the scope of the field, either row or col.
927 The second %s will be replaced by a style entry to align the field.
928 See also the variable `org-html-table-use-header-tags-for-first-column'.
929 See also the variable `org-html-table-align-individual-fields'."
930 :group 'org-export-html
931 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
933 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
934 "The opening and ending tags for table data fields.
935 This is customizable so that alignment options can be specified.
936 The first %s will be filled with the scope of the field, either row or col.
937 The second %s will be replaced by a style entry to align the field.
938 See also the variable `org-html-table-align-individual-fields'."
939 :group 'org-export-html
940 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
942 (defcustom org-html-table-row-open-tag "<tr>"
943 "The opening tag for table rows.
944 This is customizable so that alignment options can be specified.
945 Instead of strings, these can be a Lisp function that will be
946 evaluated for each row in order to construct the table row tags.
948 The function will be called with these arguments:
950 `number': row number (0 is the first row)
951 `group-number': group number of current row
952 `start-group-p': non-nil means the row starts a group
953 `end-group-p': non-nil means the row ends a group
954 `topp': non-nil means this is the top row
955 `bottomp': non-nil means this is the bottom row
957 For example:
959 \(setq org-html-table-row-open-tag
960 \(lambda (number group-number start-group-p end-group-p topp bottomp)
961 \(cond (topp \"<tr class=\\\"tr-top\\\">\")
962 \(bottomp \"<tr class=\\\"tr-bottom\\\">\")
963 \(t (if (= (mod number 2) 1)
964 \"<tr class=\\\"tr-odd\\\">\"
965 \"<tr class=\\\"tr-even\\\">\")))))
967 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
968 and the bottom row, and otherwise alternate between \"tr-odd\" and
969 \"tr-even\" for odd and even rows."
970 :group 'org-export-html
971 :type '(choice :tag "Opening tag"
972 (string :tag "Specify")
973 (function)))
975 (defcustom org-html-table-row-close-tag "</tr>"
976 "The closing tag for table rows.
977 This is customizable so that alignment options can be specified.
978 Instead of strings, this can be a Lisp function that will be
979 evaluated for each row in order to construct the table row tags.
981 See documentation of `org-html-table-row-open-tag'."
982 :group 'org-export-html
983 :type '(choice :tag "Closing tag"
984 (string :tag "Specify")
985 (function)))
987 (defcustom org-html-table-align-individual-fields t
988 "Non-nil means attach style attributes for alignment to each table field.
989 When nil, alignment will only be specified in the column tags, but this
990 is ignored by some browsers (like Firefox, Safari). Opera does it right
991 though."
992 :group 'org-export-html
993 :type 'boolean)
995 (defcustom org-html-table-use-header-tags-for-first-column nil
996 "Non-nil means format column one in tables with header tags.
997 When nil, also column one will use data tags."
998 :group 'org-export-html
999 :type 'boolean)
1001 (defcustom org-html-table-caption-above t
1002 "When non-nil, place caption string at the beginning of the table.
1003 Otherwise, place it near the end."
1004 :group 'org-export-html
1005 :type 'boolean)
1007 ;;;; Tags
1009 (defcustom org-html-tag-class-prefix ""
1010 "Prefix to class names for TODO keywords.
1011 Each tag gets a class given by the tag itself, with this prefix.
1012 The default prefix is empty because it is nice to just use the keyword
1013 as a class name. But if you get into conflicts with other, existing
1014 CSS classes, then this prefix can be very useful."
1015 :group 'org-export-html
1016 :type 'string)
1018 ;;;; Template :: Generic
1020 (defcustom org-html-extension "html"
1021 "The extension for exported HTML files."
1022 :group 'org-export-html
1023 :type 'string)
1025 (defcustom org-html-xml-declaration
1026 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
1027 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
1028 "The extension for exported HTML files.
1029 %s will be replaced with the charset of the exported file.
1030 This may be a string, or an alist with export extensions
1031 and corresponding declarations.
1033 This declaration only applies when exporting to XHTML."
1034 :group 'org-export-html
1035 :type '(choice
1036 (string :tag "Single declaration")
1037 (repeat :tag "Dependent on extension"
1038 (cons (string :tag "Extension")
1039 (string :tag "Declaration")))))
1041 (defcustom org-html-coding-system 'utf-8
1042 "Coding system for HTML export.
1043 Use utf-8 as the default value."
1044 :group 'org-export-html
1045 :version "24.4"
1046 :package-version '(Org . "8.0")
1047 :type 'coding-system)
1049 (defcustom org-html-doctype "xhtml-strict"
1050 "Document type definition to use for exported HTML files.
1051 Can be set with the in-buffer HTML_DOCTYPE property or for
1052 publishing, with :html-doctype."
1053 :group 'org-export-html
1054 :version "24.4"
1055 :package-version '(Org . "8.0")
1056 :type (append
1057 '(choice)
1058 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
1059 '((string :tag "Custom doctype" ))))
1061 (defcustom org-html-html5-fancy nil
1062 "Non-nil means using new HTML5 elements.
1063 This variable is ignored for anything other than HTML5 export.
1065 For compatibility with Internet Explorer, it's probably a good
1066 idea to download some form of the html5shiv (for instance
1067 https://code.google.com/p/html5shiv/) and add it to your
1068 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
1069 versions 8 and below."
1070 :group 'org-export-html
1071 :version "24.4"
1072 :package-version '(Org . "8.0")
1073 :type 'boolean)
1075 (defcustom org-html-container-element "div"
1076 "HTML element to use for wrapping top level sections.
1077 Can be set with the in-buffer HTML_CONTAINER property or for
1078 publishing, with :html-container.
1080 Note that changing the default will prevent you from using
1081 org-info.js for your website."
1082 :group 'org-export-html
1083 :version "24.4"
1084 :package-version '(Org . "8.0")
1085 :type 'string)
1087 (defcustom org-html-divs
1088 '((preamble "div" "preamble")
1089 (content "div" "content")
1090 (postamble "div" "postamble"))
1091 "Alist of the three section elements for HTML export.
1092 The car of each entry is one of `preamble', `content' or `postamble'.
1093 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1094 section of the exported document.
1096 Note that changing the default will prevent you from using
1097 org-info.js for your website."
1098 :group 'org-export-html
1099 :version "24.4"
1100 :package-version '(Org . "8.0")
1101 :type '(list :greedy t
1102 (list :tag "Preamble"
1103 (const :format "" preamble)
1104 (string :tag "element") (string :tag " id"))
1105 (list :tag "Content"
1106 (const :format "" content)
1107 (string :tag "element") (string :tag " id"))
1108 (list :tag "Postamble" (const :format "" postamble)
1109 (string :tag " id") (string :tag "element"))))
1111 (defconst org-html-checkbox-types
1112 '((unicode .
1113 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1114 (ascii .
1115 ((on . "<code>[X]</code>")
1116 (off . "<code>[&#xa0;]</code>")
1117 (trans . "<code>[-]</code>")))
1118 (html .
1119 ((on . "<input type='checkbox' checked='checked' />")
1120 (off . "<input type='checkbox' />")
1121 (trans . "<input type='checkbox' />"))))
1122 "Alist of checkbox types.
1123 The cdr of each entry is an alist list three checkbox types for
1124 HTML export: `on', `off' and `trans'.
1126 The choices are:
1127 `unicode' Unicode characters (HTML entities)
1128 `ascii' ASCII characters
1129 `html' HTML checkboxes
1131 Note that only the ascii characters implement tri-state
1132 checkboxes. The other two use the `off' checkbox for `trans'.")
1134 (defcustom org-html-checkbox-type 'ascii
1135 "The type of checkboxes to use for HTML export.
1136 See `org-html-checkbox-types' for for the values used for each
1137 option."
1138 :group 'org-export-html
1139 :version "24.4"
1140 :package-version '(Org . "8.0")
1141 :type '(choice
1142 (const :tag "ASCII characters" ascii)
1143 (const :tag "Unicode characters" unicode)
1144 (const :tag "HTML checkboxes" html)))
1146 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1147 "Format used for timestamps in preamble, postamble and metadata.
1148 See `format-time-string' for more information on its components."
1149 :group 'org-export-html
1150 :version "24.4"
1151 :package-version '(Org . "8.0")
1152 :type 'string)
1154 ;;;; Template :: Mathjax
1156 (defcustom org-html-mathjax-options
1157 '((path "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" )
1158 (scale "100")
1159 (align "center")
1160 (font "TeX")
1161 (linebreaks "false")
1162 (autonumber "AMS")
1163 (indent "0em")
1164 (multlinewidth "85%")
1165 (tagindent ".8em")
1166 (tagside "right"))
1167 "Options for MathJax setup.
1169 Alist of the following elements. All values are strings.
1171 path The path to MathJax.
1172 scale Scaling with HTML-CSS, MathML and SVG output engines.
1173 align How to align display math: left, center, or right.
1174 font The font to use with HTML-CSS and SVG output. As of MathJax 2.5
1175 the following values are understood: \"TeX\", \"STIX-Web\",
1176 \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\",
1177 \"Gyre-Termes\", and \"Latin-Modern\".
1178 linebreaks Let MathJax perform automatic linebreaks. Valid values
1179 are \"true\" and \"false\".
1180 indent If align is not center, how far from the left/right side?
1181 Valid values are \"left\" and \"right\"
1182 multlinewidth The width of the multline environment.
1183 autonumber How to number equations. Valid values are \"None\",
1184 \"all\" and \"AMS Math\".
1185 tagindent The amount tags are indented.
1186 tagside Which side to show tags/labels on. Valid values are
1187 \"left\" and \"right\"
1189 You can also customize this for each buffer, using something like
1191 #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler
1193 For further information about MathJax options, see the MathJax documentation:
1195 http://docs.mathjax.org/
1197 Please note that by using the default CDN one must agree with
1198 MathJax CDN Terms of Service.
1200 http://www.mathjax.org/mathjax-cdn-terms-of-service.html"
1201 :group 'org-export-html
1202 :package-version '(Org . "8.3")
1203 :type '(list :greedy t
1204 (list :tag "path (the path from where to load MathJax.js)"
1205 (const :format " " path) (string))
1206 (list :tag "scale (scaling for the displayed math)"
1207 (const :format " " scale) (string))
1208 (list :tag "align (alignment of displayed equations)"
1209 (const :format " " align) (string))
1210 (list :tag "font (used to display math)"
1211 (const :format " " font)
1212 (choice (const "TeX")
1213 (const "STIX-Web")
1214 (const "Asana-Math")
1215 (const "Neo-Euler")
1216 (const "Gyre-Pagella")
1217 (const "Gyre-Termes")
1218 (const "Latin-Modern")))
1219 (list :tag "linebreaks (automatic line-breaking)"
1220 (const :format " " linebreaks)
1221 (choice (const "true")
1222 (const "false")))
1223 (list :tag "autonumber (when should equations be numbered)"
1224 (const :format " " autonumber)
1225 (choice (const "AMS")
1226 (const "None")
1227 (const "All")))
1228 (list :tag "indent (indentation with left or right alignment)"
1229 (const :format " " indent) (string))
1230 (list :tag "multlinewidth (width to use for the multline environment)"
1231 (const :format " " multlinewidth) (string))
1232 (list :tag "tagindent (the indentation of tags from left or right)"
1233 (const :format " " tagindent) (string))
1234 (list :tag "tagside (location of tags)"
1235 (const :format " " tagside)
1236 (choice (const "left")
1237 (const "right")))))
1239 (defcustom org-html-mathjax-template
1240 "<script type=\"text/x-mathjax-config\">
1241 MathJax.Hub.Config({
1242 displayAlign: \"%ALIGN\",
1243 displayIndent: \"%INDENT\",
1245 \"HTML-CSS\": { scale: %SCALE,
1246 linebreaks: { automatic: \"%LINEBREAKS\" },
1247 webFont: \"%FONT\"
1249 SVG: {scale: %SCALE,
1250 linebreaks: { automatic: \"%LINEBREAKS\" },
1251 font: \"%FONT\"},
1252 NativeMML: {scale: %SCALE},
1253 TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
1254 MultLineWidth: \"%MULTLINEWIDTH\",
1255 TagSide: \"%TAGSIDE\",
1256 TagIndent: \"%TAGINDENT\"
1259 </script>
1260 <script type=\"text/javascript\"
1261 src=\"%PATH\"></script>"
1262 "The MathJax template. See also `org-html-mathjax-options'."
1263 :group 'org-export-html
1264 :type 'string)
1266 ;;;; Template :: Postamble
1268 (defcustom org-html-postamble 'auto
1269 "Non-nil means insert a postamble in HTML export.
1271 When set to `auto', check against the
1272 `org-export-with-author/email/creator/date' variables to set the
1273 content of the postamble. When set to a string, use this string
1274 as the postamble. When t, insert a string as defined by the
1275 formatting string in `org-html-postamble-format'.
1277 When set to a function, apply this function and insert the
1278 returned string. The function takes the property list of export
1279 options as its only argument.
1281 Setting :html-postamble in publishing projects will take
1282 precedence over this variable."
1283 :group 'org-export-html
1284 :type '(choice (const :tag "No postamble" nil)
1285 (const :tag "Auto postamble" auto)
1286 (const :tag "Default formatting string" t)
1287 (string :tag "Custom formatting string")
1288 (function :tag "Function (must return a string)")))
1290 (defcustom org-html-postamble-format
1291 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1292 <p class=\"date\">Date: %d</p>
1293 <p class=\"creator\">%c</p>
1294 <p class=\"validation\">%v</p>"))
1295 "Alist of languages and format strings for the HTML postamble.
1297 The first element of each list is the language code, as used for
1298 the LANGUAGE keyword. See `org-export-default-language'.
1300 The second element of each list is a format string to format the
1301 postamble itself. This format string can contain these elements:
1303 %t stands for the title.
1304 %s stands for the subtitle.
1305 %a stands for the author's name.
1306 %e stands for the author's email.
1307 %d stands for the date.
1308 %c will be replaced by `org-html-creator-string'.
1309 %v will be replaced by `org-html-validation-link'.
1310 %T will be replaced by the export time.
1311 %C will be replaced by the last modification time.
1313 If you need to use a \"%\" character, you need to escape it
1314 like that: \"%%\"."
1315 :group 'org-export-html
1316 :type '(repeat
1317 (list (string :tag "Language")
1318 (string :tag "Format string"))))
1320 (defcustom org-html-validation-link
1321 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1322 "Link to HTML validation service."
1323 :group 'org-export-html
1324 :type 'string)
1326 (defcustom org-html-creator-string
1327 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1328 emacs-version
1329 (if (fboundp 'org-version) (org-version) "unknown version"))
1330 "Information about the creator of the HTML document.
1331 This option can also be set on with the CREATOR keyword."
1332 :group 'org-export-html
1333 :version "24.4"
1334 :package-version '(Org . "8.0")
1335 :type '(string :tag "Creator string"))
1337 ;;;; Template :: Preamble
1339 (defcustom org-html-preamble t
1340 "Non-nil means insert a preamble in HTML export.
1342 When t, insert a string as defined by the formatting string in
1343 `org-html-preamble-format'. When set to a string, use this
1344 formatting string instead (see `org-html-postamble-format' for an
1345 example of such a formatting string).
1347 When set to a function, apply this function and insert the
1348 returned string. The function takes the property list of export
1349 options as its only argument.
1351 Setting :html-preamble in publishing projects will take
1352 precedence over this variable."
1353 :group 'org-export-html
1354 :type '(choice (const :tag "No preamble" nil)
1355 (const :tag "Default preamble" t)
1356 (string :tag "Custom formatting string")
1357 (function :tag "Function (must return a string)")))
1359 (defcustom org-html-preamble-format '(("en" ""))
1360 "Alist of languages and format strings for the HTML preamble.
1362 The first element of each list is the language code, as used for
1363 the LANGUAGE keyword. See `org-export-default-language'.
1365 The second element of each list is a format string to format the
1366 preamble itself. This format string can contain these elements:
1368 %t stands for the title.
1369 %s stands for the subtitle.
1370 %a stands for the author's name.
1371 %e stands for the author's email.
1372 %d stands for the date.
1373 %c will be replaced by `org-html-creator-string'.
1374 %v will be replaced by `org-html-validation-link'.
1375 %T will be replaced by the export time.
1376 %C will be replaced by the last modification time.
1378 If you need to use a \"%\" character, you need to escape it
1379 like that: \"%%\".
1381 See the default value of `org-html-postamble-format' for an
1382 example."
1383 :group 'org-export-html
1384 :type '(repeat
1385 (list (string :tag "Language")
1386 (string :tag "Format string"))))
1388 (defcustom org-html-link-up ""
1389 "Where should the \"UP\" link of exported HTML pages lead?"
1390 :group 'org-export-html
1391 :type '(string :tag "File or URL"))
1393 (defcustom org-html-link-home ""
1394 "Where should the \"HOME\" link of exported HTML pages lead?"
1395 :group 'org-export-html
1396 :type '(string :tag "File or URL"))
1398 (defcustom org-html-link-use-abs-url nil
1399 "Should we prepend relative links with HTML_LINK_HOME?"
1400 :group 'org-export-html
1401 :version "24.4"
1402 :package-version '(Org . "8.1")
1403 :type 'boolean)
1405 (defcustom org-html-home/up-format
1406 "<div id=\"org-div-home-and-up\">
1407 <a accesskey=\"h\" href=\"%s\"> UP </a>
1409 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1410 </div>"
1411 "Snippet used to insert the HOME and UP links.
1412 This is a format string, the first %s will receive the UP link,
1413 the second the HOME link. If both `org-html-link-up' and
1414 `org-html-link-home' are empty, the entire snippet will be
1415 ignored."
1416 :group 'org-export-html
1417 :type 'string)
1419 ;;;; Template :: Scripts
1421 (define-obsolete-variable-alias
1422 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1423 (defcustom org-html-head-include-scripts t
1424 "Non-nil means include the JavaScript snippets in exported HTML files.
1425 The actual script is defined in `org-html-scripts' and should
1426 not be modified."
1427 :group 'org-export-html
1428 :version "24.4"
1429 :package-version '(Org . "8.0")
1430 :type 'boolean)
1432 ;;;; Template :: Styles
1434 (define-obsolete-variable-alias
1435 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1436 (defcustom org-html-head-include-default-style t
1437 "Non-nil means include the default style in exported HTML files.
1438 The actual style is defined in `org-html-style-default' and
1439 should not be modified. Use `org-html-head' to use your own
1440 style information."
1441 :group 'org-export-html
1442 :version "24.4"
1443 :package-version '(Org . "8.0")
1444 :type 'boolean)
1445 ;;;###autoload
1446 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1448 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1449 (defcustom org-html-head ""
1450 "Org-wide head definitions for exported HTML files.
1452 This variable can contain the full HTML structure to provide a
1453 style, including the surrounding HTML tags. You can consider
1454 including definitions for the following classes: title, todo,
1455 done, timestamp, timestamp-kwd, tag, target.
1457 For example, a valid value would be:
1459 <style type=\"text/css\">
1460 <![CDATA[
1461 p { font-weight: normal; color: gray; }
1462 h1 { color: black; }
1463 .title { text-align: center; }
1464 .todo, .timestamp-kwd { color: red; }
1465 .done { color: green; }
1467 </style>
1469 If you want to refer to an external style, use something like
1471 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1473 As the value of this option simply gets inserted into the HTML
1474 <head> header, you can use it to add any arbitrary text to the
1475 header.
1477 You can set this on a per-file basis using #+HTML_HEAD:,
1478 or for publication projects using the :html-head property."
1479 :group 'org-export-html
1480 :version "24.4"
1481 :package-version '(Org . "8.0")
1482 :type 'string)
1483 ;;;###autoload
1484 (put 'org-html-head 'safe-local-variable 'stringp)
1486 (defcustom org-html-head-extra ""
1487 "More head information to add in the HTML output.
1489 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1490 or for publication projects using the :html-head-extra property."
1491 :group 'org-export-html
1492 :version "24.4"
1493 :package-version '(Org . "8.0")
1494 :type 'string)
1495 ;;;###autoload
1496 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1498 ;;;; Template :: Viewport
1500 (defcustom org-html-viewport '((width "device-width")
1501 (initial-scale "1")
1502 (minimum-scale "")
1503 (maximum-scale "")
1504 (user-scalable ""))
1505 "Viewport options for mobile-optimized sites.
1507 The following values are recognized
1509 width Size of the viewport.
1510 initial-scale Zoom level when the page is first loaded.
1511 minimum-scale Minimum allowed zoom level.
1512 maximum-scale Maximum allowed zoom level.
1513 user-scalable Whether zoom can be changed.
1515 The viewport meta tag is inserted if this variable is non-nil.
1517 See the following site for a reference:
1518 https://developer.mozilla.org/en-US/docs/Mozilla/Mobile/Viewport_meta_tag"
1519 :group 'org-export-html
1520 :version "25.1"
1521 :package-version '(Org . "8.3")
1522 :type '(choice (const :tag "Disable" nil)
1523 (list :tag "Enable"
1524 (list :tag "Width of viewport"
1525 (const :format " " width)
1526 (choice (const :tag "unset" "")
1527 (string)))
1528 (list :tag "Initial scale"
1529 (const :format " " initial-scale)
1530 (choice (const :tag "unset" "")
1531 (string)))
1532 (list :tag "Minimum scale/zoom"
1533 (const :format " " minimum-scale)
1534 (choice (const :tag "unset" "")
1535 (string)))
1536 (list :tag "Maximum scale/zoom"
1537 (const :format " " maximum-scale)
1538 (choice (const :tag "unset" "")
1539 (string)))
1540 (list :tag "User scalable/zoomable"
1541 (const :format " " user-scalable)
1542 (choice (const :tag "unset" "")
1543 (const "true")
1544 (const "false"))))))
1546 ;;;; Todos
1548 (defcustom org-html-todo-kwd-class-prefix ""
1549 "Prefix to class names for TODO keywords.
1550 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1551 The default prefix is empty because it is nice to just use the keyword
1552 as a class name. But if you get into conflicts with other, existing
1553 CSS classes, then this prefix can be very useful."
1554 :group 'org-export-html
1555 :type 'string)
1558 ;;; Internal Functions
1560 (defun org-html-xhtml-p (info)
1561 (let ((dt (downcase (plist-get info :html-doctype))))
1562 (string-match-p "xhtml" dt)))
1564 (defun org-html-html5-p (info)
1565 (let ((dt (downcase (plist-get info :html-doctype))))
1566 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1568 (defun org-html--html5-fancy-p (info)
1569 "Non-nil when exporting to HTML5 with fancy elements.
1570 INFO is the current state of the export process, as a plist."
1571 (and (plist-get info :html-html5-fancy)
1572 (org-html-html5-p info)))
1574 (defun org-html-close-tag (tag attr info)
1575 (concat "<" tag " " attr
1576 (if (org-html-xhtml-p info) " />" ">")))
1578 (defun org-html-doctype (info)
1579 "Return correct html doctype tag from `org-html-doctype-alist',
1580 or the literal value of :html-doctype from INFO if :html-doctype
1581 is not found in the alist.
1582 INFO is a plist used as a communication channel."
1583 (let ((dt (plist-get info :html-doctype)))
1584 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1586 (defun org-html--make-attribute-string (attributes)
1587 "Return a list of attributes, as a string.
1588 ATTRIBUTES is a plist where values are either strings or nil. An
1589 attributes with a nil value will be omitted from the result."
1590 (let (output)
1591 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1592 (cond ((null item) (pop output))
1593 ((symbolp item) (push (substring (symbol-name item) 1) output))
1594 (t (let ((key (car output))
1595 (value (replace-regexp-in-string
1596 "\"" "&quot;" (org-html-encode-plain-text item))))
1597 (setcar output (format "%s=\"%s\"" key value))))))))
1599 (defun org-html--wrap-image (contents info &optional caption label)
1600 "Wrap CONTENTS string within an appropriate environment for images.
1601 INFO is a plist used as a communication channel. When optional
1602 arguments CAPTION and LABEL are given, use them for caption and
1603 \"id\" attribute."
1604 (let ((html5-fancy (org-html--html5-fancy-p info)))
1605 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1606 "\n<div%s class=\"figure\">%s%s\n</div>")
1607 ;; ID.
1608 (if (org-string-nw-p label) (format " id=\"%s\"" label) "")
1609 ;; Contents.
1610 (format "\n<p>%s</p>" contents)
1611 ;; Caption.
1612 (if (not (org-string-nw-p caption)) ""
1613 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1614 "\n<p>%s</p>")
1615 caption)))))
1617 (defun org-html--format-image (source attributes info)
1618 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1619 SOURCE is a string specifying the location of the image.
1620 ATTRIBUTES is a plist, as returned by
1621 `org-export-read-attribute'. INFO is a plist used as
1622 a communication channel."
1623 (if (string= "svg" (file-name-extension source))
1624 (org-html--svg-image source attributes info)
1625 (org-html-close-tag
1626 "img"
1627 (org-html--make-attribute-string
1628 (org-combine-plists
1629 (list :src source
1630 :alt (if (string-match-p "^ltxpng/" source)
1631 (org-html-encode-plain-text
1632 (org-find-text-property-in-string 'org-latex-src source))
1633 (file-name-nondirectory source)))
1634 attributes))
1635 info)))
1637 (defun org-html--svg-image (source attributes info)
1638 "Return \"object\" appropriate for embedding svg file SOURCE
1639 with assoicated ATTRIBUTES. INFO is a plist used as a
1640 communication channel.
1642 The special attribute \"fallback\" can be used to specify a fallback
1643 image file to use if the object embedding is not supported."
1644 (let ((fallback (plist-get attributes :fallback))
1645 (attrs (org-html--make-attribute-string
1646 (plist-put attributes :fallback nil))))
1647 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1648 source 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 (org-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 (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 (incf count)) " " title)
2334 (format "<a href=\"#%s\">%s %s</a>"
2335 label
2336 (format initial-fmt (incf count))
2337 title))
2338 "</li>")))
2339 lol-entries "\n"))
2340 "\n</ul>\n</div>\n</div>"))))
2342 (defun org-html-list-of-tables (info)
2343 "Build a list of tables.
2344 INFO is a plist used as a communication channel. Return the list
2345 of tables as a string, or nil if it is empty."
2346 (let ((lol-entries (org-export-collect-tables info)))
2347 (when lol-entries
2348 (concat "<div id=\"list-of-tables\">\n"
2349 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2350 (format "<h%d>%s</h%d>\n"
2351 top-level
2352 (org-html--translate "List of Tables" info)
2353 top-level))
2354 "<div id=\"text-list-of-tables\">\n<ul>\n"
2355 (let ((count 0)
2356 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2357 (org-html--translate "Table %d:" info))))
2358 (mapconcat
2359 (lambda (entry)
2360 (let ((label (and (org-element-property :name entry)
2361 (org-export-get-reference entry info)))
2362 (title (org-trim
2363 (org-export-data
2364 (or (org-export-get-caption entry t)
2365 (org-export-get-caption entry))
2366 info))))
2367 (concat
2368 "<li>"
2369 (if (not label)
2370 (concat (format initial-fmt (incf count)) " " title)
2371 (format "<a href=\"#%s\">%s %s</a>"
2372 label
2373 (format initial-fmt (incf count))
2374 title))
2375 "</li>")))
2376 lol-entries "\n"))
2377 "\n</ul>\n</div>\n</div>"))))
2380 ;;; Transcode Functions
2382 ;;;; Bold
2384 (defun org-html-bold (_bold contents info)
2385 "Transcode BOLD from Org to HTML.
2386 CONTENTS is the text with bold markup. INFO is a plist holding
2387 contextual information."
2388 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2389 contents))
2391 ;;;; Center Block
2393 (defun org-html-center-block (_center-block contents _info)
2394 "Transcode a CENTER-BLOCK element from Org to HTML.
2395 CONTENTS holds the contents of the block. INFO is a plist
2396 holding contextual information."
2397 (format "<div class=\"org-center\">\n%s</div>" contents))
2399 ;;;; Clock
2401 (defun org-html-clock (clock _contents _info)
2402 "Transcode a CLOCK element from Org to HTML.
2403 CONTENTS is nil. INFO is a plist used as a communication
2404 channel."
2405 (format "<p>
2406 <span class=\"timestamp-wrapper\">
2407 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2408 </span>
2409 </p>"
2410 org-clock-string
2411 (org-timestamp-translate (org-element-property :value clock))
2412 (let ((time (org-element-property :duration clock)))
2413 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2415 ;;;; Code
2417 (defun org-html-code (code _contents info)
2418 "Transcode CODE from Org to HTML.
2419 CONTENTS is nil. INFO is a plist holding contextual
2420 information."
2421 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2422 (org-html-encode-plain-text (org-element-property :value code))))
2424 ;;;; Drawer
2426 (defun org-html-drawer (drawer contents info)
2427 "Transcode a DRAWER element from Org to HTML.
2428 CONTENTS holds the contents of the block. INFO is a plist
2429 holding contextual information."
2430 (funcall (plist-get info :html-format-drawer-function)
2431 (org-element-property :drawer-name drawer)
2432 contents))
2434 ;;;; Dynamic Block
2436 (defun org-html-dynamic-block (_dynamic-block contents _info)
2437 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2438 CONTENTS holds the contents of the block. INFO is a plist
2439 holding contextual information. See `org-export-data'."
2440 contents)
2442 ;;;; Entity
2444 (defun org-html-entity (entity _contents _info)
2445 "Transcode an ENTITY object from Org to HTML.
2446 CONTENTS are the definition itself. INFO is a plist holding
2447 contextual information."
2448 (org-element-property :html entity))
2450 ;;;; Example Block
2452 (defun org-html-example-block (example-block _contents info)
2453 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2454 CONTENTS is nil. INFO is a plist holding contextual
2455 information."
2456 (let ((attributes (org-export-read-attribute :attr_html example-block)))
2457 (if (plist-get attributes :textarea)
2458 (org-html--textarea-block example-block)
2459 (format "<pre class=\"example\"%s>\n%s</pre>"
2460 (let* ((name (org-element-property :name example-block))
2461 (a (org-html--make-attribute-string
2462 (if (or (not name) (plist-member attributes :id))
2463 attributes
2464 (plist-put attributes :id name)))))
2465 (if (org-string-nw-p a) (concat " " a) ""))
2466 (org-html-format-code example-block info)))))
2468 ;;;; Export Snippet
2470 (defun org-html-export-snippet (export-snippet _contents _info)
2471 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2472 CONTENTS is nil. INFO is a plist holding contextual
2473 information."
2474 (when (eq (org-export-snippet-backend export-snippet) 'html)
2475 (org-element-property :value export-snippet)))
2477 ;;;; Export Block
2479 (defun org-html-export-block (export-block _contents _info)
2480 "Transcode a EXPORT-BLOCK element from Org to HTML.
2481 CONTENTS is nil. INFO is a plist holding contextual information."
2482 (when (string= (org-element-property :type export-block) "HTML")
2483 (org-remove-indentation (org-element-property :value export-block))))
2485 ;;;; Fixed Width
2487 (defun org-html-fixed-width (fixed-width _contents _info)
2488 "Transcode a FIXED-WIDTH element from Org to HTML.
2489 CONTENTS is nil. INFO is a plist holding contextual information."
2490 (format "<pre class=\"example\">\n%s</pre>"
2491 (org-html-do-format-code
2492 (org-remove-indentation
2493 (org-element-property :value fixed-width)))))
2495 ;;;; Footnote Reference
2497 (defun org-html-footnote-reference (footnote-reference _contents info)
2498 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2499 CONTENTS is nil. INFO is a plist holding contextual information."
2500 (concat
2501 ;; Insert separator between two footnotes in a row.
2502 (let ((prev (org-export-get-previous-element footnote-reference info)))
2503 (when (eq (org-element-type prev) 'footnote-reference)
2504 (plist-get info :html-footnote-separator)))
2505 (let* ((n (org-export-get-footnote-number footnote-reference info))
2506 (id (format "fnr.%d%s"
2508 (if (org-export-footnote-first-reference-p
2509 footnote-reference info)
2511 ".100"))))
2512 (format
2513 (plist-get info :html-footnote-format)
2514 (org-html--anchor
2515 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2517 ;;;; Headline
2519 (defun org-html-headline (headline contents info)
2520 "Transcode a HEADLINE element from Org to HTML.
2521 CONTENTS holds the contents of the headline. INFO is a plist
2522 holding contextual information."
2523 (unless (org-element-property :footnote-section-p headline)
2524 (let* ((numberedp (org-export-numbered-headline-p headline info))
2525 (numbers (org-export-get-headline-number headline info))
2526 (level (+ (org-export-get-relative-level headline info)
2527 (1- (plist-get info :html-toplevel-hlevel))))
2528 (todo (and (plist-get info :with-todo-keywords)
2529 (let ((todo (org-element-property :todo-keyword headline)))
2530 (and todo (org-export-data todo info)))))
2531 (todo-type (and todo (org-element-property :todo-type headline)))
2532 (priority (and (plist-get info :with-priority)
2533 (org-element-property :priority headline)))
2534 (text (org-export-data (org-element-property :title headline) info))
2535 (tags (and (plist-get info :with-tags)
2536 (org-export-get-tags headline info)))
2537 (full-text (funcall (plist-get info :html-format-headline-function)
2538 todo todo-type priority text tags info))
2539 (contents (or contents ""))
2540 (ids (delq nil
2541 (list (org-element-property :CUSTOM_ID headline)
2542 (org-export-get-reference headline info)
2543 (org-element-property :ID headline))))
2544 (preferred-id (car ids))
2545 (extra-ids
2546 (mapconcat
2547 (lambda (id)
2548 (org-html--anchor
2549 (if (org-uuidgen-p id) (concat "ID-" id) id)
2550 nil nil info))
2551 (cdr ids) "")))
2552 (if (org-export-low-level-p headline info)
2553 ;; This is a deep sub-tree: export it as a list item.
2554 (let* ((type (if numberedp 'ordered 'unordered))
2555 (itemized-body
2556 (org-html-format-list-item
2557 contents type nil info nil
2558 (concat (org-html--anchor preferred-id nil nil info)
2559 extra-ids
2560 full-text))))
2561 (concat (and (org-export-first-sibling-p headline info)
2562 (org-html-begin-plain-list type))
2563 itemized-body
2564 (and (org-export-last-sibling-p headline info)
2565 (org-html-end-plain-list type))))
2566 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2567 (first-content (car (org-element-contents headline))))
2568 ;; Standard headline. Export it as a section.
2569 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2570 (org-html--container headline info)
2571 (concat "outline-container-"
2572 (org-export-get-reference headline info))
2573 (concat (format "outline-%d" level)
2574 (and extra-class " ")
2575 extra-class)
2576 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2577 level
2578 preferred-id
2579 extra-ids
2580 (concat
2581 (and numberedp
2582 (format
2583 "<span class=\"section-number-%d\">%s</span> "
2584 level
2585 (mapconcat #'number-to-string numbers ".")))
2586 full-text)
2587 level)
2588 ;; When there is no section, pretend there is an
2589 ;; empty one to get the correct <div
2590 ;; class="outline-...> which is needed by
2591 ;; `org-info.js'.
2592 (if (eq (org-element-type first-content) 'section) contents
2593 (concat (org-html-section first-content "" info) contents))
2594 (org-html--container headline info)))))))
2596 (defun org-html-format-headline-default-function
2597 (todo _todo-type priority text tags info)
2598 "Default format function for a headline.
2599 See `org-html-format-headline-function' for details."
2600 (let ((todo (org-html--todo todo info))
2601 (priority (org-html--priority priority info))
2602 (tags (org-html--tags tags info)))
2603 (concat todo (and todo " ")
2604 priority (and priority " ")
2605 text
2606 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2608 (defun org-html--container (headline info)
2609 (or (org-element-property :HTML_CONTAINER headline)
2610 (if (= 1 (org-export-get-relative-level headline info))
2611 (plist-get info :html-container)
2612 "div")))
2614 ;;;; Horizontal Rule
2616 (defun org-html-horizontal-rule (_horizontal-rule _contents info)
2617 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2618 CONTENTS is nil. INFO is a plist holding contextual information."
2619 (org-html-close-tag "hr" nil info))
2621 ;;;; Inline Src Block
2623 (defun org-html-inline-src-block (inline-src-block _contents info)
2624 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2625 CONTENTS holds the contents of the item. INFO is a plist holding
2626 contextual information."
2627 (let ((lang (org-element-property :language inline-src-block))
2628 (code (org-html-format-code inline-src-block info))
2629 (label
2630 (let ((lbl (and (org-element-property :name inline-src-block)
2631 (org-export-get-reference inline-src-block info))))
2632 (if (not lbl) "" (format " id=\"%s\"" lbl)))))
2633 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code)))
2635 ;;;; Inlinetask
2637 (defun org-html-inlinetask (inlinetask contents info)
2638 "Transcode an INLINETASK element from Org to HTML.
2639 CONTENTS holds the contents of the block. INFO is a plist
2640 holding contextual information."
2641 (let* ((todo (and (plist-get info :with-todo-keywords)
2642 (let ((todo (org-element-property :todo-keyword inlinetask)))
2643 (and todo (org-export-data todo info)))))
2644 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2645 (priority (and (plist-get info :with-priority)
2646 (org-element-property :priority inlinetask)))
2647 (text (org-export-data (org-element-property :title inlinetask) info))
2648 (tags (and (plist-get info :with-tags)
2649 (org-export-get-tags inlinetask info))))
2650 (funcall (plist-get info :html-format-inlinetask-function)
2651 todo todo-type priority text tags contents info)))
2653 (defun org-html-format-inlinetask-default-function
2654 (todo todo-type priority text tags contents info)
2655 "Default format function for a inlinetasks.
2656 See `org-html-format-inlinetask-function' for details."
2657 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2658 (org-html-format-headline-default-function
2659 todo todo-type priority text tags info)
2660 (org-html-close-tag "br" nil info)
2661 contents))
2663 ;;;; Italic
2665 (defun org-html-italic (_italic contents info)
2666 "Transcode ITALIC from Org to HTML.
2667 CONTENTS is the text with italic markup. INFO is a plist holding
2668 contextual information."
2669 (format
2670 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2671 contents))
2673 ;;;; Item
2675 (defun org-html-checkbox (checkbox info)
2676 "Format CHECKBOX into HTML.
2677 INFO is a plist holding contextual information. See
2678 `org-html-checkbox-type' for customization options."
2679 (cdr (assq checkbox
2680 (cdr (assq (plist-get info :html-checkbox-type)
2681 org-html-checkbox-types)))))
2683 (defun org-html-format-list-item (contents type checkbox info
2684 &optional term-counter-id
2685 headline)
2686 "Format a list item into HTML."
2687 (let ((class (if checkbox
2688 (format " class=\"%s\""
2689 (symbol-name checkbox)) ""))
2690 (checkbox (concat (org-html-checkbox checkbox info)
2691 (and checkbox " ")))
2692 (br (org-html-close-tag "br" nil info)))
2693 (concat
2694 (case type
2695 (ordered
2696 (let* ((counter term-counter-id)
2697 (extra (if counter (format " value=\"%s\"" counter) "")))
2698 (concat
2699 (format "<li%s%s>" class extra)
2700 (when headline (concat headline br)))))
2701 (unordered
2702 (let* ((id term-counter-id)
2703 (extra (if id (format " id=\"%s\"" id) "")))
2704 (concat
2705 (format "<li%s%s>" class extra)
2706 (when headline (concat headline br)))))
2707 (descriptive
2708 (let* ((term term-counter-id))
2709 (setq term (or term "(no term)"))
2710 ;; Check-boxes in descriptive lists are associated to tag.
2711 (concat (format "<dt%s>%s</dt>"
2712 class (concat checkbox term))
2713 "<dd>"))))
2714 (unless (eq type 'descriptive) checkbox)
2715 (and contents (org-trim contents))
2716 (case type
2717 (ordered "</li>")
2718 (unordered "</li>")
2719 (descriptive "</dd>")))))
2721 (defun org-html-item (item contents info)
2722 "Transcode an ITEM element from Org to HTML.
2723 CONTENTS holds the contents of the item. INFO is a plist holding
2724 contextual information."
2725 (let* ((plain-list (org-export-get-parent item))
2726 (type (org-element-property :type plain-list))
2727 (counter (org-element-property :counter item))
2728 (checkbox (org-element-property :checkbox item))
2729 (tag (let ((tag (org-element-property :tag item)))
2730 (and tag (org-export-data tag info)))))
2731 (org-html-format-list-item
2732 contents type checkbox info (or tag counter))))
2734 ;;;; Keyword
2736 (defun org-html-keyword (keyword _contents info)
2737 "Transcode a KEYWORD element from Org to HTML.
2738 CONTENTS is nil. INFO is a plist holding contextual information."
2739 (let ((key (org-element-property :key keyword))
2740 (value (org-element-property :value keyword)))
2741 (cond
2742 ((string= key "HTML") value)
2743 ((string= key "TOC")
2744 (let ((case-fold-search t))
2745 (cond
2746 ((string-match "\\<headlines\\>" value)
2747 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2748 (string-to-number (match-string 0 value))))
2749 (localp (org-string-match-p "\\<local\\>" value)))
2750 (org-html-toc depth info (and localp keyword))))
2751 ((string= "listings" value) (org-html-list-of-listings info))
2752 ((string= "tables" value) (org-html-list-of-tables info))))))))
2754 ;;;; Latex Environment
2756 (defun org-html-format-latex (latex-frag processing-type info)
2757 "Format a LaTeX fragment LATEX-FRAG into HTML.
2758 PROCESSING-TYPE designates the tool used for conversion. It can
2759 be `mathjax', `verbatim', nil, t or symbols in
2760 `org-preview-latex-process-alist', e.g., `dvipng', `dvisvgm' or
2761 `imagemagick'. See `org-html-with-latex' for more information.
2762 INFO is a plist containing export properties."
2763 (let ((cache-relpath "") (cache-dir ""))
2764 (unless (eq processing-type 'mathjax)
2765 (let ((bfn (or (buffer-file-name)
2766 (make-temp-name
2767 (expand-file-name "latex" temporary-file-directory))))
2768 (latex-header
2769 (let ((header (plist-get info :latex-header)))
2770 (and header
2771 (concat (mapconcat
2772 (lambda (line) (concat "#+LATEX_HEADER: " line))
2773 (org-split-string header "\n")
2774 "\n")
2775 "\n")))))
2776 (setq cache-relpath
2777 (concat (file-name-as-directory org-preview-latex-image-directory)
2778 (file-name-sans-extension
2779 (file-name-nondirectory bfn)))
2780 cache-dir (file-name-directory bfn))
2781 ;; Re-create LaTeX environment from original buffer in
2782 ;; temporary buffer so that dvipng/imagemagick can properly
2783 ;; turn the fragment into an image.
2784 (setq latex-frag (concat latex-header latex-frag))))
2785 (with-temp-buffer
2786 (insert latex-frag)
2787 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2788 nil processing-type)
2789 (buffer-string))))
2791 (defun org-html-latex-environment (latex-environment _contents info)
2792 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2793 CONTENTS is nil. INFO is a plist holding contextual information."
2794 (let ((processing-type (plist-get info :with-latex))
2795 (latex-frag (org-remove-indentation
2796 (org-element-property :value latex-environment)))
2797 (attributes (org-export-read-attribute :attr_html latex-environment)))
2798 (cond
2799 ((memq processing-type '(t mathjax))
2800 (org-html-format-latex latex-frag 'mathjax info))
2801 ((assq processing-type org-preview-latex-process-alist)
2802 (let ((formula-link
2803 (org-html-format-latex latex-frag processing-type info)))
2804 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2805 ;; Do not provide a caption or a name to be consistent with
2806 ;; `mathjax' handling.
2807 (org-html--wrap-image
2808 (org-html--format-image
2809 (match-string 1 formula-link) attributes info) info))))
2810 (t latex-frag))))
2812 ;;;; Latex Fragment
2814 (defun org-html-latex-fragment (latex-fragment _contents info)
2815 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2816 CONTENTS is nil. INFO is a plist holding contextual information."
2817 (let ((latex-frag (org-element-property :value latex-fragment))
2818 (processing-type (plist-get info :with-latex)))
2819 (cond
2820 ((memq processing-type '(t mathjax))
2821 (org-html-format-latex latex-frag 'mathjax info))
2822 ((assq processing-type org-preview-latex-process-alist)
2823 (let ((formula-link
2824 (org-html-format-latex latex-frag processing-type info)))
2825 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2826 (org-html--format-image (match-string 1 formula-link) nil info))))
2827 (t latex-frag))))
2829 ;;;; Line Break
2831 (defun org-html-line-break (_line-break _contents info)
2832 "Transcode a LINE-BREAK object from Org to HTML.
2833 CONTENTS is nil. INFO is a plist holding contextual information."
2834 (concat (org-html-close-tag "br" nil info) "\n"))
2836 ;;;; Link
2838 (defun org-html-inline-image-p (link info)
2839 "Non-nil when LINK is meant to appear as an image.
2840 INFO is a plist used as a communication channel. LINK is an
2841 inline image when it has no description and targets an image
2842 file (see `org-html-inline-image-rules' for more information), or
2843 if its description is a single link targeting an image file."
2844 (if (not (org-element-contents link))
2845 (org-export-inline-image-p
2846 link (plist-get info :html-inline-image-rules))
2847 (not
2848 (let ((link-count 0))
2849 (org-element-map (org-element-contents link)
2850 (cons 'plain-text org-element-all-objects)
2851 (lambda (obj)
2852 (case (org-element-type obj)
2853 (plain-text (org-string-nw-p obj))
2854 (link (if (= link-count 1) t
2855 (incf link-count)
2856 (not (org-export-inline-image-p
2857 obj (plist-get info :html-inline-image-rules)))))
2858 (otherwise t)))
2859 info t)))))
2861 (defvar org-html-standalone-image-predicate)
2862 (defun org-html-standalone-image-p (element info)
2863 "Non-nil if ELEMENT is a standalone image.
2865 INFO is a plist holding contextual information.
2867 An element or object is a standalone image when
2869 - its type is `paragraph' and its sole content, save for white
2870 spaces, is a link that qualifies as an inline image;
2872 - its type is `link' and its containing paragraph has no other
2873 content save white spaces.
2875 Bind `org-html-standalone-image-predicate' to constrain paragraph
2876 further. For example, to check for only captioned standalone
2877 images, set it to:
2879 (lambda (paragraph) (org-element-property :caption paragraph))"
2880 (let ((paragraph (case (org-element-type element)
2881 (paragraph element)
2882 (link (org-export-get-parent element)))))
2883 (and (eq (org-element-type paragraph) 'paragraph)
2884 (or (not (fboundp 'org-html-standalone-image-predicate))
2885 (funcall org-html-standalone-image-predicate paragraph))
2886 (catch 'exit
2887 (let ((link-count 0))
2888 (org-element-map (org-element-contents paragraph)
2889 (cons 'plain-text org-element-all-objects)
2890 #'(lambda (obj)
2891 (when (case (org-element-type obj)
2892 (plain-text (org-string-nw-p obj))
2893 (link (or (> (incf link-count) 1)
2894 (not (org-html-inline-image-p obj info))))
2895 (otherwise t))
2896 (throw 'exit nil)))
2897 info nil 'link)
2898 (= link-count 1))))))
2900 (defun org-html-link (link desc info)
2901 "Transcode a LINK object from Org to HTML.
2902 DESC is the description part of the link, or the empty string.
2903 INFO is a plist holding contextual information. See
2904 `org-export-data'."
2905 (let* ((home (when (plist-get info :html-link-home)
2906 (org-trim (plist-get info :html-link-home))))
2907 (use-abs-url (plist-get info :html-link-use-abs-url))
2908 (link-org-files-as-html-maybe
2909 (lambda (raw-path info)
2910 ;; Treat links to `file.org' as links to `file.html', if
2911 ;; needed. See `org-html-link-org-files-as-html'.
2912 (cond
2913 ((and (plist-get info :html-link-org-files-as-html)
2914 (string= ".org"
2915 (downcase (file-name-extension raw-path "."))))
2916 (concat (file-name-sans-extension raw-path) "."
2917 (plist-get info :html-extension)))
2918 (t raw-path))))
2919 (type (org-element-property :type link))
2920 (raw-path (org-element-property :path link))
2921 ;; Ensure DESC really exists, or set it to nil.
2922 (desc (org-string-nw-p desc))
2923 (path
2924 (cond
2925 ((member type '("http" "https" "ftp" "mailto" "news"))
2926 (org-link-escape-browser
2927 (org-link-unescape (concat type ":" raw-path))))
2928 ((string= type "file")
2929 ;; Treat links to ".org" files as ".html", if needed.
2930 (setq raw-path
2931 (funcall link-org-files-as-html-maybe raw-path info))
2932 ;; If file path is absolute, prepend it with protocol
2933 ;; component - "file://".
2934 (cond
2935 ((file-name-absolute-p raw-path)
2936 (setq raw-path (org-export-file-uri raw-path)))
2937 ((and home use-abs-url)
2938 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2939 ;; Add search option, if any. A search option can be
2940 ;; relative to a custom-id, a headline title, a name or
2941 ;; a target.
2942 (let ((option (org-element-property :search-option link)))
2943 (cond ((not option) raw-path)
2944 ;; Since HTML back-end use custom-id value as-is,
2945 ;; resolving is them is trivial.
2946 ((eq (string-to-char option) ?#) (concat raw-path option))
2948 (concat raw-path
2950 (org-publish-resolve-external-link
2951 option
2952 (org-element-property :path link)))))))
2953 (t raw-path)))
2954 ;; Extract attributes from parent's paragraph. HACK: Only do
2955 ;; this for the first link in parent (inner image link for
2956 ;; inline images). This is needed as long as attributes
2957 ;; cannot be set on a per link basis.
2958 (attributes-plist
2959 (let* ((parent (org-export-get-parent-element link))
2960 (link (let ((container (org-export-get-parent link)))
2961 (if (and (eq (org-element-type container) 'link)
2962 (org-html-inline-image-p link info))
2963 container
2964 link))))
2965 (and (eq (org-element-map parent 'link 'identity info t) link)
2966 (org-export-read-attribute :attr_html parent))))
2967 (attributes
2968 (let ((attr (org-html--make-attribute-string attributes-plist)))
2969 (if (org-string-nw-p attr) (concat " " attr) ""))))
2970 (cond
2971 ;; Link type is handled by a special function.
2972 ((org-export-custom-protocol-maybe link desc 'html))
2973 ;; Image file.
2974 ((and (plist-get info :html-inline-images)
2975 (org-export-inline-image-p
2976 link (plist-get info :html-inline-image-rules)))
2977 (org-html--format-image path attributes-plist info))
2978 ;; Radio target: Transcode target's contents and use them as
2979 ;; link's description.
2980 ((string= type "radio")
2981 (let ((destination (org-export-resolve-radio-link link info)))
2982 (if (not destination) desc
2983 (format "<a href=\"#%s\"%s>%s</a>"
2984 (org-export-get-reference destination info)
2985 attributes
2986 desc))))
2987 ;; Links pointing to a headline: Find destination and build
2988 ;; appropriate referencing command.
2989 ((member type '("custom-id" "fuzzy" "id"))
2990 (let ((destination (if (string= type "fuzzy")
2991 (org-export-resolve-fuzzy-link link info)
2992 (org-export-resolve-id-link link info))))
2993 (case (org-element-type destination)
2994 ;; ID link points to an external file.
2995 (plain-text
2996 (let ((fragment (concat "ID-" path))
2997 ;; Treat links to ".org" files as ".html", if needed.
2998 (path (funcall link-org-files-as-html-maybe
2999 destination info)))
3000 (format "<a href=\"%s#%s\"%s>%s</a>"
3001 path fragment attributes (or desc destination))))
3002 ;; Fuzzy link points nowhere.
3003 ((nil)
3004 (format "<i>%s</i>"
3005 (or desc
3006 (org-export-data
3007 (org-element-property :raw-link link) info))))
3008 ;; Link points to a headline.
3009 (headline
3010 (let ((href (or (org-element-property :CUSTOM_ID destination)
3011 (org-export-get-reference destination info)))
3012 ;; What description to use?
3013 (desc
3014 ;; Case 1: Headline is numbered and LINK has no
3015 ;; description. Display section number.
3016 (if (and (org-export-numbered-headline-p destination info)
3017 (not desc))
3018 (mapconcat #'number-to-string
3019 (org-export-get-headline-number
3020 destination info) ".")
3021 ;; Case 2: Either the headline is un-numbered or
3022 ;; LINK has a custom description. Display LINK's
3023 ;; description or headline's title.
3024 (or desc
3025 (org-export-data
3026 (org-element-property :title destination) info)))))
3027 (format "<a href=\"#%s\"%s>%s</a>" href attributes desc)))
3028 ;; Fuzzy link points to a target or an element.
3030 (let* ((ref (org-export-get-reference destination info))
3031 (org-html-standalone-image-predicate
3032 #'org-html--has-caption-p)
3033 (number (cond
3034 (desc nil)
3035 ((org-html-standalone-image-p destination info)
3036 (org-export-get-ordinal
3037 (org-element-map destination 'link
3038 #'identity info t)
3039 info 'link 'org-html-standalone-image-p))
3040 (t (org-export-get-ordinal
3041 destination info nil 'org-html--has-caption-p))))
3042 (desc (cond (desc)
3043 ((not number) "No description for this link")
3044 ((numberp number) (number-to-string number))
3045 (t (mapconcat #'number-to-string number ".")))))
3046 (format "<a href=\"#%s\"%s>%s</a>" ref attributes desc))))))
3047 ;; Coderef: replace link with the reference name or the
3048 ;; equivalent line number.
3049 ((string= type "coderef")
3050 (let ((fragment (concat "coderef-" (org-html-encode-plain-text path))))
3051 (format "<a href=\"#%s\"%s%s>%s</a>"
3052 fragment
3053 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, \
3054 '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
3055 fragment fragment)
3056 attributes
3057 (format (org-export-get-coderef-format path desc)
3058 (org-export-resolve-coderef path info)))))
3059 ;; External link with a description part.
3060 ((and path desc) (format "<a href=\"%s\"%s>%s</a>"
3061 (org-html-encode-plain-text path)
3062 attributes
3063 desc))
3064 ;; External link without a description part.
3065 (path (let ((path (org-html-encode-plain-text path)))
3066 (format "<a href=\"%s\"%s>%s</a>" path attributes path)))
3067 ;; No path, only description. Try to do something useful.
3068 (t (format "<i>%s</i>" desc)))))
3070 ;;;; Node Property
3072 (defun org-html-node-property (node-property _contents _info)
3073 "Transcode a NODE-PROPERTY element from Org to HTML.
3074 CONTENTS is nil. INFO is a plist holding contextual
3075 information."
3076 (format "%s:%s"
3077 (org-element-property :key node-property)
3078 (let ((value (org-element-property :value node-property)))
3079 (if value (concat " " value) ""))))
3081 ;;;; Paragraph
3083 (defun org-html-paragraph (paragraph contents info)
3084 "Transcode a PARAGRAPH element from Org to HTML.
3085 CONTENTS is the contents of the paragraph, as a string. INFO is
3086 the plist used as a communication channel."
3087 (let* ((parent (org-export-get-parent paragraph))
3088 (parent-type (org-element-type parent))
3089 (style '((footnote-definition " class=\"footpara\"")
3090 (org-data " class=\"footpara\"")))
3091 (attributes (org-html--make-attribute-string
3092 (org-export-read-attribute :attr_html paragraph)))
3093 (extra (or (cadr (assq parent-type style)) "")))
3094 (cond
3095 ((and (eq parent-type 'item)
3096 (not (org-export-get-previous-element paragraph info))
3097 (let ((followers (org-export-get-next-element paragraph info 2)))
3098 (and (not (cdr followers))
3099 (memq (org-element-type (car followers)) '(nil plain-list)))))
3100 ;; First paragraph in an item has no tag if it is alone or
3101 ;; followed, at most, by a sub-list.
3102 contents)
3103 ((org-html-standalone-image-p paragraph info)
3104 ;; Standalone image.
3105 (let ((caption
3106 (let ((raw (org-export-data
3107 (org-export-get-caption paragraph) info))
3108 (org-html-standalone-image-predicate
3109 'org-html--has-caption-p))
3110 (if (not (org-string-nw-p raw)) raw
3111 (concat
3112 "<span class=\"figure-number\">"
3113 (format (org-html--translate "Figure %d:" info)
3114 (org-export-get-ordinal
3115 (org-element-map paragraph 'link
3116 'identity info t)
3117 info nil 'org-html-standalone-image-p))
3118 "</span> " raw))))
3119 (label (and (org-element-property :name paragraph)
3120 (org-export-get-reference paragraph info))))
3121 (org-html--wrap-image contents info caption label)))
3122 ;; Regular paragraph.
3123 (t (format "<p%s%s>\n%s</p>"
3124 (if (org-string-nw-p attributes)
3125 (concat " " attributes) "")
3126 extra contents)))))
3128 ;;;; Plain List
3130 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
3131 ;; the correct value for the item counter
3132 (defun org-html-begin-plain-list (type &optional arg1)
3133 "Insert the beginning of the HTML list depending on TYPE.
3134 When ARG1 is a string, use it as the start parameter for ordered
3135 lists."
3136 (case type
3137 (ordered
3138 (format "<ol class=\"org-ol\"%s>"
3139 (if arg1 (format " start=\"%d\"" arg1) "")))
3140 (unordered "<ul class=\"org-ul\">")
3141 (descriptive "<dl class=\"org-dl\">")))
3143 (defun org-html-end-plain-list (type)
3144 "Insert the end of the HTML list depending on TYPE."
3145 (case type
3146 (ordered "</ol>")
3147 (unordered "</ul>")
3148 (descriptive "</dl>")))
3150 (defun org-html-plain-list (plain-list contents _info)
3151 "Transcode a PLAIN-LIST element from Org to HTML.
3152 CONTENTS is the contents of the list. INFO is a plist holding
3153 contextual information."
3154 (let ((type (org-element-property :type plain-list)))
3155 (format "%s\n%s%s"
3156 (org-html-begin-plain-list type)
3157 contents (org-html-end-plain-list type))))
3159 ;;;; Plain Text
3161 (defun org-html-convert-special-strings (string)
3162 "Convert special characters in STRING to HTML."
3163 (dolist (a org-html-special-string-regexps string)
3164 (let ((re (car a))
3165 (rpl (cdr a)))
3166 (setq string (replace-regexp-in-string re rpl string t)))))
3168 (defun org-html-encode-plain-text (text)
3169 "Convert plain text characters from TEXT to HTML equivalent.
3170 Possible conversions are set in `org-html-protect-char-alist'."
3171 (dolist (pair org-html-protect-char-alist text)
3172 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3174 (defun org-html-plain-text (text info)
3175 "Transcode a TEXT string from Org to HTML.
3176 TEXT is the string to transcode. INFO is a plist holding
3177 contextual information."
3178 (let ((output text))
3179 ;; Protect following characters: <, >, &.
3180 (setq output (org-html-encode-plain-text output))
3181 ;; Handle smart quotes. Be sure to provide original string since
3182 ;; OUTPUT may have been modified.
3183 (when (plist-get info :with-smart-quotes)
3184 (setq output (org-export-activate-smart-quotes output :html info text)))
3185 ;; Handle special strings.
3186 (when (plist-get info :with-special-strings)
3187 (setq output (org-html-convert-special-strings output)))
3188 ;; Handle break preservation if required.
3189 (when (plist-get info :preserve-breaks)
3190 (setq output
3191 (replace-regexp-in-string
3192 "\\(\\\\\\\\\\)?[ \t]*\n"
3193 (concat (org-html-close-tag "br" nil info) "\n") output)))
3194 ;; Return value.
3195 output))
3198 ;; Planning
3200 (defun org-html-planning (planning _contents info)
3201 "Transcode a PLANNING element from Org to HTML.
3202 CONTENTS is nil. INFO is a plist used as a communication
3203 channel."
3204 (format
3205 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3206 (org-trim
3207 (mapconcat
3208 (lambda (pair)
3209 (let ((timestamp (cdr pair)))
3210 (when timestamp
3211 (let ((string (car pair)))
3212 (format "<span class=\"timestamp-kwd\">%s</span> \
3213 <span class=\"timestamp\">%s</span> "
3214 string
3215 (org-html-plain-text (org-timestamp-translate timestamp)
3216 info))))))
3217 `((,org-closed-string . ,(org-element-property :closed planning))
3218 (,org-deadline-string . ,(org-element-property :deadline planning))
3219 (,org-scheduled-string . ,(org-element-property :scheduled planning)))
3220 ""))))
3222 ;;;; Property Drawer
3224 (defun org-html-property-drawer (_property-drawer contents _info)
3225 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3226 CONTENTS holds the contents of the drawer. INFO is a plist
3227 holding contextual information."
3228 (and (org-string-nw-p contents)
3229 (format "<pre class=\"example\">\n%s</pre>" contents)))
3231 ;;;; Quote Block
3233 (defun org-html-quote-block (quote-block contents _info)
3234 "Transcode a QUOTE-BLOCK element from Org to HTML.
3235 CONTENTS holds the contents of the block. INFO is a plist
3236 holding contextual information."
3237 (format "<blockquote%s>\n%s</blockquote>"
3238 (let* ((name (org-element-property :name quote-block))
3239 (attributes (org-export-read-attribute :attr_html quote-block))
3240 (a (org-html--make-attribute-string
3241 (if (or (not name) (plist-member attributes :id))
3242 attributes
3243 (plist-put attributes :id name)))))
3244 (if (org-string-nw-p a) (concat " " a) ""))
3245 contents))
3247 ;;;; Section
3249 (defun org-html-section (section contents info)
3250 "Transcode a SECTION element from Org to HTML.
3251 CONTENTS holds the contents of the section. INFO is a plist
3252 holding contextual information."
3253 (let ((parent (org-export-get-parent-headline section)))
3254 ;; Before first headline: no container, just return CONTENTS.
3255 (if (not parent) contents
3256 ;; Get div's class and id references.
3257 (let* ((class-num (+ (org-export-get-relative-level parent info)
3258 (1- (plist-get info :html-toplevel-hlevel))))
3259 (section-number
3260 (and (org-export-numbered-headline-p parent info)
3261 (mapconcat
3262 #'number-to-string
3263 (org-export-get-headline-number parent info) "-"))))
3264 ;; Build return value.
3265 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3266 class-num
3267 (or (org-element-property :CUSTOM_ID parent)
3268 section-number
3269 (org-export-get-reference parent info))
3270 (or contents ""))))))
3272 ;;;; Radio Target
3274 (defun org-html-radio-target (radio-target text info)
3275 "Transcode a RADIO-TARGET object from Org to HTML.
3276 TEXT is the text of the target. INFO is a plist holding
3277 contextual information."
3278 (let ((ref (org-export-get-reference radio-target info)))
3279 (org-html--anchor ref text nil info)))
3281 ;;;; Special Block
3283 (defun org-html-special-block (special-block contents info)
3284 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3285 CONTENTS holds the contents of the block. INFO is a plist
3286 holding contextual information."
3287 (let* ((block-type (org-element-property :type special-block))
3288 (html5-fancy (and (org-html--html5-fancy-p info)
3289 (member block-type org-html-html5-elements)))
3290 (attributes (org-export-read-attribute :attr_html special-block)))
3291 (unless html5-fancy
3292 (let ((class (plist-get attributes :class)))
3293 (setq attributes (plist-put attributes :class
3294 (if class (concat class " " block-type)
3295 block-type)))))
3296 (let* ((contents (or contents ""))
3297 (name (org-element-property :name special-block))
3298 (a (org-html--make-attribute-string
3299 (if (or (not name) (plist-member attributes :id))
3300 attributes
3301 (plist-put attributes :id name))))
3302 (str (if (org-string-nw-p a) (concat " " a) "")))
3303 (if html5-fancy
3304 (format "<%s%s>\n%s</%s>" block-type str contents block-type)
3305 (format "<div%s>\n%s\n</div>" str contents)))))
3307 ;;;; Src Block
3309 (defun org-html-src-block (src-block _contents info)
3310 "Transcode a SRC-BLOCK element from Org to HTML.
3311 CONTENTS holds the contents of the item. INFO is a plist holding
3312 contextual information."
3313 (if (org-export-read-attribute :attr_html src-block :textarea)
3314 (org-html--textarea-block src-block)
3315 (let ((lang (org-element-property :language src-block))
3316 (caption (org-export-get-caption src-block))
3317 (code (org-html-format-code src-block info))
3318 (label (let ((lbl (and (org-element-property :name src-block)
3319 (org-export-get-reference src-block info))))
3320 (if lbl (format " id=\"%s\"" lbl) ""))))
3321 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3322 (format
3323 "<div class=\"org-src-container\">\n%s%s\n</div>"
3324 (if (not caption) ""
3325 (format "<label class=\"org-src-name\">%s</label>"
3326 (org-export-data caption info)))
3327 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3329 ;;;; Statistics Cookie
3331 (defun org-html-statistics-cookie (statistics-cookie _contents _info)
3332 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3333 CONTENTS is nil. INFO is a plist holding contextual information."
3334 (let ((cookie-value (org-element-property :value statistics-cookie)))
3335 (format "<code>%s</code>" cookie-value)))
3337 ;;;; Strike-Through
3339 (defun org-html-strike-through (_strike-through contents info)
3340 "Transcode STRIKE-THROUGH from Org to HTML.
3341 CONTENTS is the text with strike-through markup. INFO is a plist
3342 holding contextual information."
3343 (format
3344 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3345 "%s")
3346 contents))
3348 ;;;; Subscript
3350 (defun org-html-subscript (_subscript contents _info)
3351 "Transcode a SUBSCRIPT object from Org to HTML.
3352 CONTENTS is the contents of the object. INFO is a plist holding
3353 contextual information."
3354 (format "<sub>%s</sub>" contents))
3356 ;;;; Superscript
3358 (defun org-html-superscript (_superscript contents _info)
3359 "Transcode a SUPERSCRIPT object from Org to HTML.
3360 CONTENTS is the contents of the object. INFO is a plist holding
3361 contextual information."
3362 (format "<sup>%s</sup>" contents))
3364 ;;;; Table Cell
3366 (defun org-html-table-cell (table-cell contents info)
3367 "Transcode a TABLE-CELL element from Org to HTML.
3368 CONTENTS is nil. INFO is a plist used as a communication
3369 channel."
3370 (let* ((table-row (org-export-get-parent table-cell))
3371 (table (org-export-get-parent-table table-cell))
3372 (cell-attrs
3373 (if (not (plist-get info :html-table-align-individual-fields)) ""
3374 (format (if (and (boundp 'org-html-format-table-no-css)
3375 org-html-format-table-no-css)
3376 " align=\"%s\"" " class=\"org-%s\"")
3377 (org-export-table-cell-alignment table-cell info)))))
3378 (when (or (not contents) (string= "" (org-trim contents)))
3379 (setq contents "&#xa0;"))
3380 (cond
3381 ((and (org-export-table-has-header-p table info)
3382 (= 1 (org-export-table-row-group table-row info)))
3383 (let ((header-tags (plist-get info :html-table-header-tags)))
3384 (concat "\n" (format (car header-tags) "col" cell-attrs)
3385 contents
3386 (cdr header-tags))))
3387 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3388 (zerop (cdr (org-export-table-cell-address table-cell info))))
3389 (let ((header-tags (plist-get info :html-table-header-tags)))
3390 (concat "\n" (format (car header-tags) "row" cell-attrs)
3391 contents
3392 (cdr header-tags))))
3393 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3394 (concat "\n" (format (car data-tags) cell-attrs)
3395 contents
3396 (cdr data-tags)))))))
3398 ;;;; Table Row
3400 (defun org-html-table-row (table-row contents info)
3401 "Transcode a TABLE-ROW element from Org to HTML.
3402 CONTENTS is the contents of the row. INFO is a plist used as a
3403 communication channel."
3404 ;; Rules are ignored since table separators are deduced from
3405 ;; borders of the current row.
3406 (when (eq (org-element-property :type table-row) 'standard)
3407 (let* ((group (org-export-table-row-group table-row info))
3408 (number (org-export-table-row-number table-row info))
3409 (start-group-p
3410 (org-export-table-row-starts-rowgroup-p table-row info))
3411 (end-group-p
3412 (org-export-table-row-ends-rowgroup-p table-row info))
3413 (topp (and (equal start-group-p '(top))
3414 (equal end-group-p '(below top))))
3415 (bottomp (and (equal start-group-p '(above))
3416 (equal end-group-p '(bottom above))))
3417 (row-open-tag
3418 (pcase (plist-get info :html-table-row-open-tag)
3419 ((and accessor (pred functionp))
3420 (funcall accessor
3421 number group start-group-p end-group-p topp bottomp))
3422 (accessor accessor)))
3423 (row-close-tag
3424 (pcase (plist-get info :html-table-row-close-tag)
3425 ((and accessor (pred functionp))
3426 (funcall accessor
3427 number group start-group-p end-group-p topp bottomp))
3428 (accessor accessor)))
3429 (group-tags
3430 (cond
3431 ;; Row belongs to second or subsequent groups.
3432 ((not (= 1 group)) '("<tbody>" . "\n</tbody>"))
3433 ;; Row is from first group. Table has >=1 groups.
3434 ((org-export-table-has-header-p
3435 (org-export-get-parent-table table-row) info)
3436 '("<thead>" . "\n</thead>"))
3437 ;; Row is from first and only group.
3438 (t '("<tbody>" . "\n</tbody>")))))
3439 (concat (and start-group-p (car group-tags))
3440 (concat "\n"
3441 row-open-tag
3442 contents
3443 "\n"
3444 row-close-tag)
3445 (and end-group-p (cdr group-tags))))))
3447 ;;;; Table
3449 (defun org-html-table-first-row-data-cells (table info)
3450 "Transcode the first row of TABLE.
3451 INFO is a plist used as a communication channel."
3452 (let ((table-row
3453 (org-element-map table 'table-row
3454 (lambda (row)
3455 (unless (eq (org-element-property :type row) 'rule) row))
3456 info 'first-match))
3457 (special-column-p (org-export-table-has-special-column-p table)))
3458 (if (not special-column-p) (org-element-contents table-row)
3459 (cdr (org-element-contents table-row)))))
3461 (defun org-html-table--table.el-table (table _info)
3462 "Format table.el tables into HTML.
3463 INFO is a plist used as a communication channel."
3464 (when (eq (org-element-property :type table) 'table.el)
3465 (require 'table)
3466 (let ((outbuf (with-current-buffer
3467 (get-buffer-create "*org-export-table*")
3468 (erase-buffer) (current-buffer))))
3469 (with-temp-buffer
3470 (insert (org-element-property :value table))
3471 (goto-char 1)
3472 (re-search-forward "^[ \t]*|[^|]" nil t)
3473 (table-generate-source 'html outbuf))
3474 (with-current-buffer outbuf
3475 (prog1 (org-trim (buffer-string))
3476 (kill-buffer) )))))
3478 (defun org-html-table (table contents info)
3479 "Transcode a TABLE element from Org to HTML.
3480 CONTENTS is the contents of the table. INFO is a plist holding
3481 contextual information."
3482 (case (org-element-property :type table)
3483 ;; Case 1: table.el table. Convert it using appropriate tools.
3484 (table.el (org-html-table--table.el-table table info))
3485 ;; Case 2: Standard table.
3487 (let* ((caption (org-export-get-caption table))
3488 (number (org-export-get-ordinal
3489 table info nil #'org-html--has-caption-p))
3490 (attributes
3491 (org-html--make-attribute-string
3492 (org-combine-plists
3493 (and (org-element-property :name table)
3494 (list :id (org-export-get-reference table info)))
3495 (and (not (org-html-html5-p info))
3496 (plist-get info :html-table-attributes))
3497 (org-export-read-attribute :attr_html table))))
3498 (alignspec
3499 (if (and (boundp 'org-html-format-table-no-css)
3500 org-html-format-table-no-css)
3501 "align=\"%s\"" "class=\"org-%s\""))
3502 (table-column-specs
3503 (function
3504 (lambda (table info)
3505 (mapconcat
3506 (lambda (table-cell)
3507 (let ((alignment (org-export-table-cell-alignment
3508 table-cell info)))
3509 (concat
3510 ;; Begin a colgroup?
3511 (when (org-export-table-cell-starts-colgroup-p
3512 table-cell info)
3513 "\n<colgroup>")
3514 ;; Add a column. Also specify its alignment.
3515 (format "\n%s"
3516 (org-html-close-tag
3517 "col" (concat " " (format alignspec alignment)) info))
3518 ;; End a colgroup?
3519 (when (org-export-table-cell-ends-colgroup-p
3520 table-cell info)
3521 "\n</colgroup>"))))
3522 (org-html-table-first-row-data-cells table info) "\n")))))
3523 (format "<table%s>\n%s\n%s\n%s</table>"
3524 (if (equal attributes "") "" (concat " " attributes))
3525 (if (not caption) ""
3526 (format (if (plist-get info :html-table-caption-above)
3527 "<caption class=\"t-above\">%s</caption>"
3528 "<caption class=\"t-bottom\">%s</caption>")
3529 (concat
3530 "<span class=\"table-number\">"
3531 (format (org-html--translate "Table %d:" info) number)
3532 "</span> " (org-export-data caption info))))
3533 (funcall table-column-specs table info)
3534 contents)))))
3536 ;;;; Target
3538 (defun org-html-target (target _contents info)
3539 "Transcode a TARGET object from Org to HTML.
3540 CONTENTS is nil. INFO is a plist holding contextual
3541 information."
3542 (let ((ref (org-export-get-reference target info)))
3543 (org-html--anchor ref nil nil info)))
3545 ;;;; Timestamp
3547 (defun org-html-timestamp (timestamp _contents info)
3548 "Transcode a TIMESTAMP object from Org to HTML.
3549 CONTENTS is nil. INFO is a plist holding contextual
3550 information."
3551 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3552 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3553 (replace-regexp-in-string "--" "&#x2013;" value))))
3555 ;;;; Underline
3557 (defun org-html-underline (_underline contents info)
3558 "Transcode UNDERLINE from Org to HTML.
3559 CONTENTS is the text with underline markup. INFO is a plist
3560 holding contextual information."
3561 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3562 "%s")
3563 contents))
3565 ;;;; Verbatim
3567 (defun org-html-verbatim (verbatim _contents info)
3568 "Transcode VERBATIM from Org to HTML.
3569 CONTENTS is nil. INFO is a plist holding contextual
3570 information."
3571 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3572 (org-html-encode-plain-text (org-element-property :value verbatim))))
3574 ;;;; Verse Block
3576 (defun org-html-verse-block (_verse-block contents info)
3577 "Transcode a VERSE-BLOCK element from Org to HTML.
3578 CONTENTS is verse block contents. INFO is a plist holding
3579 contextual information."
3580 ;; Replace each newline character with line break. Also replace
3581 ;; each blank line with a line break.
3582 (setq contents (replace-regexp-in-string
3583 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3584 (replace-regexp-in-string
3585 "\\(\\\\\\\\\\)?[ \t]*\n"
3586 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3587 ;; Replace each white space at beginning of a line with a
3588 ;; non-breaking space.
3589 (while (string-match "^[ \t]+" contents)
3590 (let* ((num-ws (length (match-string 0 contents)))
3591 (ws (org-html--make-string num-ws "&#xa0;")))
3592 (setq contents (replace-match ws nil t contents))))
3593 (format "<p class=\"verse\">\n%s</p>" contents))
3596 ;;; Filter Functions
3598 (defun org-html-final-function (contents _backend info)
3599 "Filter to indent the HTML and convert HTML entities."
3600 (with-temp-buffer
3601 (insert contents)
3602 (set-auto-mode t)
3603 (if (plist-get info :html-indent)
3604 (indent-region (point-min) (point-max)))
3605 (buffer-substring-no-properties (point-min) (point-max))))
3608 ;;; End-user functions
3610 ;;;###autoload
3611 (defun org-html-export-as-html
3612 (&optional async subtreep visible-only body-only ext-plist)
3613 "Export current buffer to an HTML buffer.
3615 If narrowing is active in the current buffer, only export its
3616 narrowed part.
3618 If a region is active, export that region.
3620 A non-nil optional argument ASYNC means the process should happen
3621 asynchronously. The resulting buffer should be accessible
3622 through the `org-export-stack' interface.
3624 When optional argument SUBTREEP is non-nil, export the sub-tree
3625 at point, extracting information from the headline properties
3626 first.
3628 When optional argument VISIBLE-ONLY is non-nil, don't export
3629 contents of hidden elements.
3631 When optional argument BODY-ONLY is non-nil, only write code
3632 between \"<body>\" and \"</body>\" tags.
3634 EXT-PLIST, when provided, is a property list with external
3635 parameters overriding Org default settings, but still inferior to
3636 file-local settings.
3638 Export is done in a buffer named \"*Org HTML Export*\", which
3639 will be displayed when `org-export-show-temporary-export-buffer'
3640 is non-nil."
3641 (interactive)
3642 (org-export-to-buffer 'html "*Org HTML Export*"
3643 async subtreep visible-only body-only ext-plist
3644 (lambda () (set-auto-mode t))))
3646 ;;;###autoload
3647 (defun org-html-convert-region-to-html ()
3648 "Assume the current region has org-mode syntax, and convert it to HTML.
3649 This can be used in any buffer. For example, you can write an
3650 itemized list in org-mode syntax in an HTML buffer and use this
3651 command to convert it."
3652 (interactive)
3653 (org-export-replace-region-by 'html))
3655 ;;;###autoload
3656 (defun org-html-export-to-html
3657 (&optional async subtreep visible-only body-only ext-plist)
3658 "Export current buffer to a HTML file.
3660 If narrowing is active in the current buffer, only export its
3661 narrowed part.
3663 If a region is active, export that region.
3665 A non-nil optional argument ASYNC means the process should happen
3666 asynchronously. The resulting file should be accessible through
3667 the `org-export-stack' interface.
3669 When optional argument SUBTREEP is non-nil, export the sub-tree
3670 at point, extracting information from the headline properties
3671 first.
3673 When optional argument VISIBLE-ONLY is non-nil, don't export
3674 contents of hidden elements.
3676 When optional argument BODY-ONLY is non-nil, only write code
3677 between \"<body>\" and \"</body>\" tags.
3679 EXT-PLIST, when provided, is a property list with external
3680 parameters overriding Org default settings, but still inferior to
3681 file-local settings.
3683 Return output file's name."
3684 (interactive)
3685 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3686 org-html-extension
3687 "html")))
3688 (file (org-export-output-file-name extension subtreep))
3689 (org-export-coding-system org-html-coding-system))
3690 (org-export-to-file 'html file
3691 async subtreep visible-only body-only ext-plist)))
3693 ;;;###autoload
3694 (defun org-html-publish-to-html (plist filename pub-dir)
3695 "Publish an org file to HTML.
3697 FILENAME is the filename of the Org file to be published. PLIST
3698 is the property list for the given project. PUB-DIR is the
3699 publishing directory.
3701 Return output file name."
3702 (org-publish-org-to 'html filename
3703 (concat "." (or (plist-get plist :html-extension)
3704 org-html-extension
3705 "html"))
3706 plist pub-dir))
3709 (provide 'ox-html)
3711 ;; Local variables:
3712 ;; generated-autoload-file: "org-loaddefs.el"
3713 ;; End:
3715 ;;; ox-html.el ends here