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