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