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