ox-html: Use upstream MathJax CDN
[org-mode.git] / lisp / ox-html.el
blobad71cda338fa6ccef1a82204136b0fdc76d65797
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2015 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; See Org manual for more information.
29 ;;; Code:
31 ;;; Dependencies
33 (require 'ox)
34 (require 'ox-publish)
35 (require 'format-spec)
36 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
39 ;;; Function Declarations
41 (declare-function org-id-find-id-file "org-id" (id))
42 (declare-function htmlize-region "ext:htmlize" (beg end))
43 (declare-function org-pop-to-buffer-same-window
44 "org-compat" (&optional buffer-or-name norecord label))
45 (declare-function mm-url-decode-entities "mm-url" ())
47 ;;; Define Back-End
49 (org-export-define-backend 'html
50 '((bold . org-html-bold)
51 (center-block . org-html-center-block)
52 (clock . org-html-clock)
53 (code . org-html-code)
54 (drawer . org-html-drawer)
55 (dynamic-block . org-html-dynamic-block)
56 (entity . org-html-entity)
57 (example-block . org-html-example-block)
58 (export-block . org-html-export-block)
59 (export-snippet . org-html-export-snippet)
60 (fixed-width . org-html-fixed-width)
61 (footnote-definition . org-html-footnote-definition)
62 (footnote-reference . org-html-footnote-reference)
63 (headline . org-html-headline)
64 (horizontal-rule . org-html-horizontal-rule)
65 (inline-src-block . org-html-inline-src-block)
66 (inlinetask . org-html-inlinetask)
67 (inner-template . org-html-inner-template)
68 (italic . org-html-italic)
69 (item . org-html-item)
70 (keyword . org-html-keyword)
71 (latex-environment . org-html-latex-environment)
72 (latex-fragment . org-html-latex-fragment)
73 (line-break . org-html-line-break)
74 (link . org-html-link)
75 (node-property . org-html-node-property)
76 (paragraph . org-html-paragraph)
77 (plain-list . org-html-plain-list)
78 (plain-text . org-html-plain-text)
79 (planning . org-html-planning)
80 (property-drawer . org-html-property-drawer)
81 (quote-block . org-html-quote-block)
82 (radio-target . org-html-radio-target)
83 (section . org-html-section)
84 (special-block . org-html-special-block)
85 (src-block . org-html-src-block)
86 (statistics-cookie . org-html-statistics-cookie)
87 (strike-through . org-html-strike-through)
88 (subscript . org-html-subscript)
89 (superscript . org-html-superscript)
90 (table . org-html-table)
91 (table-cell . org-html-table-cell)
92 (table-row . org-html-table-row)
93 (target . org-html-target)
94 (template . org-html-template)
95 (timestamp . org-html-timestamp)
96 (underline . org-html-underline)
97 (verbatim . org-html-verbatim)
98 (verse-block . org-html-verse-block))
99 :export-block "HTML"
100 :filters-alist '((:filter-options . org-html-infojs-install-script)
101 (:filter-final-output . org-html-final-function))
102 :menu-entry
103 '(?h "Export to HTML"
104 ((?H "As HTML buffer" org-html-export-as-html)
105 (?h "As HTML file" org-html-export-to-html)
106 (?o "As HTML file and open"
107 (lambda (a s v b)
108 (if a (org-html-export-to-html t s v b)
109 (org-open-file (org-html-export-to-html nil s v b)))))))
110 :options-alist
111 '((:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
112 (:html-container "HTML_CONTAINER" nil org-html-container-element)
113 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
114 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
115 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
116 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
117 (:html-container "HTML_CONTAINER" nil org-html-container-element)
118 (:html-mathjax "HTML_MATHJAX" nil "" space)
119 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
120 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
121 (:html-postamble nil "html-postamble" org-html-postamble)
122 (:html-preamble nil "html-preamble" org-html-preamble)
123 (:html-head "HTML_HEAD" nil org-html-head newline)
124 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
125 (:html-head-include-default-style
126 nil "html-style" org-html-head-include-default-style)
127 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
128 (:html-allow-name-attribute-in-anchors
129 nil nil org-html-allow-name-attribute-in-anchors)
130 (:html-divs nil nil org-html-divs)
131 (:html-checkbox-type nil nil org-html-checkbox-type)
132 (:html-extension nil nil org-html-extension)
133 (:html-footnote-format nil nil org-html-footnote-format)
134 (:html-footnote-separator nil nil org-html-footnote-separator)
135 (:html-footnotes-section nil nil org-html-footnotes-section)
136 (:html-format-drawer-function nil nil org-html-format-drawer-function)
137 (:html-format-headline-function nil nil org-html-format-headline-function)
138 (:html-format-inlinetask-function
139 nil nil org-html-format-inlinetask-function)
140 (:html-home/up-format nil nil org-html-home/up-format)
141 (:html-indent nil nil org-html-indent)
142 (:html-infojs-options nil nil org-html-infojs-options)
143 (:html-infojs-template nil nil org-html-infojs-template)
144 (:html-inline-image-rules nil nil org-html-inline-image-rules)
145 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html)
146 (:html-mathjax-options nil nil org-html-mathjax-options)
147 (:html-mathjax-template nil nil org-html-mathjax-template)
148 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format)
149 (:html-postamble-format nil nil org-html-postamble-format)
150 (:html-preamble-format nil nil org-html-preamble-format)
151 (:html-table-align-individual-fields
152 nil nil org-html-table-align-individual-fields)
153 (:html-table-caption-above nil nil org-html-table-caption-above)
154 (:html-table-data-tags nil nil org-html-table-data-tags)
155 (:html-table-header-tags nil nil org-html-table-header-tags)
156 (:html-table-use-header-tags-for-first-column
157 nil nil org-html-table-use-header-tags-for-first-column)
158 (:html-tag-class-prefix nil nil org-html-tag-class-prefix)
159 (:html-text-markup-alist nil nil org-html-text-markup-alist)
160 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix)
161 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel)
162 (:html-use-infojs nil nil org-html-use-infojs)
163 (:html-use-unicode-chars nil nil org-html-use-unicode-chars)
164 (:html-validation-link nil nil org-html-validation-link)
165 (:html-inline-images nil nil org-html-inline-images)
166 (:html-table-attributes nil nil org-html-table-default-attributes)
167 (:html-table-row-tags nil nil org-html-table-row-tags)
168 (:html-xml-declaration nil nil org-html-xml-declaration)
169 (:infojs-opt "INFOJS_OPT" nil nil)
170 ;; Redefine regular options.
171 (:creator "CREATOR" nil org-html-creator-string)
172 (:with-latex nil "tex" org-html-with-latex)
173 ;; Retrieve LaTeX header for fragments.
174 (:latex-header "LATEX_HEADER" nil nil newline)))
177 ;;; Internal Variables
179 (defvar org-html-format-table-no-css)
180 (defvar htmlize-buffer-places) ; from htmlize.el
182 (defvar org-html--pre/postamble-class "status"
183 "CSS class used for pre/postamble")
185 (defconst org-html-doctype-alist
186 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
187 \"http://www.w3.org/TR/html4/strict.dtd\">")
188 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
189 \"http://www.w3.org/TR/html4/loose.dtd\">")
190 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
191 \"http://www.w3.org/TR/html4/frameset.dtd\">")
193 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
194 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
195 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
196 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
197 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
198 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
199 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
200 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
202 ("html5" . "<!DOCTYPE html>")
203 ("xhtml5" . "<!DOCTYPE html>"))
204 "An alist mapping (x)html flavors to specific doctypes.")
206 (defconst org-html-html5-elements
207 '("article" "aside" "audio" "canvas" "details" "figcaption"
208 "figure" "footer" "header" "menu" "meter" "nav" "output"
209 "progress" "section" "video")
210 "New elements in html5.
212 For blocks that should contain headlines, use the HTML_CONTAINER
213 property on the headline itself.")
215 (defconst org-html-special-string-regexps
216 '(("\\\\-" . "&#x00ad;") ; shy
217 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
218 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
219 ("\\.\\.\\." . "&#x2026;")) ; hellip
220 "Regular expressions for special string conversion.")
222 (defconst org-html-scripts
223 "<script type=\"text/javascript\">
225 @licstart The following is the entire license notice for the
226 JavaScript code in this tag.
228 Copyright (C) 2012-2013 Free Software Foundation, Inc.
230 The JavaScript code in this tag is free software: you can
231 redistribute it and/or modify it under the terms of the GNU
232 General Public License (GNU GPL) as published by the Free Software
233 Foundation, either version 3 of the License, or (at your option)
234 any later version. The code is distributed WITHOUT ANY WARRANTY;
235 without even the implied warranty of MERCHANTABILITY or FITNESS
236 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
238 As additional permission under GNU GPL version 3 section 7, you
239 may distribute non-source (e.g., minimized or compacted) forms of
240 that code without the copy of the GNU GPL normally required by
241 section 4, provided you include this license notice and a URL
242 through which recipients can access the Corresponding Source.
245 @licend The above is the entire license notice
246 for the JavaScript code in this tag.
248 <!--/*--><![CDATA[/*><!--*/
249 function CodeHighlightOn(elem, id)
251 var target = document.getElementById(id);
252 if(null != target) {
253 elem.cacheClassElem = elem.className;
254 elem.cacheClassTarget = target.className;
255 target.className = \"code-highlighted\";
256 elem.className = \"code-highlighted\";
259 function CodeHighlightOff(elem, id)
261 var target = document.getElementById(id);
262 if(elem.cacheClassElem)
263 elem.className = elem.cacheClassElem;
264 if(elem.cacheClassTarget)
265 target.className = elem.cacheClassTarget;
267 /*]]>*///-->
268 </script>"
269 "Basic JavaScript that is needed by HTML files produced by Org mode.")
271 (defconst org-html-style-default
272 "<style type=\"text/css\">
273 <!--/*--><![CDATA[/*><!--*/
274 .title { text-align: center; }
275 .todo { font-family: monospace; color: red; }
276 .done { font-family: monospace; color: green; }
277 .priority { font-family: monospace; color: orange; }
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 "25.1"
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 "25.1"
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-encode-plain-text'.")
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://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" )
1068 (scale "100")
1069 (align "center")
1070 (font "TeX")
1071 (linebreaks "false")
1072 (autonumber "AMS")
1073 (indent "0em")
1074 (multlinewidth "85%")
1075 (tagindent ".8em")
1076 (tagside "right"))
1077 "Options for MathJax setup.
1079 Alist of the following elements. All values are strings.
1081 path The path to MathJax.
1082 scale Scaling with HTML-CSS, MathML and SVG output engines.
1083 align How to align display math: left, center, or right.
1084 font The font to use with HTML-CSS and SVG output. As of MathJax 2.5
1085 the following values are understood: \"TeX\", \"STIX-Web\",
1086 \"Asana-Math\", \"Neo-Euler\", \"Gyre-Pagella\",
1087 \"Gyre-Termes\", and \"Latin-Modern\".
1088 linebreaks Let MathJax perform automatic linebreaks. Valid values
1089 are \"true\" and \"false\".
1090 indent If align is not center, how far from the left/right side?
1091 Valid values are \"left\" and \"right\"
1092 multlinewidth The width of the multline environment.
1093 autonumber How to number equations. Valid values are \"None\",
1094 \"all\" and \"AMS Math\".
1095 tagindent The amount tags are indented.
1096 tagside Which side to show tags/labels on. Valid values are
1097 \"left\" and \"right\"
1099 You can also customize this for each buffer, using something like
1101 #+HTML_MATHJAX: align: left indent: 5em tagside: left font: Neo-Euler
1103 For further information about MathJax options, see the MathJax documentation:
1105 http://docs.mathjax.org/
1107 Please note that by using the default CDN one must agree with
1108 MathJax CDN Terms of Service.
1110 http://www.mathjax.org/mathjax-cdn-terms-of-service.html"
1111 :group 'org-export-html
1112 :type '(list :greedy t
1113 (list :tag "path (the path from where to load MathJax.js)"
1114 (const :format " " path) (string))
1115 (list :tag "scale (scaling for the displayed math)"
1116 (const :format " " scale) (string))
1117 (list :tag "align (alignment of displayed equations)"
1118 (const :format " " align) (string))
1119 (list :tag "font (used to display math)"
1120 (const :format " " font)
1121 (choice (const "TeX")
1122 (const "STIX-Web")
1123 (const "Asana-Math")
1124 (const "Neo-Euler")
1125 (const "Gyre-Pagella")
1126 (const "Gyre-Termes")
1127 (const "Latin-Modern")))
1128 (list :tag "linebreaks (automatic line-breaking)"
1129 (const :format " " linebreaks)
1130 (choice (const "true")
1131 (const "false")))
1132 (list :tag "autonumber (when should equations be numbered)"
1133 (const :format " " autonumber)
1134 (choice (const "AMS")
1135 (const "None")
1136 (const "All")))
1137 (list :tag "indent (indentation with left or right alignment)"
1138 (const :format " " indent) (string))
1139 (list :tag "multlinewidth (width to use for the multline environment)"
1140 (const :format " " multlinewidth) (string))
1141 (list :tag "tagindent (the indentation of tags from left or right)"
1142 (const :format " " tagindent) (string))
1143 (list :tag "tagside (location of tags)"
1144 (const :format " " tagside)
1145 (choice (const "left")
1146 (const "right")))))
1148 (defcustom org-html-mathjax-template
1149 "<script type=\"text/x-mathjax-config\">
1150 MathJax.Hub.Config({
1151 displayAlign: \"%ALIGN\",
1152 displayIndent: \"%INDENT\",
1154 \"HTML-CSS\": { scale: %SCALE,
1155 linebreaks: { automatic: \"%LINEBREAKS\" },
1156 webFont: \"%FONT\"
1158 SVG: {scale: %SCALE,
1159 linebreaks: { automatic: \"%LINEBREAKS\" },
1160 font: \"%FONT\"},
1161 NativeMML: {scale: %SCALE},
1162 TeX: { equationNumbers: {autoNumber: \"%AUTONUMBER\"},
1163 MultLineWidth: \"%MULTLINEWIDTH\",
1164 TagSide: \"%TAGSIDE\",
1165 TagIndent: \"%TAGINDENT\"
1168 </script>
1169 <script type=\"text/javascript\"
1170 src=\"%PATH\"></script>"
1171 "The MathJax template. See also `org-html-mathjax-options'."
1172 :group 'org-export-html
1173 :type 'string)
1175 ;;;; Template :: Postamble
1177 (defcustom org-html-postamble 'auto
1178 "Non-nil means insert a postamble in HTML export.
1180 When set to 'auto, check against the
1181 `org-export-with-author/email/creator/date' variables to set the
1182 content of the postamble. When set to a string, use this string
1183 as the postamble. When t, insert a string as defined by the
1184 formatting string in `org-html-postamble-format'.
1186 When set to a function, apply this function and insert the
1187 returned string. The function takes the property list of export
1188 options as its only argument.
1190 Setting :html-postamble in publishing projects will take
1191 precedence over this variable."
1192 :group 'org-export-html
1193 :type '(choice (const :tag "No postamble" nil)
1194 (const :tag "Auto postamble" auto)
1195 (const :tag "Default formatting string" t)
1196 (string :tag "Custom formatting string")
1197 (function :tag "Function (must return a string)")))
1199 (defcustom org-html-postamble-format
1200 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1201 <p class=\"date\">Date: %d</p>
1202 <p class=\"creator\">%c</p>
1203 <p class=\"validation\">%v</p>"))
1204 "Alist of languages and format strings for the HTML postamble.
1206 The first element of each list is the language code, as used for
1207 the LANGUAGE keyword. See `org-export-default-language'.
1209 The second element of each list is a format string to format the
1210 postamble itself. This format string can contain these elements:
1212 %t stands for the title.
1213 %a stands for the author's name.
1214 %e stands for the author's email.
1215 %d stands for the date.
1216 %c will be replaced by `org-html-creator-string'.
1217 %v will be replaced by `org-html-validation-link'.
1218 %T will be replaced by the export time.
1219 %C will be replaced by the last modification time.
1221 If you need to use a \"%\" character, you need to escape it
1222 like that: \"%%\"."
1223 :group 'org-export-html
1224 :type '(repeat
1225 (list (string :tag "Language")
1226 (string :tag "Format string"))))
1228 (defcustom org-html-validation-link
1229 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1230 "Link to HTML validation service."
1231 :group 'org-export-html
1232 :type 'string)
1234 (defcustom org-html-creator-string
1235 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1236 emacs-version
1237 (if (fboundp 'org-version) (org-version) "unknown version"))
1238 "Information about the creator of the HTML document.
1239 This option can also be set on with the CREATOR keyword."
1240 :group 'org-export-html
1241 :version "24.4"
1242 :package-version '(Org . "8.0")
1243 :type '(string :tag "Creator string"))
1245 ;;;; Template :: Preamble
1247 (defcustom org-html-preamble t
1248 "Non-nil means insert a preamble in HTML export.
1250 When t, insert a string as defined by the formatting string in
1251 `org-html-preamble-format'. When set to a string, use this
1252 formatting string instead (see `org-html-postamble-format' for an
1253 example of such a formatting string).
1255 When set to a function, apply this function and insert the
1256 returned string. The function takes the property list of export
1257 options as its only argument.
1259 Setting :html-preamble in publishing projects will take
1260 precedence over this variable."
1261 :group 'org-export-html
1262 :type '(choice (const :tag "No preamble" nil)
1263 (const :tag "Default preamble" t)
1264 (string :tag "Custom formatting string")
1265 (function :tag "Function (must return a string)")))
1267 (defcustom org-html-preamble-format '(("en" ""))
1268 "Alist of languages and format strings for the HTML preamble.
1270 The first element of each list is the language code, as used for
1271 the LANGUAGE keyword. See `org-export-default-language'.
1273 The second element of each list is a format string to format the
1274 preamble itself. This format string can contain these elements:
1276 %t stands for the title.
1277 %a stands for the author's name.
1278 %e stands for the author's email.
1279 %d stands for the date.
1280 %c will be replaced by `org-html-creator-string'.
1281 %v will be replaced by `org-html-validation-link'.
1282 %T will be replaced by the export time.
1283 %C will be replaced by the last modification time.
1285 If you need to use a \"%\" character, you need to escape it
1286 like that: \"%%\".
1288 See the default value of `org-html-postamble-format' for an
1289 example."
1290 :group 'org-export-html
1291 :type '(repeat
1292 (list (string :tag "Language")
1293 (string :tag "Format string"))))
1295 (defcustom org-html-link-up ""
1296 "Where should the \"UP\" link of exported HTML pages lead?"
1297 :group 'org-export-html
1298 :type '(string :tag "File or URL"))
1300 (defcustom org-html-link-home ""
1301 "Where should the \"HOME\" link of exported HTML pages lead?"
1302 :group 'org-export-html
1303 :type '(string :tag "File or URL"))
1305 (defcustom org-html-link-use-abs-url nil
1306 "Should we prepend relative links with HTML_LINK_HOME?"
1307 :group 'org-export-html
1308 :version "24.4"
1309 :package-version '(Org . "8.1")
1310 :type 'boolean)
1312 (defcustom org-html-home/up-format
1313 "<div id=\"org-div-home-and-up\">
1314 <a accesskey=\"h\" href=\"%s\"> UP </a>
1316 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1317 </div>"
1318 "Snippet used to insert the HOME and UP links.
1319 This is a format string, the first %s will receive the UP link,
1320 the second the HOME link. If both `org-html-link-up' and
1321 `org-html-link-home' are empty, the entire snippet will be
1322 ignored."
1323 :group 'org-export-html
1324 :type 'string)
1326 ;;;; Template :: Scripts
1328 (define-obsolete-variable-alias
1329 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1330 (defcustom org-html-head-include-scripts t
1331 "Non-nil means include the JavaScript snippets in exported HTML files.
1332 The actual script is defined in `org-html-scripts' and should
1333 not be modified."
1334 :group 'org-export-html
1335 :version "24.4"
1336 :package-version '(Org . "8.0")
1337 :type 'boolean)
1339 ;;;; Template :: Styles
1341 (define-obsolete-variable-alias
1342 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1343 (defcustom org-html-head-include-default-style t
1344 "Non-nil means include the default style in exported HTML files.
1345 The actual style is defined in `org-html-style-default' and
1346 should not be modified. Use `org-html-head' to use your own
1347 style information."
1348 :group 'org-export-html
1349 :version "24.4"
1350 :package-version '(Org . "8.0")
1351 :type 'boolean)
1352 ;;;###autoload
1353 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1355 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1356 (defcustom org-html-head ""
1357 "Org-wide head definitions for exported HTML files.
1359 This variable can contain the full HTML structure to provide a
1360 style, including the surrounding HTML tags. You can consider
1361 including definitions for the following classes: title, todo,
1362 done, timestamp, timestamp-kwd, tag, target.
1364 For example, a valid value would be:
1366 <style type=\"text/css\">
1367 <![CDATA[
1368 p { font-weight: normal; color: gray; }
1369 h1 { color: black; }
1370 .title { text-align: center; }
1371 .todo, .timestamp-kwd { color: red; }
1372 .done { color: green; }
1374 </style>
1376 If you want to refer to an external style, use something like
1378 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1380 As the value of this option simply gets inserted into the HTML
1381 <head> header, you can use it to add any arbitrary text to the
1382 header.
1384 You can set this on a per-file basis using #+HTML_HEAD:,
1385 or for publication projects using the :html-head property."
1386 :group 'org-export-html
1387 :version "24.4"
1388 :package-version '(Org . "8.0")
1389 :type 'string)
1390 ;;;###autoload
1391 (put 'org-html-head 'safe-local-variable 'stringp)
1393 (defcustom org-html-head-extra ""
1394 "More head information to add in the HTML output.
1396 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1397 or for publication projects using the :html-head-extra property."
1398 :group 'org-export-html
1399 :version "24.4"
1400 :package-version '(Org . "8.0")
1401 :type 'string)
1402 ;;;###autoload
1403 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1405 ;;;; Todos
1407 (defcustom org-html-todo-kwd-class-prefix ""
1408 "Prefix to class names for TODO keywords.
1409 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1410 The default prefix is empty because it is nice to just use the keyword
1411 as a class name. But if you get into conflicts with other, existing
1412 CSS classes, then this prefix can be very useful."
1413 :group 'org-export-html
1414 :type 'string)
1417 ;;; Internal Functions
1419 (defun org-html-xhtml-p (info)
1420 (let ((dt (downcase (plist-get info :html-doctype))))
1421 (string-match-p "xhtml" dt)))
1423 (defun org-html-html5-p (info)
1424 (let ((dt (downcase (plist-get info :html-doctype))))
1425 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1427 (defun org-html-close-tag (tag attr info)
1428 (concat "<" tag " " attr
1429 (if (org-html-xhtml-p info) " />" ">")))
1431 (defun org-html-doctype (info)
1432 "Return correct html doctype tag from `org-html-doctype-alist',
1433 or the literal value of :html-doctype from INFO if :html-doctype
1434 is not found in the alist.
1435 INFO is a plist used as a communication channel."
1436 (let ((dt (plist-get info :html-doctype)))
1437 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1439 (defun org-html--make-attribute-string (attributes)
1440 "Return a list of attributes, as a string.
1441 ATTRIBUTES is a plist where values are either strings or nil. An
1442 attributes with a nil value will be omitted from the result."
1443 (let (output)
1444 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1445 (cond ((null item) (pop output))
1446 ((symbolp item) (push (substring (symbol-name item) 1) output))
1447 (t (let ((key (car output))
1448 (value (replace-regexp-in-string
1449 "\"" "&quot;" (org-html-encode-plain-text item))))
1450 (setcar output (format "%s=\"%s\"" key value))))))))
1452 (defun org-html--wrap-image (contents info &optional caption label)
1453 "Wrap CONTENTS string within an appropriate environment for images.
1454 INFO is a plist used as a communication channel. When optional
1455 arguments CAPTION and LABEL are given, use them for caption and
1456 \"id\" attribute."
1457 (let ((html5-fancy (and (org-html-html5-p info)
1458 (plist-get info :html-html5-fancy))))
1459 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1460 "\n<div%s class=\"figure\">%s%s\n</div>")
1461 ;; ID.
1462 (if (not (org-string-nw-p label)) ""
1463 (format " id=\"%s\"" (org-export-solidify-link-text label)))
1464 ;; Contents.
1465 (format "\n<p>%s</p>" contents)
1466 ;; Caption.
1467 (if (not (org-string-nw-p caption)) ""
1468 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1469 "\n<p>%s</p>")
1470 caption)))))
1472 (defun org-html--format-image (source attributes info)
1473 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1474 SOURCE is a string specifying the location of the image.
1475 ATTRIBUTES is a plist, as returned by
1476 `org-export-read-attribute'. INFO is a plist used as
1477 a communication channel."
1478 (if (string= "svg" (file-name-extension source))
1479 (org-html--svg-image source attributes info)
1480 (org-html-close-tag
1481 "img"
1482 (org-html--make-attribute-string
1483 (org-combine-plists
1484 (list :src source
1485 :alt (if (string-match-p "^ltxpng/" source)
1486 (org-html-encode-plain-text
1487 (org-find-text-property-in-string 'org-latex-src source))
1488 (file-name-nondirectory source)))
1489 attributes))
1490 info)))
1492 (defun org-html--svg-image (source attributes info)
1493 "Return \"object\" appropriate for embedding svg file SOURCE
1494 with assoicated ATTRIBUTES. INFO is a plist used as a
1495 communication channel.
1497 The special attribute \"fallback\" can be used to specify a fallback
1498 image file to use if the object embedding is not supported."
1499 (let ((fallback (plist-get attributes :fallback))
1500 (attrs (org-html--make-attribute-string
1501 (plist-put attributes :fallback nil))))
1502 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1503 source attrs
1504 (if fallback
1505 (org-html-close-tag
1506 "img" (format "src=\"%s\" %s" fallback attrs) info)
1507 "Sorry, your browser does not support SVG."))))
1509 (defun org-html--textarea-block (element)
1510 "Transcode ELEMENT into a textarea block.
1511 ELEMENT is either a src block or an example block."
1512 (let* ((code (car (org-export-unravel-code element)))
1513 (attr (org-export-read-attribute :attr_html element)))
1514 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1515 (or (plist-get attr :width) 80)
1516 (or (plist-get attr :height) (org-count-lines code))
1517 code)))
1519 (defun org-html--has-caption-p (element &optional info)
1520 "Non-nil when ELEMENT has a caption affiliated keyword.
1521 INFO is a plist used as a communication channel. This function
1522 is meant to be used as a predicate for `org-export-get-ordinal' or
1523 a value to `org-html-standalone-image-predicate'."
1524 (org-element-property :caption element))
1526 ;;;; Table
1528 (defun org-html-htmlize-region-for-paste (beg end)
1529 "Convert the region between BEG and END to HTML, using htmlize.el.
1530 This is much like `htmlize-region-for-paste', only that it uses
1531 the settings define in the org-... variables."
1532 (let* ((htmlize-output-type org-html-htmlize-output-type)
1533 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1534 (htmlbuf (htmlize-region beg end)))
1535 (unwind-protect
1536 (with-current-buffer htmlbuf
1537 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1538 (plist-get htmlize-buffer-places 'content-end)))
1539 (kill-buffer htmlbuf))))
1541 ;;;###autoload
1542 (defun org-html-htmlize-generate-css ()
1543 "Create the CSS for all font definitions in the current Emacs session.
1544 Use this to create face definitions in your CSS style file that can then
1545 be used by code snippets transformed by htmlize.
1546 This command just produces a buffer that contains class definitions for all
1547 faces used in the current Emacs session. You can copy and paste the ones you
1548 need into your CSS file.
1550 If you then set `org-html-htmlize-output-type' to `css', calls
1551 to the function `org-html-htmlize-region-for-paste' will
1552 produce code that uses these same face definitions."
1553 (interactive)
1554 (require 'htmlize)
1555 (and (get-buffer "*html*") (kill-buffer "*html*"))
1556 (with-temp-buffer
1557 (let ((fl (face-list))
1558 (htmlize-css-name-prefix "org-")
1559 (htmlize-output-type 'css)
1560 f i)
1561 (while (setq f (pop fl)
1562 i (and f (face-attribute f :inherit)))
1563 (when (and (symbolp f) (or (not i) (not (listp i))))
1564 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1565 (htmlize-region (point-min) (point-max))))
1566 (org-pop-to-buffer-same-window "*html*")
1567 (goto-char (point-min))
1568 (if (re-search-forward "<style" nil t)
1569 (delete-region (point-min) (match-beginning 0)))
1570 (if (re-search-forward "</style>" nil t)
1571 (delete-region (1+ (match-end 0)) (point-max)))
1572 (beginning-of-line 1)
1573 (if (looking-at " +") (replace-match ""))
1574 (goto-char (point-min)))
1576 (defun org-html--make-string (n string)
1577 "Build a string by concatenating N times STRING."
1578 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1580 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1581 "Turn todo keyword KWD into a valid class name.
1582 Replaces invalid characters with \"_\"."
1583 (save-match-data
1584 (while (string-match "[^a-zA-Z0-9_]" kwd)
1585 (setq kwd (replace-match "_" t t kwd))))
1586 kwd)
1588 (defun org-html-footnote-section (info)
1589 "Format the footnote section.
1590 INFO is a plist used as a communication channel."
1591 (let* ((fn-alist (org-export-collect-footnote-definitions info))
1592 (fn-alist
1593 (loop for (n type raw) in fn-alist collect
1594 (cons n (if (eq (org-element-type raw) 'org-data)
1595 (org-trim (org-export-data raw info))
1596 (format "<p>%s</p>"
1597 (org-trim (org-export-data raw info))))))))
1598 (when fn-alist
1599 (format
1600 (plist-get info :html-footnotes-section)
1601 (org-html--translate "Footnotes" info)
1602 (format
1603 "\n%s\n"
1604 (mapconcat
1605 (lambda (fn)
1606 (let ((n (car fn)) (def (cdr fn)))
1607 (format
1608 "<div class=\"footdef\">%s %s</div>\n"
1609 (format
1610 (plist-get info :html-footnote-format)
1611 (org-html--anchor
1612 (format "fn.%d" n)
1614 (format " class=\"footnum\" href=\"#fnr.%d\"" n)
1615 info))
1616 def)))
1617 fn-alist
1618 "\n"))))))
1621 ;;; Template
1623 (defun org-html--build-meta-info (info)
1624 "Return meta tags for exported document.
1625 INFO is a plist used as a communication channel."
1626 (let ((protect-string
1627 (lambda (str)
1628 (replace-regexp-in-string
1629 "\"" "&quot;" (org-html-encode-plain-text str))))
1630 (title (org-export-data (plist-get info :title) info))
1631 (author (and (plist-get info :with-author)
1632 (let ((auth (plist-get info :author)))
1633 (and auth
1634 ;; Return raw Org syntax, skipping non
1635 ;; exportable objects.
1636 (org-element-interpret-data
1637 (org-element-map auth
1638 (cons 'plain-text org-element-all-objects)
1639 'identity info))))))
1640 (description (plist-get info :description))
1641 (keywords (plist-get info :keywords))
1642 (charset (or (and org-html-coding-system
1643 (fboundp 'coding-system-get)
1644 (coding-system-get org-html-coding-system
1645 'mime-charset))
1646 "iso-8859-1")))
1647 (concat
1648 (format "<title>%s</title>\n" title)
1649 (when (plist-get info :time-stamp-file)
1650 (format-time-string
1651 (concat "<!-- "
1652 (plist-get info :html-metadata-timestamp-format)
1653 " -->\n")))
1654 (format
1655 (if (org-html-html5-p info)
1656 (org-html-close-tag "meta" " charset=\"%s\"" info)
1657 (org-html-close-tag
1658 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1659 info))
1660 charset) "\n"
1661 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1662 "\n"
1663 (and (org-string-nw-p author)
1664 (concat
1665 (org-html-close-tag "meta"
1666 (format " name=\"author\" content=\"%s\""
1667 (funcall protect-string author))
1668 info)
1669 "\n"))
1670 (and (org-string-nw-p description)
1671 (concat
1672 (org-html-close-tag "meta"
1673 (format " name=\"description\" content=\"%s\"\n"
1674 (funcall protect-string description))
1675 info)
1676 "\n"))
1677 (and (org-string-nw-p keywords)
1678 (concat
1679 (org-html-close-tag "meta"
1680 (format " name=\"keywords\" content=\"%s\""
1681 (funcall protect-string keywords))
1682 info)
1683 "\n")))))
1685 (defun org-html--build-head (info)
1686 "Return information for the <head>..</head> of the HTML output.
1687 INFO is a plist used as a communication channel."
1688 (org-element-normalize-string
1689 (concat
1690 (when (plist-get info :html-head-include-default-style)
1691 (org-element-normalize-string org-html-style-default))
1692 (org-element-normalize-string (plist-get info :html-head))
1693 (org-element-normalize-string (plist-get info :html-head-extra))
1694 (when (and (plist-get info :html-htmlized-css-url)
1695 (eq org-html-htmlize-output-type 'css))
1696 (org-html-close-tag "link"
1697 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1698 (plist-get info :html-htmlized-css-url))
1699 info))
1700 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1702 (defun org-html--build-mathjax-config (info)
1703 "Insert the user setup into the mathjax template.
1704 INFO is a plist used as a communication channel."
1705 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1706 (org-element-map (plist-get info :parse-tree)
1707 '(latex-fragment latex-environment) 'identity info t))
1708 (let ((template (plist-get info :html-mathjax-template))
1709 (options (plist-get info :html-mathjax-options))
1710 (in-buffer (or (plist-get info :html-mathjax) ""))
1711 name val x)
1712 (mapc
1713 (lambda (e)
1714 (setq name (car e) val (nth 1 e))
1715 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1716 (setq val (car (read-from-string
1717 (substring in-buffer (match-end 0))))))
1718 (if (not (stringp val)) (setq val (format "%s" val)))
1719 (while (string-match (concat "%" (upcase (symbol-name name))) template)
1720 (setq template (replace-match val t t template))))
1721 options)
1722 ;; Return the modified template.
1723 (org-element-normalize-string template))))
1725 (defun org-html-format-spec (info)
1726 "Return format specification for elements that can be
1727 used in the preamble or postamble."
1728 `((?t . ,(org-export-data (plist-get info :title) info))
1729 (?d . ,(org-export-data (org-export-get-date info) info))
1730 (?T . ,(format-time-string
1731 (plist-get info :html-metadata-timestamp-format)))
1732 (?a . ,(org-export-data (plist-get info :author) info))
1733 (?e . ,(mapconcat
1734 (lambda (e)
1735 (format "<a href=\"mailto:%s\">%s</a>" e e))
1736 (split-string (plist-get info :email) ",+ *")
1737 ", "))
1738 (?c . ,(plist-get info :creator))
1739 (?C . ,(let ((file (plist-get info :input-file)))
1740 (format-time-string
1741 (plist-get info :html-metadata-timestamp-format)
1742 (if file (nth 5 (file-attributes file)) (current-time)))))
1743 (?v . ,(or (plist-get info :html-validation-link) ""))))
1745 (defun org-html--build-pre/postamble (type info)
1746 "Return document preamble or postamble as a string, or nil.
1747 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1748 communication channel."
1749 (let ((section (plist-get info (intern (format ":html-%s" type))))
1750 (spec (org-html-format-spec info)))
1751 (when section
1752 (let ((section-contents
1753 (if (functionp section) (funcall section info)
1754 (cond
1755 ((stringp section) (format-spec section spec))
1756 ((eq section 'auto)
1757 (let ((date (cdr (assq ?d spec)))
1758 (author (cdr (assq ?a spec)))
1759 (email (cdr (assq ?e spec)))
1760 (creator (cdr (assq ?c spec)))
1761 (timestamp (cdr (assq ?T spec)))
1762 (validation-link (cdr (assq ?v spec))))
1763 (concat
1764 (when (and (plist-get info :with-date)
1765 (org-string-nw-p date))
1766 (format "<p class=\"date\">%s: %s</p>\n"
1767 (org-html--translate "Date" info)
1768 date))
1769 (when (and (plist-get info :with-author)
1770 (org-string-nw-p author))
1771 (format "<p class=\"author\">%s: %s</p>\n"
1772 (org-html--translate "Author" info)
1773 author))
1774 (when (and (plist-get info :with-email)
1775 (org-string-nw-p email))
1776 (format "<p class=\"email\">%s: %s</p>\n"
1777 (org-html--translate "Email" info)
1778 email))
1779 (when (plist-get info :time-stamp-file)
1780 (format
1781 "<p class=\"date\">%s: %s</p>\n"
1782 (org-html--translate "Created" info)
1783 (format-time-string
1784 (plist-get info :html-metadata-timestamp-format))))
1785 (when (plist-get info :with-creator)
1786 (format "<p class=\"creator\">%s</p>\n" creator))
1787 (format "<p class=\"validation\">%s</p>\n"
1788 validation-link))))
1789 (t (format-spec
1790 (or (cadr (assoc
1791 (plist-get info :language)
1792 (eval (intern
1793 (format "org-html-%s-format" type)))))
1794 (cadr
1795 (assoc
1796 "en"
1797 (eval
1798 (intern (format "org-html-%s-format" type))))))
1799 spec))))))
1800 (let ((div (assq type (plist-get info :html-divs))))
1801 (when (org-string-nw-p section-contents)
1802 (concat
1803 (format "<%s id=\"%s\" class=\"%s\">\n"
1804 (nth 1 div)
1805 (nth 2 div)
1806 org-html--pre/postamble-class)
1807 (org-element-normalize-string section-contents)
1808 (format "</%s>\n" (nth 1 div)))))))))
1810 (defun org-html-inner-template (contents info)
1811 "Return body of document string after HTML conversion.
1812 CONTENTS is the transcoded contents string. INFO is a plist
1813 holding export options."
1814 (concat
1815 ;; Table of contents.
1816 (let ((depth (plist-get info :with-toc)))
1817 (when depth (org-html-toc depth info)))
1818 ;; Document contents.
1819 contents
1820 ;; Footnotes section.
1821 (org-html-footnote-section info)))
1823 (defun org-html-template (contents info)
1824 "Return complete document string after HTML conversion.
1825 CONTENTS is the transcoded contents string. INFO is a plist
1826 holding export options."
1827 (concat
1828 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1829 (let* ((xml-declaration (plist-get info :html-xml-declaration))
1830 (decl (or (and (stringp xml-declaration) xml-declaration)
1831 (cdr (assoc (plist-get info :html-extension)
1832 xml-declaration))
1833 (cdr (assoc "html" xml-declaration))
1834 "")))
1835 (when (not (or (not decl) (string= "" decl)))
1836 (format "%s\n"
1837 (format decl
1838 (or (and org-html-coding-system
1839 (fboundp 'coding-system-get)
1840 (coding-system-get org-html-coding-system 'mime-charset))
1841 "iso-8859-1"))))))
1842 (org-html-doctype info)
1843 "\n"
1844 (concat "<html"
1845 (when (org-html-xhtml-p info)
1846 (format
1847 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1848 (plist-get info :language) (plist-get info :language)))
1849 ">\n")
1850 "<head>\n"
1851 (org-html--build-meta-info info)
1852 (org-html--build-head info)
1853 (org-html--build-mathjax-config info)
1854 "</head>\n"
1855 "<body>\n"
1856 (let ((link-up (org-trim (plist-get info :html-link-up)))
1857 (link-home (org-trim (plist-get info :html-link-home))))
1858 (unless (and (string= link-up "") (string= link-home ""))
1859 (format (plist-get info :html-home/up-format)
1860 (or link-up link-home)
1861 (or link-home link-up))))
1862 ;; Preamble.
1863 (org-html--build-pre/postamble 'preamble info)
1864 ;; Document contents.
1865 (let ((div (assq 'content (plist-get info :html-divs))))
1866 (format "<%s id=\"%s\">\n" (nth 1 div) (nth 2 div)))
1867 ;; Document title.
1868 (when (plist-get info :with-title)
1869 (let ((title (plist-get info :title)))
1870 (format "<h1 class=\"title\">%s</h1>\n"
1871 (org-export-data (or title "") info))))
1872 contents
1873 (format "</%s>\n" (nth 1 (assq 'content (plist-get info :html-divs))))
1874 ;; Postamble.
1875 (org-html--build-pre/postamble 'postamble info)
1876 ;; Closing document.
1877 "</body>\n</html>"))
1879 (defun org-html--translate (s info)
1880 "Translate string S according to specified language.
1881 INFO is a plist used as a communication channel."
1882 (org-export-translate s :html info))
1884 ;;;; Anchor
1886 (defun org-html--anchor (id desc attributes info)
1887 "Format a HTML anchor."
1888 (let* ((name (and (plist-get info :html-allow-name-attribute-in-anchors) id))
1889 (attributes (concat (and id (format " id=\"%s\"" id))
1890 (and name (format " name=\"%s\"" name))
1891 attributes)))
1892 (format "<a%s>%s</a>" attributes (or desc ""))))
1894 ;;;; Todo
1896 (defun org-html--todo (todo info)
1897 "Format TODO keywords into HTML."
1898 (when todo
1899 (format "<span class=\"%s %s%s\">%s</span>"
1900 (if (member todo org-done-keywords) "done" "todo")
1901 (plist-get info :html-todo-kwd-class-prefix)
1902 (org-html-fix-class-name todo)
1903 todo)))
1905 ;;;; Priority
1907 (defun org-html--priority (priority info)
1908 "Format a priority into HTML.
1909 PRIORITY is the character code of the priority or nil. INFO is
1910 a plist containing export options."
1911 (and priority (format "<span class=\"priority\">[%c]</span>" priority)))
1913 ;;;; Tags
1915 (defun org-html--tags (tags info)
1916 "Format TAGS into HTML.
1917 INFO is a plist containing export options."
1918 (when tags
1919 (format "<span class=\"tag\">%s</span>"
1920 (mapconcat
1921 (lambda (tag)
1922 (format "<span class=\"%s\">%s</span>"
1923 (concat (plist-get info :html-tag-class-prefix)
1924 (org-html-fix-class-name tag))
1925 tag))
1926 tags "&#xa0;"))))
1928 ;;;; Src Code
1930 (defun org-html-fontify-code (code lang)
1931 "Color CODE with htmlize library.
1932 CODE is a string representing the source code to colorize. LANG
1933 is the language used for CODE, as a string, or nil."
1934 (when code
1935 (cond
1936 ;; Case 1: No lang. Possibly an example block.
1937 ((not lang)
1938 ;; Simple transcoding.
1939 (org-html-encode-plain-text code))
1940 ;; Case 2: No htmlize or an inferior version of htmlize
1941 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1942 ;; Emit a warning.
1943 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1944 ;; Simple transcoding.
1945 (org-html-encode-plain-text code))
1946 ;; Case 3: plain text explicitly set
1947 ((not org-html-htmlize-output-type)
1948 ;; Simple transcoding.
1949 (org-html-encode-plain-text code))
1951 ;; Map language
1952 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1953 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1954 (cond
1955 ;; Case 1: Language is not associated with any Emacs mode
1956 ((not (functionp lang-mode))
1957 ;; Simple transcoding.
1958 (org-html-encode-plain-text code))
1959 ;; Case 2: Default. Fontify code.
1961 ;; htmlize
1962 (setq code (with-temp-buffer
1963 ;; Switch to language-specific mode.
1964 (funcall lang-mode)
1965 ;; Disable fci-mode if present
1966 (when (and (fboundp 'fci-mode)
1967 (require 'fill-column-indicator nil 'noerror))
1968 (fci-mode -1))
1969 (insert code)
1970 ;; Fontify buffer.
1971 (font-lock-ensure)
1972 ;; Remove formatting on newline characters.
1973 (save-excursion
1974 (let ((beg (point-min))
1975 (end (point-max)))
1976 (goto-char beg)
1977 (while (progn (end-of-line) (< (point) end))
1978 (put-text-property (point) (1+ (point)) 'face nil)
1979 (forward-char 1))))
1980 (org-src-mode)
1981 (set-buffer-modified-p nil)
1982 ;; Htmlize region.
1983 (org-html-htmlize-region-for-paste
1984 (point-min) (point-max))))
1985 ;; Strip any enclosing <pre></pre> tags.
1986 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1987 (end (and beg (string-match "</pre>\\'" code))))
1988 (if (and beg end) (substring code beg end) code)))))))))
1990 (defun org-html-do-format-code
1991 (code &optional lang refs retain-labels num-start)
1992 "Format CODE string as source code.
1993 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1994 respectively, the language of the source code, as a string, an
1995 alist between line numbers and references (as returned by
1996 `org-export-unravel-code'), a boolean specifying if labels should
1997 appear in the source code, and the number associated to the first
1998 line of code."
1999 (let* ((code-lines (org-split-string code "\n"))
2000 (code-length (length code-lines))
2001 (num-fmt
2002 (and num-start
2003 (format "%%%ds: "
2004 (length (number-to-string (+ code-length num-start))))))
2005 (code (org-html-fontify-code code lang)))
2006 (org-export-format-code
2007 code
2008 (lambda (loc line-num ref)
2009 (setq loc
2010 (concat
2011 ;; Add line number, if needed.
2012 (when num-start
2013 (format "<span class=\"linenr\">%s</span>"
2014 (format num-fmt line-num)))
2015 ;; Transcoded src line.
2017 ;; Add label, if needed.
2018 (when (and ref retain-labels) (format " (%s)" ref))))
2019 ;; Mark transcoded line as an anchor, if needed.
2020 (if (not ref) loc
2021 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2022 ref loc)))
2023 num-start refs)))
2025 (defun org-html-format-code (element info)
2026 "Format contents of ELEMENT as source code.
2027 ELEMENT is either an example block or a src block. INFO is
2028 a plist used as a communication channel."
2029 (let* ((lang (org-element-property :language element))
2030 ;; Extract code and references.
2031 (code-info (org-export-unravel-code element))
2032 (code (car code-info))
2033 (refs (cdr code-info))
2034 ;; Does the src block contain labels?
2035 (retain-labels (org-element-property :retain-labels element))
2036 ;; Does it have line numbers?
2037 (num-start (case (org-element-property :number-lines element)
2038 (continued (org-export-get-loc element info))
2039 (new 0))))
2040 (org-html-do-format-code code lang refs retain-labels num-start)))
2043 ;;; Tables of Contents
2045 (defun org-html-toc (depth info &optional scope)
2046 "Build a table of contents.
2047 DEPTH is an integer specifying the depth of the table. INFO is
2048 a plist used as a communication channel. Optional argument SCOPE
2049 is an element defining the scope of the table. Return the table
2050 of contents as a string, or nil if it is empty."
2051 (let ((toc-entries
2052 (mapcar (lambda (headline)
2053 (cons (org-html--format-toc-headline headline info)
2054 (org-export-get-relative-level headline info)))
2055 (org-export-collect-headlines info depth scope))))
2056 (when toc-entries
2057 (let ((toc (concat "<div id=\"text-table-of-contents\">"
2058 (org-html--toc-text toc-entries)
2059 "</div>\n")))
2060 (if scope toc
2061 (let ((outer-tag (if (and (org-html-html5-p info)
2062 (plist-get info :html-html5-fancy))
2063 "nav"
2064 "div")))
2065 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
2066 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2067 (format "<h%d>%s</h%d>\n"
2068 top-level
2069 (org-html--translate "Table of Contents" info)
2070 top-level))
2072 (format "</%s>\n" outer-tag))))))))
2074 (defun org-html--toc-text (toc-entries)
2075 "Return innards of a table of contents, as a string.
2076 TOC-ENTRIES is an alist where key is an entry title, as a string,
2077 and value is its relative level, as an integer."
2078 (let* ((prev-level (1- (cdar toc-entries)))
2079 (start-level prev-level))
2080 (concat
2081 (mapconcat
2082 (lambda (entry)
2083 (let ((headline (car entry))
2084 (level (cdr entry)))
2085 (concat
2086 (let* ((cnt (- level prev-level))
2087 (times (if (> cnt 0) (1- cnt) (- cnt)))
2088 rtn)
2089 (setq prev-level level)
2090 (concat
2091 (org-html--make-string
2092 times (cond ((> cnt 0) "\n<ul>\n<li>")
2093 ((< cnt 0) "</li>\n</ul>\n")))
2094 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
2095 headline)))
2096 toc-entries "")
2097 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
2099 (defun org-html--format-toc-headline (headline info)
2100 "Return an appropriate table of contents entry for HEADLINE.
2101 INFO is a plist used as a communication channel."
2102 (let* ((headline-number (org-export-get-headline-number headline info))
2103 (todo (and (plist-get info :with-todo-keywords)
2104 (let ((todo (org-element-property :todo-keyword headline)))
2105 (and todo (org-export-data todo info)))))
2106 (todo-type (and todo (org-element-property :todo-type headline)))
2107 (priority (and (plist-get info :with-priority)
2108 (org-element-property :priority headline)))
2109 (text (org-export-data-with-backend
2110 (org-export-get-alt-title headline info)
2111 ;; Create an anonymous back-end that will ignore any
2112 ;; footnote-reference, link, radio-target and target
2113 ;; in table of contents.
2114 (org-export-create-backend
2115 :parent 'html
2116 :transcoders '((footnote-reference . ignore)
2117 (link . (lambda (object c i) c))
2118 (radio-target . (lambda (object c i) c))
2119 (target . ignore)))
2120 info))
2121 (tags (and (eq (plist-get info :with-tags) t)
2122 (org-export-get-tags headline info))))
2123 (format "<a href=\"#%s\">%s</a>"
2124 ;; Label.
2125 (org-export-solidify-link-text
2126 (or (org-element-property :CUSTOM_ID headline)
2127 (org-export-get-headline-id headline info)))
2128 ;; Body.
2129 (concat
2130 (and (not (org-export-low-level-p headline info))
2131 (org-export-numbered-headline-p headline info)
2132 (concat (mapconcat #'number-to-string headline-number ".")
2133 ". "))
2134 (apply (plist-get info :html-format-headline-function)
2135 todo todo-type priority text tags :section-number nil)))))
2137 (defun org-html-list-of-listings (info)
2138 "Build a list of listings.
2139 INFO is a plist used as a communication channel. Return the list
2140 of listings as a string, or nil if it is empty."
2141 (let ((lol-entries (org-export-collect-listings info)))
2142 (when lol-entries
2143 (concat "<div id=\"list-of-listings\">\n"
2144 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2145 (format "<h%d>%s</h%d>\n"
2146 top-level
2147 (org-html--translate "List of Listings" info)
2148 top-level))
2149 "<div id=\"text-list-of-listings\">\n<ul>\n"
2150 (let ((count 0)
2151 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2152 (org-html--translate "Listing %d:" info))))
2153 (mapconcat
2154 (lambda (entry)
2155 (let ((label (org-element-property :name entry))
2156 (title (org-trim
2157 (org-export-data
2158 (or (org-export-get-caption entry t)
2159 (org-export-get-caption entry))
2160 info))))
2161 (concat
2162 "<li>"
2163 (if (not label)
2164 (concat (format initial-fmt (incf count)) " " title)
2165 (format "<a href=\"#%s\">%s %s</a>"
2166 (org-export-solidify-link-text label)
2167 (format initial-fmt (incf count))
2168 title))
2169 "</li>")))
2170 lol-entries "\n"))
2171 "\n</ul>\n</div>\n</div>"))))
2173 (defun org-html-list-of-tables (info)
2174 "Build a list of tables.
2175 INFO is a plist used as a communication channel. Return the list
2176 of tables as a string, or nil if it is empty."
2177 (let ((lol-entries (org-export-collect-tables info)))
2178 (when lol-entries
2179 (concat "<div id=\"list-of-tables\">\n"
2180 (let ((top-level (plist-get info :html-toplevel-hlevel)))
2181 (format "<h%d>%s</h%d>\n"
2182 top-level
2183 (org-html--translate "List of Tables" info)
2184 top-level))
2185 "<div id=\"text-list-of-tables\">\n<ul>\n"
2186 (let ((count 0)
2187 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2188 (org-html--translate "Table %d:" info))))
2189 (mapconcat
2190 (lambda (entry)
2191 (let ((label (org-element-property :name entry))
2192 (title (org-trim
2193 (org-export-data
2194 (or (org-export-get-caption entry t)
2195 (org-export-get-caption entry))
2196 info))))
2197 (concat
2198 "<li>"
2199 (if (not label)
2200 (concat (format initial-fmt (incf count)) " " title)
2201 (format "<a href=\"#%s\">%s %s</a>"
2202 (org-export-solidify-link-text label)
2203 (format initial-fmt (incf count))
2204 title))
2205 "</li>")))
2206 lol-entries "\n"))
2207 "\n</ul>\n</div>\n</div>"))))
2210 ;;; Transcode Functions
2212 ;;;; Bold
2214 (defun org-html-bold (bold contents info)
2215 "Transcode BOLD from Org to HTML.
2216 CONTENTS is the text with bold markup. INFO is a plist holding
2217 contextual information."
2218 (format (or (cdr (assq 'bold (plist-get info :html-text-markup-alist))) "%s")
2219 contents))
2221 ;;;; Center Block
2223 (defun org-html-center-block (center-block contents info)
2224 "Transcode a CENTER-BLOCK element from Org to HTML.
2225 CONTENTS holds the contents of the block. INFO is a plist
2226 holding contextual information."
2227 (format "<div class=\"center\">\n%s</div>" contents))
2229 ;;;; Clock
2231 (defun org-html-clock (clock contents info)
2232 "Transcode a CLOCK element from Org to HTML.
2233 CONTENTS is nil. INFO is a plist used as a communication
2234 channel."
2235 (format "<p>
2236 <span class=\"timestamp-wrapper\">
2237 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2238 </span>
2239 </p>"
2240 org-clock-string
2241 (org-timestamp-translate (org-element-property :value clock))
2242 (let ((time (org-element-property :duration clock)))
2243 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2245 ;;;; Code
2247 (defun org-html-code (code contents info)
2248 "Transcode CODE from Org to HTML.
2249 CONTENTS is nil. INFO is a plist holding contextual
2250 information."
2251 (format (or (cdr (assq 'code (plist-get info :html-text-markup-alist))) "%s")
2252 (org-html-encode-plain-text (org-element-property :value code))))
2254 ;;;; Drawer
2256 (defun org-html-drawer (drawer contents info)
2257 "Transcode a DRAWER element from Org to HTML.
2258 CONTENTS holds the contents of the block. INFO is a plist
2259 holding contextual information."
2260 (funcall (plist-get info :html-format-drawer-function)
2261 (org-element-property :drawer-name drawer)
2262 contents))
2264 ;;;; Dynamic Block
2266 (defun org-html-dynamic-block (dynamic-block contents info)
2267 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2268 CONTENTS holds the contents of the block. INFO is a plist
2269 holding contextual information. See `org-export-data'."
2270 contents)
2272 ;;;; Entity
2274 (defun org-html-entity (entity contents info)
2275 "Transcode an ENTITY object from Org to HTML.
2276 CONTENTS are the definition itself. INFO is a plist holding
2277 contextual information."
2278 (org-element-property :html entity))
2280 ;;;; Example Block
2282 (defun org-html-example-block (example-block contents info)
2283 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2284 CONTENTS is nil. INFO is a plist holding contextual
2285 information."
2286 (if (org-export-read-attribute :attr_html example-block :textarea)
2287 (org-html--textarea-block example-block)
2288 (format "<pre class=\"example\">\n%s</pre>"
2289 (org-html-format-code example-block info))))
2291 ;;;; Export Snippet
2293 (defun org-html-export-snippet (export-snippet contents info)
2294 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2295 CONTENTS is nil. INFO is a plist holding contextual
2296 information."
2297 (when (eq (org-export-snippet-backend export-snippet) 'html)
2298 (org-element-property :value export-snippet)))
2300 ;;;; Export Block
2302 (defun org-html-export-block (export-block contents info)
2303 "Transcode a EXPORT-BLOCK element from Org to HTML.
2304 CONTENTS is nil. INFO is a plist holding contextual information."
2305 (when (string= (org-element-property :type export-block) "HTML")
2306 (org-remove-indentation (org-element-property :value export-block))))
2308 ;;;; Fixed Width
2310 (defun org-html-fixed-width (fixed-width contents info)
2311 "Transcode a FIXED-WIDTH element from Org to HTML.
2312 CONTENTS is nil. INFO is a plist holding contextual information."
2313 (format "<pre class=\"example\">\n%s</pre>"
2314 (org-html-do-format-code
2315 (org-remove-indentation
2316 (org-element-property :value fixed-width)))))
2318 ;;;; Footnote Reference
2320 (defun org-html-footnote-reference (footnote-reference contents info)
2321 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2322 CONTENTS is nil. INFO is a plist holding contextual information."
2323 (concat
2324 ;; Insert separator between two footnotes in a row.
2325 (let ((prev (org-export-get-previous-element footnote-reference info)))
2326 (when (eq (org-element-type prev) 'footnote-reference)
2327 (plist-get info :html-footnote-separator)))
2328 (let* ((n (org-export-get-footnote-number footnote-reference info))
2329 (id (format "fnr.%d%s"
2331 (if (org-export-footnote-first-reference-p
2332 footnote-reference info)
2334 ".100"))))
2335 (format
2336 (plist-get info :html-footnote-format)
2337 (org-html--anchor
2338 id n (format " class=\"footref\" href=\"#fn.%d\"" n) info)))))
2340 ;;;; Headline
2342 (defun org-html-headline (headline contents info)
2343 "Transcode a HEADLINE element from Org to HTML.
2344 CONTENTS holds the contents of the headline. INFO is a plist
2345 holding contextual information."
2346 (unless (org-element-property :footnote-section-p headline)
2347 (let* ((numberedp (org-export-numbered-headline-p headline info))
2348 (numbers (org-export-get-headline-number headline info))
2349 (section-number (and numbers
2350 (mapconcat #'number-to-string numbers "-")))
2351 (level (+ (org-export-get-relative-level headline info)
2352 (1- (plist-get info :html-toplevel-hlevel))))
2353 (todo (and (plist-get info :with-todo-keywords)
2354 (let ((todo (org-element-property :todo-keyword headline)))
2355 (and todo (org-export-data todo info)))))
2356 (todo-type (and todo (org-element-property :todo-type headline)))
2357 (priority (and (plist-get info :with-priority)
2358 (org-element-property :priority headline)))
2359 (text (org-export-data (org-element-property :title headline) info))
2360 (tags (and (plist-get info :with-tags)
2361 (org-export-get-tags headline info)))
2362 (full-text (funcall (plist-get info :html-format-headline-function)
2363 todo todo-type priority text tags info))
2364 (contents (or contents ""))
2365 (ids (delq nil
2366 (list (org-element-property :CUSTOM_ID headline)
2367 (org-export-get-headline-id headline info)
2368 (org-element-property :ID headline))))
2369 (preferred-id (car ids))
2370 (extra-ids (mapconcat
2371 (lambda (id)
2372 (org-html--anchor
2373 (org-export-solidify-link-text
2374 (if (org-uuidgen-p id) (concat "ID-" id) id))
2375 nil nil info))
2376 (cdr ids) "")))
2377 (if (org-export-low-level-p headline info)
2378 ;; This is a deep sub-tree: export it as a list item.
2379 (let* ((type (if numberedp 'ordered 'unordered))
2380 (itemized-body
2381 (org-html-format-list-item
2382 contents type nil info nil
2383 (concat (org-html--anchor preferred-id nil nil info)
2384 extra-ids
2385 full-text))))
2386 (concat (and (org-export-first-sibling-p headline info)
2387 (org-html-begin-plain-list type))
2388 itemized-body
2389 (and (org-export-last-sibling-p headline info)
2390 (org-html-end-plain-list type))))
2391 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2392 (first-content (car (org-element-contents headline))))
2393 ;; Standard headline. Export it as a section.
2394 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2395 (org-html--container headline info)
2396 (format "outline-container-%s"
2397 (or (org-element-property :CUSTOM_ID headline)
2398 (org-export-get-headline-id headline info)))
2399 (concat (format "outline-%d" level)
2400 (and extra-class " ")
2401 extra-class)
2402 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2403 level
2404 preferred-id
2405 extra-ids
2406 (concat
2407 (and numberedp
2408 (format
2409 "<span class=\"section-number-%d\">%s</span> "
2410 level
2411 (mapconcat #'number-to-string numbers ".")))
2412 full-text)
2413 level)
2414 ;; When there is no section, pretend there is an
2415 ;; empty one to get the correct <div
2416 ;; class="outline-...> which is needed by
2417 ;; `org-info.js'.
2418 (if (eq (org-element-type first-content) 'section) contents
2419 (concat (org-html-section first-content "" info) contents))
2420 (org-html--container headline info)))))))
2422 (defun org-html-format-headline-default-function
2423 (todo todo-type priority text tags info)
2424 "Default format function for a headline.
2425 See `org-html-format-headline-function' for details."
2426 (let ((todo (org-html--todo todo info))
2427 (priority (org-html--priority priority info))
2428 (tags (org-html--tags tags info)))
2429 (concat todo (and todo " ")
2430 priority (and priority " ")
2431 text
2432 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
2434 (defun org-html--container (headline info)
2435 (or (org-element-property :HTML_CONTAINER headline)
2436 (if (= 1 (org-export-get-relative-level headline info))
2437 (plist-get info :html-container)
2438 "div")))
2440 ;;;; Horizontal Rule
2442 (defun org-html-horizontal-rule (horizontal-rule contents info)
2443 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2444 CONTENTS is nil. INFO is a plist holding contextual information."
2445 (org-html-close-tag "hr" nil info))
2447 ;;;; Inline Src Block
2449 (defun org-html-inline-src-block (inline-src-block contents info)
2450 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2451 CONTENTS holds the contents of the item. INFO is a plist holding
2452 contextual information."
2453 (let* ((org-lang (org-element-property :language inline-src-block))
2454 (code (org-element-property :value inline-src-block)))
2455 (let ((lang (org-element-property :language inline-src-block))
2456 (code (org-html-format-code inline-src-block info))
2457 (label (let ((lbl (org-element-property :name inline-src-block)))
2458 (if (not lbl) ""
2459 (format " id=\"%s\""
2460 (org-export-solidify-link-text lbl))))))
2461 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code))))
2463 ;;;; Inlinetask
2465 (defun org-html-inlinetask (inlinetask contents info)
2466 "Transcode an INLINETASK element from Org to HTML.
2467 CONTENTS holds the contents of the block. INFO is a plist
2468 holding contextual information."
2469 (let* ((todo (and (plist-get info :with-todo-keywords)
2470 (let ((todo (org-element-property :todo-keyword inlinetask)))
2471 (and todo (org-export-data todo info)))))
2472 (todo-type (and todo (org-element-property :todo-type inlinetask)))
2473 (priority (and (plist-get info :with-priority)
2474 (org-element-property :priority inlinetask)))
2475 (text (org-export-data (org-element-property :title inlinetask) info))
2476 (tags (and (plist-get info :with-tags)
2477 (org-export-get-tags inlinetask info))))
2478 (funcall (plist-get info :html-format-inlinetask-function)
2479 todo todo-type priority text tags contents info)))
2481 (defun org-html-format-inlinetask-default-function
2482 (todo todo-type priority text tags contents info)
2483 "Default format function for a inlinetasks.
2484 See `org-html-format-inlinetask-function' for details."
2485 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2486 (org-html-format-headline-default-function
2487 todo todo-type priority text tags info)
2488 (org-html-close-tag "br" nil info)
2489 contents))
2491 ;;;; Italic
2493 (defun org-html-italic (italic contents info)
2494 "Transcode ITALIC from Org to HTML.
2495 CONTENTS is the text with italic markup. INFO is a plist holding
2496 contextual information."
2497 (format
2498 (or (cdr (assq 'italic (plist-get info :html-text-markup-alist))) "%s")
2499 contents))
2501 ;;;; Item
2503 (defun org-html-checkbox (checkbox info)
2504 "Format CHECKBOX into HTML.
2505 INFO is a plist holding contextual information. See
2506 `org-html-checkbox-type' for customization options."
2507 (cdr (assq checkbox
2508 (cdr (assq (plist-get info :html-checkbox-type)
2509 org-html-checkbox-types)))))
2511 (defun org-html-format-list-item (contents type checkbox info
2512 &optional term-counter-id
2513 headline)
2514 "Format a list item into HTML."
2515 (let ((class (if checkbox
2516 (format " class=\"%s\""
2517 (symbol-name checkbox)) ""))
2518 (checkbox (concat (org-html-checkbox checkbox info)
2519 (and checkbox " ")))
2520 (br (org-html-close-tag "br" nil info)))
2521 (concat
2522 (case type
2523 (ordered
2524 (let* ((counter term-counter-id)
2525 (extra (if counter (format " value=\"%s\"" counter) "")))
2526 (concat
2527 (format "<li%s%s>" class extra)
2528 (when headline (concat headline br)))))
2529 (unordered
2530 (let* ((id term-counter-id)
2531 (extra (if id (format " id=\"%s\"" id) "")))
2532 (concat
2533 (format "<li%s%s>" class extra)
2534 (when headline (concat headline br)))))
2535 (descriptive
2536 (let* ((term term-counter-id))
2537 (setq term (or term "(no term)"))
2538 ;; Check-boxes in descriptive lists are associated to tag.
2539 (concat (format "<dt%s>%s</dt>"
2540 class (concat checkbox term))
2541 "<dd>"))))
2542 (unless (eq type 'descriptive) checkbox)
2543 (and contents (org-trim contents))
2544 (case type
2545 (ordered "</li>")
2546 (unordered "</li>")
2547 (descriptive "</dd>")))))
2549 (defun org-html-item (item contents info)
2550 "Transcode an ITEM element from Org to HTML.
2551 CONTENTS holds the contents of the item. INFO is a plist holding
2552 contextual information."
2553 (let* ((plain-list (org-export-get-parent item))
2554 (type (org-element-property :type plain-list))
2555 (counter (org-element-property :counter item))
2556 (checkbox (org-element-property :checkbox item))
2557 (tag (let ((tag (org-element-property :tag item)))
2558 (and tag (org-export-data tag info)))))
2559 (org-html-format-list-item
2560 contents type checkbox info (or tag counter))))
2562 ;;;; Keyword
2564 (defun org-html-keyword (keyword contents info)
2565 "Transcode a KEYWORD element from Org to HTML.
2566 CONTENTS is nil. INFO is a plist holding contextual information."
2567 (let ((key (org-element-property :key keyword))
2568 (value (org-element-property :value keyword)))
2569 (cond
2570 ((string= key "HTML") value)
2571 ((string= key "TOC")
2572 (let ((case-fold-search t))
2573 (cond
2574 ((string-match "\\<headlines\\>" value)
2575 (let ((depth (and (string-match "\\<[0-9]+\\>" value)
2576 (string-to-number (match-string 0 value))))
2577 (localp (org-string-match-p "\\<local\\>" value)))
2578 (org-html-toc depth info (and localp keyword))))
2579 ((string= "listings" value) (org-html-list-of-listings info))
2580 ((string= "tables" value) (org-html-list-of-tables info))))))))
2582 ;;;; Latex Environment
2584 (defun org-html-format-latex (latex-frag processing-type info)
2585 "Format a LaTeX fragment LATEX-FRAG into HTML.
2586 PROCESSING-TYPE designates the tool used for conversion. It is
2587 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2588 and t. See `org-html-with-latex' for more information. INFO is
2589 a plist containing export properties."
2590 (let ((cache-relpath "") (cache-dir ""))
2591 (unless (eq processing-type 'mathjax)
2592 (let ((bfn (or (buffer-file-name)
2593 (make-temp-name
2594 (expand-file-name "latex" temporary-file-directory))))
2595 (latex-header
2596 (let ((header (plist-get info :latex-header)))
2597 (and header
2598 (concat (mapconcat
2599 (lambda (line) (concat "#+LATEX_HEADER: " line))
2600 (org-split-string header "\n")
2601 "\n")
2602 "\n")))))
2603 (setq cache-relpath
2604 (concat "ltxpng/"
2605 (file-name-sans-extension
2606 (file-name-nondirectory bfn)))
2607 cache-dir (file-name-directory bfn))
2608 ;; Re-create LaTeX environment from original buffer in
2609 ;; temporary buffer so that dvipng/imagemagick can properly
2610 ;; turn the fragment into an image.
2611 (setq latex-frag (concat latex-header latex-frag))))
2612 (with-temp-buffer
2613 (insert latex-frag)
2614 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2615 nil processing-type)
2616 (buffer-string))))
2618 (defun org-html-latex-environment (latex-environment contents info)
2619 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2620 CONTENTS is nil. INFO is a plist holding contextual information."
2621 (let ((processing-type (plist-get info :with-latex))
2622 (latex-frag (org-remove-indentation
2623 (org-element-property :value latex-environment)))
2624 (attributes (org-export-read-attribute :attr_html latex-environment)))
2625 (case processing-type
2626 ((t mathjax)
2627 (org-html-format-latex latex-frag 'mathjax info))
2628 ((dvipng imagemagick)
2629 (let ((formula-link
2630 (org-html-format-latex latex-frag processing-type info)))
2631 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2632 ;; Do not provide a caption or a name to be consistent with
2633 ;; `mathjax' handling.
2634 (org-html--wrap-image
2635 (org-html--format-image
2636 (match-string 1 formula-link) attributes info) info))))
2637 (t latex-frag))))
2639 ;;;; Latex Fragment
2641 (defun org-html-latex-fragment (latex-fragment contents info)
2642 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2643 CONTENTS is nil. INFO is a plist holding contextual information."
2644 (let ((latex-frag (org-element-property :value latex-fragment))
2645 (processing-type (plist-get info :with-latex)))
2646 (case processing-type
2647 ((t mathjax)
2648 (org-html-format-latex latex-frag 'mathjax info))
2649 ((dvipng imagemagick)
2650 (let ((formula-link
2651 (org-html-format-latex latex-frag processing-type info)))
2652 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2653 (org-html--format-image (match-string 1 formula-link) nil info))))
2654 (t latex-frag))))
2656 ;;;; Line Break
2658 (defun org-html-line-break (line-break contents info)
2659 "Transcode a LINE-BREAK object from Org to HTML.
2660 CONTENTS is nil. INFO is a plist holding contextual information."
2661 (concat (org-html-close-tag "br" nil info) "\n"))
2663 ;;;; Link
2665 (defun org-html-inline-image-p (link info)
2666 "Non-nil when LINK is meant to appear as an image.
2667 INFO is a plist used as a communication channel. LINK is an
2668 inline image when it has no description and targets an image
2669 file (see `org-html-inline-image-rules' for more information), or
2670 if its description is a single link targeting an image file."
2671 (if (not (org-element-contents link))
2672 (org-export-inline-image-p
2673 link (plist-get info :html-inline-image-rules))
2674 (not
2675 (let ((link-count 0))
2676 (org-element-map (org-element-contents link)
2677 (cons 'plain-text org-element-all-objects)
2678 (lambda (obj)
2679 (case (org-element-type obj)
2680 (plain-text (org-string-nw-p obj))
2681 (link (if (= link-count 1) t
2682 (incf link-count)
2683 (not (org-export-inline-image-p
2684 obj (plist-get info :html-inline-image-rules)))))
2685 (otherwise t)))
2686 info t)))))
2688 (defvar org-html-standalone-image-predicate)
2689 (defun org-html-standalone-image-p (element info)
2690 "Non-nil if ELEMENT is a standalone image.
2692 INFO is a plist holding contextual information.
2694 An element or object is a standalone image when
2696 - its type is `paragraph' and its sole content, save for white
2697 spaces, is a link that qualifies as an inline image;
2699 - its type is `link' and its containing paragraph has no other
2700 content save white spaces.
2702 Bind `org-html-standalone-image-predicate' to constrain paragraph
2703 further. For example, to check for only captioned standalone
2704 images, set it to:
2706 \(lambda (paragraph) (org-element-property :caption paragraph))"
2707 (let ((paragraph (case (org-element-type element)
2708 (paragraph element)
2709 (link (org-export-get-parent element)))))
2710 (and (eq (org-element-type paragraph) 'paragraph)
2711 (or (not (fboundp 'org-html-standalone-image-predicate))
2712 (funcall org-html-standalone-image-predicate paragraph))
2713 (catch 'exit
2714 (let ((link-count 0))
2715 (org-element-map (org-element-contents paragraph)
2716 (cons 'plain-text org-element-all-objects)
2717 #'(lambda (obj)
2718 (when (case (org-element-type obj)
2719 (plain-text (org-string-nw-p obj))
2720 (link (or (> (incf link-count) 1)
2721 (not (org-html-inline-image-p obj info))))
2722 (otherwise t))
2723 (throw 'exit nil)))
2724 info nil 'link)
2725 (= link-count 1))))))
2727 (defun org-html-link (link desc info)
2728 "Transcode a LINK object from Org to HTML.
2730 DESC is the description part of the link, or the empty string.
2731 INFO is a plist holding contextual information. See
2732 `org-export-data'."
2733 (let* ((home (when (plist-get info :html-link-home)
2734 (org-trim (plist-get info :html-link-home))))
2735 (use-abs-url (plist-get info :html-link-use-abs-url))
2736 (link-org-files-as-html-maybe
2737 (function
2738 (lambda (raw-path info)
2739 "Treat links to `file.org' as links to `file.html', if needed.
2740 See `org-html-link-org-files-as-html'."
2741 (cond
2742 ((and (plist-get info :html-link-org-files-as-html)
2743 (string= ".org"
2744 (downcase (file-name-extension raw-path "."))))
2745 (concat (file-name-sans-extension raw-path) "."
2746 (plist-get info :html-extension)))
2747 (t raw-path)))))
2748 (type (org-element-property :type link))
2749 (raw-path (org-element-property :path link))
2750 ;; Ensure DESC really exists, or set it to nil.
2751 (desc (org-string-nw-p desc))
2752 (path
2753 (cond
2754 ((member type '("http" "https" "ftp" "mailto"))
2755 (org-html-encode-plain-text
2756 (org-link-escape-browser
2757 (org-link-unescape (concat type ":" raw-path)))))
2758 ((string= type "file")
2759 ;; Treat links to ".org" files as ".html", if needed.
2760 (setq raw-path
2761 (funcall link-org-files-as-html-maybe raw-path info))
2762 ;; If file path is absolute, prepend it with protocol
2763 ;; component - "file:".
2764 (cond
2765 ((file-name-absolute-p raw-path)
2766 (setq raw-path (concat "file:" raw-path)))
2767 ((and home use-abs-url)
2768 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2769 ;; Add search option, if any. A search option can be
2770 ;; relative to a custom-id or a headline title. Append
2771 ;; a hash sign to any unresolved option, as it might point
2772 ;; to a target.
2773 (let ((option (org-element-property :search-option link)))
2774 (cond ((not option) raw-path)
2775 ((eq (aref option 0) ?#) (concat raw-path option))
2777 (let ((destination
2778 (org-publish-resolve-external-fuzzy-link
2779 (org-element-property :path link) option)))
2780 (concat raw-path
2781 (if (not destination) (concat "#" option)
2782 (concat "#sec-"
2783 (mapconcat #'number-to-string
2784 destination "-")))))))))
2785 (t raw-path)))
2786 ;; Extract attributes from parent's paragraph. HACK: Only do
2787 ;; this for the first link in parent (inner image link for
2788 ;; inline images). This is needed as long as attributes
2789 ;; cannot be set on a per link basis.
2790 (attributes-plist
2791 (let* ((parent (org-export-get-parent-element link))
2792 (link (let ((container (org-export-get-parent link)))
2793 (if (and (eq (org-element-type container) 'link)
2794 (org-html-inline-image-p link info))
2795 container
2796 link))))
2797 (and (eq (org-element-map parent 'link 'identity info t) link)
2798 (org-export-read-attribute :attr_html parent))))
2799 (attributes
2800 (let ((attr (org-html--make-attribute-string attributes-plist)))
2801 (if (org-string-nw-p attr) (concat " " attr) ""))))
2802 (cond
2803 ;; Link type is handled by a special function.
2804 ((org-export-custom-protocol-maybe link desc 'html))
2805 ;; Image file.
2806 ((and (plist-get info :html-inline-images)
2807 (org-export-inline-image-p
2808 link (plist-get info :html-inline-image-rules)))
2809 (org-html--format-image path attributes-plist info))
2810 ;; Radio target: Transcode target's contents and use them as
2811 ;; link's description.
2812 ((string= type "radio")
2813 (let ((destination (org-export-resolve-radio-link link info)))
2814 (if (not destination) desc
2815 (format "<a href=\"#%s\"%s>%s</a>"
2816 (org-export-solidify-link-text
2817 (org-element-property :value destination))
2818 attributes desc))))
2819 ;; Links pointing to a headline: Find destination and build
2820 ;; appropriate referencing command.
2821 ((member type '("custom-id" "fuzzy" "id"))
2822 (let ((destination (if (string= type "fuzzy")
2823 (org-export-resolve-fuzzy-link link info)
2824 (org-export-resolve-id-link link info))))
2825 (case (org-element-type destination)
2826 ;; ID link points to an external file.
2827 (plain-text
2828 (let ((fragment (concat "ID-" path))
2829 ;; Treat links to ".org" files as ".html", if needed.
2830 (path (funcall link-org-files-as-html-maybe
2831 destination info)))
2832 (format "<a href=\"%s#%s\"%s>%s</a>"
2833 path fragment attributes (or desc destination))))
2834 ;; Fuzzy link points nowhere.
2835 ((nil)
2836 (format "<i>%s</i>"
2837 (or desc
2838 (org-export-data
2839 (org-element-property :raw-link link) info))))
2840 ;; Link points to a headline.
2841 (headline
2842 (let ((href (or (and (string= type "custom-id")
2843 (org-element-property :CUSTOM_ID destination))
2844 (org-export-get-headline-id destination info)))
2845 ;; What description to use?
2846 (desc
2847 ;; Case 1: Headline is numbered and LINK has no
2848 ;; description. Display section number.
2849 (if (and (org-export-numbered-headline-p destination info)
2850 (not desc))
2851 (mapconcat 'number-to-string
2852 (org-export-get-headline-number
2853 destination info) ".")
2854 ;; Case 2: Either the headline is un-numbered or
2855 ;; LINK has a custom description. Display LINK's
2856 ;; description or headline's title.
2857 (or desc (org-export-data (org-element-property
2858 :title destination) info)))))
2859 (format "<a href=\"#%s\"%s>%s</a>"
2860 (org-export-solidify-link-text href) attributes desc)))
2861 ;; Fuzzy link points to a target or an element.
2863 (let* ((path (org-export-solidify-link-text path))
2864 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2865 (number (cond
2866 (desc nil)
2867 ((org-html-standalone-image-p destination info)
2868 (org-export-get-ordinal
2869 (org-element-map destination 'link
2870 'identity info t)
2871 info 'link 'org-html-standalone-image-p))
2872 (t (org-export-get-ordinal
2873 destination info nil 'org-html--has-caption-p))))
2874 (desc (cond (desc)
2875 ((not number) "No description for this link")
2876 ((numberp number) (number-to-string number))
2877 (t (mapconcat 'number-to-string number ".")))))
2878 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2879 ;; Coderef: replace link with the reference name or the
2880 ;; equivalent line number.
2881 ((string= type "coderef")
2882 (let ((fragment (concat "coderef-" path)))
2883 (format "<a href=\"#%s\"%s%s>%s</a>"
2884 fragment
2885 (org-trim
2886 (format (concat "class=\"coderef\""
2887 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2888 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2889 fragment fragment))
2890 attributes
2891 (format (org-export-get-coderef-format path desc)
2892 (org-export-resolve-coderef path info)))))
2893 ;; External link with a description part.
2894 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2895 ;; External link without a description part.
2896 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2897 ;; No path, only description. Try to do something useful.
2898 (t (format "<i>%s</i>" desc)))))
2900 ;;;; Node Property
2902 (defun org-html-node-property (node-property contents info)
2903 "Transcode a NODE-PROPERTY element from Org to HTML.
2904 CONTENTS is nil. INFO is a plist holding contextual
2905 information."
2906 (format "%s:%s"
2907 (org-element-property :key node-property)
2908 (let ((value (org-element-property :value node-property)))
2909 (if value (concat " " value) ""))))
2911 ;;;; Paragraph
2913 (defun org-html-paragraph (paragraph contents info)
2914 "Transcode a PARAGRAPH element from Org to HTML.
2915 CONTENTS is the contents of the paragraph, as a string. INFO is
2916 the plist used as a communication channel."
2917 (let* ((parent (org-export-get-parent paragraph))
2918 (parent-type (org-element-type parent))
2919 (style '((footnote-definition " class=\"footpara\"")))
2920 (attributes (org-html--make-attribute-string
2921 (org-export-read-attribute :attr_html paragraph)))
2922 (extra (or (cadr (assoc parent-type style)) "")))
2923 (cond
2924 ((and (eq parent-type 'item)
2925 (not (org-export-get-previous-element paragraph info))
2926 (let ((followers (org-export-get-next-element paragraph info 2)))
2927 (and (not (cdr followers))
2928 (memq (org-element-type (car followers)) '(nil plain-list)))))
2929 ;; First paragraph in an item has no tag if it is alone or
2930 ;; followed, at most, by a sub-list.
2931 contents)
2932 ((org-html-standalone-image-p paragraph info)
2933 ;; Standalone image.
2934 (let ((caption
2935 (let ((raw (org-export-data
2936 (org-export-get-caption paragraph) info))
2937 (org-html-standalone-image-predicate
2938 'org-html--has-caption-p))
2939 (if (not (org-string-nw-p raw)) raw
2940 (concat
2941 "<span class=\"figure-number\">"
2942 (format (org-html--translate "Figure %d:" info)
2943 (org-export-get-ordinal
2944 (org-element-map paragraph 'link
2945 'identity info t)
2946 info nil 'org-html-standalone-image-p))
2947 "</span> " raw))))
2948 (label (org-element-property :name paragraph)))
2949 (org-html--wrap-image contents info caption label)))
2950 ;; Regular paragraph.
2951 (t (format "<p%s%s>\n%s</p>"
2952 (if (org-string-nw-p attributes)
2953 (concat " " attributes) "")
2954 extra contents)))))
2956 ;;;; Plain List
2958 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2959 ;; the correct value for the item counter
2960 (defun org-html-begin-plain-list (type &optional arg1)
2961 "Insert the beginning of the HTML list depending on TYPE.
2962 When ARG1 is a string, use it as the start parameter for ordered
2963 lists."
2964 (case type
2965 (ordered
2966 (format "<ol class=\"org-ol\"%s>"
2967 (if arg1 (format " start=\"%d\"" arg1) "")))
2968 (unordered "<ul class=\"org-ul\">")
2969 (descriptive "<dl class=\"org-dl\">")))
2971 (defun org-html-end-plain-list (type)
2972 "Insert the end of the HTML list depending on TYPE."
2973 (case type
2974 (ordered "</ol>")
2975 (unordered "</ul>")
2976 (descriptive "</dl>")))
2978 (defun org-html-plain-list (plain-list contents info)
2979 "Transcode a PLAIN-LIST element from Org to HTML.
2980 CONTENTS is the contents of the list. INFO is a plist holding
2981 contextual information."
2982 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2983 (type (org-element-property :type plain-list)))
2984 (format "%s\n%s%s"
2985 (org-html-begin-plain-list type)
2986 contents (org-html-end-plain-list type))))
2988 ;;;; Plain Text
2990 (defun org-html-convert-special-strings (string)
2991 "Convert special characters in STRING to HTML."
2992 (let ((all org-html-special-string-regexps)
2993 e a re rpl start)
2994 (while (setq a (pop all))
2995 (setq re (car a) rpl (cdr a) start 0)
2996 (while (string-match re string start)
2997 (setq string (replace-match rpl t nil string))))
2998 string))
3000 (defun org-html-encode-plain-text (text)
3001 "Convert plain text characters from TEXT to HTML equivalent.
3002 Possible conversions are set in `org-html-protect-char-alist'."
3003 (dolist (pair org-html-protect-char-alist text)
3004 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t))))
3006 (defun org-html-plain-text (text info)
3007 "Transcode a TEXT string from Org to HTML.
3008 TEXT is the string to transcode. INFO is a plist holding
3009 contextual information."
3010 (let ((output text))
3011 ;; Protect following characters: <, >, &.
3012 (setq output (org-html-encode-plain-text output))
3013 ;; Handle smart quotes. Be sure to provide original string since
3014 ;; OUTPUT may have been modified.
3015 (when (plist-get info :with-smart-quotes)
3016 (setq output (org-export-activate-smart-quotes output :html info text)))
3017 ;; Handle special strings.
3018 (when (plist-get info :with-special-strings)
3019 (setq output (org-html-convert-special-strings output)))
3020 ;; Handle break preservation if required.
3021 (when (plist-get info :preserve-breaks)
3022 (setq output
3023 (replace-regexp-in-string
3024 "\\(\\\\\\\\\\)?[ \t]*\n"
3025 (concat (org-html-close-tag "br" nil info) "\n") output)))
3026 ;; Return value.
3027 output))
3030 ;; Planning
3032 (defun org-html-planning (planning contents info)
3033 "Transcode a PLANNING element from Org to HTML.
3034 CONTENTS is nil. INFO is a plist used as a communication
3035 channel."
3036 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
3037 (format
3038 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3039 (mapconcat
3040 'identity
3041 (delq nil
3042 (list
3043 (let ((closed (org-element-property :closed planning)))
3044 (when closed
3045 (format span-fmt org-closed-string
3046 (org-timestamp-translate closed))))
3047 (let ((deadline (org-element-property :deadline planning)))
3048 (when deadline
3049 (format span-fmt org-deadline-string
3050 (org-timestamp-translate deadline))))
3051 (let ((scheduled (org-element-property :scheduled planning)))
3052 (when scheduled
3053 (format span-fmt org-scheduled-string
3054 (org-timestamp-translate scheduled))))))
3055 " "))))
3057 ;;;; Property Drawer
3059 (defun org-html-property-drawer (property-drawer contents info)
3060 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3061 CONTENTS holds the contents of the drawer. INFO is a plist
3062 holding contextual information."
3063 (and (org-string-nw-p contents)
3064 (format "<pre class=\"example\">\n%s</pre>" contents)))
3066 ;;;; Quote Block
3068 (defun org-html-quote-block (quote-block contents info)
3069 "Transcode a QUOTE-BLOCK element from Org to HTML.
3070 CONTENTS holds the contents of the block. INFO is a plist
3071 holding contextual information."
3072 (format "<blockquote>\n%s</blockquote>" contents))
3074 ;;;; Section
3076 (defun org-html-section (section contents info)
3077 "Transcode a SECTION element from Org to HTML.
3078 CONTENTS holds the contents of the section. INFO is a plist
3079 holding contextual information."
3080 (let ((parent (org-export-get-parent-headline section)))
3081 ;; Before first headline: no container, just return CONTENTS.
3082 (if (not parent) contents
3083 ;; Get div's class and id references.
3084 (let* ((class-num (+ (org-export-get-relative-level parent info)
3085 (1- (plist-get info :html-toplevel-hlevel))))
3086 (section-number
3087 (and (org-export-numbered-headline-p parent info)
3088 (mapconcat
3089 #'number-to-string
3090 (org-export-get-headline-number parent info) "-"))))
3091 ;; Build return value.
3092 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3093 class-num
3094 (or (org-element-property :CUSTOM_ID parent)
3095 section-number
3096 (org-export-get-headline-id parent info))
3097 (or contents ""))))))
3099 ;;;; Radio Target
3101 (defun org-html-radio-target (radio-target text info)
3102 "Transcode a RADIO-TARGET object from Org to HTML.
3103 TEXT is the text of the target. INFO is a plist holding
3104 contextual information."
3105 (let ((id (org-export-solidify-link-text
3106 (org-element-property :value radio-target))))
3107 (org-html--anchor id text nil info)))
3109 ;;;; Special Block
3111 (defun org-html-special-block (special-block contents info)
3112 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3113 CONTENTS holds the contents of the block. INFO is a plist
3114 holding contextual information."
3115 (let* ((block-type (org-element-property :type special-block))
3116 (contents (or contents ""))
3117 (html5-fancy (and (org-html-html5-p info)
3118 (plist-get info :html-html5-fancy)
3119 (member block-type org-html-html5-elements)))
3120 (attributes (org-export-read-attribute :attr_html special-block)))
3121 (unless html5-fancy
3122 (let ((class (plist-get attributes :class)))
3123 (setq attributes (plist-put attributes :class
3124 (if class (concat class " " block-type)
3125 block-type)))))
3126 (setq attributes (org-html--make-attribute-string attributes))
3127 (when (not (equal attributes ""))
3128 (setq attributes (concat " " attributes)))
3129 (if html5-fancy
3130 (format "<%s%s>\n%s</%s>" block-type attributes
3131 contents block-type)
3132 (format "<div%s>\n%s\n</div>" attributes contents))))
3134 ;;;; Src Block
3136 (defun org-html-src-block (src-block contents info)
3137 "Transcode a SRC-BLOCK element from Org to HTML.
3138 CONTENTS holds the contents of the item. INFO is a plist holding
3139 contextual information."
3140 (if (org-export-read-attribute :attr_html src-block :textarea)
3141 (org-html--textarea-block src-block)
3142 (let ((lang (org-element-property :language src-block))
3143 (caption (org-export-get-caption src-block))
3144 (code (org-html-format-code src-block info))
3145 (label (let ((lbl (org-element-property :name src-block)))
3146 (if (not lbl) ""
3147 (format " id=\"%s\""
3148 (org-export-solidify-link-text lbl))))))
3149 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3150 (format
3151 "<div class=\"org-src-container\">\n%s%s\n</div>"
3152 (if (not caption) ""
3153 (format "<label class=\"org-src-name\">%s</label>"
3154 (org-export-data caption info)))
3155 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3157 ;;;; Statistics Cookie
3159 (defun org-html-statistics-cookie (statistics-cookie contents info)
3160 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3161 CONTENTS is nil. INFO is a plist holding contextual information."
3162 (let ((cookie-value (org-element-property :value statistics-cookie)))
3163 (format "<code>%s</code>" cookie-value)))
3165 ;;;; Strike-Through
3167 (defun org-html-strike-through (strike-through contents info)
3168 "Transcode STRIKE-THROUGH from Org to HTML.
3169 CONTENTS is the text with strike-through markup. INFO is a plist
3170 holding contextual information."
3171 (format
3172 (or (cdr (assq 'strike-through (plist-get info :html-text-markup-alist)))
3173 "%s")
3174 contents))
3176 ;;;; Subscript
3178 (defun org-html-subscript (subscript contents info)
3179 "Transcode a SUBSCRIPT object from Org to HTML.
3180 CONTENTS is the contents of the object. INFO is a plist holding
3181 contextual information."
3182 (format "<sub>%s</sub>" contents))
3184 ;;;; Superscript
3186 (defun org-html-superscript (superscript contents info)
3187 "Transcode a SUPERSCRIPT object from Org to HTML.
3188 CONTENTS is the contents of the object. INFO is a plist holding
3189 contextual information."
3190 (format "<sup>%s</sup>" contents))
3192 ;;;; Table Cell
3194 (defun org-html-table-cell (table-cell contents info)
3195 "Transcode a TABLE-CELL element from Org to HTML.
3196 CONTENTS is nil. INFO is a plist used as a communication
3197 channel."
3198 (let* ((table-row (org-export-get-parent table-cell))
3199 (table (org-export-get-parent-table table-cell))
3200 (cell-attrs
3201 (if (not (plist-get info :html-table-align-individual-fields)) ""
3202 (format (if (and (boundp 'org-html-format-table-no-css)
3203 org-html-format-table-no-css)
3204 " align=\"%s\"" " class=\"%s\"")
3205 (org-export-table-cell-alignment table-cell info)))))
3206 (when (or (not contents) (string= "" (org-trim contents)))
3207 (setq contents "&#xa0;"))
3208 (cond
3209 ((and (org-export-table-has-header-p table info)
3210 (= 1 (org-export-table-row-group table-row info)))
3211 (let ((header-tags (plist-get info :html-table-header-tags)))
3212 (concat "\n" (format (car header-tags) "col" cell-attrs)
3213 contents
3214 (cdr header-tags))))
3215 ((and (plist-get info :html-table-use-header-tags-for-first-column)
3216 (zerop (cdr (org-export-table-cell-address table-cell info))))
3217 (let ((header-tags (plist-get info :html-table-header-tags)))
3218 (concat "\n" (format (car header-tags) "row" cell-attrs)
3219 contents
3220 (cdr header-tags))))
3221 (t (let ((data-tags (plist-get info :html-table-data-tags)))
3222 (concat "\n" (format (car data-tags) cell-attrs)
3223 contents
3224 (cdr data-tags)))))))
3226 ;;;; Table Row
3228 (defun org-html-table-row (table-row contents info)
3229 "Transcode a TABLE-ROW element from Org to HTML.
3230 CONTENTS is the contents of the row. INFO is a plist used as a
3231 communication channel."
3232 ;; Rules are ignored since table separators are deduced from
3233 ;; borders of the current row.
3234 (when (eq (org-element-property :type table-row) 'standard)
3235 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3236 (row-number (org-export-table-row-number table-row info))
3237 (start-rowgroup-p
3238 (org-export-table-row-starts-rowgroup-p table-row info))
3239 (end-rowgroup-p
3240 (org-export-table-row-ends-rowgroup-p table-row info))
3241 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3242 ;; but should be set so that `org-html-table-row-tags' can
3243 ;; use them (see the docstring of this variable.)
3244 (top-row-p (and (equal start-rowgroup-p '(top))
3245 (equal end-rowgroup-p '(below top))))
3246 (bottom-row-p (and (equal start-rowgroup-p '(above))
3247 (equal end-rowgroup-p '(bottom above))))
3248 (rowgroup-tags
3249 (cond
3250 ;; Case 1: Row belongs to second or subsequent rowgroups.
3251 ((not (= 1 rowgroup-number))
3252 '("<tbody>" . "\n</tbody>"))
3253 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3254 ((org-export-table-has-header-p
3255 (org-export-get-parent-table table-row) info)
3256 '("<thead>" . "\n</thead>"))
3257 ;; Case 2: Row is from first and only row group.
3258 (t '("<tbody>" . "\n</tbody>")))))
3259 (concat
3260 ;; Begin a rowgroup?
3261 (when start-rowgroup-p (car rowgroup-tags))
3262 ;; Actual table row
3263 (concat "\n" (eval (car (plist-get info :html-table-row-tags)))
3264 contents
3265 "\n"
3266 (eval (cdr (plist-get info :html-table-row-tags))))
3267 ;; End a rowgroup?
3268 (when end-rowgroup-p (cdr rowgroup-tags))))))
3270 ;;;; Table
3272 (defun org-html-table-first-row-data-cells (table info)
3273 "Transcode the first row of TABLE.
3274 INFO is a plist used as a communication channel."
3275 (let ((table-row
3276 (org-element-map table 'table-row
3277 (lambda (row)
3278 (unless (eq (org-element-property :type row) 'rule) row))
3279 info 'first-match))
3280 (special-column-p (org-export-table-has-special-column-p table)))
3281 (if (not special-column-p) (org-element-contents table-row)
3282 (cdr (org-element-contents table-row)))))
3284 (defun org-html-table--table.el-table (table info)
3285 "Format table.el tables into HTML.
3286 INFO is a plist used as a communication channel."
3287 (when (eq (org-element-property :type table) 'table.el)
3288 (require 'table)
3289 (let ((outbuf (with-current-buffer
3290 (get-buffer-create "*org-export-table*")
3291 (erase-buffer) (current-buffer))))
3292 (with-temp-buffer
3293 (insert (org-element-property :value table))
3294 (goto-char 1)
3295 (re-search-forward "^[ \t]*|[^|]" nil t)
3296 (table-generate-source 'html outbuf))
3297 (with-current-buffer outbuf
3298 (prog1 (org-trim (buffer-string))
3299 (kill-buffer) )))))
3301 (defun org-html-table (table contents info)
3302 "Transcode a TABLE element from Org to HTML.
3303 CONTENTS is the contents of the table. INFO is a plist holding
3304 contextual information."
3305 (case (org-element-property :type table)
3306 ;; Case 1: table.el table. Convert it using appropriate tools.
3307 (table.el (org-html-table--table.el-table table info))
3308 ;; Case 2: Standard table.
3310 (let* ((label (org-element-property :name table))
3311 (caption (org-export-get-caption table))
3312 (number (org-export-get-ordinal
3313 table info nil 'org-html--has-caption-p))
3314 (attributes
3315 (org-html--make-attribute-string
3316 (org-combine-plists
3317 (and label (list :id (org-export-solidify-link-text label)))
3318 (and (not (org-html-html5-p info))
3319 (plist-get info :html-table-attributes))
3320 (org-export-read-attribute :attr_html table))))
3321 (alignspec
3322 (if (and (boundp 'org-html-format-table-no-css)
3323 org-html-format-table-no-css)
3324 "align=\"%s\"" "class=\"%s\""))
3325 (table-column-specs
3326 (function
3327 (lambda (table info)
3328 (mapconcat
3329 (lambda (table-cell)
3330 (let ((alignment (org-export-table-cell-alignment
3331 table-cell info)))
3332 (concat
3333 ;; Begin a colgroup?
3334 (when (org-export-table-cell-starts-colgroup-p
3335 table-cell info)
3336 "\n<colgroup>")
3337 ;; Add a column. Also specify it's alignment.
3338 (format "\n%s"
3339 (org-html-close-tag
3340 "col" (concat " " (format alignspec alignment)) info))
3341 ;; End a colgroup?
3342 (when (org-export-table-cell-ends-colgroup-p
3343 table-cell info)
3344 "\n</colgroup>"))))
3345 (org-html-table-first-row-data-cells table info) "\n")))))
3346 (format "<table%s>\n%s\n%s\n%s</table>"
3347 (if (equal attributes "") "" (concat " " attributes))
3348 (if (not caption) ""
3349 (format (if (plist-get info :html-table-caption-above)
3350 "<caption class=\"t-above\">%s</caption>"
3351 "<caption class=\"t-bottom\">%s</caption>")
3352 (concat
3353 "<span class=\"table-number\">"
3354 (format (org-html--translate "Table %d:" info) number)
3355 "</span> " (org-export-data caption info))))
3356 (funcall table-column-specs table info)
3357 contents)))))
3359 ;;;; Target
3361 (defun org-html-target (target contents info)
3362 "Transcode a TARGET object from Org to HTML.
3363 CONTENTS is nil. INFO is a plist holding contextual
3364 information."
3365 (let ((id (org-export-solidify-link-text
3366 (org-element-property :value target))))
3367 (org-html--anchor id nil nil info)))
3369 ;;;; Timestamp
3371 (defun org-html-timestamp (timestamp contents info)
3372 "Transcode a TIMESTAMP object from Org to HTML.
3373 CONTENTS is nil. INFO is a plist holding contextual
3374 information."
3375 (let ((value (org-html-plain-text (org-timestamp-translate timestamp) info)))
3376 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3377 (replace-regexp-in-string "--" "&#x2013;" value))))
3379 ;;;; Underline
3381 (defun org-html-underline (underline contents info)
3382 "Transcode UNDERLINE from Org to HTML.
3383 CONTENTS is the text with underline markup. INFO is a plist
3384 holding contextual information."
3385 (format (or (cdr (assq 'underline (plist-get info :html-text-markup-alist)))
3386 "%s")
3387 contents))
3389 ;;;; Verbatim
3391 (defun org-html-verbatim (verbatim contents info)
3392 "Transcode VERBATIM from Org to HTML.
3393 CONTENTS is nil. INFO is a plist holding contextual
3394 information."
3395 (format (or (cdr (assq 'verbatim (plist-get info :html-text-markup-alist))) "%s")
3396 (org-html-encode-plain-text (org-element-property :value verbatim))))
3398 ;;;; Verse Block
3400 (defun org-html-verse-block (verse-block contents info)
3401 "Transcode a VERSE-BLOCK element from Org to HTML.
3402 CONTENTS is verse block contents. INFO is a plist holding
3403 contextual information."
3404 ;; Replace each newline character with line break. Also replace
3405 ;; each blank line with a line break.
3406 (setq contents (replace-regexp-in-string
3407 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3408 (replace-regexp-in-string
3409 "\\(\\\\\\\\\\)?[ \t]*\n"
3410 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3411 ;; Replace each white space at beginning of a line with a
3412 ;; non-breaking space.
3413 (while (string-match "^[ \t]+" contents)
3414 (let* ((num-ws (length (match-string 0 contents)))
3415 (ws (let (out) (dotimes (i num-ws out)
3416 (setq out (concat out "&#xa0;"))))))
3417 (setq contents (replace-match ws nil t contents))))
3418 (format "<p class=\"verse\">\n%s</p>" contents))
3421 ;;; Filter Functions
3423 (defun org-html-final-function (contents backend info)
3424 "Filter to indent the HTML and convert HTML entities."
3425 (with-temp-buffer
3426 (insert contents)
3427 (set-auto-mode t)
3428 (if (plist-get info :html-indent)
3429 (indent-region (point-min) (point-max)))
3430 (when (plist-get info :html-use-unicode-chars)
3431 (require 'mm-url)
3432 (mm-url-decode-entities))
3433 (buffer-substring-no-properties (point-min) (point-max))))
3436 ;;; End-user functions
3438 ;;;###autoload
3439 (defun org-html-export-as-html
3440 (&optional async subtreep visible-only body-only ext-plist)
3441 "Export current buffer to an HTML buffer.
3443 If narrowing is active in the current buffer, only export its
3444 narrowed part.
3446 If a region is active, export that region.
3448 A non-nil optional argument ASYNC means the process should happen
3449 asynchronously. The resulting buffer should be accessible
3450 through the `org-export-stack' interface.
3452 When optional argument SUBTREEP is non-nil, export the sub-tree
3453 at point, extracting information from the headline properties
3454 first.
3456 When optional argument VISIBLE-ONLY is non-nil, don't export
3457 contents of hidden elements.
3459 When optional argument BODY-ONLY is non-nil, only write code
3460 between \"<body>\" and \"</body>\" tags.
3462 EXT-PLIST, when provided, is a property list with external
3463 parameters overriding Org default settings, but still inferior to
3464 file-local settings.
3466 Export is done in a buffer named \"*Org HTML Export*\", which
3467 will be displayed when `org-export-show-temporary-export-buffer'
3468 is non-nil."
3469 (interactive)
3470 (org-export-to-buffer 'html "*Org HTML Export*"
3471 async subtreep visible-only body-only ext-plist
3472 (lambda () (set-auto-mode t))))
3474 ;;;###autoload
3475 (defun org-html-convert-region-to-html ()
3476 "Assume the current region has org-mode syntax, and convert it to HTML.
3477 This can be used in any buffer. For example, you can write an
3478 itemized list in org-mode syntax in an HTML buffer and use this
3479 command to convert it."
3480 (interactive)
3481 (org-export-replace-region-by 'html))
3483 ;;;###autoload
3484 (defun org-html-export-to-html
3485 (&optional async subtreep visible-only body-only ext-plist)
3486 "Export current buffer to a HTML file.
3488 If narrowing is active in the current buffer, only export its
3489 narrowed part.
3491 If a region is active, export that region.
3493 A non-nil optional argument ASYNC means the process should happen
3494 asynchronously. The resulting file should be accessible through
3495 the `org-export-stack' interface.
3497 When optional argument SUBTREEP is non-nil, export the sub-tree
3498 at point, extracting information from the headline properties
3499 first.
3501 When optional argument VISIBLE-ONLY is non-nil, don't export
3502 contents of hidden elements.
3504 When optional argument BODY-ONLY is non-nil, only write code
3505 between \"<body>\" and \"</body>\" tags.
3507 EXT-PLIST, when provided, is a property list with external
3508 parameters overriding Org default settings, but still inferior to
3509 file-local settings.
3511 Return output file's name."
3512 (interactive)
3513 (let* ((extension (concat "." (or (plist-get ext-plist :html-extension)
3514 org-html-extension
3515 "html")))
3516 (file (org-export-output-file-name extension subtreep))
3517 (org-export-coding-system org-html-coding-system))
3518 (org-export-to-file 'html file
3519 async subtreep visible-only body-only ext-plist)))
3521 ;;;###autoload
3522 (defun org-html-publish-to-html (plist filename pub-dir)
3523 "Publish an org file to HTML.
3525 FILENAME is the filename of the Org file to be published. PLIST
3526 is the property list for the given project. PUB-DIR is the
3527 publishing directory.
3529 Return output file name."
3530 (org-publish-org-to 'html filename
3531 (concat "." (or (plist-get plist :html-extension)
3532 org-html-extension
3533 "html"))
3534 plist pub-dir))
3537 (provide 'ox-html)
3539 ;; Local variables:
3540 ;; generated-autoload-file: "org-loaddefs.el"
3541 ;; End:
3543 ;;; ox-html.el ends here