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
))
51 (org-export-define-backend html
52 ((bold . org-html-bold
)
53 (center-block . org-html-center-block
)
54 (clock . org-html-clock
)
55 (code . org-html-code
)
56 (drawer . org-html-drawer
)
57 (dynamic-block . org-html-dynamic-block
)
58 (entity . org-html-entity
)
59 (example-block . org-html-example-block
)
60 (export-block . org-html-export-block
)
61 (export-snippet . org-html-export-snippet
)
62 (fixed-width . org-html-fixed-width
)
63 (footnote-definition . org-html-footnote-definition
)
64 (footnote-reference . org-html-footnote-reference
)
65 (headline . org-html-headline
)
66 (horizontal-rule . org-html-horizontal-rule
)
67 (inline-src-block . org-html-inline-src-block
)
68 (inlinetask . org-html-inlinetask
)
69 (inner-template . org-html-inner-template
)
70 (italic . org-html-italic
)
71 (item . org-html-item
)
72 (keyword . org-html-keyword
)
73 (latex-environment . org-html-latex-environment
)
74 (latex-fragment . org-html-latex-fragment
)
75 (line-break . org-html-line-break
)
76 (link . org-html-link
)
77 (paragraph . org-html-paragraph
)
78 (plain-list . org-html-plain-list
)
79 (plain-text . org-html-plain-text
)
80 (planning . org-html-planning
)
81 (property-drawer . org-html-property-drawer
)
82 (quote-block . org-html-quote-block
)
83 (quote-section . org-html-quote-section
)
84 (radio-target . org-html-radio-target
)
85 (section . org-html-section
)
86 (special-block . org-html-special-block
)
87 (src-block . org-html-src-block
)
88 (statistics-cookie . org-html-statistics-cookie
)
89 (strike-through . org-html-strike-through
)
90 (subscript . org-html-subscript
)
91 (superscript . org-html-superscript
)
92 (table . org-html-table
)
93 (table-cell . org-html-table-cell
)
94 (table-row . org-html-table-row
)
95 (target . org-html-target
)
96 (template . org-html-template
)
97 (timestamp . org-html-timestamp
)
98 (underline . org-html-underline
)
99 (verbatim . org-html-verbatim
)
100 (verse-block . org-html-verse-block
))
102 :filters-alist
((:filter-options . org-html-infojs-install-script
)
103 (:filter-final-output . org-html-final-function
))
106 ((?H
"As HTML buffer" org-html-export-as-html
)
107 (?h
"As HTML file" org-html-export-to-html
)
108 (?o
"As HTML file and open"
110 (if a
(org-html-export-to-html t s v b
)
111 (org-open-file (org-html-export-to-html nil s v b
)))))))
113 ((:html-extension nil nil org-html-extension
)
114 (:html-doctype
"HTML_DOCTYPE" nil org-html-doctype
)
115 (:html-container
"HTML_CONTAINER" nil org-html-container-element
)
116 (:html-link-home
"HTML_LINK_HOME" nil org-html-link-home
)
117 (:html-link-up
"HTML_LINK_UP" nil org-html-link-up
)
118 (:html-mathjax
"HTML_MATHJAX" nil
"" space
)
119 (:html-postamble nil
"html-postamble" org-html-postamble
)
120 (:html-preamble nil
"html-preamble" org-html-preamble
)
121 (:html-head
"HTML_HEAD" nil org-html-head newline
)
122 (:html-head-extra
"HTML_HEAD_EXTRA" nil org-html-head-extra newline
)
123 (:html-head-include-default-style
"HTML_INCLUDE_STYLE" nil org-html-head-include-default-style newline
)
124 (:html-head-include-scripts
"HTML_INCLUDE_SCRIPTS" nil org-html-head-include-scripts newline
)
125 (:html-table-tag nil nil org-html-table-tag
)
126 ;; Redefine regular options.
127 (:creator
"CREATOR" nil org-html-creator-string
)
128 (:with-latex nil
"tex" org-html-with-latex
)
129 ;; Leave room for "ox-infojs.el" extension.
130 (:infojs-opt
"INFOJS_OPT" nil nil
)))
133 ;;; Internal Variables
135 (defvar org-html-format-table-no-css
)
136 (defvar htmlize-buffer-places
) ; from htmlize.el
138 (defconst org-html-special-string-regexps
139 '(("\\\\-" .
"­") ; shy
140 ("---\\([^-]\\)" .
"—\\1") ; mdash
141 ("--\\([^-]\\)" .
"–\\1") ; ndash
142 ("\\.\\.\\." .
"…")) ; hellip
143 "Regular expressions for special string conversion.")
145 (defconst org-html-scripts
146 "<script type=\"text/javascript\">
148 @licstart The following is the entire license notice for the
149 JavaScript code in this tag.
151 Copyright (C) 2012 Free Software Foundation, Inc.
153 The JavaScript code in this tag is free software: you can
154 redistribute it and/or modify it under the terms of the GNU
155 General Public License (GNU GPL) as published by the Free Software
156 Foundation, either version 3 of the License, or (at your option)
157 any later version. The code is distributed WITHOUT ANY WARRANTY;
158 without even the implied warranty of MERCHANTABILITY or FITNESS
159 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
161 As additional permission under GNU GPL version 3 section 7, you
162 may distribute non-source (e.g., minimized or compacted) forms of
163 that code without the copy of the GNU GPL normally required by
164 section 4, provided you include this license notice and a URL
165 through which recipients can access the Corresponding Source.
168 @licend The above is the entire license notice
169 for the JavaScript code in this tag.
171 <!--/*--><![CDATA[/*><!--*/
172 function CodeHighlightOn(elem, id)
174 var target = document.getElementById(id);
176 elem.cacheClassElem = elem.className;
177 elem.cacheClassTarget = target.className;
178 target.className = \"code-highlighted\";
179 elem.className = \"code-highlighted\";
182 function CodeHighlightOff(elem, id)
184 var target = document.getElementById(id);
185 if(elem.cacheClassElem)
186 elem.className = elem.cacheClassElem;
187 if(elem.cacheClassTarget)
188 target.className = elem.cacheClassTarget;
192 "Basic JavaScript that is needed by HTML files produced by Org mode.")
194 (defconst org-html-style-default
195 "<style type=\"text/css\">
196 <!--/*--><![CDATA[/*><!--*/
197 .title { text-align: center; }
198 .todo { font-family: monospace; color: red; }
199 .done { color: green; }
200 .tag { background-color: #eee; font-family: monospace;
201 padding: 2px; font-size: 80%; font-weight: normal; }
202 .timestamp { color: #bebebe; }
203 .timestamp-kwd { color: #5f9ea0; }
204 .right { margin-left: auto; margin-right: 0px; text-align: right; }
205 .left { margin-left: 0px; margin-right: auto; text-align: left; }
206 .center { margin-left: auto; margin-right: auto; text-align: center; }
207 .underline { text-decoration: underline; }
208 #content { margin: 3em; }
209 #postamble p, a { font-size: 90%; margin: .2em; }
210 p.verse { margin-left: 3%; }
212 border: 1px solid #ccc;
213 box-shadow: 3px 3px 3px #eee;
215 font-family: monospace;
227 background-color: white;
231 border: 1px solid black;
233 pre.src:hover:before { display: inline;}
234 pre.src-sh:before { content: 'sh'; }
235 pre.src-bash:before { content: 'sh'; }
236 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
237 pre.src-R:before { content: 'R'; }
238 pre.src-perl:before { content: 'Perl'; }
239 pre.src-java:before { content: 'Java'; }
240 pre.src-sql:before { content: 'SQL'; }
242 table { border-collapse:collapse; }
243 td, th { vertical-align:top; }
244 th.right { text-align: center; }
245 th.left { text-align: center; }
246 th.center { text-align: center; }
247 td.right { text-align: right; }
248 td.left { text-align: left; }
249 td.center { text-align: center; }
250 dt { font-weight: bold; }
251 .figure { padding: 1em; }
252 .figure p { text-align: center; }
255 border: 2px solid gray;
260 { text-align: right; font-size: 70%; white-space: nowrap; }
261 textarea { overflow-x:auto; }
262 .linenr { font-size:smaller }
263 .code-highlighted { background-color:#ffff00; }
264 .org-info-js_info-navigation { border-style:none; }
265 #org-info-js_console-label
266 { font-size:10px; font-weight:bold; white-space:nowrap; }
267 .org-info-js_search-highlight
268 { background-color:#ffff00; color:#000000; font-weight:bold; }
271 "The default style specification for exported HTML files.
272 You can use `org-html-head' and `org-html-head-extra' to add to
273 this style. If you don't want to include this default style,
274 customize `org-html-head-include-default-style'.")
277 ;;; User Configuration Variables
279 (defgroup org-export-html nil
280 "Options for exporting Org mode files to HTML."
281 :tag
"Org Export HTML"
286 (defvar org-html-infojs-opts-table
287 '((path PATH
"http://orgmode.org/org-info.js")
291 (tdepth TOC_DEPTH
"max")
292 (sdepth SECTION_DEPTH
"max")
293 (mouse MOUSE_HINT
"underline")
294 (buttons VIEW_BUTTONS
"0")
296 (up LINK_UP
:html-link-up
)
297 (home LINK_HOME
:html-link-home
))
298 "JavaScript options, long form for script, default values.")
300 (defcustom org-html-use-infojs
'when-configured
301 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
302 This option can be nil or t to never or always use the script.
303 It can also be the symbol `when-configured', meaning that the
304 script will be linked into the export file if and only if there
305 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
306 `org-html-infojs-options'."
307 :group
'org-export-html
309 :package-version
'(Org .
"8.0")
311 (const :tag
"Never" nil
)
312 (const :tag
"When configured in buffer" when-configured
)
313 (const :tag
"Always" t
)))
315 (defcustom org-html-infojs-options
316 (mapcar (lambda (x) (cons (car x
) (nth 2 x
))) org-html-infojs-opts-table
)
317 "Options settings for the INFOJS JavaScript.
318 Each of the options must have an entry in `org-html-infojs-opts-table'.
319 The value can either be a string that will be passed to the script, or
320 a property. This property is then assumed to be a property that is defined
321 by the Export/Publishing setup of Org.
322 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
323 means to use the maximum value consistent with other options."
324 :group
'org-export-html
326 :package-version
'(Org .
"8.0")
328 `(set :greedy t
:inline t
331 (list 'cons
(list 'const
(car x
))
333 (symbol :tag
"Publishing/Export property")
334 (string :tag
"Value"))))
335 org-html-infojs-opts-table
)))
337 (defcustom org-html-infojs-template
338 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
341 * @source: %SCRIPT_PATH
343 * @licstart The following is the entire license notice for the
344 * JavaScript code in %SCRIPT_PATH.
346 * Copyright (C) 2012-2013 Sebastian Rose
349 * The JavaScript code in this tag is free software: you can
350 * redistribute it and/or modify it under the terms of the GNU
351 * General Public License (GNU GPL) as published by the Free Software
352 * Foundation, either version 3 of the License, or (at your option)
353 * any later version. The code is distributed WITHOUT ANY WARRANTY;
354 * without even the implied warranty of MERCHANTABILITY or FITNESS
355 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
357 * As additional permission under GNU GPL version 3 section 7, you
358 * may distribute non-source (e.g., minimized or compacted) forms of
359 * that code without the copy of the GNU GPL normally required by
360 * section 4, provided you include this license notice and a URL
361 * through which recipients can access the Corresponding Source.
363 * @licend The above is the entire license notice
364 * for the JavaScript code in %SCRIPT_PATH.
369 <script type=\"text/javascript\">
372 @licstart The following is the entire license notice for the
373 JavaScript code in this tag.
375 Copyright (C) 2012-2013 Free Software Foundation, Inc.
377 The JavaScript code in this tag is free software: you can
378 redistribute it and/or modify it under the terms of the GNU
379 General Public License (GNU GPL) as published by the Free Software
380 Foundation, either version 3 of the License, or (at your option)
381 any later version. The code is distributed WITHOUT ANY WARRANTY;
382 without even the implied warranty of MERCHANTABILITY or FITNESS
383 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
385 As additional permission under GNU GPL version 3 section 7, you
386 may distribute non-source (e.g., minimized or compacted) forms of
387 that code without the copy of the GNU GPL normally required by
388 section 4, provided you include this license notice and a URL
389 through which recipients can access the Corresponding Source.
392 @licend The above is the entire license notice
393 for the JavaScript code in this tag.
396 <!--/*--><![CDATA[/*><!--*/
398 org_html_manager.setup(); // activate after the parameters are set
401 "The template for the export style additions when org-info.js is used.
402 Option settings will replace the %MANAGER-OPTIONS cookie."
403 :group
'org-export-html
405 :package-version
'(Org .
"8.0")
408 (defun org-html-infojs-install-script (exp-plist backend
)
409 "Install script in export options when appropriate.
410 EXP-PLIST is a plist containing export options. BACKEND is the
411 export back-end currently used."
412 (unless (or (memq 'body-only
(plist-get exp-plist
:export-options
))
413 (not org-html-use-infojs
)
414 (and (eq org-html-use-infojs
'when-configured
)
415 (or (not (plist-get exp-plist
:infojs-opt
))
416 (string-match "\\<view:nil\\>"
417 (plist-get exp-plist
:infojs-opt
)))))
418 (let* ((template org-html-infojs-template
)
419 (ptoc (plist-get exp-plist
:with-toc
))
420 (hlevels (plist-get exp-plist
:headline-levels
))
422 (tdepth (if (integerp ptoc
) (min ptoc hlevels
) hlevels
))
423 (options (plist-get exp-plist
:infojs-opt
))
424 (table org-html-infojs-opts-table
)
426 (dolist (entry table
)
427 (let* ((opt (car entry
))
429 ;; Compute default values for script option OPT from
430 ;; `org-html-infojs-options' variable.
432 (let ((default (cdr (assq opt org-html-infojs-options
))))
433 (if (and (symbolp default
) (not (memq default
'(t nil
))))
434 (plist-get exp-plist default
)
436 ;; Value set through INFOJS_OPT keyword has precedence
437 ;; over the default one.
438 (val (if (and options
439 (string-match (format "\\<%s:\\(\\S-+\\)" opt
)
441 (match-string 1 options
)
445 (replace-regexp-in-string
446 "%SCRIPT_PATH" val template t t
)))
447 (sdepth (when (integerp (read val
))
448 (setq sdepth
(min (read val
) sdepth
))))
449 (tdepth (when (integerp (read val
))
450 (setq tdepth
(min (read val
) tdepth
))))
453 ((or (eq val t
) (equal val
"t")) "1")
454 ((or (eq val nil
) (equal val
"nil")) "0")
456 (t (format "%s" val
))))
457 (push (cons var val
) style
)))))
458 ;; Now we set the depth of the *generated* TOC to SDEPTH,
459 ;; because the toc will actually determine the splitting. How
460 ;; much of the toc will actually be displayed is governed by the
462 (setq exp-plist
(plist-put exp-plist
:with-toc sdepth
))
463 ;; The table of contents should not show more sections than we
465 (setq tdepth
(min tdepth sdepth
))
466 (push (cons "TOC_DEPTH" tdepth
) style
)
467 ;; Build style string.
468 (setq style
(mapconcat
469 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
473 (when (and style
(> (length style
) 0))
474 (and (string-match "%MANAGER_OPTIONS" template
)
475 (setq style
(replace-match style t t template
))
478 exp-plist
:html-head-extra
479 (concat (or (plist-get exp-plist
:html-head-extra
) "")
482 ;; This script absolutely needs the table of contents, so we
483 ;; change that setting.
484 (unless (plist-get exp-plist
:with-toc
)
485 (setq exp-plist
(plist-put exp-plist
:with-toc t
)))
486 ;; Return the modified property list.
491 (defcustom org-html-text-markup-alist
492 '((bold .
"<b>%s</b>")
493 (code .
"<code>%s</code>")
494 (italic .
"<i>%s</i>")
495 (strike-through .
"<del>%s</del>")
496 (underline .
"<span class=\"underline\">%s</span>")
497 (verbatim .
"<code>%s</code>"))
498 "Alist of HTML expressions to convert text markup.
500 The key must be a symbol among `bold', `code', `italic',
501 `strike-through', `underline' and `verbatim'. The value is
502 a formatting string to wrap fontified text with.
504 If no association can be found for a given markup, text will be
506 :group
'org-export-html
507 :type
'(alist :key-type
(symbol :tag
"Markup type")
508 :value-type
(string :tag
"Format string"))
509 :options
'(bold code italic strike-through underline verbatim
))
511 (defcustom org-html-pretty-output nil
512 "Enable this to generate pretty HTML."
513 :group
'org-export-html
515 :package-version
'(Org .
"8.0")
520 (defcustom org-html-format-drawer-function nil
521 "Function called to format a drawer in HTML code.
523 The function must accept two parameters:
524 NAME the drawer name, like \"LOGBOOK\"
525 CONTENTS the contents of the drawer.
527 The function should return the string to be exported.
529 For example, the variable could be set to the following function
530 in order to mimic default behaviour:
532 \(defun org-html-format-drawer-default \(name contents\)
533 \"Format a drawer element for HTML export.\"
535 :group
'org-export-html
540 (defcustom org-html-footnotes-section
"<div id=\"footnotes\">
541 <h2 class=\"footnotes\">%s: </h2>
542 <div id=\"text-footnotes\">
546 "Format for the footnotes section.
547 Should contain a two instances of %s. The first will be replaced with the
548 language-specific word for \"Footnotes\", the second one will be replaced
549 by the footnotes themselves."
550 :group
'org-export-html
553 (defcustom org-html-footnote-format
"<sup>%s</sup>"
554 "The format for the footnote reference.
555 %s will be replaced by the footnote reference itself."
556 :group
'org-export-html
559 (defcustom org-html-footnote-separator
"<sup>, </sup>"
560 "Text used to separate footnotes."
561 :group
'org-export-html
566 (defcustom org-html-toplevel-hlevel
2
567 "The <H> level for level 1 headings in HTML export.
568 This is also important for the classes that will be wrapped around headlines
569 and outline structure. If this variable is 1, the top-level headlines will
570 be <h1>, and the corresponding classes will be outline-1, section-number-1,
571 and outline-text-1. If this is 2, all of these will get a 2 instead.
572 The default for this variable is 2, because we use <h1> for formatting the
574 :group
'org-export-html
577 (defcustom org-html-format-headline-function nil
578 "Function to format headline text.
580 This function will be called with 5 arguments:
581 TODO the todo keyword (string or nil).
582 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
583 PRIORITY the priority of the headline (integer or nil)
584 TEXT the main headline text (string).
585 TAGS the tags (string or nil).
587 The function result will be used in the section format string."
588 :group
'org-export-html
593 (defcustom org-html-allow-name-attribute-in-anchors t
594 "When nil, do not set \"name\" attribute in anchors.
595 By default, anchors are formatted with both \"id\" and \"name\"
596 attributes, when appropriate."
597 :group
'org-export-html
599 :package-version
'(Org .
"8.0")
604 (defcustom org-html-format-inlinetask-function nil
605 "Function called to format an inlinetask in HTML code.
607 The function must accept six parameters:
608 TODO the todo keyword, as a string
609 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
610 PRIORITY the inlinetask priority, as a string
611 NAME the inlinetask name, as a string.
612 TAGS the inlinetask tags, as a list of strings.
613 CONTENTS the contents of the inlinetask, as a string.
615 The function should return the string to be exported."
616 :group
'org-export-html
621 (defcustom org-html-with-latex org-export-with-latex
622 "Non-nil means process LaTeX math snippets.
624 When set, the exporter will process LaTeX environments and
627 This option can also be set with the +OPTIONS line,
628 e.g. \"tex:mathjax\". Allowed values are:
630 nil Ignore math snippets.
631 `verbatim' Keep everything in verbatim
632 `dvipng' Process the LaTeX fragments to images. This will also
633 include processing of non-math environments.
634 `imagemagick' Convert the LaTeX fragments to pdf files and use
635 imagemagick to convert pdf files to png files.
636 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
638 t Synonym for `mathjax'."
639 :group
'org-export-html
641 :package-version
'(Org .
"8.0")
643 (const :tag
"Do not process math in any way" nil
)
644 (const :tag
"Use dvipng to make images" dvipng
)
645 (const :tag
"Use imagemagick to make images" imagemagick
)
646 (const :tag
"Use MathJax to display math" mathjax
)
647 (const :tag
"Leave math verbatim" verbatim
)))
649 ;;;; Links :: Generic
651 (defcustom org-html-link-org-files-as-html t
652 "Non-nil means make file links to `file.org' point to `file.html'.
653 When `org-mode' is exporting an `org-mode' file to HTML, links to
654 non-html files are directly put into a href tag in HTML.
655 However, links to other Org-mode files (recognized by the
656 extension `.org.) should become links to the corresponding html
657 file, assuming that the linked `org-mode' file will also be
659 When nil, the links still point to the plain `.org' file."
660 :group
'org-export-html
663 ;;;; Links :: Inline images
665 (defcustom org-html-inline-images
'maybe
666 "Non-nil means inline images into exported HTML pages.
667 This is done using an <img> tag. When nil, an anchor with href is used to
668 link to the image. If this option is `maybe', then images in links with
669 an empty description will be inlined, while images with a description will
671 :group
'org-export-html
672 :type
'(choice (const :tag
"Never" nil
)
673 (const :tag
"Always" t
)
674 (const :tag
"When there is no description" maybe
)))
676 (defcustom org-html-inline-image-rules
677 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
678 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
679 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
680 "Rules characterizing image files that can be inlined into HTML.
682 A rule consists in an association whose key is the type of link
683 to consider, and value is a regexp that will be matched against
686 Note that, by default, the image extension *actually* allowed
687 depend on the way the HTML file is processed. When used with
688 pdflatex, pdf, jpg and png images are OK. When processing
689 through dvi to Postscript, only ps and eps are allowed. The
690 default we use here encompasses both."
691 :group
'org-export-html
693 :package-version
'(Org .
"8.0")
694 :type
'(alist :key-type
(string :tag
"Type")
695 :value-type
(regexp :tag
"Path")))
699 (defcustom org-html-protect-char-alist
703 "Alist of characters to be converted by `org-html-protect'."
704 :group
'org-export-html
705 :type
'(repeat (cons (string :tag
"Character")
706 (string :tag
"HTML equivalent"))))
710 (defcustom org-html-htmlize-output-type
'inline-css
711 "Output type to be used by htmlize when formatting code snippets.
712 Choices are `css', to export the CSS selectors only, or `inline-css', to
713 export the CSS attribute values inline in the HTML. We use as default
714 `inline-css', in order to make the resulting HTML self-containing.
716 However, this will fail when using Emacs in batch mode for export, because
717 then no rich font definitions are in place. It will also not be good if
718 people with different Emacs setup contribute HTML files to a website,
719 because the fonts will represent the individual setups. In these cases,
720 it is much better to let Org/Htmlize assign classes only, and to use
721 a style file to define the look of these classes.
722 To get a start for your css file, start Emacs session and make sure that
723 all the faces you are interested in are defined, for example by loading files
724 in all modes you want. Then, use the command
725 \\[org-html-htmlize-generate-css] to extract class definitions."
726 :group
'org-export-html
727 :type
'(choice (const css
) (const inline-css
)))
729 (defcustom org-html-htmlize-font-prefix
"org-"
730 "The prefix for CSS class names for htmlize font specifications."
731 :group
'org-export-html
736 (defcustom org-html-table-tag
737 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
738 "The HTML tag that is used to start a table.
739 This must be a <table> tag, but you may change the options like
740 borders and spacing."
741 :group
'org-export-html
744 (defcustom org-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
745 "The opening tag for table header fields.
746 This is customizable so that alignment options can be specified.
747 The first %s will be filled with the scope of the field, either row or col.
748 The second %s will be replaced by a style entry to align the field.
749 See also the variable `org-html-table-use-header-tags-for-first-column'.
750 See also the variable `org-html-table-align-individual-fields'."
751 :group
'org-export-html
752 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
754 (defcustom org-html-table-data-tags
'("<td%s>" .
"</td>")
755 "The opening tag for table data fields.
756 This is customizable so that alignment options can be specified.
757 The first %s will be filled with the scope of the field, either row or col.
758 The second %s will be replaced by a style entry to align the field.
759 See also the variable `org-html-table-align-individual-fields'."
760 :group
'org-export-html
761 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
763 (defcustom org-html-table-row-tags
'("<tr>" .
"</tr>")
764 "The opening tag for table data fields.
765 This is customizable so that alignment options can be specified.
766 Instead of strings, these can be Lisp forms that will be evaluated
767 for each row in order to construct the table row tags. During evaluation,
768 the variable `head' will be true when this is a header line, nil when this
769 is a body line. And the variable `nline' will contain the line number,
770 starting from 1 in the first header line. For example
772 (setq org-html-table-row-tags
775 (if (= (mod nline 2) 1)
776 \"<tr class=\\\"tr-odd\\\">\"
777 \"<tr class=\\\"tr-even\\\">\"))
780 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
781 :group
'org-export-html
783 (choice :tag
"Opening tag"
784 (string :tag
"Specify")
786 (choice :tag
"Closing tag"
787 (string :tag
"Specify")
790 (defcustom org-html-table-align-individual-fields t
791 "Non-nil means attach style attributes for alignment to each table field.
792 When nil, alignment will only be specified in the column tags, but this
793 is ignored by some browsers (like Firefox, Safari). Opera does it right
795 :group
'org-export-html
798 (defcustom org-html-table-use-header-tags-for-first-column nil
799 "Non-nil means format column one in tables with header tags.
800 When nil, also column one will use data tags."
801 :group
'org-export-html
804 (defcustom org-html-table-caption-above t
805 "When non-nil, place caption string at the beginning of the table.
806 Otherwise, place it near the end."
807 :group
'org-export-html
812 (defcustom org-html-tag-class-prefix
""
813 "Prefix to class names for TODO keywords.
814 Each tag gets a class given by the tag itself, with this prefix.
815 The default prefix is empty because it is nice to just use the keyword
816 as a class name. But if you get into conflicts with other, existing
817 CSS classes, then this prefix can be very useful."
818 :group
'org-export-html
821 ;;;; Template :: Generic
823 (defcustom org-html-extension
"html"
824 "The extension for exported HTML files."
825 :group
'org-export-html
828 (defcustom org-html-xml-declaration
829 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
830 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
831 "The extension for exported HTML files.
832 %s will be replaced with the charset of the exported file.
833 This may be a string, or an alist with export extensions
834 and corresponding declarations."
835 :group
'org-export-html
837 (string :tag
"Single declaration")
838 (repeat :tag
"Dependent on extension"
839 (cons (string :tag
"Extension")
840 (string :tag
"Declaration")))))
842 (defcustom org-html-coding-system
'utf-8
843 "Coding system for HTML export.
844 Use utf-8 as the default value."
845 :group
'org-export-html
847 :package-version
'(Org .
"8.0")
848 :type
'coding-system
)
850 (defcustom org-html-doctype
851 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
852 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
853 "Document type definition to use for exported HTML files.
854 Can be set with the in-buffer HTML_DOCTYPE property or for
855 publishing, with :html-doctype."
856 :group
'org-export-html
858 :package-version
'(Org .
"8.0")
861 (defcustom org-html-container-element
"div"
862 "Container class to use for wrapping top level sections.
863 Can be set with the in-buffer HTML_CONTAINER property or for
864 publishing, with :html-container.
866 Note that changing the default will prevent you from using
867 org-info.js for your website."
868 :group
'org-export-html
870 :package-version
'(Org .
"8.0")
873 (defcustom org-html-divs
874 '((preamble "div" "preamble")
875 (content "div" "content")
876 (postamble "div" "postamble"))
877 "Alist of the threed section elements for HTML export.
878 The car of each entry is one of 'preamble, 'content or 'postamble.
879 The cdrs of each entry are the ELEMENT_TYPE and ID for each
880 section of the exported document.
882 Note that changing the default will prevent you from using
883 org-info.js for your website."
884 :group
'org-export-html
886 :package-version
'(Org .
"8.0")
887 :type
'(list :greedy t
888 (list :tag
"Preamble"
889 (const :format
"" preamble
)
890 (string :tag
"element") (string :tag
" id"))
892 (const :format
"" content
)
893 (string :tag
"element") (string :tag
" id"))
894 (list :tag
"Postamble" (const :format
"" postamble
)
895 (string :tag
" id") (string :tag
"element"))))
897 ;;;; Template :: Mathjax
899 (defcustom org-html-mathjax-options
900 '((path "http://orgmode.org/mathjax/MathJax.js")
905 "Options for MathJax setup.
907 path The path where to find MathJax
908 scale Scaling for the HTML-CSS backend, usually between 100 and 133
909 align How to align display math: left, center, or right
910 indent If align is not center, how far from the left/right side?
911 mathml Should a MathML player be used if available?
912 This is faster and reduces bandwidth use, but currently
913 sometimes has lower spacing quality. Therefore, the default is
914 nil. When browsers get better, this switch can be flipped.
916 You can also customize this for each buffer, using something like
918 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
919 :group
'org-export-html
920 :type
'(list :greedy t
921 (list :tag
"path (the path from where to load MathJax.js)"
922 (const :format
" " path
) (string))
923 (list :tag
"scale (scaling for the displayed math)"
924 (const :format
" " scale
) (string))
925 (list :tag
"align (alignment of displayed equations)"
926 (const :format
" " align
) (string))
927 (list :tag
"indent (indentation with left or right alignment)"
928 (const :format
" " indent
) (string))
929 (list :tag
"mathml (should MathML display be used is possible)"
930 (const :format
" " mathml
) (boolean))))
932 (defcustom org-html-mathjax-template
933 "<script type=\"text/javascript\" src=\"%PATH\">
934 <!--/*--><![CDATA[/*><!--*/
936 // Only one of the two following lines, depending on user settings
937 // First allows browser-native MathML display, second forces HTML/CSS
938 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
939 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
940 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
941 \"TeX/noUndefined.js\"],
943 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
944 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
945 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
946 ignoreClass: \"tex2jax_ignore\",
947 processEscapes: false,
948 processEnvironments: true,
951 showProcessingMessages: true,
952 displayAlign: \"%ALIGN\",
953 displayIndent: \"%INDENT\",
957 availableFonts: [\"STIX\",\"TeX\"],
958 preferredFont: \"TeX\",
974 "The MathJax setup for XHTML files."
975 :group
'org-export-html
978 ;;;; Template :: Postamble
980 (defcustom org-html-postamble
'auto
981 "Non-nil means insert a postamble in HTML export.
983 When set to 'auto, check against the
984 `org-export-with-author/email/creator/date' variables to set the
985 content of the postamble. When set to a string, use this string
986 as the postamble. When t, insert a string as defined by the
987 formatting string in `org-html-postamble-format'.
989 When set to a function, apply this function and insert the
990 returned string. The function takes the property list of export
991 options as its only argument.
993 Setting :html-postamble in publishing projects will take
994 precedence over this variable."
995 :group
'org-export-html
996 :type
'(choice (const :tag
"No postamble" nil
)
997 (const :tag
"Auto postamble" 'auto
)
998 (const :tag
"Default formatting string" t
)
999 (string :tag
"Custom formatting string")
1000 (function :tag
"Function (must return a string)")))
1002 (defcustom org-html-postamble-format
1003 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1004 <p class=\"date\">Date: %d</p>
1005 <p class=\"creator\">Generated by %c</p>
1006 <p class=\"xhtml-validation\">%v</p>"))
1007 "Alist of languages and format strings for the HTML postamble.
1009 The first element of each list is the language code, as used for
1010 the #+LANGUAGE keyword.
1012 The second element of each list is a format string to format the
1013 postamble itself. This format string can contain these elements:
1015 %a stands for the author's name.
1016 %e stands for the author's email.
1017 %d stands for the date.
1018 %c will be replaced by information about Org/Emacs versions.
1019 %v will be replaced by `org-html-validation-link'.
1021 If you need to use a \"%\" character, you need to escape it
1023 :group
'org-export-html
1024 :type
'(alist :key-type
(string :tag
"Language")
1025 :value-type
(string :tag
"Format string")))
1027 (defcustom org-html-validation-link
1028 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
1029 "Link to HTML validation service."
1030 :group
'org-export-html
1033 (defcustom org-html-creator-string
1034 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
1035 (if (fboundp 'org-version
) (org-version) "(Unknown)")
1037 "String to insert at the end of the HTML document."
1038 :group
'org-export-html
1039 :type
'(string :tag
"Creator string"))
1041 ;;;; Template :: Preamble
1043 (defcustom org-html-preamble t
1044 "Non-nil means insert a preamble in HTML export.
1046 When t, insert a string as defined by the formatting string in
1047 `org-html-preamble-format'. When set to a string, use this
1048 formatting string instead (see `org-html-postamble-format' for an
1049 example of such a formatting string).
1051 When set to a function, apply this function and insert the
1052 returned string. The function takes the property list of export
1053 options as its only argument.
1055 Setting :html-preamble in publishing projects will take
1056 precedence over this variable."
1057 :group
'org-export-html
1058 :type
'(choice (const :tag
"No preamble" nil
)
1059 (const :tag
"Default preamble" t
)
1060 (string :tag
"Custom formatting string")
1061 (function :tag
"Function (must return a string)")))
1063 (defcustom org-html-preamble-format
'(("en" ""))
1064 "Alist of languages and format strings for the HTML preamble.
1066 The first element of each list is the language code, as used for
1067 the #+LANGUAGE keyword.
1069 The second element of each list is a format string to format the
1070 preamble itself. This format string can contain these elements:
1072 %t stands for the title.
1073 %a stands for the author's name.
1074 %e stands for the author's email.
1075 %d stands for the date.
1077 If you need to use a \"%\" character, you need to escape it
1080 See the default value of `org-html-postamble-format' for an
1082 :group
'org-export-html
1083 :type
'(alist :key-type
(string :tag
"Language")
1084 :value-type
(string :tag
"Format string")))
1086 (defcustom org-html-link-up
""
1087 "Where should the \"UP\" link of exported HTML pages lead?"
1088 :group
'org-export-html
1089 :type
'(string :tag
"File or URL"))
1091 (defcustom org-html-link-home
""
1092 "Where should the \"HOME\" link of exported HTML pages lead?"
1093 :group
'org-export-html
1094 :type
'(string :tag
"File or URL"))
1096 (defcustom org-html-home
/up-format
1097 "<div id=\"org-div-home-and-up\">
1098 <a accesskey=\"h\" href=\"%s\"> UP </a>
1100 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1102 "Snippet used to insert the HOME and UP links.
1103 This is a format string, the first %s will receive the UP link,
1104 the second the HOME link. If both `org-html-link-up' and
1105 `org-html-link-home' are empty, the entire snippet will be
1107 :group
'org-export-html
1110 ;;;; Template :: Scripts
1112 (define-obsolete-variable-alias
1113 'org-html-style-include-scripts
'org-html-head-include-scripts
"24.4")
1114 (defcustom org-html-head-include-scripts t
1115 "Non-nil means include the JavaScript snippets in exported HTML files.
1116 The actual script is defined in `org-html-scripts' and should
1118 :group
'org-export-html
1120 :package-version
'(Org .
"8.0")
1123 ;;;; Template :: Styles
1125 (define-obsolete-variable-alias
1126 'org-html-style-include-default
'org-html-head-include-default-style
"24.4")
1127 (defcustom org-html-head-include-default-style t
1128 "Non-nil means include the default style in exported HTML files.
1129 The actual style is defined in `org-html-style-default' and
1130 should not be modified. Use `org-html-head' to use your own
1132 :group
'org-export-html
1134 :package-version
'(Org .
"8.0")
1137 (put 'org-html-head-include-default-style
'safe-local-variable
'booleanp
)
1139 (define-obsolete-variable-alias 'org-html-style
'org-html-head
"24.4")
1140 (defcustom org-html-head
""
1141 "Org-wide head definitions for exported HTML files.
1143 This variable can contain the full HTML structure to provide a
1144 style, including the surrounding HTML tags. You can consider
1145 including definitions for the following classes: title, todo,
1146 done, timestamp, timestamp-kwd, tag, target.
1148 For example, a valid value would be:
1150 <style type=\"text/css\">
1152 p { font-weight: normal; color: gray; }
1153 h1 { color: black; }
1154 .title { text-align: center; }
1155 .todo, .timestamp-kwd { color: red; }
1156 .done { color: green; }
1160 If you want to refer to an external style, use something like
1162 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1164 As the value of this option simply gets inserted into the HTML
1165 <head> header, you can use it to add any arbitrary text to the
1168 You can set this on a per-file basis using #+HTML_HEAD:,
1169 or for publication projects using the :html-head property."
1170 :group
'org-export-html
1172 :package-version
'(Org .
"8.0")
1175 (put 'org-html-head
'safe-local-variable
'stringp
)
1177 (defcustom org-html-head-extra
""
1178 "More head information to add in the HTML output.
1180 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1181 or for publication projects using the :html-head-extra property."
1182 :group
'org-export-html
1184 :package-version
'(Org .
"8.0")
1187 (put 'org-html-head-extra
'safe-local-variable
'stringp
)
1191 (defcustom org-html-todo-kwd-class-prefix
""
1192 "Prefix to class names for TODO keywords.
1193 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1194 The default prefix is empty because it is nice to just use the keyword
1195 as a class name. But if you get into conflicts with other, existing
1196 CSS classes, then this prefix can be very useful."
1197 :group
'org-export-html
1201 ;;; Internal Functions
1203 (defun org-html-format-inline-image (src &optional
1204 caption label attr standalone-p
)
1205 "Format an inline image from SRC.
1206 CAPTION, LABEL and ATTR are optional arguments providing the
1207 caption, the label and the attribute of the image.
1208 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1209 (let* ((id (if (not label
) ""
1210 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1213 ((string-match "\\<alt=" (or attr
"")) "")
1214 ((string-match "^ltxpng/" src
)
1215 (format " alt=\"%s\""
1216 (org-html-encode-plain-text
1217 (org-find-text-property-in-string
1218 'org-latex-src src
))))
1219 (t (format " alt=\"%s\""
1220 (file-name-nondirectory src
)))))))
1223 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1224 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1225 id
(format "\n<p>%s</p>" img
)
1226 (when (and caption
(not (string= caption
"")))
1227 (format "\n<p>%s</p>" caption
)))))
1228 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1230 (defun org-html--textarea-block (element)
1231 "Transcode ELEMENT into a textarea block.
1232 ELEMENT is either a src block or an example block."
1233 (let* ((code (car (org-export-unravel-code element
)))
1234 (attr (org-export-read-attribute :attr_html element
)))
1235 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1236 (or (plist-get attr
:width
) 80)
1237 (or (plist-get attr
:height
) (org-count-lines code
))
1242 (defun org-html-bibliography ()
1243 "Find bibliography, cut it out and return it."
1245 (let (beg end
(cnt 1) bib
)
1247 (goto-char (point-min))
1248 (when (re-search-forward
1249 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1250 (setq beg
(match-beginning 0))
1251 (while (re-search-forward "</?div\\>" nil t
)
1252 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1254 (and (looking-at ">") (forward-char 1))
1255 (setq bib
(buffer-substring beg
(point)))
1256 (delete-region beg
(point))
1257 (throw 'exit bib
))))
1262 (defun org-html-splice-attributes (tag attributes
)
1263 "Return a HTML TAG edited wrt ATTRIBUTES."
1264 (if (not attributes
)
1266 (let (oldatt newatt
)
1267 (setq oldatt
(org-extract-attributes-from-string tag
)
1269 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1271 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1272 (if (string-match ">" tag
)
1274 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1278 (defun org-export-splice-style (style extra
)
1279 "Return STYLE updated wrt EXTRA."
1280 (if (and (stringp extra
)
1281 (string-match "\\S-" extra
)
1282 (string-match "</style>" style
))
1283 (concat (substring style
0 (match-beginning 0))
1285 (substring style
(match-beginning 0)))
1288 (defun org-html-htmlize-region-for-paste (beg end
)
1289 "Convert the region between BEG and END to HTML, using htmlize.el.
1290 This is much like `htmlize-region-for-paste', only that it uses
1291 the settings define in the org-... variables."
1292 (let* ((htmlize-output-type org-html-htmlize-output-type
)
1293 (htmlize-css-name-prefix org-html-htmlize-font-prefix
)
1294 (htmlbuf (htmlize-region beg end
)))
1296 (with-current-buffer htmlbuf
1297 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1298 (plist-get htmlize-buffer-places
'content-end
)))
1299 (kill-buffer htmlbuf
))))
1302 (defun org-html-htmlize-generate-css ()
1303 "Create the CSS for all font definitions in the current Emacs session.
1304 Use this to create face definitions in your CSS style file that can then
1305 be used by code snippets transformed by htmlize.
1306 This command just produces a buffer that contains class definitions for all
1307 faces used in the current Emacs session. You can copy and paste the ones you
1308 need into your CSS file.
1310 If you then set `org-html-htmlize-output-type' to `css', calls
1311 to the function `org-html-htmlize-region-for-paste' will
1312 produce code that uses these same face definitions."
1315 (and (get-buffer "*html*") (kill-buffer "*html*"))
1317 (let ((fl (face-list))
1318 (htmlize-css-name-prefix "org-")
1319 (htmlize-output-type 'css
)
1321 (while (setq f
(pop fl
)
1322 i
(and f
(face-attribute f
:inherit
)))
1323 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1324 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1325 (htmlize-region (point-min) (point-max))))
1326 (org-pop-to-buffer-same-window "*html*")
1327 (goto-char (point-min))
1328 (if (re-search-forward "<style" nil t
)
1329 (delete-region (point-min) (match-beginning 0)))
1330 (if (re-search-forward "</style>" nil t
)
1331 (delete-region (1+ (match-end 0)) (point-max)))
1332 (beginning-of-line 1)
1333 (if (looking-at " +") (replace-match ""))
1334 (goto-char (point-min)))
1336 (defun org-html--make-string (n string
)
1337 "Build a string by concatenating N times STRING."
1338 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1340 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1341 "Turn todo keyword KWD into a valid class name.
1342 Replaces invalid characters with \"_\"."
1344 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1345 (setq kwd
(replace-match "_" t t kwd
))))
1348 (defun org-html-format-footnote-reference (n def refcnt
)
1349 "Format footnote reference N with definition DEF into HTML."
1350 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1351 (format org-html-footnote-format
1352 (let* ((id (format "fnr.%s%s" n extra
))
1353 (href (format " href=\"#fn.%s\"" n
))
1354 (attributes (concat " class=\"footref\"" href
)))
1355 (org-html--anchor id n attributes
)))))
1357 (defun org-html-format-footnotes-section (section-name definitions
)
1358 "Format footnotes section SECTION-NAME."
1359 (if (not definitions
) ""
1360 (format org-html-footnotes-section section-name definitions
)))
1362 (defun org-html-format-footnote-definition (fn)
1363 "Format the footnote definition FN."
1364 (let ((n (car fn
)) (def (cdr fn
)))
1367 (format org-html-footnote-format
1368 (let* ((id (format "fn.%s" n
))
1369 (href (format " href=\"#fnr.%s\"" n
))
1370 (attributes (concat " class=\"footnum\"" href
)))
1371 (org-html--anchor id n attributes
)))
1374 (defun org-html-footnote-section (info)
1375 "Format the footnote section.
1376 INFO is a plist used as a communication channel."
1377 (let* ((fn-alist (org-export-collect-footnote-definitions
1378 (plist-get info
:parse-tree
) info
))
1381 (loop for
(n type raw
) in fn-alist collect
1382 (cons n
(if (eq (org-element-type raw
) 'org-data
)
1383 (org-trim (org-export-data raw info
))
1385 (org-trim (org-export-data raw info
))))))))
1387 (org-html-format-footnotes-section
1388 (org-html--translate "Footnotes" info
)
1391 (mapconcat 'org-html-format-footnote-definition fn-alist
"\n"))))))
1396 (defun org-html--build-meta-info (info)
1397 "Return meta tags for exported document.
1398 INFO is a plist used as a communication channel."
1399 (let* ((title (org-export-data (plist-get info
:title
) info
))
1400 (author (and (plist-get info
:with-author
)
1401 (let ((auth (plist-get info
:author
)))
1402 (and auth
(org-export-data auth info
)))))
1403 (date (and (plist-get info
:with-date
)
1404 (let ((date (plist-get info
:date
)))
1405 (and date
(org-export-data date info
)))))
1406 (description (plist-get info
:description
))
1407 (keywords (plist-get info
:keywords
)))
1409 (format "<title>%s</title>\n" title
)
1411 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1412 (or (and org-html-coding-system
1413 (fboundp 'coding-system-get
)
1414 (coding-system-get org-html-coding-system
'mime-charset
))
1416 (format "<meta name=\"title\" content=\"%s\"/>\n" title
)
1417 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1418 (and date
(format "<meta name=\"generated\" content=\"%s\"/>\n" date
))
1419 (and author
(format "<meta name=\"author\" content=\"%s\"/>\n" author
))
1421 (format "<meta name=\"description\" content=\"%s\"/>\n" description
))
1423 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords
)))))
1425 (defun org-html--build-head (info)
1426 "Return information for the <head>..</head> of the HTML output.
1427 INFO is a plist used as a communication channel."
1428 (org-element-normalize-string
1430 (when (plist-get info
:html-head-include-default-style
)
1431 (org-element-normalize-string org-html-style-default
))
1432 (org-element-normalize-string (plist-get info
:html-head
))
1433 (org-element-normalize-string (plist-get info
:html-head-extra
))
1434 (when (and (plist-get info
:html-htmlized-css-url
)
1435 (eq org-html-htmlize-output-type
'css
))
1436 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1437 (plist-get info
:html-htmlized-css-url
)))
1438 (when (plist-get info
:html-head-include-scripts
) org-html-scripts
))))
1440 (defun org-html--build-mathjax-config (info)
1441 "Insert the user setup into the mathjax template.
1442 INFO is a plist used as a communication channel."
1443 (when (and (memq (plist-get info
:with-latex
) '(mathjax t
))
1444 (org-element-map (plist-get info
:parse-tree
)
1445 '(latex-fragment latex-environment
) 'identity info t
))
1446 (let ((template org-html-mathjax-template
)
1447 (options org-html-mathjax-options
)
1448 (in-buffer (or (plist-get info
:html-mathjax
) ""))
1449 name val
(yes " ") (no "// ") x
)
1452 (setq name
(car e
) val
(nth 1 e
))
1453 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1454 (setq val
(car (read-from-string
1455 (substring in-buffer
(match-end 0))))))
1456 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1457 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1458 (setq template
(replace-match val t t template
))))
1460 (setq val
(nth 1 (assq 'mathml options
)))
1461 (if (string-match (concat "\\<mathml:") in-buffer
)
1462 (setq val
(car (read-from-string
1463 (substring in-buffer
(match-end 0))))))
1464 ;; Exchange prefixes depending on mathml setting.
1465 (if (not val
) (setq x yes yes no no x
))
1466 ;; Replace cookies to turn on or off the config/jax lines.
1467 (if (string-match ":MMLYES:" template
)
1468 (setq template
(replace-match yes t t template
)))
1469 (if (string-match ":MMLNO:" template
)
1470 (setq template
(replace-match no t t template
)))
1471 ;; Return the modified template.
1472 (org-element-normalize-string template
))))
1474 (defun org-html--build-preamble (info)
1475 "Return document preamble as a string, or nil.
1476 INFO is a plist used as a communication channel."
1477 (let ((preamble (plist-get info
:html-preamble
)))
1479 (let ((preamble-contents
1480 (if (functionp preamble
) (funcall preamble info
)
1481 (let ((title (org-export-data (plist-get info
:title
) info
))
1482 (date (if (not (plist-get info
:with-date
)) ""
1483 (org-export-data (plist-get info
:date
) info
)))
1484 (author (if (not (plist-get info
:with-author
)) ""
1485 (org-export-data (plist-get info
:author
) info
)))
1486 (email (if (not (plist-get info
:with-email
)) ""
1487 (plist-get info
:email
))))
1488 (if (stringp preamble
)
1489 (format-spec preamble
1490 `((?t .
,title
) (?a .
,author
)
1491 (?d .
,date
) (?e .
,email
)))
1493 (or (cadr (assoc (plist-get info
:language
)
1494 org-html-preamble-format
))
1495 (cadr (assoc "en" org-html-preamble-format
)))
1496 `((?t .
,title
) (?a .
,author
)
1497 (?d .
,date
) (?e .
,email
))))))))
1498 (when (org-string-nw-p preamble-contents
)
1499 (concat (format "<%s id=\"%s\">\n"
1500 (nth 1 (assq 'preamble org-html-divs
))
1501 (nth 2 (assq 'preamble org-html-divs
)))
1502 (org-element-normalize-string preamble-contents
)
1503 (format "</%s>\n" (nth 1 (assq 'preamble org-html-divs
)))))))))
1505 (defun org-html--build-postamble (info)
1506 "Return document postamble as a string, or nil.
1507 INFO is a plist used as a communication channel."
1508 (let ((postamble (plist-get info
:html-postamble
)))
1510 (let ((postamble-contents
1511 (if (functionp postamble
) (funcall postamble info
)
1512 (let ((date (if (not (plist-get info
:with-date
)) ""
1513 (org-export-data (plist-get info
:date
) info
)))
1514 (author (let ((author (plist-get info
:author
)))
1515 (and author
(org-export-data author info
))))
1518 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1519 (split-string (plist-get info
:email
) ",+ *")
1521 (html-validation-link (or org-html-validation-link
""))
1522 (creator-info (plist-get info
:creator
)))
1523 (cond ((stringp postamble
)
1524 (format-spec postamble
1525 `((?a .
,author
) (?e .
,email
)
1526 (?d .
,date
) (?c .
,creator-info
)
1527 (?v .
,html-validation-link
))))
1528 ((eq postamble
'auto
)
1530 (when (plist-get info
:time-stamp-file
)
1531 (format "<p class=\"date\">%s: %s</p>\n"
1532 (org-html--translate "Date" info
)
1534 (when (and (plist-get info
:with-author
) author
)
1535 (format "<p class=\"author\">%s : %s</p>\n"
1536 (org-html--translate "Author" info
)
1538 (when (and (plist-get info
:with-email
) email
)
1539 (format "<p class=\"email\">%s </p>\n" email
))
1540 (when (plist-get info
:with-creator
)
1541 (format "<p class=\"creator\">%s</p>\n"
1543 html-validation-link
"\n"))
1545 (or (cadr (assoc (plist-get info
:language
)
1546 org-html-postamble-format
))
1547 (cadr (assoc "en" org-html-postamble-format
)))
1548 `((?a .
,author
) (?e .
,email
)
1549 (?d .
,date
) (?c .
,creator-info
)
1550 (?v .
,html-validation-link
)))))))))
1551 (when (org-string-nw-p postamble-contents
)
1553 (format "<%s id=\"%s\">\n"
1554 (nth 1 (assq 'postamble org-html-divs
))
1555 (nth 2 (assq 'postamble org-html-divs
)))
1556 (org-element-normalize-string postamble-contents
)
1557 (format "</%s>\n" (nth 1 (assq 'postamble org-html-divs
)))))))))
1559 (defun org-html-inner-template (contents info
)
1560 "Return body of document string after HTML conversion.
1561 CONTENTS is the transcoded contents string. INFO is a plist
1562 holding export options."
1564 ;; Table of contents.
1565 (let ((depth (plist-get info
:with-toc
)))
1566 (when depth
(org-html-toc depth info
)))
1567 ;; Document contents.
1569 ;; Footnotes section.
1570 (org-html-footnote-section info
)
1572 (org-html-bibliography)))
1574 (defun org-html-template (contents info
)
1575 "Return complete document string after HTML conversion.
1576 CONTENTS is the transcoded contents string. INFO is a plist
1577 holding export options."
1580 (or (and (stringp org-html-xml-declaration
)
1581 org-html-xml-declaration
)
1582 (cdr (assoc (plist-get info
:html-extension
)
1583 org-html-xml-declaration
))
1584 (cdr (assoc "html" org-html-xml-declaration
))
1587 (or (and org-html-coding-system
1588 (fboundp 'coding-system-get
)
1589 (coding-system-get org-html-coding-system
'mime-charset
))
1592 (plist-get info
:html-doctype
)
1594 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1595 (plist-get info
:language
) (plist-get info
:language
))
1597 (org-html--build-meta-info info
)
1598 (org-html--build-head info
)
1599 (org-html--build-mathjax-config info
)
1602 (let ((link-up (org-trim (plist-get info
:html-link-up
)))
1603 (link-home (org-trim (plist-get info
:html-link-home
))))
1604 (unless (and (string= link-up
"") (string= link-up
""))
1605 (format org-html-home
/up-format
1606 (or link-up link-home
)
1607 (or link-home link-up
))))
1609 (org-html--build-preamble info
)
1610 ;; Document contents.
1611 (format "<%s id=\"%s\">\n"
1612 (nth 1 (assq 'content org-html-divs
))
1613 (nth 2 (assq 'content org-html-divs
)))
1615 (let ((title (plist-get info
:title
)))
1616 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title
"") info
)))
1619 (nth 1 (assq 'content org-html-divs
)))
1621 (org-html--build-postamble info
)
1622 ;; Closing document.
1623 "</body>\n</html>"))
1625 (defun org-html--translate (s info
)
1626 "Translate string S according to specified language.
1627 INFO is a plist used as a communication channel."
1628 (org-export-translate s
:html info
))
1632 (defun org-html--anchor (&optional id desc attributes
)
1633 "Format a HTML anchor."
1634 (let* ((name (and org-html-allow-name-attribute-in-anchors id
))
1635 (attributes (concat (and id
(format " id=\"%s\"" id
))
1636 (and name
(format " name=\"%s\"" name
))
1638 (format "<a%s>%s</a>" attributes
(or desc
""))))
1642 (defun org-html--todo (todo)
1643 "Format TODO keywords into HTML."
1645 (format "<span class=\"%s %s%s\">%s</span>"
1646 (if (member todo org-done-keywords
) "done" "todo")
1647 org-html-todo-kwd-class-prefix
(org-html-fix-class-name todo
)
1652 (defun org-html--tags (tags)
1653 "Format TAGS into HTML."
1655 (format "<span class=\"tag\">%s</span>"
1658 (format "<span class=\"%s\">%s</span>"
1659 (concat org-html-tag-class-prefix
1660 (org-html-fix-class-name tag
))
1666 (defun* org-html-format-headline
1667 (todo todo-type priority text tags
1668 &key level section-number headline-label
&allow-other-keys
)
1669 "Format a headline in HTML."
1670 (let ((section-number
1671 (when section-number
1672 (format "<span class=\"section-number-%d\">%s</span> "
1673 level section-number
)))
1674 (todo (org-html--todo todo
))
1675 (tags (org-html--tags tags
)))
1676 (concat section-number todo
(and todo
" ") text
1677 (and tags
"   ") tags
)))
1681 (defun org-html-fontify-code (code lang
)
1682 "Color CODE with htmlize library.
1683 CODE is a string representing the source code to colorize. LANG
1684 is the language used for CODE, as a string, or nil."
1687 ;; Case 1: No lang. Possibly an example block.
1689 ;; Simple transcoding.
1690 (org-html-encode-plain-text code
))
1691 ;; Case 2: No htmlize or an inferior version of htmlize
1692 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1694 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1695 ;; Simple transcoding.
1696 (org-html-encode-plain-text code
))
1699 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1700 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1702 ;; Case 1: Language is not associated with any Emacs mode
1703 ((not (functionp lang-mode
))
1704 ;; Simple transcoding.
1705 (org-html-encode-plain-text code
))
1706 ;; Case 2: Default. Fontify code.
1709 (setq code
(with-temp-buffer
1710 ;; Switch to language-specific mode.
1714 (font-lock-fontify-buffer)
1715 ;; Remove formatting on newline characters.
1717 (let ((beg (point-min))
1720 (while (progn (end-of-line) (< (point) end
))
1721 (put-text-property (point) (1+ (point)) 'face nil
)
1724 (set-buffer-modified-p nil
)
1726 (org-html-htmlize-region-for-paste
1727 (point-min) (point-max))))
1728 ;; Strip any enclosing <pre></pre> tags.
1729 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code
) (match-end 0)))
1730 (end (and beg
(string-match "</pre>\\'" code
))))
1731 (if (and beg end
) (substring code beg end
) code
)))))))))
1733 (defun org-html-do-format-code
1734 (code &optional lang refs retain-labels num-start
)
1735 "Format CODE string as source code.
1736 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1737 respectively, the language of the source code, as a string, an
1738 alist between line numbers and references (as returned by
1739 `org-export-unravel-code'), a boolean specifying if labels should
1740 appear in the source code, and the number associated to the first
1742 (let* ((code-lines (org-split-string code
"\n"))
1743 (code-length (length code-lines
))
1747 (length (number-to-string (+ code-length num-start
))))))
1748 (code (org-html-fontify-code code lang
)))
1749 (org-export-format-code
1751 (lambda (loc line-num ref
)
1754 ;; Add line number, if needed.
1756 (format "<span class=\"linenr\">%s</span>"
1757 (format num-fmt line-num
)))
1758 ;; Transcoded src line.
1760 ;; Add label, if needed.
1761 (when (and ref retain-labels
) (format " (%s)" ref
))))
1762 ;; Mark transcoded line as an anchor, if needed.
1764 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1768 (defun org-html-format-code (element info
)
1769 "Format contents of ELEMENT as source code.
1770 ELEMENT is either an example block or a src block. INFO is
1771 a plist used as a communication channel."
1772 (let* ((lang (org-element-property :language element
))
1773 ;; Extract code and references.
1774 (code-info (org-export-unravel-code element
))
1775 (code (car code-info
))
1776 (refs (cdr code-info
))
1777 ;; Does the src block contain labels?
1778 (retain-labels (org-element-property :retain-labels element
))
1779 ;; Does it have line numbers?
1780 (num-start (case (org-element-property :number-lines element
)
1781 (continued (org-export-get-loc element info
))
1783 (org-html-do-format-code code lang refs retain-labels num-start
)))
1786 ;;; Tables of Contents
1788 (defun org-html-toc (depth info
)
1789 "Build a table of contents.
1790 DEPTH is an integer specifying the depth of the table. INFO is a
1791 plist used as a communication channel. Return the table of
1792 contents as a string, or nil if it is empty."
1794 (mapcar (lambda (headline)
1795 (cons (org-html--format-toc-headline headline info
)
1796 (org-export-get-relative-level headline info
)))
1797 (org-export-collect-headlines info depth
))))
1799 (concat "<div id=\"table-of-contents\">\n"
1800 (format "<h%d>%s</h%d>\n"
1801 org-html-toplevel-hlevel
1802 (org-html--translate "Table of Contents" info
)
1803 org-html-toplevel-hlevel
)
1804 "<div id=\"text-table-of-contents\">"
1805 (org-html--toc-text toc-entries
)
1809 (defun org-html--toc-text (toc-entries)
1810 "Return innards of a table of contents, as a string.
1811 TOC-ENTRIES is an alist where key is an entry title, as a string,
1812 and value is its relative level, as an integer."
1813 (let* ((prev-level (1- (cdar toc-entries
)))
1814 (start-level prev-level
))
1818 (let ((headline (car entry
))
1819 (level (cdr entry
)))
1821 (let* ((cnt (- level prev-level
))
1822 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1824 (setq prev-level level
)
1826 (org-html--make-string
1827 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1828 ((< cnt
0) "</li>\n</ul>\n")))
1829 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1832 (org-html--make-string (- prev-level start-level
) "</li>\n</ul>\n"))))
1834 (defun org-html--format-toc-headline (headline info
)
1835 "Return an appropriate table of contents entry for HEADLINE.
1836 INFO is a plist used as a communication channel."
1837 (let* ((headline-number (org-export-get-headline-number headline info
))
1839 (and (not (org-export-low-level-p headline info
))
1840 (org-export-numbered-headline-p headline info
)
1841 (concat (mapconcat 'number-to-string headline-number
".") ". ")))
1842 (tags (and (eq (plist-get info
:with-tags
) t
)
1843 (org-export-get-tags headline info
))))
1844 (format "<a href=\"#%s\">%s</a>"
1846 (org-export-solidify-link-text
1847 (or (org-element-property :CUSTOM_ID headline
)
1848 (concat "sec-" (mapconcat 'number-to-string
1849 headline-number
"-"))))
1851 (concat section-number
1852 (org-export-data-with-translations
1853 (org-export-get-alt-title headline info
)
1854 ;; Ignore any footnote-reference, link,
1855 ;; radio-target and target in table of contents.
1857 '((footnote-reference . ignore
)
1858 (link .
(lambda (link desc i
) desc
))
1859 (radio-target .
(lambda (radio desc i
) desc
))
1861 (org-export-backend-translate-table 'html
))
1863 (and tags
"   ") (org-html--tags tags
)))))
1865 (defun org-html-list-of-listings (info)
1866 "Build a list of listings.
1867 INFO is a plist used as a communication channel. Return the list
1868 of listings as a string, or nil if it is empty."
1869 (let ((lol-entries (org-export-collect-listings info
)))
1871 (concat "<div id=\"list-of-listings\">\n"
1872 (format "<h%d>%s</h%d>\n"
1873 org-html-toplevel-hlevel
1874 (org-html--translate "List of Listings" info
)
1875 org-html-toplevel-hlevel
)
1876 "<div id=\"text-list-of-listings\">\n<ul>\n"
1878 (initial-fmt (org-html--translate "Listing %d:" info
)))
1881 (let ((label (org-element-property :name entry
))
1884 (or (org-export-get-caption entry t
)
1885 (org-export-get-caption entry
))
1890 (concat (format initial-fmt
(incf count
)) " " title
)
1891 (format "<a href=\"#%s\">%s %s</a>"
1892 (org-export-solidify-link-text label
)
1893 (format initial-fmt
(incf count
))
1897 "\n</ul>\n</div>\n</div>"))))
1899 (defun org-html-list-of-tables (info)
1900 "Build a list of tables.
1901 INFO is a plist used as a communication channel. Return the list
1902 of tables as a string, or nil if it is empty."
1903 (let ((lol-entries (org-export-collect-tables info
)))
1905 (concat "<div id=\"list-of-tables\">\n"
1906 (format "<h%d>%s</h%d>\n"
1907 org-html-toplevel-hlevel
1908 (org-html--translate "List of Tables" info
)
1909 org-html-toplevel-hlevel
)
1910 "<div id=\"text-list-of-tables\">\n<ul>\n"
1912 (initial-fmt (org-html--translate "Table %d:" info
)))
1915 (let ((label (org-element-property :name entry
))
1918 (or (org-export-get-caption entry t
)
1919 (org-export-get-caption entry
))
1924 (concat (format initial-fmt
(incf count
)) " " title
)
1925 (format "<a href=\"#%s\">%s %s</a>"
1926 (org-export-solidify-link-text label
)
1927 (format initial-fmt
(incf count
))
1931 "\n</ul>\n</div>\n</div>"))))
1934 ;;; Transcode Functions
1938 (defun org-html-bold (bold contents info
)
1939 "Transcode BOLD from Org to HTML.
1940 CONTENTS is the text with bold markup. INFO is a plist holding
1941 contextual information."
1942 (format (or (cdr (assq 'bold org-html-text-markup-alist
)) "%s")
1947 (defun org-html-center-block (center-block contents info
)
1948 "Transcode a CENTER-BLOCK element from Org to HTML.
1949 CONTENTS holds the contents of the block. INFO is a plist
1950 holding contextual information."
1951 (format "<div class=\"center\">\n%s</div>" contents
))
1955 (defun org-html-clock (clock contents info
)
1956 "Transcode a CLOCK element from Org to HTML.
1957 CONTENTS is nil. INFO is a plist used as a communication
1960 <span class=\"timestamp-wrapper\">
1961 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1966 (org-element-property :raw-value
1967 (org-element-property :value clock
)))
1968 (let ((time (org-element-property :duration clock
)))
1969 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1973 (defun org-html-code (code contents info
)
1974 "Transcode CODE from Org to HTML.
1975 CONTENTS is nil. INFO is a plist holding contextual
1977 (format (or (cdr (assq 'code org-html-text-markup-alist
)) "%s")
1978 (org-html-plain-text (org-element-property :value code
) info
)))
1982 (defun org-html-drawer (drawer contents info
)
1983 "Transcode a DRAWER element from Org to HTML.
1984 CONTENTS holds the contents of the block. INFO is a plist
1985 holding contextual information."
1986 (if (functionp org-html-format-drawer-function
)
1987 (funcall org-html-format-drawer-function
1988 (org-element-property :drawer-name drawer
)
1990 ;; If there's no user defined function: simply
1991 ;; display contents of the drawer.
1996 (defun org-html-dynamic-block (dynamic-block contents info
)
1997 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1998 CONTENTS holds the contents of the block. INFO is a plist
1999 holding contextual information. See `org-export-data'."
2004 (defun org-html-entity (entity contents info
)
2005 "Transcode an ENTITY object from Org to HTML.
2006 CONTENTS are the definition itself. INFO is a plist holding
2007 contextual information."
2008 (org-element-property :html entity
))
2012 (defun org-html-example-block (example-block contents info
)
2013 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2014 CONTENTS is nil. INFO is a plist holding contextual
2016 (if (org-export-read-attribute :attr_html example-block
:textarea
)
2017 (org-html--textarea-block example-block
)
2018 (format "<pre class=\"example\">\n%s</pre>"
2019 (org-html-format-code example-block info
))))
2023 (defun org-html-export-snippet (export-snippet contents info
)
2024 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2025 CONTENTS is nil. INFO is a plist holding contextual
2027 (when (eq (org-export-snippet-backend export-snippet
) 'html
)
2028 (org-element-property :value export-snippet
)))
2032 (defun org-html-export-block (export-block contents info
)
2033 "Transcode a EXPORT-BLOCK element from Org to HTML.
2034 CONTENTS is nil. INFO is a plist holding contextual information."
2035 (when (string= (org-element-property :type export-block
) "HTML")
2036 (org-remove-indentation (org-element-property :value export-block
))))
2040 (defun org-html-fixed-width (fixed-width contents info
)
2041 "Transcode a FIXED-WIDTH element from Org to HTML.
2042 CONTENTS is nil. INFO is a plist holding contextual information."
2043 (format "<pre class=\"example\">\n%s</pre>"
2044 (org-html-do-format-code
2045 (org-remove-indentation
2046 (org-element-property :value fixed-width
)))))
2048 ;;;; Footnote Reference
2050 (defun org-html-footnote-reference (footnote-reference contents info
)
2051 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2052 CONTENTS is nil. INFO is a plist holding contextual information."
2054 ;; Insert separator between two footnotes in a row.
2055 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2056 (when (eq (org-element-type prev
) 'footnote-reference
)
2057 org-html-footnote-separator
))
2059 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2060 (org-html-format-footnote-reference
2061 (org-export-get-footnote-number footnote-reference info
)
2063 ;; Inline definitions are secondary strings.
2064 ((eq (org-element-property :type footnote-reference
) 'inline
)
2065 (org-html-format-footnote-reference
2066 (org-export-get-footnote-number footnote-reference info
)
2068 ;; Non-inline footnotes definitions are full Org data.
2069 (t (org-html-format-footnote-reference
2070 (org-export-get-footnote-number footnote-reference info
)
2075 (defun org-html-format-headline--wrap
2076 (headline info
&optional format-function
&rest extra-keys
)
2077 "Transcode a HEADLINE element from Org to HTML.
2078 CONTENTS holds the contents of the headline. INFO is a plist
2079 holding contextual information."
2080 (let* ((level (+ (org-export-get-relative-level headline info
)
2081 (1- org-html-toplevel-hlevel
)))
2082 (headline-number (org-export-get-headline-number headline info
))
2083 (section-number (and (not (org-export-low-level-p headline info
))
2084 (org-export-numbered-headline-p headline info
)
2085 (mapconcat 'number-to-string
2086 headline-number
".")))
2087 (todo (and (plist-get info
:with-todo-keywords
)
2088 (let ((todo (org-element-property :todo-keyword headline
)))
2089 (and todo
(org-export-data todo info
)))))
2090 (todo-type (and todo
(org-element-property :todo-type headline
)))
2091 (priority (and (plist-get info
:with-priority
)
2092 (org-element-property :priority headline
)))
2093 (text (org-export-data (org-element-property :title headline
) info
))
2094 (tags (and (plist-get info
:with-tags
)
2095 (org-export-get-tags headline info
)))
2096 (headline-label (or (org-element-property :CUSTOM_ID headline
)
2097 (concat "sec-" (mapconcat 'number-to-string
2098 headline-number
"-"))))
2099 (format-function (cond
2100 ((functionp format-function
) format-function
)
2101 ((functionp org-html-format-headline-function
)
2103 (lambda (todo todo-type priority text tags
2105 (funcall org-html-format-headline-function
2106 todo todo-type priority text tags
))))
2107 (t 'org-html-format-headline
))))
2108 (apply format-function
2109 todo todo-type priority text tags
2110 :headline-label headline-label
:level level
2111 :section-number section-number extra-keys
)))
2113 (defun org-html-headline (headline contents info
)
2114 "Transcode a HEADLINE element from Org to HTML.
2115 CONTENTS holds the contents of the headline. INFO is a plist
2116 holding contextual information."
2118 (setq contents
(or contents
""))
2119 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2120 (level (org-export-get-relative-level headline info
))
2121 (text (org-export-data (org-element-property :title headline
) info
))
2122 (todo (and (plist-get info
:with-todo-keywords
)
2123 (let ((todo (org-element-property :todo-keyword headline
)))
2124 (and todo
(org-export-data todo info
)))))
2125 (todo-type (and todo
(org-element-property :todo-type headline
)))
2126 (tags (and (plist-get info
:with-tags
)
2127 (org-export-get-tags headline info
)))
2128 (priority (and (plist-get info
:with-priority
)
2129 (org-element-property :priority headline
)))
2130 (section-number (and (org-export-numbered-headline-p headline info
)
2131 (mapconcat 'number-to-string
2132 (org-export-get-headline-number
2133 headline info
) ".")))
2134 ;; Create the headline text.
2135 (full-text (org-html-format-headline--wrap headline info
)))
2137 ;; Case 1: This is a footnote section: ignore it.
2138 ((org-element-property :footnote-section-p headline
) nil
)
2139 ;; Case 2. This is a deep sub-tree: export it as a list item.
2140 ;; Also export as items headlines for which no section
2141 ;; format has been found.
2142 ((org-export-low-level-p headline info
)
2143 ;; Build the real contents of the sub-tree.
2144 (let* ((type (if numberedp
'ordered
'unordered
))
2145 (itemized-body (org-html-format-list-item
2146 contents type nil nil full-text
)))
2148 (and (org-export-first-sibling-p headline info
)
2149 (org-html-begin-plain-list type
))
2151 (and (org-export-last-sibling-p headline info
)
2152 (org-html-end-plain-list type
)))))
2153 ;; Case 3. Standard headline. Export it as a section.
2155 (let* ((section-number (mapconcat 'number-to-string
2156 (org-export-get-headline-number
2157 headline info
) "-"))
2159 (list (org-element-property :CUSTOM_ID headline
)
2160 (concat "sec-" section-number
)
2161 (org-element-property :ID headline
))))
2162 (preferred-id (car ids
))
2163 (extra-ids (cdr ids
))
2164 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline
))
2165 (level1 (+ level
(1- org-html-toplevel-hlevel
)))
2166 (first-content (car (org-element-contents headline
))))
2167 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2168 (if (= 1 (org-export-get-relative-level headline info
))
2169 (plist-get info
:html-container
)
2171 (format "outline-container-%s"
2172 (or (org-element-property :CUSTOM_ID headline
)
2174 (concat (format "outline-%d" level1
) (and extra-class
" ")
2176 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2181 (let ((id (org-export-solidify-link-text
2182 (if (org-uuidgen-p x
) (concat "ID-" x
)
2184 (org-html--anchor id
)))
2188 ;; When there is no section, pretend there is an empty
2189 ;; one to get the correct <div class="outline- ...>
2190 ;; which is needed by `org-info.js'.
2191 (if (not (eq (org-element-type first-content
) 'section
))
2192 (concat (org-html-section first-content
"" info
)
2195 (if (= 1 (org-export-get-relative-level headline info
))
2196 (plist-get info
:html-container
)
2199 ;;;; Horizontal Rule
2201 (defun org-html-horizontal-rule (horizontal-rule contents info
)
2202 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2203 CONTENTS is nil. INFO is a plist holding contextual information."
2206 ;;;; Inline Src Block
2208 (defun org-html-inline-src-block (inline-src-block contents info
)
2209 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2210 CONTENTS holds the contents of the item. INFO is a plist holding
2211 contextual information."
2212 (let* ((org-lang (org-element-property :language inline-src-block
))
2213 (code (org-element-property :value inline-src-block
)))
2214 (error "Cannot export inline src block")))
2218 (defun org-html-format-section (text class
&optional id
)
2219 "Format a section with TEXT into a HTML div with CLASS and ID."
2220 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2221 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2223 (defun org-html-inlinetask (inlinetask contents info
)
2224 "Transcode an INLINETASK element from Org to HTML.
2225 CONTENTS holds the contents of the block. INFO is a plist
2226 holding contextual information."
2228 ;; If `org-html-format-inlinetask-function' is provided, call it
2229 ;; with appropriate arguments.
2230 ((functionp org-html-format-inlinetask-function
)
2231 (let ((format-function
2233 (lambda (todo todo-type priority text tags
2234 &key contents
&allow-other-keys
)
2235 (funcall org-html-format-inlinetask-function
2236 todo todo-type priority text tags contents
)))))
2237 (org-html-format-headline--wrap
2238 inlinetask info format-function
:contents contents
)))
2239 ;; Otherwise, use a default template.
2240 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2241 (org-html-format-headline--wrap inlinetask info
)
2246 (defun org-html-italic (italic contents info
)
2247 "Transcode ITALIC from Org to HTML.
2248 CONTENTS is the text with italic markup. INFO is a plist holding
2249 contextual information."
2250 (format (or (cdr (assq 'italic org-html-text-markup-alist
)) "%s") contents
))
2254 (defun org-html-checkbox (checkbox)
2255 "Format CHECKBOX into HTML."
2256 (case checkbox
(on "<code>[X]</code>")
2257 (off "<code>[ ]</code>")
2258 (trans "<code>[-]</code>")
2261 (defun org-html-format-list-item (contents type checkbox
2262 &optional term-counter-id
2264 "Format a list item into HTML."
2265 (let ((checkbox (concat (org-html-checkbox checkbox
) (and checkbox
" "))))
2269 (let* ((counter term-counter-id
)
2270 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2272 (format "<li%s>" extra
)
2273 (when headline
(concat headline
"<br/>")))))
2275 (let* ((id term-counter-id
)
2276 (extra (if id
(format " id=\"%s\"" id
) "")))
2278 (format "<li%s>" extra
)
2279 (when headline
(concat headline
"<br/>")))))
2281 (let* ((term term-counter-id
))
2282 (setq term
(or term
"(no term)"))
2283 ;; Check-boxes in descriptive lists are associated to tag.
2284 (concat (format "<dt> %s </dt>"
2285 (concat checkbox term
))
2287 (unless (eq type
'descriptive
) checkbox
)
2292 (descriptive "</dd>")))))
2294 (defun org-html-item (item contents info
)
2295 "Transcode an ITEM element from Org to HTML.
2296 CONTENTS holds the contents of the item. INFO is a plist holding
2297 contextual information."
2298 (let* ((plain-list (org-export-get-parent item
))
2299 (type (org-element-property :type plain-list
))
2300 (counter (org-element-property :counter item
))
2301 (checkbox (org-element-property :checkbox item
))
2302 (tag (let ((tag (org-element-property :tag item
)))
2303 (and tag
(org-export-data tag info
)))))
2304 (org-html-format-list-item
2305 contents type checkbox
(or tag counter
))))
2309 (defun org-html-keyword (keyword contents info
)
2310 "Transcode a KEYWORD element from Org to HTML.
2311 CONTENTS is nil. INFO is a plist holding contextual information."
2312 (let ((key (org-element-property :key keyword
))
2313 (value (org-element-property :value keyword
)))
2315 ((string= key
"HTML") value
)
2316 ;; Invisible targets.
2317 ((string= key
"TARGET") nil
)
2318 ((string= key
"TOC")
2319 (let ((value (downcase value
)))
2321 ((string-match "\\<headlines\\>" value
)
2322 (let ((depth (or (and (string-match "[0-9]+" value
)
2323 (string-to-number (match-string 0 value
)))
2324 (plist-get info
:with-toc
))))
2325 (org-html-toc depth info
)))
2326 ((string= "listings" value
) (org-html-list-of-listings info
))
2327 ((string= "tables" value
) (org-html-list-of-tables info
))))))))
2329 ;;;; Latex Environment
2331 (defun org-html-format-latex (latex-frag processing-type
)
2332 "Format the LaTeX fragment LATEX-FRAG into HTML."
2333 (let ((cache-relpath "") (cache-dir "") bfn
)
2334 (unless (eq processing-type
'mathjax
)
2335 (setq bfn
(buffer-file-name)
2338 (file-name-sans-extension
2339 (file-name-nondirectory bfn
)))
2340 cache-dir
(file-name-directory bfn
)))
2343 (org-format-latex cache-relpath cache-dir nil
"Creating LaTeX Image..."
2344 nil nil processing-type
)
2347 (defun org-html-latex-environment (latex-environment contents info
)
2348 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2349 CONTENTS is nil. INFO is a plist holding contextual information."
2350 (let ((processing-type (plist-get info
:with-latex
))
2351 (latex-frag (org-remove-indentation
2352 (org-element-property :value latex-environment
)))
2353 (caption (org-export-data
2354 (org-export-get-caption latex-environment
) info
))
2356 (label (org-element-property :name latex-environment
)))
2358 ((memq processing-type
'(t mathjax
))
2359 (org-html-format-latex latex-frag
'mathjax
))
2360 ((eq processing-type
'dvipng
)
2361 (let* ((formula-link (org-html-format-latex
2362 latex-frag processing-type
)))
2363 (when (and formula-link
2364 (string-match "file:\\([^]]*\\)" formula-link
))
2365 (org-html-format-inline-image
2366 (match-string 1 formula-link
) caption label attr t
))))
2371 (defun org-html-latex-fragment (latex-fragment contents info
)
2372 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2373 CONTENTS is nil. INFO is a plist holding contextual information."
2374 (let ((latex-frag (org-element-property :value latex-fragment
))
2375 (processing-type (plist-get info
:with-latex
)))
2376 (case processing-type
2378 (org-html-format-latex latex-frag
'mathjax
))
2380 (let* ((formula-link (org-html-format-latex
2381 latex-frag processing-type
)))
2382 (when (and formula-link
2383 (string-match "file:\\([^]]*\\)" formula-link
))
2384 (org-html-format-inline-image
2385 (match-string 1 formula-link
)))))
2390 (defun org-html-line-break (line-break contents info
)
2391 "Transcode a LINE-BREAK object from Org to HTML.
2392 CONTENTS is nil. INFO is a plist holding contextual information."
2397 (defun org-html-link--inline-image (link desc info
)
2398 "Return HTML code for an inline image.
2399 LINK is the link pointing to the inline image. INFO is a plist
2400 used as a communication channel."
2401 (let* ((type (org-element-property :type link
))
2402 (raw-path (org-element-property :path link
))
2403 (path (cond ((member type
'("http" "https"))
2404 (concat type
":" raw-path
))
2405 ((file-name-absolute-p raw-path
)
2406 (expand-file-name raw-path
))
2408 (parent (org-export-get-parent-element link
))
2409 (caption (org-export-data (org-export-get-caption parent
) info
))
2410 (label (org-element-property :name parent
))
2411 (attr (mapconcat #'identity
(org-element-property :attr_html parent
) " ")))
2412 ;; Return proper string, depending on DISPOSITION.
2413 (org-html-format-inline-image
2414 path caption label attr
(org-html-standalone-image-p link info
))))
2416 (defvar org-html-standalone-image-predicate
)
2417 (defun org-html-standalone-image-p (element info
&optional predicate
)
2418 "Test if ELEMENT is a standalone image for the purpose HTML export.
2419 INFO is a plist holding contextual information.
2421 Return non-nil, if ELEMENT is of type paragraph and it's sole
2422 content, save for whitespaces, is a link that qualifies as an
2425 Return non-nil, if ELEMENT is of type link and it's containing
2426 paragraph has no other content save for leading and trailing
2429 Return nil, otherwise.
2431 Bind `org-html-standalone-image-predicate' to constrain
2432 paragraph further. For example, to check for only captioned
2433 standalone images, do the following.
2435 \(setq org-html-standalone-image-predicate
2436 \(lambda \(paragraph\)
2437 \(org-element-property :caption paragraph\)\)\)"
2438 (let ((paragraph (case (org-element-type element
)
2440 (link (and (org-export-inline-image-p
2441 element org-html-inline-image-rules
)
2442 (org-export-get-parent element
)))
2444 (when (eq (org-element-type paragraph
) 'paragraph
)
2445 (when (or (not (and (boundp 'org-html-standalone-image-predicate
)
2446 (functionp org-html-standalone-image-predicate
)))
2447 (funcall org-html-standalone-image-predicate paragraph
))
2448 (let ((contents (org-element-contents paragraph
)))
2449 (loop for x in contents
2450 with inline-image-count
= 0
2452 ((eq (org-element-type x
) 'plain-text
)
2453 (not (org-string-nw-p x
)))
2454 ((eq (org-element-type x
) 'link
)
2455 (when (org-export-inline-image-p
2456 x org-html-inline-image-rules
)
2457 (= (incf inline-image-count
) 1)))
2460 (defun org-html-link (link desc info
)
2461 "Transcode a LINK object from Org to HTML.
2463 DESC is the description part of the link, or the empty string.
2464 INFO is a plist holding contextual information. See
2466 (let* ((--link-org-files-as-html-maybe
2468 (lambda (raw-path info
)
2469 "Treat links to `file.org' as links to `file.html', if needed.
2470 See `org-html-link-org-files-as-html'."
2472 ((and org-html-link-org-files-as-html
2474 (downcase (file-name-extension raw-path
"."))))
2475 (concat (file-name-sans-extension raw-path
) "."
2476 (plist-get info
:html-extension
)))
2478 (type (org-element-property :type link
))
2479 (raw-path (org-element-property :path link
))
2480 ;; Ensure DESC really exists, or set it to nil.
2481 (desc (and (not (string= desc
"")) desc
))
2484 ((member type
'("http" "https" "ftp" "mailto"))
2485 (concat type
":" raw-path
))
2486 ((string= type
"file")
2487 ;; Treat links to ".org" files as ".html", if needed.
2489 (funcall --link-org-files-as-html-maybe raw-path info
))
2490 ;; If file path is absolute, prepend it with protocol
2491 ;; component - "file://".
2492 (when (file-name-absolute-p raw-path
)
2494 (concat "file://" (expand-file-name raw-path
))))
2495 ;; Add search option, if any. A search option can be
2496 ;; relative to a custom-id or a headline title. Any other
2497 ;; option is ignored.
2498 (let ((option (org-element-property :search-option link
)))
2499 (cond ((not option
) raw-path
)
2500 ((eq (aref option
0) ?
#) (concat raw-path option
))
2501 ;; External fuzzy link: try to resolve it if path
2502 ;; belongs to current project, if any.
2503 ((eq (aref option
0) ?
*)
2507 (org-publish-resolve-external-fuzzy-link
2508 (org-element-property :path link
) option
)))
2509 (and numbers
(concat "#sec-"
2510 (mapconcat 'number-to-string
2511 numbers
"-")))))))))
2513 attributes protocol
)
2514 ;; Extract attributes from parent's paragraph. HACK: Only do this
2515 ;; for the first link in parent. This is needed as long as
2516 ;; attributes cannot be set on a per link basis.
2517 (and (setq attributes
2518 (let ((parent (org-export-get-parent-element link
)))
2519 (if (not (eq (org-element-map parent
'link
'identity info t
)
2524 (let ((att (org-element-property :attr_html parent
)))
2525 (unless (and desc att
2526 (string-match (regexp-quote (car att
)) desc
))
2529 (unless (string= attributes
"")
2530 (setq attributes
(concat " " attributes
))))
2533 ((and (or (eq t org-html-inline-images
)
2534 (and org-html-inline-images
(not desc
)))
2535 (org-export-inline-image-p link org-html-inline-image-rules
))
2536 (org-html-link--inline-image link desc info
))
2537 ;; Radio target: Transcode target's contents and use them as
2538 ;; link's description.
2539 ((string= type
"radio")
2540 (let ((destination (org-export-resolve-radio-link link info
)))
2542 (format "<a href=\"#%s\"%s>%s</a>"
2543 (org-export-solidify-link-text path
)
2545 (org-export-data (org-element-contents destination
) info
)))))
2546 ;; Links pointing to a headline: Find destination and build
2547 ;; appropriate referencing command.
2548 ((member type
'("custom-id" "fuzzy" "id"))
2549 (let ((destination (if (string= type
"fuzzy")
2550 (org-export-resolve-fuzzy-link link info
)
2551 (org-export-resolve-id-link link info
))))
2552 (case (org-element-type destination
)
2553 ;; ID link points to an external file.
2555 (let ((fragment (concat "ID-" path
))
2556 ;; Treat links to ".org" files as ".html", if needed.
2557 (path (funcall --link-org-files-as-html-maybe
2559 (format "<a href=\"%s#%s\"%s>%s</a>"
2560 path fragment attributes
(or desc destination
))))
2561 ;; Fuzzy link points nowhere.
2566 (org-element-property :raw-link link
) info
))))
2567 ;; Fuzzy link points to an invisible target.
2569 ;; Link points to a headline.
2572 ;; What href to use?
2574 ;; Case 1: Headline is linked via it's CUSTOM_ID
2575 ;; property. Use CUSTOM_ID.
2576 ((string= type
"custom-id")
2577 (org-element-property :CUSTOM_ID destination
))
2578 ;; Case 2: Headline is linked via it's ID property
2579 ;; or through other means. Use the default href.
2580 ((member type
'("id" "fuzzy"))
2582 (mapconcat 'number-to-string
2583 (org-export-get-headline-number
2584 destination info
) "-")))
2585 (t (error "Shouldn't reach here"))))
2586 ;; What description to use?
2588 ;; Case 1: Headline is numbered and LINK has no
2589 ;; description or LINK's description matches
2590 ;; headline's title. Display section number.
2591 (if (and (org-export-numbered-headline-p destination info
)
2593 (string= desc
(org-element-property
2594 :raw-value destination
))))
2595 (mapconcat 'number-to-string
2596 (org-export-get-headline-number
2597 destination info
) ".")
2598 ;; Case 2: Either the headline is un-numbered or
2599 ;; LINK has a custom description. Display LINK's
2600 ;; description or headline's title.
2601 (or desc
(org-export-data (org-element-property
2602 :title destination
) info
)))))
2603 (format "<a href=\"#%s\"%s>%s</a>"
2604 (org-export-solidify-link-text href
) attributes desc
)))
2605 ;; Fuzzy link points to a target. Do as above.
2607 (let ((path (org-export-solidify-link-text path
)) number
)
2610 ((org-html-standalone-image-p destination info
)
2611 (org-export-get-ordinal
2612 (assoc 'link
(org-element-contents destination
))
2613 info
'link
'org-html-standalone-image-p
))
2614 (t (org-export-get-ordinal destination info
))))
2615 (setq desc
(when number
2616 (if (atom number
) (number-to-string number
)
2617 (mapconcat 'number-to-string number
".")))))
2618 (format "<a href=\"#%s\"%s>%s</a>"
2619 path attributes
(or desc
"No description for this link")))))))
2620 ;; Coderef: replace link with the reference name or the
2621 ;; equivalent line number.
2622 ((string= type
"coderef")
2623 (let ((fragment (concat "coderef-" path
)))
2624 (format "<a href=\"#%s\"%s%s>%s</a>"
2627 (format (concat "class=\"coderef\""
2628 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2629 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2632 (format (org-export-get-coderef-format path desc
)
2633 (org-export-resolve-coderef path info
)))))
2634 ;; Link type is handled by a special function.
2635 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2636 (funcall protocol
(org-link-unescape path
) desc
'html
))
2637 ;; External link with a description part.
2638 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2639 ;; External link without a description part.
2640 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2641 ;; No path, only description. Try to do something useful.
2642 (t (format "<i>%s</i>" desc
)))))
2646 (defun org-html-paragraph (paragraph contents info
)
2647 "Transcode a PARAGRAPH element from Org to HTML.
2648 CONTENTS is the contents of the paragraph, as a string. INFO is
2649 the plist used as a communication channel."
2650 (let* ((parent (org-export-get-parent paragraph
))
2651 (parent-type (org-element-type parent
))
2652 (style '((footnote-definition
2653 " style=\"display:inline;\" class=\"footnote\""
2655 (extra (or (cadr (assoc parent-type style
)) ""))
2656 (after (or (nth 1 (cdr (assoc parent-type style
))) "")))
2658 ((and (eq (org-element-type parent
) 'item
)
2659 (= (org-element-property :begin paragraph
)
2660 (org-element-property :contents-begin parent
)))
2661 ;; leading paragraph in a list item have no tags
2663 ((org-html-standalone-image-p paragraph info
)
2666 (t (format "<p%s>\n%s</p>%s" extra contents after
)))))
2670 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2671 ;; the correct value for the item counter
2672 (defun org-html-begin-plain-list (type &optional arg1
)
2673 "Insert the beginning of the HTML list depending on TYPE.
2674 When ARG1 is a string, use it as the start parameter for ordered
2678 (format "<ol class=\"org-ol\"%s>"
2679 (if arg1
(format " start=\"%d\"" arg1
) "")))
2680 (unordered "<ul class=\"org-ul\">")
2681 (descriptive "<dl class=\"org-dl\">")))
2683 (defun org-html-end-plain-list (type)
2684 "Insert the end of the HTML list depending on TYPE."
2688 (descriptive "</dl>")))
2690 (defun org-html-plain-list (plain-list contents info
)
2691 "Transcode a PLAIN-LIST element from Org to HTML.
2692 CONTENTS is the contents of the list. INFO is a plist holding
2693 contextual information."
2694 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2695 (type (org-element-property :type plain-list
)))
2697 (org-html-begin-plain-list type
)
2698 contents
(org-html-end-plain-list type
))))
2702 (defun org-html-convert-special-strings (string)
2703 "Convert special characters in STRING to HTML."
2704 (let ((all org-html-special-string-regexps
)
2706 (while (setq a
(pop all
))
2707 (setq re
(car a
) rpl
(cdr a
) start
0)
2708 (while (string-match re string start
)
2709 (setq string
(replace-match rpl t nil string
))))
2712 (defun org-html-encode-plain-text (text)
2713 "Convert plain text characters from TEXT to HTML equivalent.
2714 Possible conversions are set in `org-html-protect-char-alist'."
2717 (setq text
(replace-regexp-in-string (car pair
) (cdr pair
) text t t
)))
2718 org-html-protect-char-alist
)
2721 (defun org-html-plain-text (text info
)
2722 "Transcode a TEXT string from Org to HTML.
2723 TEXT is the string to transcode. INFO is a plist holding
2724 contextual information."
2725 (let ((output text
))
2726 ;; Protect following characters: <, >, &.
2727 (setq output
(org-html-encode-plain-text output
))
2728 ;; Handle smart quotes. Be sure to provide original string since
2729 ;; OUTPUT may have been modified.
2730 (when (plist-get info
:with-smart-quotes
)
2731 (setq output
(org-export-activate-smart-quotes output
:html info text
)))
2732 ;; Handle special strings.
2733 (when (plist-get info
:with-special-strings
)
2734 (setq output
(org-html-convert-special-strings output
)))
2735 ;; Handle break preservation if required.
2736 (when (plist-get info
:preserve-breaks
)
2738 (replace-regexp-in-string
2739 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output
)))
2746 (defun org-html-planning (planning contents info
)
2747 "Transcode a PLANNING element from Org to HTML.
2748 CONTENTS is nil. INFO is a plist used as a communication
2750 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2752 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2757 (let ((closed (org-element-property :closed planning
)))
2759 (format span-fmt org-closed-string
2761 (org-element-property :raw-value closed
)))))
2762 (let ((deadline (org-element-property :deadline planning
)))
2764 (format span-fmt org-deadline-string
2766 (org-element-property :raw-value deadline
)))))
2767 (let ((scheduled (org-element-property :scheduled planning
)))
2769 (format span-fmt org-scheduled-string
2771 (org-element-property :raw-value scheduled
)))))))
2774 ;;;; Property Drawer
2776 (defun org-html-property-drawer (property-drawer contents info
)
2777 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2778 CONTENTS is nil. INFO is a plist holding contextual
2780 ;; The property drawer isn't exported but we want separating blank
2781 ;; lines nonetheless.
2786 (defun org-html-quote-block (quote-block contents info
)
2787 "Transcode a QUOTE-BLOCK element from Org to HTML.
2788 CONTENTS holds the contents of the block. INFO is a plist
2789 holding contextual information."
2790 (format "<blockquote>\n%s</blockquote>" contents
))
2794 (defun org-html-quote-section (quote-section contents info
)
2795 "Transcode a QUOTE-SECTION element from Org to HTML.
2796 CONTENTS is nil. INFO is a plist holding contextual information."
2797 (let ((value (org-remove-indentation
2798 (org-element-property :value quote-section
))))
2799 (when value
(format "<pre>\n%s</pre>" value
))))
2803 (defun org-html-section (section contents info
)
2804 "Transcode a SECTION element from Org to HTML.
2805 CONTENTS holds the contents of the section. INFO is a plist
2806 holding contextual information."
2807 (let ((parent (org-export-get-parent-headline section
)))
2808 ;; Before first headline: no container, just return CONTENTS.
2809 (if (not parent
) contents
2810 ;; Get div's class and id references.
2811 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2812 (1- org-html-toplevel-hlevel
)))
2816 (org-export-get-headline-number parent info
) "-")))
2817 ;; Build return value.
2818 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2820 (or (org-element-property :CUSTOM_ID parent
) section-number
)
2825 (defun org-html-radio-target (radio-target text info
)
2826 "Transcode a RADIO-TARGET object from Org to HTML.
2827 TEXT is the text of the target. INFO is a plist holding
2828 contextual information."
2829 (let ((id (org-export-solidify-link-text
2830 (org-element-property :value radio-target
))))
2831 (org-html--anchor id text
)))
2835 (defun org-html-special-block (special-block contents info
)
2836 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2837 CONTENTS holds the contents of the block. INFO is a plist
2838 holding contextual information."
2839 (format "<div class=\"%s\">\n%s\n</div>"
2840 (downcase (org-element-property :type special-block
))
2845 (defun org-html-src-block (src-block contents info
)
2846 "Transcode a SRC-BLOCK element from Org to HTML.
2847 CONTENTS holds the contents of the item. INFO is a plist holding
2848 contextual information."
2849 (if (org-export-read-attribute :attr_html src-block
:textarea
)
2850 (org-html--textarea-block src-block
)
2851 (let ((lang (org-element-property :language src-block
))
2852 (caption (org-export-get-caption src-block
))
2853 (code (org-html-format-code src-block info
))
2854 (label (let ((lbl (org-element-property :name src-block
)))
2856 (format " id=\"%s\""
2857 (org-export-solidify-link-text lbl
))))))
2858 (if (not lang
) (format "<pre class=\"example\"%s>\n%s</pre>" label code
)
2860 "<div class=\"org-src-container\">\n%s%s\n</div>"
2861 (if (not caption
) ""
2862 (format "<label class=\"org-src-name\">%s</label>"
2863 (org-export-data caption info
)))
2864 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code
))))))
2866 ;;;; Statistics Cookie
2868 (defun org-html-statistics-cookie (statistics-cookie contents info
)
2869 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2870 CONTENTS is nil. INFO is a plist holding contextual information."
2871 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2872 (format "<code>%s</code>" cookie-value
)))
2876 (defun org-html-strike-through (strike-through contents info
)
2877 "Transcode STRIKE-THROUGH from Org to HTML.
2878 CONTENTS is the text with strike-through markup. INFO is a plist
2879 holding contextual information."
2880 (format (or (cdr (assq 'strike-through org-html-text-markup-alist
)) "%s")
2885 (defun org-html-subscript (subscript contents info
)
2886 "Transcode a SUBSCRIPT object from Org to HTML.
2887 CONTENTS is the contents of the object. INFO is a plist holding
2888 contextual information."
2889 (format "<sub>%s</sub>" contents
))
2893 (defun org-html-superscript (superscript contents info
)
2894 "Transcode a SUPERSCRIPT object from Org to HTML.
2895 CONTENTS is the contents of the object. INFO is a plist holding
2896 contextual information."
2897 (format "<sup>%s</sup>" contents
))
2901 (defun org-html-table-cell (table-cell contents info
)
2902 "Transcode a TABLE-CELL element from Org to HTML.
2903 CONTENTS is nil. INFO is a plist used as a communication
2905 (let* ((table-row (org-export-get-parent table-cell
))
2906 (table (org-export-get-parent-table table-cell
))
2908 (if (not org-html-table-align-individual-fields
) ""
2909 (format (if (and (boundp 'org-html-format-table-no-css
)
2910 org-html-format-table-no-css
)
2911 " align=\"%s\"" " class=\"%s\"")
2912 (org-export-table-cell-alignment table-cell info
)))))
2913 (when (or (not contents
) (string= "" (org-trim contents
)))
2914 (setq contents
" "))
2916 ((and (org-export-table-has-header-p table info
)
2917 (= 1 (org-export-table-row-group table-row info
)))
2918 (concat "\n" (format (car org-html-table-header-tags
) "col" cell-attrs
)
2919 contents
(cdr org-html-table-header-tags
)))
2920 ((and org-html-table-use-header-tags-for-first-column
2921 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2922 (concat "\n" (format (car org-html-table-header-tags
) "row" cell-attrs
)
2923 contents
(cdr org-html-table-header-tags
)))
2924 (t (concat "\n" (format (car org-html-table-data-tags
) cell-attrs
)
2925 contents
(cdr org-html-table-data-tags
))))))
2929 (defun org-html-table-row (table-row contents info
)
2930 "Transcode a TABLE-ROW element from Org to HTML.
2931 CONTENTS is the contents of the row. INFO is a plist used as a
2932 communication channel."
2933 ;; Rules are ignored since table separators are deduced from
2934 ;; borders of the current row.
2935 (when (eq (org-element-property :type table-row
) 'standard
)
2936 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2939 ;; Case 1: Row belongs to second or subsequent rowgroups.
2940 ((not (= 1 (org-export-table-row-group table-row info
)))
2941 '("<tbody>" .
"\n</tbody>"))
2942 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2943 ((org-export-table-has-header-p
2944 (org-export-get-parent-table table-row
) info
)
2945 '("<thead>" .
"\n</thead>"))
2946 ;; Case 2: Row is from first and only row group.
2947 (t '("<tbody>" .
"\n</tbody>")))))
2949 ;; Begin a rowgroup?
2950 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2951 (car rowgroup-tags
))
2953 (concat "\n" (eval (car org-html-table-row-tags
))
2956 (eval (cdr org-html-table-row-tags
)))
2958 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2959 (cdr rowgroup-tags
))))))
2963 (defun org-html-table-first-row-data-cells (table info
)
2964 "Transcode the first row of TABLE.
2965 INFO is a plist used as a communication channel."
2967 (org-element-map table
'table-row
2969 (unless (eq (org-element-property :type row
) 'rule
) row
))
2971 (special-column-p (org-export-table-has-special-column-p table
)))
2972 (if (not special-column-p
) (org-element-contents table-row
)
2973 (cdr (org-element-contents table-row
)))))
2975 (defun org-html-table--table.el-table
(table info
)
2976 "Format table.el tables into HTML.
2977 INFO is a plist used as a communication channel."
2978 (when (eq (org-element-property :type table
) 'table.el
)
2980 (let ((outbuf (with-current-buffer
2981 (get-buffer-create "*org-export-table*")
2982 (erase-buffer) (current-buffer))))
2984 (insert (org-element-property :value table
))
2986 (re-search-forward "^[ \t]*|[^|]" nil t
)
2987 (table-generate-source 'html outbuf
))
2988 (with-current-buffer outbuf
2989 (prog1 (org-trim (buffer-string))
2992 (defun org-html-table (table contents info
)
2993 "Transcode a TABLE element from Org to HTML.
2994 CONTENTS is the contents of the table. INFO is a plist holding
2995 contextual information."
2996 (case (org-element-property :type table
)
2997 ;; Case 1: table.el table. Convert it using appropriate tools.
2998 (table.el
(org-html-table--table.el-table table info
))
2999 ;; Case 2: Standard table.
3001 (let* ((label (org-element-property :name table
))
3002 (caption (org-export-get-caption table
))
3003 (attributes (mapconcat #'identity
3004 (org-element-property :attr_html table
)
3007 (if (and (boundp 'org-html-format-table-no-css
)
3008 org-html-format-table-no-css
)
3009 "align=\"%s\"" "class=\"%s\""))
3012 (lambda (table info
)
3014 (lambda (table-cell)
3015 (let ((alignment (org-export-table-cell-alignment
3018 ;; Begin a colgroup?
3019 (when (org-export-table-cell-starts-colgroup-p
3022 ;; Add a column. Also specify it's alignment.
3023 (format "\n<col %s/>" (format alignspec alignment
))
3025 (when (org-export-table-cell-ends-colgroup-p
3028 (org-html-table-first-row-data-cells table info
) "\n"))))
3030 (let ((table-tag (plist-get info
:html-table-tag
)))
3032 (and (string-match "<table\\(.*\\)>" table-tag
)
3033 (match-string 1 table-tag
))
3034 (and label
(format " id=\"%s\""
3035 (org-export-solidify-link-text label
)))
3036 (unless (string= attributes
"")
3037 (concat " " attributes
))))))
3038 ;; Remove last blank line.
3039 (setq contents
(substring contents
0 -
1))
3040 (format "<table%s>\n%s\n%s\n%s\n</table>"
3042 (if (not caption
) ""
3043 (format "<caption>%s</caption>"
3044 (org-export-data caption info
)))
3045 (funcall table-column-specs table info
)
3050 (defun org-html-target (target contents info
)
3051 "Transcode a TARGET object from Org to HTML.
3052 CONTENTS is nil. INFO is a plist holding contextual
3054 (let ((id (org-export-solidify-link-text
3055 (org-element-property :value target
))))
3056 (org-html--anchor id
)))
3060 (defun org-html-timestamp (timestamp contents info
)
3061 "Transcode a TIMESTAMP object from Org to HTML.
3062 CONTENTS is nil. INFO is a plist holding contextual
3064 (let ((value (org-html-plain-text
3065 (org-timestamp-translate timestamp
) info
)))
3066 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3067 (replace-regexp-in-string "--" "–" value
))))
3071 (defun org-html-underline (underline contents info
)
3072 "Transcode UNDERLINE from Org to HTML.
3073 CONTENTS is the text with underline markup. INFO is a plist
3074 holding contextual information."
3075 (format (or (cdr (assq 'underline org-html-text-markup-alist
)) "%s")
3080 (defun org-html-verbatim (verbatim contents info
)
3081 "Transcode VERBATIM from Org to HTML.
3082 CONTENTS is nil. INFO is a plist holding contextual
3084 (format (or (cdr (assq 'verbatim org-html-text-markup-alist
)) "%s")
3085 (org-html-plain-text (org-element-property :value verbatim
) info
)))
3089 (defun org-html-verse-block (verse-block contents info
)
3090 "Transcode a VERSE-BLOCK element from Org to HTML.
3091 CONTENTS is verse block contents. INFO is a plist holding
3092 contextual information."
3093 ;; Replace each newline character with line break. Also replace
3094 ;; each blank line with a line break.
3095 (setq contents
(replace-regexp-in-string
3096 "^ *\\\\\\\\$" "<br/>\n"
3097 (replace-regexp-in-string
3098 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3099 ;; Replace each white space at beginning of a line with a
3100 ;; non-breaking space.
3101 (while (string-match "^[ \t]+" contents
)
3102 (let* ((num-ws (length (match-string 0 contents
)))
3103 (ws (let (out) (dotimes (i num-ws out
)
3104 (setq out
(concat out
" "))))))
3105 (setq contents
(replace-match ws nil t contents
))))
3106 (format "<p class=\"verse\">\n%s</p>" contents
))
3109 ;;; Filter Functions
3111 (defun org-html-final-function (contents backend info
)
3112 "Filter to prettify the HTML output.
3113 Prettifying happens if `org-html-pretty-output' is t."
3114 (if (not org-html-pretty-output
) contents
3118 (indent-region (point-min) (point-max))
3119 (buffer-substring-no-properties (point-min) (point-max)))))
3122 ;;; End-user functions
3125 (defun org-html-export-as-html
3126 (&optional async subtreep visible-only body-only ext-plist
)
3127 "Export current buffer to an HTML buffer.
3129 If narrowing is active in the current buffer, only export its
3132 If a region is active, export that region.
3134 A non-nil optional argument ASYNC means the process should happen
3135 asynchronously. The resulting buffer should be accessible
3136 through the `org-export-stack' interface.
3138 When optional argument SUBTREEP is non-nil, export the sub-tree
3139 at point, extracting information from the headline properties
3142 When optional argument VISIBLE-ONLY is non-nil, don't export
3143 contents of hidden elements.
3145 When optional argument BODY-ONLY is non-nil, only write code
3146 between \"<body>\" and \"</body>\" tags.
3148 EXT-PLIST, when provided, is a property list with external
3149 parameters overriding Org default settings, but still inferior to
3150 file-local settings.
3152 Export is done in a buffer named \"*Org HTML Export*\", which
3153 will be displayed when `org-export-show-temporary-export-buffer'
3157 (org-export-async-start
3159 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3162 (goto-char (point-min))
3164 (org-export-add-to-stack (current-buffer) 'html
)))
3165 `(org-export-as 'html
,subtreep
,visible-only
,body-only
',ext-plist
))
3166 (let ((outbuf (org-export-to-buffer
3167 'html
"*Org HTML Export*"
3168 subtreep visible-only body-only ext-plist
)))
3170 (with-current-buffer outbuf
(set-auto-mode t
))
3171 (when org-export-show-temporary-export-buffer
3172 (switch-to-buffer-other-window outbuf
)))))
3175 (defun org-html-export-to-html
3176 (&optional async subtreep visible-only body-only ext-plist
)
3177 "Export current buffer to a HTML file.
3179 If narrowing is active in the current buffer, only export its
3182 If a region is active, export that region.
3184 A non-nil optional argument ASYNC means the process should happen
3185 asynchronously. The resulting file should be accessible through
3186 the `org-export-stack' interface.
3188 When optional argument SUBTREEP is non-nil, export the sub-tree
3189 at point, extracting information from the headline properties
3192 When optional argument VISIBLE-ONLY is non-nil, don't export
3193 contents of hidden elements.
3195 When optional argument BODY-ONLY is non-nil, only write code
3196 between \"<body>\" and \"</body>\" tags.
3198 EXT-PLIST, when provided, is a property list with external
3199 parameters overriding Org default settings, but still inferior to
3200 file-local settings.
3202 Return output file's name."
3204 (let* ((extension (concat "." org-html-extension
))
3205 (file (org-export-output-file-name extension subtreep
))
3206 (org-export-coding-system org-html-coding-system
))
3208 (org-export-async-start
3209 (lambda (f) (org-export-add-to-stack f
'html
))
3210 (let ((org-export-coding-system org-html-coding-system
))
3213 'html
,file
,subtreep
,visible-only
,body-only
',ext-plist
))))
3214 (let ((org-export-coding-system org-html-coding-system
))
3216 'html file subtreep visible-only body-only ext-plist
)))))
3219 (defun org-html-publish-to-html (plist filename pub-dir
)
3220 "Publish an org file to HTML.
3222 FILENAME is the filename of the Org file to be published. PLIST
3223 is the property list for the given project. PUB-DIR is the
3224 publishing directory.
3226 Return output file name."
3227 (org-publish-org-to 'html filename
".html" plist pub-dir
))
3232 ;;;; org-format-table-html
3233 ;;;; org-format-org-table-html
3234 ;;;; org-format-table-table-html
3235 ;;;; org-table-number-fraction
3236 ;;;; org-table-number-regexp
3237 ;;;; org-html-table-caption-above
3238 ;;;; org-html-inline-image-extensions
3239 ;;;; org-export-preferred-target-alist
3240 ;;;; class for anchors
3241 ;;;; org-export-with-section-numbers, body-only
3242 ;;;; org-export-mark-todo-in-toc
3243 ;;;; org-html-format-org-link
3244 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3245 ;;;; alt = (file-name-nondirectory path)
3250 ;; generated-autoload-file: "org-loaddefs.el"
3253 ;;; ox-html.el ends here