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