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