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