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-bibliography ()
1296 "Find bibliography, cut it out and return it."
1298 (let (beg end
(cnt 1) bib
)
1300 (goto-char (point-min))
1301 (when (re-search-forward
1302 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1303 (setq beg
(match-beginning 0))
1304 (while (re-search-forward "</?div\\>" nil t
)
1305 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1307 (and (looking-at ">") (forward-char 1))
1308 (setq bib
(buffer-substring beg
(point)))
1309 (delete-region beg
(point))
1310 (throw 'exit bib
))))
1315 (defun org-html-htmlize-region-for-paste (beg end
)
1316 "Convert the region between BEG and END to HTML, using htmlize.el.
1317 This is much like `htmlize-region-for-paste', only that it uses
1318 the settings define in the org-... variables."
1319 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1320 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1321 (htmlbuf (htmlize-region beg end
)))
1323 (with-current-buffer htmlbuf
1324 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1325 (plist-get htmlize-buffer-places
'content-end
)))
1326 (kill-buffer htmlbuf
))))
1329 (defun org-html-htmlize-generate-css ()
1330 "Create the CSS for all font definitions in the current Emacs session.
1331 Use this to create face definitions in your CSS style file that can then
1332 be used by code snippets transformed by htmlize.
1333 This command just produces a buffer that contains class definitions for all
1334 faces used in the current Emacs session. You can copy and paste the ones you
1335 need into your CSS file.
1337 If you then set `org-html-htmlize-output-type' to `css', calls
1338 to the function `org-html-htmlize-region-for-paste' will
1339 produce code that uses these same face definitions."
1342 (and (get-buffer "*html*") (kill-buffer "*html*"))
1344 (let ((fl (face-list))
1345 (htmlize-css-name-prefix "org-")
1346 (htmlize-output-type 'css
)
1348 (while (setq f
(pop fl
)
1349 i
(and f
(face-attribute f
:inherit
)))
1350 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1351 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1352 (htmlize-region (point-min) (point-max))))
1353 (org-pop-to-buffer-same-window "*html*")
1354 (goto-char (point-min))
1355 (if (re-search-forward "<style" nil t
)
1356 (delete-region (point-min) (match-beginning 0)))
1357 (if (re-search-forward "</style>" nil t
)
1358 (delete-region (1+ (match-end 0)) (point-max)))
1359 (beginning-of-line 1)
1360 (if (looking-at " +") (replace-match ""))
1361 (goto-char (point-min)))
1363 (defun org-html--make-string (n string
)
1364 "Build a string by concatenating N times STRING."
1365 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1367 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1368 "Turn todo keyword KWD into a valid class name.
1369 Replaces invalid characters with \"_\"."
1371 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1372 (setq kwd
(replace-match "_" t t kwd
))))
1375 (defun org-html-format-footnote-reference (n def refcnt
)
1376 "Format footnote reference N with definition DEF into HTML."
1377 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1378 (format org-html-footnote-format
1379 (let* ((id (format "fnr.%s%s" n extra
))
1380 (href (format " href=\"#fn.%s\"" n
))
1381 (attributes (concat " class=\"footref\"" href
)))
1382 (org-html--anchor id n attributes
)))))
1384 (defun org-html-format-footnotes-section (section-name definitions
)
1385 "Format footnotes section SECTION-NAME."
1386 (if (not definitions
) ""
1387 (format org-html-footnotes-section section-name definitions
)))
1389 (defun org-html-format-footnote-definition (fn)
1390 "Format the footnote definition FN."
1391 (let ((n (car fn
)) (def (cdr fn
)))
1393 "<div class=\"footdef\">%s %s</div>\n"
1394 (format org-html-footnote-format
1395 (let* ((id (format "fn.%s" n
))
1396 (href (format " href=\"#fnr.%s\"" n
))
1397 (attributes (concat " class=\"footnum\"" href
)))
1398 (org-html--anchor id n attributes
)))
1401 (defun org-html-footnote-section (info)
1402 "Format the footnote section.
1403 INFO is a plist used as a communication channel."
1404 (let* ((fn-alist (org-export-collect-footnote-definitions
1405 (plist-get info
:parse-tree
) info
))
1407 (loop for
(n type raw
) in fn-alist collect
1408 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1409 (org-trim (org-export-data raw info
))
1411 (org-trim (org-export-data raw info
))))))))
1413 (org-html-format-footnotes-section
1414 (org-html--translate "Footnotes" info
)
1417 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1422 (defun org-html--build-meta-info (info)
1423 "Return meta tags for exported document.
1424 INFO is a plist used as a communication channel."
1425 (let ((protect-string
1427 (replace-regexp-in-string
1428 "\"" """ (org-html-encode-plain-text str
))))
1429 (title (org-export-data (plist-get info
:title
) info
))
1430 (author (and (plist-get info
:with-author
)
1431 (let ((auth (plist-get info
:author
)))
1433 ;; Return raw Org syntax, skipping non
1434 ;; exportable objects.
1435 (org-element-interpret-data
1436 (org-element-map auth
1437 (cons 'plain-text org-element-all-objects
)
1438 'identity info
))))))
1439 (description (plist-get info
:description
))
1440 (keywords (plist-get info
:keywords
)))
1442 (format "<title>%s</title>\n" title
)
1444 (when :time-stamp-file
1446 (concat "<!-- " org-html-metadata-timestamp-format
" -->\n"))))
1448 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1449 (or (and org-html-coding-system
1450 (fboundp 'coding-system-get
)
1451 (coding-system-get org-html-coding-system
'mime-charset
))
1453 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1454 (and (org-string-nw-p author
)
1455 (format "<meta name=\"author\" content=\"%s\"/>\n"
1456 (funcall protect-string author
)))
1457 (and (org-string-nw-p description
)
1458 (format "<meta name=\"description\" content=\"%s\"/>\n"
1459 (funcall protect-string description
)))
1460 (and (org-string-nw-p keywords
)
1461 (format "<meta name=\"keywords\" content=\"%s\"/>\n"
1462 (funcall protect-string keywords
))))))
1464 (defun org-html--build-head (info)
1465 "Return information for the <head>..</head> of the HTML output.
1466 INFO is a plist used as a communication channel."
1467 (org-element-normalize-string
1469 (when (plist-get info
:html-head-include-default-style
)
1470 (org-element-normalize-string org-html-style-default
))
1471 (org-element-normalize-string (plist-get info
:html-head
))
1472 (org-element-normalize-string (plist-get info
:html-head-extra
))
1473 (when (and (plist-get info
:html-htmlized-css-url
)
1474 (eq org-html-htmlize-output-type
'css
))
1475 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1476 (plist-get info
:html-htmlized-css-url
)))
1477 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1479 (defun org-html--build-mathjax-config (info)
1480 "Insert the user setup into the mathjax template.
1481 INFO is a plist used as a communication channel."
1482 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1483 (org-element-map (plist-get info
:parse-tree
)
1484 '(latex-fragment latex-environment
) 'identity info t
))
1485 (let ((template org-html-mathjax-template
)
1486 (options org-html-mathjax-options
)
1487 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1488 name val
(yes " ") (no "// ") x
)
1491 (setq name
(car e
) val
(nth 1 e
))
1492 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1493 (setq val
(car (read-from-string
1494 (substring in-buffer
(match-end 0))))))
1495 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1496 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1497 (setq template
(replace-match val t t template
))))
1499 (setq val
(nth 1 (assq 'mathml options
)))
1500 (if (string-match (concat "\\<mathml:") in-buffer
)
1501 (setq val
(car (read-from-string
1502 (substring in-buffer
(match-end 0))))))
1503 ;; Exchange prefixes depending on mathml setting.
1504 (if (not val
) (setq x yes yes no no x
))
1505 ;; Replace cookies to turn on or off the config/jax lines.
1506 (if (string-match ":MMLYES:" template
)
1507 (setq template
(replace-match yes t t template
)))
1508 (if (string-match ":MMLNO:" template
)
1509 (setq template
(replace-match no t t template
)))
1510 ;; Return the modified template.
1511 (org-element-normalize-string template
))))
1513 (defun org-html-format-spec (info)
1514 "Return format specification for elements that can be
1515 used in the preamble or postamble."
1516 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1517 (?d .
,(org-export-data (org-export-get-date info
) info
))
1518 (?T .
,(format-time-string org-html-metadata-timestamp-format
))
1519 (?a .
,(org-export-data (plist-get info
:author
) info
))
1522 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1523 (split-string (plist-get info
:email
) ",+ *")
1525 (?c .
,(plist-get info
:creator
))
1526 (?C .
,(let ((file (plist-get info
:input-file
)))
1527 (format-time-string org-html-metadata-timestamp-format
1528 (if file
(nth 5 (file-attributes file
))
1530 (?v .
,(or org-html-validation-link
""))))
1532 (defun org-html--build-pre/postamble
(type info
)
1533 "Return document preamble or postamble as a string, or nil.
1534 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1535 communication channel."
1536 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1537 (spec (org-html-format-spec info
)))
1539 (let ((section-contents
1540 (if (functionp section
) (funcall section info
)
1542 ((stringp section
) (format-spec section spec
))
1544 (let ((date (cdr (assq ?d spec
)))
1545 (author (cdr (assq ?a spec
)))
1546 (email (cdr (assq ?e spec
)))
1547 (creator (cdr (assq ?c spec
)))
1548 (timestamp (cdr (assq ?T spec
)))
1549 (validation-link (cdr (assq ?v spec
))))
1551 (when (and (plist-get info
:with-date
)
1552 (org-string-nw-p date
))
1553 (format "<p class=\"date\">%s: %s</p>\n"
1554 (org-html--translate "Date" info
)
1556 (when (and (plist-get info
:with-author
)
1557 (org-string-nw-p author
))
1558 (format "<p class=\"author\">%s: %s</p>\n"
1559 (org-html--translate "Author" info
)
1561 (when (and (plist-get info
:with-email
)
1562 (org-string-nw-p email
))
1563 (format "<p class=\"email\">%s: %s</p>\n"
1564 (org-html--translate "Email" info
)
1566 (when (plist-get info
:time-stamp-file
)
1568 "<p class=\"date\">%s: %s</p>\n"
1569 (org-html--translate "Created" info
)
1570 (format-time-string org-html-metadata-timestamp-format
)))
1571 (when (plist-get info
:with-creator
)
1572 (format "<p class=\"creator\">%s</p>\n" creator
))
1573 (format "<p class=\"xhtml-validation\">%s</p>\n"
1577 (plist-get info
:language
)
1579 (format "org-html-%s-format" type
)))))
1584 (intern (format "org-html-%s-format" type
))))))
1586 (when (org-string-nw-p section-contents
)
1588 (format "<%s id=\"%s\" class=\"%s\">\n"
1589 (nth 1 (assq type org-html-divs
))
1590 (nth 2 (assq type org-html-divs
))
1591 org-html--pre
/postamble-class
)
1592 (org-element-normalize-string section-contents
)
1593 (format "</%s>\n" (nth 1 (assq type org-html-divs
)))))))))
1595 (defun org-html-inner-template (contents info
)
1596 "Return body of document string after HTML conversion.
1597 CONTENTS is the transcoded contents string. INFO is a plist
1598 holding export options."
1600 ;; Table of contents.
1601 (let ((depth (plist-get info
:with-toc
)))
1602 (when depth
(org-html-toc depth info
)))
1603 ;; Document contents.
1605 ;; Footnotes section.
1606 (org-html-footnote-section info
)
1608 (org-html-bibliography)))
1610 (defun org-html-template (contents info
)
1611 "Return complete document string after HTML conversion.
1612 CONTENTS is the transcoded contents string. INFO is a plist
1613 holding export options."
1616 (or (and (stringp org-html-xml-declaration
)
1617 org-html-xml-declaration
)
1618 (cdr (assoc (plist-get info
:html-extension
)
1619 org-html-xml-declaration
))
1620 (cdr (assoc "html" org-html-xml-declaration
))
1623 (or (and org-html-coding-system
1624 (fboundp 'coding-system-get
)
1625 (coding-system-get org-html-coding-system
'mime-charset
))
1628 (plist-get info
:html-doctype
)
1630 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1631 (plist-get info
:language
) (plist-get info
:language
))
1633 (org-html--build-meta-info info
)
1634 (org-html--build-head info
)
1635 (org-html--build-mathjax-config info
)
1638 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1639 (link-home (org-trim (plist-get info
:html-link-home
))))
1640 (unless (and (string= link-up
"") (string= link-up
""))
1641 (format org-html-home
/up-format
1642 (or link-up link-home
)
1643 (or link-home link-up
))))
1645 (org-html--build-pre/postamble
'preamble info
)
1646 ;; Document contents.
1647 (format "<%s id=\"%s\">\n"
1648 (nth 1 (assq 'content org-html-divs
))
1649 (nth 2 (assq 'content org-html-divs
)))
1651 (let ((title (plist-get info
:title
)))
1652 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1655 (nth 1 (assq 'content org-html-divs
)))
1657 (org-html--build-pre/postamble
'postamble info
)
1658 ;; Closing document.
1659 "</body>\n</html>"))
1661 (defun org-html--translate (s info
)
1662 "Translate string S according to specified language.
1663 INFO is a plist used as a communication channel."
1664 (org-export-translate s
:html info
))
1668 (defun org-html--anchor (&optional id desc attributes
)
1669 "Format a HTML anchor."
1670 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1671 (attributes (concat (and id
(format " id=\"%s\"" id
))
1672 (and name
(format " name=\"%s\"" name
))
1674 (format "<a%s>%s</a>" attributes
(or desc
""))))
1678 (defun org-html--todo (todo)
1679 "Format TODO keywords into HTML."
1681 (format "<span class=\"%s %s%s\">%s</span>"
1682 (if (member todo org-done-keywords
) "done" "todo")
1683 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1688 (defun org-html--tags (tags)
1689 "Format TAGS into HTML."
1691 (format "<span class=\"tag\">%s</span>"
1694 (format "<span class=\"%s\">%s</span>"
1695 (concat org-html-tag-class-prefix
1696 (org-html-fix-class-name tag
))
1702 (defun* org-html-format-headline
1703 (todo todo-type priority text tags
1704 &key level section-number headline-label
&allow-other-keys
)
1705 "Format a headline in HTML."
1706 (let ((section-number
1707 (when section-number
1708 (format "<span class=\"section-number-%d\">%s</span> "
1709 level section-number
)))
1710 (todo (org-html--todo todo
))
1711 (tags (org-html--tags tags
)))
1712 (concat section-number todo
(and todo
" ") text
1713 (and tags
"   ") tags
)))
1717 (defun org-html-fontify-code (code lang
)
1718 "Color CODE with htmlize library.
1719 CODE is a string representing the source code to colorize. LANG
1720 is the language used for CODE, as a string, or nil."
1723 ;; Case 1: No lang. Possibly an example block.
1725 ;; Simple transcoding.
1726 (org-html-encode-plain-text code
))
1727 ;; Case 2: No htmlize or an inferior version of htmlize
1728 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1730 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1731 ;; Simple transcoding.
1732 (org-html-encode-plain-text code
))
1735 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1736 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1738 ;; Case 1: Language is not associated with any Emacs mode
1739 ((not (functionp lang-mode
))
1740 ;; Simple transcoding.
1741 (org-html-encode-plain-text code
))
1742 ;; Case 2: Default. Fontify code.
1745 (setq code
(with-temp-buffer
1746 ;; Switch to language-specific mode.
1750 (font-lock-fontify-buffer)
1751 ;; Remove formatting on newline characters.
1753 (let ((beg (point-min))
1756 (while (progn (end-of-line) (< (point) end
))
1757 (put-text-property (point) (1+ (point)) 'face nil
)
1760 (set-buffer-modified-p nil
)
1762 (org-html-htmlize-region-for-paste
1763 (point-min) (point-max))))
1764 ;; Strip any enclosing <pre></pre> tags.
1765 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1766 (end (and beg
(string-match "</pre>\\'" code
))))
1767 (if (and beg end
) (substring code beg end
) code
)))))))))
1769 (defun org-html-do-format-code
1770 (code &optional lang refs retain-labels num-start
)
1771 "Format CODE string as source code.
1772 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1773 respectively, the language of the source code, as a string, an
1774 alist between line numbers and references (as returned by
1775 `org-export-unravel-code'), a boolean specifying if labels should
1776 appear in the source code, and the number associated to the first
1778 (let* ((code-lines (org-split-string code
"\n"))
1779 (code-length (length code-lines
))
1783 (length (number-to-string (+ code-length num-start
))))))
1784 (code (org-html-fontify-code code lang
)))
1785 (org-export-format-code
1787 (lambda (loc line-num ref
)
1790 ;; Add line number, if needed.
1792 (format "<span class=\"linenr\">%s</span>"
1793 (format num-fmt line-num
)))
1794 ;; Transcoded src line.
1796 ;; Add label, if needed.
1797 (when (and ref retain-labels
) (format " (%s)" ref
))))
1798 ;; Mark transcoded line as an anchor, if needed.
1800 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1804 (defun org-html-format-code (element info
)
1805 "Format contents of ELEMENT as source code.
1806 ELEMENT is either an example block or a src block. INFO is
1807 a plist used as a communication channel."
1808 (let* ((lang (org-element-property :language element
))
1809 ;; Extract code and references.
1810 (code-info (org-export-unravel-code element
))
1811 (code (car code-info
))
1812 (refs (cdr code-info
))
1813 ;; Does the src block contain labels?
1814 (retain-labels (org-element-property :retain-labels element
))
1815 ;; Does it have line numbers?
1816 (num-start (case (org-element-property :number-lines element
)
1817 (continued (org-export-get-loc element info
))
1819 (org-html-do-format-code code lang refs retain-labels num-start
)))
1822 ;;; Tables of Contents
1824 (defun org-html-toc (depth info
)
1825 "Build a table of contents.
1826 DEPTH is an integer specifying the depth of the table. INFO is a
1827 plist used as a communication channel. Return the table of
1828 contents as a string, or nil if it is empty."
1830 (mapcar (lambda (headline)
1831 (cons (org-html--format-toc-headline headline info
)
1832 (org-export-get-relative-level headline info
)))
1833 (org-export-collect-headlines info depth
))))
1835 (concat "<div id=\"table-of-contents\">\n"
1836 (format "<h%d>%s</h%d>\n"
1837 org-html-toplevel-hlevel
1838 (org-html--translate "Table of Contents" info
)
1839 org-html-toplevel-hlevel
)
1840 "<div id=\"text-table-of-contents\">"
1841 (org-html--toc-text toc-entries
)
1845 (defun org-html--toc-text (toc-entries)
1846 "Return innards of a table of contents, as a string.
1847 TOC-ENTRIES is an alist where key is an entry title, as a string,
1848 and value is its relative level, as an integer."
1849 (let* ((prev-level (1- (cdar toc-entries
)))
1850 (start-level prev-level
))
1854 (let ((headline (car entry
))
1855 (level (cdr entry
)))
1857 (let* ((cnt (- level prev-level
))
1858 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1860 (setq prev-level level
)
1862 (org-html--make-string
1863 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1864 ((< cnt
0) "</li>\n</ul>\n")))
1865 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1868 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1870 (defun org-html--format-toc-headline (headline info
)
1871 "Return an appropriate table of contents entry for HEADLINE.
1872 INFO is a plist used as a communication channel."
1873 (let* ((headline-number (org-export-get-headline-number headline info
))
1875 (and (not (org-export-low-level-p headline info
))
1876 (org-export-numbered-headline-p headline info
)
1877 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1878 (tags (and (eq (plist-get info
:with-tags
) t
)
1879 (org-export-get-tags headline info
))))
1880 (format "<a href=\"#%s\">%s</a>"
1882 (org-export-solidify-link-text
1883 (or (org-element-property :CUSTOM_ID headline
)
1884 (concat "sec-" (mapconcat 'number-to-string
1885 headline-number
"-"))))
1887 (concat section-number
1888 (org-export-data-with-translations
1889 (org-export-get-alt-title headline info
)
1890 ;; Ignore any footnote-reference, link,
1891 ;; radio-target and target in table of contents.
1893 '((footnote-reference . ignore
)
1894 (link .
(lambda (link desc i
) desc
))
1895 (radio-target .
(lambda (radio desc i
) desc
))
1897 (org-export-backend-translate-table 'html
))
1899 (and tags
"   ") (org-html--tags tags
)))))
1901 (defun org-html-list-of-listings (info)
1902 "Build a list of listings.
1903 INFO is a plist used as a communication channel. Return the list
1904 of listings as a string, or nil if it is empty."
1905 (let ((lol-entries (org-export-collect-listings info
)))
1907 (concat "<div id=\"list-of-listings\">\n"
1908 (format "<h%d>%s</h%d>\n"
1909 org-html-toplevel-hlevel
1910 (org-html--translate "List of Listings" info
)
1911 org-html-toplevel-hlevel
)
1912 "<div id=\"text-list-of-listings\">\n<ul>\n"
1914 (initial-fmt (org-html--translate "Listing %d:" info
)))
1917 (let ((label (org-element-property :name entry
))
1920 (or (org-export-get-caption entry t
)
1921 (org-export-get-caption entry
))
1926 (concat (format initial-fmt
(incf count
)) " " title
)
1927 (format "<a href=\"#%s\">%s %s</a>"
1928 (org-export-solidify-link-text label
)
1929 (format initial-fmt
(incf count
))
1933 "\n</ul>\n</div>\n</div>"))))
1935 (defun org-html-list-of-tables (info)
1936 "Build a list of tables.
1937 INFO is a plist used as a communication channel. Return the list
1938 of tables as a string, or nil if it is empty."
1939 (let ((lol-entries (org-export-collect-tables info
)))
1941 (concat "<div id=\"list-of-tables\">\n"
1942 (format "<h%d>%s</h%d>\n"
1943 org-html-toplevel-hlevel
1944 (org-html--translate "List of Tables" info
)
1945 org-html-toplevel-hlevel
)
1946 "<div id=\"text-list-of-tables\">\n<ul>\n"
1948 (initial-fmt (org-html--translate "Table %d:" info
)))
1951 (let ((label (org-element-property :name entry
))
1954 (or (org-export-get-caption entry t
)
1955 (org-export-get-caption entry
))
1960 (concat (format initial-fmt
(incf count
)) " " title
)
1961 (format "<a href=\"#%s\">%s %s</a>"
1962 (org-export-solidify-link-text label
)
1963 (format initial-fmt
(incf count
))
1967 "\n</ul>\n</div>\n</div>"))))
1970 ;;; Transcode Functions
1974 (defun org-html-bold (bold contents info
)
1975 "Transcode BOLD from Org to HTML.
1976 CONTENTS is the text with bold markup. INFO is a plist holding
1977 contextual information."
1978 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1983 (defun org-html-center-block (center-block contents info
)
1984 "Transcode a CENTER-BLOCK element from Org to HTML.
1985 CONTENTS holds the contents of the block. INFO is a plist
1986 holding contextual information."
1987 (format "<div class=\"center\">\n%s</div>" contents
))
1991 (defun org-html-clock (clock contents info
)
1992 "Transcode a CLOCK element from Org to HTML.
1993 CONTENTS is nil. INFO is a plist used as a communication
1996 <span class=\"timestamp-wrapper\">
1997 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2002 (org-element-property :raw-value
2003 (org-element-property :value clock
)))
2004 (let ((time (org-element-property :duration clock
)))
2005 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
2009 (defun org-html-code (code contents info
)
2010 "Transcode CODE from Org to HTML.
2011 CONTENTS is nil. INFO is a plist holding contextual
2013 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
2014 (org-html-plain-text (org-element-property :value code
) info
)))
2018 (defun org-html-drawer (drawer contents info
)
2019 "Transcode a DRAWER element from Org to HTML.
2020 CONTENTS holds the contents of the block. INFO is a plist
2021 holding contextual information."
2022 (if (functionp org-html-format-drawer-function
)
2023 (funcall org-html-format-drawer-function
2024 (org-element-property :drawer-name drawer
)
2026 ;; If there's no user defined function: simply
2027 ;; display contents of the drawer.
2032 (defun org-html-dynamic-block (dynamic-block contents info
)
2033 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2034 CONTENTS holds the contents of the block. INFO is a plist
2035 holding contextual information. See `org-export-data'."
2040 (defun org-html-entity (entity contents info
)
2041 "Transcode an ENTITY object from Org to HTML.
2042 CONTENTS are the definition itself. INFO is a plist holding
2043 contextual information."
2044 (org-element-property :html entity
))
2048 (defun org-html-example-block (example-block contents info
)
2049 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2050 CONTENTS is nil. INFO is a plist holding contextual
2052 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2053 (org-html--textarea-block example-block
)
2054 (format "<pre class=\"example\">\n%s</pre>"
2055 (org-html-format-code example-block info
))))
2059 (defun org-html-export-snippet (export-snippet contents info
)
2060 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2061 CONTENTS is nil. INFO is a plist holding contextual
2063 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2064 (org-element-property :value export-snippet
)))
2068 (defun org-html-export-block (export-block contents info
)
2069 "Transcode a EXPORT-BLOCK element from Org to HTML.
2070 CONTENTS is nil. INFO is a plist holding contextual information."
2071 (when (string= (org-element-property :type export-block
) "HTML")
2072 (org-remove-indentation (org-element-property :value export-block
))))
2076 (defun org-html-fixed-width (fixed-width contents info
)
2077 "Transcode a FIXED-WIDTH element from Org to HTML.
2078 CONTENTS is nil. INFO is a plist holding contextual information."
2079 (format "<pre class=\"example\">\n%s</pre>"
2080 (org-html-do-format-code
2081 (org-remove-indentation
2082 (org-element-property :value fixed-width
)))))
2084 ;;;; Footnote Reference
2086 (defun org-html-footnote-reference (footnote-reference contents info
)
2087 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2088 CONTENTS is nil. INFO is a plist holding contextual information."
2090 ;; Insert separator between two footnotes in a row.
2091 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2092 (when (eq (org-element-type prev
) 'footnote-reference
)
2093 org-html-footnote-separator
))
2095 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2096 (org-html-format-footnote-reference
2097 (org-export-get-footnote-number footnote-reference info
)
2099 ;; Inline definitions are secondary strings.
2100 ((eq (org-element-property :type footnote-reference
) 'inline
)
2101 (org-html-format-footnote-reference
2102 (org-export-get-footnote-number footnote-reference info
)
2104 ;; Non-inline footnotes definitions are full Org data.
2105 (t (org-html-format-footnote-reference
2106 (org-export-get-footnote-number footnote-reference info
)
2111 (defun org-html-format-headline--wrap
2112 (headline info
&optional format-function
&rest extra-keys
)
2113 "Transcode a HEADLINE element from Org to HTML.
2114 CONTENTS holds the contents of the headline. INFO is a plist
2115 holding contextual information."
2116 (let* ((level (+ (org-export-get-relative-level headline info
)
2117 (1- org-html-toplevel-hlevel
)))
2118 (headline-number (org-export-get-headline-number headline info
))
2119 (section-number (and (not (org-export-low-level-p headline info
))
2120 (org-export-numbered-headline-p headline info
)
2121 (mapconcat 'number-to-string
2122 headline-number
".")))
2123 (todo (and (plist-get info
:with-todo-keywords
)
2124 (let ((todo (org-element-property :todo-keyword headline
)))
2125 (and todo
(org-export-data todo info
)))))
2126 (todo-type (and todo
(org-element-property :todo-type headline
)))
2127 (priority (and (plist-get info
:with-priority
)
2128 (org-element-property :priority headline
)))
2129 (text (org-export-data (org-element-property :title headline
) info
))
2130 (tags (and (plist-get info
:with-tags
)
2131 (org-export-get-tags headline info
)))
2132 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2133 (concat "sec-" (mapconcat 'number-to-string
2134 headline-number
"-"))))
2135 (format-function (cond
2136 ((functionp format-function
) format-function
)
2137 ((functionp org-html-format-headline-function
)
2139 (lambda (todo todo-type priority text tags
2141 (funcall org-html-format-headline-function
2142 todo todo-type priority text tags
))))
2143 (t 'org-html-format-headline
))))
2144 (apply format-function
2145 todo todo-type priority text tags
2146 :headline-label headline-label
:level level
2147 :section-number section-number extra-keys
)))
2149 (defun org-html-headline (headline contents info
)
2150 "Transcode a HEADLINE element from Org to HTML.
2151 CONTENTS holds the contents of the headline. INFO is a plist
2152 holding contextual information."
2154 (setq contents
(or contents
""))
2155 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2156 (level (org-export-get-relative-level headline info
))
2157 (text (org-export-data (org-element-property :title headline
) info
))
2158 (todo (and (plist-get info
:with-todo-keywords
)
2159 (let ((todo (org-element-property :todo-keyword headline
)))
2160 (and todo
(org-export-data todo info
)))))
2161 (todo-type (and todo
(org-element-property :todo-type headline
)))
2162 (tags (and (plist-get info
:with-tags
)
2163 (org-export-get-tags headline info
)))
2164 (priority (and (plist-get info
:with-priority
)
2165 (org-element-property :priority headline
)))
2166 (section-number (and (org-export-numbered-headline-p headline info
)
2167 (mapconcat 'number-to-string
2168 (org-export-get-headline-number
2169 headline info
) ".")))
2170 ;; Create the headline text.
2171 (full-text (org-html-format-headline--wrap headline info
)))
2173 ;; Case 1: This is a footnote section: ignore it.
2174 ((org-element-property :footnote-section-p headline
) nil
)
2175 ;; Case 2. This is a deep sub-tree: export it as a list item.
2176 ;; Also export as items headlines for which no section
2177 ;; format has been found.
2178 ((org-export-low-level-p headline info
)
2179 ;; Build the real contents of the sub-tree.
2180 (let* ((type (if numberedp
'ordered
'unordered
))
2181 (itemized-body (org-html-format-list-item
2182 contents type nil nil full-text
)))
2184 (and (org-export-first-sibling-p headline info
)
2185 (org-html-begin-plain-list type
))
2187 (and (org-export-last-sibling-p headline info
)
2188 (org-html-end-plain-list type
)))))
2189 ;; Case 3. Standard headline. Export it as a section.
2191 (let* ((section-number (mapconcat 'number-to-string
2192 (org-export-get-headline-number
2193 headline info
) "-"))
2195 (list (org-element-property :CUSTOM_ID headline
)
2196 (concat "sec-" section-number
)
2197 (org-element-property :ID headline
))))
2198 (preferred-id (car ids
))
2199 (extra-ids (cdr ids
))
2200 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2201 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2202 (first-content (car (org-element-contents headline
))))
2203 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2204 (org-html--container headline info
)
2205 (format "outline-container-%s"
2206 (or (org-element-property :CUSTOM_ID headline
)
2207 (concat "sec-" section-number
)))
2208 (concat (format "outline-%d" level1
) (and extra-class
" ")
2210 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2215 (let ((id (org-export-solidify-link-text
2216 (if (org-uuidgen-p x
) (concat "ID-" x
)
2218 (org-html--anchor id
)))
2222 ;; When there is no section, pretend there is an empty
2223 ;; one to get the correct <div class="outline- ...>
2224 ;; which is needed by `org-info.js'.
2225 (if (not (eq (org-element-type first-content
) 'section
))
2226 (concat (org-html-section first-content
"" info
)
2229 (org-html--container headline info
)))))))
2231 (defun org-html--container (headline info
)
2232 (or (org-element-property :HTML_CONTAINER headline
)
2233 (if (= 1 (org-export-get-relative-level headline info
))
2234 (plist-get info
:html-container
)
2237 ;;;; Horizontal Rule
2239 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2240 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2241 CONTENTS is nil. INFO is a plist holding contextual information."
2244 ;;;; Inline Src Block
2246 (defun org-html-inline-src-block (inline-src-block contents info
)
2247 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2248 CONTENTS holds the contents of the item. INFO is a plist holding
2249 contextual information."
2250 (let* ((org-lang (org-element-property :language inline-src-block
))
2251 (code (org-element-property :value inline-src-block
)))
2252 (error "Cannot export inline src block")))
2256 (defun org-html-format-section (text class
&optional id
)
2257 "Format a section with TEXT into a HTML div with CLASS and ID."
2258 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2259 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2261 (defun org-html-inlinetask (inlinetask contents info
)
2262 "Transcode an INLINETASK element from Org to HTML.
2263 CONTENTS holds the contents of the block. INFO is a plist
2264 holding contextual information."
2266 ;; If `org-html-format-inlinetask-function' is provided, call it
2267 ;; with appropriate arguments.
2268 ((functionp org-html-format-inlinetask-function
)
2269 (let ((format-function
2271 (lambda (todo todo-type priority text tags
2272 &key contents
&allow-other-keys
)
2273 (funcall org-html-format-inlinetask-function
2274 todo todo-type priority text tags contents
)))))
2275 (org-html-format-headline--wrap
2276 inlinetask info format-function
:contents contents
)))
2277 ;; Otherwise, use a default template.
2278 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2279 (org-html-format-headline--wrap inlinetask info
)
2284 (defun org-html-italic (italic contents info
)
2285 "Transcode ITALIC from Org to HTML.
2286 CONTENTS is the text with italic markup. INFO is a plist holding
2287 contextual information."
2288 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2292 (defun org-html-checkbox (checkbox)
2293 "Format CHECKBOX into HTML."
2294 (case checkbox
(on "<code>[X]</code>")
2295 (off "<code>[ ]</code>")
2296 (trans "<code>[-]</code>")
2299 (defun org-html-format-list-item (contents type checkbox
2300 &optional term-counter-id
2302 "Format a list item into HTML."
2303 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2307 (let* ((counter term-counter-id
)
2308 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2310 (format "<li%s>" extra
)
2311 (when headline
(concat headline
"<br/>")))))
2313 (let* ((id term-counter-id
)
2314 (extra (if id
(format " id=\"%s\"" id
) "")))
2316 (format "<li%s>" extra
)
2317 (when headline
(concat headline
"<br/>")))))
2319 (let* ((term term-counter-id
))
2320 (setq term
(or term
"(no term)"))
2321 ;; Check-boxes in descriptive lists are associated to tag.
2322 (concat (format "<dt> %s </dt>"
2323 (concat checkbox term
))
2325 (unless (eq type
'descriptive
) checkbox
)
2330 (descriptive "</dd>")))))
2332 (defun org-html-item (item contents info
)
2333 "Transcode an ITEM element from Org to HTML.
2334 CONTENTS holds the contents of the item. INFO is a plist holding
2335 contextual information."
2336 (let* ((plain-list (org-export-get-parent item
))
2337 (type (org-element-property :type plain-list
))
2338 (counter (org-element-property :counter item
))
2339 (checkbox (org-element-property :checkbox item
))
2340 (tag (let ((tag (org-element-property :tag item
)))
2341 (and tag
(org-export-data tag info
)))))
2342 (org-html-format-list-item
2343 contents type checkbox
(or tag counter
))))
2347 (defun org-html-keyword (keyword contents info
)
2348 "Transcode a KEYWORD element from Org to HTML.
2349 CONTENTS is nil. INFO is a plist holding contextual information."
2350 (let ((key (org-element-property :key keyword
))
2351 (value (org-element-property :value keyword
)))
2353 ((string= key
"HTML") value
)
2354 ((string= key
"TOC")
2355 (let ((value (downcase value
)))
2357 ((string-match "\\<headlines\\>" value
)
2358 (let ((depth (or (and (string-match "[0-9]+" value
)
2359 (string-to-number (match-string 0 value
)))
2360 (plist-get info
:with-toc
))))
2361 (org-html-toc depth info
)))
2362 ((string= "listings" value
) (org-html-list-of-listings info
))
2363 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2365 ;;;; Latex Environment
2367 (defun org-html-format-latex (latex-frag processing-type
)
2368 "Format the LaTeX fragment LATEX-FRAG into HTML."
2369 (let ((cache-relpath "") (cache-dir "") bfn
)
2370 (unless (eq processing-type
'mathjax
)
2371 (setq bfn
(buffer-file-name)
2374 (file-name-sans-extension
2375 (file-name-nondirectory bfn
)))
2376 cache-dir
(file-name-directory bfn
)))
2379 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2380 nil nil processing-type
)
2383 (defun org-html-latex-environment (latex-environment contents info
)
2384 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2385 CONTENTS is nil. INFO is a plist holding contextual information."
2386 (let ((processing-type (plist-get info
:with-latex
))
2387 (latex-frag (org-remove-indentation
2388 (org-element-property :value latex-environment
)))
2389 (caption (org-export-data
2390 (org-export-get-caption latex-environment
) info
))
2392 (label (org-element-property :name latex-environment
)))
2394 ((memq processing-type
'(t mathjax
))
2395 (org-html-format-latex latex-frag
'mathjax
))
2396 ((eq processing-type
'dvipng
)
2397 (let* ((formula-link (org-html-format-latex
2398 latex-frag processing-type
)))
2399 (when (and formula-link
2400 (string-match "file:\\([^]]*\\)" formula-link
))
2401 (org-html-format-inline-image
2402 (match-string 1 formula-link
) caption label attr t
))))
2407 (defun org-html-latex-fragment (latex-fragment contents info
)
2408 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2409 CONTENTS is nil. INFO is a plist holding contextual information."
2410 (let ((latex-frag (org-element-property :value latex-fragment
))
2411 (processing-type (plist-get info
:with-latex
)))
2412 (case processing-type
2414 (org-html-format-latex latex-frag
'mathjax
))
2416 (let* ((formula-link (org-html-format-latex
2417 latex-frag processing-type
)))
2418 (when (and formula-link
2419 (string-match "file:\\([^]]*\\)" formula-link
))
2420 (org-html-format-inline-image
2421 (match-string 1 formula-link
)))))
2426 (defun org-html-line-break (line-break contents info
)
2427 "Transcode a LINE-BREAK object from Org to HTML.
2428 CONTENTS is nil. INFO is a plist holding contextual information."
2433 (defun org-html-link--inline-image (link desc info
)
2434 "Return HTML code for an inline image.
2436 LINK is the link pointing to the inline image. INFO is a plist
2437 used as a communication channel.
2439 Inline images can have these attributes:
2441 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2442 (let* ((type (org-element-property :type link
))
2443 (raw-path (org-element-property :path link
))
2444 (path (cond ((member type
'("http" "https"))
2445 (concat type
":" raw-path
))
2446 ((file-name-absolute-p raw-path
)
2447 (expand-file-name raw-path
))
2449 (parent (org-export-get-parent-element link
))
2450 (caption (org-export-data (org-export-get-caption parent
) info
))
2451 (label (org-element-property :name parent
)))
2452 ;; Return proper string, depending on DISPOSITION.
2453 (org-html-format-inline-image
2455 (org-html--make-attribute-string
2456 (org-export-read-attribute :attr_html parent
))
2457 (org-html-standalone-image-p link info
))))
2459 (defvar org-html-standalone-image-predicate
)
2460 (defun org-html-standalone-image-p (element info
&optional predicate
)
2461 "Test if ELEMENT is a standalone image for the purpose HTML export.
2462 INFO is a plist holding contextual information.
2464 Return non-nil, if ELEMENT is of type paragraph and it's sole
2465 content, save for whitespaces, is a link that qualifies as an
2468 Return non-nil, if ELEMENT is of type link and it's containing
2469 paragraph has no other content save for leading and trailing
2472 Return nil, otherwise.
2474 Bind `org-html-standalone-image-predicate' to constrain
2475 paragraph further. For example, to check for only captioned
2476 standalone images, do the following.
2478 \(setq org-html-standalone-image-predicate
2479 \(lambda \(paragraph\)
2480 \(org-element-property :caption paragraph\)\)\)"
2481 (let ((paragraph (case (org-element-type element
)
2483 (link (and (org-export-inline-image-p
2484 element org-html-inline-image-rules
)
2485 (org-export-get-parent element
)))
2487 (when (eq (org-element-type paragraph
) 'paragraph
)
2488 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2489 (functionp org-html-standalone-image-predicate
)))
2490 (funcall org-html-standalone-image-predicate paragraph
))
2491 (let ((contents (org-element-contents paragraph
)))
2492 (loop for x in contents
2493 with inline-image-count
= 0
2495 ((eq (org-element-type x
) 'plain-text
)
2496 (not (org-string-nw-p x
)))
2497 ((eq (org-element-type x
) 'link
)
2498 (when (org-export-inline-image-p
2499 x org-html-inline-image-rules
)
2500 (= (incf inline-image-count
) 1)))
2503 (defun org-html-link (link desc info
)
2504 "Transcode a LINK object from Org to HTML.
2506 DESC is the description part of the link, or the empty string.
2507 INFO is a plist holding contextual information. See
2509 (let* ((link-org-files-as-html-maybe
2511 (lambda (raw-path info
)
2512 "Treat links to `file.org' as links to `file.html', if needed.
2513 See `org-html-link-org-files-as-html'."
2515 ((and org-html-link-org-files-as-html
2517 (downcase (file-name-extension raw-path
"."))))
2518 (concat (file-name-sans-extension raw-path
) "."
2519 (plist-get info
:html-extension
)))
2521 (type (org-element-property :type link
))
2522 (raw-path (org-element-property :path link
))
2523 ;; Ensure DESC really exists, or set it to nil.
2524 (desc (and (not (string= desc
"")) desc
))
2527 ((member type
'("http" "https" "ftp" "mailto"))
2528 (concat type
":" raw-path
))
2529 ((string= type
"file")
2530 ;; Treat links to ".org" files as ".html", if needed.
2532 (funcall link-org-files-as-html-maybe raw-path info
))
2533 ;; If file path is absolute, prepend it with protocol
2534 ;; component - "file://".
2535 (when (file-name-absolute-p raw-path
)
2537 (concat "file://" (expand-file-name raw-path
))))
2538 ;; Add search option, if any. A search option can be
2539 ;; relative to a custom-id or a headline title. Any other
2540 ;; option is ignored.
2541 (let ((option (org-element-property :search-option link
)))
2542 (cond ((not option
) raw-path
)
2543 ((eq (aref option
0) ?
#) (concat raw-path option
))
2544 ;; External fuzzy link: try to resolve it if path
2545 ;; belongs to current project, if any.
2546 ((eq (aref option
0) ?
*)
2550 (org-publish-resolve-external-fuzzy-link
2551 (org-element-property :path link
) option
)))
2552 (and numbers
(concat "#sec-"
2553 (mapconcat 'number-to-string
2557 ;; Extract attributes from parent's paragraph. HACK: Only do
2558 ;; this for the first link in parent. This is needed as long
2559 ;; as attributes cannot be set on a per link basis.
2561 (let ((parent (org-export-get-parent-element link
)))
2562 (if (not (eq (org-element-map parent
'link
'identity info t
) link
))
2564 (let ((att (org-html--make-attribute-string
2565 (org-export-read-attribute :attr_html parent
))))
2566 (cond ((not (org-string-nw-p att
)) "")
2567 ((and desc
(string-match (regexp-quote att
) desc
)) "")
2568 (t (concat " " att
)))))))
2572 ((and (or (eq t org-html-inline-images
)
2573 (and org-html-inline-images
(not desc
)))
2574 (org-export-inline-image-p link org-html-inline-image-rules
))
2575 (org-html-link--inline-image link desc info
))
2576 ;; Radio target: Transcode target's contents and use them as
2577 ;; link's description.
2578 ((string= type
"radio")
2579 (let ((destination (org-export-resolve-radio-link link info
)))
2581 (format "<a href=\"#%s\"%s>%s</a>"
2582 (org-export-solidify-link-text path
)
2584 (org-export-data (org-element-contents destination
) info
)))))
2585 ;; Links pointing to a headline: Find destination and build
2586 ;; appropriate referencing command.
2587 ((member type
'("custom-id" "fuzzy" "id"))
2588 (let ((destination (if (string= type
"fuzzy")
2589 (org-export-resolve-fuzzy-link link info
)
2590 (org-export-resolve-id-link link info
))))
2591 (case (org-element-type destination
)
2592 ;; ID link points to an external file.
2594 (let ((fragment (concat "ID-" path
))
2595 ;; Treat links to ".org" files as ".html", if needed.
2596 (path (funcall link-org-files-as-html-maybe
2598 (format "<a href=\"%s#%s\"%s>%s</a>"
2599 path fragment attributes
(or desc destination
))))
2600 ;; Fuzzy link points nowhere.
2605 (org-element-property :raw-link link
) info
))))
2606 ;; Fuzzy link points to an invisible target.
2608 ;; Link points to a headline.
2611 ;; What href to use?
2613 ;; Case 1: Headline is linked via it's CUSTOM_ID
2614 ;; property. Use CUSTOM_ID.
2615 ((string= type
"custom-id")
2616 (org-element-property :CUSTOM_ID destination
))
2617 ;; Case 2: Headline is linked via it's ID property
2618 ;; or through other means. Use the default href.
2619 ((member type
'("id" "fuzzy"))
2621 (mapconcat 'number-to-string
2622 (org-export-get-headline-number
2623 destination info
) "-")))
2624 (t (error "Shouldn't reach here"))))
2625 ;; What description to use?
2627 ;; Case 1: Headline is numbered and LINK has no
2628 ;; description or LINK's description matches
2629 ;; headline's title. Display section number.
2630 (if (and (org-export-numbered-headline-p destination info
)
2632 (string= desc
(org-element-property
2633 :raw-value destination
))))
2634 (mapconcat 'number-to-string
2635 (org-export-get-headline-number
2636 destination info
) ".")
2637 ;; Case 2: Either the headline is un-numbered or
2638 ;; LINK has a custom description. Display LINK's
2639 ;; description or headline's title.
2640 (or desc
(org-export-data (org-element-property
2641 :title destination
) info
)))))
2642 (format "<a href=\"#%s\"%s>%s</a>"
2643 (org-export-solidify-link-text href
) attributes desc
)))
2644 ;; Fuzzy link points to a target. Do as above.
2646 (let ((path (org-export-solidify-link-text path
)) number
)
2649 ((org-html-standalone-image-p destination info
)
2650 (org-export-get-ordinal
2651 (assoc 'link
(org-element-contents destination
))
2652 info
'link
'org-html-standalone-image-p
))
2653 (t (org-export-get-ordinal destination info
))))
2654 (setq desc
(when number
2655 (if (atom number
) (number-to-string number
)
2656 (mapconcat 'number-to-string number
".")))))
2657 (format "<a href=\"#%s\"%s>%s</a>"
2658 path attributes
(or desc
"No description for this link")))))))
2659 ;; Coderef: replace link with the reference name or the
2660 ;; equivalent line number.
2661 ((string= type
"coderef")
2662 (let ((fragment (concat "coderef-" path
)))
2663 (format "<a href=\"#%s\"%s%s>%s</a>"
2666 (format (concat "class=\"coderef\""
2667 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2668 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2671 (format (org-export-get-coderef-format path desc
)
2672 (org-export-resolve-coderef path info
)))))
2673 ;; Link type is handled by a special function.
2674 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2675 (funcall protocol
(org-link-unescape path
) desc
'html
))
2676 ;; External link with a description part.
2677 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2678 ;; External link without a description part.
2679 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2680 ;; No path, only description. Try to do something useful.
2681 (t (format "<i>%s</i>" desc
)))))
2685 (defun org-html-paragraph (paragraph contents info
)
2686 "Transcode a PARAGRAPH element from Org to HTML.
2687 CONTENTS is the contents of the paragraph, as a string. INFO is
2688 the plist used as a communication channel."
2689 (let* ((parent (org-export-get-parent paragraph
))
2690 (parent-type (org-element-type parent
))
2691 (style '((footnote-definition " class=\"footpara\"")))
2692 (extra (or (cadr (assoc parent-type style
)) "")))
2694 ((and (eq (org-element-type parent
) 'item
)
2695 (= (org-element-property :begin paragraph
)
2696 (org-element-property :contents-begin parent
)))
2697 ;; leading paragraph in a list item have no tags
2699 ((org-html-standalone-image-p paragraph info
)
2702 (t (format "<p%s>\n%s</p>" extra contents
)))))
2706 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2707 ;; the correct value for the item counter
2708 (defun org-html-begin-plain-list (type &optional arg1
)
2709 "Insert the beginning of the HTML list depending on TYPE.
2710 When ARG1 is a string, use it as the start parameter for ordered
2714 (format "<ol class=\"org-ol\"%s>"
2715 (if arg1
(format " start=\"%d\"" arg1
) "")))
2716 (unordered "<ul class=\"org-ul\">")
2717 (descriptive "<dl class=\"org-dl\">")))
2719 (defun org-html-end-plain-list (type)
2720 "Insert the end of the HTML list depending on TYPE."
2724 (descriptive "</dl>")))
2726 (defun org-html-plain-list (plain-list contents info
)
2727 "Transcode a PLAIN-LIST element from Org to HTML.
2728 CONTENTS is the contents of the list. INFO is a plist holding
2729 contextual information."
2730 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2731 (type (org-element-property :type plain-list
)))
2733 (org-html-begin-plain-list type
)
2734 contents
(org-html-end-plain-list type
))))
2738 (defun org-html-convert-special-strings (string)
2739 "Convert special characters in STRING to HTML."
2740 (let ((all org-html-special-string-regexps
)
2742 (while (setq a
(pop all
))
2743 (setq re
(car a
) rpl
(cdr a
) start
0)
2744 (while (string-match re string start
)
2745 (setq string
(replace-match rpl t nil string
))))
2748 (defun org-html-encode-plain-text (text)
2749 "Convert plain text characters from TEXT to HTML equivalent.
2750 Possible conversions are set in `org-html-protect-char-alist'."
2753 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2754 org-html-protect-char-alist
)
2757 (defun org-html-plain-text (text info
)
2758 "Transcode a TEXT string from Org to HTML.
2759 TEXT is the string to transcode. INFO is a plist holding
2760 contextual information."
2761 (let ((output text
))
2762 ;; Protect following characters: <, >, &.
2763 (setq output
(org-html-encode-plain-text output
))
2764 ;; Handle smart quotes. Be sure to provide original string since
2765 ;; OUTPUT may have been modified.
2766 (when (plist-get info
:with-smart-quotes
)
2767 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2768 ;; Handle special strings.
2769 (when (plist-get info
:with-special-strings
)
2770 (setq output
(org-html-convert-special-strings output
)))
2771 ;; Handle break preservation if required.
2772 (when (plist-get info
:preserve-breaks
)
2774 (replace-regexp-in-string
2775 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2782 (defun org-html-planning (planning contents info
)
2783 "Transcode a PLANNING element from Org to HTML.
2784 CONTENTS is nil. INFO is a plist used as a communication
2786 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2788 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2793 (let ((closed (org-element-property :closed planning
)))
2795 (format span-fmt org-closed-string
2797 (org-element-property :raw-value closed
)))))
2798 (let ((deadline (org-element-property :deadline planning
)))
2800 (format span-fmt org-deadline-string
2802 (org-element-property :raw-value deadline
)))))
2803 (let ((scheduled (org-element-property :scheduled planning
)))
2805 (format span-fmt org-scheduled-string
2807 (org-element-property :raw-value scheduled
)))))))
2810 ;;;; Property Drawer
2812 (defun org-html-property-drawer (property-drawer contents info
)
2813 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2814 CONTENTS is nil. INFO is a plist holding contextual
2816 ;; The property drawer isn't exported but we want separating blank
2817 ;; lines nonetheless.
2822 (defun org-html-quote-block (quote-block contents info
)
2823 "Transcode a QUOTE-BLOCK element from Org to HTML.
2824 CONTENTS holds the contents of the block. INFO is a plist
2825 holding contextual information."
2826 (format "<blockquote>\n%s</blockquote>" contents
))
2830 (defun org-html-quote-section (quote-section contents info
)
2831 "Transcode a QUOTE-SECTION element from Org to HTML.
2832 CONTENTS is nil. INFO is a plist holding contextual information."
2833 (let ((value (org-remove-indentation
2834 (org-element-property :value quote-section
))))
2835 (when value
(format "<pre>\n%s</pre>" value
))))
2839 (defun org-html-section (section contents info
)
2840 "Transcode a SECTION element from Org to HTML.
2841 CONTENTS holds the contents of the section. INFO is a plist
2842 holding contextual information."
2843 (let ((parent (org-export-get-parent-headline section
)))
2844 ;; Before first headline: no container, just return CONTENTS.
2845 (if (not parent
) contents
2846 ;; Get div's class and id references.
2847 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2848 (1- org-html-toplevel-hlevel
)))
2852 (org-export-get-headline-number parent info
) "-")))
2853 ;; Build return value.
2854 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2856 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2861 (defun org-html-radio-target (radio-target text info
)
2862 "Transcode a RADIO-TARGET object from Org to HTML.
2863 TEXT is the text of the target. INFO is a plist holding
2864 contextual information."
2865 (let ((id (org-export-solidify-link-text
2866 (org-element-property :value radio-target
))))
2867 (org-html--anchor id text
)))
2871 (defun org-html-special-block (special-block contents info
)
2872 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2873 CONTENTS holds the contents of the block. INFO is a plist
2874 holding contextual information."
2875 (format "<div class=\"%s\">\n%s\n</div>"
2876 (downcase (org-element-property :type special-block
))
2881 (defun org-html-src-block (src-block contents info
)
2882 "Transcode a SRC-BLOCK element from Org to HTML.
2883 CONTENTS holds the contents of the item. INFO is a plist holding
2884 contextual information."
2885 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2886 (org-html--textarea-block src-block
)
2887 (let ((lang (org-element-property :language src-block
))
2888 (caption (org-export-get-caption src-block
))
2889 (code (org-html-format-code src-block info
))
2890 (label (let ((lbl (org-element-property :name src-block
)))
2892 (format " id=\"%s\""
2893 (org-export-solidify-link-text lbl
))))))
2894 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2896 "<div class=\"org-src-container\">\n%s%s\n</div>"
2897 (if (not caption
) ""
2898 (format "<label class=\"org-src-name\">%s</label>"
2899 (org-export-data caption info
)))
2900 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2902 ;;;; Statistics Cookie
2904 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2905 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2906 CONTENTS is nil. INFO is a plist holding contextual information."
2907 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2908 (format "<code>%s</code>" cookie-value
)))
2912 (defun org-html-strike-through (strike-through contents info
)
2913 "Transcode STRIKE-THROUGH from Org to HTML.
2914 CONTENTS is the text with strike-through markup. INFO is a plist
2915 holding contextual information."
2916 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2921 (defun org-html-subscript (subscript contents info
)
2922 "Transcode a SUBSCRIPT object from Org to HTML.
2923 CONTENTS is the contents of the object. INFO is a plist holding
2924 contextual information."
2925 (format "<sub>%s</sub>" contents
))
2929 (defun org-html-superscript (superscript contents info
)
2930 "Transcode a SUPERSCRIPT object from Org to HTML.
2931 CONTENTS is the contents of the object. INFO is a plist holding
2932 contextual information."
2933 (format "<sup>%s</sup>" contents
))
2937 (defun org-html-table-cell (table-cell contents info
)
2938 "Transcode a TABLE-CELL element from Org to HTML.
2939 CONTENTS is nil. INFO is a plist used as a communication
2941 (let* ((table-row (org-export-get-parent table-cell
))
2942 (table (org-export-get-parent-table table-cell
))
2944 (if (not org-html-table-align-individual-fields
) ""
2945 (format (if (and (boundp 'org-html-format-table-no-css
)
2946 org-html-format-table-no-css
)
2947 " align=\"%s\"" " class=\"%s\"")
2948 (org-export-table-cell-alignment table-cell info
)))))
2949 (when (or (not contents
) (string= "" (org-trim contents
)))
2950 (setq contents
" "))
2952 ((and (org-export-table-has-header-p table info
)
2953 (= 1 (org-export-table-row-group table-row info
)))
2954 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2955 contents
(cdr org-html-table-header-tags
)))
2956 ((and org-html-table-use-header-tags-for-first-column
2957 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2958 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2959 contents
(cdr org-html-table-header-tags
)))
2960 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2961 contents
(cdr org-html-table-data-tags
))))))
2965 (defun org-html-table-row (table-row contents info
)
2966 "Transcode a TABLE-ROW element from Org to HTML.
2967 CONTENTS is the contents of the row. INFO is a plist used as a
2968 communication channel."
2969 ;; Rules are ignored since table separators are deduced from
2970 ;; borders of the current row.
2971 (when (eq (org-element-property :type table-row
) 'standard
)
2972 (let* ((rowgroup-number (org-export-table-row-group table-row info
))
2973 (row-number (org-export-table-row-number table-row info
))
2975 (org-export-table-row-starts-rowgroup-p table-row info
))
2977 (org-export-table-row-ends-rowgroup-p table-row info
))
2978 ;; `top-row-p' and `end-rowgroup-p' are not used directly
2979 ;; but should be set so that `org-html-table-row-tags' can
2980 ;; use them (see the docstring of this variable.)
2981 (top-row-p (and (equal start-rowgroup-p
'(top))
2982 (equal end-rowgroup-p
'(below top
))))
2983 (bottom-row-p (and (equal start-rowgroup-p
'(above))
2984 (equal end-rowgroup-p
'(bottom above
))))
2987 ;; Case 1: Row belongs to second or subsequent rowgroups.
2988 ((not (= 1 rowgroup-number
))
2989 '("<tbody>" .
"\n</tbody>"))
2990 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2991 ((org-export-table-has-header-p
2992 (org-export-get-parent-table table-row
) info
)
2993 '("<thead>" .
"\n</thead>"))
2994 ;; Case 2: Row is from first and only row group.
2995 (t '("<tbody>" .
"\n</tbody>")))))
2997 ;; Begin a rowgroup?
2998 (when start-rowgroup-p
(car rowgroup-tags
))
3000 (concat "\n" (eval (car org-html-table-row-tags
))
3003 (eval (cdr org-html-table-row-tags
)))
3005 (when end-rowgroup-p
(cdr rowgroup-tags
))))))
3009 (defun org-html-table-first-row-data-cells (table info
)
3010 "Transcode the first row of TABLE.
3011 INFO is a plist used as a communication channel."
3013 (org-element-map table
'table-row
3015 (unless (eq (org-element-property :type row
) 'rule
) row
))
3017 (special-column-p (org-export-table-has-special-column-p table
)))
3018 (if (not special-column-p
) (org-element-contents table-row
)
3019 (cdr (org-element-contents table-row
)))))
3021 (defun org-html-table--table.el-table
(table info
)
3022 "Format table.el tables into HTML.
3023 INFO is a plist used as a communication channel."
3024 (when (eq (org-element-property :type table
) 'table.el
)
3026 (let ((outbuf (with-current-buffer
3027 (get-buffer-create "*org-export-table*")
3028 (erase-buffer) (current-buffer))))
3030 (insert (org-element-property :value table
))
3032 (re-search-forward "^[ \t]*|[^|]" nil t
)
3033 (table-generate-source 'html outbuf
))
3034 (with-current-buffer outbuf
3035 (prog1 (org-trim (buffer-string))
3038 (defun org-html-table (table contents info
)
3039 "Transcode a TABLE element from Org to HTML.
3040 CONTENTS is the contents of the table. INFO is a plist holding
3041 contextual information."
3042 (case (org-element-property :type table
)
3043 ;; Case 1: table.el table. Convert it using appropriate tools.
3044 (table.el
(org-html-table--table.el-table table info
))
3045 ;; Case 2: Standard table.
3047 (let* ((label (org-element-property :name table
))
3048 (caption (org-export-get-caption table
))
3050 (org-html--make-attribute-string
3052 (and label
(list :id
(org-export-solidify-link-text label
)))
3053 (plist-get info
:html-table-attributes
)
3054 (org-export-read-attribute :attr_html table
))))
3056 (if (and (boundp 'org-html-format-table-no-css
)
3057 org-html-format-table-no-css
)
3058 "align=\"%s\"" "class=\"%s\""))
3061 (lambda (table info
)
3063 (lambda (table-cell)
3064 (let ((alignment (org-export-table-cell-alignment
3067 ;; Begin a colgroup?
3068 (when (org-export-table-cell-starts-colgroup-p
3071 ;; Add a column. Also specify it's alignment.
3072 (format "\n<col %s/>" (format alignspec alignment
))
3074 (when (org-export-table-cell-ends-colgroup-p
3077 (org-html-table-first-row-data-cells table info
) "\n")))))
3078 (format "<table%s>\n%s\n%s\n%s</table>"
3079 (if (equal attributes
"") "" (concat " " attributes
))
3080 (if (not caption
) ""
3081 (format "<caption>%s</caption>"
3082 (org-export-data caption info
)))
3083 (funcall table-column-specs table info
)
3088 (defun org-html-target (target contents info
)
3089 "Transcode a TARGET object from Org to HTML.
3090 CONTENTS is nil. INFO is a plist holding contextual
3092 (let ((id (org-export-solidify-link-text
3093 (org-element-property :value target
))))
3094 (org-html--anchor id
)))
3098 (defun org-html-timestamp (timestamp contents info
)
3099 "Transcode a TIMESTAMP object from Org to HTML.
3100 CONTENTS is nil. INFO is a plist holding contextual
3102 (let ((value (org-html-plain-text
3103 (org-timestamp-translate timestamp
) info
)))
3104 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3105 (replace-regexp-in-string "--" "–" value
))))
3109 (defun org-html-underline (underline contents info
)
3110 "Transcode UNDERLINE from Org to HTML.
3111 CONTENTS is the text with underline markup. INFO is a plist
3112 holding contextual information."
3113 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3118 (defun org-html-verbatim (verbatim contents info
)
3119 "Transcode VERBATIM from Org to HTML.
3120 CONTENTS is nil. INFO is a plist holding contextual
3122 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3123 (org-html-plain-text (org-element-property :value verbatim
) info
)))
3127 (defun org-html-verse-block (verse-block contents info
)
3128 "Transcode a VERSE-BLOCK element from Org to HTML.
3129 CONTENTS is verse block contents. INFO is a plist holding
3130 contextual information."
3131 ;; Replace each newline character with line break. Also replace
3132 ;; each blank line with a line break.
3133 (setq contents
(replace-regexp-in-string
3134 "^ *\\\\\\\\$" "<br/>\n"
3135 (replace-regexp-in-string
3136 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3137 ;; Replace each white space at beginning of a line with a
3138 ;; non-breaking space.
3139 (while (string-match "^[ \t]+" contents
)
3140 (let* ((num-ws (length (match-string 0 contents
)))
3141 (ws (let (out) (dotimes (i num-ws out
)
3142 (setq out
(concat out
" "))))))
3143 (setq contents
(replace-match ws nil t contents
))))
3144 (format "<p class=\"verse\">\n%s</p>" contents
))
3147 ;;; Filter Functions
3149 (defun org-html-final-function (contents backend info
)
3150 "Filter to indent the HTML and convert HTML entities."
3155 (indent-region (point-min) (point-max)))
3156 (when org-html-use-unicode-chars
3158 (mm-url-decode-entities))
3159 (buffer-substring-no-properties (point-min) (point-max))))
3162 ;;; End-user functions
3165 (defun org-html-export-as-html
3166 (&optional async subtreep visible-only body-only ext-plist
)
3167 "Export current buffer to an HTML buffer.
3169 If narrowing is active in the current buffer, only export its
3172 If a region is active, export that region.
3174 A non-nil optional argument ASYNC means the process should happen
3175 asynchronously. The resulting buffer should be accessible
3176 through the `org-export-stack' interface.
3178 When optional argument SUBTREEP is non-nil, export the sub-tree
3179 at point, extracting information from the headline properties
3182 When optional argument VISIBLE-ONLY is non-nil, don't export
3183 contents of hidden elements.
3185 When optional argument BODY-ONLY is non-nil, only write code
3186 between \"<body>\" and \"</body>\" tags.
3188 EXT-PLIST, when provided, is a property list with external
3189 parameters overriding Org default settings, but still inferior to
3190 file-local settings.
3192 Export is done in a buffer named \"*Org HTML Export*\", which
3193 will be displayed when `org-export-show-temporary-export-buffer'
3197 (org-export-async-start
3199 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3202 (goto-char (point-min))
3204 (org-export-add-to-stack (current-buffer) 'html
)))
3205 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3206 (let ((outbuf (org-export-to-buffer
3207 'html
"*Org HTML Export*"
3208 subtreep visible-only body-only ext-plist
)))
3210 (with-current-buffer outbuf
(set-auto-mode t
))
3211 (when org-export-show-temporary-export-buffer
3212 (switch-to-buffer-other-window outbuf
)))))
3215 (defun org-html-convert-region-to-html ()
3216 "Assume the current region has org-mode syntax, and convert it to HTML.
3217 This can be used in any buffer. For example, you can write an
3218 itemized list in org-mode syntax in an HTML buffer and use this
3219 command to convert it."
3221 (org-export-replace-region-by 'html
))
3224 (defun org-html-export-to-html
3225 (&optional async subtreep visible-only body-only ext-plist
)
3226 "Export current buffer to a HTML file.
3228 If narrowing is active in the current buffer, only export its
3231 If a region is active, export that region.
3233 A non-nil optional argument ASYNC means the process should happen
3234 asynchronously. The resulting file should be accessible through
3235 the `org-export-stack' interface.
3237 When optional argument SUBTREEP is non-nil, export the sub-tree
3238 at point, extracting information from the headline properties
3241 When optional argument VISIBLE-ONLY is non-nil, don't export
3242 contents of hidden elements.
3244 When optional argument BODY-ONLY is non-nil, only write code
3245 between \"<body>\" and \"</body>\" tags.
3247 EXT-PLIST, when provided, is a property list with external
3248 parameters overriding Org default settings, but still inferior to
3249 file-local settings.
3251 Return output file's name."
3253 (let* ((extension (concat "." org-html-extension
))
3254 (file (org-export-output-file-name extension subtreep
))
3255 (org-export-coding-system org-html-coding-system
))
3257 (org-export-async-start
3258 (lambda (f) (org-export-add-to-stack f
'html
))
3259 (let ((org-export-coding-system org-html-coding-system
))
3262 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3263 (let ((org-export-coding-system org-html-coding-system
))
3265 'html file subtreep visible-only body-only ext-plist
)))))
3268 (defun org-html-publish-to-html (plist filename pub-dir
)
3269 "Publish an org file to HTML.
3271 FILENAME is the filename of the Org file to be published. PLIST
3272 is the property list for the given project. PUB-DIR is the
3273 publishing directory.
3275 Return output file name."
3276 (org-publish-org-to 'html filename
3277 (concat "." (or (plist-get plist
:html-extension
)
3278 org-html-extension
"html"))
3284 ;;;; org-format-table-html
3285 ;;;; org-format-org-table-html
3286 ;;;; org-format-table-table-html
3287 ;;;; org-table-number-fraction
3288 ;;;; org-table-number-regexp
3289 ;;;; org-html-table-caption-above
3290 ;;;; org-html-inline-image-extensions
3291 ;;;; org-export-preferred-target-alist
3292 ;;;; class for anchors
3293 ;;;; org-export-mark-todo-in-toc
3294 ;;;; org-html-format-org-link
3295 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3296 ;;;; alt = (file-name-nondirectory path)
3301 ;; generated-autoload-file: "org-loaddefs.el"
3304 ;;; ox-html.el ends here