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