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