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