reading tables from lisp code block output
[org-mode.git] / lisp / ox-html.el
blob0600204de07aa6c258cfe2700d273106fb2ba3ac
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 (org-link-escape
2628 (org-link-unescape
2629 (concat type ":" raw-path)) org-link-escape-chars-browser))
2630 ((string= type "file")
2631 ;; Treat links to ".org" files as ".html", if needed.
2632 (setq raw-path
2633 (funcall link-org-files-as-html-maybe raw-path info))
2634 ;; If file path is absolute, prepend it with protocol
2635 ;; component - "file://".
2636 (cond ((file-name-absolute-p raw-path)
2637 (setq raw-path
2638 (concat "file://" (expand-file-name
2639 raw-path))))
2640 ((and home use-abs-url)
2641 (setq raw-path (concat (file-name-as-directory home) raw-path))))
2642 ;; Add search option, if any. A search option can be
2643 ;; relative to a custom-id or a headline title. Any other
2644 ;; option is ignored.
2645 (let ((option (org-element-property :search-option link)))
2646 (cond ((not option) raw-path)
2647 ((eq (aref option 0) ?#) (concat raw-path option))
2648 ;; External fuzzy link: try to resolve it if path
2649 ;; belongs to current project, if any.
2650 ((eq (aref option 0) ?*)
2651 (concat
2652 raw-path
2653 (let ((numbers
2654 (org-publish-resolve-external-fuzzy-link
2655 (org-element-property :path link) option)))
2656 (and numbers (concat "#sec-"
2657 (mapconcat 'number-to-string
2658 numbers "-"))))))
2659 (t raw-path))))
2660 (t raw-path)))
2661 ;; Extract attributes from parent's paragraph. HACK: Only do
2662 ;; this for the first link in parent (inner image link for
2663 ;; inline images). This is needed as long as attributes
2664 ;; cannot be set on a per link basis.
2665 (attributes-plist
2666 (let* ((parent (org-export-get-parent-element link))
2667 (link (let ((container (org-export-get-parent link)))
2668 (if (and (eq (org-element-type container) 'link)
2669 (org-html-inline-image-p link info))
2670 container
2671 link))))
2672 (and (eq (org-element-map parent 'link 'identity info t) link)
2673 (org-export-read-attribute :attr_html parent))))
2674 (attributes
2675 (let ((attr (org-html--make-attribute-string attributes-plist)))
2676 (if (org-string-nw-p attr) (concat " " attr) "")))
2677 protocol)
2678 (cond
2679 ;; Image file.
2680 ((and org-html-inline-images
2681 (org-export-inline-image-p link org-html-inline-image-rules))
2682 (org-html--format-image path attributes-plist info))
2683 ;; Radio target: Transcode target's contents and use them as
2684 ;; link's description.
2685 ((string= type "radio")
2686 (let ((destination (org-export-resolve-radio-link link info)))
2687 (when destination
2688 (format "<a href=\"#%s\"%s>%s</a>"
2689 (org-export-solidify-link-text path)
2690 attributes
2691 (org-export-data (org-element-contents destination) info)))))
2692 ;; Links pointing to a headline: Find destination and build
2693 ;; appropriate referencing command.
2694 ((member type '("custom-id" "fuzzy" "id"))
2695 (let ((destination (if (string= type "fuzzy")
2696 (org-export-resolve-fuzzy-link link info)
2697 (org-export-resolve-id-link link info))))
2698 (case (org-element-type destination)
2699 ;; ID link points to an external file.
2700 (plain-text
2701 (let ((fragment (concat "ID-" path))
2702 ;; Treat links to ".org" files as ".html", if needed.
2703 (path (funcall link-org-files-as-html-maybe
2704 destination info)))
2705 (format "<a href=\"%s#%s\"%s>%s</a>"
2706 path fragment attributes (or desc destination))))
2707 ;; Fuzzy link points nowhere.
2708 ((nil)
2709 (format "<i>%s</i>"
2710 (or desc
2711 (org-export-data
2712 (org-element-property :raw-link link) info))))
2713 ;; Link points to a headline.
2714 (headline
2715 (let ((href
2716 ;; What href to use?
2717 (cond
2718 ;; Case 1: Headline is linked via it's CUSTOM_ID
2719 ;; property. Use CUSTOM_ID.
2720 ((string= type "custom-id")
2721 (org-element-property :CUSTOM_ID destination))
2722 ;; Case 2: Headline is linked via it's ID property
2723 ;; or through other means. Use the default href.
2724 ((member type '("id" "fuzzy"))
2725 (format "sec-%s"
2726 (mapconcat 'number-to-string
2727 (org-export-get-headline-number
2728 destination info) "-")))
2729 (t (error "Shouldn't reach here"))))
2730 ;; What description to use?
2731 (desc
2732 ;; Case 1: Headline is numbered and LINK has no
2733 ;; description. Display section number.
2734 (if (and (org-export-numbered-headline-p destination info)
2735 (not desc))
2736 (mapconcat 'number-to-string
2737 (org-export-get-headline-number
2738 destination info) ".")
2739 ;; Case 2: Either the headline is un-numbered or
2740 ;; LINK has a custom description. Display LINK's
2741 ;; description or headline's title.
2742 (or desc (org-export-data (org-element-property
2743 :title destination) info)))))
2744 (format "<a href=\"#%s\"%s>%s</a>"
2745 (org-export-solidify-link-text href) attributes desc)))
2746 ;; Fuzzy link points to a target or an element.
2748 (let* ((path (org-export-solidify-link-text path))
2749 (org-html-standalone-image-predicate 'org-html--has-caption-p)
2750 (number (cond
2751 (desc nil)
2752 ((org-html-standalone-image-p destination info)
2753 (org-export-get-ordinal
2754 (org-element-map destination 'link
2755 'identity info t)
2756 info 'link 'org-html-standalone-image-p))
2757 (t (org-export-get-ordinal
2758 destination info nil 'org-html--has-caption-p))))
2759 (desc (cond (desc)
2760 ((not number) "No description for this link")
2761 ((numberp number) (number-to-string number))
2762 (t (mapconcat 'number-to-string number ".")))))
2763 (format "<a href=\"#%s\"%s>%s</a>" path attributes desc))))))
2764 ;; Coderef: replace link with the reference name or the
2765 ;; equivalent line number.
2766 ((string= type "coderef")
2767 (let ((fragment (concat "coderef-" path)))
2768 (format "<a href=\"#%s\"%s%s>%s</a>"
2769 fragment
2770 (org-trim
2771 (format (concat "class=\"coderef\""
2772 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2773 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2774 fragment fragment))
2775 attributes
2776 (format (org-export-get-coderef-format path desc)
2777 (org-export-resolve-coderef path info)))))
2778 ;; Link type is handled by a special function.
2779 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2780 (funcall protocol (org-link-unescape path) desc 'html))
2781 ;; External link with a description part.
2782 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2783 ;; External link without a description part.
2784 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2785 ;; No path, only description. Try to do something useful.
2786 (t (format "<i>%s</i>" desc)))))
2788 ;;;; Node Property
2790 (defun org-html-node-property (node-property contents info)
2791 "Transcode a NODE-PROPERTY element from Org to HTML.
2792 CONTENTS is nil. INFO is a plist holding contextual
2793 information."
2794 (format "%s:%s"
2795 (org-element-property :key node-property)
2796 (let ((value (org-element-property :value node-property)))
2797 (if value (concat " " value) ""))))
2799 ;;;; Paragraph
2801 (defun org-html-paragraph (paragraph contents info)
2802 "Transcode a PARAGRAPH element from Org to HTML.
2803 CONTENTS is the contents of the paragraph, as a string. INFO is
2804 the plist used as a communication channel."
2805 (let* ((parent (org-export-get-parent paragraph))
2806 (parent-type (org-element-type parent))
2807 (style '((footnote-definition " class=\"footpara\"")))
2808 (extra (or (cadr (assoc parent-type style)) "")))
2809 (cond
2810 ((and (eq (org-element-type parent) 'item)
2811 (= (org-element-property :begin paragraph)
2812 (org-element-property :contents-begin parent)))
2813 ;; Leading paragraph in a list item have no tags.
2814 contents)
2815 ((org-html-standalone-image-p paragraph info)
2816 ;; Standalone image.
2817 (let ((caption
2818 (let ((raw (org-export-data
2819 (org-export-get-caption paragraph) info))
2820 (org-html-standalone-image-predicate
2821 'org-html--has-caption-p))
2822 (if (not (org-string-nw-p raw)) raw
2823 (concat
2824 "<span class=\"figure-number\">"
2825 (format (org-html--translate "Figure %d:" info)
2826 (org-export-get-ordinal
2827 (org-element-map paragraph 'link
2828 'identity info t)
2829 info nil 'org-html-standalone-image-p))
2830 "</span> " raw))))
2831 (label (org-element-property :name paragraph)))
2832 (org-html--wrap-image contents info caption label)))
2833 ;; Regular paragraph.
2834 (t (format "<p%s>\n%s</p>" extra contents)))))
2836 ;;;; Plain List
2838 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2839 ;; the correct value for the item counter
2840 (defun org-html-begin-plain-list (type &optional arg1)
2841 "Insert the beginning of the HTML list depending on TYPE.
2842 When ARG1 is a string, use it as the start parameter for ordered
2843 lists."
2844 (case type
2845 (ordered
2846 (format "<ol class=\"org-ol\"%s>"
2847 (if arg1 (format " start=\"%d\"" arg1) "")))
2848 (unordered "<ul class=\"org-ul\">")
2849 (descriptive "<dl class=\"org-dl\">")))
2851 (defun org-html-end-plain-list (type)
2852 "Insert the end of the HTML list depending on TYPE."
2853 (case type
2854 (ordered "</ol>")
2855 (unordered "</ul>")
2856 (descriptive "</dl>")))
2858 (defun org-html-plain-list (plain-list contents info)
2859 "Transcode a PLAIN-LIST element from Org to HTML.
2860 CONTENTS is the contents of the list. INFO is a plist holding
2861 contextual information."
2862 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2863 (type (org-element-property :type plain-list)))
2864 (format "%s\n%s%s"
2865 (org-html-begin-plain-list type)
2866 contents (org-html-end-plain-list type))))
2868 ;;;; Plain Text
2870 (defun org-html-convert-special-strings (string)
2871 "Convert special characters in STRING to HTML."
2872 (let ((all org-html-special-string-regexps)
2873 e a re rpl start)
2874 (while (setq a (pop all))
2875 (setq re (car a) rpl (cdr a) start 0)
2876 (while (string-match re string start)
2877 (setq string (replace-match rpl t nil string))))
2878 string))
2880 (defun org-html-encode-plain-text (text)
2881 "Convert plain text characters from TEXT to HTML equivalent.
2882 Possible conversions are set in `org-html-protect-char-alist'."
2883 (mapc
2884 (lambda (pair)
2885 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2886 org-html-protect-char-alist)
2887 text)
2889 (defun org-html-plain-text (text info)
2890 "Transcode a TEXT string from Org to HTML.
2891 TEXT is the string to transcode. INFO is a plist holding
2892 contextual information."
2893 (let ((output text))
2894 ;; Protect following characters: <, >, &.
2895 (setq output (org-html-encode-plain-text output))
2896 ;; Handle smart quotes. Be sure to provide original string since
2897 ;; OUTPUT may have been modified.
2898 (when (plist-get info :with-smart-quotes)
2899 (setq output (org-export-activate-smart-quotes output :html info text)))
2900 ;; Handle special strings.
2901 (when (plist-get info :with-special-strings)
2902 (setq output (org-html-convert-special-strings output)))
2903 ;; Handle break preservation if required.
2904 (when (plist-get info :preserve-breaks)
2905 (setq output
2906 (replace-regexp-in-string
2907 "\\(\\\\\\\\\\)?[ \t]*\n"
2908 (concat (org-html-close-tag "br" nil info) "\n") output)))
2909 ;; Return value.
2910 output))
2913 ;; Planning
2915 (defun org-html-planning (planning contents info)
2916 "Transcode a PLANNING element from Org to HTML.
2917 CONTENTS is nil. INFO is a plist used as a communication
2918 channel."
2919 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2920 (format
2921 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2922 (mapconcat
2923 'identity
2924 (delq nil
2925 (list
2926 (let ((closed (org-element-property :closed planning)))
2927 (when closed
2928 (format span-fmt org-closed-string
2929 (org-translate-time
2930 (org-element-property :raw-value closed)))))
2931 (let ((deadline (org-element-property :deadline planning)))
2932 (when deadline
2933 (format span-fmt org-deadline-string
2934 (org-translate-time
2935 (org-element-property :raw-value deadline)))))
2936 (let ((scheduled (org-element-property :scheduled planning)))
2937 (when scheduled
2938 (format span-fmt org-scheduled-string
2939 (org-translate-time
2940 (org-element-property :raw-value scheduled)))))))
2941 " "))))
2943 ;;;; Property Drawer
2945 (defun org-html-property-drawer (property-drawer contents info)
2946 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2947 CONTENTS holds the contents of the drawer. INFO is a plist
2948 holding contextual information."
2949 (and (org-string-nw-p contents)
2950 (format "<pre class=\"example\">\n%s</pre>" contents)))
2952 ;;;; Quote Block
2954 (defun org-html-quote-block (quote-block contents info)
2955 "Transcode a QUOTE-BLOCK element from Org to HTML.
2956 CONTENTS holds the contents of the block. INFO is a plist
2957 holding contextual information."
2958 (format "<blockquote>\n%s</blockquote>" contents))
2960 ;;;; Quote Section
2962 (defun org-html-quote-section (quote-section contents info)
2963 "Transcode a QUOTE-SECTION element from Org to HTML.
2964 CONTENTS is nil. INFO is a plist holding contextual information."
2965 (let ((value (org-remove-indentation
2966 (org-element-property :value quote-section))))
2967 (when value (format "<pre>\n%s</pre>" value))))
2969 ;;;; Section
2971 (defun org-html-section (section contents info)
2972 "Transcode a SECTION element from Org to HTML.
2973 CONTENTS holds the contents of the section. INFO is a plist
2974 holding contextual information."
2975 (let ((parent (org-export-get-parent-headline section)))
2976 ;; Before first headline: no container, just return CONTENTS.
2977 (if (not parent) contents
2978 ;; Get div's class and id references.
2979 (let* ((class-num (+ (org-export-get-relative-level parent info)
2980 (1- org-html-toplevel-hlevel)))
2981 (section-number
2982 (mapconcat
2983 'number-to-string
2984 (org-export-get-headline-number parent info) "-")))
2985 ;; Build return value.
2986 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2987 class-num
2988 (or (org-element-property :CUSTOM_ID parent) section-number)
2989 contents)))))
2991 ;;;; Radio Target
2993 (defun org-html-radio-target (radio-target text info)
2994 "Transcode a RADIO-TARGET object from Org to HTML.
2995 TEXT is the text of the target. INFO is a plist holding
2996 contextual information."
2997 (let ((id (org-export-solidify-link-text
2998 (org-element-property :value radio-target))))
2999 (org-html--anchor id text)))
3001 ;;;; Special Block
3003 (defun org-html-special-block (special-block contents info)
3004 "Transcode a SPECIAL-BLOCK element from Org to HTML.
3005 CONTENTS holds the contents of the block. INFO is a plist
3006 holding contextual information."
3007 (let* ((block-type (downcase
3008 (org-element-property :type special-block)))
3009 (contents (or contents ""))
3010 (html5-fancy (and (org-html-html5-p info)
3011 (plist-get info :html-html5-fancy)
3012 (member block-type org-html-html5-elements)))
3013 (attributes (org-export-read-attribute :attr_html special-block)))
3014 (unless html5-fancy
3015 (let ((class (plist-get attributes :class)))
3016 (setq attributes (plist-put attributes :class
3017 (if class (concat class " " block-type)
3018 block-type)))))
3019 (setq attributes (org-html--make-attribute-string attributes))
3020 (when (not (equal attributes ""))
3021 (setq attributes (concat " " attributes)))
3022 (if html5-fancy
3023 (format "<%s%s>\n%s</%s>" block-type attributes
3024 contents block-type)
3025 (format "<div%s>\n%s\n</div>" attributes contents))))
3027 ;;;; Src Block
3029 (defun org-html-src-block (src-block contents info)
3030 "Transcode a SRC-BLOCK element from Org to HTML.
3031 CONTENTS holds the contents of the item. INFO is a plist holding
3032 contextual information."
3033 (if (org-export-read-attribute :attr_html src-block :textarea)
3034 (org-html--textarea-block src-block)
3035 (let ((lang (org-element-property :language src-block))
3036 (caption (org-export-get-caption src-block))
3037 (code (org-html-format-code src-block info))
3038 (label (let ((lbl (org-element-property :name src-block)))
3039 (if (not lbl) ""
3040 (format " id=\"%s\""
3041 (org-export-solidify-link-text lbl))))))
3042 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
3043 (format
3044 "<div class=\"org-src-container\">\n%s%s\n</div>"
3045 (if (not caption) ""
3046 (format "<label class=\"org-src-name\">%s</label>"
3047 (org-export-data caption info)))
3048 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
3050 ;;;; Statistics Cookie
3052 (defun org-html-statistics-cookie (statistics-cookie contents info)
3053 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3054 CONTENTS is nil. INFO is a plist holding contextual information."
3055 (let ((cookie-value (org-element-property :value statistics-cookie)))
3056 (format "<code>%s</code>" cookie-value)))
3058 ;;;; Strike-Through
3060 (defun org-html-strike-through (strike-through contents info)
3061 "Transcode STRIKE-THROUGH from Org to HTML.
3062 CONTENTS is the text with strike-through markup. INFO is a plist
3063 holding contextual information."
3064 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
3065 contents))
3067 ;;;; Subscript
3069 (defun org-html-subscript (subscript contents info)
3070 "Transcode a SUBSCRIPT object from Org to HTML.
3071 CONTENTS is the contents of the object. INFO is a plist holding
3072 contextual information."
3073 (format "<sub>%s</sub>" contents))
3075 ;;;; Superscript
3077 (defun org-html-superscript (superscript contents info)
3078 "Transcode a SUPERSCRIPT object from Org to HTML.
3079 CONTENTS is the contents of the object. INFO is a plist holding
3080 contextual information."
3081 (format "<sup>%s</sup>" contents))
3083 ;;;; Tabel Cell
3085 (defun org-html-table-cell (table-cell contents info)
3086 "Transcode a TABLE-CELL element from Org to HTML.
3087 CONTENTS is nil. INFO is a plist used as a communication
3088 channel."
3089 (let* ((table-row (org-export-get-parent table-cell))
3090 (table (org-export-get-parent-table table-cell))
3091 (cell-attrs
3092 (if (not org-html-table-align-individual-fields) ""
3093 (format (if (and (boundp 'org-html-format-table-no-css)
3094 org-html-format-table-no-css)
3095 " align=\"%s\"" " class=\"%s\"")
3096 (org-export-table-cell-alignment table-cell info)))))
3097 (when (or (not contents) (string= "" (org-trim contents)))
3098 (setq contents "&#xa0;"))
3099 (cond
3100 ((and (org-export-table-has-header-p table info)
3101 (= 1 (org-export-table-row-group table-row info)))
3102 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
3103 contents (cdr org-html-table-header-tags)))
3104 ((and org-html-table-use-header-tags-for-first-column
3105 (zerop (cdr (org-export-table-cell-address table-cell info))))
3106 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
3107 contents (cdr org-html-table-header-tags)))
3108 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
3109 contents (cdr org-html-table-data-tags))))))
3111 ;;;; Table Row
3113 (defun org-html-table-row (table-row contents info)
3114 "Transcode a TABLE-ROW element from Org to HTML.
3115 CONTENTS is the contents of the row. INFO is a plist used as a
3116 communication channel."
3117 ;; Rules are ignored since table separators are deduced from
3118 ;; borders of the current row.
3119 (when (eq (org-element-property :type table-row) 'standard)
3120 (let* ((rowgroup-number (org-export-table-row-group table-row info))
3121 (row-number (org-export-table-row-number table-row info))
3122 (start-rowgroup-p
3123 (org-export-table-row-starts-rowgroup-p table-row info))
3124 (end-rowgroup-p
3125 (org-export-table-row-ends-rowgroup-p table-row info))
3126 ;; `top-row-p' and `end-rowgroup-p' are not used directly
3127 ;; but should be set so that `org-html-table-row-tags' can
3128 ;; use them (see the docstring of this variable.)
3129 (top-row-p (and (equal start-rowgroup-p '(top))
3130 (equal end-rowgroup-p '(below top))))
3131 (bottom-row-p (and (equal start-rowgroup-p '(above))
3132 (equal end-rowgroup-p '(bottom above))))
3133 (rowgroup-tags
3134 (cond
3135 ;; Case 1: Row belongs to second or subsequent rowgroups.
3136 ((not (= 1 rowgroup-number))
3137 '("<tbody>" . "\n</tbody>"))
3138 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
3139 ((org-export-table-has-header-p
3140 (org-export-get-parent-table table-row) info)
3141 '("<thead>" . "\n</thead>"))
3142 ;; Case 2: Row is from first and only row group.
3143 (t '("<tbody>" . "\n</tbody>")))))
3144 (concat
3145 ;; Begin a rowgroup?
3146 (when start-rowgroup-p (car rowgroup-tags))
3147 ;; Actual table row
3148 (concat "\n" (eval (car org-html-table-row-tags))
3149 contents
3150 "\n"
3151 (eval (cdr org-html-table-row-tags)))
3152 ;; End a rowgroup?
3153 (when end-rowgroup-p (cdr rowgroup-tags))))))
3155 ;;;; Table
3157 (defun org-html-table-first-row-data-cells (table info)
3158 "Transcode the first row of TABLE.
3159 INFO is a plist used as a communication channel."
3160 (let ((table-row
3161 (org-element-map table 'table-row
3162 (lambda (row)
3163 (unless (eq (org-element-property :type row) 'rule) row))
3164 info 'first-match))
3165 (special-column-p (org-export-table-has-special-column-p table)))
3166 (if (not special-column-p) (org-element-contents table-row)
3167 (cdr (org-element-contents table-row)))))
3169 (defun org-html-table--table.el-table (table info)
3170 "Format table.el tables into HTML.
3171 INFO is a plist used as a communication channel."
3172 (when (eq (org-element-property :type table) 'table.el)
3173 (require 'table)
3174 (let ((outbuf (with-current-buffer
3175 (get-buffer-create "*org-export-table*")
3176 (erase-buffer) (current-buffer))))
3177 (with-temp-buffer
3178 (insert (org-element-property :value table))
3179 (goto-char 1)
3180 (re-search-forward "^[ \t]*|[^|]" nil t)
3181 (table-generate-source 'html outbuf))
3182 (with-current-buffer outbuf
3183 (prog1 (org-trim (buffer-string))
3184 (kill-buffer) )))))
3186 (defun org-html-table (table contents info)
3187 "Transcode a TABLE element from Org to HTML.
3188 CONTENTS is the contents of the table. INFO is a plist holding
3189 contextual information."
3190 (case (org-element-property :type table)
3191 ;; Case 1: table.el table. Convert it using appropriate tools.
3192 (table.el (org-html-table--table.el-table table info))
3193 ;; Case 2: Standard table.
3195 (let* ((label (org-element-property :name table))
3196 (caption (org-export-get-caption table))
3197 (number (org-export-get-ordinal
3198 table info nil 'org-html--has-caption-p))
3199 (attributes
3200 (org-html--make-attribute-string
3201 (org-combine-plists
3202 (and label (list :id (org-export-solidify-link-text label)))
3203 (and (not (org-html-html5-p info))
3204 (plist-get info :html-table-attributes))
3205 (org-export-read-attribute :attr_html table))))
3206 (alignspec
3207 (if (and (boundp 'org-html-format-table-no-css)
3208 org-html-format-table-no-css)
3209 "align=\"%s\"" "class=\"%s\""))
3210 (table-column-specs
3211 (function
3212 (lambda (table info)
3213 (mapconcat
3214 (lambda (table-cell)
3215 (let ((alignment (org-export-table-cell-alignment
3216 table-cell info)))
3217 (concat
3218 ;; Begin a colgroup?
3219 (when (org-export-table-cell-starts-colgroup-p
3220 table-cell info)
3221 "\n<colgroup>")
3222 ;; Add a column. Also specify it's alignment.
3223 (format "\n%s"
3224 (org-html-close-tag
3225 "col" (concat " " (format alignspec alignment)) info))
3226 ;; End a colgroup?
3227 (when (org-export-table-cell-ends-colgroup-p
3228 table-cell info)
3229 "\n</colgroup>"))))
3230 (org-html-table-first-row-data-cells table info) "\n")))))
3231 (format "<table%s>\n%s\n%s\n%s</table>"
3232 (if (equal attributes "") "" (concat " " attributes))
3233 (if (not caption) ""
3234 (format (if org-html-table-caption-above
3235 "<caption align=\"above\">%s</caption>"
3236 "<caption align=\"bottom\">%s</caption>")
3237 (concat
3238 "<span class=\"table-number\">"
3239 (format (org-html--translate "Table %d:" info) number)
3240 "</span> " (org-export-data caption info))))
3241 (funcall table-column-specs table info)
3242 contents)))))
3244 ;;;; Target
3246 (defun org-html-target (target contents info)
3247 "Transcode a TARGET object from Org to HTML.
3248 CONTENTS is nil. INFO is a plist holding contextual
3249 information."
3250 (let ((id (org-export-solidify-link-text
3251 (org-element-property :value target))))
3252 (org-html--anchor id)))
3254 ;;;; Timestamp
3256 (defun org-html-timestamp (timestamp contents info)
3257 "Transcode a TIMESTAMP object from Org to HTML.
3258 CONTENTS is nil. INFO is a plist holding contextual
3259 information."
3260 (let ((value (org-html-plain-text
3261 (org-timestamp-translate timestamp) info)))
3262 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3263 (replace-regexp-in-string "--" "&#x2013;" value))))
3265 ;;;; Underline
3267 (defun org-html-underline (underline contents info)
3268 "Transcode UNDERLINE from Org to HTML.
3269 CONTENTS is the text with underline markup. INFO is a plist
3270 holding contextual information."
3271 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
3272 contents))
3274 ;;;; Verbatim
3276 (defun org-html-verbatim (verbatim contents info)
3277 "Transcode VERBATIM from Org to HTML.
3278 CONTENTS is nil. INFO is a plist holding contextual
3279 information."
3280 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
3281 (org-html-encode-plain-text (org-element-property :value verbatim))))
3283 ;;;; Verse Block
3285 (defun org-html-verse-block (verse-block contents info)
3286 "Transcode a VERSE-BLOCK element from Org to HTML.
3287 CONTENTS is verse block contents. INFO is a plist holding
3288 contextual information."
3289 ;; Replace each newline character with line break. Also replace
3290 ;; each blank line with a line break.
3291 (setq contents (replace-regexp-in-string
3292 "^ *\\\\\\\\$" (format "%s\n" (org-html-close-tag "br" nil info))
3293 (replace-regexp-in-string
3294 "\\(\\\\\\\\\\)?[ \t]*\n"
3295 (format "%s\n" (org-html-close-tag "br" nil info)) contents)))
3296 ;; Replace each white space at beginning of a line with a
3297 ;; non-breaking space.
3298 (while (string-match "^[ \t]+" contents)
3299 (let* ((num-ws (length (match-string 0 contents)))
3300 (ws (let (out) (dotimes (i num-ws out)
3301 (setq out (concat out "&#xa0;"))))))
3302 (setq contents (replace-match ws nil t contents))))
3303 (format "<p class=\"verse\">\n%s</p>" contents))
3306 ;;; Filter Functions
3308 (defun org-html-final-function (contents backend info)
3309 "Filter to indent the HTML and convert HTML entities."
3310 (with-temp-buffer
3311 (insert contents)
3312 (set-auto-mode t)
3313 (if org-html-indent
3314 (indent-region (point-min) (point-max)))
3315 (when org-html-use-unicode-chars
3316 (require 'mm-url)
3317 (mm-url-decode-entities))
3318 (buffer-substring-no-properties (point-min) (point-max))))
3321 ;;; End-user functions
3323 ;;;###autoload
3324 (defun org-html-export-as-html
3325 (&optional async subtreep visible-only body-only ext-plist)
3326 "Export current buffer to an HTML buffer.
3328 If narrowing is active in the current buffer, only export its
3329 narrowed part.
3331 If a region is active, export that region.
3333 A non-nil optional argument ASYNC means the process should happen
3334 asynchronously. The resulting buffer should be accessible
3335 through the `org-export-stack' interface.
3337 When optional argument SUBTREEP is non-nil, export the sub-tree
3338 at point, extracting information from the headline properties
3339 first.
3341 When optional argument VISIBLE-ONLY is non-nil, don't export
3342 contents of hidden elements.
3344 When optional argument BODY-ONLY is non-nil, only write code
3345 between \"<body>\" and \"</body>\" tags.
3347 EXT-PLIST, when provided, is a property list with external
3348 parameters overriding Org default settings, but still inferior to
3349 file-local settings.
3351 Export is done in a buffer named \"*Org HTML Export*\", which
3352 will be displayed when `org-export-show-temporary-export-buffer'
3353 is non-nil."
3354 (interactive)
3355 (org-export-to-buffer 'html "*Org HTML Export*"
3356 async subtreep visible-only body-only ext-plist
3357 (lambda () (set-auto-mode t))))
3359 ;;;###autoload
3360 (defun org-html-convert-region-to-html ()
3361 "Assume the current region has org-mode syntax, and convert it to HTML.
3362 This can be used in any buffer. For example, you can write an
3363 itemized list in org-mode syntax in an HTML buffer and use this
3364 command to convert it."
3365 (interactive)
3366 (org-export-replace-region-by 'html))
3368 ;;;###autoload
3369 (defun org-html-export-to-html
3370 (&optional async subtreep visible-only body-only ext-plist)
3371 "Export current buffer to a HTML file.
3373 If narrowing is active in the current buffer, only export its
3374 narrowed part.
3376 If a region is active, export that region.
3378 A non-nil optional argument ASYNC means the process should happen
3379 asynchronously. The resulting file should be accessible through
3380 the `org-export-stack' interface.
3382 When optional argument SUBTREEP is non-nil, export the sub-tree
3383 at point, extracting information from the headline properties
3384 first.
3386 When optional argument VISIBLE-ONLY is non-nil, don't export
3387 contents of hidden elements.
3389 When optional argument BODY-ONLY is non-nil, only write code
3390 between \"<body>\" and \"</body>\" tags.
3392 EXT-PLIST, when provided, is a property list with external
3393 parameters overriding Org default settings, but still inferior to
3394 file-local settings.
3396 Return output file's name."
3397 (interactive)
3398 (let* ((extension (concat "." org-html-extension))
3399 (file (org-export-output-file-name extension subtreep))
3400 (org-export-coding-system org-html-coding-system))
3401 (org-export-to-file 'html file
3402 async subtreep visible-only body-only ext-plist)))
3404 ;;;###autoload
3405 (defun org-html-publish-to-html (plist filename pub-dir)
3406 "Publish an org file to HTML.
3408 FILENAME is the filename of the Org file to be published. PLIST
3409 is the property list for the given project. PUB-DIR is the
3410 publishing directory.
3412 Return output file name."
3413 (org-publish-org-to 'html filename
3414 (concat "." (or (plist-get plist :html-extension)
3415 org-html-extension "html"))
3416 plist pub-dir))
3419 ;;; FIXME
3421 ;;;; org-format-table-html
3422 ;;;; org-format-org-table-html
3423 ;;;; org-format-table-table-html
3424 ;;;; org-table-number-fraction
3425 ;;;; org-table-number-regexp
3426 ;;;; org-html-inline-image-extensions
3427 ;;;; org-export-preferred-target-alist
3428 ;;;; class for anchors
3429 ;;;; org-export-mark-todo-in-toc
3430 ;;;; org-html-format-org-link
3431 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3432 ;;;; alt = (file-name-nondirectory path)
3434 (provide 'ox-html)
3436 ;; Local variables:
3437 ;; generated-autoload-file: "org-loaddefs.el"
3438 ;; End:
3440 ;;; ox-html.el ends here