Merge export and special blocks within back-ends
[org-mode.git] / lisp / ox-html.el
blob630c65df8f74004b5293882a1d8e434fa19b99fd
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; See Org manual for more information.
29 ;;; Code:
31 ;;; Dependencies
33 (require 'ox)
34 (require 'ox-publish)
35 (require 'format-spec)
36 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
39 ;;; Function Declarations
41 (declare-function org-id-find-id-file "org-id" (id))
42 (declare-function htmlize-region "ext:htmlize" (beg end))
43 (declare-function org-pop-to-buffer-same-window
44 "org-compat" (&optional buffer-or-name norecord label))
45 (declare-function mm-url-decode-entities "mm-url" ())
47 ;;; Define Back-End
49 (org-export-define-backend 'html
50 '((bold . org-html-bold)
51 (center-block . org-html-center-block)
52 (clock . org-html-clock)
53 (code . org-html-code)
54 (drawer . org-html-drawer)
55 (dynamic-block . org-html-dynamic-block)
56 (entity . org-html-entity)
57 (example-block . org-html-example-block)
58 (export-snippet . org-html-export-snippet)
59 (fixed-width . org-html-fixed-width)
60 (footnote-definition . org-html-footnote-definition)
61 (footnote-reference . org-html-footnote-reference)
62 (headline . org-html-headline)
63 (horizontal-rule . org-html-horizontal-rule)
64 (inline-src-block . org-html-inline-src-block)
65 (inlinetask . org-html-inlinetask)
66 (inner-template . org-html-inner-template)
67 (italic . org-html-italic)
68 (item . org-html-item)
69 (keyword . org-html-keyword)
70 (latex-environment . org-html-latex-environment)
71 (latex-fragment . org-html-latex-fragment)
72 (line-break . org-html-line-break)
73 (link . org-html-link)
74 (node-property . org-html-node-property)
75 (paragraph . org-html-paragraph)
76 (plain-list . org-html-plain-list)
77 (plain-text . org-html-plain-text)
78 (planning . org-html-planning)
79 (property-drawer . org-html-property-drawer)
80 (quote-block . org-html-quote-block)
81 (radio-target . org-html-radio-target)
82 (section . org-html-section)
83 (special-block . org-html-special-block)
84 (src-block . org-html-src-block)
85 (statistics-cookie . org-html-statistics-cookie)
86 (strike-through . org-html-strike-through)
87 (subscript . org-html-subscript)
88 (superscript . org-html-superscript)
89 (table . org-html-table)
90 (table-cell . org-html-table-cell)
91 (table-row . org-html-table-row)
92 (target . org-html-target)
93 (template . org-html-template)
94 (timestamp . org-html-timestamp)
95 (underline . org-html-underline)
96 (verbatim . org-html-verbatim)
97 (verse-block . org-html-verse-block))
98 :export-block "HTML"
99 :filters-alist '((:filter-options . org-html-infojs-install-script)
100 (:filter-final-output . org-html-final-function))
101 :menu-entry
102 '(?h "Export to HTML"
103 ((?H "As HTML buffer" org-html-export-as-html)
104 (?h "As HTML file" org-html-export-to-html)
105 (?o "As HTML file and open"
106 (lambda (a s v b)
107 (if a (org-html-export-to-html t s v b)
108 (org-open-file (org-html-export-to-html nil s v b)))))))
109 :options-alist
110 '((:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
111 (:html-container "HTML_CONTAINER" nil org-html-container-element)
112 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
113 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
114 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
115 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
116 (:html-head "HTML_HEAD" nil org-html-head newline)
117 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
118 (:html-container "HTML_CONTAINER" nil org-html-container-element)
119 (:html-mathjax "HTML_MATHJAX" nil "" space)
120 (:html-extension nil nil org-html-extension)
121 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
122 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
123 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
124 (:html-postamble nil "html-postamble" org-html-postamble)
125 (:html-preamble nil "html-preamble" org-html-preamble)
126 (:html-head "HTML_HEAD" nil org-html-head newline)
127 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
128 (:html-head-include-default-style
129 nil "html-style" org-html-head-include-default-style)
130 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
131 (:html-allow-name-attribute-in-anchors
132 nil nil org-html-allow-name-attribute-in-anchors)
133 (:html-coding-system nil nil org-html-coding-system)
134 (:html-divs nil nil org-html-divs)
135 (:html-extension nil nil org-html-extension)
136 (:html-footnote-format nil nil org-html-footnote-format)
137 (:html-footnote-separator nil nil org-html-footnote-separator)
138 (:html-footnotes-section nil nil org-html-footnotes-section)
139 (:html-format-drawer-function nil nil org-html-format-drawer-function)
140 (:html-format-headline-function nil nil org-html-format-headline-function)
141 (:html-format-inlinetask-function
142 nil nil org-html-format-inlinetask-function)
143 (:html-home/up-format nil nil org-html-home/up-format)
144 (:html-htmlize-font-prefix nil nil org-html-htmlize-font-prefix)
145 (:html-htmlize-output-type nil nil org-html-htmlize-output-type)
146 (:html-indent nil nil org-html-indent)
147 (:html-infojs-options nil nil org-html-infojs-options)
148 (:html-infojs-template nil nil org-html-infojs-template)
149 (:html-inline-image-rules nil nil org-html-inline-image-rules)
150 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
151 (:html-mathjax-options nil nil org-html-mathjax-options)
152 (:html-mathjax-template nil nil org-html-mathjax-template)
153 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
154 (:html-postamble-format nil nil org-html-postamble-format)
155 (:html-preamble-format nil nil org-html-preamble-format)
156 (:html-protect-char-alist nil nil org-html-protect-char-alist)
157 (:html-table-align-individual-fields
158 nil nil org-html-table-align-individual-fields)
159 (:html-table-caption-above nil nil org-html-table-caption-above)
160 (:html-table-data-tags nil nil org-html-table-data-tags)
161 (:html-table-header-tags nil nil org-html-table-header-tags)
162 (:html-table-use-header-tags-for-first-column
163 nil nil org-html-table-use-header-tags-for-first-column)
164 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
165 (:html-text-markup-alist nil nil org-html-text-markup-alist)
166 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
167 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
168 (:html-use-infojs nil nil org-html-use-infojs)
169 (:html-use-unicode-chars nil nil org-html-use-unicode-chars)
170 (:html-validation-link nil nil org-html-validation-link)
171 (:html-inline-images nil nil org-html-inline-images)
172 (:html-table-attributes nil nil org-html-table-default-attributes)
173 (:html-table-row-tags nil nil org-html-table-row-tags)
174 (:html-xml-declaration nil nil org-html-xml-declaration)
175 (:infojs-opt "INFOJS_OPT" nil nil)
176 ;; Redefine regular options.
177 (:creator "CREATOR" nil org-html-creator-string)
178 (:with-latex nil "tex" org-html-with-latex)
179 ;; Retrieve LaTeX header for fragments.
180 (:latex-header "LATEX_HEADER" nil nil newline)))
183 ;;; Internal Variables
185 (defvar org-html-format-table-no-css)
186 (defvar htmlize-buffer-places) ; from htmlize.el
188 (defvar org-html--pre/postamble-class "status"
189 "CSS class used for pre/postamble")
191 (defconst org-html-doctype-alist
192 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
193 \"http://www.w3.org/TR/html4/strict.dtd\">")
194 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
195 \"http://www.w3.org/TR/html4/loose.dtd\">")
196 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
197 \"http://www.w3.org/TR/html4/frameset.dtd\">")
199 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
200 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
201 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
202 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
203 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
204 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
205 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
206 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
208 ("html5" . "<!DOCTYPE html>")
209 ("xhtml5" . "<!DOCTYPE html>"))
210 "An alist mapping (x)html flavors to specific doctypes.")
212 (defconst org-html-html5-elements
213 '("article" "aside" "audio" "canvas" "details" "figcaption"
214 "figure" "footer" "header" "menu" "meter" "nav" "output"
215 "progress" "section" "video")
216 "New elements in html5.
218 For blocks that should contain headlines, use the HTML_CONTAINER
219 property on the headline itself.")
221 (defconst org-html-special-string-regexps
222 '(("\\\\-" . "&#x00ad;") ; shy
223 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
224 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
225 ("\\.\\.\\." . "&#x2026;")) ; hellip
226 "Regular expressions for special string conversion.")
228 (defconst org-html-scripts
229 "<script type=\"text/javascript\">
231 @licstart The following is the entire license notice for the
232 JavaScript code in this tag.
234 Copyright (C) 2012-2013 Free Software Foundation, Inc.
236 The JavaScript code in this tag is free software: you can
237 redistribute it and/or modify it under the terms of the GNU
238 General Public License (GNU GPL) as published by the Free Software
239 Foundation, either version 3 of the License, or (at your option)
240 any later version. The code is distributed WITHOUT ANY WARRANTY;
241 without even the implied warranty of MERCHANTABILITY or FITNESS
242 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
244 As additional permission under GNU GPL version 3 section 7, you
245 may distribute non-source (e.g., minimized or compacted) forms of
246 that code without the copy of the GNU GPL normally required by
247 section 4, provided you include this license notice and a URL
248 through which recipients can access the Corresponding Source.
251 @licend The above is the entire license notice
252 for the JavaScript code in this tag.
254 <!--/*--><![CDATA[/*><!--*/
255 function CodeHighlightOn(elem, id)
257 var target = document.getElementById(id);
258 if(null != target) {
259 elem.cacheClassElem = elem.className;
260 elem.cacheClassTarget = target.className;
261 target.className = \"code-highlighted\";
262 elem.className = \"code-highlighted\";
265 function CodeHighlightOff(elem, id)
267 var target = document.getElementById(id);
268 if(elem.cacheClassElem)
269 elem.className = elem.cacheClassElem;
270 if(elem.cacheClassTarget)
271 target.className = elem.cacheClassTarget;
273 /*]]>*///-->
274 </script>"
275 "Basic JavaScript that is needed by HTML files produced by Org mode.")
277 (defconst org-html-style-default
278 "<style type=\"text/css\">
279 <!--/*--><![CDATA[/*><!--*/
280 .title { text-align: center; }
281 .todo { font-family: monospace; color: red; }
282 .done { color: green; }
283 .tag { background-color: #eee; font-family: monospace;
284 padding: 2px; font-size: 80%; font-weight: normal; }
285 .timestamp { color: #bebebe; }
286 .timestamp-kwd { color: #5f9ea0; }
287 .right { margin-left: auto; margin-right: 0px; text-align: right; }
288 .left { margin-left: 0px; margin-right: auto; text-align: left; }
289 .center { margin-left: auto; margin-right: auto; text-align: center; }
290 .underline { text-decoration: underline; }
291 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
292 p.verse { margin-left: 3%; }
293 pre {
294 border: 1px solid #ccc;
295 box-shadow: 3px 3px 3px #eee;
296 padding: 8pt;
297 font-family: monospace;
298 overflow: auto;
299 margin: 1.2em;
301 pre.src {
302 position: relative;
303 overflow: visible;
304 padding-top: 1.2em;
306 pre.src:before {
307 display: none;
308 position: absolute;
309 background-color: white;
310 top: -10px;
311 right: 10px;
312 padding: 3px;
313 border: 1px solid black;
315 pre.src:hover:before { display: inline;}
316 pre.src-sh:before { content: 'sh'; }
317 pre.src-bash:before { content: 'sh'; }
318 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
319 pre.src-R:before { content: 'R'; }
320 pre.src-perl:before { content: 'Perl'; }
321 pre.src-java:before { content: 'Java'; }
322 pre.src-sql:before { content: 'SQL'; }
324 table { border-collapse:collapse; }
325 caption.t-above { caption-side: top; }
326 caption.t-bottom { caption-side: bottom; }
327 td, th { vertical-align:top; }
328 th.right { text-align: center; }
329 th.left { text-align: center; }
330 th.center { text-align: center; }
331 td.right { text-align: right; }
332 td.left { text-align: left; }
333 td.center { text-align: center; }
334 dt { font-weight: bold; }
335 .footpara:nth-child(2) { display: inline; }
336 .footpara { display: block; }
337 .footdef { margin-bottom: 1em; }
338 .figure { padding: 1em; }
339 .figure p { text-align: center; }
340 .inlinetask {
341 padding: 10px;
342 border: 2px solid gray;
343 margin: 10px;
344 background: #ffffcc;
346 #org-div-home-and-up
347 { text-align: right; font-size: 70%; white-space: nowrap; }
348 textarea { overflow-x: auto; }
349 .linenr { font-size: smaller }
350 .code-highlighted { background-color: #ffff00; }
351 .org-info-js_info-navigation { border-style: none; }
352 #org-info-js_console-label
353 { font-size: 10px; font-weight: bold; white-space: nowrap; }
354 .org-info-js_search-highlight
355 { background-color: #ffff00; color: #000000; font-weight: bold; }
356 /*]]>*/-->
357 </style>"
358 "The default style specification for exported HTML files.
359 You can use `org-html-head' and `org-html-head-extra' to add to
360 this style. If you don't want to include this default style,
361 customize `org-html-head-include-default-style'.")
364 ;;; User Configuration Variables
366 (defgroup org-export-html nil
367 "Options for exporting Org mode files to HTML."
368 :tag "Org Export HTML"
369 :group 'org-export)
371 ;;;; Handle infojs
373 (defvar org-html-infojs-opts-table
374 '((path PATH "http://orgmode.org/org-info.js")
375 (view VIEW "info")
376 (toc TOC :with-toc)
377 (ftoc FIXED_TOC "0")
378 (tdepth TOC_DEPTH "max")
379 (sdepth SECTION_DEPTH "max")
380 (mouse MOUSE_HINT "underline")
381 (buttons VIEW_BUTTONS "0")
382 (ltoc LOCAL_TOC "1")
383 (up LINK_UP :html-link-up)
384 (home LINK_HOME :html-link-home))
385 "JavaScript options, long form for script, default values.")
387 (defcustom org-html-use-infojs 'when-configured
388 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
389 This option can be nil or t to never or always use the script.
390 It can also be the symbol `when-configured', meaning that the
391 script will be linked into the export file if and only if there
392 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
393 `org-html-infojs-options'."
394 :group 'org-export-html
395 :version "24.4"
396 :package-version '(Org . "8.0")
397 :type '(choice
398 (const :tag "Never" nil)
399 (const :tag "When configured in buffer" when-configured)
400 (const :tag "Always" t)))
402 (defcustom org-html-infojs-options
403 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
404 "Options settings for the INFOJS JavaScript.
405 Each of the options must have an entry in `org-html-infojs-opts-table'.
406 The value can either be a string that will be passed to the script, or
407 a property. This property is then assumed to be a property that is defined
408 by the Export/Publishing setup of Org.
409 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
410 means to use the maximum value consistent with other options."
411 :group 'org-export-html
412 :version "24.4"
413 :package-version '(Org . "8.0")
414 :type
415 `(set :greedy t :inline t
416 ,@(mapcar
417 (lambda (x)
418 (list 'cons (list 'const (car x))
419 '(choice
420 (symbol :tag "Publishing/Export property")
421 (string :tag "Value"))))
422 org-html-infojs-opts-table)))
424 (defcustom org-html-infojs-template
425 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
428 * @source: %SCRIPT_PATH
430 * @licstart The following is the entire license notice for the
431 * JavaScript code in %SCRIPT_PATH.
433 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
436 * The JavaScript code in this tag is free software: you can
437 * redistribute it and/or modify it under the terms of the GNU
438 * General Public License (GNU GPL) as published by the Free Software
439 * Foundation, either version 3 of the License, or (at your option)
440 * any later version. The code is distributed WITHOUT ANY WARRANTY;
441 * without even the implied warranty of MERCHANTABILITY or FITNESS
442 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
444 * As additional permission under GNU GPL version 3 section 7, you
445 * may distribute non-source (e.g., minimized or compacted) forms of
446 * that code without the copy of the GNU GPL normally required by
447 * section 4, provided you include this license notice and a URL
448 * through which recipients can access the Corresponding Source.
450 * @licend The above is the entire license notice
451 * for the JavaScript code in %SCRIPT_PATH.
454 </script>
456 <script type=\"text/javascript\">
459 @licstart The following is the entire license notice for the
460 JavaScript code in this tag.
462 Copyright (C) 2012-2013 Free Software Foundation, Inc.
464 The JavaScript code in this tag is free software: you can
465 redistribute it and/or modify it under the terms of the GNU
466 General Public License (GNU GPL) as published by the Free Software
467 Foundation, either version 3 of the License, or (at your option)
468 any later version. The code is distributed WITHOUT ANY WARRANTY;
469 without even the implied warranty of MERCHANTABILITY or FITNESS
470 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
472 As additional permission under GNU GPL version 3 section 7, you
473 may distribute non-source (e.g., minimized or compacted) forms of
474 that code without the copy of the GNU GPL normally required by
475 section 4, provided you include this license notice and a URL
476 through which recipients can access the Corresponding Source.
479 @licend The above is the entire license notice
480 for the JavaScript code in this tag.
483 <!--/*--><![CDATA[/*><!--*/
484 %MANAGER_OPTIONS
485 org_html_manager.setup(); // activate after the parameters are set
486 /*]]>*///-->
487 </script>"
488 "The template for the export style additions when org-info.js is used.
489 Option settings will replace the %MANAGER-OPTIONS cookie."
490 :group 'org-export-html
491 :version "24.4"
492 :package-version '(Org . "8.0")
493 :type 'string)
495 (defun org-html-infojs-install-script (exp-plist backend)
496 "Install script in export options when appropriate.
497 EXP-PLIST is a plist containing export options. BACKEND is the
498 export back-end currently used."
499 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
500 (not org-html-use-infojs)
501 (and (eq org-html-use-infojs 'when-configured)
502 (or (not (plist-get exp-plist :infojs-opt))
503 (string= "" (plist-get exp-plist :infojs-opt))
504 (string-match "\\<view:nil\\>"
505 (plist-get exp-plist :infojs-opt)))))
506 (let* ((template org-html-infojs-template)
507 (ptoc (plist-get exp-plist :with-toc))
508 (hlevels (plist-get exp-plist :headline-levels))
509 (sdepth hlevels)
510 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
511 (options (plist-get exp-plist :infojs-opt))
512 (table org-html-infojs-opts-table)
513 style)
514 (dolist (entry table)
515 (let* ((opt (car entry))
516 (var (nth 1 entry))
517 ;; Compute default values for script option OPT from
518 ;; `org-html-infojs-options' variable.
519 (default
520 (let ((default (cdr (assq opt org-html-infojs-options))))
521 (if (and (symbolp default) (not (memq default '(t nil))))
522 (plist-get exp-plist default)
523 default)))
524 ;; Value set through INFOJS_OPT keyword has precedence
525 ;; over the default one.
526 (val (if (and options
527 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
528 options))
529 (match-string 1 options)
530 default)))
531 (case opt
532 (path (setq template
533 (replace-regexp-in-string
534 "%SCRIPT_PATH" val template t t)))
535 (sdepth (when (integerp (read val))
536 (setq sdepth (min (read val) sdepth))))
537 (tdepth (when (integerp (read val))
538 (setq tdepth (min (read val) tdepth))))
539 (otherwise (setq val
540 (cond
541 ((or (eq val t) (equal val "t")) "1")
542 ((or (eq val nil) (equal val "nil")) "0")
543 ((stringp val) val)
544 (t (format "%s" val))))
545 (push (cons var val) style)))))
546 ;; Now we set the depth of the *generated* TOC to SDEPTH,
547 ;; because the toc will actually determine the splitting. How
548 ;; much of the toc will actually be displayed is governed by the
549 ;; TDEPTH option.
550 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
551 ;; The table of contents should not show more sections than we
552 ;; generate.
553 (setq tdepth (min tdepth sdepth))
554 (push (cons "TOC_DEPTH" tdepth) style)
555 ;; Build style string.
556 (setq style (mapconcat
557 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
558 (car x)
559 (cdr x)))
560 style "\n"))
561 (when (and style (> (length style) 0))
562 (and (string-match "%MANAGER_OPTIONS" template)
563 (setq style (replace-match style t t template))
564 (setq exp-plist
565 (plist-put
566 exp-plist :html-head-extra
567 (concat (or (plist-get exp-plist :html-head-extra) "")
568 "\n"
569 style)))))
570 ;; This script absolutely needs the table of contents, so we
571 ;; change that setting.
572 (unless (plist-get exp-plist :with-toc)
573 (setq exp-plist (plist-put exp-plist :with-toc t)))
574 ;; Return the modified property list.
575 exp-plist)))
577 ;;;; Bold, etc.
579 (defcustom org-html-text-markup-alist
580 '((bold . "<b>%s</b>")
581 (code . "<code>%s</code>")
582 (italic . "<i>%s</i>")
583 (strike-through . "<del>%s</del>")
584 (underline . "<span class=\"underline\">%s</span>")
585 (verbatim . "<code>%s</code>"))
586 "Alist of HTML expressions to convert text markup.
588 The key must be a symbol among `bold', `code', `italic',
589 `strike-through', `underline' and `verbatim'. The value is
590 a formatting string to wrap fontified text with.
592 If no association can be found for a given markup, text will be
593 returned as-is."
594 :group 'org-export-html
595 :version "24.4"
596 :package-version '(Org . "8.0")
597 :type '(alist :key-type (symbol :tag "Markup type")
598 :value-type (string :tag "Format string"))
599 :options '(bold code italic strike-through underline verbatim))
601 (defcustom org-html-indent nil
602 "Non-nil means to indent the generated HTML.
603 Warning: non-nil may break indentation of source code blocks."
604 :group 'org-export-html
605 :version "24.4"
606 :package-version '(Org . "8.0")
607 :type 'boolean)
609 (defcustom org-html-use-unicode-chars nil
610 "Non-nil means to use unicode characters instead of HTML entities."
611 :group 'org-export-html
612 :version "24.4"
613 :package-version '(Org . "8.0")
614 :type 'boolean)
616 ;;;; Drawers
618 (defcustom org-html-format-drawer-function
619 (lambda (name contents) contents)
620 "Function called to format a drawer in HTML code.
622 The function must accept two parameters:
623 NAME the drawer name, like \"LOGBOOK\"
624 CONTENTS the contents of the drawer.
626 The function should return the string to be exported.
628 For example, the variable could be set to the following function
629 in order to mimic default behaviour:
631 The default value simply returns the value of CONTENTS."
632 :group 'org-export-html
633 :version "24.4"
634 :package-version '(Org . "8.0")
635 :type 'function)
637 ;;;; Footnotes
639 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
640 <h2 class=\"footnotes\">%s: </h2>
641 <div id=\"text-footnotes\">
643 </div>
644 </div>"
645 "Format for the footnotes section.
646 Should contain a two instances of %s. The first will be replaced with the
647 language-specific word for \"Footnotes\", the second one will be replaced
648 by the footnotes themselves."
649 :group 'org-export-html
650 :type 'string)
652 (defcustom org-html-footnote-format "<sup>%s</sup>"
653 "The format for the footnote reference.
654 %s will be replaced by the footnote reference itself."
655 :group 'org-export-html
656 :type 'string)
658 (defcustom org-html-footnote-separator "<sup>, </sup>"
659 "Text used to separate footnotes."
660 :group 'org-export-html
661 :type 'string)
663 ;;;; Headline
665 (defcustom org-html-toplevel-hlevel 2
666 "The <H> level for level 1 headings in HTML export.
667 This is also important for the classes that will be wrapped around headlines
668 and outline structure. If this variable is 1, the top-level headlines will
669 be <h1>, and the corresponding classes will be outline-1, section-number-1,
670 and outline-text-1. If this is 2, all of these will get a 2 instead.
671 The default for this variable is 2, because we use <h1> for formatting the
672 document title."
673 :group 'org-export-html
674 :type 'integer)
676 (defcustom org-html-format-headline-function 'ignore
677 "Function to format headline text.
679 This function will be called with 5 arguments:
680 TODO the todo keyword (string or nil).
681 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
682 PRIORITY the priority of the headline (integer or nil)
683 TEXT the main headline text (string).
684 TAGS the tags (string or nil).
686 The function result will be used in the section format string."
687 :group 'org-export-html
688 :version "24.4"
689 :package-version '(Org . "8.0")
690 :type 'function)
692 ;;;; HTML-specific
694 (defcustom org-html-allow-name-attribute-in-anchors nil
695 "When nil, do not set \"name\" attribute in anchors.
696 By default, when appropriate, anchors are formatted with \"id\"
697 but without \"name\" attribute."
698 :group 'org-export-html
699 :version "24.4"
700 :package-version '(Org . "8.0")
701 :type 'boolean)
703 ;;;; Inlinetasks
705 (defcustom org-html-format-inlinetask-function 'ignore
706 "Function called to format an inlinetask in HTML code.
708 The function must accept six parameters:
709 TODO the todo keyword, as a string
710 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
711 PRIORITY the inlinetask priority, as a string
712 NAME the inlinetask name, as a string.
713 TAGS the inlinetask tags, as a list of strings.
714 CONTENTS the contents of the inlinetask, as a string.
716 The function should return the string to be exported."
717 :group 'org-export-html
718 :version "24.4"
719 :package-version '(Org . "8.0")
720 :type 'function)
722 ;;;; LaTeX
724 (defcustom org-html-with-latex org-export-with-latex
725 "Non-nil means process LaTeX math snippets.
727 When set, the exporter will process LaTeX environments and
728 fragments.
730 This option can also be set with the +OPTIONS line,
731 e.g. \"tex:mathjax\". Allowed values are:
733 nil Ignore math snippets.
734 `verbatim' Keep everything in verbatim
735 `dvipng' Process the LaTeX fragments to images. This will also
736 include processing of non-math environments.
737 `imagemagick' Convert the LaTeX fragments to pdf files and use
738 imagemagick to convert pdf files to png files.
739 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
740 be loaded.
741 t Synonym for `mathjax'."
742 :group 'org-export-html
743 :version "24.4"
744 :package-version '(Org . "8.0")
745 :type '(choice
746 (const :tag "Do not process math in any way" nil)
747 (const :tag "Use dvipng to make images" dvipng)
748 (const :tag "Use imagemagick to make images" imagemagick)
749 (const :tag "Use MathJax to display math" mathjax)
750 (const :tag "Leave math verbatim" verbatim)))
752 ;;;; Links :: Generic
754 (defcustom org-html-link-org-files-as-html t
755 "Non-nil means make file links to `file.org' point to `file.html'.
756 When `org-mode' is exporting an `org-mode' file to HTML, links to
757 non-html files are directly put into a href tag in HTML.
758 However, links to other Org-mode files (recognized by the
759 extension `.org.) should become links to the corresponding html
760 file, assuming that the linked `org-mode' file will also be
761 converted to HTML.
762 When nil, the links still point to the plain `.org' file."
763 :group 'org-export-html
764 :type 'boolean)
766 ;;;; Links :: Inline images
768 (defcustom org-html-inline-images t
769 "Non-nil means inline images into exported HTML pages.
770 This is done using an <img> tag. When nil, an anchor with href is used to
771 link to the image."
772 :group 'org-export-html
773 :version "24.4"
774 :package-version '(Org . "8.1")
775 :type 'boolean)
777 (defcustom org-html-inline-image-rules
778 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
779 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
780 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
781 "Rules characterizing image files that can be inlined into HTML.
782 A rule consists in an association whose key is the type of link
783 to consider, and value is a regexp that will be matched against
784 link's path."
785 :group 'org-export-html
786 :version "24.4"
787 :package-version '(Org . "8.0")
788 :type '(alist :key-type (string :tag "Type")
789 :value-type (regexp :tag "Path")))
791 ;;;; Plain Text
793 (defcustom org-html-protect-char-alist
794 '(("&" . "&amp;")
795 ("<" . "&lt;")
796 (">" . "&gt;"))
797 "Alist of characters to be converted by `org-html-protect'."
798 :group 'org-export-html
799 :type '(repeat (cons (string :tag "Character")
800 (string :tag "HTML equivalent"))))
802 ;;;; Src Block
804 (defcustom org-html-htmlize-output-type 'inline-css
805 "Output type to be used by htmlize when formatting code snippets.
806 Choices are `css' to export the CSS selectors only,`inline-css'
807 to export the CSS attribute values inline in the HTML or `nil' to
808 export plain text. We use as default `inline-css', in order to
809 make the resulting HTML self-containing.
811 However, this will fail when using Emacs in batch mode for export, because
812 then no rich font definitions are in place. It will also not be good if
813 people with different Emacs setup contribute HTML files to a website,
814 because the fonts will represent the individual setups. In these cases,
815 it is much better to let Org/Htmlize assign classes only, and to use
816 a style file to define the look of these classes.
817 To get a start for your css file, start Emacs session and make sure that
818 all the faces you are interested in are defined, for example by loading files
819 in all modes you want. Then, use the command
820 \\[org-html-htmlize-generate-css] to extract class definitions."
821 :group 'org-export-html
822 :type '(choice (const css) (const inline-css) (const nil)))
824 (defcustom org-html-htmlize-font-prefix "org-"
825 "The prefix for CSS class names for htmlize font specifications."
826 :group 'org-export-html
827 :type 'string)
829 ;;;; Table
831 (defcustom org-html-table-default-attributes
832 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
833 "Default attributes and values which will be used in table tags.
834 This is a plist where attributes are symbols, starting with
835 colons, and values are strings.
837 When exporting to HTML5, these values will be disregarded."
838 :group 'org-export-html
839 :version "24.4"
840 :package-version '(Org . "8.0")
841 :type '(plist :key-type (symbol :tag "Property")
842 :value-type (string :tag "Value")))
844 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
845 "The opening and ending tags for table header fields.
846 This is customizable so that alignment options can be specified.
847 The first %s will be filled with the scope of the field, either row or col.
848 The second %s will be replaced by a style entry to align the field.
849 See also the variable `org-html-table-use-header-tags-for-first-column'.
850 See also the variable `org-html-table-align-individual-fields'."
851 :group 'org-export-html
852 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
854 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
855 "The opening and ending tags for table data fields.
856 This is customizable so that alignment options can be specified.
857 The first %s will be filled with the scope of the field, either row or col.
858 The second %s will be replaced by a style entry to align the field.
859 See also the variable `org-html-table-align-individual-fields'."
860 :group 'org-export-html
861 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
863 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
864 "The opening and ending tags for table rows.
865 This is customizable so that alignment options can be specified.
866 Instead of strings, these can be Lisp forms that will be
867 evaluated for each row in order to construct the table row tags.
869 During evaluation, these variables will be dynamically bound so that
870 you can reuse them:
872 `row-number': row number (0 is the first row)
873 `rowgroup-number': group number of current row
874 `start-rowgroup-p': non-nil means the row starts a group
875 `end-rowgroup-p': non-nil means the row ends a group
876 `top-row-p': non-nil means this is the top row
877 `bottom-row-p': non-nil means this is the bottom row
879 For example:
881 \(setq org-html-table-row-tags
882 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
883 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
884 (t (if (= (mod row-number 2) 1)
885 \"<tr class=\\\"tr-odd\\\">\"
886 \"<tr class=\\\"tr-even\\\">\")))
887 \"</tr>\"))
889 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
890 and the bottom row, and otherwise alternate between \"tr-odd\" and
891 \"tr-even\" for odd and even rows."
892 :group 'org-export-html
893 :type '(cons
894 (choice :tag "Opening tag"
895 (string :tag "Specify")
896 (sexp))
897 (choice :tag "Closing tag"
898 (string :tag "Specify")
899 (sexp))))
901 (defcustom org-html-table-align-individual-fields t
902 "Non-nil means attach style attributes for alignment to each table field.
903 When nil, alignment will only be specified in the column tags, but this
904 is ignored by some browsers (like Firefox, Safari). Opera does it right
905 though."
906 :group 'org-export-html
907 :type 'boolean)
909 (defcustom org-html-table-use-header-tags-for-first-column nil
910 "Non-nil means format column one in tables with header tags.
911 When nil, also column one will use data tags."
912 :group 'org-export-html
913 :type 'boolean)
915 (defcustom org-html-table-caption-above t
916 "When non-nil, place caption string at the beginning of the table.
917 Otherwise, place it near the end."
918 :group 'org-export-html
919 :type 'boolean)
921 ;;;; Tags
923 (defcustom org-html-tag-class-prefix ""
924 "Prefix to class names for TODO keywords.
925 Each tag gets a class given by the tag itself, with this prefix.
926 The default prefix is empty because it is nice to just use the keyword
927 as a class name. But if you get into conflicts with other, existing
928 CSS classes, then this prefix can be very useful."
929 :group 'org-export-html
930 :type 'string)
932 ;;;; Template :: Generic
934 (defcustom org-html-extension "html"
935 "The extension for exported HTML files."
936 :group 'org-export-html
937 :type 'string)
939 (defcustom org-html-xml-declaration
940 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
941 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
942 "The extension for exported HTML files.
943 %s will be replaced with the charset of the exported file.
944 This may be a string, or an alist with export extensions
945 and corresponding declarations.
947 This declaration only applies when exporting to XHTML."
948 :group 'org-export-html
949 :type '(choice
950 (string :tag "Single declaration")
951 (repeat :tag "Dependent on extension"
952 (cons (string :tag "Extension")
953 (string :tag "Declaration")))))
955 (defcustom org-html-coding-system 'utf-8
956 "Coding system for HTML export.
957 Use utf-8 as the default value."
958 :group 'org-export-html
959 :version "24.4"
960 :package-version '(Org . "8.0")
961 :type 'coding-system)
963 (defcustom org-html-doctype "xhtml-strict"
964 "Document type definition to use for exported HTML files.
965 Can be set with the in-buffer HTML_DOCTYPE property or for
966 publishing, with :html-doctype."
967 :group 'org-export-html
968 :version "24.4"
969 :package-version '(Org . "8.0")
970 :type (append
971 '(choice)
972 (mapcar (lambda (x) `(const ,(car x))) org-html-doctype-alist)
973 '((string :tag "Custom doctype" ))))
975 (defcustom org-html-html5-fancy nil
976 "Non-nil means using new HTML5 elements.
977 This variable is ignored for anything other than HTML5 export.
979 For compatibility with Internet Explorer, it's probably a good
980 idea to download some form of the html5shiv (for instance
981 https://code.google.com/p/html5shiv/) and add it to your
982 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
983 versions 8 and below."
984 :group 'org-export-html
985 :version "24.4"
986 :package-version '(Org . "8.0")
987 :type 'boolean)
989 (defcustom org-html-container-element "div"
990 "HTML element to use for wrapping top level sections.
991 Can be set with the in-buffer HTML_CONTAINER property or for
992 publishing, with :html-container.
994 Note that changing the default will prevent you from using
995 org-info.js for your website."
996 :group 'org-export-html
997 :version "24.4"
998 :package-version '(Org . "8.0")
999 :type 'string)
1001 (defcustom org-html-divs
1002 '((preamble "div" "preamble")
1003 (content "div" "content")
1004 (postamble "div" "postamble"))
1005 "Alist of the three section elements for HTML export.
1006 The car of each entry is one of 'preamble, 'content or 'postamble.
1007 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1008 section of the exported document.
1010 Note that changing the default will prevent you from using
1011 org-info.js for your website."
1012 :group 'org-export-html
1013 :version "24.4"
1014 :package-version '(Org . "8.0")
1015 :type '(list :greedy t
1016 (list :tag "Preamble"
1017 (const :format "" preamble)
1018 (string :tag "element") (string :tag " id"))
1019 (list :tag "Content"
1020 (const :format "" content)
1021 (string :tag "element") (string :tag " id"))
1022 (list :tag "Postamble" (const :format "" postamble)
1023 (string :tag " id") (string :tag "element"))))
1025 (defconst org-html-checkbox-types
1026 '((unicode .
1027 ((on . "&#x2611;") (off . "&#x2610;") (trans . "&#x2610;")))
1028 (ascii .
1029 ((on . "<code>[X]</code>")
1030 (off . "<code>[&#xa0;]</code>")
1031 (trans . "<code>[-]</code>")))
1032 (html .
1033 ((on . "<input type='checkbox' checked='checked' />")
1034 (off . "<input type='checkbox' />")
1035 (trans . "<input type='checkbox' />"))))
1036 "Alist of checkbox types.
1037 The cdr of each entry is an alist list three checkbox types for
1038 HTML export: `on', `off' and `trans'.
1040 The choices are:
1041 `unicode' Unicode characters (HTML entities)
1042 `ascii' ASCII characters
1043 `html' HTML checkboxes
1045 Note that only the ascii characters implement tri-state
1046 checkboxes. The other two use the `off' checkbox for `trans'.")
1048 (defcustom org-html-checkbox-type 'ascii
1049 "The type of checkboxes to use for HTML export.
1050 See `org-html-checkbox-types' for for the values used for each
1051 option."
1052 :group 'org-export-html
1053 :version "24.4"
1054 :package-version '(Org . "8.0")
1055 :type '(choice
1056 (const :tag "ASCII characters" ascii)
1057 (const :tag "Unicode characters" unicode)
1058 (const :tag "HTML checkboxes" html)))
1060 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
1061 "Format used for timestamps in preamble, postamble and metadata.
1062 See `format-time-string' for more information on its components."
1063 :group 'org-export-html
1064 :version "24.4"
1065 :package-version '(Org . "8.0")
1066 :type 'string)
1068 ;;;; Template :: Mathjax
1070 (defcustom org-html-mathjax-options
1071 '((path "http://orgmode.org/mathjax/MathJax.js")
1072 (scale "100")
1073 (align "center")
1074 (indent "2em")
1075 (mathml nil))
1076 "Options for MathJax setup.
1078 path The path where to find MathJax
1079 scale Scaling for the HTML-CSS backend, usually between 100 and 133
1080 align How to align display math: left, center, or right
1081 indent If align is not center, how far from the left/right side?
1082 mathml Should a MathML player be used if available?
1083 This is faster and reduces bandwidth use, but currently
1084 sometimes has lower spacing quality. Therefore, the default is
1085 nil. When browsers get better, this switch can be flipped.
1087 You can also customize this for each buffer, using something like
1089 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1090 :group 'org-export-html
1091 :type '(list :greedy t
1092 (list :tag "path (the path from where to load MathJax.js)"
1093 (const :format " " path) (string))
1094 (list :tag "scale (scaling for the displayed math)"
1095 (const :format " " scale) (string))
1096 (list :tag "align (alignment of displayed equations)"
1097 (const :format " " align) (string))
1098 (list :tag "indent (indentation with left or right alignment)"
1099 (const :format " " indent) (string))
1100 (list :tag "mathml (should MathML display be used is possible)"
1101 (const :format " " mathml) (boolean))))
1103 (defcustom org-html-mathjax-template
1104 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1105 <script type=\"text/javascript\">
1106 <!--/*--><![CDATA[/*><!--*/
1107 MathJax.Hub.Config({
1108 // Only one of the two following lines, depending on user settings
1109 // First allows browser-native MathML display, second forces HTML/CSS
1110 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1111 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1112 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1113 \"TeX/noUndefined.js\"],
1114 tex2jax: {
1115 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1116 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1117 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1118 ignoreClass: \"tex2jax_ignore\",
1119 processEscapes: false,
1120 processEnvironments: true,
1121 preview: \"TeX\"
1123 showProcessingMessages: true,
1124 displayAlign: \"%ALIGN\",
1125 displayIndent: \"%INDENT\",
1127 \"HTML-CSS\": {
1128 scale: %SCALE,
1129 availableFonts: [\"STIX\",\"TeX\"],
1130 preferredFont: \"TeX\",
1131 webFont: \"TeX\",
1132 imageFont: \"TeX\",
1133 showMathMenu: true,
1135 MMLorHTML: {
1136 prefer: {
1137 MSIE: \"MML\",
1138 Firefox: \"MML\",
1139 Opera: \"HTML\",
1140 other: \"HTML\"
1144 /*]]>*///-->
1145 </script>"
1146 "The MathJax setup for XHTML files."
1147 :group 'org-export-html
1148 :type 'string)
1150 ;;;; Template :: Postamble
1152 (defcustom org-html-postamble 'auto
1153 "Non-nil means insert a postamble in HTML export.
1155 When set to 'auto, check against the
1156 `org-export-with-author/email/creator/date' variables to set the
1157 content of the postamble. When set to a string, use this string
1158 as the postamble. When t, insert a string as defined by the
1159 formatting string in `org-html-postamble-format'.
1161 When set to a function, apply this function and insert the
1162 returned string. The function takes the property list of export
1163 options as its only argument.
1165 Setting :html-postamble in publishing projects will take
1166 precedence over this variable."
1167 :group 'org-export-html
1168 :type '(choice (const :tag "No postamble" nil)
1169 (const :tag "Auto postamble" auto)
1170 (const :tag "Default formatting string" t)
1171 (string :tag "Custom formatting string")
1172 (function :tag "Function (must return a string)")))
1174 (defcustom org-html-postamble-format
1175 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1176 <p class=\"date\">Date: %d</p>
1177 <p class=\"creator\">%c</p>
1178 <p class=\"validation\">%v</p>"))
1179 "Alist of languages and format strings for the HTML postamble.
1181 The first element of each list is the language code, as used for
1182 the LANGUAGE keyword. See `org-export-default-language'.
1184 The second element of each list is a format string to format the
1185 postamble itself. This format string can contain these elements:
1187 %t stands for the title.
1188 %a stands for the author's name.
1189 %e stands for the author's email.
1190 %d stands for the date.
1191 %c will be replaced by `org-html-creator-string'.
1192 %v will be replaced by `org-html-validation-link'.
1193 %T will be replaced by the export time.
1194 %C will be replaced by the last modification time.
1196 If you need to use a \"%\" character, you need to escape it
1197 like that: \"%%\"."
1198 :group 'org-export-html
1199 :type '(repeat
1200 (list (string :tag "Language")
1201 (string :tag "Format string"))))
1203 (defcustom org-html-validation-link
1204 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1205 "Link to HTML validation service."
1206 :group 'org-export-html
1207 :type 'string)
1209 (defcustom org-html-creator-string
1210 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1211 emacs-version
1212 (if (fboundp 'org-version) (org-version) "unknown version"))
1213 "Information about the creator of the HTML document.
1214 This option can also be set on with the CREATOR keyword."
1215 :group 'org-export-html
1216 :version "24.4"
1217 :package-version '(Org . "8.0")
1218 :type '(string :tag "Creator string"))
1220 ;;;; Template :: Preamble
1222 (defcustom org-html-preamble t
1223 "Non-nil means insert a preamble in HTML export.
1225 When t, insert a string as defined by the formatting string in
1226 `org-html-preamble-format'. When set to a string, use this
1227 formatting string instead (see `org-html-postamble-format' for an
1228 example of such a formatting string).
1230 When set to a function, apply this function and insert the
1231 returned string. The function takes the property list of export
1232 options as its only argument.
1234 Setting :html-preamble in publishing projects will take
1235 precedence over this variable."
1236 :group 'org-export-html
1237 :type '(choice (const :tag "No preamble" nil)
1238 (const :tag "Default preamble" t)
1239 (string :tag "Custom formatting string")
1240 (function :tag "Function (must return a string)")))
1242 (defcustom org-html-preamble-format '(("en" ""))
1243 "Alist of languages and format strings for the HTML preamble.
1245 The first element of each list is the language code, as used for
1246 the LANGUAGE keyword. See `org-export-default-language'.
1248 The second element of each list is a format string to format the
1249 preamble itself. This format string can contain these elements:
1251 %t stands for the title.
1252 %a stands for the author's name.
1253 %e stands for the author's email.
1254 %d stands for the date.
1255 %c will be replaced by `org-html-creator-string'.
1256 %v will be replaced by `org-html-validation-link'.
1257 %T will be replaced by the export time.
1258 %C will be replaced by the last modification time.
1260 If you need to use a \"%\" character, you need to escape it
1261 like that: \"%%\".
1263 See the default value of `org-html-postamble-format' for an
1264 example."
1265 :group 'org-export-html
1266 :type '(repeat
1267 (list (string :tag "Language")
1268 (string :tag "Format string"))))
1270 (defcustom org-html-link-up ""
1271 "Where should the \"UP\" link of exported HTML pages lead?"
1272 :group 'org-export-html
1273 :type '(string :tag "File or URL"))
1275 (defcustom org-html-link-home ""
1276 "Where should the \"HOME\" link of exported HTML pages lead?"
1277 :group 'org-export-html
1278 :type '(string :tag "File or URL"))
1280 (defcustom org-html-link-use-abs-url nil
1281 "Should we prepend relative links with HTML_LINK_HOME?"
1282 :group 'org-export-html
1283 :version "24.4"
1284 :package-version '(Org . "8.1")
1285 :type 'boolean)
1287 (defcustom org-html-home/up-format
1288 "<div id=\"org-div-home-and-up\">
1289 <a accesskey=\"h\" href=\"%s\"> UP </a>
1291 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1292 </div>"
1293 "Snippet used to insert the HOME and UP links.
1294 This is a format string, the first %s will receive the UP link,
1295 the second the HOME link. If both `org-html-link-up' and
1296 `org-html-link-home' are empty, the entire snippet will be
1297 ignored."
1298 :group 'org-export-html
1299 :type 'string)
1301 ;;;; Template :: Scripts
1303 (define-obsolete-variable-alias
1304 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1305 (defcustom org-html-head-include-scripts t
1306 "Non-nil means include the JavaScript snippets in exported HTML files.
1307 The actual script is defined in `org-html-scripts' and should
1308 not be modified."
1309 :group 'org-export-html
1310 :version "24.4"
1311 :package-version '(Org . "8.0")
1312 :type 'boolean)
1314 ;;;; Template :: Styles
1316 (define-obsolete-variable-alias
1317 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1318 (defcustom org-html-head-include-default-style t
1319 "Non-nil means include the default style in exported HTML files.
1320 The actual style is defined in `org-html-style-default' and
1321 should not be modified. Use `org-html-head' to use your own
1322 style information."
1323 :group 'org-export-html
1324 :version "24.4"
1325 :package-version '(Org . "8.0")
1326 :type 'boolean)
1327 ;;;###autoload
1328 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1330 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1331 (defcustom org-html-head ""
1332 "Org-wide head definitions for exported HTML files.
1334 This variable can contain the full HTML structure to provide a
1335 style, including the surrounding HTML tags. You can consider
1336 including definitions for the following classes: title, todo,
1337 done, timestamp, timestamp-kwd, tag, target.
1339 For example, a valid value would be:
1341 <style type=\"text/css\">
1342 <![CDATA[
1343 p { font-weight: normal; color: gray; }
1344 h1 { color: black; }
1345 .title { text-align: center; }
1346 .todo, .timestamp-kwd { color: red; }
1347 .done { color: green; }
1349 </style>
1351 If you want to refer to an external style, use something like
1353 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1355 As the value of this option simply gets inserted into the HTML
1356 <head> header, you can use it to add any arbitrary text to the
1357 header.
1359 You can set this on a per-file basis using #+HTML_HEAD:,
1360 or for publication projects using the :html-head property."
1361 :group 'org-export-html
1362 :version "24.4"
1363 :package-version '(Org . "8.0")
1364 :type 'string)
1365 ;;;###autoload
1366 (put 'org-html-head 'safe-local-variable 'stringp)
1368 (defcustom org-html-head-extra ""
1369 "More head information to add in the HTML output.
1371 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1372 or for publication projects using the :html-head-extra property."
1373 :group 'org-export-html
1374 :version "24.4"
1375 :package-version '(Org . "8.0")
1376 :type 'string)
1377 ;;;###autoload
1378 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1380 ;;;; Todos
1382 (defcustom org-html-todo-kwd-class-prefix ""
1383 "Prefix to class names for TODO keywords.
1384 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1385 The default prefix is empty because it is nice to just use the keyword
1386 as a class name. But if you get into conflicts with other, existing
1387 CSS classes, then this prefix can be very useful."
1388 :group 'org-export-html
1389 :type 'string)
1392 ;;; Internal Functions
1394 (defun org-html-xhtml-p (info)
1395 (let ((dt (downcase (plist-get info :html-doctype))))
1396 (string-match-p "xhtml" dt)))
1398 (defun org-html-html5-p (info)
1399 (let ((dt (downcase (plist-get info :html-doctype))))
1400 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1402 (defun org-html-close-tag (tag attr info)
1403 (concat "<" tag " " attr
1404 (if (org-html-xhtml-p info) " />" ">")))
1406 (defun org-html-doctype (info)
1407 "Return correct html doctype tag from `org-html-doctype-alist',
1408 or the literal value of :html-doctype from INFO if :html-doctype
1409 is not found in the alist.
1410 INFO is a plist used as a communication channel."
1411 (let ((dt (plist-get info :html-doctype)))
1412 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1414 (defun org-html--make-attribute-string (attributes)
1415 "Return a list of attributes, as a string.
1416 ATTRIBUTES is a plist where values are either strings or nil. An
1417 attributes with a nil value will be omitted from the result."
1418 (let (output)
1419 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1420 (cond ((null item) (pop output))
1421 ((symbolp item) (push (substring (symbol-name item) 1) output))
1422 (t (let ((key (car output))
1423 (value (replace-regexp-in-string
1424 "\"" "&quot;" (org-html-encode-plain-text item))))
1425 (setcar output (format "%s=\"%s\"" key value))))))))
1427 (defun org-html--wrap-image (contents info &optional caption label)
1428 "Wrap CONTENTS string within an appropriate environment for images.
1429 INFO is a plist used as a communication channel. When optional
1430 arguments CAPTION and LABEL are given, use them for caption and
1431 \"id\" attribute."
1432 (let ((html5-fancy (and (org-html-html5-p info)
1433 (plist-get info :html-html5-fancy))))
1434 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1435 "\n<div%s class=\"figure\">%s%s\n</div>")
1436 ;; ID.
1437 (if (not (org-string-nw-p label)) ""
1438 (format " id=\"%s\"" (org-export-solidify-link-text label)))
1439 ;; Contents.
1440 (format "\n<p>%s</p>" contents)
1441 ;; Caption.
1442 (if (not (org-string-nw-p caption)) ""
1443 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1444 "\n<p>%s</p>")
1445 caption)))))
1447 (defun org-html--format-image (source attributes info)
1448 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1449 SOURCE is a string specifying the location of the image.
1450 ATTRIBUTES is a plist, as returned by
1451 `org-export-read-attribute'. INFO is a plist used as
1452 a communication channel."
1453 (if (string= "svg" (file-name-extension source))
1454 (org-html--svg-image source attributes info)
1455 (org-html-close-tag
1456 "img"
1457 (org-html--make-attribute-string
1458 (org-combine-plists
1459 (list :src source
1460 :alt (if (string-match-p "^ltxpng/" source)
1461 (org-html-encode-plain-text
1462 (org-find-text-property-in-string 'org-latex-src source))
1463 (file-name-nondirectory source)))
1464 attributes))
1465 info)))
1467 (defun org-html--svg-image (source attributes info)
1468 "Return \"object\" appropriate for embedding svg file SOURCE
1469 with assoicated ATTRIBUTES. INFO is a plist used as a
1470 communication channel.
1472 The special attribute \"fallback\" can be used to specify a fallback
1473 image file to use if the object embedding is not supported."
1474 (let ((fallback (plist-get attributes :fallback))
1475 (attrs (org-html--make-attribute-string
1476 (plist-put attributes :fallback nil))))
1477 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1478 source attrs
1479 (if fallback
1480 (org-html-close-tag
1481 "img" (format "src=\"%s\" %s" fallback attrs) info)
1482 "Sorry, your browser does not support SVG."))))
1484 (defun org-html--textarea-block (element)
1485 "Transcode ELEMENT into a textarea block.
1486 ELEMENT is either a src block or an example block."
1487 (let* ((code (car (org-export-unravel-code element)))
1488 (attr (org-export-read-attribute :attr_html element)))
1489 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1490 (or (plist-get attr :width) 80)
1491 (or (plist-get attr :height) (org-count-lines code))
1492 code)))
1494 (defun org-html--has-caption-p (element &optional info)
1495 "Non-nil when ELEMENT has a caption affiliated keyword.
1496 INFO is a plist used as a communication channel. This function
1497 is meant to be used as a predicate for `org-export-get-ordinal' or
1498 a value to `org-html-standalone-image-predicate'."
1499 (org-element-property :caption element))
1501 ;;;; Table
1503 (defun org-html-htmlize-region-for-paste (beg end)
1504 "Convert the region between BEG and END to HTML, using htmlize.el.
1505 This is much like `htmlize-region-for-paste', only that it uses
1506 the settings define in the org-... variables."
1507 (let* ((htmlize-output-type org-html-htmlize-output-type)
1508 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1509 (htmlbuf (htmlize-region beg end)))
1510 (unwind-protect
1511 (with-current-buffer htmlbuf
1512 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1513 (plist-get htmlize-buffer-places 'content-end)))
1514 (kill-buffer htmlbuf))))
1516 ;;;###autoload
1517 (defun org-html-htmlize-generate-css ()
1518 "Create the CSS for all font definitions in the current Emacs session.
1519 Use this to create face definitions in your CSS style file that can then
1520 be used by code snippets transformed by htmlize.
1521 This command just produces a buffer that contains class definitions for all
1522 faces used in the current Emacs session. You can copy and paste the ones you
1523 need into your CSS file.
1525 If you then set `org-html-htmlize-output-type' to `css', calls
1526 to the function `org-html-htmlize-region-for-paste' will
1527 produce code that uses these same face definitions."
1528 (interactive)
1529 (require 'htmlize)
1530 (and (get-buffer "*html*") (kill-buffer "*html*"))
1531 (with-temp-buffer
1532 (let ((fl (face-list))
1533 (htmlize-css-name-prefix "org-")
1534 (htmlize-output-type 'css)
1535 f i)
1536 (while (setq f (pop fl)
1537 i (and f (face-attribute f :inherit)))
1538 (when (and (symbolp f) (or (not i) (not (listp i))))
1539 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1540 (htmlize-region (point-min) (point-max))))
1541 (org-pop-to-buffer-same-window "*html*")
1542 (goto-char (point-min))
1543 (if (re-search-forward "<style" nil t)
1544 (delete-region (point-min) (match-beginning 0)))
1545 (if (re-search-forward "</style>" nil t)
1546 (delete-region (1+ (match-end 0)) (point-max)))
1547 (beginning-of-line 1)
1548 (if (looking-at " +") (replace-match ""))
1549 (goto-char (point-min)))
1551 (defun org-html--make-string (n string)
1552 "Build a string by concatenating N times STRING."
1553 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1555 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1556 "Turn todo keyword KWD into a valid class name.
1557 Replaces invalid characters with \"_\"."
1558 (save-match-data
1559 (while (string-match "[^a-zA-Z0-9_]" kwd)
1560 (setq kwd (replace-match "_" t t kwd))))
1561 kwd)
1563 (defun org-html-format-footnote-reference (n def refcnt)
1564 "Format footnote reference N with definition DEF into HTML."
1565 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1566 (format org-html-footnote-format
1567 (let* ((id (format "fnr.%s%s" n extra))
1568 (href (format " href=\"#fn.%s\"" n))
1569 (attributes (concat " class=\"footref\"" href)))
1570 (org-html--anchor id n attributes)))))
1572 (defun org-html-format-footnotes-section (section-name definitions)
1573 "Format footnotes section SECTION-NAME."
1574 (if (not definitions) ""
1575 (format org-html-footnotes-section section-name definitions)))
1577 (defun org-html-format-footnote-definition (fn)
1578 "Format the footnote definition FN."
1579 (let ((n (car fn)) (def (cdr fn)))
1580 (format
1581 "<div class=\"footdef\">%s %s</div>\n"
1582 (format org-html-footnote-format
1583 (let* ((id (format "fn.%s" n))
1584 (href (format " href=\"#fnr.%s\"" n))
1585 (attributes (concat " class=\"footnum\"" href)))
1586 (org-html--anchor id n attributes)))
1587 def)))
1589 (defun org-html-footnote-section (info)
1590 "Format the footnote section.
1591 INFO is a plist used as a communication channel."
1592 (let* ((fn-alist (org-export-collect-footnote-definitions
1593 (plist-get info :parse-tree) info))
1594 (fn-alist
1595 (loop for (n type raw) in fn-alist collect
1596 (cons n (if (eq (org-element-type raw) 'org-data)
1597 (org-trim (org-export-data raw info))
1598 (format "<p>%s</p>"
1599 (org-trim (org-export-data raw info))))))))
1600 (when fn-alist
1601 (org-html-format-footnotes-section
1602 (org-html--translate "Footnotes" info)
1603 (format
1604 "\n%s\n"
1605 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1608 ;;; Template
1610 (defun org-html--build-meta-info (info)
1611 "Return meta tags for exported document.
1612 INFO is a plist used as a communication channel."
1613 (let ((protect-string
1614 (lambda (str)
1615 (replace-regexp-in-string
1616 "\"" "&quot;" (org-html-encode-plain-text str))))
1617 (title (org-export-data (plist-get info :title) info))
1618 (author (and (plist-get info :with-author)
1619 (let ((auth (plist-get info :author)))
1620 (and auth
1621 ;; Return raw Org syntax, skipping non
1622 ;; exportable objects.
1623 (org-element-interpret-data
1624 (org-element-map auth
1625 (cons 'plain-text org-element-all-objects)
1626 'identity info))))))
1627 (description (plist-get info :description))
1628 (keywords (plist-get info :keywords))
1629 (charset (or (and org-html-coding-system
1630 (fboundp 'coding-system-get)
1631 (coding-system-get org-html-coding-system
1632 'mime-charset))
1633 "iso-8859-1")))
1634 (concat
1635 (format "<title>%s</title>\n" title)
1636 (when (plist-get info :time-stamp-file)
1637 (format-time-string
1638 (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
1639 (format
1640 (if (org-html-html5-p info)
1641 (org-html-close-tag "meta" " charset=\"%s\"" info)
1642 (org-html-close-tag
1643 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1644 info))
1645 charset) "\n"
1646 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1647 "\n"
1648 (and (org-string-nw-p author)
1649 (concat
1650 (org-html-close-tag "meta"
1651 (format " name=\"author\" content=\"%s\""
1652 (funcall protect-string author))
1653 info)
1654 "\n"))
1655 (and (org-string-nw-p description)
1656 (concat
1657 (org-html-close-tag "meta"
1658 (format " name=\"description\" content=\"%s\"\n"
1659 (funcall protect-string description))
1660 info)
1661 "\n"))
1662 (and (org-string-nw-p keywords)
1663 (concat
1664 (org-html-close-tag "meta"
1665 (format " name=\"keywords\" content=\"%s\""
1666 (funcall protect-string keywords))
1667 info)
1668 "\n")))))
1670 (defun org-html--build-head (info)
1671 "Return information for the <head>..</head> of the HTML output.
1672 INFO is a plist used as a communication channel."
1673 (org-element-normalize-string
1674 (concat
1675 (when (plist-get info :html-head-include-default-style)
1676 (org-element-normalize-string org-html-style-default))
1677 (org-element-normalize-string (plist-get info :html-head))
1678 (org-element-normalize-string (plist-get info :html-head-extra))
1679 (when (and (plist-get info :html-htmlized-css-url)
1680 (eq org-html-htmlize-output-type 'css))
1681 (org-html-close-tag "link"
1682 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1683 (plist-get info :html-htmlized-css-url))
1684 info))
1685 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1687 (defun org-html--build-mathjax-config (info)
1688 "Insert the user setup into the mathjax template.
1689 INFO is a plist used as a communication channel."
1690 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1691 (org-element-map (plist-get info :parse-tree)
1692 '(latex-fragment latex-environment) 'identity info t))
1693 (let ((template org-html-mathjax-template)
1694 (options org-html-mathjax-options)
1695 (in-buffer (or (plist-get info :html-mathjax) ""))
1696 name val (yes " ") (no "// ") x)
1697 (mapc
1698 (lambda (e)
1699 (setq name (car e) val (nth 1 e))
1700 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1701 (setq val (car (read-from-string
1702 (substring in-buffer (match-end 0))))))
1703 (if (not (stringp val)) (setq val (format "%s" val)))
1704 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1705 (setq template (replace-match val t t template))))
1706 options)
1707 (setq val (nth 1 (assq 'mathml options)))
1708 (if (string-match (concat "\\<mathml:") in-buffer)
1709 (setq val (car (read-from-string
1710 (substring in-buffer (match-end 0))))))
1711 ;; Exchange prefixes depending on mathml setting.
1712 (if (not val) (setq x yes yes no no x))
1713 ;; Replace cookies to turn on or off the config/jax lines.
1714 (if (string-match ":MMLYES:" template)
1715 (setq template (replace-match yes t t template)))
1716 (if (string-match ":MMLNO:" template)
1717 (setq template (replace-match no t t template)))
1718 ;; Return the modified template.
1719 (org-element-normalize-string template))))
1721 (defun org-html-format-spec (info)
1722 "Return format specification for elements that can be
1723 used in the preamble or postamble."
1724 `((?t . ,(org-export-data (plist-get info :title) info))
1725 (?d . ,(org-export-data (org-export-get-date info) info))
1726 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1727 (?a . ,(org-export-data (plist-get info :author) info))
1728 (?e . ,(mapconcat
1729 (lambda (e)
1730 (format "<a href=\"mailto:%s\">%s</a>" e e))
1731 (split-string (plist-get info :email) ",+ *")
1732 ", "))
1733 (?c . ,(plist-get info :creator))
1734 (?C . ,(let ((file (plist-get info :input-file)))
1735 (format-time-string org-html-metadata-timestamp-format
1736 (if file (nth 5 (file-attributes file))
1737 (current-time)))))
1738 (?v . ,(or org-html-validation-link ""))))
1740 (defun org-html--build-pre/postamble (type info)
1741 "Return document preamble or postamble as a string, or nil.
1742 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1743 communication channel."
1744 (let ((section (plist-get info (intern (format ":html-%s" type))))
1745 (spec (org-html-format-spec info)))
1746 (when section
1747 (let ((section-contents
1748 (if (functionp section) (funcall section info)
1749 (cond
1750 ((stringp section) (format-spec section spec))
1751 ((eq section 'auto)
1752 (let ((date (cdr (assq ?d spec)))
1753 (author (cdr (assq ?a spec)))
1754 (email (cdr (assq ?e spec)))
1755 (creator (cdr (assq ?c spec)))
1756 (timestamp (cdr (assq ?T spec)))
1757 (validation-link (cdr (assq ?v spec))))
1758 (concat
1759 (when (and (plist-get info :with-date)
1760 (org-string-nw-p date))
1761 (format "<p class=\"date\">%s: %s</p>\n"
1762 (org-html--translate "Date" info)
1763 date))
1764 (when (and (plist-get info :with-author)
1765 (org-string-nw-p author))
1766 (format "<p class=\"author\">%s: %s</p>\n"
1767 (org-html--translate "Author" info)
1768 author))
1769 (when (and (plist-get info :with-email)
1770 (org-string-nw-p email))
1771 (format "<p class=\"email\">%s: %s</p>\n"
1772 (org-html--translate "Email" info)
1773 email))
1774 (when (plist-get info :time-stamp-file)
1775 (format
1776 "<p class=\"date\">%s: %s</p>\n"
1777 (org-html--translate "Created" info)
1778 (format-time-string org-html-metadata-timestamp-format)))
1779 (when (plist-get info :with-creator)
1780 (format "<p class=\"creator\">%s</p>\n" creator))
1781 (format "<p class=\"validation\">%s</p>\n"
1782 validation-link))))
1783 (t (format-spec
1784 (or (cadr (assoc
1785 (plist-get info :language)
1786 (eval (intern
1787 (format "org-html-%s-format" type)))))
1788 (cadr
1789 (assoc
1790 "en"
1791 (eval
1792 (intern (format "org-html-%s-format" type))))))
1793 spec))))))
1794 (when (org-string-nw-p section-contents)
1795 (concat
1796 (format "<%s id=\"%s\" class=\"%s\">\n"
1797 (nth 1 (assq type org-html-divs))
1798 (nth 2 (assq type org-html-divs))
1799 org-html--pre/postamble-class)
1800 (org-element-normalize-string section-contents)
1801 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1803 (defun org-html-inner-template (contents info)
1804 "Return body of document string after HTML conversion.
1805 CONTENTS is the transcoded contents string. INFO is a plist
1806 holding export options."
1807 (concat
1808 ;; Table of contents.
1809 (let ((depth (plist-get info :with-toc)))
1810 (when depth (org-html-toc depth info)))
1811 ;; Document contents.
1812 contents
1813 ;; Footnotes section.
1814 (org-html-footnote-section info)))
1816 (defun org-html-template (contents info)
1817 "Return complete document string after HTML conversion.
1818 CONTENTS is the transcoded contents string. INFO is a plist
1819 holding export options."
1820 (concat
1821 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1822 (let ((decl (or (and (stringp org-html-xml-declaration)
1823 org-html-xml-declaration)
1824 (cdr (assoc (plist-get info :html-extension)
1825 org-html-xml-declaration))
1826 (cdr (assoc "html" org-html-xml-declaration))
1828 "")))
1829 (when (not (or (eq nil decl) (string= "" decl)))
1830 (format "%s\n"
1831 (format decl
1832 (or (and org-html-coding-system
1833 (fboundp 'coding-system-get)
1834 (coding-system-get org-html-coding-system 'mime-charset))
1835 "iso-8859-1"))))))
1836 (org-html-doctype info)
1837 "\n"
1838 (concat "<html"
1839 (when (org-html-xhtml-p info)
1840 (format
1841 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1842 (plist-get info :language) (plist-get info :language)))
1843 ">\n")
1844 "<head>\n"
1845 (org-html--build-meta-info info)
1846 (org-html--build-head info)
1847 (org-html--build-mathjax-config info)
1848 "</head>\n"
1849 "<body>\n"
1850 (let ((link-up (org-trim (plist-get info :html-link-up)))
1851 (link-home (org-trim (plist-get info :html-link-home))))
1852 (unless (and (string= link-up "") (string= link-home ""))
1853 (format org-html-home/up-format
1854 (or link-up link-home)
1855 (or link-home link-up))))
1856 ;; Preamble.
1857 (org-html--build-pre/postamble 'preamble info)
1858 ;; Document contents.
1859 (format "<%s id=\"%s\">\n"
1860 (nth 1 (assq 'content org-html-divs))
1861 (nth 2 (assq 'content org-html-divs)))
1862 ;; Document title.
1863 (let ((title (plist-get info :title)))
1864 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1865 contents
1866 (format "</%s>\n"
1867 (nth 1 (assq 'content org-html-divs)))
1868 ;; Postamble.
1869 (org-html--build-pre/postamble 'postamble info)
1870 ;; Closing document.
1871 "</body>\n</html>"))
1873 (defun org-html--translate (s info)
1874 "Translate string S according to specified language.
1875 INFO is a plist used as a communication channel."
1876 (org-export-translate s :html info))
1878 ;;;; Anchor
1880 (defun org-html--anchor (&optional id desc attributes)
1881 "Format a HTML anchor."
1882 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1883 (attributes (concat (and id (format " id=\"%s\"" id))
1884 (and name (format " name=\"%s\"" name))
1885 attributes)))
1886 (format "<a%s>%s</a>" attributes (or desc ""))))
1888 ;;;; Todo
1890 (defun org-html--todo (todo)
1891 "Format TODO keywords into HTML."
1892 (when todo
1893 (format "<span class=\"%s %s%s\">%s</span>"
1894 (if (member todo org-done-keywords) "done" "todo")
1895 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1896 todo)))
1898 ;;;; Tags
1900 (defun org-html--tags (tags)
1901 "Format TAGS into HTML."
1902 (when tags
1903 (format "<span class=\"tag\">%s</span>"
1904 (mapconcat
1905 (lambda (tag)
1906 (format "<span class=\"%s\">%s</span>"
1907 (concat org-html-tag-class-prefix
1908 (org-html-fix-class-name tag))
1909 tag))
1910 tags "&#xa0;"))))
1912 ;;;; Headline
1914 (defun* org-html-format-headline
1915 (todo todo-type priority text tags
1916 &key level section-number headline-label &allow-other-keys)
1917 "Format a headline in HTML."
1918 (let ((section-number
1919 (when section-number
1920 (format "<span class=\"section-number-%d\">%s</span> "
1921 level section-number)))
1922 (todo (org-html--todo todo))
1923 (tags (org-html--tags tags)))
1924 (concat section-number todo (and todo " ") text
1925 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1927 ;;;; Src Code
1929 (defun org-html-fontify-code (code lang)
1930 "Color CODE with htmlize library.
1931 CODE is a string representing the source code to colorize. LANG
1932 is the language used for CODE, as a string, or nil."
1933 (when code
1934 (cond
1935 ;; Case 1: No lang. Possibly an example block.
1936 ((not lang)
1937 ;; Simple transcoding.
1938 (org-html-encode-plain-text code))
1939 ;; Case 2: No htmlize or an inferior version of htmlize
1940 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1941 ;; Emit a warning.
1942 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1943 ;; Simple transcoding.
1944 (org-html-encode-plain-text code))
1945 ;; Case 3: plain text explicitly set
1946 ((not org-html-htmlize-output-type)
1947 ;; Simple transcoding.
1948 (org-html-encode-plain-text code))
1950 ;; Map language
1951 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1952 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1953 (cond
1954 ;; Case 1: Language is not associated with any Emacs mode
1955 ((not (functionp lang-mode))
1956 ;; Simple transcoding.
1957 (org-html-encode-plain-text code))
1958 ;; Case 2: Default. Fontify code.
1960 ;; htmlize
1961 (setq code (with-temp-buffer
1962 ;; Switch to language-specific mode.
1963 (funcall lang-mode)
1964 (insert code)
1965 ;; Fontify buffer.
1966 (font-lock-ensure)
1967 ;; Remove formatting on newline characters.
1968 (save-excursion
1969 (let ((beg (point-min))
1970 (end (point-max)))
1971 (goto-char beg)
1972 (while (progn (end-of-line) (< (point) end))
1973 (put-text-property (point) (1+ (point)) 'face nil)
1974 (forward-char 1))))
1975 (org-src-mode)
1976 (set-buffer-modified-p nil)
1977 ;; Htmlize region.
1978 (org-html-htmlize-region-for-paste
1979 (point-min) (point-max))))
1980 ;; Strip any enclosing <pre></pre> tags.
1981 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1982 (end (and beg (string-match "</pre>\\'" code))))
1983 (if (and beg end) (substring code beg end) code)))))))))
1985 (defun org-html-do-format-code
1986 (code &optional lang refs retain-labels num-start)
1987 "Format CODE string as source code.
1988 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1989 respectively, the language of the source code, as a string, an
1990 alist between line numbers and references (as returned by
1991 `org-export-unravel-code'), a boolean specifying if labels should
1992 appear in the source code, and the number associated to the first
1993 line of code."
1994 (let* ((code-lines (org-split-string code "\n"))
1995 (code-length (length code-lines))
1996 (num-fmt
1997 (and num-start
1998 (format "%%%ds: "
1999 (length (number-to-string (+ code-length num-start))))))
2000 (code (org-html-fontify-code code lang)))
2001 (org-export-format-code
2002 code
2003 (lambda (loc line-num ref)
2004 (setq loc
2005 (concat
2006 ;; Add line number, if needed.
2007 (when num-start
2008 (format "<span class=\"linenr\">%s</span>"
2009 (format num-fmt line-num)))
2010 ;; Transcoded src line.
2012 ;; Add label, if needed.
2013 (when (and ref retain-labels) (format " (%s)" ref))))
2014 ;; Mark transcoded line as an anchor, if needed.
2015 (if (not ref) loc
2016 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2017 ref loc)))
2018 num-start refs)))
2020 (defun org-html-format-code (element info)
2021 "Format contents of ELEMENT as source code.
2022 ELEMENT is either an example block or a src block. INFO is
2023 a plist used as a communication channel."
2024 (let* ((lang (org-element-property :language element))
2025 ;; Extract code and references.
2026 (code-info (org-export-unravel-code element))
2027 (code (car code-info))
2028 (refs (cdr code-info))
2029 ;; Does the src block contain labels?
2030 (retain-labels (org-element-property :retain-labels element))
2031 ;; Does it have line numbers?
2032 (num-start (case (org-element-property :number-lines element)
2033 (continued (org-export-get-loc element info))
2034 (new 0))))
2035 (org-html-do-format-code code lang refs retain-labels num-start)))
2038 ;;; Tables of Contents
2040 (defun org-html-toc (depth info)
2041 "Build a table of contents.
2042 DEPTH is an integer specifying the depth of the table. INFO is a
2043 plist used as a communication channel. Return the table of
2044 contents as a string, or nil if it is empty."
2045 (let ((toc-entries
2046 (mapcar (lambda (headline)
2047 (cons (org-html--format-toc-headline headline info)
2048 (org-export-get-relative-level headline info)))
2049 (org-export-collect-headlines info depth)))
2050 (outer-tag (if (and (org-html-html5-p info)
2051 (plist-get info :html-html5-fancy))
2052 "nav"
2053 "div")))
2054 (when toc-entries
2055 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2056 (format "<h%d>%s</h%d>\n"
2057 org-html-toplevel-hlevel
2058 (org-html--translate "Table of Contents" info)
2059 org-html-toplevel-hlevel)
2060 "<div id=\"text-table-of-contents\">"
2061 (org-html--toc-text toc-entries)
2062 "</div>\n"
2063 (format "</%s>\n" outer-tag)))))
2065 (defun org-html--toc-text (toc-entries)
2066 "Return innards of a table of contents, as a string.
2067 TOC-ENTRIES is an alist where key is an entry title, as a string,
2068 and value is its relative level, as an integer."
2069 (let* ((prev-level (1- (cdar toc-entries)))
2070 (start-level prev-level))
2071 (concat
2072 (mapconcat
2073 (lambda (entry)
2074 (let ((headline (car entry))
2075 (level (cdr entry)))
2076 (concat
2077 (let* ((cnt (- level prev-level))
2078 (times (if (> cnt 0) (1- cnt) (- cnt)))
2079 rtn)
2080 (setq prev-level level)
2081 (concat
2082 (org-html--make-string
2083 times (cond ((> cnt 0) "\n<ul>\n<li>")
2084 ((< cnt 0) "</li>\n</ul>\n")))
2085 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2086 headline)))
2087 toc-entries "")
2088 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2090 (defun org-html--format-toc-headline (headline info)
2091 "Return an appropriate table of contents entry for HEADLINE.
2092 INFO is a plist used as a communication channel."
2093 (let* ((headline-number (org-export-get-headline-number headline info))
2094 (todo (and (plist-get info :with-todo-keywords)
2095 (let ((todo (org-element-property :todo-keyword headline)))
2096 (and todo (org-export-data todo info)))))
2097 (todo-type (and todo (org-element-property :todo-type headline)))
2098 (priority (and (plist-get info :with-priority)
2099 (org-element-property :priority headline)))
2100 (text (org-export-data-with-backend
2101 (org-export-get-alt-title headline info)
2102 ;; Create an anonymous back-end that will ignore any
2103 ;; footnote-reference, link, radio-target and target
2104 ;; in table of contents.
2105 (org-export-create-backend
2106 :parent 'html
2107 :transcoders '((footnote-reference . ignore)
2108 (link . (lambda (object c i) c))
2109 (radio-target . (lambda (object c i) c))
2110 (target . ignore)))
2111 info))
2112 (tags (and (eq (plist-get info :with-tags) t)
2113 (org-export-get-tags headline info))))
2114 (format "<a href=\"#%s\">%s</a>"
2115 ;; Label.
2116 (org-export-solidify-link-text
2117 (or (org-element-property :CUSTOM_ID headline)
2118 (concat "sec-"
2119 (mapconcat #'number-to-string headline-number "-"))))
2120 ;; Body.
2121 (concat
2122 (and (not (org-export-low-level-p headline info))
2123 (org-export-numbered-headline-p headline info)
2124 (concat (mapconcat #'number-to-string headline-number ".")
2125 ". "))
2126 (apply (if (not (eq org-html-format-headline-function 'ignore))
2127 (lambda (todo todo-type priority text tags &rest ignore)
2128 (funcall org-html-format-headline-function
2129 todo todo-type priority text tags))
2130 #'org-html-format-headline)
2131 todo todo-type priority text tags :section-number nil)))))
2133 (defun org-html-list-of-listings (info)
2134 "Build a list of listings.
2135 INFO is a plist used as a communication channel. Return the list
2136 of listings as a string, or nil if it is empty."
2137 (let ((lol-entries (org-export-collect-listings info)))
2138 (when lol-entries
2139 (concat "<div id=\"list-of-listings\">\n"
2140 (format "<h%d>%s</h%d>\n"
2141 org-html-toplevel-hlevel
2142 (org-html--translate "List of Listings" info)
2143 org-html-toplevel-hlevel)
2144 "<div id=\"text-list-of-listings\">\n<ul>\n"
2145 (let ((count 0)
2146 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2147 (org-html--translate "Listing %d:" info))))
2148 (mapconcat
2149 (lambda (entry)
2150 (let ((label (org-element-property :name entry))
2151 (title (org-trim
2152 (org-export-data
2153 (or (org-export-get-caption entry t)
2154 (org-export-get-caption entry))
2155 info))))
2156 (concat
2157 "<li>"
2158 (if (not label)
2159 (concat (format initial-fmt (incf count)) " " title)
2160 (format "<a href=\"#%s\">%s %s</a>"
2161 (org-export-solidify-link-text label)
2162 (format initial-fmt (incf count))
2163 title))
2164 "</li>")))
2165 lol-entries "\n"))
2166 "\n</ul>\n</div>\n</div>"))))
2168 (defun org-html-list-of-tables (info)
2169 "Build a list of tables.
2170 INFO is a plist used as a communication channel. Return the list
2171 of tables as a string, or nil if it is empty."
2172 (let ((lol-entries (org-export-collect-tables info)))
2173 (when lol-entries
2174 (concat "<div id=\"list-of-tables\">\n"
2175 (format "<h%d>%s</h%d>\n"
2176 org-html-toplevel-hlevel
2177 (org-html--translate "List of Tables" info)
2178 org-html-toplevel-hlevel)
2179 "<div id=\"text-list-of-tables\">\n<ul>\n"
2180 (let ((count 0)
2181 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2182 (org-html--translate "Table %d:" info))))
2183 (mapconcat
2184 (lambda (entry)
2185 (let ((label (org-element-property :name entry))
2186 (title (org-trim
2187 (org-export-data
2188 (or (org-export-get-caption entry t)
2189 (org-export-get-caption entry))
2190 info))))
2191 (concat
2192 "<li>"
2193 (if (not label)
2194 (concat (format initial-fmt (incf count)) " " title)
2195 (format "<a href=\"#%s\">%s %s</a>"
2196 (org-export-solidify-link-text label)
2197 (format initial-fmt (incf count))
2198 title))
2199 "</li>")))
2200 lol-entries "\n"))
2201 "\n</ul>\n</div>\n</div>"))))
2204 ;;; Transcode Functions
2206 ;;;; Bold
2208 (defun org-html-bold (bold contents info)
2209 "Transcode BOLD from Org to HTML.
2210 CONTENTS is the text with bold markup. INFO is a plist holding
2211 contextual information."
2212 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
2213 contents))
2215 ;;;; Center Block
2217 (defun org-html-center-block (center-block contents info)
2218 "Transcode a CENTER-BLOCK element from Org to HTML.
2219 CONTENTS holds the contents of the block. INFO is a plist
2220 holding contextual information."
2221 (format "<div class=\"center\">\n%s</div>" contents))
2223 ;;;; Clock
2225 (defun org-html-clock (clock contents info)
2226 "Transcode a CLOCK element from Org to HTML.
2227 CONTENTS is nil. INFO is a plist used as a communication
2228 channel."
2229 (format "<p>
2230 <span class=\"timestamp-wrapper\">
2231 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2232 </span>
2233 </p>"
2234 org-clock-string
2235 (org-translate-time
2236 (org-element-property :raw-value
2237 (org-element-property :value clock)))
2238 (let ((time (org-element-property :duration clock)))
2239 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2241 ;;;; Code
2243 (defun org-html-code (code contents info)
2244 "Transcode CODE from Org to HTML.
2245 CONTENTS is nil. INFO is a plist holding contextual
2246 information."
2247 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2248 (org-html-encode-plain-text (org-element-property :value code))))
2250 ;;;; Drawer
2252 (defun org-html-drawer (drawer contents info)
2253 "Transcode a DRAWER element from Org to HTML.
2254 CONTENTS holds the contents of the block. INFO is a plist
2255 holding contextual information."
2256 (if (functionp org-html-format-drawer-function)
2257 (funcall org-html-format-drawer-function
2258 (org-element-property :drawer-name drawer)
2259 contents)
2260 ;; If there's no user defined function: simply
2261 ;; display contents of the drawer.
2262 contents))
2264 ;;;; Dynamic Block
2266 (defun org-html-dynamic-block (dynamic-block contents info)
2267 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2268 CONTENTS holds the contents of the block. INFO is a plist
2269 holding contextual information. See `org-export-data'."
2270 contents)
2272 ;;;; Entity
2274 (defun org-html-entity (entity contents info)
2275 "Transcode an ENTITY object from Org to HTML.
2276 CONTENTS are the definition itself. INFO is a plist holding
2277 contextual information."
2278 (org-element-property :html entity))
2280 ;;;; Example Block
2282 (defun org-html-example-block (example-block contents info)
2283 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2284 CONTENTS is nil. INFO is a plist holding contextual
2285 information."
2286 (if (org-export-read-attribute :attr_html example-block :textarea)
2287 (org-html--textarea-block example-block)
2288 (format "<pre class=\"example\">\n%s</pre>"
2289 (org-html-format-code example-block info))))
2291 ;;;; Export Snippet
2293 (defun org-html-export-snippet (export-snippet contents info)
2294 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2295 CONTENTS is nil. INFO is a plist holding contextual
2296 information."
2297 (when (eq (org-export-snippet-backend export-snippet) 'html)
2298 (org-element-property :value export-snippet)))
2300 ;;;; Fixed Width
2302 (defun org-html-fixed-width (fixed-width contents info)
2303 "Transcode a FIXED-WIDTH element from Org to HTML.
2304 CONTENTS is nil. INFO is a plist holding contextual information."
2305 (format "<pre class=\"example\">\n%s</pre>"
2306 (org-html-do-format-code
2307 (org-remove-indentation
2308 (org-element-property :value fixed-width)))))
2310 ;;;; Footnote Reference
2312 (defun org-html-footnote-reference (footnote-reference contents info)
2313 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2314 CONTENTS is nil. INFO is a plist holding contextual information."
2315 (concat
2316 ;; Insert separator between two footnotes in a row.
2317 (let ((prev (org-export-get-previous-element footnote-reference info)))
2318 (when (eq (org-element-type prev) 'footnote-reference)
2319 org-html-footnote-separator))
2320 (cond
2321 ((not (org-export-footnote-first-reference-p footnote-reference info))
2322 (org-html-format-footnote-reference
2323 (org-export-get-footnote-number footnote-reference info)
2324 "IGNORED" 100))
2325 ;; Inline definitions are secondary strings.
2326 ((eq (org-element-property :type footnote-reference) 'inline)
2327 (org-html-format-footnote-reference
2328 (org-export-get-footnote-number footnote-reference info)
2329 "IGNORED" 1))
2330 ;; Non-inline footnotes definitions are full Org data.
2331 (t (org-html-format-footnote-reference
2332 (org-export-get-footnote-number footnote-reference info)
2333 "IGNORED" 1)))))
2335 ;;;; Headline
2337 (defun org-html-format-headline--wrap
2338 (headline info &optional format-function &rest extra-keys)
2339 "Transcode a HEADLINE element from Org to HTML.
2340 CONTENTS holds the contents of the headline. INFO is a plist
2341 holding contextual information."
2342 (let* ((level (+ (org-export-get-relative-level headline info)
2343 (1- org-html-toplevel-hlevel)))
2344 (headline-number (org-export-get-headline-number headline info))
2345 (section-number (and (not (org-export-low-level-p headline info))
2346 (org-export-numbered-headline-p headline info)
2347 (mapconcat 'number-to-string
2348 headline-number ".")))
2349 (todo (and (plist-get info :with-todo-keywords)
2350 (let ((todo (org-element-property :todo-keyword headline)))
2351 (and todo (org-export-data todo info)))))
2352 (todo-type (and todo (org-element-property :todo-type headline)))
2353 (priority (and (plist-get info :with-priority)
2354 (org-element-property :priority headline)))
2355 (text (org-export-data (org-element-property :title headline) info))
2356 (tags (and (plist-get info :with-tags)
2357 (org-export-get-tags headline info)))
2358 (headline-label (or (org-element-property :CUSTOM_ID headline)
2359 (concat "sec-" (mapconcat 'number-to-string
2360 headline-number "-"))))
2361 (format-function
2362 (cond ((functionp format-function) format-function)
2363 ((not (eq org-html-format-headline-function 'ignore))
2364 (lambda (todo todo-type priority text tags &rest ignore)
2365 (funcall org-html-format-headline-function
2366 todo todo-type priority text tags)))
2367 (t 'org-html-format-headline))))
2368 (apply format-function
2369 todo todo-type priority text tags
2370 :headline-label headline-label :level level
2371 :section-number section-number extra-keys)))
2373 (defun org-html-headline (headline contents info)
2374 "Transcode a HEADLINE element from Org to HTML.
2375 CONTENTS holds the contents of the headline. INFO is a plist
2376 holding contextual information."
2377 ;; Empty contents?
2378 (setq contents (or contents ""))
2379 (let* ((numberedp (org-export-numbered-headline-p headline info))
2380 (level (org-export-get-relative-level headline info))
2381 (text (org-export-data (org-element-property :title headline) info))
2382 (todo (and (plist-get info :with-todo-keywords)
2383 (let ((todo (org-element-property :todo-keyword headline)))
2384 (and todo (org-export-data todo info)))))
2385 (todo-type (and todo (org-element-property :todo-type headline)))
2386 (tags (and (plist-get info :with-tags)
2387 (org-export-get-tags headline info)))
2388 (priority (and (plist-get info :with-priority)
2389 (org-element-property :priority headline)))
2390 (section-number (and (org-export-numbered-headline-p headline info)
2391 (mapconcat 'number-to-string
2392 (org-export-get-headline-number
2393 headline info) ".")))
2394 ;; Create the headline text.
2395 (full-text (org-html-format-headline--wrap headline info)))
2396 (cond
2397 ;; Case 1: This is a footnote section: ignore it.
2398 ((org-element-property :footnote-section-p headline) nil)
2399 ;; Case 2. This is a deep sub-tree: export it as a list item.
2400 ;; Also export as items headlines for which no section
2401 ;; format has been found.
2402 ((org-export-low-level-p headline info)
2403 ;; Build the real contents of the sub-tree.
2404 (let* ((type (if numberedp 'ordered 'unordered))
2405 (itemized-body (org-html-format-list-item
2406 contents type nil info nil full-text)))
2407 (concat
2408 (and (org-export-first-sibling-p headline info)
2409 (org-html-begin-plain-list type))
2410 itemized-body
2411 (and (org-export-last-sibling-p headline info)
2412 (org-html-end-plain-list type)))))
2413 ;; Case 3. Standard headline. Export it as a section.
2415 (let* ((section-number (mapconcat 'number-to-string
2416 (org-export-get-headline-number
2417 headline info) "-"))
2418 (ids (remove 'nil
2419 (list (org-element-property :CUSTOM_ID headline)
2420 (concat "sec-" section-number)
2421 (org-element-property :ID headline))))
2422 (preferred-id (car ids))
2423 (extra-ids (cdr ids))
2424 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2425 (level1 (+ level (1- org-html-toplevel-hlevel)))
2426 (first-content (car (org-element-contents headline))))
2427 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2428 (org-html--container headline info)
2429 (format "outline-container-%s"
2430 (or (org-element-property :CUSTOM_ID headline)
2431 (concat "sec-" section-number)))
2432 (concat (format "outline-%d" level1) (and extra-class " ")
2433 extra-class)
2434 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2435 level1
2436 preferred-id
2437 (mapconcat
2438 (lambda (x)
2439 (let ((id (org-export-solidify-link-text
2440 (if (org-uuidgen-p x) (concat "ID-" x)
2441 x))))
2442 (org-html--anchor id)))
2443 extra-ids "")
2444 full-text
2445 level1)
2446 ;; When there is no section, pretend there is an empty
2447 ;; one to get the correct <div class="outline- ...>
2448 ;; which is needed by `org-info.js'.
2449 (if (not (eq (org-element-type first-content) 'section))
2450 (concat (org-html-section first-content "" info)
2451 contents)
2452 contents)
2453 (org-html--container headline info)))))))
2455 (defun org-html--container (headline info)
2456 (or (org-element-property :HTML_CONTAINER headline)
2457 (if (= 1 (org-export-get-relative-level headline info))
2458 (plist-get info :html-container)
2459 "div")))
2461 ;;;; Horizontal Rule
2463 (defun org-html-horizontal-rule (horizontal-rule contents info)
2464 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2465 CONTENTS is nil. INFO is a plist holding contextual information."
2466 (org-html-close-tag "hr" nil info))
2468 ;;;; Inline Src Block
2470 (defun org-html-inline-src-block (inline-src-block contents info)
2471 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2472 CONTENTS holds the contents of the item. INFO is a plist holding
2473 contextual information."
2474 (let* ((org-lang (org-element-property :language inline-src-block))
2475 (code (org-element-property :value inline-src-block)))
2476 (error "Cannot export inline src block")))
2478 ;;;; Inlinetask
2480 (defun org-html-format-section (text class &optional id)
2481 "Format a section with TEXT into a HTML div with CLASS and ID."
2482 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2483 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2485 (defun org-html-inlinetask (inlinetask contents info)
2486 "Transcode an INLINETASK element from Org to HTML.
2487 CONTENTS holds the contents of the block. INFO is a plist
2488 holding contextual information."
2489 (cond
2490 ;; If `org-html-format-inlinetask-function' is not 'ignore, call it
2491 ;; with appropriate arguments.
2492 ((not (eq org-html-format-inlinetask-function 'ignore))
2493 (let ((format-function
2494 (function*
2495 (lambda (todo todo-type priority text tags
2496 &key contents &allow-other-keys)
2497 (funcall org-html-format-inlinetask-function
2498 todo todo-type priority text tags contents)))))
2499 (org-html-format-headline--wrap
2500 inlinetask info format-function :contents contents)))
2501 ;; Otherwise, use a default template.
2502 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2503 (org-html-format-headline--wrap inlinetask info)
2504 (org-html-close-tag "br" nil info)
2505 contents))))
2507 ;;;; Italic
2509 (defun org-html-italic (italic contents info)
2510 "Transcode ITALIC from Org to HTML.
2511 CONTENTS is the text with italic markup. INFO is a plist holding
2512 contextual information."
2513 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2515 ;;;; Item
2517 (defun org-html-checkbox (checkbox info)
2518 "Format CHECKBOX into HTML.
2519 INFO is a plist holding contextual information. See
2520 `org-html-checkbox-type' for customization options."
2521 (cdr (assq checkbox
2522 (cdr (assq org-html-checkbox-type org-html-checkbox-types)))))
2524 (defun org-html-format-list-item (contents type checkbox info
2525 &optional term-counter-id
2526 headline)
2527 "Format a list item into HTML."
2528 (let ((class (if checkbox
2529 (format " class=\"%s\""
2530 (symbol-name checkbox)) ""))
2531 (checkbox (concat (org-html-checkbox checkbox info)
2532 (and checkbox " ")))
2533 (br (org-html-close-tag "br" nil info)))
2534 (concat
2535 (case type
2536 (ordered
2537 (let* ((counter term-counter-id)
2538 (extra (if counter (format " value=\"%s\"" counter) "")))
2539 (concat
2540 (format "<li%s%s>" class extra)
2541 (when headline (concat headline br)))))
2542 (unordered
2543 (let* ((id term-counter-id)
2544 (extra (if id (format " id=\"%s\"" id) "")))
2545 (concat
2546 (format "<li%s%s>" class extra)
2547 (when headline (concat headline br)))))
2548 (descriptive
2549 (let* ((term term-counter-id))
2550 (setq term (or term "(no term)"))
2551 ;; Check-boxes in descriptive lists are associated to tag.
2552 (concat (format "<dt%s>%s</dt>"
2553 class (concat checkbox term))
2554 "<dd>"))))
2555 (unless (eq type 'descriptive) checkbox)
2556 contents
2557 (case type
2558 (ordered "</li>")
2559 (unordered "</li>")
2560 (descriptive "</dd>")))))
2562 (defun org-html-item (item contents info)
2563 "Transcode an ITEM element from Org to HTML.
2564 CONTENTS holds the contents of the item. INFO is a plist holding
2565 contextual information."
2566 (let* ((plain-list (org-export-get-parent item))
2567 (type (org-element-property :type plain-list))
2568 (counter (org-element-property :counter item))
2569 (checkbox (org-element-property :checkbox item))
2570 (tag (let ((tag (org-element-property :tag item)))
2571 (and tag (org-export-data tag info)))))
2572 (org-html-format-list-item
2573 contents type checkbox info (or tag counter))))
2575 ;;;; Keyword
2577 (defun org-html-keyword (keyword contents info)
2578 "Transcode a KEYWORD element from Org to HTML.
2579 CONTENTS is nil. INFO is a plist holding contextual information."
2580 (let ((key (org-element-property :key keyword))
2581 (value (org-element-property :value keyword)))
2582 (cond
2583 ((string= key "HTML") value)
2584 ((string= key "TOC")
2585 (let ((value (downcase value)))
2586 (cond
2587 ((string-match "\\<headlines\\>" value)
2588 (let ((depth (or (and (string-match "[0-9]+" value)
2589 (string-to-number (match-string 0 value)))
2590 (plist-get info :with-toc))))
2591 (org-html-toc depth info)))
2592 ((string= "listings" value) (org-html-list-of-listings info))
2593 ((string= "tables" value) (org-html-list-of-tables info))))))))
2595 ;;;; Latex Environment
2597 (defun org-html-format-latex (latex-frag processing-type info)
2598 "Format a LaTeX fragment LATEX-FRAG into HTML.
2599 PROCESSING-TYPE designates the tool used for conversion. It is
2600 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2601 and t. See `org-html-with-latex' for more information. INFO is
2602 a plist containing export properties."
2603 (let ((cache-relpath "") (cache-dir ""))
2604 (unless (eq processing-type 'mathjax)
2605 (let ((bfn (or (buffer-file-name)
2606 (make-temp-name
2607 (expand-file-name "latex" temporary-file-directory))))
2608 (latex-header
2609 (let ((header (plist-get info :latex-header)))
2610 (and header
2611 (concat (mapconcat
2612 (lambda (line) (concat "#+LATEX_HEADER: " line))
2613 (org-split-string header "\n")
2614 "\n")
2615 "\n")))))
2616 (setq cache-relpath
2617 (concat "ltxpng/"
2618 (file-name-sans-extension
2619 (file-name-nondirectory bfn)))
2620 cache-dir (file-name-directory bfn))
2621 ;; Re-create LaTeX environment from original buffer in
2622 ;; temporary buffer so that dvipng/imagemagick can properly
2623 ;; turn the fragment into an image.
2624 (setq latex-frag (concat latex-header latex-frag))))
2625 (with-temp-buffer
2626 (insert latex-frag)
2627 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2628 nil nil processing-type)
2629 (buffer-string))))
2631 (defun org-html-latex-environment (latex-environment contents info)
2632 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2633 CONTENTS is nil. INFO is a plist holding contextual information."
2634 (let ((processing-type (plist-get info :with-latex))
2635 (latex-frag (org-remove-indentation
2636 (org-element-property :value latex-environment)))
2637 (attributes (org-export-read-attribute :attr_html latex-environment)))
2638 (case processing-type
2639 ((t mathjax)
2640 (org-html-format-latex latex-frag 'mathjax info))
2641 ((dvipng imagemagick)
2642 (let ((formula-link
2643 (org-html-format-latex latex-frag processing-type info)))
2644 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2645 ;; Do not provide a caption or a name to be consistent with
2646 ;; `mathjax' handling.
2647 (org-html--wrap-image
2648 (org-html--format-image
2649 (match-string 1 formula-link) attributes info) info))))
2650 (t latex-frag))))
2652 ;;;; Latex Fragment
2654 (defun org-html-latex-fragment (latex-fragment contents info)
2655 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2656 CONTENTS is nil. INFO is a plist holding contextual information."
2657 (let ((latex-frag (org-element-property :value latex-fragment))
2658 (processing-type (plist-get info :with-latex)))
2659 (case processing-type
2660 ((t mathjax)
2661 (org-html-format-latex latex-frag 'mathjax info))
2662 ((dvipng imagemagick)
2663 (let ((formula-link
2664 (org-html-format-latex latex-frag processing-type info)))
2665 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2666 (org-html--format-image (match-string 1 formula-link) nil info))))
2667 (t latex-frag))))
2669 ;;;; Line Break
2671 (defun org-html-line-break (line-break contents info)
2672 "Transcode a LINE-BREAK object from Org to HTML.
2673 CONTENTS is nil. INFO is a plist holding contextual information."
2674 (concat (org-html-close-tag "br" nil info) "\n"))
2676 ;;;; Link
2678 (defun org-html-inline-image-p (link info)
2679 "Non-nil when LINK is meant to appear as an image.
2680 INFO is a plist used as a communication channel. LINK is an
2681 inline image when it has no description and targets an image
2682 file (see `org-html-inline-image-rules' for more information), or
2683 if its description is a single link targeting an image file."
2684 (if (not (org-element-contents link))
2685 (org-export-inline-image-p link org-html-inline-image-rules)
2686 (not
2687 (let ((link-count 0))
2688 (org-element-map (org-element-contents link)
2689 (cons 'plain-text org-element-all-objects)
2690 (lambda (obj)
2691 (case (org-element-type obj)
2692 (plain-text (org-string-nw-p obj))
2693 (link (if (= link-count 1) t
2694 (incf link-count)
2695 (not (org-export-inline-image-p
2696 obj org-html-inline-image-rules))))
2697 (otherwise t)))
2698 info t)))))
2700 (defvar org-html-standalone-image-predicate)
2701 (defun org-html-standalone-image-p (element info)
2702 "Non-nil if ELEMENT is a standalone image.
2704 INFO is a plist holding contextual information.
2706 An element or object is a standalone image when
2708 - its type is `paragraph' and its sole content, save for white
2709 spaces, is a link that qualifies as an inline image;
2711 - its type is `link' and its containing paragraph has no other
2712 content save white spaces.
2714 Bind `org-html-standalone-image-predicate' to constrain paragraph
2715 further. For example, to check for only captioned standalone
2716 images, set it to:
2718 \(lambda (paragraph) (org-element-property :caption paragraph))"
2719 (let ((paragraph (case (org-element-type element)
2720 (paragraph element)
2721 (link (org-export-get-parent element)))))
2722 (and (eq (org-element-type paragraph) 'paragraph)
2723 (or (not (fboundp 'org-html-standalone-image-predicate))
2724 (funcall org-html-standalone-image-predicate paragraph))
2725 (catch 'exit
2726 (let ((link-count 0))
2727 (org-element-map (org-element-contents paragraph)
2728 (cons 'plain-text org-element-all-objects)
2729 #'(lambda (obj)
2730 (when (case (org-element-type obj)
2731 (plain-text (org-string-nw-p obj))
2732 (link (or (> (incf link-count) 1)
2733 (not (org-html-inline-image-p obj info))))
2734 (otherwise t))
2735 (throw 'exit nil)))
2736 info nil 'link)
2737 (= link-count 1))))))
2739 (defun org-html-link (link desc info)
2740 "Transcode a LINK object from Org to HTML.
2742 DESC is the description part of the link, or the empty string.
2743 INFO is a plist holding contextual information. See
2744 `org-export-data'."
2745 (let* ((home (when (plist-get info :html-link-home)
2746 (org-trim (plist-get info :html-link-home))))
2747 (use-abs-url (plist-get info :html-link-use-abs-url))
2748 (link-org-files-as-html-maybe
2749 (function
2750 (lambda (raw-path info)
2751 "Treat links to `file.org' as links to `file.html', if needed.
2752 See `org-html-link-org-files-as-html'."
2753 (cond
2754 ((and org-html-link-org-files-as-html
2755 (string= ".org"
2756 (downcase (file-name-extension raw-path "."))))
2757 (concat (file-name-sans-extension raw-path) "."
2758 (plist-get info :html-extension)))
2759 (t raw-path)))))
2760 (type (org-element-property :type link))
2761 (raw-path (org-element-property :path link))
2762 ;; Ensure DESC really exists, or set it to nil.
2763 (desc (org-string-nw-p desc))
2764 (path
2765 (cond
2766 ((member type '("http" "https" "ftp" "mailto"))
2767 (org-link-escape-browser
2768 (org-link-unescape (concat type ":" raw-path))))
2769 ((string= type "file")
2770 ;; Treat links to ".org" files as ".html", if needed.
2771 (setq raw-path
2772 (funcall link-org-files-as-html-maybe raw-path info))
2773 ;; If file path is absolute, prepend it with protocol
2774 ;; component - "file:".
2775 (cond
2776 ((file-name-absolute-p raw-path)
2777 (setq raw-path (concat "file:" raw-path)))
2778 ((and home use-abs-url)
2779 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2780 ;; Add search option, if any. A search option can be
2781 ;; relative to a custom-id or a headline title. Append
2782 ;; a hash sign to any unresolved option, as it might point
2783 ;; to a target.
2784 (let ((option (org-element-property :search-option link)))
2785 (cond ((not option) raw-path)
2786 ((eq (aref option 0) ?#) (concat raw-path option))
2788 (let ((destination
2789 (org-publish-resolve-external-fuzzy-link
2790 (org-element-property :path link) option)))
2791 (concat raw-path
2792 (if (not destination) (concat "#" option)
2793 (concat "#sec-"
2794 (mapconcat #'number-to-string
2795 destination "-")))))))))
2796 (t raw-path)))
2797 ;; Extract attributes from parent's paragraph. HACK: Only do
2798 ;; this for the first link in parent (inner image link for
2799 ;; inline images). This is needed as long as attributes
2800 ;; cannot be set on a per link basis.
2801 (attributes-plist
2802 (let* ((parent (org-export-get-parent-element link))
2803 (link (let ((container (org-export-get-parent link)))
2804 (if (and (eq (org-element-type container) 'link)
2805 (org-html-inline-image-p link info))
2806 container
2807 link))))
2808 (and (eq (org-element-map parent 'link 'identity info t) link)
2809 (org-export-read-attribute :attr_html parent))))
2810 (attributes
2811 (let ((attr (org-html--make-attribute-string attributes-plist)))
2812 (if (org-string-nw-p attr) (concat " " attr) "")))
2813 protocol)
2814 (cond
2815 ;; Image file.
2816 ((and org-html-inline-images
2817 (org-export-inline-image-p link org-html-inline-image-rules))
2818 (org-html--format-image path attributes-plist info))
2819 ;; Radio target: Transcode target's contents and use them as
2820 ;; link's description.
2821 ((string= type "radio")
2822 (let ((destination (org-export-resolve-radio-link link info)))
2823 (when destination
2824 (format "<a href=\"#%s\"%s>%s</a>"
2825 (org-export-solidify-link-text
2826 (org-element-property :value destination))
2827 attributes desc))))
2828 ;; Links pointing to a headline: Find destination and build
2829 ;; appropriate referencing command.
2830 ((member type '("custom-id" "fuzzy" "id"))
2831 (let ((destination (if (string= type "fuzzy")
2832 (org-export-resolve-fuzzy-link link info)
2833 (org-export-resolve-id-link link info))))
2834 (case (org-element-type destination)
2835 ;; ID link points to an external file.
2836 (plain-text
2837 (let ((fragment (concat "ID-" path))
2838 ;; Treat links to ".org" files as ".html", if needed.
2839 (path (funcall link-org-files-as-html-maybe
2840 destination info)))
2841 (format "<a href=\"%s#%s\"%s>%s</a>"
2842 path fragment attributes (or desc destination))))
2843 ;; Fuzzy link points nowhere.
2844 ((nil)
2845 (format "<i>%s</i>"
2846 (or desc
2847 (org-export-data
2848 (org-element-property :raw-link link) info))))
2849 ;; Link points to a headline.
2850 (headline
2851 (let ((href
2852 ;; What href to use?
2853 (cond
2854 ;; Case 1: Headline is linked via it's CUSTOM_ID
2855 ;; property. Use CUSTOM_ID.
2856 ((string= type "custom-id")
2857 (org-element-property :CUSTOM_ID destination))
2858 ;; Case 2: Headline is linked via it's ID property
2859 ;; or through other means. Use the default href.
2860 ((member type '("id" "fuzzy"))
2861 (format "sec-%s"
2862 (mapconcat 'number-to-string
2863 (org-export-get-headline-number
2864 destination info) "-")))
2865 (t (error "Shouldn't reach here"))))
2866 ;; What description to use?
2867 (desc
2868 ;; Case 1: Headline is numbered and LINK has no
2869 ;; description. Display section number.
2870 (if (and (org-export-numbered-headline-p destination info)
2871 (not desc))
2872 (mapconcat 'number-to-string
2873 (org-export-get-headline-number
2874 destination info) ".")
2875 ;; Case 2: Either the headline is un-numbered or
2876 ;; LINK has a custom description. Display LINK's
2877 ;; description or headline's title.
2878 (or desc (org-export-data (org-element-property
2879 :title destination) info)))))
2880 (format "<a href=\"#%s\"%s>%s</a>"
2881 (org-export-solidify-link-text href) attributes desc)))
2882 ;; Fuzzy link points to a target or an element.
2884 (let* ((path (org-export-solidify-link-text path))
2885 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2886 (number (cond
2887 (desc nil)
2888 ((org-html-standalone-image-p destination info)
2889 (org-export-get-ordinal
2890 (org-element-map destination 'link
2891 'identity info t)
2892 info 'link 'org-html-standalone-image-p))
2893 (t (org-export-get-ordinal
2894 destination info nil 'org-html--has-caption-p))))
2895 (desc (cond (desc)
2896 ((not number) "No description for this link")
2897 ((numberp number) (number-to-string number))
2898 (t (mapconcat 'number-to-string number ".")))))
2899 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2900 ;; Coderef: replace link with the reference name or the
2901 ;; equivalent line number.
2902 ((string= type "coderef")
2903 (let ((fragment (concat "coderef-" path)))
2904 (format "<a href=\"#%s\"%s%s>%s</a>"
2905 fragment
2906 (org-trim
2907 (format (concat "class=\"coderef\""
2908 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2909 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2910 fragment fragment))
2911 attributes
2912 (format (org-export-get-coderef-format path desc)
2913 (org-export-resolve-coderef path info)))))
2914 ;; Link type is handled by a special function.
2915 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2916 (funcall protocol (org-link-unescape path) desc 'html))
2917 ;; External link with a description part.
2918 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2919 ;; External link without a description part.
2920 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2921 ;; No path, only description. Try to do something useful.
2922 (t (format "<i>%s</i>" desc)))))
2924 ;;;; Node Property
2926 (defun org-html-node-property (node-property contents info)
2927 "Transcode a NODE-PROPERTY element from Org to HTML.
2928 CONTENTS is nil. INFO is a plist holding contextual
2929 information."
2930 (format "%s:%s"
2931 (org-element-property :key node-property)
2932 (let ((value (org-element-property :value node-property)))
2933 (if value (concat " " value) ""))))
2935 ;;;; Paragraph
2937 (defun org-html-paragraph (paragraph contents info)
2938 "Transcode a PARAGRAPH element from Org to HTML.
2939 CONTENTS is the contents of the paragraph, as a string. INFO is
2940 the plist used as a communication channel."
2941 (let* ((parent (org-export-get-parent paragraph))
2942 (parent-type (org-element-type parent))
2943 (style '((footnote-definition " class=\"footpara\"")))
2944 (attributes (org-html--make-attribute-string
2945 (org-export-read-attribute :attr_html paragraph)))
2946 (extra (or (cadr (assoc parent-type style)) "")))
2947 (cond
2948 ((and (eq (org-element-type parent) 'item)
2949 (= (org-element-property :begin paragraph)
2950 (org-element-property :contents-begin parent))
2951 (not (org-element-map (org-export-get-parent parent) 'item
2952 (lambda (item)
2953 (let ((contents (org-element-contents item)))
2954 (and contents
2955 (or (cdr contents)
2956 (not (eq (org-element-type (car contents))
2957 'paragraph))))))
2958 info 'first-match 'item)))
2959 ;; Leading paragraph in a list item have no tags if every
2960 ;; element of the containing list is only a single paragraph.
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 (if (org-export-raw-special-block-p special-block info)
3149 (org-remove-indentation (org-element-property :raw-value special-block))
3150 (let* ((block-type (downcase (org-element-property :type special-block)))
3151 (contents (or contents ""))
3152 (html5-fancy (and (org-html-html5-p info)
3153 (plist-get info :html-html5-fancy)
3154 (member block-type org-html-html5-elements)))
3155 (attributes (org-export-read-attribute :attr_html special-block)))
3156 (unless html5-fancy
3157 (let ((class (plist-get attributes :class)))
3158 (setq attributes (plist-put attributes :class
3159 (if class (concat class " " block-type)
3160 block-type)))))
3161 (setq attributes (org-html--make-attribute-string attributes))
3162 (when (not (equal attributes ""))
3163 (setq attributes (concat " " attributes)))
3164 (if html5-fancy
3165 (format "<%s%s>\n%s</%s>" block-type attributes 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