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