ox-html.el (org-html-format-headline-function): Fix docstring
[org-mode.git] / lisp / ox-html.el
blob051bc1357b6df4d8e6fff4e7d6f95521a2663dc6
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 (or (org-export-get-optional-title headline info)
1152 (org-element-property :title headline))
1153 info)
1154 (and tags "&nbsp;&nbsp;&nbsp;") (org-html--tags tags)))))
1156 (defun org-html-toc (depth info)
1157 "Build table of contents.
1158 DEPTH is an integer specifying the depth of the table. INFO is
1159 a plist used as a communication channel. Return nil if table of
1160 contents is empty."
1161 (let ((toc-entries
1162 (mapcar (lambda (headline)
1163 (list (org-html--format-toc-headline headline info)
1164 (org-export-get-relative-level headline info)))
1165 (org-export-collect-headlines info depth))))
1166 (when toc-entries
1167 (concat "<div id=\"table-of-contents\">\n"
1168 (format "<h%d>%s</h%d>\n"
1169 org-html-toplevel-hlevel
1170 (org-html--translate "Table of Contents" info)
1171 org-html-toplevel-hlevel)
1172 "<div id=\"text-table-of-contents\">"
1173 (org-html--toc-text toc-entries)
1174 "</div>\n"
1175 "</div>\n"))))
1177 (defun org-html-fix-class-name (kwd) ; audit callers of this function
1178 "Turn todo keyword into a valid class name.
1179 Replaces invalid characters with \"_\"."
1180 (save-match-data
1181 (while (string-match "[^a-zA-Z0-9_]" kwd)
1182 (setq kwd (replace-match "_" t t kwd))))
1183 kwd)
1185 (defun org-html-format-footnote-reference (n def refcnt)
1186 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1187 (format org-html-footnote-format
1188 (let* ((id (format "fnr.%s%s" n extra))
1189 (href (format " href=\"#fn.%s\"" n))
1190 (attributes (concat " class=\"footref\"" href)))
1191 (org-html--anchor id n attributes)))))
1193 (defun org-html-format-footnotes-section (section-name definitions)
1194 (if (not definitions) ""
1195 (format org-html-footnotes-section section-name definitions)))
1197 (defun org-html-format-footnote-definition (fn)
1198 (let ((n (car fn)) (def (cdr fn)))
1199 (format
1200 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1201 (format org-html-footnote-format
1202 (let* ((id (format "fn.%s" n))
1203 (href (format " href=\"#fnr.%s\"" n))
1204 (attributes (concat " class=\"footnum\"" href)))
1205 (org-html--anchor id n attributes)))
1206 def)))
1208 (defun org-html-footnote-section (info)
1209 (let* ((fn-alist (org-export-collect-footnote-definitions
1210 (plist-get info :parse-tree) info))
1212 (fn-alist
1213 (loop for (n type raw) in fn-alist collect
1214 (cons n (if (eq (org-element-type raw) 'org-data)
1215 (org-trim (org-export-data raw info))
1216 (format "<p>%s</p>"
1217 (org-trim (org-export-data raw info))))))))
1218 (when fn-alist
1219 (org-html-format-footnotes-section
1220 (org-html--translate "Footnotes" info)
1221 (format
1222 "<table>\n%s\n</table>\n"
1223 (mapconcat 'org-html-format-footnote-definition fn-alist "\n"))))))
1227 ;;; Template
1229 (defun org-html--build-meta-info (info)
1230 "Return meta tags for exported document.
1231 INFO is a plist used as a communication channel."
1232 (let* ((title (org-export-data (plist-get info :title) info))
1233 (author (and (plist-get info :with-author)
1234 (let ((auth (plist-get info :author)))
1235 (and auth (org-export-data auth info)))))
1236 (date (and (plist-get info :with-date)
1237 (let ((date (plist-get info :date)))
1238 (and date (org-export-data date info)))))
1239 (description (plist-get info :description))
1240 (keywords (plist-get info :keywords)))
1241 (concat
1242 (format "<title>%s</title>\n" title)
1243 (format
1244 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1245 (or (and org-html-coding-system
1246 (fboundp 'coding-system-get)
1247 (coding-system-get org-html-coding-system 'mime-charset))
1248 "iso-8859-1"))
1249 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1250 (format "<meta name=\"generator\" content=\"Org-mode\"/>\n")
1251 (and date (format "<meta name=\"generated\" content=\"%s\"/>\n" date))
1252 (and author (format "<meta name=\"author\" content=\"%s\"/>\n" author))
1253 (and description
1254 (format "<meta name=\"description\" content=\"%s\"/>\n" description))
1255 (and keywords
1256 (format "<meta name=\"keywords\" content=\"%s\"/>\n" keywords)))))
1258 (defun org-html--build-style (info)
1259 "Return style information for exported document.
1260 INFO is a plist used as a communication channel."
1261 (org-element-normalize-string
1262 (concat
1263 (when (plist-get info :html-style-include-default) org-html-style-default)
1264 (org-element-normalize-string (plist-get info :html-style))
1265 (org-element-normalize-string (plist-get info :html-style-extra))
1266 (when (plist-get info :html-style-include-scripts) org-html-scripts))))
1268 (defun org-html--build-mathjax-config (info)
1269 "Insert the user setup into the mathjax template.
1270 INFO is a plist used as a communication channel."
1271 (when (and (memq (plist-get info :with-latex) '(mathjax t))
1272 (org-element-map (plist-get info :parse-tree)
1273 '(latex-fragment latex-environment) 'identity info t))
1274 (let ((template org-html-mathjax-template)
1275 (options org-html-mathjax-options)
1276 (in-buffer (or (plist-get info :html-mathjax) ""))
1277 name val (yes " ") (no "// ") x)
1278 (mapc
1279 (lambda (e)
1280 (setq name (car e) val (nth 1 e))
1281 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1282 (setq val (car (read-from-string
1283 (substring in-buffer (match-end 0))))))
1284 (if (not (stringp val)) (setq val (format "%s" val)))
1285 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1286 (setq template (replace-match val t t template))))
1287 options)
1288 (setq val (nth 1 (assq 'mathml options)))
1289 (if (string-match (concat "\\<mathml:") in-buffer)
1290 (setq val (car (read-from-string
1291 (substring in-buffer (match-end 0))))))
1292 ;; Exchange prefixes depending on mathml setting.
1293 (if (not val) (setq x yes yes no no x))
1294 ;; Replace cookies to turn on or off the config/jax lines.
1295 (if (string-match ":MMLYES:" template)
1296 (setq template (replace-match yes t t template)))
1297 (if (string-match ":MMLNO:" template)
1298 (setq template (replace-match no t t template)))
1299 ;; Return the modified template.
1300 (org-element-normalize-string template))))
1302 (defun org-html--build-preamble (info)
1303 "Return document preamble as a string, or nil.
1304 INFO is a plist used as a communication channel."
1305 (let ((preamble (plist-get info :html-preamble)))
1306 (when preamble
1307 (let ((preamble-contents
1308 (if (functionp preamble) (funcall preamble info)
1309 (let ((title (org-export-data (plist-get info :title) info))
1310 (date (if (not (plist-get info :with-date)) ""
1311 (org-export-data (plist-get info :date) info)))
1312 (author (if (not (plist-get info :with-author)) ""
1313 (org-export-data (plist-get info :author) info)))
1314 (email (if (not (plist-get info :with-email)) ""
1315 (plist-get info :email))))
1316 (if (stringp preamble)
1317 (format-spec preamble
1318 `((?t . ,title) (?a . ,author)
1319 (?d . ,date) (?e . ,email)))
1320 (format-spec
1321 (or (cadr (assoc (plist-get info :language)
1322 org-html-preamble-format))
1323 (cadr (assoc "en" org-html-preamble-format)))
1324 `((?t . ,title) (?a . ,author)
1325 (?d . ,date) (?e . ,email))))))))
1326 (when (org-string-nw-p preamble-contents)
1327 (concat (format "<div id=\"%s\">\n" (nth 0 org-html-divs))
1328 (org-element-normalize-string preamble-contents)
1329 "</div>\n"))))))
1331 (defun org-html--build-postamble (info)
1332 "Return document postamble as a string, or nil.
1333 INFO is a plist used as a communication channel."
1334 (let ((postamble (plist-get info :html-postamble)))
1335 (when postamble
1336 (let ((postamble-contents
1337 (if (functionp postamble) (funcall postamble info)
1338 (let ((date (if (not (plist-get info :with-date)) ""
1339 (org-export-data (plist-get info :date) info)))
1340 (author (let ((author (plist-get info :author)))
1341 (and author (org-export-data author info))))
1342 (email (mapconcat
1343 (lambda (e)
1344 (format "<a href=\"mailto:%s\">%s</a>" e e))
1345 (split-string (plist-get info :email) ",+ *")
1346 ", "))
1347 (html-validation-link (or org-html-validation-link ""))
1348 (creator-info (plist-get info :creator)))
1349 (cond ((stringp postamble)
1350 (format-spec postamble
1351 `((?a . ,author) (?e . ,email)
1352 (?d . ,date) (?c . ,creator-info)
1353 (?v . ,html-validation-link))))
1354 ((eq postamble 'auto)
1355 (concat
1356 (when (plist-get info :time-stamp-file)
1357 (format "<p class=\"date\">%s: %s</p>\n"
1358 (org-html--translate "Date" info)
1359 date))
1360 (when (and (plist-get info :with-author) author)
1361 (format "<p class=\"author\">%s : %s</p>\n"
1362 (org-html--translate "Author" info)
1363 author))
1364 (when (and (plist-get info :with-email) email)
1365 (format "<p class=\"email\">%s </p>\n" email))
1366 (when (plist-get info :with-creator)
1367 (format "<p class=\"creator\">%s</p>\n"
1368 creator-info))
1369 html-validation-link "\n"))
1370 (t (format-spec
1371 (or (cadr (assoc (plist-get info :language)
1372 org-html-postamble-format))
1373 (cadr (assoc "en" org-html-postamble-format)))
1374 `((?a . ,author) (?e . ,email)
1375 (?d . ,date) (?c . ,creator-info)
1376 (?v . ,html-validation-link)))))))))
1377 (when (org-string-nw-p postamble-contents)
1378 (concat
1379 (format "<div id=\"%s\">\n" (nth 2 org-html-divs))
1380 (org-element-normalize-string postamble-contents)
1381 "</div>\n"))))))
1383 (defun org-html-inner-template (contents info)
1384 "Return body of document string after HTML conversion.
1385 CONTENTS is the transcoded contents string. INFO is a plist
1386 holding export options."
1387 (concat
1388 (format "<div id=\"%s\">\n" (nth 1 org-html-divs))
1389 ;; Document title.
1390 (format "<h1 class=\"title\">%s</h1>\n"
1391 (org-export-data (plist-get info :title) info))
1392 ;; Table of contents.
1393 (let ((depth (plist-get info :with-toc)))
1394 (when depth (org-html-toc depth info)))
1395 ;; Document contents.
1396 contents
1397 ;; Footnotes section.
1398 (org-html-footnote-section info)
1399 ;; Bibliography.
1400 (org-html-bibliography)
1401 "\n</div>"))
1403 (defun org-html-template (contents info)
1404 "Return complete document string after HTML conversion.
1405 CONTENTS is the transcoded contents string. INFO is a plist
1406 holding export options."
1407 (concat
1408 (format
1409 (or (and (stringp org-html-xml-declaration)
1410 org-html-xml-declaration)
1411 (cdr (assoc (plist-get info :html-extension)
1412 org-html-xml-declaration))
1413 (cdr (assoc "html" org-html-xml-declaration))
1416 (or (and org-html-coding-system
1417 (fboundp 'coding-system-get)
1418 (coding-system-get org-html-coding-system 'mime-charset))
1419 "iso-8859-1"))
1420 "\n"
1421 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1422 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
1423 (format "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">\n"
1424 (plist-get info :language) (plist-get info :language))
1425 "<head>\n"
1426 (org-html--build-meta-info info)
1427 (org-html--build-style info)
1428 (org-html--build-mathjax-config info)
1429 "</head>\n"
1430 "<body>\n"
1431 (let ((link-up (org-trim (plist-get info :html-link-up)))
1432 (link-home (org-trim (plist-get info :html-link-home))))
1433 (unless (and (string= link-up "") (string= link-up ""))
1434 (format org-html-home/up-format
1435 (or link-up link-home)
1436 (or link-home link-up))))
1437 ;; Preamble.
1438 (org-html--build-preamble info)
1439 ;; Document contents.
1440 contents
1441 ;; Postamble.
1442 (org-html--build-postamble info)
1443 ;; Closing document.
1444 "</body>\n</html>"))
1446 (defun org-html--translate (s info)
1447 "Translate string S according to specified language.
1448 INFO is a plist used as a communication channel."
1449 (org-export-translate s :html info))
1451 ;;;; Anchor
1453 (defun org-html--anchor (&optional id desc attributes)
1454 (let* ((name (and org-html-allow-name-attribute-in-anchors id))
1455 (attributes (concat (and id (format " id=\"%s\"" id))
1456 (and name (format " name=\"%s\"" name))
1457 attributes)))
1458 (format "<a%s>%s</a>" attributes (or desc ""))))
1460 ;;;; Todo
1462 (defun org-html--todo (todo)
1463 (when todo
1464 (format "<span class=\"%s %s%s\">%s</span>"
1465 (if (member todo org-done-keywords) "done" "todo")
1466 org-html-todo-kwd-class-prefix (org-html-fix-class-name todo)
1467 todo)))
1469 ;;;; Tags
1471 (defun org-html--tags (tags)
1472 (when tags
1473 (format "<span class=\"tag\">%s</span>"
1474 (mapconcat
1475 (lambda (tag)
1476 (format "<span class=\"%s\">%s</span>"
1477 (concat org-html-tag-class-prefix
1478 (org-html-fix-class-name tag))
1479 tag))
1480 tags "&nbsp;"))))
1482 ;;;; Headline
1484 (defun* org-html-format-headline
1485 (todo todo-type priority text tags
1486 &key level section-number headline-label &allow-other-keys)
1487 (let ((section-number
1488 (when section-number
1489 (format "<span class=\"section-number-%d\">%s</span> "
1490 level section-number)))
1491 (todo (org-html--todo todo))
1492 (tags (org-html--tags tags)))
1493 (concat section-number todo (and todo " ") text
1494 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1496 ;;;; Src Code
1498 (defun org-html-fontify-code (code lang)
1499 "Color CODE with htmlize library.
1500 CODE is a string representing the source code to colorize. LANG
1501 is the language used for CODE, as a string, or nil."
1502 (when code
1503 (cond
1504 ;; Case 1: No lang. Possibly an example block.
1505 ((not lang)
1506 ;; Simple transcoding.
1507 (org-html-encode-plain-text code))
1508 ;; Case 2: No htmlize or an inferior version of htmlize
1509 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1510 ;; Emit a warning.
1511 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1512 ;; Simple transcoding.
1513 (org-html-encode-plain-text code))
1515 ;; Map language
1516 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1517 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1518 (cond
1519 ;; Case 1: Language is not associated with any Emacs mode
1520 ((not (functionp lang-mode))
1521 ;; Simple transcoding.
1522 (org-html-encode-plain-text code))
1523 ;; Case 2: Default. Fontify code.
1525 ;; htmlize
1526 (setq code (with-temp-buffer
1527 ;; Switch to language-specific mode.
1528 (funcall lang-mode)
1529 (insert code)
1530 ;; Fontify buffer.
1531 (font-lock-fontify-buffer)
1532 ;; Remove formatting on newline characters.
1533 (save-excursion
1534 (let ((beg (point-min))
1535 (end (point-max)))
1536 (goto-char beg)
1537 (while (progn (end-of-line) (< (point) end))
1538 (put-text-property (point) (1+ (point)) 'face nil)
1539 (forward-char 1))))
1540 (org-src-mode)
1541 (set-buffer-modified-p nil)
1542 ;; Htmlize region.
1543 (org-html-htmlize-region-for-paste
1544 (point-min) (point-max))))
1545 ;; Strip any encolosing <pre></pre> tags.
1546 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1547 (match-string 1 code)
1548 code))))))))
1550 (defun org-html-do-format-code
1551 (code &optional lang refs retain-labels num-start)
1552 "Format CODE string as source code.
1553 Optional arguments LANG, REFS, RETAIN-LABELS and NUM-START are,
1554 respectively, the language of the source code, as a string, an
1555 alist between line numbers and references (as returned by
1556 `org-export-unravel-code'), a boolean specifying if labels should
1557 appear in the source code, and the number associated to the first
1558 line of code."
1559 (let* ((code-lines (org-split-string code "\n"))
1560 (code-length (length code-lines))
1561 (num-fmt
1562 (and num-start
1563 (format "%%%ds: "
1564 (length (number-to-string (+ code-length num-start))))))
1565 (code (org-html-fontify-code code lang)))
1566 (org-export-format-code
1567 code
1568 (lambda (loc line-num ref)
1569 (setq loc
1570 (concat
1571 ;; Add line number, if needed.
1572 (when num-start
1573 (format "<span class=\"linenr\">%s</span>"
1574 (format num-fmt line-num)))
1575 ;; Transcoded src line.
1577 ;; Add label, if needed.
1578 (when (and ref retain-labels) (format " (%s)" ref))))
1579 ;; Mark transcoded line as an anchor, if needed.
1580 (if (not ref) loc
1581 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1582 ref loc)))
1583 num-start refs)))
1585 (defun org-html-format-code (element info)
1586 "Format contents of ELEMENT as source code.
1587 ELEMENT is either an example block or a src block. INFO is
1588 a plist used as a communication channel."
1589 (let* ((lang (org-element-property :language element))
1590 ;; Extract code and references.
1591 (code-info (org-export-unravel-code element))
1592 (code (car code-info))
1593 (refs (cdr code-info))
1594 ;; Does the src block contain labels?
1595 (retain-labels (org-element-property :retain-labels element))
1596 ;; Does it have line numbers?
1597 (num-start (case (org-element-property :number-lines element)
1598 (continued (org-export-get-loc element info))
1599 (new 0))))
1600 (org-html-do-format-code code lang refs retain-labels num-start)))
1604 ;;; Transcode Functions
1606 ;;;; Bold
1608 (defun org-html-bold (bold contents info)
1609 "Transcode BOLD from Org to HTML.
1610 CONTENTS is the text with bold markup. INFO is a plist holding
1611 contextual information."
1612 (format (or (cdr (assq 'bold org-html-text-markup-alist)) "%s")
1613 contents))
1616 ;;;; Center Block
1618 (defun org-html-center-block (center-block contents info)
1619 "Transcode a CENTER-BLOCK element from Org to HTML.
1620 CONTENTS holds the contents of the block. INFO is a plist
1621 holding contextual information."
1622 (format "<div style=\"text-align: center\">\n%s</div>" contents))
1625 ;;;; Clock
1627 (defun org-html-clock (clock contents info)
1628 "Transcode a CLOCK element from Org to HTML.
1629 CONTENTS is nil. INFO is a plist used as a communication
1630 channel."
1631 (format "<p>
1632 <span class=\"timestamp-wrapper\">
1633 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1634 </span>
1635 </p>"
1636 org-clock-string
1637 (org-translate-time
1638 (org-element-property :raw-value
1639 (org-element-property :value clock)))
1640 (let ((time (org-element-property :duration clock)))
1641 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1644 ;;;; Code
1646 (defun org-html-code (code contents info)
1647 "Transcode CODE from Org to HTML.
1648 CONTENTS is nil. INFO is a plist holding contextual
1649 information."
1650 (format (or (cdr (assq 'code org-html-text-markup-alist)) "%s")
1651 (org-element-property :value code)))
1654 ;;;; Drawer
1656 (defun org-html-drawer (drawer contents info)
1657 "Transcode a DRAWER element from Org to HTML.
1658 CONTENTS holds the contents of the block. INFO is a plist
1659 holding contextual information."
1660 (if (functionp org-html-format-drawer-function)
1661 (funcall org-html-format-drawer-function
1662 (org-element-property :drawer-name drawer)
1663 contents)
1664 ;; If there's no user defined function: simply
1665 ;; display contents of the drawer.
1666 contents))
1669 ;;;; Dynamic Block
1671 (defun org-html-dynamic-block (dynamic-block contents info)
1672 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1673 CONTENTS holds the contents of the block. INFO is a plist
1674 holding contextual information. See `org-export-data'."
1675 contents)
1678 ;;;; Entity
1680 (defun org-html-entity (entity contents info)
1681 "Transcode an ENTITY object from Org to HTML.
1682 CONTENTS are the definition itself. INFO is a plist holding
1683 contextual information."
1684 (org-element-property :html entity))
1687 ;;;; Example Block
1689 (defun org-html-example-block (example-block contents info)
1690 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1691 CONTENTS is nil. INFO is a plist holding contextual
1692 information."
1693 (if (org-export-read-attribute :attr_html example-block :textarea)
1694 (org-html--textarea-block example-block)
1695 (format "<pre class=\"example\">\n%s</pre>"
1696 (org-html-format-code example-block info))))
1699 ;;;; Export Snippet
1701 (defun org-html-export-snippet (export-snippet contents info)
1702 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1703 CONTENTS is nil. INFO is a plist holding contextual
1704 information."
1705 (when (eq (org-export-snippet-backend export-snippet) 'html)
1706 (org-element-property :value export-snippet)))
1709 ;;;; Export Block
1711 (defun org-html-export-block (export-block contents info)
1712 "Transcode a EXPORT-BLOCK element from Org to HTML.
1713 CONTENTS is nil. INFO is a plist holding contextual information."
1714 (when (string= (org-element-property :type export-block) "HTML")
1715 (org-remove-indentation (org-element-property :value export-block))))
1718 ;;;; Fixed Width
1720 (defun org-html-fixed-width (fixed-width contents info)
1721 "Transcode a FIXED-WIDTH element from Org to HTML.
1722 CONTENTS is nil. INFO is a plist holding contextual information."
1723 (format "<pre class=\"example\">\n%s</pre>"
1724 (org-html-do-format-code
1725 (org-remove-indentation
1726 (org-element-property :value fixed-width)))))
1729 ;;;; Footnote Reference
1731 (defun org-html-footnote-reference (footnote-reference contents info)
1732 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1733 CONTENTS is nil. INFO is a plist holding contextual information."
1734 (concat
1735 ;; Insert separator between two footnotes in a row.
1736 (let ((prev (org-export-get-previous-element footnote-reference info)))
1737 (when (eq (org-element-type prev) 'footnote-reference)
1738 org-html-footnote-separator))
1739 (cond
1740 ((not (org-export-footnote-first-reference-p footnote-reference info))
1741 (org-html-format-footnote-reference
1742 (org-export-get-footnote-number footnote-reference info)
1743 "IGNORED" 100))
1744 ;; Inline definitions are secondary strings.
1745 ((eq (org-element-property :type footnote-reference) 'inline)
1746 (org-html-format-footnote-reference
1747 (org-export-get-footnote-number footnote-reference info)
1748 "IGNORED" 1))
1749 ;; Non-inline footnotes definitions are full Org data.
1750 (t (org-html-format-footnote-reference
1751 (org-export-get-footnote-number footnote-reference info)
1752 "IGNORED" 1)))))
1755 ;;;; Headline
1757 (defun org-html-format-headline--wrap (headline info
1758 &optional format-function
1759 &rest extra-keys)
1760 "Transcode a HEADLINE element from Org to HTML.
1761 CONTENTS holds the contents of the headline. INFO is a plist
1762 holding contextual information."
1763 (let* ((level (+ (org-export-get-relative-level headline info)
1764 (1- org-html-toplevel-hlevel)))
1765 (headline-number (org-export-get-headline-number headline info))
1766 (section-number (and (not (org-export-low-level-p headline info))
1767 (org-export-numbered-headline-p headline info)
1768 (mapconcat 'number-to-string
1769 headline-number ".")))
1770 (todo (and (plist-get info :with-todo-keywords)
1771 (let ((todo (org-element-property :todo-keyword headline)))
1772 (and todo (org-export-data todo info)))))
1773 (todo-type (and todo (org-element-property :todo-type headline)))
1774 (priority (and (plist-get info :with-priority)
1775 (org-element-property :priority headline)))
1776 (text (org-export-data (org-element-property :title headline) info))
1777 (tags (and (plist-get info :with-tags)
1778 (org-export-get-tags headline info)))
1779 (headline-label (or (org-element-property :CUSTOM_ID headline)
1780 (concat "sec-" (mapconcat 'number-to-string
1781 headline-number "-"))))
1782 (format-function (cond
1783 ((functionp format-function) format-function)
1784 ((functionp org-html-format-headline-function)
1785 (function*
1786 (lambda (todo todo-type priority text tags
1787 &allow-other-keys)
1788 (funcall org-html-format-headline-function
1789 todo todo-type priority text tags))))
1790 (t 'org-html-format-headline))))
1791 (apply format-function
1792 todo todo-type priority text tags
1793 :headline-label headline-label :level level
1794 :section-number section-number extra-keys)))
1796 (defun org-html-headline (headline contents info)
1797 "Transcode a HEADLINE element from Org to HTML.
1798 CONTENTS holds the contents of the headline. INFO is a plist
1799 holding contextual information."
1800 ;; Empty contents?
1801 (setq contents (or contents ""))
1802 (let* ((numberedp (org-export-numbered-headline-p headline info))
1803 (level (org-export-get-relative-level headline info))
1804 (text (org-export-data (org-element-property :title headline) info))
1805 (todo (and (plist-get info :with-todo-keywords)
1806 (let ((todo (org-element-property :todo-keyword headline)))
1807 (and todo (org-export-data todo info)))))
1808 (todo-type (and todo (org-element-property :todo-type headline)))
1809 (tags (and (plist-get info :with-tags)
1810 (org-export-get-tags headline info)))
1811 (priority (and (plist-get info :with-priority)
1812 (org-element-property :priority headline)))
1813 (section-number (and (org-export-numbered-headline-p headline info)
1814 (mapconcat 'number-to-string
1815 (org-export-get-headline-number
1816 headline info) ".")))
1817 ;; Create the headline text.
1818 (full-text (org-html-format-headline--wrap headline info)))
1819 (cond
1820 ;; Case 1: This is a footnote section: ignore it.
1821 ((org-element-property :footnote-section-p headline) nil)
1822 ;; Case 2. This is a deep sub-tree: export it as a list item.
1823 ;; Also export as items headlines for which no section
1824 ;; format has been found.
1825 ((org-export-low-level-p headline info)
1826 ;; Build the real contents of the sub-tree.
1827 (let* ((type (if numberedp 'ordered 'unordered))
1828 (itemized-body (org-html-format-list-item
1829 contents type nil nil full-text)))
1830 (concat
1831 (and (org-export-first-sibling-p headline info)
1832 (org-html-begin-plain-list type))
1833 itemized-body
1834 (and (org-export-last-sibling-p headline info)
1835 (org-html-end-plain-list type)))))
1836 ;; Case 3. Standard headline. Export it as a section.
1838 (let* ((section-number (mapconcat 'number-to-string
1839 (org-export-get-headline-number
1840 headline info) "-"))
1841 (ids (remove 'nil
1842 (list (org-element-property :CUSTOM_ID headline)
1843 (concat "sec-" section-number)
1844 (org-element-property :ID headline))))
1845 (preferred-id (car ids))
1846 (extra-ids (cdr ids))
1847 (extra-class (org-element-property :html-container-class headline))
1848 (level1 (+ level (1- org-html-toplevel-hlevel))))
1849 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1850 (format "outline-container-%s"
1851 (or (org-element-property :CUSTOM_ID headline)
1852 section-number))
1853 (concat (format "outline-%d" level1) (and extra-class " ")
1854 extra-class)
1855 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1856 level1
1857 preferred-id
1858 (mapconcat
1859 (lambda (x)
1860 (let ((id (org-export-solidify-link-text
1861 (if (org-uuidgen-p x) (concat "ID-" x)
1862 x))))
1863 (org-html--anchor id)))
1864 extra-ids "")
1865 full-text
1866 level1)
1867 contents))))))
1870 ;;;; Horizontal Rule
1872 (defun org-html-horizontal-rule (horizontal-rule contents info)
1873 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1874 CONTENTS is nil. INFO is a plist holding contextual information."
1875 "<hr/>")
1878 ;;;; Inline Src Block
1880 (defun org-html-inline-src-block (inline-src-block contents info)
1881 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1882 CONTENTS holds the contents of the item. INFO is a plist holding
1883 contextual information."
1884 (let* ((org-lang (org-element-property :language inline-src-block))
1885 (code (org-element-property :value inline-src-block)))
1886 (error "Cannot export inline src block")))
1889 ;;;; Inlinetask
1891 (defun org-html-format-section (text class &optional id)
1892 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1893 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1895 (defun org-html-inlinetask (inlinetask contents info)
1896 "Transcode an INLINETASK element from Org to HTML.
1897 CONTENTS holds the contents of the block. INFO is a plist
1898 holding contextual information."
1899 (cond
1900 ;; If `org-html-format-inlinetask-function' is provided, call it
1901 ;; with appropriate arguments.
1902 ((functionp org-html-format-inlinetask-function)
1903 (let ((format-function
1904 (function*
1905 (lambda (todo todo-type priority text tags
1906 &key contents &allow-other-keys)
1907 (funcall org-html-format-inlinetask-function
1908 todo todo-type priority text tags contents)))))
1909 (org-html-format-headline--wrap
1910 inlinetask info format-function :contents contents)))
1911 ;; Otherwise, use a default template.
1912 (t (format "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
1913 (org-html-format-headline--wrap inlinetask info)
1914 contents))))
1917 ;;;; Italic
1919 (defun org-html-italic (italic contents info)
1920 "Transcode ITALIC from Org to HTML.
1921 CONTENTS is the text with italic markup. INFO is a plist holding
1922 contextual information."
1923 (format (or (cdr (assq 'italic org-html-text-markup-alist)) "%s") contents))
1926 ;;;; Item
1928 (defun org-html-checkbox (checkbox)
1929 (case checkbox (on "<code>[X]</code>")
1930 (off "<code>[&nbsp;]</code>")
1931 (trans "<code>[-]</code>")
1932 (t "")))
1934 (defun org-html-format-list-item (contents type checkbox
1935 &optional term-counter-id
1936 headline)
1937 (let ((checkbox (concat (org-html-checkbox checkbox) (and checkbox " "))))
1938 (concat
1939 (case type
1940 (ordered
1941 (let* ((counter term-counter-id)
1942 (extra (if counter (format " value=\"%s\"" counter) "")))
1943 (concat
1944 (format "<li%s>" extra)
1945 (when headline (concat headline "<br/>")))))
1946 (unordered
1947 (let* ((id term-counter-id)
1948 (extra (if id (format " id=\"%s\"" id) "")))
1949 (concat
1950 (format "<li%s>" extra)
1951 (when headline (concat headline "<br/>")))))
1952 (descriptive
1953 (let* ((term term-counter-id))
1954 (setq term (or term "(no term)"))
1955 ;; Check-boxes in descriptive lists are associated to tag.
1956 (concat (format "<dt> %s </dt>"
1957 (concat checkbox term))
1958 "<dd>"))))
1959 (unless (eq type 'descriptive) checkbox)
1960 contents
1961 (case type
1962 (ordered "</li>")
1963 (unordered "</li>")
1964 (descriptive "</dd>")))))
1966 (defun org-html-item (item contents info)
1967 "Transcode an ITEM element from Org to HTML.
1968 CONTENTS holds the contents of the item. INFO is a plist holding
1969 contextual information."
1970 (let* ((plain-list (org-export-get-parent item))
1971 (type (org-element-property :type plain-list))
1972 (counter (org-element-property :counter item))
1973 (checkbox (org-element-property :checkbox item))
1974 (tag (let ((tag (org-element-property :tag item)))
1975 (and tag (org-export-data tag info)))))
1976 (org-html-format-list-item
1977 contents type checkbox (or tag counter))))
1980 ;;;; Keyword
1982 (defun org-html-keyword (keyword contents info)
1983 "Transcode a KEYWORD element from Org to HTML.
1984 CONTENTS is nil. INFO is a plist holding contextual information."
1985 (let ((key (org-element-property :key keyword))
1986 (value (org-element-property :value keyword)))
1987 (cond
1988 ((string= key "HTML") value)
1989 ;; Invisible targets.
1990 ((string= key "TARGET") nil)
1991 ((string= key "TOC")
1992 (let ((value (downcase value)))
1993 (cond
1994 ((string-match "\\<headlines\\>" value)
1995 (let ((depth (or (and (string-match "[0-9]+" value)
1996 (string-to-number (match-string 0 value)))
1997 (plist-get info :with-toc))))
1998 (org-html-toc depth info)))
1999 ((string= "tables" value) "\\listoftables")
2000 ((string= "figures" value) "\\listoffigures")
2001 ((string= "listings" value)
2002 (cond
2003 ;; At the moment, src blocks with a caption are wrapped
2004 ;; into a figure environment.
2005 (t "\\listoffigures")))))))))
2008 ;;;; Latex Environment
2010 (defun org-html-format-latex (latex-frag processing-type)
2011 "Format LaTeX fragments into HTML."
2012 (let ((cache-relpath "") (cache-dir "") bfn)
2013 (unless (eq processing-type 'mathjax)
2014 (setq bfn (buffer-file-name)
2015 cache-relpath
2016 (concat "ltxpng/"
2017 (file-name-sans-extension
2018 (file-name-nondirectory bfn)))
2019 cache-dir (file-name-directory bfn)))
2020 (with-temp-buffer
2021 (insert latex-frag)
2022 (org-format-latex cache-relpath cache-dir nil "Creating LaTeX Image..."
2023 nil nil processing-type)
2024 (buffer-string))))
2026 (defun org-html-latex-environment (latex-environment contents info)
2027 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2028 CONTENTS is nil. INFO is a plist holding contextual information."
2029 (let ((processing-type (plist-get info :with-latex))
2030 (latex-frag (org-remove-indentation
2031 (org-element-property :value latex-environment)))
2032 (caption (org-export-data
2033 (org-export-get-caption latex-environment) info))
2034 (attr nil) ; FIXME
2035 (label (org-element-property :name latex-environment)))
2036 (cond
2037 ((memq processing-type '(t mathjax))
2038 (org-html-format-latex latex-frag 'mathjax))
2039 ((eq processing-type 'dvipng)
2040 (let* ((formula-link (org-html-format-latex
2041 latex-frag processing-type)))
2042 (when (and formula-link
2043 (string-match "file:\\([^]]*\\)" formula-link))
2044 (org-html-format-inline-image
2045 (match-string 1 formula-link) caption label attr t))))
2046 (t latex-frag))))
2049 ;;;; Latex Fragment
2051 (defun org-html-latex-fragment (latex-fragment contents info)
2052 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2053 CONTENTS is nil. INFO is a plist holding contextual information."
2054 (let ((latex-frag (org-element-property :value latex-fragment))
2055 (processing-type (plist-get info :with-latex)))
2056 (case processing-type
2057 ((t mathjax)
2058 (org-html-format-latex latex-frag 'mathjax))
2059 (dvipng
2060 (let* ((formula-link (org-html-format-latex
2061 latex-frag processing-type)))
2062 (when (and formula-link
2063 (string-match "file:\\([^]]*\\)" formula-link))
2064 (org-html-format-inline-image
2065 (match-string 1 formula-link)))))
2066 (t latex-frag))))
2069 ;;;; Line Break
2071 (defun org-html-line-break (line-break contents info)
2072 "Transcode a LINE-BREAK object from Org to HTML.
2073 CONTENTS is nil. INFO is a plist holding contextual information."
2074 "<br/>\n")
2077 ;;;; Link
2079 (defun org-html-link--inline-image (link desc info)
2080 "Return HTML code for an inline image.
2081 LINK is the link pointing to the inline image. INFO is a plist
2082 used as a communication channel."
2083 (let* ((type (org-element-property :type link))
2084 (raw-path (org-element-property :path link))
2085 (path (cond ((member type '("http" "https"))
2086 (concat type ":" raw-path))
2087 ((file-name-absolute-p raw-path)
2088 (expand-file-name raw-path))
2089 (t raw-path)))
2090 (parent (org-export-get-parent-element link))
2091 (caption (org-export-data (org-export-get-caption parent) info))
2092 (label (org-element-property :name parent))
2093 ;; Retrieve latex attributes from the element around.
2094 (attr (let ((raw-attr
2095 (mapconcat #'identity
2096 (org-element-property :attr_html parent)
2097 " ")))
2098 (unless (string= raw-attr "") raw-attr))))
2099 ;; Now clear ATTR from any special keyword and set a default
2100 ;; value if nothing is left.
2101 (setq attr (if (not attr) "" (org-trim attr)))
2102 ;; Return proper string, depending on DISPOSITION.
2103 (org-html-format-inline-image
2104 path caption label attr (org-html-standalone-image-p link info))))
2106 (defvar org-html-standalone-image-predicate)
2107 (defun org-html-standalone-image-p (element info &optional predicate)
2108 "Test if ELEMENT is a standalone image for the purpose HTML export.
2109 INFO is a plist holding contextual information.
2111 Return non-nil, if ELEMENT is of type paragraph and it's sole
2112 content, save for whitespaces, is a link that qualifies as an
2113 inline image.
2115 Return non-nil, if ELEMENT is of type link and it's containing
2116 paragraph has no other content save for leading and trailing
2117 whitespaces.
2119 Return nil, otherwise.
2121 Bind `org-html-standalone-image-predicate' to constrain
2122 paragraph further. For example, to check for only captioned
2123 standalone images, do the following.
2125 \(setq org-html-standalone-image-predicate
2126 \(lambda \(paragraph\)
2127 \(org-element-property :caption paragraph\)\)\)"
2128 (let ((paragraph (case (org-element-type element)
2129 (paragraph element)
2130 (link (and (org-export-inline-image-p
2131 element org-html-inline-image-rules)
2132 (org-export-get-parent element)))
2133 (t nil))))
2134 (when (eq (org-element-type paragraph) 'paragraph)
2135 (when (or (not (and (boundp 'org-html-standalone-image-predicate)
2136 (functionp org-html-standalone-image-predicate)))
2137 (funcall org-html-standalone-image-predicate paragraph))
2138 (let ((contents (org-element-contents paragraph)))
2139 (loop for x in contents
2140 with inline-image-count = 0
2141 always (cond
2142 ((eq (org-element-type x) 'plain-text)
2143 (not (org-string-nw-p x)))
2144 ((eq (org-element-type x) 'link)
2145 (when (org-export-inline-image-p
2146 x org-html-inline-image-rules)
2147 (= (incf inline-image-count) 1)))
2148 (t nil))))))))
2150 (defun org-html-link (link desc info)
2151 "Transcode a LINK object from Org to HTML.
2153 DESC is the description part of the link, or the empty string.
2154 INFO is a plist holding contextual information. See
2155 `org-export-data'."
2156 (let* ((--link-org-files-as-html-maybe
2157 (function
2158 (lambda (raw-path info)
2159 "Treat links to `file.org' as links to `file.html', if needed.
2160 See `org-html-link-org-files-as-html'."
2161 (cond
2162 ((and org-html-link-org-files-as-html
2163 (string= ".org"
2164 (downcase (file-name-extension raw-path "."))))
2165 (concat (file-name-sans-extension raw-path) "."
2166 (plist-get info :html-extension)))
2167 (t raw-path)))))
2168 (type (org-element-property :type link))
2169 (raw-path (org-element-property :path link))
2170 ;; Ensure DESC really exists, or set it to nil.
2171 (desc (and (not (string= desc "")) desc))
2172 (path
2173 (cond
2174 ((member type '("http" "https" "ftp" "mailto"))
2175 (concat type ":" raw-path))
2176 ((string= type "file")
2177 ;; Treat links to ".org" files as ".html", if needed.
2178 (setq raw-path
2179 (funcall --link-org-files-as-html-maybe raw-path info))
2180 ;; If file path is absolute, prepend it with protocol
2181 ;; component - "file://".
2182 (when (file-name-absolute-p raw-path)
2183 (setq raw-path
2184 (concat "file://" (expand-file-name raw-path))))
2185 ;; Add search option, if any. A search option can be
2186 ;; relative to a custom-id or a headline title. Any other
2187 ;; option is ignored.
2188 (let ((option (org-element-property :search-option link)))
2189 (cond ((not option) raw-path)
2190 ((eq (aref option 0) ?#) (concat raw-path option))
2191 ;; External fuzzy link: try to resolve it if path
2192 ;; belongs to current project, if any.
2193 ((eq (aref option 0) ?*)
2194 (concat
2195 raw-path
2196 (let ((numbers
2197 (org-publish-resolve-external-fuzzy-link
2198 (org-element-property :path link) option)))
2199 (and numbers (concat "#sec-"
2200 (mapconcat 'number-to-string
2201 numbers "-")))))))))
2202 (t raw-path)))
2203 attributes protocol)
2204 ;; Extract attributes from parent's paragraph.
2205 (and (setq attributes
2206 (mapconcat
2207 'identity
2208 (let ((att (org-element-property
2209 :attr_html (org-export-get-parent-element link))))
2210 (unless (and desc att (string-match (regexp-quote (car att)) desc)) att))
2211 " "))
2212 (setq attributes (concat " " attributes)))
2214 (cond
2215 ;; Image file.
2216 ((and (or (eq t org-html-inline-images)
2217 (and org-html-inline-images (not desc)))
2218 (org-export-inline-image-p link org-html-inline-image-rules))
2219 (org-html-link--inline-image link desc info))
2220 ;; Radio target: Transcode target's contents and use them as
2221 ;; link's description.
2222 ((string= type "radio")
2223 (let ((destination (org-export-resolve-radio-link link info)))
2224 (when destination
2225 (format "<a href=\"#%s\"%s>%s</a>"
2226 (org-export-solidify-link-text path)
2227 attributes
2228 (org-export-data (org-element-contents destination) info)))))
2229 ;; Links pointing to a headline: Find destination and build
2230 ;; appropriate referencing command.
2231 ((member type '("custom-id" "fuzzy" "id"))
2232 (let ((destination (if (string= type "fuzzy")
2233 (org-export-resolve-fuzzy-link link info)
2234 (org-export-resolve-id-link link info))))
2235 (case (org-element-type destination)
2236 ;; ID link points to an external file.
2237 (plain-text
2238 (let ((fragment (concat "ID-" path))
2239 ;; Treat links to ".org" files as ".html", if needed.
2240 (path (funcall --link-org-files-as-html-maybe
2241 destination info)))
2242 (format "<a href=\"%s#%s\"%s>%s</a>"
2243 path fragment attributes (or desc destination))))
2244 ;; Fuzzy link points nowhere.
2245 ((nil)
2246 (format "<i>%s</i>"
2247 (or desc
2248 (org-export-data
2249 (org-element-property :raw-link link) info))))
2250 ;; Fuzzy link points to an invisible target.
2251 (keyword nil)
2252 ;; Link points to a headline.
2253 (headline
2254 (let ((href
2255 ;; What href to use?
2256 (cond
2257 ;; Case 1: Headline is linked via it's CUSTOM_ID
2258 ;; property. Use CUSTOM_ID.
2259 ((string= type "custom-id")
2260 (org-element-property :CUSTOM_ID destination))
2261 ;; Case 2: Headline is linked via it's ID property
2262 ;; or through other means. Use the default href.
2263 ((member type '("id" "fuzzy"))
2264 (format "sec-%s"
2265 (mapconcat 'number-to-string
2266 (org-export-get-headline-number
2267 destination info) "-")))
2268 (t (error "Shouldn't reach here"))))
2269 ;; What description to use?
2270 (desc
2271 ;; Case 1: Headline is numbered and LINK has no
2272 ;; description or LINK's description matches
2273 ;; headline's title. Display section number.
2274 (if (and (org-export-numbered-headline-p destination info)
2275 (or (not desc)
2276 (string= desc (org-element-property
2277 :raw-value destination))))
2278 (mapconcat 'number-to-string
2279 (org-export-get-headline-number
2280 destination info) ".")
2281 ;; Case 2: Either the headline is un-numbered or
2282 ;; LINK has a custom description. Display LINK's
2283 ;; description or headline's title.
2284 (or desc (org-export-data (org-element-property
2285 :title destination) info)))))
2286 (format "<a href=\"#%s\"%s>%s</a>"
2287 (org-export-solidify-link-text href) attributes desc)))
2288 ;; Fuzzy link points to a target. Do as above.
2290 (let ((path (org-export-solidify-link-text path)) number)
2291 (unless desc
2292 (setq number (cond
2293 ((org-html-standalone-image-p destination info)
2294 (org-export-get-ordinal
2295 (assoc 'link (org-element-contents destination))
2296 info 'link 'org-html-standalone-image-p))
2297 (t (org-export-get-ordinal destination info))))
2298 (setq desc (when number
2299 (if (atom number) (number-to-string number)
2300 (mapconcat 'number-to-string number ".")))))
2301 (format "<a href=\"#%s\"%s>%s</a>"
2302 path attributes (or desc "No description for this link")))))))
2303 ;; Coderef: replace link with the reference name or the
2304 ;; equivalent line number.
2305 ((string= type "coderef")
2306 (let ((fragment (concat "coderef-" path)))
2307 (format "<a href=\"#%s\" %s%s>%s</a>"
2308 fragment
2309 (format (concat "class=\"coderef\""
2310 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2311 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2312 fragment fragment)
2313 attributes
2314 (format (org-export-get-coderef-format path desc)
2315 (org-export-resolve-coderef path info)))))
2316 ;; Link type is handled by a special function.
2317 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2318 (funcall protocol (org-link-unescape path) desc 'html))
2319 ;; External link with a description part.
2320 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2321 ;; External link without a description part.
2322 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2323 ;; No path, only description. Try to do something useful.
2324 (t (format "<i>%s</i>" desc)))))
2327 ;;;; Paragraph
2329 (defun org-html-paragraph (paragraph contents info)
2330 "Transcode a PARAGRAPH element from Org to HTML.
2331 CONTENTS is the contents of the paragraph, as a string. INFO is
2332 the plist used as a communication channel."
2333 (let* ((style nil) ; FIXME
2334 (class (cdr (assoc style '((footnote . "footnote")
2335 (verse . nil)))))
2336 (extra (if class (format " class=\"%s\"" class) ""))
2337 (parent (org-export-get-parent paragraph)))
2338 (cond
2339 ((and (eq (org-element-type parent) 'item)
2340 (= (org-element-property :begin paragraph)
2341 (org-element-property :contents-begin parent)))
2342 ;; leading paragraph in a list item have no tags
2343 contents)
2344 ((org-html-standalone-image-p paragraph info)
2345 ;; standalone image
2346 contents)
2347 (t (format "<p%s>\n%s</p>" extra contents)))))
2350 ;;;; Plain List
2352 ;; FIXME Maybe arg1 is not needed because <li value="20"> already sets
2353 ;; the correct value for the item counter
2354 (defun org-html-begin-plain-list (type &optional arg1)
2355 "Insert the beginning of the HTML list depending on TYPE.
2356 When ARG1 is a string, use it as the start parameter for ordered
2357 lists."
2358 (case type
2359 (ordered
2360 (format "<ol class=\"org-ol\"%s>"
2361 (if arg1 (format " start=\"%d\"" arg1) "")))
2362 (unordered "<ul class=\"org-ul\">")
2363 (descriptive "<dl class=\"org-dl\">")))
2365 (defun org-html-end-plain-list (type)
2366 "Insert the end of the HTML list depending on TYPE."
2367 (case type
2368 (ordered "</ol>")
2369 (unordered "</ul>")
2370 (descriptive "</dl>")))
2372 (defun org-html-plain-list (plain-list contents info)
2373 "Transcode a PLAIN-LIST element from Org to HTML.
2374 CONTENTS is the contents of the list. INFO is a plist holding
2375 contextual information."
2376 (let* (arg1 ;; (assoc :counter (org-element-map plain-list 'item
2377 (type (org-element-property :type plain-list)))
2378 (format "%s\n%s%s"
2379 (org-html-begin-plain-list type)
2380 contents (org-html-end-plain-list type))))
2382 ;;;; Plain Text
2384 (defun org-html-convert-special-strings (string)
2385 "Convert special characters in STRING to HTML."
2386 (let ((all org-html-special-string-regexps)
2387 e a re rpl start)
2388 (while (setq a (pop all))
2389 (setq re (car a) rpl (cdr a) start 0)
2390 (while (string-match re string start)
2391 (setq string (replace-match rpl t nil string))))
2392 string))
2394 (defun org-html-encode-plain-text (text)
2395 "Convert plain text characters to HTML equivalent.
2396 Possible conversions are set in `org-export-html-protect-char-alist'."
2397 (mapc
2398 (lambda (pair)
2399 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2400 org-html-protect-char-alist)
2401 text)
2403 (defun org-html-plain-text (text info)
2404 "Transcode a TEXT string from Org to HTML.
2405 TEXT is the string to transcode. INFO is a plist holding
2406 contextual information."
2407 (let ((output text))
2408 ;; Protect following characters: <, >, &.
2409 (setq output (org-html-encode-plain-text output))
2410 ;; Handle smart quotes. Be sure to provide original string since
2411 ;; OUTPUT may have been modified.
2412 (when (plist-get info :with-smart-quotes)
2413 (setq output (org-export-activate-smart-quotes output :html info text)))
2414 ;; Handle special strings.
2415 (when (plist-get info :with-special-strings)
2416 (setq output (org-html-convert-special-strings output)))
2417 ;; Handle break preservation if required.
2418 (when (plist-get info :preserve-breaks)
2419 (setq output
2420 (replace-regexp-in-string
2421 "\\(\\\\\\\\\\)?[ \t]*\n" "<br/>\n" output)))
2422 ;; Return value.
2423 output))
2426 ;; Planning
2428 (defun org-html-planning (planning contents info)
2429 "Transcode a PLANNING element from Org to HTML.
2430 CONTENTS is nil. INFO is a plist used as a communication
2431 channel."
2432 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2433 (format
2434 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2435 (mapconcat
2436 'identity
2437 (delq nil
2438 (list
2439 (let ((closed (org-element-property :closed planning)))
2440 (when closed
2441 (format span-fmt org-closed-string
2442 (org-translate-time
2443 (org-element-property :raw-value closed)))))
2444 (let ((deadline (org-element-property :deadline planning)))
2445 (when deadline
2446 (format span-fmt org-deadline-string
2447 (org-translate-time
2448 (org-element-property :raw-value deadline)))))
2449 (let ((scheduled (org-element-property :scheduled planning)))
2450 (when scheduled
2451 (format span-fmt org-scheduled-string
2452 (org-translate-time
2453 (org-element-property :raw-value scheduled)))))))
2454 " "))))
2457 ;;;; Property Drawer
2459 (defun org-html-property-drawer (property-drawer contents info)
2460 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2461 CONTENTS is nil. INFO is a plist holding contextual
2462 information."
2463 ;; The property drawer isn't exported but we want separating blank
2464 ;; lines nonetheless.
2468 ;;;; Quote Block
2470 (defun org-html-quote-block (quote-block contents info)
2471 "Transcode a QUOTE-BLOCK element from Org to HTML.
2472 CONTENTS holds the contents of the block. INFO is a plist
2473 holding contextual information."
2474 (format "<blockquote>\n%s</blockquote>" contents))
2477 ;;;; Quote Section
2479 (defun org-html-quote-section (quote-section contents info)
2480 "Transcode a QUOTE-SECTION element from Org to HTML.
2481 CONTENTS is nil. INFO is a plist holding contextual information."
2482 (let ((value (org-remove-indentation
2483 (org-element-property :value quote-section))))
2484 (when value (format "<pre>\n%s</pre>" value))))
2487 ;;;; Section
2489 (defun org-html-section (section contents info)
2490 "Transcode a SECTION element from Org to HTML.
2491 CONTENTS holds the contents of the section. INFO is a plist
2492 holding contextual information."
2493 (let ((parent (org-export-get-parent-headline section)))
2494 ;; Before first headline: no container, just return CONTENTS.
2495 (if (not parent) contents
2496 ;; Get div's class and id references.
2497 (let* ((class-num (+ (org-export-get-relative-level parent info)
2498 (1- org-html-toplevel-hlevel)))
2499 (section-number
2500 (mapconcat
2501 'number-to-string
2502 (org-export-get-headline-number parent info) "-")))
2503 ;; Build return value.
2504 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2505 class-num
2506 (or (org-element-property :CUSTOM_ID parent) section-number)
2507 contents)))))
2509 ;;;; Radio Target
2511 (defun org-html-radio-target (radio-target text info)
2512 "Transcode a RADIO-TARGET object from Org to HTML.
2513 TEXT is the text of the target. INFO is a plist holding
2514 contextual information."
2515 (let ((id (org-export-solidify-link-text
2516 (org-element-property :value radio-target))))
2517 (org-html--anchor id text)))
2520 ;;;; Special Block
2522 (defun org-html-special-block (special-block contents info)
2523 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2524 CONTENTS holds the contents of the block. INFO is a plist
2525 holding contextual information."
2526 (format "<div class=\"%s\">\n%s\n</div>"
2527 (downcase (org-element-property :type special-block))
2528 contents))
2531 ;;;; Src Block
2533 (defun org-html-src-block (src-block contents info)
2534 "Transcode a SRC-BLOCK element from Org to HTML.
2535 CONTENTS holds the contents of the item. INFO is a plist holding
2536 contextual information."
2537 (if (org-export-read-attribute :attr_html src-block :textarea)
2538 (org-html--textarea-block src-block)
2539 (let ((lang (org-element-property :language src-block))
2540 (caption (org-export-get-caption src-block))
2541 (code (org-html-format-code src-block info)))
2542 (if (not lang) (format "<pre class=\"example\">\n%s</pre>" code)
2543 (format "<div class=\"org-src-container\">\n%s%s\n</div>"
2544 (if (not caption) ""
2545 (format "<label class=\"org-src-name\">%s</label>"
2546 (org-export-data caption info)))
2547 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code))))))
2550 ;;;; Statistics Cookie
2552 (defun org-html-statistics-cookie (statistics-cookie contents info)
2553 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2554 CONTENTS is nil. INFO is a plist holding contextual information."
2555 (let ((cookie-value (org-element-property :value statistics-cookie)))
2556 (format "<code>%s</code>" cookie-value)))
2559 ;;;; Strike-Through
2561 (defun org-html-strike-through (strike-through contents info)
2562 "Transcode STRIKE-THROUGH from Org to HTML.
2563 CONTENTS is the text with strike-through markup. INFO is a plist
2564 holding contextual information."
2565 (format (or (cdr (assq 'strike-through org-html-text-markup-alist)) "%s")
2566 contents))
2569 ;;;; Subscript
2571 (defun org-html-subscript (subscript contents info)
2572 "Transcode a SUBSCRIPT object from Org to HTML.
2573 CONTENTS is the contents of the object. INFO is a plist holding
2574 contextual information."
2575 (format "<sub>%s</sub>" contents))
2578 ;;;; Superscript
2580 (defun org-html-superscript (superscript contents info)
2581 "Transcode a SUPERSCRIPT object from Org to HTML.
2582 CONTENTS is the contents of the object. INFO is a plist holding
2583 contextual information."
2584 (format "<sup>%s</sup>" contents))
2587 ;;;; Tabel Cell
2589 (defun org-html-table-cell (table-cell contents info)
2590 "Transcode a TABLE-CELL element from Org to HTML.
2591 CONTENTS is nil. INFO is a plist used as a communication
2592 channel."
2593 (let* ((table-row (org-export-get-parent table-cell))
2594 (table (org-export-get-parent-table table-cell))
2595 (cell-attrs
2596 (if (not org-html-table-align-individual-fields) ""
2597 (format (if (and (boundp 'org-html-format-table-no-css)
2598 org-html-format-table-no-css)
2599 " align=\"%s\"" " class=\"%s\"")
2600 (org-export-table-cell-alignment table-cell info)))))
2601 (when (or (not contents) (string= "" (org-trim contents)))
2602 (setq contents "&nbsp;"))
2603 (cond
2604 ((and (org-export-table-has-header-p table info)
2605 (= 1 (org-export-table-row-group table-row info)))
2606 (concat "\n" (format (car org-html-table-header-tags) "col" cell-attrs)
2607 contents (cdr org-html-table-header-tags)))
2608 ((and org-html-table-use-header-tags-for-first-column
2609 (zerop (cdr (org-export-table-cell-address table-cell info))))
2610 (concat "\n" (format (car org-html-table-header-tags) "row" cell-attrs)
2611 contents (cdr org-html-table-header-tags)))
2612 (t (concat "\n" (format (car org-html-table-data-tags) cell-attrs)
2613 contents (cdr org-html-table-data-tags))))))
2616 ;;;; Table Row
2618 (defun org-html-table-row (table-row contents info)
2619 "Transcode a TABLE-ROW element from Org to HTML.
2620 CONTENTS is the contents of the row. INFO is a plist used as a
2621 communication channel."
2622 ;; Rules are ignored since table separators are deduced from
2623 ;; borders of the current row.
2624 (when (eq (org-element-property :type table-row) 'standard)
2625 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2626 (rowgroup-tags
2627 (cond
2628 ;; Case 1: Row belongs to second or subsequent rowgroups.
2629 ((not (= 1 (org-export-table-row-group table-row info)))
2630 '("<tbody>" . "\n</tbody>"))
2631 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2632 ((org-export-table-has-header-p
2633 (org-export-get-parent-table table-row) info)
2634 '("<thead>" . "\n</thead>"))
2635 ;; Case 2: Row is from first and only row group.
2636 (t '("<tbody>" . "\n</tbody>")))))
2637 (concat
2638 ;; Begin a rowgroup?
2639 (when (org-export-table-row-starts-rowgroup-p table-row info)
2640 (car rowgroup-tags))
2641 ;; Actual table row
2642 (concat "\n" (eval (car org-html-table-row-tags))
2643 contents
2644 "\n"
2645 (eval (cdr org-html-table-row-tags)))
2646 ;; End a rowgroup?
2647 (when (org-export-table-row-ends-rowgroup-p table-row info)
2648 (cdr rowgroup-tags))))))
2651 ;;;; Table
2653 (defun org-html-table-first-row-data-cells (table info)
2654 (let ((table-row
2655 (org-element-map table 'table-row
2656 (lambda (row)
2657 (unless (eq (org-element-property :type row) 'rule) row))
2658 info 'first-match))
2659 (special-column-p (org-export-table-has-special-column-p table)))
2660 (if (not special-column-p) (org-element-contents table-row)
2661 (cdr (org-element-contents table-row)))))
2663 (defun org-html-table--table.el-table (table info)
2664 (when (eq (org-element-property :type table) 'table.el)
2665 (require 'table)
2666 (let ((outbuf (with-current-buffer
2667 (get-buffer-create "*org-export-table*")
2668 (erase-buffer) (current-buffer))))
2669 (with-temp-buffer
2670 (insert (org-element-property :value table))
2671 (goto-char 1)
2672 (re-search-forward "^[ \t]*|[^|]" nil t)
2673 (table-generate-source 'html outbuf))
2674 (with-current-buffer outbuf
2675 (prog1 (org-trim (buffer-string))
2676 (kill-buffer) )))))
2678 (defun org-html-table (table contents info)
2679 "Transcode a TABLE element from Org to HTML.
2680 CONTENTS is the contents of the table. INFO is a plist holding
2681 contextual information."
2682 (case (org-element-property :type table)
2683 ;; Case 1: table.el table. Convert it using appropriate tools.
2684 (table.el (org-html-table--table.el-table table info))
2685 ;; Case 2: Standard table.
2687 (let* ((label (org-element-property :name table))
2688 (caption (org-export-get-caption table))
2689 (attributes (mapconcat #'identity
2690 (org-element-property :attr_html table)
2691 " "))
2692 (alignspec
2693 (if (and (boundp 'org-html-format-table-no-css)
2694 org-html-format-table-no-css)
2695 "align=\"%s\"" "class=\"%s\""))
2696 (table-column-specs
2697 (function
2698 (lambda (table info)
2699 (mapconcat
2700 (lambda (table-cell)
2701 (let ((alignment (org-export-table-cell-alignment
2702 table-cell info)))
2703 (concat
2704 ;; Begin a colgroup?
2705 (when (org-export-table-cell-starts-colgroup-p
2706 table-cell info)
2707 "\n<colgroup>")
2708 ;; Add a column. Also specify it's alignment.
2709 (format "\n<col %s/>" (format alignspec alignment))
2710 ;; End a colgroup?
2711 (when (org-export-table-cell-ends-colgroup-p
2712 table-cell info)
2713 "\n</colgroup>"))))
2714 (org-html-table-first-row-data-cells table info) "\n"))))
2715 (table-attributes
2716 (let ((table-tag (plist-get info :html-table-tag)))
2717 (concat
2718 (and (string-match "<table\\(.*\\)>" table-tag)
2719 (match-string 1 table-tag))
2720 (and label (format " id=\"%s\""
2721 (org-export-solidify-link-text label)))
2722 (unless (string= attributes "")
2723 (concat " " attributes))))))
2724 ;; Remove last blank line.
2725 (setq contents (substring contents 0 -1))
2726 (format "<table%s>\n%s\n%s\n%s\n</table>"
2727 table-attributes
2728 (if (not caption) ""
2729 (format "<caption>%s</caption>"
2730 (org-export-data caption info)))
2731 (funcall table-column-specs table info)
2732 contents)))))
2735 ;;;; Target
2737 (defun org-html-target (target contents info)
2738 "Transcode a TARGET object from Org to HTML.
2739 CONTENTS is nil. INFO is a plist holding contextual
2740 information."
2741 (let ((id (org-export-solidify-link-text
2742 (org-element-property :value target))))
2743 (org-html--anchor id)))
2746 ;;;; Timestamp
2748 (defun org-html-timestamp (timestamp contents info)
2749 "Transcode a TIMESTAMP object from Org to HTML.
2750 CONTENTS is nil. INFO is a plist holding contextual
2751 information."
2752 (let ((value (org-html-plain-text
2753 (org-timestamp-translate timestamp) info)))
2754 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2755 (replace-regexp-in-string "--" "&ndash;" value))))
2758 ;;;; Underline
2760 (defun org-html-underline (underline contents info)
2761 "Transcode UNDERLINE from Org to HTML.
2762 CONTENTS is the text with underline markup. INFO is a plist
2763 holding contextual information."
2764 (format (or (cdr (assq 'underline org-html-text-markup-alist)) "%s")
2765 contents))
2768 ;;;; Verbatim
2770 (defun org-html-verbatim (verbatim contents info)
2771 "Transcode VERBATIM from Org to HTML.
2772 CONTENTS is nil. INFO is a plist holding contextual
2773 information."
2774 (format (or (cdr (assq 'verbatim org-html-text-markup-alist)) "%s")
2775 (org-element-property :value verbatim)))
2778 ;;;; Verse Block
2780 (defun org-html-verse-block (verse-block contents info)
2781 "Transcode a VERSE-BLOCK element from Org to HTML.
2782 CONTENTS is verse block contents. INFO is a plist holding
2783 contextual information."
2784 ;; Replace each newline character with line break. Also replace
2785 ;; each blank line with a line break.
2786 (setq contents (replace-regexp-in-string
2787 "^ *\\\\\\\\$" "<br/>\n"
2788 (replace-regexp-in-string
2789 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2790 ;; Replace each white space at beginning of a line with a
2791 ;; non-breaking space.
2792 (while (string-match "^[ \t]+" contents)
2793 (let* ((num-ws (length (match-string 0 contents)))
2794 (ws (let (out) (dotimes (i num-ws out)
2795 (setq out (concat out "&nbsp;"))))))
2796 (setq contents (replace-match ws nil t contents))))
2797 (format "<p class=\"verse\">\n%s</p>" contents))
2801 ;;; Filter Functions
2803 (defun org-html-final-function (contents backend info)
2804 (if (not org-html-pretty-output) contents
2805 (with-temp-buffer
2806 (html-mode)
2807 (insert contents)
2808 (indent-region (point-min) (point-max))
2809 (buffer-substring-no-properties (point-min) (point-max)))))
2813 ;;; End-user functions
2815 ;;;###autoload
2816 (defun org-html-export-as-html
2817 (&optional async subtreep visible-only body-only ext-plist)
2818 "Export current buffer to an HTML buffer.
2820 If narrowing is active in the current buffer, only export its
2821 narrowed part.
2823 If a region is active, export that region.
2825 A non-nil optional argument ASYNC means the process should happen
2826 asynchronously. The resulting buffer should be accessible
2827 through the `org-export-stack' interface.
2829 When optional argument SUBTREEP is non-nil, export the sub-tree
2830 at point, extracting information from the headline properties
2831 first.
2833 When optional argument VISIBLE-ONLY is non-nil, don't export
2834 contents of hidden elements.
2836 When optional argument BODY-ONLY is non-nil, only write code
2837 between \"<body>\" and \"</body>\" tags.
2839 EXT-PLIST, when provided, is a property list with external
2840 parameters overriding Org default settings, but still inferior to
2841 file-local settings.
2843 Export is done in a buffer named \"*Org HTML Export*\", which
2844 will be displayed when `org-export-show-temporary-export-buffer'
2845 is non-nil."
2846 (interactive)
2847 (if async
2848 (org-export-async-start
2849 (lambda (output)
2850 (with-current-buffer (get-buffer-create "*Org HTML Export*")
2851 (erase-buffer)
2852 (insert output)
2853 (goto-char (point-min))
2854 (funcall org-html-display-buffer-mode)
2855 (org-export-add-to-stack (current-buffer) 'html)))
2856 `(org-export-as 'html ,subtreep ,visible-only ,body-only ',ext-plist))
2857 (let ((outbuf (org-export-to-buffer
2858 'html "*Org HTML Export*"
2859 subtreep visible-only body-only ext-plist)))
2860 ;; Set major mode.
2861 (with-current-buffer outbuf (funcall org-html-display-buffer-mode))
2862 (when org-export-show-temporary-export-buffer
2863 (switch-to-buffer-other-window outbuf)))))
2865 ;;;###autoload
2866 (defun org-html-export-to-html
2867 (&optional async subtreep visible-only body-only ext-plist)
2868 "Export current buffer to a HTML file.
2870 If narrowing is active in the current buffer, only export its
2871 narrowed part.
2873 If a region is active, export that region.
2875 A non-nil optional argument ASYNC means the process should happen
2876 asynchronously. The resulting file should be accessible through
2877 the `org-export-stack' interface.
2879 When optional argument SUBTREEP is non-nil, export the sub-tree
2880 at point, extracting information from the headline properties
2881 first.
2883 When optional argument VISIBLE-ONLY is non-nil, don't export
2884 contents of hidden elements.
2886 When optional argument BODY-ONLY is non-nil, only write code
2887 between \"<body>\" and \"</body>\" tags.
2889 EXT-PLIST, when provided, is a property list with external
2890 parameters overriding Org default settings, but still inferior to
2891 file-local settings.
2893 Return output file's name."
2894 (interactive)
2895 (let* ((extension (concat "." org-html-extension))
2896 (file (org-export-output-file-name extension subtreep))
2897 (org-export-coding-system org-html-coding-system))
2898 (if async
2899 (org-export-async-start
2900 (lambda (f) (org-export-add-to-stack f 'html))
2901 (let ((org-export-coding-system org-html-coding-system))
2902 `(expand-file-name
2903 (org-export-to-file
2904 'html ,file ,subtreep ,visible-only ,body-only ',ext-plist))))
2905 (let ((org-export-coding-system org-html-coding-system))
2906 (org-export-to-file
2907 'html file subtreep visible-only body-only ext-plist)))))
2909 ;;;###autoload
2910 (defun org-html-publish-to-html (plist filename pub-dir)
2911 "Publish an org file to HTML.
2913 FILENAME is the filename of the Org file to be published. PLIST
2914 is the property list for the given project. PUB-DIR is the
2915 publishing directory.
2917 Return output file name."
2918 (org-publish-org-to 'html filename ".html" plist pub-dir))
2922 ;;; FIXME
2924 ;;;; org-format-table-html
2925 ;;;; org-format-org-table-html
2926 ;;;; org-format-table-table-html
2927 ;;;; org-table-number-fraction
2928 ;;;; org-table-number-regexp
2929 ;;;; org-html-table-caption-above
2930 ;;;; org-html-with-timestamp
2931 ;;;; org-html-html-helper-timestamp
2932 ;;;; org-html-inline-image-extensions
2933 ;;;; org-export-preferred-target-alist
2934 ;;;; class for anchors
2935 ;;;; org-export-with-section-numbers, body-only
2936 ;;;; org-export-mark-todo-in-toc
2937 ;;;; org-html-format-org-link
2938 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
2939 ;;;; alt = (file-name-nondirectory path)
2941 (provide 'ox-html)
2943 ;; Local variables:
2944 ;; generated-autoload-file: "org-loaddefs.el"
2945 ;; End:
2947 ;;; ox-html.el ends here