Erase `org-insert-labeled-timestamps-at-point'
[org-mode.git] / lisp / ox-html.el
blob20d09eb7505f90e46811aa781d4e00ef412a84b3
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 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 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
114 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
115 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
116 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
117 (:html-head "HTML_HEAD" nil org-html-head newline)
118 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
119 (:html-container "HTML_CONTAINER" nil org-html-container-element)
120 (:html-mathjax "HTML_MATHJAX" nil "" space)
121 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
122 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
123 (:html-postamble nil "html-postamble" org-html-postamble)
124 (:html-preamble nil "html-preamble" org-html-preamble)
125 (:html-head "HTML_HEAD" nil org-html-head newline)
126 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
127 (:html-head-include-default-style
128 nil "html-style" org-html-head-include-default-style)
129 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
130 (:html-allow-name-attribute-in-anchors
131 nil nil org-html-allow-name-attribute-in-anchors)
132 (:html-divs nil nil org-html-divs)
133 (:html-checkbox-type nil nil org-html-checkbox-type)
134 (:html-extension nil nil org-html-extension)
135 (:html-footnote-format nil nil org-html-footnote-format)
136 (:html-footnote-separator nil nil org-html-footnote-separator)
137 (:html-footnotes-section nil nil org-html-footnotes-section)
138 (:html-format-drawer-function nil nil org-html-format-drawer-function)
139 (:html-format-headline-function nil nil org-html-format-headline-function)
140 (:html-format-inlinetask-function
141 nil nil org-html-format-inlinetask-function)
142 (:html-home/up-format nil nil org-html-home/up-format)
143 (:html-indent nil nil org-html-indent)
144 (:html-infojs-options nil nil org-html-infojs-options)
145 (:html-infojs-template nil nil org-html-infojs-template)
146 (:html-inline-image-rules nil nil org-html-inline-image-rules)
147 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
148 (:html-mathjax-options nil nil org-html-mathjax-options)
149 (:html-mathjax-template nil nil org-html-mathjax-template)
150 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
151 (:html-postamble-format nil nil org-html-postamble-format)
152 (:html-preamble-format nil nil org-html-preamble-format)
153 (:html-table-align-individual-fields
154 nil nil org-html-table-align-individual-fields)
155 (:html-table-caption-above nil nil org-html-table-caption-above)
156 (:html-table-data-tags nil nil org-html-table-data-tags)
157 (:html-table-header-tags nil nil org-html-table-header-tags)
158 (:html-table-use-header-tags-for-first-column
159 nil nil org-html-table-use-header-tags-for-first-column)
160 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
161 (:html-text-markup-alist nil nil org-html-text-markup-alist)
162 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
163 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
164 (:html-use-infojs nil nil org-html-use-infojs)
165 (:html-use-unicode-chars nil nil org-html-use-unicode-chars)
166 (:html-validation-link nil nil org-html-validation-link)
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 .todo { font-family: monospace; color: red; }
278 .done { color: green; }
279 .tag { background-color: #eee; font-family: monospace;
280 padding: 2px; font-size: 80%; font-weight: normal; }
281 .timestamp { color: #bebebe; }
282 .timestamp-kwd { color: #5f9ea0; }
283 .right { margin-left: auto; margin-right: 0px; text-align: right; }
284 .left { margin-left: 0px; margin-right: auto; text-align: left; }
285 .center { margin-left: auto; margin-right: auto; text-align: center; }
286 .underline { text-decoration: underline; }
287 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
288 p.verse { margin-left: 3%; }
289 pre {
290 border: 1px solid #ccc;
291 box-shadow: 3px 3px 3px #eee;
292 padding: 8pt;
293 font-family: monospace;
294 overflow: auto;
295 margin: 1.2em;
297 pre.src {
298 position: relative;
299 overflow: visible;
300 padding-top: 1.2em;
302 pre.src:before {
303 display: none;
304 position: absolute;
305 background-color: white;
306 top: -10px;
307 right: 10px;
308 padding: 3px;
309 border: 1px solid black;
311 pre.src:hover:before { display: inline;}
312 pre.src-sh:before { content: 'sh'; }
313 pre.src-bash:before { content: 'sh'; }
314 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
315 pre.src-R:before { content: 'R'; }
316 pre.src-perl:before { content: 'Perl'; }
317 pre.src-java:before { content: 'Java'; }
318 pre.src-sql:before { content: 'SQL'; }
320 table { border-collapse:collapse; }
321 caption.t-above { caption-side: top; }
322 caption.t-bottom { caption-side: bottom; }
323 td, th { vertical-align:top; }
324 th.right { text-align: center; }
325 th.left { text-align: center; }
326 th.center { text-align: center; }
327 td.right { text-align: right; }
328 td.left { text-align: left; }
329 td.center { text-align: center; }
330 dt { font-weight: bold; }
331 .footpara:nth-child(2) { display: inline; }
332 .footpara { display: block; }
333 .footdef { margin-bottom: 1em; }
334 .figure { padding: 1em; }
335 .figure p { text-align: center; }
336 .inlinetask {
337 padding: 10px;
338 border: 2px solid gray;
339 margin: 10px;
340 background: #ffffcc;
342 #org-div-home-and-up
343 { text-align: right; font-size: 70%; white-space: nowrap; }
344 textarea { overflow-x: auto; }
345 .linenr { font-size: smaller }
346 .code-highlighted { background-color: #ffff00; }
347 .org-info-js_info-navigation { border-style: none; }
348 #org-info-js_console-label
349 { font-size: 10px; font-weight: bold; white-space: nowrap; }
350 .org-info-js_search-highlight
351 { background-color: #ffff00; color: #000000; font-weight: bold; }
352 /*]]>*/-->
353 </style>"
354 "The default style specification for exported HTML files.
355 You can use `org-html-head' and `org-html-head-extra' to add to
356 this style. If you don't want to include this default style,
357 customize `org-html-head-include-default-style'.")
360 ;;; User Configuration Variables
362 (defgroup org-export-html nil
363 "Options for exporting Org mode files to HTML."
364 :tag "Org Export HTML"
365 :group 'org-export)
367 ;;;; Handle infojs
369 (defvar org-html-infojs-opts-table
370 '((path PATH "http://orgmode.org/org-info.js")
371 (view VIEW "info")
372 (toc TOC :with-toc)
373 (ftoc FIXED_TOC "0")
374 (tdepth TOC_DEPTH "max")
375 (sdepth SECTION_DEPTH "max")
376 (mouse MOUSE_HINT "underline")
377 (buttons VIEW_BUTTONS "0")
378 (ltoc LOCAL_TOC "1")
379 (up LINK_UP :html-link-up)
380 (home LINK_HOME :html-link-home))
381 "JavaScript options, long form for script, default values.")
383 (defcustom org-html-use-infojs 'when-configured
384 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
385 This option can be nil or t to never or always use the script.
386 It can also be the symbol `when-configured', meaning that the
387 script will be linked into the export file if and only if there
388 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
389 `org-html-infojs-options'."
390 :group 'org-export-html
391 :version "24.4"
392 :package-version '(Org . "8.0")
393 :type '(choice
394 (const :tag "Never" nil)
395 (const :tag "When configured in buffer" when-configured)
396 (const :tag "Always" t)))
398 (defcustom org-html-infojs-options
399 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
400 "Options settings for the INFOJS JavaScript.
401 Each of the options must have an entry in `org-html-infojs-opts-table'.
402 The value can either be a string that will be passed to the script, or
403 a property. This property is then assumed to be a property that is defined
404 by the Export/Publishing setup of Org.
405 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
406 means to use the maximum value consistent with other options."
407 :group 'org-export-html
408 :version "24.4"
409 :package-version '(Org . "8.0")
410 :type
411 `(set :greedy t :inline t
412 ,@(mapcar
413 (lambda (x)
414 (list 'cons (list 'const (car x))
415 '(choice
416 (symbol :tag "Publishing/Export property")
417 (string :tag "Value"))))
418 org-html-infojs-opts-table)))
420 (defcustom org-html-infojs-template
421 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
424 * @source: %SCRIPT_PATH
426 * @licstart The following is the entire license notice for the
427 * JavaScript code in %SCRIPT_PATH.
429 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
432 * The JavaScript code in this tag is free software: you can
433 * redistribute it and/or modify it under the terms of the GNU
434 * General Public License (GNU GPL) as published by the Free Software
435 * Foundation, either version 3 of the License, or (at your option)
436 * any later version. The code is distributed WITHOUT ANY WARRANTY;
437 * without even the implied warranty of MERCHANTABILITY or FITNESS
438 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
440 * As additional permission under GNU GPL version 3 section 7, you
441 * may distribute non-source (e.g., minimized or compacted) forms of
442 * that code without the copy of the GNU GPL normally required by
443 * section 4, provided you include this license notice and a URL
444 * through which recipients can access the Corresponding Source.
446 * @licend The above is the entire license notice
447 * for the JavaScript code in %SCRIPT_PATH.
450 </script>
452 <script type=\"text/javascript\">
455 @licstart The following is the entire license notice for the
456 JavaScript code in this tag.
458 Copyright (C) 2012-2013 Free Software Foundation, Inc.
460 The JavaScript code in this tag is free software: you can
461 redistribute it and/or modify it under the terms of the GNU
462 General Public License (GNU GPL) as published by the Free Software
463 Foundation, either version 3 of the License, or (at your option)
464 any later version. The code is distributed WITHOUT ANY WARRANTY;
465 without even the implied warranty of MERCHANTABILITY or FITNESS
466 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
468 As additional permission under GNU GPL version 3 section 7, you
469 may distribute non-source (e.g., minimized or compacted) forms of
470 that code without the copy of the GNU GPL normally required by
471 section 4, provided you include this license notice and a URL
472 through which recipients can access the Corresponding Source.
475 @licend The above is the entire license notice
476 for the JavaScript code in this tag.
479 <!--/*--><![CDATA[/*><!--*/
480 %MANAGER_OPTIONS
481 org_html_manager.setup(); // activate after the parameters are set
482 /*]]>*///-->
483 </script>"
484 "The template for the export style additions when org-info.js is used.
485 Option settings will replace the %MANAGER-OPTIONS cookie."
486 :group 'org-export-html
487 :version "24.4"
488 :package-version '(Org . "8.0")
489 :type 'string)
491 (defun org-html-infojs-install-script (exp-plist backend)
492 "Install script in export options when appropriate.
493 EXP-PLIST is a plist containing export options. BACKEND is the
494 export back-end currently used."
495 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
496 (not (plist-get exp-plist :html-use-infojs))
497 (and (eq (plist-get exp-plist :html-use-infojs) 'when-configured)
498 (let ((opt (plist-get exp-plist :infojs-opt)))
499 (or (not opt)
500 (string= "" opt)
501 (string-match "\\<view:nil\\>" opt)))))
502 (let* ((template (plist-get exp-plist :html-infojs-template))
503 (ptoc (plist-get exp-plist :with-toc))
504 (hlevels (plist-get exp-plist :headline-levels))
505 (sdepth hlevels)
506 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
507 (options (plist-get exp-plist :infojs-opt))
508 (infojs-opt (plist-get exp-plist :html-infojs-options))
509 (table org-html-infojs-opts-table)
510 style)
511 (dolist (entry table)
512 (let* ((opt (car entry))
513 (var (nth 1 entry))
514 ;; Compute default values for script option OPT from
515 ;; `org-html-infojs-options' variable.
516 (default
517 (let ((default (cdr (assq opt infojs-opt))))
518 (if (and (symbolp default) (not (memq default '(t nil))))
519 (plist-get exp-plist default)
520 default)))
521 ;; Value set through INFOJS_OPT keyword has precedence
522 ;; over the default one.
523 (val (if (and options
524 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
525 options))
526 (match-string 1 options)
527 default)))
528 (case opt
529 (path (setq template
530 (replace-regexp-in-string
531 "%SCRIPT_PATH" val template t t)))
532 (sdepth (when (integerp (read val))
533 (setq sdepth (min (read val) sdepth))))
534 (tdepth (when (integerp (read val))
535 (setq tdepth (min (read val) tdepth))))
536 (otherwise (setq val
537 (cond
538 ((or (eq val t) (equal val "t")) "1")
539 ((or (eq val nil) (equal val "nil")) "0")
540 ((stringp val) val)
541 (t (format "%s" val))))
542 (push (cons var val) style)))))
543 ;; Now we set the depth of the *generated* TOC to SDEPTH,
544 ;; because the toc will actually determine the splitting. How
545 ;; much of the toc will actually be displayed is governed by the
546 ;; TDEPTH option.
547 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
548 ;; The table of contents should not show more sections than we
549 ;; generate.
550 (setq tdepth (min tdepth sdepth))
551 (push (cons "TOC_DEPTH" tdepth) style)
552 ;; Build style string.
553 (setq style (mapconcat
554 (lambda (x)
555 (format "org_html_manager.set(\"%s\", \"%s\");"
556 (car x) (cdr x)))
557 style "\n"))
558 (when (and style (> (length style) 0))
559 (and (string-match "%MANAGER_OPTIONS" template)
560 (setq style (replace-match style t t template))
561 (setq exp-plist
562 (plist-put
563 exp-plist :html-head-extra
564 (concat (or (plist-get exp-plist :html-head-extra) "")
565 "\n"
566 style)))))
567 ;; This script absolutely needs the table of contents, so we
568 ;; change that setting.
569 (unless (plist-get exp-plist :with-toc)
570 (setq exp-plist (plist-put exp-plist :with-toc t)))
571 ;; Return the modified property list.
572 exp-plist)))
574 ;;;; Bold, etc.
576 (defcustom org-html-text-markup-alist
577 '((bold . "<b>%s</b>")
578 (code . "<code>%s</code>")
579 (italic . "<i>%s</i>")
580 (strike-through . "<del>%s</del>")
581 (underline . "<span class=\"underline\">%s</span>")
582 (verbatim . "<code>%s</code>"))
583 "Alist of HTML expressions to convert text markup.
585 The key must be a symbol among `bold', `code', `italic',
586 `strike-through', `underline' and `verbatim'. The value is
587 a formatting string to wrap fontified text with.
589 If no association can be found for a given markup, text will be
590 returned as-is."
591 :group 'org-export-html
592 :version "24.4"
593 :package-version '(Org . "8.0")
594 :type '(alist :key-type (symbol :tag "Markup type")
595 :value-type (string :tag "Format string"))
596 :options '(bold code italic strike-through underline verbatim))
598 (defcustom org-html-indent nil
599 "Non-nil means to indent the generated HTML.
600 Warning: non-nil may break indentation of source code blocks."
601 :group 'org-export-html
602 :version "24.4"
603 :package-version '(Org . "8.0")
604 :type 'boolean)
606 (defcustom org-html-use-unicode-chars nil
607 "Non-nil means to use unicode characters instead of HTML entities."
608 :group 'org-export-html
609 :version "24.4"
610 :package-version '(Org . "8.0")
611 :type 'boolean)
613 ;;;; Drawers
615 (defcustom org-html-format-drawer-function (lambda (name contents) contents)
616 "Function called to format a drawer in HTML code.
618 The function must accept two parameters:
619 NAME the drawer name, like \"LOGBOOK\"
620 CONTENTS the contents of the drawer.
622 The function should return the string to be exported.
624 For example, the variable could be set to the following function
625 in order to mimic default behaviour:
627 The default value simply returns the value of CONTENTS."
628 :group 'org-export-html
629 :version "24.4"
630 :package-version '(Org . "8.0")
631 :type 'function)
633 ;;;; Footnotes
635 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
636 <h2 class=\"footnotes\">%s: </h2>
637 <div id=\"text-footnotes\">
639 </div>
640 </div>"
641 "Format for the footnotes section.
642 Should contain a two instances of %s. The first will be replaced with the
643 language-specific word for \"Footnotes\", the second one will be replaced
644 by the footnotes themselves."
645 :group 'org-export-html
646 :type 'string)
648 (defcustom org-html-footnote-format "<sup>%s</sup>"
649 "The format for the footnote reference.
650 %s will be replaced by the footnote reference itself."
651 :group 'org-export-html
652 :type 'string)
654 (defcustom org-html-footnote-separator "<sup>, </sup>"
655 "Text used to separate footnotes."
656 :group 'org-export-html
657 :type 'string)
659 ;;;; Headline
661 (defcustom org-html-toplevel-hlevel 2
662 "The <H> level for level 1 headings in HTML export.
663 This is also important for the classes that will be wrapped around headlines
664 and outline structure. If this variable is 1, the top-level headlines will
665 be <h1>, and the corresponding classes will be outline-1, section-number-1,
666 and outline-text-1. If this is 2, all of these will get a 2 instead.
667 The default for this variable is 2, because we use <h1> for formatting the
668 document title."
669 :group 'org-export-html
670 :type 'integer)
672 (defcustom org-html-format-headline-function
673 'org-html-format-headline-default-function
674 "Function to format headline text.
676 This function will be called with six arguments:
677 TODO the todo keyword (string or nil).
678 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
679 PRIORITY the priority of the headline (integer or nil)
680 TEXT the main headline text (string).
681 TAGS the tags (string or nil).
682 INFO the export options (plist).
684 The function result will be used in the section format string."
685 :group 'org-export-html
686 :version "25.1"
687 :package-version '(Org . "8.3")
688 :type 'function)
690 ;;;; HTML-specific
692 (defcustom org-html-allow-name-attribute-in-anchors nil
693 "When nil, do not set \"name\" attribute in anchors.
694 By default, when appropriate, anchors are formatted with \"id\"
695 but without \"name\" attribute."
696 :group 'org-export-html
697 :version "24.4"
698 :package-version '(Org . "8.0")
699 :type 'boolean)
701 ;;;; Inlinetasks
703 (defcustom org-html-format-inlinetask-function
704 'org-html-format-inlinetask-default-function
705 "Function called to format an inlinetask in HTML code.
707 The function must accept seven parameters:
708 TODO the todo keyword, as a string
709 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
710 PRIORITY the inlinetask priority, as a string
711 NAME the inlinetask name, as a string.
712 TAGS the inlinetask tags, as a list of strings.
713 CONTENTS the contents of the inlinetask, as a string.
714 INFO the export options, as a plist
716 The function should return the string to be exported."
717 :group 'org-export-html
718 :version "25.1"
719 :package-version '(Org . "8.3")
720 :type 'function)
722 ;;;; LaTeX
724 (defcustom org-html-with-latex org-export-with-latex
725 "Non-nil means process LaTeX math snippets.
727 When set, the exporter will process LaTeX environments and
728 fragments.
730 This option can also be set with the +OPTIONS line,
731 e.g. \"tex:mathjax\". Allowed values are:
733 nil Ignore math snippets.
734 `verbatim' Keep everything in verbatim
735 `dvipng' Process the LaTeX fragments to images. This will also
736 include processing of non-math environments.
737 `imagemagick' Convert the LaTeX fragments to pdf files and use
738 imagemagick to convert pdf files to png files.
739 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
740 be loaded.
741 t Synonym for `mathjax'."
742 :group 'org-export-html
743 :version "24.4"
744 :package-version '(Org . "8.0")
745 :type '(choice
746 (const :tag "Do not process math in any way" nil)
747 (const :tag "Use dvipng to make images" dvipng)
748 (const :tag "Use imagemagick to make images" imagemagick)
749 (const :tag "Use MathJax to display math" mathjax)
750 (const :tag "Leave math verbatim" verbatim)))
752 ;;;; Links :: Generic
754 (defcustom org-html-link-org-files-as-html t
755 "Non-nil means make file links to `file.org' point to `file.html'.
756 When `org-mode' is exporting an `org-mode' file to HTML, links to
757 non-html files are directly put into a href tag in HTML.
758 However, links to other Org-mode files (recognized by the
759 extension `.org.) should become links to the corresponding html
760 file, assuming that the linked `org-mode' file will also be
761 converted to HTML.
762 When nil, the links still point to the plain `.org' file."
763 :group 'org-export-html
764 :type 'boolean)
766 ;;;; Links :: Inline images
768 (defcustom org-html-inline-images t
769 "Non-nil means inline images into exported HTML pages.
770 This is done using an <img> tag. When nil, an anchor with href is used to
771 link to the image."
772 :group 'org-export-html
773 :version "24.4"
774 :package-version '(Org . "8.1")
775 :type 'boolean)
777 (defcustom org-html-inline-image-rules
778 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
779 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
780 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
781 "Rules characterizing image files that can be inlined into HTML.
782 A rule consists in an association whose key is the type of link
783 to consider, and value is a regexp that will be matched against
784 link's path."
785 :group 'org-export-html
786 :version "24.4"
787 :package-version '(Org . "8.0")
788 :type '(alist :key-type (string :tag "Type")
789 :value-type (regexp :tag "Path")))
791 ;;;; Plain Text
793 (defvar org-html-protect-char-alist
794 '(("&" . "&amp;")
795 ("<" . "&lt;")
796 (">" . "&gt;"))
797 "Alist of characters to be converted by `org-html-protect'.")
799 ;;;; Src Block
801 (defcustom org-html-htmlize-output-type 'inline-css
802 "Output type to be used by htmlize when formatting code snippets.
803 Choices are `css' to export the CSS selectors only,`inline-css'
804 to export the CSS attribute values inline in the HTML or `nil' to
805 export plain text. We use as default `inline-css', in order to
806 make the resulting HTML self-containing.
808 However, this will fail when using Emacs in batch mode for export, because
809 then no rich font definitions are in place. It will also not be good if
810 people with different Emacs setup contribute HTML files to a website,
811 because the fonts will represent the individual setups. In these cases,
812 it is much better to let Org/Htmlize assign classes only, and to use
813 a style file to define the look of these classes.
814 To get a start for your css file, start Emacs session and make sure that
815 all the faces you are interested in are defined, for example by loading files
816 in all modes you want. Then, use the command
817 \\[org-html-htmlize-generate-css] to extract class definitions."
818 :group 'org-export-html
819 :type '(choice (const css) (const inline-css) (const nil)))
821 (defcustom org-html-htmlize-font-prefix "org-"
822 "The prefix for CSS class names for htmlize font specifications."
823 :group 'org-export-html
824 :type 'string)
826 ;;;; Table
828 (defcustom org-html-table-default-attributes
829 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
830 "Default attributes and values which will be used in table tags.
831 This is a plist where attributes are symbols, starting with
832 colons, and values are strings.
834 When exporting to HTML5, these values will be disregarded."
835 :group 'org-export-html
836 :version "24.4"
837 :package-version '(Org . "8.0")
838 :type '(plist :key-type (symbol :tag "Property")
839 :value-type (string :tag "Value")))
841 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
842 "The opening and ending tags for table header fields.
843 This is customizable so that alignment options can be specified.
844 The first %s will be filled with the scope of the field, either row or col.
845 The second %s will be replaced by a style entry to align the field.
846 See also the variable `org-html-table-use-header-tags-for-first-column'.
847 See also the variable `org-html-table-align-individual-fields'."
848 :group 'org-export-html
849 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
851 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
852 "The opening and ending tags for table data fields.
853 This is customizable so that alignment options can be specified.
854 The first %s will be filled with the scope of the field, either row or col.
855 The second %s will be replaced by a style entry to align the field.
856 See also the variable `org-html-table-align-individual-fields'."
857 :group 'org-export-html
858 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
860 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
861 "The opening and ending tags for table rows.
862 This is customizable so that alignment options can be specified.
863 Instead of strings, these can be Lisp forms that will be
864 evaluated for each row in order to construct the table row tags.
866 During evaluation, these variables will be dynamically bound so that
867 you can reuse them:
869 `row-number': row number (0 is the first row)
870 `rowgroup-number': group number of current row
871 `start-rowgroup-p': non-nil means the row starts a group
872 `end-rowgroup-p': non-nil means the row ends a group
873 `top-row-p': non-nil means this is the top row
874 `bottom-row-p': non-nil means this is the bottom row
876 For example:
878 \(setq org-html-table-row-tags
879 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
880 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
881 (t (if (= (mod row-number 2) 1)
882 \"<tr class=\\\"tr-odd\\\">\"
883 \"<tr class=\\\"tr-even\\\">\")))
884 \"</tr>\"))
886 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
887 and the bottom row, and otherwise alternate between \"tr-odd\" and
888 \"tr-even\" for odd and even rows."
889 :group 'org-export-html
890 :type '(cons
891 (choice :tag "Opening tag"
892 (string :tag "Specify")
893 (sexp))
894 (choice :tag "Closing tag"
895 (string :tag "Specify")
896 (sexp))))
898 (defcustom org-html-table-align-individual-fields t
899 "Non-nil means attach style attributes for alignment to each table field.
900 When nil, alignment will only be specified in the column tags, but this
901 is ignored by some browsers (like Firefox, Safari). Opera does it right
902 though."
903 :group 'org-export-html
904 :type 'boolean)
906 (defcustom org-html-table-use-header-tags-for-first-column nil
907 "Non-nil means format column one in tables with header tags.
908 When nil, also column one will use data tags."
909 :group 'org-export-html
910 :type 'boolean)
912 (defcustom org-html-table-caption-above t
913 "When non-nil, place caption string at the beginning of the table.
914 Otherwise, place it near the end."
915 :group 'org-export-html
916 :type 'boolean)
918 ;;;; Tags
920 (defcustom org-html-tag-class-prefix ""
921 "Prefix to class names for TODO keywords.
922 Each tag gets a class given by the tag itself, with this prefix.
923 The default prefix is empty because it is nice to just use the keyword
924 as a class name. But if you get into conflicts with other, existing
925 CSS classes, then this prefix can be very useful."
926 :group 'org-export-html
927 :type 'string)
929 ;;;; Template :: Generic
931 (defcustom org-html-extension "html"
932 "The extension for exported HTML files."
933 :group 'org-export-html
934 :type 'string)
936 (defcustom org-html-xml-declaration
937 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
938 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
939 "The extension for exported HTML files.
940 %s will be replaced with the charset of the exported file.
941 This may be a string, or an alist with export extensions
942 and corresponding declarations.
944 This declaration only applies when exporting to XHTML."
945 :group 'org-export-html
946 :type '(choice
947 (string :tag "Single declaration")
948 (repeat :tag "Dependent on extension"
949 (cons (string :tag "Extension")
950 (string :tag "Declaration")))))
952 (defcustom org-html-coding-system 'utf-8
953 "Coding system for HTML export.
954 Use utf-8 as the default value."
955 :group 'org-export-html
956 :version "24.4"
957 :package-version '(Org . "8.0")
958 :type 'coding-system)
960 (defcustom org-html-doctype "xhtml-strict"
961 "Document type definition to use for exported HTML files.
962 Can be set with the in-buffer HTML_DOCTYPE property or for
963 publishing, with :html-doctype."
964 :group 'org-export-html
965 :version "24.4"
966 :package-version '(Org . "8.0")
967 :type (append
968 '(choice)
969 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
970 '((string :tag "Custom doctype" ))))
972 (defcustom org-html-html5-fancy nil
973 "Non-nil means using new HTML5 elements.
974 This variable is ignored for anything other than HTML5 export.
976 For compatibility with Internet Explorer, it's probably a good
977 idea to download some form of the html5shiv (for instance
978 https://code.google.com/p/html5shiv/) and add it to your
979 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
980 versions 8 and below."
981 :group 'org-export-html
982 :version "24.4"
983 :package-version '(Org . "8.0")
984 :type 'boolean)
986 (defcustom org-html-container-element "div"
987 "HTML element to use for wrapping top level sections.
988 Can be set with the in-buffer HTML_CONTAINER property or for
989 publishing, with :html-container.
991 Note that changing the default will prevent you from using
992 org-info.js for your website."
993 :group 'org-export-html
994 :version "24.4"
995 :package-version '(Org . "8.0")
996 :type 'string)
998 (defcustom org-html-divs
999 '((preamble "div" "preamble")
1000 (content "div" "content")
1001 (postamble "div" "postamble"))
1002 "Alist of the three section elements for HTML export.
1003 The car of each entry is one of 'preamble, 'content or 'postamble.
1004 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1005 section of the exported document.
1007 Note that changing the default will prevent you from using
1008 org-info.js for your website."
1009 :group 'org-export-html
1010 :version "24.4"
1011 :package-version '(Org . "8.0")
1012 :type '(list :greedy t
1013 (list :tag "Preamble"
1014 (const :format "" preamble)
1015 (string :tag "element") (string :tag " id"))
1016 (list :tag "Content"
1017 (const :format "" content)
1018 (string :tag "element") (string :tag " id"))
1019 (list :tag "Postamble" (const :format "" postamble)
1020 (string :tag " id") (string :tag "element"))))
1022 (defconst org-html-checkbox-types
1023 '((unicode .
1024 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1025 (ascii .
1026 ((on . "<code>[X]</code>")
1027 (off . "<code>[&#xa0;]</code>")
1028 (trans . "<code>[-]</code>")))
1029 (html .
1030 ((on . "<input type='checkbox' checked='checked' />")
1031 (off . "<input type='checkbox' />")
1032 (trans . "<input type='checkbox' />"))))
1033 "Alist of checkbox types.
1034 The cdr of each entry is an alist list three checkbox types for
1035 HTML export: `on', `off' and `trans'.
1037 The choices are:
1038 `unicode' Unicode characters (HTML entities)
1039 `ascii' ASCII characters
1040 `html' HTML checkboxes
1042 Note that only the ascii characters implement tri-state
1043 checkboxes. The other two use the `off' checkbox for `trans'.")
1045 (defcustom org-html-checkbox-type 'ascii
1046 "The type of checkboxes to use for HTML export.
1047 See `org-html-checkbox-types' for for the values used for each
1048 option."
1049 :group 'org-export-html
1050 :version "24.4"
1051 :package-version '(Org . "8.0")
1052 :type '(choice
1053 (const :tag "ASCII characters" ascii)
1054 (const :tag "Unicode characters" unicode)
1055 (const :tag "HTML checkboxes" html)))
1057 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1058 "Format used for timestamps in preamble, postamble and metadata.
1059 See `format-time-string' for more information on its components."
1060 :group 'org-export-html
1061 :version "24.4"
1062 :package-version '(Org . "8.0")
1063 :type 'string)
1065 ;;;; Template :: Mathjax
1067 (defcustom org-html-mathjax-options
1068 '((path "http://orgmode.org/mathjax/MathJax.js")
1069 (scale "100")
1070 (align "center")
1071 (indent "2em")
1072 (mathml nil))
1073 "Options for MathJax setup.
1075 path The path where to find MathJax
1076 scale Scaling for the HTML-CSS backend, usually between 100 and 133
1077 align How to align display math: left, center, or right
1078 indent If align is not center, how far from the left/right side?
1079 mathml Should a MathML player be used if available?
1080 This is faster and reduces bandwidth use, but currently
1081 sometimes has lower spacing quality. Therefore, the default is
1082 nil. When browsers get better, this switch can be flipped.
1084 You can also customize this for each buffer, using something like
1086 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1087 :group 'org-export-html
1088 :type '(list :greedy t
1089 (list :tag "path (the path from where to load MathJax.js)"
1090 (const :format " " path) (string))
1091 (list :tag "scale (scaling for the displayed math)"
1092 (const :format " " scale) (string))
1093 (list :tag "align (alignment of displayed equations)"
1094 (const :format " " align) (string))
1095 (list :tag "indent (indentation with left or right alignment)"
1096 (const :format " " indent) (string))
1097 (list :tag "mathml (should MathML display be used is possible)"
1098 (const :format " " mathml) (boolean))))
1100 (defcustom org-html-mathjax-template
1101 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1102 <script type=\"text/javascript\">
1103 <!--/*--><![CDATA[/*><!--*/
1104 MathJax.Hub.Config({
1105 // Only one of the two following lines, depending on user settings
1106 // First allows browser-native MathML display, second forces HTML/CSS
1107 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1108 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1109 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1110 \"TeX/noUndefined.js\"],
1111 tex2jax: {
1112 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1113 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1114 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1115 ignoreClass: \"tex2jax_ignore\",
1116 processEscapes: false,
1117 processEnvironments: true,
1118 preview: \"TeX\"
1120 showProcessingMessages: true,
1121 displayAlign: \"%ALIGN\",
1122 displayIndent: \"%INDENT\",
1124 \"HTML-CSS\": {
1125 scale: %SCALE,
1126 availableFonts: [\"STIX\",\"TeX\"],
1127 preferredFont: \"TeX\",
1128 webFont: \"TeX\",
1129 imageFont: \"TeX\",
1130 showMathMenu: true,
1132 MMLorHTML: {
1133 prefer: {
1134 MSIE: \"MML\",
1135 Firefox: \"MML\",
1136 Opera: \"HTML\",
1137 other: \"HTML\"
1141 /*]]>*///-->
1142 </script>"
1143 "The MathJax setup for XHTML files."
1144 :group 'org-export-html
1145 :type 'string)
1147 ;;;; Template :: Postamble
1149 (defcustom org-html-postamble 'auto
1150 "Non-nil means insert a postamble in HTML export.
1152 When set to 'auto, check against the
1153 `org-export-with-author/email/creator/date' variables to set the
1154 content of the postamble. When set to a string, use this string
1155 as the postamble. When t, insert a string as defined by the
1156 formatting string in `org-html-postamble-format'.
1158 When set to a function, apply this function and insert the
1159 returned string. The function takes the property list of export
1160 options as its only argument.
1162 Setting :html-postamble in publishing projects will take
1163 precedence over this variable."
1164 :group 'org-export-html
1165 :type '(choice (const :tag "No postamble" nil)
1166 (const :tag "Auto postamble" auto)
1167 (const :tag "Default formatting string" t)
1168 (string :tag "Custom formatting string")
1169 (function :tag "Function (must return a string)")))
1171 (defcustom org-html-postamble-format
1172 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1173 <p class=\"date\">Date: %d</p>
1174 <p class=\"creator\">%c</p>
1175 <p class=\"validation\">%v</p>"))
1176 "Alist of languages and format strings for the HTML postamble.
1178 The first element of each list is the language code, as used for
1179 the LANGUAGE keyword. See `org-export-default-language'.
1181 The second element of each list is a format string to format the
1182 postamble itself. This format string can contain these elements:
1184 %t stands for the title.
1185 %a stands for the author's name.
1186 %e stands for the author's email.
1187 %d stands for the date.
1188 %c will be replaced by `org-html-creator-string'.
1189 %v will be replaced by `org-html-validation-link'.
1190 %T will be replaced by the export time.
1191 %C will be replaced by the last modification time.
1193 If you need to use a \"%\" character, you need to escape it
1194 like that: \"%%\"."
1195 :group 'org-export-html
1196 :type '(repeat
1197 (list (string :tag "Language")
1198 (string :tag "Format string"))))
1200 (defcustom org-html-validation-link
1201 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1202 "Link to HTML validation service."
1203 :group 'org-export-html
1204 :type 'string)
1206 (defcustom org-html-creator-string
1207 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1208 emacs-version
1209 (if (fboundp 'org-version) (org-version) "unknown version"))
1210 "Information about the creator of the HTML document.
1211 This option can also be set on with the CREATOR keyword."
1212 :group 'org-export-html
1213 :version "24.4"
1214 :package-version '(Org . "8.0")
1215 :type '(string :tag "Creator string"))
1217 ;;;; Template :: Preamble
1219 (defcustom org-html-preamble t
1220 "Non-nil means insert a preamble in HTML export.
1222 When t, insert a string as defined by the formatting string in
1223 `org-html-preamble-format'. When set to a string, use this
1224 formatting string instead (see `org-html-postamble-format' for an
1225 example of such a formatting string).
1227 When set to a function, apply this function and insert the
1228 returned string. The function takes the property list of export
1229 options as its only argument.
1231 Setting :html-preamble in publishing projects will take
1232 precedence over this variable."
1233 :group 'org-export-html
1234 :type '(choice (const :tag "No preamble" nil)
1235 (const :tag "Default preamble" t)
1236 (string :tag "Custom formatting string")
1237 (function :tag "Function (must return a string)")))
1239 (defcustom org-html-preamble-format '(("en" ""))
1240 "Alist of languages and format strings for the HTML preamble.
1242 The first element of each list is the language code, as used for
1243 the LANGUAGE keyword. See `org-export-default-language'.
1245 The second element of each list is a format string to format the
1246 preamble itself. This format string can contain these elements:
1248 %t stands for the title.
1249 %a stands for the author's name.
1250 %e stands for the author's email.
1251 %d stands for the date.
1252 %c will be replaced by `org-html-creator-string'.
1253 %v will be replaced by `org-html-validation-link'.
1254 %T will be replaced by the export time.
1255 %C will be replaced by the last modification time.
1257 If you need to use a \"%\" character, you need to escape it
1258 like that: \"%%\".
1260 See the default value of `org-html-postamble-format' for an
1261 example."
1262 :group 'org-export-html
1263 :type '(repeat
1264 (list (string :tag "Language")
1265 (string :tag "Format string"))))
1267 (defcustom org-html-link-up ""
1268 "Where should the \"UP\" link of exported HTML pages lead?"
1269 :group 'org-export-html
1270 :type '(string :tag "File or URL"))
1272 (defcustom org-html-link-home ""
1273 "Where should the \"HOME\" link of exported HTML pages lead?"
1274 :group 'org-export-html
1275 :type '(string :tag "File or URL"))
1277 (defcustom org-html-link-use-abs-url nil
1278 "Should we prepend relative links with HTML_LINK_HOME?"
1279 :group 'org-export-html
1280 :version "24.4"
1281 :package-version '(Org . "8.1")
1282 :type 'boolean)
1284 (defcustom org-html-home/up-format
1285 "<div id=\"org-div-home-and-up\">
1286 <a accesskey=\"h\" href=\"%s\"> UP </a>
1288 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1289 </div>"
1290 "Snippet used to insert the HOME and UP links.
1291 This is a format string, the first %s will receive the UP link,
1292 the second the HOME link. If both `org-html-link-up' and
1293 `org-html-link-home' are empty, the entire snippet will be
1294 ignored."
1295 :group 'org-export-html
1296 :type 'string)
1298 ;;;; Template :: Scripts
1300 (define-obsolete-variable-alias
1301 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1302 (defcustom org-html-head-include-scripts t
1303 "Non-nil means include the JavaScript snippets in exported HTML files.
1304 The actual script is defined in `org-html-scripts' and should
1305 not be modified."
1306 :group 'org-export-html
1307 :version "24.4"
1308 :package-version '(Org . "8.0")
1309 :type 'boolean)
1311 ;;;; Template :: Styles
1313 (define-obsolete-variable-alias
1314 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1315 (defcustom org-html-head-include-default-style t
1316 "Non-nil means include the default style in exported HTML files.
1317 The actual style is defined in `org-html-style-default' and
1318 should not be modified. Use `org-html-head' to use your own
1319 style information."
1320 :group 'org-export-html
1321 :version "24.4"
1322 :package-version '(Org . "8.0")
1323 :type 'boolean)
1324 ;;;###autoload
1325 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1327 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1328 (defcustom org-html-head ""
1329 "Org-wide head definitions for exported HTML files.
1331 This variable can contain the full HTML structure to provide a
1332 style, including the surrounding HTML tags. You can consider
1333 including definitions for the following classes: title, todo,
1334 done, timestamp, timestamp-kwd, tag, target.
1336 For example, a valid value would be:
1338 <style type=\"text/css\">
1339 <![CDATA[
1340 p { font-weight: normal; color: gray; }
1341 h1 { color: black; }
1342 .title { text-align: center; }
1343 .todo, .timestamp-kwd { color: red; }
1344 .done { color: green; }
1346 </style>
1348 If you want to refer to an external style, use something like
1350 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1352 As the value of this option simply gets inserted into the HTML
1353 <head> header, you can use it to add any arbitrary text to the
1354 header.
1356 You can set this on a per-file basis using #+HTML_HEAD:,
1357 or for publication projects using the :html-head property."
1358 :group 'org-export-html
1359 :version "24.4"
1360 :package-version '(Org . "8.0")
1361 :type 'string)
1362 ;;;###autoload
1363 (put 'org-html-head 'safe-local-variable 'stringp)
1365 (defcustom org-html-head-extra ""
1366 "More head information to add in the HTML output.
1368 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1369 or for publication projects using the :html-head-extra property."
1370 :group 'org-export-html
1371 :version "24.4"
1372 :package-version '(Org . "8.0")
1373 :type 'string)
1374 ;;;###autoload
1375 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1377 ;;;; Todos
1379 (defcustom org-html-todo-kwd-class-prefix ""
1380 "Prefix to class names for TODO keywords.
1381 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1382 The default prefix is empty because it is nice to just use the keyword
1383 as a class name. But if you get into conflicts with other, existing
1384 CSS classes, then this prefix can be very useful."
1385 :group 'org-export-html
1386 :type 'string)
1389 ;;; Internal Functions
1391 (defun org-html-xhtml-p (info)
1392 (let ((dt (downcase (plist-get info :html-doctype))))
1393 (string-match-p "xhtml" dt)))
1395 (defun org-html-html5-p (info)
1396 (let ((dt (downcase (plist-get info :html-doctype))))
1397 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1399 (defun org-html-close-tag (tag attr info)
1400 (concat "<" tag " " attr
1401 (if (org-html-xhtml-p info) " />" ">")))
1403 (defun org-html-doctype (info)
1404 "Return correct html doctype tag from `org-html-doctype-alist',
1405 or the literal value of :html-doctype from INFO if :html-doctype
1406 is not found in the alist.
1407 INFO is a plist used as a communication channel."
1408 (let ((dt (plist-get info :html-doctype)))
1409 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1411 (defun org-html--make-attribute-string (attributes)
1412 "Return a list of attributes, as a string.
1413 ATTRIBUTES is a plist where values are either strings or nil. An
1414 attributes with a nil value will be omitted from the result."
1415 (let (output)
1416 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1417 (cond ((null item) (pop output))
1418 ((symbolp item) (push (substring (symbol-name item) 1) output))
1419 (t (let ((key (car output))
1420 (value (replace-regexp-in-string
1421 "\"" "&quot;" (org-html-encode-plain-text item))))
1422 (setcar output (format "%s=\"%s\"" key value))))))))
1424 (defun org-html--wrap-image (contents info &optional caption label)
1425 "Wrap CONTENTS string within an appropriate environment for images.
1426 INFO is a plist used as a communication channel. When optional
1427 arguments CAPTION and LABEL are given, use them for caption and
1428 \"id\" attribute."
1429 (let ((html5-fancy (and (org-html-html5-p info)
1430 (plist-get info :html-html5-fancy))))
1431 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1432 "\n<div%s class=\"figure\">%s%s\n</div>")
1433 ;; ID.
1434 (if (not (org-string-nw-p label)) ""
1435 (format " id=\"%s\"" (org-export-solidify-link-text label)))
1436 ;; Contents.
1437 (format "\n<p>%s</p>" contents)
1438 ;; Caption.
1439 (if (not (org-string-nw-p caption)) ""
1440 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1441 "\n<p>%s</p>")
1442 caption)))))
1444 (defun org-html--format-image (source attributes info)
1445 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1446 SOURCE is a string specifying the location of the image.
1447 ATTRIBUTES is a plist, as returned by
1448 `org-export-read-attribute'. INFO is a plist used as
1449 a communication channel."
1450 (if (string= "svg" (file-name-extension source))
1451 (org-html--svg-image source attributes info)
1452 (org-html-close-tag
1453 "img"
1454 (org-html--make-attribute-string
1455 (org-combine-plists
1456 (list :src source
1457 :alt (if (string-match-p "^ltxpng/" source)
1458 (org-html-encode-plain-text
1459 (org-find-text-property-in-string 'org-latex-src source))
1460 (file-name-nondirectory source)))
1461 attributes))
1462 info)))
1464 (defun org-html--svg-image (source attributes info)
1465 "Return \"object\" appropriate for embedding svg file SOURCE
1466 with assoicated ATTRIBUTES. INFO is a plist used as a
1467 communication channel.
1469 The special attribute \"fallback\" can be used to specify a fallback
1470 image file to use if the object embedding is not supported."
1471 (let ((fallback (plist-get attributes :fallback))
1472 (attrs (org-html--make-attribute-string
1473 (plist-put attributes :fallback nil))))
1474 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1475 source attrs
1476 (if fallback
1477 (org-html-close-tag
1478 "img" (format "src=\"%s\" %s" fallback attrs) info)
1479 "Sorry, your browser does not support SVG."))))
1481 (defun org-html--textarea-block (element)
1482 "Transcode ELEMENT into a textarea block.
1483 ELEMENT is either a src block or an example block."
1484 (let* ((code (car (org-export-unravel-code element)))
1485 (attr (org-export-read-attribute :attr_html element)))
1486 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1487 (or (plist-get attr :width) 80)
1488 (or (plist-get attr :height) (org-count-lines code))
1489 code)))
1491 (defun org-html--has-caption-p (element &optional info)
1492 "Non-nil when ELEMENT has a caption affiliated keyword.
1493 INFO is a plist used as a communication channel. This function
1494 is meant to be used as a predicate for `org-export-get-ordinal' or
1495 a value to `org-html-standalone-image-predicate'."
1496 (org-element-property :caption element))
1498 ;;;; Table
1500 (defun org-html-htmlize-region-for-paste (beg end)
1501 "Convert the region between BEG and END to HTML, using htmlize.el.
1502 This is much like `htmlize-region-for-paste', only that it uses
1503 the settings define in the org-... variables."
1504 (let* ((htmlize-output-type org-html-htmlize-output-type)
1505 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1506 (htmlbuf (htmlize-region beg end)))
1507 (unwind-protect
1508 (with-current-buffer htmlbuf
1509 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1510 (plist-get htmlize-buffer-places 'content-end)))
1511 (kill-buffer htmlbuf))))
1513 ;;;###autoload
1514 (defun org-html-htmlize-generate-css ()
1515 "Create the CSS for all font definitions in the current Emacs session.
1516 Use this to create face definitions in your CSS style file that can then
1517 be used by code snippets transformed by htmlize.
1518 This command just produces a buffer that contains class definitions for all
1519 faces used in the current Emacs session. You can copy and paste the ones you
1520 need into your CSS file.
1522 If you then set `org-html-htmlize-output-type' to `css', calls
1523 to the function `org-html-htmlize-region-for-paste' will
1524 produce code that uses these same face definitions."
1525 (interactive)
1526 (require 'htmlize)
1527 (and (get-buffer "*html*") (kill-buffer "*html*"))
1528 (with-temp-buffer
1529 (let ((fl (face-list))
1530 (htmlize-css-name-prefix "org-")
1531 (htmlize-output-type 'css)
1532 f i)
1533 (while (setq f (pop fl)
1534 i (and f (face-attribute f :inherit)))
1535 (when (and (symbolp f) (or (not i) (not (listp i))))
1536 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1537 (htmlize-region (point-min) (point-max))))
1538 (org-pop-to-buffer-same-window "*html*")
1539 (goto-char (point-min))
1540 (if (re-search-forward "<style" nil t)
1541 (delete-region (point-min) (match-beginning 0)))
1542 (if (re-search-forward "</style>" nil t)
1543 (delete-region (1+ (match-end 0)) (point-max)))
1544 (beginning-of-line 1)
1545 (if (looking-at " +") (replace-match ""))
1546 (goto-char (point-min)))
1548 (defun org-html--make-string (n string)
1549 "Build a string by concatenating N times STRING."
1550 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1552 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1553 "Turn todo keyword KWD into a valid class name.
1554 Replaces invalid characters with \"_\"."
1555 (save-match-data
1556 (while (string-match "[^a-zA-Z0-9_]" kwd)
1557 (setq kwd (replace-match "_" t t kwd))))
1558 kwd)
1560 (defun org-html-footnote-section (info)
1561 "Format the footnote section.
1562 INFO is a plist used as a communication channel."
1563 (let* ((fn-alist (org-export-collect-footnote-definitions
1564 (plist-get info :parse-tree) info))
1565 (fn-alist
1566 (loop for (n type raw) in fn-alist collect
1567 (cons n (if (eq (org-element-type raw) 'org-data)
1568 (org-trim (org-export-data raw info))
1569 (format "<p>%s</p>"
1570 (org-trim (org-export-data raw info))))))))
1571 (when fn-alist
1572 (format
1573 (plist-get info :html-footnotes-section)
1574 (org-html--translate "Footnotes" info)
1575 (format
1576 "\n%s\n"
1577 (mapconcat
1578 (lambda (fn)
1579 (let ((n (car fn)) (def (cdr fn)))
1580 (format
1581 "<div class=\"footdef\">%s %s</div>\n"
1582 (format
1583 (plist-get info :html-footnote-format)
1584 (org-html--anchor
1585 (format "fn.%d" n)
1587 (format " class=\"footnum\" href=\"#fnr.%d\"" n)
1588 info))
1589 def)))
1590 fn-alist
1591 "\n"))))))
1594 ;;; Template
1596 (defun org-html--build-meta-info (info)
1597 "Return meta tags for exported document.
1598 INFO is a plist used as a communication channel."
1599 (let ((protect-string
1600 (lambda (str)
1601 (replace-regexp-in-string
1602 "\"" "&quot;" (org-html-encode-plain-text str))))
1603 (title (org-export-data (plist-get info :title) info))
1604 (author (and (plist-get info :with-author)
1605 (let ((auth (plist-get info :author)))
1606 (and auth
1607 ;; Return raw Org syntax, skipping non
1608 ;; exportable objects.
1609 (org-element-interpret-data
1610 (org-element-map auth
1611 (cons 'plain-text org-element-all-objects)
1612 'identity info))))))
1613 (description (plist-get info :description))
1614 (keywords (plist-get info :keywords))
1615 (charset (or (and org-html-coding-system
1616 (fboundp 'coding-system-get)
1617 (coding-system-get org-html-coding-system
1618 'mime-charset))
1619 "iso-8859-1")))
1620 (concat
1621 (format "<title>%s</title>\n" title)
1622 (when (plist-get info :time-stamp-file)
1623 (format-time-string
1624 (concat "<!-- "
1625 (plist-get info :html-metadata-timestamp-format)
1626 " -->\n")))
1627 (format
1628 (if (org-html-html5-p info)
1629 (org-html-close-tag "meta" " charset=\"%s\"" info)
1630 (org-html-close-tag
1631 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1632 info))
1633 charset) "\n"
1634 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1635 "\n"
1636 (and (org-string-nw-p author)
1637 (concat
1638 (org-html-close-tag "meta"
1639 (format " name=\"author\" content=\"%s\""
1640 (funcall protect-string author))
1641 info)
1642 "\n"))
1643 (and (org-string-nw-p description)
1644 (concat
1645 (org-html-close-tag "meta"
1646 (format " name=\"description\" content=\"%s\"\n"
1647 (funcall protect-string description))
1648 info)
1649 "\n"))
1650 (and (org-string-nw-p keywords)
1651 (concat
1652 (org-html-close-tag "meta"
1653 (format " name=\"keywords\" content=\"%s\""
1654 (funcall protect-string keywords))
1655 info)
1656 "\n")))))
1658 (defun org-html--build-head (info)
1659 "Return information for the <head>..</head> of the HTML output.
1660 INFO is a plist used as a communication channel."
1661 (org-element-normalize-string
1662 (concat
1663 (when (plist-get info :html-head-include-default-style)
1664 (org-element-normalize-string org-html-style-default))
1665 (org-element-normalize-string (plist-get info :html-head))
1666 (org-element-normalize-string (plist-get info :html-head-extra))
1667 (when (and (plist-get info :html-htmlized-css-url)
1668 (eq org-html-htmlize-output-type 'css))
1669 (org-html-close-tag "link"
1670 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1671 (plist-get info :html-htmlized-css-url))
1672 info))
1673 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1675 (defun org-html--build-mathjax-config (info)
1676 "Insert the user setup into the mathjax template.
1677 INFO is a plist used as a communication channel."
1678 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1679 (org-element-map (plist-get info :parse-tree)
1680 '(latex-fragment latex-environment) 'identity info t))
1681 (let ((template (plist-get info :html-mathjax-template))
1682 (options (plist-get info :html-mathjax-options))
1683 (in-buffer (or (plist-get info :html-mathjax) ""))
1684 name val (yes " ") (no "// ") x)
1685 (mapc
1686 (lambda (e)
1687 (setq name (car e) val (nth 1 e))
1688 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1689 (setq val (car (read-from-string
1690 (substring in-buffer (match-end 0))))))
1691 (if (not (stringp val)) (setq val (format "%s" val)))
1692 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1693 (setq template (replace-match val t t template))))
1694 options)
1695 (setq val (nth 1 (assq 'mathml options)))
1696 (if (string-match (concat "\\<mathml:") in-buffer)
1697 (setq val (car (read-from-string
1698 (substring in-buffer (match-end 0))))))
1699 ;; Exchange prefixes depending on mathml setting.
1700 (if (not val) (setq x yes yes no no x))
1701 ;; Replace cookies to turn on or off the config/jax lines.
1702 (if (string-match ":MMLYES:" template)
1703 (setq template (replace-match yes t t template)))
1704 (if (string-match ":MMLNO:" template)
1705 (setq template (replace-match no t t template)))
1706 ;; Return the modified template.
1707 (org-element-normalize-string template))))
1709 (defun org-html-format-spec (info)
1710 "Return format specification for elements that can be
1711 used in the preamble or postamble."
1712 `((?t . ,(org-export-data (plist-get info :title) info))
1713 (?d . ,(org-export-data (org-export-get-date info) info))
1714 (?T . ,(format-time-string
1715 (plist-get info :html-metadata-timestamp-format)))
1716 (?a . ,(org-export-data (plist-get info :author) info))
1717 (?e . ,(mapconcat
1718 (lambda (e)
1719 (format "<a href=\"mailto:%s\">%s</a>" e e))
1720 (split-string (plist-get info :email) ",+ *")
1721 ", "))
1722 (?c . ,(plist-get info :creator))
1723 (?C . ,(let ((file (plist-get info :input-file)))
1724 (format-time-string
1725 (plist-get info :html-metadata-timestamp-format)
1726 (if file (nth 5 (file-attributes file)) (current-time)))))
1727 (?v . ,(or (plist-get info :html-validation-link) ""))))
1729 (defun org-html--build-pre/postamble (type info)
1730 "Return document preamble or postamble as a string, or nil.
1731 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1732 communication channel."
1733 (let ((section (plist-get info (intern (format ":html-%s" type))))
1734 (spec (org-html-format-spec info)))
1735 (when section
1736 (let ((section-contents
1737 (if (functionp section) (funcall section info)
1738 (cond
1739 ((stringp section) (format-spec section spec))
1740 ((eq section 'auto)
1741 (let ((date (cdr (assq ?d spec)))
1742 (author (cdr (assq ?a spec)))
1743 (email (cdr (assq ?e spec)))
1744 (creator (cdr (assq ?c spec)))
1745 (timestamp (cdr (assq ?T spec)))
1746 (validation-link (cdr (assq ?v spec))))
1747 (concat
1748 (when (and (plist-get info :with-date)
1749 (org-string-nw-p date))
1750 (format "<p class=\"date\">%s: %s</p>\n"
1751 (org-html--translate "Date" info)
1752 date))
1753 (when (and (plist-get info :with-author)
1754 (org-string-nw-p author))
1755 (format "<p class=\"author\">%s: %s</p>\n"
1756 (org-html--translate "Author" info)
1757 author))
1758 (when (and (plist-get info :with-email)
1759 (org-string-nw-p email))
1760 (format "<p class=\"email\">%s: %s</p>\n"
1761 (org-html--translate "Email" info)
1762 email))
1763 (when (plist-get info :time-stamp-file)
1764 (format
1765 "<p class=\"date\">%s: %s</p>\n"
1766 (org-html--translate "Created" info)
1767 (format-time-string
1768 (plist-get info :html-metadata-timestamp-format))))
1769 (when (plist-get info :with-creator)
1770 (format "<p class=\"creator\">%s</p>\n" creator))
1771 (format "<p class=\"validation\">%s</p>\n"
1772 validation-link))))
1773 (t (format-spec
1774 (or (cadr (assoc
1775 (plist-get info :language)
1776 (eval (intern
1777 (format "org-html-%s-format" type)))))
1778 (cadr
1779 (assoc
1780 "en"
1781 (eval
1782 (intern (format "org-html-%s-format" type))))))
1783 spec))))))
1784 (let ((div (assq type (plist-get info :html-divs))))
1785 (when (org-string-nw-p section-contents)
1786 (concat
1787 (format "<%s id=\"%s\" class=\"%s\">\n"
1788 (nth 1 div)
1789 (nth 2 div)
1790 org-html--pre/postamble-class)
1791 (org-element-normalize-string section-contents)
1792 (format "</%s>\n" (nth 1 div)))))))))
1794 (defun org-html-inner-template (contents info)
1795 "Return body of document string after HTML conversion.
1796 CONTENTS is the transcoded contents string. INFO is a plist
1797 holding export options."
1798 (concat
1799 ;; Table of contents.
1800 (let ((depth (plist-get info :with-toc)))
1801 (when depth (org-html-toc depth info)))
1802 ;; Document contents.
1803 contents
1804 ;; Footnotes section.
1805 (org-html-footnote-section info)))
1807 (defun org-html-template (contents info)
1808 "Return complete document string after HTML conversion.
1809 CONTENTS is the transcoded contents string. INFO is a plist
1810 holding export options."
1811 (concat
1812 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1813 (let* ((xml-declaration (plist-get info :html-xml-declaration))
1814 (decl (or (and (stringp xml-declaration) xml-declaration)
1815 (cdr (assoc (plist-get info :html-extension)
1816 xml-declaration))
1817 (cdr (assoc "html" xml-declaration))
1818 "")))
1819 (when (not (or (not decl) (string= "" decl)))
1820 (format "%s\n"
1821 (format decl
1822 (or (and org-html-coding-system
1823 (fboundp 'coding-system-get)
1824 (coding-system-get org-html-coding-system 'mime-charset))
1825 "iso-8859-1"))))))
1826 (org-html-doctype info)
1827 "\n"
1828 (concat "<html"
1829 (when (org-html-xhtml-p info)
1830 (format
1831 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1832 (plist-get info :language) (plist-get info :language)))
1833 ">\n")
1834 "<head>\n"
1835 (org-html--build-meta-info info)
1836 (org-html--build-head info)
1837 (org-html--build-mathjax-config info)
1838 "</head>\n"
1839 "<body>\n"
1840 (let ((link-up (org-trim (plist-get info :html-link-up)))
1841 (link-home (org-trim (plist-get info :html-link-home))))
1842 (unless (and (string= link-up "") (string= link-home ""))
1843 (format (plist-get info :html-home/up-format)
1844 (or link-up link-home)
1845 (or link-home link-up))))
1846 ;; Preamble.
1847 (org-html--build-pre/postamble 'preamble info)
1848 ;; Document contents.
1849 (let ((div (assq 'content (plist-get info :html-divs))))
1850 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
1851 ;; Document title.
1852 (let ((title (plist-get info :title)))
1853 (format "<h1 class=\"title\">%s</h1>\n"
1854 (org-export-data (or title "") info)))
1855 contents
1856 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
1857 ;; Postamble.
1858 (org-html--build-pre/postamble 'postamble info)
1859 ;; Closing document.
1860 "</body>\n</html>"))
1862 (defun org-html--translate (s info)
1863 "Translate string S according to specified language.
1864 INFO is a plist used as a communication channel."
1865 (org-export-translate s :html info))
1867 ;;;; Anchor
1869 (defun org-html--anchor (id desc attributes info)
1870 "Format a HTML anchor."
1871 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
1872 (attributes (concat (and id (format " id=\"%s\"" id))
1873 (and name (format " name=\"%s\"" name))
1874 attributes)))
1875 (format "<a%s>%s</a>" attributes (or desc ""))))
1877 ;;;; Todo
1879 (defun org-html--todo (todo info)
1880 "Format TODO keywords into HTML."
1881 (when todo
1882 (format "<span class=\"%s %s%s\">%s</span>"
1883 (if (member todo org-done-keywords) "done" "todo")
1884 (plist-get info :html-todo-kwd-class-prefix)
1885 (org-html-fix-class-name todo)
1886 todo)))
1888 ;;;; Tags
1890 (defun org-html--tags (tags info)
1891 "Format TAGS into HTML.
1892 INFO is a plist containing export options."
1893 (when tags
1894 (format "<span class=\"tag\">%s</span>"
1895 (mapconcat
1896 (lambda (tag)
1897 (format "<span class=\"%s\">%s</span>"
1898 (concat (plist-get info :html-tag-class-prefix)
1899 (org-html-fix-class-name tag))
1900 tag))
1901 tags "&#xa0;"))))
1903 ;;;; Src Code
1905 (defun org-html-fontify-code (code lang)
1906 "Color CODE with htmlize library.
1907 CODE is a string representing the source code to colorize. LANG
1908 is the language used for CODE, as a string, or nil."
1909 (when code
1910 (cond
1911 ;; Case 1: No lang. Possibly an example block.
1912 ((not lang)
1913 ;; Simple transcoding.
1914 (org-html-encode-plain-text code))
1915 ;; Case 2: No htmlize or an inferior version of htmlize
1916 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1917 ;; Emit a warning.
1918 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1919 ;; Simple transcoding.
1920 (org-html-encode-plain-text code))
1921 ;; Case 3: plain text explicitly set
1922 ((not org-html-htmlize-output-type)
1923 ;; Simple transcoding.
1924 (org-html-encode-plain-text code))
1926 ;; Map language
1927 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1928 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1929 (cond
1930 ;; Case 1: Language is not associated with any Emacs mode
1931 ((not (functionp lang-mode))
1932 ;; Simple transcoding.
1933 (org-html-encode-plain-text code))
1934 ;; Case 2: Default. Fontify code.
1936 ;; htmlize
1937 (setq code (with-temp-buffer
1938 ;; Switch to language-specific mode.
1939 (funcall lang-mode)
1940 ;; Disable fci-mode if present
1941 (when (and (fboundp 'fci-mode)
1942 (require 'fill-column-indicator nil 'noerror))
1943 (fci-mode -1))
1944 (insert code)
1945 ;; Fontify buffer.
1946 (font-lock-ensure)
1947 ;; Remove formatting on newline characters.
1948 (save-excursion
1949 (let ((beg (point-min))
1950 (end (point-max)))
1951 (goto-char beg)
1952 (while (progn (end-of-line) (< (point) end))
1953 (put-text-property (point) (1+ (point)) 'face nil)
1954 (forward-char 1))))
1955 (org-src-mode)
1956 (set-buffer-modified-p nil)
1957 ;; Htmlize region.
1958 (org-html-htmlize-region-for-paste
1959 (point-min) (point-max))))
1960 ;; Strip any enclosing <pre></pre> tags.
1961 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1962 (end (and beg (string-match "</pre>\\'" code))))
1963 (if (and beg end) (substring code beg end) code)))))))))
1965 (defun org-html-do-format-code
1966 (code &optional lang refs retain-labels num-start)
1967 "Format CODE string as source code.
1968 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1969 respectively, the language of the source code, as a string, an
1970 alist between line numbers and references (as returned by
1971 `org-export-unravel-code'), a boolean specifying if labels should
1972 appear in the source code, and the number associated to the first
1973 line of code."
1974 (let* ((code-lines (org-split-string code "\n"))
1975 (code-length (length code-lines))
1976 (num-fmt
1977 (and num-start
1978 (format "%%%ds: "
1979 (length (number-to-string (+ code-length num-start))))))
1980 (code (org-html-fontify-code code lang)))
1981 (org-export-format-code
1982 code
1983 (lambda (loc line-num ref)
1984 (setq loc
1985 (concat
1986 ;; Add line number, if needed.
1987 (when num-start
1988 (format "<span class=\"linenr\">%s</span>"
1989 (format num-fmt line-num)))
1990 ;; Transcoded src line.
1992 ;; Add label, if needed.
1993 (when (and ref retain-labels) (format " (%s)" ref))))
1994 ;; Mark transcoded line as an anchor, if needed.
1995 (if (not ref) loc
1996 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1997 ref loc)))
1998 num-start refs)))
2000 (defun org-html-format-code (element info)
2001 "Format contents of ELEMENT as source code.
2002 ELEMENT is either an example block or a src block. INFO is
2003 a plist used as a communication channel."
2004 (let* ((lang (org-element-property :language element))
2005 ;; Extract code and references.
2006 (code-info (org-export-unravel-code element))
2007 (code (car code-info))
2008 (refs (cdr code-info))
2009 ;; Does the src block contain labels?
2010 (retain-labels (org-element-property :retain-labels element))
2011 ;; Does it have line numbers?
2012 (num-start (case (org-element-property :number-lines element)
2013 (continued (org-export-get-loc element info))
2014 (new 0))))
2015 (org-html-do-format-code code lang refs retain-labels num-start)))
2018 ;;; Tables of Contents
2020 (defun org-html-toc (depth info)
2021 "Build a table of contents.
2022 DEPTH is an integer specifying the depth of the table. INFO is a
2023 plist used as a communication channel. Return the table of
2024 contents as a string, or nil if it is empty."
2025 (let ((toc-entries
2026 (mapcar (lambda (headline)
2027 (cons (org-html--format-toc-headline headline info)
2028 (org-export-get-relative-level headline info)))
2029 (org-export-collect-headlines info depth)))
2030 (outer-tag (if (and (org-html-html5-p info)
2031 (plist-get info :html-html5-fancy))
2032 "nav"
2033 "div")))
2034 (when toc-entries
2035 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2036 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2037 (format "<h%d>%s</h%d>\n"
2038 top-level
2039 (org-html--translate "Table of Contents" info)
2040 top-level))
2041 "<div id=\"text-table-of-contents\">"
2042 (org-html--toc-text toc-entries)
2043 "</div>\n"
2044 (format "</%s>\n" outer-tag)))))
2046 (defun org-html--toc-text (toc-entries)
2047 "Return innards of a table of contents, as a string.
2048 TOC-ENTRIES is an alist where key is an entry title, as a string,
2049 and value is its relative level, as an integer."
2050 (let* ((prev-level (1- (cdar toc-entries)))
2051 (start-level prev-level))
2052 (concat
2053 (mapconcat
2054 (lambda (entry)
2055 (let ((headline (car entry))
2056 (level (cdr entry)))
2057 (concat
2058 (let* ((cnt (- level prev-level))
2059 (times (if (> cnt 0) (1- cnt) (- cnt)))
2060 rtn)
2061 (setq prev-level level)
2062 (concat
2063 (org-html--make-string
2064 times (cond ((> cnt 0) "\n<ul>\n<li>")
2065 ((< cnt 0) "</li>\n</ul>\n")))
2066 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2067 headline)))
2068 toc-entries "")
2069 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2071 (defun org-html--format-toc-headline (headline info)
2072 "Return an appropriate table of contents entry for HEADLINE.
2073 INFO is a plist used as a communication channel."
2074 (let* ((headline-number (org-export-get-headline-number headline info))
2075 (todo (and (plist-get info :with-todo-keywords)
2076 (let ((todo (org-element-property :todo-keyword headline)))
2077 (and todo (org-export-data todo info)))))
2078 (todo-type (and todo (org-element-property :todo-type headline)))
2079 (priority (and (plist-get info :with-priority)
2080 (org-element-property :priority headline)))
2081 (text (org-export-data-with-backend
2082 (org-export-get-alt-title headline info)
2083 ;; Create an anonymous back-end that will ignore any
2084 ;; footnote-reference, link, radio-target and target
2085 ;; in table of contents.
2086 (org-export-create-backend
2087 :parent 'html
2088 :transcoders '((footnote-reference . ignore)
2089 (link . (lambda (object c i) c))
2090 (radio-target . (lambda (object c i) c))
2091 (target . ignore)))
2092 info))
2093 (tags (and (eq (plist-get info :with-tags) t)
2094 (org-export-get-tags headline info))))
2095 (format "<a href=\"#%s\">%s</a>"
2096 ;; Label.
2097 (org-export-solidify-link-text
2098 (or (org-element-property :CUSTOM_ID headline)
2099 (org-export-get-headline-id headline info)))
2100 ;; Body.
2101 (concat
2102 (and (not (org-export-low-level-p headline info))
2103 (org-export-numbered-headline-p headline info)
2104 (concat (mapconcat #'number-to-string headline-number ".")
2105 ". "))
2106 (apply (plist-get info :html-format-headline-function)
2107 todo todo-type priority text tags :section-number nil)))))
2109 (defun org-html-list-of-listings (info)
2110 "Build a list of listings.
2111 INFO is a plist used as a communication channel. Return the list
2112 of listings as a string, or nil if it is empty."
2113 (let ((lol-entries (org-export-collect-listings info)))
2114 (when lol-entries
2115 (concat "<div id=\"list-of-listings\">\n"
2116 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2117 (format "<h%d>%s</h%d>\n"
2118 top-level
2119 (org-html--translate "List of Listings" info)
2120 top-level))
2121 "<div id=\"text-list-of-listings\">\n<ul>\n"
2122 (let ((count 0)
2123 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2124 (org-html--translate "Listing %d:" info))))
2125 (mapconcat
2126 (lambda (entry)
2127 (let ((label (org-element-property :name entry))
2128 (title (org-trim
2129 (org-export-data
2130 (or (org-export-get-caption entry t)
2131 (org-export-get-caption entry))
2132 info))))
2133 (concat
2134 "<li>"
2135 (if (not label)
2136 (concat (format initial-fmt (incf count)) " " title)
2137 (format "<a href=\"#%s\">%s %s</a>"
2138 (org-export-solidify-link-text label)
2139 (format initial-fmt (incf count))
2140 title))
2141 "</li>")))
2142 lol-entries "\n"))
2143 "\n</ul>\n</div>\n</div>"))))
2145 (defun org-html-list-of-tables (info)
2146 "Build a list of tables.
2147 INFO is a plist used as a communication channel. Return the list
2148 of tables as a string, or nil if it is empty."
2149 (let ((lol-entries (org-export-collect-tables info)))
2150 (when lol-entries
2151 (concat "<div id=\"list-of-tables\">\n"
2152 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2153 (format "<h%d>%s</h%d>\n"
2154 top-level
2155 (org-html--translate "List of Tables" info)
2156 top-level))
2157 "<div id=\"text-list-of-tables\">\n<ul>\n"
2158 (let ((count 0)
2159 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2160 (org-html--translate "Table %d:" info))))
2161 (mapconcat
2162 (lambda (entry)
2163 (let ((label (org-element-property :name entry))
2164 (title (org-trim
2165 (org-export-data
2166 (or (org-export-get-caption entry t)
2167 (org-export-get-caption entry))
2168 info))))
2169 (concat
2170 "<li>"
2171 (if (not label)
2172 (concat (format initial-fmt (incf count)) " " title)
2173 (format "<a href=\"#%s\">%s %s</a>"
2174 (org-export-solidify-link-text label)
2175 (format initial-fmt (incf count))
2176 title))
2177 "</li>")))
2178 lol-entries "\n"))
2179 "\n</ul>\n</div>\n</div>"))))
2182 ;;; Transcode Functions
2184 ;;;; Bold
2186 (defun org-html-bold (bold contents info)
2187 "Transcode BOLD from Org to HTML.
2188 CONTENTS is the text with bold markup. INFO is a plist holding
2189 contextual information."
2190 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2191 contents))
2193 ;;;; Center Block
2195 (defun org-html-center-block (center-block contents info)
2196 "Transcode a CENTER-BLOCK element from Org to HTML.
2197 CONTENTS holds the contents of the block. INFO is a plist
2198 holding contextual information."
2199 (format "<div class=\"center\">\n%s</div>" contents))
2201 ;;;; Clock
2203 (defun org-html-clock (clock contents info)
2204 "Transcode a CLOCK element from Org to HTML.
2205 CONTENTS is nil. INFO is a plist used as a communication
2206 channel."
2207 (format "<p>
2208 <span class=\"timestamp-wrapper\">
2209 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2210 </span>
2211 </p>"
2212 org-clock-string
2213 (org-translate-time
2214 (org-element-property :raw-value
2215 (org-element-property :value clock)))
2216 (let ((time (org-element-property :duration clock)))
2217 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2219 ;;;; Code
2221 (defun org-html-code (code contents info)
2222 "Transcode CODE from Org to HTML.
2223 CONTENTS is nil. INFO is a plist holding contextual
2224 information."
2225 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2226 (org-html-encode-plain-text (org-element-property :value code))))
2228 ;;;; Drawer
2230 (defun org-html-drawer (drawer contents info)
2231 "Transcode a DRAWER element from Org to HTML.
2232 CONTENTS holds the contents of the block. INFO is a plist
2233 holding contextual information."
2234 (funcall (plist-get info :html-format-drawer-function)
2235 (org-element-property :drawer-name drawer)
2236 contents))
2238 ;;;; Dynamic Block
2240 (defun org-html-dynamic-block (dynamic-block contents info)
2241 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2242 CONTENTS holds the contents of the block. INFO is a plist
2243 holding contextual information. See `org-export-data'."
2244 contents)
2246 ;;;; Entity
2248 (defun org-html-entity (entity contents info)
2249 "Transcode an ENTITY object from Org to HTML.
2250 CONTENTS are the definition itself. INFO is a plist holding
2251 contextual information."
2252 (org-element-property :html entity))
2254 ;;;; Example Block
2256 (defun org-html-example-block (example-block contents info)
2257 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2258 CONTENTS is nil. INFO is a plist holding contextual
2259 information."
2260 (if (org-export-read-attribute :attr_html example-block :textarea)
2261 (org-html--textarea-block example-block)
2262 (format "<pre class=\"example\">\n%s</pre>"
2263 (org-html-format-code example-block info))))
2265 ;;;; Export Snippet
2267 (defun org-html-export-snippet (export-snippet contents info)
2268 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2269 CONTENTS is nil. INFO is a plist holding contextual
2270 information."
2271 (when (eq (org-export-snippet-backend export-snippet) 'html)
2272 (org-element-property :value export-snippet)))
2274 ;;;; Export Block
2276 (defun org-html-export-block (export-block contents info)
2277 "Transcode a EXPORT-BLOCK element from Org to HTML.
2278 CONTENTS is nil. INFO is a plist holding contextual information."
2279 (when (string= (org-element-property :type export-block) "HTML")
2280 (org-remove-indentation (org-element-property :value export-block))))
2282 ;;;; Fixed Width
2284 (defun org-html-fixed-width (fixed-width contents info)
2285 "Transcode a FIXED-WIDTH element from Org to HTML.
2286 CONTENTS is nil. INFO is a plist holding contextual information."
2287 (format "<pre class=\"example\">\n%s</pre>"
2288 (org-html-do-format-code
2289 (org-remove-indentation
2290 (org-element-property :value fixed-width)))))
2292 ;;;; Footnote Reference
2294 (defun org-html-footnote-reference (footnote-reference contents info)
2295 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2296 CONTENTS is nil. INFO is a plist holding contextual information."
2297 (concat
2298 ;; Insert separator between two footnotes in a row.
2299 (let ((prev (org-export-get-previous-element footnote-reference info)))
2300 (when (eq (org-element-type prev) 'footnote-reference)
2301 (plist-get info :html-footnote-separator)))
2302 (let* ((n (org-export-get-footnote-number footnote-reference info))
2303 (id (format "fnr.%d%s"
2305 (if (org-export-footnote-first-reference-p
2306 footnote-reference info)
2308 ".100"))))
2309 (format
2310 (plist-get info :html-footnote-format)
2311 (org-html--anchor
2312 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2314 ;;;; Headline
2316 (defun org-html-headline (headline contents info)
2317 "Transcode a HEADLINE element from Org to HTML.
2318 CONTENTS holds the contents of the headline. INFO is a plist
2319 holding contextual information."
2320 (unless (org-element-property :footnote-section-p headline)
2321 (let* ((numberedp (org-export-numbered-headline-p headline info))
2322 (numbers (org-export-get-headline-number headline info))
2323 (section-number (and numbers
2324 (mapconcat #'number-to-string numbers "-")))
2325 (level (+ (org-export-get-relative-level headline info)
2326 (1- (plist-get info :html-toplevel-hlevel))))
2327 (todo (and (plist-get info :with-todo-keywords)
2328 (let ((todo (org-element-property :todo-keyword headline)))
2329 (and todo (org-export-data todo info)))))
2330 (todo-type (and todo (org-element-property :todo-type headline)))
2331 (priority (and (plist-get info :with-priority)
2332 (org-element-property :priority headline)))
2333 (text (org-export-data (org-element-property :title headline) info))
2334 (tags (and (plist-get info :with-tags)
2335 (org-export-get-tags headline info)))
2336 (full-text (funcall (plist-get info :html-format-headline-function)
2337 todo todo-type priority text tags info))
2338 (contents (or contents ""))
2339 (ids (delq nil
2340 (list (org-element-property :CUSTOM_ID headline)
2341 (org-export-get-headline-id headline info)
2342 (org-element-property :ID headline))))
2343 (preferred-id (car ids))
2344 (extra-ids (mapconcat
2345 (lambda (id)
2346 (org-html--anchor
2347 (org-export-solidify-link-text
2348 (if (org-uuidgen-p id) (concat "ID-" id) id))
2349 nil nil info))
2350 (cdr ids) "")))
2351 (if (org-export-low-level-p headline info)
2352 ;; This is a deep sub-tree: export it as a list item.
2353 (let* ((type (if numberedp 'ordered 'unordered))
2354 (itemized-body
2355 (org-html-format-list-item
2356 contents type nil info nil
2357 (concat (org-html--anchor preferred-id nil nil info)
2358 extra-ids
2359 full-text))))
2360 (concat (and (org-export-first-sibling-p headline info)
2361 (org-html-begin-plain-list type))
2362 itemized-body
2363 (and (org-export-last-sibling-p headline info)
2364 (org-html-end-plain-list type))))
2365 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2366 (first-content (car (org-element-contents headline))))
2367 ;; Standard headline. Export it as a section.
2368 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2369 (org-html--container headline info)
2370 (format "outline-container-%s"
2371 (or (org-element-property :CUSTOM_ID headline)
2372 (org-export-get-headline-id headline info)))
2373 (concat (format "outline-%d" level)
2374 (and extra-class " ")
2375 extra-class)
2376 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2377 level
2378 preferred-id
2379 extra-ids
2380 (concat
2381 (and numberedp
2382 (format
2383 "<span class=\"section-number-%d\">%s</span> "
2384 level
2385 (mapconcat #'number-to-string numbers ".")))
2386 full-text)
2387 level)
2388 ;; When there is no section, pretend there is an
2389 ;; empty one to get the correct <div
2390 ;; class="outline-...> which is needed by
2391 ;; `org-info.js'.
2392 (if (eq (org-element-type first-content) 'section) contents
2393 (concat (org-html-section first-content "" info) contents))
2394 (org-html--container headline info)))))))
2396 (defun org-html-format-headline-default-function
2397 (todo todo-type priority text tags info)
2398 "Default format function for a headline.
2399 See `org-html-format-headline-function' for details."
2400 (let ((todo (org-html--todo todo info))
2401 (tags (org-html--tags tags info)))
2402 (concat todo (and todo " ") text (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2404 (defun org-html--container (headline info)
2405 (or (org-element-property :HTML_CONTAINER headline)
2406 (if (= 1 (org-export-get-relative-level headline info))
2407 (plist-get info :html-container)
2408 "div")))
2410 ;;;; Horizontal Rule
2412 (defun org-html-horizontal-rule (horizontal-rule contents info)
2413 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2414 CONTENTS is nil. INFO is a plist holding contextual information."
2415 (org-html-close-tag "hr" nil info))
2417 ;;;; Inline Src Block
2419 (defun org-html-inline-src-block (inline-src-block contents info)
2420 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2421 CONTENTS holds the contents of the item. INFO is a plist holding
2422 contextual information."
2423 (let* ((org-lang (org-element-property :language inline-src-block))
2424 (code (org-element-property :value inline-src-block)))
2425 (let ((lang (org-element-property :language inline-src-block))
2426 (code (org-html-format-code inline-src-block info))
2427 (label (let ((lbl (org-element-property :name inline-src-block)))
2428 (if (not lbl) ""
2429 (format " id=\"%s\""
2430 (org-export-solidify-link-text lbl))))))
2431 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code))))
2433 ;;;; Inlinetask
2435 (defun org-html-inlinetask (inlinetask contents info)
2436 "Transcode an INLINETASK element from Org to HTML.
2437 CONTENTS holds the contents of the block. INFO is a plist
2438 holding contextual information."
2439 (let* ((todo (and (plist-get info :with-todo-keywords)
2440 (let ((todo (org-element-property :todo-keyword inlinetask)))
2441 (and todo (org-export-data todo info)))))
2442 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2443 (priority (and (plist-get info :with-priority)
2444 (org-element-property :priority inlinetask)))
2445 (text (org-export-data (org-element-property :title inlinetask) info))
2446 (tags (and (plist-get info :with-tags)
2447 (org-export-get-tags inlinetask info))))
2448 (funcall (plist-get info :html-format-inlinetask-function)
2449 todo todo-type priority text tags contents info)))
2451 (defun org-html-format-inlinetask-default-function
2452 (todo todo-type priority text tags contents info)
2453 "Default format function for a inlinetasks.
2454 See `org-html-format-inlinetask-function' for details."
2455 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2456 (org-html-format-headline-default-function
2457 todo todo-type priority text tags info)
2458 (org-html-close-tag "br" nil info)
2459 contents))
2461 ;;;; Italic
2463 (defun org-html-italic (italic contents info)
2464 "Transcode ITALIC from Org to HTML.
2465 CONTENTS is the text with italic markup. INFO is a plist holding
2466 contextual information."
2467 (format
2468 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2469 contents))
2471 ;;;; Item
2473 (defun org-html-checkbox (checkbox info)
2474 "Format CHECKBOX into HTML.
2475 INFO is a plist holding contextual information. See
2476 `org-html-checkbox-type' for customization options."
2477 (cdr (assq checkbox
2478 (cdr (assq (plist-get info :html-checkbox-type)
2479 org-html-checkbox-types)))))
2481 (defun org-html-format-list-item (contents type checkbox info
2482 &optional term-counter-id
2483 headline)
2484 "Format a list item into HTML."
2485 (let ((class (if checkbox
2486 (format " class=\"%s\""
2487 (symbol-name checkbox)) ""))
2488 (checkbox (concat (org-html-checkbox checkbox info)
2489 (and checkbox " ")))
2490 (br (org-html-close-tag "br" nil info)))
2491 (concat
2492 (case type
2493 (ordered
2494 (let* ((counter term-counter-id)
2495 (extra (if counter (format " value=\"%s\"" counter) "")))
2496 (concat
2497 (format "<li%s%s>" class extra)
2498 (when headline (concat headline br)))))
2499 (unordered
2500 (let* ((id term-counter-id)
2501 (extra (if id (format " id=\"%s\"" id) "")))
2502 (concat
2503 (format "<li%s%s>" class extra)
2504 (when headline (concat headline br)))))
2505 (descriptive
2506 (let* ((term term-counter-id))
2507 (setq term (or term "(no term)"))
2508 ;; Check-boxes in descriptive lists are associated to tag.
2509 (concat (format "<dt%s>%s</dt>"
2510 class (concat checkbox term))
2511 "<dd>"))))
2512 (unless (eq type 'descriptive) checkbox)
2513 contents
2514 (case type
2515 (ordered "</li>")
2516 (unordered "</li>")
2517 (descriptive "</dd>")))))
2519 (defun org-html-item (item contents info)
2520 "Transcode an ITEM element from Org to HTML.
2521 CONTENTS holds the contents of the item. INFO is a plist holding
2522 contextual information."
2523 (let* ((plain-list (org-export-get-parent item))
2524 (type (org-element-property :type plain-list))
2525 (counter (org-element-property :counter item))
2526 (checkbox (org-element-property :checkbox item))
2527 (tag (let ((tag (org-element-property :tag item)))
2528 (and tag (org-export-data tag info)))))
2529 (org-html-format-list-item
2530 contents type checkbox info (or tag counter))))
2532 ;;;; Keyword
2534 (defun org-html-keyword (keyword contents info)
2535 "Transcode a KEYWORD element from Org to HTML.
2536 CONTENTS is nil. INFO is a plist holding contextual information."
2537 (let ((key (org-element-property :key keyword))
2538 (value (org-element-property :value keyword)))
2539 (cond
2540 ((string= key "HTML") value)
2541 ((string= key "TOC")
2542 (let ((value (downcase value)))
2543 (cond
2544 ((string-match "\\<headlines\\>" value)
2545 (let ((depth (or (and (string-match "[0-9]+" value)
2546 (string-to-number (match-string 0 value)))
2547 (plist-get info :with-toc))))
2548 (org-html-toc depth info)))
2549 ((string= "listings" value) (org-html-list-of-listings info))
2550 ((string= "tables" value) (org-html-list-of-tables info))))))))
2552 ;;;; Latex Environment
2554 (defun org-html-format-latex (latex-frag processing-type info)
2555 "Format a LaTeX fragment LATEX-FRAG into HTML.
2556 PROCESSING-TYPE designates the tool used for conversion. It is
2557 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2558 and t. See `org-html-with-latex' for more information. INFO is
2559 a plist containing export properties."
2560 (let ((cache-relpath "") (cache-dir ""))
2561 (unless (eq processing-type 'mathjax)
2562 (let ((bfn (or (buffer-file-name)
2563 (make-temp-name
2564 (expand-file-name "latex" temporary-file-directory))))
2565 (latex-header
2566 (let ((header (plist-get info :latex-header)))
2567 (and header
2568 (concat (mapconcat
2569 (lambda (line) (concat "#+LATEX_HEADER: " line))
2570 (org-split-string header "\n")
2571 "\n")
2572 "\n")))))
2573 (setq cache-relpath
2574 (concat "ltxpng/"
2575 (file-name-sans-extension
2576 (file-name-nondirectory bfn)))
2577 cache-dir (file-name-directory bfn))
2578 ;; Re-create LaTeX environment from original buffer in
2579 ;; temporary buffer so that dvipng/imagemagick can properly
2580 ;; turn the fragment into an image.
2581 (setq latex-frag (concat latex-header latex-frag))))
2582 (with-temp-buffer
2583 (insert latex-frag)
2584 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2585 nil processing-type)
2586 (buffer-string))))
2588 (defun org-html-latex-environment (latex-environment contents info)
2589 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2590 CONTENTS is nil. INFO is a plist holding contextual information."
2591 (let ((processing-type (plist-get info :with-latex))
2592 (latex-frag (org-remove-indentation
2593 (org-element-property :value latex-environment)))
2594 (attributes (org-export-read-attribute :attr_html latex-environment)))
2595 (case processing-type
2596 ((t mathjax)
2597 (org-html-format-latex latex-frag 'mathjax info))
2598 ((dvipng imagemagick)
2599 (let ((formula-link
2600 (org-html-format-latex latex-frag processing-type info)))
2601 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2602 ;; Do not provide a caption or a name to be consistent with
2603 ;; `mathjax' handling.
2604 (org-html--wrap-image
2605 (org-html--format-image
2606 (match-string 1 formula-link) attributes info) info))))
2607 (t latex-frag))))
2609 ;;;; Latex Fragment
2611 (defun org-html-latex-fragment (latex-fragment contents info)
2612 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2613 CONTENTS is nil. INFO is a plist holding contextual information."
2614 (let ((latex-frag (org-element-property :value latex-fragment))
2615 (processing-type (plist-get info :with-latex)))
2616 (case processing-type
2617 ((t mathjax)
2618 (org-html-format-latex latex-frag 'mathjax info))
2619 ((dvipng imagemagick)
2620 (let ((formula-link
2621 (org-html-format-latex latex-frag processing-type info)))
2622 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2623 (org-html--format-image (match-string 1 formula-link) nil info))))
2624 (t latex-frag))))
2626 ;;;; Line Break
2628 (defun org-html-line-break (line-break contents info)
2629 "Transcode a LINE-BREAK object from Org to HTML.
2630 CONTENTS is nil. INFO is a plist holding contextual information."
2631 (concat (org-html-close-tag "br" nil info) "\n"))
2633 ;;;; Link
2635 (defun org-html-inline-image-p (link info)
2636 "Non-nil when LINK is meant to appear as an image.
2637 INFO is a plist used as a communication channel. LINK is an
2638 inline image when it has no description and targets an image
2639 file (see `org-html-inline-image-rules' for more information), or
2640 if its description is a single link targeting an image file."
2641 (if (not (org-element-contents link))
2642 (org-export-inline-image-p
2643 link (plist-get info :html-inline-image-rules))
2644 (not
2645 (let ((link-count 0))
2646 (org-element-map (org-element-contents link)
2647 (cons 'plain-text org-element-all-objects)
2648 (lambda (obj)
2649 (case (org-element-type obj)
2650 (plain-text (org-string-nw-p obj))
2651 (link (if (= link-count 1) t
2652 (incf link-count)
2653 (not (org-export-inline-image-p
2654 obj (plist-get info :html-inline-image-rules)))))
2655 (otherwise t)))
2656 info t)))))
2658 (defvar org-html-standalone-image-predicate)
2659 (defun org-html-standalone-image-p (element info)
2660 "Non-nil if ELEMENT is a standalone image.
2662 INFO is a plist holding contextual information.
2664 An element or object is a standalone image when
2666 - its type is `paragraph' and its sole content, save for white
2667 spaces, is a link that qualifies as an inline image;
2669 - its type is `link' and its containing paragraph has no other
2670 content save white spaces.
2672 Bind `org-html-standalone-image-predicate' to constrain paragraph
2673 further. For example, to check for only captioned standalone
2674 images, set it to:
2676 \(lambda (paragraph) (org-element-property :caption paragraph))"
2677 (let ((paragraph (case (org-element-type element)
2678 (paragraph element)
2679 (link (org-export-get-parent element)))))
2680 (and (eq (org-element-type paragraph) 'paragraph)
2681 (or (not (fboundp 'org-html-standalone-image-predicate))
2682 (funcall org-html-standalone-image-predicate paragraph))
2683 (catch 'exit
2684 (let ((link-count 0))
2685 (org-element-map (org-element-contents paragraph)
2686 (cons 'plain-text org-element-all-objects)
2687 #'(lambda (obj)
2688 (when (case (org-element-type obj)
2689 (plain-text (org-string-nw-p obj))
2690 (link (or (> (incf link-count) 1)
2691 (not (org-html-inline-image-p obj info))))
2692 (otherwise t))
2693 (throw 'exit nil)))
2694 info nil 'link)
2695 (= link-count 1))))))
2697 (defun org-html-link (link desc info)
2698 "Transcode a LINK object from Org to HTML.
2700 DESC is the description part of the link, or the empty string.
2701 INFO is a plist holding contextual information. See
2702 `org-export-data'."
2703 (let* ((home (when (plist-get info :html-link-home)
2704 (org-trim (plist-get info :html-link-home))))
2705 (use-abs-url (plist-get info :html-link-use-abs-url))
2706 (link-org-files-as-html-maybe
2707 (function
2708 (lambda (raw-path info)
2709 "Treat links to `file.org' as links to `file.html', if needed.
2710 See `org-html-link-org-files-as-html'."
2711 (cond
2712 ((and (plist-get info :html-link-org-files-as-html)
2713 (string= ".org"
2714 (downcase (file-name-extension raw-path "."))))
2715 (concat (file-name-sans-extension raw-path) "."
2716 (plist-get info :html-extension)))
2717 (t raw-path)))))
2718 (type (org-element-property :type link))
2719 (raw-path (org-element-property :path link))
2720 ;; Ensure DESC really exists, or set it to nil.
2721 (desc (org-string-nw-p desc))
2722 (path
2723 (cond
2724 ((member type '("http" "https" "ftp" "mailto"))
2725 (org-link-escape-browser
2726 (org-link-unescape (concat type ":" raw-path))))
2727 ((string= type "file")
2728 ;; Treat links to ".org" files as ".html", if needed.
2729 (setq raw-path
2730 (funcall link-org-files-as-html-maybe raw-path info))
2731 ;; If file path is absolute, prepend it with protocol
2732 ;; component - "file:".
2733 (cond
2734 ((file-name-absolute-p raw-path)
2735 (setq raw-path (concat "file:" raw-path)))
2736 ((and home use-abs-url)
2737 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2738 ;; Add search option, if any. A search option can be
2739 ;; relative to a custom-id or a headline title. Append
2740 ;; a hash sign to any unresolved option, as it might point
2741 ;; to a target.
2742 (let ((option (org-element-property :search-option link)))
2743 (cond ((not option) raw-path)
2744 ((eq (aref option 0) ?#) (concat raw-path option))
2746 (let ((destination
2747 (org-publish-resolve-external-fuzzy-link
2748 (org-element-property :path link) option)))
2749 (concat raw-path
2750 (if (not destination) (concat "#" option)
2751 (concat "#sec-"
2752 (mapconcat #'number-to-string
2753 destination "-")))))))))
2754 (t raw-path)))
2755 ;; Extract attributes from parent's paragraph. HACK: Only do
2756 ;; this for the first link in parent (inner image link for
2757 ;; inline images). This is needed as long as attributes
2758 ;; cannot be set on a per link basis.
2759 (attributes-plist
2760 (let* ((parent (org-export-get-parent-element link))
2761 (link (let ((container (org-export-get-parent link)))
2762 (if (and (eq (org-element-type container) 'link)
2763 (org-html-inline-image-p link info))
2764 container
2765 link))))
2766 (and (eq (org-element-map parent 'link 'identity info t) link)
2767 (org-export-read-attribute :attr_html parent))))
2768 (attributes
2769 (let ((attr (org-html--make-attribute-string attributes-plist)))
2770 (if (org-string-nw-p attr) (concat " " attr) "")))
2771 protocol)
2772 (cond
2773 ;; Image file.
2774 ((and (plist-get info :html-inline-images)
2775 (org-export-inline-image-p
2776 link (plist-get info :html-inline-image-rules)))
2777 (org-html--format-image path attributes-plist info))
2778 ;; Radio target: Transcode target's contents and use them as
2779 ;; link's description.
2780 ((string= type "radio")
2781 (let ((destination (org-export-resolve-radio-link link info)))
2782 (if (not destination) desc
2783 (format "<a href=\"#%s\"%s>%s</a>"
2784 (org-export-solidify-link-text
2785 (org-element-property :value destination))
2786 attributes desc))))
2787 ;; Links pointing to a headline: Find destination and build
2788 ;; appropriate referencing command.
2789 ((member type '("custom-id" "fuzzy" "id"))
2790 (let ((destination (if (string= type "fuzzy")
2791 (org-export-resolve-fuzzy-link link info)
2792 (org-export-resolve-id-link link info))))
2793 (case (org-element-type destination)
2794 ;; ID link points to an external file.
2795 (plain-text
2796 (let ((fragment (concat "ID-" path))
2797 ;; Treat links to ".org" files as ".html", if needed.
2798 (path (funcall link-org-files-as-html-maybe
2799 destination info)))
2800 (format "<a href=\"%s#%s\"%s>%s</a>"
2801 path fragment attributes (or desc destination))))
2802 ;; Fuzzy link points nowhere.
2803 ((nil)
2804 (format "<i>%s</i>"
2805 (or desc
2806 (org-export-data
2807 (org-element-property :raw-link link) info))))
2808 ;; Link points to a headline.
2809 (headline
2810 (let ((href (or (and (string= type "custom-id")
2811 (org-element-property :CUSTOM_ID destination))
2812 (org-export-get-headline-id destination info)))
2813 ;; What description to use?
2814 (desc
2815 ;; Case 1: Headline is numbered and LINK has no
2816 ;; description. Display section number.
2817 (if (and (org-export-numbered-headline-p destination info)
2818 (not desc))
2819 (mapconcat 'number-to-string
2820 (org-export-get-headline-number
2821 destination info) ".")
2822 ;; Case 2: Either the headline is un-numbered or
2823 ;; LINK has a custom description. Display LINK's
2824 ;; description or headline's title.
2825 (or desc (org-export-data (org-element-property
2826 :title destination) info)))))
2827 (format "<a href=\"#%s\"%s>%s</a>"
2828 (org-export-solidify-link-text href) attributes desc)))
2829 ;; Fuzzy link points to a target or an element.
2831 (let* ((path (org-export-solidify-link-text path))
2832 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2833 (number (cond
2834 (desc nil)
2835 ((org-html-standalone-image-p destination info)
2836 (org-export-get-ordinal
2837 (org-element-map destination 'link
2838 'identity info t)
2839 info 'link 'org-html-standalone-image-p))
2840 (t (org-export-get-ordinal
2841 destination info nil 'org-html--has-caption-p))))
2842 (desc (cond (desc)
2843 ((not number) "No description for this link")
2844 ((numberp number) (number-to-string number))
2845 (t (mapconcat 'number-to-string number ".")))))
2846 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2847 ;; Coderef: replace link with the reference name or the
2848 ;; equivalent line number.
2849 ((string= type "coderef")
2850 (let ((fragment (concat "coderef-" path)))
2851 (format "<a href=\"#%s\"%s%s>%s</a>"
2852 fragment
2853 (org-trim
2854 (format (concat "class=\"coderef\""
2855 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2856 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2857 fragment fragment))
2858 attributes
2859 (format (org-export-get-coderef-format path desc)
2860 (org-export-resolve-coderef path info)))))
2861 ;; Link type is handled by a special function.
2862 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2863 (funcall protocol (org-link-unescape path) desc 'html))
2864 ;; External link with a description part.
2865 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2866 ;; External link without a description part.
2867 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2868 ;; No path, only description. Try to do something useful.
2869 (t (format "<i>%s</i>" desc)))))
2871 ;;;; Node Property
2873 (defun org-html-node-property (node-property contents info)
2874 "Transcode a NODE-PROPERTY element from Org to HTML.
2875 CONTENTS is nil. INFO is a plist holding contextual
2876 information."
2877 (format "%s:%s"
2878 (org-element-property :key node-property)
2879 (let ((value (org-element-property :value node-property)))
2880 (if value (concat " " value) ""))))
2882 ;;;; Paragraph
2884 (defun org-html-paragraph (paragraph contents info)
2885 "Transcode a PARAGRAPH element from Org to HTML.
2886 CONTENTS is the contents of the paragraph, as a string. INFO is
2887 the plist used as a communication channel."
2888 (let* ((parent (org-export-get-parent paragraph))
2889 (parent-type (org-element-type parent))
2890 (style '((footnote-definition " class=\"footpara\"")))
2891 (attributes (org-html--make-attribute-string
2892 (org-export-read-attribute :attr_html paragraph)))
2893 (extra (or (cadr (assoc parent-type style)) "")))
2894 (cond
2895 ((and (eq parent-type 'item)
2896 (not (org-export-get-previous-element paragraph info))
2897 (let ((followers (org-export-get-next-element paragraph info 2)))
2898 (and (not (cdr followers))
2899 (memq (org-element-type (car followers)) '(nil plain-list)))))
2900 ;; First paragraph in an item has no tag if it is alone or
2901 ;; followed, at most, by a sub-list.
2902 contents)
2903 ((org-html-standalone-image-p paragraph info)
2904 ;; Standalone image.
2905 (let ((caption
2906 (let ((raw (org-export-data
2907 (org-export-get-caption paragraph) info))
2908 (org-html-standalone-image-predicate
2909 'org-html--has-caption-p))
2910 (if (not (org-string-nw-p raw)) raw
2911 (concat
2912 "<span class=\"figure-number\">"
2913 (format (org-html--translate "Figure %d:" info)
2914 (org-export-get-ordinal
2915 (org-element-map paragraph 'link
2916 'identity info t)
2917 info nil 'org-html-standalone-image-p))
2918 "</span> " raw))))
2919 (label (org-element-property :name paragraph)))
2920 (org-html--wrap-image contents info caption label)))
2921 ;; Regular paragraph.
2922 (t (format "<p%s%s>\n%s</p>"
2923 (if (org-string-nw-p attributes)
2924 (concat " " attributes) "")
2925 extra contents)))))
2927 ;;;; Plain List
2929 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2930 ;; the correct value for the item counter
2931 (defun org-html-begin-plain-list (type &optional arg1)
2932 "Insert the beginning of the HTML list depending on TYPE.
2933 When ARG1 is a string, use it as the start parameter for ordered
2934 lists."
2935 (case type
2936 (ordered
2937 (format "<ol class=\"org-ol\"%s>"
2938 (if arg1 (format " start=\"%d\"" arg1) "")))
2939 (unordered "<ul class=\"org-ul\">")
2940 (descriptive "<dl class=\"org-dl\">")))
2942 (defun org-html-end-plain-list (type)
2943 "Insert the end of the HTML list depending on TYPE."
2944 (case type
2945 (ordered "</ol>")
2946 (unordered "</ul>")
2947 (descriptive "</dl>")))
2949 (defun org-html-plain-list (plain-list contents info)
2950 "Transcode a PLAIN-LIST element from Org to HTML.
2951 CONTENTS is the contents of the list. INFO is a plist holding
2952 contextual information."
2953 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2954 (type (org-element-property :type plain-list)))
2955 (format "%s\n%s%s"
2956 (org-html-begin-plain-list type)
2957 contents (org-html-end-plain-list type))))
2959 ;;;; Plain Text
2961 (defun org-html-convert-special-strings (string)
2962 "Convert special characters in STRING to HTML."
2963 (let ((all org-html-special-string-regexps)
2964 e a re rpl start)
2965 (while (setq a (pop all))
2966 (setq re (car a) rpl (cdr a) start 0)
2967 (while (string-match re string start)
2968 (setq string (replace-match rpl t nil string))))
2969 string))
2971 (defun org-html-encode-plain-text (text)
2972 "Convert plain text characters from TEXT to HTML equivalent.
2973 Possible conversions are set in `org-html-protect-char-alist'."
2974 (mapc
2975 (lambda (pair)
2976 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2977 org-html-protect-char-alist)
2978 text)
2980 (defun org-html-plain-text (text info)
2981 "Transcode a TEXT string from Org to HTML.
2982 TEXT is the string to transcode. INFO is a plist holding
2983 contextual information."
2984 (let ((output text))
2985 ;; Protect following characters: <, >, &.
2986 (setq output (org-html-encode-plain-text output))
2987 ;; Handle smart quotes. Be sure to provide original string since
2988 ;; OUTPUT may have been modified.
2989 (when (plist-get info :with-smart-quotes)
2990 (setq output (org-export-activate-smart-quotes output :html info text)))
2991 ;; Handle special strings.
2992 (when (plist-get info :with-special-strings)
2993 (setq output (org-html-convert-special-strings output)))
2994 ;; Handle break preservation if required.
2995 (when (plist-get info :preserve-breaks)
2996 (setq output
2997 (replace-regexp-in-string
2998 "\\(\\\\\\\\\\)?[ \t]*\n"
2999 (concat (org-html-close-tag "br" nil info) "\n") output)))
3000 ;; Return value.
3001 output))
3004 ;; Planning
3006 (defun org-html-planning (planning contents info)
3007 "Transcode a PLANNING element from Org to HTML.
3008 CONTENTS is nil. INFO is a plist used as a communication
3009 channel."
3010 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
3011 (format
3012 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3013 (mapconcat
3014 'identity
3015 (delq nil
3016 (list
3017 (let ((closed (org-element-property :closed planning)))
3018 (when closed
3019 (format span-fmt org-closed-string
3020 (org-translate-time
3021 (org-element-property :raw-value closed)))))
3022 (let ((deadline (org-element-property :deadline planning)))
3023 (when deadline
3024 (format span-fmt org-deadline-string
3025 (org-translate-time
3026 (org-element-property :raw-value deadline)))))
3027 (let ((scheduled (org-element-property :scheduled planning)))
3028 (when scheduled
3029 (format span-fmt org-scheduled-string
3030 (org-translate-time
3031 (org-element-property :raw-value scheduled)))))))
3032 " "))))
3034 ;;;; Property Drawer
3036 (defun org-html-property-drawer (property-drawer contents info)
3037 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3038 CONTENTS holds the contents of the drawer. INFO is a plist
3039 holding contextual information."
3040 (and (org-string-nw-p contents)
3041 (format "<pre class=\"example\">\n%s</pre>" contents)))
3043 ;;;; Quote Block
3045 (defun org-html-quote-block (quote-block contents info)
3046 "Transcode a QUOTE-BLOCK element from Org to HTML.
3047 CONTENTS holds the contents of the block. INFO is a plist
3048 holding contextual information."
3049 (format "<blockquote>\n%s</blockquote>" contents))
3051 ;;;; Section
3053 (defun org-html-section (section contents info)
3054 "Transcode a SECTION element from Org to HTML.
3055 CONTENTS holds the contents of the section. INFO is a plist
3056 holding contextual information."
3057 (let ((parent (org-export-get-parent-headline section)))
3058 ;; Before first headline: no container, just return CONTENTS.
3059 (if (not parent) contents
3060 ;; Get div's class and id references.
3061 (let* ((class-num (+ (org-export-get-relative-level parent info)
3062 (1- (plist-get info :html-toplevel-hlevel))))
3063 (section-number
3064 (and (org-export-numbered-headline-p parent info)
3065 (mapconcat
3066 #'number-to-string
3067 (org-export-get-headline-number parent info) "-"))))
3068 ;; Build return value.
3069 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3070 class-num
3071 (or (org-element-property :CUSTOM_ID parent)
3072 section-number
3073 (org-export-get-headline-id parent info))
3074 contents)))))
3076 ;;;; Radio Target
3078 (defun org-html-radio-target (radio-target text info)
3079 "Transcode a RADIO-TARGET object from Org to HTML.
3080 TEXT is the text of the target. INFO is a plist holding
3081 contextual information."
3082 (let ((id (org-export-solidify-link-text
3083 (org-element-property :value radio-target))))
3084 (org-html--anchor id text nil info)))
3086 ;;;; Special Block
3088 (defun org-html-special-block (special-block contents info)
3089 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3090 CONTENTS holds the contents of the block. INFO is a plist
3091 holding contextual information."
3092 (let* ((block-type (org-element-property :type special-block))
3093 (contents (or contents ""))
3094 (html5-fancy (and (org-html-html5-p info)
3095 (plist-get info :html-html5-fancy)
3096 (member block-type org-html-html5-elements)))
3097 (attributes (org-export-read-attribute :attr_html special-block)))
3098 (unless html5-fancy
3099 (let ((class (plist-get attributes :class)))
3100 (setq attributes (plist-put attributes :class
3101 (if class (concat class " " block-type)
3102 block-type)))))
3103 (setq attributes (org-html--make-attribute-string attributes))
3104 (when (not (equal attributes ""))
3105 (setq attributes (concat " " attributes)))
3106 (if html5-fancy
3107 (format "<%s%s>\n%s</%s>" block-type attributes
3108 contents block-type)
3109 (format "<div%s>\n%s\n</div>" attributes contents))))
3111 ;;;; Src Block
3113 (defun org-html-src-block (src-block contents info)
3114 "Transcode a SRC-BLOCK element from Org to HTML.
3115 CONTENTS holds the contents of the item. INFO is a plist holding
3116 contextual information."
3117 (if (org-export-read-attribute :attr_html src-block :textarea)
3118 (org-html--textarea-block src-block)
3119 (let ((lang (org-element-property :language src-block))
3120 (caption (org-export-get-caption src-block))
3121 (code (org-html-format-code src-block info))
3122 (label (let ((lbl (org-element-property :name src-block)))
3123 (if (not lbl) ""
3124 (format " id=\"%s\""
3125 (org-export-solidify-link-text lbl))))))
3126 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3127 (format
3128 "<div class=\"org-src-container\">\n%s%s\n</div>"
3129 (if (not caption) ""
3130 (format "<label class=\"org-src-name\">%s</label>"
3131 (org-export-data caption info)))
3132 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3134 ;;;; Statistics Cookie
3136 (defun org-html-statistics-cookie (statistics-cookie contents info)
3137 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3138 CONTENTS is nil. INFO is a plist holding contextual information."
3139 (let ((cookie-value (org-element-property :value statistics-cookie)))
3140 (format "<code>%s</code>" cookie-value)))
3142 ;;;; Strike-Through
3144 (defun org-html-strike-through (strike-through contents info)
3145 "Transcode STRIKE-THROUGH from Org to HTML.
3146 CONTENTS is the text with strike-through markup. INFO is a plist
3147 holding contextual information."
3148 (format
3149 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3150 "%s")
3151 contents))
3153 ;;;; Subscript
3155 (defun org-html-subscript (subscript contents info)
3156 "Transcode a SUBSCRIPT object from Org to HTML.
3157 CONTENTS is the contents of the object. INFO is a plist holding
3158 contextual information."
3159 (format "<sub>%s</sub>" contents))
3161 ;;;; Superscript
3163 (defun org-html-superscript (superscript contents info)
3164 "Transcode a SUPERSCRIPT object from Org to HTML.
3165 CONTENTS is the contents of the object. INFO is a plist holding
3166 contextual information."
3167 (format "<sup>%s</sup>" contents))
3169 ;;;; Table Cell
3171 (defun org-html-table-cell (table-cell contents info)
3172 "Transcode a TABLE-CELL element from Org to HTML.
3173 CONTENTS is nil. INFO is a plist used as a communication
3174 channel."
3175 (let* ((table-row (org-export-get-parent table-cell))
3176 (table (org-export-get-parent-table table-cell))
3177 (cell-attrs
3178 (if (not (plist-get info :html-table-align-individual-fields)) ""
3179 (format (if (and (boundp 'org-html-format-table-no-css)
3180 org-html-format-table-no-css)
3181 " align=\"%s\"" " class=\"%s\"")
3182 (org-export-table-cell-alignment table-cell info)))))
3183 (when (or (not contents) (string= "" (org-trim contents)))
3184 (setq contents "&#xa0;"))
3185 (cond
3186 ((and (org-export-table-has-header-p table info)
3187 (= 1 (org-export-table-row-group table-row info)))
3188 (let ((header-tags (plist-get info :html-table-header-tags)))
3189 (concat "\n" (format (car header-tags) "col" cell-attrs)
3190 contents
3191 (cdr header-tags))))
3192 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3193 (zerop (cdr (org-export-table-cell-address table-cell info))))
3194 (let ((header-tags (plist-get info :html-table-header-tags)))
3195 (concat "\n" (format (car header-tags) "row" cell-attrs)
3196 contents
3197 (cdr header-tags))))
3198 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3199 (concat "\n" (format (car data-tags) cell-attrs)
3200 contents
3201 (cdr data-tags)))))))
3203 ;;;; Table Row
3205 (defun org-html-table-row (table-row contents info)
3206 "Transcode a TABLE-ROW element from Org to HTML.
3207 CONTENTS is the contents of the row. INFO is a plist used as a
3208 communication channel."
3209 ;; Rules are ignored since table separators are deduced from
3210 ;; borders of the current row.
3211 (when (eq (org-element-property :type table-row) 'standard)
3212 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3213 (row-number (org-export-table-row-number table-row info))
3214 (start-rowgroup-p
3215 (org-export-table-row-starts-rowgroup-p table-row info))
3216 (end-rowgroup-p
3217 (org-export-table-row-ends-rowgroup-p table-row info))
3218 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3219 ;; but should be set so that `org-html-table-row-tags' can
3220 ;; use them (see the docstring of this variable.)
3221 (top-row-p (and (equal start-rowgroup-p '(top))
3222 (equal end-rowgroup-p '(below top))))
3223 (bottom-row-p (and (equal start-rowgroup-p '(above))
3224 (equal end-rowgroup-p '(bottom above))))
3225 (rowgroup-tags
3226 (cond
3227 ;; Case 1: Row belongs to second or subsequent rowgroups.
3228 ((not (= 1 rowgroup-number))
3229 '("<tbody>" . "\n</tbody>"))
3230 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3231 ((org-export-table-has-header-p
3232 (org-export-get-parent-table table-row) info)
3233 '("<thead>" . "\n</thead>"))
3234 ;; Case 2: Row is from first and only row group.
3235 (t '("<tbody>" . "\n</tbody>")))))
3236 (concat
3237 ;; Begin a rowgroup?
3238 (when start-rowgroup-p (car rowgroup-tags))
3239 ;; Actual table row
3240 (concat "\n" (eval (car (plist-get info :html-table-row-tags)))
3241 contents
3242 "\n"
3243 (eval (cdr (plist-get info :html-table-row-tags))))
3244 ;; End a rowgroup?
3245 (when end-rowgroup-p (cdr rowgroup-tags))))))
3247 ;;;; Table
3249 (defun org-html-table-first-row-data-cells (table info)
3250 "Transcode the first row of TABLE.
3251 INFO is a plist used as a communication channel."
3252 (let ((table-row
3253 (org-element-map table 'table-row
3254 (lambda (row)
3255 (unless (eq (org-element-property :type row) 'rule) row))
3256 info 'first-match))
3257 (special-column-p (org-export-table-has-special-column-p table)))
3258 (if (not special-column-p) (org-element-contents table-row)
3259 (cdr (org-element-contents table-row)))))
3261 (defun org-html-table--table.el-table (table info)
3262 "Format table.el tables into HTML.
3263 INFO is a plist used as a communication channel."
3264 (when (eq (org-element-property :type table) 'table.el)
3265 (require 'table)
3266 (let ((outbuf (with-current-buffer
3267 (get-buffer-create "*org-export-table*")
3268 (erase-buffer) (current-buffer))))
3269 (with-temp-buffer
3270 (insert (org-element-property :value table))
3271 (goto-char 1)
3272 (re-search-forward "^[ \t]*|[^|]" nil t)
3273 (table-generate-source 'html outbuf))
3274 (with-current-buffer outbuf
3275 (prog1 (org-trim (buffer-string))
3276 (kill-buffer) )))))
3278 (defun org-html-table (table contents info)
3279 "Transcode a TABLE element from Org to HTML.
3280 CONTENTS is the contents of the table. INFO is a plist holding
3281 contextual information."
3282 (case (org-element-property :type table)
3283 ;; Case 1: table.el table. Convert it using appropriate tools.
3284 (table.el (org-html-table--table.el-table table info))
3285 ;; Case 2: Standard table.
3287 (let* ((label (org-element-property :name table))
3288 (caption (org-export-get-caption table))
3289 (number (org-export-get-ordinal
3290 table info nil 'org-html--has-caption-p))
3291 (attributes
3292 (org-html--make-attribute-string
3293 (org-combine-plists
3294 (and label (list :id (org-export-solidify-link-text label)))
3295 (and (not (org-html-html5-p info))
3296 (plist-get info :html-table-attributes))
3297 (org-export-read-attribute :attr_html table))))
3298 (alignspec
3299 (if (and (boundp 'org-html-format-table-no-css)
3300 org-html-format-table-no-css)
3301 "align=\"%s\"" "class=\"%s\""))
3302 (table-column-specs
3303 (function
3304 (lambda (table info)
3305 (mapconcat
3306 (lambda (table-cell)
3307 (let ((alignment (org-export-table-cell-alignment
3308 table-cell info)))
3309 (concat
3310 ;; Begin a colgroup?
3311 (when (org-export-table-cell-starts-colgroup-p
3312 table-cell info)
3313 "\n<colgroup>")
3314 ;; Add a column. Also specify it's alignment.
3315 (format "\n%s"
3316 (org-html-close-tag
3317 "col" (concat " " (format alignspec alignment)) info))
3318 ;; End a colgroup?
3319 (when (org-export-table-cell-ends-colgroup-p
3320 table-cell info)
3321 "\n</colgroup>"))))
3322 (org-html-table-first-row-data-cells table info) "\n")))))
3323 (format "<table%s>\n%s\n%s\n%s</table>"
3324 (if (equal attributes "") "" (concat " " attributes))
3325 (if (not caption) ""
3326 (format (if (plist-get info :html-table-caption-above)
3327 "<caption class=\"t-above\">%s</caption>"
3328 "<caption class=\"t-bottom\">%s</caption>")
3329 (concat
3330 "<span class=\"table-number\">"
3331 (format (org-html--translate "Table %d:" info) number)
3332 "</span> " (org-export-data caption info))))
3333 (funcall table-column-specs table info)
3334 contents)))))
3336 ;;;; Target
3338 (defun org-html-target (target contents info)
3339 "Transcode a TARGET object from Org to HTML.
3340 CONTENTS is nil. INFO is a plist holding contextual
3341 information."
3342 (let ((id (org-export-solidify-link-text
3343 (org-element-property :value target))))
3344 (org-html--anchor id nil nil info)))
3346 ;;;; Timestamp
3348 (defun org-html-timestamp (timestamp contents info)
3349 "Transcode a TIMESTAMP object from Org to HTML.
3350 CONTENTS is nil. INFO is a plist holding contextual
3351 information."
3352 (let ((value (org-html-plain-text
3353 (org-timestamp-translate timestamp) info)))
3354 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3355 (replace-regexp-in-string "--" "&#x2013;" value))))
3357 ;;;; Underline
3359 (defun org-html-underline (underline contents info)
3360 "Transcode UNDERLINE from Org to HTML.
3361 CONTENTS is the text with underline markup. INFO is a plist
3362 holding contextual information."
3363 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3364 "%s")
3365 contents))
3367 ;;;; Verbatim
3369 (defun org-html-verbatim (verbatim contents info)
3370 "Transcode VERBATIM from Org to HTML.
3371 CONTENTS is nil. INFO is a plist holding contextual
3372 information."
3373 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3374 (org-html-encode-plain-text (org-element-property :value verbatim))))
3376 ;;;; Verse Block
3378 (defun org-html-verse-block (verse-block contents info)
3379 "Transcode a VERSE-BLOCK element from Org to HTML.
3380 CONTENTS is verse block contents. INFO is a plist holding
3381 contextual information."
3382 ;; Replace each newline character with line break. Also replace
3383 ;; each blank line with a line break.
3384 (setq contents (replace-regexp-in-string
3385 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3386 (replace-regexp-in-string
3387 "\\(\\\\\\\\\\)?[ \t]*\n"
3388 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3389 ;; Replace each white space at beginning of a line with a
3390 ;; non-breaking space.
3391 (while (string-match "^[ \t]+" contents)
3392 (let* ((num-ws (length (match-string 0 contents)))
3393 (ws (let (out) (dotimes (i num-ws out)
3394 (setq out (concat out "&#xa0;"))))))
3395 (setq contents (replace-match ws nil t contents))))
3396 (format "<p class=\"verse\">\n%s</p>" contents))
3399 ;;; Filter Functions
3401 (defun org-html-final-function (contents backend info)
3402 "Filter to indent the HTML and convert HTML entities."
3403 (with-temp-buffer
3404 (insert contents)
3405 (set-auto-mode t)
3406 (if (plist-get info :html-indent)
3407 (indent-region (point-min) (point-max)))
3408 (when (plist-get info :html-use-unicode-chars)
3409 (require 'mm-url)
3410 (mm-url-decode-entities))
3411 (buffer-substring-no-properties (point-min) (point-max))))
3414 ;;; End-user functions
3416 ;;;###autoload
3417 (defun org-html-export-as-html
3418 (&optional async subtreep visible-only body-only ext-plist)
3419 "Export current buffer to an HTML buffer.
3421 If narrowing is active in the current buffer, only export its
3422 narrowed part.
3424 If a region is active, export that region.
3426 A non-nil optional argument ASYNC means the process should happen
3427 asynchronously. The resulting buffer should be accessible
3428 through the `org-export-stack' interface.
3430 When optional argument SUBTREEP is non-nil, export the sub-tree
3431 at point, extracting information from the headline properties
3432 first.
3434 When optional argument VISIBLE-ONLY is non-nil, don't export
3435 contents of hidden elements.
3437 When optional argument BODY-ONLY is non-nil, only write code
3438 between \"<body>\" and \"</body>\" tags.
3440 EXT-PLIST, when provided, is a property list with external
3441 parameters overriding Org default settings, but still inferior to
3442 file-local settings.
3444 Export is done in a buffer named \"*Org HTML Export*\", which
3445 will be displayed when `org-export-show-temporary-export-buffer'
3446 is non-nil."
3447 (interactive)
3448 (org-export-to-buffer 'html "*Org HTML Export*"
3449 async subtreep visible-only body-only ext-plist
3450 (lambda () (set-auto-mode t))))
3452 ;;;###autoload
3453 (defun org-html-convert-region-to-html ()
3454 "Assume the current region has org-mode syntax, and convert it to HTML.
3455 This can be used in any buffer. For example, you can write an
3456 itemized list in org-mode syntax in an HTML buffer and use this
3457 command to convert it."
3458 (interactive)
3459 (org-export-replace-region-by 'html))
3461 ;;;###autoload
3462 (defun org-html-export-to-html
3463 (&optional async subtreep visible-only body-only ext-plist)
3464 "Export current buffer to a HTML file.
3466 If narrowing is active in the current buffer, only export its
3467 narrowed part.
3469 If a region is active, export that region.
3471 A non-nil optional argument ASYNC means the process should happen
3472 asynchronously. The resulting file should be accessible through
3473 the `org-export-stack' interface.
3475 When optional argument SUBTREEP is non-nil, export the sub-tree
3476 at point, extracting information from the headline properties
3477 first.
3479 When optional argument VISIBLE-ONLY is non-nil, don't export
3480 contents of hidden elements.
3482 When optional argument BODY-ONLY is non-nil, only write code
3483 between \"<body>\" and \"</body>\" tags.
3485 EXT-PLIST, when provided, is a property list with external
3486 parameters overriding Org default settings, but still inferior to
3487 file-local settings.
3489 Return output file's name."
3490 (interactive)
3491 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3492 org-html-extension
3493 "html")))
3494 (file (org-export-output-file-name extension subtreep))
3495 (org-export-coding-system org-html-coding-system))
3496 (org-export-to-file 'html file
3497 async subtreep visible-only body-only ext-plist)))
3499 ;;;###autoload
3500 (defun org-html-publish-to-html (plist filename pub-dir)
3501 "Publish an org file to HTML.
3503 FILENAME is the filename of the Org file to be published. PLIST
3504 is the property list for the given project. PUB-DIR is the
3505 publishing directory.
3507 Return output file name."
3508 (org-publish-org-to 'html filename
3509 (concat "." (or (plist-get plist :html-extension)
3510 org-html-extension
3511 "html"))
3512 plist pub-dir))
3515 (provide 'ox-html)
3517 ;; Local variables:
3518 ;; generated-autoload-file: "org-loaddefs.el"
3519 ;; End:
3521 ;;; ox-html.el ends here