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