ox-html: add figure and table numbers to HTML captions
[org-mode.git] / lisp / ox-html.el
blobf46e7cf4c62e168bbbd589a736f857430a269780
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 nil 'noerror))
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 nil "html5-fancy" 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 nil "html-style" org-html-head-include-default-style)
128 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
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 "Non-nil means using new HTML5 elements.
923 This variable is ignored for anything other than HTML5 export.
925 For compatibility with Internet Explorer, it's probably a good
926 idea to download some form of the html5shiv (for instance
927 https://code.google.com/p/html5shiv/) and add it to your
928 HTML_HEAD_EXTRA, so that your pages don't break for users of IE
929 versions 8 and below."
930 :group 'org-export-html
931 :version "24.4"
932 :package-version '(Org . "8.0")
933 :type 'boolean)
935 (defcustom org-html-container-element "div"
936 "HTML element to use for wrapping top level sections.
937 Can be set with the in-buffer HTML_CONTAINER property or for
938 publishing, with :html-container.
940 Note that changing the default will prevent you from using
941 org-info.js for your website."
942 :group 'org-export-html
943 :version "24.4"
944 :package-version '(Org . "8.0")
945 :type 'string)
947 (defcustom org-html-divs
948 '((preamble "div" "preamble")
949 (content "div" "content")
950 (postamble "div" "postamble"))
951 "Alist of the three section elements for HTML export.
952 The car of each entry is one of 'preamble, 'content or 'postamble.
953 The cdrs of each entry are the ELEMENT_TYPE and ID for each
954 section of the exported document.
956 Note that changing the default will prevent you from using
957 org-info.js for your website."
958 :group 'org-export-html
959 :version "24.4"
960 :package-version '(Org . "8.0")
961 :type '(list :greedy t
962 (list :tag "Preamble"
963 (const :format "" preamble)
964 (string :tag "element") (string :tag " id"))
965 (list :tag "Content"
966 (const :format "" content)
967 (string :tag "element") (string :tag " id"))
968 (list :tag "Postamble" (const :format "" postamble)
969 (string :tag " id") (string :tag "element"))))
971 (defcustom org-html-metadata-timestamp-format "%Y-%m-%d %a %H:%M"
972 "Format used for timestamps in preamble, postamble and metadata.
973 See `format-time-string' for more information on its components."
974 :group 'org-export-html
975 :version "24.4"
976 :package-version '(Org . "8.0")
977 :type 'string)
979 ;;;; Template :: Mathjax
981 (defcustom org-html-mathjax-options
982 '((path "http://orgmode.org/mathjax/MathJax.js")
983 (scale "100")
984 (align "center")
985 (indent "2em")
986 (mathml nil))
987 "Options for MathJax setup.
989 path The path where to find MathJax
990 scale Scaling for the HTML-CSS backend, usually between 100 and 133
991 align How to align display math: left, center, or right
992 indent If align is not center, how far from the left/right side?
993 mathml Should a MathML player be used if available?
994 This is faster and reduces bandwidth use, but currently
995 sometimes has lower spacing quality. Therefore, the default is
996 nil. When browsers get better, this switch can be flipped.
998 You can also customize this for each buffer, using something like
1000 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
1001 :group 'org-export-html
1002 :type '(list :greedy t
1003 (list :tag "path (the path from where to load MathJax.js)"
1004 (const :format " " path) (string))
1005 (list :tag "scale (scaling for the displayed math)"
1006 (const :format " " scale) (string))
1007 (list :tag "align (alignment of displayed equations)"
1008 (const :format " " align) (string))
1009 (list :tag "indent (indentation with left or right alignment)"
1010 (const :format " " indent) (string))
1011 (list :tag "mathml (should MathML display be used is possible)"
1012 (const :format " " mathml) (boolean))))
1014 (defcustom org-html-mathjax-template
1015 "<script type=\"text/javascript\" src=\"%PATH\"></script>
1016 <script type=\"text/javascript\">
1017 <!--/*--><![CDATA[/*><!--*/
1018 MathJax.Hub.Config({
1019 // Only one of the two following lines, depending on user settings
1020 // First allows browser-native MathML display, second forces HTML/CSS
1021 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
1022 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
1023 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
1024 \"TeX/noUndefined.js\"],
1025 tex2jax: {
1026 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
1027 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
1028 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
1029 ignoreClass: \"tex2jax_ignore\",
1030 processEscapes: false,
1031 processEnvironments: true,
1032 preview: \"TeX\"
1034 showProcessingMessages: true,
1035 displayAlign: \"%ALIGN\",
1036 displayIndent: \"%INDENT\",
1038 \"HTML-CSS\": {
1039 scale: %SCALE,
1040 availableFonts: [\"STIX\",\"TeX\"],
1041 preferredFont: \"TeX\",
1042 webFont: \"TeX\",
1043 imageFont: \"TeX\",
1044 showMathMenu: true,
1046 MMLorHTML: {
1047 prefer: {
1048 MSIE: \"MML\",
1049 Firefox: \"MML\",
1050 Opera: \"HTML\",
1051 other: \"HTML\"
1055 /*]]>*///-->
1056 </script>"
1057 "The MathJax setup for XHTML files."
1058 :group 'org-export-html
1059 :type 'string)
1061 ;;;; Template :: Postamble
1063 (defcustom org-html-postamble 'auto
1064 "Non-nil means insert a postamble in HTML export.
1066 When set to 'auto, check against the
1067 `org-export-with-author/email/creator/date' variables to set the
1068 content of the postamble. When set to a string, use this string
1069 as the postamble. When t, insert a string as defined by the
1070 formatting string in `org-html-postamble-format'.
1072 When set to a function, apply this function and insert the
1073 returned string. The function takes the property list of export
1074 options as its only argument.
1076 Setting :html-postamble in publishing projects will take
1077 precedence over this variable."
1078 :group 'org-export-html
1079 :type '(choice (const :tag "No postamble" nil)
1080 (const :tag "Auto postamble" auto)
1081 (const :tag "Default formatting string" t)
1082 (string :tag "Custom formatting string")
1083 (function :tag "Function (must return a string)")))
1085 (defcustom org-html-postamble-format
1086 '(("en" "<p class=\"author\">Author: %a (%e)</p>
1087 <p class=\"date\">Date: %d</p>
1088 <p class=\"creator\">%c</p>
1089 <p class=\"validation\">%v</p>"))
1090 "Alist of languages and format strings for the HTML postamble.
1092 The first element of each list is the language code, as used for
1093 the LANGUAGE keyword. See `org-export-default-language'.
1095 The second element of each list is a format string to format the
1096 postamble itself. This format string can contain these elements:
1098 %t stands for the title.
1099 %a stands for the author's name.
1100 %e stands for the author's email.
1101 %d stands for the date.
1102 %c will be replaced by `org-html-creator-string'.
1103 %v will be replaced by `org-html-validation-link'.
1104 %T will be replaced by the export time.
1105 %C will be replaced by the last modification time.
1107 If you need to use a \"%\" character, you need to escape it
1108 like that: \"%%\"."
1109 :group 'org-export-html
1110 :type '(repeat
1111 (list (string :tag "Language")
1112 (string :tag "Format string"))))
1114 (defcustom org-html-validation-link
1115 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate</a>"
1116 "Link to HTML validation service."
1117 :group 'org-export-html
1118 :type 'string)
1120 (defcustom org-html-creator-string
1121 (format "<a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s (<a href=\"http://orgmode.org\">Org</a> mode %s)"
1122 emacs-version
1123 (if (fboundp 'org-version) (org-version) "unknown version"))
1124 "Information about the creator of the HTML document.
1125 This option can also be set on with the CREATOR keyword."
1126 :group 'org-export-html
1127 :type '(string :tag "Creator string"))
1129 ;;;; Template :: Preamble
1131 (defcustom org-html-preamble t
1132 "Non-nil means insert a preamble in HTML export.
1134 When t, insert a string as defined by the formatting string in
1135 `org-html-preamble-format'. When set to a string, use this
1136 formatting string instead (see `org-html-postamble-format' for an
1137 example of such a formatting string).
1139 When set to a function, apply this function and insert the
1140 returned string. The function takes the property list of export
1141 options as its only argument.
1143 Setting :html-preamble in publishing projects will take
1144 precedence over this variable."
1145 :group 'org-export-html
1146 :type '(choice (const :tag "No preamble" nil)
1147 (const :tag "Default preamble" t)
1148 (string :tag "Custom formatting string")
1149 (function :tag "Function (must return a string)")))
1151 (defcustom org-html-preamble-format '(("en" ""))
1152 "Alist of languages and format strings for the HTML preamble.
1154 The first element of each list is the language code, as used for
1155 the LANGUAGE keyword. See `org-export-default-language'.
1157 The second element of each list is a format string to format the
1158 preamble itself. This format string can contain these elements:
1160 %t stands for the title.
1161 %a stands for the author's name.
1162 %e stands for the author's email.
1163 %d stands for the date.
1164 %c will be replaced by `org-html-creator-string'.
1165 %v will be replaced by `org-html-validation-link'.
1166 %T will be replaced by the export time.
1167 %C will be replaced by the last modification time.
1169 If you need to use a \"%\" character, you need to escape it
1170 like that: \"%%\".
1172 See the default value of `org-html-postamble-format' for an
1173 example."
1174 :group 'org-export-html
1175 :type '(repeat
1176 (list (string :tag "Language")
1177 (string :tag "Format string"))))
1179 (defcustom org-html-link-up ""
1180 "Where should the \"UP\" link of exported HTML pages lead?"
1181 :group 'org-export-html
1182 :type '(string :tag "File or URL"))
1184 (defcustom org-html-link-home ""
1185 "Where should the \"HOME\" link of exported HTML pages lead?"
1186 :group 'org-export-html
1187 :type '(string :tag "File or URL"))
1189 (defcustom org-html-home/up-format
1190 "<div id=\"org-div-home-and-up\">
1191 <a accesskey=\"h\" href=\"%s\"> UP </a>
1193 <a accesskey=\"H\" href=\"%s\"> HOME </a>
1194 </div>"
1195 "Snippet used to insert the HOME and UP links.
1196 This is a format string, the first %s will receive the UP link,
1197 the second the HOME link. If both `org-html-link-up' and
1198 `org-html-link-home' are empty, the entire snippet will be
1199 ignored."
1200 :group 'org-export-html
1201 :type 'string)
1203 ;;;; Template :: Scripts
1205 (define-obsolete-variable-alias
1206 'org-html-style-include-scripts 'org-html-head-include-scripts "24.4")
1207 (defcustom org-html-head-include-scripts t
1208 "Non-nil means include the JavaScript snippets in exported HTML files.
1209 The actual script is defined in `org-html-scripts' and should
1210 not be modified."
1211 :group 'org-export-html
1212 :version "24.4"
1213 :package-version '(Org . "8.0")
1214 :type 'boolean)
1216 ;;;; Template :: Styles
1218 (define-obsolete-variable-alias
1219 'org-html-style-include-default 'org-html-head-include-default-style "24.4")
1220 (defcustom org-html-head-include-default-style t
1221 "Non-nil means include the default style in exported HTML files.
1222 The actual style is defined in `org-html-style-default' and
1223 should not be modified. Use `org-html-head' to use your own
1224 style information."
1225 :group 'org-export-html
1226 :version "24.4"
1227 :package-version '(Org . "8.0")
1228 :type 'boolean)
1229 ;;;###autoload
1230 (put 'org-html-head-include-default-style 'safe-local-variable 'booleanp)
1232 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
1233 (defcustom org-html-head ""
1234 "Org-wide head definitions for exported HTML files.
1236 This variable can contain the full HTML structure to provide a
1237 style, including the surrounding HTML tags. You can consider
1238 including definitions for the following classes: title, todo,
1239 done, timestamp, timestamp-kwd, tag, target.
1241 For example, a valid value would be:
1243 <style type=\"text/css\">
1244 <![CDATA[
1245 p { font-weight: normal; color: gray; }
1246 h1 { color: black; }
1247 .title { text-align: center; }
1248 .todo, .timestamp-kwd { color: red; }
1249 .done { color: green; }
1251 </style>
1253 If you want to refer to an external style, use something like
1255 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\" />
1257 As the value of this option simply gets inserted into the HTML
1258 <head> header, you can use it to add any arbitrary text to the
1259 header.
1261 You can set this on a per-file basis using #+HTML_HEAD:,
1262 or for publication projects using the :html-head property."
1263 :group 'org-export-html
1264 :version "24.4"
1265 :package-version '(Org . "8.0")
1266 :type 'string)
1267 ;;;###autoload
1268 (put 'org-html-head 'safe-local-variable 'stringp)
1270 (defcustom org-html-head-extra ""
1271 "More head information to add in the HTML output.
1273 You can set this on a per-file basis using #+HTML_HEAD_EXTRA:,
1274 or for publication projects using the :html-head-extra property."
1275 :group 'org-export-html
1276 :version "24.4"
1277 :package-version '(Org . "8.0")
1278 :type 'string)
1279 ;;;###autoload
1280 (put 'org-html-head-extra 'safe-local-variable 'stringp)
1282 ;;;; Todos
1284 (defcustom org-html-todo-kwd-class-prefix ""
1285 "Prefix to class names for TODO keywords.
1286 Each TODO keyword gets a class given by the keyword itself, with this prefix.
1287 The default prefix is empty because it is nice to just use the keyword
1288 as a class name. But if you get into conflicts with other, existing
1289 CSS classes, then this prefix can be very useful."
1290 :group 'org-export-html
1291 :type 'string)
1294 ;;; Internal Functions
1296 (defun org-html-xhtml-p (info)
1297 (let ((dt (downcase (plist-get info :html-doctype))))
1298 (string-match-p "xhtml" dt)))
1300 (defun org-html-html5-p (info)
1301 (let ((dt (downcase (plist-get info :html-doctype))))
1302 (member dt '("html5" "xhtml5" "<!doctype html>"))))
1304 (defun org-html-close-tag (tag attr info)
1305 (concat "<" tag " " attr
1306 (if (org-html-xhtml-p info) " />" ">")))
1308 (defun org-html-doctype (info)
1309 "Return correct html doctype tag from `org-html-doctype-alist',
1310 or the literal value of :html-doctype from INFO if :html-doctype
1311 is not found in the alist.
1312 INFO is a plist used as a communication channel."
1313 (let ((dt (plist-get info :html-doctype)))
1314 (or (cdr (assoc dt org-html-doctype-alist)) dt)))
1316 (defun org-html--make-attribute-string (attributes)
1317 "Return a list of attributes, as a string.
1318 ATTRIBUTES is a plist where values are either strings or nil. An
1319 attributes with a nil value will be omitted from the result."
1320 (let (output)
1321 (dolist (item attributes (mapconcat 'identity (nreverse output) " "))
1322 (cond ((null item) (pop output))
1323 ((symbolp item) (push (substring (symbol-name item) 1) output))
1324 (t (let ((key (car output))
1325 (value (replace-regexp-in-string
1326 "\"" "&quot;" (org-html-encode-plain-text item))))
1327 (setcar output (format "%s=\"%s\"" key value))))))))
1329 (defun org-html-format-inline-image (src info &optional
1330 caption label attr standalone-p)
1331 "Format an inline image from SRC.
1332 CAPTION, LABEL and ATTR are optional arguments providing the
1333 caption, the label and the attribute of the image.
1334 When STANDALONE-P is t, wrap the <img.../> into a <div>...</div>."
1335 (let* ((id (if (not label) ""
1336 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1337 (attr (concat attr
1338 (format " src=\"%s\"" src)
1339 (cond
1340 ((string-match "\\<alt=" (or attr "")) "")
1341 ((string-match "^ltxpng/" src)
1342 (format " alt=\"%s\""
1343 (org-html-encode-plain-text
1344 (org-find-text-property-in-string
1345 'org-latex-src src))))
1346 (t (format " alt=\"%s\""
1347 (file-name-nondirectory src))))))
1348 (html5-fancy (and (org-html-html5-p info)
1349 (plist-get info :html-html5-fancy))))
1350 (cond
1351 (standalone-p
1352 (let ((img (org-html-close-tag "img" attr info)))
1353 (format (if html5-fancy
1354 "\n<figure%s>%s%s\n</figure>"
1355 "\n<div%s class=\"figure\">%s%s\n</div>")
1356 id (format "\n<p>%s</p>" img)
1357 (if (and caption (not (string= caption "")))
1358 (format (if html5-fancy
1359 "\n<figcaption>%s</figcaption>"
1360 "\n<p>%s</p>") caption) ""))))
1361 (t (org-html-close-tag "img" (concat attr id) info)))))
1363 (defun org-html--textarea-block (element)
1364 "Transcode ELEMENT into a textarea block.
1365 ELEMENT is either a src block or an example block."
1366 (let* ((code (car (org-export-unravel-code element)))
1367 (attr (org-export-read-attribute :attr_html element)))
1368 (format "<p>\n<textarea cols=\"%s\" rows=\"%s\">\n%s</textarea>\n</p>"
1369 (or (plist-get attr :width) 80)
1370 (or (plist-get attr :height) (org-count-lines code))
1371 code)))
1373 (defun org-html--has-caption-p (element &optional info)
1374 "Non-nil when ELEMENT has a caption affiliated keyword.
1375 INFO is a plist used as a communication channel. This function
1376 is meant to be used as a predicate for `org-export-get-ordinal' or
1377 a value to `org-html-standalone-image-predicate'."
1378 (org-element-property :caption element))
1380 ;;;; Table
1382 (defun org-html-htmlize-region-for-paste (beg end)
1383 "Convert the region between BEG and END to HTML, using htmlize.el.
1384 This is much like `htmlize-region-for-paste', only that it uses
1385 the settings define in the org-... variables."
1386 (let* ((htmlize-output-type org-html-htmlize-output-type)
1387 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1388 (htmlbuf (htmlize-region beg end)))
1389 (unwind-protect
1390 (with-current-buffer htmlbuf
1391 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1392 (plist-get htmlize-buffer-places 'content-end)))
1393 (kill-buffer htmlbuf))))
1395 ;;;###autoload
1396 (defun org-html-htmlize-generate-css ()
1397 "Create the CSS for all font definitions in the current Emacs session.
1398 Use this to create face definitions in your CSS style file that can then
1399 be used by code snippets transformed by htmlize.
1400 This command just produces a buffer that contains class definitions for all
1401 faces used in the current Emacs session. You can copy and paste the ones you
1402 need into your CSS file.
1404 If you then set `org-html-htmlize-output-type' to `css', calls
1405 to the function `org-html-htmlize-region-for-paste' will
1406 produce code that uses these same face definitions."
1407 (interactive)
1408 (require 'htmlize)
1409 (and (get-buffer "*html*") (kill-buffer "*html*"))
1410 (with-temp-buffer
1411 (let ((fl (face-list))
1412 (htmlize-css-name-prefix "org-")
1413 (htmlize-output-type 'css)
1414 f i)
1415 (while (setq f (pop fl)
1416 i (and f (face-attribute f :inherit)))
1417 (when (and (symbolp f) (or (not i) (not (listp i))))
1418 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1419 (htmlize-region (point-min) (point-max))))
1420 (org-pop-to-buffer-same-window "*html*")
1421 (goto-char (point-min))
1422 (if (re-search-forward "<style" nil t)
1423 (delete-region (point-min) (match-beginning 0)))
1424 (if (re-search-forward "</style>" nil t)
1425 (delete-region (1+ (match-end 0)) (point-max)))
1426 (beginning-of-line 1)
1427 (if (looking-at " +") (replace-match ""))
1428 (goto-char (point-min)))
1430 (defun org-html--make-string (n string)
1431 "Build a string by concatenating N times STRING."
1432 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1434 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1435 "Turn todo keyword KWD into a valid class name.
1436 Replaces invalid characters with \"_\"."
1437 (save-match-data
1438 (while (string-match "[^a-zA-Z0-9_]" kwd)
1439 (setq kwd (replace-match "_" t t kwd))))
1440 kwd)
1442 (defun org-html-format-footnote-reference (n def refcnt)
1443 "Format footnote reference N with definition DEF into HTML."
1444 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1445 (format org-html-footnote-format
1446 (let* ((id (format "fnr.%s%s" n extra))
1447 (href (format " href=\"#fn.%s\"" n))
1448 (attributes (concat " class=\"footref\"" href)))
1449 (org-html--anchor id n attributes)))))
1451 (defun org-html-format-footnotes-section (section-name definitions)
1452 "Format footnotes section SECTION-NAME."
1453 (if (not definitions) ""
1454 (format org-html-footnotes-section section-name definitions)))
1456 (defun org-html-format-footnote-definition (fn)
1457 "Format the footnote definition FN."
1458 (let ((n (car fn)) (def (cdr fn)))
1459 (format
1460 "<div class=\"footdef\">%s %s</div>\n"
1461 (format org-html-footnote-format
1462 (let* ((id (format "fn.%s" n))
1463 (href (format " href=\"#fnr.%s\"" n))
1464 (attributes (concat " class=\"footnum\"" href)))
1465 (org-html--anchor id n attributes)))
1466 def)))
1468 (defun org-html-footnote-section (info)
1469 "Format the footnote section.
1470 INFO is a plist used as a communication channel."
1471 (let* ((fn-alist (org-export-collect-footnote-definitions
1472 (plist-get info :parse-tree) info))
1473 (fn-alist
1474 (loop for (n type raw) in fn-alist collect
1475 (cons n (if (eq (org-element-type raw) 'org-data)
1476 (org-trim (org-export-data raw info))
1477 (format "<p>%s</p>"
1478 (org-trim (org-export-data raw info))))))))
1479 (when fn-alist
1480 (org-html-format-footnotes-section
1481 (org-html--translate "Footnotes" info)
1482 (format
1483 "\n%s\n"
1484 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1487 ;;; Template
1489 (defun org-html--build-meta-info (info)
1490 "Return meta tags for exported document.
1491 INFO is a plist used as a communication channel."
1492 (let ((protect-string
1493 (lambda (str)
1494 (replace-regexp-in-string
1495 "\"" "&quot;" (org-html-encode-plain-text str))))
1496 (title (org-export-data (plist-get info :title) info))
1497 (author (and (plist-get info :with-author)
1498 (let ((auth (plist-get info :author)))
1499 (and auth
1500 ;; Return raw Org syntax, skipping non
1501 ;; exportable objects.
1502 (org-element-interpret-data
1503 (org-element-map auth
1504 (cons 'plain-text org-element-all-objects)
1505 'identity info))))))
1506 (description (plist-get info :description))
1507 (keywords (plist-get info :keywords))
1508 (charset (or (and org-html-coding-system
1509 (fboundp 'coding-system-get)
1510 (coding-system-get org-html-coding-system
1511 'mime-charset))
1512 "iso-8859-1")))
1513 (concat
1514 (format "<title>%s</title>\n" title)
1515 (when (plist-get info :time-stamp-file)
1516 (format-time-string
1517 (concat "<!-- " org-html-metadata-timestamp-format " -->\n")))
1518 (format
1519 (if (org-html-html5-p info)
1520 (org-html-close-tag "meta" " charset=\"%s\"" info)
1521 (org-html-close-tag
1522 "meta" " http-equiv=\"Content-Type\" content=\"text/html;charset=%s\""
1523 info))
1524 charset) "\n"
1525 (org-html-close-tag "meta" " name=\"generator\" content=\"Org-mode\"" info)
1526 "\n"
1527 (and (org-string-nw-p author)
1528 (org-html-close-tag "meta"
1529 (format " name=\"author\" content=\"%s\""
1530 (funcall protect-string author))
1531 info)
1532 "\n")
1533 (and (org-string-nw-p description)
1534 (org-html-close-tag "meta"
1535 (format " name=\"description\" content=\"%s\"\n"
1536 (funcall protect-string description))
1537 info)
1538 "\n")
1539 (and (org-string-nw-p keywords)
1540 (org-html-close-tag "meta"
1541 (format " name=\"keywords\" content=\"%s\""
1542 (funcall protect-string keywords))
1543 info)
1544 "\n"))))
1546 (defun org-html--build-head (info)
1547 "Return information for the <head>..</head> of the HTML output.
1548 INFO is a plist used as a communication channel."
1549 (org-element-normalize-string
1550 (concat
1551 (when (plist-get info :html-head-include-default-style)
1552 (org-element-normalize-string org-html-style-default))
1553 (org-element-normalize-string (plist-get info :html-head))
1554 (org-element-normalize-string (plist-get info :html-head-extra))
1555 (when (and (plist-get info :html-htmlized-css-url)
1556 (eq org-html-htmlize-output-type 'css))
1557 (org-html-close-tag "link"
1558 (format " rel=\"stylesheet\" href=\"%s\" type=\"text/css\""
1559 (plist-get info :html-htmlized-css-url))
1560 info))
1561 (when (plist-get info :html-head-include-scripts) org-html-scripts))))
1563 (defun org-html--build-mathjax-config (info)
1564 "Insert the user setup into the mathjax template.
1565 INFO is a plist used as a communication channel."
1566 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1567 (org-element-map (plist-get info :parse-tree)
1568 '(latex-fragment latex-environment) 'identity info t))
1569 (let ((template org-html-mathjax-template)
1570 (options org-html-mathjax-options)
1571 (in-buffer (or (plist-get info :html-mathjax) ""))
1572 name val (yes " ") (no "// ") x)
1573 (mapc
1574 (lambda (e)
1575 (setq name (car e) val (nth 1 e))
1576 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1577 (setq val (car (read-from-string
1578 (substring in-buffer (match-end 0))))))
1579 (if (not (stringp val)) (setq val (format "%s" val)))
1580 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1581 (setq template (replace-match val t t template))))
1582 options)
1583 (setq val (nth 1 (assq 'mathml options)))
1584 (if (string-match (concat "\\<mathml:") in-buffer)
1585 (setq val (car (read-from-string
1586 (substring in-buffer (match-end 0))))))
1587 ;; Exchange prefixes depending on mathml setting.
1588 (if (not val) (setq x yes yes no no x))
1589 ;; Replace cookies to turn on or off the config/jax lines.
1590 (if (string-match ":MMLYES:" template)
1591 (setq template (replace-match yes t t template)))
1592 (if (string-match ":MMLNO:" template)
1593 (setq template (replace-match no t t template)))
1594 ;; Return the modified template.
1595 (org-element-normalize-string template))))
1597 (defun org-html-format-spec (info)
1598 "Return format specification for elements that can be
1599 used in the preamble or postamble."
1600 `((?t . ,(org-export-data (plist-get info :title) info))
1601 (?d . ,(org-export-data (org-export-get-date info) info))
1602 (?T . ,(format-time-string org-html-metadata-timestamp-format))
1603 (?a . ,(org-export-data (plist-get info :author) info))
1604 (?e . ,(mapconcat
1605 (lambda (e)
1606 (format "<a href=\"mailto:%s\">%s</a>" e e))
1607 (split-string (plist-get info :email) ",+ *")
1608 ", "))
1609 (?c . ,(plist-get info :creator))
1610 (?C . ,(let ((file (plist-get info :input-file)))
1611 (format-time-string org-html-metadata-timestamp-format
1612 (if file (nth 5 (file-attributes file))
1613 (current-time)))))
1614 (?v . ,(or org-html-validation-link ""))))
1616 (defun org-html--build-pre/postamble (type info)
1617 "Return document preamble or postamble as a string, or nil.
1618 TYPE is either 'preamble or 'postamble, INFO is a plist used as a
1619 communication channel."
1620 (let ((section (plist-get info (intern (format ":html-%s" type))))
1621 (spec (org-html-format-spec info)))
1622 (when section
1623 (let ((section-contents
1624 (if (functionp section) (funcall section info)
1625 (cond
1626 ((stringp section) (format-spec section spec))
1627 ((eq section 'auto)
1628 (let ((date (cdr (assq ?d spec)))
1629 (author (cdr (assq ?a spec)))
1630 (email (cdr (assq ?e spec)))
1631 (creator (cdr (assq ?c spec)))
1632 (timestamp (cdr (assq ?T spec)))
1633 (validation-link (cdr (assq ?v spec))))
1634 (concat
1635 (when (and (plist-get info :with-date)
1636 (org-string-nw-p date))
1637 (format "<p class=\"date\">%s: %s</p>\n"
1638 (org-html--translate "Date" info)
1639 date))
1640 (when (and (plist-get info :with-author)
1641 (org-string-nw-p author))
1642 (format "<p class=\"author\">%s: %s</p>\n"
1643 (org-html--translate "Author" info)
1644 author))
1645 (when (and (plist-get info :with-email)
1646 (org-string-nw-p email))
1647 (format "<p class=\"email\">%s: %s</p>\n"
1648 (org-html--translate "Email" info)
1649 email))
1650 (when (plist-get info :time-stamp-file)
1651 (format
1652 "<p class=\"date\">%s: %s</p>\n"
1653 (org-html--translate "Created" info)
1654 (format-time-string org-html-metadata-timestamp-format)))
1655 (when (plist-get info :with-creator)
1656 (format "<p class=\"creator\">%s</p>\n" creator))
1657 (format "<p class=\"validation\">%s</p>\n"
1658 validation-link))))
1659 (t (format-spec
1660 (or (cadr (assoc
1661 (plist-get info :language)
1662 (eval (intern
1663 (format "org-html-%s-format" type)))))
1664 (cadr
1665 (assoc
1666 "en"
1667 (eval
1668 (intern (format "org-html-%s-format" type))))))
1669 spec))))))
1670 (when (org-string-nw-p section-contents)
1671 (concat
1672 (format "<%s id=\"%s\" class=\"%s\">\n"
1673 (nth 1 (assq type org-html-divs))
1674 (nth 2 (assq type org-html-divs))
1675 org-html--pre/postamble-class)
1676 (org-element-normalize-string section-contents)
1677 (format "</%s>\n" (nth 1 (assq type org-html-divs)))))))))
1679 (defun org-html-inner-template (contents info)
1680 "Return body of document string after HTML conversion.
1681 CONTENTS is the transcoded contents string. INFO is a plist
1682 holding export options."
1683 (concat
1684 ;; Table of contents.
1685 (let ((depth (plist-get info :with-toc)))
1686 (when depth (org-html-toc depth info)))
1687 ;; Document contents.
1688 contents
1689 ;; Footnotes section.
1690 (org-html-footnote-section info)))
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 (org-html-doctype info)
1713 "\n"
1714 (concat "<html"
1715 (when (org-html-xhtml-p info)
1716 (format
1717 " xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\""
1718 (plist-get info :language) (plist-get info :language)))
1719 ">\n")
1720 "<head>\n"
1721 (org-html--build-meta-info info)
1722 (org-html--build-head info)
1723 (org-html--build-mathjax-config info)
1724 "</head>\n"
1725 "<body>\n"
1726 (let ((link-up (org-trim (plist-get info :html-link-up)))
1727 (link-home (org-trim (plist-get info :html-link-home))))
1728 (unless (and (string= link-up "") (string= link-home ""))
1729 (format org-html-home/up-format
1730 (or link-up link-home)
1731 (or link-home link-up))))
1732 ;; Preamble.
1733 (org-html--build-pre/postamble 'preamble info)
1734 ;; Document contents.
1735 (format "<%s id=\"%s\">\n"
1736 (nth 1 (assq 'content org-html-divs))
1737 (nth 2 (assq 'content org-html-divs)))
1738 ;; Document title.
1739 (let ((title (plist-get info :title)))
1740 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data (or title "") info)))
1741 contents
1742 (format "</%s>\n"
1743 (nth 1 (assq 'content org-html-divs)))
1744 ;; Postamble.
1745 (org-html--build-pre/postamble 'postamble info)
1746 ;; Closing document.
1747 "</body>\n</html>"))
1749 (defun org-html--translate (s info)
1750 "Translate string S according to specified language.
1751 INFO is a plist used as a communication channel."
1752 (org-export-translate s :html info))
1754 ;;;; Anchor
1756 (defun org-html--anchor (&optional id desc attributes)
1757 "Format a HTML anchor."
1758 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1759 (attributes (concat (and id (format " id=\"%s\"" id))
1760 (and name (format " name=\"%s\"" name))
1761 attributes)))
1762 (format "<a%s>%s</a>" attributes (or desc ""))))
1764 ;;;; Todo
1766 (defun org-html--todo (todo)
1767 "Format TODO keywords into HTML."
1768 (when todo
1769 (format "<span class=\"%s %s%s\">%s</span>"
1770 (if (member todo org-done-keywords) "done" "todo")
1771 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1772 todo)))
1774 ;;;; Tags
1776 (defun org-html--tags (tags)
1777 "Format TAGS into HTML."
1778 (when tags
1779 (format "<span class=\"tag\">%s</span>"
1780 (mapconcat
1781 (lambda (tag)
1782 (format "<span class=\"%s\">%s</span>"
1783 (concat org-html-tag-class-prefix
1784 (org-html-fix-class-name tag))
1785 tag))
1786 tags "&#xa0;"))))
1788 ;;;; Headline
1790 (defun* org-html-format-headline
1791 (todo todo-type priority text tags
1792 &key level section-number headline-label &allow-other-keys)
1793 "Format a headline in HTML."
1794 (let ((section-number
1795 (when section-number
1796 (format "<span class=\"section-number-%d\">%s</span> "
1797 level section-number)))
1798 (todo (org-html--todo todo))
1799 (tags (org-html--tags tags)))
1800 (concat section-number todo (and todo " ") text
1801 (and tags "&#xa0;&#xa0;&#xa0;") tags)))
1803 ;;;; Src Code
1805 (defun org-html-fontify-code (code lang)
1806 "Color CODE with htmlize library.
1807 CODE is a string representing the source code to colorize. LANG
1808 is the language used for CODE, as a string, or nil."
1809 (when code
1810 (cond
1811 ;; Case 1: No lang. Possibly an example block.
1812 ((not lang)
1813 ;; Simple transcoding.
1814 (org-html-encode-plain-text code))
1815 ;; Case 2: No htmlize or an inferior version of htmlize
1816 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1817 ;; Emit a warning.
1818 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1819 ;; Simple transcoding.
1820 (org-html-encode-plain-text code))
1822 ;; Map language
1823 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1824 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1825 (cond
1826 ;; Case 1: Language is not associated with any Emacs mode
1827 ((not (functionp lang-mode))
1828 ;; Simple transcoding.
1829 (org-html-encode-plain-text code))
1830 ;; Case 2: Default. Fontify code.
1832 ;; htmlize
1833 (setq code (with-temp-buffer
1834 ;; Switch to language-specific mode.
1835 (funcall lang-mode)
1836 (insert code)
1837 ;; Fontify buffer.
1838 (font-lock-fontify-buffer)
1839 ;; Remove formatting on newline characters.
1840 (save-excursion
1841 (let ((beg (point-min))
1842 (end (point-max)))
1843 (goto-char beg)
1844 (while (progn (end-of-line) (< (point) end))
1845 (put-text-property (point) (1+ (point)) 'face nil)
1846 (forward-char 1))))
1847 (org-src-mode)
1848 (set-buffer-modified-p nil)
1849 ;; Htmlize region.
1850 (org-html-htmlize-region-for-paste
1851 (point-min) (point-max))))
1852 ;; Strip any enclosing <pre></pre> tags.
1853 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1854 (end (and beg (string-match "</pre>\\'" code))))
1855 (if (and beg end) (substring code beg end) code)))))))))
1857 (defun org-html-do-format-code
1858 (code &optional lang refs retain-labels num-start)
1859 "Format CODE string as source code.
1860 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1861 respectively, the language of the source code, as a string, an
1862 alist between line numbers and references (as returned by
1863 `org-export-unravel-code'), a boolean specifying if labels should
1864 appear in the source code, and the number associated to the first
1865 line of code."
1866 (let* ((code-lines (org-split-string code "\n"))
1867 (code-length (length code-lines))
1868 (num-fmt
1869 (and num-start
1870 (format "%%%ds: "
1871 (length (number-to-string (+ code-length num-start))))))
1872 (code (org-html-fontify-code code lang)))
1873 (org-export-format-code
1874 code
1875 (lambda (loc line-num ref)
1876 (setq loc
1877 (concat
1878 ;; Add line number, if needed.
1879 (when num-start
1880 (format "<span class=\"linenr\">%s</span>"
1881 (format num-fmt line-num)))
1882 ;; Transcoded src line.
1884 ;; Add label, if needed.
1885 (when (and ref retain-labels) (format " (%s)" ref))))
1886 ;; Mark transcoded line as an anchor, if needed.
1887 (if (not ref) loc
1888 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1889 ref loc)))
1890 num-start refs)))
1892 (defun org-html-format-code (element info)
1893 "Format contents of ELEMENT as source code.
1894 ELEMENT is either an example block or a src block. INFO is
1895 a plist used as a communication channel."
1896 (let* ((lang (org-element-property :language element))
1897 ;; Extract code and references.
1898 (code-info (org-export-unravel-code element))
1899 (code (car code-info))
1900 (refs (cdr code-info))
1901 ;; Does the src block contain labels?
1902 (retain-labels (org-element-property :retain-labels element))
1903 ;; Does it have line numbers?
1904 (num-start (case (org-element-property :number-lines element)
1905 (continued (org-export-get-loc element info))
1906 (new 0))))
1907 (org-html-do-format-code code lang refs retain-labels num-start)))
1910 ;;; Tables of Contents
1912 (defun org-html-toc (depth info)
1913 "Build a table of contents.
1914 DEPTH is an integer specifying the depth of the table. INFO is a
1915 plist used as a communication channel. Return the table of
1916 contents as a string, or nil if it is empty."
1917 (let ((toc-entries
1918 (mapcar (lambda (headline)
1919 (cons (org-html--format-toc-headline headline info)
1920 (org-export-get-relative-level headline info)))
1921 (org-export-collect-headlines info depth))))
1922 (when toc-entries
1923 (concat "<div id=\"table-of-contents\">\n"
1924 (format "<h%d>%s</h%d>\n"
1925 org-html-toplevel-hlevel
1926 (org-html--translate "Table of Contents" info)
1927 org-html-toplevel-hlevel)
1928 "<div id=\"text-table-of-contents\">"
1929 (org-html--toc-text toc-entries)
1930 "</div>\n"
1931 "</div>\n"))))
1933 (defun org-html--toc-text (toc-entries)
1934 "Return innards of a table of contents, as a string.
1935 TOC-ENTRIES is an alist where key is an entry title, as a string,
1936 and value is its relative level, as an integer."
1937 (let* ((prev-level (1- (cdar toc-entries)))
1938 (start-level prev-level))
1939 (concat
1940 (mapconcat
1941 (lambda (entry)
1942 (let ((headline (car entry))
1943 (level (cdr entry)))
1944 (concat
1945 (let* ((cnt (- level prev-level))
1946 (times (if (> cnt 0) (1- cnt) (- cnt)))
1947 rtn)
1948 (setq prev-level level)
1949 (concat
1950 (org-html--make-string
1951 times (cond ((> cnt 0) "\n<ul>\n<li>")
1952 ((< cnt 0) "</li>\n</ul>\n")))
1953 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1954 headline)))
1955 toc-entries "")
1956 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1958 (defun org-html--format-toc-headline (headline info)
1959 "Return an appropriate table of contents entry for HEADLINE.
1960 INFO is a plist used as a communication channel."
1961 (let* ((headline-number (org-export-get-headline-number headline info))
1962 (section-number
1963 (and (not (org-export-low-level-p headline info))
1964 (org-export-numbered-headline-p headline info)
1965 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1966 (tags (and (eq (plist-get info :with-tags) t)
1967 (org-export-get-tags headline info))))
1968 (format "<a href=\"#%s\">%s</a>"
1969 ;; Label.
1970 (org-export-solidify-link-text
1971 (or (org-element-property :CUSTOM_ID headline)
1972 (concat "sec-" (mapconcat 'number-to-string
1973 headline-number "-"))))
1974 ;; Body.
1975 (concat section-number
1976 (org-export-data-with-translations
1977 (org-export-get-alt-title headline info)
1978 ;; Ignore any footnote-reference, link,
1979 ;; radio-target and target in table of contents.
1980 (append
1981 '((footnote-reference . ignore)
1982 (link . (lambda (link desc i) desc))
1983 (radio-target . (lambda (radio desc i) desc))
1984 (target . ignore))
1985 (org-export-backend-translate-table 'html))
1986 info)
1987 (and tags "&#xa0;&#xa0;&#xa0;") (org-html--tags tags)))))
1989 (defun org-html-list-of-listings (info)
1990 "Build a list of listings.
1991 INFO is a plist used as a communication channel. Return the list
1992 of listings as a string, or nil if it is empty."
1993 (let ((lol-entries (org-export-collect-listings info)))
1994 (when lol-entries
1995 (concat "<div id=\"list-of-listings\">\n"
1996 (format "<h%d>%s</h%d>\n"
1997 org-html-toplevel-hlevel
1998 (org-html--translate "List of Listings" info)
1999 org-html-toplevel-hlevel)
2000 "<div id=\"text-list-of-listings\">\n<ul>\n"
2001 (let ((count 0)
2002 (initial-fmt (org-html--translate "Listing %d:" info)))
2003 (mapconcat
2004 (lambda (entry)
2005 (let ((label (org-element-property :name entry))
2006 (title (org-trim
2007 (org-export-data
2008 (or (org-export-get-caption entry t)
2009 (org-export-get-caption entry))
2010 info))))
2011 (concat
2012 "<li>"
2013 (if (not label)
2014 (concat (format initial-fmt (incf count)) " " title)
2015 (format "<a href=\"#%s\">%s %s</a>"
2016 (org-export-solidify-link-text label)
2017 (format initial-fmt (incf count))
2018 title))
2019 "</li>")))
2020 lol-entries "\n"))
2021 "\n</ul>\n</div>\n</div>"))))
2023 (defun org-html-list-of-tables (info)
2024 "Build a list of tables.
2025 INFO is a plist used as a communication channel. Return the list
2026 of tables as a string, or nil if it is empty."
2027 (let ((lol-entries (org-export-collect-tables info)))
2028 (when lol-entries
2029 (concat "<div id=\"list-of-tables\">\n"
2030 (format "<h%d>%s</h%d>\n"
2031 org-html-toplevel-hlevel
2032 (org-html--translate "List of Tables" info)
2033 org-html-toplevel-hlevel)
2034 "<div id=\"text-list-of-tables\">\n<ul>\n"
2035 (let ((count 0)
2036 (initial-fmt (org-html--translate "Table %d:" info)))
2037 (mapconcat
2038 (lambda (entry)
2039 (let ((label (org-element-property :name entry))
2040 (title (org-trim
2041 (org-export-data
2042 (or (org-export-get-caption entry t)
2043 (org-export-get-caption entry))
2044 info))))
2045 (concat
2046 "<li>"
2047 (if (not label)
2048 (concat (format initial-fmt (incf count)) " " title)
2049 (format "<a href=\"#%s\">%s %s</a>"
2050 (org-export-solidify-link-text label)
2051 (format initial-fmt (incf count))
2052 title))
2053 "</li>")))
2054 lol-entries "\n"))
2055 "\n</ul>\n</div>\n</div>"))))
2058 ;;; Transcode Functions
2060 ;;;; Bold
2062 (defun org-html-bold (bold contents info)
2063 "Transcode BOLD from Org to HTML.
2064 CONTENTS is the text with bold markup. INFO is a plist holding
2065 contextual information."
2066 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
2067 contents))
2069 ;;;; Center Block
2071 (defun org-html-center-block (center-block contents info)
2072 "Transcode a CENTER-BLOCK element from Org to HTML.
2073 CONTENTS holds the contents of the block. INFO is a plist
2074 holding contextual information."
2075 (format "<div class=\"center\">\n%s</div>" contents))
2077 ;;;; Clock
2079 (defun org-html-clock (clock contents info)
2080 "Transcode a CLOCK element from Org to HTML.
2081 CONTENTS is nil. INFO is a plist used as a communication
2082 channel."
2083 (format "<p>
2084 <span class=\"timestamp-wrapper\">
2085 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
2086 </span>
2087 </p>"
2088 org-clock-string
2089 (org-translate-time
2090 (org-element-property :raw-value
2091 (org-element-property :value clock)))
2092 (let ((time (org-element-property :duration clock)))
2093 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
2095 ;;;; Code
2097 (defun org-html-code (code contents info)
2098 "Transcode CODE from Org to HTML.
2099 CONTENTS is nil. INFO is a plist holding contextual
2100 information."
2101 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
2102 (org-html-encode-plain-text (org-element-property :value code))))
2104 ;;;; Drawer
2106 (defun org-html-drawer (drawer contents info)
2107 "Transcode a DRAWER element from Org to HTML.
2108 CONTENTS holds the contents of the block. INFO is a plist
2109 holding contextual information."
2110 (if (functionp org-html-format-drawer-function)
2111 (funcall org-html-format-drawer-function
2112 (org-element-property :drawer-name drawer)
2113 contents)
2114 ;; If there's no user defined function: simply
2115 ;; display contents of the drawer.
2116 contents))
2118 ;;;; Dynamic Block
2120 (defun org-html-dynamic-block (dynamic-block contents info)
2121 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2122 CONTENTS holds the contents of the block. INFO is a plist
2123 holding contextual information. See `org-export-data'."
2124 contents)
2126 ;;;; Entity
2128 (defun org-html-entity (entity contents info)
2129 "Transcode an ENTITY object from Org to HTML.
2130 CONTENTS are the definition itself. INFO is a plist holding
2131 contextual information."
2132 (org-element-property :html entity))
2134 ;;;; Example Block
2136 (defun org-html-example-block (example-block contents info)
2137 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2138 CONTENTS is nil. INFO is a plist holding contextual
2139 information."
2140 (if (org-export-read-attribute :attr_html example-block :textarea)
2141 (org-html--textarea-block example-block)
2142 (format "<pre class=\"example\">\n%s</pre>"
2143 (org-html-format-code example-block info))))
2145 ;;;; Export Snippet
2147 (defun org-html-export-snippet (export-snippet contents info)
2148 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2149 CONTENTS is nil. INFO is a plist holding contextual
2150 information."
2151 (when (eq (org-export-snippet-backend export-snippet) 'html)
2152 (org-element-property :value export-snippet)))
2154 ;;;; Export Block
2156 (defun org-html-export-block (export-block contents info)
2157 "Transcode a EXPORT-BLOCK element from Org to HTML.
2158 CONTENTS is nil. INFO is a plist holding contextual information."
2159 (when (string= (org-element-property :type export-block) "HTML")
2160 (org-remove-indentation (org-element-property :value export-block))))
2162 ;;;; Fixed Width
2164 (defun org-html-fixed-width (fixed-width contents info)
2165 "Transcode a FIXED-WIDTH element from Org to HTML.
2166 CONTENTS is nil. INFO is a plist holding contextual information."
2167 (format "<pre class=\"example\">\n%s</pre>"
2168 (org-html-do-format-code
2169 (org-remove-indentation
2170 (org-element-property :value fixed-width)))))
2172 ;;;; Footnote Reference
2174 (defun org-html-footnote-reference (footnote-reference contents info)
2175 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2176 CONTENTS is nil. INFO is a plist holding contextual information."
2177 (concat
2178 ;; Insert separator between two footnotes in a row.
2179 (let ((prev (org-export-get-previous-element footnote-reference info)))
2180 (when (eq (org-element-type prev) 'footnote-reference)
2181 org-html-footnote-separator))
2182 (cond
2183 ((not (org-export-footnote-first-reference-p footnote-reference info))
2184 (org-html-format-footnote-reference
2185 (org-export-get-footnote-number footnote-reference info)
2186 "IGNORED" 100))
2187 ;; Inline definitions are secondary strings.
2188 ((eq (org-element-property :type footnote-reference) 'inline)
2189 (org-html-format-footnote-reference
2190 (org-export-get-footnote-number footnote-reference info)
2191 "IGNORED" 1))
2192 ;; Non-inline footnotes definitions are full Org data.
2193 (t (org-html-format-footnote-reference
2194 (org-export-get-footnote-number footnote-reference info)
2195 "IGNORED" 1)))))
2197 ;;;; Headline
2199 (defun org-html-format-headline--wrap
2200 (headline info &optional format-function &rest extra-keys)
2201 "Transcode a HEADLINE element from Org to HTML.
2202 CONTENTS holds the contents of the headline. INFO is a plist
2203 holding contextual information."
2204 (let* ((level (+ (org-export-get-relative-level headline info)
2205 (1- org-html-toplevel-hlevel)))
2206 (headline-number (org-export-get-headline-number headline info))
2207 (section-number (and (not (org-export-low-level-p headline info))
2208 (org-export-numbered-headline-p headline info)
2209 (mapconcat 'number-to-string
2210 headline-number ".")))
2211 (todo (and (plist-get info :with-todo-keywords)
2212 (let ((todo (org-element-property :todo-keyword headline)))
2213 (and todo (org-export-data todo info)))))
2214 (todo-type (and todo (org-element-property :todo-type headline)))
2215 (priority (and (plist-get info :with-priority)
2216 (org-element-property :priority headline)))
2217 (text (org-export-data (org-element-property :title headline) info))
2218 (tags (and (plist-get info :with-tags)
2219 (org-export-get-tags headline info)))
2220 (headline-label (or (org-element-property :CUSTOM_ID headline)
2221 (concat "sec-" (mapconcat 'number-to-string
2222 headline-number "-"))))
2223 (format-function (cond
2224 ((functionp format-function) format-function)
2225 ((functionp org-html-format-headline-function)
2226 (function*
2227 (lambda (todo todo-type priority text tags
2228 &allow-other-keys)
2229 (funcall org-html-format-headline-function
2230 todo todo-type priority text tags))))
2231 (t 'org-html-format-headline))))
2232 (apply format-function
2233 todo todo-type priority text tags
2234 :headline-label headline-label :level level
2235 :section-number section-number extra-keys)))
2237 (defun org-html-headline (headline contents info)
2238 "Transcode a HEADLINE element from Org to HTML.
2239 CONTENTS holds the contents of the headline. INFO is a plist
2240 holding contextual information."
2241 ;; Empty contents?
2242 (setq contents (or contents ""))
2243 (let* ((numberedp (org-export-numbered-headline-p headline info))
2244 (level (org-export-get-relative-level headline info))
2245 (text (org-export-data (org-element-property :title headline) info))
2246 (todo (and (plist-get info :with-todo-keywords)
2247 (let ((todo (org-element-property :todo-keyword headline)))
2248 (and todo (org-export-data todo info)))))
2249 (todo-type (and todo (org-element-property :todo-type headline)))
2250 (tags (and (plist-get info :with-tags)
2251 (org-export-get-tags headline info)))
2252 (priority (and (plist-get info :with-priority)
2253 (org-element-property :priority headline)))
2254 (section-number (and (org-export-numbered-headline-p headline info)
2255 (mapconcat 'number-to-string
2256 (org-export-get-headline-number
2257 headline info) ".")))
2258 ;; Create the headline text.
2259 (full-text (org-html-format-headline--wrap headline info)))
2260 (cond
2261 ;; Case 1: This is a footnote section: ignore it.
2262 ((org-element-property :footnote-section-p headline) nil)
2263 ;; Case 2. This is a deep sub-tree: export it as a list item.
2264 ;; Also export as items headlines for which no section
2265 ;; format has been found.
2266 ((org-export-low-level-p headline info)
2267 ;; Build the real contents of the sub-tree.
2268 (let* ((type (if numberedp 'ordered 'unordered))
2269 (itemized-body (org-html-format-list-item
2270 contents type nil info nil full-text)))
2271 (concat
2272 (and (org-export-first-sibling-p headline info)
2273 (org-html-begin-plain-list type))
2274 itemized-body
2275 (and (org-export-last-sibling-p headline info)
2276 (org-html-end-plain-list type)))))
2277 ;; Case 3. Standard headline. Export it as a section.
2279 (let* ((section-number (mapconcat 'number-to-string
2280 (org-export-get-headline-number
2281 headline info) "-"))
2282 (ids (remove 'nil
2283 (list (org-element-property :CUSTOM_ID headline)
2284 (concat "sec-" section-number)
2285 (org-element-property :ID headline))))
2286 (preferred-id (car ids))
2287 (extra-ids (cdr ids))
2288 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2289 (level1 (+ level (1- org-html-toplevel-hlevel)))
2290 (first-content (car (org-element-contents headline))))
2291 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2292 (org-html--container headline info)
2293 (format "outline-container-%s"
2294 (or (org-element-property :CUSTOM_ID headline)
2295 (concat "sec-" section-number)))
2296 (concat (format "outline-%d" level1) (and extra-class " ")
2297 extra-class)
2298 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2299 level1
2300 preferred-id
2301 (mapconcat
2302 (lambda (x)
2303 (let ((id (org-export-solidify-link-text
2304 (if (org-uuidgen-p x) (concat "ID-" x)
2305 x))))
2306 (org-html--anchor id)))
2307 extra-ids "")
2308 full-text
2309 level1)
2310 ;; When there is no section, pretend there is an empty
2311 ;; one to get the correct <div class="outline- ...>
2312 ;; which is needed by `org-info.js'.
2313 (if (not (eq (org-element-type first-content) 'section))
2314 (concat (org-html-section first-content "" info)
2315 contents)
2316 contents)
2317 (org-html--container headline info)))))))
2319 (defun org-html--container (headline info)
2320 (or (org-element-property :HTML_CONTAINER headline)
2321 (if (= 1 (org-export-get-relative-level headline info))
2322 (plist-get info :html-container)
2323 "div")))
2325 ;;;; Horizontal Rule
2327 (defun org-html-horizontal-rule (horizontal-rule contents info)
2328 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2329 CONTENTS is nil. INFO is a plist holding contextual information."
2330 (org-html-close-tag "hr" nil info))
2332 ;;;; Inline Src Block
2334 (defun org-html-inline-src-block (inline-src-block contents info)
2335 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2336 CONTENTS holds the contents of the item. INFO is a plist holding
2337 contextual information."
2338 (let* ((org-lang (org-element-property :language inline-src-block))
2339 (code (org-element-property :value inline-src-block)))
2340 (error "Cannot export inline src block")))
2342 ;;;; Inlinetask
2344 (defun org-html-format-section (text class &optional id)
2345 "Format a section with TEXT into a HTML div with CLASS and ID."
2346 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2347 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2349 (defun org-html-inlinetask (inlinetask contents info)
2350 "Transcode an INLINETASK element from Org to HTML.
2351 CONTENTS holds the contents of the block. INFO is a plist
2352 holding contextual information."
2353 (cond
2354 ;; If `org-html-format-inlinetask-function' is provided, call it
2355 ;; with appropriate arguments.
2356 ((functionp org-html-format-inlinetask-function)
2357 (let ((format-function
2358 (function*
2359 (lambda (todo todo-type priority text tags
2360 &key contents &allow-other-keys)
2361 (funcall org-html-format-inlinetask-function
2362 todo todo-type priority text tags contents)))))
2363 (org-html-format-headline--wrap
2364 inlinetask info format-function :contents contents)))
2365 ;; Otherwise, use a default template.
2366 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2367 (org-html-format-headline--wrap inlinetask info)
2368 (org-html-close-tag "br" nil info)
2369 contents))))
2371 ;;;; Italic
2373 (defun org-html-italic (italic contents info)
2374 "Transcode ITALIC from Org to HTML.
2375 CONTENTS is the text with italic markup. INFO is a plist holding
2376 contextual information."
2377 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2379 ;;;; Item
2381 (defun org-html-checkbox (checkbox)
2382 "Format CHECKBOX into HTML."
2383 (case checkbox (on "<code>[X]</code>")
2384 (off "<code>[&#xa0;]</code>")
2385 (trans "<code>[-]</code>")
2386 (t "")))
2388 (defun org-html-format-list-item (contents type checkbox info
2389 &optional term-counter-id
2390 headline)
2391 "Format a list item into HTML."
2392 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
2393 (br (org-html-close-tag "br" nil info)))
2394 (concat
2395 (case type
2396 (ordered
2397 (let* ((counter term-counter-id)
2398 (extra (if counter (format " value=\"%s\"" counter) "")))
2399 (concat
2400 (format "<li%s>" extra)
2401 (when headline (concat headline br)))))
2402 (unordered
2403 (let* ((id term-counter-id)
2404 (extra (if id (format " id=\"%s\"" id) "")))
2405 (concat
2406 (format "<li%s>" extra)
2407 (when headline (concat headline br)))))
2408 (descriptive
2409 (let* ((term term-counter-id))
2410 (setq term (or term "(no term)"))
2411 ;; Check-boxes in descriptive lists are associated to tag.
2412 (concat (format "<dt> %s </dt>"
2413 (concat checkbox term))
2414 "<dd>"))))
2415 (unless (eq type 'descriptive) checkbox)
2416 contents
2417 (case type
2418 (ordered "</li>")
2419 (unordered "</li>")
2420 (descriptive "</dd>")))))
2422 (defun org-html-item (item contents info)
2423 "Transcode an ITEM element from Org to HTML.
2424 CONTENTS holds the contents of the item. INFO is a plist holding
2425 contextual information."
2426 (let* ((plain-list (org-export-get-parent item))
2427 (type (org-element-property :type plain-list))
2428 (counter (org-element-property :counter item))
2429 (checkbox (org-element-property :checkbox item))
2430 (tag (let ((tag (org-element-property :tag item)))
2431 (and tag (org-export-data tag info)))))
2432 (org-html-format-list-item
2433 contents type checkbox info (or tag counter))))
2435 ;;;; Keyword
2437 (defun org-html-keyword (keyword contents info)
2438 "Transcode a KEYWORD element from Org to HTML.
2439 CONTENTS is nil. INFO is a plist holding contextual information."
2440 (let ((key (org-element-property :key keyword))
2441 (value (org-element-property :value keyword)))
2442 (cond
2443 ((string= key "HTML") value)
2444 ((string= key "TOC")
2445 (let ((value (downcase value)))
2446 (cond
2447 ((string-match "\\<headlines\\>" value)
2448 (let ((depth (or (and (string-match "[0-9]+" value)
2449 (string-to-number (match-string 0 value)))
2450 (plist-get info :with-toc))))
2451 (org-html-toc depth info)))
2452 ((string= "listings" value) (org-html-list-of-listings info))
2453 ((string= "tables" value) (org-html-list-of-tables info))))))))
2455 ;;;; Latex Environment
2457 (defun org-html-format-latex (latex-frag processing-type)
2458 "Format a LaTeX fragment LATEX-FRAG into HTML."
2459 (let ((cache-relpath "") (cache-dir ""))
2460 (unless (eq processing-type 'mathjax)
2461 (let ((bfn (or (buffer-file-name)
2462 (make-temp-name
2463 (expand-file-name "latex" temporary-file-directory)))))
2464 (setq cache-relpath
2465 (concat "ltxpng/"
2466 (file-name-sans-extension
2467 (file-name-nondirectory bfn)))
2468 cache-dir (file-name-directory bfn))))
2469 (with-temp-buffer
2470 (insert latex-frag)
2471 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2472 nil nil processing-type)
2473 (buffer-string))))
2475 (defun org-html-latex-environment (latex-environment contents info)
2476 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2477 CONTENTS is nil. INFO is a plist holding contextual information."
2478 (let ((processing-type (plist-get info :with-latex))
2479 (latex-frag (org-remove-indentation
2480 (org-element-property :value latex-environment)))
2481 (caption (org-export-data
2482 (org-export-get-caption latex-environment) info))
2483 (attr nil) ; FIXME
2484 (label (org-element-property :name latex-environment)))
2485 (cond
2486 ((memq processing-type '(t mathjax))
2487 (org-html-format-latex latex-frag 'mathjax))
2488 ((eq processing-type 'dvipng)
2489 (let* ((formula-link (org-html-format-latex
2490 latex-frag processing-type)))
2491 (when (and formula-link
2492 (string-match "file:\\([^]]*\\)" formula-link))
2493 (org-html-format-inline-image
2494 (match-string 1 formula-link) info caption label attr t))))
2495 (t latex-frag))))
2497 ;;;; Latex Fragment
2499 (defun org-html-latex-fragment (latex-fragment contents info)
2500 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2501 CONTENTS is nil. INFO is a plist holding contextual information."
2502 (let ((latex-frag (org-element-property :value latex-fragment))
2503 (processing-type (plist-get info :with-latex)))
2504 (case processing-type
2505 ((t mathjax)
2506 (org-html-format-latex latex-frag 'mathjax))
2507 (dvipng
2508 (let* ((formula-link (org-html-format-latex
2509 latex-frag processing-type)))
2510 (when (and formula-link
2511 (string-match "file:\\([^]]*\\)" formula-link))
2512 (org-html-format-inline-image
2513 (match-string 1 formula-link) info))))
2514 (t latex-frag))))
2516 ;;;; Line Break
2518 (defun org-html-line-break (line-break contents info)
2519 "Transcode a LINE-BREAK object from Org to HTML.
2520 CONTENTS is nil. INFO is a plist holding contextual information."
2521 (concat (org-html-close-tag "br" nil info) "\n"))
2523 ;;;; Link
2525 (defun org-html-link--inline-image (link desc info)
2526 "Return HTML code for an inline image.
2528 LINK is the link pointing to the inline image. INFO is a plist
2529 used as a communication channel.
2531 Inline images can have these attributes:
2533 #+ATTR_HTML: :width 100px :height 100px :alt \"Alt description\"."
2534 (let* ((type (org-element-property :type link))
2535 (raw-path (org-element-property :path link))
2536 (path (cond ((member type '("http" "https"))
2537 (concat type ":" raw-path))
2538 ((file-name-absolute-p raw-path)
2539 (expand-file-name raw-path))
2540 (t raw-path)))
2541 (parent (org-export-get-parent-element link))
2542 (caption
2543 (let ((raw (org-export-data (org-export-get-caption parent) info))
2544 (org-html-standalone-image-predicate 'org-html--has-caption-p))
2545 (if (not (org-string-nw-p raw)) raw
2546 (concat (format (org-html--translate "Figure %d:" info)
2547 (org-export-get-ordinal
2548 link info nil 'org-html-standalone-image-p))
2549 " " raw))))
2550 (label (org-element-property :name parent)))
2551 ;; Return proper string, depending on DISPOSITION.
2552 (org-html-format-inline-image
2553 path info caption label
2554 (org-html--make-attribute-string
2555 (org-export-read-attribute :attr_html parent))
2556 (org-html-standalone-image-p link info))))
2558 (defvar org-html-standalone-image-predicate)
2559 (defun org-html-standalone-image-p (element info &optional predicate)
2560 "Test if ELEMENT is a standalone image for the purpose HTML export.
2561 INFO is a plist holding contextual information.
2563 Return non-nil, if ELEMENT is of type paragraph and it's sole
2564 content, save for whitespaces, is a link that qualifies as an
2565 inline image.
2567 Return non-nil, if ELEMENT is of type link and it's containing
2568 paragraph has no other content save for leading and trailing
2569 whitespaces.
2571 Return nil, otherwise.
2573 Bind `org-html-standalone-image-predicate' to constrain
2574 paragraph further. For example, to check for only captioned
2575 standalone images, do the following.
2577 \(setq org-html-standalone-image-predicate
2578 \(lambda \(paragraph\)
2579 \(org-element-property :caption paragraph\)\)\)"
2580 (let ((paragraph (case (org-element-type element)
2581 (paragraph element)
2582 (link (and (org-export-inline-image-p
2583 element org-html-inline-image-rules)
2584 (org-export-get-parent element)))
2585 (t nil))))
2586 (when (eq (org-element-type paragraph) 'paragraph)
2587 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2588 (functionp org-html-standalone-image-predicate)))
2589 (funcall org-html-standalone-image-predicate paragraph))
2590 (let ((contents (org-element-contents paragraph)))
2591 (loop for x in contents
2592 with inline-image-count = 0
2593 always (cond
2594 ((eq (org-element-type x) 'plain-text)
2595 (not (org-string-nw-p x)))
2596 ((eq (org-element-type x) 'link)
2597 (when (org-export-inline-image-p
2598 x org-html-inline-image-rules)
2599 (= (incf inline-image-count) 1)))
2600 (t nil))))))))
2602 (defun org-html-link (link desc info)
2603 "Transcode a LINK object from Org to HTML.
2605 DESC is the description part of the link, or the empty string.
2606 INFO is a plist holding contextual information. See
2607 `org-export-data'."
2608 (let* ((link-org-files-as-html-maybe
2609 (function
2610 (lambda (raw-path info)
2611 "Treat links to `file.org' as links to `file.html', if needed.
2612 See `org-html-link-org-files-as-html'."
2613 (cond
2614 ((and org-html-link-org-files-as-html
2615 (string= ".org"
2616 (downcase (file-name-extension raw-path "."))))
2617 (concat (file-name-sans-extension raw-path) "."
2618 (plist-get info :html-extension)))
2619 (t raw-path)))))
2620 (type (org-element-property :type link))
2621 (raw-path (org-element-property :path link))
2622 ;; Ensure DESC really exists, or set it to nil.
2623 (desc (org-string-nw-p desc))
2624 (path
2625 (cond
2626 ((member type '("http" "https" "ftp" "mailto"))
2627 (concat type ":" raw-path))
2628 ((string= type "file")
2629 ;; Treat links to ".org" files as ".html", if needed.
2630 (setq raw-path
2631 (funcall link-org-files-as-html-maybe raw-path info))
2632 ;; If file path is absolute, prepend it with protocol
2633 ;; component - "file://".
2634 (when (file-name-absolute-p raw-path)
2635 (setq raw-path
2636 (concat "file://" (expand-file-name raw-path))))
2637 ;; Add search option, if any. A search option can be
2638 ;; relative to a custom-id or a headline title. Any other
2639 ;; option is ignored.
2640 (let ((option (org-element-property :search-option link)))
2641 (cond ((not option) raw-path)
2642 ((eq (aref option 0) ?#) (concat raw-path option))
2643 ;; External fuzzy link: try to resolve it if path
2644 ;; belongs to current project, if any.
2645 ((eq (aref option 0) ?*)
2646 (concat
2647 raw-path
2648 (let ((numbers
2649 (org-publish-resolve-external-fuzzy-link
2650 (org-element-property :path link) option)))
2651 (and numbers (concat "#sec-"
2652 (mapconcat 'number-to-string
2653 numbers "-"))))))
2654 (t raw-path))))
2655 (t raw-path)))
2656 ;; Extract attributes from parent's paragraph. HACK: Only do
2657 ;; this for the first link in parent. This is needed as long
2658 ;; as attributes cannot be set on a per link basis.
2659 (attributes
2660 (let ((parent (org-export-get-parent-element link)))
2661 (if (not (eq (org-element-map parent 'link 'identity info t) link))
2663 (let ((att (org-html--make-attribute-string
2664 (org-export-read-attribute :attr_html parent))))
2665 (cond ((not (org-string-nw-p att)) "")
2666 ((and desc (string-match (regexp-quote att) desc)) "")
2667 (t (concat " " att)))))))
2668 protocol)
2669 (cond
2670 ;; Image file.
2671 ((and (or (eq t org-html-inline-images)
2672 (and org-html-inline-images (not desc)))
2673 (org-export-inline-image-p link org-html-inline-image-rules))
2674 (org-html-link--inline-image link desc info))
2675 ;; Radio target: Transcode target's contents and use them as
2676 ;; link's description.
2677 ((string= type "radio")
2678 (let ((destination (org-export-resolve-radio-link link info)))
2679 (when destination
2680 (format "<a href=\"#%s\"%s>%s</a>"
2681 (org-export-solidify-link-text path)
2682 attributes
2683 (org-export-data (org-element-contents destination) info)))))
2684 ;; Links pointing to a headline: Find destination and build
2685 ;; appropriate referencing command.
2686 ((member type '("custom-id" "fuzzy" "id"))
2687 (let ((destination (if (string= type "fuzzy")
2688 (org-export-resolve-fuzzy-link link info)
2689 (org-export-resolve-id-link link info))))
2690 (case (org-element-type destination)
2691 ;; ID link points to an external file.
2692 (plain-text
2693 (let ((fragment (concat "ID-" path))
2694 ;; Treat links to ".org" files as ".html", if needed.
2695 (path (funcall link-org-files-as-html-maybe
2696 destination info)))
2697 (format "<a href=\"%s#%s\"%s>%s</a>"
2698 path fragment attributes (or desc destination))))
2699 ;; Fuzzy link points nowhere.
2700 ((nil)
2701 (format "<i>%s</i>"
2702 (or desc
2703 (org-export-data
2704 (org-element-property :raw-link link) info))))
2705 ;; Fuzzy link points to an invisible target.
2706 (keyword nil)
2707 ;; Link points to a headline.
2708 (headline
2709 (let ((href
2710 ;; What href to use?
2711 (cond
2712 ;; Case 1: Headline is linked via it's CUSTOM_ID
2713 ;; property. Use CUSTOM_ID.
2714 ((string= type "custom-id")
2715 (org-element-property :CUSTOM_ID destination))
2716 ;; Case 2: Headline is linked via it's ID property
2717 ;; or through other means. Use the default href.
2718 ((member type '("id" "fuzzy"))
2719 (format "sec-%s"
2720 (mapconcat 'number-to-string
2721 (org-export-get-headline-number
2722 destination info) "-")))
2723 (t (error "Shouldn't reach here"))))
2724 ;; What description to use?
2725 (desc
2726 ;; Case 1: Headline is numbered and LINK has no
2727 ;; description. Display section number.
2728 (if (and (org-export-numbered-headline-p destination info)
2729 (not desc))
2730 (mapconcat 'number-to-string
2731 (org-export-get-headline-number
2732 destination info) ".")
2733 ;; Case 2: Either the headline is un-numbered or
2734 ;; LINK has a custom description. Display LINK's
2735 ;; description or headline's title.
2736 (or desc (org-export-data (org-element-property
2737 :title destination) info)))))
2738 (format "<a href=\"#%s\"%s>%s</a>"
2739 (org-export-solidify-link-text href) attributes desc)))
2740 ;; Fuzzy link points to a target. Do as above.
2742 (let ((path (org-export-solidify-link-text path)) number
2743 (org-html-standalone-image-predicate 'org-html--has-caption-p))
2744 (unless desc
2745 (setq number (cond
2746 ((org-html-standalone-image-p destination info)
2747 (org-export-get-ordinal
2748 (assoc 'link (org-element-contents destination))
2749 info 'link 'org-html-standalone-image-p))
2750 (t (org-export-get-ordinal
2751 destination info nil 'org-html--has-caption-p))))
2752 (setq desc (when number
2753 (if (atom number) (number-to-string number)
2754 (mapconcat 'number-to-string number ".")))))
2755 (format "<a href=\"#%s\"%s>%s</a>"
2756 path attributes (or desc "No description for this link")))))))
2757 ;; Coderef: replace link with the reference name or the
2758 ;; equivalent line number.
2759 ((string= type "coderef")
2760 (let ((fragment (concat "coderef-" path)))
2761 (format "<a href=\"#%s\"%s%s>%s</a>"
2762 fragment
2763 (org-trim
2764 (format (concat "class=\"coderef\""
2765 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2766 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2767 fragment fragment))
2768 attributes
2769 (format (org-export-get-coderef-format path desc)
2770 (org-export-resolve-coderef path info)))))
2771 ;; Link type is handled by a special function.
2772 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2773 (funcall protocol (org-link-unescape path) desc 'html))
2774 ;; External link with a description part.
2775 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2776 ;; External link without a description part.
2777 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2778 ;; No path, only description. Try to do something useful.
2779 (t (format "<i>%s</i>" desc)))))
2781 ;;;; Paragraph
2783 (defun org-html-paragraph (paragraph contents info)
2784 "Transcode a PARAGRAPH element from Org to HTML.
2785 CONTENTS is the contents of the paragraph, as a string. INFO is
2786 the plist used as a communication channel."
2787 (let* ((parent (org-export-get-parent paragraph))
2788 (parent-type (org-element-type parent))
2789 (style '((footnote-definition " class=\"footpara\"")))
2790 (extra (or (cadr (assoc parent-type style)) "")))
2791 (cond
2792 ((and (eq (org-element-type parent) 'item)
2793 (= (org-element-property :begin paragraph)
2794 (org-element-property :contents-begin parent)))
2795 ;; leading paragraph in a list item have no tags
2796 contents)
2797 ((org-html-standalone-image-p paragraph info)
2798 ;; standalone image
2799 contents)
2800 (t (format "<p%s>\n%s</p>" extra contents)))))
2802 ;;;; Plain List
2804 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2805 ;; the correct value for the item counter
2806 (defun org-html-begin-plain-list (type &optional arg1)
2807 "Insert the beginning of the HTML list depending on TYPE.
2808 When ARG1 is a string, use it as the start parameter for ordered
2809 lists."
2810 (case type
2811 (ordered
2812 (format "<ol class=\"org-ol\"%s>"
2813 (if arg1 (format " start=\"%d\"" arg1) "")))
2814 (unordered "<ul class=\"org-ul\">")
2815 (descriptive "<dl class=\"org-dl\">")))
2817 (defun org-html-end-plain-list (type)
2818 "Insert the end of the HTML list depending on TYPE."
2819 (case type
2820 (ordered "</ol>")
2821 (unordered "</ul>")
2822 (descriptive "</dl>")))
2824 (defun org-html-plain-list (plain-list contents info)
2825 "Transcode a PLAIN-LIST element from Org to HTML.
2826 CONTENTS is the contents of the list. INFO is a plist holding
2827 contextual information."
2828 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2829 (type (org-element-property :type plain-list)))
2830 (format "%s\n%s%s"
2831 (org-html-begin-plain-list type)
2832 contents (org-html-end-plain-list type))))
2834 ;;;; Plain Text
2836 (defun org-html-convert-special-strings (string)
2837 "Convert special characters in STRING to HTML."
2838 (let ((all org-html-special-string-regexps)
2839 e a re rpl start)
2840 (while (setq a (pop all))
2841 (setq re (car a) rpl (cdr a) start 0)
2842 (while (string-match re string start)
2843 (setq string (replace-match rpl t nil string))))
2844 string))
2846 (defun org-html-encode-plain-text (text)
2847 "Convert plain text characters from TEXT to HTML equivalent.
2848 Possible conversions are set in `org-html-protect-char-alist'."
2849 (mapc
2850 (lambda (pair)
2851 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2852 org-html-protect-char-alist)
2853 text)
2855 (defun org-html-plain-text (text info)
2856 "Transcode a TEXT string from Org to HTML.
2857 TEXT is the string to transcode. INFO is a plist holding
2858 contextual information."
2859 (let ((output text))
2860 ;; Protect following characters: <, >, &.
2861 (setq output (org-html-encode-plain-text output))
2862 ;; Handle smart quotes. Be sure to provide original string since
2863 ;; OUTPUT may have been modified.
2864 (when (plist-get info :with-smart-quotes)
2865 (setq output (org-export-activate-smart-quotes output :html info text)))
2866 ;; Handle special strings.
2867 (when (plist-get info :with-special-strings)
2868 (setq output (org-html-convert-special-strings output)))
2869 ;; Handle break preservation if required.
2870 (when (plist-get info :preserve-breaks)
2871 (setq output
2872 (replace-regexp-in-string
2873 "\\(\\\\\\\\\\)?[ \t]*\n"
2874 (concat (org-html-close-tag "br" nil info) "\n") output)))
2875 ;; Return value.
2876 output))
2879 ;; Planning
2881 (defun org-html-planning (planning contents info)
2882 "Transcode a PLANNING element from Org to HTML.
2883 CONTENTS is nil. INFO is a plist used as a communication
2884 channel."
2885 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2886 (format
2887 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2888 (mapconcat
2889 'identity
2890 (delq nil
2891 (list
2892 (let ((closed (org-element-property :closed planning)))
2893 (when closed
2894 (format span-fmt org-closed-string
2895 (org-translate-time
2896 (org-element-property :raw-value closed)))))
2897 (let ((deadline (org-element-property :deadline planning)))
2898 (when deadline
2899 (format span-fmt org-deadline-string
2900 (org-translate-time
2901 (org-element-property :raw-value deadline)))))
2902 (let ((scheduled (org-element-property :scheduled planning)))
2903 (when scheduled
2904 (format span-fmt org-scheduled-string
2905 (org-translate-time
2906 (org-element-property :raw-value scheduled)))))))
2907 " "))))
2909 ;;;; Property Drawer
2911 (defun org-html-property-drawer (property-drawer contents info)
2912 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2913 CONTENTS is nil. INFO is a plist holding contextual
2914 information."
2915 ;; The property drawer isn't exported but we want separating blank
2916 ;; lines nonetheless.
2919 ;;;; Quote Block
2921 (defun org-html-quote-block (quote-block contents info)
2922 "Transcode a QUOTE-BLOCK element from Org to HTML.
2923 CONTENTS holds the contents of the block. INFO is a plist
2924 holding contextual information."
2925 (format "<blockquote>\n%s</blockquote>" contents))
2927 ;;;; Quote Section
2929 (defun org-html-quote-section (quote-section contents info)
2930 "Transcode a QUOTE-SECTION element from Org to HTML.
2931 CONTENTS is nil. INFO is a plist holding contextual information."
2932 (let ((value (org-remove-indentation
2933 (org-element-property :value quote-section))))
2934 (when value (format "<pre>\n%s</pre>" value))))
2936 ;;;; Section
2938 (defun org-html-section (section contents info)
2939 "Transcode a SECTION element from Org to HTML.
2940 CONTENTS holds the contents of the section. INFO is a plist
2941 holding contextual information."
2942 (let ((parent (org-export-get-parent-headline section)))
2943 ;; Before first headline: no container, just return CONTENTS.
2944 (if (not parent) contents
2945 ;; Get div's class and id references.
2946 (let* ((class-num (+ (org-export-get-relative-level parent info)
2947 (1- org-html-toplevel-hlevel)))
2948 (section-number
2949 (mapconcat
2950 'number-to-string
2951 (org-export-get-headline-number parent info) "-")))
2952 ;; Build return value.
2953 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2954 class-num
2955 (or (org-element-property :CUSTOM_ID parent) section-number)
2956 contents)))))
2958 ;;;; Radio Target
2960 (defun org-html-radio-target (radio-target text info)
2961 "Transcode a RADIO-TARGET object from Org to HTML.
2962 TEXT is the text of the target. INFO is a plist holding
2963 contextual information."
2964 (let ((id (org-export-solidify-link-text
2965 (org-element-property :value radio-target))))
2966 (org-html--anchor id text)))
2968 ;;;; Special Block
2970 (defun org-html-special-block (special-block contents info)
2971 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2972 CONTENTS holds the contents of the block. INFO is a plist
2973 holding contextual information."
2974 (let* ((block-type (downcase
2975 (org-element-property :type special-block)))
2976 (contents (or contents ""))
2977 (html5-fancy (and (org-html-html5-p info)
2978 (plist-get info :html-html5-fancy)
2979 (member block-type org-html-html5-elements)))
2980 (attributes (org-export-read-attribute :attr_html special-block)))
2981 (unless html5-fancy
2982 (let ((class (plist-get attributes :class)))
2983 (setq attributes (plist-put attributes :class
2984 (if class (concat class " " block-type)
2985 block-type)))))
2986 (setq attributes (org-html--make-attribute-string attributes))
2987 (when (not (equal attributes ""))
2988 (setq attributes (concat " " attributes)))
2989 (if html5-fancy
2990 (format "<%s%s>\n%s</%s>" block-type attributes
2991 contents block-type)
2992 (format "<div%s>\n%s\n</div>" attributes contents))))
2994 ;;;; Src Block
2996 (defun org-html-src-block (src-block contents info)
2997 "Transcode a SRC-BLOCK element from Org to HTML.
2998 CONTENTS holds the contents of the item. INFO is a plist holding
2999 contextual information."
3000 (if (org-export-read-attribute :attr_html src-block :textarea)
3001 (org-html--textarea-block src-block)
3002 (let ((lang (org-element-property :language src-block))
3003 (caption (org-export-get-caption src-block))
3004 (code (org-html-format-code src-block info))
3005 (label (let ((lbl (org-element-property :name src-block)))
3006 (if (not lbl) ""
3007 (format " id=\"%s\""
3008 (org-export-solidify-link-text lbl))))))
3009 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3010 (format
3011 "<div class=\"org-src-container\">\n%s%s\n</div>"
3012 (if (not caption) ""
3013 (format "<label class=\"org-src-name\">%s</label>"
3014 (org-export-data caption info)))
3015 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3017 ;;;; Statistics Cookie
3019 (defun org-html-statistics-cookie (statistics-cookie contents info)
3020 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3021 CONTENTS is nil. INFO is a plist holding contextual information."
3022 (let ((cookie-value (org-element-property :value statistics-cookie)))
3023 (format "<code>%s</code>" cookie-value)))
3025 ;;;; Strike-Through
3027 (defun org-html-strike-through (strike-through contents info)
3028 "Transcode STRIKE-THROUGH from Org to HTML.
3029 CONTENTS is the text with strike-through markup. INFO is a plist
3030 holding contextual information."
3031 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3032 contents))
3034 ;;;; Subscript
3036 (defun org-html-subscript (subscript contents info)
3037 "Transcode a SUBSCRIPT object from Org to HTML.
3038 CONTENTS is the contents of the object. INFO is a plist holding
3039 contextual information."
3040 (format "<sub>%s</sub>" contents))
3042 ;;;; Superscript
3044 (defun org-html-superscript (superscript contents info)
3045 "Transcode a SUPERSCRIPT object from Org to HTML.
3046 CONTENTS is the contents of the object. INFO is a plist holding
3047 contextual information."
3048 (format "<sup>%s</sup>" contents))
3050 ;;;; Tabel Cell
3052 (defun org-html-table-cell (table-cell contents info)
3053 "Transcode a TABLE-CELL element from Org to HTML.
3054 CONTENTS is nil. INFO is a plist used as a communication
3055 channel."
3056 (let* ((table-row (org-export-get-parent table-cell))
3057 (table (org-export-get-parent-table table-cell))
3058 (cell-attrs
3059 (if (not org-html-table-align-individual-fields) ""
3060 (format (if (and (boundp 'org-html-format-table-no-css)
3061 org-html-format-table-no-css)
3062 " align=\"%s\"" " class=\"%s\"")
3063 (org-export-table-cell-alignment table-cell info)))))
3064 (when (or (not contents) (string= "" (org-trim contents)))
3065 (setq contents "&#xa0;"))
3066 (cond
3067 ((and (org-export-table-has-header-p table info)
3068 (= 1 (org-export-table-row-group table-row info)))
3069 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3070 contents (cdr org-html-table-header-tags)))
3071 ((and org-html-table-use-header-tags-for-first-column
3072 (zerop (cdr (org-export-table-cell-address table-cell info))))
3073 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3074 contents (cdr org-html-table-header-tags)))
3075 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3076 contents (cdr org-html-table-data-tags))))))
3078 ;;;; Table Row
3080 (defun org-html-table-row (table-row contents info)
3081 "Transcode a TABLE-ROW element from Org to HTML.
3082 CONTENTS is the contents of the row. INFO is a plist used as a
3083 communication channel."
3084 ;; Rules are ignored since table separators are deduced from
3085 ;; borders of the current row.
3086 (when (eq (org-element-property :type table-row) 'standard)
3087 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3088 (row-number (org-export-table-row-number table-row info))
3089 (start-rowgroup-p
3090 (org-export-table-row-starts-rowgroup-p table-row info))
3091 (end-rowgroup-p
3092 (org-export-table-row-ends-rowgroup-p table-row info))
3093 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3094 ;; but should be set so that `org-html-table-row-tags' can
3095 ;; use them (see the docstring of this variable.)
3096 (top-row-p (and (equal start-rowgroup-p '(top))
3097 (equal end-rowgroup-p '(below top))))
3098 (bottom-row-p (and (equal start-rowgroup-p '(above))
3099 (equal end-rowgroup-p '(bottom above))))
3100 (rowgroup-tags
3101 (cond
3102 ;; Case 1: Row belongs to second or subsequent rowgroups.
3103 ((not (= 1 rowgroup-number))
3104 '("<tbody>" . "\n</tbody>"))
3105 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3106 ((org-export-table-has-header-p
3107 (org-export-get-parent-table table-row) info)
3108 '("<thead>" . "\n</thead>"))
3109 ;; Case 2: Row is from first and only row group.
3110 (t '("<tbody>" . "\n</tbody>")))))
3111 (concat
3112 ;; Begin a rowgroup?
3113 (when start-rowgroup-p (car rowgroup-tags))
3114 ;; Actual table row
3115 (concat "\n" (eval (car org-html-table-row-tags))
3116 contents
3117 "\n"
3118 (eval (cdr org-html-table-row-tags)))
3119 ;; End a rowgroup?
3120 (when end-rowgroup-p (cdr rowgroup-tags))))))
3122 ;;;; Table
3124 (defun org-html-table-first-row-data-cells (table info)
3125 "Transcode the first row of TABLE.
3126 INFO is a plist used as a communication channel."
3127 (let ((table-row
3128 (org-element-map table 'table-row
3129 (lambda (row)
3130 (unless (eq (org-element-property :type row) 'rule) row))
3131 info 'first-match))
3132 (special-column-p (org-export-table-has-special-column-p table)))
3133 (if (not special-column-p) (org-element-contents table-row)
3134 (cdr (org-element-contents table-row)))))
3136 (defun org-html-table--table.el-table (table info)
3137 "Format table.el tables into HTML.
3138 INFO is a plist used as a communication channel."
3139 (when (eq (org-element-property :type table) 'table.el)
3140 (require 'table)
3141 (let ((outbuf (with-current-buffer
3142 (get-buffer-create "*org-export-table*")
3143 (erase-buffer) (current-buffer))))
3144 (with-temp-buffer
3145 (insert (org-element-property :value table))
3146 (goto-char 1)
3147 (re-search-forward "^[ \t]*|[^|]" nil t)
3148 (table-generate-source 'html outbuf))
3149 (with-current-buffer outbuf
3150 (prog1 (org-trim (buffer-string))
3151 (kill-buffer) )))))
3153 (defun org-html-table (table contents info)
3154 "Transcode a TABLE element from Org to HTML.
3155 CONTENTS is the contents of the table. INFO is a plist holding
3156 contextual information."
3157 (case (org-element-property :type table)
3158 ;; Case 1: table.el table. Convert it using appropriate tools.
3159 (table.el (org-html-table--table.el-table table info))
3160 ;; Case 2: Standard table.
3162 (let* ((label (org-element-property :name table))
3163 (caption (org-export-get-caption table))
3164 (number (org-export-get-ordinal
3165 table info nil 'org-html--has-caption-p))
3166 (attributes
3167 (if (org-html-html5-p info) ""
3168 (org-html--make-attribute-string
3169 (org-combine-plists
3170 (and label (list :id (org-export-solidify-link-text label)))
3171 (plist-get info :html-table-attributes)
3172 (org-export-read-attribute :attr_html table)))))
3173 (alignspec
3174 (if (and (boundp 'org-html-format-table-no-css)
3175 org-html-format-table-no-css)
3176 "align=\"%s\"" "class=\"%s\""))
3177 (table-column-specs
3178 (function
3179 (lambda (table info)
3180 (mapconcat
3181 (lambda (table-cell)
3182 (let ((alignment (org-export-table-cell-alignment
3183 table-cell info)))
3184 (concat
3185 ;; Begin a colgroup?
3186 (when (org-export-table-cell-starts-colgroup-p
3187 table-cell info)
3188 "\n<colgroup>")
3189 ;; Add a column. Also specify it's alignment.
3190 (format "\n%s"
3191 (org-html-close-tag
3192 "col" (concat " " (format alignspec alignment)) info))
3193 ;; End a colgroup?
3194 (when (org-export-table-cell-ends-colgroup-p
3195 table-cell info)
3196 "\n</colgroup>"))))
3197 (org-html-table-first-row-data-cells table info) "\n")))))
3198 (format "<table%s>\n%s\n%s\n%s</table>"
3199 (if (equal attributes "") "" (concat " " attributes))
3200 (if (not caption) ""
3201 (format (if org-html-table-caption-above
3202 "<caption align=\"above\">%s</caption>"
3203 "<caption align=\"bottom\">%s</caption>")
3204 (concat
3205 (format (org-html--translate "Table %d:" info) number)
3206 " " (org-export-data caption info))))
3207 (funcall table-column-specs table info)
3208 contents)))))
3210 ;;;; Target
3212 (defun org-html-target (target contents info)
3213 "Transcode a TARGET object from Org to HTML.
3214 CONTENTS is nil. INFO is a plist holding contextual
3215 information."
3216 (let ((id (org-export-solidify-link-text
3217 (org-element-property :value target))))
3218 (org-html--anchor id)))
3220 ;;;; Timestamp
3222 (defun org-html-timestamp (timestamp contents info)
3223 "Transcode a TIMESTAMP object from Org to HTML.
3224 CONTENTS is nil. INFO is a plist holding contextual
3225 information."
3226 (let ((value (org-html-plain-text
3227 (org-timestamp-translate timestamp) info)))
3228 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3229 (replace-regexp-in-string "--" "&#x2013;" value))))
3231 ;;;; Underline
3233 (defun org-html-underline (underline contents info)
3234 "Transcode UNDERLINE from Org to HTML.
3235 CONTENTS is the text with underline markup. INFO is a plist
3236 holding contextual information."
3237 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3238 contents))
3240 ;;;; Verbatim
3242 (defun org-html-verbatim (verbatim contents info)
3243 "Transcode VERBATIM from Org to HTML.
3244 CONTENTS is nil. INFO is a plist holding contextual
3245 information."
3246 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3247 (org-html-encode-plain-text (org-element-property :value verbatim))))
3249 ;;;; Verse Block
3251 (defun org-html-verse-block (verse-block contents info)
3252 "Transcode a VERSE-BLOCK element from Org to HTML.
3253 CONTENTS is verse block contents. INFO is a plist holding
3254 contextual information."
3255 ;; Replace each newline character with line break. Also replace
3256 ;; each blank line with a line break.
3257 (setq contents (replace-regexp-in-string
3258 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3259 (replace-regexp-in-string
3260 "\\(\\\\\\\\\\)?[ \t]*\n"
3261 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3262 ;; Replace each white space at beginning of a line with a
3263 ;; non-breaking space.
3264 (while (string-match "^[ \t]+" contents)
3265 (let* ((num-ws (length (match-string 0 contents)))
3266 (ws (let (out) (dotimes (i num-ws out)
3267 (setq out (concat out "&#xa0;"))))))
3268 (setq contents (replace-match ws nil t contents))))
3269 (format "<p class=\"verse\">\n%s</p>" contents))
3272 ;;; Filter Functions
3274 (defun org-html-final-function (contents backend info)
3275 "Filter to indent the HTML and convert HTML entities."
3276 (with-temp-buffer
3277 (insert contents)
3278 (set-auto-mode t)
3279 (if org-html-indent
3280 (indent-region (point-min) (point-max)))
3281 (when org-html-use-unicode-chars
3282 (require 'mm-url)
3283 (mm-url-decode-entities))
3284 (buffer-substring-no-properties (point-min) (point-max))))
3287 ;;; End-user functions
3289 ;;;###autoload
3290 (defun org-html-export-as-html
3291 (&optional async subtreep visible-only body-only ext-plist)
3292 "Export current buffer to an HTML buffer.
3294 If narrowing is active in the current buffer, only export its
3295 narrowed part.
3297 If a region is active, export that region.
3299 A non-nil optional argument ASYNC means the process should happen
3300 asynchronously. The resulting buffer should be accessible
3301 through the `org-export-stack' interface.
3303 When optional argument SUBTREEP is non-nil, export the sub-tree
3304 at point, extracting information from the headline properties
3305 first.
3307 When optional argument VISIBLE-ONLY is non-nil, don't export
3308 contents of hidden elements.
3310 When optional argument BODY-ONLY is non-nil, only write code
3311 between \"<body>\" and \"</body>\" tags.
3313 EXT-PLIST, when provided, is a property list with external
3314 parameters overriding Org default settings, but still inferior to
3315 file-local settings.
3317 Export is done in a buffer named \"*Org HTML Export*\", which
3318 will be displayed when `org-export-show-temporary-export-buffer'
3319 is non-nil."
3320 (interactive)
3321 (if async
3322 (org-export-async-start
3323 (lambda (output)
3324 (with-current-buffer (get-buffer-create "*Org HTML Export*")
3325 (erase-buffer)
3326 (insert output)
3327 (goto-char (point-min))
3328 (set-auto-mode t)
3329 (org-export-add-to-stack (current-buffer) 'html)))
3330 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
3331 (let ((outbuf (org-export-to-buffer
3332 'html "*Org HTML Export*"
3333 subtreep visible-only body-only ext-plist)))
3334 ;; Set major mode.
3335 (with-current-buffer outbuf (set-auto-mode t))
3336 (when org-export-show-temporary-export-buffer
3337 (switch-to-buffer-other-window outbuf)))))
3339 ;;;###autoload
3340 (defun org-html-convert-region-to-html ()
3341 "Assume the current region has org-mode syntax, and convert it to HTML.
3342 This can be used in any buffer. For example, you can write an
3343 itemized list in org-mode syntax in an HTML buffer and use this
3344 command to convert it."
3345 (interactive)
3346 (org-export-replace-region-by 'html))
3348 ;;;###autoload
3349 (defun org-html-export-to-html
3350 (&optional async subtreep visible-only body-only ext-plist)
3351 "Export current buffer to a HTML file.
3353 If narrowing is active in the current buffer, only export its
3354 narrowed part.
3356 If a region is active, export that region.
3358 A non-nil optional argument ASYNC means the process should happen
3359 asynchronously. The resulting file should be accessible through
3360 the `org-export-stack' interface.
3362 When optional argument SUBTREEP is non-nil, export the sub-tree
3363 at point, extracting information from the headline properties
3364 first.
3366 When optional argument VISIBLE-ONLY is non-nil, don't export
3367 contents of hidden elements.
3369 When optional argument BODY-ONLY is non-nil, only write code
3370 between \"<body>\" and \"</body>\" tags.
3372 EXT-PLIST, when provided, is a property list with external
3373 parameters overriding Org default settings, but still inferior to
3374 file-local settings.
3376 Return output file's name."
3377 (interactive)
3378 (let* ((extension (concat "." org-html-extension))
3379 (file (org-export-output-file-name extension subtreep))
3380 (org-export-coding-system org-html-coding-system))
3381 (if async
3382 (org-export-async-start
3383 (lambda (f) (org-export-add-to-stack f 'html))
3384 (let ((org-export-coding-system org-html-coding-system))
3385 `(expand-file-name
3386 (org-export-to-file
3387 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
3388 (let ((org-export-coding-system org-html-coding-system))
3389 (org-export-to-file
3390 'html file subtreep visible-only body-only ext-plist)))))
3392 ;;;###autoload
3393 (defun org-html-publish-to-html (plist filename pub-dir)
3394 "Publish an org file to HTML.
3396 FILENAME is the filename of the Org file to be published. PLIST
3397 is the property list for the given project. PUB-DIR is the
3398 publishing directory.
3400 Return output file name."
3401 (org-publish-org-to 'html filename
3402 (concat "." (or (plist-get plist :html-extension)
3403 org-html-extension "html"))
3404 plist pub-dir))
3407 ;;; FIXME
3409 ;;;; org-format-table-html
3410 ;;;; org-format-org-table-html
3411 ;;;; org-format-table-table-html
3412 ;;;; org-table-number-fraction
3413 ;;;; org-table-number-regexp
3414 ;;;; org-html-inline-image-extensions
3415 ;;;; org-export-preferred-target-alist
3416 ;;;; class for anchors
3417 ;;;; org-export-mark-todo-in-toc
3418 ;;;; org-html-format-org-link
3419 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3420 ;;;; alt = (file-name-nondirectory path)
3422 (provide 'ox-html)
3424 ;; Local variables:
3425 ;; generated-autoload-file: "org-loaddefs.el"
3426 ;; End:
3428 ;;; ox-html.el ends here