Allow setting :HTML_CONTAINER as a per-headline property.
[org-mode.git] / lisp / ox-html.el
blobcfb83abf9b16aa5f590f80688b2c143386105ce3
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 (org-html--container headline info)
2204 (format "outline-container-%s"
2205 (or (org-element-property :CUSTOM_ID headline)
2206 (concat "sec-" section-number)))
2207 (concat (format "outline-%d" level1) (and extra-class " ")
2208 extra-class)
2209 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2210 level1
2211 preferred-id
2212 (mapconcat
2213 (lambda (x)
2214 (let ((id (org-export-solidify-link-text
2215 (if (org-uuidgen-p x) (concat "ID-" x)
2216 x))))
2217 (org-html--anchor id)))
2218 extra-ids "")
2219 full-text
2220 level1)
2221 ;; When there is no section, pretend there is an empty
2222 ;; one to get the correct <div class="outline- ...>
2223 ;; which is needed by `org-info.js'.
2224 (if (not (eq (org-element-type first-content) 'section))
2225 (concat (org-html-section first-content "" info)
2226 contents)
2227 contents)
2228 (org-html--container headline info)))))))
2230 (defun org-html--container (headline info)
2231 (or (org-element-property :HTML_CONTAINER headline)
2232 (if (= 1 (org-export-get-relative-level headline info))
2233 (plist-get info :html-container)
2234 "div")))
2236 ;;;; Horizontal Rule
2238 (defun org-html-horizontal-rule (horizontal-rule contents info)
2239 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2240 CONTENTS is nil. INFO is a plist holding contextual information."
2241 "<hr/>")
2243 ;;;; Inline Src Block
2245 (defun org-html-inline-src-block (inline-src-block contents info)
2246 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2247 CONTENTS holds the contents of the item. INFO is a plist holding
2248 contextual information."
2249 (let* ((org-lang (org-element-property :language inline-src-block))
2250 (code (org-element-property :value inline-src-block)))
2251 (error "Cannot export inline src block")))
2253 ;;;; Inlinetask
2255 (defun org-html-format-section (text class &optional id)
2256 "Format a section with TEXT into a HTML div with CLASS and ID."
2257 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2258 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2260 (defun org-html-inlinetask (inlinetask contents info)
2261 "Transcode an INLINETASK element from Org to HTML.
2262 CONTENTS holds the contents of the block. INFO is a plist
2263 holding contextual information."
2264 (cond
2265 ;; If `org-html-format-inlinetask-function' is provided, call it
2266 ;; with appropriate arguments.
2267 ((functionp org-html-format-inlinetask-function)
2268 (let ((format-function
2269 (function*
2270 (lambda (todo todo-type priority text tags
2271 &key contents &allow-other-keys)
2272 (funcall org-html-format-inlinetask-function
2273 todo todo-type priority text tags contents)))))
2274 (org-html-format-headline--wrap
2275 inlinetask info format-function :contents contents)))
2276 ;; Otherwise, use a default template.
2277 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2278 (org-html-format-headline--wrap inlinetask info)
2279 contents))))
2281 ;;;; Italic
2283 (defun org-html-italic (italic contents info)
2284 "Transcode ITALIC from Org to HTML.
2285 CONTENTS is the text with italic markup. INFO is a plist holding
2286 contextual information."
2287 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2289 ;;;; Item
2291 (defun org-html-checkbox (checkbox)
2292 "Format CHECKBOX into HTML."
2293 (case checkbox (on "<code>[X]</code>")
2294 (off "<code>[&#xa0;]</code>")
2295 (trans "<code>[-]</code>")
2296 (t "")))
2298 (defun org-html-format-list-item (contents type checkbox
2299 &optional term-counter-id
2300 headline)
2301 "Format a list item into HTML."
2302 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2303 (concat
2304 (case type
2305 (ordered
2306 (let* ((counter term-counter-id)
2307 (extra (if counter (format " value=\"%s\"" counter) "")))
2308 (concat
2309 (format "<li%s>" extra)
2310 (when headline (concat headline "<br/>")))))
2311 (unordered
2312 (let* ((id term-counter-id)
2313 (extra (if id (format " id=\"%s\"" id) "")))
2314 (concat
2315 (format "<li%s>" extra)
2316 (when headline (concat headline "<br/>")))))
2317 (descriptive
2318 (let* ((term term-counter-id))
2319 (setq term (or term "(no term)"))
2320 ;; Check-boxes in descriptive lists are associated to tag.
2321 (concat (format "<dt> %s </dt>"
2322 (concat checkbox term))
2323 "<dd>"))))
2324 (unless (eq type 'descriptive) checkbox)
2325 contents
2326 (case type
2327 (ordered "</li>")
2328 (unordered "</li>")
2329 (descriptive "</dd>")))))
2331 (defun org-html-item (item contents info)
2332 "Transcode an ITEM element from Org to HTML.
2333 CONTENTS holds the contents of the item. INFO is a plist holding
2334 contextual information."
2335 (let* ((plain-list (org-export-get-parent item))
2336 (type (org-element-property :type plain-list))
2337 (counter (org-element-property :counter item))
2338 (checkbox (org-element-property :checkbox item))
2339 (tag (let ((tag (org-element-property :tag item)))
2340 (and tag (org-export-data tag info)))))
2341 (org-html-format-list-item
2342 contents type checkbox (or tag counter))))
2344 ;;;; Keyword
2346 (defun org-html-keyword (keyword contents info)
2347 "Transcode a KEYWORD element from Org to HTML.
2348 CONTENTS is nil. INFO is a plist holding contextual information."
2349 (let ((key (org-element-property :key keyword))
2350 (value (org-element-property :value keyword)))
2351 (cond
2352 ((string= key "HTML") value)
2353 ((string= key "TOC")
2354 (let ((value (downcase value)))
2355 (cond
2356 ((string-match "\\<headlines\\>" value)
2357 (let ((depth (or (and (string-match "[0-9]+" value)
2358 (string-to-number (match-string 0 value)))
2359 (plist-get info :with-toc))))
2360 (org-html-toc depth info)))
2361 ((string= "listings" value) (org-html-list-of-listings info))
2362 ((string= "tables" value) (org-html-list-of-tables info))))))))
2364 ;;;; Latex Environment
2366 (defun org-html-format-latex (latex-frag processing-type)
2367 "Format the LaTeX fragment LATEX-FRAG into HTML."
2368 (let ((cache-relpath "") (cache-dir "") bfn)
2369 (unless (eq processing-type 'mathjax)
2370 (setq bfn (buffer-file-name)
2371 cache-relpath
2372 (concat "ltxpng/"
2373 (file-name-sans-extension
2374 (file-name-nondirectory bfn)))
2375 cache-dir (file-name-directory bfn)))
2376 (with-temp-buffer
2377 (insert latex-frag)
2378 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2379 nil nil processing-type)
2380 (buffer-string))))
2382 (defun org-html-latex-environment (latex-environment contents info)
2383 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2384 CONTENTS is nil. INFO is a plist holding contextual information."
2385 (let ((processing-type (plist-get info :with-latex))
2386 (latex-frag (org-remove-indentation
2387 (org-element-property :value latex-environment)))
2388 (caption (org-export-data
2389 (org-export-get-caption latex-environment) info))
2390 (attr nil) ; FIXME
2391 (label (org-element-property :name latex-environment)))
2392 (cond
2393 ((memq processing-type '(t mathjax))
2394 (org-html-format-latex latex-frag 'mathjax))
2395 ((eq processing-type 'dvipng)
2396 (let* ((formula-link (org-html-format-latex
2397 latex-frag processing-type)))
2398 (when (and formula-link
2399 (string-match "file:\\([^]]*\\)" formula-link))
2400 (org-html-format-inline-image
2401 (match-string 1 formula-link) caption label attr t))))
2402 (t latex-frag))))
2404 ;;;; Latex Fragment
2406 (defun org-html-latex-fragment (latex-fragment contents info)
2407 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2408 CONTENTS is nil. INFO is a plist holding contextual information."
2409 (let ((latex-frag (org-element-property :value latex-fragment))
2410 (processing-type (plist-get info :with-latex)))
2411 (case processing-type
2412 ((t mathjax)
2413 (org-html-format-latex latex-frag 'mathjax))
2414 (dvipng
2415 (let* ((formula-link (org-html-format-latex
2416 latex-frag processing-type)))
2417 (when (and formula-link
2418 (string-match "file:\\([^]]*\\)" formula-link))
2419 (org-html-format-inline-image
2420 (match-string 1 formula-link)))))
2421 (t latex-frag))))
2423 ;;;; Line Break
2425 (defun org-html-line-break (line-break contents info)
2426 "Transcode a LINE-BREAK object from Org to HTML.
2427 CONTENTS is nil. INFO is a plist holding contextual information."
2428 "<br/>\n")
2430 ;;;; Link
2432 (defun org-html-link--inline-image (link desc info)
2433 "Return HTML code for an inline image.
2435 LINK is the link pointing to the inline image. INFO is a plist
2436 used as a communication channel.
2438 Inline images can have these attributes:
2440 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2441 (let* ((type (org-element-property :type link))
2442 (raw-path (org-element-property :path link))
2443 (path (cond ((member type '("http" "https"))
2444 (concat type ":" raw-path))
2445 ((file-name-absolute-p raw-path)
2446 (expand-file-name raw-path))
2447 (t raw-path)))
2448 (parent (org-export-get-parent-element link))
2449 (caption (org-export-data (org-export-get-caption parent) info))
2450 (label (org-element-property :name parent)))
2451 ;; Return proper string, depending on DISPOSITION.
2452 (org-html-format-inline-image
2453 path caption label
2454 (org-html--make-attribute-string
2455 (org-export-read-attribute :attr_html parent))
2456 (org-html-standalone-image-p link info))))
2458 (defvar org-html-standalone-image-predicate)
2459 (defun org-html-standalone-image-p (element info &optional predicate)
2460 "Test if ELEMENT is a standalone image for the purpose HTML export.
2461 INFO is a plist holding contextual information.
2463 Return non-nil, if ELEMENT is of type paragraph and it's sole
2464 content, save for whitespaces, is a link that qualifies as an
2465 inline image.
2467 Return non-nil, if ELEMENT is of type link and it's containing
2468 paragraph has no other content save for leading and trailing
2469 whitespaces.
2471 Return nil, otherwise.
2473 Bind `org-html-standalone-image-predicate' to constrain
2474 paragraph further. For example, to check for only captioned
2475 standalone images, do the following.
2477 \(setq org-html-standalone-image-predicate
2478 \(lambda \(paragraph\)
2479 \(org-element-property :caption paragraph\)\)\)"
2480 (let ((paragraph (case (org-element-type element)
2481 (paragraph element)
2482 (link (and (org-export-inline-image-p
2483 element org-html-inline-image-rules)
2484 (org-export-get-parent element)))
2485 (t nil))))
2486 (when (eq (org-element-type paragraph) 'paragraph)
2487 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2488 (functionp org-html-standalone-image-predicate)))
2489 (funcall org-html-standalone-image-predicate paragraph))
2490 (let ((contents (org-element-contents paragraph)))
2491 (loop for x in contents
2492 with inline-image-count = 0
2493 always (cond
2494 ((eq (org-element-type x) 'plain-text)
2495 (not (org-string-nw-p x)))
2496 ((eq (org-element-type x) 'link)
2497 (when (org-export-inline-image-p
2498 x org-html-inline-image-rules)
2499 (= (incf inline-image-count) 1)))
2500 (t nil))))))))
2502 (defun org-html-link (link desc info)
2503 "Transcode a LINK object from Org to HTML.
2505 DESC is the description part of the link, or the empty string.
2506 INFO is a plist holding contextual information. See
2507 `org-export-data'."
2508 (let* ((link-org-files-as-html-maybe
2509 (function
2510 (lambda (raw-path info)
2511 "Treat links to `file.org' as links to `file.html', if needed.
2512 See `org-html-link-org-files-as-html'."
2513 (cond
2514 ((and org-html-link-org-files-as-html
2515 (string= ".org"
2516 (downcase (file-name-extension raw-path "."))))
2517 (concat (file-name-sans-extension raw-path) "."
2518 (plist-get info :html-extension)))
2519 (t raw-path)))))
2520 (type (org-element-property :type link))
2521 (raw-path (org-element-property :path link))
2522 ;; Ensure DESC really exists, or set it to nil.
2523 (desc (and (not (string= desc "")) desc))
2524 (path
2525 (cond
2526 ((member type '("http" "https" "ftp" "mailto"))
2527 (concat type ":" raw-path))
2528 ((string= type "file")
2529 ;; Treat links to ".org" files as ".html", if needed.
2530 (setq raw-path
2531 (funcall link-org-files-as-html-maybe raw-path info))
2532 ;; If file path is absolute, prepend it with protocol
2533 ;; component - "file://".
2534 (when (file-name-absolute-p raw-path)
2535 (setq raw-path
2536 (concat "file://" (expand-file-name raw-path))))
2537 ;; Add search option, if any. A search option can be
2538 ;; relative to a custom-id or a headline title. Any other
2539 ;; option is ignored.
2540 (let ((option (org-element-property :search-option link)))
2541 (cond ((not option) raw-path)
2542 ((eq (aref option 0) ?#) (concat raw-path option))
2543 ;; External fuzzy link: try to resolve it if path
2544 ;; belongs to current project, if any.
2545 ((eq (aref option 0) ?*)
2546 (concat
2547 raw-path
2548 (let ((numbers
2549 (org-publish-resolve-external-fuzzy-link
2550 (org-element-property :path link) option)))
2551 (and numbers (concat "#sec-"
2552 (mapconcat 'number-to-string
2553 numbers "-"))))))
2554 (t raw-path))))
2555 (t raw-path)))
2556 ;; Extract attributes from parent's paragraph. HACK: Only do
2557 ;; this for the first link in parent. This is needed as long
2558 ;; as attributes cannot be set on a per link basis.
2559 (attributes
2560 (let ((parent (org-export-get-parent-element link)))
2561 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2563 (let ((att (org-html--make-attribute-string
2564 (org-export-read-attribute :attr_html parent))))
2565 (cond ((not (org-string-nw-p att)) "")
2566 ((and desc (string-match (regexp-quote att) desc)) "")
2567 (t (concat " " att)))))))
2568 protocol)
2569 (cond
2570 ;; Image file.
2571 ((and (or (eq t org-html-inline-images)
2572 (and org-html-inline-images (not desc)))
2573 (org-export-inline-image-p link org-html-inline-image-rules))
2574 (org-html-link--inline-image link desc info))
2575 ;; Radio target: Transcode target's contents and use them as
2576 ;; link's description.
2577 ((string= type "radio")
2578 (let ((destination (org-export-resolve-radio-link link info)))
2579 (when destination
2580 (format "<a href=\"#%s\"%s>%s</a>"
2581 (org-export-solidify-link-text path)
2582 attributes
2583 (org-export-data (org-element-contents destination) info)))))
2584 ;; Links pointing to a headline: Find destination and build
2585 ;; appropriate referencing command.
2586 ((member type '("custom-id" "fuzzy" "id"))
2587 (let ((destination (if (string= type "fuzzy")
2588 (org-export-resolve-fuzzy-link link info)
2589 (org-export-resolve-id-link link info))))
2590 (case (org-element-type destination)
2591 ;; ID link points to an external file.
2592 (plain-text
2593 (let ((fragment (concat "ID-" path))
2594 ;; Treat links to ".org" files as ".html", if needed.
2595 (path (funcall link-org-files-as-html-maybe
2596 destination info)))
2597 (format "<a href=\"%s#%s\"%s>%s</a>"
2598 path fragment attributes (or desc destination))))
2599 ;; Fuzzy link points nowhere.
2600 ((nil)
2601 (format "<i>%s</i>"
2602 (or desc
2603 (org-export-data
2604 (org-element-property :raw-link link) info))))
2605 ;; Fuzzy link points to an invisible target.
2606 (keyword nil)
2607 ;; Link points to a headline.
2608 (headline
2609 (let ((href
2610 ;; What href to use?
2611 (cond
2612 ;; Case 1: Headline is linked via it's CUSTOM_ID
2613 ;; property. Use CUSTOM_ID.
2614 ((string= type "custom-id")
2615 (org-element-property :CUSTOM_ID destination))
2616 ;; Case 2: Headline is linked via it's ID property
2617 ;; or through other means. Use the default href.
2618 ((member type '("id" "fuzzy"))
2619 (format "sec-%s"
2620 (mapconcat 'number-to-string
2621 (org-export-get-headline-number
2622 destination info) "-")))
2623 (t (error "Shouldn't reach here"))))
2624 ;; What description to use?
2625 (desc
2626 ;; Case 1: Headline is numbered and LINK has no
2627 ;; description or LINK's description matches
2628 ;; headline's title. Display section number.
2629 (if (and (org-export-numbered-headline-p destination info)
2630 (or (not desc)
2631 (string= desc (org-element-property
2632 :raw-value destination))))
2633 (mapconcat 'number-to-string
2634 (org-export-get-headline-number
2635 destination info) ".")
2636 ;; Case 2: Either the headline is un-numbered or
2637 ;; LINK has a custom description. Display LINK's
2638 ;; description or headline's title.
2639 (or desc (org-export-data (org-element-property
2640 :title destination) info)))))
2641 (format "<a href=\"#%s\"%s>%s</a>"
2642 (org-export-solidify-link-text href) attributes desc)))
2643 ;; Fuzzy link points to a target. Do as above.
2645 (let ((path (org-export-solidify-link-text path)) number)
2646 (unless desc
2647 (setq number (cond
2648 ((org-html-standalone-image-p destination info)
2649 (org-export-get-ordinal
2650 (assoc 'link (org-element-contents destination))
2651 info 'link 'org-html-standalone-image-p))
2652 (t (org-export-get-ordinal destination info))))
2653 (setq desc (when number
2654 (if (atom number) (number-to-string number)
2655 (mapconcat 'number-to-string number ".")))))
2656 (format "<a href=\"#%s\"%s>%s</a>"
2657 path attributes (or desc "No description for this link")))))))
2658 ;; Coderef: replace link with the reference name or the
2659 ;; equivalent line number.
2660 ((string= type "coderef")
2661 (let ((fragment (concat "coderef-" path)))
2662 (format "<a href=\"#%s\"%s%s>%s</a>"
2663 fragment
2664 (org-trim
2665 (format (concat "class=\"coderef\""
2666 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2667 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2668 fragment fragment))
2669 attributes
2670 (format (org-export-get-coderef-format path desc)
2671 (org-export-resolve-coderef path info)))))
2672 ;; Link type is handled by a special function.
2673 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2674 (funcall protocol (org-link-unescape path) desc 'html))
2675 ;; External link with a description part.
2676 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2677 ;; External link without a description part.
2678 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2679 ;; No path, only description. Try to do something useful.
2680 (t (format "<i>%s</i>" desc)))))
2682 ;;;; Paragraph
2684 (defun org-html-paragraph (paragraph contents info)
2685 "Transcode a PARAGRAPH element from Org to HTML.
2686 CONTENTS is the contents of the paragraph, as a string. INFO is
2687 the plist used as a communication channel."
2688 (let* ((parent (org-export-get-parent paragraph))
2689 (parent-type (org-element-type parent))
2690 (style '((footnote-definition " class=\"footpara\"")))
2691 (extra (or (cadr (assoc parent-type style)) "")))
2692 (cond
2693 ((and (eq (org-element-type parent) 'item)
2694 (= (org-element-property :begin paragraph)
2695 (org-element-property :contents-begin parent)))
2696 ;; leading paragraph in a list item have no tags
2697 contents)
2698 ((org-html-standalone-image-p paragraph info)
2699 ;; standalone image
2700 contents)
2701 (t (format "<p%s>\n%s</p>" extra contents)))))
2703 ;;;; Plain List
2705 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2706 ;; the correct value for the item counter
2707 (defun org-html-begin-plain-list (type &optional arg1)
2708 "Insert the beginning of the HTML list depending on TYPE.
2709 When ARG1 is a string, use it as the start parameter for ordered
2710 lists."
2711 (case type
2712 (ordered
2713 (format "<ol class=\"org-ol\"%s>"
2714 (if arg1 (format " start=\"%d\"" arg1) "")))
2715 (unordered "<ul class=\"org-ul\">")
2716 (descriptive "<dl class=\"org-dl\">")))
2718 (defun org-html-end-plain-list (type)
2719 "Insert the end of the HTML list depending on TYPE."
2720 (case type
2721 (ordered "</ol>")
2722 (unordered "</ul>")
2723 (descriptive "</dl>")))
2725 (defun org-html-plain-list (plain-list contents info)
2726 "Transcode a PLAIN-LIST element from Org to HTML.
2727 CONTENTS is the contents of the list. INFO is a plist holding
2728 contextual information."
2729 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2730 (type (org-element-property :type plain-list)))
2731 (format "%s\n%s%s"
2732 (org-html-begin-plain-list type)
2733 contents (org-html-end-plain-list type))))
2735 ;;;; Plain Text
2737 (defun org-html-convert-special-strings (string)
2738 "Convert special characters in STRING to HTML."
2739 (let ((all org-html-special-string-regexps)
2740 e a re rpl start)
2741 (while (setq a (pop all))
2742 (setq re (car a) rpl (cdr a) start 0)
2743 (while (string-match re string start)
2744 (setq string (replace-match rpl t nil string))))
2745 string))
2747 (defun org-html-encode-plain-text (text)
2748 "Convert plain text characters from TEXT to HTML equivalent.
2749 Possible conversions are set in `org-html-protect-char-alist'."
2750 (mapc
2751 (lambda (pair)
2752 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2753 org-html-protect-char-alist)
2754 text)
2756 (defun org-html-plain-text (text info)
2757 "Transcode a TEXT string from Org to HTML.
2758 TEXT is the string to transcode. INFO is a plist holding
2759 contextual information."
2760 (let ((output text))
2761 ;; Protect following characters: <, >, &.
2762 (setq output (org-html-encode-plain-text output))
2763 ;; Handle smart quotes. Be sure to provide original string since
2764 ;; OUTPUT may have been modified.
2765 (when (plist-get info :with-smart-quotes)
2766 (setq output (org-export-activate-smart-quotes output :html info text)))
2767 ;; Handle special strings.
2768 (when (plist-get info :with-special-strings)
2769 (setq output (org-html-convert-special-strings output)))
2770 ;; Handle break preservation if required.
2771 (when (plist-get info :preserve-breaks)
2772 (setq output
2773 (replace-regexp-in-string
2774 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2775 ;; Return value.
2776 output))
2779 ;; Planning
2781 (defun org-html-planning (planning contents info)
2782 "Transcode a PLANNING element from Org to HTML.
2783 CONTENTS is nil. INFO is a plist used as a communication
2784 channel."
2785 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2786 (format
2787 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2788 (mapconcat
2789 'identity
2790 (delq nil
2791 (list
2792 (let ((closed (org-element-property :closed planning)))
2793 (when closed
2794 (format span-fmt org-closed-string
2795 (org-translate-time
2796 (org-element-property :raw-value closed)))))
2797 (let ((deadline (org-element-property :deadline planning)))
2798 (when deadline
2799 (format span-fmt org-deadline-string
2800 (org-translate-time
2801 (org-element-property :raw-value deadline)))))
2802 (let ((scheduled (org-element-property :scheduled planning)))
2803 (when scheduled
2804 (format span-fmt org-scheduled-string
2805 (org-translate-time
2806 (org-element-property :raw-value scheduled)))))))
2807 " "))))
2809 ;;;; Property Drawer
2811 (defun org-html-property-drawer (property-drawer contents info)
2812 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2813 CONTENTS is nil. INFO is a plist holding contextual
2814 information."
2815 ;; The property drawer isn't exported but we want separating blank
2816 ;; lines nonetheless.
2819 ;;;; Quote Block
2821 (defun org-html-quote-block (quote-block contents info)
2822 "Transcode a QUOTE-BLOCK element from Org to HTML.
2823 CONTENTS holds the contents of the block. INFO is a plist
2824 holding contextual information."
2825 (format "<blockquote>\n%s</blockquote>" contents))
2827 ;;;; Quote Section
2829 (defun org-html-quote-section (quote-section contents info)
2830 "Transcode a QUOTE-SECTION element from Org to HTML.
2831 CONTENTS is nil. INFO is a plist holding contextual information."
2832 (let ((value (org-remove-indentation
2833 (org-element-property :value quote-section))))
2834 (when value (format "<pre>\n%s</pre>" value))))
2836 ;;;; Section
2838 (defun org-html-section (section contents info)
2839 "Transcode a SECTION element from Org to HTML.
2840 CONTENTS holds the contents of the section. INFO is a plist
2841 holding contextual information."
2842 (let ((parent (org-export-get-parent-headline section)))
2843 ;; Before first headline: no container, just return CONTENTS.
2844 (if (not parent) contents
2845 ;; Get div's class and id references.
2846 (let* ((class-num (+ (org-export-get-relative-level parent info)
2847 (1- org-html-toplevel-hlevel)))
2848 (section-number
2849 (mapconcat
2850 'number-to-string
2851 (org-export-get-headline-number parent info) "-")))
2852 ;; Build return value.
2853 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2854 class-num
2855 (or (org-element-property :CUSTOM_ID parent) section-number)
2856 contents)))))
2858 ;;;; Radio Target
2860 (defun org-html-radio-target (radio-target text info)
2861 "Transcode a RADIO-TARGET object from Org to HTML.
2862 TEXT is the text of the target. INFO is a plist holding
2863 contextual information."
2864 (let ((id (org-export-solidify-link-text
2865 (org-element-property :value radio-target))))
2866 (org-html--anchor id text)))
2868 ;;;; Special Block
2870 (defun org-html-special-block (special-block contents info)
2871 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2872 CONTENTS holds the contents of the block. INFO is a plist
2873 holding contextual information."
2874 (format "<div class=\"%s\">\n%s\n</div>"
2875 (downcase (org-element-property :type special-block))
2876 contents))
2878 ;;;; Src Block
2880 (defun org-html-src-block (src-block contents info)
2881 "Transcode a SRC-BLOCK element from Org to HTML.
2882 CONTENTS holds the contents of the item. INFO is a plist holding
2883 contextual information."
2884 (if (org-export-read-attribute :attr_html src-block :textarea)
2885 (org-html--textarea-block src-block)
2886 (let ((lang (org-element-property :language src-block))
2887 (caption (org-export-get-caption src-block))
2888 (code (org-html-format-code src-block info))
2889 (label (let ((lbl (org-element-property :name src-block)))
2890 (if (not lbl) ""
2891 (format " id=\"%s\""
2892 (org-export-solidify-link-text lbl))))))
2893 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2894 (format
2895 "<div class=\"org-src-container\">\n%s%s\n</div>"
2896 (if (not caption) ""
2897 (format "<label class=\"org-src-name\">%s</label>"
2898 (org-export-data caption info)))
2899 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2901 ;;;; Statistics Cookie
2903 (defun org-html-statistics-cookie (statistics-cookie contents info)
2904 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2905 CONTENTS is nil. INFO is a plist holding contextual information."
2906 (let ((cookie-value (org-element-property :value statistics-cookie)))
2907 (format "<code>%s</code>" cookie-value)))
2909 ;;;; Strike-Through
2911 (defun org-html-strike-through (strike-through contents info)
2912 "Transcode STRIKE-THROUGH from Org to HTML.
2913 CONTENTS is the text with strike-through markup. INFO is a plist
2914 holding contextual information."
2915 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2916 contents))
2918 ;;;; Subscript
2920 (defun org-html-subscript (subscript contents info)
2921 "Transcode a SUBSCRIPT object from Org to HTML.
2922 CONTENTS is the contents of the object. INFO is a plist holding
2923 contextual information."
2924 (format "<sub>%s</sub>" contents))
2926 ;;;; Superscript
2928 (defun org-html-superscript (superscript contents info)
2929 "Transcode a SUPERSCRIPT object from Org to HTML.
2930 CONTENTS is the contents of the object. INFO is a plist holding
2931 contextual information."
2932 (format "<sup>%s</sup>" contents))
2934 ;;;; Tabel Cell
2936 (defun org-html-table-cell (table-cell contents info)
2937 "Transcode a TABLE-CELL element from Org to HTML.
2938 CONTENTS is nil. INFO is a plist used as a communication
2939 channel."
2940 (let* ((table-row (org-export-get-parent table-cell))
2941 (table (org-export-get-parent-table table-cell))
2942 (cell-attrs
2943 (if (not org-html-table-align-individual-fields) ""
2944 (format (if (and (boundp 'org-html-format-table-no-css)
2945 org-html-format-table-no-css)
2946 " align=\"%s\"" " class=\"%s\"")
2947 (org-export-table-cell-alignment table-cell info)))))
2948 (when (or (not contents) (string= "" (org-trim contents)))
2949 (setq contents "&#xa0;"))
2950 (cond
2951 ((and (org-export-table-has-header-p table info)
2952 (= 1 (org-export-table-row-group table-row info)))
2953 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2954 contents (cdr org-html-table-header-tags)))
2955 ((and org-html-table-use-header-tags-for-first-column
2956 (zerop (cdr (org-export-table-cell-address table-cell info))))
2957 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2958 contents (cdr org-html-table-header-tags)))
2959 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2960 contents (cdr org-html-table-data-tags))))))
2962 ;;;; Table Row
2964 (defun org-html-table-row (table-row contents info)
2965 "Transcode a TABLE-ROW element from Org to HTML.
2966 CONTENTS is the contents of the row. INFO is a plist used as a
2967 communication channel."
2968 ;; Rules are ignored since table separators are deduced from
2969 ;; borders of the current row.
2970 (when (eq (org-element-property :type table-row) 'standard)
2971 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2972 (row-number (org-export-table-row-number table-row info))
2973 (start-rowgroup-p
2974 (org-export-table-row-starts-rowgroup-p table-row info))
2975 (end-rowgroup-p
2976 (org-export-table-row-ends-rowgroup-p table-row info))
2977 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2978 ;; but should be set so that `org-html-table-row-tags' can
2979 ;; use them (see the docstring of this variable.)
2980 (top-row-p (and (equal start-rowgroup-p '(top))
2981 (equal end-rowgroup-p '(below top))))
2982 (bottom-row-p (and (equal start-rowgroup-p '(above))
2983 (equal end-rowgroup-p '(bottom above))))
2984 (rowgroup-tags
2985 (cond
2986 ;; Case 1: Row belongs to second or subsequent rowgroups.
2987 ((not (= 1 rowgroup-number))
2988 '("<tbody>" . "\n</tbody>"))
2989 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2990 ((org-export-table-has-header-p
2991 (org-export-get-parent-table table-row) info)
2992 '("<thead>" . "\n</thead>"))
2993 ;; Case 2: Row is from first and only row group.
2994 (t '("<tbody>" . "\n</tbody>")))))
2995 (concat
2996 ;; Begin a rowgroup?
2997 (when start-rowgroup-p (car rowgroup-tags))
2998 ;; Actual table row
2999 (concat "\n" (eval (car org-html-table-row-tags))
3000 contents
3001 "\n"
3002 (eval (cdr org-html-table-row-tags)))
3003 ;; End a rowgroup?
3004 (when end-rowgroup-p (cdr rowgroup-tags))))))
3006 ;;;; Table
3008 (defun org-html-table-first-row-data-cells (table info)
3009 "Transcode the first row of TABLE.
3010 INFO is a plist used as a communication channel."
3011 (let ((table-row
3012 (org-element-map table 'table-row
3013 (lambda (row)
3014 (unless (eq (org-element-property :type row) 'rule) row))
3015 info 'first-match))
3016 (special-column-p (org-export-table-has-special-column-p table)))
3017 (if (not special-column-p) (org-element-contents table-row)
3018 (cdr (org-element-contents table-row)))))
3020 (defun org-html-table--table.el-table (table info)
3021 "Format table.el tables into HTML.
3022 INFO is a plist used as a communication channel."
3023 (when (eq (org-element-property :type table) 'table.el)
3024 (require 'table)
3025 (let ((outbuf (with-current-buffer
3026 (get-buffer-create "*org-export-table*")
3027 (erase-buffer) (current-buffer))))
3028 (with-temp-buffer
3029 (insert (org-element-property :value table))
3030 (goto-char 1)
3031 (re-search-forward "^[ \t]*|[^|]" nil t)
3032 (table-generate-source 'html outbuf))
3033 (with-current-buffer outbuf
3034 (prog1 (org-trim (buffer-string))
3035 (kill-buffer) )))))
3037 (defun org-html-table (table contents info)
3038 "Transcode a TABLE element from Org to HTML.
3039 CONTENTS is the contents of the table. INFO is a plist holding
3040 contextual information."
3041 (case (org-element-property :type table)
3042 ;; Case 1: table.el table. Convert it using appropriate tools.
3043 (table.el (org-html-table--table.el-table table info))
3044 ;; Case 2: Standard table.
3046 (let* ((label (org-element-property :name table))
3047 (caption (org-export-get-caption table))
3048 (attributes
3049 (org-html--make-attribute-string
3050 (org-combine-plists
3051 (and label (list :id (org-export-solidify-link-text label)))
3052 (plist-get info :html-table-attributes)
3053 (org-export-read-attribute :attr_html table))))
3054 (alignspec
3055 (if (and (boundp 'org-html-format-table-no-css)
3056 org-html-format-table-no-css)
3057 "align=\"%s\"" "class=\"%s\""))
3058 (table-column-specs
3059 (function
3060 (lambda (table info)
3061 (mapconcat
3062 (lambda (table-cell)
3063 (let ((alignment (org-export-table-cell-alignment
3064 table-cell info)))
3065 (concat
3066 ;; Begin a colgroup?
3067 (when (org-export-table-cell-starts-colgroup-p
3068 table-cell info)
3069 "\n<colgroup>")
3070 ;; Add a column. Also specify it's alignment.
3071 (format "\n<col %s/>" (format alignspec alignment))
3072 ;; End a colgroup?
3073 (when (org-export-table-cell-ends-colgroup-p
3074 table-cell info)
3075 "\n</colgroup>"))))
3076 (org-html-table-first-row-data-cells table info) "\n")))))
3077 (format "<table%s>\n%s\n%s\n%s</table>"
3078 (if (equal attributes "") "" (concat " " attributes))
3079 (if (not caption) ""
3080 (format "<caption>%s</caption>"
3081 (org-export-data caption info)))
3082 (funcall table-column-specs table info)
3083 contents)))))
3085 ;;;; Target
3087 (defun org-html-target (target contents info)
3088 "Transcode a TARGET object from Org to HTML.
3089 CONTENTS is nil. INFO is a plist holding contextual
3090 information."
3091 (let ((id (org-export-solidify-link-text
3092 (org-element-property :value target))))
3093 (org-html--anchor id)))
3095 ;;;; Timestamp
3097 (defun org-html-timestamp (timestamp contents info)
3098 "Transcode a TIMESTAMP object from Org to HTML.
3099 CONTENTS is nil. INFO is a plist holding contextual
3100 information."
3101 (let ((value (org-html-plain-text
3102 (org-timestamp-translate timestamp) info)))
3103 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3104 (replace-regexp-in-string "--" "&#x2013;" value))))
3106 ;;;; Underline
3108 (defun org-html-underline (underline contents info)
3109 "Transcode UNDERLINE from Org to HTML.
3110 CONTENTS is the text with underline markup. INFO is a plist
3111 holding contextual information."
3112 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3113 contents))
3115 ;;;; Verbatim
3117 (defun org-html-verbatim (verbatim contents info)
3118 "Transcode VERBATIM from Org to HTML.
3119 CONTENTS is nil. INFO is a plist holding contextual
3120 information."
3121 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3122 (org-html-plain-text (org-element-property :value verbatim) info)))
3124 ;;;; Verse Block
3126 (defun org-html-verse-block (verse-block contents info)
3127 "Transcode a VERSE-BLOCK element from Org to HTML.
3128 CONTENTS is verse block contents. INFO is a plist holding
3129 contextual information."
3130 ;; Replace each newline character with line break. Also replace
3131 ;; each blank line with a line break.
3132 (setq contents (replace-regexp-in-string
3133 "^ *\\\\\\\\$" "<br/>\n"
3134 (replace-regexp-in-string
3135 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3136 ;; Replace each white space at beginning of a line with a
3137 ;; non-breaking space.
3138 (while (string-match "^[ \t]+" contents)
3139 (let* ((num-ws (length (match-string 0 contents)))
3140 (ws (let (out) (dotimes (i num-ws out)
3141 (setq out (concat out "&#xa0;"))))))
3142 (setq contents (replace-match ws nil t contents))))
3143 (format "<p class=\"verse\">\n%s</p>" contents))
3146 ;;; Filter Functions
3148 (defun org-html-final-function (contents backend info)
3149 "Filter to indent the HTML and convert HTML entities."
3150 (with-temp-buffer
3151 (insert contents)
3152 (set-auto-mode t)
3153 (if org-html-indent
3154 (indent-region (point-min) (point-max)))
3155 (when org-html-use-unicode-chars
3156 (require 'mm-url)
3157 (mm-url-decode-entities))
3158 (buffer-substring-no-properties (point-min) (point-max))))
3161 ;;; End-user functions
3163 ;;;###autoload
3164 (defun org-html-export-as-html
3165 (&optional async subtreep visible-only body-only ext-plist)
3166 "Export current buffer to an HTML buffer.
3168 If narrowing is active in the current buffer, only export its
3169 narrowed part.
3171 If a region is active, export that region.
3173 A non-nil optional argument ASYNC means the process should happen
3174 asynchronously. The resulting buffer should be accessible
3175 through the `org-export-stack' interface.
3177 When optional argument SUBTREEP is non-nil, export the sub-tree
3178 at point, extracting information from the headline properties
3179 first.
3181 When optional argument VISIBLE-ONLY is non-nil, don't export
3182 contents of hidden elements.
3184 When optional argument BODY-ONLY is non-nil, only write code
3185 between \"<body>\" and \"</body>\" tags.
3187 EXT-PLIST, when provided, is a property list with external
3188 parameters overriding Org default settings, but still inferior to
3189 file-local settings.
3191 Export is done in a buffer named \"*Org HTML Export*\", which
3192 will be displayed when `org-export-show-temporary-export-buffer'
3193 is non-nil."
3194 (interactive)
3195 (if async
3196 (org-export-async-start
3197 (lambda (output)
3198 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3199 (erase-buffer)
3200 (insert output)
3201 (goto-char (point-min))
3202 (set-auto-mode t)
3203 (org-export-add-to-stack (current-buffer) 'html)))
3204 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3205 (let ((outbuf (org-export-to-buffer
3206 'html "*Org HTML Export*"
3207 subtreep visible-only body-only ext-plist)))
3208 ;; Set major mode.
3209 (with-current-buffer outbuf (set-auto-mode t))
3210 (when org-export-show-temporary-export-buffer
3211 (switch-to-buffer-other-window outbuf)))))
3213 ;;;###autoload
3214 (defun org-html-convert-region-to-html ()
3215 "Assume the current region has org-mode syntax, and convert it to HTML.
3216 This can be used in any buffer. For example, you can write an
3217 itemized list in org-mode syntax in an HTML buffer and use this
3218 command to convert it."
3219 (interactive)
3220 (org-export-replace-region-by 'html))
3222 ;;;###autoload
3223 (defun org-html-export-to-html
3224 (&optional async subtreep visible-only body-only ext-plist)
3225 "Export current buffer to a HTML file.
3227 If narrowing is active in the current buffer, only export its
3228 narrowed part.
3230 If a region is active, export that region.
3232 A non-nil optional argument ASYNC means the process should happen
3233 asynchronously. The resulting file should be accessible through
3234 the `org-export-stack' interface.
3236 When optional argument SUBTREEP is non-nil, export the sub-tree
3237 at point, extracting information from the headline properties
3238 first.
3240 When optional argument VISIBLE-ONLY is non-nil, don't export
3241 contents of hidden elements.
3243 When optional argument BODY-ONLY is non-nil, only write code
3244 between \"<body>\" and \"</body>\" tags.
3246 EXT-PLIST, when provided, is a property list with external
3247 parameters overriding Org default settings, but still inferior to
3248 file-local settings.
3250 Return output file's name."
3251 (interactive)
3252 (let* ((extension (concat "." org-html-extension))
3253 (file (org-export-output-file-name extension subtreep))
3254 (org-export-coding-system org-html-coding-system))
3255 (if async
3256 (org-export-async-start
3257 (lambda (f) (org-export-add-to-stack f 'html))
3258 (let ((org-export-coding-system org-html-coding-system))
3259 `(expand-file-name
3260 (org-export-to-file
3261 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3262 (let ((org-export-coding-system org-html-coding-system))
3263 (org-export-to-file
3264 'html file subtreep visible-only body-only ext-plist)))))
3266 ;;;###autoload
3267 (defun org-html-publish-to-html (plist filename pub-dir)
3268 "Publish an org file to HTML.
3270 FILENAME is the filename of the Org file to be published. PLIST
3271 is the property list for the given project. PUB-DIR is the
3272 publishing directory.
3274 Return output file name."
3275 (org-publish-org-to 'html filename
3276 (concat "." (or (plist-get plist :html-extension)
3277 org-html-extension "html"))
3278 plist pub-dir))
3281 ;;; FIXME
3283 ;;;; org-format-table-html
3284 ;;;; org-format-org-table-html
3285 ;;;; org-format-table-table-html
3286 ;;;; org-table-number-fraction
3287 ;;;; org-table-number-regexp
3288 ;;;; org-html-table-caption-above
3289 ;;;; org-html-inline-image-extensions
3290 ;;;; org-export-preferred-target-alist
3291 ;;;; class for anchors
3292 ;;;; org-export-mark-todo-in-toc
3293 ;;;; org-html-format-org-link
3294 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3295 ;;;; alt = (file-name-nondirectory path)
3297 (provide 'ox-html)
3299 ;; Local variables:
3300 ;; generated-autoload-file: "org-loaddefs.el"
3301 ;; End:
3303 ;;; ox-html.el ends here