ox-html: Add defcustom for timestamps in metadata
[org-mode.git] / lisp / ox-html.el
blobe91467b8d9478c96405bb547a72e1da105cad5ac
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a HTML back-end for Org generic exporter.
25 ;; To test it, run:
27 ;; M-x org-export-as-html
29 ;; in an Org mode buffer. See ox.el for more details on how this
30 ;; exporter works.
32 ;;; Code:
34 ;;; Dependencies
36 (require 'ox)
37 (require 'ox-publish)
38 (require 'format-spec)
39 (eval-when-compile (require 'cl) (require 'table))
42 ;;; Function Declarations
44 (declare-function org-id-find-id-file "org-id" (id))
45 (declare-function htmlize-region "ext:htmlize" (beg end))
46 (declare-function org-pop-to-buffer-same-window
47 "org-compat" (&optional buffer-or-name norecord label))
48 (declare-function mm-url-decode-entities "mm-url" ())
50 ;;; Define Back-End
52 (org-export-define-backend 'html
53 '((bold . org-html-bold)
54 (center-block . org-html-center-block)
55 (clock . org-html-clock)
56 (code . org-html-code)
57 (drawer . org-html-drawer)
58 (dynamic-block . org-html-dynamic-block)
59 (entity . org-html-entity)
60 (example-block . org-html-example-block)
61 (export-block . org-html-export-block)
62 (export-snippet . org-html-export-snippet)
63 (fixed-width . org-html-fixed-width)
64 (footnote-definition . org-html-footnote-definition)
65 (footnote-reference . org-html-footnote-reference)
66 (headline . org-html-headline)
67 (horizontal-rule . org-html-horizontal-rule)
68 (inline-src-block . org-html-inline-src-block)
69 (inlinetask . org-html-inlinetask)
70 (inner-template . org-html-inner-template)
71 (italic . org-html-italic)
72 (item . org-html-item)
73 (keyword . org-html-keyword)
74 (latex-environment . org-html-latex-environment)
75 (latex-fragment . org-html-latex-fragment)
76 (line-break . org-html-line-break)
77 (link . org-html-link)
78 (paragraph . org-html-paragraph)
79 (plain-list . org-html-plain-list)
80 (plain-text . org-html-plain-text)
81 (planning . org-html-planning)
82 (property-drawer . org-html-property-drawer)
83 (quote-block . org-html-quote-block)
84 (quote-section . org-html-quote-section)
85 (radio-target . org-html-radio-target)
86 (section . org-html-section)
87 (special-block . org-html-special-block)
88 (src-block . org-html-src-block)
89 (statistics-cookie . org-html-statistics-cookie)
90 (strike-through . org-html-strike-through)
91 (subscript . org-html-subscript)
92 (superscript . org-html-superscript)
93 (table . org-html-table)
94 (table-cell . org-html-table-cell)
95 (table-row . org-html-table-row)
96 (target . org-html-target)
97 (template . org-html-template)
98 (timestamp . org-html-timestamp)
99 (underline . org-html-underline)
100 (verbatim . org-html-verbatim)
101 (verse-block . org-html-verse-block))
102 :export-block "HTML"
103 :filters-alist '((:filter-options . org-html-infojs-install-script)
104 (:filter-final-output . org-html-final-function))
105 :menu-entry
106 '(?h "Export to HTML"
107 ((?H "As HTML buffer" org-html-export-as-html)
108 (?h "As HTML file" org-html-export-to-html)
109 (?o "As HTML file and open"
110 (lambda (a s v b)
111 (if a (org-html-export-to-html t s v b)
112 (org-open-file (org-html-export-to-html nil s v b)))))))
113 :options-alist
114 '((:html-extension nil nil org-html-extension)
115 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
116 (:html-container "HTML_CONTAINER" nil org-html-container-element)
117 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
118 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
119 (:html-mathjax "HTML_MATHJAX" nil "" space)
120 (:html-postamble nil "html-postamble" org-html-postamble)
121 (:html-preamble nil "html-preamble" org-html-preamble)
122 (:html-head "HTML_HEAD" nil org-html-head newline)
123 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
124 (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
125 (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
126 (:html-table-tag nil nil org-html-table-tag)
127 (:infojs-opt "INFOJS_OPT" nil nil)
128 ;; Redefine regular options.
129 (:creator "CREATOR" nil org-html-creator-string)
130 (:with-latex nil "tex" org-html-with-latex)))
133 ;;; Internal Variables
135 (defvar org-html-format-table-no-css)
136 (defvar htmlize-buffer-places) ; from htmlize.el
138 (defvar org-html--pre/postamble-class "status"
139 "CSS class used for pre/postamble")
141 (defconst org-html-special-string-regexps
142 '(("\\\\-" . "&#x00ad;") ; shy
143 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
144 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
145 ("\\.\\.\\." . "&#x2026;")) ; hellip
146 "Regular expressions for special string conversion.")
148 (defconst org-html-scripts
149 "<script type=\"text/javascript\">
151 @licstart The following is the entire license notice for the
152 JavaScript code in this tag.
154 Copyright (C) 2012 Free Software Foundation, Inc.
156 The JavaScript code in this tag is free software: you can
157 redistribute it and/or modify it under the terms of the GNU
158 General Public License (GNU GPL) as published by the Free Software
159 Foundation, either version 3 of the License, or (at your option)
160 any later version. The code is distributed WITHOUT ANY WARRANTY;
161 without even the implied warranty of MERCHANTABILITY or FITNESS
162 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
164 As additional permission under GNU GPL version 3 section 7, you
165 may distribute non-source (e.g., minimized or compacted) forms of
166 that code without the copy of the GNU GPL normally required by
167 section 4, provided you include this license notice and a URL
168 through which recipients can access the Corresponding Source.
171 @licend The above is the entire license notice
172 for the JavaScript code in this tag.
174 <!--/*--><![CDATA[/*><!--*/
175 function CodeHighlightOn(elem, id)
177 var target = document.getElementById(id);
178 if(null != target) {
179 elem.cacheClassElem = elem.className;
180 elem.cacheClassTarget = target.className;
181 target.className = \"code-highlighted\";
182 elem.className = \"code-highlighted\";
185 function CodeHighlightOff(elem, id)
187 var target = document.getElementById(id);
188 if(elem.cacheClassElem)
189 elem.className = elem.cacheClassElem;
190 if(elem.cacheClassTarget)
191 target.className = elem.cacheClassTarget;
193 /*]]>*///-->
194 </script>"
195 "Basic JavaScript that is needed by HTML files produced by Org mode.")
197 (defconst org-html-style-default
198 "<style type=\"text/css\">
199 <!--/*--><![CDATA[/*><!--*/
200 .title { text-align: center; }
201 .todo { font-family: monospace; color: red; }
202 .done { color: green; }
203 .tag { background-color: #eee; font-family: monospace;
204 padding: 2px; font-size: 80%; font-weight: normal; }
205 .timestamp { color: #bebebe; }
206 .timestamp-kwd { color: #5f9ea0; }
207 .right { margin-left: auto; margin-right: 0px; text-align: right; }
208 .left { margin-left: 0px; margin-right: auto; text-align: left; }
209 .center { margin-left: auto; margin-right: auto; text-align: center; }
210 .underline { text-decoration: underline; }
211 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
212 p.verse { margin-left: 3%; }
213 pre {
214 border: 1px solid #ccc;
215 box-shadow: 3px 3px 3px #eee;
216 padding: 8pt;
217 font-family: monospace;
218 overflow: auto;
219 margin: 1.2em;
221 pre.src {
222 position: relative;
223 overflow: visible;
224 padding-top: 1.2em;
226 pre.src:before {
227 display: none;
228 position: absolute;
229 background-color: white;
230 top: -10px;
231 right: 10px;
232 padding: 3px;
233 border: 1px solid black;
235 pre.src:hover:before { display: inline;}
236 pre.src-sh:before { content: 'sh'; }
237 pre.src-bash:before { content: 'sh'; }
238 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
239 pre.src-R:before { content: 'R'; }
240 pre.src-perl:before { content: 'Perl'; }
241 pre.src-java:before { content: 'Java'; }
242 pre.src-sql:before { content: 'SQL'; }
244 table { border-collapse:collapse; }
245 td, th { vertical-align:top; }
246 th.right { text-align: center; }
247 th.left { text-align: center; }
248 th.center { text-align: center; }
249 td.right { text-align: right; }
250 td.left { text-align: left; }
251 td.center { text-align: center; }
252 dt { font-weight: bold; }
253 .footpara:nth-child(2) { display: inline; }
254 .footpara { display: block; }
255 .footdef { margin-bottom: 1em; }
256 .figure { padding: 1em; }
257 .figure p { text-align: center; }
258 .inlinetask {
259 padding: 10px;
260 border: 2px solid gray;
261 margin: 10px;
262 background: #ffffcc;
264 #org-div-home-and-up
265 { text-align: right; font-size: 70%; white-space: nowrap; }
266 textarea { overflow-x: auto; }
267 .linenr { font-size: smaller }
268 .code-highlighted { background-color: #ffff00; }
269 .org-info-js_info-navigation { border-style: none; }
270 #org-info-js_console-label
271 { font-size: 10px; font-weight: bold; white-space: nowrap; }
272 .org-info-js_search-highlight
273 { background-color: #ffff00; color: #000000; font-weight: bold; }
274 /*]]>*/-->
275 </style>"
276 "The default style specification for exported HTML files.
277 You can use `org-html-head' and `org-html-head-extra' to add to
278 this style. If you don't want to include this default style,
279 customize `org-html-head-include-default-style'.")
282 ;;; User Configuration Variables
284 (defgroup org-export-html nil
285 "Options for exporting Org mode files to HTML."
286 :tag "Org Export HTML"
287 :group 'org-export)
289 ;;;; Handle infojs
291 (defvar org-html-infojs-opts-table
292 '((path PATH "http://orgmode.org/org-info.js")
293 (view VIEW "info")
294 (toc TOC :with-toc)
295 (ftoc FIXED_TOC "0")
296 (tdepth TOC_DEPTH "max")
297 (sdepth SECTION_DEPTH "max")
298 (mouse MOUSE_HINT "underline")
299 (buttons VIEW_BUTTONS "0")
300 (ltoc LOCAL_TOC "1")
301 (up LINK_UP :html-link-up)
302 (home LINK_HOME :html-link-home))
303 "JavaScript options, long form for script, default values.")
305 (defcustom org-html-use-infojs 'when-configured
306 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
307 This option can be nil or t to never or always use the script.
308 It can also be the symbol `when-configured', meaning that the
309 script will be linked into the export file if and only if there
310 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
311 `org-html-infojs-options'."
312 :group 'org-export-html
313 :version "24.4"
314 :package-version '(Org . "8.0")
315 :type '(choice
316 (const :tag "Never" nil)
317 (const :tag "When configured in buffer" when-configured)
318 (const :tag "Always" t)))
320 (defcustom org-html-infojs-options
321 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
322 "Options settings for the INFOJS JavaScript.
323 Each of the options must have an entry in `org-html-infojs-opts-table'.
324 The value can either be a string that will be passed to the script, or
325 a property. This property is then assumed to be a property that is defined
326 by the Export/Publishing setup of Org.
327 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
328 means to use the maximum value consistent with other options."
329 :group 'org-export-html
330 :version "24.4"
331 :package-version '(Org . "8.0")
332 :type
333 `(set :greedy t :inline t
334 ,@(mapcar
335 (lambda (x)
336 (list 'cons (list 'const (car x))
337 '(choice
338 (symbol :tag "Publishing/Export property")
339 (string :tag "Value"))))
340 org-html-infojs-opts-table)))
342 (defcustom org-html-infojs-template
343 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
346 * @source: %SCRIPT_PATH
348 * @licstart The following is the entire license notice for the
349 * JavaScript code in %SCRIPT_PATH.
351 * Copyright (C) 2012-2013 Sebastian Rose
354 * The JavaScript code in this tag is free software: you can
355 * redistribute it and/or modify it under the terms of the GNU
356 * General Public License (GNU GPL) as published by the Free Software
357 * Foundation, either version 3 of the License, or (at your option)
358 * any later version. The code is distributed WITHOUT ANY WARRANTY;
359 * without even the implied warranty of MERCHANTABILITY or FITNESS
360 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
362 * As additional permission under GNU GPL version 3 section 7, you
363 * may distribute non-source (e.g., minimized or compacted) forms of
364 * that code without the copy of the GNU GPL normally required by
365 * section 4, provided you include this license notice and a URL
366 * through which recipients can access the Corresponding Source.
368 * @licend The above is the entire license notice
369 * for the JavaScript code in %SCRIPT_PATH.
372 </script>
374 <script type=\"text/javascript\">
377 @licstart The following is the entire license notice for the
378 JavaScript code in this tag.
380 Copyright (C) 2012-2013 Free Software Foundation, Inc.
382 The JavaScript code in this tag is free software: you can
383 redistribute it and/or modify it under the terms of the GNU
384 General Public License (GNU GPL) as published by the Free Software
385 Foundation, either version 3 of the License, or (at your option)
386 any later version. The code is distributed WITHOUT ANY WARRANTY;
387 without even the implied warranty of MERCHANTABILITY or FITNESS
388 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
390 As additional permission under GNU GPL version 3 section 7, you
391 may distribute non-source (e.g., minimized or compacted) forms of
392 that code without the copy of the GNU GPL normally required by
393 section 4, provided you include this license notice and a URL
394 through which recipients can access the Corresponding Source.
397 @licend The above is the entire license notice
398 for the JavaScript code in this tag.
401 <!--/*--><![CDATA[/*><!--*/
402 %MANAGER_OPTIONS
403 org_html_manager.setup(); // activate after the parameters are set
404 /*]]>*///-->
405 </script>"
406 "The template for the export style additions when org-info.js is used.
407 Option settings will replace the %MANAGER-OPTIONS cookie."
408 :group 'org-export-html
409 :version "24.4"
410 :package-version '(Org . "8.0")
411 :type 'string)
413 (defun org-html-infojs-install-script (exp-plist backend)
414 "Install script in export options when appropriate.
415 EXP-PLIST is a plist containing export options. BACKEND is the
416 export back-end currently used."
417 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
418 (not org-html-use-infojs)
419 (and (eq org-html-use-infojs 'when-configured)
420 (or (not (plist-get exp-plist :infojs-opt))
421 (string-match "\\<view:nil\\>"
422 (plist-get exp-plist :infojs-opt)))))
423 (let* ((template org-html-infojs-template)
424 (ptoc (plist-get exp-plist :with-toc))
425 (hlevels (plist-get exp-plist :headline-levels))
426 (sdepth hlevels)
427 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
428 (options (plist-get exp-plist :infojs-opt))
429 (table org-html-infojs-opts-table)
430 style)
431 (dolist (entry table)
432 (let* ((opt (car entry))
433 (var (nth 1 entry))
434 ;; Compute default values for script option OPT from
435 ;; `org-html-infojs-options' variable.
436 (default
437 (let ((default (cdr (assq opt org-html-infojs-options))))
438 (if (and (symbolp default) (not (memq default '(t nil))))
439 (plist-get exp-plist default)
440 default)))
441 ;; Value set through INFOJS_OPT keyword has precedence
442 ;; over the default one.
443 (val (if (and options
444 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
445 options))
446 (match-string 1 options)
447 default)))
448 (case opt
449 (path (setq template
450 (replace-regexp-in-string
451 "%SCRIPT_PATH" val template t t)))
452 (sdepth (when (integerp (read val))
453 (setq sdepth (min (read val) sdepth))))
454 (tdepth (when (integerp (read val))
455 (setq tdepth (min (read val) tdepth))))
456 (otherwise (setq val
457 (cond
458 ((or (eq val t) (equal val "t")) "1")
459 ((or (eq val nil) (equal val "nil")) "0")
460 ((stringp val) val)
461 (t (format "%s" val))))
462 (push (cons var val) style)))))
463 ;; Now we set the depth of the *generated* TOC to SDEPTH,
464 ;; because the toc will actually determine the splitting. How
465 ;; much of the toc will actually be displayed is governed by the
466 ;; TDEPTH option.
467 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
468 ;; The table of contents should not show more sections than we
469 ;; generate.
470 (setq tdepth (min tdepth sdepth))
471 (push (cons "TOC_DEPTH" tdepth) style)
472 ;; Build style string.
473 (setq style (mapconcat
474 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
475 (car x)
476 (cdr x)))
477 style "\n"))
478 (when (and style (> (length style) 0))
479 (and (string-match "%MANAGER_OPTIONS" template)
480 (setq style (replace-match style t t template))
481 (setq exp-plist
482 (plist-put
483 exp-plist :html-head-extra
484 (concat (or (plist-get exp-plist :html-head-extra) "")
485 "\n"
486 style)))))
487 ;; This script absolutely needs the table of contents, so we
488 ;; change that setting.
489 (unless (plist-get exp-plist :with-toc)
490 (setq exp-plist (plist-put exp-plist :with-toc t)))
491 ;; Return the modified property list.
492 exp-plist)))
494 ;;;; Bold, etc.
496 (defcustom org-html-text-markup-alist
497 '((bold . "<b>%s</b>")
498 (code . "<code>%s</code>")
499 (italic . "<i>%s</i>")
500 (strike-through . "<del>%s</del>")
501 (underline . "<span class=\"underline\">%s</span>")
502 (verbatim . "<code>%s</code>"))
503 "Alist of HTML expressions to convert text markup.
505 The key must be a symbol among `bold', `code', `italic',
506 `strike-through', `underline' and `verbatim'. The value is
507 a formatting string to wrap fontified text with.
509 If no association can be found for a given markup, text will be
510 returned as-is."
511 :group 'org-export-html
512 :type '(alist :key-type (symbol :tag "Markup type")
513 :value-type (string :tag "Format string"))
514 :options '(bold code italic strike-through underline verbatim))
516 (defcustom org-html-indent nil
517 "Non-nil means to indent the generated HTML.
518 Warning: non-nil may break indentation of source code blocks."
519 :group 'org-export-html
520 :version "24.4"
521 :package-version '(Org . "8.0")
522 :type 'boolean)
524 (defcustom org-html-use-unicode-chars nil
525 "Non-nil means to use unicode characters instead of HTML entities."
526 :group 'org-export-html
527 :version "24.4"
528 :package-version '(Org . "8.0")
529 :type 'boolean)
531 ;;;; Drawers
533 (defcustom org-html-format-drawer-function nil
534 "Function called to format a drawer in HTML code.
536 The function must accept two parameters:
537 NAME the drawer name, like \"LOGBOOK\"
538 CONTENTS the contents of the drawer.
540 The function should return the string to be exported.
542 For example, the variable could be set to the following function
543 in order to mimic default behaviour:
545 \(defun org-html-format-drawer-default \(name contents\)
546 \"Format a drawer element for HTML export.\"
547 contents\)"
548 :group 'org-export-html
549 :type 'function)
551 ;;;; Footnotes
553 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
554 <h2 class=\"footnotes\">%s: </h2>
555 <div id=\"text-footnotes\">
557 </div>
558 </div>"
559 "Format for the footnotes section.
560 Should contain a two instances of %s. The first will be replaced with the
561 language-specific word for \"Footnotes\", the second one will be replaced
562 by the footnotes themselves."
563 :group 'org-export-html
564 :type 'string)
566 (defcustom org-html-footnote-format "<sup>%s</sup>"
567 "The format for the footnote reference.
568 %s will be replaced by the footnote reference itself."
569 :group 'org-export-html
570 :type 'string)
572 (defcustom org-html-footnote-separator "<sup>, </sup>"
573 "Text used to separate footnotes."
574 :group 'org-export-html
575 :type 'string)
577 ;;;; Headline
579 (defcustom org-html-toplevel-hlevel 2
580 "The <H> level for level 1 headings in HTML export.
581 This is also important for the classes that will be wrapped around headlines
582 and outline structure. If this variable is 1, the top-level headlines will
583 be <h1>, and the corresponding classes will be outline-1, section-number-1,
584 and outline-text-1. If this is 2, all of these will get a 2 instead.
585 The default for this variable is 2, because we use <h1> for formatting the
586 document title."
587 :group 'org-export-html
588 :type 'integer)
590 (defcustom org-html-format-headline-function nil
591 "Function to format headline text.
593 This function will be called with 5 arguments:
594 TODO the todo keyword (string or nil).
595 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
596 PRIORITY the priority of the headline (integer or nil)
597 TEXT the main headline text (string).
598 TAGS the tags (string or nil).
600 The function result will be used in the section format string."
601 :group 'org-export-html
602 :type 'function)
604 ;;;; HTML-specific
606 (defcustom org-html-allow-name-attribute-in-anchors t
607 "When nil, do not set \"name\" attribute in anchors.
608 By default, anchors are formatted with both \"id\" and \"name\"
609 attributes, when appropriate."
610 :group 'org-export-html
611 :version "24.4"
612 :package-version '(Org . "8.0")
613 :type 'boolean)
615 ;;;; Inlinetasks
617 (defcustom org-html-format-inlinetask-function nil
618 "Function called to format an inlinetask in HTML code.
620 The function must accept six parameters:
621 TODO the todo keyword, as a string
622 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
623 PRIORITY the inlinetask priority, as a string
624 NAME the inlinetask name, as a string.
625 TAGS the inlinetask tags, as a list of strings.
626 CONTENTS the contents of the inlinetask, as a string.
628 The function should return the string to be exported."
629 :group 'org-export-html
630 :type 'function)
632 ;;;; LaTeX
634 (defcustom org-html-with-latex org-export-with-latex
635 "Non-nil means process LaTeX math snippets.
637 When set, the exporter will process LaTeX environments and
638 fragments.
640 This option can also be set with the +OPTIONS line,
641 e.g. \"tex:mathjax\". Allowed values are:
643 nil Ignore math snippets.
644 `verbatim' Keep everything in verbatim
645 `dvipng' Process the LaTeX fragments to images. This will also
646 include processing of non-math environments.
647 `imagemagick' Convert the LaTeX fragments to pdf files and use
648 imagemagick to convert pdf files to png files.
649 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
650 be loaded.
651 t Synonym for `mathjax'."
652 :group 'org-export-html
653 :version "24.4"
654 :package-version '(Org . "8.0")
655 :type '(choice
656 (const :tag "Do not process math in any way" nil)
657 (const :tag "Use dvipng to make images" dvipng)
658 (const :tag "Use imagemagick to make images" imagemagick)
659 (const :tag "Use MathJax to display math" mathjax)
660 (const :tag "Leave math verbatim" verbatim)))
662 ;;;; Links :: Generic
664 (defcustom org-html-link-org-files-as-html t
665 "Non-nil means make file links to `file.org' point to `file.html'.
666 When `org-mode' is exporting an `org-mode' file to HTML, links to
667 non-html files are directly put into a href tag in HTML.
668 However, links to other Org-mode files (recognized by the
669 extension `.org.) should become links to the corresponding html
670 file, assuming that the linked `org-mode' file will also be
671 converted to HTML.
672 When nil, the links still point to the plain `.org' file."
673 :group 'org-export-html
674 :type 'boolean)
676 ;;;; Links :: Inline images
678 (defcustom org-html-inline-images 'maybe
679 "Non-nil means inline images into exported HTML pages.
680 This is done using an <img> tag. When nil, an anchor with href is used to
681 link to the image. If this option is `maybe', then images in links with
682 an empty description will be inlined, while images with a description will
683 be linked only."
684 :group 'org-export-html
685 :type '(choice (const :tag "Never" nil)
686 (const :tag "Always" t)
687 (const :tag "When there is no description" maybe)))
689 (defcustom org-html-inline-image-rules
690 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
691 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
692 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
693 "Rules characterizing image files that can be inlined into HTML.
695 A rule consists in an association whose key is the type of link
696 to consider, and value is a regexp that will be matched against
697 link's path.
699 Note that, by default, the image extension *actually* allowed
700 depend on the way the HTML file is processed. When used with
701 pdflatex, pdf, jpg and png images are OK. When processing
702 through dvi to Postscript, only ps and eps are allowed. The
703 default we use here encompasses both."
704 :group 'org-export-html
705 :version "24.4"
706 :package-version '(Org . "8.0")
707 :type '(alist :key-type (string :tag "Type")
708 :value-type (regexp :tag "Path")))
710 ;;;; Plain Text
712 (defcustom org-html-protect-char-alist
713 '(("&" . "&amp;")
714 ("<" . "&lt;")
715 (">" . "&gt;"))
716 "Alist of characters to be converted by `org-html-protect'."
717 :group 'org-export-html
718 :type '(repeat (cons (string :tag "Character")
719 (string :tag "HTML equivalent"))))
721 ;;;; Src Block
723 (defcustom org-html-htmlize-output-type 'inline-css
724 "Output type to be used by htmlize when formatting code snippets.
725 Choices are `css', to export the CSS selectors only, or `inline-css', to
726 export the CSS attribute values inline in the HTML. We use as default
727 `inline-css', in order to make the resulting HTML self-containing.
729 However, this will fail when using Emacs in batch mode for export, because
730 then no rich font definitions are in place. It will also not be good if
731 people with different Emacs setup contribute HTML files to a website,
732 because the fonts will represent the individual setups. In these cases,
733 it is much better to let Org/Htmlize assign classes only, and to use
734 a style file to define the look of these classes.
735 To get a start for your css file, start Emacs session and make sure that
736 all the faces you are interested in are defined, for example by loading files
737 in all modes you want. Then, use the command
738 \\[org-html-htmlize-generate-css] to extract class definitions."
739 :group 'org-export-html
740 :type '(choice (const css) (const inline-css)))
742 (defcustom org-html-htmlize-font-prefix "org-"
743 "The prefix for CSS class names for htmlize font specifications."
744 :group 'org-export-html
745 :type 'string)
747 ;;;; Table
749 (defcustom org-html-table-tag
750 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
751 "The HTML tag that is used to start a table.
752 This must be a <table> tag, but you may change the options like
753 borders and spacing."
754 :group 'org-export-html
755 :type 'string)
757 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
758 "The opening tag for table header fields.
759 This is customizable so that alignment options can be specified.
760 The first %s will be filled with the scope of the field, either row or col.
761 The second %s will be replaced by a style entry to align the field.
762 See also the variable `org-html-table-use-header-tags-for-first-column'.
763 See also the variable `org-html-table-align-individual-fields'."
764 :group 'org-export-html
765 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
767 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
768 "The opening tag for table data fields.
769 This is customizable so that alignment options can be specified.
770 The first %s will be filled with the scope of the field, either row or col.
771 The second %s will be replaced by a style entry to align the field.
772 See also the variable `org-html-table-align-individual-fields'."
773 :group 'org-export-html
774 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
776 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
777 "The opening and ending tags for table rows.
778 This is customizable so that alignment options can be specified.
779 Instead of strings, these can be Lisp forms that will be
780 evaluated for each row in order to construct the table row tags.
782 During evaluation, these variables will be dynamically bound so that
783 you can reuse them:
785 `row-number': row number (0 is the first row)
786 `rowgroup-number': group number of current row
787 `start-rowgroup-p': non-nil means the row starts a group
788 `end-rowgroup-p': non-nil means the row ends a group
789 `top-row-p': non-nil means this is the top row
790 `bottom-row-p': non-nil means this is the bottom row
792 For example:
794 \(setq org-html-table-row-tags
795 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
796 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
797 (t (if (= (mod row-number 2) 1)
798 \"<tr class=\\\"tr-odd\\\">\"
799 \"<tr class=\\\"tr-even\\\">\")))
800 \"</tr>\"))
802 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
803 and the bottom row, and otherwise alternate between \"tr-odd\" and
804 \"tr-even\" for odd and even rows."
805 :group 'org-export-html
806 :type '(cons
807 (choice :tag "Opening tag"
808 (string :tag "Specify")
809 (sexp))
810 (choice :tag "Closing tag"
811 (string :tag "Specify")
812 (sexp))))
814 (defcustom org-html-table-align-individual-fields t
815 "Non-nil means attach style attributes for alignment to each table field.
816 When nil, alignment will only be specified in the column tags, but this
817 is ignored by some browsers (like Firefox, Safari). Opera does it right
818 though."
819 :group 'org-export-html
820 :type 'boolean)
822 (defcustom org-html-table-use-header-tags-for-first-column nil
823 "Non-nil means format column one in tables with header tags.
824 When nil, also column one will use data tags."
825 :group 'org-export-html
826 :type 'boolean)
828 (defcustom org-html-table-caption-above t
829 "When non-nil, place caption string at the beginning of the table.
830 Otherwise, place it near the end."
831 :group 'org-export-html
832 :type 'boolean)
834 ;;;; Tags
836 (defcustom org-html-tag-class-prefix ""
837 "Prefix to class names for TODO keywords.
838 Each tag gets a class given by the tag itself, with this prefix.
839 The default prefix is empty because it is nice to just use the keyword
840 as a class name. But if you get into conflicts with other, existing
841 CSS classes, then this prefix can be very useful."
842 :group 'org-export-html
843 :type 'string)
845 ;;;; Template :: Generic
847 (defcustom org-html-extension "html"
848 "The extension for exported HTML files."
849 :group 'org-export-html
850 :type 'string)
852 (defcustom org-html-xml-declaration
853 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
854 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
855 "The extension for exported HTML files.
856 %s will be replaced with the charset of the exported file.
857 This may be a string, or an alist with export extensions
858 and corresponding declarations."
859 :group 'org-export-html
860 :type '(choice
861 (string :tag "Single declaration")
862 (repeat :tag "Dependent on extension"
863 (cons (string :tag "Extension")
864 (string :tag "Declaration")))))
866 (defcustom org-html-coding-system 'utf-8
867 "Coding system for HTML export.
868 Use utf-8 as the default value."
869 :group 'org-export-html
870 :version "24.4"
871 :package-version '(Org . "8.0")
872 :type 'coding-system)
874 (defcustom org-html-doctype
875 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
876 "Document type definition to use for exported HTML files.
877 Can be set with the in-buffer HTML_DOCTYPE property or for
878 publishing, with :html-doctype."
879 :group 'org-export-html
880 :version "24.4"
881 :package-version '(Org . "8.0")
882 :type 'string)
884 (defcustom org-html-container-element "div"
885 "HTML element to use for wrapping top level sections.
886 Can be set with the in-buffer HTML_CONTAINER property or for
887 publishing, with :html-container.
889 Note that changing the default will prevent you from using
890 org-info.js for your website."
891 :group 'org-export-html
892 :version "24.4"
893 :package-version '(Org . "8.0")
894 :type 'string)
896 (defcustom org-html-divs
897 '((preamble "div" "preamble")
898 (content "div" "content")
899 (postamble "div" "postamble"))
900 "Alist of the three section elements for HTML export.
901 The car of each entry is one of 'preamble, 'content or 'postamble.
902 The cdrs of each entry are the ELEMENT_TYPE and ID for each
903 section of the exported document.
905 Note that changing the default will prevent you from using
906 org-info.js for your website."
907 :group 'org-export-html
908 :version "24.4"
909 :package-version '(Org . "8.0")
910 :type '(list :greedy t
911 (list :tag "Preamble"
912 (const :format "" preamble)
913 (string :tag "element") (string :tag " id"))
914 (list :tag "Content"
915 (const :format "" content)
916 (string :tag "element") (string :tag " id"))
917 (list :tag "Postamble" (const :format "" postamble)
918 (string :tag " id") (string :tag "element"))))
920 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
921 "Format used for timestamps in preamble, postamble and metadata.
922 See `format-time-string' for more information on its components."
923 :group 'org-export-html
924 :version "24.4"
925 :package-version '(Org . "8.0")
926 :type 'string)
928 ;;;; Template :: Mathjax
930 (defcustom org-html-mathjax-options
931 '((path "http://orgmode.org/mathjax/MathJax.js")
932 (scale "100")
933 (align "center")
934 (indent "2em")
935 (mathml nil))
936 "Options for MathJax setup.
938 path The path where to find MathJax
939 scale Scaling for the HTML-CSS backend, usually between 100 and 133
940 align How to align display math: left, center, or right
941 indent If align is not center, how far from the left/right side?
942 mathml Should a MathML player be used if available?
943 This is faster and reduces bandwidth use, but currently
944 sometimes has lower spacing quality. Therefore, the default is
945 nil. When browsers get better, this switch can be flipped.
947 You can also customize this for each buffer, using something like
949 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
950 :group 'org-export-html
951 :type '(list :greedy t
952 (list :tag "path (the path from where to load MathJax.js)"
953 (const :format " " path) (string))
954 (list :tag "scale (scaling for the displayed math)"
955 (const :format " " scale) (string))
956 (list :tag "align (alignment of displayed equations)"
957 (const :format " " align) (string))
958 (list :tag "indent (indentation with left or right alignment)"
959 (const :format " " indent) (string))
960 (list :tag "mathml (should MathML display be used is possible)"
961 (const :format " " mathml) (boolean))))
963 (defcustom org-html-mathjax-template
964 "<script type=\"text/javascript\" src=\"%PATH\">
965 <!--/*--><![CDATA[/*><!--*/
966 MathJax.Hub.Config({
967 // Only one of the two following lines, depending on user settings
968 // First allows browser-native MathML display, second forces HTML/CSS
969 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
970 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
971 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
972 \"TeX/noUndefined.js\"],
973 tex2jax: {
974 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
975 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
976 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
977 ignoreClass: \"tex2jax_ignore\",
978 processEscapes: false,
979 processEnvironments: true,
980 preview: \"TeX\"
982 showProcessingMessages: true,
983 displayAlign: \"%ALIGN\",
984 displayIndent: \"%INDENT\",
986 \"HTML-CSS\": {
987 scale: %SCALE,
988 availableFonts: [\"STIX\",\"TeX\"],
989 preferredFont: \"TeX\",
990 webFont: \"TeX\",
991 imageFont: \"TeX\",
992 showMathMenu: true,
994 MMLorHTML: {
995 prefer: {
996 MSIE: \"MML\",
997 Firefox: \"MML\",
998 Opera: \"HTML\",
999 other: \"HTML\"
1003 /*]]>*///-->
1004 </script>"
1005 "The MathJax setup for XHTML files."
1006 :group 'org-export-html
1007 :type 'string)
1009 ;;;; Template :: Postamble
1011 (defcustom org-html-postamble 'auto
1012 "Non-nil means insert a postamble in HTML export.
1014 When set to 'auto, check against the
1015 `org-export-with-author/email/creator/date' variables to set the
1016 content of the postamble. When set to a string, use this string
1017 as the postamble. When t, insert a string as defined by the
1018 formatting string in `org-html-postamble-format'.
1020 When set to a function, apply this function and insert the
1021 returned string. The function takes the property list of export
1022 options as its only argument.
1024 Setting :html-postamble in publishing projects will take
1025 precedence over this variable."
1026 :group 'org-export-html
1027 :type '(choice (const :tag "No postamble" nil)
1028 (const :tag "Auto postamble" 'auto)
1029 (const :tag "Default formatting string" t)
1030 (string :tag "Custom formatting string")
1031 (function :tag "Function (must return a string)")))
1033 (defcustom org-html-postamble-format
1034 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1035 <p class=\"date\">Date: %d</p>
1036 <p class=\"creator\">%c</p>
1037 <p class=\"xhtml-validation\">%v</p>"))
1038 "Alist of languages and format strings for the HTML postamble.
1040 The first element of each list is the language code, as used for
1041 the LANGUAGE keyword. See `org-export-default-language'.
1043 The second element of each list is a format string to format the
1044 postamble itself. This format string can contain these elements:
1046 %t stands for the title.
1047 %a stands for the author's name.
1048 %e stands for the author's email.
1049 %d stands for the date.
1050 %c will be replaced by `org-html-creator-string'.
1051 %v will be replaced by `org-html-validation-link'.
1052 %T will be replaced by the export time.
1053 %C will be replaced by the last modification time.
1055 If you need to use a \"%\" character, you need to escape it
1056 like that: \"%%\"."
1057 :group 'org-export-html
1058 :type '(alist :key-type (string :tag "Language")
1059 :value-type (string :tag "Format string")))
1061 (defcustom org-html-validation-link
1062 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1063 "Link to HTML validation service."
1064 :group 'org-export-html
1065 :type 'string)
1067 (defcustom org-html-creator-string
1068 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1069 emacs-version
1070 (if (fboundp 'org-version) (org-version) "unknown version"))
1071 "Information about the creator of the HTML document.
1072 This option can also be set on with the CREATOR keyword."
1073 :group 'org-export-html
1074 :type '(string :tag "Creator string"))
1076 ;;;; Template :: Preamble
1078 (defcustom org-html-preamble t
1079 "Non-nil means insert a preamble in HTML export.
1081 When t, insert a string as defined by the formatting string in
1082 `org-html-preamble-format'. When set to a string, use this
1083 formatting string instead (see `org-html-postamble-format' for an
1084 example of such a formatting string).
1086 When set to a function, apply this function and insert the
1087 returned string. The function takes the property list of export
1088 options as its only argument.
1090 Setting :html-preamble in publishing projects will take
1091 precedence over this variable."
1092 :group 'org-export-html
1093 :type '(choice (const :tag "No preamble" nil)
1094 (const :tag "Default preamble" t)
1095 (string :tag "Custom formatting string")
1096 (function :tag "Function (must return a string)")))
1098 (defcustom org-html-preamble-format '(("en" ""))
1099 "Alist of languages and format strings for the HTML preamble.
1101 The first element of each list is the language code, as used for
1102 the LANGUAGE keyword. See `org-export-default-language'.
1104 The second element of each list is a format string to format the
1105 preamble itself. This format string can contain these elements:
1107 %t stands for the title.
1108 %a stands for the author's name.
1109 %e stands for the author's email.
1110 %d stands for the date.
1111 %c will be replaced by `org-html-creator-string'.
1112 %v will be replaced by `org-html-validation-link'.
1113 %T will be replaced by the export time.
1114 %C will be replaced by the last modification time.
1116 If you need to use a \"%\" character, you need to escape it
1117 like that: \"%%\".
1119 See the default value of `org-html-postamble-format' for an
1120 example."
1121 :group 'org-export-html
1122 :type '(alist :key-type (string :tag "Language")
1123 :value-type (string :tag "Format string")))
1125 (defcustom org-html-link-up ""
1126 "Where should the \"UP\" link of exported HTML pages lead?"
1127 :group 'org-export-html
1128 :type '(string :tag "File or URL"))
1130 (defcustom org-html-link-home ""
1131 "Where should the \"HOME\" link of exported HTML pages lead?"
1132 :group 'org-export-html
1133 :type '(string :tag "File or URL"))
1135 (defcustom org-html-home/up-format
1136 "<div id=\"org-div-home-and-up\">
1137 <a accesskey=\"h\" href=\"%s\"> UP </a>
1139 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1140 </div>"
1141 "Snippet used to insert the HOME and UP links.
1142 This is a format string, the first %s will receive the UP link,
1143 the second the HOME link. If both `org-html-link-up' and
1144 `org-html-link-home' are empty, the entire snippet will be
1145 ignored."
1146 :group 'org-export-html
1147 :type 'string)
1149 ;;;; Template :: Scripts
1151 (define-obsolete-variable-alias
1152 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1153 (defcustom org-html-head-include-scripts t
1154 "Non-nil means include the JavaScript snippets in exported HTML files.
1155 The actual script is defined in `org-html-scripts' and should
1156 not be modified."
1157 :group 'org-export-html
1158 :version "24.4"
1159 :package-version '(Org . "8.0")
1160 :type 'boolean)
1162 ;;;; Template :: Styles
1164 (define-obsolete-variable-alias
1165 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1166 (defcustom org-html-head-include-default-style t
1167 "Non-nil means include the default style in exported HTML files.
1168 The actual style is defined in `org-html-style-default' and
1169 should not be modified. Use `org-html-head' to use your own
1170 style information."
1171 :group 'org-export-html
1172 :version "24.4"
1173 :package-version '(Org . "8.0")
1174 :type 'boolean)
1175 ;;;###autoload
1176 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1178 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1179 (defcustom org-html-head ""
1180 "Org-wide head definitions for exported HTML files.
1182 This variable can contain the full HTML structure to provide a
1183 style, including the surrounding HTML tags. You can consider
1184 including definitions for the following classes: title, todo,
1185 done, timestamp, timestamp-kwd, tag, target.
1187 For example, a valid value would be:
1189 <style type=\"text/css\">
1190 <![CDATA[
1191 p { font-weight: normal; color: gray; }
1192 h1 { color: black; }
1193 .title { text-align: center; }
1194 .todo, .timestamp-kwd { color: red; }
1195 .done { color: green; }
1197 </style>
1199 If you want to refer to an external style, use something like
1201 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1203 As the value of this option simply gets inserted into the HTML
1204 <head> header, you can use it to add any arbitrary text to the
1205 header.
1207 You can set this on a per-file basis using #+HTML_HEAD:,
1208 or for publication projects using the :html-head property."
1209 :group 'org-export-html
1210 :version "24.4"
1211 :package-version '(Org . "8.0")
1212 :type 'string)
1213 ;;;###autoload
1214 (put 'org-html-head 'safe-local-variable 'stringp)
1216 (defcustom org-html-head-extra ""
1217 "More head information to add in the HTML output.
1219 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1220 or for publication projects using the :html-head-extra property."
1221 :group 'org-export-html
1222 :version "24.4"
1223 :package-version '(Org . "8.0")
1224 :type 'string)
1225 ;;;###autoload
1226 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1228 ;;;; Todos
1230 (defcustom org-html-todo-kwd-class-prefix ""
1231 "Prefix to class names for TODO keywords.
1232 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1233 The default prefix is empty because it is nice to just use the keyword
1234 as a class name. But if you get into conflicts with other, existing
1235 CSS classes, then this prefix can be very useful."
1236 :group 'org-export-html
1237 :type 'string)
1240 ;;; Internal Functions
1242 (defun org-html-format-inline-image (src &optional
1243 caption label attr standalone-p)
1244 "Format an inline image from SRC.
1245 CAPTION, LABEL and ATTR are optional arguments providing the
1246 caption, the label and the attribute of the image.
1247 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1248 (let* ((id (if (not label) ""
1249 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1250 (attr (concat attr
1251 (cond
1252 ((string-match "\\<alt=" (or attr "")) "")
1253 ((string-match "^ltxpng/" src)
1254 (format " alt=\"%s\""
1255 (org-html-encode-plain-text
1256 (org-find-text-property-in-string
1257 'org-latex-src src))))
1258 (t (format " alt=\"%s\""
1259 (file-name-nondirectory src)))))))
1260 (cond
1261 (standalone-p
1262 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1263 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1264 id (format "\n<p>%s</p>" img)
1265 (if (and caption (not (string= caption "")))
1266 (format "\n<p>%s</p>" caption) ""))))
1267 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1269 (defun org-html--textarea-block (element)
1270 "Transcode ELEMENT into a textarea block.
1271 ELEMENT is either a src block or an example block."
1272 (let* ((code (car (org-export-unravel-code element)))
1273 (attr (org-export-read-attribute :attr_html element)))
1274 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1275 (or (plist-get attr :width) 80)
1276 (or (plist-get attr :height) (org-count-lines code))
1277 code)))
1279 ;;;; Bibliography
1281 (defun org-html-bibliography ()
1282 "Find bibliography, cut it out and return it."
1283 (catch 'exit
1284 (let (beg end (cnt 1) bib)
1285 (save-excursion
1286 (goto-char (point-min))
1287 (when (re-search-forward
1288 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1289 (setq beg (match-beginning 0))
1290 (while (re-search-forward "</?div\\>" nil t)
1291 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1292 (when (= cnt 0)
1293 (and (looking-at ">") (forward-char 1))
1294 (setq bib (buffer-substring beg (point)))
1295 (delete-region beg (point))
1296 (throw 'exit bib))))
1297 nil))))
1299 ;;;; Table
1301 (defun org-html-splice-attributes (tag attributes)
1302 "Return a HTML TAG edited wrt ATTRIBUTES."
1303 (if (not attributes)
1305 (let (oldatt newatt)
1306 (setq oldatt (org-extract-attributes-from-string tag)
1307 tag (pop oldatt)
1308 newatt (cdr (org-extract-attributes-from-string attributes)))
1309 (while newatt
1310 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1311 (if (string-match ">" tag)
1312 (setq tag
1313 (replace-match (concat (org-attributes-to-string oldatt) ">")
1314 t t tag)))
1315 tag)))
1317 (defun org-export-splice-style (style extra)
1318 "Return STYLE updated wrt EXTRA."
1319 (if (and (stringp extra)
1320 (string-match "\\S-" extra)
1321 (string-match "</style>" style))
1322 (concat (substring style 0 (match-beginning 0))
1323 "\n" extra "\n"
1324 (substring style (match-beginning 0)))
1325 style))
1327 (defun org-html-htmlize-region-for-paste (beg end)
1328 "Convert the region between BEG and END to HTML, using htmlize.el.
1329 This is much like `htmlize-region-for-paste', only that it uses
1330 the settings define in the org-... variables."
1331 (let* ((htmlize-output-type org-html-htmlize-output-type)
1332 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1333 (htmlbuf (htmlize-region beg end)))
1334 (unwind-protect
1335 (with-current-buffer htmlbuf
1336 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1337 (plist-get htmlize-buffer-places 'content-end)))
1338 (kill-buffer htmlbuf))))
1340 ;;;###autoload
1341 (defun org-html-htmlize-generate-css ()
1342 "Create the CSS for all font definitions in the current Emacs session.
1343 Use this to create face definitions in your CSS style file that can then
1344 be used by code snippets transformed by htmlize.
1345 This command just produces a buffer that contains class definitions for all
1346 faces used in the current Emacs session. You can copy and paste the ones you
1347 need into your CSS file.
1349 If you then set `org-html-htmlize-output-type' to `css', calls
1350 to the function `org-html-htmlize-region-for-paste' will
1351 produce code that uses these same face definitions."
1352 (interactive)
1353 (require 'htmlize)
1354 (and (get-buffer "*html*") (kill-buffer "*html*"))
1355 (with-temp-buffer
1356 (let ((fl (face-list))
1357 (htmlize-css-name-prefix "org-")
1358 (htmlize-output-type 'css)
1359 f i)
1360 (while (setq f (pop fl)
1361 i (and f (face-attribute f :inherit)))
1362 (when (and (symbolp f) (or (not i) (not (listp i))))
1363 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1364 (htmlize-region (point-min) (point-max))))
1365 (org-pop-to-buffer-same-window "*html*")
1366 (goto-char (point-min))
1367 (if (re-search-forward "<style" nil t)
1368 (delete-region (point-min) (match-beginning 0)))
1369 (if (re-search-forward "</style>" nil t)
1370 (delete-region (1+ (match-end 0)) (point-max)))
1371 (beginning-of-line 1)
1372 (if (looking-at " +") (replace-match ""))
1373 (goto-char (point-min)))
1375 (defun org-html--make-string (n string)
1376 "Build a string by concatenating N times STRING."
1377 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1379 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1380 "Turn todo keyword KWD into a valid class name.
1381 Replaces invalid characters with \"_\"."
1382 (save-match-data
1383 (while (string-match "[^a-zA-Z0-9_]" kwd)
1384 (setq kwd (replace-match "_" t t kwd))))
1385 kwd)
1387 (defun org-html-format-footnote-reference (n def refcnt)
1388 "Format footnote reference N with definition DEF into HTML."
1389 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1390 (format org-html-footnote-format
1391 (let* ((id (format "fnr.%s%s" n extra))
1392 (href (format " href=\"#fn.%s\"" n))
1393 (attributes (concat " class=\"footref\"" href)))
1394 (org-html--anchor id n attributes)))))
1396 (defun org-html-format-footnotes-section (section-name definitions)
1397 "Format footnotes section SECTION-NAME."
1398 (if (not definitions) ""
1399 (format org-html-footnotes-section section-name definitions)))
1401 (defun org-html-format-footnote-definition (fn)
1402 "Format the footnote definition FN."
1403 (let ((n (car fn)) (def (cdr fn)))
1404 (format
1405 "<div class=\"footdef\">%s %s</div>\n"
1406 (format org-html-footnote-format
1407 (let* ((id (format "fn.%s" n))
1408 (href (format " href=\"#fnr.%s\"" n))
1409 (attributes (concat " class=\"footnum\"" href)))
1410 (org-html--anchor id n attributes)))
1411 def)))
1413 (defun org-html-footnote-section (info)
1414 "Format the footnote section.
1415 INFO is a plist used as a communication channel."
1416 (let* ((fn-alist (org-export-collect-footnote-definitions
1417 (plist-get info :parse-tree) info))
1418 (fn-alist
1419 (loop for (n type raw) in fn-alist collect
1420 (cons n (if (eq (org-element-type raw) 'org-data)
1421 (org-trim (org-export-data raw info))
1422 (format "<p>%s</p>"
1423 (org-trim (org-export-data raw info))))))))
1424 (when fn-alist
1425 (org-html-format-footnotes-section
1426 (org-html--translate "Footnotes" info)
1427 (format
1428 "\n%s\n"
1429 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1432 ;;; Template
1434 (defun org-html--build-meta-info (info)
1435 "Return meta tags for exported document.
1436 INFO is a plist used as a communication channel."
1437 (let* ((title (org-export-data (plist-get info :title) info))
1438 (author (and (plist-get info :with-author)
1439 (let ((auth (plist-get info :author)))
1440 (and auth (org-export-data auth info)))))
1441 (description (plist-get info :description))
1442 (keywords (plist-get info :keywords)))
1443 (concat
1444 (format "<title>%s</title>\n" title)
1445 (format
1446 (when :time-stamp-file
1447 (format-time-string
1448 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
1449 (format
1450 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1451 (or (and org-html-coding-system
1452 (fboundp 'coding-system-get)
1453 (coding-system-get org-html-coding-system 'mime-charset))
1454 "iso-8859-1"))
1455 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1456 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1457 (and description
1458 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1459 (and keywords
1460 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1462 (defun org-html--build-head (info)
1463 "Return information for the <head>..</head> of the HTML output.
1464 INFO is a plist used as a communication channel."
1465 (org-element-normalize-string
1466 (concat
1467 (when (plist-get info :html-head-include-default-style)
1468 (org-element-normalize-string org-html-style-default))
1469 (org-element-normalize-string (plist-get info :html-head))
1470 (org-element-normalize-string (plist-get info :html-head-extra))
1471 (when (and (plist-get info :html-htmlized-css-url)
1472 (eq org-html-htmlize-output-type 'css))
1473 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1474 (plist-get info :html-htmlized-css-url)))
1475 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1477 (defun org-html--build-mathjax-config (info)
1478 "Insert the user setup into the mathjax template.
1479 INFO is a plist used as a communication channel."
1480 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1481 (org-element-map (plist-get info :parse-tree)
1482 '(latex-fragment latex-environment) 'identity info t))
1483 (let ((template org-html-mathjax-template)
1484 (options org-html-mathjax-options)
1485 (in-buffer (or (plist-get info :html-mathjax) ""))
1486 name val (yes " ") (no "// ") x)
1487 (mapc
1488 (lambda (e)
1489 (setq name (car e) val (nth 1 e))
1490 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1491 (setq val (car (read-from-string
1492 (substring in-buffer (match-end 0))))))
1493 (if (not (stringp val)) (setq val (format "%s" val)))
1494 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1495 (setq template (replace-match val t t template))))
1496 options)
1497 (setq val (nth 1 (assq 'mathml options)))
1498 (if (string-match (concat "\\<mathml:") in-buffer)
1499 (setq val (car (read-from-string
1500 (substring in-buffer (match-end 0))))))
1501 ;; Exchange prefixes depending on mathml setting.
1502 (if (not val) (setq x yes yes no no x))
1503 ;; Replace cookies to turn on or off the config/jax lines.
1504 (if (string-match ":MMLYES:" template)
1505 (setq template (replace-match yes t t template)))
1506 (if (string-match ":MMLNO:" template)
1507 (setq template (replace-match no t t template)))
1508 ;; Return the modified template.
1509 (org-element-normalize-string template))))
1511 (defun org-html-format-spec (info)
1512 "Return format specification for elements that can be
1513 used in the preamble or postamble."
1514 `((?t . ,(org-export-data (plist-get info :title) info))
1515 (?d . ,(org-export-data (org-export-get-date info) info))
1516 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1517 (?a . ,(org-export-data (plist-get info :author) info))
1518 (?e . ,(mapconcat
1519 (lambda (e)
1520 (format "<a href=\"mailto:%s\">%s</a>" e e))
1521 (split-string (plist-get info :email) ",+ *")
1522 ", "))
1523 (?c . ,(plist-get info :creator))
1524 (?C . ,(let ((file (plist-get info :input-file)))
1525 (format-time-string org-html-metadata-timestamp-format
1526 (if file (nth 5 (file-attributes file))
1527 (current-time)))))
1528 (?v . ,(or org-html-validation-link ""))))
1530 (defun org-html--build-pre/postamble (type info)
1531 "Return document preamble or postamble as a string, or nil.
1532 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1533 communication channel."
1534 (let ((section (plist-get info (intern (format ":html-%s" type))))
1535 (spec (org-html-format-spec info)))
1536 (when section
1537 (let ((section-contents
1538 (if (functionp section) (funcall section info)
1539 (cond
1540 ((stringp section) (format-spec section spec))
1541 ((eq section 'auto)
1542 (let ((date (cdr (assq ?d spec)))
1543 (author (cdr (assq ?a spec)))
1544 (email (cdr (assq ?e spec)))
1545 (creator (cdr (assq ?c spec)))
1546 (timestamp (cdr (assq ?T spec)))
1547 (validation-link (cdr (assq ?v spec))))
1548 (concat
1549 (when (and (plist-get info :with-date)
1550 (org-string-nw-p date))
1551 (format "<p class=\"date\">%s: %s</p>\n"
1552 (org-html--translate "Date" info)
1553 date))
1554 (when (and (plist-get info :with-author)
1555 (org-string-nw-p author))
1556 (format "<p class=\"author\">%s: %s</p>\n"
1557 (org-html--translate "Author" info)
1558 author))
1559 (when (and (plist-get info :with-email)
1560 (org-string-nw-p email))
1561 (format "<p class=\"email\">%s: %s</p>\n"
1562 (org-html--translate "Email" info)
1563 email))
1564 (when (plist-get info :time-stamp-file)
1565 (format
1566 "<p class=\"date\">%s: %s</p>\n"
1567 (org-html--translate "Created" info)
1568 (format-time-string org-html-metadata-timestamp-format)))
1569 (when (plist-get info :with-creator)
1570 (format "<p class=\"creator\">%s</p>\n" creator))
1571 (format "<p class=\"xhtml-validation\">%s</p>\n"
1572 validation-link))))
1573 (t (format-spec
1574 (or (cadr (assoc
1575 (plist-get info :language)
1576 (eval (intern
1577 (format "org-html-%s-format" type)))))
1578 (cadr
1579 (assoc
1580 "en"
1581 (eval
1582 (intern (format "org-html-%s-format" type))))))
1583 spec))))))
1584 (when (org-string-nw-p section-contents)
1585 (concat
1586 (format "<%s id=\"%s\" class=\"%s\">\n"
1587 (nth 1 (assq type org-html-divs))
1588 (nth 2 (assq type org-html-divs))
1589 org-html--pre/postamble-class)
1590 (org-element-normalize-string section-contents)
1591 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1593 (defun org-html-inner-template (contents info)
1594 "Return body of document string after HTML conversion.
1595 CONTENTS is the transcoded contents string. INFO is a plist
1596 holding export options."
1597 (concat
1598 ;; Table of contents.
1599 (let ((depth (plist-get info :with-toc)))
1600 (when depth (org-html-toc depth info)))
1601 ;; Document contents.
1602 contents
1603 ;; Footnotes section.
1604 (org-html-footnote-section info)
1605 ;; Bibliography.
1606 (org-html-bibliography)))
1608 (defun org-html-template (contents info)
1609 "Return complete document string after HTML conversion.
1610 CONTENTS is the transcoded contents string. INFO is a plist
1611 holding export options."
1612 (concat
1613 (format
1614 (or (and (stringp org-html-xml-declaration)
1615 org-html-xml-declaration)
1616 (cdr (assoc (plist-get info :html-extension)
1617 org-html-xml-declaration))
1618 (cdr (assoc "html" org-html-xml-declaration))
1621 (or (and org-html-coding-system
1622 (fboundp 'coding-system-get)
1623 (coding-system-get org-html-coding-system 'mime-charset))
1624 "iso-8859-1"))
1625 "\n"
1626 (plist-get info :html-doctype)
1627 "\n"
1628 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1629 (plist-get info :language) (plist-get info :language))
1630 "<head>\n"
1631 (org-html--build-meta-info info)
1632 (org-html--build-head info)
1633 (org-html--build-mathjax-config info)
1634 "</head>\n"
1635 "<body>\n"
1636 (let ((link-up (org-trim (plist-get info :html-link-up)))
1637 (link-home (org-trim (plist-get info :html-link-home))))
1638 (unless (and (string= link-up "") (string= link-up ""))
1639 (format org-html-home/up-format
1640 (or link-up link-home)
1641 (or link-home link-up))))
1642 ;; Preamble.
1643 (org-html--build-pre/postamble 'preamble info)
1644 ;; Document contents.
1645 (format "<%s id=\"%s\">\n"
1646 (nth 1 (assq 'content org-html-divs))
1647 (nth 2 (assq 'content org-html-divs)))
1648 ;; Document title.
1649 (let ((title (plist-get info :title)))
1650 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1651 contents
1652 (format "</%s>\n"
1653 (nth 1 (assq 'content org-html-divs)))
1654 ;; Postamble.
1655 (org-html--build-pre/postamble 'postamble info)
1656 ;; Closing document.
1657 "</body>\n</html>"))
1659 (defun org-html--translate (s info)
1660 "Translate string S according to specified language.
1661 INFO is a plist used as a communication channel."
1662 (org-export-translate s :html info))
1664 ;;;; Anchor
1666 (defun org-html--anchor (&optional id desc attributes)
1667 "Format a HTML anchor."
1668 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1669 (attributes (concat (and id (format " id=\"%s\"" id))
1670 (and name (format " name=\"%s\"" name))
1671 attributes)))
1672 (format "<a%s>%s</a>" attributes (or desc ""))))
1674 ;;;; Todo
1676 (defun org-html--todo (todo)
1677 "Format TODO keywords into HTML."
1678 (when todo
1679 (format "<span class=\"%s %s%s\">%s</span>"
1680 (if (member todo org-done-keywords) "done" "todo")
1681 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1682 todo)))
1684 ;;;; Tags
1686 (defun org-html--tags (tags)
1687 "Format TAGS into HTML."
1688 (when tags
1689 (format "<span class=\"tag\">%s</span>"
1690 (mapconcat
1691 (lambda (tag)
1692 (format "<span class=\"%s\">%s</span>"
1693 (concat org-html-tag-class-prefix
1694 (org-html-fix-class-name tag))
1695 tag))
1696 tags "&#xa0;"))))
1698 ;;;; Headline
1700 (defun* org-html-format-headline
1701 (todo todo-type priority text tags
1702 &key level section-number headline-label &allow-other-keys)
1703 "Format a headline in HTML."
1704 (let ((section-number
1705 (when section-number
1706 (format "<span class=\"section-number-%d\">%s</span> "
1707 level section-number)))
1708 (todo (org-html--todo todo))
1709 (tags (org-html--tags tags)))
1710 (concat section-number todo (and todo " ") text
1711 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1713 ;;;; Src Code
1715 (defun org-html-fontify-code (code lang)
1716 "Color CODE with htmlize library.
1717 CODE is a string representing the source code to colorize. LANG
1718 is the language used for CODE, as a string, or nil."
1719 (when code
1720 (cond
1721 ;; Case 1: No lang. Possibly an example block.
1722 ((not lang)
1723 ;; Simple transcoding.
1724 (org-html-encode-plain-text code))
1725 ;; Case 2: No htmlize or an inferior version of htmlize
1726 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1727 ;; Emit a warning.
1728 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1729 ;; Simple transcoding.
1730 (org-html-encode-plain-text code))
1732 ;; Map language
1733 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1734 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1735 (cond
1736 ;; Case 1: Language is not associated with any Emacs mode
1737 ((not (functionp lang-mode))
1738 ;; Simple transcoding.
1739 (org-html-encode-plain-text code))
1740 ;; Case 2: Default. Fontify code.
1742 ;; htmlize
1743 (setq code (with-temp-buffer
1744 ;; Switch to language-specific mode.
1745 (funcall lang-mode)
1746 (insert code)
1747 ;; Fontify buffer.
1748 (font-lock-fontify-buffer)
1749 ;; Remove formatting on newline characters.
1750 (save-excursion
1751 (let ((beg (point-min))
1752 (end (point-max)))
1753 (goto-char beg)
1754 (while (progn (end-of-line) (< (point) end))
1755 (put-text-property (point) (1+ (point)) 'face nil)
1756 (forward-char 1))))
1757 (org-src-mode)
1758 (set-buffer-modified-p nil)
1759 ;; Htmlize region.
1760 (org-html-htmlize-region-for-paste
1761 (point-min) (point-max))))
1762 ;; Strip any enclosing <pre></pre> tags.
1763 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1764 (end (and beg (string-match "</pre>\\'" code))))
1765 (if (and beg end) (substring code beg end) code)))))))))
1767 (defun org-html-do-format-code
1768 (code &optional lang refs retain-labels num-start)
1769 "Format CODE string as source code.
1770 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1771 respectively, the language of the source code, as a string, an
1772 alist between line numbers and references (as returned by
1773 `org-export-unravel-code'), a boolean specifying if labels should
1774 appear in the source code, and the number associated to the first
1775 line of code."
1776 (let* ((code-lines (org-split-string code "\n"))
1777 (code-length (length code-lines))
1778 (num-fmt
1779 (and num-start
1780 (format "%%%ds: "
1781 (length (number-to-string (+ code-length num-start))))))
1782 (code (org-html-fontify-code code lang)))
1783 (org-export-format-code
1784 code
1785 (lambda (loc line-num ref)
1786 (setq loc
1787 (concat
1788 ;; Add line number, if needed.
1789 (when num-start
1790 (format "<span class=\"linenr\">%s</span>"
1791 (format num-fmt line-num)))
1792 ;; Transcoded src line.
1794 ;; Add label, if needed.
1795 (when (and ref retain-labels) (format " (%s)" ref))))
1796 ;; Mark transcoded line as an anchor, if needed.
1797 (if (not ref) loc
1798 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1799 ref loc)))
1800 num-start refs)))
1802 (defun org-html-format-code (element info)
1803 "Format contents of ELEMENT as source code.
1804 ELEMENT is either an example block or a src block. INFO is
1805 a plist used as a communication channel."
1806 (let* ((lang (org-element-property :language element))
1807 ;; Extract code and references.
1808 (code-info (org-export-unravel-code element))
1809 (code (car code-info))
1810 (refs (cdr code-info))
1811 ;; Does the src block contain labels?
1812 (retain-labels (org-element-property :retain-labels element))
1813 ;; Does it have line numbers?
1814 (num-start (case (org-element-property :number-lines element)
1815 (continued (org-export-get-loc element info))
1816 (new 0))))
1817 (org-html-do-format-code code lang refs retain-labels num-start)))
1820 ;;; Tables of Contents
1822 (defun org-html-toc (depth info)
1823 "Build a table of contents.
1824 DEPTH is an integer specifying the depth of the table. INFO is a
1825 plist used as a communication channel. Return the table of
1826 contents as a string, or nil if it is empty."
1827 (let ((toc-entries
1828 (mapcar (lambda (headline)
1829 (cons (org-html--format-toc-headline headline info)
1830 (org-export-get-relative-level headline info)))
1831 (org-export-collect-headlines info depth))))
1832 (when toc-entries
1833 (concat "<div id=\"table-of-contents\">\n"
1834 (format "<h%d>%s</h%d>\n"
1835 org-html-toplevel-hlevel
1836 (org-html--translate "Table of Contents" info)
1837 org-html-toplevel-hlevel)
1838 "<div id=\"text-table-of-contents\">"
1839 (org-html--toc-text toc-entries)
1840 "</div>\n"
1841 "</div>\n"))))
1843 (defun org-html--toc-text (toc-entries)
1844 "Return innards of a table of contents, as a string.
1845 TOC-ENTRIES is an alist where key is an entry title, as a string,
1846 and value is its relative level, as an integer."
1847 (let* ((prev-level (1- (cdar toc-entries)))
1848 (start-level prev-level))
1849 (concat
1850 (mapconcat
1851 (lambda (entry)
1852 (let ((headline (car entry))
1853 (level (cdr entry)))
1854 (concat
1855 (let* ((cnt (- level prev-level))
1856 (times (if (> cnt 0) (1- cnt) (- cnt)))
1857 rtn)
1858 (setq prev-level level)
1859 (concat
1860 (org-html--make-string
1861 times (cond ((> cnt 0) "\n<ul>\n<li>")
1862 ((< cnt 0) "</li>\n</ul>\n")))
1863 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1864 headline)))
1865 toc-entries "")
1866 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1868 (defun org-html--format-toc-headline (headline info)
1869 "Return an appropriate table of contents entry for HEADLINE.
1870 INFO is a plist used as a communication channel."
1871 (let* ((headline-number (org-export-get-headline-number headline info))
1872 (section-number
1873 (and (not (org-export-low-level-p headline info))
1874 (org-export-numbered-headline-p headline info)
1875 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1876 (tags (and (eq (plist-get info :with-tags) t)
1877 (org-export-get-tags headline info))))
1878 (format "<a href=\"#%s\">%s</a>"
1879 ;; Label.
1880 (org-export-solidify-link-text
1881 (or (org-element-property :CUSTOM_ID headline)
1882 (concat "sec-" (mapconcat 'number-to-string
1883 headline-number "-"))))
1884 ;; Body.
1885 (concat section-number
1886 (org-export-data-with-translations
1887 (org-export-get-alt-title headline info)
1888 ;; Ignore any footnote-reference, link,
1889 ;; radio-target and target in table of contents.
1890 (append
1891 '((footnote-reference . ignore)
1892 (link . (lambda (link desc i) desc))
1893 (radio-target . (lambda (radio desc i) desc))
1894 (target . ignore))
1895 (org-export-backend-translate-table 'html))
1896 info)
1897 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1899 (defun org-html-list-of-listings (info)
1900 "Build a list of listings.
1901 INFO is a plist used as a communication channel. Return the list
1902 of listings as a string, or nil if it is empty."
1903 (let ((lol-entries (org-export-collect-listings info)))
1904 (when lol-entries
1905 (concat "<div id=\"list-of-listings\">\n"
1906 (format "<h%d>%s</h%d>\n"
1907 org-html-toplevel-hlevel
1908 (org-html--translate "List of Listings" info)
1909 org-html-toplevel-hlevel)
1910 "<div id=\"text-list-of-listings\">\n<ul>\n"
1911 (let ((count 0)
1912 (initial-fmt (org-html--translate "Listing %d:" info)))
1913 (mapconcat
1914 (lambda (entry)
1915 (let ((label (org-element-property :name entry))
1916 (title (org-trim
1917 (org-export-data
1918 (or (org-export-get-caption entry t)
1919 (org-export-get-caption entry))
1920 info))))
1921 (concat
1922 "<li>"
1923 (if (not label)
1924 (concat (format initial-fmt (incf count)) " " title)
1925 (format "<a href=\"#%s\">%s %s</a>"
1926 (org-export-solidify-link-text label)
1927 (format initial-fmt (incf count))
1928 title))
1929 "</li>")))
1930 lol-entries "\n"))
1931 "\n</ul>\n</div>\n</div>"))))
1933 (defun org-html-list-of-tables (info)
1934 "Build a list of tables.
1935 INFO is a plist used as a communication channel. Return the list
1936 of tables as a string, or nil if it is empty."
1937 (let ((lol-entries (org-export-collect-tables info)))
1938 (when lol-entries
1939 (concat "<div id=\"list-of-tables\">\n"
1940 (format "<h%d>%s</h%d>\n"
1941 org-html-toplevel-hlevel
1942 (org-html--translate "List of Tables" info)
1943 org-html-toplevel-hlevel)
1944 "<div id=\"text-list-of-tables\">\n<ul>\n"
1945 (let ((count 0)
1946 (initial-fmt (org-html--translate "Table %d:" info)))
1947 (mapconcat
1948 (lambda (entry)
1949 (let ((label (org-element-property :name entry))
1950 (title (org-trim
1951 (org-export-data
1952 (or (org-export-get-caption entry t)
1953 (org-export-get-caption entry))
1954 info))))
1955 (concat
1956 "<li>"
1957 (if (not label)
1958 (concat (format initial-fmt (incf count)) " " title)
1959 (format "<a href=\"#%s\">%s %s</a>"
1960 (org-export-solidify-link-text label)
1961 (format initial-fmt (incf count))
1962 title))
1963 "</li>")))
1964 lol-entries "\n"))
1965 "\n</ul>\n</div>\n</div>"))))
1968 ;;; Transcode Functions
1970 ;;;; Bold
1972 (defun org-html-bold (bold contents info)
1973 "Transcode BOLD from Org to HTML.
1974 CONTENTS is the text with bold markup. INFO is a plist holding
1975 contextual information."
1976 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1977 contents))
1979 ;;;; Center Block
1981 (defun org-html-center-block (center-block contents info)
1982 "Transcode a CENTER-BLOCK element from Org to HTML.
1983 CONTENTS holds the contents of the block. INFO is a plist
1984 holding contextual information."
1985 (format "<div class=\"center\">\n%s</div>" contents))
1987 ;;;; Clock
1989 (defun org-html-clock (clock contents info)
1990 "Transcode a CLOCK element from Org to HTML.
1991 CONTENTS is nil. INFO is a plist used as a communication
1992 channel."
1993 (format "<p>
1994 <span class=\"timestamp-wrapper\">
1995 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1996 </span>
1997 </p>"
1998 org-clock-string
1999 (org-translate-time
2000 (org-element-property :raw-value
2001 (org-element-property :value clock)))
2002 (let ((time (org-element-property :duration clock)))
2003 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2005 ;;;; Code
2007 (defun org-html-code (code contents info)
2008 "Transcode CODE from Org to HTML.
2009 CONTENTS is nil. INFO is a plist holding contextual
2010 information."
2011 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2012 (org-html-plain-text (org-element-property :value code) info)))
2014 ;;;; Drawer
2016 (defun org-html-drawer (drawer contents info)
2017 "Transcode a DRAWER element from Org to HTML.
2018 CONTENTS holds the contents of the block. INFO is a plist
2019 holding contextual information."
2020 (if (functionp org-html-format-drawer-function)
2021 (funcall org-html-format-drawer-function
2022 (org-element-property :drawer-name drawer)
2023 contents)
2024 ;; If there's no user defined function: simply
2025 ;; display contents of the drawer.
2026 contents))
2028 ;;;; Dynamic Block
2030 (defun org-html-dynamic-block (dynamic-block contents info)
2031 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2032 CONTENTS holds the contents of the block. INFO is a plist
2033 holding contextual information. See `org-export-data'."
2034 contents)
2036 ;;;; Entity
2038 (defun org-html-entity (entity contents info)
2039 "Transcode an ENTITY object from Org to HTML.
2040 CONTENTS are the definition itself. INFO is a plist holding
2041 contextual information."
2042 (org-element-property :html entity))
2044 ;;;; Example Block
2046 (defun org-html-example-block (example-block contents info)
2047 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2048 CONTENTS is nil. INFO is a plist holding contextual
2049 information."
2050 (if (org-export-read-attribute :attr_html example-block :textarea)
2051 (org-html--textarea-block example-block)
2052 (format "<pre class=\"example\">\n%s</pre>"
2053 (org-html-format-code example-block info))))
2055 ;;;; Export Snippet
2057 (defun org-html-export-snippet (export-snippet contents info)
2058 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2059 CONTENTS is nil. INFO is a plist holding contextual
2060 information."
2061 (when (eq (org-export-snippet-backend export-snippet) 'html)
2062 (org-element-property :value export-snippet)))
2064 ;;;; Export Block
2066 (defun org-html-export-block (export-block contents info)
2067 "Transcode a EXPORT-BLOCK element from Org to HTML.
2068 CONTENTS is nil. INFO is a plist holding contextual information."
2069 (when (string= (org-element-property :type export-block) "HTML")
2070 (org-remove-indentation (org-element-property :value export-block))))
2072 ;;;; Fixed Width
2074 (defun org-html-fixed-width (fixed-width contents info)
2075 "Transcode a FIXED-WIDTH element from Org to HTML.
2076 CONTENTS is nil. INFO is a plist holding contextual information."
2077 (format "<pre class=\"example\">\n%s</pre>"
2078 (org-html-do-format-code
2079 (org-remove-indentation
2080 (org-element-property :value fixed-width)))))
2082 ;;;; Footnote Reference
2084 (defun org-html-footnote-reference (footnote-reference contents info)
2085 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2086 CONTENTS is nil. INFO is a plist holding contextual information."
2087 (concat
2088 ;; Insert separator between two footnotes in a row.
2089 (let ((prev (org-export-get-previous-element footnote-reference info)))
2090 (when (eq (org-element-type prev) 'footnote-reference)
2091 org-html-footnote-separator))
2092 (cond
2093 ((not (org-export-footnote-first-reference-p footnote-reference info))
2094 (org-html-format-footnote-reference
2095 (org-export-get-footnote-number footnote-reference info)
2096 "IGNORED" 100))
2097 ;; Inline definitions are secondary strings.
2098 ((eq (org-element-property :type footnote-reference) 'inline)
2099 (org-html-format-footnote-reference
2100 (org-export-get-footnote-number footnote-reference info)
2101 "IGNORED" 1))
2102 ;; Non-inline footnotes definitions are full Org data.
2103 (t (org-html-format-footnote-reference
2104 (org-export-get-footnote-number footnote-reference info)
2105 "IGNORED" 1)))))
2107 ;;;; Headline
2109 (defun org-html-format-headline--wrap
2110 (headline info &optional format-function &rest extra-keys)
2111 "Transcode a HEADLINE element from Org to HTML.
2112 CONTENTS holds the contents of the headline. INFO is a plist
2113 holding contextual information."
2114 (let* ((level (+ (org-export-get-relative-level headline info)
2115 (1- org-html-toplevel-hlevel)))
2116 (headline-number (org-export-get-headline-number headline info))
2117 (section-number (and (not (org-export-low-level-p headline info))
2118 (org-export-numbered-headline-p headline info)
2119 (mapconcat 'number-to-string
2120 headline-number ".")))
2121 (todo (and (plist-get info :with-todo-keywords)
2122 (let ((todo (org-element-property :todo-keyword headline)))
2123 (and todo (org-export-data todo info)))))
2124 (todo-type (and todo (org-element-property :todo-type headline)))
2125 (priority (and (plist-get info :with-priority)
2126 (org-element-property :priority headline)))
2127 (text (org-export-data (org-element-property :title headline) info))
2128 (tags (and (plist-get info :with-tags)
2129 (org-export-get-tags headline info)))
2130 (headline-label (or (org-element-property :CUSTOM_ID headline)
2131 (concat "sec-" (mapconcat 'number-to-string
2132 headline-number "-"))))
2133 (format-function (cond
2134 ((functionp format-function) format-function)
2135 ((functionp org-html-format-headline-function)
2136 (function*
2137 (lambda (todo todo-type priority text tags
2138 &allow-other-keys)
2139 (funcall org-html-format-headline-function
2140 todo todo-type priority text tags))))
2141 (t 'org-html-format-headline))))
2142 (apply format-function
2143 todo todo-type priority text tags
2144 :headline-label headline-label :level level
2145 :section-number section-number extra-keys)))
2147 (defun org-html-headline (headline contents info)
2148 "Transcode a HEADLINE element from Org to HTML.
2149 CONTENTS holds the contents of the headline. INFO is a plist
2150 holding contextual information."
2151 ;; Empty contents?
2152 (setq contents (or contents ""))
2153 (let* ((numberedp (org-export-numbered-headline-p headline info))
2154 (level (org-export-get-relative-level headline info))
2155 (text (org-export-data (org-element-property :title headline) info))
2156 (todo (and (plist-get info :with-todo-keywords)
2157 (let ((todo (org-element-property :todo-keyword headline)))
2158 (and todo (org-export-data todo info)))))
2159 (todo-type (and todo (org-element-property :todo-type headline)))
2160 (tags (and (plist-get info :with-tags)
2161 (org-export-get-tags headline info)))
2162 (priority (and (plist-get info :with-priority)
2163 (org-element-property :priority headline)))
2164 (section-number (and (org-export-numbered-headline-p headline info)
2165 (mapconcat 'number-to-string
2166 (org-export-get-headline-number
2167 headline info) ".")))
2168 ;; Create the headline text.
2169 (full-text (org-html-format-headline--wrap headline info)))
2170 (cond
2171 ;; Case 1: This is a footnote section: ignore it.
2172 ((org-element-property :footnote-section-p headline) nil)
2173 ;; Case 2. This is a deep sub-tree: export it as a list item.
2174 ;; Also export as items headlines for which no section
2175 ;; format has been found.
2176 ((org-export-low-level-p headline info)
2177 ;; Build the real contents of the sub-tree.
2178 (let* ((type (if numberedp 'ordered 'unordered))
2179 (itemized-body (org-html-format-list-item
2180 contents type nil nil full-text)))
2181 (concat
2182 (and (org-export-first-sibling-p headline info)
2183 (org-html-begin-plain-list type))
2184 itemized-body
2185 (and (org-export-last-sibling-p headline info)
2186 (org-html-end-plain-list type)))))
2187 ;; Case 3. Standard headline. Export it as a section.
2189 (let* ((section-number (mapconcat 'number-to-string
2190 (org-export-get-headline-number
2191 headline info) "-"))
2192 (ids (remove 'nil
2193 (list (org-element-property :CUSTOM_ID headline)
2194 (concat "sec-" section-number)
2195 (org-element-property :ID headline))))
2196 (preferred-id (car ids))
2197 (extra-ids (cdr ids))
2198 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2199 (level1 (+ level (1- org-html-toplevel-hlevel)))
2200 (first-content (car (org-element-contents headline))))
2201 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2202 (if (= 1 (org-export-get-relative-level headline info))
2203 (plist-get info :html-container)
2204 "div")
2205 (format "outline-container-%s"
2206 (or (org-element-property :CUSTOM_ID headline)
2207 (concat "sec-" section-number)))
2208 (concat (format "outline-%d" level1) (and extra-class " ")
2209 extra-class)
2210 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2211 level1
2212 preferred-id
2213 (mapconcat
2214 (lambda (x)
2215 (let ((id (org-export-solidify-link-text
2216 (if (org-uuidgen-p x) (concat "ID-" x)
2217 x))))
2218 (org-html--anchor id)))
2219 extra-ids "")
2220 full-text
2221 level1)
2222 ;; When there is no section, pretend there is an empty
2223 ;; one to get the correct <div class="outline- ...>
2224 ;; which is needed by `org-info.js'.
2225 (if (not (eq (org-element-type first-content) 'section))
2226 (concat (org-html-section first-content "" info)
2227 contents)
2228 contents)
2229 (if (= 1 (org-export-get-relative-level headline info))
2230 (plist-get info :html-container)
2231 "div")))))))
2233 ;;;; Horizontal Rule
2235 (defun org-html-horizontal-rule (horizontal-rule contents info)
2236 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2237 CONTENTS is nil. INFO is a plist holding contextual information."
2238 "<hr/>")
2240 ;;;; Inline Src Block
2242 (defun org-html-inline-src-block (inline-src-block contents info)
2243 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2244 CONTENTS holds the contents of the item. INFO is a plist holding
2245 contextual information."
2246 (let* ((org-lang (org-element-property :language inline-src-block))
2247 (code (org-element-property :value inline-src-block)))
2248 (error "Cannot export inline src block")))
2250 ;;;; Inlinetask
2252 (defun org-html-format-section (text class &optional id)
2253 "Format a section with TEXT into a HTML div with CLASS and ID."
2254 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2255 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2257 (defun org-html-inlinetask (inlinetask contents info)
2258 "Transcode an INLINETASK element from Org to HTML.
2259 CONTENTS holds the contents of the block. INFO is a plist
2260 holding contextual information."
2261 (cond
2262 ;; If `org-html-format-inlinetask-function' is provided, call it
2263 ;; with appropriate arguments.
2264 ((functionp org-html-format-inlinetask-function)
2265 (let ((format-function
2266 (function*
2267 (lambda (todo todo-type priority text tags
2268 &key contents &allow-other-keys)
2269 (funcall org-html-format-inlinetask-function
2270 todo todo-type priority text tags contents)))))
2271 (org-html-format-headline--wrap
2272 inlinetask info format-function :contents contents)))
2273 ;; Otherwise, use a default template.
2274 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2275 (org-html-format-headline--wrap inlinetask info)
2276 contents))))
2278 ;;;; Italic
2280 (defun org-html-italic (italic contents info)
2281 "Transcode ITALIC from Org to HTML.
2282 CONTENTS is the text with italic markup. INFO is a plist holding
2283 contextual information."
2284 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2286 ;;;; Item
2288 (defun org-html-checkbox (checkbox)
2289 "Format CHECKBOX into HTML."
2290 (case checkbox (on "<code>[X]</code>")
2291 (off "<code>[&#xa0;]</code>")
2292 (trans "<code>[-]</code>")
2293 (t "")))
2295 (defun org-html-format-list-item (contents type checkbox
2296 &optional term-counter-id
2297 headline)
2298 "Format a list item into HTML."
2299 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2300 (concat
2301 (case type
2302 (ordered
2303 (let* ((counter term-counter-id)
2304 (extra (if counter (format " value=\"%s\"" counter) "")))
2305 (concat
2306 (format "<li%s>" extra)
2307 (when headline (concat headline "<br/>")))))
2308 (unordered
2309 (let* ((id term-counter-id)
2310 (extra (if id (format " id=\"%s\"" id) "")))
2311 (concat
2312 (format "<li%s>" extra)
2313 (when headline (concat headline "<br/>")))))
2314 (descriptive
2315 (let* ((term term-counter-id))
2316 (setq term (or term "(no term)"))
2317 ;; Check-boxes in descriptive lists are associated to tag.
2318 (concat (format "<dt> %s </dt>"
2319 (concat checkbox term))
2320 "<dd>"))))
2321 (unless (eq type 'descriptive) checkbox)
2322 contents
2323 (case type
2324 (ordered "</li>")
2325 (unordered "</li>")
2326 (descriptive "</dd>")))))
2328 (defun org-html-item (item contents info)
2329 "Transcode an ITEM element from Org to HTML.
2330 CONTENTS holds the contents of the item. INFO is a plist holding
2331 contextual information."
2332 (let* ((plain-list (org-export-get-parent item))
2333 (type (org-element-property :type plain-list))
2334 (counter (org-element-property :counter item))
2335 (checkbox (org-element-property :checkbox item))
2336 (tag (let ((tag (org-element-property :tag item)))
2337 (and tag (org-export-data tag info)))))
2338 (org-html-format-list-item
2339 contents type checkbox (or tag counter))))
2341 ;;;; Keyword
2343 (defun org-html-keyword (keyword contents info)
2344 "Transcode a KEYWORD element from Org to HTML.
2345 CONTENTS is nil. INFO is a plist holding contextual information."
2346 (let ((key (org-element-property :key keyword))
2347 (value (org-element-property :value keyword)))
2348 (cond
2349 ((string= key "HTML") value)
2350 ((string= key "TOC")
2351 (let ((value (downcase value)))
2352 (cond
2353 ((string-match "\\<headlines\\>" value)
2354 (let ((depth (or (and (string-match "[0-9]+" value)
2355 (string-to-number (match-string 0 value)))
2356 (plist-get info :with-toc))))
2357 (org-html-toc depth info)))
2358 ((string= "listings" value) (org-html-list-of-listings info))
2359 ((string= "tables" value) (org-html-list-of-tables info))))))))
2361 ;;;; Latex Environment
2363 (defun org-html-format-latex (latex-frag processing-type)
2364 "Format the LaTeX fragment LATEX-FRAG into HTML."
2365 (let ((cache-relpath "") (cache-dir "") bfn)
2366 (unless (eq processing-type 'mathjax)
2367 (setq bfn (buffer-file-name)
2368 cache-relpath
2369 (concat "ltxpng/"
2370 (file-name-sans-extension
2371 (file-name-nondirectory bfn)))
2372 cache-dir (file-name-directory bfn)))
2373 (with-temp-buffer
2374 (insert latex-frag)
2375 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2376 nil nil processing-type)
2377 (buffer-string))))
2379 (defun org-html-latex-environment (latex-environment contents info)
2380 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2381 CONTENTS is nil. INFO is a plist holding contextual information."
2382 (let ((processing-type (plist-get info :with-latex))
2383 (latex-frag (org-remove-indentation
2384 (org-element-property :value latex-environment)))
2385 (caption (org-export-data
2386 (org-export-get-caption latex-environment) info))
2387 (attr nil) ; FIXME
2388 (label (org-element-property :name latex-environment)))
2389 (cond
2390 ((memq processing-type '(t mathjax))
2391 (org-html-format-latex latex-frag 'mathjax))
2392 ((eq processing-type 'dvipng)
2393 (let* ((formula-link (org-html-format-latex
2394 latex-frag processing-type)))
2395 (when (and formula-link
2396 (string-match "file:\\([^]]*\\)" formula-link))
2397 (org-html-format-inline-image
2398 (match-string 1 formula-link) caption label attr t))))
2399 (t latex-frag))))
2401 ;;;; Latex Fragment
2403 (defun org-html-latex-fragment (latex-fragment contents info)
2404 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2405 CONTENTS is nil. INFO is a plist holding contextual information."
2406 (let ((latex-frag (org-element-property :value latex-fragment))
2407 (processing-type (plist-get info :with-latex)))
2408 (case processing-type
2409 ((t mathjax)
2410 (org-html-format-latex latex-frag 'mathjax))
2411 (dvipng
2412 (let* ((formula-link (org-html-format-latex
2413 latex-frag processing-type)))
2414 (when (and formula-link
2415 (string-match "file:\\([^]]*\\)" formula-link))
2416 (org-html-format-inline-image
2417 (match-string 1 formula-link)))))
2418 (t latex-frag))))
2420 ;;;; Line Break
2422 (defun org-html-line-break (line-break contents info)
2423 "Transcode a LINE-BREAK object from Org to HTML.
2424 CONTENTS is nil. INFO is a plist holding contextual information."
2425 "<br/>\n")
2427 ;;;; Link
2429 (defun org-html-link--inline-image (link desc info)
2430 "Return HTML code for an inline image.
2431 LINK is the link pointing to the inline image. INFO is a plist
2432 used as a communication channel.
2434 Inline images can have these attributes:
2436 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2437 (let* ((type (org-element-property :type link))
2438 (raw-path (org-element-property :path link))
2439 (path (cond ((member type '("http" "https"))
2440 (concat type ":" raw-path))
2441 ((file-name-absolute-p raw-path)
2442 (expand-file-name raw-path))
2443 (t raw-path)))
2444 (parent (org-export-get-parent-element link))
2445 (caption (org-export-data (org-export-get-caption parent) info))
2446 (label (org-element-property :name parent))
2447 (attrs (org-export-read-attribute :attr_html parent))
2448 (alt (plist-get attrs :alt))
2449 (width (plist-get attrs :width))
2450 (height (plist-get attrs :height))
2451 (options (plist-get attrs :options)))
2452 ;; Return proper string, depending on DISPOSITION.
2453 (org-html-format-inline-image
2454 path caption label
2455 (mapconcat 'identity
2456 (delq nil (list (if width (format "width=\"%s\"" width))
2457 (if alt (format "alt=\"%s\"" alt))
2458 (if height (format "height=\"%s\"" height))
2459 options)) " ")
2460 (org-html-standalone-image-p link info))))
2462 (defvar org-html-standalone-image-predicate)
2463 (defun org-html-standalone-image-p (element info &optional predicate)
2464 "Test if ELEMENT is a standalone image for the purpose HTML export.
2465 INFO is a plist holding contextual information.
2467 Return non-nil, if ELEMENT is of type paragraph and it's sole
2468 content, save for whitespaces, is a link that qualifies as an
2469 inline image.
2471 Return non-nil, if ELEMENT is of type link and it's containing
2472 paragraph has no other content save for leading and trailing
2473 whitespaces.
2475 Return nil, otherwise.
2477 Bind `org-html-standalone-image-predicate' to constrain
2478 paragraph further. For example, to check for only captioned
2479 standalone images, do the following.
2481 \(setq org-html-standalone-image-predicate
2482 \(lambda \(paragraph\)
2483 \(org-element-property :caption paragraph\)\)\)"
2484 (let ((paragraph (case (org-element-type element)
2485 (paragraph element)
2486 (link (and (org-export-inline-image-p
2487 element org-html-inline-image-rules)
2488 (org-export-get-parent element)))
2489 (t nil))))
2490 (when (eq (org-element-type paragraph) 'paragraph)
2491 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2492 (functionp org-html-standalone-image-predicate)))
2493 (funcall org-html-standalone-image-predicate paragraph))
2494 (let ((contents (org-element-contents paragraph)))
2495 (loop for x in contents
2496 with inline-image-count = 0
2497 always (cond
2498 ((eq (org-element-type x) 'plain-text)
2499 (not (org-string-nw-p x)))
2500 ((eq (org-element-type x) 'link)
2501 (when (org-export-inline-image-p
2502 x org-html-inline-image-rules)
2503 (= (incf inline-image-count) 1)))
2504 (t nil))))))))
2506 (defun org-html-link (link desc info)
2507 "Transcode a LINK object from Org to HTML.
2509 DESC is the description part of the link, or the empty string.
2510 INFO is a plist holding contextual information. See
2511 `org-export-data'."
2512 (let* ((link-org-files-as-html-maybe
2513 (function
2514 (lambda (raw-path info)
2515 "Treat links to `file.org' as links to `file.html', if needed.
2516 See `org-html-link-org-files-as-html'."
2517 (cond
2518 ((and org-html-link-org-files-as-html
2519 (string= ".org"
2520 (downcase (file-name-extension raw-path "."))))
2521 (concat (file-name-sans-extension raw-path) "."
2522 (plist-get info :html-extension)))
2523 (t raw-path)))))
2524 (type (org-element-property :type link))
2525 (raw-path (org-element-property :path link))
2526 ;; Ensure DESC really exists, or set it to nil.
2527 (desc (and (not (string= desc "")) desc))
2528 (path
2529 (cond
2530 ((member type '("http" "https" "ftp" "mailto"))
2531 (concat type ":" raw-path))
2532 ((string= type "file")
2533 ;; Treat links to ".org" files as ".html", if needed.
2534 (setq raw-path
2535 (funcall link-org-files-as-html-maybe raw-path info))
2536 ;; If file path is absolute, prepend it with protocol
2537 ;; component - "file://".
2538 (when (file-name-absolute-p raw-path)
2539 (setq raw-path
2540 (concat "file://" (expand-file-name raw-path))))
2541 ;; Add search option, if any. A search option can be
2542 ;; relative to a custom-id or a headline title. Any other
2543 ;; option is ignored.
2544 (let ((option (org-element-property :search-option link)))
2545 (cond ((not option) raw-path)
2546 ((eq (aref option 0) ?#) (concat raw-path option))
2547 ;; External fuzzy link: try to resolve it if path
2548 ;; belongs to current project, if any.
2549 ((eq (aref option 0) ?*)
2550 (concat
2551 raw-path
2552 (let ((numbers
2553 (org-publish-resolve-external-fuzzy-link
2554 (org-element-property :path link) option)))
2555 (and numbers (concat "#sec-"
2556 (mapconcat 'number-to-string
2557 numbers "-"))))))
2558 (t raw-path))))
2559 (t raw-path)))
2560 attributes protocol)
2561 ;; Extract attributes from parent's paragraph. HACK: Only do this
2562 ;; for the first link in parent. This is needed as long as
2563 ;; attributes cannot be set on a per link basis.
2564 (and (setq attributes
2565 (let ((parent (org-export-get-parent-element link)))
2566 (if (not (eq (org-element-map parent 'link 'identity info t)
2567 link))
2569 (let ((att (org-export-read-attribute :attr_html parent :options)))
2570 (unless (and desc att (string-match (regexp-quote att) desc))
2571 (or att ""))))))
2572 (unless (string= attributes "")
2573 (setq attributes (concat " " attributes))))
2574 (cond
2575 ;; Image file.
2576 ((and (or (eq t org-html-inline-images)
2577 (and org-html-inline-images (not desc)))
2578 (org-export-inline-image-p link org-html-inline-image-rules))
2579 (org-html-link--inline-image link desc info))
2580 ;; Radio target: Transcode target's contents and use them as
2581 ;; link's description.
2582 ((string= type "radio")
2583 (let ((destination (org-export-resolve-radio-link link info)))
2584 (when destination
2585 (format "<a href=\"#%s\"%s>%s</a>"
2586 (org-export-solidify-link-text path)
2587 attributes
2588 (org-export-data (org-element-contents destination) info)))))
2589 ;; Links pointing to a headline: Find destination and build
2590 ;; appropriate referencing command.
2591 ((member type '("custom-id" "fuzzy" "id"))
2592 (let ((destination (if (string= type "fuzzy")
2593 (org-export-resolve-fuzzy-link link info)
2594 (org-export-resolve-id-link link info))))
2595 (case (org-element-type destination)
2596 ;; ID link points to an external file.
2597 (plain-text
2598 (let ((fragment (concat "ID-" path))
2599 ;; Treat links to ".org" files as ".html", if needed.
2600 (path (funcall link-org-files-as-html-maybe
2601 destination info)))
2602 (format "<a href=\"%s#%s\"%s>%s</a>"
2603 path fragment attributes (or desc destination))))
2604 ;; Fuzzy link points nowhere.
2605 ((nil)
2606 (format "<i>%s</i>"
2607 (or desc
2608 (org-export-data
2609 (org-element-property :raw-link link) info))))
2610 ;; Fuzzy link points to an invisible target.
2611 (keyword nil)
2612 ;; Link points to a headline.
2613 (headline
2614 (let ((href
2615 ;; What href to use?
2616 (cond
2617 ;; Case 1: Headline is linked via it's CUSTOM_ID
2618 ;; property. Use CUSTOM_ID.
2619 ((string= type "custom-id")
2620 (org-element-property :CUSTOM_ID destination))
2621 ;; Case 2: Headline is linked via it's ID property
2622 ;; or through other means. Use the default href.
2623 ((member type '("id" "fuzzy"))
2624 (format "sec-%s"
2625 (mapconcat 'number-to-string
2626 (org-export-get-headline-number
2627 destination info) "-")))
2628 (t (error "Shouldn't reach here"))))
2629 ;; What description to use?
2630 (desc
2631 ;; Case 1: Headline is numbered and LINK has no
2632 ;; description or LINK's description matches
2633 ;; headline's title. Display section number.
2634 (if (and (org-export-numbered-headline-p destination info)
2635 (or (not desc)
2636 (string= desc (org-element-property
2637 :raw-value destination))))
2638 (mapconcat 'number-to-string
2639 (org-export-get-headline-number
2640 destination info) ".")
2641 ;; Case 2: Either the headline is un-numbered or
2642 ;; LINK has a custom description. Display LINK's
2643 ;; description or headline's title.
2644 (or desc (org-export-data (org-element-property
2645 :title destination) info)))))
2646 (format "<a href=\"#%s\"%s>%s</a>"
2647 (org-export-solidify-link-text href) attributes desc)))
2648 ;; Fuzzy link points to a target. Do as above.
2650 (let ((path (org-export-solidify-link-text path)) number)
2651 (unless desc
2652 (setq number (cond
2653 ((org-html-standalone-image-p destination info)
2654 (org-export-get-ordinal
2655 (assoc 'link (org-element-contents destination))
2656 info 'link 'org-html-standalone-image-p))
2657 (t (org-export-get-ordinal destination info))))
2658 (setq desc (when number
2659 (if (atom number) (number-to-string number)
2660 (mapconcat 'number-to-string number ".")))))
2661 (format "<a href=\"#%s\"%s>%s</a>"
2662 path attributes (or desc "No description for this link")))))))
2663 ;; Coderef: replace link with the reference name or the
2664 ;; equivalent line number.
2665 ((string= type "coderef")
2666 (let ((fragment (concat "coderef-" path)))
2667 (format "<a href=\"#%s\"%s%s>%s</a>"
2668 fragment
2669 (org-trim
2670 (format (concat "class=\"coderef\""
2671 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2672 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2673 fragment fragment))
2674 attributes
2675 (format (org-export-get-coderef-format path desc)
2676 (org-export-resolve-coderef path info)))))
2677 ;; Link type is handled by a special function.
2678 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2679 (funcall protocol (org-link-unescape path) desc 'html))
2680 ;; External link with a description part.
2681 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2682 ;; External link without a description part.
2683 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2684 ;; No path, only description. Try to do something useful.
2685 (t (format "<i>%s</i>" desc)))))
2687 ;;;; Paragraph
2689 (defun org-html-paragraph (paragraph contents info)
2690 "Transcode a PARAGRAPH element from Org to HTML.
2691 CONTENTS is the contents of the paragraph, as a string. INFO is
2692 the plist used as a communication channel."
2693 (let* ((parent (org-export-get-parent paragraph))
2694 (parent-type (org-element-type parent))
2695 (style '((footnote-definition " class=\"footpara\"")))
2696 (extra (or (cadr (assoc parent-type style)) "")))
2697 (cond
2698 ((and (eq (org-element-type parent) 'item)
2699 (= (org-element-property :begin paragraph)
2700 (org-element-property :contents-begin parent)))
2701 ;; leading paragraph in a list item have no tags
2702 contents)
2703 ((org-html-standalone-image-p paragraph info)
2704 ;; standalone image
2705 contents)
2706 (t (format "<p%s>\n%s</p>" extra contents)))))
2708 ;;;; Plain List
2710 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2711 ;; the correct value for the item counter
2712 (defun org-html-begin-plain-list (type &optional arg1)
2713 "Insert the beginning of the HTML list depending on TYPE.
2714 When ARG1 is a string, use it as the start parameter for ordered
2715 lists."
2716 (case type
2717 (ordered
2718 (format "<ol class=\"org-ol\"%s>"
2719 (if arg1 (format " start=\"%d\"" arg1) "")))
2720 (unordered "<ul class=\"org-ul\">")
2721 (descriptive "<dl class=\"org-dl\">")))
2723 (defun org-html-end-plain-list (type)
2724 "Insert the end of the HTML list depending on TYPE."
2725 (case type
2726 (ordered "</ol>")
2727 (unordered "</ul>")
2728 (descriptive "</dl>")))
2730 (defun org-html-plain-list (plain-list contents info)
2731 "Transcode a PLAIN-LIST element from Org to HTML.
2732 CONTENTS is the contents of the list. INFO is a plist holding
2733 contextual information."
2734 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2735 (type (org-element-property :type plain-list)))
2736 (format "%s\n%s%s"
2737 (org-html-begin-plain-list type)
2738 contents (org-html-end-plain-list type))))
2740 ;;;; Plain Text
2742 (defun org-html-convert-special-strings (string)
2743 "Convert special characters in STRING to HTML."
2744 (let ((all org-html-special-string-regexps)
2745 e a re rpl start)
2746 (while (setq a (pop all))
2747 (setq re (car a) rpl (cdr a) start 0)
2748 (while (string-match re string start)
2749 (setq string (replace-match rpl t nil string))))
2750 string))
2752 (defun org-html-encode-plain-text (text)
2753 "Convert plain text characters from TEXT to HTML equivalent.
2754 Possible conversions are set in `org-html-protect-char-alist'."
2755 (mapc
2756 (lambda (pair)
2757 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2758 org-html-protect-char-alist)
2759 text)
2761 (defun org-html-plain-text (text info)
2762 "Transcode a TEXT string from Org to HTML.
2763 TEXT is the string to transcode. INFO is a plist holding
2764 contextual information."
2765 (let ((output text))
2766 ;; Protect following characters: <, >, &.
2767 (setq output (org-html-encode-plain-text output))
2768 ;; Handle smart quotes. Be sure to provide original string since
2769 ;; OUTPUT may have been modified.
2770 (when (plist-get info :with-smart-quotes)
2771 (setq output (org-export-activate-smart-quotes output :html info text)))
2772 ;; Handle special strings.
2773 (when (plist-get info :with-special-strings)
2774 (setq output (org-html-convert-special-strings output)))
2775 ;; Handle break preservation if required.
2776 (when (plist-get info :preserve-breaks)
2777 (setq output
2778 (replace-regexp-in-string
2779 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2780 ;; Return value.
2781 output))
2784 ;; Planning
2786 (defun org-html-planning (planning contents info)
2787 "Transcode a PLANNING element from Org to HTML.
2788 CONTENTS is nil. INFO is a plist used as a communication
2789 channel."
2790 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2791 (format
2792 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2793 (mapconcat
2794 'identity
2795 (delq nil
2796 (list
2797 (let ((closed (org-element-property :closed planning)))
2798 (when closed
2799 (format span-fmt org-closed-string
2800 (org-translate-time
2801 (org-element-property :raw-value closed)))))
2802 (let ((deadline (org-element-property :deadline planning)))
2803 (when deadline
2804 (format span-fmt org-deadline-string
2805 (org-translate-time
2806 (org-element-property :raw-value deadline)))))
2807 (let ((scheduled (org-element-property :scheduled planning)))
2808 (when scheduled
2809 (format span-fmt org-scheduled-string
2810 (org-translate-time
2811 (org-element-property :raw-value scheduled)))))))
2812 " "))))
2814 ;;;; Property Drawer
2816 (defun org-html-property-drawer (property-drawer contents info)
2817 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2818 CONTENTS is nil. INFO is a plist holding contextual
2819 information."
2820 ;; The property drawer isn't exported but we want separating blank
2821 ;; lines nonetheless.
2824 ;;;; Quote Block
2826 (defun org-html-quote-block (quote-block contents info)
2827 "Transcode a QUOTE-BLOCK element from Org to HTML.
2828 CONTENTS holds the contents of the block. INFO is a plist
2829 holding contextual information."
2830 (format "<blockquote>\n%s</blockquote>" contents))
2832 ;;;; Quote Section
2834 (defun org-html-quote-section (quote-section contents info)
2835 "Transcode a QUOTE-SECTION element from Org to HTML.
2836 CONTENTS is nil. INFO is a plist holding contextual information."
2837 (let ((value (org-remove-indentation
2838 (org-element-property :value quote-section))))
2839 (when value (format "<pre>\n%s</pre>" value))))
2841 ;;;; Section
2843 (defun org-html-section (section contents info)
2844 "Transcode a SECTION element from Org to HTML.
2845 CONTENTS holds the contents of the section. INFO is a plist
2846 holding contextual information."
2847 (let ((parent (org-export-get-parent-headline section)))
2848 ;; Before first headline: no container, just return CONTENTS.
2849 (if (not parent) contents
2850 ;; Get div's class and id references.
2851 (let* ((class-num (+ (org-export-get-relative-level parent info)
2852 (1- org-html-toplevel-hlevel)))
2853 (section-number
2854 (mapconcat
2855 'number-to-string
2856 (org-export-get-headline-number parent info) "-")))
2857 ;; Build return value.
2858 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2859 class-num
2860 (or (org-element-property :CUSTOM_ID parent) section-number)
2861 contents)))))
2863 ;;;; Radio Target
2865 (defun org-html-radio-target (radio-target text info)
2866 "Transcode a RADIO-TARGET object from Org to HTML.
2867 TEXT is the text of the target. INFO is a plist holding
2868 contextual information."
2869 (let ((id (org-export-solidify-link-text
2870 (org-element-property :value radio-target))))
2871 (org-html--anchor id text)))
2873 ;;;; Special Block
2875 (defun org-html-special-block (special-block contents info)
2876 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2877 CONTENTS holds the contents of the block. INFO is a plist
2878 holding contextual information."
2879 (format "<div class=\"%s\">\n%s\n</div>"
2880 (downcase (org-element-property :type special-block))
2881 contents))
2883 ;;;; Src Block
2885 (defun org-html-src-block (src-block contents info)
2886 "Transcode a SRC-BLOCK element from Org to HTML.
2887 CONTENTS holds the contents of the item. INFO is a plist holding
2888 contextual information."
2889 (if (org-export-read-attribute :attr_html src-block :textarea)
2890 (org-html--textarea-block src-block)
2891 (let ((lang (org-element-property :language src-block))
2892 (caption (org-export-get-caption src-block))
2893 (code (org-html-format-code src-block info))
2894 (label (let ((lbl (org-element-property :name src-block)))
2895 (if (not lbl) ""
2896 (format " id=\"%s\""
2897 (org-export-solidify-link-text lbl))))))
2898 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2899 (format
2900 "<div class=\"org-src-container\">\n%s%s\n</div>"
2901 (if (not caption) ""
2902 (format "<label class=\"org-src-name\">%s</label>"
2903 (org-export-data caption info)))
2904 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2906 ;;;; Statistics Cookie
2908 (defun org-html-statistics-cookie (statistics-cookie contents info)
2909 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2910 CONTENTS is nil. INFO is a plist holding contextual information."
2911 (let ((cookie-value (org-element-property :value statistics-cookie)))
2912 (format "<code>%s</code>" cookie-value)))
2914 ;;;; Strike-Through
2916 (defun org-html-strike-through (strike-through contents info)
2917 "Transcode STRIKE-THROUGH from Org to HTML.
2918 CONTENTS is the text with strike-through markup. INFO is a plist
2919 holding contextual information."
2920 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2921 contents))
2923 ;;;; Subscript
2925 (defun org-html-subscript (subscript contents info)
2926 "Transcode a SUBSCRIPT object from Org to HTML.
2927 CONTENTS is the contents of the object. INFO is a plist holding
2928 contextual information."
2929 (format "<sub>%s</sub>" contents))
2931 ;;;; Superscript
2933 (defun org-html-superscript (superscript contents info)
2934 "Transcode a SUPERSCRIPT object from Org to HTML.
2935 CONTENTS is the contents of the object. INFO is a plist holding
2936 contextual information."
2937 (format "<sup>%s</sup>" contents))
2939 ;;;; Tabel Cell
2941 (defun org-html-table-cell (table-cell contents info)
2942 "Transcode a TABLE-CELL element from Org to HTML.
2943 CONTENTS is nil. INFO is a plist used as a communication
2944 channel."
2945 (let* ((table-row (org-export-get-parent table-cell))
2946 (table (org-export-get-parent-table table-cell))
2947 (cell-attrs
2948 (if (not org-html-table-align-individual-fields) ""
2949 (format (if (and (boundp 'org-html-format-table-no-css)
2950 org-html-format-table-no-css)
2951 " align=\"%s\"" " class=\"%s\"")
2952 (org-export-table-cell-alignment table-cell info)))))
2953 (when (or (not contents) (string= "" (org-trim contents)))
2954 (setq contents "&#xa0;"))
2955 (cond
2956 ((and (org-export-table-has-header-p table info)
2957 (= 1 (org-export-table-row-group table-row info)))
2958 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2959 contents (cdr org-html-table-header-tags)))
2960 ((and org-html-table-use-header-tags-for-first-column
2961 (zerop (cdr (org-export-table-cell-address table-cell info))))
2962 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2963 contents (cdr org-html-table-header-tags)))
2964 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2965 contents (cdr org-html-table-data-tags))))))
2967 ;;;; Table Row
2969 (defun org-html-table-row (table-row contents info)
2970 "Transcode a TABLE-ROW element from Org to HTML.
2971 CONTENTS is the contents of the row. INFO is a plist used as a
2972 communication channel."
2973 ;; Rules are ignored since table separators are deduced from
2974 ;; borders of the current row.
2975 (when (eq (org-element-property :type table-row) 'standard)
2976 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2977 (row-number (org-export-table-row-number table-row info))
2978 (start-rowgroup-p
2979 (org-export-table-row-starts-rowgroup-p table-row info))
2980 (end-rowgroup-p
2981 (org-export-table-row-ends-rowgroup-p table-row info))
2982 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2983 ;; but should be set so that `org-html-table-row-tags' can
2984 ;; use them (see the docstring of this variable.)
2985 (top-row-p (and (equal start-rowgroup-p '(top))
2986 (equal end-rowgroup-p '(below top))))
2987 (bottom-row-p (and (equal start-rowgroup-p '(above))
2988 (equal end-rowgroup-p '(bottom above))))
2989 (rowgroup-tags
2990 (cond
2991 ;; Case 1: Row belongs to second or subsequent rowgroups.
2992 ((not (= 1 rowgroup-number))
2993 '("<tbody>" . "\n</tbody>"))
2994 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2995 ((org-export-table-has-header-p
2996 (org-export-get-parent-table table-row) info)
2997 '("<thead>" . "\n</thead>"))
2998 ;; Case 2: Row is from first and only row group.
2999 (t '("<tbody>" . "\n</tbody>")))))
3000 (concat
3001 ;; Begin a rowgroup?
3002 (when start-rowgroup-p (car rowgroup-tags))
3003 ;; Actual table row
3004 (concat "\n" (eval (car org-html-table-row-tags))
3005 contents
3006 "\n"
3007 (eval (cdr org-html-table-row-tags)))
3008 ;; End a rowgroup?
3009 (when end-rowgroup-p (cdr rowgroup-tags))))))
3011 ;;;; Table
3013 (defun org-html-table-first-row-data-cells (table info)
3014 "Transcode the first row of TABLE.
3015 INFO is a plist used as a communication channel."
3016 (let ((table-row
3017 (org-element-map table 'table-row
3018 (lambda (row)
3019 (unless (eq (org-element-property :type row) 'rule) row))
3020 info 'first-match))
3021 (special-column-p (org-export-table-has-special-column-p table)))
3022 (if (not special-column-p) (org-element-contents table-row)
3023 (cdr (org-element-contents table-row)))))
3025 (defun org-html-table--table.el-table (table info)
3026 "Format table.el tables into HTML.
3027 INFO is a plist used as a communication channel."
3028 (when (eq (org-element-property :type table) 'table.el)
3029 (require 'table)
3030 (let ((outbuf (with-current-buffer
3031 (get-buffer-create "*org-export-table*")
3032 (erase-buffer) (current-buffer))))
3033 (with-temp-buffer
3034 (insert (org-element-property :value table))
3035 (goto-char 1)
3036 (re-search-forward "^[ \t]*|[^|]" nil t)
3037 (table-generate-source 'html outbuf))
3038 (with-current-buffer outbuf
3039 (prog1 (org-trim (buffer-string))
3040 (kill-buffer) )))))
3042 (defun org-html-table (table contents info)
3043 "Transcode a TABLE element from Org to HTML.
3044 CONTENTS is the contents of the table. INFO is a plist holding
3045 contextual information."
3046 (case (org-element-property :type table)
3047 ;; Case 1: table.el table. Convert it using appropriate tools.
3048 (table.el (org-html-table--table.el-table table info))
3049 ;; Case 2: Standard table.
3051 (let* ((label (org-element-property :name table))
3052 (caption (org-export-get-caption table))
3053 (attributes
3054 (org-export-read-attribute :attr_html table :options))
3055 (alignspec
3056 (if (and (boundp 'org-html-format-table-no-css)
3057 org-html-format-table-no-css)
3058 "align=\"%s\"" "class=\"%s\""))
3059 (table-column-specs
3060 (function
3061 (lambda (table info)
3062 (mapconcat
3063 (lambda (table-cell)
3064 (let ((alignment (org-export-table-cell-alignment
3065 table-cell info)))
3066 (concat
3067 ;; Begin a colgroup?
3068 (when (org-export-table-cell-starts-colgroup-p
3069 table-cell info)
3070 "\n<colgroup>")
3071 ;; Add a column. Also specify it's alignment.
3072 (format "\n<col %s/>" (format alignspec alignment))
3073 ;; End a colgroup?
3074 (when (org-export-table-cell-ends-colgroup-p
3075 table-cell info)
3076 "\n</colgroup>"))))
3077 (org-html-table-first-row-data-cells table info) "\n"))))
3078 (table-attributes
3079 (let ((table-tag (plist-get info :html-table-tag)))
3080 (concat
3081 (and (string-match "<table\\(.*\\)>" table-tag)
3082 (match-string 1 table-tag))
3083 (and label (format " id=\"%s\""
3084 (org-export-solidify-link-text label)))
3085 (unless (string= attributes "")
3086 (concat " " attributes))))))
3087 ;; Remove last blank line.
3088 (setq contents (substring contents 0 -1))
3089 (format "<table%s>\n%s\n%s\n%s\n</table>"
3090 table-attributes
3091 (if (not caption) ""
3092 (format "<caption>%s</caption>"
3093 (org-export-data caption info)))
3094 (funcall table-column-specs table info)
3095 contents)))))
3097 ;;;; Target
3099 (defun org-html-target (target contents info)
3100 "Transcode a TARGET object from Org to HTML.
3101 CONTENTS is nil. INFO is a plist holding contextual
3102 information."
3103 (let ((id (org-export-solidify-link-text
3104 (org-element-property :value target))))
3105 (org-html--anchor id)))
3107 ;;;; Timestamp
3109 (defun org-html-timestamp (timestamp contents info)
3110 "Transcode a TIMESTAMP object from Org to HTML.
3111 CONTENTS is nil. INFO is a plist holding contextual
3112 information."
3113 (let ((value (org-html-plain-text
3114 (org-timestamp-translate timestamp) info)))
3115 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3116 (replace-regexp-in-string "--" "&#x2013;" value))))
3118 ;;;; Underline
3120 (defun org-html-underline (underline contents info)
3121 "Transcode UNDERLINE from Org to HTML.
3122 CONTENTS is the text with underline markup. INFO is a plist
3123 holding contextual information."
3124 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3125 contents))
3127 ;;;; Verbatim
3129 (defun org-html-verbatim (verbatim contents info)
3130 "Transcode VERBATIM from Org to HTML.
3131 CONTENTS is nil. INFO is a plist holding contextual
3132 information."
3133 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3134 (org-html-plain-text (org-element-property :value verbatim) info)))
3136 ;;;; Verse Block
3138 (defun org-html-verse-block (verse-block contents info)
3139 "Transcode a VERSE-BLOCK element from Org to HTML.
3140 CONTENTS is verse block contents. INFO is a plist holding
3141 contextual information."
3142 ;; Replace each newline character with line break. Also replace
3143 ;; each blank line with a line break.
3144 (setq contents (replace-regexp-in-string
3145 "^ *\\\\\\\\$" "<br/>\n"
3146 (replace-regexp-in-string
3147 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3148 ;; Replace each white space at beginning of a line with a
3149 ;; non-breaking space.
3150 (while (string-match "^[ \t]+" contents)
3151 (let* ((num-ws (length (match-string 0 contents)))
3152 (ws (let (out) (dotimes (i num-ws out)
3153 (setq out (concat out "&#xa0;"))))))
3154 (setq contents (replace-match ws nil t contents))))
3155 (format "<p class=\"verse\">\n%s</p>" contents))
3158 ;;; Filter Functions
3160 (defun org-html-final-function (contents backend info)
3161 "Filter to indent the HTML and convert HTML entities."
3162 (with-temp-buffer
3163 (insert contents)
3164 (set-auto-mode t)
3165 (if org-html-indent
3166 (indent-region (point-min) (point-max)))
3167 (when org-html-use-unicode-chars
3168 (require 'mm-url)
3169 (mm-url-decode-entities))
3170 (buffer-substring-no-properties (point-min) (point-max))))
3173 ;;; End-user functions
3175 ;;;###autoload
3176 (defun org-html-export-as-html
3177 (&optional async subtreep visible-only body-only ext-plist)
3178 "Export current buffer to an HTML buffer.
3180 If narrowing is active in the current buffer, only export its
3181 narrowed part.
3183 If a region is active, export that region.
3185 A non-nil optional argument ASYNC means the process should happen
3186 asynchronously. The resulting buffer should be accessible
3187 through the `org-export-stack' interface.
3189 When optional argument SUBTREEP is non-nil, export the sub-tree
3190 at point, extracting information from the headline properties
3191 first.
3193 When optional argument VISIBLE-ONLY is non-nil, don't export
3194 contents of hidden elements.
3196 When optional argument BODY-ONLY is non-nil, only write code
3197 between \"<body>\" and \"</body>\" tags.
3199 EXT-PLIST, when provided, is a property list with external
3200 parameters overriding Org default settings, but still inferior to
3201 file-local settings.
3203 Export is done in a buffer named \"*Org HTML Export*\", which
3204 will be displayed when `org-export-show-temporary-export-buffer'
3205 is non-nil."
3206 (interactive)
3207 (if async
3208 (org-export-async-start
3209 (lambda (output)
3210 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3211 (erase-buffer)
3212 (insert output)
3213 (goto-char (point-min))
3214 (set-auto-mode t)
3215 (org-export-add-to-stack (current-buffer) 'html)))
3216 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3217 (let ((outbuf (org-export-to-buffer
3218 'html "*Org HTML Export*"
3219 subtreep visible-only body-only ext-plist)))
3220 ;; Set major mode.
3221 (with-current-buffer outbuf (set-auto-mode t))
3222 (when org-export-show-temporary-export-buffer
3223 (switch-to-buffer-other-window outbuf)))))
3225 ;;;###autoload
3226 (defun org-html-convert-region-to-html ()
3227 "Assume the current region has org-mode syntax, and convert it to HTML.
3228 This can be used in any buffer. For example, you can write an
3229 itemized list in org-mode syntax in an HTML buffer and use this
3230 command to convert it."
3231 (interactive)
3232 (org-export-replace-region-by 'html))
3234 ;;;###autoload
3235 (defun org-html-export-to-html
3236 (&optional async subtreep visible-only body-only ext-plist)
3237 "Export current buffer to a HTML file.
3239 If narrowing is active in the current buffer, only export its
3240 narrowed part.
3242 If a region is active, export that region.
3244 A non-nil optional argument ASYNC means the process should happen
3245 asynchronously. The resulting file should be accessible through
3246 the `org-export-stack' interface.
3248 When optional argument SUBTREEP is non-nil, export the sub-tree
3249 at point, extracting information from the headline properties
3250 first.
3252 When optional argument VISIBLE-ONLY is non-nil, don't export
3253 contents of hidden elements.
3255 When optional argument BODY-ONLY is non-nil, only write code
3256 between \"<body>\" and \"</body>\" tags.
3258 EXT-PLIST, when provided, is a property list with external
3259 parameters overriding Org default settings, but still inferior to
3260 file-local settings.
3262 Return output file's name."
3263 (interactive)
3264 (let* ((extension (concat "." org-html-extension))
3265 (file (org-export-output-file-name extension subtreep))
3266 (org-export-coding-system org-html-coding-system))
3267 (if async
3268 (org-export-async-start
3269 (lambda (f) (org-export-add-to-stack f 'html))
3270 (let ((org-export-coding-system org-html-coding-system))
3271 `(expand-file-name
3272 (org-export-to-file
3273 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3274 (let ((org-export-coding-system org-html-coding-system))
3275 (org-export-to-file
3276 'html file subtreep visible-only body-only ext-plist)))))
3278 ;;;###autoload
3279 (defun org-html-publish-to-html (plist filename pub-dir)
3280 "Publish an org file to HTML.
3282 FILENAME is the filename of the Org file to be published. PLIST
3283 is the property list for the given project. PUB-DIR is the
3284 publishing directory.
3286 Return output file name."
3287 (org-publish-org-to 'html filename
3288 (concat "." (or (plist-get plist :html-extension)
3289 org-html-extension "html"))
3290 plist pub-dir))
3293 ;;; FIXME
3295 ;;;; org-format-table-html
3296 ;;;; org-format-org-table-html
3297 ;;;; org-format-table-table-html
3298 ;;;; org-table-number-fraction
3299 ;;;; org-table-number-regexp
3300 ;;;; org-html-table-caption-above
3301 ;;;; org-html-inline-image-extensions
3302 ;;;; org-export-preferred-target-alist
3303 ;;;; class for anchors
3304 ;;;; org-export-mark-todo-in-toc
3305 ;;;; org-html-format-org-link
3306 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3307 ;;;; alt = (file-name-nondirectory path)
3309 (provide 'ox-html)
3311 ;; Local variables:
3312 ;; generated-autoload-file: "org-loaddefs.el"
3313 ;; End:
3315 ;;; ox-html.el ends here