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