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