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