sub/superscript character has to follow a non-blank character
[org-mode.git] / lisp / ox-html.el
blob628cf84c3de261b49e9eab178cb6ff14a454054c
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))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file "org-id" (id))
46 (declare-function htmlize-region "ext:htmlize" (beg end))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label))
51 ;;; Define Back-End
53 (org-export-define-backend html
54 ((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (paragraph . org-html-paragraph)
80 (plain-list . org-html-plain-list)
81 (plain-text . org-html-plain-text)
82 (planning . org-html-planning)
83 (property-drawer . org-html-property-drawer)
84 (quote-block . org-html-quote-block)
85 (quote-section . org-html-quote-section)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :export-block "HTML"
104 :filters-alist ((:filter-final-output . org-html-final-function))
105 :menu-entry
106 (?h "Export to HTML"
107 ((?H "As HTML buffer" org-html-export-as-html)
108 (?h "As HTML file" org-html-export-to-html)
109 (?o "As HTML file and open"
110 (lambda (a s v b)
111 (if a (org-html-export-to-html t s v b)
112 (org-open-file (org-html-export-to-html nil s v b)))))))
113 :options-alist
114 ((:html-extension nil nil org-html-extension)
115 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
116 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
117 (:html-mathjax "HTML_MATHJAX" nil "" space)
118 (:html-postamble nil "html-postamble" org-html-postamble)
119 (:html-preamble nil "html-preamble" org-html-preamble)
120 (:html-style nil nil org-html-style)
121 (:html-style-extra "HTML_STYLE" nil org-html-style-extra newline)
122 (:html-style-include-default nil nil org-html-style-include-default)
123 (:html-style-include-scripts nil nil org-html-style-include-scripts)
124 (:html-table-tag nil nil org-html-table-tag)
125 (:html-htmlized-css-url "HTML_HTMLIZED_CSS_URL" nil org-html-htmlized-org-css-url)
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)))
134 ;;; Internal Variables
136 (defvar org-html-format-table-no-css)
137 (defvar htmlize-buffer-places) ; from htmlize.el
139 (defconst org-html-special-string-regexps
140 '(("\\\\-" . "&shy;")
141 ("---\\([^-]\\)" . "&mdash;\\1")
142 ("--\\([^-]\\)" . "&ndash;\\1")
143 ("\\.\\.\\." . "&hellip;"))
144 "Regular expressions for special string conversion.")
146 (defconst org-html-scripts
147 "<script type=\"text/javascript\">
149 @licstart The following is the entire license notice for the
150 JavaScript code in this tag.
152 Copyright (C) 2012 Free Software Foundation, Inc.
154 The JavaScript code in this tag is free software: you can
155 redistribute it and/or modify it under the terms of the GNU
156 General Public License (GNU GPL) as published by the Free Software
157 Foundation, either version 3 of the License, or (at your option)
158 any later version. The code is distributed WITHOUT ANY WARRANTY;
159 without even the implied warranty of MERCHANTABILITY or FITNESS
160 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
162 As additional permission under GNU GPL version 3 section 7, you
163 may distribute non-source (e.g., minimized or compacted) forms of
164 that code without the copy of the GNU GPL normally required by
165 section 4, provided you include this license notice and a URL
166 through which recipients can access the Corresponding Source.
169 @licend The above is the entire license notice
170 for the JavaScript code in this tag.
172 <!--/*--><![CDATA[/*><!--*/
173 function CodeHighlightOn(elem, id)
175 var target = document.getElementById(id);
176 if(null != target) {
177 elem.cacheClassElem = elem.className;
178 elem.cacheClassTarget = target.className;
179 target.className = \"code-highlighted\";
180 elem.className = \"code-highlighted\";
183 function CodeHighlightOff(elem, id)
185 var target = document.getElementById(id);
186 if(elem.cacheClassElem)
187 elem.className = elem.cacheClassElem;
188 if(elem.cacheClassTarget)
189 target.className = elem.cacheClassTarget;
191 /*]]>*///-->
192 </script>"
193 "Basic JavaScript that is needed by HTML files produced by Org mode.")
195 (defconst org-html-style-default
196 "<style type=\"text/css\">
197 <!--/*--><![CDATA[/*><!--*/
198 html { font-family: Times, serif; font-size: 12pt; }
199 .title { text-align: center; }
200 .todo { color: red; }
201 .done { color: green; }
202 .tag { background-color: #add8e6; font-weight:normal }
203 .target { }
204 .timestamp { color: #bebebe; }
205 .timestamp-kwd { color: #5f9ea0; }
206 .right {margin-left:auto; margin-right:0px; text-align:right;}
207 .left {margin-left:0px; margin-right:auto; text-align:left;}
208 .center {margin-left:auto; margin-right:auto; text-align:center;}
209 p.verse { margin-left: 3% }
210 pre {
211 border: 1pt solid #AEBDCC;
212 background-color: #F3F5F7;
213 padding: 5pt;
214 font-family: courier, monospace;
215 font-size: 90%;
216 overflow:auto;
218 table { border-collapse: collapse; }
219 td, th { vertical-align: top; }
220 th.right { text-align:center; }
221 th.left { text-align:center; }
222 th.center { text-align:center; }
223 td.right { text-align:right; }
224 td.left { text-align:left; }
225 td.center { text-align:center; }
226 dt { font-weight: bold; }
227 div.figure { padding: 0.5em; }
228 div.figure p { text-align: center; }
229 div.inlinetask {
230 padding:10px;
231 border:2px solid gray;
232 margin:10px;
233 background: #ffffcc;
235 textarea { overflow-x: auto; }
236 .linenr { font-size:smaller }
237 .code-highlighted {background-color:#ffff00;}
238 .org-info-js_info-navigation { border-style:none; }
239 #org-info-js_console-label { font-size:10px; font-weight:bold;
240 white-space:nowrap; }
241 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
242 font-weight:bold; }
243 /*]]>*/-->
244 </style>"
245 "The default style specification for exported HTML files.
246 Please use the variables `org-html-style' and
247 `org-html-style-extra' to add to this style. If you wish to not
248 have the default style included, customize the variable
249 `org-html-style-include-default'.")
253 ;;; User Configuration Variables
255 (defgroup org-export-html nil
256 "Options for exporting Org mode files to HTML."
257 :tag "Org Export HTML"
258 :group 'org-export)
261 ;;;; Bold etc
263 (defcustom org-html-text-markup-alist
264 '((bold . "<b>%s</b>")
265 (code . "<code>%s</code>")
266 (italic . "<i>%s</i>")
267 (strike-through . "<del>%s</del>")
268 (underline . "<span style=\"text-decoration:underline;\">%s</span>")
269 (verbatim . "<code>%s</code>"))
270 "Alist of HTML expressions to convert text markup
272 The key must be a symbol among `bold', `code', `italic',
273 `strike-through', `underline' and `verbatim'. The value is
274 a formatting string to wrap fontified text with.
276 If no association can be found for a given markup, text will be
277 returned as-is."
278 :group 'org-export-html
279 :type '(alist :key-type (symbol :tag "Markup type")
280 :value-type (string :tag "Format string"))
281 :options '(bold code italic strike-through underline verbatim))
284 ;;;; Debugging
286 (defcustom org-html-pretty-output nil
287 "Enable this to generate pretty HTML."
288 :group 'org-export-html
289 :type 'boolean)
292 ;;;; Drawers
294 (defcustom org-html-format-drawer-function nil
295 "Function called to format a drawer in HTML code.
297 The function must accept two parameters:
298 NAME the drawer name, like \"LOGBOOK\"
299 CONTENTS the contents of the drawer.
301 The function should return the string to be exported.
303 For example, the variable could be set to the following function
304 in order to mimic default behaviour:
306 \(defun org-html-format-drawer-default \(name contents\)
307 \"Format a drawer element for HTML export.\"
308 contents\)"
309 :group 'org-export-html
310 :type 'function)
313 ;;;; Footnotes
315 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
316 <h2 class=\"footnotes\">%s: </h2>
317 <div id=\"text-footnotes\">
319 </div>
320 </div>"
321 "Format for the footnotes section.
322 Should contain a two instances of %s. The first will be replaced with the
323 language-specific word for \"Footnotes\", the second one will be replaced
324 by the footnotes themselves."
325 :group 'org-export-html
326 :type 'string)
328 (defcustom org-html-footnote-format "<sup>%s</sup>"
329 "The format for the footnote reference.
330 %s will be replaced by the footnote reference itself."
331 :group 'org-export-html
332 :type 'string)
334 (defcustom org-html-footnote-separator "<sup>, </sup>"
335 "Text used to separate footnotes."
336 :group 'org-export-html
337 :type 'string)
340 ;;;; Headline
342 (defcustom org-html-toplevel-hlevel 2
343 "The <H> level for level 1 headings in HTML export.
344 This is also important for the classes that will be wrapped around headlines
345 and outline structure. If this variable is 1, the top-level headlines will
346 be <h1>, and the corresponding classes will be outline-1, section-number-1,
347 and outline-text-1. If this is 2, all of these will get a 2 instead.
348 The default for this variable is 2, because we use <h1> for formatting the
349 document title."
350 :group 'org-export-html
351 :type 'integer)
353 (defcustom org-html-format-headline-function nil
354 "Function to format headline text.
356 This function will be called with 5 arguments:
357 TODO the todo keyword (string or nil).
358 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
359 PRIORITY the priority of the headline (integer or nil)
360 TEXT the main headline text (string).
361 TAGS the tags (string or nil).
363 The function result will be used in the section format string."
364 :group 'org-export-html
365 :type 'function)
368 ;;;; HTML-specific
370 (defcustom org-html-allow-name-attribute-in-anchors t
371 "When nil, do not set \"name\" attribute in anchors.
372 By default, anchors are formatted with both \"id\" and \"name\"
373 attributes, when appropriate."
374 :group 'org-export-html
375 :type 'boolean)
378 ;;;; Inlinetasks
380 (defcustom org-html-format-inlinetask-function nil
381 "Function called to format an inlinetask in HTML code.
383 The function must accept six parameters:
384 TODO the todo keyword, as a string
385 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
386 PRIORITY the inlinetask priority, as a string
387 NAME the inlinetask name, as a string.
388 TAGS the inlinetask tags, as a list of strings.
389 CONTENTS the contents of the inlinetask, as a string.
391 The function should return the string to be exported.
393 For example, the variable could be set to the following function
394 in order to mimic default behaviour:
396 \(defun org-html-format-inlinetask \(todo type priority name tags contents\)
397 \"Format an inline task element for HTML export.\"
398 \(let \(\(full-title
399 \(concat
400 \(when todo
401 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
402 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
403 title
404 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
405 \(format (concat \"\\\\begin{center}\\n\"
406 \"\\\\fbox{\\n\"
407 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
408 \"%s\\n\\n\"
409 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
410 \"%s\"
411 \"\\\\end{minipage}}\"
412 \"\\\\end{center}\")
413 full-title contents))"
414 :group 'org-export-html
415 :type 'function)
418 ;;;; LaTeX
420 (defcustom org-html-with-latex org-export-with-latex
421 "Non-nil means process LaTeX math snippets.
423 When set, the exporter will process LaTeX environments and
424 fragments.
426 This option can also be set with the +OPTIONS line,
427 e.g. \"tex:mathjax\". Allowed values are:
429 nil Ignore math snippets.
430 `verbatim' Keep everything in verbatim
431 `dvipng' Process the LaTeX fragments to images. This will also
432 include processing of non-math environments.
433 `imagemagick' Convert the LaTeX fragments to pdf files and use
434 imagemagick to convert pdf files to png files.
435 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
436 be loaded.
437 t Synonym for `mathjax'."
438 :group 'org-export-html
439 :type '(choice
440 (const :tag "Do not process math in any way" nil)
441 (const :tag "Use dvipng to make images" dvipng)
442 (const :tag "Use imagemagick to make images" imagemagick)
443 (const :tag "Use MathJax to display math" mathjax)
444 (const :tag "Leave math verbatim" verbatim)))
447 ;;;; Links :: Generic
449 (defcustom org-html-link-org-files-as-html t
450 "Non-nil means make file links to `file.org' point to `file.html'.
451 When org-mode is exporting an org-mode file to HTML, links to
452 non-html files are directly put into a href tag in HTML.
453 However, links to other Org-mode files (recognized by the
454 extension `.org.) should become links to the corresponding html
455 file, assuming that the linked org-mode file will also be
456 converted to HTML.
457 When nil, the links still point to the plain `.org' file."
458 :group 'org-export-html
459 :type 'boolean)
462 ;;;; Links :: Inline images
464 (defcustom org-html-inline-images 'maybe
465 "Non-nil means inline images into exported HTML pages.
466 This is done using an <img> tag. When nil, an anchor with href is used to
467 link to the image. If this option is `maybe', then images in links with
468 an empty description will be inlined, while images with a description will
469 be linked only."
470 :group 'org-export-html
471 :type '(choice (const :tag "Never" nil)
472 (const :tag "Always" t)
473 (const :tag "When there is no description" maybe)))
475 (defcustom org-html-inline-image-rules
476 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
477 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
478 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
479 "Rules characterizing image files that can be inlined into HTML.
481 A rule consists in an association whose key is the type of link
482 to consider, and value is a regexp that will be matched against
483 link's path.
485 Note that, by default, the image extension *actually* allowed
486 depend on the way the HTML file is processed. When used with
487 pdflatex, pdf, jpg and png images are OK. When processing
488 through dvi to Postscript, only ps and eps are allowed. The
489 default we use here encompasses both."
490 :group 'org-export-html
491 :type '(alist :key-type (string :tag "Type")
492 :value-type (regexp :tag "Path")))
495 ;;;; Plain Text
497 (defcustom org-html-protect-char-alist
498 '(("&" . "&amp;")
499 ("<" . "&lt;")
500 (">" . "&gt;"))
501 "Alist of characters to be converted by `org-html-protect'."
502 :group 'org-export-html
503 :type '(repeat (cons (string :tag "Character")
504 (string :tag "HTML equivalent"))))
507 ;;;; Src Block
509 (defcustom org-html-htmlize-output-type 'inline-css
510 "Output type to be used by htmlize when formatting code snippets.
511 Choices are `css', to export the CSS selectors only, or `inline-css', to
512 export the CSS attribute values inline in the HTML. We use as default
513 `inline-css', in order to make the resulting HTML self-containing.
515 However, this will fail when using Emacs in batch mode for export, because
516 then no rich font definitions are in place. It will also not be good if
517 people with different Emacs setup contribute HTML files to a website,
518 because the fonts will represent the individual setups. In these cases,
519 it is much better to let Org/Htmlize assign classes only, and to use
520 a style file to define the look of these classes.
521 To get a start for your css file, start Emacs session and make sure that
522 all the faces you are interested in are defined, for example by loading files
523 in all modes you want. Then, use the command
524 \\[org-html-htmlize-generate-css] to extract class definitions."
525 :group 'org-export-html
526 :type '(choice (const css) (const inline-css)))
528 (defcustom org-html-htmlize-font-prefix "org-"
529 "The prefix for CSS class names for htmlize font specifications."
530 :group 'org-export-html
531 :type 'string)
533 (defcustom org-html-htmlized-org-css-url nil
534 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
535 Normally when creating an htmlized version of an Org buffer, htmlize will
536 create CSS to define the font colors. However, this does not work when
537 converting in batch mode, and it also can look bad if different people
538 with different fontification setup work on the same website.
539 When this variable is non-nil, creating an htmlized version of an Org buffer
540 using `org-export-as-org' will include a link to this URL if the
541 setting of `org-html-htmlize-output-type' is 'css."
542 :group 'org-export-html
543 :type '(choice
544 (const :tag "Don't include external stylesheet link" nil)
545 (string :tag "URL or local href")))
548 ;;;; Table
550 (defcustom org-html-table-tag
551 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
552 "The HTML tag that is used to start a table.
553 This must be a <table> tag, but you may change the options like
554 borders and spacing."
555 :group 'org-export-html
556 :type 'string)
558 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
559 "The opening tag for table header fields.
560 This is customizable so that alignment options can be specified.
561 The first %s will be filled with the scope of the field, either row or col.
562 The second %s will be replaced by a style entry to align the field.
563 See also the variable `org-html-table-use-header-tags-for-first-column'.
564 See also the variable `org-html-table-align-individual-fields'."
565 :group 'org-export-html
566 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
568 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
569 "The opening tag for table data fields.
570 This is customizable so that alignment options can be specified.
571 The first %s will be filled with the scope of the field, either row or col.
572 The second %s will be replaced by a style entry to align the field.
573 See also the variable `org-html-table-align-individual-fields'."
574 :group 'org-export-html
575 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
577 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
578 "The opening tag for table data fields.
579 This is customizable so that alignment options can be specified.
580 Instead of strings, these can be Lisp forms that will be evaluated
581 for each row in order to construct the table row tags. During evaluation,
582 the variable `head' will be true when this is a header line, nil when this
583 is a body line. And the variable `nline' will contain the line number,
584 starting from 1 in the first header line. For example
586 (setq org-html-table-row-tags
587 (cons '(if head
588 \"<tr>\"
589 (if (= (mod nline 2) 1)
590 \"<tr class=\\\"tr-odd\\\">\"
591 \"<tr class=\\\"tr-even\\\">\"))
592 \"</tr>\"))
594 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
595 :group 'org-export-html
596 :type '(cons
597 (choice :tag "Opening tag"
598 (string :tag "Specify")
599 (sexp))
600 (choice :tag "Closing tag"
601 (string :tag "Specify")
602 (sexp))))
604 (defcustom org-html-table-align-individual-fields t
605 "Non-nil means attach style attributes for alignment to each table field.
606 When nil, alignment will only be specified in the column tags, but this
607 is ignored by some browsers (like Firefox, Safari). Opera does it right
608 though."
609 :group 'org-export-html
610 :type 'boolean)
612 (defcustom org-html-table-use-header-tags-for-first-column nil
613 "Non-nil means format column one in tables with header tags.
614 When nil, also column one will use data tags."
615 :group 'org-export-html
616 :type 'boolean)
618 (defcustom org-html-table-caption-above t
619 "When non-nil, place caption string at the beginning of the table.
620 Otherwise, place it near the end."
621 :group 'org-export-html
622 :type 'boolean)
625 ;;;; Tags
627 (defcustom org-html-tag-class-prefix ""
628 "Prefix to class names for TODO keywords.
629 Each tag gets a class given by the tag itself, with this prefix.
630 The default prefix is empty because it is nice to just use the keyword
631 as a class name. But if you get into conflicts with other, existing
632 CSS classes, then this prefix can be very useful."
633 :group 'org-export-html
634 :type 'string)
637 ;;;; Template :: Generic
639 (defcustom org-html-extension "html"
640 "The extension for exported HTML files."
641 :group 'org-export-html
642 :type 'string)
644 (defcustom org-html-xml-declaration
645 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
646 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
647 "The extension for exported HTML files.
648 %s will be replaced with the charset of the exported file.
649 This may be a string, or an alist with export extensions
650 and corresponding declarations."
651 :group 'org-export-html
652 :type '(choice
653 (string :tag "Single declaration")
654 (repeat :tag "Dependent on extension"
655 (cons (string :tag "Extension")
656 (string :tag "Declaration")))))
658 (defcustom org-html-coding-system 'utf-8
659 "Coding system for HTML export.
660 Use utf-8 as the default value."
661 :group 'org-export-html
662 :type 'coding-system)
664 (defcustom org-html-divs '("preamble" "content" "postamble")
665 "The name of the main divs for HTML export.
666 This is a list of three strings, the first one for the preamble
667 DIV, the second one for the content DIV and the third one for the
668 postamble DIV."
669 :group 'org-export-html
670 :type '(list
671 (string :tag " Div for the preamble:")
672 (string :tag " Div for the content:")
673 (string :tag "Div for the postamble:")))
676 ;;;; Template :: Mathjax
678 (defcustom org-html-mathjax-options
679 '((path "http://orgmode.org/mathjax/MathJax.js")
680 (scale "100")
681 (align "center")
682 (indent "2em")
683 (mathml nil))
684 "Options for MathJax setup.
686 path The path where to find MathJax
687 scale Scaling for the HTML-CSS backend, usually between 100 and 133
688 align How to align display math: left, center, or right
689 indent If align is not center, how far from the left/right side?
690 mathml Should a MathML player be used if available?
691 This is faster and reduces bandwidth use, but currently
692 sometimes has lower spacing quality. Therefore, the default is
693 nil. When browsers get better, this switch can be flipped.
695 You can also customize this for each buffer, using something like
697 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
698 :group 'org-export-html
699 :type '(list :greedy t
700 (list :tag "path (the path from where to load MathJax.js)"
701 (const :format " " path) (string))
702 (list :tag "scale (scaling for the displayed math)"
703 (const :format " " scale) (string))
704 (list :tag "align (alignment of displayed equations)"
705 (const :format " " align) (string))
706 (list :tag "indent (indentation with left or right alignment)"
707 (const :format " " indent) (string))
708 (list :tag "mathml (should MathML display be used is possible)"
709 (const :format " " mathml) (boolean))))
711 (defcustom org-html-mathjax-template
712 "<script type=\"text/javascript\" src=\"%PATH\">
713 <!--/*--><![CDATA[/*><!--*/
714 MathJax.Hub.Config({
715 // Only one of the two following lines, depending on user settings
716 // First allows browser-native MathML display, second forces HTML/CSS
717 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
718 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
719 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
720 \"TeX/noUndefined.js\"],
721 tex2jax: {
722 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
723 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
724 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
725 ignoreClass: \"tex2jax_ignore\",
726 processEscapes: false,
727 processEnvironments: true,
728 preview: \"TeX\"
730 showProcessingMessages: true,
731 displayAlign: \"%ALIGN\",
732 displayIndent: \"%INDENT\",
734 \"HTML-CSS\": {
735 scale: %SCALE,
736 availableFonts: [\"STIX\",\"TeX\"],
737 preferredFont: \"TeX\",
738 webFont: \"TeX\",
739 imageFont: \"TeX\",
740 showMathMenu: true,
742 MMLorHTML: {
743 prefer: {
744 MSIE: \"MML\",
745 Firefox: \"MML\",
746 Opera: \"HTML\",
747 other: \"HTML\"
751 /*]]>*///-->
752 </script>"
753 "The MathJax setup for XHTML files."
754 :group 'org-export-html
755 :type 'string)
758 ;;;; Template :: Postamble
760 (defcustom org-html-postamble 'auto
761 "Non-nil means insert a postamble in HTML export.
763 When `t', insert a string as defined by the formatting string in
764 `org-html-postamble-format'. When set to a string, this
765 string overrides `org-html-postamble-format'. When set to
766 'auto, discard `org-html-postamble-format' and honor
767 `org-export-author/email/creator-info' variables. When set to a
768 function, apply this function and insert the returned string.
769 The function takes the property list of export options as its
770 only argument.
772 Setting :html-postamble in publishing projects will take
773 precedence over this variable."
774 :group 'org-export-html
775 :type '(choice (const :tag "No postamble" nil)
776 (const :tag "Auto preamble" 'auto)
777 (const :tag "Default formatting string" t)
778 (string :tag "Custom formatting string")
779 (function :tag "Function (must return a string)")))
781 (defcustom org-html-postamble-format
782 '(("en" "<p class=\"author\">Author: %a (%e)</p>
783 <p class=\"date\">Date: %d</p>
784 <p class=\"creator\">Generated by %c</p>
785 <p class=\"xhtml-validation\">%v</p>"))
786 "Alist of languages and format strings for the HTML postamble.
788 The first element of each list is the language code, as used for
789 the #+LANGUAGE keyword.
791 The second element of each list is a format string to format the
792 postamble itself. This format string can contain these elements:
794 %a stands for the author's name.
795 %e stands for the author's email.
796 %d stands for the date.
797 %c will be replaced by information about Org/Emacs versions.
798 %v will be replaced by `org-html-validation-link'.
800 If you need to use a \"%\" character, you need to escape it
801 like that: \"%%\"."
802 :group 'org-export-html
803 :type '(alist :key-type (string :tag "Language")
804 :value-type (string :tag "Format string")))
806 (defcustom org-html-validation-link
807 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
808 "Link to HTML validation service."
809 :group 'org-export-html
810 :type 'string)
812 (defcustom org-html-creator-string
813 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
814 (if (fboundp 'org-version) (org-version) "(Unknown)")
815 emacs-version)
816 "String to insert at the end of the HTML document."
817 :group 'org-export-html
818 :type '(string :tag "Creator string"))
821 ;;;; Template :: Preamble
823 (defcustom org-html-preamble t
824 "Non-nil means insert a preamble in HTML export.
826 When `t', insert a string as defined by one of the formatting
827 strings in `org-html-preamble-format'. When set to a
828 string, this string overrides `org-html-preamble-format'.
829 When set to a function, apply this function and insert the
830 returned string. The function takes the property list of export
831 options as its only argument.
833 Setting :html-preamble in publishing projects will take
834 precedence over this variable."
835 :group 'org-export-html
836 :type '(choice (const :tag "No preamble" nil)
837 (const :tag "Default preamble" t)
838 (string :tag "Custom formatting string")
839 (function :tag "Function (must return a string)")))
841 (defcustom org-html-preamble-format '(("en" ""))
842 "Alist of languages and format strings for the HTML preamble.
844 The first element of each list is the language code, as used for
845 the #+LANGUAGE keyword.
847 The second element of each list is a format string to format the
848 preamble itself. This format string can contain these elements:
850 %t stands for the title.
851 %a stands for the author's name.
852 %e stands for the author's email.
853 %d stands for the date.
855 If you need to use a \"%\" character, you need to escape it
856 like that: \"%%\"."
857 :group 'org-export-html
858 :type '(alist :key-type (string :tag "Language")
859 :value-type (string :tag "Format string")))
861 (defcustom org-html-link-up ""
862 "Where should the \"UP\" link of exported HTML pages lead?"
863 :group 'org-export-html
864 :type '(string :tag "File or URL"))
866 (defcustom org-html-link-home ""
867 "Where should the \"HOME\" link of exported HTML pages lead?"
868 :group 'org-export-html
869 :type '(string :tag "File or URL"))
871 (defcustom org-html-home/up-format
872 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
873 <a accesskey=\"h\" href=\"%s\"> UP </a>
875 <a accesskey=\"H\" href=\"%s\"> HOME </a>
876 </div>"
877 "Snippet used to insert the HOME and UP links.
878 This is a format string, the first %s will receive the UP link,
879 the second the HOME link. If both `org-html-link-up' and
880 `org-html-link-home' are empty, the entire snippet will be
881 ignored."
882 :group 'org-export-html
883 :type 'string)
886 ;;;; Template :: Scripts
888 (defcustom org-html-style-include-scripts t
889 "Non-nil means include the JavaScript snippets in exported HTML files.
890 The actual script is defined in `org-html-scripts' and should
891 not be modified."
892 :group 'org-export-html
893 :type 'boolean)
896 ;;;; Template :: Styles
898 (defcustom org-html-style-include-default t
899 "Non-nil means include the default style in exported HTML files.
900 The actual style is defined in `org-html-style-default' and should
901 not be modified. Use the variables `org-html-style' to add
902 your own style information."
903 :group 'org-export-html
904 :type 'boolean)
905 ;;;###autoload
906 (put 'org-html-style-include-default 'safe-local-variable 'booleanp)
908 (defcustom org-html-style ""
909 "Org-wide style definitions for exported HTML files.
911 This variable needs to contain the full HTML structure to provide a style,
912 including the surrounding HTML tags. If you set the value of this variable,
913 you should consider to include definitions for the following classes:
914 title, todo, done, timestamp, timestamp-kwd, tag, target.
916 For example, a valid value would be:
918 <style type=\"text/css\">
919 <![CDATA[
920 p { font-weight: normal; color: gray; }
921 h1 { color: black; }
922 .title { text-align: center; }
923 .todo, .timestamp-kwd { color: red; }
924 .done { color: green; }
926 </style>
928 If you'd like to refer to an external style file, use something like
930 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
932 As the value of this option simply gets inserted into the HTML <head> header,
933 you can \"misuse\" it to add arbitrary text to the header.
934 See also the variable `org-html-style-extra'."
935 :group 'org-export-html
936 :type 'string)
937 ;;;###autoload
938 (put 'org-html-style 'safe-local-variable 'stringp)
940 (defcustom org-html-style-extra ""
941 "Additional style information for HTML export.
942 The value of this variable is inserted into the HTML buffer right after
943 the value of `org-html-style'. Use this variable for per-file
944 settings of style information, and do not forget to surround the style
945 settings with <style>...</style> tags."
946 :group 'org-export-html
947 :type 'string)
948 ;;;###autoload
949 (put 'org-html-style-extra 'safe-local-variable 'stringp)
952 ;;;; Todos
954 (defcustom org-html-todo-kwd-class-prefix ""
955 "Prefix to class names for TODO keywords.
956 Each TODO keyword gets a class given by the keyword itself, with this prefix.
957 The default prefix is empty because it is nice to just use the keyword
958 as a class name. But if you get into conflicts with other, existing
959 CSS classes, then this prefix can be very useful."
960 :group 'org-export-html
961 :type 'string)
963 (defcustom org-html-display-buffer-mode 'html-mode
964 "Default mode when visiting the HTML output."
965 :group 'org-export-html
966 :version "24.3"
967 :type '(choice (function 'html-mode)
968 (function 'nxml-mode)
969 (function :tag "Other mode")))
973 ;;; Internal Functions
975 (defun org-html-format-inline-image (src &optional
976 caption label attr standalone-p)
977 (let* ((id (if (not label) ""
978 (format " id=\"%s\"" (org-export-solidify-link-text label))))
979 (attr (concat attr
980 (cond
981 ((string-match "\\<alt=" (or attr "")) "")
982 ((string-match "^ltxpng/" src)
983 (format " alt=\"%s\""
984 (org-html-encode-plain-text
985 (org-find-text-property-in-string
986 'org-latex-src src))))
987 (t (format " alt=\"%s\""
988 (file-name-nondirectory src)))))))
989 (cond
990 (standalone-p
991 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
992 (format "\n<div%s class=\"figure\">%s%s\n</div>"
993 id (format "\n<p>%s</p>" img)
994 (when caption (format "\n<p>%s</p>" caption)))))
995 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
997 (defun org-html--textarea-block (element)
998 "Transcode ELEMENT into a textarea block.
999 ELEMENT is either a src block or an example block."
1000 (let ((code (car (org-export-unravel-code element)))
1001 (attr (org-export-read-attribute :attr_html element)))
1002 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1003 (or (plist-get attr :width) 80)
1004 (or (plist-get attr :height) (org-count-lines code))
1005 code)))
1008 ;;;; Bibliography
1010 (defun org-html-bibliography ()
1011 "Find bibliography, cut it out and return it."
1012 (catch 'exit
1013 (let (beg end (cnt 1) bib)
1014 (save-excursion
1015 (goto-char (point-min))
1016 (when (re-search-forward
1017 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1018 (setq beg (match-beginning 0))
1019 (while (re-search-forward "</?div\\>" nil t)
1020 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1021 (when (= cnt 0)
1022 (and (looking-at ">") (forward-char 1))
1023 (setq bib (buffer-substring beg (point)))
1024 (delete-region beg (point))
1025 (throw 'exit bib))))
1026 nil))))
1028 ;;;; Table
1030 (defun org-html-splice-attributes (tag attributes)
1031 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1032 (if (not attributes)
1034 (let (oldatt newatt)
1035 (setq oldatt (org-extract-attributes-from-string tag)
1036 tag (pop oldatt)
1037 newatt (cdr (org-extract-attributes-from-string attributes)))
1038 (while newatt
1039 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1040 (if (string-match ">" tag)
1041 (setq tag
1042 (replace-match (concat (org-attributes-to-string oldatt) ">")
1043 t t tag)))
1044 tag)))
1046 (defun org-export-splice-style (style extra)
1047 "Splice EXTRA into STYLE, just before \"</style>\"."
1048 (if (and (stringp extra)
1049 (string-match "\\S-" extra)
1050 (string-match "</style>" style))
1051 (concat (substring style 0 (match-beginning 0))
1052 "\n" extra "\n"
1053 (substring style (match-beginning 0)))
1054 style))
1056 (defun org-html-htmlize-region-for-paste (beg end)
1057 "Convert the region to HTML, using htmlize.el.
1058 This is much like `htmlize-region-for-paste', only that it uses
1059 the settings define in the org-... variables."
1060 (let* ((htmlize-output-type org-html-htmlize-output-type)
1061 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1062 (htmlbuf (htmlize-region beg end)))
1063 (unwind-protect
1064 (with-current-buffer htmlbuf
1065 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1066 (plist-get htmlize-buffer-places 'content-end)))
1067 (kill-buffer htmlbuf))))
1069 ;;;###autoload
1070 (defun org-html-htmlize-generate-css ()
1071 "Create the CSS for all font definitions in the current Emacs session.
1072 Use this to create face definitions in your CSS style file that can then
1073 be used by code snippets transformed by htmlize.
1074 This command just produces a buffer that contains class definitions for all
1075 faces used in the current Emacs session. You can copy and paste the ones you
1076 need into your CSS file.
1078 If you then set `org-html-htmlize-output-type' to `css', calls
1079 to the function `org-html-htmlize-region-for-paste' will
1080 produce code that uses these same face definitions."
1081 (interactive)
1082 (require 'htmlize)
1083 (and (get-buffer "*html*") (kill-buffer "*html*"))
1084 (with-temp-buffer
1085 (let ((fl (face-list))
1086 (htmlize-css-name-prefix "org-")
1087 (htmlize-output-type 'css)
1088 f i)
1089 (while (setq f (pop fl)
1090 i (and f (face-attribute f :inherit)))
1091 (when (and (symbolp f) (or (not i) (not (listp i))))
1092 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1093 (htmlize-region (point-min) (point-max))))
1094 (org-pop-to-buffer-same-window "*html*")
1095 (goto-char (point-min))
1096 (if (re-search-forward "<style" nil t)
1097 (delete-region (point-min) (match-beginning 0)))
1098 (if (re-search-forward "</style>" nil t)
1099 (delete-region (1+ (match-end 0)) (point-max)))
1100 (beginning-of-line 1)
1101 (if (looking-at " +") (replace-match ""))
1102 (goto-char (point-min)))
1104 (defun org-html--make-string (n string)
1105 "Build a string by concatenating N times STRING."
1106 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1108 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1109 "Turn todo keyword into a valid class name.
1110 Replaces invalid characters with \"_\"."
1111 (save-match-data
1112 (while (string-match "[^a-zA-Z0-9_]" kwd)
1113 (setq kwd (replace-match "_" t t kwd))))
1114 kwd)
1116 (defun org-html-format-footnote-reference (n def refcnt)
1117 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1118 (format org-html-footnote-format
1119 (let* ((id (format "fnr.%s%s" n extra))
1120 (href (format " href=\"#fn.%s\"" n))
1121 (attributes (concat " class=\"footref\"" href)))
1122 (org-html--anchor id n attributes)))))
1124 (defun org-html-format-footnotes-section (section-name definitions)
1125 (if (not definitions) ""
1126 (format org-html-footnotes-section section-name definitions)))
1128 (defun org-html-format-footnote-definition (fn)
1129 (let ((n (car fn)) (def (cdr fn)))
1130 (format
1131 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1132 (format org-html-footnote-format
1133 (let* ((id (format "fn.%s" n))
1134 (href (format " href=\"#fnr.%s\"" n))
1135 (attributes (concat " class=\"footnum\"" href)))
1136 (org-html--anchor id n attributes)))
1137 def)))
1139 (defun org-html-footnote-section (info)
1140 (let* ((fn-alist (org-export-collect-footnote-definitions
1141 (plist-get info :parse-tree) info))
1143 (fn-alist
1144 (loop for (n type raw) in fn-alist collect
1145 (cons n (if (eq (org-element-type raw) 'org-data)
1146 (org-trim (org-export-data raw info))
1147 (format "<p>%s</p>"
1148 (org-trim (org-export-data raw info))))))))
1149 (when fn-alist
1150 (org-html-format-footnotes-section
1151 (org-html--translate "Footnotes" info)
1152 (format
1153 "<table>\n%s\n</table>\n"
1154 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1158 ;;; Template
1160 (defun org-html--build-meta-info (info)
1161 "Return meta tags for exported document.
1162 INFO is a plist used as a communication channel."
1163 (let* ((title (org-export-data (plist-get info :title) info))
1164 (author (and (plist-get info :with-author)
1165 (let ((auth (plist-get info :author)))
1166 (and auth (org-export-data auth info)))))
1167 (date (and (plist-get info :with-date)
1168 (let ((date (plist-get info :date)))
1169 (and date (org-export-data date info)))))
1170 (description (plist-get info :description))
1171 (keywords (plist-get info :keywords)))
1172 (concat
1173 (format "<title>%s</title>\n" title)
1174 (format
1175 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1176 (or (and org-html-coding-system
1177 (fboundp 'coding-system-get)
1178 (coding-system-get org-html-coding-system 'mime-charset))
1179 "iso-8859-1"))
1180 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1181 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1182 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1183 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1184 (and description
1185 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1186 (and keywords
1187 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1189 (defun org-html--build-style (info)
1190 "Return style information for exported document.
1191 INFO is a plist used as a communication channel."
1192 (org-element-normalize-string
1193 (concat
1194 (when (plist-get info :html-style-include-default)
1195 (org-element-normalize-string org-html-style-default))
1196 (org-element-normalize-string (plist-get info :html-style))
1197 (when (and (plist-get info :html-htmlized-css-url)
1198 (eq org-html-htmlize-output-type 'css))
1199 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1200 (plist-get info :html-htmlized-css-url)))
1201 (org-element-normalize-string (plist-get info :html-style-extra))
1202 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1204 (defun org-html--build-mathjax-config (info)
1205 "Insert the user setup into the mathjax template.
1206 INFO is a plist used as a communication channel."
1207 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1208 (org-element-map (plist-get info :parse-tree)
1209 '(latex-fragment latex-environment) 'identity info t))
1210 (let ((template org-html-mathjax-template)
1211 (options org-html-mathjax-options)
1212 (in-buffer (or (plist-get info :html-mathjax) ""))
1213 name val (yes " ") (no "// ") x)
1214 (mapc
1215 (lambda (e)
1216 (setq name (car e) val (nth 1 e))
1217 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1218 (setq val (car (read-from-string
1219 (substring in-buffer (match-end 0))))))
1220 (if (not (stringp val)) (setq val (format "%s" val)))
1221 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1222 (setq template (replace-match val t t template))))
1223 options)
1224 (setq val (nth 1 (assq 'mathml options)))
1225 (if (string-match (concat "\\<mathml:") in-buffer)
1226 (setq val (car (read-from-string
1227 (substring in-buffer (match-end 0))))))
1228 ;; Exchange prefixes depending on mathml setting.
1229 (if (not val) (setq x yes yes no no x))
1230 ;; Replace cookies to turn on or off the config/jax lines.
1231 (if (string-match ":MMLYES:" template)
1232 (setq template (replace-match yes t t template)))
1233 (if (string-match ":MMLNO:" template)
1234 (setq template (replace-match no t t template)))
1235 ;; Return the modified template.
1236 (org-element-normalize-string template))))
1238 (defun org-html--build-preamble (info)
1239 "Return document preamble as a string, or nil.
1240 INFO is a plist used as a communication channel."
1241 (let ((preamble (plist-get info :html-preamble)))
1242 (when preamble
1243 (let ((preamble-contents
1244 (if (functionp preamble) (funcall preamble info)
1245 (let ((title (org-export-data (plist-get info :title) info))
1246 (date (if (not (plist-get info :with-date)) ""
1247 (org-export-data (plist-get info :date) info)))
1248 (author (if (not (plist-get info :with-author)) ""
1249 (org-export-data (plist-get info :author) info)))
1250 (email (if (not (plist-get info :with-email)) ""
1251 (plist-get info :email))))
1252 (if (stringp preamble)
1253 (format-spec preamble
1254 `((?t . ,title) (?a . ,author)
1255 (?d . ,date) (?e . ,email)))
1256 (format-spec
1257 (or (cadr (assoc (plist-get info :language)
1258 org-html-preamble-format))
1259 (cadr (assoc "en" org-html-preamble-format)))
1260 `((?t . ,title) (?a . ,author)
1261 (?d . ,date) (?e . ,email))))))))
1262 (when (org-string-nw-p preamble-contents)
1263 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1264 (org-element-normalize-string preamble-contents)
1265 "</div>\n"))))))
1267 (defun org-html--build-postamble (info)
1268 "Return document postamble as a string, or nil.
1269 INFO is a plist used as a communication channel."
1270 (let ((postamble (plist-get info :html-postamble)))
1271 (when postamble
1272 (let ((postamble-contents
1273 (if (functionp postamble) (funcall postamble info)
1274 (let ((date (if (not (plist-get info :with-date)) ""
1275 (org-export-data (plist-get info :date) info)))
1276 (author (let ((author (plist-get info :author)))
1277 (and author (org-export-data author info))))
1278 (email (mapconcat
1279 (lambda (e)
1280 (format "<a href=\"mailto:%s\">%s</a>" e e))
1281 (split-string (plist-get info :email) ",+ *")
1282 ", "))
1283 (html-validation-link (or org-html-validation-link ""))
1284 (creator-info (plist-get info :creator)))
1285 (cond ((stringp postamble)
1286 (format-spec postamble
1287 `((?a . ,author) (?e . ,email)
1288 (?d . ,date) (?c . ,creator-info)
1289 (?v . ,html-validation-link))))
1290 ((eq postamble 'auto)
1291 (concat
1292 (when (plist-get info :time-stamp-file)
1293 (format "<p class=\"date\">%s: %s</p>\n"
1294 (org-html--translate "Date" info)
1295 date))
1296 (when (and (plist-get info :with-author) author)
1297 (format "<p class=\"author\">%s : %s</p>\n"
1298 (org-html--translate "Author" info)
1299 author))
1300 (when (and (plist-get info :with-email) email)
1301 (format "<p class=\"email\">%s </p>\n" email))
1302 (when (plist-get info :with-creator)
1303 (format "<p class=\"creator\">%s</p>\n"
1304 creator-info))
1305 html-validation-link "\n"))
1306 (t (format-spec
1307 (or (cadr (assoc (plist-get info :language)
1308 org-html-postamble-format))
1309 (cadr (assoc "en" org-html-postamble-format)))
1310 `((?a . ,author) (?e . ,email)
1311 (?d . ,date) (?c . ,creator-info)
1312 (?v . ,html-validation-link)))))))))
1313 (when (org-string-nw-p postamble-contents)
1314 (concat
1315 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1316 (org-element-normalize-string postamble-contents)
1317 "</div>\n"))))))
1319 (defun org-html-inner-template (contents info)
1320 "Return body of document string after HTML conversion.
1321 CONTENTS is the transcoded contents string. INFO is a plist
1322 holding export options."
1323 (concat
1324 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1325 ;; Document title.
1326 (format "<h1 class=\"title\">%s</h1>\n"
1327 (org-export-data (plist-get info :title) info))
1328 ;; Table of contents.
1329 (let ((depth (plist-get info :with-toc)))
1330 (when depth (org-html-toc depth info)))
1331 ;; Document contents.
1332 contents
1333 ;; Footnotes section.
1334 (org-html-footnote-section info)
1335 ;; Bibliography.
1336 (org-html-bibliography)
1337 "\n</div>"))
1339 (defun org-html-template (contents info)
1340 "Return complete document string after HTML conversion.
1341 CONTENTS is the transcoded contents string. INFO is a plist
1342 holding export options."
1343 (concat
1344 (format
1345 (or (and (stringp org-html-xml-declaration)
1346 org-html-xml-declaration)
1347 (cdr (assoc (plist-get info :html-extension)
1348 org-html-xml-declaration))
1349 (cdr (assoc "html" org-html-xml-declaration))
1352 (or (and org-html-coding-system
1353 (fboundp 'coding-system-get)
1354 (coding-system-get org-html-coding-system 'mime-charset))
1355 "iso-8859-1"))
1356 "\n"
1357 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1358 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1359 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1360 (plist-get info :language) (plist-get info :language))
1361 "<head>\n"
1362 (org-html--build-meta-info info)
1363 (org-html--build-style info)
1364 (org-html--build-mathjax-config info)
1365 "</head>\n"
1366 "<body>\n"
1367 (let ((link-up (org-trim (plist-get info :html-link-up)))
1368 (link-home (org-trim (plist-get info :html-link-home))))
1369 (unless (and (string= link-up "") (string= link-up ""))
1370 (format org-html-home/up-format
1371 (or link-up link-home)
1372 (or link-home link-up))))
1373 ;; Preamble.
1374 (org-html--build-preamble info)
1375 ;; Document contents.
1376 contents
1377 ;; Postamble.
1378 (org-html--build-postamble info)
1379 ;; Closing document.
1380 "</body>\n</html>"))
1382 (defun org-html--translate (s info)
1383 "Translate string S according to specified language.
1384 INFO is a plist used as a communication channel."
1385 (org-export-translate s :html info))
1387 ;;;; Anchor
1389 (defun org-html--anchor (&optional id desc attributes)
1390 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1391 (attributes (concat (and id (format " id=\"%s\"" id))
1392 (and name (format " name=\"%s\"" name))
1393 attributes)))
1394 (format "<a%s>%s</a>" attributes (or desc ""))))
1396 ;;;; Todo
1398 (defun org-html--todo (todo)
1399 (when todo
1400 (format "<span class=\"%s %s%s\">%s</span>"
1401 (if (member todo org-done-keywords) "done" "todo")
1402 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1403 todo)))
1405 ;;;; Tags
1407 (defun org-html--tags (tags)
1408 (when tags
1409 (format "<span class=\"tag\">%s</span>"
1410 (mapconcat
1411 (lambda (tag)
1412 (format "<span class=\"%s\">%s</span>"
1413 (concat org-html-tag-class-prefix
1414 (org-html-fix-class-name tag))
1415 tag))
1416 tags "&nbsp;"))))
1418 ;;;; Headline
1420 (defun* org-html-format-headline
1421 (todo todo-type priority text tags
1422 &key level section-number headline-label &allow-other-keys)
1423 (let ((section-number
1424 (when section-number
1425 (format "<span class=\"section-number-%d\">%s</span> "
1426 level section-number)))
1427 (todo (org-html--todo todo))
1428 (tags (org-html--tags tags)))
1429 (concat section-number todo (and todo " ") text
1430 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1432 ;;;; Src Code
1434 (defun org-html-fontify-code (code lang)
1435 "Color CODE with htmlize library.
1436 CODE is a string representing the source code to colorize. LANG
1437 is the language used for CODE, as a string, or nil."
1438 (when code
1439 (cond
1440 ;; Case 1: No lang. Possibly an example block.
1441 ((not lang)
1442 ;; Simple transcoding.
1443 (org-html-encode-plain-text code))
1444 ;; Case 2: No htmlize or an inferior version of htmlize
1445 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1446 ;; Emit a warning.
1447 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1448 ;; Simple transcoding.
1449 (org-html-encode-plain-text code))
1451 ;; Map language
1452 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1453 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1454 (cond
1455 ;; Case 1: Language is not associated with any Emacs mode
1456 ((not (functionp lang-mode))
1457 ;; Simple transcoding.
1458 (org-html-encode-plain-text code))
1459 ;; Case 2: Default. Fontify code.
1461 ;; htmlize
1462 (setq code (with-temp-buffer
1463 ;; Switch to language-specific mode.
1464 (funcall lang-mode)
1465 (insert code)
1466 ;; Fontify buffer.
1467 (font-lock-fontify-buffer)
1468 ;; Remove formatting on newline characters.
1469 (save-excursion
1470 (let ((beg (point-min))
1471 (end (point-max)))
1472 (goto-char beg)
1473 (while (progn (end-of-line) (< (point) end))
1474 (put-text-property (point) (1+ (point)) 'face nil)
1475 (forward-char 1))))
1476 (org-src-mode)
1477 (set-buffer-modified-p nil)
1478 ;; Htmlize region.
1479 (org-html-htmlize-region-for-paste
1480 (point-min) (point-max))))
1481 ;; Strip any encolosing <pre></pre> tags.
1482 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1483 (match-string 1 code)
1484 code))))))))
1486 (defun org-html-do-format-code
1487 (code &optional lang refs retain-labels num-start)
1488 "Format CODE string as source code.
1489 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1490 respectively, the language of the source code, as a string, an
1491 alist between line numbers and references (as returned by
1492 `org-export-unravel-code'), a boolean specifying if labels should
1493 appear in the source code, and the number associated to the first
1494 line of code."
1495 (let* ((code-lines (org-split-string code "\n"))
1496 (code-length (length code-lines))
1497 (num-fmt
1498 (and num-start
1499 (format "%%%ds: "
1500 (length (number-to-string (+ code-length num-start))))))
1501 (code (org-html-fontify-code code lang)))
1502 (org-export-format-code
1503 code
1504 (lambda (loc line-num ref)
1505 (setq loc
1506 (concat
1507 ;; Add line number, if needed.
1508 (when num-start
1509 (format "<span class=\"linenr\">%s</span>"
1510 (format num-fmt line-num)))
1511 ;; Transcoded src line.
1513 ;; Add label, if needed.
1514 (when (and ref retain-labels) (format " (%s)" ref))))
1515 ;; Mark transcoded line as an anchor, if needed.
1516 (if (not ref) loc
1517 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1518 ref loc)))
1519 num-start refs)))
1521 (defun org-html-format-code (element info)
1522 "Format contents of ELEMENT as source code.
1523 ELEMENT is either an example block or a src block. INFO is
1524 a plist used as a communication channel."
1525 (let* ((lang (org-element-property :language element))
1526 ;; Extract code and references.
1527 (code-info (org-export-unravel-code element))
1528 (code (car code-info))
1529 (refs (cdr code-info))
1530 ;; Does the src block contain labels?
1531 (retain-labels (org-element-property :retain-labels element))
1532 ;; Does it have line numbers?
1533 (num-start (case (org-element-property :number-lines element)
1534 (continued (org-export-get-loc element info))
1535 (new 0))))
1536 (org-html-do-format-code code lang refs retain-labels num-start)))
1540 ;;; Tables of Contents
1542 (defun org-html-toc (depth info)
1543 "Build a table of contents.
1544 DEPTH is an integer specifying the depth of the table. INFO is
1545 a plist used as a communication channel. Return the table of
1546 contents as a string, or nil if it is empty."
1547 (let ((toc-entries
1548 (mapcar (lambda (headline)
1549 (cons (org-html--format-toc-headline headline info)
1550 (org-export-get-relative-level headline info)))
1551 (org-export-collect-headlines info depth))))
1552 (when toc-entries
1553 (concat "<div id=\"table-of-contents\">\n"
1554 (format "<h%d>%s</h%d>\n"
1555 org-html-toplevel-hlevel
1556 (org-html--translate "Table of Contents" info)
1557 org-html-toplevel-hlevel)
1558 "<div id=\"text-table-of-contents\">"
1559 (org-html--toc-text toc-entries)
1560 "</div>\n"
1561 "</div>\n"))))
1563 (defun org-html--toc-text (toc-entries)
1564 "Return innards of a table of contents, as a string.
1565 TOC-ENTRIES is an alist where key is an entry title, as a string,
1566 and value is its relative level, as an integer."
1567 (let* ((prev-level (1- (cdar toc-entries)))
1568 (start-level prev-level))
1569 (concat
1570 (mapconcat
1571 (lambda (entry)
1572 (let ((headline (car entry))
1573 (level (cdr entry)))
1574 (concat
1575 (let* ((cnt (- level prev-level))
1576 (times (if (> cnt 0) (1- cnt) (- cnt)))
1577 rtn)
1578 (setq prev-level level)
1579 (concat
1580 (org-html--make-string
1581 times (cond ((> cnt 0) "\n<ul>\n<li>")
1582 ((< cnt 0) "</li>\n</ul>\n")))
1583 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1584 headline)))
1585 toc-entries "")
1586 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1588 (defun org-html--format-toc-headline (headline info)
1589 "Return an appropriate table of contents entry for HEADLINE.
1590 INFO is a plist used as a communication channel."
1591 (let* ((headline-number (org-export-get-headline-number headline info))
1592 (section-number
1593 (and (not (org-export-low-level-p headline info))
1594 (org-export-numbered-headline-p headline info)
1595 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1596 (tags (and (eq (plist-get info :with-tags) t)
1597 (org-export-get-tags headline info))))
1598 (format "<a href=\"#%s\">%s</a>"
1599 ;; Label.
1600 (org-export-solidify-link-text
1601 (or (org-element-property :CUSTOM_ID headline)
1602 (concat "sec-" (mapconcat 'number-to-string
1603 headline-number "-"))))
1604 ;; Body.
1605 (concat section-number
1606 (org-export-data
1607 (org-export-get-optional-title headline info) info)
1608 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags)))))
1610 (defun org-html-list-of-listings (info)
1611 "Build a list of listings.
1612 INFO is a plist used as a communication channel. Return the list
1613 of listings as a string, or nil if it is empty."
1614 (let ((lol-entries (org-export-collect-listings info)))
1615 (when lol-entries
1616 (concat "<div id=\"list-of-listings\">\n"
1617 (format "<h%d>%s</h%d>\n"
1618 org-html-toplevel-hlevel
1619 (org-html--translate "List of Listings" info)
1620 org-html-toplevel-hlevel)
1621 "<div id=\"text-list-of-listings\">\n<ul>\n"
1622 (let ((count 0)
1623 (initial-fmt (org-html--translate "Listing %d:" info)))
1624 (mapconcat
1625 (lambda (entry)
1626 (let ((label (org-element-property :name entry))
1627 (title (org-trim
1628 (org-export-data
1629 (or (org-export-get-caption entry t)
1630 (org-export-get-caption entry))
1631 info))))
1632 (concat
1633 "<li>"
1634 (if (not label)
1635 (concat (format initial-fmt (incf count)) " " title)
1636 (format "<a href=\"#%s\">%s %s</a>"
1637 (org-export-solidify-link-text label)
1638 (format initial-fmt (incf count))
1639 title))
1640 "</li>")))
1641 lol-entries "\n"))
1642 "\n</ul>\n</div>\n</div>"))))
1644 (defun org-html-list-of-tables (info)
1645 "Build a list of tables.
1646 INFO is a plist used as a communication channel. Return the list
1647 of tables as a string, or nil if it is empty."
1648 (let ((lol-entries (org-export-collect-tables info)))
1649 (when lol-entries
1650 (concat "<div id=\"list-of-tables\">\n"
1651 (format "<h%d>%s</h%d>\n"
1652 org-html-toplevel-hlevel
1653 (org-html--translate "List of Tables" info)
1654 org-html-toplevel-hlevel)
1655 "<div id=\"text-list-of-tables\">\n<ul>\n"
1656 (let ((count 0)
1657 (initial-fmt (org-html--translate "Table %d:" info)))
1658 (mapconcat
1659 (lambda (entry)
1660 (let ((label (org-element-property :name entry))
1661 (title (org-trim
1662 (org-export-data
1663 (or (org-export-get-caption entry t)
1664 (org-export-get-caption entry))
1665 info))))
1666 (concat
1667 "<li>"
1668 (if (not label)
1669 (concat (format initial-fmt (incf count)) " " title)
1670 (format "<a href=\"#%s\">%s %s</a>"
1671 (org-export-solidify-link-text label)
1672 (format initial-fmt (incf count))
1673 title))
1674 "</li>")))
1675 lol-entries "\n"))
1676 "\n</ul>\n</div>\n</div>"))))
1680 ;;; Transcode Functions
1682 ;;;; Bold
1684 (defun org-html-bold (bold contents info)
1685 "Transcode BOLD from Org to HTML.
1686 CONTENTS is the text with bold markup. INFO is a plist holding
1687 contextual information."
1688 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1689 contents))
1692 ;;;; Center Block
1694 (defun org-html-center-block (center-block contents info)
1695 "Transcode a CENTER-BLOCK element from Org to HTML.
1696 CONTENTS holds the contents of the block. INFO is a plist
1697 holding contextual information."
1698 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1701 ;;;; Clock
1703 (defun org-html-clock (clock contents info)
1704 "Transcode a CLOCK element from Org to HTML.
1705 CONTENTS is nil. INFO is a plist used as a communication
1706 channel."
1707 (format "<p>
1708 <span class=\"timestamp-wrapper\">
1709 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1710 </span>
1711 </p>"
1712 org-clock-string
1713 (org-translate-time
1714 (org-element-property :raw-value
1715 (org-element-property :value clock)))
1716 (let ((time (org-element-property :duration clock)))
1717 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1720 ;;;; Code
1722 (defun org-html-code (code contents info)
1723 "Transcode CODE from Org to HTML.
1724 CONTENTS is nil. INFO is a plist holding contextual
1725 information."
1726 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1727 (org-element-property :value code)))
1730 ;;;; Drawer
1732 (defun org-html-drawer (drawer contents info)
1733 "Transcode a DRAWER element from Org to HTML.
1734 CONTENTS holds the contents of the block. INFO is a plist
1735 holding contextual information."
1736 (if (functionp org-html-format-drawer-function)
1737 (funcall org-html-format-drawer-function
1738 (org-element-property :drawer-name drawer)
1739 contents)
1740 ;; If there's no user defined function: simply
1741 ;; display contents of the drawer.
1742 contents))
1745 ;;;; Dynamic Block
1747 (defun org-html-dynamic-block (dynamic-block contents info)
1748 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1749 CONTENTS holds the contents of the block. INFO is a plist
1750 holding contextual information. See `org-export-data'."
1751 contents)
1754 ;;;; Entity
1756 (defun org-html-entity (entity contents info)
1757 "Transcode an ENTITY object from Org to HTML.
1758 CONTENTS are the definition itself. INFO is a plist holding
1759 contextual information."
1760 (org-element-property :html entity))
1763 ;;;; Example Block
1765 (defun org-html-example-block (example-block contents info)
1766 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1767 CONTENTS is nil. INFO is a plist holding contextual
1768 information."
1769 (if (org-export-read-attribute :attr_html example-block :textarea)
1770 (org-html--textarea-block example-block)
1771 (format "<pre class=\"example\">\n%s</pre>"
1772 (org-html-format-code example-block info))))
1775 ;;;; Export Snippet
1777 (defun org-html-export-snippet (export-snippet contents info)
1778 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1779 CONTENTS is nil. INFO is a plist holding contextual
1780 information."
1781 (when (eq (org-export-snippet-backend export-snippet) 'html)
1782 (org-element-property :value export-snippet)))
1785 ;;;; Export Block
1787 (defun org-html-export-block (export-block contents info)
1788 "Transcode a EXPORT-BLOCK element from Org to HTML.
1789 CONTENTS is nil. INFO is a plist holding contextual information."
1790 (when (string= (org-element-property :type export-block) "HTML")
1791 (org-remove-indentation (org-element-property :value export-block))))
1794 ;;;; Fixed Width
1796 (defun org-html-fixed-width (fixed-width contents info)
1797 "Transcode a FIXED-WIDTH element from Org to HTML.
1798 CONTENTS is nil. INFO is a plist holding contextual information."
1799 (format "<pre class=\"example\">\n%s</pre>"
1800 (org-html-do-format-code
1801 (org-remove-indentation
1802 (org-element-property :value fixed-width)))))
1805 ;;;; Footnote Reference
1807 (defun org-html-footnote-reference (footnote-reference contents info)
1808 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1809 CONTENTS is nil. INFO is a plist holding contextual information."
1810 (concat
1811 ;; Insert separator between two footnotes in a row.
1812 (let ((prev (org-export-get-previous-element footnote-reference info)))
1813 (when (eq (org-element-type prev) 'footnote-reference)
1814 org-html-footnote-separator))
1815 (cond
1816 ((not (org-export-footnote-first-reference-p footnote-reference info))
1817 (org-html-format-footnote-reference
1818 (org-export-get-footnote-number footnote-reference info)
1819 "IGNORED" 100))
1820 ;; Inline definitions are secondary strings.
1821 ((eq (org-element-property :type footnote-reference) 'inline)
1822 (org-html-format-footnote-reference
1823 (org-export-get-footnote-number footnote-reference info)
1824 "IGNORED" 1))
1825 ;; Non-inline footnotes definitions are full Org data.
1826 (t (org-html-format-footnote-reference
1827 (org-export-get-footnote-number footnote-reference info)
1828 "IGNORED" 1)))))
1831 ;;;; Headline
1833 (defun org-html-format-headline--wrap
1834 (headline info &optional format-function &rest extra-keys)
1835 "Transcode a HEADLINE element from Org to HTML.
1836 CONTENTS holds the contents of the headline. INFO is a plist
1837 holding contextual information."
1838 (let* ((level (+ (org-export-get-relative-level headline info)
1839 (1- org-html-toplevel-hlevel)))
1840 (headline-number (org-export-get-headline-number headline info))
1841 (section-number (and (not (org-export-low-level-p headline info))
1842 (org-export-numbered-headline-p headline info)
1843 (mapconcat 'number-to-string
1844 headline-number ".")))
1845 (todo (and (plist-get info :with-todo-keywords)
1846 (let ((todo (org-element-property :todo-keyword headline)))
1847 (and todo (org-export-data todo info)))))
1848 (todo-type (and todo (org-element-property :todo-type headline)))
1849 (priority (and (plist-get info :with-priority)
1850 (org-element-property :priority headline)))
1851 (text (org-export-data (org-element-property :title headline) info))
1852 (tags (and (plist-get info :with-tags)
1853 (org-export-get-tags headline info)))
1854 (headline-label (or (org-element-property :CUSTOM_ID headline)
1855 (concat "sec-" (mapconcat 'number-to-string
1856 headline-number "-"))))
1857 (format-function (cond
1858 ((functionp format-function) format-function)
1859 ((functionp org-html-format-headline-function)
1860 (function*
1861 (lambda (todo todo-type priority text tags
1862 &allow-other-keys)
1863 (funcall org-html-format-headline-function
1864 todo todo-type priority text tags))))
1865 (t 'org-html-format-headline))))
1866 (apply format-function
1867 todo todo-type priority text tags
1868 :headline-label headline-label :level level
1869 :section-number section-number extra-keys)))
1871 (defun org-html-headline (headline contents info)
1872 "Transcode a HEADLINE element from Org to HTML.
1873 CONTENTS holds the contents of the headline. INFO is a plist
1874 holding contextual information."
1875 ;; Empty contents?
1876 (setq contents (or contents ""))
1877 (let* ((numberedp (org-export-numbered-headline-p headline info))
1878 (level (org-export-get-relative-level headline info))
1879 (text (org-export-data (org-element-property :title headline) info))
1880 (todo (and (plist-get info :with-todo-keywords)
1881 (let ((todo (org-element-property :todo-keyword headline)))
1882 (and todo (org-export-data todo info)))))
1883 (todo-type (and todo (org-element-property :todo-type headline)))
1884 (tags (and (plist-get info :with-tags)
1885 (org-export-get-tags headline info)))
1886 (priority (and (plist-get info :with-priority)
1887 (org-element-property :priority headline)))
1888 (section-number (and (org-export-numbered-headline-p headline info)
1889 (mapconcat 'number-to-string
1890 (org-export-get-headline-number
1891 headline info) ".")))
1892 ;; Create the headline text.
1893 (full-text (org-html-format-headline--wrap headline info)))
1894 (cond
1895 ;; Case 1: This is a footnote section: ignore it.
1896 ((org-element-property :footnote-section-p headline) nil)
1897 ;; Case 2. This is a deep sub-tree: export it as a list item.
1898 ;; Also export as items headlines for which no section
1899 ;; format has been found.
1900 ((org-export-low-level-p headline info)
1901 ;; Build the real contents of the sub-tree.
1902 (let* ((type (if numberedp 'ordered 'unordered))
1903 (itemized-body (org-html-format-list-item
1904 contents type nil nil full-text)))
1905 (concat
1906 (and (org-export-first-sibling-p headline info)
1907 (org-html-begin-plain-list type))
1908 itemized-body
1909 (and (org-export-last-sibling-p headline info)
1910 (org-html-end-plain-list type)))))
1911 ;; Case 3. Standard headline. Export it as a section.
1913 (let* ((section-number (mapconcat 'number-to-string
1914 (org-export-get-headline-number
1915 headline info) "-"))
1916 (ids (remove 'nil
1917 (list (org-element-property :CUSTOM_ID headline)
1918 (concat "sec-" section-number)
1919 (org-element-property :ID headline))))
1920 (preferred-id (car ids))
1921 (extra-ids (cdr ids))
1922 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
1923 (level1 (+ level (1- org-html-toplevel-hlevel))))
1924 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1925 (format "outline-container-%s"
1926 (or (org-element-property :CUSTOM_ID headline)
1927 section-number))
1928 (concat (format "outline-%d" level1) (and extra-class " ")
1929 extra-class)
1930 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1931 level1
1932 preferred-id
1933 (mapconcat
1934 (lambda (x)
1935 (let ((id (org-export-solidify-link-text
1936 (if (org-uuidgen-p x) (concat "ID-" x)
1937 x))))
1938 (org-html--anchor id)))
1939 extra-ids "")
1940 full-text
1941 level1)
1942 contents))))))
1945 ;;;; Horizontal Rule
1947 (defun org-html-horizontal-rule (horizontal-rule contents info)
1948 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1949 CONTENTS is nil. INFO is a plist holding contextual information."
1950 "<hr/>")
1953 ;;;; Inline Src Block
1955 (defun org-html-inline-src-block (inline-src-block contents info)
1956 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1957 CONTENTS holds the contents of the item. INFO is a plist holding
1958 contextual information."
1959 (let* ((org-lang (org-element-property :language inline-src-block))
1960 (code (org-element-property :value inline-src-block)))
1961 (error "Cannot export inline src block")))
1964 ;;;; Inlinetask
1966 (defun org-html-format-section (text class &optional id)
1967 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1968 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1970 (defun org-html-inlinetask (inlinetask contents info)
1971 "Transcode an INLINETASK element from Org to HTML.
1972 CONTENTS holds the contents of the block. INFO is a plist
1973 holding contextual information."
1974 (cond
1975 ;; If `org-html-format-inlinetask-function' is provided, call it
1976 ;; with appropriate arguments.
1977 ((functionp org-html-format-inlinetask-function)
1978 (let ((format-function
1979 (function*
1980 (lambda (todo todo-type priority text tags
1981 &key contents &allow-other-keys)
1982 (funcall org-html-format-inlinetask-function
1983 todo todo-type priority text tags contents)))))
1984 (org-html-format-headline--wrap
1985 inlinetask info format-function :contents contents)))
1986 ;; Otherwise, use a default template.
1987 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1988 (org-html-format-headline--wrap inlinetask info)
1989 contents))))
1992 ;;;; Italic
1994 (defun org-html-italic (italic contents info)
1995 "Transcode ITALIC from Org to HTML.
1996 CONTENTS is the text with italic markup. INFO is a plist holding
1997 contextual information."
1998 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2001 ;;;; Item
2003 (defun org-html-checkbox (checkbox)
2004 (case checkbox (on "<code>[X]</code>")
2005 (off "<code>[&nbsp;]</code>")
2006 (trans "<code>[-]</code>")
2007 (t "")))
2009 (defun org-html-format-list-item (contents type checkbox
2010 &optional term-counter-id
2011 headline)
2012 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2013 (concat
2014 (case type
2015 (ordered
2016 (let* ((counter term-counter-id)
2017 (extra (if counter (format " value=\"%s\"" counter) "")))
2018 (concat
2019 (format "<li%s>" extra)
2020 (when headline (concat headline "<br/>")))))
2021 (unordered
2022 (let* ((id term-counter-id)
2023 (extra (if id (format " id=\"%s\"" id) "")))
2024 (concat
2025 (format "<li%s>" extra)
2026 (when headline (concat headline "<br/>")))))
2027 (descriptive
2028 (let* ((term term-counter-id))
2029 (setq term (or term "(no term)"))
2030 ;; Check-boxes in descriptive lists are associated to tag.
2031 (concat (format "<dt> %s </dt>"
2032 (concat checkbox term))
2033 "<dd>"))))
2034 (unless (eq type 'descriptive) checkbox)
2035 contents
2036 (case type
2037 (ordered "</li>")
2038 (unordered "</li>")
2039 (descriptive "</dd>")))))
2041 (defun org-html-item (item contents info)
2042 "Transcode an ITEM element from Org to HTML.
2043 CONTENTS holds the contents of the item. INFO is a plist holding
2044 contextual information."
2045 (let* ((plain-list (org-export-get-parent item))
2046 (type (org-element-property :type plain-list))
2047 (counter (org-element-property :counter item))
2048 (checkbox (org-element-property :checkbox item))
2049 (tag (let ((tag (org-element-property :tag item)))
2050 (and tag (org-export-data tag info)))))
2051 (org-html-format-list-item
2052 contents type checkbox (or tag counter))))
2055 ;;;; Keyword
2057 (defun org-html-keyword (keyword contents info)
2058 "Transcode a KEYWORD element from Org to HTML.
2059 CONTENTS is nil. INFO is a plist holding contextual information."
2060 (let ((key (org-element-property :key keyword))
2061 (value (org-element-property :value keyword)))
2062 (cond
2063 ((string= key "HTML") value)
2064 ;; Invisible targets.
2065 ((string= key "TARGET") nil)
2066 ((string= key "TOC")
2067 (let ((value (downcase value)))
2068 (cond
2069 ((string-match "\\<headlines\\>" value)
2070 (let ((depth (or (and (string-match "[0-9]+" value)
2071 (string-to-number (match-string 0 value)))
2072 (plist-get info :with-toc))))
2073 (org-html-toc depth info)))
2074 ((string= "listings" value) (org-html-list-of-listings info))
2075 ((string= "tables" value) (org-html-list-of-tables info))))))))
2078 ;;;; Latex Environment
2080 (defun org-html-format-latex (latex-frag processing-type)
2081 "Format LaTeX fragments into HTML."
2082 (let ((cache-relpath "") (cache-dir "") bfn)
2083 (unless (eq processing-type 'mathjax)
2084 (setq bfn (buffer-file-name)
2085 cache-relpath
2086 (concat "ltxpng/"
2087 (file-name-sans-extension
2088 (file-name-nondirectory bfn)))
2089 cache-dir (file-name-directory bfn)))
2090 (with-temp-buffer
2091 (insert latex-frag)
2092 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2093 nil nil processing-type)
2094 (buffer-string))))
2096 (defun org-html-latex-environment (latex-environment contents info)
2097 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2098 CONTENTS is nil. INFO is a plist holding contextual information."
2099 (let ((processing-type (plist-get info :with-latex))
2100 (latex-frag (org-remove-indentation
2101 (org-element-property :value latex-environment)))
2102 (caption (org-export-data
2103 (org-export-get-caption latex-environment) info))
2104 (attr nil) ; FIXME
2105 (label (org-element-property :name latex-environment)))
2106 (cond
2107 ((memq processing-type '(t mathjax))
2108 (org-html-format-latex latex-frag 'mathjax))
2109 ((eq processing-type 'dvipng)
2110 (let* ((formula-link (org-html-format-latex
2111 latex-frag processing-type)))
2112 (when (and formula-link
2113 (string-match "file:\\([^]]*\\)" formula-link))
2114 (org-html-format-inline-image
2115 (match-string 1 formula-link) caption label attr t))))
2116 (t latex-frag))))
2119 ;;;; Latex Fragment
2121 (defun org-html-latex-fragment (latex-fragment contents info)
2122 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2123 CONTENTS is nil. INFO is a plist holding contextual information."
2124 (let ((latex-frag (org-element-property :value latex-fragment))
2125 (processing-type (plist-get info :with-latex)))
2126 (case processing-type
2127 ((t mathjax)
2128 (org-html-format-latex latex-frag 'mathjax))
2129 (dvipng
2130 (let* ((formula-link (org-html-format-latex
2131 latex-frag processing-type)))
2132 (when (and formula-link
2133 (string-match "file:\\([^]]*\\)" formula-link))
2134 (org-html-format-inline-image
2135 (match-string 1 formula-link)))))
2136 (t latex-frag))))
2139 ;;;; Line Break
2141 (defun org-html-line-break (line-break contents info)
2142 "Transcode a LINE-BREAK object from Org to HTML.
2143 CONTENTS is nil. INFO is a plist holding contextual information."
2144 "<br/>\n")
2147 ;;;; Link
2149 (defun org-html-link--inline-image (link desc info)
2150 "Return HTML code for an inline image.
2151 LINK is the link pointing to the inline image. INFO is a plist
2152 used as a communication channel."
2153 (let* ((type (org-element-property :type link))
2154 (raw-path (org-element-property :path link))
2155 (path (cond ((member type '("http" "https"))
2156 (concat type ":" raw-path))
2157 ((file-name-absolute-p raw-path)
2158 (expand-file-name raw-path))
2159 (t raw-path)))
2160 (parent (org-export-get-parent-element link))
2161 (caption (org-export-data (org-export-get-caption parent) info))
2162 (label (org-element-property :name parent))
2163 ;; Retrieve latex attributes from the PARENT element. HACK:
2164 ;; Only do this for the first link in PARENT. This is needed
2165 ;; as long as attributes cannot be set on a per link basis.
2166 (attr (when (eq link (org-element-map parent 'link 'identity info t))
2167 (let ((raw-attr
2168 (mapconcat #'identity
2169 (org-element-property :attr_html parent)
2170 " ")))
2171 (unless (string= raw-attr "") raw-attr)))))
2172 ;; Now clear ATTR from any special keyword and set a default
2173 ;; value if nothing is left.
2174 (setq attr (if (not attr) "" (org-trim attr)))
2175 ;; Return proper string, depending on DISPOSITION.
2176 (org-html-format-inline-image
2177 path caption label attr (org-html-standalone-image-p link info))))
2179 (defvar org-html-standalone-image-predicate)
2180 (defun org-html-standalone-image-p (element info &optional predicate)
2181 "Test if ELEMENT is a standalone image for the purpose HTML export.
2182 INFO is a plist holding contextual information.
2184 Return non-nil, if ELEMENT is of type paragraph and it's sole
2185 content, save for whitespaces, is a link that qualifies as an
2186 inline image.
2188 Return non-nil, if ELEMENT is of type link and it's containing
2189 paragraph has no other content save for leading and trailing
2190 whitespaces.
2192 Return nil, otherwise.
2194 Bind `org-html-standalone-image-predicate' to constrain
2195 paragraph further. For example, to check for only captioned
2196 standalone images, do the following.
2198 \(setq org-html-standalone-image-predicate
2199 \(lambda \(paragraph\)
2200 \(org-element-property :caption paragraph\)\)\)"
2201 (let ((paragraph (case (org-element-type element)
2202 (paragraph element)
2203 (link (and (org-export-inline-image-p
2204 element org-html-inline-image-rules)
2205 (org-export-get-parent element)))
2206 (t nil))))
2207 (when (eq (org-element-type paragraph) 'paragraph)
2208 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2209 (functionp org-html-standalone-image-predicate)))
2210 (funcall org-html-standalone-image-predicate paragraph))
2211 (let ((contents (org-element-contents paragraph)))
2212 (loop for x in contents
2213 with inline-image-count = 0
2214 always (cond
2215 ((eq (org-element-type x) 'plain-text)
2216 (not (org-string-nw-p x)))
2217 ((eq (org-element-type x) 'link)
2218 (when (org-export-inline-image-p
2219 x org-html-inline-image-rules)
2220 (= (incf inline-image-count) 1)))
2221 (t nil))))))))
2223 (defun org-html-link (link desc info)
2224 "Transcode a LINK object from Org to HTML.
2226 DESC is the description part of the link, or the empty string.
2227 INFO is a plist holding contextual information. See
2228 `org-export-data'."
2229 (let* ((--link-org-files-as-html-maybe
2230 (function
2231 (lambda (raw-path info)
2232 "Treat links to `file.org' as links to `file.html', if needed.
2233 See `org-html-link-org-files-as-html'."
2234 (cond
2235 ((and org-html-link-org-files-as-html
2236 (string= ".org"
2237 (downcase (file-name-extension raw-path "."))))
2238 (concat (file-name-sans-extension raw-path) "."
2239 (plist-get info :html-extension)))
2240 (t raw-path)))))
2241 (type (org-element-property :type link))
2242 (raw-path (org-element-property :path link))
2243 ;; Ensure DESC really exists, or set it to nil.
2244 (desc (and (not (string= desc "")) desc))
2245 (path
2246 (cond
2247 ((member type '("http" "https" "ftp" "mailto"))
2248 (concat type ":" raw-path))
2249 ((string= type "file")
2250 ;; Treat links to ".org" files as ".html", if needed.
2251 (setq raw-path
2252 (funcall --link-org-files-as-html-maybe raw-path info))
2253 ;; If file path is absolute, prepend it with protocol
2254 ;; component - "file://".
2255 (when (file-name-absolute-p raw-path)
2256 (setq raw-path
2257 (concat "file://" (expand-file-name raw-path))))
2258 ;; Add search option, if any. A search option can be
2259 ;; relative to a custom-id or a headline title. Any other
2260 ;; option is ignored.
2261 (let ((option (org-element-property :search-option link)))
2262 (cond ((not option) raw-path)
2263 ((eq (aref option 0) ?#) (concat raw-path option))
2264 ;; External fuzzy link: try to resolve it if path
2265 ;; belongs to current project, if any.
2266 ((eq (aref option 0) ?*)
2267 (concat
2268 raw-path
2269 (let ((numbers
2270 (org-publish-resolve-external-fuzzy-link
2271 (org-element-property :path link) option)))
2272 (and numbers (concat "#sec-"
2273 (mapconcat 'number-to-string
2274 numbers "-")))))))))
2275 (t raw-path)))
2276 attributes protocol)
2277 ;; Extract attributes from parent's paragraph. HACK: Only do this
2278 ;; for the first link in parent. This is needed as long as
2279 ;; attributes cannot be set on a per link basis.
2280 (and (setq attributes
2281 (let ((parent (org-export-get-parent-element link)))
2282 (if (not (eq (org-element-map parent 'link 'identity info t)
2283 link))
2285 (mapconcat
2286 'identity
2287 (let ((att (org-element-property :attr_html parent)))
2288 (unless (and desc att
2289 (string-match (regexp-quote (car att)) desc))
2290 att))
2291 " "))))
2292 (setq attributes (concat " " attributes)))
2293 (cond
2294 ;; Image file.
2295 ((and (or (eq t org-html-inline-images)
2296 (and org-html-inline-images (not desc)))
2297 (org-export-inline-image-p link org-html-inline-image-rules))
2298 (org-html-link--inline-image link desc info))
2299 ;; Radio target: Transcode target's contents and use them as
2300 ;; link's description.
2301 ((string= type "radio")
2302 (let ((destination (org-export-resolve-radio-link link info)))
2303 (when destination
2304 (format "<a href=\"#%s\"%s>%s</a>"
2305 (org-export-solidify-link-text path)
2306 attributes
2307 (org-export-data (org-element-contents destination) info)))))
2308 ;; Links pointing to a headline: Find destination and build
2309 ;; appropriate referencing command.
2310 ((member type '("custom-id" "fuzzy" "id"))
2311 (let ((destination (if (string= type "fuzzy")
2312 (org-export-resolve-fuzzy-link link info)
2313 (org-export-resolve-id-link link info))))
2314 (case (org-element-type destination)
2315 ;; ID link points to an external file.
2316 (plain-text
2317 (let ((fragment (concat "ID-" path))
2318 ;; Treat links to ".org" files as ".html", if needed.
2319 (path (funcall --link-org-files-as-html-maybe
2320 destination info)))
2321 (format "<a href=\"%s#%s\"%s>%s</a>"
2322 path fragment attributes (or desc destination))))
2323 ;; Fuzzy link points nowhere.
2324 ((nil)
2325 (format "<i>%s</i>"
2326 (or desc
2327 (org-export-data
2328 (org-element-property :raw-link link) info))))
2329 ;; Fuzzy link points to an invisible target.
2330 (keyword nil)
2331 ;; Link points to a headline.
2332 (headline
2333 (let ((href
2334 ;; What href to use?
2335 (cond
2336 ;; Case 1: Headline is linked via it's CUSTOM_ID
2337 ;; property. Use CUSTOM_ID.
2338 ((string= type "custom-id")
2339 (org-element-property :CUSTOM_ID destination))
2340 ;; Case 2: Headline is linked via it's ID property
2341 ;; or through other means. Use the default href.
2342 ((member type '("id" "fuzzy"))
2343 (format "sec-%s"
2344 (mapconcat 'number-to-string
2345 (org-export-get-headline-number
2346 destination info) "-")))
2347 (t (error "Shouldn't reach here"))))
2348 ;; What description to use?
2349 (desc
2350 ;; Case 1: Headline is numbered and LINK has no
2351 ;; description or LINK's description matches
2352 ;; headline's title. Display section number.
2353 (if (and (org-export-numbered-headline-p destination info)
2354 (or (not desc)
2355 (string= desc (org-element-property
2356 :raw-value destination))))
2357 (mapconcat 'number-to-string
2358 (org-export-get-headline-number
2359 destination info) ".")
2360 ;; Case 2: Either the headline is un-numbered or
2361 ;; LINK has a custom description. Display LINK's
2362 ;; description or headline's title.
2363 (or desc (org-export-data (org-element-property
2364 :title destination) info)))))
2365 (format "<a href=\"#%s\"%s>%s</a>"
2366 (org-export-solidify-link-text href) attributes desc)))
2367 ;; Fuzzy link points to a target. Do as above.
2369 (let ((path (org-export-solidify-link-text path)) number)
2370 (unless desc
2371 (setq number (cond
2372 ((org-html-standalone-image-p destination info)
2373 (org-export-get-ordinal
2374 (assoc 'link (org-element-contents destination))
2375 info 'link 'org-html-standalone-image-p))
2376 (t (org-export-get-ordinal destination info))))
2377 (setq desc (when number
2378 (if (atom number) (number-to-string number)
2379 (mapconcat 'number-to-string number ".")))))
2380 (format "<a href=\"#%s\"%s>%s</a>"
2381 path attributes (or desc "No description for this link")))))))
2382 ;; Coderef: replace link with the reference name or the
2383 ;; equivalent line number.
2384 ((string= type "coderef")
2385 (let ((fragment (concat "coderef-" path)))
2386 (format "<a href=\"#%s\" %s%s>%s</a>"
2387 fragment
2388 (format (concat "class=\"coderef\""
2389 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2390 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2391 fragment fragment)
2392 attributes
2393 (format (org-export-get-coderef-format path desc)
2394 (org-export-resolve-coderef path info)))))
2395 ;; Link type is handled by a special function.
2396 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2397 (funcall protocol (org-link-unescape path) desc 'html))
2398 ;; External link with a description part.
2399 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2400 ;; External link without a description part.
2401 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2402 ;; No path, only description. Try to do something useful.
2403 (t (format "<i>%s</i>" desc)))))
2406 ;;;; Paragraph
2408 (defun org-html-paragraph (paragraph contents info)
2409 "Transcode a PARAGRAPH element from Org to HTML.
2410 CONTENTS is the contents of the paragraph, as a string. INFO is
2411 the plist used as a communication channel."
2412 (let* ((style nil) ; FIXME
2413 (class (cdr (assoc style '((footnote . "footnote")
2414 (verse . nil)))))
2415 (extra (if class (format " class=\"%s\"" class) ""))
2416 (parent (org-export-get-parent paragraph)))
2417 (cond
2418 ((and (eq (org-element-type parent) 'item)
2419 (= (org-element-property :begin paragraph)
2420 (org-element-property :contents-begin parent)))
2421 ;; leading paragraph in a list item have no tags
2422 contents)
2423 ((org-html-standalone-image-p paragraph info)
2424 ;; standalone image
2425 contents)
2426 (t (format "<p%s>\n%s</p>" extra contents)))))
2429 ;;;; Plain List
2431 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2432 ;; the correct value for the item counter
2433 (defun org-html-begin-plain-list (type &optional arg1)
2434 "Insert the beginning of the HTML list depending on TYPE.
2435 When ARG1 is a string, use it as the start parameter for ordered
2436 lists."
2437 (case type
2438 (ordered
2439 (format "<ol class=\"org-ol\"%s>"
2440 (if arg1 (format " start=\"%d\"" arg1) "")))
2441 (unordered "<ul class=\"org-ul\">")
2442 (descriptive "<dl class=\"org-dl\">")))
2444 (defun org-html-end-plain-list (type)
2445 "Insert the end of the HTML list depending on TYPE."
2446 (case type
2447 (ordered "</ol>")
2448 (unordered "</ul>")
2449 (descriptive "</dl>")))
2451 (defun org-html-plain-list (plain-list contents info)
2452 "Transcode a PLAIN-LIST element from Org to HTML.
2453 CONTENTS is the contents of the list. INFO is a plist holding
2454 contextual information."
2455 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2456 (type (org-element-property :type plain-list)))
2457 (format "%s\n%s%s"
2458 (org-html-begin-plain-list type)
2459 contents (org-html-end-plain-list type))))
2461 ;;;; Plain Text
2463 (defun org-html-convert-special-strings (string)
2464 "Convert special characters in STRING to HTML."
2465 (let ((all org-html-special-string-regexps)
2466 e a re rpl start)
2467 (while (setq a (pop all))
2468 (setq re (car a) rpl (cdr a) start 0)
2469 (while (string-match re string start)
2470 (setq string (replace-match rpl t nil string))))
2471 string))
2473 (defun org-html-encode-plain-text (text)
2474 "Convert plain text characters to HTML equivalent.
2475 Possible conversions are set in `org-export-html-protect-char-alist'."
2476 (mapc
2477 (lambda (pair)
2478 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2479 org-html-protect-char-alist)
2480 text)
2482 (defun org-html-plain-text (text info)
2483 "Transcode a TEXT string from Org to HTML.
2484 TEXT is the string to transcode. INFO is a plist holding
2485 contextual information."
2486 (let ((output text))
2487 ;; Protect following characters: <, >, &.
2488 (setq output (org-html-encode-plain-text output))
2489 ;; Handle smart quotes. Be sure to provide original string since
2490 ;; OUTPUT may have been modified.
2491 (when (plist-get info :with-smart-quotes)
2492 (setq output (org-export-activate-smart-quotes output :html info text)))
2493 ;; Handle special strings.
2494 (when (plist-get info :with-special-strings)
2495 (setq output (org-html-convert-special-strings output)))
2496 ;; Handle break preservation if required.
2497 (when (plist-get info :preserve-breaks)
2498 (setq output
2499 (replace-regexp-in-string
2500 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2501 ;; Return value.
2502 output))
2505 ;; Planning
2507 (defun org-html-planning (planning contents info)
2508 "Transcode a PLANNING element from Org to HTML.
2509 CONTENTS is nil. INFO is a plist used as a communication
2510 channel."
2511 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2512 (format
2513 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2514 (mapconcat
2515 'identity
2516 (delq nil
2517 (list
2518 (let ((closed (org-element-property :closed planning)))
2519 (when closed
2520 (format span-fmt org-closed-string
2521 (org-translate-time
2522 (org-element-property :raw-value closed)))))
2523 (let ((deadline (org-element-property :deadline planning)))
2524 (when deadline
2525 (format span-fmt org-deadline-string
2526 (org-translate-time
2527 (org-element-property :raw-value deadline)))))
2528 (let ((scheduled (org-element-property :scheduled planning)))
2529 (when scheduled
2530 (format span-fmt org-scheduled-string
2531 (org-translate-time
2532 (org-element-property :raw-value scheduled)))))))
2533 " "))))
2536 ;;;; Property Drawer
2538 (defun org-html-property-drawer (property-drawer contents info)
2539 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2540 CONTENTS is nil. INFO is a plist holding contextual
2541 information."
2542 ;; The property drawer isn't exported but we want separating blank
2543 ;; lines nonetheless.
2547 ;;;; Quote Block
2549 (defun org-html-quote-block (quote-block contents info)
2550 "Transcode a QUOTE-BLOCK element from Org to HTML.
2551 CONTENTS holds the contents of the block. INFO is a plist
2552 holding contextual information."
2553 (format "<blockquote>\n%s</blockquote>" contents))
2556 ;;;; Quote Section
2558 (defun org-html-quote-section (quote-section contents info)
2559 "Transcode a QUOTE-SECTION element from Org to HTML.
2560 CONTENTS is nil. INFO is a plist holding contextual information."
2561 (let ((value (org-remove-indentation
2562 (org-element-property :value quote-section))))
2563 (when value (format "<pre>\n%s</pre>" value))))
2566 ;;;; Section
2568 (defun org-html-section (section contents info)
2569 "Transcode a SECTION element from Org to HTML.
2570 CONTENTS holds the contents of the section. INFO is a plist
2571 holding contextual information."
2572 (let ((parent (org-export-get-parent-headline section)))
2573 ;; Before first headline: no container, just return CONTENTS.
2574 (if (not parent) contents
2575 ;; Get div's class and id references.
2576 (let* ((class-num (+ (org-export-get-relative-level parent info)
2577 (1- org-html-toplevel-hlevel)))
2578 (section-number
2579 (mapconcat
2580 'number-to-string
2581 (org-export-get-headline-number parent info) "-")))
2582 ;; Build return value.
2583 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2584 class-num
2585 (or (org-element-property :CUSTOM_ID parent) section-number)
2586 contents)))))
2588 ;;;; Radio Target
2590 (defun org-html-radio-target (radio-target text info)
2591 "Transcode a RADIO-TARGET object from Org to HTML.
2592 TEXT is the text of the target. INFO is a plist holding
2593 contextual information."
2594 (let ((id (org-export-solidify-link-text
2595 (org-element-property :value radio-target))))
2596 (org-html--anchor id text)))
2599 ;;;; Special Block
2601 (defun org-html-special-block (special-block contents info)
2602 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2603 CONTENTS holds the contents of the block. INFO is a plist
2604 holding contextual information."
2605 (format "<div class=\"%s\">\n%s\n</div>"
2606 (downcase (org-element-property :type special-block))
2607 contents))
2610 ;;;; Src Block
2612 (defun org-html-src-block (src-block contents info)
2613 "Transcode a SRC-BLOCK element from Org to HTML.
2614 CONTENTS holds the contents of the item. INFO is a plist holding
2615 contextual information."
2616 (if (org-export-read-attribute :attr_html src-block :textarea)
2617 (org-html--textarea-block src-block)
2618 (let ((lang (org-element-property :language src-block))
2619 (caption (org-export-get-caption src-block))
2620 (code (org-html-format-code src-block info))
2621 (label (let ((lbl (org-element-property :name src-block)))
2622 (if (not lbl) ""
2623 (format " id=\"%s\""
2624 (org-export-solidify-link-text lbl))))))
2625 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2626 (format
2627 "<div class=\"org-src-container\">\n%s%s\n</div>"
2628 (if (not caption) ""
2629 (format "<label class=\"org-src-name\">%s</label>"
2630 (org-export-data caption info)))
2631 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2634 ;;;; Statistics Cookie
2636 (defun org-html-statistics-cookie (statistics-cookie contents info)
2637 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2638 CONTENTS is nil. INFO is a plist holding contextual information."
2639 (let ((cookie-value (org-element-property :value statistics-cookie)))
2640 (format "<code>%s</code>" cookie-value)))
2643 ;;;; Strike-Through
2645 (defun org-html-strike-through (strike-through contents info)
2646 "Transcode STRIKE-THROUGH from Org to HTML.
2647 CONTENTS is the text with strike-through markup. INFO is a plist
2648 holding contextual information."
2649 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2650 contents))
2653 ;;;; Subscript
2655 (defun org-html-subscript (subscript contents info)
2656 "Transcode a SUBSCRIPT object from Org to HTML.
2657 CONTENTS is the contents of the object. INFO is a plist holding
2658 contextual information."
2659 (format "<sub>%s</sub>" contents))
2662 ;;;; Superscript
2664 (defun org-html-superscript (superscript contents info)
2665 "Transcode a SUPERSCRIPT object from Org to HTML.
2666 CONTENTS is the contents of the object. INFO is a plist holding
2667 contextual information."
2668 (format "<sup>%s</sup>" contents))
2671 ;;;; Tabel Cell
2673 (defun org-html-table-cell (table-cell contents info)
2674 "Transcode a TABLE-CELL element from Org to HTML.
2675 CONTENTS is nil. INFO is a plist used as a communication
2676 channel."
2677 (let* ((table-row (org-export-get-parent table-cell))
2678 (table (org-export-get-parent-table table-cell))
2679 (cell-attrs
2680 (if (not org-html-table-align-individual-fields) ""
2681 (format (if (and (boundp 'org-html-format-table-no-css)
2682 org-html-format-table-no-css)
2683 " align=\"%s\"" " class=\"%s\"")
2684 (org-export-table-cell-alignment table-cell info)))))
2685 (when (or (not contents) (string= "" (org-trim contents)))
2686 (setq contents "&nbsp;"))
2687 (cond
2688 ((and (org-export-table-has-header-p table info)
2689 (= 1 (org-export-table-row-group table-row info)))
2690 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2691 contents (cdr org-html-table-header-tags)))
2692 ((and org-html-table-use-header-tags-for-first-column
2693 (zerop (cdr (org-export-table-cell-address table-cell info))))
2694 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2695 contents (cdr org-html-table-header-tags)))
2696 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2697 contents (cdr org-html-table-data-tags))))))
2700 ;;;; Table Row
2702 (defun org-html-table-row (table-row contents info)
2703 "Transcode a TABLE-ROW element from Org to HTML.
2704 CONTENTS is the contents of the row. INFO is a plist used as a
2705 communication channel."
2706 ;; Rules are ignored since table separators are deduced from
2707 ;; borders of the current row.
2708 (when (eq (org-element-property :type table-row) 'standard)
2709 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2710 (rowgroup-tags
2711 (cond
2712 ;; Case 1: Row belongs to second or subsequent rowgroups.
2713 ((not (= 1 (org-export-table-row-group table-row info)))
2714 '("<tbody>" . "\n</tbody>"))
2715 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2716 ((org-export-table-has-header-p
2717 (org-export-get-parent-table table-row) info)
2718 '("<thead>" . "\n</thead>"))
2719 ;; Case 2: Row is from first and only row group.
2720 (t '("<tbody>" . "\n</tbody>")))))
2721 (concat
2722 ;; Begin a rowgroup?
2723 (when (org-export-table-row-starts-rowgroup-p table-row info)
2724 (car rowgroup-tags))
2725 ;; Actual table row
2726 (concat "\n" (eval (car org-html-table-row-tags))
2727 contents
2728 "\n"
2729 (eval (cdr org-html-table-row-tags)))
2730 ;; End a rowgroup?
2731 (when (org-export-table-row-ends-rowgroup-p table-row info)
2732 (cdr rowgroup-tags))))))
2735 ;;;; Table
2737 (defun org-html-table-first-row-data-cells (table info)
2738 (let ((table-row
2739 (org-element-map table 'table-row
2740 (lambda (row)
2741 (unless (eq (org-element-property :type row) 'rule) row))
2742 info 'first-match))
2743 (special-column-p (org-export-table-has-special-column-p table)))
2744 (if (not special-column-p) (org-element-contents table-row)
2745 (cdr (org-element-contents table-row)))))
2747 (defun org-html-table--table.el-table (table info)
2748 (when (eq (org-element-property :type table) 'table.el)
2749 (require 'table)
2750 (let ((outbuf (with-current-buffer
2751 (get-buffer-create "*org-export-table*")
2752 (erase-buffer) (current-buffer))))
2753 (with-temp-buffer
2754 (insert (org-element-property :value table))
2755 (goto-char 1)
2756 (re-search-forward "^[ \t]*|[^|]" nil t)
2757 (table-generate-source 'html outbuf))
2758 (with-current-buffer outbuf
2759 (prog1 (org-trim (buffer-string))
2760 (kill-buffer) )))))
2762 (defun org-html-table (table contents info)
2763 "Transcode a TABLE element from Org to HTML.
2764 CONTENTS is the contents of the table. INFO is a plist holding
2765 contextual information."
2766 (case (org-element-property :type table)
2767 ;; Case 1: table.el table. Convert it using appropriate tools.
2768 (table.el (org-html-table--table.el-table table info))
2769 ;; Case 2: Standard table.
2771 (let* ((label (org-element-property :name table))
2772 (caption (org-export-get-caption table))
2773 (attributes (mapconcat #'identity
2774 (org-element-property :attr_html table)
2775 " "))
2776 (alignspec
2777 (if (and (boundp 'org-html-format-table-no-css)
2778 org-html-format-table-no-css)
2779 "align=\"%s\"" "class=\"%s\""))
2780 (table-column-specs
2781 (function
2782 (lambda (table info)
2783 (mapconcat
2784 (lambda (table-cell)
2785 (let ((alignment (org-export-table-cell-alignment
2786 table-cell info)))
2787 (concat
2788 ;; Begin a colgroup?
2789 (when (org-export-table-cell-starts-colgroup-p
2790 table-cell info)
2791 "\n<colgroup>")
2792 ;; Add a column. Also specify it's alignment.
2793 (format "\n<col %s/>" (format alignspec alignment))
2794 ;; End a colgroup?
2795 (when (org-export-table-cell-ends-colgroup-p
2796 table-cell info)
2797 "\n</colgroup>"))))
2798 (org-html-table-first-row-data-cells table info) "\n"))))
2799 (table-attributes
2800 (let ((table-tag (plist-get info :html-table-tag)))
2801 (concat
2802 (and (string-match "<table\\(.*\\)>" table-tag)
2803 (match-string 1 table-tag))
2804 (and label (format " id=\"%s\""
2805 (org-export-solidify-link-text label)))
2806 (unless (string= attributes "")
2807 (concat " " attributes))))))
2808 ;; Remove last blank line.
2809 (setq contents (substring contents 0 -1))
2810 (format "<table%s>\n%s\n%s\n%s\n</table>"
2811 table-attributes
2812 (if (not caption) ""
2813 (format "<caption>%s</caption>"
2814 (org-export-data caption info)))
2815 (funcall table-column-specs table info)
2816 contents)))))
2819 ;;;; Target
2821 (defun org-html-target (target contents info)
2822 "Transcode a TARGET object from Org to HTML.
2823 CONTENTS is nil. INFO is a plist holding contextual
2824 information."
2825 (let ((id (org-export-solidify-link-text
2826 (org-element-property :value target))))
2827 (org-html--anchor id)))
2830 ;;;; Timestamp
2832 (defun org-html-timestamp (timestamp contents info)
2833 "Transcode a TIMESTAMP object from Org to HTML.
2834 CONTENTS is nil. INFO is a plist holding contextual
2835 information."
2836 (let ((value (org-html-plain-text
2837 (org-timestamp-translate timestamp) info)))
2838 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2839 (replace-regexp-in-string "--" "&ndash;" value))))
2842 ;;;; Underline
2844 (defun org-html-underline (underline contents info)
2845 "Transcode UNDERLINE from Org to HTML.
2846 CONTENTS is the text with underline markup. INFO is a plist
2847 holding contextual information."
2848 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2849 contents))
2852 ;;;; Verbatim
2854 (defun org-html-verbatim (verbatim contents info)
2855 "Transcode VERBATIM from Org to HTML.
2856 CONTENTS is nil. INFO is a plist holding contextual
2857 information."
2858 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2859 (org-element-property :value verbatim)))
2862 ;;;; Verse Block
2864 (defun org-html-verse-block (verse-block contents info)
2865 "Transcode a VERSE-BLOCK element from Org to HTML.
2866 CONTENTS is verse block contents. INFO is a plist holding
2867 contextual information."
2868 ;; Replace each newline character with line break. Also replace
2869 ;; each blank line with a line break.
2870 (setq contents (replace-regexp-in-string
2871 "^ *\\\\\\\\$" "<br/>\n"
2872 (replace-regexp-in-string
2873 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2874 ;; Replace each white space at beginning of a line with a
2875 ;; non-breaking space.
2876 (while (string-match "^[ \t]+" contents)
2877 (let* ((num-ws (length (match-string 0 contents)))
2878 (ws (let (out) (dotimes (i num-ws out)
2879 (setq out (concat out "&nbsp;"))))))
2880 (setq contents (replace-match ws nil t contents))))
2881 (format "<p class=\"verse\">\n%s</p>" contents))
2885 ;;; Filter Functions
2887 (defun org-html-final-function (contents backend info)
2888 (if (not org-html-pretty-output) contents
2889 (with-temp-buffer
2890 (html-mode)
2891 (insert contents)
2892 (indent-region (point-min) (point-max))
2893 (buffer-substring-no-properties (point-min) (point-max)))))
2897 ;;; End-user functions
2899 ;;;###autoload
2900 (defun org-html-export-as-html
2901 (&optional async subtreep visible-only body-only ext-plist)
2902 "Export current buffer to an HTML buffer.
2904 If narrowing is active in the current buffer, only export its
2905 narrowed part.
2907 If a region is active, export that region.
2909 A non-nil optional argument ASYNC means the process should happen
2910 asynchronously. The resulting buffer should be accessible
2911 through the `org-export-stack' interface.
2913 When optional argument SUBTREEP is non-nil, export the sub-tree
2914 at point, extracting information from the headline properties
2915 first.
2917 When optional argument VISIBLE-ONLY is non-nil, don't export
2918 contents of hidden elements.
2920 When optional argument BODY-ONLY is non-nil, only write code
2921 between \"<body>\" and \"</body>\" tags.
2923 EXT-PLIST, when provided, is a property list with external
2924 parameters overriding Org default settings, but still inferior to
2925 file-local settings.
2927 Export is done in a buffer named \"*Org HTML Export*\", which
2928 will be displayed when `org-export-show-temporary-export-buffer'
2929 is non-nil."
2930 (interactive)
2931 (if async
2932 (org-export-async-start
2933 (lambda (output)
2934 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2935 (erase-buffer)
2936 (insert output)
2937 (goto-char (point-min))
2938 (funcall org-html-display-buffer-mode)
2939 (org-export-add-to-stack (current-buffer) 'html)))
2940 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2941 (let ((outbuf (org-export-to-buffer
2942 'html "*Org HTML Export*"
2943 subtreep visible-only body-only ext-plist)))
2944 ;; Set major mode.
2945 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2946 (when org-export-show-temporary-export-buffer
2947 (switch-to-buffer-other-window outbuf)))))
2949 ;;;###autoload
2950 (defun org-html-export-to-html
2951 (&optional async subtreep visible-only body-only ext-plist)
2952 "Export current buffer to a HTML file.
2954 If narrowing is active in the current buffer, only export its
2955 narrowed part.
2957 If a region is active, export that region.
2959 A non-nil optional argument ASYNC means the process should happen
2960 asynchronously. The resulting file should be accessible through
2961 the `org-export-stack' interface.
2963 When optional argument SUBTREEP is non-nil, export the sub-tree
2964 at point, extracting information from the headline properties
2965 first.
2967 When optional argument VISIBLE-ONLY is non-nil, don't export
2968 contents of hidden elements.
2970 When optional argument BODY-ONLY is non-nil, only write code
2971 between \"<body>\" and \"</body>\" tags.
2973 EXT-PLIST, when provided, is a property list with external
2974 parameters overriding Org default settings, but still inferior to
2975 file-local settings.
2977 Return output file's name."
2978 (interactive)
2979 (let* ((extension (concat "." org-html-extension))
2980 (file (org-export-output-file-name extension subtreep))
2981 (org-export-coding-system org-html-coding-system))
2982 (if async
2983 (org-export-async-start
2984 (lambda (f) (org-export-add-to-stack f 'html))
2985 (let ((org-export-coding-system org-html-coding-system))
2986 `(expand-file-name
2987 (org-export-to-file
2988 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2989 (let ((org-export-coding-system org-html-coding-system))
2990 (org-export-to-file
2991 'html file subtreep visible-only body-only ext-plist)))))
2993 ;;;###autoload
2994 (defun org-html-publish-to-html (plist filename pub-dir)
2995 "Publish an org file to HTML.
2997 FILENAME is the filename of the Org file to be published. PLIST
2998 is the property list for the given project. PUB-DIR is the
2999 publishing directory.
3001 Return output file name."
3002 (org-publish-org-to 'html filename ".html" plist pub-dir))
3006 ;;; FIXME
3008 ;;;; org-format-table-html
3009 ;;;; org-format-org-table-html
3010 ;;;; org-format-table-table-html
3011 ;;;; org-table-number-fraction
3012 ;;;; org-table-number-regexp
3013 ;;;; org-html-table-caption-above
3014 ;;;; org-html-with-timestamp
3015 ;;;; org-html-html-helper-timestamp
3016 ;;;; org-html-inline-image-extensions
3017 ;;;; org-export-preferred-target-alist
3018 ;;;; class for anchors
3019 ;;;; org-export-with-section-numbers, body-only
3020 ;;;; org-export-mark-todo-in-toc
3021 ;;;; org-html-format-org-link
3022 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3023 ;;;; alt = (file-name-nondirectory path)
3025 (provide 'ox-html)
3027 ;; Local variables:
3028 ;; generated-autoload-file: "org-loaddefs.el"
3029 ;; End:
3031 ;;; ox-html.el ends here