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