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