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