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