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