Merge branch 'maint'
[org-mode.git] / lisp / ox-html.el
blobb425e55d87de584fcd759d478f8e46b98eb9c779
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; This library implements a HTML back-end for Org generic exporter.
25 ;; See Org manual for more information.
27 ;;; Code:
29 ;;; Dependencies
31 (require 'ox)
32 (require 'ox-publish)
33 (require 'format-spec)
34 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
37 ;;; Function Declarations
39 (declare-function org-id-find-id-file "org-id" (id))
40 (declare-function htmlize-region "ext:htmlize" (beg end))
41 (declare-function org-pop-to-buffer-same-window
42 "org-compat" (&optional buffer-or-name norecord label))
43 (declare-function mm-url-decode-entities "mm-url" ())
45 ;;; Define Back-End
47 (org-export-define-backend 'html
48 '((bold . org-html-bold)
49 (center-block . org-html-center-block)
50 (clock . org-html-clock)
51 (code . org-html-code)
52 (drawer . org-html-drawer)
53 (dynamic-block . org-html-dynamic-block)
54 (entity . org-html-entity)
55 (example-block . org-html-example-block)
56 (export-block . org-html-export-block)
57 (export-snippet . org-html-export-snippet)
58 (fixed-width . org-html-fixed-width)
59 (footnote-definition . org-html-footnote-definition)
60 (footnote-reference . org-html-footnote-reference)
61 (headline . org-html-headline)
62 (horizontal-rule . org-html-horizontal-rule)
63 (inline-src-block . org-html-inline-src-block)
64 (inlinetask . org-html-inlinetask)
65 (inner-template . org-html-inner-template)
66 (italic . org-html-italic)
67 (item . org-html-item)
68 (keyword . org-html-keyword)
69 (latex-environment . org-html-latex-environment)
70 (latex-fragment . org-html-latex-fragment)
71 (line-break . org-html-line-break)
72 (link . org-html-link)
73 (node-property . org-html-node-property)
74 (paragraph . org-html-paragraph)
75 (plain-list . org-html-plain-list)
76 (plain-text . org-html-plain-text)
77 (planning . org-html-planning)
78 (property-drawer . org-html-property-drawer)
79 (quote-block . org-html-quote-block)
80 (quote-section . org-html-quote-section)
81 (radio-target . org-html-radio-target)
82 (section . org-html-section)
83 (special-block . org-html-special-block)
84 (src-block . org-html-src-block)
85 (statistics-cookie . org-html-statistics-cookie)
86 (strike-through . org-html-strike-through)
87 (subscript . org-html-subscript)
88 (superscript . org-html-superscript)
89 (table . org-html-table)
90 (table-cell . org-html-table-cell)
91 (table-row . org-html-table-row)
92 (target . org-html-target)
93 (template . org-html-template)
94 (timestamp . org-html-timestamp)
95 (underline . org-html-underline)
96 (verbatim . org-html-verbatim)
97 (verse-block . org-html-verse-block))
98 :export-block "HTML"
99 :filters-alist '((:filter-options . org-html-infojs-install-script)
100 (:filter-final-output . org-html-final-function))
101 :menu-entry
102 '(?h "Export to HTML"
103 ((?H "As HTML buffer" org-html-export-as-html)
104 (?h "As HTML file" org-html-export-to-html)
105 (?o "As HTML file and open"
106 (lambda (a s v b)
107 (if a (org-html-export-to-html t s v b)
108 (org-open-file (org-html-export-to-html nil s v b)))))))
109 :options-alist
110 '((:html-extension nil nil org-html-extension)
111 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
112 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
113 (:html-container "HTML_CONTAINER" nil org-html-container-element)
114 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
115 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
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 nil "html-style" org-html-head-include-default-style)
124 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
125 (:html-table-attributes nil nil org-html-table-default-attributes)
126 (:html-table-row-tags nil nil org-html-table-row-tags)
127 (:html-xml-declaration nil nil org-html-xml-declaration)
128 (:html-inline-images nil nil org-html-inline-images)
129 (:infojs-opt "INFOJS_OPT" nil nil)
130 ;; Redefine regular options.
131 (:creator "CREATOR" nil org-html-creator-string)
132 (:with-latex nil "tex" org-html-with-latex)))
135 ;;; Internal Variables
137 (defvar org-html-format-table-no-css)
138 (defvar htmlize-buffer-places) ; from htmlize.el
140 (defvar org-html--pre/postamble-class "status"
141 "CSS class used for pre/postamble")
143 (defconst org-html-doctype-alist
144 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
145 \"http://www.w3.org/TR/html4/strict.dtd\">")
146 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
147 \"http://www.w3.org/TR/html4/loose.dtd\">")
148 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
149 \"http://www.w3.org/TR/html4/frameset.dtd\">")
151 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
152 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
153 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
154 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
155 ("xhtml-framset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
156 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
157 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
158 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
160 ("html5" . "<!DOCTYPE html>")
161 ("xhtml5" . "<!DOCTYPE html>"))
162 "An alist mapping (x)html flavors to specific doctypes.")
164 (defconst org-html-html5-elements
165 '("article" "aside" "audio" "canvas" "details" "figcaption"
166 "figure" "footer" "header" "menu" "meter" "nav" "output"
167 "progress" "section" "video")
168 "New elements in html5.
170 <hgroup> is not included because it's currently impossible to
171 wrap special blocks around multiple headlines. For other blocks
172 that should contain headlines, use the HTML_CONTAINER property on
173 the headline itself.")
175 (defconst org-html-special-string-regexps
176 '(("\\\\-" . "&#x00ad;") ; shy
177 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
178 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
179 ("\\.\\.\\." . "&#x2026;")) ; hellip
180 "Regular expressions for special string conversion.")
182 (defconst org-html-scripts
183 "<script type=\"text/javascript\">
185 @licstart The following is the entire license notice for the
186 JavaScript code in this tag.
188 Copyright (C) 2012 Free Software Foundation, Inc.
190 The JavaScript code in this tag is free software: you can
191 redistribute it and/or modify it under the terms of the GNU
192 General Public License (GNU GPL) as published by the Free Software
193 Foundation, either version 3 of the License, or (at your option)
194 any later version. The code is distributed WITHOUT ANY WARRANTY;
195 without even the implied warranty of MERCHANTABILITY or FITNESS
196 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
198 As additional permission under GNU GPL version 3 section 7, you
199 may distribute non-source (e.g., minimized or compacted) forms of
200 that code without the copy of the GNU GPL normally required by
201 section 4, provided you include this license notice and a URL
202 through which recipients can access the Corresponding Source.
205 @licend The above is the entire license notice
206 for the JavaScript code in this tag.
208 <!--/*--><![CDATA[/*><!--*/
209 function CodeHighlightOn(elem, id)
211 var target = document.getElementById(id);
212 if(null != target) {
213 elem.cacheClassElem = elem.className;
214 elem.cacheClassTarget = target.className;
215 target.className = \"code-highlighted\";
216 elem.className = \"code-highlighted\";
219 function CodeHighlightOff(elem, id)
221 var target = document.getElementById(id);
222 if(elem.cacheClassElem)
223 elem.className = elem.cacheClassElem;
224 if(elem.cacheClassTarget)
225 target.className = elem.cacheClassTarget;
227 /*]]>*///-->
228 </script>"
229 "Basic JavaScript that is needed by HTML files produced by Org mode.")
231 (defconst org-html-style-default
232 "<style type=\"text/css\">
233 <!--/*--><![CDATA[/*><!--*/
234 .title { text-align: center; }
235 .todo { font-family: monospace; color: red; }
236 .done { color: green; }
237 .tag { background-color: #eee; font-family: monospace;
238 padding: 2px; font-size: 80%; font-weight: normal; }
239 .timestamp { color: #bebebe; }
240 .timestamp-kwd { color: #5f9ea0; }
241 .right { margin-left: auto; margin-right: 0px; text-align: right; }
242 .left { margin-left: 0px; margin-right: auto; text-align: left; }
243 .center { margin-left: auto; margin-right: auto; text-align: center; }
244 .underline { text-decoration: underline; }
245 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
246 p.verse { margin-left: 3%; }
247 pre {
248 border: 1px solid #ccc;
249 box-shadow: 3px 3px 3px #eee;
250 padding: 8pt;
251 font-family: monospace;
252 overflow: auto;
253 margin: 1.2em;
255 pre.src {
256 position: relative;
257 overflow: visible;
258 padding-top: 1.2em;
260 pre.src:before {
261 display: none;
262 position: absolute;
263 background-color: white;
264 top: -10px;
265 right: 10px;
266 padding: 3px;
267 border: 1px solid black;
269 pre.src:hover:before { display: inline;}
270 pre.src-sh:before { content: 'sh'; }
271 pre.src-bash:before { content: 'sh'; }
272 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
273 pre.src-R:before { content: 'R'; }
274 pre.src-perl:before { content: 'Perl'; }
275 pre.src-java:before { content: 'Java'; }
276 pre.src-sql:before { content: 'SQL'; }
278 table { border-collapse:collapse; }
279 td, th { vertical-align:top; }
280 th.right { text-align: center; }
281 th.left { text-align: center; }
282 th.center { text-align: center; }
283 td.right { text-align: right; }
284 td.left { text-align: left; }
285 td.center { text-align: center; }
286 dt { font-weight: bold; }
287 .footpara:nth-child(2) { display: inline; }
288 .footpara { display: block; }
289 .footdef { margin-bottom: 1em; }
290 .figure { padding: 1em; }
291 .figure p { text-align: center; }
292 .inlinetask {
293 padding: 10px;
294 border: 2px solid gray;
295 margin: 10px;
296 background: #ffffcc;
298 #org-div-home-and-up
299 { text-align: right; font-size: 70%; white-space: nowrap; }
300 textarea { overflow-x: auto; }
301 .linenr { font-size: smaller }
302 .code-highlighted { background-color: #ffff00; }
303 .org-info-js_info-navigation { border-style: none; }
304 #org-info-js_console-label
305 { font-size: 10px; font-weight: bold; white-space: nowrap; }
306 .org-info-js_search-highlight
307 { background-color: #ffff00; color: #000000; font-weight: bold; }
308 /*]]>*/-->
309 </style>"
310 "The default style specification for exported HTML files.
311 You can use `org-html-head' and `org-html-head-extra' to add to
312 this style. If you don't want to include this default style,
313 customize `org-html-head-include-default-style'.")
316 ;;; User Configuration Variables
318 (defgroup org-export-html nil
319 "Options for exporting Org mode files to HTML."
320 :tag "Org Export HTML"
321 :group 'org-export)
323 ;;;; Handle infojs
325 (defvar org-html-infojs-opts-table
326 '((path PATH "http://orgmode.org/org-info.js")
327 (view VIEW "info")
328 (toc TOC :with-toc)
329 (ftoc FIXED_TOC "0")
330 (tdepth TOC_DEPTH "max")
331 (sdepth SECTION_DEPTH "max")
332 (mouse MOUSE_HINT "underline")
333 (buttons VIEW_BUTTONS "0")
334 (ltoc LOCAL_TOC "1")
335 (up LINK_UP :html-link-up)
336 (home LINK_HOME :html-link-home))
337 "JavaScript options, long form for script, default values.")
339 (defcustom org-html-use-infojs 'when-configured
340 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
341 This option can be nil or t to never or always use the script.
342 It can also be the symbol `when-configured', meaning that the
343 script will be linked into the export file if and only if there
344 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
345 `org-html-infojs-options'."
346 :group 'org-export-html
347 :version "24.4"
348 :package-version '(Org . "8.0")
349 :type '(choice
350 (const :tag "Never" nil)
351 (const :tag "When configured in buffer" when-configured)
352 (const :tag "Always" t)))
354 (defcustom org-html-infojs-options
355 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
356 "Options settings for the INFOJS JavaScript.
357 Each of the options must have an entry in `org-html-infojs-opts-table'.
358 The value can either be a string that will be passed to the script, or
359 a property. This property is then assumed to be a property that is defined
360 by the Export/Publishing setup of Org.
361 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
362 means to use the maximum value consistent with other options."
363 :group 'org-export-html
364 :version "24.4"
365 :package-version '(Org . "8.0")
366 :type
367 `(set :greedy t :inline t
368 ,@(mapcar
369 (lambda (x)
370 (list 'cons (list 'const (car x))
371 '(choice
372 (symbol :tag "Publishing/Export property")
373 (string :tag "Value"))))
374 org-html-infojs-opts-table)))
376 (defcustom org-html-infojs-template
377 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
380 * @source: %SCRIPT_PATH
382 * @licstart The following is the entire license notice for the
383 * JavaScript code in %SCRIPT_PATH.
385 * Copyright (C) 2012-2013 Sebastian Rose
388 * The JavaScript code in this tag is free software: you can
389 * redistribute it and/or modify it under the terms of the GNU
390 * General Public License (GNU GPL) as published by the Free Software
391 * Foundation, either version 3 of the License, or (at your option)
392 * any later version. The code is distributed WITHOUT ANY WARRANTY;
393 * without even the implied warranty of MERCHANTABILITY or FITNESS
394 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
396 * As additional permission under GNU GPL version 3 section 7, you
397 * may distribute non-source (e.g., minimized or compacted) forms of
398 * that code without the copy of the GNU GPL normally required by
399 * section 4, provided you include this license notice and a URL
400 * through which recipients can access the Corresponding Source.
402 * @licend The above is the entire license notice
403 * for the JavaScript code in %SCRIPT_PATH.
406 </script>
408 <script type=\"text/javascript\">
411 @licstart The following is the entire license notice for the
412 JavaScript code in this tag.
414 Copyright (C) 2012-2013 Free Software Foundation, Inc.
416 The JavaScript code in this tag is free software: you can
417 redistribute it and/or modify it under the terms of the GNU
418 General Public License (GNU GPL) as published by the Free Software
419 Foundation, either version 3 of the License, or (at your option)
420 any later version. The code is distributed WITHOUT ANY WARRANTY;
421 without even the implied warranty of MERCHANTABILITY or FITNESS
422 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
424 As additional permission under GNU GPL version 3 section 7, you
425 may distribute non-source (e.g., minimized or compacted) forms of
426 that code without the copy of the GNU GPL normally required by
427 section 4, provided you include this license notice and a URL
428 through which recipients can access the Corresponding Source.
431 @licend The above is the entire license notice
432 for the JavaScript code in this tag.
435 <!--/*--><![CDATA[/*><!--*/
436 %MANAGER_OPTIONS
437 org_html_manager.setup(); // activate after the parameters are set
438 /*]]>*///-->
439 </script>"
440 "The template for the export style additions when org-info.js is used.
441 Option settings will replace the %MANAGER-OPTIONS cookie."
442 :group 'org-export-html
443 :version "24.4"
444 :package-version '(Org . "8.0")
445 :type 'string)
447 (defun org-html-infojs-install-script (exp-plist backend)
448 "Install script in export options when appropriate.
449 EXP-PLIST is a plist containing export options. BACKEND is the
450 export back-end currently used."
451 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
452 (not org-html-use-infojs)
453 (and (eq org-html-use-infojs 'when-configured)
454 (or (not (plist-get exp-plist :infojs-opt))
455 (string-match "\\<view:nil\\>"
456 (plist-get exp-plist :infojs-opt)))))
457 (let* ((template org-html-infojs-template)
458 (ptoc (plist-get exp-plist :with-toc))
459 (hlevels (plist-get exp-plist :headline-levels))
460 (sdepth hlevels)
461 (tdepth (if (integerp ptoc) (min ptoc hlevels) hlevels))
462 (options (plist-get exp-plist :infojs-opt))
463 (table org-html-infojs-opts-table)
464 style)
465 (dolist (entry table)
466 (let* ((opt (car entry))
467 (var (nth 1 entry))
468 ;; Compute default values for script option OPT from
469 ;; `org-html-infojs-options' variable.
470 (default
471 (let ((default (cdr (assq opt org-html-infojs-options))))
472 (if (and (symbolp default) (not (memq default '(t nil))))
473 (plist-get exp-plist default)
474 default)))
475 ;; Value set through INFOJS_OPT keyword has precedence
476 ;; over the default one.
477 (val (if (and options
478 (string-match (format "\\<%s:\\(\\S-+\\)" opt)
479 options))
480 (match-string 1 options)
481 default)))
482 (case opt
483 (path (setq template
484 (replace-regexp-in-string
485 "%SCRIPT_PATH" val template t t)))
486 (sdepth (when (integerp (read val))
487 (setq sdepth (min (read val) sdepth))))
488 (tdepth (when (integerp (read val))
489 (setq tdepth (min (read val) tdepth))))
490 (otherwise (setq val
491 (cond
492 ((or (eq val t) (equal val "t")) "1")
493 ((or (eq val nil) (equal val "nil")) "0")
494 ((stringp val) val)
495 (t (format "%s" val))))
496 (push (cons var val) style)))))
497 ;; Now we set the depth of the *generated* TOC to SDEPTH,
498 ;; because the toc will actually determine the splitting. How
499 ;; much of the toc will actually be displayed is governed by the
500 ;; TDEPTH option.
501 (setq exp-plist (plist-put exp-plist :with-toc sdepth))
502 ;; The table of contents should not show more sections than we
503 ;; generate.
504 (setq tdepth (min tdepth sdepth))
505 (push (cons "TOC_DEPTH" tdepth) style)
506 ;; Build style string.
507 (setq style (mapconcat
508 (lambda (x) (format "org_html_manager.set(\"%s\", \"%s\");"
509 (car x)
510 (cdr x)))
511 style "\n"))
512 (when (and style (> (length style) 0))
513 (and (string-match "%MANAGER_OPTIONS" template)
514 (setq style (replace-match style t t template))
515 (setq exp-plist
516 (plist-put
517 exp-plist :html-head-extra
518 (concat (or (plist-get exp-plist :html-head-extra) "")
519 "\n"
520 style)))))
521 ;; This script absolutely needs the table of contents, so we
522 ;; change that setting.
523 (unless (plist-get exp-plist :with-toc)
524 (setq exp-plist (plist-put exp-plist :with-toc t)))
525 ;; Return the modified property list.
526 exp-plist)))
528 ;;;; Bold, etc.
530 (defcustom org-html-text-markup-alist
531 '((bold . "<b>%s</b>")
532 (code . "<code>%s</code>")
533 (italic . "<i>%s</i>")
534 (strike-through . "<del>%s</del>")
535 (underline . "<span class=\"underline\">%s</span>")
536 (verbatim . "<code>%s</code>"))
537 "Alist of HTML expressions to convert text markup.
539 The key must be a symbol among `bold', `code', `italic',
540 `strike-through', `underline' and `verbatim'. The value is
541 a formatting string to wrap fontified text with.
543 If no association can be found for a given markup, text will be
544 returned as-is."
545 :group 'org-export-html
546 :type '(alist :key-type (symbol :tag "Markup type")
547 :value-type (string :tag "Format string"))
548 :options '(bold code italic strike-through underline verbatim))
550 (defcustom org-html-indent nil
551 "Non-nil means to indent the generated HTML.
552 Warning: non-nil may break indentation of source code blocks."
553 :group 'org-export-html
554 :version "24.4"
555 :package-version '(Org . "8.0")
556 :type 'boolean)
558 (defcustom org-html-use-unicode-chars nil
559 "Non-nil means to use unicode characters instead of HTML entities."
560 :group 'org-export-html
561 :version "24.4"
562 :package-version '(Org . "8.0")
563 :type 'boolean)
565 ;;;; Drawers
567 (defcustom org-html-format-drawer-function nil
568 "Function called to format a drawer in HTML code.
570 The function must accept two parameters:
571 NAME the drawer name, like \"LOGBOOK\"
572 CONTENTS the contents of the drawer.
574 The function should return the string to be exported.
576 For example, the variable could be set to the following function
577 in order to mimic default behaviour:
579 \(defun org-html-format-drawer-default \(name contents\)
580 \"Format a drawer element for HTML export.\"
581 contents\)"
582 :group 'org-export-html
583 :type 'function)
585 ;;;; Footnotes
587 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
588 <h2 class=\"footnotes\">%s: </h2>
589 <div id=\"text-footnotes\">
591 </div>
592 </div>"
593 "Format for the footnotes section.
594 Should contain a two instances of %s. The first will be replaced with the
595 language-specific word for \"Footnotes\", the second one will be replaced
596 by the footnotes themselves."
597 :group 'org-export-html
598 :type 'string)
600 (defcustom org-html-footnote-format "<sup>%s</sup>"
601 "The format for the footnote reference.
602 %s will be replaced by the footnote reference itself."
603 :group 'org-export-html
604 :type 'string)
606 (defcustom org-html-footnote-separator "<sup>, </sup>"
607 "Text used to separate footnotes."
608 :group 'org-export-html
609 :type 'string)
611 ;;;; Headline
613 (defcustom org-html-toplevel-hlevel 2
614 "The <H> level for level 1 headings in HTML export.
615 This is also important for the classes that will be wrapped around headlines
616 and outline structure. If this variable is 1, the top-level headlines will
617 be <h1>, and the corresponding classes will be outline-1, section-number-1,
618 and outline-text-1. If this is 2, all of these will get a 2 instead.
619 The default for this variable is 2, because we use <h1> for formatting the
620 document title."
621 :group 'org-export-html
622 :type 'integer)
624 (defcustom org-html-format-headline-function nil
625 "Function to format headline text.
627 This function will be called with 5 arguments:
628 TODO the todo keyword (string or nil).
629 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
630 PRIORITY the priority of the headline (integer or nil)
631 TEXT the main headline text (string).
632 TAGS the tags (string or nil).
634 The function result will be used in the section format string."
635 :group 'org-export-html
636 :type 'function)
638 ;;;; HTML-specific
640 (defcustom org-html-allow-name-attribute-in-anchors t
641 "When nil, do not set \"name\" attribute in anchors.
642 By default, anchors are formatted with both \"id\" and \"name\"
643 attributes, when appropriate."
644 :group 'org-export-html
645 :version "24.4"
646 :package-version '(Org . "8.0")
647 :type 'boolean)
649 ;;;; Inlinetasks
651 (defcustom org-html-format-inlinetask-function nil
652 "Function called to format an inlinetask in HTML code.
654 The function must accept six parameters:
655 TODO the todo keyword, as a string
656 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
657 PRIORITY the inlinetask priority, as a string
658 NAME the inlinetask name, as a string.
659 TAGS the inlinetask tags, as a list of strings.
660 CONTENTS the contents of the inlinetask, as a string.
662 The function should return the string to be exported."
663 :group 'org-export-html
664 :type 'function)
666 ;;;; LaTeX
668 (defcustom org-html-with-latex org-export-with-latex
669 "Non-nil means process LaTeX math snippets.
671 When set, the exporter will process LaTeX environments and
672 fragments.
674 This option can also be set with the +OPTIONS line,
675 e.g. \"tex:mathjax\". Allowed values are:
677 nil Ignore math snippets.
678 `verbatim' Keep everything in verbatim
679 `dvipng' Process the LaTeX fragments to images. This will also
680 include processing of non-math environments.
681 `imagemagick' Convert the LaTeX fragments to pdf files and use
682 imagemagick to convert pdf files to png files.
683 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
684 be loaded.
685 t Synonym for `mathjax'."
686 :group 'org-export-html
687 :version "24.4"
688 :package-version '(Org . "8.0")
689 :type '(choice
690 (const :tag "Do not process math in any way" nil)
691 (const :tag "Use dvipng to make images" dvipng)
692 (const :tag "Use imagemagick to make images" imagemagick)
693 (const :tag "Use MathJax to display math" mathjax)
694 (const :tag "Leave math verbatim" verbatim)))
696 ;;;; Links :: Generic
698 (defcustom org-html-link-org-files-as-html t
699 "Non-nil means make file links to `file.org' point to `file.html'.
700 When `org-mode' is exporting an `org-mode' file to HTML, links to
701 non-html files are directly put into a href tag in HTML.
702 However, links to other Org-mode files (recognized by the
703 extension `.org.) should become links to the corresponding html
704 file, assuming that the linked `org-mode' file will also be
705 converted to HTML.
706 When nil, the links still point to the plain `.org' file."
707 :group 'org-export-html
708 :type 'boolean)
710 ;;;; Links :: Inline images
712 (defcustom org-html-inline-images t
713 "Non-nil means inline images into exported HTML pages.
714 This is done using an <img> tag. When nil, an anchor with href is used to
715 link to the image."
716 :group 'org-export-html
717 :version "24.4"
718 :package-version '(Org . "8.1")
719 :type 'boolean)
721 (defcustom org-html-inline-image-rules
722 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
723 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
724 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
725 "Rules characterizing image files that can be inlined into HTML.
726 A rule consists in an association whose key is the type of link
727 to consider, and value is a regexp that will be matched against
728 link's path."
729 :group 'org-export-html
730 :version "24.4"
731 :package-version '(Org . "8.0")
732 :type '(alist :key-type (string :tag "Type")
733 :value-type (regexp :tag "Path")))
735 ;;;; Plain Text
737 (defcustom org-html-protect-char-alist
738 '(("&" . "&amp;")
739 ("<" . "&lt;")
740 (">" . "&gt;"))
741 "Alist of characters to be converted by `org-html-protect'."
742 :group 'org-export-html
743 :type '(repeat (cons (string :tag "Character")
744 (string :tag "HTML equivalent"))))
746 ;;;; Src Block
748 (defcustom org-html-htmlize-output-type 'inline-css
749 "Output type to be used by htmlize when formatting code snippets.
750 Choices are `css', to export the CSS selectors only, or `inline-css', to
751 export the CSS attribute values inline in the HTML. We use as default
752 `inline-css', in order to make the resulting HTML self-containing.
754 However, this will fail when using Emacs in batch mode for export, because
755 then no rich font definitions are in place. It will also not be good if
756 people with different Emacs setup contribute HTML files to a website,
757 because the fonts will represent the individual setups. In these cases,
758 it is much better to let Org/Htmlize assign classes only, and to use
759 a style file to define the look of these classes.
760 To get a start for your css file, start Emacs session and make sure that
761 all the faces you are interested in are defined, for example by loading files
762 in all modes you want. Then, use the command
763 \\[org-html-htmlize-generate-css] to extract class definitions."
764 :group 'org-export-html
765 :type '(choice (const css) (const inline-css)))
767 (defcustom org-html-htmlize-font-prefix "org-"
768 "The prefix for CSS class names for htmlize font specifications."
769 :group 'org-export-html
770 :type 'string)
772 ;;;; Table
774 (defcustom org-html-table-default-attributes
775 '(:border "2" :cellspacing "0" :cellpadding "6" :rules "groups" :frame "hsides")
776 "Default attributes and values which will be used in table tags.
777 This is a plist where attributes are symbols, starting with
778 colons, and values are strings.
780 When exporting to HTML5, these values will be disregarded."
781 :group 'org-export-html
782 :version "24.4"
783 :package-version '(Org . "8.0")
784 :type '(plist :key-type (symbol :tag "Property")
785 :value-type (string :tag "Value")))
787 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
788 "The opening tag for table header fields.
789 This is customizable so that alignment options can be specified.
790 The first %s will be filled with the scope of the field, either row or col.
791 The second %s will be replaced by a style entry to align the field.
792 See also the variable `org-html-table-use-header-tags-for-first-column'.
793 See also the variable `org-html-table-align-individual-fields'."
794 :group 'org-export-html
795 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
797 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
798 "The opening tag for table data fields.
799 This is customizable so that alignment options can be specified.
800 The first %s will be filled with the scope of the field, either row or col.
801 The second %s will be replaced by a style entry to align the field.
802 See also the variable `org-html-table-align-individual-fields'."
803 :group 'org-export-html
804 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
806 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
807 "The opening and ending tags for table rows.
808 This is customizable so that alignment options can be specified.
809 Instead of strings, these can be Lisp forms that will be
810 evaluated for each row in order to construct the table row tags.
812 During evaluation, these variables will be dynamically bound so that
813 you can reuse them:
815 `row-number': row number (0 is the first row)
816 `rowgroup-number': group number of current row
817 `start-rowgroup-p': non-nil means the row starts a group
818 `end-rowgroup-p': non-nil means the row ends a group
819 `top-row-p': non-nil means this is the top row
820 `bottom-row-p': non-nil means this is the bottom row
822 For example:
824 \(setq org-html-table-row-tags
825 (cons '(cond (top-row-p \"<tr class=\\\"tr-top\\\">\")
826 (bottom-row-p \"<tr class=\\\"tr-bottom\\\">\")
827 (t (if (= (mod row-number 2) 1)
828 \"<tr class=\\\"tr-odd\\\">\"
829 \"<tr class=\\\"tr-even\\\">\")))
830 \"</tr>\"))
832 will use the \"tr-top\" and \"tr-bottom\" classes for the top row
833 and the bottom row, and otherwise alternate between \"tr-odd\" and
834 \"tr-even\" for odd and even rows."
835 :group 'org-export-html
836 :type '(cons
837 (choice :tag "Opening tag"
838 (string :tag "Specify")
839 (sexp))
840 (choice :tag "Closing tag"
841 (string :tag "Specify")
842 (sexp))))
844 (defcustom org-html-table-align-individual-fields t
845 "Non-nil means attach style attributes for alignment to each table field.
846 When nil, alignment will only be specified in the column tags, but this
847 is ignored by some browsers (like Firefox, Safari). Opera does it right
848 though."
849 :group 'org-export-html
850 :type 'boolean)
852 (defcustom org-html-table-use-header-tags-for-first-column nil
853 "Non-nil means format column one in tables with header tags.
854 When nil, also column one will use data tags."
855 :group 'org-export-html
856 :type 'boolean)
858 (defcustom org-html-table-caption-above t
859 "When non-nil, place caption string at the beginning of the table.
860 Otherwise, place it near the end."
861 :group 'org-export-html
862 :type 'boolean)
864 ;;;; Tags
866 (defcustom org-html-tag-class-prefix ""
867 "Prefix to class names for TODO keywords.
868 Each tag gets a class given by the tag itself, with this prefix.
869 The default prefix is empty because it is nice to just use the keyword
870 as a class name. But if you get into conflicts with other, existing
871 CSS classes, then this prefix can be very useful."
872 :group 'org-export-html
873 :type 'string)
875 ;;;; Template :: Generic
877 (defcustom org-html-extension "html"
878 "The extension for exported HTML files."
879 :group 'org-export-html
880 :type 'string)
882 (defcustom org-html-xml-declaration
883 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
884 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
885 "The extension for exported HTML files.
886 %s will be replaced with the charset of the exported file.
887 This may be a string, or an alist with export extensions
888 and corresponding declarations.
890 This declaration only applies when exporting to XHTML."
891 :group 'org-export-html
892 :type '(choice
893 (string :tag "Single declaration")
894 (repeat :tag "Dependent on extension"
895 (cons (string :tag "Extension")
896 (string :tag "Declaration")))))
898 (defcustom org-html-coding-system 'utf-8
899 "Coding system for HTML export.
900 Use utf-8 as the default value."
901 :group 'org-export-html
902 :version "24.4"
903 :package-version '(Org . "8.0")
904 :type 'coding-system)
906 (defcustom org-html-doctype "xhtml-strict"
907 "Document type definition to use for exported HTML files.
908 Can be set with the in-buffer HTML_DOCTYPE property or for
909 publishing, with :html-doctype."
910 :group 'org-export-html
911 :version "24.4"
912 :package-version '(Org . "8.0")
913 :type 'string)
915 (defcustom org-html-html5-fancy nil
916 "Non-nil means using new HTML5 elements.
917 This variable is ignored for anything other than HTML5 export.
919 For compatibility with Internet Explorer, it's probably a good
920 idea to download some form of the html5shiv (for instance
921 https://code.google.com/p/html5shiv/) and add it to your
922 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
923 versions 8 and below."
924 :group 'org-export-html
925 :version "24.4"
926 :package-version '(Org . "8.0")
927 :type 'boolean)
929 (defcustom org-html-container-element "div"
930 "HTML element to use for wrapping top level sections.
931 Can be set with the in-buffer HTML_CONTAINER property or for
932 publishing, with :html-container.
934 Note that changing the default will prevent you from using
935 org-info.js for your website."
936 :group 'org-export-html
937 :version "24.4"
938 :package-version '(Org . "8.0")
939 :type 'string)
941 (defcustom org-html-divs
942 '((preamble "div" "preamble")
943 (content "div" "content")
944 (postamble "div" "postamble"))
945 "Alist of the three section elements for HTML export.
946 The car of each entry is one of 'preamble, 'content or 'postamble.
947 The cdrs of each entry are the ELEMENT_TYPE and ID for each
948 section of the exported document.
950 Note that changing the default will prevent you from using
951 org-info.js for your website."
952 :group 'org-export-html
953 :version "24.4"
954 :package-version '(Org . "8.0")
955 :type '(list :greedy t
956 (list :tag "Preamble"
957 (const :format "" preamble)
958 (string :tag "element") (string :tag " id"))
959 (list :tag "Content"
960 (const :format "" content)
961 (string :tag "element") (string :tag " id"))
962 (list :tag "Postamble" (const :format "" postamble)
963 (string :tag " id") (string :tag "element"))))
965 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
966 "Format used for timestamps in preamble, postamble and metadata.
967 See `format-time-string' for more information on its components."
968 :group 'org-export-html
969 :version "24.4"
970 :package-version '(Org . "8.0")
971 :type 'string)
973 ;;;; Template :: Mathjax
975 (defcustom org-html-mathjax-options
976 '((path "http://orgmode.org/mathjax/MathJax.js")
977 (scale "100")
978 (align "center")
979 (indent "2em")
980 (mathml nil))
981 "Options for MathJax setup.
983 path The path where to find MathJax
984 scale Scaling for the HTML-CSS backend, usually between 100 and 133
985 align How to align display math: left, center, or right
986 indent If align is not center, how far from the left/right side?
987 mathml Should a MathML player be used if available?
988 This is faster and reduces bandwidth use, but currently
989 sometimes has lower spacing quality. Therefore, the default is
990 nil. When browsers get better, this switch can be flipped.
992 You can also customize this for each buffer, using something like
994 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
995 :group 'org-export-html
996 :type '(list :greedy t
997 (list :tag "path (the path from where to load MathJax.js)"
998 (const :format " " path) (string))
999 (list :tag "scale (scaling for the displayed math)"
1000 (const :format " " scale) (string))
1001 (list :tag "align (alignment of displayed equations)"
1002 (const :format " " align) (string))
1003 (list :tag "indent (indentation with left or right alignment)"
1004 (const :format " " indent) (string))
1005 (list :tag "mathml (should MathML display be used is possible)"
1006 (const :format " " mathml) (boolean))))
1008 (defcustom org-html-mathjax-template
1009 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1010 <script type=\"text/javascript\">
1011 <!--/*--><![CDATA[/*><!--*/
1012 MathJax.Hub.Config({
1013 // Only one of the two following lines, depending on user settings
1014 // First allows browser-native MathML display, second forces HTML/CSS
1015 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1016 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1017 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1018 \"TeX/noUndefined.js\"],
1019 tex2jax: {
1020 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1021 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1022 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1023 ignoreClass: \"tex2jax_ignore\",
1024 processEscapes: false,
1025 processEnvironments: true,
1026 preview: \"TeX\"
1028 showProcessingMessages: true,
1029 displayAlign: \"%ALIGN\",
1030 displayIndent: \"%INDENT\",
1032 \"HTML-CSS\": {
1033 scale: %SCALE,
1034 availableFonts: [\"STIX\",\"TeX\"],
1035 preferredFont: \"TeX\",
1036 webFont: \"TeX\",
1037 imageFont: \"TeX\",
1038 showMathMenu: true,
1040 MMLorHTML: {
1041 prefer: {
1042 MSIE: \"MML\",
1043 Firefox: \"MML\",
1044 Opera: \"HTML\",
1045 other: \"HTML\"
1049 /*]]>*///-->
1050 </script>"
1051 "The MathJax setup for XHTML files."
1052 :group 'org-export-html
1053 :type 'string)
1055 ;;;; Template :: Postamble
1057 (defcustom org-html-postamble 'auto
1058 "Non-nil means insert a postamble in HTML export.
1060 When set to 'auto, check against the
1061 `org-export-with-author/email/creator/date' variables to set the
1062 content of the postamble. When set to a string, use this string
1063 as the postamble. When t, insert a string as defined by the
1064 formatting string in `org-html-postamble-format'.
1066 When set to a function, apply this function and insert the
1067 returned string. The function takes the property list of export
1068 options as its only argument.
1070 Setting :html-postamble in publishing projects will take
1071 precedence over this variable."
1072 :group 'org-export-html
1073 :type '(choice (const :tag "No postamble" nil)
1074 (const :tag "Auto postamble" auto)
1075 (const :tag "Default formatting string" t)
1076 (string :tag "Custom formatting string")
1077 (function :tag "Function (must return a string)")))
1079 (defcustom org-html-postamble-format
1080 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1081 <p class=\"date\">Date: %d</p>
1082 <p class=\"creator\">%c</p>
1083 <p class=\"validation\">%v</p>"))
1084 "Alist of languages and format strings for the HTML postamble.
1086 The first element of each list is the language code, as used for
1087 the LANGUAGE keyword. See `org-export-default-language'.
1089 The second element of each list is a format string to format the
1090 postamble itself. This format string can contain these elements:
1092 %t stands for the title.
1093 %a stands for the author's name.
1094 %e stands for the author's email.
1095 %d stands for the date.
1096 %c will be replaced by `org-html-creator-string'.
1097 %v will be replaced by `org-html-validation-link'.
1098 %T will be replaced by the export time.
1099 %C will be replaced by the last modification time.
1101 If you need to use a \"%\" character, you need to escape it
1102 like that: \"%%\"."
1103 :group 'org-export-html
1104 :type '(repeat
1105 (list (string :tag "Language")
1106 (string :tag "Format string"))))
1108 (defcustom org-html-validation-link
1109 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1110 "Link to HTML validation service."
1111 :group 'org-export-html
1112 :type 'string)
1114 (defcustom org-html-creator-string
1115 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1116 emacs-version
1117 (if (fboundp 'org-version) (org-version) "unknown version"))
1118 "Information about the creator of the HTML document.
1119 This option can also be set on with the CREATOR keyword."
1120 :group 'org-export-html
1121 :type '(string :tag "Creator string"))
1123 ;;;; Template :: Preamble
1125 (defcustom org-html-preamble t
1126 "Non-nil means insert a preamble in HTML export.
1128 When t, insert a string as defined by the formatting string in
1129 `org-html-preamble-format'. When set to a string, use this
1130 formatting string instead (see `org-html-postamble-format' for an
1131 example of such a formatting string).
1133 When set to a function, apply this function and insert the
1134 returned string. The function takes the property list of export
1135 options as its only argument.
1137 Setting :html-preamble in publishing projects will take
1138 precedence over this variable."
1139 :group 'org-export-html
1140 :type '(choice (const :tag "No preamble" nil)
1141 (const :tag "Default preamble" t)
1142 (string :tag "Custom formatting string")
1143 (function :tag "Function (must return a string)")))
1145 (defcustom org-html-preamble-format '(("en" ""))
1146 "Alist of languages and format strings for the HTML preamble.
1148 The first element of each list is the language code, as used for
1149 the LANGUAGE keyword. See `org-export-default-language'.
1151 The second element of each list is a format string to format the
1152 preamble itself. This format string can contain these elements:
1154 %t stands for the title.
1155 %a stands for the author's name.
1156 %e stands for the author's email.
1157 %d stands for the date.
1158 %c will be replaced by `org-html-creator-string'.
1159 %v will be replaced by `org-html-validation-link'.
1160 %T will be replaced by the export time.
1161 %C will be replaced by the last modification time.
1163 If you need to use a \"%\" character, you need to escape it
1164 like that: \"%%\".
1166 See the default value of `org-html-postamble-format' for an
1167 example."
1168 :group 'org-export-html
1169 :type '(repeat
1170 (list (string :tag "Language")
1171 (string :tag "Format string"))))
1173 (defcustom org-html-link-up ""
1174 "Where should the \"UP\" link of exported HTML pages lead?"
1175 :group 'org-export-html
1176 :type '(string :tag "File or URL"))
1178 (defcustom org-html-link-home ""
1179 "Where should the \"HOME\" link of exported HTML pages lead?"
1180 :group 'org-export-html
1181 :type '(string :tag "File or URL"))
1183 (defcustom org-html-link-use-abs-url nil
1184 "Should we prepend relative links with HTML_LINK_HOME?"
1185 :group 'org-export-html
1186 :version "24.4"
1187 :package-version '(Org . "8.1")
1188 :type 'boolean)
1190 (defcustom org-html-home/up-format
1191 "<div id=\"org-div-home-and-up\">
1192 <a accesskey=\"h\" href=\"%s\"> UP </a>
1194 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1195 </div>"
1196 "Snippet used to insert the HOME and UP links.
1197 This is a format string, the first %s will receive the UP link,
1198 the second the HOME link. If both `org-html-link-up' and
1199 `org-html-link-home' are empty, the entire snippet will be
1200 ignored."
1201 :group 'org-export-html
1202 :type 'string)
1204 ;;;; Template :: Scripts
1206 (define-obsolete-variable-alias
1207 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1208 (defcustom org-html-head-include-scripts t
1209 "Non-nil means include the JavaScript snippets in exported HTML files.
1210 The actual script is defined in `org-html-scripts' and should
1211 not be modified."
1212 :group 'org-export-html
1213 :version "24.4"
1214 :package-version '(Org . "8.0")
1215 :type 'boolean)
1217 ;;;; Template :: Styles
1219 (define-obsolete-variable-alias
1220 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1221 (defcustom org-html-head-include-default-style t
1222 "Non-nil means include the default style in exported HTML files.
1223 The actual style is defined in `org-html-style-default' and
1224 should not be modified. Use `org-html-head' to use your own
1225 style information."
1226 :group 'org-export-html
1227 :version "24.4"
1228 :package-version '(Org . "8.0")
1229 :type 'boolean)
1230 ;;;###autoload
1231 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1233 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1234 (defcustom org-html-head ""
1235 "Org-wide head definitions for exported HTML files.
1237 This variable can contain the full HTML structure to provide a
1238 style, including the surrounding HTML tags. You can consider
1239 including definitions for the following classes: title, todo,
1240 done, timestamp, timestamp-kwd, tag, target.
1242 For example, a valid value would be:
1244 <style type=\"text/css\">
1245 <![CDATA[
1246 p { font-weight: normal; color: gray; }
1247 h1 { color: black; }
1248 .title { text-align: center; }
1249 .todo, .timestamp-kwd { color: red; }
1250 .done { color: green; }
1252 </style>
1254 If you want to refer to an external style, use something like
1256 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1258 As the value of this option simply gets inserted into the HTML
1259 <head> header, you can use it to add any arbitrary text to the
1260 header.
1262 You can set this on a per-file basis using #+HTML_HEAD:,
1263 or for publication projects using the :html-head property."
1264 :group 'org-export-html
1265 :version "24.4"
1266 :package-version '(Org . "8.0")
1267 :type 'string)
1268 ;;;###autoload
1269 (put 'org-html-head 'safe-local-variable 'stringp)
1271 (defcustom org-html-head-extra ""
1272 "More head information to add in the HTML output.
1274 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1275 or for publication projects using the :html-head-extra property."
1276 :group 'org-export-html
1277 :version "24.4"
1278 :package-version '(Org . "8.0")
1279 :type 'string)
1280 ;;;###autoload
1281 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1283 ;;;; Todos
1285 (defcustom org-html-todo-kwd-class-prefix ""
1286 "Prefix to class names for TODO keywords.
1287 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1288 The default prefix is empty because it is nice to just use the keyword
1289 as a class name. But if you get into conflicts with other, existing
1290 CSS classes, then this prefix can be very useful."
1291 :group 'org-export-html
1292 :type 'string)
1295 ;;; Internal Functions
1297 (defun org-html-xhtml-p (info)
1298 (let ((dt (downcase (plist-get info :html-doctype))))
1299 (string-match-p "xhtml" dt)))
1301 (defun org-html-html5-p (info)
1302 (let ((dt (downcase (plist-get info :html-doctype))))
1303 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1305 (defun org-html-close-tag (tag attr info)
1306 (concat "<" tag " " attr
1307 (if (org-html-xhtml-p info) " />" ">")))
1309 (defun org-html-doctype (info)
1310 "Return correct html doctype tag from `org-html-doctype-alist',
1311 or the literal value of :html-doctype from INFO if :html-doctype
1312 is not found in the alist.
1313 INFO is a plist used as a communication channel."
1314 (let ((dt (plist-get info :html-doctype)))
1315 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1317 (defun org-html--make-attribute-string (attributes)
1318 "Return a list of attributes, as a string.
1319 ATTRIBUTES is a plist where values are either strings or nil. An
1320 attributes with a nil value will be omitted from the result."
1321 (let (output)
1322 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1323 (cond ((null item) (pop output))
1324 ((symbolp item) (push (substring (symbol-name item) 1) output))
1325 (t (let ((key (car output))
1326 (value (replace-regexp-in-string
1327 "\"" "&quot;" (org-html-encode-plain-text item))))
1328 (setcar output (format "%s=\"%s\"" key value))))))))
1330 (defun org-html--wrap-image (contents info &optional caption label)
1331 "Wrap CONTENTS string within an appropriate environment for images.
1332 INFO is a plist used as a communication channel. When optional
1333 arguments CAPTION and LABEL are given, use them for caption and
1334 \"id\" attribute."
1335 (let ((html5-fancy (and (org-html-html5-p info)
1336 (plist-get info :html-html5-fancy))))
1337 (format (if html5-fancy "\n<figure%s>%s%s\n</figure>"
1338 "\n<div%s class=\"figure\">%s%s\n</div>")
1339 ;; ID.
1340 (if (not (org-string-nw-p label)) ""
1341 (format " id=\"%s\"" (org-export-solidify-link-text label)))
1342 ;; Contents.
1343 (format "\n<p>%s</p>" contents)
1344 ;; Caption.
1345 (if (not (org-string-nw-p caption)) ""
1346 (format (if html5-fancy "\n<figcaption>%s</figcaption>"
1347 "\n<p>%s</p>")
1348 caption)))))
1350 (defun org-html--format-image (source attributes info)
1351 "Return \"img\" tag with given SOURCE and ATTRIBUTES.
1352 SOURCE is a string specifying the location of the image.
1353 ATTRIBUTES is a plist, as returned by
1354 `org-export-read-attribute'. INFO is a plist used as
1355 a communication channel."
1356 (org-html-close-tag
1357 "img"
1358 (org-html--make-attribute-string
1359 (org-combine-plists
1360 (list :src source
1361 :alt (if (string-match-p "^ltxpng/" source)
1362 (org-html-encode-plain-text
1363 (org-find-text-property-in-string 'org-latex-src source))
1364 (file-name-nondirectory source)))
1365 attributes))
1366 info))
1368 (defun org-html--textarea-block (element)
1369 "Transcode ELEMENT into a textarea block.
1370 ELEMENT is either a src block or an example block."
1371 (let* ((code (car (org-export-unravel-code element)))
1372 (attr (org-export-read-attribute :attr_html element)))
1373 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1374 (or (plist-get attr :width) 80)
1375 (or (plist-get attr :height) (org-count-lines code))
1376 code)))
1378 (defun org-html--has-caption-p (element &optional info)
1379 "Non-nil when ELEMENT has a caption affiliated keyword.
1380 INFO is a plist used as a communication channel. This function
1381 is meant to be used as a predicate for `org-export-get-ordinal' or
1382 a value to `org-html-standalone-image-predicate'."
1383 (org-element-property :caption element))
1385 ;;;; Table
1387 (defun org-html-htmlize-region-for-paste (beg end)
1388 "Convert the region between BEG and END to HTML, using htmlize.el.
1389 This is much like `htmlize-region-for-paste', only that it uses
1390 the settings define in the org-... variables."
1391 (let* ((htmlize-output-type org-html-htmlize-output-type)
1392 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1393 (htmlbuf (htmlize-region beg end)))
1394 (unwind-protect
1395 (with-current-buffer htmlbuf
1396 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1397 (plist-get htmlize-buffer-places 'content-end)))
1398 (kill-buffer htmlbuf))))
1400 ;;;###autoload
1401 (defun org-html-htmlize-generate-css ()
1402 "Create the CSS for all font definitions in the current Emacs session.
1403 Use this to create face definitions in your CSS style file that can then
1404 be used by code snippets transformed by htmlize.
1405 This command just produces a buffer that contains class definitions for all
1406 faces used in the current Emacs session. You can copy and paste the ones you
1407 need into your CSS file.
1409 If you then set `org-html-htmlize-output-type' to `css', calls
1410 to the function `org-html-htmlize-region-for-paste' will
1411 produce code that uses these same face definitions."
1412 (interactive)
1413 (require 'htmlize)
1414 (and (get-buffer "*html*") (kill-buffer "*html*"))
1415 (with-temp-buffer
1416 (let ((fl (face-list))
1417 (htmlize-css-name-prefix "org-")
1418 (htmlize-output-type 'css)
1419 f i)
1420 (while (setq f (pop fl)
1421 i (and f (face-attribute f :inherit)))
1422 (when (and (symbolp f) (or (not i) (not (listp i))))
1423 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1424 (htmlize-region (point-min) (point-max))))
1425 (org-pop-to-buffer-same-window "*html*")
1426 (goto-char (point-min))
1427 (if (re-search-forward "<style" nil t)
1428 (delete-region (point-min) (match-beginning 0)))
1429 (if (re-search-forward "</style>" nil t)
1430 (delete-region (1+ (match-end 0)) (point-max)))
1431 (beginning-of-line 1)
1432 (if (looking-at " +") (replace-match ""))
1433 (goto-char (point-min)))
1435 (defun org-html--make-string (n string)
1436 "Build a string by concatenating N times STRING."
1437 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1439 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1440 "Turn todo keyword KWD into a valid class name.
1441 Replaces invalid characters with \"_\"."
1442 (save-match-data
1443 (while (string-match "[^a-zA-Z0-9_]" kwd)
1444 (setq kwd (replace-match "_" t t kwd))))
1445 kwd)
1447 (defun org-html-format-footnote-reference (n def refcnt)
1448 "Format footnote reference N with definition DEF into HTML."
1449 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1450 (format org-html-footnote-format
1451 (let* ((id (format "fnr.%s%s" n extra))
1452 (href (format " href=\"#fn.%s\"" n))
1453 (attributes (concat " class=\"footref\"" href)))
1454 (org-html--anchor id n attributes)))))
1456 (defun org-html-format-footnotes-section (section-name definitions)
1457 "Format footnotes section SECTION-NAME."
1458 (if (not definitions) ""
1459 (format org-html-footnotes-section section-name definitions)))
1461 (defun org-html-format-footnote-definition (fn)
1462 "Format the footnote definition FN."
1463 (let ((n (car fn)) (def (cdr fn)))
1464 (format
1465 "<div class=\"footdef\">%s %s</div>\n"
1466 (format org-html-footnote-format
1467 (let* ((id (format "fn.%s" n))
1468 (href (format " href=\"#fnr.%s\"" n))
1469 (attributes (concat " class=\"footnum\"" href)))
1470 (org-html--anchor id n attributes)))
1471 def)))
1473 (defun org-html-footnote-section (info)
1474 "Format the footnote section.
1475 INFO is a plist used as a communication channel."
1476 (let* ((fn-alist (org-export-collect-footnote-definitions
1477 (plist-get info :parse-tree) info))
1478 (fn-alist
1479 (loop for (n type raw) in fn-alist collect
1480 (cons n (if (eq (org-element-type raw) 'org-data)
1481 (org-trim (org-export-data raw info))
1482 (format "<p>%s</p>"
1483 (org-trim (org-export-data raw info))))))))
1484 (when fn-alist
1485 (org-html-format-footnotes-section
1486 (org-html--translate "Footnotes" info)
1487 (format
1488 "\n%s\n"
1489 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1492 ;;; Template
1494 (defun org-html--build-meta-info (info)
1495 "Return meta tags for exported document.
1496 INFO is a plist used as a communication channel."
1497 (let ((protect-string
1498 (lambda (str)
1499 (replace-regexp-in-string
1500 "\"" "&quot;" (org-html-encode-plain-text str))))
1501 (title (org-export-data (plist-get info :title) info))
1502 (author (and (plist-get info :with-author)
1503 (let ((auth (plist-get info :author)))
1504 (and auth
1505 ;; Return raw Org syntax, skipping non
1506 ;; exportable objects.
1507 (org-element-interpret-data
1508 (org-element-map auth
1509 (cons 'plain-text org-element-all-objects)
1510 'identity info))))))
1511 (description (plist-get info :description))
1512 (keywords (plist-get info :keywords))
1513 (charset (or (and org-html-coding-system
1514 (fboundp 'coding-system-get)
1515 (coding-system-get org-html-coding-system
1516 'mime-charset))
1517 "iso-8859-1")))
1518 (concat
1519 (format "<title>%s</title>\n" title)
1520 (when (plist-get info :time-stamp-file)
1521 (format-time-string
1522 (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
1523 (format
1524 (if (org-html-html5-p info)
1525 (org-html-close-tag "meta" " charset=\"%s\"" info)
1526 (org-html-close-tag
1527 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1528 info))
1529 charset) "\n"
1530 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1531 "\n"
1532 (and (org-string-nw-p author)
1533 (concat
1534 (org-html-close-tag "meta"
1535 (format " name=\"author\" content=\"%s\""
1536 (funcall protect-string author))
1537 info)
1538 "\n"))
1539 (and (org-string-nw-p description)
1540 (concat
1541 (org-html-close-tag "meta"
1542 (format " name=\"description\" content=\"%s\"\n"
1543 (funcall protect-string description))
1544 info)
1545 "\n"))
1546 (and (org-string-nw-p keywords)
1547 (concat
1548 (org-html-close-tag "meta"
1549 (format " name=\"keywords\" content=\"%s\""
1550 (funcall protect-string keywords))
1551 info)
1552 "\n")))))
1554 (defun org-html--build-head (info)
1555 "Return information for the <head>..</head> of the HTML output.
1556 INFO is a plist used as a communication channel."
1557 (org-element-normalize-string
1558 (concat
1559 (when (plist-get info :html-head-include-default-style)
1560 (org-element-normalize-string org-html-style-default))
1561 (org-element-normalize-string (plist-get info :html-head))
1562 (org-element-normalize-string (plist-get info :html-head-extra))
1563 (when (and (plist-get info :html-htmlized-css-url)
1564 (eq org-html-htmlize-output-type 'css))
1565 (org-html-close-tag "link"
1566 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1567 (plist-get info :html-htmlized-css-url))
1568 info))
1569 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1571 (defun org-html--build-mathjax-config (info)
1572 "Insert the user setup into the mathjax template.
1573 INFO is a plist used as a communication channel."
1574 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1575 (org-element-map (plist-get info :parse-tree)
1576 '(latex-fragment latex-environment) 'identity info t))
1577 (let ((template org-html-mathjax-template)
1578 (options org-html-mathjax-options)
1579 (in-buffer (or (plist-get info :html-mathjax) ""))
1580 name val (yes " ") (no "// ") x)
1581 (mapc
1582 (lambda (e)
1583 (setq name (car e) val (nth 1 e))
1584 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1585 (setq val (car (read-from-string
1586 (substring in-buffer (match-end 0))))))
1587 (if (not (stringp val)) (setq val (format "%s" val)))
1588 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1589 (setq template (replace-match val t t template))))
1590 options)
1591 (setq val (nth 1 (assq 'mathml options)))
1592 (if (string-match (concat "\\<mathml:") in-buffer)
1593 (setq val (car (read-from-string
1594 (substring in-buffer (match-end 0))))))
1595 ;; Exchange prefixes depending on mathml setting.
1596 (if (not val) (setq x yes yes no no x))
1597 ;; Replace cookies to turn on or off the config/jax lines.
1598 (if (string-match ":MMLYES:" template)
1599 (setq template (replace-match yes t t template)))
1600 (if (string-match ":MMLNO:" template)
1601 (setq template (replace-match no t t template)))
1602 ;; Return the modified template.
1603 (org-element-normalize-string template))))
1605 (defun org-html-format-spec (info)
1606 "Return format specification for elements that can be
1607 used in the preamble or postamble."
1608 `((?t . ,(org-export-data (plist-get info :title) info))
1609 (?d . ,(org-export-data (org-export-get-date info) info))
1610 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1611 (?a . ,(org-export-data (plist-get info :author) info))
1612 (?e . ,(mapconcat
1613 (lambda (e)
1614 (format "<a href=\"mailto:%s\">%s</a>" e e))
1615 (split-string (plist-get info :email) ",+ *")
1616 ", "))
1617 (?c . ,(plist-get info :creator))
1618 (?C . ,(let ((file (plist-get info :input-file)))
1619 (format-time-string org-html-metadata-timestamp-format
1620 (if file (nth 5 (file-attributes file))
1621 (current-time)))))
1622 (?v . ,(or org-html-validation-link ""))))
1624 (defun org-html--build-pre/postamble (type info)
1625 "Return document preamble or postamble as a string, or nil.
1626 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1627 communication channel."
1628 (let ((section (plist-get info (intern (format ":html-%s" type))))
1629 (spec (org-html-format-spec info)))
1630 (when section
1631 (let ((section-contents
1632 (if (functionp section) (funcall section info)
1633 (cond
1634 ((stringp section) (format-spec section spec))
1635 ((eq section 'auto)
1636 (let ((date (cdr (assq ?d spec)))
1637 (author (cdr (assq ?a spec)))
1638 (email (cdr (assq ?e spec)))
1639 (creator (cdr (assq ?c spec)))
1640 (timestamp (cdr (assq ?T spec)))
1641 (validation-link (cdr (assq ?v spec))))
1642 (concat
1643 (when (and (plist-get info :with-date)
1644 (org-string-nw-p date))
1645 (format "<p class=\"date\">%s: %s</p>\n"
1646 (org-html--translate "Date" info)
1647 date))
1648 (when (and (plist-get info :with-author)
1649 (org-string-nw-p author))
1650 (format "<p class=\"author\">%s: %s</p>\n"
1651 (org-html--translate "Author" info)
1652 author))
1653 (when (and (plist-get info :with-email)
1654 (org-string-nw-p email))
1655 (format "<p class=\"email\">%s: %s</p>\n"
1656 (org-html--translate "Email" info)
1657 email))
1658 (when (plist-get info :time-stamp-file)
1659 (format
1660 "<p class=\"date\">%s: %s</p>\n"
1661 (org-html--translate "Created" info)
1662 (format-time-string org-html-metadata-timestamp-format)))
1663 (when (plist-get info :with-creator)
1664 (format "<p class=\"creator\">%s</p>\n" creator))
1665 (format "<p class=\"validation\">%s</p>\n"
1666 validation-link))))
1667 (t (format-spec
1668 (or (cadr (assoc
1669 (plist-get info :language)
1670 (eval (intern
1671 (format "org-html-%s-format" type)))))
1672 (cadr
1673 (assoc
1674 "en"
1675 (eval
1676 (intern (format "org-html-%s-format" type))))))
1677 spec))))))
1678 (when (org-string-nw-p section-contents)
1679 (concat
1680 (format "<%s id=\"%s\" class=\"%s\">\n"
1681 (nth 1 (assq type org-html-divs))
1682 (nth 2 (assq type org-html-divs))
1683 org-html--pre/postamble-class)
1684 (org-element-normalize-string section-contents)
1685 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1687 (defun org-html-inner-template (contents info)
1688 "Return body of document string after HTML conversion.
1689 CONTENTS is the transcoded contents string. INFO is a plist
1690 holding export options."
1691 (concat
1692 ;; Table of contents.
1693 (let ((depth (plist-get info :with-toc)))
1694 (when depth (org-html-toc depth info)))
1695 ;; Document contents.
1696 contents
1697 ;; Footnotes section.
1698 (org-html-footnote-section info)))
1700 (defun org-html-template (contents info)
1701 "Return complete document string after HTML conversion.
1702 CONTENTS is the transcoded contents string. INFO is a plist
1703 holding export options."
1704 (concat
1705 (when (and (not (org-html-html5-p info)) (org-html-xhtml-p info))
1706 (let ((decl (or (and (stringp org-html-xml-declaration)
1707 org-html-xml-declaration)
1708 (cdr (assoc (plist-get info :html-extension)
1709 org-html-xml-declaration))
1710 (cdr (assoc "html" org-html-xml-declaration))
1712 "")))
1713 (when (not (or (eq nil decl) (string= "" decl)))
1714 (format "%s\n"
1715 (format decl
1716 (or (and org-html-coding-system
1717 (fboundp 'coding-system-get)
1718 (coding-system-get org-html-coding-system 'mime-charset))
1719 "iso-8859-1"))))))
1720 (org-html-doctype info)
1721 "\n"
1722 (concat "<html"
1723 (when (org-html-xhtml-p info)
1724 (format
1725 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1726 (plist-get info :language) (plist-get info :language)))
1727 ">\n")
1728 "<head>\n"
1729 (org-html--build-meta-info info)
1730 (org-html--build-head info)
1731 (org-html--build-mathjax-config info)
1732 "</head>\n"
1733 "<body>\n"
1734 (let ((link-up (org-trim (plist-get info :html-link-up)))
1735 (link-home (org-trim (plist-get info :html-link-home))))
1736 (unless (and (string= link-up "") (string= link-home ""))
1737 (format org-html-home/up-format
1738 (or link-up link-home)
1739 (or link-home link-up))))
1740 ;; Preamble.
1741 (org-html--build-pre/postamble 'preamble info)
1742 ;; Document contents.
1743 (format "<%s id=\"%s\">\n"
1744 (nth 1 (assq 'content org-html-divs))
1745 (nth 2 (assq 'content org-html-divs)))
1746 ;; Document title.
1747 (let ((title (plist-get info :title)))
1748 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1749 contents
1750 (format "</%s>\n"
1751 (nth 1 (assq 'content org-html-divs)))
1752 ;; Postamble.
1753 (org-html--build-pre/postamble 'postamble info)
1754 ;; Closing document.
1755 "</body>\n</html>"))
1757 (defun org-html--translate (s info)
1758 "Translate string S according to specified language.
1759 INFO is a plist used as a communication channel."
1760 (org-export-translate s :html info))
1762 ;;;; Anchor
1764 (defun org-html--anchor (&optional id desc attributes)
1765 "Format a HTML anchor."
1766 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1767 (attributes (concat (and id (format " id=\"%s\"" id))
1768 (and name (format " name=\"%s\"" name))
1769 attributes)))
1770 (format "<a%s>%s</a>" attributes (or desc ""))))
1772 ;;;; Todo
1774 (defun org-html--todo (todo)
1775 "Format TODO keywords into HTML."
1776 (when todo
1777 (format "<span class=\"%s %s%s\">%s</span>"
1778 (if (member todo org-done-keywords) "done" "todo")
1779 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1780 todo)))
1782 ;;;; Tags
1784 (defun org-html--tags (tags)
1785 "Format TAGS into HTML."
1786 (when tags
1787 (format "<span class=\"tag\">%s</span>"
1788 (mapconcat
1789 (lambda (tag)
1790 (format "<span class=\"%s\">%s</span>"
1791 (concat org-html-tag-class-prefix
1792 (org-html-fix-class-name tag))
1793 tag))
1794 tags "&#xa0;"))))
1796 ;;;; Headline
1798 (defun* org-html-format-headline
1799 (todo todo-type priority text tags
1800 &key level section-number headline-label &allow-other-keys)
1801 "Format a headline in HTML."
1802 (let ((section-number
1803 (when section-number
1804 (format "<span class=\"section-number-%d\">%s</span> "
1805 level section-number)))
1806 (todo (org-html--todo todo))
1807 (tags (org-html--tags tags)))
1808 (concat section-number todo (and todo " ") text
1809 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1811 ;;;; Src Code
1813 (defun org-html-fontify-code (code lang)
1814 "Color CODE with htmlize library.
1815 CODE is a string representing the source code to colorize. LANG
1816 is the language used for CODE, as a string, or nil."
1817 (when code
1818 (cond
1819 ;; Case 1: No lang. Possibly an example block.
1820 ((not lang)
1821 ;; Simple transcoding.
1822 (org-html-encode-plain-text code))
1823 ;; Case 2: No htmlize or an inferior version of htmlize
1824 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1825 ;; Emit a warning.
1826 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1827 ;; Simple transcoding.
1828 (org-html-encode-plain-text code))
1830 ;; Map language
1831 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1832 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1833 (cond
1834 ;; Case 1: Language is not associated with any Emacs mode
1835 ((not (functionp lang-mode))
1836 ;; Simple transcoding.
1837 (org-html-encode-plain-text code))
1838 ;; Case 2: Default. Fontify code.
1840 ;; htmlize
1841 (setq code (with-temp-buffer
1842 ;; Switch to language-specific mode.
1843 (funcall lang-mode)
1844 (insert code)
1845 ;; Fontify buffer.
1846 (font-lock-fontify-buffer)
1847 ;; Remove formatting on newline characters.
1848 (save-excursion
1849 (let ((beg (point-min))
1850 (end (point-max)))
1851 (goto-char beg)
1852 (while (progn (end-of-line) (< (point) end))
1853 (put-text-property (point) (1+ (point)) 'face nil)
1854 (forward-char 1))))
1855 (org-src-mode)
1856 (set-buffer-modified-p nil)
1857 ;; Htmlize region.
1858 (org-html-htmlize-region-for-paste
1859 (point-min) (point-max))))
1860 ;; Strip any enclosing <pre></pre> tags.
1861 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1862 (end (and beg (string-match "</pre>\\'" code))))
1863 (if (and beg end) (substring code beg end) code)))))))))
1865 (defun org-html-do-format-code
1866 (code &optional lang refs retain-labels num-start)
1867 "Format CODE string as source code.
1868 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1869 respectively, the language of the source code, as a string, an
1870 alist between line numbers and references (as returned by
1871 `org-export-unravel-code'), a boolean specifying if labels should
1872 appear in the source code, and the number associated to the first
1873 line of code."
1874 (let* ((code-lines (org-split-string code "\n"))
1875 (code-length (length code-lines))
1876 (num-fmt
1877 (and num-start
1878 (format "%%%ds: "
1879 (length (number-to-string (+ code-length num-start))))))
1880 (code (org-html-fontify-code code lang)))
1881 (org-export-format-code
1882 code
1883 (lambda (loc line-num ref)
1884 (setq loc
1885 (concat
1886 ;; Add line number, if needed.
1887 (when num-start
1888 (format "<span class=\"linenr\">%s</span>"
1889 (format num-fmt line-num)))
1890 ;; Transcoded src line.
1892 ;; Add label, if needed.
1893 (when (and ref retain-labels) (format " (%s)" ref))))
1894 ;; Mark transcoded line as an anchor, if needed.
1895 (if (not ref) loc
1896 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1897 ref loc)))
1898 num-start refs)))
1900 (defun org-html-format-code (element info)
1901 "Format contents of ELEMENT as source code.
1902 ELEMENT is either an example block or a src block. INFO is
1903 a plist used as a communication channel."
1904 (let* ((lang (org-element-property :language element))
1905 ;; Extract code and references.
1906 (code-info (org-export-unravel-code element))
1907 (code (car code-info))
1908 (refs (cdr code-info))
1909 ;; Does the src block contain labels?
1910 (retain-labels (org-element-property :retain-labels element))
1911 ;; Does it have line numbers?
1912 (num-start (case (org-element-property :number-lines element)
1913 (continued (org-export-get-loc element info))
1914 (new 0))))
1915 (org-html-do-format-code code lang refs retain-labels num-start)))
1918 ;;; Tables of Contents
1920 (defun org-html-toc (depth info)
1921 "Build a table of contents.
1922 DEPTH is an integer specifying the depth of the table. INFO is a
1923 plist used as a communication channel. Return the table of
1924 contents as a string, or nil if it is empty."
1925 (let ((toc-entries
1926 (mapcar (lambda (headline)
1927 (cons (org-html--format-toc-headline headline info)
1928 (org-export-get-relative-level headline info)))
1929 (org-export-collect-headlines info depth)))
1930 (outer-tag (if (and (org-html-html5-p info)
1931 (plist-get info :html-html5-fancy))
1932 "nav"
1933 "div")))
1934 (when toc-entries
1935 (concat (format "<%s id=\"table-of-contents\">\n" outer-tag)
1936 (format "<h%d>%s</h%d>\n"
1937 org-html-toplevel-hlevel
1938 (org-html--translate "Table of Contents" info)
1939 org-html-toplevel-hlevel)
1940 "<div id=\"text-table-of-contents\">"
1941 (org-html--toc-text toc-entries)
1942 "</div>\n"
1943 (format "</%s>\n" outer-tag)))))
1945 (defun org-html--toc-text (toc-entries)
1946 "Return innards of a table of contents, as a string.
1947 TOC-ENTRIES is an alist where key is an entry title, as a string,
1948 and value is its relative level, as an integer."
1949 (let* ((prev-level (1- (cdar toc-entries)))
1950 (start-level prev-level))
1951 (concat
1952 (mapconcat
1953 (lambda (entry)
1954 (let ((headline (car entry))
1955 (level (cdr entry)))
1956 (concat
1957 (let* ((cnt (- level prev-level))
1958 (times (if (> cnt 0) (1- cnt) (- cnt)))
1959 rtn)
1960 (setq prev-level level)
1961 (concat
1962 (org-html--make-string
1963 times (cond ((> cnt 0) "\n<ul>\n<li>")
1964 ((< cnt 0) "</li>\n</ul>\n")))
1965 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1966 headline)))
1967 toc-entries "")
1968 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1970 (defun org-html--format-toc-headline (headline info)
1971 "Return an appropriate table of contents entry for HEADLINE.
1972 INFO is a plist used as a communication channel."
1973 (let* ((headline-number (org-export-get-headline-number headline info))
1974 (section-number
1975 (and (not (org-export-low-level-p headline info))
1976 (org-export-numbered-headline-p headline info)
1977 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1978 (tags (and (eq (plist-get info :with-tags) t)
1979 (org-export-get-tags headline info))))
1980 (format "<a href=\"#%s\">%s</a>"
1981 ;; Label.
1982 (org-export-solidify-link-text
1983 (or (org-element-property :CUSTOM_ID headline)
1984 (concat "sec-" (mapconcat 'number-to-string
1985 headline-number "-"))))
1986 ;; Body.
1987 (concat section-number
1988 (org-export-data-with-backend
1989 (org-export-get-alt-title headline info)
1990 ;; Create an anonymous back-end that will ignore
1991 ;; any footnote-reference, link, radio-target and
1992 ;; target in table of contents.
1993 (org-export-create-backend
1994 :parent 'html
1995 :transcoders '((footnote-reference . ignore)
1996 (link . (lambda (object c i) c))
1997 (radio-target . (lambda (object c i) c))
1998 (target . ignore)))
1999 info)
2000 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
2002 (defun org-html-list-of-listings (info)
2003 "Build a list of listings.
2004 INFO is a plist used as a communication channel. Return the list
2005 of listings as a string, or nil if it is empty."
2006 (let ((lol-entries (org-export-collect-listings info)))
2007 (when lol-entries
2008 (concat "<div id=\"list-of-listings\">\n"
2009 (format "<h%d>%s</h%d>\n"
2010 org-html-toplevel-hlevel
2011 (org-html--translate "List of Listings" info)
2012 org-html-toplevel-hlevel)
2013 "<div id=\"text-list-of-listings\">\n<ul>\n"
2014 (let ((count 0)
2015 (initial-fmt (format "<span class=\"listing-number\">%s</span>"
2016 (org-html--translate "Listing %d:" info))))
2017 (mapconcat
2018 (lambda (entry)
2019 (let ((label (org-element-property :name entry))
2020 (title (org-trim
2021 (org-export-data
2022 (or (org-export-get-caption entry t)
2023 (org-export-get-caption entry))
2024 info))))
2025 (concat
2026 "<li>"
2027 (if (not label)
2028 (concat (format initial-fmt (incf count)) " " title)
2029 (format "<a href=\"#%s\">%s %s</a>"
2030 (org-export-solidify-link-text label)
2031 (format initial-fmt (incf count))
2032 title))
2033 "</li>")))
2034 lol-entries "\n"))
2035 "\n</ul>\n</div>\n</div>"))))
2037 (defun org-html-list-of-tables (info)
2038 "Build a list of tables.
2039 INFO is a plist used as a communication channel. Return the list
2040 of tables as a string, or nil if it is empty."
2041 (let ((lol-entries (org-export-collect-tables info)))
2042 (when lol-entries
2043 (concat "<div id=\"list-of-tables\">\n"
2044 (format "<h%d>%s</h%d>\n"
2045 org-html-toplevel-hlevel
2046 (org-html--translate "List of Tables" info)
2047 org-html-toplevel-hlevel)
2048 "<div id=\"text-list-of-tables\">\n<ul>\n"
2049 (let ((count 0)
2050 (initial-fmt (format "<span class=\"table-number\">%s</span>"
2051 (org-html--translate "Table %d:" info))))
2052 (mapconcat
2053 (lambda (entry)
2054 (let ((label (org-element-property :name entry))
2055 (title (org-trim
2056 (org-export-data
2057 (or (org-export-get-caption entry t)
2058 (org-export-get-caption entry))
2059 info))))
2060 (concat
2061 "<li>"
2062 (if (not label)
2063 (concat (format initial-fmt (incf count)) " " title)
2064 (format "<a href=\"#%s\">%s %s</a>"
2065 (org-export-solidify-link-text label)
2066 (format initial-fmt (incf count))
2067 title))
2068 "</li>")))
2069 lol-entries "\n"))
2070 "\n</ul>\n</div>\n</div>"))))
2073 ;;; Transcode Functions
2075 ;;;; Bold
2077 (defun org-html-bold (bold contents info)
2078 "Transcode BOLD from Org to HTML.
2079 CONTENTS is the text with bold markup. INFO is a plist holding
2080 contextual information."
2081 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
2082 contents))
2084 ;;;; Center Block
2086 (defun org-html-center-block (center-block contents info)
2087 "Transcode a CENTER-BLOCK element from Org to HTML.
2088 CONTENTS holds the contents of the block. INFO is a plist
2089 holding contextual information."
2090 (format "<div class=\"center\">\n%s</div>" contents))
2092 ;;;; Clock
2094 (defun org-html-clock (clock contents info)
2095 "Transcode a CLOCK element from Org to HTML.
2096 CONTENTS is nil. INFO is a plist used as a communication
2097 channel."
2098 (format "<p>
2099 <span class=\"timestamp-wrapper\">
2100 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2101 </span>
2102 </p>"
2103 org-clock-string
2104 (org-translate-time
2105 (org-element-property :raw-value
2106 (org-element-property :value clock)))
2107 (let ((time (org-element-property :duration clock)))
2108 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2110 ;;;; Code
2112 (defun org-html-code (code contents info)
2113 "Transcode CODE from Org to HTML.
2114 CONTENTS is nil. INFO is a plist holding contextual
2115 information."
2116 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2117 (org-html-encode-plain-text (org-element-property :value code))))
2119 ;;;; Drawer
2121 (defun org-html-drawer (drawer contents info)
2122 "Transcode a DRAWER element from Org to HTML.
2123 CONTENTS holds the contents of the block. INFO is a plist
2124 holding contextual information."
2125 (if (functionp org-html-format-drawer-function)
2126 (funcall org-html-format-drawer-function
2127 (org-element-property :drawer-name drawer)
2128 contents)
2129 ;; If there's no user defined function: simply
2130 ;; display contents of the drawer.
2131 contents))
2133 ;;;; Dynamic Block
2135 (defun org-html-dynamic-block (dynamic-block contents info)
2136 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2137 CONTENTS holds the contents of the block. INFO is a plist
2138 holding contextual information. See `org-export-data'."
2139 contents)
2141 ;;;; Entity
2143 (defun org-html-entity (entity contents info)
2144 "Transcode an ENTITY object from Org to HTML.
2145 CONTENTS are the definition itself. INFO is a plist holding
2146 contextual information."
2147 (org-element-property :html entity))
2149 ;;;; Example Block
2151 (defun org-html-example-block (example-block contents info)
2152 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2153 CONTENTS is nil. INFO is a plist holding contextual
2154 information."
2155 (if (org-export-read-attribute :attr_html example-block :textarea)
2156 (org-html--textarea-block example-block)
2157 (format "<pre class=\"example\">\n%s</pre>"
2158 (org-html-format-code example-block info))))
2160 ;;;; Export Snippet
2162 (defun org-html-export-snippet (export-snippet contents info)
2163 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2164 CONTENTS is nil. INFO is a plist holding contextual
2165 information."
2166 (when (eq (org-export-snippet-backend export-snippet) 'html)
2167 (org-element-property :value export-snippet)))
2169 ;;;; Export Block
2171 (defun org-html-export-block (export-block contents info)
2172 "Transcode a EXPORT-BLOCK element from Org to HTML.
2173 CONTENTS is nil. INFO is a plist holding contextual information."
2174 (when (string= (org-element-property :type export-block) "HTML")
2175 (org-remove-indentation (org-element-property :value export-block))))
2177 ;;;; Fixed Width
2179 (defun org-html-fixed-width (fixed-width contents info)
2180 "Transcode a FIXED-WIDTH element from Org to HTML.
2181 CONTENTS is nil. INFO is a plist holding contextual information."
2182 (format "<pre class=\"example\">\n%s</pre>"
2183 (org-html-do-format-code
2184 (org-remove-indentation
2185 (org-element-property :value fixed-width)))))
2187 ;;;; Footnote Reference
2189 (defun org-html-footnote-reference (footnote-reference contents info)
2190 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2191 CONTENTS is nil. INFO is a plist holding contextual information."
2192 (concat
2193 ;; Insert separator between two footnotes in a row.
2194 (let ((prev (org-export-get-previous-element footnote-reference info)))
2195 (when (eq (org-element-type prev) 'footnote-reference)
2196 org-html-footnote-separator))
2197 (cond
2198 ((not (org-export-footnote-first-reference-p footnote-reference info))
2199 (org-html-format-footnote-reference
2200 (org-export-get-footnote-number footnote-reference info)
2201 "IGNORED" 100))
2202 ;; Inline definitions are secondary strings.
2203 ((eq (org-element-property :type footnote-reference) 'inline)
2204 (org-html-format-footnote-reference
2205 (org-export-get-footnote-number footnote-reference info)
2206 "IGNORED" 1))
2207 ;; Non-inline footnotes definitions are full Org data.
2208 (t (org-html-format-footnote-reference
2209 (org-export-get-footnote-number footnote-reference info)
2210 "IGNORED" 1)))))
2212 ;;;; Headline
2214 (defun org-html-format-headline--wrap
2215 (headline info &optional format-function &rest extra-keys)
2216 "Transcode a HEADLINE element from Org to HTML.
2217 CONTENTS holds the contents of the headline. INFO is a plist
2218 holding contextual information."
2219 (let* ((level (+ (org-export-get-relative-level headline info)
2220 (1- org-html-toplevel-hlevel)))
2221 (headline-number (org-export-get-headline-number headline info))
2222 (section-number (and (not (org-export-low-level-p headline info))
2223 (org-export-numbered-headline-p headline info)
2224 (mapconcat 'number-to-string
2225 headline-number ".")))
2226 (todo (and (plist-get info :with-todo-keywords)
2227 (let ((todo (org-element-property :todo-keyword headline)))
2228 (and todo (org-export-data todo info)))))
2229 (todo-type (and todo (org-element-property :todo-type headline)))
2230 (priority (and (plist-get info :with-priority)
2231 (org-element-property :priority headline)))
2232 (text (org-export-data (org-element-property :title headline) info))
2233 (tags (and (plist-get info :with-tags)
2234 (org-export-get-tags headline info)))
2235 (headline-label (or (org-element-property :CUSTOM_ID headline)
2236 (concat "sec-" (mapconcat 'number-to-string
2237 headline-number "-"))))
2238 (format-function
2239 (cond ((functionp format-function) format-function)
2240 ((functionp org-html-format-headline-function)
2241 (lambda (todo todo-type priority text tags &rest ignore)
2242 (funcall org-html-format-headline-function
2243 todo todo-type priority text tags)))
2244 (t 'org-html-format-headline))))
2245 (apply format-function
2246 todo todo-type priority text tags
2247 :headline-label headline-label :level level
2248 :section-number section-number extra-keys)))
2250 (defun org-html-headline (headline contents info)
2251 "Transcode a HEADLINE element from Org to HTML.
2252 CONTENTS holds the contents of the headline. INFO is a plist
2253 holding contextual information."
2254 ;; Empty contents?
2255 (setq contents (or contents ""))
2256 (let* ((numberedp (org-export-numbered-headline-p headline info))
2257 (level (org-export-get-relative-level headline info))
2258 (text (org-export-data (org-element-property :title headline) info))
2259 (todo (and (plist-get info :with-todo-keywords)
2260 (let ((todo (org-element-property :todo-keyword headline)))
2261 (and todo (org-export-data todo info)))))
2262 (todo-type (and todo (org-element-property :todo-type headline)))
2263 (tags (and (plist-get info :with-tags)
2264 (org-export-get-tags headline info)))
2265 (priority (and (plist-get info :with-priority)
2266 (org-element-property :priority headline)))
2267 (section-number (and (org-export-numbered-headline-p headline info)
2268 (mapconcat 'number-to-string
2269 (org-export-get-headline-number
2270 headline info) ".")))
2271 ;; Create the headline text.
2272 (full-text (org-html-format-headline--wrap headline info)))
2273 (cond
2274 ;; Case 1: This is a footnote section: ignore it.
2275 ((org-element-property :footnote-section-p headline) nil)
2276 ;; Case 2. This is a deep sub-tree: export it as a list item.
2277 ;; Also export as items headlines for which no section
2278 ;; format has been found.
2279 ((org-export-low-level-p headline info)
2280 ;; Build the real contents of the sub-tree.
2281 (let* ((type (if numberedp 'ordered 'unordered))
2282 (itemized-body (org-html-format-list-item
2283 contents type nil info nil full-text)))
2284 (concat
2285 (and (org-export-first-sibling-p headline info)
2286 (org-html-begin-plain-list type))
2287 itemized-body
2288 (and (org-export-last-sibling-p headline info)
2289 (org-html-end-plain-list type)))))
2290 ;; Case 3. Standard headline. Export it as a section.
2292 (let* ((section-number (mapconcat 'number-to-string
2293 (org-export-get-headline-number
2294 headline info) "-"))
2295 (ids (remove 'nil
2296 (list (org-element-property :CUSTOM_ID headline)
2297 (concat "sec-" section-number)
2298 (org-element-property :ID headline))))
2299 (preferred-id (car ids))
2300 (extra-ids (cdr ids))
2301 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2302 (level1 (+ level (1- org-html-toplevel-hlevel)))
2303 (first-content (car (org-element-contents headline))))
2304 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2305 (org-html--container headline info)
2306 (format "outline-container-%s"
2307 (or (org-element-property :CUSTOM_ID headline)
2308 (concat "sec-" section-number)))
2309 (concat (format "outline-%d" level1) (and extra-class " ")
2310 extra-class)
2311 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2312 level1
2313 preferred-id
2314 (mapconcat
2315 (lambda (x)
2316 (let ((id (org-export-solidify-link-text
2317 (if (org-uuidgen-p x) (concat "ID-" x)
2318 x))))
2319 (org-html--anchor id)))
2320 extra-ids "")
2321 full-text
2322 level1)
2323 ;; When there is no section, pretend there is an empty
2324 ;; one to get the correct <div class="outline- ...>
2325 ;; which is needed by `org-info.js'.
2326 (if (not (eq (org-element-type first-content) 'section))
2327 (concat (org-html-section first-content "" info)
2328 contents)
2329 contents)
2330 (org-html--container headline info)))))))
2332 (defun org-html--container (headline info)
2333 (or (org-element-property :HTML_CONTAINER headline)
2334 (if (= 1 (org-export-get-relative-level headline info))
2335 (plist-get info :html-container)
2336 "div")))
2338 ;;;; Horizontal Rule
2340 (defun org-html-horizontal-rule (horizontal-rule contents info)
2341 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2342 CONTENTS is nil. INFO is a plist holding contextual information."
2343 (org-html-close-tag "hr" nil info))
2345 ;;;; Inline Src Block
2347 (defun org-html-inline-src-block (inline-src-block contents info)
2348 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2349 CONTENTS holds the contents of the item. INFO is a plist holding
2350 contextual information."
2351 (let* ((org-lang (org-element-property :language inline-src-block))
2352 (code (org-element-property :value inline-src-block)))
2353 (error "Cannot export inline src block")))
2355 ;;;; Inlinetask
2357 (defun org-html-format-section (text class &optional id)
2358 "Format a section with TEXT into a HTML div with CLASS and ID."
2359 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2360 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2362 (defun org-html-inlinetask (inlinetask contents info)
2363 "Transcode an INLINETASK element from Org to HTML.
2364 CONTENTS holds the contents of the block. INFO is a plist
2365 holding contextual information."
2366 (cond
2367 ;; If `org-html-format-inlinetask-function' is provided, call it
2368 ;; with appropriate arguments.
2369 ((functionp org-html-format-inlinetask-function)
2370 (let ((format-function
2371 (function*
2372 (lambda (todo todo-type priority text tags
2373 &key contents &allow-other-keys)
2374 (funcall org-html-format-inlinetask-function
2375 todo todo-type priority text tags contents)))))
2376 (org-html-format-headline--wrap
2377 inlinetask info format-function :contents contents)))
2378 ;; Otherwise, use a default template.
2379 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2380 (org-html-format-headline--wrap inlinetask info)
2381 (org-html-close-tag "br" nil info)
2382 contents))))
2384 ;;;; Italic
2386 (defun org-html-italic (italic contents info)
2387 "Transcode ITALIC from Org to HTML.
2388 CONTENTS is the text with italic markup. INFO is a plist holding
2389 contextual information."
2390 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2392 ;;;; Item
2394 (defun org-html-checkbox (checkbox)
2395 "Format CHECKBOX into HTML."
2396 (case checkbox (on "<code>[X]</code>")
2397 (off "<code>[&#xa0;]</code>")
2398 (trans "<code>[-]</code>")
2399 (t "")))
2401 (defun org-html-format-list-item (contents type checkbox info
2402 &optional term-counter-id
2403 headline)
2404 "Format a list item into HTML."
2405 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
2406 (br (org-html-close-tag "br" nil info)))
2407 (concat
2408 (case type
2409 (ordered
2410 (let* ((counter term-counter-id)
2411 (extra (if counter (format " value=\"%s\"" counter) "")))
2412 (concat
2413 (format "<li%s>" extra)
2414 (when headline (concat headline br)))))
2415 (unordered
2416 (let* ((id term-counter-id)
2417 (extra (if id (format " id=\"%s\"" id) "")))
2418 (concat
2419 (format "<li%s>" extra)
2420 (when headline (concat headline br)))))
2421 (descriptive
2422 (let* ((term term-counter-id))
2423 (setq term (or term "(no term)"))
2424 ;; Check-boxes in descriptive lists are associated to tag.
2425 (concat (format "<dt> %s </dt>"
2426 (concat checkbox term))
2427 "<dd>"))))
2428 (unless (eq type 'descriptive) checkbox)
2429 contents
2430 (case type
2431 (ordered "</li>")
2432 (unordered "</li>")
2433 (descriptive "</dd>")))))
2435 (defun org-html-item (item contents info)
2436 "Transcode an ITEM element from Org to HTML.
2437 CONTENTS holds the contents of the item. INFO is a plist holding
2438 contextual information."
2439 (let* ((plain-list (org-export-get-parent item))
2440 (type (org-element-property :type plain-list))
2441 (counter (org-element-property :counter item))
2442 (checkbox (org-element-property :checkbox item))
2443 (tag (let ((tag (org-element-property :tag item)))
2444 (and tag (org-export-data tag info)))))
2445 (org-html-format-list-item
2446 contents type checkbox info (or tag counter))))
2448 ;;;; Keyword
2450 (defun org-html-keyword (keyword contents info)
2451 "Transcode a KEYWORD element from Org to HTML.
2452 CONTENTS is nil. INFO is a plist holding contextual information."
2453 (let ((key (org-element-property :key keyword))
2454 (value (org-element-property :value keyword)))
2455 (cond
2456 ((string= key "HTML") value)
2457 ((string= key "TOC")
2458 (let ((value (downcase value)))
2459 (cond
2460 ((string-match "\\<headlines\\>" value)
2461 (let ((depth (or (and (string-match "[0-9]+" value)
2462 (string-to-number (match-string 0 value)))
2463 (plist-get info :with-toc))))
2464 (org-html-toc depth info)))
2465 ((string= "listings" value) (org-html-list-of-listings info))
2466 ((string= "tables" value) (org-html-list-of-tables info))))))))
2468 ;;;; Latex Environment
2470 (defun org-html-format-latex (latex-frag processing-type)
2471 "Format a LaTeX fragment LATEX-FRAG into HTML."
2472 (let ((cache-relpath "") (cache-dir ""))
2473 (unless (eq processing-type 'mathjax)
2474 (let ((bfn (or (buffer-file-name)
2475 (make-temp-name
2476 (expand-file-name "latex" temporary-file-directory)))))
2477 (setq cache-relpath
2478 (concat "ltxpng/"
2479 (file-name-sans-extension
2480 (file-name-nondirectory bfn)))
2481 cache-dir (file-name-directory bfn))))
2482 (with-temp-buffer
2483 (insert latex-frag)
2484 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2485 nil nil processing-type)
2486 (buffer-string))))
2488 (defun org-html-latex-environment (latex-environment contents info)
2489 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2490 CONTENTS is nil. INFO is a plist holding contextual information."
2491 (let ((processing-type (plist-get info :with-latex))
2492 (latex-frag (org-remove-indentation
2493 (org-element-property :value latex-environment)))
2494 (attributes (org-export-read-attribute :attr_html latex-environment)))
2495 (case processing-type
2496 ((t mathjax)
2497 (org-html-format-latex latex-frag 'mathjax))
2498 ((dvipng imagemagick)
2499 (let ((formula-link (org-html-format-latex latex-frag processing-type)))
2500 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2501 ;; Do not provide a caption or a name to be consistent with
2502 ;; `mathjax' handling.
2503 (org-html--wrap-image
2504 (org-html--format-image
2505 (match-string 1 formula-link) attributes info) info))))
2506 (t latex-frag))))
2508 ;;;; Latex Fragment
2510 (defun org-html-latex-fragment (latex-fragment contents info)
2511 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2512 CONTENTS is nil. INFO is a plist holding contextual information."
2513 (let ((latex-frag (org-element-property :value latex-fragment))
2514 (processing-type (plist-get info :with-latex)))
2515 (case processing-type
2516 ((t mathjax)
2517 (org-html-format-latex latex-frag 'mathjax))
2518 ((dvipng imagemagick)
2519 (let ((formula-link (org-html-format-latex latex-frag processing-type)))
2520 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2521 (org-html--format-image (match-string 1 formula-link) nil info))))
2522 (t latex-frag))))
2524 ;;;; Line Break
2526 (defun org-html-line-break (line-break contents info)
2527 "Transcode a LINE-BREAK object from Org to HTML.
2528 CONTENTS is nil. INFO is a plist holding contextual information."
2529 (concat (org-html-close-tag "br" nil info) "\n"))
2531 ;;;; Link
2533 (defun org-html-inline-image-p (link info)
2534 "Non-nil when LINK is meant to appear as an image.
2535 INFO is a plist used as a communication channel. LINK is an
2536 inline image when it has no description and targets an image
2537 file (see `org-html-inline-image-rules' for more information), or
2538 if its description is a single link targeting an image file."
2539 (if (not (org-element-contents link))
2540 (org-export-inline-image-p link org-html-inline-image-rules)
2541 (not
2542 (let ((link-count 0))
2543 (org-element-map (org-element-contents link)
2544 (cons 'plain-text org-element-all-objects)
2545 (lambda (obj)
2546 (case (org-element-type obj)
2547 (plain-text (org-string-nw-p obj))
2548 (link (if (= link-count 1) t
2549 (incf link-count)
2550 (not (org-export-inline-image-p
2551 obj org-html-inline-image-rules))))
2552 (otherwise t)))
2553 info t)))))
2555 (defvar org-html-standalone-image-predicate)
2556 (defun org-html-standalone-image-p (element info)
2557 "Test if ELEMENT is a standalone image.
2559 INFO is a plist holding contextual information.
2561 Return non-nil, if ELEMENT is of type paragraph and its sole
2562 content, save for white spaces, is a link that qualifies as an
2563 inline image.
2565 Return non-nil, if ELEMENT is of type link and its containing
2566 paragraph has no other content save white spaces.
2568 Return nil, otherwise.
2570 Bind `org-html-standalone-image-predicate' to constrain paragraph
2571 further. For example, to check for only captioned standalone
2572 images, set it to:
2574 \(lambda (paragraph) (org-element-property :caption paragraph))"
2575 (let ((paragraph (case (org-element-type element)
2576 (paragraph element)
2577 (link (org-export-get-parent element)))))
2578 (and (eq (org-element-type paragraph) 'paragraph)
2579 (or (not (and (boundp 'org-html-standalone-image-predicate)
2580 (functionp org-html-standalone-image-predicate)))
2581 (funcall org-html-standalone-image-predicate paragraph))
2582 (not (let ((link-count 0))
2583 (org-element-map (org-element-contents paragraph)
2584 (cons 'plain-text org-element-all-objects)
2585 (lambda (obj) (case (org-element-type obj)
2586 (plain-text (org-string-nw-p obj))
2587 (link
2588 (or (> (incf link-count) 1)
2589 (not (org-html-inline-image-p obj info))))
2590 (otherwise t)))
2591 info 'first-match 'link))))))
2593 (defun org-html-link (link desc info)
2594 "Transcode a LINK object from Org to HTML.
2596 DESC is the description part of the link, or the empty string.
2597 INFO is a plist holding contextual information. See
2598 `org-export-data'."
2599 (let* ((home (when (plist-get info :html-link-home)
2600 (org-trim (plist-get info :html-link-home))))
2601 (use-abs-url (plist-get info :html-link-use-abs-url))
2602 (link-org-files-as-html-maybe
2603 (function
2604 (lambda (raw-path info)
2605 "Treat links to `file.org' as links to `file.html', if needed.
2606 See `org-html-link-org-files-as-html'."
2607 (cond
2608 ((and org-html-link-org-files-as-html
2609 (string= ".org"
2610 (downcase (file-name-extension raw-path "."))))
2611 (concat (file-name-sans-extension raw-path) "."
2612 (plist-get info :html-extension)))
2613 (t raw-path)))))
2614 (type (org-element-property :type link))
2615 (raw-path (org-element-property :path link))
2616 ;; Ensure DESC really exists, or set it to nil.
2617 (desc (org-string-nw-p desc))
2618 (path
2619 (cond
2620 ((member type '("http" "https" "ftp" "mailto"))
2621 (org-link-escape
2622 (org-link-unescape
2623 (concat type ":" raw-path)) org-link-escape-chars-browser))
2624 ((string= type "file")
2625 ;; Treat links to ".org" files as ".html", if needed.
2626 (setq raw-path
2627 (funcall link-org-files-as-html-maybe raw-path info))
2628 ;; If file path is absolute, prepend it with protocol
2629 ;; component - "file://".
2630 (cond ((file-name-absolute-p raw-path)
2631 (setq raw-path
2632 (concat "file://" (expand-file-name
2633 raw-path))))
2634 ((and home use-abs-url)
2635 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2636 ;; Add search option, if any. A search option can be
2637 ;; relative to a custom-id or a headline title. Any other
2638 ;; option is ignored.
2639 (let ((option (org-element-property :search-option link)))
2640 (cond ((not option) raw-path)
2641 ((eq (aref option 0) ?#) (concat raw-path option))
2642 ;; External fuzzy link: try to resolve it if path
2643 ;; belongs to current project, if any.
2644 ((eq (aref option 0) ?*)
2645 (concat
2646 raw-path
2647 (let ((numbers
2648 (org-publish-resolve-external-fuzzy-link
2649 (org-element-property :path link) option)))
2650 (and numbers (concat "#sec-"
2651 (mapconcat 'number-to-string
2652 numbers "-"))))))
2653 (t raw-path))))
2654 (t raw-path)))
2655 ;; Extract attributes from parent's paragraph. HACK: Only do
2656 ;; this for the first link in parent (inner image link for
2657 ;; inline images). This is needed as long as attributes
2658 ;; cannot be set on a per link basis.
2659 (attributes-plist
2660 (let* ((parent (org-export-get-parent-element link))
2661 (link (let ((container (org-export-get-parent link)))
2662 (if (and (eq (org-element-type container) 'link)
2663 (org-html-inline-image-p link info))
2664 container
2665 link))))
2666 (and (eq (org-element-map parent 'link 'identity info t) link)
2667 (org-export-read-attribute :attr_html parent))))
2668 (attributes
2669 (let ((attr (org-html--make-attribute-string attributes-plist)))
2670 (if (org-string-nw-p attr) (concat " " attr) "")))
2671 protocol)
2672 (cond
2673 ;; Image file.
2674 ((and org-html-inline-images
2675 (org-export-inline-image-p link org-html-inline-image-rules))
2676 (org-html--format-image path attributes-plist info))
2677 ;; Radio target: Transcode target's contents and use them as
2678 ;; link's description.
2679 ((string= type "radio")
2680 (let ((destination (org-export-resolve-radio-link link info)))
2681 (when destination
2682 (format "<a href=\"#%s\"%s>%s</a>"
2683 (org-export-solidify-link-text path)
2684 attributes
2685 (org-export-data (org-element-contents destination) info)))))
2686 ;; Links pointing to a headline: Find destination and build
2687 ;; appropriate referencing command.
2688 ((member type '("custom-id" "fuzzy" "id"))
2689 (let ((destination (if (string= type "fuzzy")
2690 (org-export-resolve-fuzzy-link link info)
2691 (org-export-resolve-id-link link info))))
2692 (case (org-element-type destination)
2693 ;; ID link points to an external file.
2694 (plain-text
2695 (let ((fragment (concat "ID-" path))
2696 ;; Treat links to ".org" files as ".html", if needed.
2697 (path (funcall link-org-files-as-html-maybe
2698 destination info)))
2699 (format "<a href=\"%s#%s\"%s>%s</a>"
2700 path fragment attributes (or desc destination))))
2701 ;; Fuzzy link points nowhere.
2702 ((nil)
2703 (format "<i>%s</i>"
2704 (or desc
2705 (org-export-data
2706 (org-element-property :raw-link link) info))))
2707 ;; Link points to a headline.
2708 (headline
2709 (let ((href
2710 ;; What href to use?
2711 (cond
2712 ;; Case 1: Headline is linked via it's CUSTOM_ID
2713 ;; property. Use CUSTOM_ID.
2714 ((string= type "custom-id")
2715 (org-element-property :CUSTOM_ID destination))
2716 ;; Case 2: Headline is linked via it's ID property
2717 ;; or through other means. Use the default href.
2718 ((member type '("id" "fuzzy"))
2719 (format "sec-%s"
2720 (mapconcat 'number-to-string
2721 (org-export-get-headline-number
2722 destination info) "-")))
2723 (t (error "Shouldn't reach here"))))
2724 ;; What description to use?
2725 (desc
2726 ;; Case 1: Headline is numbered and LINK has no
2727 ;; description. Display section number.
2728 (if (and (org-export-numbered-headline-p destination info)
2729 (not desc))
2730 (mapconcat 'number-to-string
2731 (org-export-get-headline-number
2732 destination info) ".")
2733 ;; Case 2: Either the headline is un-numbered or
2734 ;; LINK has a custom description. Display LINK's
2735 ;; description or headline's title.
2736 (or desc (org-export-data (org-element-property
2737 :title destination) info)))))
2738 (format "<a href=\"#%s\"%s>%s</a>"
2739 (org-export-solidify-link-text href) attributes desc)))
2740 ;; Fuzzy link points to a target or an element.
2742 (let* ((path (org-export-solidify-link-text path))
2743 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2744 (number (cond
2745 (desc nil)
2746 ((org-html-standalone-image-p destination info)
2747 (org-export-get-ordinal
2748 (org-element-map destination 'link
2749 'identity info t)
2750 info 'link 'org-html-standalone-image-p))
2751 (t (org-export-get-ordinal
2752 destination info nil 'org-html--has-caption-p))))
2753 (desc (cond (desc)
2754 ((not number) "No description for this link")
2755 ((numberp number) (number-to-string number))
2756 (t (mapconcat 'number-to-string number ".")))))
2757 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2758 ;; Coderef: replace link with the reference name or the
2759 ;; equivalent line number.
2760 ((string= type "coderef")
2761 (let ((fragment (concat "coderef-" path)))
2762 (format "<a href=\"#%s\"%s%s>%s</a>"
2763 fragment
2764 (org-trim
2765 (format (concat "class=\"coderef\""
2766 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2767 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2768 fragment fragment))
2769 attributes
2770 (format (org-export-get-coderef-format path desc)
2771 (org-export-resolve-coderef path info)))))
2772 ;; Link type is handled by a special function.
2773 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2774 (funcall protocol (org-link-unescape path) desc 'html))
2775 ;; External link with a description part.
2776 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2777 ;; External link without a description part.
2778 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2779 ;; No path, only description. Try to do something useful.
2780 (t (format "<i>%s</i>" desc)))))
2782 ;;;; Node Property
2784 (defun org-html-node-property (node-property contents info)
2785 "Transcode a NODE-PROPERTY element from Org to HTML.
2786 CONTENTS is nil. INFO is a plist holding contextual
2787 information."
2788 (format "%s:%s"
2789 (org-element-property :key node-property)
2790 (let ((value (org-element-property :value node-property)))
2791 (if value (concat " " value) ""))))
2793 ;;;; Paragraph
2795 (defun org-html-paragraph (paragraph contents info)
2796 "Transcode a PARAGRAPH element from Org to HTML.
2797 CONTENTS is the contents of the paragraph, as a string. INFO is
2798 the plist used as a communication channel."
2799 (let* ((parent (org-export-get-parent paragraph))
2800 (parent-type (org-element-type parent))
2801 (style '((footnote-definition " class=\"footpara\"")))
2802 (extra (or (cadr (assoc parent-type style)) "")))
2803 (cond
2804 ((and (eq (org-element-type parent) 'item)
2805 (= (org-element-property :begin paragraph)
2806 (org-element-property :contents-begin parent)))
2807 ;; Leading paragraph in a list item have no tags.
2808 contents)
2809 ((org-html-standalone-image-p paragraph info)
2810 ;; Standalone image.
2811 (let ((caption
2812 (let ((raw (org-export-data
2813 (org-export-get-caption paragraph) info))
2814 (org-html-standalone-image-predicate
2815 'org-html--has-caption-p))
2816 (if (not (org-string-nw-p raw)) raw
2817 (concat
2818 "<span class=\"figure-number\">"
2819 (format (org-html--translate "Figure %d:" info)
2820 (org-export-get-ordinal
2821 (org-element-map paragraph 'link
2822 'identity info t)
2823 info nil 'org-html-standalone-image-p))
2824 "</span> " raw))))
2825 (label (org-element-property :name paragraph)))
2826 (org-html--wrap-image contents info caption label)))
2827 ;; Regular paragraph.
2828 (t (format "<p%s>\n%s</p>" extra contents)))))
2830 ;;;; Plain List
2832 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2833 ;; the correct value for the item counter
2834 (defun org-html-begin-plain-list (type &optional arg1)
2835 "Insert the beginning of the HTML list depending on TYPE.
2836 When ARG1 is a string, use it as the start parameter for ordered
2837 lists."
2838 (case type
2839 (ordered
2840 (format "<ol class=\"org-ol\"%s>"
2841 (if arg1 (format " start=\"%d\"" arg1) "")))
2842 (unordered "<ul class=\"org-ul\">")
2843 (descriptive "<dl class=\"org-dl\">")))
2845 (defun org-html-end-plain-list (type)
2846 "Insert the end of the HTML list depending on TYPE."
2847 (case type
2848 (ordered "</ol>")
2849 (unordered "</ul>")
2850 (descriptive "</dl>")))
2852 (defun org-html-plain-list (plain-list contents info)
2853 "Transcode a PLAIN-LIST element from Org to HTML.
2854 CONTENTS is the contents of the list. INFO is a plist holding
2855 contextual information."
2856 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2857 (type (org-element-property :type plain-list)))
2858 (format "%s\n%s%s"
2859 (org-html-begin-plain-list type)
2860 contents (org-html-end-plain-list type))))
2862 ;;;; Plain Text
2864 (defun org-html-convert-special-strings (string)
2865 "Convert special characters in STRING to HTML."
2866 (let ((all org-html-special-string-regexps)
2867 e a re rpl start)
2868 (while (setq a (pop all))
2869 (setq re (car a) rpl (cdr a) start 0)
2870 (while (string-match re string start)
2871 (setq string (replace-match rpl t nil string))))
2872 string))
2874 (defun org-html-encode-plain-text (text)
2875 "Convert plain text characters from TEXT to HTML equivalent.
2876 Possible conversions are set in `org-html-protect-char-alist'."
2877 (mapc
2878 (lambda (pair)
2879 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2880 org-html-protect-char-alist)
2881 text)
2883 (defun org-html-plain-text (text info)
2884 "Transcode a TEXT string from Org to HTML.
2885 TEXT is the string to transcode. INFO is a plist holding
2886 contextual information."
2887 (let ((output text))
2888 ;; Protect following characters: <, >, &.
2889 (setq output (org-html-encode-plain-text output))
2890 ;; Handle smart quotes. Be sure to provide original string since
2891 ;; OUTPUT may have been modified.
2892 (when (plist-get info :with-smart-quotes)
2893 (setq output (org-export-activate-smart-quotes output :html info text)))
2894 ;; Handle special strings.
2895 (when (plist-get info :with-special-strings)
2896 (setq output (org-html-convert-special-strings output)))
2897 ;; Handle break preservation if required.
2898 (when (plist-get info :preserve-breaks)
2899 (setq output
2900 (replace-regexp-in-string
2901 "\\(\\\\\\\\\\)?[ \t]*\n"
2902 (concat (org-html-close-tag "br" nil info) "\n") output)))
2903 ;; Return value.
2904 output))
2907 ;; Planning
2909 (defun org-html-planning (planning contents info)
2910 "Transcode a PLANNING element from Org to HTML.
2911 CONTENTS is nil. INFO is a plist used as a communication
2912 channel."
2913 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2914 (format
2915 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2916 (mapconcat
2917 'identity
2918 (delq nil
2919 (list
2920 (let ((closed (org-element-property :closed planning)))
2921 (when closed
2922 (format span-fmt org-closed-string
2923 (org-translate-time
2924 (org-element-property :raw-value closed)))))
2925 (let ((deadline (org-element-property :deadline planning)))
2926 (when deadline
2927 (format span-fmt org-deadline-string
2928 (org-translate-time
2929 (org-element-property :raw-value deadline)))))
2930 (let ((scheduled (org-element-property :scheduled planning)))
2931 (when scheduled
2932 (format span-fmt org-scheduled-string
2933 (org-translate-time
2934 (org-element-property :raw-value scheduled)))))))
2935 " "))))
2937 ;;;; Property Drawer
2939 (defun org-html-property-drawer (property-drawer contents info)
2940 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2941 CONTENTS holds the contents of the drawer. INFO is a plist
2942 holding contextual information."
2943 (and (org-string-nw-p contents)
2944 (format "<pre class=\"example\">\n%s</pre>" contents)))
2946 ;;;; Quote Block
2948 (defun org-html-quote-block (quote-block contents info)
2949 "Transcode a QUOTE-BLOCK element from Org to HTML.
2950 CONTENTS holds the contents of the block. INFO is a plist
2951 holding contextual information."
2952 (format "<blockquote>\n%s</blockquote>" contents))
2954 ;;;; Quote Section
2956 (defun org-html-quote-section (quote-section contents info)
2957 "Transcode a QUOTE-SECTION element from Org to HTML.
2958 CONTENTS is nil. INFO is a plist holding contextual information."
2959 (let ((value (org-remove-indentation
2960 (org-element-property :value quote-section))))
2961 (when value (format "<pre>\n%s</pre>" value))))
2963 ;;;; Section
2965 (defun org-html-section (section contents info)
2966 "Transcode a SECTION element from Org to HTML.
2967 CONTENTS holds the contents of the section. INFO is a plist
2968 holding contextual information."
2969 (let ((parent (org-export-get-parent-headline section)))
2970 ;; Before first headline: no container, just return CONTENTS.
2971 (if (not parent) contents
2972 ;; Get div's class and id references.
2973 (let* ((class-num (+ (org-export-get-relative-level parent info)
2974 (1- org-html-toplevel-hlevel)))
2975 (section-number
2976 (mapconcat
2977 'number-to-string
2978 (org-export-get-headline-number parent info) "-")))
2979 ;; Build return value.
2980 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2981 class-num
2982 (or (org-element-property :CUSTOM_ID parent) section-number)
2983 contents)))))
2985 ;;;; Radio Target
2987 (defun org-html-radio-target (radio-target text info)
2988 "Transcode a RADIO-TARGET object from Org to HTML.
2989 TEXT is the text of the target. INFO is a plist holding
2990 contextual information."
2991 (let ((id (org-export-solidify-link-text
2992 (org-element-property :value radio-target))))
2993 (org-html--anchor id text)))
2995 ;;;; Special Block
2997 (defun org-html-special-block (special-block contents info)
2998 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2999 CONTENTS holds the contents of the block. INFO is a plist
3000 holding contextual information."
3001 (let* ((block-type (downcase
3002 (org-element-property :type special-block)))
3003 (contents (or contents ""))
3004 (html5-fancy (and (org-html-html5-p info)
3005 (plist-get info :html-html5-fancy)
3006 (member block-type org-html-html5-elements)))
3007 (attributes (org-export-read-attribute :attr_html special-block)))
3008 (unless html5-fancy
3009 (let ((class (plist-get attributes :class)))
3010 (setq attributes (plist-put attributes :class
3011 (if class (concat class " " block-type)
3012 block-type)))))
3013 (setq attributes (org-html--make-attribute-string attributes))
3014 (when (not (equal attributes ""))
3015 (setq attributes (concat " " attributes)))
3016 (if html5-fancy
3017 (format "<%s%s>\n%s</%s>" block-type attributes
3018 contents block-type)
3019 (format "<div%s>\n%s\n</div>" attributes contents))))
3021 ;;;; Src Block
3023 (defun org-html-src-block (src-block contents info)
3024 "Transcode a SRC-BLOCK element from Org to HTML.
3025 CONTENTS holds the contents of the item. INFO is a plist holding
3026 contextual information."
3027 (if (org-export-read-attribute :attr_html src-block :textarea)
3028 (org-html--textarea-block src-block)
3029 (let ((lang (org-element-property :language src-block))
3030 (caption (org-export-get-caption src-block))
3031 (code (org-html-format-code src-block info))
3032 (label (let ((lbl (org-element-property :name src-block)))
3033 (if (not lbl) ""
3034 (format " id=\"%s\""
3035 (org-export-solidify-link-text lbl))))))
3036 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3037 (format
3038 "<div class=\"org-src-container\">\n%s%s\n</div>"
3039 (if (not caption) ""
3040 (format "<label class=\"org-src-name\">%s</label>"
3041 (org-export-data caption info)))
3042 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3044 ;;;; Statistics Cookie
3046 (defun org-html-statistics-cookie (statistics-cookie contents info)
3047 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3048 CONTENTS is nil. INFO is a plist holding contextual information."
3049 (let ((cookie-value (org-element-property :value statistics-cookie)))
3050 (format "<code>%s</code>" cookie-value)))
3052 ;;;; Strike-Through
3054 (defun org-html-strike-through (strike-through contents info)
3055 "Transcode STRIKE-THROUGH from Org to HTML.
3056 CONTENTS is the text with strike-through markup. INFO is a plist
3057 holding contextual information."
3058 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3059 contents))
3061 ;;;; Subscript
3063 (defun org-html-subscript (subscript contents info)
3064 "Transcode a SUBSCRIPT object from Org to HTML.
3065 CONTENTS is the contents of the object. INFO is a plist holding
3066 contextual information."
3067 (format "<sub>%s</sub>" contents))
3069 ;;;; Superscript
3071 (defun org-html-superscript (superscript contents info)
3072 "Transcode a SUPERSCRIPT object from Org to HTML.
3073 CONTENTS is the contents of the object. INFO is a plist holding
3074 contextual information."
3075 (format "<sup>%s</sup>" contents))
3077 ;;;; Tabel Cell
3079 (defun org-html-table-cell (table-cell contents info)
3080 "Transcode a TABLE-CELL element from Org to HTML.
3081 CONTENTS is nil. INFO is a plist used as a communication
3082 channel."
3083 (let* ((table-row (org-export-get-parent table-cell))
3084 (table (org-export-get-parent-table table-cell))
3085 (cell-attrs
3086 (if (not org-html-table-align-individual-fields) ""
3087 (format (if (and (boundp 'org-html-format-table-no-css)
3088 org-html-format-table-no-css)
3089 " align=\"%s\"" " class=\"%s\"")
3090 (org-export-table-cell-alignment table-cell info)))))
3091 (when (or (not contents) (string= "" (org-trim contents)))
3092 (setq contents "&#xa0;"))
3093 (cond
3094 ((and (org-export-table-has-header-p table info)
3095 (= 1 (org-export-table-row-group table-row info)))
3096 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3097 contents (cdr org-html-table-header-tags)))
3098 ((and org-html-table-use-header-tags-for-first-column
3099 (zerop (cdr (org-export-table-cell-address table-cell info))))
3100 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3101 contents (cdr org-html-table-header-tags)))
3102 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3103 contents (cdr org-html-table-data-tags))))))
3105 ;;;; Table Row
3107 (defun org-html-table-row (table-row contents info)
3108 "Transcode a TABLE-ROW element from Org to HTML.
3109 CONTENTS is the contents of the row. INFO is a plist used as a
3110 communication channel."
3111 ;; Rules are ignored since table separators are deduced from
3112 ;; borders of the current row.
3113 (when (eq (org-element-property :type table-row) 'standard)
3114 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3115 (row-number (org-export-table-row-number table-row info))
3116 (start-rowgroup-p
3117 (org-export-table-row-starts-rowgroup-p table-row info))
3118 (end-rowgroup-p
3119 (org-export-table-row-ends-rowgroup-p table-row info))
3120 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3121 ;; but should be set so that `org-html-table-row-tags' can
3122 ;; use them (see the docstring of this variable.)
3123 (top-row-p (and (equal start-rowgroup-p '(top))
3124 (equal end-rowgroup-p '(below top))))
3125 (bottom-row-p (and (equal start-rowgroup-p '(above))
3126 (equal end-rowgroup-p '(bottom above))))
3127 (rowgroup-tags
3128 (cond
3129 ;; Case 1: Row belongs to second or subsequent rowgroups.
3130 ((not (= 1 rowgroup-number))
3131 '("<tbody>" . "\n</tbody>"))
3132 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3133 ((org-export-table-has-header-p
3134 (org-export-get-parent-table table-row) info)
3135 '("<thead>" . "\n</thead>"))
3136 ;; Case 2: Row is from first and only row group.
3137 (t '("<tbody>" . "\n</tbody>")))))
3138 (concat
3139 ;; Begin a rowgroup?
3140 (when start-rowgroup-p (car rowgroup-tags))
3141 ;; Actual table row
3142 (concat "\n" (eval (car org-html-table-row-tags))
3143 contents
3144 "\n"
3145 (eval (cdr org-html-table-row-tags)))
3146 ;; End a rowgroup?
3147 (when end-rowgroup-p (cdr rowgroup-tags))))))
3149 ;;;; Table
3151 (defun org-html-table-first-row-data-cells (table info)
3152 "Transcode the first row of TABLE.
3153 INFO is a plist used as a communication channel."
3154 (let ((table-row
3155 (org-element-map table 'table-row
3156 (lambda (row)
3157 (unless (eq (org-element-property :type row) 'rule) row))
3158 info 'first-match))
3159 (special-column-p (org-export-table-has-special-column-p table)))
3160 (if (not special-column-p) (org-element-contents table-row)
3161 (cdr (org-element-contents table-row)))))
3163 (defun org-html-table--table.el-table (table info)
3164 "Format table.el tables into HTML.
3165 INFO is a plist used as a communication channel."
3166 (when (eq (org-element-property :type table) 'table.el)
3167 (require 'table)
3168 (let ((outbuf (with-current-buffer
3169 (get-buffer-create "*org-export-table*")
3170 (erase-buffer) (current-buffer))))
3171 (with-temp-buffer
3172 (insert (org-element-property :value table))
3173 (goto-char 1)
3174 (re-search-forward "^[ \t]*|[^|]" nil t)
3175 (table-generate-source 'html outbuf))
3176 (with-current-buffer outbuf
3177 (prog1 (org-trim (buffer-string))
3178 (kill-buffer) )))))
3180 (defun org-html-table (table contents info)
3181 "Transcode a TABLE element from Org to HTML.
3182 CONTENTS is the contents of the table. INFO is a plist holding
3183 contextual information."
3184 (case (org-element-property :type table)
3185 ;; Case 1: table.el table. Convert it using appropriate tools.
3186 (table.el (org-html-table--table.el-table table info))
3187 ;; Case 2: Standard table.
3189 (let* ((label (org-element-property :name table))
3190 (caption (org-export-get-caption table))
3191 (number (org-export-get-ordinal
3192 table info nil 'org-html--has-caption-p))
3193 (attributes
3194 (org-html--make-attribute-string
3195 (org-combine-plists
3196 (and label (list :id (org-export-solidify-link-text label)))
3197 (and (not (org-html-html5-p info))
3198 (plist-get info :html-table-attributes))
3199 (org-export-read-attribute :attr_html table))))
3200 (alignspec
3201 (if (and (boundp 'org-html-format-table-no-css)
3202 org-html-format-table-no-css)
3203 "align=\"%s\"" "class=\"%s\""))
3204 (table-column-specs
3205 (function
3206 (lambda (table info)
3207 (mapconcat
3208 (lambda (table-cell)
3209 (let ((alignment (org-export-table-cell-alignment
3210 table-cell info)))
3211 (concat
3212 ;; Begin a colgroup?
3213 (when (org-export-table-cell-starts-colgroup-p
3214 table-cell info)
3215 "\n<colgroup>")
3216 ;; Add a column. Also specify it's alignment.
3217 (format "\n%s"
3218 (org-html-close-tag
3219 "col" (concat " " (format alignspec alignment)) info))
3220 ;; End a colgroup?
3221 (when (org-export-table-cell-ends-colgroup-p
3222 table-cell info)
3223 "\n</colgroup>"))))
3224 (org-html-table-first-row-data-cells table info) "\n")))))
3225 (format "<table%s>\n%s\n%s\n%s</table>"
3226 (if (equal attributes "") "" (concat " " attributes))
3227 (if (not caption) ""
3228 (format (if org-html-table-caption-above
3229 "<caption align=\"above\">%s</caption>"
3230 "<caption align=\"bottom\">%s</caption>")
3231 (concat
3232 "<span class=\"table-number\">"
3233 (format (org-html--translate "Table %d:" info) number)
3234 "</span> " (org-export-data caption info))))
3235 (funcall table-column-specs table info)
3236 contents)))))
3238 ;;;; Target
3240 (defun org-html-target (target contents info)
3241 "Transcode a TARGET object from Org to HTML.
3242 CONTENTS is nil. INFO is a plist holding contextual
3243 information."
3244 (let ((id (org-export-solidify-link-text
3245 (org-element-property :value target))))
3246 (org-html--anchor id)))
3248 ;;;; Timestamp
3250 (defun org-html-timestamp (timestamp contents info)
3251 "Transcode a TIMESTAMP object from Org to HTML.
3252 CONTENTS is nil. INFO is a plist holding contextual
3253 information."
3254 (let ((value (org-html-plain-text
3255 (org-timestamp-translate timestamp) info)))
3256 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3257 (replace-regexp-in-string "--" "&#x2013;" value))))
3259 ;;;; Underline
3261 (defun org-html-underline (underline contents info)
3262 "Transcode UNDERLINE from Org to HTML.
3263 CONTENTS is the text with underline markup. INFO is a plist
3264 holding contextual information."
3265 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3266 contents))
3268 ;;;; Verbatim
3270 (defun org-html-verbatim (verbatim contents info)
3271 "Transcode VERBATIM from Org to HTML.
3272 CONTENTS is nil. INFO is a plist holding contextual
3273 information."
3274 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3275 (org-html-encode-plain-text (org-element-property :value verbatim))))
3277 ;;;; Verse Block
3279 (defun org-html-verse-block (verse-block contents info)
3280 "Transcode a VERSE-BLOCK element from Org to HTML.
3281 CONTENTS is verse block contents. INFO is a plist holding
3282 contextual information."
3283 ;; Replace each newline character with line break. Also replace
3284 ;; each blank line with a line break.
3285 (setq contents (replace-regexp-in-string
3286 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3287 (replace-regexp-in-string
3288 "\\(\\\\\\\\\\)?[ \t]*\n"
3289 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3290 ;; Replace each white space at beginning of a line with a
3291 ;; non-breaking space.
3292 (while (string-match "^[ \t]+" contents)
3293 (let* ((num-ws (length (match-string 0 contents)))
3294 (ws (let (out) (dotimes (i num-ws out)
3295 (setq out (concat out "&#xa0;"))))))
3296 (setq contents (replace-match ws nil t contents))))
3297 (format "<p class=\"verse\">\n%s</p>" contents))
3300 ;;; Filter Functions
3302 (defun org-html-final-function (contents backend info)
3303 "Filter to indent the HTML and convert HTML entities."
3304 (with-temp-buffer
3305 (insert contents)
3306 (set-auto-mode t)
3307 (if org-html-indent
3308 (indent-region (point-min) (point-max)))
3309 (when org-html-use-unicode-chars
3310 (require 'mm-url)
3311 (mm-url-decode-entities))
3312 (buffer-substring-no-properties (point-min) (point-max))))
3315 ;;; End-user functions
3317 ;;;###autoload
3318 (defun org-html-export-as-html
3319 (&optional async subtreep visible-only body-only ext-plist)
3320 "Export current buffer to an HTML buffer.
3322 If narrowing is active in the current buffer, only export its
3323 narrowed part.
3325 If a region is active, export that region.
3327 A non-nil optional argument ASYNC means the process should happen
3328 asynchronously. The resulting buffer should be accessible
3329 through the `org-export-stack' interface.
3331 When optional argument SUBTREEP is non-nil, export the sub-tree
3332 at point, extracting information from the headline properties
3333 first.
3335 When optional argument VISIBLE-ONLY is non-nil, don't export
3336 contents of hidden elements.
3338 When optional argument BODY-ONLY is non-nil, only write code
3339 between \"<body>\" and \"</body>\" tags.
3341 EXT-PLIST, when provided, is a property list with external
3342 parameters overriding Org default settings, but still inferior to
3343 file-local settings.
3345 Export is done in a buffer named \"*Org HTML Export*\", which
3346 will be displayed when `org-export-show-temporary-export-buffer'
3347 is non-nil."
3348 (interactive)
3349 (org-export-to-buffer 'html "*Org HTML Export*"
3350 async subtreep visible-only body-only ext-plist
3351 (lambda () (set-auto-mode t))))
3353 ;;;###autoload
3354 (defun org-html-convert-region-to-html ()
3355 "Assume the current region has org-mode syntax, and convert it to HTML.
3356 This can be used in any buffer. For example, you can write an
3357 itemized list in org-mode syntax in an HTML buffer and use this
3358 command to convert it."
3359 (interactive)
3360 (org-export-replace-region-by 'html))
3362 ;;;###autoload
3363 (defun org-html-export-to-html
3364 (&optional async subtreep visible-only body-only ext-plist)
3365 "Export current buffer to a HTML file.
3367 If narrowing is active in the current buffer, only export its
3368 narrowed part.
3370 If a region is active, export that region.
3372 A non-nil optional argument ASYNC means the process should happen
3373 asynchronously. The resulting file should be accessible through
3374 the `org-export-stack' interface.
3376 When optional argument SUBTREEP is non-nil, export the sub-tree
3377 at point, extracting information from the headline properties
3378 first.
3380 When optional argument VISIBLE-ONLY is non-nil, don't export
3381 contents of hidden elements.
3383 When optional argument BODY-ONLY is non-nil, only write code
3384 between \"<body>\" and \"</body>\" tags.
3386 EXT-PLIST, when provided, is a property list with external
3387 parameters overriding Org default settings, but still inferior to
3388 file-local settings.
3390 Return output file's name."
3391 (interactive)
3392 (let* ((extension (concat "." org-html-extension))
3393 (file (org-export-output-file-name extension subtreep))
3394 (org-export-coding-system org-html-coding-system))
3395 (org-export-to-file 'html file
3396 async subtreep visible-only body-only ext-plist)))
3398 ;;;###autoload
3399 (defun org-html-publish-to-html (plist filename pub-dir)
3400 "Publish an org file to HTML.
3402 FILENAME is the filename of the Org file to be published. PLIST
3403 is the property list for the given project. PUB-DIR is the
3404 publishing directory.
3406 Return output file name."
3407 (org-publish-org-to 'html filename
3408 (concat "." (or (plist-get plist :html-extension)
3409 org-html-extension "html"))
3410 plist pub-dir))
3413 ;;; FIXME
3415 ;;;; org-format-table-html
3416 ;;;; org-format-org-table-html
3417 ;;;; org-format-table-table-html
3418 ;;;; org-table-number-fraction
3419 ;;;; org-table-number-regexp
3420 ;;;; org-html-inline-image-extensions
3421 ;;;; org-export-preferred-target-alist
3422 ;;;; class for anchors
3423 ;;;; org-export-mark-todo-in-toc
3424 ;;;; org-html-format-org-link
3425 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3426 ;;;; alt = (file-name-nondirectory path)
3428 (provide 'ox-html)
3430 ;; Local variables:
3431 ;; generated-autoload-file: "org-loaddefs.el"
3432 ;; End:
3434 ;;; ox-html.el ends here