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-extension nil nil org-html-extension
)
122 (:html-link-org-as-html nil nil org-html-link-org-files-as-html
)
123 (:html-html5-fancy nil
"html5-fancy" org-html-html5-fancy
)
124 (:html-link-use-abs-url nil
"html-link-use-abs-url" org-html-link-use-abs-url
)
125 (:html-postamble nil
"html-postamble" org-html-postamble
)
126 (:html-preamble nil
"html-preamble" org-html-preamble
)
127 (:html-head
"HTML_HEAD" nil org-html-head newline
)
128 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
129 (:html-head-include-default-style
130 nil
"html-style" org-html-head-include-default-style
)
131 (:html-head-include-scripts nil
"html-scripts" org-html-head-include-scripts
)
132 (:html-allow-name-attribute-in-anchors
133 nil nil org-html-allow-name-attribute-in-anchors
)
134 (:html-coding-system nil nil org-html-coding-system
)
135 (:html-divs nil nil org-html-divs
)
136 (:html-extension nil nil org-html-extension
)
137 (:html-footnote-format nil nil org-html-footnote-format
)
138 (:html-footnote-separator nil nil org-html-footnote-separator
)
139 (:html-footnotes-section nil nil org-html-footnotes-section
)
140 (:html-format-drawer-function nil nil org-html-format-drawer-function
)
141 (:html-format-headline-function nil nil org-html-format-headline-function
)
142 (:html-format-inlinetask-function
143 nil nil org-html-format-inlinetask-function
)
144 (:html-home
/up-format nil nil org-html-home
/up-format
)
145 (:html-htmlize-font-prefix nil nil org-html-htmlize-font-prefix
)
146 (:html-htmlize-output-type nil nil org-html-htmlize-output-type
)
147 (:html-indent nil nil org-html-indent
)
148 (:html-infojs-options nil nil org-html-infojs-options
)
149 (:html-infojs-template nil nil org-html-infojs-template
)
150 (:html-inline-image-rules nil nil org-html-inline-image-rules
)
151 (:html-link-org-as-html nil nil org-html-link-org-files-as-html
)
152 (:html-mathjax-options nil nil org-html-mathjax-options
)
153 (:html-mathjax-template nil nil org-html-mathjax-template
)
154 (:html-metadata-timestamp-format nil nil org-html-metadata-timestamp-format
)
155 (:html-postamble-format nil nil org-html-postamble-format
)
156 (:html-preamble-format nil nil org-html-preamble-format
)
157 (:html-protect-char-alist nil nil org-html-protect-char-alist
)
158 (:html-table-align-individual-fields
159 nil nil org-html-table-align-individual-fields
)
160 (:html-table-caption-above nil nil org-html-table-caption-above
)
161 (:html-table-data-tags nil nil org-html-table-data-tags
)
162 (:html-table-header-tags nil nil org-html-table-header-tags
)
163 (:html-table-use-header-tags-for-first-column
164 nil nil org-html-table-use-header-tags-for-first-column
)
165 (:html-tag-class-prefix nil nil org-html-tag-class-prefix
)
166 (:html-text-markup-alist nil nil org-html-text-markup-alist
)
167 (:html-todo-kwd-class-prefix nil nil org-html-todo-kwd-class-prefix
)
168 (:html-toplevel-hlevel nil nil org-html-toplevel-hlevel
)
169 (:html-use-infojs nil nil org-html-use-infojs
)
170 (:html-use-unicode-chars nil nil org-html-use-unicode-chars
)
171 (:html-validation-link nil nil org-html-validation-link
)
172 (:html-inline-images nil nil org-html-inline-images
)
173 (:html-table-attributes nil nil org-html-table-default-attributes
)
174 (:html-table-row-tags nil nil org-html-table-row-tags
)
175 (:html-xml-declaration nil nil org-html-xml-declaration
)
176 (:infojs-opt
"INFOJS_OPT" nil nil
)
177 ;; Redefine regular options.
178 (:creator
"CREATOR" nil org-html-creator-string
)
179 (:with-latex nil
"tex" org-html-with-latex
)
180 ;; Retrieve LaTeX header for fragments.
181 (:latex-header
"LATEX_HEADER" nil nil newline
)))
184 ;;; Internal Variables
186 (defvar org-html-format-table-no-css
)
187 (defvar htmlize-buffer-places
) ; from htmlize.el
189 (defvar org-html--pre
/postamble-class
"status"
190 "CSS class used for pre/postamble")
192 (defconst org-html-doctype-alist
193 '(("html4-strict" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
194 \"http://www.w3.org/TR/html4/strict.dtd\">")
195 ("html4-transitional" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
196 \"http://www.w3.org/TR/html4/loose.dtd\">")
197 ("html4-frameset" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
198 \"http://www.w3.org/TR/html4/frameset.dtd\">")
200 ("xhtml-strict" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
201 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
202 ("xhtml-transitional" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
203 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
204 ("xhtml-frameset" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
205 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
206 ("xhtml-11" .
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
207 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
209 ("html5" .
"<!DOCTYPE html>")
210 ("xhtml5" .
"<!DOCTYPE html>"))
211 "An alist mapping (x)html flavors to specific doctypes.")
213 (defconst org-html-html5-elements
214 '("article" "aside" "audio" "canvas" "details" "figcaption"
215 "figure" "footer" "header" "menu" "meter" "nav" "output"
216 "progress" "section" "video")
217 "New elements in html5.
219 For blocks that should contain headlines, use the HTML_CONTAINER
220 property on the headline itself.")
222 (defconst org-html-special-string-regexps
223 '(("\\\\-" .
"­") ; shy
224 ("---\\([^-]\\)" .
"—\\1") ; mdash
225 ("--\\([^-]\\)" .
"–\\1") ; ndash
226 ("\\.\\.\\." .
"…")) ; hellip
227 "Regular expressions for special string conversion.")
229 (defconst org-html-scripts
230 "<script type=\"text/javascript\">
232 @licstart The following is the entire license notice for the
233 JavaScript code in this tag.
235 Copyright (C) 2012-2013 Free Software Foundation, Inc.
237 The JavaScript code in this tag is free software: you can
238 redistribute it and/or modify it under the terms of the GNU
239 General Public License (GNU GPL) as published by the Free Software
240 Foundation, either version 3 of the License, or (at your option)
241 any later version. The code is distributed WITHOUT ANY WARRANTY;
242 without even the implied warranty of MERCHANTABILITY or FITNESS
243 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
245 As additional permission under GNU GPL version 3 section 7, you
246 may distribute non-source (e.g., minimized or compacted) forms of
247 that code without the copy of the GNU GPL normally required by
248 section 4, provided you include this license notice and a URL
249 through which recipients can access the Corresponding Source.
252 @licend The above is the entire license notice
253 for the JavaScript code in this tag.
255 <!--/*--><![CDATA[/*><!--*/
256 function CodeHighlightOn(elem, id)
258 var target = document.getElementById(id);
260 elem.cacheClassElem = elem.className;
261 elem.cacheClassTarget = target.className;
262 target.className = \"code-highlighted\";
263 elem.className = \"code-highlighted\";
266 function CodeHighlightOff(elem, id)
268 var target = document.getElementById(id);
269 if(elem.cacheClassElem)
270 elem.className = elem.cacheClassElem;
271 if(elem.cacheClassTarget)
272 target.className = elem.cacheClassTarget;
276 "Basic JavaScript that is needed by HTML files produced by Org mode.")
278 (defconst org-html-style-default
279 "<style type=\"text/css\">
280 <!--/*--><![CDATA[/*><!--*/
281 .title { text-align: center; }
282 .todo { font-family: monospace; color: red; }
283 .done { color: green; }
284 .tag { background-color: #eee; font-family: monospace;
285 padding: 2px; font-size: 80%; font-weight: normal; }
286 .timestamp { color: #bebebe; }
287 .timestamp-kwd { color: #5f9ea0; }
288 .right { margin-left: auto; margin-right: 0px; text-align: right; }
289 .left { margin-left: 0px; margin-right: auto; text-align: left; }
290 .center { margin-left: auto; margin-right: auto; text-align: center; }
291 .underline { text-decoration: underline; }
292 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
293 p.verse { margin-left: 3%; }
295 border: 1px solid #ccc;
296 box-shadow: 3px 3px 3px #eee;
298 font-family: monospace;
310 background-color: white;
314 border: 1px solid black;
316 pre.src:hover:before { display: inline;}
317 pre.src-sh:before { content: 'sh'; }
318 pre.src-bash:before { content: 'sh'; }
319 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
320 pre.src-R:before { content: 'R'; }
321 pre.src-perl:before { content: 'Perl'; }
322 pre.src-java:before { content: 'Java'; }
323 pre.src-sql:before { content: 'SQL'; }
325 table { border-collapse:collapse; }
326 caption.t-above { caption-side: top; }
327 caption.t-bottom { caption-side: bottom; }
328 td, th { vertical-align:top; }
329 th.right { text-align: center; }
330 th.left { text-align: center; }
331 th.center { text-align: center; }
332 td.right { text-align: right; }
333 td.left { text-align: left; }
334 td.center { text-align: center; }
335 dt { font-weight: bold; }
336 .footpara:nth-child(2) { display: inline; }
337 .footpara { display: block; }
338 .footdef { margin-bottom: 1em; }
339 .figure { padding: 1em; }
340 .figure p { text-align: center; }
343 border: 2px solid gray;
348 { text-align: right; font-size: 70%; white-space: nowrap; }
349 textarea { overflow-x: auto; }
350 .linenr { font-size: smaller }
351 .code-highlighted { background-color: #ffff00; }
352 .org-info-js_info-navigation { border-style: none; }
353 #org-info-js_console-label
354 { font-size: 10px; font-weight: bold; white-space: nowrap; }
355 .org-info-js_search-highlight
356 { background-color: #ffff00; color: #000000; font-weight: bold; }
359 "The default style specification for exported HTML files.
360 You can use `org-html-head' and `org-html-head-extra' to add to
361 this style. If you don't want to include this default style,
362 customize `org-html-head-include-default-style'.")
365 ;;; User Configuration Variables
367 (defgroup org-export-html nil
368 "Options for exporting Org mode files to HTML."
369 :tag
"Org Export HTML"
374 (defvar org-html-infojs-opts-table
375 '((path PATH
"http://orgmode.org/org-info.js")
379 (tdepth TOC_DEPTH
"max")
380 (sdepth SECTION_DEPTH
"max")
381 (mouse MOUSE_HINT
"underline")
382 (buttons VIEW_BUTTONS
"0")
384 (up LINK_UP
:html-link-up
)
385 (home LINK_HOME
:html-link-home
))
386 "JavaScript options, long form for script, default values.")
388 (defcustom org-html-use-infojs
'when-configured
389 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
390 This option can be nil or t to never or always use the script.
391 It can also be the symbol `when-configured', meaning that the
392 script will be linked into the export file if and only if there
393 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
394 `org-html-infojs-options'."
395 :group
'org-export-html
397 :package-version
'(Org .
"8.0")
399 (const :tag
"Never" nil
)
400 (const :tag
"When configured in buffer" when-configured
)
401 (const :tag
"Always" t
)))
403 (defcustom org-html-infojs-options
404 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
405 "Options settings for the INFOJS JavaScript.
406 Each of the options must have an entry in `org-html-infojs-opts-table'.
407 The value can either be a string that will be passed to the script, or
408 a property. This property is then assumed to be a property that is defined
409 by the Export/Publishing setup of Org.
410 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
411 means to use the maximum value consistent with other options."
412 :group
'org-export-html
414 :package-version
'(Org .
"8.0")
416 `(set :greedy t
:inline t
419 (list 'cons
(list 'const
(car x
))
421 (symbol :tag
"Publishing/Export property")
422 (string :tag
"Value"))))
423 org-html-infojs-opts-table
)))
425 (defcustom org-html-infojs-template
426 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
429 * @source: %SCRIPT_PATH
431 * @licstart The following is the entire license notice for the
432 * JavaScript code in %SCRIPT_PATH.
434 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
437 * The JavaScript code in this tag is free software: you can
438 * redistribute it and/or modify it under the terms of the GNU
439 * General Public License (GNU GPL) as published by the Free Software
440 * Foundation, either version 3 of the License, or (at your option)
441 * any later version. The code is distributed WITHOUT ANY WARRANTY;
442 * without even the implied warranty of MERCHANTABILITY or FITNESS
443 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
445 * As additional permission under GNU GPL version 3 section 7, you
446 * may distribute non-source (e.g., minimized or compacted) forms of
447 * that code without the copy of the GNU GPL normally required by
448 * section 4, provided you include this license notice and a URL
449 * through which recipients can access the Corresponding Source.
451 * @licend The above is the entire license notice
452 * for the JavaScript code in %SCRIPT_PATH.
457 <script type=\"text/javascript\">
460 @licstart The following is the entire license notice for the
461 JavaScript code in this tag.
463 Copyright (C) 2012-2013 Free Software Foundation, Inc.
465 The JavaScript code in this tag is free software: you can
466 redistribute it and/or modify it under the terms of the GNU
467 General Public License (GNU GPL) as published by the Free Software
468 Foundation, either version 3 of the License, or (at your option)
469 any later version. The code is distributed WITHOUT ANY WARRANTY;
470 without even the implied warranty of MERCHANTABILITY or FITNESS
471 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
473 As additional permission under GNU GPL version 3 section 7, you
474 may distribute non-source (e.g., minimized or compacted) forms of
475 that code without the copy of the GNU GPL normally required by
476 section 4, provided you include this license notice and a URL
477 through which recipients can access the Corresponding Source.
480 @licend The above is the entire license notice
481 for the JavaScript code in this tag.
484 <!--/*--><![CDATA[/*><!--*/
486 org_html_manager.setup(); // activate after the parameters are set
489 "The template for the export style additions when org-info.js is used.
490 Option settings will replace the %MANAGER-OPTIONS cookie."
491 :group
'org-export-html
493 :package-version
'(Org .
"8.0")
496 (defun org-html-infojs-install-script (exp-plist backend
)
497 "Install script in export options when appropriate.
498 EXP-PLIST is a plist containing export options. BACKEND is the
499 export back-end currently used."
500 (unless (or (memq 'body-only
(plist-get exp-plist
:export-options
))
501 (not org-html-use-infojs
)
502 (and (eq org-html-use-infojs
'when-configured
)
503 (or (not (plist-get exp-plist
:infojs-opt
))
504 (string= "" (plist-get exp-plist
:infojs-opt
))
505 (string-match "\\<view:nil\\>"
506 (plist-get exp-plist
:infojs-opt
)))))
507 (let* ((template org-html-infojs-template
)
508 (ptoc (plist-get exp-plist
:with-toc
))
509 (hlevels (plist-get exp-plist
:headline-levels
))
511 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
512 (options (plist-get exp-plist
:infojs-opt
))
513 (table org-html-infojs-opts-table
)
515 (dolist (entry table
)
516 (let* ((opt (car entry
))
518 ;; Compute default values for script option OPT from
519 ;; `org-html-infojs-options' variable.
521 (let ((default (cdr (assq opt org-html-infojs-options
))))
522 (if (and (symbolp default
) (not (memq default
'(t nil
))))
523 (plist-get exp-plist default
)
525 ;; Value set through INFOJS_OPT keyword has precedence
526 ;; over the default one.
527 (val (if (and options
528 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
530 (match-string 1 options
)
534 (replace-regexp-in-string
535 "%SCRIPT_PATH" val template t t
)))
536 (sdepth (when (integerp (read val
))
537 (setq sdepth
(min (read val
) sdepth
))))
538 (tdepth (when (integerp (read val
))
539 (setq tdepth
(min (read val
) tdepth
))))
542 ((or (eq val t
) (equal val
"t")) "1")
543 ((or (eq val nil
) (equal val
"nil")) "0")
545 (t (format "%s" val
))))
546 (push (cons var val
) style
)))))
547 ;; Now we set the depth of the *generated* TOC to SDEPTH,
548 ;; because the toc will actually determine the splitting. How
549 ;; much of the toc will actually be displayed is governed by the
551 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
552 ;; The table of contents should not show more sections than we
554 (setq tdepth
(min tdepth sdepth
))
555 (push (cons "TOC_DEPTH" tdepth
) style
)
556 ;; Build style string.
557 (setq style
(mapconcat
558 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
562 (when (and style
(> (length style
) 0))
563 (and (string-match "%MANAGER_OPTIONS" template
)
564 (setq style
(replace-match style t t template
))
567 exp-plist
:html-head-extra
568 (concat (or (plist-get exp-plist
:html-head-extra
) "")
571 ;; This script absolutely needs the table of contents, so we
572 ;; change that setting.
573 (unless (plist-get exp-plist
:with-toc
)
574 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
575 ;; Return the modified property list.
580 (defcustom org-html-text-markup-alist
581 '((bold .
"<b>%s</b>")
582 (code .
"<code>%s</code>")
583 (italic .
"<i>%s</i>")
584 (strike-through .
"<del>%s</del>")
585 (underline .
"<span class=\"underline\">%s</span>")
586 (verbatim .
"<code>%s</code>"))
587 "Alist of HTML expressions to convert text markup.
589 The key must be a symbol among `bold', `code', `italic',
590 `strike-through', `underline' and `verbatim'. The value is
591 a formatting string to wrap fontified text with.
593 If no association can be found for a given markup, text will be
595 :group
'org-export-html
597 :package-version
'(Org .
"8.0")
598 :type
'(alist :key-type
(symbol :tag
"Markup type")
599 :value-type
(string :tag
"Format string"))
600 :options
'(bold code italic strike-through underline verbatim
))
602 (defcustom org-html-indent nil
603 "Non-nil means to indent the generated HTML.
604 Warning: non-nil may break indentation of source code blocks."
605 :group
'org-export-html
607 :package-version
'(Org .
"8.0")
610 (defcustom org-html-use-unicode-chars nil
611 "Non-nil means to use unicode characters instead of HTML entities."
612 :group
'org-export-html
614 :package-version
'(Org .
"8.0")
619 (defcustom org-html-format-drawer-function
620 (lambda (name contents
) contents
)
621 "Function called to format a drawer in HTML code.
623 The function must accept two parameters:
624 NAME the drawer name, like \"LOGBOOK\"
625 CONTENTS the contents of the drawer.
627 The function should return the string to be exported.
629 For example, the variable could be set to the following function
630 in order to mimic default behaviour:
632 The default value simply returns the value of CONTENTS."
633 :group
'org-export-html
635 :package-version
'(Org .
"8.0")
640 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
641 <h2 class=\"footnotes\">%s: </h2>
642 <div id=\"text-footnotes\">
646 "Format for the footnotes section.
647 Should contain a two instances of %s. The first will be replaced with the
648 language-specific word for \"Footnotes\", the second one will be replaced
649 by the footnotes themselves."
650 :group
'org-export-html
653 (defcustom org-html-footnote-format
"<sup>%s</sup>"
654 "The format for the footnote reference.
655 %s will be replaced by the footnote reference itself."
656 :group
'org-export-html
659 (defcustom org-html-footnote-separator
"<sup>, </sup>"
660 "Text used to separate footnotes."
661 :group
'org-export-html
666 (defcustom org-html-toplevel-hlevel
2
667 "The <H> level for level 1 headings in HTML export.
668 This is also important for the classes that will be wrapped around headlines
669 and outline structure. If this variable is 1, the top-level headlines will
670 be <h1>, and the corresponding classes will be outline-1, section-number-1,
671 and outline-text-1. If this is 2, all of these will get a 2 instead.
672 The default for this variable is 2, because we use <h1> for formatting the
674 :group
'org-export-html
677 (defcustom org-html-format-headline-function
'ignore
678 "Function to format headline text.
680 This function will be called with 5 arguments:
681 TODO the todo keyword (string or nil).
682 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
683 PRIORITY the priority of the headline (integer or nil)
684 TEXT the main headline text (string).
685 TAGS the tags (string or nil).
687 The function result will be used in the section format string."
688 :group
'org-export-html
690 :package-version
'(Org .
"8.0")
695 (defcustom org-html-allow-name-attribute-in-anchors nil
696 "When nil, do not set \"name\" attribute in anchors.
697 By default, when appropriate, anchors are formatted with \"id\"
698 but without \"name\" attribute."
699 :group
'org-export-html
701 :package-version
'(Org .
"8.0")
706 (defcustom org-html-format-inlinetask-function
'ignore
707 "Function called to format an inlinetask in HTML code.
709 The function must accept six parameters:
710 TODO the todo keyword, as a string
711 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
712 PRIORITY the inlinetask priority, as a string
713 NAME the inlinetask name, as a string.
714 TAGS the inlinetask tags, as a list of strings.
715 CONTENTS the contents of the inlinetask, as a string.
717 The function should return the string to be exported."
718 :group
'org-export-html
720 :package-version
'(Org .
"8.0")
725 (defcustom org-html-with-latex org-export-with-latex
726 "Non-nil means process LaTeX math snippets.
728 When set, the exporter will process LaTeX environments and
731 This option can also be set with the +OPTIONS line,
732 e.g. \"tex:mathjax\". Allowed values are:
734 nil Ignore math snippets.
735 `verbatim' Keep everything in verbatim
736 `dvipng' Process the LaTeX fragments to images. This will also
737 include processing of non-math environments.
738 `imagemagick' Convert the LaTeX fragments to pdf files and use
739 imagemagick to convert pdf files to png files.
740 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
742 t Synonym for `mathjax'."
743 :group
'org-export-html
745 :package-version
'(Org .
"8.0")
747 (const :tag
"Do not process math in any way" nil
)
748 (const :tag
"Use dvipng to make images" dvipng
)
749 (const :tag
"Use imagemagick to make images" imagemagick
)
750 (const :tag
"Use MathJax to display math" mathjax
)
751 (const :tag
"Leave math verbatim" verbatim
)))
753 ;;;; Links :: Generic
755 (defcustom org-html-link-org-files-as-html t
756 "Non-nil means make file links to `file.org' point to `file.html'.
757 When `org-mode' is exporting an `org-mode' file to HTML, links to
758 non-html files are directly put into a href tag in HTML.
759 However, links to other Org-mode files (recognized by the
760 extension `.org.) should become links to the corresponding html
761 file, assuming that the linked `org-mode' file will also be
763 When nil, the links still point to the plain `.org' file."
764 :group
'org-export-html
767 ;;;; Links :: Inline images
769 (defcustom org-html-inline-images t
770 "Non-nil means inline images into exported HTML pages.
771 This is done using an <img> tag. When nil, an anchor with href is used to
773 :group
'org-export-html
775 :package-version
'(Org .
"8.1")
778 (defcustom org-html-inline-image-rules
779 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
780 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
781 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
782 "Rules characterizing image files that can be inlined into HTML.
783 A rule consists in an association whose key is the type of link
784 to consider, and value is a regexp that will be matched against
786 :group
'org-export-html
788 :package-version
'(Org .
"8.0")
789 :type
'(alist :key-type
(string :tag
"Type")
790 :value-type
(regexp :tag
"Path")))
794 (defcustom org-html-protect-char-alist
798 "Alist of characters to be converted by `org-html-protect'."
799 :group
'org-export-html
800 :type
'(repeat (cons (string :tag
"Character")
801 (string :tag
"HTML equivalent"))))
805 (defcustom org-html-htmlize-output-type
'inline-css
806 "Output type to be used by htmlize when formatting code snippets.
807 Choices are `css' to export the CSS selectors only,`inline-css'
808 to export the CSS attribute values inline in the HTML or `nil' to
809 export plain text. We use as default `inline-css', in order to
810 make the resulting HTML self-containing.
812 However, this will fail when using Emacs in batch mode for export, because
813 then no rich font definitions are in place. It will also not be good if
814 people with different Emacs setup contribute HTML files to a website,
815 because the fonts will represent the individual setups. In these cases,
816 it is much better to let Org/Htmlize assign classes only, and to use
817 a style file to define the look of these classes.
818 To get a start for your css file, start Emacs session and make sure that
819 all the faces you are interested in are defined, for example by loading files
820 in all modes you want. Then, use the command
821 \\[org-html-htmlize-generate-css] to extract class definitions."
822 :group
'org-export-html
823 :type
'(choice (const css
) (const inline-css
) (const nil
)))
825 (defcustom org-html-htmlize-font-prefix
"org-"
826 "The prefix for CSS class names for htmlize font specifications."
827 :group
'org-export-html
832 (defcustom org-html-table-default-attributes
833 '(:border
"2" :cellspacing
"0" :cellpadding
"6" :rules
"groups" :frame
"hsides")
834 "Default attributes and values which will be used in table tags.
835 This is a plist where attributes are symbols, starting with
836 colons, and values are strings.
838 When exporting to HTML5, these values will be disregarded."
839 :group
'org-export-html
841 :package-version
'(Org .
"8.0")
842 :type
'(plist :key-type
(symbol :tag
"Property")
843 :value-type
(string :tag
"Value")))
845 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
846 "The opening and ending tags for table header fields.
847 This is customizable so that alignment options can be specified.
848 The first %s will be filled with the scope of the field, either row or col.
849 The second %s will be replaced by a style entry to align the field.
850 See also the variable `org-html-table-use-header-tags-for-first-column'.
851 See also the variable `org-html-table-align-individual-fields'."
852 :group
'org-export-html
853 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
855 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
856 "The opening and ending tags for table data fields.
857 This is customizable so that alignment options can be specified.
858 The first %s will be filled with the scope of the field, either row or col.
859 The second %s will be replaced by a style entry to align the field.
860 See also the variable `org-html-table-align-individual-fields'."
861 :group
'org-export-html
862 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
864 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
865 "The opening and ending tags for table rows.
866 This is customizable so that alignment options can be specified.
867 Instead of strings, these can be Lisp forms that will be
868 evaluated for each row in order to construct the table row tags.
870 During evaluation, these variables will be dynamically bound so that
873 `row-number': row number (0 is the first row)
874 `rowgroup-number': group number of current row
875 `start-rowgroup-p': non-nil means the row starts a group
876 `end-rowgroup-p': non-nil means the row ends a group
877 `top-row-p': non-nil means this is the top row
878 `bottom-row-p': non-nil means this is the bottom row
882 \(setq org-html-table-row-tags
883 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
884 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
885 (t (if (= (mod row-number 2) 1)
886 \"<tr class=\\\"tr-odd\\\">\"
887 \"<tr class=\\\"tr-even\\\">\")))
890 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
891 and the bottom row, and otherwise alternate between \"tr-odd\" and
892 \"tr-even\" for odd and even rows."
893 :group
'org-export-html
895 (choice :tag
"Opening tag"
896 (string :tag
"Specify")
898 (choice :tag
"Closing tag"
899 (string :tag
"Specify")
902 (defcustom org-html-table-align-individual-fields t
903 "Non-nil means attach style attributes for alignment to each table field.
904 When nil, alignment will only be specified in the column tags, but this
905 is ignored by some browsers (like Firefox, Safari). Opera does it right
907 :group
'org-export-html
910 (defcustom org-html-table-use-header-tags-for-first-column nil
911 "Non-nil means format column one in tables with header tags.
912 When nil, also column one will use data tags."
913 :group
'org-export-html
916 (defcustom org-html-table-caption-above t
917 "When non-nil, place caption string at the beginning of the table.
918 Otherwise, place it near the end."
919 :group
'org-export-html
924 (defcustom org-html-tag-class-prefix
""
925 "Prefix to class names for TODO keywords.
926 Each tag gets a class given by the tag itself, with this prefix.
927 The default prefix is empty because it is nice to just use the keyword
928 as a class name. But if you get into conflicts with other, existing
929 CSS classes, then this prefix can be very useful."
930 :group
'org-export-html
933 ;;;; Template :: Generic
935 (defcustom org-html-extension
"html"
936 "The extension for exported HTML files."
937 :group
'org-export-html
940 (defcustom org-html-xml-declaration
941 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
942 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
943 "The extension for exported HTML files.
944 %s will be replaced with the charset of the exported file.
945 This may be a string, or an alist with export extensions
946 and corresponding declarations.
948 This declaration only applies when exporting to XHTML."
949 :group
'org-export-html
951 (string :tag
"Single declaration")
952 (repeat :tag
"Dependent on extension"
953 (cons (string :tag
"Extension")
954 (string :tag
"Declaration")))))
956 (defcustom org-html-coding-system
'utf-8
957 "Coding system for HTML export.
958 Use utf-8 as the default value."
959 :group
'org-export-html
961 :package-version
'(Org .
"8.0")
962 :type
'coding-system
)
964 (defcustom org-html-doctype
"xhtml-strict"
965 "Document type definition to use for exported HTML files.
966 Can be set with the in-buffer HTML_DOCTYPE property or for
967 publishing, with :html-doctype."
968 :group
'org-export-html
970 :package-version
'(Org .
"8.0")
973 (mapcar (lambda (x) `(const ,(car x
))) org-html-doctype-alist
)
974 '((string :tag
"Custom doctype" ))))
976 (defcustom org-html-html5-fancy nil
977 "Non-nil means using new HTML5 elements.
978 This variable is ignored for anything other than HTML5 export.
980 For compatibility with Internet Explorer, it's probably a good
981 idea to download some form of the html5shiv (for instance
982 https://code.google.com/p/html5shiv/) and add it to your
983 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
984 versions 8 and below."
985 :group
'org-export-html
987 :package-version
'(Org .
"8.0")
990 (defcustom org-html-container-element
"div"
991 "HTML element to use for wrapping top level sections.
992 Can be set with the in-buffer HTML_CONTAINER property or for
993 publishing, with :html-container.
995 Note that changing the default will prevent you from using
996 org-info.js for your website."
997 :group
'org-export-html
999 :package-version
'(Org .
"8.0")
1002 (defcustom org-html-divs
1003 '((preamble "div" "preamble")
1004 (content "div" "content")
1005 (postamble "div" "postamble"))
1006 "Alist of the three section elements for HTML export.
1007 The car of each entry is one of 'preamble, 'content or 'postamble.
1008 The cdrs of each entry are the ELEMENT_TYPE and ID for each
1009 section of the exported document.
1011 Note that changing the default will prevent you from using
1012 org-info.js for your website."
1013 :group
'org-export-html
1015 :package-version
'(Org .
"8.0")
1016 :type
'(list :greedy t
1017 (list :tag
"Preamble"
1018 (const :format
"" preamble
)
1019 (string :tag
"element") (string :tag
" id"))
1020 (list :tag
"Content"
1021 (const :format
"" content
)
1022 (string :tag
"element") (string :tag
" id"))
1023 (list :tag
"Postamble" (const :format
"" postamble
)
1024 (string :tag
" id") (string :tag
"element"))))
1026 (defconst org-html-checkbox-types
1028 ((on .
"☑") (off .
"☐") (trans .
"☐")))
1030 ((on .
"<code>[X]</code>")
1031 (off .
"<code>[ ]</code>")
1032 (trans .
"<code>[-]</code>")))
1034 ((on .
"<input type='checkbox' checked='checked' />")
1035 (off .
"<input type='checkbox' />")
1036 (trans .
"<input type='checkbox' />"))))
1037 "Alist of checkbox types.
1038 The cdr of each entry is an alist list three checkbox types for
1039 HTML export: `on', `off' and `trans'.
1042 `unicode' Unicode characters (HTML entities)
1043 `ascii' ASCII characters
1044 `html' HTML checkboxes
1046 Note that only the ascii characters implement tri-state
1047 checkboxes. The other two use the `off' checkbox for `trans'.")
1049 (defcustom org-html-checkbox-type
'ascii
1050 "The type of checkboxes to use for HTML export.
1051 See `org-html-checkbox-types' for for the values used for each
1053 :group
'org-export-html
1055 :package-version
'(Org .
"8.0")
1057 (const :tag
"ASCII characters" ascii
)
1058 (const :tag
"Unicode characters" unicode
)
1059 (const :tag
"HTML checkboxes" html
)))
1061 (defcustom org-html-metadata-timestamp-format
"%Y-%m-%d %a %H:%M"
1062 "Format used for timestamps in preamble, postamble and metadata.
1063 See `format-time-string' for more information on its components."
1064 :group
'org-export-html
1066 :package-version
'(Org .
"8.0")
1069 ;;;; Template :: Mathjax
1071 (defcustom org-html-mathjax-options
1072 '((path "http://orgmode.org/mathjax/MathJax.js")
1077 "Options for MathJax setup.
1079 path The path where to find MathJax
1080 scale Scaling for the HTML-CSS backend, usually between 100 and 133
1081 align How to align display math: left, center, or right
1082 indent If align is not center, how far from the left/right side?
1083 mathml Should a MathML player be used if available?
1084 This is faster and reduces bandwidth use, but currently
1085 sometimes has lower spacing quality. Therefore, the default is
1086 nil. When browsers get better, this switch can be flipped.
1088 You can also customize this for each buffer, using something like
1090 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1091 :group
'org-export-html
1092 :type
'(list :greedy t
1093 (list :tag
"path (the path from where to load MathJax.js)"
1094 (const :format
" " path
) (string))
1095 (list :tag
"scale (scaling for the displayed math)"
1096 (const :format
" " scale
) (string))
1097 (list :tag
"align (alignment of displayed equations)"
1098 (const :format
" " align
) (string))
1099 (list :tag
"indent (indentation with left or right alignment)"
1100 (const :format
" " indent
) (string))
1101 (list :tag
"mathml (should MathML display be used is possible)"
1102 (const :format
" " mathml
) (boolean))))
1104 (defcustom org-html-mathjax-template
1105 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1106 <script type=\"text/javascript\">
1107 <!--/*--><![CDATA[/*><!--*/
1108 MathJax.Hub.Config({
1109 // Only one of the two following lines, depending on user settings
1110 // First allows browser-native MathML display, second forces HTML/CSS
1111 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1112 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1113 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1114 \"TeX/noUndefined.js\"],
1116 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1117 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1118 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1119 ignoreClass: \"tex2jax_ignore\",
1120 processEscapes: false,
1121 processEnvironments: true,
1124 showProcessingMessages: true,
1125 displayAlign: \"%ALIGN\",
1126 displayIndent: \"%INDENT\",
1130 availableFonts: [\"STIX\",\"TeX\"],
1131 preferredFont: \"TeX\",
1147 "The MathJax setup for XHTML files."
1148 :group
'org-export-html
1151 ;;;; Template :: Postamble
1153 (defcustom org-html-postamble
'auto
1154 "Non-nil means insert a postamble in HTML export.
1156 When set to 'auto, check against the
1157 `org-export-with-author/email/creator/date' variables to set the
1158 content of the postamble. When set to a string, use this string
1159 as the postamble. When t, insert a string as defined by the
1160 formatting string in `org-html-postamble-format'.
1162 When set to a function, apply this function and insert the
1163 returned string. The function takes the property list of export
1164 options as its only argument.
1166 Setting :html-postamble in publishing projects will take
1167 precedence over this variable."
1168 :group
'org-export-html
1169 :type
'(choice (const :tag
"No postamble" nil
)
1170 (const :tag
"Auto postamble" auto
)
1171 (const :tag
"Default formatting string" t
)
1172 (string :tag
"Custom formatting string")
1173 (function :tag
"Function (must return a string)")))
1175 (defcustom org-html-postamble-format
1176 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1177 <p class=\"date\">Date: %d</p>
1178 <p class=\"creator\">%c</p>
1179 <p class=\"validation\">%v</p>"))
1180 "Alist of languages and format strings for the HTML postamble.
1182 The first element of each list is the language code, as used for
1183 the LANGUAGE keyword. See `org-export-default-language'.
1185 The second element of each list is a format string to format the
1186 postamble itself. This format string can contain these elements:
1188 %t stands for the title.
1189 %a stands for the author's name.
1190 %e stands for the author's email.
1191 %d stands for the date.
1192 %c will be replaced by `org-html-creator-string'.
1193 %v will be replaced by `org-html-validation-link'.
1194 %T will be replaced by the export time.
1195 %C will be replaced by the last modification time.
1197 If you need to use a \"%\" character, you need to escape it
1199 :group
'org-export-html
1201 (list (string :tag
"Language")
1202 (string :tag
"Format string"))))
1204 (defcustom org-html-validation-link
1205 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1206 "Link to HTML validation service."
1207 :group
'org-export-html
1210 (defcustom org-html-creator-string
1211 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1213 (if (fboundp 'org-version
) (org-version) "unknown version"))
1214 "Information about the creator of the HTML document.
1215 This option can also be set on with the CREATOR keyword."
1216 :group
'org-export-html
1218 :package-version
'(Org .
"8.0")
1219 :type
'(string :tag
"Creator string"))
1221 ;;;; Template :: Preamble
1223 (defcustom org-html-preamble t
1224 "Non-nil means insert a preamble in HTML export.
1226 When t, insert a string as defined by the formatting string in
1227 `org-html-preamble-format'. When set to a string, use this
1228 formatting string instead (see `org-html-postamble-format' for an
1229 example of such a formatting string).
1231 When set to a function, apply this function and insert the
1232 returned string. The function takes the property list of export
1233 options as its only argument.
1235 Setting :html-preamble in publishing projects will take
1236 precedence over this variable."
1237 :group
'org-export-html
1238 :type
'(choice (const :tag
"No preamble" nil
)
1239 (const :tag
"Default preamble" t
)
1240 (string :tag
"Custom formatting string")
1241 (function :tag
"Function (must return a string)")))
1243 (defcustom org-html-preamble-format
'(("en" ""))
1244 "Alist of languages and format strings for the HTML preamble.
1246 The first element of each list is the language code, as used for
1247 the LANGUAGE keyword. See `org-export-default-language'.
1249 The second element of each list is a format string to format the
1250 preamble itself. This format string can contain these elements:
1252 %t stands for the title.
1253 %a stands for the author's name.
1254 %e stands for the author's email.
1255 %d stands for the date.
1256 %c will be replaced by `org-html-creator-string'.
1257 %v will be replaced by `org-html-validation-link'.
1258 %T will be replaced by the export time.
1259 %C will be replaced by the last modification time.
1261 If you need to use a \"%\" character, you need to escape it
1264 See the default value of `org-html-postamble-format' for an
1266 :group
'org-export-html
1268 (list (string :tag
"Language")
1269 (string :tag
"Format string"))))
1271 (defcustom org-html-link-up
""
1272 "Where should the \"UP\" link of exported HTML pages lead?"
1273 :group
'org-export-html
1274 :type
'(string :tag
"File or URL"))
1276 (defcustom org-html-link-home
""
1277 "Where should the \"HOME\" link of exported HTML pages lead?"
1278 :group
'org-export-html
1279 :type
'(string :tag
"File or URL"))
1281 (defcustom org-html-link-use-abs-url nil
1282 "Should we prepend relative links with HTML_LINK_HOME?"
1283 :group
'org-export-html
1285 :package-version
'(Org .
"8.1")
1288 (defcustom org-html-home
/up-format
1289 "<div id=\"org-div-home-and-up\">
1290 <a accesskey=\"h\" href=\"%s\"> UP </a>
1292 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1294 "Snippet used to insert the HOME and UP links.
1295 This is a format string, the first %s will receive the UP link,
1296 the second the HOME link. If both `org-html-link-up' and
1297 `org-html-link-home' are empty, the entire snippet will be
1299 :group
'org-export-html
1302 ;;;; Template :: Scripts
1304 (define-obsolete-variable-alias
1305 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1306 (defcustom org-html-head-include-scripts t
1307 "Non-nil means include the JavaScript snippets in exported HTML files.
1308 The actual script is defined in `org-html-scripts' and should
1310 :group
'org-export-html
1312 :package-version
'(Org .
"8.0")
1315 ;;;; Template :: Styles
1317 (define-obsolete-variable-alias
1318 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1319 (defcustom org-html-head-include-default-style t
1320 "Non-nil means include the default style in exported HTML files.
1321 The actual style is defined in `org-html-style-default' and
1322 should not be modified. Use `org-html-head' to use your own
1324 :group
'org-export-html
1326 :package-version
'(Org .
"8.0")
1329 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1331 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1332 (defcustom org-html-head
""
1333 "Org-wide head definitions for exported HTML files.
1335 This variable can contain the full HTML structure to provide a
1336 style, including the surrounding HTML tags. You can consider
1337 including definitions for the following classes: title, todo,
1338 done, timestamp, timestamp-kwd, tag, target.
1340 For example, a valid value would be:
1342 <style type=\"text/css\">
1344 p { font-weight: normal; color: gray; }
1345 h1 { color: black; }
1346 .title { text-align: center; }
1347 .todo, .timestamp-kwd { color: red; }
1348 .done { color: green; }
1352 If you want to refer to an external style, use something like
1354 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1356 As the value of this option simply gets inserted into the HTML
1357 <head> header, you can use it to add any arbitrary text to the
1360 You can set this on a per-file basis using #+HTML_HEAD:,
1361 or for publication projects using the :html-head property."
1362 :group
'org-export-html
1364 :package-version
'(Org .
"8.0")
1367 (put 'org-html-head
'safe-local-variable
'stringp
)
1369 (defcustom org-html-head-extra
""
1370 "More head information to add in the HTML output.
1372 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1373 or for publication projects using the :html-head-extra property."
1374 :group
'org-export-html
1376 :package-version
'(Org .
"8.0")
1379 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1383 (defcustom org-html-todo-kwd-class-prefix
""
1384 "Prefix to class names for TODO keywords.
1385 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1386 The default prefix is empty because it is nice to just use the keyword
1387 as a class name. But if you get into conflicts with other, existing
1388 CSS classes, then this prefix can be very useful."
1389 :group
'org-export-html
1393 ;;; Internal Functions
1395 (defun org-html-xhtml-p (info)
1396 (let ((dt (downcase (plist-get info
:html-doctype
))))
1397 (string-match-p "xhtml" dt
)))
1399 (defun org-html-html5-p (info)
1400 (let ((dt (downcase (plist-get info
:html-doctype
))))
1401 (member dt
'("html5" "xhtml5" "<!doctype html>"))))
1403 (defun org-html-close-tag (tag attr info
)
1404 (concat "<" tag
" " attr
1405 (if (org-html-xhtml-p info
) " />" ">")))
1407 (defun org-html-doctype (info)
1408 "Return correct html doctype tag from `org-html-doctype-alist',
1409 or the literal value of :html-doctype from INFO if :html-doctype
1410 is not found in the alist.
1411 INFO is a plist used as a communication channel."
1412 (let ((dt (plist-get info
:html-doctype
)))
1413 (or (cdr (assoc dt org-html-doctype-alist
)) dt
)))
1415 (defun org-html--make-attribute-string (attributes)
1416 "Return a list of attributes, as a string.
1417 ATTRIBUTES is a plist where values are either strings or nil. An
1418 attributes with a nil value will be omitted from the result."
1420 (dolist (item attributes
(mapconcat 'identity
(nreverse output
) " "))
1421 (cond ((null item
) (pop output
))
1422 ((symbolp item
) (push (substring (symbol-name item
) 1) output
))
1423 (t (let ((key (car output
))
1424 (value (replace-regexp-in-string
1425 "\"" """ (org-html-encode-plain-text item
))))
1426 (setcar output
(format "%s=\"%s\"" key value
))))))))
1428 (defun org-html--wrap-image (contents info
&optional caption label
)
1429 "Wrap CONTENTS string within an appropriate environment for images.
1430 INFO is a plist used as a communication channel. When optional
1431 arguments CAPTION and LABEL are given, use them for caption and
1433 (let ((html5-fancy (and (org-html-html5-p info
)
1434 (plist-get info
:html-html5-fancy
))))
1435 (format (if html5-fancy
"\n<figure%s>%s%s\n</figure>"
1436 "\n<div%s class=\"figure\">%s%s\n</div>")
1438 (if (not (org-string-nw-p label
)) ""
1439 (format " id=\"%s\"" (org-export-solidify-link-text label
)))
1441 (format "\n<p>%s</p>" contents
)
1443 (if (not (org-string-nw-p caption
)) ""
1444 (format (if html5-fancy
"\n<figcaption>%s</figcaption>"
1448 (defun org-html--format-image (source attributes info
)
1449 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1450 SOURCE is a string specifying the location of the image.
1451 ATTRIBUTES is a plist, as returned by
1452 `org-export-read-attribute'. INFO is a plist used as
1453 a communication channel."
1454 (if (string= "svg" (file-name-extension source
))
1455 (org-html--svg-image source attributes info
)
1458 (org-html--make-attribute-string
1461 :alt
(if (string-match-p "^ltxpng/" source
)
1462 (org-html-encode-plain-text
1463 (org-find-text-property-in-string 'org-latex-src source
))
1464 (file-name-nondirectory source
)))
1468 (defun org-html--svg-image (source attributes info
)
1469 "Return \"object\" appropriate for embedding svg file SOURCE
1470 with assoicated ATTRIBUTES. INFO is a plist used as a
1471 communication channel.
1473 The special attribute \"fallback\" can be used to specify a fallback
1474 image file to use if the object embedding is not supported."
1475 (let ((fallback (plist-get attributes
:fallback
))
1476 (attrs (org-html--make-attribute-string
1477 (plist-put attributes
:fallback nil
))))
1478 (format "<object type=\"image/svg+xml\" data=\"%s\" %s>\n%s</object>"
1482 "img" (format "src=\"%s\" %s" fallback attrs
) info
)
1483 "Sorry, your browser does not support SVG."))))
1485 (defun org-html--textarea-block (element)
1486 "Transcode ELEMENT into a textarea block.
1487 ELEMENT is either a src block or an example block."
1488 (let* ((code (car (org-export-unravel-code element
)))
1489 (attr (org-export-read-attribute :attr_html element
)))
1490 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1491 (or (plist-get attr
:width
) 80)
1492 (or (plist-get attr
:height
) (org-count-lines code
))
1495 (defun org-html--has-caption-p (element &optional info
)
1496 "Non-nil when ELEMENT has a caption affiliated keyword.
1497 INFO is a plist used as a communication channel. This function
1498 is meant to be used as a predicate for `org-export-get-ordinal' or
1499 a value to `org-html-standalone-image-predicate'."
1500 (org-element-property :caption element
))
1504 (defun org-html-htmlize-region-for-paste (beg end
)
1505 "Convert the region between BEG and END to HTML, using htmlize.el.
1506 This is much like `htmlize-region-for-paste', only that it uses
1507 the settings define in the org-... variables."
1508 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1509 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1510 (htmlbuf (htmlize-region beg end
)))
1512 (with-current-buffer htmlbuf
1513 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1514 (plist-get htmlize-buffer-places
'content-end
)))
1515 (kill-buffer htmlbuf
))))
1518 (defun org-html-htmlize-generate-css ()
1519 "Create the CSS for all font definitions in the current Emacs session.
1520 Use this to create face definitions in your CSS style file that can then
1521 be used by code snippets transformed by htmlize.
1522 This command just produces a buffer that contains class definitions for all
1523 faces used in the current Emacs session. You can copy and paste the ones you
1524 need into your CSS file.
1526 If you then set `org-html-htmlize-output-type' to `css', calls
1527 to the function `org-html-htmlize-region-for-paste' will
1528 produce code that uses these same face definitions."
1531 (and (get-buffer "*html*") (kill-buffer "*html*"))
1533 (let ((fl (face-list))
1534 (htmlize-css-name-prefix "org-")
1535 (htmlize-output-type 'css
)
1537 (while (setq f
(pop fl
)
1538 i
(and f
(face-attribute f
:inherit
)))
1539 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1540 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1541 (htmlize-region (point-min) (point-max))))
1542 (org-pop-to-buffer-same-window "*html*")
1543 (goto-char (point-min))
1544 (if (re-search-forward "<style" nil t
)
1545 (delete-region (point-min) (match-beginning 0)))
1546 (if (re-search-forward "</style>" nil t
)
1547 (delete-region (1+ (match-end 0)) (point-max)))
1548 (beginning-of-line 1)
1549 (if (looking-at " +") (replace-match ""))
1550 (goto-char (point-min)))
1552 (defun org-html--make-string (n string
)
1553 "Build a string by concatenating N times STRING."
1554 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1556 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1557 "Turn todo keyword KWD into a valid class name.
1558 Replaces invalid characters with \"_\"."
1560 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1561 (setq kwd
(replace-match "_" t t kwd
))))
1564 (defun org-html-format-footnote-reference (n def refcnt
)
1565 "Format footnote reference N with definition DEF into HTML."
1566 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1567 (format org-html-footnote-format
1568 (let* ((id (format "fnr.%s%s" n extra
))
1569 (href (format " href=\"#fn.%s\"" n
))
1570 (attributes (concat " class=\"footref\"" href
)))
1571 (org-html--anchor id n attributes
)))))
1573 (defun org-html-format-footnotes-section (section-name definitions
)
1574 "Format footnotes section SECTION-NAME."
1575 (if (not definitions
) ""
1576 (format org-html-footnotes-section section-name definitions
)))
1578 (defun org-html-format-footnote-definition (fn)
1579 "Format the footnote definition FN."
1580 (let ((n (car fn
)) (def (cdr fn
)))
1582 "<div class=\"footdef\">%s %s</div>\n"
1583 (format org-html-footnote-format
1584 (let* ((id (format "fn.%s" n
))
1585 (href (format " href=\"#fnr.%s\"" n
))
1586 (attributes (concat " class=\"footnum\"" href
)))
1587 (org-html--anchor id n attributes
)))
1590 (defun org-html-footnote-section (info)
1591 "Format the footnote section.
1592 INFO is a plist used as a communication channel."
1593 (let* ((fn-alist (org-export-collect-footnote-definitions
1594 (plist-get info
:parse-tree
) info
))
1596 (loop for
(n type raw
) in fn-alist collect
1597 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1598 (org-trim (org-export-data raw info
))
1600 (org-trim (org-export-data raw info
))))))))
1602 (org-html-format-footnotes-section
1603 (org-html--translate "Footnotes" info
)
1606 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1611 (defun org-html--build-meta-info (info)
1612 "Return meta tags for exported document.
1613 INFO is a plist used as a communication channel."
1614 (let ((protect-string
1616 (replace-regexp-in-string
1617 "\"" """ (org-html-encode-plain-text str
))))
1618 (title (org-export-data (plist-get info
:title
) info
))
1619 (author (and (plist-get info
:with-author
)
1620 (let ((auth (plist-get info
:author
)))
1622 ;; Return raw Org syntax, skipping non
1623 ;; exportable objects.
1624 (org-element-interpret-data
1625 (org-element-map auth
1626 (cons 'plain-text org-element-all-objects
)
1627 'identity info
))))))
1628 (description (plist-get info
:description
))
1629 (keywords (plist-get info
:keywords
))
1630 (charset (or (and org-html-coding-system
1631 (fboundp 'coding-system-get
)
1632 (coding-system-get org-html-coding-system
1636 (format "<title>%s</title>\n" title
)
1637 (when (plist-get info
:time-stamp-file
)
1639 (concat "<!-- " org-html-metadata-timestamp-format
" -->\n")))
1641 (if (org-html-html5-p info
)
1642 (org-html-close-tag "meta" " charset=\"%s\"" info
)
1644 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1647 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info
)
1649 (and (org-string-nw-p author
)
1651 (org-html-close-tag "meta"
1652 (format " name=\"author\" content=\"%s\""
1653 (funcall protect-string author
))
1656 (and (org-string-nw-p description
)
1658 (org-html-close-tag "meta"
1659 (format " name=\"description\" content=\"%s\"\n"
1660 (funcall protect-string description
))
1663 (and (org-string-nw-p keywords
)
1665 (org-html-close-tag "meta"
1666 (format " name=\"keywords\" content=\"%s\""
1667 (funcall protect-string keywords
))
1671 (defun org-html--build-head (info)
1672 "Return information for the <head>..</head> of the HTML output.
1673 INFO is a plist used as a communication channel."
1674 (org-element-normalize-string
1676 (when (plist-get info
:html-head-include-default-style
)
1677 (org-element-normalize-string org-html-style-default
))
1678 (org-element-normalize-string (plist-get info
:html-head
))
1679 (org-element-normalize-string (plist-get info
:html-head-extra
))
1680 (when (and (plist-get info
:html-htmlized-css-url
)
1681 (eq org-html-htmlize-output-type
'css
))
1682 (org-html-close-tag "link"
1683 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1684 (plist-get info
:html-htmlized-css-url
))
1686 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1688 (defun org-html--build-mathjax-config (info)
1689 "Insert the user setup into the mathjax template.
1690 INFO is a plist used as a communication channel."
1691 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1692 (org-element-map (plist-get info
:parse-tree
)
1693 '(latex-fragment latex-environment
) 'identity info t
))
1694 (let ((template org-html-mathjax-template
)
1695 (options org-html-mathjax-options
)
1696 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1697 name val
(yes " ") (no "// ") x
)
1700 (setq name
(car e
) val
(nth 1 e
))
1701 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1702 (setq val
(car (read-from-string
1703 (substring in-buffer
(match-end 0))))))
1704 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1705 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1706 (setq template
(replace-match val t t template
))))
1708 (setq val
(nth 1 (assq 'mathml options
)))
1709 (if (string-match (concat "\\<mathml:") in-buffer
)
1710 (setq val
(car (read-from-string
1711 (substring in-buffer
(match-end 0))))))
1712 ;; Exchange prefixes depending on mathml setting.
1713 (if (not val
) (setq x yes yes no no x
))
1714 ;; Replace cookies to turn on or off the config/jax lines.
1715 (if (string-match ":MMLYES:" template
)
1716 (setq template
(replace-match yes t t template
)))
1717 (if (string-match ":MMLNO:" template
)
1718 (setq template
(replace-match no t t template
)))
1719 ;; Return the modified template.
1720 (org-element-normalize-string template
))))
1722 (defun org-html-format-spec (info)
1723 "Return format specification for elements that can be
1724 used in the preamble or postamble."
1725 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1726 (?d .
,(org-export-data (org-export-get-date info
) info
))
1727 (?T .
,(format-time-string org-html-metadata-timestamp-format
))
1728 (?a .
,(org-export-data (plist-get info
:author
) info
))
1731 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1732 (split-string (plist-get info
:email
) ",+ *")
1734 (?c .
,(plist-get info
:creator
))
1735 (?C .
,(let ((file (plist-get info
:input-file
)))
1736 (format-time-string org-html-metadata-timestamp-format
1737 (if file
(nth 5 (file-attributes file
))
1739 (?v .
,(or org-html-validation-link
""))))
1741 (defun org-html--build-pre/postamble
(type info
)
1742 "Return document preamble or postamble as a string, or nil.
1743 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1744 communication channel."
1745 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1746 (spec (org-html-format-spec info
)))
1748 (let ((section-contents
1749 (if (functionp section
) (funcall section info
)
1751 ((stringp section
) (format-spec section spec
))
1753 (let ((date (cdr (assq ?d spec
)))
1754 (author (cdr (assq ?a spec
)))
1755 (email (cdr (assq ?e spec
)))
1756 (creator (cdr (assq ?c spec
)))
1757 (timestamp (cdr (assq ?T spec
)))
1758 (validation-link (cdr (assq ?v spec
))))
1760 (when (and (plist-get info
:with-date
)
1761 (org-string-nw-p date
))
1762 (format "<p class=\"date\">%s: %s</p>\n"
1763 (org-html--translate "Date" info
)
1765 (when (and (plist-get info
:with-author
)
1766 (org-string-nw-p author
))
1767 (format "<p class=\"author\">%s: %s</p>\n"
1768 (org-html--translate "Author" info
)
1770 (when (and (plist-get info
:with-email
)
1771 (org-string-nw-p email
))
1772 (format "<p class=\"email\">%s: %s</p>\n"
1773 (org-html--translate "Email" info
)
1775 (when (plist-get info
:time-stamp-file
)
1777 "<p class=\"date\">%s: %s</p>\n"
1778 (org-html--translate "Created" info
)
1779 (format-time-string org-html-metadata-timestamp-format
)))
1780 (when (plist-get info
:with-creator
)
1781 (format "<p class=\"creator\">%s</p>\n" creator
))
1782 (format "<p class=\"validation\">%s</p>\n"
1786 (plist-get info
:language
)
1788 (format "org-html-%s-format" type
)))))
1793 (intern (format "org-html-%s-format" type
))))))
1795 (when (org-string-nw-p section-contents
)
1797 (format "<%s id=\"%s\" class=\"%s\">\n"
1798 (nth 1 (assq type org-html-divs
))
1799 (nth 2 (assq type org-html-divs
))
1800 org-html--pre
/postamble-class
)
1801 (org-element-normalize-string section-contents
)
1802 (format "</%s>\n" (nth 1 (assq type org-html-divs
)))))))))
1804 (defun org-html-inner-template (contents info
)
1805 "Return body of document string after HTML conversion.
1806 CONTENTS is the transcoded contents string. INFO is a plist
1807 holding export options."
1809 ;; Table of contents.
1810 (let ((depth (plist-get info
:with-toc
)))
1811 (when depth
(org-html-toc depth info
)))
1812 ;; Document contents.
1814 ;; Footnotes section.
1815 (org-html-footnote-section info
)))
1817 (defun org-html-template (contents info
)
1818 "Return complete document string after HTML conversion.
1819 CONTENTS is the transcoded contents string. INFO is a plist
1820 holding export options."
1822 (when (and (not (org-html-html5-p info
)) (org-html-xhtml-p info
))
1823 (let ((decl (or (and (stringp org-html-xml-declaration
)
1824 org-html-xml-declaration
)
1825 (cdr (assoc (plist-get info
:html-extension
)
1826 org-html-xml-declaration
))
1827 (cdr (assoc "html" org-html-xml-declaration
))
1830 (when (not (or (eq nil decl
) (string= "" decl
)))
1833 (or (and org-html-coding-system
1834 (fboundp 'coding-system-get
)
1835 (coding-system-get org-html-coding-system
'mime-charset
))
1837 (org-html-doctype info
)
1840 (when (org-html-xhtml-p info
)
1842 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1843 (plist-get info
:language
) (plist-get info
:language
)))
1846 (org-html--build-meta-info info
)
1847 (org-html--build-head info
)
1848 (org-html--build-mathjax-config info
)
1851 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1852 (link-home (org-trim (plist-get info
:html-link-home
))))
1853 (unless (and (string= link-up
"") (string= link-home
""))
1854 (format org-html-home
/up-format
1855 (or link-up link-home
)
1856 (or link-home link-up
))))
1858 (org-html--build-pre/postamble
'preamble info
)
1859 ;; Document contents.
1860 (format "<%s id=\"%s\">\n"
1861 (nth 1 (assq 'content org-html-divs
))
1862 (nth 2 (assq 'content org-html-divs
)))
1864 (let ((title (plist-get info
:title
)))
1865 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1868 (nth 1 (assq 'content org-html-divs
)))
1870 (org-html--build-pre/postamble
'postamble info
)
1871 ;; Closing document.
1872 "</body>\n</html>"))
1874 (defun org-html--translate (s info
)
1875 "Translate string S according to specified language.
1876 INFO is a plist used as a communication channel."
1877 (org-export-translate s
:html info
))
1881 (defun org-html--anchor (&optional id desc attributes
)
1882 "Format a HTML anchor."
1883 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1884 (attributes (concat (and id
(format " id=\"%s\"" id
))
1885 (and name
(format " name=\"%s\"" name
))
1887 (format "<a%s>%s</a>" attributes
(or desc
""))))
1891 (defun org-html--todo (todo)
1892 "Format TODO keywords into HTML."
1894 (format "<span class=\"%s %s%s\">%s</span>"
1895 (if (member todo org-done-keywords
) "done" "todo")
1896 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1901 (defun org-html--tags (tags)
1902 "Format TAGS into HTML."
1904 (format "<span class=\"tag\">%s</span>"
1907 (format "<span class=\"%s\">%s</span>"
1908 (concat org-html-tag-class-prefix
1909 (org-html-fix-class-name tag
))
1915 (defun* org-html-format-headline
1916 (todo todo-type priority text tags
1917 &key level section-number headline-label
&allow-other-keys
)
1918 "Format a headline in HTML."
1919 (let ((section-number
1920 (when section-number
1921 (format "<span class=\"section-number-%d\">%s</span> "
1922 level section-number
)))
1923 (todo (org-html--todo todo
))
1924 (tags (org-html--tags tags
)))
1925 (concat section-number todo
(and todo
" ") text
1926 (and tags
"   ") tags
)))
1930 (defun org-html-fontify-code (code lang
)
1931 "Color CODE with htmlize library.
1932 CODE is a string representing the source code to colorize. LANG
1933 is the language used for CODE, as a string, or nil."
1936 ;; Case 1: No lang. Possibly an example block.
1938 ;; Simple transcoding.
1939 (org-html-encode-plain-text code
))
1940 ;; Case 2: No htmlize or an inferior version of htmlize
1941 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1943 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1944 ;; Simple transcoding.
1945 (org-html-encode-plain-text code
))
1946 ;; Case 3: plain text explicitly set
1947 ((not org-html-htmlize-output-type
)
1948 ;; Simple transcoding.
1949 (org-html-encode-plain-text code
))
1952 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1953 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1955 ;; Case 1: Language is not associated with any Emacs mode
1956 ((not (functionp lang-mode
))
1957 ;; Simple transcoding.
1958 (org-html-encode-plain-text code
))
1959 ;; Case 2: Default. Fontify code.
1962 (setq code
(with-temp-buffer
1963 ;; Switch to language-specific mode.
1968 ;; Remove formatting on newline characters.
1970 (let ((beg (point-min))
1973 (while (progn (end-of-line) (< (point) end
))
1974 (put-text-property (point) (1+ (point)) 'face nil
)
1977 (set-buffer-modified-p nil
)
1979 (org-html-htmlize-region-for-paste
1980 (point-min) (point-max))))
1981 ;; Strip any enclosing <pre></pre> tags.
1982 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1983 (end (and beg
(string-match "</pre>\\'" code
))))
1984 (if (and beg end
) (substring code beg end
) code
)))))))))
1986 (defun org-html-do-format-code
1987 (code &optional lang refs retain-labels num-start
)
1988 "Format CODE string as source code.
1989 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1990 respectively, the language of the source code, as a string, an
1991 alist between line numbers and references (as returned by
1992 `org-export-unravel-code'), a boolean specifying if labels should
1993 appear in the source code, and the number associated to the first
1995 (let* ((code-lines (org-split-string code
"\n"))
1996 (code-length (length code-lines
))
2000 (length (number-to-string (+ code-length num-start
))))))
2001 (code (org-html-fontify-code code lang
)))
2002 (org-export-format-code
2004 (lambda (loc line-num ref
)
2007 ;; Add line number, if needed.
2009 (format "<span class=\"linenr\">%s</span>"
2010 (format num-fmt line-num
)))
2011 ;; Transcoded src line.
2013 ;; Add label, if needed.
2014 (when (and ref retain-labels
) (format " (%s)" ref
))))
2015 ;; Mark transcoded line as an anchor, if needed.
2017 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
2021 (defun org-html-format-code (element info
)
2022 "Format contents of ELEMENT as source code.
2023 ELEMENT is either an example block or a src block. INFO is
2024 a plist used as a communication channel."
2025 (let* ((lang (org-element-property :language element
))
2026 ;; Extract code and references.
2027 (code-info (org-export-unravel-code element
))
2028 (code (car code-info
))
2029 (refs (cdr code-info
))
2030 ;; Does the src block contain labels?
2031 (retain-labels (org-element-property :retain-labels element
))
2032 ;; Does it have line numbers?
2033 (num-start (case (org-element-property :number-lines element
)
2034 (continued (org-export-get-loc element info
))
2036 (org-html-do-format-code code lang refs retain-labels num-start
)))
2039 ;;; Tables of Contents
2041 (defun org-html-toc (depth info
)
2042 "Build a table of contents.
2043 DEPTH is an integer specifying the depth of the table. INFO is a
2044 plist used as a communication channel. Return the table of
2045 contents as a string, or nil if it is empty."
2047 (mapcar (lambda (headline)
2048 (cons (org-html--format-toc-headline headline info
)
2049 (org-export-get-relative-level headline info
)))
2050 (org-export-collect-headlines info depth
)))
2051 (outer-tag (if (and (org-html-html5-p info
)
2052 (plist-get info
:html-html5-fancy
))
2056 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag
)
2057 (format "<h%d>%s</h%d>\n"
2058 org-html-toplevel-hlevel
2059 (org-html--translate "Table of Contents" info
)
2060 org-html-toplevel-hlevel
)
2061 "<div id=\"text-table-of-contents\">"
2062 (org-html--toc-text toc-entries
)
2064 (format "</%s>\n" outer-tag
)))))
2066 (defun org-html--toc-text (toc-entries)
2067 "Return innards of a table of contents, as a string.
2068 TOC-ENTRIES is an alist where key is an entry title, as a string,
2069 and value is its relative level, as an integer."
2070 (let* ((prev-level (1- (cdar toc-entries
)))
2071 (start-level prev-level
))
2075 (let ((headline (car entry
))
2076 (level (cdr entry
)))
2078 (let* ((cnt (- level prev-level
))
2079 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
2081 (setq prev-level level
)
2083 (org-html--make-string
2084 times
(cond ((> cnt
0) "\n<ul>\n<li>")
2085 ((< cnt
0) "</li>\n</ul>\n")))
2086 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
2089 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
2091 (defun org-html--format-toc-headline (headline info
)
2092 "Return an appropriate table of contents entry for HEADLINE.
2093 INFO is a plist used as a communication channel."
2094 (let* ((headline-number (org-export-get-headline-number headline info
))
2095 (todo (and (plist-get info
:with-todo-keywords
)
2096 (let ((todo (org-element-property :todo-keyword headline
)))
2097 (and todo
(org-export-data todo info
)))))
2098 (todo-type (and todo
(org-element-property :todo-type headline
)))
2099 (priority (and (plist-get info
:with-priority
)
2100 (org-element-property :priority headline
)))
2101 (text (org-export-data-with-backend
2102 (org-export-get-alt-title headline info
)
2103 ;; Create an anonymous back-end that will ignore any
2104 ;; footnote-reference, link, radio-target and target
2105 ;; in table of contents.
2106 (org-export-create-backend
2108 :transcoders
'((footnote-reference . ignore
)
2109 (link .
(lambda (object c i
) c
))
2110 (radio-target .
(lambda (object c i
) c
))
2113 (tags (and (eq (plist-get info
:with-tags
) t
)
2114 (org-export-get-tags headline info
))))
2115 (format "<a href=\"#%s\">%s</a>"
2117 (org-export-solidify-link-text
2118 (or (org-element-property :CUSTOM_ID headline
)
2120 (mapconcat #'number-to-string headline-number
"-"))))
2123 (and (not (org-export-low-level-p headline info
))
2124 (org-export-numbered-headline-p headline info
)
2125 (concat (mapconcat #'number-to-string headline-number
".")
2127 (apply (if (not (eq org-html-format-headline-function
'ignore
))
2128 (lambda (todo todo-type priority text tags
&rest ignore
)
2129 (funcall org-html-format-headline-function
2130 todo todo-type priority text tags
))
2131 #'org-html-format-headline
)
2132 todo todo-type priority text tags
:section-number nil
)))))
2134 (defun org-html-list-of-listings (info)
2135 "Build a list of listings.
2136 INFO is a plist used as a communication channel. Return the list
2137 of listings as a string, or nil if it is empty."
2138 (let ((lol-entries (org-export-collect-listings info
)))
2140 (concat "<div id=\"list-of-listings\">\n"
2141 (format "<h%d>%s</h%d>\n"
2142 org-html-toplevel-hlevel
2143 (org-html--translate "List of Listings" info
)
2144 org-html-toplevel-hlevel
)
2145 "<div id=\"text-list-of-listings\">\n<ul>\n"
2147 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2148 (org-html--translate "Listing %d:" info
))))
2151 (let ((label (org-element-property :name entry
))
2154 (or (org-export-get-caption entry t
)
2155 (org-export-get-caption entry
))
2160 (concat (format initial-fmt
(incf count
)) " " title
)
2161 (format "<a href=\"#%s\">%s %s</a>"
2162 (org-export-solidify-link-text label
)
2163 (format initial-fmt
(incf count
))
2167 "\n</ul>\n</div>\n</div>"))))
2169 (defun org-html-list-of-tables (info)
2170 "Build a list of tables.
2171 INFO is a plist used as a communication channel. Return the list
2172 of tables as a string, or nil if it is empty."
2173 (let ((lol-entries (org-export-collect-tables info
)))
2175 (concat "<div id=\"list-of-tables\">\n"
2176 (format "<h%d>%s</h%d>\n"
2177 org-html-toplevel-hlevel
2178 (org-html--translate "List of Tables" info
)
2179 org-html-toplevel-hlevel
)
2180 "<div id=\"text-list-of-tables\">\n<ul>\n"
2182 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2183 (org-html--translate "Table %d:" info
))))
2186 (let ((label (org-element-property :name entry
))
2189 (or (org-export-get-caption entry t
)
2190 (org-export-get-caption entry
))
2195 (concat (format initial-fmt
(incf count
)) " " title
)
2196 (format "<a href=\"#%s\">%s %s</a>"
2197 (org-export-solidify-link-text label
)
2198 (format initial-fmt
(incf count
))
2202 "\n</ul>\n</div>\n</div>"))))
2205 ;;; Transcode Functions
2209 (defun org-html-bold (bold contents info
)
2210 "Transcode BOLD from Org to HTML.
2211 CONTENTS is the text with bold markup. INFO is a plist holding
2212 contextual information."
2213 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
2218 (defun org-html-center-block (center-block contents info
)
2219 "Transcode a CENTER-BLOCK element from Org to HTML.
2220 CONTENTS holds the contents of the block. INFO is a plist
2221 holding contextual information."
2222 (format "<div class=\"center\">\n%s</div>" contents
))
2226 (defun org-html-clock (clock contents info
)
2227 "Transcode a CLOCK element from Org to HTML.
2228 CONTENTS is nil. INFO is a plist used as a communication
2231 <span class=\"timestamp-wrapper\">
2232 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2237 (org-element-property :raw-value
2238 (org-element-property :value clock
)))
2239 (let ((time (org-element-property :duration clock
)))
2240 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
2244 (defun org-html-code (code contents info
)
2245 "Transcode CODE from Org to HTML.
2246 CONTENTS is nil. INFO is a plist holding contextual
2248 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
2249 (org-html-encode-plain-text (org-element-property :value code
))))
2253 (defun org-html-drawer (drawer contents info
)
2254 "Transcode a DRAWER element from Org to HTML.
2255 CONTENTS holds the contents of the block. INFO is a plist
2256 holding contextual information."
2257 (if (functionp org-html-format-drawer-function
)
2258 (funcall org-html-format-drawer-function
2259 (org-element-property :drawer-name drawer
)
2261 ;; If there's no user defined function: simply
2262 ;; display contents of the drawer.
2267 (defun org-html-dynamic-block (dynamic-block contents info
)
2268 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2269 CONTENTS holds the contents of the block. INFO is a plist
2270 holding contextual information. See `org-export-data'."
2275 (defun org-html-entity (entity contents info
)
2276 "Transcode an ENTITY object from Org to HTML.
2277 CONTENTS are the definition itself. INFO is a plist holding
2278 contextual information."
2279 (org-element-property :html entity
))
2283 (defun org-html-example-block (example-block contents info
)
2284 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2285 CONTENTS is nil. INFO is a plist holding contextual
2287 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2288 (org-html--textarea-block example-block
)
2289 (format "<pre class=\"example\">\n%s</pre>"
2290 (org-html-format-code example-block info
))))
2294 (defun org-html-export-snippet (export-snippet contents info
)
2295 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2296 CONTENTS is nil. INFO is a plist holding contextual
2298 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2299 (org-element-property :value export-snippet
)))
2303 (defun org-html-export-block (export-block contents info
)
2304 "Transcode a EXPORT-BLOCK element from Org to HTML.
2305 CONTENTS is nil. INFO is a plist holding contextual information."
2306 (when (string= (org-element-property :type export-block
) "HTML")
2307 (org-remove-indentation (org-element-property :value export-block
))))
2311 (defun org-html-fixed-width (fixed-width contents info
)
2312 "Transcode a FIXED-WIDTH element from Org to HTML.
2313 CONTENTS is nil. INFO is a plist holding contextual information."
2314 (format "<pre class=\"example\">\n%s</pre>"
2315 (org-html-do-format-code
2316 (org-remove-indentation
2317 (org-element-property :value fixed-width
)))))
2319 ;;;; Footnote Reference
2321 (defun org-html-footnote-reference (footnote-reference contents info
)
2322 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2323 CONTENTS is nil. INFO is a plist holding contextual information."
2325 ;; Insert separator between two footnotes in a row.
2326 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2327 (when (eq (org-element-type prev
) 'footnote-reference
)
2328 org-html-footnote-separator
))
2330 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2331 (org-html-format-footnote-reference
2332 (org-export-get-footnote-number footnote-reference info
)
2334 ;; Inline definitions are secondary strings.
2335 ((eq (org-element-property :type footnote-reference
) 'inline
)
2336 (org-html-format-footnote-reference
2337 (org-export-get-footnote-number footnote-reference info
)
2339 ;; Non-inline footnotes definitions are full Org data.
2340 (t (org-html-format-footnote-reference
2341 (org-export-get-footnote-number footnote-reference info
)
2346 (defun org-html-format-headline--wrap
2347 (headline info
&optional format-function
&rest extra-keys
)
2348 "Transcode a HEADLINE element from Org to HTML.
2349 CONTENTS holds the contents of the headline. INFO is a plist
2350 holding contextual information."
2351 (let* ((level (+ (org-export-get-relative-level headline info
)
2352 (1- org-html-toplevel-hlevel
)))
2353 (headline-number (org-export-get-headline-number headline info
))
2354 (section-number (and (not (org-export-low-level-p headline info
))
2355 (org-export-numbered-headline-p headline info
)
2356 (mapconcat 'number-to-string
2357 headline-number
".")))
2358 (todo (and (plist-get info
:with-todo-keywords
)
2359 (let ((todo (org-element-property :todo-keyword headline
)))
2360 (and todo
(org-export-data todo info
)))))
2361 (todo-type (and todo
(org-element-property :todo-type headline
)))
2362 (priority (and (plist-get info
:with-priority
)
2363 (org-element-property :priority headline
)))
2364 (text (org-export-data (org-element-property :title headline
) info
))
2365 (tags (and (plist-get info
:with-tags
)
2366 (org-export-get-tags headline info
)))
2367 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2368 (concat "sec-" (mapconcat 'number-to-string
2369 headline-number
"-"))))
2371 (cond ((functionp format-function
) format-function
)
2372 ((not (eq org-html-format-headline-function
'ignore
))
2373 (lambda (todo todo-type priority text tags
&rest ignore
)
2374 (funcall org-html-format-headline-function
2375 todo todo-type priority text tags
)))
2376 (t 'org-html-format-headline
))))
2377 (apply format-function
2378 todo todo-type priority text tags
2379 :headline-label headline-label
:level level
2380 :section-number section-number extra-keys
)))
2382 (defun org-html-headline (headline contents info
)
2383 "Transcode a HEADLINE element from Org to HTML.
2384 CONTENTS holds the contents of the headline. INFO is a plist
2385 holding contextual information."
2387 (setq contents
(or contents
""))
2388 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2389 (level (org-export-get-relative-level headline info
))
2390 (text (org-export-data (org-element-property :title headline
) info
))
2391 (todo (and (plist-get info
:with-todo-keywords
)
2392 (let ((todo (org-element-property :todo-keyword headline
)))
2393 (and todo
(org-export-data todo info
)))))
2394 (todo-type (and todo
(org-element-property :todo-type headline
)))
2395 (tags (and (plist-get info
:with-tags
)
2396 (org-export-get-tags headline info
)))
2397 (priority (and (plist-get info
:with-priority
)
2398 (org-element-property :priority headline
)))
2399 (section-number (and (org-export-numbered-headline-p headline info
)
2400 (mapconcat 'number-to-string
2401 (org-export-get-headline-number
2402 headline info
) ".")))
2403 ;; Create the headline text.
2404 (full-text (org-html-format-headline--wrap headline info
)))
2406 ;; Case 1: This is a footnote section: ignore it.
2407 ((org-element-property :footnote-section-p headline
) nil
)
2408 ;; Case 2. This is a deep sub-tree: export it as a list item.
2409 ;; Also export as items headlines for which no section
2410 ;; format has been found.
2411 ((org-export-low-level-p headline info
)
2412 ;; Build the real contents of the sub-tree.
2413 (let* ((type (if numberedp
'ordered
'unordered
))
2414 (itemized-body (org-html-format-list-item
2415 contents type nil info nil full-text
)))
2417 (and (org-export-first-sibling-p headline info
)
2418 (org-html-begin-plain-list type
))
2420 (and (org-export-last-sibling-p headline info
)
2421 (org-html-end-plain-list type
)))))
2422 ;; Case 3. Standard headline. Export it as a section.
2424 (let* ((section-number (mapconcat 'number-to-string
2425 (org-export-get-headline-number
2426 headline info
) "-"))
2428 (list (org-element-property :CUSTOM_ID headline
)
2429 (concat "sec-" section-number
)
2430 (org-element-property :ID headline
))))
2431 (preferred-id (car ids
))
2432 (extra-ids (cdr ids
))
2433 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2434 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2435 (first-content (car (org-element-contents headline
))))
2436 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2437 (org-html--container headline info
)
2438 (format "outline-container-%s"
2439 (or (org-element-property :CUSTOM_ID headline
)
2440 (concat "sec-" section-number
)))
2441 (concat (format "outline-%d" level1
) (and extra-class
" ")
2443 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2448 (let ((id (org-export-solidify-link-text
2449 (if (org-uuidgen-p x
) (concat "ID-" x
)
2451 (org-html--anchor id
)))
2455 ;; When there is no section, pretend there is an empty
2456 ;; one to get the correct <div class="outline- ...>
2457 ;; which is needed by `org-info.js'.
2458 (if (not (eq (org-element-type first-content
) 'section
))
2459 (concat (org-html-section first-content
"" info
)
2462 (org-html--container headline info
)))))))
2464 (defun org-html--container (headline info
)
2465 (or (org-element-property :HTML_CONTAINER headline
)
2466 (if (= 1 (org-export-get-relative-level headline info
))
2467 (plist-get info
:html-container
)
2470 ;;;; Horizontal Rule
2472 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2473 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2474 CONTENTS is nil. INFO is a plist holding contextual information."
2475 (org-html-close-tag "hr" nil info
))
2477 ;;;; Inline Src Block
2479 (defun org-html-inline-src-block (inline-src-block contents info
)
2480 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2481 CONTENTS holds the contents of the item. INFO is a plist holding
2482 contextual information."
2483 (let* ((org-lang (org-element-property :language inline-src-block
))
2484 (code (org-element-property :value inline-src-block
)))
2485 (error "Cannot export inline src block")))
2489 (defun org-html-format-section (text class
&optional id
)
2490 "Format a section with TEXT into a HTML div with CLASS and ID."
2491 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2492 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2494 (defun org-html-inlinetask (inlinetask contents info
)
2495 "Transcode an INLINETASK element from Org to HTML.
2496 CONTENTS holds the contents of the block. INFO is a plist
2497 holding contextual information."
2499 ;; If `org-html-format-inlinetask-function' is not 'ignore, call it
2500 ;; with appropriate arguments.
2501 ((not (eq org-html-format-inlinetask-function
'ignore
))
2502 (let ((format-function
2504 (lambda (todo todo-type priority text tags
2505 &key contents
&allow-other-keys
)
2506 (funcall org-html-format-inlinetask-function
2507 todo todo-type priority text tags contents
)))))
2508 (org-html-format-headline--wrap
2509 inlinetask info format-function
:contents contents
)))
2510 ;; Otherwise, use a default template.
2511 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2512 (org-html-format-headline--wrap inlinetask info
)
2513 (org-html-close-tag "br" nil info
)
2518 (defun org-html-italic (italic contents info
)
2519 "Transcode ITALIC from Org to HTML.
2520 CONTENTS is the text with italic markup. INFO is a plist holding
2521 contextual information."
2522 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2526 (defun org-html-checkbox (checkbox info
)
2527 "Format CHECKBOX into HTML.
2528 INFO is a plist holding contextual information. See
2529 `org-html-checkbox-type' for customization options."
2531 (cdr (assq org-html-checkbox-type org-html-checkbox-types
)))))
2533 (defun org-html-format-list-item (contents type checkbox info
2534 &optional term-counter-id
2536 "Format a list item into HTML."
2537 (let ((class (if checkbox
2538 (format " class=\"%s\""
2539 (symbol-name checkbox
)) ""))
2540 (checkbox (concat (org-html-checkbox checkbox info
)
2541 (and checkbox
" ")))
2542 (br (org-html-close-tag "br" nil info
)))
2546 (let* ((counter term-counter-id
)
2547 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2549 (format "<li%s%s>" class extra
)
2550 (when headline
(concat headline br
)))))
2552 (let* ((id term-counter-id
)
2553 (extra (if id
(format " id=\"%s\"" id
) "")))
2555 (format "<li%s%s>" class extra
)
2556 (when headline
(concat headline br
)))))
2558 (let* ((term term-counter-id
))
2559 (setq term
(or term
"(no term)"))
2560 ;; Check-boxes in descriptive lists are associated to tag.
2561 (concat (format "<dt%s>%s</dt>"
2562 class
(concat checkbox term
))
2564 (unless (eq type
'descriptive
) checkbox
)
2569 (descriptive "</dd>")))))
2571 (defun org-html-item (item contents info
)
2572 "Transcode an ITEM element from Org to HTML.
2573 CONTENTS holds the contents of the item. INFO is a plist holding
2574 contextual information."
2575 (let* ((plain-list (org-export-get-parent item
))
2576 (type (org-element-property :type plain-list
))
2577 (counter (org-element-property :counter item
))
2578 (checkbox (org-element-property :checkbox item
))
2579 (tag (let ((tag (org-element-property :tag item
)))
2580 (and tag
(org-export-data tag info
)))))
2581 (org-html-format-list-item
2582 contents type checkbox info
(or tag counter
))))
2586 (defun org-html-keyword (keyword contents info
)
2587 "Transcode a KEYWORD element from Org to HTML.
2588 CONTENTS is nil. INFO is a plist holding contextual information."
2589 (let ((key (org-element-property :key keyword
))
2590 (value (org-element-property :value keyword
)))
2592 ((string= key
"HTML") value
)
2593 ((string= key
"TOC")
2594 (let ((value (downcase value
)))
2596 ((string-match "\\<headlines\\>" value
)
2597 (let ((depth (or (and (string-match "[0-9]+" value
)
2598 (string-to-number (match-string 0 value
)))
2599 (plist-get info
:with-toc
))))
2600 (org-html-toc depth info
)))
2601 ((string= "listings" value
) (org-html-list-of-listings info
))
2602 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2604 ;;;; Latex Environment
2606 (defun org-html-format-latex (latex-frag processing-type info
)
2607 "Format a LaTeX fragment LATEX-FRAG into HTML.
2608 PROCESSING-TYPE designates the tool used for conversion. It is
2609 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2610 and t. See `org-html-with-latex' for more information. INFO is
2611 a plist containing export properties."
2612 (let ((cache-relpath "") (cache-dir ""))
2613 (unless (eq processing-type
'mathjax
)
2614 (let ((bfn (or (buffer-file-name)
2616 (expand-file-name "latex" temporary-file-directory
))))
2618 (let ((header (plist-get info
:latex-header
)))
2621 (lambda (line) (concat "#+LATEX_HEADER: " line
))
2622 (org-split-string header
"\n")
2627 (file-name-sans-extension
2628 (file-name-nondirectory bfn
)))
2629 cache-dir
(file-name-directory bfn
))
2630 ;; Re-create LaTeX environment from original buffer in
2631 ;; temporary buffer so that dvipng/imagemagick can properly
2632 ;; turn the fragment into an image.
2633 (setq latex-frag
(concat latex-header latex-frag
))))
2636 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2637 nil nil processing-type
)
2640 (defun org-html-latex-environment (latex-environment contents info
)
2641 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2642 CONTENTS is nil. INFO is a plist holding contextual information."
2643 (let ((processing-type (plist-get info
:with-latex
))
2644 (latex-frag (org-remove-indentation
2645 (org-element-property :value latex-environment
)))
2646 (attributes (org-export-read-attribute :attr_html latex-environment
)))
2647 (case processing-type
2649 (org-html-format-latex latex-frag
'mathjax info
))
2650 ((dvipng imagemagick
)
2652 (org-html-format-latex latex-frag processing-type info
)))
2653 (when (and formula-link
(string-match "file:\\([^]]*\\)" formula-link
))
2654 ;; Do not provide a caption or a name to be consistent with
2655 ;; `mathjax' handling.
2656 (org-html--wrap-image
2657 (org-html--format-image
2658 (match-string 1 formula-link
) attributes info
) info
))))
2663 (defun org-html-latex-fragment (latex-fragment contents info
)
2664 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2665 CONTENTS is nil. INFO is a plist holding contextual information."
2666 (let ((latex-frag (org-element-property :value latex-fragment
))
2667 (processing-type (plist-get info
:with-latex
)))
2668 (case processing-type
2670 (org-html-format-latex latex-frag
'mathjax info
))
2671 ((dvipng imagemagick
)
2673 (org-html-format-latex latex-frag processing-type info
)))
2674 (when (and formula-link
(string-match "file:\\([^]]*\\)" formula-link
))
2675 (org-html--format-image (match-string 1 formula-link
) nil info
))))
2680 (defun org-html-line-break (line-break contents info
)
2681 "Transcode a LINE-BREAK object from Org to HTML.
2682 CONTENTS is nil. INFO is a plist holding contextual information."
2683 (concat (org-html-close-tag "br" nil info
) "\n"))
2687 (defun org-html-inline-image-p (link info
)
2688 "Non-nil when LINK is meant to appear as an image.
2689 INFO is a plist used as a communication channel. LINK is an
2690 inline image when it has no description and targets an image
2691 file (see `org-html-inline-image-rules' for more information), or
2692 if its description is a single link targeting an image file."
2693 (if (not (org-element-contents link
))
2694 (org-export-inline-image-p link org-html-inline-image-rules
)
2696 (let ((link-count 0))
2697 (org-element-map (org-element-contents link
)
2698 (cons 'plain-text org-element-all-objects
)
2700 (case (org-element-type obj
)
2701 (plain-text (org-string-nw-p obj
))
2702 (link (if (= link-count
1) t
2704 (not (org-export-inline-image-p
2705 obj org-html-inline-image-rules
))))
2709 (defvar org-html-standalone-image-predicate
)
2710 (defun org-html-standalone-image-p (element info
)
2711 "Non-nil if ELEMENT is a standalone image.
2713 INFO is a plist holding contextual information.
2715 An element or object is a standalone image when
2717 - its type is `paragraph' and its sole content, save for white
2718 spaces, is a link that qualifies as an inline image;
2720 - its type is `link' and its containing paragraph has no other
2721 content save white spaces.
2723 Bind `org-html-standalone-image-predicate' to constrain paragraph
2724 further. For example, to check for only captioned standalone
2727 \(lambda (paragraph) (org-element-property :caption paragraph))"
2728 (let ((paragraph (case (org-element-type element
)
2730 (link (org-export-get-parent element
)))))
2731 (and (eq (org-element-type paragraph
) 'paragraph
)
2732 (or (not (fboundp 'org-html-standalone-image-predicate
))
2733 (funcall org-html-standalone-image-predicate paragraph
))
2735 (let ((link-count 0))
2736 (org-element-map (org-element-contents paragraph
)
2737 (cons 'plain-text org-element-all-objects
)
2739 (when (case (org-element-type obj
)
2740 (plain-text (org-string-nw-p obj
))
2741 (link (or (> (incf link-count
) 1)
2742 (not (org-html-inline-image-p obj info
))))
2746 (= link-count
1))))))
2748 (defun org-html-link (link desc info
)
2749 "Transcode a LINK object from Org to HTML.
2751 DESC is the description part of the link, or the empty string.
2752 INFO is a plist holding contextual information. See
2754 (let* ((home (when (plist-get info
:html-link-home
)
2755 (org-trim (plist-get info
:html-link-home
))))
2756 (use-abs-url (plist-get info
:html-link-use-abs-url
))
2757 (link-org-files-as-html-maybe
2759 (lambda (raw-path info
)
2760 "Treat links to `file.org' as links to `file.html', if needed.
2761 See `org-html-link-org-files-as-html'."
2763 ((and org-html-link-org-files-as-html
2765 (downcase (file-name-extension raw-path
"."))))
2766 (concat (file-name-sans-extension raw-path
) "."
2767 (plist-get info
:html-extension
)))
2769 (type (org-element-property :type link
))
2770 (raw-path (org-element-property :path link
))
2771 ;; Ensure DESC really exists, or set it to nil.
2772 (desc (org-string-nw-p desc
))
2775 ((member type
'("http" "https" "ftp" "mailto"))
2776 (org-link-escape-browser
2777 (org-link-unescape (concat type
":" raw-path
))))
2778 ((string= type
"file")
2779 ;; Treat links to ".org" files as ".html", if needed.
2781 (funcall link-org-files-as-html-maybe raw-path info
))
2782 ;; If file path is absolute, prepend it with protocol
2783 ;; component - "file:".
2785 ((file-name-absolute-p raw-path
)
2786 (setq raw-path
(concat "file:" raw-path
)))
2787 ((and home use-abs-url
)
2788 (setq raw-path
(concat (file-name-as-directory home
) raw-path
))))
2789 ;; Add search option, if any. A search option can be
2790 ;; relative to a custom-id or a headline title. Append
2791 ;; a hash sign to any unresolved option, as it might point
2793 (let ((option (org-element-property :search-option link
)))
2794 (cond ((not option
) raw-path
)
2795 ((eq (aref option
0) ?
#) (concat raw-path option
))
2798 (org-publish-resolve-external-fuzzy-link
2799 (org-element-property :path link
) option
)))
2801 (if (not destination
) (concat "#" option
)
2803 (mapconcat #'number-to-string
2804 destination
"-")))))))))
2806 ;; Extract attributes from parent's paragraph. HACK: Only do
2807 ;; this for the first link in parent (inner image link for
2808 ;; inline images). This is needed as long as attributes
2809 ;; cannot be set on a per link basis.
2811 (let* ((parent (org-export-get-parent-element link
))
2812 (link (let ((container (org-export-get-parent link
)))
2813 (if (and (eq (org-element-type container
) 'link
)
2814 (org-html-inline-image-p link info
))
2817 (and (eq (org-element-map parent
'link
'identity info t
) link
)
2818 (org-export-read-attribute :attr_html parent
))))
2820 (let ((attr (org-html--make-attribute-string attributes-plist
)))
2821 (if (org-string-nw-p attr
) (concat " " attr
) "")))
2825 ((and org-html-inline-images
2826 (org-export-inline-image-p link org-html-inline-image-rules
))
2827 (org-html--format-image path attributes-plist info
))
2828 ;; Radio target: Transcode target's contents and use them as
2829 ;; link's description.
2830 ((string= type
"radio")
2831 (let ((destination (org-export-resolve-radio-link link info
)))
2833 (format "<a href=\"#%s\"%s>%s</a>"
2834 (org-export-solidify-link-text
2835 (org-element-property :value destination
))
2837 ;; Links pointing to a headline: Find destination and build
2838 ;; appropriate referencing command.
2839 ((member type
'("custom-id" "fuzzy" "id"))
2840 (let ((destination (if (string= type
"fuzzy")
2841 (org-export-resolve-fuzzy-link link info
)
2842 (org-export-resolve-id-link link info
))))
2843 (case (org-element-type destination
)
2844 ;; ID link points to an external file.
2846 (let ((fragment (concat "ID-" path
))
2847 ;; Treat links to ".org" files as ".html", if needed.
2848 (path (funcall link-org-files-as-html-maybe
2850 (format "<a href=\"%s#%s\"%s>%s</a>"
2851 path fragment attributes
(or desc destination
))))
2852 ;; Fuzzy link points nowhere.
2857 (org-element-property :raw-link link
) info
))))
2858 ;; Link points to a headline.
2861 ;; What href to use?
2863 ;; Case 1: Headline is linked via it's CUSTOM_ID
2864 ;; property. Use CUSTOM_ID.
2865 ((string= type
"custom-id")
2866 (org-element-property :CUSTOM_ID destination
))
2867 ;; Case 2: Headline is linked via it's ID property
2868 ;; or through other means. Use the default href.
2869 ((member type
'("id" "fuzzy"))
2871 (mapconcat 'number-to-string
2872 (org-export-get-headline-number
2873 destination info
) "-")))
2874 (t (error "Shouldn't reach here"))))
2875 ;; What description to use?
2877 ;; Case 1: Headline is numbered and LINK has no
2878 ;; description. Display section number.
2879 (if (and (org-export-numbered-headline-p destination info
)
2881 (mapconcat 'number-to-string
2882 (org-export-get-headline-number
2883 destination info
) ".")
2884 ;; Case 2: Either the headline is un-numbered or
2885 ;; LINK has a custom description. Display LINK's
2886 ;; description or headline's title.
2887 (or desc
(org-export-data (org-element-property
2888 :title destination
) info
)))))
2889 (format "<a href=\"#%s\"%s>%s</a>"
2890 (org-export-solidify-link-text href
) attributes desc
)))
2891 ;; Fuzzy link points to a target or an element.
2893 (let* ((path (org-export-solidify-link-text path
))
2894 (org-html-standalone-image-predicate 'org-html--has-caption-p
)
2897 ((org-html-standalone-image-p destination info
)
2898 (org-export-get-ordinal
2899 (org-element-map destination
'link
2901 info
'link
'org-html-standalone-image-p
))
2902 (t (org-export-get-ordinal
2903 destination info nil
'org-html--has-caption-p
))))
2905 ((not number
) "No description for this link")
2906 ((numberp number
) (number-to-string number
))
2907 (t (mapconcat 'number-to-string number
".")))))
2908 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc
))))))
2909 ;; Coderef: replace link with the reference name or the
2910 ;; equivalent line number.
2911 ((string= type
"coderef")
2912 (let ((fragment (concat "coderef-" path
)))
2913 (format "<a href=\"#%s\"%s%s>%s</a>"
2916 (format (concat "class=\"coderef\""
2917 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2918 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2921 (format (org-export-get-coderef-format path desc
)
2922 (org-export-resolve-coderef path info
)))))
2923 ;; Link type is handled by a special function.
2924 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2925 (funcall protocol
(org-link-unescape path
) desc
'html
))
2926 ;; External link with a description part.
2927 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2928 ;; External link without a description part.
2929 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2930 ;; No path, only description. Try to do something useful.
2931 (t (format "<i>%s</i>" desc
)))))
2935 (defun org-html-node-property (node-property contents info
)
2936 "Transcode a NODE-PROPERTY element from Org to HTML.
2937 CONTENTS is nil. INFO is a plist holding contextual
2940 (org-element-property :key node-property
)
2941 (let ((value (org-element-property :value node-property
)))
2942 (if value
(concat " " value
) ""))))
2946 (defun org-html-paragraph (paragraph contents info
)
2947 "Transcode a PARAGRAPH element from Org to HTML.
2948 CONTENTS is the contents of the paragraph, as a string. INFO is
2949 the plist used as a communication channel."
2950 (let* ((parent (org-export-get-parent paragraph
))
2951 (parent-type (org-element-type parent
))
2952 (style '((footnote-definition " class=\"footpara\"")))
2953 (attributes (org-html--make-attribute-string
2954 (org-export-read-attribute :attr_html paragraph
)))
2955 (extra (or (cadr (assoc parent-type style
)) "")))
2957 ((and (eq (org-element-type parent
) 'item
)
2958 (= (org-element-property :begin paragraph
)
2959 (org-element-property :contents-begin parent
)))
2960 ;; Leading paragraph in a list item have no tags.
2962 ((org-html-standalone-image-p paragraph info
)
2963 ;; Standalone image.
2965 (let ((raw (org-export-data
2966 (org-export-get-caption paragraph
) info
))
2967 (org-html-standalone-image-predicate
2968 'org-html--has-caption-p
))
2969 (if (not (org-string-nw-p raw
)) raw
2971 "<span class=\"figure-number\">"
2972 (format (org-html--translate "Figure %d:" info
)
2973 (org-export-get-ordinal
2974 (org-element-map paragraph
'link
2976 info nil
'org-html-standalone-image-p
))
2978 (label (org-element-property :name paragraph
)))
2979 (org-html--wrap-image contents info caption label
)))
2980 ;; Regular paragraph.
2981 (t (format "<p%s%s>\n%s</p>"
2982 (if (org-string-nw-p attributes
)
2983 (concat " " attributes
) "")
2988 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2989 ;; the correct value for the item counter
2990 (defun org-html-begin-plain-list (type &optional arg1
)
2991 "Insert the beginning of the HTML list depending on TYPE.
2992 When ARG1 is a string, use it as the start parameter for ordered
2996 (format "<ol class=\"org-ol\"%s>"
2997 (if arg1
(format " start=\"%d\"" arg1
) "")))
2998 (unordered "<ul class=\"org-ul\">")
2999 (descriptive "<dl class=\"org-dl\">")))
3001 (defun org-html-end-plain-list (type)
3002 "Insert the end of the HTML list depending on TYPE."
3006 (descriptive "</dl>")))
3008 (defun org-html-plain-list (plain-list contents info
)
3009 "Transcode a PLAIN-LIST element from Org to HTML.
3010 CONTENTS is the contents of the list. INFO is a plist holding
3011 contextual information."
3012 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
3013 (type (org-element-property :type plain-list
)))
3015 (org-html-begin-plain-list type
)
3016 contents
(org-html-end-plain-list type
))))
3020 (defun org-html-convert-special-strings (string)
3021 "Convert special characters in STRING to HTML."
3022 (let ((all org-html-special-string-regexps
)
3024 (while (setq a
(pop all
))
3025 (setq re
(car a
) rpl
(cdr a
) start
0)
3026 (while (string-match re string start
)
3027 (setq string
(replace-match rpl t nil string
))))
3030 (defun org-html-encode-plain-text (text)
3031 "Convert plain text characters from TEXT to HTML equivalent.
3032 Possible conversions are set in `org-html-protect-char-alist'."
3035 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
3036 org-html-protect-char-alist
)
3039 (defun org-html-plain-text (text info
)
3040 "Transcode a TEXT string from Org to HTML.
3041 TEXT is the string to transcode. INFO is a plist holding
3042 contextual information."
3043 (let ((output text
))
3044 ;; Protect following characters: <, >, &.
3045 (setq output
(org-html-encode-plain-text output
))
3046 ;; Handle smart quotes. Be sure to provide original string since
3047 ;; OUTPUT may have been modified.
3048 (when (plist-get info
:with-smart-quotes
)
3049 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
3050 ;; Handle special strings.
3051 (when (plist-get info
:with-special-strings
)
3052 (setq output
(org-html-convert-special-strings output
)))
3053 ;; Handle break preservation if required.
3054 (when (plist-get info
:preserve-breaks
)
3056 (replace-regexp-in-string
3057 "\\(\\\\\\\\\\)?[ \t]*\n"
3058 (concat (org-html-close-tag "br" nil info
) "\n") output
)))
3065 (defun org-html-planning (planning contents info
)
3066 "Transcode a PLANNING element from Org to HTML.
3067 CONTENTS is nil. INFO is a plist used as a communication
3069 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
3071 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
3076 (let ((closed (org-element-property :closed planning
)))
3078 (format span-fmt org-closed-string
3080 (org-element-property :raw-value closed
)))))
3081 (let ((deadline (org-element-property :deadline planning
)))
3083 (format span-fmt org-deadline-string
3085 (org-element-property :raw-value deadline
)))))
3086 (let ((scheduled (org-element-property :scheduled planning
)))
3088 (format span-fmt org-scheduled-string
3090 (org-element-property :raw-value scheduled
)))))))
3093 ;;;; Property Drawer
3095 (defun org-html-property-drawer (property-drawer contents info
)
3096 "Transcode a PROPERTY-DRAWER element from Org to HTML.
3097 CONTENTS holds the contents of the drawer. INFO is a plist
3098 holding contextual information."
3099 (and (org-string-nw-p contents
)
3100 (format "<pre class=\"example\">\n%s</pre>" contents
)))
3104 (defun org-html-quote-block (quote-block contents info
)
3105 "Transcode a QUOTE-BLOCK element from Org to HTML.
3106 CONTENTS holds the contents of the block. INFO is a plist
3107 holding contextual information."
3108 (format "<blockquote>\n%s</blockquote>" contents
))
3112 (defun org-html-section (section contents info
)
3113 "Transcode a SECTION element from Org to HTML.
3114 CONTENTS holds the contents of the section. INFO is a plist
3115 holding contextual information."
3116 (let ((parent (org-export-get-parent-headline section
)))
3117 ;; Before first headline: no container, just return CONTENTS.
3118 (if (not parent
) contents
3119 ;; Get div's class and id references.
3120 (let* ((class-num (+ (org-export-get-relative-level parent info
)
3121 (1- org-html-toplevel-hlevel
)))
3125 (org-export-get-headline-number parent info
) "-")))
3126 ;; Build return value.
3127 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3129 (or (org-element-property :CUSTOM_ID parent
) section-number
)
3134 (defun org-html-radio-target (radio-target text info
)
3135 "Transcode a RADIO-TARGET object from Org to HTML.
3136 TEXT is the text of the target. INFO is a plist holding
3137 contextual information."
3138 (let ((id (org-export-solidify-link-text
3139 (org-element-property :value radio-target
))))
3140 (org-html--anchor id text
)))
3144 (defun org-html-special-block (special-block contents info
)
3145 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3146 CONTENTS holds the contents of the block. INFO is a plist
3147 holding contextual information."
3148 (let* ((block-type (downcase
3149 (org-element-property :type special-block
)))
3150 (contents (or contents
""))
3151 (html5-fancy (and (org-html-html5-p info
)
3152 (plist-get info
:html-html5-fancy
)
3153 (member block-type org-html-html5-elements
)))
3154 (attributes (org-export-read-attribute :attr_html special-block
)))
3156 (let ((class (plist-get attributes
:class
)))
3157 (setq attributes
(plist-put attributes
:class
3158 (if class
(concat class
" " block-type
)
3160 (setq attributes
(org-html--make-attribute-string attributes
))
3161 (when (not (equal attributes
""))
3162 (setq attributes
(concat " " attributes
)))
3164 (format "<%s%s>\n%s</%s>" block-type attributes
3165 contents block-type
)
3166 (format "<div%s>\n%s\n</div>" attributes contents
))))
3170 (defun org-html-src-block (src-block contents info
)
3171 "Transcode a SRC-BLOCK element from Org to HTML.
3172 CONTENTS holds the contents of the item. INFO is a plist holding
3173 contextual information."
3174 (if (org-export-read-attribute :attr_html src-block
:textarea
)
3175 (org-html--textarea-block src-block
)
3176 (let ((lang (org-element-property :language src-block
))
3177 (caption (org-export-get-caption src-block
))
3178 (code (org-html-format-code src-block info
))
3179 (label (let ((lbl (org-element-property :name src-block
)))
3181 (format " id=\"%s\""
3182 (org-export-solidify-link-text lbl
))))))
3183 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
3185 "<div class=\"org-src-container\">\n%s%s\n</div>"
3186 (if (not caption
) ""
3187 (format "<label class=\"org-src-name\">%s</label>"
3188 (org-export-data caption info
)))
3189 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
3191 ;;;; Statistics Cookie
3193 (defun org-html-statistics-cookie (statistics-cookie contents info
)
3194 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3195 CONTENTS is nil. INFO is a plist holding contextual information."
3196 (let ((cookie-value (org-element-property :value statistics-cookie
)))
3197 (format "<code>%s</code>" cookie-value
)))
3201 (defun org-html-strike-through (strike-through contents info
)
3202 "Transcode STRIKE-THROUGH from Org to HTML.
3203 CONTENTS is the text with strike-through markup. INFO is a plist
3204 holding contextual information."
3205 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
3210 (defun org-html-subscript (subscript contents info
)
3211 "Transcode a SUBSCRIPT object from Org to HTML.
3212 CONTENTS is the contents of the object. INFO is a plist holding
3213 contextual information."
3214 (format "<sub>%s</sub>" contents
))
3218 (defun org-html-superscript (superscript contents info
)
3219 "Transcode a SUPERSCRIPT object from Org to HTML.
3220 CONTENTS is the contents of the object. INFO is a plist holding
3221 contextual information."
3222 (format "<sup>%s</sup>" contents
))
3226 (defun org-html-table-cell (table-cell contents info
)
3227 "Transcode a TABLE-CELL element from Org to HTML.
3228 CONTENTS is nil. INFO is a plist used as a communication
3230 (let* ((table-row (org-export-get-parent table-cell
))
3231 (table (org-export-get-parent-table table-cell
))
3233 (if (not org-html-table-align-individual-fields
) ""
3234 (format (if (and (boundp 'org-html-format-table-no-css
)
3235 org-html-format-table-no-css
)
3236 " align=\"%s\"" " class=\"%s\"")
3237 (org-export-table-cell-alignment table-cell info
)))))
3238 (when (or (not contents
) (string= "" (org-trim contents
)))
3239 (setq contents
" "))
3241 ((and (org-export-table-has-header-p table info
)
3242 (= 1 (org-export-table-row-group table-row info
)))
3243 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
3244 contents
(cdr org-html-table-header-tags
)))
3245 ((and org-html-table-use-header-tags-for-first-column
3246 (zerop (cdr (org-export-table-cell-address table-cell info
))))
3247 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
3248 contents
(cdr org-html-table-header-tags
)))
3249 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
3250 contents
(cdr org-html-table-data-tags
))))))
3254 (defun org-html-table-row (table-row contents info
)
3255 "Transcode a TABLE-ROW element from Org to HTML.
3256 CONTENTS is the contents of the row. INFO is a plist used as a
3257 communication channel."
3258 ;; Rules are ignored since table separators are deduced from
3259 ;; borders of the current row.
3260 (when (eq (org-element-property :type table-row
) 'standard
)
3261 (let* ((rowgroup-number (org-export-table-row-group table-row info
))
3262 (row-number (org-export-table-row-number table-row info
))
3264 (org-export-table-row-starts-rowgroup-p table-row info
))
3266 (org-export-table-row-ends-rowgroup-p table-row info
))
3267 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3268 ;; but should be set so that `org-html-table-row-tags' can
3269 ;; use them (see the docstring of this variable.)
3270 (top-row-p (and (equal start-rowgroup-p
'(top))
3271 (equal end-rowgroup-p
'(below top
))))
3272 (bottom-row-p (and (equal start-rowgroup-p
'(above))
3273 (equal end-rowgroup-p
'(bottom above
))))
3276 ;; Case 1: Row belongs to second or subsequent rowgroups.
3277 ((not (= 1 rowgroup-number
))
3278 '("<tbody>" .
"\n</tbody>"))
3279 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3280 ((org-export-table-has-header-p
3281 (org-export-get-parent-table table-row
) info
)
3282 '("<thead>" .
"\n</thead>"))
3283 ;; Case 2: Row is from first and only row group.
3284 (t '("<tbody>" .
"\n</tbody>")))))
3286 ;; Begin a rowgroup?
3287 (when start-rowgroup-p
(car rowgroup-tags
))
3289 (concat "\n" (eval (car org-html-table-row-tags
))
3292 (eval (cdr org-html-table-row-tags
)))
3294 (when end-rowgroup-p
(cdr rowgroup-tags
))))))
3298 (defun org-html-table-first-row-data-cells (table info
)
3299 "Transcode the first row of TABLE.
3300 INFO is a plist used as a communication channel."
3302 (org-element-map table
'table-row
3304 (unless (eq (org-element-property :type row
) 'rule
) row
))
3306 (special-column-p (org-export-table-has-special-column-p table
)))
3307 (if (not special-column-p
) (org-element-contents table-row
)
3308 (cdr (org-element-contents table-row
)))))
3310 (defun org-html-table--table.el-table
(table info
)
3311 "Format table.el tables into HTML.
3312 INFO is a plist used as a communication channel."
3313 (when (eq (org-element-property :type table
) 'table.el
)
3315 (let ((outbuf (with-current-buffer
3316 (get-buffer-create "*org-export-table*")
3317 (erase-buffer) (current-buffer))))
3319 (insert (org-element-property :value table
))
3321 (re-search-forward "^[ \t]*|[^|]" nil t
)
3322 (table-generate-source 'html outbuf
))
3323 (with-current-buffer outbuf
3324 (prog1 (org-trim (buffer-string))
3327 (defun org-html-table (table contents info
)
3328 "Transcode a TABLE element from Org to HTML.
3329 CONTENTS is the contents of the table. INFO is a plist holding
3330 contextual information."
3331 (case (org-element-property :type table
)
3332 ;; Case 1: table.el table. Convert it using appropriate tools.
3333 (table.el
(org-html-table--table.el-table table info
))
3334 ;; Case 2: Standard table.
3336 (let* ((label (org-element-property :name table
))
3337 (caption (org-export-get-caption table
))
3338 (number (org-export-get-ordinal
3339 table info nil
'org-html--has-caption-p
))
3341 (org-html--make-attribute-string
3343 (and label
(list :id
(org-export-solidify-link-text label
)))
3344 (and (not (org-html-html5-p info
))
3345 (plist-get info
:html-table-attributes
))
3346 (org-export-read-attribute :attr_html table
))))
3348 (if (and (boundp 'org-html-format-table-no-css
)
3349 org-html-format-table-no-css
)
3350 "align=\"%s\"" "class=\"%s\""))
3353 (lambda (table info
)
3355 (lambda (table-cell)
3356 (let ((alignment (org-export-table-cell-alignment
3359 ;; Begin a colgroup?
3360 (when (org-export-table-cell-starts-colgroup-p
3363 ;; Add a column. Also specify it's alignment.
3366 "col" (concat " " (format alignspec alignment
)) info
))
3368 (when (org-export-table-cell-ends-colgroup-p
3371 (org-html-table-first-row-data-cells table info
) "\n")))))
3372 (format "<table%s>\n%s\n%s\n%s</table>"
3373 (if (equal attributes
"") "" (concat " " attributes
))
3374 (if (not caption
) ""
3375 (format (if org-html-table-caption-above
3376 "<caption class=\"t-above\">%s</caption>"
3377 "<caption class=\"t-bottom\">%s</caption>")
3379 "<span class=\"table-number\">"
3380 (format (org-html--translate "Table %d:" info
) number
)
3381 "</span> " (org-export-data caption info
))))
3382 (funcall table-column-specs table info
)
3387 (defun org-html-target (target contents info
)
3388 "Transcode a TARGET object from Org to HTML.
3389 CONTENTS is nil. INFO is a plist holding contextual
3391 (let ((id (org-export-solidify-link-text
3392 (org-element-property :value target
))))
3393 (org-html--anchor id
)))
3397 (defun org-html-timestamp (timestamp contents info
)
3398 "Transcode a TIMESTAMP object from Org to HTML.
3399 CONTENTS is nil. INFO is a plist holding contextual
3401 (let ((value (org-html-plain-text
3402 (org-timestamp-translate timestamp
) info
)))
3403 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3404 (replace-regexp-in-string "--" "–" value
))))
3408 (defun org-html-underline (underline contents info
)
3409 "Transcode UNDERLINE from Org to HTML.
3410 CONTENTS is the text with underline markup. INFO is a plist
3411 holding contextual information."
3412 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3417 (defun org-html-verbatim (verbatim contents info
)
3418 "Transcode VERBATIM from Org to HTML.
3419 CONTENTS is nil. INFO is a plist holding contextual
3421 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3422 (org-html-encode-plain-text (org-element-property :value verbatim
))))
3426 (defun org-html-verse-block (verse-block contents info
)
3427 "Transcode a VERSE-BLOCK element from Org to HTML.
3428 CONTENTS is verse block contents. INFO is a plist holding
3429 contextual information."
3430 ;; Replace each newline character with line break. Also replace
3431 ;; each blank line with a line break.
3432 (setq contents
(replace-regexp-in-string
3433 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info
))
3434 (replace-regexp-in-string
3435 "\\(\\\\\\\\\\)?[ \t]*\n"
3436 (format "%s\n" (org-html-close-tag "br" nil info
)) contents
)))
3437 ;; Replace each white space at beginning of a line with a
3438 ;; non-breaking space.
3439 (while (string-match "^[ \t]+" contents
)
3440 (let* ((num-ws (length (match-string 0 contents
)))
3441 (ws (let (out) (dotimes (i num-ws out
)
3442 (setq out
(concat out
" "))))))
3443 (setq contents
(replace-match ws nil t contents
))))
3444 (format "<p class=\"verse\">\n%s</p>" contents
))
3447 ;;; Filter Functions
3449 (defun org-html-final-function (contents backend info
)
3450 "Filter to indent the HTML and convert HTML entities."
3455 (indent-region (point-min) (point-max)))
3456 (when org-html-use-unicode-chars
3458 (mm-url-decode-entities))
3459 (buffer-substring-no-properties (point-min) (point-max))))
3462 ;;; End-user functions
3465 (defun org-html-export-as-html
3466 (&optional async subtreep visible-only body-only ext-plist
)
3467 "Export current buffer to an HTML buffer.
3469 If narrowing is active in the current buffer, only export its
3472 If a region is active, export that region.
3474 A non-nil optional argument ASYNC means the process should happen
3475 asynchronously. The resulting buffer should be accessible
3476 through the `org-export-stack' interface.
3478 When optional argument SUBTREEP is non-nil, export the sub-tree
3479 at point, extracting information from the headline properties
3482 When optional argument VISIBLE-ONLY is non-nil, don't export
3483 contents of hidden elements.
3485 When optional argument BODY-ONLY is non-nil, only write code
3486 between \"<body>\" and \"</body>\" tags.
3488 EXT-PLIST, when provided, is a property list with external
3489 parameters overriding Org default settings, but still inferior to
3490 file-local settings.
3492 Export is done in a buffer named \"*Org HTML Export*\", which
3493 will be displayed when `org-export-show-temporary-export-buffer'
3496 (org-export-to-buffer 'html
"*Org HTML Export*"
3497 async subtreep visible-only body-only ext-plist
3498 (lambda () (set-auto-mode t
))))
3501 (defun org-html-convert-region-to-html ()
3502 "Assume the current region has org-mode syntax, and convert it to HTML.
3503 This can be used in any buffer. For example, you can write an
3504 itemized list in org-mode syntax in an HTML buffer and use this
3505 command to convert it."
3507 (org-export-replace-region-by 'html
))
3510 (defun org-html-export-to-html
3511 (&optional async subtreep visible-only body-only ext-plist
)
3512 "Export current buffer to a HTML file.
3514 If narrowing is active in the current buffer, only export its
3517 If a region is active, export that region.
3519 A non-nil optional argument ASYNC means the process should happen
3520 asynchronously. The resulting file should be accessible through
3521 the `org-export-stack' interface.
3523 When optional argument SUBTREEP is non-nil, export the sub-tree
3524 at point, extracting information from the headline properties
3527 When optional argument VISIBLE-ONLY is non-nil, don't export
3528 contents of hidden elements.
3530 When optional argument BODY-ONLY is non-nil, only write code
3531 between \"<body>\" and \"</body>\" tags.
3533 EXT-PLIST, when provided, is a property list with external
3534 parameters overriding Org default settings, but still inferior to
3535 file-local settings.
3537 Return output file's name."
3539 (let* ((extension (concat "." org-html-extension
))
3540 (file (org-export-output-file-name extension subtreep
))
3541 (org-export-coding-system org-html-coding-system
))
3542 (org-export-to-file 'html file
3543 async subtreep visible-only body-only ext-plist
)))
3546 (defun org-html-publish-to-html (plist filename pub-dir
)
3547 "Publish an org file to HTML.
3549 FILENAME is the filename of the Org file to be published. PLIST
3550 is the property list for the given project. PUB-DIR is the
3551 publishing directory.
3553 Return output file name."
3554 (org-publish-org-to 'html filename
3555 (concat "." (or (plist-get plist
:html-extension
)
3556 org-html-extension
"html"))
3563 ;; generated-autoload-file: "org-loaddefs.el"
3566 ;;; ox-html.el ends here