Merge branch 'maint'
[org-mode.git] / lisp / ox-html.el
blob81551bfcf02a5d5ef85d96da012522450fd8e84d
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 ;; Document title.
1327 (format "<h1 class=\"title\">%s</h1>\n"
1328 (org-export-data (plist-get info :title) info))
1329 ;; Table of contents.
1330 (let ((depth (plist-get info :with-toc)))
1331 (when depth (org-html-toc depth info)))
1332 ;; Document contents.
1333 contents
1334 ;; Footnotes section.
1335 (org-html-footnote-section info)
1336 ;; Bibliography.
1337 (org-html-bibliography)
1338 "\n</div>"))
1340 (defun org-html-template (contents info)
1341 "Return complete document string after HTML conversion.
1342 CONTENTS is the transcoded contents string. INFO is a plist
1343 holding export options."
1344 (concat
1345 (format
1346 (or (and (stringp org-html-xml-declaration)
1347 org-html-xml-declaration)
1348 (cdr (assoc (plist-get info :html-extension)
1349 org-html-xml-declaration))
1350 (cdr (assoc "html" org-html-xml-declaration))
1353 (or (and org-html-coding-system
1354 (fboundp 'coding-system-get)
1355 (coding-system-get org-html-coding-system 'mime-charset))
1356 "iso-8859-1"))
1357 "\n"
1358 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1359 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1360 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1361 (plist-get info :language) (plist-get info :language))
1362 "<head>\n"
1363 (org-html--build-meta-info info)
1364 (org-html--build-style info)
1365 (org-html--build-mathjax-config info)
1366 "</head>\n"
1367 "<body>\n"
1368 (let ((link-up (org-trim (plist-get info :html-link-up)))
1369 (link-home (org-trim (plist-get info :html-link-home))))
1370 (unless (and (string= link-up "") (string= link-up ""))
1371 (format org-html-home/up-format
1372 (or link-up link-home)
1373 (or link-home link-up))))
1374 ;; Preamble.
1375 (org-html--build-preamble info)
1376 ;; Document contents.
1377 contents
1378 ;; Postamble.
1379 (org-html--build-postamble info)
1380 ;; Closing document.
1381 "</body>\n</html>"))
1383 (defun org-html--translate (s info)
1384 "Translate string S according to specified language.
1385 INFO is a plist used as a communication channel."
1386 (org-export-translate s :html info))
1388 ;;;; Anchor
1390 (defun org-html--anchor (&optional id desc attributes)
1391 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1392 (attributes (concat (and id (format " id=\"%s\"" id))
1393 (and name (format " name=\"%s\"" name))
1394 attributes)))
1395 (format "<a%s>%s</a>" attributes (or desc ""))))
1397 ;;;; Todo
1399 (defun org-html--todo (todo)
1400 (when todo
1401 (format "<span class=\"%s %s%s\">%s</span>"
1402 (if (member todo org-done-keywords) "done" "todo")
1403 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1404 todo)))
1406 ;;;; Tags
1408 (defun org-html--tags (tags)
1409 (when tags
1410 (format "<span class=\"tag\">%s</span>"
1411 (mapconcat
1412 (lambda (tag)
1413 (format "<span class=\"%s\">%s</span>"
1414 (concat org-html-tag-class-prefix
1415 (org-html-fix-class-name tag))
1416 tag))
1417 tags "&nbsp;"))))
1419 ;;;; Headline
1421 (defun* org-html-format-headline
1422 (todo todo-type priority text tags
1423 &key level section-number headline-label &allow-other-keys)
1424 (let ((section-number
1425 (when section-number
1426 (format "<span class=\"section-number-%d\">%s</span> "
1427 level section-number)))
1428 (todo (org-html--todo todo))
1429 (tags (org-html--tags tags)))
1430 (concat section-number todo (and todo " ") text
1431 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1433 ;;;; Src Code
1435 (defun org-html-fontify-code (code lang)
1436 "Color CODE with htmlize library.
1437 CODE is a string representing the source code to colorize. LANG
1438 is the language used for CODE, as a string, or nil."
1439 (when code
1440 (cond
1441 ;; Case 1: No lang. Possibly an example block.
1442 ((not lang)
1443 ;; Simple transcoding.
1444 (org-html-encode-plain-text code))
1445 ;; Case 2: No htmlize or an inferior version of htmlize
1446 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1447 ;; Emit a warning.
1448 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1449 ;; Simple transcoding.
1450 (org-html-encode-plain-text code))
1452 ;; Map language
1453 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1454 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1455 (cond
1456 ;; Case 1: Language is not associated with any Emacs mode
1457 ((not (functionp lang-mode))
1458 ;; Simple transcoding.
1459 (org-html-encode-plain-text code))
1460 ;; Case 2: Default. Fontify code.
1462 ;; htmlize
1463 (setq code (with-temp-buffer
1464 ;; Switch to language-specific mode.
1465 (funcall lang-mode)
1466 (insert code)
1467 ;; Fontify buffer.
1468 (font-lock-fontify-buffer)
1469 ;; Remove formatting on newline characters.
1470 (save-excursion
1471 (let ((beg (point-min))
1472 (end (point-max)))
1473 (goto-char beg)
1474 (while (progn (end-of-line) (< (point) end))
1475 (put-text-property (point) (1+ (point)) 'face nil)
1476 (forward-char 1))))
1477 (org-src-mode)
1478 (set-buffer-modified-p nil)
1479 ;; Htmlize region.
1480 (org-html-htmlize-region-for-paste
1481 (point-min) (point-max))))
1482 ;; Strip any enclosing <pre></pre> tags.
1483 (let* ((beg (and (string-match "\\`<pre[^>]*>\n*" code) (match-end 0)))
1484 (end (and beg (string-match "</pre>\\'" code))))
1485 (if (and beg end) (substring code beg end) code)))))))))
1487 (defun org-html-do-format-code
1488 (code &optional lang refs retain-labels num-start)
1489 "Format CODE string as source code.
1490 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1491 respectively, the language of the source code, as a string, an
1492 alist between line numbers and references (as returned by
1493 `org-export-unravel-code'), a boolean specifying if labels should
1494 appear in the source code, and the number associated to the first
1495 line of code."
1496 (let* ((code-lines (org-split-string code "\n"))
1497 (code-length (length code-lines))
1498 (num-fmt
1499 (and num-start
1500 (format "%%%ds: "
1501 (length (number-to-string (+ code-length num-start))))))
1502 (code (org-html-fontify-code code lang)))
1503 (org-export-format-code
1504 code
1505 (lambda (loc line-num ref)
1506 (setq loc
1507 (concat
1508 ;; Add line number, if needed.
1509 (when num-start
1510 (format "<span class=\"linenr\">%s</span>"
1511 (format num-fmt line-num)))
1512 ;; Transcoded src line.
1514 ;; Add label, if needed.
1515 (when (and ref retain-labels) (format " (%s)" ref))))
1516 ;; Mark transcoded line as an anchor, if needed.
1517 (if (not ref) loc
1518 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1519 ref loc)))
1520 num-start refs)))
1522 (defun org-html-format-code (element info)
1523 "Format contents of ELEMENT as source code.
1524 ELEMENT is either an example block or a src block. INFO is
1525 a plist used as a communication channel."
1526 (let* ((lang (org-element-property :language element))
1527 ;; Extract code and references.
1528 (code-info (org-export-unravel-code element))
1529 (code (car code-info))
1530 (refs (cdr code-info))
1531 ;; Does the src block contain labels?
1532 (retain-labels (org-element-property :retain-labels element))
1533 ;; Does it have line numbers?
1534 (num-start (case (org-element-property :number-lines element)
1535 (continued (org-export-get-loc element info))
1536 (new 0))))
1537 (org-html-do-format-code code lang refs retain-labels num-start)))
1541 ;;; Tables of Contents
1543 (defun org-html-toc (depth info)
1544 "Build a table of contents.
1545 DEPTH is an integer specifying the depth of the table. INFO is
1546 a plist used as a communication channel. Return the table of
1547 contents as a string, or nil if it is empty."
1548 (let ((toc-entries
1549 (mapcar (lambda (headline)
1550 (cons (org-html--format-toc-headline headline info)
1551 (org-export-get-relative-level headline info)))
1552 (org-export-collect-headlines info depth))))
1553 (when toc-entries
1554 (concat "<div id=\"table-of-contents\">\n"
1555 (format "<h%d>%s</h%d>\n"
1556 org-html-toplevel-hlevel
1557 (org-html--translate "Table of Contents" info)
1558 org-html-toplevel-hlevel)
1559 "<div id=\"text-table-of-contents\">"
1560 (org-html--toc-text toc-entries)
1561 "</div>\n"
1562 "</div>\n"))))
1564 (defun org-html--toc-text (toc-entries)
1565 "Return innards of a table of contents, as a string.
1566 TOC-ENTRIES is an alist where key is an entry title, as a string,
1567 and value is its relative level, as an integer."
1568 (let* ((prev-level (1- (cdar toc-entries)))
1569 (start-level prev-level))
1570 (concat
1571 (mapconcat
1572 (lambda (entry)
1573 (let ((headline (car entry))
1574 (level (cdr entry)))
1575 (concat
1576 (let* ((cnt (- level prev-level))
1577 (times (if (> cnt 0) (1- cnt) (- cnt)))
1578 rtn)
1579 (setq prev-level level)
1580 (concat
1581 (org-html--make-string
1582 times (cond ((> cnt 0) "\n<ul>\n<li>")
1583 ((< cnt 0) "</li>\n</ul>\n")))
1584 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1585 headline)))
1586 toc-entries "")
1587 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1589 (defun org-html--format-toc-headline (headline info)
1590 "Return an appropriate table of contents entry for HEADLINE.
1591 INFO is a plist used as a communication channel."
1592 (let* ((headline-number (org-export-get-headline-number headline info))
1593 (section-number
1594 (and (not (org-export-low-level-p headline info))
1595 (org-export-numbered-headline-p headline info)
1596 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1597 (tags (and (eq (plist-get info :with-tags) t)
1598 (org-export-get-tags headline info))))
1599 (format "<a href=\"#%s\">%s</a>"
1600 ;; Label.
1601 (org-export-solidify-link-text
1602 (or (org-element-property :CUSTOM_ID headline)
1603 (concat "sec-" (mapconcat 'number-to-string
1604 headline-number "-"))))
1605 ;; Body.
1606 (concat section-number
1607 (org-export-data
1608 (org-export-get-optional-title headline info) info)
1609 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags)))))
1611 (defun org-html-list-of-listings (info)
1612 "Build a list of listings.
1613 INFO is a plist used as a communication channel. Return the list
1614 of listings as a string, or nil if it is empty."
1615 (let ((lol-entries (org-export-collect-listings info)))
1616 (when lol-entries
1617 (concat "<div id=\"list-of-listings\">\n"
1618 (format "<h%d>%s</h%d>\n"
1619 org-html-toplevel-hlevel
1620 (org-html--translate "List of Listings" info)
1621 org-html-toplevel-hlevel)
1622 "<div id=\"text-list-of-listings\">\n<ul>\n"
1623 (let ((count 0)
1624 (initial-fmt (org-html--translate "Listing %d:" info)))
1625 (mapconcat
1626 (lambda (entry)
1627 (let ((label (org-element-property :name entry))
1628 (title (org-trim
1629 (org-export-data
1630 (or (org-export-get-caption entry t)
1631 (org-export-get-caption entry))
1632 info))))
1633 (concat
1634 "<li>"
1635 (if (not label)
1636 (concat (format initial-fmt (incf count)) " " title)
1637 (format "<a href=\"#%s\">%s %s</a>"
1638 (org-export-solidify-link-text label)
1639 (format initial-fmt (incf count))
1640 title))
1641 "</li>")))
1642 lol-entries "\n"))
1643 "\n</ul>\n</div>\n</div>"))))
1645 (defun org-html-list-of-tables (info)
1646 "Build a list of tables.
1647 INFO is a plist used as a communication channel. Return the list
1648 of tables as a string, or nil if it is empty."
1649 (let ((lol-entries (org-export-collect-tables info)))
1650 (when lol-entries
1651 (concat "<div id=\"list-of-tables\">\n"
1652 (format "<h%d>%s</h%d>\n"
1653 org-html-toplevel-hlevel
1654 (org-html--translate "List of Tables" info)
1655 org-html-toplevel-hlevel)
1656 "<div id=\"text-list-of-tables\">\n<ul>\n"
1657 (let ((count 0)
1658 (initial-fmt (org-html--translate "Table %d:" info)))
1659 (mapconcat
1660 (lambda (entry)
1661 (let ((label (org-element-property :name entry))
1662 (title (org-trim
1663 (org-export-data
1664 (or (org-export-get-caption entry t)
1665 (org-export-get-caption entry))
1666 info))))
1667 (concat
1668 "<li>"
1669 (if (not label)
1670 (concat (format initial-fmt (incf count)) " " title)
1671 (format "<a href=\"#%s\">%s %s</a>"
1672 (org-export-solidify-link-text label)
1673 (format initial-fmt (incf count))
1674 title))
1675 "</li>")))
1676 lol-entries "\n"))
1677 "\n</ul>\n</div>\n</div>"))))
1681 ;;; Transcode Functions
1683 ;;;; Bold
1685 (defun org-html-bold (bold contents info)
1686 "Transcode BOLD from Org to HTML.
1687 CONTENTS is the text with bold markup. INFO is a plist holding
1688 contextual information."
1689 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1690 contents))
1693 ;;;; Center Block
1695 (defun org-html-center-block (center-block contents info)
1696 "Transcode a CENTER-BLOCK element from Org to HTML.
1697 CONTENTS holds the contents of the block. INFO is a plist
1698 holding contextual information."
1699 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1702 ;;;; Clock
1704 (defun org-html-clock (clock contents info)
1705 "Transcode a CLOCK element from Org to HTML.
1706 CONTENTS is nil. INFO is a plist used as a communication
1707 channel."
1708 (format "<p>
1709 <span class=\"timestamp-wrapper\">
1710 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1711 </span>
1712 </p>"
1713 org-clock-string
1714 (org-translate-time
1715 (org-element-property :raw-value
1716 (org-element-property :value clock)))
1717 (let ((time (org-element-property :duration clock)))
1718 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1721 ;;;; Code
1723 (defun org-html-code (code contents info)
1724 "Transcode CODE from Org to HTML.
1725 CONTENTS is nil. INFO is a plist holding contextual
1726 information."
1727 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1728 (org-element-property :value code)))
1731 ;;;; Drawer
1733 (defun org-html-drawer (drawer contents info)
1734 "Transcode a DRAWER element from Org to HTML.
1735 CONTENTS holds the contents of the block. INFO is a plist
1736 holding contextual information."
1737 (if (functionp org-html-format-drawer-function)
1738 (funcall org-html-format-drawer-function
1739 (org-element-property :drawer-name drawer)
1740 contents)
1741 ;; If there's no user defined function: simply
1742 ;; display contents of the drawer.
1743 contents))
1746 ;;;; Dynamic Block
1748 (defun org-html-dynamic-block (dynamic-block contents info)
1749 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1750 CONTENTS holds the contents of the block. INFO is a plist
1751 holding contextual information. See `org-export-data'."
1752 contents)
1755 ;;;; Entity
1757 (defun org-html-entity (entity contents info)
1758 "Transcode an ENTITY object from Org to HTML.
1759 CONTENTS are the definition itself. INFO is a plist holding
1760 contextual information."
1761 (org-element-property :html entity))
1764 ;;;; Example Block
1766 (defun org-html-example-block (example-block contents info)
1767 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1768 CONTENTS is nil. INFO is a plist holding contextual
1769 information."
1770 (if (org-export-read-attribute :attr_html example-block :textarea)
1771 (org-html--textarea-block example-block)
1772 (format "<pre class=\"example\">\n%s</pre>"
1773 (org-html-format-code example-block info))))
1776 ;;;; Export Snippet
1778 (defun org-html-export-snippet (export-snippet contents info)
1779 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1780 CONTENTS is nil. INFO is a plist holding contextual
1781 information."
1782 (when (eq (org-export-snippet-backend export-snippet) 'html)
1783 (org-element-property :value export-snippet)))
1786 ;;;; Export Block
1788 (defun org-html-export-block (export-block contents info)
1789 "Transcode a EXPORT-BLOCK element from Org to HTML.
1790 CONTENTS is nil. INFO is a plist holding contextual information."
1791 (when (string= (org-element-property :type export-block) "HTML")
1792 (org-remove-indentation (org-element-property :value export-block))))
1795 ;;;; Fixed Width
1797 (defun org-html-fixed-width (fixed-width contents info)
1798 "Transcode a FIXED-WIDTH element from Org to HTML.
1799 CONTENTS is nil. INFO is a plist holding contextual information."
1800 (format "<pre class=\"example\">\n%s</pre>"
1801 (org-html-do-format-code
1802 (org-remove-indentation
1803 (org-element-property :value fixed-width)))))
1806 ;;;; Footnote Reference
1808 (defun org-html-footnote-reference (footnote-reference contents info)
1809 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1810 CONTENTS is nil. INFO is a plist holding contextual information."
1811 (concat
1812 ;; Insert separator between two footnotes in a row.
1813 (let ((prev (org-export-get-previous-element footnote-reference info)))
1814 (when (eq (org-element-type prev) 'footnote-reference)
1815 org-html-footnote-separator))
1816 (cond
1817 ((not (org-export-footnote-first-reference-p footnote-reference info))
1818 (org-html-format-footnote-reference
1819 (org-export-get-footnote-number footnote-reference info)
1820 "IGNORED" 100))
1821 ;; Inline definitions are secondary strings.
1822 ((eq (org-element-property :type footnote-reference) 'inline)
1823 (org-html-format-footnote-reference
1824 (org-export-get-footnote-number footnote-reference info)
1825 "IGNORED" 1))
1826 ;; Non-inline footnotes definitions are full Org data.
1827 (t (org-html-format-footnote-reference
1828 (org-export-get-footnote-number footnote-reference info)
1829 "IGNORED" 1)))))
1832 ;;;; Headline
1834 (defun org-html-format-headline--wrap
1835 (headline info &optional format-function &rest extra-keys)
1836 "Transcode a HEADLINE element from Org to HTML.
1837 CONTENTS holds the contents of the headline. INFO is a plist
1838 holding contextual information."
1839 (let* ((level (+ (org-export-get-relative-level headline info)
1840 (1- org-html-toplevel-hlevel)))
1841 (headline-number (org-export-get-headline-number headline info))
1842 (section-number (and (not (org-export-low-level-p headline info))
1843 (org-export-numbered-headline-p headline info)
1844 (mapconcat 'number-to-string
1845 headline-number ".")))
1846 (todo (and (plist-get info :with-todo-keywords)
1847 (let ((todo (org-element-property :todo-keyword headline)))
1848 (and todo (org-export-data todo info)))))
1849 (todo-type (and todo (org-element-property :todo-type headline)))
1850 (priority (and (plist-get info :with-priority)
1851 (org-element-property :priority headline)))
1852 (text (org-export-data (org-element-property :title headline) info))
1853 (tags (and (plist-get info :with-tags)
1854 (org-export-get-tags headline info)))
1855 (headline-label (or (org-element-property :CUSTOM_ID headline)
1856 (concat "sec-" (mapconcat 'number-to-string
1857 headline-number "-"))))
1858 (format-function (cond
1859 ((functionp format-function) format-function)
1860 ((functionp org-html-format-headline-function)
1861 (function*
1862 (lambda (todo todo-type priority text tags
1863 &allow-other-keys)
1864 (funcall org-html-format-headline-function
1865 todo todo-type priority text tags))))
1866 (t 'org-html-format-headline))))
1867 (apply format-function
1868 todo todo-type priority text tags
1869 :headline-label headline-label :level level
1870 :section-number section-number extra-keys)))
1872 (defun org-html-headline (headline contents info)
1873 "Transcode a HEADLINE element from Org to HTML.
1874 CONTENTS holds the contents of the headline. INFO is a plist
1875 holding contextual information."
1876 ;; Empty contents?
1877 (setq contents (or contents ""))
1878 (let* ((numberedp (org-export-numbered-headline-p headline info))
1879 (level (org-export-get-relative-level headline info))
1880 (text (org-export-data (org-element-property :title headline) info))
1881 (todo (and (plist-get info :with-todo-keywords)
1882 (let ((todo (org-element-property :todo-keyword headline)))
1883 (and todo (org-export-data todo info)))))
1884 (todo-type (and todo (org-element-property :todo-type headline)))
1885 (tags (and (plist-get info :with-tags)
1886 (org-export-get-tags headline info)))
1887 (priority (and (plist-get info :with-priority)
1888 (org-element-property :priority headline)))
1889 (section-number (and (org-export-numbered-headline-p headline info)
1890 (mapconcat 'number-to-string
1891 (org-export-get-headline-number
1892 headline info) ".")))
1893 ;; Create the headline text.
1894 (full-text (org-html-format-headline--wrap headline info)))
1895 (cond
1896 ;; Case 1: This is a footnote section: ignore it.
1897 ((org-element-property :footnote-section-p headline) nil)
1898 ;; Case 2. This is a deep sub-tree: export it as a list item.
1899 ;; Also export as items headlines for which no section
1900 ;; format has been found.
1901 ((org-export-low-level-p headline info)
1902 ;; Build the real contents of the sub-tree.
1903 (let* ((type (if numberedp 'ordered 'unordered))
1904 (itemized-body (org-html-format-list-item
1905 contents type nil nil full-text)))
1906 (concat
1907 (and (org-export-first-sibling-p headline info)
1908 (org-html-begin-plain-list type))
1909 itemized-body
1910 (and (org-export-last-sibling-p headline info)
1911 (org-html-end-plain-list type)))))
1912 ;; Case 3. Standard headline. Export it as a section.
1914 (let* ((section-number (mapconcat 'number-to-string
1915 (org-export-get-headline-number
1916 headline info) "-"))
1917 (ids (remove 'nil
1918 (list (org-element-property :CUSTOM_ID headline)
1919 (concat "sec-" section-number)
1920 (org-element-property :ID headline))))
1921 (preferred-id (car ids))
1922 (extra-ids (cdr ids))
1923 (extra-class (org-element-property :HTML_CONTAINER_CLASS headline))
1924 (level1 (+ level (1- org-html-toplevel-hlevel))))
1925 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1926 (format "outline-container-%s"
1927 (or (org-element-property :CUSTOM_ID headline)
1928 section-number))
1929 (concat (format "outline-%d" level1) (and extra-class " ")
1930 extra-class)
1931 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1932 level1
1933 preferred-id
1934 (mapconcat
1935 (lambda (x)
1936 (let ((id (org-export-solidify-link-text
1937 (if (org-uuidgen-p x) (concat "ID-" x)
1938 x))))
1939 (org-html--anchor id)))
1940 extra-ids "")
1941 full-text
1942 level1)
1943 contents))))))
1946 ;;;; Horizontal Rule
1948 (defun org-html-horizontal-rule (horizontal-rule contents info)
1949 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1950 CONTENTS is nil. INFO is a plist holding contextual information."
1951 "<hr/>")
1954 ;;;; Inline Src Block
1956 (defun org-html-inline-src-block (inline-src-block contents info)
1957 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1958 CONTENTS holds the contents of the item. INFO is a plist holding
1959 contextual information."
1960 (let* ((org-lang (org-element-property :language inline-src-block))
1961 (code (org-element-property :value inline-src-block)))
1962 (error "Cannot export inline src block")))
1965 ;;;; Inlinetask
1967 (defun org-html-format-section (text class &optional id)
1968 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1969 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1971 (defun org-html-inlinetask (inlinetask contents info)
1972 "Transcode an INLINETASK element from Org to HTML.
1973 CONTENTS holds the contents of the block. INFO is a plist
1974 holding contextual information."
1975 (cond
1976 ;; If `org-html-format-inlinetask-function' is provided, call it
1977 ;; with appropriate arguments.
1978 ((functionp org-html-format-inlinetask-function)
1979 (let ((format-function
1980 (function*
1981 (lambda (todo todo-type priority text tags
1982 &key contents &allow-other-keys)
1983 (funcall org-html-format-inlinetask-function
1984 todo todo-type priority text tags contents)))))
1985 (org-html-format-headline--wrap
1986 inlinetask info format-function :contents contents)))
1987 ;; Otherwise, use a default template.
1988 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1989 (org-html-format-headline--wrap inlinetask info)
1990 contents))))
1993 ;;;; Italic
1995 (defun org-html-italic (italic contents info)
1996 "Transcode ITALIC from Org to HTML.
1997 CONTENTS is the text with italic markup. INFO is a plist holding
1998 contextual information."
1999 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
2002 ;;;; Item
2004 (defun org-html-checkbox (checkbox)
2005 (case checkbox (on "<code>[X]</code>")
2006 (off "<code>[&nbsp;]</code>")
2007 (trans "<code>[-]</code>")
2008 (t "")))
2010 (defun org-html-format-list-item (contents type checkbox
2011 &optional term-counter-id
2012 headline)
2013 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
2014 (concat
2015 (case type
2016 (ordered
2017 (let* ((counter term-counter-id)
2018 (extra (if counter (format " value=\"%s\"" counter) "")))
2019 (concat
2020 (format "<li%s>" extra)
2021 (when headline (concat headline "<br/>")))))
2022 (unordered
2023 (let* ((id term-counter-id)
2024 (extra (if id (format " id=\"%s\"" id) "")))
2025 (concat
2026 (format "<li%s>" extra)
2027 (when headline (concat headline "<br/>")))))
2028 (descriptive
2029 (let* ((term term-counter-id))
2030 (setq term (or term "(no term)"))
2031 ;; Check-boxes in descriptive lists are associated to tag.
2032 (concat (format "<dt> %s </dt>"
2033 (concat checkbox term))
2034 "<dd>"))))
2035 (unless (eq type 'descriptive) checkbox)
2036 contents
2037 (case type
2038 (ordered "</li>")
2039 (unordered "</li>")
2040 (descriptive "</dd>")))))
2042 (defun org-html-item (item contents info)
2043 "Transcode an ITEM element from Org to HTML.
2044 CONTENTS holds the contents of the item. INFO is a plist holding
2045 contextual information."
2046 (let* ((plain-list (org-export-get-parent item))
2047 (type (org-element-property :type plain-list))
2048 (counter (org-element-property :counter item))
2049 (checkbox (org-element-property :checkbox item))
2050 (tag (let ((tag (org-element-property :tag item)))
2051 (and tag (org-export-data tag info)))))
2052 (org-html-format-list-item
2053 contents type checkbox (or tag counter))))
2056 ;;;; Keyword
2058 (defun org-html-keyword (keyword contents info)
2059 "Transcode a KEYWORD element from Org to HTML.
2060 CONTENTS is nil. INFO is a plist holding contextual information."
2061 (let ((key (org-element-property :key keyword))
2062 (value (org-element-property :value keyword)))
2063 (cond
2064 ((string= key "HTML") value)
2065 ;; Invisible targets.
2066 ((string= key "TARGET") nil)
2067 ((string= key "TOC")
2068 (let ((value (downcase value)))
2069 (cond
2070 ((string-match "\\<headlines\\>" value)
2071 (let ((depth (or (and (string-match "[0-9]+" value)
2072 (string-to-number (match-string 0 value)))
2073 (plist-get info :with-toc))))
2074 (org-html-toc depth info)))
2075 ((string= "listings" value) (org-html-list-of-listings info))
2076 ((string= "tables" value) (org-html-list-of-tables info))))))))
2079 ;;;; Latex Environment
2081 (defun org-html-format-latex (latex-frag processing-type)
2082 "Format LaTeX fragments into HTML."
2083 (let ((cache-relpath "") (cache-dir "") bfn)
2084 (unless (eq processing-type 'mathjax)
2085 (setq bfn (buffer-file-name)
2086 cache-relpath
2087 (concat "ltxpng/"
2088 (file-name-sans-extension
2089 (file-name-nondirectory bfn)))
2090 cache-dir (file-name-directory bfn)))
2091 (with-temp-buffer
2092 (insert latex-frag)
2093 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2094 nil nil processing-type)
2095 (buffer-string))))
2097 (defun org-html-latex-environment (latex-environment contents info)
2098 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2099 CONTENTS is nil. INFO is a plist holding contextual information."
2100 (let ((processing-type (plist-get info :with-latex))
2101 (latex-frag (org-remove-indentation
2102 (org-element-property :value latex-environment)))
2103 (caption (org-export-data
2104 (org-export-get-caption latex-environment) info))
2105 (attr nil) ; FIXME
2106 (label (org-element-property :name latex-environment)))
2107 (cond
2108 ((memq processing-type '(t mathjax))
2109 (org-html-format-latex latex-frag 'mathjax))
2110 ((eq processing-type 'dvipng)
2111 (let* ((formula-link (org-html-format-latex
2112 latex-frag processing-type)))
2113 (when (and formula-link
2114 (string-match "file:\\([^]]*\\)" formula-link))
2115 (org-html-format-inline-image
2116 (match-string 1 formula-link) caption label attr t))))
2117 (t latex-frag))))
2120 ;;;; Latex Fragment
2122 (defun org-html-latex-fragment (latex-fragment contents info)
2123 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2124 CONTENTS is nil. INFO is a plist holding contextual information."
2125 (let ((latex-frag (org-element-property :value latex-fragment))
2126 (processing-type (plist-get info :with-latex)))
2127 (case processing-type
2128 ((t mathjax)
2129 (org-html-format-latex latex-frag 'mathjax))
2130 (dvipng
2131 (let* ((formula-link (org-html-format-latex
2132 latex-frag processing-type)))
2133 (when (and formula-link
2134 (string-match "file:\\([^]]*\\)" formula-link))
2135 (org-html-format-inline-image
2136 (match-string 1 formula-link)))))
2137 (t latex-frag))))
2140 ;;;; Line Break
2142 (defun org-html-line-break (line-break contents info)
2143 "Transcode a LINE-BREAK object from Org to HTML.
2144 CONTENTS is nil. INFO is a plist holding contextual information."
2145 "<br/>\n")
2148 ;;;; Link
2150 (defun org-html-link--inline-image (link desc info)
2151 "Return HTML code for an inline image.
2152 LINK is the link pointing to the inline image. INFO is a plist
2153 used as a communication channel."
2154 (let* ((type (org-element-property :type link))
2155 (raw-path (org-element-property :path link))
2156 (path (cond ((member type '("http" "https"))
2157 (concat type ":" raw-path))
2158 ((file-name-absolute-p raw-path)
2159 (expand-file-name raw-path))
2160 (t raw-path)))
2161 (parent (org-export-get-parent-element link))
2162 (caption (org-export-data (org-export-get-caption parent) info))
2163 (label (org-element-property :name parent))
2164 ;; Retrieve latex attributes from the PARENT element. HACK:
2165 ;; Only do this for the first link in PARENT. This is needed
2166 ;; as long as attributes cannot be set on a per link basis.
2167 (attr (when (eq link (org-element-map parent 'link 'identity info t))
2168 (let ((raw-attr
2169 (mapconcat #'identity
2170 (org-element-property :attr_html parent)
2171 " ")))
2172 (unless (string= raw-attr "") raw-attr)))))
2173 ;; Now clear ATTR from any special keyword and set a default
2174 ;; value if nothing is left.
2175 (setq attr (if (not attr) "" (org-trim attr)))
2176 ;; Return proper string, depending on DISPOSITION.
2177 (org-html-format-inline-image
2178 path caption label attr (org-html-standalone-image-p link info))))
2180 (defvar org-html-standalone-image-predicate)
2181 (defun org-html-standalone-image-p (element info &optional predicate)
2182 "Test if ELEMENT is a standalone image for the purpose HTML export.
2183 INFO is a plist holding contextual information.
2185 Return non-nil, if ELEMENT is of type paragraph and it's sole
2186 content, save for whitespaces, is a link that qualifies as an
2187 inline image.
2189 Return non-nil, if ELEMENT is of type link and it's containing
2190 paragraph has no other content save for leading and trailing
2191 whitespaces.
2193 Return nil, otherwise.
2195 Bind `org-html-standalone-image-predicate' to constrain
2196 paragraph further. For example, to check for only captioned
2197 standalone images, do the following.
2199 \(setq org-html-standalone-image-predicate
2200 \(lambda \(paragraph\)
2201 \(org-element-property :caption paragraph\)\)\)"
2202 (let ((paragraph (case (org-element-type element)
2203 (paragraph element)
2204 (link (and (org-export-inline-image-p
2205 element org-html-inline-image-rules)
2206 (org-export-get-parent element)))
2207 (t nil))))
2208 (when (eq (org-element-type paragraph) 'paragraph)
2209 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2210 (functionp org-html-standalone-image-predicate)))
2211 (funcall org-html-standalone-image-predicate paragraph))
2212 (let ((contents (org-element-contents paragraph)))
2213 (loop for x in contents
2214 with inline-image-count = 0
2215 always (cond
2216 ((eq (org-element-type x) 'plain-text)
2217 (not (org-string-nw-p x)))
2218 ((eq (org-element-type x) 'link)
2219 (when (org-export-inline-image-p
2220 x org-html-inline-image-rules)
2221 (= (incf inline-image-count) 1)))
2222 (t nil))))))))
2224 (defun org-html-link (link desc info)
2225 "Transcode a LINK object from Org to HTML.
2227 DESC is the description part of the link, or the empty string.
2228 INFO is a plist holding contextual information. See
2229 `org-export-data'."
2230 (let* ((--link-org-files-as-html-maybe
2231 (function
2232 (lambda (raw-path info)
2233 "Treat links to `file.org' as links to `file.html', if needed.
2234 See `org-html-link-org-files-as-html'."
2235 (cond
2236 ((and org-html-link-org-files-as-html
2237 (string= ".org"
2238 (downcase (file-name-extension raw-path "."))))
2239 (concat (file-name-sans-extension raw-path) "."
2240 (plist-get info :html-extension)))
2241 (t raw-path)))))
2242 (type (org-element-property :type link))
2243 (raw-path (org-element-property :path link))
2244 ;; Ensure DESC really exists, or set it to nil.
2245 (desc (and (not (string= desc "")) desc))
2246 (path
2247 (cond
2248 ((member type '("http" "https" "ftp" "mailto"))
2249 (concat type ":" raw-path))
2250 ((string= type "file")
2251 ;; Treat links to ".org" files as ".html", if needed.
2252 (setq raw-path
2253 (funcall --link-org-files-as-html-maybe raw-path info))
2254 ;; If file path is absolute, prepend it with protocol
2255 ;; component - "file://".
2256 (when (file-name-absolute-p raw-path)
2257 (setq raw-path
2258 (concat "file://" (expand-file-name raw-path))))
2259 ;; Add search option, if any. A search option can be
2260 ;; relative to a custom-id or a headline title. Any other
2261 ;; option is ignored.
2262 (let ((option (org-element-property :search-option link)))
2263 (cond ((not option) raw-path)
2264 ((eq (aref option 0) ?#) (concat raw-path option))
2265 ;; External fuzzy link: try to resolve it if path
2266 ;; belongs to current project, if any.
2267 ((eq (aref option 0) ?*)
2268 (concat
2269 raw-path
2270 (let ((numbers
2271 (org-publish-resolve-external-fuzzy-link
2272 (org-element-property :path link) option)))
2273 (and numbers (concat "#sec-"
2274 (mapconcat 'number-to-string
2275 numbers "-")))))))))
2276 (t raw-path)))
2277 attributes protocol)
2278 ;; Extract attributes from parent's paragraph. HACK: Only do this
2279 ;; for the first link in parent. This is needed as long as
2280 ;; attributes cannot be set on a per link basis.
2281 (and (setq attributes
2282 (let ((parent (org-export-get-parent-element link)))
2283 (if (not (eq (org-element-map parent 'link 'identity info t)
2284 link))
2286 (mapconcat
2287 'identity
2288 (let ((att (org-element-property :attr_html parent)))
2289 (unless (and desc att
2290 (string-match (regexp-quote (car att)) desc))
2291 att))
2292 " "))))
2293 (setq attributes (concat " " attributes)))
2294 (cond
2295 ;; Image file.
2296 ((and (or (eq t org-html-inline-images)
2297 (and org-html-inline-images (not desc)))
2298 (org-export-inline-image-p link org-html-inline-image-rules))
2299 (org-html-link--inline-image link desc info))
2300 ;; Radio target: Transcode target's contents and use them as
2301 ;; link's description.
2302 ((string= type "radio")
2303 (let ((destination (org-export-resolve-radio-link link info)))
2304 (when destination
2305 (format "<a href=\"#%s\"%s>%s</a>"
2306 (org-export-solidify-link-text path)
2307 attributes
2308 (org-export-data (org-element-contents destination) info)))))
2309 ;; Links pointing to a headline: Find destination and build
2310 ;; appropriate referencing command.
2311 ((member type '("custom-id" "fuzzy" "id"))
2312 (let ((destination (if (string= type "fuzzy")
2313 (org-export-resolve-fuzzy-link link info)
2314 (org-export-resolve-id-link link info))))
2315 (case (org-element-type destination)
2316 ;; ID link points to an external file.
2317 (plain-text
2318 (let ((fragment (concat "ID-" path))
2319 ;; Treat links to ".org" files as ".html", if needed.
2320 (path (funcall --link-org-files-as-html-maybe
2321 destination info)))
2322 (format "<a href=\"%s#%s\"%s>%s</a>"
2323 path fragment attributes (or desc destination))))
2324 ;; Fuzzy link points nowhere.
2325 ((nil)
2326 (format "<i>%s</i>"
2327 (or desc
2328 (org-export-data
2329 (org-element-property :raw-link link) info))))
2330 ;; Fuzzy link points to an invisible target.
2331 (keyword nil)
2332 ;; Link points to a headline.
2333 (headline
2334 (let ((href
2335 ;; What href to use?
2336 (cond
2337 ;; Case 1: Headline is linked via it's CUSTOM_ID
2338 ;; property. Use CUSTOM_ID.
2339 ((string= type "custom-id")
2340 (org-element-property :CUSTOM_ID destination))
2341 ;; Case 2: Headline is linked via it's ID property
2342 ;; or through other means. Use the default href.
2343 ((member type '("id" "fuzzy"))
2344 (format "sec-%s"
2345 (mapconcat 'number-to-string
2346 (org-export-get-headline-number
2347 destination info) "-")))
2348 (t (error "Shouldn't reach here"))))
2349 ;; What description to use?
2350 (desc
2351 ;; Case 1: Headline is numbered and LINK has no
2352 ;; description or LINK's description matches
2353 ;; headline's title. Display section number.
2354 (if (and (org-export-numbered-headline-p destination info)
2355 (or (not desc)
2356 (string= desc (org-element-property
2357 :raw-value destination))))
2358 (mapconcat 'number-to-string
2359 (org-export-get-headline-number
2360 destination info) ".")
2361 ;; Case 2: Either the headline is un-numbered or
2362 ;; LINK has a custom description. Display LINK's
2363 ;; description or headline's title.
2364 (or desc (org-export-data (org-element-property
2365 :title destination) info)))))
2366 (format "<a href=\"#%s\"%s>%s</a>"
2367 (org-export-solidify-link-text href) attributes desc)))
2368 ;; Fuzzy link points to a target. Do as above.
2370 (let ((path (org-export-solidify-link-text path)) number)
2371 (unless desc
2372 (setq number (cond
2373 ((org-html-standalone-image-p destination info)
2374 (org-export-get-ordinal
2375 (assoc 'link (org-element-contents destination))
2376 info 'link 'org-html-standalone-image-p))
2377 (t (org-export-get-ordinal destination info))))
2378 (setq desc (when number
2379 (if (atom number) (number-to-string number)
2380 (mapconcat 'number-to-string number ".")))))
2381 (format "<a href=\"#%s\"%s>%s</a>"
2382 path attributes (or desc "No description for this link")))))))
2383 ;; Coderef: replace link with the reference name or the
2384 ;; equivalent line number.
2385 ((string= type "coderef")
2386 (let ((fragment (concat "coderef-" path)))
2387 (format "<a href=\"#%s\" %s%s>%s</a>"
2388 fragment
2389 (format (concat "class=\"coderef\""
2390 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2391 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2392 fragment fragment)
2393 attributes
2394 (format (org-export-get-coderef-format path desc)
2395 (org-export-resolve-coderef path info)))))
2396 ;; Link type is handled by a special function.
2397 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2398 (funcall protocol (org-link-unescape path) desc 'html))
2399 ;; External link with a description part.
2400 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2401 ;; External link without a description part.
2402 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2403 ;; No path, only description. Try to do something useful.
2404 (t (format "<i>%s</i>" desc)))))
2407 ;;;; Paragraph
2409 (defun org-html-paragraph (paragraph contents info)
2410 "Transcode a PARAGRAPH element from Org to HTML.
2411 CONTENTS is the contents of the paragraph, as a string. INFO is
2412 the plist used as a communication channel."
2413 (let* ((style nil) ; FIXME
2414 (class (cdr (assoc style '((footnote . "footnote")
2415 (verse . nil)))))
2416 (extra (if class (format " class=\"%s\"" class) ""))
2417 (parent (org-export-get-parent paragraph)))
2418 (cond
2419 ((and (eq (org-element-type parent) 'item)
2420 (= (org-element-property :begin paragraph)
2421 (org-element-property :contents-begin parent)))
2422 ;; leading paragraph in a list item have no tags
2423 contents)
2424 ((org-html-standalone-image-p paragraph info)
2425 ;; standalone image
2426 contents)
2427 (t (format "<p%s>\n%s</p>" extra contents)))))
2430 ;;;; Plain List
2432 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2433 ;; the correct value for the item counter
2434 (defun org-html-begin-plain-list (type &optional arg1)
2435 "Insert the beginning of the HTML list depending on TYPE.
2436 When ARG1 is a string, use it as the start parameter for ordered
2437 lists."
2438 (case type
2439 (ordered
2440 (format "<ol class=\"org-ol\"%s>"
2441 (if arg1 (format " start=\"%d\"" arg1) "")))
2442 (unordered "<ul class=\"org-ul\">")
2443 (descriptive "<dl class=\"org-dl\">")))
2445 (defun org-html-end-plain-list (type)
2446 "Insert the end of the HTML list depending on TYPE."
2447 (case type
2448 (ordered "</ol>")
2449 (unordered "</ul>")
2450 (descriptive "</dl>")))
2452 (defun org-html-plain-list (plain-list contents info)
2453 "Transcode a PLAIN-LIST element from Org to HTML.
2454 CONTENTS is the contents of the list. INFO is a plist holding
2455 contextual information."
2456 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2457 (type (org-element-property :type plain-list)))
2458 (format "%s\n%s%s"
2459 (org-html-begin-plain-list type)
2460 contents (org-html-end-plain-list type))))
2462 ;;;; Plain Text
2464 (defun org-html-convert-special-strings (string)
2465 "Convert special characters in STRING to HTML."
2466 (let ((all org-html-special-string-regexps)
2467 e a re rpl start)
2468 (while (setq a (pop all))
2469 (setq re (car a) rpl (cdr a) start 0)
2470 (while (string-match re string start)
2471 (setq string (replace-match rpl t nil string))))
2472 string))
2474 (defun org-html-encode-plain-text (text)
2475 "Convert plain text characters to HTML equivalent.
2476 Possible conversions are set in `org-export-html-protect-char-alist'."
2477 (mapc
2478 (lambda (pair)
2479 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2480 org-html-protect-char-alist)
2481 text)
2483 (defun org-html-plain-text (text info)
2484 "Transcode a TEXT string from Org to HTML.
2485 TEXT is the string to transcode. INFO is a plist holding
2486 contextual information."
2487 (let ((output text))
2488 ;; Protect following characters: <, >, &.
2489 (setq output (org-html-encode-plain-text output))
2490 ;; Handle smart quotes. Be sure to provide original string since
2491 ;; OUTPUT may have been modified.
2492 (when (plist-get info :with-smart-quotes)
2493 (setq output (org-export-activate-smart-quotes output :html info text)))
2494 ;; Handle special strings.
2495 (when (plist-get info :with-special-strings)
2496 (setq output (org-html-convert-special-strings output)))
2497 ;; Handle break preservation if required.
2498 (when (plist-get info :preserve-breaks)
2499 (setq output
2500 (replace-regexp-in-string
2501 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2502 ;; Return value.
2503 output))
2506 ;; Planning
2508 (defun org-html-planning (planning contents info)
2509 "Transcode a PLANNING element from Org to HTML.
2510 CONTENTS is nil. INFO is a plist used as a communication
2511 channel."
2512 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2513 (format
2514 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2515 (mapconcat
2516 'identity
2517 (delq nil
2518 (list
2519 (let ((closed (org-element-property :closed planning)))
2520 (when closed
2521 (format span-fmt org-closed-string
2522 (org-translate-time
2523 (org-element-property :raw-value closed)))))
2524 (let ((deadline (org-element-property :deadline planning)))
2525 (when deadline
2526 (format span-fmt org-deadline-string
2527 (org-translate-time
2528 (org-element-property :raw-value deadline)))))
2529 (let ((scheduled (org-element-property :scheduled planning)))
2530 (when scheduled
2531 (format span-fmt org-scheduled-string
2532 (org-translate-time
2533 (org-element-property :raw-value scheduled)))))))
2534 " "))))
2537 ;;;; Property Drawer
2539 (defun org-html-property-drawer (property-drawer contents info)
2540 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2541 CONTENTS is nil. INFO is a plist holding contextual
2542 information."
2543 ;; The property drawer isn't exported but we want separating blank
2544 ;; lines nonetheless.
2548 ;;;; Quote Block
2550 (defun org-html-quote-block (quote-block contents info)
2551 "Transcode a QUOTE-BLOCK element from Org to HTML.
2552 CONTENTS holds the contents of the block. INFO is a plist
2553 holding contextual information."
2554 (format "<blockquote>\n%s</blockquote>" contents))
2557 ;;;; Quote Section
2559 (defun org-html-quote-section (quote-section contents info)
2560 "Transcode a QUOTE-SECTION element from Org to HTML.
2561 CONTENTS is nil. INFO is a plist holding contextual information."
2562 (let ((value (org-remove-indentation
2563 (org-element-property :value quote-section))))
2564 (when value (format "<pre>\n%s</pre>" value))))
2567 ;;;; Section
2569 (defun org-html-section (section contents info)
2570 "Transcode a SECTION element from Org to HTML.
2571 CONTENTS holds the contents of the section. INFO is a plist
2572 holding contextual information."
2573 (let ((parent (org-export-get-parent-headline section)))
2574 ;; Before first headline: no container, just return CONTENTS.
2575 (if (not parent) contents
2576 ;; Get div's class and id references.
2577 (let* ((class-num (+ (org-export-get-relative-level parent info)
2578 (1- org-html-toplevel-hlevel)))
2579 (section-number
2580 (mapconcat
2581 'number-to-string
2582 (org-export-get-headline-number parent info) "-")))
2583 ;; Build return value.
2584 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2585 class-num
2586 (or (org-element-property :CUSTOM_ID parent) section-number)
2587 contents)))))
2589 ;;;; Radio Target
2591 (defun org-html-radio-target (radio-target text info)
2592 "Transcode a RADIO-TARGET object from Org to HTML.
2593 TEXT is the text of the target. INFO is a plist holding
2594 contextual information."
2595 (let ((id (org-export-solidify-link-text
2596 (org-element-property :value radio-target))))
2597 (org-html--anchor id text)))
2600 ;;;; Special Block
2602 (defun org-html-special-block (special-block contents info)
2603 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2604 CONTENTS holds the contents of the block. INFO is a plist
2605 holding contextual information."
2606 (format "<div class=\"%s\">\n%s\n</div>"
2607 (downcase (org-element-property :type special-block))
2608 contents))
2611 ;;;; Src Block
2613 (defun org-html-src-block (src-block contents info)
2614 "Transcode a SRC-BLOCK element from Org to HTML.
2615 CONTENTS holds the contents of the item. INFO is a plist holding
2616 contextual information."
2617 (if (org-export-read-attribute :attr_html src-block :textarea)
2618 (org-html--textarea-block src-block)
2619 (let ((lang (org-element-property :language src-block))
2620 (caption (org-export-get-caption src-block))
2621 (code (org-html-format-code src-block info))
2622 (label (let ((lbl (org-element-property :name src-block)))
2623 (if (not lbl) ""
2624 (format " id=\"%s\""
2625 (org-export-solidify-link-text lbl))))))
2626 (if (not lang) (format "<pre class=\"example\"%s>\n%s</pre>" label code)
2627 (format
2628 "<div class=\"org-src-container\">\n%s%s\n</div>"
2629 (if (not caption) ""
2630 (format "<label class=\"org-src-name\">%s</label>"
2631 (org-export-data caption info)))
2632 (format "\n<pre class=\"src src-%s\"%s>%s</pre>" lang label code))))))
2635 ;;;; Statistics Cookie
2637 (defun org-html-statistics-cookie (statistics-cookie contents info)
2638 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2639 CONTENTS is nil. INFO is a plist holding contextual information."
2640 (let ((cookie-value (org-element-property :value statistics-cookie)))
2641 (format "<code>%s</code>" cookie-value)))
2644 ;;;; Strike-Through
2646 (defun org-html-strike-through (strike-through contents info)
2647 "Transcode STRIKE-THROUGH from Org to HTML.
2648 CONTENTS is the text with strike-through markup. INFO is a plist
2649 holding contextual information."
2650 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2651 contents))
2654 ;;;; Subscript
2656 (defun org-html-subscript (subscript contents info)
2657 "Transcode a SUBSCRIPT object from Org to HTML.
2658 CONTENTS is the contents of the object. INFO is a plist holding
2659 contextual information."
2660 (format "<sub>%s</sub>" contents))
2663 ;;;; Superscript
2665 (defun org-html-superscript (superscript contents info)
2666 "Transcode a SUPERSCRIPT object from Org to HTML.
2667 CONTENTS is the contents of the object. INFO is a plist holding
2668 contextual information."
2669 (format "<sup>%s</sup>" contents))
2672 ;;;; Tabel Cell
2674 (defun org-html-table-cell (table-cell contents info)
2675 "Transcode a TABLE-CELL element from Org to HTML.
2676 CONTENTS is nil. INFO is a plist used as a communication
2677 channel."
2678 (let* ((table-row (org-export-get-parent table-cell))
2679 (table (org-export-get-parent-table table-cell))
2680 (cell-attrs
2681 (if (not org-html-table-align-individual-fields) ""
2682 (format (if (and (boundp 'org-html-format-table-no-css)
2683 org-html-format-table-no-css)
2684 " align=\"%s\"" " class=\"%s\"")
2685 (org-export-table-cell-alignment table-cell info)))))
2686 (when (or (not contents) (string= "" (org-trim contents)))
2687 (setq contents "&nbsp;"))
2688 (cond
2689 ((and (org-export-table-has-header-p table info)
2690 (= 1 (org-export-table-row-group table-row info)))
2691 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2692 contents (cdr org-html-table-header-tags)))
2693 ((and org-html-table-use-header-tags-for-first-column
2694 (zerop (cdr (org-export-table-cell-address table-cell info))))
2695 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2696 contents (cdr org-html-table-header-tags)))
2697 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2698 contents (cdr org-html-table-data-tags))))))
2701 ;;;; Table Row
2703 (defun org-html-table-row (table-row contents info)
2704 "Transcode a TABLE-ROW element from Org to HTML.
2705 CONTENTS is the contents of the row. INFO is a plist used as a
2706 communication channel."
2707 ;; Rules are ignored since table separators are deduced from
2708 ;; borders of the current row.
2709 (when (eq (org-element-property :type table-row) 'standard)
2710 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2711 (rowgroup-tags
2712 (cond
2713 ;; Case 1: Row belongs to second or subsequent rowgroups.
2714 ((not (= 1 (org-export-table-row-group table-row info)))
2715 '("<tbody>" . "\n</tbody>"))
2716 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2717 ((org-export-table-has-header-p
2718 (org-export-get-parent-table table-row) info)
2719 '("<thead>" . "\n</thead>"))
2720 ;; Case 2: Row is from first and only row group.
2721 (t '("<tbody>" . "\n</tbody>")))))
2722 (concat
2723 ;; Begin a rowgroup?
2724 (when (org-export-table-row-starts-rowgroup-p table-row info)
2725 (car rowgroup-tags))
2726 ;; Actual table row
2727 (concat "\n" (eval (car org-html-table-row-tags))
2728 contents
2729 "\n"
2730 (eval (cdr org-html-table-row-tags)))
2731 ;; End a rowgroup?
2732 (when (org-export-table-row-ends-rowgroup-p table-row info)
2733 (cdr rowgroup-tags))))))
2736 ;;;; Table
2738 (defun org-html-table-first-row-data-cells (table info)
2739 (let ((table-row
2740 (org-element-map table 'table-row
2741 (lambda (row)
2742 (unless (eq (org-element-property :type row) 'rule) row))
2743 info 'first-match))
2744 (special-column-p (org-export-table-has-special-column-p table)))
2745 (if (not special-column-p) (org-element-contents table-row)
2746 (cdr (org-element-contents table-row)))))
2748 (defun org-html-table--table.el-table (table info)
2749 (when (eq (org-element-property :type table) 'table.el)
2750 (require 'table)
2751 (let ((outbuf (with-current-buffer
2752 (get-buffer-create "*org-export-table*")
2753 (erase-buffer) (current-buffer))))
2754 (with-temp-buffer
2755 (insert (org-element-property :value table))
2756 (goto-char 1)
2757 (re-search-forward "^[ \t]*|[^|]" nil t)
2758 (table-generate-source 'html outbuf))
2759 (with-current-buffer outbuf
2760 (prog1 (org-trim (buffer-string))
2761 (kill-buffer) )))))
2763 (defun org-html-table (table contents info)
2764 "Transcode a TABLE element from Org to HTML.
2765 CONTENTS is the contents of the table. INFO is a plist holding
2766 contextual information."
2767 (case (org-element-property :type table)
2768 ;; Case 1: table.el table. Convert it using appropriate tools.
2769 (table.el (org-html-table--table.el-table table info))
2770 ;; Case 2: Standard table.
2772 (let* ((label (org-element-property :name table))
2773 (caption (org-export-get-caption table))
2774 (attributes (mapconcat #'identity
2775 (org-element-property :attr_html table)
2776 " "))
2777 (alignspec
2778 (if (and (boundp 'org-html-format-table-no-css)
2779 org-html-format-table-no-css)
2780 "align=\"%s\"" "class=\"%s\""))
2781 (table-column-specs
2782 (function
2783 (lambda (table info)
2784 (mapconcat
2785 (lambda (table-cell)
2786 (let ((alignment (org-export-table-cell-alignment
2787 table-cell info)))
2788 (concat
2789 ;; Begin a colgroup?
2790 (when (org-export-table-cell-starts-colgroup-p
2791 table-cell info)
2792 "\n<colgroup>")
2793 ;; Add a column. Also specify it's alignment.
2794 (format "\n<col %s/>" (format alignspec alignment))
2795 ;; End a colgroup?
2796 (when (org-export-table-cell-ends-colgroup-p
2797 table-cell info)
2798 "\n</colgroup>"))))
2799 (org-html-table-first-row-data-cells table info) "\n"))))
2800 (table-attributes
2801 (let ((table-tag (plist-get info :html-table-tag)))
2802 (concat
2803 (and (string-match "<table\\(.*\\)>" table-tag)
2804 (match-string 1 table-tag))
2805 (and label (format " id=\"%s\""
2806 (org-export-solidify-link-text label)))
2807 (unless (string= attributes "")
2808 (concat " " attributes))))))
2809 ;; Remove last blank line.
2810 (setq contents (substring contents 0 -1))
2811 (format "<table%s>\n%s\n%s\n%s\n</table>"
2812 table-attributes
2813 (if (not caption) ""
2814 (format "<caption>%s</caption>"
2815 (org-export-data caption info)))
2816 (funcall table-column-specs table info)
2817 contents)))))
2820 ;;;; Target
2822 (defun org-html-target (target contents info)
2823 "Transcode a TARGET object from Org to HTML.
2824 CONTENTS is nil. INFO is a plist holding contextual
2825 information."
2826 (let ((id (org-export-solidify-link-text
2827 (org-element-property :value target))))
2828 (org-html--anchor id)))
2831 ;;;; Timestamp
2833 (defun org-html-timestamp (timestamp contents info)
2834 "Transcode a TIMESTAMP object from Org to HTML.
2835 CONTENTS is nil. INFO is a plist holding contextual
2836 information."
2837 (let ((value (org-html-plain-text
2838 (org-timestamp-translate timestamp) info)))
2839 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2840 (replace-regexp-in-string "--" "&ndash;" value))))
2843 ;;;; Underline
2845 (defun org-html-underline (underline contents info)
2846 "Transcode UNDERLINE from Org to HTML.
2847 CONTENTS is the text with underline markup. INFO is a plist
2848 holding contextual information."
2849 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2850 contents))
2853 ;;;; Verbatim
2855 (defun org-html-verbatim (verbatim contents info)
2856 "Transcode VERBATIM from Org to HTML.
2857 CONTENTS is nil. INFO is a plist holding contextual
2858 information."
2859 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2860 (org-element-property :value verbatim)))
2863 ;;;; Verse Block
2865 (defun org-html-verse-block (verse-block contents info)
2866 "Transcode a VERSE-BLOCK element from Org to HTML.
2867 CONTENTS is verse block contents. INFO is a plist holding
2868 contextual information."
2869 ;; Replace each newline character with line break. Also replace
2870 ;; each blank line with a line break.
2871 (setq contents (replace-regexp-in-string
2872 "^ *\\\\\\\\$" "<br/>\n"
2873 (replace-regexp-in-string
2874 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2875 ;; Replace each white space at beginning of a line with a
2876 ;; non-breaking space.
2877 (while (string-match "^[ \t]+" contents)
2878 (let* ((num-ws (length (match-string 0 contents)))
2879 (ws (let (out) (dotimes (i num-ws out)
2880 (setq out (concat out "&nbsp;"))))))
2881 (setq contents (replace-match ws nil t contents))))
2882 (format "<p class=\"verse\">\n%s</p>" contents))
2886 ;;; Filter Functions
2888 (defun org-html-final-function (contents backend info)
2889 (if (not org-html-pretty-output) contents
2890 (with-temp-buffer
2891 (html-mode)
2892 (insert contents)
2893 (indent-region (point-min) (point-max))
2894 (buffer-substring-no-properties (point-min) (point-max)))))
2898 ;;; End-user functions
2900 ;;;###autoload
2901 (defun org-html-export-as-html
2902 (&optional async subtreep visible-only body-only ext-plist)
2903 "Export current buffer to an HTML buffer.
2905 If narrowing is active in the current buffer, only export its
2906 narrowed part.
2908 If a region is active, export that region.
2910 A non-nil optional argument ASYNC means the process should happen
2911 asynchronously. The resulting buffer should be accessible
2912 through the `org-export-stack' interface.
2914 When optional argument SUBTREEP is non-nil, export the sub-tree
2915 at point, extracting information from the headline properties
2916 first.
2918 When optional argument VISIBLE-ONLY is non-nil, don't export
2919 contents of hidden elements.
2921 When optional argument BODY-ONLY is non-nil, only write code
2922 between \"<body>\" and \"</body>\" tags.
2924 EXT-PLIST, when provided, is a property list with external
2925 parameters overriding Org default settings, but still inferior to
2926 file-local settings.
2928 Export is done in a buffer named \"*Org HTML Export*\", which
2929 will be displayed when `org-export-show-temporary-export-buffer'
2930 is non-nil."
2931 (interactive)
2932 (if async
2933 (org-export-async-start
2934 (lambda (output)
2935 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2936 (erase-buffer)
2937 (insert output)
2938 (goto-char (point-min))
2939 (funcall org-html-display-buffer-mode)
2940 (org-export-add-to-stack (current-buffer) 'html)))
2941 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2942 (let ((outbuf (org-export-to-buffer
2943 'html "*Org HTML Export*"
2944 subtreep visible-only body-only ext-plist)))
2945 ;; Set major mode.
2946 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2947 (when org-export-show-temporary-export-buffer
2948 (switch-to-buffer-other-window outbuf)))))
2950 ;;;###autoload
2951 (defun org-html-export-to-html
2952 (&optional async subtreep visible-only body-only ext-plist)
2953 "Export current buffer to a HTML file.
2955 If narrowing is active in the current buffer, only export its
2956 narrowed part.
2958 If a region is active, export that region.
2960 A non-nil optional argument ASYNC means the process should happen
2961 asynchronously. The resulting file should be accessible through
2962 the `org-export-stack' interface.
2964 When optional argument SUBTREEP is non-nil, export the sub-tree
2965 at point, extracting information from the headline properties
2966 first.
2968 When optional argument VISIBLE-ONLY is non-nil, don't export
2969 contents of hidden elements.
2971 When optional argument BODY-ONLY is non-nil, only write code
2972 between \"<body>\" and \"</body>\" tags.
2974 EXT-PLIST, when provided, is a property list with external
2975 parameters overriding Org default settings, but still inferior to
2976 file-local settings.
2978 Return output file's name."
2979 (interactive)
2980 (let* ((extension (concat "." org-html-extension))
2981 (file (org-export-output-file-name extension subtreep))
2982 (org-export-coding-system org-html-coding-system))
2983 (if async
2984 (org-export-async-start
2985 (lambda (f) (org-export-add-to-stack f 'html))
2986 (let ((org-export-coding-system org-html-coding-system))
2987 `(expand-file-name
2988 (org-export-to-file
2989 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2990 (let ((org-export-coding-system org-html-coding-system))
2991 (org-export-to-file
2992 'html file subtreep visible-only body-only ext-plist)))))
2994 ;;;###autoload
2995 (defun org-html-publish-to-html (plist filename pub-dir)
2996 "Publish an org file to HTML.
2998 FILENAME is the filename of the Org file to be published. PLIST
2999 is the property list for the given project. PUB-DIR is the
3000 publishing directory.
3002 Return output file name."
3003 (org-publish-org-to 'html filename ".html" plist pub-dir))
3007 ;;; FIXME
3009 ;;;; org-format-table-html
3010 ;;;; org-format-org-table-html
3011 ;;;; org-format-table-table-html
3012 ;;;; org-table-number-fraction
3013 ;;;; org-table-number-regexp
3014 ;;;; org-html-table-caption-above
3015 ;;;; org-html-with-timestamp
3016 ;;;; org-html-html-helper-timestamp
3017 ;;;; org-html-inline-image-extensions
3018 ;;;; org-export-preferred-target-alist
3019 ;;;; class for anchors
3020 ;;;; org-export-with-section-numbers, body-only
3021 ;;;; org-export-mark-todo-in-toc
3022 ;;;; org-html-format-org-link
3023 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3024 ;;;; alt = (file-name-nondirectory path)
3026 (provide 'ox-html)
3028 ;; Local variables:
3029 ;; generated-autoload-file: "org-loaddefs.el"
3030 ;; End:
3032 ;;; ox-html.el ends here