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