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