3f67c5c50a26551c17e12884fa5c025e0a92e870
[org-mode.git] / lisp / ox-html.el
blob3f67c5c50a26551c17e12884fa5c025e0a92e870
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)
981 ;;; Internal Functions
983 (defun org-html-format-inline-image (src &optional
984 caption label attr standalone-p)
985 (let* ((id (if (not label) ""
986 (format " id=\"%s\"" (org-export-solidify-link-text label))))
987 (attr (concat attr
988 (cond
989 ((string-match "\\<alt=" (or attr "")) "")
990 ((string-match "^ltxpng/" src)
991 (format " alt=\"%s\""
992 (org-html-encode-plain-text
993 (org-find-text-property-in-string
994 'org-latex-src src))))
995 (t (format " alt=\"%s\""
996 (file-name-nondirectory src)))))))
997 (cond
998 (standalone-p
999 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1000 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1001 id (format "\n<p>%s</p>" img)
1002 (when caption (format "\n<p>%s</p>" caption)))))
1003 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1005 (defun org-html--textarea-block (element)
1006 "Transcode ELEMENT into a textarea block.
1007 ELEMENT is either a src block or an example block."
1008 (let ((code (car (org-export-unravel-code element)))
1009 (attr (org-export-read-attribute :attr_html element)))
1010 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1011 (or (plist-get attr :width) 80)
1012 (or (plist-get attr :height) (org-count-lines code))
1013 code)))
1016 ;;;; Bibliography
1018 (defun org-html-bibliography ()
1019 "Find bibliography, cut it out and return it."
1020 (catch 'exit
1021 (let (beg end (cnt 1) bib)
1022 (save-excursion
1023 (goto-char (point-min))
1024 (when (re-search-forward
1025 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1026 (setq beg (match-beginning 0))
1027 (while (re-search-forward "</?div\\>" nil t)
1028 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1029 (when (= cnt 0)
1030 (and (looking-at ">") (forward-char 1))
1031 (setq bib (buffer-substring beg (point)))
1032 (delete-region beg (point))
1033 (throw 'exit bib))))
1034 nil))))
1036 ;;;; Table
1038 (defun org-html-splice-attributes (tag attributes)
1039 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1040 (if (not attributes)
1042 (let (oldatt newatt)
1043 (setq oldatt (org-extract-attributes-from-string tag)
1044 tag (pop oldatt)
1045 newatt (cdr (org-extract-attributes-from-string attributes)))
1046 (while newatt
1047 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1048 (if (string-match ">" tag)
1049 (setq tag
1050 (replace-match (concat (org-attributes-to-string oldatt) ">")
1051 t t tag)))
1052 tag)))
1054 (defun org-export-splice-style (style extra)
1055 "Splice EXTRA into STYLE, just before \"</style>\"."
1056 (if (and (stringp extra)
1057 (string-match "\\S-" extra)
1058 (string-match "</style>" style))
1059 (concat (substring style 0 (match-beginning 0))
1060 "\n" extra "\n"
1061 (substring style (match-beginning 0)))
1062 style))
1064 (defun org-export-htmlize-region-for-paste (beg end)
1065 "Convert the region to HTML, using htmlize.el.
1066 This is much like `htmlize-region-for-paste', only that it uses
1067 the settings define in the org-... variables."
1068 (let* ((htmlize-output-type org-export-htmlize-output-type)
1069 (htmlize-css-name-prefix org-export-htmlize-font-prefix)
1070 (htmlbuf (htmlize-region beg end)))
1071 (unwind-protect
1072 (with-current-buffer htmlbuf
1073 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1074 (plist-get htmlize-buffer-places 'content-end)))
1075 (kill-buffer htmlbuf))))
1077 ;;;###autoload
1078 (defun org-export-htmlize-generate-css ()
1079 "Create the CSS for all font definitions in the current Emacs session.
1080 Use this to create face definitions in your CSS style file that can then
1081 be used by code snippets transformed by htmlize.
1082 This command just produces a buffer that contains class definitions for all
1083 faces used in the current Emacs session. You can copy and paste the ones you
1084 need into your CSS file.
1086 If you then set `org-export-htmlize-output-type' to `css', calls
1087 to the function `org-export-htmlize-region-for-paste' will
1088 produce code that uses these same face definitions."
1089 (interactive)
1090 (require 'htmlize)
1091 (and (get-buffer "*html*") (kill-buffer "*html*"))
1092 (with-temp-buffer
1093 (let ((fl (face-list))
1094 (htmlize-css-name-prefix "org-")
1095 (htmlize-output-type 'css)
1096 f i)
1097 (while (setq f (pop fl)
1098 i (and f (face-attribute f :inherit)))
1099 (when (and (symbolp f) (or (not i) (not (listp i))))
1100 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1101 (htmlize-region (point-min) (point-max))))
1102 (org-pop-to-buffer-same-window "*html*")
1103 (goto-char (point-min))
1104 (if (re-search-forward "<style" nil t)
1105 (delete-region (point-min) (match-beginning 0)))
1106 (if (re-search-forward "</style>" nil t)
1107 (delete-region (1+ (match-end 0)) (point-max)))
1108 (beginning-of-line 1)
1109 (if (looking-at " +") (replace-match ""))
1110 (goto-char (point-min)))
1112 (defun org-html--make-string (n string)
1113 "Build a string by concatenating N times STRING."
1114 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1116 (defun org-html-toc-text (toc-entries)
1117 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1118 (start-level prev-level))
1119 (concat
1120 (mapconcat
1121 (lambda (entry)
1122 (let ((headline (nth 0 entry))
1123 (level (nth 1 entry)))
1124 (concat
1125 (let* ((cnt (- level prev-level))
1126 (times (if (> cnt 0) (1- cnt) (- cnt)))
1127 rtn)
1128 (setq prev-level level)
1129 (concat
1130 (org-html--make-string
1131 times (cond ((> cnt 0) "\n<ul>\n<li>")
1132 ((< cnt 0) "</li>\n</ul>\n")))
1133 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1134 headline)))
1135 toc-entries "")
1136 (org-html--make-string (- prev-level start-level) "</li>\n</ul>\n"))))
1138 (defun* org-html-format-toc-headline
1139 (todo todo-type priority text tags
1140 &key level section-number headline-label &allow-other-keys)
1141 (let ((headline (concat
1142 section-number (and section-number ". ")
1143 text
1144 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags))))
1145 (format "<a href=\"#%s\">%s</a>"
1146 (org-export-solidify-link-text headline-label)
1147 (if (not nil) headline
1148 (format "<span class=\"%s\">%s</span>" todo-type headline)))))
1150 (defun org-html-toc (depth info)
1151 (let* ((headlines (org-export-collect-headlines info depth))
1152 (toc-entries
1153 (loop for headline in headlines collect
1154 (list (org-html-format-headline--wrap
1155 headline info 'org-html-format-toc-headline)
1156 (org-export-get-relative-level headline info)))))
1157 (when toc-entries
1158 (concat
1159 "<div id=\"table-of-contents\">\n"
1160 (format "<h%d>%s</h%d>\n"
1161 org-html-toplevel-hlevel
1162 (org-html--translate "Table of Contents" info)
1163 org-html-toplevel-hlevel)
1164 "<div id=\"text-table-of-contents\">"
1165 (org-html-toc-text toc-entries)
1166 "</div>\n"
1167 "</div>\n"))))
1169 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1170 "Turn todo keyword into a valid class name.
1171 Replaces invalid characters with \"_\"."
1172 (save-match-data
1173 (while (string-match "[^a-zA-Z0-9_]" kwd)
1174 (setq kwd (replace-match "_" t t kwd))))
1175 kwd)
1177 (defun org-html-format-footnote-reference (n def refcnt)
1178 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1179 (format org-html-footnote-format
1180 (let* ((id (format "fnr.%s%s" n extra))
1181 (href (format " href=\"#fn.%s\"" n))
1182 (attributes (concat " class=\"footref\"" href)))
1183 (org-html--anchor id n attributes)))))
1185 (defun org-html-format-footnotes-section (section-name definitions)
1186 (if (not definitions) ""
1187 (format org-html-footnotes-section section-name definitions)))
1189 (defun org-html-format-footnote-definition (fn)
1190 (let ((n (car fn)) (def (cdr fn)))
1191 (format
1192 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1193 (format org-html-footnote-format
1194 (let* ((id (format "fn.%s" n))
1195 (href (format " href=\"#fnr.%s\"" n))
1196 (attributes (concat " class=\"footnum\"" href)))
1197 (org-html--anchor id n attributes)))
1198 def)))
1200 (defun org-html-footnote-section (info)
1201 (let* ((fn-alist (org-export-collect-footnote-definitions
1202 (plist-get info :parse-tree) info))
1204 (fn-alist
1205 (loop for (n type raw) in fn-alist collect
1206 (cons n (if (eq (org-element-type raw) 'org-data)
1207 (org-trim (org-export-data raw info))
1208 (format "<p>%s</p>"
1209 (org-trim (org-export-data raw info))))))))
1210 (when fn-alist
1211 (org-html-format-footnotes-section
1212 (org-html--translate "Footnotes" info)
1213 (format
1214 "<table>\n%s\n</table>\n"
1215 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1219 ;;; Template
1221 (defun org-html--build-meta-info (info)
1222 "Return meta tags for exported document.
1223 INFO is a plist used as a communication channel."
1224 (let* ((title (org-export-data (plist-get info :title) info))
1225 (author (and (plist-get info :with-author)
1226 (let ((auth (plist-get info :author)))
1227 (and auth (org-export-data auth info)))))
1228 (date (and (plist-get info :with-date)
1229 (let ((date (plist-get info :date)))
1230 (and date (org-export-data date info)))))
1231 (description (plist-get info :description))
1232 (keywords (plist-get info :keywords)))
1233 (concat
1234 (format "<title>%s</title>\n" title)
1235 (format
1236 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1237 (or (and org-html-coding-system
1238 (fboundp 'coding-system-get)
1239 (coding-system-get org-html-coding-system 'mime-charset))
1240 "iso-8859-1"))
1241 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1242 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1243 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1244 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1245 (and description
1246 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1247 (and keywords
1248 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1250 (defun org-html--build-style (info)
1251 "Return style information for exported document.
1252 INFO is a plist used as a communication channel."
1253 (org-element-normalize-string
1254 (concat
1255 (when (plist-get info :html-style-include-default) org-html-style-default)
1256 (org-element-normalize-string (plist-get info :html-style))
1257 (org-element-normalize-string (plist-get info :html-style-extra))
1258 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1260 (defun org-html--build-mathjax-config (info)
1261 "Insert the user setup into the mathjax template.
1262 INFO is a plist used as a communication channel."
1263 (when (memq (plist-get info :with-latex) '(mathjax t))
1264 (let ((template org-html-mathjax-template)
1265 (options org-html-mathjax-options)
1266 (in-buffer (or (plist-get info :html-mathjax) ""))
1267 name val (yes " ") (no "// ") x)
1268 (mapc
1269 (lambda (e)
1270 (setq name (car e) val (nth 1 e))
1271 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1272 (setq val (car (read-from-string
1273 (substring in-buffer (match-end 0))))))
1274 (if (not (stringp val)) (setq val (format "%s" val)))
1275 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1276 (setq template (replace-match val t t template))))
1277 options)
1278 (setq val (nth 1 (assq 'mathml options)))
1279 (if (string-match (concat "\\<mathml:") in-buffer)
1280 (setq val (car (read-from-string
1281 (substring in-buffer (match-end 0))))))
1282 ;; Exchange prefixes depending on mathml setting.
1283 (if (not val) (setq x yes yes no no x))
1284 ;; Replace cookies to turn on or off the config/jax lines.
1285 (if (string-match ":MMLYES:" template)
1286 (setq template (replace-match yes t t template)))
1287 (if (string-match ":MMLNO:" template)
1288 (setq template (replace-match no t t template)))
1289 ;; Return the modified template.
1290 (org-element-normalize-string template))))
1292 (defun org-html--build-preamble (info)
1293 "Return document preamble as a string, or nil.
1294 INFO is a plist used as a communication channel."
1295 (let ((preamble (plist-get info :html-preamble)))
1296 (when preamble
1297 (let ((preamble-contents
1298 (if (functionp preamble) (funcall preamble info)
1299 (let ((title (org-export-data (plist-get info :title) info))
1300 (date (if (not (plist-get info :with-date)) ""
1301 (org-export-data (plist-get info :date) info)))
1302 (author (if (not (plist-get info :with-author)) ""
1303 (org-export-data (plist-get info :author) info)))
1304 (email (if (not (plist-get info :with-email)) ""
1305 (plist-get info :email))))
1306 (if (stringp preamble)
1307 (format-spec preamble
1308 `((?t . ,title) (?a . ,author)
1309 (?d . ,date) (?e . ,email)))
1310 (format-spec
1311 (or (cadr (assoc (plist-get info :language)
1312 org-html-preamble-format))
1313 (cadr (assoc "en" org-html-preamble-format)))
1314 `((?t . ,title) (?a . ,author)
1315 (?d . ,date) (?e . ,email))))))))
1316 (when (org-string-nw-p preamble-contents)
1317 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1318 (org-element-normalize-string preamble-contents)
1319 "</div>\n"))))))
1321 (defun org-html--build-postamble (info)
1322 "Return document postamble as a string, or nil.
1323 INFO is a plist used as a communication channel."
1324 (let ((postamble (plist-get info :html-postamble)))
1325 (when postamble
1326 (let ((postamble-contents
1327 (if (functionp postamble) (funcall postamble info)
1328 (let ((date (if (not (plist-get info :with-date)) ""
1329 (org-export-data (plist-get info :date) info)))
1330 (author (let ((author (plist-get info :author)))
1331 (and author (org-export-data author info))))
1332 (email (mapconcat
1333 (lambda (e)
1334 (format "<a href=\"mailto:%s\">%s</a>" e e))
1335 (split-string (plist-get info :email) ",+ *")
1336 ", "))
1337 (html-validation-link (or org-html-validation-link ""))
1338 (creator-info (plist-get info :creator)))
1339 (cond ((stringp postamble)
1340 (format-spec postamble
1341 `((?a . ,author) (?e . ,email)
1342 (?d . ,date) (?c . ,creator-info)
1343 (?v . ,html-validation-link))))
1344 ((eq postamble 'auto)
1345 (concat
1346 (when (plist-get info :time-stamp-file)
1347 (format "<p class=\"date\">%s: %s</p>\n"
1348 (org-html--translate "Date" info)
1349 date))
1350 (when (and (plist-get info :with-author) author)
1351 (format "<p class=\"author\">%s : %s</p>\n"
1352 (org-html--translate "Author" info)
1353 author))
1354 (when (and (plist-get info :with-email) email)
1355 (format "<p class=\"email\">%s </p>\n" email))
1356 (when (plist-get info :with-creator)
1357 (format "<p class=\"creator\">%s</p>\n"
1358 creator-info))
1359 html-validation-link "\n"))
1360 (t (format-spec
1361 (or (cadr (assoc (plist-get info :language)
1362 org-html-postamble-format))
1363 (cadr (assoc "en" org-html-postamble-format)))
1364 `((?a . ,author) (?e . ,email)
1365 (?d . ,date) (?c . ,creator-info)
1366 (?v . ,html-validation-link)))))))))
1367 (when (org-string-nw-p postamble-contents)
1368 (concat
1369 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1370 (org-element-normalize-string postamble-contents)
1371 "</div>\n"))))))
1373 (defun org-html-inner-template (contents info)
1374 "Return body of document string after HTML conversion.
1375 CONTENTS is the transcoded contents string. INFO is a plist
1376 holding export options."
1377 (concat
1378 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1379 ;; Document title.
1380 (format "<h1 class=\"title\">%s</h1>\n"
1381 (org-export-data (plist-get info :title) info))
1382 ;; Table of contents.
1383 (let ((depth (plist-get info :with-toc)))
1384 (when depth (org-html-toc depth info)))
1385 ;; Document contents.
1386 contents
1387 ;; Footnotes section.
1388 (org-html-footnote-section info)
1389 ;; Bibliography.
1390 (org-html-bibliography)
1391 "\n</div>"))
1393 (defun org-html-template (contents info)
1394 "Return complete document string after HTML conversion.
1395 CONTENTS is the transcoded contents string. INFO is a plist
1396 holding export options."
1397 (concat
1398 (format
1399 (or (and (stringp org-html-xml-declaration)
1400 org-html-xml-declaration)
1401 (cdr (assoc (plist-get info :html-extension)
1402 org-html-xml-declaration))
1403 (cdr (assoc "html" org-html-xml-declaration))
1406 (or (and org-html-coding-system
1407 (fboundp 'coding-system-get)
1408 (coding-system-get org-html-coding-system 'mime-charset))
1409 "iso-8859-1"))
1410 "\n"
1411 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1412 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1413 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1414 (plist-get info :language) (plist-get info :language))
1415 "<head>\n"
1416 (org-html--build-meta-info info)
1417 (org-html--build-style info)
1418 (org-html--build-mathjax-config info)
1419 "</head>\n"
1420 "<body>\n"
1421 (let ((link-up (org-trim (plist-get info :html-link-up)))
1422 (link-home (org-trim (plist-get info :html-link-home))))
1423 (unless (and (string= link-up "") (string= link-up ""))
1424 (format org-html-home/up-format
1425 (or link-up link-home)
1426 (or link-home link-up))))
1427 ;; Preamble.
1428 (org-html--build-preamble info)
1429 ;; Document contents.
1430 contents
1431 ;; Postamble.
1432 (org-html--build-postamble info)
1433 ;; Closing document.
1434 "</body>\n</html>"))
1436 (defun org-html--translate (s info)
1437 "Translate string S according to specified language.
1438 INFO is a plist used as a communication channel."
1439 (org-export-translate s :html info))
1441 ;;;; Anchor
1443 (defun org-html--anchor (&optional id desc attributes)
1444 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1445 (attributes (concat (and id (format " id=\"%s\"" id))
1446 (and name (format " name=\"%s\"" name))
1447 attributes)))
1448 (format "<a%s>%s</a>" attributes (or desc ""))))
1450 ;;;; Todo
1452 (defun org-html--todo (todo)
1453 (when todo
1454 (format "<span class=\"%s %s%s\">%s</span>"
1455 (if (member todo org-done-keywords) "done" "todo")
1456 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1457 todo)))
1459 ;;;; Tags
1461 (defun org-html--tags (tags)
1462 (when tags
1463 (format "<span class=\"tag\">%s</span>"
1464 (mapconcat
1465 (lambda (tag)
1466 (format "<span class=\"%s\">%s</span>"
1467 (concat org-html-tag-class-prefix
1468 (org-html-fix-class-name tag))
1469 tag))
1470 tags "&nbsp;"))))
1472 ;;;; Headline
1474 (defun* org-html-format-headline
1475 (todo todo-type priority text tags
1476 &key level section-number headline-label &allow-other-keys)
1477 (let ((section-number
1478 (when section-number
1479 (format "<span class=\"section-number-%d\">%s</span> "
1480 level section-number)))
1481 (todo (org-html--todo todo))
1482 (tags (org-html--tags tags)))
1483 (concat section-number todo (and todo " ") text
1484 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1486 ;;;; Src Code
1488 (defun org-html-fontify-code (code lang)
1489 "Color CODE with htmlize library.
1490 CODE is a string representing the source code to colorize. LANG
1491 is the language used for CODE, as a string, or nil."
1492 (when code
1493 (cond
1494 ;; Case 1: No lang. Possibly an example block.
1495 ((not lang)
1496 ;; Simple transcoding.
1497 (org-html-encode-plain-text code))
1498 ;; Case 2: No htmlize or an inferior version of htmlize
1499 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1500 ;; Emit a warning.
1501 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1502 ;; Simple transcoding.
1503 (org-html-encode-plain-text code))
1505 ;; Map language
1506 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1507 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1508 (cond
1509 ;; Case 1: Language is not associated with any Emacs mode
1510 ((not (functionp lang-mode))
1511 ;; Simple transcoding.
1512 (org-html-encode-plain-text code))
1513 ;; Case 2: Default. Fontify code.
1515 ;; htmlize
1516 (setq code (with-temp-buffer
1517 ;; Switch to language-specific mode.
1518 (funcall lang-mode)
1519 (insert code)
1520 ;; Fontify buffer.
1521 (font-lock-fontify-buffer)
1522 ;; Remove formatting on newline characters.
1523 (save-excursion
1524 (let ((beg (point-min))
1525 (end (point-max)))
1526 (goto-char beg)
1527 (while (progn (end-of-line) (< (point) end))
1528 (put-text-property (point) (1+ (point)) 'face nil)
1529 (forward-char 1))))
1530 (org-src-mode)
1531 (set-buffer-modified-p nil)
1532 ;; Htmlize region.
1533 (org-export-htmlize-region-for-paste
1534 (point-min) (point-max))))
1535 ;; Strip any encolosing <pre></pre> tags.
1536 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1537 (match-string 1 code)
1538 code))))))))
1540 (defun org-html-do-format-code
1541 (code &optional lang refs retain-labels num-start)
1542 "Format CODE string as source code.
1543 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1544 respectively, the language of the source code, as a string, an
1545 alist between line numbers and references (as returned by
1546 `org-export-unravel-code'), a boolean specifying if labels should
1547 appear in the source code, and the number associated to the first
1548 line of code."
1549 (let* ((code-lines (org-split-string code "\n"))
1550 (code-length (length code-lines))
1551 (num-fmt
1552 (and num-start
1553 (format "%%%ds: "
1554 (length (number-to-string (+ code-length num-start))))))
1555 (code (org-html-fontify-code code lang)))
1556 (org-export-format-code
1557 code
1558 (lambda (loc line-num ref)
1559 (setq loc
1560 (concat
1561 ;; Add line number, if needed.
1562 (when num-start
1563 (format "<span class=\"linenr\">%s</span>"
1564 (format num-fmt line-num)))
1565 ;; Transcoded src line.
1567 ;; Add label, if needed.
1568 (when (and ref retain-labels) (format " (%s)" ref))))
1569 ;; Mark transcoded line as an anchor, if needed.
1570 (if (not ref) loc
1571 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1572 ref loc)))
1573 num-start refs)))
1575 (defun org-html-format-code (element info)
1576 "Format contents of ELEMENT as source code.
1577 ELEMENT is either an example block or a src block. INFO is
1578 a plist used as a communication channel."
1579 (let* ((lang (org-element-property :language element))
1580 ;; Extract code and references.
1581 (code-info (org-export-unravel-code element))
1582 (code (car code-info))
1583 (refs (cdr code-info))
1584 ;; Does the src block contain labels?
1585 (retain-labels (org-element-property :retain-labels element))
1586 ;; Does it have line numbers?
1587 (num-start (case (org-element-property :number-lines element)
1588 (continued (org-export-get-loc element info))
1589 (new 0))))
1590 (org-html-do-format-code code lang refs retain-labels num-start)))
1594 ;;; Transcode Functions
1596 ;;;; Bold
1598 (defun org-html-bold (bold contents info)
1599 "Transcode BOLD from Org to HTML.
1600 CONTENTS is the text with bold markup. INFO is a plist holding
1601 contextual information."
1602 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1603 contents))
1606 ;;;; Center Block
1608 (defun org-html-center-block (center-block contents info)
1609 "Transcode a CENTER-BLOCK element from Org to HTML.
1610 CONTENTS holds the contents of the block. INFO is a plist
1611 holding contextual information."
1612 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1615 ;;;; Clock
1617 (defun org-html-clock (clock contents info)
1618 "Transcode a CLOCK element from Org to HTML.
1619 CONTENTS is nil. INFO is a plist used as a communication
1620 channel."
1621 (format "<p>
1622 <span class=\"timestamp-wrapper\">
1623 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1624 </span>
1625 </p>"
1626 org-clock-string
1627 (org-translate-time
1628 (org-element-property :raw-value
1629 (org-element-property :value clock)))
1630 (let ((time (org-element-property :duration clock)))
1631 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1634 ;;;; Code
1636 (defun org-html-code (code contents info)
1637 "Transcode CODE from Org to HTML.
1638 CONTENTS is nil. INFO is a plist holding contextual
1639 information."
1640 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1641 (org-element-property :value code)))
1644 ;;;; Drawer
1646 (defun org-html-drawer (drawer contents info)
1647 "Transcode a DRAWER element from Org to HTML.
1648 CONTENTS holds the contents of the block. INFO is a plist
1649 holding contextual information."
1650 (if (functionp org-html-format-drawer-function)
1651 (funcall org-html-format-drawer-function
1652 (org-element-property :drawer-name drawer)
1653 contents)
1654 ;; If there's no user defined function: simply
1655 ;; display contents of the drawer.
1656 contents))
1659 ;;;; Dynamic Block
1661 (defun org-html-dynamic-block (dynamic-block contents info)
1662 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1663 CONTENTS holds the contents of the block. INFO is a plist
1664 holding contextual information. See `org-export-data'."
1665 contents)
1668 ;;;; Entity
1670 (defun org-html-entity (entity contents info)
1671 "Transcode an ENTITY object from Org to HTML.
1672 CONTENTS are the definition itself. INFO is a plist holding
1673 contextual information."
1674 (org-element-property :html entity))
1677 ;;;; Example Block
1679 (defun org-html-example-block (example-block contents info)
1680 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1681 CONTENTS is nil. INFO is a plist holding contextual
1682 information."
1683 (if (org-export-read-attribute :attr_html example-block :textarea)
1684 (org-html--textarea-block example-block)
1685 (format "<pre class=\"example\">\n%s</pre>"
1686 (org-html-format-code example-block info))))
1689 ;;;; Export Snippet
1691 (defun org-html-export-snippet (export-snippet contents info)
1692 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1693 CONTENTS is nil. INFO is a plist holding contextual
1694 information."
1695 (when (eq (org-export-snippet-backend export-snippet) 'html)
1696 (org-element-property :value export-snippet)))
1699 ;;;; Export Block
1701 (defun org-html-export-block (export-block contents info)
1702 "Transcode a EXPORT-BLOCK element from Org to HTML.
1703 CONTENTS is nil. INFO is a plist holding contextual information."
1704 (when (string= (org-element-property :type export-block) "HTML")
1705 (org-remove-indentation (org-element-property :value export-block))))
1708 ;;;; Fixed Width
1710 (defun org-html-fixed-width (fixed-width contents info)
1711 "Transcode a FIXED-WIDTH element from Org to HTML.
1712 CONTENTS is nil. INFO is a plist holding contextual information."
1713 (format "<pre class=\"example\">\n%s</pre>"
1714 (org-html-do-format-code
1715 (org-remove-indentation
1716 (org-element-property :value fixed-width)))))
1719 ;;;; Footnote Reference
1721 (defun org-html-footnote-reference (footnote-reference contents info)
1722 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1723 CONTENTS is nil. INFO is a plist holding contextual information."
1724 (concat
1725 ;; Insert separator between two footnotes in a row.
1726 (let ((prev (org-export-get-previous-element footnote-reference info)))
1727 (when (eq (org-element-type prev) 'footnote-reference)
1728 org-html-footnote-separator))
1729 (cond
1730 ((not (org-export-footnote-first-reference-p footnote-reference info))
1731 (org-html-format-footnote-reference
1732 (org-export-get-footnote-number footnote-reference info)
1733 "IGNORED" 100))
1734 ;; Inline definitions are secondary strings.
1735 ((eq (org-element-property :type footnote-reference) 'inline)
1736 (org-html-format-footnote-reference
1737 (org-export-get-footnote-number footnote-reference info)
1738 "IGNORED" 1))
1739 ;; Non-inline footnotes definitions are full Org data.
1740 (t (org-html-format-footnote-reference
1741 (org-export-get-footnote-number footnote-reference info)
1742 "IGNORED" 1)))))
1745 ;;;; Headline
1747 (defun org-html-format-headline--wrap (headline info
1748 &optional format-function
1749 &rest extra-keys)
1750 "Transcode an HEADLINE element from Org to HTML.
1751 CONTENTS holds the contents of the headline. INFO is a plist
1752 holding contextual information."
1753 (let* ((level (+ (org-export-get-relative-level headline info)
1754 (1- org-html-toplevel-hlevel)))
1755 (headline-number (org-export-get-headline-number headline info))
1756 (section-number (and (not (org-export-low-level-p headline info))
1757 (org-export-numbered-headline-p headline info)
1758 (mapconcat 'number-to-string
1759 headline-number ".")))
1760 (todo (and (plist-get info :with-todo-keywords)
1761 (let ((todo (org-element-property :todo-keyword headline)))
1762 (and todo (org-export-data todo info)))))
1763 (todo-type (and todo (org-element-property :todo-type headline)))
1764 (priority (and (plist-get info :with-priority)
1765 (org-element-property :priority headline)))
1766 (text (org-export-data (org-element-property :title headline) info))
1767 (tags (and (plist-get info :with-tags)
1768 (org-export-get-tags headline info)))
1769 (headline-label (or (org-element-property :custom-id headline)
1770 (concat "sec-" (mapconcat 'number-to-string
1771 headline-number "-"))))
1772 (format-function (cond
1773 ((functionp format-function) format-function)
1774 ((functionp org-html-format-headline-function)
1775 (function*
1776 (lambda (todo todo-type priority text tags
1777 &allow-other-keys)
1778 (funcall org-html-format-headline-function
1779 todo todo-type priority text tags))))
1780 (t 'org-html-format-headline))))
1781 (apply format-function
1782 todo todo-type priority text tags
1783 :headline-label headline-label :level level
1784 :section-number section-number extra-keys)))
1786 (defun org-html-headline (headline contents info)
1787 "Transcode an HEADLINE element from Org to HTML.
1788 CONTENTS holds the contents of the headline. INFO is a plist
1789 holding contextual information."
1790 ;; Empty contents?
1791 (setq contents (or contents ""))
1792 (let* ((numberedp (org-export-numbered-headline-p headline info))
1793 (level (org-export-get-relative-level headline info))
1794 (text (org-export-data (org-element-property :title headline) info))
1795 (todo (and (plist-get info :with-todo-keywords)
1796 (let ((todo (org-element-property :todo-keyword headline)))
1797 (and todo (org-export-data todo info)))))
1798 (todo-type (and todo (org-element-property :todo-type headline)))
1799 (tags (and (plist-get info :with-tags)
1800 (org-export-get-tags headline info)))
1801 (priority (and (plist-get info :with-priority)
1802 (org-element-property :priority headline)))
1803 (section-number (and (org-export-numbered-headline-p headline info)
1804 (mapconcat 'number-to-string
1805 (org-export-get-headline-number
1806 headline info) ".")))
1807 ;; Create the headline text.
1808 (full-text (org-html-format-headline--wrap headline info)))
1809 (cond
1810 ;; Case 1: This is a footnote section: ignore it.
1811 ((org-element-property :footnote-section-p headline) nil)
1812 ;; Case 2. This is a deep sub-tree: export it as a list item.
1813 ;; Also export as items headlines for which no section
1814 ;; format has been found.
1815 ((org-export-low-level-p headline info)
1816 ;; Build the real contents of the sub-tree.
1817 (let* ((type (if numberedp 'ordered 'unordered))
1818 (itemized-body (org-html-format-list-item
1819 contents type nil nil full-text)))
1820 (concat
1821 (and (org-export-first-sibling-p headline info)
1822 (org-html-begin-plain-list type))
1823 itemized-body
1824 (and (org-export-last-sibling-p headline info)
1825 (org-html-end-plain-list type)))))
1826 ;; Case 3. Standard headline. Export it as a section.
1828 (let* ((section-number (mapconcat 'number-to-string
1829 (org-export-get-headline-number
1830 headline info) "-"))
1831 (ids (remove 'nil
1832 (list (org-element-property :custom-id headline)
1833 (concat "sec-" section-number)
1834 (org-element-property :id headline))))
1835 (preferred-id (car ids))
1836 (extra-ids (cdr ids))
1837 (extra-class (org-element-property :html-container-class headline))
1838 (level1 (+ level (1- org-html-toplevel-hlevel))))
1839 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1840 (format "outline-container-%s"
1841 (or (org-element-property :custom-id headline)
1842 section-number))
1843 (concat (format "outline-%d" level1) (and extra-class " ")
1844 extra-class)
1845 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1846 level1
1847 preferred-id
1848 (mapconcat
1849 (lambda (x)
1850 (let ((id (org-export-solidify-link-text
1851 (if (org-uuidgen-p x) (concat "ID-" x)
1852 x))))
1853 (org-html--anchor id)))
1854 extra-ids "")
1855 full-text
1856 level1)
1857 contents))))))
1860 ;;;; Horizontal Rule
1862 (defun org-html-horizontal-rule (horizontal-rule contents info)
1863 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1864 CONTENTS is nil. INFO is a plist holding contextual information."
1865 "<hr/>")
1868 ;;;; Inline Src Block
1870 (defun org-html-inline-src-block (inline-src-block contents info)
1871 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1872 CONTENTS holds the contents of the item. INFO is a plist holding
1873 contextual information."
1874 (let* ((org-lang (org-element-property :language inline-src-block))
1875 (code (org-element-property :value inline-src-block)))
1876 (error "FIXME")))
1879 ;;;; Inlinetask
1881 (defun org-html-format-section (text class &optional id)
1882 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1883 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1885 (defun org-html-inlinetask (inlinetask contents info)
1886 "Transcode an INLINETASK element from Org to HTML.
1887 CONTENTS holds the contents of the block. INFO is a plist
1888 holding contextual information."
1889 (cond
1890 ;; If `org-html-format-inlinetask-function' is provided, call it
1891 ;; with appropriate arguments.
1892 ((functionp org-html-format-inlinetask-function)
1893 (let ((format-function
1894 (function*
1895 (lambda (todo todo-type priority text tags
1896 &key contents &allow-other-keys)
1897 (funcall org-html-format-inlinetask-function
1898 todo todo-type priority text tags contents)))))
1899 (org-html-format-headline--wrap
1900 inlinetask info format-function :contents contents)))
1901 ;; Otherwise, use a default template.
1902 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1903 (org-html-format-headline--wrap inlinetask info)
1904 contents))))
1907 ;;;; Italic
1909 (defun org-html-italic (italic contents info)
1910 "Transcode ITALIC from Org to HTML.
1911 CONTENTS is the text with italic markup. INFO is a plist holding
1912 contextual information."
1913 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
1916 ;;;; Item
1918 (defun org-html-checkbox (checkbox)
1919 (case checkbox (on "<code>[X]</code>")
1920 (off "<code>[&nbsp;]</code>")
1921 (trans "<code>[-]</code>")
1922 (t "")))
1924 (defun org-html-format-list-item (contents type checkbox
1925 &optional term-counter-id
1926 headline)
1927 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
1928 (concat
1929 (case type
1930 (ordered
1931 (let* ((counter term-counter-id)
1932 (extra (if counter (format " value=\"%s\"" counter) "")))
1933 (concat
1934 (format "<li%s>" extra)
1935 (when headline (concat headline "<br/>")))))
1936 (unordered
1937 (let* ((id term-counter-id)
1938 (extra (if id (format " id=\"%s\"" id) "")))
1939 (concat
1940 (format "<li%s>" extra)
1941 (when headline (concat headline "<br/>")))))
1942 (descriptive
1943 (let* ((term term-counter-id))
1944 (setq term (or term "(no term)"))
1945 ;; Check-boxes in descriptive lists are associated to tag.
1946 (concat (format "<dt> %s </dt>"
1947 (concat checkbox term))
1948 "<dd>"))))
1949 (unless (eq type 'descriptive) checkbox)
1950 contents
1951 (case type
1952 (ordered "</li>")
1953 (unordered "</li>")
1954 (descriptive "</dd>")))))
1956 (defun org-html-item (item contents info)
1957 "Transcode an ITEM element from Org to HTML.
1958 CONTENTS holds the contents of the item. INFO is a plist holding
1959 contextual information."
1960 (let* ((plain-list (org-export-get-parent item))
1961 (type (org-element-property :type plain-list))
1962 (counter (org-element-property :counter item))
1963 (checkbox (org-element-property :checkbox item))
1964 (tag (let ((tag (org-element-property :tag item)))
1965 (and tag (org-export-data tag info)))))
1966 (org-html-format-list-item
1967 contents type checkbox (or tag counter))))
1970 ;;;; Keyword
1972 (defun org-html-keyword (keyword contents info)
1973 "Transcode a KEYWORD element from Org to HTML.
1974 CONTENTS is nil. INFO is a plist holding contextual information."
1975 (let ((key (org-element-property :key keyword))
1976 (value (org-element-property :value keyword)))
1977 (cond
1978 ((string= key "HTML") value)
1979 ((string= key "INDEX") (format "\\index{%s}" value))
1980 ;; Invisible targets.
1981 ((string= key "TARGET") nil)
1982 ((string= key "TOC")
1983 (let ((value (downcase value)))
1984 (cond
1985 ((string-match "\\<headlines\\>" value)
1986 (let ((depth (or (and (string-match "[0-9]+" value)
1987 (string-to-number (match-string 0 value)))
1988 (plist-get info :with-toc))))
1989 (org-html-toc depth info)))
1990 ((string= "tables" value) "\\listoftables")
1991 ((string= "figures" value) "\\listoffigures")
1992 ((string= "listings" value)
1993 (cond
1994 ;; At the moment, src blocks with a caption are wrapped
1995 ;; into a figure environment.
1996 (t "\\listoffigures")))))))))
1999 ;;;; Latex Environment
2001 (defun org-html-format-latex (latex-frag processing-type)
2002 "Format LaTeX fragments into HTML."
2003 (let (cache-relpath cache-dir bfn)
2004 (unless (eq processing-type 'mathjax)
2005 (setq bfn (buffer-file-name)
2006 cache-relpath
2007 (concat "ltxpng/"
2008 (file-name-sans-extension
2009 (file-name-nondirectory bfn)))
2010 cache-dir (file-name-directory bfn)))
2011 (with-temp-buffer
2012 (insert latex-frag)
2013 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2014 nil nil processing-type)
2015 (buffer-string))))
2017 (defun org-html-latex-environment (latex-environment contents info)
2018 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2019 CONTENTS is nil. INFO is a plist holding contextual information."
2020 (let ((processing-type (plist-get info :with-latex))
2021 (latex-frag (org-remove-indentation
2022 (org-element-property :value latex-environment)))
2023 (caption (org-export-data
2024 (org-export-get-caption latex-environment) info))
2025 (attr nil) ; FIXME
2026 (label (org-element-property :name latex-environment)))
2027 (cond
2028 ((memq processing-type '(t mathjax))
2029 (org-html-format-latex latex-frag 'mathjax))
2030 ((eq processing-type 'dvipng)
2031 (let* ((formula-link (org-html-format-latex
2032 latex-frag processing-type)))
2033 (when (and formula-link
2034 (string-match "file:\\([^]]*\\)" formula-link))
2035 (org-html-format-inline-image
2036 (match-string 1 formula-link) caption label attr t))))
2037 (t latex-frag))))
2040 ;;;; Latex Fragment
2042 (defun org-html-latex-fragment (latex-fragment contents info)
2043 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2044 CONTENTS is nil. INFO is a plist holding contextual information."
2045 (let ((latex-frag (org-element-property :value latex-fragment))
2046 (processing-type (plist-get info :with-latex)))
2047 (case processing-type
2048 ((t mathjax)
2049 (org-html-format-latex latex-frag 'mathjax))
2050 (dvipng
2051 (let* ((formula-link (org-html-format-latex
2052 latex-frag processing-type)))
2053 (when (and formula-link
2054 (string-match "file:\\([^]]*\\)" formula-link))
2055 (org-html-format-inline-image
2056 (match-string 1 formula-link)))))
2057 (t latex-frag))))
2060 ;;;; Line Break
2062 (defun org-html-line-break (line-break contents info)
2063 "Transcode a LINE-BREAK object from Org to HTML.
2064 CONTENTS is nil. INFO is a plist holding contextual information."
2065 "<br/>\n")
2068 ;;;; Link
2070 (defun org-html-link--inline-image (link desc info)
2071 "Return HTML code for an inline image.
2072 LINK is the link pointing to the inline image. INFO is a plist
2073 used as a communication channel."
2074 (let* ((type (org-element-property :type link))
2075 (raw-path (org-element-property :path link))
2076 (path (cond ((member type '("http" "https"))
2077 (concat type ":" raw-path))
2078 ((file-name-absolute-p raw-path)
2079 (expand-file-name raw-path))
2080 (t raw-path)))
2081 (parent (org-export-get-parent-element link))
2082 (caption (org-export-data (org-export-get-caption parent) info))
2083 (label (org-element-property :name parent))
2084 ;; Retrieve latex attributes from the element around.
2085 (attr (let ((raw-attr
2086 (mapconcat #'identity
2087 (org-element-property :attr_html parent)
2088 " ")))
2089 (unless (string= raw-attr "") raw-attr))))
2090 ;; Now clear ATTR from any special keyword and set a default
2091 ;; value if nothing is left.
2092 (setq attr (if (not attr) "" (org-trim attr)))
2093 ;; Return proper string, depending on DISPOSITION.
2094 (org-html-format-inline-image
2095 path caption label attr (org-html-standalone-image-p link info))))
2097 (defvar org-html-standalone-image-predicate)
2098 (defun org-html-standalone-image-p (element info &optional predicate)
2099 "Test if ELEMENT is a standalone image for the purpose HTML export.
2100 INFO is a plist holding contextual information.
2102 Return non-nil, if ELEMENT is of type paragraph and it's sole
2103 content, save for whitespaces, is a link that qualifies as an
2104 inline image.
2106 Return non-nil, if ELEMENT is of type link and it's containing
2107 paragraph has no other content save for leading and trailing
2108 whitespaces.
2110 Return nil, otherwise.
2112 Bind `org-html-standalone-image-predicate' to constrain
2113 paragraph further. For example, to check for only captioned
2114 standalone images, do the following.
2116 \(setq org-html-standalone-image-predicate
2117 \(lambda \(paragraph\)
2118 \(org-element-property :caption paragraph\)\)\)"
2119 (let ((paragraph (case (org-element-type element)
2120 (paragraph element)
2121 (link (and (org-export-inline-image-p
2122 element org-html-inline-image-rules)
2123 (org-export-get-parent element)))
2124 (t nil))))
2125 (when (eq (org-element-type paragraph) 'paragraph)
2126 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2127 (functionp org-html-standalone-image-predicate)))
2128 (funcall org-html-standalone-image-predicate paragraph))
2129 (let ((contents (org-element-contents paragraph)))
2130 (loop for x in contents
2131 with inline-image-count = 0
2132 always (cond
2133 ((eq (org-element-type x) 'plain-text)
2134 (not (org-string-nw-p x)))
2135 ((eq (org-element-type x) 'link)
2136 (when (org-export-inline-image-p
2137 x org-html-inline-image-rules)
2138 (= (incf inline-image-count) 1)))
2139 (t nil))))))))
2141 (defun org-html-link (link desc info)
2142 "Transcode a LINK object from Org to HTML.
2144 DESC is the description part of the link, or the empty string.
2145 INFO is a plist holding contextual information. See
2146 `org-export-data'."
2147 (let* ((--link-org-files-as-html-maybe
2148 (function
2149 (lambda (raw-path info)
2150 "Treat links to `file.org' as links to `file.html', if needed.
2151 See `org-html-link-org-files-as-html'."
2152 (cond
2153 ((and org-html-link-org-files-as-html
2154 (string= ".org"
2155 (downcase (file-name-extension raw-path "."))))
2156 (concat (file-name-sans-extension raw-path) "."
2157 (plist-get info :html-extension)))
2158 (t raw-path)))))
2159 (type (org-element-property :type link))
2160 (raw-path (org-element-property :path link))
2161 ;; Ensure DESC really exists, or set it to nil.
2162 (desc (and (not (string= desc "")) desc))
2163 (path (cond
2164 ((member type '("http" "https" "ftp" "mailto"))
2165 (concat type ":" raw-path))
2166 ((string= type "file")
2167 ;; Treat links to ".org" files as ".html", if needed.
2168 (setq raw-path (funcall --link-org-files-as-html-maybe
2169 raw-path info))
2170 ;; If file path is absolute, prepend it with protocol
2171 ;; component - "file://".
2172 (if (not (file-name-absolute-p raw-path)) raw-path
2173 (concat "file://" (expand-file-name raw-path))))
2174 (t raw-path)))
2175 attributes protocol)
2176 ;; Extract attributes from parent's paragraph.
2177 (and (setq attributes
2178 (mapconcat
2179 'identity
2180 (let ((att (org-element-property
2181 :attr_html (org-export-get-parent-element link))))
2182 (unless (and desc att (string-match (regexp-quote (car att)) desc)) att))
2183 " "))
2184 (setq attributes (concat " " attributes)))
2186 (cond
2187 ;; Image file.
2188 ((and (or (eq t org-html-inline-images)
2189 (and org-html-inline-images (not desc)))
2190 (org-export-inline-image-p link org-html-inline-image-rules))
2191 (org-html-link--inline-image link desc info))
2192 ;; Radio target: Transcode target's contents and use them as
2193 ;; link's description.
2194 ((string= type "radio")
2195 (let ((destination (org-export-resolve-radio-link link info)))
2196 (when destination
2197 (format "<a href=\"#%s\"%s>%s</a>"
2198 (org-export-solidify-link-text path)
2199 attributes
2200 (org-export-data (org-element-contents destination) info)))))
2201 ;; Links pointing to an headline: Find destination and build
2202 ;; appropriate referencing command.
2203 ((member type '("custom-id" "fuzzy" "id"))
2204 (let ((destination (if (string= type "fuzzy")
2205 (org-export-resolve-fuzzy-link link info)
2206 (org-export-resolve-id-link link info))))
2207 (case (org-element-type destination)
2208 ;; ID link points to an external file.
2209 (plain-text
2210 (assert (org-uuidgen-p path))
2211 (let ((fragment (concat "ID-" path))
2212 ;; Treat links to ".org" files as ".html", if needed.
2213 (path (funcall --link-org-files-as-html-maybe
2214 destination info)))
2215 (format "<a href=\"%s#%s\"%s>%s</a>"
2216 path fragment attributes (or desc destination))))
2217 ;; Fuzzy link points nowhere.
2218 ((nil)
2219 (format "<i>%s</i>"
2220 (or desc
2221 (org-export-data
2222 (org-element-property :raw-link link) info))))
2223 ;; Fuzzy link points to an invisible target.
2224 (keyword nil)
2225 ;; Link points to an headline.
2226 (headline
2227 (let ((href
2228 ;; What href to use?
2229 (cond
2230 ;; Case 1: Headline is linked via it's CUSTOM_ID
2231 ;; property. Use CUSTOM_ID.
2232 ((string= type "custom-id")
2233 (org-element-property :custom-id destination))
2234 ;; Case 2: Headline is linked via it's ID property
2235 ;; or through other means. Use the default href.
2236 ((member type '("id" "fuzzy"))
2237 (format "sec-%s"
2238 (mapconcat 'number-to-string
2239 (org-export-get-headline-number
2240 destination info) "-")))
2241 (t (error "Shouldn't reach here"))))
2242 ;; What description to use?
2243 (desc
2244 ;; Case 1: Headline is numbered and LINK has no
2245 ;; description or LINK's description matches
2246 ;; headline's title. Display section number.
2247 (if (and (org-export-numbered-headline-p destination info)
2248 (or (not desc)
2249 (string= desc (org-element-property
2250 :raw-value destination))))
2251 (mapconcat 'number-to-string
2252 (org-export-get-headline-number
2253 destination info) ".")
2254 ;; Case 2: Either the headline is un-numbered or
2255 ;; LINK has a custom description. Display LINK's
2256 ;; description or headline's title.
2257 (or desc (org-export-data (org-element-property
2258 :title destination) info)))))
2259 (format "<a href=\"#%s\"%s>%s</a>"
2260 (org-export-solidify-link-text href) attributes desc)))
2261 ;; Fuzzy link points to a target. Do as above.
2263 (let ((path (org-export-solidify-link-text path)) number)
2264 (unless desc
2265 (setq number (cond
2266 ((org-html-standalone-image-p destination info)
2267 (org-export-get-ordinal
2268 (assoc 'link (org-element-contents destination))
2269 info 'link 'org-html-standalone-image-p))
2270 (t (org-export-get-ordinal destination info))))
2271 (setq desc (when number
2272 (if (atom number) (number-to-string number)
2273 (mapconcat 'number-to-string number ".")))))
2274 (format "<a href=\"#%s\"%s>%s</a>"
2275 path attributes (or desc "FIXME")))))))
2276 ;; Coderef: replace link with the reference name or the
2277 ;; equivalent line number.
2278 ((string= type "coderef")
2279 (let ((fragment (concat "coderef-" path)))
2280 (format "<a href=\"#%s\" %s%s>%s</a>"
2281 fragment
2282 (format (concat "class=\"coderef\""
2283 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2284 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2285 fragment fragment)
2286 attributes
2287 (format (org-export-get-coderef-format path desc)
2288 (org-export-resolve-coderef path info)))))
2289 ;; Link type is handled by a special function.
2290 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2291 (funcall protocol (org-link-unescape path) desc 'html))
2292 ;; External link with a description part.
2293 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2294 ;; External link without a description part.
2295 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2296 ;; No path, only description. Try to do something useful.
2297 (t (format "<i>%s</i>" desc)))))
2300 ;;;; Paragraph
2302 (defun org-html-paragraph (paragraph contents info)
2303 "Transcode a PARAGRAPH element from Org to HTML.
2304 CONTENTS is the contents of the paragraph, as a string. INFO is
2305 the plist used as a communication channel."
2306 (let* ((style nil) ; FIXME
2307 (class (cdr (assoc style '((footnote . "footnote")
2308 (verse . nil)))))
2309 (extra (if class (format " class=\"%s\"" class) ""))
2310 (parent (org-export-get-parent paragraph)))
2311 (cond
2312 ((and (eq (org-element-type parent) 'item)
2313 (= (org-element-property :begin paragraph)
2314 (org-element-property :contents-begin parent)))
2315 ;; leading paragraph in a list item have no tags
2316 contents)
2317 ((org-html-standalone-image-p paragraph info)
2318 ;; standalone image
2319 contents)
2320 (t (format "<p%s>\n%s</p>" extra contents)))))
2323 ;;;; Plain List
2325 (defun org-html-begin-plain-list (type &optional arg1)
2326 (case type
2327 (ordered
2328 (format "<ol class=\"org-ol\"%s>" (if arg1 ; FIXME
2329 (format " start=\"%d\"" arg1)
2330 "")))
2331 (unordered "<ul class=\"org-ul\">")
2332 (descriptive "<dl class=\"org-dl\">")))
2334 (defun org-html-end-plain-list (type)
2335 (case type
2336 (ordered "</ol>")
2337 (unordered "</ul>")
2338 (descriptive "</dl>")))
2340 (defun org-html-plain-list (plain-list contents info)
2341 "Transcode a PLAIN-LIST element from Org to HTML.
2342 CONTENTS is the contents of the list. INFO is a plist holding
2343 contextual information."
2344 (let* (arg1 ;; FIXME
2345 (type (org-element-property :type plain-list)))
2346 (format "%s\n%s%s"
2347 (org-html-begin-plain-list type)
2348 contents (org-html-end-plain-list type))))
2350 ;;;; Plain Text
2352 (defun org-html-convert-special-strings (string)
2353 "Convert special characters in STRING to HTML."
2354 (let ((all org-html-special-string-regexps)
2355 e a re rpl start)
2356 (while (setq a (pop all))
2357 (setq re (car a) rpl (cdr a) start 0)
2358 (while (string-match re string start)
2359 (setq string (replace-match rpl t nil string))))
2360 string))
2362 (defun org-html-encode-plain-text (text)
2363 "Convert plain text characters to HTML equivalent.
2364 Possible conversions are set in `org-export-html-protect-char-alist'."
2365 (mapc
2366 (lambda (pair)
2367 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2368 org-html-protect-char-alist)
2369 text)
2371 (defun org-html-plain-text (text info)
2372 "Transcode a TEXT string from Org to HTML.
2373 TEXT is the string to transcode. INFO is a plist holding
2374 contextual information."
2375 (let ((output text))
2376 ;; Protect following characters: <, >, &.
2377 (setq output (org-html-encode-plain-text output))
2378 ;; Handle smart quotes. Be sure to provide original string since
2379 ;; OUTPUT may have been modified.
2380 (when (plist-get info :with-smart-quotes)
2381 (setq output (org-export-activate-smart-quotes output :html info text)))
2382 ;; Handle special strings.
2383 (when (plist-get info :with-special-strings)
2384 (setq output (org-html-convert-special-strings output)))
2385 ;; Handle break preservation if required.
2386 (when (plist-get info :preserve-breaks)
2387 (setq output
2388 (replace-regexp-in-string
2389 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2390 ;; Return value.
2391 output))
2394 ;; Planning
2396 (defun org-html-planning (planning contents info)
2397 "Transcode a PLANNING element from Org to HTML.
2398 CONTENTS is nil. INFO is a plist used as a communication
2399 channel."
2400 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2401 (format
2402 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2403 (mapconcat
2404 'identity
2405 (delq nil
2406 (list
2407 (let ((closed (org-element-property :closed planning)))
2408 (when closed
2409 (format span-fmt org-closed-string
2410 (org-translate-time
2411 (org-element-property :raw-value closed)))))
2412 (let ((deadline (org-element-property :deadline planning)))
2413 (when deadline
2414 (format span-fmt org-deadline-string
2415 (org-translate-time
2416 (org-element-property :raw-value deadline)))))
2417 (let ((scheduled (org-element-property :scheduled planning)))
2418 (when scheduled
2419 (format span-fmt org-scheduled-string
2420 (org-translate-time
2421 (org-element-property :raw-value scheduled)))))))
2422 " "))))
2425 ;;;; Property Drawer
2427 (defun org-html-property-drawer (property-drawer contents info)
2428 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2429 CONTENTS is nil. INFO is a plist holding contextual
2430 information."
2431 ;; The property drawer isn't exported but we want separating blank
2432 ;; lines nonetheless.
2436 ;;;; Quote Block
2438 (defun org-html-quote-block (quote-block contents info)
2439 "Transcode a QUOTE-BLOCK element from Org to HTML.
2440 CONTENTS holds the contents of the block. INFO is a plist
2441 holding contextual information."
2442 (format "<blockquote>\n%s</blockquote>" contents))
2445 ;;;; Quote Section
2447 (defun org-html-quote-section (quote-section contents info)
2448 "Transcode a QUOTE-SECTION element from Org to HTML.
2449 CONTENTS is nil. INFO is a plist holding contextual information."
2450 (let ((value (org-remove-indentation
2451 (org-element-property :value quote-section))))
2452 (when value (format "<pre>\n%s</pre>" value))))
2455 ;;;; Section
2457 (defun org-html-section (section contents info)
2458 "Transcode a SECTION element from Org to HTML.
2459 CONTENTS holds the contents of the section. INFO is a plist
2460 holding contextual information."
2461 (let ((parent (org-export-get-parent-headline section)))
2462 ;; Before first headline: no container, just return CONTENTS.
2463 (if (not parent) contents
2464 ;; Get div's class and id references.
2465 (let* ((class-num (+ (org-export-get-relative-level parent info)
2466 (1- org-html-toplevel-hlevel)))
2467 (section-number
2468 (mapconcat
2469 'number-to-string
2470 (org-export-get-headline-number parent info) "-")))
2471 ;; Build return value.
2472 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2473 class-num
2474 (or (org-element-property :custom-id parent) section-number)
2475 contents)))))
2477 ;;;; Radio Target
2479 (defun org-html-radio-target (radio-target text info)
2480 "Transcode a RADIO-TARGET object from Org to HTML.
2481 TEXT is the text of the target. INFO is a plist holding
2482 contextual information."
2483 (let ((id (org-export-solidify-link-text
2484 (org-element-property :value radio-target))))
2485 (org-html--anchor id text)))
2488 ;;;; Special Block
2490 (defun org-html-special-block (special-block contents info)
2491 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2492 CONTENTS holds the contents of the block. INFO is a plist
2493 holding contextual information."
2494 (format "<div class=\"%s\">\n%s\n</div>"
2495 (downcase (org-element-property :type special-block))
2496 contents))
2499 ;;;; Src Block
2501 (defun org-html-src-block (src-block contents info)
2502 "Transcode a SRC-BLOCK element from Org to HTML.
2503 CONTENTS holds the contents of the item. INFO is a plist holding
2504 contextual information."
2505 (if (org-export-read-attribute :attr_html src-block :textarea)
2506 (org-html--textarea-block src-block)
2507 (let ((lang (org-element-property :language src-block))
2508 (caption (org-export-get-caption src-block))
2509 (code (org-html-format-code src-block info)))
2510 (if (not lang) (format "<pre class=\"example\">\n%s</pre>" code)
2511 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
2512 (if (not caption) ""
2513 (format "<label class=\"org-src-name\">%s</label>"
2514 (org-export-data caption info)))
2515 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code))))))
2518 ;;;; Statistics Cookie
2520 (defun org-html-statistics-cookie (statistics-cookie contents info)
2521 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2522 CONTENTS is nil. INFO is a plist holding contextual information."
2523 (let ((cookie-value (org-element-property :value statistics-cookie)))
2524 (format "<code>%s</code>" cookie-value)))
2527 ;;;; Strike-Through
2529 (defun org-html-strike-through (strike-through contents info)
2530 "Transcode STRIKE-THROUGH from Org to HTML.
2531 CONTENTS is the text with strike-through markup. INFO is a plist
2532 holding contextual information."
2533 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2534 contents))
2537 ;;;; Subscript
2539 (defun org-html-subscript (subscript contents info)
2540 "Transcode a SUBSCRIPT object from Org to HTML.
2541 CONTENTS is the contents of the object. INFO is a plist holding
2542 contextual information."
2543 (format "<sub>%s</sub>" contents))
2546 ;;;; Superscript
2548 (defun org-html-superscript (superscript contents info)
2549 "Transcode a SUPERSCRIPT object from Org to HTML.
2550 CONTENTS is the contents of the object. INFO is a plist holding
2551 contextual information."
2552 (format "<sup>%s</sup>" contents))
2555 ;;;; Tabel Cell
2557 (defun org-html-table-cell (table-cell contents info)
2558 "Transcode a TABLE-CELL element from Org to HTML.
2559 CONTENTS is nil. INFO is a plist used as a communication
2560 channel."
2561 (let* ((table-row (org-export-get-parent table-cell))
2562 (table (org-export-get-parent-table table-cell))
2563 (cell-attrs
2564 (if (not org-html-table-align-individual-fields) ""
2565 (format (if (and (boundp 'org-html-format-table-no-css)
2566 org-html-format-table-no-css)
2567 " align=\"%s\"" " class=\"%s\"")
2568 (org-export-table-cell-alignment table-cell info)))))
2569 (when (or (not contents) (string= "" (org-trim contents)))
2570 (setq contents "&nbsp;"))
2571 (cond
2572 ((and (org-export-table-has-header-p table info)
2573 (= 1 (org-export-table-row-group table-row info)))
2574 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2575 contents (cdr org-html-table-header-tags)))
2576 ((and org-html-table-use-header-tags-for-first-column
2577 (zerop (cdr (org-export-table-cell-address table-cell info))))
2578 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2579 contents (cdr org-html-table-header-tags)))
2580 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2581 contents (cdr org-html-table-data-tags))))))
2584 ;;;; Table Row
2586 (defun org-html-table-row (table-row contents info)
2587 "Transcode a TABLE-ROW element from Org to HTML.
2588 CONTENTS is the contents of the row. INFO is a plist used as a
2589 communication channel."
2590 ;; Rules are ignored since table separators are deduced from
2591 ;; borders of the current row.
2592 (when (eq (org-element-property :type table-row) 'standard)
2593 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2594 (rowgroup-tags
2595 (cond
2596 ;; Case 1: Row belongs to second or subsequent rowgroups.
2597 ((not (= 1 (org-export-table-row-group table-row info)))
2598 '("<tbody>" . "\n</tbody>"))
2599 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2600 ((org-export-table-has-header-p
2601 (org-export-get-parent-table table-row) info)
2602 '("<thead>" . "\n</thead>"))
2603 ;; Case 2: Row is from first and only row group.
2604 (t '("<tbody>" . "\n</tbody>")))))
2605 (concat
2606 ;; Begin a rowgroup?
2607 (when (org-export-table-row-starts-rowgroup-p table-row info)
2608 (car rowgroup-tags))
2609 ;; Actual table row
2610 (concat "\n" (eval (car org-html-table-row-tags))
2611 contents
2612 "\n"
2613 (eval (cdr org-html-table-row-tags)))
2614 ;; End a rowgroup?
2615 (when (org-export-table-row-ends-rowgroup-p table-row info)
2616 (cdr rowgroup-tags))))))
2619 ;;;; Table
2621 (defun org-html-table-first-row-data-cells (table info)
2622 (let ((table-row
2623 (org-element-map table 'table-row
2624 (lambda (row)
2625 (unless (eq (org-element-property :type row) 'rule) row))
2626 info 'first-match))
2627 (special-column-p (org-export-table-has-special-column-p table)))
2628 (if (not special-column-p) (org-element-contents table-row)
2629 (cdr (org-element-contents table-row)))))
2631 (defun org-html-table--table.el-table (table info)
2632 (when (eq (org-element-property :type table) 'table.el)
2633 (require 'table)
2634 (let ((outbuf (with-current-buffer
2635 (get-buffer-create "*org-export-table*")
2636 (erase-buffer) (current-buffer))))
2637 (with-temp-buffer
2638 (insert (org-element-property :value table))
2639 (goto-char 1)
2640 (re-search-forward "^[ \t]*|[^|]" nil t)
2641 (table-generate-source 'html outbuf))
2642 (with-current-buffer outbuf
2643 (prog1 (org-trim (buffer-string))
2644 (kill-buffer) )))))
2646 (defun org-html-table (table contents info)
2647 "Transcode a TABLE element from Org to HTML.
2648 CONTENTS is the contents of the table. INFO is a plist holding
2649 contextual information."
2650 (case (org-element-property :type table)
2651 ;; Case 1: table.el table. Convert it using appropriate tools.
2652 (table.el (org-html-table--table.el-table table info))
2653 ;; Case 2: Standard table.
2655 (let* ((label (org-element-property :name table))
2656 (caption (org-export-get-caption table))
2657 (attributes (mapconcat #'identity
2658 (org-element-property :attr_html table)
2659 " "))
2660 (alignspec
2661 (if (and (boundp 'org-html-format-table-no-css)
2662 org-html-format-table-no-css)
2663 "align=\"%s\"" "class=\"%s\""))
2664 (table-column-specs
2665 (function
2666 (lambda (table info)
2667 (mapconcat
2668 (lambda (table-cell)
2669 (let ((alignment (org-export-table-cell-alignment
2670 table-cell info)))
2671 (concat
2672 ;; Begin a colgroup?
2673 (when (org-export-table-cell-starts-colgroup-p
2674 table-cell info)
2675 "\n<colgroup>")
2676 ;; Add a column. Also specify it's alignment.
2677 (format "\n<col %s/>" (format alignspec alignment))
2678 ;; End a colgroup?
2679 (when (org-export-table-cell-ends-colgroup-p
2680 table-cell info)
2681 "\n</colgroup>"))))
2682 (org-html-table-first-row-data-cells table info) "\n"))))
2683 (table-attributes
2684 (let ((table-tag (plist-get info :html-table-tag)))
2685 (concat
2686 (and (string-match "<table\\(.*\\)>" table-tag)
2687 (match-string 1 table-tag))
2688 (and label (format " id=\"%s\""
2689 (org-export-solidify-link-text label)))))))
2690 ;; Remove last blank line.
2691 (setq contents (substring contents 0 -1))
2692 (format "<table%s>\n%s\n%s\n%s\n</table>"
2693 table-attributes
2694 (if (not caption) ""
2695 (format "<caption>%s</caption>"
2696 (org-export-data caption info)))
2697 (funcall table-column-specs table info)
2698 contents)))))
2701 ;;;; Target
2703 (defun org-html-target (target contents info)
2704 "Transcode a TARGET object from Org to HTML.
2705 CONTENTS is nil. INFO is a plist holding contextual
2706 information."
2707 (let ((id (org-export-solidify-link-text
2708 (org-element-property :value target))))
2709 (org-html--anchor id)))
2712 ;;;; Timestamp
2714 (defun org-html-timestamp (timestamp contents info)
2715 "Transcode a TIMESTAMP object from Org to HTML.
2716 CONTENTS is nil. INFO is a plist holding contextual
2717 information."
2718 (let ((value (org-html-plain-text
2719 (org-timestamp-translate timestamp) info)))
2720 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2721 (replace-regexp-in-string "--" "&ndash;" value))))
2724 ;;;; Underline
2726 (defun org-html-underline (underline contents info)
2727 "Transcode UNDERLINE from Org to HTML.
2728 CONTENTS is the text with underline markup. INFO is a plist
2729 holding contextual information."
2730 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2731 contents))
2734 ;;;; Verbatim
2736 (defun org-html-verbatim (verbatim contents info)
2737 "Transcode VERBATIM from Org to HTML.
2738 CONTENTS is nil. INFO is a plist holding contextual
2739 information."
2740 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2741 (org-element-property :value verbatim)))
2744 ;;;; Verse Block
2746 (defun org-html-verse-block (verse-block contents info)
2747 "Transcode a VERSE-BLOCK element from Org to HTML.
2748 CONTENTS is verse block contents. INFO is a plist holding
2749 contextual information."
2750 ;; Replace each newline character with line break. Also replace
2751 ;; each blank line with a line break.
2752 (setq contents (replace-regexp-in-string
2753 "^ *\\\\\\\\$" "<br/>\n"
2754 (replace-regexp-in-string
2755 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2756 ;; Replace each white space at beginning of a line with a
2757 ;; non-breaking space.
2758 (while (string-match "^[ \t]+" contents)
2759 (let* ((num-ws (length (match-string 0 contents)))
2760 (ws (let (out) (dotimes (i num-ws out)
2761 (setq out (concat out "&nbsp;"))))))
2762 (setq contents (replace-match ws nil t contents))))
2763 (format "<p class=\"verse\">\n%s</p>" contents))
2767 ;;; Filter Functions
2769 (defun org-html-final-function (contents backend info)
2770 (if (not org-html-pretty-output) contents
2771 (with-temp-buffer
2772 (html-mode)
2773 (insert contents)
2774 (indent-region (point-min) (point-max))
2775 (buffer-substring-no-properties (point-min) (point-max)))))
2779 ;;; End-user functions
2781 ;;;###autoload
2782 (defun org-html-export-as-html
2783 (&optional async subtreep visible-only body-only ext-plist)
2784 "Export current buffer to an HTML buffer.
2786 If narrowing is active in the current buffer, only export its
2787 narrowed part.
2789 If a region is active, export that region.
2791 A non-nil optional argument ASYNC means the process should happen
2792 asynchronously. The resulting buffer should be accessible
2793 through the `org-export-stack' interface.
2795 When optional argument SUBTREEP is non-nil, export the sub-tree
2796 at point, extracting information from the headline properties
2797 first.
2799 When optional argument VISIBLE-ONLY is non-nil, don't export
2800 contents of hidden elements.
2802 When optional argument BODY-ONLY is non-nil, only write code
2803 between \"<body>\" and \"</body>\" tags.
2805 EXT-PLIST, when provided, is a property list with external
2806 parameters overriding Org default settings, but still inferior to
2807 file-local settings.
2809 Export is done in a buffer named \"*Org HTML Export*\", which
2810 will be displayed when `org-export-show-temporary-export-buffer'
2811 is non-nil."
2812 (interactive)
2813 (if async
2814 (org-export-async-start
2815 (lambda (output)
2816 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2817 (erase-buffer)
2818 (insert output)
2819 (goto-char (point-min))
2820 (nxml-mode)
2821 (org-export-add-to-stack (current-buffer) 'html)))
2822 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2823 (let ((outbuf (org-export-to-buffer
2824 'html "*Org HTML Export*"
2825 subtreep visible-only body-only ext-plist)))
2826 ;; Set major mode.
2827 (with-current-buffer outbuf (nxml-mode))
2828 (when org-export-show-temporary-export-buffer
2829 (switch-to-buffer-other-window outbuf)))))
2831 ;;;###autoload
2832 (defun org-html-export-to-html
2833 (&optional async subtreep visible-only body-only ext-plist)
2834 "Export current buffer to a HTML file.
2836 If narrowing is active in the current buffer, only export its
2837 narrowed part.
2839 If a region is active, export that region.
2841 A non-nil optional argument ASYNC means the process should happen
2842 asynchronously. The resulting file should be accessible through
2843 the `org-export-stack' interface.
2845 When optional argument SUBTREEP is non-nil, export the sub-tree
2846 at point, extracting information from the headline properties
2847 first.
2849 When optional argument VISIBLE-ONLY is non-nil, don't export
2850 contents of hidden elements.
2852 When optional argument BODY-ONLY is non-nil, only write code
2853 between \"<body>\" and \"</body>\" tags.
2855 EXT-PLIST, when provided, is a property list with external
2856 parameters overriding Org default settings, but still inferior to
2857 file-local settings.
2859 Return output file's name."
2860 (interactive)
2861 (let* ((extension (concat "." org-html-extension))
2862 (file (org-export-output-file-name extension subtreep))
2863 (org-export-coding-system org-html-coding-system))
2864 (if async
2865 (org-export-async-start
2866 (lambda (f) (org-export-add-to-stack f 'html))
2867 (let ((org-export-coding-system org-html-coding-system))
2868 `(expand-file-name
2869 (org-export-to-file
2870 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2871 (let ((org-export-coding-system org-html-coding-system))
2872 (org-export-to-file
2873 'html file subtreep visible-only body-only ext-plist)))))
2875 ;;;###autoload
2876 (defun org-html-publish-to-html (plist filename pub-dir)
2877 "Publish an org file to HTML.
2879 FILENAME is the filename of the Org file to be published. PLIST
2880 is the property list for the given project. PUB-DIR is the
2881 publishing directory.
2883 Return output file name."
2884 (org-publish-org-to 'html filename ".html" plist pub-dir))
2888 ;;; FIXME
2890 ;;;; org-format-table-html
2891 ;;;; org-format-org-table-html
2892 ;;;; org-format-table-table-html
2893 ;;;; org-table-number-fraction
2894 ;;;; org-table-number-regexp
2895 ;;;; org-html-table-caption-above
2897 ;;;; org-html-with-timestamp
2898 ;;;; org-html-html-helper-timestamp
2900 ;;;; org-export-as-html-and-open
2901 ;;;; org-export-as-html-batch
2902 ;;;; org-export-as-html-to-buffer
2903 ;;;; org-replace-region-by-html
2904 ;;;; org-export-region-as-html
2905 ;;;; org-export-as-html
2907 ;;;; (org-export-directory :html opt-plist)
2908 ;;;; (plist-get opt-plist :html-extension)
2909 ;;;; org-html-toplevel-hlevel
2910 ;;;; org-html-special-string-regexps
2911 ;;;; org-html-inline-images
2912 ;;;; org-html-inline-image-extensions
2913 ;;;; org-html-protect-char-alist
2914 ;;;; org-html-table-use-header-tags-for-first-column
2915 ;;;; org-html-todo-kwd-class-prefix
2916 ;;;; org-html-tag-class-prefix
2917 ;;;; org-html-footnote-separator
2919 ;;;; org-export-preferred-target-alist
2920 ;;;; org-export-solidify-link-text
2921 ;;;; class for anchors
2922 ;;;; org-export-with-section-numbers, body-only
2923 ;;;; org-export-mark-todo-in-toc
2925 ;;;; org-html-format-org-link
2926 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
2927 ;;;; alt = (file-name-nondirectory path)
2929 ;;;; org-export-time-stamp-file'
2931 (provide 'ox-html)
2933 ;; Local variables:
2934 ;; generated-autoload-file: "org-loaddefs.el"
2935 ;; End:
2937 ;;; ox-html.el ends here