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