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