ox-publish: Fix :recursive parameter ignoring extension restriction
[org-mode.git] / lisp / ox-html.el
blob8794882b816b47be818a8e3b0be497be3a0589f8
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 ;;;; Table
1295 (defun org-html-htmlize-region-for-paste (beg end)
1296 "Convert the region between BEG and END to HTML, using htmlize.el.
1297 This is much like `htmlize-region-for-paste', only that it uses
1298 the settings define in the org-... variables."
1299 (let* ((htmlize-output-type org-html-htmlize-output-type)
1300 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1301 (htmlbuf (htmlize-region beg end)))
1302 (unwind-protect
1303 (with-current-buffer htmlbuf
1304 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1305 (plist-get htmlize-buffer-places 'content-end)))
1306 (kill-buffer htmlbuf))))
1308 ;;;###autoload
1309 (defun org-html-htmlize-generate-css ()
1310 "Create the CSS for all font definitions in the current Emacs session.
1311 Use this to create face definitions in your CSS style file that can then
1312 be used by code snippets transformed by htmlize.
1313 This command just produces a buffer that contains class definitions for all
1314 faces used in the current Emacs session. You can copy and paste the ones you
1315 need into your CSS file.
1317 If you then set `org-html-htmlize-output-type' to `css', calls
1318 to the function `org-html-htmlize-region-for-paste' will
1319 produce code that uses these same face definitions."
1320 (interactive)
1321 (require 'htmlize)
1322 (and (get-buffer "*html*") (kill-buffer "*html*"))
1323 (with-temp-buffer
1324 (let ((fl (face-list))
1325 (htmlize-css-name-prefix "org-")
1326 (htmlize-output-type 'css)
1327 f i)
1328 (while (setq f (pop fl)
1329 i (and f (face-attribute f :inherit)))
1330 (when (and (symbolp f) (or (not i) (not (listp i))))
1331 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1332 (htmlize-region (point-min) (point-max))))
1333 (org-pop-to-buffer-same-window "*html*")
1334 (goto-char (point-min))
1335 (if (re-search-forward "<style" nil t)
1336 (delete-region (point-min) (match-beginning 0)))
1337 (if (re-search-forward "</style>" nil t)
1338 (delete-region (1+ (match-end 0)) (point-max)))
1339 (beginning-of-line 1)
1340 (if (looking-at " +") (replace-match ""))
1341 (goto-char (point-min)))
1343 (defun org-html--make-string (n string)
1344 "Build a string by concatenating N times STRING."
1345 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1347 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1348 "Turn todo keyword KWD into a valid class name.
1349 Replaces invalid characters with \"_\"."
1350 (save-match-data
1351 (while (string-match "[^a-zA-Z0-9_]" kwd)
1352 (setq kwd (replace-match "_" t t kwd))))
1353 kwd)
1355 (defun org-html-format-footnote-reference (n def refcnt)
1356 "Format footnote reference N with definition DEF into HTML."
1357 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1358 (format org-html-footnote-format
1359 (let* ((id (format "fnr.%s%s" n extra))
1360 (href (format " href=\"#fn.%s\"" n))
1361 (attributes (concat " class=\"footref\"" href)))
1362 (org-html--anchor id n attributes)))))
1364 (defun org-html-format-footnotes-section (section-name definitions)
1365 "Format footnotes section SECTION-NAME."
1366 (if (not definitions) ""
1367 (format org-html-footnotes-section section-name definitions)))
1369 (defun org-html-format-footnote-definition (fn)
1370 "Format the footnote definition FN."
1371 (let ((n (car fn)) (def (cdr fn)))
1372 (format
1373 "<div class=\"footdef\">%s %s</div>\n"
1374 (format org-html-footnote-format
1375 (let* ((id (format "fn.%s" n))
1376 (href (format " href=\"#fnr.%s\"" n))
1377 (attributes (concat " class=\"footnum\"" href)))
1378 (org-html--anchor id n attributes)))
1379 def)))
1381 (defun org-html-footnote-section (info)
1382 "Format the footnote section.
1383 INFO is a plist used as a communication channel."
1384 (let* ((fn-alist (org-export-collect-footnote-definitions
1385 (plist-get info :parse-tree) info))
1386 (fn-alist
1387 (loop for (n type raw) in fn-alist collect
1388 (cons n (if (eq (org-element-type raw) 'org-data)
1389 (org-trim (org-export-data raw info))
1390 (format "<p>%s</p>"
1391 (org-trim (org-export-data raw info))))))))
1392 (when fn-alist
1393 (org-html-format-footnotes-section
1394 (org-html--translate "Footnotes" info)
1395 (format
1396 "\n%s\n"
1397 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1400 ;;; Template
1402 (defun org-html--build-meta-info (info)
1403 "Return meta tags for exported document.
1404 INFO is a plist used as a communication channel."
1405 (let ((protect-string
1406 (lambda (str)
1407 (replace-regexp-in-string
1408 "\"" "&quot;" (org-html-encode-plain-text str))))
1409 (title (org-export-data (plist-get info :title) info))
1410 (author (and (plist-get info :with-author)
1411 (let ((auth (plist-get info :author)))
1412 (and auth
1413 ;; Return raw Org syntax, skipping non
1414 ;; exportable objects.
1415 (org-element-interpret-data
1416 (org-element-map auth
1417 (cons 'plain-text org-element-all-objects)
1418 'identity info))))))
1419 (description (plist-get info :description))
1420 (keywords (plist-get info :keywords)))
1421 (concat
1422 (format "<title>%s</title>\n" title)
1423 (when (plist-get info :time-stamp-file)
1424 (format-time-string
1425 (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
1426 (format
1427 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1428 (or (and org-html-coding-system
1429 (fboundp 'coding-system-get)
1430 (coding-system-get org-html-coding-system 'mime-charset))
1431 "iso-8859-1"))
1432 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1433 (and (org-string-nw-p author)
1434 (format "<meta name=\"author\" content=\"%s\"/>\n"
1435 (funcall protect-string author)))
1436 (and (org-string-nw-p description)
1437 (format "<meta name=\"description\" content=\"%s\"/>\n"
1438 (funcall protect-string description)))
1439 (and (org-string-nw-p keywords)
1440 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1441 (funcall protect-string keywords))))))
1443 (defun org-html--build-head (info)
1444 "Return information for the <head>..</head> of the HTML output.
1445 INFO is a plist used as a communication channel."
1446 (org-element-normalize-string
1447 (concat
1448 (when (plist-get info :html-head-include-default-style)
1449 (org-element-normalize-string org-html-style-default))
1450 (org-element-normalize-string (plist-get info :html-head))
1451 (org-element-normalize-string (plist-get info :html-head-extra))
1452 (when (and (plist-get info :html-htmlized-css-url)
1453 (eq org-html-htmlize-output-type 'css))
1454 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1455 (plist-get info :html-htmlized-css-url)))
1456 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1458 (defun org-html--build-mathjax-config (info)
1459 "Insert the user setup into the mathjax template.
1460 INFO is a plist used as a communication channel."
1461 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1462 (org-element-map (plist-get info :parse-tree)
1463 '(latex-fragment latex-environment) 'identity info t))
1464 (let ((template org-html-mathjax-template)
1465 (options org-html-mathjax-options)
1466 (in-buffer (or (plist-get info :html-mathjax) ""))
1467 name val (yes " ") (no "// ") x)
1468 (mapc
1469 (lambda (e)
1470 (setq name (car e) val (nth 1 e))
1471 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1472 (setq val (car (read-from-string
1473 (substring in-buffer (match-end 0))))))
1474 (if (not (stringp val)) (setq val (format "%s" val)))
1475 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1476 (setq template (replace-match val t t template))))
1477 options)
1478 (setq val (nth 1 (assq 'mathml options)))
1479 (if (string-match (concat "\\<mathml:") in-buffer)
1480 (setq val (car (read-from-string
1481 (substring in-buffer (match-end 0))))))
1482 ;; Exchange prefixes depending on mathml setting.
1483 (if (not val) (setq x yes yes no no x))
1484 ;; Replace cookies to turn on or off the config/jax lines.
1485 (if (string-match ":MMLYES:" template)
1486 (setq template (replace-match yes t t template)))
1487 (if (string-match ":MMLNO:" template)
1488 (setq template (replace-match no t t template)))
1489 ;; Return the modified template.
1490 (org-element-normalize-string template))))
1492 (defun org-html-format-spec (info)
1493 "Return format specification for elements that can be
1494 used in the preamble or postamble."
1495 `((?t . ,(org-export-data (plist-get info :title) info))
1496 (?d . ,(org-export-data (org-export-get-date info) info))
1497 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1498 (?a . ,(org-export-data (plist-get info :author) info))
1499 (?e . ,(mapconcat
1500 (lambda (e)
1501 (format "<a href=\"mailto:%s\">%s</a>" e e))
1502 (split-string (plist-get info :email) ",+ *")
1503 ", "))
1504 (?c . ,(plist-get info :creator))
1505 (?C . ,(let ((file (plist-get info :input-file)))
1506 (format-time-string org-html-metadata-timestamp-format
1507 (if file (nth 5 (file-attributes file))
1508 (current-time)))))
1509 (?v . ,(or org-html-validation-link ""))))
1511 (defun org-html--build-pre/postamble (type info)
1512 "Return document preamble or postamble as a string, or nil.
1513 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1514 communication channel."
1515 (let ((section (plist-get info (intern (format ":html-%s" type))))
1516 (spec (org-html-format-spec info)))
1517 (when section
1518 (let ((section-contents
1519 (if (functionp section) (funcall section info)
1520 (cond
1521 ((stringp section) (format-spec section spec))
1522 ((eq section 'auto)
1523 (let ((date (cdr (assq ?d spec)))
1524 (author (cdr (assq ?a spec)))
1525 (email (cdr (assq ?e spec)))
1526 (creator (cdr (assq ?c spec)))
1527 (timestamp (cdr (assq ?T spec)))
1528 (validation-link (cdr (assq ?v spec))))
1529 (concat
1530 (when (and (plist-get info :with-date)
1531 (org-string-nw-p date))
1532 (format "<p class=\"date\">%s: %s</p>\n"
1533 (org-html--translate "Date" info)
1534 date))
1535 (when (and (plist-get info :with-author)
1536 (org-string-nw-p author))
1537 (format "<p class=\"author\">%s: %s</p>\n"
1538 (org-html--translate "Author" info)
1539 author))
1540 (when (and (plist-get info :with-email)
1541 (org-string-nw-p email))
1542 (format "<p class=\"email\">%s: %s</p>\n"
1543 (org-html--translate "Email" info)
1544 email))
1545 (when (plist-get info :time-stamp-file)
1546 (format
1547 "<p class=\"date\">%s: %s</p>\n"
1548 (org-html--translate "Created" info)
1549 (format-time-string org-html-metadata-timestamp-format)))
1550 (when (plist-get info :with-creator)
1551 (format "<p class=\"creator\">%s</p>\n" creator))
1552 (format "<p class=\"xhtml-validation\">%s</p>\n"
1553 validation-link))))
1554 (t (format-spec
1555 (or (cadr (assoc
1556 (plist-get info :language)
1557 (eval (intern
1558 (format "org-html-%s-format" type)))))
1559 (cadr
1560 (assoc
1561 "en"
1562 (eval
1563 (intern (format "org-html-%s-format" type))))))
1564 spec))))))
1565 (when (org-string-nw-p section-contents)
1566 (concat
1567 (format "<%s id=\"%s\" class=\"%s\">\n"
1568 (nth 1 (assq type org-html-divs))
1569 (nth 2 (assq type org-html-divs))
1570 org-html--pre/postamble-class)
1571 (org-element-normalize-string section-contents)
1572 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1574 (defun org-html-inner-template (contents info)
1575 "Return body of document string after HTML conversion.
1576 CONTENTS is the transcoded contents string. INFO is a plist
1577 holding export options."
1578 (concat
1579 ;; Table of contents.
1580 (let ((depth (plist-get info :with-toc)))
1581 (when depth (org-html-toc depth info)))
1582 ;; Document contents.
1583 contents
1584 ;; Footnotes section.
1585 (org-html-footnote-section info)))
1587 (defun org-html-template (contents info)
1588 "Return complete document string after HTML conversion.
1589 CONTENTS is the transcoded contents string. INFO is a plist
1590 holding export options."
1591 (concat
1592 (format
1593 (or (and (stringp org-html-xml-declaration)
1594 org-html-xml-declaration)
1595 (cdr (assoc (plist-get info :html-extension)
1596 org-html-xml-declaration))
1597 (cdr (assoc "html" org-html-xml-declaration))
1600 (or (and org-html-coding-system
1601 (fboundp 'coding-system-get)
1602 (coding-system-get org-html-coding-system 'mime-charset))
1603 "iso-8859-1"))
1604 "\n"
1605 (plist-get info :html-doctype)
1606 "\n"
1607 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1608 (plist-get info :language) (plist-get info :language))
1609 "<head>\n"
1610 (org-html--build-meta-info info)
1611 (org-html--build-head info)
1612 (org-html--build-mathjax-config info)
1613 "</head>\n"
1614 "<body>\n"
1615 (let ((link-up (org-trim (plist-get info :html-link-up)))
1616 (link-home (org-trim (plist-get info :html-link-home))))
1617 (unless (and (string= link-up "") (string= link-home ""))
1618 (format org-html-home/up-format
1619 (or link-up link-home)
1620 (or link-home link-up))))
1621 ;; Preamble.
1622 (org-html--build-pre/postamble 'preamble info)
1623 ;; Document contents.
1624 (format "<%s id=\"%s\">\n"
1625 (nth 1 (assq 'content org-html-divs))
1626 (nth 2 (assq 'content org-html-divs)))
1627 ;; Document title.
1628 (let ((title (plist-get info :title)))
1629 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1630 contents
1631 (format "</%s>\n"
1632 (nth 1 (assq 'content org-html-divs)))
1633 ;; Postamble.
1634 (org-html--build-pre/postamble 'postamble info)
1635 ;; Closing document.
1636 "</body>\n</html>"))
1638 (defun org-html--translate (s info)
1639 "Translate string S according to specified language.
1640 INFO is a plist used as a communication channel."
1641 (org-export-translate s :html info))
1643 ;;;; Anchor
1645 (defun org-html--anchor (&optional id desc attributes)
1646 "Format a HTML anchor."
1647 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1648 (attributes (concat (and id (format " id=\"%s\"" id))
1649 (and name (format " name=\"%s\"" name))
1650 attributes)))
1651 (format "<a%s>%s</a>" attributes (or desc ""))))
1653 ;;;; Todo
1655 (defun org-html--todo (todo)
1656 "Format TODO keywords into HTML."
1657 (when todo
1658 (format "<span class=\"%s %s%s\">%s</span>"
1659 (if (member todo org-done-keywords) "done" "todo")
1660 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1661 todo)))
1663 ;;;; Tags
1665 (defun org-html--tags (tags)
1666 "Format TAGS into HTML."
1667 (when tags
1668 (format "<span class=\"tag\">%s</span>"
1669 (mapconcat
1670 (lambda (tag)
1671 (format "<span class=\"%s\">%s</span>"
1672 (concat org-html-tag-class-prefix
1673 (org-html-fix-class-name tag))
1674 tag))
1675 tags "&#xa0;"))))
1677 ;;;; Headline
1679 (defun* org-html-format-headline
1680 (todo todo-type priority text tags
1681 &key level section-number headline-label &allow-other-keys)
1682 "Format a headline in HTML."
1683 (let ((section-number
1684 (when section-number
1685 (format "<span class=\"section-number-%d\">%s</span> "
1686 level section-number)))
1687 (todo (org-html--todo todo))
1688 (tags (org-html--tags tags)))
1689 (concat section-number todo (and todo " ") text
1690 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1692 ;;;; Src Code
1694 (defun org-html-fontify-code (code lang)
1695 "Color CODE with htmlize library.
1696 CODE is a string representing the source code to colorize. LANG
1697 is the language used for CODE, as a string, or nil."
1698 (when code
1699 (cond
1700 ;; Case 1: No lang. Possibly an example block.
1701 ((not lang)
1702 ;; Simple transcoding.
1703 (org-html-encode-plain-text code))
1704 ;; Case 2: No htmlize or an inferior version of htmlize
1705 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1706 ;; Emit a warning.
1707 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1708 ;; Simple transcoding.
1709 (org-html-encode-plain-text code))
1711 ;; Map language
1712 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1713 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1714 (cond
1715 ;; Case 1: Language is not associated with any Emacs mode
1716 ((not (functionp lang-mode))
1717 ;; Simple transcoding.
1718 (org-html-encode-plain-text code))
1719 ;; Case 2: Default. Fontify code.
1721 ;; htmlize
1722 (setq code (with-temp-buffer
1723 ;; Switch to language-specific mode.
1724 (funcall lang-mode)
1725 (insert code)
1726 ;; Fontify buffer.
1727 (font-lock-fontify-buffer)
1728 ;; Remove formatting on newline characters.
1729 (save-excursion
1730 (let ((beg (point-min))
1731 (end (point-max)))
1732 (goto-char beg)
1733 (while (progn (end-of-line) (< (point) end))
1734 (put-text-property (point) (1+ (point)) 'face nil)
1735 (forward-char 1))))
1736 (org-src-mode)
1737 (set-buffer-modified-p nil)
1738 ;; Htmlize region.
1739 (org-html-htmlize-region-for-paste
1740 (point-min) (point-max))))
1741 ;; Strip any enclosing <pre></pre> tags.
1742 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1743 (end (and beg (string-match "</pre>\\'" code))))
1744 (if (and beg end) (substring code beg end) code)))))))))
1746 (defun org-html-do-format-code
1747 (code &optional lang refs retain-labels num-start)
1748 "Format CODE string as source code.
1749 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1750 respectively, the language of the source code, as a string, an
1751 alist between line numbers and references (as returned by
1752 `org-export-unravel-code'), a boolean specifying if labels should
1753 appear in the source code, and the number associated to the first
1754 line of code."
1755 (let* ((code-lines (org-split-string code "\n"))
1756 (code-length (length code-lines))
1757 (num-fmt
1758 (and num-start
1759 (format "%%%ds: "
1760 (length (number-to-string (+ code-length num-start))))))
1761 (code (org-html-fontify-code code lang)))
1762 (org-export-format-code
1763 code
1764 (lambda (loc line-num ref)
1765 (setq loc
1766 (concat
1767 ;; Add line number, if needed.
1768 (when num-start
1769 (format "<span class=\"linenr\">%s</span>"
1770 (format num-fmt line-num)))
1771 ;; Transcoded src line.
1773 ;; Add label, if needed.
1774 (when (and ref retain-labels) (format " (%s)" ref))))
1775 ;; Mark transcoded line as an anchor, if needed.
1776 (if (not ref) loc
1777 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1778 ref loc)))
1779 num-start refs)))
1781 (defun org-html-format-code (element info)
1782 "Format contents of ELEMENT as source code.
1783 ELEMENT is either an example block or a src block. INFO is
1784 a plist used as a communication channel."
1785 (let* ((lang (org-element-property :language element))
1786 ;; Extract code and references.
1787 (code-info (org-export-unravel-code element))
1788 (code (car code-info))
1789 (refs (cdr code-info))
1790 ;; Does the src block contain labels?
1791 (retain-labels (org-element-property :retain-labels element))
1792 ;; Does it have line numbers?
1793 (num-start (case (org-element-property :number-lines element)
1794 (continued (org-export-get-loc element info))
1795 (new 0))))
1796 (org-html-do-format-code code lang refs retain-labels num-start)))
1799 ;;; Tables of Contents
1801 (defun org-html-toc (depth info)
1802 "Build a table of contents.
1803 DEPTH is an integer specifying the depth of the table. INFO is a
1804 plist used as a communication channel. Return the table of
1805 contents as a string, or nil if it is empty."
1806 (let ((toc-entries
1807 (mapcar (lambda (headline)
1808 (cons (org-html--format-toc-headline headline info)
1809 (org-export-get-relative-level headline info)))
1810 (org-export-collect-headlines info depth))))
1811 (when toc-entries
1812 (concat "<div id=\"table-of-contents\">\n"
1813 (format "<h%d>%s</h%d>\n"
1814 org-html-toplevel-hlevel
1815 (org-html--translate "Table of Contents" info)
1816 org-html-toplevel-hlevel)
1817 "<div id=\"text-table-of-contents\">"
1818 (org-html--toc-text toc-entries)
1819 "</div>\n"
1820 "</div>\n"))))
1822 (defun org-html--toc-text (toc-entries)
1823 "Return innards of a table of contents, as a string.
1824 TOC-ENTRIES is an alist where key is an entry title, as a string,
1825 and value is its relative level, as an integer."
1826 (let* ((prev-level (1- (cdar toc-entries)))
1827 (start-level prev-level))
1828 (concat
1829 (mapconcat
1830 (lambda (entry)
1831 (let ((headline (car entry))
1832 (level (cdr entry)))
1833 (concat
1834 (let* ((cnt (- level prev-level))
1835 (times (if (> cnt 0) (1- cnt) (- cnt)))
1836 rtn)
1837 (setq prev-level level)
1838 (concat
1839 (org-html--make-string
1840 times (cond ((> cnt 0) "\n<ul>\n<li>")
1841 ((< cnt 0) "</li>\n</ul>\n")))
1842 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1843 headline)))
1844 toc-entries "")
1845 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1847 (defun org-html--format-toc-headline (headline info)
1848 "Return an appropriate table of contents entry for HEADLINE.
1849 INFO is a plist used as a communication channel."
1850 (let* ((headline-number (org-export-get-headline-number headline info))
1851 (section-number
1852 (and (not (org-export-low-level-p headline info))
1853 (org-export-numbered-headline-p headline info)
1854 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1855 (tags (and (eq (plist-get info :with-tags) t)
1856 (org-export-get-tags headline info))))
1857 (format "<a href=\"#%s\">%s</a>"
1858 ;; Label.
1859 (org-export-solidify-link-text
1860 (or (org-element-property :CUSTOM_ID headline)
1861 (concat "sec-" (mapconcat 'number-to-string
1862 headline-number "-"))))
1863 ;; Body.
1864 (concat section-number
1865 (org-export-data-with-translations
1866 (org-export-get-alt-title headline info)
1867 ;; Ignore any footnote-reference, link,
1868 ;; radio-target and target in table of contents.
1869 (append
1870 '((footnote-reference . ignore)
1871 (link . (lambda (link desc i) desc))
1872 (radio-target . (lambda (radio desc i) desc))
1873 (target . ignore))
1874 (org-export-backend-translate-table 'html))
1875 info)
1876 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1878 (defun org-html-list-of-listings (info)
1879 "Build a list of listings.
1880 INFO is a plist used as a communication channel. Return the list
1881 of listings as a string, or nil if it is empty."
1882 (let ((lol-entries (org-export-collect-listings info)))
1883 (when lol-entries
1884 (concat "<div id=\"list-of-listings\">\n"
1885 (format "<h%d>%s</h%d>\n"
1886 org-html-toplevel-hlevel
1887 (org-html--translate "List of Listings" info)
1888 org-html-toplevel-hlevel)
1889 "<div id=\"text-list-of-listings\">\n<ul>\n"
1890 (let ((count 0)
1891 (initial-fmt (org-html--translate "Listing %d:" info)))
1892 (mapconcat
1893 (lambda (entry)
1894 (let ((label (org-element-property :name entry))
1895 (title (org-trim
1896 (org-export-data
1897 (or (org-export-get-caption entry t)
1898 (org-export-get-caption entry))
1899 info))))
1900 (concat
1901 "<li>"
1902 (if (not label)
1903 (concat (format initial-fmt (incf count)) " " title)
1904 (format "<a href=\"#%s\">%s %s</a>"
1905 (org-export-solidify-link-text label)
1906 (format initial-fmt (incf count))
1907 title))
1908 "</li>")))
1909 lol-entries "\n"))
1910 "\n</ul>\n</div>\n</div>"))))
1912 (defun org-html-list-of-tables (info)
1913 "Build a list of tables.
1914 INFO is a plist used as a communication channel. Return the list
1915 of tables as a string, or nil if it is empty."
1916 (let ((lol-entries (org-export-collect-tables info)))
1917 (when lol-entries
1918 (concat "<div id=\"list-of-tables\">\n"
1919 (format "<h%d>%s</h%d>\n"
1920 org-html-toplevel-hlevel
1921 (org-html--translate "List of Tables" info)
1922 org-html-toplevel-hlevel)
1923 "<div id=\"text-list-of-tables\">\n<ul>\n"
1924 (let ((count 0)
1925 (initial-fmt (org-html--translate "Table %d:" info)))
1926 (mapconcat
1927 (lambda (entry)
1928 (let ((label (org-element-property :name entry))
1929 (title (org-trim
1930 (org-export-data
1931 (or (org-export-get-caption entry t)
1932 (org-export-get-caption entry))
1933 info))))
1934 (concat
1935 "<li>"
1936 (if (not label)
1937 (concat (format initial-fmt (incf count)) " " title)
1938 (format "<a href=\"#%s\">%s %s</a>"
1939 (org-export-solidify-link-text label)
1940 (format initial-fmt (incf count))
1941 title))
1942 "</li>")))
1943 lol-entries "\n"))
1944 "\n</ul>\n</div>\n</div>"))))
1947 ;;; Transcode Functions
1949 ;;;; Bold
1951 (defun org-html-bold (bold contents info)
1952 "Transcode BOLD from Org to HTML.
1953 CONTENTS is the text with bold markup. INFO is a plist holding
1954 contextual information."
1955 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1956 contents))
1958 ;;;; Center Block
1960 (defun org-html-center-block (center-block contents info)
1961 "Transcode a CENTER-BLOCK element from Org to HTML.
1962 CONTENTS holds the contents of the block. INFO is a plist
1963 holding contextual information."
1964 (format "<div class=\"center\">\n%s</div>" contents))
1966 ;;;; Clock
1968 (defun org-html-clock (clock contents info)
1969 "Transcode a CLOCK element from Org to HTML.
1970 CONTENTS is nil. INFO is a plist used as a communication
1971 channel."
1972 (format "<p>
1973 <span class=\"timestamp-wrapper\">
1974 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1975 </span>
1976 </p>"
1977 org-clock-string
1978 (org-translate-time
1979 (org-element-property :raw-value
1980 (org-element-property :value clock)))
1981 (let ((time (org-element-property :duration clock)))
1982 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1984 ;;;; Code
1986 (defun org-html-code (code contents info)
1987 "Transcode CODE from Org to HTML.
1988 CONTENTS is nil. INFO is a plist holding contextual
1989 information."
1990 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1991 (org-html-encode-plain-text (org-element-property :value code))))
1993 ;;;; Drawer
1995 (defun org-html-drawer (drawer contents info)
1996 "Transcode a DRAWER element from Org to HTML.
1997 CONTENTS holds the contents of the block. INFO is a plist
1998 holding contextual information."
1999 (if (functionp org-html-format-drawer-function)
2000 (funcall org-html-format-drawer-function
2001 (org-element-property :drawer-name drawer)
2002 contents)
2003 ;; If there's no user defined function: simply
2004 ;; display contents of the drawer.
2005 contents))
2007 ;;;; Dynamic Block
2009 (defun org-html-dynamic-block (dynamic-block contents info)
2010 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2011 CONTENTS holds the contents of the block. INFO is a plist
2012 holding contextual information. See `org-export-data'."
2013 contents)
2015 ;;;; Entity
2017 (defun org-html-entity (entity contents info)
2018 "Transcode an ENTITY object from Org to HTML.
2019 CONTENTS are the definition itself. INFO is a plist holding
2020 contextual information."
2021 (org-element-property :html entity))
2023 ;;;; Example Block
2025 (defun org-html-example-block (example-block contents info)
2026 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2027 CONTENTS is nil. INFO is a plist holding contextual
2028 information."
2029 (if (org-export-read-attribute :attr_html example-block :textarea)
2030 (org-html--textarea-block example-block)
2031 (format "<pre class=\"example\">\n%s</pre>"
2032 (org-html-format-code example-block info))))
2034 ;;;; Export Snippet
2036 (defun org-html-export-snippet (export-snippet contents info)
2037 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2038 CONTENTS is nil. INFO is a plist holding contextual
2039 information."
2040 (when (eq (org-export-snippet-backend export-snippet) 'html)
2041 (org-element-property :value export-snippet)))
2043 ;;;; Export Block
2045 (defun org-html-export-block (export-block contents info)
2046 "Transcode a EXPORT-BLOCK element from Org to HTML.
2047 CONTENTS is nil. INFO is a plist holding contextual information."
2048 (when (string= (org-element-property :type export-block) "HTML")
2049 (org-remove-indentation (org-element-property :value export-block))))
2051 ;;;; Fixed Width
2053 (defun org-html-fixed-width (fixed-width contents info)
2054 "Transcode a FIXED-WIDTH element from Org to HTML.
2055 CONTENTS is nil. INFO is a plist holding contextual information."
2056 (format "<pre class=\"example\">\n%s</pre>"
2057 (org-html-do-format-code
2058 (org-remove-indentation
2059 (org-element-property :value fixed-width)))))
2061 ;;;; Footnote Reference
2063 (defun org-html-footnote-reference (footnote-reference contents info)
2064 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2065 CONTENTS is nil. INFO is a plist holding contextual information."
2066 (concat
2067 ;; Insert separator between two footnotes in a row.
2068 (let ((prev (org-export-get-previous-element footnote-reference info)))
2069 (when (eq (org-element-type prev) 'footnote-reference)
2070 org-html-footnote-separator))
2071 (cond
2072 ((not (org-export-footnote-first-reference-p footnote-reference info))
2073 (org-html-format-footnote-reference
2074 (org-export-get-footnote-number footnote-reference info)
2075 "IGNORED" 100))
2076 ;; Inline definitions are secondary strings.
2077 ((eq (org-element-property :type footnote-reference) 'inline)
2078 (org-html-format-footnote-reference
2079 (org-export-get-footnote-number footnote-reference info)
2080 "IGNORED" 1))
2081 ;; Non-inline footnotes definitions are full Org data.
2082 (t (org-html-format-footnote-reference
2083 (org-export-get-footnote-number footnote-reference info)
2084 "IGNORED" 1)))))
2086 ;;;; Headline
2088 (defun org-html-format-headline--wrap
2089 (headline info &optional format-function &rest extra-keys)
2090 "Transcode a HEADLINE element from Org to HTML.
2091 CONTENTS holds the contents of the headline. INFO is a plist
2092 holding contextual information."
2093 (let* ((level (+ (org-export-get-relative-level headline info)
2094 (1- org-html-toplevel-hlevel)))
2095 (headline-number (org-export-get-headline-number headline info))
2096 (section-number (and (not (org-export-low-level-p headline info))
2097 (org-export-numbered-headline-p headline info)
2098 (mapconcat 'number-to-string
2099 headline-number ".")))
2100 (todo (and (plist-get info :with-todo-keywords)
2101 (let ((todo (org-element-property :todo-keyword headline)))
2102 (and todo (org-export-data todo info)))))
2103 (todo-type (and todo (org-element-property :todo-type headline)))
2104 (priority (and (plist-get info :with-priority)
2105 (org-element-property :priority headline)))
2106 (text (org-export-data (org-element-property :title headline) info))
2107 (tags (and (plist-get info :with-tags)
2108 (org-export-get-tags headline info)))
2109 (headline-label (or (org-element-property :CUSTOM_ID headline)
2110 (concat "sec-" (mapconcat 'number-to-string
2111 headline-number "-"))))
2112 (format-function
2113 (cond ((functionp format-function) format-function)
2114 ((functionp org-html-format-headline-function)
2115 (lambda (todo todo-type priority text tags &rest ignore)
2116 (funcall org-html-format-headline-function
2117 todo todo-type priority text tags)))
2118 (t 'org-html-format-headline))))
2119 (apply format-function
2120 todo todo-type priority text tags
2121 :headline-label headline-label :level level
2122 :section-number section-number extra-keys)))
2124 (defun org-html-headline (headline contents info)
2125 "Transcode a HEADLINE element from Org to HTML.
2126 CONTENTS holds the contents of the headline. INFO is a plist
2127 holding contextual information."
2128 ;; Empty contents?
2129 (setq contents (or contents ""))
2130 (let* ((numberedp (org-export-numbered-headline-p headline info))
2131 (level (org-export-get-relative-level headline info))
2132 (text (org-export-data (org-element-property :title headline) info))
2133 (todo (and (plist-get info :with-todo-keywords)
2134 (let ((todo (org-element-property :todo-keyword headline)))
2135 (and todo (org-export-data todo info)))))
2136 (todo-type (and todo (org-element-property :todo-type headline)))
2137 (tags (and (plist-get info :with-tags)
2138 (org-export-get-tags headline info)))
2139 (priority (and (plist-get info :with-priority)
2140 (org-element-property :priority headline)))
2141 (section-number (and (org-export-numbered-headline-p headline info)
2142 (mapconcat 'number-to-string
2143 (org-export-get-headline-number
2144 headline info) ".")))
2145 ;; Create the headline text.
2146 (full-text (org-html-format-headline--wrap headline info)))
2147 (cond
2148 ;; Case 1: This is a footnote section: ignore it.
2149 ((org-element-property :footnote-section-p headline) nil)
2150 ;; Case 2. This is a deep sub-tree: export it as a list item.
2151 ;; Also export as items headlines for which no section
2152 ;; format has been found.
2153 ((org-export-low-level-p headline info)
2154 ;; Build the real contents of the sub-tree.
2155 (let* ((type (if numberedp 'ordered 'unordered))
2156 (itemized-body (org-html-format-list-item
2157 contents type nil nil full-text)))
2158 (concat
2159 (and (org-export-first-sibling-p headline info)
2160 (org-html-begin-plain-list type))
2161 itemized-body
2162 (and (org-export-last-sibling-p headline info)
2163 (org-html-end-plain-list type)))))
2164 ;; Case 3. Standard headline. Export it as a section.
2166 (let* ((section-number (mapconcat 'number-to-string
2167 (org-export-get-headline-number
2168 headline info) "-"))
2169 (ids (remove 'nil
2170 (list (org-element-property :CUSTOM_ID headline)
2171 (concat "sec-" section-number)
2172 (org-element-property :ID headline))))
2173 (preferred-id (car ids))
2174 (extra-ids (cdr ids))
2175 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2176 (level1 (+ level (1- org-html-toplevel-hlevel)))
2177 (first-content (car (org-element-contents headline))))
2178 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2179 (org-html--container headline info)
2180 (format "outline-container-%s"
2181 (or (org-element-property :CUSTOM_ID headline)
2182 (concat "sec-" section-number)))
2183 (concat (format "outline-%d" level1) (and extra-class " ")
2184 extra-class)
2185 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2186 level1
2187 preferred-id
2188 (mapconcat
2189 (lambda (x)
2190 (let ((id (org-export-solidify-link-text
2191 (if (org-uuidgen-p x) (concat "ID-" x)
2192 x))))
2193 (org-html--anchor id)))
2194 extra-ids "")
2195 full-text
2196 level1)
2197 ;; When there is no section, pretend there is an empty
2198 ;; one to get the correct <div class="outline- ...>
2199 ;; which is needed by `org-info.js'.
2200 (if (not (eq (org-element-type first-content) 'section))
2201 (concat (org-html-section first-content "" info)
2202 contents)
2203 contents)
2204 (org-html--container headline info)))))))
2206 (defun org-html--container (headline info)
2207 (or (org-element-property :HTML_CONTAINER headline)
2208 (if (= 1 (org-export-get-relative-level headline info))
2209 (plist-get info :html-container)
2210 "div")))
2212 ;;;; Horizontal Rule
2214 (defun org-html-horizontal-rule (horizontal-rule contents info)
2215 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2216 CONTENTS is nil. INFO is a plist holding contextual information."
2217 "<hr/>")
2219 ;;;; Inline Src Block
2221 (defun org-html-inline-src-block (inline-src-block contents info)
2222 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2223 CONTENTS holds the contents of the item. INFO is a plist holding
2224 contextual information."
2225 (let* ((org-lang (org-element-property :language inline-src-block))
2226 (code (org-element-property :value inline-src-block)))
2227 (error "Cannot export inline src block")))
2229 ;;;; Inlinetask
2231 (defun org-html-format-section (text class &optional id)
2232 "Format a section with TEXT into a HTML div with CLASS and ID."
2233 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2234 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2236 (defun org-html-inlinetask (inlinetask contents info)
2237 "Transcode an INLINETASK element from Org to HTML.
2238 CONTENTS holds the contents of the block. INFO is a plist
2239 holding contextual information."
2240 (cond
2241 ;; If `org-html-format-inlinetask-function' is provided, call it
2242 ;; with appropriate arguments.
2243 ((functionp org-html-format-inlinetask-function)
2244 (let ((format-function
2245 (function*
2246 (lambda (todo todo-type priority text tags
2247 &key contents &allow-other-keys)
2248 (funcall org-html-format-inlinetask-function
2249 todo todo-type priority text tags contents)))))
2250 (org-html-format-headline--wrap
2251 inlinetask info format-function :contents contents)))
2252 ;; Otherwise, use a default template.
2253 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2254 (org-html-format-headline--wrap inlinetask info)
2255 contents))))
2257 ;;;; Italic
2259 (defun org-html-italic (italic contents info)
2260 "Transcode ITALIC from Org to HTML.
2261 CONTENTS is the text with italic markup. INFO is a plist holding
2262 contextual information."
2263 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2265 ;;;; Item
2267 (defun org-html-checkbox (checkbox)
2268 "Format CHECKBOX into HTML."
2269 (case checkbox (on "<code>[X]</code>")
2270 (off "<code>[&#xa0;]</code>")
2271 (trans "<code>[-]</code>")
2272 (t "")))
2274 (defun org-html-format-list-item (contents type checkbox
2275 &optional term-counter-id
2276 headline)
2277 "Format a list item into HTML."
2278 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2279 (concat
2280 (case type
2281 (ordered
2282 (let* ((counter term-counter-id)
2283 (extra (if counter (format " value=\"%s\"" counter) "")))
2284 (concat
2285 (format "<li%s>" extra)
2286 (when headline (concat headline "<br/>")))))
2287 (unordered
2288 (let* ((id term-counter-id)
2289 (extra (if id (format " id=\"%s\"" id) "")))
2290 (concat
2291 (format "<li%s>" extra)
2292 (when headline (concat headline "<br/>")))))
2293 (descriptive
2294 (let* ((term term-counter-id))
2295 (setq term (or term "(no term)"))
2296 ;; Check-boxes in descriptive lists are associated to tag.
2297 (concat (format "<dt> %s </dt>"
2298 (concat checkbox term))
2299 "<dd>"))))
2300 (unless (eq type 'descriptive) checkbox)
2301 contents
2302 (case type
2303 (ordered "</li>")
2304 (unordered "</li>")
2305 (descriptive "</dd>")))))
2307 (defun org-html-item (item contents info)
2308 "Transcode an ITEM element from Org to HTML.
2309 CONTENTS holds the contents of the item. INFO is a plist holding
2310 contextual information."
2311 (let* ((plain-list (org-export-get-parent item))
2312 (type (org-element-property :type plain-list))
2313 (counter (org-element-property :counter item))
2314 (checkbox (org-element-property :checkbox item))
2315 (tag (let ((tag (org-element-property :tag item)))
2316 (and tag (org-export-data tag info)))))
2317 (org-html-format-list-item
2318 contents type checkbox (or tag counter))))
2320 ;;;; Keyword
2322 (defun org-html-keyword (keyword contents info)
2323 "Transcode a KEYWORD element from Org to HTML.
2324 CONTENTS is nil. INFO is a plist holding contextual information."
2325 (let ((key (org-element-property :key keyword))
2326 (value (org-element-property :value keyword)))
2327 (cond
2328 ((string= key "HTML") value)
2329 ((string= key "TOC")
2330 (let ((value (downcase value)))
2331 (cond
2332 ((string-match "\\<headlines\\>" value)
2333 (let ((depth (or (and (string-match "[0-9]+" value)
2334 (string-to-number (match-string 0 value)))
2335 (plist-get info :with-toc))))
2336 (org-html-toc depth info)))
2337 ((string= "listings" value) (org-html-list-of-listings info))
2338 ((string= "tables" value) (org-html-list-of-tables info))))))))
2340 ;;;; Latex Environment
2342 (defun org-html-format-latex (latex-frag processing-type)
2343 "Format a LaTeX fragment LATEX-FRAG into HTML."
2344 (let ((cache-relpath "") (cache-dir ""))
2345 (unless (eq processing-type 'mathjax)
2346 (let ((bfn (or (buffer-file-name)
2347 (make-temp-name
2348 (expand-file-name "latex" temporary-file-directory)))))
2349 (setq cache-relpath
2350 (concat "ltxpng/"
2351 (file-name-sans-extension
2352 (file-name-nondirectory bfn)))
2353 cache-dir (file-name-directory bfn))))
2354 (with-temp-buffer
2355 (insert latex-frag)
2356 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2357 nil nil processing-type)
2358 (buffer-string))))
2360 (defun org-html-latex-environment (latex-environment contents info)
2361 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2362 CONTENTS is nil. INFO is a plist holding contextual information."
2363 (let ((processing-type (plist-get info :with-latex))
2364 (latex-frag (org-remove-indentation
2365 (org-element-property :value latex-environment)))
2366 (caption (org-export-data
2367 (org-export-get-caption latex-environment) info))
2368 (attr nil) ; FIXME
2369 (label (org-element-property :name latex-environment)))
2370 (cond
2371 ((memq processing-type '(t mathjax))
2372 (org-html-format-latex latex-frag 'mathjax))
2373 ((eq processing-type 'dvipng)
2374 (let* ((formula-link (org-html-format-latex
2375 latex-frag processing-type)))
2376 (when (and formula-link
2377 (string-match "file:\\([^]]*\\)" formula-link))
2378 (org-html-format-inline-image
2379 (match-string 1 formula-link) caption label attr t))))
2380 (t latex-frag))))
2382 ;;;; Latex Fragment
2384 (defun org-html-latex-fragment (latex-fragment contents info)
2385 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2386 CONTENTS is nil. INFO is a plist holding contextual information."
2387 (let ((latex-frag (org-element-property :value latex-fragment))
2388 (processing-type (plist-get info :with-latex)))
2389 (case processing-type
2390 ((t mathjax)
2391 (org-html-format-latex latex-frag 'mathjax))
2392 (dvipng
2393 (let* ((formula-link (org-html-format-latex
2394 latex-frag processing-type)))
2395 (when (and formula-link
2396 (string-match "file:\\([^]]*\\)" formula-link))
2397 (org-html-format-inline-image
2398 (match-string 1 formula-link)))))
2399 (t latex-frag))))
2401 ;;;; Line Break
2403 (defun org-html-line-break (line-break contents info)
2404 "Transcode a LINE-BREAK object from Org to HTML.
2405 CONTENTS is nil. INFO is a plist holding contextual information."
2406 "<br/>\n")
2408 ;;;; Link
2410 (defun org-html-link--inline-image (link desc info)
2411 "Return HTML code for an inline image.
2413 LINK is the link pointing to the inline image. INFO is a plist
2414 used as a communication channel.
2416 Inline images can have these attributes:
2418 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2419 (let* ((type (org-element-property :type link))
2420 (raw-path (org-element-property :path link))
2421 (path (cond ((member type '("http" "https"))
2422 (concat type ":" raw-path))
2423 ((file-name-absolute-p raw-path)
2424 (expand-file-name raw-path))
2425 (t raw-path)))
2426 (parent (org-export-get-parent-element link))
2427 (caption (org-export-data (org-export-get-caption parent) info))
2428 (label (org-element-property :name parent)))
2429 ;; Return proper string, depending on DISPOSITION.
2430 (org-html-format-inline-image
2431 path caption label
2432 (org-html--make-attribute-string
2433 (org-export-read-attribute :attr_html parent))
2434 (org-html-standalone-image-p link info))))
2436 (defvar org-html-standalone-image-predicate)
2437 (defun org-html-standalone-image-p (element info &optional predicate)
2438 "Test if ELEMENT is a standalone image for the purpose HTML export.
2439 INFO is a plist holding contextual information.
2441 Return non-nil, if ELEMENT is of type paragraph and it's sole
2442 content, save for whitespaces, is a link that qualifies as an
2443 inline image.
2445 Return non-nil, if ELEMENT is of type link and it's containing
2446 paragraph has no other content save for leading and trailing
2447 whitespaces.
2449 Return nil, otherwise.
2451 Bind `org-html-standalone-image-predicate' to constrain
2452 paragraph further. For example, to check for only captioned
2453 standalone images, do the following.
2455 \(setq org-html-standalone-image-predicate
2456 \(lambda \(paragraph\)
2457 \(org-element-property :caption paragraph\)\)\)"
2458 (let ((paragraph (case (org-element-type element)
2459 (paragraph element)
2460 (link (and (org-export-inline-image-p
2461 element org-html-inline-image-rules)
2462 (org-export-get-parent element)))
2463 (t nil))))
2464 (when (eq (org-element-type paragraph) 'paragraph)
2465 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2466 (functionp org-html-standalone-image-predicate)))
2467 (funcall org-html-standalone-image-predicate paragraph))
2468 (let ((contents (org-element-contents paragraph)))
2469 (loop for x in contents
2470 with inline-image-count = 0
2471 always (cond
2472 ((eq (org-element-type x) 'plain-text)
2473 (not (org-string-nw-p x)))
2474 ((eq (org-element-type x) 'link)
2475 (when (org-export-inline-image-p
2476 x org-html-inline-image-rules)
2477 (= (incf inline-image-count) 1)))
2478 (t nil))))))))
2480 (defun org-html-link (link desc info)
2481 "Transcode a LINK object from Org to HTML.
2483 DESC is the description part of the link, or the empty string.
2484 INFO is a plist holding contextual information. See
2485 `org-export-data'."
2486 (let* ((link-org-files-as-html-maybe
2487 (function
2488 (lambda (raw-path info)
2489 "Treat links to `file.org' as links to `file.html', if needed.
2490 See `org-html-link-org-files-as-html'."
2491 (cond
2492 ((and org-html-link-org-files-as-html
2493 (string= ".org"
2494 (downcase (file-name-extension raw-path "."))))
2495 (concat (file-name-sans-extension raw-path) "."
2496 (plist-get info :html-extension)))
2497 (t raw-path)))))
2498 (type (org-element-property :type link))
2499 (raw-path (org-element-property :path link))
2500 ;; Ensure DESC really exists, or set it to nil.
2501 (desc (org-string-nw-p desc))
2502 (path
2503 (cond
2504 ((member type '("http" "https" "ftp" "mailto"))
2505 (concat type ":" raw-path))
2506 ((string= type "file")
2507 ;; Treat links to ".org" files as ".html", if needed.
2508 (setq raw-path
2509 (funcall link-org-files-as-html-maybe raw-path info))
2510 ;; If file path is absolute, prepend it with protocol
2511 ;; component - "file://".
2512 (when (file-name-absolute-p raw-path)
2513 (setq raw-path
2514 (concat "file://" (expand-file-name raw-path))))
2515 ;; Add search option, if any. A search option can be
2516 ;; relative to a custom-id or a headline title. Any other
2517 ;; option is ignored.
2518 (let ((option (org-element-property :search-option link)))
2519 (cond ((not option) raw-path)
2520 ((eq (aref option 0) ?#) (concat raw-path option))
2521 ;; External fuzzy link: try to resolve it if path
2522 ;; belongs to current project, if any.
2523 ((eq (aref option 0) ?*)
2524 (concat
2525 raw-path
2526 (let ((numbers
2527 (org-publish-resolve-external-fuzzy-link
2528 (org-element-property :path link) option)))
2529 (and numbers (concat "#sec-"
2530 (mapconcat 'number-to-string
2531 numbers "-"))))))
2532 (t raw-path))))
2533 (t raw-path)))
2534 ;; Extract attributes from parent's paragraph. HACK: Only do
2535 ;; this for the first link in parent. This is needed as long
2536 ;; as attributes cannot be set on a per link basis.
2537 (attributes
2538 (let ((parent (org-export-get-parent-element link)))
2539 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2541 (let ((att (org-html--make-attribute-string
2542 (org-export-read-attribute :attr_html parent))))
2543 (cond ((not (org-string-nw-p att)) "")
2544 ((and desc (string-match (regexp-quote att) desc)) "")
2545 (t (concat " " att)))))))
2546 protocol)
2547 (cond
2548 ;; Image file.
2549 ((and (or (eq t org-html-inline-images)
2550 (and org-html-inline-images (not desc)))
2551 (org-export-inline-image-p link org-html-inline-image-rules))
2552 (org-html-link--inline-image link desc info))
2553 ;; Radio target: Transcode target's contents and use them as
2554 ;; link's description.
2555 ((string= type "radio")
2556 (let ((destination (org-export-resolve-radio-link link info)))
2557 (when destination
2558 (format "<a href=\"#%s\"%s>%s</a>"
2559 (org-export-solidify-link-text path)
2560 attributes
2561 (org-export-data (org-element-contents destination) info)))))
2562 ;; Links pointing to a headline: Find destination and build
2563 ;; appropriate referencing command.
2564 ((member type '("custom-id" "fuzzy" "id"))
2565 (let ((destination (if (string= type "fuzzy")
2566 (org-export-resolve-fuzzy-link link info)
2567 (org-export-resolve-id-link link info))))
2568 (case (org-element-type destination)
2569 ;; ID link points to an external file.
2570 (plain-text
2571 (let ((fragment (concat "ID-" path))
2572 ;; Treat links to ".org" files as ".html", if needed.
2573 (path (funcall link-org-files-as-html-maybe
2574 destination info)))
2575 (format "<a href=\"%s#%s\"%s>%s</a>"
2576 path fragment attributes (or desc destination))))
2577 ;; Fuzzy link points nowhere.
2578 ((nil)
2579 (format "<i>%s</i>"
2580 (or desc
2581 (org-export-data
2582 (org-element-property :raw-link link) info))))
2583 ;; Fuzzy link points to an invisible target.
2584 (keyword nil)
2585 ;; Link points to a headline.
2586 (headline
2587 (let ((href
2588 ;; What href to use?
2589 (cond
2590 ;; Case 1: Headline is linked via it's CUSTOM_ID
2591 ;; property. Use CUSTOM_ID.
2592 ((string= type "custom-id")
2593 (org-element-property :CUSTOM_ID destination))
2594 ;; Case 2: Headline is linked via it's ID property
2595 ;; or through other means. Use the default href.
2596 ((member type '("id" "fuzzy"))
2597 (format "sec-%s"
2598 (mapconcat 'number-to-string
2599 (org-export-get-headline-number
2600 destination info) "-")))
2601 (t (error "Shouldn't reach here"))))
2602 ;; What description to use?
2603 (desc
2604 ;; Case 1: Headline is numbered and LINK has no
2605 ;; description. Display section number.
2606 (if (and (org-export-numbered-headline-p destination info)
2607 (not desc))
2608 (mapconcat 'number-to-string
2609 (org-export-get-headline-number
2610 destination info) ".")
2611 ;; Case 2: Either the headline is un-numbered or
2612 ;; LINK has a custom description. Display LINK's
2613 ;; description or headline's title.
2614 (or desc (org-export-data (org-element-property
2615 :title destination) info)))))
2616 (format "<a href=\"#%s\"%s>%s</a>"
2617 (org-export-solidify-link-text href) attributes desc)))
2618 ;; Fuzzy link points to a target. Do as above.
2620 (let ((path (org-export-solidify-link-text path)) number)
2621 (unless desc
2622 (setq number (cond
2623 ((org-html-standalone-image-p destination info)
2624 (org-export-get-ordinal
2625 (assoc 'link (org-element-contents destination))
2626 info 'link 'org-html-standalone-image-p))
2627 (t (org-export-get-ordinal destination info))))
2628 (setq desc (when number
2629 (if (atom number) (number-to-string number)
2630 (mapconcat 'number-to-string number ".")))))
2631 (format "<a href=\"#%s\"%s>%s</a>"
2632 path attributes (or desc "No description for this link")))))))
2633 ;; Coderef: replace link with the reference name or the
2634 ;; equivalent line number.
2635 ((string= type "coderef")
2636 (let ((fragment (concat "coderef-" path)))
2637 (format "<a href=\"#%s\"%s%s>%s</a>"
2638 fragment
2639 (org-trim
2640 (format (concat "class=\"coderef\""
2641 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2642 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2643 fragment fragment))
2644 attributes
2645 (format (org-export-get-coderef-format path desc)
2646 (org-export-resolve-coderef path info)))))
2647 ;; Link type is handled by a special function.
2648 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2649 (funcall protocol (org-link-unescape path) desc 'html))
2650 ;; External link with a description part.
2651 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2652 ;; External link without a description part.
2653 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2654 ;; No path, only description. Try to do something useful.
2655 (t (format "<i>%s</i>" desc)))))
2657 ;;;; Paragraph
2659 (defun org-html-paragraph (paragraph contents info)
2660 "Transcode a PARAGRAPH element from Org to HTML.
2661 CONTENTS is the contents of the paragraph, as a string. INFO is
2662 the plist used as a communication channel."
2663 (let* ((parent (org-export-get-parent paragraph))
2664 (parent-type (org-element-type parent))
2665 (style '((footnote-definition " class=\"footpara\"")))
2666 (extra (or (cadr (assoc parent-type style)) "")))
2667 (cond
2668 ((and (eq (org-element-type parent) 'item)
2669 (= (org-element-property :begin paragraph)
2670 (org-element-property :contents-begin parent)))
2671 ;; leading paragraph in a list item have no tags
2672 contents)
2673 ((org-html-standalone-image-p paragraph info)
2674 ;; standalone image
2675 contents)
2676 (t (format "<p%s>\n%s</p>" extra contents)))))
2678 ;;;; Plain List
2680 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2681 ;; the correct value for the item counter
2682 (defun org-html-begin-plain-list (type &optional arg1)
2683 "Insert the beginning of the HTML list depending on TYPE.
2684 When ARG1 is a string, use it as the start parameter for ordered
2685 lists."
2686 (case type
2687 (ordered
2688 (format "<ol class=\"org-ol\"%s>"
2689 (if arg1 (format " start=\"%d\"" arg1) "")))
2690 (unordered "<ul class=\"org-ul\">")
2691 (descriptive "<dl class=\"org-dl\">")))
2693 (defun org-html-end-plain-list (type)
2694 "Insert the end of the HTML list depending on TYPE."
2695 (case type
2696 (ordered "</ol>")
2697 (unordered "</ul>")
2698 (descriptive "</dl>")))
2700 (defun org-html-plain-list (plain-list contents info)
2701 "Transcode a PLAIN-LIST element from Org to HTML.
2702 CONTENTS is the contents of the list. INFO is a plist holding
2703 contextual information."
2704 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2705 (type (org-element-property :type plain-list)))
2706 (format "%s\n%s%s"
2707 (org-html-begin-plain-list type)
2708 contents (org-html-end-plain-list type))))
2710 ;;;; Plain Text
2712 (defun org-html-convert-special-strings (string)
2713 "Convert special characters in STRING to HTML."
2714 (let ((all org-html-special-string-regexps)
2715 e a re rpl start)
2716 (while (setq a (pop all))
2717 (setq re (car a) rpl (cdr a) start 0)
2718 (while (string-match re string start)
2719 (setq string (replace-match rpl t nil string))))
2720 string))
2722 (defun org-html-encode-plain-text (text)
2723 "Convert plain text characters from TEXT to HTML equivalent.
2724 Possible conversions are set in `org-html-protect-char-alist'."
2725 (mapc
2726 (lambda (pair)
2727 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2728 org-html-protect-char-alist)
2729 text)
2731 (defun org-html-plain-text (text info)
2732 "Transcode a TEXT string from Org to HTML.
2733 TEXT is the string to transcode. INFO is a plist holding
2734 contextual information."
2735 (let ((output text))
2736 ;; Protect following characters: <, >, &.
2737 (setq output (org-html-encode-plain-text output))
2738 ;; Handle smart quotes. Be sure to provide original string since
2739 ;; OUTPUT may have been modified.
2740 (when (plist-get info :with-smart-quotes)
2741 (setq output (org-export-activate-smart-quotes output :html info text)))
2742 ;; Handle special strings.
2743 (when (plist-get info :with-special-strings)
2744 (setq output (org-html-convert-special-strings output)))
2745 ;; Handle break preservation if required.
2746 (when (plist-get info :preserve-breaks)
2747 (setq output
2748 (replace-regexp-in-string
2749 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2750 ;; Return value.
2751 output))
2754 ;; Planning
2756 (defun org-html-planning (planning contents info)
2757 "Transcode a PLANNING element from Org to HTML.
2758 CONTENTS is nil. INFO is a plist used as a communication
2759 channel."
2760 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2761 (format
2762 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2763 (mapconcat
2764 'identity
2765 (delq nil
2766 (list
2767 (let ((closed (org-element-property :closed planning)))
2768 (when closed
2769 (format span-fmt org-closed-string
2770 (org-translate-time
2771 (org-element-property :raw-value closed)))))
2772 (let ((deadline (org-element-property :deadline planning)))
2773 (when deadline
2774 (format span-fmt org-deadline-string
2775 (org-translate-time
2776 (org-element-property :raw-value deadline)))))
2777 (let ((scheduled (org-element-property :scheduled planning)))
2778 (when scheduled
2779 (format span-fmt org-scheduled-string
2780 (org-translate-time
2781 (org-element-property :raw-value scheduled)))))))
2782 " "))))
2784 ;;;; Property Drawer
2786 (defun org-html-property-drawer (property-drawer contents info)
2787 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2788 CONTENTS is nil. INFO is a plist holding contextual
2789 information."
2790 ;; The property drawer isn't exported but we want separating blank
2791 ;; lines nonetheless.
2794 ;;;; Quote Block
2796 (defun org-html-quote-block (quote-block contents info)
2797 "Transcode a QUOTE-BLOCK element from Org to HTML.
2798 CONTENTS holds the contents of the block. INFO is a plist
2799 holding contextual information."
2800 (format "<blockquote>\n%s</blockquote>" contents))
2802 ;;;; Quote Section
2804 (defun org-html-quote-section (quote-section contents info)
2805 "Transcode a QUOTE-SECTION element from Org to HTML.
2806 CONTENTS is nil. INFO is a plist holding contextual information."
2807 (let ((value (org-remove-indentation
2808 (org-element-property :value quote-section))))
2809 (when value (format "<pre>\n%s</pre>" value))))
2811 ;;;; Section
2813 (defun org-html-section (section contents info)
2814 "Transcode a SECTION element from Org to HTML.
2815 CONTENTS holds the contents of the section. INFO is a plist
2816 holding contextual information."
2817 (let ((parent (org-export-get-parent-headline section)))
2818 ;; Before first headline: no container, just return CONTENTS.
2819 (if (not parent) contents
2820 ;; Get div's class and id references.
2821 (let* ((class-num (+ (org-export-get-relative-level parent info)
2822 (1- org-html-toplevel-hlevel)))
2823 (section-number
2824 (mapconcat
2825 'number-to-string
2826 (org-export-get-headline-number parent info) "-")))
2827 ;; Build return value.
2828 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2829 class-num
2830 (or (org-element-property :CUSTOM_ID parent) section-number)
2831 contents)))))
2833 ;;;; Radio Target
2835 (defun org-html-radio-target (radio-target text info)
2836 "Transcode a RADIO-TARGET object from Org to HTML.
2837 TEXT is the text of the target. INFO is a plist holding
2838 contextual information."
2839 (let ((id (org-export-solidify-link-text
2840 (org-element-property :value radio-target))))
2841 (org-html--anchor id text)))
2843 ;;;; Special Block
2845 (defun org-html-special-block (special-block contents info)
2846 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2847 CONTENTS holds the contents of the block. INFO is a plist
2848 holding contextual information."
2849 (format "<div class=\"%s\">\n%s\n</div>"
2850 (downcase (org-element-property :type special-block))
2851 contents))
2853 ;;;; Src Block
2855 (defun org-html-src-block (src-block contents info)
2856 "Transcode a SRC-BLOCK element from Org to HTML.
2857 CONTENTS holds the contents of the item. INFO is a plist holding
2858 contextual information."
2859 (if (org-export-read-attribute :attr_html src-block :textarea)
2860 (org-html--textarea-block src-block)
2861 (let ((lang (org-element-property :language src-block))
2862 (caption (org-export-get-caption src-block))
2863 (code (org-html-format-code src-block info))
2864 (label (let ((lbl (org-element-property :name src-block)))
2865 (if (not lbl) ""
2866 (format " id=\"%s\""
2867 (org-export-solidify-link-text lbl))))))
2868 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2869 (format
2870 "<div class=\"org-src-container\">\n%s%s\n</div>"
2871 (if (not caption) ""
2872 (format "<label class=\"org-src-name\">%s</label>"
2873 (org-export-data caption info)))
2874 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2876 ;;;; Statistics Cookie
2878 (defun org-html-statistics-cookie (statistics-cookie contents info)
2879 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2880 CONTENTS is nil. INFO is a plist holding contextual information."
2881 (let ((cookie-value (org-element-property :value statistics-cookie)))
2882 (format "<code>%s</code>" cookie-value)))
2884 ;;;; Strike-Through
2886 (defun org-html-strike-through (strike-through contents info)
2887 "Transcode STRIKE-THROUGH from Org to HTML.
2888 CONTENTS is the text with strike-through markup. INFO is a plist
2889 holding contextual information."
2890 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2891 contents))
2893 ;;;; Subscript
2895 (defun org-html-subscript (subscript contents info)
2896 "Transcode a SUBSCRIPT object from Org to HTML.
2897 CONTENTS is the contents of the object. INFO is a plist holding
2898 contextual information."
2899 (format "<sub>%s</sub>" contents))
2901 ;;;; Superscript
2903 (defun org-html-superscript (superscript contents info)
2904 "Transcode a SUPERSCRIPT object from Org to HTML.
2905 CONTENTS is the contents of the object. INFO is a plist holding
2906 contextual information."
2907 (format "<sup>%s</sup>" contents))
2909 ;;;; Tabel Cell
2911 (defun org-html-table-cell (table-cell contents info)
2912 "Transcode a TABLE-CELL element from Org to HTML.
2913 CONTENTS is nil. INFO is a plist used as a communication
2914 channel."
2915 (let* ((table-row (org-export-get-parent table-cell))
2916 (table (org-export-get-parent-table table-cell))
2917 (cell-attrs
2918 (if (not org-html-table-align-individual-fields) ""
2919 (format (if (and (boundp 'org-html-format-table-no-css)
2920 org-html-format-table-no-css)
2921 " align=\"%s\"" " class=\"%s\"")
2922 (org-export-table-cell-alignment table-cell info)))))
2923 (when (or (not contents) (string= "" (org-trim contents)))
2924 (setq contents "&#xa0;"))
2925 (cond
2926 ((and (org-export-table-has-header-p table info)
2927 (= 1 (org-export-table-row-group table-row info)))
2928 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2929 contents (cdr org-html-table-header-tags)))
2930 ((and org-html-table-use-header-tags-for-first-column
2931 (zerop (cdr (org-export-table-cell-address table-cell info))))
2932 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2933 contents (cdr org-html-table-header-tags)))
2934 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2935 contents (cdr org-html-table-data-tags))))))
2937 ;;;; Table Row
2939 (defun org-html-table-row (table-row contents info)
2940 "Transcode a TABLE-ROW element from Org to HTML.
2941 CONTENTS is the contents of the row. INFO is a plist used as a
2942 communication channel."
2943 ;; Rules are ignored since table separators are deduced from
2944 ;; borders of the current row.
2945 (when (eq (org-element-property :type table-row) 'standard)
2946 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2947 (row-number (org-export-table-row-number table-row info))
2948 (start-rowgroup-p
2949 (org-export-table-row-starts-rowgroup-p table-row info))
2950 (end-rowgroup-p
2951 (org-export-table-row-ends-rowgroup-p table-row info))
2952 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2953 ;; but should be set so that `org-html-table-row-tags' can
2954 ;; use them (see the docstring of this variable.)
2955 (top-row-p (and (equal start-rowgroup-p '(top))
2956 (equal end-rowgroup-p '(below top))))
2957 (bottom-row-p (and (equal start-rowgroup-p '(above))
2958 (equal end-rowgroup-p '(bottom above))))
2959 (rowgroup-tags
2960 (cond
2961 ;; Case 1: Row belongs to second or subsequent rowgroups.
2962 ((not (= 1 rowgroup-number))
2963 '("<tbody>" . "\n</tbody>"))
2964 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2965 ((org-export-table-has-header-p
2966 (org-export-get-parent-table table-row) info)
2967 '("<thead>" . "\n</thead>"))
2968 ;; Case 2: Row is from first and only row group.
2969 (t '("<tbody>" . "\n</tbody>")))))
2970 (concat
2971 ;; Begin a rowgroup?
2972 (when start-rowgroup-p (car rowgroup-tags))
2973 ;; Actual table row
2974 (concat "\n" (eval (car org-html-table-row-tags))
2975 contents
2976 "\n"
2977 (eval (cdr org-html-table-row-tags)))
2978 ;; End a rowgroup?
2979 (when end-rowgroup-p (cdr rowgroup-tags))))))
2981 ;;;; Table
2983 (defun org-html-table-first-row-data-cells (table info)
2984 "Transcode the first row of TABLE.
2985 INFO is a plist used as a communication channel."
2986 (let ((table-row
2987 (org-element-map table 'table-row
2988 (lambda (row)
2989 (unless (eq (org-element-property :type row) 'rule) row))
2990 info 'first-match))
2991 (special-column-p (org-export-table-has-special-column-p table)))
2992 (if (not special-column-p) (org-element-contents table-row)
2993 (cdr (org-element-contents table-row)))))
2995 (defun org-html-table--table.el-table (table info)
2996 "Format table.el tables into HTML.
2997 INFO is a plist used as a communication channel."
2998 (when (eq (org-element-property :type table) 'table.el)
2999 (require 'table)
3000 (let ((outbuf (with-current-buffer
3001 (get-buffer-create "*org-export-table*")
3002 (erase-buffer) (current-buffer))))
3003 (with-temp-buffer
3004 (insert (org-element-property :value table))
3005 (goto-char 1)
3006 (re-search-forward "^[ \t]*|[^|]" nil t)
3007 (table-generate-source 'html outbuf))
3008 (with-current-buffer outbuf
3009 (prog1 (org-trim (buffer-string))
3010 (kill-buffer) )))))
3012 (defun org-html-table (table contents info)
3013 "Transcode a TABLE element from Org to HTML.
3014 CONTENTS is the contents of the table. INFO is a plist holding
3015 contextual information."
3016 (case (org-element-property :type table)
3017 ;; Case 1: table.el table. Convert it using appropriate tools.
3018 (table.el (org-html-table--table.el-table table info))
3019 ;; Case 2: Standard table.
3021 (let* ((label (org-element-property :name table))
3022 (caption (org-export-get-caption table))
3023 (attributes
3024 (org-html--make-attribute-string
3025 (org-combine-plists
3026 (and label (list :id (org-export-solidify-link-text label)))
3027 (plist-get info :html-table-attributes)
3028 (org-export-read-attribute :attr_html table))))
3029 (alignspec
3030 (if (and (boundp 'org-html-format-table-no-css)
3031 org-html-format-table-no-css)
3032 "align=\"%s\"" "class=\"%s\""))
3033 (table-column-specs
3034 (function
3035 (lambda (table info)
3036 (mapconcat
3037 (lambda (table-cell)
3038 (let ((alignment (org-export-table-cell-alignment
3039 table-cell info)))
3040 (concat
3041 ;; Begin a colgroup?
3042 (when (org-export-table-cell-starts-colgroup-p
3043 table-cell info)
3044 "\n<colgroup>")
3045 ;; Add a column. Also specify it's alignment.
3046 (format "\n<col %s/>" (format alignspec alignment))
3047 ;; End a colgroup?
3048 (when (org-export-table-cell-ends-colgroup-p
3049 table-cell info)
3050 "\n</colgroup>"))))
3051 (org-html-table-first-row-data-cells table info) "\n")))))
3052 (format "<table%s>\n%s\n%s\n%s</table>"
3053 (if (equal attributes "") "" (concat " " attributes))
3054 (if (not caption) ""
3055 (format "<caption>%s</caption>"
3056 (org-export-data caption info)))
3057 (funcall table-column-specs table info)
3058 contents)))))
3060 ;;;; Target
3062 (defun org-html-target (target contents info)
3063 "Transcode a TARGET object from Org to HTML.
3064 CONTENTS is nil. INFO is a plist holding contextual
3065 information."
3066 (let ((id (org-export-solidify-link-text
3067 (org-element-property :value target))))
3068 (org-html--anchor id)))
3070 ;;;; Timestamp
3072 (defun org-html-timestamp (timestamp contents info)
3073 "Transcode a TIMESTAMP object from Org to HTML.
3074 CONTENTS is nil. INFO is a plist holding contextual
3075 information."
3076 (let ((value (org-html-plain-text
3077 (org-timestamp-translate timestamp) info)))
3078 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3079 (replace-regexp-in-string "--" "&#x2013;" value))))
3081 ;;;; Underline
3083 (defun org-html-underline (underline contents info)
3084 "Transcode UNDERLINE from Org to HTML.
3085 CONTENTS is the text with underline markup. INFO is a plist
3086 holding contextual information."
3087 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3088 contents))
3090 ;;;; Verbatim
3092 (defun org-html-verbatim (verbatim contents info)
3093 "Transcode VERBATIM from Org to HTML.
3094 CONTENTS is nil. INFO is a plist holding contextual
3095 information."
3096 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3097 (org-html-encode-plain-text (org-element-property :value verbatim))))
3099 ;;;; Verse Block
3101 (defun org-html-verse-block (verse-block contents info)
3102 "Transcode a VERSE-BLOCK element from Org to HTML.
3103 CONTENTS is verse block contents. INFO is a plist holding
3104 contextual information."
3105 ;; Replace each newline character with line break. Also replace
3106 ;; each blank line with a line break.
3107 (setq contents (replace-regexp-in-string
3108 "^ *\\\\\\\\$" "<br/>\n"
3109 (replace-regexp-in-string
3110 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3111 ;; Replace each white space at beginning of a line with a
3112 ;; non-breaking space.
3113 (while (string-match "^[ \t]+" contents)
3114 (let* ((num-ws (length (match-string 0 contents)))
3115 (ws (let (out) (dotimes (i num-ws out)
3116 (setq out (concat out "&#xa0;"))))))
3117 (setq contents (replace-match ws nil t contents))))
3118 (format "<p class=\"verse\">\n%s</p>" contents))
3121 ;;; Filter Functions
3123 (defun org-html-final-function (contents backend info)
3124 "Filter to indent the HTML and convert HTML entities."
3125 (with-temp-buffer
3126 (insert contents)
3127 (set-auto-mode t)
3128 (if org-html-indent
3129 (indent-region (point-min) (point-max)))
3130 (when org-html-use-unicode-chars
3131 (require 'mm-url)
3132 (mm-url-decode-entities))
3133 (buffer-substring-no-properties (point-min) (point-max))))
3136 ;;; End-user functions
3138 ;;;###autoload
3139 (defun org-html-export-as-html
3140 (&optional async subtreep visible-only body-only ext-plist)
3141 "Export current buffer to an HTML buffer.
3143 If narrowing is active in the current buffer, only export its
3144 narrowed part.
3146 If a region is active, export that region.
3148 A non-nil optional argument ASYNC means the process should happen
3149 asynchronously. The resulting buffer should be accessible
3150 through the `org-export-stack' interface.
3152 When optional argument SUBTREEP is non-nil, export the sub-tree
3153 at point, extracting information from the headline properties
3154 first.
3156 When optional argument VISIBLE-ONLY is non-nil, don't export
3157 contents of hidden elements.
3159 When optional argument BODY-ONLY is non-nil, only write code
3160 between \"<body>\" and \"</body>\" tags.
3162 EXT-PLIST, when provided, is a property list with external
3163 parameters overriding Org default settings, but still inferior to
3164 file-local settings.
3166 Export is done in a buffer named \"*Org HTML Export*\", which
3167 will be displayed when `org-export-show-temporary-export-buffer'
3168 is non-nil."
3169 (interactive)
3170 (if async
3171 (org-export-async-start
3172 (lambda (output)
3173 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3174 (erase-buffer)
3175 (insert output)
3176 (goto-char (point-min))
3177 (set-auto-mode t)
3178 (org-export-add-to-stack (current-buffer) 'html)))
3179 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3180 (let ((outbuf (org-export-to-buffer
3181 'html "*Org HTML Export*"
3182 subtreep visible-only body-only ext-plist)))
3183 ;; Set major mode.
3184 (with-current-buffer outbuf (set-auto-mode t))
3185 (when org-export-show-temporary-export-buffer
3186 (switch-to-buffer-other-window outbuf)))))
3188 ;;;###autoload
3189 (defun org-html-convert-region-to-html ()
3190 "Assume the current region has org-mode syntax, and convert it to HTML.
3191 This can be used in any buffer. For example, you can write an
3192 itemized list in org-mode syntax in an HTML buffer and use this
3193 command to convert it."
3194 (interactive)
3195 (org-export-replace-region-by 'html))
3197 ;;;###autoload
3198 (defun org-html-export-to-html
3199 (&optional async subtreep visible-only body-only ext-plist)
3200 "Export current buffer to a HTML file.
3202 If narrowing is active in the current buffer, only export its
3203 narrowed part.
3205 If a region is active, export that region.
3207 A non-nil optional argument ASYNC means the process should happen
3208 asynchronously. The resulting file should be accessible through
3209 the `org-export-stack' interface.
3211 When optional argument SUBTREEP is non-nil, export the sub-tree
3212 at point, extracting information from the headline properties
3213 first.
3215 When optional argument VISIBLE-ONLY is non-nil, don't export
3216 contents of hidden elements.
3218 When optional argument BODY-ONLY is non-nil, only write code
3219 between \"<body>\" and \"</body>\" tags.
3221 EXT-PLIST, when provided, is a property list with external
3222 parameters overriding Org default settings, but still inferior to
3223 file-local settings.
3225 Return output file's name."
3226 (interactive)
3227 (let* ((extension (concat "." org-html-extension))
3228 (file (org-export-output-file-name extension subtreep))
3229 (org-export-coding-system org-html-coding-system))
3230 (if async
3231 (org-export-async-start
3232 (lambda (f) (org-export-add-to-stack f 'html))
3233 (let ((org-export-coding-system org-html-coding-system))
3234 `(expand-file-name
3235 (org-export-to-file
3236 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3237 (let ((org-export-coding-system org-html-coding-system))
3238 (org-export-to-file
3239 'html file subtreep visible-only body-only ext-plist)))))
3241 ;;;###autoload
3242 (defun org-html-publish-to-html (plist filename pub-dir)
3243 "Publish an org file to HTML.
3245 FILENAME is the filename of the Org file to be published. PLIST
3246 is the property list for the given project. PUB-DIR is the
3247 publishing directory.
3249 Return output file name."
3250 (org-publish-org-to 'html filename
3251 (concat "." (or (plist-get plist :html-extension)
3252 org-html-extension "html"))
3253 plist pub-dir))
3256 ;;; FIXME
3258 ;;;; org-format-table-html
3259 ;;;; org-format-org-table-html
3260 ;;;; org-format-table-table-html
3261 ;;;; org-table-number-fraction
3262 ;;;; org-table-number-regexp
3263 ;;;; org-html-table-caption-above
3264 ;;;; org-html-inline-image-extensions
3265 ;;;; org-export-preferred-target-alist
3266 ;;;; class for anchors
3267 ;;;; org-export-mark-todo-in-toc
3268 ;;;; org-html-format-org-link
3269 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3270 ;;;; alt = (file-name-nondirectory path)
3272 (provide 'ox-html)
3274 ;; Local variables:
3275 ;; generated-autoload-file: "org-loaddefs.el"
3276 ;; End:
3278 ;;; ox-html.el ends here