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