Merge branch 'maint'
[org-mode.git] / lisp / ox-html.el
blob1800f5e315f1f9705c1ee0cff6b0717f990eec04
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 ;; This program 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 ;; This program 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 this program. 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 ;; Redefine regular options.
126 (:creator "CREATOR" nil org-html-creator-string)
127 (:with-latex nil "tex" org-html-with-latex)
128 ;; Leave room for "ox-infojs.el" extension.
129 (:infojs-opt "INFOJS_OPT" nil nil)))
133 ;;; Internal Variables
135 (defvar org-html-format-table-no-css)
136 (defvar htmlize-buffer-places) ; from htmlize.el
138 (defconst org-html-special-string-regexps
139 '(("\\\\-" . "&shy;")
140 ("---\\([^-]\\)" . "&mdash;\\1")
141 ("--\\([^-]\\)" . "&ndash;\\1")
142 ("\\.\\.\\." . "&hellip;"))
143 "Regular expressions for special string conversion.")
145 (defconst org-html-scripts
146 "<script type=\"text/javascript\">
148 @licstart The following is the entire license notice for the
149 JavaScript code in this tag.
151 Copyright (C) 2012 Free Software Foundation, Inc.
153 The JavaScript code in this tag is free software: you can
154 redistribute it and/or modify it under the terms of the GNU
155 General Public License (GNU GPL) as published by the Free Software
156 Foundation, either version 3 of the License, or (at your option)
157 any later version. The code is distributed WITHOUT ANY WARRANTY;
158 without even the implied warranty of MERCHANTABILITY or FITNESS
159 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
161 As additional permission under GNU GPL version 3 section 7, you
162 may distribute non-source (e.g., minimized or compacted) forms of
163 that code without the copy of the GNU GPL normally required by
164 section 4, provided you include this license notice and a URL
165 through which recipients can access the Corresponding Source.
168 @licend The above is the entire license notice
169 for the JavaScript code in this tag.
171 <!--/*--><![CDATA[/*><!--*/
172 function CodeHighlightOn(elem, id)
174 var target = document.getElementById(id);
175 if(null != target) {
176 elem.cacheClassElem = elem.className;
177 elem.cacheClassTarget = target.className;
178 target.className = \"code-highlighted\";
179 elem.className = \"code-highlighted\";
182 function CodeHighlightOff(elem, id)
184 var target = document.getElementById(id);
185 if(elem.cacheClassElem)
186 elem.className = elem.cacheClassElem;
187 if(elem.cacheClassTarget)
188 target.className = elem.cacheClassTarget;
190 /*]]>*///-->
191 </script>"
192 "Basic JavaScript that is needed by HTML files produced by Org mode.")
194 (defconst org-html-style-default
195 "<style type=\"text/css\">
196 <!--/*--><![CDATA[/*><!--*/
197 html { font-family: Times, serif; font-size: 12pt; }
198 .title { text-align: center; }
199 .todo { color: red; }
200 .done { color: green; }
201 .tag { background-color: #add8e6; font-weight:normal }
202 .target { }
203 .timestamp { color: #bebebe; }
204 .timestamp-kwd { color: #5f9ea0; }
205 .right {margin-left:auto; margin-right:0px; text-align:right;}
206 .left {margin-left:0px; margin-right:auto; text-align:left;}
207 .center {margin-left:auto; margin-right:auto; text-align:center;}
208 p.verse { margin-left: 3% }
209 pre {
210 border: 1pt solid #AEBDCC;
211 background-color: #F3F5F7;
212 padding: 5pt;
213 font-family: courier, monospace;
214 font-size: 90%;
215 overflow:auto;
217 table { border-collapse: collapse; }
218 td, th { vertical-align: top; }
219 th.right { text-align:center; }
220 th.left { text-align:center; }
221 th.center { text-align:center; }
222 td.right { text-align:right; }
223 td.left { text-align:left; }
224 td.center { text-align:center; }
225 dt { font-weight: bold; }
226 div.figure { padding: 0.5em; }
227 div.figure p { text-align: center; }
228 div.inlinetask {
229 padding:10px;
230 border:2px solid gray;
231 margin:10px;
232 background: #ffffcc;
234 textarea { overflow-x: auto; }
235 .linenr { font-size:smaller }
236 .code-highlighted {background-color:#ffff00;}
237 .org-info-js_info-navigation { border-style:none; }
238 #org-info-js_console-label { font-size:10px; font-weight:bold;
239 white-space:nowrap; }
240 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
241 font-weight:bold; }
242 /*]]>*/-->
243 </style>"
244 "The default style specification for exported HTML files.
245 Please use the variables `org-html-style' and
246 `org-html-style-extra' to add to this style. If you wish to not
247 have the default style included, customize the variable
248 `org-html-style-include-default'.")
252 ;;; User Configuration Variables
254 (defgroup org-export-html nil
255 "Options for exporting Org mode files to HTML."
256 :tag "Org Export HTML"
257 :group 'org-export)
260 ;;;; Bold etc
262 (defcustom org-html-text-markup-alist
263 '((bold . "<b>%s</b>")
264 (code . "<code>%s</code>")
265 (italic . "<i>%s</i>")
266 (strike-through . "<del>%s</del>")
267 (underline . "<span style=\"text-decoration:underline;\">%s</span>")
268 (verbatim . "<code>%s</code>"))
269 "Alist of HTML expressions to convert text markup
271 The key must be a symbol among `bold', `code', `italic',
272 `strike-through', `underline' and `verbatim'. The value is
273 a formatting string to wrap fontified text with.
275 If no association can be found for a given markup, text will be
276 returned as-is."
277 :group 'org-export-html
278 :type '(alist :key-type (symbol :tag "Markup type")
279 :value-type (string :tag "Format string"))
280 :options '(bold code italic strike-through underline verbatim))
283 ;;;; Debugging
285 (defcustom org-html-pretty-output nil
286 "Enable this to generate pretty HTML."
287 :group 'org-export-html
288 :type 'boolean)
291 ;;;; Drawers
293 (defcustom org-html-format-drawer-function nil
294 "Function called to format a drawer in HTML code.
296 The function must accept two parameters:
297 NAME the drawer name, like \"LOGBOOK\"
298 CONTENTS the contents of the drawer.
300 The function should return the string to be exported.
302 For example, the variable could be set to the following function
303 in order to mimic default behaviour:
305 \(defun org-html-format-drawer-default \(name contents\)
306 \"Format a drawer element for HTML export.\"
307 contents\)"
308 :group 'org-export-html
309 :type 'function)
312 ;;;; Footnotes
314 (defcustom org-html-footnotes-section "<div id=\"footnotes\">
315 <h2 class=\"footnotes\">%s: </h2>
316 <div id=\"text-footnotes\">
318 </div>
319 </div>"
320 "Format for the footnotes section.
321 Should contain a two instances of %s. The first will be replaced with the
322 language-specific word for \"Footnotes\", the second one will be replaced
323 by the footnotes themselves."
324 :group 'org-export-html
325 :type 'string)
327 (defcustom org-html-footnote-format "<sup>%s</sup>"
328 "The format for the footnote reference.
329 %s will be replaced by the footnote reference itself."
330 :group 'org-export-html
331 :type 'string)
333 (defcustom org-html-footnote-separator "<sup>, </sup>"
334 "Text used to separate footnotes."
335 :group 'org-export-html
336 :type 'string)
339 ;;;; Headline
341 (defcustom org-html-toplevel-hlevel 2
342 "The <H> level for level 1 headings in HTML export.
343 This is also important for the classes that will be wrapped around headlines
344 and outline structure. If this variable is 1, the top-level headlines will
345 be <h1>, and the corresponding classes will be outline-1, section-number-1,
346 and outline-text-1. If this is 2, all of these will get a 2 instead.
347 The default for this variable is 2, because we use <h1> for formatting the
348 document title."
349 :group 'org-export-html
350 :type 'integer)
352 (defcustom org-html-format-headline-function nil
353 "Function to format headline text.
355 This function will be called with 5 arguments:
356 TODO the todo keyword (string or nil).
357 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
358 PRIORITY the priority of the headline (integer or nil)
359 TEXT the main headline text (string).
360 TAGS the tags (string or nil).
362 The function result will be used in the section format string.
364 As an example, one could set the variable to the following, in
365 order to reproduce the default set-up:
367 \(defun org-html-format-headline \(todo todo-type priority text tags)
368 \"Default format function for an headline.\"
369 \(concat \(when todo
370 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
371 \(when priority
372 \(format \"\\\\framebox{\\\\#%c} \" priority))
373 text
374 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
375 :group 'org-export-html
376 :type 'function)
379 ;;;; HTML-specific
381 (defcustom org-html-allow-name-attribute-in-anchors t
382 "When nil, do not set \"name\" attribute in anchors.
383 By default, anchors are formatted with both \"id\" and \"name\"
384 attributes, when appropriate."
385 :group 'org-export-html
386 :type 'boolean)
389 ;;;; Inlinetasks
391 (defcustom org-html-format-inlinetask-function nil
392 "Function called to format an inlinetask in HTML code.
394 The function must accept six parameters:
395 TODO the todo keyword, as a string
396 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
397 PRIORITY the inlinetask priority, as a string
398 NAME the inlinetask name, as a string.
399 TAGS the inlinetask tags, as a list of strings.
400 CONTENTS the contents of the inlinetask, as a string.
402 The function should return the string to be exported.
404 For example, the variable could be set to the following function
405 in order to mimic default behaviour:
407 \(defun org-html-format-inlinetask \(todo type priority name tags contents\)
408 \"Format an inline task element for HTML export.\"
409 \(let \(\(full-title
410 \(concat
411 \(when todo
412 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
413 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
414 title
415 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
416 \(format (concat \"\\\\begin{center}\\n\"
417 \"\\\\fbox{\\n\"
418 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
419 \"%s\\n\\n\"
420 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
421 \"%s\"
422 \"\\\\end{minipage}}\"
423 \"\\\\end{center}\")
424 full-title contents))"
425 :group 'org-export-html
426 :type 'function)
429 ;;;; LaTeX
431 (defcustom org-html-with-latex org-export-with-latex
432 "Non-nil means process LaTeX math snippets.
434 When set, the exporter will process LaTeX environments and
435 fragments.
437 This option can also be set with the +OPTIONS line,
438 e.g. \"tex:mathjax\". Allowed values are:
440 nil Ignore math snippets.
441 `verbatim' Keep everything in verbatim
442 `dvipng' Process the LaTeX fragments to images. This will also
443 include processing of non-math environments.
444 `imagemagick' Convert the LaTeX fragments to pdf files and use
445 imagemagick to convert pdf files to png files.
446 `mathjax' Do MathJax preprocessing and arrange for MathJax.js to
447 be loaded.
448 t Synonym for `mathjax'."
449 :group 'org-export-html
450 :type '(choice
451 (const :tag "Do not process math in any way" nil)
452 (const :tag "Use dvipng to make images" dvipng)
453 (const :tag "Use imagemagick to make images" imagemagick)
454 (const :tag "Use MathJax to display math" mathjax)
455 (const :tag "Leave math verbatim" verbatim)))
458 ;;;; Links :: Generic
460 (defcustom org-html-link-org-files-as-html t
461 "Non-nil means make file links to `file.org' point to `file.html'.
462 When org-mode is exporting an org-mode file to HTML, links to
463 non-html files are directly put into a href tag in HTML.
464 However, links to other Org-mode files (recognized by the
465 extension `.org.) should become links to the corresponding html
466 file, assuming that the linked org-mode file will also be
467 converted to HTML.
468 When nil, the links still point to the plain `.org' file."
469 :group 'org-export-html
470 :type 'boolean)
473 ;;;; Links :: Inline images
475 (defcustom org-html-inline-images 'maybe
476 "Non-nil means inline images into exported HTML pages.
477 This is done using an <img> tag. When nil, an anchor with href is used to
478 link to the image. If this option is `maybe', then images in links with
479 an empty description will be inlined, while images with a description will
480 be linked only."
481 :group 'org-export-html
482 :type '(choice (const :tag "Never" nil)
483 (const :tag "Always" t)
484 (const :tag "When there is no description" maybe)))
486 (defcustom org-html-inline-image-rules
487 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
488 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
489 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
490 "Rules characterizing image files that can be inlined into HTML.
492 A rule consists in an association whose key is the type of link
493 to consider, and value is a regexp that will be matched against
494 link's path.
496 Note that, by default, the image extension *actually* allowed
497 depend on the way the HTML file is processed. When used with
498 pdflatex, pdf, jpg and png images are OK. When processing
499 through dvi to Postscript, only ps and eps are allowed. The
500 default we use here encompasses both."
501 :group 'org-export-html
502 :type '(alist :key-type (string :tag "Type")
503 :value-type (regexp :tag "Path")))
506 ;;;; Plain Text
508 (defcustom org-html-protect-char-alist
509 '(("&" . "&amp;")
510 ("<" . "&lt;")
511 (">" . "&gt;"))
512 "Alist of characters to be converted by `org-html-protect'."
513 :group 'org-export-html
514 :type '(repeat (cons (string :tag "Character")
515 (string :tag "HTML equivalent"))))
518 ;;;; Src Block
520 (defcustom org-html-htmlize-output-type 'inline-css
521 "Output type to be used by htmlize when formatting code snippets.
522 Choices are `css', to export the CSS selectors only, or `inline-css', to
523 export the CSS attribute values inline in the HTML. We use as default
524 `inline-css', in order to make the resulting HTML self-containing.
526 However, this will fail when using Emacs in batch mode for export, because
527 then no rich font definitions are in place. It will also not be good if
528 people with different Emacs setup contribute HTML files to a website,
529 because the fonts will represent the individual setups. In these cases,
530 it is much better to let Org/Htmlize assign classes only, and to use
531 a style file to define the look of these classes.
532 To get a start for your css file, start Emacs session and make sure that
533 all the faces you are interested in are defined, for example by loading files
534 in all modes you want. Then, use the command
535 \\[org-html-htmlize-generate-css] to extract class definitions."
536 :group 'org-export-html
537 :type '(choice (const css) (const inline-css)))
539 (defcustom org-html-htmlize-font-prefix "org-"
540 "The prefix for CSS class names for htmlize font specifications."
541 :group 'org-export-html
542 :type 'string)
544 (defcustom org-html-htmlized-org-css-url nil
545 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
546 Normally when creating an htmlized version of an Org buffer, htmlize will
547 create CSS to define the font colors. However, this does not work when
548 converting in batch mode, and it also can look bad if different people
549 with different fontification setup work on the same website.
550 When this variable is non-nil, creating an htmlized version of an Org buffer
551 using `org-export-as-org' will remove the internal CSS section and replace it
552 with a link to this URL."
553 :group 'org-export-html
554 :type '(choice
555 (const :tag "Keep internal css" nil)
556 (string :tag "URL or local href")))
559 ;;;; Table
561 (defcustom org-html-table-tag
562 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
563 "The HTML tag that is used to start a table.
564 This must be a <table> tag, but you may change the options like
565 borders and spacing."
566 :group 'org-export-html
567 :type 'string)
569 (defcustom org-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
570 "The opening tag for table header fields.
571 This is customizable so that alignment options can be specified.
572 The first %s will be filled with the scope of the field, either row or col.
573 The second %s will be replaced by a style entry to align the field.
574 See also the variable `org-html-table-use-header-tags-for-first-column'.
575 See also the variable `org-html-table-align-individual-fields'."
576 :group 'org-export-tables ; FIXME: change group?
577 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
579 (defcustom org-html-table-data-tags '("<td%s>" . "</td>")
580 "The opening tag for table data fields.
581 This is customizable so that alignment options can be specified.
582 The first %s will be filled with the scope of the field, either row or col.
583 The second %s will be replaced by a style entry to align the field.
584 See also the variable `org-html-table-align-individual-fields'."
585 :group 'org-export-tables
586 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
588 (defcustom org-html-table-row-tags '("<tr>" . "</tr>")
589 "The opening tag for table data fields.
590 This is customizable so that alignment options can be specified.
591 Instead of strings, these can be Lisp forms that will be evaluated
592 for each row in order to construct the table row tags. During evaluation,
593 the variable `head' will be true when this is a header line, nil when this
594 is a body line. And the variable `nline' will contain the line number,
595 starting from 1 in the first header line. For example
597 (setq org-html-table-row-tags
598 (cons '(if head
599 \"<tr>\"
600 (if (= (mod nline 2) 1)
601 \"<tr class=\\\"tr-odd\\\">\"
602 \"<tr class=\\\"tr-even\\\">\"))
603 \"</tr>\"))
605 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
606 :group 'org-export-tables
607 :type '(cons
608 (choice :tag "Opening tag"
609 (string :tag "Specify")
610 (sexp))
611 (choice :tag "Closing tag"
612 (string :tag "Specify")
613 (sexp))))
615 (defcustom org-html-table-align-individual-fields t
616 "Non-nil means attach style attributes for alignment to each table field.
617 When nil, alignment will only be specified in the column tags, but this
618 is ignored by some browsers (like Firefox, Safari). Opera does it right
619 though."
620 :group 'org-export-tables
621 :type 'boolean)
623 (defcustom org-html-table-use-header-tags-for-first-column nil
624 "Non-nil means format column one in tables with header tags.
625 When nil, also column one will use data tags."
626 :group 'org-export-tables
627 :type 'boolean)
629 (defcustom org-html-table-caption-above t
630 "When non-nil, place caption string at the beginning of the table.
631 Otherwise, place it near the end."
632 :group 'org-export-html
633 :type 'boolean)
636 ;;;; Tags
638 (defcustom org-html-tag-class-prefix ""
639 "Prefix to class names for TODO keywords.
640 Each tag gets a class given by the tag itself, with this prefix.
641 The default prefix is empty because it is nice to just use the keyword
642 as a class name. But if you get into conflicts with other, existing
643 CSS classes, then this prefix can be very useful."
644 :group 'org-export-html
645 :type 'string)
648 ;;;; Template :: Generic
650 (defcustom org-html-extension "html"
651 "The extension for exported HTML files."
652 :group 'org-export-html
653 :type 'string)
655 (defcustom org-html-xml-declaration
656 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
657 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
658 "The extension for exported HTML files.
659 %s will be replaced with the charset of the exported file.
660 This may be a string, or an alist with export extensions
661 and corresponding declarations."
662 :group 'org-export-html
663 :type '(choice
664 (string :tag "Single declaration")
665 (repeat :tag "Dependent on extension"
666 (cons (string :tag "Extension")
667 (string :tag "Declaration")))))
669 (defcustom org-html-coding-system 'utf-8
670 "Coding system for HTML export.
671 Use utf-8 as the default value."
672 :group 'org-export-html
673 :type 'coding-system)
675 (defcustom org-html-divs '("preamble" "content" "postamble")
676 "The name of the main divs for HTML export.
677 This is a list of three strings, the first one for the preamble
678 DIV, the second one for the content DIV and the third one for the
679 postamble DIV."
680 :group 'org-export-html
681 :type '(list
682 (string :tag " Div for the preamble:")
683 (string :tag " Div for the content:")
684 (string :tag "Div for the postamble:")))
687 ;;;; Template :: Mathjax
689 (defcustom org-html-mathjax-options
690 '((path "http://orgmode.org/mathjax/MathJax.js")
691 (scale "100")
692 (align "center")
693 (indent "2em")
694 (mathml nil))
695 "Options for MathJax setup.
697 path The path where to find MathJax
698 scale Scaling for the HTML-CSS backend, usually between 100 and 133
699 align How to align display math: left, center, or right
700 indent If align is not center, how far from the left/right side?
701 mathml Should a MathML player be used if available?
702 This is faster and reduces bandwidth use, but currently
703 sometimes has lower spacing quality. Therefore, the default is
704 nil. When browsers get better, this switch can be flipped.
706 You can also customize this for each buffer, using something like
708 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
709 :group 'org-export-html
710 :type '(list :greedy t
711 (list :tag "path (the path from where to load MathJax.js)"
712 (const :format " " path) (string))
713 (list :tag "scale (scaling for the displayed math)"
714 (const :format " " scale) (string))
715 (list :tag "align (alignment of displayed equations)"
716 (const :format " " align) (string))
717 (list :tag "indent (indentation with left or right alignment)"
718 (const :format " " indent) (string))
719 (list :tag "mathml (should MathML display be used is possible)"
720 (const :format " " mathml) (boolean))))
722 (defcustom org-html-mathjax-template
723 "<script type=\"text/javascript\" src=\"%PATH\">
724 <!--/*--><![CDATA[/*><!--*/
725 MathJax.Hub.Config({
726 // Only one of the two following lines, depending on user settings
727 // First allows browser-native MathML display, second forces HTML/CSS
728 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
729 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
730 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
731 \"TeX/noUndefined.js\"],
732 tex2jax: {
733 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
734 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
735 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
736 ignoreClass: \"tex2jax_ignore\",
737 processEscapes: false,
738 processEnvironments: true,
739 preview: \"TeX\"
741 showProcessingMessages: true,
742 displayAlign: \"%ALIGN\",
743 displayIndent: \"%INDENT\",
745 \"HTML-CSS\": {
746 scale: %SCALE,
747 availableFonts: [\"STIX\",\"TeX\"],
748 preferredFont: \"TeX\",
749 webFont: \"TeX\",
750 imageFont: \"TeX\",
751 showMathMenu: true,
753 MMLorHTML: {
754 prefer: {
755 MSIE: \"MML\",
756 Firefox: \"MML\",
757 Opera: \"HTML\",
758 other: \"HTML\"
762 /*]]>*///-->
763 </script>"
764 "The MathJax setup for XHTML files."
765 :group 'org-export-html
766 :type 'string)
769 ;;;; Template :: Postamble
771 (defcustom org-html-postamble 'auto
772 "Non-nil means insert a postamble in HTML export.
774 When `t', insert a string as defined by the formatting string in
775 `org-html-postamble-format'. When set to a string, this
776 string overrides `org-html-postamble-format'. When set to
777 'auto, discard `org-html-postamble-format' and honor
778 `org-export-author/email/creator-info' variables. When set to a
779 function, apply this function and insert the returned string.
780 The function takes the property list of export options as its
781 only argument.
783 Setting :html-postamble in publishing projects will take
784 precedence over this variable."
785 :group 'org-export-html
786 :type '(choice (const :tag "No postamble" nil)
787 (const :tag "Auto preamble" 'auto)
788 (const :tag "Default formatting string" t)
789 (string :tag "Custom formatting string")
790 (function :tag "Function (must return a string)")))
792 (defcustom org-html-postamble-format
793 '(("en" "<p class=\"author\">Author: %a (%e)</p>
794 <p class=\"date\">Date: %d</p>
795 <p class=\"creator\">Generated by %c</p>
796 <p class=\"xhtml-validation\">%v</p>"))
797 "Alist of languages and format strings for the HTML postamble.
799 The first element of each list is the language code, as used for
800 the #+LANGUAGE keyword.
802 The second element of each list is a format string to format the
803 postamble itself. This format string can contain these elements:
805 %a stands for the author's name.
806 %e stands for the author's email.
807 %d stands for the date.
808 %c will be replaced by information about Org/Emacs versions.
809 %v will be replaced by `org-html-validation-link'.
811 If you need to use a \"%\" character, you need to escape it
812 like that: \"%%\"."
813 :group 'org-export-html
814 :type '(alist :key-type (string :tag "Language")
815 :value-type (string :tag "Format string")))
817 (defcustom org-html-validation-link
818 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
819 "Link to HTML validation service."
820 :group 'org-export-html
821 :type 'string)
823 (defcustom org-html-creator-string
824 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
825 (if (fboundp 'org-version) (org-version) "(Unknown)")
826 emacs-version)
827 "String to insert at the end of the HTML document."
828 :group 'org-export-html
829 :type '(string :tag "Creator string"))
832 ;;;; Template :: Preamble
834 (defcustom org-html-preamble t
835 "Non-nil means insert a preamble in HTML export.
837 When `t', insert a string as defined by one of the formatting
838 strings in `org-html-preamble-format'. When set to a
839 string, this string overrides `org-html-preamble-format'.
840 When set to a function, apply this function and insert the
841 returned string. The function takes the property list of export
842 options as its only argument.
844 Setting :html-preamble in publishing projects will take
845 precedence over this variable."
846 :group 'org-export-html
847 :type '(choice (const :tag "No preamble" nil)
848 (const :tag "Default preamble" t)
849 (string :tag "Custom formatting string")
850 (function :tag "Function (must return a string)")))
852 (defcustom org-html-preamble-format '(("en" ""))
853 "Alist of languages and format strings for the HTML preamble.
855 The first element of each list is the language code, as used for
856 the #+LANGUAGE keyword.
858 The second element of each list is a format string to format the
859 preamble itself. This format string can contain these elements:
861 %t stands for the title.
862 %a stands for the author's name.
863 %e stands for the author's email.
864 %d stands for the date.
866 If you need to use a \"%\" character, you need to escape it
867 like that: \"%%\"."
868 :group 'org-export-html
869 :type '(alist :key-type (string :tag "Language")
870 :value-type (string :tag "Format string")))
872 (defcustom org-html-link-up ""
873 "Where should the \"UP\" link of exported HTML pages lead?"
874 :group 'org-export-html
875 :type '(string :tag "File or URL"))
877 (defcustom org-html-link-home ""
878 "Where should the \"HOME\" link of exported HTML pages lead?"
879 :group 'org-export-html
880 :type '(string :tag "File or URL"))
882 (defcustom org-html-home/up-format
883 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
884 <a accesskey=\"h\" href=\"%s\"> UP </a>
886 <a accesskey=\"H\" href=\"%s\"> HOME </a>
887 </div>"
888 "Snippet used to insert the HOME and UP links.
889 This is a format string, the first %s will receive the UP link,
890 the second the HOME link. If both `org-html-link-up' and
891 `org-html-link-home' are empty, the entire snippet will be
892 ignored."
893 :group 'org-export-html
894 :type 'string)
897 ;;;; Template :: Scripts
899 (defcustom org-html-style-include-scripts t
900 "Non-nil means include the JavaScript snippets in exported HTML files.
901 The actual script is defined in `org-html-scripts' and should
902 not be modified."
903 :group 'org-export-html
904 :type 'boolean)
907 ;;;; Template :: Styles
909 (defcustom org-html-style-include-default t
910 "Non-nil means include the default style in exported HTML files.
911 The actual style is defined in `org-html-style-default' and should
912 not be modified. Use the variables `org-html-style' to add
913 your own style information."
914 :group 'org-export-html
915 :type 'boolean)
916 ;;;###autoload
917 (put 'org-html-style-include-default 'safe-local-variable 'booleanp)
919 (defcustom org-html-style ""
920 "Org-wide style definitions for exported HTML files.
922 This variable needs to contain the full HTML structure to provide a style,
923 including the surrounding HTML tags. If you set the value of this variable,
924 you should consider to include definitions for the following classes:
925 title, todo, done, timestamp, timestamp-kwd, tag, target.
927 For example, a valid value would be:
929 <style type=\"text/css\">
930 <![CDATA[
931 p { font-weight: normal; color: gray; }
932 h1 { color: black; }
933 .title { text-align: center; }
934 .todo, .timestamp-kwd { color: red; }
935 .done { color: green; }
937 </style>
939 If you'd like to refer to an external style file, use something like
941 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
943 As the value of this option simply gets inserted into the HTML <head> header,
944 you can \"misuse\" it to add arbitrary text to the header.
945 See also the variable `org-html-style-extra'."
946 :group 'org-export-html
947 :type 'string)
948 ;;;###autoload
949 (put 'org-html-style 'safe-local-variable 'stringp)
951 (defcustom org-html-style-extra ""
952 "Additional style information for HTML export.
953 The value of this variable is inserted into the HTML buffer right after
954 the value of `org-html-style'. Use this variable for per-file
955 settings of style information, and do not forget to surround the style
956 settings with <style>...</style> tags."
957 :group 'org-export-html
958 :type 'string)
959 ;;;###autoload
960 (put 'org-html-style-extra 'safe-local-variable 'stringp)
963 ;;;; Todos
965 (defcustom org-html-todo-kwd-class-prefix ""
966 "Prefix to class names for TODO keywords.
967 Each TODO keyword gets a class given by the keyword itself, with this prefix.
968 The default prefix is empty because it is nice to just use the keyword
969 as a class name. But if you get into conflicts with other, existing
970 CSS classes, then this prefix can be very useful."
971 :group 'org-export-html
972 :type 'string)
974 (defcustom org-html-display-buffer-mode 'html-mode
975 "Default mode when visiting the HTML output."
976 :group 'org-export-html
977 :version "24.3"
978 :type '(choice (function 'html-mode)
979 (function 'nxml-mode)
980 (function :tag "Other mode")))
984 ;;; Internal Functions
986 (defun org-html-format-inline-image (src &optional
987 caption label attr standalone-p)
988 (let* ((id (if (not label) ""
989 (format " id=\"%s\"" (org-export-solidify-link-text label))))
990 (attr (concat attr
991 (cond
992 ((string-match "\\<alt=" (or attr "")) "")
993 ((string-match "^ltxpng/" src)
994 (format " alt=\"%s\""
995 (org-html-encode-plain-text
996 (org-find-text-property-in-string
997 'org-latex-src src))))
998 (t (format " alt=\"%s\""
999 (file-name-nondirectory src)))))))
1000 (cond
1001 (standalone-p
1002 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1003 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1004 id (format "\n<p>%s</p>" img)
1005 (when caption (format "\n<p>%s</p>" caption)))))
1006 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1008 (defun org-html--textarea-block (element)
1009 "Transcode ELEMENT into a textarea block.
1010 ELEMENT is either a src block or an example block."
1011 (let ((code (car (org-export-unravel-code element)))
1012 (attr (org-export-read-attribute :attr_html element)))
1013 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1014 (or (plist-get attr :width) 80)
1015 (or (plist-get attr :height) (org-count-lines code))
1016 code)))
1019 ;;;; Bibliography
1021 (defun org-html-bibliography ()
1022 "Find bibliography, cut it out and return it."
1023 (catch 'exit
1024 (let (beg end (cnt 1) bib)
1025 (save-excursion
1026 (goto-char (point-min))
1027 (when (re-search-forward
1028 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1029 (setq beg (match-beginning 0))
1030 (while (re-search-forward "</?div\\>" nil t)
1031 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1032 (when (= cnt 0)
1033 (and (looking-at ">") (forward-char 1))
1034 (setq bib (buffer-substring beg (point)))
1035 (delete-region beg (point))
1036 (throw 'exit bib))))
1037 nil))))
1039 ;;;; Table
1041 (defun org-html-splice-attributes (tag attributes)
1042 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1043 (if (not attributes)
1045 (let (oldatt newatt)
1046 (setq oldatt (org-extract-attributes-from-string tag)
1047 tag (pop oldatt)
1048 newatt (cdr (org-extract-attributes-from-string attributes)))
1049 (while newatt
1050 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1051 (if (string-match ">" tag)
1052 (setq tag
1053 (replace-match (concat (org-attributes-to-string oldatt) ">")
1054 t t tag)))
1055 tag)))
1057 (defun org-export-splice-style (style extra)
1058 "Splice EXTRA into STYLE, just before \"</style>\"."
1059 (if (and (stringp extra)
1060 (string-match "\\S-" extra)
1061 (string-match "</style>" style))
1062 (concat (substring style 0 (match-beginning 0))
1063 "\n" extra "\n"
1064 (substring style (match-beginning 0)))
1065 style))
1067 (defun org-html-htmlize-region-for-paste (beg end)
1068 "Convert the region to HTML, using htmlize.el.
1069 This is much like `htmlize-region-for-paste', only that it uses
1070 the settings define in the org-... variables."
1071 (let* ((htmlize-output-type org-html-htmlize-output-type)
1072 (htmlize-css-name-prefix org-html-htmlize-font-prefix)
1073 (htmlbuf (htmlize-region beg end)))
1074 (unwind-protect
1075 (with-current-buffer htmlbuf
1076 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1077 (plist-get htmlize-buffer-places 'content-end)))
1078 (kill-buffer htmlbuf))))
1080 ;;;###autoload
1081 (defun org-html-htmlize-generate-css ()
1082 "Create the CSS for all font definitions in the current Emacs session.
1083 Use this to create face definitions in your CSS style file that can then
1084 be used by code snippets transformed by htmlize.
1085 This command just produces a buffer that contains class definitions for all
1086 faces used in the current Emacs session. You can copy and paste the ones you
1087 need into your CSS file.
1089 If you then set `org-html-htmlize-output-type' to `css', calls
1090 to the function `org-html-htmlize-region-for-paste' will
1091 produce code that uses these same face definitions."
1092 (interactive)
1093 (require 'htmlize)
1094 (and (get-buffer "*html*") (kill-buffer "*html*"))
1095 (with-temp-buffer
1096 (let ((fl (face-list))
1097 (htmlize-css-name-prefix "org-")
1098 (htmlize-output-type 'css)
1099 f i)
1100 (while (setq f (pop fl)
1101 i (and f (face-attribute f :inherit)))
1102 (when (and (symbolp f) (or (not i) (not (listp i))))
1103 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1104 (htmlize-region (point-min) (point-max))))
1105 (org-pop-to-buffer-same-window "*html*")
1106 (goto-char (point-min))
1107 (if (re-search-forward "<style" nil t)
1108 (delete-region (point-min) (match-beginning 0)))
1109 (if (re-search-forward "</style>" nil t)
1110 (delete-region (1+ (match-end 0)) (point-max)))
1111 (beginning-of-line 1)
1112 (if (looking-at " +") (replace-match ""))
1113 (goto-char (point-min)))
1115 (defun org-html--make-string (n string)
1116 "Build a string by concatenating N times STRING."
1117 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1119 (defun org-html-toc-text (toc-entries)
1120 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1121 (start-level prev-level))
1122 (concat
1123 (mapconcat
1124 (lambda (entry)
1125 (let ((headline (nth 0 entry))
1126 (level (nth 1 entry)))
1127 (concat
1128 (let* ((cnt (- level prev-level))
1129 (times (if (> cnt 0) (1- cnt) (- cnt)))
1130 rtn)
1131 (setq prev-level level)
1132 (concat
1133 (org-html--make-string
1134 times (cond ((> cnt 0) "\n<ul>\n<li>")
1135 ((< cnt 0) "</li>\n</ul>\n")))
1136 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1137 headline)))
1138 toc-entries "")
1139 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1141 (defun* org-html-format-toc-headline
1142 (todo todo-type priority text tags
1143 &key level section-number headline-label &allow-other-keys)
1144 (let ((headline (concat
1145 section-number (and section-number ". ")
1146 text
1147 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags))))
1148 (format "<a href=\"#%s\">%s</a>"
1149 (org-export-solidify-link-text headline-label)
1150 (if (not nil) headline
1151 (format "<span class=\"%s\">%s</span>" todo-type headline)))))
1153 (defun org-html-toc (depth info)
1154 (let* ((headlines (org-export-collect-headlines info depth))
1155 (toc-entries
1156 (loop for headline in headlines collect
1157 (list (org-html-format-headline--wrap
1158 headline info 'org-html-format-toc-headline)
1159 (org-export-get-relative-level headline info)))))
1160 (when toc-entries
1161 (concat
1162 "<div id=\"table-of-contents\">\n"
1163 (format "<h%d>%s</h%d>\n"
1164 org-html-toplevel-hlevel
1165 (org-html--translate "Table of Contents" info)
1166 org-html-toplevel-hlevel)
1167 "<div id=\"text-table-of-contents\">"
1168 (org-html-toc-text toc-entries)
1169 "</div>\n"
1170 "</div>\n"))))
1172 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1173 "Turn todo keyword into a valid class name.
1174 Replaces invalid characters with \"_\"."
1175 (save-match-data
1176 (while (string-match "[^a-zA-Z0-9_]" kwd)
1177 (setq kwd (replace-match "_" t t kwd))))
1178 kwd)
1180 (defun org-html-format-footnote-reference (n def refcnt)
1181 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1182 (format org-html-footnote-format
1183 (let* ((id (format "fnr.%s%s" n extra))
1184 (href (format " href=\"#fn.%s\"" n))
1185 (attributes (concat " class=\"footref\"" href)))
1186 (org-html--anchor id n attributes)))))
1188 (defun org-html-format-footnotes-section (section-name definitions)
1189 (if (not definitions) ""
1190 (format org-html-footnotes-section section-name definitions)))
1192 (defun org-html-format-footnote-definition (fn)
1193 (let ((n (car fn)) (def (cdr fn)))
1194 (format
1195 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1196 (format org-html-footnote-format
1197 (let* ((id (format "fn.%s" n))
1198 (href (format " href=\"#fnr.%s\"" n))
1199 (attributes (concat " class=\"footnum\"" href)))
1200 (org-html--anchor id n attributes)))
1201 def)))
1203 (defun org-html-footnote-section (info)
1204 (let* ((fn-alist (org-export-collect-footnote-definitions
1205 (plist-get info :parse-tree) info))
1207 (fn-alist
1208 (loop for (n type raw) in fn-alist collect
1209 (cons n (if (eq (org-element-type raw) 'org-data)
1210 (org-trim (org-export-data raw info))
1211 (format "<p>%s</p>"
1212 (org-trim (org-export-data raw info))))))))
1213 (when fn-alist
1214 (org-html-format-footnotes-section
1215 (org-html--translate "Footnotes" info)
1216 (format
1217 "<table>\n%s\n</table>\n"
1218 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1222 ;;; Template
1224 (defun org-html--build-meta-info (info)
1225 "Return meta tags for exported document.
1226 INFO is a plist used as a communication channel."
1227 (let* ((title (org-export-data (plist-get info :title) info))
1228 (author (and (plist-get info :with-author)
1229 (let ((auth (plist-get info :author)))
1230 (and auth (org-export-data auth info)))))
1231 (date (and (plist-get info :with-date)
1232 (let ((date (plist-get info :date)))
1233 (and date (org-export-data date info)))))
1234 (description (plist-get info :description))
1235 (keywords (plist-get info :keywords)))
1236 (concat
1237 (format "<title>%s</title>\n" title)
1238 (format
1239 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1240 (or (and org-html-coding-system
1241 (fboundp 'coding-system-get)
1242 (coding-system-get org-html-coding-system 'mime-charset))
1243 "iso-8859-1"))
1244 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1245 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1246 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1247 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1248 (and description
1249 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1250 (and keywords
1251 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1253 (defun org-html--build-style (info)
1254 "Return style information for exported document.
1255 INFO is a plist used as a communication channel."
1256 (org-element-normalize-string
1257 (concat
1258 (when (plist-get info :html-style-include-default) org-html-style-default)
1259 (org-element-normalize-string (plist-get info :html-style))
1260 (org-element-normalize-string (plist-get info :html-style-extra))
1261 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1263 (defun org-html--build-mathjax-config (info)
1264 "Insert the user setup into the mathjax template.
1265 INFO is a plist used as a communication channel."
1266 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1267 (org-element-map (plist-get info :parse-tree)
1268 '(latex-fragment latex-environment) 'identity info t))
1269 (let ((template org-html-mathjax-template)
1270 (options org-html-mathjax-options)
1271 (in-buffer (or (plist-get info :html-mathjax) ""))
1272 name val (yes " ") (no "// ") x)
1273 (mapc
1274 (lambda (e)
1275 (setq name (car e) val (nth 1 e))
1276 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1277 (setq val (car (read-from-string
1278 (substring in-buffer (match-end 0))))))
1279 (if (not (stringp val)) (setq val (format "%s" val)))
1280 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1281 (setq template (replace-match val t t template))))
1282 options)
1283 (setq val (nth 1 (assq 'mathml options)))
1284 (if (string-match (concat "\\<mathml:") in-buffer)
1285 (setq val (car (read-from-string
1286 (substring in-buffer (match-end 0))))))
1287 ;; Exchange prefixes depending on mathml setting.
1288 (if (not val) (setq x yes yes no no x))
1289 ;; Replace cookies to turn on or off the config/jax lines.
1290 (if (string-match ":MMLYES:" template)
1291 (setq template (replace-match yes t t template)))
1292 (if (string-match ":MMLNO:" template)
1293 (setq template (replace-match no t t template)))
1294 ;; Return the modified template.
1295 (org-element-normalize-string template))))
1297 (defun org-html--build-preamble (info)
1298 "Return document preamble as a string, or nil.
1299 INFO is a plist used as a communication channel."
1300 (let ((preamble (plist-get info :html-preamble)))
1301 (when preamble
1302 (let ((preamble-contents
1303 (if (functionp preamble) (funcall preamble info)
1304 (let ((title (org-export-data (plist-get info :title) info))
1305 (date (if (not (plist-get info :with-date)) ""
1306 (org-export-data (plist-get info :date) info)))
1307 (author (if (not (plist-get info :with-author)) ""
1308 (org-export-data (plist-get info :author) info)))
1309 (email (if (not (plist-get info :with-email)) ""
1310 (plist-get info :email))))
1311 (if (stringp preamble)
1312 (format-spec preamble
1313 `((?t . ,title) (?a . ,author)
1314 (?d . ,date) (?e . ,email)))
1315 (format-spec
1316 (or (cadr (assoc (plist-get info :language)
1317 org-html-preamble-format))
1318 (cadr (assoc "en" org-html-preamble-format)))
1319 `((?t . ,title) (?a . ,author)
1320 (?d . ,date) (?e . ,email))))))))
1321 (when (org-string-nw-p preamble-contents)
1322 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1323 (org-element-normalize-string preamble-contents)
1324 "</div>\n"))))))
1326 (defun org-html--build-postamble (info)
1327 "Return document postamble as a string, or nil.
1328 INFO is a plist used as a communication channel."
1329 (let ((postamble (plist-get info :html-postamble)))
1330 (when postamble
1331 (let ((postamble-contents
1332 (if (functionp postamble) (funcall postamble info)
1333 (let ((date (if (not (plist-get info :with-date)) ""
1334 (org-export-data (plist-get info :date) info)))
1335 (author (let ((author (plist-get info :author)))
1336 (and author (org-export-data author info))))
1337 (email (mapconcat
1338 (lambda (e)
1339 (format "<a href=\"mailto:%s\">%s</a>" e e))
1340 (split-string (plist-get info :email) ",+ *")
1341 ", "))
1342 (html-validation-link (or org-html-validation-link ""))
1343 (creator-info (plist-get info :creator)))
1344 (cond ((stringp postamble)
1345 (format-spec postamble
1346 `((?a . ,author) (?e . ,email)
1347 (?d . ,date) (?c . ,creator-info)
1348 (?v . ,html-validation-link))))
1349 ((eq postamble 'auto)
1350 (concat
1351 (when (plist-get info :time-stamp-file)
1352 (format "<p class=\"date\">%s: %s</p>\n"
1353 (org-html--translate "Date" info)
1354 date))
1355 (when (and (plist-get info :with-author) author)
1356 (format "<p class=\"author\">%s : %s</p>\n"
1357 (org-html--translate "Author" info)
1358 author))
1359 (when (and (plist-get info :with-email) email)
1360 (format "<p class=\"email\">%s </p>\n" email))
1361 (when (plist-get info :with-creator)
1362 (format "<p class=\"creator\">%s</p>\n"
1363 creator-info))
1364 html-validation-link "\n"))
1365 (t (format-spec
1366 (or (cadr (assoc (plist-get info :language)
1367 org-html-postamble-format))
1368 (cadr (assoc "en" org-html-postamble-format)))
1369 `((?a . ,author) (?e . ,email)
1370 (?d . ,date) (?c . ,creator-info)
1371 (?v . ,html-validation-link)))))))))
1372 (when (org-string-nw-p postamble-contents)
1373 (concat
1374 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1375 (org-element-normalize-string postamble-contents)
1376 "</div>\n"))))))
1378 (defun org-html-inner-template (contents info)
1379 "Return body of document string after HTML conversion.
1380 CONTENTS is the transcoded contents string. INFO is a plist
1381 holding export options."
1382 (concat
1383 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1384 ;; Document title.
1385 (format "<h1 class=\"title\">%s</h1>\n"
1386 (org-export-data (plist-get info :title) info))
1387 ;; Table of contents.
1388 (let ((depth (plist-get info :with-toc)))
1389 (when depth (org-html-toc depth info)))
1390 ;; Document contents.
1391 contents
1392 ;; Footnotes section.
1393 (org-html-footnote-section info)
1394 ;; Bibliography.
1395 (org-html-bibliography)
1396 "\n</div>"))
1398 (defun org-html-template (contents info)
1399 "Return complete document string after HTML conversion.
1400 CONTENTS is the transcoded contents string. INFO is a plist
1401 holding export options."
1402 (concat
1403 (format
1404 (or (and (stringp org-html-xml-declaration)
1405 org-html-xml-declaration)
1406 (cdr (assoc (plist-get info :html-extension)
1407 org-html-xml-declaration))
1408 (cdr (assoc "html" org-html-xml-declaration))
1411 (or (and org-html-coding-system
1412 (fboundp 'coding-system-get)
1413 (coding-system-get org-html-coding-system 'mime-charset))
1414 "iso-8859-1"))
1415 "\n"
1416 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1417 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1418 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1419 (plist-get info :language) (plist-get info :language))
1420 "<head>\n"
1421 (org-html--build-meta-info info)
1422 (org-html--build-style info)
1423 (org-html--build-mathjax-config info)
1424 "</head>\n"
1425 "<body>\n"
1426 (let ((link-up (org-trim (plist-get info :html-link-up)))
1427 (link-home (org-trim (plist-get info :html-link-home))))
1428 (unless (and (string= link-up "") (string= link-up ""))
1429 (format org-html-home/up-format
1430 (or link-up link-home)
1431 (or link-home link-up))))
1432 ;; Preamble.
1433 (org-html--build-preamble info)
1434 ;; Document contents.
1435 contents
1436 ;; Postamble.
1437 (org-html--build-postamble info)
1438 ;; Closing document.
1439 "</body>\n</html>"))
1441 (defun org-html--translate (s info)
1442 "Translate string S according to specified language.
1443 INFO is a plist used as a communication channel."
1444 (org-export-translate s :html info))
1446 ;;;; Anchor
1448 (defun org-html--anchor (&optional id desc attributes)
1449 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1450 (attributes (concat (and id (format " id=\"%s\"" id))
1451 (and name (format " name=\"%s\"" name))
1452 attributes)))
1453 (format "<a%s>%s</a>" attributes (or desc ""))))
1455 ;;;; Todo
1457 (defun org-html--todo (todo)
1458 (when todo
1459 (format "<span class=\"%s %s%s\">%s</span>"
1460 (if (member todo org-done-keywords) "done" "todo")
1461 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1462 todo)))
1464 ;;;; Tags
1466 (defun org-html--tags (tags)
1467 (when tags
1468 (format "<span class=\"tag\">%s</span>"
1469 (mapconcat
1470 (lambda (tag)
1471 (format "<span class=\"%s\">%s</span>"
1472 (concat org-html-tag-class-prefix
1473 (org-html-fix-class-name tag))
1474 tag))
1475 tags "&nbsp;"))))
1477 ;;;; Headline
1479 (defun* org-html-format-headline
1480 (todo todo-type priority text tags
1481 &key level section-number headline-label &allow-other-keys)
1482 (let ((section-number
1483 (when section-number
1484 (format "<span class=\"section-number-%d\">%s</span> "
1485 level section-number)))
1486 (todo (org-html--todo todo))
1487 (tags (org-html--tags tags)))
1488 (concat section-number todo (and todo " ") text
1489 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1491 ;;;; Src Code
1493 (defun org-html-fontify-code (code lang)
1494 "Color CODE with htmlize library.
1495 CODE is a string representing the source code to colorize. LANG
1496 is the language used for CODE, as a string, or nil."
1497 (when code
1498 (cond
1499 ;; Case 1: No lang. Possibly an example block.
1500 ((not lang)
1501 ;; Simple transcoding.
1502 (org-html-encode-plain-text code))
1503 ;; Case 2: No htmlize or an inferior version of htmlize
1504 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1505 ;; Emit a warning.
1506 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1507 ;; Simple transcoding.
1508 (org-html-encode-plain-text code))
1510 ;; Map language
1511 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1512 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1513 (cond
1514 ;; Case 1: Language is not associated with any Emacs mode
1515 ((not (functionp lang-mode))
1516 ;; Simple transcoding.
1517 (org-html-encode-plain-text code))
1518 ;; Case 2: Default. Fontify code.
1520 ;; htmlize
1521 (setq code (with-temp-buffer
1522 ;; Switch to language-specific mode.
1523 (funcall lang-mode)
1524 (insert code)
1525 ;; Fontify buffer.
1526 (font-lock-fontify-buffer)
1527 ;; Remove formatting on newline characters.
1528 (save-excursion
1529 (let ((beg (point-min))
1530 (end (point-max)))
1531 (goto-char beg)
1532 (while (progn (end-of-line) (< (point) end))
1533 (put-text-property (point) (1+ (point)) 'face nil)
1534 (forward-char 1))))
1535 (org-src-mode)
1536 (set-buffer-modified-p nil)
1537 ;; Htmlize region.
1538 (org-html-htmlize-region-for-paste
1539 (point-min) (point-max))))
1540 ;; Strip any encolosing <pre></pre> tags.
1541 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1542 (match-string 1 code)
1543 code))))))))
1545 (defun org-html-do-format-code
1546 (code &optional lang refs retain-labels num-start)
1547 "Format CODE string as source code.
1548 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1549 respectively, the language of the source code, as a string, an
1550 alist between line numbers and references (as returned by
1551 `org-export-unravel-code'), a boolean specifying if labels should
1552 appear in the source code, and the number associated to the first
1553 line of code."
1554 (let* ((code-lines (org-split-string code "\n"))
1555 (code-length (length code-lines))
1556 (num-fmt
1557 (and num-start
1558 (format "%%%ds: "
1559 (length (number-to-string (+ code-length num-start))))))
1560 (code (org-html-fontify-code code lang)))
1561 (org-export-format-code
1562 code
1563 (lambda (loc line-num ref)
1564 (setq loc
1565 (concat
1566 ;; Add line number, if needed.
1567 (when num-start
1568 (format "<span class=\"linenr\">%s</span>"
1569 (format num-fmt line-num)))
1570 ;; Transcoded src line.
1572 ;; Add label, if needed.
1573 (when (and ref retain-labels) (format " (%s)" ref))))
1574 ;; Mark transcoded line as an anchor, if needed.
1575 (if (not ref) loc
1576 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1577 ref loc)))
1578 num-start refs)))
1580 (defun org-html-format-code (element info)
1581 "Format contents of ELEMENT as source code.
1582 ELEMENT is either an example block or a src block. INFO is
1583 a plist used as a communication channel."
1584 (let* ((lang (org-element-property :language element))
1585 ;; Extract code and references.
1586 (code-info (org-export-unravel-code element))
1587 (code (car code-info))
1588 (refs (cdr code-info))
1589 ;; Does the src block contain labels?
1590 (retain-labels (org-element-property :retain-labels element))
1591 ;; Does it have line numbers?
1592 (num-start (case (org-element-property :number-lines element)
1593 (continued (org-export-get-loc element info))
1594 (new 0))))
1595 (org-html-do-format-code code lang refs retain-labels num-start)))
1599 ;;; Transcode Functions
1601 ;;;; Bold
1603 (defun org-html-bold (bold contents info)
1604 "Transcode BOLD from Org to HTML.
1605 CONTENTS is the text with bold markup. INFO is a plist holding
1606 contextual information."
1607 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1608 contents))
1611 ;;;; Center Block
1613 (defun org-html-center-block (center-block contents info)
1614 "Transcode a CENTER-BLOCK element from Org to HTML.
1615 CONTENTS holds the contents of the block. INFO is a plist
1616 holding contextual information."
1617 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1620 ;;;; Clock
1622 (defun org-html-clock (clock contents info)
1623 "Transcode a CLOCK element from Org to HTML.
1624 CONTENTS is nil. INFO is a plist used as a communication
1625 channel."
1626 (format "<p>
1627 <span class=\"timestamp-wrapper\">
1628 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1629 </span>
1630 </p>"
1631 org-clock-string
1632 (org-translate-time
1633 (org-element-property :raw-value
1634 (org-element-property :value clock)))
1635 (let ((time (org-element-property :duration clock)))
1636 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1639 ;;;; Code
1641 (defun org-html-code (code contents info)
1642 "Transcode CODE from Org to HTML.
1643 CONTENTS is nil. INFO is a plist holding contextual
1644 information."
1645 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1646 (org-element-property :value code)))
1649 ;;;; Drawer
1651 (defun org-html-drawer (drawer contents info)
1652 "Transcode a DRAWER element from Org to HTML.
1653 CONTENTS holds the contents of the block. INFO is a plist
1654 holding contextual information."
1655 (if (functionp org-html-format-drawer-function)
1656 (funcall org-html-format-drawer-function
1657 (org-element-property :drawer-name drawer)
1658 contents)
1659 ;; If there's no user defined function: simply
1660 ;; display contents of the drawer.
1661 contents))
1664 ;;;; Dynamic Block
1666 (defun org-html-dynamic-block (dynamic-block contents info)
1667 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1668 CONTENTS holds the contents of the block. INFO is a plist
1669 holding contextual information. See `org-export-data'."
1670 contents)
1673 ;;;; Entity
1675 (defun org-html-entity (entity contents info)
1676 "Transcode an ENTITY object from Org to HTML.
1677 CONTENTS are the definition itself. INFO is a plist holding
1678 contextual information."
1679 (org-element-property :html entity))
1682 ;;;; Example Block
1684 (defun org-html-example-block (example-block contents info)
1685 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1686 CONTENTS is nil. INFO is a plist holding contextual
1687 information."
1688 (if (org-export-read-attribute :attr_html example-block :textarea)
1689 (org-html--textarea-block example-block)
1690 (format "<pre class=\"example\">\n%s</pre>"
1691 (org-html-format-code example-block info))))
1694 ;;;; Export Snippet
1696 (defun org-html-export-snippet (export-snippet contents info)
1697 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1698 CONTENTS is nil. INFO is a plist holding contextual
1699 information."
1700 (when (eq (org-export-snippet-backend export-snippet) 'html)
1701 (org-element-property :value export-snippet)))
1704 ;;;; Export Block
1706 (defun org-html-export-block (export-block contents info)
1707 "Transcode a EXPORT-BLOCK element from Org to HTML.
1708 CONTENTS is nil. INFO is a plist holding contextual information."
1709 (when (string= (org-element-property :type export-block) "HTML")
1710 (org-remove-indentation (org-element-property :value export-block))))
1713 ;;;; Fixed Width
1715 (defun org-html-fixed-width (fixed-width contents info)
1716 "Transcode a FIXED-WIDTH element from Org to HTML.
1717 CONTENTS is nil. INFO is a plist holding contextual information."
1718 (format "<pre class=\"example\">\n%s</pre>"
1719 (org-html-do-format-code
1720 (org-remove-indentation
1721 (org-element-property :value fixed-width)))))
1724 ;;;; Footnote Reference
1726 (defun org-html-footnote-reference (footnote-reference contents info)
1727 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1728 CONTENTS is nil. INFO is a plist holding contextual information."
1729 (concat
1730 ;; Insert separator between two footnotes in a row.
1731 (let ((prev (org-export-get-previous-element footnote-reference info)))
1732 (when (eq (org-element-type prev) 'footnote-reference)
1733 org-html-footnote-separator))
1734 (cond
1735 ((not (org-export-footnote-first-reference-p footnote-reference info))
1736 (org-html-format-footnote-reference
1737 (org-export-get-footnote-number footnote-reference info)
1738 "IGNORED" 100))
1739 ;; Inline definitions are secondary strings.
1740 ((eq (org-element-property :type footnote-reference) 'inline)
1741 (org-html-format-footnote-reference
1742 (org-export-get-footnote-number footnote-reference info)
1743 "IGNORED" 1))
1744 ;; Non-inline footnotes definitions are full Org data.
1745 (t (org-html-format-footnote-reference
1746 (org-export-get-footnote-number footnote-reference info)
1747 "IGNORED" 1)))))
1750 ;;;; Headline
1752 (defun org-html-format-headline--wrap (headline info
1753 &optional format-function
1754 &rest extra-keys)
1755 "Transcode an HEADLINE element from Org to HTML.
1756 CONTENTS holds the contents of the headline. INFO is a plist
1757 holding contextual information."
1758 (let* ((level (+ (org-export-get-relative-level headline info)
1759 (1- org-html-toplevel-hlevel)))
1760 (headline-number (org-export-get-headline-number headline info))
1761 (section-number (and (not (org-export-low-level-p headline info))
1762 (org-export-numbered-headline-p headline info)
1763 (mapconcat 'number-to-string
1764 headline-number ".")))
1765 (todo (and (plist-get info :with-todo-keywords)
1766 (let ((todo (org-element-property :todo-keyword headline)))
1767 (and todo (org-export-data todo info)))))
1768 (todo-type (and todo (org-element-property :todo-type headline)))
1769 (priority (and (plist-get info :with-priority)
1770 (org-element-property :priority headline)))
1771 (text (org-export-data (org-element-property :title headline) info))
1772 (tags (and (plist-get info :with-tags)
1773 (org-export-get-tags headline info)))
1774 (headline-label (or (org-element-property :custom-id headline)
1775 (concat "sec-" (mapconcat 'number-to-string
1776 headline-number "-"))))
1777 (format-function (cond
1778 ((functionp format-function) format-function)
1779 ((functionp org-html-format-headline-function)
1780 (function*
1781 (lambda (todo todo-type priority text tags
1782 &allow-other-keys)
1783 (funcall org-html-format-headline-function
1784 todo todo-type priority text tags))))
1785 (t 'org-html-format-headline))))
1786 (apply format-function
1787 todo todo-type priority text tags
1788 :headline-label headline-label :level level
1789 :section-number section-number extra-keys)))
1791 (defun org-html-headline (headline contents info)
1792 "Transcode an HEADLINE element from Org to HTML.
1793 CONTENTS holds the contents of the headline. INFO is a plist
1794 holding contextual information."
1795 ;; Empty contents?
1796 (setq contents (or contents ""))
1797 (let* ((numberedp (org-export-numbered-headline-p headline info))
1798 (level (org-export-get-relative-level headline info))
1799 (text (org-export-data (org-element-property :title headline) info))
1800 (todo (and (plist-get info :with-todo-keywords)
1801 (let ((todo (org-element-property :todo-keyword headline)))
1802 (and todo (org-export-data todo info)))))
1803 (todo-type (and todo (org-element-property :todo-type headline)))
1804 (tags (and (plist-get info :with-tags)
1805 (org-export-get-tags headline info)))
1806 (priority (and (plist-get info :with-priority)
1807 (org-element-property :priority headline)))
1808 (section-number (and (org-export-numbered-headline-p headline info)
1809 (mapconcat 'number-to-string
1810 (org-export-get-headline-number
1811 headline info) ".")))
1812 ;; Create the headline text.
1813 (full-text (org-html-format-headline--wrap headline info)))
1814 (cond
1815 ;; Case 1: This is a footnote section: ignore it.
1816 ((org-element-property :footnote-section-p headline) nil)
1817 ;; Case 2. This is a deep sub-tree: export it as a list item.
1818 ;; Also export as items headlines for which no section
1819 ;; format has been found.
1820 ((org-export-low-level-p headline info)
1821 ;; Build the real contents of the sub-tree.
1822 (let* ((type (if numberedp 'ordered 'unordered))
1823 (itemized-body (org-html-format-list-item
1824 contents type nil nil full-text)))
1825 (concat
1826 (and (org-export-first-sibling-p headline info)
1827 (org-html-begin-plain-list type))
1828 itemized-body
1829 (and (org-export-last-sibling-p headline info)
1830 (org-html-end-plain-list type)))))
1831 ;; Case 3. Standard headline. Export it as a section.
1833 (let* ((section-number (mapconcat 'number-to-string
1834 (org-export-get-headline-number
1835 headline info) "-"))
1836 (ids (remove 'nil
1837 (list (org-element-property :CUSTOM_ID headline)
1838 (concat "sec-" section-number)
1839 (org-element-property :ID headline))))
1840 (preferred-id (car ids))
1841 (extra-ids (cdr ids))
1842 (extra-class (org-element-property :html-container-class headline))
1843 (level1 (+ level (1- org-html-toplevel-hlevel))))
1844 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1845 (format "outline-container-%s"
1846 (or (org-element-property :custom-id headline)
1847 section-number))
1848 (concat (format "outline-%d" level1) (and extra-class " ")
1849 extra-class)
1850 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1851 level1
1852 preferred-id
1853 (mapconcat
1854 (lambda (x)
1855 (let ((id (org-export-solidify-link-text
1856 (if (org-uuidgen-p x) (concat "ID-" x)
1857 x))))
1858 (org-html--anchor id)))
1859 extra-ids "")
1860 full-text
1861 level1)
1862 contents))))))
1865 ;;;; Horizontal Rule
1867 (defun org-html-horizontal-rule (horizontal-rule contents info)
1868 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1869 CONTENTS is nil. INFO is a plist holding contextual information."
1870 "<hr/>")
1873 ;;;; Inline Src Block
1875 (defun org-html-inline-src-block (inline-src-block contents info)
1876 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1877 CONTENTS holds the contents of the item. INFO is a plist holding
1878 contextual information."
1879 (let* ((org-lang (org-element-property :language inline-src-block))
1880 (code (org-element-property :value inline-src-block)))
1881 (error "FIXME")))
1884 ;;;; Inlinetask
1886 (defun org-html-format-section (text class &optional id)
1887 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1888 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1890 (defun org-html-inlinetask (inlinetask contents info)
1891 "Transcode an INLINETASK element from Org to HTML.
1892 CONTENTS holds the contents of the block. INFO is a plist
1893 holding contextual information."
1894 (cond
1895 ;; If `org-html-format-inlinetask-function' is provided, call it
1896 ;; with appropriate arguments.
1897 ((functionp org-html-format-inlinetask-function)
1898 (let ((format-function
1899 (function*
1900 (lambda (todo todo-type priority text tags
1901 &key contents &allow-other-keys)
1902 (funcall org-html-format-inlinetask-function
1903 todo todo-type priority text tags contents)))))
1904 (org-html-format-headline--wrap
1905 inlinetask info format-function :contents contents)))
1906 ;; Otherwise, use a default template.
1907 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1908 (org-html-format-headline--wrap inlinetask info)
1909 contents))))
1912 ;;;; Italic
1914 (defun org-html-italic (italic contents info)
1915 "Transcode ITALIC from Org to HTML.
1916 CONTENTS is the text with italic markup. INFO is a plist holding
1917 contextual information."
1918 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
1921 ;;;; Item
1923 (defun org-html-checkbox (checkbox)
1924 (case checkbox (on "<code>[X]</code>")
1925 (off "<code>[&nbsp;]</code>")
1926 (trans "<code>[-]</code>")
1927 (t "")))
1929 (defun org-html-format-list-item (contents type checkbox
1930 &optional term-counter-id
1931 headline)
1932 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
1933 (concat
1934 (case type
1935 (ordered
1936 (let* ((counter term-counter-id)
1937 (extra (if counter (format " value=\"%s\"" counter) "")))
1938 (concat
1939 (format "<li%s>" extra)
1940 (when headline (concat headline "<br/>")))))
1941 (unordered
1942 (let* ((id term-counter-id)
1943 (extra (if id (format " id=\"%s\"" id) "")))
1944 (concat
1945 (format "<li%s>" extra)
1946 (when headline (concat headline "<br/>")))))
1947 (descriptive
1948 (let* ((term term-counter-id))
1949 (setq term (or term "(no term)"))
1950 ;; Check-boxes in descriptive lists are associated to tag.
1951 (concat (format "<dt> %s </dt>"
1952 (concat checkbox term))
1953 "<dd>"))))
1954 (unless (eq type 'descriptive) checkbox)
1955 contents
1956 (case type
1957 (ordered "</li>")
1958 (unordered "</li>")
1959 (descriptive "</dd>")))))
1961 (defun org-html-item (item contents info)
1962 "Transcode an ITEM element from Org to HTML.
1963 CONTENTS holds the contents of the item. INFO is a plist holding
1964 contextual information."
1965 (let* ((plain-list (org-export-get-parent item))
1966 (type (org-element-property :type plain-list))
1967 (counter (org-element-property :counter item))
1968 (checkbox (org-element-property :checkbox item))
1969 (tag (let ((tag (org-element-property :tag item)))
1970 (and tag (org-export-data tag info)))))
1971 (org-html-format-list-item
1972 contents type checkbox (or tag counter))))
1975 ;;;; Keyword
1977 (defun org-html-keyword (keyword contents info)
1978 "Transcode a KEYWORD element from Org to HTML.
1979 CONTENTS is nil. INFO is a plist holding contextual information."
1980 (let ((key (org-element-property :key keyword))
1981 (value (org-element-property :value keyword)))
1982 (cond
1983 ((string= key "HTML") value)
1984 ;; Invisible targets.
1985 ((string= key "TARGET") nil)
1986 ((string= key "TOC")
1987 (let ((value (downcase value)))
1988 (cond
1989 ((string-match "\\<headlines\\>" value)
1990 (let ((depth (or (and (string-match "[0-9]+" value)
1991 (string-to-number (match-string 0 value)))
1992 (plist-get info :with-toc))))
1993 (org-html-toc depth info)))
1994 ((string= "tables" value) "\\listoftables")
1995 ((string= "figures" value) "\\listoffigures")
1996 ((string= "listings" value)
1997 (cond
1998 ;; At the moment, src blocks with a caption are wrapped
1999 ;; into a figure environment.
2000 (t "\\listoffigures")))))))))
2003 ;;;; Latex Environment
2005 (defun org-html-format-latex (latex-frag processing-type)
2006 "Format LaTeX fragments into HTML."
2007 (let ((cache-relpath "") (cache-dir "") bfn)
2008 (unless (eq processing-type 'mathjax)
2009 (setq bfn (buffer-file-name)
2010 cache-relpath
2011 (concat "ltxpng/"
2012 (file-name-sans-extension
2013 (file-name-nondirectory bfn)))
2014 cache-dir (file-name-directory bfn)))
2015 (with-temp-buffer
2016 (insert latex-frag)
2017 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2018 nil nil processing-type)
2019 (buffer-string))))
2021 (defun org-html-latex-environment (latex-environment contents info)
2022 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2023 CONTENTS is nil. INFO is a plist holding contextual information."
2024 (let ((processing-type (plist-get info :with-latex))
2025 (latex-frag (org-remove-indentation
2026 (org-element-property :value latex-environment)))
2027 (caption (org-export-data
2028 (org-export-get-caption latex-environment) info))
2029 (attr nil) ; FIXME
2030 (label (org-element-property :name latex-environment)))
2031 (cond
2032 ((memq processing-type '(t mathjax))
2033 (org-html-format-latex latex-frag 'mathjax))
2034 ((eq processing-type 'dvipng)
2035 (let* ((formula-link (org-html-format-latex
2036 latex-frag processing-type)))
2037 (when (and formula-link
2038 (string-match "file:\\([^]]*\\)" formula-link))
2039 (org-html-format-inline-image
2040 (match-string 1 formula-link) caption label attr t))))
2041 (t latex-frag))))
2044 ;;;; Latex Fragment
2046 (defun org-html-latex-fragment (latex-fragment contents info)
2047 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2048 CONTENTS is nil. INFO is a plist holding contextual information."
2049 (let ((latex-frag (org-element-property :value latex-fragment))
2050 (processing-type (plist-get info :with-latex)))
2051 (case processing-type
2052 ((t mathjax)
2053 (org-html-format-latex latex-frag 'mathjax))
2054 (dvipng
2055 (let* ((formula-link (org-html-format-latex
2056 latex-frag processing-type)))
2057 (when (and formula-link
2058 (string-match "file:\\([^]]*\\)" formula-link))
2059 (org-html-format-inline-image
2060 (match-string 1 formula-link)))))
2061 (t latex-frag))))
2064 ;;;; Line Break
2066 (defun org-html-line-break (line-break contents info)
2067 "Transcode a LINE-BREAK object from Org to HTML.
2068 CONTENTS is nil. INFO is a plist holding contextual information."
2069 "<br/>\n")
2072 ;;;; Link
2074 (defun org-html-link--inline-image (link desc info)
2075 "Return HTML code for an inline image.
2076 LINK is the link pointing to the inline image. INFO is a plist
2077 used as a communication channel."
2078 (let* ((type (org-element-property :type link))
2079 (raw-path (org-element-property :path link))
2080 (path (cond ((member type '("http" "https"))
2081 (concat type ":" raw-path))
2082 ((file-name-absolute-p raw-path)
2083 (expand-file-name raw-path))
2084 (t raw-path)))
2085 (parent (org-export-get-parent-element link))
2086 (caption (org-export-data (org-export-get-caption parent) info))
2087 (label (org-element-property :name parent))
2088 ;; Retrieve latex attributes from the element around.
2089 (attr (let ((raw-attr
2090 (mapconcat #'identity
2091 (org-element-property :attr_html parent)
2092 " ")))
2093 (unless (string= raw-attr "") raw-attr))))
2094 ;; Now clear ATTR from any special keyword and set a default
2095 ;; value if nothing is left.
2096 (setq attr (if (not attr) "" (org-trim attr)))
2097 ;; Return proper string, depending on DISPOSITION.
2098 (org-html-format-inline-image
2099 path caption label attr (org-html-standalone-image-p link info))))
2101 (defvar org-html-standalone-image-predicate)
2102 (defun org-html-standalone-image-p (element info &optional predicate)
2103 "Test if ELEMENT is a standalone image for the purpose HTML export.
2104 INFO is a plist holding contextual information.
2106 Return non-nil, if ELEMENT is of type paragraph and it's sole
2107 content, save for whitespaces, is a link that qualifies as an
2108 inline image.
2110 Return non-nil, if ELEMENT is of type link and it's containing
2111 paragraph has no other content save for leading and trailing
2112 whitespaces.
2114 Return nil, otherwise.
2116 Bind `org-html-standalone-image-predicate' to constrain
2117 paragraph further. For example, to check for only captioned
2118 standalone images, do the following.
2120 \(setq org-html-standalone-image-predicate
2121 \(lambda \(paragraph\)
2122 \(org-element-property :caption paragraph\)\)\)"
2123 (let ((paragraph (case (org-element-type element)
2124 (paragraph element)
2125 (link (and (org-export-inline-image-p
2126 element org-html-inline-image-rules)
2127 (org-export-get-parent element)))
2128 (t nil))))
2129 (when (eq (org-element-type paragraph) 'paragraph)
2130 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2131 (functionp org-html-standalone-image-predicate)))
2132 (funcall org-html-standalone-image-predicate paragraph))
2133 (let ((contents (org-element-contents paragraph)))
2134 (loop for x in contents
2135 with inline-image-count = 0
2136 always (cond
2137 ((eq (org-element-type x) 'plain-text)
2138 (not (org-string-nw-p x)))
2139 ((eq (org-element-type x) 'link)
2140 (when (org-export-inline-image-p
2141 x org-html-inline-image-rules)
2142 (= (incf inline-image-count) 1)))
2143 (t nil))))))))
2145 (defun org-html-link (link desc info)
2146 "Transcode a LINK object from Org to HTML.
2148 DESC is the description part of the link, or the empty string.
2149 INFO is a plist holding contextual information. See
2150 `org-export-data'."
2151 (let* ((--link-org-files-as-html-maybe
2152 (function
2153 (lambda (raw-path info)
2154 "Treat links to `file.org' as links to `file.html', if needed.
2155 See `org-html-link-org-files-as-html'."
2156 (cond
2157 ((and org-html-link-org-files-as-html
2158 (string= ".org"
2159 (downcase (file-name-extension raw-path "."))))
2160 (concat (file-name-sans-extension raw-path) "."
2161 (plist-get info :html-extension)))
2162 (t raw-path)))))
2163 (type (org-element-property :type link))
2164 (raw-path (org-element-property :path link))
2165 ;; Ensure DESC really exists, or set it to nil.
2166 (desc (and (not (string= desc "")) desc))
2167 (path (cond
2168 ((member type '("http" "https" "ftp" "mailto"))
2169 (concat type ":" raw-path))
2170 ((string= type "file")
2171 ;; Treat links to ".org" files as ".html", if needed.
2172 (setq raw-path (funcall --link-org-files-as-html-maybe
2173 raw-path info))
2174 ;; If file path is absolute, prepend it with protocol
2175 ;; component - "file://".
2176 (if (not (file-name-absolute-p raw-path)) raw-path
2177 (concat "file://" (expand-file-name raw-path))))
2178 (t raw-path)))
2179 attributes protocol)
2180 ;; Extract attributes from parent's paragraph.
2181 (and (setq attributes
2182 (mapconcat
2183 'identity
2184 (let ((att (org-element-property
2185 :attr_html (org-export-get-parent-element link))))
2186 (unless (and desc att (string-match (regexp-quote (car att)) desc)) att))
2187 " "))
2188 (setq attributes (concat " " attributes)))
2190 (cond
2191 ;; Image file.
2192 ((and (or (eq t org-html-inline-images)
2193 (and org-html-inline-images (not desc)))
2194 (org-export-inline-image-p link org-html-inline-image-rules))
2195 (org-html-link--inline-image link desc info))
2196 ;; Radio target: Transcode target's contents and use them as
2197 ;; link's description.
2198 ((string= type "radio")
2199 (let ((destination (org-export-resolve-radio-link link info)))
2200 (when destination
2201 (format "<a href=\"#%s\"%s>%s</a>"
2202 (org-export-solidify-link-text path)
2203 attributes
2204 (org-export-data (org-element-contents destination) info)))))
2205 ;; Links pointing to an headline: Find destination and build
2206 ;; appropriate referencing command.
2207 ((member type '("custom-id" "fuzzy" "id"))
2208 (let ((destination (if (string= type "fuzzy")
2209 (org-export-resolve-fuzzy-link link info)
2210 (org-export-resolve-id-link link info))))
2211 (case (org-element-type destination)
2212 ;; ID link points to an external file.
2213 (plain-text
2214 (let ((fragment (concat "ID-" path))
2215 ;; Treat links to ".org" files as ".html", if needed.
2216 (path (funcall --link-org-files-as-html-maybe
2217 destination info)))
2218 (format "<a href=\"%s#%s\"%s>%s</a>"
2219 path fragment attributes (or desc destination))))
2220 ;; Fuzzy link points nowhere.
2221 ((nil)
2222 (format "<i>%s</i>"
2223 (or desc
2224 (org-export-data
2225 (org-element-property :raw-link link) info))))
2226 ;; Fuzzy link points to an invisible target.
2227 (keyword nil)
2228 ;; Link points to an headline.
2229 (headline
2230 (let ((href
2231 ;; What href to use?
2232 (cond
2233 ;; Case 1: Headline is linked via it's CUSTOM_ID
2234 ;; property. Use CUSTOM_ID.
2235 ((string= type "custom-id")
2236 (org-element-property :CUSTOM_ID destination))
2237 ;; Case 2: Headline is linked via it's ID property
2238 ;; or through other means. Use the default href.
2239 ((member type '("id" "fuzzy"))
2240 (format "sec-%s"
2241 (mapconcat 'number-to-string
2242 (org-export-get-headline-number
2243 destination info) "-")))
2244 (t (error "Shouldn't reach here"))))
2245 ;; What description to use?
2246 (desc
2247 ;; Case 1: Headline is numbered and LINK has no
2248 ;; description or LINK's description matches
2249 ;; headline's title. Display section number.
2250 (if (and (org-export-numbered-headline-p destination info)
2251 (or (not desc)
2252 (string= desc (org-element-property
2253 :raw-value destination))))
2254 (mapconcat 'number-to-string
2255 (org-export-get-headline-number
2256 destination info) ".")
2257 ;; Case 2: Either the headline is un-numbered or
2258 ;; LINK has a custom description. Display LINK's
2259 ;; description or headline's title.
2260 (or desc (org-export-data (org-element-property
2261 :title destination) info)))))
2262 (format "<a href=\"#%s\"%s>%s</a>"
2263 (org-export-solidify-link-text href) attributes desc)))
2264 ;; Fuzzy link points to a target. Do as above.
2266 (let ((path (org-export-solidify-link-text path)) number)
2267 (unless desc
2268 (setq number (cond
2269 ((org-html-standalone-image-p destination info)
2270 (org-export-get-ordinal
2271 (assoc 'link (org-element-contents destination))
2272 info 'link 'org-html-standalone-image-p))
2273 (t (org-export-get-ordinal destination info))))
2274 (setq desc (when number
2275 (if (atom number) (number-to-string number)
2276 (mapconcat 'number-to-string number ".")))))
2277 (format "<a href=\"#%s\"%s>%s</a>"
2278 path attributes (or desc "FIXME")))))))
2279 ;; Coderef: replace link with the reference name or the
2280 ;; equivalent line number.
2281 ((string= type "coderef")
2282 (let ((fragment (concat "coderef-" path)))
2283 (format "<a href=\"#%s\" %s%s>%s</a>"
2284 fragment
2285 (format (concat "class=\"coderef\""
2286 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2287 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2288 fragment fragment)
2289 attributes
2290 (format (org-export-get-coderef-format path desc)
2291 (org-export-resolve-coderef path info)))))
2292 ;; Link type is handled by a special function.
2293 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2294 (funcall protocol (org-link-unescape path) desc 'html))
2295 ;; External link with a description part.
2296 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2297 ;; External link without a description part.
2298 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2299 ;; No path, only description. Try to do something useful.
2300 (t (format "<i>%s</i>" desc)))))
2303 ;;;; Paragraph
2305 (defun org-html-paragraph (paragraph contents info)
2306 "Transcode a PARAGRAPH element from Org to HTML.
2307 CONTENTS is the contents of the paragraph, as a string. INFO is
2308 the plist used as a communication channel."
2309 (let* ((style nil) ; FIXME
2310 (class (cdr (assoc style '((footnote . "footnote")
2311 (verse . nil)))))
2312 (extra (if class (format " class=\"%s\"" class) ""))
2313 (parent (org-export-get-parent paragraph)))
2314 (cond
2315 ((and (eq (org-element-type parent) 'item)
2316 (= (org-element-property :begin paragraph)
2317 (org-element-property :contents-begin parent)))
2318 ;; leading paragraph in a list item have no tags
2319 contents)
2320 ((org-html-standalone-image-p paragraph info)
2321 ;; standalone image
2322 contents)
2323 (t (format "<p%s>\n%s</p>" extra contents)))))
2326 ;;;; Plain List
2328 (defun org-html-begin-plain-list (type &optional arg1)
2329 (case type
2330 (ordered
2331 (format "<ol class=\"org-ol\"%s>" (if arg1 ; FIXME
2332 (format " start=\"%d\"" arg1)
2333 "")))
2334 (unordered "<ul class=\"org-ul\">")
2335 (descriptive "<dl class=\"org-dl\">")))
2337 (defun org-html-end-plain-list (type)
2338 (case type
2339 (ordered "</ol>")
2340 (unordered "</ul>")
2341 (descriptive "</dl>")))
2343 (defun org-html-plain-list (plain-list contents info)
2344 "Transcode a PLAIN-LIST element from Org to HTML.
2345 CONTENTS is the contents of the list. INFO is a plist holding
2346 contextual information."
2347 (let* (arg1 ;; FIXME
2348 (type (org-element-property :type plain-list)))
2349 (format "%s\n%s%s"
2350 (org-html-begin-plain-list type)
2351 contents (org-html-end-plain-list type))))
2353 ;;;; Plain Text
2355 (defun org-html-convert-special-strings (string)
2356 "Convert special characters in STRING to HTML."
2357 (let ((all org-html-special-string-regexps)
2358 e a re rpl start)
2359 (while (setq a (pop all))
2360 (setq re (car a) rpl (cdr a) start 0)
2361 (while (string-match re string start)
2362 (setq string (replace-match rpl t nil string))))
2363 string))
2365 (defun org-html-encode-plain-text (text)
2366 "Convert plain text characters to HTML equivalent.
2367 Possible conversions are set in `org-export-html-protect-char-alist'."
2368 (mapc
2369 (lambda (pair)
2370 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2371 org-html-protect-char-alist)
2372 text)
2374 (defun org-html-plain-text (text info)
2375 "Transcode a TEXT string from Org to HTML.
2376 TEXT is the string to transcode. INFO is a plist holding
2377 contextual information."
2378 (let ((output text))
2379 ;; Protect following characters: <, >, &.
2380 (setq output (org-html-encode-plain-text output))
2381 ;; Handle smart quotes. Be sure to provide original string since
2382 ;; OUTPUT may have been modified.
2383 (when (plist-get info :with-smart-quotes)
2384 (setq output (org-export-activate-smart-quotes output :html info text)))
2385 ;; Handle special strings.
2386 (when (plist-get info :with-special-strings)
2387 (setq output (org-html-convert-special-strings output)))
2388 ;; Handle break preservation if required.
2389 (when (plist-get info :preserve-breaks)
2390 (setq output
2391 (replace-regexp-in-string
2392 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2393 ;; Return value.
2394 output))
2397 ;; Planning
2399 (defun org-html-planning (planning contents info)
2400 "Transcode a PLANNING element from Org to HTML.
2401 CONTENTS is nil. INFO is a plist used as a communication
2402 channel."
2403 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2404 (format
2405 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2406 (mapconcat
2407 'identity
2408 (delq nil
2409 (list
2410 (let ((closed (org-element-property :closed planning)))
2411 (when closed
2412 (format span-fmt org-closed-string
2413 (org-translate-time
2414 (org-element-property :raw-value closed)))))
2415 (let ((deadline (org-element-property :deadline planning)))
2416 (when deadline
2417 (format span-fmt org-deadline-string
2418 (org-translate-time
2419 (org-element-property :raw-value deadline)))))
2420 (let ((scheduled (org-element-property :scheduled planning)))
2421 (when scheduled
2422 (format span-fmt org-scheduled-string
2423 (org-translate-time
2424 (org-element-property :raw-value scheduled)))))))
2425 " "))))
2428 ;;;; Property Drawer
2430 (defun org-html-property-drawer (property-drawer contents info)
2431 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2432 CONTENTS is nil. INFO is a plist holding contextual
2433 information."
2434 ;; The property drawer isn't exported but we want separating blank
2435 ;; lines nonetheless.
2439 ;;;; Quote Block
2441 (defun org-html-quote-block (quote-block contents info)
2442 "Transcode a QUOTE-BLOCK element from Org to HTML.
2443 CONTENTS holds the contents of the block. INFO is a plist
2444 holding contextual information."
2445 (format "<blockquote>\n%s</blockquote>" contents))
2448 ;;;; Quote Section
2450 (defun org-html-quote-section (quote-section contents info)
2451 "Transcode a QUOTE-SECTION element from Org to HTML.
2452 CONTENTS is nil. INFO is a plist holding contextual information."
2453 (let ((value (org-remove-indentation
2454 (org-element-property :value quote-section))))
2455 (when value (format "<pre>\n%s</pre>" value))))
2458 ;;;; Section
2460 (defun org-html-section (section contents info)
2461 "Transcode a SECTION element from Org to HTML.
2462 CONTENTS holds the contents of the section. INFO is a plist
2463 holding contextual information."
2464 (let ((parent (org-export-get-parent-headline section)))
2465 ;; Before first headline: no container, just return CONTENTS.
2466 (if (not parent) contents
2467 ;; Get div's class and id references.
2468 (let* ((class-num (+ (org-export-get-relative-level parent info)
2469 (1- org-html-toplevel-hlevel)))
2470 (section-number
2471 (mapconcat
2472 'number-to-string
2473 (org-export-get-headline-number parent info) "-")))
2474 ;; Build return value.
2475 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2476 class-num
2477 (or (org-element-property :CUSTOM_ID parent) section-number)
2478 contents)))))
2480 ;;;; Radio Target
2482 (defun org-html-radio-target (radio-target text info)
2483 "Transcode a RADIO-TARGET object from Org to HTML.
2484 TEXT is the text of the target. INFO is a plist holding
2485 contextual information."
2486 (let ((id (org-export-solidify-link-text
2487 (org-element-property :value radio-target))))
2488 (org-html--anchor id text)))
2491 ;;;; Special Block
2493 (defun org-html-special-block (special-block contents info)
2494 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2495 CONTENTS holds the contents of the block. INFO is a plist
2496 holding contextual information."
2497 (format "<div class=\"%s\">\n%s\n</div>"
2498 (downcase (org-element-property :type special-block))
2499 contents))
2502 ;;;; Src Block
2504 (defun org-html-src-block (src-block contents info)
2505 "Transcode a SRC-BLOCK element from Org to HTML.
2506 CONTENTS holds the contents of the item. INFO is a plist holding
2507 contextual information."
2508 (if (org-export-read-attribute :attr_html src-block :textarea)
2509 (org-html--textarea-block src-block)
2510 (let ((lang (org-element-property :language src-block))
2511 (caption (org-export-get-caption src-block))
2512 (code (org-html-format-code src-block info)))
2513 (if (not lang) (format "<pre class=\"example\">\n%s</pre>" code)
2514 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
2515 (if (not caption) ""
2516 (format "<label class=\"org-src-name\">%s</label>"
2517 (org-export-data caption info)))
2518 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code))))))
2521 ;;;; Statistics Cookie
2523 (defun org-html-statistics-cookie (statistics-cookie contents info)
2524 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2525 CONTENTS is nil. INFO is a plist holding contextual information."
2526 (let ((cookie-value (org-element-property :value statistics-cookie)))
2527 (format "<code>%s</code>" cookie-value)))
2530 ;;;; Strike-Through
2532 (defun org-html-strike-through (strike-through contents info)
2533 "Transcode STRIKE-THROUGH from Org to HTML.
2534 CONTENTS is the text with strike-through markup. INFO is a plist
2535 holding contextual information."
2536 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2537 contents))
2540 ;;;; Subscript
2542 (defun org-html-subscript (subscript contents info)
2543 "Transcode a SUBSCRIPT object from Org to HTML.
2544 CONTENTS is the contents of the object. INFO is a plist holding
2545 contextual information."
2546 (format "<sub>%s</sub>" contents))
2549 ;;;; Superscript
2551 (defun org-html-superscript (superscript contents info)
2552 "Transcode a SUPERSCRIPT object from Org to HTML.
2553 CONTENTS is the contents of the object. INFO is a plist holding
2554 contextual information."
2555 (format "<sup>%s</sup>" contents))
2558 ;;;; Tabel Cell
2560 (defun org-html-table-cell (table-cell contents info)
2561 "Transcode a TABLE-CELL element from Org to HTML.
2562 CONTENTS is nil. INFO is a plist used as a communication
2563 channel."
2564 (let* ((table-row (org-export-get-parent table-cell))
2565 (table (org-export-get-parent-table table-cell))
2566 (cell-attrs
2567 (if (not org-html-table-align-individual-fields) ""
2568 (format (if (and (boundp 'org-html-format-table-no-css)
2569 org-html-format-table-no-css)
2570 " align=\"%s\"" " class=\"%s\"")
2571 (org-export-table-cell-alignment table-cell info)))))
2572 (when (or (not contents) (string= "" (org-trim contents)))
2573 (setq contents "&nbsp;"))
2574 (cond
2575 ((and (org-export-table-has-header-p table info)
2576 (= 1 (org-export-table-row-group table-row info)))
2577 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2578 contents (cdr org-html-table-header-tags)))
2579 ((and org-html-table-use-header-tags-for-first-column
2580 (zerop (cdr (org-export-table-cell-address table-cell info))))
2581 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2582 contents (cdr org-html-table-header-tags)))
2583 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2584 contents (cdr org-html-table-data-tags))))))
2587 ;;;; Table Row
2589 (defun org-html-table-row (table-row contents info)
2590 "Transcode a TABLE-ROW element from Org to HTML.
2591 CONTENTS is the contents of the row. INFO is a plist used as a
2592 communication channel."
2593 ;; Rules are ignored since table separators are deduced from
2594 ;; borders of the current row.
2595 (when (eq (org-element-property :type table-row) 'standard)
2596 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2597 (rowgroup-tags
2598 (cond
2599 ;; Case 1: Row belongs to second or subsequent rowgroups.
2600 ((not (= 1 (org-export-table-row-group table-row info)))
2601 '("<tbody>" . "\n</tbody>"))
2602 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2603 ((org-export-table-has-header-p
2604 (org-export-get-parent-table table-row) info)
2605 '("<thead>" . "\n</thead>"))
2606 ;; Case 2: Row is from first and only row group.
2607 (t '("<tbody>" . "\n</tbody>")))))
2608 (concat
2609 ;; Begin a rowgroup?
2610 (when (org-export-table-row-starts-rowgroup-p table-row info)
2611 (car rowgroup-tags))
2612 ;; Actual table row
2613 (concat "\n" (eval (car org-html-table-row-tags))
2614 contents
2615 "\n"
2616 (eval (cdr org-html-table-row-tags)))
2617 ;; End a rowgroup?
2618 (when (org-export-table-row-ends-rowgroup-p table-row info)
2619 (cdr rowgroup-tags))))))
2622 ;;;; Table
2624 (defun org-html-table-first-row-data-cells (table info)
2625 (let ((table-row
2626 (org-element-map table 'table-row
2627 (lambda (row)
2628 (unless (eq (org-element-property :type row) 'rule) row))
2629 info 'first-match))
2630 (special-column-p (org-export-table-has-special-column-p table)))
2631 (if (not special-column-p) (org-element-contents table-row)
2632 (cdr (org-element-contents table-row)))))
2634 (defun org-html-table--table.el-table (table info)
2635 (when (eq (org-element-property :type table) 'table.el)
2636 (require 'table)
2637 (let ((outbuf (with-current-buffer
2638 (get-buffer-create "*org-export-table*")
2639 (erase-buffer) (current-buffer))))
2640 (with-temp-buffer
2641 (insert (org-element-property :value table))
2642 (goto-char 1)
2643 (re-search-forward "^[ \t]*|[^|]" nil t)
2644 (table-generate-source 'html outbuf))
2645 (with-current-buffer outbuf
2646 (prog1 (org-trim (buffer-string))
2647 (kill-buffer) )))))
2649 (defun org-html-table (table contents info)
2650 "Transcode a TABLE element from Org to HTML.
2651 CONTENTS is the contents of the table. INFO is a plist holding
2652 contextual information."
2653 (case (org-element-property :type table)
2654 ;; Case 1: table.el table. Convert it using appropriate tools.
2655 (table.el (org-html-table--table.el-table table info))
2656 ;; Case 2: Standard table.
2658 (let* ((label (org-element-property :name table))
2659 (caption (org-export-get-caption table))
2660 (attributes (mapconcat #'identity
2661 (org-element-property :attr_html table)
2662 " "))
2663 (alignspec
2664 (if (and (boundp 'org-html-format-table-no-css)
2665 org-html-format-table-no-css)
2666 "align=\"%s\"" "class=\"%s\""))
2667 (table-column-specs
2668 (function
2669 (lambda (table info)
2670 (mapconcat
2671 (lambda (table-cell)
2672 (let ((alignment (org-export-table-cell-alignment
2673 table-cell info)))
2674 (concat
2675 ;; Begin a colgroup?
2676 (when (org-export-table-cell-starts-colgroup-p
2677 table-cell info)
2678 "\n<colgroup>")
2679 ;; Add a column. Also specify it's alignment.
2680 (format "\n<col %s/>" (format alignspec alignment))
2681 ;; End a colgroup?
2682 (when (org-export-table-cell-ends-colgroup-p
2683 table-cell info)
2684 "\n</colgroup>"))))
2685 (org-html-table-first-row-data-cells table info) "\n"))))
2686 (table-attributes
2687 (let ((table-tag (plist-get info :html-table-tag)))
2688 (concat
2689 (and (string-match "<table\\(.*\\)>" table-tag)
2690 (match-string 1 table-tag))
2691 (and label (format " id=\"%s\""
2692 (org-export-solidify-link-text label)))
2693 (unless (string= attributes "")
2694 (concat " " attributes))))))
2695 ;; Remove last blank line.
2696 (setq contents (substring contents 0 -1))
2697 (format "<table%s>\n%s\n%s\n%s\n</table>"
2698 table-attributes
2699 (if (not caption) ""
2700 (format "<caption>%s</caption>"
2701 (org-export-data caption info)))
2702 (funcall table-column-specs table info)
2703 contents)))))
2706 ;;;; Target
2708 (defun org-html-target (target contents info)
2709 "Transcode a TARGET object from Org to HTML.
2710 CONTENTS is nil. INFO is a plist holding contextual
2711 information."
2712 (let ((id (org-export-solidify-link-text
2713 (org-element-property :value target))))
2714 (org-html--anchor id)))
2717 ;;;; Timestamp
2719 (defun org-html-timestamp (timestamp contents info)
2720 "Transcode a TIMESTAMP object from Org to HTML.
2721 CONTENTS is nil. INFO is a plist holding contextual
2722 information."
2723 (let ((value (org-html-plain-text
2724 (org-timestamp-translate timestamp) info)))
2725 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2726 (replace-regexp-in-string "--" "&ndash;" value))))
2729 ;;;; Underline
2731 (defun org-html-underline (underline contents info)
2732 "Transcode UNDERLINE from Org to HTML.
2733 CONTENTS is the text with underline markup. INFO is a plist
2734 holding contextual information."
2735 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2736 contents))
2739 ;;;; Verbatim
2741 (defun org-html-verbatim (verbatim contents info)
2742 "Transcode VERBATIM from Org to HTML.
2743 CONTENTS is nil. INFO is a plist holding contextual
2744 information."
2745 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2746 (org-element-property :value verbatim)))
2749 ;;;; Verse Block
2751 (defun org-html-verse-block (verse-block contents info)
2752 "Transcode a VERSE-BLOCK element from Org to HTML.
2753 CONTENTS is verse block contents. INFO is a plist holding
2754 contextual information."
2755 ;; Replace each newline character with line break. Also replace
2756 ;; each blank line with a line break.
2757 (setq contents (replace-regexp-in-string
2758 "^ *\\\\\\\\$" "<br/>\n"
2759 (replace-regexp-in-string
2760 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2761 ;; Replace each white space at beginning of a line with a
2762 ;; non-breaking space.
2763 (while (string-match "^[ \t]+" contents)
2764 (let* ((num-ws (length (match-string 0 contents)))
2765 (ws (let (out) (dotimes (i num-ws out)
2766 (setq out (concat out "&nbsp;"))))))
2767 (setq contents (replace-match ws nil t contents))))
2768 (format "<p class=\"verse\">\n%s</p>" contents))
2772 ;;; Filter Functions
2774 (defun org-html-final-function (contents backend info)
2775 (if (not org-html-pretty-output) contents
2776 (with-temp-buffer
2777 (html-mode)
2778 (insert contents)
2779 (indent-region (point-min) (point-max))
2780 (buffer-substring-no-properties (point-min) (point-max)))))
2784 ;;; End-user functions
2786 ;;;###autoload
2787 (defun org-html-export-as-html
2788 (&optional async subtreep visible-only body-only ext-plist)
2789 "Export current buffer to an HTML buffer.
2791 If narrowing is active in the current buffer, only export its
2792 narrowed part.
2794 If a region is active, export that region.
2796 A non-nil optional argument ASYNC means the process should happen
2797 asynchronously. The resulting buffer should be accessible
2798 through the `org-export-stack' interface.
2800 When optional argument SUBTREEP is non-nil, export the sub-tree
2801 at point, extracting information from the headline properties
2802 first.
2804 When optional argument VISIBLE-ONLY is non-nil, don't export
2805 contents of hidden elements.
2807 When optional argument BODY-ONLY is non-nil, only write code
2808 between \"<body>\" and \"</body>\" tags.
2810 EXT-PLIST, when provided, is a property list with external
2811 parameters overriding Org default settings, but still inferior to
2812 file-local settings.
2814 Export is done in a buffer named \"*Org HTML Export*\", which
2815 will be displayed when `org-export-show-temporary-export-buffer'
2816 is non-nil."
2817 (interactive)
2818 (if async
2819 (org-export-async-start
2820 (lambda (output)
2821 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2822 (erase-buffer)
2823 (insert output)
2824 (goto-char (point-min))
2825 (funcall org-html-display-buffer-mode)
2826 (org-export-add-to-stack (current-buffer) 'html)))
2827 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2828 (let ((outbuf (org-export-to-buffer
2829 'html "*Org HTML Export*"
2830 subtreep visible-only body-only ext-plist)))
2831 ;; Set major mode.
2832 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2833 (when org-export-show-temporary-export-buffer
2834 (switch-to-buffer-other-window outbuf)))))
2836 ;;;###autoload
2837 (defun org-html-export-to-html
2838 (&optional async subtreep visible-only body-only ext-plist)
2839 "Export current buffer to a HTML file.
2841 If narrowing is active in the current buffer, only export its
2842 narrowed part.
2844 If a region is active, export that region.
2846 A non-nil optional argument ASYNC means the process should happen
2847 asynchronously. The resulting file should be accessible through
2848 the `org-export-stack' interface.
2850 When optional argument SUBTREEP is non-nil, export the sub-tree
2851 at point, extracting information from the headline properties
2852 first.
2854 When optional argument VISIBLE-ONLY is non-nil, don't export
2855 contents of hidden elements.
2857 When optional argument BODY-ONLY is non-nil, only write code
2858 between \"<body>\" and \"</body>\" tags.
2860 EXT-PLIST, when provided, is a property list with external
2861 parameters overriding Org default settings, but still inferior to
2862 file-local settings.
2864 Return output file's name."
2865 (interactive)
2866 (let* ((extension (concat "." org-html-extension))
2867 (file (org-export-output-file-name extension subtreep))
2868 (org-export-coding-system org-html-coding-system))
2869 (if async
2870 (org-export-async-start
2871 (lambda (f) (org-export-add-to-stack f 'html))
2872 (let ((org-export-coding-system org-html-coding-system))
2873 `(expand-file-name
2874 (org-export-to-file
2875 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2876 (let ((org-export-coding-system org-html-coding-system))
2877 (org-export-to-file
2878 'html file subtreep visible-only body-only ext-plist)))))
2880 ;;;###autoload
2881 (defun org-html-publish-to-html (plist filename pub-dir)
2882 "Publish an org file to HTML.
2884 FILENAME is the filename of the Org file to be published. PLIST
2885 is the property list for the given project. PUB-DIR is the
2886 publishing directory.
2888 Return output file name."
2889 (org-publish-org-to 'html filename ".html" plist pub-dir))
2893 ;;; FIXME
2895 ;;;; org-format-table-html
2896 ;;;; org-format-org-table-html
2897 ;;;; org-format-table-table-html
2898 ;;;; org-table-number-fraction
2899 ;;;; org-table-number-regexp
2900 ;;;; org-html-table-caption-above
2902 ;;;; org-html-with-timestamp
2903 ;;;; org-html-html-helper-timestamp
2905 ;;;; org-html-toplevel-hlevel
2906 ;;;; org-html-special-string-regexps
2907 ;;;; org-html-inline-images
2908 ;;;; org-html-inline-image-extensions
2909 ;;;; org-html-protect-char-alist
2910 ;;;; org-html-table-use-header-tags-for-first-column
2911 ;;;; org-html-todo-kwd-class-prefix
2912 ;;;; org-html-tag-class-prefix
2913 ;;;; org-html-footnote-separator
2915 ;;;; org-export-preferred-target-alist
2916 ;;;; org-export-solidify-link-text
2917 ;;;; class for anchors
2918 ;;;; org-export-with-section-numbers, body-only
2919 ;;;; org-export-mark-todo-in-toc
2921 ;;;; org-html-format-org-link
2922 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
2923 ;;;; alt = (file-name-nondirectory path)
2925 ;;;; org-export-time-stamp-file'
2927 (provide 'ox-html)
2929 ;; Local variables:
2930 ;; generated-autoload-file: "org-loaddefs.el"
2931 ;; End:
2933 ;;; ox-html.el ends here