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