Merge from emacs-24; up to 2014-07-16T17:06:12Z!rgm@gnu.org
[emacs.git] / lisp / org / ox-html.el
blob21f34810f152be6eb24066e0da18a9e5e19ce2fd
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2014 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Jambunathan K <kjambunathan at gmail dot com>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; See Org manual for more information.
29 ;;; Code:
31 ;;; Dependencies
33 (require 'ox)
34 (require 'ox-publish)
35 (require 'format-spec)
36 (eval-when-compile (require 'cl) (require 'table nil 'noerror))
39 ;;; Function Declarations
41 (declare-function org-id-find-id-file "org-id" (id))
42 (declare-function htmlize-region "ext:htmlize" (beg end))
43 (declare-function org-pop-to-buffer-same-window
44 "org-compat" (&optional buffer-or-name norecord label))
45 (declare-function mm-url-decode-entities "mm-url" ())
47 ;;; Define Back-End
49 (org-export-define-backend 'html
50 '((bold . org-html-bold)
51 (center-block . org-html-center-block)
52 (clock . org-html-clock)
53 (code . org-html-code)
54 (drawer . org-html-drawer)
55 (dynamic-block . org-html-dynamic-block)
56 (entity . org-html-entity)
57 (example-block . org-html-example-block)
58 (export-block . org-html-export-block)
59 (export-snippet . org-html-export-snippet)
60 (fixed-width . org-html-fixed-width)
61 (footnote-definition . org-html-footnote-definition)
62 (footnote-reference . org-html-footnote-reference)
63 (headline . org-html-headline)
64 (horizontal-rule . org-html-horizontal-rule)
65 (inline-src-block . org-html-inline-src-block)
66 (inlinetask . org-html-inlinetask)
67 (inner-template . org-html-inner-template)
68 (italic . org-html-italic)
69 (item . org-html-item)
70 (keyword . org-html-keyword)
71 (latex-environment . org-html-latex-environment)
72 (latex-fragment . org-html-latex-fragment)
73 (line-break . org-html-line-break)
74 (link . org-html-link)
75 (paragraph . org-html-paragraph)
76 (plain-list . org-html-plain-list)
77 (plain-text . org-html-plain-text)
78 (planning . org-html-planning)
79 (property-drawer . org-html-property-drawer)
80 (quote-block . org-html-quote-block)
81 (quote-section . org-html-quote-section)
82 (radio-target . org-html-radio-target)
83 (section . org-html-section)
84 (special-block . org-html-special-block)
85 (src-block . org-html-src-block)
86 (statistics-cookie . org-html-statistics-cookie)
87 (strike-through . org-html-strike-through)
88 (subscript . org-html-subscript)
89 (superscript . org-html-superscript)
90 (table . org-html-table)
91 (table-cell . org-html-table-cell)
92 (table-row . org-html-table-row)
93 (target . org-html-target)
94 (template . org-html-template)
95 (timestamp . org-html-timestamp)
96 (underline . org-html-underline)
97 (verbatim . org-html-verbatim)
98 (verse-block . org-html-verse-block))
99 :export-block "HTML"
100 :filters-alist '((:filter-options . org-html-infojs-install-script)
101 (:filter-final-output . org-html-final-function))
102 :menu-entry
103 '(?h "Export to HTML"
104 ((?H "As HTML buffer" org-html-export-as-html)
105 (?h "As HTML file" org-html-export-to-html)
106 (?o "As HTML file and open"
107 (lambda (a s v b)
108 (if a (org-html-export-to-html t s v b)
109 (org-open-file (org-html-export-to-html nil s v b)))))))
110 :options-alist
111 '((:html-extension nil nil org-html-extension)
112 (:html-link-org-as-html nil nil org-html-link-org-files-as-html)
113 (:html-doctype "HTML_DOCTYPE" nil org-html-doctype)
114 (:html-container "HTML_CONTAINER" nil org-html-container-element)
115 (:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
116 (:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
117 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
118 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
119 (:html-mathjax "HTML_MATHJAX" nil "" space)
120 (:html-postamble nil "html-postamble" org-html-postamble)
121 (:html-preamble nil "html-preamble" org-html-preamble)
122 (:html-head "HTML_HEAD" nil org-html-head newline)
123 (:html-head-extra "HTML_HEAD_EXTRA" nil org-html-head-extra newline)
124 (:html-head-include-default-style nil "html-style" org-html-head-include-default-style)
125 (:html-head-include-scripts nil "html-scripts" org-html-head-include-scripts)
126 (:html-table-attributes nil nil org-html-table-default-attributes)
127 (:html-table-row-tags nil nil org-html-table-row-tags)
128 (:html-xml-declaration nil nil org-html-xml-declaration)
129 (:html-inline-images nil nil org-html-inline-images)
130 (:infojs-opt "INFOJS_OPT" nil nil)
131 ;; Redefine regular options.
132 (:creator "CREATOR" nil org-html-creator-string)
133 (:with-latex nil "tex" org-html-with-latex)
134 ;; Retrieve LaTeX header for fragments.
135 (:latex-header "LATEX_HEADER" nil nil newline)))
138 ;;; Internal Variables
140 (defvar org-html-format-table-no-css)
141 (defvar htmlize-buffer-places) ; from htmlize.el
143 (defvar org-html--pre/postamble-class "status"
144 "CSS class used for pre/postamble")
146 (defconst org-html-doctype-alist
147 '(("html4-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
148 \"http://www.w3.org/TR/html4/strict.dtd\">")
149 ("html4-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
150 \"http://www.w3.org/TR/html4/loose.dtd\">")
151 ("html4-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"
152 \"http://www.w3.org/TR/html4/frameset.dtd\">")
154 ("xhtml-strict" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
155 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">")
156 ("xhtml-transitional" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
157 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">")
158 ("xhtml-frameset" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"
159 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">")
160 ("xhtml-11" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
161 \"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd\">")
163 ("html5" . "<!DOCTYPE html>")
164 ("xhtml5" . "<!DOCTYPE html>"))
165 "An alist mapping (x)html flavors to specific doctypes.")
167 (defconst org-html-html5-elements
168 '("article" "aside" "audio" "canvas" "details" "figcaption"
169 "figure" "footer" "header" "menu" "meter" "nav" "output"
170 "progress" "section" "video")
171 "New elements in html5.
173 For blocks that should contain headlines, use the HTML_CONTAINER
174 property on the headline itself.")
176 (defconst org-html-special-string-regexps
177 '(("\\\\-" . "&#x00ad;") ; shy
178 ("---\\([^-]\\)" . "&#x2014;\\1") ; mdash
179 ("--\\([^-]\\)" . "&#x2013;\\1") ; ndash
180 ("\\.\\.\\." . "&#x2026;")) ; hellip
181 "Regular expressions for special string conversion.")
183 (defconst org-html-scripts
184 "<script type=\"text/javascript\">
186 @licstart The following is the entire license notice for the
187 JavaScript code in this tag.
189 Copyright (C) 2012-2013 Free Software Foundation, Inc.
191 The JavaScript code in this tag is free software: you can
192 redistribute it and/or modify it under the terms of the GNU
193 General Public License (GNU GPL) as published by the Free Software
194 Foundation, either version 3 of the License, or (at your option)
195 any later version. The code is distributed WITHOUT ANY WARRANTY;
196 without even the implied warranty of MERCHANTABILITY or FITNESS
197 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
199 As additional permission under GNU GPL version 3 section 7, you
200 may distribute non-source (e.g., minimized or compacted) forms of
201 that code without the copy of the GNU GPL normally required by
202 section 4, provided you include this license notice and a URL
203 through which recipients can access the Corresponding Source.
206 @licend The above is the entire license notice
207 for the JavaScript code in this tag.
209 <!--/*--><![CDATA[/*><!--*/
210 function CodeHighlightOn(elem, id)
212 var target = document.getElementById(id);
213 if(null != target) {
214 elem.cacheClassElem = elem.className;
215 elem.cacheClassTarget = target.className;
216 target.className = \"code-highlighted\";
217 elem.className = \"code-highlighted\";
220 function CodeHighlightOff(elem, id)
222 var target = document.getElementById(id);
223 if(elem.cacheClassElem)
224 elem.className = elem.cacheClassElem;
225 if(elem.cacheClassTarget)
226 target.className = elem.cacheClassTarget;
228 /*]]>*///-->
229 </script>"
230 "Basic JavaScript that is needed by HTML files produced by Org mode.")
232 (defconst org-html-style-default
233 "<style type=\"text/css\">
234 <!--/*--><![CDATA[/*><!--*/
235 .title { text-align: center; }
236 .todo { font-family: monospace; color: red; }
237 .done { color: green; }
238 .tag { background-color: #eee; font-family: monospace;
239 padding: 2px; font-size: 80%; font-weight: normal; }
240 .timestamp { color: #bebebe; }
241 .timestamp-kwd { color: #5f9ea0; }
242 .right { margin-left: auto; margin-right: 0px; text-align: right; }
243 .left { margin-left: 0px; margin-right: auto; text-align: left; }
244 .center { margin-left: auto; margin-right: auto; text-align: center; }
245 .underline { text-decoration: underline; }
246 #postamble p, #preamble p { font-size: 90%; margin: .2em; }
247 p.verse { margin-left: 3%; }
248 pre {
249 border: 1px solid #ccc;
250 box-shadow: 3px 3px 3px #eee;
251 padding: 8pt;
252 font-family: monospace;
253 overflow: auto;
254 margin: 1.2em;
256 pre.src {
257 position: relative;
258 overflow: visible;
259 padding-top: 1.2em;
261 pre.src:before {
262 display: none;
263 position: absolute;
264 background-color: white;
265 top: -10px;
266 right: 10px;
267 padding: 3px;
268 border: 1px solid black;
270 pre.src:hover:before { display: inline;}
271 pre.src-sh:before { content: 'sh'; }
272 pre.src-bash:before { content: 'sh'; }
273 pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
274 pre.src-R:before { content: 'R'; }
275 pre.src-perl:before { content: 'Perl'; }
276 pre.src-java:before { content: 'Java'; }
277 pre.src-sql:before { content: 'SQL'; }
279 table { border-collapse:collapse; }
280 caption.t-above { caption-side: top; }
281 caption.t-bottom { caption-side: bottom; }
282 td, th { vertical-align:top; }
283 th.right { text-align: center; }
284 th.left { text-align: center; }
285 th.center { text-align: center; }
286 td.right { text-align: right; }
287 td.left { text-align: left; }
288 td.center { text-align: center; }
289 dt { font-weight: bold; }
290 .footpara:nth-child(2) { display: inline; }
291 .footpara { display: block; }
292 .footdef { margin-bottom: 1em; }
293 .figure { padding: 1em; }
294 .figure p { text-align: center; }
295 .inlinetask {
296 padding: 10px;
297 border: 2px solid gray;
298 margin: 10px;
299 background: #ffffcc;
301 #org-div-home-and-up
302 { text-align: right; font-size: 70%; white-space: nowrap; }
303 textarea { overflow-x: auto; }
304 .linenr { font-size: smaller }
305 .code-highlighted { background-color: #ffff00; }
306 .org-info-js_info-navigation { border-style: none; }
307 #org-info-js_console-label
308 { font-size: 10px; font-weight: bold; white-space: nowrap; }
309 .org-info-js_search-highlight
310 { background-color: #ffff00; color: #000000; font-weight: bold; }
311 /*]]>*/-->
312 </style>"
313 "The default style specification for exported HTML files.
314 You can use `org-html-head' and `org-html-head-extra' to add to
315 this style. If you don't want to include this default style,
316 customize `org-html-head-include-default-style'.")
319 ;;; User Configuration Variables
321 (defgroup org-export-html nil
322 "Options for exporting Org mode files to HTML."
323 :tag "Org Export HTML"
324 :group 'org-export)
326 ;;;; Handle infojs
328 (defvar org-html-infojs-opts-table
329 '((path PATH "http://orgmode.org/org-info.js")
330 (view VIEW "info")
331 (toc TOC :with-toc)
332 (ftoc FIXED_TOC "0")
333 (tdepth TOC_DEPTH "max")
334 (sdepth SECTION_DEPTH "max")
335 (mouse MOUSE_HINT "underline")
336 (buttons VIEW_BUTTONS "0")
337 (ltoc LOCAL_TOC "1")
338 (up LINK_UP :html-link-up)
339 (home LINK_HOME :html-link-home))
340 "JavaScript options, long form for script, default values.")
342 (defcustom org-html-use-infojs 'when-configured
343 "Non-nil when Sebastian Rose's Java Script org-info.js should be active.
344 This option can be nil or t to never or always use the script.
345 It can also be the symbol `when-configured', meaning that the
346 script will be linked into the export file if and only if there
347 is a \"#+INFOJS_OPT:\" line in the buffer. See also the variable
348 `org-html-infojs-options'."
349 :group 'org-export-html
350 :version "24.4"
351 :package-version '(Org . "8.0")
352 :type '(choice
353 (const :tag "Never" nil)
354 (const :tag "When configured in buffer" when-configured)
355 (const :tag "Always" t)))
357 (defcustom org-html-infojs-options
358 (mapcar (lambda (x) (cons (car x) (nth 2 x))) org-html-infojs-opts-table)
359 "Options settings for the INFOJS JavaScript.
360 Each of the options must have an entry in `org-html-infojs-opts-table'.
361 The value can either be a string that will be passed to the script, or
362 a property. This property is then assumed to be a property that is defined
363 by the Export/Publishing setup of Org.
364 The `sdepth' and `tdepth' parameters can also be set to \"max\", which
365 means to use the maximum value consistent with other options."
366 :group 'org-export-html
367 :version "24.4"
368 :package-version '(Org . "8.0")
369 :type
370 `(set :greedy t :inline t
371 ,@(mapcar
372 (lambda (x)
373 (list 'cons (list 'const (car x))
374 '(choice
375 (symbol :tag "Publishing/Export property")
376 (string :tag "Value"))))
377 org-html-infojs-opts-table)))
379 (defcustom org-html-infojs-template
380 "<script type=\"text/javascript\" src=\"%SCRIPT_PATH\">
383 * @source: %SCRIPT_PATH
385 * @licstart The following is the entire license notice for the
386 * JavaScript code in %SCRIPT_PATH.
388 * Copyright (C) 2012-2013 Free Software Foundation, Inc.
391 * The JavaScript code in this tag is free software: you can
392 * redistribute it and/or modify it under the terms of the GNU
393 * General Public License (GNU GPL) as published by the Free Software
394 * Foundation, either version 3 of the License, or (at your option)
395 * any later version. The code is distributed WITHOUT ANY WARRANTY;
396 * without even the implied warranty of MERCHANTABILITY or FITNESS
397 * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
399 * As additional permission under GNU GPL version 3 section 7, you
400 * may distribute non-source (e.g., minimized or compacted) forms of
401 * that code without the copy of the GNU GPL normally required by
402 * section 4, provided you include this license notice and a URL
403 * through which recipients can access the Corresponding Source.
405 * @licend The above is the entire license notice
406 * for the JavaScript code in %SCRIPT_PATH.
409 </script>
411 <script type=\"text/javascript\">
414 @licstart The following is the entire license notice for the
415 JavaScript code in this tag.
417 Copyright (C) 2012-2013 Free Software Foundation, Inc.
419 The JavaScript code in this tag is free software: you can
420 redistribute it and/or modify it under the terms of the GNU
421 General Public License (GNU GPL) as published by the Free Software
422 Foundation, either version 3 of the License, or (at your option)
423 any later version. The code is distributed WITHOUT ANY WARRANTY;
424 without even the implied warranty of MERCHANTABILITY or FITNESS
425 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
427 As additional permission under GNU GPL version 3 section 7, you
428 may distribute non-source (e.g., minimized or compacted) forms of
429 that code without the copy of the GNU GPL normally required by
430 section 4, provided you include this license notice and a URL
431 through which recipients can access the Corresponding Source.
434 @licend The above is the entire license notice
435 for the JavaScript code in this tag.
438 <!--/*--><![CDATA[/*><!--*/
439 %MANAGER_OPTIONS
440 org_html_manager.setup(); // activate after the parameters are set
441 /*]]>*///-->
442 </script>"
443 "The template for the export style additions when org-info.js is used.
444 Option settings will replace the %MANAGER-OPTIONS cookie."
445 :group 'org-export-html
446 :version "24.4"
447 :package-version '(Org . "8.0")
448 :type 'string)
450 (defun org-html-infojs-install-script (exp-plist backend)
451 "Install script in export options when appropriate.
452 EXP-PLIST is a plist containing export options. BACKEND is the
453 export back-end currently used."
454 (unless (or (memq 'body-only (plist-get exp-plist :export-options))
455 (not org-html-use-infojs)
456 (and (eq org-html-use-infojs 'when-configured)
457 (or (not (plist-get exp-plist :infojs-opt))
458 (string= "" (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 (org-font-lock-ensure)
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 (unless (org-element-property :footnote-section-p headline)
2279 (let* ((contents (or contents ""))
2280 (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 (mapconcat #'number-to-string
2292 (org-export-get-headline-number
2293 headline info) "-"))
2294 (ids (delq 'nil
2295 (list (org-element-property :CUSTOM_ID headline)
2296 (concat "sec-" section-number)
2297 (org-element-property :ID headline))))
2298 (preferred-id (car ids))
2299 (extra-ids (mapconcat
2300 (lambda (id)
2301 (org-html--anchor
2302 (org-export-solidify-link-text
2303 (if (org-uuidgen-p id) (concat "ID-" id) id))))
2304 (cdr ids) ""))
2305 ;; Create the headline text.
2306 (full-text (org-html-format-headline--wrap headline info)))
2307 (if (org-export-low-level-p headline info)
2308 ;; This is a deep sub-tree: export it as a list item.
2309 (let* ((type (if numberedp 'ordered 'unordered))
2310 (itemized-body
2311 (org-html-format-list-item
2312 contents type nil info nil
2313 (concat (org-html--anchor preferred-id) extra-ids
2314 full-text))))
2315 (concat
2316 (and (org-export-first-sibling-p headline info)
2317 (org-html-begin-plain-list type))
2318 itemized-body
2319 (and (org-export-last-sibling-p headline info)
2320 (org-html-end-plain-list type))))
2321 ;; Standard headline. Export it as a section.
2322 (let ((extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
2323 (level1 (+ level (1- org-html-toplevel-hlevel)))
2324 (first-content (car (org-element-contents headline))))
2325 (format "<%s id=\"%s\" class=\"%s\">%s%s</%s>\n"
2326 (org-html--container headline info)
2327 (format "outline-container-%s"
2328 (or (org-element-property :CUSTOM_ID headline)
2329 (concat "sec-" section-number)))
2330 (concat (format "outline-%d" level1) (and extra-class " ")
2331 extra-class)
2332 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2333 level1 preferred-id extra-ids full-text level1)
2334 ;; When there is no section, pretend there is an
2335 ;; empty one to get the correct <div class="outline-
2336 ;; ...> which is needed by `org-info.js'.
2337 (if (not (eq (org-element-type first-content) 'section))
2338 (concat (org-html-section first-content "" info)
2339 contents)
2340 contents)
2341 (org-html--container headline info)))))))
2343 (defun org-html--container (headline info)
2344 (or (org-element-property :HTML_CONTAINER headline)
2345 (if (= 1 (org-export-get-relative-level headline info))
2346 (plist-get info :html-container)
2347 "div")))
2349 ;;;; Horizontal Rule
2351 (defun org-html-horizontal-rule (horizontal-rule contents info)
2352 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2353 CONTENTS is nil. INFO is a plist holding contextual information."
2354 (org-html-close-tag "hr" nil info))
2356 ;;;; Inline Src Block
2358 (defun org-html-inline-src-block (inline-src-block contents info)
2359 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2360 CONTENTS holds the contents of the item. INFO is a plist holding
2361 contextual information."
2362 (let* ((org-lang (org-element-property :language inline-src-block))
2363 (code (org-element-property :value inline-src-block)))
2364 (error "Cannot export inline src block")))
2366 ;;;; Inlinetask
2368 (defun org-html-format-section (text class &optional id)
2369 "Format a section with TEXT into a HTML div with CLASS and ID."
2370 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2371 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2373 (defun org-html-inlinetask (inlinetask contents info)
2374 "Transcode an INLINETASK element from Org to HTML.
2375 CONTENTS holds the contents of the block. INFO is a plist
2376 holding contextual information."
2377 (cond
2378 ;; If `org-html-format-inlinetask-function' is not 'ignore, call it
2379 ;; with appropriate arguments.
2380 ((not (eq org-html-format-inlinetask-function 'ignore))
2381 (let ((format-function
2382 (function*
2383 (lambda (todo todo-type priority text tags
2384 &key contents &allow-other-keys)
2385 (funcall org-html-format-inlinetask-function
2386 todo todo-type priority text tags contents)))))
2387 (org-html-format-headline--wrap
2388 inlinetask info format-function :contents contents)))
2389 ;; Otherwise, use a default template.
2390 (t (format "<div class=\"inlinetask\">\n<b>%s</b>%s\n%s</div>"
2391 (org-html-format-headline--wrap inlinetask info)
2392 (org-html-close-tag "br" nil info)
2393 contents))))
2395 ;;;; Italic
2397 (defun org-html-italic (italic contents info)
2398 "Transcode ITALIC from Org to HTML.
2399 CONTENTS is the text with italic markup. INFO is a plist holding
2400 contextual information."
2401 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2403 ;;;; Item
2405 (defun org-html-checkbox (checkbox)
2406 "Format CHECKBOX into HTML."
2407 (case checkbox (on "<code>[X]</code>")
2408 (off "<code>[&#xa0;]</code>")
2409 (trans "<code>[-]</code>")
2410 (t "")))
2412 (defun org-html-format-list-item (contents type checkbox info
2413 &optional term-counter-id
2414 headline)
2415 "Format a list item into HTML."
2416 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " ")))
2417 (br (org-html-close-tag "br" nil info)))
2418 (concat
2419 (case type
2420 (ordered
2421 (let* ((counter term-counter-id)
2422 (extra (if counter (format " value=\"%s\"" counter) "")))
2423 (concat
2424 (format "<li%s>" extra)
2425 (when headline (concat headline br)))))
2426 (unordered
2427 (let* ((id term-counter-id)
2428 (extra (if id (format " id=\"%s\"" id) "")))
2429 (concat
2430 (format "<li%s>" extra)
2431 (when headline (concat headline br)))))
2432 (descriptive
2433 (let* ((term term-counter-id))
2434 (setq term (or term "(no term)"))
2435 ;; Check-boxes in descriptive lists are associated to tag.
2436 (concat (format "<dt> %s </dt>"
2437 (concat checkbox term))
2438 "<dd>"))))
2439 (unless (eq type 'descriptive) checkbox)
2440 contents
2441 (case type
2442 (ordered "</li>")
2443 (unordered "</li>")
2444 (descriptive "</dd>")))))
2446 (defun org-html-item (item contents info)
2447 "Transcode an ITEM element from Org to HTML.
2448 CONTENTS holds the contents of the item. INFO is a plist holding
2449 contextual information."
2450 (let* ((plain-list (org-export-get-parent item))
2451 (type (org-element-property :type plain-list))
2452 (counter (org-element-property :counter item))
2453 (checkbox (org-element-property :checkbox item))
2454 (tag (let ((tag (org-element-property :tag item)))
2455 (and tag (org-export-data tag info)))))
2456 (org-html-format-list-item
2457 contents type checkbox info (or tag counter))))
2459 ;;;; Keyword
2461 (defun org-html-keyword (keyword contents info)
2462 "Transcode a KEYWORD element from Org to HTML.
2463 CONTENTS is nil. INFO is a plist holding contextual information."
2464 (let ((key (org-element-property :key keyword))
2465 (value (org-element-property :value keyword)))
2466 (cond
2467 ((string= key "HTML") value)
2468 ((string= key "TOC")
2469 (let ((value (downcase value)))
2470 (cond
2471 ((string-match "\\<headlines\\>" value)
2472 (let ((depth (or (and (string-match "[0-9]+" value)
2473 (string-to-number (match-string 0 value)))
2474 (plist-get info :with-toc))))
2475 (org-html-toc depth info)))
2476 ((string= "listings" value) (org-html-list-of-listings info))
2477 ((string= "tables" value) (org-html-list-of-tables info))))))))
2479 ;;;; Latex Environment
2481 (defun org-html-format-latex (latex-frag processing-type info)
2482 "Format a LaTeX fragment LATEX-FRAG into HTML.
2483 PROCESSING-TYPE designates the tool used for conversion. It is
2484 a symbol among `mathjax', `dvipng', `imagemagick', `verbatim' nil
2485 and t. See `org-html-with-latex' for more information. INFO is
2486 a plist containing export properties."
2487 (let ((cache-relpath "") (cache-dir ""))
2488 (unless (eq processing-type 'mathjax)
2489 (let ((bfn (or (buffer-file-name)
2490 (make-temp-name
2491 (expand-file-name "latex" temporary-file-directory))))
2492 (latex-header
2493 (let ((header (plist-get info :latex-header)))
2494 (and header
2495 (concat (mapconcat
2496 (lambda (line) (concat "#+LATEX_HEADER: " line))
2497 (org-split-string header "\n")
2498 "\n")
2499 "\n")))))
2500 (setq cache-relpath
2501 (concat "ltxpng/"
2502 (file-name-sans-extension
2503 (file-name-nondirectory bfn)))
2504 cache-dir (file-name-directory bfn))
2505 ;; Re-create LaTeX environment from original buffer in
2506 ;; temporary buffer so that dvipng/imagemagick can properly
2507 ;; turn the fragment into an image.
2508 (setq latex-frag (concat latex-header latex-frag))))
2509 (with-temp-buffer
2510 (insert latex-frag)
2511 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2512 nil nil processing-type)
2513 (buffer-string))))
2515 (defun org-html-latex-environment (latex-environment contents info)
2516 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2517 CONTENTS is nil. INFO is a plist holding contextual information."
2518 (let ((processing-type (plist-get info :with-latex))
2519 (latex-frag (org-remove-indentation
2520 (org-element-property :value latex-environment)))
2521 (attributes (org-export-read-attribute :attr_html latex-environment)))
2522 (case processing-type
2523 ((t mathjax)
2524 (org-html-format-latex latex-frag 'mathjax info))
2525 ((dvipng imagemagick)
2526 (let ((formula-link
2527 (org-html-format-latex latex-frag processing-type info)))
2528 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2529 ;; Do not provide a caption or a name to be consistent with
2530 ;; `mathjax' handling.
2531 (org-html--wrap-image
2532 (org-html--format-image
2533 (match-string 1 formula-link) attributes info) info))))
2534 (t latex-frag))))
2536 ;;;; Latex Fragment
2538 (defun org-html-latex-fragment (latex-fragment contents info)
2539 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2540 CONTENTS is nil. INFO is a plist holding contextual information."
2541 (let ((latex-frag (org-element-property :value latex-fragment))
2542 (processing-type (plist-get info :with-latex)))
2543 (case processing-type
2544 ((t mathjax)
2545 (org-html-format-latex latex-frag 'mathjax info))
2546 ((dvipng imagemagick)
2547 (let ((formula-link
2548 (org-html-format-latex latex-frag processing-type info)))
2549 (when (and formula-link (string-match "file:\\([^]]*\\)" formula-link))
2550 (org-html--format-image (match-string 1 formula-link) nil info))))
2551 (t latex-frag))))
2553 ;;;; Line Break
2555 (defun org-html-line-break (line-break contents info)
2556 "Transcode a LINE-BREAK object from Org to HTML.
2557 CONTENTS is nil. INFO is a plist holding contextual information."
2558 (concat (org-html-close-tag "br" nil info) "\n"))
2560 ;;;; Link
2562 (defun org-html-inline-image-p (link info)
2563 "Non-nil when LINK is meant to appear as an image.
2564 INFO is a plist used as a communication channel. LINK is an
2565 inline image when it has no description and targets an image
2566 file (see `org-html-inline-image-rules' for more information), or
2567 if its description is a single link targeting an image file."
2568 (if (not (org-element-contents link))
2569 (org-export-inline-image-p link org-html-inline-image-rules)
2570 (not
2571 (let ((link-count 0))
2572 (org-element-map (org-element-contents link)
2573 (cons 'plain-text org-element-all-objects)
2574 (lambda (obj)
2575 (case (org-element-type obj)
2576 (plain-text (org-string-nw-p obj))
2577 (link (if (= link-count 1) t
2578 (incf link-count)
2579 (not (org-export-inline-image-p
2580 obj org-html-inline-image-rules))))
2581 (otherwise t)))
2582 info t)))))
2584 (defvar org-html-standalone-image-predicate)
2585 (defun org-html-standalone-image-p (element info)
2586 "Non-nil if ELEMENT is a standalone image.
2588 INFO is a plist holding contextual information.
2590 An element or object is a standalone image when
2592 - its type is `paragraph' and its sole content, save for white
2593 spaces, is a link that qualifies as an inline image;
2595 - its type is `link' and its containing paragraph has no other
2596 content save white spaces.
2598 Bind `org-html-standalone-image-predicate' to constrain paragraph
2599 further. For example, to check for only captioned standalone
2600 images, set it to:
2602 \(lambda (paragraph) (org-element-property :caption paragraph))"
2603 (let ((paragraph (case (org-element-type element)
2604 (paragraph element)
2605 (link (org-export-get-parent element)))))
2606 (and (eq (org-element-type paragraph) 'paragraph)
2607 (or (not (fboundp 'org-html-standalone-image-predicate))
2608 (funcall org-html-standalone-image-predicate paragraph))
2609 (catch 'exit
2610 (let ((link-count 0))
2611 (org-element-map (org-element-contents paragraph)
2612 (cons 'plain-text org-element-all-objects)
2613 #'(lambda (obj)
2614 (when (case (org-element-type obj)
2615 (plain-text (org-string-nw-p obj))
2616 (link (or (> (incf link-count) 1)
2617 (not (org-html-inline-image-p obj info))))
2618 (otherwise t))
2619 (throw 'exit nil)))
2620 info nil 'link)
2621 (= link-count 1))))))
2623 (defun org-html-link (link desc info)
2624 "Transcode a LINK object from Org to HTML.
2626 DESC is the description part of the link, or the empty string.
2627 INFO is a plist holding contextual information. See
2628 `org-export-data'."
2629 (let* ((home (when (plist-get info :html-link-home)
2630 (org-trim (plist-get info :html-link-home))))
2631 (use-abs-url (plist-get info :html-link-use-abs-url))
2632 (link-org-files-as-html-maybe
2633 (function
2634 (lambda (raw-path info)
2635 "Treat links to `file.org' as links to `file.html', if needed.
2636 See `org-html-link-org-files-as-html'."
2637 (cond
2638 ((and org-html-link-org-files-as-html
2639 (string= ".org"
2640 (downcase (file-name-extension raw-path "."))))
2641 (concat (file-name-sans-extension raw-path) "."
2642 (plist-get info :html-extension)))
2643 (t raw-path)))))
2644 (type (org-element-property :type link))
2645 (raw-path (org-element-property :path link))
2646 ;; Ensure DESC really exists, or set it to nil.
2647 (desc (org-string-nw-p desc))
2648 (path
2649 (cond
2650 ((member type '("http" "https" "ftp" "mailto"))
2651 (org-link-escape
2652 (org-link-unescape
2653 (concat type ":" raw-path)) org-link-escape-chars-browser))
2654 ((string= type "file")
2655 ;; Treat links to ".org" files as ".html", if needed.
2656 (setq raw-path
2657 (funcall link-org-files-as-html-maybe raw-path info))
2658 ;; If file path is absolute, prepend it with protocol
2659 ;; component - "file:".
2660 (cond
2661 ((file-name-absolute-p raw-path)
2662 (setq raw-path (concat "file:" raw-path)))
2663 ((and home use-abs-url)
2664 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2665 ;; Add search option, if any. A search option can be
2666 ;; relative to a custom-id or a headline title. Any other
2667 ;; option is ignored.
2668 (let ((option (org-element-property :search-option link)))
2669 (cond ((not option) raw-path)
2670 ((eq (aref option 0) ?#) (concat raw-path option))
2671 ;; External fuzzy link: try to resolve it if path
2672 ;; belongs to current project, if any.
2673 ((eq (aref option 0) ?*)
2674 (concat
2675 raw-path
2676 (let ((numbers
2677 (org-publish-resolve-external-fuzzy-link
2678 (org-element-property :path link) option)))
2679 (and numbers (concat "#sec-"
2680 (mapconcat 'number-to-string
2681 numbers "-"))))))
2682 (t raw-path))))
2683 (t raw-path)))
2684 ;; Extract attributes from parent's paragraph. HACK: Only do
2685 ;; this for the first link in parent (inner image link for
2686 ;; inline images). This is needed as long as attributes
2687 ;; cannot be set on a per link basis.
2688 (attributes-plist
2689 (let* ((parent (org-export-get-parent-element link))
2690 (link (let ((container (org-export-get-parent link)))
2691 (if (and (eq (org-element-type container) 'link)
2692 (org-html-inline-image-p link info))
2693 container
2694 link))))
2695 (and (eq (org-element-map parent 'link 'identity info t) link)
2696 (org-export-read-attribute :attr_html parent))))
2697 (attributes
2698 (let ((attr (org-html--make-attribute-string attributes-plist)))
2699 (if (org-string-nw-p attr) (concat " " attr) "")))
2700 protocol)
2701 (cond
2702 ;; Image file.
2703 ((and org-html-inline-images
2704 (org-export-inline-image-p link org-html-inline-image-rules))
2705 (org-html--format-image path attributes-plist info))
2706 ;; Radio target: Transcode target's contents and use them as
2707 ;; link's description.
2708 ((string= type "radio")
2709 (let ((destination (org-export-resolve-radio-link link info)))
2710 (if (not destination) desc
2711 (format "<a href=\"#%s\"%s>%s</a>"
2712 (org-export-solidify-link-text
2713 (org-element-property :value destination))
2714 attributes desc))))
2715 ;; Links pointing to a headline: Find destination and build
2716 ;; appropriate referencing command.
2717 ((member type '("custom-id" "fuzzy" "id"))
2718 (let ((destination (if (string= type "fuzzy")
2719 (org-export-resolve-fuzzy-link link info)
2720 (org-export-resolve-id-link link info))))
2721 (case (org-element-type destination)
2722 ;; ID link points to an external file.
2723 (plain-text
2724 (let ((fragment (concat "ID-" path))
2725 ;; Treat links to ".org" files as ".html", if needed.
2726 (path (funcall link-org-files-as-html-maybe
2727 destination info)))
2728 (format "<a href=\"%s#%s\"%s>%s</a>"
2729 path fragment attributes (or desc destination))))
2730 ;; Fuzzy link points nowhere.
2731 ((nil)
2732 (format "<i>%s</i>"
2733 (or desc
2734 (org-export-data
2735 (org-element-property :raw-link link) info))))
2736 ;; Link points to a headline.
2737 (headline
2738 (let ((href
2739 ;; What href to use?
2740 (cond
2741 ;; Case 1: Headline is linked via it's CUSTOM_ID
2742 ;; property. Use CUSTOM_ID.
2743 ((string= type "custom-id")
2744 (org-element-property :CUSTOM_ID destination))
2745 ;; Case 2: Headline is linked via it's ID property
2746 ;; or through other means. Use the default href.
2747 ((member type '("id" "fuzzy"))
2748 (format "sec-%s"
2749 (mapconcat 'number-to-string
2750 (org-export-get-headline-number
2751 destination info) "-")))
2752 (t (error "Shouldn't reach here"))))
2753 ;; What description to use?
2754 (desc
2755 ;; Case 1: Headline is numbered and LINK has no
2756 ;; description. Display section number.
2757 (if (and (org-export-numbered-headline-p destination info)
2758 (not desc))
2759 (mapconcat 'number-to-string
2760 (org-export-get-headline-number
2761 destination info) ".")
2762 ;; Case 2: Either the headline is un-numbered or
2763 ;; LINK has a custom description. Display LINK's
2764 ;; description or headline's title.
2765 (or desc (org-export-data (org-element-property
2766 :title destination) info)))))
2767 (format "<a href=\"#%s\"%s>%s</a>"
2768 (org-export-solidify-link-text href) attributes desc)))
2769 ;; Fuzzy link points to a target or an element.
2771 (let* ((path (org-export-solidify-link-text path))
2772 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2773 (number (cond
2774 (desc nil)
2775 ((org-html-standalone-image-p destination info)
2776 (org-export-get-ordinal
2777 (org-element-map destination 'link
2778 'identity info t)
2779 info 'link 'org-html-standalone-image-p))
2780 (t (org-export-get-ordinal
2781 destination info nil 'org-html--has-caption-p))))
2782 (desc (cond (desc)
2783 ((not number) "No description for this link")
2784 ((numberp number) (number-to-string number))
2785 (t (mapconcat 'number-to-string number ".")))))
2786 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2787 ;; Coderef: replace link with the reference name or the
2788 ;; equivalent line number.
2789 ((string= type "coderef")
2790 (let ((fragment (concat "coderef-" path)))
2791 (format "<a href=\"#%s\"%s%s>%s</a>"
2792 fragment
2793 (org-trim
2794 (format (concat "class=\"coderef\""
2795 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2796 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2797 fragment fragment))
2798 attributes
2799 (format (org-export-get-coderef-format path desc)
2800 (org-export-resolve-coderef path info)))))
2801 ;; Link type is handled by a special function.
2802 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2803 (funcall protocol (org-link-unescape path) desc 'html))
2804 ;; External link with a description part.
2805 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2806 ;; External link without a description part.
2807 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2808 ;; No path, only description. Try to do something useful.
2809 (t (format "<i>%s</i>" desc)))))
2811 ;;;; Paragraph
2813 (defun org-html-paragraph (paragraph contents info)
2814 "Transcode a PARAGRAPH element from Org to HTML.
2815 CONTENTS is the contents of the paragraph, as a string. INFO is
2816 the plist used as a communication channel."
2817 (let* ((parent (org-export-get-parent paragraph))
2818 (parent-type (org-element-type parent))
2819 (style '((footnote-definition " class=\"footpara\"")))
2820 (extra (or (cadr (assoc parent-type style)) "")))
2821 (cond
2822 ((and (eq (org-element-type parent) 'item)
2823 (= (org-element-property :begin paragraph)
2824 (org-element-property :contents-begin parent)))
2825 ;; Leading paragraph in a list item have no tags.
2826 contents)
2827 ((org-html-standalone-image-p paragraph info)
2828 ;; Standalone image.
2829 (let ((caption
2830 (let ((raw (org-export-data
2831 (org-export-get-caption paragraph) info))
2832 (org-html-standalone-image-predicate
2833 'org-html--has-caption-p))
2834 (if (not (org-string-nw-p raw)) raw
2835 (concat
2836 "<span class=\"figure-number\">"
2837 (format (org-html--translate "Figure %d:" info)
2838 (org-export-get-ordinal
2839 (org-element-map paragraph 'link
2840 'identity info t)
2841 info nil 'org-html-standalone-image-p))
2842 "</span> " raw))))
2843 (label (org-element-property :name paragraph)))
2844 (org-html--wrap-image contents info caption label)))
2845 ;; Regular paragraph.
2846 (t (format "<p%s>\n%s</p>" extra contents)))))
2848 ;;;; Plain List
2850 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2851 ;; the correct value for the item counter
2852 (defun org-html-begin-plain-list (type &optional arg1)
2853 "Insert the beginning of the HTML list depending on TYPE.
2854 When ARG1 is a string, use it as the start parameter for ordered
2855 lists."
2856 (case type
2857 (ordered
2858 (format "<ol class=\"org-ol\"%s>"
2859 (if arg1 (format " start=\"%d\"" arg1) "")))
2860 (unordered "<ul class=\"org-ul\">")
2861 (descriptive "<dl class=\"org-dl\">")))
2863 (defun org-html-end-plain-list (type)
2864 "Insert the end of the HTML list depending on TYPE."
2865 (case type
2866 (ordered "</ol>")
2867 (unordered "</ul>")
2868 (descriptive "</dl>")))
2870 (defun org-html-plain-list (plain-list contents info)
2871 "Transcode a PLAIN-LIST element from Org to HTML.
2872 CONTENTS is the contents of the list. INFO is a plist holding
2873 contextual information."
2874 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2875 (type (org-element-property :type plain-list)))
2876 (format "%s\n%s%s"
2877 (org-html-begin-plain-list type)
2878 contents (org-html-end-plain-list type))))
2880 ;;;; Plain Text
2882 (defun org-html-convert-special-strings (string)
2883 "Convert special characters in STRING to HTML."
2884 (let ((all org-html-special-string-regexps)
2885 e a re rpl start)
2886 (while (setq a (pop all))
2887 (setq re (car a) rpl (cdr a) start 0)
2888 (while (string-match re string start)
2889 (setq string (replace-match rpl t nil string))))
2890 string))
2892 (defun org-html-encode-plain-text (text)
2893 "Convert plain text characters from TEXT to HTML equivalent.
2894 Possible conversions are set in `org-html-protect-char-alist'."
2895 (mapc
2896 (lambda (pair)
2897 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2898 org-html-protect-char-alist)
2899 text)
2901 (defun org-html-plain-text (text info)
2902 "Transcode a TEXT string from Org to HTML.
2903 TEXT is the string to transcode. INFO is a plist holding
2904 contextual information."
2905 (let ((output text))
2906 ;; Protect following characters: <, >, &.
2907 (setq output (org-html-encode-plain-text output))
2908 ;; Handle smart quotes. Be sure to provide original string since
2909 ;; OUTPUT may have been modified.
2910 (when (plist-get info :with-smart-quotes)
2911 (setq output (org-export-activate-smart-quotes output :html info text)))
2912 ;; Handle special strings.
2913 (when (plist-get info :with-special-strings)
2914 (setq output (org-html-convert-special-strings output)))
2915 ;; Handle break preservation if required.
2916 (when (plist-get info :preserve-breaks)
2917 (setq output
2918 (replace-regexp-in-string
2919 "\\(\\\\\\\\\\)?[ \t]*\n"
2920 (concat (org-html-close-tag "br" nil info) "\n") output)))
2921 ;; Return value.
2922 output))
2925 ;; Planning
2927 (defun org-html-planning (planning contents info)
2928 "Transcode a PLANNING element from Org to HTML.
2929 CONTENTS is nil. INFO is a plist used as a communication
2930 channel."
2931 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2932 (format
2933 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2934 (mapconcat
2935 'identity
2936 (delq nil
2937 (list
2938 (let ((closed (org-element-property :closed planning)))
2939 (when closed
2940 (format span-fmt org-closed-string
2941 (org-translate-time
2942 (org-element-property :raw-value closed)))))
2943 (let ((deadline (org-element-property :deadline planning)))
2944 (when deadline
2945 (format span-fmt org-deadline-string
2946 (org-translate-time
2947 (org-element-property :raw-value deadline)))))
2948 (let ((scheduled (org-element-property :scheduled planning)))
2949 (when scheduled
2950 (format span-fmt org-scheduled-string
2951 (org-translate-time
2952 (org-element-property :raw-value scheduled)))))))
2953 " "))))
2955 ;;;; Property Drawer
2957 (defun org-html-property-drawer (property-drawer contents info)
2958 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2959 CONTENTS is nil. INFO is a plist holding contextual
2960 information."
2961 ;; The property drawer isn't exported but we want separating blank
2962 ;; lines nonetheless.
2965 ;;;; Quote Block
2967 (defun org-html-quote-block (quote-block contents info)
2968 "Transcode a QUOTE-BLOCK element from Org to HTML.
2969 CONTENTS holds the contents of the block. INFO is a plist
2970 holding contextual information."
2971 (format "<blockquote>\n%s</blockquote>" contents))
2973 ;;;; Quote Section
2975 (defun org-html-quote-section (quote-section contents info)
2976 "Transcode a QUOTE-SECTION element from Org to HTML.
2977 CONTENTS is nil. INFO is a plist holding contextual information."
2978 (let ((value (org-remove-indentation
2979 (org-element-property :value quote-section))))
2980 (when value (format "<pre>\n%s</pre>" value))))
2982 ;;;; Section
2984 (defun org-html-section (section contents info)
2985 "Transcode a SECTION element from Org to HTML.
2986 CONTENTS holds the contents of the section. INFO is a plist
2987 holding contextual information."
2988 (let ((parent (org-export-get-parent-headline section)))
2989 ;; Before first headline: no container, just return CONTENTS.
2990 (if (not parent) contents
2991 ;; Get div's class and id references.
2992 (let* ((class-num (+ (org-export-get-relative-level parent info)
2993 (1- org-html-toplevel-hlevel)))
2994 (section-number
2995 (mapconcat
2996 'number-to-string
2997 (org-export-get-headline-number parent info) "-")))
2998 ;; Build return value.
2999 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
3000 class-num
3001 (or (org-element-property :CUSTOM_ID parent) section-number)
3002 contents)))))
3004 ;;;; Radio Target
3006 (defun org-html-radio-target (radio-target text info)
3007 "Transcode a RADIO-TARGET object from Org to HTML.
3008 TEXT is the text of the target. INFO is a plist holding
3009 contextual information."
3010 (let ((id (org-export-solidify-link-text
3011 (org-element-property :value radio-target))))
3012 (org-html--anchor id text)))
3014 ;;;; Special Block
3016 (defun org-html-special-block (special-block contents info)
3017 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3018 CONTENTS holds the contents of the block. INFO is a plist
3019 holding contextual information."
3020 (let* ((block-type (downcase
3021 (org-element-property :type special-block)))
3022 (contents (or contents ""))
3023 (html5-fancy (and (org-html-html5-p info)
3024 (plist-get info :html-html5-fancy)
3025 (member block-type org-html-html5-elements)))
3026 (attributes (org-export-read-attribute :attr_html special-block)))
3027 (unless html5-fancy
3028 (let ((class (plist-get attributes :class)))
3029 (setq attributes (plist-put attributes :class
3030 (if class (concat class " " block-type)
3031 block-type)))))
3032 (setq attributes (org-html--make-attribute-string attributes))
3033 (when (not (equal attributes ""))
3034 (setq attributes (concat " " attributes)))
3035 (if html5-fancy
3036 (format "<%s%s>\n%s</%s>" block-type attributes
3037 contents block-type)
3038 (format "<div%s>\n%s\n</div>" attributes contents))))
3040 ;;;; Src Block
3042 (defun org-html-src-block (src-block contents info)
3043 "Transcode a SRC-BLOCK element from Org to HTML.
3044 CONTENTS holds the contents of the item. INFO is a plist holding
3045 contextual information."
3046 (if (org-export-read-attribute :attr_html src-block :textarea)
3047 (org-html--textarea-block src-block)
3048 (let ((lang (org-element-property :language src-block))
3049 (caption (org-export-get-caption src-block))
3050 (code (org-html-format-code src-block info))
3051 (label (let ((lbl (org-element-property :name src-block)))
3052 (if (not lbl) ""
3053 (format " id=\"%s\""
3054 (org-export-solidify-link-text lbl))))))
3055 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3056 (format
3057 "<div class=\"org-src-container\">\n%s%s\n</div>"
3058 (if (not caption) ""
3059 (format "<label class=\"org-src-name\">%s</label>"
3060 (org-export-data caption info)))
3061 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3063 ;;;; Statistics Cookie
3065 (defun org-html-statistics-cookie (statistics-cookie contents info)
3066 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3067 CONTENTS is nil. INFO is a plist holding contextual information."
3068 (let ((cookie-value (org-element-property :value statistics-cookie)))
3069 (format "<code>%s</code>" cookie-value)))
3071 ;;;; Strike-Through
3073 (defun org-html-strike-through (strike-through contents info)
3074 "Transcode STRIKE-THROUGH from Org to HTML.
3075 CONTENTS is the text with strike-through markup. INFO is a plist
3076 holding contextual information."
3077 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3078 contents))
3080 ;;;; Subscript
3082 (defun org-html-subscript (subscript contents info)
3083 "Transcode a SUBSCRIPT object from Org to HTML.
3084 CONTENTS is the contents of the object. INFO is a plist holding
3085 contextual information."
3086 (format "<sub>%s</sub>" contents))
3088 ;;;; Superscript
3090 (defun org-html-superscript (superscript contents info)
3091 "Transcode a SUPERSCRIPT object from Org to HTML.
3092 CONTENTS is the contents of the object. INFO is a plist holding
3093 contextual information."
3094 (format "<sup>%s</sup>" contents))
3096 ;;;; Table Cell
3098 (defun org-html-table-cell (table-cell contents info)
3099 "Transcode a TABLE-CELL element from Org to HTML.
3100 CONTENTS is nil. INFO is a plist used as a communication
3101 channel."
3102 (let* ((table-row (org-export-get-parent table-cell))
3103 (table (org-export-get-parent-table table-cell))
3104 (cell-attrs
3105 (if (not org-html-table-align-individual-fields) ""
3106 (format (if (and (boundp 'org-html-format-table-no-css)
3107 org-html-format-table-no-css)
3108 " align=\"%s\"" " class=\"%s\"")
3109 (org-export-table-cell-alignment table-cell info)))))
3110 (when (or (not contents) (string= "" (org-trim contents)))
3111 (setq contents "&#xa0;"))
3112 (cond
3113 ((and (org-export-table-has-header-p table info)
3114 (= 1 (org-export-table-row-group table-row info)))
3115 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3116 contents (cdr org-html-table-header-tags)))
3117 ((and org-html-table-use-header-tags-for-first-column
3118 (zerop (cdr (org-export-table-cell-address table-cell info))))
3119 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3120 contents (cdr org-html-table-header-tags)))
3121 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3122 contents (cdr org-html-table-data-tags))))))
3124 ;;;; Table Row
3126 (defun org-html-table-row (table-row contents info)
3127 "Transcode a TABLE-ROW element from Org to HTML.
3128 CONTENTS is the contents of the row. INFO is a plist used as a
3129 communication channel."
3130 ;; Rules are ignored since table separators are deduced from
3131 ;; borders of the current row.
3132 (when (eq (org-element-property :type table-row) 'standard)
3133 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3134 (row-number (org-export-table-row-number table-row info))
3135 (start-rowgroup-p
3136 (org-export-table-row-starts-rowgroup-p table-row info))
3137 (end-rowgroup-p
3138 (org-export-table-row-ends-rowgroup-p table-row info))
3139 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3140 ;; but should be set so that `org-html-table-row-tags' can
3141 ;; use them (see the docstring of this variable.)
3142 (top-row-p (and (equal start-rowgroup-p '(top))
3143 (equal end-rowgroup-p '(below top))))
3144 (bottom-row-p (and (equal start-rowgroup-p '(above))
3145 (equal end-rowgroup-p '(bottom above))))
3146 (rowgroup-tags
3147 (cond
3148 ;; Case 1: Row belongs to second or subsequent rowgroups.
3149 ((not (= 1 rowgroup-number))
3150 '("<tbody>" . "\n</tbody>"))
3151 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3152 ((org-export-table-has-header-p
3153 (org-export-get-parent-table table-row) info)
3154 '("<thead>" . "\n</thead>"))
3155 ;; Case 2: Row is from first and only row group.
3156 (t '("<tbody>" . "\n</tbody>")))))
3157 (concat
3158 ;; Begin a rowgroup?
3159 (when start-rowgroup-p (car rowgroup-tags))
3160 ;; Actual table row
3161 (concat "\n" (eval (car org-html-table-row-tags))
3162 contents
3163 "\n"
3164 (eval (cdr org-html-table-row-tags)))
3165 ;; End a rowgroup?
3166 (when end-rowgroup-p (cdr rowgroup-tags))))))
3168 ;;;; Table
3170 (defun org-html-table-first-row-data-cells (table info)
3171 "Transcode the first row of TABLE.
3172 INFO is a plist used as a communication channel."
3173 (let ((table-row
3174 (org-element-map table 'table-row
3175 (lambda (row)
3176 (unless (eq (org-element-property :type row) 'rule) row))
3177 info 'first-match))
3178 (special-column-p (org-export-table-has-special-column-p table)))
3179 (if (not special-column-p) (org-element-contents table-row)
3180 (cdr (org-element-contents table-row)))))
3182 (defun org-html-table--table.el-table (table info)
3183 "Format table.el tables into HTML.
3184 INFO is a plist used as a communication channel."
3185 (when (eq (org-element-property :type table) 'table.el)
3186 (require 'table)
3187 (let ((outbuf (with-current-buffer
3188 (get-buffer-create "*org-export-table*")
3189 (erase-buffer) (current-buffer))))
3190 (with-temp-buffer
3191 (insert (org-element-property :value table))
3192 (goto-char 1)
3193 (re-search-forward "^[ \t]*|[^|]" nil t)
3194 (table-generate-source 'html outbuf))
3195 (with-current-buffer outbuf
3196 (prog1 (org-trim (buffer-string))
3197 (kill-buffer) )))))
3199 (defun org-html-table (table contents info)
3200 "Transcode a TABLE element from Org to HTML.
3201 CONTENTS is the contents of the table. INFO is a plist holding
3202 contextual information."
3203 (case (org-element-property :type table)
3204 ;; Case 1: table.el table. Convert it using appropriate tools.
3205 (table.el (org-html-table--table.el-table table info))
3206 ;; Case 2: Standard table.
3208 (let* ((label (org-element-property :name table))
3209 (caption (org-export-get-caption table))
3210 (number (org-export-get-ordinal
3211 table info nil 'org-html--has-caption-p))
3212 (attributes
3213 (org-html--make-attribute-string
3214 (org-combine-plists
3215 (and label (list :id (org-export-solidify-link-text label)))
3216 (and (not (org-html-html5-p info))
3217 (plist-get info :html-table-attributes))
3218 (org-export-read-attribute :attr_html table))))
3219 (alignspec
3220 (if (and (boundp 'org-html-format-table-no-css)
3221 org-html-format-table-no-css)
3222 "align=\"%s\"" "class=\"%s\""))
3223 (table-column-specs
3224 (function
3225 (lambda (table info)
3226 (mapconcat
3227 (lambda (table-cell)
3228 (let ((alignment (org-export-table-cell-alignment
3229 table-cell info)))
3230 (concat
3231 ;; Begin a colgroup?
3232 (when (org-export-table-cell-starts-colgroup-p
3233 table-cell info)
3234 "\n<colgroup>")
3235 ;; Add a column. Also specify it's alignment.
3236 (format "\n%s"
3237 (org-html-close-tag
3238 "col" (concat " " (format alignspec alignment)) info))
3239 ;; End a colgroup?
3240 (when (org-export-table-cell-ends-colgroup-p
3241 table-cell info)
3242 "\n</colgroup>"))))
3243 (org-html-table-first-row-data-cells table info) "\n")))))
3244 (format "<table%s>\n%s\n%s\n%s</table>"
3245 (if (equal attributes "") "" (concat " " attributes))
3246 (if (not caption) ""
3247 (format (if org-html-table-caption-above
3248 "<caption class=\"t-above\">%s</caption>"
3249 "<caption class=\"t-bottom\">%s</caption>")
3250 (concat
3251 "<span class=\"table-number\">"
3252 (format (org-html--translate "Table %d:" info) number)
3253 "</span> " (org-export-data caption info))))
3254 (funcall table-column-specs table info)
3255 contents)))))
3257 ;;;; Target
3259 (defun org-html-target (target contents info)
3260 "Transcode a TARGET object from Org to HTML.
3261 CONTENTS is nil. INFO is a plist holding contextual
3262 information."
3263 (let ((id (org-export-solidify-link-text
3264 (org-element-property :value target))))
3265 (org-html--anchor id)))
3267 ;;;; Timestamp
3269 (defun org-html-timestamp (timestamp contents info)
3270 "Transcode a TIMESTAMP object from Org to HTML.
3271 CONTENTS is nil. INFO is a plist holding contextual
3272 information."
3273 (let ((value (org-html-plain-text
3274 (org-timestamp-translate timestamp) info)))
3275 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3276 (replace-regexp-in-string "--" "&#x2013;" value))))
3278 ;;;; Underline
3280 (defun org-html-underline (underline contents info)
3281 "Transcode UNDERLINE from Org to HTML.
3282 CONTENTS is the text with underline markup. INFO is a plist
3283 holding contextual information."
3284 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3285 contents))
3287 ;;;; Verbatim
3289 (defun org-html-verbatim (verbatim contents info)
3290 "Transcode VERBATIM from Org to HTML.
3291 CONTENTS is nil. INFO is a plist holding contextual
3292 information."
3293 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3294 (org-html-encode-plain-text (org-element-property :value verbatim))))
3296 ;;;; Verse Block
3298 (defun org-html-verse-block (verse-block contents info)
3299 "Transcode a VERSE-BLOCK element from Org to HTML.
3300 CONTENTS is verse block contents. INFO is a plist holding
3301 contextual information."
3302 ;; Replace each newline character with line break. Also replace
3303 ;; each blank line with a line break.
3304 (setq contents (replace-regexp-in-string
3305 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3306 (replace-regexp-in-string
3307 "\\(\\\\\\\\\\)?[ \t]*\n"
3308 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3309 ;; Replace each white space at beginning of a line with a
3310 ;; non-breaking space.
3311 (while (string-match "^[ \t]+" contents)
3312 (let* ((num-ws (length (match-string 0 contents)))
3313 (ws (let (out) (dotimes (i num-ws out)
3314 (setq out (concat out "&#xa0;"))))))
3315 (setq contents (replace-match ws nil t contents))))
3316 (format "<p class=\"verse\">\n%s</p>" contents))
3319 ;;; Filter Functions
3321 (defun org-html-final-function (contents backend info)
3322 "Filter to indent the HTML and convert HTML entities."
3323 (with-temp-buffer
3324 (insert contents)
3325 (set-auto-mode t)
3326 (if org-html-indent
3327 (indent-region (point-min) (point-max)))
3328 (when org-html-use-unicode-chars
3329 (require 'mm-url)
3330 (mm-url-decode-entities))
3331 (buffer-substring-no-properties (point-min) (point-max))))
3334 ;;; End-user functions
3336 ;;;###autoload
3337 (defun org-html-export-as-html
3338 (&optional async subtreep visible-only body-only ext-plist)
3339 "Export current buffer to an HTML buffer.
3341 If narrowing is active in the current buffer, only export its
3342 narrowed part.
3344 If a region is active, export that region.
3346 A non-nil optional argument ASYNC means the process should happen
3347 asynchronously. The resulting buffer should be accessible
3348 through the `org-export-stack' interface.
3350 When optional argument SUBTREEP is non-nil, export the sub-tree
3351 at point, extracting information from the headline properties
3352 first.
3354 When optional argument VISIBLE-ONLY is non-nil, don't export
3355 contents of hidden elements.
3357 When optional argument BODY-ONLY is non-nil, only write code
3358 between \"<body>\" and \"</body>\" tags.
3360 EXT-PLIST, when provided, is a property list with external
3361 parameters overriding Org default settings, but still inferior to
3362 file-local settings.
3364 Export is done in a buffer named \"*Org HTML Export*\", which
3365 will be displayed when `org-export-show-temporary-export-buffer'
3366 is non-nil."
3367 (interactive)
3368 (org-export-to-buffer 'html "*Org HTML Export*"
3369 async subtreep visible-only body-only ext-plist
3370 (lambda () (set-auto-mode t))))
3372 ;;;###autoload
3373 (defun org-html-convert-region-to-html ()
3374 "Assume the current region has org-mode syntax, and convert it to HTML.
3375 This can be used in any buffer. For example, you can write an
3376 itemized list in org-mode syntax in an HTML buffer and use this
3377 command to convert it."
3378 (interactive)
3379 (org-export-replace-region-by 'html))
3381 ;;;###autoload
3382 (defun org-html-export-to-html
3383 (&optional async subtreep visible-only body-only ext-plist)
3384 "Export current buffer to a HTML file.
3386 If narrowing is active in the current buffer, only export its
3387 narrowed part.
3389 If a region is active, export that region.
3391 A non-nil optional argument ASYNC means the process should happen
3392 asynchronously. The resulting file should be accessible through
3393 the `org-export-stack' interface.
3395 When optional argument SUBTREEP is non-nil, export the sub-tree
3396 at point, extracting information from the headline properties
3397 first.
3399 When optional argument VISIBLE-ONLY is non-nil, don't export
3400 contents of hidden elements.
3402 When optional argument BODY-ONLY is non-nil, only write code
3403 between \"<body>\" and \"</body>\" tags.
3405 EXT-PLIST, when provided, is a property list with external
3406 parameters overriding Org default settings, but still inferior to
3407 file-local settings.
3409 Return output file's name."
3410 (interactive)
3411 (let* ((extension (concat "." org-html-extension))
3412 (file (org-export-output-file-name extension subtreep))
3413 (org-export-coding-system org-html-coding-system))
3414 (org-export-to-file 'html file
3415 async subtreep visible-only body-only ext-plist)))
3417 ;;;###autoload
3418 (defun org-html-publish-to-html (plist filename pub-dir)
3419 "Publish an org file to HTML.
3421 FILENAME is the filename of the Org file to be published. PLIST
3422 is the property list for the given project. PUB-DIR is the
3423 publishing directory.
3425 Return output file name."
3426 (org-publish-org-to 'html filename
3427 (concat "." (or (plist-get plist :html-extension)
3428 org-html-extension "html"))
3429 plist pub-dir))
3432 (provide 'ox-html)
3434 ;; Local variables:
3435 ;; generated-autoload-file: "org-loaddefs.el"
3436 ;; End:
3438 ;;; ox-html.el ends here