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