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