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