ox-html: Fix invalid syntax in html attributes
[org-mode.git] / lisp / ox-html.el
blob84609b975190ec6b6a011e0a98a0d7382aef6d94
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-link-org-as-html nil nil org-html-link-org-files-as-html)
116 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
117 (:html-container "HTML_CONTAINER" nil org-html-container-element)
118 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
119 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
120 (:html-mathjax "HTML_MATHJAX" nil "" space)
121 (:html-postamble nil "html-postamble" org-html-postamble)
122 (:html-preamble nil "html-preamble" org-html-preamble)
123 (:html-head "HTML_HEAD" nil org-html-head newline)
124 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
125 (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
126 (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
127 (:html-table-attributes nil nil org-html-table-default-attributes)
128 (:html-table-row-tags nil nil org-html-table-row-tags)
129 (:html-xml-declaration nil nil org-html-xml-declaration)
130 (:html-inline-images nil nil org-html-inline-images)
131 (:infojs-opt "INFOJS_OPT" nil nil)
132 ;; Redefine regular options.
133 (:creator "CREATOR" nil org-html-creator-string)
134 (:with-latex nil "tex" org-html-with-latex)))
137 ;;; Internal Variables
139 (defvar org-html-format-table-no-css)
140 (defvar htmlize-buffer-places) ; from htmlize.el
142 (defvar org-html--pre/postamble-class "status"
143 "CSS class used for pre/postamble")
145 (defconst org-html-special-string-regexps
146 '(("\\\\-" . "&#x00ad;") ; shy
147 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
148 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
149 ("\\.\\.\\." . "&#x2026;")) ; hellip
150 "Regular expressions for special string conversion.")
152 (defconst org-html-scripts
153 "<script type=\"text/javascript\">
155 @licstart The following is the entire license notice for the
156 JavaScript code in this tag.
158 Copyright (C) 2012 Free Software Foundation, Inc.
160 The JavaScript code in this tag is free software: you can
161 redistribute it and/or modify it under the terms of the GNU
162 General Public License (GNU GPL) as published by the Free Software
163 Foundation, either version 3 of the License, or (at your option)
164 any later version. The code is distributed WITHOUT ANY WARRANTY;
165 without even the implied warranty of MERCHANTABILITY or FITNESS
166 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
168 As additional permission under GNU GPL version 3 section 7, you
169 may distribute non-source (e.g., minimized or compacted) forms of
170 that code without the copy of the GNU GPL normally required by
171 section 4, provided you include this license notice and a URL
172 through which recipients can access the Corresponding Source.
175 @licend The above is the entire license notice
176 for the JavaScript code in this tag.
178 <!--/*--><![CDATA[/*><!--*/
179 function CodeHighlightOn(elem, id)
181 var target = document.getElementById(id);
182 if(null != target) {
183 elem.cacheClassElem = elem.className;
184 elem.cacheClassTarget = target.className;
185 target.className = \"code-highlighted\";
186 elem.className = \"code-highlighted\";
189 function CodeHighlightOff(elem, id)
191 var target = document.getElementById(id);
192 if(elem.cacheClassElem)
193 elem.className = elem.cacheClassElem;
194 if(elem.cacheClassTarget)
195 target.className = elem.cacheClassTarget;
197 /*]]>*///-->
198 </script>"
199 "Basic JavaScript that is needed by HTML files produced by Org mode.")
201 (defconst org-html-style-default
202 "<style type=\"text/css\">
203 <!--/*--><![CDATA[/*><!--*/
204 .title { text-align: center; }
205 .todo { font-family: monospace; color: red; }
206 .done { color: green; }
207 .tag { background-color: #eee; font-family: monospace;
208 padding: 2px; font-size: 80%; font-weight: normal; }
209 .timestamp { color: #bebebe; }
210 .timestamp-kwd { color: #5f9ea0; }
211 .right { margin-left: auto; margin-right: 0px; text-align: right; }
212 .left { margin-left: 0px; margin-right: auto; text-align: left; }
213 .center { margin-left: auto; margin-right: auto; text-align: center; }
214 .underline { text-decoration: underline; }
215 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
216 p.verse { margin-left: 3%; }
217 pre {
218 border: 1px solid #ccc;
219 box-shadow: 3px 3px 3px #eee;
220 padding: 8pt;
221 font-family: monospace;
222 overflow: auto;
223 margin: 1.2em;
225 pre.src {
226 position: relative;
227 overflow: visible;
228 padding-top: 1.2em;
230 pre.src:before {
231 display: none;
232 position: absolute;
233 background-color: white;
234 top: -10px;
235 right: 10px;
236 padding: 3px;
237 border: 1px solid black;
239 pre.src:hover:before { display: inline;}
240 pre.src-sh:before { content: 'sh'; }
241 pre.src-bash:before { content: 'sh'; }
242 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
243 pre.src-R:before { content: 'R'; }
244 pre.src-perl:before { content: 'Perl'; }
245 pre.src-java:before { content: 'Java'; }
246 pre.src-sql:before { content: 'SQL'; }
248 table { border-collapse:collapse; }
249 td, th { vertical-align:top; }
250 th.right { text-align: center; }
251 th.left { text-align: center; }
252 th.center { text-align: center; }
253 td.right { text-align: right; }
254 td.left { text-align: left; }
255 td.center { text-align: center; }
256 dt { font-weight: bold; }
257 .footpara:nth-child(2) { display: inline; }
258 .footpara { display: block; }
259 .footdef { margin-bottom: 1em; }
260 .figure { padding: 1em; }
261 .figure p { text-align: center; }
262 .inlinetask {
263 padding: 10px;
264 border: 2px solid gray;
265 margin: 10px;
266 background: #ffffcc;
268 #org-div-home-and-up
269 { text-align: right; font-size: 70%; white-space: nowrap; }
270 textarea { overflow-x: auto; }
271 .linenr { font-size: smaller }
272 .code-highlighted { background-color: #ffff00; }
273 .org-info-js_info-navigation { border-style: none; }
274 #org-info-js_console-label
275 { font-size: 10px; font-weight: bold; white-space: nowrap; }
276 .org-info-js_search-highlight
277 { background-color: #ffff00; color: #000000; font-weight: bold; }
278 /*]]>*/-->
279 </style>"
280 "The default style specification for exported HTML files.
281 You can use `org-html-head' and `org-html-head-extra' to add to
282 this style. If you don't want to include this default style,
283 customize `org-html-head-include-default-style'.")
286 ;;; User Configuration Variables
288 (defgroup org-export-html nil
289 "Options for exporting Org mode files to HTML."
290 :tag "Org Export HTML"
291 :group 'org-export)
293 ;;;; Handle infojs
295 (defvar org-html-infojs-opts-table
296 '((path PATH "http://orgmode.org/org-info.js")
297 (view VIEW "info")
298 (toc TOC :with-toc)
299 (ftoc FIXED_TOC "0")
300 (tdepth TOC_DEPTH "max")
301 (sdepth SECTION_DEPTH "max")
302 (mouse MOUSE_HINT "underline")
303 (buttons VIEW_BUTTONS "0")
304 (ltoc LOCAL_TOC "1")
305 (up LINK_UP :html-link-up)
306 (home LINK_HOME :html-link-home))
307 "JavaScript options, long form for script, default values.")
309 (defcustom org-html-use-infojs 'when-configured
310 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
311 This option can be nil or t to never or always use the script.
312 It can also be the symbol `when-configured', meaning that the
313 script will be linked into the export file if and only if there
314 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
315 `org-html-infojs-options'."
316 :group 'org-export-html
317 :version "24.4"
318 :package-version '(Org . "8.0")
319 :type '(choice
320 (const :tag "Never" nil)
321 (const :tag "When configured in buffer" when-configured)
322 (const :tag "Always" t)))
324 (defcustom org-html-infojs-options
325 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
326 "Options settings for the INFOJS JavaScript.
327 Each of the options must have an entry in `org-html-infojs-opts-table'.
328 The value can either be a string that will be passed to the script, or
329 a property. This property is then assumed to be a property that is defined
330 by the Export/Publishing setup of Org.
331 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
332 means to use the maximum value consistent with other options."
333 :group 'org-export-html
334 :version "24.4"
335 :package-version '(Org . "8.0")
336 :type
337 `(set :greedy t :inline t
338 ,@(mapcar
339 (lambda (x)
340 (list 'cons (list 'const (car x))
341 '(choice
342 (symbol :tag "Publishing/Export property")
343 (string :tag "Value"))))
344 org-html-infojs-opts-table)))
346 (defcustom org-html-infojs-template
347 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
350 * @source: %SCRIPT_PATH
352 * @licstart The following is the entire license notice for the
353 * JavaScript code in %SCRIPT_PATH.
355 * Copyright (C) 2012-2013 Sebastian Rose
358 * The JavaScript code in this tag is free software: you can
359 * redistribute it and/or modify it under the terms of the GNU
360 * General Public License (GNU GPL) as published by the Free Software
361 * Foundation, either version 3 of the License, or (at your option)
362 * any later version. The code is distributed WITHOUT ANY WARRANTY;
363 * without even the implied warranty of MERCHANTABILITY or FITNESS
364 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
366 * As additional permission under GNU GPL version 3 section 7, you
367 * may distribute non-source (e.g., minimized or compacted) forms of
368 * that code without the copy of the GNU GPL normally required by
369 * section 4, provided you include this license notice and a URL
370 * through which recipients can access the Corresponding Source.
372 * @licend The above is the entire license notice
373 * for the JavaScript code in %SCRIPT_PATH.
376 </script>
378 <script type=\"text/javascript\">
381 @licstart The following is the entire license notice for the
382 JavaScript code in this tag.
384 Copyright (C) 2012-2013 Free Software Foundation, Inc.
386 The JavaScript code in this tag is free software: you can
387 redistribute it and/or modify it under the terms of the GNU
388 General Public License (GNU GPL) as published by the Free Software
389 Foundation, either version 3 of the License, or (at your option)
390 any later version. The code is distributed WITHOUT ANY WARRANTY;
391 without even the implied warranty of MERCHANTABILITY or FITNESS
392 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
394 As additional permission under GNU GPL version 3 section 7, you
395 may distribute non-source (e.g., minimized or compacted) forms of
396 that code without the copy of the GNU GPL normally required by
397 section 4, provided you include this license notice and a URL
398 through which recipients can access the Corresponding Source.
401 @licend The above is the entire license notice
402 for the JavaScript code in this tag.
405 <!--/*--><![CDATA[/*><!--*/
406 %MANAGER_OPTIONS
407 org_html_manager.setup(); // activate after the parameters are set
408 /*]]>*///-->
409 </script>"
410 "The template for the export style additions when org-info.js is used.
411 Option settings will replace the %MANAGER-OPTIONS cookie."
412 :group 'org-export-html
413 :version "24.4"
414 :package-version '(Org . "8.0")
415 :type 'string)
417 (defun org-html-infojs-install-script (exp-plist backend)
418 "Install script in export options when appropriate.
419 EXP-PLIST is a plist containing export options. BACKEND is the
420 export back-end currently used."
421 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
422 (not org-html-use-infojs)
423 (and (eq org-html-use-infojs 'when-configured)
424 (or (not (plist-get exp-plist :infojs-opt))
425 (string-match "\\<view:nil\\>"
426 (plist-get exp-plist :infojs-opt)))))
427 (let* ((template org-html-infojs-template)
428 (ptoc (plist-get exp-plist :with-toc))
429 (hlevels (plist-get exp-plist :headline-levels))
430 (sdepth hlevels)
431 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
432 (options (plist-get exp-plist :infojs-opt))
433 (table org-html-infojs-opts-table)
434 style)
435 (dolist (entry table)
436 (let* ((opt (car entry))
437 (var (nth 1 entry))
438 ;; Compute default values for script option OPT from
439 ;; `org-html-infojs-options' variable.
440 (default
441 (let ((default (cdr (assq opt org-html-infojs-options))))
442 (if (and (symbolp default) (not (memq default '(t nil))))
443 (plist-get exp-plist default)
444 default)))
445 ;; Value set through INFOJS_OPT keyword has precedence
446 ;; over the default one.
447 (val (if (and options
448 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
449 options))
450 (match-string 1 options)
451 default)))
452 (case opt
453 (path (setq template
454 (replace-regexp-in-string
455 "%SCRIPT_PATH" val template t t)))
456 (sdepth (when (integerp (read val))
457 (setq sdepth (min (read val) sdepth))))
458 (tdepth (when (integerp (read val))
459 (setq tdepth (min (read val) tdepth))))
460 (otherwise (setq val
461 (cond
462 ((or (eq val t) (equal val "t")) "1")
463 ((or (eq val nil) (equal val "nil")) "0")
464 ((stringp val) val)
465 (t (format "%s" val))))
466 (push (cons var val) style)))))
467 ;; Now we set the depth of the *generated* TOC to SDEPTH,
468 ;; because the toc will actually determine the splitting. How
469 ;; much of the toc will actually be displayed is governed by the
470 ;; TDEPTH option.
471 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
472 ;; The table of contents should not show more sections than we
473 ;; generate.
474 (setq tdepth (min tdepth sdepth))
475 (push (cons "TOC_DEPTH" tdepth) style)
476 ;; Build style string.
477 (setq style (mapconcat
478 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
479 (car x)
480 (cdr x)))
481 style "\n"))
482 (when (and style (> (length style) 0))
483 (and (string-match "%MANAGER_OPTIONS" template)
484 (setq style (replace-match style t t template))
485 (setq exp-plist
486 (plist-put
487 exp-plist :html-head-extra
488 (concat (or (plist-get exp-plist :html-head-extra) "")
489 "\n"
490 style)))))
491 ;; This script absolutely needs the table of contents, so we
492 ;; change that setting.
493 (unless (plist-get exp-plist :with-toc)
494 (setq exp-plist (plist-put exp-plist :with-toc t)))
495 ;; Return the modified property list.
496 exp-plist)))
498 ;;;; Bold, etc.
500 (defcustom org-html-text-markup-alist
501 '((bold . "<b>%s</b>")
502 (code . "<code>%s</code>")
503 (italic . "<i>%s</i>")
504 (strike-through . "<del>%s</del>")
505 (underline . "<span class=\"underline\">%s</span>")
506 (verbatim . "<code>%s</code>"))
507 "Alist of HTML expressions to convert text markup.
509 The key must be a symbol among `bold', `code', `italic',
510 `strike-through', `underline' and `verbatim'. The value is
511 a formatting string to wrap fontified text with.
513 If no association can be found for a given markup, text will be
514 returned as-is."
515 :group 'org-export-html
516 :type '(alist :key-type (symbol :tag "Markup type")
517 :value-type (string :tag "Format string"))
518 :options '(bold code italic strike-through underline verbatim))
520 (defcustom org-html-indent nil
521 "Non-nil means to indent the generated HTML.
522 Warning: non-nil may break indentation of source code blocks."
523 :group 'org-export-html
524 :version "24.4"
525 :package-version '(Org . "8.0")
526 :type 'boolean)
528 (defcustom org-html-use-unicode-chars nil
529 "Non-nil means to use unicode characters instead of HTML entities."
530 :group 'org-export-html
531 :version "24.4"
532 :package-version '(Org . "8.0")
533 :type 'boolean)
535 ;;;; Drawers
537 (defcustom org-html-format-drawer-function nil
538 "Function called to format a drawer in HTML code.
540 The function must accept two parameters:
541 NAME the drawer name, like \"LOGBOOK\"
542 CONTENTS the contents of the drawer.
544 The function should return the string to be exported.
546 For example, the variable could be set to the following function
547 in order to mimic default behaviour:
549 \(defun org-html-format-drawer-default \(name contents\)
550 \"Format a drawer element for HTML export.\"
551 contents\)"
552 :group 'org-export-html
553 :type 'function)
555 ;;;; Footnotes
557 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
558 <h2 class=\"footnotes\">%s: </h2>
559 <div id=\"text-footnotes\">
561 </div>
562 </div>"
563 "Format for the footnotes section.
564 Should contain a two instances of %s. The first will be replaced with the
565 language-specific word for \"Footnotes\", the second one will be replaced
566 by the footnotes themselves."
567 :group 'org-export-html
568 :type 'string)
570 (defcustom org-html-footnote-format "<sup>%s</sup>"
571 "The format for the footnote reference.
572 %s will be replaced by the footnote reference itself."
573 :group 'org-export-html
574 :type 'string)
576 (defcustom org-html-footnote-separator "<sup>, </sup>"
577 "Text used to separate footnotes."
578 :group 'org-export-html
579 :type 'string)
581 ;;;; Headline
583 (defcustom org-html-toplevel-hlevel 2
584 "The <H> level for level 1 headings in HTML export.
585 This is also important for the classes that will be wrapped around headlines
586 and outline structure. If this variable is 1, the top-level headlines will
587 be <h1>, and the corresponding classes will be outline-1, section-number-1,
588 and outline-text-1. If this is 2, all of these will get a 2 instead.
589 The default for this variable is 2, because we use <h1> for formatting the
590 document title."
591 :group 'org-export-html
592 :type 'integer)
594 (defcustom org-html-format-headline-function nil
595 "Function to format headline text.
597 This function will be called with 5 arguments:
598 TODO the todo keyword (string or nil).
599 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
600 PRIORITY the priority of the headline (integer or nil)
601 TEXT the main headline text (string).
602 TAGS the tags (string or nil).
604 The function result will be used in the section format string."
605 :group 'org-export-html
606 :type 'function)
608 ;;;; HTML-specific
610 (defcustom org-html-allow-name-attribute-in-anchors t
611 "When nil, do not set \"name\" attribute in anchors.
612 By default, anchors are formatted with both \"id\" and \"name\"
613 attributes, when appropriate."
614 :group 'org-export-html
615 :version "24.4"
616 :package-version '(Org . "8.0")
617 :type 'boolean)
619 ;;;; Inlinetasks
621 (defcustom org-html-format-inlinetask-function nil
622 "Function called to format an inlinetask in HTML code.
624 The function must accept six parameters:
625 TODO the todo keyword, as a string
626 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
627 PRIORITY the inlinetask priority, as a string
628 NAME the inlinetask name, as a string.
629 TAGS the inlinetask tags, as a list of strings.
630 CONTENTS the contents of the inlinetask, as a string.
632 The function should return the string to be exported."
633 :group 'org-export-html
634 :type 'function)
636 ;;;; LaTeX
638 (defcustom org-html-with-latex org-export-with-latex
639 "Non-nil means process LaTeX math snippets.
641 When set, the exporter will process LaTeX environments and
642 fragments.
644 This option can also be set with the +OPTIONS line,
645 e.g. \"tex:mathjax\". Allowed values are:
647 nil Ignore math snippets.
648 `verbatim' Keep everything in verbatim
649 `dvipng' Process the LaTeX fragments to images. This will also
650 include processing of non-math environments.
651 `imagemagick' Convert the LaTeX fragments to pdf files and use
652 imagemagick to convert pdf files to png files.
653 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
654 be loaded.
655 t Synonym for `mathjax'."
656 :group 'org-export-html
657 :version "24.4"
658 :package-version '(Org . "8.0")
659 :type '(choice
660 (const :tag "Do not process math in any way" nil)
661 (const :tag "Use dvipng to make images" dvipng)
662 (const :tag "Use imagemagick to make images" imagemagick)
663 (const :tag "Use MathJax to display math" mathjax)
664 (const :tag "Leave math verbatim" verbatim)))
666 ;;;; Links :: Generic
668 (defcustom org-html-link-org-files-as-html t
669 "Non-nil means make file links to `file.org' point to `file.html'.
670 When `org-mode' is exporting an `org-mode' file to HTML, links to
671 non-html files are directly put into a href tag in HTML.
672 However, links to other Org-mode files (recognized by the
673 extension `.org.) should become links to the corresponding html
674 file, assuming that the linked `org-mode' file will also be
675 converted to HTML.
676 When nil, the links still point to the plain `.org' file."
677 :group 'org-export-html
678 :type 'boolean)
680 ;;;; Links :: Inline images
682 (defcustom org-html-inline-images 'maybe
683 "Non-nil means inline images into exported HTML pages.
684 This is done using an <img> tag. When nil, an anchor with href is used to
685 link to the image. If this option is `maybe', then images in links with
686 an empty description will be inlined, while images with a description will
687 be linked only."
688 :group 'org-export-html
689 :type '(choice (const :tag "Never" nil)
690 (const :tag "Always" t)
691 (const :tag "When there is no description" maybe)))
693 (defcustom org-html-inline-image-rules
694 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
695 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
697 "Rules characterizing image files that can be inlined into HTML.
698 A rule consists in an association whose key is the type of link
699 to consider, and value is a regexp that will be matched against
700 link's path."
701 :group 'org-export-html
702 :version "24.4"
703 :package-version '(Org . "8.0")
704 :type '(alist :key-type (string :tag "Type")
705 :value-type (regexp :tag "Path")))
707 ;;;; Plain Text
709 (defcustom org-html-protect-char-alist
710 '(("&" . "&amp;")
711 ("<" . "&lt;")
712 (">" . "&gt;"))
713 "Alist of characters to be converted by `org-html-protect'."
714 :group 'org-export-html
715 :type '(repeat (cons (string :tag "Character")
716 (string :tag "HTML equivalent"))))
718 ;;;; Src Block
720 (defcustom org-html-htmlize-output-type 'inline-css
721 "Output type to be used by htmlize when formatting code snippets.
722 Choices are `css', to export the CSS selectors only, or `inline-css', to
723 export the CSS attribute values inline in the HTML. We use as default
724 `inline-css', in order to make the resulting HTML self-containing.
726 However, this will fail when using Emacs in batch mode for export, because
727 then no rich font definitions are in place. It will also not be good if
728 people with different Emacs setup contribute HTML files to a website,
729 because the fonts will represent the individual setups. In these cases,
730 it is much better to let Org/Htmlize assign classes only, and to use
731 a style file to define the look of these classes.
732 To get a start for your css file, start Emacs session and make sure that
733 all the faces you are interested in are defined, for example by loading files
734 in all modes you want. Then, use the command
735 \\[org-html-htmlize-generate-css] to extract class definitions."
736 :group 'org-export-html
737 :type '(choice (const css) (const inline-css)))
739 (defcustom org-html-htmlize-font-prefix "org-"
740 "The prefix for CSS class names for htmlize font specifications."
741 :group 'org-export-html
742 :type 'string)
744 ;;;; Table
746 (defcustom org-html-table-default-attributes
747 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
748 "Default attributes and values which will be used in table tags.
749 This is a plist where attributes are symbols, starting with
750 colons, and values are strings."
751 :group 'org-export-html
752 :version "24.4"
753 :package-version '(Org . "8.0")
754 :type '(plist :key-type (symbol :tag "Property")
755 :value-type (string :tag "Value")))
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--make-attribute-string (attributes)
1243 "Return a list of attributes, as a string.
1244 ATTRIBUTES is a plist where values are either strings or nil. An
1245 attributes with a nil value will be omitted from the result."
1246 (let (output)
1247 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1248 (cond ((null item) (pop output))
1249 ((symbolp item) (push (substring (symbol-name item) 1) output))
1250 (t (let ((key (car output))
1251 (value (replace-regexp-in-string
1252 "\"" "&quot;" (org-html-encode-plain-text item))))
1253 (setcar output (format "%s=\"%s\"" key value))))))))
1255 (defun org-html-format-inline-image (src &optional
1256 caption label attr standalone-p)
1257 "Format an inline image from SRC.
1258 CAPTION, LABEL and ATTR are optional arguments providing the
1259 caption, the label and the attribute of the image.
1260 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1261 (let* ((id (if (not label) ""
1262 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1263 (attr (concat attr
1264 (cond
1265 ((string-match "\\<alt=" (or attr "")) "")
1266 ((string-match "^ltxpng/" src)
1267 (format " alt=\"%s\""
1268 (org-html-encode-plain-text
1269 (org-find-text-property-in-string
1270 'org-latex-src src))))
1271 (t (format " alt=\"%s\""
1272 (file-name-nondirectory src)))))))
1273 (cond
1274 (standalone-p
1275 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1276 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1277 id (format "\n<p>%s</p>" img)
1278 (if (and caption (not (string= caption "")))
1279 (format "\n<p>%s</p>" caption) ""))))
1280 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1282 (defun org-html--textarea-block (element)
1283 "Transcode ELEMENT into a textarea block.
1284 ELEMENT is either a src block or an example block."
1285 (let* ((code (car (org-export-unravel-code element)))
1286 (attr (org-export-read-attribute :attr_html element)))
1287 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1288 (or (plist-get attr :width) 80)
1289 (or (plist-get attr :height) (org-count-lines code))
1290 code)))
1292 ;;;; Bibliography
1294 (defun org-html-bibliography ()
1295 "Find bibliography, cut it out and return it."
1296 (catch 'exit
1297 (let (beg end (cnt 1) bib)
1298 (save-excursion
1299 (goto-char (point-min))
1300 (when (re-search-forward
1301 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1302 (setq beg (match-beginning 0))
1303 (while (re-search-forward "</?div\\>" nil t)
1304 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1305 (when (= cnt 0)
1306 (and (looking-at ">") (forward-char 1))
1307 (setq bib (buffer-substring beg (point)))
1308 (delete-region beg (point))
1309 (throw 'exit bib))))
1310 nil))))
1312 ;;;; Table
1314 (defun org-html-htmlize-region-for-paste (beg end)
1315 "Convert the region between BEG and END to HTML, using htmlize.el.
1316 This is much like `htmlize-region-for-paste', only that it uses
1317 the settings define in the org-... variables."
1318 (let* ((htmlize-output-type org-html-htmlize-output-type)
1319 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1320 (htmlbuf (htmlize-region beg end)))
1321 (unwind-protect
1322 (with-current-buffer htmlbuf
1323 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1324 (plist-get htmlize-buffer-places 'content-end)))
1325 (kill-buffer htmlbuf))))
1327 ;;;###autoload
1328 (defun org-html-htmlize-generate-css ()
1329 "Create the CSS for all font definitions in the current Emacs session.
1330 Use this to create face definitions in your CSS style file that can then
1331 be used by code snippets transformed by htmlize.
1332 This command just produces a buffer that contains class definitions for all
1333 faces used in the current Emacs session. You can copy and paste the ones you
1334 need into your CSS file.
1336 If you then set `org-html-htmlize-output-type' to `css', calls
1337 to the function `org-html-htmlize-region-for-paste' will
1338 produce code that uses these same face definitions."
1339 (interactive)
1340 (require 'htmlize)
1341 (and (get-buffer "*html*") (kill-buffer "*html*"))
1342 (with-temp-buffer
1343 (let ((fl (face-list))
1344 (htmlize-css-name-prefix "org-")
1345 (htmlize-output-type 'css)
1346 f i)
1347 (while (setq f (pop fl)
1348 i (and f (face-attribute f :inherit)))
1349 (when (and (symbolp f) (or (not i) (not (listp i))))
1350 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1351 (htmlize-region (point-min) (point-max))))
1352 (org-pop-to-buffer-same-window "*html*")
1353 (goto-char (point-min))
1354 (if (re-search-forward "<style" nil t)
1355 (delete-region (point-min) (match-beginning 0)))
1356 (if (re-search-forward "</style>" nil t)
1357 (delete-region (1+ (match-end 0)) (point-max)))
1358 (beginning-of-line 1)
1359 (if (looking-at " +") (replace-match ""))
1360 (goto-char (point-min)))
1362 (defun org-html--make-string (n string)
1363 "Build a string by concatenating N times STRING."
1364 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1366 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1367 "Turn todo keyword KWD into a valid class name.
1368 Replaces invalid characters with \"_\"."
1369 (save-match-data
1370 (while (string-match "[^a-zA-Z0-9_]" kwd)
1371 (setq kwd (replace-match "_" t t kwd))))
1372 kwd)
1374 (defun org-html-format-footnote-reference (n def refcnt)
1375 "Format footnote reference N with definition DEF into HTML."
1376 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1377 (format org-html-footnote-format
1378 (let* ((id (format "fnr.%s%s" n extra))
1379 (href (format " href=\"#fn.%s\"" n))
1380 (attributes (concat " class=\"footref\"" href)))
1381 (org-html--anchor id n attributes)))))
1383 (defun org-html-format-footnotes-section (section-name definitions)
1384 "Format footnotes section SECTION-NAME."
1385 (if (not definitions) ""
1386 (format org-html-footnotes-section section-name definitions)))
1388 (defun org-html-format-footnote-definition (fn)
1389 "Format the footnote definition FN."
1390 (let ((n (car fn)) (def (cdr fn)))
1391 (format
1392 "<div class=\"footdef\">%s %s</div>\n"
1393 (format org-html-footnote-format
1394 (let* ((id (format "fn.%s" n))
1395 (href (format " href=\"#fnr.%s\"" n))
1396 (attributes (concat " class=\"footnum\"" href)))
1397 (org-html--anchor id n attributes)))
1398 def)))
1400 (defun org-html-footnote-section (info)
1401 "Format the footnote section.
1402 INFO is a plist used as a communication channel."
1403 (let* ((fn-alist (org-export-collect-footnote-definitions
1404 (plist-get info :parse-tree) info))
1405 (fn-alist
1406 (loop for (n type raw) in fn-alist collect
1407 (cons n (if (eq (org-element-type raw) 'org-data)
1408 (org-trim (org-export-data raw info))
1409 (format "<p>%s</p>"
1410 (org-trim (org-export-data raw info))))))))
1411 (when fn-alist
1412 (org-html-format-footnotes-section
1413 (org-html--translate "Footnotes" info)
1414 (format
1415 "\n%s\n"
1416 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1419 ;;; Template
1421 (defun org-html--build-meta-info (info)
1422 "Return meta tags for exported document.
1423 INFO is a plist used as a communication channel."
1424 (let ((protect-string
1425 (lambda (str)
1426 (replace-regexp-in-string
1427 "\"" "&quot;" (org-html-encode-plain-text str))))
1428 (title (org-export-data (plist-get info :title) info))
1429 (author (and (plist-get info :with-author)
1430 (let ((auth (plist-get info :author)))
1431 (and auth
1432 ;; Return raw Org syntax, skipping non
1433 ;; exportable objects.
1434 (org-element-interpret-data
1435 (org-element-map auth
1436 (cons 'plain-text org-element-all-objects)
1437 'identity info))))))
1438 (description (plist-get info :description))
1439 (keywords (plist-get info :keywords)))
1440 (concat
1441 (format "<title>%s</title>\n" title)
1442 (format
1443 (when :time-stamp-file
1444 (format-time-string
1445 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
1446 (format
1447 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1448 (or (and org-html-coding-system
1449 (fboundp 'coding-system-get)
1450 (coding-system-get org-html-coding-system 'mime-charset))
1451 "iso-8859-1"))
1452 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1453 (and (org-string-nw-p author)
1454 (format "<meta name=\"author\" content=\"%s\"/>\n"
1455 (funcall protect-string author)))
1456 (and (org-string-nw-p description)
1457 (format "<meta name=\"description\" content=\"%s\"/>\n"
1458 (funcall protect-string description)))
1459 (and (org-string-nw-p keywords)
1460 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1461 (funcall protect-string keywords))))))
1463 (defun org-html--build-head (info)
1464 "Return information for the <head>..</head> of the HTML output.
1465 INFO is a plist used as a communication channel."
1466 (org-element-normalize-string
1467 (concat
1468 (when (plist-get info :html-head-include-default-style)
1469 (org-element-normalize-string org-html-style-default))
1470 (org-element-normalize-string (plist-get info :html-head))
1471 (org-element-normalize-string (plist-get info :html-head-extra))
1472 (when (and (plist-get info :html-htmlized-css-url)
1473 (eq org-html-htmlize-output-type 'css))
1474 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1475 (plist-get info :html-htmlized-css-url)))
1476 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1478 (defun org-html--build-mathjax-config (info)
1479 "Insert the user setup into the mathjax template.
1480 INFO is a plist used as a communication channel."
1481 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1482 (org-element-map (plist-get info :parse-tree)
1483 '(latex-fragment latex-environment) 'identity info t))
1484 (let ((template org-html-mathjax-template)
1485 (options org-html-mathjax-options)
1486 (in-buffer (or (plist-get info :html-mathjax) ""))
1487 name val (yes " ") (no "// ") x)
1488 (mapc
1489 (lambda (e)
1490 (setq name (car e) val (nth 1 e))
1491 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1492 (setq val (car (read-from-string
1493 (substring in-buffer (match-end 0))))))
1494 (if (not (stringp val)) (setq val (format "%s" val)))
1495 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1496 (setq template (replace-match val t t template))))
1497 options)
1498 (setq val (nth 1 (assq 'mathml options)))
1499 (if (string-match (concat "\\<mathml:") in-buffer)
1500 (setq val (car (read-from-string
1501 (substring in-buffer (match-end 0))))))
1502 ;; Exchange prefixes depending on mathml setting.
1503 (if (not val) (setq x yes yes no no x))
1504 ;; Replace cookies to turn on or off the config/jax lines.
1505 (if (string-match ":MMLYES:" template)
1506 (setq template (replace-match yes t t template)))
1507 (if (string-match ":MMLNO:" template)
1508 (setq template (replace-match no t t template)))
1509 ;; Return the modified template.
1510 (org-element-normalize-string template))))
1512 (defun org-html-format-spec (info)
1513 "Return format specification for elements that can be
1514 used in the preamble or postamble."
1515 `((?t . ,(org-export-data (plist-get info :title) info))
1516 (?d . ,(org-export-data (org-export-get-date info) info))
1517 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1518 (?a . ,(org-export-data (plist-get info :author) info))
1519 (?e . ,(mapconcat
1520 (lambda (e)
1521 (format "<a href=\"mailto:%s\">%s</a>" e e))
1522 (split-string (plist-get info :email) ",+ *")
1523 ", "))
1524 (?c . ,(plist-get info :creator))
1525 (?C . ,(let ((file (plist-get info :input-file)))
1526 (format-time-string org-html-metadata-timestamp-format
1527 (if file (nth 5 (file-attributes file))
1528 (current-time)))))
1529 (?v . ,(or org-html-validation-link ""))))
1531 (defun org-html--build-pre/postamble (type info)
1532 "Return document preamble or postamble as a string, or nil.
1533 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1534 communication channel."
1535 (let ((section (plist-get info (intern (format ":html-%s" type))))
1536 (spec (org-html-format-spec info)))
1537 (when section
1538 (let ((section-contents
1539 (if (functionp section) (funcall section info)
1540 (cond
1541 ((stringp section) (format-spec section spec))
1542 ((eq section 'auto)
1543 (let ((date (cdr (assq ?d spec)))
1544 (author (cdr (assq ?a spec)))
1545 (email (cdr (assq ?e spec)))
1546 (creator (cdr (assq ?c spec)))
1547 (timestamp (cdr (assq ?T spec)))
1548 (validation-link (cdr (assq ?v spec))))
1549 (concat
1550 (when (and (plist-get info :with-date)
1551 (org-string-nw-p date))
1552 (format "<p class=\"date\">%s: %s</p>\n"
1553 (org-html--translate "Date" info)
1554 date))
1555 (when (and (plist-get info :with-author)
1556 (org-string-nw-p author))
1557 (format "<p class=\"author\">%s: %s</p>\n"
1558 (org-html--translate "Author" info)
1559 author))
1560 (when (and (plist-get info :with-email)
1561 (org-string-nw-p email))
1562 (format "<p class=\"email\">%s: %s</p>\n"
1563 (org-html--translate "Email" info)
1564 email))
1565 (when (plist-get info :time-stamp-file)
1566 (format
1567 "<p class=\"date\">%s: %s</p>\n"
1568 (org-html--translate "Created" info)
1569 (format-time-string org-html-metadata-timestamp-format)))
1570 (when (plist-get info :with-creator)
1571 (format "<p class=\"creator\">%s</p>\n" creator))
1572 (format "<p class=\"xhtml-validation\">%s</p>\n"
1573 validation-link))))
1574 (t (format-spec
1575 (or (cadr (assoc
1576 (plist-get info :language)
1577 (eval (intern
1578 (format "org-html-%s-format" type)))))
1579 (cadr
1580 (assoc
1581 "en"
1582 (eval
1583 (intern (format "org-html-%s-format" type))))))
1584 spec))))))
1585 (when (org-string-nw-p section-contents)
1586 (concat
1587 (format "<%s id=\"%s\" class=\"%s\">\n"
1588 (nth 1 (assq type org-html-divs))
1589 (nth 2 (assq type org-html-divs))
1590 org-html--pre/postamble-class)
1591 (org-element-normalize-string section-contents)
1592 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1594 (defun org-html-inner-template (contents info)
1595 "Return body of document string after HTML conversion.
1596 CONTENTS is the transcoded contents string. INFO is a plist
1597 holding export options."
1598 (concat
1599 ;; Table of contents.
1600 (let ((depth (plist-get info :with-toc)))
1601 (when depth (org-html-toc depth info)))
1602 ;; Document contents.
1603 contents
1604 ;; Footnotes section.
1605 (org-html-footnote-section info)
1606 ;; Bibliography.
1607 (org-html-bibliography)))
1609 (defun org-html-template (contents info)
1610 "Return complete document string after HTML conversion.
1611 CONTENTS is the transcoded contents string. INFO is a plist
1612 holding export options."
1613 (concat
1614 (format
1615 (or (and (stringp org-html-xml-declaration)
1616 org-html-xml-declaration)
1617 (cdr (assoc (plist-get info :html-extension)
1618 org-html-xml-declaration))
1619 (cdr (assoc "html" org-html-xml-declaration))
1622 (or (and org-html-coding-system
1623 (fboundp 'coding-system-get)
1624 (coding-system-get org-html-coding-system 'mime-charset))
1625 "iso-8859-1"))
1626 "\n"
1627 (plist-get info :html-doctype)
1628 "\n"
1629 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1630 (plist-get info :language) (plist-get info :language))
1631 "<head>\n"
1632 (org-html--build-meta-info info)
1633 (org-html--build-head info)
1634 (org-html--build-mathjax-config info)
1635 "</head>\n"
1636 "<body>\n"
1637 (let ((link-up (org-trim (plist-get info :html-link-up)))
1638 (link-home (org-trim (plist-get info :html-link-home))))
1639 (unless (and (string= link-up "") (string= link-up ""))
1640 (format org-html-home/up-format
1641 (or link-up link-home)
1642 (or link-home link-up))))
1643 ;; Preamble.
1644 (org-html--build-pre/postamble 'preamble info)
1645 ;; Document contents.
1646 (format "<%s id=\"%s\">\n"
1647 (nth 1 (assq 'content org-html-divs))
1648 (nth 2 (assq 'content org-html-divs)))
1649 ;; Document title.
1650 (let ((title (plist-get info :title)))
1651 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1652 contents
1653 (format "</%s>\n"
1654 (nth 1 (assq 'content org-html-divs)))
1655 ;; Postamble.
1656 (org-html--build-pre/postamble 'postamble info)
1657 ;; Closing document.
1658 "</body>\n</html>"))
1660 (defun org-html--translate (s info)
1661 "Translate string S according to specified language.
1662 INFO is a plist used as a communication channel."
1663 (org-export-translate s :html info))
1665 ;;;; Anchor
1667 (defun org-html--anchor (&optional id desc attributes)
1668 "Format a HTML anchor."
1669 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1670 (attributes (concat (and id (format " id=\"%s\"" id))
1671 (and name (format " name=\"%s\"" name))
1672 attributes)))
1673 (format "<a%s>%s</a>" attributes (or desc ""))))
1675 ;;;; Todo
1677 (defun org-html--todo (todo)
1678 "Format TODO keywords into HTML."
1679 (when todo
1680 (format "<span class=\"%s %s%s\">%s</span>"
1681 (if (member todo org-done-keywords) "done" "todo")
1682 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1683 todo)))
1685 ;;;; Tags
1687 (defun org-html--tags (tags)
1688 "Format TAGS into HTML."
1689 (when tags
1690 (format "<span class=\"tag\">%s</span>"
1691 (mapconcat
1692 (lambda (tag)
1693 (format "<span class=\"%s\">%s</span>"
1694 (concat org-html-tag-class-prefix
1695 (org-html-fix-class-name tag))
1696 tag))
1697 tags "&#xa0;"))))
1699 ;;;; Headline
1701 (defun* org-html-format-headline
1702 (todo todo-type priority text tags
1703 &key level section-number headline-label &allow-other-keys)
1704 "Format a headline in HTML."
1705 (let ((section-number
1706 (when section-number
1707 (format "<span class=\"section-number-%d\">%s</span> "
1708 level section-number)))
1709 (todo (org-html--todo todo))
1710 (tags (org-html--tags tags)))
1711 (concat section-number todo (and todo " ") text
1712 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1714 ;;;; Src Code
1716 (defun org-html-fontify-code (code lang)
1717 "Color CODE with htmlize library.
1718 CODE is a string representing the source code to colorize. LANG
1719 is the language used for CODE, as a string, or nil."
1720 (when code
1721 (cond
1722 ;; Case 1: No lang. Possibly an example block.
1723 ((not lang)
1724 ;; Simple transcoding.
1725 (org-html-encode-plain-text code))
1726 ;; Case 2: No htmlize or an inferior version of htmlize
1727 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1728 ;; Emit a warning.
1729 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1730 ;; Simple transcoding.
1731 (org-html-encode-plain-text code))
1733 ;; Map language
1734 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1735 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1736 (cond
1737 ;; Case 1: Language is not associated with any Emacs mode
1738 ((not (functionp lang-mode))
1739 ;; Simple transcoding.
1740 (org-html-encode-plain-text code))
1741 ;; Case 2: Default. Fontify code.
1743 ;; htmlize
1744 (setq code (with-temp-buffer
1745 ;; Switch to language-specific mode.
1746 (funcall lang-mode)
1747 (insert code)
1748 ;; Fontify buffer.
1749 (font-lock-fontify-buffer)
1750 ;; Remove formatting on newline characters.
1751 (save-excursion
1752 (let ((beg (point-min))
1753 (end (point-max)))
1754 (goto-char beg)
1755 (while (progn (end-of-line) (< (point) end))
1756 (put-text-property (point) (1+ (point)) 'face nil)
1757 (forward-char 1))))
1758 (org-src-mode)
1759 (set-buffer-modified-p nil)
1760 ;; Htmlize region.
1761 (org-html-htmlize-region-for-paste
1762 (point-min) (point-max))))
1763 ;; Strip any enclosing <pre></pre> tags.
1764 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1765 (end (and beg (string-match "</pre>\\'" code))))
1766 (if (and beg end) (substring code beg end) code)))))))))
1768 (defun org-html-do-format-code
1769 (code &optional lang refs retain-labels num-start)
1770 "Format CODE string as source code.
1771 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1772 respectively, the language of the source code, as a string, an
1773 alist between line numbers and references (as returned by
1774 `org-export-unravel-code'), a boolean specifying if labels should
1775 appear in the source code, and the number associated to the first
1776 line of code."
1777 (let* ((code-lines (org-split-string code "\n"))
1778 (code-length (length code-lines))
1779 (num-fmt
1780 (and num-start
1781 (format "%%%ds: "
1782 (length (number-to-string (+ code-length num-start))))))
1783 (code (org-html-fontify-code code lang)))
1784 (org-export-format-code
1785 code
1786 (lambda (loc line-num ref)
1787 (setq loc
1788 (concat
1789 ;; Add line number, if needed.
1790 (when num-start
1791 (format "<span class=\"linenr\">%s</span>"
1792 (format num-fmt line-num)))
1793 ;; Transcoded src line.
1795 ;; Add label, if needed.
1796 (when (and ref retain-labels) (format " (%s)" ref))))
1797 ;; Mark transcoded line as an anchor, if needed.
1798 (if (not ref) loc
1799 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1800 ref loc)))
1801 num-start refs)))
1803 (defun org-html-format-code (element info)
1804 "Format contents of ELEMENT as source code.
1805 ELEMENT is either an example block or a src block. INFO is
1806 a plist used as a communication channel."
1807 (let* ((lang (org-element-property :language element))
1808 ;; Extract code and references.
1809 (code-info (org-export-unravel-code element))
1810 (code (car code-info))
1811 (refs (cdr code-info))
1812 ;; Does the src block contain labels?
1813 (retain-labels (org-element-property :retain-labels element))
1814 ;; Does it have line numbers?
1815 (num-start (case (org-element-property :number-lines element)
1816 (continued (org-export-get-loc element info))
1817 (new 0))))
1818 (org-html-do-format-code code lang refs retain-labels num-start)))
1821 ;;; Tables of Contents
1823 (defun org-html-toc (depth info)
1824 "Build a table of contents.
1825 DEPTH is an integer specifying the depth of the table. INFO is a
1826 plist used as a communication channel. Return the table of
1827 contents as a string, or nil if it is empty."
1828 (let ((toc-entries
1829 (mapcar (lambda (headline)
1830 (cons (org-html--format-toc-headline headline info)
1831 (org-export-get-relative-level headline info)))
1832 (org-export-collect-headlines info depth))))
1833 (when toc-entries
1834 (concat "<div id=\"table-of-contents\">\n"
1835 (format "<h%d>%s</h%d>\n"
1836 org-html-toplevel-hlevel
1837 (org-html--translate "Table of Contents" info)
1838 org-html-toplevel-hlevel)
1839 "<div id=\"text-table-of-contents\">"
1840 (org-html--toc-text toc-entries)
1841 "</div>\n"
1842 "</div>\n"))))
1844 (defun org-html--toc-text (toc-entries)
1845 "Return innards of a table of contents, as a string.
1846 TOC-ENTRIES is an alist where key is an entry title, as a string,
1847 and value is its relative level, as an integer."
1848 (let* ((prev-level (1- (cdar toc-entries)))
1849 (start-level prev-level))
1850 (concat
1851 (mapconcat
1852 (lambda (entry)
1853 (let ((headline (car entry))
1854 (level (cdr entry)))
1855 (concat
1856 (let* ((cnt (- level prev-level))
1857 (times (if (> cnt 0) (1- cnt) (- cnt)))
1858 rtn)
1859 (setq prev-level level)
1860 (concat
1861 (org-html--make-string
1862 times (cond ((> cnt 0) "\n<ul>\n<li>")
1863 ((< cnt 0) "</li>\n</ul>\n")))
1864 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1865 headline)))
1866 toc-entries "")
1867 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1869 (defun org-html--format-toc-headline (headline info)
1870 "Return an appropriate table of contents entry for HEADLINE.
1871 INFO is a plist used as a communication channel."
1872 (let* ((headline-number (org-export-get-headline-number headline info))
1873 (section-number
1874 (and (not (org-export-low-level-p headline info))
1875 (org-export-numbered-headline-p headline info)
1876 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1877 (tags (and (eq (plist-get info :with-tags) t)
1878 (org-export-get-tags headline info))))
1879 (format "<a href=\"#%s\">%s</a>"
1880 ;; Label.
1881 (org-export-solidify-link-text
1882 (or (org-element-property :CUSTOM_ID headline)
1883 (concat "sec-" (mapconcat 'number-to-string
1884 headline-number "-"))))
1885 ;; Body.
1886 (concat section-number
1887 (org-export-data-with-translations
1888 (org-export-get-alt-title headline info)
1889 ;; Ignore any footnote-reference, link,
1890 ;; radio-target and target in table of contents.
1891 (append
1892 '((footnote-reference . ignore)
1893 (link . (lambda (link desc i) desc))
1894 (radio-target . (lambda (radio desc i) desc))
1895 (target . ignore))
1896 (org-export-backend-translate-table 'html))
1897 info)
1898 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1900 (defun org-html-list-of-listings (info)
1901 "Build a list of listings.
1902 INFO is a plist used as a communication channel. Return the list
1903 of listings as a string, or nil if it is empty."
1904 (let ((lol-entries (org-export-collect-listings info)))
1905 (when lol-entries
1906 (concat "<div id=\"list-of-listings\">\n"
1907 (format "<h%d>%s</h%d>\n"
1908 org-html-toplevel-hlevel
1909 (org-html--translate "List of Listings" info)
1910 org-html-toplevel-hlevel)
1911 "<div id=\"text-list-of-listings\">\n<ul>\n"
1912 (let ((count 0)
1913 (initial-fmt (org-html--translate "Listing %d:" info)))
1914 (mapconcat
1915 (lambda (entry)
1916 (let ((label (org-element-property :name entry))
1917 (title (org-trim
1918 (org-export-data
1919 (or (org-export-get-caption entry t)
1920 (org-export-get-caption entry))
1921 info))))
1922 (concat
1923 "<li>"
1924 (if (not label)
1925 (concat (format initial-fmt (incf count)) " " title)
1926 (format "<a href=\"#%s\">%s %s</a>"
1927 (org-export-solidify-link-text label)
1928 (format initial-fmt (incf count))
1929 title))
1930 "</li>")))
1931 lol-entries "\n"))
1932 "\n</ul>\n</div>\n</div>"))))
1934 (defun org-html-list-of-tables (info)
1935 "Build a list of tables.
1936 INFO is a plist used as a communication channel. Return the list
1937 of tables as a string, or nil if it is empty."
1938 (let ((lol-entries (org-export-collect-tables info)))
1939 (when lol-entries
1940 (concat "<div id=\"list-of-tables\">\n"
1941 (format "<h%d>%s</h%d>\n"
1942 org-html-toplevel-hlevel
1943 (org-html--translate "List of Tables" info)
1944 org-html-toplevel-hlevel)
1945 "<div id=\"text-list-of-tables\">\n<ul>\n"
1946 (let ((count 0)
1947 (initial-fmt (org-html--translate "Table %d:" info)))
1948 (mapconcat
1949 (lambda (entry)
1950 (let ((label (org-element-property :name entry))
1951 (title (org-trim
1952 (org-export-data
1953 (or (org-export-get-caption entry t)
1954 (org-export-get-caption entry))
1955 info))))
1956 (concat
1957 "<li>"
1958 (if (not label)
1959 (concat (format initial-fmt (incf count)) " " title)
1960 (format "<a href=\"#%s\">%s %s</a>"
1961 (org-export-solidify-link-text label)
1962 (format initial-fmt (incf count))
1963 title))
1964 "</li>")))
1965 lol-entries "\n"))
1966 "\n</ul>\n</div>\n</div>"))))
1969 ;;; Transcode Functions
1971 ;;;; Bold
1973 (defun org-html-bold (bold contents info)
1974 "Transcode BOLD from Org to HTML.
1975 CONTENTS is the text with bold markup. INFO is a plist holding
1976 contextual information."
1977 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1978 contents))
1980 ;;;; Center Block
1982 (defun org-html-center-block (center-block contents info)
1983 "Transcode a CENTER-BLOCK element from Org to HTML.
1984 CONTENTS holds the contents of the block. INFO is a plist
1985 holding contextual information."
1986 (format "<div class=\"center\">\n%s</div>" contents))
1988 ;;;; Clock
1990 (defun org-html-clock (clock contents info)
1991 "Transcode a CLOCK element from Org to HTML.
1992 CONTENTS is nil. INFO is a plist used as a communication
1993 channel."
1994 (format "<p>
1995 <span class=\"timestamp-wrapper\">
1996 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1997 </span>
1998 </p>"
1999 org-clock-string
2000 (org-translate-time
2001 (org-element-property :raw-value
2002 (org-element-property :value clock)))
2003 (let ((time (org-element-property :duration clock)))
2004 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2006 ;;;; Code
2008 (defun org-html-code (code contents info)
2009 "Transcode CODE from Org to HTML.
2010 CONTENTS is nil. INFO is a plist holding contextual
2011 information."
2012 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2013 (org-html-plain-text (org-element-property :value code) info)))
2015 ;;;; Drawer
2017 (defun org-html-drawer (drawer contents info)
2018 "Transcode a DRAWER element from Org to HTML.
2019 CONTENTS holds the contents of the block. INFO is a plist
2020 holding contextual information."
2021 (if (functionp org-html-format-drawer-function)
2022 (funcall org-html-format-drawer-function
2023 (org-element-property :drawer-name drawer)
2024 contents)
2025 ;; If there's no user defined function: simply
2026 ;; display contents of the drawer.
2027 contents))
2029 ;;;; Dynamic Block
2031 (defun org-html-dynamic-block (dynamic-block contents info)
2032 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2033 CONTENTS holds the contents of the block. INFO is a plist
2034 holding contextual information. See `org-export-data'."
2035 contents)
2037 ;;;; Entity
2039 (defun org-html-entity (entity contents info)
2040 "Transcode an ENTITY object from Org to HTML.
2041 CONTENTS are the definition itself. INFO is a plist holding
2042 contextual information."
2043 (org-element-property :html entity))
2045 ;;;; Example Block
2047 (defun org-html-example-block (example-block contents info)
2048 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2049 CONTENTS is nil. INFO is a plist holding contextual
2050 information."
2051 (if (org-export-read-attribute :attr_html example-block :textarea)
2052 (org-html--textarea-block example-block)
2053 (format "<pre class=\"example\">\n%s</pre>"
2054 (org-html-format-code example-block info))))
2056 ;;;; Export Snippet
2058 (defun org-html-export-snippet (export-snippet contents info)
2059 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2060 CONTENTS is nil. INFO is a plist holding contextual
2061 information."
2062 (when (eq (org-export-snippet-backend export-snippet) 'html)
2063 (org-element-property :value export-snippet)))
2065 ;;;; Export Block
2067 (defun org-html-export-block (export-block contents info)
2068 "Transcode a EXPORT-BLOCK element from Org to HTML.
2069 CONTENTS is nil. INFO is a plist holding contextual information."
2070 (when (string= (org-element-property :type export-block) "HTML")
2071 (org-remove-indentation (org-element-property :value export-block))))
2073 ;;;; Fixed Width
2075 (defun org-html-fixed-width (fixed-width contents info)
2076 "Transcode a FIXED-WIDTH element from Org to HTML.
2077 CONTENTS is nil. INFO is a plist holding contextual information."
2078 (format "<pre class=\"example\">\n%s</pre>"
2079 (org-html-do-format-code
2080 (org-remove-indentation
2081 (org-element-property :value fixed-width)))))
2083 ;;;; Footnote Reference
2085 (defun org-html-footnote-reference (footnote-reference contents info)
2086 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2087 CONTENTS is nil. INFO is a plist holding contextual information."
2088 (concat
2089 ;; Insert separator between two footnotes in a row.
2090 (let ((prev (org-export-get-previous-element footnote-reference info)))
2091 (when (eq (org-element-type prev) 'footnote-reference)
2092 org-html-footnote-separator))
2093 (cond
2094 ((not (org-export-footnote-first-reference-p footnote-reference info))
2095 (org-html-format-footnote-reference
2096 (org-export-get-footnote-number footnote-reference info)
2097 "IGNORED" 100))
2098 ;; Inline definitions are secondary strings.
2099 ((eq (org-element-property :type footnote-reference) 'inline)
2100 (org-html-format-footnote-reference
2101 (org-export-get-footnote-number footnote-reference info)
2102 "IGNORED" 1))
2103 ;; Non-inline footnotes definitions are full Org data.
2104 (t (org-html-format-footnote-reference
2105 (org-export-get-footnote-number footnote-reference info)
2106 "IGNORED" 1)))))
2108 ;;;; Headline
2110 (defun org-html-format-headline--wrap
2111 (headline info &optional format-function &rest extra-keys)
2112 "Transcode a HEADLINE element from Org to HTML.
2113 CONTENTS holds the contents of the headline. INFO is a plist
2114 holding contextual information."
2115 (let* ((level (+ (org-export-get-relative-level headline info)
2116 (1- org-html-toplevel-hlevel)))
2117 (headline-number (org-export-get-headline-number headline info))
2118 (section-number (and (not (org-export-low-level-p headline info))
2119 (org-export-numbered-headline-p headline info)
2120 (mapconcat 'number-to-string
2121 headline-number ".")))
2122 (todo (and (plist-get info :with-todo-keywords)
2123 (let ((todo (org-element-property :todo-keyword headline)))
2124 (and todo (org-export-data todo info)))))
2125 (todo-type (and todo (org-element-property :todo-type headline)))
2126 (priority (and (plist-get info :with-priority)
2127 (org-element-property :priority headline)))
2128 (text (org-export-data (org-element-property :title headline) info))
2129 (tags (and (plist-get info :with-tags)
2130 (org-export-get-tags headline info)))
2131 (headline-label (or (org-element-property :CUSTOM_ID headline)
2132 (concat "sec-" (mapconcat 'number-to-string
2133 headline-number "-"))))
2134 (format-function (cond
2135 ((functionp format-function) format-function)
2136 ((functionp org-html-format-headline-function)
2137 (function*
2138 (lambda (todo todo-type priority text tags
2139 &allow-other-keys)
2140 (funcall org-html-format-headline-function
2141 todo todo-type priority text tags))))
2142 (t 'org-html-format-headline))))
2143 (apply format-function
2144 todo todo-type priority text tags
2145 :headline-label headline-label :level level
2146 :section-number section-number extra-keys)))
2148 (defun org-html-headline (headline contents info)
2149 "Transcode a HEADLINE element from Org to HTML.
2150 CONTENTS holds the contents of the headline. INFO is a plist
2151 holding contextual information."
2152 ;; Empty contents?
2153 (setq contents (or contents ""))
2154 (let* ((numberedp (org-export-numbered-headline-p headline info))
2155 (level (org-export-get-relative-level headline info))
2156 (text (org-export-data (org-element-property :title headline) info))
2157 (todo (and (plist-get info :with-todo-keywords)
2158 (let ((todo (org-element-property :todo-keyword headline)))
2159 (and todo (org-export-data todo info)))))
2160 (todo-type (and todo (org-element-property :todo-type headline)))
2161 (tags (and (plist-get info :with-tags)
2162 (org-export-get-tags headline info)))
2163 (priority (and (plist-get info :with-priority)
2164 (org-element-property :priority headline)))
2165 (section-number (and (org-export-numbered-headline-p headline info)
2166 (mapconcat 'number-to-string
2167 (org-export-get-headline-number
2168 headline info) ".")))
2169 ;; Create the headline text.
2170 (full-text (org-html-format-headline--wrap headline info)))
2171 (cond
2172 ;; Case 1: This is a footnote section: ignore it.
2173 ((org-element-property :footnote-section-p headline) nil)
2174 ;; Case 2. This is a deep sub-tree: export it as a list item.
2175 ;; Also export as items headlines for which no section
2176 ;; format has been found.
2177 ((org-export-low-level-p headline info)
2178 ;; Build the real contents of the sub-tree.
2179 (let* ((type (if numberedp 'ordered 'unordered))
2180 (itemized-body (org-html-format-list-item
2181 contents type nil nil full-text)))
2182 (concat
2183 (and (org-export-first-sibling-p headline info)
2184 (org-html-begin-plain-list type))
2185 itemized-body
2186 (and (org-export-last-sibling-p headline info)
2187 (org-html-end-plain-list type)))))
2188 ;; Case 3. Standard headline. Export it as a section.
2190 (let* ((section-number (mapconcat 'number-to-string
2191 (org-export-get-headline-number
2192 headline info) "-"))
2193 (ids (remove 'nil
2194 (list (org-element-property :CUSTOM_ID headline)
2195 (concat "sec-" section-number)
2196 (org-element-property :ID headline))))
2197 (preferred-id (car ids))
2198 (extra-ids (cdr ids))
2199 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2200 (level1 (+ level (1- org-html-toplevel-hlevel)))
2201 (first-content (car (org-element-contents headline))))
2202 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2203 (if (= 1 (org-export-get-relative-level headline info))
2204 (plist-get info :html-container)
2205 "div")
2206 (format "outline-container-%s"
2207 (or (org-element-property :CUSTOM_ID headline)
2208 (concat "sec-" section-number)))
2209 (concat (format "outline-%d" level1) (and extra-class " ")
2210 extra-class)
2211 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2212 level1
2213 preferred-id
2214 (mapconcat
2215 (lambda (x)
2216 (let ((id (org-export-solidify-link-text
2217 (if (org-uuidgen-p x) (concat "ID-" x)
2218 x))))
2219 (org-html--anchor id)))
2220 extra-ids "")
2221 full-text
2222 level1)
2223 ;; When there is no section, pretend there is an empty
2224 ;; one to get the correct <div class="outline- ...>
2225 ;; which is needed by `org-info.js'.
2226 (if (not (eq (org-element-type first-content) 'section))
2227 (concat (org-html-section first-content "" info)
2228 contents)
2229 contents)
2230 (if (= 1 (org-export-get-relative-level headline info))
2231 (plist-get info :html-container)
2232 "div")))))))
2234 ;;;; Horizontal Rule
2236 (defun org-html-horizontal-rule (horizontal-rule contents info)
2237 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2238 CONTENTS is nil. INFO is a plist holding contextual information."
2239 "<hr/>")
2241 ;;;; Inline Src Block
2243 (defun org-html-inline-src-block (inline-src-block contents info)
2244 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2245 CONTENTS holds the contents of the item. INFO is a plist holding
2246 contextual information."
2247 (let* ((org-lang (org-element-property :language inline-src-block))
2248 (code (org-element-property :value inline-src-block)))
2249 (error "Cannot export inline src block")))
2251 ;;;; Inlinetask
2253 (defun org-html-format-section (text class &optional id)
2254 "Format a section with TEXT into a HTML div with CLASS and ID."
2255 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2256 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2258 (defun org-html-inlinetask (inlinetask contents info)
2259 "Transcode an INLINETASK element from Org to HTML.
2260 CONTENTS holds the contents of the block. INFO is a plist
2261 holding contextual information."
2262 (cond
2263 ;; If `org-html-format-inlinetask-function' is provided, call it
2264 ;; with appropriate arguments.
2265 ((functionp org-html-format-inlinetask-function)
2266 (let ((format-function
2267 (function*
2268 (lambda (todo todo-type priority text tags
2269 &key contents &allow-other-keys)
2270 (funcall org-html-format-inlinetask-function
2271 todo todo-type priority text tags contents)))))
2272 (org-html-format-headline--wrap
2273 inlinetask info format-function :contents contents)))
2274 ;; Otherwise, use a default template.
2275 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2276 (org-html-format-headline--wrap inlinetask info)
2277 contents))))
2279 ;;;; Italic
2281 (defun org-html-italic (italic contents info)
2282 "Transcode ITALIC from Org to HTML.
2283 CONTENTS is the text with italic markup. INFO is a plist holding
2284 contextual information."
2285 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2287 ;;;; Item
2289 (defun org-html-checkbox (checkbox)
2290 "Format CHECKBOX into HTML."
2291 (case checkbox (on "<code>[X]</code>")
2292 (off "<code>[&#xa0;]</code>")
2293 (trans "<code>[-]</code>")
2294 (t "")))
2296 (defun org-html-format-list-item (contents type checkbox
2297 &optional term-counter-id
2298 headline)
2299 "Format a list item into HTML."
2300 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2301 (concat
2302 (case type
2303 (ordered
2304 (let* ((counter term-counter-id)
2305 (extra (if counter (format " value=\"%s\"" counter) "")))
2306 (concat
2307 (format "<li%s>" extra)
2308 (when headline (concat headline "<br/>")))))
2309 (unordered
2310 (let* ((id term-counter-id)
2311 (extra (if id (format " id=\"%s\"" id) "")))
2312 (concat
2313 (format "<li%s>" extra)
2314 (when headline (concat headline "<br/>")))))
2315 (descriptive
2316 (let* ((term term-counter-id))
2317 (setq term (or term "(no term)"))
2318 ;; Check-boxes in descriptive lists are associated to tag.
2319 (concat (format "<dt> %s </dt>"
2320 (concat checkbox term))
2321 "<dd>"))))
2322 (unless (eq type 'descriptive) checkbox)
2323 contents
2324 (case type
2325 (ordered "</li>")
2326 (unordered "</li>")
2327 (descriptive "</dd>")))))
2329 (defun org-html-item (item contents info)
2330 "Transcode an ITEM element from Org to HTML.
2331 CONTENTS holds the contents of the item. INFO is a plist holding
2332 contextual information."
2333 (let* ((plain-list (org-export-get-parent item))
2334 (type (org-element-property :type plain-list))
2335 (counter (org-element-property :counter item))
2336 (checkbox (org-element-property :checkbox item))
2337 (tag (let ((tag (org-element-property :tag item)))
2338 (and tag (org-export-data tag info)))))
2339 (org-html-format-list-item
2340 contents type checkbox (or tag counter))))
2342 ;;;; Keyword
2344 (defun org-html-keyword (keyword contents info)
2345 "Transcode a KEYWORD element from Org to HTML.
2346 CONTENTS is nil. INFO is a plist holding contextual information."
2347 (let ((key (org-element-property :key keyword))
2348 (value (org-element-property :value keyword)))
2349 (cond
2350 ((string= key "HTML") value)
2351 ((string= key "TOC")
2352 (let ((value (downcase value)))
2353 (cond
2354 ((string-match "\\<headlines\\>" value)
2355 (let ((depth (or (and (string-match "[0-9]+" value)
2356 (string-to-number (match-string 0 value)))
2357 (plist-get info :with-toc))))
2358 (org-html-toc depth info)))
2359 ((string= "listings" value) (org-html-list-of-listings info))
2360 ((string= "tables" value) (org-html-list-of-tables info))))))))
2362 ;;;; Latex Environment
2364 (defun org-html-format-latex (latex-frag processing-type)
2365 "Format the LaTeX fragment LATEX-FRAG into HTML."
2366 (let ((cache-relpath "") (cache-dir "") bfn)
2367 (unless (eq processing-type 'mathjax)
2368 (setq bfn (buffer-file-name)
2369 cache-relpath
2370 (concat "ltxpng/"
2371 (file-name-sans-extension
2372 (file-name-nondirectory bfn)))
2373 cache-dir (file-name-directory bfn)))
2374 (with-temp-buffer
2375 (insert latex-frag)
2376 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2377 nil nil processing-type)
2378 (buffer-string))))
2380 (defun org-html-latex-environment (latex-environment contents info)
2381 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2382 CONTENTS is nil. INFO is a plist holding contextual information."
2383 (let ((processing-type (plist-get info :with-latex))
2384 (latex-frag (org-remove-indentation
2385 (org-element-property :value latex-environment)))
2386 (caption (org-export-data
2387 (org-export-get-caption latex-environment) info))
2388 (attr nil) ; FIXME
2389 (label (org-element-property :name latex-environment)))
2390 (cond
2391 ((memq processing-type '(t mathjax))
2392 (org-html-format-latex latex-frag 'mathjax))
2393 ((eq processing-type 'dvipng)
2394 (let* ((formula-link (org-html-format-latex
2395 latex-frag processing-type)))
2396 (when (and formula-link
2397 (string-match "file:\\([^]]*\\)" formula-link))
2398 (org-html-format-inline-image
2399 (match-string 1 formula-link) caption label attr t))))
2400 (t latex-frag))))
2402 ;;;; Latex Fragment
2404 (defun org-html-latex-fragment (latex-fragment contents info)
2405 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2406 CONTENTS is nil. INFO is a plist holding contextual information."
2407 (let ((latex-frag (org-element-property :value latex-fragment))
2408 (processing-type (plist-get info :with-latex)))
2409 (case processing-type
2410 ((t mathjax)
2411 (org-html-format-latex latex-frag 'mathjax))
2412 (dvipng
2413 (let* ((formula-link (org-html-format-latex
2414 latex-frag processing-type)))
2415 (when (and formula-link
2416 (string-match "file:\\([^]]*\\)" formula-link))
2417 (org-html-format-inline-image
2418 (match-string 1 formula-link)))))
2419 (t latex-frag))))
2421 ;;;; Line Break
2423 (defun org-html-line-break (line-break contents info)
2424 "Transcode a LINE-BREAK object from Org to HTML.
2425 CONTENTS is nil. INFO is a plist holding contextual information."
2426 "<br/>\n")
2428 ;;;; Link
2430 (defun org-html-link--inline-image (link desc info)
2431 "Return HTML code for an inline image.
2433 LINK is the link pointing to the inline image. INFO is a plist
2434 used as a communication channel.
2436 Inline images can have these attributes:
2438 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2439 (let* ((type (org-element-property :type link))
2440 (raw-path (org-element-property :path link))
2441 (path (cond ((member type '("http" "https"))
2442 (concat type ":" raw-path))
2443 ((file-name-absolute-p raw-path)
2444 (expand-file-name raw-path))
2445 (t raw-path)))
2446 (parent (org-export-get-parent-element link))
2447 (caption (org-export-data (org-export-get-caption parent) info))
2448 (label (org-element-property :name parent)))
2449 ;; Return proper string, depending on DISPOSITION.
2450 (org-html-format-inline-image
2451 path caption label
2452 (org-html--make-attribute-string
2453 (org-export-read-attribute :attr_html parent))
2454 (org-html-standalone-image-p link info))))
2456 (defvar org-html-standalone-image-predicate)
2457 (defun org-html-standalone-image-p (element info &optional predicate)
2458 "Test if ELEMENT is a standalone image for the purpose HTML export.
2459 INFO is a plist holding contextual information.
2461 Return non-nil, if ELEMENT is of type paragraph and it's sole
2462 content, save for whitespaces, is a link that qualifies as an
2463 inline image.
2465 Return non-nil, if ELEMENT is of type link and it's containing
2466 paragraph has no other content save for leading and trailing
2467 whitespaces.
2469 Return nil, otherwise.
2471 Bind `org-html-standalone-image-predicate' to constrain
2472 paragraph further. For example, to check for only captioned
2473 standalone images, do the following.
2475 \(setq org-html-standalone-image-predicate
2476 \(lambda \(paragraph\)
2477 \(org-element-property :caption paragraph\)\)\)"
2478 (let ((paragraph (case (org-element-type element)
2479 (paragraph element)
2480 (link (and (org-export-inline-image-p
2481 element org-html-inline-image-rules)
2482 (org-export-get-parent element)))
2483 (t nil))))
2484 (when (eq (org-element-type paragraph) 'paragraph)
2485 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2486 (functionp org-html-standalone-image-predicate)))
2487 (funcall org-html-standalone-image-predicate paragraph))
2488 (let ((contents (org-element-contents paragraph)))
2489 (loop for x in contents
2490 with inline-image-count = 0
2491 always (cond
2492 ((eq (org-element-type x) 'plain-text)
2493 (not (org-string-nw-p x)))
2494 ((eq (org-element-type x) 'link)
2495 (when (org-export-inline-image-p
2496 x org-html-inline-image-rules)
2497 (= (incf inline-image-count) 1)))
2498 (t nil))))))))
2500 (defun org-html-link (link desc info)
2501 "Transcode a LINK object from Org to HTML.
2503 DESC is the description part of the link, or the empty string.
2504 INFO is a plist holding contextual information. See
2505 `org-export-data'."
2506 (let* ((link-org-files-as-html-maybe
2507 (function
2508 (lambda (raw-path info)
2509 "Treat links to `file.org' as links to `file.html', if needed.
2510 See `org-html-link-org-files-as-html'."
2511 (cond
2512 ((and org-html-link-org-files-as-html
2513 (string= ".org"
2514 (downcase (file-name-extension raw-path "."))))
2515 (concat (file-name-sans-extension raw-path) "."
2516 (plist-get info :html-extension)))
2517 (t raw-path)))))
2518 (type (org-element-property :type link))
2519 (raw-path (org-element-property :path link))
2520 ;; Ensure DESC really exists, or set it to nil.
2521 (desc (and (not (string= desc "")) desc))
2522 (path
2523 (cond
2524 ((member type '("http" "https" "ftp" "mailto"))
2525 (concat type ":" raw-path))
2526 ((string= type "file")
2527 ;; Treat links to ".org" files as ".html", if needed.
2528 (setq raw-path
2529 (funcall link-org-files-as-html-maybe raw-path info))
2530 ;; If file path is absolute, prepend it with protocol
2531 ;; component - "file://".
2532 (when (file-name-absolute-p raw-path)
2533 (setq raw-path
2534 (concat "file://" (expand-file-name raw-path))))
2535 ;; Add search option, if any. A search option can be
2536 ;; relative to a custom-id or a headline title. Any other
2537 ;; option is ignored.
2538 (let ((option (org-element-property :search-option link)))
2539 (cond ((not option) raw-path)
2540 ((eq (aref option 0) ?#) (concat raw-path option))
2541 ;; External fuzzy link: try to resolve it if path
2542 ;; belongs to current project, if any.
2543 ((eq (aref option 0) ?*)
2544 (concat
2545 raw-path
2546 (let ((numbers
2547 (org-publish-resolve-external-fuzzy-link
2548 (org-element-property :path link) option)))
2549 (and numbers (concat "#sec-"
2550 (mapconcat 'number-to-string
2551 numbers "-"))))))
2552 (t raw-path))))
2553 (t raw-path)))
2554 ;; Extract attributes from parent's paragraph. HACK: Only do
2555 ;; this for the first link in parent. This is needed as long
2556 ;; as attributes cannot be set on a per link basis.
2557 (attributes
2558 (let ((parent (org-export-get-parent-element link)))
2559 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2561 (let ((att (org-html--make-attribute-string
2562 (org-export-read-attribute :attr_html parent))))
2563 (cond ((not (org-string-nw-p att)) "")
2564 ((and desc (string-match (regexp-quote att) desc)) "")
2565 (t (concat " " att)))))))
2566 protocol)
2567 (cond
2568 ;; Image file.
2569 ((and (or (eq t org-html-inline-images)
2570 (and org-html-inline-images (not desc)))
2571 (org-export-inline-image-p link org-html-inline-image-rules))
2572 (org-html-link--inline-image link desc info))
2573 ;; Radio target: Transcode target's contents and use them as
2574 ;; link's description.
2575 ((string= type "radio")
2576 (let ((destination (org-export-resolve-radio-link link info)))
2577 (when destination
2578 (format "<a href=\"#%s\"%s>%s</a>"
2579 (org-export-solidify-link-text path)
2580 attributes
2581 (org-export-data (org-element-contents destination) info)))))
2582 ;; Links pointing to a headline: Find destination and build
2583 ;; appropriate referencing command.
2584 ((member type '("custom-id" "fuzzy" "id"))
2585 (let ((destination (if (string= type "fuzzy")
2586 (org-export-resolve-fuzzy-link link info)
2587 (org-export-resolve-id-link link info))))
2588 (case (org-element-type destination)
2589 ;; ID link points to an external file.
2590 (plain-text
2591 (let ((fragment (concat "ID-" path))
2592 ;; Treat links to ".org" files as ".html", if needed.
2593 (path (funcall link-org-files-as-html-maybe
2594 destination info)))
2595 (format "<a href=\"%s#%s\"%s>%s</a>"
2596 path fragment attributes (or desc destination))))
2597 ;; Fuzzy link points nowhere.
2598 ((nil)
2599 (format "<i>%s</i>"
2600 (or desc
2601 (org-export-data
2602 (org-element-property :raw-link link) info))))
2603 ;; Fuzzy link points to an invisible target.
2604 (keyword nil)
2605 ;; Link points to a headline.
2606 (headline
2607 (let ((href
2608 ;; What href to use?
2609 (cond
2610 ;; Case 1: Headline is linked via it's CUSTOM_ID
2611 ;; property. Use CUSTOM_ID.
2612 ((string= type "custom-id")
2613 (org-element-property :CUSTOM_ID destination))
2614 ;; Case 2: Headline is linked via it's ID property
2615 ;; or through other means. Use the default href.
2616 ((member type '("id" "fuzzy"))
2617 (format "sec-%s"
2618 (mapconcat 'number-to-string
2619 (org-export-get-headline-number
2620 destination info) "-")))
2621 (t (error "Shouldn't reach here"))))
2622 ;; What description to use?
2623 (desc
2624 ;; Case 1: Headline is numbered and LINK has no
2625 ;; description or LINK's description matches
2626 ;; headline's title. Display section number.
2627 (if (and (org-export-numbered-headline-p destination info)
2628 (or (not desc)
2629 (string= desc (org-element-property
2630 :raw-value destination))))
2631 (mapconcat 'number-to-string
2632 (org-export-get-headline-number
2633 destination info) ".")
2634 ;; Case 2: Either the headline is un-numbered or
2635 ;; LINK has a custom description. Display LINK's
2636 ;; description or headline's title.
2637 (or desc (org-export-data (org-element-property
2638 :title destination) info)))))
2639 (format "<a href=\"#%s\"%s>%s</a>"
2640 (org-export-solidify-link-text href) attributes desc)))
2641 ;; Fuzzy link points to a target. Do as above.
2643 (let ((path (org-export-solidify-link-text path)) number)
2644 (unless desc
2645 (setq number (cond
2646 ((org-html-standalone-image-p destination info)
2647 (org-export-get-ordinal
2648 (assoc 'link (org-element-contents destination))
2649 info 'link 'org-html-standalone-image-p))
2650 (t (org-export-get-ordinal destination info))))
2651 (setq desc (when number
2652 (if (atom number) (number-to-string number)
2653 (mapconcat 'number-to-string number ".")))))
2654 (format "<a href=\"#%s\"%s>%s</a>"
2655 path attributes (or desc "No description for this link")))))))
2656 ;; Coderef: replace link with the reference name or the
2657 ;; equivalent line number.
2658 ((string= type "coderef")
2659 (let ((fragment (concat "coderef-" path)))
2660 (format "<a href=\"#%s\"%s%s>%s</a>"
2661 fragment
2662 (org-trim
2663 (format (concat "class=\"coderef\""
2664 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2665 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2666 fragment fragment))
2667 attributes
2668 (format (org-export-get-coderef-format path desc)
2669 (org-export-resolve-coderef path info)))))
2670 ;; Link type is handled by a special function.
2671 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2672 (funcall protocol (org-link-unescape path) desc 'html))
2673 ;; External link with a description part.
2674 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2675 ;; External link without a description part.
2676 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2677 ;; No path, only description. Try to do something useful.
2678 (t (format "<i>%s</i>" desc)))))
2680 ;;;; Paragraph
2682 (defun org-html-paragraph (paragraph contents info)
2683 "Transcode a PARAGRAPH element from Org to HTML.
2684 CONTENTS is the contents of the paragraph, as a string. INFO is
2685 the plist used as a communication channel."
2686 (let* ((parent (org-export-get-parent paragraph))
2687 (parent-type (org-element-type parent))
2688 (style '((footnote-definition " class=\"footpara\"")))
2689 (extra (or (cadr (assoc parent-type style)) "")))
2690 (cond
2691 ((and (eq (org-element-type parent) 'item)
2692 (= (org-element-property :begin paragraph)
2693 (org-element-property :contents-begin parent)))
2694 ;; leading paragraph in a list item have no tags
2695 contents)
2696 ((org-html-standalone-image-p paragraph info)
2697 ;; standalone image
2698 contents)
2699 (t (format "<p%s>\n%s</p>" extra contents)))))
2701 ;;;; Plain List
2703 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2704 ;; the correct value for the item counter
2705 (defun org-html-begin-plain-list (type &optional arg1)
2706 "Insert the beginning of the HTML list depending on TYPE.
2707 When ARG1 is a string, use it as the start parameter for ordered
2708 lists."
2709 (case type
2710 (ordered
2711 (format "<ol class=\"org-ol\"%s>"
2712 (if arg1 (format " start=\"%d\"" arg1) "")))
2713 (unordered "<ul class=\"org-ul\">")
2714 (descriptive "<dl class=\"org-dl\">")))
2716 (defun org-html-end-plain-list (type)
2717 "Insert the end of the HTML list depending on TYPE."
2718 (case type
2719 (ordered "</ol>")
2720 (unordered "</ul>")
2721 (descriptive "</dl>")))
2723 (defun org-html-plain-list (plain-list contents info)
2724 "Transcode a PLAIN-LIST element from Org to HTML.
2725 CONTENTS is the contents of the list. INFO is a plist holding
2726 contextual information."
2727 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2728 (type (org-element-property :type plain-list)))
2729 (format "%s\n%s%s"
2730 (org-html-begin-plain-list type)
2731 contents (org-html-end-plain-list type))))
2733 ;;;; Plain Text
2735 (defun org-html-convert-special-strings (string)
2736 "Convert special characters in STRING to HTML."
2737 (let ((all org-html-special-string-regexps)
2738 e a re rpl start)
2739 (while (setq a (pop all))
2740 (setq re (car a) rpl (cdr a) start 0)
2741 (while (string-match re string start)
2742 (setq string (replace-match rpl t nil string))))
2743 string))
2745 (defun org-html-encode-plain-text (text)
2746 "Convert plain text characters from TEXT to HTML equivalent.
2747 Possible conversions are set in `org-html-protect-char-alist'."
2748 (mapc
2749 (lambda (pair)
2750 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2751 org-html-protect-char-alist)
2752 text)
2754 (defun org-html-plain-text (text info)
2755 "Transcode a TEXT string from Org to HTML.
2756 TEXT is the string to transcode. INFO is a plist holding
2757 contextual information."
2758 (let ((output text))
2759 ;; Protect following characters: <, >, &.
2760 (setq output (org-html-encode-plain-text output))
2761 ;; Handle smart quotes. Be sure to provide original string since
2762 ;; OUTPUT may have been modified.
2763 (when (plist-get info :with-smart-quotes)
2764 (setq output (org-export-activate-smart-quotes output :html info text)))
2765 ;; Handle special strings.
2766 (when (plist-get info :with-special-strings)
2767 (setq output (org-html-convert-special-strings output)))
2768 ;; Handle break preservation if required.
2769 (when (plist-get info :preserve-breaks)
2770 (setq output
2771 (replace-regexp-in-string
2772 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2773 ;; Return value.
2774 output))
2777 ;; Planning
2779 (defun org-html-planning (planning contents info)
2780 "Transcode a PLANNING element from Org to HTML.
2781 CONTENTS is nil. INFO is a plist used as a communication
2782 channel."
2783 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2784 (format
2785 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2786 (mapconcat
2787 'identity
2788 (delq nil
2789 (list
2790 (let ((closed (org-element-property :closed planning)))
2791 (when closed
2792 (format span-fmt org-closed-string
2793 (org-translate-time
2794 (org-element-property :raw-value closed)))))
2795 (let ((deadline (org-element-property :deadline planning)))
2796 (when deadline
2797 (format span-fmt org-deadline-string
2798 (org-translate-time
2799 (org-element-property :raw-value deadline)))))
2800 (let ((scheduled (org-element-property :scheduled planning)))
2801 (when scheduled
2802 (format span-fmt org-scheduled-string
2803 (org-translate-time
2804 (org-element-property :raw-value scheduled)))))))
2805 " "))))
2807 ;;;; Property Drawer
2809 (defun org-html-property-drawer (property-drawer contents info)
2810 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2811 CONTENTS is nil. INFO is a plist holding contextual
2812 information."
2813 ;; The property drawer isn't exported but we want separating blank
2814 ;; lines nonetheless.
2817 ;;;; Quote Block
2819 (defun org-html-quote-block (quote-block contents info)
2820 "Transcode a QUOTE-BLOCK element from Org to HTML.
2821 CONTENTS holds the contents of the block. INFO is a plist
2822 holding contextual information."
2823 (format "<blockquote>\n%s</blockquote>" contents))
2825 ;;;; Quote Section
2827 (defun org-html-quote-section (quote-section contents info)
2828 "Transcode a QUOTE-SECTION element from Org to HTML.
2829 CONTENTS is nil. INFO is a plist holding contextual information."
2830 (let ((value (org-remove-indentation
2831 (org-element-property :value quote-section))))
2832 (when value (format "<pre>\n%s</pre>" value))))
2834 ;;;; Section
2836 (defun org-html-section (section contents info)
2837 "Transcode a SECTION element from Org to HTML.
2838 CONTENTS holds the contents of the section. INFO is a plist
2839 holding contextual information."
2840 (let ((parent (org-export-get-parent-headline section)))
2841 ;; Before first headline: no container, just return CONTENTS.
2842 (if (not parent) contents
2843 ;; Get div's class and id references.
2844 (let* ((class-num (+ (org-export-get-relative-level parent info)
2845 (1- org-html-toplevel-hlevel)))
2846 (section-number
2847 (mapconcat
2848 'number-to-string
2849 (org-export-get-headline-number parent info) "-")))
2850 ;; Build return value.
2851 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2852 class-num
2853 (or (org-element-property :CUSTOM_ID parent) section-number)
2854 contents)))))
2856 ;;;; Radio Target
2858 (defun org-html-radio-target (radio-target text info)
2859 "Transcode a RADIO-TARGET object from Org to HTML.
2860 TEXT is the text of the target. INFO is a plist holding
2861 contextual information."
2862 (let ((id (org-export-solidify-link-text
2863 (org-element-property :value radio-target))))
2864 (org-html--anchor id text)))
2866 ;;;; Special Block
2868 (defun org-html-special-block (special-block contents info)
2869 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2870 CONTENTS holds the contents of the block. INFO is a plist
2871 holding contextual information."
2872 (format "<div class=\"%s\">\n%s\n</div>"
2873 (downcase (org-element-property :type special-block))
2874 contents))
2876 ;;;; Src Block
2878 (defun org-html-src-block (src-block contents info)
2879 "Transcode a SRC-BLOCK element from Org to HTML.
2880 CONTENTS holds the contents of the item. INFO is a plist holding
2881 contextual information."
2882 (if (org-export-read-attribute :attr_html src-block :textarea)
2883 (org-html--textarea-block src-block)
2884 (let ((lang (org-element-property :language src-block))
2885 (caption (org-export-get-caption src-block))
2886 (code (org-html-format-code src-block info))
2887 (label (let ((lbl (org-element-property :name src-block)))
2888 (if (not lbl) ""
2889 (format " id=\"%s\""
2890 (org-export-solidify-link-text lbl))))))
2891 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2892 (format
2893 "<div class=\"org-src-container\">\n%s%s\n</div>"
2894 (if (not caption) ""
2895 (format "<label class=\"org-src-name\">%s</label>"
2896 (org-export-data caption info)))
2897 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2899 ;;;; Statistics Cookie
2901 (defun org-html-statistics-cookie (statistics-cookie contents info)
2902 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2903 CONTENTS is nil. INFO is a plist holding contextual information."
2904 (let ((cookie-value (org-element-property :value statistics-cookie)))
2905 (format "<code>%s</code>" cookie-value)))
2907 ;;;; Strike-Through
2909 (defun org-html-strike-through (strike-through contents info)
2910 "Transcode STRIKE-THROUGH from Org to HTML.
2911 CONTENTS is the text with strike-through markup. INFO is a plist
2912 holding contextual information."
2913 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2914 contents))
2916 ;;;; Subscript
2918 (defun org-html-subscript (subscript contents info)
2919 "Transcode a SUBSCRIPT object from Org to HTML.
2920 CONTENTS is the contents of the object. INFO is a plist holding
2921 contextual information."
2922 (format "<sub>%s</sub>" contents))
2924 ;;;; Superscript
2926 (defun org-html-superscript (superscript contents info)
2927 "Transcode a SUPERSCRIPT object from Org to HTML.
2928 CONTENTS is the contents of the object. INFO is a plist holding
2929 contextual information."
2930 (format "<sup>%s</sup>" contents))
2932 ;;;; Tabel Cell
2934 (defun org-html-table-cell (table-cell contents info)
2935 "Transcode a TABLE-CELL element from Org to HTML.
2936 CONTENTS is nil. INFO is a plist used as a communication
2937 channel."
2938 (let* ((table-row (org-export-get-parent table-cell))
2939 (table (org-export-get-parent-table table-cell))
2940 (cell-attrs
2941 (if (not org-html-table-align-individual-fields) ""
2942 (format (if (and (boundp 'org-html-format-table-no-css)
2943 org-html-format-table-no-css)
2944 " align=\"%s\"" " class=\"%s\"")
2945 (org-export-table-cell-alignment table-cell info)))))
2946 (when (or (not contents) (string= "" (org-trim contents)))
2947 (setq contents "&#xa0;"))
2948 (cond
2949 ((and (org-export-table-has-header-p table info)
2950 (= 1 (org-export-table-row-group table-row info)))
2951 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2952 contents (cdr org-html-table-header-tags)))
2953 ((and org-html-table-use-header-tags-for-first-column
2954 (zerop (cdr (org-export-table-cell-address table-cell info))))
2955 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2956 contents (cdr org-html-table-header-tags)))
2957 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2958 contents (cdr org-html-table-data-tags))))))
2960 ;;;; Table Row
2962 (defun org-html-table-row (table-row contents info)
2963 "Transcode a TABLE-ROW element from Org to HTML.
2964 CONTENTS is the contents of the row. INFO is a plist used as a
2965 communication channel."
2966 ;; Rules are ignored since table separators are deduced from
2967 ;; borders of the current row.
2968 (when (eq (org-element-property :type table-row) 'standard)
2969 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2970 (row-number (org-export-table-row-number table-row info))
2971 (start-rowgroup-p
2972 (org-export-table-row-starts-rowgroup-p table-row info))
2973 (end-rowgroup-p
2974 (org-export-table-row-ends-rowgroup-p table-row info))
2975 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2976 ;; but should be set so that `org-html-table-row-tags' can
2977 ;; use them (see the docstring of this variable.)
2978 (top-row-p (and (equal start-rowgroup-p '(top))
2979 (equal end-rowgroup-p '(below top))))
2980 (bottom-row-p (and (equal start-rowgroup-p '(above))
2981 (equal end-rowgroup-p '(bottom above))))
2982 (rowgroup-tags
2983 (cond
2984 ;; Case 1: Row belongs to second or subsequent rowgroups.
2985 ((not (= 1 rowgroup-number))
2986 '("<tbody>" . "\n</tbody>"))
2987 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2988 ((org-export-table-has-header-p
2989 (org-export-get-parent-table table-row) info)
2990 '("<thead>" . "\n</thead>"))
2991 ;; Case 2: Row is from first and only row group.
2992 (t '("<tbody>" . "\n</tbody>")))))
2993 (concat
2994 ;; Begin a rowgroup?
2995 (when start-rowgroup-p (car rowgroup-tags))
2996 ;; Actual table row
2997 (concat "\n" (eval (car org-html-table-row-tags))
2998 contents
2999 "\n"
3000 (eval (cdr org-html-table-row-tags)))
3001 ;; End a rowgroup?
3002 (when end-rowgroup-p (cdr rowgroup-tags))))))
3004 ;;;; Table
3006 (defun org-html-table-first-row-data-cells (table info)
3007 "Transcode the first row of TABLE.
3008 INFO is a plist used as a communication channel."
3009 (let ((table-row
3010 (org-element-map table 'table-row
3011 (lambda (row)
3012 (unless (eq (org-element-property :type row) 'rule) row))
3013 info 'first-match))
3014 (special-column-p (org-export-table-has-special-column-p table)))
3015 (if (not special-column-p) (org-element-contents table-row)
3016 (cdr (org-element-contents table-row)))))
3018 (defun org-html-table--table.el-table (table info)
3019 "Format table.el tables into HTML.
3020 INFO is a plist used as a communication channel."
3021 (when (eq (org-element-property :type table) 'table.el)
3022 (require 'table)
3023 (let ((outbuf (with-current-buffer
3024 (get-buffer-create "*org-export-table*")
3025 (erase-buffer) (current-buffer))))
3026 (with-temp-buffer
3027 (insert (org-element-property :value table))
3028 (goto-char 1)
3029 (re-search-forward "^[ \t]*|[^|]" nil t)
3030 (table-generate-source 'html outbuf))
3031 (with-current-buffer outbuf
3032 (prog1 (org-trim (buffer-string))
3033 (kill-buffer) )))))
3035 (defun org-html-table (table contents info)
3036 "Transcode a TABLE element from Org to HTML.
3037 CONTENTS is the contents of the table. INFO is a plist holding
3038 contextual information."
3039 (case (org-element-property :type table)
3040 ;; Case 1: table.el table. Convert it using appropriate tools.
3041 (table.el (org-html-table--table.el-table table info))
3042 ;; Case 2: Standard table.
3044 (let* ((label (org-element-property :name table))
3045 (caption (org-export-get-caption table))
3046 (attributes
3047 (org-html--make-attribute-string
3048 (org-combine-plists
3049 (and label (list :id (org-export-solidify-link-text label)))
3050 (plist-get info :html-table-attributes)
3051 (org-export-read-attribute :attr_html table))))
3052 (alignspec
3053 (if (and (boundp 'org-html-format-table-no-css)
3054 org-html-format-table-no-css)
3055 "align=\"%s\"" "class=\"%s\""))
3056 (table-column-specs
3057 (function
3058 (lambda (table info)
3059 (mapconcat
3060 (lambda (table-cell)
3061 (let ((alignment (org-export-table-cell-alignment
3062 table-cell info)))
3063 (concat
3064 ;; Begin a colgroup?
3065 (when (org-export-table-cell-starts-colgroup-p
3066 table-cell info)
3067 "\n<colgroup>")
3068 ;; Add a column. Also specify it's alignment.
3069 (format "\n<col %s/>" (format alignspec alignment))
3070 ;; End a colgroup?
3071 (when (org-export-table-cell-ends-colgroup-p
3072 table-cell info)
3073 "\n</colgroup>"))))
3074 (org-html-table-first-row-data-cells table info) "\n")))))
3075 (format "<table%s>\n%s\n%s\n%s</table>"
3076 (if (equal attributes "") "" (concat " " attributes))
3077 (if (not caption) ""
3078 (format "<caption>%s</caption>"
3079 (org-export-data caption info)))
3080 (funcall table-column-specs table info)
3081 contents)))))
3083 ;;;; Target
3085 (defun org-html-target (target contents info)
3086 "Transcode a TARGET object from Org to HTML.
3087 CONTENTS is nil. INFO is a plist holding contextual
3088 information."
3089 (let ((id (org-export-solidify-link-text
3090 (org-element-property :value target))))
3091 (org-html--anchor id)))
3093 ;;;; Timestamp
3095 (defun org-html-timestamp (timestamp contents info)
3096 "Transcode a TIMESTAMP object from Org to HTML.
3097 CONTENTS is nil. INFO is a plist holding contextual
3098 information."
3099 (let ((value (org-html-plain-text
3100 (org-timestamp-translate timestamp) info)))
3101 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3102 (replace-regexp-in-string "--" "&#x2013;" value))))
3104 ;;;; Underline
3106 (defun org-html-underline (underline contents info)
3107 "Transcode UNDERLINE from Org to HTML.
3108 CONTENTS is the text with underline markup. INFO is a plist
3109 holding contextual information."
3110 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3111 contents))
3113 ;;;; Verbatim
3115 (defun org-html-verbatim (verbatim contents info)
3116 "Transcode VERBATIM from Org to HTML.
3117 CONTENTS is nil. INFO is a plist holding contextual
3118 information."
3119 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3120 (org-html-plain-text (org-element-property :value verbatim) info)))
3122 ;;;; Verse Block
3124 (defun org-html-verse-block (verse-block contents info)
3125 "Transcode a VERSE-BLOCK element from Org to HTML.
3126 CONTENTS is verse block contents. INFO is a plist holding
3127 contextual information."
3128 ;; Replace each newline character with line break. Also replace
3129 ;; each blank line with a line break.
3130 (setq contents (replace-regexp-in-string
3131 "^ *\\\\\\\\$" "<br/>\n"
3132 (replace-regexp-in-string
3133 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3134 ;; Replace each white space at beginning of a line with a
3135 ;; non-breaking space.
3136 (while (string-match "^[ \t]+" contents)
3137 (let* ((num-ws (length (match-string 0 contents)))
3138 (ws (let (out) (dotimes (i num-ws out)
3139 (setq out (concat out "&#xa0;"))))))
3140 (setq contents (replace-match ws nil t contents))))
3141 (format "<p class=\"verse\">\n%s</p>" contents))
3144 ;;; Filter Functions
3146 (defun org-html-final-function (contents backend info)
3147 "Filter to indent the HTML and convert HTML entities."
3148 (with-temp-buffer
3149 (insert contents)
3150 (set-auto-mode t)
3151 (if org-html-indent
3152 (indent-region (point-min) (point-max)))
3153 (when org-html-use-unicode-chars
3154 (require 'mm-url)
3155 (mm-url-decode-entities))
3156 (buffer-substring-no-properties (point-min) (point-max))))
3159 ;;; End-user functions
3161 ;;;###autoload
3162 (defun org-html-export-as-html
3163 (&optional async subtreep visible-only body-only ext-plist)
3164 "Export current buffer to an HTML buffer.
3166 If narrowing is active in the current buffer, only export its
3167 narrowed part.
3169 If a region is active, export that region.
3171 A non-nil optional argument ASYNC means the process should happen
3172 asynchronously. The resulting buffer should be accessible
3173 through the `org-export-stack' interface.
3175 When optional argument SUBTREEP is non-nil, export the sub-tree
3176 at point, extracting information from the headline properties
3177 first.
3179 When optional argument VISIBLE-ONLY is non-nil, don't export
3180 contents of hidden elements.
3182 When optional argument BODY-ONLY is non-nil, only write code
3183 between \"<body>\" and \"</body>\" tags.
3185 EXT-PLIST, when provided, is a property list with external
3186 parameters overriding Org default settings, but still inferior to
3187 file-local settings.
3189 Export is done in a buffer named \"*Org HTML Export*\", which
3190 will be displayed when `org-export-show-temporary-export-buffer'
3191 is non-nil."
3192 (interactive)
3193 (if async
3194 (org-export-async-start
3195 (lambda (output)
3196 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3197 (erase-buffer)
3198 (insert output)
3199 (goto-char (point-min))
3200 (set-auto-mode t)
3201 (org-export-add-to-stack (current-buffer) 'html)))
3202 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3203 (let ((outbuf (org-export-to-buffer
3204 'html "*Org HTML Export*"
3205 subtreep visible-only body-only ext-plist)))
3206 ;; Set major mode.
3207 (with-current-buffer outbuf (set-auto-mode t))
3208 (when org-export-show-temporary-export-buffer
3209 (switch-to-buffer-other-window outbuf)))))
3211 ;;;###autoload
3212 (defun org-html-convert-region-to-html ()
3213 "Assume the current region has org-mode syntax, and convert it to HTML.
3214 This can be used in any buffer. For example, you can write an
3215 itemized list in org-mode syntax in an HTML buffer and use this
3216 command to convert it."
3217 (interactive)
3218 (org-export-replace-region-by 'html))
3220 ;;;###autoload
3221 (defun org-html-export-to-html
3222 (&optional async subtreep visible-only body-only ext-plist)
3223 "Export current buffer to a HTML file.
3225 If narrowing is active in the current buffer, only export its
3226 narrowed part.
3228 If a region is active, export that region.
3230 A non-nil optional argument ASYNC means the process should happen
3231 asynchronously. The resulting file should be accessible through
3232 the `org-export-stack' interface.
3234 When optional argument SUBTREEP is non-nil, export the sub-tree
3235 at point, extracting information from the headline properties
3236 first.
3238 When optional argument VISIBLE-ONLY is non-nil, don't export
3239 contents of hidden elements.
3241 When optional argument BODY-ONLY is non-nil, only write code
3242 between \"<body>\" and \"</body>\" tags.
3244 EXT-PLIST, when provided, is a property list with external
3245 parameters overriding Org default settings, but still inferior to
3246 file-local settings.
3248 Return output file's name."
3249 (interactive)
3250 (let* ((extension (concat "." org-html-extension))
3251 (file (org-export-output-file-name extension subtreep))
3252 (org-export-coding-system org-html-coding-system))
3253 (if async
3254 (org-export-async-start
3255 (lambda (f) (org-export-add-to-stack f 'html))
3256 (let ((org-export-coding-system org-html-coding-system))
3257 `(expand-file-name
3258 (org-export-to-file
3259 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3260 (let ((org-export-coding-system org-html-coding-system))
3261 (org-export-to-file
3262 'html file subtreep visible-only body-only ext-plist)))))
3264 ;;;###autoload
3265 (defun org-html-publish-to-html (plist filename pub-dir)
3266 "Publish an org file to HTML.
3268 FILENAME is the filename of the Org file to be published. PLIST
3269 is the property list for the given project. PUB-DIR is the
3270 publishing directory.
3272 Return output file name."
3273 (org-publish-org-to 'html filename
3274 (concat "." (or (plist-get plist :html-extension)
3275 org-html-extension "html"))
3276 plist pub-dir))
3279 ;;; FIXME
3281 ;;;; org-format-table-html
3282 ;;;; org-format-org-table-html
3283 ;;;; org-format-table-table-html
3284 ;;;; org-table-number-fraction
3285 ;;;; org-table-number-regexp
3286 ;;;; org-html-table-caption-above
3287 ;;;; org-html-inline-image-extensions
3288 ;;;; org-export-preferred-target-alist
3289 ;;;; class for anchors
3290 ;;;; org-export-mark-todo-in-toc
3291 ;;;; org-html-format-org-link
3292 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3293 ;;;; alt = (file-name-nondirectory path)
3295 (provide 'ox-html)
3297 ;; Local variables:
3298 ;; generated-autoload-file: "org-loaddefs.el"
3299 ;; End:
3301 ;;; ox-html.el ends here