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