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