1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; M-x org-export-as-html
29 ;; in an Org mode buffer. See ox.el for more details on how this
38 (require 'format-spec
)
39 (eval-when-compile (require 'cl
) (require 'table
))
42 ;;; Function Declarations
44 (declare-function org-id-find-id-file
"org-id" (id))
45 (declare-function htmlize-region
"ext:htmlize" (beg end
))
46 (declare-function org-pop-to-buffer-same-window
47 "org-compat" (&optional buffer-or-name norecord label
))
48 (declare-function mm-url-decode-entities
"mm-url" ())
52 (org-export-define-backend 'html
53 '((bold . org-html-bold
)
54 (center-block . org-html-center-block
)
55 (clock . org-html-clock
)
56 (code . org-html-code
)
57 (drawer . org-html-drawer
)
58 (dynamic-block . org-html-dynamic-block
)
59 (entity . org-html-entity
)
60 (example-block . org-html-example-block
)
61 (export-block . org-html-export-block
)
62 (export-snippet . org-html-export-snippet
)
63 (fixed-width . org-html-fixed-width
)
64 (footnote-definition . org-html-footnote-definition
)
65 (footnote-reference . org-html-footnote-reference
)
66 (headline . org-html-headline
)
67 (horizontal-rule . org-html-horizontal-rule
)
68 (inline-src-block . org-html-inline-src-block
)
69 (inlinetask . org-html-inlinetask
)
70 (inner-template . org-html-inner-template
)
71 (italic . org-html-italic
)
72 (item . org-html-item
)
73 (keyword . org-html-keyword
)
74 (latex-environment . org-html-latex-environment
)
75 (latex-fragment . org-html-latex-fragment
)
76 (line-break . org-html-line-break
)
77 (link . org-html-link
)
78 (paragraph . org-html-paragraph
)
79 (plain-list . org-html-plain-list
)
80 (plain-text . org-html-plain-text
)
81 (planning . org-html-planning
)
82 (property-drawer . org-html-property-drawer
)
83 (quote-block . org-html-quote-block
)
84 (quote-section . org-html-quote-section
)
85 (radio-target . org-html-radio-target
)
86 (section . org-html-section
)
87 (special-block . org-html-special-block
)
88 (src-block . org-html-src-block
)
89 (statistics-cookie . org-html-statistics-cookie
)
90 (strike-through . org-html-strike-through
)
91 (subscript . org-html-subscript
)
92 (superscript . org-html-superscript
)
93 (table . org-html-table
)
94 (table-cell . org-html-table-cell
)
95 (table-row . org-html-table-row
)
96 (target . org-html-target
)
97 (template . org-html-template
)
98 (timestamp . org-html-timestamp
)
99 (underline . org-html-underline
)
100 (verbatim . org-html-verbatim
)
101 (verse-block . org-html-verse-block
))
103 :filters-alist
'((:filter-options . org-html-infojs-install-script
)
104 (:filter-final-output . org-html-final-function
))
106 '(?h
"Export to HTML"
107 ((?H
"As HTML buffer" org-html-export-as-html
)
108 (?h
"As HTML file" org-html-export-to-html
)
109 (?o
"As HTML file and open"
111 (if a
(org-html-export-to-html t s v b
)
112 (org-open-file (org-html-export-to-html nil s v b
)))))))
114 '((:html-extension nil nil org-html-extension
)
115 (:html-doctype
"HTML_DOCTYPE" nil org-html-doctype
)
116 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
117 (:html-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
118 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
119 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
120 (:html-postamble nil
"html-postamble" org-html-postamble
)
121 (:html-preamble nil
"html-preamble" org-html-preamble
)
122 (:html-head
"HTML_HEAD" nil org-html-head newline
)
123 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
124 (:html-head-include-default-style
"HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline
)
125 (:html-head-include-scripts
"HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline
)
126 (:html-table-tag nil nil org-html-table-tag
)
127 ;; Redefine regular options.
128 (:creator
"CREATOR" nil org-html-creator-string
)
129 (:with-latex nil
"tex" org-html-with-latex
)
130 ;; Leave room for "ox-infojs.el" extension.
131 (:infojs-opt
"INFOJS_OPT" nil nil
)))
134 ;;; Internal Variables
136 (defvar org-html-format-table-no-css
)
137 (defvar htmlize-buffer-places
) ; from htmlize.el
139 (defvar org-html--timestamp-format
"%Y-%m-%d %a %H:%M"
140 "FORMAT used by `format-time-string' for timestamps in
141 preamble, postamble and metadata.")
143 (defvar org-html--pre
/postamble-class
"status"
144 "CSS class used for pre/postamble")
146 (defconst org-html-special-string-regexps
147 '(("\\\\-" .
"­") ; shy
148 ("---\\([^-]\\)" .
"—\\1") ; mdash
149 ("--\\([^-]\\)" .
"–\\1") ; ndash
150 ("\\.\\.\\." .
"…")) ; hellip
151 "Regular expressions for special string conversion.")
153 (defconst org-html-scripts
154 "<script type=\"text/javascript\">
156 @licstart The following is the entire license notice for the
157 JavaScript code in this tag.
159 Copyright (C) 2012 Free Software Foundation, Inc.
161 The JavaScript code in this tag is free software: you can
162 redistribute it and/or modify it under the terms of the GNU
163 General Public License (GNU GPL) as published by the Free Software
164 Foundation, either version 3 of the License, or (at your option)
165 any later version. The code is distributed WITHOUT ANY WARRANTY;
166 without even the implied warranty of MERCHANTABILITY or FITNESS
167 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
169 As additional permission under GNU GPL version 3 section 7, you
170 may distribute non-source (e.g., minimized or compacted) forms of
171 that code without the copy of the GNU GPL normally required by
172 section 4, provided you include this license notice and a URL
173 through which recipients can access the Corresponding Source.
176 @licend The above is the entire license notice
177 for the JavaScript code in this tag.
179 <!--/*--><![CDATA[/*><!--*/
180 function CodeHighlightOn(elem, id)
182 var target = document.getElementById(id);
184 elem.cacheClassElem = elem.className;
185 elem.cacheClassTarget = target.className;
186 target.className = \"code-highlighted\";
187 elem.className = \"code-highlighted\";
190 function CodeHighlightOff(elem, id)
192 var target = document.getElementById(id);
193 if(elem.cacheClassElem)
194 elem.className = elem.cacheClassElem;
195 if(elem.cacheClassTarget)
196 target.className = elem.cacheClassTarget;
200 "Basic JavaScript that is needed by HTML files produced by Org mode.")
202 (defconst org-html-style-default
203 "<style type=\"text/css\">
204 <!--/*--><![CDATA[/*><!--*/
205 .title { text-align: center; }
206 .todo { font-family: monospace; color: red; }
207 .done { color: green; }
208 .tag { background-color: #eee; font-family: monospace;
209 padding: 2px; font-size: 80%; font-weight: normal; }
210 .timestamp { color: #bebebe; }
211 .timestamp-kwd { color: #5f9ea0; }
212 .right { margin-left: auto; margin-right: 0px; text-align: right; }
213 .left { margin-left: 0px; margin-right: auto; text-align: left; }
214 .center { margin-left: auto; margin-right: auto; text-align: center; }
215 .underline { text-decoration: underline; }
216 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
217 p.verse { margin-left: 3%; }
219 border: 1px solid #ccc;
220 box-shadow: 3px 3px 3px #eee;
222 font-family: monospace;
234 background-color: white;
238 border: 1px solid black;
240 pre.src:hover:before { display: inline;}
241 pre.src-sh:before { content: 'sh'; }
242 pre.src-bash:before { content: 'sh'; }
243 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
244 pre.src-R:before { content: 'R'; }
245 pre.src-perl:before { content: 'Perl'; }
246 pre.src-java:before { content: 'Java'; }
247 pre.src-sql:before { content: 'SQL'; }
249 table { border-collapse:collapse; }
250 td, th { vertical-align:top; }
251 th.right { text-align: center; }
252 th.left { text-align: center; }
253 th.center { text-align: center; }
254 td.right { text-align: right; }
255 td.left { text-align: left; }
256 td.center { text-align: center; }
257 dt { font-weight: bold; }
258 .footpara:nth-child(2) { display: inline; }
259 .footpara { display: block; }
260 .footdef { margin-bottom: 1em; }
261 .figure { padding: 1em; }
262 .figure p { text-align: center; }
265 border: 2px solid gray;
270 { text-align: right; font-size: 70%; white-space: nowrap; }
271 textarea { overflow-x: auto; }
272 .linenr { font-size: smaller }
273 .code-highlighted { background-color: #ffff00; }
274 .org-info-js_info-navigation { border-style: none; }
275 #org-info-js_console-label
276 { font-size: 10px; font-weight: bold; white-space: nowrap; }
277 .org-info-js_search-highlight
278 { background-color: #ffff00; color: #000000; font-weight: bold; }
281 "The default style specification for exported HTML files.
282 You can use `org-html-head' and `org-html-head-extra' to add to
283 this style. If you don't want to include this default style,
284 customize `org-html-head-include-default-style'.")
287 ;;; User Configuration Variables
289 (defgroup org-export-html nil
290 "Options for exporting Org mode files to HTML."
291 :tag
"Org Export HTML"
296 (defvar org-html-infojs-opts-table
297 '((path PATH
"http://orgmode.org/org-info.js")
301 (tdepth TOC_DEPTH
"max")
302 (sdepth SECTION_DEPTH
"max")
303 (mouse MOUSE_HINT
"underline")
304 (buttons VIEW_BUTTONS
"0")
306 (up LINK_UP
:html-link-up
)
307 (home LINK_HOME
:html-link-home
))
308 "JavaScript options, long form for script, default values.")
310 (defcustom org-html-use-infojs
'when-configured
311 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
312 This option can be nil or t to never or always use the script.
313 It can also be the symbol `when-configured', meaning that the
314 script will be linked into the export file if and only if there
315 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
316 `org-html-infojs-options'."
317 :group
'org-export-html
319 :package-version
'(Org .
"8.0")
321 (const :tag
"Never" nil
)
322 (const :tag
"When configured in buffer" when-configured
)
323 (const :tag
"Always" t
)))
325 (defcustom org-html-infojs-options
326 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
327 "Options settings for the INFOJS JavaScript.
328 Each of the options must have an entry in `org-html-infojs-opts-table'.
329 The value can either be a string that will be passed to the script, or
330 a property. This property is then assumed to be a property that is defined
331 by the Export/Publishing setup of Org.
332 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
333 means to use the maximum value consistent with other options."
334 :group
'org-export-html
336 :package-version
'(Org .
"8.0")
338 `(set :greedy t
:inline t
341 (list 'cons
(list 'const
(car x
))
343 (symbol :tag
"Publishing/Export property")
344 (string :tag
"Value"))))
345 org-html-infojs-opts-table
)))
347 (defcustom org-html-infojs-template
348 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
351 * @source: %SCRIPT_PATH
353 * @licstart The following is the entire license notice for the
354 * JavaScript code in %SCRIPT_PATH.
356 * Copyright (C) 2012-2013 Sebastian Rose
359 * The JavaScript code in this tag is free software: you can
360 * redistribute it and/or modify it under the terms of the GNU
361 * General Public License (GNU GPL) as published by the Free Software
362 * Foundation, either version 3 of the License, or (at your option)
363 * any later version. The code is distributed WITHOUT ANY WARRANTY;
364 * without even the implied warranty of MERCHANTABILITY or FITNESS
365 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
367 * As additional permission under GNU GPL version 3 section 7, you
368 * may distribute non-source (e.g., minimized or compacted) forms of
369 * that code without the copy of the GNU GPL normally required by
370 * section 4, provided you include this license notice and a URL
371 * through which recipients can access the Corresponding Source.
373 * @licend The above is the entire license notice
374 * for the JavaScript code in %SCRIPT_PATH.
379 <script type=\"text/javascript\">
382 @licstart The following is the entire license notice for the
383 JavaScript code in this tag.
385 Copyright (C) 2012-2013 Free Software Foundation, Inc.
387 The JavaScript code in this tag is free software: you can
388 redistribute it and/or modify it under the terms of the GNU
389 General Public License (GNU GPL) as published by the Free Software
390 Foundation, either version 3 of the License, or (at your option)
391 any later version. The code is distributed WITHOUT ANY WARRANTY;
392 without even the implied warranty of MERCHANTABILITY or FITNESS
393 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
395 As additional permission under GNU GPL version 3 section 7, you
396 may distribute non-source (e.g., minimized or compacted) forms of
397 that code without the copy of the GNU GPL normally required by
398 section 4, provided you include this license notice and a URL
399 through which recipients can access the Corresponding Source.
402 @licend The above is the entire license notice
403 for the JavaScript code in this tag.
406 <!--/*--><![CDATA[/*><!--*/
408 org_html_manager.setup(); // activate after the parameters are set
411 "The template for the export style additions when org-info.js is used.
412 Option settings will replace the %MANAGER-OPTIONS cookie."
413 :group
'org-export-html
415 :package-version
'(Org .
"8.0")
418 (defun org-html-infojs-install-script (exp-plist backend
)
419 "Install script in export options when appropriate.
420 EXP-PLIST is a plist containing export options. BACKEND is the
421 export back-end currently used."
422 (unless (or (memq 'body-only
(plist-get exp-plist
:export-options
))
423 (not org-html-use-infojs
)
424 (and (eq org-html-use-infojs
'when-configured
)
425 (or (not (plist-get exp-plist
:infojs-opt
))
426 (string-match "\\<view:nil\\>"
427 (plist-get exp-plist
:infojs-opt
)))))
428 (let* ((template org-html-infojs-template
)
429 (ptoc (plist-get exp-plist
:with-toc
))
430 (hlevels (plist-get exp-plist
:headline-levels
))
432 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
433 (options (plist-get exp-plist
:infojs-opt
))
434 (table org-html-infojs-opts-table
)
436 (dolist (entry table
)
437 (let* ((opt (car entry
))
439 ;; Compute default values for script option OPT from
440 ;; `org-html-infojs-options' variable.
442 (let ((default (cdr (assq opt org-html-infojs-options
))))
443 (if (and (symbolp default
) (not (memq default
'(t nil
))))
444 (plist-get exp-plist default
)
446 ;; Value set through INFOJS_OPT keyword has precedence
447 ;; over the default one.
448 (val (if (and options
449 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
451 (match-string 1 options
)
455 (replace-regexp-in-string
456 "%SCRIPT_PATH" val template t t
)))
457 (sdepth (when (integerp (read val
))
458 (setq sdepth
(min (read val
) sdepth
))))
459 (tdepth (when (integerp (read val
))
460 (setq tdepth
(min (read val
) tdepth
))))
463 ((or (eq val t
) (equal val
"t")) "1")
464 ((or (eq val nil
) (equal val
"nil")) "0")
466 (t (format "%s" val
))))
467 (push (cons var val
) style
)))))
468 ;; Now we set the depth of the *generated* TOC to SDEPTH,
469 ;; because the toc will actually determine the splitting. How
470 ;; much of the toc will actually be displayed is governed by the
472 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
473 ;; The table of contents should not show more sections than we
475 (setq tdepth
(min tdepth sdepth
))
476 (push (cons "TOC_DEPTH" tdepth
) style
)
477 ;; Build style string.
478 (setq style
(mapconcat
479 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
483 (when (and style
(> (length style
) 0))
484 (and (string-match "%MANAGER_OPTIONS" template
)
485 (setq style
(replace-match style t t template
))
488 exp-plist
:html-head-extra
489 (concat (or (plist-get exp-plist
:html-head-extra
) "")
492 ;; This script absolutely needs the table of contents, so we
493 ;; change that setting.
494 (unless (plist-get exp-plist
:with-toc
)
495 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
496 ;; Return the modified property list.
501 (defcustom org-html-text-markup-alist
502 '((bold .
"<b>%s</b>")
503 (code .
"<code>%s</code>")
504 (italic .
"<i>%s</i>")
505 (strike-through .
"<del>%s</del>")
506 (underline .
"<span class=\"underline\">%s</span>")
507 (verbatim .
"<code>%s</code>"))
508 "Alist of HTML expressions to convert text markup.
510 The key must be a symbol among `bold', `code', `italic',
511 `strike-through', `underline' and `verbatim'. The value is
512 a formatting string to wrap fontified text with.
514 If no association can be found for a given markup, text will be
516 :group
'org-export-html
517 :type
'(alist :key-type
(symbol :tag
"Markup type")
518 :value-type
(string :tag
"Format string"))
519 :options
'(bold code italic strike-through underline verbatim
))
521 (defcustom org-html-indent nil
522 "Non-nil means to indent the generated HTML.
523 Warning: non-nil may break indentation of source code blocks."
524 :group
'org-export-html
526 :package-version
'(Org .
"8.0")
529 (defcustom org-html-use-unicode-chars nil
530 "Non-nil means to use unicode characters instead of HTML entities."
531 :group
'org-export-html
533 :package-version
'(Org .
"8.0")
538 (defcustom org-html-format-drawer-function nil
539 "Function called to format a drawer in HTML code.
541 The function must accept two parameters:
542 NAME the drawer name, like \"LOGBOOK\"
543 CONTENTS the contents of the drawer.
545 The function should return the string to be exported.
547 For example, the variable could be set to the following function
548 in order to mimic default behaviour:
550 \(defun org-html-format-drawer-default \(name contents\)
551 \"Format a drawer element for HTML export.\"
553 :group
'org-export-html
558 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
559 <h2 class=\"footnotes\">%s: </h2>
560 <div id=\"text-footnotes\">
564 "Format for the footnotes section.
565 Should contain a two instances of %s. The first will be replaced with the
566 language-specific word for \"Footnotes\", the second one will be replaced
567 by the footnotes themselves."
568 :group
'org-export-html
571 (defcustom org-html-footnote-format
"<sup>%s</sup>"
572 "The format for the footnote reference.
573 %s will be replaced by the footnote reference itself."
574 :group
'org-export-html
577 (defcustom org-html-footnote-separator
"<sup>, </sup>"
578 "Text used to separate footnotes."
579 :group
'org-export-html
584 (defcustom org-html-toplevel-hlevel
2
585 "The <H> level for level 1 headings in HTML export.
586 This is also important for the classes that will be wrapped around headlines
587 and outline structure. If this variable is 1, the top-level headlines will
588 be <h1>, and the corresponding classes will be outline-1, section-number-1,
589 and outline-text-1. If this is 2, all of these will get a 2 instead.
590 The default for this variable is 2, because we use <h1> for formatting the
592 :group
'org-export-html
595 (defcustom org-html-format-headline-function nil
596 "Function to format headline text.
598 This function will be called with 5 arguments:
599 TODO the todo keyword (string or nil).
600 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
601 PRIORITY the priority of the headline (integer or nil)
602 TEXT the main headline text (string).
603 TAGS the tags (string or nil).
605 The function result will be used in the section format string."
606 :group
'org-export-html
611 (defcustom org-html-allow-name-attribute-in-anchors t
612 "When nil, do not set \"name\" attribute in anchors.
613 By default, anchors are formatted with both \"id\" and \"name\"
614 attributes, when appropriate."
615 :group
'org-export-html
617 :package-version
'(Org .
"8.0")
622 (defcustom org-html-format-inlinetask-function nil
623 "Function called to format an inlinetask in HTML code.
625 The function must accept six parameters:
626 TODO the todo keyword, as a string
627 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
628 PRIORITY the inlinetask priority, as a string
629 NAME the inlinetask name, as a string.
630 TAGS the inlinetask tags, as a list of strings.
631 CONTENTS the contents of the inlinetask, as a string.
633 The function should return the string to be exported."
634 :group
'org-export-html
639 (defcustom org-html-with-latex org-export-with-latex
640 "Non-nil means process LaTeX math snippets.
642 When set, the exporter will process LaTeX environments and
645 This option can also be set with the +OPTIONS line,
646 e.g. \"tex:mathjax\". Allowed values are:
648 nil Ignore math snippets.
649 `verbatim' Keep everything in verbatim
650 `dvipng' Process the LaTeX fragments to images. This will also
651 include processing of non-math environments.
652 `imagemagick' Convert the LaTeX fragments to pdf files and use
653 imagemagick to convert pdf files to png files.
654 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
656 t Synonym for `mathjax'."
657 :group
'org-export-html
659 :package-version
'(Org .
"8.0")
661 (const :tag
"Do not process math in any way" nil
)
662 (const :tag
"Use dvipng to make images" dvipng
)
663 (const :tag
"Use imagemagick to make images" imagemagick
)
664 (const :tag
"Use MathJax to display math" mathjax
)
665 (const :tag
"Leave math verbatim" verbatim
)))
667 ;;;; Links :: Generic
669 (defcustom org-html-link-org-files-as-html t
670 "Non-nil means make file links to `file.org' point to `file.html'.
671 When `org-mode' is exporting an `org-mode' file to HTML, links to
672 non-html files are directly put into a href tag in HTML.
673 However, links to other Org-mode files (recognized by the
674 extension `.org.) should become links to the corresponding html
675 file, assuming that the linked `org-mode' file will also be
677 When nil, the links still point to the plain `.org' file."
678 :group
'org-export-html
681 ;;;; Links :: Inline images
683 (defcustom org-html-inline-images
'maybe
684 "Non-nil means inline images into exported HTML pages.
685 This is done using an <img> tag. When nil, an anchor with href is used to
686 link to the image. If this option is `maybe', then images in links with
687 an empty description will be inlined, while images with a description will
689 :group
'org-export-html
690 :type
'(choice (const :tag
"Never" nil
)
691 (const :tag
"Always" t
)
692 (const :tag
"When there is no description" maybe
)))
694 (defcustom org-html-inline-image-rules
695 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
697 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
698 "Rules characterizing image files that can be inlined into HTML.
700 A rule consists in an association whose key is the type of link
701 to consider, and value is a regexp that will be matched against
704 Note that, by default, the image extension *actually* allowed
705 depend on the way the HTML file is processed. When used with
706 pdflatex, pdf, jpg and png images are OK. When processing
707 through dvi to Postscript, only ps and eps are allowed. The
708 default we use here encompasses both."
709 :group
'org-export-html
711 :package-version
'(Org .
"8.0")
712 :type
'(alist :key-type
(string :tag
"Type")
713 :value-type
(regexp :tag
"Path")))
717 (defcustom org-html-protect-char-alist
721 "Alist of characters to be converted by `org-html-protect'."
722 :group
'org-export-html
723 :type
'(repeat (cons (string :tag
"Character")
724 (string :tag
"HTML equivalent"))))
728 (defcustom org-html-htmlize-output-type
'inline-css
729 "Output type to be used by htmlize when formatting code snippets.
730 Choices are `css', to export the CSS selectors only, or `inline-css', to
731 export the CSS attribute values inline in the HTML. We use as default
732 `inline-css', in order to make the resulting HTML self-containing.
734 However, this will fail when using Emacs in batch mode for export, because
735 then no rich font definitions are in place. It will also not be good if
736 people with different Emacs setup contribute HTML files to a website,
737 because the fonts will represent the individual setups. In these cases,
738 it is much better to let Org/Htmlize assign classes only, and to use
739 a style file to define the look of these classes.
740 To get a start for your css file, start Emacs session and make sure that
741 all the faces you are interested in are defined, for example by loading files
742 in all modes you want. Then, use the command
743 \\[org-html-htmlize-generate-css] to extract class definitions."
744 :group
'org-export-html
745 :type
'(choice (const css
) (const inline-css
)))
747 (defcustom org-html-htmlize-font-prefix
"org-"
748 "The prefix for CSS class names for htmlize font specifications."
749 :group
'org-export-html
754 (defcustom org-html-table-tag
755 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
756 "The HTML tag that is used to start a table.
757 This must be a <table> tag, but you may change the options like
758 borders and spacing."
759 :group
'org-export-html
762 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
763 "The opening tag for table header fields.
764 This is customizable so that alignment options can be specified.
765 The first %s will be filled with the scope of the field, either row or col.
766 The second %s will be replaced by a style entry to align the field.
767 See also the variable `org-html-table-use-header-tags-for-first-column'.
768 See also the variable `org-html-table-align-individual-fields'."
769 :group
'org-export-html
770 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
772 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
773 "The opening tag for table data fields.
774 This is customizable so that alignment options can be specified.
775 The first %s will be filled with the scope of the field, either row or col.
776 The second %s will be replaced by a style entry to align the field.
777 See also the variable `org-html-table-align-individual-fields'."
778 :group
'org-export-html
779 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
781 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
782 "The opening tag for table data fields.
783 This is customizable so that alignment options can be specified.
784 Instead of strings, these can be Lisp forms that will be evaluated
785 for each row in order to construct the table row tags. During evaluation,
786 the variable `head' will be true when this is a header line, nil when this
787 is a body line. And the variable `nline' will contain the line number,
788 starting from 1 in the first header line. For example
790 (setq org-html-table-row-tags
793 (if (= (mod nline 2) 1)
794 \"<tr class=\\\"tr-odd\\\">\"
795 \"<tr class=\\\"tr-even\\\">\"))
798 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
799 :group
'org-export-html
801 (choice :tag
"Opening tag"
802 (string :tag
"Specify")
804 (choice :tag
"Closing tag"
805 (string :tag
"Specify")
808 (defcustom org-html-table-align-individual-fields t
809 "Non-nil means attach style attributes for alignment to each table field.
810 When nil, alignment will only be specified in the column tags, but this
811 is ignored by some browsers (like Firefox, Safari). Opera does it right
813 :group
'org-export-html
816 (defcustom org-html-table-use-header-tags-for-first-column nil
817 "Non-nil means format column one in tables with header tags.
818 When nil, also column one will use data tags."
819 :group
'org-export-html
822 (defcustom org-html-table-caption-above t
823 "When non-nil, place caption string at the beginning of the table.
824 Otherwise, place it near the end."
825 :group
'org-export-html
830 (defcustom org-html-tag-class-prefix
""
831 "Prefix to class names for TODO keywords.
832 Each tag gets a class given by the tag itself, with this prefix.
833 The default prefix is empty because it is nice to just use the keyword
834 as a class name. But if you get into conflicts with other, existing
835 CSS classes, then this prefix can be very useful."
836 :group
'org-export-html
839 ;;;; Template :: Generic
841 (defcustom org-html-extension
"html"
842 "The extension for exported HTML files."
843 :group
'org-export-html
846 (defcustom org-html-xml-declaration
847 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
848 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
849 "The extension for exported HTML files.
850 %s will be replaced with the charset of the exported file.
851 This may be a string, or an alist with export extensions
852 and corresponding declarations."
853 :group
'org-export-html
855 (string :tag
"Single declaration")
856 (repeat :tag
"Dependent on extension"
857 (cons (string :tag
"Extension")
858 (string :tag
"Declaration")))))
860 (defcustom org-html-coding-system
'utf-8
861 "Coding system for HTML export.
862 Use utf-8 as the default value."
863 :group
'org-export-html
865 :package-version
'(Org .
"8.0")
866 :type
'coding-system
)
868 (defcustom org-html-doctype
869 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
870 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
871 "Document type definition to use for exported HTML files.
872 Can be set with the in-buffer HTML_DOCTYPE property or for
873 publishing, with :html-doctype."
874 :group
'org-export-html
876 :package-version
'(Org .
"8.0")
879 (defcustom org-html-container-element
"div"
880 "HTML element to use for wrapping top level sections.
881 Can be set with the in-buffer HTML_CONTAINER property or for
882 publishing, with :html-container.
884 Note that changing the default will prevent you from using
885 org-info.js for your website."
886 :group
'org-export-html
888 :package-version
'(Org .
"8.0")
891 (defcustom org-html-divs
892 '((preamble "div" "preamble")
893 (content "div" "content")
894 (postamble "div" "postamble"))
895 "Alist of the threed section elements for HTML export.
896 The car of each entry is one of 'preamble, 'content or 'postamble.
897 The cdrs of each entry are the ELEMENT_TYPE and ID for each
898 section of the exported document.
900 Note that changing the default will prevent you from using
901 org-info.js for your website."
902 :group
'org-export-html
904 :package-version
'(Org .
"8.0")
905 :type
'(list :greedy t
906 (list :tag
"Preamble"
907 (const :format
"" preamble
)
908 (string :tag
"element") (string :tag
" id"))
910 (const :format
"" content
)
911 (string :tag
"element") (string :tag
" id"))
912 (list :tag
"Postamble" (const :format
"" postamble
)
913 (string :tag
" id") (string :tag
"element"))))
915 ;;;; Template :: Mathjax
917 (defcustom org-html-mathjax-options
918 '((path "http://orgmode.org/mathjax/MathJax.js")
923 "Options for MathJax setup.
925 path The path where to find MathJax
926 scale Scaling for the HTML-CSS backend, usually between 100 and 133
927 align How to align display math: left, center, or right
928 indent If align is not center, how far from the left/right side?
929 mathml Should a MathML player be used if available?
930 This is faster and reduces bandwidth use, but currently
931 sometimes has lower spacing quality. Therefore, the default is
932 nil. When browsers get better, this switch can be flipped.
934 You can also customize this for each buffer, using something like
936 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
937 :group
'org-export-html
938 :type
'(list :greedy t
939 (list :tag
"path (the path from where to load MathJax.js)"
940 (const :format
" " path
) (string))
941 (list :tag
"scale (scaling for the displayed math)"
942 (const :format
" " scale
) (string))
943 (list :tag
"align (alignment of displayed equations)"
944 (const :format
" " align
) (string))
945 (list :tag
"indent (indentation with left or right alignment)"
946 (const :format
" " indent
) (string))
947 (list :tag
"mathml (should MathML display be used is possible)"
948 (const :format
" " mathml
) (boolean))))
950 (defcustom org-html-mathjax-template
951 "<script type=\"text/javascript\" src=\"%PATH\">
952 <!--/*--><![CDATA[/*><!--*/
954 // Only one of the two following lines, depending on user settings
955 // First allows browser-native MathML display, second forces HTML/CSS
956 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
957 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
958 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
959 \"TeX/noUndefined.js\"],
961 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
962 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
963 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
964 ignoreClass: \"tex2jax_ignore\",
965 processEscapes: false,
966 processEnvironments: true,
969 showProcessingMessages: true,
970 displayAlign: \"%ALIGN\",
971 displayIndent: \"%INDENT\",
975 availableFonts: [\"STIX\",\"TeX\"],
976 preferredFont: \"TeX\",
992 "The MathJax setup for XHTML files."
993 :group
'org-export-html
996 ;;;; Template :: Postamble
998 (defcustom org-html-postamble
'auto
999 "Non-nil means insert a postamble in HTML export.
1001 When set to 'auto, check against the
1002 `org-export-with-author/email/creator/date' variables to set the
1003 content of the postamble. When set to a string, use this string
1004 as the postamble. When t, insert a string as defined by the
1005 formatting string in `org-html-postamble-format'.
1007 When set to a function, apply this function and insert the
1008 returned string. The function takes the property list of export
1009 options as its only argument.
1011 Setting :html-postamble in publishing projects will take
1012 precedence over this variable."
1013 :group
'org-export-html
1014 :type
'(choice (const :tag
"No postamble" nil
)
1015 (const :tag
"Auto postamble" 'auto
)
1016 (const :tag
"Default formatting string" t
)
1017 (string :tag
"Custom formatting string")
1018 (function :tag
"Function (must return a string)")))
1020 (defcustom org-html-postamble-format
1021 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1022 <p class=\"date\">Date: %d</p>
1023 <p class=\"creator\">%c</p>
1024 <p class=\"xhtml-validation\">%v</p>"))
1025 "Alist of languages and format strings for the HTML postamble.
1027 The first element of each list is the language code, as used for
1028 the LANGUAGE keyword. See `org-export-default-language'.
1030 The second element of each list is a format string to format the
1031 postamble itself. This format string can contain these elements:
1033 %t stands for the title.
1034 %a stands for the author's name.
1035 %e stands for the author's email.
1036 %d stands for the date.
1037 %c will be replaced by `org-html-creator-string'.
1038 %v will be replaced by `org-html-validation-link'.
1039 %T will be replaced by the export time.
1040 %C will be replaced by the last modification time.
1042 If you need to use a \"%\" character, you need to escape it
1044 :group
'org-export-html
1045 :type
'(alist :key-type
(string :tag
"Language")
1046 :value-type
(string :tag
"Format string")))
1048 (defcustom org-html-validation-link
1049 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1050 "Link to HTML validation service."
1051 :group
'org-export-html
1054 (defcustom org-html-creator-string
1055 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
1056 (if (fboundp 'org-version
) (org-version) "(Unknown)")
1058 "Information about the creator of the HTML document.
1059 This option can also be set on with the CREATOR keyword."
1060 :group
'org-export-html
1061 :type
'(string :tag
"Creator string"))
1063 ;;;; Template :: Preamble
1065 (defcustom org-html-preamble t
1066 "Non-nil means insert a preamble in HTML export.
1068 When t, insert a string as defined by the formatting string in
1069 `org-html-preamble-format'. When set to a string, use this
1070 formatting string instead (see `org-html-postamble-format' for an
1071 example of such a formatting string).
1073 When set to a function, apply this function and insert the
1074 returned string. The function takes the property list of export
1075 options as its only argument.
1077 Setting :html-preamble in publishing projects will take
1078 precedence over this variable."
1079 :group
'org-export-html
1080 :type
'(choice (const :tag
"No preamble" nil
)
1081 (const :tag
"Default preamble" t
)
1082 (string :tag
"Custom formatting string")
1083 (function :tag
"Function (must return a string)")))
1085 (defcustom org-html-preamble-format
'(("en" ""))
1086 "Alist of languages and format strings for the HTML preamble.
1088 The first element of each list is the language code, as used for
1089 the LANGUAGE keyword. See `org-export-default-language'.
1091 The second element of each list is a format string to format the
1092 preamble itself. This format string can contain these elements:
1094 %t stands for the title.
1095 %a stands for the author's name.
1096 %e stands for the author's email.
1097 %d stands for the date.
1098 %c will be replaced by `org-html-creator-string'.
1099 %v will be replaced by `org-html-validation-link'.
1100 %T will be replaced by the export time.
1101 %C will be replaced by the last modification time.
1103 If you need to use a \"%\" character, you need to escape it
1106 See the default value of `org-html-postamble-format' for an
1108 :group
'org-export-html
1109 :type
'(alist :key-type
(string :tag
"Language")
1110 :value-type
(string :tag
"Format string")))
1112 (defcustom org-html-link-up
""
1113 "Where should the \"UP\" link of exported HTML pages lead?"
1114 :group
'org-export-html
1115 :type
'(string :tag
"File or URL"))
1117 (defcustom org-html-link-home
""
1118 "Where should the \"HOME\" link of exported HTML pages lead?"
1119 :group
'org-export-html
1120 :type
'(string :tag
"File or URL"))
1122 (defcustom org-html-home
/up-format
1123 "<div id=\"org-div-home-and-up\">
1124 <a accesskey=\"h\" href=\"%s\"> UP </a>
1126 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1128 "Snippet used to insert the HOME and UP links.
1129 This is a format string, the first %s will receive the UP link,
1130 the second the HOME link. If both `org-html-link-up' and
1131 `org-html-link-home' are empty, the entire snippet will be
1133 :group
'org-export-html
1136 ;;;; Template :: Scripts
1138 (define-obsolete-variable-alias
1139 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1140 (defcustom org-html-head-include-scripts t
1141 "Non-nil means include the JavaScript snippets in exported HTML files.
1142 The actual script is defined in `org-html-scripts' and should
1144 :group
'org-export-html
1146 :package-version
'(Org .
"8.0")
1149 ;;;; Template :: Styles
1151 (define-obsolete-variable-alias
1152 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1153 (defcustom org-html-head-include-default-style t
1154 "Non-nil means include the default style in exported HTML files.
1155 The actual style is defined in `org-html-style-default' and
1156 should not be modified. Use `org-html-head' to use your own
1158 :group
'org-export-html
1160 :package-version
'(Org .
"8.0")
1163 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1165 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1166 (defcustom org-html-head
""
1167 "Org-wide head definitions for exported HTML files.
1169 This variable can contain the full HTML structure to provide a
1170 style, including the surrounding HTML tags. You can consider
1171 including definitions for the following classes: title, todo,
1172 done, timestamp, timestamp-kwd, tag, target.
1174 For example, a valid value would be:
1176 <style type=\"text/css\">
1178 p { font-weight: normal; color: gray; }
1179 h1 { color: black; }
1180 .title { text-align: center; }
1181 .todo, .timestamp-kwd { color: red; }
1182 .done { color: green; }
1186 If you want to refer to an external style, use something like
1188 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1190 As the value of this option simply gets inserted into the HTML
1191 <head> header, you can use it to add any arbitrary text to the
1194 You can set this on a per-file basis using #+HTML_HEAD:,
1195 or for publication projects using the :html-head property."
1196 :group
'org-export-html
1198 :package-version
'(Org .
"8.0")
1201 (put 'org-html-head
'safe-local-variable
'stringp
)
1203 (defcustom org-html-head-extra
""
1204 "More head information to add in the HTML output.
1206 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1207 or for publication projects using the :html-head-extra property."
1208 :group
'org-export-html
1210 :package-version
'(Org .
"8.0")
1213 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1217 (defcustom org-html-todo-kwd-class-prefix
""
1218 "Prefix to class names for TODO keywords.
1219 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1220 The default prefix is empty because it is nice to just use the keyword
1221 as a class name. But if you get into conflicts with other, existing
1222 CSS classes, then this prefix can be very useful."
1223 :group
'org-export-html
1227 ;;; Internal Functions
1229 (defun org-html-format-inline-image (src &optional
1230 caption label attr standalone-p
)
1231 "Format an inline image from SRC.
1232 CAPTION, LABEL and ATTR are optional arguments providing the
1233 caption, the label and the attribute of the image.
1234 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1235 (let* ((id (if (not label
) ""
1236 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1239 ((string-match "\\<alt=" (or attr
"")) "")
1240 ((string-match "^ltxpng/" src
)
1241 (format " alt=\"%s\""
1242 (org-html-encode-plain-text
1243 (org-find-text-property-in-string
1244 'org-latex-src src
))))
1245 (t (format " alt=\"%s\""
1246 (file-name-nondirectory src
)))))))
1249 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1250 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1251 id
(format "\n<p>%s</p>" img
)
1252 (if (and caption
(not (string= caption
"")))
1253 (format "\n<p>%s</p>" caption
) ""))))
1254 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1256 (defun org-html--textarea-block (element)
1257 "Transcode ELEMENT into a textarea block.
1258 ELEMENT is either a src block or an example block."
1259 (let* ((code (car (org-export-unravel-code element
)))
1260 (attr (org-export-read-attribute :attr_html element
)))
1261 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1262 (or (plist-get attr
:width
) 80)
1263 (or (plist-get attr
:height
) (org-count-lines code
))
1268 (defun org-html-bibliography ()
1269 "Find bibliography, cut it out and return it."
1271 (let (beg end
(cnt 1) bib
)
1273 (goto-char (point-min))
1274 (when (re-search-forward
1275 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1276 (setq beg
(match-beginning 0))
1277 (while (re-search-forward "</?div\\>" nil t
)
1278 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1280 (and (looking-at ">") (forward-char 1))
1281 (setq bib
(buffer-substring beg
(point)))
1282 (delete-region beg
(point))
1283 (throw 'exit bib
))))
1288 (defun org-html-splice-attributes (tag attributes
)
1289 "Return a HTML TAG edited wrt ATTRIBUTES."
1290 (if (not attributes
)
1292 (let (oldatt newatt
)
1293 (setq oldatt
(org-extract-attributes-from-string tag
)
1295 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1297 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1298 (if (string-match ">" tag
)
1300 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1304 (defun org-export-splice-style (style extra
)
1305 "Return STYLE updated wrt EXTRA."
1306 (if (and (stringp extra
)
1307 (string-match "\\S-" extra
)
1308 (string-match "</style>" style
))
1309 (concat (substring style
0 (match-beginning 0))
1311 (substring style
(match-beginning 0)))
1314 (defun org-html-htmlize-region-for-paste (beg end
)
1315 "Convert the region between BEG and END to HTML, using htmlize.el.
1316 This is much like `htmlize-region-for-paste', only that it uses
1317 the settings define in the org-... variables."
1318 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1319 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1320 (htmlbuf (htmlize-region beg end
)))
1322 (with-current-buffer htmlbuf
1323 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1324 (plist-get htmlize-buffer-places
'content-end
)))
1325 (kill-buffer htmlbuf
))))
1328 (defun org-html-htmlize-generate-css ()
1329 "Create the CSS for all font definitions in the current Emacs session.
1330 Use this to create face definitions in your CSS style file that can then
1331 be used by code snippets transformed by htmlize.
1332 This command just produces a buffer that contains class definitions for all
1333 faces used in the current Emacs session. You can copy and paste the ones you
1334 need into your CSS file.
1336 If you then set `org-html-htmlize-output-type' to `css', calls
1337 to the function `org-html-htmlize-region-for-paste' will
1338 produce code that uses these same face definitions."
1341 (and (get-buffer "*html*") (kill-buffer "*html*"))
1343 (let ((fl (face-list))
1344 (htmlize-css-name-prefix "org-")
1345 (htmlize-output-type 'css
)
1347 (while (setq f
(pop fl
)
1348 i
(and f
(face-attribute f
:inherit
)))
1349 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1350 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1351 (htmlize-region (point-min) (point-max))))
1352 (org-pop-to-buffer-same-window "*html*")
1353 (goto-char (point-min))
1354 (if (re-search-forward "<style" nil t
)
1355 (delete-region (point-min) (match-beginning 0)))
1356 (if (re-search-forward "</style>" nil t
)
1357 (delete-region (1+ (match-end 0)) (point-max)))
1358 (beginning-of-line 1)
1359 (if (looking-at " +") (replace-match ""))
1360 (goto-char (point-min)))
1362 (defun org-html--make-string (n string
)
1363 "Build a string by concatenating N times STRING."
1364 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1366 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1367 "Turn todo keyword KWD into a valid class name.
1368 Replaces invalid characters with \"_\"."
1370 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1371 (setq kwd
(replace-match "_" t t kwd
))))
1374 (defun org-html-format-footnote-reference (n def refcnt
)
1375 "Format footnote reference N with definition DEF into HTML."
1376 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1377 (format org-html-footnote-format
1378 (let* ((id (format "fnr.%s%s" n extra
))
1379 (href (format " href=\"#fn.%s\"" n
))
1380 (attributes (concat " class=\"footref\"" href
)))
1381 (org-html--anchor id n attributes
)))))
1383 (defun org-html-format-footnotes-section (section-name definitions
)
1384 "Format footnotes section SECTION-NAME."
1385 (if (not definitions
) ""
1386 (format org-html-footnotes-section section-name definitions
)))
1388 (defun org-html-format-footnote-definition (fn)
1389 "Format the footnote definition FN."
1390 (let ((n (car fn
)) (def (cdr fn
)))
1392 "<div class=\"footdef\">%s %s</div>\n"
1393 (format org-html-footnote-format
1394 (let* ((id (format "fn.%s" n
))
1395 (href (format " href=\"#fnr.%s\"" n
))
1396 (attributes (concat " class=\"footnum\"" href
)))
1397 (org-html--anchor id n attributes
)))
1400 (defun org-html-footnote-section (info)
1401 "Format the footnote section.
1402 INFO is a plist used as a communication channel."
1403 (let* ((fn-alist (org-export-collect-footnote-definitions
1404 (plist-get info
:parse-tree
) info
))
1406 (loop for
(n type raw
) in fn-alist collect
1407 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1408 (org-trim (org-export-data raw info
))
1410 (org-trim (org-export-data raw info
))))))))
1412 (org-html-format-footnotes-section
1413 (org-html--translate "Footnotes" info
)
1416 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1421 (defun org-html--build-meta-info (info)
1422 "Return meta tags for exported document.
1423 INFO is a plist used as a communication channel."
1424 (let* ((title (org-export-data (plist-get info
:title
) info
))
1425 (author (and (plist-get info
:with-author
)
1426 (let ((auth (plist-get info
:author
)))
1427 (and auth
(org-export-data auth info
)))))
1428 (description (plist-get info
:description
))
1429 (keywords (plist-get info
:keywords
)))
1431 (format "<title>%s</title>\n" title
)
1433 (when :time-stamp-file
1435 (concat "<!-- " org-html--timestamp-format
" -->\n"))))
1437 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1438 (or (and org-html-coding-system
1439 (fboundp 'coding-system-get
)
1440 (coding-system-get org-html-coding-system
'mime-charset
))
1442 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1443 (and author
(format "<meta name=\"author\" content=\"%s\"/>\n" author
))
1445 (format "<meta name=\"description\" content=\"%s\"/>\n" description
))
1447 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords
)))))
1449 (defun org-html--build-head (info)
1450 "Return information for the <head>..</head> of the HTML output.
1451 INFO is a plist used as a communication channel."
1452 (org-element-normalize-string
1454 (when (plist-get info
:html-head-include-default-style
)
1455 (org-element-normalize-string org-html-style-default
))
1456 (org-element-normalize-string (plist-get info
:html-head
))
1457 (org-element-normalize-string (plist-get info
:html-head-extra
))
1458 (when (and (plist-get info
:html-htmlized-css-url
)
1459 (eq org-html-htmlize-output-type
'css
))
1460 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1461 (plist-get info
:html-htmlized-css-url
)))
1462 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1464 (defun org-html--build-mathjax-config (info)
1465 "Insert the user setup into the mathjax template.
1466 INFO is a plist used as a communication channel."
1467 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1468 (org-element-map (plist-get info
:parse-tree
)
1469 '(latex-fragment latex-environment
) 'identity info t
))
1470 (let ((template org-html-mathjax-template
)
1471 (options org-html-mathjax-options
)
1472 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1473 name val
(yes " ") (no "// ") x
)
1476 (setq name
(car e
) val
(nth 1 e
))
1477 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1478 (setq val
(car (read-from-string
1479 (substring in-buffer
(match-end 0))))))
1480 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1481 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1482 (setq template
(replace-match val t t template
))))
1484 (setq val
(nth 1 (assq 'mathml options
)))
1485 (if (string-match (concat "\\<mathml:") in-buffer
)
1486 (setq val
(car (read-from-string
1487 (substring in-buffer
(match-end 0))))))
1488 ;; Exchange prefixes depending on mathml setting.
1489 (if (not val
) (setq x yes yes no no x
))
1490 ;; Replace cookies to turn on or off the config/jax lines.
1491 (if (string-match ":MMLYES:" template
)
1492 (setq template
(replace-match yes t t template
)))
1493 (if (string-match ":MMLNO:" template
)
1494 (setq template
(replace-match no t t template
)))
1495 ;; Return the modified template.
1496 (org-element-normalize-string template
))))
1498 (defun org-html-format-spec (info)
1499 "Return format specification for elements that can be
1500 used in the preamble or postamble."
1501 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1502 (?d .
,(org-export-data (org-export-get-date info
) info
))
1503 (?T .
,(format-time-string org-html--timestamp-format
))
1504 (?a .
,(org-export-data (plist-get info
:author
) info
))
1507 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1508 (split-string (plist-get info
:email
) ",+ *")
1510 (?c .
,(plist-get info
:creator
))
1511 (?C .
,(let ((file (plist-get info
:input-file
)))
1512 (format-time-string org-html--timestamp-format
1513 (if file
(nth 5 (file-attributes file
))
1515 (?v .
,(or org-html-validation-link
""))))
1517 (defun org-html--build-pre/postamble
(type info
)
1518 "Return document preamble or postamble as a string, or nil.
1519 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1520 communication channel."
1521 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1522 (spec (org-html-format-spec info
)))
1524 (let ((section-contents
1525 (if (functionp section
) (funcall section info
)
1527 ((stringp section
) (format-spec section spec
))
1529 (let ((date (cdr (assq ?d spec
)))
1530 (author (cdr (assq ?a spec
)))
1531 (email (cdr (assq ?e spec
)))
1532 (creator (cdr (assq ?c spec
)))
1533 (timestamp (cdr (assq ?T spec
)))
1534 (validation-link (cdr (assq ?v spec
))))
1536 (when (and (plist-get info
:with-date
)
1537 (org-string-nw-p date
))
1538 (format "<p class=\"date\">%s: %s</p>\n"
1539 (org-html--translate "Date" info
)
1541 (when (and (plist-get info
:with-author
)
1542 (org-string-nw-p author
))
1543 (format "<p class=\"author\">%s: %s</p>\n"
1544 (org-html--translate "Author" info
)
1546 (when (and (plist-get info
:with-email
)
1547 (org-string-nw-p email
))
1548 (format "<p class=\"email\">%s: %s</p>\n"
1549 (org-html--translate "Email" info
)
1551 (when (plist-get info
:time-stamp-file
)
1553 "<p class=\"date\">%s: %s</p>\n"
1554 (org-html--translate "Created" info
)
1555 (format-time-string org-html--timestamp-format
)))
1556 (when (plist-get info
:with-creator
)
1557 (format "<p class=\"creator\">%s</p>\n"
1559 (format "<p class=\"xhtml-validation\">%s</p>\n"
1563 (plist-get info
:language
)
1565 (format "org-html-%s-format" type
)))))
1570 (intern (format "org-html-%s-format" type
))))))
1572 (when (org-string-nw-p section-contents
)
1574 (format "<%s id=\"%s\" class=\"%s\">\n"
1575 (nth 1 (assq type org-html-divs
))
1576 (nth 2 (assq type org-html-divs
))
1577 org-html--pre
/postamble-class
)
1578 (org-element-normalize-string section-contents
)
1579 (format "</%s>\n" (nth 1 (assq type org-html-divs
)))))))))
1581 (defun org-html-inner-template (contents info
)
1582 "Return body of document string after HTML conversion.
1583 CONTENTS is the transcoded contents string. INFO is a plist
1584 holding export options."
1586 ;; Table of contents.
1587 (let ((depth (plist-get info
:with-toc
)))
1588 (when depth
(org-html-toc depth info
)))
1589 ;; Document contents.
1591 ;; Footnotes section.
1592 (org-html-footnote-section info
)
1594 (org-html-bibliography)))
1596 (defun org-html-template (contents info
)
1597 "Return complete document string after HTML conversion.
1598 CONTENTS is the transcoded contents string. INFO is a plist
1599 holding export options."
1602 (or (and (stringp org-html-xml-declaration
)
1603 org-html-xml-declaration
)
1604 (cdr (assoc (plist-get info
:html-extension
)
1605 org-html-xml-declaration
))
1606 (cdr (assoc "html" org-html-xml-declaration
))
1609 (or (and org-html-coding-system
1610 (fboundp 'coding-system-get
)
1611 (coding-system-get org-html-coding-system
'mime-charset
))
1614 (plist-get info
:html-doctype
)
1616 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1617 (plist-get info
:language
) (plist-get info
:language
))
1619 (org-html--build-meta-info info
)
1620 (org-html--build-head info
)
1621 (org-html--build-mathjax-config info
)
1624 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1625 (link-home (org-trim (plist-get info
:html-link-home
))))
1626 (unless (and (string= link-up
"") (string= link-up
""))
1627 (format org-html-home
/up-format
1628 (or link-up link-home
)
1629 (or link-home link-up
))))
1631 (org-html--build-pre/postamble
'preamble info
)
1632 ;; Document contents.
1633 (format "<%s id=\"%s\">\n"
1634 (nth 1 (assq 'content org-html-divs
))
1635 (nth 2 (assq 'content org-html-divs
)))
1637 (let ((title (plist-get info
:title
)))
1638 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1641 (nth 1 (assq 'content org-html-divs
)))
1643 (org-html--build-pre/postamble
'postamble info
)
1644 ;; Closing document.
1645 "</body>\n</html>"))
1647 (defun org-html--translate (s info
)
1648 "Translate string S according to specified language.
1649 INFO is a plist used as a communication channel."
1650 (org-export-translate s
:html info
))
1654 (defun org-html--anchor (&optional id desc attributes
)
1655 "Format a HTML anchor."
1656 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1657 (attributes (concat (and id
(format " id=\"%s\"" id
))
1658 (and name
(format " name=\"%s\"" name
))
1660 (format "<a%s>%s</a>" attributes
(or desc
""))))
1664 (defun org-html--todo (todo)
1665 "Format TODO keywords into HTML."
1667 (format "<span class=\"%s %s%s\">%s</span>"
1668 (if (member todo org-done-keywords
) "done" "todo")
1669 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1674 (defun org-html--tags (tags)
1675 "Format TAGS into HTML."
1677 (format "<span class=\"tag\">%s</span>"
1680 (format "<span class=\"%s\">%s</span>"
1681 (concat org-html-tag-class-prefix
1682 (org-html-fix-class-name tag
))
1688 (defun* org-html-format-headline
1689 (todo todo-type priority text tags
1690 &key level section-number headline-label
&allow-other-keys
)
1691 "Format a headline in HTML."
1692 (let ((section-number
1693 (when section-number
1694 (format "<span class=\"section-number-%d\">%s</span> "
1695 level section-number
)))
1696 (todo (org-html--todo todo
))
1697 (tags (org-html--tags tags
)))
1698 (concat section-number todo
(and todo
" ") text
1699 (and tags
"   ") tags
)))
1703 (defun org-html-fontify-code (code lang
)
1704 "Color CODE with htmlize library.
1705 CODE is a string representing the source code to colorize. LANG
1706 is the language used for CODE, as a string, or nil."
1709 ;; Case 1: No lang. Possibly an example block.
1711 ;; Simple transcoding.
1712 (org-html-encode-plain-text code
))
1713 ;; Case 2: No htmlize or an inferior version of htmlize
1714 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1716 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1717 ;; Simple transcoding.
1718 (org-html-encode-plain-text code
))
1721 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1722 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1724 ;; Case 1: Language is not associated with any Emacs mode
1725 ((not (functionp lang-mode
))
1726 ;; Simple transcoding.
1727 (org-html-encode-plain-text code
))
1728 ;; Case 2: Default. Fontify code.
1731 (setq code
(with-temp-buffer
1732 ;; Switch to language-specific mode.
1736 (font-lock-fontify-buffer)
1737 ;; Remove formatting on newline characters.
1739 (let ((beg (point-min))
1742 (while (progn (end-of-line) (< (point) end
))
1743 (put-text-property (point) (1+ (point)) 'face nil
)
1746 (set-buffer-modified-p nil
)
1748 (org-html-htmlize-region-for-paste
1749 (point-min) (point-max))))
1750 ;; Strip any enclosing <pre></pre> tags.
1751 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1752 (end (and beg
(string-match "</pre>\\'" code
))))
1753 (if (and beg end
) (substring code beg end
) code
)))))))))
1755 (defun org-html-do-format-code
1756 (code &optional lang refs retain-labels num-start
)
1757 "Format CODE string as source code.
1758 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1759 respectively, the language of the source code, as a string, an
1760 alist between line numbers and references (as returned by
1761 `org-export-unravel-code'), a boolean specifying if labels should
1762 appear in the source code, and the number associated to the first
1764 (let* ((code-lines (org-split-string code
"\n"))
1765 (code-length (length code-lines
))
1769 (length (number-to-string (+ code-length num-start
))))))
1770 (code (org-html-fontify-code code lang
)))
1771 (org-export-format-code
1773 (lambda (loc line-num ref
)
1776 ;; Add line number, if needed.
1778 (format "<span class=\"linenr\">%s</span>"
1779 (format num-fmt line-num
)))
1780 ;; Transcoded src line.
1782 ;; Add label, if needed.
1783 (when (and ref retain-labels
) (format " (%s)" ref
))))
1784 ;; Mark transcoded line as an anchor, if needed.
1786 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1790 (defun org-html-format-code (element info
)
1791 "Format contents of ELEMENT as source code.
1792 ELEMENT is either an example block or a src block. INFO is
1793 a plist used as a communication channel."
1794 (let* ((lang (org-element-property :language element
))
1795 ;; Extract code and references.
1796 (code-info (org-export-unravel-code element
))
1797 (code (car code-info
))
1798 (refs (cdr code-info
))
1799 ;; Does the src block contain labels?
1800 (retain-labels (org-element-property :retain-labels element
))
1801 ;; Does it have line numbers?
1802 (num-start (case (org-element-property :number-lines element
)
1803 (continued (org-export-get-loc element info
))
1805 (org-html-do-format-code code lang refs retain-labels num-start
)))
1808 ;;; Tables of Contents
1810 (defun org-html-toc (depth info
)
1811 "Build a table of contents.
1812 DEPTH is an integer specifying the depth of the table. INFO is a
1813 plist used as a communication channel. Return the table of
1814 contents as a string, or nil if it is empty."
1816 (mapcar (lambda (headline)
1817 (cons (org-html--format-toc-headline headline info
)
1818 (org-export-get-relative-level headline info
)))
1819 (org-export-collect-headlines info depth
))))
1821 (concat "<div id=\"table-of-contents\">\n"
1822 (format "<h%d>%s</h%d>\n"
1823 org-html-toplevel-hlevel
1824 (org-html--translate "Table of Contents" info
)
1825 org-html-toplevel-hlevel
)
1826 "<div id=\"text-table-of-contents\">"
1827 (org-html--toc-text toc-entries
)
1831 (defun org-html--toc-text (toc-entries)
1832 "Return innards of a table of contents, as a string.
1833 TOC-ENTRIES is an alist where key is an entry title, as a string,
1834 and value is its relative level, as an integer."
1835 (let* ((prev-level (1- (cdar toc-entries
)))
1836 (start-level prev-level
))
1840 (let ((headline (car entry
))
1841 (level (cdr entry
)))
1843 (let* ((cnt (- level prev-level
))
1844 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1846 (setq prev-level level
)
1848 (org-html--make-string
1849 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1850 ((< cnt
0) "</li>\n</ul>\n")))
1851 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1854 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1856 (defun org-html--format-toc-headline (headline info
)
1857 "Return an appropriate table of contents entry for HEADLINE.
1858 INFO is a plist used as a communication channel."
1859 (let* ((headline-number (org-export-get-headline-number headline info
))
1861 (and (not (org-export-low-level-p headline info
))
1862 (org-export-numbered-headline-p headline info
)
1863 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1864 (tags (and (eq (plist-get info
:with-tags
) t
)
1865 (org-export-get-tags headline info
))))
1866 (format "<a href=\"#%s\">%s</a>"
1868 (org-export-solidify-link-text
1869 (or (org-element-property :CUSTOM_ID headline
)
1870 (concat "sec-" (mapconcat 'number-to-string
1871 headline-number
"-"))))
1873 (concat section-number
1874 (org-export-data-with-translations
1875 (org-export-get-alt-title headline info
)
1876 ;; Ignore any footnote-reference, link,
1877 ;; radio-target and target in table of contents.
1879 '((footnote-reference . ignore
)
1880 (link .
(lambda (link desc i
) desc
))
1881 (radio-target .
(lambda (radio desc i
) desc
))
1883 (org-export-backend-translate-table 'html
))
1885 (and tags
"   ") (org-html--tags tags
)))))
1887 (defun org-html-list-of-listings (info)
1888 "Build a list of listings.
1889 INFO is a plist used as a communication channel. Return the list
1890 of listings as a string, or nil if it is empty."
1891 (let ((lol-entries (org-export-collect-listings info
)))
1893 (concat "<div id=\"list-of-listings\">\n"
1894 (format "<h%d>%s</h%d>\n"
1895 org-html-toplevel-hlevel
1896 (org-html--translate "List of Listings" info
)
1897 org-html-toplevel-hlevel
)
1898 "<div id=\"text-list-of-listings\">\n<ul>\n"
1900 (initial-fmt (org-html--translate "Listing %d:" info
)))
1903 (let ((label (org-element-property :name entry
))
1906 (or (org-export-get-caption entry t
)
1907 (org-export-get-caption entry
))
1912 (concat (format initial-fmt
(incf count
)) " " title
)
1913 (format "<a href=\"#%s\">%s %s</a>"
1914 (org-export-solidify-link-text label
)
1915 (format initial-fmt
(incf count
))
1919 "\n</ul>\n</div>\n</div>"))))
1921 (defun org-html-list-of-tables (info)
1922 "Build a list of tables.
1923 INFO is a plist used as a communication channel. Return the list
1924 of tables as a string, or nil if it is empty."
1925 (let ((lol-entries (org-export-collect-tables info
)))
1927 (concat "<div id=\"list-of-tables\">\n"
1928 (format "<h%d>%s</h%d>\n"
1929 org-html-toplevel-hlevel
1930 (org-html--translate "List of Tables" info
)
1931 org-html-toplevel-hlevel
)
1932 "<div id=\"text-list-of-tables\">\n<ul>\n"
1934 (initial-fmt (org-html--translate "Table %d:" info
)))
1937 (let ((label (org-element-property :name entry
))
1940 (or (org-export-get-caption entry t
)
1941 (org-export-get-caption entry
))
1946 (concat (format initial-fmt
(incf count
)) " " title
)
1947 (format "<a href=\"#%s\">%s %s</a>"
1948 (org-export-solidify-link-text label
)
1949 (format initial-fmt
(incf count
))
1953 "\n</ul>\n</div>\n</div>"))))
1956 ;;; Transcode Functions
1960 (defun org-html-bold (bold contents info
)
1961 "Transcode BOLD from Org to HTML.
1962 CONTENTS is the text with bold markup. INFO is a plist holding
1963 contextual information."
1964 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1969 (defun org-html-center-block (center-block contents info
)
1970 "Transcode a CENTER-BLOCK element from Org to HTML.
1971 CONTENTS holds the contents of the block. INFO is a plist
1972 holding contextual information."
1973 (format "<div class=\"center\">\n%s</div>" contents
))
1977 (defun org-html-clock (clock contents info
)
1978 "Transcode a CLOCK element from Org to HTML.
1979 CONTENTS is nil. INFO is a plist used as a communication
1982 <span class=\"timestamp-wrapper\">
1983 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1988 (org-element-property :raw-value
1989 (org-element-property :value clock
)))
1990 (let ((time (org-element-property :duration clock
)))
1991 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1995 (defun org-html-code (code contents info
)
1996 "Transcode CODE from Org to HTML.
1997 CONTENTS is nil. INFO is a plist holding contextual
1999 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
2000 (org-html-plain-text (org-element-property :value code
) info
)))
2004 (defun org-html-drawer (drawer contents info
)
2005 "Transcode a DRAWER element from Org to HTML.
2006 CONTENTS holds the contents of the block. INFO is a plist
2007 holding contextual information."
2008 (if (functionp org-html-format-drawer-function
)
2009 (funcall org-html-format-drawer-function
2010 (org-element-property :drawer-name drawer
)
2012 ;; If there's no user defined function: simply
2013 ;; display contents of the drawer.
2018 (defun org-html-dynamic-block (dynamic-block contents info
)
2019 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2020 CONTENTS holds the contents of the block. INFO is a plist
2021 holding contextual information. See `org-export-data'."
2026 (defun org-html-entity (entity contents info
)
2027 "Transcode an ENTITY object from Org to HTML.
2028 CONTENTS are the definition itself. INFO is a plist holding
2029 contextual information."
2030 (org-element-property :html entity
))
2034 (defun org-html-example-block (example-block contents info
)
2035 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2036 CONTENTS is nil. INFO is a plist holding contextual
2038 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2039 (org-html--textarea-block example-block
)
2040 (format "<pre class=\"example\">\n%s</pre>"
2041 (org-html-format-code example-block info
))))
2045 (defun org-html-export-snippet (export-snippet contents info
)
2046 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2047 CONTENTS is nil. INFO is a plist holding contextual
2049 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2050 (org-element-property :value export-snippet
)))
2054 (defun org-html-export-block (export-block contents info
)
2055 "Transcode a EXPORT-BLOCK element from Org to HTML.
2056 CONTENTS is nil. INFO is a plist holding contextual information."
2057 (when (string= (org-element-property :type export-block
) "HTML")
2058 (org-remove-indentation (org-element-property :value export-block
))))
2062 (defun org-html-fixed-width (fixed-width contents info
)
2063 "Transcode a FIXED-WIDTH element from Org to HTML.
2064 CONTENTS is nil. INFO is a plist holding contextual information."
2065 (format "<pre class=\"example\">\n%s</pre>"
2066 (org-html-do-format-code
2067 (org-remove-indentation
2068 (org-element-property :value fixed-width
)))))
2070 ;;;; Footnote Reference
2072 (defun org-html-footnote-reference (footnote-reference contents info
)
2073 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2074 CONTENTS is nil. INFO is a plist holding contextual information."
2076 ;; Insert separator between two footnotes in a row.
2077 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2078 (when (eq (org-element-type prev
) 'footnote-reference
)
2079 org-html-footnote-separator
))
2081 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2082 (org-html-format-footnote-reference
2083 (org-export-get-footnote-number footnote-reference info
)
2085 ;; Inline definitions are secondary strings.
2086 ((eq (org-element-property :type footnote-reference
) 'inline
)
2087 (org-html-format-footnote-reference
2088 (org-export-get-footnote-number footnote-reference info
)
2090 ;; Non-inline footnotes definitions are full Org data.
2091 (t (org-html-format-footnote-reference
2092 (org-export-get-footnote-number footnote-reference info
)
2097 (defun org-html-format-headline--wrap
2098 (headline info
&optional format-function
&rest extra-keys
)
2099 "Transcode a HEADLINE element from Org to HTML.
2100 CONTENTS holds the contents of the headline. INFO is a plist
2101 holding contextual information."
2102 (let* ((level (+ (org-export-get-relative-level headline info
)
2103 (1- org-html-toplevel-hlevel
)))
2104 (headline-number (org-export-get-headline-number headline info
))
2105 (section-number (and (not (org-export-low-level-p headline info
))
2106 (org-export-numbered-headline-p headline info
)
2107 (mapconcat 'number-to-string
2108 headline-number
".")))
2109 (todo (and (plist-get info
:with-todo-keywords
)
2110 (let ((todo (org-element-property :todo-keyword headline
)))
2111 (and todo
(org-export-data todo info
)))))
2112 (todo-type (and todo
(org-element-property :todo-type headline
)))
2113 (priority (and (plist-get info
:with-priority
)
2114 (org-element-property :priority headline
)))
2115 (text (org-export-data (org-element-property :title headline
) info
))
2116 (tags (and (plist-get info
:with-tags
)
2117 (org-export-get-tags headline info
)))
2118 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2119 (concat "sec-" (mapconcat 'number-to-string
2120 headline-number
"-"))))
2121 (format-function (cond
2122 ((functionp format-function
) format-function
)
2123 ((functionp org-html-format-headline-function
)
2125 (lambda (todo todo-type priority text tags
2127 (funcall org-html-format-headline-function
2128 todo todo-type priority text tags
))))
2129 (t 'org-html-format-headline
))))
2130 (apply format-function
2131 todo todo-type priority text tags
2132 :headline-label headline-label
:level level
2133 :section-number section-number extra-keys
)))
2135 (defun org-html-headline (headline contents info
)
2136 "Transcode a HEADLINE element from Org to HTML.
2137 CONTENTS holds the contents of the headline. INFO is a plist
2138 holding contextual information."
2140 (setq contents
(or contents
""))
2141 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2142 (level (org-export-get-relative-level headline info
))
2143 (text (org-export-data (org-element-property :title headline
) info
))
2144 (todo (and (plist-get info
:with-todo-keywords
)
2145 (let ((todo (org-element-property :todo-keyword headline
)))
2146 (and todo
(org-export-data todo info
)))))
2147 (todo-type (and todo
(org-element-property :todo-type headline
)))
2148 (tags (and (plist-get info
:with-tags
)
2149 (org-export-get-tags headline info
)))
2150 (priority (and (plist-get info
:with-priority
)
2151 (org-element-property :priority headline
)))
2152 (section-number (and (org-export-numbered-headline-p headline info
)
2153 (mapconcat 'number-to-string
2154 (org-export-get-headline-number
2155 headline info
) ".")))
2156 ;; Create the headline text.
2157 (full-text (org-html-format-headline--wrap headline info
)))
2159 ;; Case 1: This is a footnote section: ignore it.
2160 ((org-element-property :footnote-section-p headline
) nil
)
2161 ;; Case 2. This is a deep sub-tree: export it as a list item.
2162 ;; Also export as items headlines for which no section
2163 ;; format has been found.
2164 ((org-export-low-level-p headline info
)
2165 ;; Build the real contents of the sub-tree.
2166 (let* ((type (if numberedp
'ordered
'unordered
))
2167 (itemized-body (org-html-format-list-item
2168 contents type nil nil full-text
)))
2170 (and (org-export-first-sibling-p headline info
)
2171 (org-html-begin-plain-list type
))
2173 (and (org-export-last-sibling-p headline info
)
2174 (org-html-end-plain-list type
)))))
2175 ;; Case 3. Standard headline. Export it as a section.
2177 (let* ((section-number (mapconcat 'number-to-string
2178 (org-export-get-headline-number
2179 headline info
) "-"))
2181 (list (org-element-property :CUSTOM_ID headline
)
2182 (concat "sec-" section-number
)
2183 (org-element-property :ID headline
))))
2184 (preferred-id (car ids
))
2185 (extra-ids (cdr ids
))
2186 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2187 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2188 (first-content (car (org-element-contents headline
))))
2189 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2190 (if (= 1 (org-export-get-relative-level headline info
))
2191 (plist-get info
:html-container
)
2193 (format "outline-container-%s"
2194 (or (org-element-property :CUSTOM_ID headline
)
2196 (concat (format "outline-%d" level1
) (and extra-class
" ")
2198 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2203 (let ((id (org-export-solidify-link-text
2204 (if (org-uuidgen-p x
) (concat "ID-" x
)
2206 (org-html--anchor id
)))
2210 ;; When there is no section, pretend there is an empty
2211 ;; one to get the correct <div class="outline- ...>
2212 ;; which is needed by `org-info.js'.
2213 (if (not (eq (org-element-type first-content
) 'section
))
2214 (concat (org-html-section first-content
"" info
)
2217 (if (= 1 (org-export-get-relative-level headline info
))
2218 (plist-get info
:html-container
)
2221 ;;;; Horizontal Rule
2223 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2224 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2225 CONTENTS is nil. INFO is a plist holding contextual information."
2228 ;;;; Inline Src Block
2230 (defun org-html-inline-src-block (inline-src-block contents info
)
2231 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2232 CONTENTS holds the contents of the item. INFO is a plist holding
2233 contextual information."
2234 (let* ((org-lang (org-element-property :language inline-src-block
))
2235 (code (org-element-property :value inline-src-block
)))
2236 (error "Cannot export inline src block")))
2240 (defun org-html-format-section (text class
&optional id
)
2241 "Format a section with TEXT into a HTML div with CLASS and ID."
2242 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2243 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2245 (defun org-html-inlinetask (inlinetask contents info
)
2246 "Transcode an INLINETASK element from Org to HTML.
2247 CONTENTS holds the contents of the block. INFO is a plist
2248 holding contextual information."
2250 ;; If `org-html-format-inlinetask-function' is provided, call it
2251 ;; with appropriate arguments.
2252 ((functionp org-html-format-inlinetask-function
)
2253 (let ((format-function
2255 (lambda (todo todo-type priority text tags
2256 &key contents
&allow-other-keys
)
2257 (funcall org-html-format-inlinetask-function
2258 todo todo-type priority text tags contents
)))))
2259 (org-html-format-headline--wrap
2260 inlinetask info format-function
:contents contents
)))
2261 ;; Otherwise, use a default template.
2262 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2263 (org-html-format-headline--wrap inlinetask info
)
2268 (defun org-html-italic (italic contents info
)
2269 "Transcode ITALIC from Org to HTML.
2270 CONTENTS is the text with italic markup. INFO is a plist holding
2271 contextual information."
2272 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2276 (defun org-html-checkbox (checkbox)
2277 "Format CHECKBOX into HTML."
2278 (case checkbox
(on "<code>[X]</code>")
2279 (off "<code>[ ]</code>")
2280 (trans "<code>[-]</code>")
2283 (defun org-html-format-list-item (contents type checkbox
2284 &optional term-counter-id
2286 "Format a list item into HTML."
2287 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2291 (let* ((counter term-counter-id
)
2292 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2294 (format "<li%s>" extra
)
2295 (when headline
(concat headline
"<br/>")))))
2297 (let* ((id term-counter-id
)
2298 (extra (if id
(format " id=\"%s\"" id
) "")))
2300 (format "<li%s>" extra
)
2301 (when headline
(concat headline
"<br/>")))))
2303 (let* ((term term-counter-id
))
2304 (setq term
(or term
"(no term)"))
2305 ;; Check-boxes in descriptive lists are associated to tag.
2306 (concat (format "<dt> %s </dt>"
2307 (concat checkbox term
))
2309 (unless (eq type
'descriptive
) checkbox
)
2314 (descriptive "</dd>")))))
2316 (defun org-html-item (item contents info
)
2317 "Transcode an ITEM element from Org to HTML.
2318 CONTENTS holds the contents of the item. INFO is a plist holding
2319 contextual information."
2320 (let* ((plain-list (org-export-get-parent item
))
2321 (type (org-element-property :type plain-list
))
2322 (counter (org-element-property :counter item
))
2323 (checkbox (org-element-property :checkbox item
))
2324 (tag (let ((tag (org-element-property :tag item
)))
2325 (and tag
(org-export-data tag info
)))))
2326 (org-html-format-list-item
2327 contents type checkbox
(or tag counter
))))
2331 (defun org-html-keyword (keyword contents info
)
2332 "Transcode a KEYWORD element from Org to HTML.
2333 CONTENTS is nil. INFO is a plist holding contextual information."
2334 (let ((key (org-element-property :key keyword
))
2335 (value (org-element-property :value keyword
)))
2337 ((string= key
"HTML") value
)
2338 ((string= key
"TOC")
2339 (let ((value (downcase value
)))
2341 ((string-match "\\<headlines\\>" value
)
2342 (let ((depth (or (and (string-match "[0-9]+" value
)
2343 (string-to-number (match-string 0 value
)))
2344 (plist-get info
:with-toc
))))
2345 (org-html-toc depth info
)))
2346 ((string= "listings" value
) (org-html-list-of-listings info
))
2347 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2349 ;;;; Latex Environment
2351 (defun org-html-format-latex (latex-frag processing-type
)
2352 "Format the LaTeX fragment LATEX-FRAG into HTML."
2353 (let ((cache-relpath "") (cache-dir "") bfn
)
2354 (unless (eq processing-type
'mathjax
)
2355 (setq bfn
(buffer-file-name)
2358 (file-name-sans-extension
2359 (file-name-nondirectory bfn
)))
2360 cache-dir
(file-name-directory bfn
)))
2363 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2364 nil nil processing-type
)
2367 (defun org-html-latex-environment (latex-environment contents info
)
2368 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2369 CONTENTS is nil. INFO is a plist holding contextual information."
2370 (let ((processing-type (plist-get info
:with-latex
))
2371 (latex-frag (org-remove-indentation
2372 (org-element-property :value latex-environment
)))
2373 (caption (org-export-data
2374 (org-export-get-caption latex-environment
) info
))
2376 (label (org-element-property :name latex-environment
)))
2378 ((memq processing-type
'(t mathjax
))
2379 (org-html-format-latex latex-frag
'mathjax
))
2380 ((eq processing-type
'dvipng
)
2381 (let* ((formula-link (org-html-format-latex
2382 latex-frag processing-type
)))
2383 (when (and formula-link
2384 (string-match "file:\\([^]]*\\)" formula-link
))
2385 (org-html-format-inline-image
2386 (match-string 1 formula-link
) caption label attr t
))))
2391 (defun org-html-latex-fragment (latex-fragment contents info
)
2392 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2393 CONTENTS is nil. INFO is a plist holding contextual information."
2394 (let ((latex-frag (org-element-property :value latex-fragment
))
2395 (processing-type (plist-get info
:with-latex
)))
2396 (case processing-type
2398 (org-html-format-latex latex-frag
'mathjax
))
2400 (let* ((formula-link (org-html-format-latex
2401 latex-frag processing-type
)))
2402 (when (and formula-link
2403 (string-match "file:\\([^]]*\\)" formula-link
))
2404 (org-html-format-inline-image
2405 (match-string 1 formula-link
)))))
2410 (defun org-html-line-break (line-break contents info
)
2411 "Transcode a LINE-BREAK object from Org to HTML.
2412 CONTENTS is nil. INFO is a plist holding contextual information."
2417 (defun org-html-link--inline-image (link desc info
)
2418 "Return HTML code for an inline image.
2419 LINK is the link pointing to the inline image. INFO is a plist
2420 used as a communication channel.
2422 Inline images can have these attributes:
2424 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2425 (let* ((type (org-element-property :type link
))
2426 (raw-path (org-element-property :path link
))
2427 (path (cond ((member type
'("http" "https"))
2428 (concat type
":" raw-path
))
2429 ((file-name-absolute-p raw-path
)
2430 (expand-file-name raw-path
))
2432 (parent (org-export-get-parent-element link
))
2433 (caption (org-export-data (org-export-get-caption parent
) info
))
2434 (label (org-element-property :name parent
))
2435 (attrs (org-export-read-attribute :attr_html parent
))
2436 (alt (plist-get attrs
:alt
))
2437 (width (plist-get attrs
:width
))
2438 (height (plist-get attrs
:height
))
2439 (options (plist-get attrs
:options
)))
2440 ;; Return proper string, depending on DISPOSITION.
2441 (org-html-format-inline-image
2443 (mapconcat 'identity
2444 (delq nil
(list (if width
(format "width=\"%s\"" width
))
2445 (if alt
(format "alt=\"%s\"" alt
))
2446 (if height
(format "height=\"%s\"" height
))
2448 (org-html-standalone-image-p link info
))))
2450 (defvar org-html-standalone-image-predicate
)
2451 (defun org-html-standalone-image-p (element info
&optional predicate
)
2452 "Test if ELEMENT is a standalone image for the purpose HTML export.
2453 INFO is a plist holding contextual information.
2455 Return non-nil, if ELEMENT is of type paragraph and it's sole
2456 content, save for whitespaces, is a link that qualifies as an
2459 Return non-nil, if ELEMENT is of type link and it's containing
2460 paragraph has no other content save for leading and trailing
2463 Return nil, otherwise.
2465 Bind `org-html-standalone-image-predicate' to constrain
2466 paragraph further. For example, to check for only captioned
2467 standalone images, do the following.
2469 \(setq org-html-standalone-image-predicate
2470 \(lambda \(paragraph\)
2471 \(org-element-property :caption paragraph\)\)\)"
2472 (let ((paragraph (case (org-element-type element
)
2474 (link (and (org-export-inline-image-p
2475 element org-html-inline-image-rules
)
2476 (org-export-get-parent element
)))
2478 (when (eq (org-element-type paragraph
) 'paragraph
)
2479 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2480 (functionp org-html-standalone-image-predicate
)))
2481 (funcall org-html-standalone-image-predicate paragraph
))
2482 (let ((contents (org-element-contents paragraph
)))
2483 (loop for x in contents
2484 with inline-image-count
= 0
2486 ((eq (org-element-type x
) 'plain-text
)
2487 (not (org-string-nw-p x
)))
2488 ((eq (org-element-type x
) 'link
)
2489 (when (org-export-inline-image-p
2490 x org-html-inline-image-rules
)
2491 (= (incf inline-image-count
) 1)))
2494 (defun org-html-link (link desc info
)
2495 "Transcode a LINK object from Org to HTML.
2497 DESC is the description part of the link, or the empty string.
2498 INFO is a plist holding contextual information. See
2500 (let* ((link-org-files-as-html-maybe
2502 (lambda (raw-path info
)
2503 "Treat links to `file.org' as links to `file.html', if needed.
2504 See `org-html-link-org-files-as-html'."
2506 ((and org-html-link-org-files-as-html
2508 (downcase (file-name-extension raw-path
"."))))
2509 (concat (file-name-sans-extension raw-path
) "."
2510 (plist-get info
:html-extension
)))
2512 (type (org-element-property :type link
))
2513 (raw-path (org-element-property :path link
))
2514 ;; Ensure DESC really exists, or set it to nil.
2515 (desc (and (not (string= desc
"")) desc
))
2518 ((member type
'("http" "https" "ftp" "mailto"))
2519 (concat type
":" raw-path
))
2520 ((string= type
"file")
2521 ;; Treat links to ".org" files as ".html", if needed.
2523 (funcall link-org-files-as-html-maybe raw-path info
))
2524 ;; If file path is absolute, prepend it with protocol
2525 ;; component - "file://".
2526 (when (file-name-absolute-p raw-path
)
2528 (concat "file://" (expand-file-name raw-path
))))
2529 ;; Add search option, if any. A search option can be
2530 ;; relative to a custom-id or a headline title. Any other
2531 ;; option is ignored.
2532 (let ((option (org-element-property :search-option link
)))
2533 (cond ((not option
) raw-path
)
2534 ((eq (aref option
0) ?
#) (concat raw-path option
))
2535 ;; External fuzzy link: try to resolve it if path
2536 ;; belongs to current project, if any.
2537 ((eq (aref option
0) ?
*)
2541 (org-publish-resolve-external-fuzzy-link
2542 (org-element-property :path link
) option
)))
2543 (and numbers
(concat "#sec-"
2544 (mapconcat 'number-to-string
2548 attributes protocol
)
2549 ;; Extract attributes from parent's paragraph. HACK: Only do this
2550 ;; for the first link in parent. This is needed as long as
2551 ;; attributes cannot be set on a per link basis.
2552 (and (setq attributes
2553 (let ((parent (org-export-get-parent-element link
)))
2554 (if (not (eq (org-element-map parent
'link
'identity info t
)
2557 (let ((att (org-export-read-attribute :attr_html parent
:options
)))
2558 (unless (and desc att
(string-match (regexp-quote att
) desc
))
2560 (unless (string= attributes
"")
2561 (setq attributes
(concat " " attributes
))))
2564 ((and (or (eq t org-html-inline-images
)
2565 (and org-html-inline-images
(not desc
)))
2566 (org-export-inline-image-p link org-html-inline-image-rules
))
2567 (org-html-link--inline-image link desc info
))
2568 ;; Radio target: Transcode target's contents and use them as
2569 ;; link's description.
2570 ((string= type
"radio")
2571 (let ((destination (org-export-resolve-radio-link link info
)))
2573 (format "<a href=\"#%s\"%s>%s</a>"
2574 (org-export-solidify-link-text path
)
2576 (org-export-data (org-element-contents destination
) info
)))))
2577 ;; Links pointing to a headline: Find destination and build
2578 ;; appropriate referencing command.
2579 ((member type
'("custom-id" "fuzzy" "id"))
2580 (let ((destination (if (string= type
"fuzzy")
2581 (org-export-resolve-fuzzy-link link info
)
2582 (org-export-resolve-id-link link info
))))
2583 (case (org-element-type destination
)
2584 ;; ID link points to an external file.
2586 (let ((fragment (concat "ID-" path
))
2587 ;; Treat links to ".org" files as ".html", if needed.
2588 (path (funcall link-org-files-as-html-maybe
2590 (format "<a href=\"%s#%s\"%s>%s</a>"
2591 path fragment attributes
(or desc destination
))))
2592 ;; Fuzzy link points nowhere.
2597 (org-element-property :raw-link link
) info
))))
2598 ;; Fuzzy link points to an invisible target.
2600 ;; Link points to a headline.
2603 ;; What href to use?
2605 ;; Case 1: Headline is linked via it's CUSTOM_ID
2606 ;; property. Use CUSTOM_ID.
2607 ((string= type
"custom-id")
2608 (org-element-property :CUSTOM_ID destination
))
2609 ;; Case 2: Headline is linked via it's ID property
2610 ;; or through other means. Use the default href.
2611 ((member type
'("id" "fuzzy"))
2613 (mapconcat 'number-to-string
2614 (org-export-get-headline-number
2615 destination info
) "-")))
2616 (t (error "Shouldn't reach here"))))
2617 ;; What description to use?
2619 ;; Case 1: Headline is numbered and LINK has no
2620 ;; description or LINK's description matches
2621 ;; headline's title. Display section number.
2622 (if (and (org-export-numbered-headline-p destination info
)
2624 (string= desc
(org-element-property
2625 :raw-value destination
))))
2626 (mapconcat 'number-to-string
2627 (org-export-get-headline-number
2628 destination info
) ".")
2629 ;; Case 2: Either the headline is un-numbered or
2630 ;; LINK has a custom description. Display LINK's
2631 ;; description or headline's title.
2632 (or desc
(org-export-data (org-element-property
2633 :title destination
) info
)))))
2634 (format "<a href=\"#%s\"%s>%s</a>"
2635 (org-export-solidify-link-text href
) attributes desc
)))
2636 ;; Fuzzy link points to a target. Do as above.
2638 (let ((path (org-export-solidify-link-text path
)) number
)
2641 ((org-html-standalone-image-p destination info
)
2642 (org-export-get-ordinal
2643 (assoc 'link
(org-element-contents destination
))
2644 info
'link
'org-html-standalone-image-p
))
2645 (t (org-export-get-ordinal destination info
))))
2646 (setq desc
(when number
2647 (if (atom number
) (number-to-string number
)
2648 (mapconcat 'number-to-string number
".")))))
2649 (format "<a href=\"#%s\"%s>%s</a>"
2650 path attributes
(or desc
"No description for this link")))))))
2651 ;; Coderef: replace link with the reference name or the
2652 ;; equivalent line number.
2653 ((string= type
"coderef")
2654 (let ((fragment (concat "coderef-" path
)))
2655 (format "<a href=\"#%s\"%s%s>%s</a>"
2658 (format (concat "class=\"coderef\""
2659 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2660 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2663 (format (org-export-get-coderef-format path desc
)
2664 (org-export-resolve-coderef path info
)))))
2665 ;; Link type is handled by a special function.
2666 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2667 (funcall protocol
(org-link-unescape path
) desc
'html
))
2668 ;; External link with a description part.
2669 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2670 ;; External link without a description part.
2671 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2672 ;; No path, only description. Try to do something useful.
2673 (t (format "<i>%s</i>" desc
)))))
2677 (defun org-html-paragraph (paragraph contents info
)
2678 "Transcode a PARAGRAPH element from Org to HTML.
2679 CONTENTS is the contents of the paragraph, as a string. INFO is
2680 the plist used as a communication channel."
2681 (let* ((parent (org-export-get-parent paragraph
))
2682 (parent-type (org-element-type parent
))
2683 (style '((footnote-definition " class=\"footpara\"")))
2684 (extra (or (cadr (assoc parent-type style
)) "")))
2686 ((and (eq (org-element-type parent
) 'item
)
2687 (= (org-element-property :begin paragraph
)
2688 (org-element-property :contents-begin parent
)))
2689 ;; leading paragraph in a list item have no tags
2691 ((org-html-standalone-image-p paragraph info
)
2694 (t (format "<p%s>\n%s</p>" extra contents
)))))
2698 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2699 ;; the correct value for the item counter
2700 (defun org-html-begin-plain-list (type &optional arg1
)
2701 "Insert the beginning of the HTML list depending on TYPE.
2702 When ARG1 is a string, use it as the start parameter for ordered
2706 (format "<ol class=\"org-ol\"%s>"
2707 (if arg1
(format " start=\"%d\"" arg1
) "")))
2708 (unordered "<ul class=\"org-ul\">")
2709 (descriptive "<dl class=\"org-dl\">")))
2711 (defun org-html-end-plain-list (type)
2712 "Insert the end of the HTML list depending on TYPE."
2716 (descriptive "</dl>")))
2718 (defun org-html-plain-list (plain-list contents info
)
2719 "Transcode a PLAIN-LIST element from Org to HTML.
2720 CONTENTS is the contents of the list. INFO is a plist holding
2721 contextual information."
2722 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2723 (type (org-element-property :type plain-list
)))
2725 (org-html-begin-plain-list type
)
2726 contents
(org-html-end-plain-list type
))))
2730 (defun org-html-convert-special-strings (string)
2731 "Convert special characters in STRING to HTML."
2732 (let ((all org-html-special-string-regexps
)
2734 (while (setq a
(pop all
))
2735 (setq re
(car a
) rpl
(cdr a
) start
0)
2736 (while (string-match re string start
)
2737 (setq string
(replace-match rpl t nil string
))))
2740 (defun org-html-encode-plain-text (text)
2741 "Convert plain text characters from TEXT to HTML equivalent.
2742 Possible conversions are set in `org-html-protect-char-alist'."
2745 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2746 org-html-protect-char-alist
)
2749 (defun org-html-plain-text (text info
)
2750 "Transcode a TEXT string from Org to HTML.
2751 TEXT is the string to transcode. INFO is a plist holding
2752 contextual information."
2753 (let ((output text
))
2754 ;; Protect following characters: <, >, &.
2755 (setq output
(org-html-encode-plain-text output
))
2756 ;; Handle smart quotes. Be sure to provide original string since
2757 ;; OUTPUT may have been modified.
2758 (when (plist-get info
:with-smart-quotes
)
2759 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2760 ;; Handle special strings.
2761 (when (plist-get info
:with-special-strings
)
2762 (setq output
(org-html-convert-special-strings output
)))
2763 ;; Handle break preservation if required.
2764 (when (plist-get info
:preserve-breaks
)
2766 (replace-regexp-in-string
2767 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2774 (defun org-html-planning (planning contents info
)
2775 "Transcode a PLANNING element from Org to HTML.
2776 CONTENTS is nil. INFO is a plist used as a communication
2778 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2780 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2785 (let ((closed (org-element-property :closed planning
)))
2787 (format span-fmt org-closed-string
2789 (org-element-property :raw-value closed
)))))
2790 (let ((deadline (org-element-property :deadline planning
)))
2792 (format span-fmt org-deadline-string
2794 (org-element-property :raw-value deadline
)))))
2795 (let ((scheduled (org-element-property :scheduled planning
)))
2797 (format span-fmt org-scheduled-string
2799 (org-element-property :raw-value scheduled
)))))))
2802 ;;;; Property Drawer
2804 (defun org-html-property-drawer (property-drawer contents info
)
2805 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2806 CONTENTS is nil. INFO is a plist holding contextual
2808 ;; The property drawer isn't exported but we want separating blank
2809 ;; lines nonetheless.
2814 (defun org-html-quote-block (quote-block contents info
)
2815 "Transcode a QUOTE-BLOCK element from Org to HTML.
2816 CONTENTS holds the contents of the block. INFO is a plist
2817 holding contextual information."
2818 (format "<blockquote>\n%s</blockquote>" contents
))
2822 (defun org-html-quote-section (quote-section contents info
)
2823 "Transcode a QUOTE-SECTION element from Org to HTML.
2824 CONTENTS is nil. INFO is a plist holding contextual information."
2825 (let ((value (org-remove-indentation
2826 (org-element-property :value quote-section
))))
2827 (when value
(format "<pre>\n%s</pre>" value
))))
2831 (defun org-html-section (section contents info
)
2832 "Transcode a SECTION element from Org to HTML.
2833 CONTENTS holds the contents of the section. INFO is a plist
2834 holding contextual information."
2835 (let ((parent (org-export-get-parent-headline section
)))
2836 ;; Before first headline: no container, just return CONTENTS.
2837 (if (not parent
) contents
2838 ;; Get div's class and id references.
2839 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2840 (1- org-html-toplevel-hlevel
)))
2844 (org-export-get-headline-number parent info
) "-")))
2845 ;; Build return value.
2846 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2848 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2853 (defun org-html-radio-target (radio-target text info
)
2854 "Transcode a RADIO-TARGET object from Org to HTML.
2855 TEXT is the text of the target. INFO is a plist holding
2856 contextual information."
2857 (let ((id (org-export-solidify-link-text
2858 (org-element-property :value radio-target
))))
2859 (org-html--anchor id text
)))
2863 (defun org-html-special-block (special-block contents info
)
2864 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2865 CONTENTS holds the contents of the block. INFO is a plist
2866 holding contextual information."
2867 (format "<div class=\"%s\">\n%s\n</div>"
2868 (downcase (org-element-property :type special-block
))
2873 (defun org-html-src-block (src-block contents info
)
2874 "Transcode a SRC-BLOCK element from Org to HTML.
2875 CONTENTS holds the contents of the item. INFO is a plist holding
2876 contextual information."
2877 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2878 (org-html--textarea-block src-block
)
2879 (let ((lang (org-element-property :language src-block
))
2880 (caption (org-export-get-caption src-block
))
2881 (code (org-html-format-code src-block info
))
2882 (label (let ((lbl (org-element-property :name src-block
)))
2884 (format " id=\"%s\""
2885 (org-export-solidify-link-text lbl
))))))
2886 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2888 "<div class=\"org-src-container\">\n%s%s\n</div>"
2889 (if (not caption
) ""
2890 (format "<label class=\"org-src-name\">%s</label>"
2891 (org-export-data caption info
)))
2892 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2894 ;;;; Statistics Cookie
2896 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2897 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2898 CONTENTS is nil. INFO is a plist holding contextual information."
2899 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2900 (format "<code>%s</code>" cookie-value
)))
2904 (defun org-html-strike-through (strike-through contents info
)
2905 "Transcode STRIKE-THROUGH from Org to HTML.
2906 CONTENTS is the text with strike-through markup. INFO is a plist
2907 holding contextual information."
2908 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2913 (defun org-html-subscript (subscript contents info
)
2914 "Transcode a SUBSCRIPT object from Org to HTML.
2915 CONTENTS is the contents of the object. INFO is a plist holding
2916 contextual information."
2917 (format "<sub>%s</sub>" contents
))
2921 (defun org-html-superscript (superscript contents info
)
2922 "Transcode a SUPERSCRIPT object from Org to HTML.
2923 CONTENTS is the contents of the object. INFO is a plist holding
2924 contextual information."
2925 (format "<sup>%s</sup>" contents
))
2929 (defun org-html-table-cell (table-cell contents info
)
2930 "Transcode a TABLE-CELL element from Org to HTML.
2931 CONTENTS is nil. INFO is a plist used as a communication
2933 (let* ((table-row (org-export-get-parent table-cell
))
2934 (table (org-export-get-parent-table table-cell
))
2936 (if (not org-html-table-align-individual-fields
) ""
2937 (format (if (and (boundp 'org-html-format-table-no-css
)
2938 org-html-format-table-no-css
)
2939 " align=\"%s\"" " class=\"%s\"")
2940 (org-export-table-cell-alignment table-cell info
)))))
2941 (when (or (not contents
) (string= "" (org-trim contents
)))
2942 (setq contents
" "))
2944 ((and (org-export-table-has-header-p table info
)
2945 (= 1 (org-export-table-row-group table-row info
)))
2946 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2947 contents
(cdr org-html-table-header-tags
)))
2948 ((and org-html-table-use-header-tags-for-first-column
2949 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2950 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2951 contents
(cdr org-html-table-header-tags
)))
2952 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2953 contents
(cdr org-html-table-data-tags
))))))
2957 (defun org-html-table-row (table-row contents info
)
2958 "Transcode a TABLE-ROW element from Org to HTML.
2959 CONTENTS is the contents of the row. INFO is a plist used as a
2960 communication channel."
2961 ;; Rules are ignored since table separators are deduced from
2962 ;; borders of the current row.
2963 (when (eq (org-element-property :type table-row
) 'standard
)
2964 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2967 ;; Case 1: Row belongs to second or subsequent rowgroups.
2968 ((not (= 1 (org-export-table-row-group table-row info
)))
2969 '("<tbody>" .
"\n</tbody>"))
2970 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2971 ((org-export-table-has-header-p
2972 (org-export-get-parent-table table-row
) info
)
2973 '("<thead>" .
"\n</thead>"))
2974 ;; Case 2: Row is from first and only row group.
2975 (t '("<tbody>" .
"\n</tbody>")))))
2977 ;; Begin a rowgroup?
2978 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2979 (car rowgroup-tags
))
2981 (concat "\n" (eval (car org-html-table-row-tags
))
2984 (eval (cdr org-html-table-row-tags
)))
2986 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2987 (cdr rowgroup-tags
))))))
2991 (defun org-html-table-first-row-data-cells (table info
)
2992 "Transcode the first row of TABLE.
2993 INFO is a plist used as a communication channel."
2995 (org-element-map table
'table-row
2997 (unless (eq (org-element-property :type row
) 'rule
) row
))
2999 (special-column-p (org-export-table-has-special-column-p table
)))
3000 (if (not special-column-p
) (org-element-contents table-row
)
3001 (cdr (org-element-contents table-row
)))))
3003 (defun org-html-table--table.el-table
(table info
)
3004 "Format table.el tables into HTML.
3005 INFO is a plist used as a communication channel."
3006 (when (eq (org-element-property :type table
) 'table.el
)
3008 (let ((outbuf (with-current-buffer
3009 (get-buffer-create "*org-export-table*")
3010 (erase-buffer) (current-buffer))))
3012 (insert (org-element-property :value table
))
3014 (re-search-forward "^[ \t]*|[^|]" nil t
)
3015 (table-generate-source 'html outbuf
))
3016 (with-current-buffer outbuf
3017 (prog1 (org-trim (buffer-string))
3020 (defun org-html-table (table contents info
)
3021 "Transcode a TABLE element from Org to HTML.
3022 CONTENTS is the contents of the table. INFO is a plist holding
3023 contextual information."
3024 (case (org-element-property :type table
)
3025 ;; Case 1: table.el table. Convert it using appropriate tools.
3026 (table.el
(org-html-table--table.el-table table info
))
3027 ;; Case 2: Standard table.
3029 (let* ((label (org-element-property :name table
))
3030 (caption (org-export-get-caption table
))
3032 (org-export-read-attribute :attr_html table
:options
))
3034 (if (and (boundp 'org-html-format-table-no-css
)
3035 org-html-format-table-no-css
)
3036 "align=\"%s\"" "class=\"%s\""))
3039 (lambda (table info
)
3041 (lambda (table-cell)
3042 (let ((alignment (org-export-table-cell-alignment
3045 ;; Begin a colgroup?
3046 (when (org-export-table-cell-starts-colgroup-p
3049 ;; Add a column. Also specify it's alignment.
3050 (format "\n<col %s/>" (format alignspec alignment
))
3052 (when (org-export-table-cell-ends-colgroup-p
3055 (org-html-table-first-row-data-cells table info
) "\n"))))
3057 (let ((table-tag (plist-get info
:html-table-tag
)))
3059 (and (string-match "<table\\(.*\\)>" table-tag
)
3060 (match-string 1 table-tag
))
3061 (and label
(format " id=\"%s\""
3062 (org-export-solidify-link-text label
)))
3063 (unless (string= attributes
"")
3064 (concat " " attributes
))))))
3065 ;; Remove last blank line.
3066 (setq contents
(substring contents
0 -
1))
3067 (format "<table%s>\n%s\n%s\n%s\n</table>"
3069 (if (not caption
) ""
3070 (format "<caption>%s</caption>"
3071 (org-export-data caption info
)))
3072 (funcall table-column-specs table info
)
3077 (defun org-html-target (target contents info
)
3078 "Transcode a TARGET object from Org to HTML.
3079 CONTENTS is nil. INFO is a plist holding contextual
3081 (let ((id (org-export-solidify-link-text
3082 (org-element-property :value target
))))
3083 (org-html--anchor id
)))
3087 (defun org-html-timestamp (timestamp contents info
)
3088 "Transcode a TIMESTAMP object from Org to HTML.
3089 CONTENTS is nil. INFO is a plist holding contextual
3091 (let ((value (org-html-plain-text
3092 (org-timestamp-translate timestamp
) info
)))
3093 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3094 (replace-regexp-in-string "--" "–" value
))))
3098 (defun org-html-underline (underline contents info
)
3099 "Transcode UNDERLINE from Org to HTML.
3100 CONTENTS is the text with underline markup. INFO is a plist
3101 holding contextual information."
3102 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3107 (defun org-html-verbatim (verbatim contents info
)
3108 "Transcode VERBATIM from Org to HTML.
3109 CONTENTS is nil. INFO is a plist holding contextual
3111 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3112 (org-html-plain-text (org-element-property :value verbatim
) info
)))
3116 (defun org-html-verse-block (verse-block contents info
)
3117 "Transcode a VERSE-BLOCK element from Org to HTML.
3118 CONTENTS is verse block contents. INFO is a plist holding
3119 contextual information."
3120 ;; Replace each newline character with line break. Also replace
3121 ;; each blank line with a line break.
3122 (setq contents
(replace-regexp-in-string
3123 "^ *\\\\\\\\$" "<br/>\n"
3124 (replace-regexp-in-string
3125 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3126 ;; Replace each white space at beginning of a line with a
3127 ;; non-breaking space.
3128 (while (string-match "^[ \t]+" contents
)
3129 (let* ((num-ws (length (match-string 0 contents
)))
3130 (ws (let (out) (dotimes (i num-ws out
)
3131 (setq out
(concat out
" "))))))
3132 (setq contents
(replace-match ws nil t contents
))))
3133 (format "<p class=\"verse\">\n%s</p>" contents
))
3136 ;;; Filter Functions
3138 (defun org-html-final-function (contents backend info
)
3139 "Filter to indent the HTML and convert HTML entities."
3144 (indent-region (point-min) (point-max)))
3145 (when org-html-use-unicode-chars
3147 (mm-url-decode-entities))
3148 (buffer-substring-no-properties (point-min) (point-max))))
3151 ;;; End-user functions
3154 (defun org-html-export-as-html
3155 (&optional async subtreep visible-only body-only ext-plist
)
3156 "Export current buffer to an HTML buffer.
3158 If narrowing is active in the current buffer, only export its
3161 If a region is active, export that region.
3163 A non-nil optional argument ASYNC means the process should happen
3164 asynchronously. The resulting buffer should be accessible
3165 through the `org-export-stack' interface.
3167 When optional argument SUBTREEP is non-nil, export the sub-tree
3168 at point, extracting information from the headline properties
3171 When optional argument VISIBLE-ONLY is non-nil, don't export
3172 contents of hidden elements.
3174 When optional argument BODY-ONLY is non-nil, only write code
3175 between \"<body>\" and \"</body>\" tags.
3177 EXT-PLIST, when provided, is a property list with external
3178 parameters overriding Org default settings, but still inferior to
3179 file-local settings.
3181 Export is done in a buffer named \"*Org HTML Export*\", which
3182 will be displayed when `org-export-show-temporary-export-buffer'
3186 (org-export-async-start
3188 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3191 (goto-char (point-min))
3193 (org-export-add-to-stack (current-buffer) 'html
)))
3194 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3195 (let ((outbuf (org-export-to-buffer
3196 'html
"*Org HTML Export*"
3197 subtreep visible-only body-only ext-plist
)))
3199 (with-current-buffer outbuf
(set-auto-mode t
))
3200 (when org-export-show-temporary-export-buffer
3201 (switch-to-buffer-other-window outbuf
)))))
3204 (defun org-html-convert-region-to-html ()
3205 "Assume the current region has org-mode syntax, and convert it to HTML.
3206 This can be used in any buffer. For example, you can write an
3207 itemized list in org-mode syntax in an HTML buffer and use this
3208 command to convert it."
3210 (org-export-replace-region-by 'html
))
3213 (defun org-html-export-to-html
3214 (&optional async subtreep visible-only body-only ext-plist
)
3215 "Export current buffer to a HTML file.
3217 If narrowing is active in the current buffer, only export its
3220 If a region is active, export that region.
3222 A non-nil optional argument ASYNC means the process should happen
3223 asynchronously. The resulting file should be accessible through
3224 the `org-export-stack' interface.
3226 When optional argument SUBTREEP is non-nil, export the sub-tree
3227 at point, extracting information from the headline properties
3230 When optional argument VISIBLE-ONLY is non-nil, don't export
3231 contents of hidden elements.
3233 When optional argument BODY-ONLY is non-nil, only write code
3234 between \"<body>\" and \"</body>\" tags.
3236 EXT-PLIST, when provided, is a property list with external
3237 parameters overriding Org default settings, but still inferior to
3238 file-local settings.
3240 Return output file's name."
3242 (let* ((extension (concat "." org-html-extension
))
3243 (file (org-export-output-file-name extension subtreep
))
3244 (org-export-coding-system org-html-coding-system
))
3246 (org-export-async-start
3247 (lambda (f) (org-export-add-to-stack f
'html
))
3248 (let ((org-export-coding-system org-html-coding-system
))
3251 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3252 (let ((org-export-coding-system org-html-coding-system
))
3254 'html file subtreep visible-only body-only ext-plist
)))))
3257 (defun org-html-publish-to-html (plist filename pub-dir
)
3258 "Publish an org file to HTML.
3260 FILENAME is the filename of the Org file to be published. PLIST
3261 is the property list for the given project. PUB-DIR is the
3262 publishing directory.
3264 Return output file name."
3265 (org-publish-org-to 'html filename
3266 (concat "." (or (plist-get plist
:html-extension
)
3267 org-html-extension
"html"))
3273 ;;;; org-format-table-html
3274 ;;;; org-format-org-table-html
3275 ;;;; org-format-table-table-html
3276 ;;;; org-table-number-fraction
3277 ;;;; org-table-number-regexp
3278 ;;;; org-html-table-caption-above
3279 ;;;; org-html-inline-image-extensions
3280 ;;;; org-export-preferred-target-alist
3281 ;;;; class for anchors
3282 ;;;; org-export-with-section-numbers, body-only
3283 ;;;; org-export-mark-todo-in-toc
3284 ;;;; org-html-format-org-link
3285 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3286 ;;;; alt = (file-name-nondirectory path)
3291 ;; generated-autoload-file: "org-loaddefs.el"
3294 ;;; ox-html.el ends here