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