ox-ascii/ox-latex/ox-html: Make use of optional title in toc
[org-mode.git] / lisp / ox-html.el
blobd9799094eb69281df183b32889fd3bece0169b40
1 ;;; ox-html.el --- HTML Back-End for Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; GNU Emacs is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a HTML back-end for Org generic exporter.
25 ;; To test it, run:
27 ;; M-x org-export-as-html
29 ;; in an Org mode buffer. See ox.el for more details on how this
30 ;; exporter works.
32 ;;; Code:
34 ;;; Dependencies
36 (require 'ox)
37 (require 'ox-publish)
38 (require 'format-spec)
39 (eval-when-compile (require 'cl) (require 'table))
43 ;;; Function Declarations
45 (declare-function org-id-find-id-file "org-id" (id))
46 (declare-function htmlize-region "ext:htmlize" (beg end))
47 (declare-function org-pop-to-buffer-same-window
48 "org-compat" (&optional buffer-or-name norecord label))
51 ;;; Define Back-End
53 (org-export-define-backend html
54 ((bold . org-html-bold)
55 (center-block . org-html-center-block)
56 (clock . org-html-clock)
57 (code . org-html-code)
58 (drawer . org-html-drawer)
59 (dynamic-block . org-html-dynamic-block)
60 (entity . org-html-entity)
61 (example-block . org-html-example-block)
62 (export-block . org-html-export-block)
63 (export-snippet . org-html-export-snippet)
64 (fixed-width . org-html-fixed-width)
65 (footnote-definition . org-html-footnote-definition)
66 (footnote-reference . org-html-footnote-reference)
67 (headline . org-html-headline)
68 (horizontal-rule . org-html-horizontal-rule)
69 (inline-src-block . org-html-inline-src-block)
70 (inlinetask . org-html-inlinetask)
71 (inner-template . org-html-inner-template)
72 (italic . org-html-italic)
73 (item . org-html-item)
74 (keyword . org-html-keyword)
75 (latex-environment . org-html-latex-environment)
76 (latex-fragment . org-html-latex-fragment)
77 (line-break . org-html-line-break)
78 (link . org-html-link)
79 (paragraph . org-html-paragraph)
80 (plain-list . org-html-plain-list)
81 (plain-text . org-html-plain-text)
82 (planning . org-html-planning)
83 (property-drawer . org-html-property-drawer)
84 (quote-block . org-html-quote-block)
85 (quote-section . org-html-quote-section)
86 (radio-target . org-html-radio-target)
87 (section . org-html-section)
88 (special-block . org-html-special-block)
89 (src-block . org-html-src-block)
90 (statistics-cookie . org-html-statistics-cookie)
91 (strike-through . org-html-strike-through)
92 (subscript . org-html-subscript)
93 (superscript . org-html-superscript)
94 (table . org-html-table)
95 (table-cell . org-html-table-cell)
96 (table-row . org-html-table-row)
97 (target . org-html-target)
98 (template . org-html-template)
99 (timestamp . org-html-timestamp)
100 (underline . org-html-underline)
101 (verbatim . org-html-verbatim)
102 (verse-block . org-html-verse-block))
103 :export-block "HTML"
104 :filters-alist ((:filter-final-output . org-html-final-function))
105 :menu-entry
106 (?h "Export to HTML"
107 ((?H "As HTML buffer" org-html-export-as-html)
108 (?h "As HTML file" org-html-export-to-html)
109 (?o "As HTML file and open"
110 (lambda (a s v b)
111 (if a (org-html-export-to-html t s v b)
112 (org-open-file (org-html-export-to-html nil s v b)))))))
113 :options-alist
114 ((:html-extension nil nil org-html-extension)
115 (:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
116 (:html-link-up "HTML_LINK_UP" nil org-html-link-up)
117 (:html-mathjax "HTML_MATHJAX" nil "" space)
118 (:html-postamble nil "html-postamble" org-html-postamble)
119 (:html-preamble nil "html-preamble" org-html-preamble)
120 (:html-style nil nil org-html-style)
121 (:html-style-extra "HTML_STYLE" nil org-html-style-extra newline)
122 (:html-style-include-default nil nil org-html-style-include-default)
123 (:html-style-include-scripts nil nil org-html-style-include-scripts)
124 (:html-table-tag nil nil org-html-table-tag)
125 ;; 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 a 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-html
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-html
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-html
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-html
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-html
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 "Return innards of a table of contents, as a string.
1121 TOC-ENTRIES is an alist where key is a headline title, as
1122 a string, and value is its relative level, as an integer."
1123 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1124 (start-level prev-level))
1125 (concat
1126 (mapconcat
1127 (lambda (entry)
1128 (let ((headline (nth 0 entry))
1129 (level (nth 1 entry)))
1130 (concat
1131 (let* ((cnt (- level prev-level))
1132 (times (if (> cnt 0) (1- cnt) (- cnt)))
1133 rtn)
1134 (setq prev-level level)
1135 (concat
1136 (org-html--make-string
1137 times (cond ((> cnt 0) "\n<ul>\n<li>")
1138 ((< cnt 0) "</li>\n</ul>\n")))
1139 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1140 headline)))
1141 toc-entries "")
1142 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1144 (defun org-html--format-toc-headline (headline info)
1145 "Return an appropriate table of contents entry for HEADLINE.
1146 INFO is a plist used as a communication channel."
1147 (let* ((headline-number (org-export-get-headline-number headline info))
1148 (section-number
1149 (and (not (org-export-low-level-p headline info))
1150 (org-export-numbered-headline-p headline info)
1151 (concat (mapconcat 'number-to-string headline-number ".") ". ")))
1152 (tags (and (eq (plist-get info :with-tags) t)
1153 (org-export-get-tags headline info))))
1154 (format "<a href=\"#%s\">%s</a>"
1155 ;; Label.
1156 (org-export-solidify-link-text
1157 (or (org-element-property :CUSTOM_ID headline)
1158 (concat "sec-" (mapconcat 'number-to-string
1159 headline-number "-"))))
1160 ;; Body.
1161 (concat section-number
1162 (org-export-data
1163 (or (org-export-get-optional-title headline info)
1164 (org-element-property :title headline))
1165 info)
1166 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags)))))
1168 (defun org-html-toc (depth info)
1169 "Build table of contents.
1170 DEPTH is an integer specifying the depth of the table. INFO is
1171 a plist used as a communication channel. Return nil if table of
1172 contents is empty."
1173 (let ((toc-entries
1174 (mapcar (lambda (headline)
1175 (list (org-html--format-toc-headline headline info)
1176 (org-export-get-relative-level headline info)))
1177 (org-export-collect-headlines info depth))))
1178 (when toc-entries
1179 (concat "<div id=\"table-of-contents\">\n"
1180 (format "<h%d>%s</h%d>\n"
1181 org-html-toplevel-hlevel
1182 (org-html--translate "Table of Contents" info)
1183 org-html-toplevel-hlevel)
1184 "<div id=\"text-table-of-contents\">"
1185 (org-html--toc-text toc-entries)
1186 "</div>\n"
1187 "</div>\n"))))
1189 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1190 "Turn todo keyword into a valid class name.
1191 Replaces invalid characters with \"_\"."
1192 (save-match-data
1193 (while (string-match "[^a-zA-Z0-9_]" kwd)
1194 (setq kwd (replace-match "_" t t kwd))))
1195 kwd)
1197 (defun org-html-format-footnote-reference (n def refcnt)
1198 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1199 (format org-html-footnote-format
1200 (let* ((id (format "fnr.%s%s" n extra))
1201 (href (format " href=\"#fn.%s\"" n))
1202 (attributes (concat " class=\"footref\"" href)))
1203 (org-html--anchor id n attributes)))))
1205 (defun org-html-format-footnotes-section (section-name definitions)
1206 (if (not definitions) ""
1207 (format org-html-footnotes-section section-name definitions)))
1209 (defun org-html-format-footnote-definition (fn)
1210 (let ((n (car fn)) (def (cdr fn)))
1211 (format
1212 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1213 (format org-html-footnote-format
1214 (let* ((id (format "fn.%s" n))
1215 (href (format " href=\"#fnr.%s\"" n))
1216 (attributes (concat " class=\"footnum\"" href)))
1217 (org-html--anchor id n attributes)))
1218 def)))
1220 (defun org-html-footnote-section (info)
1221 (let* ((fn-alist (org-export-collect-footnote-definitions
1222 (plist-get info :parse-tree) info))
1224 (fn-alist
1225 (loop for (n type raw) in fn-alist collect
1226 (cons n (if (eq (org-element-type raw) 'org-data)
1227 (org-trim (org-export-data raw info))
1228 (format "<p>%s</p>"
1229 (org-trim (org-export-data raw info))))))))
1230 (when fn-alist
1231 (org-html-format-footnotes-section
1232 (org-html--translate "Footnotes" info)
1233 (format
1234 "<table>\n%s\n</table>\n"
1235 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1239 ;;; Template
1241 (defun org-html--build-meta-info (info)
1242 "Return meta tags for exported document.
1243 INFO is a plist used as a communication channel."
1244 (let* ((title (org-export-data (plist-get info :title) info))
1245 (author (and (plist-get info :with-author)
1246 (let ((auth (plist-get info :author)))
1247 (and auth (org-export-data auth info)))))
1248 (date (and (plist-get info :with-date)
1249 (let ((date (plist-get info :date)))
1250 (and date (org-export-data date info)))))
1251 (description (plist-get info :description))
1252 (keywords (plist-get info :keywords)))
1253 (concat
1254 (format "<title>%s</title>\n" title)
1255 (format
1256 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1257 (or (and org-html-coding-system
1258 (fboundp 'coding-system-get)
1259 (coding-system-get org-html-coding-system 'mime-charset))
1260 "iso-8859-1"))
1261 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1262 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1263 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1264 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1265 (and description
1266 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1267 (and keywords
1268 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1270 (defun org-html--build-style (info)
1271 "Return style information for exported document.
1272 INFO is a plist used as a communication channel."
1273 (org-element-normalize-string
1274 (concat
1275 (when (plist-get info :html-style-include-default) org-html-style-default)
1276 (org-element-normalize-string (plist-get info :html-style))
1277 (org-element-normalize-string (plist-get info :html-style-extra))
1278 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1280 (defun org-html--build-mathjax-config (info)
1281 "Insert the user setup into the mathjax template.
1282 INFO is a plist used as a communication channel."
1283 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1284 (org-element-map (plist-get info :parse-tree)
1285 '(latex-fragment latex-environment) 'identity info t))
1286 (let ((template org-html-mathjax-template)
1287 (options org-html-mathjax-options)
1288 (in-buffer (or (plist-get info :html-mathjax) ""))
1289 name val (yes " ") (no "// ") x)
1290 (mapc
1291 (lambda (e)
1292 (setq name (car e) val (nth 1 e))
1293 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1294 (setq val (car (read-from-string
1295 (substring in-buffer (match-end 0))))))
1296 (if (not (stringp val)) (setq val (format "%s" val)))
1297 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1298 (setq template (replace-match val t t template))))
1299 options)
1300 (setq val (nth 1 (assq 'mathml options)))
1301 (if (string-match (concat "\\<mathml:") in-buffer)
1302 (setq val (car (read-from-string
1303 (substring in-buffer (match-end 0))))))
1304 ;; Exchange prefixes depending on mathml setting.
1305 (if (not val) (setq x yes yes no no x))
1306 ;; Replace cookies to turn on or off the config/jax lines.
1307 (if (string-match ":MMLYES:" template)
1308 (setq template (replace-match yes t t template)))
1309 (if (string-match ":MMLNO:" template)
1310 (setq template (replace-match no t t template)))
1311 ;; Return the modified template.
1312 (org-element-normalize-string template))))
1314 (defun org-html--build-preamble (info)
1315 "Return document preamble as a string, or nil.
1316 INFO is a plist used as a communication channel."
1317 (let ((preamble (plist-get info :html-preamble)))
1318 (when preamble
1319 (let ((preamble-contents
1320 (if (functionp preamble) (funcall preamble info)
1321 (let ((title (org-export-data (plist-get info :title) info))
1322 (date (if (not (plist-get info :with-date)) ""
1323 (org-export-data (plist-get info :date) info)))
1324 (author (if (not (plist-get info :with-author)) ""
1325 (org-export-data (plist-get info :author) info)))
1326 (email (if (not (plist-get info :with-email)) ""
1327 (plist-get info :email))))
1328 (if (stringp preamble)
1329 (format-spec preamble
1330 `((?t . ,title) (?a . ,author)
1331 (?d . ,date) (?e . ,email)))
1332 (format-spec
1333 (or (cadr (assoc (plist-get info :language)
1334 org-html-preamble-format))
1335 (cadr (assoc "en" org-html-preamble-format)))
1336 `((?t . ,title) (?a . ,author)
1337 (?d . ,date) (?e . ,email))))))))
1338 (when (org-string-nw-p preamble-contents)
1339 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1340 (org-element-normalize-string preamble-contents)
1341 "</div>\n"))))))
1343 (defun org-html--build-postamble (info)
1344 "Return document postamble as a string, or nil.
1345 INFO is a plist used as a communication channel."
1346 (let ((postamble (plist-get info :html-postamble)))
1347 (when postamble
1348 (let ((postamble-contents
1349 (if (functionp postamble) (funcall postamble info)
1350 (let ((date (if (not (plist-get info :with-date)) ""
1351 (org-export-data (plist-get info :date) info)))
1352 (author (let ((author (plist-get info :author)))
1353 (and author (org-export-data author info))))
1354 (email (mapconcat
1355 (lambda (e)
1356 (format "<a href=\"mailto:%s\">%s</a>" e e))
1357 (split-string (plist-get info :email) ",+ *")
1358 ", "))
1359 (html-validation-link (or org-html-validation-link ""))
1360 (creator-info (plist-get info :creator)))
1361 (cond ((stringp postamble)
1362 (format-spec postamble
1363 `((?a . ,author) (?e . ,email)
1364 (?d . ,date) (?c . ,creator-info)
1365 (?v . ,html-validation-link))))
1366 ((eq postamble 'auto)
1367 (concat
1368 (when (plist-get info :time-stamp-file)
1369 (format "<p class=\"date\">%s: %s</p>\n"
1370 (org-html--translate "Date" info)
1371 date))
1372 (when (and (plist-get info :with-author) author)
1373 (format "<p class=\"author\">%s : %s</p>\n"
1374 (org-html--translate "Author" info)
1375 author))
1376 (when (and (plist-get info :with-email) email)
1377 (format "<p class=\"email\">%s </p>\n" email))
1378 (when (plist-get info :with-creator)
1379 (format "<p class=\"creator\">%s</p>\n"
1380 creator-info))
1381 html-validation-link "\n"))
1382 (t (format-spec
1383 (or (cadr (assoc (plist-get info :language)
1384 org-html-postamble-format))
1385 (cadr (assoc "en" org-html-postamble-format)))
1386 `((?a . ,author) (?e . ,email)
1387 (?d . ,date) (?c . ,creator-info)
1388 (?v . ,html-validation-link)))))))))
1389 (when (org-string-nw-p postamble-contents)
1390 (concat
1391 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1392 (org-element-normalize-string postamble-contents)
1393 "</div>\n"))))))
1395 (defun org-html-inner-template (contents info)
1396 "Return body of document string after HTML conversion.
1397 CONTENTS is the transcoded contents string. INFO is a plist
1398 holding export options."
1399 (concat
1400 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1401 ;; Document title.
1402 (format "<h1 class=\"title\">%s</h1>\n"
1403 (org-export-data (plist-get info :title) info))
1404 ;; Table of contents.
1405 (let ((depth (plist-get info :with-toc)))
1406 (when depth (org-html-toc depth info)))
1407 ;; Document contents.
1408 contents
1409 ;; Footnotes section.
1410 (org-html-footnote-section info)
1411 ;; Bibliography.
1412 (org-html-bibliography)
1413 "\n</div>"))
1415 (defun org-html-template (contents info)
1416 "Return complete document string after HTML conversion.
1417 CONTENTS is the transcoded contents string. INFO is a plist
1418 holding export options."
1419 (concat
1420 (format
1421 (or (and (stringp org-html-xml-declaration)
1422 org-html-xml-declaration)
1423 (cdr (assoc (plist-get info :html-extension)
1424 org-html-xml-declaration))
1425 (cdr (assoc "html" org-html-xml-declaration))
1428 (or (and org-html-coding-system
1429 (fboundp 'coding-system-get)
1430 (coding-system-get org-html-coding-system 'mime-charset))
1431 "iso-8859-1"))
1432 "\n"
1433 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1434 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1435 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1436 (plist-get info :language) (plist-get info :language))
1437 "<head>\n"
1438 (org-html--build-meta-info info)
1439 (org-html--build-style info)
1440 (org-html--build-mathjax-config info)
1441 "</head>\n"
1442 "<body>\n"
1443 (let ((link-up (org-trim (plist-get info :html-link-up)))
1444 (link-home (org-trim (plist-get info :html-link-home))))
1445 (unless (and (string= link-up "") (string= link-up ""))
1446 (format org-html-home/up-format
1447 (or link-up link-home)
1448 (or link-home link-up))))
1449 ;; Preamble.
1450 (org-html--build-preamble info)
1451 ;; Document contents.
1452 contents
1453 ;; Postamble.
1454 (org-html--build-postamble info)
1455 ;; Closing document.
1456 "</body>\n</html>"))
1458 (defun org-html--translate (s info)
1459 "Translate string S according to specified language.
1460 INFO is a plist used as a communication channel."
1461 (org-export-translate s :html info))
1463 ;;;; Anchor
1465 (defun org-html--anchor (&optional id desc attributes)
1466 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1467 (attributes (concat (and id (format " id=\"%s\"" id))
1468 (and name (format " name=\"%s\"" name))
1469 attributes)))
1470 (format "<a%s>%s</a>" attributes (or desc ""))))
1472 ;;;; Todo
1474 (defun org-html--todo (todo)
1475 (when todo
1476 (format "<span class=\"%s %s%s\">%s</span>"
1477 (if (member todo org-done-keywords) "done" "todo")
1478 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1479 todo)))
1481 ;;;; Tags
1483 (defun org-html--tags (tags)
1484 (when tags
1485 (format "<span class=\"tag\">%s</span>"
1486 (mapconcat
1487 (lambda (tag)
1488 (format "<span class=\"%s\">%s</span>"
1489 (concat org-html-tag-class-prefix
1490 (org-html-fix-class-name tag))
1491 tag))
1492 tags "&nbsp;"))))
1494 ;;;; Headline
1496 (defun* org-html-format-headline
1497 (todo todo-type priority text tags
1498 &key level section-number headline-label &allow-other-keys)
1499 (let ((section-number
1500 (when section-number
1501 (format "<span class=\"section-number-%d\">%s</span> "
1502 level section-number)))
1503 (todo (org-html--todo todo))
1504 (tags (org-html--tags tags)))
1505 (concat section-number todo (and todo " ") text
1506 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1508 ;;;; Src Code
1510 (defun org-html-fontify-code (code lang)
1511 "Color CODE with htmlize library.
1512 CODE is a string representing the source code to colorize. LANG
1513 is the language used for CODE, as a string, or nil."
1514 (when code
1515 (cond
1516 ;; Case 1: No lang. Possibly an example block.
1517 ((not lang)
1518 ;; Simple transcoding.
1519 (org-html-encode-plain-text code))
1520 ;; Case 2: No htmlize or an inferior version of htmlize
1521 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1522 ;; Emit a warning.
1523 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1524 ;; Simple transcoding.
1525 (org-html-encode-plain-text code))
1527 ;; Map language
1528 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1529 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1530 (cond
1531 ;; Case 1: Language is not associated with any Emacs mode
1532 ((not (functionp lang-mode))
1533 ;; Simple transcoding.
1534 (org-html-encode-plain-text code))
1535 ;; Case 2: Default. Fontify code.
1537 ;; htmlize
1538 (setq code (with-temp-buffer
1539 ;; Switch to language-specific mode.
1540 (funcall lang-mode)
1541 (insert code)
1542 ;; Fontify buffer.
1543 (font-lock-fontify-buffer)
1544 ;; Remove formatting on newline characters.
1545 (save-excursion
1546 (let ((beg (point-min))
1547 (end (point-max)))
1548 (goto-char beg)
1549 (while (progn (end-of-line) (< (point) end))
1550 (put-text-property (point) (1+ (point)) 'face nil)
1551 (forward-char 1))))
1552 (org-src-mode)
1553 (set-buffer-modified-p nil)
1554 ;; Htmlize region.
1555 (org-html-htmlize-region-for-paste
1556 (point-min) (point-max))))
1557 ;; Strip any encolosing <pre></pre> tags.
1558 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1559 (match-string 1 code)
1560 code))))))))
1562 (defun org-html-do-format-code
1563 (code &optional lang refs retain-labels num-start)
1564 "Format CODE string as source code.
1565 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1566 respectively, the language of the source code, as a string, an
1567 alist between line numbers and references (as returned by
1568 `org-export-unravel-code'), a boolean specifying if labels should
1569 appear in the source code, and the number associated to the first
1570 line of code."
1571 (let* ((code-lines (org-split-string code "\n"))
1572 (code-length (length code-lines))
1573 (num-fmt
1574 (and num-start
1575 (format "%%%ds: "
1576 (length (number-to-string (+ code-length num-start))))))
1577 (code (org-html-fontify-code code lang)))
1578 (org-export-format-code
1579 code
1580 (lambda (loc line-num ref)
1581 (setq loc
1582 (concat
1583 ;; Add line number, if needed.
1584 (when num-start
1585 (format "<span class=\"linenr\">%s</span>"
1586 (format num-fmt line-num)))
1587 ;; Transcoded src line.
1589 ;; Add label, if needed.
1590 (when (and ref retain-labels) (format " (%s)" ref))))
1591 ;; Mark transcoded line as an anchor, if needed.
1592 (if (not ref) loc
1593 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1594 ref loc)))
1595 num-start refs)))
1597 (defun org-html-format-code (element info)
1598 "Format contents of ELEMENT as source code.
1599 ELEMENT is either an example block or a src block. INFO is
1600 a plist used as a communication channel."
1601 (let* ((lang (org-element-property :language element))
1602 ;; Extract code and references.
1603 (code-info (org-export-unravel-code element))
1604 (code (car code-info))
1605 (refs (cdr code-info))
1606 ;; Does the src block contain labels?
1607 (retain-labels (org-element-property :retain-labels element))
1608 ;; Does it have line numbers?
1609 (num-start (case (org-element-property :number-lines element)
1610 (continued (org-export-get-loc element info))
1611 (new 0))))
1612 (org-html-do-format-code code lang refs retain-labels num-start)))
1616 ;;; Transcode Functions
1618 ;;;; Bold
1620 (defun org-html-bold (bold contents info)
1621 "Transcode BOLD from Org to HTML.
1622 CONTENTS is the text with bold markup. INFO is a plist holding
1623 contextual information."
1624 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1625 contents))
1628 ;;;; Center Block
1630 (defun org-html-center-block (center-block contents info)
1631 "Transcode a CENTER-BLOCK element from Org to HTML.
1632 CONTENTS holds the contents of the block. INFO is a plist
1633 holding contextual information."
1634 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1637 ;;;; Clock
1639 (defun org-html-clock (clock contents info)
1640 "Transcode a CLOCK element from Org to HTML.
1641 CONTENTS is nil. INFO is a plist used as a communication
1642 channel."
1643 (format "<p>
1644 <span class=\"timestamp-wrapper\">
1645 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1646 </span>
1647 </p>"
1648 org-clock-string
1649 (org-translate-time
1650 (org-element-property :raw-value
1651 (org-element-property :value clock)))
1652 (let ((time (org-element-property :duration clock)))
1653 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1656 ;;;; Code
1658 (defun org-html-code (code contents info)
1659 "Transcode CODE from Org to HTML.
1660 CONTENTS is nil. INFO is a plist holding contextual
1661 information."
1662 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1663 (org-element-property :value code)))
1666 ;;;; Drawer
1668 (defun org-html-drawer (drawer contents info)
1669 "Transcode a DRAWER element from Org to HTML.
1670 CONTENTS holds the contents of the block. INFO is a plist
1671 holding contextual information."
1672 (if (functionp org-html-format-drawer-function)
1673 (funcall org-html-format-drawer-function
1674 (org-element-property :drawer-name drawer)
1675 contents)
1676 ;; If there's no user defined function: simply
1677 ;; display contents of the drawer.
1678 contents))
1681 ;;;; Dynamic Block
1683 (defun org-html-dynamic-block (dynamic-block contents info)
1684 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1685 CONTENTS holds the contents of the block. INFO is a plist
1686 holding contextual information. See `org-export-data'."
1687 contents)
1690 ;;;; Entity
1692 (defun org-html-entity (entity contents info)
1693 "Transcode an ENTITY object from Org to HTML.
1694 CONTENTS are the definition itself. INFO is a plist holding
1695 contextual information."
1696 (org-element-property :html entity))
1699 ;;;; Example Block
1701 (defun org-html-example-block (example-block contents info)
1702 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1703 CONTENTS is nil. INFO is a plist holding contextual
1704 information."
1705 (if (org-export-read-attribute :attr_html example-block :textarea)
1706 (org-html--textarea-block example-block)
1707 (format "<pre class=\"example\">\n%s</pre>"
1708 (org-html-format-code example-block info))))
1711 ;;;; Export Snippet
1713 (defun org-html-export-snippet (export-snippet contents info)
1714 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1715 CONTENTS is nil. INFO is a plist holding contextual
1716 information."
1717 (when (eq (org-export-snippet-backend export-snippet) 'html)
1718 (org-element-property :value export-snippet)))
1721 ;;;; Export Block
1723 (defun org-html-export-block (export-block contents info)
1724 "Transcode a EXPORT-BLOCK element from Org to HTML.
1725 CONTENTS is nil. INFO is a plist holding contextual information."
1726 (when (string= (org-element-property :type export-block) "HTML")
1727 (org-remove-indentation (org-element-property :value export-block))))
1730 ;;;; Fixed Width
1732 (defun org-html-fixed-width (fixed-width contents info)
1733 "Transcode a FIXED-WIDTH element from Org to HTML.
1734 CONTENTS is nil. INFO is a plist holding contextual information."
1735 (format "<pre class=\"example\">\n%s</pre>"
1736 (org-html-do-format-code
1737 (org-remove-indentation
1738 (org-element-property :value fixed-width)))))
1741 ;;;; Footnote Reference
1743 (defun org-html-footnote-reference (footnote-reference contents info)
1744 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1745 CONTENTS is nil. INFO is a plist holding contextual information."
1746 (concat
1747 ;; Insert separator between two footnotes in a row.
1748 (let ((prev (org-export-get-previous-element footnote-reference info)))
1749 (when (eq (org-element-type prev) 'footnote-reference)
1750 org-html-footnote-separator))
1751 (cond
1752 ((not (org-export-footnote-first-reference-p footnote-reference info))
1753 (org-html-format-footnote-reference
1754 (org-export-get-footnote-number footnote-reference info)
1755 "IGNORED" 100))
1756 ;; Inline definitions are secondary strings.
1757 ((eq (org-element-property :type footnote-reference) 'inline)
1758 (org-html-format-footnote-reference
1759 (org-export-get-footnote-number footnote-reference info)
1760 "IGNORED" 1))
1761 ;; Non-inline footnotes definitions are full Org data.
1762 (t (org-html-format-footnote-reference
1763 (org-export-get-footnote-number footnote-reference info)
1764 "IGNORED" 1)))))
1767 ;;;; Headline
1769 (defun org-html-format-headline--wrap (headline info
1770 &optional format-function
1771 &rest extra-keys)
1772 "Transcode a HEADLINE element from Org to HTML.
1773 CONTENTS holds the contents of the headline. INFO is a plist
1774 holding contextual information."
1775 (let* ((level (+ (org-export-get-relative-level headline info)
1776 (1- org-html-toplevel-hlevel)))
1777 (headline-number (org-export-get-headline-number headline info))
1778 (section-number (and (not (org-export-low-level-p headline info))
1779 (org-export-numbered-headline-p headline info)
1780 (mapconcat 'number-to-string
1781 headline-number ".")))
1782 (todo (and (plist-get info :with-todo-keywords)
1783 (let ((todo (org-element-property :todo-keyword headline)))
1784 (and todo (org-export-data todo info)))))
1785 (todo-type (and todo (org-element-property :todo-type headline)))
1786 (priority (and (plist-get info :with-priority)
1787 (org-element-property :priority headline)))
1788 (text (org-export-data (org-element-property :title headline) info))
1789 (tags (and (plist-get info :with-tags)
1790 (org-export-get-tags headline info)))
1791 (headline-label (or (org-element-property :CUSTOM_ID headline)
1792 (concat "sec-" (mapconcat 'number-to-string
1793 headline-number "-"))))
1794 (format-function (cond
1795 ((functionp format-function) format-function)
1796 ((functionp org-html-format-headline-function)
1797 (function*
1798 (lambda (todo todo-type priority text tags
1799 &allow-other-keys)
1800 (funcall org-html-format-headline-function
1801 todo todo-type priority text tags))))
1802 (t 'org-html-format-headline))))
1803 (apply format-function
1804 todo todo-type priority text tags
1805 :headline-label headline-label :level level
1806 :section-number section-number extra-keys)))
1808 (defun org-html-headline (headline contents info)
1809 "Transcode a HEADLINE element from Org to HTML.
1810 CONTENTS holds the contents of the headline. INFO is a plist
1811 holding contextual information."
1812 ;; Empty contents?
1813 (setq contents (or contents ""))
1814 (let* ((numberedp (org-export-numbered-headline-p headline info))
1815 (level (org-export-get-relative-level headline info))
1816 (text (org-export-data (org-element-property :title headline) info))
1817 (todo (and (plist-get info :with-todo-keywords)
1818 (let ((todo (org-element-property :todo-keyword headline)))
1819 (and todo (org-export-data todo info)))))
1820 (todo-type (and todo (org-element-property :todo-type headline)))
1821 (tags (and (plist-get info :with-tags)
1822 (org-export-get-tags headline info)))
1823 (priority (and (plist-get info :with-priority)
1824 (org-element-property :priority headline)))
1825 (section-number (and (org-export-numbered-headline-p headline info)
1826 (mapconcat 'number-to-string
1827 (org-export-get-headline-number
1828 headline info) ".")))
1829 ;; Create the headline text.
1830 (full-text (org-html-format-headline--wrap headline info)))
1831 (cond
1832 ;; Case 1: This is a footnote section: ignore it.
1833 ((org-element-property :footnote-section-p headline) nil)
1834 ;; Case 2. This is a deep sub-tree: export it as a list item.
1835 ;; Also export as items headlines for which no section
1836 ;; format has been found.
1837 ((org-export-low-level-p headline info)
1838 ;; Build the real contents of the sub-tree.
1839 (let* ((type (if numberedp 'ordered 'unordered))
1840 (itemized-body (org-html-format-list-item
1841 contents type nil nil full-text)))
1842 (concat
1843 (and (org-export-first-sibling-p headline info)
1844 (org-html-begin-plain-list type))
1845 itemized-body
1846 (and (org-export-last-sibling-p headline info)
1847 (org-html-end-plain-list type)))))
1848 ;; Case 3. Standard headline. Export it as a section.
1850 (let* ((section-number (mapconcat 'number-to-string
1851 (org-export-get-headline-number
1852 headline info) "-"))
1853 (ids (remove 'nil
1854 (list (org-element-property :CUSTOM_ID headline)
1855 (concat "sec-" section-number)
1856 (org-element-property :ID headline))))
1857 (preferred-id (car ids))
1858 (extra-ids (cdr ids))
1859 (extra-class (org-element-property :html-container-class headline))
1860 (level1 (+ level (1- org-html-toplevel-hlevel))))
1861 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1862 (format "outline-container-%s"
1863 (or (org-element-property :CUSTOM_ID headline)
1864 section-number))
1865 (concat (format "outline-%d" level1) (and extra-class " ")
1866 extra-class)
1867 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1868 level1
1869 preferred-id
1870 (mapconcat
1871 (lambda (x)
1872 (let ((id (org-export-solidify-link-text
1873 (if (org-uuidgen-p x) (concat "ID-" x)
1874 x))))
1875 (org-html--anchor id)))
1876 extra-ids "")
1877 full-text
1878 level1)
1879 contents))))))
1882 ;;;; Horizontal Rule
1884 (defun org-html-horizontal-rule (horizontal-rule contents info)
1885 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1886 CONTENTS is nil. INFO is a plist holding contextual information."
1887 "<hr/>")
1890 ;;;; Inline Src Block
1892 (defun org-html-inline-src-block (inline-src-block contents info)
1893 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1894 CONTENTS holds the contents of the item. INFO is a plist holding
1895 contextual information."
1896 (let* ((org-lang (org-element-property :language inline-src-block))
1897 (code (org-element-property :value inline-src-block)))
1898 (error "Cannot export inline src block")))
1901 ;;;; Inlinetask
1903 (defun org-html-format-section (text class &optional id)
1904 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1905 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1907 (defun org-html-inlinetask (inlinetask contents info)
1908 "Transcode an INLINETASK element from Org to HTML.
1909 CONTENTS holds the contents of the block. INFO is a plist
1910 holding contextual information."
1911 (cond
1912 ;; If `org-html-format-inlinetask-function' is provided, call it
1913 ;; with appropriate arguments.
1914 ((functionp org-html-format-inlinetask-function)
1915 (let ((format-function
1916 (function*
1917 (lambda (todo todo-type priority text tags
1918 &key contents &allow-other-keys)
1919 (funcall org-html-format-inlinetask-function
1920 todo todo-type priority text tags contents)))))
1921 (org-html-format-headline--wrap
1922 inlinetask info format-function :contents contents)))
1923 ;; Otherwise, use a default template.
1924 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1925 (org-html-format-headline--wrap inlinetask info)
1926 contents))))
1929 ;;;; Italic
1931 (defun org-html-italic (italic contents info)
1932 "Transcode ITALIC from Org to HTML.
1933 CONTENTS is the text with italic markup. INFO is a plist holding
1934 contextual information."
1935 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
1938 ;;;; Item
1940 (defun org-html-checkbox (checkbox)
1941 (case checkbox (on "<code>[X]</code>")
1942 (off "<code>[&nbsp;]</code>")
1943 (trans "<code>[-]</code>")
1944 (t "")))
1946 (defun org-html-format-list-item (contents type checkbox
1947 &optional term-counter-id
1948 headline)
1949 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
1950 (concat
1951 (case type
1952 (ordered
1953 (let* ((counter term-counter-id)
1954 (extra (if counter (format " value=\"%s\"" counter) "")))
1955 (concat
1956 (format "<li%s>" extra)
1957 (when headline (concat headline "<br/>")))))
1958 (unordered
1959 (let* ((id term-counter-id)
1960 (extra (if id (format " id=\"%s\"" id) "")))
1961 (concat
1962 (format "<li%s>" extra)
1963 (when headline (concat headline "<br/>")))))
1964 (descriptive
1965 (let* ((term term-counter-id))
1966 (setq term (or term "(no term)"))
1967 ;; Check-boxes in descriptive lists are associated to tag.
1968 (concat (format "<dt> %s </dt>"
1969 (concat checkbox term))
1970 "<dd>"))))
1971 (unless (eq type 'descriptive) checkbox)
1972 contents
1973 (case type
1974 (ordered "</li>")
1975 (unordered "</li>")
1976 (descriptive "</dd>")))))
1978 (defun org-html-item (item contents info)
1979 "Transcode an ITEM element from Org to HTML.
1980 CONTENTS holds the contents of the item. INFO is a plist holding
1981 contextual information."
1982 (let* ((plain-list (org-export-get-parent item))
1983 (type (org-element-property :type plain-list))
1984 (counter (org-element-property :counter item))
1985 (checkbox (org-element-property :checkbox item))
1986 (tag (let ((tag (org-element-property :tag item)))
1987 (and tag (org-export-data tag info)))))
1988 (org-html-format-list-item
1989 contents type checkbox (or tag counter))))
1992 ;;;; Keyword
1994 (defun org-html-keyword (keyword contents info)
1995 "Transcode a KEYWORD element from Org to HTML.
1996 CONTENTS is nil. INFO is a plist holding contextual information."
1997 (let ((key (org-element-property :key keyword))
1998 (value (org-element-property :value keyword)))
1999 (cond
2000 ((string= key "HTML") value)
2001 ;; Invisible targets.
2002 ((string= key "TARGET") nil)
2003 ((string= key "TOC")
2004 (let ((value (downcase value)))
2005 (cond
2006 ((string-match "\\<headlines\\>" value)
2007 (let ((depth (or (and (string-match "[0-9]+" value)
2008 (string-to-number (match-string 0 value)))
2009 (plist-get info :with-toc))))
2010 (org-html-toc depth info)))
2011 ((string= "tables" value) "\\listoftables")
2012 ((string= "figures" value) "\\listoffigures")
2013 ((string= "listings" value)
2014 (cond
2015 ;; At the moment, src blocks with a caption are wrapped
2016 ;; into a figure environment.
2017 (t "\\listoffigures")))))))))
2020 ;;;; Latex Environment
2022 (defun org-html-format-latex (latex-frag processing-type)
2023 "Format LaTeX fragments into HTML."
2024 (let ((cache-relpath "") (cache-dir "") bfn)
2025 (unless (eq processing-type 'mathjax)
2026 (setq bfn (buffer-file-name)
2027 cache-relpath
2028 (concat "ltxpng/"
2029 (file-name-sans-extension
2030 (file-name-nondirectory bfn)))
2031 cache-dir (file-name-directory bfn)))
2032 (with-temp-buffer
2033 (insert latex-frag)
2034 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2035 nil nil processing-type)
2036 (buffer-string))))
2038 (defun org-html-latex-environment (latex-environment contents info)
2039 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2040 CONTENTS is nil. INFO is a plist holding contextual information."
2041 (let ((processing-type (plist-get info :with-latex))
2042 (latex-frag (org-remove-indentation
2043 (org-element-property :value latex-environment)))
2044 (caption (org-export-data
2045 (org-export-get-caption latex-environment) info))
2046 (attr nil) ; FIXME
2047 (label (org-element-property :name latex-environment)))
2048 (cond
2049 ((memq processing-type '(t mathjax))
2050 (org-html-format-latex latex-frag 'mathjax))
2051 ((eq processing-type 'dvipng)
2052 (let* ((formula-link (org-html-format-latex
2053 latex-frag processing-type)))
2054 (when (and formula-link
2055 (string-match "file:\\([^]]*\\)" formula-link))
2056 (org-html-format-inline-image
2057 (match-string 1 formula-link) caption label attr t))))
2058 (t latex-frag))))
2061 ;;;; Latex Fragment
2063 (defun org-html-latex-fragment (latex-fragment contents info)
2064 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2065 CONTENTS is nil. INFO is a plist holding contextual information."
2066 (let ((latex-frag (org-element-property :value latex-fragment))
2067 (processing-type (plist-get info :with-latex)))
2068 (case processing-type
2069 ((t mathjax)
2070 (org-html-format-latex latex-frag 'mathjax))
2071 (dvipng
2072 (let* ((formula-link (org-html-format-latex
2073 latex-frag processing-type)))
2074 (when (and formula-link
2075 (string-match "file:\\([^]]*\\)" formula-link))
2076 (org-html-format-inline-image
2077 (match-string 1 formula-link)))))
2078 (t latex-frag))))
2081 ;;;; Line Break
2083 (defun org-html-line-break (line-break contents info)
2084 "Transcode a LINE-BREAK object from Org to HTML.
2085 CONTENTS is nil. INFO is a plist holding contextual information."
2086 "<br/>\n")
2089 ;;;; Link
2091 (defun org-html-link--inline-image (link desc info)
2092 "Return HTML code for an inline image.
2093 LINK is the link pointing to the inline image. INFO is a plist
2094 used as a communication channel."
2095 (let* ((type (org-element-property :type link))
2096 (raw-path (org-element-property :path link))
2097 (path (cond ((member type '("http" "https"))
2098 (concat type ":" raw-path))
2099 ((file-name-absolute-p raw-path)
2100 (expand-file-name raw-path))
2101 (t raw-path)))
2102 (parent (org-export-get-parent-element link))
2103 (caption (org-export-data (org-export-get-caption parent) info))
2104 (label (org-element-property :name parent))
2105 ;; Retrieve latex attributes from the element around.
2106 (attr (let ((raw-attr
2107 (mapconcat #'identity
2108 (org-element-property :attr_html parent)
2109 " ")))
2110 (unless (string= raw-attr "") raw-attr))))
2111 ;; Now clear ATTR from any special keyword and set a default
2112 ;; value if nothing is left.
2113 (setq attr (if (not attr) "" (org-trim attr)))
2114 ;; Return proper string, depending on DISPOSITION.
2115 (org-html-format-inline-image
2116 path caption label attr (org-html-standalone-image-p link info))))
2118 (defvar org-html-standalone-image-predicate)
2119 (defun org-html-standalone-image-p (element info &optional predicate)
2120 "Test if ELEMENT is a standalone image for the purpose HTML export.
2121 INFO is a plist holding contextual information.
2123 Return non-nil, if ELEMENT is of type paragraph and it's sole
2124 content, save for whitespaces, is a link that qualifies as an
2125 inline image.
2127 Return non-nil, if ELEMENT is of type link and it's containing
2128 paragraph has no other content save for leading and trailing
2129 whitespaces.
2131 Return nil, otherwise.
2133 Bind `org-html-standalone-image-predicate' to constrain
2134 paragraph further. For example, to check for only captioned
2135 standalone images, do the following.
2137 \(setq org-html-standalone-image-predicate
2138 \(lambda \(paragraph\)
2139 \(org-element-property :caption paragraph\)\)\)"
2140 (let ((paragraph (case (org-element-type element)
2141 (paragraph element)
2142 (link (and (org-export-inline-image-p
2143 element org-html-inline-image-rules)
2144 (org-export-get-parent element)))
2145 (t nil))))
2146 (when (eq (org-element-type paragraph) 'paragraph)
2147 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2148 (functionp org-html-standalone-image-predicate)))
2149 (funcall org-html-standalone-image-predicate paragraph))
2150 (let ((contents (org-element-contents paragraph)))
2151 (loop for x in contents
2152 with inline-image-count = 0
2153 always (cond
2154 ((eq (org-element-type x) 'plain-text)
2155 (not (org-string-nw-p x)))
2156 ((eq (org-element-type x) 'link)
2157 (when (org-export-inline-image-p
2158 x org-html-inline-image-rules)
2159 (= (incf inline-image-count) 1)))
2160 (t nil))))))))
2162 (defun org-html-link (link desc info)
2163 "Transcode a LINK object from Org to HTML.
2165 DESC is the description part of the link, or the empty string.
2166 INFO is a plist holding contextual information. See
2167 `org-export-data'."
2168 (let* ((--link-org-files-as-html-maybe
2169 (function
2170 (lambda (raw-path info)
2171 "Treat links to `file.org' as links to `file.html', if needed.
2172 See `org-html-link-org-files-as-html'."
2173 (cond
2174 ((and org-html-link-org-files-as-html
2175 (string= ".org"
2176 (downcase (file-name-extension raw-path "."))))
2177 (concat (file-name-sans-extension raw-path) "."
2178 (plist-get info :html-extension)))
2179 (t raw-path)))))
2180 (type (org-element-property :type link))
2181 (raw-path (org-element-property :path link))
2182 ;; Ensure DESC really exists, or set it to nil.
2183 (desc (and (not (string= desc "")) desc))
2184 (path
2185 (cond
2186 ((member type '("http" "https" "ftp" "mailto"))
2187 (concat type ":" raw-path))
2188 ((string= type "file")
2189 ;; Treat links to ".org" files as ".html", if needed.
2190 (setq raw-path
2191 (funcall --link-org-files-as-html-maybe raw-path info))
2192 ;; If file path is absolute, prepend it with protocol
2193 ;; component - "file://".
2194 (when (file-name-absolute-p raw-path)
2195 (setq raw-path
2196 (concat "file://" (expand-file-name raw-path))))
2197 ;; Add search option, if any. A search option can be
2198 ;; relative to a custom-id or a headline title. Any other
2199 ;; option is ignored.
2200 (let ((option (org-element-property :search-option link)))
2201 (cond ((not option) raw-path)
2202 ((eq (aref option 0) ?#) (concat raw-path option))
2203 ;; External fuzzy link: try to resolve it if path
2204 ;; belongs to current project, if any.
2205 ((eq (aref option 0) ?*)
2206 (concat
2207 raw-path
2208 (let ((numbers
2209 (org-publish-resolve-external-fuzzy-link
2210 (org-element-property :path link) option)))
2211 (and numbers (concat "#sec-"
2212 (mapconcat 'number-to-string
2213 numbers "-")))))))))
2214 (t raw-path)))
2215 attributes protocol)
2216 ;; Extract attributes from parent's paragraph.
2217 (and (setq attributes
2218 (mapconcat
2219 'identity
2220 (let ((att (org-element-property
2221 :attr_html (org-export-get-parent-element link))))
2222 (unless (and desc att (string-match (regexp-quote (car att)) desc)) att))
2223 " "))
2224 (setq attributes (concat " " attributes)))
2226 (cond
2227 ;; Image file.
2228 ((and (or (eq t org-html-inline-images)
2229 (and org-html-inline-images (not desc)))
2230 (org-export-inline-image-p link org-html-inline-image-rules))
2231 (org-html-link--inline-image link desc info))
2232 ;; Radio target: Transcode target's contents and use them as
2233 ;; link's description.
2234 ((string= type "radio")
2235 (let ((destination (org-export-resolve-radio-link link info)))
2236 (when destination
2237 (format "<a href=\"#%s\"%s>%s</a>"
2238 (org-export-solidify-link-text path)
2239 attributes
2240 (org-export-data (org-element-contents destination) info)))))
2241 ;; Links pointing to a headline: Find destination and build
2242 ;; appropriate referencing command.
2243 ((member type '("custom-id" "fuzzy" "id"))
2244 (let ((destination (if (string= type "fuzzy")
2245 (org-export-resolve-fuzzy-link link info)
2246 (org-export-resolve-id-link link info))))
2247 (case (org-element-type destination)
2248 ;; ID link points to an external file.
2249 (plain-text
2250 (let ((fragment (concat "ID-" path))
2251 ;; Treat links to ".org" files as ".html", if needed.
2252 (path (funcall --link-org-files-as-html-maybe
2253 destination info)))
2254 (format "<a href=\"%s#%s\"%s>%s</a>"
2255 path fragment attributes (or desc destination))))
2256 ;; Fuzzy link points nowhere.
2257 ((nil)
2258 (format "<i>%s</i>"
2259 (or desc
2260 (org-export-data
2261 (org-element-property :raw-link link) info))))
2262 ;; Fuzzy link points to an invisible target.
2263 (keyword nil)
2264 ;; Link points to a headline.
2265 (headline
2266 (let ((href
2267 ;; What href to use?
2268 (cond
2269 ;; Case 1: Headline is linked via it's CUSTOM_ID
2270 ;; property. Use CUSTOM_ID.
2271 ((string= type "custom-id")
2272 (org-element-property :CUSTOM_ID destination))
2273 ;; Case 2: Headline is linked via it's ID property
2274 ;; or through other means. Use the default href.
2275 ((member type '("id" "fuzzy"))
2276 (format "sec-%s"
2277 (mapconcat 'number-to-string
2278 (org-export-get-headline-number
2279 destination info) "-")))
2280 (t (error "Shouldn't reach here"))))
2281 ;; What description to use?
2282 (desc
2283 ;; Case 1: Headline is numbered and LINK has no
2284 ;; description or LINK's description matches
2285 ;; headline's title. Display section number.
2286 (if (and (org-export-numbered-headline-p destination info)
2287 (or (not desc)
2288 (string= desc (org-element-property
2289 :raw-value destination))))
2290 (mapconcat 'number-to-string
2291 (org-export-get-headline-number
2292 destination info) ".")
2293 ;; Case 2: Either the headline is un-numbered or
2294 ;; LINK has a custom description. Display LINK's
2295 ;; description or headline's title.
2296 (or desc (org-export-data (org-element-property
2297 :title destination) info)))))
2298 (format "<a href=\"#%s\"%s>%s</a>"
2299 (org-export-solidify-link-text href) attributes desc)))
2300 ;; Fuzzy link points to a target. Do as above.
2302 (let ((path (org-export-solidify-link-text path)) number)
2303 (unless desc
2304 (setq number (cond
2305 ((org-html-standalone-image-p destination info)
2306 (org-export-get-ordinal
2307 (assoc 'link (org-element-contents destination))
2308 info 'link 'org-html-standalone-image-p))
2309 (t (org-export-get-ordinal destination info))))
2310 (setq desc (when number
2311 (if (atom number) (number-to-string number)
2312 (mapconcat 'number-to-string number ".")))))
2313 (format "<a href=\"#%s\"%s>%s</a>"
2314 path attributes (or desc "No description for this link")))))))
2315 ;; Coderef: replace link with the reference name or the
2316 ;; equivalent line number.
2317 ((string= type "coderef")
2318 (let ((fragment (concat "coderef-" path)))
2319 (format "<a href=\"#%s\" %s%s>%s</a>"
2320 fragment
2321 (format (concat "class=\"coderef\""
2322 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2323 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2324 fragment fragment)
2325 attributes
2326 (format (org-export-get-coderef-format path desc)
2327 (org-export-resolve-coderef path info)))))
2328 ;; Link type is handled by a special function.
2329 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2330 (funcall protocol (org-link-unescape path) desc 'html))
2331 ;; External link with a description part.
2332 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2333 ;; External link without a description part.
2334 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2335 ;; No path, only description. Try to do something useful.
2336 (t (format "<i>%s</i>" desc)))))
2339 ;;;; Paragraph
2341 (defun org-html-paragraph (paragraph contents info)
2342 "Transcode a PARAGRAPH element from Org to HTML.
2343 CONTENTS is the contents of the paragraph, as a string. INFO is
2344 the plist used as a communication channel."
2345 (let* ((style nil) ; FIXME
2346 (class (cdr (assoc style '((footnote . "footnote")
2347 (verse . nil)))))
2348 (extra (if class (format " class=\"%s\"" class) ""))
2349 (parent (org-export-get-parent paragraph)))
2350 (cond
2351 ((and (eq (org-element-type parent) 'item)
2352 (= (org-element-property :begin paragraph)
2353 (org-element-property :contents-begin parent)))
2354 ;; leading paragraph in a list item have no tags
2355 contents)
2356 ((org-html-standalone-image-p paragraph info)
2357 ;; standalone image
2358 contents)
2359 (t (format "<p%s>\n%s</p>" extra contents)))))
2362 ;;;; Plain List
2364 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2365 ;; the correct value for the item counter
2366 (defun org-html-begin-plain-list (type &optional arg1)
2367 "Insert the beginning of the HTML list depending on TYPE.
2368 When ARG1 is a string, use it as the start parameter for ordered
2369 lists."
2370 (case type
2371 (ordered
2372 (format "<ol class=\"org-ol\"%s>"
2373 (if arg1 (format " start=\"%d\"" arg1) "")))
2374 (unordered "<ul class=\"org-ul\">")
2375 (descriptive "<dl class=\"org-dl\">")))
2377 (defun org-html-end-plain-list (type)
2378 "Insert the end of the HTML list depending on TYPE."
2379 (case type
2380 (ordered "</ol>")
2381 (unordered "</ul>")
2382 (descriptive "</dl>")))
2384 (defun org-html-plain-list (plain-list contents info)
2385 "Transcode a PLAIN-LIST element from Org to HTML.
2386 CONTENTS is the contents of the list. INFO is a plist holding
2387 contextual information."
2388 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2389 (type (org-element-property :type plain-list)))
2390 (format "%s\n%s%s"
2391 (org-html-begin-plain-list type)
2392 contents (org-html-end-plain-list type))))
2394 ;;;; Plain Text
2396 (defun org-html-convert-special-strings (string)
2397 "Convert special characters in STRING to HTML."
2398 (let ((all org-html-special-string-regexps)
2399 e a re rpl start)
2400 (while (setq a (pop all))
2401 (setq re (car a) rpl (cdr a) start 0)
2402 (while (string-match re string start)
2403 (setq string (replace-match rpl t nil string))))
2404 string))
2406 (defun org-html-encode-plain-text (text)
2407 "Convert plain text characters to HTML equivalent.
2408 Possible conversions are set in `org-export-html-protect-char-alist'."
2409 (mapc
2410 (lambda (pair)
2411 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2412 org-html-protect-char-alist)
2413 text)
2415 (defun org-html-plain-text (text info)
2416 "Transcode a TEXT string from Org to HTML.
2417 TEXT is the string to transcode. INFO is a plist holding
2418 contextual information."
2419 (let ((output text))
2420 ;; Protect following characters: <, >, &.
2421 (setq output (org-html-encode-plain-text output))
2422 ;; Handle smart quotes. Be sure to provide original string since
2423 ;; OUTPUT may have been modified.
2424 (when (plist-get info :with-smart-quotes)
2425 (setq output (org-export-activate-smart-quotes output :html info text)))
2426 ;; Handle special strings.
2427 (when (plist-get info :with-special-strings)
2428 (setq output (org-html-convert-special-strings output)))
2429 ;; Handle break preservation if required.
2430 (when (plist-get info :preserve-breaks)
2431 (setq output
2432 (replace-regexp-in-string
2433 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2434 ;; Return value.
2435 output))
2438 ;; Planning
2440 (defun org-html-planning (planning contents info)
2441 "Transcode a PLANNING element from Org to HTML.
2442 CONTENTS is nil. INFO is a plist used as a communication
2443 channel."
2444 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2445 (format
2446 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2447 (mapconcat
2448 'identity
2449 (delq nil
2450 (list
2451 (let ((closed (org-element-property :closed planning)))
2452 (when closed
2453 (format span-fmt org-closed-string
2454 (org-translate-time
2455 (org-element-property :raw-value closed)))))
2456 (let ((deadline (org-element-property :deadline planning)))
2457 (when deadline
2458 (format span-fmt org-deadline-string
2459 (org-translate-time
2460 (org-element-property :raw-value deadline)))))
2461 (let ((scheduled (org-element-property :scheduled planning)))
2462 (when scheduled
2463 (format span-fmt org-scheduled-string
2464 (org-translate-time
2465 (org-element-property :raw-value scheduled)))))))
2466 " "))))
2469 ;;;; Property Drawer
2471 (defun org-html-property-drawer (property-drawer contents info)
2472 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2473 CONTENTS is nil. INFO is a plist holding contextual
2474 information."
2475 ;; The property drawer isn't exported but we want separating blank
2476 ;; lines nonetheless.
2480 ;;;; Quote Block
2482 (defun org-html-quote-block (quote-block contents info)
2483 "Transcode a QUOTE-BLOCK element from Org to HTML.
2484 CONTENTS holds the contents of the block. INFO is a plist
2485 holding contextual information."
2486 (format "<blockquote>\n%s</blockquote>" contents))
2489 ;;;; Quote Section
2491 (defun org-html-quote-section (quote-section contents info)
2492 "Transcode a QUOTE-SECTION element from Org to HTML.
2493 CONTENTS is nil. INFO is a plist holding contextual information."
2494 (let ((value (org-remove-indentation
2495 (org-element-property :value quote-section))))
2496 (when value (format "<pre>\n%s</pre>" value))))
2499 ;;;; Section
2501 (defun org-html-section (section contents info)
2502 "Transcode a SECTION element from Org to HTML.
2503 CONTENTS holds the contents of the section. INFO is a plist
2504 holding contextual information."
2505 (let ((parent (org-export-get-parent-headline section)))
2506 ;; Before first headline: no container, just return CONTENTS.
2507 (if (not parent) contents
2508 ;; Get div's class and id references.
2509 (let* ((class-num (+ (org-export-get-relative-level parent info)
2510 (1- org-html-toplevel-hlevel)))
2511 (section-number
2512 (mapconcat
2513 'number-to-string
2514 (org-export-get-headline-number parent info) "-")))
2515 ;; Build return value.
2516 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2517 class-num
2518 (or (org-element-property :CUSTOM_ID parent) section-number)
2519 contents)))))
2521 ;;;; Radio Target
2523 (defun org-html-radio-target (radio-target text info)
2524 "Transcode a RADIO-TARGET object from Org to HTML.
2525 TEXT is the text of the target. INFO is a plist holding
2526 contextual information."
2527 (let ((id (org-export-solidify-link-text
2528 (org-element-property :value radio-target))))
2529 (org-html--anchor id text)))
2532 ;;;; Special Block
2534 (defun org-html-special-block (special-block contents info)
2535 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2536 CONTENTS holds the contents of the block. INFO is a plist
2537 holding contextual information."
2538 (format "<div class=\"%s\">\n%s\n</div>"
2539 (downcase (org-element-property :type special-block))
2540 contents))
2543 ;;;; Src Block
2545 (defun org-html-src-block (src-block contents info)
2546 "Transcode a SRC-BLOCK element from Org to HTML.
2547 CONTENTS holds the contents of the item. INFO is a plist holding
2548 contextual information."
2549 (if (org-export-read-attribute :attr_html src-block :textarea)
2550 (org-html--textarea-block src-block)
2551 (let ((lang (org-element-property :language src-block))
2552 (caption (org-export-get-caption src-block))
2553 (code (org-html-format-code src-block info)))
2554 (if (not lang) (format "<pre class=\"example\">\n%s</pre>" code)
2555 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
2556 (if (not caption) ""
2557 (format "<label class=\"org-src-name\">%s</label>"
2558 (org-export-data caption info)))
2559 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code))))))
2562 ;;;; Statistics Cookie
2564 (defun org-html-statistics-cookie (statistics-cookie contents info)
2565 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2566 CONTENTS is nil. INFO is a plist holding contextual information."
2567 (let ((cookie-value (org-element-property :value statistics-cookie)))
2568 (format "<code>%s</code>" cookie-value)))
2571 ;;;; Strike-Through
2573 (defun org-html-strike-through (strike-through contents info)
2574 "Transcode STRIKE-THROUGH from Org to HTML.
2575 CONTENTS is the text with strike-through markup. INFO is a plist
2576 holding contextual information."
2577 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2578 contents))
2581 ;;;; Subscript
2583 (defun org-html-subscript (subscript contents info)
2584 "Transcode a SUBSCRIPT object from Org to HTML.
2585 CONTENTS is the contents of the object. INFO is a plist holding
2586 contextual information."
2587 (format "<sub>%s</sub>" contents))
2590 ;;;; Superscript
2592 (defun org-html-superscript (superscript contents info)
2593 "Transcode a SUPERSCRIPT object from Org to HTML.
2594 CONTENTS is the contents of the object. INFO is a plist holding
2595 contextual information."
2596 (format "<sup>%s</sup>" contents))
2599 ;;;; Tabel Cell
2601 (defun org-html-table-cell (table-cell contents info)
2602 "Transcode a TABLE-CELL element from Org to HTML.
2603 CONTENTS is nil. INFO is a plist used as a communication
2604 channel."
2605 (let* ((table-row (org-export-get-parent table-cell))
2606 (table (org-export-get-parent-table table-cell))
2607 (cell-attrs
2608 (if (not org-html-table-align-individual-fields) ""
2609 (format (if (and (boundp 'org-html-format-table-no-css)
2610 org-html-format-table-no-css)
2611 " align=\"%s\"" " class=\"%s\"")
2612 (org-export-table-cell-alignment table-cell info)))))
2613 (when (or (not contents) (string= "" (org-trim contents)))
2614 (setq contents "&nbsp;"))
2615 (cond
2616 ((and (org-export-table-has-header-p table info)
2617 (= 1 (org-export-table-row-group table-row info)))
2618 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2619 contents (cdr org-html-table-header-tags)))
2620 ((and org-html-table-use-header-tags-for-first-column
2621 (zerop (cdr (org-export-table-cell-address table-cell info))))
2622 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2623 contents (cdr org-html-table-header-tags)))
2624 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2625 contents (cdr org-html-table-data-tags))))))
2628 ;;;; Table Row
2630 (defun org-html-table-row (table-row contents info)
2631 "Transcode a TABLE-ROW element from Org to HTML.
2632 CONTENTS is the contents of the row. INFO is a plist used as a
2633 communication channel."
2634 ;; Rules are ignored since table separators are deduced from
2635 ;; borders of the current row.
2636 (when (eq (org-element-property :type table-row) 'standard)
2637 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2638 (rowgroup-tags
2639 (cond
2640 ;; Case 1: Row belongs to second or subsequent rowgroups.
2641 ((not (= 1 (org-export-table-row-group table-row info)))
2642 '("<tbody>" . "\n</tbody>"))
2643 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2644 ((org-export-table-has-header-p
2645 (org-export-get-parent-table table-row) info)
2646 '("<thead>" . "\n</thead>"))
2647 ;; Case 2: Row is from first and only row group.
2648 (t '("<tbody>" . "\n</tbody>")))))
2649 (concat
2650 ;; Begin a rowgroup?
2651 (when (org-export-table-row-starts-rowgroup-p table-row info)
2652 (car rowgroup-tags))
2653 ;; Actual table row
2654 (concat "\n" (eval (car org-html-table-row-tags))
2655 contents
2656 "\n"
2657 (eval (cdr org-html-table-row-tags)))
2658 ;; End a rowgroup?
2659 (when (org-export-table-row-ends-rowgroup-p table-row info)
2660 (cdr rowgroup-tags))))))
2663 ;;;; Table
2665 (defun org-html-table-first-row-data-cells (table info)
2666 (let ((table-row
2667 (org-element-map table 'table-row
2668 (lambda (row)
2669 (unless (eq (org-element-property :type row) 'rule) row))
2670 info 'first-match))
2671 (special-column-p (org-export-table-has-special-column-p table)))
2672 (if (not special-column-p) (org-element-contents table-row)
2673 (cdr (org-element-contents table-row)))))
2675 (defun org-html-table--table.el-table (table info)
2676 (when (eq (org-element-property :type table) 'table.el)
2677 (require 'table)
2678 (let ((outbuf (with-current-buffer
2679 (get-buffer-create "*org-export-table*")
2680 (erase-buffer) (current-buffer))))
2681 (with-temp-buffer
2682 (insert (org-element-property :value table))
2683 (goto-char 1)
2684 (re-search-forward "^[ \t]*|[^|]" nil t)
2685 (table-generate-source 'html outbuf))
2686 (with-current-buffer outbuf
2687 (prog1 (org-trim (buffer-string))
2688 (kill-buffer) )))))
2690 (defun org-html-table (table contents info)
2691 "Transcode a TABLE element from Org to HTML.
2692 CONTENTS is the contents of the table. INFO is a plist holding
2693 contextual information."
2694 (case (org-element-property :type table)
2695 ;; Case 1: table.el table. Convert it using appropriate tools.
2696 (table.el (org-html-table--table.el-table table info))
2697 ;; Case 2: Standard table.
2699 (let* ((label (org-element-property :name table))
2700 (caption (org-export-get-caption table))
2701 (attributes (mapconcat #'identity
2702 (org-element-property :attr_html table)
2703 " "))
2704 (alignspec
2705 (if (and (boundp 'org-html-format-table-no-css)
2706 org-html-format-table-no-css)
2707 "align=\"%s\"" "class=\"%s\""))
2708 (table-column-specs
2709 (function
2710 (lambda (table info)
2711 (mapconcat
2712 (lambda (table-cell)
2713 (let ((alignment (org-export-table-cell-alignment
2714 table-cell info)))
2715 (concat
2716 ;; Begin a colgroup?
2717 (when (org-export-table-cell-starts-colgroup-p
2718 table-cell info)
2719 "\n<colgroup>")
2720 ;; Add a column. Also specify it's alignment.
2721 (format "\n<col %s/>" (format alignspec alignment))
2722 ;; End a colgroup?
2723 (when (org-export-table-cell-ends-colgroup-p
2724 table-cell info)
2725 "\n</colgroup>"))))
2726 (org-html-table-first-row-data-cells table info) "\n"))))
2727 (table-attributes
2728 (let ((table-tag (plist-get info :html-table-tag)))
2729 (concat
2730 (and (string-match "<table\\(.*\\)>" table-tag)
2731 (match-string 1 table-tag))
2732 (and label (format " id=\"%s\""
2733 (org-export-solidify-link-text label)))
2734 (unless (string= attributes "")
2735 (concat " " attributes))))))
2736 ;; Remove last blank line.
2737 (setq contents (substring contents 0 -1))
2738 (format "<table%s>\n%s\n%s\n%s\n</table>"
2739 table-attributes
2740 (if (not caption) ""
2741 (format "<caption>%s</caption>"
2742 (org-export-data caption info)))
2743 (funcall table-column-specs table info)
2744 contents)))))
2747 ;;;; Target
2749 (defun org-html-target (target contents info)
2750 "Transcode a TARGET object from Org to HTML.
2751 CONTENTS is nil. INFO is a plist holding contextual
2752 information."
2753 (let ((id (org-export-solidify-link-text
2754 (org-element-property :value target))))
2755 (org-html--anchor id)))
2758 ;;;; Timestamp
2760 (defun org-html-timestamp (timestamp contents info)
2761 "Transcode a TIMESTAMP object from Org to HTML.
2762 CONTENTS is nil. INFO is a plist holding contextual
2763 information."
2764 (let ((value (org-html-plain-text
2765 (org-timestamp-translate timestamp) info)))
2766 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2767 (replace-regexp-in-string "--" "&ndash;" value))))
2770 ;;;; Underline
2772 (defun org-html-underline (underline contents info)
2773 "Transcode UNDERLINE from Org to HTML.
2774 CONTENTS is the text with underline markup. INFO is a plist
2775 holding contextual information."
2776 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2777 contents))
2780 ;;;; Verbatim
2782 (defun org-html-verbatim (verbatim contents info)
2783 "Transcode VERBATIM from Org to HTML.
2784 CONTENTS is nil. INFO is a plist holding contextual
2785 information."
2786 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2787 (org-element-property :value verbatim)))
2790 ;;;; Verse Block
2792 (defun org-html-verse-block (verse-block contents info)
2793 "Transcode a VERSE-BLOCK element from Org to HTML.
2794 CONTENTS is verse block contents. INFO is a plist holding
2795 contextual information."
2796 ;; Replace each newline character with line break. Also replace
2797 ;; each blank line with a line break.
2798 (setq contents (replace-regexp-in-string
2799 "^ *\\\\\\\\$" "<br/>\n"
2800 (replace-regexp-in-string
2801 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2802 ;; Replace each white space at beginning of a line with a
2803 ;; non-breaking space.
2804 (while (string-match "^[ \t]+" contents)
2805 (let* ((num-ws (length (match-string 0 contents)))
2806 (ws (let (out) (dotimes (i num-ws out)
2807 (setq out (concat out "&nbsp;"))))))
2808 (setq contents (replace-match ws nil t contents))))
2809 (format "<p class=\"verse\">\n%s</p>" contents))
2813 ;;; Filter Functions
2815 (defun org-html-final-function (contents backend info)
2816 (if (not org-html-pretty-output) contents
2817 (with-temp-buffer
2818 (html-mode)
2819 (insert contents)
2820 (indent-region (point-min) (point-max))
2821 (buffer-substring-no-properties (point-min) (point-max)))))
2825 ;;; End-user functions
2827 ;;;###autoload
2828 (defun org-html-export-as-html
2829 (&optional async subtreep visible-only body-only ext-plist)
2830 "Export current buffer to an HTML buffer.
2832 If narrowing is active in the current buffer, only export its
2833 narrowed part.
2835 If a region is active, export that region.
2837 A non-nil optional argument ASYNC means the process should happen
2838 asynchronously. The resulting buffer should be accessible
2839 through the `org-export-stack' interface.
2841 When optional argument SUBTREEP is non-nil, export the sub-tree
2842 at point, extracting information from the headline properties
2843 first.
2845 When optional argument VISIBLE-ONLY is non-nil, don't export
2846 contents of hidden elements.
2848 When optional argument BODY-ONLY is non-nil, only write code
2849 between \"<body>\" and \"</body>\" tags.
2851 EXT-PLIST, when provided, is a property list with external
2852 parameters overriding Org default settings, but still inferior to
2853 file-local settings.
2855 Export is done in a buffer named \"*Org HTML Export*\", which
2856 will be displayed when `org-export-show-temporary-export-buffer'
2857 is non-nil."
2858 (interactive)
2859 (if async
2860 (org-export-async-start
2861 (lambda (output)
2862 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2863 (erase-buffer)
2864 (insert output)
2865 (goto-char (point-min))
2866 (funcall org-html-display-buffer-mode)
2867 (org-export-add-to-stack (current-buffer) 'html)))
2868 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2869 (let ((outbuf (org-export-to-buffer
2870 'html "*Org HTML Export*"
2871 subtreep visible-only body-only ext-plist)))
2872 ;; Set major mode.
2873 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2874 (when org-export-show-temporary-export-buffer
2875 (switch-to-buffer-other-window outbuf)))))
2877 ;;;###autoload
2878 (defun org-html-export-to-html
2879 (&optional async subtreep visible-only body-only ext-plist)
2880 "Export current buffer to a HTML file.
2882 If narrowing is active in the current buffer, only export its
2883 narrowed part.
2885 If a region is active, export that region.
2887 A non-nil optional argument ASYNC means the process should happen
2888 asynchronously. The resulting file should be accessible through
2889 the `org-export-stack' interface.
2891 When optional argument SUBTREEP is non-nil, export the sub-tree
2892 at point, extracting information from the headline properties
2893 first.
2895 When optional argument VISIBLE-ONLY is non-nil, don't export
2896 contents of hidden elements.
2898 When optional argument BODY-ONLY is non-nil, only write code
2899 between \"<body>\" and \"</body>\" tags.
2901 EXT-PLIST, when provided, is a property list with external
2902 parameters overriding Org default settings, but still inferior to
2903 file-local settings.
2905 Return output file's name."
2906 (interactive)
2907 (let* ((extension (concat "." org-html-extension))
2908 (file (org-export-output-file-name extension subtreep))
2909 (org-export-coding-system org-html-coding-system))
2910 (if async
2911 (org-export-async-start
2912 (lambda (f) (org-export-add-to-stack f 'html))
2913 (let ((org-export-coding-system org-html-coding-system))
2914 `(expand-file-name
2915 (org-export-to-file
2916 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2917 (let ((org-export-coding-system org-html-coding-system))
2918 (org-export-to-file
2919 'html file subtreep visible-only body-only ext-plist)))))
2921 ;;;###autoload
2922 (defun org-html-publish-to-html (plist filename pub-dir)
2923 "Publish an org file to HTML.
2925 FILENAME is the filename of the Org file to be published. PLIST
2926 is the property list for the given project. PUB-DIR is the
2927 publishing directory.
2929 Return output file name."
2930 (org-publish-org-to 'html filename ".html" plist pub-dir))
2934 ;;; FIXME
2936 ;;;; org-format-table-html
2937 ;;;; org-format-org-table-html
2938 ;;;; org-format-table-table-html
2939 ;;;; org-table-number-fraction
2940 ;;;; org-table-number-regexp
2941 ;;;; org-html-table-caption-above
2942 ;;;; org-html-with-timestamp
2943 ;;;; org-html-html-helper-timestamp
2944 ;;;; org-html-inline-image-extensions
2945 ;;;; org-export-preferred-target-alist
2946 ;;;; class for anchors
2947 ;;;; org-export-with-section-numbers, body-only
2948 ;;;; org-export-mark-todo-in-toc
2949 ;;;; org-html-format-org-link
2950 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
2951 ;;;; alt = (file-name-nondirectory path)
2953 (provide 'ox-html)
2955 ;; Local variables:
2956 ;; generated-autoload-file: "org-loaddefs.el"
2957 ;; End:
2959 ;;; ox-html.el ends here