1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 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 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; See Org manual for more information.
35 (require 'format-spec
)
36 (eval-when-compile (require 'cl
) (require 'table nil
'noerror
))
39 ;;; Function Declarations
41 (declare-function org-id-find-id-file
"org-id" (id))
42 (declare-function htmlize-region
"ext:htmlize" (beg end
))
43 (declare-function org-pop-to-buffer-same-window
44 "org-compat" (&optional buffer-or-name norecord label
))
45 (declare-function mm-url-decode-entities
"mm-url" ())
49 (org-export-define-backend 'html
50 '((bold . org-html-bold
)
51 (center-block . org-html-center-block
)
52 (clock . org-html-clock
)
53 (code . org-html-code
)
54 (drawer . org-html-drawer
)
55 (dynamic-block . org-html-dynamic-block
)
56 (entity . org-html-entity
)
57 (example-block . org-html-example-block
)
58 (export-block . org-html-export-block
)
59 (export-snippet . org-html-export-snippet
)
60 (fixed-width . org-html-fixed-width
)
61 (footnote-definition . org-html-footnote-definition
)
62 (footnote-reference . org-html-footnote-reference
)
63 (headline . org-html-headline
)
64 (horizontal-rule . org-html-horizontal-rule
)
65 (inline-src-block . org-html-inline-src-block
)
66 (inlinetask . org-html-inlinetask
)
67 (inner-template . org-html-inner-template
)
68 (italic . org-html-italic
)
69 (item . org-html-item
)
70 (keyword . org-html-keyword
)
71 (latex-environment . org-html-latex-environment
)
72 (latex-fragment . org-html-latex-fragment
)
73 (line-break . org-html-line-break
)
74 (link . org-html-link
)
75 (node-property . org-html-node-property
)
76 (paragraph . org-html-paragraph
)
77 (plain-list . org-html-plain-list
)
78 (plain-text . org-html-plain-text
)
79 (planning . org-html-planning
)
80 (property-drawer . org-html-property-drawer
)
81 (quote-block . org-html-quote-block
)
82 (radio-target . org-html-radio-target
)
83 (section . org-html-section
)
84 (special-block . org-html-special-block
)
85 (src-block . org-html-src-block
)
86 (statistics-cookie . org-html-statistics-cookie
)
87 (strike-through . org-html-strike-through
)
88 (subscript . org-html-subscript
)
89 (superscript . org-html-superscript
)
90 (table . org-html-table
)
91 (table-cell . org-html-table-cell
)
92 (table-row . org-html-table-row
)
93 (target . org-html-target
)
94 (template . org-html-template
)
95 (timestamp . org-html-timestamp
)
96 (underline . org-html-underline
)
97 (verbatim . org-html-verbatim
)
98 (verse-block . org-html-verse-block
))
100 :filters-alist
'((:filter-options . org-html-infojs-install-script
)
101 (:filter-final-output . org-html-final-function
))
103 '(?h
"Export to HTML"
104 ((?H
"As HTML buffer" org-html-export-as-html
)
105 (?h
"As HTML file" org-html-export-to-html
)
106 (?o
"As HTML file and open"
108 (if a
(org-html-export-to-html t s v b
)
109 (org-open-file (org-html-export-to-html nil s v b
)))))))
111 '((:html-doctype
"HTML_DOCTYPE" nil org-html-doctype
)
112 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
113 (:html-html5-fancy nil
"html5-fancy" org-html-html5-fancy
)
114 (:html-link-use-abs-url nil
"html-link-use-abs-url" org-html-link-use-abs-url
)
115 (:html-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
116 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
117 (:html-head
"HTML_HEAD" nil org-html-head newline
)
118 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
119 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
120 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
121 (:html-html5-fancy nil
"html5-fancy" org-html-html5-fancy
)
122 (:html-link-use-abs-url nil
"html-link-use-abs-url" org-html-link-use-abs-url
)
123 (:html-postamble nil
"html-postamble" org-html-postamble
)
124 (:html-preamble nil
"html-preamble" org-html-preamble
)
125 (:html-head
"HTML_HEAD" nil org-html-head newline
)
126 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
127 (:html-head-include-default-style
128 nil
"html-style" org-html-head-include-default-style
)
129 (:html-head-include-scripts nil
"html-scripts" org-html-head-include-scripts
)
130 (:html-allow-name-attribute-in-anchors
131 nil nil org-html-allow-name-attribute-in-anchors
)
132 (:html-divs nil nil org-html-divs
)
133 (:html-checkbox-type nil nil org-html-checkbox-type
)
134 (:html-extension nil nil org-html-extension
)
135 (:html-footnote-format nil nil org-html-footnote-format
)
136 (:html-footnote-separator nil nil org-html-footnote-separator
)
137 (:html-footnotes-section nil nil org-html-footnotes-section
)
138 (:html-format-drawer-function nil nil org-html-format-drawer-function
)
139 (:html-format-headline-function nil nil org-html-format-headline-function
)
140 (:html-format-inlinetask-function
141 nil nil org-html-format-inlinetask-function
)
142 (:html-home
/up-format nil nil org-html-home
/up-format
)
143 (:html-indent nil nil org-html-indent
)
144 (:html-infojs-options nil nil org-html-infojs-options
)
145 (:html-infojs-template nil nil org-html-infojs-template
)
146 (:html-inline-image-rules nil nil org-html-inline-image-rules
)
147 (:html-link-org-files-as-html nil nil org-html-link-org-files-as-html
)
148 (:html-mathjax-options nil nil org-html-mathjax-options
)
149 (:html-mathjax-template nil nil org-html-mathjax-template
)
150 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format
)
151 (:html-postamble-format nil nil org-html-postamble-format
)
152 (:html-preamble-format nil nil org-html-preamble-format
)
153 (:html-table-align-individual-fields
154 nil nil org-html-table-align-individual-fields
)
155 (:html-table-caption-above nil nil org-html-table-caption-above
)
156 (:html-table-data-tags nil nil org-html-table-data-tags
)
157 (:html-table-header-tags nil nil org-html-table-header-tags
)
158 (:html-table-use-header-tags-for-first-column
159 nil nil org-html-table-use-header-tags-for-first-column
)
160 (:html-tag-class-prefix nil nil org-html-tag-class-prefix
)
161 (:html-text-markup-alist nil nil org-html-text-markup-alist
)
162 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix
)
163 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel
)
164 (:html-use-infojs nil nil org-html-use-infojs
)
165 (:html-use-unicode-chars nil nil org-html-use-unicode-chars
)
166 (:html-validation-link nil nil org-html-validation-link
)
167 (:html-inline-images nil nil org-html-inline-images
)
168 (:html-table-attributes nil nil org-html-table-default-attributes
)
169 (:html-table-row-tags nil nil org-html-table-row-tags
)
170 (:html-xml-declaration nil nil org-html-xml-declaration
)
171 (:infojs-opt
"INFOJS_OPT" nil nil
)
172 ;; Redefine regular options.
173 (:creator
"CREATOR" nil org-html-creator-string
)
174 (:with-latex nil
"tex" org-html-with-latex
)
175 ;; Retrieve LaTeX header for fragments.
176 (:latex-header
"LATEX_HEADER" nil nil newline
)))
179 ;;; Internal Variables
181 (defvar org-html-format-table-no-css
)
182 (defvar htmlize-buffer-places
) ; from htmlize.el
184 (defvar org-html--pre
/postamble-class
"status"
185 "CSS class used for pre/postamble")
187 (defconst org-html-doctype-alist
188 '(("html4-strict" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
189 \"http://www.w3.org/TR/html4/strict.dtd\">")
190 ("html4-transitional" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
191 \"http://www.w3.org/TR/html4/loose.dtd\">")
192 ("html4-frameset" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
193 \"http://www.w3.org/TR/html4/frameset.dtd\">")
195 ("xhtml-strict" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
196 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
197 ("xhtml-transitional" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
198 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
199 ("xhtml-frameset" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
200 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
201 ("xhtml-11" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
202 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
204 ("html5" .
"<!DOCTYPE html>")
205 ("xhtml5" .
"<!DOCTYPE html>"))
206 "An alist mapping (x)html flavors to specific doctypes.")
208 (defconst org-html-html5-elements
209 '("article" "aside" "audio" "canvas" "details" "figcaption"
210 "figure" "footer" "header" "menu" "meter" "nav" "output"
211 "progress" "section" "video")
212 "New elements in html5.
214 For blocks that should contain headlines, use the HTML_CONTAINER
215 property on the headline itself.")
217 (defconst org-html-special-string-regexps
218 '(("\\\\-" .
"­") ; shy
219 ("---\\([^-]\\)" .
"—\\1") ; mdash
220 ("--\\([^-]\\)" .
"–\\1") ; ndash
221 ("\\.\\.\\." .
"…")) ; hellip
222 "Regular expressions for special string conversion.")
224 (defconst org-html-scripts
225 "<script type=\"text/javascript\">
227 @licstart The following is the entire license notice for the
228 JavaScript code in this tag.
230 Copyright (C) 2012-2013 Free Software Foundation, Inc.
232 The JavaScript code in this tag is free software: you can
233 redistribute it and/or modify it under the terms of the GNU
234 General Public License (GNU GPL) as published by the Free Software
235 Foundation, either version 3 of the License, or (at your option)
236 any later version. The code is distributed WITHOUT ANY WARRANTY;
237 without even the implied warranty of MERCHANTABILITY or FITNESS
238 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
240 As additional permission under GNU GPL version 3 section 7, you
241 may distribute non-source (e.g., minimized or compacted) forms of
242 that code without the copy of the GNU GPL normally required by
243 section 4, provided you include this license notice and a URL
244 through which recipients can access the Corresponding Source.
247 @licend The above is the entire license notice
248 for the JavaScript code in this tag.
250 <!--/*--><![CDATA[/*><!--*/
251 function CodeHighlightOn(elem, id)
253 var target = document.getElementById(id);
255 elem.cacheClassElem = elem.className;
256 elem.cacheClassTarget = target.className;
257 target.className = \"code-highlighted\";
258 elem.className = \"code-highlighted\";
261 function CodeHighlightOff(elem, id)
263 var target = document.getElementById(id);
264 if(elem.cacheClassElem)
265 elem.className = elem.cacheClassElem;
266 if(elem.cacheClassTarget)
267 target.className = elem.cacheClassTarget;
271 "Basic JavaScript that is needed by HTML files produced by Org mode.")
273 (defconst org-html-style-default
274 "<style type=\"text/css\">
275 <!--/*--><![CDATA[/*><!--*/
276 .title { text-align: center; }
277 .todo { font-family: monospace; color: red; }
278 .done { color: green; }
279 .tag { background-color: #eee; font-family: monospace;
280 padding: 2px; font-size: 80%; font-weight: normal; }
281 .timestamp { color: #bebebe; }
282 .timestamp-kwd { color: #5f9ea0; }
283 .right { margin-left: auto; margin-right: 0px; text-align: right; }
284 .left { margin-left: 0px; margin-right: auto; text-align: left; }
285 .center { margin-left: auto; margin-right: auto; text-align: center; }
286 .underline { text-decoration: underline; }
287 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
288 p.verse { margin-left: 3%; }
290 border: 1px solid #ccc;
291 box-shadow: 3px 3px 3px #eee;
293 font-family: monospace;
305 background-color: white;
309 border: 1px solid black;
311 pre.src:hover:before { display: inline;}
312 pre.src-sh:before { content: 'sh'; }
313 pre.src-bash:before { content: 'sh'; }
314 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
315 pre.src-R:before { content: 'R'; }
316 pre.src-perl:before { content: 'Perl'; }
317 pre.src-java:before { content: 'Java'; }
318 pre.src-sql:before { content: 'SQL'; }
320 table { border-collapse:collapse; }
321 caption.t-above { caption-side: top; }
322 caption.t-bottom { caption-side: bottom; }
323 td, th { vertical-align:top; }
324 th.right { text-align: center; }
325 th.left { text-align: center; }
326 th.center { text-align: center; }
327 td.right { text-align: right; }
328 td.left { text-align: left; }
329 td.center { text-align: center; }
330 dt { font-weight: bold; }
331 .footpara:nth-child(2) { display: inline; }
332 .footpara { display: block; }
333 .footdef { margin-bottom: 1em; }
334 .figure { padding: 1em; }
335 .figure p { text-align: center; }
338 border: 2px solid gray;
343 { text-align: right; font-size: 70%; white-space: nowrap; }
344 textarea { overflow-x: auto; }
345 .linenr { font-size: smaller }
346 .code-highlighted { background-color: #ffff00; }
347 .org-info-js_info-navigation { border-style: none; }
348 #org-info-js_console-label
349 { font-size: 10px; font-weight: bold; white-space: nowrap; }
350 .org-info-js_search-highlight
351 { background-color: #ffff00; color: #000000; font-weight: bold; }
354 "The default style specification for exported HTML files.
355 You can use `org-html-head' and `org-html-head-extra' to add to
356 this style. If you don't want to include this default style,
357 customize `org-html-head-include-default-style'.")
360 ;;; User Configuration Variables
362 (defgroup org-export-html nil
363 "Options for exporting Org mode files to HTML."
364 :tag
"Org Export HTML"
369 (defvar org-html-infojs-opts-table
370 '((path PATH
"http://orgmode.org/org-info.js")
374 (tdepth TOC_DEPTH
"max")
375 (sdepth SECTION_DEPTH
"max")
376 (mouse MOUSE_HINT
"underline")
377 (buttons VIEW_BUTTONS
"0")
379 (up LINK_UP
:html-link-up
)
380 (home LINK_HOME
:html-link-home
))
381 "JavaScript options, long form for script, default values.")
383 (defcustom org-html-use-infojs
'when-configured
384 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
385 This option can be nil or t to never or always use the script.
386 It can also be the symbol `when-configured', meaning that the
387 script will be linked into the export file if and only if there
388 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
389 `org-html-infojs-options'."
390 :group
'org-export-html
392 :package-version
'(Org .
"8.0")
394 (const :tag
"Never" nil
)
395 (const :tag
"When configured in buffer" when-configured
)
396 (const :tag
"Always" t
)))
398 (defcustom org-html-infojs-options
399 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
400 "Options settings for the INFOJS JavaScript.
401 Each of the options must have an entry in `org-html-infojs-opts-table'.
402 The value can either be a string that will be passed to the script, or
403 a property. This property is then assumed to be a property that is defined
404 by the Export/Publishing setup of Org.
405 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
406 means to use the maximum value consistent with other options."
407 :group
'org-export-html
409 :package-version
'(Org .
"8.0")
411 `(set :greedy t
:inline t
414 (list 'cons
(list 'const
(car x
))
416 (symbol :tag
"Publishing/Export property")
417 (string :tag
"Value"))))
418 org-html-infojs-opts-table
)))
420 (defcustom org-html-infojs-template
421 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
424 * @source: %SCRIPT_PATH
426 * @licstart The following is the entire license notice for the
427 * JavaScript code in %SCRIPT_PATH.
429 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
432 * The JavaScript code in this tag is free software: you can
433 * redistribute it and/or modify it under the terms of the GNU
434 * General Public License (GNU GPL) as published by the Free Software
435 * Foundation, either version 3 of the License, or (at your option)
436 * any later version. The code is distributed WITHOUT ANY WARRANTY;
437 * without even the implied warranty of MERCHANTABILITY or FITNESS
438 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
440 * As additional permission under GNU GPL version 3 section 7, you
441 * may distribute non-source (e.g., minimized or compacted) forms of
442 * that code without the copy of the GNU GPL normally required by
443 * section 4, provided you include this license notice and a URL
444 * through which recipients can access the Corresponding Source.
446 * @licend The above is the entire license notice
447 * for the JavaScript code in %SCRIPT_PATH.
452 <script type=\"text/javascript\">
455 @licstart The following is the entire license notice for the
456 JavaScript code in this tag.
458 Copyright (C) 2012-2013 Free Software Foundation, Inc.
460 The JavaScript code in this tag is free software: you can
461 redistribute it and/or modify it under the terms of the GNU
462 General Public License (GNU GPL) as published by the Free Software
463 Foundation, either version 3 of the License, or (at your option)
464 any later version. The code is distributed WITHOUT ANY WARRANTY;
465 without even the implied warranty of MERCHANTABILITY or FITNESS
466 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
468 As additional permission under GNU GPL version 3 section 7, you
469 may distribute non-source (e.g., minimized or compacted) forms of
470 that code without the copy of the GNU GPL normally required by
471 section 4, provided you include this license notice and a URL
472 through which recipients can access the Corresponding Source.
475 @licend The above is the entire license notice
476 for the JavaScript code in this tag.
479 <!--/*--><![CDATA[/*><!--*/
481 org_html_manager.setup(); // activate after the parameters are set
484 "The template for the export style additions when org-info.js is used.
485 Option settings will replace the %MANAGER-OPTIONS cookie."
486 :group
'org-export-html
488 :package-version
'(Org .
"8.0")
491 (defun org-html-infojs-install-script (exp-plist backend
)
492 "Install script in export options when appropriate.
493 EXP-PLIST is a plist containing export options. BACKEND is the
494 export back-end currently used."
495 (unless (or (memq 'body-only
(plist-get exp-plist
:export-options
))
496 (not (plist-get exp-plist
:html-use-infojs
))
497 (and (eq (plist-get exp-plist
:html-use-infojs
) 'when-configured
)
498 (let ((opt (plist-get exp-plist
:infojs-opt
)))
501 (string-match "\\<view:nil\\>" opt
)))))
502 (let* ((template (plist-get exp-plist
:html-infojs-template
))
503 (ptoc (plist-get exp-plist
:with-toc
))
504 (hlevels (plist-get exp-plist
:headline-levels
))
506 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
507 (options (plist-get exp-plist
:infojs-opt
))
508 (infojs-opt (plist-get exp-plist
:html-infojs-options
))
509 (table org-html-infojs-opts-table
)
511 (dolist (entry table
)
512 (let* ((opt (car entry
))
514 ;; Compute default values for script option OPT from
515 ;; `org-html-infojs-options' variable.
517 (let ((default (cdr (assq opt infojs-opt
))))
518 (if (and (symbolp default
) (not (memq default
'(t nil
))))
519 (plist-get exp-plist default
)
521 ;; Value set through INFOJS_OPT keyword has precedence
522 ;; over the default one.
523 (val (if (and options
524 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
526 (match-string 1 options
)
530 (replace-regexp-in-string
531 "%SCRIPT_PATH" val template t t
)))
532 (sdepth (when (integerp (read val
))
533 (setq sdepth
(min (read val
) sdepth
))))
534 (tdepth (when (integerp (read val
))
535 (setq tdepth
(min (read val
) tdepth
))))
538 ((or (eq val t
) (equal val
"t")) "1")
539 ((or (eq val nil
) (equal val
"nil")) "0")
541 (t (format "%s" val
))))
542 (push (cons var val
) style
)))))
543 ;; Now we set the depth of the *generated* TOC to SDEPTH,
544 ;; because the toc will actually determine the splitting. How
545 ;; much of the toc will actually be displayed is governed by the
547 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
548 ;; The table of contents should not show more sections than we
550 (setq tdepth
(min tdepth sdepth
))
551 (push (cons "TOC_DEPTH" tdepth
) style
)
552 ;; Build style string.
553 (setq style
(mapconcat
555 (format "org_html_manager.set(\"%s\", \"%s\");"
558 (when (and style
(> (length style
) 0))
559 (and (string-match "%MANAGER_OPTIONS" template
)
560 (setq style
(replace-match style t t template
))
563 exp-plist
:html-head-extra
564 (concat (or (plist-get exp-plist
:html-head-extra
) "")
567 ;; This script absolutely needs the table of contents, so we
568 ;; change that setting.
569 (unless (plist-get exp-plist
:with-toc
)
570 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
571 ;; Return the modified property list.
576 (defcustom org-html-text-markup-alist
577 '((bold .
"<b>%s</b>")
578 (code .
"<code>%s</code>")
579 (italic .
"<i>%s</i>")
580 (strike-through .
"<del>%s</del>")
581 (underline .
"<span class=\"underline\">%s</span>")
582 (verbatim .
"<code>%s</code>"))
583 "Alist of HTML expressions to convert text markup.
585 The key must be a symbol among `bold', `code', `italic',
586 `strike-through', `underline' and `verbatim'. The value is
587 a formatting string to wrap fontified text with.
589 If no association can be found for a given markup, text will be
591 :group
'org-export-html
593 :package-version
'(Org .
"8.0")
594 :type
'(alist :key-type
(symbol :tag
"Markup type")
595 :value-type
(string :tag
"Format string"))
596 :options
'(bold code italic strike-through underline verbatim
))
598 (defcustom org-html-indent nil
599 "Non-nil means to indent the generated HTML.
600 Warning: non-nil may break indentation of source code blocks."
601 :group
'org-export-html
603 :package-version
'(Org .
"8.0")
606 (defcustom org-html-use-unicode-chars nil
607 "Non-nil means to use unicode characters instead of HTML entities."
608 :group
'org-export-html
610 :package-version
'(Org .
"8.0")
615 (defcustom org-html-format-drawer-function
(lambda (name contents
) contents
)
616 "Function called to format a drawer in HTML code.
618 The function must accept two parameters:
619 NAME the drawer name, like \"LOGBOOK\"
620 CONTENTS the contents of the drawer.
622 The function should return the string to be exported.
624 For example, the variable could be set to the following function
625 in order to mimic default behaviour:
627 The default value simply returns the value of CONTENTS."
628 :group
'org-export-html
630 :package-version
'(Org .
"8.0")
635 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
636 <h2 class=\"footnotes\">%s: </h2>
637 <div id=\"text-footnotes\">
641 "Format for the footnotes section.
642 Should contain a two instances of %s. The first will be replaced with the
643 language-specific word for \"Footnotes\", the second one will be replaced
644 by the footnotes themselves."
645 :group
'org-export-html
648 (defcustom org-html-footnote-format
"<sup>%s</sup>"
649 "The format for the footnote reference.
650 %s will be replaced by the footnote reference itself."
651 :group
'org-export-html
654 (defcustom org-html-footnote-separator
"<sup>, </sup>"
655 "Text used to separate footnotes."
656 :group
'org-export-html
661 (defcustom org-html-toplevel-hlevel
2
662 "The <H> level for level 1 headings in HTML export.
663 This is also important for the classes that will be wrapped around headlines
664 and outline structure. If this variable is 1, the top-level headlines will
665 be <h1>, and the corresponding classes will be outline-1, section-number-1,
666 and outline-text-1. If this is 2, all of these will get a 2 instead.
667 The default for this variable is 2, because we use <h1> for formatting the
669 :group
'org-export-html
672 (defcustom org-html-format-headline-function
673 'org-html-format-headline-default-function
674 "Function to format headline text.
676 This function will be called with six arguments:
677 TODO the todo keyword (string or nil).
678 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
679 PRIORITY the priority of the headline (integer or nil)
680 TEXT the main headline text (string).
681 TAGS the tags (string or nil).
682 INFO the export options (plist).
684 The function result will be used in the section format string."
685 :group
'org-export-html
687 :package-version
'(Org .
"8.3")
692 (defcustom org-html-allow-name-attribute-in-anchors nil
693 "When nil, do not set \"name\" attribute in anchors.
694 By default, when appropriate, anchors are formatted with \"id\"
695 but without \"name\" attribute."
696 :group
'org-export-html
698 :package-version
'(Org .
"8.0")
703 (defcustom org-html-format-inlinetask-function
704 'org-html-format-inlinetask-default-function
705 "Function called to format an inlinetask in HTML code.
707 The function must accept seven parameters:
708 TODO the todo keyword, as a string
709 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
710 PRIORITY the inlinetask priority, as a string
711 NAME the inlinetask name, as a string.
712 TAGS the inlinetask tags, as a list of strings.
713 CONTENTS the contents of the inlinetask, as a string.
714 INFO the export options, as a plist
716 The function should return the string to be exported."
717 :group
'org-export-html
719 :package-version
'(Org .
"8.3")
724 (defcustom org-html-with-latex org-export-with-latex
725 "Non-nil means process LaTeX math snippets.
727 When set, the exporter will process LaTeX environments and
730 This option can also be set with the +OPTIONS line,
731 e.g. \"tex:mathjax\". Allowed values are:
733 nil Ignore math snippets.
734 `verbatim' Keep everything in verbatim
735 `dvipng' Process the LaTeX fragments to images. This will also
736 include processing of non-math environments.
737 `imagemagick' Convert the LaTeX fragments to pdf files and use
738 imagemagick to convert pdf files to png files.
739 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
741 t Synonym for `mathjax'."
742 :group
'org-export-html
744 :package-version
'(Org .
"8.0")
746 (const :tag
"Do not process math in any way" nil
)
747 (const :tag
"Use dvipng to make images" dvipng
)
748 (const :tag
"Use imagemagick to make images" imagemagick
)
749 (const :tag
"Use MathJax to display math" mathjax
)
750 (const :tag
"Leave math verbatim" verbatim
)))
752 ;;;; Links :: Generic
754 (defcustom org-html-link-org-files-as-html t
755 "Non-nil means make file links to `file.org' point to `file.html'.
756 When `org-mode' is exporting an `org-mode' file to HTML, links to
757 non-html files are directly put into a href tag in HTML.
758 However, links to other Org-mode files (recognized by the
759 extension `.org.) should become links to the corresponding html
760 file, assuming that the linked `org-mode' file will also be
762 When nil, the links still point to the plain `.org' file."
763 :group
'org-export-html
766 ;;;; Links :: Inline images
768 (defcustom org-html-inline-images t
769 "Non-nil means inline images into exported HTML pages.
770 This is done using an <img> tag. When nil, an anchor with href is used to
772 :group
'org-export-html
774 :package-version
'(Org .
"8.1")
777 (defcustom org-html-inline-image-rules
778 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
779 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
780 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
781 "Rules characterizing image files that can be inlined into HTML.
782 A rule consists in an association whose key is the type of link
783 to consider, and value is a regexp that will be matched against
785 :group
'org-export-html
787 :package-version
'(Org .
"8.0")
788 :type
'(alist :key-type
(string :tag
"Type")
789 :value-type
(regexp :tag
"Path")))
793 (defvar org-html-protect-char-alist
797 "Alist of characters to be converted by `org-html-encode-plain-text'.")
801 (defcustom org-html-htmlize-output-type
'inline-css
802 "Output type to be used by htmlize when formatting code snippets.
803 Choices are `css' to export the CSS selectors only,`inline-css'
804 to export the CSS attribute values inline in the HTML or `nil' to
805 export plain text. We use as default `inline-css', in order to
806 make the resulting HTML self-containing.
808 However, this will fail when using Emacs in batch mode for export, because
809 then no rich font definitions are in place. It will also not be good if
810 people with different Emacs setup contribute HTML files to a website,
811 because the fonts will represent the individual setups. In these cases,
812 it is much better to let Org/Htmlize assign classes only, and to use
813 a style file to define the look of these classes.
814 To get a start for your css file, start Emacs session and make sure that
815 all the faces you are interested in are defined, for example by loading files
816 in all modes you want. Then, use the command
817 \\[org-html-htmlize-generate-css] to extract class definitions."
818 :group
'org-export-html
819 :type
'(choice (const css
) (const inline-css
) (const nil
)))
821 (defcustom org-html-htmlize-font-prefix
"org-"
822 "The prefix for CSS class names for htmlize font specifications."
823 :group
'org-export-html
828 (defcustom org-html-table-default-attributes
829 '(:border
"2" :cellspacing
"0" :cellpadding
"6" :rules
"groups" :frame
"hsides")
830 "Default attributes and values which will be used in table tags.
831 This is a plist where attributes are symbols, starting with
832 colons, and values are strings.
834 When exporting to HTML5, these values will be disregarded."
835 :group
'org-export-html
837 :package-version
'(Org .
"8.0")
838 :type
'(plist :key-type
(symbol :tag
"Property")
839 :value-type
(string :tag
"Value")))
841 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
842 "The opening and ending tags for table header fields.
843 This is customizable so that alignment options can be specified.
844 The first %s will be filled with the scope of the field, either row or col.
845 The second %s will be replaced by a style entry to align the field.
846 See also the variable `org-html-table-use-header-tags-for-first-column'.
847 See also the variable `org-html-table-align-individual-fields'."
848 :group
'org-export-html
849 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
851 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
852 "The opening and ending tags for table data fields.
853 This is customizable so that alignment options can be specified.
854 The first %s will be filled with the scope of the field, either row or col.
855 The second %s will be replaced by a style entry to align the field.
856 See also the variable `org-html-table-align-individual-fields'."
857 :group
'org-export-html
858 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
860 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
861 "The opening and ending tags for table rows.
862 This is customizable so that alignment options can be specified.
863 Instead of strings, these can be Lisp forms that will be
864 evaluated for each row in order to construct the table row tags.
866 During evaluation, these variables will be dynamically bound so that
869 `row-number': row number (0 is the first row)
870 `rowgroup-number': group number of current row
871 `start-rowgroup-p': non-nil means the row starts a group
872 `end-rowgroup-p': non-nil means the row ends a group
873 `top-row-p': non-nil means this is the top row
874 `bottom-row-p': non-nil means this is the bottom row
878 \(setq org-html-table-row-tags
879 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
880 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
881 (t (if (= (mod row-number 2) 1)
882 \"<tr class=\\\"tr-odd\\\">\"
883 \"<tr class=\\\"tr-even\\\">\")))
886 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
887 and the bottom row, and otherwise alternate between \"tr-odd\" and
888 \"tr-even\" for odd and even rows."
889 :group
'org-export-html
891 (choice :tag
"Opening tag"
892 (string :tag
"Specify")
894 (choice :tag
"Closing tag"
895 (string :tag
"Specify")
898 (defcustom org-html-table-align-individual-fields t
899 "Non-nil means attach style attributes for alignment to each table field.
900 When nil, alignment will only be specified in the column tags, but this
901 is ignored by some browsers (like Firefox, Safari). Opera does it right
903 :group
'org-export-html
906 (defcustom org-html-table-use-header-tags-for-first-column nil
907 "Non-nil means format column one in tables with header tags.
908 When nil, also column one will use data tags."
909 :group
'org-export-html
912 (defcustom org-html-table-caption-above t
913 "When non-nil, place caption string at the beginning of the table.
914 Otherwise, place it near the end."
915 :group
'org-export-html
920 (defcustom org-html-tag-class-prefix
""
921 "Prefix to class names for TODO keywords.
922 Each tag gets a class given by the tag itself, with this prefix.
923 The default prefix is empty because it is nice to just use the keyword
924 as a class name. But if you get into conflicts with other, existing
925 CSS classes, then this prefix can be very useful."
926 :group
'org-export-html
929 ;;;; Template :: Generic
931 (defcustom org-html-extension
"html"
932 "The extension for exported HTML files."
933 :group
'org-export-html
936 (defcustom org-html-xml-declaration
937 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
938 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
939 "The extension for exported HTML files.
940 %s will be replaced with the charset of the exported file.
941 This may be a string, or an alist with export extensions
942 and corresponding declarations.
944 This declaration only applies when exporting to XHTML."
945 :group
'org-export-html
947 (string :tag
"Single declaration")
948 (repeat :tag
"Dependent on extension"
949 (cons (string :tag
"Extension")
950 (string :tag
"Declaration")))))
952 (defcustom org-html-coding-system
'utf-8
953 "Coding system for HTML export.
954 Use utf-8 as the default value."
955 :group
'org-export-html
957 :package-version
'(Org .
"8.0")
958 :type
'coding-system
)
960 (defcustom org-html-doctype
"xhtml-strict"
961 "Document type definition to use for exported HTML files.
962 Can be set with the in-buffer HTML_DOCTYPE property or for
963 publishing, with :html-doctype."
964 :group
'org-export-html
966 :package-version
'(Org .
"8.0")
969 (mapcar (lambda (x) `(const ,(car x
))) org-html-doctype-alist
)
970 '((string :tag
"Custom doctype" ))))
972 (defcustom org-html-html5-fancy nil
973 "Non-nil means using new HTML5 elements.
974 This variable is ignored for anything other than HTML5 export.
976 For compatibility with Internet Explorer, it's probably a good
977 idea to download some form of the html5shiv (for instance
978 https://code.google.com/p/html5shiv/) and add it to your
979 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
980 versions 8 and below."
981 :group
'org-export-html
983 :package-version
'(Org .
"8.0")
986 (defcustom org-html-container-element
"div"
987 "HTML element to use for wrapping top level sections.
988 Can be set with the in-buffer HTML_CONTAINER property or for
989 publishing, with :html-container.
991 Note that changing the default will prevent you from using
992 org-info.js for your website."
993 :group
'org-export-html
995 :package-version
'(Org .
"8.0")
998 (defcustom org-html-divs
999 '((preamble "div" "preamble")
1000 (content "div" "content")
1001 (postamble "div" "postamble"))
1002 "Alist of the three section elements for HTML export.
1003 The car of each entry is one of 'preamble, 'content or 'postamble.
1004 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1005 section of the exported document.
1007 Note that changing the default will prevent you from using
1008 org-info.js for your website."
1009 :group
'org-export-html
1011 :package-version
'(Org .
"8.0")
1012 :type
'(list :greedy t
1013 (list :tag
"Preamble"
1014 (const :format
"" preamble
)
1015 (string :tag
"element") (string :tag
" id"))
1016 (list :tag
"Content"
1017 (const :format
"" content
)
1018 (string :tag
"element") (string :tag
" id"))
1019 (list :tag
"Postamble" (const :format
"" postamble
)
1020 (string :tag
" id") (string :tag
"element"))))
1022 (defconst org-html-checkbox-types
1024 ((on .
"☑") (off .
"☐") (trans .
"☐")))
1026 ((on .
"<code>[X]</code>")
1027 (off .
"<code>[ ]</code>")
1028 (trans .
"<code>[-]</code>")))
1030 ((on .
"<input type='checkbox' checked='checked' />")
1031 (off .
"<input type='checkbox' />")
1032 (trans .
"<input type='checkbox' />"))))
1033 "Alist of checkbox types.
1034 The cdr of each entry is an alist list three checkbox types for
1035 HTML export: `on', `off' and `trans'.
1038 `unicode' Unicode characters (HTML entities)
1039 `ascii' ASCII characters
1040 `html' HTML checkboxes
1042 Note that only the ascii characters implement tri-state
1043 checkboxes. The other two use the `off' checkbox for `trans'.")
1045 (defcustom org-html-checkbox-type
'ascii
1046 "The type of checkboxes to use for HTML export.
1047 See `org-html-checkbox-types' for for the values used for each
1049 :group
'org-export-html
1051 :package-version
'(Org .
"8.0")
1053 (const :tag
"ASCII characters" ascii
)
1054 (const :tag
"Unicode characters" unicode
)
1055 (const :tag
"HTML checkboxes" html
)))
1057 (defcustom org-html-metadata-timestamp-format
"%Y-%m-%d %a %H:%M"
1058 "Format used for timestamps in preamble, postamble and metadata.
1059 See `format-time-string' for more information on its components."
1060 :group
'org-export-html
1062 :package-version
'(Org .
"8.0")
1065 ;;;; Template :: Mathjax
1067 (defcustom org-html-mathjax-options
1068 '((path "http://orgmode.org/mathjax/MathJax.js")
1073 "Options for MathJax setup.
1075 path The path where to find MathJax
1076 scale Scaling for the HTML-CSS backend, usually between 100 and 133
1077 align How to align display math: left, center, or right
1078 indent If align is not center, how far from the left/right side?
1079 mathml Should a MathML player be used if available?
1080 This is faster and reduces bandwidth use, but currently
1081 sometimes has lower spacing quality. Therefore, the default is
1082 nil. When browsers get better, this switch can be flipped.
1084 You can also customize this for each buffer, using something like
1086 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1087 :group
'org-export-html
1088 :type
'(list :greedy t
1089 (list :tag
"path (the path from where to load MathJax.js)"
1090 (const :format
" " path
) (string))
1091 (list :tag
"scale (scaling for the displayed math)"
1092 (const :format
" " scale
) (string))
1093 (list :tag
"align (alignment of displayed equations)"
1094 (const :format
" " align
) (string))
1095 (list :tag
"indent (indentation with left or right alignment)"
1096 (const :format
" " indent
) (string))
1097 (list :tag
"mathml (should MathML display be used is possible)"
1098 (const :format
" " mathml
) (boolean))))
1100 (defcustom org-html-mathjax-template
1101 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1102 <script type=\"text/javascript\">
1103 <!--/*--><![CDATA[/*><!--*/
1104 MathJax.Hub.Config({
1105 // Only one of the two following lines, depending on user settings
1106 // First allows browser-native MathML display, second forces HTML/CSS
1107 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1108 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1109 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1110 \"TeX/noUndefined.js\"],
1112 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1113 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1114 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1115 ignoreClass: \"tex2jax_ignore\",
1116 processEscapes: false,
1117 processEnvironments: true,
1120 showProcessingMessages: true,
1121 displayAlign: \"%ALIGN\",
1122 displayIndent: \"%INDENT\",
1126 availableFonts: [\"STIX\",\"TeX\"],
1127 preferredFont: \"TeX\",
1143 "The MathJax setup for XHTML files."
1144 :group
'org-export-html
1147 ;;;; Template :: Postamble
1149 (defcustom org-html-postamble
'auto
1150 "Non-nil means insert a postamble in HTML export.
1152 When set to 'auto, check against the
1153 `org-export-with-author/email/creator/date' variables to set the
1154 content of the postamble. When set to a string, use this string
1155 as the postamble. When t, insert a string as defined by the
1156 formatting string in `org-html-postamble-format'.
1158 When set to a function, apply this function and insert the
1159 returned string. The function takes the property list of export
1160 options as its only argument.
1162 Setting :html-postamble in publishing projects will take
1163 precedence over this variable."
1164 :group
'org-export-html
1165 :type
'(choice (const :tag
"No postamble" nil
)
1166 (const :tag
"Auto postamble" auto
)
1167 (const :tag
"Default formatting string" t
)
1168 (string :tag
"Custom formatting string")
1169 (function :tag
"Function (must return a string)")))
1171 (defcustom org-html-postamble-format
1172 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1173 <p class=\"date\">Date: %d</p>
1174 <p class=\"creator\">%c</p>
1175 <p class=\"validation\">%v</p>"))
1176 "Alist of languages and format strings for the HTML postamble.
1178 The first element of each list is the language code, as used for
1179 the LANGUAGE keyword. See `org-export-default-language'.
1181 The second element of each list is a format string to format the
1182 postamble itself. This format string can contain these elements:
1184 %t stands for the title.
1185 %a stands for the author's name.
1186 %e stands for the author's email.
1187 %d stands for the date.
1188 %c will be replaced by `org-html-creator-string'.
1189 %v will be replaced by `org-html-validation-link'.
1190 %T will be replaced by the export time.
1191 %C will be replaced by the last modification time.
1193 If you need to use a \"%\" character, you need to escape it
1195 :group
'org-export-html
1197 (list (string :tag
"Language")
1198 (string :tag
"Format string"))))
1200 (defcustom org-html-validation-link
1201 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1202 "Link to HTML validation service."
1203 :group
'org-export-html
1206 (defcustom org-html-creator-string
1207 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1209 (if (fboundp 'org-version
) (org-version) "unknown version"))
1210 "Information about the creator of the HTML document.
1211 This option can also be set on with the CREATOR keyword."
1212 :group
'org-export-html
1214 :package-version
'(Org .
"8.0")
1215 :type
'(string :tag
"Creator string"))
1217 ;;;; Template :: Preamble
1219 (defcustom org-html-preamble t
1220 "Non-nil means insert a preamble in HTML export.
1222 When t, insert a string as defined by the formatting string in
1223 `org-html-preamble-format'. When set to a string, use this
1224 formatting string instead (see `org-html-postamble-format' for an
1225 example of such a formatting string).
1227 When set to a function, apply this function and insert the
1228 returned string. The function takes the property list of export
1229 options as its only argument.
1231 Setting :html-preamble in publishing projects will take
1232 precedence over this variable."
1233 :group
'org-export-html
1234 :type
'(choice (const :tag
"No preamble" nil
)
1235 (const :tag
"Default preamble" t
)
1236 (string :tag
"Custom formatting string")
1237 (function :tag
"Function (must return a string)")))
1239 (defcustom org-html-preamble-format
'(("en" ""))
1240 "Alist of languages and format strings for the HTML preamble.
1242 The first element of each list is the language code, as used for
1243 the LANGUAGE keyword. See `org-export-default-language'.
1245 The second element of each list is a format string to format the
1246 preamble itself. This format string can contain these elements:
1248 %t stands for the title.
1249 %a stands for the author's name.
1250 %e stands for the author's email.
1251 %d stands for the date.
1252 %c will be replaced by `org-html-creator-string'.
1253 %v will be replaced by `org-html-validation-link'.
1254 %T will be replaced by the export time.
1255 %C will be replaced by the last modification time.
1257 If you need to use a \"%\" character, you need to escape it
1260 See the default value of `org-html-postamble-format' for an
1262 :group
'org-export-html
1264 (list (string :tag
"Language")
1265 (string :tag
"Format string"))))
1267 (defcustom org-html-link-up
""
1268 "Where should the \"UP\" link of exported HTML pages lead?"
1269 :group
'org-export-html
1270 :type
'(string :tag
"File or URL"))
1272 (defcustom org-html-link-home
""
1273 "Where should the \"HOME\" link of exported HTML pages lead?"
1274 :group
'org-export-html
1275 :type
'(string :tag
"File or URL"))
1277 (defcustom org-html-link-use-abs-url nil
1278 "Should we prepend relative links with HTML_LINK_HOME?"
1279 :group
'org-export-html
1281 :package-version
'(Org .
"8.1")
1284 (defcustom org-html-home
/up-format
1285 "<div id=\"org-div-home-and-up\">
1286 <a accesskey=\"h\" href=\"%s\"> UP </a>
1288 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1290 "Snippet used to insert the HOME and UP links.
1291 This is a format string, the first %s will receive the UP link,
1292 the second the HOME link. If both `org-html-link-up' and
1293 `org-html-link-home' are empty, the entire snippet will be
1295 :group
'org-export-html
1298 ;;;; Template :: Scripts
1300 (define-obsolete-variable-alias
1301 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1302 (defcustom org-html-head-include-scripts t
1303 "Non-nil means include the JavaScript snippets in exported HTML files.
1304 The actual script is defined in `org-html-scripts' and should
1306 :group
'org-export-html
1308 :package-version
'(Org .
"8.0")
1311 ;;;; Template :: Styles
1313 (define-obsolete-variable-alias
1314 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1315 (defcustom org-html-head-include-default-style t
1316 "Non-nil means include the default style in exported HTML files.
1317 The actual style is defined in `org-html-style-default' and
1318 should not be modified. Use `org-html-head' to use your own
1320 :group
'org-export-html
1322 :package-version
'(Org .
"8.0")
1325 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1327 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1328 (defcustom org-html-head
""
1329 "Org-wide head definitions for exported HTML files.
1331 This variable can contain the full HTML structure to provide a
1332 style, including the surrounding HTML tags. You can consider
1333 including definitions for the following classes: title, todo,
1334 done, timestamp, timestamp-kwd, tag, target.
1336 For example, a valid value would be:
1338 <style type=\"text/css\">
1340 p { font-weight: normal; color: gray; }
1341 h1 { color: black; }
1342 .title { text-align: center; }
1343 .todo, .timestamp-kwd { color: red; }
1344 .done { color: green; }
1348 If you want to refer to an external style, use something like
1350 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1352 As the value of this option simply gets inserted into the HTML
1353 <head> header, you can use it to add any arbitrary text to the
1356 You can set this on a per-file basis using #+HTML_HEAD:,
1357 or for publication projects using the :html-head property."
1358 :group
'org-export-html
1360 :package-version
'(Org .
"8.0")
1363 (put 'org-html-head
'safe-local-variable
'stringp
)
1365 (defcustom org-html-head-extra
""
1366 "More head information to add in the HTML output.
1368 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1369 or for publication projects using the :html-head-extra property."
1370 :group
'org-export-html
1372 :package-version
'(Org .
"8.0")
1375 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1379 (defcustom org-html-todo-kwd-class-prefix
""
1380 "Prefix to class names for TODO keywords.
1381 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1382 The default prefix is empty because it is nice to just use the keyword
1383 as a class name. But if you get into conflicts with other, existing
1384 CSS classes, then this prefix can be very useful."
1385 :group
'org-export-html
1389 ;;; Internal Functions
1391 (defun org-html-xhtml-p (info)
1392 (let ((dt (downcase (plist-get info
:html-doctype
))))
1393 (string-match-p "xhtml" dt
)))
1395 (defun org-html-html5-p (info)
1396 (let ((dt (downcase (plist-get info
:html-doctype
))))
1397 (member dt
'("html5" "xhtml5" "<!doctype html>"))))
1399 (defun org-html-close-tag (tag attr info
)
1400 (concat "<" tag
" " attr
1401 (if (org-html-xhtml-p info
) " />" ">")))
1403 (defun org-html-doctype (info)
1404 "Return correct html doctype tag from `org-html-doctype-alist',
1405 or the literal value of :html-doctype from INFO if :html-doctype
1406 is not found in the alist.
1407 INFO is a plist used as a communication channel."
1408 (let ((dt (plist-get info
:html-doctype
)))
1409 (or (cdr (assoc dt org-html-doctype-alist
)) dt
)))
1411 (defun org-html--make-attribute-string (attributes)
1412 "Return a list of attributes, as a string.
1413 ATTRIBUTES is a plist where values are either strings or nil. An
1414 attributes with a nil value will be omitted from the result."
1416 (dolist (item attributes
(mapconcat 'identity
(nreverse output
) " "))
1417 (cond ((null item
) (pop output
))
1418 ((symbolp item
) (push (substring (symbol-name item
) 1) output
))
1419 (t (let ((key (car output
))
1420 (value (replace-regexp-in-string
1421 "\"" """ (org-html-encode-plain-text item
))))
1422 (setcar output
(format "%s=\"%s\"" key value
))))))))
1424 (defun org-html--wrap-image (contents info
&optional caption label
)
1425 "Wrap CONTENTS string within an appropriate environment for images.
1426 INFO is a plist used as a communication channel. When optional
1427 arguments CAPTION and LABEL are given, use them for caption and
1429 (let ((html5-fancy (and (org-html-html5-p info
)
1430 (plist-get info
:html-html5-fancy
))))
1431 (format (if html5-fancy
"\n<figure%s>%s%s\n</figure>"
1432 "\n<div%s class=\"figure\">%s%s\n</div>")
1434 (if (not (org-string-nw-p label
)) ""
1435 (format " id=\"%s\"" (org-export-solidify-link-text label
)))
1437 (format "\n<p>%s</p>" contents
)
1439 (if (not (org-string-nw-p caption
)) ""
1440 (format (if html5-fancy
"\n<figcaption>%s</figcaption>"
1444 (defun org-html--format-image (source attributes info
)
1445 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1446 SOURCE is a string specifying the location of the image.
1447 ATTRIBUTES is a plist, as returned by
1448 `org-export-read-attribute'. INFO is a plist used as
1449 a communication channel."
1450 (if (string= "svg" (file-name-extension source
))
1451 (org-html--svg-image source attributes info
)
1454 (org-html--make-attribute-string
1457 :alt
(if (string-match-p "^ltxpng/" source
)
1458 (org-html-encode-plain-text
1459 (org-find-text-property-in-string 'org-latex-src source
))
1460 (file-name-nondirectory source
)))
1464 (defun org-html--svg-image (source attributes info
)
1465 "Return \"object\" appropriate for embedding svg file SOURCE
1466 with assoicated ATTRIBUTES. INFO is a plist used as a
1467 communication channel.
1469 The special attribute \"fallback\" can be used to specify a fallback
1470 image file to use if the object embedding is not supported."
1471 (let ((fallback (plist-get attributes
:fallback
))
1472 (attrs (org-html--make-attribute-string
1473 (plist-put attributes
:fallback nil
))))
1474 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1478 "img" (format "src=\"%s\" %s" fallback attrs
) info
)
1479 "Sorry, your browser does not support SVG."))))
1481 (defun org-html--textarea-block (element)
1482 "Transcode ELEMENT into a textarea block.
1483 ELEMENT is either a src block or an example block."
1484 (let* ((code (car (org-export-unravel-code element
)))
1485 (attr (org-export-read-attribute :attr_html element
)))
1486 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1487 (or (plist-get attr
:width
) 80)
1488 (or (plist-get attr
:height
) (org-count-lines code
))
1491 (defun org-html--has-caption-p (element &optional info
)
1492 "Non-nil when ELEMENT has a caption affiliated keyword.
1493 INFO is a plist used as a communication channel. This function
1494 is meant to be used as a predicate for `org-export-get-ordinal' or
1495 a value to `org-html-standalone-image-predicate'."
1496 (org-element-property :caption element
))
1500 (defun org-html-htmlize-region-for-paste (beg end
)
1501 "Convert the region between BEG and END to HTML, using htmlize.el.
1502 This is much like `htmlize-region-for-paste', only that it uses
1503 the settings define in the org-... variables."
1504 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1505 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1506 (htmlbuf (htmlize-region beg end
)))
1508 (with-current-buffer htmlbuf
1509 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1510 (plist-get htmlize-buffer-places
'content-end
)))
1511 (kill-buffer htmlbuf
))))
1514 (defun org-html-htmlize-generate-css ()
1515 "Create the CSS for all font definitions in the current Emacs session.
1516 Use this to create face definitions in your CSS style file that can then
1517 be used by code snippets transformed by htmlize.
1518 This command just produces a buffer that contains class definitions for all
1519 faces used in the current Emacs session. You can copy and paste the ones you
1520 need into your CSS file.
1522 If you then set `org-html-htmlize-output-type' to `css', calls
1523 to the function `org-html-htmlize-region-for-paste' will
1524 produce code that uses these same face definitions."
1527 (and (get-buffer "*html*") (kill-buffer "*html*"))
1529 (let ((fl (face-list))
1530 (htmlize-css-name-prefix "org-")
1531 (htmlize-output-type 'css
)
1533 (while (setq f
(pop fl
)
1534 i
(and f
(face-attribute f
:inherit
)))
1535 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1536 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1537 (htmlize-region (point-min) (point-max))))
1538 (org-pop-to-buffer-same-window "*html*")
1539 (goto-char (point-min))
1540 (if (re-search-forward "<style" nil t
)
1541 (delete-region (point-min) (match-beginning 0)))
1542 (if (re-search-forward "</style>" nil t
)
1543 (delete-region (1+ (match-end 0)) (point-max)))
1544 (beginning-of-line 1)
1545 (if (looking-at " +") (replace-match ""))
1546 (goto-char (point-min)))
1548 (defun org-html--make-string (n string
)
1549 "Build a string by concatenating N times STRING."
1550 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1552 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1553 "Turn todo keyword KWD into a valid class name.
1554 Replaces invalid characters with \"_\"."
1556 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1557 (setq kwd
(replace-match "_" t t kwd
))))
1560 (defun org-html-footnote-section (info)
1561 "Format the footnote section.
1562 INFO is a plist used as a communication channel."
1563 (let* ((fn-alist (org-export-collect-footnote-definitions
1564 (plist-get info
:parse-tree
) info
))
1566 (loop for
(n type raw
) in fn-alist collect
1567 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1568 (org-trim (org-export-data raw info
))
1570 (org-trim (org-export-data raw info
))))))))
1573 (plist-get info
:html-footnotes-section
)
1574 (org-html--translate "Footnotes" info
)
1579 (let ((n (car fn
)) (def (cdr fn
)))
1581 "<div class=\"footdef\">%s %s</div>\n"
1583 (plist-get info
:html-footnote-format
)
1587 (format " class=\"footnum\" href=\"#fnr.%d\"" n
)
1596 (defun org-html--build-meta-info (info)
1597 "Return meta tags for exported document.
1598 INFO is a plist used as a communication channel."
1599 (let ((protect-string
1601 (replace-regexp-in-string
1602 "\"" """ (org-html-encode-plain-text str
))))
1603 (title (org-export-data (plist-get info
:title
) info
))
1604 (author (and (plist-get info
:with-author
)
1605 (let ((auth (plist-get info
:author
)))
1607 ;; Return raw Org syntax, skipping non
1608 ;; exportable objects.
1609 (org-element-interpret-data
1610 (org-element-map auth
1611 (cons 'plain-text org-element-all-objects
)
1612 'identity info
))))))
1613 (description (plist-get info
:description
))
1614 (keywords (plist-get info
:keywords
))
1615 (charset (or (and org-html-coding-system
1616 (fboundp 'coding-system-get
)
1617 (coding-system-get org-html-coding-system
1621 (format "<title>%s</title>\n" title
)
1622 (when (plist-get info
:time-stamp-file
)
1625 (plist-get info
:html-metadata-timestamp-format
)
1628 (if (org-html-html5-p info
)
1629 (org-html-close-tag "meta" " charset=\"%s\"" info
)
1631 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1634 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info
)
1636 (and (org-string-nw-p author
)
1638 (org-html-close-tag "meta"
1639 (format " name=\"author\" content=\"%s\""
1640 (funcall protect-string author
))
1643 (and (org-string-nw-p description
)
1645 (org-html-close-tag "meta"
1646 (format " name=\"description\" content=\"%s\"\n"
1647 (funcall protect-string description
))
1650 (and (org-string-nw-p keywords
)
1652 (org-html-close-tag "meta"
1653 (format " name=\"keywords\" content=\"%s\""
1654 (funcall protect-string keywords
))
1658 (defun org-html--build-head (info)
1659 "Return information for the <head>..</head> of the HTML output.
1660 INFO is a plist used as a communication channel."
1661 (org-element-normalize-string
1663 (when (plist-get info
:html-head-include-default-style
)
1664 (org-element-normalize-string org-html-style-default
))
1665 (org-element-normalize-string (plist-get info
:html-head
))
1666 (org-element-normalize-string (plist-get info
:html-head-extra
))
1667 (when (and (plist-get info
:html-htmlized-css-url
)
1668 (eq org-html-htmlize-output-type
'css
))
1669 (org-html-close-tag "link"
1670 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1671 (plist-get info
:html-htmlized-css-url
))
1673 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1675 (defun org-html--build-mathjax-config (info)
1676 "Insert the user setup into the mathjax template.
1677 INFO is a plist used as a communication channel."
1678 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1679 (org-element-map (plist-get info
:parse-tree
)
1680 '(latex-fragment latex-environment
) 'identity info t
))
1681 (let ((template (plist-get info
:html-mathjax-template
))
1682 (options (plist-get info
:html-mathjax-options
))
1683 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1684 name val
(yes " ") (no "// ") x
)
1687 (setq name
(car e
) val
(nth 1 e
))
1688 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1689 (setq val
(car (read-from-string
1690 (substring in-buffer
(match-end 0))))))
1691 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1692 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1693 (setq template
(replace-match val t t template
))))
1695 (setq val
(nth 1 (assq 'mathml options
)))
1696 (if (string-match (concat "\\<mathml:") in-buffer
)
1697 (setq val
(car (read-from-string
1698 (substring in-buffer
(match-end 0))))))
1699 ;; Exchange prefixes depending on mathml setting.
1700 (if (not val
) (setq x yes yes no no x
))
1701 ;; Replace cookies to turn on or off the config/jax lines.
1702 (if (string-match ":MMLYES:" template
)
1703 (setq template
(replace-match yes t t template
)))
1704 (if (string-match ":MMLNO:" template
)
1705 (setq template
(replace-match no t t template
)))
1706 ;; Return the modified template.
1707 (org-element-normalize-string template
))))
1709 (defun org-html-format-spec (info)
1710 "Return format specification for elements that can be
1711 used in the preamble or postamble."
1712 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1713 (?d .
,(org-export-data (org-export-get-date info
) info
))
1714 (?T .
,(format-time-string
1715 (plist-get info
:html-metadata-timestamp-format
)))
1716 (?a .
,(org-export-data (plist-get info
:author
) info
))
1719 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1720 (split-string (plist-get info
:email
) ",+ *")
1722 (?c .
,(plist-get info
:creator
))
1723 (?C .
,(let ((file (plist-get info
:input-file
)))
1725 (plist-get info
:html-metadata-timestamp-format
)
1726 (if file
(nth 5 (file-attributes file
)) (current-time)))))
1727 (?v .
,(or (plist-get info
:html-validation-link
) ""))))
1729 (defun org-html--build-pre/postamble
(type info
)
1730 "Return document preamble or postamble as a string, or nil.
1731 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1732 communication channel."
1733 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1734 (spec (org-html-format-spec info
)))
1736 (let ((section-contents
1737 (if (functionp section
) (funcall section info
)
1739 ((stringp section
) (format-spec section spec
))
1741 (let ((date (cdr (assq ?d spec
)))
1742 (author (cdr (assq ?a spec
)))
1743 (email (cdr (assq ?e spec
)))
1744 (creator (cdr (assq ?c spec
)))
1745 (timestamp (cdr (assq ?T spec
)))
1746 (validation-link (cdr (assq ?v spec
))))
1748 (when (and (plist-get info
:with-date
)
1749 (org-string-nw-p date
))
1750 (format "<p class=\"date\">%s: %s</p>\n"
1751 (org-html--translate "Date" info
)
1753 (when (and (plist-get info
:with-author
)
1754 (org-string-nw-p author
))
1755 (format "<p class=\"author\">%s: %s</p>\n"
1756 (org-html--translate "Author" info
)
1758 (when (and (plist-get info
:with-email
)
1759 (org-string-nw-p email
))
1760 (format "<p class=\"email\">%s: %s</p>\n"
1761 (org-html--translate "Email" info
)
1763 (when (plist-get info
:time-stamp-file
)
1765 "<p class=\"date\">%s: %s</p>\n"
1766 (org-html--translate "Created" info
)
1768 (plist-get info
:html-metadata-timestamp-format
))))
1769 (when (plist-get info
:with-creator
)
1770 (format "<p class=\"creator\">%s</p>\n" creator
))
1771 (format "<p class=\"validation\">%s</p>\n"
1775 (plist-get info
:language
)
1777 (format "org-html-%s-format" type
)))))
1782 (intern (format "org-html-%s-format" type
))))))
1784 (let ((div (assq type
(plist-get info
:html-divs
))))
1785 (when (org-string-nw-p section-contents
)
1787 (format "<%s id=\"%s\" class=\"%s\">\n"
1790 org-html--pre
/postamble-class
)
1791 (org-element-normalize-string section-contents
)
1792 (format "</%s>\n" (nth 1 div
)))))))))
1794 (defun org-html-inner-template (contents info
)
1795 "Return body of document string after HTML conversion.
1796 CONTENTS is the transcoded contents string. INFO is a plist
1797 holding export options."
1799 ;; Table of contents.
1800 (let ((depth (plist-get info
:with-toc
)))
1801 (when depth
(org-html-toc depth info
)))
1802 ;; Document contents.
1804 ;; Footnotes section.
1805 (org-html-footnote-section info
)))
1807 (defun org-html-template (contents info
)
1808 "Return complete document string after HTML conversion.
1809 CONTENTS is the transcoded contents string. INFO is a plist
1810 holding export options."
1812 (when (and (not (org-html-html5-p info
)) (org-html-xhtml-p info
))
1813 (let* ((xml-declaration (plist-get info
:html-xml-declaration
))
1814 (decl (or (and (stringp xml-declaration
) xml-declaration
)
1815 (cdr (assoc (plist-get info
:html-extension
)
1817 (cdr (assoc "html" xml-declaration
))
1819 (when (not (or (not decl
) (string= "" decl
)))
1822 (or (and org-html-coding-system
1823 (fboundp 'coding-system-get
)
1824 (coding-system-get org-html-coding-system
'mime-charset
))
1826 (org-html-doctype info
)
1829 (when (org-html-xhtml-p info
)
1831 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1832 (plist-get info
:language
) (plist-get info
:language
)))
1835 (org-html--build-meta-info info
)
1836 (org-html--build-head info
)
1837 (org-html--build-mathjax-config info
)
1840 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1841 (link-home (org-trim (plist-get info
:html-link-home
))))
1842 (unless (and (string= link-up
"") (string= link-home
""))
1843 (format (plist-get info
:html-home
/up-format
)
1844 (or link-up link-home
)
1845 (or link-home link-up
))))
1847 (org-html--build-pre/postamble
'preamble info
)
1848 ;; Document contents.
1849 (let ((div (assq 'content
(plist-get info
:html-divs
))))
1850 (format "<%s id=\"%s\">\n" (nth 1 div
) (nth 2 div
)))
1852 (let ((title (plist-get info
:title
)))
1853 (format "<h1 class=\"title\">%s</h1>\n"
1854 (org-export-data (or title
"") info
)))
1856 (format "</%s>\n" (nth 1 (assq 'content
(plist-get info
:html-divs
))))
1858 (org-html--build-pre/postamble
'postamble info
)
1859 ;; Closing document.
1860 "</body>\n</html>"))
1862 (defun org-html--translate (s info
)
1863 "Translate string S according to specified language.
1864 INFO is a plist used as a communication channel."
1865 (org-export-translate s
:html info
))
1869 (defun org-html--anchor (id desc attributes info
)
1870 "Format a HTML anchor."
1871 (let* ((name (and (plist-get info
:html-allow-name-attribute-in-anchors
) id
))
1872 (attributes (concat (and id
(format " id=\"%s\"" id
))
1873 (and name
(format " name=\"%s\"" name
))
1875 (format "<a%s>%s</a>" attributes
(or desc
""))))
1879 (defun org-html--todo (todo info
)
1880 "Format TODO keywords into HTML."
1882 (format "<span class=\"%s %s%s\">%s</span>"
1883 (if (member todo org-done-keywords
) "done" "todo")
1884 (plist-get info
:html-todo-kwd-class-prefix
)
1885 (org-html-fix-class-name todo
)
1890 (defun org-html--tags (tags info
)
1891 "Format TAGS into HTML.
1892 INFO is a plist containing export options."
1894 (format "<span class=\"tag\">%s</span>"
1897 (format "<span class=\"%s\">%s</span>"
1898 (concat (plist-get info
:html-tag-class-prefix
)
1899 (org-html-fix-class-name tag
))
1905 (defun org-html-fontify-code (code lang
)
1906 "Color CODE with htmlize library.
1907 CODE is a string representing the source code to colorize. LANG
1908 is the language used for CODE, as a string, or nil."
1911 ;; Case 1: No lang. Possibly an example block.
1913 ;; Simple transcoding.
1914 (org-html-encode-plain-text code
))
1915 ;; Case 2: No htmlize or an inferior version of htmlize
1916 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1918 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1919 ;; Simple transcoding.
1920 (org-html-encode-plain-text code
))
1921 ;; Case 3: plain text explicitly set
1922 ((not org-html-htmlize-output-type
)
1923 ;; Simple transcoding.
1924 (org-html-encode-plain-text code
))
1927 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1928 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1930 ;; Case 1: Language is not associated with any Emacs mode
1931 ((not (functionp lang-mode
))
1932 ;; Simple transcoding.
1933 (org-html-encode-plain-text code
))
1934 ;; Case 2: Default. Fontify code.
1937 (setq code
(with-temp-buffer
1938 ;; Switch to language-specific mode.
1940 ;; Disable fci-mode if present
1941 (when (and (fboundp 'fci-mode
)
1942 (require 'fill-column-indicator nil
'noerror
))
1947 ;; Remove formatting on newline characters.
1949 (let ((beg (point-min))
1952 (while (progn (end-of-line) (< (point) end
))
1953 (put-text-property (point) (1+ (point)) 'face nil
)
1956 (set-buffer-modified-p nil
)
1958 (org-html-htmlize-region-for-paste
1959 (point-min) (point-max))))
1960 ;; Strip any enclosing <pre></pre> tags.
1961 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1962 (end (and beg
(string-match "</pre>\\'" code
))))
1963 (if (and beg end
) (substring code beg end
) code
)))))))))
1965 (defun org-html-do-format-code
1966 (code &optional lang refs retain-labels num-start
)
1967 "Format CODE string as source code.
1968 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1969 respectively, the language of the source code, as a string, an
1970 alist between line numbers and references (as returned by
1971 `org-export-unravel-code'), a boolean specifying if labels should
1972 appear in the source code, and the number associated to the first
1974 (let* ((code-lines (org-split-string code
"\n"))
1975 (code-length (length code-lines
))
1979 (length (number-to-string (+ code-length num-start
))))))
1980 (code (org-html-fontify-code code lang
)))
1981 (org-export-format-code
1983 (lambda (loc line-num ref
)
1986 ;; Add line number, if needed.
1988 (format "<span class=\"linenr\">%s</span>"
1989 (format num-fmt line-num
)))
1990 ;; Transcoded src line.
1992 ;; Add label, if needed.
1993 (when (and ref retain-labels
) (format " (%s)" ref
))))
1994 ;; Mark transcoded line as an anchor, if needed.
1996 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2000 (defun org-html-format-code (element info
)
2001 "Format contents of ELEMENT as source code.
2002 ELEMENT is either an example block or a src block. INFO is
2003 a plist used as a communication channel."
2004 (let* ((lang (org-element-property :language element
))
2005 ;; Extract code and references.
2006 (code-info (org-export-unravel-code element
))
2007 (code (car code-info
))
2008 (refs (cdr code-info
))
2009 ;; Does the src block contain labels?
2010 (retain-labels (org-element-property :retain-labels element
))
2011 ;; Does it have line numbers?
2012 (num-start (case (org-element-property :number-lines element
)
2013 (continued (org-export-get-loc element info
))
2015 (org-html-do-format-code code lang refs retain-labels num-start
)))
2018 ;;; Tables of Contents
2020 (defun org-html-toc (depth info
)
2021 "Build a table of contents.
2022 DEPTH is an integer specifying the depth of the table. INFO is a
2023 plist used as a communication channel. Return the table of
2024 contents as a string, or nil if it is empty."
2026 (mapcar (lambda (headline)
2027 (cons (org-html--format-toc-headline headline info
)
2028 (org-export-get-relative-level headline info
)))
2029 (org-export-collect-headlines info depth
)))
2030 (outer-tag (if (and (org-html-html5-p info
)
2031 (plist-get info
:html-html5-fancy
))
2035 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag
)
2036 (let ((top-level (plist-get info
:html-toplevel-hlevel
)))
2037 (format "<h%d>%s</h%d>\n"
2039 (org-html--translate "Table of Contents" info
)
2041 "<div id=\"text-table-of-contents\">"
2042 (org-html--toc-text toc-entries
)
2044 (format "</%s>\n" outer-tag
)))))
2046 (defun org-html--toc-text (toc-entries)
2047 "Return innards of a table of contents, as a string.
2048 TOC-ENTRIES is an alist where key is an entry title, as a string,
2049 and value is its relative level, as an integer."
2050 (let* ((prev-level (1- (cdar toc-entries
)))
2051 (start-level prev-level
))
2055 (let ((headline (car entry
))
2056 (level (cdr entry
)))
2058 (let* ((cnt (- level prev-level
))
2059 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
2061 (setq prev-level level
)
2063 (org-html--make-string
2064 times
(cond ((> cnt
0) "\n<ul>\n<li>")
2065 ((< cnt
0) "</li>\n</ul>\n")))
2066 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
2069 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
2071 (defun org-html--format-toc-headline (headline info
)
2072 "Return an appropriate table of contents entry for HEADLINE.
2073 INFO is a plist used as a communication channel."
2074 (let* ((headline-number (org-export-get-headline-number headline info
))
2075 (todo (and (plist-get info
:with-todo-keywords
)
2076 (let ((todo (org-element-property :todo-keyword headline
)))
2077 (and todo
(org-export-data todo info
)))))
2078 (todo-type (and todo
(org-element-property :todo-type headline
)))
2079 (priority (and (plist-get info
:with-priority
)
2080 (org-element-property :priority headline
)))
2081 (text (org-export-data-with-backend
2082 (org-export-get-alt-title headline info
)
2083 ;; Create an anonymous back-end that will ignore any
2084 ;; footnote-reference, link, radio-target and target
2085 ;; in table of contents.
2086 (org-export-create-backend
2088 :transcoders
'((footnote-reference . ignore
)
2089 (link .
(lambda (object c i
) c
))
2090 (radio-target .
(lambda (object c i
) c
))
2093 (tags (and (eq (plist-get info
:with-tags
) t
)
2094 (org-export-get-tags headline info
))))
2095 (format "<a href=\"#%s\">%s</a>"
2097 (org-export-solidify-link-text
2098 (or (org-element-property :CUSTOM_ID headline
)
2099 (org-export-get-headline-id headline info
)))
2102 (and (not (org-export-low-level-p headline info
))
2103 (org-export-numbered-headline-p headline info
)
2104 (concat (mapconcat #'number-to-string headline-number
".")
2106 (apply (plist-get info
:html-format-headline-function
)
2107 todo todo-type priority text tags
:section-number nil
)))))
2109 (defun org-html-list-of-listings (info)
2110 "Build a list of listings.
2111 INFO is a plist used as a communication channel. Return the list
2112 of listings as a string, or nil if it is empty."
2113 (let ((lol-entries (org-export-collect-listings info
)))
2115 (concat "<div id=\"list-of-listings\">\n"
2116 (let ((top-level (plist-get info
:html-toplevel-hlevel
)))
2117 (format "<h%d>%s</h%d>\n"
2119 (org-html--translate "List of Listings" info
)
2121 "<div id=\"text-list-of-listings\">\n<ul>\n"
2123 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2124 (org-html--translate "Listing %d:" info
))))
2127 (let ((label (org-element-property :name entry
))
2130 (or (org-export-get-caption entry t
)
2131 (org-export-get-caption entry
))
2136 (concat (format initial-fmt
(incf count
)) " " title
)
2137 (format "<a href=\"#%s\">%s %s</a>"
2138 (org-export-solidify-link-text label
)
2139 (format initial-fmt
(incf count
))
2143 "\n</ul>\n</div>\n</div>"))))
2145 (defun org-html-list-of-tables (info)
2146 "Build a list of tables.
2147 INFO is a plist used as a communication channel. Return the list
2148 of tables as a string, or nil if it is empty."
2149 (let ((lol-entries (org-export-collect-tables info
)))
2151 (concat "<div id=\"list-of-tables\">\n"
2152 (let ((top-level (plist-get info
:html-toplevel-hlevel
)))
2153 (format "<h%d>%s</h%d>\n"
2155 (org-html--translate "List of Tables" info
)
2157 "<div id=\"text-list-of-tables\">\n<ul>\n"
2159 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2160 (org-html--translate "Table %d:" info
))))
2163 (let ((label (org-element-property :name entry
))
2166 (or (org-export-get-caption entry t
)
2167 (org-export-get-caption entry
))
2172 (concat (format initial-fmt
(incf count
)) " " title
)
2173 (format "<a href=\"#%s\">%s %s</a>"
2174 (org-export-solidify-link-text label
)
2175 (format initial-fmt
(incf count
))
2179 "\n</ul>\n</div>\n</div>"))))
2182 ;;; Transcode Functions
2186 (defun org-html-bold (bold contents info
)
2187 "Transcode BOLD from Org to HTML.
2188 CONTENTS is the text with bold markup. INFO is a plist holding
2189 contextual information."
2190 (format (or (cdr (assq 'bold
(plist-get info
:html-text-markup-alist
))) "%s")
2195 (defun org-html-center-block (center-block contents info
)
2196 "Transcode a CENTER-BLOCK element from Org to HTML.
2197 CONTENTS holds the contents of the block. INFO is a plist
2198 holding contextual information."
2199 (format "<div class=\"center\">\n%s</div>" contents
))
2203 (defun org-html-clock (clock contents info
)
2204 "Transcode a CLOCK element from Org to HTML.
2205 CONTENTS is nil. INFO is a plist used as a communication
2208 <span class=\"timestamp-wrapper\">
2209 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2213 (org-timestamp-translate (org-element-property :value clock
))
2214 (let ((time (org-element-property :duration clock
)))
2215 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
2219 (defun org-html-code (code contents info
)
2220 "Transcode CODE from Org to HTML.
2221 CONTENTS is nil. INFO is a plist holding contextual
2223 (format (or (cdr (assq 'code
(plist-get info
:html-text-markup-alist
))) "%s")
2224 (org-html-encode-plain-text (org-element-property :value code
))))
2228 (defun org-html-drawer (drawer contents info
)
2229 "Transcode a DRAWER element from Org to HTML.
2230 CONTENTS holds the contents of the block. INFO is a plist
2231 holding contextual information."
2232 (funcall (plist-get info
:html-format-drawer-function
)
2233 (org-element-property :drawer-name drawer
)
2238 (defun org-html-dynamic-block (dynamic-block contents info
)
2239 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2240 CONTENTS holds the contents of the block. INFO is a plist
2241 holding contextual information. See `org-export-data'."
2246 (defun org-html-entity (entity contents info
)
2247 "Transcode an ENTITY object from Org to HTML.
2248 CONTENTS are the definition itself. INFO is a plist holding
2249 contextual information."
2250 (org-element-property :html entity
))
2254 (defun org-html-example-block (example-block contents info
)
2255 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2256 CONTENTS is nil. INFO is a plist holding contextual
2258 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2259 (org-html--textarea-block example-block
)
2260 (format "<pre class=\"example\">\n%s</pre>"
2261 (org-html-format-code example-block info
))))
2265 (defun org-html-export-snippet (export-snippet contents info
)
2266 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2267 CONTENTS is nil. INFO is a plist holding contextual
2269 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2270 (org-element-property :value export-snippet
)))
2274 (defun org-html-export-block (export-block contents info
)
2275 "Transcode a EXPORT-BLOCK element from Org to HTML.
2276 CONTENTS is nil. INFO is a plist holding contextual information."
2277 (when (string= (org-element-property :type export-block
) "HTML")
2278 (org-remove-indentation (org-element-property :value export-block
))))
2282 (defun org-html-fixed-width (fixed-width contents info
)
2283 "Transcode a FIXED-WIDTH element from Org to HTML.
2284 CONTENTS is nil. INFO is a plist holding contextual information."
2285 (format "<pre class=\"example\">\n%s</pre>"
2286 (org-html-do-format-code
2287 (org-remove-indentation
2288 (org-element-property :value fixed-width
)))))
2290 ;;;; Footnote Reference
2292 (defun org-html-footnote-reference (footnote-reference contents info
)
2293 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2294 CONTENTS is nil. INFO is a plist holding contextual information."
2296 ;; Insert separator between two footnotes in a row.
2297 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2298 (when (eq (org-element-type prev
) 'footnote-reference
)
2299 (plist-get info
:html-footnote-separator
)))
2300 (let* ((n (org-export-get-footnote-number footnote-reference info
))
2301 (id (format "fnr.%d%s"
2303 (if (org-export-footnote-first-reference-p
2304 footnote-reference info
)
2308 (plist-get info
:html-footnote-format
)
2310 id n
(format " class=\"footref\" href=\"#fn.%d\"" n
) info
)))))
2314 (defun org-html-headline (headline contents info
)
2315 "Transcode a HEADLINE element from Org to HTML.
2316 CONTENTS holds the contents of the headline. INFO is a plist
2317 holding contextual information."
2318 (unless (org-element-property :footnote-section-p headline
)
2319 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2320 (numbers (org-export-get-headline-number headline info
))
2321 (section-number (and numbers
2322 (mapconcat #'number-to-string numbers
"-")))
2323 (level (+ (org-export-get-relative-level headline info
)
2324 (1- (plist-get info
:html-toplevel-hlevel
))))
2325 (todo (and (plist-get info
:with-todo-keywords
)
2326 (let ((todo (org-element-property :todo-keyword headline
)))
2327 (and todo
(org-export-data todo info
)))))
2328 (todo-type (and todo
(org-element-property :todo-type headline
)))
2329 (priority (and (plist-get info
:with-priority
)
2330 (org-element-property :priority headline
)))
2331 (text (org-export-data (org-element-property :title headline
) info
))
2332 (tags (and (plist-get info
:with-tags
)
2333 (org-export-get-tags headline info
)))
2334 (full-text (funcall (plist-get info
:html-format-headline-function
)
2335 todo todo-type priority text tags info
))
2336 (contents (or contents
""))
2338 (list (org-element-property :CUSTOM_ID headline
)
2339 (org-export-get-headline-id headline info
)
2340 (org-element-property :ID headline
))))
2341 (preferred-id (car ids
))
2342 (extra-ids (mapconcat
2345 (org-export-solidify-link-text
2346 (if (org-uuidgen-p id
) (concat "ID-" id
) id
))
2349 (if (org-export-low-level-p headline info
)
2350 ;; This is a deep sub-tree: export it as a list item.
2351 (let* ((type (if numberedp
'ordered
'unordered
))
2353 (org-html-format-list-item
2354 contents type nil info nil
2355 (concat (org-html--anchor preferred-id nil nil info
)
2358 (concat (and (org-export-first-sibling-p headline info
)
2359 (org-html-begin-plain-list type
))
2361 (and (org-export-last-sibling-p headline info
)
2362 (org-html-end-plain-list type
))))
2363 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2364 (first-content (car (org-element-contents headline
))))
2365 ;; Standard headline. Export it as a section.
2366 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2367 (org-html--container headline info
)
2368 (format "outline-container-%s"
2369 (or (org-element-property :CUSTOM_ID headline
)
2370 (org-export-get-headline-id headline info
)))
2371 (concat (format "outline-%d" level
)
2372 (and extra-class
" ")
2374 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2381 "<span class=\"section-number-%d\">%s</span> "
2383 (mapconcat #'number-to-string numbers
".")))
2386 ;; When there is no section, pretend there is an
2387 ;; empty one to get the correct <div
2388 ;; class="outline-...> which is needed by
2390 (if (eq (org-element-type first-content
) 'section
) contents
2391 (concat (org-html-section first-content
"" info
) contents
))
2392 (org-html--container headline info
)))))))
2394 (defun org-html-format-headline-default-function
2395 (todo todo-type priority text tags info
)
2396 "Default format function for a headline.
2397 See `org-html-format-headline-function' for details."
2398 (let ((todo (org-html--todo todo info
))
2399 (tags (org-html--tags tags info
)))
2400 (concat todo
(and todo
" ") text
(and tags
"   ") tags
)))
2402 (defun org-html--container (headline info
)
2403 (or (org-element-property :HTML_CONTAINER headline
)
2404 (if (= 1 (org-export-get-relative-level headline info
))
2405 (plist-get info
:html-container
)
2408 ;;;; Horizontal Rule
2410 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2411 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2412 CONTENTS is nil. INFO is a plist holding contextual information."
2413 (org-html-close-tag "hr" nil info
))
2415 ;;;; Inline Src Block
2417 (defun org-html-inline-src-block (inline-src-block contents info
)
2418 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2419 CONTENTS holds the contents of the item. INFO is a plist holding
2420 contextual information."
2421 (let* ((org-lang (org-element-property :language inline-src-block
))
2422 (code (org-element-property :value inline-src-block
)))
2423 (let ((lang (org-element-property :language inline-src-block
))
2424 (code (org-html-format-code inline-src-block info
))
2425 (label (let ((lbl (org-element-property :name inline-src-block
)))
2427 (format " id=\"%s\""
2428 (org-export-solidify-link-text lbl
))))))
2429 (format "<code class=\"src src-%s\"%s>%s</code>" lang label code
))))
2433 (defun org-html-inlinetask (inlinetask contents info
)
2434 "Transcode an INLINETASK element from Org to HTML.
2435 CONTENTS holds the contents of the block. INFO is a plist
2436 holding contextual information."
2437 (let* ((todo (and (plist-get info
:with-todo-keywords
)
2438 (let ((todo (org-element-property :todo-keyword inlinetask
)))
2439 (and todo
(org-export-data todo info
)))))
2440 (todo-type (and todo
(org-element-property :todo-type inlinetask
)))
2441 (priority (and (plist-get info
:with-priority
)
2442 (org-element-property :priority inlinetask
)))
2443 (text (org-export-data (org-element-property :title inlinetask
) info
))
2444 (tags (and (plist-get info
:with-tags
)
2445 (org-export-get-tags inlinetask info
))))
2446 (funcall (plist-get info
:html-format-inlinetask-function
)
2447 todo todo-type priority text tags contents info
)))
2449 (defun org-html-format-inlinetask-default-function
2450 (todo todo-type priority text tags contents info
)
2451 "Default format function for a inlinetasks.
2452 See `org-html-format-inlinetask-function' for details."
2453 (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2454 (org-html-format-headline-default-function
2455 todo todo-type priority text tags info
)
2456 (org-html-close-tag "br" nil info
)
2461 (defun org-html-italic (italic contents info
)
2462 "Transcode ITALIC from Org to HTML.
2463 CONTENTS is the text with italic markup. INFO is a plist holding
2464 contextual information."
2466 (or (cdr (assq 'italic
(plist-get info
:html-text-markup-alist
))) "%s")
2471 (defun org-html-checkbox (checkbox info
)
2472 "Format CHECKBOX into HTML.
2473 INFO is a plist holding contextual information. See
2474 `org-html-checkbox-type' for customization options."
2476 (cdr (assq (plist-get info
:html-checkbox-type
)
2477 org-html-checkbox-types
)))))
2479 (defun org-html-format-list-item (contents type checkbox info
2480 &optional term-counter-id
2482 "Format a list item into HTML."
2483 (let ((class (if checkbox
2484 (format " class=\"%s\""
2485 (symbol-name checkbox
)) ""))
2486 (checkbox (concat (org-html-checkbox checkbox info
)
2487 (and checkbox
" ")))
2488 (br (org-html-close-tag "br" nil info
)))
2492 (let* ((counter term-counter-id
)
2493 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2495 (format "<li%s%s>" class extra
)
2496 (when headline
(concat headline br
)))))
2498 (let* ((id term-counter-id
)
2499 (extra (if id
(format " id=\"%s\"" id
) "")))
2501 (format "<li%s%s>" class extra
)
2502 (when headline
(concat headline br
)))))
2504 (let* ((term term-counter-id
))
2505 (setq term
(or term
"(no term)"))
2506 ;; Check-boxes in descriptive lists are associated to tag.
2507 (concat (format "<dt%s>%s</dt>"
2508 class
(concat checkbox term
))
2510 (unless (eq type
'descriptive
) checkbox
)
2515 (descriptive "</dd>")))))
2517 (defun org-html-item (item contents info
)
2518 "Transcode an ITEM element from Org to HTML.
2519 CONTENTS holds the contents of the item. INFO is a plist holding
2520 contextual information."
2521 (let* ((plain-list (org-export-get-parent item
))
2522 (type (org-element-property :type plain-list
))
2523 (counter (org-element-property :counter item
))
2524 (checkbox (org-element-property :checkbox item
))
2525 (tag (let ((tag (org-element-property :tag item
)))
2526 (and tag
(org-export-data tag info
)))))
2527 (org-html-format-list-item
2528 contents type checkbox info
(or tag counter
))))
2532 (defun org-html-keyword (keyword contents info
)
2533 "Transcode a KEYWORD element from Org to HTML.
2534 CONTENTS is nil. INFO is a plist holding contextual information."
2535 (let ((key (org-element-property :key keyword
))
2536 (value (org-element-property :value keyword
)))
2538 ((string= key
"HTML") value
)
2539 ((string= key
"TOC")
2540 (let ((value (downcase value
)))
2542 ((string-match "\\<headlines\\>" value
)
2543 (let ((depth (or (and (string-match "[0-9]+" value
)
2544 (string-to-number (match-string 0 value
)))
2545 (plist-get info
:with-toc
))))
2546 (org-html-toc depth info
)))
2547 ((string= "listings" value
) (org-html-list-of-listings info
))
2548 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2550 ;;;; Latex Environment
2552 (defun org-html-format-latex (latex-frag processing-type info
)
2553 "Format a LaTeX fragment LATEX-FRAG into HTML.
2554 PROCESSING-TYPE designates the tool used for conversion. It is
2555 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2556 and t. See `org-html-with-latex' for more information. INFO is
2557 a plist containing export properties."
2558 (let ((cache-relpath "") (cache-dir ""))
2559 (unless (eq processing-type
'mathjax
)
2560 (let ((bfn (or (buffer-file-name)
2562 (expand-file-name "latex" temporary-file-directory
))))
2564 (let ((header (plist-get info
:latex-header
)))
2567 (lambda (line) (concat "#+LATEX_HEADER: " line
))
2568 (org-split-string header
"\n")
2573 (file-name-sans-extension
2574 (file-name-nondirectory bfn
)))
2575 cache-dir
(file-name-directory bfn
))
2576 ;; Re-create LaTeX environment from original buffer in
2577 ;; temporary buffer so that dvipng/imagemagick can properly
2578 ;; turn the fragment into an image.
2579 (setq latex-frag
(concat latex-header latex-frag
))))
2582 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2583 nil processing-type
)
2586 (defun org-html-latex-environment (latex-environment contents info
)
2587 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2588 CONTENTS is nil. INFO is a plist holding contextual information."
2589 (let ((processing-type (plist-get info
:with-latex
))
2590 (latex-frag (org-remove-indentation
2591 (org-element-property :value latex-environment
)))
2592 (attributes (org-export-read-attribute :attr_html latex-environment
)))
2593 (case processing-type
2595 (org-html-format-latex latex-frag
'mathjax info
))
2596 ((dvipng imagemagick
)
2598 (org-html-format-latex latex-frag processing-type info
)))
2599 (when (and formula-link
(string-match "file:\\([^]]*\\)" formula-link
))
2600 ;; Do not provide a caption or a name to be consistent with
2601 ;; `mathjax' handling.
2602 (org-html--wrap-image
2603 (org-html--format-image
2604 (match-string 1 formula-link
) attributes info
) info
))))
2609 (defun org-html-latex-fragment (latex-fragment contents info
)
2610 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2611 CONTENTS is nil. INFO is a plist holding contextual information."
2612 (let ((latex-frag (org-element-property :value latex-fragment
))
2613 (processing-type (plist-get info
:with-latex
)))
2614 (case processing-type
2616 (org-html-format-latex latex-frag
'mathjax info
))
2617 ((dvipng imagemagick
)
2619 (org-html-format-latex latex-frag processing-type info
)))
2620 (when (and formula-link
(string-match "file:\\([^]]*\\)" formula-link
))
2621 (org-html--format-image (match-string 1 formula-link
) nil info
))))
2626 (defun org-html-line-break (line-break contents info
)
2627 "Transcode a LINE-BREAK object from Org to HTML.
2628 CONTENTS is nil. INFO is a plist holding contextual information."
2629 (concat (org-html-close-tag "br" nil info
) "\n"))
2633 (defun org-html-inline-image-p (link info
)
2634 "Non-nil when LINK is meant to appear as an image.
2635 INFO is a plist used as a communication channel. LINK is an
2636 inline image when it has no description and targets an image
2637 file (see `org-html-inline-image-rules' for more information), or
2638 if its description is a single link targeting an image file."
2639 (if (not (org-element-contents link
))
2640 (org-export-inline-image-p
2641 link
(plist-get info
:html-inline-image-rules
))
2643 (let ((link-count 0))
2644 (org-element-map (org-element-contents link
)
2645 (cons 'plain-text org-element-all-objects
)
2647 (case (org-element-type obj
)
2648 (plain-text (org-string-nw-p obj
))
2649 (link (if (= link-count
1) t
2651 (not (org-export-inline-image-p
2652 obj
(plist-get info
:html-inline-image-rules
)))))
2656 (defvar org-html-standalone-image-predicate
)
2657 (defun org-html-standalone-image-p (element info
)
2658 "Non-nil if ELEMENT is a standalone image.
2660 INFO is a plist holding contextual information.
2662 An element or object is a standalone image when
2664 - its type is `paragraph' and its sole content, save for white
2665 spaces, is a link that qualifies as an inline image;
2667 - its type is `link' and its containing paragraph has no other
2668 content save white spaces.
2670 Bind `org-html-standalone-image-predicate' to constrain paragraph
2671 further. For example, to check for only captioned standalone
2674 \(lambda (paragraph) (org-element-property :caption paragraph))"
2675 (let ((paragraph (case (org-element-type element
)
2677 (link (org-export-get-parent element
)))))
2678 (and (eq (org-element-type paragraph
) 'paragraph
)
2679 (or (not (fboundp 'org-html-standalone-image-predicate
))
2680 (funcall org-html-standalone-image-predicate paragraph
))
2682 (let ((link-count 0))
2683 (org-element-map (org-element-contents paragraph
)
2684 (cons 'plain-text org-element-all-objects
)
2686 (when (case (org-element-type obj
)
2687 (plain-text (org-string-nw-p obj
))
2688 (link (or (> (incf link-count
) 1)
2689 (not (org-html-inline-image-p obj info
))))
2693 (= link-count
1))))))
2695 (defun org-html-link (link desc info
)
2696 "Transcode a LINK object from Org to HTML.
2698 DESC is the description part of the link, or the empty string.
2699 INFO is a plist holding contextual information. See
2701 (let* ((home (when (plist-get info
:html-link-home
)
2702 (org-trim (plist-get info
:html-link-home
))))
2703 (use-abs-url (plist-get info
:html-link-use-abs-url
))
2704 (link-org-files-as-html-maybe
2706 (lambda (raw-path info
)
2707 "Treat links to `file.org' as links to `file.html', if needed.
2708 See `org-html-link-org-files-as-html'."
2710 ((and (plist-get info
:html-link-org-files-as-html
)
2712 (downcase (file-name-extension raw-path
"."))))
2713 (concat (file-name-sans-extension raw-path
) "."
2714 (plist-get info
:html-extension
)))
2716 (type (org-element-property :type link
))
2717 (raw-path (org-element-property :path link
))
2718 ;; Ensure DESC really exists, or set it to nil.
2719 (desc (org-string-nw-p desc
))
2722 ((member type
'("http" "https" "ftp" "mailto"))
2723 (org-link-escape-browser
2724 (org-link-unescape (concat type
":" raw-path
))))
2725 ((string= type
"file")
2726 ;; Treat links to ".org" files as ".html", if needed.
2728 (funcall link-org-files-as-html-maybe raw-path info
))
2729 ;; If file path is absolute, prepend it with protocol
2730 ;; component - "file:".
2732 ((file-name-absolute-p raw-path
)
2733 (setq raw-path
(concat "file:" raw-path
)))
2734 ((and home use-abs-url
)
2735 (setq raw-path
(concat (file-name-as-directory home
) raw-path
))))
2736 ;; Add search option, if any. A search option can be
2737 ;; relative to a custom-id or a headline title. Append
2738 ;; a hash sign to any unresolved option, as it might point
2740 (let ((option (org-element-property :search-option link
)))
2741 (cond ((not option
) raw-path
)
2742 ((eq (aref option
0) ?
#) (concat raw-path option
))
2745 (org-publish-resolve-external-fuzzy-link
2746 (org-element-property :path link
) option
)))
2748 (if (not destination
) (concat "#" option
)
2750 (mapconcat #'number-to-string
2751 destination
"-")))))))))
2753 ;; Extract attributes from parent's paragraph. HACK: Only do
2754 ;; this for the first link in parent (inner image link for
2755 ;; inline images). This is needed as long as attributes
2756 ;; cannot be set on a per link basis.
2758 (let* ((parent (org-export-get-parent-element link
))
2759 (link (let ((container (org-export-get-parent link
)))
2760 (if (and (eq (org-element-type container
) 'link
)
2761 (org-html-inline-image-p link info
))
2764 (and (eq (org-element-map parent
'link
'identity info t
) link
)
2765 (org-export-read-attribute :attr_html parent
))))
2767 (let ((attr (org-html--make-attribute-string attributes-plist
)))
2768 (if (org-string-nw-p attr
) (concat " " attr
) "")))
2772 ((and (plist-get info
:html-inline-images
)
2773 (org-export-inline-image-p
2774 link
(plist-get info
:html-inline-image-rules
)))
2775 (org-html--format-image path attributes-plist info
))
2776 ;; Radio target: Transcode target's contents and use them as
2777 ;; link's description.
2778 ((string= type
"radio")
2779 (let ((destination (org-export-resolve-radio-link link info
)))
2780 (if (not destination
) desc
2781 (format "<a href=\"#%s\"%s>%s</a>"
2782 (org-export-solidify-link-text
2783 (org-element-property :value destination
))
2785 ;; Links pointing to a headline: Find destination and build
2786 ;; appropriate referencing command.
2787 ((member type
'("custom-id" "fuzzy" "id"))
2788 (let ((destination (if (string= type
"fuzzy")
2789 (org-export-resolve-fuzzy-link link info
)
2790 (org-export-resolve-id-link link info
))))
2791 (case (org-element-type destination
)
2792 ;; ID link points to an external file.
2794 (let ((fragment (concat "ID-" path
))
2795 ;; Treat links to ".org" files as ".html", if needed.
2796 (path (funcall link-org-files-as-html-maybe
2798 (format "<a href=\"%s#%s\"%s>%s</a>"
2799 path fragment attributes
(or desc destination
))))
2800 ;; Fuzzy link points nowhere.
2805 (org-element-property :raw-link link
) info
))))
2806 ;; Link points to a headline.
2808 (let ((href (or (and (string= type
"custom-id")
2809 (org-element-property :CUSTOM_ID destination
))
2810 (org-export-get-headline-id destination info
)))
2811 ;; What description to use?
2813 ;; Case 1: Headline is numbered and LINK has no
2814 ;; description. Display section number.
2815 (if (and (org-export-numbered-headline-p destination info
)
2817 (mapconcat 'number-to-string
2818 (org-export-get-headline-number
2819 destination info
) ".")
2820 ;; Case 2: Either the headline is un-numbered or
2821 ;; LINK has a custom description. Display LINK's
2822 ;; description or headline's title.
2823 (or desc
(org-export-data (org-element-property
2824 :title destination
) info
)))))
2825 (format "<a href=\"#%s\"%s>%s</a>"
2826 (org-export-solidify-link-text href
) attributes desc
)))
2827 ;; Fuzzy link points to a target or an element.
2829 (let* ((path (org-export-solidify-link-text path
))
2830 (org-html-standalone-image-predicate 'org-html--has-caption-p
)
2833 ((org-html-standalone-image-p destination info
)
2834 (org-export-get-ordinal
2835 (org-element-map destination
'link
2837 info
'link
'org-html-standalone-image-p
))
2838 (t (org-export-get-ordinal
2839 destination info nil
'org-html--has-caption-p
))))
2841 ((not number
) "No description for this link")
2842 ((numberp number
) (number-to-string number
))
2843 (t (mapconcat 'number-to-string number
".")))))
2844 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc
))))))
2845 ;; Coderef: replace link with the reference name or the
2846 ;; equivalent line number.
2847 ((string= type
"coderef")
2848 (let ((fragment (concat "coderef-" path
)))
2849 (format "<a href=\"#%s\"%s%s>%s</a>"
2852 (format (concat "class=\"coderef\""
2853 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2854 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2857 (format (org-export-get-coderef-format path desc
)
2858 (org-export-resolve-coderef path info
)))))
2859 ;; Link type is handled by a special function.
2860 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2861 (funcall protocol
(org-link-unescape path
) desc
'html
))
2862 ;; External link with a description part.
2863 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2864 ;; External link without a description part.
2865 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2866 ;; No path, only description. Try to do something useful.
2867 (t (format "<i>%s</i>" desc
)))))
2871 (defun org-html-node-property (node-property contents info
)
2872 "Transcode a NODE-PROPERTY element from Org to HTML.
2873 CONTENTS is nil. INFO is a plist holding contextual
2876 (org-element-property :key node-property
)
2877 (let ((value (org-element-property :value node-property
)))
2878 (if value
(concat " " value
) ""))))
2882 (defun org-html-paragraph (paragraph contents info
)
2883 "Transcode a PARAGRAPH element from Org to HTML.
2884 CONTENTS is the contents of the paragraph, as a string. INFO is
2885 the plist used as a communication channel."
2886 (let* ((parent (org-export-get-parent paragraph
))
2887 (parent-type (org-element-type parent
))
2888 (style '((footnote-definition " class=\"footpara\"")))
2889 (attributes (org-html--make-attribute-string
2890 (org-export-read-attribute :attr_html paragraph
)))
2891 (extra (or (cadr (assoc parent-type style
)) "")))
2893 ((and (eq parent-type
'item
)
2894 (not (org-export-get-previous-element paragraph info
))
2895 (let ((followers (org-export-get-next-element paragraph info
2)))
2896 (and (not (cdr followers
))
2897 (memq (org-element-type (car followers
)) '(nil plain-list
)))))
2898 ;; First paragraph in an item has no tag if it is alone or
2899 ;; followed, at most, by a sub-list.
2901 ((org-html-standalone-image-p paragraph info
)
2902 ;; Standalone image.
2904 (let ((raw (org-export-data
2905 (org-export-get-caption paragraph
) info
))
2906 (org-html-standalone-image-predicate
2907 'org-html--has-caption-p
))
2908 (if (not (org-string-nw-p raw
)) raw
2910 "<span class=\"figure-number\">"
2911 (format (org-html--translate "Figure %d:" info
)
2912 (org-export-get-ordinal
2913 (org-element-map paragraph
'link
2915 info nil
'org-html-standalone-image-p
))
2917 (label (org-element-property :name paragraph
)))
2918 (org-html--wrap-image contents info caption label
)))
2919 ;; Regular paragraph.
2920 (t (format "<p%s%s>\n%s</p>"
2921 (if (org-string-nw-p attributes
)
2922 (concat " " attributes
) "")
2927 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2928 ;; the correct value for the item counter
2929 (defun org-html-begin-plain-list (type &optional arg1
)
2930 "Insert the beginning of the HTML list depending on TYPE.
2931 When ARG1 is a string, use it as the start parameter for ordered
2935 (format "<ol class=\"org-ol\"%s>"
2936 (if arg1
(format " start=\"%d\"" arg1
) "")))
2937 (unordered "<ul class=\"org-ul\">")
2938 (descriptive "<dl class=\"org-dl\">")))
2940 (defun org-html-end-plain-list (type)
2941 "Insert the end of the HTML list depending on TYPE."
2945 (descriptive "</dl>")))
2947 (defun org-html-plain-list (plain-list contents info
)
2948 "Transcode a PLAIN-LIST element from Org to HTML.
2949 CONTENTS is the contents of the list. INFO is a plist holding
2950 contextual information."
2951 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2952 (type (org-element-property :type plain-list
)))
2954 (org-html-begin-plain-list type
)
2955 contents
(org-html-end-plain-list type
))))
2959 (defun org-html-convert-special-strings (string)
2960 "Convert special characters in STRING to HTML."
2961 (let ((all org-html-special-string-regexps
)
2963 (while (setq a
(pop all
))
2964 (setq re
(car a
) rpl
(cdr a
) start
0)
2965 (while (string-match re string start
)
2966 (setq string
(replace-match rpl t nil string
))))
2969 (defun org-html-encode-plain-text (text)
2970 "Convert plain text characters from TEXT to HTML equivalent.
2971 Possible conversions are set in `org-html-protect-char-alist'."
2974 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2975 org-html-protect-char-alist
)
2978 (defun org-html-plain-text (text info
)
2979 "Transcode a TEXT string from Org to HTML.
2980 TEXT is the string to transcode. INFO is a plist holding
2981 contextual information."
2982 (let ((output text
))
2983 ;; Protect following characters: <, >, &.
2984 (setq output
(org-html-encode-plain-text output
))
2985 ;; Handle smart quotes. Be sure to provide original string since
2986 ;; OUTPUT may have been modified.
2987 (when (plist-get info
:with-smart-quotes
)
2988 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2989 ;; Handle special strings.
2990 (when (plist-get info
:with-special-strings
)
2991 (setq output
(org-html-convert-special-strings output
)))
2992 ;; Handle break preservation if required.
2993 (when (plist-get info
:preserve-breaks
)
2995 (replace-regexp-in-string
2996 "\\(\\\\\\\\\\)?[ \t]*\n"
2997 (concat (org-html-close-tag "br" nil info
) "\n") output
)))
3004 (defun org-html-planning (planning contents info
)
3005 "Transcode a PLANNING element from Org to HTML.
3006 CONTENTS is nil. INFO is a plist used as a communication
3008 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
3010 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3015 (let ((closed (org-element-property :closed planning
)))
3017 (format span-fmt org-closed-string
3018 (org-timestamp-translate closed
))))
3019 (let ((deadline (org-element-property :deadline planning
)))
3021 (format span-fmt org-deadline-string
3022 (org-timestamp-translate deadline
))))
3023 (let ((scheduled (org-element-property :scheduled planning
)))
3025 (format span-fmt org-scheduled-string
3026 (org-timestamp-translate scheduled
))))))
3029 ;;;; Property Drawer
3031 (defun org-html-property-drawer (property-drawer contents info
)
3032 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3033 CONTENTS holds the contents of the drawer. INFO is a plist
3034 holding contextual information."
3035 (and (org-string-nw-p contents
)
3036 (format "<pre class=\"example\">\n%s</pre>" contents
)))
3040 (defun org-html-quote-block (quote-block contents info
)
3041 "Transcode a QUOTE-BLOCK element from Org to HTML.
3042 CONTENTS holds the contents of the block. INFO is a plist
3043 holding contextual information."
3044 (format "<blockquote>\n%s</blockquote>" contents
))
3048 (defun org-html-section (section contents info
)
3049 "Transcode a SECTION element from Org to HTML.
3050 CONTENTS holds the contents of the section. INFO is a plist
3051 holding contextual information."
3052 (let ((parent (org-export-get-parent-headline section
)))
3053 ;; Before first headline: no container, just return CONTENTS.
3054 (if (not parent
) contents
3055 ;; Get div's class and id references.
3056 (let* ((class-num (+ (org-export-get-relative-level parent info
)
3057 (1- (plist-get info
:html-toplevel-hlevel
))))
3059 (and (org-export-numbered-headline-p parent info
)
3062 (org-export-get-headline-number parent info
) "-"))))
3063 ;; Build return value.
3064 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3066 (or (org-element-property :CUSTOM_ID parent
)
3068 (org-export-get-headline-id parent info
))
3073 (defun org-html-radio-target (radio-target text info
)
3074 "Transcode a RADIO-TARGET object from Org to HTML.
3075 TEXT is the text of the target. INFO is a plist holding
3076 contextual information."
3077 (let ((id (org-export-solidify-link-text
3078 (org-element-property :value radio-target
))))
3079 (org-html--anchor id text nil info
)))
3083 (defun org-html-special-block (special-block contents info
)
3084 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3085 CONTENTS holds the contents of the block. INFO is a plist
3086 holding contextual information."
3087 (let* ((block-type (org-element-property :type special-block
))
3088 (contents (or contents
""))
3089 (html5-fancy (and (org-html-html5-p info
)
3090 (plist-get info
:html-html5-fancy
)
3091 (member block-type org-html-html5-elements
)))
3092 (attributes (org-export-read-attribute :attr_html special-block
)))
3094 (let ((class (plist-get attributes
:class
)))
3095 (setq attributes
(plist-put attributes
:class
3096 (if class
(concat class
" " block-type
)
3098 (setq attributes
(org-html--make-attribute-string attributes
))
3099 (when (not (equal attributes
""))
3100 (setq attributes
(concat " " attributes
)))
3102 (format "<%s%s>\n%s</%s>" block-type attributes
3103 contents block-type
)
3104 (format "<div%s>\n%s\n</div>" attributes contents
))))
3108 (defun org-html-src-block (src-block contents info
)
3109 "Transcode a SRC-BLOCK element from Org to HTML.
3110 CONTENTS holds the contents of the item. INFO is a plist holding
3111 contextual information."
3112 (if (org-export-read-attribute :attr_html src-block
:textarea
)
3113 (org-html--textarea-block src-block
)
3114 (let ((lang (org-element-property :language src-block
))
3115 (caption (org-export-get-caption src-block
))
3116 (code (org-html-format-code src-block info
))
3117 (label (let ((lbl (org-element-property :name src-block
)))
3119 (format " id=\"%s\""
3120 (org-export-solidify-link-text lbl
))))))
3121 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
3123 "<div class=\"org-src-container\">\n%s%s\n</div>"
3124 (if (not caption
) ""
3125 (format "<label class=\"org-src-name\">%s</label>"
3126 (org-export-data caption info
)))
3127 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
3129 ;;;; Statistics Cookie
3131 (defun org-html-statistics-cookie (statistics-cookie contents info
)
3132 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3133 CONTENTS is nil. INFO is a plist holding contextual information."
3134 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3135 (format "<code>%s</code>" cookie-value
)))
3139 (defun org-html-strike-through (strike-through contents info
)
3140 "Transcode STRIKE-THROUGH from Org to HTML.
3141 CONTENTS is the text with strike-through markup. INFO is a plist
3142 holding contextual information."
3144 (or (cdr (assq 'strike-through
(plist-get info
:html-text-markup-alist
)))
3150 (defun org-html-subscript (subscript contents info
)
3151 "Transcode a SUBSCRIPT object from Org to HTML.
3152 CONTENTS is the contents of the object. INFO is a plist holding
3153 contextual information."
3154 (format "<sub>%s</sub>" contents
))
3158 (defun org-html-superscript (superscript contents info
)
3159 "Transcode a SUPERSCRIPT object from Org to HTML.
3160 CONTENTS is the contents of the object. INFO is a plist holding
3161 contextual information."
3162 (format "<sup>%s</sup>" contents
))
3166 (defun org-html-table-cell (table-cell contents info
)
3167 "Transcode a TABLE-CELL element from Org to HTML.
3168 CONTENTS is nil. INFO is a plist used as a communication
3170 (let* ((table-row (org-export-get-parent table-cell
))
3171 (table (org-export-get-parent-table table-cell
))
3173 (if (not (plist-get info
:html-table-align-individual-fields
)) ""
3174 (format (if (and (boundp 'org-html-format-table-no-css
)
3175 org-html-format-table-no-css
)
3176 " align=\"%s\"" " class=\"%s\"")
3177 (org-export-table-cell-alignment table-cell info
)))))
3178 (when (or (not contents
) (string= "" (org-trim contents
)))
3179 (setq contents
" "))
3181 ((and (org-export-table-has-header-p table info
)
3182 (= 1 (org-export-table-row-group table-row info
)))
3183 (let ((header-tags (plist-get info
:html-table-header-tags
)))
3184 (concat "\n" (format (car header-tags
) "col" cell-attrs
)
3186 (cdr header-tags
))))
3187 ((and (plist-get info
:html-table-use-header-tags-for-first-column
)
3188 (zerop (cdr (org-export-table-cell-address table-cell info
))))
3189 (let ((header-tags (plist-get info
:html-table-header-tags
)))
3190 (concat "\n" (format (car header-tags
) "row" cell-attrs
)
3192 (cdr header-tags
))))
3193 (t (let ((data-tags (plist-get info
:html-table-data-tags
)))
3194 (concat "\n" (format (car data-tags
) cell-attrs
)
3196 (cdr data-tags
)))))))
3200 (defun org-html-table-row (table-row contents info
)
3201 "Transcode a TABLE-ROW element from Org to HTML.
3202 CONTENTS is the contents of the row. INFO is a plist used as a
3203 communication channel."
3204 ;; Rules are ignored since table separators are deduced from
3205 ;; borders of the current row.
3206 (when (eq (org-element-property :type table-row
) 'standard
)
3207 (let* ((rowgroup-number (org-export-table-row-group table-row info
))
3208 (row-number (org-export-table-row-number table-row info
))
3210 (org-export-table-row-starts-rowgroup-p table-row info
))
3212 (org-export-table-row-ends-rowgroup-p table-row info
))
3213 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3214 ;; but should be set so that `org-html-table-row-tags' can
3215 ;; use them (see the docstring of this variable.)
3216 (top-row-p (and (equal start-rowgroup-p
'(top))
3217 (equal end-rowgroup-p
'(below top
))))
3218 (bottom-row-p (and (equal start-rowgroup-p
'(above))
3219 (equal end-rowgroup-p
'(bottom above
))))
3222 ;; Case 1: Row belongs to second or subsequent rowgroups.
3223 ((not (= 1 rowgroup-number
))
3224 '("<tbody>" .
"\n</tbody>"))
3225 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3226 ((org-export-table-has-header-p
3227 (org-export-get-parent-table table-row
) info
)
3228 '("<thead>" .
"\n</thead>"))
3229 ;; Case 2: Row is from first and only row group.
3230 (t '("<tbody>" .
"\n</tbody>")))))
3232 ;; Begin a rowgroup?
3233 (when start-rowgroup-p
(car rowgroup-tags
))
3235 (concat "\n" (eval (car (plist-get info
:html-table-row-tags
)))
3238 (eval (cdr (plist-get info
:html-table-row-tags
))))
3240 (when end-rowgroup-p
(cdr rowgroup-tags
))))))
3244 (defun org-html-table-first-row-data-cells (table info
)
3245 "Transcode the first row of TABLE.
3246 INFO is a plist used as a communication channel."
3248 (org-element-map table
'table-row
3250 (unless (eq (org-element-property :type row
) 'rule
) row
))
3252 (special-column-p (org-export-table-has-special-column-p table
)))
3253 (if (not special-column-p
) (org-element-contents table-row
)
3254 (cdr (org-element-contents table-row
)))))
3256 (defun org-html-table--table.el-table
(table info
)
3257 "Format table.el tables into HTML.
3258 INFO is a plist used as a communication channel."
3259 (when (eq (org-element-property :type table
) 'table.el
)
3261 (let ((outbuf (with-current-buffer
3262 (get-buffer-create "*org-export-table*")
3263 (erase-buffer) (current-buffer))))
3265 (insert (org-element-property :value table
))
3267 (re-search-forward "^[ \t]*|[^|]" nil t
)
3268 (table-generate-source 'html outbuf
))
3269 (with-current-buffer outbuf
3270 (prog1 (org-trim (buffer-string))
3273 (defun org-html-table (table contents info
)
3274 "Transcode a TABLE element from Org to HTML.
3275 CONTENTS is the contents of the table. INFO is a plist holding
3276 contextual information."
3277 (case (org-element-property :type table
)
3278 ;; Case 1: table.el table. Convert it using appropriate tools.
3279 (table.el
(org-html-table--table.el-table table info
))
3280 ;; Case 2: Standard table.
3282 (let* ((label (org-element-property :name table
))
3283 (caption (org-export-get-caption table
))
3284 (number (org-export-get-ordinal
3285 table info nil
'org-html--has-caption-p
))
3287 (org-html--make-attribute-string
3289 (and label
(list :id
(org-export-solidify-link-text label
)))
3290 (and (not (org-html-html5-p info
))
3291 (plist-get info
:html-table-attributes
))
3292 (org-export-read-attribute :attr_html table
))))
3294 (if (and (boundp 'org-html-format-table-no-css
)
3295 org-html-format-table-no-css
)
3296 "align=\"%s\"" "class=\"%s\""))
3299 (lambda (table info
)
3301 (lambda (table-cell)
3302 (let ((alignment (org-export-table-cell-alignment
3305 ;; Begin a colgroup?
3306 (when (org-export-table-cell-starts-colgroup-p
3309 ;; Add a column. Also specify it's alignment.
3312 "col" (concat " " (format alignspec alignment
)) info
))
3314 (when (org-export-table-cell-ends-colgroup-p
3317 (org-html-table-first-row-data-cells table info
) "\n")))))
3318 (format "<table%s>\n%s\n%s\n%s</table>"
3319 (if (equal attributes
"") "" (concat " " attributes
))
3320 (if (not caption
) ""
3321 (format (if (plist-get info
:html-table-caption-above
)
3322 "<caption class=\"t-above\">%s</caption>"
3323 "<caption class=\"t-bottom\">%s</caption>")
3325 "<span class=\"table-number\">"
3326 (format (org-html--translate "Table %d:" info
) number
)
3327 "</span> " (org-export-data caption info
))))
3328 (funcall table-column-specs table info
)
3333 (defun org-html-target (target contents info
)
3334 "Transcode a TARGET object from Org to HTML.
3335 CONTENTS is nil. INFO is a plist holding contextual
3337 (let ((id (org-export-solidify-link-text
3338 (org-element-property :value target
))))
3339 (org-html--anchor id nil nil info
)))
3343 (defun org-html-timestamp (timestamp contents info
)
3344 "Transcode a TIMESTAMP object from Org to HTML.
3345 CONTENTS is nil. INFO is a plist holding contextual
3347 (let ((value (org-html-plain-text (org-timestamp-translate timestamp
) info
)))
3348 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3349 (replace-regexp-in-string "--" "–" value
))))
3353 (defun org-html-underline (underline contents info
)
3354 "Transcode UNDERLINE from Org to HTML.
3355 CONTENTS is the text with underline markup. INFO is a plist
3356 holding contextual information."
3357 (format (or (cdr (assq 'underline
(plist-get info
:html-text-markup-alist
)))
3363 (defun org-html-verbatim (verbatim contents info
)
3364 "Transcode VERBATIM from Org to HTML.
3365 CONTENTS is nil. INFO is a plist holding contextual
3367 (format (or (cdr (assq 'verbatim
(plist-get info
:html-text-markup-alist
))) "%s")
3368 (org-html-encode-plain-text (org-element-property :value verbatim
))))
3372 (defun org-html-verse-block (verse-block contents info
)
3373 "Transcode a VERSE-BLOCK element from Org to HTML.
3374 CONTENTS is verse block contents. INFO is a plist holding
3375 contextual information."
3376 ;; Replace each newline character with line break. Also replace
3377 ;; each blank line with a line break.
3378 (setq contents
(replace-regexp-in-string
3379 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info
))
3380 (replace-regexp-in-string
3381 "\\(\\\\\\\\\\)?[ \t]*\n"
3382 (format "%s\n" (org-html-close-tag "br" nil info
)) contents
)))
3383 ;; Replace each white space at beginning of a line with a
3384 ;; non-breaking space.
3385 (while (string-match "^[ \t]+" contents
)
3386 (let* ((num-ws (length (match-string 0 contents
)))
3387 (ws (let (out) (dotimes (i num-ws out
)
3388 (setq out
(concat out
" "))))))
3389 (setq contents
(replace-match ws nil t contents
))))
3390 (format "<p class=\"verse\">\n%s</p>" contents
))
3393 ;;; Filter Functions
3395 (defun org-html-final-function (contents backend info
)
3396 "Filter to indent the HTML and convert HTML entities."
3400 (if (plist-get info
:html-indent
)
3401 (indent-region (point-min) (point-max)))
3402 (when (plist-get info
:html-use-unicode-chars
)
3404 (mm-url-decode-entities))
3405 (buffer-substring-no-properties (point-min) (point-max))))
3408 ;;; End-user functions
3411 (defun org-html-export-as-html
3412 (&optional async subtreep visible-only body-only ext-plist
)
3413 "Export current buffer to an HTML buffer.
3415 If narrowing is active in the current buffer, only export its
3418 If a region is active, export that region.
3420 A non-nil optional argument ASYNC means the process should happen
3421 asynchronously. The resulting buffer should be accessible
3422 through the `org-export-stack' interface.
3424 When optional argument SUBTREEP is non-nil, export the sub-tree
3425 at point, extracting information from the headline properties
3428 When optional argument VISIBLE-ONLY is non-nil, don't export
3429 contents of hidden elements.
3431 When optional argument BODY-ONLY is non-nil, only write code
3432 between \"<body>\" and \"</body>\" tags.
3434 EXT-PLIST, when provided, is a property list with external
3435 parameters overriding Org default settings, but still inferior to
3436 file-local settings.
3438 Export is done in a buffer named \"*Org HTML Export*\", which
3439 will be displayed when `org-export-show-temporary-export-buffer'
3442 (org-export-to-buffer 'html
"*Org HTML Export*"
3443 async subtreep visible-only body-only ext-plist
3444 (lambda () (set-auto-mode t
))))
3447 (defun org-html-convert-region-to-html ()
3448 "Assume the current region has org-mode syntax, and convert it to HTML.
3449 This can be used in any buffer. For example, you can write an
3450 itemized list in org-mode syntax in an HTML buffer and use this
3451 command to convert it."
3453 (org-export-replace-region-by 'html
))
3456 (defun org-html-export-to-html
3457 (&optional async subtreep visible-only body-only ext-plist
)
3458 "Export current buffer to a HTML file.
3460 If narrowing is active in the current buffer, only export its
3463 If a region is active, export that region.
3465 A non-nil optional argument ASYNC means the process should happen
3466 asynchronously. The resulting file should be accessible through
3467 the `org-export-stack' interface.
3469 When optional argument SUBTREEP is non-nil, export the sub-tree
3470 at point, extracting information from the headline properties
3473 When optional argument VISIBLE-ONLY is non-nil, don't export
3474 contents of hidden elements.
3476 When optional argument BODY-ONLY is non-nil, only write code
3477 between \"<body>\" and \"</body>\" tags.
3479 EXT-PLIST, when provided, is a property list with external
3480 parameters overriding Org default settings, but still inferior to
3481 file-local settings.
3483 Return output file's name."
3485 (let* ((extension (concat "." (or (plist-get ext-plist
:html-extension
)
3488 (file (org-export-output-file-name extension subtreep
))
3489 (org-export-coding-system org-html-coding-system
))
3490 (org-export-to-file 'html file
3491 async subtreep visible-only body-only ext-plist
)))
3494 (defun org-html-publish-to-html (plist filename pub-dir
)
3495 "Publish an org file to HTML.
3497 FILENAME is the filename of the Org file to be published. PLIST
3498 is the property list for the given project. PUB-DIR is the
3499 publishing directory.
3501 Return output file name."
3502 (org-publish-org-to 'html filename
3503 (concat "." (or (plist-get plist
:html-extension
)
3512 ;; generated-autoload-file: "org-loaddefs.el"
3515 ;;; ox-html.el ends here