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