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