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