ox-html: Fix missing <span> block around section number
[org-mode.git] / lisp / ox-html.el
blob3b34a84afae3078e7c9af8be15bb0343294df964
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-files-as-html nil nil org-html-link-org-files-as-html)
146 (:html-mathjax-options nil nil org-html-mathjax-options)
147 (:html-mathjax-template nil nil org-html-mathjax-template)
148 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
149 (:html-postamble-format nil nil org-html-postamble-format)
150 (:html-preamble-format nil nil org-html-preamble-format)
151 (:html-table-align-individual-fields
152 nil nil org-html-table-align-individual-fields)
153 (:html-table-caption-above nil nil org-html-table-caption-above)
154 (:html-table-data-tags nil nil org-html-table-data-tags)
155 (:html-table-header-tags nil nil org-html-table-header-tags)
156 (:html-table-use-header-tags-for-first-column
157 nil nil org-html-table-use-header-tags-for-first-column)
158 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
159 (:html-text-markup-alist nil nil org-html-text-markup-alist)
160 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
161 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
162 (:html-use-infojs nil nil org-html-use-infojs)
163 (:html-use-unicode-chars nil nil org-html-use-unicode-chars)
164 (:html-validation-link nil nil org-html-validation-link)
165 (:html-inline-images nil nil org-html-inline-images)
166 (:html-table-attributes nil nil org-html-table-default-attributes)
167 (:html-table-row-tags nil nil org-html-table-row-tags)
168 (:html-xml-declaration nil nil org-html-xml-declaration)
169 (:infojs-opt "INFOJS_OPT" nil nil)
170 ;; Redefine regular options.
171 (:creator "CREATOR" nil org-html-creator-string)
172 (:with-latex nil "tex" org-html-with-latex)
173 ;; Retrieve LaTeX header for fragments.
174 (:latex-header "LATEX_HEADER" nil nil newline)))
177 ;;; Internal Variables
179 (defvar org-html-format-table-no-css)
180 (defvar htmlize-buffer-places) ; from htmlize.el
182 (defvar org-html--pre/postamble-class "status"
183 "CSS class used for pre/postamble")
185 (defconst org-html-doctype-alist
186 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
187 \"http://www.w3.org/TR/html4/strict.dtd\">")
188 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
189 \"http://www.w3.org/TR/html4/loose.dtd\">")
190 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
191 \"http://www.w3.org/TR/html4/frameset.dtd\">")
193 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
194 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
195 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
196 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
197 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
198 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
199 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
200 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
202 ("html5" . "<!DOCTYPE html>")
203 ("xhtml5" . "<!DOCTYPE html>"))
204 "An alist mapping (x)html flavors to specific doctypes.")
206 (defconst org-html-html5-elements
207 '("article" "aside" "audio" "canvas" "details" "figcaption"
208 "figure" "footer" "header" "menu" "meter" "nav" "output"
209 "progress" "section" "video")
210 "New elements in html5.
212 For blocks that should contain headlines, use the HTML_CONTAINER
213 property on the headline itself.")
215 (defconst org-html-special-string-regexps
216 '(("\\\\-" . "&#x00ad;") ; shy
217 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
218 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
219 ("\\.\\.\\." . "&#x2026;")) ; hellip
220 "Regular expressions for special string conversion.")
222 (defconst org-html-scripts
223 "<script type=\"text/javascript\">
225 @licstart The following is the entire license notice for the
226 JavaScript code in this tag.
228 Copyright (C) 2012-2013 Free Software Foundation, Inc.
230 The JavaScript code in this tag is free software: you can
231 redistribute it and/or modify it under the terms of the GNU
232 General Public License (GNU GPL) as published by the Free Software
233 Foundation, either version 3 of the License, or (at your option)
234 any later version. The code is distributed WITHOUT ANY WARRANTY;
235 without even the implied warranty of MERCHANTABILITY or FITNESS
236 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
238 As additional permission under GNU GPL version 3 section 7, you
239 may distribute non-source (e.g., minimized or compacted) forms of
240 that code without the copy of the GNU GPL normally required by
241 section 4, provided you include this license notice and a URL
242 through which recipients can access the Corresponding Source.
245 @licend The above is the entire license notice
246 for the JavaScript code in this tag.
248 <!--/*--><![CDATA[/*><!--*/
249 function CodeHighlightOn(elem, id)
251 var target = document.getElementById(id);
252 if(null != target) {
253 elem.cacheClassElem = elem.className;
254 elem.cacheClassTarget = target.className;
255 target.className = \"code-highlighted\";
256 elem.className = \"code-highlighted\";
259 function CodeHighlightOff(elem, id)
261 var target = document.getElementById(id);
262 if(elem.cacheClassElem)
263 elem.className = elem.cacheClassElem;
264 if(elem.cacheClassTarget)
265 target.className = elem.cacheClassTarget;
267 /*]]>*///-->
268 </script>"
269 "Basic JavaScript that is needed by HTML files produced by Org mode.")
271 (defconst org-html-style-default
272 "<style type=\"text/css\">
273 <!--/*--><![CDATA[/*><!--*/
274 .title { text-align: center; }
275 .todo { font-family: monospace; color: red; }
276 .done { 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 (plist-get exp-plist :html-use-infojs))
495 (and (eq (plist-get exp-plist :html-use-infojs) 'when-configured)
496 (let ((opt (plist-get exp-plist :infojs-opt)))
497 (or (not opt)
498 (string= "" opt)
499 (string-match "\\<view:nil\\>" opt)))))
500 (let* ((template (plist-get exp-plist :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 (infojs-opt (plist-get exp-plist :html-infojs-options))
507 (table org-html-infojs-opts-table)
508 style)
509 (dolist (entry table)
510 (let* ((opt (car entry))
511 (var (nth 1 entry))
512 ;; Compute default values for script option OPT from
513 ;; `org-html-infojs-options' variable.
514 (default
515 (let ((default (cdr (assq opt infojs-opt))))
516 (if (and (symbolp default) (not (memq default '(t nil))))
517 (plist-get exp-plist default)
518 default)))
519 ;; Value set through INFOJS_OPT keyword has precedence
520 ;; over the default one.
521 (val (if (and options
522 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
523 options))
524 (match-string 1 options)
525 default)))
526 (case opt
527 (path (setq template
528 (replace-regexp-in-string
529 "%SCRIPT_PATH" val template t t)))
530 (sdepth (when (integerp (read val))
531 (setq sdepth (min (read val) sdepth))))
532 (tdepth (when (integerp (read val))
533 (setq tdepth (min (read val) tdepth))))
534 (otherwise (setq val
535 (cond
536 ((or (eq val t) (equal val "t")) "1")
537 ((or (eq val nil) (equal val "nil")) "0")
538 ((stringp val) val)
539 (t (format "%s" val))))
540 (push (cons var val) style)))))
541 ;; Now we set the depth of the *generated* TOC to SDEPTH,
542 ;; because the toc will actually determine the splitting. How
543 ;; much of the toc will actually be displayed is governed by the
544 ;; TDEPTH option.
545 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
546 ;; The table of contents should not show more sections than we
547 ;; generate.
548 (setq tdepth (min tdepth sdepth))
549 (push (cons "TOC_DEPTH" tdepth) style)
550 ;; Build style string.
551 (setq style (mapconcat
552 (lambda (x)
553 (format "org_html_manager.set(\"%s\", \"%s\");"
554 (car x) (cdr x)))
555 style "\n"))
556 (when (and style (> (length style) 0))
557 (and (string-match "%MANAGER_OPTIONS" template)
558 (setq style (replace-match style t t template))
559 (setq exp-plist
560 (plist-put
561 exp-plist :html-head-extra
562 (concat (or (plist-get exp-plist :html-head-extra) "")
563 "\n"
564 style)))))
565 ;; This script absolutely needs the table of contents, so we
566 ;; change that setting.
567 (unless (plist-get exp-plist :with-toc)
568 (setq exp-plist (plist-put exp-plist :with-toc t)))
569 ;; Return the modified property list.
570 exp-plist)))
572 ;;;; Bold, etc.
574 (defcustom org-html-text-markup-alist
575 '((bold . "<b>%s</b>")
576 (code . "<code>%s</code>")
577 (italic . "<i>%s</i>")
578 (strike-through . "<del>%s</del>")
579 (underline . "<span class=\"underline\">%s</span>")
580 (verbatim . "<code>%s</code>"))
581 "Alist of HTML expressions to convert text markup.
583 The key must be a symbol among `bold', `code', `italic',
584 `strike-through', `underline' and `verbatim'. The value is
585 a formatting string to wrap fontified text with.
587 If no association can be found for a given markup, text will be
588 returned as-is."
589 :group 'org-export-html
590 :version "24.4"
591 :package-version '(Org . "8.0")
592 :type '(alist :key-type (symbol :tag "Markup type")
593 :value-type (string :tag "Format string"))
594 :options '(bold code italic strike-through underline verbatim))
596 (defcustom org-html-indent nil
597 "Non-nil means to indent the generated HTML.
598 Warning: non-nil may break indentation of source code blocks."
599 :group 'org-export-html
600 :version "24.4"
601 :package-version '(Org . "8.0")
602 :type 'boolean)
604 (defcustom org-html-use-unicode-chars nil
605 "Non-nil means to use unicode characters instead of HTML entities."
606 :group 'org-export-html
607 :version "24.4"
608 :package-version '(Org . "8.0")
609 :type 'boolean)
611 ;;;; Drawers
613 (defcustom org-html-format-drawer-function (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
671 'org-html-format-headline-default-function
672 "Function to format headline text.
674 This function will be called with six arguments:
675 TODO the todo keyword (string or nil).
676 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
677 PRIORITY the priority of the headline (integer or nil)
678 TEXT the main headline text (string).
679 TAGS the tags (string or nil).
680 INFO the export options (plist).
682 The function result will be used in the section format string."
683 :group 'org-export-html
684 :version "24.5"
685 :package-version '(Org . "8.3")
686 :type 'function)
688 ;;;; HTML-specific
690 (defcustom org-html-allow-name-attribute-in-anchors nil
691 "When nil, do not set \"name\" attribute in anchors.
692 By default, when appropriate, anchors are formatted with \"id\"
693 but without \"name\" attribute."
694 :group 'org-export-html
695 :version "24.4"
696 :package-version '(Org . "8.0")
697 :type 'boolean)
699 ;;;; Inlinetasks
701 (defcustom org-html-format-inlinetask-function
702 'org-html-format-inlinetask-default-function
703 "Function called to format an inlinetask in HTML code.
705 The function must accept seven parameters:
706 TODO the todo keyword, as a string
707 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
708 PRIORITY the inlinetask priority, as a string
709 NAME the inlinetask name, as a string.
710 TAGS the inlinetask tags, as a list of strings.
711 CONTENTS the contents of the inlinetask, as a string.
712 INFO the export options, as a plist
714 The function should return the string to be exported."
715 :group 'org-export-html
716 :version "24.5"
717 :package-version '(Org . "8.3")
718 :type 'function)
720 ;;;; LaTeX
722 (defcustom org-html-with-latex org-export-with-latex
723 "Non-nil means process LaTeX math snippets.
725 When set, the exporter will process LaTeX environments and
726 fragments.
728 This option can also be set with the +OPTIONS line,
729 e.g. \"tex:mathjax\". Allowed values are:
731 nil Ignore math snippets.
732 `verbatim' Keep everything in verbatim
733 `dvipng' Process the LaTeX fragments to images. This will also
734 include processing of non-math environments.
735 `imagemagick' Convert the LaTeX fragments to pdf files and use
736 imagemagick to convert pdf files to png files.
737 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
738 be loaded.
739 t Synonym for `mathjax'."
740 :group 'org-export-html
741 :version "24.4"
742 :package-version '(Org . "8.0")
743 :type '(choice
744 (const :tag "Do not process math in any way" nil)
745 (const :tag "Use dvipng to make images" dvipng)
746 (const :tag "Use imagemagick to make images" imagemagick)
747 (const :tag "Use MathJax to display math" mathjax)
748 (const :tag "Leave math verbatim" verbatim)))
750 ;;;; Links :: Generic
752 (defcustom org-html-link-org-files-as-html t
753 "Non-nil means make file links to `file.org' point to `file.html'.
754 When `org-mode' is exporting an `org-mode' file to HTML, links to
755 non-html files are directly put into a href tag in HTML.
756 However, links to other Org-mode files (recognized by the
757 extension `.org.) should become links to the corresponding html
758 file, assuming that the linked `org-mode' file will also be
759 converted to HTML.
760 When nil, the links still point to the plain `.org' file."
761 :group 'org-export-html
762 :type 'boolean)
764 ;;;; Links :: Inline images
766 (defcustom org-html-inline-images t
767 "Non-nil means inline images into exported HTML pages.
768 This is done using an <img> tag. When nil, an anchor with href is used to
769 link to the image."
770 :group 'org-export-html
771 :version "24.4"
772 :package-version '(Org . "8.1")
773 :type 'boolean)
775 (defcustom org-html-inline-image-rules
776 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
777 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
778 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
779 "Rules characterizing image files that can be inlined into HTML.
780 A rule consists in an association whose key is the type of link
781 to consider, and value is a regexp that will be matched against
782 link's path."
783 :group 'org-export-html
784 :version "24.4"
785 :package-version '(Org . "8.0")
786 :type '(alist :key-type (string :tag "Type")
787 :value-type (regexp :tag "Path")))
789 ;;;; Plain Text
791 (defvar org-html-protect-char-alist
792 '(("&" . "&amp;")
793 ("<" . "&lt;")
794 (">" . "&gt;"))
795 "Alist of characters to be converted by `org-html-protect'.")
797 ;;;; Src Block
799 (defcustom org-html-htmlize-output-type 'inline-css
800 "Output type to be used by htmlize when formatting code snippets.
801 Choices are `css' to export the CSS selectors only,`inline-css'
802 to export the CSS attribute values inline in the HTML or `nil' to
803 export plain text. We use as default `inline-css', in order to
804 make the resulting HTML self-containing.
806 However, this will fail when using Emacs in batch mode for export, because
807 then no rich font definitions are in place. It will also not be good if
808 people with different Emacs setup contribute HTML files to a website,
809 because the fonts will represent the individual setups. In these cases,
810 it is much better to let Org/Htmlize assign classes only, and to use
811 a style file to define the look of these classes.
812 To get a start for your css file, start Emacs session and make sure that
813 all the faces you are interested in are defined, for example by loading files
814 in all modes you want. Then, use the command
815 \\[org-html-htmlize-generate-css] to extract class definitions."
816 :group 'org-export-html
817 :type '(choice (const css) (const inline-css) (const nil)))
819 (defcustom org-html-htmlize-font-prefix "org-"
820 "The prefix for CSS class names for htmlize font specifications."
821 :group 'org-export-html
822 :type 'string)
824 ;;;; Table
826 (defcustom org-html-table-default-attributes
827 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
828 "Default attributes and values which will be used in table tags.
829 This is a plist where attributes are symbols, starting with
830 colons, and values are strings.
832 When exporting to HTML5, these values will be disregarded."
833 :group 'org-export-html
834 :version "24.4"
835 :package-version '(Org . "8.0")
836 :type '(plist :key-type (symbol :tag "Property")
837 :value-type (string :tag "Value")))
839 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
840 "The opening and ending tags for table header fields.
841 This is customizable so that alignment options can be specified.
842 The first %s will be filled with the scope of the field, either row or col.
843 The second %s will be replaced by a style entry to align the field.
844 See also the variable `org-html-table-use-header-tags-for-first-column'.
845 See also the variable `org-html-table-align-individual-fields'."
846 :group 'org-export-html
847 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
849 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
850 "The opening and ending tags for table data fields.
851 This is customizable so that alignment options can be specified.
852 The first %s will be filled with the scope of the field, either row or col.
853 The second %s will be replaced by a style entry to align the field.
854 See also the variable `org-html-table-align-individual-fields'."
855 :group 'org-export-html
856 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
858 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
859 "The opening and ending tags for table rows.
860 This is customizable so that alignment options can be specified.
861 Instead of strings, these can be Lisp forms that will be
862 evaluated for each row in order to construct the table row tags.
864 During evaluation, these variables will be dynamically bound so that
865 you can reuse them:
867 `row-number': row number (0 is the first row)
868 `rowgroup-number': group number of current row
869 `start-rowgroup-p': non-nil means the row starts a group
870 `end-rowgroup-p': non-nil means the row ends a group
871 `top-row-p': non-nil means this is the top row
872 `bottom-row-p': non-nil means this is the bottom row
874 For example:
876 \(setq org-html-table-row-tags
877 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
878 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
879 (t (if (= (mod row-number 2) 1)
880 \"<tr class=\\\"tr-odd\\\">\"
881 \"<tr class=\\\"tr-even\\\">\")))
882 \"</tr>\"))
884 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
885 and the bottom row, and otherwise alternate between \"tr-odd\" and
886 \"tr-even\" for odd and even rows."
887 :group 'org-export-html
888 :type '(cons
889 (choice :tag "Opening tag"
890 (string :tag "Specify")
891 (sexp))
892 (choice :tag "Closing tag"
893 (string :tag "Specify")
894 (sexp))))
896 (defcustom org-html-table-align-individual-fields t
897 "Non-nil means attach style attributes for alignment to each table field.
898 When nil, alignment will only be specified in the column tags, but this
899 is ignored by some browsers (like Firefox, Safari). Opera does it right
900 though."
901 :group 'org-export-html
902 :type 'boolean)
904 (defcustom org-html-table-use-header-tags-for-first-column nil
905 "Non-nil means format column one in tables with header tags.
906 When nil, also column one will use data tags."
907 :group 'org-export-html
908 :type 'boolean)
910 (defcustom org-html-table-caption-above t
911 "When non-nil, place caption string at the beginning of the table.
912 Otherwise, place it near the end."
913 :group 'org-export-html
914 :type 'boolean)
916 ;;;; Tags
918 (defcustom org-html-tag-class-prefix ""
919 "Prefix to class names for TODO keywords.
920 Each tag gets a class given by the tag itself, with this prefix.
921 The default prefix is empty because it is nice to just use the keyword
922 as a class name. But if you get into conflicts with other, existing
923 CSS classes, then this prefix can be very useful."
924 :group 'org-export-html
925 :type 'string)
927 ;;;; Template :: Generic
929 (defcustom org-html-extension "html"
930 "The extension for exported HTML files."
931 :group 'org-export-html
932 :type 'string)
934 (defcustom org-html-xml-declaration
935 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
936 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
937 "The extension for exported HTML files.
938 %s will be replaced with the charset of the exported file.
939 This may be a string, or an alist with export extensions
940 and corresponding declarations.
942 This declaration only applies when exporting to XHTML."
943 :group 'org-export-html
944 :type '(choice
945 (string :tag "Single declaration")
946 (repeat :tag "Dependent on extension"
947 (cons (string :tag "Extension")
948 (string :tag "Declaration")))))
950 (defcustom org-html-coding-system 'utf-8
951 "Coding system for HTML export.
952 Use utf-8 as the default value."
953 :group 'org-export-html
954 :version "24.4"
955 :package-version '(Org . "8.0")
956 :type 'coding-system)
958 (defcustom org-html-doctype "xhtml-strict"
959 "Document type definition to use for exported HTML files.
960 Can be set with the in-buffer HTML_DOCTYPE property or for
961 publishing, with :html-doctype."
962 :group 'org-export-html
963 :version "24.4"
964 :package-version '(Org . "8.0")
965 :type (append
966 '(choice)
967 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
968 '((string :tag "Custom doctype" ))))
970 (defcustom org-html-html5-fancy nil
971 "Non-nil means using new HTML5 elements.
972 This variable is ignored for anything other than HTML5 export.
974 For compatibility with Internet Explorer, it's probably a good
975 idea to download some form of the html5shiv (for instance
976 https://code.google.com/p/html5shiv/) and add it to your
977 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
978 versions 8 and below."
979 :group 'org-export-html
980 :version "24.4"
981 :package-version '(Org . "8.0")
982 :type 'boolean)
984 (defcustom org-html-container-element "div"
985 "HTML element to use for wrapping top level sections.
986 Can be set with the in-buffer HTML_CONTAINER property or for
987 publishing, with :html-container.
989 Note that changing the default will prevent you from using
990 org-info.js for your website."
991 :group 'org-export-html
992 :version "24.4"
993 :package-version '(Org . "8.0")
994 :type 'string)
996 (defcustom org-html-divs
997 '((preamble "div" "preamble")
998 (content "div" "content")
999 (postamble "div" "postamble"))
1000 "Alist of the three section elements for HTML export.
1001 The car of each entry is one of 'preamble, 'content or 'postamble.
1002 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1003 section of the exported document.
1005 Note that changing the default will prevent you from using
1006 org-info.js for your website."
1007 :group 'org-export-html
1008 :version "24.4"
1009 :package-version '(Org . "8.0")
1010 :type '(list :greedy t
1011 (list :tag "Preamble"
1012 (const :format "" preamble)
1013 (string :tag "element") (string :tag " id"))
1014 (list :tag "Content"
1015 (const :format "" content)
1016 (string :tag "element") (string :tag " id"))
1017 (list :tag "Postamble" (const :format "" postamble)
1018 (string :tag " id") (string :tag "element"))))
1020 (defconst org-html-checkbox-types
1021 '((unicode .
1022 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1023 (ascii .
1024 ((on . "<code>[X]</code>")
1025 (off . "<code>[&#xa0;]</code>")
1026 (trans . "<code>[-]</code>")))
1027 (html .
1028 ((on . "<input type='checkbox' checked='checked' />")
1029 (off . "<input type='checkbox' />")
1030 (trans . "<input type='checkbox' />"))))
1031 "Alist of checkbox types.
1032 The cdr of each entry is an alist list three checkbox types for
1033 HTML export: `on', `off' and `trans'.
1035 The choices are:
1036 `unicode' Unicode characters (HTML entities)
1037 `ascii' ASCII characters
1038 `html' HTML checkboxes
1040 Note that only the ascii characters implement tri-state
1041 checkboxes. The other two use the `off' checkbox for `trans'.")
1043 (defcustom org-html-checkbox-type 'ascii
1044 "The type of checkboxes to use for HTML export.
1045 See `org-html-checkbox-types' for for the values used for each
1046 option."
1047 :group 'org-export-html
1048 :version "24.4"
1049 :package-version '(Org . "8.0")
1050 :type '(choice
1051 (const :tag "ASCII characters" ascii)
1052 (const :tag "Unicode characters" unicode)
1053 (const :tag "HTML checkboxes" html)))
1055 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1056 "Format used for timestamps in preamble, postamble and metadata.
1057 See `format-time-string' for more information on its components."
1058 :group 'org-export-html
1059 :version "24.4"
1060 :package-version '(Org . "8.0")
1061 :type 'string)
1063 ;;;; Template :: Mathjax
1065 (defcustom org-html-mathjax-options
1066 '((path "http://orgmode.org/mathjax/MathJax.js")
1067 (scale "100")
1068 (align "center")
1069 (indent "2em")
1070 (mathml nil))
1071 "Options for MathJax setup.
1073 path The path where to find MathJax
1074 scale Scaling for the HTML-CSS backend, usually between 100 and 133
1075 align How to align display math: left, center, or right
1076 indent If align is not center, how far from the left/right side?
1077 mathml Should a MathML player be used if available?
1078 This is faster and reduces bandwidth use, but currently
1079 sometimes has lower spacing quality. Therefore, the default is
1080 nil. When browsers get better, this switch can be flipped.
1082 You can also customize this for each buffer, using something like
1084 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1085 :group 'org-export-html
1086 :type '(list :greedy t
1087 (list :tag "path (the path from where to load MathJax.js)"
1088 (const :format " " path) (string))
1089 (list :tag "scale (scaling for the displayed math)"
1090 (const :format " " scale) (string))
1091 (list :tag "align (alignment of displayed equations)"
1092 (const :format " " align) (string))
1093 (list :tag "indent (indentation with left or right alignment)"
1094 (const :format " " indent) (string))
1095 (list :tag "mathml (should MathML display be used is possible)"
1096 (const :format " " mathml) (boolean))))
1098 (defcustom org-html-mathjax-template
1099 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1100 <script type=\"text/javascript\">
1101 <!--/*--><![CDATA[/*><!--*/
1102 MathJax.Hub.Config({
1103 // Only one of the two following lines, depending on user settings
1104 // First allows browser-native MathML display, second forces HTML/CSS
1105 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1106 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1107 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1108 \"TeX/noUndefined.js\"],
1109 tex2jax: {
1110 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1111 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1112 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1113 ignoreClass: \"tex2jax_ignore\",
1114 processEscapes: false,
1115 processEnvironments: true,
1116 preview: \"TeX\"
1118 showProcessingMessages: true,
1119 displayAlign: \"%ALIGN\",
1120 displayIndent: \"%INDENT\",
1122 \"HTML-CSS\": {
1123 scale: %SCALE,
1124 availableFonts: [\"STIX\",\"TeX\"],
1125 preferredFont: \"TeX\",
1126 webFont: \"TeX\",
1127 imageFont: \"TeX\",
1128 showMathMenu: true,
1130 MMLorHTML: {
1131 prefer: {
1132 MSIE: \"MML\",
1133 Firefox: \"MML\",
1134 Opera: \"HTML\",
1135 other: \"HTML\"
1139 /*]]>*///-->
1140 </script>"
1141 "The MathJax setup for XHTML files."
1142 :group 'org-export-html
1143 :type 'string)
1145 ;;;; Template :: Postamble
1147 (defcustom org-html-postamble 'auto
1148 "Non-nil means insert a postamble in HTML export.
1150 When set to 'auto, check against the
1151 `org-export-with-author/email/creator/date' variables to set the
1152 content of the postamble. When set to a string, use this string
1153 as the postamble. When t, insert a string as defined by the
1154 formatting string in `org-html-postamble-format'.
1156 When set to a function, apply this function and insert the
1157 returned string. The function takes the property list of export
1158 options as its only argument.
1160 Setting :html-postamble in publishing projects will take
1161 precedence over this variable."
1162 :group 'org-export-html
1163 :type '(choice (const :tag "No postamble" nil)
1164 (const :tag "Auto postamble" auto)
1165 (const :tag "Default formatting string" t)
1166 (string :tag "Custom formatting string")
1167 (function :tag "Function (must return a string)")))
1169 (defcustom org-html-postamble-format
1170 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1171 <p class=\"date\">Date: %d</p>
1172 <p class=\"creator\">%c</p>
1173 <p class=\"validation\">%v</p>"))
1174 "Alist of languages and format strings for the HTML postamble.
1176 The first element of each list is the language code, as used for
1177 the LANGUAGE keyword. See `org-export-default-language'.
1179 The second element of each list is a format string to format the
1180 postamble itself. This format string can contain these elements:
1182 %t stands for the title.
1183 %a stands for the author's name.
1184 %e stands for the author's email.
1185 %d stands for the date.
1186 %c will be replaced by `org-html-creator-string'.
1187 %v will be replaced by `org-html-validation-link'.
1188 %T will be replaced by the export time.
1189 %C will be replaced by the last modification time.
1191 If you need to use a \"%\" character, you need to escape it
1192 like that: \"%%\"."
1193 :group 'org-export-html
1194 :type '(repeat
1195 (list (string :tag "Language")
1196 (string :tag "Format string"))))
1198 (defcustom org-html-validation-link
1199 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1200 "Link to HTML validation service."
1201 :group 'org-export-html
1202 :type 'string)
1204 (defcustom org-html-creator-string
1205 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1206 emacs-version
1207 (if (fboundp 'org-version) (org-version) "unknown version"))
1208 "Information about the creator of the HTML document.
1209 This option can also be set on with the CREATOR keyword."
1210 :group 'org-export-html
1211 :version "24.4"
1212 :package-version '(Org . "8.0")
1213 :type '(string :tag "Creator string"))
1215 ;;;; Template :: Preamble
1217 (defcustom org-html-preamble t
1218 "Non-nil means insert a preamble in HTML export.
1220 When t, insert a string as defined by the formatting string in
1221 `org-html-preamble-format'. When set to a string, use this
1222 formatting string instead (see `org-html-postamble-format' for an
1223 example of such a formatting string).
1225 When set to a function, apply this function and insert the
1226 returned string. The function takes the property list of export
1227 options as its only argument.
1229 Setting :html-preamble in publishing projects will take
1230 precedence over this variable."
1231 :group 'org-export-html
1232 :type '(choice (const :tag "No preamble" nil)
1233 (const :tag "Default preamble" t)
1234 (string :tag "Custom formatting string")
1235 (function :tag "Function (must return a string)")))
1237 (defcustom org-html-preamble-format '(("en" ""))
1238 "Alist of languages and format strings for the HTML preamble.
1240 The first element of each list is the language code, as used for
1241 the LANGUAGE keyword. See `org-export-default-language'.
1243 The second element of each list is a format string to format the
1244 preamble itself. This format string can contain these elements:
1246 %t stands for the title.
1247 %a stands for the author's name.
1248 %e stands for the author's email.
1249 %d stands for the date.
1250 %c will be replaced by `org-html-creator-string'.
1251 %v will be replaced by `org-html-validation-link'.
1252 %T will be replaced by the export time.
1253 %C will be replaced by the last modification time.
1255 If you need to use a \"%\" character, you need to escape it
1256 like that: \"%%\".
1258 See the default value of `org-html-postamble-format' for an
1259 example."
1260 :group 'org-export-html
1261 :type '(repeat
1262 (list (string :tag "Language")
1263 (string :tag "Format string"))))
1265 (defcustom org-html-link-up ""
1266 "Where should the \"UP\" link of exported HTML pages lead?"
1267 :group 'org-export-html
1268 :type '(string :tag "File or URL"))
1270 (defcustom org-html-link-home ""
1271 "Where should the \"HOME\" link of exported HTML pages lead?"
1272 :group 'org-export-html
1273 :type '(string :tag "File or URL"))
1275 (defcustom org-html-link-use-abs-url nil
1276 "Should we prepend relative links with HTML_LINK_HOME?"
1277 :group 'org-export-html
1278 :version "24.4"
1279 :package-version '(Org . "8.1")
1280 :type 'boolean)
1282 (defcustom org-html-home/up-format
1283 "<div id=\"org-div-home-and-up\">
1284 <a accesskey=\"h\" href=\"%s\"> UP </a>
1286 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1287 </div>"
1288 "Snippet used to insert the HOME and UP links.
1289 This is a format string, the first %s will receive the UP link,
1290 the second the HOME link. If both `org-html-link-up' and
1291 `org-html-link-home' are empty, the entire snippet will be
1292 ignored."
1293 :group 'org-export-html
1294 :type 'string)
1296 ;;;; Template :: Scripts
1298 (define-obsolete-variable-alias
1299 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1300 (defcustom org-html-head-include-scripts t
1301 "Non-nil means include the JavaScript snippets in exported HTML files.
1302 The actual script is defined in `org-html-scripts' and should
1303 not be modified."
1304 :group 'org-export-html
1305 :version "24.4"
1306 :package-version '(Org . "8.0")
1307 :type 'boolean)
1309 ;;;; Template :: Styles
1311 (define-obsolete-variable-alias
1312 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1313 (defcustom org-html-head-include-default-style t
1314 "Non-nil means include the default style in exported HTML files.
1315 The actual style is defined in `org-html-style-default' and
1316 should not be modified. Use `org-html-head' to use your own
1317 style information."
1318 :group 'org-export-html
1319 :version "24.4"
1320 :package-version '(Org . "8.0")
1321 :type 'boolean)
1322 ;;;###autoload
1323 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1325 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1326 (defcustom org-html-head ""
1327 "Org-wide head definitions for exported HTML files.
1329 This variable can contain the full HTML structure to provide a
1330 style, including the surrounding HTML tags. You can consider
1331 including definitions for the following classes: title, todo,
1332 done, timestamp, timestamp-kwd, tag, target.
1334 For example, a valid value would be:
1336 <style type=\"text/css\">
1337 <![CDATA[
1338 p { font-weight: normal; color: gray; }
1339 h1 { color: black; }
1340 .title { text-align: center; }
1341 .todo, .timestamp-kwd { color: red; }
1342 .done { color: green; }
1344 </style>
1346 If you want to refer to an external style, use something like
1348 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1350 As the value of this option simply gets inserted into the HTML
1351 <head> header, you can use it to add any arbitrary text to the
1352 header.
1354 You can set this on a per-file basis using #+HTML_HEAD:,
1355 or for publication projects using the :html-head property."
1356 :group 'org-export-html
1357 :version "24.4"
1358 :package-version '(Org . "8.0")
1359 :type 'string)
1360 ;;;###autoload
1361 (put 'org-html-head 'safe-local-variable 'stringp)
1363 (defcustom org-html-head-extra ""
1364 "More head information to add in the HTML output.
1366 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1367 or for publication projects using the :html-head-extra property."
1368 :group 'org-export-html
1369 :version "24.4"
1370 :package-version '(Org . "8.0")
1371 :type 'string)
1372 ;;;###autoload
1373 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1375 ;;;; Todos
1377 (defcustom org-html-todo-kwd-class-prefix ""
1378 "Prefix to class names for TODO keywords.
1379 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1380 The default prefix is empty because it is nice to just use the keyword
1381 as a class name. But if you get into conflicts with other, existing
1382 CSS classes, then this prefix can be very useful."
1383 :group 'org-export-html
1384 :type 'string)
1387 ;;; Internal Functions
1389 (defun org-html-xhtml-p (info)
1390 (let ((dt (downcase (plist-get info :html-doctype))))
1391 (string-match-p "xhtml" dt)))
1393 (defun org-html-html5-p (info)
1394 (let ((dt (downcase (plist-get info :html-doctype))))
1395 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1397 (defun org-html-close-tag (tag attr info)
1398 (concat "<" tag " " attr
1399 (if (org-html-xhtml-p info) " />" ">")))
1401 (defun org-html-doctype (info)
1402 "Return correct html doctype tag from `org-html-doctype-alist',
1403 or the literal value of :html-doctype from INFO if :html-doctype
1404 is not found in the alist.
1405 INFO is a plist used as a communication channel."
1406 (let ((dt (plist-get info :html-doctype)))
1407 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1409 (defun org-html--make-attribute-string (attributes)
1410 "Return a list of attributes, as a string.
1411 ATTRIBUTES is a plist where values are either strings or nil. An
1412 attributes with a nil value will be omitted from the result."
1413 (let (output)
1414 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1415 (cond ((null item) (pop output))
1416 ((symbolp item) (push (substring (symbol-name item) 1) output))
1417 (t (let ((key (car output))
1418 (value (replace-regexp-in-string
1419 "\"" "&quot;" (org-html-encode-plain-text item))))
1420 (setcar output (format "%s=\"%s\"" key value))))))))
1422 (defun org-html--wrap-image (contents info &optional caption label)
1423 "Wrap CONTENTS string within an appropriate environment for images.
1424 INFO is a plist used as a communication channel. When optional
1425 arguments CAPTION and LABEL are given, use them for caption and
1426 \"id\" attribute."
1427 (let ((html5-fancy (and (org-html-html5-p info)
1428 (plist-get info :html-html5-fancy))))
1429 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1430 "\n<div%s class=\"figure\">%s%s\n</div>")
1431 ;; ID.
1432 (if (not (org-string-nw-p label)) ""
1433 (format " id=\"%s\"" (org-export-solidify-link-text label)))
1434 ;; Contents.
1435 (format "\n<p>%s</p>" contents)
1436 ;; Caption.
1437 (if (not (org-string-nw-p caption)) ""
1438 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1439 "\n<p>%s</p>")
1440 caption)))))
1442 (defun org-html--format-image (source attributes info)
1443 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1444 SOURCE is a string specifying the location of the image.
1445 ATTRIBUTES is a plist, as returned by
1446 `org-export-read-attribute'. INFO is a plist used as
1447 a communication channel."
1448 (if (string= "svg" (file-name-extension source))
1449 (org-html--svg-image source attributes info)
1450 (org-html-close-tag
1451 "img"
1452 (org-html--make-attribute-string
1453 (org-combine-plists
1454 (list :src source
1455 :alt (if (string-match-p "^ltxpng/" source)
1456 (org-html-encode-plain-text
1457 (org-find-text-property-in-string 'org-latex-src source))
1458 (file-name-nondirectory source)))
1459 attributes))
1460 info)))
1462 (defun org-html--svg-image (source attributes info)
1463 "Return \"object\" appropriate for embedding svg file SOURCE
1464 with assoicated ATTRIBUTES. INFO is a plist used as a
1465 communication channel.
1467 The special attribute \"fallback\" can be used to specify a fallback
1468 image file to use if the object embedding is not supported."
1469 (let ((fallback (plist-get attributes :fallback))
1470 (attrs (org-html--make-attribute-string
1471 (plist-put attributes :fallback nil))))
1472 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1473 source attrs
1474 (if fallback
1475 (org-html-close-tag
1476 "img" (format "src=\"%s\" %s" fallback attrs) info)
1477 "Sorry, your browser does not support SVG."))))
1479 (defun org-html--textarea-block (element)
1480 "Transcode ELEMENT into a textarea block.
1481 ELEMENT is either a src block or an example block."
1482 (let* ((code (car (org-export-unravel-code element)))
1483 (attr (org-export-read-attribute :attr_html element)))
1484 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1485 (or (plist-get attr :width) 80)
1486 (or (plist-get attr :height) (org-count-lines code))
1487 code)))
1489 (defun org-html--has-caption-p (element &optional info)
1490 "Non-nil when ELEMENT has a caption affiliated keyword.
1491 INFO is a plist used as a communication channel. This function
1492 is meant to be used as a predicate for `org-export-get-ordinal' or
1493 a value to `org-html-standalone-image-predicate'."
1494 (org-element-property :caption element))
1496 ;;;; Table
1498 (defun org-html-htmlize-region-for-paste (beg end)
1499 "Convert the region between BEG and END to HTML, using htmlize.el.
1500 This is much like `htmlize-region-for-paste', only that it uses
1501 the settings define in the org-... variables."
1502 (let* ((htmlize-output-type org-html-htmlize-output-type)
1503 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1504 (htmlbuf (htmlize-region beg end)))
1505 (unwind-protect
1506 (with-current-buffer htmlbuf
1507 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1508 (plist-get htmlize-buffer-places 'content-end)))
1509 (kill-buffer htmlbuf))))
1511 ;;;###autoload
1512 (defun org-html-htmlize-generate-css ()
1513 "Create the CSS for all font definitions in the current Emacs session.
1514 Use this to create face definitions in your CSS style file that can then
1515 be used by code snippets transformed by htmlize.
1516 This command just produces a buffer that contains class definitions for all
1517 faces used in the current Emacs session. You can copy and paste the ones you
1518 need into your CSS file.
1520 If you then set `org-html-htmlize-output-type' to `css', calls
1521 to the function `org-html-htmlize-region-for-paste' will
1522 produce code that uses these same face definitions."
1523 (interactive)
1524 (require 'htmlize)
1525 (and (get-buffer "*html*") (kill-buffer "*html*"))
1526 (with-temp-buffer
1527 (let ((fl (face-list))
1528 (htmlize-css-name-prefix "org-")
1529 (htmlize-output-type 'css)
1530 f i)
1531 (while (setq f (pop fl)
1532 i (and f (face-attribute f :inherit)))
1533 (when (and (symbolp f) (or (not i) (not (listp i))))
1534 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1535 (htmlize-region (point-min) (point-max))))
1536 (org-pop-to-buffer-same-window "*html*")
1537 (goto-char (point-min))
1538 (if (re-search-forward "<style" nil t)
1539 (delete-region (point-min) (match-beginning 0)))
1540 (if (re-search-forward "</style>" nil t)
1541 (delete-region (1+ (match-end 0)) (point-max)))
1542 (beginning-of-line 1)
1543 (if (looking-at " +") (replace-match ""))
1544 (goto-char (point-min)))
1546 (defun org-html--make-string (n string)
1547 "Build a string by concatenating N times STRING."
1548 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1550 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1551 "Turn todo keyword KWD into a valid class name.
1552 Replaces invalid characters with \"_\"."
1553 (save-match-data
1554 (while (string-match "[^a-zA-Z0-9_]" kwd)
1555 (setq kwd (replace-match "_" t t kwd))))
1556 kwd)
1558 (defun org-html-footnote-section (info)
1559 "Format the footnote section.
1560 INFO is a plist used as a communication channel."
1561 (let* ((fn-alist (org-export-collect-footnote-definitions
1562 (plist-get info :parse-tree) info))
1563 (fn-alist
1564 (loop for (n type raw) in fn-alist collect
1565 (cons n (if (eq (org-element-type raw) 'org-data)
1566 (org-trim (org-export-data raw info))
1567 (format "<p>%s</p>"
1568 (org-trim (org-export-data raw info))))))))
1569 (when fn-alist
1570 (format
1571 (plist-get info :html-footnotes-section)
1572 (org-html--translate "Footnotes" info)
1573 (format
1574 "\n%s\n"
1575 (mapconcat
1576 (lambda (fn)
1577 (let ((n (car fn)) (def (cdr fn)))
1578 (format
1579 "<div class=\"footdef\">%s %s</div>\n"
1580 (format
1581 (plist-get info :html-footnote-format)
1582 (org-html--anchor
1583 (format "fn.%d" n)
1585 (format " class=\"footnum\" href=\"#fnr.%d\"" n)
1586 info))
1587 def)))
1588 fn-alist
1589 "\n"))))))
1592 ;;; Template
1594 (defun org-html--build-meta-info (info)
1595 "Return meta tags for exported document.
1596 INFO is a plist used as a communication channel."
1597 (let ((protect-string
1598 (lambda (str)
1599 (replace-regexp-in-string
1600 "\"" "&quot;" (org-html-encode-plain-text str))))
1601 (title (org-export-data (plist-get info :title) info))
1602 (author (and (plist-get info :with-author)
1603 (let ((auth (plist-get info :author)))
1604 (and auth
1605 ;; Return raw Org syntax, skipping non
1606 ;; exportable objects.
1607 (org-element-interpret-data
1608 (org-element-map auth
1609 (cons 'plain-text org-element-all-objects)
1610 'identity info))))))
1611 (description (plist-get info :description))
1612 (keywords (plist-get info :keywords))
1613 (charset (or (and org-html-coding-system
1614 (fboundp 'coding-system-get)
1615 (coding-system-get org-html-coding-system
1616 'mime-charset))
1617 "iso-8859-1")))
1618 (concat
1619 (format "<title>%s</title>\n" title)
1620 (when (plist-get info :time-stamp-file)
1621 (format-time-string
1622 (concat "<!-- "
1623 (plist-get info :html-metadata-timestamp-format)
1624 " -->\n")))
1625 (format
1626 (if (org-html-html5-p info)
1627 (org-html-close-tag "meta" " charset=\"%s\"" info)
1628 (org-html-close-tag
1629 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1630 info))
1631 charset) "\n"
1632 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1633 "\n"
1634 (and (org-string-nw-p author)
1635 (concat
1636 (org-html-close-tag "meta"
1637 (format " name=\"author\" content=\"%s\""
1638 (funcall protect-string author))
1639 info)
1640 "\n"))
1641 (and (org-string-nw-p description)
1642 (concat
1643 (org-html-close-tag "meta"
1644 (format " name=\"description\" content=\"%s\"\n"
1645 (funcall protect-string description))
1646 info)
1647 "\n"))
1648 (and (org-string-nw-p keywords)
1649 (concat
1650 (org-html-close-tag "meta"
1651 (format " name=\"keywords\" content=\"%s\""
1652 (funcall protect-string keywords))
1653 info)
1654 "\n")))))
1656 (defun org-html--build-head (info)
1657 "Return information for the <head>..</head> of the HTML output.
1658 INFO is a plist used as a communication channel."
1659 (org-element-normalize-string
1660 (concat
1661 (when (plist-get info :html-head-include-default-style)
1662 (org-element-normalize-string org-html-style-default))
1663 (org-element-normalize-string (plist-get info :html-head))
1664 (org-element-normalize-string (plist-get info :html-head-extra))
1665 (when (and (plist-get info :html-htmlized-css-url)
1666 (eq org-html-htmlize-output-type 'css))
1667 (org-html-close-tag "link"
1668 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1669 (plist-get info :html-htmlized-css-url))
1670 info))
1671 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1673 (defun org-html--build-mathjax-config (info)
1674 "Insert the user setup into the mathjax template.
1675 INFO is a plist used as a communication channel."
1676 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1677 (org-element-map (plist-get info :parse-tree)
1678 '(latex-fragment latex-environment) 'identity info t))
1679 (let ((template (plist-get info :html-mathjax-template))
1680 (options (plist-get info :html-mathjax-options))
1681 (in-buffer (or (plist-get info :html-mathjax) ""))
1682 name val (yes " ") (no "// ") x)
1683 (mapc
1684 (lambda (e)
1685 (setq name (car e) val (nth 1 e))
1686 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1687 (setq val (car (read-from-string
1688 (substring in-buffer (match-end 0))))))
1689 (if (not (stringp val)) (setq val (format "%s" val)))
1690 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1691 (setq template (replace-match val t t template))))
1692 options)
1693 (setq val (nth 1 (assq 'mathml options)))
1694 (if (string-match (concat "\\<mathml:") in-buffer)
1695 (setq val (car (read-from-string
1696 (substring in-buffer (match-end 0))))))
1697 ;; Exchange prefixes depending on mathml setting.
1698 (if (not val) (setq x yes yes no no x))
1699 ;; Replace cookies to turn on or off the config/jax lines.
1700 (if (string-match ":MMLYES:" template)
1701 (setq template (replace-match yes t t template)))
1702 (if (string-match ":MMLNO:" template)
1703 (setq template (replace-match no t t template)))
1704 ;; Return the modified template.
1705 (org-element-normalize-string template))))
1707 (defun org-html-format-spec (info)
1708 "Return format specification for elements that can be
1709 used in the preamble or postamble."
1710 `((?t . ,(org-export-data (plist-get info :title) info))
1711 (?d . ,(org-export-data (org-export-get-date info) info))
1712 (?T . ,(format-time-string
1713 (plist-get info :html-metadata-timestamp-format)))
1714 (?a . ,(org-export-data (plist-get info :author) info))
1715 (?e . ,(mapconcat
1716 (lambda (e)
1717 (format "<a href=\"mailto:%s\">%s</a>" e e))
1718 (split-string (plist-get info :email) ",+ *")
1719 ", "))
1720 (?c . ,(plist-get info :creator))
1721 (?C . ,(let ((file (plist-get info :input-file)))
1722 (format-time-string
1723 (plist-get info :html-metadata-timestamp-format)
1724 (if file (nth 5 (file-attributes file)) (current-time)))))
1725 (?v . ,(or (plist-get info :html-validation-link) ""))))
1727 (defun org-html--build-pre/postamble (type info)
1728 "Return document preamble or postamble as a string, or nil.
1729 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1730 communication channel."
1731 (let ((section (plist-get info (intern (format ":html-%s" type))))
1732 (spec (org-html-format-spec info)))
1733 (when section
1734 (let ((section-contents
1735 (if (functionp section) (funcall section info)
1736 (cond
1737 ((stringp section) (format-spec section spec))
1738 ((eq section 'auto)
1739 (let ((date (cdr (assq ?d spec)))
1740 (author (cdr (assq ?a spec)))
1741 (email (cdr (assq ?e spec)))
1742 (creator (cdr (assq ?c spec)))
1743 (timestamp (cdr (assq ?T spec)))
1744 (validation-link (cdr (assq ?v spec))))
1745 (concat
1746 (when (and (plist-get info :with-date)
1747 (org-string-nw-p date))
1748 (format "<p class=\"date\">%s: %s</p>\n"
1749 (org-html--translate "Date" info)
1750 date))
1751 (when (and (plist-get info :with-author)
1752 (org-string-nw-p author))
1753 (format "<p class=\"author\">%s: %s</p>\n"
1754 (org-html--translate "Author" info)
1755 author))
1756 (when (and (plist-get info :with-email)
1757 (org-string-nw-p email))
1758 (format "<p class=\"email\">%s: %s</p>\n"
1759 (org-html--translate "Email" info)
1760 email))
1761 (when (plist-get info :time-stamp-file)
1762 (format
1763 "<p class=\"date\">%s: %s</p>\n"
1764 (org-html--translate "Created" info)
1765 (format-time-string
1766 (plist-get info :html-metadata-timestamp-format))))
1767 (when (plist-get info :with-creator)
1768 (format "<p class=\"creator\">%s</p>\n" creator))
1769 (format "<p class=\"validation\">%s</p>\n"
1770 validation-link))))
1771 (t (format-spec
1772 (or (cadr (assoc
1773 (plist-get info :language)
1774 (eval (intern
1775 (format "org-html-%s-format" type)))))
1776 (cadr
1777 (assoc
1778 "en"
1779 (eval
1780 (intern (format "org-html-%s-format" type))))))
1781 spec))))))
1782 (let ((div (assq type (plist-get info :html-divs))))
1783 (when (org-string-nw-p section-contents)
1784 (concat
1785 (format "<%s id=\"%s\" class=\"%s\">\n"
1786 (nth 1 div)
1787 (nth 2 div)
1788 org-html--pre/postamble-class)
1789 (org-element-normalize-string section-contents)
1790 (format "</%s>\n" (nth 1 div)))))))))
1792 (defun org-html-inner-template (contents info)
1793 "Return body of document string after HTML conversion.
1794 CONTENTS is the transcoded contents string. INFO is a plist
1795 holding export options."
1796 (concat
1797 ;; Table of contents.
1798 (let ((depth (plist-get info :with-toc)))
1799 (when depth (org-html-toc depth info)))
1800 ;; Document contents.
1801 contents
1802 ;; Footnotes section.
1803 (org-html-footnote-section info)))
1805 (defun org-html-template (contents info)
1806 "Return complete document string after HTML conversion.
1807 CONTENTS is the transcoded contents string. INFO is a plist
1808 holding export options."
1809 (concat
1810 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1811 (let* ((xml-declaration (plist-get info :html-xml-declaration))
1812 (decl (or (and (stringp xml-declaration) xml-declaration)
1813 (cdr (assoc (plist-get info :html-extension)
1814 xml-declaration))
1815 (cdr (assoc "html" xml-declaration))
1816 "")))
1817 (when (not (or (not decl) (string= "" decl)))
1818 (format "%s\n"
1819 (format decl
1820 (or (and org-html-coding-system
1821 (fboundp 'coding-system-get)
1822 (coding-system-get org-html-coding-system 'mime-charset))
1823 "iso-8859-1"))))))
1824 (org-html-doctype info)
1825 "\n"
1826 (concat "<html"
1827 (when (org-html-xhtml-p info)
1828 (format
1829 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1830 (plist-get info :language) (plist-get info :language)))
1831 ">\n")
1832 "<head>\n"
1833 (org-html--build-meta-info info)
1834 (org-html--build-head info)
1835 (org-html--build-mathjax-config info)
1836 "</head>\n"
1837 "<body>\n"
1838 (let ((link-up (org-trim (plist-get info :html-link-up)))
1839 (link-home (org-trim (plist-get info :html-link-home))))
1840 (unless (and (string= link-up "") (string= link-home ""))
1841 (format (plist-get info :html-home/up-format)
1842 (or link-up link-home)
1843 (or link-home link-up))))
1844 ;; Preamble.
1845 (org-html--build-pre/postamble 'preamble info)
1846 ;; Document contents.
1847 (let ((div (assq 'content (plist-get info :html-divs))))
1848 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
1849 ;; Document title.
1850 (let ((title (plist-get info :title)))
1851 (format "<h1 class=\"title\">%s</h1>\n"
1852 (org-export-data (or title "") info)))
1853 contents
1854 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
1855 ;; Postamble.
1856 (org-html--build-pre/postamble 'postamble info)
1857 ;; Closing document.
1858 "</body>\n</html>"))
1860 (defun org-html--translate (s info)
1861 "Translate string S according to specified language.
1862 INFO is a plist used as a communication channel."
1863 (org-export-translate s :html info))
1865 ;;;; Anchor
1867 (defun org-html--anchor (id desc attributes info)
1868 "Format a HTML anchor."
1869 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
1870 (attributes (concat (and id (format " id=\"%s\"" id))
1871 (and name (format " name=\"%s\"" name))
1872 attributes)))
1873 (format "<a%s>%s</a>" attributes (or desc ""))))
1875 ;;;; Todo
1877 (defun org-html--todo (todo info)
1878 "Format TODO keywords into HTML."
1879 (when todo
1880 (format "<span class=\"%s %s%s\">%s</span>"
1881 (if (member todo org-done-keywords) "done" "todo")
1882 (plist-get info :html-todo-kwd-class-prefix)
1883 (org-html-fix-class-name todo)
1884 todo)))
1886 ;;;; Tags
1888 (defun org-html--tags (tags info)
1889 "Format TAGS into HTML.
1890 INFO is a plist containing export options."
1891 (when tags
1892 (format "<span class=\"tag\">%s</span>"
1893 (mapconcat
1894 (lambda (tag)
1895 (format "<span class=\"%s\">%s</span>"
1896 (concat (plist-get info :html-tag-class-prefix)
1897 (org-html-fix-class-name tag))
1898 tag))
1899 tags "&#xa0;"))))
1901 ;;;; Src Code
1903 (defun org-html-fontify-code (code lang)
1904 "Color CODE with htmlize library.
1905 CODE is a string representing the source code to colorize. LANG
1906 is the language used for CODE, as a string, or nil."
1907 (when code
1908 (cond
1909 ;; Case 1: No lang. Possibly an example block.
1910 ((not lang)
1911 ;; Simple transcoding.
1912 (org-html-encode-plain-text code))
1913 ;; Case 2: No htmlize or an inferior version of htmlize
1914 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1915 ;; Emit a warning.
1916 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1917 ;; Simple transcoding.
1918 (org-html-encode-plain-text code))
1919 ;; Case 3: plain text explicitly set
1920 ((not org-html-htmlize-output-type)
1921 ;; Simple transcoding.
1922 (org-html-encode-plain-text code))
1924 ;; Map language
1925 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1926 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1927 (cond
1928 ;; Case 1: Language is not associated with any Emacs mode
1929 ((not (functionp lang-mode))
1930 ;; Simple transcoding.
1931 (org-html-encode-plain-text code))
1932 ;; Case 2: Default. Fontify code.
1934 ;; htmlize
1935 (setq code (with-temp-buffer
1936 ;; Switch to language-specific mode.
1937 (funcall lang-mode)
1938 ;; Disable fci-mode if present
1939 (when (and (fboundp 'fci-mode)
1940 (require 'fill-column-indicator nil 'noerror))
1941 (fci-mode -1))
1942 (insert code)
1943 ;; Fontify buffer.
1944 (font-lock-ensure)
1945 ;; Remove formatting on newline characters.
1946 (save-excursion
1947 (let ((beg (point-min))
1948 (end (point-max)))
1949 (goto-char beg)
1950 (while (progn (end-of-line) (< (point) end))
1951 (put-text-property (point) (1+ (point)) 'face nil)
1952 (forward-char 1))))
1953 (org-src-mode)
1954 (set-buffer-modified-p nil)
1955 ;; Htmlize region.
1956 (org-html-htmlize-region-for-paste
1957 (point-min) (point-max))))
1958 ;; Strip any enclosing <pre></pre> tags.
1959 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1960 (end (and beg (string-match "</pre>\\'" code))))
1961 (if (and beg end) (substring code beg end) code)))))))))
1963 (defun org-html-do-format-code
1964 (code &optional lang refs retain-labels num-start)
1965 "Format CODE string as source code.
1966 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1967 respectively, the language of the source code, as a string, an
1968 alist between line numbers and references (as returned by
1969 `org-export-unravel-code'), a boolean specifying if labels should
1970 appear in the source code, and the number associated to the first
1971 line of code."
1972 (let* ((code-lines (org-split-string code "\n"))
1973 (code-length (length code-lines))
1974 (num-fmt
1975 (and num-start
1976 (format "%%%ds: "
1977 (length (number-to-string (+ code-length num-start))))))
1978 (code (org-html-fontify-code code lang)))
1979 (org-export-format-code
1980 code
1981 (lambda (loc line-num ref)
1982 (setq loc
1983 (concat
1984 ;; Add line number, if needed.
1985 (when num-start
1986 (format "<span class=\"linenr\">%s</span>"
1987 (format num-fmt line-num)))
1988 ;; Transcoded src line.
1990 ;; Add label, if needed.
1991 (when (and ref retain-labels) (format " (%s)" ref))))
1992 ;; Mark transcoded line as an anchor, if needed.
1993 (if (not ref) loc
1994 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1995 ref loc)))
1996 num-start refs)))
1998 (defun org-html-format-code (element info)
1999 "Format contents of ELEMENT as source code.
2000 ELEMENT is either an example block or a src block. INFO is
2001 a plist used as a communication channel."
2002 (let* ((lang (org-element-property :language element))
2003 ;; Extract code and references.
2004 (code-info (org-export-unravel-code element))
2005 (code (car code-info))
2006 (refs (cdr code-info))
2007 ;; Does the src block contain labels?
2008 (retain-labels (org-element-property :retain-labels element))
2009 ;; Does it have line numbers?
2010 (num-start (case (org-element-property :number-lines element)
2011 (continued (org-export-get-loc element info))
2012 (new 0))))
2013 (org-html-do-format-code code lang refs retain-labels num-start)))
2016 ;;; Tables of Contents
2018 (defun org-html-toc (depth info)
2019 "Build a table of contents.
2020 DEPTH is an integer specifying the depth of the table. INFO is a
2021 plist used as a communication channel. Return the table of
2022 contents as a string, or nil if it is empty."
2023 (let ((toc-entries
2024 (mapcar (lambda (headline)
2025 (cons (org-html--format-toc-headline headline info)
2026 (org-export-get-relative-level headline info)))
2027 (org-export-collect-headlines info depth)))
2028 (outer-tag (if (and (org-html-html5-p info)
2029 (plist-get info :html-html5-fancy))
2030 "nav"
2031 "div")))
2032 (when toc-entries
2033 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2034 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2035 (format "<h%d>%s</h%d>\n"
2036 top-level
2037 (org-html--translate "Table of Contents" info)
2038 top-level))
2039 "<div id=\"text-table-of-contents\">"
2040 (org-html--toc-text toc-entries)
2041 "</div>\n"
2042 (format "</%s>\n" outer-tag)))))
2044 (defun org-html--toc-text (toc-entries)
2045 "Return innards of a table of contents, as a string.
2046 TOC-ENTRIES is an alist where key is an entry title, as a string,
2047 and value is its relative level, as an integer."
2048 (let* ((prev-level (1- (cdar toc-entries)))
2049 (start-level prev-level))
2050 (concat
2051 (mapconcat
2052 (lambda (entry)
2053 (let ((headline (car entry))
2054 (level (cdr entry)))
2055 (concat
2056 (let* ((cnt (- level prev-level))
2057 (times (if (> cnt 0) (1- cnt) (- cnt)))
2058 rtn)
2059 (setq prev-level level)
2060 (concat
2061 (org-html--make-string
2062 times (cond ((> cnt 0) "\n<ul>\n<li>")
2063 ((< cnt 0) "</li>\n</ul>\n")))
2064 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2065 headline)))
2066 toc-entries "")
2067 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2069 (defun org-html--format-toc-headline (headline info)
2070 "Return an appropriate table of contents entry for HEADLINE.
2071 INFO is a plist used as a communication channel."
2072 (let* ((headline-number (org-export-get-headline-number headline info))
2073 (todo (and (plist-get info :with-todo-keywords)
2074 (let ((todo (org-element-property :todo-keyword headline)))
2075 (and todo (org-export-data todo info)))))
2076 (todo-type (and todo (org-element-property :todo-type headline)))
2077 (priority (and (plist-get info :with-priority)
2078 (org-element-property :priority headline)))
2079 (text (org-export-data-with-backend
2080 (org-export-get-alt-title headline info)
2081 ;; Create an anonymous back-end that will ignore any
2082 ;; footnote-reference, link, radio-target and target
2083 ;; in table of contents.
2084 (org-export-create-backend
2085 :parent 'html
2086 :transcoders '((footnote-reference . ignore)
2087 (link . (lambda (object c i) c))
2088 (radio-target . (lambda (object c i) c))
2089 (target . ignore)))
2090 info))
2091 (tags (and (eq (plist-get info :with-tags) t)
2092 (org-export-get-tags headline info))))
2093 (format "<a href=\"#%s\">%s</a>"
2094 ;; Label.
2095 (org-export-solidify-link-text
2096 (or (org-element-property :CUSTOM_ID headline)
2097 (concat "sec-"
2098 (mapconcat #'number-to-string headline-number "-"))))
2099 ;; Body.
2100 (concat
2101 (and (not (org-export-low-level-p headline info))
2102 (org-export-numbered-headline-p headline info)
2103 (concat (mapconcat #'number-to-string headline-number ".")
2104 ". "))
2105 (apply (plist-get info :html-format-headline-function)
2106 todo todo-type priority text tags :section-number nil)))))
2108 (defun org-html-list-of-listings (info)
2109 "Build a list of listings.
2110 INFO is a plist used as a communication channel. Return the list
2111 of listings as a string, or nil if it is empty."
2112 (let ((lol-entries (org-export-collect-listings info)))
2113 (when lol-entries
2114 (concat "<div id=\"list-of-listings\">\n"
2115 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2116 (format "<h%d>%s</h%d>\n"
2117 top-level
2118 (org-html--translate "List of Listings" info)
2119 top-level))
2120 "<div id=\"text-list-of-listings\">\n<ul>\n"
2121 (let ((count 0)
2122 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2123 (org-html--translate "Listing %d:" info))))
2124 (mapconcat
2125 (lambda (entry)
2126 (let ((label (org-element-property :name entry))
2127 (title (org-trim
2128 (org-export-data
2129 (or (org-export-get-caption entry t)
2130 (org-export-get-caption entry))
2131 info))))
2132 (concat
2133 "<li>"
2134 (if (not label)
2135 (concat (format initial-fmt (incf count)) " " title)
2136 (format "<a href=\"#%s\">%s %s</a>"
2137 (org-export-solidify-link-text label)
2138 (format initial-fmt (incf count))
2139 title))
2140 "</li>")))
2141 lol-entries "\n"))
2142 "\n</ul>\n</div>\n</div>"))))
2144 (defun org-html-list-of-tables (info)
2145 "Build a list of tables.
2146 INFO is a plist used as a communication channel. Return the list
2147 of tables as a string, or nil if it is empty."
2148 (let ((lol-entries (org-export-collect-tables info)))
2149 (when lol-entries
2150 (concat "<div id=\"list-of-tables\">\n"
2151 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2152 (format "<h%d>%s</h%d>\n"
2153 top-level
2154 (org-html--translate "List of Tables" info)
2155 top-level))
2156 "<div id=\"text-list-of-tables\">\n<ul>\n"
2157 (let ((count 0)
2158 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2159 (org-html--translate "Table %d:" info))))
2160 (mapconcat
2161 (lambda (entry)
2162 (let ((label (org-element-property :name entry))
2163 (title (org-trim
2164 (org-export-data
2165 (or (org-export-get-caption entry t)
2166 (org-export-get-caption entry))
2167 info))))
2168 (concat
2169 "<li>"
2170 (if (not label)
2171 (concat (format initial-fmt (incf count)) " " title)
2172 (format "<a href=\"#%s\">%s %s</a>"
2173 (org-export-solidify-link-text label)
2174 (format initial-fmt (incf count))
2175 title))
2176 "</li>")))
2177 lol-entries "\n"))
2178 "\n</ul>\n</div>\n</div>"))))
2181 ;;; Transcode Functions
2183 ;;;; Bold
2185 (defun org-html-bold (bold contents info)
2186 "Transcode BOLD from Org to HTML.
2187 CONTENTS is the text with bold markup. INFO is a plist holding
2188 contextual information."
2189 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2190 contents))
2192 ;;;; Center Block
2194 (defun org-html-center-block (center-block contents info)
2195 "Transcode a CENTER-BLOCK element from Org to HTML.
2196 CONTENTS holds the contents of the block. INFO is a plist
2197 holding contextual information."
2198 (format "<div class=\"center\">\n%s</div>" contents))
2200 ;;;; Clock
2202 (defun org-html-clock (clock contents info)
2203 "Transcode a CLOCK element from Org to HTML.
2204 CONTENTS is nil. INFO is a plist used as a communication
2205 channel."
2206 (format "<p>
2207 <span class=\"timestamp-wrapper\">
2208 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2209 </span>
2210 </p>"
2211 org-clock-string
2212 (org-translate-time
2213 (org-element-property :raw-value
2214 (org-element-property :value clock)))
2215 (let ((time (org-element-property :duration clock)))
2216 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2218 ;;;; Code
2220 (defun org-html-code (code contents info)
2221 "Transcode CODE from Org to HTML.
2222 CONTENTS is nil. INFO is a plist holding contextual
2223 information."
2224 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2225 (org-html-encode-plain-text (org-element-property :value code))))
2227 ;;;; Drawer
2229 (defun org-html-drawer (drawer contents info)
2230 "Transcode a DRAWER element from Org to HTML.
2231 CONTENTS holds the contents of the block. INFO is a plist
2232 holding contextual information."
2233 (funcall (plist-get info :html-format-drawer-function)
2234 (org-element-property :drawer-name drawer)
2235 contents))
2237 ;;;; Dynamic Block
2239 (defun org-html-dynamic-block (dynamic-block contents info)
2240 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2241 CONTENTS holds the contents of the block. INFO is a plist
2242 holding contextual information. See `org-export-data'."
2243 contents)
2245 ;;;; Entity
2247 (defun org-html-entity (entity contents info)
2248 "Transcode an ENTITY object from Org to HTML.
2249 CONTENTS are the definition itself. INFO is a plist holding
2250 contextual information."
2251 (org-element-property :html entity))
2253 ;;;; Example Block
2255 (defun org-html-example-block (example-block contents info)
2256 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2257 CONTENTS is nil. INFO is a plist holding contextual
2258 information."
2259 (if (org-export-read-attribute :attr_html example-block :textarea)
2260 (org-html--textarea-block example-block)
2261 (format "<pre class=\"example\">\n%s</pre>"
2262 (org-html-format-code example-block info))))
2264 ;;;; Export Snippet
2266 (defun org-html-export-snippet (export-snippet contents info)
2267 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2268 CONTENTS is nil. INFO is a plist holding contextual
2269 information."
2270 (when (eq (org-export-snippet-backend export-snippet) 'html)
2271 (org-element-property :value export-snippet)))
2273 ;;;; Fixed Width
2275 (defun org-html-fixed-width (fixed-width contents info)
2276 "Transcode a FIXED-WIDTH element from Org to HTML.
2277 CONTENTS is nil. INFO is a plist holding contextual information."
2278 (format "<pre class=\"example\">\n%s</pre>"
2279 (org-html-do-format-code
2280 (org-remove-indentation
2281 (org-element-property :value fixed-width)))))
2283 ;;;; Footnote Reference
2285 (defun org-html-footnote-reference (footnote-reference contents info)
2286 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2287 CONTENTS is nil. INFO is a plist holding contextual information."
2288 (concat
2289 ;; Insert separator between two footnotes in a row.
2290 (let ((prev (org-export-get-previous-element footnote-reference info)))
2291 (when (eq (org-element-type prev) 'footnote-reference)
2292 (plist-get info :html-footnote-separator)))
2293 (let* ((n (org-export-get-footnote-number footnote-reference info))
2294 (id (format "fnr.%d%s"
2296 (if (org-export-footnote-first-reference-p
2297 footnote-reference info)
2299 ".100"))))
2300 (format
2301 (plist-get info :html-footnote-format)
2302 (org-html--anchor
2303 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2305 ;;;; Headline
2307 (defun org-html-headline (headline contents info)
2308 "Transcode a HEADLINE element from Org to HTML.
2309 CONTENTS holds the contents of the headline. INFO is a plist
2310 holding contextual information."
2311 (let* ((numberedp (org-export-numbered-headline-p headline info))
2312 (level (+ (org-export-get-relative-level headline info)
2313 (1- (plist-get info :html-toplevel-hlevel))))
2314 (todo (and (plist-get info :with-todo-keywords)
2315 (let ((todo (org-element-property :todo-keyword headline)))
2316 (and todo (org-export-data todo info)))))
2317 (todo-type (and todo (org-element-property :todo-type headline)))
2318 (priority (and (plist-get info :with-priority)
2319 (org-element-property :priority headline)))
2320 (text (org-export-data (org-element-property :title headline) info))
2321 (tags (and (plist-get info :with-tags)
2322 (org-export-get-tags headline info)))
2323 (full-text (funcall (plist-get info :html-format-headline-function)
2324 todo todo-type priority text tags info))
2325 (contents (or contents "")))
2326 (cond
2327 ;; Case 1: This is a footnote section: ignore it.
2328 ((org-element-property :footnote-section-p headline) nil)
2329 ;; Case 2: This is a deep sub-tree: export it as a list item.
2330 ;; Also export as items headlines for which no section
2331 ;; format has been found.
2332 ((org-export-low-level-p headline info)
2333 ;; Build the real contents of the sub-tree.
2334 (let* ((type (if numberedp 'ordered 'unordered))
2335 (itemized-body (org-html-format-list-item
2336 contents type nil info nil full-text)))
2337 (concat (and (org-export-first-sibling-p headline info)
2338 (org-html-begin-plain-list type))
2339 itemized-body
2340 (and (org-export-last-sibling-p headline info)
2341 (org-html-end-plain-list type)))))
2342 ;; Case 3: Standard headline. Export it as a section.
2344 (let* ((numbers (org-export-get-headline-number headline info))
2345 (section-number (mapconcat #'number-to-string numbers "-"))
2346 (ids (remq nil
2347 (list (org-element-property :CUSTOM_ID headline)
2348 (concat "sec-" section-number)
2349 (org-element-property :ID headline))))
2350 (preferred-id (car ids))
2351 (extra-ids (cdr ids))
2352 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2353 (first-content (car (org-element-contents headline))))
2354 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2355 (org-html--container headline info)
2356 (format "outline-container-%s"
2357 (or (org-element-property :CUSTOM_ID headline)
2358 (concat "sec-" section-number)))
2359 (concat (format "outline-%d" level)
2360 (and extra-class " ")
2361 extra-class)
2362 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2363 level
2364 preferred-id
2365 (mapconcat
2366 (lambda (x)
2367 (let ((id (org-export-solidify-link-text
2368 (if (org-uuidgen-p x) (concat "ID-" x)
2369 x))))
2370 (org-html--anchor id nil nil info)))
2371 extra-ids "")
2372 (concat
2373 (and numberedp
2374 (format
2375 "<span class=\"section-number-%d\">%s</span> "
2376 level
2377 (mapconcat #'number-to-string numbers ".")))
2378 full-text)
2379 level)
2380 ;; When there is no section, pretend there is an empty
2381 ;; one to get the correct <div class="outline- ...>
2382 ;; which is needed by `org-info.js'.
2383 (if (eq (org-element-type first-content) 'section) contents
2384 (concat (org-html-section first-content "" info) contents))
2385 (org-html--container headline info)))))))
2387 (defun org-html-format-headline-default-function
2388 (todo todo-type priority text tags info)
2389 "Default format function for a headline.
2390 See `org-html-format-headline-function' for details."
2391 (let ((todo (org-html--todo todo info))
2392 (tags (org-html--tags tags info)))
2393 (concat todo (and todo " ") text (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2395 (defun org-html--container (headline info)
2396 (or (org-element-property :HTML_CONTAINER headline)
2397 (if (= 1 (org-export-get-relative-level headline info))
2398 (plist-get info :html-container)
2399 "div")))
2401 ;;;; Horizontal Rule
2403 (defun org-html-horizontal-rule (horizontal-rule contents info)
2404 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2405 CONTENTS is nil. INFO is a plist holding contextual information."
2406 (org-html-close-tag "hr" nil info))
2408 ;;;; Inline Src Block
2410 (defun org-html-inline-src-block (inline-src-block contents info)
2411 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2412 CONTENTS holds the contents of the item. INFO is a plist holding
2413 contextual information."
2414 (let* ((org-lang (org-element-property :language inline-src-block))
2415 (code (org-element-property :value inline-src-block)))
2416 (error "Cannot export inline src block")))
2418 ;;;; Inlinetask
2420 (defun org-html-inlinetask (inlinetask contents info)
2421 "Transcode an INLINETASK element from Org to HTML.
2422 CONTENTS holds the contents of the block. INFO is a plist
2423 holding contextual information."
2424 (let* ((todo (and (plist-get info :with-todo-keywords)
2425 (let ((todo (org-element-property :todo-keyword inlinetask)))
2426 (and todo (org-export-data todo info)))))
2427 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2428 (priority (and (plist-get info :with-priority)
2429 (org-element-property :priority inlinetask)))
2430 (text (org-export-data (org-element-property :title inlinetask) info))
2431 (tags (and (plist-get info :with-tags)
2432 (org-export-get-tags inlinetask info))))
2433 (funcall (plist-get info :html-format-inlinetask-function)
2434 todo todo-type priority text tags contents)))
2436 (defun org-html-format-inlinetask-default-function
2437 (todo todo-type priority text tags contents info)
2438 "Default format function for a inlinetasks.
2439 See `org-html-format-inlinetask-function' for details."
2440 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2441 (org-html-format-headline-default-function
2442 todo todo-type priority text tags info)
2443 (org-html-close-tag "br" nil info)
2444 contents))
2446 ;;;; Italic
2448 (defun org-html-italic (italic contents info)
2449 "Transcode ITALIC from Org to HTML.
2450 CONTENTS is the text with italic markup. INFO is a plist holding
2451 contextual information."
2452 (format
2453 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2454 contents))
2456 ;;;; Item
2458 (defun org-html-checkbox (checkbox info)
2459 "Format CHECKBOX into HTML.
2460 INFO is a plist holding contextual information. See
2461 `org-html-checkbox-type' for customization options."
2462 (cdr (assq checkbox
2463 (cdr (assq (plist-get info :html-checkbox-type)
2464 org-html-checkbox-types)))))
2466 (defun org-html-format-list-item (contents type checkbox info
2467 &optional term-counter-id
2468 headline)
2469 "Format a list item into HTML."
2470 (let ((class (if checkbox
2471 (format " class=\"%s\""
2472 (symbol-name checkbox)) ""))
2473 (checkbox (concat (org-html-checkbox checkbox info)
2474 (and checkbox " ")))
2475 (br (org-html-close-tag "br" nil info)))
2476 (concat
2477 (case type
2478 (ordered
2479 (let* ((counter term-counter-id)
2480 (extra (if counter (format " value=\"%s\"" counter) "")))
2481 (concat
2482 (format "<li%s%s>" class extra)
2483 (when headline (concat headline br)))))
2484 (unordered
2485 (let* ((id term-counter-id)
2486 (extra (if id (format " id=\"%s\"" id) "")))
2487 (concat
2488 (format "<li%s%s>" class extra)
2489 (when headline (concat headline br)))))
2490 (descriptive
2491 (let* ((term term-counter-id))
2492 (setq term (or term "(no term)"))
2493 ;; Check-boxes in descriptive lists are associated to tag.
2494 (concat (format "<dt%s>%s</dt>"
2495 class (concat checkbox term))
2496 "<dd>"))))
2497 (unless (eq type 'descriptive) checkbox)
2498 contents
2499 (case type
2500 (ordered "</li>")
2501 (unordered "</li>")
2502 (descriptive "</dd>")))))
2504 (defun org-html-item (item contents info)
2505 "Transcode an ITEM element from Org to HTML.
2506 CONTENTS holds the contents of the item. INFO is a plist holding
2507 contextual information."
2508 (let* ((plain-list (org-export-get-parent item))
2509 (type (org-element-property :type plain-list))
2510 (counter (org-element-property :counter item))
2511 (checkbox (org-element-property :checkbox item))
2512 (tag (let ((tag (org-element-property :tag item)))
2513 (and tag (org-export-data tag info)))))
2514 (org-html-format-list-item
2515 contents type checkbox info (or tag counter))))
2517 ;;;; Keyword
2519 (defun org-html-keyword (keyword contents info)
2520 "Transcode a KEYWORD element from Org to HTML.
2521 CONTENTS is nil. INFO is a plist holding contextual information."
2522 (let ((key (org-element-property :key keyword))
2523 (value (org-element-property :value keyword)))
2524 (cond
2525 ((string= key "HTML") value)
2526 ((string= key "TOC")
2527 (let ((value (downcase value)))
2528 (cond
2529 ((string-match "\\<headlines\\>" value)
2530 (let ((depth (or (and (string-match "[0-9]+" value)
2531 (string-to-number (match-string 0 value)))
2532 (plist-get info :with-toc))))
2533 (org-html-toc depth info)))
2534 ((string= "listings" value) (org-html-list-of-listings info))
2535 ((string= "tables" value) (org-html-list-of-tables info))))))))
2537 ;;;; Latex Environment
2539 (defun org-html-format-latex (latex-frag processing-type info)
2540 "Format a LaTeX fragment LATEX-FRAG into HTML.
2541 PROCESSING-TYPE designates the tool used for conversion. It is
2542 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2543 and t. See `org-html-with-latex' for more information. INFO is
2544 a plist containing export properties."
2545 (let ((cache-relpath "") (cache-dir ""))
2546 (unless (eq processing-type 'mathjax)
2547 (let ((bfn (or (buffer-file-name)
2548 (make-temp-name
2549 (expand-file-name "latex" temporary-file-directory))))
2550 (latex-header
2551 (let ((header (plist-get info :latex-header)))
2552 (and header
2553 (concat (mapconcat
2554 (lambda (line) (concat "#+LATEX_HEADER: " line))
2555 (org-split-string header "\n")
2556 "\n")
2557 "\n")))))
2558 (setq cache-relpath
2559 (concat "ltxpng/"
2560 (file-name-sans-extension
2561 (file-name-nondirectory bfn)))
2562 cache-dir (file-name-directory bfn))
2563 ;; Re-create LaTeX environment from original buffer in
2564 ;; temporary buffer so that dvipng/imagemagick can properly
2565 ;; turn the fragment into an image.
2566 (setq latex-frag (concat latex-header latex-frag))))
2567 (with-temp-buffer
2568 (insert latex-frag)
2569 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2570 nil nil processing-type)
2571 (buffer-string))))
2573 (defun org-html-latex-environment (latex-environment contents info)
2574 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2575 CONTENTS is nil. INFO is a plist holding contextual information."
2576 (let ((processing-type (plist-get info :with-latex))
2577 (latex-frag (org-remove-indentation
2578 (org-element-property :value latex-environment)))
2579 (attributes (org-export-read-attribute :attr_html latex-environment)))
2580 (case processing-type
2581 ((t mathjax)
2582 (org-html-format-latex latex-frag 'mathjax info))
2583 ((dvipng imagemagick)
2584 (let ((formula-link
2585 (org-html-format-latex latex-frag processing-type info)))
2586 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2587 ;; Do not provide a caption or a name to be consistent with
2588 ;; `mathjax' handling.
2589 (org-html--wrap-image
2590 (org-html--format-image
2591 (match-string 1 formula-link) attributes info) info))))
2592 (t latex-frag))))
2594 ;;;; Latex Fragment
2596 (defun org-html-latex-fragment (latex-fragment contents info)
2597 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2598 CONTENTS is nil. INFO is a plist holding contextual information."
2599 (let ((latex-frag (org-element-property :value latex-fragment))
2600 (processing-type (plist-get info :with-latex)))
2601 (case processing-type
2602 ((t mathjax)
2603 (org-html-format-latex latex-frag 'mathjax info))
2604 ((dvipng imagemagick)
2605 (let ((formula-link
2606 (org-html-format-latex latex-frag processing-type info)))
2607 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2608 (org-html--format-image (match-string 1 formula-link) nil info))))
2609 (t latex-frag))))
2611 ;;;; Line Break
2613 (defun org-html-line-break (line-break contents info)
2614 "Transcode a LINE-BREAK object from Org to HTML.
2615 CONTENTS is nil. INFO is a plist holding contextual information."
2616 (concat (org-html-close-tag "br" nil info) "\n"))
2618 ;;;; Link
2620 (defun org-html-inline-image-p (link info)
2621 "Non-nil when LINK is meant to appear as an image.
2622 INFO is a plist used as a communication channel. LINK is an
2623 inline image when it has no description and targets an image
2624 file (see `org-html-inline-image-rules' for more information), or
2625 if its description is a single link targeting an image file."
2626 (if (not (org-element-contents link))
2627 (org-export-inline-image-p
2628 link (plist-get info :html-inline-image-rules))
2629 (not
2630 (let ((link-count 0))
2631 (org-element-map (org-element-contents link)
2632 (cons 'plain-text org-element-all-objects)
2633 (lambda (obj)
2634 (case (org-element-type obj)
2635 (plain-text (org-string-nw-p obj))
2636 (link (if (= link-count 1) t
2637 (incf link-count)
2638 (not (org-export-inline-image-p
2639 obj (plist-get info :html-inline-image-rules)))))
2640 (otherwise t)))
2641 info t)))))
2643 (defvar org-html-standalone-image-predicate)
2644 (defun org-html-standalone-image-p (element info)
2645 "Non-nil if ELEMENT is a standalone image.
2647 INFO is a plist holding contextual information.
2649 An element or object is a standalone image when
2651 - its type is `paragraph' and its sole content, save for white
2652 spaces, is a link that qualifies as an inline image;
2654 - its type is `link' and its containing paragraph has no other
2655 content save white spaces.
2657 Bind `org-html-standalone-image-predicate' to constrain paragraph
2658 further. For example, to check for only captioned standalone
2659 images, set it to:
2661 \(lambda (paragraph) (org-element-property :caption paragraph))"
2662 (let ((paragraph (case (org-element-type element)
2663 (paragraph element)
2664 (link (org-export-get-parent element)))))
2665 (and (eq (org-element-type paragraph) 'paragraph)
2666 (or (not (fboundp 'org-html-standalone-image-predicate))
2667 (funcall org-html-standalone-image-predicate paragraph))
2668 (catch 'exit
2669 (let ((link-count 0))
2670 (org-element-map (org-element-contents paragraph)
2671 (cons 'plain-text org-element-all-objects)
2672 #'(lambda (obj)
2673 (when (case (org-element-type obj)
2674 (plain-text (org-string-nw-p obj))
2675 (link (or (> (incf link-count) 1)
2676 (not (org-html-inline-image-p obj info))))
2677 (otherwise t))
2678 (throw 'exit nil)))
2679 info nil 'link)
2680 (= link-count 1))))))
2682 (defun org-html-link (link desc info)
2683 "Transcode a LINK object from Org to HTML.
2685 DESC is the description part of the link, or the empty string.
2686 INFO is a plist holding contextual information. See
2687 `org-export-data'."
2688 (let* ((home (when (plist-get info :html-link-home)
2689 (org-trim (plist-get info :html-link-home))))
2690 (use-abs-url (plist-get info :html-link-use-abs-url))
2691 (link-org-files-as-html-maybe
2692 (function
2693 (lambda (raw-path info)
2694 "Treat links to `file.org' as links to `file.html', if needed.
2695 See `org-html-link-org-files-as-html'."
2696 (cond
2697 ((and (plist-get info :html-link-org-files-as-html)
2698 (string= ".org"
2699 (downcase (file-name-extension raw-path "."))))
2700 (concat (file-name-sans-extension raw-path) "."
2701 (plist-get info :html-extension)))
2702 (t raw-path)))))
2703 (type (org-element-property :type link))
2704 (raw-path (org-element-property :path link))
2705 ;; Ensure DESC really exists, or set it to nil.
2706 (desc (org-string-nw-p desc))
2707 (path
2708 (cond
2709 ((member type '("http" "https" "ftp" "mailto"))
2710 (org-link-escape-browser
2711 (org-link-unescape (concat type ":" raw-path))))
2712 ((string= type "file")
2713 ;; Treat links to ".org" files as ".html", if needed.
2714 (setq raw-path
2715 (funcall link-org-files-as-html-maybe raw-path info))
2716 ;; If file path is absolute, prepend it with protocol
2717 ;; component - "file:".
2718 (cond
2719 ((file-name-absolute-p raw-path)
2720 (setq raw-path (concat "file:" raw-path)))
2721 ((and home use-abs-url)
2722 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2723 ;; Add search option, if any. A search option can be
2724 ;; relative to a custom-id or a headline title. Append
2725 ;; a hash sign to any unresolved option, as it might point
2726 ;; to a target.
2727 (let ((option (org-element-property :search-option link)))
2728 (cond ((not option) raw-path)
2729 ((eq (aref option 0) ?#) (concat raw-path option))
2731 (let ((destination
2732 (org-publish-resolve-external-fuzzy-link
2733 (org-element-property :path link) option)))
2734 (concat raw-path
2735 (if (not destination) (concat "#" option)
2736 (concat "#sec-"
2737 (mapconcat #'number-to-string
2738 destination "-")))))))))
2739 (t raw-path)))
2740 ;; Extract attributes from parent's paragraph. HACK: Only do
2741 ;; this for the first link in parent (inner image link for
2742 ;; inline images). This is needed as long as attributes
2743 ;; cannot be set on a per link basis.
2744 (attributes-plist
2745 (let* ((parent (org-export-get-parent-element link))
2746 (link (let ((container (org-export-get-parent link)))
2747 (if (and (eq (org-element-type container) 'link)
2748 (org-html-inline-image-p link info))
2749 container
2750 link))))
2751 (and (eq (org-element-map parent 'link 'identity info t) link)
2752 (org-export-read-attribute :attr_html parent))))
2753 (attributes
2754 (let ((attr (org-html--make-attribute-string attributes-plist)))
2755 (if (org-string-nw-p attr) (concat " " attr) "")))
2756 protocol)
2757 (cond
2758 ;; Image file.
2759 ((and (plist-get info :html-inline-images)
2760 (org-export-inline-image-p
2761 link (plist-get info :html-inline-image-rules)))
2762 (org-html--format-image path attributes-plist info))
2763 ;; Radio target: Transcode target's contents and use them as
2764 ;; link's description.
2765 ((string= type "radio")
2766 (let ((destination (org-export-resolve-radio-link link info)))
2767 (when destination
2768 (format "<a href=\"#%s\"%s>%s</a>"
2769 (org-export-solidify-link-text
2770 (org-element-property :value destination))
2771 attributes desc))))
2772 ;; Links pointing to a headline: Find destination and build
2773 ;; appropriate referencing command.
2774 ((member type '("custom-id" "fuzzy" "id"))
2775 (let ((destination (if (string= type "fuzzy")
2776 (org-export-resolve-fuzzy-link link info)
2777 (org-export-resolve-id-link link info))))
2778 (case (org-element-type destination)
2779 ;; ID link points to an external file.
2780 (plain-text
2781 (let ((fragment (concat "ID-" path))
2782 ;; Treat links to ".org" files as ".html", if needed.
2783 (path (funcall link-org-files-as-html-maybe
2784 destination info)))
2785 (format "<a href=\"%s#%s\"%s>%s</a>"
2786 path fragment attributes (or desc destination))))
2787 ;; Fuzzy link points nowhere.
2788 ((nil)
2789 (format "<i>%s</i>"
2790 (or desc
2791 (org-export-data
2792 (org-element-property :raw-link link) info))))
2793 ;; Link points to a headline.
2794 (headline
2795 (let ((href
2796 ;; What href to use?
2797 (cond
2798 ;; Case 1: Headline is linked via it's CUSTOM_ID
2799 ;; property. Use CUSTOM_ID.
2800 ((string= type "custom-id")
2801 (org-element-property :CUSTOM_ID destination))
2802 ;; Case 2: Headline is linked via it's ID property
2803 ;; or through other means. Use the default href.
2804 ((member type '("id" "fuzzy"))
2805 (format "sec-%s"
2806 (mapconcat 'number-to-string
2807 (org-export-get-headline-number
2808 destination info) "-")))
2809 (t (error "Shouldn't reach here"))))
2810 ;; What description to use?
2811 (desc
2812 ;; Case 1: Headline is numbered and LINK has no
2813 ;; description. Display section number.
2814 (if (and (org-export-numbered-headline-p destination info)
2815 (not desc))
2816 (mapconcat 'number-to-string
2817 (org-export-get-headline-number
2818 destination info) ".")
2819 ;; Case 2: Either the headline is un-numbered or
2820 ;; LINK has a custom description. Display LINK's
2821 ;; description or headline's title.
2822 (or desc (org-export-data (org-element-property
2823 :title destination) info)))))
2824 (format "<a href=\"#%s\"%s>%s</a>"
2825 (org-export-solidify-link-text href) attributes desc)))
2826 ;; Fuzzy link points to a target or an element.
2828 (let* ((path (org-export-solidify-link-text path))
2829 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2830 (number (cond
2831 (desc nil)
2832 ((org-html-standalone-image-p destination info)
2833 (org-export-get-ordinal
2834 (org-element-map destination 'link
2835 'identity info t)
2836 info 'link 'org-html-standalone-image-p))
2837 (t (org-export-get-ordinal
2838 destination info nil 'org-html--has-caption-p))))
2839 (desc (cond (desc)
2840 ((not number) "No description for this link")
2841 ((numberp number) (number-to-string number))
2842 (t (mapconcat 'number-to-string number ".")))))
2843 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2844 ;; Coderef: replace link with the reference name or the
2845 ;; equivalent line number.
2846 ((string= type "coderef")
2847 (let ((fragment (concat "coderef-" path)))
2848 (format "<a href=\"#%s\"%s%s>%s</a>"
2849 fragment
2850 (org-trim
2851 (format (concat "class=\"coderef\""
2852 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2853 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2854 fragment fragment))
2855 attributes
2856 (format (org-export-get-coderef-format path desc)
2857 (org-export-resolve-coderef path info)))))
2858 ;; Link type is handled by a special function.
2859 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2860 (funcall protocol (org-link-unescape path) desc 'html))
2861 ;; External link with a description part.
2862 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2863 ;; External link without a description part.
2864 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2865 ;; No path, only description. Try to do something useful.
2866 (t (format "<i>%s</i>" desc)))))
2868 ;;;; Node Property
2870 (defun org-html-node-property (node-property contents info)
2871 "Transcode a NODE-PROPERTY element from Org to HTML.
2872 CONTENTS is nil. INFO is a plist holding contextual
2873 information."
2874 (format "%s:%s"
2875 (org-element-property :key node-property)
2876 (let ((value (org-element-property :value node-property)))
2877 (if value (concat " " value) ""))))
2879 ;;;; Paragraph
2881 (defun org-html-paragraph (paragraph contents info)
2882 "Transcode a PARAGRAPH element from Org to HTML.
2883 CONTENTS is the contents of the paragraph, as a string. INFO is
2884 the plist used as a communication channel."
2885 (let* ((parent (org-export-get-parent paragraph))
2886 (parent-type (org-element-type parent))
2887 (style '((footnote-definition " class=\"footpara\"")))
2888 (attributes (org-html--make-attribute-string
2889 (org-export-read-attribute :attr_html paragraph)))
2890 (extra (or (cadr (assoc parent-type style)) "")))
2891 (cond
2892 ((and (eq (org-element-type parent) 'item)
2893 (= (org-element-property :begin paragraph)
2894 (org-element-property :contents-begin parent))
2895 (not (org-element-map (org-export-get-parent parent) 'item
2896 (lambda (item)
2897 (let ((contents (org-element-contents item)))
2898 (and contents
2899 (or (cdr contents)
2900 (not (eq (org-element-type (car contents))
2901 'paragraph))))))
2902 info 'first-match 'item)))
2903 ;; Leading paragraph in a list item have no tags if every
2904 ;; element of the containing list is only a single paragraph.
2905 contents)
2906 ((org-html-standalone-image-p paragraph info)
2907 ;; Standalone image.
2908 (let ((caption
2909 (let ((raw (org-export-data
2910 (org-export-get-caption paragraph) info))
2911 (org-html-standalone-image-predicate
2912 'org-html--has-caption-p))
2913 (if (not (org-string-nw-p raw)) raw
2914 (concat
2915 "<span class=\"figure-number\">"
2916 (format (org-html--translate "Figure %d:" info)
2917 (org-export-get-ordinal
2918 (org-element-map paragraph 'link
2919 'identity info t)
2920 info nil 'org-html-standalone-image-p))
2921 "</span> " raw))))
2922 (label (org-element-property :name paragraph)))
2923 (org-html--wrap-image contents info caption label)))
2924 ;; Regular paragraph.
2925 (t (format "<p%s%s>\n%s</p>"
2926 (if (org-string-nw-p attributes)
2927 (concat " " attributes) "")
2928 extra contents)))))
2930 ;;;; Plain List
2932 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2933 ;; the correct value for the item counter
2934 (defun org-html-begin-plain-list (type &optional arg1)
2935 "Insert the beginning of the HTML list depending on TYPE.
2936 When ARG1 is a string, use it as the start parameter for ordered
2937 lists."
2938 (case type
2939 (ordered
2940 (format "<ol class=\"org-ol\"%s>"
2941 (if arg1 (format " start=\"%d\"" arg1) "")))
2942 (unordered "<ul class=\"org-ul\">")
2943 (descriptive "<dl class=\"org-dl\">")))
2945 (defun org-html-end-plain-list (type)
2946 "Insert the end of the HTML list depending on TYPE."
2947 (case type
2948 (ordered "</ol>")
2949 (unordered "</ul>")
2950 (descriptive "</dl>")))
2952 (defun org-html-plain-list (plain-list contents info)
2953 "Transcode a PLAIN-LIST element from Org to HTML.
2954 CONTENTS is the contents of the list. INFO is a plist holding
2955 contextual information."
2956 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2957 (type (org-element-property :type plain-list)))
2958 (format "%s\n%s%s"
2959 (org-html-begin-plain-list type)
2960 contents (org-html-end-plain-list type))))
2962 ;;;; Plain Text
2964 (defun org-html-convert-special-strings (string)
2965 "Convert special characters in STRING to HTML."
2966 (let ((all org-html-special-string-regexps)
2967 e a re rpl start)
2968 (while (setq a (pop all))
2969 (setq re (car a) rpl (cdr a) start 0)
2970 (while (string-match re string start)
2971 (setq string (replace-match rpl t nil string))))
2972 string))
2974 (defun org-html-encode-plain-text (text)
2975 "Convert plain text characters from TEXT to HTML equivalent.
2976 Possible conversions are set in `org-html-protect-char-alist'."
2977 (mapc
2978 (lambda (pair)
2979 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2980 org-html-protect-char-alist)
2981 text)
2983 (defun org-html-plain-text (text info)
2984 "Transcode a TEXT string from Org to HTML.
2985 TEXT is the string to transcode. INFO is a plist holding
2986 contextual information."
2987 (let ((output text))
2988 ;; Protect following characters: <, >, &.
2989 (setq output (org-html-encode-plain-text output))
2990 ;; Handle smart quotes. Be sure to provide original string since
2991 ;; OUTPUT may have been modified.
2992 (when (plist-get info :with-smart-quotes)
2993 (setq output (org-export-activate-smart-quotes output :html info text)))
2994 ;; Handle special strings.
2995 (when (plist-get info :with-special-strings)
2996 (setq output (org-html-convert-special-strings output)))
2997 ;; Handle break preservation if required.
2998 (when (plist-get info :preserve-breaks)
2999 (setq output
3000 (replace-regexp-in-string
3001 "\\(\\\\\\\\\\)?[ \t]*\n"
3002 (concat (org-html-close-tag "br" nil info) "\n") output)))
3003 ;; Return value.
3004 output))
3007 ;; Planning
3009 (defun org-html-planning (planning contents info)
3010 "Transcode a PLANNING element from Org to HTML.
3011 CONTENTS is nil. INFO is a plist used as a communication
3012 channel."
3013 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
3014 (format
3015 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3016 (mapconcat
3017 'identity
3018 (delq nil
3019 (list
3020 (let ((closed (org-element-property :closed planning)))
3021 (when closed
3022 (format span-fmt org-closed-string
3023 (org-translate-time
3024 (org-element-property :raw-value closed)))))
3025 (let ((deadline (org-element-property :deadline planning)))
3026 (when deadline
3027 (format span-fmt org-deadline-string
3028 (org-translate-time
3029 (org-element-property :raw-value deadline)))))
3030 (let ((scheduled (org-element-property :scheduled planning)))
3031 (when scheduled
3032 (format span-fmt org-scheduled-string
3033 (org-translate-time
3034 (org-element-property :raw-value scheduled)))))))
3035 " "))))
3037 ;;;; Property Drawer
3039 (defun org-html-property-drawer (property-drawer contents info)
3040 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3041 CONTENTS holds the contents of the drawer. INFO is a plist
3042 holding contextual information."
3043 (and (org-string-nw-p contents)
3044 (format "<pre class=\"example\">\n%s</pre>" contents)))
3046 ;;;; Quote Block
3048 (defun org-html-quote-block (quote-block contents info)
3049 "Transcode a QUOTE-BLOCK element from Org to HTML.
3050 CONTENTS holds the contents of the block. INFO is a plist
3051 holding contextual information."
3052 (format "<blockquote>\n%s</blockquote>" contents))
3054 ;;;; Section
3056 (defun org-html-section (section contents info)
3057 "Transcode a SECTION element from Org to HTML.
3058 CONTENTS holds the contents of the section. INFO is a plist
3059 holding contextual information."
3060 (let ((parent (org-export-get-parent-headline section)))
3061 ;; Before first headline: no container, just return CONTENTS.
3062 (if (not parent) contents
3063 ;; Get div's class and id references.
3064 (let* ((class-num (+ (org-export-get-relative-level parent info)
3065 (1- (plist-get info :html-toplevel-hlevel))))
3066 (section-number
3067 (mapconcat
3068 'number-to-string
3069 (org-export-get-headline-number parent info) "-")))
3070 ;; Build return value.
3071 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3072 class-num
3073 (or (org-element-property :CUSTOM_ID parent) section-number)
3074 contents)))))
3076 ;;;; Radio Target
3078 (defun org-html-radio-target (radio-target text info)
3079 "Transcode a RADIO-TARGET object from Org to HTML.
3080 TEXT is the text of the target. INFO is a plist holding
3081 contextual information."
3082 (let ((id (org-export-solidify-link-text
3083 (org-element-property :value radio-target))))
3084 (org-html--anchor id text nil info)))
3086 ;;;; Special Block
3088 (defun org-html-special-block (special-block contents info)
3089 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3090 CONTENTS holds the contents of the block. INFO is a plist
3091 holding contextual information."
3092 (if (org-export-raw-special-block-p special-block info)
3093 (org-remove-indentation (org-element-property :raw-value special-block))
3094 (let* ((block-type (downcase (org-element-property :type special-block)))
3095 (contents (or contents ""))
3096 (html5-fancy (and (org-html-html5-p info)
3097 (plist-get info :html-html5-fancy)
3098 (member block-type org-html-html5-elements)))
3099 (attributes (org-export-read-attribute :attr_html special-block)))
3100 (unless html5-fancy
3101 (let ((class (plist-get attributes :class)))
3102 (setq attributes (plist-put attributes :class
3103 (if class (concat class " " block-type)
3104 block-type)))))
3105 (setq attributes (org-html--make-attribute-string attributes))
3106 (when (not (equal attributes ""))
3107 (setq attributes (concat " " attributes)))
3108 (if html5-fancy
3109 (format "<%s%s>\n%s</%s>" block-type attributes contents block-type)
3110 (format "<div%s>\n%s\n</div>" attributes contents)))))
3112 ;;;; Src Block
3114 (defun org-html-src-block (src-block contents info)
3115 "Transcode a SRC-BLOCK element from Org to HTML.
3116 CONTENTS holds the contents of the item. INFO is a plist holding
3117 contextual information."
3118 (if (org-export-read-attribute :attr_html src-block :textarea)
3119 (org-html--textarea-block src-block)
3120 (let ((lang (org-element-property :language src-block))
3121 (caption (org-export-get-caption src-block))
3122 (code (org-html-format-code src-block info))
3123 (label (let ((lbl (org-element-property :name src-block)))
3124 (if (not lbl) ""
3125 (format " id=\"%s\""
3126 (org-export-solidify-link-text lbl))))))
3127 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3128 (format
3129 "<div class=\"org-src-container\">\n%s%s\n</div>"
3130 (if (not caption) ""
3131 (format "<label class=\"org-src-name\">%s</label>"
3132 (org-export-data caption info)))
3133 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3135 ;;;; Statistics Cookie
3137 (defun org-html-statistics-cookie (statistics-cookie contents info)
3138 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3139 CONTENTS is nil. INFO is a plist holding contextual information."
3140 (let ((cookie-value (org-element-property :value statistics-cookie)))
3141 (format "<code>%s</code>" cookie-value)))
3143 ;;;; Strike-Through
3145 (defun org-html-strike-through (strike-through contents info)
3146 "Transcode STRIKE-THROUGH from Org to HTML.
3147 CONTENTS is the text with strike-through markup. INFO is a plist
3148 holding contextual information."
3149 (format
3150 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3151 "%s")
3152 contents))
3154 ;;;; Subscript
3156 (defun org-html-subscript (subscript contents info)
3157 "Transcode a SUBSCRIPT object from Org to HTML.
3158 CONTENTS is the contents of the object. INFO is a plist holding
3159 contextual information."
3160 (format "<sub>%s</sub>" contents))
3162 ;;;; Superscript
3164 (defun org-html-superscript (superscript contents info)
3165 "Transcode a SUPERSCRIPT object from Org to HTML.
3166 CONTENTS is the contents of the object. INFO is a plist holding
3167 contextual information."
3168 (format "<sup>%s</sup>" contents))
3170 ;;;; Table Cell
3172 (defun org-html-table-cell (table-cell contents info)
3173 "Transcode a TABLE-CELL element from Org to HTML.
3174 CONTENTS is nil. INFO is a plist used as a communication
3175 channel."
3176 (let* ((table-row (org-export-get-parent table-cell))
3177 (table (org-export-get-parent-table table-cell))
3178 (cell-attrs
3179 (if (not (plist-get info :html-table-align-individual-fields)) ""
3180 (format (if (and (boundp 'org-html-format-table-no-css)
3181 org-html-format-table-no-css)
3182 " align=\"%s\"" " class=\"%s\"")
3183 (org-export-table-cell-alignment table-cell info)))))
3184 (when (or (not contents) (string= "" (org-trim contents)))
3185 (setq contents "&#xa0;"))
3186 (cond
3187 ((and (org-export-table-has-header-p table info)
3188 (= 1 (org-export-table-row-group table-row info)))
3189 (let ((header-tags (plist-get info :html-table-header-tags)))
3190 (concat "\n" (format (car header-tags) "col" cell-attrs)
3191 contents
3192 (cdr header-tags))))
3193 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3194 (zerop (cdr (org-export-table-cell-address table-cell info))))
3195 (let ((header-tags (plist-get info :html-table-header-tags)))
3196 (concat "\n" (format (car header-tags) "row" cell-attrs)
3197 contents
3198 (cdr header-tags))))
3199 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3200 (concat "\n" (format (car data-tags) cell-attrs)
3201 contents
3202 (cdr data-tags)))))))
3204 ;;;; Table Row
3206 (defun org-html-table-row (table-row contents info)
3207 "Transcode a TABLE-ROW element from Org to HTML.
3208 CONTENTS is the contents of the row. INFO is a plist used as a
3209 communication channel."
3210 ;; Rules are ignored since table separators are deduced from
3211 ;; borders of the current row.
3212 (when (eq (org-element-property :type table-row) 'standard)
3213 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3214 (row-number (org-export-table-row-number table-row info))
3215 (start-rowgroup-p
3216 (org-export-table-row-starts-rowgroup-p table-row info))
3217 (end-rowgroup-p
3218 (org-export-table-row-ends-rowgroup-p table-row info))
3219 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3220 ;; but should be set so that `org-html-table-row-tags' can
3221 ;; use them (see the docstring of this variable.)
3222 (top-row-p (and (equal start-rowgroup-p '(top))
3223 (equal end-rowgroup-p '(below top))))
3224 (bottom-row-p (and (equal start-rowgroup-p '(above))
3225 (equal end-rowgroup-p '(bottom above))))
3226 (rowgroup-tags
3227 (cond
3228 ;; Case 1: Row belongs to second or subsequent rowgroups.
3229 ((not (= 1 rowgroup-number))
3230 '("<tbody>" . "\n</tbody>"))
3231 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3232 ((org-export-table-has-header-p
3233 (org-export-get-parent-table table-row) info)
3234 '("<thead>" . "\n</thead>"))
3235 ;; Case 2: Row is from first and only row group.
3236 (t '("<tbody>" . "\n</tbody>")))))
3237 (concat
3238 ;; Begin a rowgroup?
3239 (when start-rowgroup-p (car rowgroup-tags))
3240 ;; Actual table row
3241 (concat "\n" (eval (car (plist-get info :html-table-row-tags)))
3242 contents
3243 "\n"
3244 (eval (cdr (plist-get info :html-table-row-tags))))
3245 ;; End a rowgroup?
3246 (when end-rowgroup-p (cdr rowgroup-tags))))))
3248 ;;;; Table
3250 (defun org-html-table-first-row-data-cells (table info)
3251 "Transcode the first row of TABLE.
3252 INFO is a plist used as a communication channel."
3253 (let ((table-row
3254 (org-element-map table 'table-row
3255 (lambda (row)
3256 (unless (eq (org-element-property :type row) 'rule) row))
3257 info 'first-match))
3258 (special-column-p (org-export-table-has-special-column-p table)))
3259 (if (not special-column-p) (org-element-contents table-row)
3260 (cdr (org-element-contents table-row)))))
3262 (defun org-html-table--table.el-table (table info)
3263 "Format table.el tables into HTML.
3264 INFO is a plist used as a communication channel."
3265 (when (eq (org-element-property :type table) 'table.el)
3266 (require 'table)
3267 (let ((outbuf (with-current-buffer
3268 (get-buffer-create "*org-export-table*")
3269 (erase-buffer) (current-buffer))))
3270 (with-temp-buffer
3271 (insert (org-element-property :value table))
3272 (goto-char 1)
3273 (re-search-forward "^[ \t]*|[^|]" nil t)
3274 (table-generate-source 'html outbuf))
3275 (with-current-buffer outbuf
3276 (prog1 (org-trim (buffer-string))
3277 (kill-buffer) )))))
3279 (defun org-html-table (table contents info)
3280 "Transcode a TABLE element from Org to HTML.
3281 CONTENTS is the contents of the table. INFO is a plist holding
3282 contextual information."
3283 (case (org-element-property :type table)
3284 ;; Case 1: table.el table. Convert it using appropriate tools.
3285 (table.el (org-html-table--table.el-table table info))
3286 ;; Case 2: Standard table.
3288 (let* ((label (org-element-property :name table))
3289 (caption (org-export-get-caption table))
3290 (number (org-export-get-ordinal
3291 table info nil 'org-html--has-caption-p))
3292 (attributes
3293 (org-html--make-attribute-string
3294 (org-combine-plists
3295 (and label (list :id (org-export-solidify-link-text label)))
3296 (and (not (org-html-html5-p info))
3297 (plist-get info :html-table-attributes))
3298 (org-export-read-attribute :attr_html table))))
3299 (alignspec
3300 (if (and (boundp 'org-html-format-table-no-css)
3301 org-html-format-table-no-css)
3302 "align=\"%s\"" "class=\"%s\""))
3303 (table-column-specs
3304 (function
3305 (lambda (table info)
3306 (mapconcat
3307 (lambda (table-cell)
3308 (let ((alignment (org-export-table-cell-alignment
3309 table-cell info)))
3310 (concat
3311 ;; Begin a colgroup?
3312 (when (org-export-table-cell-starts-colgroup-p
3313 table-cell info)
3314 "\n<colgroup>")
3315 ;; Add a column. Also specify it's alignment.
3316 (format "\n%s"
3317 (org-html-close-tag
3318 "col" (concat " " (format alignspec alignment)) info))
3319 ;; End a colgroup?
3320 (when (org-export-table-cell-ends-colgroup-p
3321 table-cell info)
3322 "\n</colgroup>"))))
3323 (org-html-table-first-row-data-cells table info) "\n")))))
3324 (format "<table%s>\n%s\n%s\n%s</table>"
3325 (if (equal attributes "") "" (concat " " attributes))
3326 (if (not caption) ""
3327 (format (if (plist-get info :html-table-caption-above)
3328 "<caption class=\"t-above\">%s</caption>"
3329 "<caption class=\"t-bottom\">%s</caption>")
3330 (concat
3331 "<span class=\"table-number\">"
3332 (format (org-html--translate "Table %d:" info) number)
3333 "</span> " (org-export-data caption info))))
3334 (funcall table-column-specs table info)
3335 contents)))))
3337 ;;;; Target
3339 (defun org-html-target (target contents info)
3340 "Transcode a TARGET object from Org to HTML.
3341 CONTENTS is nil. INFO is a plist holding contextual
3342 information."
3343 (let ((id (org-export-solidify-link-text
3344 (org-element-property :value target))))
3345 (org-html--anchor id nil nil info)))
3347 ;;;; Timestamp
3349 (defun org-html-timestamp (timestamp contents info)
3350 "Transcode a TIMESTAMP object from Org to HTML.
3351 CONTENTS is nil. INFO is a plist holding contextual
3352 information."
3353 (let ((value (org-html-plain-text
3354 (org-timestamp-translate timestamp) info)))
3355 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3356 (replace-regexp-in-string "--" "&#x2013;" value))))
3358 ;;;; Underline
3360 (defun org-html-underline (underline contents info)
3361 "Transcode UNDERLINE from Org to HTML.
3362 CONTENTS is the text with underline markup. INFO is a plist
3363 holding contextual information."
3364 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3365 "%s")
3366 contents))
3368 ;;;; Verbatim
3370 (defun org-html-verbatim (verbatim contents info)
3371 "Transcode VERBATIM from Org to HTML.
3372 CONTENTS is nil. INFO is a plist holding contextual
3373 information."
3374 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3375 (org-html-encode-plain-text (org-element-property :value verbatim))))
3377 ;;;; Verse Block
3379 (defun org-html-verse-block (verse-block contents info)
3380 "Transcode a VERSE-BLOCK element from Org to HTML.
3381 CONTENTS is verse block contents. INFO is a plist holding
3382 contextual information."
3383 ;; Replace each newline character with line break. Also replace
3384 ;; each blank line with a line break.
3385 (setq contents (replace-regexp-in-string
3386 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3387 (replace-regexp-in-string
3388 "\\(\\\\\\\\\\)?[ \t]*\n"
3389 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3390 ;; Replace each white space at beginning of a line with a
3391 ;; non-breaking space.
3392 (while (string-match "^[ \t]+" contents)
3393 (let* ((num-ws (length (match-string 0 contents)))
3394 (ws (let (out) (dotimes (i num-ws out)
3395 (setq out (concat out "&#xa0;"))))))
3396 (setq contents (replace-match ws nil t contents))))
3397 (format "<p class=\"verse\">\n%s</p>" contents))
3400 ;;; Filter Functions
3402 (defun org-html-final-function (contents backend info)
3403 "Filter to indent the HTML and convert HTML entities."
3404 (with-temp-buffer
3405 (insert contents)
3406 (set-auto-mode t)
3407 (if (plist-get info :html-indent)
3408 (indent-region (point-min) (point-max)))
3409 (when (plist-get info :html-use-unicode-chars)
3410 (require 'mm-url)
3411 (mm-url-decode-entities))
3412 (buffer-substring-no-properties (point-min) (point-max))))
3415 ;;; End-user functions
3417 ;;;###autoload
3418 (defun org-html-export-as-html
3419 (&optional async subtreep visible-only body-only ext-plist)
3420 "Export current buffer to an HTML buffer.
3422 If narrowing is active in the current buffer, only export its
3423 narrowed part.
3425 If a region is active, export that region.
3427 A non-nil optional argument ASYNC means the process should happen
3428 asynchronously. The resulting buffer should be accessible
3429 through the `org-export-stack' interface.
3431 When optional argument SUBTREEP is non-nil, export the sub-tree
3432 at point, extracting information from the headline properties
3433 first.
3435 When optional argument VISIBLE-ONLY is non-nil, don't export
3436 contents of hidden elements.
3438 When optional argument BODY-ONLY is non-nil, only write code
3439 between \"<body>\" and \"</body>\" tags.
3441 EXT-PLIST, when provided, is a property list with external
3442 parameters overriding Org default settings, but still inferior to
3443 file-local settings.
3445 Export is done in a buffer named \"*Org HTML Export*\", which
3446 will be displayed when `org-export-show-temporary-export-buffer'
3447 is non-nil."
3448 (interactive)
3449 (org-export-to-buffer 'html "*Org HTML Export*"
3450 async subtreep visible-only body-only ext-plist
3451 (lambda () (set-auto-mode t))))
3453 ;;;###autoload
3454 (defun org-html-convert-region-to-html ()
3455 "Assume the current region has org-mode syntax, and convert it to HTML.
3456 This can be used in any buffer. For example, you can write an
3457 itemized list in org-mode syntax in an HTML buffer and use this
3458 command to convert it."
3459 (interactive)
3460 (org-export-replace-region-by 'html))
3462 ;;;###autoload
3463 (defun org-html-export-to-html
3464 (&optional async subtreep visible-only body-only ext-plist)
3465 "Export current buffer to a HTML file.
3467 If narrowing is active in the current buffer, only export its
3468 narrowed part.
3470 If a region is active, export that region.
3472 A non-nil optional argument ASYNC means the process should happen
3473 asynchronously. The resulting file should be accessible through
3474 the `org-export-stack' interface.
3476 When optional argument SUBTREEP is non-nil, export the sub-tree
3477 at point, extracting information from the headline properties
3478 first.
3480 When optional argument VISIBLE-ONLY is non-nil, don't export
3481 contents of hidden elements.
3483 When optional argument BODY-ONLY is non-nil, only write code
3484 between \"<body>\" and \"</body>\" tags.
3486 EXT-PLIST, when provided, is a property list with external
3487 parameters overriding Org default settings, but still inferior to
3488 file-local settings.
3490 Return output file's name."
3491 (interactive)
3492 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3493 org-html-extension
3494 "html")))
3495 (file (org-export-output-file-name extension subtreep))
3496 (org-export-coding-system org-html-coding-system))
3497 (org-export-to-file 'html file
3498 async subtreep visible-only body-only ext-plist)))
3500 ;;;###autoload
3501 (defun org-html-publish-to-html (plist filename pub-dir)
3502 "Publish an org file to HTML.
3504 FILENAME is the filename of the Org file to be published. PLIST
3505 is the property list for the given project. PUB-DIR is the
3506 publishing directory.
3508 Return output file name."
3509 (org-publish-org-to 'html filename
3510 (concat "." (or (plist-get plist :html-extension)
3511 org-html-extension
3512 "html"))
3513 plist pub-dir))
3516 (provide 'ox-html)
3518 ;; Local variables:
3519 ;; generated-autoload-file: "org-loaddefs.el"
3520 ;; End:
3522 ;;; ox-html.el ends here