ox-html.el (org-html-link): Don't insert nil if there is no attributes
[org-mode/org-tableheadings.git] / lisp / ox-html.el
blobc11954918ed906dc805bc953a53f2b41eac0a69c
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 t
522 "Non-nil means to indent the generated HTML."
523 :group 'org-export-html
524 :version "24.4"
525 :package-version '(Org . "8.0")
526 :type 'boolean)
528 (defcustom org-html-use-unicode-chars nil
529 "Non-nil means to use unicode characters instead of HTML entities."
530 :group 'org-export-html
531 :version "24.4"
532 :package-version '(Org . "8.0")
533 :type 'boolean)
535 ;;;; Drawers
537 (defcustom org-html-format-drawer-function nil
538 "Function called to format a drawer in HTML code.
540 The function must accept two parameters:
541 NAME the drawer name, like \"LOGBOOK\"
542 CONTENTS the contents of the drawer.
544 The function should return the string to be exported.
546 For example, the variable could be set to the following function
547 in order to mimic default behaviour:
549 \(defun org-html-format-drawer-default \(name contents\)
550 \"Format a drawer element for HTML export.\"
551 contents\)"
552 :group 'org-export-html
553 :type 'function)
555 ;;;; Footnotes
557 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
558 <h2 class=\"footnotes\">%s: </h2>
559 <div id=\"text-footnotes\">
561 </div>
562 </div>"
563 "Format for the footnotes section.
564 Should contain a two instances of %s. The first will be replaced with the
565 language-specific word for \"Footnotes\", the second one will be replaced
566 by the footnotes themselves."
567 :group 'org-export-html
568 :type 'string)
570 (defcustom org-html-footnote-format "<sup>%s</sup>"
571 "The format for the footnote reference.
572 %s will be replaced by the footnote reference itself."
573 :group 'org-export-html
574 :type 'string)
576 (defcustom org-html-footnote-separator "<sup>, </sup>"
577 "Text used to separate footnotes."
578 :group 'org-export-html
579 :type 'string)
581 ;;;; Headline
583 (defcustom org-html-toplevel-hlevel 2
584 "The <H> level for level 1 headings in HTML export.
585 This is also important for the classes that will be wrapped around headlines
586 and outline structure. If this variable is 1, the top-level headlines will
587 be <h1>, and the corresponding classes will be outline-1, section-number-1,
588 and outline-text-1. If this is 2, all of these will get a 2 instead.
589 The default for this variable is 2, because we use <h1> for formatting the
590 document title."
591 :group 'org-export-html
592 :type 'integer)
594 (defcustom org-html-format-headline-function nil
595 "Function to format headline text.
597 This function will be called with 5 arguments:
598 TODO the todo keyword (string or nil).
599 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
600 PRIORITY the priority of the headline (integer or nil)
601 TEXT the main headline text (string).
602 TAGS the tags (string or nil).
604 The function result will be used in the section format string."
605 :group 'org-export-html
606 :type 'function)
608 ;;;; HTML-specific
610 (defcustom org-html-allow-name-attribute-in-anchors t
611 "When nil, do not set \"name\" attribute in anchors.
612 By default, anchors are formatted with both \"id\" and \"name\"
613 attributes, when appropriate."
614 :group 'org-export-html
615 :version "24.4"
616 :package-version '(Org . "8.0")
617 :type 'boolean)
619 ;;;; Inlinetasks
621 (defcustom org-html-format-inlinetask-function nil
622 "Function called to format an inlinetask in HTML code.
624 The function must accept six parameters:
625 TODO the todo keyword, as a string
626 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
627 PRIORITY the inlinetask priority, as a string
628 NAME the inlinetask name, as a string.
629 TAGS the inlinetask tags, as a list of strings.
630 CONTENTS the contents of the inlinetask, as a string.
632 The function should return the string to be exported."
633 :group 'org-export-html
634 :type 'function)
636 ;;;; LaTeX
638 (defcustom org-html-with-latex org-export-with-latex
639 "Non-nil means process LaTeX math snippets.
641 When set, the exporter will process LaTeX environments and
642 fragments.
644 This option can also be set with the +OPTIONS line,
645 e.g. \"tex:mathjax\". Allowed values are:
647 nil Ignore math snippets.
648 `verbatim' Keep everything in verbatim
649 `dvipng' Process the LaTeX fragments to images. This will also
650 include processing of non-math environments.
651 `imagemagick' Convert the LaTeX fragments to pdf files and use
652 imagemagick to convert pdf files to png files.
653 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
654 be loaded.
655 t Synonym for `mathjax'."
656 :group 'org-export-html
657 :version "24.4"
658 :package-version '(Org . "8.0")
659 :type '(choice
660 (const :tag "Do not process math in any way" nil)
661 (const :tag "Use dvipng to make images" dvipng)
662 (const :tag "Use imagemagick to make images" imagemagick)
663 (const :tag "Use MathJax to display math" mathjax)
664 (const :tag "Leave math verbatim" verbatim)))
666 ;;;; Links :: Generic
668 (defcustom org-html-link-org-files-as-html t
669 "Non-nil means make file links to `file.org' point to `file.html'.
670 When `org-mode' is exporting an `org-mode' file to HTML, links to
671 non-html files are directly put into a href tag in HTML.
672 However, links to other Org-mode files (recognized by the
673 extension `.org.) should become links to the corresponding html
674 file, assuming that the linked `org-mode' file will also be
675 converted to HTML.
676 When nil, the links still point to the plain `.org' file."
677 :group 'org-export-html
678 :type 'boolean)
680 ;;;; Links :: Inline images
682 (defcustom org-html-inline-images 'maybe
683 "Non-nil means inline images into exported HTML pages.
684 This is done using an <img> tag. When nil, an anchor with href is used to
685 link to the image. If this option is `maybe', then images in links with
686 an empty description will be inlined, while images with a description will
687 be linked only."
688 :group 'org-export-html
689 :type '(choice (const :tag "Never" nil)
690 (const :tag "Always" t)
691 (const :tag "When there is no description" maybe)))
693 (defcustom org-html-inline-image-rules
694 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
695 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
697 "Rules characterizing image files that can be inlined into HTML.
699 A rule consists in an association whose key is the type of link
700 to consider, and value is a regexp that will be matched against
701 link's path.
703 Note that, by default, the image extension *actually* allowed
704 depend on the way the HTML file is processed. When used with
705 pdflatex, pdf, jpg and png images are OK. When processing
706 through dvi to Postscript, only ps and eps are allowed. The
707 default we use here encompasses both."
708 :group 'org-export-html
709 :version "24.4"
710 :package-version '(Org . "8.0")
711 :type '(alist :key-type (string :tag "Type")
712 :value-type (regexp :tag "Path")))
714 ;;;; Plain Text
716 (defcustom org-html-protect-char-alist
717 '(("&" . "&amp;")
718 ("<" . "&lt;")
719 (">" . "&gt;"))
720 "Alist of characters to be converted by `org-html-protect'."
721 :group 'org-export-html
722 :type '(repeat (cons (string :tag "Character")
723 (string :tag "HTML equivalent"))))
725 ;;;; Src Block
727 (defcustom org-html-htmlize-output-type 'inline-css
728 "Output type to be used by htmlize when formatting code snippets.
729 Choices are `css', to export the CSS selectors only, or `inline-css', to
730 export the CSS attribute values inline in the HTML. We use as default
731 `inline-css', in order to make the resulting HTML self-containing.
733 However, this will fail when using Emacs in batch mode for export, because
734 then no rich font definitions are in place. It will also not be good if
735 people with different Emacs setup contribute HTML files to a website,
736 because the fonts will represent the individual setups. In these cases,
737 it is much better to let Org/Htmlize assign classes only, and to use
738 a style file to define the look of these classes.
739 To get a start for your css file, start Emacs session and make sure that
740 all the faces you are interested in are defined, for example by loading files
741 in all modes you want. Then, use the command
742 \\[org-html-htmlize-generate-css] to extract class definitions."
743 :group 'org-export-html
744 :type '(choice (const css) (const inline-css)))
746 (defcustom org-html-htmlize-font-prefix "org-"
747 "The prefix for CSS class names for htmlize font specifications."
748 :group 'org-export-html
749 :type 'string)
751 ;;;; Table
753 (defcustom org-html-table-tag
754 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
755 "The HTML tag that is used to start a table.
756 This must be a <table> tag, but you may change the options like
757 borders and spacing."
758 :group 'org-export-html
759 :type 'string)
761 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
762 "The opening tag for table header fields.
763 This is customizable so that alignment options can be specified.
764 The first %s will be filled with the scope of the field, either row or col.
765 The second %s will be replaced by a style entry to align the field.
766 See also the variable `org-html-table-use-header-tags-for-first-column'.
767 See also the variable `org-html-table-align-individual-fields'."
768 :group 'org-export-html
769 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
771 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
772 "The opening tag for table data fields.
773 This is customizable so that alignment options can be specified.
774 The first %s will be filled with the scope of the field, either row or col.
775 The second %s will be replaced by a style entry to align the field.
776 See also the variable `org-html-table-align-individual-fields'."
777 :group 'org-export-html
778 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
780 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
781 "The opening tag for table data fields.
782 This is customizable so that alignment options can be specified.
783 Instead of strings, these can be Lisp forms that will be evaluated
784 for each row in order to construct the table row tags. During evaluation,
785 the variable `head' will be true when this is a header line, nil when this
786 is a body line. And the variable `nline' will contain the line number,
787 starting from 1 in the first header line. For example
789 (setq org-html-table-row-tags
790 (cons '(if head
791 \"<tr>\"
792 (if (= (mod nline 2) 1)
793 \"<tr class=\\\"tr-odd\\\">\"
794 \"<tr class=\\\"tr-even\\\">\"))
795 \"</tr>\"))
797 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
798 :group 'org-export-html
799 :type '(cons
800 (choice :tag "Opening tag"
801 (string :tag "Specify")
802 (sexp))
803 (choice :tag "Closing tag"
804 (string :tag "Specify")
805 (sexp))))
807 (defcustom org-html-table-align-individual-fields t
808 "Non-nil means attach style attributes for alignment to each table field.
809 When nil, alignment will only be specified in the column tags, but this
810 is ignored by some browsers (like Firefox, Safari). Opera does it right
811 though."
812 :group 'org-export-html
813 :type 'boolean)
815 (defcustom org-html-table-use-header-tags-for-first-column nil
816 "Non-nil means format column one in tables with header tags.
817 When nil, also column one will use data tags."
818 :group 'org-export-html
819 :type 'boolean)
821 (defcustom org-html-table-caption-above t
822 "When non-nil, place caption string at the beginning of the table.
823 Otherwise, place it near the end."
824 :group 'org-export-html
825 :type 'boolean)
827 ;;;; Tags
829 (defcustom org-html-tag-class-prefix ""
830 "Prefix to class names for TODO keywords.
831 Each tag gets a class given by the tag itself, with this prefix.
832 The default prefix is empty because it is nice to just use the keyword
833 as a class name. But if you get into conflicts with other, existing
834 CSS classes, then this prefix can be very useful."
835 :group 'org-export-html
836 :type 'string)
838 ;;;; Template :: Generic
840 (defcustom org-html-extension "html"
841 "The extension for exported HTML files."
842 :group 'org-export-html
843 :type 'string)
845 (defcustom org-html-xml-declaration
846 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
847 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
848 "The extension for exported HTML files.
849 %s will be replaced with the charset of the exported file.
850 This may be a string, or an alist with export extensions
851 and corresponding declarations."
852 :group 'org-export-html
853 :type '(choice
854 (string :tag "Single declaration")
855 (repeat :tag "Dependent on extension"
856 (cons (string :tag "Extension")
857 (string :tag "Declaration")))))
859 (defcustom org-html-coding-system 'utf-8
860 "Coding system for HTML export.
861 Use utf-8 as the default value."
862 :group 'org-export-html
863 :version "24.4"
864 :package-version '(Org . "8.0")
865 :type 'coding-system)
867 (defcustom org-html-doctype
868 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
869 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
870 "Document type definition to use for exported HTML files.
871 Can be set with the in-buffer HTML_DOCTYPE property or for
872 publishing, with :html-doctype."
873 :group 'org-export-html
874 :version "24.4"
875 :package-version '(Org . "8.0")
876 :type 'string)
878 (defcustom org-html-container-element "div"
879 "HTML element to use for wrapping top level sections.
880 Can be set with the in-buffer HTML_CONTAINER property or for
881 publishing, with :html-container.
883 Note that changing the default will prevent you from using
884 org-info.js for your website."
885 :group 'org-export-html
886 :version "24.4"
887 :package-version '(Org . "8.0")
888 :type 'string)
890 (defcustom org-html-divs
891 '((preamble "div" "preamble")
892 (content "div" "content")
893 (postamble "div" "postamble"))
894 "Alist of the threed section elements for HTML export.
895 The car of each entry is one of 'preamble, 'content or 'postamble.
896 The cdrs of each entry are the ELEMENT_TYPE and ID for each
897 section of the exported document.
899 Note that changing the default will prevent you from using
900 org-info.js for your website."
901 :group 'org-export-html
902 :version "24.4"
903 :package-version '(Org . "8.0")
904 :type '(list :greedy t
905 (list :tag "Preamble"
906 (const :format "" preamble)
907 (string :tag "element") (string :tag " id"))
908 (list :tag "Content"
909 (const :format "" content)
910 (string :tag "element") (string :tag " id"))
911 (list :tag "Postamble" (const :format "" postamble)
912 (string :tag " id") (string :tag "element"))))
914 ;;;; Template :: Mathjax
916 (defcustom org-html-mathjax-options
917 '((path "http://orgmode.org/mathjax/MathJax.js")
918 (scale "100")
919 (align "center")
920 (indent "2em")
921 (mathml nil))
922 "Options for MathJax setup.
924 path The path where to find MathJax
925 scale Scaling for the HTML-CSS backend, usually between 100 and 133
926 align How to align display math: left, center, or right
927 indent If align is not center, how far from the left/right side?
928 mathml Should a MathML player be used if available?
929 This is faster and reduces bandwidth use, but currently
930 sometimes has lower spacing quality. Therefore, the default is
931 nil. When browsers get better, this switch can be flipped.
933 You can also customize this for each buffer, using something like
935 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
936 :group 'org-export-html
937 :type '(list :greedy t
938 (list :tag "path (the path from where to load MathJax.js)"
939 (const :format " " path) (string))
940 (list :tag "scale (scaling for the displayed math)"
941 (const :format " " scale) (string))
942 (list :tag "align (alignment of displayed equations)"
943 (const :format " " align) (string))
944 (list :tag "indent (indentation with left or right alignment)"
945 (const :format " " indent) (string))
946 (list :tag "mathml (should MathML display be used is possible)"
947 (const :format " " mathml) (boolean))))
949 (defcustom org-html-mathjax-template
950 "<script type=\"text/javascript\" src=\"%PATH\">
951 <!--/*--><![CDATA[/*><!--*/
952 MathJax.Hub.Config({
953 // Only one of the two following lines, depending on user settings
954 // First allows browser-native MathML display, second forces HTML/CSS
955 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
956 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
957 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
958 \"TeX/noUndefined.js\"],
959 tex2jax: {
960 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
961 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
962 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
963 ignoreClass: \"tex2jax_ignore\",
964 processEscapes: false,
965 processEnvironments: true,
966 preview: \"TeX\"
968 showProcessingMessages: true,
969 displayAlign: \"%ALIGN\",
970 displayIndent: \"%INDENT\",
972 \"HTML-CSS\": {
973 scale: %SCALE,
974 availableFonts: [\"STIX\",\"TeX\"],
975 preferredFont: \"TeX\",
976 webFont: \"TeX\",
977 imageFont: \"TeX\",
978 showMathMenu: true,
980 MMLorHTML: {
981 prefer: {
982 MSIE: \"MML\",
983 Firefox: \"MML\",
984 Opera: \"HTML\",
985 other: \"HTML\"
989 /*]]>*///-->
990 </script>"
991 "The MathJax setup for XHTML files."
992 :group 'org-export-html
993 :type 'string)
995 ;;;; Template :: Postamble
997 (defcustom org-html-postamble 'auto
998 "Non-nil means insert a postamble in HTML export.
1000 When set to 'auto, check against the
1001 `org-export-with-author/email/creator/date' variables to set the
1002 content of the postamble. When set to a string, use this string
1003 as the postamble. When t, insert a string as defined by the
1004 formatting string in `org-html-postamble-format'.
1006 When set to a function, apply this function and insert the
1007 returned string. The function takes the property list of export
1008 options as its only argument.
1010 Setting :html-postamble in publishing projects will take
1011 precedence over this variable."
1012 :group 'org-export-html
1013 :type '(choice (const :tag "No postamble" nil)
1014 (const :tag "Auto postamble" 'auto)
1015 (const :tag "Default formatting string" t)
1016 (string :tag "Custom formatting string")
1017 (function :tag "Function (must return a string)")))
1019 (defcustom org-html-postamble-format
1020 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1021 <p class=\"date\">Date: %d</p>
1022 <p class=\"creator\">Generated by %c</p>
1023 <p class=\"xhtml-validation\">%v</p>"))
1024 "Alist of languages and format strings for the HTML postamble.
1026 The first element of each list is the language code, as used for
1027 the #+LANGUAGE keyword.
1029 The second element of each list is a format string to format the
1030 postamble itself. This format string can contain these elements:
1032 %t stands for the title.
1033 %a stands for the author's name.
1034 %e stands for the author's email.
1035 %d stands for the date.
1036 %c will be replaced by information about Org/Emacs versions.
1037 %v will be replaced by `org-html-validation-link'.
1038 %T will be replace by the creation time of the file.
1040 If you need to use a \"%\" character, you need to escape it
1041 like that: \"%%\"."
1042 :group 'org-export-html
1043 :type '(alist :key-type (string :tag "Language")
1044 :value-type (string :tag "Format string")))
1046 (defcustom org-html-validation-link
1047 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1048 "Link to HTML validation service."
1049 :group 'org-export-html
1050 :type 'string)
1052 (defcustom org-html-creator-string
1053 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
1054 (if (fboundp 'org-version) (org-version) "(Unknown)")
1055 emacs-version)
1056 "String to insert at the end of the HTML document."
1057 :group 'org-export-html
1058 :type '(string :tag "Creator string"))
1060 ;;;; Template :: Preamble
1062 (defcustom org-html-preamble t
1063 "Non-nil means insert a preamble in HTML export.
1065 When t, insert a string as defined by the formatting string in
1066 `org-html-preamble-format'. When set to a string, use this
1067 formatting string instead (see `org-html-postamble-format' for an
1068 example of such a formatting string).
1070 When set to a function, apply this function and insert the
1071 returned string. The function takes the property list of export
1072 options as its only argument.
1074 Setting :html-preamble in publishing projects will take
1075 precedence over this variable."
1076 :group 'org-export-html
1077 :type '(choice (const :tag "No preamble" nil)
1078 (const :tag "Default preamble" t)
1079 (string :tag "Custom formatting string")
1080 (function :tag "Function (must return a string)")))
1082 (defcustom org-html-preamble-format '(("en" ""))
1083 "Alist of languages and format strings for the HTML preamble.
1085 The first element of each list is the language code, as used for
1086 the #+LANGUAGE keyword.
1088 The second element of each list is a format string to format the
1089 preamble itself. This format string can contain these elements:
1091 %t stands for the title.
1092 %a stands for the author's name.
1093 %e stands for the author's email.
1094 %d stands for the date.
1095 %c will be replaced by information about Org/Emacs versions.
1096 %v will be replaced by `org-html-validation-link'.
1097 %T will be replace by the creation time of the file.
1099 If you need to use a \"%\" character, you need to escape it
1100 like that: \"%%\".
1102 See the default value of `org-html-postamble-format' for an
1103 example."
1104 :group 'org-export-html
1105 :type '(alist :key-type (string :tag "Language")
1106 :value-type (string :tag "Format string")))
1108 (defcustom org-html-link-up ""
1109 "Where should the \"UP\" link of exported HTML pages lead?"
1110 :group 'org-export-html
1111 :type '(string :tag "File or URL"))
1113 (defcustom org-html-link-home ""
1114 "Where should the \"HOME\" link of exported HTML pages lead?"
1115 :group 'org-export-html
1116 :type '(string :tag "File or URL"))
1118 (defcustom org-html-home/up-format
1119 "<div id=\"org-div-home-and-up\">
1120 <a accesskey=\"h\" href=\"%s\"> UP </a>
1122 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1123 </div>"
1124 "Snippet used to insert the HOME and UP links.
1125 This is a format string, the first %s will receive the UP link,
1126 the second the HOME link. If both `org-html-link-up' and
1127 `org-html-link-home' are empty, the entire snippet will be
1128 ignored."
1129 :group 'org-export-html
1130 :type 'string)
1132 ;;;; Template :: Scripts
1134 (define-obsolete-variable-alias
1135 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1136 (defcustom org-html-head-include-scripts t
1137 "Non-nil means include the JavaScript snippets in exported HTML files.
1138 The actual script is defined in `org-html-scripts' and should
1139 not be modified."
1140 :group 'org-export-html
1141 :version "24.4"
1142 :package-version '(Org . "8.0")
1143 :type 'boolean)
1145 ;;;; Template :: Styles
1147 (define-obsolete-variable-alias
1148 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1149 (defcustom org-html-head-include-default-style t
1150 "Non-nil means include the default style in exported HTML files.
1151 The actual style is defined in `org-html-style-default' and
1152 should not be modified. Use `org-html-head' to use your own
1153 style information."
1154 :group 'org-export-html
1155 :version "24.4"
1156 :package-version '(Org . "8.0")
1157 :type 'boolean)
1158 ;;;###autoload
1159 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1161 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1162 (defcustom org-html-head ""
1163 "Org-wide head definitions for exported HTML files.
1165 This variable can contain the full HTML structure to provide a
1166 style, including the surrounding HTML tags. You can consider
1167 including definitions for the following classes: title, todo,
1168 done, timestamp, timestamp-kwd, tag, target.
1170 For example, a valid value would be:
1172 <style type=\"text/css\">
1173 <![CDATA[
1174 p { font-weight: normal; color: gray; }
1175 h1 { color: black; }
1176 .title { text-align: center; }
1177 .todo, .timestamp-kwd { color: red; }
1178 .done { color: green; }
1180 </style>
1182 If you want to refer to an external style, use something like
1184 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1186 As the value of this option simply gets inserted into the HTML
1187 <head> header, you can use it to add any arbitrary text to the
1188 header.
1190 You can set this on a per-file basis using #+HTML_HEAD:,
1191 or for publication projects using the :html-head property."
1192 :group 'org-export-html
1193 :version "24.4"
1194 :package-version '(Org . "8.0")
1195 :type 'string)
1196 ;;;###autoload
1197 (put 'org-html-head 'safe-local-variable 'stringp)
1199 (defcustom org-html-head-extra ""
1200 "More head information to add in the HTML output.
1202 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1203 or for publication projects using the :html-head-extra property."
1204 :group 'org-export-html
1205 :version "24.4"
1206 :package-version '(Org . "8.0")
1207 :type 'string)
1208 ;;;###autoload
1209 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1211 ;;;; Todos
1213 (defcustom org-html-todo-kwd-class-prefix ""
1214 "Prefix to class names for TODO keywords.
1215 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1216 The default prefix is empty because it is nice to just use the keyword
1217 as a class name. But if you get into conflicts with other, existing
1218 CSS classes, then this prefix can be very useful."
1219 :group 'org-export-html
1220 :type 'string)
1223 ;;; Internal Functions
1225 (defun org-html-format-inline-image (src &optional
1226 caption label attr standalone-p)
1227 "Format an inline image from SRC.
1228 CAPTION, LABEL and ATTR are optional arguments providing the
1229 caption, the label and the attribute of the image.
1230 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1231 (let* ((id (if (not label) ""
1232 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1233 (attr (concat attr
1234 (cond
1235 ((string-match "\\<alt=" (or attr "")) "")
1236 ((string-match "^ltxpng/" src)
1237 (format " alt=\"%s\""
1238 (org-html-encode-plain-text
1239 (org-find-text-property-in-string
1240 'org-latex-src src))))
1241 (t (format " alt=\"%s\""
1242 (file-name-nondirectory src)))))))
1243 (cond
1244 (standalone-p
1245 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1246 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1247 id (format "\n<p>%s</p>" img)
1248 (if (and caption (not (string= caption "")))
1249 (format "\n<p>%s</p>" caption) ""))))
1250 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1252 (defun org-html--textarea-block (element)
1253 "Transcode ELEMENT into a textarea block.
1254 ELEMENT is either a src block or an example block."
1255 (let* ((code (car (org-export-unravel-code element)))
1256 (attr (org-export-read-attribute :attr_html element)))
1257 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1258 (or (plist-get attr :width) 80)
1259 (or (plist-get attr :height) (org-count-lines code))
1260 code)))
1262 ;;;; Bibliography
1264 (defun org-html-bibliography ()
1265 "Find bibliography, cut it out and return it."
1266 (catch 'exit
1267 (let (beg end (cnt 1) bib)
1268 (save-excursion
1269 (goto-char (point-min))
1270 (when (re-search-forward
1271 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1272 (setq beg (match-beginning 0))
1273 (while (re-search-forward "</?div\\>" nil t)
1274 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1275 (when (= cnt 0)
1276 (and (looking-at ">") (forward-char 1))
1277 (setq bib (buffer-substring beg (point)))
1278 (delete-region beg (point))
1279 (throw 'exit bib))))
1280 nil))))
1282 ;;;; Table
1284 (defun org-html-splice-attributes (tag attributes)
1285 "Return a HTML TAG edited wrt ATTRIBUTES."
1286 (if (not attributes)
1288 (let (oldatt newatt)
1289 (setq oldatt (org-extract-attributes-from-string tag)
1290 tag (pop oldatt)
1291 newatt (cdr (org-extract-attributes-from-string attributes)))
1292 (while newatt
1293 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1294 (if (string-match ">" tag)
1295 (setq tag
1296 (replace-match (concat (org-attributes-to-string oldatt) ">")
1297 t t tag)))
1298 tag)))
1300 (defun org-export-splice-style (style extra)
1301 "Return STYLE updated wrt EXTRA."
1302 (if (and (stringp extra)
1303 (string-match "\\S-" extra)
1304 (string-match "</style>" style))
1305 (concat (substring style 0 (match-beginning 0))
1306 "\n" extra "\n"
1307 (substring style (match-beginning 0)))
1308 style))
1310 (defun org-html-htmlize-region-for-paste (beg end)
1311 "Convert the region between BEG and END to HTML, using htmlize.el.
1312 This is much like `htmlize-region-for-paste', only that it uses
1313 the settings define in the org-... variables."
1314 (let* ((htmlize-output-type org-html-htmlize-output-type)
1315 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1316 (htmlbuf (htmlize-region beg end)))
1317 (unwind-protect
1318 (with-current-buffer htmlbuf
1319 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1320 (plist-get htmlize-buffer-places 'content-end)))
1321 (kill-buffer htmlbuf))))
1323 ;;;###autoload
1324 (defun org-html-htmlize-generate-css ()
1325 "Create the CSS for all font definitions in the current Emacs session.
1326 Use this to create face definitions in your CSS style file that can then
1327 be used by code snippets transformed by htmlize.
1328 This command just produces a buffer that contains class definitions for all
1329 faces used in the current Emacs session. You can copy and paste the ones you
1330 need into your CSS file.
1332 If you then set `org-html-htmlize-output-type' to `css', calls
1333 to the function `org-html-htmlize-region-for-paste' will
1334 produce code that uses these same face definitions."
1335 (interactive)
1336 (require 'htmlize)
1337 (and (get-buffer "*html*") (kill-buffer "*html*"))
1338 (with-temp-buffer
1339 (let ((fl (face-list))
1340 (htmlize-css-name-prefix "org-")
1341 (htmlize-output-type 'css)
1342 f i)
1343 (while (setq f (pop fl)
1344 i (and f (face-attribute f :inherit)))
1345 (when (and (symbolp f) (or (not i) (not (listp i))))
1346 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1347 (htmlize-region (point-min) (point-max))))
1348 (org-pop-to-buffer-same-window "*html*")
1349 (goto-char (point-min))
1350 (if (re-search-forward "<style" nil t)
1351 (delete-region (point-min) (match-beginning 0)))
1352 (if (re-search-forward "</style>" nil t)
1353 (delete-region (1+ (match-end 0)) (point-max)))
1354 (beginning-of-line 1)
1355 (if (looking-at " +") (replace-match ""))
1356 (goto-char (point-min)))
1358 (defun org-html--make-string (n string)
1359 "Build a string by concatenating N times STRING."
1360 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1362 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1363 "Turn todo keyword KWD into a valid class name.
1364 Replaces invalid characters with \"_\"."
1365 (save-match-data
1366 (while (string-match "[^a-zA-Z0-9_]" kwd)
1367 (setq kwd (replace-match "_" t t kwd))))
1368 kwd)
1370 (defun org-html-format-footnote-reference (n def refcnt)
1371 "Format footnote reference N with definition DEF into HTML."
1372 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1373 (format org-html-footnote-format
1374 (let* ((id (format "fnr.%s%s" n extra))
1375 (href (format " href=\"#fn.%s\"" n))
1376 (attributes (concat " class=\"footref\"" href)))
1377 (org-html--anchor id n attributes)))))
1379 (defun org-html-format-footnotes-section (section-name definitions)
1380 "Format footnotes section SECTION-NAME."
1381 (if (not definitions) ""
1382 (format org-html-footnotes-section section-name definitions)))
1384 (defun org-html-format-footnote-definition (fn)
1385 "Format the footnote definition FN."
1386 (let ((n (car fn)) (def (cdr fn)))
1387 (format
1388 "<div class=\"footdef\">%s %s</div>\n"
1389 (format org-html-footnote-format
1390 (let* ((id (format "fn.%s" n))
1391 (href (format " href=\"#fnr.%s\"" n))
1392 (attributes (concat " class=\"footnum\"" href)))
1393 (org-html--anchor id n attributes)))
1394 def)))
1396 (defun org-html-footnote-section (info)
1397 "Format the footnote section.
1398 INFO is a plist used as a communication channel."
1399 (let* ((fn-alist (org-export-collect-footnote-definitions
1400 (plist-get info :parse-tree) info))
1401 (fn-alist
1402 (loop for (n type raw) in fn-alist collect
1403 (cons n (if (eq (org-element-type raw) 'org-data)
1404 (org-trim (org-export-data raw info))
1405 (format "<p>%s</p>"
1406 (org-trim (org-export-data raw info))))))))
1407 (when fn-alist
1408 (org-html-format-footnotes-section
1409 (org-html--translate "Footnotes" info)
1410 (format
1411 "\n%s\n"
1412 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1415 ;;; Template
1417 (defun org-html--build-meta-info (info)
1418 "Return meta tags for exported document.
1419 INFO is a plist used as a communication channel."
1420 (let* ((title (org-export-data (plist-get info :title) info))
1421 (author (and (plist-get info :with-author)
1422 (let ((auth (plist-get info :author)))
1423 (and auth (org-export-data auth info)))))
1424 (description (plist-get info :description))
1425 (keywords (plist-get info :keywords)))
1426 (concat
1427 (format "<title>%s</title>\n" title)
1428 (format
1429 (when :time-stamp-file
1430 (format-time-string
1431 (concat "<!-- " org-html--timestamp-format " -->\n"))))
1432 (format
1433 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1434 (or (and org-html-coding-system
1435 (fboundp 'coding-system-get)
1436 (coding-system-get org-html-coding-system 'mime-charset))
1437 "iso-8859-1"))
1438 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1439 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1440 (and description
1441 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1442 (and keywords
1443 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1445 (defun org-html--build-head (info)
1446 "Return information for the <head>..</head> of the HTML output.
1447 INFO is a plist used as a communication channel."
1448 (org-element-normalize-string
1449 (concat
1450 (when (plist-get info :html-head-include-default-style)
1451 (org-element-normalize-string org-html-style-default))
1452 (org-element-normalize-string (plist-get info :html-head))
1453 (org-element-normalize-string (plist-get info :html-head-extra))
1454 (when (and (plist-get info :html-htmlized-css-url)
1455 (eq org-html-htmlize-output-type 'css))
1456 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1457 (plist-get info :html-htmlized-css-url)))
1458 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1460 (defun org-html--build-mathjax-config (info)
1461 "Insert the user setup into the mathjax template.
1462 INFO is a plist used as a communication channel."
1463 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1464 (org-element-map (plist-get info :parse-tree)
1465 '(latex-fragment latex-environment) 'identity info t))
1466 (let ((template org-html-mathjax-template)
1467 (options org-html-mathjax-options)
1468 (in-buffer (or (plist-get info :html-mathjax) ""))
1469 name val (yes " ") (no "// ") x)
1470 (mapc
1471 (lambda (e)
1472 (setq name (car e) val (nth 1 e))
1473 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1474 (setq val (car (read-from-string
1475 (substring in-buffer (match-end 0))))))
1476 (if (not (stringp val)) (setq val (format "%s" val)))
1477 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1478 (setq template (replace-match val t t template))))
1479 options)
1480 (setq val (nth 1 (assq 'mathml options)))
1481 (if (string-match (concat "\\<mathml:") in-buffer)
1482 (setq val (car (read-from-string
1483 (substring in-buffer (match-end 0))))))
1484 ;; Exchange prefixes depending on mathml setting.
1485 (if (not val) (setq x yes yes no no x))
1486 ;; Replace cookies to turn on or off the config/jax lines.
1487 (if (string-match ":MMLYES:" template)
1488 (setq template (replace-match yes t t template)))
1489 (if (string-match ":MMLNO:" template)
1490 (setq template (replace-match no t t template)))
1491 ;; Return the modified template.
1492 (org-element-normalize-string template))))
1494 (defun org-html-format-spec (info)
1495 "Return format specification for elements that can be
1496 used in the preamble or postamble."
1497 `((?t . ,(org-export-data (plist-get info :title) info))
1498 (?d . ,(org-export-data (plist-get info :date) info))
1499 (?T . ,(format-time-string org-html--timestamp-format))
1500 (?a . ,(org-export-data (plist-get info :author) info))
1501 (?e . ,(mapconcat
1502 (lambda (e)
1503 (format "<a href=\"mailto:%s\">%s</a>" e e))
1504 (split-string (plist-get info :email) ",+ *")
1505 ", "))
1506 (?c . ,(plist-get info :creator))
1507 (?v . ,(or org-html-validation-link ""))))
1509 (defun org-html--build-pre/postamble (type info)
1510 "Return document preamble or postamble as a string, or nil.
1511 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1512 communication channel."
1513 (let ((section (plist-get info (intern (format ":html-%s" type))))
1514 (spec (org-html-format-spec info)))
1515 (when section
1516 (let ((section-contents
1517 (if (functionp section) (funcall section info)
1518 (cond
1519 ((stringp section) (format-spec section spec))
1520 ((eq section 'auto)
1521 (let ((date (cdr (assq ?d spec)))
1522 (author (cdr (assq ?a spec)))
1523 (email (cdr (assq ?e spec)))
1524 (creator (cdr (assq ?c spec)))
1525 (timestamp (cdr (assq ?T spec)))
1526 (validation-link (cdr (assq ?v spec))))
1527 (concat
1528 (when (and (plist-get info :with-date)
1529 (org-string-nw-p date))
1530 (format "<p class=\"date\">%s: %s</p>\n"
1531 (org-html--translate "Date" info)
1532 date))
1533 (when (and (plist-get info :with-author)
1534 (org-string-nw-p author))
1535 (format "<p class=\"author\">%s: %s</p>\n"
1536 (org-html--translate "Author" info)
1537 author))
1538 (when (and (plist-get info :with-email)
1539 (org-string-nw-p email))
1540 (format "<p class=\"email\">%s: %s</p>\n"
1541 (org-html--translate "Email" info)
1542 email))
1543 (when (plist-get info :time-stamp-file)
1544 (format
1545 "<p class=\"date\">%s: %s</p>\n"
1546 (org-html--translate "Created" info)
1547 (format-time-string org-html--timestamp-format)))
1548 (when (plist-get info :with-creator)
1549 (format "<p class=\"creator\">%s</p>\n"
1550 creator))
1551 (format "<p class=\"xhtml-validation\">%s</p>\n"
1552 validation-link))))
1553 (t (format-spec
1554 (or (cadr (assoc
1555 (plist-get info :language)
1556 (eval (intern
1557 (format "org-html-%s-format" type)))))
1558 (cadr
1559 (assoc
1560 "en"
1561 (eval
1562 (intern (format "org-html-%s-format" type))))))
1563 spec))))))
1564 (when (org-string-nw-p section-contents)
1565 (concat
1566 (format "<%s id=\"%s\" class=\"%s\">\n"
1567 (nth 1 (assq type org-html-divs))
1568 (nth 2 (assq type org-html-divs))
1569 org-html--pre/postamble-class)
1570 (org-element-normalize-string section-contents)
1571 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1573 (defun org-html-inner-template (contents info)
1574 "Return body of document string after HTML conversion.
1575 CONTENTS is the transcoded contents string. INFO is a plist
1576 holding export options."
1577 (concat
1578 ;; Table of contents.
1579 (let ((depth (plist-get info :with-toc)))
1580 (when depth (org-html-toc depth info)))
1581 ;; Document contents.
1582 contents
1583 ;; Footnotes section.
1584 (org-html-footnote-section info)
1585 ;; Bibliography.
1586 (org-html-bibliography)))
1588 (defun org-html-template (contents info)
1589 "Return complete document string after HTML conversion.
1590 CONTENTS is the transcoded contents string. INFO is a plist
1591 holding export options."
1592 (concat
1593 (format
1594 (or (and (stringp org-html-xml-declaration)
1595 org-html-xml-declaration)
1596 (cdr (assoc (plist-get info :html-extension)
1597 org-html-xml-declaration))
1598 (cdr (assoc "html" org-html-xml-declaration))
1601 (or (and org-html-coding-system
1602 (fboundp 'coding-system-get)
1603 (coding-system-get org-html-coding-system 'mime-charset))
1604 "iso-8859-1"))
1605 "\n"
1606 (plist-get info :html-doctype)
1607 "\n"
1608 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1609 (plist-get info :language) (plist-get info :language))
1610 "<head>\n"
1611 (org-html--build-meta-info info)
1612 (org-html--build-head info)
1613 (org-html--build-mathjax-config info)
1614 "</head>\n"
1615 "<body>\n"
1616 (let ((link-up (org-trim (plist-get info :html-link-up)))
1617 (link-home (org-trim (plist-get info :html-link-home))))
1618 (unless (and (string= link-up "") (string= link-up ""))
1619 (format org-html-home/up-format
1620 (or link-up link-home)
1621 (or link-home link-up))))
1622 ;; Preamble.
1623 (org-html--build-pre/postamble 'preamble info)
1624 ;; Document contents.
1625 (format "<%s id=\"%s\">\n"
1626 (nth 1 (assq 'content org-html-divs))
1627 (nth 2 (assq 'content org-html-divs)))
1628 ;; Document title.
1629 (let ((title (plist-get info :title)))
1630 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1631 contents
1632 (format "</%s>\n"
1633 (nth 1 (assq 'content org-html-divs)))
1634 ;; Postamble.
1635 (org-html--build-pre/postamble 'postamble info)
1636 ;; Closing document.
1637 "</body>\n</html>"))
1639 (defun org-html--translate (s info)
1640 "Translate string S according to specified language.
1641 INFO is a plist used as a communication channel."
1642 (org-export-translate s :html info))
1644 ;;;; Anchor
1646 (defun org-html--anchor (&optional id desc attributes)
1647 "Format a HTML anchor."
1648 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1649 (attributes (concat (and id (format " id=\"%s\"" id))
1650 (and name (format " name=\"%s\"" name))
1651 attributes)))
1652 (format "<a%s>%s</a>" attributes (or desc ""))))
1654 ;;;; Todo
1656 (defun org-html--todo (todo)
1657 "Format TODO keywords into HTML."
1658 (when todo
1659 (format "<span class=\"%s %s%s\">%s</span>"
1660 (if (member todo org-done-keywords) "done" "todo")
1661 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1662 todo)))
1664 ;;;; Tags
1666 (defun org-html--tags (tags)
1667 "Format TAGS into HTML."
1668 (when tags
1669 (format "<span class=\"tag\">%s</span>"
1670 (mapconcat
1671 (lambda (tag)
1672 (format "<span class=\"%s\">%s</span>"
1673 (concat org-html-tag-class-prefix
1674 (org-html-fix-class-name tag))
1675 tag))
1676 tags "&#xa0;"))))
1678 ;;;; Headline
1680 (defun* org-html-format-headline
1681 (todo todo-type priority text tags
1682 &key level section-number headline-label &allow-other-keys)
1683 "Format a headline in HTML."
1684 (let ((section-number
1685 (when section-number
1686 (format "<span class=\"section-number-%d\">%s</span> "
1687 level section-number)))
1688 (todo (org-html--todo todo))
1689 (tags (org-html--tags tags)))
1690 (concat section-number todo (and todo " ") text
1691 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1693 ;;;; Src Code
1695 (defun org-html-fontify-code (code lang)
1696 "Color CODE with htmlize library.
1697 CODE is a string representing the source code to colorize. LANG
1698 is the language used for CODE, as a string, or nil."
1699 (when code
1700 (cond
1701 ;; Case 1: No lang. Possibly an example block.
1702 ((not lang)
1703 ;; Simple transcoding.
1704 (org-html-encode-plain-text code))
1705 ;; Case 2: No htmlize or an inferior version of htmlize
1706 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1707 ;; Emit a warning.
1708 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1709 ;; Simple transcoding.
1710 (org-html-encode-plain-text code))
1712 ;; Map language
1713 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1714 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1715 (cond
1716 ;; Case 1: Language is not associated with any Emacs mode
1717 ((not (functionp lang-mode))
1718 ;; Simple transcoding.
1719 (org-html-encode-plain-text code))
1720 ;; Case 2: Default. Fontify code.
1722 ;; htmlize
1723 (setq code (with-temp-buffer
1724 ;; Switch to language-specific mode.
1725 (funcall lang-mode)
1726 (insert code)
1727 ;; Fontify buffer.
1728 (font-lock-fontify-buffer)
1729 ;; Remove formatting on newline characters.
1730 (save-excursion
1731 (let ((beg (point-min))
1732 (end (point-max)))
1733 (goto-char beg)
1734 (while (progn (end-of-line) (< (point) end))
1735 (put-text-property (point) (1+ (point)) 'face nil)
1736 (forward-char 1))))
1737 (org-src-mode)
1738 (set-buffer-modified-p nil)
1739 ;; Htmlize region.
1740 (org-html-htmlize-region-for-paste
1741 (point-min) (point-max))))
1742 ;; Strip any enclosing <pre></pre> tags.
1743 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1744 (end (and beg (string-match "</pre>\\'" code))))
1745 (if (and beg end) (substring code beg end) code)))))))))
1747 (defun org-html-do-format-code
1748 (code &optional lang refs retain-labels num-start)
1749 "Format CODE string as source code.
1750 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1751 respectively, the language of the source code, as a string, an
1752 alist between line numbers and references (as returned by
1753 `org-export-unravel-code'), a boolean specifying if labels should
1754 appear in the source code, and the number associated to the first
1755 line of code."
1756 (let* ((code-lines (org-split-string code "\n"))
1757 (code-length (length code-lines))
1758 (num-fmt
1759 (and num-start
1760 (format "%%%ds: "
1761 (length (number-to-string (+ code-length num-start))))))
1762 (code (org-html-fontify-code code lang)))
1763 (org-export-format-code
1764 code
1765 (lambda (loc line-num ref)
1766 (setq loc
1767 (concat
1768 ;; Add line number, if needed.
1769 (when num-start
1770 (format "<span class=\"linenr\">%s</span>"
1771 (format num-fmt line-num)))
1772 ;; Transcoded src line.
1774 ;; Add label, if needed.
1775 (when (and ref retain-labels) (format " (%s)" ref))))
1776 ;; Mark transcoded line as an anchor, if needed.
1777 (if (not ref) loc
1778 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1779 ref loc)))
1780 num-start refs)))
1782 (defun org-html-format-code (element info)
1783 "Format contents of ELEMENT as source code.
1784 ELEMENT is either an example block or a src block. INFO is
1785 a plist used as a communication channel."
1786 (let* ((lang (org-element-property :language element))
1787 ;; Extract code and references.
1788 (code-info (org-export-unravel-code element))
1789 (code (car code-info))
1790 (refs (cdr code-info))
1791 ;; Does the src block contain labels?
1792 (retain-labels (org-element-property :retain-labels element))
1793 ;; Does it have line numbers?
1794 (num-start (case (org-element-property :number-lines element)
1795 (continued (org-export-get-loc element info))
1796 (new 0))))
1797 (org-html-do-format-code code lang refs retain-labels num-start)))
1800 ;;; Tables of Contents
1802 (defun org-html-toc (depth info)
1803 "Build a table of contents.
1804 DEPTH is an integer specifying the depth of the table. INFO is a
1805 plist used as a communication channel. Return the table of
1806 contents as a string, or nil if it is empty."
1807 (let ((toc-entries
1808 (mapcar (lambda (headline)
1809 (cons (org-html--format-toc-headline headline info)
1810 (org-export-get-relative-level headline info)))
1811 (org-export-collect-headlines info depth))))
1812 (when toc-entries
1813 (concat "<div id=\"table-of-contents\">\n"
1814 (format "<h%d>%s</h%d>\n"
1815 org-html-toplevel-hlevel
1816 (org-html--translate "Table of Contents" info)
1817 org-html-toplevel-hlevel)
1818 "<div id=\"text-table-of-contents\">"
1819 (org-html--toc-text toc-entries)
1820 "</div>\n"
1821 "</div>\n"))))
1823 (defun org-html--toc-text (toc-entries)
1824 "Return innards of a table of contents, as a string.
1825 TOC-ENTRIES is an alist where key is an entry title, as a string,
1826 and value is its relative level, as an integer."
1827 (let* ((prev-level (1- (cdar toc-entries)))
1828 (start-level prev-level))
1829 (concat
1830 (mapconcat
1831 (lambda (entry)
1832 (let ((headline (car entry))
1833 (level (cdr entry)))
1834 (concat
1835 (let* ((cnt (- level prev-level))
1836 (times (if (> cnt 0) (1- cnt) (- cnt)))
1837 rtn)
1838 (setq prev-level level)
1839 (concat
1840 (org-html--make-string
1841 times (cond ((> cnt 0) "\n<ul>\n<li>")
1842 ((< cnt 0) "</li>\n</ul>\n")))
1843 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1844 headline)))
1845 toc-entries "")
1846 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1848 (defun org-html--format-toc-headline (headline info)
1849 "Return an appropriate table of contents entry for HEADLINE.
1850 INFO is a plist used as a communication channel."
1851 (let* ((headline-number (org-export-get-headline-number headline info))
1852 (section-number
1853 (and (not (org-export-low-level-p headline info))
1854 (org-export-numbered-headline-p headline info)
1855 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1856 (tags (and (eq (plist-get info :with-tags) t)
1857 (org-export-get-tags headline info))))
1858 (format "<a href=\"#%s\">%s</a>"
1859 ;; Label.
1860 (org-export-solidify-link-text
1861 (or (org-element-property :CUSTOM_ID headline)
1862 (concat "sec-" (mapconcat 'number-to-string
1863 headline-number "-"))))
1864 ;; Body.
1865 (concat section-number
1866 (org-export-data-with-translations
1867 (org-export-get-alt-title headline info)
1868 ;; Ignore any footnote-reference, link,
1869 ;; radio-target and target in table of contents.
1870 (append
1871 '((footnote-reference . ignore)
1872 (link . (lambda (link desc i) desc))
1873 (radio-target . (lambda (radio desc i) desc))
1874 (target . ignore))
1875 (org-export-backend-translate-table 'html))
1876 info)
1877 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1879 (defun org-html-list-of-listings (info)
1880 "Build a list of listings.
1881 INFO is a plist used as a communication channel. Return the list
1882 of listings as a string, or nil if it is empty."
1883 (let ((lol-entries (org-export-collect-listings info)))
1884 (when lol-entries
1885 (concat "<div id=\"list-of-listings\">\n"
1886 (format "<h%d>%s</h%d>\n"
1887 org-html-toplevel-hlevel
1888 (org-html--translate "List of Listings" info)
1889 org-html-toplevel-hlevel)
1890 "<div id=\"text-list-of-listings\">\n<ul>\n"
1891 (let ((count 0)
1892 (initial-fmt (org-html--translate "Listing %d:" info)))
1893 (mapconcat
1894 (lambda (entry)
1895 (let ((label (org-element-property :name entry))
1896 (title (org-trim
1897 (org-export-data
1898 (or (org-export-get-caption entry t)
1899 (org-export-get-caption entry))
1900 info))))
1901 (concat
1902 "<li>"
1903 (if (not label)
1904 (concat (format initial-fmt (incf count)) " " title)
1905 (format "<a href=\"#%s\">%s %s</a>"
1906 (org-export-solidify-link-text label)
1907 (format initial-fmt (incf count))
1908 title))
1909 "</li>")))
1910 lol-entries "\n"))
1911 "\n</ul>\n</div>\n</div>"))))
1913 (defun org-html-list-of-tables (info)
1914 "Build a list of tables.
1915 INFO is a plist used as a communication channel. Return the list
1916 of tables as a string, or nil if it is empty."
1917 (let ((lol-entries (org-export-collect-tables info)))
1918 (when lol-entries
1919 (concat "<div id=\"list-of-tables\">\n"
1920 (format "<h%d>%s</h%d>\n"
1921 org-html-toplevel-hlevel
1922 (org-html--translate "List of Tables" info)
1923 org-html-toplevel-hlevel)
1924 "<div id=\"text-list-of-tables\">\n<ul>\n"
1925 (let ((count 0)
1926 (initial-fmt (org-html--translate "Table %d:" info)))
1927 (mapconcat
1928 (lambda (entry)
1929 (let ((label (org-element-property :name entry))
1930 (title (org-trim
1931 (org-export-data
1932 (or (org-export-get-caption entry t)
1933 (org-export-get-caption entry))
1934 info))))
1935 (concat
1936 "<li>"
1937 (if (not label)
1938 (concat (format initial-fmt (incf count)) " " title)
1939 (format "<a href=\"#%s\">%s %s</a>"
1940 (org-export-solidify-link-text label)
1941 (format initial-fmt (incf count))
1942 title))
1943 "</li>")))
1944 lol-entries "\n"))
1945 "\n</ul>\n</div>\n</div>"))))
1948 ;;; Transcode Functions
1950 ;;;; Bold
1952 (defun org-html-bold (bold contents info)
1953 "Transcode BOLD from Org to HTML.
1954 CONTENTS is the text with bold markup. INFO is a plist holding
1955 contextual information."
1956 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1957 contents))
1959 ;;;; Center Block
1961 (defun org-html-center-block (center-block contents info)
1962 "Transcode a CENTER-BLOCK element from Org to HTML.
1963 CONTENTS holds the contents of the block. INFO is a plist
1964 holding contextual information."
1965 (format "<div class=\"center\">\n%s</div>" contents))
1967 ;;;; Clock
1969 (defun org-html-clock (clock contents info)
1970 "Transcode a CLOCK element from Org to HTML.
1971 CONTENTS is nil. INFO is a plist used as a communication
1972 channel."
1973 (format "<p>
1974 <span class=\"timestamp-wrapper\">
1975 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1976 </span>
1977 </p>"
1978 org-clock-string
1979 (org-translate-time
1980 (org-element-property :raw-value
1981 (org-element-property :value clock)))
1982 (let ((time (org-element-property :duration clock)))
1983 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1985 ;;;; Code
1987 (defun org-html-code (code contents info)
1988 "Transcode CODE from Org to HTML.
1989 CONTENTS is nil. INFO is a plist holding contextual
1990 information."
1991 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1992 (org-html-plain-text (org-element-property :value code) info)))
1994 ;;;; Drawer
1996 (defun org-html-drawer (drawer contents info)
1997 "Transcode a DRAWER element from Org to HTML.
1998 CONTENTS holds the contents of the block. INFO is a plist
1999 holding contextual information."
2000 (if (functionp org-html-format-drawer-function)
2001 (funcall org-html-format-drawer-function
2002 (org-element-property :drawer-name drawer)
2003 contents)
2004 ;; If there's no user defined function: simply
2005 ;; display contents of the drawer.
2006 contents))
2008 ;;;; Dynamic Block
2010 (defun org-html-dynamic-block (dynamic-block contents info)
2011 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2012 CONTENTS holds the contents of the block. INFO is a plist
2013 holding contextual information. See `org-export-data'."
2014 contents)
2016 ;;;; Entity
2018 (defun org-html-entity (entity contents info)
2019 "Transcode an ENTITY object from Org to HTML.
2020 CONTENTS are the definition itself. INFO is a plist holding
2021 contextual information."
2022 (org-element-property :html entity))
2024 ;;;; Example Block
2026 (defun org-html-example-block (example-block contents info)
2027 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2028 CONTENTS is nil. INFO is a plist holding contextual
2029 information."
2030 (if (org-export-read-attribute :attr_html example-block :textarea)
2031 (org-html--textarea-block example-block)
2032 (format "<pre class=\"example\">\n%s</pre>"
2033 (org-html-format-code example-block info))))
2035 ;;;; Export Snippet
2037 (defun org-html-export-snippet (export-snippet contents info)
2038 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2039 CONTENTS is nil. INFO is a plist holding contextual
2040 information."
2041 (when (eq (org-export-snippet-backend export-snippet) 'html)
2042 (org-element-property :value export-snippet)))
2044 ;;;; Export Block
2046 (defun org-html-export-block (export-block contents info)
2047 "Transcode a EXPORT-BLOCK element from Org to HTML.
2048 CONTENTS is nil. INFO is a plist holding contextual information."
2049 (when (string= (org-element-property :type export-block) "HTML")
2050 (org-remove-indentation (org-element-property :value export-block))))
2052 ;;;; Fixed Width
2054 (defun org-html-fixed-width (fixed-width contents info)
2055 "Transcode a FIXED-WIDTH element from Org to HTML.
2056 CONTENTS is nil. INFO is a plist holding contextual information."
2057 (format "<pre class=\"example\">\n%s</pre>"
2058 (org-html-do-format-code
2059 (org-remove-indentation
2060 (org-element-property :value fixed-width)))))
2062 ;;;; Footnote Reference
2064 (defun org-html-footnote-reference (footnote-reference contents info)
2065 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2066 CONTENTS is nil. INFO is a plist holding contextual information."
2067 (concat
2068 ;; Insert separator between two footnotes in a row.
2069 (let ((prev (org-export-get-previous-element footnote-reference info)))
2070 (when (eq (org-element-type prev) 'footnote-reference)
2071 org-html-footnote-separator))
2072 (cond
2073 ((not (org-export-footnote-first-reference-p footnote-reference info))
2074 (org-html-format-footnote-reference
2075 (org-export-get-footnote-number footnote-reference info)
2076 "IGNORED" 100))
2077 ;; Inline definitions are secondary strings.
2078 ((eq (org-element-property :type footnote-reference) 'inline)
2079 (org-html-format-footnote-reference
2080 (org-export-get-footnote-number footnote-reference info)
2081 "IGNORED" 1))
2082 ;; Non-inline footnotes definitions are full Org data.
2083 (t (org-html-format-footnote-reference
2084 (org-export-get-footnote-number footnote-reference info)
2085 "IGNORED" 1)))))
2087 ;;;; Headline
2089 (defun org-html-format-headline--wrap
2090 (headline info &optional format-function &rest extra-keys)
2091 "Transcode a HEADLINE element from Org to HTML.
2092 CONTENTS holds the contents of the headline. INFO is a plist
2093 holding contextual information."
2094 (let* ((level (+ (org-export-get-relative-level headline info)
2095 (1- org-html-toplevel-hlevel)))
2096 (headline-number (org-export-get-headline-number headline info))
2097 (section-number (and (not (org-export-low-level-p headline info))
2098 (org-export-numbered-headline-p headline info)
2099 (mapconcat 'number-to-string
2100 headline-number ".")))
2101 (todo (and (plist-get info :with-todo-keywords)
2102 (let ((todo (org-element-property :todo-keyword headline)))
2103 (and todo (org-export-data todo info)))))
2104 (todo-type (and todo (org-element-property :todo-type headline)))
2105 (priority (and (plist-get info :with-priority)
2106 (org-element-property :priority headline)))
2107 (text (org-export-data (org-element-property :title headline) info))
2108 (tags (and (plist-get info :with-tags)
2109 (org-export-get-tags headline info)))
2110 (headline-label (or (org-element-property :CUSTOM_ID headline)
2111 (concat "sec-" (mapconcat 'number-to-string
2112 headline-number "-"))))
2113 (format-function (cond
2114 ((functionp format-function) format-function)
2115 ((functionp org-html-format-headline-function)
2116 (function*
2117 (lambda (todo todo-type priority text tags
2118 &allow-other-keys)
2119 (funcall org-html-format-headline-function
2120 todo todo-type priority text tags))))
2121 (t 'org-html-format-headline))))
2122 (apply format-function
2123 todo todo-type priority text tags
2124 :headline-label headline-label :level level
2125 :section-number section-number extra-keys)))
2127 (defun org-html-headline (headline contents info)
2128 "Transcode a HEADLINE element from Org to HTML.
2129 CONTENTS holds the contents of the headline. INFO is a plist
2130 holding contextual information."
2131 ;; Empty contents?
2132 (setq contents (or contents ""))
2133 (let* ((numberedp (org-export-numbered-headline-p headline info))
2134 (level (org-export-get-relative-level headline info))
2135 (text (org-export-data (org-element-property :title headline) info))
2136 (todo (and (plist-get info :with-todo-keywords)
2137 (let ((todo (org-element-property :todo-keyword headline)))
2138 (and todo (org-export-data todo info)))))
2139 (todo-type (and todo (org-element-property :todo-type headline)))
2140 (tags (and (plist-get info :with-tags)
2141 (org-export-get-tags headline info)))
2142 (priority (and (plist-get info :with-priority)
2143 (org-element-property :priority headline)))
2144 (section-number (and (org-export-numbered-headline-p headline info)
2145 (mapconcat 'number-to-string
2146 (org-export-get-headline-number
2147 headline info) ".")))
2148 ;; Create the headline text.
2149 (full-text (org-html-format-headline--wrap headline info)))
2150 (cond
2151 ;; Case 1: This is a footnote section: ignore it.
2152 ((org-element-property :footnote-section-p headline) nil)
2153 ;; Case 2. This is a deep sub-tree: export it as a list item.
2154 ;; Also export as items headlines for which no section
2155 ;; format has been found.
2156 ((org-export-low-level-p headline info)
2157 ;; Build the real contents of the sub-tree.
2158 (let* ((type (if numberedp 'ordered 'unordered))
2159 (itemized-body (org-html-format-list-item
2160 contents type nil nil full-text)))
2161 (concat
2162 (and (org-export-first-sibling-p headline info)
2163 (org-html-begin-plain-list type))
2164 itemized-body
2165 (and (org-export-last-sibling-p headline info)
2166 (org-html-end-plain-list type)))))
2167 ;; Case 3. Standard headline. Export it as a section.
2169 (let* ((section-number (mapconcat 'number-to-string
2170 (org-export-get-headline-number
2171 headline info) "-"))
2172 (ids (remove 'nil
2173 (list (org-element-property :CUSTOM_ID headline)
2174 (concat "sec-" section-number)
2175 (org-element-property :ID headline))))
2176 (preferred-id (car ids))
2177 (extra-ids (cdr ids))
2178 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2179 (level1 (+ level (1- org-html-toplevel-hlevel)))
2180 (first-content (car (org-element-contents headline))))
2181 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2182 (if (= 1 (org-export-get-relative-level headline info))
2183 (plist-get info :html-container)
2184 "div")
2185 (format "outline-container-%s"
2186 (or (org-element-property :CUSTOM_ID headline)
2187 section-number))
2188 (concat (format "outline-%d" level1) (and extra-class " ")
2189 extra-class)
2190 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2191 level1
2192 preferred-id
2193 (mapconcat
2194 (lambda (x)
2195 (let ((id (org-export-solidify-link-text
2196 (if (org-uuidgen-p x) (concat "ID-" x)
2197 x))))
2198 (org-html--anchor id)))
2199 extra-ids "")
2200 full-text
2201 level1)
2202 ;; When there is no section, pretend there is an empty
2203 ;; one to get the correct <div class="outline- ...>
2204 ;; which is needed by `org-info.js'.
2205 (if (not (eq (org-element-type first-content) 'section))
2206 (concat (org-html-section first-content "" info)
2207 contents)
2208 contents)
2209 (if (= 1 (org-export-get-relative-level headline info))
2210 (plist-get info :html-container)
2211 "div")))))))
2213 ;;;; Horizontal Rule
2215 (defun org-html-horizontal-rule (horizontal-rule contents info)
2216 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2217 CONTENTS is nil. INFO is a plist holding contextual information."
2218 "<hr/>")
2220 ;;;; Inline Src Block
2222 (defun org-html-inline-src-block (inline-src-block contents info)
2223 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2224 CONTENTS holds the contents of the item. INFO is a plist holding
2225 contextual information."
2226 (let* ((org-lang (org-element-property :language inline-src-block))
2227 (code (org-element-property :value inline-src-block)))
2228 (error "Cannot export inline src block")))
2230 ;;;; Inlinetask
2232 (defun org-html-format-section (text class &optional id)
2233 "Format a section with TEXT into a HTML div with CLASS and ID."
2234 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2235 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2237 (defun org-html-inlinetask (inlinetask contents info)
2238 "Transcode an INLINETASK element from Org to HTML.
2239 CONTENTS holds the contents of the block. INFO is a plist
2240 holding contextual information."
2241 (cond
2242 ;; If `org-html-format-inlinetask-function' is provided, call it
2243 ;; with appropriate arguments.
2244 ((functionp org-html-format-inlinetask-function)
2245 (let ((format-function
2246 (function*
2247 (lambda (todo todo-type priority text tags
2248 &key contents &allow-other-keys)
2249 (funcall org-html-format-inlinetask-function
2250 todo todo-type priority text tags contents)))))
2251 (org-html-format-headline--wrap
2252 inlinetask info format-function :contents contents)))
2253 ;; Otherwise, use a default template.
2254 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2255 (org-html-format-headline--wrap inlinetask info)
2256 contents))))
2258 ;;;; Italic
2260 (defun org-html-italic (italic contents info)
2261 "Transcode ITALIC from Org to HTML.
2262 CONTENTS is the text with italic markup. INFO is a plist holding
2263 contextual information."
2264 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2266 ;;;; Item
2268 (defun org-html-checkbox (checkbox)
2269 "Format CHECKBOX into HTML."
2270 (case checkbox (on "<code>[X]</code>")
2271 (off "<code>[&#xa0;]</code>")
2272 (trans "<code>[-]</code>")
2273 (t "")))
2275 (defun org-html-format-list-item (contents type checkbox
2276 &optional term-counter-id
2277 headline)
2278 "Format a list item into HTML."
2279 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2280 (concat
2281 (case type
2282 (ordered
2283 (let* ((counter term-counter-id)
2284 (extra (if counter (format " value=\"%s\"" counter) "")))
2285 (concat
2286 (format "<li%s>" extra)
2287 (when headline (concat headline "<br/>")))))
2288 (unordered
2289 (let* ((id term-counter-id)
2290 (extra (if id (format " id=\"%s\"" id) "")))
2291 (concat
2292 (format "<li%s>" extra)
2293 (when headline (concat headline "<br/>")))))
2294 (descriptive
2295 (let* ((term term-counter-id))
2296 (setq term (or term "(no term)"))
2297 ;; Check-boxes in descriptive lists are associated to tag.
2298 (concat (format "<dt> %s </dt>"
2299 (concat checkbox term))
2300 "<dd>"))))
2301 (unless (eq type 'descriptive) checkbox)
2302 contents
2303 (case type
2304 (ordered "</li>")
2305 (unordered "</li>")
2306 (descriptive "</dd>")))))
2308 (defun org-html-item (item contents info)
2309 "Transcode an ITEM element from Org to HTML.
2310 CONTENTS holds the contents of the item. INFO is a plist holding
2311 contextual information."
2312 (let* ((plain-list (org-export-get-parent item))
2313 (type (org-element-property :type plain-list))
2314 (counter (org-element-property :counter item))
2315 (checkbox (org-element-property :checkbox item))
2316 (tag (let ((tag (org-element-property :tag item)))
2317 (and tag (org-export-data tag info)))))
2318 (org-html-format-list-item
2319 contents type checkbox (or tag counter))))
2321 ;;;; Keyword
2323 (defun org-html-keyword (keyword contents info)
2324 "Transcode a KEYWORD element from Org to HTML.
2325 CONTENTS is nil. INFO is a plist holding contextual information."
2326 (let ((key (org-element-property :key keyword))
2327 (value (org-element-property :value keyword)))
2328 (cond
2329 ((string= key "HTML") value)
2330 ;; Invisible targets.
2331 ((string= key "TARGET") nil)
2332 ((string= key "TOC")
2333 (let ((value (downcase value)))
2334 (cond
2335 ((string-match "\\<headlines\\>" value)
2336 (let ((depth (or (and (string-match "[0-9]+" value)
2337 (string-to-number (match-string 0 value)))
2338 (plist-get info :with-toc))))
2339 (org-html-toc depth info)))
2340 ((string= "listings" value) (org-html-list-of-listings info))
2341 ((string= "tables" value) (org-html-list-of-tables info))))))))
2343 ;;;; Latex Environment
2345 (defun org-html-format-latex (latex-frag processing-type)
2346 "Format the LaTeX fragment LATEX-FRAG into HTML."
2347 (let ((cache-relpath "") (cache-dir "") bfn)
2348 (unless (eq processing-type 'mathjax)
2349 (setq bfn (buffer-file-name)
2350 cache-relpath
2351 (concat "ltxpng/"
2352 (file-name-sans-extension
2353 (file-name-nondirectory bfn)))
2354 cache-dir (file-name-directory bfn)))
2355 (with-temp-buffer
2356 (insert latex-frag)
2357 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2358 nil nil processing-type)
2359 (buffer-string))))
2361 (defun org-html-latex-environment (latex-environment contents info)
2362 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2363 CONTENTS is nil. INFO is a plist holding contextual information."
2364 (let ((processing-type (plist-get info :with-latex))
2365 (latex-frag (org-remove-indentation
2366 (org-element-property :value latex-environment)))
2367 (caption (org-export-data
2368 (org-export-get-caption latex-environment) info))
2369 (attr nil) ; FIXME
2370 (label (org-element-property :name latex-environment)))
2371 (cond
2372 ((memq processing-type '(t mathjax))
2373 (org-html-format-latex latex-frag 'mathjax))
2374 ((eq processing-type 'dvipng)
2375 (let* ((formula-link (org-html-format-latex
2376 latex-frag processing-type)))
2377 (when (and formula-link
2378 (string-match "file:\\([^]]*\\)" formula-link))
2379 (org-html-format-inline-image
2380 (match-string 1 formula-link) caption label attr t))))
2381 (t latex-frag))))
2383 ;;;; Latex Fragment
2385 (defun org-html-latex-fragment (latex-fragment contents info)
2386 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2387 CONTENTS is nil. INFO is a plist holding contextual information."
2388 (let ((latex-frag (org-element-property :value latex-fragment))
2389 (processing-type (plist-get info :with-latex)))
2390 (case processing-type
2391 ((t mathjax)
2392 (org-html-format-latex latex-frag 'mathjax))
2393 (dvipng
2394 (let* ((formula-link (org-html-format-latex
2395 latex-frag processing-type)))
2396 (when (and formula-link
2397 (string-match "file:\\([^]]*\\)" formula-link))
2398 (org-html-format-inline-image
2399 (match-string 1 formula-link)))))
2400 (t latex-frag))))
2402 ;;;; Line Break
2404 (defun org-html-line-break (line-break contents info)
2405 "Transcode a LINE-BREAK object from Org to HTML.
2406 CONTENTS is nil. INFO is a plist holding contextual information."
2407 "<br/>\n")
2409 ;;;; Link
2411 (defun org-html-link--inline-image (link desc info)
2412 "Return HTML code for an inline image.
2413 LINK is the link pointing to the inline image. INFO is a plist
2414 used as a communication channel.
2416 Inline images can have these attributes:
2418 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2419 (let* ((type (org-element-property :type link))
2420 (raw-path (org-element-property :path link))
2421 (path (cond ((member type '("http" "https"))
2422 (concat type ":" raw-path))
2423 ((file-name-absolute-p raw-path)
2424 (expand-file-name raw-path))
2425 (t raw-path)))
2426 (parent (org-export-get-parent-element link))
2427 (caption (org-export-data (org-export-get-caption parent) info))
2428 (label (org-element-property :name parent))
2429 (attrs (org-export-read-attribute :attr_html parent))
2430 (alt (plist-get attrs :alt))
2431 (width (plist-get attrs :width))
2432 (height (plist-get attrs :height))
2433 (options (plist-get attrs :options)))
2434 ;; Return proper string, depending on DISPOSITION.
2435 (org-html-format-inline-image
2436 path caption label
2437 (mapconcat 'identity
2438 (delq nil (list (if width (format "width=\"%s\"" width))
2439 (if alt (format "alt=\"%s\"" alt))
2440 (if height (format "height=\"%s\"" height))
2441 options)) " ")
2442 (org-html-standalone-image-p link info))))
2444 (defvar org-html-standalone-image-predicate)
2445 (defun org-html-standalone-image-p (element info &optional predicate)
2446 "Test if ELEMENT is a standalone image for the purpose HTML export.
2447 INFO is a plist holding contextual information.
2449 Return non-nil, if ELEMENT is of type paragraph and it's sole
2450 content, save for whitespaces, is a link that qualifies as an
2451 inline image.
2453 Return non-nil, if ELEMENT is of type link and it's containing
2454 paragraph has no other content save for leading and trailing
2455 whitespaces.
2457 Return nil, otherwise.
2459 Bind `org-html-standalone-image-predicate' to constrain
2460 paragraph further. For example, to check for only captioned
2461 standalone images, do the following.
2463 \(setq org-html-standalone-image-predicate
2464 \(lambda \(paragraph\)
2465 \(org-element-property :caption paragraph\)\)\)"
2466 (let ((paragraph (case (org-element-type element)
2467 (paragraph element)
2468 (link (and (org-export-inline-image-p
2469 element org-html-inline-image-rules)
2470 (org-export-get-parent element)))
2471 (t nil))))
2472 (when (eq (org-element-type paragraph) 'paragraph)
2473 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2474 (functionp org-html-standalone-image-predicate)))
2475 (funcall org-html-standalone-image-predicate paragraph))
2476 (let ((contents (org-element-contents paragraph)))
2477 (loop for x in contents
2478 with inline-image-count = 0
2479 always (cond
2480 ((eq (org-element-type x) 'plain-text)
2481 (not (org-string-nw-p x)))
2482 ((eq (org-element-type x) 'link)
2483 (when (org-export-inline-image-p
2484 x org-html-inline-image-rules)
2485 (= (incf inline-image-count) 1)))
2486 (t nil))))))))
2488 (defun org-html-link (link desc info)
2489 "Transcode a LINK object from Org to HTML.
2491 DESC is the description part of the link, or the empty string.
2492 INFO is a plist holding contextual information. See
2493 `org-export-data'."
2494 (let* ((link-org-files-as-html-maybe
2495 (function
2496 (lambda (raw-path info)
2497 "Treat links to `file.org' as links to `file.html', if needed.
2498 See `org-html-link-org-files-as-html'."
2499 (cond
2500 ((and org-html-link-org-files-as-html
2501 (string= ".org"
2502 (downcase (file-name-extension raw-path "."))))
2503 (concat (file-name-sans-extension raw-path) "."
2504 (plist-get info :html-extension)))
2505 (t raw-path)))))
2506 (type (org-element-property :type link))
2507 (raw-path (org-element-property :path link))
2508 ;; Ensure DESC really exists, or set it to nil.
2509 (desc (and (not (string= desc "")) desc))
2510 (path
2511 (cond
2512 ((member type '("http" "https" "ftp" "mailto"))
2513 (concat type ":" raw-path))
2514 ((string= type "file")
2515 ;; Treat links to ".org" files as ".html", if needed.
2516 (setq raw-path
2517 (funcall link-org-files-as-html-maybe raw-path info))
2518 ;; If file path is absolute, prepend it with protocol
2519 ;; component - "file://".
2520 (when (file-name-absolute-p raw-path)
2521 (setq raw-path
2522 (concat "file://" (expand-file-name raw-path))))
2523 ;; Add search option, if any. A search option can be
2524 ;; relative to a custom-id or a headline title. Any other
2525 ;; option is ignored.
2526 (let ((option (org-element-property :search-option link)))
2527 (cond ((not option) raw-path)
2528 ((eq (aref option 0) ?#) (concat raw-path option))
2529 ;; External fuzzy link: try to resolve it if path
2530 ;; belongs to current project, if any.
2531 ((eq (aref option 0) ?*)
2532 (concat
2533 raw-path
2534 (let ((numbers
2535 (org-publish-resolve-external-fuzzy-link
2536 (org-element-property :path link) option)))
2537 (and numbers (concat "#sec-"
2538 (mapconcat 'number-to-string
2539 numbers "-"))))))
2540 (t raw-path))))
2541 (t raw-path)))
2542 attributes protocol)
2543 ;; Extract attributes from parent's paragraph. HACK: Only do this
2544 ;; for the first link in parent. This is needed as long as
2545 ;; attributes cannot be set on a per link basis.
2546 (and (setq attributes
2547 (let ((parent (org-export-get-parent-element link)))
2548 (if (not (eq (org-element-map parent 'link 'identity info t)
2549 link))
2551 (let ((att (org-export-read-attribute :attr_html parent :options)))
2552 (unless (and desc att (string-match (regexp-quote att) desc))
2553 (or att ""))))))
2554 (unless (string= attributes "")
2555 (setq attributes (concat " " attributes))))
2556 (cond
2557 ;; Image file.
2558 ((and (or (eq t org-html-inline-images)
2559 (and org-html-inline-images (not desc)))
2560 (org-export-inline-image-p link org-html-inline-image-rules))
2561 (org-html-link--inline-image link desc info))
2562 ;; Radio target: Transcode target's contents and use them as
2563 ;; link's description.
2564 ((string= type "radio")
2565 (let ((destination (org-export-resolve-radio-link link info)))
2566 (when destination
2567 (format "<a href=\"#%s\"%s>%s</a>"
2568 (org-export-solidify-link-text path)
2569 attributes
2570 (org-export-data (org-element-contents destination) info)))))
2571 ;; Links pointing to a headline: Find destination and build
2572 ;; appropriate referencing command.
2573 ((member type '("custom-id" "fuzzy" "id"))
2574 (let ((destination (if (string= type "fuzzy")
2575 (org-export-resolve-fuzzy-link link info)
2576 (org-export-resolve-id-link link info))))
2577 (case (org-element-type destination)
2578 ;; ID link points to an external file.
2579 (plain-text
2580 (let ((fragment (concat "ID-" path))
2581 ;; Treat links to ".org" files as ".html", if needed.
2582 (path (funcall link-org-files-as-html-maybe
2583 destination info)))
2584 (format "<a href=\"%s#%s\"%s>%s</a>"
2585 path fragment attributes (or desc destination))))
2586 ;; Fuzzy link points nowhere.
2587 ((nil)
2588 (format "<i>%s</i>"
2589 (or desc
2590 (org-export-data
2591 (org-element-property :raw-link link) info))))
2592 ;; Fuzzy link points to an invisible target.
2593 (keyword nil)
2594 ;; Link points to a headline.
2595 (headline
2596 (let ((href
2597 ;; What href to use?
2598 (cond
2599 ;; Case 1: Headline is linked via it's CUSTOM_ID
2600 ;; property. Use CUSTOM_ID.
2601 ((string= type "custom-id")
2602 (org-element-property :CUSTOM_ID destination))
2603 ;; Case 2: Headline is linked via it's ID property
2604 ;; or through other means. Use the default href.
2605 ((member type '("id" "fuzzy"))
2606 (format "sec-%s"
2607 (mapconcat 'number-to-string
2608 (org-export-get-headline-number
2609 destination info) "-")))
2610 (t (error "Shouldn't reach here"))))
2611 ;; What description to use?
2612 (desc
2613 ;; Case 1: Headline is numbered and LINK has no
2614 ;; description or LINK's description matches
2615 ;; headline's title. Display section number.
2616 (if (and (org-export-numbered-headline-p destination info)
2617 (or (not desc)
2618 (string= desc (org-element-property
2619 :raw-value destination))))
2620 (mapconcat 'number-to-string
2621 (org-export-get-headline-number
2622 destination info) ".")
2623 ;; Case 2: Either the headline is un-numbered or
2624 ;; LINK has a custom description. Display LINK's
2625 ;; description or headline's title.
2626 (or desc (org-export-data (org-element-property
2627 :title destination) info)))))
2628 (format "<a href=\"#%s\"%s>%s</a>"
2629 (org-export-solidify-link-text href) attributes desc)))
2630 ;; Fuzzy link points to a target. Do as above.
2632 (let ((path (org-export-solidify-link-text path)) number)
2633 (unless desc
2634 (setq number (cond
2635 ((org-html-standalone-image-p destination info)
2636 (org-export-get-ordinal
2637 (assoc 'link (org-element-contents destination))
2638 info 'link 'org-html-standalone-image-p))
2639 (t (org-export-get-ordinal destination info))))
2640 (setq desc (when number
2641 (if (atom number) (number-to-string number)
2642 (mapconcat 'number-to-string number ".")))))
2643 (format "<a href=\"#%s\"%s>%s</a>"
2644 path attributes (or desc "No description for this link")))))))
2645 ;; Coderef: replace link with the reference name or the
2646 ;; equivalent line number.
2647 ((string= type "coderef")
2648 (let ((fragment (concat "coderef-" path)))
2649 (format "<a href=\"#%s\"%s%s>%s</a>"
2650 fragment
2651 (org-trim
2652 (format (concat "class=\"coderef\""
2653 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2654 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2655 fragment fragment))
2656 attributes
2657 (format (org-export-get-coderef-format path desc)
2658 (org-export-resolve-coderef path info)))))
2659 ;; Link type is handled by a special function.
2660 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2661 (funcall protocol (org-link-unescape path) desc 'html))
2662 ;; External link with a description part.
2663 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2664 ;; External link without a description part.
2665 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2666 ;; No path, only description. Try to do something useful.
2667 (t (format "<i>%s</i>" desc)))))
2669 ;;;; Paragraph
2671 (defun org-html-paragraph (paragraph contents info)
2672 "Transcode a PARAGRAPH element from Org to HTML.
2673 CONTENTS is the contents of the paragraph, as a string. INFO is
2674 the plist used as a communication channel."
2675 (let* ((parent (org-export-get-parent paragraph))
2676 (parent-type (org-element-type parent))
2677 (style '((footnote-definition " class=\"footpara\"")))
2678 (extra (or (cadr (assoc parent-type style)) "")))
2679 (cond
2680 ((and (eq (org-element-type parent) 'item)
2681 (= (org-element-property :begin paragraph)
2682 (org-element-property :contents-begin parent)))
2683 ;; leading paragraph in a list item have no tags
2684 contents)
2685 ((org-html-standalone-image-p paragraph info)
2686 ;; standalone image
2687 contents)
2688 (t (format "<p%s>\n%s</p>" extra contents)))))
2690 ;;;; Plain List
2692 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2693 ;; the correct value for the item counter
2694 (defun org-html-begin-plain-list (type &optional arg1)
2695 "Insert the beginning of the HTML list depending on TYPE.
2696 When ARG1 is a string, use it as the start parameter for ordered
2697 lists."
2698 (case type
2699 (ordered
2700 (format "<ol class=\"org-ol\"%s>"
2701 (if arg1 (format " start=\"%d\"" arg1) "")))
2702 (unordered "<ul class=\"org-ul\">")
2703 (descriptive "<dl class=\"org-dl\">")))
2705 (defun org-html-end-plain-list (type)
2706 "Insert the end of the HTML list depending on TYPE."
2707 (case type
2708 (ordered "</ol>")
2709 (unordered "</ul>")
2710 (descriptive "</dl>")))
2712 (defun org-html-plain-list (plain-list contents info)
2713 "Transcode a PLAIN-LIST element from Org to HTML.
2714 CONTENTS is the contents of the list. INFO is a plist holding
2715 contextual information."
2716 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2717 (type (org-element-property :type plain-list)))
2718 (format "%s\n%s%s"
2719 (org-html-begin-plain-list type)
2720 contents (org-html-end-plain-list type))))
2722 ;;;; Plain Text
2724 (defun org-html-convert-special-strings (string)
2725 "Convert special characters in STRING to HTML."
2726 (let ((all org-html-special-string-regexps)
2727 e a re rpl start)
2728 (while (setq a (pop all))
2729 (setq re (car a) rpl (cdr a) start 0)
2730 (while (string-match re string start)
2731 (setq string (replace-match rpl t nil string))))
2732 string))
2734 (defun org-html-encode-plain-text (text)
2735 "Convert plain text characters from TEXT to HTML equivalent.
2736 Possible conversions are set in `org-html-protect-char-alist'."
2737 (mapc
2738 (lambda (pair)
2739 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2740 org-html-protect-char-alist)
2741 text)
2743 (defun org-html-plain-text (text info)
2744 "Transcode a TEXT string from Org to HTML.
2745 TEXT is the string to transcode. INFO is a plist holding
2746 contextual information."
2747 (let ((output text))
2748 ;; Protect following characters: <, >, &.
2749 (setq output (org-html-encode-plain-text output))
2750 ;; Handle smart quotes. Be sure to provide original string since
2751 ;; OUTPUT may have been modified.
2752 (when (plist-get info :with-smart-quotes)
2753 (setq output (org-export-activate-smart-quotes output :html info text)))
2754 ;; Handle special strings.
2755 (when (plist-get info :with-special-strings)
2756 (setq output (org-html-convert-special-strings output)))
2757 ;; Handle break preservation if required.
2758 (when (plist-get info :preserve-breaks)
2759 (setq output
2760 (replace-regexp-in-string
2761 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2762 ;; Return value.
2763 output))
2766 ;; Planning
2768 (defun org-html-planning (planning contents info)
2769 "Transcode a PLANNING element from Org to HTML.
2770 CONTENTS is nil. INFO is a plist used as a communication
2771 channel."
2772 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2773 (format
2774 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2775 (mapconcat
2776 'identity
2777 (delq nil
2778 (list
2779 (let ((closed (org-element-property :closed planning)))
2780 (when closed
2781 (format span-fmt org-closed-string
2782 (org-translate-time
2783 (org-element-property :raw-value closed)))))
2784 (let ((deadline (org-element-property :deadline planning)))
2785 (when deadline
2786 (format span-fmt org-deadline-string
2787 (org-translate-time
2788 (org-element-property :raw-value deadline)))))
2789 (let ((scheduled (org-element-property :scheduled planning)))
2790 (when scheduled
2791 (format span-fmt org-scheduled-string
2792 (org-translate-time
2793 (org-element-property :raw-value scheduled)))))))
2794 " "))))
2796 ;;;; Property Drawer
2798 (defun org-html-property-drawer (property-drawer contents info)
2799 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2800 CONTENTS is nil. INFO is a plist holding contextual
2801 information."
2802 ;; The property drawer isn't exported but we want separating blank
2803 ;; lines nonetheless.
2806 ;;;; Quote Block
2808 (defun org-html-quote-block (quote-block contents info)
2809 "Transcode a QUOTE-BLOCK element from Org to HTML.
2810 CONTENTS holds the contents of the block. INFO is a plist
2811 holding contextual information."
2812 (format "<blockquote>\n%s</blockquote>" contents))
2814 ;;;; Quote Section
2816 (defun org-html-quote-section (quote-section contents info)
2817 "Transcode a QUOTE-SECTION element from Org to HTML.
2818 CONTENTS is nil. INFO is a plist holding contextual information."
2819 (let ((value (org-remove-indentation
2820 (org-element-property :value quote-section))))
2821 (when value (format "<pre>\n%s</pre>" value))))
2823 ;;;; Section
2825 (defun org-html-section (section contents info)
2826 "Transcode a SECTION element from Org to HTML.
2827 CONTENTS holds the contents of the section. INFO is a plist
2828 holding contextual information."
2829 (let ((parent (org-export-get-parent-headline section)))
2830 ;; Before first headline: no container, just return CONTENTS.
2831 (if (not parent) contents
2832 ;; Get div's class and id references.
2833 (let* ((class-num (+ (org-export-get-relative-level parent info)
2834 (1- org-html-toplevel-hlevel)))
2835 (section-number
2836 (mapconcat
2837 'number-to-string
2838 (org-export-get-headline-number parent info) "-")))
2839 ;; Build return value.
2840 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2841 class-num
2842 (or (org-element-property :CUSTOM_ID parent) section-number)
2843 contents)))))
2845 ;;;; Radio Target
2847 (defun org-html-radio-target (radio-target text info)
2848 "Transcode a RADIO-TARGET object from Org to HTML.
2849 TEXT is the text of the target. INFO is a plist holding
2850 contextual information."
2851 (let ((id (org-export-solidify-link-text
2852 (org-element-property :value radio-target))))
2853 (org-html--anchor id text)))
2855 ;;;; Special Block
2857 (defun org-html-special-block (special-block contents info)
2858 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2859 CONTENTS holds the contents of the block. INFO is a plist
2860 holding contextual information."
2861 (format "<div class=\"%s\">\n%s\n</div>"
2862 (downcase (org-element-property :type special-block))
2863 contents))
2865 ;;;; Src Block
2867 (defun org-html-src-block (src-block contents info)
2868 "Transcode a SRC-BLOCK element from Org to HTML.
2869 CONTENTS holds the contents of the item. INFO is a plist holding
2870 contextual information."
2871 (if (org-export-read-attribute :attr_html src-block :textarea)
2872 (org-html--textarea-block src-block)
2873 (let ((lang (org-element-property :language src-block))
2874 (caption (org-export-get-caption src-block))
2875 (code (org-html-format-code src-block info))
2876 (label (let ((lbl (org-element-property :name src-block)))
2877 (if (not lbl) ""
2878 (format " id=\"%s\""
2879 (org-export-solidify-link-text lbl))))))
2880 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2881 (format
2882 "<div class=\"org-src-container\">\n%s%s\n</div>"
2883 (if (not caption) ""
2884 (format "<label class=\"org-src-name\">%s</label>"
2885 (org-export-data caption info)))
2886 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2888 ;;;; Statistics Cookie
2890 (defun org-html-statistics-cookie (statistics-cookie contents info)
2891 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2892 CONTENTS is nil. INFO is a plist holding contextual information."
2893 (let ((cookie-value (org-element-property :value statistics-cookie)))
2894 (format "<code>%s</code>" cookie-value)))
2896 ;;;; Strike-Through
2898 (defun org-html-strike-through (strike-through contents info)
2899 "Transcode STRIKE-THROUGH from Org to HTML.
2900 CONTENTS is the text with strike-through markup. INFO is a plist
2901 holding contextual information."
2902 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2903 contents))
2905 ;;;; Subscript
2907 (defun org-html-subscript (subscript contents info)
2908 "Transcode a SUBSCRIPT object from Org to HTML.
2909 CONTENTS is the contents of the object. INFO is a plist holding
2910 contextual information."
2911 (format "<sub>%s</sub>" contents))
2913 ;;;; Superscript
2915 (defun org-html-superscript (superscript contents info)
2916 "Transcode a SUPERSCRIPT object from Org to HTML.
2917 CONTENTS is the contents of the object. INFO is a plist holding
2918 contextual information."
2919 (format "<sup>%s</sup>" contents))
2921 ;;;; Tabel Cell
2923 (defun org-html-table-cell (table-cell contents info)
2924 "Transcode a TABLE-CELL element from Org to HTML.
2925 CONTENTS is nil. INFO is a plist used as a communication
2926 channel."
2927 (let* ((table-row (org-export-get-parent table-cell))
2928 (table (org-export-get-parent-table table-cell))
2929 (cell-attrs
2930 (if (not org-html-table-align-individual-fields) ""
2931 (format (if (and (boundp 'org-html-format-table-no-css)
2932 org-html-format-table-no-css)
2933 " align=\"%s\"" " class=\"%s\"")
2934 (org-export-table-cell-alignment table-cell info)))))
2935 (when (or (not contents) (string= "" (org-trim contents)))
2936 (setq contents "&#xa0;"))
2937 (cond
2938 ((and (org-export-table-has-header-p table info)
2939 (= 1 (org-export-table-row-group table-row info)))
2940 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2941 contents (cdr org-html-table-header-tags)))
2942 ((and org-html-table-use-header-tags-for-first-column
2943 (zerop (cdr (org-export-table-cell-address table-cell info))))
2944 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2945 contents (cdr org-html-table-header-tags)))
2946 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2947 contents (cdr org-html-table-data-tags))))))
2949 ;;;; Table Row
2951 (defun org-html-table-row (table-row contents info)
2952 "Transcode a TABLE-ROW element from Org to HTML.
2953 CONTENTS is the contents of the row. INFO is a plist used as a
2954 communication channel."
2955 ;; Rules are ignored since table separators are deduced from
2956 ;; borders of the current row.
2957 (when (eq (org-element-property :type table-row) 'standard)
2958 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2959 (rowgroup-tags
2960 (cond
2961 ;; Case 1: Row belongs to second or subsequent rowgroups.
2962 ((not (= 1 (org-export-table-row-group table-row info)))
2963 '("<tbody>" . "\n</tbody>"))
2964 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2965 ((org-export-table-has-header-p
2966 (org-export-get-parent-table table-row) info)
2967 '("<thead>" . "\n</thead>"))
2968 ;; Case 2: Row is from first and only row group.
2969 (t '("<tbody>" . "\n</tbody>")))))
2970 (concat
2971 ;; Begin a rowgroup?
2972 (when (org-export-table-row-starts-rowgroup-p table-row info)
2973 (car rowgroup-tags))
2974 ;; Actual table row
2975 (concat "\n" (eval (car org-html-table-row-tags))
2976 contents
2977 "\n"
2978 (eval (cdr org-html-table-row-tags)))
2979 ;; End a rowgroup?
2980 (when (org-export-table-row-ends-rowgroup-p table-row info)
2981 (cdr rowgroup-tags))))))
2983 ;;;; Table
2985 (defun org-html-table-first-row-data-cells (table info)
2986 "Transcode the first row of TABLE.
2987 INFO is a plist used as a communication channel."
2988 (let ((table-row
2989 (org-element-map table 'table-row
2990 (lambda (row)
2991 (unless (eq (org-element-property :type row) 'rule) row))
2992 info 'first-match))
2993 (special-column-p (org-export-table-has-special-column-p table)))
2994 (if (not special-column-p) (org-element-contents table-row)
2995 (cdr (org-element-contents table-row)))))
2997 (defun org-html-table--table.el-table (table info)
2998 "Format table.el tables into HTML.
2999 INFO is a plist used as a communication channel."
3000 (when (eq (org-element-property :type table) 'table.el)
3001 (require 'table)
3002 (let ((outbuf (with-current-buffer
3003 (get-buffer-create "*org-export-table*")
3004 (erase-buffer) (current-buffer))))
3005 (with-temp-buffer
3006 (insert (org-element-property :value table))
3007 (goto-char 1)
3008 (re-search-forward "^[ \t]*|[^|]" nil t)
3009 (table-generate-source 'html outbuf))
3010 (with-current-buffer outbuf
3011 (prog1 (org-trim (buffer-string))
3012 (kill-buffer) )))))
3014 (defun org-html-table (table contents info)
3015 "Transcode a TABLE element from Org to HTML.
3016 CONTENTS is the contents of the table. INFO is a plist holding
3017 contextual information."
3018 (case (org-element-property :type table)
3019 ;; Case 1: table.el table. Convert it using appropriate tools.
3020 (table.el (org-html-table--table.el-table table info))
3021 ;; Case 2: Standard table.
3023 (let* ((label (org-element-property :name table))
3024 (caption (org-export-get-caption table))
3025 (attributes
3026 (org-export-read-attribute :attr_html table :options))
3027 (alignspec
3028 (if (and (boundp 'org-html-format-table-no-css)
3029 org-html-format-table-no-css)
3030 "align=\"%s\"" "class=\"%s\""))
3031 (table-column-specs
3032 (function
3033 (lambda (table info)
3034 (mapconcat
3035 (lambda (table-cell)
3036 (let ((alignment (org-export-table-cell-alignment
3037 table-cell info)))
3038 (concat
3039 ;; Begin a colgroup?
3040 (when (org-export-table-cell-starts-colgroup-p
3041 table-cell info)
3042 "\n<colgroup>")
3043 ;; Add a column. Also specify it's alignment.
3044 (format "\n<col %s/>" (format alignspec alignment))
3045 ;; End a colgroup?
3046 (when (org-export-table-cell-ends-colgroup-p
3047 table-cell info)
3048 "\n</colgroup>"))))
3049 (org-html-table-first-row-data-cells table info) "\n"))))
3050 (table-attributes
3051 (let ((table-tag (plist-get info :html-table-tag)))
3052 (concat
3053 (and (string-match "<table\\(.*\\)>" table-tag)
3054 (match-string 1 table-tag))
3055 (and label (format " id=\"%s\""
3056 (org-export-solidify-link-text label)))
3057 (unless (string= attributes "")
3058 (concat " " attributes))))))
3059 ;; Remove last blank line.
3060 (setq contents (substring contents 0 -1))
3061 (format "<table%s>\n%s\n%s\n%s\n</table>"
3062 table-attributes
3063 (if (not caption) ""
3064 (format "<caption>%s</caption>"
3065 (org-export-data caption info)))
3066 (funcall table-column-specs table info)
3067 contents)))))
3069 ;;;; Target
3071 (defun org-html-target (target contents info)
3072 "Transcode a TARGET object from Org to HTML.
3073 CONTENTS is nil. INFO is a plist holding contextual
3074 information."
3075 (let ((id (org-export-solidify-link-text
3076 (org-element-property :value target))))
3077 (org-html--anchor id)))
3079 ;;;; Timestamp
3081 (defun org-html-timestamp (timestamp contents info)
3082 "Transcode a TIMESTAMP object from Org to HTML.
3083 CONTENTS is nil. INFO is a plist holding contextual
3084 information."
3085 (let ((value (org-html-plain-text
3086 (org-timestamp-translate timestamp) info)))
3087 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3088 (replace-regexp-in-string "--" "&#x2013;" value))))
3090 ;;;; Underline
3092 (defun org-html-underline (underline contents info)
3093 "Transcode UNDERLINE from Org to HTML.
3094 CONTENTS is the text with underline markup. INFO is a plist
3095 holding contextual information."
3096 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3097 contents))
3099 ;;;; Verbatim
3101 (defun org-html-verbatim (verbatim contents info)
3102 "Transcode VERBATIM from Org to HTML.
3103 CONTENTS is nil. INFO is a plist holding contextual
3104 information."
3105 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3106 (org-html-plain-text (org-element-property :value verbatim) info)))
3108 ;;;; Verse Block
3110 (defun org-html-verse-block (verse-block contents info)
3111 "Transcode a VERSE-BLOCK element from Org to HTML.
3112 CONTENTS is verse block contents. INFO is a plist holding
3113 contextual information."
3114 ;; Replace each newline character with line break. Also replace
3115 ;; each blank line with a line break.
3116 (setq contents (replace-regexp-in-string
3117 "^ *\\\\\\\\$" "<br/>\n"
3118 (replace-regexp-in-string
3119 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3120 ;; Replace each white space at beginning of a line with a
3121 ;; non-breaking space.
3122 (while (string-match "^[ \t]+" contents)
3123 (let* ((num-ws (length (match-string 0 contents)))
3124 (ws (let (out) (dotimes (i num-ws out)
3125 (setq out (concat out "&#xa0;"))))))
3126 (setq contents (replace-match ws nil t contents))))
3127 (format "<p class=\"verse\">\n%s</p>" contents))
3130 ;;; Filter Functions
3132 (defun org-html-final-function (contents backend info)
3133 "Filter to indent the HTML and convert HTML entities."
3134 (with-temp-buffer
3135 (insert contents)
3136 (set-auto-mode t)
3137 (if org-html-indent
3138 (indent-region (point-min) (point-max)))
3139 (when org-html-use-unicode-chars
3140 (require 'mm-url)
3141 (mm-url-decode-entities))
3142 (buffer-substring-no-properties (point-min) (point-max))))
3145 ;;; End-user functions
3147 ;;;###autoload
3148 (defun org-html-export-as-html
3149 (&optional async subtreep visible-only body-only ext-plist)
3150 "Export current buffer to an HTML buffer.
3152 If narrowing is active in the current buffer, only export its
3153 narrowed part.
3155 If a region is active, export that region.
3157 A non-nil optional argument ASYNC means the process should happen
3158 asynchronously. The resulting buffer should be accessible
3159 through the `org-export-stack' interface.
3161 When optional argument SUBTREEP is non-nil, export the sub-tree
3162 at point, extracting information from the headline properties
3163 first.
3165 When optional argument VISIBLE-ONLY is non-nil, don't export
3166 contents of hidden elements.
3168 When optional argument BODY-ONLY is non-nil, only write code
3169 between \"<body>\" and \"</body>\" tags.
3171 EXT-PLIST, when provided, is a property list with external
3172 parameters overriding Org default settings, but still inferior to
3173 file-local settings.
3175 Export is done in a buffer named \"*Org HTML Export*\", which
3176 will be displayed when `org-export-show-temporary-export-buffer'
3177 is non-nil."
3178 (interactive)
3179 (if async
3180 (org-export-async-start
3181 (lambda (output)
3182 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3183 (erase-buffer)
3184 (insert output)
3185 (goto-char (point-min))
3186 (set-auto-mode t)
3187 (org-export-add-to-stack (current-buffer) 'html)))
3188 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3189 (let ((outbuf (org-export-to-buffer
3190 'html "*Org HTML Export*"
3191 subtreep visible-only body-only ext-plist)))
3192 ;; Set major mode.
3193 (with-current-buffer outbuf (set-auto-mode t))
3194 (when org-export-show-temporary-export-buffer
3195 (switch-to-buffer-other-window outbuf)))))
3197 ;;;###autoload
3198 (defun org-html-export-to-html
3199 (&optional async subtreep visible-only body-only ext-plist)
3200 "Export current buffer to a HTML file.
3202 If narrowing is active in the current buffer, only export its
3203 narrowed part.
3205 If a region is active, export that region.
3207 A non-nil optional argument ASYNC means the process should happen
3208 asynchronously. The resulting file should be accessible through
3209 the `org-export-stack' interface.
3211 When optional argument SUBTREEP is non-nil, export the sub-tree
3212 at point, extracting information from the headline properties
3213 first.
3215 When optional argument VISIBLE-ONLY is non-nil, don't export
3216 contents of hidden elements.
3218 When optional argument BODY-ONLY is non-nil, only write code
3219 between \"<body>\" and \"</body>\" tags.
3221 EXT-PLIST, when provided, is a property list with external
3222 parameters overriding Org default settings, but still inferior to
3223 file-local settings.
3225 Return output file's name."
3226 (interactive)
3227 (let* ((extension (concat "." org-html-extension))
3228 (file (org-export-output-file-name extension subtreep))
3229 (org-export-coding-system org-html-coding-system))
3230 (if async
3231 (org-export-async-start
3232 (lambda (f) (org-export-add-to-stack f 'html))
3233 (let ((org-export-coding-system org-html-coding-system))
3234 `(expand-file-name
3235 (org-export-to-file
3236 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3237 (let ((org-export-coding-system org-html-coding-system))
3238 (org-export-to-file
3239 'html file subtreep visible-only body-only ext-plist)))))
3241 ;;;###autoload
3242 (defun org-html-publish-to-html (plist filename pub-dir)
3243 "Publish an org file to HTML.
3245 FILENAME is the filename of the Org file to be published. PLIST
3246 is the property list for the given project. PUB-DIR is the
3247 publishing directory.
3249 Return output file name."
3250 (org-publish-org-to 'html filename ".html" plist pub-dir))
3253 ;;; FIXME
3255 ;;;; org-format-table-html
3256 ;;;; org-format-org-table-html
3257 ;;;; org-format-table-table-html
3258 ;;;; org-table-number-fraction
3259 ;;;; org-table-number-regexp
3260 ;;;; org-html-table-caption-above
3261 ;;;; org-html-inline-image-extensions
3262 ;;;; org-export-preferred-target-alist
3263 ;;;; class for anchors
3264 ;;;; org-export-with-section-numbers, body-only
3265 ;;;; org-export-mark-todo-in-toc
3266 ;;;; org-html-format-org-link
3267 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3268 ;;;; alt = (file-name-nondirectory path)
3270 (provide 'ox-html)
3272 ;; Local variables:
3273 ;; generated-autoload-file: "org-loaddefs.el"
3274 ;; End:
3276 ;;; ox-html.el ends here