1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;; This library implements a HTML back-end for Org generic exporter.
28 ;; M-x org-html-export-as-html
30 ;; in an Org mode buffer. See ox.el for more details on how this
39 (require 'format-spec
)
40 (eval-when-compile (require 'cl
) (require 'table
))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file
"org-id" (id))
46 (declare-function htmlize-region
"ext:htmlize" (beg end
))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label
))
49 (declare-function mm-url-decode-entities
"mm-url" ())
53 (org-export-define-backend 'html
54 '((bold . org-html-bold
)
55 (center-block . org-html-center-block
)
56 (clock . org-html-clock
)
57 (code . org-html-code
)
58 (drawer . org-html-drawer
)
59 (dynamic-block . org-html-dynamic-block
)
60 (entity . org-html-entity
)
61 (example-block . org-html-example-block
)
62 (export-block . org-html-export-block
)
63 (export-snippet . org-html-export-snippet
)
64 (fixed-width . org-html-fixed-width
)
65 (footnote-definition . org-html-footnote-definition
)
66 (footnote-reference . org-html-footnote-reference
)
67 (headline . org-html-headline
)
68 (horizontal-rule . org-html-horizontal-rule
)
69 (inline-src-block . org-html-inline-src-block
)
70 (inlinetask . org-html-inlinetask
)
71 (inner-template . org-html-inner-template
)
72 (italic . org-html-italic
)
73 (item . org-html-item
)
74 (keyword . org-html-keyword
)
75 (latex-environment . org-html-latex-environment
)
76 (latex-fragment . org-html-latex-fragment
)
77 (line-break . org-html-line-break
)
78 (link . org-html-link
)
79 (paragraph . org-html-paragraph
)
80 (plain-list . org-html-plain-list
)
81 (plain-text . org-html-plain-text
)
82 (planning . org-html-planning
)
83 (property-drawer . org-html-property-drawer
)
84 (quote-block . org-html-quote-block
)
85 (quote-section . org-html-quote-section
)
86 (radio-target . org-html-radio-target
)
87 (section . org-html-section
)
88 (special-block . org-html-special-block
)
89 (src-block . org-html-src-block
)
90 (statistics-cookie . org-html-statistics-cookie
)
91 (strike-through . org-html-strike-through
)
92 (subscript . org-html-subscript
)
93 (superscript . org-html-superscript
)
94 (table . org-html-table
)
95 (table-cell . org-html-table-cell
)
96 (table-row . org-html-table-row
)
97 (target . org-html-target
)
98 (template . org-html-template
)
99 (timestamp . org-html-timestamp
)
100 (underline . org-html-underline
)
101 (verbatim . org-html-verbatim
)
102 (verse-block . org-html-verse-block
))
104 :filters-alist
'((:filter-options . org-html-infojs-install-script
)
105 (:filter-final-output . org-html-final-function
))
107 '(?h
"Export to HTML"
108 ((?H
"As HTML buffer" org-html-export-as-html
)
109 (?h
"As HTML file" org-html-export-to-html
)
110 (?o
"As HTML file and open"
112 (if a
(org-html-export-to-html t s v b
)
113 (org-open-file (org-html-export-to-html nil s v b
)))))))
115 '((:html-extension nil nil org-html-extension
)
116 (:html-link-org-as-html nil nil org-html-link-org-files-as-html
)
117 (:html-doctype
"HTML_DOCTYPE" nil org-html-doctype
)
118 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
119 (:html-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
120 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
121 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
122 (:html-postamble nil
"html-postamble" org-html-postamble
)
123 (:html-preamble nil
"html-preamble" org-html-preamble
)
124 (:html-head
"HTML_HEAD" nil org-html-head newline
)
125 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
126 (:html-head-include-default-style
"HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline
)
127 (:html-head-include-scripts
"HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline
)
128 (:html-table-attributes nil nil org-html-table-default-attributes
)
129 (:html-table-row-tags nil nil org-html-table-row-tags
)
130 (:html-xml-declaration nil nil org-html-xml-declaration
)
131 (:html-inline-images nil nil org-html-inline-images
)
132 (:infojs-opt
"INFOJS_OPT" nil nil
)
133 ;; Redefine regular options.
134 (:creator
"CREATOR" nil org-html-creator-string
)
135 (:with-latex nil
"tex" org-html-with-latex
)))
138 ;;; Internal Variables
140 (defvar org-html-format-table-no-css
)
141 (defvar htmlize-buffer-places
) ; from htmlize.el
143 (defvar org-html--pre
/postamble-class
"status"
144 "CSS class used for pre/postamble")
146 (defconst org-html-special-string-regexps
147 '(("\\\\-" .
"­") ; shy
148 ("---\\([^-]\\)" .
"—\\1") ; mdash
149 ("--\\([^-]\\)" .
"–\\1") ; ndash
150 ("\\.\\.\\." .
"…")) ; 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);
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;
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%; }
219 border: 1px solid #ccc;
220 box-shadow: 3px 3px 3px #eee;
222 font-family: monospace;
234 background-color: white;
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; }
265 border: 2px solid gray;
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; }
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"
296 (defvar org-html-infojs-opts-table
297 '((path PATH
"http://orgmode.org/org-info.js")
301 (tdepth TOC_DEPTH
"max")
302 (sdepth SECTION_DEPTH
"max")
303 (mouse MOUSE_HINT
"underline")
304 (buttons VIEW_BUTTONS
"0")
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
319 :package-version
'(Org .
"8.0")
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
336 :package-version
'(Org .
"8.0")
338 `(set :greedy t
:inline t
341 (list 'cons
(list 'const
(car x
))
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.
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[/*><!--*/
408 org_html_manager.setup(); // activate after the parameters are set
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
415 :package-version
'(Org .
"8.0")
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
))
432 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
433 (options (plist-get exp-plist
:infojs-opt
))
434 (table org-html-infojs-opts-table
)
436 (dolist (entry table
)
437 (let* ((opt (car entry
))
439 ;; Compute default values for script option OPT from
440 ;; `org-html-infojs-options' variable.
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
)
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
)
451 (match-string 1 options
)
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
))))
463 ((or (eq val t
) (equal val
"t")) "1")
464 ((or (eq val nil
) (equal val
"nil")) "0")
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
472 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
473 ;; The table of contents should not show more sections than we
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\");"
483 (when (and style
(> (length style
) 0))
484 (and (string-match "%MANAGER_OPTIONS" template
)
485 (setq style
(replace-match style t t template
))
488 exp-plist
:html-head-extra
489 (concat (or (plist-get exp-plist
:html-head-extra
) "")
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.
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
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
526 :package-version
'(Org .
"8.0")
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
533 :package-version
'(Org .
"8.0")
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.\"
553 :group
'org-export-html
558 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
559 <h2 class=\"footnotes\">%s: </h2>
560 <div id=\"text-footnotes\">
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
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
577 (defcustom org-html-footnote-separator
"<sup>, </sup>"
578 "Text used to separate footnotes."
579 :group
'org-export-html
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
592 :group
'org-export-html
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
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
617 :package-version
'(Org .
"8.0")
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
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
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
656 t Synonym for `mathjax'."
657 :group
'org-export-html
659 :package-version
'(Org .
"8.0")
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
677 When nil, the links still point to the plain `.org' file."
678 :group
'org-export-html
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
689 :group
'org-export-html
690 :type
'(choice (const :tag
"Never" nil
)
691 (const :tag
"Always" t
)
692 (const :tag
"When there is no description" maybe
)))
694 (defcustom org-html-inline-image-rules
695 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
697 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
698 "Rules characterizing image files that can be inlined into HTML.
699 A rule consists in an association whose key is the type of link
700 to consider, and value is a regexp that will be matched against
702 :group
'org-export-html
704 :package-version
'(Org .
"8.0")
705 :type
'(alist :key-type
(string :tag
"Type")
706 :value-type
(regexp :tag
"Path")))
710 (defcustom org-html-protect-char-alist
714 "Alist of characters to be converted by `org-html-protect'."
715 :group
'org-export-html
716 :type
'(repeat (cons (string :tag
"Character")
717 (string :tag
"HTML equivalent"))))
721 (defcustom org-html-htmlize-output-type
'inline-css
722 "Output type to be used by htmlize when formatting code snippets.
723 Choices are `css', to export the CSS selectors only, or `inline-css', to
724 export the CSS attribute values inline in the HTML. We use as default
725 `inline-css', in order to make the resulting HTML self-containing.
727 However, this will fail when using Emacs in batch mode for export, because
728 then no rich font definitions are in place. It will also not be good if
729 people with different Emacs setup contribute HTML files to a website,
730 because the fonts will represent the individual setups. In these cases,
731 it is much better to let Org/Htmlize assign classes only, and to use
732 a style file to define the look of these classes.
733 To get a start for your css file, start Emacs session and make sure that
734 all the faces you are interested in are defined, for example by loading files
735 in all modes you want. Then, use the command
736 \\[org-html-htmlize-generate-css] to extract class definitions."
737 :group
'org-export-html
738 :type
'(choice (const css
) (const inline-css
)))
740 (defcustom org-html-htmlize-font-prefix
"org-"
741 "The prefix for CSS class names for htmlize font specifications."
742 :group
'org-export-html
747 (defcustom org-html-table-default-attributes
748 '(:border
"2" :cellspacing
"0" :cellpadding
"6" :rules
"groups" :frame
"hsides")
749 "Default attributes and values which will be used in table tags.
750 This is a plist where attributes are symbols, starting with
751 colons, and values are strings."
752 :group
'org-export-html
754 :package-version
'(Org .
"8.0")
755 :type
'(plist :key-type
(symbol :tag
"Property")
756 :value-type
(string :tag
"Value")))
758 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
759 "The opening tag for table header fields.
760 This is customizable so that alignment options can be specified.
761 The first %s will be filled with the scope of the field, either row or col.
762 The second %s will be replaced by a style entry to align the field.
763 See also the variable `org-html-table-use-header-tags-for-first-column'.
764 See also the variable `org-html-table-align-individual-fields'."
765 :group
'org-export-html
766 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
768 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
769 "The opening tag for table data fields.
770 This is customizable so that alignment options can be specified.
771 The first %s will be filled with the scope of the field, either row or col.
772 The second %s will be replaced by a style entry to align the field.
773 See also the variable `org-html-table-align-individual-fields'."
774 :group
'org-export-html
775 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
777 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
778 "The opening and ending tags for table rows.
779 This is customizable so that alignment options can be specified.
780 Instead of strings, these can be Lisp forms that will be
781 evaluated for each row in order to construct the table row tags.
783 During evaluation, these variables will be dynamically bound so that
786 `row-number': row number (0 is the first row)
787 `rowgroup-number': group number of current row
788 `start-rowgroup-p': non-nil means the row starts a group
789 `end-rowgroup-p': non-nil means the row ends a group
790 `top-row-p': non-nil means this is the top row
791 `bottom-row-p': non-nil means this is the bottom row
795 \(setq org-html-table-row-tags
796 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
797 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
798 (t (if (= (mod row-number 2) 1)
799 \"<tr class=\\\"tr-odd\\\">\"
800 \"<tr class=\\\"tr-even\\\">\")))
803 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
804 and the bottom row, and otherwise alternate between \"tr-odd\" and
805 \"tr-even\" for odd and even rows."
806 :group
'org-export-html
808 (choice :tag
"Opening tag"
809 (string :tag
"Specify")
811 (choice :tag
"Closing tag"
812 (string :tag
"Specify")
815 (defcustom org-html-table-align-individual-fields t
816 "Non-nil means attach style attributes for alignment to each table field.
817 When nil, alignment will only be specified in the column tags, but this
818 is ignored by some browsers (like Firefox, Safari). Opera does it right
820 :group
'org-export-html
823 (defcustom org-html-table-use-header-tags-for-first-column nil
824 "Non-nil means format column one in tables with header tags.
825 When nil, also column one will use data tags."
826 :group
'org-export-html
829 (defcustom org-html-table-caption-above t
830 "When non-nil, place caption string at the beginning of the table.
831 Otherwise, place it near the end."
832 :group
'org-export-html
837 (defcustom org-html-tag-class-prefix
""
838 "Prefix to class names for TODO keywords.
839 Each tag gets a class given by the tag itself, with this prefix.
840 The default prefix is empty because it is nice to just use the keyword
841 as a class name. But if you get into conflicts with other, existing
842 CSS classes, then this prefix can be very useful."
843 :group
'org-export-html
846 ;;;; Template :: Generic
848 (defcustom org-html-extension
"html"
849 "The extension for exported HTML files."
850 :group
'org-export-html
853 (defcustom org-html-xml-declaration
854 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
855 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
856 "The extension for exported HTML files.
857 %s will be replaced with the charset of the exported file.
858 This may be a string, or an alist with export extensions
859 and corresponding declarations."
860 :group
'org-export-html
862 (string :tag
"Single declaration")
863 (repeat :tag
"Dependent on extension"
864 (cons (string :tag
"Extension")
865 (string :tag
"Declaration")))))
867 (defcustom org-html-coding-system
'utf-8
868 "Coding system for HTML export.
869 Use utf-8 as the default value."
870 :group
'org-export-html
872 :package-version
'(Org .
"8.0")
873 :type
'coding-system
)
875 (defcustom org-html-doctype
876 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
877 "Document type definition to use for exported HTML files.
878 Can be set with the in-buffer HTML_DOCTYPE property or for
879 publishing, with :html-doctype."
880 :group
'org-export-html
882 :package-version
'(Org .
"8.0")
885 (defcustom org-html-container-element
"div"
886 "HTML element to use for wrapping top level sections.
887 Can be set with the in-buffer HTML_CONTAINER property or for
888 publishing, with :html-container.
890 Note that changing the default will prevent you from using
891 org-info.js for your website."
892 :group
'org-export-html
894 :package-version
'(Org .
"8.0")
897 (defcustom org-html-divs
898 '((preamble "div" "preamble")
899 (content "div" "content")
900 (postamble "div" "postamble"))
901 "Alist of the three section elements for HTML export.
902 The car of each entry is one of 'preamble, 'content or 'postamble.
903 The cdrs of each entry are the ELEMENT_TYPE and ID for each
904 section of the exported document.
906 Note that changing the default will prevent you from using
907 org-info.js for your website."
908 :group
'org-export-html
910 :package-version
'(Org .
"8.0")
911 :type
'(list :greedy t
912 (list :tag
"Preamble"
913 (const :format
"" preamble
)
914 (string :tag
"element") (string :tag
" id"))
916 (const :format
"" content
)
917 (string :tag
"element") (string :tag
" id"))
918 (list :tag
"Postamble" (const :format
"" postamble
)
919 (string :tag
" id") (string :tag
"element"))))
921 (defcustom org-html-metadata-timestamp-format
"%Y-%m-%d %a %H:%M"
922 "Format used for timestamps in preamble, postamble and metadata.
923 See `format-time-string' for more information on its components."
924 :group
'org-export-html
926 :package-version
'(Org .
"8.0")
929 ;;;; Template :: Mathjax
931 (defcustom org-html-mathjax-options
932 '((path "http://orgmode.org/mathjax/MathJax.js")
937 "Options for MathJax setup.
939 path The path where to find MathJax
940 scale Scaling for the HTML-CSS backend, usually between 100 and 133
941 align How to align display math: left, center, or right
942 indent If align is not center, how far from the left/right side?
943 mathml Should a MathML player be used if available?
944 This is faster and reduces bandwidth use, but currently
945 sometimes has lower spacing quality. Therefore, the default is
946 nil. When browsers get better, this switch can be flipped.
948 You can also customize this for each buffer, using something like
950 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
951 :group
'org-export-html
952 :type
'(list :greedy t
953 (list :tag
"path (the path from where to load MathJax.js)"
954 (const :format
" " path
) (string))
955 (list :tag
"scale (scaling for the displayed math)"
956 (const :format
" " scale
) (string))
957 (list :tag
"align (alignment of displayed equations)"
958 (const :format
" " align
) (string))
959 (list :tag
"indent (indentation with left or right alignment)"
960 (const :format
" " indent
) (string))
961 (list :tag
"mathml (should MathML display be used is possible)"
962 (const :format
" " mathml
) (boolean))))
964 (defcustom org-html-mathjax-template
965 "<script type=\"text/javascript\" src=\"%PATH\">
966 <!--/*--><![CDATA[/*><!--*/
968 // Only one of the two following lines, depending on user settings
969 // First allows browser-native MathML display, second forces HTML/CSS
970 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
971 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
972 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
973 \"TeX/noUndefined.js\"],
975 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
976 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
977 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
978 ignoreClass: \"tex2jax_ignore\",
979 processEscapes: false,
980 processEnvironments: true,
983 showProcessingMessages: true,
984 displayAlign: \"%ALIGN\",
985 displayIndent: \"%INDENT\",
989 availableFonts: [\"STIX\",\"TeX\"],
990 preferredFont: \"TeX\",
1006 "The MathJax setup for XHTML files."
1007 :group
'org-export-html
1010 ;;;; Template :: Postamble
1012 (defcustom org-html-postamble
'auto
1013 "Non-nil means insert a postamble in HTML export.
1015 When set to 'auto, check against the
1016 `org-export-with-author/email/creator/date' variables to set the
1017 content of the postamble. When set to a string, use this string
1018 as the postamble. When t, insert a string as defined by the
1019 formatting string in `org-html-postamble-format'.
1021 When set to a function, apply this function and insert the
1022 returned string. The function takes the property list of export
1023 options as its only argument.
1025 Setting :html-postamble in publishing projects will take
1026 precedence over this variable."
1027 :group
'org-export-html
1028 :type
'(choice (const :tag
"No postamble" nil
)
1029 (const :tag
"Auto postamble" 'auto
)
1030 (const :tag
"Default formatting string" t
)
1031 (string :tag
"Custom formatting string")
1032 (function :tag
"Function (must return a string)")))
1034 (defcustom org-html-postamble-format
1035 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1036 <p class=\"date\">Date: %d</p>
1037 <p class=\"creator\">%c</p>
1038 <p class=\"xhtml-validation\">%v</p>"))
1039 "Alist of languages and format strings for the HTML postamble.
1041 The first element of each list is the language code, as used for
1042 the LANGUAGE keyword. See `org-export-default-language'.
1044 The second element of each list is a format string to format the
1045 postamble itself. This format string can contain these elements:
1047 %t stands for the title.
1048 %a stands for the author's name.
1049 %e stands for the author's email.
1050 %d stands for the date.
1051 %c will be replaced by `org-html-creator-string'.
1052 %v will be replaced by `org-html-validation-link'.
1053 %T will be replaced by the export time.
1054 %C will be replaced by the last modification time.
1056 If you need to use a \"%\" character, you need to escape it
1058 :group
'org-export-html
1059 :type
'(alist :key-type
(string :tag
"Language")
1060 :value-type
(string :tag
"Format string")))
1062 (defcustom org-html-validation-link
1063 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1064 "Link to HTML validation service."
1065 :group
'org-export-html
1068 (defcustom org-html-creator-string
1069 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1071 (if (fboundp 'org-version
) (org-version) "unknown version"))
1072 "Information about the creator of the HTML document.
1073 This option can also be set on with the CREATOR keyword."
1074 :group
'org-export-html
1075 :type
'(string :tag
"Creator string"))
1077 ;;;; Template :: Preamble
1079 (defcustom org-html-preamble t
1080 "Non-nil means insert a preamble in HTML export.
1082 When t, insert a string as defined by the formatting string in
1083 `org-html-preamble-format'. When set to a string, use this
1084 formatting string instead (see `org-html-postamble-format' for an
1085 example of such a formatting string).
1087 When set to a function, apply this function and insert the
1088 returned string. The function takes the property list of export
1089 options as its only argument.
1091 Setting :html-preamble in publishing projects will take
1092 precedence over this variable."
1093 :group
'org-export-html
1094 :type
'(choice (const :tag
"No preamble" nil
)
1095 (const :tag
"Default preamble" t
)
1096 (string :tag
"Custom formatting string")
1097 (function :tag
"Function (must return a string)")))
1099 (defcustom org-html-preamble-format
'(("en" ""))
1100 "Alist of languages and format strings for the HTML preamble.
1102 The first element of each list is the language code, as used for
1103 the LANGUAGE keyword. See `org-export-default-language'.
1105 The second element of each list is a format string to format the
1106 preamble itself. This format string can contain these elements:
1108 %t stands for the title.
1109 %a stands for the author's name.
1110 %e stands for the author's email.
1111 %d stands for the date.
1112 %c will be replaced by `org-html-creator-string'.
1113 %v will be replaced by `org-html-validation-link'.
1114 %T will be replaced by the export time.
1115 %C will be replaced by the last modification time.
1117 If you need to use a \"%\" character, you need to escape it
1120 See the default value of `org-html-postamble-format' for an
1122 :group
'org-export-html
1123 :type
'(alist :key-type
(string :tag
"Language")
1124 :value-type
(string :tag
"Format string")))
1126 (defcustom org-html-link-up
""
1127 "Where should the \"UP\" link of exported HTML pages lead?"
1128 :group
'org-export-html
1129 :type
'(string :tag
"File or URL"))
1131 (defcustom org-html-link-home
""
1132 "Where should the \"HOME\" link of exported HTML pages lead?"
1133 :group
'org-export-html
1134 :type
'(string :tag
"File or URL"))
1136 (defcustom org-html-home
/up-format
1137 "<div id=\"org-div-home-and-up\">
1138 <a accesskey=\"h\" href=\"%s\"> UP </a>
1140 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1142 "Snippet used to insert the HOME and UP links.
1143 This is a format string, the first %s will receive the UP link,
1144 the second the HOME link. If both `org-html-link-up' and
1145 `org-html-link-home' are empty, the entire snippet will be
1147 :group
'org-export-html
1150 ;;;; Template :: Scripts
1152 (define-obsolete-variable-alias
1153 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1154 (defcustom org-html-head-include-scripts t
1155 "Non-nil means include the JavaScript snippets in exported HTML files.
1156 The actual script is defined in `org-html-scripts' and should
1158 :group
'org-export-html
1160 :package-version
'(Org .
"8.0")
1163 ;;;; Template :: Styles
1165 (define-obsolete-variable-alias
1166 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1167 (defcustom org-html-head-include-default-style t
1168 "Non-nil means include the default style in exported HTML files.
1169 The actual style is defined in `org-html-style-default' and
1170 should not be modified. Use `org-html-head' to use your own
1172 :group
'org-export-html
1174 :package-version
'(Org .
"8.0")
1177 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1179 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1180 (defcustom org-html-head
""
1181 "Org-wide head definitions for exported HTML files.
1183 This variable can contain the full HTML structure to provide a
1184 style, including the surrounding HTML tags. You can consider
1185 including definitions for the following classes: title, todo,
1186 done, timestamp, timestamp-kwd, tag, target.
1188 For example, a valid value would be:
1190 <style type=\"text/css\">
1192 p { font-weight: normal; color: gray; }
1193 h1 { color: black; }
1194 .title { text-align: center; }
1195 .todo, .timestamp-kwd { color: red; }
1196 .done { color: green; }
1200 If you want to refer to an external style, use something like
1202 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1204 As the value of this option simply gets inserted into the HTML
1205 <head> header, you can use it to add any arbitrary text to the
1208 You can set this on a per-file basis using #+HTML_HEAD:,
1209 or for publication projects using the :html-head property."
1210 :group
'org-export-html
1212 :package-version
'(Org .
"8.0")
1215 (put 'org-html-head
'safe-local-variable
'stringp
)
1217 (defcustom org-html-head-extra
""
1218 "More head information to add in the HTML output.
1220 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1221 or for publication projects using the :html-head-extra property."
1222 :group
'org-export-html
1224 :package-version
'(Org .
"8.0")
1227 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1231 (defcustom org-html-todo-kwd-class-prefix
""
1232 "Prefix to class names for TODO keywords.
1233 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1234 The default prefix is empty because it is nice to just use the keyword
1235 as a class name. But if you get into conflicts with other, existing
1236 CSS classes, then this prefix can be very useful."
1237 :group
'org-export-html
1241 ;;; Internal Functions
1243 (defun org-html--make-attribute-string (attributes)
1244 "Return a list of attributes, as a string.
1245 ATTRIBUTES is a plist where values are either strings or nil. An
1246 attributes with a nil value will be omitted from the result."
1248 (dolist (item attributes
(mapconcat 'identity
(nreverse output
) " "))
1249 (cond ((null item
) (pop output
))
1250 ((symbolp item
) (push (substring (symbol-name item
) 1) output
))
1251 (t (let ((key (car output
))
1252 (value (replace-regexp-in-string
1253 "\"" """ (org-html-encode-plain-text item
))))
1254 (setcar output
(format "%s=\"%s\"" key value
))))))))
1256 (defun org-html-format-inline-image (src &optional
1257 caption label attr standalone-p
)
1258 "Format an inline image from SRC.
1259 CAPTION, LABEL and ATTR are optional arguments providing the
1260 caption, the label and the attribute of the image.
1261 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1262 (let* ((id (if (not label
) ""
1263 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1266 ((string-match "\\<alt=" (or attr
"")) "")
1267 ((string-match "^ltxpng/" src
)
1268 (format " alt=\"%s\""
1269 (org-html-encode-plain-text
1270 (org-find-text-property-in-string
1271 'org-latex-src src
))))
1272 (t (format " alt=\"%s\""
1273 (file-name-nondirectory src
)))))))
1276 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1277 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1278 id
(format "\n<p>%s</p>" img
)
1279 (if (and caption
(not (string= caption
"")))
1280 (format "\n<p>%s</p>" caption
) ""))))
1281 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1283 (defun org-html--textarea-block (element)
1284 "Transcode ELEMENT into a textarea block.
1285 ELEMENT is either a src block or an example block."
1286 (let* ((code (car (org-export-unravel-code element
)))
1287 (attr (org-export-read-attribute :attr_html element
)))
1288 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1289 (or (plist-get attr
:width
) 80)
1290 (or (plist-get attr
:height
) (org-count-lines code
))
1295 (defun org-html-htmlize-region-for-paste (beg end
)
1296 "Convert the region between BEG and END to HTML, using htmlize.el.
1297 This is much like `htmlize-region-for-paste', only that it uses
1298 the settings define in the org-... variables."
1299 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1300 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1301 (htmlbuf (htmlize-region beg end
)))
1303 (with-current-buffer htmlbuf
1304 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1305 (plist-get htmlize-buffer-places
'content-end
)))
1306 (kill-buffer htmlbuf
))))
1309 (defun org-html-htmlize-generate-css ()
1310 "Create the CSS for all font definitions in the current Emacs session.
1311 Use this to create face definitions in your CSS style file that can then
1312 be used by code snippets transformed by htmlize.
1313 This command just produces a buffer that contains class definitions for all
1314 faces used in the current Emacs session. You can copy and paste the ones you
1315 need into your CSS file.
1317 If you then set `org-html-htmlize-output-type' to `css', calls
1318 to the function `org-html-htmlize-region-for-paste' will
1319 produce code that uses these same face definitions."
1322 (and (get-buffer "*html*") (kill-buffer "*html*"))
1324 (let ((fl (face-list))
1325 (htmlize-css-name-prefix "org-")
1326 (htmlize-output-type 'css
)
1328 (while (setq f
(pop fl
)
1329 i
(and f
(face-attribute f
:inherit
)))
1330 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1331 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1332 (htmlize-region (point-min) (point-max))))
1333 (org-pop-to-buffer-same-window "*html*")
1334 (goto-char (point-min))
1335 (if (re-search-forward "<style" nil t
)
1336 (delete-region (point-min) (match-beginning 0)))
1337 (if (re-search-forward "</style>" nil t
)
1338 (delete-region (1+ (match-end 0)) (point-max)))
1339 (beginning-of-line 1)
1340 (if (looking-at " +") (replace-match ""))
1341 (goto-char (point-min)))
1343 (defun org-html--make-string (n string
)
1344 "Build a string by concatenating N times STRING."
1345 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1347 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1348 "Turn todo keyword KWD into a valid class name.
1349 Replaces invalid characters with \"_\"."
1351 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1352 (setq kwd
(replace-match "_" t t kwd
))))
1355 (defun org-html-format-footnote-reference (n def refcnt
)
1356 "Format footnote reference N with definition DEF into HTML."
1357 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1358 (format org-html-footnote-format
1359 (let* ((id (format "fnr.%s%s" n extra
))
1360 (href (format " href=\"#fn.%s\"" n
))
1361 (attributes (concat " class=\"footref\"" href
)))
1362 (org-html--anchor id n attributes
)))))
1364 (defun org-html-format-footnotes-section (section-name definitions
)
1365 "Format footnotes section SECTION-NAME."
1366 (if (not definitions
) ""
1367 (format org-html-footnotes-section section-name definitions
)))
1369 (defun org-html-format-footnote-definition (fn)
1370 "Format the footnote definition FN."
1371 (let ((n (car fn
)) (def (cdr fn
)))
1373 "<div class=\"footdef\">%s %s</div>\n"
1374 (format org-html-footnote-format
1375 (let* ((id (format "fn.%s" n
))
1376 (href (format " href=\"#fnr.%s\"" n
))
1377 (attributes (concat " class=\"footnum\"" href
)))
1378 (org-html--anchor id n attributes
)))
1381 (defun org-html-footnote-section (info)
1382 "Format the footnote section.
1383 INFO is a plist used as a communication channel."
1384 (let* ((fn-alist (org-export-collect-footnote-definitions
1385 (plist-get info
:parse-tree
) info
))
1387 (loop for
(n type raw
) in fn-alist collect
1388 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1389 (org-trim (org-export-data raw info
))
1391 (org-trim (org-export-data raw info
))))))))
1393 (org-html-format-footnotes-section
1394 (org-html--translate "Footnotes" info
)
1397 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1402 (defun org-html--build-meta-info (info)
1403 "Return meta tags for exported document.
1404 INFO is a plist used as a communication channel."
1405 (let ((protect-string
1407 (replace-regexp-in-string
1408 "\"" """ (org-html-encode-plain-text str
))))
1409 (title (org-export-data (plist-get info
:title
) info
))
1410 (author (and (plist-get info
:with-author
)
1411 (let ((auth (plist-get info
:author
)))
1413 ;; Return raw Org syntax, skipping non
1414 ;; exportable objects.
1415 (org-element-interpret-data
1416 (org-element-map auth
1417 (cons 'plain-text org-element-all-objects
)
1418 'identity info
))))))
1419 (description (plist-get info
:description
))
1420 (keywords (plist-get info
:keywords
)))
1422 (format "<title>%s</title>\n" title
)
1423 (when (plist-get info
:time-stamp-file
)
1425 (concat "<!-- " org-html-metadata-timestamp-format
" -->\n")))
1427 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1428 (or (and org-html-coding-system
1429 (fboundp 'coding-system-get
)
1430 (coding-system-get org-html-coding-system
'mime-charset
))
1432 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1433 (and (org-string-nw-p author
)
1434 (format "<meta name=\"author\" content=\"%s\"/>\n"
1435 (funcall protect-string author
)))
1436 (and (org-string-nw-p description
)
1437 (format "<meta name=\"description\" content=\"%s\"/>\n"
1438 (funcall protect-string description
)))
1439 (and (org-string-nw-p keywords
)
1440 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1441 (funcall protect-string keywords
))))))
1443 (defun org-html--build-head (info)
1444 "Return information for the <head>..</head> of the HTML output.
1445 INFO is a plist used as a communication channel."
1446 (org-element-normalize-string
1448 (when (plist-get info
:html-head-include-default-style
)
1449 (org-element-normalize-string org-html-style-default
))
1450 (org-element-normalize-string (plist-get info
:html-head
))
1451 (org-element-normalize-string (plist-get info
:html-head-extra
))
1452 (when (and (plist-get info
:html-htmlized-css-url
)
1453 (eq org-html-htmlize-output-type
'css
))
1454 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1455 (plist-get info
:html-htmlized-css-url
)))
1456 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1458 (defun org-html--build-mathjax-config (info)
1459 "Insert the user setup into the mathjax template.
1460 INFO is a plist used as a communication channel."
1461 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1462 (org-element-map (plist-get info
:parse-tree
)
1463 '(latex-fragment latex-environment
) 'identity info t
))
1464 (let ((template org-html-mathjax-template
)
1465 (options org-html-mathjax-options
)
1466 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1467 name val
(yes " ") (no "// ") x
)
1470 (setq name
(car e
) val
(nth 1 e
))
1471 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1472 (setq val
(car (read-from-string
1473 (substring in-buffer
(match-end 0))))))
1474 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1475 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1476 (setq template
(replace-match val t t template
))))
1478 (setq val
(nth 1 (assq 'mathml options
)))
1479 (if (string-match (concat "\\<mathml:") in-buffer
)
1480 (setq val
(car (read-from-string
1481 (substring in-buffer
(match-end 0))))))
1482 ;; Exchange prefixes depending on mathml setting.
1483 (if (not val
) (setq x yes yes no no x
))
1484 ;; Replace cookies to turn on or off the config/jax lines.
1485 (if (string-match ":MMLYES:" template
)
1486 (setq template
(replace-match yes t t template
)))
1487 (if (string-match ":MMLNO:" template
)
1488 (setq template
(replace-match no t t template
)))
1489 ;; Return the modified template.
1490 (org-element-normalize-string template
))))
1492 (defun org-html-format-spec (info)
1493 "Return format specification for elements that can be
1494 used in the preamble or postamble."
1495 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1496 (?d .
,(org-export-data (org-export-get-date info
) info
))
1497 (?T .
,(format-time-string org-html-metadata-timestamp-format
))
1498 (?a .
,(org-export-data (plist-get info
:author
) info
))
1501 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1502 (split-string (plist-get info
:email
) ",+ *")
1504 (?c .
,(plist-get info
:creator
))
1505 (?C .
,(let ((file (plist-get info
:input-file
)))
1506 (format-time-string org-html-metadata-timestamp-format
1507 (if file
(nth 5 (file-attributes file
))
1509 (?v .
,(or org-html-validation-link
""))))
1511 (defun org-html--build-pre/postamble
(type info
)
1512 "Return document preamble or postamble as a string, or nil.
1513 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1514 communication channel."
1515 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1516 (spec (org-html-format-spec info
)))
1518 (let ((section-contents
1519 (if (functionp section
) (funcall section info
)
1521 ((stringp section
) (format-spec section spec
))
1523 (let ((date (cdr (assq ?d spec
)))
1524 (author (cdr (assq ?a spec
)))
1525 (email (cdr (assq ?e spec
)))
1526 (creator (cdr (assq ?c spec
)))
1527 (timestamp (cdr (assq ?T spec
)))
1528 (validation-link (cdr (assq ?v spec
))))
1530 (when (and (plist-get info
:with-date
)
1531 (org-string-nw-p date
))
1532 (format "<p class=\"date\">%s: %s</p>\n"
1533 (org-html--translate "Date" info
)
1535 (when (and (plist-get info
:with-author
)
1536 (org-string-nw-p author
))
1537 (format "<p class=\"author\">%s: %s</p>\n"
1538 (org-html--translate "Author" info
)
1540 (when (and (plist-get info
:with-email
)
1541 (org-string-nw-p email
))
1542 (format "<p class=\"email\">%s: %s</p>\n"
1543 (org-html--translate "Email" info
)
1545 (when (plist-get info
:time-stamp-file
)
1547 "<p class=\"date\">%s: %s</p>\n"
1548 (org-html--translate "Created" info
)
1549 (format-time-string org-html-metadata-timestamp-format
)))
1550 (when (plist-get info
:with-creator
)
1551 (format "<p class=\"creator\">%s</p>\n" creator
))
1552 (format "<p class=\"xhtml-validation\">%s</p>\n"
1556 (plist-get info
:language
)
1558 (format "org-html-%s-format" type
)))))
1563 (intern (format "org-html-%s-format" type
))))))
1565 (when (org-string-nw-p section-contents
)
1567 (format "<%s id=\"%s\" class=\"%s\">\n"
1568 (nth 1 (assq type org-html-divs
))
1569 (nth 2 (assq type org-html-divs
))
1570 org-html--pre
/postamble-class
)
1571 (org-element-normalize-string section-contents
)
1572 (format "</%s>\n" (nth 1 (assq type org-html-divs
)))))))))
1574 (defun org-html-inner-template (contents info
)
1575 "Return body of document string after HTML conversion.
1576 CONTENTS is the transcoded contents string. INFO is a plist
1577 holding export options."
1579 ;; Table of contents.
1580 (let ((depth (plist-get info
:with-toc
)))
1581 (when depth
(org-html-toc depth info
)))
1582 ;; Document contents.
1584 ;; Footnotes section.
1585 (org-html-footnote-section info
)))
1587 (defun org-html-template (contents info
)
1588 "Return complete document string after HTML conversion.
1589 CONTENTS is the transcoded contents string. INFO is a plist
1590 holding export options."
1593 (or (and (stringp org-html-xml-declaration
)
1594 org-html-xml-declaration
)
1595 (cdr (assoc (plist-get info
:html-extension
)
1596 org-html-xml-declaration
))
1597 (cdr (assoc "html" org-html-xml-declaration
))
1600 (or (and org-html-coding-system
1601 (fboundp 'coding-system-get
)
1602 (coding-system-get org-html-coding-system
'mime-charset
))
1605 (plist-get info
:html-doctype
)
1607 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1608 (plist-get info
:language
) (plist-get info
:language
))
1610 (org-html--build-meta-info info
)
1611 (org-html--build-head info
)
1612 (org-html--build-mathjax-config info
)
1615 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1616 (link-home (org-trim (plist-get info
:html-link-home
))))
1617 (unless (and (string= link-up
"") (string= link-home
""))
1618 (format org-html-home
/up-format
1619 (or link-up link-home
)
1620 (or link-home link-up
))))
1622 (org-html--build-pre/postamble
'preamble info
)
1623 ;; Document contents.
1624 (format "<%s id=\"%s\">\n"
1625 (nth 1 (assq 'content org-html-divs
))
1626 (nth 2 (assq 'content org-html-divs
)))
1628 (let ((title (plist-get info
:title
)))
1629 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1632 (nth 1 (assq 'content org-html-divs
)))
1634 (org-html--build-pre/postamble
'postamble info
)
1635 ;; Closing document.
1636 "</body>\n</html>"))
1638 (defun org-html--translate (s info
)
1639 "Translate string S according to specified language.
1640 INFO is a plist used as a communication channel."
1641 (org-export-translate s
:html info
))
1645 (defun org-html--anchor (&optional id desc attributes
)
1646 "Format a HTML anchor."
1647 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1648 (attributes (concat (and id
(format " id=\"%s\"" id
))
1649 (and name
(format " name=\"%s\"" name
))
1651 (format "<a%s>%s</a>" attributes
(or desc
""))))
1655 (defun org-html--todo (todo)
1656 "Format TODO keywords into HTML."
1658 (format "<span class=\"%s %s%s\">%s</span>"
1659 (if (member todo org-done-keywords
) "done" "todo")
1660 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1665 (defun org-html--tags (tags)
1666 "Format TAGS into HTML."
1668 (format "<span class=\"tag\">%s</span>"
1671 (format "<span class=\"%s\">%s</span>"
1672 (concat org-html-tag-class-prefix
1673 (org-html-fix-class-name tag
))
1679 (defun* org-html-format-headline
1680 (todo todo-type priority text tags
1681 &key level section-number headline-label
&allow-other-keys
)
1682 "Format a headline in HTML."
1683 (let ((section-number
1684 (when section-number
1685 (format "<span class=\"section-number-%d\">%s</span> "
1686 level section-number
)))
1687 (todo (org-html--todo todo
))
1688 (tags (org-html--tags tags
)))
1689 (concat section-number todo
(and todo
" ") text
1690 (and tags
"   ") tags
)))
1694 (defun org-html-fontify-code (code lang
)
1695 "Color CODE with htmlize library.
1696 CODE is a string representing the source code to colorize. LANG
1697 is the language used for CODE, as a string, or nil."
1700 ;; Case 1: No lang. Possibly an example block.
1702 ;; Simple transcoding.
1703 (org-html-encode-plain-text code
))
1704 ;; Case 2: No htmlize or an inferior version of htmlize
1705 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1707 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1708 ;; Simple transcoding.
1709 (org-html-encode-plain-text code
))
1712 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1713 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1715 ;; Case 1: Language is not associated with any Emacs mode
1716 ((not (functionp lang-mode
))
1717 ;; Simple transcoding.
1718 (org-html-encode-plain-text code
))
1719 ;; Case 2: Default. Fontify code.
1722 (setq code
(with-temp-buffer
1723 ;; Switch to language-specific mode.
1727 (font-lock-fontify-buffer)
1728 ;; Remove formatting on newline characters.
1730 (let ((beg (point-min))
1733 (while (progn (end-of-line) (< (point) end
))
1734 (put-text-property (point) (1+ (point)) 'face nil
)
1737 (set-buffer-modified-p nil
)
1739 (org-html-htmlize-region-for-paste
1740 (point-min) (point-max))))
1741 ;; Strip any enclosing <pre></pre> tags.
1742 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1743 (end (and beg
(string-match "</pre>\\'" code
))))
1744 (if (and beg end
) (substring code beg end
) code
)))))))))
1746 (defun org-html-do-format-code
1747 (code &optional lang refs retain-labels num-start
)
1748 "Format CODE string as source code.
1749 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1750 respectively, the language of the source code, as a string, an
1751 alist between line numbers and references (as returned by
1752 `org-export-unravel-code'), a boolean specifying if labels should
1753 appear in the source code, and the number associated to the first
1755 (let* ((code-lines (org-split-string code
"\n"))
1756 (code-length (length code-lines
))
1760 (length (number-to-string (+ code-length num-start
))))))
1761 (code (org-html-fontify-code code lang
)))
1762 (org-export-format-code
1764 (lambda (loc line-num ref
)
1767 ;; Add line number, if needed.
1769 (format "<span class=\"linenr\">%s</span>"
1770 (format num-fmt line-num
)))
1771 ;; Transcoded src line.
1773 ;; Add label, if needed.
1774 (when (and ref retain-labels
) (format " (%s)" ref
))))
1775 ;; Mark transcoded line as an anchor, if needed.
1777 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1781 (defun org-html-format-code (element info
)
1782 "Format contents of ELEMENT as source code.
1783 ELEMENT is either an example block or a src block. INFO is
1784 a plist used as a communication channel."
1785 (let* ((lang (org-element-property :language element
))
1786 ;; Extract code and references.
1787 (code-info (org-export-unravel-code element
))
1788 (code (car code-info
))
1789 (refs (cdr code-info
))
1790 ;; Does the src block contain labels?
1791 (retain-labels (org-element-property :retain-labels element
))
1792 ;; Does it have line numbers?
1793 (num-start (case (org-element-property :number-lines element
)
1794 (continued (org-export-get-loc element info
))
1796 (org-html-do-format-code code lang refs retain-labels num-start
)))
1799 ;;; Tables of Contents
1801 (defun org-html-toc (depth info
)
1802 "Build a table of contents.
1803 DEPTH is an integer specifying the depth of the table. INFO is a
1804 plist used as a communication channel. Return the table of
1805 contents as a string, or nil if it is empty."
1807 (mapcar (lambda (headline)
1808 (cons (org-html--format-toc-headline headline info
)
1809 (org-export-get-relative-level headline info
)))
1810 (org-export-collect-headlines info depth
))))
1812 (concat "<div id=\"table-of-contents\">\n"
1813 (format "<h%d>%s</h%d>\n"
1814 org-html-toplevel-hlevel
1815 (org-html--translate "Table of Contents" info
)
1816 org-html-toplevel-hlevel
)
1817 "<div id=\"text-table-of-contents\">"
1818 (org-html--toc-text toc-entries
)
1822 (defun org-html--toc-text (toc-entries)
1823 "Return innards of a table of contents, as a string.
1824 TOC-ENTRIES is an alist where key is an entry title, as a string,
1825 and value is its relative level, as an integer."
1826 (let* ((prev-level (1- (cdar toc-entries
)))
1827 (start-level prev-level
))
1831 (let ((headline (car entry
))
1832 (level (cdr entry
)))
1834 (let* ((cnt (- level prev-level
))
1835 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1837 (setq prev-level level
)
1839 (org-html--make-string
1840 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1841 ((< cnt
0) "</li>\n</ul>\n")))
1842 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1845 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1847 (defun org-html--format-toc-headline (headline info
)
1848 "Return an appropriate table of contents entry for HEADLINE.
1849 INFO is a plist used as a communication channel."
1850 (let* ((headline-number (org-export-get-headline-number headline info
))
1852 (and (not (org-export-low-level-p headline info
))
1853 (org-export-numbered-headline-p headline info
)
1854 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1855 (tags (and (eq (plist-get info
:with-tags
) t
)
1856 (org-export-get-tags headline info
))))
1857 (format "<a href=\"#%s\">%s</a>"
1859 (org-export-solidify-link-text
1860 (or (org-element-property :CUSTOM_ID headline
)
1861 (concat "sec-" (mapconcat 'number-to-string
1862 headline-number
"-"))))
1864 (concat section-number
1865 (org-export-data-with-translations
1866 (org-export-get-alt-title headline info
)
1867 ;; Ignore any footnote-reference, link,
1868 ;; radio-target and target in table of contents.
1870 '((footnote-reference . ignore
)
1871 (link .
(lambda (link desc i
) desc
))
1872 (radio-target .
(lambda (radio desc i
) desc
))
1874 (org-export-backend-translate-table 'html
))
1876 (and tags
"   ") (org-html--tags tags
)))))
1878 (defun org-html-list-of-listings (info)
1879 "Build a list of listings.
1880 INFO is a plist used as a communication channel. Return the list
1881 of listings as a string, or nil if it is empty."
1882 (let ((lol-entries (org-export-collect-listings info
)))
1884 (concat "<div id=\"list-of-listings\">\n"
1885 (format "<h%d>%s</h%d>\n"
1886 org-html-toplevel-hlevel
1887 (org-html--translate "List of Listings" info
)
1888 org-html-toplevel-hlevel
)
1889 "<div id=\"text-list-of-listings\">\n<ul>\n"
1891 (initial-fmt (org-html--translate "Listing %d:" info
)))
1894 (let ((label (org-element-property :name entry
))
1897 (or (org-export-get-caption entry t
)
1898 (org-export-get-caption entry
))
1903 (concat (format initial-fmt
(incf count
)) " " title
)
1904 (format "<a href=\"#%s\">%s %s</a>"
1905 (org-export-solidify-link-text label
)
1906 (format initial-fmt
(incf count
))
1910 "\n</ul>\n</div>\n</div>"))))
1912 (defun org-html-list-of-tables (info)
1913 "Build a list of tables.
1914 INFO is a plist used as a communication channel. Return the list
1915 of tables as a string, or nil if it is empty."
1916 (let ((lol-entries (org-export-collect-tables info
)))
1918 (concat "<div id=\"list-of-tables\">\n"
1919 (format "<h%d>%s</h%d>\n"
1920 org-html-toplevel-hlevel
1921 (org-html--translate "List of Tables" info
)
1922 org-html-toplevel-hlevel
)
1923 "<div id=\"text-list-of-tables\">\n<ul>\n"
1925 (initial-fmt (org-html--translate "Table %d:" info
)))
1928 (let ((label (org-element-property :name entry
))
1931 (or (org-export-get-caption entry t
)
1932 (org-export-get-caption entry
))
1937 (concat (format initial-fmt
(incf count
)) " " title
)
1938 (format "<a href=\"#%s\">%s %s</a>"
1939 (org-export-solidify-link-text label
)
1940 (format initial-fmt
(incf count
))
1944 "\n</ul>\n</div>\n</div>"))))
1947 ;;; Transcode Functions
1951 (defun org-html-bold (bold contents info
)
1952 "Transcode BOLD from Org to HTML.
1953 CONTENTS is the text with bold markup. INFO is a plist holding
1954 contextual information."
1955 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1960 (defun org-html-center-block (center-block contents info
)
1961 "Transcode a CENTER-BLOCK element from Org to HTML.
1962 CONTENTS holds the contents of the block. INFO is a plist
1963 holding contextual information."
1964 (format "<div class=\"center\">\n%s</div>" contents
))
1968 (defun org-html-clock (clock contents info
)
1969 "Transcode a CLOCK element from Org to HTML.
1970 CONTENTS is nil. INFO is a plist used as a communication
1973 <span class=\"timestamp-wrapper\">
1974 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1979 (org-element-property :raw-value
1980 (org-element-property :value clock
)))
1981 (let ((time (org-element-property :duration clock
)))
1982 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1986 (defun org-html-code (code contents info
)
1987 "Transcode CODE from Org to HTML.
1988 CONTENTS is nil. INFO is a plist holding contextual
1990 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
1991 (org-html-encode-plain-text (org-element-property :value code
))))
1995 (defun org-html-drawer (drawer contents info
)
1996 "Transcode a DRAWER element from Org to HTML.
1997 CONTENTS holds the contents of the block. INFO is a plist
1998 holding contextual information."
1999 (if (functionp org-html-format-drawer-function
)
2000 (funcall org-html-format-drawer-function
2001 (org-element-property :drawer-name drawer
)
2003 ;; If there's no user defined function: simply
2004 ;; display contents of the drawer.
2009 (defun org-html-dynamic-block (dynamic-block contents info
)
2010 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2011 CONTENTS holds the contents of the block. INFO is a plist
2012 holding contextual information. See `org-export-data'."
2017 (defun org-html-entity (entity contents info
)
2018 "Transcode an ENTITY object from Org to HTML.
2019 CONTENTS are the definition itself. INFO is a plist holding
2020 contextual information."
2021 (org-element-property :html entity
))
2025 (defun org-html-example-block (example-block contents info
)
2026 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2027 CONTENTS is nil. INFO is a plist holding contextual
2029 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2030 (org-html--textarea-block example-block
)
2031 (format "<pre class=\"example\">\n%s</pre>"
2032 (org-html-format-code example-block info
))))
2036 (defun org-html-export-snippet (export-snippet contents info
)
2037 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2038 CONTENTS is nil. INFO is a plist holding contextual
2040 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2041 (org-element-property :value export-snippet
)))
2045 (defun org-html-export-block (export-block contents info
)
2046 "Transcode a EXPORT-BLOCK element from Org to HTML.
2047 CONTENTS is nil. INFO is a plist holding contextual information."
2048 (when (string= (org-element-property :type export-block
) "HTML")
2049 (org-remove-indentation (org-element-property :value export-block
))))
2053 (defun org-html-fixed-width (fixed-width contents info
)
2054 "Transcode a FIXED-WIDTH element from Org to HTML.
2055 CONTENTS is nil. INFO is a plist holding contextual information."
2056 (format "<pre class=\"example\">\n%s</pre>"
2057 (org-html-do-format-code
2058 (org-remove-indentation
2059 (org-element-property :value fixed-width
)))))
2061 ;;;; Footnote Reference
2063 (defun org-html-footnote-reference (footnote-reference contents info
)
2064 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2065 CONTENTS is nil. INFO is a plist holding contextual information."
2067 ;; Insert separator between two footnotes in a row.
2068 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2069 (when (eq (org-element-type prev
) 'footnote-reference
)
2070 org-html-footnote-separator
))
2072 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2073 (org-html-format-footnote-reference
2074 (org-export-get-footnote-number footnote-reference info
)
2076 ;; Inline definitions are secondary strings.
2077 ((eq (org-element-property :type footnote-reference
) 'inline
)
2078 (org-html-format-footnote-reference
2079 (org-export-get-footnote-number footnote-reference info
)
2081 ;; Non-inline footnotes definitions are full Org data.
2082 (t (org-html-format-footnote-reference
2083 (org-export-get-footnote-number footnote-reference info
)
2088 (defun org-html-format-headline--wrap
2089 (headline info
&optional format-function
&rest extra-keys
)
2090 "Transcode a HEADLINE element from Org to HTML.
2091 CONTENTS holds the contents of the headline. INFO is a plist
2092 holding contextual information."
2093 (let* ((level (+ (org-export-get-relative-level headline info
)
2094 (1- org-html-toplevel-hlevel
)))
2095 (headline-number (org-export-get-headline-number headline info
))
2096 (section-number (and (not (org-export-low-level-p headline info
))
2097 (org-export-numbered-headline-p headline info
)
2098 (mapconcat 'number-to-string
2099 headline-number
".")))
2100 (todo (and (plist-get info
:with-todo-keywords
)
2101 (let ((todo (org-element-property :todo-keyword headline
)))
2102 (and todo
(org-export-data todo info
)))))
2103 (todo-type (and todo
(org-element-property :todo-type headline
)))
2104 (priority (and (plist-get info
:with-priority
)
2105 (org-element-property :priority headline
)))
2106 (text (org-export-data (org-element-property :title headline
) info
))
2107 (tags (and (plist-get info
:with-tags
)
2108 (org-export-get-tags headline info
)))
2109 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2110 (concat "sec-" (mapconcat 'number-to-string
2111 headline-number
"-"))))
2112 (format-function (cond
2113 ((functionp format-function
) format-function
)
2114 ((functionp org-html-format-headline-function
)
2116 (lambda (todo todo-type priority text tags
2118 (funcall org-html-format-headline-function
2119 todo todo-type priority text tags
))))
2120 (t 'org-html-format-headline
))))
2121 (apply format-function
2122 todo todo-type priority text tags
2123 :headline-label headline-label
:level level
2124 :section-number section-number extra-keys
)))
2126 (defun org-html-headline (headline contents info
)
2127 "Transcode a HEADLINE element from Org to HTML.
2128 CONTENTS holds the contents of the headline. INFO is a plist
2129 holding contextual information."
2131 (setq contents
(or contents
""))
2132 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2133 (level (org-export-get-relative-level headline info
))
2134 (text (org-export-data (org-element-property :title headline
) info
))
2135 (todo (and (plist-get info
:with-todo-keywords
)
2136 (let ((todo (org-element-property :todo-keyword headline
)))
2137 (and todo
(org-export-data todo info
)))))
2138 (todo-type (and todo
(org-element-property :todo-type headline
)))
2139 (tags (and (plist-get info
:with-tags
)
2140 (org-export-get-tags headline info
)))
2141 (priority (and (plist-get info
:with-priority
)
2142 (org-element-property :priority headline
)))
2143 (section-number (and (org-export-numbered-headline-p headline info
)
2144 (mapconcat 'number-to-string
2145 (org-export-get-headline-number
2146 headline info
) ".")))
2147 ;; Create the headline text.
2148 (full-text (org-html-format-headline--wrap headline info
)))
2150 ;; Case 1: This is a footnote section: ignore it.
2151 ((org-element-property :footnote-section-p headline
) nil
)
2152 ;; Case 2. This is a deep sub-tree: export it as a list item.
2153 ;; Also export as items headlines for which no section
2154 ;; format has been found.
2155 ((org-export-low-level-p headline info
)
2156 ;; Build the real contents of the sub-tree.
2157 (let* ((type (if numberedp
'ordered
'unordered
))
2158 (itemized-body (org-html-format-list-item
2159 contents type nil nil full-text
)))
2161 (and (org-export-first-sibling-p headline info
)
2162 (org-html-begin-plain-list type
))
2164 (and (org-export-last-sibling-p headline info
)
2165 (org-html-end-plain-list type
)))))
2166 ;; Case 3. Standard headline. Export it as a section.
2168 (let* ((section-number (mapconcat 'number-to-string
2169 (org-export-get-headline-number
2170 headline info
) "-"))
2172 (list (org-element-property :CUSTOM_ID headline
)
2173 (concat "sec-" section-number
)
2174 (org-element-property :ID headline
))))
2175 (preferred-id (car ids
))
2176 (extra-ids (cdr ids
))
2177 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2178 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2179 (first-content (car (org-element-contents headline
))))
2180 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2181 (org-html--container headline info
)
2182 (format "outline-container-%s"
2183 (or (org-element-property :CUSTOM_ID headline
)
2184 (concat "sec-" section-number
)))
2185 (concat (format "outline-%d" level1
) (and extra-class
" ")
2187 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2192 (let ((id (org-export-solidify-link-text
2193 (if (org-uuidgen-p x
) (concat "ID-" x
)
2195 (org-html--anchor id
)))
2199 ;; When there is no section, pretend there is an empty
2200 ;; one to get the correct <div class="outline- ...>
2201 ;; which is needed by `org-info.js'.
2202 (if (not (eq (org-element-type first-content
) 'section
))
2203 (concat (org-html-section first-content
"" info
)
2206 (org-html--container headline info
)))))))
2208 (defun org-html--container (headline info
)
2209 (or (org-element-property :HTML_CONTAINER headline
)
2210 (if (= 1 (org-export-get-relative-level headline info
))
2211 (plist-get info
:html-container
)
2214 ;;;; Horizontal Rule
2216 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2217 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2218 CONTENTS is nil. INFO is a plist holding contextual information."
2221 ;;;; Inline Src Block
2223 (defun org-html-inline-src-block (inline-src-block contents info
)
2224 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2225 CONTENTS holds the contents of the item. INFO is a plist holding
2226 contextual information."
2227 (let* ((org-lang (org-element-property :language inline-src-block
))
2228 (code (org-element-property :value inline-src-block
)))
2229 (error "Cannot export inline src block")))
2233 (defun org-html-format-section (text class
&optional id
)
2234 "Format a section with TEXT into a HTML div with CLASS and ID."
2235 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2236 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2238 (defun org-html-inlinetask (inlinetask contents info
)
2239 "Transcode an INLINETASK element from Org to HTML.
2240 CONTENTS holds the contents of the block. INFO is a plist
2241 holding contextual information."
2243 ;; If `org-html-format-inlinetask-function' is provided, call it
2244 ;; with appropriate arguments.
2245 ((functionp org-html-format-inlinetask-function
)
2246 (let ((format-function
2248 (lambda (todo todo-type priority text tags
2249 &key contents
&allow-other-keys
)
2250 (funcall org-html-format-inlinetask-function
2251 todo todo-type priority text tags contents
)))))
2252 (org-html-format-headline--wrap
2253 inlinetask info format-function
:contents contents
)))
2254 ;; Otherwise, use a default template.
2255 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2256 (org-html-format-headline--wrap inlinetask info
)
2261 (defun org-html-italic (italic contents info
)
2262 "Transcode ITALIC from Org to HTML.
2263 CONTENTS is the text with italic markup. INFO is a plist holding
2264 contextual information."
2265 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2269 (defun org-html-checkbox (checkbox)
2270 "Format CHECKBOX into HTML."
2271 (case checkbox
(on "<code>[X]</code>")
2272 (off "<code>[ ]</code>")
2273 (trans "<code>[-]</code>")
2276 (defun org-html-format-list-item (contents type checkbox
2277 &optional term-counter-id
2279 "Format a list item into HTML."
2280 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2284 (let* ((counter term-counter-id
)
2285 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2287 (format "<li%s>" extra
)
2288 (when headline
(concat headline
"<br/>")))))
2290 (let* ((id term-counter-id
)
2291 (extra (if id
(format " id=\"%s\"" id
) "")))
2293 (format "<li%s>" extra
)
2294 (when headline
(concat headline
"<br/>")))))
2296 (let* ((term term-counter-id
))
2297 (setq term
(or term
"(no term)"))
2298 ;; Check-boxes in descriptive lists are associated to tag.
2299 (concat (format "<dt> %s </dt>"
2300 (concat checkbox term
))
2302 (unless (eq type
'descriptive
) checkbox
)
2307 (descriptive "</dd>")))))
2309 (defun org-html-item (item contents info
)
2310 "Transcode an ITEM element from Org to HTML.
2311 CONTENTS holds the contents of the item. INFO is a plist holding
2312 contextual information."
2313 (let* ((plain-list (org-export-get-parent item
))
2314 (type (org-element-property :type plain-list
))
2315 (counter (org-element-property :counter item
))
2316 (checkbox (org-element-property :checkbox item
))
2317 (tag (let ((tag (org-element-property :tag item
)))
2318 (and tag
(org-export-data tag info
)))))
2319 (org-html-format-list-item
2320 contents type checkbox
(or tag counter
))))
2324 (defun org-html-keyword (keyword contents info
)
2325 "Transcode a KEYWORD element from Org to HTML.
2326 CONTENTS is nil. INFO is a plist holding contextual information."
2327 (let ((key (org-element-property :key keyword
))
2328 (value (org-element-property :value keyword
)))
2330 ((string= key
"HTML") value
)
2331 ((string= key
"TOC")
2332 (let ((value (downcase value
)))
2334 ((string-match "\\<headlines\\>" value
)
2335 (let ((depth (or (and (string-match "[0-9]+" value
)
2336 (string-to-number (match-string 0 value
)))
2337 (plist-get info
:with-toc
))))
2338 (org-html-toc depth info
)))
2339 ((string= "listings" value
) (org-html-list-of-listings info
))
2340 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2342 ;;;; Latex Environment
2344 (defun org-html-format-latex (latex-frag processing-type
)
2345 "Format a LaTeX fragment LATEX-FRAG into HTML."
2346 (let ((cache-relpath "") (cache-dir ""))
2347 (unless (eq processing-type
'mathjax
)
2348 (let ((bfn (or (buffer-file-name)
2350 (expand-file-name "latex" temporary-file-directory
)))))
2353 (file-name-sans-extension
2354 (file-name-nondirectory bfn
)))
2355 cache-dir
(file-name-directory bfn
))))
2358 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2359 nil nil processing-type
)
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
))
2371 (label (org-element-property :name latex-environment
)))
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
))))
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
2393 (org-html-format-latex latex-frag
'mathjax
))
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
)))))
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."
2412 (defun org-html-link--inline-image (link desc info
)
2413 "Return HTML code for an inline image.
2415 LINK is the link pointing to the inline image. INFO is a plist
2416 used as a communication channel.
2418 Inline images can have these attributes:
2420 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2421 (let* ((type (org-element-property :type link
))
2422 (raw-path (org-element-property :path link
))
2423 (path (cond ((member type
'("http" "https"))
2424 (concat type
":" raw-path
))
2425 ((file-name-absolute-p raw-path
)
2426 (expand-file-name raw-path
))
2428 (parent (org-export-get-parent-element link
))
2429 (caption (org-export-data (org-export-get-caption parent
) info
))
2430 (label (org-element-property :name parent
)))
2431 ;; Return proper string, depending on DISPOSITION.
2432 (org-html-format-inline-image
2434 (org-html--make-attribute-string
2435 (org-export-read-attribute :attr_html parent
))
2436 (org-html-standalone-image-p link info
))))
2438 (defvar org-html-standalone-image-predicate
)
2439 (defun org-html-standalone-image-p (element info
&optional predicate
)
2440 "Test if ELEMENT is a standalone image for the purpose HTML export.
2441 INFO is a plist holding contextual information.
2443 Return non-nil, if ELEMENT is of type paragraph and it's sole
2444 content, save for whitespaces, is a link that qualifies as an
2447 Return non-nil, if ELEMENT is of type link and it's containing
2448 paragraph has no other content save for leading and trailing
2451 Return nil, otherwise.
2453 Bind `org-html-standalone-image-predicate' to constrain
2454 paragraph further. For example, to check for only captioned
2455 standalone images, do the following.
2457 \(setq org-html-standalone-image-predicate
2458 \(lambda \(paragraph\)
2459 \(org-element-property :caption paragraph\)\)\)"
2460 (let ((paragraph (case (org-element-type element
)
2462 (link (and (org-export-inline-image-p
2463 element org-html-inline-image-rules
)
2464 (org-export-get-parent element
)))
2466 (when (eq (org-element-type paragraph
) 'paragraph
)
2467 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2468 (functionp org-html-standalone-image-predicate
)))
2469 (funcall org-html-standalone-image-predicate paragraph
))
2470 (let ((contents (org-element-contents paragraph
)))
2471 (loop for x in contents
2472 with inline-image-count
= 0
2474 ((eq (org-element-type x
) 'plain-text
)
2475 (not (org-string-nw-p x
)))
2476 ((eq (org-element-type x
) 'link
)
2477 (when (org-export-inline-image-p
2478 x org-html-inline-image-rules
)
2479 (= (incf inline-image-count
) 1)))
2482 (defun org-html-link (link desc info
)
2483 "Transcode a LINK object from Org to HTML.
2485 DESC is the description part of the link, or the empty string.
2486 INFO is a plist holding contextual information. See
2488 (let* ((link-org-files-as-html-maybe
2490 (lambda (raw-path info
)
2491 "Treat links to `file.org' as links to `file.html', if needed.
2492 See `org-html-link-org-files-as-html'."
2494 ((and org-html-link-org-files-as-html
2496 (downcase (file-name-extension raw-path
"."))))
2497 (concat (file-name-sans-extension raw-path
) "."
2498 (plist-get info
:html-extension
)))
2500 (type (org-element-property :type link
))
2501 (raw-path (org-element-property :path link
))
2502 ;; Ensure DESC really exists, or set it to nil.
2503 (desc (org-string-nw-p desc
))
2506 ((member type
'("http" "https" "ftp" "mailto"))
2507 (concat type
":" raw-path
))
2508 ((string= type
"file")
2509 ;; Treat links to ".org" files as ".html", if needed.
2511 (funcall link-org-files-as-html-maybe raw-path info
))
2512 ;; If file path is absolute, prepend it with protocol
2513 ;; component - "file://".
2514 (when (file-name-absolute-p raw-path
)
2516 (concat "file://" (expand-file-name raw-path
))))
2517 ;; Add search option, if any. A search option can be
2518 ;; relative to a custom-id or a headline title. Any other
2519 ;; option is ignored.
2520 (let ((option (org-element-property :search-option link
)))
2521 (cond ((not option
) raw-path
)
2522 ((eq (aref option
0) ?
#) (concat raw-path option
))
2523 ;; External fuzzy link: try to resolve it if path
2524 ;; belongs to current project, if any.
2525 ((eq (aref option
0) ?
*)
2529 (org-publish-resolve-external-fuzzy-link
2530 (org-element-property :path link
) option
)))
2531 (and numbers
(concat "#sec-"
2532 (mapconcat 'number-to-string
2536 ;; Extract attributes from parent's paragraph. HACK: Only do
2537 ;; this for the first link in parent. This is needed as long
2538 ;; as attributes cannot be set on a per link basis.
2540 (let ((parent (org-export-get-parent-element link
)))
2541 (if (not (eq (org-element-map parent
'link
'identity info t
) link
))
2543 (let ((att (org-html--make-attribute-string
2544 (org-export-read-attribute :attr_html parent
))))
2545 (cond ((not (org-string-nw-p att
)) "")
2546 ((and desc
(string-match (regexp-quote att
) desc
)) "")
2547 (t (concat " " att
)))))))
2551 ((and (or (eq t org-html-inline-images
)
2552 (and org-html-inline-images
(not desc
)))
2553 (org-export-inline-image-p link org-html-inline-image-rules
))
2554 (org-html-link--inline-image link desc info
))
2555 ;; Radio target: Transcode target's contents and use them as
2556 ;; link's description.
2557 ((string= type
"radio")
2558 (let ((destination (org-export-resolve-radio-link link info
)))
2560 (format "<a href=\"#%s\"%s>%s</a>"
2561 (org-export-solidify-link-text path
)
2563 (org-export-data (org-element-contents destination
) info
)))))
2564 ;; Links pointing to a headline: Find destination and build
2565 ;; appropriate referencing command.
2566 ((member type
'("custom-id" "fuzzy" "id"))
2567 (let ((destination (if (string= type
"fuzzy")
2568 (org-export-resolve-fuzzy-link link info
)
2569 (org-export-resolve-id-link link info
))))
2570 (case (org-element-type destination
)
2571 ;; ID link points to an external file.
2573 (let ((fragment (concat "ID-" path
))
2574 ;; Treat links to ".org" files as ".html", if needed.
2575 (path (funcall link-org-files-as-html-maybe
2577 (format "<a href=\"%s#%s\"%s>%s</a>"
2578 path fragment attributes
(or desc destination
))))
2579 ;; Fuzzy link points nowhere.
2584 (org-element-property :raw-link link
) info
))))
2585 ;; Fuzzy link points to an invisible target.
2587 ;; Link points to a headline.
2590 ;; What href to use?
2592 ;; Case 1: Headline is linked via it's CUSTOM_ID
2593 ;; property. Use CUSTOM_ID.
2594 ((string= type
"custom-id")
2595 (org-element-property :CUSTOM_ID destination
))
2596 ;; Case 2: Headline is linked via it's ID property
2597 ;; or through other means. Use the default href.
2598 ((member type
'("id" "fuzzy"))
2600 (mapconcat 'number-to-string
2601 (org-export-get-headline-number
2602 destination info
) "-")))
2603 (t (error "Shouldn't reach here"))))
2604 ;; What description to use?
2606 ;; Case 1: Headline is numbered and LINK has no
2607 ;; description. Display section number.
2608 (if (and (org-export-numbered-headline-p destination info
)
2610 (mapconcat 'number-to-string
2611 (org-export-get-headline-number
2612 destination info
) ".")
2613 ;; Case 2: Either the headline is un-numbered or
2614 ;; LINK has a custom description. Display LINK's
2615 ;; description or headline's title.
2616 (or desc
(org-export-data (org-element-property
2617 :title destination
) info
)))))
2618 (format "<a href=\"#%s\"%s>%s</a>"
2619 (org-export-solidify-link-text href
) attributes desc
)))
2620 ;; Fuzzy link points to a target. Do as above.
2622 (let ((path (org-export-solidify-link-text path
)) number
)
2625 ((org-html-standalone-image-p destination info
)
2626 (org-export-get-ordinal
2627 (assoc 'link
(org-element-contents destination
))
2628 info
'link
'org-html-standalone-image-p
))
2629 (t (org-export-get-ordinal destination info
))))
2630 (setq desc
(when number
2631 (if (atom number
) (number-to-string number
)
2632 (mapconcat 'number-to-string number
".")))))
2633 (format "<a href=\"#%s\"%s>%s</a>"
2634 path attributes
(or desc
"No description for this link")))))))
2635 ;; Coderef: replace link with the reference name or the
2636 ;; equivalent line number.
2637 ((string= type
"coderef")
2638 (let ((fragment (concat "coderef-" path
)))
2639 (format "<a href=\"#%s\"%s%s>%s</a>"
2642 (format (concat "class=\"coderef\""
2643 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2644 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2647 (format (org-export-get-coderef-format path desc
)
2648 (org-export-resolve-coderef path info
)))))
2649 ;; Link type is handled by a special function.
2650 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2651 (funcall protocol
(org-link-unescape path
) desc
'html
))
2652 ;; External link with a description part.
2653 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2654 ;; External link without a description part.
2655 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2656 ;; No path, only description. Try to do something useful.
2657 (t (format "<i>%s</i>" desc
)))))
2661 (defun org-html-paragraph (paragraph contents info
)
2662 "Transcode a PARAGRAPH element from Org to HTML.
2663 CONTENTS is the contents of the paragraph, as a string. INFO is
2664 the plist used as a communication channel."
2665 (let* ((parent (org-export-get-parent paragraph
))
2666 (parent-type (org-element-type parent
))
2667 (style '((footnote-definition " class=\"footpara\"")))
2668 (extra (or (cadr (assoc parent-type style
)) "")))
2670 ((and (eq (org-element-type parent
) 'item
)
2671 (= (org-element-property :begin paragraph
)
2672 (org-element-property :contents-begin parent
)))
2673 ;; leading paragraph in a list item have no tags
2675 ((org-html-standalone-image-p paragraph info
)
2678 (t (format "<p%s>\n%s</p>" extra contents
)))))
2682 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2683 ;; the correct value for the item counter
2684 (defun org-html-begin-plain-list (type &optional arg1
)
2685 "Insert the beginning of the HTML list depending on TYPE.
2686 When ARG1 is a string, use it as the start parameter for ordered
2690 (format "<ol class=\"org-ol\"%s>"
2691 (if arg1
(format " start=\"%d\"" arg1
) "")))
2692 (unordered "<ul class=\"org-ul\">")
2693 (descriptive "<dl class=\"org-dl\">")))
2695 (defun org-html-end-plain-list (type)
2696 "Insert the end of the HTML list depending on TYPE."
2700 (descriptive "</dl>")))
2702 (defun org-html-plain-list (plain-list contents info
)
2703 "Transcode a PLAIN-LIST element from Org to HTML.
2704 CONTENTS is the contents of the list. INFO is a plist holding
2705 contextual information."
2706 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2707 (type (org-element-property :type plain-list
)))
2709 (org-html-begin-plain-list type
)
2710 contents
(org-html-end-plain-list type
))))
2714 (defun org-html-convert-special-strings (string)
2715 "Convert special characters in STRING to HTML."
2716 (let ((all org-html-special-string-regexps
)
2718 (while (setq a
(pop all
))
2719 (setq re
(car a
) rpl
(cdr a
) start
0)
2720 (while (string-match re string start
)
2721 (setq string
(replace-match rpl t nil string
))))
2724 (defun org-html-encode-plain-text (text)
2725 "Convert plain text characters from TEXT to HTML equivalent.
2726 Possible conversions are set in `org-html-protect-char-alist'."
2729 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2730 org-html-protect-char-alist
)
2733 (defun org-html-plain-text (text info
)
2734 "Transcode a TEXT string from Org to HTML.
2735 TEXT is the string to transcode. INFO is a plist holding
2736 contextual information."
2737 (let ((output text
))
2738 ;; Protect following characters: <, >, &.
2739 (setq output
(org-html-encode-plain-text output
))
2740 ;; Handle smart quotes. Be sure to provide original string since
2741 ;; OUTPUT may have been modified.
2742 (when (plist-get info
:with-smart-quotes
)
2743 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2744 ;; Handle special strings.
2745 (when (plist-get info
:with-special-strings
)
2746 (setq output
(org-html-convert-special-strings output
)))
2747 ;; Handle break preservation if required.
2748 (when (plist-get info
:preserve-breaks
)
2750 (replace-regexp-in-string
2751 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2758 (defun org-html-planning (planning contents info
)
2759 "Transcode a PLANNING element from Org to HTML.
2760 CONTENTS is nil. INFO is a plist used as a communication
2762 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2764 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2769 (let ((closed (org-element-property :closed planning
)))
2771 (format span-fmt org-closed-string
2773 (org-element-property :raw-value closed
)))))
2774 (let ((deadline (org-element-property :deadline planning
)))
2776 (format span-fmt org-deadline-string
2778 (org-element-property :raw-value deadline
)))))
2779 (let ((scheduled (org-element-property :scheduled planning
)))
2781 (format span-fmt org-scheduled-string
2783 (org-element-property :raw-value scheduled
)))))))
2786 ;;;; Property Drawer
2788 (defun org-html-property-drawer (property-drawer contents info
)
2789 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2790 CONTENTS is nil. INFO is a plist holding contextual
2792 ;; The property drawer isn't exported but we want separating blank
2793 ;; lines nonetheless.
2798 (defun org-html-quote-block (quote-block contents info
)
2799 "Transcode a QUOTE-BLOCK element from Org to HTML.
2800 CONTENTS holds the contents of the block. INFO is a plist
2801 holding contextual information."
2802 (format "<blockquote>\n%s</blockquote>" contents
))
2806 (defun org-html-quote-section (quote-section contents info
)
2807 "Transcode a QUOTE-SECTION element from Org to HTML.
2808 CONTENTS is nil. INFO is a plist holding contextual information."
2809 (let ((value (org-remove-indentation
2810 (org-element-property :value quote-section
))))
2811 (when value
(format "<pre>\n%s</pre>" value
))))
2815 (defun org-html-section (section contents info
)
2816 "Transcode a SECTION element from Org to HTML.
2817 CONTENTS holds the contents of the section. INFO is a plist
2818 holding contextual information."
2819 (let ((parent (org-export-get-parent-headline section
)))
2820 ;; Before first headline: no container, just return CONTENTS.
2821 (if (not parent
) contents
2822 ;; Get div's class and id references.
2823 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2824 (1- org-html-toplevel-hlevel
)))
2828 (org-export-get-headline-number parent info
) "-")))
2829 ;; Build return value.
2830 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2832 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2837 (defun org-html-radio-target (radio-target text info
)
2838 "Transcode a RADIO-TARGET object from Org to HTML.
2839 TEXT is the text of the target. INFO is a plist holding
2840 contextual information."
2841 (let ((id (org-export-solidify-link-text
2842 (org-element-property :value radio-target
))))
2843 (org-html--anchor id text
)))
2847 (defun org-html-special-block (special-block contents info
)
2848 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2849 CONTENTS holds the contents of the block. INFO is a plist
2850 holding contextual information."
2851 (format "<div class=\"%s\">\n%s\n</div>"
2852 (downcase (org-element-property :type special-block
))
2857 (defun org-html-src-block (src-block contents info
)
2858 "Transcode a SRC-BLOCK element from Org to HTML.
2859 CONTENTS holds the contents of the item. INFO is a plist holding
2860 contextual information."
2861 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2862 (org-html--textarea-block src-block
)
2863 (let ((lang (org-element-property :language src-block
))
2864 (caption (org-export-get-caption src-block
))
2865 (code (org-html-format-code src-block info
))
2866 (label (let ((lbl (org-element-property :name src-block
)))
2868 (format " id=\"%s\""
2869 (org-export-solidify-link-text lbl
))))))
2870 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2872 "<div class=\"org-src-container\">\n%s%s\n</div>"
2873 (if (not caption
) ""
2874 (format "<label class=\"org-src-name\">%s</label>"
2875 (org-export-data caption info
)))
2876 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2878 ;;;; Statistics Cookie
2880 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2881 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2882 CONTENTS is nil. INFO is a plist holding contextual information."
2883 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2884 (format "<code>%s</code>" cookie-value
)))
2888 (defun org-html-strike-through (strike-through contents info
)
2889 "Transcode STRIKE-THROUGH from Org to HTML.
2890 CONTENTS is the text with strike-through markup. INFO is a plist
2891 holding contextual information."
2892 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2897 (defun org-html-subscript (subscript contents info
)
2898 "Transcode a SUBSCRIPT object from Org to HTML.
2899 CONTENTS is the contents of the object. INFO is a plist holding
2900 contextual information."
2901 (format "<sub>%s</sub>" contents
))
2905 (defun org-html-superscript (superscript contents info
)
2906 "Transcode a SUPERSCRIPT object from Org to HTML.
2907 CONTENTS is the contents of the object. INFO is a plist holding
2908 contextual information."
2909 (format "<sup>%s</sup>" contents
))
2913 (defun org-html-table-cell (table-cell contents info
)
2914 "Transcode a TABLE-CELL element from Org to HTML.
2915 CONTENTS is nil. INFO is a plist used as a communication
2917 (let* ((table-row (org-export-get-parent table-cell
))
2918 (table (org-export-get-parent-table table-cell
))
2920 (if (not org-html-table-align-individual-fields
) ""
2921 (format (if (and (boundp 'org-html-format-table-no-css
)
2922 org-html-format-table-no-css
)
2923 " align=\"%s\"" " class=\"%s\"")
2924 (org-export-table-cell-alignment table-cell info
)))))
2925 (when (or (not contents
) (string= "" (org-trim contents
)))
2926 (setq contents
" "))
2928 ((and (org-export-table-has-header-p table info
)
2929 (= 1 (org-export-table-row-group table-row info
)))
2930 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2931 contents
(cdr org-html-table-header-tags
)))
2932 ((and org-html-table-use-header-tags-for-first-column
2933 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2934 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2935 contents
(cdr org-html-table-header-tags
)))
2936 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2937 contents
(cdr org-html-table-data-tags
))))))
2941 (defun org-html-table-row (table-row contents info
)
2942 "Transcode a TABLE-ROW element from Org to HTML.
2943 CONTENTS is the contents of the row. INFO is a plist used as a
2944 communication channel."
2945 ;; Rules are ignored since table separators are deduced from
2946 ;; borders of the current row.
2947 (when (eq (org-element-property :type table-row
) 'standard
)
2948 (let* ((rowgroup-number (org-export-table-row-group table-row info
))
2949 (row-number (org-export-table-row-number table-row info
))
2951 (org-export-table-row-starts-rowgroup-p table-row info
))
2953 (org-export-table-row-ends-rowgroup-p table-row info
))
2954 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2955 ;; but should be set so that `org-html-table-row-tags' can
2956 ;; use them (see the docstring of this variable.)
2957 (top-row-p (and (equal start-rowgroup-p
'(top))
2958 (equal end-rowgroup-p
'(below top
))))
2959 (bottom-row-p (and (equal start-rowgroup-p
'(above))
2960 (equal end-rowgroup-p
'(bottom above
))))
2963 ;; Case 1: Row belongs to second or subsequent rowgroups.
2964 ((not (= 1 rowgroup-number
))
2965 '("<tbody>" .
"\n</tbody>"))
2966 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2967 ((org-export-table-has-header-p
2968 (org-export-get-parent-table table-row
) info
)
2969 '("<thead>" .
"\n</thead>"))
2970 ;; Case 2: Row is from first and only row group.
2971 (t '("<tbody>" .
"\n</tbody>")))))
2973 ;; Begin a rowgroup?
2974 (when start-rowgroup-p
(car rowgroup-tags
))
2976 (concat "\n" (eval (car org-html-table-row-tags
))
2979 (eval (cdr org-html-table-row-tags
)))
2981 (when end-rowgroup-p
(cdr rowgroup-tags
))))))
2985 (defun org-html-table-first-row-data-cells (table info
)
2986 "Transcode the first row of TABLE.
2987 INFO is a plist used as a communication channel."
2989 (org-element-map table
'table-row
2991 (unless (eq (org-element-property :type row
) 'rule
) row
))
2993 (special-column-p (org-export-table-has-special-column-p table
)))
2994 (if (not special-column-p
) (org-element-contents table-row
)
2995 (cdr (org-element-contents table-row
)))))
2997 (defun org-html-table--table.el-table
(table info
)
2998 "Format table.el tables into HTML.
2999 INFO is a plist used as a communication channel."
3000 (when (eq (org-element-property :type table
) 'table.el
)
3002 (let ((outbuf (with-current-buffer
3003 (get-buffer-create "*org-export-table*")
3004 (erase-buffer) (current-buffer))))
3006 (insert (org-element-property :value table
))
3008 (re-search-forward "^[ \t]*|[^|]" nil t
)
3009 (table-generate-source 'html outbuf
))
3010 (with-current-buffer outbuf
3011 (prog1 (org-trim (buffer-string))
3014 (defun org-html-table (table contents info
)
3015 "Transcode a TABLE element from Org to HTML.
3016 CONTENTS is the contents of the table. INFO is a plist holding
3017 contextual information."
3018 (case (org-element-property :type table
)
3019 ;; Case 1: table.el table. Convert it using appropriate tools.
3020 (table.el
(org-html-table--table.el-table table info
))
3021 ;; Case 2: Standard table.
3023 (let* ((label (org-element-property :name table
))
3024 (caption (org-export-get-caption table
))
3026 (org-html--make-attribute-string
3028 (and label
(list :id
(org-export-solidify-link-text label
)))
3029 (plist-get info
:html-table-attributes
)
3030 (org-export-read-attribute :attr_html table
))))
3032 (if (and (boundp 'org-html-format-table-no-css
)
3033 org-html-format-table-no-css
)
3034 "align=\"%s\"" "class=\"%s\""))
3037 (lambda (table info
)
3039 (lambda (table-cell)
3040 (let ((alignment (org-export-table-cell-alignment
3043 ;; Begin a colgroup?
3044 (when (org-export-table-cell-starts-colgroup-p
3047 ;; Add a column. Also specify it's alignment.
3048 (format "\n<col %s/>" (format alignspec alignment
))
3050 (when (org-export-table-cell-ends-colgroup-p
3053 (org-html-table-first-row-data-cells table info
) "\n")))))
3054 (format "<table%s>\n%s\n%s\n%s</table>"
3055 (if (equal attributes
"") "" (concat " " attributes
))
3056 (if (not caption
) ""
3057 (format "<caption>%s</caption>"
3058 (org-export-data caption info
)))
3059 (funcall table-column-specs table info
)
3064 (defun org-html-target (target contents info
)
3065 "Transcode a TARGET object from Org to HTML.
3066 CONTENTS is nil. INFO is a plist holding contextual
3068 (let ((id (org-export-solidify-link-text
3069 (org-element-property :value target
))))
3070 (org-html--anchor id
)))
3074 (defun org-html-timestamp (timestamp contents info
)
3075 "Transcode a TIMESTAMP object from Org to HTML.
3076 CONTENTS is nil. INFO is a plist holding contextual
3078 (let ((value (org-html-plain-text
3079 (org-timestamp-translate timestamp
) info
)))
3080 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3081 (replace-regexp-in-string "--" "–" value
))))
3085 (defun org-html-underline (underline contents info
)
3086 "Transcode UNDERLINE from Org to HTML.
3087 CONTENTS is the text with underline markup. INFO is a plist
3088 holding contextual information."
3089 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3094 (defun org-html-verbatim (verbatim contents info
)
3095 "Transcode VERBATIM from Org to HTML.
3096 CONTENTS is nil. INFO is a plist holding contextual
3098 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3099 (org-html-encode-plain-text (org-element-property :value verbatim
))))
3103 (defun org-html-verse-block (verse-block contents info
)
3104 "Transcode a VERSE-BLOCK element from Org to HTML.
3105 CONTENTS is verse block contents. INFO is a plist holding
3106 contextual information."
3107 ;; Replace each newline character with line break. Also replace
3108 ;; each blank line with a line break.
3109 (setq contents
(replace-regexp-in-string
3110 "^ *\\\\\\\\$" "<br/>\n"
3111 (replace-regexp-in-string
3112 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3113 ;; Replace each white space at beginning of a line with a
3114 ;; non-breaking space.
3115 (while (string-match "^[ \t]+" contents
)
3116 (let* ((num-ws (length (match-string 0 contents
)))
3117 (ws (let (out) (dotimes (i num-ws out
)
3118 (setq out
(concat out
" "))))))
3119 (setq contents
(replace-match ws nil t contents
))))
3120 (format "<p class=\"verse\">\n%s</p>" contents
))
3123 ;;; Filter Functions
3125 (defun org-html-final-function (contents backend info
)
3126 "Filter to indent the HTML and convert HTML entities."
3131 (indent-region (point-min) (point-max)))
3132 (when org-html-use-unicode-chars
3134 (mm-url-decode-entities))
3135 (buffer-substring-no-properties (point-min) (point-max))))
3138 ;;; End-user functions
3141 (defun org-html-export-as-html
3142 (&optional async subtreep visible-only body-only ext-plist
)
3143 "Export current buffer to an HTML buffer.
3145 If narrowing is active in the current buffer, only export its
3148 If a region is active, export that region.
3150 A non-nil optional argument ASYNC means the process should happen
3151 asynchronously. The resulting buffer should be accessible
3152 through the `org-export-stack' interface.
3154 When optional argument SUBTREEP is non-nil, export the sub-tree
3155 at point, extracting information from the headline properties
3158 When optional argument VISIBLE-ONLY is non-nil, don't export
3159 contents of hidden elements.
3161 When optional argument BODY-ONLY is non-nil, only write code
3162 between \"<body>\" and \"</body>\" tags.
3164 EXT-PLIST, when provided, is a property list with external
3165 parameters overriding Org default settings, but still inferior to
3166 file-local settings.
3168 Export is done in a buffer named \"*Org HTML Export*\", which
3169 will be displayed when `org-export-show-temporary-export-buffer'
3173 (org-export-async-start
3175 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3178 (goto-char (point-min))
3180 (org-export-add-to-stack (current-buffer) 'html
)))
3181 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3182 (let ((outbuf (org-export-to-buffer
3183 'html
"*Org HTML Export*"
3184 subtreep visible-only body-only ext-plist
)))
3186 (with-current-buffer outbuf
(set-auto-mode t
))
3187 (when org-export-show-temporary-export-buffer
3188 (switch-to-buffer-other-window outbuf
)))))
3191 (defun org-html-convert-region-to-html ()
3192 "Assume the current region has org-mode syntax, and convert it to HTML.
3193 This can be used in any buffer. For example, you can write an
3194 itemized list in org-mode syntax in an HTML buffer and use this
3195 command to convert it."
3197 (org-export-replace-region-by 'html
))
3200 (defun org-html-export-to-html
3201 (&optional async subtreep visible-only body-only ext-plist
)
3202 "Export current buffer to a HTML file.
3204 If narrowing is active in the current buffer, only export its
3207 If a region is active, export that region.
3209 A non-nil optional argument ASYNC means the process should happen
3210 asynchronously. The resulting file should be accessible through
3211 the `org-export-stack' interface.
3213 When optional argument SUBTREEP is non-nil, export the sub-tree
3214 at point, extracting information from the headline properties
3217 When optional argument VISIBLE-ONLY is non-nil, don't export
3218 contents of hidden elements.
3220 When optional argument BODY-ONLY is non-nil, only write code
3221 between \"<body>\" and \"</body>\" tags.
3223 EXT-PLIST, when provided, is a property list with external
3224 parameters overriding Org default settings, but still inferior to
3225 file-local settings.
3227 Return output file's name."
3229 (let* ((extension (concat "." org-html-extension
))
3230 (file (org-export-output-file-name extension subtreep
))
3231 (org-export-coding-system org-html-coding-system
))
3233 (org-export-async-start
3234 (lambda (f) (org-export-add-to-stack f
'html
))
3235 (let ((org-export-coding-system org-html-coding-system
))
3238 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3239 (let ((org-export-coding-system org-html-coding-system
))
3241 'html file subtreep visible-only body-only ext-plist
)))))
3244 (defun org-html-publish-to-html (plist filename pub-dir
)
3245 "Publish an org file to HTML.
3247 FILENAME is the filename of the Org file to be published. PLIST
3248 is the property list for the given project. PUB-DIR is the
3249 publishing directory.
3251 Return output file name."
3252 (org-publish-org-to 'html filename
3253 (concat "." (or (plist-get plist
:html-extension
)
3254 org-html-extension
"html"))
3260 ;;;; org-format-table-html
3261 ;;;; org-format-org-table-html
3262 ;;;; org-format-table-table-html
3263 ;;;; org-table-number-fraction
3264 ;;;; org-table-number-regexp
3265 ;;;; org-html-table-caption-above
3266 ;;;; org-html-inline-image-extensions
3267 ;;;; org-export-preferred-target-alist
3268 ;;;; class for anchors
3269 ;;;; org-export-mark-todo-in-toc
3270 ;;;; org-html-format-org-link
3271 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3272 ;;;; alt = (file-name-nondirectory path)
3277 ;; generated-autoload-file: "org-loaddefs.el"
3280 ;;; ox-html.el ends here