ox-html: Fix docstring
[org-mode.git] / lisp / ox-html.el
blob6ab3722ad7ac5d0ecbaedd975f493db0b1c9d597
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-tag nil nil org-html-table-tag)
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-tag
747 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
748 "The HTML tag that is used to start a table.
749 This must be a <table> tag, but you may change the options like
750 borders and spacing."
751 :group 'org-export-html
752 :type 'string)
754 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
755 "The opening tag for table header fields.
756 This is customizable so that alignment options can be specified.
757 The first %s will be filled with the scope of the field, either row or col.
758 The second %s will be replaced by a style entry to align the field.
759 See also the variable `org-html-table-use-header-tags-for-first-column'.
760 See also the variable `org-html-table-align-individual-fields'."
761 :group 'org-export-html
762 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
764 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
765 "The opening tag for table data fields.
766 This is customizable so that alignment options can be specified.
767 The first %s will be filled with the scope of the field, either row or col.
768 The second %s will be replaced by a style entry to align the field.
769 See also the variable `org-html-table-align-individual-fields'."
770 :group 'org-export-html
771 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
773 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
774 "The opening and ending tags for table rows.
775 This is customizable so that alignment options can be specified.
776 Instead of strings, these can be Lisp forms that will be
777 evaluated for each row in order to construct the table row tags.
779 During evaluation, these variables will be dynamically bound so that
780 you can reuse them:
782 `row-number': row number (0 is the first row)
783 `rowgroup-number': group number of current row
784 `start-rowgroup-p': non-nil means the row starts a group
785 `end-rowgroup-p': non-nil means the row ends a group
786 `top-row-p': non-nil means this is the top row
787 `bottom-row-p': non-nil means this is the bottom row
789 For example:
791 \(setq org-html-table-row-tags
792 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
793 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
794 (t (if (= (mod row-number 2) 1)
795 \"<tr class=\\\"tr-odd\\\">\"
796 \"<tr class=\\\"tr-even\\\">\")))
797 \"</tr>\"))
799 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
800 and the bottom row, and otherwise alternate between \"tr-odd\" and
801 \"tr-even\" for odd and even rows."
802 :group 'org-export-html
803 :type '(cons
804 (choice :tag "Opening tag"
805 (string :tag "Specify")
806 (sexp))
807 (choice :tag "Closing tag"
808 (string :tag "Specify")
809 (sexp))))
811 (defcustom org-html-table-align-individual-fields t
812 "Non-nil means attach style attributes for alignment to each table field.
813 When nil, alignment will only be specified in the column tags, but this
814 is ignored by some browsers (like Firefox, Safari). Opera does it right
815 though."
816 :group 'org-export-html
817 :type 'boolean)
819 (defcustom org-html-table-use-header-tags-for-first-column nil
820 "Non-nil means format column one in tables with header tags.
821 When nil, also column one will use data tags."
822 :group 'org-export-html
823 :type 'boolean)
825 (defcustom org-html-table-caption-above t
826 "When non-nil, place caption string at the beginning of the table.
827 Otherwise, place it near the end."
828 :group 'org-export-html
829 :type 'boolean)
831 ;;;; Tags
833 (defcustom org-html-tag-class-prefix ""
834 "Prefix to class names for TODO keywords.
835 Each tag gets a class given by the tag itself, with this prefix.
836 The default prefix is empty because it is nice to just use the keyword
837 as a class name. But if you get into conflicts with other, existing
838 CSS classes, then this prefix can be very useful."
839 :group 'org-export-html
840 :type 'string)
842 ;;;; Template :: Generic
844 (defcustom org-html-extension "html"
845 "The extension for exported HTML files."
846 :group 'org-export-html
847 :type 'string)
849 (defcustom org-html-xml-declaration
850 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
851 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
852 "The extension for exported HTML files.
853 %s will be replaced with the charset of the exported file.
854 This may be a string, or an alist with export extensions
855 and corresponding declarations."
856 :group 'org-export-html
857 :type '(choice
858 (string :tag "Single declaration")
859 (repeat :tag "Dependent on extension"
860 (cons (string :tag "Extension")
861 (string :tag "Declaration")))))
863 (defcustom org-html-coding-system 'utf-8
864 "Coding system for HTML export.
865 Use utf-8 as the default value."
866 :group 'org-export-html
867 :version "24.4"
868 :package-version '(Org . "8.0")
869 :type 'coding-system)
871 (defcustom org-html-doctype
872 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
873 "Document type definition to use for exported HTML files.
874 Can be set with the in-buffer HTML_DOCTYPE property or for
875 publishing, with :html-doctype."
876 :group 'org-export-html
877 :version "24.4"
878 :package-version '(Org . "8.0")
879 :type 'string)
881 (defcustom org-html-container-element "div"
882 "HTML element to use for wrapping top level sections.
883 Can be set with the in-buffer HTML_CONTAINER property or for
884 publishing, with :html-container.
886 Note that changing the default will prevent you from using
887 org-info.js for your website."
888 :group 'org-export-html
889 :version "24.4"
890 :package-version '(Org . "8.0")
891 :type 'string)
893 (defcustom org-html-divs
894 '((preamble "div" "preamble")
895 (content "div" "content")
896 (postamble "div" "postamble"))
897 "Alist of the three section elements for HTML export.
898 The car of each entry is one of 'preamble, 'content or 'postamble.
899 The cdrs of each entry are the ELEMENT_TYPE and ID for each
900 section of the exported document.
902 Note that changing the default will prevent you from using
903 org-info.js for your website."
904 :group 'org-export-html
905 :version "24.4"
906 :package-version '(Org . "8.0")
907 :type '(list :greedy t
908 (list :tag "Preamble"
909 (const :format "" preamble)
910 (string :tag "element") (string :tag " id"))
911 (list :tag "Content"
912 (const :format "" content)
913 (string :tag "element") (string :tag " id"))
914 (list :tag "Postamble" (const :format "" postamble)
915 (string :tag " id") (string :tag "element"))))
917 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
918 "Format used for timestamps in preamble, postamble and metadata.
919 See `format-time-string' for more information on its components."
920 :group 'org-export-html
921 :version "24.4"
922 :package-version '(Org . "8.0")
923 :type 'string)
925 ;;;; Template :: Mathjax
927 (defcustom org-html-mathjax-options
928 '((path "http://orgmode.org/mathjax/MathJax.js")
929 (scale "100")
930 (align "center")
931 (indent "2em")
932 (mathml nil))
933 "Options for MathJax setup.
935 path The path where to find MathJax
936 scale Scaling for the HTML-CSS backend, usually between 100 and 133
937 align How to align display math: left, center, or right
938 indent If align is not center, how far from the left/right side?
939 mathml Should a MathML player be used if available?
940 This is faster and reduces bandwidth use, but currently
941 sometimes has lower spacing quality. Therefore, the default is
942 nil. When browsers get better, this switch can be flipped.
944 You can also customize this for each buffer, using something like
946 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
947 :group 'org-export-html
948 :type '(list :greedy t
949 (list :tag "path (the path from where to load MathJax.js)"
950 (const :format " " path) (string))
951 (list :tag "scale (scaling for the displayed math)"
952 (const :format " " scale) (string))
953 (list :tag "align (alignment of displayed equations)"
954 (const :format " " align) (string))
955 (list :tag "indent (indentation with left or right alignment)"
956 (const :format " " indent) (string))
957 (list :tag "mathml (should MathML display be used is possible)"
958 (const :format " " mathml) (boolean))))
960 (defcustom org-html-mathjax-template
961 "<script type=\"text/javascript\" src=\"%PATH\">
962 <!--/*--><![CDATA[/*><!--*/
963 MathJax.Hub.Config({
964 // Only one of the two following lines, depending on user settings
965 // First allows browser-native MathML display, second forces HTML/CSS
966 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
967 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
968 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
969 \"TeX/noUndefined.js\"],
970 tex2jax: {
971 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
972 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
973 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
974 ignoreClass: \"tex2jax_ignore\",
975 processEscapes: false,
976 processEnvironments: true,
977 preview: \"TeX\"
979 showProcessingMessages: true,
980 displayAlign: \"%ALIGN\",
981 displayIndent: \"%INDENT\",
983 \"HTML-CSS\": {
984 scale: %SCALE,
985 availableFonts: [\"STIX\",\"TeX\"],
986 preferredFont: \"TeX\",
987 webFont: \"TeX\",
988 imageFont: \"TeX\",
989 showMathMenu: true,
991 MMLorHTML: {
992 prefer: {
993 MSIE: \"MML\",
994 Firefox: \"MML\",
995 Opera: \"HTML\",
996 other: \"HTML\"
1000 /*]]>*///-->
1001 </script>"
1002 "The MathJax setup for XHTML files."
1003 :group 'org-export-html
1004 :type 'string)
1006 ;;;; Template :: Postamble
1008 (defcustom org-html-postamble 'auto
1009 "Non-nil means insert a postamble in HTML export.
1011 When set to 'auto, check against the
1012 `org-export-with-author/email/creator/date' variables to set the
1013 content of the postamble. When set to a string, use this string
1014 as the postamble. When t, insert a string as defined by the
1015 formatting string in `org-html-postamble-format'.
1017 When set to a function, apply this function and insert the
1018 returned string. The function takes the property list of export
1019 options as its only argument.
1021 Setting :html-postamble in publishing projects will take
1022 precedence over this variable."
1023 :group 'org-export-html
1024 :type '(choice (const :tag "No postamble" nil)
1025 (const :tag "Auto postamble" 'auto)
1026 (const :tag "Default formatting string" t)
1027 (string :tag "Custom formatting string")
1028 (function :tag "Function (must return a string)")))
1030 (defcustom org-html-postamble-format
1031 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1032 <p class=\"date\">Date: %d</p>
1033 <p class=\"creator\">%c</p>
1034 <p class=\"xhtml-validation\">%v</p>"))
1035 "Alist of languages and format strings for the HTML postamble.
1037 The first element of each list is the language code, as used for
1038 the LANGUAGE keyword. See `org-export-default-language'.
1040 The second element of each list is a format string to format the
1041 postamble itself. This format string can contain these elements:
1043 %t stands for the title.
1044 %a stands for the author's name.
1045 %e stands for the author's email.
1046 %d stands for the date.
1047 %c will be replaced by `org-html-creator-string'.
1048 %v will be replaced by `org-html-validation-link'.
1049 %T will be replaced by the export time.
1050 %C will be replaced by the last modification time.
1052 If you need to use a \"%\" character, you need to escape it
1053 like that: \"%%\"."
1054 :group 'org-export-html
1055 :type '(alist :key-type (string :tag "Language")
1056 :value-type (string :tag "Format string")))
1058 (defcustom org-html-validation-link
1059 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1060 "Link to HTML validation service."
1061 :group 'org-export-html
1062 :type 'string)
1064 (defcustom org-html-creator-string
1065 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1066 emacs-version
1067 (if (fboundp 'org-version) (org-version) "unknown version"))
1068 "Information about the creator of the HTML document.
1069 This option can also be set on with the CREATOR keyword."
1070 :group 'org-export-html
1071 :type '(string :tag "Creator string"))
1073 ;;;; Template :: Preamble
1075 (defcustom org-html-preamble t
1076 "Non-nil means insert a preamble in HTML export.
1078 When t, insert a string as defined by the formatting string in
1079 `org-html-preamble-format'. When set to a string, use this
1080 formatting string instead (see `org-html-postamble-format' for an
1081 example of such a formatting string).
1083 When set to a function, apply this function and insert the
1084 returned string. The function takes the property list of export
1085 options as its only argument.
1087 Setting :html-preamble in publishing projects will take
1088 precedence over this variable."
1089 :group 'org-export-html
1090 :type '(choice (const :tag "No preamble" nil)
1091 (const :tag "Default preamble" t)
1092 (string :tag "Custom formatting string")
1093 (function :tag "Function (must return a string)")))
1095 (defcustom org-html-preamble-format '(("en" ""))
1096 "Alist of languages and format strings for the HTML preamble.
1098 The first element of each list is the language code, as used for
1099 the LANGUAGE keyword. See `org-export-default-language'.
1101 The second element of each list is a format string to format the
1102 preamble itself. This format string can contain these elements:
1104 %t stands for the title.
1105 %a stands for the author's name.
1106 %e stands for the author's email.
1107 %d stands for the date.
1108 %c will be replaced by `org-html-creator-string'.
1109 %v will be replaced by `org-html-validation-link'.
1110 %T will be replaced by the export time.
1111 %C will be replaced by the last modification time.
1113 If you need to use a \"%\" character, you need to escape it
1114 like that: \"%%\".
1116 See the default value of `org-html-postamble-format' for an
1117 example."
1118 :group 'org-export-html
1119 :type '(alist :key-type (string :tag "Language")
1120 :value-type (string :tag "Format string")))
1122 (defcustom org-html-link-up ""
1123 "Where should the \"UP\" link of exported HTML pages lead?"
1124 :group 'org-export-html
1125 :type '(string :tag "File or URL"))
1127 (defcustom org-html-link-home ""
1128 "Where should the \"HOME\" link of exported HTML pages lead?"
1129 :group 'org-export-html
1130 :type '(string :tag "File or URL"))
1132 (defcustom org-html-home/up-format
1133 "<div id=\"org-div-home-and-up\">
1134 <a accesskey=\"h\" href=\"%s\"> UP </a>
1136 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1137 </div>"
1138 "Snippet used to insert the HOME and UP links.
1139 This is a format string, the first %s will receive the UP link,
1140 the second the HOME link. If both `org-html-link-up' and
1141 `org-html-link-home' are empty, the entire snippet will be
1142 ignored."
1143 :group 'org-export-html
1144 :type 'string)
1146 ;;;; Template :: Scripts
1148 (define-obsolete-variable-alias
1149 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1150 (defcustom org-html-head-include-scripts t
1151 "Non-nil means include the JavaScript snippets in exported HTML files.
1152 The actual script is defined in `org-html-scripts' and should
1153 not be modified."
1154 :group 'org-export-html
1155 :version "24.4"
1156 :package-version '(Org . "8.0")
1157 :type 'boolean)
1159 ;;;; Template :: Styles
1161 (define-obsolete-variable-alias
1162 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1163 (defcustom org-html-head-include-default-style t
1164 "Non-nil means include the default style in exported HTML files.
1165 The actual style is defined in `org-html-style-default' and
1166 should not be modified. Use `org-html-head' to use your own
1167 style information."
1168 :group 'org-export-html
1169 :version "24.4"
1170 :package-version '(Org . "8.0")
1171 :type 'boolean)
1172 ;;;###autoload
1173 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1175 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1176 (defcustom org-html-head ""
1177 "Org-wide head definitions for exported HTML files.
1179 This variable can contain the full HTML structure to provide a
1180 style, including the surrounding HTML tags. You can consider
1181 including definitions for the following classes: title, todo,
1182 done, timestamp, timestamp-kwd, tag, target.
1184 For example, a valid value would be:
1186 <style type=\"text/css\">
1187 <![CDATA[
1188 p { font-weight: normal; color: gray; }
1189 h1 { color: black; }
1190 .title { text-align: center; }
1191 .todo, .timestamp-kwd { color: red; }
1192 .done { color: green; }
1194 </style>
1196 If you want to refer to an external style, use something like
1198 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1200 As the value of this option simply gets inserted into the HTML
1201 <head> header, you can use it to add any arbitrary text to the
1202 header.
1204 You can set this on a per-file basis using #+HTML_HEAD:,
1205 or for publication projects using the :html-head property."
1206 :group 'org-export-html
1207 :version "24.4"
1208 :package-version '(Org . "8.0")
1209 :type 'string)
1210 ;;;###autoload
1211 (put 'org-html-head 'safe-local-variable 'stringp)
1213 (defcustom org-html-head-extra ""
1214 "More head information to add in the HTML output.
1216 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1217 or for publication projects using the :html-head-extra property."
1218 :group 'org-export-html
1219 :version "24.4"
1220 :package-version '(Org . "8.0")
1221 :type 'string)
1222 ;;;###autoload
1223 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1225 ;;;; Todos
1227 (defcustom org-html-todo-kwd-class-prefix ""
1228 "Prefix to class names for TODO keywords.
1229 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1230 The default prefix is empty because it is nice to just use the keyword
1231 as a class name. But if you get into conflicts with other, existing
1232 CSS classes, then this prefix can be very useful."
1233 :group 'org-export-html
1234 :type 'string)
1237 ;;; Internal Functions
1239 (defun org-html-format-inline-image (src &optional
1240 caption label attr standalone-p)
1241 "Format an inline image from SRC.
1242 CAPTION, LABEL and ATTR are optional arguments providing the
1243 caption, the label and the attribute of the image.
1244 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1245 (let* ((id (if (not label) ""
1246 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1247 (attr (concat attr
1248 (cond
1249 ((string-match "\\<alt=" (or attr "")) "")
1250 ((string-match "^ltxpng/" src)
1251 (format " alt=\"%s\""
1252 (org-html-encode-plain-text
1253 (org-find-text-property-in-string
1254 'org-latex-src src))))
1255 (t (format " alt=\"%s\""
1256 (file-name-nondirectory src)))))))
1257 (cond
1258 (standalone-p
1259 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1260 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1261 id (format "\n<p>%s</p>" img)
1262 (if (and caption (not (string= caption "")))
1263 (format "\n<p>%s</p>" caption) ""))))
1264 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1266 (defun org-html--textarea-block (element)
1267 "Transcode ELEMENT into a textarea block.
1268 ELEMENT is either a src block or an example block."
1269 (let* ((code (car (org-export-unravel-code element)))
1270 (attr (org-export-read-attribute :attr_html element)))
1271 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1272 (or (plist-get attr :width) 80)
1273 (or (plist-get attr :height) (org-count-lines code))
1274 code)))
1276 ;;;; Bibliography
1278 (defun org-html-bibliography ()
1279 "Find bibliography, cut it out and return it."
1280 (catch 'exit
1281 (let (beg end (cnt 1) bib)
1282 (save-excursion
1283 (goto-char (point-min))
1284 (when (re-search-forward
1285 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1286 (setq beg (match-beginning 0))
1287 (while (re-search-forward "</?div\\>" nil t)
1288 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1289 (when (= cnt 0)
1290 (and (looking-at ">") (forward-char 1))
1291 (setq bib (buffer-substring beg (point)))
1292 (delete-region beg (point))
1293 (throw 'exit bib))))
1294 nil))))
1296 ;;;; Table
1298 (defun org-html-splice-attributes (tag attributes)
1299 "Return a HTML TAG edited wrt ATTRIBUTES."
1300 (if (not attributes)
1302 (let (oldatt newatt)
1303 (setq oldatt (org-extract-attributes-from-string tag)
1304 tag (pop oldatt)
1305 newatt (cdr (org-extract-attributes-from-string attributes)))
1306 (while newatt
1307 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1308 (if (string-match ">" tag)
1309 (setq tag
1310 (replace-match (concat (org-attributes-to-string oldatt) ">")
1311 t t tag)))
1312 tag)))
1314 (defun org-export-splice-style (style extra)
1315 "Return STYLE updated wrt EXTRA."
1316 (if (and (stringp extra)
1317 (string-match "\\S-" extra)
1318 (string-match "</style>" style))
1319 (concat (substring style 0 (match-beginning 0))
1320 "\n" extra "\n"
1321 (substring style (match-beginning 0)))
1322 style))
1324 (defun org-html-htmlize-region-for-paste (beg end)
1325 "Convert the region between BEG and END to HTML, using htmlize.el.
1326 This is much like `htmlize-region-for-paste', only that it uses
1327 the settings define in the org-... variables."
1328 (let* ((htmlize-output-type org-html-htmlize-output-type)
1329 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1330 (htmlbuf (htmlize-region beg end)))
1331 (unwind-protect
1332 (with-current-buffer htmlbuf
1333 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1334 (plist-get htmlize-buffer-places 'content-end)))
1335 (kill-buffer htmlbuf))))
1337 ;;;###autoload
1338 (defun org-html-htmlize-generate-css ()
1339 "Create the CSS for all font definitions in the current Emacs session.
1340 Use this to create face definitions in your CSS style file that can then
1341 be used by code snippets transformed by htmlize.
1342 This command just produces a buffer that contains class definitions for all
1343 faces used in the current Emacs session. You can copy and paste the ones you
1344 need into your CSS file.
1346 If you then set `org-html-htmlize-output-type' to `css', calls
1347 to the function `org-html-htmlize-region-for-paste' will
1348 produce code that uses these same face definitions."
1349 (interactive)
1350 (require 'htmlize)
1351 (and (get-buffer "*html*") (kill-buffer "*html*"))
1352 (with-temp-buffer
1353 (let ((fl (face-list))
1354 (htmlize-css-name-prefix "org-")
1355 (htmlize-output-type 'css)
1356 f i)
1357 (while (setq f (pop fl)
1358 i (and f (face-attribute f :inherit)))
1359 (when (and (symbolp f) (or (not i) (not (listp i))))
1360 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1361 (htmlize-region (point-min) (point-max))))
1362 (org-pop-to-buffer-same-window "*html*")
1363 (goto-char (point-min))
1364 (if (re-search-forward "<style" nil t)
1365 (delete-region (point-min) (match-beginning 0)))
1366 (if (re-search-forward "</style>" nil t)
1367 (delete-region (1+ (match-end 0)) (point-max)))
1368 (beginning-of-line 1)
1369 (if (looking-at " +") (replace-match ""))
1370 (goto-char (point-min)))
1372 (defun org-html--make-string (n string)
1373 "Build a string by concatenating N times STRING."
1374 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1376 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1377 "Turn todo keyword KWD into a valid class name.
1378 Replaces invalid characters with \"_\"."
1379 (save-match-data
1380 (while (string-match "[^a-zA-Z0-9_]" kwd)
1381 (setq kwd (replace-match "_" t t kwd))))
1382 kwd)
1384 (defun org-html-format-footnote-reference (n def refcnt)
1385 "Format footnote reference N with definition DEF into HTML."
1386 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1387 (format org-html-footnote-format
1388 (let* ((id (format "fnr.%s%s" n extra))
1389 (href (format " href=\"#fn.%s\"" n))
1390 (attributes (concat " class=\"footref\"" href)))
1391 (org-html--anchor id n attributes)))))
1393 (defun org-html-format-footnotes-section (section-name definitions)
1394 "Format footnotes section SECTION-NAME."
1395 (if (not definitions) ""
1396 (format org-html-footnotes-section section-name definitions)))
1398 (defun org-html-format-footnote-definition (fn)
1399 "Format the footnote definition FN."
1400 (let ((n (car fn)) (def (cdr fn)))
1401 (format
1402 "<div class=\"footdef\">%s %s</div>\n"
1403 (format org-html-footnote-format
1404 (let* ((id (format "fn.%s" n))
1405 (href (format " href=\"#fnr.%s\"" n))
1406 (attributes (concat " class=\"footnum\"" href)))
1407 (org-html--anchor id n attributes)))
1408 def)))
1410 (defun org-html-footnote-section (info)
1411 "Format the footnote section.
1412 INFO is a plist used as a communication channel."
1413 (let* ((fn-alist (org-export-collect-footnote-definitions
1414 (plist-get info :parse-tree) info))
1415 (fn-alist
1416 (loop for (n type raw) in fn-alist collect
1417 (cons n (if (eq (org-element-type raw) 'org-data)
1418 (org-trim (org-export-data raw info))
1419 (format "<p>%s</p>"
1420 (org-trim (org-export-data raw info))))))))
1421 (when fn-alist
1422 (org-html-format-footnotes-section
1423 (org-html--translate "Footnotes" info)
1424 (format
1425 "\n%s\n"
1426 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1429 ;;; Template
1431 (defun org-html--build-meta-info (info)
1432 "Return meta tags for exported document.
1433 INFO is a plist used as a communication channel."
1434 (let* ((title (org-export-data (plist-get info :title) info))
1435 (author (and (plist-get info :with-author)
1436 (let ((auth (plist-get info :author)))
1437 (and auth (org-export-data auth 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 author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1454 (and description
1455 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1456 (and keywords
1457 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1459 (defun org-html--build-head (info)
1460 "Return information for the <head>..</head> of the HTML output.
1461 INFO is a plist used as a communication channel."
1462 (org-element-normalize-string
1463 (concat
1464 (when (plist-get info :html-head-include-default-style)
1465 (org-element-normalize-string org-html-style-default))
1466 (org-element-normalize-string (plist-get info :html-head))
1467 (org-element-normalize-string (plist-get info :html-head-extra))
1468 (when (and (plist-get info :html-htmlized-css-url)
1469 (eq org-html-htmlize-output-type 'css))
1470 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1471 (plist-get info :html-htmlized-css-url)))
1472 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1474 (defun org-html--build-mathjax-config (info)
1475 "Insert the user setup into the mathjax template.
1476 INFO is a plist used as a communication channel."
1477 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1478 (org-element-map (plist-get info :parse-tree)
1479 '(latex-fragment latex-environment) 'identity info t))
1480 (let ((template org-html-mathjax-template)
1481 (options org-html-mathjax-options)
1482 (in-buffer (or (plist-get info :html-mathjax) ""))
1483 name val (yes " ") (no "// ") x)
1484 (mapc
1485 (lambda (e)
1486 (setq name (car e) val (nth 1 e))
1487 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1488 (setq val (car (read-from-string
1489 (substring in-buffer (match-end 0))))))
1490 (if (not (stringp val)) (setq val (format "%s" val)))
1491 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1492 (setq template (replace-match val t t template))))
1493 options)
1494 (setq val (nth 1 (assq 'mathml options)))
1495 (if (string-match (concat "\\<mathml:") in-buffer)
1496 (setq val (car (read-from-string
1497 (substring in-buffer (match-end 0))))))
1498 ;; Exchange prefixes depending on mathml setting.
1499 (if (not val) (setq x yes yes no no x))
1500 ;; Replace cookies to turn on or off the config/jax lines.
1501 (if (string-match ":MMLYES:" template)
1502 (setq template (replace-match yes t t template)))
1503 (if (string-match ":MMLNO:" template)
1504 (setq template (replace-match no t t template)))
1505 ;; Return the modified template.
1506 (org-element-normalize-string template))))
1508 (defun org-html-format-spec (info)
1509 "Return format specification for elements that can be
1510 used in the preamble or postamble."
1511 `((?t . ,(org-export-data (plist-get info :title) info))
1512 (?d . ,(org-export-data (org-export-get-date info) info))
1513 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1514 (?a . ,(org-export-data (plist-get info :author) info))
1515 (?e . ,(mapconcat
1516 (lambda (e)
1517 (format "<a href=\"mailto:%s\">%s</a>" e e))
1518 (split-string (plist-get info :email) ",+ *")
1519 ", "))
1520 (?c . ,(plist-get info :creator))
1521 (?C . ,(let ((file (plist-get info :input-file)))
1522 (format-time-string org-html-metadata-timestamp-format
1523 (if file (nth 5 (file-attributes file))
1524 (current-time)))))
1525 (?v . ,(or org-html-validation-link ""))))
1527 (defun org-html--build-pre/postamble (type info)
1528 "Return document preamble or postamble as a string, or nil.
1529 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1530 communication channel."
1531 (let ((section (plist-get info (intern (format ":html-%s" type))))
1532 (spec (org-html-format-spec info)))
1533 (when section
1534 (let ((section-contents
1535 (if (functionp section) (funcall section info)
1536 (cond
1537 ((stringp section) (format-spec section spec))
1538 ((eq section 'auto)
1539 (let ((date (cdr (assq ?d spec)))
1540 (author (cdr (assq ?a spec)))
1541 (email (cdr (assq ?e spec)))
1542 (creator (cdr (assq ?c spec)))
1543 (timestamp (cdr (assq ?T spec)))
1544 (validation-link (cdr (assq ?v spec))))
1545 (concat
1546 (when (and (plist-get info :with-date)
1547 (org-string-nw-p date))
1548 (format "<p class=\"date\">%s: %s</p>\n"
1549 (org-html--translate "Date" info)
1550 date))
1551 (when (and (plist-get info :with-author)
1552 (org-string-nw-p author))
1553 (format "<p class=\"author\">%s: %s</p>\n"
1554 (org-html--translate "Author" info)
1555 author))
1556 (when (and (plist-get info :with-email)
1557 (org-string-nw-p email))
1558 (format "<p class=\"email\">%s: %s</p>\n"
1559 (org-html--translate "Email" info)
1560 email))
1561 (when (plist-get info :time-stamp-file)
1562 (format
1563 "<p class=\"date\">%s: %s</p>\n"
1564 (org-html--translate "Created" info)
1565 (format-time-string org-html-metadata-timestamp-format)))
1566 (when (plist-get info :with-creator)
1567 (format "<p class=\"creator\">%s</p>\n" creator))
1568 (format "<p class=\"xhtml-validation\">%s</p>\n"
1569 validation-link))))
1570 (t (format-spec
1571 (or (cadr (assoc
1572 (plist-get info :language)
1573 (eval (intern
1574 (format "org-html-%s-format" type)))))
1575 (cadr
1576 (assoc
1577 "en"
1578 (eval
1579 (intern (format "org-html-%s-format" type))))))
1580 spec))))))
1581 (when (org-string-nw-p section-contents)
1582 (concat
1583 (format "<%s id=\"%s\" class=\"%s\">\n"
1584 (nth 1 (assq type org-html-divs))
1585 (nth 2 (assq type org-html-divs))
1586 org-html--pre/postamble-class)
1587 (org-element-normalize-string section-contents)
1588 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1590 (defun org-html-inner-template (contents info)
1591 "Return body of document string after HTML conversion.
1592 CONTENTS is the transcoded contents string. INFO is a plist
1593 holding export options."
1594 (concat
1595 ;; Table of contents.
1596 (let ((depth (plist-get info :with-toc)))
1597 (when depth (org-html-toc depth info)))
1598 ;; Document contents.
1599 contents
1600 ;; Footnotes section.
1601 (org-html-footnote-section info)
1602 ;; Bibliography.
1603 (org-html-bibliography)))
1605 (defun org-html-template (contents info)
1606 "Return complete document string after HTML conversion.
1607 CONTENTS is the transcoded contents string. INFO is a plist
1608 holding export options."
1609 (concat
1610 (format
1611 (or (and (stringp org-html-xml-declaration)
1612 org-html-xml-declaration)
1613 (cdr (assoc (plist-get info :html-extension)
1614 org-html-xml-declaration))
1615 (cdr (assoc "html" org-html-xml-declaration))
1618 (or (and org-html-coding-system
1619 (fboundp 'coding-system-get)
1620 (coding-system-get org-html-coding-system 'mime-charset))
1621 "iso-8859-1"))
1622 "\n"
1623 (plist-get info :html-doctype)
1624 "\n"
1625 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1626 (plist-get info :language) (plist-get info :language))
1627 "<head>\n"
1628 (org-html--build-meta-info info)
1629 (org-html--build-head info)
1630 (org-html--build-mathjax-config info)
1631 "</head>\n"
1632 "<body>\n"
1633 (let ((link-up (org-trim (plist-get info :html-link-up)))
1634 (link-home (org-trim (plist-get info :html-link-home))))
1635 (unless (and (string= link-up "") (string= link-up ""))
1636 (format org-html-home/up-format
1637 (or link-up link-home)
1638 (or link-home link-up))))
1639 ;; Preamble.
1640 (org-html--build-pre/postamble 'preamble info)
1641 ;; Document contents.
1642 (format "<%s id=\"%s\">\n"
1643 (nth 1 (assq 'content org-html-divs))
1644 (nth 2 (assq 'content org-html-divs)))
1645 ;; Document title.
1646 (let ((title (plist-get info :title)))
1647 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1648 contents
1649 (format "</%s>\n"
1650 (nth 1 (assq 'content org-html-divs)))
1651 ;; Postamble.
1652 (org-html--build-pre/postamble 'postamble info)
1653 ;; Closing document.
1654 "</body>\n</html>"))
1656 (defun org-html--translate (s info)
1657 "Translate string S according to specified language.
1658 INFO is a plist used as a communication channel."
1659 (org-export-translate s :html info))
1661 ;;;; Anchor
1663 (defun org-html--anchor (&optional id desc attributes)
1664 "Format a HTML anchor."
1665 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1666 (attributes (concat (and id (format " id=\"%s\"" id))
1667 (and name (format " name=\"%s\"" name))
1668 attributes)))
1669 (format "<a%s>%s</a>" attributes (or desc ""))))
1671 ;;;; Todo
1673 (defun org-html--todo (todo)
1674 "Format TODO keywords into HTML."
1675 (when todo
1676 (format "<span class=\"%s %s%s\">%s</span>"
1677 (if (member todo org-done-keywords) "done" "todo")
1678 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1679 todo)))
1681 ;;;; Tags
1683 (defun org-html--tags (tags)
1684 "Format TAGS into HTML."
1685 (when tags
1686 (format "<span class=\"tag\">%s</span>"
1687 (mapconcat
1688 (lambda (tag)
1689 (format "<span class=\"%s\">%s</span>"
1690 (concat org-html-tag-class-prefix
1691 (org-html-fix-class-name tag))
1692 tag))
1693 tags "&#xa0;"))))
1695 ;;;; Headline
1697 (defun* org-html-format-headline
1698 (todo todo-type priority text tags
1699 &key level section-number headline-label &allow-other-keys)
1700 "Format a headline in HTML."
1701 (let ((section-number
1702 (when section-number
1703 (format "<span class=\"section-number-%d\">%s</span> "
1704 level section-number)))
1705 (todo (org-html--todo todo))
1706 (tags (org-html--tags tags)))
1707 (concat section-number todo (and todo " ") text
1708 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1710 ;;;; Src Code
1712 (defun org-html-fontify-code (code lang)
1713 "Color CODE with htmlize library.
1714 CODE is a string representing the source code to colorize. LANG
1715 is the language used for CODE, as a string, or nil."
1716 (when code
1717 (cond
1718 ;; Case 1: No lang. Possibly an example block.
1719 ((not lang)
1720 ;; Simple transcoding.
1721 (org-html-encode-plain-text code))
1722 ;; Case 2: No htmlize or an inferior version of htmlize
1723 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1724 ;; Emit a warning.
1725 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1726 ;; Simple transcoding.
1727 (org-html-encode-plain-text code))
1729 ;; Map language
1730 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1731 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1732 (cond
1733 ;; Case 1: Language is not associated with any Emacs mode
1734 ((not (functionp lang-mode))
1735 ;; Simple transcoding.
1736 (org-html-encode-plain-text code))
1737 ;; Case 2: Default. Fontify code.
1739 ;; htmlize
1740 (setq code (with-temp-buffer
1741 ;; Switch to language-specific mode.
1742 (funcall lang-mode)
1743 (insert code)
1744 ;; Fontify buffer.
1745 (font-lock-fontify-buffer)
1746 ;; Remove formatting on newline characters.
1747 (save-excursion
1748 (let ((beg (point-min))
1749 (end (point-max)))
1750 (goto-char beg)
1751 (while (progn (end-of-line) (< (point) end))
1752 (put-text-property (point) (1+ (point)) 'face nil)
1753 (forward-char 1))))
1754 (org-src-mode)
1755 (set-buffer-modified-p nil)
1756 ;; Htmlize region.
1757 (org-html-htmlize-region-for-paste
1758 (point-min) (point-max))))
1759 ;; Strip any enclosing <pre></pre> tags.
1760 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1761 (end (and beg (string-match "</pre>\\'" code))))
1762 (if (and beg end) (substring code beg end) code)))))))))
1764 (defun org-html-do-format-code
1765 (code &optional lang refs retain-labels num-start)
1766 "Format CODE string as source code.
1767 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1768 respectively, the language of the source code, as a string, an
1769 alist between line numbers and references (as returned by
1770 `org-export-unravel-code'), a boolean specifying if labels should
1771 appear in the source code, and the number associated to the first
1772 line of code."
1773 (let* ((code-lines (org-split-string code "\n"))
1774 (code-length (length code-lines))
1775 (num-fmt
1776 (and num-start
1777 (format "%%%ds: "
1778 (length (number-to-string (+ code-length num-start))))))
1779 (code (org-html-fontify-code code lang)))
1780 (org-export-format-code
1781 code
1782 (lambda (loc line-num ref)
1783 (setq loc
1784 (concat
1785 ;; Add line number, if needed.
1786 (when num-start
1787 (format "<span class=\"linenr\">%s</span>"
1788 (format num-fmt line-num)))
1789 ;; Transcoded src line.
1791 ;; Add label, if needed.
1792 (when (and ref retain-labels) (format " (%s)" ref))))
1793 ;; Mark transcoded line as an anchor, if needed.
1794 (if (not ref) loc
1795 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1796 ref loc)))
1797 num-start refs)))
1799 (defun org-html-format-code (element info)
1800 "Format contents of ELEMENT as source code.
1801 ELEMENT is either an example block or a src block. INFO is
1802 a plist used as a communication channel."
1803 (let* ((lang (org-element-property :language element))
1804 ;; Extract code and references.
1805 (code-info (org-export-unravel-code element))
1806 (code (car code-info))
1807 (refs (cdr code-info))
1808 ;; Does the src block contain labels?
1809 (retain-labels (org-element-property :retain-labels element))
1810 ;; Does it have line numbers?
1811 (num-start (case (org-element-property :number-lines element)
1812 (continued (org-export-get-loc element info))
1813 (new 0))))
1814 (org-html-do-format-code code lang refs retain-labels num-start)))
1817 ;;; Tables of Contents
1819 (defun org-html-toc (depth info)
1820 "Build a table of contents.
1821 DEPTH is an integer specifying the depth of the table. INFO is a
1822 plist used as a communication channel. Return the table of
1823 contents as a string, or nil if it is empty."
1824 (let ((toc-entries
1825 (mapcar (lambda (headline)
1826 (cons (org-html--format-toc-headline headline info)
1827 (org-export-get-relative-level headline info)))
1828 (org-export-collect-headlines info depth))))
1829 (when toc-entries
1830 (concat "<div id=\"table-of-contents\">\n"
1831 (format "<h%d>%s</h%d>\n"
1832 org-html-toplevel-hlevel
1833 (org-html--translate "Table of Contents" info)
1834 org-html-toplevel-hlevel)
1835 "<div id=\"text-table-of-contents\">"
1836 (org-html--toc-text toc-entries)
1837 "</div>\n"
1838 "</div>\n"))))
1840 (defun org-html--toc-text (toc-entries)
1841 "Return innards of a table of contents, as a string.
1842 TOC-ENTRIES is an alist where key is an entry title, as a string,
1843 and value is its relative level, as an integer."
1844 (let* ((prev-level (1- (cdar toc-entries)))
1845 (start-level prev-level))
1846 (concat
1847 (mapconcat
1848 (lambda (entry)
1849 (let ((headline (car entry))
1850 (level (cdr entry)))
1851 (concat
1852 (let* ((cnt (- level prev-level))
1853 (times (if (> cnt 0) (1- cnt) (- cnt)))
1854 rtn)
1855 (setq prev-level level)
1856 (concat
1857 (org-html--make-string
1858 times (cond ((> cnt 0) "\n<ul>\n<li>")
1859 ((< cnt 0) "</li>\n</ul>\n")))
1860 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1861 headline)))
1862 toc-entries "")
1863 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1865 (defun org-html--format-toc-headline (headline info)
1866 "Return an appropriate table of contents entry for HEADLINE.
1867 INFO is a plist used as a communication channel."
1868 (let* ((headline-number (org-export-get-headline-number headline info))
1869 (section-number
1870 (and (not (org-export-low-level-p headline info))
1871 (org-export-numbered-headline-p headline info)
1872 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1873 (tags (and (eq (plist-get info :with-tags) t)
1874 (org-export-get-tags headline info))))
1875 (format "<a href=\"#%s\">%s</a>"
1876 ;; Label.
1877 (org-export-solidify-link-text
1878 (or (org-element-property :CUSTOM_ID headline)
1879 (concat "sec-" (mapconcat 'number-to-string
1880 headline-number "-"))))
1881 ;; Body.
1882 (concat section-number
1883 (org-export-data-with-translations
1884 (org-export-get-alt-title headline info)
1885 ;; Ignore any footnote-reference, link,
1886 ;; radio-target and target in table of contents.
1887 (append
1888 '((footnote-reference . ignore)
1889 (link . (lambda (link desc i) desc))
1890 (radio-target . (lambda (radio desc i) desc))
1891 (target . ignore))
1892 (org-export-backend-translate-table 'html))
1893 info)
1894 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1896 (defun org-html-list-of-listings (info)
1897 "Build a list of listings.
1898 INFO is a plist used as a communication channel. Return the list
1899 of listings as a string, or nil if it is empty."
1900 (let ((lol-entries (org-export-collect-listings info)))
1901 (when lol-entries
1902 (concat "<div id=\"list-of-listings\">\n"
1903 (format "<h%d>%s</h%d>\n"
1904 org-html-toplevel-hlevel
1905 (org-html--translate "List of Listings" info)
1906 org-html-toplevel-hlevel)
1907 "<div id=\"text-list-of-listings\">\n<ul>\n"
1908 (let ((count 0)
1909 (initial-fmt (org-html--translate "Listing %d:" info)))
1910 (mapconcat
1911 (lambda (entry)
1912 (let ((label (org-element-property :name entry))
1913 (title (org-trim
1914 (org-export-data
1915 (or (org-export-get-caption entry t)
1916 (org-export-get-caption entry))
1917 info))))
1918 (concat
1919 "<li>"
1920 (if (not label)
1921 (concat (format initial-fmt (incf count)) " " title)
1922 (format "<a href=\"#%s\">%s %s</a>"
1923 (org-export-solidify-link-text label)
1924 (format initial-fmt (incf count))
1925 title))
1926 "</li>")))
1927 lol-entries "\n"))
1928 "\n</ul>\n</div>\n</div>"))))
1930 (defun org-html-list-of-tables (info)
1931 "Build a list of tables.
1932 INFO is a plist used as a communication channel. Return the list
1933 of tables as a string, or nil if it is empty."
1934 (let ((lol-entries (org-export-collect-tables info)))
1935 (when lol-entries
1936 (concat "<div id=\"list-of-tables\">\n"
1937 (format "<h%d>%s</h%d>\n"
1938 org-html-toplevel-hlevel
1939 (org-html--translate "List of Tables" info)
1940 org-html-toplevel-hlevel)
1941 "<div id=\"text-list-of-tables\">\n<ul>\n"
1942 (let ((count 0)
1943 (initial-fmt (org-html--translate "Table %d:" info)))
1944 (mapconcat
1945 (lambda (entry)
1946 (let ((label (org-element-property :name entry))
1947 (title (org-trim
1948 (org-export-data
1949 (or (org-export-get-caption entry t)
1950 (org-export-get-caption entry))
1951 info))))
1952 (concat
1953 "<li>"
1954 (if (not label)
1955 (concat (format initial-fmt (incf count)) " " title)
1956 (format "<a href=\"#%s\">%s %s</a>"
1957 (org-export-solidify-link-text label)
1958 (format initial-fmt (incf count))
1959 title))
1960 "</li>")))
1961 lol-entries "\n"))
1962 "\n</ul>\n</div>\n</div>"))))
1965 ;;; Transcode Functions
1967 ;;;; Bold
1969 (defun org-html-bold (bold contents info)
1970 "Transcode BOLD from Org to HTML.
1971 CONTENTS is the text with bold markup. INFO is a plist holding
1972 contextual information."
1973 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1974 contents))
1976 ;;;; Center Block
1978 (defun org-html-center-block (center-block contents info)
1979 "Transcode a CENTER-BLOCK element from Org to HTML.
1980 CONTENTS holds the contents of the block. INFO is a plist
1981 holding contextual information."
1982 (format "<div class=\"center\">\n%s</div>" contents))
1984 ;;;; Clock
1986 (defun org-html-clock (clock contents info)
1987 "Transcode a CLOCK element from Org to HTML.
1988 CONTENTS is nil. INFO is a plist used as a communication
1989 channel."
1990 (format "<p>
1991 <span class=\"timestamp-wrapper\">
1992 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1993 </span>
1994 </p>"
1995 org-clock-string
1996 (org-translate-time
1997 (org-element-property :raw-value
1998 (org-element-property :value clock)))
1999 (let ((time (org-element-property :duration clock)))
2000 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2002 ;;;; Code
2004 (defun org-html-code (code contents info)
2005 "Transcode CODE from Org to HTML.
2006 CONTENTS is nil. INFO is a plist holding contextual
2007 information."
2008 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2009 (org-html-plain-text (org-element-property :value code) info)))
2011 ;;;; Drawer
2013 (defun org-html-drawer (drawer contents info)
2014 "Transcode a DRAWER element from Org to HTML.
2015 CONTENTS holds the contents of the block. INFO is a plist
2016 holding contextual information."
2017 (if (functionp org-html-format-drawer-function)
2018 (funcall org-html-format-drawer-function
2019 (org-element-property :drawer-name drawer)
2020 contents)
2021 ;; If there's no user defined function: simply
2022 ;; display contents of the drawer.
2023 contents))
2025 ;;;; Dynamic Block
2027 (defun org-html-dynamic-block (dynamic-block contents info)
2028 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2029 CONTENTS holds the contents of the block. INFO is a plist
2030 holding contextual information. See `org-export-data'."
2031 contents)
2033 ;;;; Entity
2035 (defun org-html-entity (entity contents info)
2036 "Transcode an ENTITY object from Org to HTML.
2037 CONTENTS are the definition itself. INFO is a plist holding
2038 contextual information."
2039 (org-element-property :html entity))
2041 ;;;; Example Block
2043 (defun org-html-example-block (example-block contents info)
2044 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2045 CONTENTS is nil. INFO is a plist holding contextual
2046 information."
2047 (if (org-export-read-attribute :attr_html example-block :textarea)
2048 (org-html--textarea-block example-block)
2049 (format "<pre class=\"example\">\n%s</pre>"
2050 (org-html-format-code example-block info))))
2052 ;;;; Export Snippet
2054 (defun org-html-export-snippet (export-snippet contents info)
2055 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2056 CONTENTS is nil. INFO is a plist holding contextual
2057 information."
2058 (when (eq (org-export-snippet-backend export-snippet) 'html)
2059 (org-element-property :value export-snippet)))
2061 ;;;; Export Block
2063 (defun org-html-export-block (export-block contents info)
2064 "Transcode a EXPORT-BLOCK element from Org to HTML.
2065 CONTENTS is nil. INFO is a plist holding contextual information."
2066 (when (string= (org-element-property :type export-block) "HTML")
2067 (org-remove-indentation (org-element-property :value export-block))))
2069 ;;;; Fixed Width
2071 (defun org-html-fixed-width (fixed-width contents info)
2072 "Transcode a FIXED-WIDTH element from Org to HTML.
2073 CONTENTS is nil. INFO is a plist holding contextual information."
2074 (format "<pre class=\"example\">\n%s</pre>"
2075 (org-html-do-format-code
2076 (org-remove-indentation
2077 (org-element-property :value fixed-width)))))
2079 ;;;; Footnote Reference
2081 (defun org-html-footnote-reference (footnote-reference contents info)
2082 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2083 CONTENTS is nil. INFO is a plist holding contextual information."
2084 (concat
2085 ;; Insert separator between two footnotes in a row.
2086 (let ((prev (org-export-get-previous-element footnote-reference info)))
2087 (when (eq (org-element-type prev) 'footnote-reference)
2088 org-html-footnote-separator))
2089 (cond
2090 ((not (org-export-footnote-first-reference-p footnote-reference info))
2091 (org-html-format-footnote-reference
2092 (org-export-get-footnote-number footnote-reference info)
2093 "IGNORED" 100))
2094 ;; Inline definitions are secondary strings.
2095 ((eq (org-element-property :type footnote-reference) 'inline)
2096 (org-html-format-footnote-reference
2097 (org-export-get-footnote-number footnote-reference info)
2098 "IGNORED" 1))
2099 ;; Non-inline footnotes definitions are full Org data.
2100 (t (org-html-format-footnote-reference
2101 (org-export-get-footnote-number footnote-reference info)
2102 "IGNORED" 1)))))
2104 ;;;; Headline
2106 (defun org-html-format-headline--wrap
2107 (headline info &optional format-function &rest extra-keys)
2108 "Transcode a HEADLINE element from Org to HTML.
2109 CONTENTS holds the contents of the headline. INFO is a plist
2110 holding contextual information."
2111 (let* ((level (+ (org-export-get-relative-level headline info)
2112 (1- org-html-toplevel-hlevel)))
2113 (headline-number (org-export-get-headline-number headline info))
2114 (section-number (and (not (org-export-low-level-p headline info))
2115 (org-export-numbered-headline-p headline info)
2116 (mapconcat 'number-to-string
2117 headline-number ".")))
2118 (todo (and (plist-get info :with-todo-keywords)
2119 (let ((todo (org-element-property :todo-keyword headline)))
2120 (and todo (org-export-data todo info)))))
2121 (todo-type (and todo (org-element-property :todo-type headline)))
2122 (priority (and (plist-get info :with-priority)
2123 (org-element-property :priority headline)))
2124 (text (org-export-data (org-element-property :title headline) info))
2125 (tags (and (plist-get info :with-tags)
2126 (org-export-get-tags headline info)))
2127 (headline-label (or (org-element-property :CUSTOM_ID headline)
2128 (concat "sec-" (mapconcat 'number-to-string
2129 headline-number "-"))))
2130 (format-function (cond
2131 ((functionp format-function) format-function)
2132 ((functionp org-html-format-headline-function)
2133 (function*
2134 (lambda (todo todo-type priority text tags
2135 &allow-other-keys)
2136 (funcall org-html-format-headline-function
2137 todo todo-type priority text tags))))
2138 (t 'org-html-format-headline))))
2139 (apply format-function
2140 todo todo-type priority text tags
2141 :headline-label headline-label :level level
2142 :section-number section-number extra-keys)))
2144 (defun org-html-headline (headline contents info)
2145 "Transcode a HEADLINE element from Org to HTML.
2146 CONTENTS holds the contents of the headline. INFO is a plist
2147 holding contextual information."
2148 ;; Empty contents?
2149 (setq contents (or contents ""))
2150 (let* ((numberedp (org-export-numbered-headline-p headline info))
2151 (level (org-export-get-relative-level headline info))
2152 (text (org-export-data (org-element-property :title headline) info))
2153 (todo (and (plist-get info :with-todo-keywords)
2154 (let ((todo (org-element-property :todo-keyword headline)))
2155 (and todo (org-export-data todo info)))))
2156 (todo-type (and todo (org-element-property :todo-type headline)))
2157 (tags (and (plist-get info :with-tags)
2158 (org-export-get-tags headline info)))
2159 (priority (and (plist-get info :with-priority)
2160 (org-element-property :priority headline)))
2161 (section-number (and (org-export-numbered-headline-p headline info)
2162 (mapconcat 'number-to-string
2163 (org-export-get-headline-number
2164 headline info) ".")))
2165 ;; Create the headline text.
2166 (full-text (org-html-format-headline--wrap headline info)))
2167 (cond
2168 ;; Case 1: This is a footnote section: ignore it.
2169 ((org-element-property :footnote-section-p headline) nil)
2170 ;; Case 2. This is a deep sub-tree: export it as a list item.
2171 ;; Also export as items headlines for which no section
2172 ;; format has been found.
2173 ((org-export-low-level-p headline info)
2174 ;; Build the real contents of the sub-tree.
2175 (let* ((type (if numberedp 'ordered 'unordered))
2176 (itemized-body (org-html-format-list-item
2177 contents type nil nil full-text)))
2178 (concat
2179 (and (org-export-first-sibling-p headline info)
2180 (org-html-begin-plain-list type))
2181 itemized-body
2182 (and (org-export-last-sibling-p headline info)
2183 (org-html-end-plain-list type)))))
2184 ;; Case 3. Standard headline. Export it as a section.
2186 (let* ((section-number (mapconcat 'number-to-string
2187 (org-export-get-headline-number
2188 headline info) "-"))
2189 (ids (remove 'nil
2190 (list (org-element-property :CUSTOM_ID headline)
2191 (concat "sec-" section-number)
2192 (org-element-property :ID headline))))
2193 (preferred-id (car ids))
2194 (extra-ids (cdr ids))
2195 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2196 (level1 (+ level (1- org-html-toplevel-hlevel)))
2197 (first-content (car (org-element-contents headline))))
2198 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2199 (if (= 1 (org-export-get-relative-level headline info))
2200 (plist-get info :html-container)
2201 "div")
2202 (format "outline-container-%s"
2203 (or (org-element-property :CUSTOM_ID headline)
2204 (concat "sec-" section-number)))
2205 (concat (format "outline-%d" level1) (and extra-class " ")
2206 extra-class)
2207 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2208 level1
2209 preferred-id
2210 (mapconcat
2211 (lambda (x)
2212 (let ((id (org-export-solidify-link-text
2213 (if (org-uuidgen-p x) (concat "ID-" x)
2214 x))))
2215 (org-html--anchor id)))
2216 extra-ids "")
2217 full-text
2218 level1)
2219 ;; When there is no section, pretend there is an empty
2220 ;; one to get the correct <div class="outline- ...>
2221 ;; which is needed by `org-info.js'.
2222 (if (not (eq (org-element-type first-content) 'section))
2223 (concat (org-html-section first-content "" info)
2224 contents)
2225 contents)
2226 (if (= 1 (org-export-get-relative-level headline info))
2227 (plist-get info :html-container)
2228 "div")))))))
2230 ;;;; Horizontal Rule
2232 (defun org-html-horizontal-rule (horizontal-rule contents info)
2233 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2234 CONTENTS is nil. INFO is a plist holding contextual information."
2235 "<hr/>")
2237 ;;;; Inline Src Block
2239 (defun org-html-inline-src-block (inline-src-block contents info)
2240 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2241 CONTENTS holds the contents of the item. INFO is a plist holding
2242 contextual information."
2243 (let* ((org-lang (org-element-property :language inline-src-block))
2244 (code (org-element-property :value inline-src-block)))
2245 (error "Cannot export inline src block")))
2247 ;;;; Inlinetask
2249 (defun org-html-format-section (text class &optional id)
2250 "Format a section with TEXT into a HTML div with CLASS and ID."
2251 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2252 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2254 (defun org-html-inlinetask (inlinetask contents info)
2255 "Transcode an INLINETASK element from Org to HTML.
2256 CONTENTS holds the contents of the block. INFO is a plist
2257 holding contextual information."
2258 (cond
2259 ;; If `org-html-format-inlinetask-function' is provided, call it
2260 ;; with appropriate arguments.
2261 ((functionp org-html-format-inlinetask-function)
2262 (let ((format-function
2263 (function*
2264 (lambda (todo todo-type priority text tags
2265 &key contents &allow-other-keys)
2266 (funcall org-html-format-inlinetask-function
2267 todo todo-type priority text tags contents)))))
2268 (org-html-format-headline--wrap
2269 inlinetask info format-function :contents contents)))
2270 ;; Otherwise, use a default template.
2271 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2272 (org-html-format-headline--wrap inlinetask info)
2273 contents))))
2275 ;;;; Italic
2277 (defun org-html-italic (italic contents info)
2278 "Transcode ITALIC from Org to HTML.
2279 CONTENTS is the text with italic markup. INFO is a plist holding
2280 contextual information."
2281 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2283 ;;;; Item
2285 (defun org-html-checkbox (checkbox)
2286 "Format CHECKBOX into HTML."
2287 (case checkbox (on "<code>[X]</code>")
2288 (off "<code>[&#xa0;]</code>")
2289 (trans "<code>[-]</code>")
2290 (t "")))
2292 (defun org-html-format-list-item (contents type checkbox
2293 &optional term-counter-id
2294 headline)
2295 "Format a list item into HTML."
2296 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2297 (concat
2298 (case type
2299 (ordered
2300 (let* ((counter term-counter-id)
2301 (extra (if counter (format " value=\"%s\"" counter) "")))
2302 (concat
2303 (format "<li%s>" extra)
2304 (when headline (concat headline "<br/>")))))
2305 (unordered
2306 (let* ((id term-counter-id)
2307 (extra (if id (format " id=\"%s\"" id) "")))
2308 (concat
2309 (format "<li%s>" extra)
2310 (when headline (concat headline "<br/>")))))
2311 (descriptive
2312 (let* ((term term-counter-id))
2313 (setq term (or term "(no term)"))
2314 ;; Check-boxes in descriptive lists are associated to tag.
2315 (concat (format "<dt> %s </dt>"
2316 (concat checkbox term))
2317 "<dd>"))))
2318 (unless (eq type 'descriptive) checkbox)
2319 contents
2320 (case type
2321 (ordered "</li>")
2322 (unordered "</li>")
2323 (descriptive "</dd>")))))
2325 (defun org-html-item (item contents info)
2326 "Transcode an ITEM element from Org to HTML.
2327 CONTENTS holds the contents of the item. INFO is a plist holding
2328 contextual information."
2329 (let* ((plain-list (org-export-get-parent item))
2330 (type (org-element-property :type plain-list))
2331 (counter (org-element-property :counter item))
2332 (checkbox (org-element-property :checkbox item))
2333 (tag (let ((tag (org-element-property :tag item)))
2334 (and tag (org-export-data tag info)))))
2335 (org-html-format-list-item
2336 contents type checkbox (or tag counter))))
2338 ;;;; Keyword
2340 (defun org-html-keyword (keyword contents info)
2341 "Transcode a KEYWORD element from Org to HTML.
2342 CONTENTS is nil. INFO is a plist holding contextual information."
2343 (let ((key (org-element-property :key keyword))
2344 (value (org-element-property :value keyword)))
2345 (cond
2346 ((string= key "HTML") value)
2347 ((string= key "TOC")
2348 (let ((value (downcase value)))
2349 (cond
2350 ((string-match "\\<headlines\\>" value)
2351 (let ((depth (or (and (string-match "[0-9]+" value)
2352 (string-to-number (match-string 0 value)))
2353 (plist-get info :with-toc))))
2354 (org-html-toc depth info)))
2355 ((string= "listings" value) (org-html-list-of-listings info))
2356 ((string= "tables" value) (org-html-list-of-tables info))))))))
2358 ;;;; Latex Environment
2360 (defun org-html-format-latex (latex-frag processing-type)
2361 "Format the LaTeX fragment LATEX-FRAG into HTML."
2362 (let ((cache-relpath "") (cache-dir "") bfn)
2363 (unless (eq processing-type 'mathjax)
2364 (setq bfn (buffer-file-name)
2365 cache-relpath
2366 (concat "ltxpng/"
2367 (file-name-sans-extension
2368 (file-name-nondirectory bfn)))
2369 cache-dir (file-name-directory bfn)))
2370 (with-temp-buffer
2371 (insert latex-frag)
2372 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2373 nil nil processing-type)
2374 (buffer-string))))
2376 (defun org-html-latex-environment (latex-environment contents info)
2377 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2378 CONTENTS is nil. INFO is a plist holding contextual information."
2379 (let ((processing-type (plist-get info :with-latex))
2380 (latex-frag (org-remove-indentation
2381 (org-element-property :value latex-environment)))
2382 (caption (org-export-data
2383 (org-export-get-caption latex-environment) info))
2384 (attr nil) ; FIXME
2385 (label (org-element-property :name latex-environment)))
2386 (cond
2387 ((memq processing-type '(t mathjax))
2388 (org-html-format-latex latex-frag 'mathjax))
2389 ((eq processing-type 'dvipng)
2390 (let* ((formula-link (org-html-format-latex
2391 latex-frag processing-type)))
2392 (when (and formula-link
2393 (string-match "file:\\([^]]*\\)" formula-link))
2394 (org-html-format-inline-image
2395 (match-string 1 formula-link) caption label attr t))))
2396 (t latex-frag))))
2398 ;;;; Latex Fragment
2400 (defun org-html-latex-fragment (latex-fragment contents info)
2401 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2402 CONTENTS is nil. INFO is a plist holding contextual information."
2403 (let ((latex-frag (org-element-property :value latex-fragment))
2404 (processing-type (plist-get info :with-latex)))
2405 (case processing-type
2406 ((t mathjax)
2407 (org-html-format-latex latex-frag 'mathjax))
2408 (dvipng
2409 (let* ((formula-link (org-html-format-latex
2410 latex-frag processing-type)))
2411 (when (and formula-link
2412 (string-match "file:\\([^]]*\\)" formula-link))
2413 (org-html-format-inline-image
2414 (match-string 1 formula-link)))))
2415 (t latex-frag))))
2417 ;;;; Line Break
2419 (defun org-html-line-break (line-break contents info)
2420 "Transcode a LINE-BREAK object from Org to HTML.
2421 CONTENTS is nil. INFO is a plist holding contextual information."
2422 "<br/>\n")
2424 ;;;; Link
2426 (defun org-html-link--inline-image (link desc info)
2427 "Return HTML code for an inline image.
2428 LINK is the link pointing to the inline image. INFO is a plist
2429 used as a communication channel.
2431 Inline images can have these attributes:
2433 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2434 (let* ((type (org-element-property :type link))
2435 (raw-path (org-element-property :path link))
2436 (path (cond ((member type '("http" "https"))
2437 (concat type ":" raw-path))
2438 ((file-name-absolute-p raw-path)
2439 (expand-file-name raw-path))
2440 (t raw-path)))
2441 (parent (org-export-get-parent-element link))
2442 (caption (org-export-data (org-export-get-caption parent) info))
2443 (label (org-element-property :name parent))
2444 (attrs (org-export-read-attribute :attr_html parent))
2445 (alt (plist-get attrs :alt))
2446 (width (plist-get attrs :width))
2447 (height (plist-get attrs :height))
2448 (options (plist-get attrs :options)))
2449 ;; Return proper string, depending on DISPOSITION.
2450 (org-html-format-inline-image
2451 path caption label
2452 (mapconcat 'identity
2453 (delq nil (list (if width (format "width=\"%s\"" width))
2454 (if alt (format "alt=\"%s\"" alt))
2455 (if height (format "height=\"%s\"" height))
2456 options)) " ")
2457 (org-html-standalone-image-p link info))))
2459 (defvar org-html-standalone-image-predicate)
2460 (defun org-html-standalone-image-p (element info &optional predicate)
2461 "Test if ELEMENT is a standalone image for the purpose HTML export.
2462 INFO is a plist holding contextual information.
2464 Return non-nil, if ELEMENT is of type paragraph and it's sole
2465 content, save for whitespaces, is a link that qualifies as an
2466 inline image.
2468 Return non-nil, if ELEMENT is of type link and it's containing
2469 paragraph has no other content save for leading and trailing
2470 whitespaces.
2472 Return nil, otherwise.
2474 Bind `org-html-standalone-image-predicate' to constrain
2475 paragraph further. For example, to check for only captioned
2476 standalone images, do the following.
2478 \(setq org-html-standalone-image-predicate
2479 \(lambda \(paragraph\)
2480 \(org-element-property :caption paragraph\)\)\)"
2481 (let ((paragraph (case (org-element-type element)
2482 (paragraph element)
2483 (link (and (org-export-inline-image-p
2484 element org-html-inline-image-rules)
2485 (org-export-get-parent element)))
2486 (t nil))))
2487 (when (eq (org-element-type paragraph) 'paragraph)
2488 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2489 (functionp org-html-standalone-image-predicate)))
2490 (funcall org-html-standalone-image-predicate paragraph))
2491 (let ((contents (org-element-contents paragraph)))
2492 (loop for x in contents
2493 with inline-image-count = 0
2494 always (cond
2495 ((eq (org-element-type x) 'plain-text)
2496 (not (org-string-nw-p x)))
2497 ((eq (org-element-type x) 'link)
2498 (when (org-export-inline-image-p
2499 x org-html-inline-image-rules)
2500 (= (incf inline-image-count) 1)))
2501 (t nil))))))))
2503 (defun org-html-link (link desc info)
2504 "Transcode a LINK object from Org to HTML.
2506 DESC is the description part of the link, or the empty string.
2507 INFO is a plist holding contextual information. See
2508 `org-export-data'."
2509 (let* ((link-org-files-as-html-maybe
2510 (function
2511 (lambda (raw-path info)
2512 "Treat links to `file.org' as links to `file.html', if needed.
2513 See `org-html-link-org-files-as-html'."
2514 (cond
2515 ((and org-html-link-org-files-as-html
2516 (string= ".org"
2517 (downcase (file-name-extension raw-path "."))))
2518 (concat (file-name-sans-extension raw-path) "."
2519 (plist-get info :html-extension)))
2520 (t raw-path)))))
2521 (type (org-element-property :type link))
2522 (raw-path (org-element-property :path link))
2523 ;; Ensure DESC really exists, or set it to nil.
2524 (desc (and (not (string= desc "")) desc))
2525 (path
2526 (cond
2527 ((member type '("http" "https" "ftp" "mailto"))
2528 (concat type ":" raw-path))
2529 ((string= type "file")
2530 ;; Treat links to ".org" files as ".html", if needed.
2531 (setq raw-path
2532 (funcall link-org-files-as-html-maybe raw-path info))
2533 ;; If file path is absolute, prepend it with protocol
2534 ;; component - "file://".
2535 (when (file-name-absolute-p raw-path)
2536 (setq raw-path
2537 (concat "file://" (expand-file-name raw-path))))
2538 ;; Add search option, if any. A search option can be
2539 ;; relative to a custom-id or a headline title. Any other
2540 ;; option is ignored.
2541 (let ((option (org-element-property :search-option link)))
2542 (cond ((not option) raw-path)
2543 ((eq (aref option 0) ?#) (concat raw-path option))
2544 ;; External fuzzy link: try to resolve it if path
2545 ;; belongs to current project, if any.
2546 ((eq (aref option 0) ?*)
2547 (concat
2548 raw-path
2549 (let ((numbers
2550 (org-publish-resolve-external-fuzzy-link
2551 (org-element-property :path link) option)))
2552 (and numbers (concat "#sec-"
2553 (mapconcat 'number-to-string
2554 numbers "-"))))))
2555 (t raw-path))))
2556 (t raw-path)))
2557 attributes protocol)
2558 ;; Extract attributes from parent's paragraph. HACK: Only do this
2559 ;; for the first link in parent. This is needed as long as
2560 ;; attributes cannot be set on a per link basis.
2561 (and (setq attributes
2562 (let ((parent (org-export-get-parent-element link)))
2563 (if (not (eq (org-element-map parent 'link 'identity info t)
2564 link))
2566 (let ((att (org-export-read-attribute :attr_html parent :options)))
2567 (unless (and desc att (string-match (regexp-quote att) desc))
2568 (or att ""))))))
2569 (unless (string= attributes "")
2570 (setq attributes (concat " " attributes))))
2571 (cond
2572 ;; Image file.
2573 ((and (or (eq t org-html-inline-images)
2574 (and org-html-inline-images (not desc)))
2575 (org-export-inline-image-p link org-html-inline-image-rules))
2576 (org-html-link--inline-image link desc info))
2577 ;; Radio target: Transcode target's contents and use them as
2578 ;; link's description.
2579 ((string= type "radio")
2580 (let ((destination (org-export-resolve-radio-link link info)))
2581 (when destination
2582 (format "<a href=\"#%s\"%s>%s</a>"
2583 (org-export-solidify-link-text path)
2584 attributes
2585 (org-export-data (org-element-contents destination) info)))))
2586 ;; Links pointing to a headline: Find destination and build
2587 ;; appropriate referencing command.
2588 ((member type '("custom-id" "fuzzy" "id"))
2589 (let ((destination (if (string= type "fuzzy")
2590 (org-export-resolve-fuzzy-link link info)
2591 (org-export-resolve-id-link link info))))
2592 (case (org-element-type destination)
2593 ;; ID link points to an external file.
2594 (plain-text
2595 (let ((fragment (concat "ID-" path))
2596 ;; Treat links to ".org" files as ".html", if needed.
2597 (path (funcall link-org-files-as-html-maybe
2598 destination info)))
2599 (format "<a href=\"%s#%s\"%s>%s</a>"
2600 path fragment attributes (or desc destination))))
2601 ;; Fuzzy link points nowhere.
2602 ((nil)
2603 (format "<i>%s</i>"
2604 (or desc
2605 (org-export-data
2606 (org-element-property :raw-link link) info))))
2607 ;; Fuzzy link points to an invisible target.
2608 (keyword nil)
2609 ;; Link points to a headline.
2610 (headline
2611 (let ((href
2612 ;; What href to use?
2613 (cond
2614 ;; Case 1: Headline is linked via it's CUSTOM_ID
2615 ;; property. Use CUSTOM_ID.
2616 ((string= type "custom-id")
2617 (org-element-property :CUSTOM_ID destination))
2618 ;; Case 2: Headline is linked via it's ID property
2619 ;; or through other means. Use the default href.
2620 ((member type '("id" "fuzzy"))
2621 (format "sec-%s"
2622 (mapconcat 'number-to-string
2623 (org-export-get-headline-number
2624 destination info) "-")))
2625 (t (error "Shouldn't reach here"))))
2626 ;; What description to use?
2627 (desc
2628 ;; Case 1: Headline is numbered and LINK has no
2629 ;; description or LINK's description matches
2630 ;; headline's title. Display section number.
2631 (if (and (org-export-numbered-headline-p destination info)
2632 (or (not desc)
2633 (string= desc (org-element-property
2634 :raw-value destination))))
2635 (mapconcat 'number-to-string
2636 (org-export-get-headline-number
2637 destination info) ".")
2638 ;; Case 2: Either the headline is un-numbered or
2639 ;; LINK has a custom description. Display LINK's
2640 ;; description or headline's title.
2641 (or desc (org-export-data (org-element-property
2642 :title destination) info)))))
2643 (format "<a href=\"#%s\"%s>%s</a>"
2644 (org-export-solidify-link-text href) attributes desc)))
2645 ;; Fuzzy link points to a target. Do as above.
2647 (let ((path (org-export-solidify-link-text path)) number)
2648 (unless desc
2649 (setq number (cond
2650 ((org-html-standalone-image-p destination info)
2651 (org-export-get-ordinal
2652 (assoc 'link (org-element-contents destination))
2653 info 'link 'org-html-standalone-image-p))
2654 (t (org-export-get-ordinal destination info))))
2655 (setq desc (when number
2656 (if (atom number) (number-to-string number)
2657 (mapconcat 'number-to-string number ".")))))
2658 (format "<a href=\"#%s\"%s>%s</a>"
2659 path attributes (or desc "No description for this link")))))))
2660 ;; Coderef: replace link with the reference name or the
2661 ;; equivalent line number.
2662 ((string= type "coderef")
2663 (let ((fragment (concat "coderef-" path)))
2664 (format "<a href=\"#%s\"%s%s>%s</a>"
2665 fragment
2666 (org-trim
2667 (format (concat "class=\"coderef\""
2668 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2669 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2670 fragment fragment))
2671 attributes
2672 (format (org-export-get-coderef-format path desc)
2673 (org-export-resolve-coderef path info)))))
2674 ;; Link type is handled by a special function.
2675 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2676 (funcall protocol (org-link-unescape path) desc 'html))
2677 ;; External link with a description part.
2678 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2679 ;; External link without a description part.
2680 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2681 ;; No path, only description. Try to do something useful.
2682 (t (format "<i>%s</i>" desc)))))
2684 ;;;; Paragraph
2686 (defun org-html-paragraph (paragraph contents info)
2687 "Transcode a PARAGRAPH element from Org to HTML.
2688 CONTENTS is the contents of the paragraph, as a string. INFO is
2689 the plist used as a communication channel."
2690 (let* ((parent (org-export-get-parent paragraph))
2691 (parent-type (org-element-type parent))
2692 (style '((footnote-definition " class=\"footpara\"")))
2693 (extra (or (cadr (assoc parent-type style)) "")))
2694 (cond
2695 ((and (eq (org-element-type parent) 'item)
2696 (= (org-element-property :begin paragraph)
2697 (org-element-property :contents-begin parent)))
2698 ;; leading paragraph in a list item have no tags
2699 contents)
2700 ((org-html-standalone-image-p paragraph info)
2701 ;; standalone image
2702 contents)
2703 (t (format "<p%s>\n%s</p>" extra contents)))))
2705 ;;;; Plain List
2707 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2708 ;; the correct value for the item counter
2709 (defun org-html-begin-plain-list (type &optional arg1)
2710 "Insert the beginning of the HTML list depending on TYPE.
2711 When ARG1 is a string, use it as the start parameter for ordered
2712 lists."
2713 (case type
2714 (ordered
2715 (format "<ol class=\"org-ol\"%s>"
2716 (if arg1 (format " start=\"%d\"" arg1) "")))
2717 (unordered "<ul class=\"org-ul\">")
2718 (descriptive "<dl class=\"org-dl\">")))
2720 (defun org-html-end-plain-list (type)
2721 "Insert the end of the HTML list depending on TYPE."
2722 (case type
2723 (ordered "</ol>")
2724 (unordered "</ul>")
2725 (descriptive "</dl>")))
2727 (defun org-html-plain-list (plain-list contents info)
2728 "Transcode a PLAIN-LIST element from Org to HTML.
2729 CONTENTS is the contents of the list. INFO is a plist holding
2730 contextual information."
2731 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2732 (type (org-element-property :type plain-list)))
2733 (format "%s\n%s%s"
2734 (org-html-begin-plain-list type)
2735 contents (org-html-end-plain-list type))))
2737 ;;;; Plain Text
2739 (defun org-html-convert-special-strings (string)
2740 "Convert special characters in STRING to HTML."
2741 (let ((all org-html-special-string-regexps)
2742 e a re rpl start)
2743 (while (setq a (pop all))
2744 (setq re (car a) rpl (cdr a) start 0)
2745 (while (string-match re string start)
2746 (setq string (replace-match rpl t nil string))))
2747 string))
2749 (defun org-html-encode-plain-text (text)
2750 "Convert plain text characters from TEXT to HTML equivalent.
2751 Possible conversions are set in `org-html-protect-char-alist'."
2752 (mapc
2753 (lambda (pair)
2754 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2755 org-html-protect-char-alist)
2756 text)
2758 (defun org-html-plain-text (text info)
2759 "Transcode a TEXT string from Org to HTML.
2760 TEXT is the string to transcode. INFO is a plist holding
2761 contextual information."
2762 (let ((output text))
2763 ;; Protect following characters: <, >, &.
2764 (setq output (org-html-encode-plain-text output))
2765 ;; Handle smart quotes. Be sure to provide original string since
2766 ;; OUTPUT may have been modified.
2767 (when (plist-get info :with-smart-quotes)
2768 (setq output (org-export-activate-smart-quotes output :html info text)))
2769 ;; Handle special strings.
2770 (when (plist-get info :with-special-strings)
2771 (setq output (org-html-convert-special-strings output)))
2772 ;; Handle break preservation if required.
2773 (when (plist-get info :preserve-breaks)
2774 (setq output
2775 (replace-regexp-in-string
2776 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2777 ;; Return value.
2778 output))
2781 ;; Planning
2783 (defun org-html-planning (planning contents info)
2784 "Transcode a PLANNING element from Org to HTML.
2785 CONTENTS is nil. INFO is a plist used as a communication
2786 channel."
2787 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2788 (format
2789 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2790 (mapconcat
2791 'identity
2792 (delq nil
2793 (list
2794 (let ((closed (org-element-property :closed planning)))
2795 (when closed
2796 (format span-fmt org-closed-string
2797 (org-translate-time
2798 (org-element-property :raw-value closed)))))
2799 (let ((deadline (org-element-property :deadline planning)))
2800 (when deadline
2801 (format span-fmt org-deadline-string
2802 (org-translate-time
2803 (org-element-property :raw-value deadline)))))
2804 (let ((scheduled (org-element-property :scheduled planning)))
2805 (when scheduled
2806 (format span-fmt org-scheduled-string
2807 (org-translate-time
2808 (org-element-property :raw-value scheduled)))))))
2809 " "))))
2811 ;;;; Property Drawer
2813 (defun org-html-property-drawer (property-drawer contents info)
2814 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2815 CONTENTS is nil. INFO is a plist holding contextual
2816 information."
2817 ;; The property drawer isn't exported but we want separating blank
2818 ;; lines nonetheless.
2821 ;;;; Quote Block
2823 (defun org-html-quote-block (quote-block contents info)
2824 "Transcode a QUOTE-BLOCK element from Org to HTML.
2825 CONTENTS holds the contents of the block. INFO is a plist
2826 holding contextual information."
2827 (format "<blockquote>\n%s</blockquote>" contents))
2829 ;;;; Quote Section
2831 (defun org-html-quote-section (quote-section contents info)
2832 "Transcode a QUOTE-SECTION element from Org to HTML.
2833 CONTENTS is nil. INFO is a plist holding contextual information."
2834 (let ((value (org-remove-indentation
2835 (org-element-property :value quote-section))))
2836 (when value (format "<pre>\n%s</pre>" value))))
2838 ;;;; Section
2840 (defun org-html-section (section contents info)
2841 "Transcode a SECTION element from Org to HTML.
2842 CONTENTS holds the contents of the section. INFO is a plist
2843 holding contextual information."
2844 (let ((parent (org-export-get-parent-headline section)))
2845 ;; Before first headline: no container, just return CONTENTS.
2846 (if (not parent) contents
2847 ;; Get div's class and id references.
2848 (let* ((class-num (+ (org-export-get-relative-level parent info)
2849 (1- org-html-toplevel-hlevel)))
2850 (section-number
2851 (mapconcat
2852 'number-to-string
2853 (org-export-get-headline-number parent info) "-")))
2854 ;; Build return value.
2855 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2856 class-num
2857 (or (org-element-property :CUSTOM_ID parent) section-number)
2858 contents)))))
2860 ;;;; Radio Target
2862 (defun org-html-radio-target (radio-target text info)
2863 "Transcode a RADIO-TARGET object from Org to HTML.
2864 TEXT is the text of the target. INFO is a plist holding
2865 contextual information."
2866 (let ((id (org-export-solidify-link-text
2867 (org-element-property :value radio-target))))
2868 (org-html--anchor id text)))
2870 ;;;; Special Block
2872 (defun org-html-special-block (special-block contents info)
2873 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2874 CONTENTS holds the contents of the block. INFO is a plist
2875 holding contextual information."
2876 (format "<div class=\"%s\">\n%s\n</div>"
2877 (downcase (org-element-property :type special-block))
2878 contents))
2880 ;;;; Src Block
2882 (defun org-html-src-block (src-block contents info)
2883 "Transcode a SRC-BLOCK element from Org to HTML.
2884 CONTENTS holds the contents of the item. INFO is a plist holding
2885 contextual information."
2886 (if (org-export-read-attribute :attr_html src-block :textarea)
2887 (org-html--textarea-block src-block)
2888 (let ((lang (org-element-property :language src-block))
2889 (caption (org-export-get-caption src-block))
2890 (code (org-html-format-code src-block info))
2891 (label (let ((lbl (org-element-property :name src-block)))
2892 (if (not lbl) ""
2893 (format " id=\"%s\""
2894 (org-export-solidify-link-text lbl))))))
2895 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2896 (format
2897 "<div class=\"org-src-container\">\n%s%s\n</div>"
2898 (if (not caption) ""
2899 (format "<label class=\"org-src-name\">%s</label>"
2900 (org-export-data caption info)))
2901 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2903 ;;;; Statistics Cookie
2905 (defun org-html-statistics-cookie (statistics-cookie contents info)
2906 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2907 CONTENTS is nil. INFO is a plist holding contextual information."
2908 (let ((cookie-value (org-element-property :value statistics-cookie)))
2909 (format "<code>%s</code>" cookie-value)))
2911 ;;;; Strike-Through
2913 (defun org-html-strike-through (strike-through contents info)
2914 "Transcode STRIKE-THROUGH from Org to HTML.
2915 CONTENTS is the text with strike-through markup. INFO is a plist
2916 holding contextual information."
2917 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2918 contents))
2920 ;;;; Subscript
2922 (defun org-html-subscript (subscript contents info)
2923 "Transcode a SUBSCRIPT object from Org to HTML.
2924 CONTENTS is the contents of the object. INFO is a plist holding
2925 contextual information."
2926 (format "<sub>%s</sub>" contents))
2928 ;;;; Superscript
2930 (defun org-html-superscript (superscript contents info)
2931 "Transcode a SUPERSCRIPT object from Org to HTML.
2932 CONTENTS is the contents of the object. INFO is a plist holding
2933 contextual information."
2934 (format "<sup>%s</sup>" contents))
2936 ;;;; Tabel Cell
2938 (defun org-html-table-cell (table-cell contents info)
2939 "Transcode a TABLE-CELL element from Org to HTML.
2940 CONTENTS is nil. INFO is a plist used as a communication
2941 channel."
2942 (let* ((table-row (org-export-get-parent table-cell))
2943 (table (org-export-get-parent-table table-cell))
2944 (cell-attrs
2945 (if (not org-html-table-align-individual-fields) ""
2946 (format (if (and (boundp 'org-html-format-table-no-css)
2947 org-html-format-table-no-css)
2948 " align=\"%s\"" " class=\"%s\"")
2949 (org-export-table-cell-alignment table-cell info)))))
2950 (when (or (not contents) (string= "" (org-trim contents)))
2951 (setq contents "&#xa0;"))
2952 (cond
2953 ((and (org-export-table-has-header-p table info)
2954 (= 1 (org-export-table-row-group table-row info)))
2955 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2956 contents (cdr org-html-table-header-tags)))
2957 ((and org-html-table-use-header-tags-for-first-column
2958 (zerop (cdr (org-export-table-cell-address table-cell info))))
2959 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2960 contents (cdr org-html-table-header-tags)))
2961 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2962 contents (cdr org-html-table-data-tags))))))
2964 ;;;; Table Row
2966 (defun org-html-table-row (table-row contents info)
2967 "Transcode a TABLE-ROW element from Org to HTML.
2968 CONTENTS is the contents of the row. INFO is a plist used as a
2969 communication channel."
2970 ;; Rules are ignored since table separators are deduced from
2971 ;; borders of the current row.
2972 (when (eq (org-element-property :type table-row) 'standard)
2973 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2974 (row-number (org-export-table-row-number table-row info))
2975 (start-rowgroup-p
2976 (org-export-table-row-starts-rowgroup-p table-row info))
2977 (end-rowgroup-p
2978 (org-export-table-row-ends-rowgroup-p table-row info))
2979 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2980 ;; but should be set so that `org-html-table-row-tags' can
2981 ;; use them (see the docstring of this variable.)
2982 (top-row-p (and (equal start-rowgroup-p '(top))
2983 (equal end-rowgroup-p '(below top))))
2984 (bottom-row-p (and (equal start-rowgroup-p '(above))
2985 (equal end-rowgroup-p '(bottom above))))
2986 (rowgroup-tags
2987 (cond
2988 ;; Case 1: Row belongs to second or subsequent rowgroups.
2989 ((not (= 1 rowgroup-number))
2990 '("<tbody>" . "\n</tbody>"))
2991 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2992 ((org-export-table-has-header-p
2993 (org-export-get-parent-table table-row) info)
2994 '("<thead>" . "\n</thead>"))
2995 ;; Case 2: Row is from first and only row group.
2996 (t '("<tbody>" . "\n</tbody>")))))
2997 (concat
2998 ;; Begin a rowgroup?
2999 (when start-rowgroup-p (car rowgroup-tags))
3000 ;; Actual table row
3001 (concat "\n" (eval (car org-html-table-row-tags))
3002 contents
3003 "\n"
3004 (eval (cdr org-html-table-row-tags)))
3005 ;; End a rowgroup?
3006 (when end-rowgroup-p (cdr rowgroup-tags))))))
3008 ;;;; Table
3010 (defun org-html-table-first-row-data-cells (table info)
3011 "Transcode the first row of TABLE.
3012 INFO is a plist used as a communication channel."
3013 (let ((table-row
3014 (org-element-map table 'table-row
3015 (lambda (row)
3016 (unless (eq (org-element-property :type row) 'rule) row))
3017 info 'first-match))
3018 (special-column-p (org-export-table-has-special-column-p table)))
3019 (if (not special-column-p) (org-element-contents table-row)
3020 (cdr (org-element-contents table-row)))))
3022 (defun org-html-table--table.el-table (table info)
3023 "Format table.el tables into HTML.
3024 INFO is a plist used as a communication channel."
3025 (when (eq (org-element-property :type table) 'table.el)
3026 (require 'table)
3027 (let ((outbuf (with-current-buffer
3028 (get-buffer-create "*org-export-table*")
3029 (erase-buffer) (current-buffer))))
3030 (with-temp-buffer
3031 (insert (org-element-property :value table))
3032 (goto-char 1)
3033 (re-search-forward "^[ \t]*|[^|]" nil t)
3034 (table-generate-source 'html outbuf))
3035 (with-current-buffer outbuf
3036 (prog1 (org-trim (buffer-string))
3037 (kill-buffer) )))))
3039 (defun org-html-table (table contents info)
3040 "Transcode a TABLE element from Org to HTML.
3041 CONTENTS is the contents of the table. INFO is a plist holding
3042 contextual information."
3043 (case (org-element-property :type table)
3044 ;; Case 1: table.el table. Convert it using appropriate tools.
3045 (table.el (org-html-table--table.el-table table info))
3046 ;; Case 2: Standard table.
3048 (let* ((label (org-element-property :name table))
3049 (caption (org-export-get-caption table))
3050 (attributes
3051 (org-export-read-attribute :attr_html table :options))
3052 (alignspec
3053 (if (and (boundp 'org-html-format-table-no-css)
3054 org-html-format-table-no-css)
3055 "align=\"%s\"" "class=\"%s\""))
3056 (table-column-specs
3057 (function
3058 (lambda (table info)
3059 (mapconcat
3060 (lambda (table-cell)
3061 (let ((alignment (org-export-table-cell-alignment
3062 table-cell info)))
3063 (concat
3064 ;; Begin a colgroup?
3065 (when (org-export-table-cell-starts-colgroup-p
3066 table-cell info)
3067 "\n<colgroup>")
3068 ;; Add a column. Also specify it's alignment.
3069 (format "\n<col %s/>" (format alignspec alignment))
3070 ;; End a colgroup?
3071 (when (org-export-table-cell-ends-colgroup-p
3072 table-cell info)
3073 "\n</colgroup>"))))
3074 (org-html-table-first-row-data-cells table info) "\n"))))
3075 (table-attributes
3076 (let ((table-tag (plist-get info :html-table-tag)))
3077 (concat
3078 (and (string-match "<table\\(.*\\)>" table-tag)
3079 (match-string 1 table-tag))
3080 (and label (format " id=\"%s\""
3081 (org-export-solidify-link-text label)))
3082 (unless (string= attributes "")
3083 (concat " " attributes))))))
3084 ;; Remove last blank line.
3085 (setq contents (substring contents 0 -1))
3086 (format "<table%s>\n%s\n%s\n%s\n</table>"
3087 table-attributes
3088 (if (not caption) ""
3089 (format "<caption>%s</caption>"
3090 (org-export-data caption info)))
3091 (funcall table-column-specs table info)
3092 contents)))))
3094 ;;;; Target
3096 (defun org-html-target (target contents info)
3097 "Transcode a TARGET object from Org to HTML.
3098 CONTENTS is nil. INFO is a plist holding contextual
3099 information."
3100 (let ((id (org-export-solidify-link-text
3101 (org-element-property :value target))))
3102 (org-html--anchor id)))
3104 ;;;; Timestamp
3106 (defun org-html-timestamp (timestamp contents info)
3107 "Transcode a TIMESTAMP object from Org to HTML.
3108 CONTENTS is nil. INFO is a plist holding contextual
3109 information."
3110 (let ((value (org-html-plain-text
3111 (org-timestamp-translate timestamp) info)))
3112 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3113 (replace-regexp-in-string "--" "&#x2013;" value))))
3115 ;;;; Underline
3117 (defun org-html-underline (underline contents info)
3118 "Transcode UNDERLINE from Org to HTML.
3119 CONTENTS is the text with underline markup. INFO is a plist
3120 holding contextual information."
3121 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3122 contents))
3124 ;;;; Verbatim
3126 (defun org-html-verbatim (verbatim contents info)
3127 "Transcode VERBATIM from Org to HTML.
3128 CONTENTS is nil. INFO is a plist holding contextual
3129 information."
3130 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3131 (org-html-plain-text (org-element-property :value verbatim) info)))
3133 ;;;; Verse Block
3135 (defun org-html-verse-block (verse-block contents info)
3136 "Transcode a VERSE-BLOCK element from Org to HTML.
3137 CONTENTS is verse block contents. INFO is a plist holding
3138 contextual information."
3139 ;; Replace each newline character with line break. Also replace
3140 ;; each blank line with a line break.
3141 (setq contents (replace-regexp-in-string
3142 "^ *\\\\\\\\$" "<br/>\n"
3143 (replace-regexp-in-string
3144 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3145 ;; Replace each white space at beginning of a line with a
3146 ;; non-breaking space.
3147 (while (string-match "^[ \t]+" contents)
3148 (let* ((num-ws (length (match-string 0 contents)))
3149 (ws (let (out) (dotimes (i num-ws out)
3150 (setq out (concat out "&#xa0;"))))))
3151 (setq contents (replace-match ws nil t contents))))
3152 (format "<p class=\"verse\">\n%s</p>" contents))
3155 ;;; Filter Functions
3157 (defun org-html-final-function (contents backend info)
3158 "Filter to indent the HTML and convert HTML entities."
3159 (with-temp-buffer
3160 (insert contents)
3161 (set-auto-mode t)
3162 (if org-html-indent
3163 (indent-region (point-min) (point-max)))
3164 (when org-html-use-unicode-chars
3165 (require 'mm-url)
3166 (mm-url-decode-entities))
3167 (buffer-substring-no-properties (point-min) (point-max))))
3170 ;;; End-user functions
3172 ;;;###autoload
3173 (defun org-html-export-as-html
3174 (&optional async subtreep visible-only body-only ext-plist)
3175 "Export current buffer to an HTML buffer.
3177 If narrowing is active in the current buffer, only export its
3178 narrowed part.
3180 If a region is active, export that region.
3182 A non-nil optional argument ASYNC means the process should happen
3183 asynchronously. The resulting buffer should be accessible
3184 through the `org-export-stack' interface.
3186 When optional argument SUBTREEP is non-nil, export the sub-tree
3187 at point, extracting information from the headline properties
3188 first.
3190 When optional argument VISIBLE-ONLY is non-nil, don't export
3191 contents of hidden elements.
3193 When optional argument BODY-ONLY is non-nil, only write code
3194 between \"<body>\" and \"</body>\" tags.
3196 EXT-PLIST, when provided, is a property list with external
3197 parameters overriding Org default settings, but still inferior to
3198 file-local settings.
3200 Export is done in a buffer named \"*Org HTML Export*\", which
3201 will be displayed when `org-export-show-temporary-export-buffer'
3202 is non-nil."
3203 (interactive)
3204 (if async
3205 (org-export-async-start
3206 (lambda (output)
3207 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3208 (erase-buffer)
3209 (insert output)
3210 (goto-char (point-min))
3211 (set-auto-mode t)
3212 (org-export-add-to-stack (current-buffer) 'html)))
3213 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3214 (let ((outbuf (org-export-to-buffer
3215 'html "*Org HTML Export*"
3216 subtreep visible-only body-only ext-plist)))
3217 ;; Set major mode.
3218 (with-current-buffer outbuf (set-auto-mode t))
3219 (when org-export-show-temporary-export-buffer
3220 (switch-to-buffer-other-window outbuf)))))
3222 ;;;###autoload
3223 (defun org-html-convert-region-to-html ()
3224 "Assume the current region has org-mode syntax, and convert it to HTML.
3225 This can be used in any buffer. For example, you can write an
3226 itemized list in org-mode syntax in an HTML buffer and use this
3227 command to convert it."
3228 (interactive)
3229 (org-export-replace-region-by 'html))
3231 ;;;###autoload
3232 (defun org-html-export-to-html
3233 (&optional async subtreep visible-only body-only ext-plist)
3234 "Export current buffer to a HTML file.
3236 If narrowing is active in the current buffer, only export its
3237 narrowed part.
3239 If a region is active, export that region.
3241 A non-nil optional argument ASYNC means the process should happen
3242 asynchronously. The resulting file should be accessible through
3243 the `org-export-stack' interface.
3245 When optional argument SUBTREEP is non-nil, export the sub-tree
3246 at point, extracting information from the headline properties
3247 first.
3249 When optional argument VISIBLE-ONLY is non-nil, don't export
3250 contents of hidden elements.
3252 When optional argument BODY-ONLY is non-nil, only write code
3253 between \"<body>\" and \"</body>\" tags.
3255 EXT-PLIST, when provided, is a property list with external
3256 parameters overriding Org default settings, but still inferior to
3257 file-local settings.
3259 Return output file's name."
3260 (interactive)
3261 (let* ((extension (concat "." org-html-extension))
3262 (file (org-export-output-file-name extension subtreep))
3263 (org-export-coding-system org-html-coding-system))
3264 (if async
3265 (org-export-async-start
3266 (lambda (f) (org-export-add-to-stack f 'html))
3267 (let ((org-export-coding-system org-html-coding-system))
3268 `(expand-file-name
3269 (org-export-to-file
3270 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3271 (let ((org-export-coding-system org-html-coding-system))
3272 (org-export-to-file
3273 'html file subtreep visible-only body-only ext-plist)))))
3275 ;;;###autoload
3276 (defun org-html-publish-to-html (plist filename pub-dir)
3277 "Publish an org file to HTML.
3279 FILENAME is the filename of the Org file to be published. PLIST
3280 is the property list for the given project. PUB-DIR is the
3281 publishing directory.
3283 Return output file name."
3284 (org-publish-org-to 'html filename
3285 (concat "." (or (plist-get plist :html-extension)
3286 org-html-extension "html"))
3287 plist pub-dir))
3290 ;;; FIXME
3292 ;;;; org-format-table-html
3293 ;;;; org-format-org-table-html
3294 ;;;; org-format-table-table-html
3295 ;;;; org-table-number-fraction
3296 ;;;; org-table-number-regexp
3297 ;;;; org-html-table-caption-above
3298 ;;;; org-html-inline-image-extensions
3299 ;;;; org-export-preferred-target-alist
3300 ;;;; class for anchors
3301 ;;;; org-export-mark-todo-in-toc
3302 ;;;; org-html-format-org-link
3303 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3304 ;;;; alt = (file-name-nondirectory path)
3306 (provide 'ox-html)
3308 ;; Local variables:
3309 ;; generated-autoload-file: "org-loaddefs.el"
3310 ;; End:
3312 ;;; ox-html.el ends here