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