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