Merge branch 'maint'
[org-mode.git] / lisp / ox-html.el
blob365802f39357355b28b2f9231b49b0caa28b4a79
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 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 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements a HTML back-end for Org generic exporter.
26 ;; To test it, run:
28 ;; M-x org-html-export-as-html
30 ;; in an Org mode buffer. See ox.el for more details on how this
31 ;; exporter works.
33 ;;; Code:
35 ;;; Dependencies
37 (require 'ox)
38 (require 'ox-publish)
39 (require 'format-spec)
40 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file "org-id" (id))
46 (declare-function htmlize-region "ext:htmlize" (beg end))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label))
49 (declare-function mm-url-decode-entities "mm-url" ())
51 ;;; Define Back-End
53 (org-export-define-backend 'html
54 '((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (paragraph . org-html-paragraph)
80 (plain-list . org-html-plain-list)
81 (plain-text . org-html-plain-text)
82 (planning . org-html-planning)
83 (property-drawer . org-html-property-drawer)
84 (quote-block . org-html-quote-block)
85 (quote-section . org-html-quote-section)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :export-block "HTML"
104 :filters-alist '((:filter-options . org-html-infojs-install-script)
105 (:filter-final-output . org-html-final-function))
106 :menu-entry
107 '(?h "Export to HTML"
108 ((?H "As HTML buffer" org-html-export-as-html)
109 (?h "As HTML file" org-html-export-to-html)
110 (?o "As HTML file and open"
111 (lambda (a s v b)
112 (if a (org-html-export-to-html t s v b)
113 (org-open-file (org-html-export-to-html nil s v b)))))))
114 :options-alist
115 '((:html-extension nil nil org-html-extension)
116 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
117 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
118 (:html-container "HTML_CONTAINER" nil org-html-container-element)
119 (:html-html5-fancy "HTML_HTML5_FANCY" nil org-html-html5-fancy)
120 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
121 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
122 (:html-mathjax "HTML_MATHJAX" nil "" space)
123 (:html-postamble nil "html-postamble" org-html-postamble)
124 (:html-preamble nil "html-preamble" org-html-preamble)
125 (:html-head "HTML_HEAD" nil org-html-head newline)
126 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
127 (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
128 (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
129 (:html-table-attributes nil nil org-html-table-default-attributes)
130 (:html-table-row-tags nil nil org-html-table-row-tags)
131 (:html-xml-declaration nil nil org-html-xml-declaration)
132 (:html-inline-images nil nil org-html-inline-images)
133 (:infojs-opt "INFOJS_OPT" nil nil)
134 ;; Redefine regular options.
135 (:creator "CREATOR" nil org-html-creator-string)
136 (:with-latex nil "tex" org-html-with-latex)))
139 ;;; Internal Variables
141 (defvar org-html-format-table-no-css)
142 (defvar htmlize-buffer-places) ; from htmlize.el
144 (defvar org-html--pre/postamble-class "status"
145 "CSS class used for pre/postamble")
147 (defconst org-html-doctype-alist
148 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
149 \"http://www.w3.org/TR/html4/strict.dtd\">")
150 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
151 \"http://www.w3.org/TR/html4/loose.dtd\">")
152 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
153 \"http://www.w3.org/TR/html4/frameset.dtd\">")
155 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
156 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
157 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
158 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
159 ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
160 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
161 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
162 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
164 ("html5" . "<!DOCTYPE html>")
165 ("xhtml5" . "<!DOCTYPE html>"))
166 "An alist mapping (x)html flavors to specific doctypes.")
168 (defconst org-html-html5-elements
169 '("article" "aside" "audio" "canvas" "details" "figcaption"
170 "figure" "footer" "header" "menu" "meter" "nav" "output"
171 "progress" "section" "video")
172 "New elements in html5.
174 <hgroup> is not included because it's currently impossible to
175 wrap special blocks around multiple headlines. For other blocks
176 that should contain headlines, use the HTML_CONTAINER property on
177 the headline itself.")
179 (defconst org-html-special-string-regexps
180 '(("\\\\-" . "&#x00ad;") ; shy
181 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
182 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
183 ("\\.\\.\\." . "&#x2026;")) ; hellip
184 "Regular expressions for special string conversion.")
186 (defconst org-html-scripts
187 "<script type=\"text/javascript\">
189 @licstart The following is the entire license notice for the
190 JavaScript code in this tag.
192 Copyright (C) 2012 Free Software Foundation, Inc.
194 The JavaScript code in this tag is free software: you can
195 redistribute it and/or modify it under the terms of the GNU
196 General Public License (GNU GPL) as published by the Free Software
197 Foundation, either version 3 of the License, or (at your option)
198 any later version. The code is distributed WITHOUT ANY WARRANTY;
199 without even the implied warranty of MERCHANTABILITY or FITNESS
200 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
202 As additional permission under GNU GPL version 3 section 7, you
203 may distribute non-source (e.g., minimized or compacted) forms of
204 that code without the copy of the GNU GPL normally required by
205 section 4, provided you include this license notice and a URL
206 through which recipients can access the Corresponding Source.
209 @licend The above is the entire license notice
210 for the JavaScript code in this tag.
212 <!--/*--><![CDATA[/*><!--*/
213 function CodeHighlightOn(elem, id)
215 var target = document.getElementById(id);
216 if(null != target) {
217 elem.cacheClassElem = elem.className;
218 elem.cacheClassTarget = target.className;
219 target.className = \"code-highlighted\";
220 elem.className = \"code-highlighted\";
223 function CodeHighlightOff(elem, id)
225 var target = document.getElementById(id);
226 if(elem.cacheClassElem)
227 elem.className = elem.cacheClassElem;
228 if(elem.cacheClassTarget)
229 target.className = elem.cacheClassTarget;
231 /*]]>*///-->
232 </script>"
233 "Basic JavaScript that is needed by HTML files produced by Org mode.")
235 (defconst org-html-style-default
236 "<style type=\"text/css\">
237 <!--/*--><![CDATA[/*><!--*/
238 .title { text-align: center; }
239 .todo { font-family: monospace; color: red; }
240 .done { color: green; }
241 .tag { background-color: #eee; font-family: monospace;
242 padding: 2px; font-size: 80%; font-weight: normal; }
243 .timestamp { color: #bebebe; }
244 .timestamp-kwd { color: #5f9ea0; }
245 .right { margin-left: auto; margin-right: 0px; text-align: right; }
246 .left { margin-left: 0px; margin-right: auto; text-align: left; }
247 .center { margin-left: auto; margin-right: auto; text-align: center; }
248 .underline { text-decoration: underline; }
249 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
250 p.verse { margin-left: 3%; }
251 pre {
252 border: 1px solid #ccc;
253 box-shadow: 3px 3px 3px #eee;
254 padding: 8pt;
255 font-family: monospace;
256 overflow: auto;
257 margin: 1.2em;
259 pre.src {
260 position: relative;
261 overflow: visible;
262 padding-top: 1.2em;
264 pre.src:before {
265 display: none;
266 position: absolute;
267 background-color: white;
268 top: -10px;
269 right: 10px;
270 padding: 3px;
271 border: 1px solid black;
273 pre.src:hover:before { display: inline;}
274 pre.src-sh:before { content: 'sh'; }
275 pre.src-bash:before { content: 'sh'; }
276 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
277 pre.src-R:before { content: 'R'; }
278 pre.src-perl:before { content: 'Perl'; }
279 pre.src-java:before { content: 'Java'; }
280 pre.src-sql:before { content: 'SQL'; }
282 table { border-collapse:collapse; }
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 Sebastian Rose
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 :type '(alist :key-type (symbol :tag "Markup type")
551 :value-type (string :tag "Format string"))
552 :options '(bold code italic strike-through underline verbatim))
554 (defcustom org-html-indent nil
555 "Non-nil means to indent the generated HTML.
556 Warning: non-nil may break indentation of source code blocks."
557 :group 'org-export-html
558 :version "24.4"
559 :package-version '(Org . "8.0")
560 :type 'boolean)
562 (defcustom org-html-use-unicode-chars nil
563 "Non-nil means to use unicode characters instead of HTML entities."
564 :group 'org-export-html
565 :version "24.4"
566 :package-version '(Org . "8.0")
567 :type 'boolean)
569 ;;;; Drawers
571 (defcustom org-html-format-drawer-function nil
572 "Function called to format a drawer in HTML code.
574 The function must accept two parameters:
575 NAME the drawer name, like \"LOGBOOK\"
576 CONTENTS the contents of the drawer.
578 The function should return the string to be exported.
580 For example, the variable could be set to the following function
581 in order to mimic default behaviour:
583 \(defun org-html-format-drawer-default \(name contents\)
584 \"Format a drawer element for HTML export.\"
585 contents\)"
586 :group 'org-export-html
587 :type 'function)
589 ;;;; Footnotes
591 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
592 <h2 class=\"footnotes\">%s: </h2>
593 <div id=\"text-footnotes\">
595 </div>
596 </div>"
597 "Format for the footnotes section.
598 Should contain a two instances of %s. The first will be replaced with the
599 language-specific word for \"Footnotes\", the second one will be replaced
600 by the footnotes themselves."
601 :group 'org-export-html
602 :type 'string)
604 (defcustom org-html-footnote-format "<sup>%s</sup>"
605 "The format for the footnote reference.
606 %s will be replaced by the footnote reference itself."
607 :group 'org-export-html
608 :type 'string)
610 (defcustom org-html-footnote-separator "<sup>, </sup>"
611 "Text used to separate footnotes."
612 :group 'org-export-html
613 :type 'string)
615 ;;;; Headline
617 (defcustom org-html-toplevel-hlevel 2
618 "The <H> level for level 1 headings in HTML export.
619 This is also important for the classes that will be wrapped around headlines
620 and outline structure. If this variable is 1, the top-level headlines will
621 be <h1>, and the corresponding classes will be outline-1, section-number-1,
622 and outline-text-1. If this is 2, all of these will get a 2 instead.
623 The default for this variable is 2, because we use <h1> for formatting the
624 document title."
625 :group 'org-export-html
626 :type 'integer)
628 (defcustom org-html-format-headline-function nil
629 "Function to format headline text.
631 This function will be called with 5 arguments:
632 TODO the todo keyword (string or nil).
633 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
634 PRIORITY the priority of the headline (integer or nil)
635 TEXT the main headline text (string).
636 TAGS the tags (string or nil).
638 The function result will be used in the section format string."
639 :group 'org-export-html
640 :type 'function)
642 ;;;; HTML-specific
644 (defcustom org-html-allow-name-attribute-in-anchors t
645 "When nil, do not set \"name\" attribute in anchors.
646 By default, anchors are formatted with both \"id\" and \"name\"
647 attributes, when appropriate."
648 :group 'org-export-html
649 :version "24.4"
650 :package-version '(Org . "8.0")
651 :type 'boolean)
653 ;;;; Inlinetasks
655 (defcustom org-html-format-inlinetask-function nil
656 "Function called to format an inlinetask in HTML code.
658 The function must accept six parameters:
659 TODO the todo keyword, as a string
660 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
661 PRIORITY the inlinetask priority, as a string
662 NAME the inlinetask name, as a string.
663 TAGS the inlinetask tags, as a list of strings.
664 CONTENTS the contents of the inlinetask, as a string.
666 The function should return the string to be exported."
667 :group 'org-export-html
668 :type 'function)
670 ;;;; LaTeX
672 (defcustom org-html-with-latex org-export-with-latex
673 "Non-nil means process LaTeX math snippets.
675 When set, the exporter will process LaTeX environments and
676 fragments.
678 This option can also be set with the +OPTIONS line,
679 e.g. \"tex:mathjax\". Allowed values are:
681 nil Ignore math snippets.
682 `verbatim' Keep everything in verbatim
683 `dvipng' Process the LaTeX fragments to images. This will also
684 include processing of non-math environments.
685 `imagemagick' Convert the LaTeX fragments to pdf files and use
686 imagemagick to convert pdf files to png files.
687 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
688 be loaded.
689 t Synonym for `mathjax'."
690 :group 'org-export-html
691 :version "24.4"
692 :package-version '(Org . "8.0")
693 :type '(choice
694 (const :tag "Do not process math in any way" nil)
695 (const :tag "Use dvipng to make images" dvipng)
696 (const :tag "Use imagemagick to make images" imagemagick)
697 (const :tag "Use MathJax to display math" mathjax)
698 (const :tag "Leave math verbatim" verbatim)))
700 ;;;; Links :: Generic
702 (defcustom org-html-link-org-files-as-html t
703 "Non-nil means make file links to `file.org' point to `file.html'.
704 When `org-mode' is exporting an `org-mode' file to HTML, links to
705 non-html files are directly put into a href tag in HTML.
706 However, links to other Org-mode files (recognized by the
707 extension `.org.) should become links to the corresponding html
708 file, assuming that the linked `org-mode' file will also be
709 converted to HTML.
710 When nil, the links still point to the plain `.org' file."
711 :group 'org-export-html
712 :type 'boolean)
714 ;;;; Links :: Inline images
716 (defcustom org-html-inline-images 'maybe
717 "Non-nil means inline images into exported HTML pages.
718 This is done using an <img> tag. When nil, an anchor with href is used to
719 link to the image. If this option is `maybe', then images in links with
720 an empty description will be inlined, while images with a description will
721 be linked only."
722 :group 'org-export-html
723 :type '(choice (const :tag "Never" nil)
724 (const :tag "Always" t)
725 (const :tag "When there is no description" maybe)))
727 (defcustom org-html-inline-image-rules
728 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
729 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
730 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
731 "Rules characterizing image files that can be inlined into HTML.
732 A rule consists in an association whose key is the type of link
733 to consider, and value is a regexp that will be matched against
734 link's path."
735 :group 'org-export-html
736 :version "24.4"
737 :package-version '(Org . "8.0")
738 :type '(alist :key-type (string :tag "Type")
739 :value-type (regexp :tag "Path")))
741 ;;;; Plain Text
743 (defcustom org-html-protect-char-alist
744 '(("&" . "&amp;")
745 ("<" . "&lt;")
746 (">" . "&gt;"))
747 "Alist of characters to be converted by `org-html-protect'."
748 :group 'org-export-html
749 :type '(repeat (cons (string :tag "Character")
750 (string :tag "HTML equivalent"))))
752 ;;;; Src Block
754 (defcustom org-html-htmlize-output-type 'inline-css
755 "Output type to be used by htmlize when formatting code snippets.
756 Choices are `css', to export the CSS selectors only, or `inline-css', to
757 export the CSS attribute values inline in the HTML. We use as default
758 `inline-css', in order to make the resulting HTML self-containing.
760 However, this will fail when using Emacs in batch mode for export, because
761 then no rich font definitions are in place. It will also not be good if
762 people with different Emacs setup contribute HTML files to a website,
763 because the fonts will represent the individual setups. In these cases,
764 it is much better to let Org/Htmlize assign classes only, and to use
765 a style file to define the look of these classes.
766 To get a start for your css file, start Emacs session and make sure that
767 all the faces you are interested in are defined, for example by loading files
768 in all modes you want. Then, use the command
769 \\[org-html-htmlize-generate-css] to extract class definitions."
770 :group 'org-export-html
771 :type '(choice (const css) (const inline-css)))
773 (defcustom org-html-htmlize-font-prefix "org-"
774 "The prefix for CSS class names for htmlize font specifications."
775 :group 'org-export-html
776 :type 'string)
778 ;;;; Table
780 (defcustom org-html-table-default-attributes
781 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
782 "Default attributes and values which will be used in table tags.
783 This is a plist where attributes are symbols, starting with
784 colons, and values are strings.
786 When exporting to HTML5, these values will be disregarded."
787 :group 'org-export-html
788 :version "24.4"
789 :package-version '(Org . "8.0")
790 :type '(plist :key-type (symbol :tag "Property")
791 :value-type (string :tag "Value")))
793 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
794 "The opening tag for table header fields.
795 This is customizable so that alignment options can be specified.
796 The first %s will be filled with the scope of the field, either row or col.
797 The second %s will be replaced by a style entry to align the field.
798 See also the variable `org-html-table-use-header-tags-for-first-column'.
799 See also the variable `org-html-table-align-individual-fields'."
800 :group 'org-export-html
801 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
803 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
804 "The opening tag for table data fields.
805 This is customizable so that alignment options can be specified.
806 The first %s will be filled with the scope of the field, either row or col.
807 The second %s will be replaced by a style entry to align the field.
808 See also the variable `org-html-table-align-individual-fields'."
809 :group 'org-export-html
810 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
812 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
813 "The opening and ending tags for table rows.
814 This is customizable so that alignment options can be specified.
815 Instead of strings, these can be Lisp forms that will be
816 evaluated for each row in order to construct the table row tags.
818 During evaluation, these variables will be dynamically bound so that
819 you can reuse them:
821 `row-number': row number (0 is the first row)
822 `rowgroup-number': group number of current row
823 `start-rowgroup-p': non-nil means the row starts a group
824 `end-rowgroup-p': non-nil means the row ends a group
825 `top-row-p': non-nil means this is the top row
826 `bottom-row-p': non-nil means this is the bottom row
828 For example:
830 \(setq org-html-table-row-tags
831 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
832 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
833 (t (if (= (mod row-number 2) 1)
834 \"<tr class=\\\"tr-odd\\\">\"
835 \"<tr class=\\\"tr-even\\\">\")))
836 \"</tr>\"))
838 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
839 and the bottom row, and otherwise alternate between \"tr-odd\" and
840 \"tr-even\" for odd and even rows."
841 :group 'org-export-html
842 :type '(cons
843 (choice :tag "Opening tag"
844 (string :tag "Specify")
845 (sexp))
846 (choice :tag "Closing tag"
847 (string :tag "Specify")
848 (sexp))))
850 (defcustom org-html-table-align-individual-fields t
851 "Non-nil means attach style attributes for alignment to each table field.
852 When nil, alignment will only be specified in the column tags, but this
853 is ignored by some browsers (like Firefox, Safari). Opera does it right
854 though."
855 :group 'org-export-html
856 :type 'boolean)
858 (defcustom org-html-table-use-header-tags-for-first-column nil
859 "Non-nil means format column one in tables with header tags.
860 When nil, also column one will use data tags."
861 :group 'org-export-html
862 :type 'boolean)
864 (defcustom org-html-table-caption-above t
865 "When non-nil, place caption string at the beginning of the table.
866 Otherwise, place it near the end."
867 :group 'org-export-html
868 :type 'boolean)
870 ;;;; Tags
872 (defcustom org-html-tag-class-prefix ""
873 "Prefix to class names for TODO keywords.
874 Each tag gets a class given by the tag itself, with this prefix.
875 The default prefix is empty because it is nice to just use the keyword
876 as a class name. But if you get into conflicts with other, existing
877 CSS classes, then this prefix can be very useful."
878 :group 'org-export-html
879 :type 'string)
881 ;;;; Template :: Generic
883 (defcustom org-html-extension "html"
884 "The extension for exported HTML files."
885 :group 'org-export-html
886 :type 'string)
888 (defcustom org-html-xml-declaration
889 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
890 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
891 "The extension for exported HTML files.
892 %s will be replaced with the charset of the exported file.
893 This may be a string, or an alist with export extensions
894 and corresponding declarations.
896 This declaration only applies when exporting to XHTML."
897 :group 'org-export-html
898 :type '(choice
899 (string :tag "Single declaration")
900 (repeat :tag "Dependent on extension"
901 (cons (string :tag "Extension")
902 (string :tag "Declaration")))))
904 (defcustom org-html-coding-system 'utf-8
905 "Coding system for HTML export.
906 Use utf-8 as the default value."
907 :group 'org-export-html
908 :version "24.4"
909 :package-version '(Org . "8.0")
910 :type 'coding-system)
912 (defcustom org-html-doctype "xhtml-strict"
913 "Document type definition to use for exported HTML files.
914 Can be set with the in-buffer HTML_DOCTYPE property or for
915 publishing, with :html-doctype."
916 :group 'org-export-html
917 :version "24.4"
918 :package-version '(Org . "8.0")
919 :type 'string)
921 (defcustom org-html-html5-fancy nil
922 "When exporting to HTML5, set this to t to use new HTML5
923 elements. This variable is ignored for anything other than
924 HTML5.
926 For compatibility with Internet Explorer, it's probably a good
927 idea to download some form of the html5shiv (for instance
928 https://code.google.com/p/html5shiv/) and add it to your
929 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
930 versions 8 and below."
931 :group 'org-export-html
932 :version "24.4"
933 :package-version '(Org . "8.0")
934 :type 'boolean)
936 (defcustom org-html-container-element "div"
937 "HTML element to use for wrapping top level sections.
938 Can be set with the in-buffer HTML_CONTAINER property or for
939 publishing, with :html-container.
941 Note that changing the default will prevent you from using
942 org-info.js for your website."
943 :group 'org-export-html
944 :version "24.4"
945 :package-version '(Org . "8.0")
946 :type 'string)
948 (defcustom org-html-divs
949 '((preamble "div" "preamble")
950 (content "div" "content")
951 (postamble "div" "postamble"))
952 "Alist of the three section elements for HTML export.
953 The car of each entry is one of 'preamble, 'content or 'postamble.
954 The cdrs of each entry are the ELEMENT_TYPE and ID for each
955 section of the exported document.
957 Note that changing the default will prevent you from using
958 org-info.js for your website."
959 :group 'org-export-html
960 :version "24.4"
961 :package-version '(Org . "8.0")
962 :type '(list :greedy t
963 (list :tag "Preamble"
964 (const :format "" preamble)
965 (string :tag "element") (string :tag " id"))
966 (list :tag "Content"
967 (const :format "" content)
968 (string :tag "element") (string :tag " id"))
969 (list :tag "Postamble" (const :format "" postamble)
970 (string :tag " id") (string :tag "element"))))
972 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
973 "Format used for timestamps in preamble, postamble and metadata.
974 See `format-time-string' for more information on its components."
975 :group 'org-export-html
976 :version "24.4"
977 :package-version '(Org . "8.0")
978 :type 'string)
980 ;;;; Template :: Mathjax
982 (defcustom org-html-mathjax-options
983 '((path "http://orgmode.org/mathjax/MathJax.js")
984 (scale "100")
985 (align "center")
986 (indent "2em")
987 (mathml nil))
988 "Options for MathJax setup.
990 path The path where to find MathJax
991 scale Scaling for the HTML-CSS backend, usually between 100 and 133
992 align How to align display math: left, center, or right
993 indent If align is not center, how far from the left/right side?
994 mathml Should a MathML player be used if available?
995 This is faster and reduces bandwidth use, but currently
996 sometimes has lower spacing quality. Therefore, the default is
997 nil. When browsers get better, this switch can be flipped.
999 You can also customize this for each buffer, using something like
1001 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1002 :group 'org-export-html
1003 :type '(list :greedy t
1004 (list :tag "path (the path from where to load MathJax.js)"
1005 (const :format " " path) (string))
1006 (list :tag "scale (scaling for the displayed math)"
1007 (const :format " " scale) (string))
1008 (list :tag "align (alignment of displayed equations)"
1009 (const :format " " align) (string))
1010 (list :tag "indent (indentation with left or right alignment)"
1011 (const :format " " indent) (string))
1012 (list :tag "mathml (should MathML display be used is possible)"
1013 (const :format " " mathml) (boolean))))
1015 (defcustom org-html-mathjax-template
1016 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1017 <script type=\"text/javascript\">
1018 <!--/*--><![CDATA[/*><!--*/
1019 MathJax.Hub.Config({
1020 // Only one of the two following lines, depending on user settings
1021 // First allows browser-native MathML display, second forces HTML/CSS
1022 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1023 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1024 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1025 \"TeX/noUndefined.js\"],
1026 tex2jax: {
1027 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1028 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1029 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1030 ignoreClass: \"tex2jax_ignore\",
1031 processEscapes: false,
1032 processEnvironments: true,
1033 preview: \"TeX\"
1035 showProcessingMessages: true,
1036 displayAlign: \"%ALIGN\",
1037 displayIndent: \"%INDENT\",
1039 \"HTML-CSS\": {
1040 scale: %SCALE,
1041 availableFonts: [\"STIX\",\"TeX\"],
1042 preferredFont: \"TeX\",
1043 webFont: \"TeX\",
1044 imageFont: \"TeX\",
1045 showMathMenu: true,
1047 MMLorHTML: {
1048 prefer: {
1049 MSIE: \"MML\",
1050 Firefox: \"MML\",
1051 Opera: \"HTML\",
1052 other: \"HTML\"
1056 /*]]>*///-->
1057 </script>"
1058 "The MathJax setup for XHTML files."
1059 :group 'org-export-html
1060 :type 'string)
1062 ;;;; Template :: Postamble
1064 (defcustom org-html-postamble 'auto
1065 "Non-nil means insert a postamble in HTML export.
1067 When set to 'auto, check against the
1068 `org-export-with-author/email/creator/date' variables to set the
1069 content of the postamble. When set to a string, use this string
1070 as the postamble. When t, insert a string as defined by the
1071 formatting string in `org-html-postamble-format'.
1073 When set to a function, apply this function and insert the
1074 returned string. The function takes the property list of export
1075 options as its only argument.
1077 Setting :html-postamble in publishing projects will take
1078 precedence over this variable."
1079 :group 'org-export-html
1080 :type '(choice (const :tag "No postamble" nil)
1081 (const :tag "Auto postamble" auto)
1082 (const :tag "Default formatting string" t)
1083 (string :tag "Custom formatting string")
1084 (function :tag "Function (must return a string)")))
1086 (defcustom org-html-postamble-format
1087 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1088 <p class=\"date\">Date: %d</p>
1089 <p class=\"creator\">%c</p>
1090 <p class=\"validation\">%v</p>"))
1091 "Alist of languages and format strings for the HTML postamble.
1093 The first element of each list is the language code, as used for
1094 the LANGUAGE keyword. See `org-export-default-language'.
1096 The second element of each list is a format string to format the
1097 postamble itself. This format string can contain these elements:
1099 %t stands for the title.
1100 %a stands for the author's name.
1101 %e stands for the author's email.
1102 %d stands for the date.
1103 %c will be replaced by `org-html-creator-string'.
1104 %v will be replaced by `org-html-validation-link'.
1105 %T will be replaced by the export time.
1106 %C will be replaced by the last modification time.
1108 If you need to use a \"%\" character, you need to escape it
1109 like that: \"%%\"."
1110 :group 'org-export-html
1111 :type '(repeat
1112 (list (string :tag "Language")
1113 (string :tag "Format string"))))
1115 (defcustom org-html-validation-link
1116 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1117 "Link to HTML validation service."
1118 :group 'org-export-html
1119 :type 'string)
1121 (defcustom org-html-creator-string
1122 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1123 emacs-version
1124 (if (fboundp 'org-version) (org-version) "unknown version"))
1125 "Information about the creator of the HTML document.
1126 This option can also be set on with the CREATOR keyword."
1127 :group 'org-export-html
1128 :type '(string :tag "Creator string"))
1130 ;;;; Template :: Preamble
1132 (defcustom org-html-preamble t
1133 "Non-nil means insert a preamble in HTML export.
1135 When t, insert a string as defined by the formatting string in
1136 `org-html-preamble-format'. When set to a string, use this
1137 formatting string instead (see `org-html-postamble-format' for an
1138 example of such a formatting string).
1140 When set to a function, apply this function and insert the
1141 returned string. The function takes the property list of export
1142 options as its only argument.
1144 Setting :html-preamble in publishing projects will take
1145 precedence over this variable."
1146 :group 'org-export-html
1147 :type '(choice (const :tag "No preamble" nil)
1148 (const :tag "Default preamble" t)
1149 (string :tag "Custom formatting string")
1150 (function :tag "Function (must return a string)")))
1152 (defcustom org-html-preamble-format '(("en" ""))
1153 "Alist of languages and format strings for the HTML preamble.
1155 The first element of each list is the language code, as used for
1156 the LANGUAGE keyword. See `org-export-default-language'.
1158 The second element of each list is a format string to format the
1159 preamble itself. This format string can contain these elements:
1161 %t stands for the title.
1162 %a stands for the author's name.
1163 %e stands for the author's email.
1164 %d stands for the date.
1165 %c will be replaced by `org-html-creator-string'.
1166 %v will be replaced by `org-html-validation-link'.
1167 %T will be replaced by the export time.
1168 %C will be replaced by the last modification time.
1170 If you need to use a \"%\" character, you need to escape it
1171 like that: \"%%\".
1173 See the default value of `org-html-postamble-format' for an
1174 example."
1175 :group 'org-export-html
1176 :type '(repeat
1177 (list (string :tag "Language")
1178 (string :tag "Format string"))))
1180 (defcustom org-html-link-up ""
1181 "Where should the \"UP\" link of exported HTML pages lead?"
1182 :group 'org-export-html
1183 :type '(string :tag "File or URL"))
1185 (defcustom org-html-link-home ""
1186 "Where should the \"HOME\" link of exported HTML pages lead?"
1187 :group 'org-export-html
1188 :type '(string :tag "File or URL"))
1190 (defcustom org-html-home/up-format
1191 "<div id=\"org-div-home-and-up\">
1192 <a accesskey=\"h\" href=\"%s\"> UP </a>
1194 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1195 </div>"
1196 "Snippet used to insert the HOME and UP links.
1197 This is a format string, the first %s will receive the UP link,
1198 the second the HOME link. If both `org-html-link-up' and
1199 `org-html-link-home' are empty, the entire snippet will be
1200 ignored."
1201 :group 'org-export-html
1202 :type 'string)
1204 ;;;; Template :: Scripts
1206 (define-obsolete-variable-alias
1207 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1208 (defcustom org-html-head-include-scripts t
1209 "Non-nil means include the JavaScript snippets in exported HTML files.
1210 The actual script is defined in `org-html-scripts' and should
1211 not be modified."
1212 :group 'org-export-html
1213 :version "24.4"
1214 :package-version '(Org . "8.0")
1215 :type 'boolean)
1217 ;;;; Template :: Styles
1219 (define-obsolete-variable-alias
1220 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1221 (defcustom org-html-head-include-default-style t
1222 "Non-nil means include the default style in exported HTML files.
1223 The actual style is defined in `org-html-style-default' and
1224 should not be modified. Use `org-html-head' to use your own
1225 style information."
1226 :group 'org-export-html
1227 :version "24.4"
1228 :package-version '(Org . "8.0")
1229 :type 'boolean)
1230 ;;;###autoload
1231 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1233 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1234 (defcustom org-html-head ""
1235 "Org-wide head definitions for exported HTML files.
1237 This variable can contain the full HTML structure to provide a
1238 style, including the surrounding HTML tags. You can consider
1239 including definitions for the following classes: title, todo,
1240 done, timestamp, timestamp-kwd, tag, target.
1242 For example, a valid value would be:
1244 <style type=\"text/css\">
1245 <![CDATA[
1246 p { font-weight: normal; color: gray; }
1247 h1 { color: black; }
1248 .title { text-align: center; }
1249 .todo, .timestamp-kwd { color: red; }
1250 .done { color: green; }
1252 </style>
1254 If you want to refer to an external style, use something like
1256 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1258 As the value of this option simply gets inserted into the HTML
1259 <head> header, you can use it to add any arbitrary text to the
1260 header.
1262 You can set this on a per-file basis using #+HTML_HEAD:,
1263 or for publication projects using the :html-head property."
1264 :group 'org-export-html
1265 :version "24.4"
1266 :package-version '(Org . "8.0")
1267 :type 'string)
1268 ;;;###autoload
1269 (put 'org-html-head 'safe-local-variable 'stringp)
1271 (defcustom org-html-head-extra ""
1272 "More head information to add in the HTML output.
1274 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1275 or for publication projects using the :html-head-extra property."
1276 :group 'org-export-html
1277 :version "24.4"
1278 :package-version '(Org . "8.0")
1279 :type 'string)
1280 ;;;###autoload
1281 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1283 ;;;; Todos
1285 (defcustom org-html-todo-kwd-class-prefix ""
1286 "Prefix to class names for TODO keywords.
1287 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1288 The default prefix is empty because it is nice to just use the keyword
1289 as a class name. But if you get into conflicts with other, existing
1290 CSS classes, then this prefix can be very useful."
1291 :group 'org-export-html
1292 :type 'string)
1295 ;;; Internal Functions
1297 (defun org-html-xhtml-p (info)
1298 (let ((dt (downcase (plist-get info :html-doctype))))
1299 (string-match-p "xhtml" dt)))
1301 (defun org-html-html5-p (info)
1302 (let ((dt (downcase (plist-get info :html-doctype))))
1303 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1305 (defun org-html-close-tag (tag attr info)
1306 (concat "<" tag " " attr
1307 (if (org-html-xhtml-p info) " />" ">")))
1309 (defun org-html-doctype (info)
1310 "Return correct html doctype tag from `org-html-doctype-alist',
1311 or the literal value of :html-doctype from INFO if :html-doctype
1312 is not found in the alist.
1313 INFO is a plist used as a communication channel."
1314 (let ((dt (plist-get info :html-doctype)))
1315 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1317 (defun org-html--make-attribute-string (attributes)
1318 "Return a list of attributes, as a string.
1319 ATTRIBUTES is a plist where values are either strings or nil. An
1320 attributes with a nil value will be omitted from the result."
1321 (let (output)
1322 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1323 (cond ((null item) (pop output))
1324 ((symbolp item) (push (substring (symbol-name item) 1) output))
1325 (t (let ((key (car output))
1326 (value (replace-regexp-in-string
1327 "\"" "&quot;" (org-html-encode-plain-text item))))
1328 (setcar output (format "%s=\"%s\"" key value))))))))
1330 (defun org-html-format-inline-image (src info &optional
1331 caption label attr standalone-p)
1332 "Format an inline image from SRC.
1333 CAPTION, LABEL and ATTR are optional arguments providing the
1334 caption, the label and the attribute of the image.
1335 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1336 (let* ((id (if (not label) ""
1337 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1338 (attr (concat attr
1339 (format " src=\"%s\"" src)
1340 (cond
1341 ((string-match "\\<alt=" (or attr "")) "")
1342 ((string-match "^ltxpng/" src)
1343 (format " alt=\"%s\""
1344 (org-html-encode-plain-text
1345 (org-find-text-property-in-string
1346 'org-latex-src src))))
1347 (t (format " alt=\"%s\""
1348 (file-name-nondirectory src))))))
1349 (html5-fancy (and (org-html-html5-p info)
1350 (plist-get info :html-html5-fancy))))
1351 (cond
1352 (standalone-p
1353 (let ((img (org-html-close-tag "img" attr info)))
1354 (format (if html5-fancy
1355 "\n<figure%s>%s%s\n</figure>"
1356 "\n<div%s class=\"figure\">%s%s\n</div>")
1357 id (format "\n<p>%s</p>" img)
1358 (if (and caption (not (string= caption "")))
1359 (format (if html5-fancy
1360 "\n<figcaption>%s</figcaption>"
1361 "\n<p>%s</p>") caption) ""))))
1362 (t (org-html-close-tag "img" (concat attr id) info)))))
1364 (defun org-html--textarea-block (element)
1365 "Transcode ELEMENT into a textarea block.
1366 ELEMENT is either a src block or an example block."
1367 (let* ((code (car (org-export-unravel-code element)))
1368 (attr (org-export-read-attribute :attr_html element)))
1369 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1370 (or (plist-get attr :width) 80)
1371 (or (plist-get attr :height) (org-count-lines code))
1372 code)))
1374 ;;;; Table
1376 (defun org-html-htmlize-region-for-paste (beg end)
1377 "Convert the region between BEG and END to HTML, using htmlize.el.
1378 This is much like `htmlize-region-for-paste', only that it uses
1379 the settings define in the org-... variables."
1380 (let* ((htmlize-output-type org-html-htmlize-output-type)
1381 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1382 (htmlbuf (htmlize-region beg end)))
1383 (unwind-protect
1384 (with-current-buffer htmlbuf
1385 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1386 (plist-get htmlize-buffer-places 'content-end)))
1387 (kill-buffer htmlbuf))))
1389 ;;;###autoload
1390 (defun org-html-htmlize-generate-css ()
1391 "Create the CSS for all font definitions in the current Emacs session.
1392 Use this to create face definitions in your CSS style file that can then
1393 be used by code snippets transformed by htmlize.
1394 This command just produces a buffer that contains class definitions for all
1395 faces used in the current Emacs session. You can copy and paste the ones you
1396 need into your CSS file.
1398 If you then set `org-html-htmlize-output-type' to `css', calls
1399 to the function `org-html-htmlize-region-for-paste' will
1400 produce code that uses these same face definitions."
1401 (interactive)
1402 (require 'htmlize)
1403 (and (get-buffer "*html*") (kill-buffer "*html*"))
1404 (with-temp-buffer
1405 (let ((fl (face-list))
1406 (htmlize-css-name-prefix "org-")
1407 (htmlize-output-type 'css)
1408 f i)
1409 (while (setq f (pop fl)
1410 i (and f (face-attribute f :inherit)))
1411 (when (and (symbolp f) (or (not i) (not (listp i))))
1412 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1413 (htmlize-region (point-min) (point-max))))
1414 (org-pop-to-buffer-same-window "*html*")
1415 (goto-char (point-min))
1416 (if (re-search-forward "<style" nil t)
1417 (delete-region (point-min) (match-beginning 0)))
1418 (if (re-search-forward "</style>" nil t)
1419 (delete-region (1+ (match-end 0)) (point-max)))
1420 (beginning-of-line 1)
1421 (if (looking-at " +") (replace-match ""))
1422 (goto-char (point-min)))
1424 (defun org-html--make-string (n string)
1425 "Build a string by concatenating N times STRING."
1426 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1428 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1429 "Turn todo keyword KWD into a valid class name.
1430 Replaces invalid characters with \"_\"."
1431 (save-match-data
1432 (while (string-match "[^a-zA-Z0-9_]" kwd)
1433 (setq kwd (replace-match "_" t t kwd))))
1434 kwd)
1436 (defun org-html-format-footnote-reference (n def refcnt)
1437 "Format footnote reference N with definition DEF into HTML."
1438 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1439 (format org-html-footnote-format
1440 (let* ((id (format "fnr.%s%s" n extra))
1441 (href (format " href=\"#fn.%s\"" n))
1442 (attributes (concat " class=\"footref\"" href)))
1443 (org-html--anchor id n attributes)))))
1445 (defun org-html-format-footnotes-section (section-name definitions)
1446 "Format footnotes section SECTION-NAME."
1447 (if (not definitions) ""
1448 (format org-html-footnotes-section section-name definitions)))
1450 (defun org-html-format-footnote-definition (fn)
1451 "Format the footnote definition FN."
1452 (let ((n (car fn)) (def (cdr fn)))
1453 (format
1454 "<div class=\"footdef\">%s %s</div>\n"
1455 (format org-html-footnote-format
1456 (let* ((id (format "fn.%s" n))
1457 (href (format " href=\"#fnr.%s\"" n))
1458 (attributes (concat " class=\"footnum\"" href)))
1459 (org-html--anchor id n attributes)))
1460 def)))
1462 (defun org-html-footnote-section (info)
1463 "Format the footnote section.
1464 INFO is a plist used as a communication channel."
1465 (let* ((fn-alist (org-export-collect-footnote-definitions
1466 (plist-get info :parse-tree) info))
1467 (fn-alist
1468 (loop for (n type raw) in fn-alist collect
1469 (cons n (if (eq (org-element-type raw) 'org-data)
1470 (org-trim (org-export-data raw info))
1471 (format "<p>%s</p>"
1472 (org-trim (org-export-data raw info))))))))
1473 (when fn-alist
1474 (org-html-format-footnotes-section
1475 (org-html--translate "Footnotes" info)
1476 (format
1477 "\n%s\n"
1478 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1481 ;;; Template
1483 (defun org-html--build-meta-info (info)
1484 "Return meta tags for exported document.
1485 INFO is a plist used as a communication channel."
1486 (let ((protect-string
1487 (lambda (str)
1488 (replace-regexp-in-string
1489 "\"" "&quot;" (org-html-encode-plain-text str))))
1490 (title (org-export-data (plist-get info :title) info))
1491 (author (and (plist-get info :with-author)
1492 (let ((auth (plist-get info :author)))
1493 (and auth
1494 ;; Return raw Org syntax, skipping non
1495 ;; exportable objects.
1496 (org-element-interpret-data
1497 (org-element-map auth
1498 (cons 'plain-text org-element-all-objects)
1499 'identity info))))))
1500 (description (plist-get info :description))
1501 (keywords (plist-get info :keywords))
1502 (charset (or (and org-html-coding-system
1503 (fboundp 'coding-system-get)
1504 (coding-system-get org-html-coding-system
1505 'mime-charset))
1506 "iso-8859-1")))
1507 (concat
1508 (format "<title>%s</title>\n" title)
1509 (when (plist-get info :time-stamp-file)
1510 (format-time-string
1511 (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
1512 (format
1513 (if (org-html-html5-p info)
1514 (org-html-close-tag "meta" " charset=\"%s\"" info)
1515 (org-html-close-tag
1516 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1517 info))
1518 charset) "\n"
1519 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1520 "\n"
1521 (and (org-string-nw-p author)
1522 (org-html-close-tag "meta"
1523 (format " name=\"author\" content=\"%s\""
1524 (funcall protect-string author))
1525 info)
1526 "\n")
1527 (and (org-string-nw-p description)
1528 (org-html-close-tag "meta"
1529 (format " name=\"description\" content=\"%s\"\n"
1530 (funcall protect-string description))
1531 info)
1532 "\n")
1533 (and (org-string-nw-p keywords)
1534 (org-html-close-tag "meta"
1535 (format " name=\"keywords\" content=\"%s\""
1536 (funcall protect-string keywords))
1537 info)
1538 "\n"))))
1540 (defun org-html--build-head (info)
1541 "Return information for the <head>..</head> of the HTML output.
1542 INFO is a plist used as a communication channel."
1543 (org-element-normalize-string
1544 (concat
1545 (when (plist-get info :html-head-include-default-style)
1546 (org-element-normalize-string org-html-style-default))
1547 (org-element-normalize-string (plist-get info :html-head))
1548 (org-element-normalize-string (plist-get info :html-head-extra))
1549 (when (and (plist-get info :html-htmlized-css-url)
1550 (eq org-html-htmlize-output-type 'css))
1551 (org-html-close-tag "link"
1552 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1553 (plist-get info :html-htmlized-css-url))
1554 info))
1555 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1557 (defun org-html--build-mathjax-config (info)
1558 "Insert the user setup into the mathjax template.
1559 INFO is a plist used as a communication channel."
1560 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1561 (org-element-map (plist-get info :parse-tree)
1562 '(latex-fragment latex-environment) 'identity info t))
1563 (let ((template org-html-mathjax-template)
1564 (options org-html-mathjax-options)
1565 (in-buffer (or (plist-get info :html-mathjax) ""))
1566 name val (yes " ") (no "// ") x)
1567 (mapc
1568 (lambda (e)
1569 (setq name (car e) val (nth 1 e))
1570 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1571 (setq val (car (read-from-string
1572 (substring in-buffer (match-end 0))))))
1573 (if (not (stringp val)) (setq val (format "%s" val)))
1574 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1575 (setq template (replace-match val t t template))))
1576 options)
1577 (setq val (nth 1 (assq 'mathml options)))
1578 (if (string-match (concat "\\<mathml:") in-buffer)
1579 (setq val (car (read-from-string
1580 (substring in-buffer (match-end 0))))))
1581 ;; Exchange prefixes depending on mathml setting.
1582 (if (not val) (setq x yes yes no no x))
1583 ;; Replace cookies to turn on or off the config/jax lines.
1584 (if (string-match ":MMLYES:" template)
1585 (setq template (replace-match yes t t template)))
1586 (if (string-match ":MMLNO:" template)
1587 (setq template (replace-match no t t template)))
1588 ;; Return the modified template.
1589 (org-element-normalize-string template))))
1591 (defun org-html-format-spec (info)
1592 "Return format specification for elements that can be
1593 used in the preamble or postamble."
1594 `((?t . ,(org-export-data (plist-get info :title) info))
1595 (?d . ,(org-export-data (org-export-get-date info) info))
1596 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1597 (?a . ,(org-export-data (plist-get info :author) info))
1598 (?e . ,(mapconcat
1599 (lambda (e)
1600 (format "<a href=\"mailto:%s\">%s</a>" e e))
1601 (split-string (plist-get info :email) ",+ *")
1602 ", "))
1603 (?c . ,(plist-get info :creator))
1604 (?C . ,(let ((file (plist-get info :input-file)))
1605 (format-time-string org-html-metadata-timestamp-format
1606 (if file (nth 5 (file-attributes file))
1607 (current-time)))))
1608 (?v . ,(or org-html-validation-link ""))))
1610 (defun org-html--build-pre/postamble (type info)
1611 "Return document preamble or postamble as a string, or nil.
1612 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1613 communication channel."
1614 (let ((section (plist-get info (intern (format ":html-%s" type))))
1615 (spec (org-html-format-spec info)))
1616 (when section
1617 (let ((section-contents
1618 (if (functionp section) (funcall section info)
1619 (cond
1620 ((stringp section) (format-spec section spec))
1621 ((eq section 'auto)
1622 (let ((date (cdr (assq ?d spec)))
1623 (author (cdr (assq ?a spec)))
1624 (email (cdr (assq ?e spec)))
1625 (creator (cdr (assq ?c spec)))
1626 (timestamp (cdr (assq ?T spec)))
1627 (validation-link (cdr (assq ?v spec))))
1628 (concat
1629 (when (and (plist-get info :with-date)
1630 (org-string-nw-p date))
1631 (format "<p class=\"date\">%s: %s</p>\n"
1632 (org-html--translate "Date" info)
1633 date))
1634 (when (and (plist-get info :with-author)
1635 (org-string-nw-p author))
1636 (format "<p class=\"author\">%s: %s</p>\n"
1637 (org-html--translate "Author" info)
1638 author))
1639 (when (and (plist-get info :with-email)
1640 (org-string-nw-p email))
1641 (format "<p class=\"email\">%s: %s</p>\n"
1642 (org-html--translate "Email" info)
1643 email))
1644 (when (plist-get info :time-stamp-file)
1645 (format
1646 "<p class=\"date\">%s: %s</p>\n"
1647 (org-html--translate "Created" info)
1648 (format-time-string org-html-metadata-timestamp-format)))
1649 (when (plist-get info :with-creator)
1650 (format "<p class=\"creator\">%s</p>\n" creator))
1651 (format "<p class=\"validation\">%s</p>\n"
1652 validation-link))))
1653 (t (format-spec
1654 (or (cadr (assoc
1655 (plist-get info :language)
1656 (eval (intern
1657 (format "org-html-%s-format" type)))))
1658 (cadr
1659 (assoc
1660 "en"
1661 (eval
1662 (intern (format "org-html-%s-format" type))))))
1663 spec))))))
1664 (when (org-string-nw-p section-contents)
1665 (concat
1666 (format "<%s id=\"%s\" class=\"%s\">\n"
1667 (nth 1 (assq type org-html-divs))
1668 (nth 2 (assq type org-html-divs))
1669 org-html--pre/postamble-class)
1670 (org-element-normalize-string section-contents)
1671 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1673 (defun org-html-inner-template (contents info)
1674 "Return body of document string after HTML conversion.
1675 CONTENTS is the transcoded contents string. INFO is a plist
1676 holding export options."
1677 (concat
1678 ;; Table of contents.
1679 (let ((depth (plist-get info :with-toc)))
1680 (when depth (org-html-toc depth info)))
1681 ;; Document contents.
1682 contents
1683 ;; Footnotes section.
1684 (org-html-footnote-section info)))
1686 (defun org-html-template (contents info)
1687 "Return complete document string after HTML conversion.
1688 CONTENTS is the transcoded contents string. INFO is a plist
1689 holding export options."
1690 (concat
1691 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1692 (let ((decl (or (and (stringp org-html-xml-declaration)
1693 org-html-xml-declaration)
1694 (cdr (assoc (plist-get info :html-extension)
1695 org-html-xml-declaration))
1696 (cdr (assoc "html" org-html-xml-declaration))
1698 "")))
1699 (when (not (or (eq nil decl) (string= "" decl)))
1700 (format "%s\n"
1701 (format decl
1702 (or (and org-html-coding-system
1703 (fboundp 'coding-system-get)
1704 (coding-system-get org-html-coding-system 'mime-charset))
1705 "iso-8859-1"))))))
1706 (org-html-doctype info)
1707 "\n"
1708 (concat "<html"
1709 (when (org-html-xhtml-p info)
1710 (format
1711 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1712 (plist-get info :language) (plist-get info :language)))
1713 ">\n")
1714 "<head>\n"
1715 (org-html--build-meta-info info)
1716 (org-html--build-head info)
1717 (org-html--build-mathjax-config info)
1718 "</head>\n"
1719 "<body>\n"
1720 (let ((link-up (org-trim (plist-get info :html-link-up)))
1721 (link-home (org-trim (plist-get info :html-link-home))))
1722 (unless (and (string= link-up "") (string= link-up ""))
1723 (format org-html-home/up-format
1724 (or link-up link-home)
1725 (or link-home link-up))))
1726 ;; Preamble.
1727 (org-html--build-pre/postamble 'preamble info)
1728 ;; Document contents.
1729 (format "<%s id=\"%s\">\n"
1730 (nth 1 (assq 'content org-html-divs))
1731 (nth 2 (assq 'content org-html-divs)))
1732 ;; Document title.
1733 (let ((title (plist-get info :title)))
1734 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1735 contents
1736 (format "</%s>\n"
1737 (nth 1 (assq 'content org-html-divs)))
1738 ;; Postamble.
1739 (org-html--build-pre/postamble 'postamble info)
1740 ;; Closing document.
1741 "</body>\n</html>"))
1743 (defun org-html--translate (s info)
1744 "Translate string S according to specified language.
1745 INFO is a plist used as a communication channel."
1746 (org-export-translate s :html info))
1748 ;;;; Anchor
1750 (defun org-html--anchor (&optional id desc attributes)
1751 "Format a HTML anchor."
1752 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1753 (attributes (concat (and id (format " id=\"%s\"" id))
1754 (and name (format " name=\"%s\"" name))
1755 attributes)))
1756 (format "<a%s>%s</a>" attributes (or desc ""))))
1758 ;;;; Todo
1760 (defun org-html--todo (todo)
1761 "Format TODO keywords into HTML."
1762 (when todo
1763 (format "<span class=\"%s %s%s\">%s</span>"
1764 (if (member todo org-done-keywords) "done" "todo")
1765 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1766 todo)))
1768 ;;;; Tags
1770 (defun org-html--tags (tags)
1771 "Format TAGS into HTML."
1772 (when tags
1773 (format "<span class=\"tag\">%s</span>"
1774 (mapconcat
1775 (lambda (tag)
1776 (format "<span class=\"%s\">%s</span>"
1777 (concat org-html-tag-class-prefix
1778 (org-html-fix-class-name tag))
1779 tag))
1780 tags "&#xa0;"))))
1782 ;;;; Headline
1784 (defun* org-html-format-headline
1785 (todo todo-type priority text tags
1786 &key level section-number headline-label &allow-other-keys)
1787 "Format a headline in HTML."
1788 (let ((section-number
1789 (when section-number
1790 (format "<span class=\"section-number-%d\">%s</span> "
1791 level section-number)))
1792 (todo (org-html--todo todo))
1793 (tags (org-html--tags tags)))
1794 (concat section-number todo (and todo " ") text
1795 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1797 ;;;; Src Code
1799 (defun org-html-fontify-code (code lang)
1800 "Color CODE with htmlize library.
1801 CODE is a string representing the source code to colorize. LANG
1802 is the language used for CODE, as a string, or nil."
1803 (when code
1804 (cond
1805 ;; Case 1: No lang. Possibly an example block.
1806 ((not lang)
1807 ;; Simple transcoding.
1808 (org-html-encode-plain-text code))
1809 ;; Case 2: No htmlize or an inferior version of htmlize
1810 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1811 ;; Emit a warning.
1812 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1813 ;; Simple transcoding.
1814 (org-html-encode-plain-text code))
1816 ;; Map language
1817 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1818 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1819 (cond
1820 ;; Case 1: Language is not associated with any Emacs mode
1821 ((not (functionp lang-mode))
1822 ;; Simple transcoding.
1823 (org-html-encode-plain-text code))
1824 ;; Case 2: Default. Fontify code.
1826 ;; htmlize
1827 (setq code (with-temp-buffer
1828 ;; Switch to language-specific mode.
1829 (funcall lang-mode)
1830 (insert code)
1831 ;; Fontify buffer.
1832 (font-lock-fontify-buffer)
1833 ;; Remove formatting on newline characters.
1834 (save-excursion
1835 (let ((beg (point-min))
1836 (end (point-max)))
1837 (goto-char beg)
1838 (while (progn (end-of-line) (< (point) end))
1839 (put-text-property (point) (1+ (point)) 'face nil)
1840 (forward-char 1))))
1841 (org-src-mode)
1842 (set-buffer-modified-p nil)
1843 ;; Htmlize region.
1844 (org-html-htmlize-region-for-paste
1845 (point-min) (point-max))))
1846 ;; Strip any enclosing <pre></pre> tags.
1847 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1848 (end (and beg (string-match "</pre>\\'" code))))
1849 (if (and beg end) (substring code beg end) code)))))))))
1851 (defun org-html-do-format-code
1852 (code &optional lang refs retain-labels num-start)
1853 "Format CODE string as source code.
1854 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1855 respectively, the language of the source code, as a string, an
1856 alist between line numbers and references (as returned by
1857 `org-export-unravel-code'), a boolean specifying if labels should
1858 appear in the source code, and the number associated to the first
1859 line of code."
1860 (let* ((code-lines (org-split-string code "\n"))
1861 (code-length (length code-lines))
1862 (num-fmt
1863 (and num-start
1864 (format "%%%ds: "
1865 (length (number-to-string (+ code-length num-start))))))
1866 (code (org-html-fontify-code code lang)))
1867 (org-export-format-code
1868 code
1869 (lambda (loc line-num ref)
1870 (setq loc
1871 (concat
1872 ;; Add line number, if needed.
1873 (when num-start
1874 (format "<span class=\"linenr\">%s</span>"
1875 (format num-fmt line-num)))
1876 ;; Transcoded src line.
1878 ;; Add label, if needed.
1879 (when (and ref retain-labels) (format " (%s)" ref))))
1880 ;; Mark transcoded line as an anchor, if needed.
1881 (if (not ref) loc
1882 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1883 ref loc)))
1884 num-start refs)))
1886 (defun org-html-format-code (element info)
1887 "Format contents of ELEMENT as source code.
1888 ELEMENT is either an example block or a src block. INFO is
1889 a plist used as a communication channel."
1890 (let* ((lang (org-element-property :language element))
1891 ;; Extract code and references.
1892 (code-info (org-export-unravel-code element))
1893 (code (car code-info))
1894 (refs (cdr code-info))
1895 ;; Does the src block contain labels?
1896 (retain-labels (org-element-property :retain-labels element))
1897 ;; Does it have line numbers?
1898 (num-start (case (org-element-property :number-lines element)
1899 (continued (org-export-get-loc element info))
1900 (new 0))))
1901 (org-html-do-format-code code lang refs retain-labels num-start)))
1904 ;;; Tables of Contents
1906 (defun org-html-toc (depth info)
1907 "Build a table of contents.
1908 DEPTH is an integer specifying the depth of the table. INFO is a
1909 plist used as a communication channel. Return the table of
1910 contents as a string, or nil if it is empty."
1911 (let ((toc-entries
1912 (mapcar (lambda (headline)
1913 (cons (org-html--format-toc-headline headline info)
1914 (org-export-get-relative-level headline info)))
1915 (org-export-collect-headlines info depth))))
1916 (when toc-entries
1917 (concat "<div id=\"table-of-contents\">\n"
1918 (format "<h%d>%s</h%d>\n"
1919 org-html-toplevel-hlevel
1920 (org-html--translate "Table of Contents" info)
1921 org-html-toplevel-hlevel)
1922 "<div id=\"text-table-of-contents\">"
1923 (org-html--toc-text toc-entries)
1924 "</div>\n"
1925 "</div>\n"))))
1927 (defun org-html--toc-text (toc-entries)
1928 "Return innards of a table of contents, as a string.
1929 TOC-ENTRIES is an alist where key is an entry title, as a string,
1930 and value is its relative level, as an integer."
1931 (let* ((prev-level (1- (cdar toc-entries)))
1932 (start-level prev-level))
1933 (concat
1934 (mapconcat
1935 (lambda (entry)
1936 (let ((headline (car entry))
1937 (level (cdr entry)))
1938 (concat
1939 (let* ((cnt (- level prev-level))
1940 (times (if (> cnt 0) (1- cnt) (- cnt)))
1941 rtn)
1942 (setq prev-level level)
1943 (concat
1944 (org-html--make-string
1945 times (cond ((> cnt 0) "\n<ul>\n<li>")
1946 ((< cnt 0) "</li>\n</ul>\n")))
1947 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1948 headline)))
1949 toc-entries "")
1950 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1952 (defun org-html--format-toc-headline (headline info)
1953 "Return an appropriate table of contents entry for HEADLINE.
1954 INFO is a plist used as a communication channel."
1955 (let* ((headline-number (org-export-get-headline-number headline info))
1956 (section-number
1957 (and (not (org-export-low-level-p headline info))
1958 (org-export-numbered-headline-p headline info)
1959 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1960 (tags (and (eq (plist-get info :with-tags) t)
1961 (org-export-get-tags headline info))))
1962 (format "<a href=\"#%s\">%s</a>"
1963 ;; Label.
1964 (org-export-solidify-link-text
1965 (or (org-element-property :CUSTOM_ID headline)
1966 (concat "sec-" (mapconcat 'number-to-string
1967 headline-number "-"))))
1968 ;; Body.
1969 (concat section-number
1970 (org-export-data-with-translations
1971 (org-export-get-alt-title headline info)
1972 ;; Ignore any footnote-reference, link,
1973 ;; radio-target and target in table of contents.
1974 (append
1975 '((footnote-reference . ignore)
1976 (link . (lambda (link desc i) desc))
1977 (radio-target . (lambda (radio desc i) desc))
1978 (target . ignore))
1979 (org-export-backend-translate-table 'html))
1980 info)
1981 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1983 (defun org-html-list-of-listings (info)
1984 "Build a list of listings.
1985 INFO is a plist used as a communication channel. Return the list
1986 of listings as a string, or nil if it is empty."
1987 (let ((lol-entries (org-export-collect-listings info)))
1988 (when lol-entries
1989 (concat "<div id=\"list-of-listings\">\n"
1990 (format "<h%d>%s</h%d>\n"
1991 org-html-toplevel-hlevel
1992 (org-html--translate "List of Listings" info)
1993 org-html-toplevel-hlevel)
1994 "<div id=\"text-list-of-listings\">\n<ul>\n"
1995 (let ((count 0)
1996 (initial-fmt (org-html--translate "Listing %d:" info)))
1997 (mapconcat
1998 (lambda (entry)
1999 (let ((label (org-element-property :name entry))
2000 (title (org-trim
2001 (org-export-data
2002 (or (org-export-get-caption entry t)
2003 (org-export-get-caption entry))
2004 info))))
2005 (concat
2006 "<li>"
2007 (if (not label)
2008 (concat (format initial-fmt (incf count)) " " title)
2009 (format "<a href=\"#%s\">%s %s</a>"
2010 (org-export-solidify-link-text label)
2011 (format initial-fmt (incf count))
2012 title))
2013 "</li>")))
2014 lol-entries "\n"))
2015 "\n</ul>\n</div>\n</div>"))))
2017 (defun org-html-list-of-tables (info)
2018 "Build a list of tables.
2019 INFO is a plist used as a communication channel. Return the list
2020 of tables as a string, or nil if it is empty."
2021 (let ((lol-entries (org-export-collect-tables info)))
2022 (when lol-entries
2023 (concat "<div id=\"list-of-tables\">\n"
2024 (format "<h%d>%s</h%d>\n"
2025 org-html-toplevel-hlevel
2026 (org-html--translate "List of Tables" info)
2027 org-html-toplevel-hlevel)
2028 "<div id=\"text-list-of-tables\">\n<ul>\n"
2029 (let ((count 0)
2030 (initial-fmt (org-html--translate "Table %d:" info)))
2031 (mapconcat
2032 (lambda (entry)
2033 (let ((label (org-element-property :name entry))
2034 (title (org-trim
2035 (org-export-data
2036 (or (org-export-get-caption entry t)
2037 (org-export-get-caption entry))
2038 info))))
2039 (concat
2040 "<li>"
2041 (if (not label)
2042 (concat (format initial-fmt (incf count)) " " title)
2043 (format "<a href=\"#%s\">%s %s</a>"
2044 (org-export-solidify-link-text label)
2045 (format initial-fmt (incf count))
2046 title))
2047 "</li>")))
2048 lol-entries "\n"))
2049 "\n</ul>\n</div>\n</div>"))))
2052 ;;; Transcode Functions
2054 ;;;; Bold
2056 (defun org-html-bold (bold contents info)
2057 "Transcode BOLD from Org to HTML.
2058 CONTENTS is the text with bold markup. INFO is a plist holding
2059 contextual information."
2060 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
2061 contents))
2063 ;;;; Center Block
2065 (defun org-html-center-block (center-block contents info)
2066 "Transcode a CENTER-BLOCK element from Org to HTML.
2067 CONTENTS holds the contents of the block. INFO is a plist
2068 holding contextual information."
2069 (format "<div class=\"center\">\n%s</div>" contents))
2071 ;;;; Clock
2073 (defun org-html-clock (clock contents info)
2074 "Transcode a CLOCK element from Org to HTML.
2075 CONTENTS is nil. INFO is a plist used as a communication
2076 channel."
2077 (format "<p>
2078 <span class=\"timestamp-wrapper\">
2079 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2080 </span>
2081 </p>"
2082 org-clock-string
2083 (org-translate-time
2084 (org-element-property :raw-value
2085 (org-element-property :value clock)))
2086 (let ((time (org-element-property :duration clock)))
2087 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2089 ;;;; Code
2091 (defun org-html-code (code contents info)
2092 "Transcode CODE from Org to HTML.
2093 CONTENTS is nil. INFO is a plist holding contextual
2094 information."
2095 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2096 (org-html-encode-plain-text (org-element-property :value code))))
2098 ;;;; Drawer
2100 (defun org-html-drawer (drawer contents info)
2101 "Transcode a DRAWER element from Org to HTML.
2102 CONTENTS holds the contents of the block. INFO is a plist
2103 holding contextual information."
2104 (if (functionp org-html-format-drawer-function)
2105 (funcall org-html-format-drawer-function
2106 (org-element-property :drawer-name drawer)
2107 contents)
2108 ;; If there's no user defined function: simply
2109 ;; display contents of the drawer.
2110 contents))
2112 ;;;; Dynamic Block
2114 (defun org-html-dynamic-block (dynamic-block contents info)
2115 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2116 CONTENTS holds the contents of the block. INFO is a plist
2117 holding contextual information. See `org-export-data'."
2118 contents)
2120 ;;;; Entity
2122 (defun org-html-entity (entity contents info)
2123 "Transcode an ENTITY object from Org to HTML.
2124 CONTENTS are the definition itself. INFO is a plist holding
2125 contextual information."
2126 (org-element-property :html entity))
2128 ;;;; Example Block
2130 (defun org-html-example-block (example-block contents info)
2131 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2132 CONTENTS is nil. INFO is a plist holding contextual
2133 information."
2134 (if (org-export-read-attribute :attr_html example-block :textarea)
2135 (org-html--textarea-block example-block)
2136 (format "<pre class=\"example\">\n%s</pre>"
2137 (org-html-format-code example-block info))))
2139 ;;;; Export Snippet
2141 (defun org-html-export-snippet (export-snippet contents info)
2142 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2143 CONTENTS is nil. INFO is a plist holding contextual
2144 information."
2145 (when (eq (org-export-snippet-backend export-snippet) 'html)
2146 (org-element-property :value export-snippet)))
2148 ;;;; Export Block
2150 (defun org-html-export-block (export-block contents info)
2151 "Transcode a EXPORT-BLOCK element from Org to HTML.
2152 CONTENTS is nil. INFO is a plist holding contextual information."
2153 (when (string= (org-element-property :type export-block) "HTML")
2154 (org-remove-indentation (org-element-property :value export-block))))
2156 ;;;; Fixed Width
2158 (defun org-html-fixed-width (fixed-width contents info)
2159 "Transcode a FIXED-WIDTH element from Org to HTML.
2160 CONTENTS is nil. INFO is a plist holding contextual information."
2161 (format "<pre class=\"example\">\n%s</pre>"
2162 (org-html-do-format-code
2163 (org-remove-indentation
2164 (org-element-property :value fixed-width)))))
2166 ;;;; Footnote Reference
2168 (defun org-html-footnote-reference (footnote-reference contents info)
2169 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2170 CONTENTS is nil. INFO is a plist holding contextual information."
2171 (concat
2172 ;; Insert separator between two footnotes in a row.
2173 (let ((prev (org-export-get-previous-element footnote-reference info)))
2174 (when (eq (org-element-type prev) 'footnote-reference)
2175 org-html-footnote-separator))
2176 (cond
2177 ((not (org-export-footnote-first-reference-p footnote-reference info))
2178 (org-html-format-footnote-reference
2179 (org-export-get-footnote-number footnote-reference info)
2180 "IGNORED" 100))
2181 ;; Inline definitions are secondary strings.
2182 ((eq (org-element-property :type footnote-reference) 'inline)
2183 (org-html-format-footnote-reference
2184 (org-export-get-footnote-number footnote-reference info)
2185 "IGNORED" 1))
2186 ;; Non-inline footnotes definitions are full Org data.
2187 (t (org-html-format-footnote-reference
2188 (org-export-get-footnote-number footnote-reference info)
2189 "IGNORED" 1)))))
2191 ;;;; Headline
2193 (defun org-html-format-headline--wrap
2194 (headline info &optional format-function &rest extra-keys)
2195 "Transcode a HEADLINE element from Org to HTML.
2196 CONTENTS holds the contents of the headline. INFO is a plist
2197 holding contextual information."
2198 (let* ((level (+ (org-export-get-relative-level headline info)
2199 (1- org-html-toplevel-hlevel)))
2200 (headline-number (org-export-get-headline-number headline info))
2201 (section-number (and (not (org-export-low-level-p headline info))
2202 (org-export-numbered-headline-p headline info)
2203 (mapconcat 'number-to-string
2204 headline-number ".")))
2205 (todo (and (plist-get info :with-todo-keywords)
2206 (let ((todo (org-element-property :todo-keyword headline)))
2207 (and todo (org-export-data todo info)))))
2208 (todo-type (and todo (org-element-property :todo-type headline)))
2209 (priority (and (plist-get info :with-priority)
2210 (org-element-property :priority headline)))
2211 (text (org-export-data (org-element-property :title headline) info))
2212 (tags (and (plist-get info :with-tags)
2213 (org-export-get-tags headline info)))
2214 (headline-label (or (org-element-property :CUSTOM_ID headline)
2215 (concat "sec-" (mapconcat 'number-to-string
2216 headline-number "-"))))
2217 (format-function (cond
2218 ((functionp format-function) format-function)
2219 ((functionp org-html-format-headline-function)
2220 (function*
2221 (lambda (todo todo-type priority text tags
2222 &allow-other-keys)
2223 (funcall org-html-format-headline-function
2224 todo todo-type priority text tags))))
2225 (t 'org-html-format-headline))))
2226 (apply format-function
2227 todo todo-type priority text tags
2228 :headline-label headline-label :level level
2229 :section-number section-number extra-keys)))
2231 (defun org-html-headline (headline contents info)
2232 "Transcode a HEADLINE element from Org to HTML.
2233 CONTENTS holds the contents of the headline. INFO is a plist
2234 holding contextual information."
2235 ;; Empty contents?
2236 (setq contents (or contents ""))
2237 (let* ((numberedp (org-export-numbered-headline-p headline info))
2238 (level (org-export-get-relative-level headline info))
2239 (text (org-export-data (org-element-property :title headline) info))
2240 (todo (and (plist-get info :with-todo-keywords)
2241 (let ((todo (org-element-property :todo-keyword headline)))
2242 (and todo (org-export-data todo info)))))
2243 (todo-type (and todo (org-element-property :todo-type headline)))
2244 (tags (and (plist-get info :with-tags)
2245 (org-export-get-tags headline info)))
2246 (priority (and (plist-get info :with-priority)
2247 (org-element-property :priority headline)))
2248 (section-number (and (org-export-numbered-headline-p headline info)
2249 (mapconcat 'number-to-string
2250 (org-export-get-headline-number
2251 headline info) ".")))
2252 ;; Create the headline text.
2253 (full-text (org-html-format-headline--wrap headline info)))
2254 (cond
2255 ;; Case 1: This is a footnote section: ignore it.
2256 ((org-element-property :footnote-section-p headline) nil)
2257 ;; Case 2. This is a deep sub-tree: export it as a list item.
2258 ;; Also export as items headlines for which no section
2259 ;; format has been found.
2260 ((org-export-low-level-p headline info)
2261 ;; Build the real contents of the sub-tree.
2262 (let* ((type (if numberedp 'ordered 'unordered))
2263 (itemized-body (org-html-format-list-item
2264 contents type nil info nil full-text)))
2265 (concat
2266 (and (org-export-first-sibling-p headline info)
2267 (org-html-begin-plain-list type))
2268 itemized-body
2269 (and (org-export-last-sibling-p headline info)
2270 (org-html-end-plain-list type)))))
2271 ;; Case 3. Standard headline. Export it as a section.
2273 (let* ((section-number (mapconcat 'number-to-string
2274 (org-export-get-headline-number
2275 headline info) "-"))
2276 (ids (remove 'nil
2277 (list (org-element-property :CUSTOM_ID headline)
2278 (concat "sec-" section-number)
2279 (org-element-property :ID headline))))
2280 (preferred-id (car ids))
2281 (extra-ids (cdr ids))
2282 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2283 (level1 (+ level (1- org-html-toplevel-hlevel)))
2284 (first-content (car (org-element-contents headline))))
2285 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2286 (org-html--container headline info)
2287 (format "outline-container-%s"
2288 (or (org-element-property :CUSTOM_ID headline)
2289 (concat "sec-" section-number)))
2290 (concat (format "outline-%d" level1) (and extra-class " ")
2291 extra-class)
2292 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2293 level1
2294 preferred-id
2295 (mapconcat
2296 (lambda (x)
2297 (let ((id (org-export-solidify-link-text
2298 (if (org-uuidgen-p x) (concat "ID-" x)
2299 x))))
2300 (org-html--anchor id)))
2301 extra-ids "")
2302 full-text
2303 level1)
2304 ;; When there is no section, pretend there is an empty
2305 ;; one to get the correct <div class="outline- ...>
2306 ;; which is needed by `org-info.js'.
2307 (if (not (eq (org-element-type first-content) 'section))
2308 (concat (org-html-section first-content "" info)
2309 contents)
2310 contents)
2311 (org-html--container headline info)))))))
2313 (defun org-html--container (headline info)
2314 (or (org-element-property :HTML_CONTAINER headline)
2315 (if (= 1 (org-export-get-relative-level headline info))
2316 (plist-get info :html-container)
2317 "div")))
2319 ;;;; Horizontal Rule
2321 (defun org-html-horizontal-rule (horizontal-rule contents info)
2322 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2323 CONTENTS is nil. INFO is a plist holding contextual information."
2324 (org-html-close-tag "hr" nil info))
2326 ;;;; Inline Src Block
2328 (defun org-html-inline-src-block (inline-src-block contents info)
2329 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2330 CONTENTS holds the contents of the item. INFO is a plist holding
2331 contextual information."
2332 (let* ((org-lang (org-element-property :language inline-src-block))
2333 (code (org-element-property :value inline-src-block)))
2334 (error "Cannot export inline src block")))
2336 ;;;; Inlinetask
2338 (defun org-html-format-section (text class &optional id)
2339 "Format a section with TEXT into a HTML div with CLASS and ID."
2340 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2341 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2343 (defun org-html-inlinetask (inlinetask contents info)
2344 "Transcode an INLINETASK element from Org to HTML.
2345 CONTENTS holds the contents of the block. INFO is a plist
2346 holding contextual information."
2347 (cond
2348 ;; If `org-html-format-inlinetask-function' is provided, call it
2349 ;; with appropriate arguments.
2350 ((functionp org-html-format-inlinetask-function)
2351 (let ((format-function
2352 (function*
2353 (lambda (todo todo-type priority text tags
2354 &key contents &allow-other-keys)
2355 (funcall org-html-format-inlinetask-function
2356 todo todo-type priority text tags contents)))))
2357 (org-html-format-headline--wrap
2358 inlinetask info format-function :contents contents)))
2359 ;; Otherwise, use a default template.
2360 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2361 (org-html-format-headline--wrap inlinetask info)
2362 (org-html-close-tag "br" nil info)
2363 contents))))
2365 ;;;; Italic
2367 (defun org-html-italic (italic contents info)
2368 "Transcode ITALIC from Org to HTML.
2369 CONTENTS is the text with italic markup. INFO is a plist holding
2370 contextual information."
2371 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2373 ;;;; Item
2375 (defun org-html-checkbox (checkbox)
2376 "Format CHECKBOX into HTML."
2377 (case checkbox (on "<code>[X]</code>")
2378 (off "<code>[&#xa0;]</code>")
2379 (trans "<code>[-]</code>")
2380 (t "")))
2382 (defun org-html-format-list-item (contents type checkbox info
2383 &optional term-counter-id
2384 headline)
2385 "Format a list item into HTML."
2386 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
2387 (br (org-html-close-tag "br" nil info)))
2388 (concat
2389 (case type
2390 (ordered
2391 (let* ((counter term-counter-id)
2392 (extra (if counter (format " value=\"%s\"" counter) "")))
2393 (concat
2394 (format "<li%s>" extra)
2395 (when headline (concat headline br)))))
2396 (unordered
2397 (let* ((id term-counter-id)
2398 (extra (if id (format " id=\"%s\"" id) "")))
2399 (concat
2400 (format "<li%s>" extra)
2401 (when headline (concat headline br)))))
2402 (descriptive
2403 (let* ((term term-counter-id))
2404 (setq term (or term "(no term)"))
2405 ;; Check-boxes in descriptive lists are associated to tag.
2406 (concat (format "<dt> %s </dt>"
2407 (concat checkbox term))
2408 "<dd>"))))
2409 (unless (eq type 'descriptive) checkbox)
2410 contents
2411 (case type
2412 (ordered "</li>")
2413 (unordered "</li>")
2414 (descriptive "</dd>")))))
2416 (defun org-html-item (item contents info)
2417 "Transcode an ITEM element from Org to HTML.
2418 CONTENTS holds the contents of the item. INFO is a plist holding
2419 contextual information."
2420 (let* ((plain-list (org-export-get-parent item))
2421 (type (org-element-property :type plain-list))
2422 (counter (org-element-property :counter item))
2423 (checkbox (org-element-property :checkbox item))
2424 (tag (let ((tag (org-element-property :tag item)))
2425 (and tag (org-export-data tag info)))))
2426 (org-html-format-list-item
2427 contents type checkbox info (or tag counter))))
2429 ;;;; Keyword
2431 (defun org-html-keyword (keyword contents info)
2432 "Transcode a KEYWORD element from Org to HTML.
2433 CONTENTS is nil. INFO is a plist holding contextual information."
2434 (let ((key (org-element-property :key keyword))
2435 (value (org-element-property :value keyword)))
2436 (cond
2437 ((string= key "HTML") value)
2438 ((string= key "TOC")
2439 (let ((value (downcase value)))
2440 (cond
2441 ((string-match "\\<headlines\\>" value)
2442 (let ((depth (or (and (string-match "[0-9]+" value)
2443 (string-to-number (match-string 0 value)))
2444 (plist-get info :with-toc))))
2445 (org-html-toc depth info)))
2446 ((string= "listings" value) (org-html-list-of-listings info))
2447 ((string= "tables" value) (org-html-list-of-tables info))))))))
2449 ;;;; Latex Environment
2451 (defun org-html-format-latex (latex-frag processing-type)
2452 "Format a LaTeX fragment LATEX-FRAG into HTML."
2453 (let ((cache-relpath "") (cache-dir ""))
2454 (unless (eq processing-type 'mathjax)
2455 (let ((bfn (or (buffer-file-name)
2456 (make-temp-name
2457 (expand-file-name "latex" temporary-file-directory)))))
2458 (setq cache-relpath
2459 (concat "ltxpng/"
2460 (file-name-sans-extension
2461 (file-name-nondirectory bfn)))
2462 cache-dir (file-name-directory bfn))))
2463 (with-temp-buffer
2464 (insert latex-frag)
2465 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2466 nil nil processing-type)
2467 (buffer-string))))
2469 (defun org-html-latex-environment (latex-environment contents info)
2470 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2471 CONTENTS is nil. INFO is a plist holding contextual information."
2472 (let ((processing-type (plist-get info :with-latex))
2473 (latex-frag (org-remove-indentation
2474 (org-element-property :value latex-environment)))
2475 (caption (org-export-data
2476 (org-export-get-caption latex-environment) info))
2477 (attr nil) ; FIXME
2478 (label (org-element-property :name latex-environment)))
2479 (cond
2480 ((memq processing-type '(t mathjax))
2481 (org-html-format-latex latex-frag 'mathjax))
2482 ((eq processing-type 'dvipng)
2483 (let* ((formula-link (org-html-format-latex
2484 latex-frag processing-type)))
2485 (when (and formula-link
2486 (string-match "file:\\([^]]*\\)" formula-link))
2487 (org-html-format-inline-image
2488 (match-string 1 formula-link) info caption label attr t))))
2489 (t latex-frag))))
2491 ;;;; Latex Fragment
2493 (defun org-html-latex-fragment (latex-fragment contents info)
2494 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2495 CONTENTS is nil. INFO is a plist holding contextual information."
2496 (let ((latex-frag (org-element-property :value latex-fragment))
2497 (processing-type (plist-get info :with-latex)))
2498 (case processing-type
2499 ((t mathjax)
2500 (org-html-format-latex latex-frag 'mathjax))
2501 (dvipng
2502 (let* ((formula-link (org-html-format-latex
2503 latex-frag processing-type)))
2504 (when (and formula-link
2505 (string-match "file:\\([^]]*\\)" formula-link))
2506 (org-html-format-inline-image
2507 (match-string 1 formula-link) info))))
2508 (t latex-frag))))
2510 ;;;; Line Break
2512 (defun org-html-line-break (line-break contents info)
2513 "Transcode a LINE-BREAK object from Org to HTML.
2514 CONTENTS is nil. INFO is a plist holding contextual information."
2515 (concat (org-html-close-tag "br" nil info) "\n"))
2517 ;;;; Link
2519 (defun org-html-link--inline-image (link desc info)
2520 "Return HTML code for an inline image.
2522 LINK is the link pointing to the inline image. INFO is a plist
2523 used as a communication channel.
2525 Inline images can have these attributes:
2527 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2528 (let* ((type (org-element-property :type link))
2529 (raw-path (org-element-property :path link))
2530 (path (cond ((member type '("http" "https"))
2531 (concat type ":" raw-path))
2532 ((file-name-absolute-p raw-path)
2533 (expand-file-name raw-path))
2534 (t raw-path)))
2535 (parent (org-export-get-parent-element link))
2536 (caption (org-export-data (org-export-get-caption parent) info))
2537 (label (org-element-property :name parent)))
2538 ;; Return proper string, depending on DISPOSITION.
2539 (org-html-format-inline-image
2540 path info caption label
2541 (org-html--make-attribute-string
2542 (org-export-read-attribute :attr_html parent))
2543 (org-html-standalone-image-p link info))))
2545 (defvar org-html-standalone-image-predicate)
2546 (defun org-html-standalone-image-p (element info &optional predicate)
2547 "Test if ELEMENT is a standalone image for the purpose HTML export.
2548 INFO is a plist holding contextual information.
2550 Return non-nil, if ELEMENT is of type paragraph and it's sole
2551 content, save for whitespaces, is a link that qualifies as an
2552 inline image.
2554 Return non-nil, if ELEMENT is of type link and it's containing
2555 paragraph has no other content save for leading and trailing
2556 whitespaces.
2558 Return nil, otherwise.
2560 Bind `org-html-standalone-image-predicate' to constrain
2561 paragraph further. For example, to check for only captioned
2562 standalone images, do the following.
2564 \(setq org-html-standalone-image-predicate
2565 \(lambda \(paragraph\)
2566 \(org-element-property :caption paragraph\)\)\)"
2567 (let ((paragraph (case (org-element-type element)
2568 (paragraph element)
2569 (link (and (org-export-inline-image-p
2570 element org-html-inline-image-rules)
2571 (org-export-get-parent element)))
2572 (t nil))))
2573 (when (eq (org-element-type paragraph) 'paragraph)
2574 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2575 (functionp org-html-standalone-image-predicate)))
2576 (funcall org-html-standalone-image-predicate paragraph))
2577 (let ((contents (org-element-contents paragraph)))
2578 (loop for x in contents
2579 with inline-image-count = 0
2580 always (cond
2581 ((eq (org-element-type x) 'plain-text)
2582 (not (org-string-nw-p x)))
2583 ((eq (org-element-type x) 'link)
2584 (when (org-export-inline-image-p
2585 x org-html-inline-image-rules)
2586 (= (incf inline-image-count) 1)))
2587 (t nil))))))))
2589 (defun org-html-link (link desc info)
2590 "Transcode a LINK object from Org to HTML.
2592 DESC is the description part of the link, or the empty string.
2593 INFO is a plist holding contextual information. See
2594 `org-export-data'."
2595 (let* ((link-org-files-as-html-maybe
2596 (function
2597 (lambda (raw-path info)
2598 "Treat links to `file.org' as links to `file.html', if needed.
2599 See `org-html-link-org-files-as-html'."
2600 (cond
2601 ((and org-html-link-org-files-as-html
2602 (string= ".org"
2603 (downcase (file-name-extension raw-path "."))))
2604 (concat (file-name-sans-extension raw-path) "."
2605 (plist-get info :html-extension)))
2606 (t raw-path)))))
2607 (type (org-element-property :type link))
2608 (raw-path (org-element-property :path link))
2609 ;; Ensure DESC really exists, or set it to nil.
2610 (desc (org-string-nw-p desc))
2611 (path
2612 (cond
2613 ((member type '("http" "https" "ftp" "mailto"))
2614 (concat type ":" raw-path))
2615 ((string= type "file")
2616 ;; Treat links to ".org" files as ".html", if needed.
2617 (setq raw-path
2618 (funcall link-org-files-as-html-maybe raw-path info))
2619 ;; If file path is absolute, prepend it with protocol
2620 ;; component - "file://".
2621 (when (file-name-absolute-p raw-path)
2622 (setq raw-path
2623 (concat "file://" (expand-file-name raw-path))))
2624 ;; Add search option, if any. A search option can be
2625 ;; relative to a custom-id or a headline title. Any other
2626 ;; option is ignored.
2627 (let ((option (org-element-property :search-option link)))
2628 (cond ((not option) raw-path)
2629 ((eq (aref option 0) ?#) (concat raw-path option))
2630 ;; External fuzzy link: try to resolve it if path
2631 ;; belongs to current project, if any.
2632 ((eq (aref option 0) ?*)
2633 (concat
2634 raw-path
2635 (let ((numbers
2636 (org-publish-resolve-external-fuzzy-link
2637 (org-element-property :path link) option)))
2638 (and numbers (concat "#sec-"
2639 (mapconcat 'number-to-string
2640 numbers "-"))))))
2641 (t raw-path))))
2642 (t raw-path)))
2643 ;; Extract attributes from parent's paragraph. HACK: Only do
2644 ;; this for the first link in parent. This is needed as long
2645 ;; as attributes cannot be set on a per link basis.
2646 (attributes
2647 (let ((parent (org-export-get-parent-element link)))
2648 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2650 (let ((att (org-html--make-attribute-string
2651 (org-export-read-attribute :attr_html parent))))
2652 (cond ((not (org-string-nw-p att)) "")
2653 ((and desc (string-match (regexp-quote att) desc)) "")
2654 (t (concat " " att)))))))
2655 protocol)
2656 (cond
2657 ;; Image file.
2658 ((and (or (eq t org-html-inline-images)
2659 (and org-html-inline-images (not desc)))
2660 (org-export-inline-image-p link org-html-inline-image-rules))
2661 (org-html-link--inline-image link desc info))
2662 ;; Radio target: Transcode target's contents and use them as
2663 ;; link's description.
2664 ((string= type "radio")
2665 (let ((destination (org-export-resolve-radio-link link info)))
2666 (when destination
2667 (format "<a href=\"#%s\"%s>%s</a>"
2668 (org-export-solidify-link-text path)
2669 attributes
2670 (org-export-data (org-element-contents destination) info)))))
2671 ;; Links pointing to a headline: Find destination and build
2672 ;; appropriate referencing command.
2673 ((member type '("custom-id" "fuzzy" "id"))
2674 (let ((destination (if (string= type "fuzzy")
2675 (org-export-resolve-fuzzy-link link info)
2676 (org-export-resolve-id-link link info))))
2677 (case (org-element-type destination)
2678 ;; ID link points to an external file.
2679 (plain-text
2680 (let ((fragment (concat "ID-" path))
2681 ;; Treat links to ".org" files as ".html", if needed.
2682 (path (funcall link-org-files-as-html-maybe
2683 destination info)))
2684 (format "<a href=\"%s#%s\"%s>%s</a>"
2685 path fragment attributes (or desc destination))))
2686 ;; Fuzzy link points nowhere.
2687 ((nil)
2688 (format "<i>%s</i>"
2689 (or desc
2690 (org-export-data
2691 (org-element-property :raw-link link) info))))
2692 ;; Fuzzy link points to an invisible target.
2693 (keyword nil)
2694 ;; Link points to a headline.
2695 (headline
2696 (let ((href
2697 ;; What href to use?
2698 (cond
2699 ;; Case 1: Headline is linked via it's CUSTOM_ID
2700 ;; property. Use CUSTOM_ID.
2701 ((string= type "custom-id")
2702 (org-element-property :CUSTOM_ID destination))
2703 ;; Case 2: Headline is linked via it's ID property
2704 ;; or through other means. Use the default href.
2705 ((member type '("id" "fuzzy"))
2706 (format "sec-%s"
2707 (mapconcat 'number-to-string
2708 (org-export-get-headline-number
2709 destination info) "-")))
2710 (t (error "Shouldn't reach here"))))
2711 ;; What description to use?
2712 (desc
2713 ;; Case 1: Headline is numbered and LINK has no
2714 ;; description. Display section number.
2715 (if (and (org-export-numbered-headline-p destination info)
2716 (not desc))
2717 (mapconcat 'number-to-string
2718 (org-export-get-headline-number
2719 destination info) ".")
2720 ;; Case 2: Either the headline is un-numbered or
2721 ;; LINK has a custom description. Display LINK's
2722 ;; description or headline's title.
2723 (or desc (org-export-data (org-element-property
2724 :title destination) info)))))
2725 (format "<a href=\"#%s\"%s>%s</a>"
2726 (org-export-solidify-link-text href) attributes desc)))
2727 ;; Fuzzy link points to a target. Do as above.
2729 (let ((path (org-export-solidify-link-text path)) number)
2730 (unless desc
2731 (setq number (cond
2732 ((org-html-standalone-image-p destination info)
2733 (org-export-get-ordinal
2734 (assoc 'link (org-element-contents destination))
2735 info 'link 'org-html-standalone-image-p))
2736 (t (org-export-get-ordinal destination info))))
2737 (setq desc (when number
2738 (if (atom number) (number-to-string number)
2739 (mapconcat 'number-to-string number ".")))))
2740 (format "<a href=\"#%s\"%s>%s</a>"
2741 path attributes (or desc "No description for this link")))))))
2742 ;; Coderef: replace link with the reference name or the
2743 ;; equivalent line number.
2744 ((string= type "coderef")
2745 (let ((fragment (concat "coderef-" path)))
2746 (format "<a href=\"#%s\"%s%s>%s</a>"
2747 fragment
2748 (org-trim
2749 (format (concat "class=\"coderef\""
2750 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2751 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2752 fragment fragment))
2753 attributes
2754 (format (org-export-get-coderef-format path desc)
2755 (org-export-resolve-coderef path info)))))
2756 ;; Link type is handled by a special function.
2757 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2758 (funcall protocol (org-link-unescape path) desc 'html))
2759 ;; External link with a description part.
2760 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2761 ;; External link without a description part.
2762 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2763 ;; No path, only description. Try to do something useful.
2764 (t (format "<i>%s</i>" desc)))))
2766 ;;;; Paragraph
2768 (defun org-html-paragraph (paragraph contents info)
2769 "Transcode a PARAGRAPH element from Org to HTML.
2770 CONTENTS is the contents of the paragraph, as a string. INFO is
2771 the plist used as a communication channel."
2772 (let* ((parent (org-export-get-parent paragraph))
2773 (parent-type (org-element-type parent))
2774 (style '((footnote-definition " class=\"footpara\"")))
2775 (extra (or (cadr (assoc parent-type style)) "")))
2776 (cond
2777 ((and (eq (org-element-type parent) 'item)
2778 (= (org-element-property :begin paragraph)
2779 (org-element-property :contents-begin parent)))
2780 ;; leading paragraph in a list item have no tags
2781 contents)
2782 ((org-html-standalone-image-p paragraph info)
2783 ;; standalone image
2784 contents)
2785 (t (format "<p%s>\n%s</p>" extra contents)))))
2787 ;;;; Plain List
2789 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2790 ;; the correct value for the item counter
2791 (defun org-html-begin-plain-list (type &optional arg1)
2792 "Insert the beginning of the HTML list depending on TYPE.
2793 When ARG1 is a string, use it as the start parameter for ordered
2794 lists."
2795 (case type
2796 (ordered
2797 (format "<ol class=\"org-ol\"%s>"
2798 (if arg1 (format " start=\"%d\"" arg1) "")))
2799 (unordered "<ul class=\"org-ul\">")
2800 (descriptive "<dl class=\"org-dl\">")))
2802 (defun org-html-end-plain-list (type)
2803 "Insert the end of the HTML list depending on TYPE."
2804 (case type
2805 (ordered "</ol>")
2806 (unordered "</ul>")
2807 (descriptive "</dl>")))
2809 (defun org-html-plain-list (plain-list contents info)
2810 "Transcode a PLAIN-LIST element from Org to HTML.
2811 CONTENTS is the contents of the list. INFO is a plist holding
2812 contextual information."
2813 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2814 (type (org-element-property :type plain-list)))
2815 (format "%s\n%s%s"
2816 (org-html-begin-plain-list type)
2817 contents (org-html-end-plain-list type))))
2819 ;;;; Plain Text
2821 (defun org-html-convert-special-strings (string)
2822 "Convert special characters in STRING to HTML."
2823 (let ((all org-html-special-string-regexps)
2824 e a re rpl start)
2825 (while (setq a (pop all))
2826 (setq re (car a) rpl (cdr a) start 0)
2827 (while (string-match re string start)
2828 (setq string (replace-match rpl t nil string))))
2829 string))
2831 (defun org-html-encode-plain-text (text)
2832 "Convert plain text characters from TEXT to HTML equivalent.
2833 Possible conversions are set in `org-html-protect-char-alist'."
2834 (mapc
2835 (lambda (pair)
2836 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2837 org-html-protect-char-alist)
2838 text)
2840 (defun org-html-plain-text (text info)
2841 "Transcode a TEXT string from Org to HTML.
2842 TEXT is the string to transcode. INFO is a plist holding
2843 contextual information."
2844 (let ((output text))
2845 ;; Protect following characters: <, >, &.
2846 (setq output (org-html-encode-plain-text output))
2847 ;; Handle smart quotes. Be sure to provide original string since
2848 ;; OUTPUT may have been modified.
2849 (when (plist-get info :with-smart-quotes)
2850 (setq output (org-export-activate-smart-quotes output :html info text)))
2851 ;; Handle special strings.
2852 (when (plist-get info :with-special-strings)
2853 (setq output (org-html-convert-special-strings output)))
2854 ;; Handle break preservation if required.
2855 (when (plist-get info :preserve-breaks)
2856 (setq output
2857 (replace-regexp-in-string
2858 "\\(\\\\\\\\\\)?[ \t]*\n"
2859 (concat (org-html-close-tag "br" nil info) "\n") output)))
2860 ;; Return value.
2861 output))
2864 ;; Planning
2866 (defun org-html-planning (planning contents info)
2867 "Transcode a PLANNING element from Org to HTML.
2868 CONTENTS is nil. INFO is a plist used as a communication
2869 channel."
2870 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2871 (format
2872 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2873 (mapconcat
2874 'identity
2875 (delq nil
2876 (list
2877 (let ((closed (org-element-property :closed planning)))
2878 (when closed
2879 (format span-fmt org-closed-string
2880 (org-translate-time
2881 (org-element-property :raw-value closed)))))
2882 (let ((deadline (org-element-property :deadline planning)))
2883 (when deadline
2884 (format span-fmt org-deadline-string
2885 (org-translate-time
2886 (org-element-property :raw-value deadline)))))
2887 (let ((scheduled (org-element-property :scheduled planning)))
2888 (when scheduled
2889 (format span-fmt org-scheduled-string
2890 (org-translate-time
2891 (org-element-property :raw-value scheduled)))))))
2892 " "))))
2894 ;;;; Property Drawer
2896 (defun org-html-property-drawer (property-drawer contents info)
2897 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2898 CONTENTS is nil. INFO is a plist holding contextual
2899 information."
2900 ;; The property drawer isn't exported but we want separating blank
2901 ;; lines nonetheless.
2904 ;;;; Quote Block
2906 (defun org-html-quote-block (quote-block contents info)
2907 "Transcode a QUOTE-BLOCK element from Org to HTML.
2908 CONTENTS holds the contents of the block. INFO is a plist
2909 holding contextual information."
2910 (format "<blockquote>\n%s</blockquote>" contents))
2912 ;;;; Quote Section
2914 (defun org-html-quote-section (quote-section contents info)
2915 "Transcode a QUOTE-SECTION element from Org to HTML.
2916 CONTENTS is nil. INFO is a plist holding contextual information."
2917 (let ((value (org-remove-indentation
2918 (org-element-property :value quote-section))))
2919 (when value (format "<pre>\n%s</pre>" value))))
2921 ;;;; Section
2923 (defun org-html-section (section contents info)
2924 "Transcode a SECTION element from Org to HTML.
2925 CONTENTS holds the contents of the section. INFO is a plist
2926 holding contextual information."
2927 (let ((parent (org-export-get-parent-headline section)))
2928 ;; Before first headline: no container, just return CONTENTS.
2929 (if (not parent) contents
2930 ;; Get div's class and id references.
2931 (let* ((class-num (+ (org-export-get-relative-level parent info)
2932 (1- org-html-toplevel-hlevel)))
2933 (section-number
2934 (mapconcat
2935 'number-to-string
2936 (org-export-get-headline-number parent info) "-")))
2937 ;; Build return value.
2938 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2939 class-num
2940 (or (org-element-property :CUSTOM_ID parent) section-number)
2941 contents)))))
2943 ;;;; Radio Target
2945 (defun org-html-radio-target (radio-target text info)
2946 "Transcode a RADIO-TARGET object from Org to HTML.
2947 TEXT is the text of the target. INFO is a plist holding
2948 contextual information."
2949 (let ((id (org-export-solidify-link-text
2950 (org-element-property :value radio-target))))
2951 (org-html--anchor id text)))
2953 ;;;; Special Block
2955 (defun org-html-special-block (special-block contents info)
2956 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2957 CONTENTS holds the contents of the block. INFO is a plist
2958 holding contextual information."
2959 (let* ((block-type (downcase
2960 (org-element-property :type special-block)))
2961 (contents (or contents ""))
2962 (html5-fancy (and (org-html-html5-p info)
2963 (plist-get info :html-html5-fancy)
2964 (member block-type org-html-html5-elements)))
2965 (attributes (org-export-read-attribute :attr_html special-block)))
2966 (unless html5-fancy
2967 (let ((class (plist-get attributes :class)))
2968 (setq attributes (plist-put attributes :class
2969 (if class (concat class " " block-type)
2970 block-type)))))
2971 (setq attributes (org-html--make-attribute-string attributes))
2972 (when (not (equal attributes ""))
2973 (setq attributes (concat " " attributes)))
2974 (if html5-fancy
2975 (format "<%s%s>\n%s</%s>" block-type attributes
2976 contents block-type)
2977 (format "<div%s>\n%s\n</div>" attributes contents))))
2979 ;;;; Src Block
2981 (defun org-html-src-block (src-block contents info)
2982 "Transcode a SRC-BLOCK element from Org to HTML.
2983 CONTENTS holds the contents of the item. INFO is a plist holding
2984 contextual information."
2985 (if (org-export-read-attribute :attr_html src-block :textarea)
2986 (org-html--textarea-block src-block)
2987 (let ((lang (org-element-property :language src-block))
2988 (caption (org-export-get-caption src-block))
2989 (code (org-html-format-code src-block info))
2990 (label (let ((lbl (org-element-property :name src-block)))
2991 (if (not lbl) ""
2992 (format " id=\"%s\""
2993 (org-export-solidify-link-text lbl))))))
2994 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2995 (format
2996 "<div class=\"org-src-container\">\n%s%s\n</div>"
2997 (if (not caption) ""
2998 (format "<label class=\"org-src-name\">%s</label>"
2999 (org-export-data caption info)))
3000 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3002 ;;;; Statistics Cookie
3004 (defun org-html-statistics-cookie (statistics-cookie contents info)
3005 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3006 CONTENTS is nil. INFO is a plist holding contextual information."
3007 (let ((cookie-value (org-element-property :value statistics-cookie)))
3008 (format "<code>%s</code>" cookie-value)))
3010 ;;;; Strike-Through
3012 (defun org-html-strike-through (strike-through contents info)
3013 "Transcode STRIKE-THROUGH from Org to HTML.
3014 CONTENTS is the text with strike-through markup. INFO is a plist
3015 holding contextual information."
3016 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3017 contents))
3019 ;;;; Subscript
3021 (defun org-html-subscript (subscript contents info)
3022 "Transcode a SUBSCRIPT object from Org to HTML.
3023 CONTENTS is the contents of the object. INFO is a plist holding
3024 contextual information."
3025 (format "<sub>%s</sub>" contents))
3027 ;;;; Superscript
3029 (defun org-html-superscript (superscript contents info)
3030 "Transcode a SUPERSCRIPT object from Org to HTML.
3031 CONTENTS is the contents of the object. INFO is a plist holding
3032 contextual information."
3033 (format "<sup>%s</sup>" contents))
3035 ;;;; Tabel Cell
3037 (defun org-html-table-cell (table-cell contents info)
3038 "Transcode a TABLE-CELL element from Org to HTML.
3039 CONTENTS is nil. INFO is a plist used as a communication
3040 channel."
3041 (let* ((table-row (org-export-get-parent table-cell))
3042 (table (org-export-get-parent-table table-cell))
3043 (cell-attrs
3044 (if (not org-html-table-align-individual-fields) ""
3045 (format (if (and (boundp 'org-html-format-table-no-css)
3046 org-html-format-table-no-css)
3047 " align=\"%s\"" " class=\"%s\"")
3048 (org-export-table-cell-alignment table-cell info)))))
3049 (when (or (not contents) (string= "" (org-trim contents)))
3050 (setq contents "&#xa0;"))
3051 (cond
3052 ((and (org-export-table-has-header-p table info)
3053 (= 1 (org-export-table-row-group table-row info)))
3054 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3055 contents (cdr org-html-table-header-tags)))
3056 ((and org-html-table-use-header-tags-for-first-column
3057 (zerop (cdr (org-export-table-cell-address table-cell info))))
3058 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3059 contents (cdr org-html-table-header-tags)))
3060 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3061 contents (cdr org-html-table-data-tags))))))
3063 ;;;; Table Row
3065 (defun org-html-table-row (table-row contents info)
3066 "Transcode a TABLE-ROW element from Org to HTML.
3067 CONTENTS is the contents of the row. INFO is a plist used as a
3068 communication channel."
3069 ;; Rules are ignored since table separators are deduced from
3070 ;; borders of the current row.
3071 (when (eq (org-element-property :type table-row) 'standard)
3072 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3073 (row-number (org-export-table-row-number table-row info))
3074 (start-rowgroup-p
3075 (org-export-table-row-starts-rowgroup-p table-row info))
3076 (end-rowgroup-p
3077 (org-export-table-row-ends-rowgroup-p table-row info))
3078 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3079 ;; but should be set so that `org-html-table-row-tags' can
3080 ;; use them (see the docstring of this variable.)
3081 (top-row-p (and (equal start-rowgroup-p '(top))
3082 (equal end-rowgroup-p '(below top))))
3083 (bottom-row-p (and (equal start-rowgroup-p '(above))
3084 (equal end-rowgroup-p '(bottom above))))
3085 (rowgroup-tags
3086 (cond
3087 ;; Case 1: Row belongs to second or subsequent rowgroups.
3088 ((not (= 1 rowgroup-number))
3089 '("<tbody>" . "\n</tbody>"))
3090 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3091 ((org-export-table-has-header-p
3092 (org-export-get-parent-table table-row) info)
3093 '("<thead>" . "\n</thead>"))
3094 ;; Case 2: Row is from first and only row group.
3095 (t '("<tbody>" . "\n</tbody>")))))
3096 (concat
3097 ;; Begin a rowgroup?
3098 (when start-rowgroup-p (car rowgroup-tags))
3099 ;; Actual table row
3100 (concat "\n" (eval (car org-html-table-row-tags))
3101 contents
3102 "\n"
3103 (eval (cdr org-html-table-row-tags)))
3104 ;; End a rowgroup?
3105 (when end-rowgroup-p (cdr rowgroup-tags))))))
3107 ;;;; Table
3109 (defun org-html-table-first-row-data-cells (table info)
3110 "Transcode the first row of TABLE.
3111 INFO is a plist used as a communication channel."
3112 (let ((table-row
3113 (org-element-map table 'table-row
3114 (lambda (row)
3115 (unless (eq (org-element-property :type row) 'rule) row))
3116 info 'first-match))
3117 (special-column-p (org-export-table-has-special-column-p table)))
3118 (if (not special-column-p) (org-element-contents table-row)
3119 (cdr (org-element-contents table-row)))))
3121 (defun org-html-table--table.el-table (table info)
3122 "Format table.el tables into HTML.
3123 INFO is a plist used as a communication channel."
3124 (when (eq (org-element-property :type table) 'table.el)
3125 (require 'table)
3126 (let ((outbuf (with-current-buffer
3127 (get-buffer-create "*org-export-table*")
3128 (erase-buffer) (current-buffer))))
3129 (with-temp-buffer
3130 (insert (org-element-property :value table))
3131 (goto-char 1)
3132 (re-search-forward "^[ \t]*|[^|]" nil t)
3133 (table-generate-source 'html outbuf))
3134 (with-current-buffer outbuf
3135 (prog1 (org-trim (buffer-string))
3136 (kill-buffer) )))))
3138 (defun org-html-table (table contents info)
3139 "Transcode a TABLE element from Org to HTML.
3140 CONTENTS is the contents of the table. INFO is a plist holding
3141 contextual information."
3142 (case (org-element-property :type table)
3143 ;; Case 1: table.el table. Convert it using appropriate tools.
3144 (table.el (org-html-table--table.el-table table info))
3145 ;; Case 2: Standard table.
3147 (let* ((label (org-element-property :name table))
3148 (caption (org-export-get-caption table))
3149 (attributes
3150 (if (org-html-html5-p info) ""
3151 (org-html--make-attribute-string
3152 (org-combine-plists
3153 (and label (list :id (org-export-solidify-link-text label)))
3154 (plist-get info :html-table-attributes)
3155 (org-export-read-attribute :attr_html table)))))
3156 (alignspec
3157 (if (and (boundp 'org-html-format-table-no-css)
3158 org-html-format-table-no-css)
3159 "align=\"%s\"" "class=\"%s\""))
3160 (table-column-specs
3161 (function
3162 (lambda (table info)
3163 (mapconcat
3164 (lambda (table-cell)
3165 (let ((alignment (org-export-table-cell-alignment
3166 table-cell info)))
3167 (concat
3168 ;; Begin a colgroup?
3169 (when (org-export-table-cell-starts-colgroup-p
3170 table-cell info)
3171 "\n<colgroup>")
3172 ;; Add a column. Also specify it's alignment.
3173 (format "\n%s"
3174 (org-html-close-tag
3175 "col" (concat " " (format alignspec alignment)) info))
3176 ;; End a colgroup?
3177 (when (org-export-table-cell-ends-colgroup-p
3178 table-cell info)
3179 "\n</colgroup>"))))
3180 (org-html-table-first-row-data-cells table info) "\n")))))
3181 (format "<table%s>\n%s\n%s\n%s</table>"
3182 (if (equal attributes "") "" (concat " " attributes))
3183 (if (not caption) ""
3184 (format (if org-html-table-caption-above
3185 "<caption align=\"above\">%s</caption>"
3186 "<caption align=\"bottom\">%s</caption>")
3187 (org-export-data caption info)))
3188 (funcall table-column-specs table info)
3189 contents)))))
3191 ;;;; Target
3193 (defun org-html-target (target contents info)
3194 "Transcode a TARGET object from Org to HTML.
3195 CONTENTS is nil. INFO is a plist holding contextual
3196 information."
3197 (let ((id (org-export-solidify-link-text
3198 (org-element-property :value target))))
3199 (org-html--anchor id)))
3201 ;;;; Timestamp
3203 (defun org-html-timestamp (timestamp contents info)
3204 "Transcode a TIMESTAMP object from Org to HTML.
3205 CONTENTS is nil. INFO is a plist holding contextual
3206 information."
3207 (let ((value (org-html-plain-text
3208 (org-timestamp-translate timestamp) info)))
3209 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3210 (replace-regexp-in-string "--" "&#x2013;" value))))
3212 ;;;; Underline
3214 (defun org-html-underline (underline contents info)
3215 "Transcode UNDERLINE from Org to HTML.
3216 CONTENTS is the text with underline markup. INFO is a plist
3217 holding contextual information."
3218 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3219 contents))
3221 ;;;; Verbatim
3223 (defun org-html-verbatim (verbatim contents info)
3224 "Transcode VERBATIM from Org to HTML.
3225 CONTENTS is nil. INFO is a plist holding contextual
3226 information."
3227 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3228 (org-html-encode-plain-text (org-element-property :value verbatim))))
3230 ;;;; Verse Block
3232 (defun org-html-verse-block (verse-block contents info)
3233 "Transcode a VERSE-BLOCK element from Org to HTML.
3234 CONTENTS is verse block contents. INFO is a plist holding
3235 contextual information."
3236 ;; Replace each newline character with line break. Also replace
3237 ;; each blank line with a line break.
3238 (setq contents (replace-regexp-in-string
3239 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3240 (replace-regexp-in-string
3241 "\\(\\\\\\\\\\)?[ \t]*\n"
3242 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3243 ;; Replace each white space at beginning of a line with a
3244 ;; non-breaking space.
3245 (while (string-match "^[ \t]+" contents)
3246 (let* ((num-ws (length (match-string 0 contents)))
3247 (ws (let (out) (dotimes (i num-ws out)
3248 (setq out (concat out "&#xa0;"))))))
3249 (setq contents (replace-match ws nil t contents))))
3250 (format "<p class=\"verse\">\n%s</p>" contents))
3253 ;;; Filter Functions
3255 (defun org-html-final-function (contents backend info)
3256 "Filter to indent the HTML and convert HTML entities."
3257 (with-temp-buffer
3258 (insert contents)
3259 (set-auto-mode t)
3260 (if org-html-indent
3261 (indent-region (point-min) (point-max)))
3262 (when org-html-use-unicode-chars
3263 (require 'mm-url)
3264 (mm-url-decode-entities))
3265 (buffer-substring-no-properties (point-min) (point-max))))
3268 ;;; End-user functions
3270 ;;;###autoload
3271 (defun org-html-export-as-html
3272 (&optional async subtreep visible-only body-only ext-plist)
3273 "Export current buffer to an HTML buffer.
3275 If narrowing is active in the current buffer, only export its
3276 narrowed part.
3278 If a region is active, export that region.
3280 A non-nil optional argument ASYNC means the process should happen
3281 asynchronously. The resulting buffer should be accessible
3282 through the `org-export-stack' interface.
3284 When optional argument SUBTREEP is non-nil, export the sub-tree
3285 at point, extracting information from the headline properties
3286 first.
3288 When optional argument VISIBLE-ONLY is non-nil, don't export
3289 contents of hidden elements.
3291 When optional argument BODY-ONLY is non-nil, only write code
3292 between \"<body>\" and \"</body>\" tags.
3294 EXT-PLIST, when provided, is a property list with external
3295 parameters overriding Org default settings, but still inferior to
3296 file-local settings.
3298 Export is done in a buffer named \"*Org HTML Export*\", which
3299 will be displayed when `org-export-show-temporary-export-buffer'
3300 is non-nil."
3301 (interactive)
3302 (if async
3303 (org-export-async-start
3304 (lambda (output)
3305 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3306 (erase-buffer)
3307 (insert output)
3308 (goto-char (point-min))
3309 (set-auto-mode t)
3310 (org-export-add-to-stack (current-buffer) 'html)))
3311 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3312 (let ((outbuf (org-export-to-buffer
3313 'html "*Org HTML Export*"
3314 subtreep visible-only body-only ext-plist)))
3315 ;; Set major mode.
3316 (with-current-buffer outbuf (set-auto-mode t))
3317 (when org-export-show-temporary-export-buffer
3318 (switch-to-buffer-other-window outbuf)))))
3320 ;;;###autoload
3321 (defun org-html-convert-region-to-html ()
3322 "Assume the current region has org-mode syntax, and convert it to HTML.
3323 This can be used in any buffer. For example, you can write an
3324 itemized list in org-mode syntax in an HTML buffer and use this
3325 command to convert it."
3326 (interactive)
3327 (org-export-replace-region-by 'html))
3329 ;;;###autoload
3330 (defun org-html-export-to-html
3331 (&optional async subtreep visible-only body-only ext-plist)
3332 "Export current buffer to a HTML file.
3334 If narrowing is active in the current buffer, only export its
3335 narrowed part.
3337 If a region is active, export that region.
3339 A non-nil optional argument ASYNC means the process should happen
3340 asynchronously. The resulting file should be accessible through
3341 the `org-export-stack' interface.
3343 When optional argument SUBTREEP is non-nil, export the sub-tree
3344 at point, extracting information from the headline properties
3345 first.
3347 When optional argument VISIBLE-ONLY is non-nil, don't export
3348 contents of hidden elements.
3350 When optional argument BODY-ONLY is non-nil, only write code
3351 between \"<body>\" and \"</body>\" tags.
3353 EXT-PLIST, when provided, is a property list with external
3354 parameters overriding Org default settings, but still inferior to
3355 file-local settings.
3357 Return output file's name."
3358 (interactive)
3359 (let* ((extension (concat "." org-html-extension))
3360 (file (org-export-output-file-name extension subtreep))
3361 (org-export-coding-system org-html-coding-system))
3362 (if async
3363 (org-export-async-start
3364 (lambda (f) (org-export-add-to-stack f 'html))
3365 (let ((org-export-coding-system org-html-coding-system))
3366 `(expand-file-name
3367 (org-export-to-file
3368 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3369 (let ((org-export-coding-system org-html-coding-system))
3370 (org-export-to-file
3371 'html file subtreep visible-only body-only ext-plist)))))
3373 ;;;###autoload
3374 (defun org-html-publish-to-html (plist filename pub-dir)
3375 "Publish an org file to HTML.
3377 FILENAME is the filename of the Org file to be published. PLIST
3378 is the property list for the given project. PUB-DIR is the
3379 publishing directory.
3381 Return output file name."
3382 (org-publish-org-to 'html filename
3383 (concat "." (or (plist-get plist :html-extension)
3384 org-html-extension "html"))
3385 plist pub-dir))
3388 ;;; FIXME
3390 ;;;; org-format-table-html
3391 ;;;; org-format-org-table-html
3392 ;;;; org-format-table-table-html
3393 ;;;; org-table-number-fraction
3394 ;;;; org-table-number-regexp
3395 ;;;; org-html-inline-image-extensions
3396 ;;;; org-export-preferred-target-alist
3397 ;;;; class for anchors
3398 ;;;; org-export-mark-todo-in-toc
3399 ;;;; org-html-format-org-link
3400 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3401 ;;;; alt = (file-name-nondirectory path)
3403 (provide 'ox-html)
3405 ;; Local variables:
3406 ;; generated-autoload-file: "org-loaddefs.el"
3407 ;; End:
3409 ;;; ox-html.el ends here