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