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