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