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