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