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