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