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