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