ox: Fix radio target resolution
[org-mode/org-tableheadings.git] / lisp / ox-html.el
blob6fdf795dabb2410c3b6c2208a79756075d7d9843
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements a HTML back-end for Org generic exporter.
26 ;; To test it, run:
28 ;; M-x org-html-export-as-html
30 ;; in an Org mode buffer. See ox.el for more details on how this
31 ;; exporter works.
33 ;;; Code:
35 ;;; Dependencies
37 (require 'ox)
38 (require 'ox-publish)
39 (require 'format-spec)
40 (eval-when-compile (require 'cl) (require 'table))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file "org-id" (id))
46 (declare-function htmlize-region "ext:htmlize" (beg end))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label))
49 (declare-function mm-url-decode-entities "mm-url" ())
51 ;;; Define Back-End
53 (org-export-define-backend 'html
54 '((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (paragraph . org-html-paragraph)
80 (plain-list . org-html-plain-list)
81 (plain-text . org-html-plain-text)
82 (planning . org-html-planning)
83 (property-drawer . org-html-property-drawer)
84 (quote-block . org-html-quote-block)
85 (quote-section . org-html-quote-section)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :export-block "HTML"
104 :filters-alist '((:filter-options . org-html-infojs-install-script)
105 (:filter-final-output . org-html-final-function))
106 :menu-entry
107 '(?h "Export to HTML"
108 ((?H "As HTML buffer" org-html-export-as-html)
109 (?h "As HTML file" org-html-export-to-html)
110 (?o "As HTML file and open"
111 (lambda (a s v b)
112 (if a (org-html-export-to-html t s v b)
113 (org-open-file (org-html-export-to-html nil s v b)))))))
114 :options-alist
115 '((:html-extension nil nil org-html-extension)
116 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
117 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
118 (:html-container "HTML_CONTAINER" nil org-html-container-element)
119 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
120 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
121 (:html-mathjax "HTML_MATHJAX" nil "" space)
122 (:html-postamble nil "html-postamble" org-html-postamble)
123 (:html-preamble nil "html-preamble" org-html-preamble)
124 (:html-head "HTML_HEAD" nil org-html-head newline)
125 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
126 (:html-head-include-default-style "HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline)
127 (:html-head-include-scripts "HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline)
128 (:html-table-attributes nil nil org-html-table-default-attributes)
129 (:html-table-row-tags nil nil org-html-table-row-tags)
130 (:html-xml-declaration nil nil org-html-xml-declaration)
131 (:html-inline-images nil nil org-html-inline-images)
132 (:infojs-opt "INFOJS_OPT" nil nil)
133 ;; Redefine regular options.
134 (:creator "CREATOR" nil org-html-creator-string)
135 (:with-latex nil "tex" org-html-with-latex)))
138 ;;; Internal Variables
140 (defvar org-html-format-table-no-css)
141 (defvar htmlize-buffer-places) ; from htmlize.el
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.
699 A rule consists in an association whose key is the type of link
700 to consider, and value is a regexp that will be matched against
701 link's path."
702 :group 'org-export-html
703 :version "24.4"
704 :package-version '(Org . "8.0")
705 :type '(alist :key-type (string :tag "Type")
706 :value-type (regexp :tag "Path")))
708 ;;;; Plain Text
710 (defcustom org-html-protect-char-alist
711 '(("&" . "&amp;")
712 ("<" . "&lt;")
713 (">" . "&gt;"))
714 "Alist of characters to be converted by `org-html-protect'."
715 :group 'org-export-html
716 :type '(repeat (cons (string :tag "Character")
717 (string :tag "HTML equivalent"))))
719 ;;;; Src Block
721 (defcustom org-html-htmlize-output-type 'inline-css
722 "Output type to be used by htmlize when formatting code snippets.
723 Choices are `css', to export the CSS selectors only, or `inline-css', to
724 export the CSS attribute values inline in the HTML. We use as default
725 `inline-css', in order to make the resulting HTML self-containing.
727 However, this will fail when using Emacs in batch mode for export, because
728 then no rich font definitions are in place. It will also not be good if
729 people with different Emacs setup contribute HTML files to a website,
730 because the fonts will represent the individual setups. In these cases,
731 it is much better to let Org/Htmlize assign classes only, and to use
732 a style file to define the look of these classes.
733 To get a start for your css file, start Emacs session and make sure that
734 all the faces you are interested in are defined, for example by loading files
735 in all modes you want. Then, use the command
736 \\[org-html-htmlize-generate-css] to extract class definitions."
737 :group 'org-export-html
738 :type '(choice (const css) (const inline-css)))
740 (defcustom org-html-htmlize-font-prefix "org-"
741 "The prefix for CSS class names for htmlize font specifications."
742 :group 'org-export-html
743 :type 'string)
745 ;;;; Table
747 (defcustom org-html-table-default-attributes
748 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
749 "Default attributes and values which will be used in table tags.
750 This is a plist where attributes are symbols, starting with
751 colons, and values are strings."
752 :group 'org-export-html
753 :version "24.4"
754 :package-version '(Org . "8.0")
755 :type '(plist :key-type (symbol :tag "Property")
756 :value-type (string :tag "Value")))
758 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
759 "The opening tag for table header fields.
760 This is customizable so that alignment options can be specified.
761 The first %s will be filled with the scope of the field, either row or col.
762 The second %s will be replaced by a style entry to align the field.
763 See also the variable `org-html-table-use-header-tags-for-first-column'.
764 See also the variable `org-html-table-align-individual-fields'."
765 :group 'org-export-html
766 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
768 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
769 "The opening tag for table data fields.
770 This is customizable so that alignment options can be specified.
771 The first %s will be filled with the scope of the field, either row or col.
772 The second %s will be replaced by a style entry to align the field.
773 See also the variable `org-html-table-align-individual-fields'."
774 :group 'org-export-html
775 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
777 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
778 "The opening and ending tags for table rows.
779 This is customizable so that alignment options can be specified.
780 Instead of strings, these can be Lisp forms that will be
781 evaluated for each row in order to construct the table row tags.
783 During evaluation, these variables will be dynamically bound so that
784 you can reuse them:
786 `row-number': row number (0 is the first row)
787 `rowgroup-number': group number of current row
788 `start-rowgroup-p': non-nil means the row starts a group
789 `end-rowgroup-p': non-nil means the row ends a group
790 `top-row-p': non-nil means this is the top row
791 `bottom-row-p': non-nil means this is the bottom row
793 For example:
795 \(setq org-html-table-row-tags
796 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
797 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
798 (t (if (= (mod row-number 2) 1)
799 \"<tr class=\\\"tr-odd\\\">\"
800 \"<tr class=\\\"tr-even\\\">\")))
801 \"</tr>\"))
803 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
804 and the bottom row, and otherwise alternate between \"tr-odd\" and
805 \"tr-even\" for odd and even rows."
806 :group 'org-export-html
807 :type '(cons
808 (choice :tag "Opening tag"
809 (string :tag "Specify")
810 (sexp))
811 (choice :tag "Closing tag"
812 (string :tag "Specify")
813 (sexp))))
815 (defcustom org-html-table-align-individual-fields t
816 "Non-nil means attach style attributes for alignment to each table field.
817 When nil, alignment will only be specified in the column tags, but this
818 is ignored by some browsers (like Firefox, Safari). Opera does it right
819 though."
820 :group 'org-export-html
821 :type 'boolean)
823 (defcustom org-html-table-use-header-tags-for-first-column nil
824 "Non-nil means format column one in tables with header tags.
825 When nil, also column one will use data tags."
826 :group 'org-export-html
827 :type 'boolean)
829 (defcustom org-html-table-caption-above t
830 "When non-nil, place caption string at the beginning of the table.
831 Otherwise, place it near the end."
832 :group 'org-export-html
833 :type 'boolean)
835 ;;;; Tags
837 (defcustom org-html-tag-class-prefix ""
838 "Prefix to class names for TODO keywords.
839 Each tag gets a class given by the tag itself, with this prefix.
840 The default prefix is empty because it is nice to just use the keyword
841 as a class name. But if you get into conflicts with other, existing
842 CSS classes, then this prefix can be very useful."
843 :group 'org-export-html
844 :type 'string)
846 ;;;; Template :: Generic
848 (defcustom org-html-extension "html"
849 "The extension for exported HTML files."
850 :group 'org-export-html
851 :type 'string)
853 (defcustom org-html-xml-declaration
854 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
855 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
856 "The extension for exported HTML files.
857 %s will be replaced with the charset of the exported file.
858 This may be a string, or an alist with export extensions
859 and corresponding declarations."
860 :group 'org-export-html
861 :type '(choice
862 (string :tag "Single declaration")
863 (repeat :tag "Dependent on extension"
864 (cons (string :tag "Extension")
865 (string :tag "Declaration")))))
867 (defcustom org-html-coding-system 'utf-8
868 "Coding system for HTML export.
869 Use utf-8 as the default value."
870 :group 'org-export-html
871 :version "24.4"
872 :package-version '(Org . "8.0")
873 :type 'coding-system)
875 (defcustom org-html-doctype
876 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
877 "Document type definition to use for exported HTML files.
878 Can be set with the in-buffer HTML_DOCTYPE property or for
879 publishing, with :html-doctype."
880 :group 'org-export-html
881 :version "24.4"
882 :package-version '(Org . "8.0")
883 :type 'string)
885 (defcustom org-html-container-element "div"
886 "HTML element to use for wrapping top level sections.
887 Can be set with the in-buffer HTML_CONTAINER property or for
888 publishing, with :html-container.
890 Note that changing the default will prevent you from using
891 org-info.js for your website."
892 :group 'org-export-html
893 :version "24.4"
894 :package-version '(Org . "8.0")
895 :type 'string)
897 (defcustom org-html-divs
898 '((preamble "div" "preamble")
899 (content "div" "content")
900 (postamble "div" "postamble"))
901 "Alist of the three section elements for HTML export.
902 The car of each entry is one of 'preamble, 'content or 'postamble.
903 The cdrs of each entry are the ELEMENT_TYPE and ID for each
904 section of the exported document.
906 Note that changing the default will prevent you from using
907 org-info.js for your website."
908 :group 'org-export-html
909 :version "24.4"
910 :package-version '(Org . "8.0")
911 :type '(list :greedy t
912 (list :tag "Preamble"
913 (const :format "" preamble)
914 (string :tag "element") (string :tag " id"))
915 (list :tag "Content"
916 (const :format "" content)
917 (string :tag "element") (string :tag " id"))
918 (list :tag "Postamble" (const :format "" postamble)
919 (string :tag " id") (string :tag "element"))))
921 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
922 "Format used for timestamps in preamble, postamble and metadata.
923 See `format-time-string' for more information on its components."
924 :group 'org-export-html
925 :version "24.4"
926 :package-version '(Org . "8.0")
927 :type 'string)
929 ;;;; Template :: Mathjax
931 (defcustom org-html-mathjax-options
932 '((path "http://orgmode.org/mathjax/MathJax.js")
933 (scale "100")
934 (align "center")
935 (indent "2em")
936 (mathml nil))
937 "Options for MathJax setup.
939 path The path where to find MathJax
940 scale Scaling for the HTML-CSS backend, usually between 100 and 133
941 align How to align display math: left, center, or right
942 indent If align is not center, how far from the left/right side?
943 mathml Should a MathML player be used if available?
944 This is faster and reduces bandwidth use, but currently
945 sometimes has lower spacing quality. Therefore, the default is
946 nil. When browsers get better, this switch can be flipped.
948 You can also customize this for each buffer, using something like
950 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
951 :group 'org-export-html
952 :type '(list :greedy t
953 (list :tag "path (the path from where to load MathJax.js)"
954 (const :format " " path) (string))
955 (list :tag "scale (scaling for the displayed math)"
956 (const :format " " scale) (string))
957 (list :tag "align (alignment of displayed equations)"
958 (const :format " " align) (string))
959 (list :tag "indent (indentation with left or right alignment)"
960 (const :format " " indent) (string))
961 (list :tag "mathml (should MathML display be used is possible)"
962 (const :format " " mathml) (boolean))))
964 (defcustom org-html-mathjax-template
965 "<script type=\"text/javascript\" src=\"%PATH\">
966 <!--/*--><![CDATA[/*><!--*/
967 MathJax.Hub.Config({
968 // Only one of the two following lines, depending on user settings
969 // First allows browser-native MathML display, second forces HTML/CSS
970 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
971 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
972 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
973 \"TeX/noUndefined.js\"],
974 tex2jax: {
975 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
976 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
977 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
978 ignoreClass: \"tex2jax_ignore\",
979 processEscapes: false,
980 processEnvironments: true,
981 preview: \"TeX\"
983 showProcessingMessages: true,
984 displayAlign: \"%ALIGN\",
985 displayIndent: \"%INDENT\",
987 \"HTML-CSS\": {
988 scale: %SCALE,
989 availableFonts: [\"STIX\",\"TeX\"],
990 preferredFont: \"TeX\",
991 webFont: \"TeX\",
992 imageFont: \"TeX\",
993 showMathMenu: true,
995 MMLorHTML: {
996 prefer: {
997 MSIE: \"MML\",
998 Firefox: \"MML\",
999 Opera: \"HTML\",
1000 other: \"HTML\"
1004 /*]]>*///-->
1005 </script>"
1006 "The MathJax setup for XHTML files."
1007 :group 'org-export-html
1008 :type 'string)
1010 ;;;; Template :: Postamble
1012 (defcustom org-html-postamble 'auto
1013 "Non-nil means insert a postamble in HTML export.
1015 When set to 'auto, check against the
1016 `org-export-with-author/email/creator/date' variables to set the
1017 content of the postamble. When set to a string, use this string
1018 as the postamble. When t, insert a string as defined by the
1019 formatting string in `org-html-postamble-format'.
1021 When set to a function, apply this function and insert the
1022 returned string. The function takes the property list of export
1023 options as its only argument.
1025 Setting :html-postamble in publishing projects will take
1026 precedence over this variable."
1027 :group 'org-export-html
1028 :type '(choice (const :tag "No postamble" nil)
1029 (const :tag "Auto postamble" 'auto)
1030 (const :tag "Default formatting string" t)
1031 (string :tag "Custom formatting string")
1032 (function :tag "Function (must return a string)")))
1034 (defcustom org-html-postamble-format
1035 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1036 <p class=\"date\">Date: %d</p>
1037 <p class=\"creator\">%c</p>
1038 <p class=\"xhtml-validation\">%v</p>"))
1039 "Alist of languages and format strings for the HTML postamble.
1041 The first element of each list is the language code, as used for
1042 the LANGUAGE keyword. See `org-export-default-language'.
1044 The second element of each list is a format string to format the
1045 postamble itself. This format string can contain these elements:
1047 %t stands for the title.
1048 %a stands for the author's name.
1049 %e stands for the author's email.
1050 %d stands for the date.
1051 %c will be replaced by `org-html-creator-string'.
1052 %v will be replaced by `org-html-validation-link'.
1053 %T will be replaced by the export time.
1054 %C will be replaced by the last modification time.
1056 If you need to use a \"%\" character, you need to escape it
1057 like that: \"%%\"."
1058 :group 'org-export-html
1059 :type '(alist :key-type (string :tag "Language")
1060 :value-type (string :tag "Format string")))
1062 (defcustom org-html-validation-link
1063 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1064 "Link to HTML validation service."
1065 :group 'org-export-html
1066 :type 'string)
1068 (defcustom org-html-creator-string
1069 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1070 emacs-version
1071 (if (fboundp 'org-version) (org-version) "unknown version"))
1072 "Information about the creator of the HTML document.
1073 This option can also be set on with the CREATOR keyword."
1074 :group 'org-export-html
1075 :type '(string :tag "Creator string"))
1077 ;;;; Template :: Preamble
1079 (defcustom org-html-preamble t
1080 "Non-nil means insert a preamble in HTML export.
1082 When t, insert a string as defined by the formatting string in
1083 `org-html-preamble-format'. When set to a string, use this
1084 formatting string instead (see `org-html-postamble-format' for an
1085 example of such a formatting string).
1087 When set to a function, apply this function and insert the
1088 returned string. The function takes the property list of export
1089 options as its only argument.
1091 Setting :html-preamble in publishing projects will take
1092 precedence over this variable."
1093 :group 'org-export-html
1094 :type '(choice (const :tag "No preamble" nil)
1095 (const :tag "Default preamble" t)
1096 (string :tag "Custom formatting string")
1097 (function :tag "Function (must return a string)")))
1099 (defcustom org-html-preamble-format '(("en" ""))
1100 "Alist of languages and format strings for the HTML preamble.
1102 The first element of each list is the language code, as used for
1103 the LANGUAGE keyword. See `org-export-default-language'.
1105 The second element of each list is a format string to format the
1106 preamble itself. This format string can contain these elements:
1108 %t stands for the title.
1109 %a stands for the author's name.
1110 %e stands for the author's email.
1111 %d stands for the date.
1112 %c will be replaced by `org-html-creator-string'.
1113 %v will be replaced by `org-html-validation-link'.
1114 %T will be replaced by the export time.
1115 %C will be replaced by the last modification time.
1117 If you need to use a \"%\" character, you need to escape it
1118 like that: \"%%\".
1120 See the default value of `org-html-postamble-format' for an
1121 example."
1122 :group 'org-export-html
1123 :type '(alist :key-type (string :tag "Language")
1124 :value-type (string :tag "Format string")))
1126 (defcustom org-html-link-up ""
1127 "Where should the \"UP\" link of exported HTML pages lead?"
1128 :group 'org-export-html
1129 :type '(string :tag "File or URL"))
1131 (defcustom org-html-link-home ""
1132 "Where should the \"HOME\" link of exported HTML pages lead?"
1133 :group 'org-export-html
1134 :type '(string :tag "File or URL"))
1136 (defcustom org-html-home/up-format
1137 "<div id=\"org-div-home-and-up\">
1138 <a accesskey=\"h\" href=\"%s\"> UP </a>
1140 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1141 </div>"
1142 "Snippet used to insert the HOME and UP links.
1143 This is a format string, the first %s will receive the UP link,
1144 the second the HOME link. If both `org-html-link-up' and
1145 `org-html-link-home' are empty, the entire snippet will be
1146 ignored."
1147 :group 'org-export-html
1148 :type 'string)
1150 ;;;; Template :: Scripts
1152 (define-obsolete-variable-alias
1153 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1154 (defcustom org-html-head-include-scripts t
1155 "Non-nil means include the JavaScript snippets in exported HTML files.
1156 The actual script is defined in `org-html-scripts' and should
1157 not be modified."
1158 :group 'org-export-html
1159 :version "24.4"
1160 :package-version '(Org . "8.0")
1161 :type 'boolean)
1163 ;;;; Template :: Styles
1165 (define-obsolete-variable-alias
1166 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1167 (defcustom org-html-head-include-default-style t
1168 "Non-nil means include the default style in exported HTML files.
1169 The actual style is defined in `org-html-style-default' and
1170 should not be modified. Use `org-html-head' to use your own
1171 style information."
1172 :group 'org-export-html
1173 :version "24.4"
1174 :package-version '(Org . "8.0")
1175 :type 'boolean)
1176 ;;;###autoload
1177 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1179 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1180 (defcustom org-html-head ""
1181 "Org-wide head definitions for exported HTML files.
1183 This variable can contain the full HTML structure to provide a
1184 style, including the surrounding HTML tags. You can consider
1185 including definitions for the following classes: title, todo,
1186 done, timestamp, timestamp-kwd, tag, target.
1188 For example, a valid value would be:
1190 <style type=\"text/css\">
1191 <![CDATA[
1192 p { font-weight: normal; color: gray; }
1193 h1 { color: black; }
1194 .title { text-align: center; }
1195 .todo, .timestamp-kwd { color: red; }
1196 .done { color: green; }
1198 </style>
1200 If you want to refer to an external style, use something like
1202 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1204 As the value of this option simply gets inserted into the HTML
1205 <head> header, you can use it to add any arbitrary text to the
1206 header.
1208 You can set this on a per-file basis using #+HTML_HEAD:,
1209 or for publication projects using the :html-head property."
1210 :group 'org-export-html
1211 :version "24.4"
1212 :package-version '(Org . "8.0")
1213 :type 'string)
1214 ;;;###autoload
1215 (put 'org-html-head 'safe-local-variable 'stringp)
1217 (defcustom org-html-head-extra ""
1218 "More head information to add in the HTML output.
1220 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1221 or for publication projects using the :html-head-extra property."
1222 :group 'org-export-html
1223 :version "24.4"
1224 :package-version '(Org . "8.0")
1225 :type 'string)
1226 ;;;###autoload
1227 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1229 ;;;; Todos
1231 (defcustom org-html-todo-kwd-class-prefix ""
1232 "Prefix to class names for TODO keywords.
1233 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1234 The default prefix is empty because it is nice to just use the keyword
1235 as a class name. But if you get into conflicts with other, existing
1236 CSS classes, then this prefix can be very useful."
1237 :group 'org-export-html
1238 :type 'string)
1241 ;;; Internal Functions
1243 (defun org-html--make-attribute-string (attributes)
1244 "Return a list of attributes, as a string.
1245 ATTRIBUTES is a plist where values are either strings or nil. An
1246 attributes with a nil value will be omitted from the result."
1247 (let (output)
1248 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1249 (cond ((null item) (pop output))
1250 ((symbolp item) (push (substring (symbol-name item) 1) output))
1251 (t (let ((key (car output))
1252 (value (replace-regexp-in-string
1253 "\"" "&quot;" (org-html-encode-plain-text item))))
1254 (setcar output (format "%s=\"%s\"" key value))))))))
1256 (defun org-html-format-inline-image (src &optional
1257 caption label attr standalone-p)
1258 "Format an inline image from SRC.
1259 CAPTION, LABEL and ATTR are optional arguments providing the
1260 caption, the label and the attribute of the image.
1261 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1262 (let* ((id (if (not label) ""
1263 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1264 (attr (concat attr
1265 (cond
1266 ((string-match "\\<alt=" (or attr "")) "")
1267 ((string-match "^ltxpng/" src)
1268 (format " alt=\"%s\""
1269 (org-html-encode-plain-text
1270 (org-find-text-property-in-string
1271 'org-latex-src src))))
1272 (t (format " alt=\"%s\""
1273 (file-name-nondirectory src)))))))
1274 (cond
1275 (standalone-p
1276 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1277 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1278 id (format "\n<p>%s</p>" img)
1279 (if (and caption (not (string= caption "")))
1280 (format "\n<p>%s</p>" caption) ""))))
1281 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1283 (defun org-html--textarea-block (element)
1284 "Transcode ELEMENT into a textarea block.
1285 ELEMENT is either a src block or an example block."
1286 (let* ((code (car (org-export-unravel-code element)))
1287 (attr (org-export-read-attribute :attr_html element)))
1288 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1289 (or (plist-get attr :width) 80)
1290 (or (plist-get attr :height) (org-count-lines code))
1291 code)))
1293 ;;;; Table
1295 (defun org-html-htmlize-region-for-paste (beg end)
1296 "Convert the region between BEG and END to HTML, using htmlize.el.
1297 This is much like `htmlize-region-for-paste', only that it uses
1298 the settings define in the org-... variables."
1299 (let* ((htmlize-output-type org-html-htmlize-output-type)
1300 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1301 (htmlbuf (htmlize-region beg end)))
1302 (unwind-protect
1303 (with-current-buffer htmlbuf
1304 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1305 (plist-get htmlize-buffer-places 'content-end)))
1306 (kill-buffer htmlbuf))))
1308 ;;;###autoload
1309 (defun org-html-htmlize-generate-css ()
1310 "Create the CSS for all font definitions in the current Emacs session.
1311 Use this to create face definitions in your CSS style file that can then
1312 be used by code snippets transformed by htmlize.
1313 This command just produces a buffer that contains class definitions for all
1314 faces used in the current Emacs session. You can copy and paste the ones you
1315 need into your CSS file.
1317 If you then set `org-html-htmlize-output-type' to `css', calls
1318 to the function `org-html-htmlize-region-for-paste' will
1319 produce code that uses these same face definitions."
1320 (interactive)
1321 (require 'htmlize)
1322 (and (get-buffer "*html*") (kill-buffer "*html*"))
1323 (with-temp-buffer
1324 (let ((fl (face-list))
1325 (htmlize-css-name-prefix "org-")
1326 (htmlize-output-type 'css)
1327 f i)
1328 (while (setq f (pop fl)
1329 i (and f (face-attribute f :inherit)))
1330 (when (and (symbolp f) (or (not i) (not (listp i))))
1331 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1332 (htmlize-region (point-min) (point-max))))
1333 (org-pop-to-buffer-same-window "*html*")
1334 (goto-char (point-min))
1335 (if (re-search-forward "<style" nil t)
1336 (delete-region (point-min) (match-beginning 0)))
1337 (if (re-search-forward "</style>" nil t)
1338 (delete-region (1+ (match-end 0)) (point-max)))
1339 (beginning-of-line 1)
1340 (if (looking-at " +") (replace-match ""))
1341 (goto-char (point-min)))
1343 (defun org-html--make-string (n string)
1344 "Build a string by concatenating N times STRING."
1345 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1347 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1348 "Turn todo keyword KWD into a valid class name.
1349 Replaces invalid characters with \"_\"."
1350 (save-match-data
1351 (while (string-match "[^a-zA-Z0-9_]" kwd)
1352 (setq kwd (replace-match "_" t t kwd))))
1353 kwd)
1355 (defun org-html-format-footnote-reference (n def refcnt)
1356 "Format footnote reference N with definition DEF into HTML."
1357 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1358 (format org-html-footnote-format
1359 (let* ((id (format "fnr.%s%s" n extra))
1360 (href (format " href=\"#fn.%s\"" n))
1361 (attributes (concat " class=\"footref\"" href)))
1362 (org-html--anchor id n attributes)))))
1364 (defun org-html-format-footnotes-section (section-name definitions)
1365 "Format footnotes section SECTION-NAME."
1366 (if (not definitions) ""
1367 (format org-html-footnotes-section section-name definitions)))
1369 (defun org-html-format-footnote-definition (fn)
1370 "Format the footnote definition FN."
1371 (let ((n (car fn)) (def (cdr fn)))
1372 (format
1373 "<div class=\"footdef\">%s %s</div>\n"
1374 (format org-html-footnote-format
1375 (let* ((id (format "fn.%s" n))
1376 (href (format " href=\"#fnr.%s\"" n))
1377 (attributes (concat " class=\"footnum\"" href)))
1378 (org-html--anchor id n attributes)))
1379 def)))
1381 (defun org-html-footnote-section (info)
1382 "Format the footnote section.
1383 INFO is a plist used as a communication channel."
1384 (let* ((fn-alist (org-export-collect-footnote-definitions
1385 (plist-get info :parse-tree) info))
1386 (fn-alist
1387 (loop for (n type raw) in fn-alist collect
1388 (cons n (if (eq (org-element-type raw) 'org-data)
1389 (org-trim (org-export-data raw info))
1390 (format "<p>%s</p>"
1391 (org-trim (org-export-data raw info))))))))
1392 (when fn-alist
1393 (org-html-format-footnotes-section
1394 (org-html--translate "Footnotes" info)
1395 (format
1396 "\n%s\n"
1397 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1400 ;;; Template
1402 (defun org-html--build-meta-info (info)
1403 "Return meta tags for exported document.
1404 INFO is a plist used as a communication channel."
1405 (let ((protect-string
1406 (lambda (str)
1407 (replace-regexp-in-string
1408 "\"" "&quot;" (org-html-encode-plain-text str))))
1409 (title (org-export-data (plist-get info :title) info))
1410 (author (and (plist-get info :with-author)
1411 (let ((auth (plist-get info :author)))
1412 (and auth
1413 ;; Return raw Org syntax, skipping non
1414 ;; exportable objects.
1415 (org-element-interpret-data
1416 (org-element-map auth
1417 (cons 'plain-text org-element-all-objects)
1418 'identity info))))))
1419 (description (plist-get info :description))
1420 (keywords (plist-get info :keywords)))
1421 (concat
1422 (format "<title>%s</title>\n" title)
1423 (format
1424 (when :time-stamp-file
1425 (format-time-string
1426 (concat "<!-- " org-html-metadata-timestamp-format " -->\n"))))
1427 (format
1428 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1429 (or (and org-html-coding-system
1430 (fboundp 'coding-system-get)
1431 (coding-system-get org-html-coding-system 'mime-charset))
1432 "iso-8859-1"))
1433 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1434 (and (org-string-nw-p author)
1435 (format "<meta name=\"author\" content=\"%s\"/>\n"
1436 (funcall protect-string author)))
1437 (and (org-string-nw-p description)
1438 (format "<meta name=\"description\" content=\"%s\"/>\n"
1439 (funcall protect-string description)))
1440 (and (org-string-nw-p keywords)
1441 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1442 (funcall protect-string keywords))))))
1444 (defun org-html--build-head (info)
1445 "Return information for the <head>..</head> of the HTML output.
1446 INFO is a plist used as a communication channel."
1447 (org-element-normalize-string
1448 (concat
1449 (when (plist-get info :html-head-include-default-style)
1450 (org-element-normalize-string org-html-style-default))
1451 (org-element-normalize-string (plist-get info :html-head))
1452 (org-element-normalize-string (plist-get info :html-head-extra))
1453 (when (and (plist-get info :html-htmlized-css-url)
1454 (eq org-html-htmlize-output-type 'css))
1455 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1456 (plist-get info :html-htmlized-css-url)))
1457 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1459 (defun org-html--build-mathjax-config (info)
1460 "Insert the user setup into the mathjax template.
1461 INFO is a plist used as a communication channel."
1462 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1463 (org-element-map (plist-get info :parse-tree)
1464 '(latex-fragment latex-environment) 'identity info t))
1465 (let ((template org-html-mathjax-template)
1466 (options org-html-mathjax-options)
1467 (in-buffer (or (plist-get info :html-mathjax) ""))
1468 name val (yes " ") (no "// ") x)
1469 (mapc
1470 (lambda (e)
1471 (setq name (car e) val (nth 1 e))
1472 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1473 (setq val (car (read-from-string
1474 (substring in-buffer (match-end 0))))))
1475 (if (not (stringp val)) (setq val (format "%s" val)))
1476 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1477 (setq template (replace-match val t t template))))
1478 options)
1479 (setq val (nth 1 (assq 'mathml options)))
1480 (if (string-match (concat "\\<mathml:") in-buffer)
1481 (setq val (car (read-from-string
1482 (substring in-buffer (match-end 0))))))
1483 ;; Exchange prefixes depending on mathml setting.
1484 (if (not val) (setq x yes yes no no x))
1485 ;; Replace cookies to turn on or off the config/jax lines.
1486 (if (string-match ":MMLYES:" template)
1487 (setq template (replace-match yes t t template)))
1488 (if (string-match ":MMLNO:" template)
1489 (setq template (replace-match no t t template)))
1490 ;; Return the modified template.
1491 (org-element-normalize-string template))))
1493 (defun org-html-format-spec (info)
1494 "Return format specification for elements that can be
1495 used in the preamble or postamble."
1496 `((?t . ,(org-export-data (plist-get info :title) info))
1497 (?d . ,(org-export-data (org-export-get-date info) info))
1498 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1499 (?a . ,(org-export-data (plist-get info :author) info))
1500 (?e . ,(mapconcat
1501 (lambda (e)
1502 (format "<a href=\"mailto:%s\">%s</a>" e e))
1503 (split-string (plist-get info :email) ",+ *")
1504 ", "))
1505 (?c . ,(plist-get info :creator))
1506 (?C . ,(let ((file (plist-get info :input-file)))
1507 (format-time-string org-html-metadata-timestamp-format
1508 (if file (nth 5 (file-attributes file))
1509 (current-time)))))
1510 (?v . ,(or org-html-validation-link ""))))
1512 (defun org-html--build-pre/postamble (type info)
1513 "Return document preamble or postamble as a string, or nil.
1514 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1515 communication channel."
1516 (let ((section (plist-get info (intern (format ":html-%s" type))))
1517 (spec (org-html-format-spec info)))
1518 (when section
1519 (let ((section-contents
1520 (if (functionp section) (funcall section info)
1521 (cond
1522 ((stringp section) (format-spec section spec))
1523 ((eq section 'auto)
1524 (let ((date (cdr (assq ?d spec)))
1525 (author (cdr (assq ?a spec)))
1526 (email (cdr (assq ?e spec)))
1527 (creator (cdr (assq ?c spec)))
1528 (timestamp (cdr (assq ?T spec)))
1529 (validation-link (cdr (assq ?v spec))))
1530 (concat
1531 (when (and (plist-get info :with-date)
1532 (org-string-nw-p date))
1533 (format "<p class=\"date\">%s: %s</p>\n"
1534 (org-html--translate "Date" info)
1535 date))
1536 (when (and (plist-get info :with-author)
1537 (org-string-nw-p author))
1538 (format "<p class=\"author\">%s: %s</p>\n"
1539 (org-html--translate "Author" info)
1540 author))
1541 (when (and (plist-get info :with-email)
1542 (org-string-nw-p email))
1543 (format "<p class=\"email\">%s: %s</p>\n"
1544 (org-html--translate "Email" info)
1545 email))
1546 (when (plist-get info :time-stamp-file)
1547 (format
1548 "<p class=\"date\">%s: %s</p>\n"
1549 (org-html--translate "Created" info)
1550 (format-time-string org-html-metadata-timestamp-format)))
1551 (when (plist-get info :with-creator)
1552 (format "<p class=\"creator\">%s</p>\n" creator))
1553 (format "<p class=\"xhtml-validation\">%s</p>\n"
1554 validation-link))))
1555 (t (format-spec
1556 (or (cadr (assoc
1557 (plist-get info :language)
1558 (eval (intern
1559 (format "org-html-%s-format" type)))))
1560 (cadr
1561 (assoc
1562 "en"
1563 (eval
1564 (intern (format "org-html-%s-format" type))))))
1565 spec))))))
1566 (when (org-string-nw-p section-contents)
1567 (concat
1568 (format "<%s id=\"%s\" class=\"%s\">\n"
1569 (nth 1 (assq type org-html-divs))
1570 (nth 2 (assq type org-html-divs))
1571 org-html--pre/postamble-class)
1572 (org-element-normalize-string section-contents)
1573 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1575 (defun org-html-inner-template (contents info)
1576 "Return body of document string after HTML conversion.
1577 CONTENTS is the transcoded contents string. INFO is a plist
1578 holding export options."
1579 (concat
1580 ;; Table of contents.
1581 (let ((depth (plist-get info :with-toc)))
1582 (when depth (org-html-toc depth info)))
1583 ;; Document contents.
1584 contents
1585 ;; Footnotes section.
1586 (org-html-footnote-section info)))
1588 (defun org-html-template (contents info)
1589 "Return complete document string after HTML conversion.
1590 CONTENTS is the transcoded contents string. INFO is a plist
1591 holding export options."
1592 (concat
1593 (format
1594 (or (and (stringp org-html-xml-declaration)
1595 org-html-xml-declaration)
1596 (cdr (assoc (plist-get info :html-extension)
1597 org-html-xml-declaration))
1598 (cdr (assoc "html" org-html-xml-declaration))
1601 (or (and org-html-coding-system
1602 (fboundp 'coding-system-get)
1603 (coding-system-get org-html-coding-system 'mime-charset))
1604 "iso-8859-1"))
1605 "\n"
1606 (plist-get info :html-doctype)
1607 "\n"
1608 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1609 (plist-get info :language) (plist-get info :language))
1610 "<head>\n"
1611 (org-html--build-meta-info info)
1612 (org-html--build-head info)
1613 (org-html--build-mathjax-config info)
1614 "</head>\n"
1615 "<body>\n"
1616 (let ((link-up (org-trim (plist-get info :html-link-up)))
1617 (link-home (org-trim (plist-get info :html-link-home))))
1618 (unless (and (string= link-up "") (string= link-up ""))
1619 (format org-html-home/up-format
1620 (or link-up link-home)
1621 (or link-home link-up))))
1622 ;; Preamble.
1623 (org-html--build-pre/postamble 'preamble info)
1624 ;; Document contents.
1625 (format "<%s id=\"%s\">\n"
1626 (nth 1 (assq 'content org-html-divs))
1627 (nth 2 (assq 'content org-html-divs)))
1628 ;; Document title.
1629 (let ((title (plist-get info :title)))
1630 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1631 contents
1632 (format "</%s>\n"
1633 (nth 1 (assq 'content org-html-divs)))
1634 ;; Postamble.
1635 (org-html--build-pre/postamble 'postamble info)
1636 ;; Closing document.
1637 "</body>\n</html>"))
1639 (defun org-html--translate (s info)
1640 "Translate string S according to specified language.
1641 INFO is a plist used as a communication channel."
1642 (org-export-translate s :html info))
1644 ;;;; Anchor
1646 (defun org-html--anchor (&optional id desc attributes)
1647 "Format a HTML anchor."
1648 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1649 (attributes (concat (and id (format " id=\"%s\"" id))
1650 (and name (format " name=\"%s\"" name))
1651 attributes)))
1652 (format "<a%s>%s</a>" attributes (or desc ""))))
1654 ;;;; Todo
1656 (defun org-html--todo (todo)
1657 "Format TODO keywords into HTML."
1658 (when todo
1659 (format "<span class=\"%s %s%s\">%s</span>"
1660 (if (member todo org-done-keywords) "done" "todo")
1661 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1662 todo)))
1664 ;;;; Tags
1666 (defun org-html--tags (tags)
1667 "Format TAGS into HTML."
1668 (when tags
1669 (format "<span class=\"tag\">%s</span>"
1670 (mapconcat
1671 (lambda (tag)
1672 (format "<span class=\"%s\">%s</span>"
1673 (concat org-html-tag-class-prefix
1674 (org-html-fix-class-name tag))
1675 tag))
1676 tags "&#xa0;"))))
1678 ;;;; Headline
1680 (defun* org-html-format-headline
1681 (todo todo-type priority text tags
1682 &key level section-number headline-label &allow-other-keys)
1683 "Format a headline in HTML."
1684 (let ((section-number
1685 (when section-number
1686 (format "<span class=\"section-number-%d\">%s</span> "
1687 level section-number)))
1688 (todo (org-html--todo todo))
1689 (tags (org-html--tags tags)))
1690 (concat section-number todo (and todo " ") text
1691 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1693 ;;;; Src Code
1695 (defun org-html-fontify-code (code lang)
1696 "Color CODE with htmlize library.
1697 CODE is a string representing the source code to colorize. LANG
1698 is the language used for CODE, as a string, or nil."
1699 (when code
1700 (cond
1701 ;; Case 1: No lang. Possibly an example block.
1702 ((not lang)
1703 ;; Simple transcoding.
1704 (org-html-encode-plain-text code))
1705 ;; Case 2: No htmlize or an inferior version of htmlize
1706 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1707 ;; Emit a warning.
1708 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1709 ;; Simple transcoding.
1710 (org-html-encode-plain-text code))
1712 ;; Map language
1713 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1714 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1715 (cond
1716 ;; Case 1: Language is not associated with any Emacs mode
1717 ((not (functionp lang-mode))
1718 ;; Simple transcoding.
1719 (org-html-encode-plain-text code))
1720 ;; Case 2: Default. Fontify code.
1722 ;; htmlize
1723 (setq code (with-temp-buffer
1724 ;; Switch to language-specific mode.
1725 (funcall lang-mode)
1726 (insert code)
1727 ;; Fontify buffer.
1728 (font-lock-fontify-buffer)
1729 ;; Remove formatting on newline characters.
1730 (save-excursion
1731 (let ((beg (point-min))
1732 (end (point-max)))
1733 (goto-char beg)
1734 (while (progn (end-of-line) (< (point) end))
1735 (put-text-property (point) (1+ (point)) 'face nil)
1736 (forward-char 1))))
1737 (org-src-mode)
1738 (set-buffer-modified-p nil)
1739 ;; Htmlize region.
1740 (org-html-htmlize-region-for-paste
1741 (point-min) (point-max))))
1742 ;; Strip any enclosing <pre></pre> tags.
1743 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1744 (end (and beg (string-match "</pre>\\'" code))))
1745 (if (and beg end) (substring code beg end) code)))))))))
1747 (defun org-html-do-format-code
1748 (code &optional lang refs retain-labels num-start)
1749 "Format CODE string as source code.
1750 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1751 respectively, the language of the source code, as a string, an
1752 alist between line numbers and references (as returned by
1753 `org-export-unravel-code'), a boolean specifying if labels should
1754 appear in the source code, and the number associated to the first
1755 line of code."
1756 (let* ((code-lines (org-split-string code "\n"))
1757 (code-length (length code-lines))
1758 (num-fmt
1759 (and num-start
1760 (format "%%%ds: "
1761 (length (number-to-string (+ code-length num-start))))))
1762 (code (org-html-fontify-code code lang)))
1763 (org-export-format-code
1764 code
1765 (lambda (loc line-num ref)
1766 (setq loc
1767 (concat
1768 ;; Add line number, if needed.
1769 (when num-start
1770 (format "<span class=\"linenr\">%s</span>"
1771 (format num-fmt line-num)))
1772 ;; Transcoded src line.
1774 ;; Add label, if needed.
1775 (when (and ref retain-labels) (format " (%s)" ref))))
1776 ;; Mark transcoded line as an anchor, if needed.
1777 (if (not ref) loc
1778 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1779 ref loc)))
1780 num-start refs)))
1782 (defun org-html-format-code (element info)
1783 "Format contents of ELEMENT as source code.
1784 ELEMENT is either an example block or a src block. INFO is
1785 a plist used as a communication channel."
1786 (let* ((lang (org-element-property :language element))
1787 ;; Extract code and references.
1788 (code-info (org-export-unravel-code element))
1789 (code (car code-info))
1790 (refs (cdr code-info))
1791 ;; Does the src block contain labels?
1792 (retain-labels (org-element-property :retain-labels element))
1793 ;; Does it have line numbers?
1794 (num-start (case (org-element-property :number-lines element)
1795 (continued (org-export-get-loc element info))
1796 (new 0))))
1797 (org-html-do-format-code code lang refs retain-labels num-start)))
1800 ;;; Tables of Contents
1802 (defun org-html-toc (depth info)
1803 "Build a table of contents.
1804 DEPTH is an integer specifying the depth of the table. INFO is a
1805 plist used as a communication channel. Return the table of
1806 contents as a string, or nil if it is empty."
1807 (let ((toc-entries
1808 (mapcar (lambda (headline)
1809 (cons (org-html--format-toc-headline headline info)
1810 (org-export-get-relative-level headline info)))
1811 (org-export-collect-headlines info depth))))
1812 (when toc-entries
1813 (concat "<div id=\"table-of-contents\">\n"
1814 (format "<h%d>%s</h%d>\n"
1815 org-html-toplevel-hlevel
1816 (org-html--translate "Table of Contents" info)
1817 org-html-toplevel-hlevel)
1818 "<div id=\"text-table-of-contents\">"
1819 (org-html--toc-text toc-entries)
1820 "</div>\n"
1821 "</div>\n"))))
1823 (defun org-html--toc-text (toc-entries)
1824 "Return innards of a table of contents, as a string.
1825 TOC-ENTRIES is an alist where key is an entry title, as a string,
1826 and value is its relative level, as an integer."
1827 (let* ((prev-level (1- (cdar toc-entries)))
1828 (start-level prev-level))
1829 (concat
1830 (mapconcat
1831 (lambda (entry)
1832 (let ((headline (car entry))
1833 (level (cdr entry)))
1834 (concat
1835 (let* ((cnt (- level prev-level))
1836 (times (if (> cnt 0) (1- cnt) (- cnt)))
1837 rtn)
1838 (setq prev-level level)
1839 (concat
1840 (org-html--make-string
1841 times (cond ((> cnt 0) "\n<ul>\n<li>")
1842 ((< cnt 0) "</li>\n</ul>\n")))
1843 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1844 headline)))
1845 toc-entries "")
1846 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1848 (defun org-html--format-toc-headline (headline info)
1849 "Return an appropriate table of contents entry for HEADLINE.
1850 INFO is a plist used as a communication channel."
1851 (let* ((headline-number (org-export-get-headline-number headline info))
1852 (section-number
1853 (and (not (org-export-low-level-p headline info))
1854 (org-export-numbered-headline-p headline info)
1855 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1856 (tags (and (eq (plist-get info :with-tags) t)
1857 (org-export-get-tags headline info))))
1858 (format "<a href=\"#%s\">%s</a>"
1859 ;; Label.
1860 (org-export-solidify-link-text
1861 (or (org-element-property :CUSTOM_ID headline)
1862 (concat "sec-" (mapconcat 'number-to-string
1863 headline-number "-"))))
1864 ;; Body.
1865 (concat section-number
1866 (org-export-data-with-translations
1867 (org-export-get-alt-title headline info)
1868 ;; Ignore any footnote-reference, link,
1869 ;; radio-target and target in table of contents.
1870 (append
1871 '((footnote-reference . ignore)
1872 (link . (lambda (link desc i) desc))
1873 (radio-target . (lambda (radio desc i) desc))
1874 (target . ignore))
1875 (org-export-backend-translate-table 'html))
1876 info)
1877 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1879 (defun org-html-list-of-listings (info)
1880 "Build a list of listings.
1881 INFO is a plist used as a communication channel. Return the list
1882 of listings as a string, or nil if it is empty."
1883 (let ((lol-entries (org-export-collect-listings info)))
1884 (when lol-entries
1885 (concat "<div id=\"list-of-listings\">\n"
1886 (format "<h%d>%s</h%d>\n"
1887 org-html-toplevel-hlevel
1888 (org-html--translate "List of Listings" info)
1889 org-html-toplevel-hlevel)
1890 "<div id=\"text-list-of-listings\">\n<ul>\n"
1891 (let ((count 0)
1892 (initial-fmt (org-html--translate "Listing %d:" info)))
1893 (mapconcat
1894 (lambda (entry)
1895 (let ((label (org-element-property :name entry))
1896 (title (org-trim
1897 (org-export-data
1898 (or (org-export-get-caption entry t)
1899 (org-export-get-caption entry))
1900 info))))
1901 (concat
1902 "<li>"
1903 (if (not label)
1904 (concat (format initial-fmt (incf count)) " " title)
1905 (format "<a href=\"#%s\">%s %s</a>"
1906 (org-export-solidify-link-text label)
1907 (format initial-fmt (incf count))
1908 title))
1909 "</li>")))
1910 lol-entries "\n"))
1911 "\n</ul>\n</div>\n</div>"))))
1913 (defun org-html-list-of-tables (info)
1914 "Build a list of tables.
1915 INFO is a plist used as a communication channel. Return the list
1916 of tables as a string, or nil if it is empty."
1917 (let ((lol-entries (org-export-collect-tables info)))
1918 (when lol-entries
1919 (concat "<div id=\"list-of-tables\">\n"
1920 (format "<h%d>%s</h%d>\n"
1921 org-html-toplevel-hlevel
1922 (org-html--translate "List of Tables" info)
1923 org-html-toplevel-hlevel)
1924 "<div id=\"text-list-of-tables\">\n<ul>\n"
1925 (let ((count 0)
1926 (initial-fmt (org-html--translate "Table %d:" info)))
1927 (mapconcat
1928 (lambda (entry)
1929 (let ((label (org-element-property :name entry))
1930 (title (org-trim
1931 (org-export-data
1932 (or (org-export-get-caption entry t)
1933 (org-export-get-caption entry))
1934 info))))
1935 (concat
1936 "<li>"
1937 (if (not label)
1938 (concat (format initial-fmt (incf count)) " " title)
1939 (format "<a href=\"#%s\">%s %s</a>"
1940 (org-export-solidify-link-text label)
1941 (format initial-fmt (incf count))
1942 title))
1943 "</li>")))
1944 lol-entries "\n"))
1945 "\n</ul>\n</div>\n</div>"))))
1948 ;;; Transcode Functions
1950 ;;;; Bold
1952 (defun org-html-bold (bold contents info)
1953 "Transcode BOLD from Org to HTML.
1954 CONTENTS is the text with bold markup. INFO is a plist holding
1955 contextual information."
1956 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1957 contents))
1959 ;;;; Center Block
1961 (defun org-html-center-block (center-block contents info)
1962 "Transcode a CENTER-BLOCK element from Org to HTML.
1963 CONTENTS holds the contents of the block. INFO is a plist
1964 holding contextual information."
1965 (format "<div class=\"center\">\n%s</div>" contents))
1967 ;;;; Clock
1969 (defun org-html-clock (clock contents info)
1970 "Transcode a CLOCK element from Org to HTML.
1971 CONTENTS is nil. INFO is a plist used as a communication
1972 channel."
1973 (format "<p>
1974 <span class=\"timestamp-wrapper\">
1975 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1976 </span>
1977 </p>"
1978 org-clock-string
1979 (org-translate-time
1980 (org-element-property :raw-value
1981 (org-element-property :value clock)))
1982 (let ((time (org-element-property :duration clock)))
1983 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1985 ;;;; Code
1987 (defun org-html-code (code contents info)
1988 "Transcode CODE from Org to HTML.
1989 CONTENTS is nil. INFO is a plist holding contextual
1990 information."
1991 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1992 (org-html-plain-text (org-element-property :value code) info)))
1994 ;;;; Drawer
1996 (defun org-html-drawer (drawer contents info)
1997 "Transcode a DRAWER element from Org to HTML.
1998 CONTENTS holds the contents of the block. INFO is a plist
1999 holding contextual information."
2000 (if (functionp org-html-format-drawer-function)
2001 (funcall org-html-format-drawer-function
2002 (org-element-property :drawer-name drawer)
2003 contents)
2004 ;; If there's no user defined function: simply
2005 ;; display contents of the drawer.
2006 contents))
2008 ;;;; Dynamic Block
2010 (defun org-html-dynamic-block (dynamic-block contents info)
2011 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2012 CONTENTS holds the contents of the block. INFO is a plist
2013 holding contextual information. See `org-export-data'."
2014 contents)
2016 ;;;; Entity
2018 (defun org-html-entity (entity contents info)
2019 "Transcode an ENTITY object from Org to HTML.
2020 CONTENTS are the definition itself. INFO is a plist holding
2021 contextual information."
2022 (org-element-property :html entity))
2024 ;;;; Example Block
2026 (defun org-html-example-block (example-block contents info)
2027 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2028 CONTENTS is nil. INFO is a plist holding contextual
2029 information."
2030 (if (org-export-read-attribute :attr_html example-block :textarea)
2031 (org-html--textarea-block example-block)
2032 (format "<pre class=\"example\">\n%s</pre>"
2033 (org-html-format-code example-block info))))
2035 ;;;; Export Snippet
2037 (defun org-html-export-snippet (export-snippet contents info)
2038 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2039 CONTENTS is nil. INFO is a plist holding contextual
2040 information."
2041 (when (eq (org-export-snippet-backend export-snippet) 'html)
2042 (org-element-property :value export-snippet)))
2044 ;;;; Export Block
2046 (defun org-html-export-block (export-block contents info)
2047 "Transcode a EXPORT-BLOCK element from Org to HTML.
2048 CONTENTS is nil. INFO is a plist holding contextual information."
2049 (when (string= (org-element-property :type export-block) "HTML")
2050 (org-remove-indentation (org-element-property :value export-block))))
2052 ;;;; Fixed Width
2054 (defun org-html-fixed-width (fixed-width contents info)
2055 "Transcode a FIXED-WIDTH element from Org to HTML.
2056 CONTENTS is nil. INFO is a plist holding contextual information."
2057 (format "<pre class=\"example\">\n%s</pre>"
2058 (org-html-do-format-code
2059 (org-remove-indentation
2060 (org-element-property :value fixed-width)))))
2062 ;;;; Footnote Reference
2064 (defun org-html-footnote-reference (footnote-reference contents info)
2065 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2066 CONTENTS is nil. INFO is a plist holding contextual information."
2067 (concat
2068 ;; Insert separator between two footnotes in a row.
2069 (let ((prev (org-export-get-previous-element footnote-reference info)))
2070 (when (eq (org-element-type prev) 'footnote-reference)
2071 org-html-footnote-separator))
2072 (cond
2073 ((not (org-export-footnote-first-reference-p footnote-reference info))
2074 (org-html-format-footnote-reference
2075 (org-export-get-footnote-number footnote-reference info)
2076 "IGNORED" 100))
2077 ;; Inline definitions are secondary strings.
2078 ((eq (org-element-property :type footnote-reference) 'inline)
2079 (org-html-format-footnote-reference
2080 (org-export-get-footnote-number footnote-reference info)
2081 "IGNORED" 1))
2082 ;; Non-inline footnotes definitions are full Org data.
2083 (t (org-html-format-footnote-reference
2084 (org-export-get-footnote-number footnote-reference info)
2085 "IGNORED" 1)))))
2087 ;;;; Headline
2089 (defun org-html-format-headline--wrap
2090 (headline info &optional format-function &rest extra-keys)
2091 "Transcode a HEADLINE element from Org to HTML.
2092 CONTENTS holds the contents of the headline. INFO is a plist
2093 holding contextual information."
2094 (let* ((level (+ (org-export-get-relative-level headline info)
2095 (1- org-html-toplevel-hlevel)))
2096 (headline-number (org-export-get-headline-number headline info))
2097 (section-number (and (not (org-export-low-level-p headline info))
2098 (org-export-numbered-headline-p headline info)
2099 (mapconcat 'number-to-string
2100 headline-number ".")))
2101 (todo (and (plist-get info :with-todo-keywords)
2102 (let ((todo (org-element-property :todo-keyword headline)))
2103 (and todo (org-export-data todo info)))))
2104 (todo-type (and todo (org-element-property :todo-type headline)))
2105 (priority (and (plist-get info :with-priority)
2106 (org-element-property :priority headline)))
2107 (text (org-export-data (org-element-property :title headline) info))
2108 (tags (and (plist-get info :with-tags)
2109 (org-export-get-tags headline info)))
2110 (headline-label (or (org-element-property :CUSTOM_ID headline)
2111 (concat "sec-" (mapconcat 'number-to-string
2112 headline-number "-"))))
2113 (format-function (cond
2114 ((functionp format-function) format-function)
2115 ((functionp org-html-format-headline-function)
2116 (function*
2117 (lambda (todo todo-type priority text tags
2118 &allow-other-keys)
2119 (funcall org-html-format-headline-function
2120 todo todo-type priority text tags))))
2121 (t 'org-html-format-headline))))
2122 (apply format-function
2123 todo todo-type priority text tags
2124 :headline-label headline-label :level level
2125 :section-number section-number extra-keys)))
2127 (defun org-html-headline (headline contents info)
2128 "Transcode a HEADLINE element from Org to HTML.
2129 CONTENTS holds the contents of the headline. INFO is a plist
2130 holding contextual information."
2131 ;; Empty contents?
2132 (setq contents (or contents ""))
2133 (let* ((numberedp (org-export-numbered-headline-p headline info))
2134 (level (org-export-get-relative-level headline info))
2135 (text (org-export-data (org-element-property :title headline) info))
2136 (todo (and (plist-get info :with-todo-keywords)
2137 (let ((todo (org-element-property :todo-keyword headline)))
2138 (and todo (org-export-data todo info)))))
2139 (todo-type (and todo (org-element-property :todo-type headline)))
2140 (tags (and (plist-get info :with-tags)
2141 (org-export-get-tags headline info)))
2142 (priority (and (plist-get info :with-priority)
2143 (org-element-property :priority headline)))
2144 (section-number (and (org-export-numbered-headline-p headline info)
2145 (mapconcat 'number-to-string
2146 (org-export-get-headline-number
2147 headline info) ".")))
2148 ;; Create the headline text.
2149 (full-text (org-html-format-headline--wrap headline info)))
2150 (cond
2151 ;; Case 1: This is a footnote section: ignore it.
2152 ((org-element-property :footnote-section-p headline) nil)
2153 ;; Case 2. This is a deep sub-tree: export it as a list item.
2154 ;; Also export as items headlines for which no section
2155 ;; format has been found.
2156 ((org-export-low-level-p headline info)
2157 ;; Build the real contents of the sub-tree.
2158 (let* ((type (if numberedp 'ordered 'unordered))
2159 (itemized-body (org-html-format-list-item
2160 contents type nil nil full-text)))
2161 (concat
2162 (and (org-export-first-sibling-p headline info)
2163 (org-html-begin-plain-list type))
2164 itemized-body
2165 (and (org-export-last-sibling-p headline info)
2166 (org-html-end-plain-list type)))))
2167 ;; Case 3. Standard headline. Export it as a section.
2169 (let* ((section-number (mapconcat 'number-to-string
2170 (org-export-get-headline-number
2171 headline info) "-"))
2172 (ids (remove 'nil
2173 (list (org-element-property :CUSTOM_ID headline)
2174 (concat "sec-" section-number)
2175 (org-element-property :ID headline))))
2176 (preferred-id (car ids))
2177 (extra-ids (cdr ids))
2178 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2179 (level1 (+ level (1- org-html-toplevel-hlevel)))
2180 (first-content (car (org-element-contents headline))))
2181 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2182 (org-html--container headline info)
2183 (format "outline-container-%s"
2184 (or (org-element-property :CUSTOM_ID headline)
2185 (concat "sec-" section-number)))
2186 (concat (format "outline-%d" level1) (and extra-class " ")
2187 extra-class)
2188 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2189 level1
2190 preferred-id
2191 (mapconcat
2192 (lambda (x)
2193 (let ((id (org-export-solidify-link-text
2194 (if (org-uuidgen-p x) (concat "ID-" x)
2195 x))))
2196 (org-html--anchor id)))
2197 extra-ids "")
2198 full-text
2199 level1)
2200 ;; When there is no section, pretend there is an empty
2201 ;; one to get the correct <div class="outline- ...>
2202 ;; which is needed by `org-info.js'.
2203 (if (not (eq (org-element-type first-content) 'section))
2204 (concat (org-html-section first-content "" info)
2205 contents)
2206 contents)
2207 (org-html--container headline info)))))))
2209 (defun org-html--container (headline info)
2210 (or (org-element-property :HTML_CONTAINER headline)
2211 (if (= 1 (org-export-get-relative-level headline info))
2212 (plist-get info :html-container)
2213 "div")))
2215 ;;;; Horizontal Rule
2217 (defun org-html-horizontal-rule (horizontal-rule contents info)
2218 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2219 CONTENTS is nil. INFO is a plist holding contextual information."
2220 "<hr/>")
2222 ;;;; Inline Src Block
2224 (defun org-html-inline-src-block (inline-src-block contents info)
2225 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2226 CONTENTS holds the contents of the item. INFO is a plist holding
2227 contextual information."
2228 (let* ((org-lang (org-element-property :language inline-src-block))
2229 (code (org-element-property :value inline-src-block)))
2230 (error "Cannot export inline src block")))
2232 ;;;; Inlinetask
2234 (defun org-html-format-section (text class &optional id)
2235 "Format a section with TEXT into a HTML div with CLASS and ID."
2236 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2237 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2239 (defun org-html-inlinetask (inlinetask contents info)
2240 "Transcode an INLINETASK element from Org to HTML.
2241 CONTENTS holds the contents of the block. INFO is a plist
2242 holding contextual information."
2243 (cond
2244 ;; If `org-html-format-inlinetask-function' is provided, call it
2245 ;; with appropriate arguments.
2246 ((functionp org-html-format-inlinetask-function)
2247 (let ((format-function
2248 (function*
2249 (lambda (todo todo-type priority text tags
2250 &key contents &allow-other-keys)
2251 (funcall org-html-format-inlinetask-function
2252 todo todo-type priority text tags contents)))))
2253 (org-html-format-headline--wrap
2254 inlinetask info format-function :contents contents)))
2255 ;; Otherwise, use a default template.
2256 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2257 (org-html-format-headline--wrap inlinetask info)
2258 contents))))
2260 ;;;; Italic
2262 (defun org-html-italic (italic contents info)
2263 "Transcode ITALIC from Org to HTML.
2264 CONTENTS is the text with italic markup. INFO is a plist holding
2265 contextual information."
2266 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2268 ;;;; Item
2270 (defun org-html-checkbox (checkbox)
2271 "Format CHECKBOX into HTML."
2272 (case checkbox (on "<code>[X]</code>")
2273 (off "<code>[&#xa0;]</code>")
2274 (trans "<code>[-]</code>")
2275 (t "")))
2277 (defun org-html-format-list-item (contents type checkbox
2278 &optional term-counter-id
2279 headline)
2280 "Format a list item into HTML."
2281 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2282 (concat
2283 (case type
2284 (ordered
2285 (let* ((counter term-counter-id)
2286 (extra (if counter (format " value=\"%s\"" counter) "")))
2287 (concat
2288 (format "<li%s>" extra)
2289 (when headline (concat headline "<br/>")))))
2290 (unordered
2291 (let* ((id term-counter-id)
2292 (extra (if id (format " id=\"%s\"" id) "")))
2293 (concat
2294 (format "<li%s>" extra)
2295 (when headline (concat headline "<br/>")))))
2296 (descriptive
2297 (let* ((term term-counter-id))
2298 (setq term (or term "(no term)"))
2299 ;; Check-boxes in descriptive lists are associated to tag.
2300 (concat (format "<dt> %s </dt>"
2301 (concat checkbox term))
2302 "<dd>"))))
2303 (unless (eq type 'descriptive) checkbox)
2304 contents
2305 (case type
2306 (ordered "</li>")
2307 (unordered "</li>")
2308 (descriptive "</dd>")))))
2310 (defun org-html-item (item contents info)
2311 "Transcode an ITEM element from Org to HTML.
2312 CONTENTS holds the contents of the item. INFO is a plist holding
2313 contextual information."
2314 (let* ((plain-list (org-export-get-parent item))
2315 (type (org-element-property :type plain-list))
2316 (counter (org-element-property :counter item))
2317 (checkbox (org-element-property :checkbox item))
2318 (tag (let ((tag (org-element-property :tag item)))
2319 (and tag (org-export-data tag info)))))
2320 (org-html-format-list-item
2321 contents type checkbox (or tag counter))))
2323 ;;;; Keyword
2325 (defun org-html-keyword (keyword contents info)
2326 "Transcode a KEYWORD element from Org to HTML.
2327 CONTENTS is nil. INFO is a plist holding contextual information."
2328 (let ((key (org-element-property :key keyword))
2329 (value (org-element-property :value keyword)))
2330 (cond
2331 ((string= key "HTML") value)
2332 ((string= key "TOC")
2333 (let ((value (downcase value)))
2334 (cond
2335 ((string-match "\\<headlines\\>" value)
2336 (let ((depth (or (and (string-match "[0-9]+" value)
2337 (string-to-number (match-string 0 value)))
2338 (plist-get info :with-toc))))
2339 (org-html-toc depth info)))
2340 ((string= "listings" value) (org-html-list-of-listings info))
2341 ((string= "tables" value) (org-html-list-of-tables info))))))))
2343 ;;;; Latex Environment
2345 (defun org-html-format-latex (latex-frag processing-type)
2346 "Format the LaTeX fragment LATEX-FRAG into HTML."
2347 (let ((cache-relpath "") (cache-dir "") bfn)
2348 (unless (eq processing-type 'mathjax)
2349 (setq bfn (buffer-file-name)
2350 cache-relpath
2351 (concat "ltxpng/"
2352 (file-name-sans-extension
2353 (file-name-nondirectory bfn)))
2354 cache-dir (file-name-directory bfn)))
2355 (with-temp-buffer
2356 (insert latex-frag)
2357 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2358 nil nil processing-type)
2359 (buffer-string))))
2361 (defun org-html-latex-environment (latex-environment contents info)
2362 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2363 CONTENTS is nil. INFO is a plist holding contextual information."
2364 (let ((processing-type (plist-get info :with-latex))
2365 (latex-frag (org-remove-indentation
2366 (org-element-property :value latex-environment)))
2367 (caption (org-export-data
2368 (org-export-get-caption latex-environment) info))
2369 (attr nil) ; FIXME
2370 (label (org-element-property :name latex-environment)))
2371 (cond
2372 ((memq processing-type '(t mathjax))
2373 (org-html-format-latex latex-frag 'mathjax))
2374 ((eq processing-type 'dvipng)
2375 (let* ((formula-link (org-html-format-latex
2376 latex-frag processing-type)))
2377 (when (and formula-link
2378 (string-match "file:\\([^]]*\\)" formula-link))
2379 (org-html-format-inline-image
2380 (match-string 1 formula-link) caption label attr t))))
2381 (t latex-frag))))
2383 ;;;; Latex Fragment
2385 (defun org-html-latex-fragment (latex-fragment contents info)
2386 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2387 CONTENTS is nil. INFO is a plist holding contextual information."
2388 (let ((latex-frag (org-element-property :value latex-fragment))
2389 (processing-type (plist-get info :with-latex)))
2390 (case processing-type
2391 ((t mathjax)
2392 (org-html-format-latex latex-frag 'mathjax))
2393 (dvipng
2394 (let* ((formula-link (org-html-format-latex
2395 latex-frag processing-type)))
2396 (when (and formula-link
2397 (string-match "file:\\([^]]*\\)" formula-link))
2398 (org-html-format-inline-image
2399 (match-string 1 formula-link)))))
2400 (t latex-frag))))
2402 ;;;; Line Break
2404 (defun org-html-line-break (line-break contents info)
2405 "Transcode a LINE-BREAK object from Org to HTML.
2406 CONTENTS is nil. INFO is a plist holding contextual information."
2407 "<br/>\n")
2409 ;;;; Link
2411 (defun org-html-link--inline-image (link desc info)
2412 "Return HTML code for an inline image.
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 ;; Return proper string, depending on DISPOSITION.
2431 (org-html-format-inline-image
2432 path caption label
2433 (org-html--make-attribute-string
2434 (org-export-read-attribute :attr_html parent))
2435 (org-html-standalone-image-p link info))))
2437 (defvar org-html-standalone-image-predicate)
2438 (defun org-html-standalone-image-p (element info &optional predicate)
2439 "Test if ELEMENT is a standalone image for the purpose HTML export.
2440 INFO is a plist holding contextual information.
2442 Return non-nil, if ELEMENT is of type paragraph and it's sole
2443 content, save for whitespaces, is a link that qualifies as an
2444 inline image.
2446 Return non-nil, if ELEMENT is of type link and it's containing
2447 paragraph has no other content save for leading and trailing
2448 whitespaces.
2450 Return nil, otherwise.
2452 Bind `org-html-standalone-image-predicate' to constrain
2453 paragraph further. For example, to check for only captioned
2454 standalone images, do the following.
2456 \(setq org-html-standalone-image-predicate
2457 \(lambda \(paragraph\)
2458 \(org-element-property :caption paragraph\)\)\)"
2459 (let ((paragraph (case (org-element-type element)
2460 (paragraph element)
2461 (link (and (org-export-inline-image-p
2462 element org-html-inline-image-rules)
2463 (org-export-get-parent element)))
2464 (t nil))))
2465 (when (eq (org-element-type paragraph) 'paragraph)
2466 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2467 (functionp org-html-standalone-image-predicate)))
2468 (funcall org-html-standalone-image-predicate paragraph))
2469 (let ((contents (org-element-contents paragraph)))
2470 (loop for x in contents
2471 with inline-image-count = 0
2472 always (cond
2473 ((eq (org-element-type x) 'plain-text)
2474 (not (org-string-nw-p x)))
2475 ((eq (org-element-type x) 'link)
2476 (when (org-export-inline-image-p
2477 x org-html-inline-image-rules)
2478 (= (incf inline-image-count) 1)))
2479 (t nil))))))))
2481 (defun org-html-link (link desc info)
2482 "Transcode a LINK object from Org to HTML.
2484 DESC is the description part of the link, or the empty string.
2485 INFO is a plist holding contextual information. See
2486 `org-export-data'."
2487 (let* ((link-org-files-as-html-maybe
2488 (function
2489 (lambda (raw-path info)
2490 "Treat links to `file.org' as links to `file.html', if needed.
2491 See `org-html-link-org-files-as-html'."
2492 (cond
2493 ((and org-html-link-org-files-as-html
2494 (string= ".org"
2495 (downcase (file-name-extension raw-path "."))))
2496 (concat (file-name-sans-extension raw-path) "."
2497 (plist-get info :html-extension)))
2498 (t raw-path)))))
2499 (type (org-element-property :type link))
2500 (raw-path (org-element-property :path link))
2501 ;; Ensure DESC really exists, or set it to nil.
2502 (desc (org-string-nw-p desc))
2503 (path
2504 (cond
2505 ((member type '("http" "https" "ftp" "mailto"))
2506 (concat type ":" raw-path))
2507 ((string= type "file")
2508 ;; Treat links to ".org" files as ".html", if needed.
2509 (setq raw-path
2510 (funcall link-org-files-as-html-maybe raw-path info))
2511 ;; If file path is absolute, prepend it with protocol
2512 ;; component - "file://".
2513 (when (file-name-absolute-p raw-path)
2514 (setq raw-path
2515 (concat "file://" (expand-file-name raw-path))))
2516 ;; Add search option, if any. A search option can be
2517 ;; relative to a custom-id or a headline title. Any other
2518 ;; option is ignored.
2519 (let ((option (org-element-property :search-option link)))
2520 (cond ((not option) raw-path)
2521 ((eq (aref option 0) ?#) (concat raw-path option))
2522 ;; External fuzzy link: try to resolve it if path
2523 ;; belongs to current project, if any.
2524 ((eq (aref option 0) ?*)
2525 (concat
2526 raw-path
2527 (let ((numbers
2528 (org-publish-resolve-external-fuzzy-link
2529 (org-element-property :path link) option)))
2530 (and numbers (concat "#sec-"
2531 (mapconcat 'number-to-string
2532 numbers "-"))))))
2533 (t raw-path))))
2534 (t raw-path)))
2535 ;; Extract attributes from parent's paragraph. HACK: Only do
2536 ;; this for the first link in parent. This is needed as long
2537 ;; as attributes cannot be set on a per link basis.
2538 (attributes
2539 (let ((parent (org-export-get-parent-element link)))
2540 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2542 (let ((att (org-html--make-attribute-string
2543 (org-export-read-attribute :attr_html parent))))
2544 (cond ((not (org-string-nw-p att)) "")
2545 ((and desc (string-match (regexp-quote att) desc)) "")
2546 (t (concat " " att)))))))
2547 protocol)
2548 (cond
2549 ;; Image file.
2550 ((and (or (eq t org-html-inline-images)
2551 (and org-html-inline-images (not desc)))
2552 (org-export-inline-image-p link org-html-inline-image-rules))
2553 (org-html-link--inline-image link desc info))
2554 ;; Radio target: Transcode target's contents and use them as
2555 ;; link's description.
2556 ((string= type "radio")
2557 (let ((destination (org-export-resolve-radio-link link info)))
2558 (when destination
2559 (format "<a href=\"#%s\"%s>%s</a>"
2560 (org-export-solidify-link-text path)
2561 attributes
2562 (org-export-data (org-element-contents destination) info)))))
2563 ;; Links pointing to a headline: Find destination and build
2564 ;; appropriate referencing command.
2565 ((member type '("custom-id" "fuzzy" "id"))
2566 (let ((destination (if (string= type "fuzzy")
2567 (org-export-resolve-fuzzy-link link info)
2568 (org-export-resolve-id-link link info))))
2569 (case (org-element-type destination)
2570 ;; ID link points to an external file.
2571 (plain-text
2572 (let ((fragment (concat "ID-" path))
2573 ;; Treat links to ".org" files as ".html", if needed.
2574 (path (funcall link-org-files-as-html-maybe
2575 destination info)))
2576 (format "<a href=\"%s#%s\"%s>%s</a>"
2577 path fragment attributes (or desc destination))))
2578 ;; Fuzzy link points nowhere.
2579 ((nil)
2580 (format "<i>%s</i>"
2581 (or desc
2582 (org-export-data
2583 (org-element-property :raw-link link) info))))
2584 ;; Fuzzy link points to an invisible target.
2585 (keyword nil)
2586 ;; Link points to a headline.
2587 (headline
2588 (let ((href
2589 ;; What href to use?
2590 (cond
2591 ;; Case 1: Headline is linked via it's CUSTOM_ID
2592 ;; property. Use CUSTOM_ID.
2593 ((string= type "custom-id")
2594 (org-element-property :CUSTOM_ID destination))
2595 ;; Case 2: Headline is linked via it's ID property
2596 ;; or through other means. Use the default href.
2597 ((member type '("id" "fuzzy"))
2598 (format "sec-%s"
2599 (mapconcat 'number-to-string
2600 (org-export-get-headline-number
2601 destination info) "-")))
2602 (t (error "Shouldn't reach here"))))
2603 ;; What description to use?
2604 (desc
2605 ;; Case 1: Headline is numbered and LINK has no
2606 ;; description. Display section number.
2607 (if (and (org-export-numbered-headline-p destination info)
2608 (not desc))
2609 (mapconcat 'number-to-string
2610 (org-export-get-headline-number
2611 destination info) ".")
2612 ;; Case 2: Either the headline is un-numbered or
2613 ;; LINK has a custom description. Display LINK's
2614 ;; description or headline's title.
2615 (or desc (org-export-data (org-element-property
2616 :title destination) info)))))
2617 (format "<a href=\"#%s\"%s>%s</a>"
2618 (org-export-solidify-link-text href) attributes desc)))
2619 ;; Fuzzy link points to a target. Do as above.
2621 (let ((path (org-export-solidify-link-text path)) number)
2622 (unless desc
2623 (setq number (cond
2624 ((org-html-standalone-image-p destination info)
2625 (org-export-get-ordinal
2626 (assoc 'link (org-element-contents destination))
2627 info 'link 'org-html-standalone-image-p))
2628 (t (org-export-get-ordinal destination info))))
2629 (setq desc (when number
2630 (if (atom number) (number-to-string number)
2631 (mapconcat 'number-to-string number ".")))))
2632 (format "<a href=\"#%s\"%s>%s</a>"
2633 path attributes (or desc "No description for this link")))))))
2634 ;; Coderef: replace link with the reference name or the
2635 ;; equivalent line number.
2636 ((string= type "coderef")
2637 (let ((fragment (concat "coderef-" path)))
2638 (format "<a href=\"#%s\"%s%s>%s</a>"
2639 fragment
2640 (org-trim
2641 (format (concat "class=\"coderef\""
2642 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2643 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2644 fragment fragment))
2645 attributes
2646 (format (org-export-get-coderef-format path desc)
2647 (org-export-resolve-coderef path info)))))
2648 ;; Link type is handled by a special function.
2649 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2650 (funcall protocol (org-link-unescape path) desc 'html))
2651 ;; External link with a description part.
2652 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2653 ;; External link without a description part.
2654 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2655 ;; No path, only description. Try to do something useful.
2656 (t (format "<i>%s</i>" desc)))))
2658 ;;;; Paragraph
2660 (defun org-html-paragraph (paragraph contents info)
2661 "Transcode a PARAGRAPH element from Org to HTML.
2662 CONTENTS is the contents of the paragraph, as a string. INFO is
2663 the plist used as a communication channel."
2664 (let* ((parent (org-export-get-parent paragraph))
2665 (parent-type (org-element-type parent))
2666 (style '((footnote-definition " class=\"footpara\"")))
2667 (extra (or (cadr (assoc parent-type style)) "")))
2668 (cond
2669 ((and (eq (org-element-type parent) 'item)
2670 (= (org-element-property :begin paragraph)
2671 (org-element-property :contents-begin parent)))
2672 ;; leading paragraph in a list item have no tags
2673 contents)
2674 ((org-html-standalone-image-p paragraph info)
2675 ;; standalone image
2676 contents)
2677 (t (format "<p%s>\n%s</p>" extra contents)))))
2679 ;;;; Plain List
2681 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2682 ;; the correct value for the item counter
2683 (defun org-html-begin-plain-list (type &optional arg1)
2684 "Insert the beginning of the HTML list depending on TYPE.
2685 When ARG1 is a string, use it as the start parameter for ordered
2686 lists."
2687 (case type
2688 (ordered
2689 (format "<ol class=\"org-ol\"%s>"
2690 (if arg1 (format " start=\"%d\"" arg1) "")))
2691 (unordered "<ul class=\"org-ul\">")
2692 (descriptive "<dl class=\"org-dl\">")))
2694 (defun org-html-end-plain-list (type)
2695 "Insert the end of the HTML list depending on TYPE."
2696 (case type
2697 (ordered "</ol>")
2698 (unordered "</ul>")
2699 (descriptive "</dl>")))
2701 (defun org-html-plain-list (plain-list contents info)
2702 "Transcode a PLAIN-LIST element from Org to HTML.
2703 CONTENTS is the contents of the list. INFO is a plist holding
2704 contextual information."
2705 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2706 (type (org-element-property :type plain-list)))
2707 (format "%s\n%s%s"
2708 (org-html-begin-plain-list type)
2709 contents (org-html-end-plain-list type))))
2711 ;;;; Plain Text
2713 (defun org-html-convert-special-strings (string)
2714 "Convert special characters in STRING to HTML."
2715 (let ((all org-html-special-string-regexps)
2716 e a re rpl start)
2717 (while (setq a (pop all))
2718 (setq re (car a) rpl (cdr a) start 0)
2719 (while (string-match re string start)
2720 (setq string (replace-match rpl t nil string))))
2721 string))
2723 (defun org-html-encode-plain-text (text)
2724 "Convert plain text characters from TEXT to HTML equivalent.
2725 Possible conversions are set in `org-html-protect-char-alist'."
2726 (mapc
2727 (lambda (pair)
2728 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2729 org-html-protect-char-alist)
2730 text)
2732 (defun org-html-plain-text (text info)
2733 "Transcode a TEXT string from Org to HTML.
2734 TEXT is the string to transcode. INFO is a plist holding
2735 contextual information."
2736 (let ((output text))
2737 ;; Protect following characters: <, >, &.
2738 (setq output (org-html-encode-plain-text output))
2739 ;; Handle smart quotes. Be sure to provide original string since
2740 ;; OUTPUT may have been modified.
2741 (when (plist-get info :with-smart-quotes)
2742 (setq output (org-export-activate-smart-quotes output :html info text)))
2743 ;; Handle special strings.
2744 (when (plist-get info :with-special-strings)
2745 (setq output (org-html-convert-special-strings output)))
2746 ;; Handle break preservation if required.
2747 (when (plist-get info :preserve-breaks)
2748 (setq output
2749 (replace-regexp-in-string
2750 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2751 ;; Return value.
2752 output))
2755 ;; Planning
2757 (defun org-html-planning (planning contents info)
2758 "Transcode a PLANNING element from Org to HTML.
2759 CONTENTS is nil. INFO is a plist used as a communication
2760 channel."
2761 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2762 (format
2763 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2764 (mapconcat
2765 'identity
2766 (delq nil
2767 (list
2768 (let ((closed (org-element-property :closed planning)))
2769 (when closed
2770 (format span-fmt org-closed-string
2771 (org-translate-time
2772 (org-element-property :raw-value closed)))))
2773 (let ((deadline (org-element-property :deadline planning)))
2774 (when deadline
2775 (format span-fmt org-deadline-string
2776 (org-translate-time
2777 (org-element-property :raw-value deadline)))))
2778 (let ((scheduled (org-element-property :scheduled planning)))
2779 (when scheduled
2780 (format span-fmt org-scheduled-string
2781 (org-translate-time
2782 (org-element-property :raw-value scheduled)))))))
2783 " "))))
2785 ;;;; Property Drawer
2787 (defun org-html-property-drawer (property-drawer contents info)
2788 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2789 CONTENTS is nil. INFO is a plist holding contextual
2790 information."
2791 ;; The property drawer isn't exported but we want separating blank
2792 ;; lines nonetheless.
2795 ;;;; Quote Block
2797 (defun org-html-quote-block (quote-block contents info)
2798 "Transcode a QUOTE-BLOCK element from Org to HTML.
2799 CONTENTS holds the contents of the block. INFO is a plist
2800 holding contextual information."
2801 (format "<blockquote>\n%s</blockquote>" contents))
2803 ;;;; Quote Section
2805 (defun org-html-quote-section (quote-section contents info)
2806 "Transcode a QUOTE-SECTION element from Org to HTML.
2807 CONTENTS is nil. INFO is a plist holding contextual information."
2808 (let ((value (org-remove-indentation
2809 (org-element-property :value quote-section))))
2810 (when value (format "<pre>\n%s</pre>" value))))
2812 ;;;; Section
2814 (defun org-html-section (section contents info)
2815 "Transcode a SECTION element from Org to HTML.
2816 CONTENTS holds the contents of the section. INFO is a plist
2817 holding contextual information."
2818 (let ((parent (org-export-get-parent-headline section)))
2819 ;; Before first headline: no container, just return CONTENTS.
2820 (if (not parent) contents
2821 ;; Get div's class and id references.
2822 (let* ((class-num (+ (org-export-get-relative-level parent info)
2823 (1- org-html-toplevel-hlevel)))
2824 (section-number
2825 (mapconcat
2826 'number-to-string
2827 (org-export-get-headline-number parent info) "-")))
2828 ;; Build return value.
2829 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2830 class-num
2831 (or (org-element-property :CUSTOM_ID parent) section-number)
2832 contents)))))
2834 ;;;; Radio Target
2836 (defun org-html-radio-target (radio-target text info)
2837 "Transcode a RADIO-TARGET object from Org to HTML.
2838 TEXT is the text of the target. INFO is a plist holding
2839 contextual information."
2840 (let ((id (org-export-solidify-link-text
2841 (org-element-property :value radio-target))))
2842 (org-html--anchor id text)))
2844 ;;;; Special Block
2846 (defun org-html-special-block (special-block contents info)
2847 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2848 CONTENTS holds the contents of the block. INFO is a plist
2849 holding contextual information."
2850 (format "<div class=\"%s\">\n%s\n</div>"
2851 (downcase (org-element-property :type special-block))
2852 contents))
2854 ;;;; Src Block
2856 (defun org-html-src-block (src-block contents info)
2857 "Transcode a SRC-BLOCK element from Org to HTML.
2858 CONTENTS holds the contents of the item. INFO is a plist holding
2859 contextual information."
2860 (if (org-export-read-attribute :attr_html src-block :textarea)
2861 (org-html--textarea-block src-block)
2862 (let ((lang (org-element-property :language src-block))
2863 (caption (org-export-get-caption src-block))
2864 (code (org-html-format-code src-block info))
2865 (label (let ((lbl (org-element-property :name src-block)))
2866 (if (not lbl) ""
2867 (format " id=\"%s\""
2868 (org-export-solidify-link-text lbl))))))
2869 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2870 (format
2871 "<div class=\"org-src-container\">\n%s%s\n</div>"
2872 (if (not caption) ""
2873 (format "<label class=\"org-src-name\">%s</label>"
2874 (org-export-data caption info)))
2875 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2877 ;;;; Statistics Cookie
2879 (defun org-html-statistics-cookie (statistics-cookie contents info)
2880 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2881 CONTENTS is nil. INFO is a plist holding contextual information."
2882 (let ((cookie-value (org-element-property :value statistics-cookie)))
2883 (format "<code>%s</code>" cookie-value)))
2885 ;;;; Strike-Through
2887 (defun org-html-strike-through (strike-through contents info)
2888 "Transcode STRIKE-THROUGH from Org to HTML.
2889 CONTENTS is the text with strike-through markup. INFO is a plist
2890 holding contextual information."
2891 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2892 contents))
2894 ;;;; Subscript
2896 (defun org-html-subscript (subscript contents info)
2897 "Transcode a SUBSCRIPT object from Org to HTML.
2898 CONTENTS is the contents of the object. INFO is a plist holding
2899 contextual information."
2900 (format "<sub>%s</sub>" contents))
2902 ;;;; Superscript
2904 (defun org-html-superscript (superscript contents info)
2905 "Transcode a SUPERSCRIPT object from Org to HTML.
2906 CONTENTS is the contents of the object. INFO is a plist holding
2907 contextual information."
2908 (format "<sup>%s</sup>" contents))
2910 ;;;; Tabel Cell
2912 (defun org-html-table-cell (table-cell contents info)
2913 "Transcode a TABLE-CELL element from Org to HTML.
2914 CONTENTS is nil. INFO is a plist used as a communication
2915 channel."
2916 (let* ((table-row (org-export-get-parent table-cell))
2917 (table (org-export-get-parent-table table-cell))
2918 (cell-attrs
2919 (if (not org-html-table-align-individual-fields) ""
2920 (format (if (and (boundp 'org-html-format-table-no-css)
2921 org-html-format-table-no-css)
2922 " align=\"%s\"" " class=\"%s\"")
2923 (org-export-table-cell-alignment table-cell info)))))
2924 (when (or (not contents) (string= "" (org-trim contents)))
2925 (setq contents "&#xa0;"))
2926 (cond
2927 ((and (org-export-table-has-header-p table info)
2928 (= 1 (org-export-table-row-group table-row info)))
2929 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2930 contents (cdr org-html-table-header-tags)))
2931 ((and org-html-table-use-header-tags-for-first-column
2932 (zerop (cdr (org-export-table-cell-address table-cell info))))
2933 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2934 contents (cdr org-html-table-header-tags)))
2935 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2936 contents (cdr org-html-table-data-tags))))))
2938 ;;;; Table Row
2940 (defun org-html-table-row (table-row contents info)
2941 "Transcode a TABLE-ROW element from Org to HTML.
2942 CONTENTS is the contents of the row. INFO is a plist used as a
2943 communication channel."
2944 ;; Rules are ignored since table separators are deduced from
2945 ;; borders of the current row.
2946 (when (eq (org-element-property :type table-row) 'standard)
2947 (let* ((rowgroup-number (org-export-table-row-group table-row info))
2948 (row-number (org-export-table-row-number table-row info))
2949 (start-rowgroup-p
2950 (org-export-table-row-starts-rowgroup-p table-row info))
2951 (end-rowgroup-p
2952 (org-export-table-row-ends-rowgroup-p table-row info))
2953 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2954 ;; but should be set so that `org-html-table-row-tags' can
2955 ;; use them (see the docstring of this variable.)
2956 (top-row-p (and (equal start-rowgroup-p '(top))
2957 (equal end-rowgroup-p '(below top))))
2958 (bottom-row-p (and (equal start-rowgroup-p '(above))
2959 (equal end-rowgroup-p '(bottom above))))
2960 (rowgroup-tags
2961 (cond
2962 ;; Case 1: Row belongs to second or subsequent rowgroups.
2963 ((not (= 1 rowgroup-number))
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 start-rowgroup-p (car rowgroup-tags))
2974 ;; Actual table row
2975 (concat "\n" (eval (car org-html-table-row-tags))
2976 contents
2977 "\n"
2978 (eval (cdr org-html-table-row-tags)))
2979 ;; End a rowgroup?
2980 (when end-rowgroup-p (cdr rowgroup-tags))))))
2982 ;;;; Table
2984 (defun org-html-table-first-row-data-cells (table info)
2985 "Transcode the first row of TABLE.
2986 INFO is a plist used as a communication channel."
2987 (let ((table-row
2988 (org-element-map table 'table-row
2989 (lambda (row)
2990 (unless (eq (org-element-property :type row) 'rule) row))
2991 info 'first-match))
2992 (special-column-p (org-export-table-has-special-column-p table)))
2993 (if (not special-column-p) (org-element-contents table-row)
2994 (cdr (org-element-contents table-row)))))
2996 (defun org-html-table--table.el-table (table info)
2997 "Format table.el tables into HTML.
2998 INFO is a plist used as a communication channel."
2999 (when (eq (org-element-property :type table) 'table.el)
3000 (require 'table)
3001 (let ((outbuf (with-current-buffer
3002 (get-buffer-create "*org-export-table*")
3003 (erase-buffer) (current-buffer))))
3004 (with-temp-buffer
3005 (insert (org-element-property :value table))
3006 (goto-char 1)
3007 (re-search-forward "^[ \t]*|[^|]" nil t)
3008 (table-generate-source 'html outbuf))
3009 (with-current-buffer outbuf
3010 (prog1 (org-trim (buffer-string))
3011 (kill-buffer) )))))
3013 (defun org-html-table (table contents info)
3014 "Transcode a TABLE element from Org to HTML.
3015 CONTENTS is the contents of the table. INFO is a plist holding
3016 contextual information."
3017 (case (org-element-property :type table)
3018 ;; Case 1: table.el table. Convert it using appropriate tools.
3019 (table.el (org-html-table--table.el-table table info))
3020 ;; Case 2: Standard table.
3022 (let* ((label (org-element-property :name table))
3023 (caption (org-export-get-caption table))
3024 (attributes
3025 (org-html--make-attribute-string
3026 (org-combine-plists
3027 (and label (list :id (org-export-solidify-link-text label)))
3028 (plist-get info :html-table-attributes)
3029 (org-export-read-attribute :attr_html table))))
3030 (alignspec
3031 (if (and (boundp 'org-html-format-table-no-css)
3032 org-html-format-table-no-css)
3033 "align=\"%s\"" "class=\"%s\""))
3034 (table-column-specs
3035 (function
3036 (lambda (table info)
3037 (mapconcat
3038 (lambda (table-cell)
3039 (let ((alignment (org-export-table-cell-alignment
3040 table-cell info)))
3041 (concat
3042 ;; Begin a colgroup?
3043 (when (org-export-table-cell-starts-colgroup-p
3044 table-cell info)
3045 "\n<colgroup>")
3046 ;; Add a column. Also specify it's alignment.
3047 (format "\n<col %s/>" (format alignspec alignment))
3048 ;; End a colgroup?
3049 (when (org-export-table-cell-ends-colgroup-p
3050 table-cell info)
3051 "\n</colgroup>"))))
3052 (org-html-table-first-row-data-cells table info) "\n")))))
3053 (format "<table%s>\n%s\n%s\n%s</table>"
3054 (if (equal attributes "") "" (concat " " attributes))
3055 (if (not caption) ""
3056 (format "<caption>%s</caption>"
3057 (org-export-data caption info)))
3058 (funcall table-column-specs table info)
3059 contents)))))
3061 ;;;; Target
3063 (defun org-html-target (target contents info)
3064 "Transcode a TARGET object from Org to HTML.
3065 CONTENTS is nil. INFO is a plist holding contextual
3066 information."
3067 (let ((id (org-export-solidify-link-text
3068 (org-element-property :value target))))
3069 (org-html--anchor id)))
3071 ;;;; Timestamp
3073 (defun org-html-timestamp (timestamp contents info)
3074 "Transcode a TIMESTAMP object from Org to HTML.
3075 CONTENTS is nil. INFO is a plist holding contextual
3076 information."
3077 (let ((value (org-html-plain-text
3078 (org-timestamp-translate timestamp) info)))
3079 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3080 (replace-regexp-in-string "--" "&#x2013;" value))))
3082 ;;;; Underline
3084 (defun org-html-underline (underline contents info)
3085 "Transcode UNDERLINE from Org to HTML.
3086 CONTENTS is the text with underline markup. INFO is a plist
3087 holding contextual information."
3088 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3089 contents))
3091 ;;;; Verbatim
3093 (defun org-html-verbatim (verbatim contents info)
3094 "Transcode VERBATIM from Org to HTML.
3095 CONTENTS is nil. INFO is a plist holding contextual
3096 information."
3097 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3098 (org-html-plain-text (org-element-property :value verbatim) info)))
3100 ;;;; Verse Block
3102 (defun org-html-verse-block (verse-block contents info)
3103 "Transcode a VERSE-BLOCK element from Org to HTML.
3104 CONTENTS is verse block contents. INFO is a plist holding
3105 contextual information."
3106 ;; Replace each newline character with line break. Also replace
3107 ;; each blank line with a line break.
3108 (setq contents (replace-regexp-in-string
3109 "^ *\\\\\\\\$" "<br/>\n"
3110 (replace-regexp-in-string
3111 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3112 ;; Replace each white space at beginning of a line with a
3113 ;; non-breaking space.
3114 (while (string-match "^[ \t]+" contents)
3115 (let* ((num-ws (length (match-string 0 contents)))
3116 (ws (let (out) (dotimes (i num-ws out)
3117 (setq out (concat out "&#xa0;"))))))
3118 (setq contents (replace-match ws nil t contents))))
3119 (format "<p class=\"verse\">\n%s</p>" contents))
3122 ;;; Filter Functions
3124 (defun org-html-final-function (contents backend info)
3125 "Filter to indent the HTML and convert HTML entities."
3126 (with-temp-buffer
3127 (insert contents)
3128 (set-auto-mode t)
3129 (if org-html-indent
3130 (indent-region (point-min) (point-max)))
3131 (when org-html-use-unicode-chars
3132 (require 'mm-url)
3133 (mm-url-decode-entities))
3134 (buffer-substring-no-properties (point-min) (point-max))))
3137 ;;; End-user functions
3139 ;;;###autoload
3140 (defun org-html-export-as-html
3141 (&optional async subtreep visible-only body-only ext-plist)
3142 "Export current buffer to an HTML buffer.
3144 If narrowing is active in the current buffer, only export its
3145 narrowed part.
3147 If a region is active, export that region.
3149 A non-nil optional argument ASYNC means the process should happen
3150 asynchronously. The resulting buffer should be accessible
3151 through the `org-export-stack' interface.
3153 When optional argument SUBTREEP is non-nil, export the sub-tree
3154 at point, extracting information from the headline properties
3155 first.
3157 When optional argument VISIBLE-ONLY is non-nil, don't export
3158 contents of hidden elements.
3160 When optional argument BODY-ONLY is non-nil, only write code
3161 between \"<body>\" and \"</body>\" tags.
3163 EXT-PLIST, when provided, is a property list with external
3164 parameters overriding Org default settings, but still inferior to
3165 file-local settings.
3167 Export is done in a buffer named \"*Org HTML Export*\", which
3168 will be displayed when `org-export-show-temporary-export-buffer'
3169 is non-nil."
3170 (interactive)
3171 (if async
3172 (org-export-async-start
3173 (lambda (output)
3174 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3175 (erase-buffer)
3176 (insert output)
3177 (goto-char (point-min))
3178 (set-auto-mode t)
3179 (org-export-add-to-stack (current-buffer) 'html)))
3180 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3181 (let ((outbuf (org-export-to-buffer
3182 'html "*Org HTML Export*"
3183 subtreep visible-only body-only ext-plist)))
3184 ;; Set major mode.
3185 (with-current-buffer outbuf (set-auto-mode t))
3186 (when org-export-show-temporary-export-buffer
3187 (switch-to-buffer-other-window outbuf)))))
3189 ;;;###autoload
3190 (defun org-html-convert-region-to-html ()
3191 "Assume the current region has org-mode syntax, and convert it to HTML.
3192 This can be used in any buffer. For example, you can write an
3193 itemized list in org-mode syntax in an HTML buffer and use this
3194 command to convert it."
3195 (interactive)
3196 (org-export-replace-region-by 'html))
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
3252 (concat "." (or (plist-get plist :html-extension)
3253 org-html-extension "html"))
3254 plist pub-dir))
3257 ;;; FIXME
3259 ;;;; org-format-table-html
3260 ;;;; org-format-org-table-html
3261 ;;;; org-format-table-table-html
3262 ;;;; org-table-number-fraction
3263 ;;;; org-table-number-regexp
3264 ;;;; org-html-table-caption-above
3265 ;;;; org-html-inline-image-extensions
3266 ;;;; org-export-preferred-target-alist
3267 ;;;; class for anchors
3268 ;;;; org-export-mark-todo-in-toc
3269 ;;;; org-html-format-org-link
3270 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3271 ;;;; alt = (file-name-nondirectory path)
3273 (provide 'ox-html)
3275 ;; Local variables:
3276 ;; generated-autoload-file: "org-loaddefs.el"
3277 ;; End:
3279 ;;; ox-html.el ends here