Merge branch 'maint'
[org-mode.git] / lisp / ox-html.el
blobef7d15a105716af9ea0a5c0028595efa7c3c097c
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements a HTML back-end for Org generic exporter.
26 ;; To test it, run:
28 ;; M-x org-html-export-as-html
30 ;; in an Org mode buffer. See ox.el for more details on how this
31 ;; exporter works.
33 ;;; Code:
35 ;;; Dependencies
37 (require 'ox)
38 (require 'ox-publish)
39 (require 'format-spec)
40 (eval-when-compile (require 'cl) (require 'table))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file "org-id" (id))
46 (declare-function htmlize-region "ext:htmlize" (beg end))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label))
49 (declare-function mm-url-decode-entities "mm-url" ())
51 ;;; Define Back-End
53 (org-export-define-backend 'html
54 '((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (paragraph . org-html-paragraph)
80 (plain-list . org-html-plain-list)
81 (plain-text . org-html-plain-text)
82 (planning . org-html-planning)
83 (property-drawer . org-html-property-drawer)
84 (quote-block . org-html-quote-block)
85 (quote-section . org-html-quote-section)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :export-block "HTML"
104 :filters-alist '((:filter-options . org-html-infojs-install-script)
105 (:filter-final-output . org-html-final-function))
106 :menu-entry
107 '(?h "Export to HTML"
108 ((?H "As HTML buffer" org-html-export-as-html)
109 (?h "As HTML file" org-html-export-to-html)
110 (?o "As HTML file and open"
111 (lambda (a s v b)
112 (if a (org-html-export-to-html t s v b)
113 (org-open-file (org-html-export-to-html nil s v b)))))))
114 :options-alist
115 '((:html-extension nil nil org-html-extension)
116 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
117 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
118 (:html-container "HTML_CONTAINER" nil org-html-container-element)
119 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
120 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
121 (:html-mathjax "HTML_MATHJAX" nil "" space)
122 (:html-postamble nil "html-postamble" org-html-postamble)
123 (:html-preamble nil "html-preamble" org-html-preamble)
124 (:html-head "HTML_HEAD" nil org-html-head newline)
125 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
126 (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
127 (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
128 (:html-table-attributes nil nil org-html-table-default-attributes)
129 (:html-table-row-tags nil nil org-html-table-row-tags)
130 (:html-xml-declaration nil nil org-html-xml-declaration)
131 (:html-inline-images nil nil org-html-inline-images)
132 (:infojs-opt "INFOJS_OPT" nil nil)
133 ;; Redefine regular options.
134 (:creator "CREATOR" nil org-html-creator-string)
135 (:with-latex nil "tex" org-html-with-latex)))
138 ;;; Internal Variables
140 (defvar org-html-format-table-no-css)
141 (defvar htmlize-buffer-places) ; from htmlize.el
143 (defvar org-html--pre/postamble-class "status"
144 "CSS class used for pre/postamble")
146 (defconst org-html-special-string-regexps
147 '(("\\\\-" . "&#x00ad;") ; shy
148 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
149 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
150 ("\\.\\.\\." . "&#x2026;")) ; hellip
151 "Regular expressions for special string conversion.")
153 (defconst org-html-scripts
154 "<script type=\"text/javascript\">
156 @licstart The following is the entire license notice for the
157 JavaScript code in this tag.
159 Copyright (C) 2012 Free Software Foundation, Inc.
161 The JavaScript code in this tag is free software: you can
162 redistribute it and/or modify it under the terms of the GNU
163 General Public License (GNU GPL) as published by the Free Software
164 Foundation, either version 3 of the License, or (at your option)
165 any later version. The code is distributed WITHOUT ANY WARRANTY;
166 without even the implied warranty of MERCHANTABILITY or FITNESS
167 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
169 As additional permission under GNU GPL version 3 section 7, you
170 may distribute non-source (e.g., minimized or compacted) forms of
171 that code without the copy of the GNU GPL normally required by
172 section 4, provided you include this license notice and a URL
173 through which recipients can access the Corresponding Source.
176 @licend The above is the entire license notice
177 for the JavaScript code in this tag.
179 <!--/*--><![CDATA[/*><!--*/
180 function CodeHighlightOn(elem, id)
182 var target = document.getElementById(id);
183 if(null != target) {
184 elem.cacheClassElem = elem.className;
185 elem.cacheClassTarget = target.className;
186 target.className = \"code-highlighted\";
187 elem.className = \"code-highlighted\";
190 function CodeHighlightOff(elem, id)
192 var target = document.getElementById(id);
193 if(elem.cacheClassElem)
194 elem.className = elem.cacheClassElem;
195 if(elem.cacheClassTarget)
196 target.className = elem.cacheClassTarget;
198 /*]]>*///-->
199 </script>"
200 "Basic JavaScript that is needed by HTML files produced by Org mode.")
202 (defconst org-html-style-default
203 "<style type=\"text/css\">
204 <!--/*--><![CDATA[/*><!--*/
205 .title { text-align: center; }
206 .todo { font-family: monospace; color: red; }
207 .done { color: green; }
208 .tag { background-color: #eee; font-family: monospace;
209 padding: 2px; font-size: 80%; font-weight: normal; }
210 .timestamp { color: #bebebe; }
211 .timestamp-kwd { color: #5f9ea0; }
212 .right { margin-left: auto; margin-right: 0px; text-align: right; }
213 .left { margin-left: 0px; margin-right: auto; text-align: left; }
214 .center { margin-left: auto; margin-right: auto; text-align: center; }
215 .underline { text-decoration: underline; }
216 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
217 p.verse { margin-left: 3%; }
218 pre {
219 border: 1px solid #ccc;
220 box-shadow: 3px 3px 3px #eee;
221 padding: 8pt;
222 font-family: monospace;
223 overflow: auto;
224 margin: 1.2em;
226 pre.src {
227 position: relative;
228 overflow: visible;
229 padding-top: 1.2em;
231 pre.src:before {
232 display: none;
233 position: absolute;
234 background-color: white;
235 top: -10px;
236 right: 10px;
237 padding: 3px;
238 border: 1px solid black;
240 pre.src:hover:before { display: inline;}
241 pre.src-sh:before { content: 'sh'; }
242 pre.src-bash:before { content: 'sh'; }
243 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
244 pre.src-R:before { content: 'R'; }
245 pre.src-perl:before { content: 'Perl'; }
246 pre.src-java:before { content: 'Java'; }
247 pre.src-sql:before { content: 'SQL'; }
249 table { border-collapse:collapse; }
250 td, th { vertical-align:top; }
251 th.right { text-align: center; }
252 th.left { text-align: center; }
253 th.center { text-align: center; }
254 td.right { text-align: right; }
255 td.left { text-align: left; }
256 td.center { text-align: center; }
257 dt { font-weight: bold; }
258 .footpara:nth-child(2) { display: inline; }
259 .footpara { display: block; }
260 .footdef { margin-bottom: 1em; }
261 .figure { padding: 1em; }
262 .figure p { text-align: center; }
263 .inlinetask {
264 padding: 10px;
265 border: 2px solid gray;
266 margin: 10px;
267 background: #ffffcc;
269 #org-div-home-and-up
270 { text-align: right; font-size: 70%; white-space: nowrap; }
271 textarea { overflow-x: auto; }
272 .linenr { font-size: smaller }
273 .code-highlighted { background-color: #ffff00; }
274 .org-info-js_info-navigation { border-style: none; }
275 #org-info-js_console-label
276 { font-size: 10px; font-weight: bold; white-space: nowrap; }
277 .org-info-js_search-highlight
278 { background-color: #ffff00; color: #000000; font-weight: bold; }
279 /*]]>*/-->
280 </style>"
281 "The default style specification for exported HTML files.
282 You can use `org-html-head' and `org-html-head-extra' to add to
283 this style. If you don't want to include this default style,
284 customize `org-html-head-include-default-style'.")
287 ;;; User Configuration Variables
289 (defgroup org-export-html nil
290 "Options for exporting Org mode files to HTML."
291 :tag "Org Export HTML"
292 :group 'org-export)
294 ;;;; Handle infojs
296 (defvar org-html-infojs-opts-table
297 '((path PATH "http://orgmode.org/org-info.js")
298 (view VIEW "info")
299 (toc TOC :with-toc)
300 (ftoc FIXED_TOC "0")
301 (tdepth TOC_DEPTH "max")
302 (sdepth SECTION_DEPTH "max")
303 (mouse MOUSE_HINT "underline")
304 (buttons VIEW_BUTTONS "0")
305 (ltoc LOCAL_TOC "1")
306 (up LINK_UP :html-link-up)
307 (home LINK_HOME :html-link-home))
308 "JavaScript options, long form for script, default values.")
310 (defcustom org-html-use-infojs 'when-configured
311 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
312 This option can be nil or t to never or always use the script.
313 It can also be the symbol `when-configured', meaning that the
314 script will be linked into the export file if and only if there
315 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
316 `org-html-infojs-options'."
317 :group 'org-export-html
318 :version "24.4"
319 :package-version '(Org . "8.0")
320 :type '(choice
321 (const :tag "Never" nil)
322 (const :tag "When configured in buffer" when-configured)
323 (const :tag "Always" t)))
325 (defcustom org-html-infojs-options
326 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
327 "Options settings for the INFOJS JavaScript.
328 Each of the options must have an entry in `org-html-infojs-opts-table'.
329 The value can either be a string that will be passed to the script, or
330 a property. This property is then assumed to be a property that is defined
331 by the Export/Publishing setup of Org.
332 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
333 means to use the maximum value consistent with other options."
334 :group 'org-export-html
335 :version "24.4"
336 :package-version '(Org . "8.0")
337 :type
338 `(set :greedy t :inline t
339 ,@(mapcar
340 (lambda (x)
341 (list 'cons (list 'const (car x))
342 '(choice
343 (symbol :tag "Publishing/Export property")
344 (string :tag "Value"))))
345 org-html-infojs-opts-table)))
347 (defcustom org-html-infojs-template
348 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
351 * @source: %SCRIPT_PATH
353 * @licstart The following is the entire license notice for the
354 * JavaScript code in %SCRIPT_PATH.
356 * Copyright (C) 2012-2013 Sebastian Rose
359 * The JavaScript code in this tag is free software: you can
360 * redistribute it and/or modify it under the terms of the GNU
361 * General Public License (GNU GPL) as published by the Free Software
362 * Foundation, either version 3 of the License, or (at your option)
363 * any later version. The code is distributed WITHOUT ANY WARRANTY;
364 * without even the implied warranty of MERCHANTABILITY or FITNESS
365 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
367 * As additional permission under GNU GPL version 3 section 7, you
368 * may distribute non-source (e.g., minimized or compacted) forms of
369 * that code without the copy of the GNU GPL normally required by
370 * section 4, provided you include this license notice and a URL
371 * through which recipients can access the Corresponding Source.
373 * @licend The above is the entire license notice
374 * for the JavaScript code in %SCRIPT_PATH.
377 </script>
379 <script type=\"text/javascript\">
382 @licstart The following is the entire license notice for the
383 JavaScript code in this tag.
385 Copyright (C) 2012-2013 Free Software Foundation, Inc.
387 The JavaScript code in this tag is free software: you can
388 redistribute it and/or modify it under the terms of the GNU
389 General Public License (GNU GPL) as published by the Free Software
390 Foundation, either version 3 of the License, or (at your option)
391 any later version. The code is distributed WITHOUT ANY WARRANTY;
392 without even the implied warranty of MERCHANTABILITY or FITNESS
393 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
395 As additional permission under GNU GPL version 3 section 7, you
396 may distribute non-source (e.g., minimized or compacted) forms of
397 that code without the copy of the GNU GPL normally required by
398 section 4, provided you include this license notice and a URL
399 through which recipients can access the Corresponding Source.
402 @licend The above is the entire license notice
403 for the JavaScript code in this tag.
406 <!--/*--><![CDATA[/*><!--*/
407 %MANAGER_OPTIONS
408 org_html_manager.setup(); // activate after the parameters are set
409 /*]]>*///-->
410 </script>"
411 "The template for the export style additions when org-info.js is used.
412 Option settings will replace the %MANAGER-OPTIONS cookie."
413 :group 'org-export-html
414 :version "24.4"
415 :package-version '(Org . "8.0")
416 :type 'string)
418 (defun org-html-infojs-install-script (exp-plist backend)
419 "Install script in export options when appropriate.
420 EXP-PLIST is a plist containing export options. BACKEND is the
421 export back-end currently used."
422 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
423 (not org-html-use-infojs)
424 (and (eq org-html-use-infojs 'when-configured)
425 (or (not (plist-get exp-plist :infojs-opt))
426 (string-match "\\<view:nil\\>"
427 (plist-get exp-plist :infojs-opt)))))
428 (let* ((template org-html-infojs-template)
429 (ptoc (plist-get exp-plist :with-toc))
430 (hlevels (plist-get exp-plist :headline-levels))
431 (sdepth hlevels)
432 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
433 (options (plist-get exp-plist :infojs-opt))
434 (table org-html-infojs-opts-table)
435 style)
436 (dolist (entry table)
437 (let* ((opt (car entry))
438 (var (nth 1 entry))
439 ;; Compute default values for script option OPT from
440 ;; `org-html-infojs-options' variable.
441 (default
442 (let ((default (cdr (assq opt org-html-infojs-options))))
443 (if (and (symbolp default) (not (memq default '(t nil))))
444 (plist-get exp-plist default)
445 default)))
446 ;; Value set through INFOJS_OPT keyword has precedence
447 ;; over the default one.
448 (val (if (and options
449 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
450 options))
451 (match-string 1 options)
452 default)))
453 (case opt
454 (path (setq template
455 (replace-regexp-in-string
456 "%SCRIPT_PATH" val template t t)))
457 (sdepth (when (integerp (read val))
458 (setq sdepth (min (read val) sdepth))))
459 (tdepth (when (integerp (read val))
460 (setq tdepth (min (read val) tdepth))))
461 (otherwise (setq val
462 (cond
463 ((or (eq val t) (equal val "t")) "1")
464 ((or (eq val nil) (equal val "nil")) "0")
465 ((stringp val) val)
466 (t (format "%s" val))))
467 (push (cons var val) style)))))
468 ;; Now we set the depth of the *generated* TOC to SDEPTH,
469 ;; because the toc will actually determine the splitting. How
470 ;; much of the toc will actually be displayed is governed by the
471 ;; TDEPTH option.
472 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
473 ;; The table of contents should not show more sections than we
474 ;; generate.
475 (setq tdepth (min tdepth sdepth))
476 (push (cons "TOC_DEPTH" tdepth) style)
477 ;; Build style string.
478 (setq style (mapconcat
479 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
480 (car x)
481 (cdr x)))
482 style "\n"))
483 (when (and style (> (length style) 0))
484 (and (string-match "%MANAGER_OPTIONS" template)
485 (setq style (replace-match style t t template))
486 (setq exp-plist
487 (plist-put
488 exp-plist :html-head-extra
489 (concat (or (plist-get exp-plist :html-head-extra) "")
490 "\n"
491 style)))))
492 ;; This script absolutely needs the table of contents, so we
493 ;; change that setting.
494 (unless (plist-get exp-plist :with-toc)
495 (setq exp-plist (plist-put exp-plist :with-toc t)))
496 ;; Return the modified property list.
497 exp-plist)))
499 ;;;; Bold, etc.
501 (defcustom org-html-text-markup-alist
502 '((bold . "<b>%s</b>")
503 (code . "<code>%s</code>")
504 (italic . "<i>%s</i>")
505 (strike-through . "<del>%s</del>")
506 (underline . "<span class=\"underline\">%s</span>")
507 (verbatim . "<code>%s</code>"))
508 "Alist of HTML expressions to convert text markup.
510 The key must be a symbol among `bold', `code', `italic',
511 `strike-through', `underline' and `verbatim'. The value is
512 a formatting string to wrap fontified text with.
514 If no association can be found for a given markup, text will be
515 returned as-is."
516 :group 'org-export-html
517 :type '(alist :key-type (symbol :tag "Markup type")
518 :value-type (string :tag "Format string"))
519 :options '(bold code italic strike-through underline verbatim))
521 (defcustom org-html-indent nil
522 "Non-nil means to indent the generated HTML.
523 Warning: non-nil may break indentation of source code blocks."
524 :group 'org-export-html
525 :version "24.4"
526 :package-version '(Org . "8.0")
527 :type 'boolean)
529 (defcustom org-html-use-unicode-chars nil
530 "Non-nil means to use unicode characters instead of HTML entities."
531 :group 'org-export-html
532 :version "24.4"
533 :package-version '(Org . "8.0")
534 :type 'boolean)
536 ;;;; Drawers
538 (defcustom org-html-format-drawer-function nil
539 "Function called to format a drawer in HTML code.
541 The function must accept two parameters:
542 NAME the drawer name, like \"LOGBOOK\"
543 CONTENTS the contents of the drawer.
545 The function should return the string to be exported.
547 For example, the variable could be set to the following function
548 in order to mimic default behaviour:
550 \(defun org-html-format-drawer-default \(name contents\)
551 \"Format a drawer element for HTML export.\"
552 contents\)"
553 :group 'org-export-html
554 :type 'function)
556 ;;;; Footnotes
558 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
559 <h2 class=\"footnotes\">%s: </h2>
560 <div id=\"text-footnotes\">
562 </div>
563 </div>"
564 "Format for the footnotes section.
565 Should contain a two instances of %s. The first will be replaced with the
566 language-specific word for \"Footnotes\", the second one will be replaced
567 by the footnotes themselves."
568 :group 'org-export-html
569 :type 'string)
571 (defcustom org-html-footnote-format "<sup>%s</sup>"
572 "The format for the footnote reference.
573 %s will be replaced by the footnote reference itself."
574 :group 'org-export-html
575 :type 'string)
577 (defcustom org-html-footnote-separator "<sup>, </sup>"
578 "Text used to separate footnotes."
579 :group 'org-export-html
580 :type 'string)
582 ;;;; Headline
584 (defcustom org-html-toplevel-hlevel 2
585 "The <H> level for level 1 headings in HTML export.
586 This is also important for the classes that will be wrapped around headlines
587 and outline structure. If this variable is 1, the top-level headlines will
588 be <h1>, and the corresponding classes will be outline-1, section-number-1,
589 and outline-text-1. If this is 2, all of these will get a 2 instead.
590 The default for this variable is 2, because we use <h1> for formatting the
591 document title."
592 :group 'org-export-html
593 :type 'integer)
595 (defcustom org-html-format-headline-function nil
596 "Function to format headline text.
598 This function will be called with 5 arguments:
599 TODO the todo keyword (string or nil).
600 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
601 PRIORITY the priority of the headline (integer or nil)
602 TEXT the main headline text (string).
603 TAGS the tags (string or nil).
605 The function result will be used in the section format string."
606 :group 'org-export-html
607 :type 'function)
609 ;;;; HTML-specific
611 (defcustom org-html-allow-name-attribute-in-anchors t
612 "When nil, do not set \"name\" attribute in anchors.
613 By default, anchors are formatted with both \"id\" and \"name\"
614 attributes, when appropriate."
615 :group 'org-export-html
616 :version "24.4"
617 :package-version '(Org . "8.0")
618 :type 'boolean)
620 ;;;; Inlinetasks
622 (defcustom org-html-format-inlinetask-function nil
623 "Function called to format an inlinetask in HTML code.
625 The function must accept six parameters:
626 TODO the todo keyword, as a string
627 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
628 PRIORITY the inlinetask priority, as a string
629 NAME the inlinetask name, as a string.
630 TAGS the inlinetask tags, as a list of strings.
631 CONTENTS the contents of the inlinetask, as a string.
633 The function should return the string to be exported."
634 :group 'org-export-html
635 :type 'function)
637 ;;;; LaTeX
639 (defcustom org-html-with-latex org-export-with-latex
640 "Non-nil means process LaTeX math snippets.
642 When set, the exporter will process LaTeX environments and
643 fragments.
645 This option can also be set with the +OPTIONS line,
646 e.g. \"tex:mathjax\". Allowed values are:
648 nil Ignore math snippets.
649 `verbatim' Keep everything in verbatim
650 `dvipng' Process the LaTeX fragments to images. This will also
651 include processing of non-math environments.
652 `imagemagick' Convert the LaTeX fragments to pdf files and use
653 imagemagick to convert pdf files to png files.
654 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
655 be loaded.
656 t Synonym for `mathjax'."
657 :group 'org-export-html
658 :version "24.4"
659 :package-version '(Org . "8.0")
660 :type '(choice
661 (const :tag "Do not process math in any way" nil)
662 (const :tag "Use dvipng to make images" dvipng)
663 (const :tag "Use imagemagick to make images" imagemagick)
664 (const :tag "Use MathJax to display math" mathjax)
665 (const :tag "Leave math verbatim" verbatim)))
667 ;;;; Links :: Generic
669 (defcustom org-html-link-org-files-as-html t
670 "Non-nil means make file links to `file.org' point to `file.html'.
671 When `org-mode' is exporting an `org-mode' file to HTML, links to
672 non-html files are directly put into a href tag in HTML.
673 However, links to other Org-mode files (recognized by the
674 extension `.org.) should become links to the corresponding html
675 file, assuming that the linked `org-mode' file will also be
676 converted to HTML.
677 When nil, the links still point to the plain `.org' file."
678 :group 'org-export-html
679 :type 'boolean)
681 ;;;; Links :: Inline images
683 (defcustom org-html-inline-images 'maybe
684 "Non-nil means inline images into exported HTML pages.
685 This is done using an <img> tag. When nil, an anchor with href is used to
686 link to the image. If this option is `maybe', then images in links with
687 an empty description will be inlined, while images with a description will
688 be linked only."
689 :group 'org-export-html
690 :type '(choice (const :tag "Never" nil)
691 (const :tag "Always" t)
692 (const :tag "When there is no description" maybe)))
694 (defcustom org-html-inline-image-rules
695 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
697 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
698 "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."
702 :group 'org-export-html
703 :version "24.4"
704 :package-version '(Org . "8.0")
705 :type '(alist :key-type (string :tag "Type")
706 :value-type (regexp :tag "Path")))
708 ;;;; Plain Text
710 (defcustom org-html-protect-char-alist
711 '(("&" . "&amp;")
712 ("<" . "&lt;")
713 (">" . "&gt;"))
714 "Alist of characters to be converted by `org-html-protect'."
715 :group 'org-export-html
716 :type '(repeat (cons (string :tag "Character")
717 (string :tag "HTML equivalent"))))
719 ;;;; Src Block
721 (defcustom org-html-htmlize-output-type 'inline-css
722 "Output type to be used by htmlize when formatting code snippets.
723 Choices are `css', to export the CSS selectors only, or `inline-css', to
724 export the CSS attribute values inline in the HTML. We use as default
725 `inline-css', in order to make the resulting HTML self-containing.
727 However, this will fail when using Emacs in batch mode for export, because
728 then no rich font definitions are in place. It will also not be good if
729 people with different Emacs setup contribute HTML files to a website,
730 because the fonts will represent the individual setups. In these cases,
731 it is much better to let Org/Htmlize assign classes only, and to use
732 a style file to define the look of these classes.
733 To get a start for your css file, start Emacs session and make sure that
734 all the faces you are interested in are defined, for example by loading files
735 in all modes you want. Then, use the command
736 \\[org-html-htmlize-generate-css] to extract class definitions."
737 :group 'org-export-html
738 :type '(choice (const css) (const inline-css)))
740 (defcustom org-html-htmlize-font-prefix "org-"
741 "The prefix for CSS class names for htmlize font specifications."
742 :group 'org-export-html
743 :type 'string)
745 ;;;; Table
747 (defcustom org-html-table-default-attributes
748 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
749 "Default attributes and values which will be used in table tags.
750 This is a plist where attributes are symbols, starting with
751 colons, and values are strings."
752 :group 'org-export-html
753 :version "24.4"
754 :package-version '(Org . "8.0")
755 :type '(plist :key-type (symbol :tag "Property")
756 :value-type (string :tag "Value")))
758 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
759 "The opening tag for table header fields.
760 This is customizable so that alignment options can be specified.
761 The first %s will be filled with the scope of the field, either row or col.
762 The second %s will be replaced by a style entry to align the field.
763 See also the variable `org-html-table-use-header-tags-for-first-column'.
764 See also the variable `org-html-table-align-individual-fields'."
765 :group 'org-export-html
766 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
768 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
769 "The opening tag for table data fields.
770 This is customizable so that alignment options can be specified.
771 The first %s will be filled with the scope of the field, either row or col.
772 The second %s will be replaced by a style entry to align the field.
773 See also the variable `org-html-table-align-individual-fields'."
774 :group 'org-export-html
775 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
777 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
778 "The opening and ending tags for table rows.
779 This is customizable so that alignment options can be specified.
780 Instead of strings, these can be Lisp forms that will be
781 evaluated for each row in order to construct the table row tags.
783 During evaluation, these variables will be dynamically bound so that
784 you can reuse them:
786 `row-number': row number (0 is the first row)
787 `rowgroup-number': group number of current row
788 `start-rowgroup-p': non-nil means the row starts a group
789 `end-rowgroup-p': non-nil means the row ends a group
790 `top-row-p': non-nil means this is the top row
791 `bottom-row-p': non-nil means this is the bottom row
793 For example:
795 \(setq org-html-table-row-tags
796 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
797 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
798 (t (if (= (mod row-number 2) 1)
799 \"<tr class=\\\"tr-odd\\\">\"
800 \"<tr class=\\\"tr-even\\\">\")))
801 \"</tr>\"))
803 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
804 and the bottom row, and otherwise alternate between \"tr-odd\" and
805 \"tr-even\" for odd and even rows."
806 :group 'org-export-html
807 :type '(cons
808 (choice :tag "Opening tag"
809 (string :tag "Specify")
810 (sexp))
811 (choice :tag "Closing tag"
812 (string :tag "Specify")
813 (sexp))))
815 (defcustom org-html-table-align-individual-fields t
816 "Non-nil means attach style attributes for alignment to each table field.
817 When nil, alignment will only be specified in the column tags, but this
818 is ignored by some browsers (like Firefox, Safari). Opera does it right
819 though."
820 :group 'org-export-html
821 :type 'boolean)
823 (defcustom org-html-table-use-header-tags-for-first-column nil
824 "Non-nil means format column one in tables with header tags.
825 When nil, also column one will use data tags."
826 :group 'org-export-html
827 :type 'boolean)
829 (defcustom org-html-table-caption-above t
830 "When non-nil, place caption string at the beginning of the table.
831 Otherwise, place it near the end."
832 :group 'org-export-html
833 :type 'boolean)
835 ;;;; Tags
837 (defcustom org-html-tag-class-prefix ""
838 "Prefix to class names for TODO keywords.
839 Each tag gets a class given by the tag itself, with this prefix.
840 The default prefix is empty because it is nice to just use the keyword
841 as a class name. But if you get into conflicts with other, existing
842 CSS classes, then this prefix can be very useful."
843 :group 'org-export-html
844 :type 'string)
846 ;;;; Template :: Generic
848 (defcustom org-html-extension "html"
849 "The extension for exported HTML files."
850 :group 'org-export-html
851 :type 'string)
853 (defcustom org-html-xml-declaration
854 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
855 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
856 "The extension for exported HTML files.
857 %s will be replaced with the charset of the exported file.
858 This may be a string, or an alist with export extensions
859 and corresponding declarations."
860 :group 'org-export-html
861 :type '(choice
862 (string :tag "Single declaration")
863 (repeat :tag "Dependent on extension"
864 (cons (string :tag "Extension")
865 (string :tag "Declaration")))))
867 (defcustom org-html-coding-system 'utf-8
868 "Coding system for HTML export.
869 Use utf-8 as the default value."
870 :group 'org-export-html
871 :version "24.4"
872 :package-version '(Org . "8.0")
873 :type 'coding-system)
875 (defcustom org-html-doctype
876 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
877 "Document type definition to use for exported HTML files.
878 Can be set with the in-buffer HTML_DOCTYPE property or for
879 publishing, with :html-doctype."
880 :group 'org-export-html
881 :version "24.4"
882 :package-version '(Org . "8.0")
883 :type 'string)
885 (defcustom org-html-container-element "div"
886 "HTML element to use for wrapping top level sections.
887 Can be set with the in-buffer HTML_CONTAINER property or for
888 publishing, with :html-container.
890 Note that changing the default will prevent you from using
891 org-info.js for your website."
892 :group 'org-export-html
893 :version "24.4"
894 :package-version '(Org . "8.0")
895 :type 'string)
897 (defcustom org-html-divs
898 '((preamble "div" "preamble")
899 (content "div" "content")
900 (postamble "div" "postamble"))
901 "Alist of the three section elements for HTML export.
902 The car of each entry is one of 'preamble, 'content or 'postamble.
903 The cdrs of each entry are the ELEMENT_TYPE and ID for each
904 section of the exported document.
906 Note that changing the default will prevent you from using
907 org-info.js for your website."
908 :group 'org-export-html
909 :version "24.4"
910 :package-version '(Org . "8.0")
911 :type '(list :greedy t
912 (list :tag "Preamble"
913 (const :format "" preamble)
914 (string :tag "element") (string :tag " id"))
915 (list :tag "Content"
916 (const :format "" content)
917 (string :tag "element") (string :tag " id"))
918 (list :tag "Postamble" (const :format "" postamble)
919 (string :tag " id") (string :tag "element"))))
921 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
922 "Format used for timestamps in preamble, postamble and metadata.
923 See `format-time-string' for more information on its components."
924 :group 'org-export-html
925 :version "24.4"
926 :package-version '(Org . "8.0")
927 :type 'string)
929 ;;;; Template :: Mathjax
931 (defcustom org-html-mathjax-options
932 '((path "http://orgmode.org/mathjax/MathJax.js")
933 (scale "100")
934 (align "center")
935 (indent "2em")
936 (mathml nil))
937 "Options for MathJax setup.
939 path The path where to find MathJax
940 scale Scaling for the HTML-CSS backend, usually between 100 and 133
941 align How to align display math: left, center, or right
942 indent If align is not center, how far from the left/right side?
943 mathml Should a MathML player be used if available?
944 This is faster and reduces bandwidth use, but currently
945 sometimes has lower spacing quality. Therefore, the default is
946 nil. When browsers get better, this switch can be flipped.
948 You can also customize this for each buffer, using something like
950 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
951 :group 'org-export-html
952 :type '(list :greedy t
953 (list :tag "path (the path from where to load MathJax.js)"
954 (const :format " " path) (string))
955 (list :tag "scale (scaling for the displayed math)"
956 (const :format " " scale) (string))
957 (list :tag "align (alignment of displayed equations)"
958 (const :format " " align) (string))
959 (list :tag "indent (indentation with left or right alignment)"
960 (const :format " " indent) (string))
961 (list :tag "mathml (should MathML display be used is possible)"
962 (const :format " " mathml) (boolean))))
964 (defcustom org-html-mathjax-template
965 "<script type=\"text/javascript\" src=\"%PATH\">
966 <!--/*--><![CDATA[/*><!--*/
967 MathJax.Hub.Config({
968 // Only one of the two following lines, depending on user settings
969 // First allows browser-native MathML display, second forces HTML/CSS
970 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
971 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
972 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
973 \"TeX/noUndefined.js\"],
974 tex2jax: {
975 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
976 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
977 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
978 ignoreClass: \"tex2jax_ignore\",
979 processEscapes: false,
980 processEnvironments: true,
981 preview: \"TeX\"
983 showProcessingMessages: true,
984 displayAlign: \"%ALIGN\",
985 displayIndent: \"%INDENT\",
987 \"HTML-CSS\": {
988 scale: %SCALE,
989 availableFonts: [\"STIX\",\"TeX\"],
990 preferredFont: \"TeX\",
991 webFont: \"TeX\",
992 imageFont: \"TeX\",
993 showMathMenu: true,
995 MMLorHTML: {
996 prefer: {
997 MSIE: \"MML\",
998 Firefox: \"MML\",
999 Opera: \"HTML\",
1000 other: \"HTML\"
1004 /*]]>*///-->
1005 </script>"
1006 "The MathJax setup for XHTML files."
1007 :group 'org-export-html
1008 :type 'string)
1010 ;;;; Template :: Postamble
1012 (defcustom org-html-postamble 'auto
1013 "Non-nil means insert a postamble in HTML export.
1015 When set to 'auto, check against the
1016 `org-export-with-author/email/creator/date' variables to set the
1017 content of the postamble. When set to a string, use this string
1018 as the postamble. When t, insert a string as defined by the
1019 formatting string in `org-html-postamble-format'.
1021 When set to a function, apply this function and insert the
1022 returned string. The function takes the property list of export
1023 options as its only argument.
1025 Setting :html-postamble in publishing projects will take
1026 precedence over this variable."
1027 :group 'org-export-html
1028 :type '(choice (const :tag "No postamble" nil)
1029 (const :tag "Auto postamble" 'auto)
1030 (const :tag "Default formatting string" t)
1031 (string :tag "Custom formatting string")
1032 (function :tag "Function (must return a string)")))
1034 (defcustom org-html-postamble-format
1035 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1036 <p class=\"date\">Date: %d</p>
1037 <p class=\"creator\">%c</p>
1038 <p class=\"xhtml-validation\">%v</p>"))
1039 "Alist of languages and format strings for the HTML postamble.
1041 The first element of each list is the language code, as used for
1042 the LANGUAGE keyword. See `org-export-default-language'.
1044 The second element of each list is a format string to format the
1045 postamble itself. This format string can contain these elements:
1047 %t stands for the title.
1048 %a stands for the author's name.
1049 %e stands for the author's email.
1050 %d stands for the date.
1051 %c will be replaced by `org-html-creator-string'.
1052 %v will be replaced by `org-html-validation-link'.
1053 %T will be replaced by the export time.
1054 %C will be replaced by the last modification time.
1056 If you need to use a \"%\" character, you need to escape it
1057 like that: \"%%\"."
1058 :group 'org-export-html
1059 :type '(alist :key-type (string :tag "Language")
1060 :value-type (string :tag "Format string")))
1062 (defcustom org-html-validation-link
1063 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1064 "Link to HTML validation service."
1065 :group 'org-export-html
1066 :type 'string)
1068 (defcustom org-html-creator-string
1069 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1070 emacs-version
1071 (if (fboundp 'org-version) (org-version) "unknown version"))
1072 "Information about the creator of the HTML document.
1073 This option can also be set on with the CREATOR keyword."
1074 :group 'org-export-html
1075 :type '(string :tag "Creator string"))
1077 ;;;; Template :: Preamble
1079 (defcustom org-html-preamble t
1080 "Non-nil means insert a preamble in HTML export.
1082 When t, insert a string as defined by the formatting string in
1083 `org-html-preamble-format'. When set to a string, use this
1084 formatting string instead (see `org-html-postamble-format' for an
1085 example of such a formatting string).
1087 When set to a function, apply this function and insert the
1088 returned string. The function takes the property list of export
1089 options as its only argument.
1091 Setting :html-preamble in publishing projects will take
1092 precedence over this variable."
1093 :group 'org-export-html
1094 :type '(choice (const :tag "No preamble" nil)
1095 (const :tag "Default preamble" t)
1096 (string :tag "Custom formatting string")
1097 (function :tag "Function (must return a string)")))
1099 (defcustom org-html-preamble-format '(("en" ""))
1100 "Alist of languages and format strings for the HTML preamble.
1102 The first element of each list is the language code, as used for
1103 the LANGUAGE keyword. See `org-export-default-language'.
1105 The second element of each list is a format string to format the
1106 preamble itself. This format string can contain these elements:
1108 %t stands for the title.
1109 %a stands for the author's name.
1110 %e stands for the author's email.
1111 %d stands for the date.
1112 %c will be replaced by `org-html-creator-string'.
1113 %v will be replaced by `org-html-validation-link'.
1114 %T will be replaced by the export time.
1115 %C will be replaced by the last modification time.
1117 If you need to use a \"%\" character, you need to escape it
1118 like that: \"%%\".
1120 See the default value of `org-html-postamble-format' for an
1121 example."
1122 :group 'org-export-html
1123 :type '(alist :key-type (string :tag "Language")
1124 :value-type (string :tag "Format string")))
1126 (defcustom org-html-link-up ""
1127 "Where should the \"UP\" link of exported HTML pages lead?"
1128 :group 'org-export-html
1129 :type '(string :tag "File or URL"))
1131 (defcustom org-html-link-home ""
1132 "Where should the \"HOME\" link of exported HTML pages lead?"
1133 :group 'org-export-html
1134 :type '(string :tag "File or URL"))
1136 (defcustom org-html-home/up-format
1137 "<div id=\"org-div-home-and-up\">
1138 <a accesskey=\"h\" href=\"%s\"> UP </a>
1140 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1141 </div>"
1142 "Snippet used to insert the HOME and UP links.
1143 This is a format string, the first %s will receive the UP link,
1144 the second the HOME link. If both `org-html-link-up' and
1145 `org-html-link-home' are empty, the entire snippet will be
1146 ignored."
1147 :group 'org-export-html
1148 :type 'string)
1150 ;;;; Template :: Scripts
1152 (define-obsolete-variable-alias
1153 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1154 (defcustom org-html-head-include-scripts t
1155 "Non-nil means include the JavaScript snippets in exported HTML files.
1156 The actual script is defined in `org-html-scripts' and should
1157 not be modified."
1158 :group 'org-export-html
1159 :version "24.4"
1160 :package-version '(Org . "8.0")
1161 :type 'boolean)
1163 ;;;; Template :: Styles
1165 (define-obsolete-variable-alias
1166 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1167 (defcustom org-html-head-include-default-style t
1168 "Non-nil means include the default style in exported HTML files.
1169 The actual style is defined in `org-html-style-default' and
1170 should not be modified. Use `org-html-head' to use your own
1171 style information."
1172 :group 'org-export-html
1173 :version "24.4"
1174 :package-version '(Org . "8.0")
1175 :type 'boolean)
1176 ;;;###autoload
1177 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1179 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1180 (defcustom org-html-head ""
1181 "Org-wide head definitions for exported HTML files.
1183 This variable can contain the full HTML structure to provide a
1184 style, including the surrounding HTML tags. You can consider
1185 including definitions for the following classes: title, todo,
1186 done, timestamp, timestamp-kwd, tag, target.
1188 For example, a valid value would be:
1190 <style type=\"text/css\">
1191 <![CDATA[
1192 p { font-weight: normal; color: gray; }
1193 h1 { color: black; }
1194 .title { text-align: center; }
1195 .todo, .timestamp-kwd { color: red; }
1196 .done { color: green; }
1198 </style>
1200 If you want to refer to an external style, use something like
1202 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1204 As the value of this option simply gets inserted into the HTML
1205 <head> header, you can use it to add any arbitrary text to the
1206 header.
1208 You can set this on a per-file basis using #+HTML_HEAD:,
1209 or for publication projects using the :html-head property."
1210 :group 'org-export-html
1211 :version "24.4"
1212 :package-version '(Org . "8.0")
1213 :type 'string)
1214 ;;;###autoload
1215 (put 'org-html-head 'safe-local-variable 'stringp)
1217 (defcustom org-html-head-extra ""
1218 "More head information to add in the HTML output.
1220 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1221 or for publication projects using the :html-head-extra property."
1222 :group 'org-export-html
1223 :version "24.4"
1224 :package-version '(Org . "8.0")
1225 :type 'string)
1226 ;;;###autoload
1227 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1229 ;;;; Todos
1231 (defcustom org-html-todo-kwd-class-prefix ""
1232 "Prefix to class names for TODO keywords.
1233 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1234 The default prefix is empty because it is nice to just use the keyword
1235 as a class name. But if you get into conflicts with other, existing
1236 CSS classes, then this prefix can be very useful."
1237 :group 'org-export-html
1238 :type 'string)
1241 ;;; Internal Functions
1243 (defun org-html--make-attribute-string (attributes)
1244 "Return a list of attributes, as a string.
1245 ATTRIBUTES is a plist where values are either strings or nil. An
1246 attributes with a nil value will be omitted from the result."
1247 (let (output)
1248 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1249 (cond ((null item) (pop output))
1250 ((symbolp item) (push (substring (symbol-name item) 1) output))
1251 (t (let ((key (car output))
1252 (value (replace-regexp-in-string
1253 "\"" "&quot;" (org-html-encode-plain-text item))))
1254 (setcar output (format "%s=\"%s\"" key value))))))))
1256 (defun org-html-format-inline-image (src &optional
1257 caption label attr standalone-p)
1258 "Format an inline image from SRC.
1259 CAPTION, LABEL and ATTR are optional arguments providing the
1260 caption, the label and the attribute of the image.
1261 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1262 (let* ((id (if (not label) ""
1263 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1264 (attr (concat attr
1265 (cond
1266 ((string-match "\\<alt=" (or attr "")) "")
1267 ((string-match "^ltxpng/" src)
1268 (format " alt=\"%s\""
1269 (org-html-encode-plain-text
1270 (org-find-text-property-in-string
1271 'org-latex-src src))))
1272 (t (format " alt=\"%s\""
1273 (file-name-nondirectory src)))))))
1274 (cond
1275 (standalone-p
1276 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1277 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1278 id (format "\n<p>%s</p>" img)
1279 (if (and caption (not (string= caption "")))
1280 (format "\n<p>%s</p>" caption) ""))))
1281 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1283 (defun org-html--textarea-block (element)
1284 "Transcode ELEMENT into a textarea block.
1285 ELEMENT is either a src block or an example block."
1286 (let* ((code (car (org-export-unravel-code element)))
1287 (attr (org-export-read-attribute :attr_html element)))
1288 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1289 (or (plist-get attr :width) 80)
1290 (or (plist-get attr :height) (org-count-lines code))
1291 code)))
1293 ;;;; Bibliography
1295 (defun org-html-bibliography ()
1296 "Find bibliography, cut it out and return it."
1297 (catch 'exit
1298 (let (beg end (cnt 1) bib)
1299 (save-excursion
1300 (goto-char (point-min))
1301 (when (re-search-forward
1302 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1303 (setq beg (match-beginning 0))
1304 (while (re-search-forward "</?div\\>" nil t)
1305 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1306 (when (= cnt 0)
1307 (and (looking-at ">") (forward-char 1))
1308 (setq bib (buffer-substring beg (point)))
1309 (delete-region beg (point))
1310 (throw 'exit bib))))
1311 nil))))
1313 ;;;; Table
1315 (defun org-html-htmlize-region-for-paste (beg end)
1316 "Convert the region between BEG and END to HTML, using htmlize.el.
1317 This is much like `htmlize-region-for-paste', only that it uses
1318 the settings define in the org-... variables."
1319 (let* ((htmlize-output-type org-html-htmlize-output-type)
1320 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1321 (htmlbuf (htmlize-region beg end)))
1322 (unwind-protect
1323 (with-current-buffer htmlbuf
1324 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1325 (plist-get htmlize-buffer-places 'content-end)))
1326 (kill-buffer htmlbuf))))
1328 ;;;###autoload
1329 (defun org-html-htmlize-generate-css ()
1330 "Create the CSS for all font definitions in the current Emacs session.
1331 Use this to create face definitions in your CSS style file that can then
1332 be used by code snippets transformed by htmlize.
1333 This command just produces a buffer that contains class definitions for all
1334 faces used in the current Emacs session. You can copy and paste the ones you
1335 need into your CSS file.
1337 If you then set `org-html-htmlize-output-type' to `css', calls
1338 to the function `org-html-htmlize-region-for-paste' will
1339 produce code that uses these same face definitions."
1340 (interactive)
1341 (require 'htmlize)
1342 (and (get-buffer "*html*") (kill-buffer "*html*"))
1343 (with-temp-buffer
1344 (let ((fl (face-list))
1345 (htmlize-css-name-prefix "org-")
1346 (htmlize-output-type 'css)
1347 f i)
1348 (while (setq f (pop fl)
1349 i (and f (face-attribute f :inherit)))
1350 (when (and (symbolp f) (or (not i) (not (listp i))))
1351 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1352 (htmlize-region (point-min) (point-max))))
1353 (org-pop-to-buffer-same-window "*html*")
1354 (goto-char (point-min))
1355 (if (re-search-forward "<style" nil t)
1356 (delete-region (point-min) (match-beginning 0)))
1357 (if (re-search-forward "</style>" nil t)
1358 (delete-region (1+ (match-end 0)) (point-max)))
1359 (beginning-of-line 1)
1360 (if (looking-at " +") (replace-match ""))
1361 (goto-char (point-min)))
1363 (defun org-html--make-string (n string)
1364 "Build a string by concatenating N times STRING."
1365 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1367 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1368 "Turn todo keyword KWD into a valid class name.
1369 Replaces invalid characters with \"_\"."
1370 (save-match-data
1371 (while (string-match "[^a-zA-Z0-9_]" kwd)
1372 (setq kwd (replace-match "_" t t kwd))))
1373 kwd)
1375 (defun org-html-format-footnote-reference (n def refcnt)
1376 "Format footnote reference N with definition DEF into HTML."
1377 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1378 (format org-html-footnote-format
1379 (let* ((id (format "fnr.%s%s" n extra))
1380 (href (format " href=\"#fn.%s\"" n))
1381 (attributes (concat " class=\"footref\"" href)))
1382 (org-html--anchor id n attributes)))))
1384 (defun org-html-format-footnotes-section (section-name definitions)
1385 "Format footnotes section SECTION-NAME."
1386 (if (not definitions) ""
1387 (format org-html-footnotes-section section-name definitions)))
1389 (defun org-html-format-footnote-definition (fn)
1390 "Format the footnote definition FN."
1391 (let ((n (car fn)) (def (cdr fn)))
1392 (format
1393 "<div class=\"footdef\">%s %s</div>\n"
1394 (format org-html-footnote-format
1395 (let* ((id (format "fn.%s" n))
1396 (href (format " href=\"#fnr.%s\"" n))
1397 (attributes (concat " class=\"footnum\"" href)))
1398 (org-html--anchor id n attributes)))
1399 def)))
1401 (defun org-html-footnote-section (info)
1402 "Format the footnote section.
1403 INFO is a plist used as a communication channel."
1404 (let* ((fn-alist (org-export-collect-footnote-definitions
1405 (plist-get info :parse-tree) info))
1406 (fn-alist
1407 (loop for (n type raw) in fn-alist collect
1408 (cons n (if (eq (org-element-type raw) 'org-data)
1409 (org-trim (org-export-data raw info))
1410 (format "<p>%s</p>"
1411 (org-trim (org-export-data raw info))))))))
1412 (when fn-alist
1413 (org-html-format-footnotes-section
1414 (org-html--translate "Footnotes" info)
1415 (format
1416 "\n%s\n"
1417 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1420 ;;; Template
1422 (defun org-html--build-meta-info (info)
1423 "Return meta tags for exported document.
1424 INFO is a plist used as a communication channel."
1425 (let ((protect-string
1426 (lambda (str)
1427 (replace-regexp-in-string
1428 "\"" "&quot;" (org-html-encode-plain-text str))))
1429 (title (org-export-data (plist-get info :title) info))
1430 (author (and (plist-get info :with-author)
1431 (let ((auth (plist-get info :author)))
1432 (and auth
1433 ;; Return raw Org syntax, skipping non
1434 ;; exportable objects.
1435 (org-element-interpret-data
1436 (org-element-map auth
1437 (cons 'plain-text org-element-all-objects)
1438 'identity info))))))
1439 (description (plist-get info :description))
1440 (keywords (plist-get info :keywords)))
1441 (concat
1442 (format "<title>%s</title>\n" title)
1443 (format
1444 (when :time-stamp-file
1445 (format-time-string
1446 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
1447 (format
1448 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1449 (or (and org-html-coding-system
1450 (fboundp 'coding-system-get)
1451 (coding-system-get org-html-coding-system 'mime-charset))
1452 "iso-8859-1"))
1453 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1454 (and (org-string-nw-p author)
1455 (format "<meta name=\"author\" content=\"%s\"/>\n"
1456 (funcall protect-string author)))
1457 (and (org-string-nw-p description)
1458 (format "<meta name=\"description\" content=\"%s\"/>\n"
1459 (funcall protect-string description)))
1460 (and (org-string-nw-p keywords)
1461 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1462 (funcall protect-string keywords))))))
1464 (defun org-html--build-head (info)
1465 "Return information for the <head>..</head> of the HTML output.
1466 INFO is a plist used as a communication channel."
1467 (org-element-normalize-string
1468 (concat
1469 (when (plist-get info :html-head-include-default-style)
1470 (org-element-normalize-string org-html-style-default))
1471 (org-element-normalize-string (plist-get info :html-head))
1472 (org-element-normalize-string (plist-get info :html-head-extra))
1473 (when (and (plist-get info :html-htmlized-css-url)
1474 (eq org-html-htmlize-output-type 'css))
1475 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1476 (plist-get info :html-htmlized-css-url)))
1477 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1479 (defun org-html--build-mathjax-config (info)
1480 "Insert the user setup into the mathjax template.
1481 INFO is a plist used as a communication channel."
1482 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1483 (org-element-map (plist-get info :parse-tree)
1484 '(latex-fragment latex-environment) 'identity info t))
1485 (let ((template org-html-mathjax-template)
1486 (options org-html-mathjax-options)
1487 (in-buffer (or (plist-get info :html-mathjax) ""))
1488 name val (yes " ") (no "// ") x)
1489 (mapc
1490 (lambda (e)
1491 (setq name (car e) val (nth 1 e))
1492 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1493 (setq val (car (read-from-string
1494 (substring in-buffer (match-end 0))))))
1495 (if (not (stringp val)) (setq val (format "%s" val)))
1496 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1497 (setq template (replace-match val t t template))))
1498 options)
1499 (setq val (nth 1 (assq 'mathml options)))
1500 (if (string-match (concat "\\<mathml:") in-buffer)
1501 (setq val (car (read-from-string
1502 (substring in-buffer (match-end 0))))))
1503 ;; Exchange prefixes depending on mathml setting.
1504 (if (not val) (setq x yes yes no no x))
1505 ;; Replace cookies to turn on or off the config/jax lines.
1506 (if (string-match ":MMLYES:" template)
1507 (setq template (replace-match yes t t template)))
1508 (if (string-match ":MMLNO:" template)
1509 (setq template (replace-match no t t template)))
1510 ;; Return the modified template.
1511 (org-element-normalize-string template))))
1513 (defun org-html-format-spec (info)
1514 "Return format specification for elements that can be
1515 used in the preamble or postamble."
1516 `((?t . ,(org-export-data (plist-get info :title) info))
1517 (?d . ,(org-export-data (org-export-get-date info) info))
1518 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1519 (?a . ,(org-export-data (plist-get info :author) info))
1520 (?e . ,(mapconcat
1521 (lambda (e)
1522 (format "<a href=\"mailto:%s\">%s</a>" e e))
1523 (split-string (plist-get info :email) ",+ *")
1524 ", "))
1525 (?c . ,(plist-get info :creator))
1526 (?C . ,(let ((file (plist-get info :input-file)))
1527 (format-time-string org-html-metadata-timestamp-format
1528 (if file (nth 5 (file-attributes file))
1529 (current-time)))))
1530 (?v . ,(or org-html-validation-link ""))))
1532 (defun org-html--build-pre/postamble (type info)
1533 "Return document preamble or postamble as a string, or nil.
1534 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1535 communication channel."
1536 (let ((section (plist-get info (intern (format ":html-%s" type))))
1537 (spec (org-html-format-spec info)))
1538 (when section
1539 (let ((section-contents
1540 (if (functionp section) (funcall section info)
1541 (cond
1542 ((stringp section) (format-spec section spec))
1543 ((eq section 'auto)
1544 (let ((date (cdr (assq ?d spec)))
1545 (author (cdr (assq ?a spec)))
1546 (email (cdr (assq ?e spec)))
1547 (creator (cdr (assq ?c spec)))
1548 (timestamp (cdr (assq ?T spec)))
1549 (validation-link (cdr (assq ?v spec))))
1550 (concat
1551 (when (and (plist-get info :with-date)
1552 (org-string-nw-p date))
1553 (format "<p class=\"date\">%s: %s</p>\n"
1554 (org-html--translate "Date" info)
1555 date))
1556 (when (and (plist-get info :with-author)
1557 (org-string-nw-p author))
1558 (format "<p class=\"author\">%s: %s</p>\n"
1559 (org-html--translate "Author" info)
1560 author))
1561 (when (and (plist-get info :with-email)
1562 (org-string-nw-p email))
1563 (format "<p class=\"email\">%s: %s</p>\n"
1564 (org-html--translate "Email" info)
1565 email))
1566 (when (plist-get info :time-stamp-file)
1567 (format
1568 "<p class=\"date\">%s: %s</p>\n"
1569 (org-html--translate "Created" info)
1570 (format-time-string org-html-metadata-timestamp-format)))
1571 (when (plist-get info :with-creator)
1572 (format "<p class=\"creator\">%s</p>\n" creator))
1573 (format "<p class=\"xhtml-validation\">%s</p>\n"
1574 validation-link))))
1575 (t (format-spec
1576 (or (cadr (assoc
1577 (plist-get info :language)
1578 (eval (intern
1579 (format "org-html-%s-format" type)))))
1580 (cadr
1581 (assoc
1582 "en"
1583 (eval
1584 (intern (format "org-html-%s-format" type))))))
1585 spec))))))
1586 (when (org-string-nw-p section-contents)
1587 (concat
1588 (format "<%s id=\"%s\" class=\"%s\">\n"
1589 (nth 1 (assq type org-html-divs))
1590 (nth 2 (assq type org-html-divs))
1591 org-html--pre/postamble-class)
1592 (org-element-normalize-string section-contents)
1593 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1595 (defun org-html-inner-template (contents info)
1596 "Return body of document string after HTML conversion.
1597 CONTENTS is the transcoded contents string. INFO is a plist
1598 holding export options."
1599 (concat
1600 ;; Table of contents.
1601 (let ((depth (plist-get info :with-toc)))
1602 (when depth (org-html-toc depth info)))
1603 ;; Document contents.
1604 contents
1605 ;; Footnotes section.
1606 (org-html-footnote-section info)
1607 ;; Bibliography.
1608 (org-html-bibliography)))
1610 (defun org-html-template (contents info)
1611 "Return complete document string after HTML conversion.
1612 CONTENTS is the transcoded contents string. INFO is a plist
1613 holding export options."
1614 (concat
1615 (format
1616 (or (and (stringp org-html-xml-declaration)
1617 org-html-xml-declaration)
1618 (cdr (assoc (plist-get info :html-extension)
1619 org-html-xml-declaration))
1620 (cdr (assoc "html" org-html-xml-declaration))
1623 (or (and org-html-coding-system
1624 (fboundp 'coding-system-get)
1625 (coding-system-get org-html-coding-system 'mime-charset))
1626 "iso-8859-1"))
1627 "\n"
1628 (plist-get info :html-doctype)
1629 "\n"
1630 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1631 (plist-get info :language) (plist-get info :language))
1632 "<head>\n"
1633 (org-html--build-meta-info info)
1634 (org-html--build-head info)
1635 (org-html--build-mathjax-config info)
1636 "</head>\n"
1637 "<body>\n"
1638 (let ((link-up (org-trim (plist-get info :html-link-up)))
1639 (link-home (org-trim (plist-get info :html-link-home))))
1640 (unless (and (string= link-up "") (string= link-up ""))
1641 (format org-html-home/up-format
1642 (or link-up link-home)
1643 (or link-home link-up))))
1644 ;; Preamble.
1645 (org-html--build-pre/postamble 'preamble info)
1646 ;; Document contents.
1647 (format "<%s id=\"%s\">\n"
1648 (nth 1 (assq 'content org-html-divs))
1649 (nth 2 (assq 'content org-html-divs)))
1650 ;; Document title.
1651 (let ((title (plist-get info :title)))
1652 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1653 contents
1654 (format "</%s>\n"
1655 (nth 1 (assq 'content org-html-divs)))
1656 ;; Postamble.
1657 (org-html--build-pre/postamble 'postamble info)
1658 ;; Closing document.
1659 "</body>\n</html>"))
1661 (defun org-html--translate (s info)
1662 "Translate string S according to specified language.
1663 INFO is a plist used as a communication channel."
1664 (org-export-translate s :html info))
1666 ;;;; Anchor
1668 (defun org-html--anchor (&optional id desc attributes)
1669 "Format a HTML anchor."
1670 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1671 (attributes (concat (and id (format " id=\"%s\"" id))
1672 (and name (format " name=\"%s\"" name))
1673 attributes)))
1674 (format "<a%s>%s</a>" attributes (or desc ""))))
1676 ;;;; Todo
1678 (defun org-html--todo (todo)
1679 "Format TODO keywords into HTML."
1680 (when todo
1681 (format "<span class=\"%s %s%s\">%s</span>"
1682 (if (member todo org-done-keywords) "done" "todo")
1683 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1684 todo)))
1686 ;;;; Tags
1688 (defun org-html--tags (tags)
1689 "Format TAGS into HTML."
1690 (when tags
1691 (format "<span class=\"tag\">%s</span>"
1692 (mapconcat
1693 (lambda (tag)
1694 (format "<span class=\"%s\">%s</span>"
1695 (concat org-html-tag-class-prefix
1696 (org-html-fix-class-name tag))
1697 tag))
1698 tags "&#xa0;"))))
1700 ;;;; Headline
1702 (defun* org-html-format-headline
1703 (todo todo-type priority text tags
1704 &key level section-number headline-label &allow-other-keys)
1705 "Format a headline in HTML."
1706 (let ((section-number
1707 (when section-number
1708 (format "<span class=\"section-number-%d\">%s</span> "
1709 level section-number)))
1710 (todo (org-html--todo todo))
1711 (tags (org-html--tags tags)))
1712 (concat section-number todo (and todo " ") text
1713 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1715 ;;;; Src Code
1717 (defun org-html-fontify-code (code lang)
1718 "Color CODE with htmlize library.
1719 CODE is a string representing the source code to colorize. LANG
1720 is the language used for CODE, as a string, or nil."
1721 (when code
1722 (cond
1723 ;; Case 1: No lang. Possibly an example block.
1724 ((not lang)
1725 ;; Simple transcoding.
1726 (org-html-encode-plain-text code))
1727 ;; Case 2: No htmlize or an inferior version of htmlize
1728 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1729 ;; Emit a warning.
1730 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1731 ;; Simple transcoding.
1732 (org-html-encode-plain-text code))
1734 ;; Map language
1735 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1736 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1737 (cond
1738 ;; Case 1: Language is not associated with any Emacs mode
1739 ((not (functionp lang-mode))
1740 ;; Simple transcoding.
1741 (org-html-encode-plain-text code))
1742 ;; Case 2: Default. Fontify code.
1744 ;; htmlize
1745 (setq code (with-temp-buffer
1746 ;; Switch to language-specific mode.
1747 (funcall lang-mode)
1748 (insert code)
1749 ;; Fontify buffer.
1750 (font-lock-fontify-buffer)
1751 ;; Remove formatting on newline characters.
1752 (save-excursion
1753 (let ((beg (point-min))
1754 (end (point-max)))
1755 (goto-char beg)
1756 (while (progn (end-of-line) (< (point) end))
1757 (put-text-property (point) (1+ (point)) 'face nil)
1758 (forward-char 1))))
1759 (org-src-mode)
1760 (set-buffer-modified-p nil)
1761 ;; Htmlize region.
1762 (org-html-htmlize-region-for-paste
1763 (point-min) (point-max))))
1764 ;; Strip any enclosing <pre></pre> tags.
1765 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1766 (end (and beg (string-match "</pre>\\'" code))))
1767 (if (and beg end) (substring code beg end) code)))))))))
1769 (defun org-html-do-format-code
1770 (code &optional lang refs retain-labels num-start)
1771 "Format CODE string as source code.
1772 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1773 respectively, the language of the source code, as a string, an
1774 alist between line numbers and references (as returned by
1775 `org-export-unravel-code'), a boolean specifying if labels should
1776 appear in the source code, and the number associated to the first
1777 line of code."
1778 (let* ((code-lines (org-split-string code "\n"))
1779 (code-length (length code-lines))
1780 (num-fmt
1781 (and num-start
1782 (format "%%%ds: "
1783 (length (number-to-string (+ code-length num-start))))))
1784 (code (org-html-fontify-code code lang)))
1785 (org-export-format-code
1786 code
1787 (lambda (loc line-num ref)
1788 (setq loc
1789 (concat
1790 ;; Add line number, if needed.
1791 (when num-start
1792 (format "<span class=\"linenr\">%s</span>"
1793 (format num-fmt line-num)))
1794 ;; Transcoded src line.
1796 ;; Add label, if needed.
1797 (when (and ref retain-labels) (format " (%s)" ref))))
1798 ;; Mark transcoded line as an anchor, if needed.
1799 (if (not ref) loc
1800 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1801 ref loc)))
1802 num-start refs)))
1804 (defun org-html-format-code (element info)
1805 "Format contents of ELEMENT as source code.
1806 ELEMENT is either an example block or a src block. INFO is
1807 a plist used as a communication channel."
1808 (let* ((lang (org-element-property :language element))
1809 ;; Extract code and references.
1810 (code-info (org-export-unravel-code element))
1811 (code (car code-info))
1812 (refs (cdr code-info))
1813 ;; Does the src block contain labels?
1814 (retain-labels (org-element-property :retain-labels element))
1815 ;; Does it have line numbers?
1816 (num-start (case (org-element-property :number-lines element)
1817 (continued (org-export-get-loc element info))
1818 (new 0))))
1819 (org-html-do-format-code code lang refs retain-labels num-start)))
1822 ;;; Tables of Contents
1824 (defun org-html-toc (depth info)
1825 "Build a table of contents.
1826 DEPTH is an integer specifying the depth of the table. INFO is a
1827 plist used as a communication channel. Return the table of
1828 contents as a string, or nil if it is empty."
1829 (let ((toc-entries
1830 (mapcar (lambda (headline)
1831 (cons (org-html--format-toc-headline headline info)
1832 (org-export-get-relative-level headline info)))
1833 (org-export-collect-headlines info depth))))
1834 (when toc-entries
1835 (concat "<div id=\"table-of-contents\">\n"
1836 (format "<h%d>%s</h%d>\n"
1837 org-html-toplevel-hlevel
1838 (org-html--translate "Table of Contents" info)
1839 org-html-toplevel-hlevel)
1840 "<div id=\"text-table-of-contents\">"
1841 (org-html--toc-text toc-entries)
1842 "</div>\n"
1843 "</div>\n"))))
1845 (defun org-html--toc-text (toc-entries)
1846 "Return innards of a table of contents, as a string.
1847 TOC-ENTRIES is an alist where key is an entry title, as a string,
1848 and value is its relative level, as an integer."
1849 (let* ((prev-level (1- (cdar toc-entries)))
1850 (start-level prev-level))
1851 (concat
1852 (mapconcat
1853 (lambda (entry)
1854 (let ((headline (car entry))
1855 (level (cdr entry)))
1856 (concat
1857 (let* ((cnt (- level prev-level))
1858 (times (if (> cnt 0) (1- cnt) (- cnt)))
1859 rtn)
1860 (setq prev-level level)
1861 (concat
1862 (org-html--make-string
1863 times (cond ((> cnt 0) "\n<ul>\n<li>")
1864 ((< cnt 0) "</li>\n</ul>\n")))
1865 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1866 headline)))
1867 toc-entries "")
1868 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1870 (defun org-html--format-toc-headline (headline info)
1871 "Return an appropriate table of contents entry for HEADLINE.
1872 INFO is a plist used as a communication channel."
1873 (let* ((headline-number (org-export-get-headline-number headline info))
1874 (section-number
1875 (and (not (org-export-low-level-p headline info))
1876 (org-export-numbered-headline-p headline info)
1877 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1878 (tags (and (eq (plist-get info :with-tags) t)
1879 (org-export-get-tags headline info))))
1880 (format "<a href=\"#%s\">%s</a>"
1881 ;; Label.
1882 (org-export-solidify-link-text
1883 (or (org-element-property :CUSTOM_ID headline)
1884 (concat "sec-" (mapconcat 'number-to-string
1885 headline-number "-"))))
1886 ;; Body.
1887 (concat section-number
1888 (org-export-data-with-translations
1889 (org-export-get-alt-title headline info)
1890 ;; Ignore any footnote-reference, link,
1891 ;; radio-target and target in table of contents.
1892 (append
1893 '((footnote-reference . ignore)
1894 (link . (lambda (link desc i) desc))
1895 (radio-target . (lambda (radio desc i) desc))
1896 (target . ignore))
1897 (org-export-backend-translate-table 'html))
1898 info)
1899 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1901 (defun org-html-list-of-listings (info)
1902 "Build a list of listings.
1903 INFO is a plist used as a communication channel. Return the list
1904 of listings as a string, or nil if it is empty."
1905 (let ((lol-entries (org-export-collect-listings info)))
1906 (when lol-entries
1907 (concat "<div id=\"list-of-listings\">\n"
1908 (format "<h%d>%s</h%d>\n"
1909 org-html-toplevel-hlevel
1910 (org-html--translate "List of Listings" info)
1911 org-html-toplevel-hlevel)
1912 "<div id=\"text-list-of-listings\">\n<ul>\n"
1913 (let ((count 0)
1914 (initial-fmt (org-html--translate "Listing %d:" info)))
1915 (mapconcat
1916 (lambda (entry)
1917 (let ((label (org-element-property :name entry))
1918 (title (org-trim
1919 (org-export-data
1920 (or (org-export-get-caption entry t)
1921 (org-export-get-caption entry))
1922 info))))
1923 (concat
1924 "<li>"
1925 (if (not label)
1926 (concat (format initial-fmt (incf count)) " " title)
1927 (format "<a href=\"#%s\">%s %s</a>"
1928 (org-export-solidify-link-text label)
1929 (format initial-fmt (incf count))
1930 title))
1931 "</li>")))
1932 lol-entries "\n"))
1933 "\n</ul>\n</div>\n</div>"))))
1935 (defun org-html-list-of-tables (info)
1936 "Build a list of tables.
1937 INFO is a plist used as a communication channel. Return the list
1938 of tables as a string, or nil if it is empty."
1939 (let ((lol-entries (org-export-collect-tables info)))
1940 (when lol-entries
1941 (concat "<div id=\"list-of-tables\">\n"
1942 (format "<h%d>%s</h%d>\n"
1943 org-html-toplevel-hlevel
1944 (org-html--translate "List of Tables" info)
1945 org-html-toplevel-hlevel)
1946 "<div id=\"text-list-of-tables\">\n<ul>\n"
1947 (let ((count 0)
1948 (initial-fmt (org-html--translate "Table %d:" info)))
1949 (mapconcat
1950 (lambda (entry)
1951 (let ((label (org-element-property :name entry))
1952 (title (org-trim
1953 (org-export-data
1954 (or (org-export-get-caption entry t)
1955 (org-export-get-caption entry))
1956 info))))
1957 (concat
1958 "<li>"
1959 (if (not label)
1960 (concat (format initial-fmt (incf count)) " " title)
1961 (format "<a href=\"#%s\">%s %s</a>"
1962 (org-export-solidify-link-text label)
1963 (format initial-fmt (incf count))
1964 title))
1965 "</li>")))
1966 lol-entries "\n"))
1967 "\n</ul>\n</div>\n</div>"))))
1970 ;;; Transcode Functions
1972 ;;;; Bold
1974 (defun org-html-bold (bold contents info)
1975 "Transcode BOLD from Org to HTML.
1976 CONTENTS is the text with bold markup. INFO is a plist holding
1977 contextual information."
1978 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1979 contents))
1981 ;;;; Center Block
1983 (defun org-html-center-block (center-block contents info)
1984 "Transcode a CENTER-BLOCK element from Org to HTML.
1985 CONTENTS holds the contents of the block. INFO is a plist
1986 holding contextual information."
1987 (format "<div class=\"center\">\n%s</div>" contents))
1989 ;;;; Clock
1991 (defun org-html-clock (clock contents info)
1992 "Transcode a CLOCK element from Org to HTML.
1993 CONTENTS is nil. INFO is a plist used as a communication
1994 channel."
1995 (format "<p>
1996 <span class=\"timestamp-wrapper\">
1997 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1998 </span>
1999 </p>"
2000 org-clock-string
2001 (org-translate-time
2002 (org-element-property :raw-value
2003 (org-element-property :value clock)))
2004 (let ((time (org-element-property :duration clock)))
2005 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2007 ;;;; Code
2009 (defun org-html-code (code contents info)
2010 "Transcode CODE from Org to HTML.
2011 CONTENTS is nil. INFO is a plist holding contextual
2012 information."
2013 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2014 (org-html-plain-text (org-element-property :value code) info)))
2016 ;;;; Drawer
2018 (defun org-html-drawer (drawer contents info)
2019 "Transcode a DRAWER element from Org to HTML.
2020 CONTENTS holds the contents of the block. INFO is a plist
2021 holding contextual information."
2022 (if (functionp org-html-format-drawer-function)
2023 (funcall org-html-format-drawer-function
2024 (org-element-property :drawer-name drawer)
2025 contents)
2026 ;; If there's no user defined function: simply
2027 ;; display contents of the drawer.
2028 contents))
2030 ;;;; Dynamic Block
2032 (defun org-html-dynamic-block (dynamic-block contents info)
2033 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2034 CONTENTS holds the contents of the block. INFO is a plist
2035 holding contextual information. See `org-export-data'."
2036 contents)
2038 ;;;; Entity
2040 (defun org-html-entity (entity contents info)
2041 "Transcode an ENTITY object from Org to HTML.
2042 CONTENTS are the definition itself. INFO is a plist holding
2043 contextual information."
2044 (org-element-property :html entity))
2046 ;;;; Example Block
2048 (defun org-html-example-block (example-block contents info)
2049 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2050 CONTENTS is nil. INFO is a plist holding contextual
2051 information."
2052 (if (org-export-read-attribute :attr_html example-block :textarea)
2053 (org-html--textarea-block example-block)
2054 (format "<pre class=\"example\">\n%s</pre>"
2055 (org-html-format-code example-block info))))
2057 ;;;; Export Snippet
2059 (defun org-html-export-snippet (export-snippet contents info)
2060 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2061 CONTENTS is nil. INFO is a plist holding contextual
2062 information."
2063 (when (eq (org-export-snippet-backend export-snippet) 'html)
2064 (org-element-property :value export-snippet)))
2066 ;;;; Export Block
2068 (defun org-html-export-block (export-block contents info)
2069 "Transcode a EXPORT-BLOCK element from Org to HTML.
2070 CONTENTS is nil. INFO is a plist holding contextual information."
2071 (when (string= (org-element-property :type export-block) "HTML")
2072 (org-remove-indentation (org-element-property :value export-block))))
2074 ;;;; Fixed Width
2076 (defun org-html-fixed-width (fixed-width contents info)
2077 "Transcode a FIXED-WIDTH element from Org to HTML.
2078 CONTENTS is nil. INFO is a plist holding contextual information."
2079 (format "<pre class=\"example\">\n%s</pre>"
2080 (org-html-do-format-code
2081 (org-remove-indentation
2082 (org-element-property :value fixed-width)))))
2084 ;;;; Footnote Reference
2086 (defun org-html-footnote-reference (footnote-reference contents info)
2087 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2088 CONTENTS is nil. INFO is a plist holding contextual information."
2089 (concat
2090 ;; Insert separator between two footnotes in a row.
2091 (let ((prev (org-export-get-previous-element footnote-reference info)))
2092 (when (eq (org-element-type prev) 'footnote-reference)
2093 org-html-footnote-separator))
2094 (cond
2095 ((not (org-export-footnote-first-reference-p footnote-reference info))
2096 (org-html-format-footnote-reference
2097 (org-export-get-footnote-number footnote-reference info)
2098 "IGNORED" 100))
2099 ;; Inline definitions are secondary strings.
2100 ((eq (org-element-property :type footnote-reference) 'inline)
2101 (org-html-format-footnote-reference
2102 (org-export-get-footnote-number footnote-reference info)
2103 "IGNORED" 1))
2104 ;; Non-inline footnotes definitions are full Org data.
2105 (t (org-html-format-footnote-reference
2106 (org-export-get-footnote-number footnote-reference info)
2107 "IGNORED" 1)))))
2109 ;;;; Headline
2111 (defun org-html-format-headline--wrap
2112 (headline info &optional format-function &rest extra-keys)
2113 "Transcode a HEADLINE element from Org to HTML.
2114 CONTENTS holds the contents of the headline. INFO is a plist
2115 holding contextual information."
2116 (let* ((level (+ (org-export-get-relative-level headline info)
2117 (1- org-html-toplevel-hlevel)))
2118 (headline-number (org-export-get-headline-number headline info))
2119 (section-number (and (not (org-export-low-level-p headline info))
2120 (org-export-numbered-headline-p headline info)
2121 (mapconcat 'number-to-string
2122 headline-number ".")))
2123 (todo (and (plist-get info :with-todo-keywords)
2124 (let ((todo (org-element-property :todo-keyword headline)))
2125 (and todo (org-export-data todo info)))))
2126 (todo-type (and todo (org-element-property :todo-type headline)))
2127 (priority (and (plist-get info :with-priority)
2128 (org-element-property :priority headline)))
2129 (text (org-export-data (org-element-property :title headline) info))
2130 (tags (and (plist-get info :with-tags)
2131 (org-export-get-tags headline info)))
2132 (headline-label (or (org-element-property :CUSTOM_ID headline)
2133 (concat "sec-" (mapconcat 'number-to-string
2134 headline-number "-"))))
2135 (format-function (cond
2136 ((functionp format-function) format-function)
2137 ((functionp org-html-format-headline-function)
2138 (function*
2139 (lambda (todo todo-type priority text tags
2140 &allow-other-keys)
2141 (funcall org-html-format-headline-function
2142 todo todo-type priority text tags))))
2143 (t 'org-html-format-headline))))
2144 (apply format-function
2145 todo todo-type priority text tags
2146 :headline-label headline-label :level level
2147 :section-number section-number extra-keys)))
2149 (defun org-html-headline (headline contents info)
2150 "Transcode a HEADLINE element from Org to HTML.
2151 CONTENTS holds the contents of the headline. INFO is a plist
2152 holding contextual information."
2153 ;; Empty contents?
2154 (setq contents (or contents ""))
2155 (let* ((numberedp (org-export-numbered-headline-p headline info))
2156 (level (org-export-get-relative-level headline info))
2157 (text (org-export-data (org-element-property :title headline) info))
2158 (todo (and (plist-get info :with-todo-keywords)
2159 (let ((todo (org-element-property :todo-keyword headline)))
2160 (and todo (org-export-data todo info)))))
2161 (todo-type (and todo (org-element-property :todo-type headline)))
2162 (tags (and (plist-get info :with-tags)
2163 (org-export-get-tags headline info)))
2164 (priority (and (plist-get info :with-priority)
2165 (org-element-property :priority headline)))
2166 (section-number (and (org-export-numbered-headline-p headline info)
2167 (mapconcat 'number-to-string
2168 (org-export-get-headline-number
2169 headline info) ".")))
2170 ;; Create the headline text.
2171 (full-text (org-html-format-headline--wrap headline info)))
2172 (cond
2173 ;; Case 1: This is a footnote section: ignore it.
2174 ((org-element-property :footnote-section-p headline) nil)
2175 ;; Case 2. This is a deep sub-tree: export it as a list item.
2176 ;; Also export as items headlines for which no section
2177 ;; format has been found.
2178 ((org-export-low-level-p headline info)
2179 ;; Build the real contents of the sub-tree.
2180 (let* ((type (if numberedp 'ordered 'unordered))
2181 (itemized-body (org-html-format-list-item
2182 contents type nil nil full-text)))
2183 (concat
2184 (and (org-export-first-sibling-p headline info)
2185 (org-html-begin-plain-list type))
2186 itemized-body
2187 (and (org-export-last-sibling-p headline info)
2188 (org-html-end-plain-list type)))))
2189 ;; Case 3. Standard headline. Export it as a section.
2191 (let* ((section-number (mapconcat 'number-to-string
2192 (org-export-get-headline-number
2193 headline info) "-"))
2194 (ids (remove 'nil
2195 (list (org-element-property :CUSTOM_ID headline)
2196 (concat "sec-" section-number)
2197 (org-element-property :ID headline))))
2198 (preferred-id (car ids))
2199 (extra-ids (cdr ids))
2200 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2201 (level1 (+ level (1- org-html-toplevel-hlevel)))
2202 (first-content (car (org-element-contents headline))))
2203 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2204 (org-html--container headline info)
2205 (format "outline-container-%s"
2206 (or (org-element-property :CUSTOM_ID headline)
2207 (concat "sec-" section-number)))
2208 (concat (format "outline-%d" level1) (and extra-class " ")
2209 extra-class)
2210 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2211 level1
2212 preferred-id
2213 (mapconcat
2214 (lambda (x)
2215 (let ((id (org-export-solidify-link-text
2216 (if (org-uuidgen-p x) (concat "ID-" x)
2217 x))))
2218 (org-html--anchor id)))
2219 extra-ids "")
2220 full-text
2221 level1)
2222 ;; When there is no section, pretend there is an empty
2223 ;; one to get the correct <div class="outline- ...>
2224 ;; which is needed by `org-info.js'.
2225 (if (not (eq (org-element-type first-content) 'section))
2226 (concat (org-html-section first-content "" info)
2227 contents)
2228 contents)
2229 (org-html--container headline info)))))))
2231 (defun org-html--container (headline info)
2232 (or (org-element-property :HTML_CONTAINER headline)
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.
2436 LINK is the link pointing to the inline image. INFO is a plist
2437 used as a communication channel.
2439 Inline images can have these attributes:
2441 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2442 (let* ((type (org-element-property :type link))
2443 (raw-path (org-element-property :path link))
2444 (path (cond ((member type '("http" "https"))
2445 (concat type ":" raw-path))
2446 ((file-name-absolute-p raw-path)
2447 (expand-file-name raw-path))
2448 (t raw-path)))
2449 (parent (org-export-get-parent-element link))
2450 (caption (org-export-data (org-export-get-caption parent) info))
2451 (label (org-element-property :name parent)))
2452 ;; Return proper string, depending on DISPOSITION.
2453 (org-html-format-inline-image
2454 path caption label
2455 (org-html--make-attribute-string
2456 (org-export-read-attribute :attr_html parent))
2457 (org-html-standalone-image-p link info))))
2459 (defvar org-html-standalone-image-predicate)
2460 (defun org-html-standalone-image-p (element info &optional predicate)
2461 "Test if ELEMENT is a standalone image for the purpose HTML export.
2462 INFO is a plist holding contextual information.
2464 Return non-nil, if ELEMENT is of type paragraph and it's sole
2465 content, save for whitespaces, is a link that qualifies as an
2466 inline image.
2468 Return non-nil, if ELEMENT is of type link and it's containing
2469 paragraph has no other content save for leading and trailing
2470 whitespaces.
2472 Return nil, otherwise.
2474 Bind `org-html-standalone-image-predicate' to constrain
2475 paragraph further. For example, to check for only captioned
2476 standalone images, do the following.
2478 \(setq org-html-standalone-image-predicate
2479 \(lambda \(paragraph\)
2480 \(org-element-property :caption paragraph\)\)\)"
2481 (let ((paragraph (case (org-element-type element)
2482 (paragraph element)
2483 (link (and (org-export-inline-image-p
2484 element org-html-inline-image-rules)
2485 (org-export-get-parent element)))
2486 (t nil))))
2487 (when (eq (org-element-type paragraph) 'paragraph)
2488 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2489 (functionp org-html-standalone-image-predicate)))
2490 (funcall org-html-standalone-image-predicate paragraph))
2491 (let ((contents (org-element-contents paragraph)))
2492 (loop for x in contents
2493 with inline-image-count = 0
2494 always (cond
2495 ((eq (org-element-type x) 'plain-text)
2496 (not (org-string-nw-p x)))
2497 ((eq (org-element-type x) 'link)
2498 (when (org-export-inline-image-p
2499 x org-html-inline-image-rules)
2500 (= (incf inline-image-count) 1)))
2501 (t nil))))))))
2503 (defun org-html-link (link desc info)
2504 "Transcode a LINK object from Org to HTML.
2506 DESC is the description part of the link, or the empty string.
2507 INFO is a plist holding contextual information. See
2508 `org-export-data'."
2509 (let* ((link-org-files-as-html-maybe
2510 (function
2511 (lambda (raw-path info)
2512 "Treat links to `file.org' as links to `file.html', if needed.
2513 See `org-html-link-org-files-as-html'."
2514 (cond
2515 ((and org-html-link-org-files-as-html
2516 (string= ".org"
2517 (downcase (file-name-extension raw-path "."))))
2518 (concat (file-name-sans-extension raw-path) "."
2519 (plist-get info :html-extension)))
2520 (t raw-path)))))
2521 (type (org-element-property :type link))
2522 (raw-path (org-element-property :path link))
2523 ;; Ensure DESC really exists, or set it to nil.
2524 (desc (org-string-nw-p desc))
2525 (path
2526 (cond
2527 ((member type '("http" "https" "ftp" "mailto"))
2528 (concat type ":" raw-path))
2529 ((string= type "file")
2530 ;; Treat links to ".org" files as ".html", if needed.
2531 (setq raw-path
2532 (funcall link-org-files-as-html-maybe raw-path info))
2533 ;; If file path is absolute, prepend it with protocol
2534 ;; component - "file://".
2535 (when (file-name-absolute-p raw-path)
2536 (setq raw-path
2537 (concat "file://" (expand-file-name raw-path))))
2538 ;; Add search option, if any. A search option can be
2539 ;; relative to a custom-id or a headline title. Any other
2540 ;; option is ignored.
2541 (let ((option (org-element-property :search-option link)))
2542 (cond ((not option) raw-path)
2543 ((eq (aref option 0) ?#) (concat raw-path option))
2544 ;; External fuzzy link: try to resolve it if path
2545 ;; belongs to current project, if any.
2546 ((eq (aref option 0) ?*)
2547 (concat
2548 raw-path
2549 (let ((numbers
2550 (org-publish-resolve-external-fuzzy-link
2551 (org-element-property :path link) option)))
2552 (and numbers (concat "#sec-"
2553 (mapconcat 'number-to-string
2554 numbers "-"))))))
2555 (t raw-path))))
2556 (t raw-path)))
2557 ;; Extract attributes from parent's paragraph. HACK: Only do
2558 ;; this for the first link in parent. This is needed as long
2559 ;; as attributes cannot be set on a per link basis.
2560 (attributes
2561 (let ((parent (org-export-get-parent-element link)))
2562 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2564 (let ((att (org-html--make-attribute-string
2565 (org-export-read-attribute :attr_html parent))))
2566 (cond ((not (org-string-nw-p att)) "")
2567 ((and desc (string-match (regexp-quote att) desc)) "")
2568 (t (concat " " att)))))))
2569 protocol)
2570 (cond
2571 ;; Image file.
2572 ((and (or (eq t org-html-inline-images)
2573 (and org-html-inline-images (not desc)))
2574 (org-export-inline-image-p link org-html-inline-image-rules))
2575 (org-html-link--inline-image link desc info))
2576 ;; Radio target: Transcode target's contents and use them as
2577 ;; link's description.
2578 ((string= type "radio")
2579 (let ((destination (org-export-resolve-radio-link link info)))
2580 (when destination
2581 (format "<a href=\"#%s\"%s>%s</a>"
2582 (org-export-solidify-link-text path)
2583 attributes
2584 (org-export-data (org-element-contents destination) info)))))
2585 ;; Links pointing to a headline: Find destination and build
2586 ;; appropriate referencing command.
2587 ((member type '("custom-id" "fuzzy" "id"))
2588 (let ((destination (if (string= type "fuzzy")
2589 (org-export-resolve-fuzzy-link link info)
2590 (org-export-resolve-id-link link info))))
2591 (case (org-element-type destination)
2592 ;; ID link points to an external file.
2593 (plain-text
2594 (let ((fragment (concat "ID-" path))
2595 ;; Treat links to ".org" files as ".html", if needed.
2596 (path (funcall link-org-files-as-html-maybe
2597 destination info)))
2598 (format "<a href=\"%s#%s\"%s>%s</a>"
2599 path fragment attributes (or desc destination))))
2600 ;; Fuzzy link points nowhere.
2601 ((nil)
2602 (format "<i>%s</i>"
2603 (or desc
2604 (org-export-data
2605 (org-element-property :raw-link link) info))))
2606 ;; Fuzzy link points to an invisible target.
2607 (keyword nil)
2608 ;; Link points to a headline.
2609 (headline
2610 (let ((href
2611 ;; What href to use?
2612 (cond
2613 ;; Case 1: Headline is linked via it's CUSTOM_ID
2614 ;; property. Use CUSTOM_ID.
2615 ((string= type "custom-id")
2616 (org-element-property :CUSTOM_ID destination))
2617 ;; Case 2: Headline is linked via it's ID property
2618 ;; or through other means. Use the default href.
2619 ((member type '("id" "fuzzy"))
2620 (format "sec-%s"
2621 (mapconcat 'number-to-string
2622 (org-export-get-headline-number
2623 destination info) "-")))
2624 (t (error "Shouldn't reach here"))))
2625 ;; What description to use?
2626 (desc
2627 ;; Case 1: Headline is numbered and LINK has no
2628 ;; description. Display section number.
2629 (if (and (org-export-numbered-headline-p destination info)
2630 (not desc))
2631 (mapconcat 'number-to-string
2632 (org-export-get-headline-number
2633 destination info) ".")
2634 ;; Case 2: Either the headline is un-numbered or
2635 ;; LINK has a custom description. Display LINK's
2636 ;; description or headline's title.
2637 (or desc (org-export-data (org-element-property
2638 :title destination) info)))))
2639 (format "<a href=\"#%s\"%s>%s</a>"
2640 (org-export-solidify-link-text href) attributes desc)))
2641 ;; Fuzzy link points to a target. Do as above.
2643 (let ((path (org-export-solidify-link-text path)) number)
2644 (unless desc
2645 (setq number (cond
2646 ((org-html-standalone-image-p destination info)
2647 (org-export-get-ordinal
2648 (assoc 'link (org-element-contents destination))
2649 info 'link 'org-html-standalone-image-p))
2650 (t (org-export-get-ordinal destination info))))
2651 (setq desc (when number
2652 (if (atom number) (number-to-string number)
2653 (mapconcat 'number-to-string number ".")))))
2654 (format "<a href=\"#%s\"%s>%s</a>"
2655 path attributes (or desc "No description for this link")))))))
2656 ;; Coderef: replace link with the reference name or the
2657 ;; equivalent line number.
2658 ((string= type "coderef")
2659 (let ((fragment (concat "coderef-" path)))
2660 (format "<a href=\"#%s\"%s%s>%s</a>"
2661 fragment
2662 (org-trim
2663 (format (concat "class=\"coderef\""
2664 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2665 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2666 fragment fragment))
2667 attributes
2668 (format (org-export-get-coderef-format path desc)
2669 (org-export-resolve-coderef path info)))))
2670 ;; Link type is handled by a special function.
2671 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2672 (funcall protocol (org-link-unescape path) desc 'html))
2673 ;; External link with a description part.
2674 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2675 ;; External link without a description part.
2676 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2677 ;; No path, only description. Try to do something useful.
2678 (t (format "<i>%s</i>" desc)))))
2680 ;;;; Paragraph
2682 (defun org-html-paragraph (paragraph contents info)
2683 "Transcode a PARAGRAPH element from Org to HTML.
2684 CONTENTS is the contents of the paragraph, as a string. INFO is
2685 the plist used as a communication channel."
2686 (let* ((parent (org-export-get-parent paragraph))
2687 (parent-type (org-element-type parent))
2688 (style '((footnote-definition " class=\"footpara\"")))
2689 (extra (or (cadr (assoc parent-type style)) "")))
2690 (cond
2691 ((and (eq (org-element-type parent) 'item)
2692 (= (org-element-property :begin paragraph)
2693 (org-element-property :contents-begin parent)))
2694 ;; leading paragraph in a list item have no tags
2695 contents)
2696 ((org-html-standalone-image-p paragraph info)
2697 ;; standalone image
2698 contents)
2699 (t (format "<p%s>\n%s</p>" extra contents)))))
2701 ;;;; Plain List
2703 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2704 ;; the correct value for the item counter
2705 (defun org-html-begin-plain-list (type &optional arg1)
2706 "Insert the beginning of the HTML list depending on TYPE.
2707 When ARG1 is a string, use it as the start parameter for ordered
2708 lists."
2709 (case type
2710 (ordered
2711 (format "<ol class=\"org-ol\"%s>"
2712 (if arg1 (format " start=\"%d\"" arg1) "")))
2713 (unordered "<ul class=\"org-ul\">")
2714 (descriptive "<dl class=\"org-dl\">")))
2716 (defun org-html-end-plain-list (type)
2717 "Insert the end of the HTML list depending on TYPE."
2718 (case type
2719 (ordered "</ol>")
2720 (unordered "</ul>")
2721 (descriptive "</dl>")))
2723 (defun org-html-plain-list (plain-list contents info)
2724 "Transcode a PLAIN-LIST element from Org to HTML.
2725 CONTENTS is the contents of the list. INFO is a plist holding
2726 contextual information."
2727 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2728 (type (org-element-property :type plain-list)))
2729 (format "%s\n%s%s"
2730 (org-html-begin-plain-list type)
2731 contents (org-html-end-plain-list type))))
2733 ;;;; Plain Text
2735 (defun org-html-convert-special-strings (string)
2736 "Convert special characters in STRING to HTML."
2737 (let ((all org-html-special-string-regexps)
2738 e a re rpl start)
2739 (while (setq a (pop all))
2740 (setq re (car a) rpl (cdr a) start 0)
2741 (while (string-match re string start)
2742 (setq string (replace-match rpl t nil string))))
2743 string))
2745 (defun org-html-encode-plain-text (text)
2746 "Convert plain text characters from TEXT to HTML equivalent.
2747 Possible conversions are set in `org-html-protect-char-alist'."
2748 (mapc
2749 (lambda (pair)
2750 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2751 org-html-protect-char-alist)
2752 text)
2754 (defun org-html-plain-text (text info)
2755 "Transcode a TEXT string from Org to HTML.
2756 TEXT is the string to transcode. INFO is a plist holding
2757 contextual information."
2758 (let ((output text))
2759 ;; Protect following characters: <, >, &.
2760 (setq output (org-html-encode-plain-text output))
2761 ;; Handle smart quotes. Be sure to provide original string since
2762 ;; OUTPUT may have been modified.
2763 (when (plist-get info :with-smart-quotes)
2764 (setq output (org-export-activate-smart-quotes output :html info text)))
2765 ;; Handle special strings.
2766 (when (plist-get info :with-special-strings)
2767 (setq output (org-html-convert-special-strings output)))
2768 ;; Handle break preservation if required.
2769 (when (plist-get info :preserve-breaks)
2770 (setq output
2771 (replace-regexp-in-string
2772 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2773 ;; Return value.
2774 output))
2777 ;; Planning
2779 (defun org-html-planning (planning contents info)
2780 "Transcode a PLANNING element from Org to HTML.
2781 CONTENTS is nil. INFO is a plist used as a communication
2782 channel."
2783 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2784 (format
2785 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2786 (mapconcat
2787 'identity
2788 (delq nil
2789 (list
2790 (let ((closed (org-element-property :closed planning)))
2791 (when closed
2792 (format span-fmt org-closed-string
2793 (org-translate-time
2794 (org-element-property :raw-value closed)))))
2795 (let ((deadline (org-element-property :deadline planning)))
2796 (when deadline
2797 (format span-fmt org-deadline-string
2798 (org-translate-time
2799 (org-element-property :raw-value deadline)))))
2800 (let ((scheduled (org-element-property :scheduled planning)))
2801 (when scheduled
2802 (format span-fmt org-scheduled-string
2803 (org-translate-time
2804 (org-element-property :raw-value scheduled)))))))
2805 " "))))
2807 ;;;; Property Drawer
2809 (defun org-html-property-drawer (property-drawer contents info)
2810 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2811 CONTENTS is nil. INFO is a plist holding contextual
2812 information."
2813 ;; The property drawer isn't exported but we want separating blank
2814 ;; lines nonetheless.
2817 ;;;; Quote Block
2819 (defun org-html-quote-block (quote-block contents info)
2820 "Transcode a QUOTE-BLOCK element from Org to HTML.
2821 CONTENTS holds the contents of the block. INFO is a plist
2822 holding contextual information."
2823 (format "<blockquote>\n%s</blockquote>" contents))
2825 ;;;; Quote Section
2827 (defun org-html-quote-section (quote-section contents info)
2828 "Transcode a QUOTE-SECTION element from Org to HTML.
2829 CONTENTS is nil. INFO is a plist holding contextual information."
2830 (let ((value (org-remove-indentation
2831 (org-element-property :value quote-section))))
2832 (when value (format "<pre>\n%s</pre>" value))))
2834 ;;;; Section
2836 (defun org-html-section (section contents info)
2837 "Transcode a SECTION element from Org to HTML.
2838 CONTENTS holds the contents of the section. INFO is a plist
2839 holding contextual information."
2840 (let ((parent (org-export-get-parent-headline section)))
2841 ;; Before first headline: no container, just return CONTENTS.
2842 (if (not parent) contents
2843 ;; Get div's class and id references.
2844 (let* ((class-num (+ (org-export-get-relative-level parent info)
2845 (1- org-html-toplevel-hlevel)))
2846 (section-number
2847 (mapconcat
2848 'number-to-string
2849 (org-export-get-headline-number parent info) "-")))
2850 ;; Build return value.
2851 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2852 class-num
2853 (or (org-element-property :CUSTOM_ID parent) section-number)
2854 contents)))))
2856 ;;;; Radio Target
2858 (defun org-html-radio-target (radio-target text info)
2859 "Transcode a RADIO-TARGET object from Org to HTML.
2860 TEXT is the text of the target. INFO is a plist holding
2861 contextual information."
2862 (let ((id (org-export-solidify-link-text
2863 (org-element-property :value radio-target))))
2864 (org-html--anchor id text)))
2866 ;;;; Special Block
2868 (defun org-html-special-block (special-block contents info)
2869 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2870 CONTENTS holds the contents of the block. INFO is a plist
2871 holding contextual information."
2872 (format "<div class=\"%s\">\n%s\n</div>"
2873 (downcase (org-element-property :type special-block))
2874 contents))
2876 ;;;; Src Block
2878 (defun org-html-src-block (src-block contents info)
2879 "Transcode a SRC-BLOCK element from Org to HTML.
2880 CONTENTS holds the contents of the item. INFO is a plist holding
2881 contextual information."
2882 (if (org-export-read-attribute :attr_html src-block :textarea)
2883 (org-html--textarea-block src-block)
2884 (let ((lang (org-element-property :language src-block))
2885 (caption (org-export-get-caption src-block))
2886 (code (org-html-format-code src-block info))
2887 (label (let ((lbl (org-element-property :name src-block)))
2888 (if (not lbl) ""
2889 (format " id=\"%s\""
2890 (org-export-solidify-link-text lbl))))))
2891 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2892 (format
2893 "<div class=\"org-src-container\">\n%s%s\n</div>"
2894 (if (not caption) ""
2895 (format "<label class=\"org-src-name\">%s</label>"
2896 (org-export-data caption info)))
2897 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2899 ;;;; Statistics Cookie
2901 (defun org-html-statistics-cookie (statistics-cookie contents info)
2902 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2903 CONTENTS is nil. INFO is a plist holding contextual information."
2904 (let ((cookie-value (org-element-property :value statistics-cookie)))
2905 (format "<code>%s</code>" cookie-value)))
2907 ;;;; Strike-Through
2909 (defun org-html-strike-through (strike-through contents info)
2910 "Transcode STRIKE-THROUGH from Org to HTML.
2911 CONTENTS is the text with strike-through markup. INFO is a plist
2912 holding contextual information."
2913 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2914 contents))
2916 ;;;; Subscript
2918 (defun org-html-subscript (subscript contents info)
2919 "Transcode a SUBSCRIPT object from Org to HTML.
2920 CONTENTS is the contents of the object. INFO is a plist holding
2921 contextual information."
2922 (format "<sub>%s</sub>" contents))
2924 ;;;; Superscript
2926 (defun org-html-superscript (superscript contents info)
2927 "Transcode a SUPERSCRIPT object from Org to HTML.
2928 CONTENTS is the contents of the object. INFO is a plist holding
2929 contextual information."
2930 (format "<sup>%s</sup>" contents))
2932 ;;;; Tabel Cell
2934 (defun org-html-table-cell (table-cell contents info)
2935 "Transcode a TABLE-CELL element from Org to HTML.
2936 CONTENTS is nil. INFO is a plist used as a communication
2937 channel."
2938 (let* ((table-row (org-export-get-parent table-cell))
2939 (table (org-export-get-parent-table table-cell))
2940 (cell-attrs
2941 (if (not org-html-table-align-individual-fields) ""
2942 (format (if (and (boundp 'org-html-format-table-no-css)
2943 org-html-format-table-no-css)
2944 " align=\"%s\"" " class=\"%s\"")
2945 (org-export-table-cell-alignment table-cell info)))))
2946 (when (or (not contents) (string= "" (org-trim contents)))
2947 (setq contents "&#xa0;"))
2948 (cond
2949 ((and (org-export-table-has-header-p table info)
2950 (= 1 (org-export-table-row-group table-row info)))
2951 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2952 contents (cdr org-html-table-header-tags)))
2953 ((and org-html-table-use-header-tags-for-first-column
2954 (zerop (cdr (org-export-table-cell-address table-cell info))))
2955 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2956 contents (cdr org-html-table-header-tags)))
2957 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2958 contents (cdr org-html-table-data-tags))))))
2960 ;;;; Table Row
2962 (defun org-html-table-row (table-row contents info)
2963 "Transcode a TABLE-ROW element from Org to HTML.
2964 CONTENTS is the contents of the row. INFO is a plist used as a
2965 communication channel."
2966 ;; Rules are ignored since table separators are deduced from
2967 ;; borders of the current row.
2968 (when (eq (org-element-property :type table-row) 'standard)
2969 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2970 (row-number (org-export-table-row-number table-row info))
2971 (start-rowgroup-p
2972 (org-export-table-row-starts-rowgroup-p table-row info))
2973 (end-rowgroup-p
2974 (org-export-table-row-ends-rowgroup-p table-row info))
2975 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2976 ;; but should be set so that `org-html-table-row-tags' can
2977 ;; use them (see the docstring of this variable.)
2978 (top-row-p (and (equal start-rowgroup-p '(top))
2979 (equal end-rowgroup-p '(below top))))
2980 (bottom-row-p (and (equal start-rowgroup-p '(above))
2981 (equal end-rowgroup-p '(bottom above))))
2982 (rowgroup-tags
2983 (cond
2984 ;; Case 1: Row belongs to second or subsequent rowgroups.
2985 ((not (= 1 rowgroup-number))
2986 '("<tbody>" . "\n</tbody>"))
2987 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2988 ((org-export-table-has-header-p
2989 (org-export-get-parent-table table-row) info)
2990 '("<thead>" . "\n</thead>"))
2991 ;; Case 2: Row is from first and only row group.
2992 (t '("<tbody>" . "\n</tbody>")))))
2993 (concat
2994 ;; Begin a rowgroup?
2995 (when start-rowgroup-p (car rowgroup-tags))
2996 ;; Actual table row
2997 (concat "\n" (eval (car org-html-table-row-tags))
2998 contents
2999 "\n"
3000 (eval (cdr org-html-table-row-tags)))
3001 ;; End a rowgroup?
3002 (when end-rowgroup-p (cdr rowgroup-tags))))))
3004 ;;;; Table
3006 (defun org-html-table-first-row-data-cells (table info)
3007 "Transcode the first row of TABLE.
3008 INFO is a plist used as a communication channel."
3009 (let ((table-row
3010 (org-element-map table 'table-row
3011 (lambda (row)
3012 (unless (eq (org-element-property :type row) 'rule) row))
3013 info 'first-match))
3014 (special-column-p (org-export-table-has-special-column-p table)))
3015 (if (not special-column-p) (org-element-contents table-row)
3016 (cdr (org-element-contents table-row)))))
3018 (defun org-html-table--table.el-table (table info)
3019 "Format table.el tables into HTML.
3020 INFO is a plist used as a communication channel."
3021 (when (eq (org-element-property :type table) 'table.el)
3022 (require 'table)
3023 (let ((outbuf (with-current-buffer
3024 (get-buffer-create "*org-export-table*")
3025 (erase-buffer) (current-buffer))))
3026 (with-temp-buffer
3027 (insert (org-element-property :value table))
3028 (goto-char 1)
3029 (re-search-forward "^[ \t]*|[^|]" nil t)
3030 (table-generate-source 'html outbuf))
3031 (with-current-buffer outbuf
3032 (prog1 (org-trim (buffer-string))
3033 (kill-buffer) )))))
3035 (defun org-html-table (table contents info)
3036 "Transcode a TABLE element from Org to HTML.
3037 CONTENTS is the contents of the table. INFO is a plist holding
3038 contextual information."
3039 (case (org-element-property :type table)
3040 ;; Case 1: table.el table. Convert it using appropriate tools.
3041 (table.el (org-html-table--table.el-table table info))
3042 ;; Case 2: Standard table.
3044 (let* ((label (org-element-property :name table))
3045 (caption (org-export-get-caption table))
3046 (attributes
3047 (org-html--make-attribute-string
3048 (org-combine-plists
3049 (and label (list :id (org-export-solidify-link-text label)))
3050 (plist-get info :html-table-attributes)
3051 (org-export-read-attribute :attr_html table))))
3052 (alignspec
3053 (if (and (boundp 'org-html-format-table-no-css)
3054 org-html-format-table-no-css)
3055 "align=\"%s\"" "class=\"%s\""))
3056 (table-column-specs
3057 (function
3058 (lambda (table info)
3059 (mapconcat
3060 (lambda (table-cell)
3061 (let ((alignment (org-export-table-cell-alignment
3062 table-cell info)))
3063 (concat
3064 ;; Begin a colgroup?
3065 (when (org-export-table-cell-starts-colgroup-p
3066 table-cell info)
3067 "\n<colgroup>")
3068 ;; Add a column. Also specify it's alignment.
3069 (format "\n<col %s/>" (format alignspec alignment))
3070 ;; End a colgroup?
3071 (when (org-export-table-cell-ends-colgroup-p
3072 table-cell info)
3073 "\n</colgroup>"))))
3074 (org-html-table-first-row-data-cells table info) "\n")))))
3075 (format "<table%s>\n%s\n%s\n%s</table>"
3076 (if (equal attributes "") "" (concat " " attributes))
3077 (if (not caption) ""
3078 (format "<caption>%s</caption>"
3079 (org-export-data caption info)))
3080 (funcall table-column-specs table info)
3081 contents)))))
3083 ;;;; Target
3085 (defun org-html-target (target contents info)
3086 "Transcode a TARGET object from Org to HTML.
3087 CONTENTS is nil. INFO is a plist holding contextual
3088 information."
3089 (let ((id (org-export-solidify-link-text
3090 (org-element-property :value target))))
3091 (org-html--anchor id)))
3093 ;;;; Timestamp
3095 (defun org-html-timestamp (timestamp contents info)
3096 "Transcode a TIMESTAMP object from Org to HTML.
3097 CONTENTS is nil. INFO is a plist holding contextual
3098 information."
3099 (let ((value (org-html-plain-text
3100 (org-timestamp-translate timestamp) info)))
3101 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3102 (replace-regexp-in-string "--" "&#x2013;" value))))
3104 ;;;; Underline
3106 (defun org-html-underline (underline contents info)
3107 "Transcode UNDERLINE from Org to HTML.
3108 CONTENTS is the text with underline markup. INFO is a plist
3109 holding contextual information."
3110 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3111 contents))
3113 ;;;; Verbatim
3115 (defun org-html-verbatim (verbatim contents info)
3116 "Transcode VERBATIM from Org to HTML.
3117 CONTENTS is nil. INFO is a plist holding contextual
3118 information."
3119 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3120 (org-html-plain-text (org-element-property :value verbatim) info)))
3122 ;;;; Verse Block
3124 (defun org-html-verse-block (verse-block contents info)
3125 "Transcode a VERSE-BLOCK element from Org to HTML.
3126 CONTENTS is verse block contents. INFO is a plist holding
3127 contextual information."
3128 ;; Replace each newline character with line break. Also replace
3129 ;; each blank line with a line break.
3130 (setq contents (replace-regexp-in-string
3131 "^ *\\\\\\\\$" "<br/>\n"
3132 (replace-regexp-in-string
3133 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3134 ;; Replace each white space at beginning of a line with a
3135 ;; non-breaking space.
3136 (while (string-match "^[ \t]+" contents)
3137 (let* ((num-ws (length (match-string 0 contents)))
3138 (ws (let (out) (dotimes (i num-ws out)
3139 (setq out (concat out "&#xa0;"))))))
3140 (setq contents (replace-match ws nil t contents))))
3141 (format "<p class=\"verse\">\n%s</p>" contents))
3144 ;;; Filter Functions
3146 (defun org-html-final-function (contents backend info)
3147 "Filter to indent the HTML and convert HTML entities."
3148 (with-temp-buffer
3149 (insert contents)
3150 (set-auto-mode t)
3151 (if org-html-indent
3152 (indent-region (point-min) (point-max)))
3153 (when org-html-use-unicode-chars
3154 (require 'mm-url)
3155 (mm-url-decode-entities))
3156 (buffer-substring-no-properties (point-min) (point-max))))
3159 ;;; End-user functions
3161 ;;;###autoload
3162 (defun org-html-export-as-html
3163 (&optional async subtreep visible-only body-only ext-plist)
3164 "Export current buffer to an HTML buffer.
3166 If narrowing is active in the current buffer, only export its
3167 narrowed part.
3169 If a region is active, export that region.
3171 A non-nil optional argument ASYNC means the process should happen
3172 asynchronously. The resulting buffer should be accessible
3173 through the `org-export-stack' interface.
3175 When optional argument SUBTREEP is non-nil, export the sub-tree
3176 at point, extracting information from the headline properties
3177 first.
3179 When optional argument VISIBLE-ONLY is non-nil, don't export
3180 contents of hidden elements.
3182 When optional argument BODY-ONLY is non-nil, only write code
3183 between \"<body>\" and \"</body>\" tags.
3185 EXT-PLIST, when provided, is a property list with external
3186 parameters overriding Org default settings, but still inferior to
3187 file-local settings.
3189 Export is done in a buffer named \"*Org HTML Export*\", which
3190 will be displayed when `org-export-show-temporary-export-buffer'
3191 is non-nil."
3192 (interactive)
3193 (if async
3194 (org-export-async-start
3195 (lambda (output)
3196 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3197 (erase-buffer)
3198 (insert output)
3199 (goto-char (point-min))
3200 (set-auto-mode t)
3201 (org-export-add-to-stack (current-buffer) 'html)))
3202 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3203 (let ((outbuf (org-export-to-buffer
3204 'html "*Org HTML Export*"
3205 subtreep visible-only body-only ext-plist)))
3206 ;; Set major mode.
3207 (with-current-buffer outbuf (set-auto-mode t))
3208 (when org-export-show-temporary-export-buffer
3209 (switch-to-buffer-other-window outbuf)))))
3211 ;;;###autoload
3212 (defun org-html-convert-region-to-html ()
3213 "Assume the current region has org-mode syntax, and convert it to HTML.
3214 This can be used in any buffer. For example, you can write an
3215 itemized list in org-mode syntax in an HTML buffer and use this
3216 command to convert it."
3217 (interactive)
3218 (org-export-replace-region-by 'html))
3220 ;;;###autoload
3221 (defun org-html-export-to-html
3222 (&optional async subtreep visible-only body-only ext-plist)
3223 "Export current buffer to a HTML file.
3225 If narrowing is active in the current buffer, only export its
3226 narrowed part.
3228 If a region is active, export that region.
3230 A non-nil optional argument ASYNC means the process should happen
3231 asynchronously. The resulting file should be accessible through
3232 the `org-export-stack' interface.
3234 When optional argument SUBTREEP is non-nil, export the sub-tree
3235 at point, extracting information from the headline properties
3236 first.
3238 When optional argument VISIBLE-ONLY is non-nil, don't export
3239 contents of hidden elements.
3241 When optional argument BODY-ONLY is non-nil, only write code
3242 between \"<body>\" and \"</body>\" tags.
3244 EXT-PLIST, when provided, is a property list with external
3245 parameters overriding Org default settings, but still inferior to
3246 file-local settings.
3248 Return output file's name."
3249 (interactive)
3250 (let* ((extension (concat "." org-html-extension))
3251 (file (org-export-output-file-name extension subtreep))
3252 (org-export-coding-system org-html-coding-system))
3253 (if async
3254 (org-export-async-start
3255 (lambda (f) (org-export-add-to-stack f 'html))
3256 (let ((org-export-coding-system org-html-coding-system))
3257 `(expand-file-name
3258 (org-export-to-file
3259 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3260 (let ((org-export-coding-system org-html-coding-system))
3261 (org-export-to-file
3262 'html file subtreep visible-only body-only ext-plist)))))
3264 ;;;###autoload
3265 (defun org-html-publish-to-html (plist filename pub-dir)
3266 "Publish an org file to HTML.
3268 FILENAME is the filename of the Org file to be published. PLIST
3269 is the property list for the given project. PUB-DIR is the
3270 publishing directory.
3272 Return output file name."
3273 (org-publish-org-to 'html filename
3274 (concat "." (or (plist-get plist :html-extension)
3275 org-html-extension "html"))
3276 plist pub-dir))
3279 ;;; FIXME
3281 ;;;; org-format-table-html
3282 ;;;; org-format-org-table-html
3283 ;;;; org-format-table-table-html
3284 ;;;; org-table-number-fraction
3285 ;;;; org-table-number-regexp
3286 ;;;; org-html-table-caption-above
3287 ;;;; org-html-inline-image-extensions
3288 ;;;; org-export-preferred-target-alist
3289 ;;;; class for anchors
3290 ;;;; org-export-mark-todo-in-toc
3291 ;;;; org-html-format-org-link
3292 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3293 ;;;; alt = (file-name-nondirectory path)
3295 (provide 'ox-html)
3297 ;; Local variables:
3298 ;; generated-autoload-file: "org-loaddefs.el"
3299 ;; End:
3301 ;;; ox-html.el ends here