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