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