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