ox-html: Fix code typo
[org-mode.git] / lisp / ox-html.el
blob30de11ff08303d3ae4be821deeebca6b31c01c80
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))
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 '(alist :key-type (string :tag "Language")
1112 :value-type (string :tag "Format string")))
1114 (defcustom org-html-validation-link
1115 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1116 "Link to HTML validation service."
1117 :group 'org-export-html
1118 :type 'string)
1120 (defcustom org-html-creator-string
1121 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1122 emacs-version
1123 (if (fboundp 'org-version) (org-version) "unknown version"))
1124 "Information about the creator of the HTML document.
1125 This option can also be set on with the CREATOR keyword."
1126 :group 'org-export-html
1127 :type '(string :tag "Creator string"))
1129 ;;;; Template :: Preamble
1131 (defcustom org-html-preamble t
1132 "Non-nil means insert a preamble in HTML export.
1134 When t, insert a string as defined by the formatting string in
1135 `org-html-preamble-format'. When set to a string, use this
1136 formatting string instead (see `org-html-postamble-format' for an
1137 example of such a formatting string).
1139 When set to a function, apply this function and insert the
1140 returned string. The function takes the property list of export
1141 options as its only argument.
1143 Setting :html-preamble in publishing projects will take
1144 precedence over this variable."
1145 :group 'org-export-html
1146 :type '(choice (const :tag "No preamble" nil)
1147 (const :tag "Default preamble" t)
1148 (string :tag "Custom formatting string")
1149 (function :tag "Function (must return a string)")))
1151 (defcustom org-html-preamble-format '(("en" ""))
1152 "Alist of languages and format strings for the HTML preamble.
1154 The first element of each list is the language code, as used for
1155 the LANGUAGE keyword. See `org-export-default-language'.
1157 The second element of each list is a format string to format the
1158 preamble itself. This format string can contain these elements:
1160 %t stands for the title.
1161 %a stands for the author's name.
1162 %e stands for the author's email.
1163 %d stands for the date.
1164 %c will be replaced by `org-html-creator-string'.
1165 %v will be replaced by `org-html-validation-link'.
1166 %T will be replaced by the export time.
1167 %C will be replaced by the last modification time.
1169 If you need to use a \"%\" character, you need to escape it
1170 like that: \"%%\".
1172 See the default value of `org-html-postamble-format' for an
1173 example."
1174 :group 'org-export-html
1175 :type '(alist :key-type (string :tag "Language")
1176 :value-type (string :tag "Format string")))
1178 (defcustom org-html-link-up ""
1179 "Where should the \"UP\" link of exported HTML pages lead?"
1180 :group 'org-export-html
1181 :type '(string :tag "File or URL"))
1183 (defcustom org-html-link-home ""
1184 "Where should the \"HOME\" link of exported HTML pages lead?"
1185 :group 'org-export-html
1186 :type '(string :tag "File or URL"))
1188 (defcustom org-html-home/up-format
1189 "<div id=\"org-div-home-and-up\">
1190 <a accesskey=\"h\" href=\"%s\"> UP </a>
1192 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1193 </div>"
1194 "Snippet used to insert the HOME and UP links.
1195 This is a format string, the first %s will receive the UP link,
1196 the second the HOME link. If both `org-html-link-up' and
1197 `org-html-link-home' are empty, the entire snippet will be
1198 ignored."
1199 :group 'org-export-html
1200 :type 'string)
1202 ;;;; Template :: Scripts
1204 (define-obsolete-variable-alias
1205 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1206 (defcustom org-html-head-include-scripts t
1207 "Non-nil means include the JavaScript snippets in exported HTML files.
1208 The actual script is defined in `org-html-scripts' and should
1209 not be modified."
1210 :group 'org-export-html
1211 :version "24.4"
1212 :package-version '(Org . "8.0")
1213 :type 'boolean)
1215 ;;;; Template :: Styles
1217 (define-obsolete-variable-alias
1218 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1219 (defcustom org-html-head-include-default-style t
1220 "Non-nil means include the default style in exported HTML files.
1221 The actual style is defined in `org-html-style-default' and
1222 should not be modified. Use `org-html-head' to use your own
1223 style information."
1224 :group 'org-export-html
1225 :version "24.4"
1226 :package-version '(Org . "8.0")
1227 :type 'boolean)
1228 ;;;###autoload
1229 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1231 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1232 (defcustom org-html-head ""
1233 "Org-wide head definitions for exported HTML files.
1235 This variable can contain the full HTML structure to provide a
1236 style, including the surrounding HTML tags. You can consider
1237 including definitions for the following classes: title, todo,
1238 done, timestamp, timestamp-kwd, tag, target.
1240 For example, a valid value would be:
1242 <style type=\"text/css\">
1243 <![CDATA[
1244 p { font-weight: normal; color: gray; }
1245 h1 { color: black; }
1246 .title { text-align: center; }
1247 .todo, .timestamp-kwd { color: red; }
1248 .done { color: green; }
1250 </style>
1252 If you want to refer to an external style, use something like
1254 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1256 As the value of this option simply gets inserted into the HTML
1257 <head> header, you can use it to add any arbitrary text to the
1258 header.
1260 You can set this on a per-file basis using #+HTML_HEAD:,
1261 or for publication projects using the :html-head property."
1262 :group 'org-export-html
1263 :version "24.4"
1264 :package-version '(Org . "8.0")
1265 :type 'string)
1266 ;;;###autoload
1267 (put 'org-html-head 'safe-local-variable 'stringp)
1269 (defcustom org-html-head-extra ""
1270 "More head information to add in the HTML output.
1272 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1273 or for publication projects using the :html-head-extra property."
1274 :group 'org-export-html
1275 :version "24.4"
1276 :package-version '(Org . "8.0")
1277 :type 'string)
1278 ;;;###autoload
1279 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1281 ;;;; Todos
1283 (defcustom org-html-todo-kwd-class-prefix ""
1284 "Prefix to class names for TODO keywords.
1285 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1286 The default prefix is empty because it is nice to just use the keyword
1287 as a class name. But if you get into conflicts with other, existing
1288 CSS classes, then this prefix can be very useful."
1289 :group 'org-export-html
1290 :type 'string)
1293 ;;; Internal Functions
1295 (defun org-html-xhtml-p (info)
1296 (let ((dt (downcase (plist-get info :html-doctype))))
1297 (string-match-p "xhtml" dt)))
1299 (defun org-html-html5-p (info)
1300 (let ((dt (downcase (plist-get info :html-doctype))))
1301 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1303 (defun org-html-close-tag (tag attr info)
1304 (concat "<" tag " " attr
1305 (if (org-html-xhtml-p info) " />" ">")))
1307 (defun org-html--make-attribute-string (attributes)
1308 "Return a list of attributes, as a string.
1309 ATTRIBUTES is a plist where values are either strings or nil. An
1310 attributes with a nil value will be omitted from the result."
1311 (let (output)
1312 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1313 (cond ((null item) (pop output))
1314 ((symbolp item) (push (substring (symbol-name item) 1) output))
1315 (t (let ((key (car output))
1316 (value (replace-regexp-in-string
1317 "\"" "&quot;" (org-html-encode-plain-text item))))
1318 (setcar output (format "%s=\"%s\"" key value))))))))
1320 (defun org-html-format-inline-image (src info &optional
1321 caption label attr standalone-p)
1322 "Format an inline image from SRC.
1323 CAPTION, LABEL and ATTR are optional arguments providing the
1324 caption, the label and the attribute of the image.
1325 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1326 (let* ((id (if (not label) ""
1327 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1328 (attr (concat attr
1329 (format " src=\"%s\"" src)
1330 (cond
1331 ((string-match "\\<alt=" (or attr "")) "")
1332 ((string-match "^ltxpng/" src)
1333 (format " alt=\"%s\""
1334 (org-html-encode-plain-text
1335 (org-find-text-property-in-string
1336 'org-latex-src src))))
1337 (t (format " alt=\"%s\""
1338 (file-name-nondirectory src))))))
1339 (html5-fancy (and (org-html-html5-p info)
1340 (plist-get info :html-html5-fancy))))
1341 (cond
1342 (standalone-p
1343 (let ((img (org-html-close-tag "img" attr info)))
1344 (format (if html5-fancy
1345 "\n<figure%s>%s%s\n</figure>"
1346 "\n<div%s class=\"figure\">%s%s\n</div>")
1347 id (format "\n<p>%s</p>" img)
1348 (if (and caption (not (string= caption "")))
1349 (format (if html5-fancy
1350 "\n<figcaption>%s</figcaption>"
1351 "\n<p>%s</p>") caption) ""))))
1352 (t (org-html-close-tag "img" (concat attr id) info)))))
1354 (defun org-html--textarea-block (element)
1355 "Transcode ELEMENT into a textarea block.
1356 ELEMENT is either a src block or an example block."
1357 (let* ((code (car (org-export-unravel-code element)))
1358 (attr (org-export-read-attribute :attr_html element)))
1359 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1360 (or (plist-get attr :width) 80)
1361 (or (plist-get attr :height) (org-count-lines code))
1362 code)))
1364 ;;;; Bibliography
1366 (defun org-html-bibliography ()
1367 "Find bibliography, cut it out and return it."
1368 (catch 'exit
1369 (let (beg end (cnt 1) bib)
1370 (save-excursion
1371 (goto-char (point-min))
1372 (when (re-search-forward
1373 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1374 (setq beg (match-beginning 0))
1375 (while (re-search-forward "</?div\\>" nil t)
1376 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1377 (when (= cnt 0)
1378 (and (looking-at ">") (forward-char 1))
1379 (setq bib (buffer-substring beg (point)))
1380 (delete-region beg (point))
1381 (throw 'exit bib))))
1382 nil))))
1384 ;;;; Table
1386 (defun org-html-htmlize-region-for-paste (beg end)
1387 "Convert the region between BEG and END to HTML, using htmlize.el.
1388 This is much like `htmlize-region-for-paste', only that it uses
1389 the settings define in the org-... variables."
1390 (let* ((htmlize-output-type org-html-htmlize-output-type)
1391 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1392 (htmlbuf (htmlize-region beg end)))
1393 (unwind-protect
1394 (with-current-buffer htmlbuf
1395 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1396 (plist-get htmlize-buffer-places 'content-end)))
1397 (kill-buffer htmlbuf))))
1399 ;;;###autoload
1400 (defun org-html-htmlize-generate-css ()
1401 "Create the CSS for all font definitions in the current Emacs session.
1402 Use this to create face definitions in your CSS style file that can then
1403 be used by code snippets transformed by htmlize.
1404 This command just produces a buffer that contains class definitions for all
1405 faces used in the current Emacs session. You can copy and paste the ones you
1406 need into your CSS file.
1408 If you then set `org-html-htmlize-output-type' to `css', calls
1409 to the function `org-html-htmlize-region-for-paste' will
1410 produce code that uses these same face definitions."
1411 (interactive)
1412 (require 'htmlize)
1413 (and (get-buffer "*html*") (kill-buffer "*html*"))
1414 (with-temp-buffer
1415 (let ((fl (face-list))
1416 (htmlize-css-name-prefix "org-")
1417 (htmlize-output-type 'css)
1418 f i)
1419 (while (setq f (pop fl)
1420 i (and f (face-attribute f :inherit)))
1421 (when (and (symbolp f) (or (not i) (not (listp i))))
1422 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1423 (htmlize-region (point-min) (point-max))))
1424 (org-pop-to-buffer-same-window "*html*")
1425 (goto-char (point-min))
1426 (if (re-search-forward "<style" nil t)
1427 (delete-region (point-min) (match-beginning 0)))
1428 (if (re-search-forward "</style>" nil t)
1429 (delete-region (1+ (match-end 0)) (point-max)))
1430 (beginning-of-line 1)
1431 (if (looking-at " +") (replace-match ""))
1432 (goto-char (point-min)))
1434 (defun org-html--make-string (n string)
1435 "Build a string by concatenating N times STRING."
1436 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1438 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1439 "Turn todo keyword KWD into a valid class name.
1440 Replaces invalid characters with \"_\"."
1441 (save-match-data
1442 (while (string-match "[^a-zA-Z0-9_]" kwd)
1443 (setq kwd (replace-match "_" t t kwd))))
1444 kwd)
1446 (defun org-html-format-footnote-reference (n def refcnt)
1447 "Format footnote reference N with definition DEF into HTML."
1448 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1449 (format org-html-footnote-format
1450 (let* ((id (format "fnr.%s%s" n extra))
1451 (href (format " href=\"#fn.%s\"" n))
1452 (attributes (concat " class=\"footref\"" href)))
1453 (org-html--anchor id n attributes)))))
1455 (defun org-html-format-footnotes-section (section-name definitions)
1456 "Format footnotes section SECTION-NAME."
1457 (if (not definitions) ""
1458 (format org-html-footnotes-section section-name definitions)))
1460 (defun org-html-format-footnote-definition (fn)
1461 "Format the footnote definition FN."
1462 (let ((n (car fn)) (def (cdr fn)))
1463 (format
1464 "<div class=\"footdef\">%s %s</div>\n"
1465 (format org-html-footnote-format
1466 (let* ((id (format "fn.%s" n))
1467 (href (format " href=\"#fnr.%s\"" n))
1468 (attributes (concat " class=\"footnum\"" href)))
1469 (org-html--anchor id n attributes)))
1470 def)))
1472 (defun org-html-footnote-section (info)
1473 "Format the footnote section.
1474 INFO is a plist used as a communication channel."
1475 (let* ((fn-alist (org-export-collect-footnote-definitions
1476 (plist-get info :parse-tree) info))
1477 (fn-alist
1478 (loop for (n type raw) in fn-alist collect
1479 (cons n (if (eq (org-element-type raw) 'org-data)
1480 (org-trim (org-export-data raw info))
1481 (format "<p>%s</p>"
1482 (org-trim (org-export-data raw info))))))))
1483 (when fn-alist
1484 (org-html-format-footnotes-section
1485 (org-html--translate "Footnotes" info)
1486 (format
1487 "\n%s\n"
1488 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1491 ;;; Template
1493 (defun org-html--build-meta-info (info)
1494 "Return meta tags for exported document.
1495 INFO is a plist used as a communication channel."
1496 (let ((protect-string
1497 (lambda (str)
1498 (replace-regexp-in-string
1499 "\"" "&quot;" (org-html-encode-plain-text str))))
1500 (title (org-export-data (plist-get info :title) info))
1501 (author (and (plist-get info :with-author)
1502 (let ((auth (plist-get info :author)))
1503 (and auth
1504 ;; Return raw Org syntax, skipping non
1505 ;; exportable objects.
1506 (org-element-interpret-data
1507 (org-element-map auth
1508 (cons 'plain-text org-element-all-objects)
1509 'identity info))))))
1510 (description (plist-get info :description))
1511 (keywords (plist-get info :keywords))
1512 (charset (or (and org-html-coding-system
1513 (fboundp 'coding-system-get)
1514 (coding-system-get org-html-coding-system
1515 'mime-charset))
1516 "iso-8859-1")))
1517 (concat
1518 (format "<title>%s</title>\n" title)
1519 (format
1520 (when :time-stamp-file
1521 (format-time-string
1522 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
1523 (format
1524 (if (org-html-html5-p info)
1525 (org-html-close-tag "meta" " charset=\"%s\"" info)
1526 (org-html-close-tag
1527 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1528 info))
1529 charset) "\n"
1530 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1531 "\n"
1532 (and (org-string-nw-p author)
1533 (org-html-close-tag "meta"
1534 (format " name=\"author\" content=\"%s\""
1535 (funcall protect-string author))
1536 info)
1537 "\n")
1538 (and (org-string-nw-p description)
1539 (org-html-close-tag "meta"
1540 (format " name=\"description\" content=\"%s\"\n"
1541 (funcall protect-string description))
1542 info)
1543 "\n")
1544 (and (org-string-nw-p keywords)
1545 (org-html-close-tag "meta"
1546 (format " name=\"keywords\" content=\"%s\""
1547 (funcall protect-string keywords))
1548 info)
1549 "\n"))))
1551 (defun org-html--build-head (info)
1552 "Return information for the <head>..</head> of the HTML output.
1553 INFO is a plist used as a communication channel."
1554 (org-element-normalize-string
1555 (concat
1556 (when (plist-get info :html-head-include-default-style)
1557 (org-element-normalize-string org-html-style-default))
1558 (org-element-normalize-string (plist-get info :html-head))
1559 (org-element-normalize-string (plist-get info :html-head-extra))
1560 (when (and (plist-get info :html-htmlized-css-url)
1561 (eq org-html-htmlize-output-type 'css))
1562 (org-html-close-tag "link"
1563 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1564 (plist-get info :html-htmlized-css-url))
1565 info))
1566 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1568 (defun org-html--build-mathjax-config (info)
1569 "Insert the user setup into the mathjax template.
1570 INFO is a plist used as a communication channel."
1571 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1572 (org-element-map (plist-get info :parse-tree)
1573 '(latex-fragment latex-environment) 'identity info t))
1574 (let ((template org-html-mathjax-template)
1575 (options org-html-mathjax-options)
1576 (in-buffer (or (plist-get info :html-mathjax) ""))
1577 name val (yes " ") (no "// ") x)
1578 (mapc
1579 (lambda (e)
1580 (setq name (car e) val (nth 1 e))
1581 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1582 (setq val (car (read-from-string
1583 (substring in-buffer (match-end 0))))))
1584 (if (not (stringp val)) (setq val (format "%s" val)))
1585 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1586 (setq template (replace-match val t t template))))
1587 options)
1588 (setq val (nth 1 (assq 'mathml options)))
1589 (if (string-match (concat "\\<mathml:") in-buffer)
1590 (setq val (car (read-from-string
1591 (substring in-buffer (match-end 0))))))
1592 ;; Exchange prefixes depending on mathml setting.
1593 (if (not val) (setq x yes yes no no x))
1594 ;; Replace cookies to turn on or off the config/jax lines.
1595 (if (string-match ":MMLYES:" template)
1596 (setq template (replace-match yes t t template)))
1597 (if (string-match ":MMLNO:" template)
1598 (setq template (replace-match no t t template)))
1599 ;; Return the modified template.
1600 (org-element-normalize-string template))))
1602 (defun org-html-format-spec (info)
1603 "Return format specification for elements that can be
1604 used in the preamble or postamble."
1605 `((?t . ,(org-export-data (plist-get info :title) info))
1606 (?d . ,(org-export-data (org-export-get-date info) info))
1607 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1608 (?a . ,(org-export-data (plist-get info :author) info))
1609 (?e . ,(mapconcat
1610 (lambda (e)
1611 (format "<a href=\"mailto:%s\">%s</a>" e e))
1612 (split-string (plist-get info :email) ",+ *")
1613 ", "))
1614 (?c . ,(plist-get info :creator))
1615 (?C . ,(let ((file (plist-get info :input-file)))
1616 (format-time-string org-html-metadata-timestamp-format
1617 (if file (nth 5 (file-attributes file))
1618 (current-time)))))
1619 (?v . ,(or org-html-validation-link ""))))
1621 (defun org-html--build-pre/postamble (type info)
1622 "Return document preamble or postamble as a string, or nil.
1623 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1624 communication channel."
1625 (let ((section (plist-get info (intern (format ":html-%s" type))))
1626 (spec (org-html-format-spec info)))
1627 (when section
1628 (let ((section-contents
1629 (if (functionp section) (funcall section info)
1630 (cond
1631 ((stringp section) (format-spec section spec))
1632 ((eq section 'auto)
1633 (let ((date (cdr (assq ?d spec)))
1634 (author (cdr (assq ?a spec)))
1635 (email (cdr (assq ?e spec)))
1636 (creator (cdr (assq ?c spec)))
1637 (timestamp (cdr (assq ?T spec)))
1638 (validation-link (cdr (assq ?v spec))))
1639 (concat
1640 (when (and (plist-get info :with-date)
1641 (org-string-nw-p date))
1642 (format "<p class=\"date\">%s: %s</p>\n"
1643 (org-html--translate "Date" info)
1644 date))
1645 (when (and (plist-get info :with-author)
1646 (org-string-nw-p author))
1647 (format "<p class=\"author\">%s: %s</p>\n"
1648 (org-html--translate "Author" info)
1649 author))
1650 (when (and (plist-get info :with-email)
1651 (org-string-nw-p email))
1652 (format "<p class=\"email\">%s: %s</p>\n"
1653 (org-html--translate "Email" info)
1654 email))
1655 (when (plist-get info :time-stamp-file)
1656 (format
1657 "<p class=\"date\">%s: %s</p>\n"
1658 (org-html--translate "Created" info)
1659 (format-time-string org-html-metadata-timestamp-format)))
1660 (when (plist-get info :with-creator)
1661 (format "<p class=\"creator\">%s</p>\n" creator))
1662 (format "<p class=\"validation\">%s</p>\n"
1663 validation-link))))
1664 (t (format-spec
1665 (or (cadr (assoc
1666 (plist-get info :language)
1667 (eval (intern
1668 (format "org-html-%s-format" type)))))
1669 (cadr
1670 (assoc
1671 "en"
1672 (eval
1673 (intern (format "org-html-%s-format" type))))))
1674 spec))))))
1675 (when (org-string-nw-p section-contents)
1676 (concat
1677 (format "<%s id=\"%s\" class=\"%s\">\n"
1678 (nth 1 (assq type org-html-divs))
1679 (nth 2 (assq type org-html-divs))
1680 org-html--pre/postamble-class)
1681 (org-element-normalize-string section-contents)
1682 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1684 (defun org-html-inner-template (contents info)
1685 "Return body of document string after HTML conversion.
1686 CONTENTS is the transcoded contents string. INFO is a plist
1687 holding export options."
1688 (concat
1689 ;; Table of contents.
1690 (let ((depth (plist-get info :with-toc)))
1691 (when depth (org-html-toc depth info)))
1692 ;; Document contents.
1693 contents
1694 ;; Footnotes section.
1695 (org-html-footnote-section info)
1696 ;; Bibliography.
1697 (org-html-bibliography)))
1699 (defun org-html-template (contents info)
1700 "Return complete document string after HTML conversion.
1701 CONTENTS is the transcoded contents string. INFO is a plist
1702 holding export options."
1703 (concat
1704 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1705 (let ((decl (or (and (stringp org-html-xml-declaration)
1706 org-html-xml-declaration)
1707 (cdr (assoc (plist-get info :html-extension)
1708 org-html-xml-declaration))
1709 (cdr (assoc "html" org-html-xml-declaration))
1711 "")))
1712 (when (not (or (eq nil decl) (string= "" decl)))
1713 (format "%s\n"
1714 (format decl
1715 (or (and org-html-coding-system
1716 (fboundp 'coding-system-get)
1717 (coding-system-get org-html-coding-system 'mime-charset))
1718 "iso-8859-1"))))))
1719 (let* ((dt (plist-get info :html-doctype))
1720 (dt-cons (assoc dt org-html-doctype-alist)))
1721 (if dt-cons
1722 (cdr dt-cons)
1723 dt))
1724 "\n"
1725 (concat "<html"
1726 (when (org-html-xhtml-p info)
1727 (format
1728 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1729 (plist-get info :language) (plist-get info :language)))
1730 ">\n")
1731 "<head>\n"
1732 (org-html--build-meta-info info)
1733 (org-html--build-head info)
1734 (org-html--build-mathjax-config info)
1735 "</head>\n"
1736 "<body>\n"
1737 (let ((link-up (org-trim (plist-get info :html-link-up)))
1738 (link-home (org-trim (plist-get info :html-link-home))))
1739 (unless (and (string= link-up "") (string= link-up ""))
1740 (format org-html-home/up-format
1741 (or link-up link-home)
1742 (or link-home link-up))))
1743 ;; Preamble.
1744 (org-html--build-pre/postamble 'preamble info)
1745 ;; Document contents.
1746 (format "<%s id=\"%s\">\n"
1747 (nth 1 (assq 'content org-html-divs))
1748 (nth 2 (assq 'content org-html-divs)))
1749 ;; Document title.
1750 (let ((title (plist-get info :title)))
1751 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1752 contents
1753 (format "</%s>\n"
1754 (nth 1 (assq 'content org-html-divs)))
1755 ;; Postamble.
1756 (org-html--build-pre/postamble 'postamble info)
1757 ;; Closing document.
1758 "</body>\n</html>"))
1760 (defun org-html--translate (s info)
1761 "Translate string S according to specified language.
1762 INFO is a plist used as a communication channel."
1763 (org-export-translate s :html info))
1765 ;;;; Anchor
1767 (defun org-html--anchor (&optional id desc attributes)
1768 "Format a HTML anchor."
1769 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1770 (attributes (concat (and id (format " id=\"%s\"" id))
1771 (and name (format " name=\"%s\"" name))
1772 attributes)))
1773 (format "<a%s>%s</a>" attributes (or desc ""))))
1775 ;;;; Todo
1777 (defun org-html--todo (todo)
1778 "Format TODO keywords into HTML."
1779 (when todo
1780 (format "<span class=\"%s %s%s\">%s</span>"
1781 (if (member todo org-done-keywords) "done" "todo")
1782 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1783 todo)))
1785 ;;;; Tags
1787 (defun org-html--tags (tags)
1788 "Format TAGS into HTML."
1789 (when tags
1790 (format "<span class=\"tag\">%s</span>"
1791 (mapconcat
1792 (lambda (tag)
1793 (format "<span class=\"%s\">%s</span>"
1794 (concat org-html-tag-class-prefix
1795 (org-html-fix-class-name tag))
1796 tag))
1797 tags "&#xa0;"))))
1799 ;;;; Headline
1801 (defun* org-html-format-headline
1802 (todo todo-type priority text tags
1803 &key level section-number headline-label &allow-other-keys)
1804 "Format a headline in HTML."
1805 (let ((section-number
1806 (when section-number
1807 (format "<span class=\"section-number-%d\">%s</span> "
1808 level section-number)))
1809 (todo (org-html--todo todo))
1810 (tags (org-html--tags tags)))
1811 (concat section-number todo (and todo " ") text
1812 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1814 ;;;; Src Code
1816 (defun org-html-fontify-code (code lang)
1817 "Color CODE with htmlize library.
1818 CODE is a string representing the source code to colorize. LANG
1819 is the language used for CODE, as a string, or nil."
1820 (when code
1821 (cond
1822 ;; Case 1: No lang. Possibly an example block.
1823 ((not lang)
1824 ;; Simple transcoding.
1825 (org-html-encode-plain-text code))
1826 ;; Case 2: No htmlize or an inferior version of htmlize
1827 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1828 ;; Emit a warning.
1829 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1830 ;; Simple transcoding.
1831 (org-html-encode-plain-text code))
1833 ;; Map language
1834 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1835 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1836 (cond
1837 ;; Case 1: Language is not associated with any Emacs mode
1838 ((not (functionp lang-mode))
1839 ;; Simple transcoding.
1840 (org-html-encode-plain-text code))
1841 ;; Case 2: Default. Fontify code.
1843 ;; htmlize
1844 (setq code (with-temp-buffer
1845 ;; Switch to language-specific mode.
1846 (funcall lang-mode)
1847 (insert code)
1848 ;; Fontify buffer.
1849 (font-lock-fontify-buffer)
1850 ;; Remove formatting on newline characters.
1851 (save-excursion
1852 (let ((beg (point-min))
1853 (end (point-max)))
1854 (goto-char beg)
1855 (while (progn (end-of-line) (< (point) end))
1856 (put-text-property (point) (1+ (point)) 'face nil)
1857 (forward-char 1))))
1858 (org-src-mode)
1859 (set-buffer-modified-p nil)
1860 ;; Htmlize region.
1861 (org-html-htmlize-region-for-paste
1862 (point-min) (point-max))))
1863 ;; Strip any enclosing <pre></pre> tags.
1864 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1865 (end (and beg (string-match "</pre>\\'" code))))
1866 (if (and beg end) (substring code beg end) code)))))))))
1868 (defun org-html-do-format-code
1869 (code &optional lang refs retain-labels num-start)
1870 "Format CODE string as source code.
1871 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1872 respectively, the language of the source code, as a string, an
1873 alist between line numbers and references (as returned by
1874 `org-export-unravel-code'), a boolean specifying if labels should
1875 appear in the source code, and the number associated to the first
1876 line of code."
1877 (let* ((code-lines (org-split-string code "\n"))
1878 (code-length (length code-lines))
1879 (num-fmt
1880 (and num-start
1881 (format "%%%ds: "
1882 (length (number-to-string (+ code-length num-start))))))
1883 (code (org-html-fontify-code code lang)))
1884 (org-export-format-code
1885 code
1886 (lambda (loc line-num ref)
1887 (setq loc
1888 (concat
1889 ;; Add line number, if needed.
1890 (when num-start
1891 (format "<span class=\"linenr\">%s</span>"
1892 (format num-fmt line-num)))
1893 ;; Transcoded src line.
1895 ;; Add label, if needed.
1896 (when (and ref retain-labels) (format " (%s)" ref))))
1897 ;; Mark transcoded line as an anchor, if needed.
1898 (if (not ref) loc
1899 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1900 ref loc)))
1901 num-start refs)))
1903 (defun org-html-format-code (element info)
1904 "Format contents of ELEMENT as source code.
1905 ELEMENT is either an example block or a src block. INFO is
1906 a plist used as a communication channel."
1907 (let* ((lang (org-element-property :language element))
1908 ;; Extract code and references.
1909 (code-info (org-export-unravel-code element))
1910 (code (car code-info))
1911 (refs (cdr code-info))
1912 ;; Does the src block contain labels?
1913 (retain-labels (org-element-property :retain-labels element))
1914 ;; Does it have line numbers?
1915 (num-start (case (org-element-property :number-lines element)
1916 (continued (org-export-get-loc element info))
1917 (new 0))))
1918 (org-html-do-format-code code lang refs retain-labels num-start)))
1921 ;;; Tables of Contents
1923 (defun org-html-toc (depth info)
1924 "Build a table of contents.
1925 DEPTH is an integer specifying the depth of the table. INFO is a
1926 plist used as a communication channel. Return the table of
1927 contents as a string, or nil if it is empty."
1928 (let ((toc-entries
1929 (mapcar (lambda (headline)
1930 (cons (org-html--format-toc-headline headline info)
1931 (org-export-get-relative-level headline info)))
1932 (org-export-collect-headlines info depth))))
1933 (when toc-entries
1934 (concat "<div id=\"table-of-contents\">\n"
1935 (format "<h%d>%s</h%d>\n"
1936 org-html-toplevel-hlevel
1937 (org-html--translate "Table of Contents" info)
1938 org-html-toplevel-hlevel)
1939 "<div id=\"text-table-of-contents\">"
1940 (org-html--toc-text toc-entries)
1941 "</div>\n"
1942 "</div>\n"))))
1944 (defun org-html--toc-text (toc-entries)
1945 "Return innards of a table of contents, as a string.
1946 TOC-ENTRIES is an alist where key is an entry title, as a string,
1947 and value is its relative level, as an integer."
1948 (let* ((prev-level (1- (cdar toc-entries)))
1949 (start-level prev-level))
1950 (concat
1951 (mapconcat
1952 (lambda (entry)
1953 (let ((headline (car entry))
1954 (level (cdr entry)))
1955 (concat
1956 (let* ((cnt (- level prev-level))
1957 (times (if (> cnt 0) (1- cnt) (- cnt)))
1958 rtn)
1959 (setq prev-level level)
1960 (concat
1961 (org-html--make-string
1962 times (cond ((> cnt 0) "\n<ul>\n<li>")
1963 ((< cnt 0) "</li>\n</ul>\n")))
1964 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1965 headline)))
1966 toc-entries "")
1967 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1969 (defun org-html--format-toc-headline (headline info)
1970 "Return an appropriate table of contents entry for HEADLINE.
1971 INFO is a plist used as a communication channel."
1972 (let* ((headline-number (org-export-get-headline-number headline info))
1973 (section-number
1974 (and (not (org-export-low-level-p headline info))
1975 (org-export-numbered-headline-p headline info)
1976 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1977 (tags (and (eq (plist-get info :with-tags) t)
1978 (org-export-get-tags headline info))))
1979 (format "<a href=\"#%s\">%s</a>"
1980 ;; Label.
1981 (org-export-solidify-link-text
1982 (or (org-element-property :CUSTOM_ID headline)
1983 (concat "sec-" (mapconcat 'number-to-string
1984 headline-number "-"))))
1985 ;; Body.
1986 (concat section-number
1987 (org-export-data-with-translations
1988 (org-export-get-alt-title headline info)
1989 ;; Ignore any footnote-reference, link,
1990 ;; radio-target and target in table of contents.
1991 (append
1992 '((footnote-reference . ignore)
1993 (link . (lambda (link desc i) desc))
1994 (radio-target . (lambda (radio desc i) desc))
1995 (target . ignore))
1996 (org-export-backend-translate-table 'html))
1997 info)
1998 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
2000 (defun org-html-list-of-listings (info)
2001 "Build a list of listings.
2002 INFO is a plist used as a communication channel. Return the list
2003 of listings as a string, or nil if it is empty."
2004 (let ((lol-entries (org-export-collect-listings info)))
2005 (when lol-entries
2006 (concat "<div id=\"list-of-listings\">\n"
2007 (format "<h%d>%s</h%d>\n"
2008 org-html-toplevel-hlevel
2009 (org-html--translate "List of Listings" info)
2010 org-html-toplevel-hlevel)
2011 "<div id=\"text-list-of-listings\">\n<ul>\n"
2012 (let ((count 0)
2013 (initial-fmt (org-html--translate "Listing %d:" info)))
2014 (mapconcat
2015 (lambda (entry)
2016 (let ((label (org-element-property :name entry))
2017 (title (org-trim
2018 (org-export-data
2019 (or (org-export-get-caption entry t)
2020 (org-export-get-caption entry))
2021 info))))
2022 (concat
2023 "<li>"
2024 (if (not label)
2025 (concat (format initial-fmt (incf count)) " " title)
2026 (format "<a href=\"#%s\">%s %s</a>"
2027 (org-export-solidify-link-text label)
2028 (format initial-fmt (incf count))
2029 title))
2030 "</li>")))
2031 lol-entries "\n"))
2032 "\n</ul>\n</div>\n</div>"))))
2034 (defun org-html-list-of-tables (info)
2035 "Build a list of tables.
2036 INFO is a plist used as a communication channel. Return the list
2037 of tables as a string, or nil if it is empty."
2038 (let ((lol-entries (org-export-collect-tables info)))
2039 (when lol-entries
2040 (concat "<div id=\"list-of-tables\">\n"
2041 (format "<h%d>%s</h%d>\n"
2042 org-html-toplevel-hlevel
2043 (org-html--translate "List of Tables" info)
2044 org-html-toplevel-hlevel)
2045 "<div id=\"text-list-of-tables\">\n<ul>\n"
2046 (let ((count 0)
2047 (initial-fmt (org-html--translate "Table %d:" info)))
2048 (mapconcat
2049 (lambda (entry)
2050 (let ((label (org-element-property :name entry))
2051 (title (org-trim
2052 (org-export-data
2053 (or (org-export-get-caption entry t)
2054 (org-export-get-caption entry))
2055 info))))
2056 (concat
2057 "<li>"
2058 (if (not label)
2059 (concat (format initial-fmt (incf count)) " " title)
2060 (format "<a href=\"#%s\">%s %s</a>"
2061 (org-export-solidify-link-text label)
2062 (format initial-fmt (incf count))
2063 title))
2064 "</li>")))
2065 lol-entries "\n"))
2066 "\n</ul>\n</div>\n</div>"))))
2069 ;;; Transcode Functions
2071 ;;;; Bold
2073 (defun org-html-bold (bold contents info)
2074 "Transcode BOLD from Org to HTML.
2075 CONTENTS is the text with bold markup. INFO is a plist holding
2076 contextual information."
2077 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
2078 contents))
2080 ;;;; Center Block
2082 (defun org-html-center-block (center-block contents info)
2083 "Transcode a CENTER-BLOCK element from Org to HTML.
2084 CONTENTS holds the contents of the block. INFO is a plist
2085 holding contextual information."
2086 (format "<div class=\"center\">\n%s</div>" contents))
2088 ;;;; Clock
2090 (defun org-html-clock (clock contents info)
2091 "Transcode a CLOCK element from Org to HTML.
2092 CONTENTS is nil. INFO is a plist used as a communication
2093 channel."
2094 (format "<p>
2095 <span class=\"timestamp-wrapper\">
2096 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2097 </span>
2098 </p>"
2099 org-clock-string
2100 (org-translate-time
2101 (org-element-property :raw-value
2102 (org-element-property :value clock)))
2103 (let ((time (org-element-property :duration clock)))
2104 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2106 ;;;; Code
2108 (defun org-html-code (code contents info)
2109 "Transcode CODE from Org to HTML.
2110 CONTENTS is nil. INFO is a plist holding contextual
2111 information."
2112 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2113 (org-html-plain-text (org-element-property :value code) info)))
2115 ;;;; Drawer
2117 (defun org-html-drawer (drawer contents info)
2118 "Transcode a DRAWER element from Org to HTML.
2119 CONTENTS holds the contents of the block. INFO is a plist
2120 holding contextual information."
2121 (if (functionp org-html-format-drawer-function)
2122 (funcall org-html-format-drawer-function
2123 (org-element-property :drawer-name drawer)
2124 contents)
2125 ;; If there's no user defined function: simply
2126 ;; display contents of the drawer.
2127 contents))
2129 ;;;; Dynamic Block
2131 (defun org-html-dynamic-block (dynamic-block contents info)
2132 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2133 CONTENTS holds the contents of the block. INFO is a plist
2134 holding contextual information. See `org-export-data'."
2135 contents)
2137 ;;;; Entity
2139 (defun org-html-entity (entity contents info)
2140 "Transcode an ENTITY object from Org to HTML.
2141 CONTENTS are the definition itself. INFO is a plist holding
2142 contextual information."
2143 (org-element-property :html entity))
2145 ;;;; Example Block
2147 (defun org-html-example-block (example-block contents info)
2148 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2149 CONTENTS is nil. INFO is a plist holding contextual
2150 information."
2151 (if (org-export-read-attribute :attr_html example-block :textarea)
2152 (org-html--textarea-block example-block)
2153 (format "<pre class=\"example\">\n%s</pre>"
2154 (org-html-format-code example-block info))))
2156 ;;;; Export Snippet
2158 (defun org-html-export-snippet (export-snippet contents info)
2159 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2160 CONTENTS is nil. INFO is a plist holding contextual
2161 information."
2162 (when (eq (org-export-snippet-backend export-snippet) 'html)
2163 (org-element-property :value export-snippet)))
2165 ;;;; Export Block
2167 (defun org-html-export-block (export-block contents info)
2168 "Transcode a EXPORT-BLOCK element from Org to HTML.
2169 CONTENTS is nil. INFO is a plist holding contextual information."
2170 (when (string= (org-element-property :type export-block) "HTML")
2171 (org-remove-indentation (org-element-property :value export-block))))
2173 ;;;; Fixed Width
2175 (defun org-html-fixed-width (fixed-width contents info)
2176 "Transcode a FIXED-WIDTH element from Org to HTML.
2177 CONTENTS is nil. INFO is a plist holding contextual information."
2178 (format "<pre class=\"example\">\n%s</pre>"
2179 (org-html-do-format-code
2180 (org-remove-indentation
2181 (org-element-property :value fixed-width)))))
2183 ;;;; Footnote Reference
2185 (defun org-html-footnote-reference (footnote-reference contents info)
2186 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2187 CONTENTS is nil. INFO is a plist holding contextual information."
2188 (concat
2189 ;; Insert separator between two footnotes in a row.
2190 (let ((prev (org-export-get-previous-element footnote-reference info)))
2191 (when (eq (org-element-type prev) 'footnote-reference)
2192 org-html-footnote-separator))
2193 (cond
2194 ((not (org-export-footnote-first-reference-p footnote-reference info))
2195 (org-html-format-footnote-reference
2196 (org-export-get-footnote-number footnote-reference info)
2197 "IGNORED" 100))
2198 ;; Inline definitions are secondary strings.
2199 ((eq (org-element-property :type footnote-reference) 'inline)
2200 (org-html-format-footnote-reference
2201 (org-export-get-footnote-number footnote-reference info)
2202 "IGNORED" 1))
2203 ;; Non-inline footnotes definitions are full Org data.
2204 (t (org-html-format-footnote-reference
2205 (org-export-get-footnote-number footnote-reference info)
2206 "IGNORED" 1)))))
2208 ;;;; Headline
2210 (defun org-html-format-headline--wrap
2211 (headline info &optional format-function &rest extra-keys)
2212 "Transcode a HEADLINE element from Org to HTML.
2213 CONTENTS holds the contents of the headline. INFO is a plist
2214 holding contextual information."
2215 (let* ((level (+ (org-export-get-relative-level headline info)
2216 (1- org-html-toplevel-hlevel)))
2217 (headline-number (org-export-get-headline-number headline info))
2218 (section-number (and (not (org-export-low-level-p headline info))
2219 (org-export-numbered-headline-p headline info)
2220 (mapconcat 'number-to-string
2221 headline-number ".")))
2222 (todo (and (plist-get info :with-todo-keywords)
2223 (let ((todo (org-element-property :todo-keyword headline)))
2224 (and todo (org-export-data todo info)))))
2225 (todo-type (and todo (org-element-property :todo-type headline)))
2226 (priority (and (plist-get info :with-priority)
2227 (org-element-property :priority headline)))
2228 (text (org-export-data (org-element-property :title headline) info))
2229 (tags (and (plist-get info :with-tags)
2230 (org-export-get-tags headline info)))
2231 (headline-label (or (org-element-property :CUSTOM_ID headline)
2232 (concat "sec-" (mapconcat 'number-to-string
2233 headline-number "-"))))
2234 (format-function (cond
2235 ((functionp format-function) format-function)
2236 ((functionp org-html-format-headline-function)
2237 (function*
2238 (lambda (todo todo-type priority text tags
2239 &allow-other-keys)
2240 (funcall org-html-format-headline-function
2241 todo todo-type priority text tags))))
2242 (t 'org-html-format-headline))))
2243 (apply format-function
2244 todo todo-type priority text tags
2245 :headline-label headline-label :level level
2246 :section-number section-number extra-keys)))
2248 (defun org-html-headline (headline contents info)
2249 "Transcode a HEADLINE element from Org to HTML.
2250 CONTENTS holds the contents of the headline. INFO is a plist
2251 holding contextual information."
2252 ;; Empty contents?
2253 (setq contents (or contents ""))
2254 (let* ((numberedp (org-export-numbered-headline-p headline info))
2255 (level (org-export-get-relative-level headline info))
2256 (text (org-export-data (org-element-property :title headline) info))
2257 (todo (and (plist-get info :with-todo-keywords)
2258 (let ((todo (org-element-property :todo-keyword headline)))
2259 (and todo (org-export-data todo info)))))
2260 (todo-type (and todo (org-element-property :todo-type headline)))
2261 (tags (and (plist-get info :with-tags)
2262 (org-export-get-tags headline info)))
2263 (priority (and (plist-get info :with-priority)
2264 (org-element-property :priority headline)))
2265 (section-number (and (org-export-numbered-headline-p headline info)
2266 (mapconcat 'number-to-string
2267 (org-export-get-headline-number
2268 headline info) ".")))
2269 ;; Create the headline text.
2270 (full-text (org-html-format-headline--wrap headline info)))
2271 (cond
2272 ;; Case 1: This is a footnote section: ignore it.
2273 ((org-element-property :footnote-section-p headline) nil)
2274 ;; Case 2. This is a deep sub-tree: export it as a list item.
2275 ;; Also export as items headlines for which no section
2276 ;; format has been found.
2277 ((org-export-low-level-p headline info)
2278 ;; Build the real contents of the sub-tree.
2279 (let* ((type (if numberedp 'ordered 'unordered))
2280 (itemized-body (org-html-format-list-item
2281 contents type nil info nil full-text)))
2282 (concat
2283 (and (org-export-first-sibling-p headline info)
2284 (org-html-begin-plain-list type))
2285 itemized-body
2286 (and (org-export-last-sibling-p headline info)
2287 (org-html-end-plain-list type)))))
2288 ;; Case 3. Standard headline. Export it as a section.
2290 (let* ((section-number (mapconcat 'number-to-string
2291 (org-export-get-headline-number
2292 headline info) "-"))
2293 (ids (remove 'nil
2294 (list (org-element-property :CUSTOM_ID headline)
2295 (concat "sec-" section-number)
2296 (org-element-property :ID headline))))
2297 (preferred-id (car ids))
2298 (extra-ids (cdr ids))
2299 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2300 (level1 (+ level (1- org-html-toplevel-hlevel)))
2301 (first-content (car (org-element-contents headline))))
2302 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2303 (org-html--container headline info)
2304 (format "outline-container-%s"
2305 (or (org-element-property :CUSTOM_ID headline)
2306 (concat "sec-" section-number)))
2307 (concat (format "outline-%d" level1) (and extra-class " ")
2308 extra-class)
2309 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2310 level1
2311 preferred-id
2312 (mapconcat
2313 (lambda (x)
2314 (let ((id (org-export-solidify-link-text
2315 (if (org-uuidgen-p x) (concat "ID-" x)
2316 x))))
2317 (org-html--anchor id)))
2318 extra-ids "")
2319 full-text
2320 level1)
2321 ;; When there is no section, pretend there is an empty
2322 ;; one to get the correct <div class="outline- ...>
2323 ;; which is needed by `org-info.js'.
2324 (if (not (eq (org-element-type first-content) 'section))
2325 (concat (org-html-section first-content "" info)
2326 contents)
2327 contents)
2328 (org-html--container headline info)))))))
2330 (defun org-html--container (headline info)
2331 (or (org-element-property :HTML_CONTAINER headline)
2332 (if (= 1 (org-export-get-relative-level headline info))
2333 (plist-get info :html-container)
2334 "div")))
2336 ;;;; Horizontal Rule
2338 (defun org-html-horizontal-rule (horizontal-rule contents info)
2339 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2340 CONTENTS is nil. INFO is a plist holding contextual information."
2341 (org-html-close-tag "hr" nil info))
2343 ;;;; Inline Src Block
2345 (defun org-html-inline-src-block (inline-src-block contents info)
2346 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2347 CONTENTS holds the contents of the item. INFO is a plist holding
2348 contextual information."
2349 (let* ((org-lang (org-element-property :language inline-src-block))
2350 (code (org-element-property :value inline-src-block)))
2351 (error "Cannot export inline src block")))
2353 ;;;; Inlinetask
2355 (defun org-html-format-section (text class &optional id)
2356 "Format a section with TEXT into a HTML div with CLASS and ID."
2357 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2358 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2360 (defun org-html-inlinetask (inlinetask contents info)
2361 "Transcode an INLINETASK element from Org to HTML.
2362 CONTENTS holds the contents of the block. INFO is a plist
2363 holding contextual information."
2364 (cond
2365 ;; If `org-html-format-inlinetask-function' is provided, call it
2366 ;; with appropriate arguments.
2367 ((functionp org-html-format-inlinetask-function)
2368 (let ((format-function
2369 (function*
2370 (lambda (todo todo-type priority text tags
2371 &key contents &allow-other-keys)
2372 (funcall org-html-format-inlinetask-function
2373 todo todo-type priority text tags contents)))))
2374 (org-html-format-headline--wrap
2375 inlinetask info format-function :contents contents)))
2376 ;; Otherwise, use a default template.
2377 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2378 (org-html-format-headline--wrap inlinetask info)
2379 (org-html-close-tag "br" nil info)
2380 contents))))
2382 ;;;; Italic
2384 (defun org-html-italic (italic contents info)
2385 "Transcode ITALIC from Org to HTML.
2386 CONTENTS is the text with italic markup. INFO is a plist holding
2387 contextual information."
2388 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2390 ;;;; Item
2392 (defun org-html-checkbox (checkbox)
2393 "Format CHECKBOX into HTML."
2394 (case checkbox (on "<code>[X]</code>")
2395 (off "<code>[&#xa0;]</code>")
2396 (trans "<code>[-]</code>")
2397 (t "")))
2399 (defun org-html-format-list-item (contents type checkbox info
2400 &optional term-counter-id
2401 headline)
2402 "Format a list item into HTML."
2403 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
2404 (br (org-html-close-tag "br" nil info)))
2405 (concat
2406 (case type
2407 (ordered
2408 (let* ((counter term-counter-id)
2409 (extra (if counter (format " value=\"%s\"" counter) "")))
2410 (concat
2411 (format "<li%s>" extra)
2412 (when headline (concat headline br)))))
2413 (unordered
2414 (let* ((id term-counter-id)
2415 (extra (if id (format " id=\"%s\"" id) "")))
2416 (concat
2417 (format "<li%s>" extra)
2418 (when headline (concat headline br)))))
2419 (descriptive
2420 (let* ((term term-counter-id))
2421 (setq term (or term "(no term)"))
2422 ;; Check-boxes in descriptive lists are associated to tag.
2423 (concat (format "<dt> %s </dt>"
2424 (concat checkbox term))
2425 "<dd>"))))
2426 (unless (eq type 'descriptive) checkbox)
2427 contents
2428 (case type
2429 (ordered "</li>")
2430 (unordered "</li>")
2431 (descriptive "</dd>")))))
2433 (defun org-html-item (item contents info)
2434 "Transcode an ITEM element from Org to HTML.
2435 CONTENTS holds the contents of the item. INFO is a plist holding
2436 contextual information."
2437 (let* ((plain-list (org-export-get-parent item))
2438 (type (org-element-property :type plain-list))
2439 (counter (org-element-property :counter item))
2440 (checkbox (org-element-property :checkbox item))
2441 (tag (let ((tag (org-element-property :tag item)))
2442 (and tag (org-export-data tag info)))))
2443 (org-html-format-list-item
2444 contents type checkbox info (or tag counter))))
2446 ;;;; Keyword
2448 (defun org-html-keyword (keyword contents info)
2449 "Transcode a KEYWORD element from Org to HTML.
2450 CONTENTS is nil. INFO is a plist holding contextual information."
2451 (let ((key (org-element-property :key keyword))
2452 (value (org-element-property :value keyword)))
2453 (cond
2454 ((string= key "HTML") value)
2455 ((string= key "TOC")
2456 (let ((value (downcase value)))
2457 (cond
2458 ((string-match "\\<headlines\\>" value)
2459 (let ((depth (or (and (string-match "[0-9]+" value)
2460 (string-to-number (match-string 0 value)))
2461 (plist-get info :with-toc))))
2462 (org-html-toc depth info)))
2463 ((string= "listings" value) (org-html-list-of-listings info))
2464 ((string= "tables" value) (org-html-list-of-tables info))))))))
2466 ;;;; Latex Environment
2468 (defun org-html-format-latex (latex-frag processing-type)
2469 "Format the LaTeX fragment LATEX-FRAG into HTML."
2470 (let ((cache-relpath "") (cache-dir "") bfn)
2471 (unless (eq processing-type 'mathjax)
2472 (setq bfn (buffer-file-name)
2473 cache-relpath
2474 (concat "ltxpng/"
2475 (file-name-sans-extension
2476 (file-name-nondirectory bfn)))
2477 cache-dir (file-name-directory bfn)))
2478 (with-temp-buffer
2479 (insert latex-frag)
2480 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2481 nil nil processing-type)
2482 (buffer-string))))
2484 (defun org-html-latex-environment (latex-environment contents info)
2485 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2486 CONTENTS is nil. INFO is a plist holding contextual information."
2487 (let ((processing-type (plist-get info :with-latex))
2488 (latex-frag (org-remove-indentation
2489 (org-element-property :value latex-environment)))
2490 (caption (org-export-data
2491 (org-export-get-caption latex-environment) info))
2492 (attr nil) ; FIXME
2493 (label (org-element-property :name latex-environment)))
2494 (cond
2495 ((memq processing-type '(t mathjax))
2496 (org-html-format-latex latex-frag 'mathjax))
2497 ((eq processing-type 'dvipng)
2498 (let* ((formula-link (org-html-format-latex
2499 latex-frag processing-type)))
2500 (when (and formula-link
2501 (string-match "file:\\([^]]*\\)" formula-link))
2502 (org-html-format-inline-image
2503 (match-string 1 formula-link) info caption label attr t))))
2504 (t latex-frag))))
2506 ;;;; Latex Fragment
2508 (defun org-html-latex-fragment (latex-fragment contents info)
2509 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2510 CONTENTS is nil. INFO is a plist holding contextual information."
2511 (let ((latex-frag (org-element-property :value latex-fragment))
2512 (processing-type (plist-get info :with-latex)))
2513 (case processing-type
2514 ((t mathjax)
2515 (org-html-format-latex latex-frag 'mathjax))
2516 (dvipng
2517 (let* ((formula-link (org-html-format-latex
2518 latex-frag processing-type)))
2519 (when (and formula-link
2520 (string-match "file:\\([^]]*\\)" formula-link))
2521 (org-html-format-inline-image
2522 (match-string 1 formula-link) info))))
2523 (t latex-frag))))
2525 ;;;; Line Break
2527 (defun org-html-line-break (line-break contents info)
2528 "Transcode a LINE-BREAK object from Org to HTML.
2529 CONTENTS is nil. INFO is a plist holding contextual information."
2530 (concat (org-html-close-tag "br" nil info) "\n"))
2532 ;;;; Link
2534 (defun org-html-link--inline-image (link desc info)
2535 "Return HTML code for an inline image.
2537 LINK is the link pointing to the inline image. INFO is a plist
2538 used as a communication channel.
2540 Inline images can have these attributes:
2542 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2543 (let* ((type (org-element-property :type link))
2544 (raw-path (org-element-property :path link))
2545 (path (cond ((member type '("http" "https"))
2546 (concat type ":" raw-path))
2547 ((file-name-absolute-p raw-path)
2548 (expand-file-name raw-path))
2549 (t raw-path)))
2550 (parent (org-export-get-parent-element link))
2551 (caption (org-export-data (org-export-get-caption parent) info))
2552 (label (org-element-property :name parent)))
2553 ;; Return proper string, depending on DISPOSITION.
2554 (org-html-format-inline-image
2555 path info caption label
2556 (org-html--make-attribute-string
2557 (org-export-read-attribute :attr_html parent))
2558 (org-html-standalone-image-p link info))))
2560 (defvar org-html-standalone-image-predicate)
2561 (defun org-html-standalone-image-p (element info &optional predicate)
2562 "Test if ELEMENT is a standalone image for the purpose HTML export.
2563 INFO is a plist holding contextual information.
2565 Return non-nil, if ELEMENT is of type paragraph and it's sole
2566 content, save for whitespaces, is a link that qualifies as an
2567 inline image.
2569 Return non-nil, if ELEMENT is of type link and it's containing
2570 paragraph has no other content save for leading and trailing
2571 whitespaces.
2573 Return nil, otherwise.
2575 Bind `org-html-standalone-image-predicate' to constrain
2576 paragraph further. For example, to check for only captioned
2577 standalone images, do the following.
2579 \(setq org-html-standalone-image-predicate
2580 \(lambda \(paragraph\)
2581 \(org-element-property :caption paragraph\)\)\)"
2582 (let ((paragraph (case (org-element-type element)
2583 (paragraph element)
2584 (link (and (org-export-inline-image-p
2585 element org-html-inline-image-rules)
2586 (org-export-get-parent element)))
2587 (t nil))))
2588 (when (eq (org-element-type paragraph) 'paragraph)
2589 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2590 (functionp org-html-standalone-image-predicate)))
2591 (funcall org-html-standalone-image-predicate paragraph))
2592 (let ((contents (org-element-contents paragraph)))
2593 (loop for x in contents
2594 with inline-image-count = 0
2595 always (cond
2596 ((eq (org-element-type x) 'plain-text)
2597 (not (org-string-nw-p x)))
2598 ((eq (org-element-type x) 'link)
2599 (when (org-export-inline-image-p
2600 x org-html-inline-image-rules)
2601 (= (incf inline-image-count) 1)))
2602 (t nil))))))))
2604 (defun org-html-link (link desc info)
2605 "Transcode a LINK object from Org to HTML.
2607 DESC is the description part of the link, or the empty string.
2608 INFO is a plist holding contextual information. See
2609 `org-export-data'."
2610 (let* ((link-org-files-as-html-maybe
2611 (function
2612 (lambda (raw-path info)
2613 "Treat links to `file.org' as links to `file.html', if needed.
2614 See `org-html-link-org-files-as-html'."
2615 (cond
2616 ((and org-html-link-org-files-as-html
2617 (string= ".org"
2618 (downcase (file-name-extension raw-path "."))))
2619 (concat (file-name-sans-extension raw-path) "."
2620 (plist-get info :html-extension)))
2621 (t raw-path)))))
2622 (type (org-element-property :type link))
2623 (raw-path (org-element-property :path link))
2624 ;; Ensure DESC really exists, or set it to nil.
2625 (desc (org-string-nw-p desc))
2626 (path
2627 (cond
2628 ((member type '("http" "https" "ftp" "mailto"))
2629 (concat type ":" raw-path))
2630 ((string= type "file")
2631 ;; Treat links to ".org" files as ".html", if needed.
2632 (setq raw-path
2633 (funcall link-org-files-as-html-maybe raw-path info))
2634 ;; If file path is absolute, prepend it with protocol
2635 ;; component - "file://".
2636 (when (file-name-absolute-p raw-path)
2637 (setq raw-path
2638 (concat "file://" (expand-file-name raw-path))))
2639 ;; Add search option, if any. A search option can be
2640 ;; relative to a custom-id or a headline title. Any other
2641 ;; option is ignored.
2642 (let ((option (org-element-property :search-option link)))
2643 (cond ((not option) raw-path)
2644 ((eq (aref option 0) ?#) (concat raw-path option))
2645 ;; External fuzzy link: try to resolve it if path
2646 ;; belongs to current project, if any.
2647 ((eq (aref option 0) ?*)
2648 (concat
2649 raw-path
2650 (let ((numbers
2651 (org-publish-resolve-external-fuzzy-link
2652 (org-element-property :path link) option)))
2653 (and numbers (concat "#sec-"
2654 (mapconcat 'number-to-string
2655 numbers "-"))))))
2656 (t raw-path))))
2657 (t raw-path)))
2658 ;; Extract attributes from parent's paragraph. HACK: Only do
2659 ;; this for the first link in parent. This is needed as long
2660 ;; as attributes cannot be set on a per link basis.
2661 (attributes
2662 (let ((parent (org-export-get-parent-element link)))
2663 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2665 (let ((att (org-html--make-attribute-string
2666 (org-export-read-attribute :attr_html parent))))
2667 (cond ((not (org-string-nw-p att)) "")
2668 ((and desc (string-match (regexp-quote att) desc)) "")
2669 (t (concat " " att)))))))
2670 protocol)
2671 (cond
2672 ;; Image file.
2673 ((and (or (eq t org-html-inline-images)
2674 (and org-html-inline-images (not desc)))
2675 (org-export-inline-image-p link org-html-inline-image-rules))
2676 (org-html-link--inline-image link desc info))
2677 ;; Radio target: Transcode target's contents and use them as
2678 ;; link's description.
2679 ((string= type "radio")
2680 (let ((destination (org-export-resolve-radio-link link info)))
2681 (when destination
2682 (format "<a href=\"#%s\"%s>%s</a>"
2683 (org-export-solidify-link-text path)
2684 attributes
2685 (org-export-data (org-element-contents destination) info)))))
2686 ;; Links pointing to a headline: Find destination and build
2687 ;; appropriate referencing command.
2688 ((member type '("custom-id" "fuzzy" "id"))
2689 (let ((destination (if (string= type "fuzzy")
2690 (org-export-resolve-fuzzy-link link info)
2691 (org-export-resolve-id-link link info))))
2692 (case (org-element-type destination)
2693 ;; ID link points to an external file.
2694 (plain-text
2695 (let ((fragment (concat "ID-" path))
2696 ;; Treat links to ".org" files as ".html", if needed.
2697 (path (funcall link-org-files-as-html-maybe
2698 destination info)))
2699 (format "<a href=\"%s#%s\"%s>%s</a>"
2700 path fragment attributes (or desc destination))))
2701 ;; Fuzzy link points nowhere.
2702 ((nil)
2703 (format "<i>%s</i>"
2704 (or desc
2705 (org-export-data
2706 (org-element-property :raw-link link) info))))
2707 ;; Fuzzy link points to an invisible target.
2708 (keyword nil)
2709 ;; Link points to a headline.
2710 (headline
2711 (let ((href
2712 ;; What href to use?
2713 (cond
2714 ;; Case 1: Headline is linked via it's CUSTOM_ID
2715 ;; property. Use CUSTOM_ID.
2716 ((string= type "custom-id")
2717 (org-element-property :CUSTOM_ID destination))
2718 ;; Case 2: Headline is linked via it's ID property
2719 ;; or through other means. Use the default href.
2720 ((member type '("id" "fuzzy"))
2721 (format "sec-%s"
2722 (mapconcat 'number-to-string
2723 (org-export-get-headline-number
2724 destination info) "-")))
2725 (t (error "Shouldn't reach here"))))
2726 ;; What description to use?
2727 (desc
2728 ;; Case 1: Headline is numbered and LINK has no
2729 ;; description. Display section number.
2730 (if (and (org-export-numbered-headline-p destination info)
2731 (not desc))
2732 (mapconcat 'number-to-string
2733 (org-export-get-headline-number
2734 destination info) ".")
2735 ;; Case 2: Either the headline is un-numbered or
2736 ;; LINK has a custom description. Display LINK's
2737 ;; description or headline's title.
2738 (or desc (org-export-data (org-element-property
2739 :title destination) info)))))
2740 (format "<a href=\"#%s\"%s>%s</a>"
2741 (org-export-solidify-link-text href) attributes desc)))
2742 ;; Fuzzy link points to a target. Do as above.
2744 (let ((path (org-export-solidify-link-text path)) number)
2745 (unless desc
2746 (setq number (cond
2747 ((org-html-standalone-image-p destination info)
2748 (org-export-get-ordinal
2749 (assoc 'link (org-element-contents destination))
2750 info 'link 'org-html-standalone-image-p))
2751 (t (org-export-get-ordinal destination info))))
2752 (setq desc (when number
2753 (if (atom number) (number-to-string number)
2754 (mapconcat 'number-to-string number ".")))))
2755 (format "<a href=\"#%s\"%s>%s</a>"
2756 path attributes (or desc "No description for this link")))))))
2757 ;; Coderef: replace link with the reference name or the
2758 ;; equivalent line number.
2759 ((string= type "coderef")
2760 (let ((fragment (concat "coderef-" path)))
2761 (format "<a href=\"#%s\"%s%s>%s</a>"
2762 fragment
2763 (org-trim
2764 (format (concat "class=\"coderef\""
2765 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2766 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2767 fragment fragment))
2768 attributes
2769 (format (org-export-get-coderef-format path desc)
2770 (org-export-resolve-coderef path info)))))
2771 ;; Link type is handled by a special function.
2772 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2773 (funcall protocol (org-link-unescape path) desc 'html))
2774 ;; External link with a description part.
2775 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2776 ;; External link without a description part.
2777 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2778 ;; No path, only description. Try to do something useful.
2779 (t (format "<i>%s</i>" desc)))))
2781 ;;;; Paragraph
2783 (defun org-html-paragraph (paragraph contents info)
2784 "Transcode a PARAGRAPH element from Org to HTML.
2785 CONTENTS is the contents of the paragraph, as a string. INFO is
2786 the plist used as a communication channel."
2787 (let* ((parent (org-export-get-parent paragraph))
2788 (parent-type (org-element-type parent))
2789 (style '((footnote-definition " class=\"footpara\"")))
2790 (extra (or (cadr (assoc parent-type style)) "")))
2791 (cond
2792 ((and (eq (org-element-type parent) 'item)
2793 (= (org-element-property :begin paragraph)
2794 (org-element-property :contents-begin parent)))
2795 ;; leading paragraph in a list item have no tags
2796 contents)
2797 ((org-html-standalone-image-p paragraph info)
2798 ;; standalone image
2799 contents)
2800 (t (format "<p%s>\n%s</p>" extra contents)))))
2802 ;;;; Plain List
2804 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2805 ;; the correct value for the item counter
2806 (defun org-html-begin-plain-list (type &optional arg1)
2807 "Insert the beginning of the HTML list depending on TYPE.
2808 When ARG1 is a string, use it as the start parameter for ordered
2809 lists."
2810 (case type
2811 (ordered
2812 (format "<ol class=\"org-ol\"%s>"
2813 (if arg1 (format " start=\"%d\"" arg1) "")))
2814 (unordered "<ul class=\"org-ul\">")
2815 (descriptive "<dl class=\"org-dl\">")))
2817 (defun org-html-end-plain-list (type)
2818 "Insert the end of the HTML list depending on TYPE."
2819 (case type
2820 (ordered "</ol>")
2821 (unordered "</ul>")
2822 (descriptive "</dl>")))
2824 (defun org-html-plain-list (plain-list contents info)
2825 "Transcode a PLAIN-LIST element from Org to HTML.
2826 CONTENTS is the contents of the list. INFO is a plist holding
2827 contextual information."
2828 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2829 (type (org-element-property :type plain-list)))
2830 (format "%s\n%s%s"
2831 (org-html-begin-plain-list type)
2832 contents (org-html-end-plain-list type))))
2834 ;;;; Plain Text
2836 (defun org-html-convert-special-strings (string)
2837 "Convert special characters in STRING to HTML."
2838 (let ((all org-html-special-string-regexps)
2839 e a re rpl start)
2840 (while (setq a (pop all))
2841 (setq re (car a) rpl (cdr a) start 0)
2842 (while (string-match re string start)
2843 (setq string (replace-match rpl t nil string))))
2844 string))
2846 (defun org-html-encode-plain-text (text)
2847 "Convert plain text characters from TEXT to HTML equivalent.
2848 Possible conversions are set in `org-html-protect-char-alist'."
2849 (mapc
2850 (lambda (pair)
2851 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2852 org-html-protect-char-alist)
2853 text)
2855 (defun org-html-plain-text (text info)
2856 "Transcode a TEXT string from Org to HTML.
2857 TEXT is the string to transcode. INFO is a plist holding
2858 contextual information."
2859 (let ((output text))
2860 ;; Protect following characters: <, >, &.
2861 (setq output (org-html-encode-plain-text output))
2862 ;; Handle smart quotes. Be sure to provide original string since
2863 ;; OUTPUT may have been modified.
2864 (when (plist-get info :with-smart-quotes)
2865 (setq output (org-export-activate-smart-quotes output :html info text)))
2866 ;; Handle special strings.
2867 (when (plist-get info :with-special-strings)
2868 (setq output (org-html-convert-special-strings output)))
2869 ;; Handle break preservation if required.
2870 (when (plist-get info :preserve-breaks)
2871 (setq output
2872 (replace-regexp-in-string
2873 "\\(\\\\\\\\\\)?[ \t]*\n"
2874 (concat (org-html-close-tag "br" nil info) "\n") output)))
2875 ;; Return value.
2876 output))
2879 ;; Planning
2881 (defun org-html-planning (planning contents info)
2882 "Transcode a PLANNING element from Org to HTML.
2883 CONTENTS is nil. INFO is a plist used as a communication
2884 channel."
2885 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2886 (format
2887 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2888 (mapconcat
2889 'identity
2890 (delq nil
2891 (list
2892 (let ((closed (org-element-property :closed planning)))
2893 (when closed
2894 (format span-fmt org-closed-string
2895 (org-translate-time
2896 (org-element-property :raw-value closed)))))
2897 (let ((deadline (org-element-property :deadline planning)))
2898 (when deadline
2899 (format span-fmt org-deadline-string
2900 (org-translate-time
2901 (org-element-property :raw-value deadline)))))
2902 (let ((scheduled (org-element-property :scheduled planning)))
2903 (when scheduled
2904 (format span-fmt org-scheduled-string
2905 (org-translate-time
2906 (org-element-property :raw-value scheduled)))))))
2907 " "))))
2909 ;;;; Property Drawer
2911 (defun org-html-property-drawer (property-drawer contents info)
2912 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2913 CONTENTS is nil. INFO is a plist holding contextual
2914 information."
2915 ;; The property drawer isn't exported but we want separating blank
2916 ;; lines nonetheless.
2919 ;;;; Quote Block
2921 (defun org-html-quote-block (quote-block contents info)
2922 "Transcode a QUOTE-BLOCK element from Org to HTML.
2923 CONTENTS holds the contents of the block. INFO is a plist
2924 holding contextual information."
2925 (format "<blockquote>\n%s</blockquote>" contents))
2927 ;;;; Quote Section
2929 (defun org-html-quote-section (quote-section contents info)
2930 "Transcode a QUOTE-SECTION element from Org to HTML.
2931 CONTENTS is nil. INFO is a plist holding contextual information."
2932 (let ((value (org-remove-indentation
2933 (org-element-property :value quote-section))))
2934 (when value (format "<pre>\n%s</pre>" value))))
2936 ;;;; Section
2938 (defun org-html-section (section contents info)
2939 "Transcode a SECTION element from Org to HTML.
2940 CONTENTS holds the contents of the section. INFO is a plist
2941 holding contextual information."
2942 (let ((parent (org-export-get-parent-headline section)))
2943 ;; Before first headline: no container, just return CONTENTS.
2944 (if (not parent) contents
2945 ;; Get div's class and id references.
2946 (let* ((class-num (+ (org-export-get-relative-level parent info)
2947 (1- org-html-toplevel-hlevel)))
2948 (section-number
2949 (mapconcat
2950 'number-to-string
2951 (org-export-get-headline-number parent info) "-")))
2952 ;; Build return value.
2953 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2954 class-num
2955 (or (org-element-property :CUSTOM_ID parent) section-number)
2956 contents)))))
2958 ;;;; Radio Target
2960 (defun org-html-radio-target (radio-target text info)
2961 "Transcode a RADIO-TARGET object from Org to HTML.
2962 TEXT is the text of the target. INFO is a plist holding
2963 contextual information."
2964 (let ((id (org-export-solidify-link-text
2965 (org-element-property :value radio-target))))
2966 (org-html--anchor id text)))
2968 ;;;; Special Block
2970 (defun org-html-special-block (special-block contents info)
2971 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2972 CONTENTS holds the contents of the block. INFO is a plist
2973 holding contextual information."
2974 (let* ((block-type (downcase
2975 (org-element-property :type special-block)))
2976 (contents (or contents ""))
2977 (html5-fancy (and (org-html-html5-p info)
2978 (plist-get info :html-html5-fancy)
2979 (member block-type org-html-html5-elements)))
2980 (attributes (org-export-read-attribute :attr_html special-block)))
2981 (unless html5-fancy
2982 (let ((class (plist-get attributes :class)))
2983 (setq attributes (plist-put attributes :class
2984 (if class (concat class " " block-type)
2985 block-type)))))
2986 (setq attributes (org-html--make-attribute-string attributes))
2987 (when (not (equal attributes ""))
2988 (setq attributes (concat " " attributes)))
2989 (if html5-fancy
2990 (format "<%s%s>\n%s</%s>" block-type attributes
2991 contents block-type)
2992 (format "<div%s>\n%s\n</div>" attributes contents))))
2994 ;;;; Src Block
2996 (defun org-html-src-block (src-block contents info)
2997 "Transcode a SRC-BLOCK element from Org to HTML.
2998 CONTENTS holds the contents of the item. INFO is a plist holding
2999 contextual information."
3000 (if (org-export-read-attribute :attr_html src-block :textarea)
3001 (org-html--textarea-block src-block)
3002 (let ((lang (org-element-property :language src-block))
3003 (caption (org-export-get-caption src-block))
3004 (code (org-html-format-code src-block info))
3005 (label (let ((lbl (org-element-property :name src-block)))
3006 (if (not lbl) ""
3007 (format " id=\"%s\""
3008 (org-export-solidify-link-text lbl))))))
3009 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3010 (format
3011 "<div class=\"org-src-container\">\n%s%s\n</div>"
3012 (if (not caption) ""
3013 (format "<label class=\"org-src-name\">%s</label>"
3014 (org-export-data caption info)))
3015 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3017 ;;;; Statistics Cookie
3019 (defun org-html-statistics-cookie (statistics-cookie contents info)
3020 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3021 CONTENTS is nil. INFO is a plist holding contextual information."
3022 (let ((cookie-value (org-element-property :value statistics-cookie)))
3023 (format "<code>%s</code>" cookie-value)))
3025 ;;;; Strike-Through
3027 (defun org-html-strike-through (strike-through contents info)
3028 "Transcode STRIKE-THROUGH from Org to HTML.
3029 CONTENTS is the text with strike-through markup. INFO is a plist
3030 holding contextual information."
3031 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3032 contents))
3034 ;;;; Subscript
3036 (defun org-html-subscript (subscript contents info)
3037 "Transcode a SUBSCRIPT object from Org to HTML.
3038 CONTENTS is the contents of the object. INFO is a plist holding
3039 contextual information."
3040 (format "<sub>%s</sub>" contents))
3042 ;;;; Superscript
3044 (defun org-html-superscript (superscript contents info)
3045 "Transcode a SUPERSCRIPT object from Org to HTML.
3046 CONTENTS is the contents of the object. INFO is a plist holding
3047 contextual information."
3048 (format "<sup>%s</sup>" contents))
3050 ;;;; Tabel Cell
3052 (defun org-html-table-cell (table-cell contents info)
3053 "Transcode a TABLE-CELL element from Org to HTML.
3054 CONTENTS is nil. INFO is a plist used as a communication
3055 channel."
3056 (let* ((table-row (org-export-get-parent table-cell))
3057 (table (org-export-get-parent-table table-cell))
3058 (cell-attrs
3059 (if (not org-html-table-align-individual-fields) ""
3060 (format (if (and (boundp 'org-html-format-table-no-css)
3061 org-html-format-table-no-css)
3062 " align=\"%s\"" " class=\"%s\"")
3063 (org-export-table-cell-alignment table-cell info)))))
3064 (when (or (not contents) (string= "" (org-trim contents)))
3065 (setq contents "&#xa0;"))
3066 (cond
3067 ((and (org-export-table-has-header-p table info)
3068 (= 1 (org-export-table-row-group table-row info)))
3069 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3070 contents (cdr org-html-table-header-tags)))
3071 ((and org-html-table-use-header-tags-for-first-column
3072 (zerop (cdr (org-export-table-cell-address table-cell info))))
3073 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3074 contents (cdr org-html-table-header-tags)))
3075 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3076 contents (cdr org-html-table-data-tags))))))
3078 ;;;; Table Row
3080 (defun org-html-table-row (table-row contents info)
3081 "Transcode a TABLE-ROW element from Org to HTML.
3082 CONTENTS is the contents of the row. INFO is a plist used as a
3083 communication channel."
3084 ;; Rules are ignored since table separators are deduced from
3085 ;; borders of the current row.
3086 (when (eq (org-element-property :type table-row) 'standard)
3087 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3088 (row-number (org-export-table-row-number table-row info))
3089 (start-rowgroup-p
3090 (org-export-table-row-starts-rowgroup-p table-row info))
3091 (end-rowgroup-p
3092 (org-export-table-row-ends-rowgroup-p table-row info))
3093 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3094 ;; but should be set so that `org-html-table-row-tags' can
3095 ;; use them (see the docstring of this variable.)
3096 (top-row-p (and (equal start-rowgroup-p '(top))
3097 (equal end-rowgroup-p '(below top))))
3098 (bottom-row-p (and (equal start-rowgroup-p '(above))
3099 (equal end-rowgroup-p '(bottom above))))
3100 (rowgroup-tags
3101 (cond
3102 ;; Case 1: Row belongs to second or subsequent rowgroups.
3103 ((not (= 1 rowgroup-number))
3104 '("<tbody>" . "\n</tbody>"))
3105 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3106 ((org-export-table-has-header-p
3107 (org-export-get-parent-table table-row) info)
3108 '("<thead>" . "\n</thead>"))
3109 ;; Case 2: Row is from first and only row group.
3110 (t '("<tbody>" . "\n</tbody>")))))
3111 (concat
3112 ;; Begin a rowgroup?
3113 (when start-rowgroup-p (car rowgroup-tags))
3114 ;; Actual table row
3115 (concat "\n" (eval (car org-html-table-row-tags))
3116 contents
3117 "\n"
3118 (eval (cdr org-html-table-row-tags)))
3119 ;; End a rowgroup?
3120 (when end-rowgroup-p (cdr rowgroup-tags))))))
3122 ;;;; Table
3124 (defun org-html-table-first-row-data-cells (table info)
3125 "Transcode the first row of TABLE.
3126 INFO is a plist used as a communication channel."
3127 (let ((table-row
3128 (org-element-map table 'table-row
3129 (lambda (row)
3130 (unless (eq (org-element-property :type row) 'rule) row))
3131 info 'first-match))
3132 (special-column-p (org-export-table-has-special-column-p table)))
3133 (if (not special-column-p) (org-element-contents table-row)
3134 (cdr (org-element-contents table-row)))))
3136 (defun org-html-table--table.el-table (table info)
3137 "Format table.el tables into HTML.
3138 INFO is a plist used as a communication channel."
3139 (when (eq (org-element-property :type table) 'table.el)
3140 (require 'table)
3141 (let ((outbuf (with-current-buffer
3142 (get-buffer-create "*org-export-table*")
3143 (erase-buffer) (current-buffer))))
3144 (with-temp-buffer
3145 (insert (org-element-property :value table))
3146 (goto-char 1)
3147 (re-search-forward "^[ \t]*|[^|]" nil t)
3148 (table-generate-source 'html outbuf))
3149 (with-current-buffer outbuf
3150 (prog1 (org-trim (buffer-string))
3151 (kill-buffer) )))))
3153 (defun org-html-table (table contents info)
3154 "Transcode a TABLE element from Org to HTML.
3155 CONTENTS is the contents of the table. INFO is a plist holding
3156 contextual information."
3157 (case (org-element-property :type table)
3158 ;; Case 1: table.el table. Convert it using appropriate tools.
3159 (table.el (org-html-table--table.el-table table info))
3160 ;; Case 2: Standard table.
3162 (let* ((label (org-element-property :name table))
3163 (caption (org-export-get-caption table))
3164 (attributes
3165 (if (org-html-html5-p info) ""
3166 (org-html--make-attribute-string
3167 (org-combine-plists
3168 (and label (list :id (org-export-solidify-link-text label)))
3169 (plist-get info :html-table-attributes)
3170 (org-export-read-attribute :attr_html table)))))
3171 (alignspec
3172 (if (and (boundp 'org-html-format-table-no-css)
3173 org-html-format-table-no-css)
3174 "align=\"%s\"" "class=\"%s\""))
3175 (table-column-specs
3176 (function
3177 (lambda (table info)
3178 (mapconcat
3179 (lambda (table-cell)
3180 (let ((alignment (org-export-table-cell-alignment
3181 table-cell info)))
3182 (concat
3183 ;; Begin a colgroup?
3184 (when (org-export-table-cell-starts-colgroup-p
3185 table-cell info)
3186 "\n<colgroup>")
3187 ;; Add a column. Also specify it's alignment.
3188 (format "\n%s"
3189 (org-html-close-tag
3190 "col" (concat " " (format alignspec alignment)) info))
3191 ;; End a colgroup?
3192 (when (org-export-table-cell-ends-colgroup-p
3193 table-cell info)
3194 "\n</colgroup>"))))
3195 (org-html-table-first-row-data-cells table info) "\n")))))
3196 (format "<table%s>\n%s\n%s\n%s</table>"
3197 (if (equal attributes "") "" (concat " " attributes))
3198 (if (not caption) ""
3199 (format "<caption>%s</caption>"
3200 (org-export-data caption info)))
3201 (funcall table-column-specs table info)
3202 contents)))))
3204 ;;;; Target
3206 (defun org-html-target (target contents info)
3207 "Transcode a TARGET object from Org to HTML.
3208 CONTENTS is nil. INFO is a plist holding contextual
3209 information."
3210 (let ((id (org-export-solidify-link-text
3211 (org-element-property :value target))))
3212 (org-html--anchor id)))
3214 ;;;; Timestamp
3216 (defun org-html-timestamp (timestamp contents info)
3217 "Transcode a TIMESTAMP object from Org to HTML.
3218 CONTENTS is nil. INFO is a plist holding contextual
3219 information."
3220 (let ((value (org-html-plain-text
3221 (org-timestamp-translate timestamp) info)))
3222 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3223 (replace-regexp-in-string "--" "&#x2013;" value))))
3225 ;;;; Underline
3227 (defun org-html-underline (underline contents info)
3228 "Transcode UNDERLINE from Org to HTML.
3229 CONTENTS is the text with underline markup. INFO is a plist
3230 holding contextual information."
3231 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3232 contents))
3234 ;;;; Verbatim
3236 (defun org-html-verbatim (verbatim contents info)
3237 "Transcode VERBATIM from Org to HTML.
3238 CONTENTS is nil. INFO is a plist holding contextual
3239 information."
3240 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3241 (org-html-plain-text (org-element-property :value verbatim) info)))
3243 ;;;; Verse Block
3245 (defun org-html-verse-block (verse-block contents info)
3246 "Transcode a VERSE-BLOCK element from Org to HTML.
3247 CONTENTS is verse block contents. INFO is a plist holding
3248 contextual information."
3249 ;; Replace each newline character with line break. Also replace
3250 ;; each blank line with a line break.
3251 (setq contents (replace-regexp-in-string
3252 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3253 (replace-regexp-in-string
3254 "\\(\\\\\\\\\\)?[ \t]*\n"
3255 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3256 ;; Replace each white space at beginning of a line with a
3257 ;; non-breaking space.
3258 (while (string-match "^[ \t]+" contents)
3259 (let* ((num-ws (length (match-string 0 contents)))
3260 (ws (let (out) (dotimes (i num-ws out)
3261 (setq out (concat out "&#xa0;"))))))
3262 (setq contents (replace-match ws nil t contents))))
3263 (format "<p class=\"verse\">\n%s</p>" contents))
3266 ;;; Filter Functions
3268 (defun org-html-final-function (contents backend info)
3269 "Filter to indent the HTML and convert HTML entities."
3270 (with-temp-buffer
3271 (insert contents)
3272 (set-auto-mode t)
3273 (if org-html-indent
3274 (indent-region (point-min) (point-max)))
3275 (when org-html-use-unicode-chars
3276 (require 'mm-url)
3277 (mm-url-decode-entities))
3278 (buffer-substring-no-properties (point-min) (point-max))))
3281 ;;; End-user functions
3283 ;;;###autoload
3284 (defun org-html-export-as-html
3285 (&optional async subtreep visible-only body-only ext-plist)
3286 "Export current buffer to an HTML buffer.
3288 If narrowing is active in the current buffer, only export its
3289 narrowed part.
3291 If a region is active, export that region.
3293 A non-nil optional argument ASYNC means the process should happen
3294 asynchronously. The resulting buffer should be accessible
3295 through the `org-export-stack' interface.
3297 When optional argument SUBTREEP is non-nil, export the sub-tree
3298 at point, extracting information from the headline properties
3299 first.
3301 When optional argument VISIBLE-ONLY is non-nil, don't export
3302 contents of hidden elements.
3304 When optional argument BODY-ONLY is non-nil, only write code
3305 between \"<body>\" and \"</body>\" tags.
3307 EXT-PLIST, when provided, is a property list with external
3308 parameters overriding Org default settings, but still inferior to
3309 file-local settings.
3311 Export is done in a buffer named \"*Org HTML Export*\", which
3312 will be displayed when `org-export-show-temporary-export-buffer'
3313 is non-nil."
3314 (interactive)
3315 (if async
3316 (org-export-async-start
3317 (lambda (output)
3318 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3319 (erase-buffer)
3320 (insert output)
3321 (goto-char (point-min))
3322 (set-auto-mode t)
3323 (org-export-add-to-stack (current-buffer) 'html)))
3324 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3325 (let ((outbuf (org-export-to-buffer
3326 'html "*Org HTML Export*"
3327 subtreep visible-only body-only ext-plist)))
3328 ;; Set major mode.
3329 (with-current-buffer outbuf (set-auto-mode t))
3330 (when org-export-show-temporary-export-buffer
3331 (switch-to-buffer-other-window outbuf)))))
3333 ;;;###autoload
3334 (defun org-html-convert-region-to-html ()
3335 "Assume the current region has org-mode syntax, and convert it to HTML.
3336 This can be used in any buffer. For example, you can write an
3337 itemized list in org-mode syntax in an HTML buffer and use this
3338 command to convert it."
3339 (interactive)
3340 (org-export-replace-region-by 'html))
3342 ;;;###autoload
3343 (defun org-html-export-to-html
3344 (&optional async subtreep visible-only body-only ext-plist)
3345 "Export current buffer to a HTML file.
3347 If narrowing is active in the current buffer, only export its
3348 narrowed part.
3350 If a region is active, export that region.
3352 A non-nil optional argument ASYNC means the process should happen
3353 asynchronously. The resulting file should be accessible through
3354 the `org-export-stack' interface.
3356 When optional argument SUBTREEP is non-nil, export the sub-tree
3357 at point, extracting information from the headline properties
3358 first.
3360 When optional argument VISIBLE-ONLY is non-nil, don't export
3361 contents of hidden elements.
3363 When optional argument BODY-ONLY is non-nil, only write code
3364 between \"<body>\" and \"</body>\" tags.
3366 EXT-PLIST, when provided, is a property list with external
3367 parameters overriding Org default settings, but still inferior to
3368 file-local settings.
3370 Return output file's name."
3371 (interactive)
3372 (let* ((extension (concat "." org-html-extension))
3373 (file (org-export-output-file-name extension subtreep))
3374 (org-export-coding-system org-html-coding-system))
3375 (if async
3376 (org-export-async-start
3377 (lambda (f) (org-export-add-to-stack f 'html))
3378 (let ((org-export-coding-system org-html-coding-system))
3379 `(expand-file-name
3380 (org-export-to-file
3381 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3382 (let ((org-export-coding-system org-html-coding-system))
3383 (org-export-to-file
3384 'html file subtreep visible-only body-only ext-plist)))))
3386 ;;;###autoload
3387 (defun org-html-publish-to-html (plist filename pub-dir)
3388 "Publish an org file to HTML.
3390 FILENAME is the filename of the Org file to be published. PLIST
3391 is the property list for the given project. PUB-DIR is the
3392 publishing directory.
3394 Return output file name."
3395 (org-publish-org-to 'html filename
3396 (concat "." (or (plist-get plist :html-extension)
3397 org-html-extension "html"))
3398 plist pub-dir))
3401 ;;; FIXME
3403 ;;;; org-format-table-html
3404 ;;;; org-format-org-table-html
3405 ;;;; org-format-table-table-html
3406 ;;;; org-table-number-fraction
3407 ;;;; org-table-number-regexp
3408 ;;;; org-html-table-caption-above
3409 ;;;; org-html-inline-image-extensions
3410 ;;;; org-export-preferred-target-alist
3411 ;;;; class for anchors
3412 ;;;; org-export-mark-todo-in-toc
3413 ;;;; org-html-format-org-link
3414 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3415 ;;;; alt = (file-name-nondirectory path)
3417 (provide 'ox-html)
3419 ;; Local variables:
3420 ;; generated-autoload-file: "org-loaddefs.el"
3421 ;; End:
3423 ;;; ox-html.el ends here