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