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