ox-html: Do not display title in body-only export
[org-mode.git] / lisp / ox-html.el
blob710009aba9e12fcb2c5d7f604c2d0cd3dd0919b5
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.4"
967 :package-version '(Org . "8.0")
968 :type '(choice (function 'html-mode)
969 (function 'nxml-mode)
970 (function :tag "Other mode")))
974 ;;; Internal Functions
976 (defun org-html-format-inline-image (src &optional
977 caption label attr standalone-p)
978 (let* ((id (if (not label) ""
979 (format " id=\"%s\"" (org-export-solidify-link-text label))))
980 (attr (concat attr
981 (cond
982 ((string-match "\\<alt=" (or attr "")) "")
983 ((string-match "^ltxpng/" src)
984 (format " alt=\"%s\""
985 (org-html-encode-plain-text
986 (org-find-text-property-in-string
987 'org-latex-src src))))
988 (t (format " alt=\"%s\""
989 (file-name-nondirectory src)))))))
990 (cond
991 (standalone-p
992 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
993 (format "\n<div%s class=\"figure\">%s%s\n</div>"
994 id (format "\n<p>%s</p>" img)
995 (when caption (format "\n<p>%s</p>" caption)))))
996 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
998 (defun org-html--textarea-block (element)
999 "Transcode ELEMENT into a textarea block.
1000 ELEMENT is either a src block or an example block."
1001 (let ((code (car (org-export-unravel-code element)))
1002 (attr (org-export-read-attribute :attr_html element)))
1003 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1004 (or (plist-get attr :width) 80)
1005 (or (plist-get attr :height) (org-count-lines code))
1006 code)))
1009 ;;;; Bibliography
1011 (defun org-html-bibliography ()
1012 "Find bibliography, cut it out and return it."
1013 (catch 'exit
1014 (let (beg end (cnt 1) bib)
1015 (save-excursion
1016 (goto-char (point-min))
1017 (when (re-search-forward
1018 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1019 (setq beg (match-beginning 0))
1020 (while (re-search-forward "</?div\\>" nil t)
1021 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1022 (when (= cnt 0)
1023 (and (looking-at ">") (forward-char 1))
1024 (setq bib (buffer-substring beg (point)))
1025 (delete-region beg (point))
1026 (throw 'exit bib))))
1027 nil))))
1029 ;;;; Table
1031 (defun org-html-splice-attributes (tag attributes)
1032 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1033 (if (not attributes)
1035 (let (oldatt newatt)
1036 (setq oldatt (org-extract-attributes-from-string tag)
1037 tag (pop oldatt)
1038 newatt (cdr (org-extract-attributes-from-string attributes)))
1039 (while newatt
1040 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1041 (if (string-match ">" tag)
1042 (setq tag
1043 (replace-match (concat (org-attributes-to-string oldatt) ">")
1044 t t tag)))
1045 tag)))
1047 (defun org-export-splice-style (style extra)
1048 "Splice EXTRA into STYLE, just before \"</style>\"."
1049 (if (and (stringp extra)
1050 (string-match "\\S-" extra)
1051 (string-match "</style>" style))
1052 (concat (substring style 0 (match-beginning 0))
1053 "\n" extra "\n"
1054 (substring style (match-beginning 0)))
1055 style))
1057 (defun org-html-htmlize-region-for-paste (beg end)
1058 "Convert the region to HTML, using htmlize.el.
1059 This is much like `htmlize-region-for-paste', only that it uses
1060 the settings define in the org-... variables."
1061 (let* ((htmlize-output-type org-html-htmlize-output-type)
1062 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1063 (htmlbuf (htmlize-region beg end)))
1064 (unwind-protect
1065 (with-current-buffer htmlbuf
1066 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1067 (plist-get htmlize-buffer-places 'content-end)))
1068 (kill-buffer htmlbuf))))
1070 ;;;###autoload
1071 (defun org-html-htmlize-generate-css ()
1072 "Create the CSS for all font definitions in the current Emacs session.
1073 Use this to create face definitions in your CSS style file that can then
1074 be used by code snippets transformed by htmlize.
1075 This command just produces a buffer that contains class definitions for all
1076 faces used in the current Emacs session. You can copy and paste the ones you
1077 need into your CSS file.
1079 If you then set `org-html-htmlize-output-type' to `css', calls
1080 to the function `org-html-htmlize-region-for-paste' will
1081 produce code that uses these same face definitions."
1082 (interactive)
1083 (require 'htmlize)
1084 (and (get-buffer "*html*") (kill-buffer "*html*"))
1085 (with-temp-buffer
1086 (let ((fl (face-list))
1087 (htmlize-css-name-prefix "org-")
1088 (htmlize-output-type 'css)
1089 f i)
1090 (while (setq f (pop fl)
1091 i (and f (face-attribute f :inherit)))
1092 (when (and (symbolp f) (or (not i) (not (listp i))))
1093 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1094 (htmlize-region (point-min) (point-max))))
1095 (org-pop-to-buffer-same-window "*html*")
1096 (goto-char (point-min))
1097 (if (re-search-forward "<style" nil t)
1098 (delete-region (point-min) (match-beginning 0)))
1099 (if (re-search-forward "</style>" nil t)
1100 (delete-region (1+ (match-end 0)) (point-max)))
1101 (beginning-of-line 1)
1102 (if (looking-at " +") (replace-match ""))
1103 (goto-char (point-min)))
1105 (defun org-html--make-string (n string)
1106 "Build a string by concatenating N times STRING."
1107 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1109 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1110 "Turn todo keyword into a valid class name.
1111 Replaces invalid characters with \"_\"."
1112 (save-match-data
1113 (while (string-match "[^a-zA-Z0-9_]" kwd)
1114 (setq kwd (replace-match "_" t t kwd))))
1115 kwd)
1117 (defun org-html-format-footnote-reference (n def refcnt)
1118 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1119 (format org-html-footnote-format
1120 (let* ((id (format "fnr.%s%s" n extra))
1121 (href (format " href=\"#fn.%s\"" n))
1122 (attributes (concat " class=\"footref\"" href)))
1123 (org-html--anchor id n attributes)))))
1125 (defun org-html-format-footnotes-section (section-name definitions)
1126 (if (not definitions) ""
1127 (format org-html-footnotes-section section-name definitions)))
1129 (defun org-html-format-footnote-definition (fn)
1130 (let ((n (car fn)) (def (cdr fn)))
1131 (format
1132 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1133 (format org-html-footnote-format
1134 (let* ((id (format "fn.%s" n))
1135 (href (format " href=\"#fnr.%s\"" n))
1136 (attributes (concat " class=\"footnum\"" href)))
1137 (org-html--anchor id n attributes)))
1138 def)))
1140 (defun org-html-footnote-section (info)
1141 (let* ((fn-alist (org-export-collect-footnote-definitions
1142 (plist-get info :parse-tree) info))
1144 (fn-alist
1145 (loop for (n type raw) in fn-alist collect
1146 (cons n (if (eq (org-element-type raw) 'org-data)
1147 (org-trim (org-export-data raw info))
1148 (format "<p>%s</p>"
1149 (org-trim (org-export-data raw info))))))))
1150 (when fn-alist
1151 (org-html-format-footnotes-section
1152 (org-html--translate "Footnotes" info)
1153 (format
1154 "<table>\n%s\n</table>\n"
1155 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1159 ;;; Template
1161 (defun org-html--build-meta-info (info)
1162 "Return meta tags for exported document.
1163 INFO is a plist used as a communication channel."
1164 (let* ((title (org-export-data (plist-get info :title) info))
1165 (author (and (plist-get info :with-author)
1166 (let ((auth (plist-get info :author)))
1167 (and auth (org-export-data auth info)))))
1168 (date (and (plist-get info :with-date)
1169 (let ((date (plist-get info :date)))
1170 (and date (org-export-data date info)))))
1171 (description (plist-get info :description))
1172 (keywords (plist-get info :keywords)))
1173 (concat
1174 (format "<title>%s</title>\n" title)
1175 (format
1176 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1177 (or (and org-html-coding-system
1178 (fboundp 'coding-system-get)
1179 (coding-system-get org-html-coding-system 'mime-charset))
1180 "iso-8859-1"))
1181 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1182 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1183 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1184 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1185 (and description
1186 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1187 (and keywords
1188 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1190 (defun org-html--build-style (info)
1191 "Return style information for exported document.
1192 INFO is a plist used as a communication channel."
1193 (org-element-normalize-string
1194 (concat
1195 (when (plist-get info :html-style-include-default)
1196 (org-element-normalize-string org-html-style-default))
1197 (org-element-normalize-string (plist-get info :html-style))
1198 (when (and (plist-get info :html-htmlized-css-url)
1199 (eq org-html-htmlize-output-type 'css))
1200 (format "<link rel=\"stylesheet\" href=\"%s\" type=\"text/css\" />\n"
1201 (plist-get info :html-htmlized-css-url)))
1202 (org-element-normalize-string (plist-get info :html-style-extra))
1203 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1205 (defun org-html--build-mathjax-config (info)
1206 "Insert the user setup into the mathjax template.
1207 INFO is a plist used as a communication channel."
1208 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1209 (org-element-map (plist-get info :parse-tree)
1210 '(latex-fragment latex-environment) 'identity info t))
1211 (let ((template org-html-mathjax-template)
1212 (options org-html-mathjax-options)
1213 (in-buffer (or (plist-get info :html-mathjax) ""))
1214 name val (yes " ") (no "// ") x)
1215 (mapc
1216 (lambda (e)
1217 (setq name (car e) val (nth 1 e))
1218 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1219 (setq val (car (read-from-string
1220 (substring in-buffer (match-end 0))))))
1221 (if (not (stringp val)) (setq val (format "%s" val)))
1222 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1223 (setq template (replace-match val t t template))))
1224 options)
1225 (setq val (nth 1 (assq 'mathml options)))
1226 (if (string-match (concat "\\<mathml:") in-buffer)
1227 (setq val (car (read-from-string
1228 (substring in-buffer (match-end 0))))))
1229 ;; Exchange prefixes depending on mathml setting.
1230 (if (not val) (setq x yes yes no no x))
1231 ;; Replace cookies to turn on or off the config/jax lines.
1232 (if (string-match ":MMLYES:" template)
1233 (setq template (replace-match yes t t template)))
1234 (if (string-match ":MMLNO:" template)
1235 (setq template (replace-match no t t template)))
1236 ;; Return the modified template.
1237 (org-element-normalize-string template))))
1239 (defun org-html--build-preamble (info)
1240 "Return document preamble as a string, or nil.
1241 INFO is a plist used as a communication channel."
1242 (let ((preamble (plist-get info :html-preamble)))
1243 (when preamble
1244 (let ((preamble-contents
1245 (if (functionp preamble) (funcall preamble info)
1246 (let ((title (org-export-data (plist-get info :title) info))
1247 (date (if (not (plist-get info :with-date)) ""
1248 (org-export-data (plist-get info :date) info)))
1249 (author (if (not (plist-get info :with-author)) ""
1250 (org-export-data (plist-get info :author) info)))
1251 (email (if (not (plist-get info :with-email)) ""
1252 (plist-get info :email))))
1253 (if (stringp preamble)
1254 (format-spec preamble
1255 `((?t . ,title) (?a . ,author)
1256 (?d . ,date) (?e . ,email)))
1257 (format-spec
1258 (or (cadr (assoc (plist-get info :language)
1259 org-html-preamble-format))
1260 (cadr (assoc "en" org-html-preamble-format)))
1261 `((?t . ,title) (?a . ,author)
1262 (?d . ,date) (?e . ,email))))))))
1263 (when (org-string-nw-p preamble-contents)
1264 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1265 (org-element-normalize-string preamble-contents)
1266 "</div>\n"))))))
1268 (defun org-html--build-postamble (info)
1269 "Return document postamble as a string, or nil.
1270 INFO is a plist used as a communication channel."
1271 (let ((postamble (plist-get info :html-postamble)))
1272 (when postamble
1273 (let ((postamble-contents
1274 (if (functionp postamble) (funcall postamble info)
1275 (let ((date (if (not (plist-get info :with-date)) ""
1276 (org-export-data (plist-get info :date) info)))
1277 (author (let ((author (plist-get info :author)))
1278 (and author (org-export-data author info))))
1279 (email (mapconcat
1280 (lambda (e)
1281 (format "<a href=\"mailto:%s\">%s</a>" e e))
1282 (split-string (plist-get info :email) ",+ *")
1283 ", "))
1284 (html-validation-link (or org-html-validation-link ""))
1285 (creator-info (plist-get info :creator)))
1286 (cond ((stringp postamble)
1287 (format-spec postamble
1288 `((?a . ,author) (?e . ,email)
1289 (?d . ,date) (?c . ,creator-info)
1290 (?v . ,html-validation-link))))
1291 ((eq postamble 'auto)
1292 (concat
1293 (when (plist-get info :time-stamp-file)
1294 (format "<p class=\"date\">%s: %s</p>\n"
1295 (org-html--translate "Date" info)
1296 date))
1297 (when (and (plist-get info :with-author) author)
1298 (format "<p class=\"author\">%s : %s</p>\n"
1299 (org-html--translate "Author" info)
1300 author))
1301 (when (and (plist-get info :with-email) email)
1302 (format "<p class=\"email\">%s </p>\n" email))
1303 (when (plist-get info :with-creator)
1304 (format "<p class=\"creator\">%s</p>\n"
1305 creator-info))
1306 html-validation-link "\n"))
1307 (t (format-spec
1308 (or (cadr (assoc (plist-get info :language)
1309 org-html-postamble-format))
1310 (cadr (assoc "en" org-html-postamble-format)))
1311 `((?a . ,author) (?e . ,email)
1312 (?d . ,date) (?c . ,creator-info)
1313 (?v . ,html-validation-link)))))))))
1314 (when (org-string-nw-p postamble-contents)
1315 (concat
1316 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1317 (org-element-normalize-string postamble-contents)
1318 "</div>\n"))))))
1320 (defun org-html-inner-template (contents info)
1321 "Return body of document string after HTML conversion.
1322 CONTENTS is the transcoded contents string. INFO is a plist
1323 holding export options."
1324 (concat
1325 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1326 ;; Table of contents.
1327 (let ((depth (plist-get info :with-toc)))
1328 (when depth (org-html-toc depth info)))
1329 ;; Document contents.
1330 contents
1331 ;; Footnotes section.
1332 (org-html-footnote-section info)
1333 ;; Bibliography.
1334 (org-html-bibliography)
1335 "\n</div>"))
1337 (defun org-html-template (contents info)
1338 "Return complete document string after HTML conversion.
1339 CONTENTS is the transcoded contents string. INFO is a plist
1340 holding export options."
1341 (concat
1342 (format
1343 (or (and (stringp org-html-xml-declaration)
1344 org-html-xml-declaration)
1345 (cdr (assoc (plist-get info :html-extension)
1346 org-html-xml-declaration))
1347 (cdr (assoc "html" org-html-xml-declaration))
1350 (or (and org-html-coding-system
1351 (fboundp 'coding-system-get)
1352 (coding-system-get org-html-coding-system 'mime-charset))
1353 "iso-8859-1"))
1354 "\n"
1355 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1356 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1357 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1358 (plist-get info :language) (plist-get info :language))
1359 "<head>\n"
1360 (org-html--build-meta-info info)
1361 (org-html--build-style info)
1362 (org-html--build-mathjax-config info)
1363 "</head>\n"
1364 "<body>\n"
1365 (let ((link-up (org-trim (plist-get info :html-link-up)))
1366 (link-home (org-trim (plist-get info :html-link-home))))
1367 (unless (and (string= link-up "") (string= link-up ""))
1368 (format org-html-home/up-format
1369 (or link-up link-home)
1370 (or link-home link-up))))
1371 ;; Preamble.
1372 (org-html--build-preamble info)
1373 ;; Document title.
1374 (let ((title (plist-get info :title)))
1375 (when title
1376 (format "<h1 class=\"title\">%s</h1>\n" (org-export-data title info))))
1377 ;; Document contents.
1378 contents
1379 ;; Postamble.
1380 (org-html--build-postamble info)
1381 ;; Closing document.
1382 "</body>\n</html>"))
1384 (defun org-html--translate (s info)
1385 "Translate string S according to specified language.
1386 INFO is a plist used as a communication channel."
1387 (org-export-translate s :html info))
1389 ;;;; Anchor
1391 (defun org-html--anchor (&optional id desc attributes)
1392 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1393 (attributes (concat (and id (format " id=\"%s\"" id))
1394 (and name (format " name=\"%s\"" name))
1395 attributes)))
1396 (format "<a%s>%s</a>" attributes (or desc ""))))
1398 ;;;; Todo
1400 (defun org-html--todo (todo)
1401 (when todo
1402 (format "<span class=\"%s %s%s\">%s</span>"
1403 (if (member todo org-done-keywords) "done" "todo")
1404 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1405 todo)))
1407 ;;;; Tags
1409 (defun org-html--tags (tags)
1410 (when tags
1411 (format "<span class=\"tag\">%s</span>"
1412 (mapconcat
1413 (lambda (tag)
1414 (format "<span class=\"%s\">%s</span>"
1415 (concat org-html-tag-class-prefix
1416 (org-html-fix-class-name tag))
1417 tag))
1418 tags "&nbsp;"))))
1420 ;;;; Headline
1422 (defun* org-html-format-headline
1423 (todo todo-type priority text tags
1424 &key level section-number headline-label &allow-other-keys)
1425 (let ((section-number
1426 (when section-number
1427 (format "<span class=\"section-number-%d\">%s</span> "
1428 level section-number)))
1429 (todo (org-html--todo todo))
1430 (tags (org-html--tags tags)))
1431 (concat section-number todo (and todo " ") text
1432 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1434 ;;;; Src Code
1436 (defun org-html-fontify-code (code lang)
1437 "Color CODE with htmlize library.
1438 CODE is a string representing the source code to colorize. LANG
1439 is the language used for CODE, as a string, or nil."
1440 (when code
1441 (cond
1442 ;; Case 1: No lang. Possibly an example block.
1443 ((not lang)
1444 ;; Simple transcoding.
1445 (org-html-encode-plain-text code))
1446 ;; Case 2: No htmlize or an inferior version of htmlize
1447 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1448 ;; Emit a warning.
1449 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1450 ;; Simple transcoding.
1451 (org-html-encode-plain-text code))
1453 ;; Map language
1454 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1455 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1456 (cond
1457 ;; Case 1: Language is not associated with any Emacs mode
1458 ((not (functionp lang-mode))
1459 ;; Simple transcoding.
1460 (org-html-encode-plain-text code))
1461 ;; Case 2: Default. Fontify code.
1463 ;; htmlize
1464 (setq code (with-temp-buffer
1465 ;; Switch to language-specific mode.
1466 (funcall lang-mode)
1467 (insert code)
1468 ;; Fontify buffer.
1469 (font-lock-fontify-buffer)
1470 ;; Remove formatting on newline characters.
1471 (save-excursion
1472 (let ((beg (point-min))
1473 (end (point-max)))
1474 (goto-char beg)
1475 (while (progn (end-of-line) (< (point) end))
1476 (put-text-property (point) (1+ (point)) 'face nil)
1477 (forward-char 1))))
1478 (org-src-mode)
1479 (set-buffer-modified-p nil)
1480 ;; Htmlize region.
1481 (org-html-htmlize-region-for-paste
1482 (point-min) (point-max))))
1483 ;; Strip any enclosing <pre></pre> tags.
1484 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1485 (end (and beg (string-match "</pre>\\'" code))))
1486 (if (and beg end) (substring code beg end) code)))))))))
1488 (defun org-html-do-format-code
1489 (code &optional lang refs retain-labels num-start)
1490 "Format CODE string as source code.
1491 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1492 respectively, the language of the source code, as a string, an
1493 alist between line numbers and references (as returned by
1494 `org-export-unravel-code'), a boolean specifying if labels should
1495 appear in the source code, and the number associated to the first
1496 line of code."
1497 (let* ((code-lines (org-split-string code "\n"))
1498 (code-length (length code-lines))
1499 (num-fmt
1500 (and num-start
1501 (format "%%%ds: "
1502 (length (number-to-string (+ code-length num-start))))))
1503 (code (org-html-fontify-code code lang)))
1504 (org-export-format-code
1505 code
1506 (lambda (loc line-num ref)
1507 (setq loc
1508 (concat
1509 ;; Add line number, if needed.
1510 (when num-start
1511 (format "<span class=\"linenr\">%s</span>"
1512 (format num-fmt line-num)))
1513 ;; Transcoded src line.
1515 ;; Add label, if needed.
1516 (when (and ref retain-labels) (format " (%s)" ref))))
1517 ;; Mark transcoded line as an anchor, if needed.
1518 (if (not ref) loc
1519 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1520 ref loc)))
1521 num-start refs)))
1523 (defun org-html-format-code (element info)
1524 "Format contents of ELEMENT as source code.
1525 ELEMENT is either an example block or a src block. INFO is
1526 a plist used as a communication channel."
1527 (let* ((lang (org-element-property :language element))
1528 ;; Extract code and references.
1529 (code-info (org-export-unravel-code element))
1530 (code (car code-info))
1531 (refs (cdr code-info))
1532 ;; Does the src block contain labels?
1533 (retain-labels (org-element-property :retain-labels element))
1534 ;; Does it have line numbers?
1535 (num-start (case (org-element-property :number-lines element)
1536 (continued (org-export-get-loc element info))
1537 (new 0))))
1538 (org-html-do-format-code code lang refs retain-labels num-start)))
1542 ;;; Tables of Contents
1544 (defun org-html-toc (depth info)
1545 "Build a table of contents.
1546 DEPTH is an integer specifying the depth of the table. INFO is
1547 a plist used as a communication channel. Return the table of
1548 contents as a string, or nil if it is empty."
1549 (let ((toc-entries
1550 (mapcar (lambda (headline)
1551 (cons (org-html--format-toc-headline headline info)
1552 (org-export-get-relative-level headline info)))
1553 (org-export-collect-headlines info depth))))
1554 (when toc-entries
1555 (concat "<div id=\"table-of-contents\">\n"
1556 (format "<h%d>%s</h%d>\n"
1557 org-html-toplevel-hlevel
1558 (org-html--translate "Table of Contents" info)
1559 org-html-toplevel-hlevel)
1560 "<div id=\"text-table-of-contents\">"
1561 (org-html--toc-text toc-entries)
1562 "</div>\n"
1563 "</div>\n"))))
1565 (defun org-html--toc-text (toc-entries)
1566 "Return innards of a table of contents, as a string.
1567 TOC-ENTRIES is an alist where key is an entry title, as a string,
1568 and value is its relative level, as an integer."
1569 (let* ((prev-level (1- (cdar toc-entries)))
1570 (start-level prev-level))
1571 (concat
1572 (mapconcat
1573 (lambda (entry)
1574 (let ((headline (car entry))
1575 (level (cdr entry)))
1576 (concat
1577 (let* ((cnt (- level prev-level))
1578 (times (if (> cnt 0) (1- cnt) (- cnt)))
1579 rtn)
1580 (setq prev-level level)
1581 (concat
1582 (org-html--make-string
1583 times (cond ((> cnt 0) "\n<ul>\n<li>")
1584 ((< cnt 0) "</li>\n</ul>\n")))
1585 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1586 headline)))
1587 toc-entries "")
1588 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1590 (defun org-html--format-toc-headline (headline info)
1591 "Return an appropriate table of contents entry for HEADLINE.
1592 INFO is a plist used as a communication channel."
1593 (let* ((headline-number (org-export-get-headline-number headline info))
1594 (section-number
1595 (and (not (org-export-low-level-p headline info))
1596 (org-export-numbered-headline-p headline info)
1597 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1598 (tags (and (eq (plist-get info :with-tags) t)
1599 (org-export-get-tags headline info))))
1600 (format "<a href=\"#%s\">%s</a>"
1601 ;; Label.
1602 (org-export-solidify-link-text
1603 (or (org-element-property :CUSTOM_ID headline)
1604 (concat "sec-" (mapconcat 'number-to-string
1605 headline-number "-"))))
1606 ;; Body.
1607 (concat section-number
1608 (org-export-data
1609 (org-export-get-alt-title headline info) info)
1610 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags)))))
1612 (defun org-html-list-of-listings (info)
1613 "Build a list of listings.
1614 INFO is a plist used as a communication channel. Return the list
1615 of listings as a string, or nil if it is empty."
1616 (let ((lol-entries (org-export-collect-listings info)))
1617 (when lol-entries
1618 (concat "<div id=\"list-of-listings\">\n"
1619 (format "<h%d>%s</h%d>\n"
1620 org-html-toplevel-hlevel
1621 (org-html--translate "List of Listings" info)
1622 org-html-toplevel-hlevel)
1623 "<div id=\"text-list-of-listings\">\n<ul>\n"
1624 (let ((count 0)
1625 (initial-fmt (org-html--translate "Listing %d:" info)))
1626 (mapconcat
1627 (lambda (entry)
1628 (let ((label (org-element-property :name entry))
1629 (title (org-trim
1630 (org-export-data
1631 (or (org-export-get-caption entry t)
1632 (org-export-get-caption entry))
1633 info))))
1634 (concat
1635 "<li>"
1636 (if (not label)
1637 (concat (format initial-fmt (incf count)) " " title)
1638 (format "<a href=\"#%s\">%s %s</a>"
1639 (org-export-solidify-link-text label)
1640 (format initial-fmt (incf count))
1641 title))
1642 "</li>")))
1643 lol-entries "\n"))
1644 "\n</ul>\n</div>\n</div>"))))
1646 (defun org-html-list-of-tables (info)
1647 "Build a list of tables.
1648 INFO is a plist used as a communication channel. Return the list
1649 of tables as a string, or nil if it is empty."
1650 (let ((lol-entries (org-export-collect-tables info)))
1651 (when lol-entries
1652 (concat "<div id=\"list-of-tables\">\n"
1653 (format "<h%d>%s</h%d>\n"
1654 org-html-toplevel-hlevel
1655 (org-html--translate "List of Tables" info)
1656 org-html-toplevel-hlevel)
1657 "<div id=\"text-list-of-tables\">\n<ul>\n"
1658 (let ((count 0)
1659 (initial-fmt (org-html--translate "Table %d:" info)))
1660 (mapconcat
1661 (lambda (entry)
1662 (let ((label (org-element-property :name entry))
1663 (title (org-trim
1664 (org-export-data
1665 (or (org-export-get-caption entry t)
1666 (org-export-get-caption entry))
1667 info))))
1668 (concat
1669 "<li>"
1670 (if (not label)
1671 (concat (format initial-fmt (incf count)) " " title)
1672 (format "<a href=\"#%s\">%s %s</a>"
1673 (org-export-solidify-link-text label)
1674 (format initial-fmt (incf count))
1675 title))
1676 "</li>")))
1677 lol-entries "\n"))
1678 "\n</ul>\n</div>\n</div>"))))
1682 ;;; Transcode Functions
1684 ;;;; Bold
1686 (defun org-html-bold (bold contents info)
1687 "Transcode BOLD from Org to HTML.
1688 CONTENTS is the text with bold markup. INFO is a plist holding
1689 contextual information."
1690 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1691 contents))
1694 ;;;; Center Block
1696 (defun org-html-center-block (center-block contents info)
1697 "Transcode a CENTER-BLOCK element from Org to HTML.
1698 CONTENTS holds the contents of the block. INFO is a plist
1699 holding contextual information."
1700 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1703 ;;;; Clock
1705 (defun org-html-clock (clock contents info)
1706 "Transcode a CLOCK element from Org to HTML.
1707 CONTENTS is nil. INFO is a plist used as a communication
1708 channel."
1709 (format "<p>
1710 <span class=\"timestamp-wrapper\">
1711 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1712 </span>
1713 </p>"
1714 org-clock-string
1715 (org-translate-time
1716 (org-element-property :raw-value
1717 (org-element-property :value clock)))
1718 (let ((time (org-element-property :duration clock)))
1719 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1722 ;;;; Code
1724 (defun org-html-code (code contents info)
1725 "Transcode CODE from Org to HTML.
1726 CONTENTS is nil. INFO is a plist holding contextual
1727 information."
1728 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1729 (org-element-property :value code)))
1732 ;;;; Drawer
1734 (defun org-html-drawer (drawer contents info)
1735 "Transcode a DRAWER element from Org to HTML.
1736 CONTENTS holds the contents of the block. INFO is a plist
1737 holding contextual information."
1738 (if (functionp org-html-format-drawer-function)
1739 (funcall org-html-format-drawer-function
1740 (org-element-property :drawer-name drawer)
1741 contents)
1742 ;; If there's no user defined function: simply
1743 ;; display contents of the drawer.
1744 contents))
1747 ;;;; Dynamic Block
1749 (defun org-html-dynamic-block (dynamic-block contents info)
1750 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1751 CONTENTS holds the contents of the block. INFO is a plist
1752 holding contextual information. See `org-export-data'."
1753 contents)
1756 ;;;; Entity
1758 (defun org-html-entity (entity contents info)
1759 "Transcode an ENTITY object from Org to HTML.
1760 CONTENTS are the definition itself. INFO is a plist holding
1761 contextual information."
1762 (org-element-property :html entity))
1765 ;;;; Example Block
1767 (defun org-html-example-block (example-block contents info)
1768 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1769 CONTENTS is nil. INFO is a plist holding contextual
1770 information."
1771 (if (org-export-read-attribute :attr_html example-block :textarea)
1772 (org-html--textarea-block example-block)
1773 (format "<pre class=\"example\">\n%s</pre>"
1774 (org-html-format-code example-block info))))
1777 ;;;; Export Snippet
1779 (defun org-html-export-snippet (export-snippet contents info)
1780 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1781 CONTENTS is nil. INFO is a plist holding contextual
1782 information."
1783 (when (eq (org-export-snippet-backend export-snippet) 'html)
1784 (org-element-property :value export-snippet)))
1787 ;;;; Export Block
1789 (defun org-html-export-block (export-block contents info)
1790 "Transcode a EXPORT-BLOCK element from Org to HTML.
1791 CONTENTS is nil. INFO is a plist holding contextual information."
1792 (when (string= (org-element-property :type export-block) "HTML")
1793 (org-remove-indentation (org-element-property :value export-block))))
1796 ;;;; Fixed Width
1798 (defun org-html-fixed-width (fixed-width contents info)
1799 "Transcode a FIXED-WIDTH element from Org to HTML.
1800 CONTENTS is nil. INFO is a plist holding contextual information."
1801 (format "<pre class=\"example\">\n%s</pre>"
1802 (org-html-do-format-code
1803 (org-remove-indentation
1804 (org-element-property :value fixed-width)))))
1807 ;;;; Footnote Reference
1809 (defun org-html-footnote-reference (footnote-reference contents info)
1810 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1811 CONTENTS is nil. INFO is a plist holding contextual information."
1812 (concat
1813 ;; Insert separator between two footnotes in a row.
1814 (let ((prev (org-export-get-previous-element footnote-reference info)))
1815 (when (eq (org-element-type prev) 'footnote-reference)
1816 org-html-footnote-separator))
1817 (cond
1818 ((not (org-export-footnote-first-reference-p footnote-reference info))
1819 (org-html-format-footnote-reference
1820 (org-export-get-footnote-number footnote-reference info)
1821 "IGNORED" 100))
1822 ;; Inline definitions are secondary strings.
1823 ((eq (org-element-property :type footnote-reference) 'inline)
1824 (org-html-format-footnote-reference
1825 (org-export-get-footnote-number footnote-reference info)
1826 "IGNORED" 1))
1827 ;; Non-inline footnotes definitions are full Org data.
1828 (t (org-html-format-footnote-reference
1829 (org-export-get-footnote-number footnote-reference info)
1830 "IGNORED" 1)))))
1833 ;;;; Headline
1835 (defun org-html-format-headline--wrap
1836 (headline info &optional format-function &rest extra-keys)
1837 "Transcode a HEADLINE element from Org to HTML.
1838 CONTENTS holds the contents of the headline. INFO is a plist
1839 holding contextual information."
1840 (let* ((level (+ (org-export-get-relative-level headline info)
1841 (1- org-html-toplevel-hlevel)))
1842 (headline-number (org-export-get-headline-number headline info))
1843 (section-number (and (not (org-export-low-level-p headline info))
1844 (org-export-numbered-headline-p headline info)
1845 (mapconcat 'number-to-string
1846 headline-number ".")))
1847 (todo (and (plist-get info :with-todo-keywords)
1848 (let ((todo (org-element-property :todo-keyword headline)))
1849 (and todo (org-export-data todo info)))))
1850 (todo-type (and todo (org-element-property :todo-type headline)))
1851 (priority (and (plist-get info :with-priority)
1852 (org-element-property :priority headline)))
1853 (text (org-export-data (org-element-property :title headline) info))
1854 (tags (and (plist-get info :with-tags)
1855 (org-export-get-tags headline info)))
1856 (headline-label (or (org-element-property :CUSTOM_ID headline)
1857 (concat "sec-" (mapconcat 'number-to-string
1858 headline-number "-"))))
1859 (format-function (cond
1860 ((functionp format-function) format-function)
1861 ((functionp org-html-format-headline-function)
1862 (function*
1863 (lambda (todo todo-type priority text tags
1864 &allow-other-keys)
1865 (funcall org-html-format-headline-function
1866 todo todo-type priority text tags))))
1867 (t 'org-html-format-headline))))
1868 (apply format-function
1869 todo todo-type priority text tags
1870 :headline-label headline-label :level level
1871 :section-number section-number extra-keys)))
1873 (defun org-html-headline (headline contents info)
1874 "Transcode a HEADLINE element from Org to HTML.
1875 CONTENTS holds the contents of the headline. INFO is a plist
1876 holding contextual information."
1877 ;; Empty contents?
1878 (setq contents (or contents ""))
1879 (let* ((numberedp (org-export-numbered-headline-p headline info))
1880 (level (org-export-get-relative-level headline info))
1881 (text (org-export-data (org-element-property :title headline) info))
1882 (todo (and (plist-get info :with-todo-keywords)
1883 (let ((todo (org-element-property :todo-keyword headline)))
1884 (and todo (org-export-data todo info)))))
1885 (todo-type (and todo (org-element-property :todo-type headline)))
1886 (tags (and (plist-get info :with-tags)
1887 (org-export-get-tags headline info)))
1888 (priority (and (plist-get info :with-priority)
1889 (org-element-property :priority headline)))
1890 (section-number (and (org-export-numbered-headline-p headline info)
1891 (mapconcat 'number-to-string
1892 (org-export-get-headline-number
1893 headline info) ".")))
1894 ;; Create the headline text.
1895 (full-text (org-html-format-headline--wrap headline info)))
1896 (cond
1897 ;; Case 1: This is a footnote section: ignore it.
1898 ((org-element-property :footnote-section-p headline) nil)
1899 ;; Case 2. This is a deep sub-tree: export it as a list item.
1900 ;; Also export as items headlines for which no section
1901 ;; format has been found.
1902 ((org-export-low-level-p headline info)
1903 ;; Build the real contents of the sub-tree.
1904 (let* ((type (if numberedp 'ordered 'unordered))
1905 (itemized-body (org-html-format-list-item
1906 contents type nil nil full-text)))
1907 (concat
1908 (and (org-export-first-sibling-p headline info)
1909 (org-html-begin-plain-list type))
1910 itemized-body
1911 (and (org-export-last-sibling-p headline info)
1912 (org-html-end-plain-list type)))))
1913 ;; Case 3. Standard headline. Export it as a section.
1915 (let* ((section-number (mapconcat 'number-to-string
1916 (org-export-get-headline-number
1917 headline info) "-"))
1918 (ids (remove 'nil
1919 (list (org-element-property :CUSTOM_ID headline)
1920 (concat "sec-" section-number)
1921 (org-element-property :ID headline))))
1922 (preferred-id (car ids))
1923 (extra-ids (cdr ids))
1924 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
1925 (level1 (+ level (1- org-html-toplevel-hlevel))))
1926 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1927 (format "outline-container-%s"
1928 (or (org-element-property :CUSTOM_ID headline)
1929 section-number))
1930 (concat (format "outline-%d" level1) (and extra-class " ")
1931 extra-class)
1932 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1933 level1
1934 preferred-id
1935 (mapconcat
1936 (lambda (x)
1937 (let ((id (org-export-solidify-link-text
1938 (if (org-uuidgen-p x) (concat "ID-" x)
1939 x))))
1940 (org-html--anchor id)))
1941 extra-ids "")
1942 full-text
1943 level1)
1944 contents))))))
1947 ;;;; Horizontal Rule
1949 (defun org-html-horizontal-rule (horizontal-rule contents info)
1950 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1951 CONTENTS is nil. INFO is a plist holding contextual information."
1952 "<hr/>")
1955 ;;;; Inline Src Block
1957 (defun org-html-inline-src-block (inline-src-block contents info)
1958 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1959 CONTENTS holds the contents of the item. INFO is a plist holding
1960 contextual information."
1961 (let* ((org-lang (org-element-property :language inline-src-block))
1962 (code (org-element-property :value inline-src-block)))
1963 (error "Cannot export inline src block")))
1966 ;;;; Inlinetask
1968 (defun org-html-format-section (text class &optional id)
1969 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1970 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1972 (defun org-html-inlinetask (inlinetask contents info)
1973 "Transcode an INLINETASK element from Org to HTML.
1974 CONTENTS holds the contents of the block. INFO is a plist
1975 holding contextual information."
1976 (cond
1977 ;; If `org-html-format-inlinetask-function' is provided, call it
1978 ;; with appropriate arguments.
1979 ((functionp org-html-format-inlinetask-function)
1980 (let ((format-function
1981 (function*
1982 (lambda (todo todo-type priority text tags
1983 &key contents &allow-other-keys)
1984 (funcall org-html-format-inlinetask-function
1985 todo todo-type priority text tags contents)))))
1986 (org-html-format-headline--wrap
1987 inlinetask info format-function :contents contents)))
1988 ;; Otherwise, use a default template.
1989 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1990 (org-html-format-headline--wrap inlinetask info)
1991 contents))))
1994 ;;;; Italic
1996 (defun org-html-italic (italic contents info)
1997 "Transcode ITALIC from Org to HTML.
1998 CONTENTS is the text with italic markup. INFO is a plist holding
1999 contextual information."
2000 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2003 ;;;; Item
2005 (defun org-html-checkbox (checkbox)
2006 (case checkbox (on "<code>[X]</code>")
2007 (off "<code>[&nbsp;]</code>")
2008 (trans "<code>[-]</code>")
2009 (t "")))
2011 (defun org-html-format-list-item (contents type checkbox
2012 &optional term-counter-id
2013 headline)
2014 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2015 (concat
2016 (case type
2017 (ordered
2018 (let* ((counter term-counter-id)
2019 (extra (if counter (format " value=\"%s\"" counter) "")))
2020 (concat
2021 (format "<li%s>" extra)
2022 (when headline (concat headline "<br/>")))))
2023 (unordered
2024 (let* ((id term-counter-id)
2025 (extra (if id (format " id=\"%s\"" id) "")))
2026 (concat
2027 (format "<li%s>" extra)
2028 (when headline (concat headline "<br/>")))))
2029 (descriptive
2030 (let* ((term term-counter-id))
2031 (setq term (or term "(no term)"))
2032 ;; Check-boxes in descriptive lists are associated to tag.
2033 (concat (format "<dt> %s </dt>"
2034 (concat checkbox term))
2035 "<dd>"))))
2036 (unless (eq type 'descriptive) checkbox)
2037 contents
2038 (case type
2039 (ordered "</li>")
2040 (unordered "</li>")
2041 (descriptive "</dd>")))))
2043 (defun org-html-item (item contents info)
2044 "Transcode an ITEM element from Org to HTML.
2045 CONTENTS holds the contents of the item. INFO is a plist holding
2046 contextual information."
2047 (let* ((plain-list (org-export-get-parent item))
2048 (type (org-element-property :type plain-list))
2049 (counter (org-element-property :counter item))
2050 (checkbox (org-element-property :checkbox item))
2051 (tag (let ((tag (org-element-property :tag item)))
2052 (and tag (org-export-data tag info)))))
2053 (org-html-format-list-item
2054 contents type checkbox (or tag counter))))
2057 ;;;; Keyword
2059 (defun org-html-keyword (keyword contents info)
2060 "Transcode a KEYWORD element from Org to HTML.
2061 CONTENTS is nil. INFO is a plist holding contextual information."
2062 (let ((key (org-element-property :key keyword))
2063 (value (org-element-property :value keyword)))
2064 (cond
2065 ((string= key "HTML") value)
2066 ;; Invisible targets.
2067 ((string= key "TARGET") nil)
2068 ((string= key "TOC")
2069 (let ((value (downcase value)))
2070 (cond
2071 ((string-match "\\<headlines\\>" value)
2072 (let ((depth (or (and (string-match "[0-9]+" value)
2073 (string-to-number (match-string 0 value)))
2074 (plist-get info :with-toc))))
2075 (org-html-toc depth info)))
2076 ((string= "listings" value) (org-html-list-of-listings info))
2077 ((string= "tables" value) (org-html-list-of-tables info))))))))
2080 ;;;; Latex Environment
2082 (defun org-html-format-latex (latex-frag processing-type)
2083 "Format LaTeX fragments into HTML."
2084 (let ((cache-relpath "") (cache-dir "") bfn)
2085 (unless (eq processing-type 'mathjax)
2086 (setq bfn (buffer-file-name)
2087 cache-relpath
2088 (concat "ltxpng/"
2089 (file-name-sans-extension
2090 (file-name-nondirectory bfn)))
2091 cache-dir (file-name-directory bfn)))
2092 (with-temp-buffer
2093 (insert latex-frag)
2094 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2095 nil nil processing-type)
2096 (buffer-string))))
2098 (defun org-html-latex-environment (latex-environment contents info)
2099 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2100 CONTENTS is nil. INFO is a plist holding contextual information."
2101 (let ((processing-type (plist-get info :with-latex))
2102 (latex-frag (org-remove-indentation
2103 (org-element-property :value latex-environment)))
2104 (caption (org-export-data
2105 (org-export-get-caption latex-environment) info))
2106 (attr nil) ; FIXME
2107 (label (org-element-property :name latex-environment)))
2108 (cond
2109 ((memq processing-type '(t mathjax))
2110 (org-html-format-latex latex-frag 'mathjax))
2111 ((eq processing-type 'dvipng)
2112 (let* ((formula-link (org-html-format-latex
2113 latex-frag processing-type)))
2114 (when (and formula-link
2115 (string-match "file:\\([^]]*\\)" formula-link))
2116 (org-html-format-inline-image
2117 (match-string 1 formula-link) caption label attr t))))
2118 (t latex-frag))))
2121 ;;;; Latex Fragment
2123 (defun org-html-latex-fragment (latex-fragment contents info)
2124 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2125 CONTENTS is nil. INFO is a plist holding contextual information."
2126 (let ((latex-frag (org-element-property :value latex-fragment))
2127 (processing-type (plist-get info :with-latex)))
2128 (case processing-type
2129 ((t mathjax)
2130 (org-html-format-latex latex-frag 'mathjax))
2131 (dvipng
2132 (let* ((formula-link (org-html-format-latex
2133 latex-frag processing-type)))
2134 (when (and formula-link
2135 (string-match "file:\\([^]]*\\)" formula-link))
2136 (org-html-format-inline-image
2137 (match-string 1 formula-link)))))
2138 (t latex-frag))))
2141 ;;;; Line Break
2143 (defun org-html-line-break (line-break contents info)
2144 "Transcode a LINE-BREAK object from Org to HTML.
2145 CONTENTS is nil. INFO is a plist holding contextual information."
2146 "<br/>\n")
2149 ;;;; Link
2151 (defun org-html-link--inline-image (link desc info)
2152 "Return HTML code for an inline image.
2153 LINK is the link pointing to the inline image. INFO is a plist
2154 used as a communication channel."
2155 (let* ((type (org-element-property :type link))
2156 (raw-path (org-element-property :path link))
2157 (path (cond ((member type '("http" "https"))
2158 (concat type ":" raw-path))
2159 ((file-name-absolute-p raw-path)
2160 (expand-file-name raw-path))
2161 (t raw-path)))
2162 (parent (org-export-get-parent-element link))
2163 (caption (org-export-data (org-export-get-caption parent) info))
2164 (label (org-element-property :name parent))
2165 ;; Retrieve latex attributes from the PARENT element. HACK:
2166 ;; Only do this for the first link in PARENT. This is needed
2167 ;; as long as attributes cannot be set on a per link basis.
2168 (attr (when (eq link (org-element-map parent 'link 'identity info t))
2169 (let ((raw-attr
2170 (mapconcat #'identity
2171 (org-element-property :attr_html parent)
2172 " ")))
2173 (unless (string= raw-attr "") raw-attr)))))
2174 ;; Now clear ATTR from any special keyword and set a default
2175 ;; value if nothing is left.
2176 (setq attr (if (not attr) "" (org-trim attr)))
2177 ;; Return proper string, depending on DISPOSITION.
2178 (org-html-format-inline-image
2179 path caption label attr (org-html-standalone-image-p link info))))
2181 (defvar org-html-standalone-image-predicate)
2182 (defun org-html-standalone-image-p (element info &optional predicate)
2183 "Test if ELEMENT is a standalone image for the purpose HTML export.
2184 INFO is a plist holding contextual information.
2186 Return non-nil, if ELEMENT is of type paragraph and it's sole
2187 content, save for whitespaces, is a link that qualifies as an
2188 inline image.
2190 Return non-nil, if ELEMENT is of type link and it's containing
2191 paragraph has no other content save for leading and trailing
2192 whitespaces.
2194 Return nil, otherwise.
2196 Bind `org-html-standalone-image-predicate' to constrain
2197 paragraph further. For example, to check for only captioned
2198 standalone images, do the following.
2200 \(setq org-html-standalone-image-predicate
2201 \(lambda \(paragraph\)
2202 \(org-element-property :caption paragraph\)\)\)"
2203 (let ((paragraph (case (org-element-type element)
2204 (paragraph element)
2205 (link (and (org-export-inline-image-p
2206 element org-html-inline-image-rules)
2207 (org-export-get-parent element)))
2208 (t nil))))
2209 (when (eq (org-element-type paragraph) 'paragraph)
2210 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2211 (functionp org-html-standalone-image-predicate)))
2212 (funcall org-html-standalone-image-predicate paragraph))
2213 (let ((contents (org-element-contents paragraph)))
2214 (loop for x in contents
2215 with inline-image-count = 0
2216 always (cond
2217 ((eq (org-element-type x) 'plain-text)
2218 (not (org-string-nw-p x)))
2219 ((eq (org-element-type x) 'link)
2220 (when (org-export-inline-image-p
2221 x org-html-inline-image-rules)
2222 (= (incf inline-image-count) 1)))
2223 (t nil))))))))
2225 (defun org-html-link (link desc info)
2226 "Transcode a LINK object from Org to HTML.
2228 DESC is the description part of the link, or the empty string.
2229 INFO is a plist holding contextual information. See
2230 `org-export-data'."
2231 (let* ((--link-org-files-as-html-maybe
2232 (function
2233 (lambda (raw-path info)
2234 "Treat links to `file.org' as links to `file.html', if needed.
2235 See `org-html-link-org-files-as-html'."
2236 (cond
2237 ((and org-html-link-org-files-as-html
2238 (string= ".org"
2239 (downcase (file-name-extension raw-path "."))))
2240 (concat (file-name-sans-extension raw-path) "."
2241 (plist-get info :html-extension)))
2242 (t raw-path)))))
2243 (type (org-element-property :type link))
2244 (raw-path (org-element-property :path link))
2245 ;; Ensure DESC really exists, or set it to nil.
2246 (desc (and (not (string= desc "")) desc))
2247 (path
2248 (cond
2249 ((member type '("http" "https" "ftp" "mailto"))
2250 (concat type ":" raw-path))
2251 ((string= type "file")
2252 ;; Treat links to ".org" files as ".html", if needed.
2253 (setq raw-path
2254 (funcall --link-org-files-as-html-maybe raw-path info))
2255 ;; If file path is absolute, prepend it with protocol
2256 ;; component - "file://".
2257 (when (file-name-absolute-p raw-path)
2258 (setq raw-path
2259 (concat "file://" (expand-file-name raw-path))))
2260 ;; Add search option, if any. A search option can be
2261 ;; relative to a custom-id or a headline title. Any other
2262 ;; option is ignored.
2263 (let ((option (org-element-property :search-option link)))
2264 (cond ((not option) raw-path)
2265 ((eq (aref option 0) ?#) (concat raw-path option))
2266 ;; External fuzzy link: try to resolve it if path
2267 ;; belongs to current project, if any.
2268 ((eq (aref option 0) ?*)
2269 (concat
2270 raw-path
2271 (let ((numbers
2272 (org-publish-resolve-external-fuzzy-link
2273 (org-element-property :path link) option)))
2274 (and numbers (concat "#sec-"
2275 (mapconcat 'number-to-string
2276 numbers "-")))))))))
2277 (t raw-path)))
2278 attributes protocol)
2279 ;; Extract attributes from parent's paragraph. HACK: Only do this
2280 ;; for the first link in parent. This is needed as long as
2281 ;; attributes cannot be set on a per link basis.
2282 (and (setq attributes
2283 (let ((parent (org-export-get-parent-element link)))
2284 (if (not (eq (org-element-map parent 'link 'identity info t)
2285 link))
2287 (mapconcat
2288 'identity
2289 (let ((att (org-element-property :attr_html parent)))
2290 (unless (and desc att
2291 (string-match (regexp-quote (car att)) desc))
2292 att))
2293 " "))))
2294 (setq attributes (concat " " attributes)))
2295 (cond
2296 ;; Image file.
2297 ((and (or (eq t org-html-inline-images)
2298 (and org-html-inline-images (not desc)))
2299 (org-export-inline-image-p link org-html-inline-image-rules))
2300 (org-html-link--inline-image link desc info))
2301 ;; Radio target: Transcode target's contents and use them as
2302 ;; link's description.
2303 ((string= type "radio")
2304 (let ((destination (org-export-resolve-radio-link link info)))
2305 (when destination
2306 (format "<a href=\"#%s\"%s>%s</a>"
2307 (org-export-solidify-link-text path)
2308 attributes
2309 (org-export-data (org-element-contents destination) info)))))
2310 ;; Links pointing to a headline: Find destination and build
2311 ;; appropriate referencing command.
2312 ((member type '("custom-id" "fuzzy" "id"))
2313 (let ((destination (if (string= type "fuzzy")
2314 (org-export-resolve-fuzzy-link link info)
2315 (org-export-resolve-id-link link info))))
2316 (case (org-element-type destination)
2317 ;; ID link points to an external file.
2318 (plain-text
2319 (let ((fragment (concat "ID-" path))
2320 ;; Treat links to ".org" files as ".html", if needed.
2321 (path (funcall --link-org-files-as-html-maybe
2322 destination info)))
2323 (format "<a href=\"%s#%s\"%s>%s</a>"
2324 path fragment attributes (or desc destination))))
2325 ;; Fuzzy link points nowhere.
2326 ((nil)
2327 (format "<i>%s</i>"
2328 (or desc
2329 (org-export-data
2330 (org-element-property :raw-link link) info))))
2331 ;; Fuzzy link points to an invisible target.
2332 (keyword nil)
2333 ;; Link points to a headline.
2334 (headline
2335 (let ((href
2336 ;; What href to use?
2337 (cond
2338 ;; Case 1: Headline is linked via it's CUSTOM_ID
2339 ;; property. Use CUSTOM_ID.
2340 ((string= type "custom-id")
2341 (org-element-property :CUSTOM_ID destination))
2342 ;; Case 2: Headline is linked via it's ID property
2343 ;; or through other means. Use the default href.
2344 ((member type '("id" "fuzzy"))
2345 (format "sec-%s"
2346 (mapconcat 'number-to-string
2347 (org-export-get-headline-number
2348 destination info) "-")))
2349 (t (error "Shouldn't reach here"))))
2350 ;; What description to use?
2351 (desc
2352 ;; Case 1: Headline is numbered and LINK has no
2353 ;; description or LINK's description matches
2354 ;; headline's title. Display section number.
2355 (if (and (org-export-numbered-headline-p destination info)
2356 (or (not desc)
2357 (string= desc (org-element-property
2358 :raw-value destination))))
2359 (mapconcat 'number-to-string
2360 (org-export-get-headline-number
2361 destination info) ".")
2362 ;; Case 2: Either the headline is un-numbered or
2363 ;; LINK has a custom description. Display LINK's
2364 ;; description or headline's title.
2365 (or desc (org-export-data (org-element-property
2366 :title destination) info)))))
2367 (format "<a href=\"#%s\"%s>%s</a>"
2368 (org-export-solidify-link-text href) attributes desc)))
2369 ;; Fuzzy link points to a target. Do as above.
2371 (let ((path (org-export-solidify-link-text path)) number)
2372 (unless desc
2373 (setq number (cond
2374 ((org-html-standalone-image-p destination info)
2375 (org-export-get-ordinal
2376 (assoc 'link (org-element-contents destination))
2377 info 'link 'org-html-standalone-image-p))
2378 (t (org-export-get-ordinal destination info))))
2379 (setq desc (when number
2380 (if (atom number) (number-to-string number)
2381 (mapconcat 'number-to-string number ".")))))
2382 (format "<a href=\"#%s\"%s>%s</a>"
2383 path attributes (or desc "No description for this link")))))))
2384 ;; Coderef: replace link with the reference name or the
2385 ;; equivalent line number.
2386 ((string= type "coderef")
2387 (let ((fragment (concat "coderef-" path)))
2388 (format "<a href=\"#%s\" %s%s>%s</a>"
2389 fragment
2390 (format (concat "class=\"coderef\""
2391 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2392 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2393 fragment fragment)
2394 attributes
2395 (format (org-export-get-coderef-format path desc)
2396 (org-export-resolve-coderef path info)))))
2397 ;; Link type is handled by a special function.
2398 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2399 (funcall protocol (org-link-unescape path) desc 'html))
2400 ;; External link with a description part.
2401 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2402 ;; External link without a description part.
2403 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2404 ;; No path, only description. Try to do something useful.
2405 (t (format "<i>%s</i>" desc)))))
2408 ;;;; Paragraph
2410 (defun org-html-paragraph (paragraph contents info)
2411 "Transcode a PARAGRAPH element from Org to HTML.
2412 CONTENTS is the contents of the paragraph, as a string. INFO is
2413 the plist used as a communication channel."
2414 (let* ((style nil) ; FIXME
2415 (class (cdr (assoc style '((footnote . "footnote")
2416 (verse . nil)))))
2417 (extra (if class (format " class=\"%s\"" class) ""))
2418 (parent (org-export-get-parent paragraph)))
2419 (cond
2420 ((and (eq (org-element-type parent) 'item)
2421 (= (org-element-property :begin paragraph)
2422 (org-element-property :contents-begin parent)))
2423 ;; leading paragraph in a list item have no tags
2424 contents)
2425 ((org-html-standalone-image-p paragraph info)
2426 ;; standalone image
2427 contents)
2428 (t (format "<p%s>\n%s</p>" extra contents)))))
2431 ;;;; Plain List
2433 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2434 ;; the correct value for the item counter
2435 (defun org-html-begin-plain-list (type &optional arg1)
2436 "Insert the beginning of the HTML list depending on TYPE.
2437 When ARG1 is a string, use it as the start parameter for ordered
2438 lists."
2439 (case type
2440 (ordered
2441 (format "<ol class=\"org-ol\"%s>"
2442 (if arg1 (format " start=\"%d\"" arg1) "")))
2443 (unordered "<ul class=\"org-ul\">")
2444 (descriptive "<dl class=\"org-dl\">")))
2446 (defun org-html-end-plain-list (type)
2447 "Insert the end of the HTML list depending on TYPE."
2448 (case type
2449 (ordered "</ol>")
2450 (unordered "</ul>")
2451 (descriptive "</dl>")))
2453 (defun org-html-plain-list (plain-list contents info)
2454 "Transcode a PLAIN-LIST element from Org to HTML.
2455 CONTENTS is the contents of the list. INFO is a plist holding
2456 contextual information."
2457 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2458 (type (org-element-property :type plain-list)))
2459 (format "%s\n%s%s"
2460 (org-html-begin-plain-list type)
2461 contents (org-html-end-plain-list type))))
2463 ;;;; Plain Text
2465 (defun org-html-convert-special-strings (string)
2466 "Convert special characters in STRING to HTML."
2467 (let ((all org-html-special-string-regexps)
2468 e a re rpl start)
2469 (while (setq a (pop all))
2470 (setq re (car a) rpl (cdr a) start 0)
2471 (while (string-match re string start)
2472 (setq string (replace-match rpl t nil string))))
2473 string))
2475 (defun org-html-encode-plain-text (text)
2476 "Convert plain text characters to HTML equivalent.
2477 Possible conversions are set in `org-export-html-protect-char-alist'."
2478 (mapc
2479 (lambda (pair)
2480 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2481 org-html-protect-char-alist)
2482 text)
2484 (defun org-html-plain-text (text info)
2485 "Transcode a TEXT string from Org to HTML.
2486 TEXT is the string to transcode. INFO is a plist holding
2487 contextual information."
2488 (let ((output text))
2489 ;; Protect following characters: <, >, &.
2490 (setq output (org-html-encode-plain-text output))
2491 ;; Handle smart quotes. Be sure to provide original string since
2492 ;; OUTPUT may have been modified.
2493 (when (plist-get info :with-smart-quotes)
2494 (setq output (org-export-activate-smart-quotes output :html info text)))
2495 ;; Handle special strings.
2496 (when (plist-get info :with-special-strings)
2497 (setq output (org-html-convert-special-strings output)))
2498 ;; Handle break preservation if required.
2499 (when (plist-get info :preserve-breaks)
2500 (setq output
2501 (replace-regexp-in-string
2502 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2503 ;; Return value.
2504 output))
2507 ;; Planning
2509 (defun org-html-planning (planning contents info)
2510 "Transcode a PLANNING element from Org to HTML.
2511 CONTENTS is nil. INFO is a plist used as a communication
2512 channel."
2513 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2514 (format
2515 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2516 (mapconcat
2517 'identity
2518 (delq nil
2519 (list
2520 (let ((closed (org-element-property :closed planning)))
2521 (when closed
2522 (format span-fmt org-closed-string
2523 (org-translate-time
2524 (org-element-property :raw-value closed)))))
2525 (let ((deadline (org-element-property :deadline planning)))
2526 (when deadline
2527 (format span-fmt org-deadline-string
2528 (org-translate-time
2529 (org-element-property :raw-value deadline)))))
2530 (let ((scheduled (org-element-property :scheduled planning)))
2531 (when scheduled
2532 (format span-fmt org-scheduled-string
2533 (org-translate-time
2534 (org-element-property :raw-value scheduled)))))))
2535 " "))))
2538 ;;;; Property Drawer
2540 (defun org-html-property-drawer (property-drawer contents info)
2541 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2542 CONTENTS is nil. INFO is a plist holding contextual
2543 information."
2544 ;; The property drawer isn't exported but we want separating blank
2545 ;; lines nonetheless.
2549 ;;;; Quote Block
2551 (defun org-html-quote-block (quote-block contents info)
2552 "Transcode a QUOTE-BLOCK element from Org to HTML.
2553 CONTENTS holds the contents of the block. INFO is a plist
2554 holding contextual information."
2555 (format "<blockquote>\n%s</blockquote>" contents))
2558 ;;;; Quote Section
2560 (defun org-html-quote-section (quote-section contents info)
2561 "Transcode a QUOTE-SECTION element from Org to HTML.
2562 CONTENTS is nil. INFO is a plist holding contextual information."
2563 (let ((value (org-remove-indentation
2564 (org-element-property :value quote-section))))
2565 (when value (format "<pre>\n%s</pre>" value))))
2568 ;;;; Section
2570 (defun org-html-section (section contents info)
2571 "Transcode a SECTION element from Org to HTML.
2572 CONTENTS holds the contents of the section. INFO is a plist
2573 holding contextual information."
2574 (let ((parent (org-export-get-parent-headline section)))
2575 ;; Before first headline: no container, just return CONTENTS.
2576 (if (not parent) contents
2577 ;; Get div's class and id references.
2578 (let* ((class-num (+ (org-export-get-relative-level parent info)
2579 (1- org-html-toplevel-hlevel)))
2580 (section-number
2581 (mapconcat
2582 'number-to-string
2583 (org-export-get-headline-number parent info) "-")))
2584 ;; Build return value.
2585 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2586 class-num
2587 (or (org-element-property :CUSTOM_ID parent) section-number)
2588 contents)))))
2590 ;;;; Radio Target
2592 (defun org-html-radio-target (radio-target text info)
2593 "Transcode a RADIO-TARGET object from Org to HTML.
2594 TEXT is the text of the target. INFO is a plist holding
2595 contextual information."
2596 (let ((id (org-export-solidify-link-text
2597 (org-element-property :value radio-target))))
2598 (org-html--anchor id text)))
2601 ;;;; Special Block
2603 (defun org-html-special-block (special-block contents info)
2604 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2605 CONTENTS holds the contents of the block. INFO is a plist
2606 holding contextual information."
2607 (format "<div class=\"%s\">\n%s\n</div>"
2608 (downcase (org-element-property :type special-block))
2609 contents))
2612 ;;;; Src Block
2614 (defun org-html-src-block (src-block contents info)
2615 "Transcode a SRC-BLOCK element from Org to HTML.
2616 CONTENTS holds the contents of the item. INFO is a plist holding
2617 contextual information."
2618 (if (org-export-read-attribute :attr_html src-block :textarea)
2619 (org-html--textarea-block src-block)
2620 (let ((lang (org-element-property :language src-block))
2621 (caption (org-export-get-caption src-block))
2622 (code (org-html-format-code src-block info))
2623 (label (let ((lbl (org-element-property :name src-block)))
2624 (if (not lbl) ""
2625 (format " id=\"%s\""
2626 (org-export-solidify-link-text lbl))))))
2627 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2628 (format
2629 "<div class=\"org-src-container\">\n%s%s\n</div>"
2630 (if (not caption) ""
2631 (format "<label class=\"org-src-name\">%s</label>"
2632 (org-export-data caption info)))
2633 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2636 ;;;; Statistics Cookie
2638 (defun org-html-statistics-cookie (statistics-cookie contents info)
2639 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2640 CONTENTS is nil. INFO is a plist holding contextual information."
2641 (let ((cookie-value (org-element-property :value statistics-cookie)))
2642 (format "<code>%s</code>" cookie-value)))
2645 ;;;; Strike-Through
2647 (defun org-html-strike-through (strike-through contents info)
2648 "Transcode STRIKE-THROUGH from Org to HTML.
2649 CONTENTS is the text with strike-through markup. INFO is a plist
2650 holding contextual information."
2651 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2652 contents))
2655 ;;;; Subscript
2657 (defun org-html-subscript (subscript contents info)
2658 "Transcode a SUBSCRIPT object from Org to HTML.
2659 CONTENTS is the contents of the object. INFO is a plist holding
2660 contextual information."
2661 (format "<sub>%s</sub>" contents))
2664 ;;;; Superscript
2666 (defun org-html-superscript (superscript contents info)
2667 "Transcode a SUPERSCRIPT object from Org to HTML.
2668 CONTENTS is the contents of the object. INFO is a plist holding
2669 contextual information."
2670 (format "<sup>%s</sup>" contents))
2673 ;;;; Tabel Cell
2675 (defun org-html-table-cell (table-cell contents info)
2676 "Transcode a TABLE-CELL element from Org to HTML.
2677 CONTENTS is nil. INFO is a plist used as a communication
2678 channel."
2679 (let* ((table-row (org-export-get-parent table-cell))
2680 (table (org-export-get-parent-table table-cell))
2681 (cell-attrs
2682 (if (not org-html-table-align-individual-fields) ""
2683 (format (if (and (boundp 'org-html-format-table-no-css)
2684 org-html-format-table-no-css)
2685 " align=\"%s\"" " class=\"%s\"")
2686 (org-export-table-cell-alignment table-cell info)))))
2687 (when (or (not contents) (string= "" (org-trim contents)))
2688 (setq contents "&nbsp;"))
2689 (cond
2690 ((and (org-export-table-has-header-p table info)
2691 (= 1 (org-export-table-row-group table-row info)))
2692 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2693 contents (cdr org-html-table-header-tags)))
2694 ((and org-html-table-use-header-tags-for-first-column
2695 (zerop (cdr (org-export-table-cell-address table-cell info))))
2696 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2697 contents (cdr org-html-table-header-tags)))
2698 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2699 contents (cdr org-html-table-data-tags))))))
2702 ;;;; Table Row
2704 (defun org-html-table-row (table-row contents info)
2705 "Transcode a TABLE-ROW element from Org to HTML.
2706 CONTENTS is the contents of the row. INFO is a plist used as a
2707 communication channel."
2708 ;; Rules are ignored since table separators are deduced from
2709 ;; borders of the current row.
2710 (when (eq (org-element-property :type table-row) 'standard)
2711 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2712 (rowgroup-tags
2713 (cond
2714 ;; Case 1: Row belongs to second or subsequent rowgroups.
2715 ((not (= 1 (org-export-table-row-group table-row info)))
2716 '("<tbody>" . "\n</tbody>"))
2717 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2718 ((org-export-table-has-header-p
2719 (org-export-get-parent-table table-row) info)
2720 '("<thead>" . "\n</thead>"))
2721 ;; Case 2: Row is from first and only row group.
2722 (t '("<tbody>" . "\n</tbody>")))))
2723 (concat
2724 ;; Begin a rowgroup?
2725 (when (org-export-table-row-starts-rowgroup-p table-row info)
2726 (car rowgroup-tags))
2727 ;; Actual table row
2728 (concat "\n" (eval (car org-html-table-row-tags))
2729 contents
2730 "\n"
2731 (eval (cdr org-html-table-row-tags)))
2732 ;; End a rowgroup?
2733 (when (org-export-table-row-ends-rowgroup-p table-row info)
2734 (cdr rowgroup-tags))))))
2737 ;;;; Table
2739 (defun org-html-table-first-row-data-cells (table info)
2740 (let ((table-row
2741 (org-element-map table 'table-row
2742 (lambda (row)
2743 (unless (eq (org-element-property :type row) 'rule) row))
2744 info 'first-match))
2745 (special-column-p (org-export-table-has-special-column-p table)))
2746 (if (not special-column-p) (org-element-contents table-row)
2747 (cdr (org-element-contents table-row)))))
2749 (defun org-html-table--table.el-table (table info)
2750 (when (eq (org-element-property :type table) 'table.el)
2751 (require 'table)
2752 (let ((outbuf (with-current-buffer
2753 (get-buffer-create "*org-export-table*")
2754 (erase-buffer) (current-buffer))))
2755 (with-temp-buffer
2756 (insert (org-element-property :value table))
2757 (goto-char 1)
2758 (re-search-forward "^[ \t]*|[^|]" nil t)
2759 (table-generate-source 'html outbuf))
2760 (with-current-buffer outbuf
2761 (prog1 (org-trim (buffer-string))
2762 (kill-buffer) )))))
2764 (defun org-html-table (table contents info)
2765 "Transcode a TABLE element from Org to HTML.
2766 CONTENTS is the contents of the table. INFO is a plist holding
2767 contextual information."
2768 (case (org-element-property :type table)
2769 ;; Case 1: table.el table. Convert it using appropriate tools.
2770 (table.el (org-html-table--table.el-table table info))
2771 ;; Case 2: Standard table.
2773 (let* ((label (org-element-property :name table))
2774 (caption (org-export-get-caption table))
2775 (attributes (mapconcat #'identity
2776 (org-element-property :attr_html table)
2777 " "))
2778 (alignspec
2779 (if (and (boundp 'org-html-format-table-no-css)
2780 org-html-format-table-no-css)
2781 "align=\"%s\"" "class=\"%s\""))
2782 (table-column-specs
2783 (function
2784 (lambda (table info)
2785 (mapconcat
2786 (lambda (table-cell)
2787 (let ((alignment (org-export-table-cell-alignment
2788 table-cell info)))
2789 (concat
2790 ;; Begin a colgroup?
2791 (when (org-export-table-cell-starts-colgroup-p
2792 table-cell info)
2793 "\n<colgroup>")
2794 ;; Add a column. Also specify it's alignment.
2795 (format "\n<col %s/>" (format alignspec alignment))
2796 ;; End a colgroup?
2797 (when (org-export-table-cell-ends-colgroup-p
2798 table-cell info)
2799 "\n</colgroup>"))))
2800 (org-html-table-first-row-data-cells table info) "\n"))))
2801 (table-attributes
2802 (let ((table-tag (plist-get info :html-table-tag)))
2803 (concat
2804 (and (string-match "<table\\(.*\\)>" table-tag)
2805 (match-string 1 table-tag))
2806 (and label (format " id=\"%s\""
2807 (org-export-solidify-link-text label)))
2808 (unless (string= attributes "")
2809 (concat " " attributes))))))
2810 ;; Remove last blank line.
2811 (setq contents (substring contents 0 -1))
2812 (format "<table%s>\n%s\n%s\n%s\n</table>"
2813 table-attributes
2814 (if (not caption) ""
2815 (format "<caption>%s</caption>"
2816 (org-export-data caption info)))
2817 (funcall table-column-specs table info)
2818 contents)))))
2821 ;;;; Target
2823 (defun org-html-target (target contents info)
2824 "Transcode a TARGET object from Org to HTML.
2825 CONTENTS is nil. INFO is a plist holding contextual
2826 information."
2827 (let ((id (org-export-solidify-link-text
2828 (org-element-property :value target))))
2829 (org-html--anchor id)))
2832 ;;;; Timestamp
2834 (defun org-html-timestamp (timestamp contents info)
2835 "Transcode a TIMESTAMP object from Org to HTML.
2836 CONTENTS is nil. INFO is a plist holding contextual
2837 information."
2838 (let ((value (org-html-plain-text
2839 (org-timestamp-translate timestamp) info)))
2840 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2841 (replace-regexp-in-string "--" "&ndash;" value))))
2844 ;;;; Underline
2846 (defun org-html-underline (underline contents info)
2847 "Transcode UNDERLINE from Org to HTML.
2848 CONTENTS is the text with underline markup. INFO is a plist
2849 holding contextual information."
2850 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2851 contents))
2854 ;;;; Verbatim
2856 (defun org-html-verbatim (verbatim contents info)
2857 "Transcode VERBATIM from Org to HTML.
2858 CONTENTS is nil. INFO is a plist holding contextual
2859 information."
2860 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2861 (org-element-property :value verbatim)))
2864 ;;;; Verse Block
2866 (defun org-html-verse-block (verse-block contents info)
2867 "Transcode a VERSE-BLOCK element from Org to HTML.
2868 CONTENTS is verse block contents. INFO is a plist holding
2869 contextual information."
2870 ;; Replace each newline character with line break. Also replace
2871 ;; each blank line with a line break.
2872 (setq contents (replace-regexp-in-string
2873 "^ *\\\\\\\\$" "<br/>\n"
2874 (replace-regexp-in-string
2875 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2876 ;; Replace each white space at beginning of a line with a
2877 ;; non-breaking space.
2878 (while (string-match "^[ \t]+" contents)
2879 (let* ((num-ws (length (match-string 0 contents)))
2880 (ws (let (out) (dotimes (i num-ws out)
2881 (setq out (concat out "&nbsp;"))))))
2882 (setq contents (replace-match ws nil t contents))))
2883 (format "<p class=\"verse\">\n%s</p>" contents))
2887 ;;; Filter Functions
2889 (defun org-html-final-function (contents backend info)
2890 (if (not org-html-pretty-output) contents
2891 (with-temp-buffer
2892 (html-mode)
2893 (insert contents)
2894 (indent-region (point-min) (point-max))
2895 (buffer-substring-no-properties (point-min) (point-max)))))
2899 ;;; End-user functions
2901 ;;;###autoload
2902 (defun org-html-export-as-html
2903 (&optional async subtreep visible-only body-only ext-plist)
2904 "Export current buffer to an HTML buffer.
2906 If narrowing is active in the current buffer, only export its
2907 narrowed part.
2909 If a region is active, export that region.
2911 A non-nil optional argument ASYNC means the process should happen
2912 asynchronously. The resulting buffer should be accessible
2913 through the `org-export-stack' interface.
2915 When optional argument SUBTREEP is non-nil, export the sub-tree
2916 at point, extracting information from the headline properties
2917 first.
2919 When optional argument VISIBLE-ONLY is non-nil, don't export
2920 contents of hidden elements.
2922 When optional argument BODY-ONLY is non-nil, only write code
2923 between \"<body>\" and \"</body>\" tags.
2925 EXT-PLIST, when provided, is a property list with external
2926 parameters overriding Org default settings, but still inferior to
2927 file-local settings.
2929 Export is done in a buffer named \"*Org HTML Export*\", which
2930 will be displayed when `org-export-show-temporary-export-buffer'
2931 is non-nil."
2932 (interactive)
2933 (if async
2934 (org-export-async-start
2935 (lambda (output)
2936 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2937 (erase-buffer)
2938 (insert output)
2939 (goto-char (point-min))
2940 (funcall org-html-display-buffer-mode)
2941 (org-export-add-to-stack (current-buffer) 'html)))
2942 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2943 (let ((outbuf (org-export-to-buffer
2944 'html "*Org HTML Export*"
2945 subtreep visible-only body-only ext-plist)))
2946 ;; Set major mode.
2947 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2948 (when org-export-show-temporary-export-buffer
2949 (switch-to-buffer-other-window outbuf)))))
2951 ;;;###autoload
2952 (defun org-html-export-to-html
2953 (&optional async subtreep visible-only body-only ext-plist)
2954 "Export current buffer to a HTML file.
2956 If narrowing is active in the current buffer, only export its
2957 narrowed part.
2959 If a region is active, export that region.
2961 A non-nil optional argument ASYNC means the process should happen
2962 asynchronously. The resulting file should be accessible through
2963 the `org-export-stack' interface.
2965 When optional argument SUBTREEP is non-nil, export the sub-tree
2966 at point, extracting information from the headline properties
2967 first.
2969 When optional argument VISIBLE-ONLY is non-nil, don't export
2970 contents of hidden elements.
2972 When optional argument BODY-ONLY is non-nil, only write code
2973 between \"<body>\" and \"</body>\" tags.
2975 EXT-PLIST, when provided, is a property list with external
2976 parameters overriding Org default settings, but still inferior to
2977 file-local settings.
2979 Return output file's name."
2980 (interactive)
2981 (let* ((extension (concat "." org-html-extension))
2982 (file (org-export-output-file-name extension subtreep))
2983 (org-export-coding-system org-html-coding-system))
2984 (if async
2985 (org-export-async-start
2986 (lambda (f) (org-export-add-to-stack f 'html))
2987 (let ((org-export-coding-system org-html-coding-system))
2988 `(expand-file-name
2989 (org-export-to-file
2990 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2991 (let ((org-export-coding-system org-html-coding-system))
2992 (org-export-to-file
2993 'html file subtreep visible-only body-only ext-plist)))))
2995 ;;;###autoload
2996 (defun org-html-publish-to-html (plist filename pub-dir)
2997 "Publish an org file to HTML.
2999 FILENAME is the filename of the Org file to be published. PLIST
3000 is the property list for the given project. PUB-DIR is the
3001 publishing directory.
3003 Return output file name."
3004 (org-publish-org-to 'html filename ".html" plist pub-dir))
3008 ;;; FIXME
3010 ;;;; org-format-table-html
3011 ;;;; org-format-org-table-html
3012 ;;;; org-format-table-table-html
3013 ;;;; org-table-number-fraction
3014 ;;;; org-table-number-regexp
3015 ;;;; org-html-table-caption-above
3016 ;;;; org-html-with-timestamp
3017 ;;;; org-html-html-helper-timestamp
3018 ;;;; org-html-inline-image-extensions
3019 ;;;; org-export-preferred-target-alist
3020 ;;;; class for anchors
3021 ;;;; org-export-with-section-numbers, body-only
3022 ;;;; org-export-mark-todo-in-toc
3023 ;;;; org-html-format-org-link
3024 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3025 ;;;; alt = (file-name-nondirectory path)
3027 (provide 'ox-html)
3029 ;; Local variables:
3030 ;; generated-autoload-file: "org-loaddefs.el"
3031 ;; End:
3033 ;;; ox-html.el ends here