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