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