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 t
522 "Non-nil means to indent the generated HTML."
523 :group
'org-export-html
525 :package-version
'(Org .
"8.0")
528 (defcustom org-html-use-unicode-chars nil
529 "Non-nil means to use unicode characters instead of HTML entities."
530 :group
'org-export-html
532 :package-version
'(Org .
"8.0")
537 (defcustom org-html-format-drawer-function nil
538 "Function called to format a drawer in HTML code.
540 The function must accept two parameters:
541 NAME the drawer name, like \"LOGBOOK\"
542 CONTENTS the contents of the drawer.
544 The function should return the string to be exported.
546 For example, the variable could be set to the following function
547 in order to mimic default behaviour:
549 \(defun org-html-format-drawer-default \(name contents\)
550 \"Format a drawer element for HTML export.\"
552 :group
'org-export-html
557 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
558 <h2 class=\"footnotes\">%s: </h2>
559 <div id=\"text-footnotes\">
563 "Format for the footnotes section.
564 Should contain a two instances of %s. The first will be replaced with the
565 language-specific word for \"Footnotes\", the second one will be replaced
566 by the footnotes themselves."
567 :group
'org-export-html
570 (defcustom org-html-footnote-format
"<sup>%s</sup>"
571 "The format for the footnote reference.
572 %s will be replaced by the footnote reference itself."
573 :group
'org-export-html
576 (defcustom org-html-footnote-separator
"<sup>, </sup>"
577 "Text used to separate footnotes."
578 :group
'org-export-html
583 (defcustom org-html-toplevel-hlevel
2
584 "The <H> level for level 1 headings in HTML export.
585 This is also important for the classes that will be wrapped around headlines
586 and outline structure. If this variable is 1, the top-level headlines will
587 be <h1>, and the corresponding classes will be outline-1, section-number-1,
588 and outline-text-1. If this is 2, all of these will get a 2 instead.
589 The default for this variable is 2, because we use <h1> for formatting the
591 :group
'org-export-html
594 (defcustom org-html-format-headline-function nil
595 "Function to format headline text.
597 This function will be called with 5 arguments:
598 TODO the todo keyword (string or nil).
599 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
600 PRIORITY the priority of the headline (integer or nil)
601 TEXT the main headline text (string).
602 TAGS the tags (string or nil).
604 The function result will be used in the section format string."
605 :group
'org-export-html
610 (defcustom org-html-allow-name-attribute-in-anchors t
611 "When nil, do not set \"name\" attribute in anchors.
612 By default, anchors are formatted with both \"id\" and \"name\"
613 attributes, when appropriate."
614 :group
'org-export-html
616 :package-version
'(Org .
"8.0")
621 (defcustom org-html-format-inlinetask-function nil
622 "Function called to format an inlinetask in HTML code.
624 The function must accept six parameters:
625 TODO the todo keyword, as a string
626 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
627 PRIORITY the inlinetask priority, as a string
628 NAME the inlinetask name, as a string.
629 TAGS the inlinetask tags, as a list of strings.
630 CONTENTS the contents of the inlinetask, as a string.
632 The function should return the string to be exported."
633 :group
'org-export-html
638 (defcustom org-html-with-latex org-export-with-latex
639 "Non-nil means process LaTeX math snippets.
641 When set, the exporter will process LaTeX environments and
644 This option can also be set with the +OPTIONS line,
645 e.g. \"tex:mathjax\". Allowed values are:
647 nil Ignore math snippets.
648 `verbatim' Keep everything in verbatim
649 `dvipng' Process the LaTeX fragments to images. This will also
650 include processing of non-math environments.
651 `imagemagick' Convert the LaTeX fragments to pdf files and use
652 imagemagick to convert pdf files to png files.
653 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
655 t Synonym for `mathjax'."
656 :group
'org-export-html
658 :package-version
'(Org .
"8.0")
660 (const :tag
"Do not process math in any way" nil
)
661 (const :tag
"Use dvipng to make images" dvipng
)
662 (const :tag
"Use imagemagick to make images" imagemagick
)
663 (const :tag
"Use MathJax to display math" mathjax
)
664 (const :tag
"Leave math verbatim" verbatim
)))
666 ;;;; Links :: Generic
668 (defcustom org-html-link-org-files-as-html t
669 "Non-nil means make file links to `file.org' point to `file.html'.
670 When `org-mode' is exporting an `org-mode' file to HTML, links to
671 non-html files are directly put into a href tag in HTML.
672 However, links to other Org-mode files (recognized by the
673 extension `.org.) should become links to the corresponding html
674 file, assuming that the linked `org-mode' file will also be
676 When nil, the links still point to the plain `.org' file."
677 :group
'org-export-html
680 ;;;; Links :: Inline images
682 (defcustom org-html-inline-images
'maybe
683 "Non-nil means inline images into exported HTML pages.
684 This is done using an <img> tag. When nil, an anchor with href is used to
685 link to the image. If this option is `maybe', then images in links with
686 an empty description will be inlined, while images with a description will
688 :group
'org-export-html
689 :type
'(choice (const :tag
"Never" nil
)
690 (const :tag
"Always" t
)
691 (const :tag
"When there is no description" maybe
)))
693 (defcustom org-html-inline-image-rules
694 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
695 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
696 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
697 "Rules characterizing image files that can be inlined into HTML.
699 A rule consists in an association whose key is the type of link
700 to consider, and value is a regexp that will be matched against
703 Note that, by default, the image extension *actually* allowed
704 depend on the way the HTML file is processed. When used with
705 pdflatex, pdf, jpg and png images are OK. When processing
706 through dvi to Postscript, only ps and eps are allowed. The
707 default we use here encompasses both."
708 :group
'org-export-html
710 :package-version
'(Org .
"8.0")
711 :type
'(alist :key-type
(string :tag
"Type")
712 :value-type
(regexp :tag
"Path")))
716 (defcustom org-html-protect-char-alist
720 "Alist of characters to be converted by `org-html-protect'."
721 :group
'org-export-html
722 :type
'(repeat (cons (string :tag
"Character")
723 (string :tag
"HTML equivalent"))))
727 (defcustom org-html-htmlize-output-type
'inline-css
728 "Output type to be used by htmlize when formatting code snippets.
729 Choices are `css', to export the CSS selectors only, or `inline-css', to
730 export the CSS attribute values inline in the HTML. We use as default
731 `inline-css', in order to make the resulting HTML self-containing.
733 However, this will fail when using Emacs in batch mode for export, because
734 then no rich font definitions are in place. It will also not be good if
735 people with different Emacs setup contribute HTML files to a website,
736 because the fonts will represent the individual setups. In these cases,
737 it is much better to let Org/Htmlize assign classes only, and to use
738 a style file to define the look of these classes.
739 To get a start for your css file, start Emacs session and make sure that
740 all the faces you are interested in are defined, for example by loading files
741 in all modes you want. Then, use the command
742 \\[org-html-htmlize-generate-css] to extract class definitions."
743 :group
'org-export-html
744 :type
'(choice (const css
) (const inline-css
)))
746 (defcustom org-html-htmlize-font-prefix
"org-"
747 "The prefix for CSS class names for htmlize font specifications."
748 :group
'org-export-html
753 (defcustom org-html-table-tag
754 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
755 "The HTML tag that is used to start a table.
756 This must be a <table> tag, but you may change the options like
757 borders and spacing."
758 :group
'org-export-html
761 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
762 "The opening tag for table header fields.
763 This is customizable so that alignment options can be specified.
764 The first %s will be filled with the scope of the field, either row or col.
765 The second %s will be replaced by a style entry to align the field.
766 See also the variable `org-html-table-use-header-tags-for-first-column'.
767 See also the variable `org-html-table-align-individual-fields'."
768 :group
'org-export-html
769 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
771 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
772 "The opening tag for table data fields.
773 This is customizable so that alignment options can be specified.
774 The first %s will be filled with the scope of the field, either row or col.
775 The second %s will be replaced by a style entry to align the field.
776 See also the variable `org-html-table-align-individual-fields'."
777 :group
'org-export-html
778 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
780 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
781 "The opening tag for table data fields.
782 This is customizable so that alignment options can be specified.
783 Instead of strings, these can be Lisp forms that will be evaluated
784 for each row in order to construct the table row tags. During evaluation,
785 the variable `head' will be true when this is a header line, nil when this
786 is a body line. And the variable `nline' will contain the line number,
787 starting from 1 in the first header line. For example
789 (setq org-html-table-row-tags
792 (if (= (mod nline 2) 1)
793 \"<tr class=\\\"tr-odd\\\">\"
794 \"<tr class=\\\"tr-even\\\">\"))
797 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
798 :group
'org-export-html
800 (choice :tag
"Opening tag"
801 (string :tag
"Specify")
803 (choice :tag
"Closing tag"
804 (string :tag
"Specify")
807 (defcustom org-html-table-align-individual-fields t
808 "Non-nil means attach style attributes for alignment to each table field.
809 When nil, alignment will only be specified in the column tags, but this
810 is ignored by some browsers (like Firefox, Safari). Opera does it right
812 :group
'org-export-html
815 (defcustom org-html-table-use-header-tags-for-first-column nil
816 "Non-nil means format column one in tables with header tags.
817 When nil, also column one will use data tags."
818 :group
'org-export-html
821 (defcustom org-html-table-caption-above t
822 "When non-nil, place caption string at the beginning of the table.
823 Otherwise, place it near the end."
824 :group
'org-export-html
829 (defcustom org-html-tag-class-prefix
""
830 "Prefix to class names for TODO keywords.
831 Each tag gets a class given by the tag itself, with this prefix.
832 The default prefix is empty because it is nice to just use the keyword
833 as a class name. But if you get into conflicts with other, existing
834 CSS classes, then this prefix can be very useful."
835 :group
'org-export-html
838 ;;;; Template :: Generic
840 (defcustom org-html-extension
"html"
841 "The extension for exported HTML files."
842 :group
'org-export-html
845 (defcustom org-html-xml-declaration
846 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
847 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
848 "The extension for exported HTML files.
849 %s will be replaced with the charset of the exported file.
850 This may be a string, or an alist with export extensions
851 and corresponding declarations."
852 :group
'org-export-html
854 (string :tag
"Single declaration")
855 (repeat :tag
"Dependent on extension"
856 (cons (string :tag
"Extension")
857 (string :tag
"Declaration")))))
859 (defcustom org-html-coding-system
'utf-8
860 "Coding system for HTML export.
861 Use utf-8 as the default value."
862 :group
'org-export-html
864 :package-version
'(Org .
"8.0")
865 :type
'coding-system
)
867 (defcustom org-html-doctype
868 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
869 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
870 "Document type definition to use for exported HTML files.
871 Can be set with the in-buffer HTML_DOCTYPE property or for
872 publishing, with :html-doctype."
873 :group
'org-export-html
875 :package-version
'(Org .
"8.0")
878 (defcustom org-html-container-element
"div"
879 "HTML element to use for wrapping top level sections.
880 Can be set with the in-buffer HTML_CONTAINER property or for
881 publishing, with :html-container.
883 Note that changing the default will prevent you from using
884 org-info.js for your website."
885 :group
'org-export-html
887 :package-version
'(Org .
"8.0")
890 (defcustom org-html-divs
891 '((preamble "div" "preamble")
892 (content "div" "content")
893 (postamble "div" "postamble"))
894 "Alist of the threed section elements for HTML export.
895 The car of each entry is one of 'preamble, 'content or 'postamble.
896 The cdrs of each entry are the ELEMENT_TYPE and ID for each
897 section of the exported document.
899 Note that changing the default will prevent you from using
900 org-info.js for your website."
901 :group
'org-export-html
903 :package-version
'(Org .
"8.0")
904 :type
'(list :greedy t
905 (list :tag
"Preamble"
906 (const :format
"" preamble
)
907 (string :tag
"element") (string :tag
" id"))
909 (const :format
"" content
)
910 (string :tag
"element") (string :tag
" id"))
911 (list :tag
"Postamble" (const :format
"" postamble
)
912 (string :tag
" id") (string :tag
"element"))))
914 ;;;; Template :: Mathjax
916 (defcustom org-html-mathjax-options
917 '((path "http://orgmode.org/mathjax/MathJax.js")
922 "Options for MathJax setup.
924 path The path where to find MathJax
925 scale Scaling for the HTML-CSS backend, usually between 100 and 133
926 align How to align display math: left, center, or right
927 indent If align is not center, how far from the left/right side?
928 mathml Should a MathML player be used if available?
929 This is faster and reduces bandwidth use, but currently
930 sometimes has lower spacing quality. Therefore, the default is
931 nil. When browsers get better, this switch can be flipped.
933 You can also customize this for each buffer, using something like
935 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
936 :group
'org-export-html
937 :type
'(list :greedy t
938 (list :tag
"path (the path from where to load MathJax.js)"
939 (const :format
" " path
) (string))
940 (list :tag
"scale (scaling for the displayed math)"
941 (const :format
" " scale
) (string))
942 (list :tag
"align (alignment of displayed equations)"
943 (const :format
" " align
) (string))
944 (list :tag
"indent (indentation with left or right alignment)"
945 (const :format
" " indent
) (string))
946 (list :tag
"mathml (should MathML display be used is possible)"
947 (const :format
" " mathml
) (boolean))))
949 (defcustom org-html-mathjax-template
950 "<script type=\"text/javascript\" src=\"%PATH\">
951 <!--/*--><![CDATA[/*><!--*/
953 // Only one of the two following lines, depending on user settings
954 // First allows browser-native MathML display, second forces HTML/CSS
955 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
956 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
957 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
958 \"TeX/noUndefined.js\"],
960 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
961 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
962 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
963 ignoreClass: \"tex2jax_ignore\",
964 processEscapes: false,
965 processEnvironments: true,
968 showProcessingMessages: true,
969 displayAlign: \"%ALIGN\",
970 displayIndent: \"%INDENT\",
974 availableFonts: [\"STIX\",\"TeX\"],
975 preferredFont: \"TeX\",
991 "The MathJax setup for XHTML files."
992 :group
'org-export-html
995 ;;;; Template :: Postamble
997 (defcustom org-html-postamble
'auto
998 "Non-nil means insert a postamble in HTML export.
1000 When set to 'auto, check against the
1001 `org-export-with-author/email/creator/date' variables to set the
1002 content of the postamble. When set to a string, use this string
1003 as the postamble. When t, insert a string as defined by the
1004 formatting string in `org-html-postamble-format'.
1006 When set to a function, apply this function and insert the
1007 returned string. The function takes the property list of export
1008 options as its only argument.
1010 Setting :html-postamble in publishing projects will take
1011 precedence over this variable."
1012 :group
'org-export-html
1013 :type
'(choice (const :tag
"No postamble" nil
)
1014 (const :tag
"Auto postamble" 'auto
)
1015 (const :tag
"Default formatting string" t
)
1016 (string :tag
"Custom formatting string")
1017 (function :tag
"Function (must return a string)")))
1019 (defcustom org-html-postamble-format
1020 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1021 <p class=\"date\">Date: %d</p>
1022 <p class=\"creator\">Generated by %c</p>
1023 <p class=\"xhtml-validation\">%v</p>"))
1024 "Alist of languages and format strings for the HTML postamble.
1026 The first element of each list is the language code, as used for
1027 the #+LANGUAGE keyword.
1029 The second element of each list is a format string to format the
1030 postamble itself. This format string can contain these elements:
1032 %t stands for the title.
1033 %a stands for the author's name.
1034 %e stands for the author's email.
1035 %d stands for the date.
1036 %c will be replaced by information about Org/Emacs versions.
1037 %v will be replaced by `org-html-validation-link'.
1038 %T will be replace by the creation time of the file.
1040 If you need to use a \"%\" character, you need to escape it
1042 :group
'org-export-html
1043 :type
'(alist :key-type
(string :tag
"Language")
1044 :value-type
(string :tag
"Format string")))
1046 (defcustom org-html-validation-link
1047 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1048 "Link to HTML validation service."
1049 :group
'org-export-html
1052 (defcustom org-html-creator-string
1053 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
1054 (if (fboundp 'org-version
) (org-version) "(Unknown)")
1056 "String to insert at the end of the HTML document."
1057 :group
'org-export-html
1058 :type
'(string :tag
"Creator string"))
1060 ;;;; Template :: Preamble
1062 (defcustom org-html-preamble t
1063 "Non-nil means insert a preamble in HTML export.
1065 When t, insert a string as defined by the formatting string in
1066 `org-html-preamble-format'. When set to a string, use this
1067 formatting string instead (see `org-html-postamble-format' for an
1068 example of such a formatting string).
1070 When set to a function, apply this function and insert the
1071 returned string. The function takes the property list of export
1072 options as its only argument.
1074 Setting :html-preamble in publishing projects will take
1075 precedence over this variable."
1076 :group
'org-export-html
1077 :type
'(choice (const :tag
"No preamble" nil
)
1078 (const :tag
"Default preamble" t
)
1079 (string :tag
"Custom formatting string")
1080 (function :tag
"Function (must return a string)")))
1082 (defcustom org-html-preamble-format
'(("en" ""))
1083 "Alist of languages and format strings for the HTML preamble.
1085 The first element of each list is the language code, as used for
1086 the #+LANGUAGE keyword.
1088 The second element of each list is a format string to format the
1089 preamble itself. This format string can contain these elements:
1091 %t stands for the title.
1092 %a stands for the author's name.
1093 %e stands for the author's email.
1094 %d stands for the date.
1095 %c will be replaced by information about Org/Emacs versions.
1096 %v will be replaced by `org-html-validation-link'.
1097 %T will be replace by the creation time of the file.
1099 If you need to use a \"%\" character, you need to escape it
1102 See the default value of `org-html-postamble-format' for an
1104 :group
'org-export-html
1105 :type
'(alist :key-type
(string :tag
"Language")
1106 :value-type
(string :tag
"Format string")))
1108 (defcustom org-html-link-up
""
1109 "Where should the \"UP\" link of exported HTML pages lead?"
1110 :group
'org-export-html
1111 :type
'(string :tag
"File or URL"))
1113 (defcustom org-html-link-home
""
1114 "Where should the \"HOME\" link of exported HTML pages lead?"
1115 :group
'org-export-html
1116 :type
'(string :tag
"File or URL"))
1118 (defcustom org-html-home
/up-format
1119 "<div id=\"org-div-home-and-up\">
1120 <a accesskey=\"h\" href=\"%s\"> UP </a>
1122 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1124 "Snippet used to insert the HOME and UP links.
1125 This is a format string, the first %s will receive the UP link,
1126 the second the HOME link. If both `org-html-link-up' and
1127 `org-html-link-home' are empty, the entire snippet will be
1129 :group
'org-export-html
1132 ;;;; Template :: Scripts
1134 (define-obsolete-variable-alias
1135 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1136 (defcustom org-html-head-include-scripts t
1137 "Non-nil means include the JavaScript snippets in exported HTML files.
1138 The actual script is defined in `org-html-scripts' and should
1140 :group
'org-export-html
1142 :package-version
'(Org .
"8.0")
1145 ;;;; Template :: Styles
1147 (define-obsolete-variable-alias
1148 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1149 (defcustom org-html-head-include-default-style t
1150 "Non-nil means include the default style in exported HTML files.
1151 The actual style is defined in `org-html-style-default' and
1152 should not be modified. Use `org-html-head' to use your own
1154 :group
'org-export-html
1156 :package-version
'(Org .
"8.0")
1159 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1161 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1162 (defcustom org-html-head
""
1163 "Org-wide head definitions for exported HTML files.
1165 This variable can contain the full HTML structure to provide a
1166 style, including the surrounding HTML tags. You can consider
1167 including definitions for the following classes: title, todo,
1168 done, timestamp, timestamp-kwd, tag, target.
1170 For example, a valid value would be:
1172 <style type=\"text/css\">
1174 p { font-weight: normal; color: gray; }
1175 h1 { color: black; }
1176 .title { text-align: center; }
1177 .todo, .timestamp-kwd { color: red; }
1178 .done { color: green; }
1182 If you want to refer to an external style, use something like
1184 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1186 As the value of this option simply gets inserted into the HTML
1187 <head> header, you can use it to add any arbitrary text to the
1190 You can set this on a per-file basis using #+HTML_HEAD:,
1191 or for publication projects using the :html-head property."
1192 :group
'org-export-html
1194 :package-version
'(Org .
"8.0")
1197 (put 'org-html-head
'safe-local-variable
'stringp
)
1199 (defcustom org-html-head-extra
""
1200 "More head information to add in the HTML output.
1202 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1203 or for publication projects using the :html-head-extra property."
1204 :group
'org-export-html
1206 :package-version
'(Org .
"8.0")
1209 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1213 (defcustom org-html-todo-kwd-class-prefix
""
1214 "Prefix to class names for TODO keywords.
1215 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1216 The default prefix is empty because it is nice to just use the keyword
1217 as a class name. But if you get into conflicts with other, existing
1218 CSS classes, then this prefix can be very useful."
1219 :group
'org-export-html
1223 ;;; Internal Functions
1225 (defun org-html-format-inline-image (src &optional
1226 caption label attr standalone-p
)
1227 "Format an inline image from SRC.
1228 CAPTION, LABEL and ATTR are optional arguments providing the
1229 caption, the label and the attribute of the image.
1230 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1231 (let* ((id (if (not label
) ""
1232 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1235 ((string-match "\\<alt=" (or attr
"")) "")
1236 ((string-match "^ltxpng/" src
)
1237 (format " alt=\"%s\""
1238 (org-html-encode-plain-text
1239 (org-find-text-property-in-string
1240 'org-latex-src src
))))
1241 (t (format " alt=\"%s\""
1242 (file-name-nondirectory src
)))))))
1245 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1246 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1247 id
(format "\n<p>%s</p>" img
)
1248 (if (and caption
(not (string= caption
"")))
1249 (format "\n<p>%s</p>" caption
) ""))))
1250 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1252 (defun org-html--textarea-block (element)
1253 "Transcode ELEMENT into a textarea block.
1254 ELEMENT is either a src block or an example block."
1255 (let* ((code (car (org-export-unravel-code element
)))
1256 (attr (org-export-read-attribute :attr_html element
)))
1257 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1258 (or (plist-get attr
:width
) 80)
1259 (or (plist-get attr
:height
) (org-count-lines code
))
1264 (defun org-html-bibliography ()
1265 "Find bibliography, cut it out and return it."
1267 (let (beg end
(cnt 1) bib
)
1269 (goto-char (point-min))
1270 (when (re-search-forward
1271 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1272 (setq beg
(match-beginning 0))
1273 (while (re-search-forward "</?div\\>" nil t
)
1274 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1276 (and (looking-at ">") (forward-char 1))
1277 (setq bib
(buffer-substring beg
(point)))
1278 (delete-region beg
(point))
1279 (throw 'exit bib
))))
1284 (defun org-html-splice-attributes (tag attributes
)
1285 "Return a HTML TAG edited wrt ATTRIBUTES."
1286 (if (not attributes
)
1288 (let (oldatt newatt
)
1289 (setq oldatt
(org-extract-attributes-from-string tag
)
1291 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1293 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1294 (if (string-match ">" tag
)
1296 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1300 (defun org-export-splice-style (style extra
)
1301 "Return STYLE updated wrt EXTRA."
1302 (if (and (stringp extra
)
1303 (string-match "\\S-" extra
)
1304 (string-match "</style>" style
))
1305 (concat (substring style
0 (match-beginning 0))
1307 (substring style
(match-beginning 0)))
1310 (defun org-html-htmlize-region-for-paste (beg end
)
1311 "Convert the region between BEG and END to HTML, using htmlize.el.
1312 This is much like `htmlize-region-for-paste', only that it uses
1313 the settings define in the org-... variables."
1314 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1315 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1316 (htmlbuf (htmlize-region beg end
)))
1318 (with-current-buffer htmlbuf
1319 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1320 (plist-get htmlize-buffer-places
'content-end
)))
1321 (kill-buffer htmlbuf
))))
1324 (defun org-html-htmlize-generate-css ()
1325 "Create the CSS for all font definitions in the current Emacs session.
1326 Use this to create face definitions in your CSS style file that can then
1327 be used by code snippets transformed by htmlize.
1328 This command just produces a buffer that contains class definitions for all
1329 faces used in the current Emacs session. You can copy and paste the ones you
1330 need into your CSS file.
1332 If you then set `org-html-htmlize-output-type' to `css', calls
1333 to the function `org-html-htmlize-region-for-paste' will
1334 produce code that uses these same face definitions."
1337 (and (get-buffer "*html*") (kill-buffer "*html*"))
1339 (let ((fl (face-list))
1340 (htmlize-css-name-prefix "org-")
1341 (htmlize-output-type 'css
)
1343 (while (setq f
(pop fl
)
1344 i
(and f
(face-attribute f
:inherit
)))
1345 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1346 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1347 (htmlize-region (point-min) (point-max))))
1348 (org-pop-to-buffer-same-window "*html*")
1349 (goto-char (point-min))
1350 (if (re-search-forward "<style" nil t
)
1351 (delete-region (point-min) (match-beginning 0)))
1352 (if (re-search-forward "</style>" nil t
)
1353 (delete-region (1+ (match-end 0)) (point-max)))
1354 (beginning-of-line 1)
1355 (if (looking-at " +") (replace-match ""))
1356 (goto-char (point-min)))
1358 (defun org-html--make-string (n string
)
1359 "Build a string by concatenating N times STRING."
1360 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1362 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1363 "Turn todo keyword KWD into a valid class name.
1364 Replaces invalid characters with \"_\"."
1366 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1367 (setq kwd
(replace-match "_" t t kwd
))))
1370 (defun org-html-format-footnote-reference (n def refcnt
)
1371 "Format footnote reference N with definition DEF into HTML."
1372 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1373 (format org-html-footnote-format
1374 (let* ((id (format "fnr.%s%s" n extra
))
1375 (href (format " href=\"#fn.%s\"" n
))
1376 (attributes (concat " class=\"footref\"" href
)))
1377 (org-html--anchor id n attributes
)))))
1379 (defun org-html-format-footnotes-section (section-name definitions
)
1380 "Format footnotes section SECTION-NAME."
1381 (if (not definitions
) ""
1382 (format org-html-footnotes-section section-name definitions
)))
1384 (defun org-html-format-footnote-definition (fn)
1385 "Format the footnote definition FN."
1386 (let ((n (car fn
)) (def (cdr fn
)))
1388 "<div class=\"footdef\">%s %s</div>\n"
1389 (format org-html-footnote-format
1390 (let* ((id (format "fn.%s" n
))
1391 (href (format " href=\"#fnr.%s\"" n
))
1392 (attributes (concat " class=\"footnum\"" href
)))
1393 (org-html--anchor id n attributes
)))
1396 (defun org-html-footnote-section (info)
1397 "Format the footnote section.
1398 INFO is a plist used as a communication channel."
1399 (let* ((fn-alist (org-export-collect-footnote-definitions
1400 (plist-get info
:parse-tree
) info
))
1402 (loop for
(n type raw
) in fn-alist collect
1403 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1404 (org-trim (org-export-data raw info
))
1406 (org-trim (org-export-data raw info
))))))))
1408 (org-html-format-footnotes-section
1409 (org-html--translate "Footnotes" info
)
1412 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1417 (defun org-html--build-meta-info (info)
1418 "Return meta tags for exported document.
1419 INFO is a plist used as a communication channel."
1420 (let* ((title (org-export-data (plist-get info
:title
) info
))
1421 (author (and (plist-get info
:with-author
)
1422 (let ((auth (plist-get info
:author
)))
1423 (and auth
(org-export-data auth info
)))))
1424 (description (plist-get info
:description
))
1425 (keywords (plist-get info
:keywords
)))
1427 (format "<title>%s</title>\n" title
)
1429 (when :time-stamp-file
1431 (concat "<!-- " org-html--timestamp-format
" -->\n"))))
1433 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1434 (or (and org-html-coding-system
1435 (fboundp 'coding-system-get
)
1436 (coding-system-get org-html-coding-system
'mime-charset
))
1438 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1439 (and author
(format "<meta name=\"author\" content=\"%s\"/>\n" author
))
1441 (format "<meta name=\"description\" content=\"%s\"/>\n" description
))
1443 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords
)))))
1445 (defun org-html--build-head (info)
1446 "Return information for the <head>..</head> of the HTML output.
1447 INFO is a plist used as a communication channel."
1448 (org-element-normalize-string
1450 (when (plist-get info
:html-head-include-default-style
)
1451 (org-element-normalize-string org-html-style-default
))
1452 (org-element-normalize-string (plist-get info
:html-head
))
1453 (org-element-normalize-string (plist-get info
:html-head-extra
))
1454 (when (and (plist-get info
:html-htmlized-css-url
)
1455 (eq org-html-htmlize-output-type
'css
))
1456 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1457 (plist-get info
:html-htmlized-css-url
)))
1458 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1460 (defun org-html--build-mathjax-config (info)
1461 "Insert the user setup into the mathjax template.
1462 INFO is a plist used as a communication channel."
1463 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1464 (org-element-map (plist-get info
:parse-tree
)
1465 '(latex-fragment latex-environment
) 'identity info t
))
1466 (let ((template org-html-mathjax-template
)
1467 (options org-html-mathjax-options
)
1468 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1469 name val
(yes " ") (no "// ") x
)
1472 (setq name
(car e
) val
(nth 1 e
))
1473 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1474 (setq val
(car (read-from-string
1475 (substring in-buffer
(match-end 0))))))
1476 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1477 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1478 (setq template
(replace-match val t t template
))))
1480 (setq val
(nth 1 (assq 'mathml options
)))
1481 (if (string-match (concat "\\<mathml:") in-buffer
)
1482 (setq val
(car (read-from-string
1483 (substring in-buffer
(match-end 0))))))
1484 ;; Exchange prefixes depending on mathml setting.
1485 (if (not val
) (setq x yes yes no no x
))
1486 ;; Replace cookies to turn on or off the config/jax lines.
1487 (if (string-match ":MMLYES:" template
)
1488 (setq template
(replace-match yes t t template
)))
1489 (if (string-match ":MMLNO:" template
)
1490 (setq template
(replace-match no t t template
)))
1491 ;; Return the modified template.
1492 (org-element-normalize-string template
))))
1494 (defun org-html-format-spec (info)
1495 "Return format specification for elements that can be
1496 used in the preamble or postamble."
1497 `((?t .
,(org-export-data (plist-get info
:title
) info
))
1498 (?d .
,(org-export-data (plist-get info
:date
) info
))
1499 (?T .
,(format-time-string org-html--timestamp-format
))
1500 (?a .
,(org-export-data (plist-get info
:author
) info
))
1503 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1504 (split-string (plist-get info
:email
) ",+ *")
1506 (?c .
,(plist-get info
:creator
))
1507 (?v .
,(or org-html-validation-link
""))))
1509 (defun org-html--build-pre/postamble
(type info
)
1510 "Return document preamble or postamble as a string, or nil.
1511 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1512 communication channel."
1513 (let ((section (plist-get info
(intern (format ":html-%s" type
))))
1514 (spec (org-html-format-spec info
)))
1516 (let ((section-contents
1517 (if (functionp section
) (funcall section info
)
1519 ((stringp section
) (format-spec section spec
))
1521 (let ((date (cdr (assq ?d spec
)))
1522 (author (cdr (assq ?a spec
)))
1523 (email (cdr (assq ?e spec
)))
1524 (creator (cdr (assq ?c spec
)))
1525 (timestamp (cdr (assq ?T spec
)))
1526 (validation-link (cdr (assq ?v spec
))))
1528 (when (and (plist-get info
:with-date
)
1529 (org-string-nw-p date
))
1530 (format "<p class=\"date\">%s: %s</p>\n"
1531 (org-html--translate "Date" info
)
1533 (when (and (plist-get info
:with-author
)
1534 (org-string-nw-p author
))
1535 (format "<p class=\"author\">%s: %s</p>\n"
1536 (org-html--translate "Author" info
)
1538 (when (and (plist-get info
:with-email
)
1539 (org-string-nw-p email
))
1540 (format "<p class=\"email\">%s: %s</p>\n"
1541 (org-html--translate "Email" info
)
1543 (when (plist-get info
:time-stamp-file
)
1545 "<p class=\"date\">%s: %s</p>\n"
1546 (org-html--translate "Created" info
)
1547 (format-time-string org-html--timestamp-format
)))
1548 (when (plist-get info
:with-creator
)
1549 (format "<p class=\"creator\">%s</p>\n"
1551 (format "<p class=\"xhtml-validation\">%s</p>\n"
1555 (plist-get info
:language
)
1557 (format "org-html-%s-format" type
)))))
1562 (intern (format "org-html-%s-format" type
))))))
1564 (when (org-string-nw-p section-contents
)
1566 (format "<%s id=\"%s\" class=\"%s\">\n"
1567 (nth 1 (assq type org-html-divs
))
1568 (nth 2 (assq type org-html-divs
))
1569 org-html--pre
/postamble-class
)
1570 (org-element-normalize-string section-contents
)
1571 (format "</%s>\n" (nth 1 (assq type org-html-divs
)))))))))
1573 (defun org-html-inner-template (contents info
)
1574 "Return body of document string after HTML conversion.
1575 CONTENTS is the transcoded contents string. INFO is a plist
1576 holding export options."
1578 ;; Table of contents.
1579 (let ((depth (plist-get info
:with-toc
)))
1580 (when depth
(org-html-toc depth info
)))
1581 ;; Document contents.
1583 ;; Footnotes section.
1584 (org-html-footnote-section info
)
1586 (org-html-bibliography)))
1588 (defun org-html-template (contents info
)
1589 "Return complete document string after HTML conversion.
1590 CONTENTS is the transcoded contents string. INFO is a plist
1591 holding export options."
1594 (or (and (stringp org-html-xml-declaration
)
1595 org-html-xml-declaration
)
1596 (cdr (assoc (plist-get info
:html-extension
)
1597 org-html-xml-declaration
))
1598 (cdr (assoc "html" org-html-xml-declaration
))
1601 (or (and org-html-coding-system
1602 (fboundp 'coding-system-get
)
1603 (coding-system-get org-html-coding-system
'mime-charset
))
1606 (plist-get info
:html-doctype
)
1608 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1609 (plist-get info
:language
) (plist-get info
:language
))
1611 (org-html--build-meta-info info
)
1612 (org-html--build-head info
)
1613 (org-html--build-mathjax-config info
)
1616 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1617 (link-home (org-trim (plist-get info
:html-link-home
))))
1618 (unless (and (string= link-up
"") (string= link-up
""))
1619 (format org-html-home
/up-format
1620 (or link-up link-home
)
1621 (or link-home link-up
))))
1623 (org-html--build-pre/postamble
'preamble info
)
1624 ;; Document contents.
1625 (format "<%s id=\"%s\">\n"
1626 (nth 1 (assq 'content org-html-divs
))
1627 (nth 2 (assq 'content org-html-divs
)))
1629 (let ((title (plist-get info
:title
)))
1630 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1633 (nth 1 (assq 'content org-html-divs
)))
1635 (org-html--build-pre/postamble
'postamble info
)
1636 ;; Closing document.
1637 "</body>\n</html>"))
1639 (defun org-html--translate (s info
)
1640 "Translate string S according to specified language.
1641 INFO is a plist used as a communication channel."
1642 (org-export-translate s
:html info
))
1646 (defun org-html--anchor (&optional id desc attributes
)
1647 "Format a HTML anchor."
1648 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1649 (attributes (concat (and id
(format " id=\"%s\"" id
))
1650 (and name
(format " name=\"%s\"" name
))
1652 (format "<a%s>%s</a>" attributes
(or desc
""))))
1656 (defun org-html--todo (todo)
1657 "Format TODO keywords into HTML."
1659 (format "<span class=\"%s %s%s\">%s</span>"
1660 (if (member todo org-done-keywords
) "done" "todo")
1661 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1666 (defun org-html--tags (tags)
1667 "Format TAGS into HTML."
1669 (format "<span class=\"tag\">%s</span>"
1672 (format "<span class=\"%s\">%s</span>"
1673 (concat org-html-tag-class-prefix
1674 (org-html-fix-class-name tag
))
1680 (defun* org-html-format-headline
1681 (todo todo-type priority text tags
1682 &key level section-number headline-label
&allow-other-keys
)
1683 "Format a headline in HTML."
1684 (let ((section-number
1685 (when section-number
1686 (format "<span class=\"section-number-%d\">%s</span> "
1687 level section-number
)))
1688 (todo (org-html--todo todo
))
1689 (tags (org-html--tags tags
)))
1690 (concat section-number todo
(and todo
" ") text
1691 (and tags
"   ") tags
)))
1695 (defun org-html-fontify-code (code lang
)
1696 "Color CODE with htmlize library.
1697 CODE is a string representing the source code to colorize. LANG
1698 is the language used for CODE, as a string, or nil."
1701 ;; Case 1: No lang. Possibly an example block.
1703 ;; Simple transcoding.
1704 (org-html-encode-plain-text code
))
1705 ;; Case 2: No htmlize or an inferior version of htmlize
1706 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1708 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1709 ;; Simple transcoding.
1710 (org-html-encode-plain-text code
))
1713 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1714 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1716 ;; Case 1: Language is not associated with any Emacs mode
1717 ((not (functionp lang-mode
))
1718 ;; Simple transcoding.
1719 (org-html-encode-plain-text code
))
1720 ;; Case 2: Default. Fontify code.
1723 (setq code
(with-temp-buffer
1724 ;; Switch to language-specific mode.
1728 (font-lock-fontify-buffer)
1729 ;; Remove formatting on newline characters.
1731 (let ((beg (point-min))
1734 (while (progn (end-of-line) (< (point) end
))
1735 (put-text-property (point) (1+ (point)) 'face nil
)
1738 (set-buffer-modified-p nil
)
1740 (org-html-htmlize-region-for-paste
1741 (point-min) (point-max))))
1742 ;; Strip any enclosing <pre></pre> tags.
1743 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1744 (end (and beg
(string-match "</pre>\\'" code
))))
1745 (if (and beg end
) (substring code beg end
) code
)))))))))
1747 (defun org-html-do-format-code
1748 (code &optional lang refs retain-labels num-start
)
1749 "Format CODE string as source code.
1750 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1751 respectively, the language of the source code, as a string, an
1752 alist between line numbers and references (as returned by
1753 `org-export-unravel-code'), a boolean specifying if labels should
1754 appear in the source code, and the number associated to the first
1756 (let* ((code-lines (org-split-string code
"\n"))
1757 (code-length (length code-lines
))
1761 (length (number-to-string (+ code-length num-start
))))))
1762 (code (org-html-fontify-code code lang
)))
1763 (org-export-format-code
1765 (lambda (loc line-num ref
)
1768 ;; Add line number, if needed.
1770 (format "<span class=\"linenr\">%s</span>"
1771 (format num-fmt line-num
)))
1772 ;; Transcoded src line.
1774 ;; Add label, if needed.
1775 (when (and ref retain-labels
) (format " (%s)" ref
))))
1776 ;; Mark transcoded line as an anchor, if needed.
1778 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1782 (defun org-html-format-code (element info
)
1783 "Format contents of ELEMENT as source code.
1784 ELEMENT is either an example block or a src block. INFO is
1785 a plist used as a communication channel."
1786 (let* ((lang (org-element-property :language element
))
1787 ;; Extract code and references.
1788 (code-info (org-export-unravel-code element
))
1789 (code (car code-info
))
1790 (refs (cdr code-info
))
1791 ;; Does the src block contain labels?
1792 (retain-labels (org-element-property :retain-labels element
))
1793 ;; Does it have line numbers?
1794 (num-start (case (org-element-property :number-lines element
)
1795 (continued (org-export-get-loc element info
))
1797 (org-html-do-format-code code lang refs retain-labels num-start
)))
1800 ;;; Tables of Contents
1802 (defun org-html-toc (depth info
)
1803 "Build a table of contents.
1804 DEPTH is an integer specifying the depth of the table. INFO is a
1805 plist used as a communication channel. Return the table of
1806 contents as a string, or nil if it is empty."
1808 (mapcar (lambda (headline)
1809 (cons (org-html--format-toc-headline headline info
)
1810 (org-export-get-relative-level headline info
)))
1811 (org-export-collect-headlines info depth
))))
1813 (concat "<div id=\"table-of-contents\">\n"
1814 (format "<h%d>%s</h%d>\n"
1815 org-html-toplevel-hlevel
1816 (org-html--translate "Table of Contents" info
)
1817 org-html-toplevel-hlevel
)
1818 "<div id=\"text-table-of-contents\">"
1819 (org-html--toc-text toc-entries
)
1823 (defun org-html--toc-text (toc-entries)
1824 "Return innards of a table of contents, as a string.
1825 TOC-ENTRIES is an alist where key is an entry title, as a string,
1826 and value is its relative level, as an integer."
1827 (let* ((prev-level (1- (cdar toc-entries
)))
1828 (start-level prev-level
))
1832 (let ((headline (car entry
))
1833 (level (cdr entry
)))
1835 (let* ((cnt (- level prev-level
))
1836 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1838 (setq prev-level level
)
1840 (org-html--make-string
1841 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1842 ((< cnt
0) "</li>\n</ul>\n")))
1843 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1846 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1848 (defun org-html--format-toc-headline (headline info
)
1849 "Return an appropriate table of contents entry for HEADLINE.
1850 INFO is a plist used as a communication channel."
1851 (let* ((headline-number (org-export-get-headline-number headline info
))
1853 (and (not (org-export-low-level-p headline info
))
1854 (org-export-numbered-headline-p headline info
)
1855 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1856 (tags (and (eq (plist-get info
:with-tags
) t
)
1857 (org-export-get-tags headline info
))))
1858 (format "<a href=\"#%s\">%s</a>"
1860 (org-export-solidify-link-text
1861 (or (org-element-property :CUSTOM_ID headline
)
1862 (concat "sec-" (mapconcat 'number-to-string
1863 headline-number
"-"))))
1865 (concat section-number
1866 (org-export-data-with-translations
1867 (org-export-get-alt-title headline info
)
1868 ;; Ignore any footnote-reference, link,
1869 ;; radio-target and target in table of contents.
1871 '((footnote-reference . ignore
)
1872 (link .
(lambda (link desc i
) desc
))
1873 (radio-target .
(lambda (radio desc i
) desc
))
1875 (org-export-backend-translate-table 'html
))
1877 (and tags
"   ") (org-html--tags tags
)))))
1879 (defun org-html-list-of-listings (info)
1880 "Build a list of listings.
1881 INFO is a plist used as a communication channel. Return the list
1882 of listings as a string, or nil if it is empty."
1883 (let ((lol-entries (org-export-collect-listings info
)))
1885 (concat "<div id=\"list-of-listings\">\n"
1886 (format "<h%d>%s</h%d>\n"
1887 org-html-toplevel-hlevel
1888 (org-html--translate "List of Listings" info
)
1889 org-html-toplevel-hlevel
)
1890 "<div id=\"text-list-of-listings\">\n<ul>\n"
1892 (initial-fmt (org-html--translate "Listing %d:" info
)))
1895 (let ((label (org-element-property :name entry
))
1898 (or (org-export-get-caption entry t
)
1899 (org-export-get-caption entry
))
1904 (concat (format initial-fmt
(incf count
)) " " title
)
1905 (format "<a href=\"#%s\">%s %s</a>"
1906 (org-export-solidify-link-text label
)
1907 (format initial-fmt
(incf count
))
1911 "\n</ul>\n</div>\n</div>"))))
1913 (defun org-html-list-of-tables (info)
1914 "Build a list of tables.
1915 INFO is a plist used as a communication channel. Return the list
1916 of tables as a string, or nil if it is empty."
1917 (let ((lol-entries (org-export-collect-tables info
)))
1919 (concat "<div id=\"list-of-tables\">\n"
1920 (format "<h%d>%s</h%d>\n"
1921 org-html-toplevel-hlevel
1922 (org-html--translate "List of Tables" info
)
1923 org-html-toplevel-hlevel
)
1924 "<div id=\"text-list-of-tables\">\n<ul>\n"
1926 (initial-fmt (org-html--translate "Table %d:" info
)))
1929 (let ((label (org-element-property :name entry
))
1932 (or (org-export-get-caption entry t
)
1933 (org-export-get-caption entry
))
1938 (concat (format initial-fmt
(incf count
)) " " title
)
1939 (format "<a href=\"#%s\">%s %s</a>"
1940 (org-export-solidify-link-text label
)
1941 (format initial-fmt
(incf count
))
1945 "\n</ul>\n</div>\n</div>"))))
1948 ;;; Transcode Functions
1952 (defun org-html-bold (bold contents info
)
1953 "Transcode BOLD from Org to HTML.
1954 CONTENTS is the text with bold markup. INFO is a plist holding
1955 contextual information."
1956 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1961 (defun org-html-center-block (center-block contents info
)
1962 "Transcode a CENTER-BLOCK element from Org to HTML.
1963 CONTENTS holds the contents of the block. INFO is a plist
1964 holding contextual information."
1965 (format "<div class=\"center\">\n%s</div>" contents
))
1969 (defun org-html-clock (clock contents info
)
1970 "Transcode a CLOCK element from Org to HTML.
1971 CONTENTS is nil. INFO is a plist used as a communication
1974 <span class=\"timestamp-wrapper\">
1975 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1980 (org-element-property :raw-value
1981 (org-element-property :value clock
)))
1982 (let ((time (org-element-property :duration clock
)))
1983 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1987 (defun org-html-code (code contents info
)
1988 "Transcode CODE from Org to HTML.
1989 CONTENTS is nil. INFO is a plist holding contextual
1991 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
1992 (org-html-plain-text (org-element-property :value code
) info
)))
1996 (defun org-html-drawer (drawer contents info
)
1997 "Transcode a DRAWER element from Org to HTML.
1998 CONTENTS holds the contents of the block. INFO is a plist
1999 holding contextual information."
2000 (if (functionp org-html-format-drawer-function
)
2001 (funcall org-html-format-drawer-function
2002 (org-element-property :drawer-name drawer
)
2004 ;; If there's no user defined function: simply
2005 ;; display contents of the drawer.
2010 (defun org-html-dynamic-block (dynamic-block contents info
)
2011 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2012 CONTENTS holds the contents of the block. INFO is a plist
2013 holding contextual information. See `org-export-data'."
2018 (defun org-html-entity (entity contents info
)
2019 "Transcode an ENTITY object from Org to HTML.
2020 CONTENTS are the definition itself. INFO is a plist holding
2021 contextual information."
2022 (org-element-property :html entity
))
2026 (defun org-html-example-block (example-block contents info
)
2027 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2028 CONTENTS is nil. INFO is a plist holding contextual
2030 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2031 (org-html--textarea-block example-block
)
2032 (format "<pre class=\"example\">\n%s</pre>"
2033 (org-html-format-code example-block info
))))
2037 (defun org-html-export-snippet (export-snippet contents info
)
2038 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2039 CONTENTS is nil. INFO is a plist holding contextual
2041 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2042 (org-element-property :value export-snippet
)))
2046 (defun org-html-export-block (export-block contents info
)
2047 "Transcode a EXPORT-BLOCK element from Org to HTML.
2048 CONTENTS is nil. INFO is a plist holding contextual information."
2049 (when (string= (org-element-property :type export-block
) "HTML")
2050 (org-remove-indentation (org-element-property :value export-block
))))
2054 (defun org-html-fixed-width (fixed-width contents info
)
2055 "Transcode a FIXED-WIDTH element from Org to HTML.
2056 CONTENTS is nil. INFO is a plist holding contextual information."
2057 (format "<pre class=\"example\">\n%s</pre>"
2058 (org-html-do-format-code
2059 (org-remove-indentation
2060 (org-element-property :value fixed-width
)))))
2062 ;;;; Footnote Reference
2064 (defun org-html-footnote-reference (footnote-reference contents info
)
2065 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2066 CONTENTS is nil. INFO is a plist holding contextual information."
2068 ;; Insert separator between two footnotes in a row.
2069 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2070 (when (eq (org-element-type prev
) 'footnote-reference
)
2071 org-html-footnote-separator
))
2073 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2074 (org-html-format-footnote-reference
2075 (org-export-get-footnote-number footnote-reference info
)
2077 ;; Inline definitions are secondary strings.
2078 ((eq (org-element-property :type footnote-reference
) 'inline
)
2079 (org-html-format-footnote-reference
2080 (org-export-get-footnote-number footnote-reference info
)
2082 ;; Non-inline footnotes definitions are full Org data.
2083 (t (org-html-format-footnote-reference
2084 (org-export-get-footnote-number footnote-reference info
)
2089 (defun org-html-format-headline--wrap
2090 (headline info
&optional format-function
&rest extra-keys
)
2091 "Transcode a HEADLINE element from Org to HTML.
2092 CONTENTS holds the contents of the headline. INFO is a plist
2093 holding contextual information."
2094 (let* ((level (+ (org-export-get-relative-level headline info
)
2095 (1- org-html-toplevel-hlevel
)))
2096 (headline-number (org-export-get-headline-number headline info
))
2097 (section-number (and (not (org-export-low-level-p headline info
))
2098 (org-export-numbered-headline-p headline info
)
2099 (mapconcat 'number-to-string
2100 headline-number
".")))
2101 (todo (and (plist-get info
:with-todo-keywords
)
2102 (let ((todo (org-element-property :todo-keyword headline
)))
2103 (and todo
(org-export-data todo info
)))))
2104 (todo-type (and todo
(org-element-property :todo-type headline
)))
2105 (priority (and (plist-get info
:with-priority
)
2106 (org-element-property :priority headline
)))
2107 (text (org-export-data (org-element-property :title headline
) info
))
2108 (tags (and (plist-get info
:with-tags
)
2109 (org-export-get-tags headline info
)))
2110 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2111 (concat "sec-" (mapconcat 'number-to-string
2112 headline-number
"-"))))
2113 (format-function (cond
2114 ((functionp format-function
) format-function
)
2115 ((functionp org-html-format-headline-function
)
2117 (lambda (todo todo-type priority text tags
2119 (funcall org-html-format-headline-function
2120 todo todo-type priority text tags
))))
2121 (t 'org-html-format-headline
))))
2122 (apply format-function
2123 todo todo-type priority text tags
2124 :headline-label headline-label
:level level
2125 :section-number section-number extra-keys
)))
2127 (defun org-html-headline (headline contents info
)
2128 "Transcode a HEADLINE element from Org to HTML.
2129 CONTENTS holds the contents of the headline. INFO is a plist
2130 holding contextual information."
2132 (setq contents
(or contents
""))
2133 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2134 (level (org-export-get-relative-level headline info
))
2135 (text (org-export-data (org-element-property :title headline
) info
))
2136 (todo (and (plist-get info
:with-todo-keywords
)
2137 (let ((todo (org-element-property :todo-keyword headline
)))
2138 (and todo
(org-export-data todo info
)))))
2139 (todo-type (and todo
(org-element-property :todo-type headline
)))
2140 (tags (and (plist-get info
:with-tags
)
2141 (org-export-get-tags headline info
)))
2142 (priority (and (plist-get info
:with-priority
)
2143 (org-element-property :priority headline
)))
2144 (section-number (and (org-export-numbered-headline-p headline info
)
2145 (mapconcat 'number-to-string
2146 (org-export-get-headline-number
2147 headline info
) ".")))
2148 ;; Create the headline text.
2149 (full-text (org-html-format-headline--wrap headline info
)))
2151 ;; Case 1: This is a footnote section: ignore it.
2152 ((org-element-property :footnote-section-p headline
) nil
)
2153 ;; Case 2. This is a deep sub-tree: export it as a list item.
2154 ;; Also export as items headlines for which no section
2155 ;; format has been found.
2156 ((org-export-low-level-p headline info
)
2157 ;; Build the real contents of the sub-tree.
2158 (let* ((type (if numberedp
'ordered
'unordered
))
2159 (itemized-body (org-html-format-list-item
2160 contents type nil nil full-text
)))
2162 (and (org-export-first-sibling-p headline info
)
2163 (org-html-begin-plain-list type
))
2165 (and (org-export-last-sibling-p headline info
)
2166 (org-html-end-plain-list type
)))))
2167 ;; Case 3. Standard headline. Export it as a section.
2169 (let* ((section-number (mapconcat 'number-to-string
2170 (org-export-get-headline-number
2171 headline info
) "-"))
2173 (list (org-element-property :CUSTOM_ID headline
)
2174 (concat "sec-" section-number
)
2175 (org-element-property :ID headline
))))
2176 (preferred-id (car ids
))
2177 (extra-ids (cdr ids
))
2178 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2179 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2180 (first-content (car (org-element-contents headline
))))
2181 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2182 (if (= 1 (org-export-get-relative-level headline info
))
2183 (plist-get info
:html-container
)
2185 (format "outline-container-%s"
2186 (or (org-element-property :CUSTOM_ID headline
)
2188 (concat (format "outline-%d" level1
) (and extra-class
" ")
2190 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2195 (let ((id (org-export-solidify-link-text
2196 (if (org-uuidgen-p x
) (concat "ID-" x
)
2198 (org-html--anchor id
)))
2202 ;; When there is no section, pretend there is an empty
2203 ;; one to get the correct <div class="outline- ...>
2204 ;; which is needed by `org-info.js'.
2205 (if (not (eq (org-element-type first-content
) 'section
))
2206 (concat (org-html-section first-content
"" info
)
2209 (if (= 1 (org-export-get-relative-level headline info
))
2210 (plist-get info
:html-container
)
2213 ;;;; Horizontal Rule
2215 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2216 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2217 CONTENTS is nil. INFO is a plist holding contextual information."
2220 ;;;; Inline Src Block
2222 (defun org-html-inline-src-block (inline-src-block contents info
)
2223 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2224 CONTENTS holds the contents of the item. INFO is a plist holding
2225 contextual information."
2226 (let* ((org-lang (org-element-property :language inline-src-block
))
2227 (code (org-element-property :value inline-src-block
)))
2228 (error "Cannot export inline src block")))
2232 (defun org-html-format-section (text class
&optional id
)
2233 "Format a section with TEXT into a HTML div with CLASS and ID."
2234 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2235 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2237 (defun org-html-inlinetask (inlinetask contents info
)
2238 "Transcode an INLINETASK element from Org to HTML.
2239 CONTENTS holds the contents of the block. INFO is a plist
2240 holding contextual information."
2242 ;; If `org-html-format-inlinetask-function' is provided, call it
2243 ;; with appropriate arguments.
2244 ((functionp org-html-format-inlinetask-function
)
2245 (let ((format-function
2247 (lambda (todo todo-type priority text tags
2248 &key contents
&allow-other-keys
)
2249 (funcall org-html-format-inlinetask-function
2250 todo todo-type priority text tags contents
)))))
2251 (org-html-format-headline--wrap
2252 inlinetask info format-function
:contents contents
)))
2253 ;; Otherwise, use a default template.
2254 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2255 (org-html-format-headline--wrap inlinetask info
)
2260 (defun org-html-italic (italic contents info
)
2261 "Transcode ITALIC from Org to HTML.
2262 CONTENTS is the text with italic markup. INFO is a plist holding
2263 contextual information."
2264 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2268 (defun org-html-checkbox (checkbox)
2269 "Format CHECKBOX into HTML."
2270 (case checkbox
(on "<code>[X]</code>")
2271 (off "<code>[ ]</code>")
2272 (trans "<code>[-]</code>")
2275 (defun org-html-format-list-item (contents type checkbox
2276 &optional term-counter-id
2278 "Format a list item into HTML."
2279 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2283 (let* ((counter term-counter-id
)
2284 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2286 (format "<li%s>" extra
)
2287 (when headline
(concat headline
"<br/>")))))
2289 (let* ((id term-counter-id
)
2290 (extra (if id
(format " id=\"%s\"" id
) "")))
2292 (format "<li%s>" extra
)
2293 (when headline
(concat headline
"<br/>")))))
2295 (let* ((term term-counter-id
))
2296 (setq term
(or term
"(no term)"))
2297 ;; Check-boxes in descriptive lists are associated to tag.
2298 (concat (format "<dt> %s </dt>"
2299 (concat checkbox term
))
2301 (unless (eq type
'descriptive
) checkbox
)
2306 (descriptive "</dd>")))))
2308 (defun org-html-item (item contents info
)
2309 "Transcode an ITEM element from Org to HTML.
2310 CONTENTS holds the contents of the item. INFO is a plist holding
2311 contextual information."
2312 (let* ((plain-list (org-export-get-parent item
))
2313 (type (org-element-property :type plain-list
))
2314 (counter (org-element-property :counter item
))
2315 (checkbox (org-element-property :checkbox item
))
2316 (tag (let ((tag (org-element-property :tag item
)))
2317 (and tag
(org-export-data tag info
)))))
2318 (org-html-format-list-item
2319 contents type checkbox
(or tag counter
))))
2323 (defun org-html-keyword (keyword contents info
)
2324 "Transcode a KEYWORD element from Org to HTML.
2325 CONTENTS is nil. INFO is a plist holding contextual information."
2326 (let ((key (org-element-property :key keyword
))
2327 (value (org-element-property :value keyword
)))
2329 ((string= key
"HTML") value
)
2330 ;; Invisible targets.
2331 ((string= key
"TARGET") nil
)
2332 ((string= key
"TOC")
2333 (let ((value (downcase value
)))
2335 ((string-match "\\<headlines\\>" value
)
2336 (let ((depth (or (and (string-match "[0-9]+" value
)
2337 (string-to-number (match-string 0 value
)))
2338 (plist-get info
:with-toc
))))
2339 (org-html-toc depth info
)))
2340 ((string= "listings" value
) (org-html-list-of-listings info
))
2341 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2343 ;;;; Latex Environment
2345 (defun org-html-format-latex (latex-frag processing-type
)
2346 "Format the LaTeX fragment LATEX-FRAG into HTML."
2347 (let ((cache-relpath "") (cache-dir "") bfn
)
2348 (unless (eq processing-type
'mathjax
)
2349 (setq bfn
(buffer-file-name)
2352 (file-name-sans-extension
2353 (file-name-nondirectory bfn
)))
2354 cache-dir
(file-name-directory bfn
)))
2357 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2358 nil nil processing-type
)
2361 (defun org-html-latex-environment (latex-environment contents info
)
2362 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2363 CONTENTS is nil. INFO is a plist holding contextual information."
2364 (let ((processing-type (plist-get info
:with-latex
))
2365 (latex-frag (org-remove-indentation
2366 (org-element-property :value latex-environment
)))
2367 (caption (org-export-data
2368 (org-export-get-caption latex-environment
) info
))
2370 (label (org-element-property :name latex-environment
)))
2372 ((memq processing-type
'(t mathjax
))
2373 (org-html-format-latex latex-frag
'mathjax
))
2374 ((eq processing-type
'dvipng
)
2375 (let* ((formula-link (org-html-format-latex
2376 latex-frag processing-type
)))
2377 (when (and formula-link
2378 (string-match "file:\\([^]]*\\)" formula-link
))
2379 (org-html-format-inline-image
2380 (match-string 1 formula-link
) caption label attr t
))))
2385 (defun org-html-latex-fragment (latex-fragment contents info
)
2386 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2387 CONTENTS is nil. INFO is a plist holding contextual information."
2388 (let ((latex-frag (org-element-property :value latex-fragment
))
2389 (processing-type (plist-get info
:with-latex
)))
2390 (case processing-type
2392 (org-html-format-latex latex-frag
'mathjax
))
2394 (let* ((formula-link (org-html-format-latex
2395 latex-frag processing-type
)))
2396 (when (and formula-link
2397 (string-match "file:\\([^]]*\\)" formula-link
))
2398 (org-html-format-inline-image
2399 (match-string 1 formula-link
)))))
2404 (defun org-html-line-break (line-break contents info
)
2405 "Transcode a LINE-BREAK object from Org to HTML.
2406 CONTENTS is nil. INFO is a plist holding contextual information."
2411 (defun org-html-link--inline-image (link desc info
)
2412 "Return HTML code for an inline image.
2413 LINK is the link pointing to the inline image. INFO is a plist
2414 used as a communication channel."
2415 (let* ((type (org-element-property :type link
))
2416 (raw-path (org-element-property :path link
))
2417 (path (cond ((member type
'("http" "https"))
2418 (concat type
":" raw-path
))
2419 ((file-name-absolute-p raw-path
)
2420 (expand-file-name raw-path
))
2422 (parent (org-export-get-parent-element link
))
2423 (caption (org-export-data (org-export-get-caption parent
) info
))
2424 (label (org-element-property :name parent
))
2425 (attr (mapconcat #'identity
(org-element-property :attr_html parent
) " ")))
2426 ;; Return proper string, depending on DISPOSITION.
2427 (org-html-format-inline-image
2428 path caption label attr
(org-html-standalone-image-p link info
))))
2430 (defvar org-html-standalone-image-predicate
)
2431 (defun org-html-standalone-image-p (element info
&optional predicate
)
2432 "Test if ELEMENT is a standalone image for the purpose HTML export.
2433 INFO is a plist holding contextual information.
2435 Return non-nil, if ELEMENT is of type paragraph and it's sole
2436 content, save for whitespaces, is a link that qualifies as an
2439 Return non-nil, if ELEMENT is of type link and it's containing
2440 paragraph has no other content save for leading and trailing
2443 Return nil, otherwise.
2445 Bind `org-html-standalone-image-predicate' to constrain
2446 paragraph further. For example, to check for only captioned
2447 standalone images, do the following.
2449 \(setq org-html-standalone-image-predicate
2450 \(lambda \(paragraph\)
2451 \(org-element-property :caption paragraph\)\)\)"
2452 (let ((paragraph (case (org-element-type element
)
2454 (link (and (org-export-inline-image-p
2455 element org-html-inline-image-rules
)
2456 (org-export-get-parent element
)))
2458 (when (eq (org-element-type paragraph
) 'paragraph
)
2459 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2460 (functionp org-html-standalone-image-predicate
)))
2461 (funcall org-html-standalone-image-predicate paragraph
))
2462 (let ((contents (org-element-contents paragraph
)))
2463 (loop for x in contents
2464 with inline-image-count
= 0
2466 ((eq (org-element-type x
) 'plain-text
)
2467 (not (org-string-nw-p x
)))
2468 ((eq (org-element-type x
) 'link
)
2469 (when (org-export-inline-image-p
2470 x org-html-inline-image-rules
)
2471 (= (incf inline-image-count
) 1)))
2474 (defun org-html-link (link desc info
)
2475 "Transcode a LINK object from Org to HTML.
2477 DESC is the description part of the link, or the empty string.
2478 INFO is a plist holding contextual information. See
2480 (let* ((link-org-files-as-html-maybe
2482 (lambda (raw-path info
)
2483 "Treat links to `file.org' as links to `file.html', if needed.
2484 See `org-html-link-org-files-as-html'."
2486 ((and org-html-link-org-files-as-html
2488 (downcase (file-name-extension raw-path
"."))))
2489 (concat (file-name-sans-extension raw-path
) "."
2490 (plist-get info
:html-extension
)))
2492 (type (org-element-property :type link
))
2493 (raw-path (org-element-property :path link
))
2494 ;; Ensure DESC really exists, or set it to nil.
2495 (desc (and (not (string= desc
"")) desc
))
2498 ((member type
'("http" "https" "ftp" "mailto"))
2499 (concat type
":" raw-path
))
2500 ((string= type
"file")
2501 ;; Treat links to ".org" files as ".html", if needed.
2503 (funcall link-org-files-as-html-maybe raw-path info
))
2504 ;; If file path is absolute, prepend it with protocol
2505 ;; component - "file://".
2506 (when (file-name-absolute-p raw-path
)
2508 (concat "file://" (expand-file-name raw-path
))))
2509 ;; Add search option, if any. A search option can be
2510 ;; relative to a custom-id or a headline title. Any other
2511 ;; option is ignored.
2512 (let ((option (org-element-property :search-option link
)))
2513 (cond ((not option
) raw-path
)
2514 ((eq (aref option
0) ?
#) (concat raw-path option
))
2515 ;; External fuzzy link: try to resolve it if path
2516 ;; belongs to current project, if any.
2517 ((eq (aref option
0) ?
*)
2521 (org-publish-resolve-external-fuzzy-link
2522 (org-element-property :path link
) option
)))
2523 (and numbers
(concat "#sec-"
2524 (mapconcat 'number-to-string
2528 attributes protocol
)
2529 ;; Extract attributes from parent's paragraph. HACK: Only do this
2530 ;; for the first link in parent. This is needed as long as
2531 ;; attributes cannot be set on a per link basis.
2532 (and (setq attributes
2533 (let ((parent (org-export-get-parent-element link
)))
2534 (if (not (eq (org-element-map parent
'link
'identity info t
)
2539 (let ((att (org-element-property :attr_html parent
)))
2540 (unless (and desc att
2541 (string-match (regexp-quote (car att
)) desc
))
2544 (unless (string= attributes
"")
2545 (setq attributes
(concat " " attributes
))))
2548 ((and (or (eq t org-html-inline-images
)
2549 (and org-html-inline-images
(not desc
)))
2550 (org-export-inline-image-p link org-html-inline-image-rules
))
2551 (org-html-link--inline-image link desc info
))
2552 ;; Radio target: Transcode target's contents and use them as
2553 ;; link's description.
2554 ((string= type
"radio")
2555 (let ((destination (org-export-resolve-radio-link link info
)))
2557 (format "<a href=\"#%s\"%s>%s</a>"
2558 (org-export-solidify-link-text path
)
2560 (org-export-data (org-element-contents destination
) info
)))))
2561 ;; Links pointing to a headline: Find destination and build
2562 ;; appropriate referencing command.
2563 ((member type
'("custom-id" "fuzzy" "id"))
2564 (let ((destination (if (string= type
"fuzzy")
2565 (org-export-resolve-fuzzy-link link info
)
2566 (org-export-resolve-id-link link info
))))
2567 (case (org-element-type destination
)
2568 ;; ID link points to an external file.
2570 (let ((fragment (concat "ID-" path
))
2571 ;; Treat links to ".org" files as ".html", if needed.
2572 (path (funcall link-org-files-as-html-maybe
2574 (format "<a href=\"%s#%s\"%s>%s</a>"
2575 path fragment attributes
(or desc destination
))))
2576 ;; Fuzzy link points nowhere.
2581 (org-element-property :raw-link link
) info
))))
2582 ;; Fuzzy link points to an invisible target.
2584 ;; Link points to a headline.
2587 ;; What href to use?
2589 ;; Case 1: Headline is linked via it's CUSTOM_ID
2590 ;; property. Use CUSTOM_ID.
2591 ((string= type
"custom-id")
2592 (org-element-property :CUSTOM_ID destination
))
2593 ;; Case 2: Headline is linked via it's ID property
2594 ;; or through other means. Use the default href.
2595 ((member type
'("id" "fuzzy"))
2597 (mapconcat 'number-to-string
2598 (org-export-get-headline-number
2599 destination info
) "-")))
2600 (t (error "Shouldn't reach here"))))
2601 ;; What description to use?
2603 ;; Case 1: Headline is numbered and LINK has no
2604 ;; description or LINK's description matches
2605 ;; headline's title. Display section number.
2606 (if (and (org-export-numbered-headline-p destination info
)
2608 (string= desc
(org-element-property
2609 :raw-value destination
))))
2610 (mapconcat 'number-to-string
2611 (org-export-get-headline-number
2612 destination info
) ".")
2613 ;; Case 2: Either the headline is un-numbered or
2614 ;; LINK has a custom description. Display LINK's
2615 ;; description or headline's title.
2616 (or desc
(org-export-data (org-element-property
2617 :title destination
) info
)))))
2618 (format "<a href=\"#%s\"%s>%s</a>"
2619 (org-export-solidify-link-text href
) attributes desc
)))
2620 ;; Fuzzy link points to a target. Do as above.
2622 (let ((path (org-export-solidify-link-text path
)) number
)
2625 ((org-html-standalone-image-p destination info
)
2626 (org-export-get-ordinal
2627 (assoc 'link
(org-element-contents destination
))
2628 info
'link
'org-html-standalone-image-p
))
2629 (t (org-export-get-ordinal destination info
))))
2630 (setq desc
(when number
2631 (if (atom number
) (number-to-string number
)
2632 (mapconcat 'number-to-string number
".")))))
2633 (format "<a href=\"#%s\"%s>%s</a>"
2634 path attributes
(or desc
"No description for this link")))))))
2635 ;; Coderef: replace link with the reference name or the
2636 ;; equivalent line number.
2637 ((string= type
"coderef")
2638 (let ((fragment (concat "coderef-" path
)))
2639 (format "<a href=\"#%s\"%s%s>%s</a>"
2642 (format (concat "class=\"coderef\""
2643 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2644 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2647 (format (org-export-get-coderef-format path desc
)
2648 (org-export-resolve-coderef path info
)))))
2649 ;; Link type is handled by a special function.
2650 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2651 (funcall protocol
(org-link-unescape path
) desc
'html
))
2652 ;; External link with a description part.
2653 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2654 ;; External link without a description part.
2655 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2656 ;; No path, only description. Try to do something useful.
2657 (t (format "<i>%s</i>" desc
)))))
2661 (defun org-html-paragraph (paragraph contents info
)
2662 "Transcode a PARAGRAPH element from Org to HTML.
2663 CONTENTS is the contents of the paragraph, as a string. INFO is
2664 the plist used as a communication channel."
2665 (let* ((parent (org-export-get-parent paragraph
))
2666 (parent-type (org-element-type parent
))
2667 (style '((footnote-definition " class=\"footpara\"")))
2668 (extra (or (cadr (assoc parent-type style
)) "")))
2670 ((and (eq (org-element-type parent
) 'item
)
2671 (= (org-element-property :begin paragraph
)
2672 (org-element-property :contents-begin parent
)))
2673 ;; leading paragraph in a list item have no tags
2675 ((org-html-standalone-image-p paragraph info
)
2678 (t (format "<p%s>\n%s</p>" extra contents
)))))
2682 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2683 ;; the correct value for the item counter
2684 (defun org-html-begin-plain-list (type &optional arg1
)
2685 "Insert the beginning of the HTML list depending on TYPE.
2686 When ARG1 is a string, use it as the start parameter for ordered
2690 (format "<ol class=\"org-ol\"%s>"
2691 (if arg1
(format " start=\"%d\"" arg1
) "")))
2692 (unordered "<ul class=\"org-ul\">")
2693 (descriptive "<dl class=\"org-dl\">")))
2695 (defun org-html-end-plain-list (type)
2696 "Insert the end of the HTML list depending on TYPE."
2700 (descriptive "</dl>")))
2702 (defun org-html-plain-list (plain-list contents info
)
2703 "Transcode a PLAIN-LIST element from Org to HTML.
2704 CONTENTS is the contents of the list. INFO is a plist holding
2705 contextual information."
2706 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2707 (type (org-element-property :type plain-list
)))
2709 (org-html-begin-plain-list type
)
2710 contents
(org-html-end-plain-list type
))))
2714 (defun org-html-convert-special-strings (string)
2715 "Convert special characters in STRING to HTML."
2716 (let ((all org-html-special-string-regexps
)
2718 (while (setq a
(pop all
))
2719 (setq re
(car a
) rpl
(cdr a
) start
0)
2720 (while (string-match re string start
)
2721 (setq string
(replace-match rpl t nil string
))))
2724 (defun org-html-encode-plain-text (text)
2725 "Convert plain text characters from TEXT to HTML equivalent.
2726 Possible conversions are set in `org-html-protect-char-alist'."
2729 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2730 org-html-protect-char-alist
)
2733 (defun org-html-plain-text (text info
)
2734 "Transcode a TEXT string from Org to HTML.
2735 TEXT is the string to transcode. INFO is a plist holding
2736 contextual information."
2737 (let ((output text
))
2738 ;; Protect following characters: <, >, &.
2739 (setq output
(org-html-encode-plain-text output
))
2740 ;; Handle smart quotes. Be sure to provide original string since
2741 ;; OUTPUT may have been modified.
2742 (when (plist-get info
:with-smart-quotes
)
2743 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2744 ;; Handle special strings.
2745 (when (plist-get info
:with-special-strings
)
2746 (setq output
(org-html-convert-special-strings output
)))
2747 ;; Handle break preservation if required.
2748 (when (plist-get info
:preserve-breaks
)
2750 (replace-regexp-in-string
2751 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2758 (defun org-html-planning (planning contents info
)
2759 "Transcode a PLANNING element from Org to HTML.
2760 CONTENTS is nil. INFO is a plist used as a communication
2762 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2764 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2769 (let ((closed (org-element-property :closed planning
)))
2771 (format span-fmt org-closed-string
2773 (org-element-property :raw-value closed
)))))
2774 (let ((deadline (org-element-property :deadline planning
)))
2776 (format span-fmt org-deadline-string
2778 (org-element-property :raw-value deadline
)))))
2779 (let ((scheduled (org-element-property :scheduled planning
)))
2781 (format span-fmt org-scheduled-string
2783 (org-element-property :raw-value scheduled
)))))))
2786 ;;;; Property Drawer
2788 (defun org-html-property-drawer (property-drawer contents info
)
2789 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2790 CONTENTS is nil. INFO is a plist holding contextual
2792 ;; The property drawer isn't exported but we want separating blank
2793 ;; lines nonetheless.
2798 (defun org-html-quote-block (quote-block contents info
)
2799 "Transcode a QUOTE-BLOCK element from Org to HTML.
2800 CONTENTS holds the contents of the block. INFO is a plist
2801 holding contextual information."
2802 (format "<blockquote>\n%s</blockquote>" contents
))
2806 (defun org-html-quote-section (quote-section contents info
)
2807 "Transcode a QUOTE-SECTION element from Org to HTML.
2808 CONTENTS is nil. INFO is a plist holding contextual information."
2809 (let ((value (org-remove-indentation
2810 (org-element-property :value quote-section
))))
2811 (when value
(format "<pre>\n%s</pre>" value
))))
2815 (defun org-html-section (section contents info
)
2816 "Transcode a SECTION element from Org to HTML.
2817 CONTENTS holds the contents of the section. INFO is a plist
2818 holding contextual information."
2819 (let ((parent (org-export-get-parent-headline section
)))
2820 ;; Before first headline: no container, just return CONTENTS.
2821 (if (not parent
) contents
2822 ;; Get div's class and id references.
2823 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2824 (1- org-html-toplevel-hlevel
)))
2828 (org-export-get-headline-number parent info
) "-")))
2829 ;; Build return value.
2830 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2832 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2837 (defun org-html-radio-target (radio-target text info
)
2838 "Transcode a RADIO-TARGET object from Org to HTML.
2839 TEXT is the text of the target. INFO is a plist holding
2840 contextual information."
2841 (let ((id (org-export-solidify-link-text
2842 (org-element-property :value radio-target
))))
2843 (org-html--anchor id text
)))
2847 (defun org-html-special-block (special-block contents info
)
2848 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2849 CONTENTS holds the contents of the block. INFO is a plist
2850 holding contextual information."
2851 (format "<div class=\"%s\">\n%s\n</div>"
2852 (downcase (org-element-property :type special-block
))
2857 (defun org-html-src-block (src-block contents info
)
2858 "Transcode a SRC-BLOCK element from Org to HTML.
2859 CONTENTS holds the contents of the item. INFO is a plist holding
2860 contextual information."
2861 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2862 (org-html--textarea-block src-block
)
2863 (let ((lang (org-element-property :language src-block
))
2864 (caption (org-export-get-caption src-block
))
2865 (code (org-html-format-code src-block info
))
2866 (label (let ((lbl (org-element-property :name src-block
)))
2868 (format " id=\"%s\""
2869 (org-export-solidify-link-text lbl
))))))
2870 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2872 "<div class=\"org-src-container\">\n%s%s\n</div>"
2873 (if (not caption
) ""
2874 (format "<label class=\"org-src-name\">%s</label>"
2875 (org-export-data caption info
)))
2876 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2878 ;;;; Statistics Cookie
2880 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2881 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2882 CONTENTS is nil. INFO is a plist holding contextual information."
2883 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2884 (format "<code>%s</code>" cookie-value
)))
2888 (defun org-html-strike-through (strike-through contents info
)
2889 "Transcode STRIKE-THROUGH from Org to HTML.
2890 CONTENTS is the text with strike-through markup. INFO is a plist
2891 holding contextual information."
2892 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2897 (defun org-html-subscript (subscript contents info
)
2898 "Transcode a SUBSCRIPT object from Org to HTML.
2899 CONTENTS is the contents of the object. INFO is a plist holding
2900 contextual information."
2901 (format "<sub>%s</sub>" contents
))
2905 (defun org-html-superscript (superscript contents info
)
2906 "Transcode a SUPERSCRIPT object from Org to HTML.
2907 CONTENTS is the contents of the object. INFO is a plist holding
2908 contextual information."
2909 (format "<sup>%s</sup>" contents
))
2913 (defun org-html-table-cell (table-cell contents info
)
2914 "Transcode a TABLE-CELL element from Org to HTML.
2915 CONTENTS is nil. INFO is a plist used as a communication
2917 (let* ((table-row (org-export-get-parent table-cell
))
2918 (table (org-export-get-parent-table table-cell
))
2920 (if (not org-html-table-align-individual-fields
) ""
2921 (format (if (and (boundp 'org-html-format-table-no-css
)
2922 org-html-format-table-no-css
)
2923 " align=\"%s\"" " class=\"%s\"")
2924 (org-export-table-cell-alignment table-cell info
)))))
2925 (when (or (not contents
) (string= "" (org-trim contents
)))
2926 (setq contents
" "))
2928 ((and (org-export-table-has-header-p table info
)
2929 (= 1 (org-export-table-row-group table-row info
)))
2930 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2931 contents
(cdr org-html-table-header-tags
)))
2932 ((and org-html-table-use-header-tags-for-first-column
2933 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2934 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2935 contents
(cdr org-html-table-header-tags
)))
2936 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2937 contents
(cdr org-html-table-data-tags
))))))
2941 (defun org-html-table-row (table-row contents info
)
2942 "Transcode a TABLE-ROW element from Org to HTML.
2943 CONTENTS is the contents of the row. INFO is a plist used as a
2944 communication channel."
2945 ;; Rules are ignored since table separators are deduced from
2946 ;; borders of the current row.
2947 (when (eq (org-element-property :type table-row
) 'standard
)
2948 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2951 ;; Case 1: Row belongs to second or subsequent rowgroups.
2952 ((not (= 1 (org-export-table-row-group table-row info
)))
2953 '("<tbody>" .
"\n</tbody>"))
2954 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2955 ((org-export-table-has-header-p
2956 (org-export-get-parent-table table-row
) info
)
2957 '("<thead>" .
"\n</thead>"))
2958 ;; Case 2: Row is from first and only row group.
2959 (t '("<tbody>" .
"\n</tbody>")))))
2961 ;; Begin a rowgroup?
2962 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2963 (car rowgroup-tags
))
2965 (concat "\n" (eval (car org-html-table-row-tags
))
2968 (eval (cdr org-html-table-row-tags
)))
2970 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2971 (cdr rowgroup-tags
))))))
2975 (defun org-html-table-first-row-data-cells (table info
)
2976 "Transcode the first row of TABLE.
2977 INFO is a plist used as a communication channel."
2979 (org-element-map table
'table-row
2981 (unless (eq (org-element-property :type row
) 'rule
) row
))
2983 (special-column-p (org-export-table-has-special-column-p table
)))
2984 (if (not special-column-p
) (org-element-contents table-row
)
2985 (cdr (org-element-contents table-row
)))))
2987 (defun org-html-table--table.el-table
(table info
)
2988 "Format table.el tables into HTML.
2989 INFO is a plist used as a communication channel."
2990 (when (eq (org-element-property :type table
) 'table.el
)
2992 (let ((outbuf (with-current-buffer
2993 (get-buffer-create "*org-export-table*")
2994 (erase-buffer) (current-buffer))))
2996 (insert (org-element-property :value table
))
2998 (re-search-forward "^[ \t]*|[^|]" nil t
)
2999 (table-generate-source 'html outbuf
))
3000 (with-current-buffer outbuf
3001 (prog1 (org-trim (buffer-string))
3004 (defun org-html-table (table contents info
)
3005 "Transcode a TABLE element from Org to HTML.
3006 CONTENTS is the contents of the table. INFO is a plist holding
3007 contextual information."
3008 (case (org-element-property :type table
)
3009 ;; Case 1: table.el table. Convert it using appropriate tools.
3010 (table.el
(org-html-table--table.el-table table info
))
3011 ;; Case 2: Standard table.
3013 (let* ((label (org-element-property :name table
))
3014 (caption (org-export-get-caption table
))
3015 (attributes (mapconcat #'identity
3016 (org-element-property :attr_html table
)
3019 (if (and (boundp 'org-html-format-table-no-css
)
3020 org-html-format-table-no-css
)
3021 "align=\"%s\"" "class=\"%s\""))
3024 (lambda (table info
)
3026 (lambda (table-cell)
3027 (let ((alignment (org-export-table-cell-alignment
3030 ;; Begin a colgroup?
3031 (when (org-export-table-cell-starts-colgroup-p
3034 ;; Add a column. Also specify it's alignment.
3035 (format "\n<col %s/>" (format alignspec alignment
))
3037 (when (org-export-table-cell-ends-colgroup-p
3040 (org-html-table-first-row-data-cells table info
) "\n"))))
3042 (let ((table-tag (plist-get info
:html-table-tag
)))
3044 (and (string-match "<table\\(.*\\)>" table-tag
)
3045 (match-string 1 table-tag
))
3046 (and label
(format " id=\"%s\""
3047 (org-export-solidify-link-text label
)))
3048 (unless (string= attributes
"")
3049 (concat " " attributes
))))))
3050 ;; Remove last blank line.
3051 (setq contents
(substring contents
0 -
1))
3052 (format "<table%s>\n%s\n%s\n%s\n</table>"
3054 (if (not caption
) ""
3055 (format "<caption>%s</caption>"
3056 (org-export-data caption info
)))
3057 (funcall table-column-specs table info
)
3062 (defun org-html-target (target contents info
)
3063 "Transcode a TARGET object from Org to HTML.
3064 CONTENTS is nil. INFO is a plist holding contextual
3066 (let ((id (org-export-solidify-link-text
3067 (org-element-property :value target
))))
3068 (org-html--anchor id
)))
3072 (defun org-html-timestamp (timestamp contents info
)
3073 "Transcode a TIMESTAMP object from Org to HTML.
3074 CONTENTS is nil. INFO is a plist holding contextual
3076 (let ((value (org-html-plain-text
3077 (org-timestamp-translate timestamp
) info
)))
3078 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3079 (replace-regexp-in-string "--" "–" value
))))
3083 (defun org-html-underline (underline contents info
)
3084 "Transcode UNDERLINE from Org to HTML.
3085 CONTENTS is the text with underline markup. INFO is a plist
3086 holding contextual information."
3087 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3092 (defun org-html-verbatim (verbatim contents info
)
3093 "Transcode VERBATIM from Org to HTML.
3094 CONTENTS is nil. INFO is a plist holding contextual
3096 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3097 (org-html-plain-text (org-element-property :value verbatim
) info
)))
3101 (defun org-html-verse-block (verse-block contents info
)
3102 "Transcode a VERSE-BLOCK element from Org to HTML.
3103 CONTENTS is verse block contents. INFO is a plist holding
3104 contextual information."
3105 ;; Replace each newline character with line break. Also replace
3106 ;; each blank line with a line break.
3107 (setq contents
(replace-regexp-in-string
3108 "^ *\\\\\\\\$" "<br/>\n"
3109 (replace-regexp-in-string
3110 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3111 ;; Replace each white space at beginning of a line with a
3112 ;; non-breaking space.
3113 (while (string-match "^[ \t]+" contents
)
3114 (let* ((num-ws (length (match-string 0 contents
)))
3115 (ws (let (out) (dotimes (i num-ws out
)
3116 (setq out
(concat out
" "))))))
3117 (setq contents
(replace-match ws nil t contents
))))
3118 (format "<p class=\"verse\">\n%s</p>" contents
))
3121 ;;; Filter Functions
3123 (defun org-html-final-function (contents backend info
)
3124 "Filter to indent the HTML and convert HTML entities."
3129 (indent-region (point-min) (point-max)))
3130 (when org-html-use-unicode-chars
3132 (mm-url-decode-entities))
3133 (buffer-substring-no-properties (point-min) (point-max))))
3136 ;;; End-user functions
3139 (defun org-html-export-as-html
3140 (&optional async subtreep visible-only body-only ext-plist
)
3141 "Export current buffer to an HTML buffer.
3143 If narrowing is active in the current buffer, only export its
3146 If a region is active, export that region.
3148 A non-nil optional argument ASYNC means the process should happen
3149 asynchronously. The resulting buffer should be accessible
3150 through the `org-export-stack' interface.
3152 When optional argument SUBTREEP is non-nil, export the sub-tree
3153 at point, extracting information from the headline properties
3156 When optional argument VISIBLE-ONLY is non-nil, don't export
3157 contents of hidden elements.
3159 When optional argument BODY-ONLY is non-nil, only write code
3160 between \"<body>\" and \"</body>\" tags.
3162 EXT-PLIST, when provided, is a property list with external
3163 parameters overriding Org default settings, but still inferior to
3164 file-local settings.
3166 Export is done in a buffer named \"*Org HTML Export*\", which
3167 will be displayed when `org-export-show-temporary-export-buffer'
3171 (org-export-async-start
3173 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3176 (goto-char (point-min))
3178 (org-export-add-to-stack (current-buffer) 'html
)))
3179 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3180 (let ((outbuf (org-export-to-buffer
3181 'html
"*Org HTML Export*"
3182 subtreep visible-only body-only ext-plist
)))
3184 (with-current-buffer outbuf
(set-auto-mode t
))
3185 (when org-export-show-temporary-export-buffer
3186 (switch-to-buffer-other-window outbuf
)))))
3189 (defun org-html-export-to-html
3190 (&optional async subtreep visible-only body-only ext-plist
)
3191 "Export current buffer to a HTML file.
3193 If narrowing is active in the current buffer, only export its
3196 If a region is active, export that region.
3198 A non-nil optional argument ASYNC means the process should happen
3199 asynchronously. The resulting file should be accessible through
3200 the `org-export-stack' interface.
3202 When optional argument SUBTREEP is non-nil, export the sub-tree
3203 at point, extracting information from the headline properties
3206 When optional argument VISIBLE-ONLY is non-nil, don't export
3207 contents of hidden elements.
3209 When optional argument BODY-ONLY is non-nil, only write code
3210 between \"<body>\" and \"</body>\" tags.
3212 EXT-PLIST, when provided, is a property list with external
3213 parameters overriding Org default settings, but still inferior to
3214 file-local settings.
3216 Return output file's name."
3218 (let* ((extension (concat "." org-html-extension
))
3219 (file (org-export-output-file-name extension subtreep
))
3220 (org-export-coding-system org-html-coding-system
))
3222 (org-export-async-start
3223 (lambda (f) (org-export-add-to-stack f
'html
))
3224 (let ((org-export-coding-system org-html-coding-system
))
3227 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3228 (let ((org-export-coding-system org-html-coding-system
))
3230 'html file subtreep visible-only body-only ext-plist
)))))
3233 (defun org-html-publish-to-html (plist filename pub-dir
)
3234 "Publish an org file to HTML.
3236 FILENAME is the filename of the Org file to be published. PLIST
3237 is the property list for the given project. PUB-DIR is the
3238 publishing directory.
3240 Return output file name."
3241 (org-publish-org-to 'html filename
".html" plist pub-dir
))
3246 ;;;; org-format-table-html
3247 ;;;; org-format-org-table-html
3248 ;;;; org-format-table-table-html
3249 ;;;; org-table-number-fraction
3250 ;;;; org-table-number-regexp
3251 ;;;; org-html-table-caption-above
3252 ;;;; org-html-inline-image-extensions
3253 ;;;; org-export-preferred-target-alist
3254 ;;;; class for anchors
3255 ;;;; org-export-with-section-numbers, body-only
3256 ;;;; org-export-mark-todo-in-toc
3257 ;;;; org-html-format-org-link
3258 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3259 ;;;; alt = (file-name-nondirectory path)
3264 ;; generated-autoload-file: "org-loaddefs.el"
3267 ;;; ox-html.el ends here