org.texi (Installation): Enhance instructions again
[org-mode.git] / contrib / lisp / org-e-html.el
blob477bc235b081a2ffed0a0a4b5044f936e27b1a48
1 ;;; org-e-html.el --- HTML Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2013 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a HTML back-end for Org generic exporter.
25 ;; To test it, run
27 ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
29 ;; in an org-mode buffer then switch to the buffer to see the HTML
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
33 ;;; Code:
35 ;;; org-e-html.el
36 ;;; Dependencies
38 (require 'org-export)
39 (require '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 (macro . org-e-html-macro)
80 (paragraph . org-e-html-paragraph)
81 (plain-list . org-e-html-plain-list)
82 (plain-text . org-e-html-plain-text)
83 (planning . org-e-html-planning)
84 (property-drawer . org-e-html-property-drawer)
85 (quote-block . org-e-html-quote-block)
86 (quote-section . org-e-html-quote-section)
87 (radio-target . org-e-html-radio-target)
88 (section . org-e-html-section)
89 (special-block . org-e-html-special-block)
90 (src-block . org-e-html-src-block)
91 (statistics-cookie . org-e-html-statistics-cookie)
92 (strike-through . org-e-html-strike-through)
93 (subscript . org-e-html-subscript)
94 (superscript . org-e-html-superscript)
95 (table . org-e-html-table)
96 (table-cell . org-e-html-table-cell)
97 (table-row . org-e-html-table-row)
98 (target . org-e-html-target)
99 (template . org-e-html-template)
100 (timestamp . org-e-html-timestamp)
101 (underline . org-e-html-underline)
102 (verbatim . org-e-html-verbatim)
103 (verse-block . org-e-html-verse-block))
104 :export-block "HTML"
105 :filters-alist ((:filter-final-output . org-e-html-final-function))
106 :options-alist
107 ;; FIXME: Prefix KEYWORD and OPTION with "HTML_". Prefix
108 ;; corresponding properties with `:html-". If such a renaming is
109 ;; taken up, some changes will be required in `org-jsinfo.el',
110 ;; I think. So defer renaming for now.
111 ((:agenda-style nil nil org-agenda-export-html-style)
112 (:creator "CREATOR" nil org-e-html-creator-string)
113 (:convert-org-links nil nil org-e-html-link-org-files-as-html)
114 ;; (:expand-quoted-html nil "@" org-e-html-expand)
115 (:inline-images nil nil org-e-html-inline-images)
116 (:link-home "LINK_HOME" nil org-e-html-link-home)
117 (:link-up "LINK_UP" nil org-e-html-link-up)
118 (:style nil nil org-e-html-style)
119 (:style-extra "STYLE" nil org-e-html-style-extra newline)
120 (:style-include-default nil nil org-e-html-style-include-default)
121 (:style-include-scripts nil nil org-e-html-style-include-scripts)
122 ;; (:timestamp nil nil org-e-html-with-timestamp)
123 (:html-extension nil nil org-e-html-extension)
124 (:html-postamble nil nil org-e-html-postamble)
125 (:html-preamble nil nil org-e-html-preamble)
126 (:html-table-tag nil nil org-e-html-table-tag)
127 (:xml-declaration nil nil org-e-html-xml-declaration)
128 (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)
129 (:mathjax "MATHJAX" nil "" space)))
133 ;;; Internal Variables
135 ;; FIXME: it already exists in org-e-html.el
136 (defconst org-e-html-cvt-link-fn
138 "Function to convert link URLs to exportable URLs.
139 Takes two arguments, TYPE and PATH.
140 Returns exportable url as (TYPE PATH), or nil to signal that it
141 didn't handle this case.
142 Intended to be locally bound around a call to `org-export-as-html'." )
144 (defvar org-e-html-format-table-no-css)
145 (defvar htmlize-buffer-places) ; from htmlize.el
146 (defvar body-only) ; dynamically scoped into this.
148 (defconst org-e-html-special-string-regexps
149 '(("\\\\-" . "&shy;")
150 ("---\\([^-]\\)" . "&mdash;\\1")
151 ("--\\([^-]\\)" . "&ndash;\\1")
152 ("\\.\\.\\." . "&hellip;"))
153 "Regular expressions for special string conversion.")
156 (defconst org-e-html-scripts
157 "<script type=\"text/javascript\">
158 <!--/*--><![CDATA[/*><!--*/
159 function CodeHighlightOn(elem, id)
161 var target = document.getElementById(id);
162 if(null != target) {
163 elem.cacheClassElem = elem.className;
164 elem.cacheClassTarget = target.className;
165 target.className = \"code-highlighted\";
166 elem.className = \"code-highlighted\";
169 function CodeHighlightOff(elem, id)
171 var target = document.getElementById(id);
172 if(elem.cacheClassElem)
173 elem.className = elem.cacheClassElem;
174 if(elem.cacheClassTarget)
175 target.className = elem.cacheClassTarget;
177 /*]]>*///-->
178 </script>"
179 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
182 (defconst org-e-html-style-default
183 "<style type=\"text/css\">
184 <!--/*--><![CDATA[/*><!--*/
185 html { font-family: Times, serif; font-size: 12pt; }
186 .title { text-align: center; }
187 .todo { color: red; }
188 .done { color: green; }
189 .tag { background-color: #add8e6; font-weight:normal }
190 .target { }
191 .timestamp { color: #bebebe; }
192 .timestamp-kwd { color: #5f9ea0; }
193 .right {margin-left:auto; margin-right:0px; text-align:right;}
194 .left {margin-left:0px; margin-right:auto; text-align:left;}
195 .center {margin-left:auto; margin-right:auto; text-align:center;}
196 p.verse { margin-left: 3% }
197 pre {
198 border: 1pt solid #AEBDCC;
199 background-color: #F3F5F7;
200 padding: 5pt;
201 font-family: courier, monospace;
202 font-size: 90%;
203 overflow:auto;
205 table { border-collapse: collapse; }
206 td, th { vertical-align: top; }
207 th.right { text-align:center; }
208 th.left { text-align:center; }
209 th.center { text-align:center; }
210 td.right { text-align:right; }
211 td.left { text-align:left; }
212 td.center { text-align:center; }
213 dt { font-weight: bold; }
214 div.figure { padding: 0.5em; }
215 div.figure p { text-align: center; }
216 div.inlinetask {
217 padding:10px;
218 border:2px solid gray;
219 margin:10px;
220 background: #ffffcc;
222 textarea { overflow-x: auto; }
223 .linenr { font-size:smaller }
224 .code-highlighted {background-color:#ffff00;}
225 .org-info-js_info-navigation { border-style:none; }
226 #org-info-js_console-label { font-size:10px; font-weight:bold;
227 white-space:nowrap; }
228 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
229 font-weight:bold; }
230 /*]]>*/-->
231 </style>"
232 "The default style specification for exported HTML files.
233 Please use the variables `org-e-html-style' and
234 `org-e-html-style-extra' to add to this style. If you wish to not
235 have the default style included, customize the variable
236 `org-e-html-style-include-default'.")
240 (defvar org-e-html-content-div "content"
241 "The name of the container DIV that holds all the page contents.
243 This variable is obsolete since Org version 7.7.
244 Please set `org-e-html-divs' instead.")
248 ;;; User Configuration Variables
250 (defgroup org-export-e-html nil
251 "Options for exporting Org mode files to HTML."
252 :tag "Org Export HTML"
253 :group 'org-export)
255 (defgroup org-export-e-htmlize nil
256 "Options for processing examples with htmlize.el."
257 :tag "Org Export Htmlize"
258 :group 'org-export-e-html)
261 ;;;; Bold etc
263 (defcustom org-e-html-text-markup-alist
264 '((bold . "<b>%s</b>")
265 (code . "<code>%s</code>")
266 (italic . "<i>%s</i>")
267 (strike-through . "<del>%s</del>")
268 (underline . "<span style=\"text-decoration:underline;\">%s</span>")
269 (verbatim . "<code>%s</code>"))
270 "Alist of HTML expressions to convert text markup
272 The key must be a symbol among `bold', `code', `italic',
273 `strike-through', `underline' and `verbatim'. The value is
274 a formatting string to wrap fontified text with.
276 If no association can be found for a given markup, text will be
277 returned as-is."
278 :group 'org-export-e-html
279 :type '(alist :key-type (symbol :tag "Markup type")
280 :value-type (string :tag "Format string"))
281 :options '(bold code italic strike-through underline verbatim))
284 ;;;; Debugging
286 (defcustom org-e-html-pretty-output nil
287 "Enable this to generate pretty HTML."
288 :group 'org-export-e-html
289 :type 'boolean)
292 ;;;; Drawers
294 (defcustom org-e-html-format-drawer-function nil
295 "Function called to format a drawer in HTML code.
297 The function must accept two parameters:
298 NAME the drawer name, like \"LOGBOOK\"
299 CONTENTS the contents of the drawer.
301 The function should return the string to be exported.
303 For example, the variable could be set to the following function
304 in order to mimic default behaviour:
306 \(defun org-e-html-format-drawer-default \(name contents\)
307 \"Format a drawer element for HTML export.\"
308 contents\)"
309 :group 'org-export-e-html
310 :type 'function)
313 ;;;; Footnotes
315 (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
316 <h2 class=\"footnotes\">%s: </h2>
317 <div id=\"text-footnotes\">
319 </div>
320 </div>"
321 "Format for the footnotes section.
322 Should contain a two instances of %s. The first will be replaced with the
323 language-specific word for \"Footnotes\", the second one will be replaced
324 by the footnotes themselves."
325 :group 'org-export-e-html
326 :type 'string)
328 (defcustom org-e-html-footnote-format "<sup>%s</sup>"
329 "The format for the footnote reference.
330 %s will be replaced by the footnote reference itself."
331 :group 'org-export-e-html
332 :type 'string)
334 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
335 "Text used to separate footnotes."
336 :group 'org-export-e-html
337 :type 'string)
340 ;;;; Headline
342 (defcustom org-e-html-toplevel-hlevel 2
343 "The <H> level for level 1 headings in HTML export.
344 This is also important for the classes that will be wrapped around headlines
345 and outline structure. If this variable is 1, the top-level headlines will
346 be <h1>, and the corresponding classes will be outline-1, section-number-1,
347 and outline-text-1. If this is 2, all of these will get a 2 instead.
348 The default for this variable is 2, because we use <h1> for formatting the
349 document title."
350 :group 'org-export-e-html
351 :type 'string)
353 (defcustom org-e-html-format-headline-function nil
354 "Function to format headline text.
356 This function will be called with 5 arguments:
357 TODO the todo keyword (string or nil).
358 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
359 PRIORITY the priority of the headline (integer or nil)
360 TEXT the main headline text (string).
361 TAGS the tags (string or nil).
363 The function result will be used in the section format string.
365 As an example, one could set the variable to the following, in
366 order to reproduce the default set-up:
368 \(defun org-e-html-format-headline \(todo todo-type priority text tags)
369 \"Default format function for an headline.\"
370 \(concat \(when todo
371 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
372 \(when priority
373 \(format \"\\\\framebox{\\\\#%c} \" priority))
374 text
375 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
376 :group 'org-export-e-html
377 :type 'function)
380 ;;;; HTML-specific
382 (defcustom org-e-html-allow-name-attribute-in-anchors t
383 "When nil, do not set \"name\" attribute in anchors.
384 By default, anchors are formatted with both \"id\" and \"name\"
385 attributes, when appropriate."
386 :group 'org-export-e-html
387 :type 'boolean)
390 ;;;; Inlinetasks
392 (defcustom org-e-html-format-inlinetask-function nil
393 "Function called to format an inlinetask in HTML code.
395 The function must accept six parameters:
396 TODO the todo keyword, as a string
397 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
398 PRIORITY the inlinetask priority, as a string
399 NAME the inlinetask name, as a string.
400 TAGS the inlinetask tags, as a list of strings.
401 CONTENTS the contents of the inlinetask, as a string.
403 The function should return the string to be exported.
405 For example, the variable could be set to the following function
406 in order to mimic default behaviour:
408 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
409 \"Format an inline task element for HTML export.\"
410 \(let \(\(full-title
411 \(concat
412 \(when todo
413 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
414 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
415 title
416 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
417 \(format (concat \"\\\\begin{center}\\n\"
418 \"\\\\fbox{\\n\"
419 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
420 \"%s\\n\\n\"
421 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
422 \"%s\"
423 \"\\\\end{minipage}}\"
424 \"\\\\end{center}\")
425 full-title contents))"
426 :group 'org-export-e-html
427 :type 'function)
430 ;;;; Links :: Generic
432 (defcustom org-e-html-link-org-files-as-html t
433 "Non-nil means make file links to `file.org' point to `file.html'.
434 When org-mode is exporting an org-mode file to HTML, links to
435 non-html files are directly put into a href tag in HTML.
436 However, links to other Org-mode files (recognized by the
437 extension `.org.) should become links to the corresponding html
438 file, assuming that the linked org-mode file will also be
439 converted to HTML.
440 When nil, the links still point to the plain `.org' file."
441 :group 'org-export-e-html
442 :type 'boolean)
445 ;;;; Links :: Inline images
447 (defcustom org-e-html-inline-images 'maybe
448 "Non-nil means inline images into exported HTML pages.
449 This is done using an <img> tag. When nil, an anchor with href is used to
450 link to the image. If this option is `maybe', then images in links with
451 an empty description will be inlined, while images with a description will
452 be linked only."
453 :group 'org-export-e-html
454 :type '(choice (const :tag "Never" nil)
455 (const :tag "Always" t)
456 (const :tag "When there is no description" maybe)))
458 (defcustom org-e-html-inline-image-rules
459 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
460 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
461 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
462 "Rules characterizing image files that can be inlined into HTML.
464 A rule consists in an association whose key is the type of link
465 to consider, and value is a regexp that will be matched against
466 link's path.
468 Note that, by default, the image extension *actually* allowed
469 depend on the way the HTML file is processed. When used with
470 pdflatex, pdf, jpg and png images are OK. When processing
471 through dvi to Postscript, only ps and eps are allowed. The
472 default we use here encompasses both."
473 :group 'org-export-e-html
474 :type '(alist :key-type (string :tag "Type")
475 :value-type (regexp :tag "Path")))
478 ;;;; Plain Text
480 (defcustom org-e-html-protect-char-alist
481 '(("&" . "&amp;")
482 ("<" . "&lt;")
483 (">" . "&gt;"))
484 "Alist of characters to be converted by `org-e-html-protect'."
485 :group 'org-export-e-html
486 :type '(repeat (cons (string :tag "Character")
487 (string :tag "HTML equivalent"))))
489 (defcustom org-e-html-quotes
490 '(("fr"
491 ("\\(\\s-\\|[[(]\\|^\\)\"" . "&laquo;&nbsp;")
492 ("\\(\\S-\\)\"" . "&nbsp;&raquo;")
493 ("\\(\\s-\\|(\\|^\\)'" . "&rsquo;"))
494 ("en"
495 ("\\(\\s-\\|[[(]\\|^\\)\"" . "&ldquo;")
496 ("\\(\\S-\\)\"" . "&rdquo;")
497 ("\\(\\s-\\|(\\|^\\)'" . "&lsquo;")))
498 "Alist for quotes to use when converting english double-quotes.
500 The CAR of each item in this alist is the language code.
501 The CDR of each item in this alist is a list of three CONS:
502 - the first CONS defines the opening quote;
503 - the second CONS defines the closing quote;
504 - the last CONS defines single quotes.
506 For each item in a CONS, the first string is a regexp
507 for allowed characters before/after the quote, the second
508 string defines the replacement string for this quote."
509 :group 'org-export-e-html
510 :type '(list
511 (cons :tag "Opening quote"
512 (string :tag "Regexp for char before")
513 (string :tag "Replacement quote "))
514 (cons :tag "Closing quote"
515 (string :tag "Regexp for char after ")
516 (string :tag "Replacement quote "))
517 (cons :tag "Single quote"
518 (string :tag "Regexp for char before")
519 (string :tag "Replacement quote "))))
522 ;;;; Src Block
524 (defcustom org-export-e-htmlize-output-type 'inline-css
525 "Output type to be used by htmlize when formatting code snippets.
526 Choices are `css', to export the CSS selectors only, or `inline-css', to
527 export the CSS attribute values inline in the HTML. We use as default
528 `inline-css', in order to make the resulting HTML self-containing.
530 However, this will fail when using Emacs in batch mode for export, because
531 then no rich font definitions are in place. It will also not be good if
532 people with different Emacs setup contribute HTML files to a website,
533 because the fonts will represent the individual setups. In these cases,
534 it is much better to let Org/Htmlize assign classes only, and to use
535 a style file to define the look of these classes.
536 To get a start for your css file, start Emacs session and make sure that
537 all the faces you are interested in are defined, for example by loading files
538 in all modes you want. Then, use the command
539 \\[org-export-e-htmlize-generate-css] to extract class definitions."
540 :group 'org-export-e-htmlize
541 :type '(choice (const css) (const inline-css)))
543 (defcustom org-export-e-htmlize-css-font-prefix "org-"
544 "The prefix for CSS class names for htmlize font specifications."
545 :group 'org-export-e-htmlize
546 :type 'string)
548 (defcustom org-export-e-htmlized-org-css-url nil
549 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
550 Normally when creating an htmlized version of an Org buffer, htmlize will
551 create CSS to define the font colors. However, this does not work when
552 converting in batch mode, and it also can look bad if different people
553 with different fontification setup work on the same website.
554 When this variable is non-nil, creating an htmlized version of an Org buffer
555 using `org-export-as-org' will remove the internal CSS section and replace it
556 with a link to this URL."
557 :group 'org-export-e-htmlize
558 :type '(choice
559 (const :tag "Keep internal css" nil)
560 (string :tag "URL or local href")))
563 ;;;; Table
565 (defcustom org-e-html-table-tag
566 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
567 "The HTML tag that is used to start a table.
568 This must be a <table> tag, but you may change the options like
569 borders and spacing."
570 :group 'org-export-e-html
571 :type 'string)
573 (defcustom org-e-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
574 "The opening tag for table header fields.
575 This is customizable so that alignment options can be specified.
576 The first %s will be filled with the scope of the field, either row or col.
577 The second %s will be replaced by a style entry to align the field.
578 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
579 See also the variable `org-e-html-table-align-individual-fields'."
580 :group 'org-export-tables ; FIXME: change group?
581 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
583 (defcustom org-e-html-table-data-tags '("<td%s>" . "</td>")
584 "The opening tag for table data fields.
585 This is customizable so that alignment options can be specified.
586 The first %s will be filled with the scope of the field, either row or col.
587 The second %s will be replaced by a style entry to align the field.
588 See also the variable `org-e-html-table-align-individual-fields'."
589 :group 'org-export-tables
590 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
592 (defcustom org-e-html-table-row-tags '("<tr>" . "</tr>")
593 "The opening tag for table data fields.
594 This is customizable so that alignment options can be specified.
595 Instead of strings, these can be Lisp forms that will be evaluated
596 for each row in order to construct the table row tags. During evaluation,
597 the variable `head' will be true when this is a header line, nil when this
598 is a body line. And the variable `nline' will contain the line number,
599 starting from 1 in the first header line. For example
601 (setq org-e-html-table-row-tags
602 (cons '(if head
603 \"<tr>\"
604 (if (= (mod nline 2) 1)
605 \"<tr class=\\\"tr-odd\\\">\"
606 \"<tr class=\\\"tr-even\\\">\"))
607 \"</tr>\"))
609 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
610 :group 'org-export-tables
611 :type '(cons
612 (choice :tag "Opening tag"
613 (string :tag "Specify")
614 (sexp))
615 (choice :tag "Closing tag"
616 (string :tag "Specify")
617 (sexp))))
619 (defcustom org-e-html-table-align-individual-fields t
620 "Non-nil means attach style attributes for alignment to each table field.
621 When nil, alignment will only be specified in the column tags, but this
622 is ignored by some browsers (like Firefox, Safari). Opera does it right
623 though."
624 :group 'org-export-tables
625 :type 'boolean)
627 (defcustom org-e-html-table-use-header-tags-for-first-column nil
628 "Non-nil means format column one in tables with header tags.
629 When nil, also column one will use data tags."
630 :group 'org-export-tables
631 :type 'boolean)
633 (defcustom org-e-html-table-caption-above t
634 "When non-nil, place caption string at the beginning of the table.
635 Otherwise, place it near the end."
636 :group 'org-export-e-html
637 :type 'boolean)
640 ;;;; Tags
642 (defcustom org-e-html-tag-class-prefix ""
643 "Prefix to class names for TODO keywords.
644 Each tag gets a class given by the tag itself, with this prefix.
645 The default prefix is empty because it is nice to just use the keyword
646 as a class name. But if you get into conflicts with other, existing
647 CSS classes, then this prefix can be very useful."
648 :group 'org-export-e-html
649 :type 'string)
652 ;;;; Template :: Generic
654 (defcustom org-e-html-extension "html"
655 "The extension for exported HTML files."
656 :group 'org-export-e-html
657 :type 'string)
659 (defcustom org-e-html-xml-declaration
660 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
661 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
662 "The extension for exported HTML files.
663 %s will be replaced with the charset of the exported file.
664 This may be a string, or an alist with export extensions
665 and corresponding declarations."
666 :group 'org-export-e-html
667 :type '(choice
668 (string :tag "Single declaration")
669 (repeat :tag "Dependent on extension"
670 (cons (string :tag "Extension")
671 (string :tag "Declaration")))))
673 (defcustom org-e-html-coding-system 'utf-8
674 "Coding system for HTML export.
675 Use utf-8 as the default value."
676 :group 'org-export-e-html
677 :type 'coding-system)
679 (defcustom org-e-html-divs '("preamble" "content" "postamble")
680 "The name of the main divs for HTML export.
681 This is a list of three strings, the first one for the preamble
682 DIV, the second one for the content DIV and the third one for the
683 postamble DIV."
684 :group 'org-export-e-html
685 :type '(list
686 (string :tag " Div for the preamble:")
687 (string :tag " Div for the content:")
688 (string :tag "Div for the postamble:")))
691 ;;;; Template :: Mathjax
693 (defcustom org-e-html-mathjax-options
694 '((path "http://orgmode.org/mathjax/MathJax.js")
695 (scale "100")
696 (align "center")
697 (indent "2em")
698 (mathml nil))
699 "Options for MathJax setup.
701 path The path where to find MathJax
702 scale Scaling for the HTML-CSS backend, usually between 100 and 133
703 align How to align display math: left, center, or right
704 indent If align is not center, how far from the left/right side?
705 mathml Should a MathML player be used if available?
706 This is faster and reduces bandwidth use, but currently
707 sometimes has lower spacing quality. Therefore, the default is
708 nil. When browsers get better, this switch can be flipped.
710 You can also customize this for each buffer, using something like
712 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
713 :group 'org-export-e-html
714 :type '(list :greedy t
715 (list :tag "path (the path from where to load MathJax.js)"
716 (const :format " " path) (string))
717 (list :tag "scale (scaling for the displayed math)"
718 (const :format " " scale) (string))
719 (list :tag "align (alignment of displayed equations)"
720 (const :format " " align) (string))
721 (list :tag "indent (indentation with left or right alignment)"
722 (const :format " " indent) (string))
723 (list :tag "mathml (should MathML display be used is possible)"
724 (const :format " " mathml) (boolean))))
726 (defcustom org-e-html-mathjax-template
727 "<script type=\"text/javascript\" src=\"%PATH\">
728 <!--/*--><![CDATA[/*><!--*/
729 MathJax.Hub.Config({
730 // Only one of the two following lines, depending on user settings
731 // First allows browser-native MathML display, second forces HTML/CSS
732 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
733 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
734 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
735 \"TeX/noUndefined.js\"],
736 tex2jax: {
737 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
738 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
739 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
740 ignoreClass: \"tex2jax_ignore\",
741 processEscapes: false,
742 processEnvironments: true,
743 preview: \"TeX\"
745 showProcessingMessages: true,
746 displayAlign: \"%ALIGN\",
747 displayIndent: \"%INDENT\",
749 \"HTML-CSS\": {
750 scale: %SCALE,
751 availableFonts: [\"STIX\",\"TeX\"],
752 preferredFont: \"TeX\",
753 webFont: \"TeX\",
754 imageFont: \"TeX\",
755 showMathMenu: true,
757 MMLorHTML: {
758 prefer: {
759 MSIE: \"MML\",
760 Firefox: \"MML\",
761 Opera: \"HTML\",
762 other: \"HTML\"
766 /*]]>*///-->
767 </script>"
768 "The MathJax setup for XHTML files."
769 :group 'org-export-e-html
770 :type 'string)
773 ;;;; Template :: Postamble
775 (defcustom org-e-html-postamble 'auto
776 "Non-nil means insert a postamble in HTML export.
778 When `t', insert a string as defined by the formatting string in
779 `org-e-html-postamble-format'. When set to a string, this
780 string overrides `org-e-html-postamble-format'. When set to
781 'auto, discard `org-e-html-postamble-format' and honor
782 `org-export-author/email/creator-info' variables. When set to a
783 function, apply this function and insert the returned string.
784 The function takes the property list of export options as its
785 only argument.
787 Setting :html-postamble in publishing projects will take
788 precedence over this variable."
789 :group 'org-export-e-html
790 :type '(choice (const :tag "No postamble" nil)
791 (const :tag "Auto preamble" 'auto)
792 (const :tag "Default formatting string" t)
793 (string :tag "Custom formatting string")
794 (function :tag "Function (must return a string)")))
796 (defcustom org-e-html-postamble-format
797 '(("en" "<p class=\"author\">Author: %a (%e)</p>
798 <p class=\"date\">Date: %d</p>
799 <p class=\"creator\">Generated by %c</p>
800 <p class=\"xhtml-validation\">%v</p>
802 "The format for the HTML postamble.
804 %a stands for the author's name.
805 %e stands for the author's email.
806 %d stands for the date.
807 %c will be replaced by information about Org/Emacs versions.
808 %v will be replaced by `org-e-html-validation-link'.
810 If you need to use a \"%\" character, you need to escape it
811 like that: \"%%\"."
812 :group 'org-export-e-html
813 :type 'string)
815 (defcustom org-e-html-validation-link
816 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
817 "Link to HTML validation service."
818 :group 'org-export-e-html
819 :type 'string)
821 (defcustom org-e-html-creator-string
822 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
823 (if (fboundp 'org-version) (org-version) "(Unknown)")
824 emacs-version)
825 "String to insert at the end of the HTML document."
826 :group 'org-export-e-html
827 :type '(string :tag "Creator string"))
830 ;;;; Template :: Preamble
832 (defcustom org-e-html-preamble t
833 "Non-nil means insert a preamble in HTML export.
835 When `t', insert a string as defined by one of the formatting
836 strings in `org-e-html-preamble-format'. When set to a
837 string, this string overrides `org-e-html-preamble-format'.
838 When set to a function, apply this function and insert the
839 returned string. The function takes the property list of export
840 options as its only argument.
842 Setting :html-preamble in publishing projects will take
843 precedence over this variable."
844 :group 'org-export-e-html
845 :type '(choice (const :tag "No preamble" nil)
846 (const :tag "Default preamble" t)
847 (string :tag "Custom formatting string")
848 (function :tag "Function (must return a string)")))
850 (defcustom org-e-html-preamble-format '(("en" ""))
851 "The format for the HTML preamble.
853 %t stands for the title.
854 %a stands for the author's name.
855 %e stands for the author's email.
856 %d stands for the date.
858 If you need to use a \"%\" character, you need to escape it
859 like that: \"%%\"."
860 :group 'org-export-e-html
861 :type 'string)
863 (defcustom org-e-html-link-up ""
864 "Where should the \"UP\" link of exported HTML pages lead?"
865 :group 'org-export-e-html
866 :type '(string :tag "File or URL"))
868 (defcustom org-e-html-link-home ""
869 "Where should the \"HOME\" link of exported HTML pages lead?"
870 :group 'org-export-e-html
871 :type '(string :tag "File or URL"))
873 (defcustom org-e-html-home/up-format
874 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
875 <a accesskey=\"h\" href=\"%s\"> UP </a>
877 <a accesskey=\"H\" href=\"%s\"> HOME </a>
878 </div>"
879 "Snippet used to insert the HOME and UP links.
880 This is a format string, the first %s will receive the UP link,
881 the second the HOME link. If both `org-e-html-link-up' and
882 `org-e-html-link-home' are empty, the entire snippet will be
883 ignored."
884 :group 'org-export-e-html
885 :type 'string)
888 ;;;; Template :: Scripts
890 (defcustom org-e-html-style-include-scripts t
891 "Non-nil means include the JavaScript snippets in exported HTML files.
892 The actual script is defined in `org-e-html-scripts' and should
893 not be modified."
894 :group 'org-export-e-html
895 :type 'boolean)
898 ;;;; Template :: Styles
900 (defcustom org-e-html-style-include-default t
901 "Non-nil means include the default style in exported HTML files.
902 The actual style is defined in `org-e-html-style-default' and should
903 not be modified. Use the variables `org-e-html-style' to add
904 your own style information."
905 :group 'org-export-e-html
906 :type 'boolean)
907 ;;;###autoload
908 (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
910 (defcustom org-e-html-style ""
911 "Org-wide style definitions for exported HTML files.
913 This variable needs to contain the full HTML structure to provide a style,
914 including the surrounding HTML tags. If you set the value of this variable,
915 you should consider to include definitions for the following classes:
916 title, todo, done, timestamp, timestamp-kwd, tag, target.
918 For example, a valid value would be:
920 <style type=\"text/css\">
921 <![CDATA[
922 p { font-weight: normal; color: gray; }
923 h1 { color: black; }
924 .title { text-align: center; }
925 .todo, .timestamp-kwd { color: red; }
926 .done { color: green; }
928 </style>
930 If you'd like to refer to an external style file, use something like
932 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
934 As the value of this option simply gets inserted into the HTML <head> header,
935 you can \"misuse\" it to add arbitrary text to the header.
936 See also the variable `org-e-html-style-extra'."
937 :group 'org-export-e-html
938 :type 'string)
939 ;;;###autoload
940 (put 'org-e-html-style 'safe-local-variable 'stringp)
942 (defcustom org-e-html-style-extra ""
943 "Additional style information for HTML export.
944 The value of this variable is inserted into the HTML buffer right after
945 the value of `org-e-html-style'. Use this variable for per-file
946 settings of style information, and do not forget to surround the style
947 settings with <style>...</style> tags."
948 :group 'org-export-e-html
949 :type 'string)
950 ;;;###autoload
951 (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
954 ;;;; Todos
956 (defcustom org-e-html-todo-kwd-class-prefix ""
957 "Prefix to class names for TODO keywords.
958 Each TODO keyword gets a class given by the keyword itself, with this prefix.
959 The default prefix is empty because it is nice to just use the keyword
960 as a class name. But if you get into conflicts with other, existing
961 CSS classes, then this prefix can be very useful."
962 :group 'org-export-e-html
963 :type 'string)
967 ;;; Internal Functions
969 (defun org-e-html-format-inline-image (src &optional
970 caption label attr standalone-p)
971 (let* ((id (if (not label) ""
972 (format " id=\"%s\"" (org-export-solidify-link-text label))))
973 (attr (concat attr
974 (cond
975 ((string-match "\\<alt=" (or attr "")) "")
976 ((string-match "^ltxpng/" src)
977 (format " alt=\"%s\""
978 (org-e-html-encode-plain-text
979 (org-find-text-property-in-string
980 'org-latex-src src))))
981 (t (format " alt=\"%s\""
982 (file-name-nondirectory src)))))))
983 (cond
984 (standalone-p
985 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
986 (format "\n<div%s class=\"figure\">%s%s\n</div>"
987 id (format "\n<p>%s</p>" img)
988 (when caption (format "\n<p>%s</p>" caption)))))
989 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
991 ;;;; Bibliography
993 (defun org-e-html-bibliography ()
994 "Find bibliography, cut it out and return it."
995 (catch 'exit
996 (let (beg end (cnt 1) bib)
997 (save-excursion
998 (goto-char (point-min))
999 (when (re-search-forward
1000 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1001 (setq beg (match-beginning 0))
1002 (while (re-search-forward "</?div\\>" nil t)
1003 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1004 (when (= cnt 0)
1005 (and (looking-at ">") (forward-char 1))
1006 (setq bib (buffer-substring beg (point)))
1007 (delete-region beg (point))
1008 (throw 'exit bib))))
1009 nil))))
1011 ;;;; Table
1013 (defun org-e-html-splice-attributes (tag attributes)
1014 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1015 (if (not attributes)
1017 (let (oldatt newatt)
1018 (setq oldatt (org-extract-attributes-from-string tag)
1019 tag (pop oldatt)
1020 newatt (cdr (org-extract-attributes-from-string attributes)))
1021 (while newatt
1022 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1023 (if (string-match ">" tag)
1024 (setq tag
1025 (replace-match (concat (org-attributes-to-string oldatt) ">")
1026 t t tag)))
1027 tag)))
1029 (defun org-export-splice-style (style extra)
1030 "Splice EXTRA into STYLE, just before \"</style>\"."
1031 (if (and (stringp extra)
1032 (string-match "\\S-" extra)
1033 (string-match "</style>" style))
1034 (concat (substring style 0 (match-beginning 0))
1035 "\n" extra "\n"
1036 (substring style (match-beginning 0)))
1037 style))
1039 (defun org-export-e-htmlize-region-for-paste (beg end)
1040 "Convert the region to HTML, using htmlize.el.
1041 This is much like `htmlize-region-for-paste', only that it uses
1042 the settings define in the org-... variables."
1043 (let* ((htmlize-output-type org-export-e-htmlize-output-type)
1044 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
1045 (htmlbuf (htmlize-region beg end)))
1046 (unwind-protect
1047 (with-current-buffer htmlbuf
1048 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1049 (plist-get htmlize-buffer-places 'content-end)))
1050 (kill-buffer htmlbuf))))
1052 ;;;###autoload
1053 (defun org-export-e-htmlize-generate-css ()
1054 "Create the CSS for all font definitions in the current Emacs session.
1055 Use this to create face definitions in your CSS style file that can then
1056 be used by code snippets transformed by htmlize.
1057 This command just produces a buffer that contains class definitions for all
1058 faces used in the current Emacs session. You can copy and paste the ones you
1059 need into your CSS file.
1061 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1062 the function `org-export-e-htmlize-region-for-paste' will produce code
1063 that uses these same face definitions."
1064 (interactive)
1065 (require 'htmlize)
1066 (and (get-buffer "*html*") (kill-buffer "*html*"))
1067 (with-temp-buffer
1068 (let ((fl (face-list))
1069 (htmlize-css-name-prefix "org-")
1070 (htmlize-output-type 'css)
1071 f i)
1072 (while (setq f (pop fl)
1073 i (and f (face-attribute f :inherit)))
1074 (when (and (symbolp f) (or (not i) (not (listp i))))
1075 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1076 (htmlize-region (point-min) (point-max))))
1077 (org-pop-to-buffer-same-window "*html*")
1078 (goto-char (point-min))
1079 (if (re-search-forward "<style" nil t)
1080 (delete-region (point-min) (match-beginning 0)))
1081 (if (re-search-forward "</style>" nil t)
1082 (delete-region (1+ (match-end 0)) (point-max)))
1083 (beginning-of-line 1)
1084 (if (looking-at " +") (replace-match ""))
1085 (goto-char (point-min)))
1087 (defun org-e-html-make-string (n string)
1088 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1090 (defun org-e-html-toc-text (toc-entries)
1091 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1092 (start-level prev-level))
1093 (concat
1094 (mapconcat
1095 (lambda (entry)
1096 (let ((headline (nth 0 entry))
1097 (level (nth 1 entry)))
1098 (concat
1099 (let* ((cnt (- level prev-level))
1100 (times (if (> cnt 0) (1- cnt) (- cnt)))
1101 rtn)
1102 (setq prev-level level)
1103 (concat
1104 (org-e-html-make-string
1105 times (cond ((> cnt 0) "\n<ul>\n<li>")
1106 ((< cnt 0) "</li>\n</ul>\n")))
1107 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1108 headline)))
1109 toc-entries "")
1110 (org-e-html-make-string
1111 (- prev-level start-level) "</li>\n</ul>\n"))))
1113 (defun* org-e-html-format-toc-headline
1114 (todo todo-type priority text tags
1115 &key level section-number headline-label &allow-other-keys)
1116 (let ((headline (concat
1117 section-number (and section-number ". ")
1118 text
1119 (and tags "&nbsp;&nbsp;&nbsp;") (org-e-html--tags tags))))
1120 (format "<a href=\"#%s\">%s</a>"
1121 (org-export-solidify-link-text headline-label)
1122 (if (not nil) headline
1123 (format "<span class=\"%s\">%s</span>" todo-type headline)))))
1125 (defun org-e-html-toc (depth info)
1126 (let* ((headlines (org-export-collect-headlines info depth))
1127 (toc-entries
1128 (loop for headline in headlines collect
1129 (list (org-e-html-format-headline--wrap
1130 headline info 'org-e-html-format-toc-headline)
1131 (org-export-get-relative-level headline info)))))
1132 (when toc-entries
1133 (concat
1134 "<div id=\"table-of-contents\">\n"
1135 (format "<h%d>%s</h%d>\n"
1136 org-e-html-toplevel-hlevel
1137 (org-e-html--translate "Table of Contents" info)
1138 org-e-html-toplevel-hlevel)
1139 "<div id=\"text-table-of-contents\">"
1140 (org-e-html-toc-text toc-entries)
1141 "</div>\n"
1142 "</div>\n"))))
1144 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1145 "Turn todo keyword into a valid class name.
1146 Replaces invalid characters with \"_\"."
1147 (save-match-data
1148 (while (string-match "[^a-zA-Z0-9_]" kwd)
1149 (setq kwd (replace-match "_" t t kwd))))
1150 kwd)
1152 (defun org-e-html-format-footnote-reference (n def refcnt)
1153 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1154 (format org-e-html-footnote-format
1155 (let* ((id (format "fnr.%s%s" n extra))
1156 (href (format " href=\"#fn.%s\"" n))
1157 (attributes (concat " class=\"footref\"" href)))
1158 (org-e-html--anchor id n attributes)))))
1160 (defun org-e-html-format-footnotes-section (section-name definitions)
1161 (if (not definitions) ""
1162 (format org-e-html-footnotes-section section-name definitions)))
1164 (defun org-e-html-format-footnote-definition (fn)
1165 (let ((n (car fn)) (def (cdr fn)))
1166 (format
1167 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1168 (format org-e-html-footnote-format
1169 (let* ((id (format "fn.%s" n))
1170 (href (format " href=\"#fnr.%s\"" n))
1171 (attributes (concat " class=\"footnum\"" href)))
1172 (org-e-html--anchor id n attributes)))
1173 def)))
1175 (defun org-e-html-footnote-section (info)
1176 (let* ((fn-alist (org-export-collect-footnote-definitions
1177 (plist-get info :parse-tree) info))
1179 (fn-alist
1180 (loop for (n type raw) in fn-alist collect
1181 (cons n (if (eq (org-element-type raw) 'org-data)
1182 (org-trim (org-export-data raw info))
1183 (format "<p>%s</p>"
1184 (org-trim (org-export-data raw info))))))))
1185 (when fn-alist
1186 (org-e-html-format-footnotes-section
1187 (org-e-html--translate "Footnotes" info)
1188 (format
1189 "<table>\n%s\n</table>\n"
1190 (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
1192 (defun org-e-html-format-date (info)
1193 (let ((date (org-export-data (plist-get info :date) info)))
1194 (cond
1195 ((and date (string-match "%" date))
1196 (format-time-string date))
1197 (date date)
1198 (t (format-time-string "%Y-%m-%d %T %Z")))))
1200 (defun org-e-html--caption/label-string (caption label info)
1201 "Return caption and label HTML string for floats.
1203 CAPTION is a cons cell of secondary strings, the car being the
1204 standard caption and the cdr its short form. LABEL is a string
1205 representing the label. INFO is a plist holding contextual
1206 information.
1208 If there's no caption nor label, return the empty string.
1210 For non-floats, see `org-e-html--wrap-label'."
1211 (setq label nil) ;; FIXME
1213 (let ((label-str (if label (format "\\label{%s}" label) "")))
1214 (cond
1215 ((and (not caption) (not label)) "")
1216 ((not caption) (format "\\label{%s}\n" label))
1217 ;; Option caption format with short name.
1218 ((cdr caption)
1219 (format "\\caption[%s]{%s%s}\n"
1220 (org-export-data (cdr caption) info)
1221 label-str
1222 (org-export-data (car caption) info)))
1223 ;; Standard caption format.
1224 ;; (t (format "\\caption{%s%s}\n"
1225 ;; label-str
1226 ;; (org-export-data (car caption) info)))
1227 (t (org-export-data (car caption) info)))))
1229 (defun org-e-html--find-verb-separator (s)
1230 "Return a character not used in string S.
1231 This is used to choose a separator for constructs like \\verb."
1232 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1233 (loop for c across ll
1234 when (not (string-match (regexp-quote (char-to-string c)) s))
1235 return (char-to-string c))))
1237 (defun org-e-html--quotation-marks (text info)
1238 "Export quotation marks depending on language conventions.
1239 TEXT is a string containing quotation marks to be replaced. INFO
1240 is a plist used as a communication channel."
1241 (mapc (lambda(l)
1242 (let ((start 0))
1243 (while (setq start (string-match (car l) text start))
1244 (let ((new-quote (concat (match-string 1 text) (cdr l))))
1245 (setq text (replace-match new-quote t t text))))))
1246 (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
1247 ;; Falls back on English.
1248 (assoc "en" org-e-html-quotes))))
1249 text)
1251 (defun org-e-html--wrap-label (element output)
1252 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1253 This function shouldn't be used for floats. See
1254 `org-e-html--caption/label-string'."
1255 ;; (let ((label (org-element-property :name element)))
1256 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1257 ;; output
1258 ;; (concat (format "\\label{%s}\n" label) output)))
1259 output)
1263 ;;; Template
1265 (defun org-e-html-meta-info (info)
1266 (let* ((title (org-export-data (plist-get info :title) info))
1267 (author (and (plist-get info :with-author)
1268 (let ((auth (plist-get info :author)))
1269 (and auth (org-export-data auth info)))))
1270 (description (plist-get info :description))
1271 (keywords (plist-get info :keywords)))
1272 (concat
1273 (format "\n<title>%s</title>\n" title)
1274 (format
1275 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1276 (or (and org-e-html-coding-system
1277 (fboundp 'coding-system-get)
1278 (coding-system-get org-e-html-coding-system
1279 'mime-charset))
1280 "iso-8859-1"))
1281 (format "\n<meta name=\"title\" content=\"%s\"/>" title)
1282 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1283 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1284 (org-e-html-format-date info))
1285 (format "\n<meta name=\"author\" content=\"%s\"/>" author)
1286 (format "\n<meta name=\"description\" content=\"%s\"/>" description)
1287 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords))))
1289 (defun org-e-html-style (info)
1290 (concat
1291 "\n" (when (plist-get info :style-include-default) org-e-html-style-default)
1292 (plist-get info :style)
1293 (plist-get info :style-extra)
1294 "\n"
1295 (when (plist-get info :style-include-scripts)
1296 org-e-html-scripts)))
1298 (defun org-e-html-mathjax-config (info)
1299 "Insert the user setup into the matchjax template."
1300 (when (member (plist-get info :LaTeX-fragments) '(mathjax t))
1301 (let ((template org-e-html-mathjax-template)
1302 (options org-e-html-mathjax-options)
1303 (in-buffer (or (plist-get info :mathjax) ""))
1304 name val (yes " ") (no "// ") x)
1305 (mapc
1306 (lambda (e)
1307 (setq name (car e) val (nth 1 e))
1308 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1309 (setq val (car (read-from-string
1310 (substring in-buffer (match-end 0))))))
1311 (if (not (stringp val)) (setq val (format "%s" val)))
1312 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1313 (setq template (replace-match val t t template))))
1314 options)
1315 (setq val (nth 1 (assq 'mathml options)))
1316 (if (string-match (concat "\\<mathml:") in-buffer)
1317 (setq val (car (read-from-string
1318 (substring in-buffer (match-end 0))))))
1319 ;; Exchange prefixes depending on mathml setting
1320 (if (not val) (setq x yes yes no no x))
1321 ;; Replace cookies to turn on or off the config/jax lines
1322 (if (string-match ":MMLYES:" template)
1323 (setq template (replace-match yes t t template)))
1324 (if (string-match ":MMLNO:" template)
1325 (setq template (replace-match no t t template)))
1326 ;; Return the modified template
1327 template)))
1329 (defun org-e-html-preamble (info)
1330 (when (plist-get info :html-preamble)
1331 (let* ((title (org-export-data (plist-get info :title) info))
1332 (date (org-e-html-format-date info))
1333 (author (org-export-data (plist-get info :author) info))
1334 (email (plist-get info :email))
1335 (html-pre-real-contents
1336 (cond
1337 ((functionp (plist-get info :html-preamble))
1338 (with-temp-buffer
1339 (funcall (plist-get info :html-preamble))
1340 (buffer-string)))
1341 ((stringp (plist-get info :html-preamble))
1342 (format-spec (plist-get info :html-preamble)
1343 `((?t . ,title) (?a . ,author)
1344 (?d . ,date) (?e . ,email))))
1346 (format-spec
1347 (or (cadr (assoc (plist-get info :language)
1348 org-e-html-preamble-format))
1349 (cadr (assoc "en" org-e-html-preamble-format)))
1350 `((?t . ,title) (?a . ,author)
1351 (?d . ,date) (?e . ,email)))))))
1352 (when (not (equal html-pre-real-contents ""))
1353 (concat
1354 (format "
1355 <div id=\"%s\"> " (nth 0 org-e-html-divs))
1358 html-pre-real-contents
1360 </div>")))))
1362 (defun org-e-html-postamble (info)
1363 (concat
1364 (when (and (not body-only)
1365 (plist-get info :html-postamble))
1366 (let* ((html-post (plist-get info :html-postamble))
1367 (date (org-e-html-format-date info))
1368 (author (let ((author (plist-get info :author)))
1369 (and author (org-export-data author info))))
1370 (email
1371 (mapconcat (lambda(e)
1372 (format "<a href=\"mailto:%s\">%s</a>" e e))
1373 (split-string (plist-get info :email) ",+ *")
1374 ", "))
1375 (html-validation-link (or org-e-html-validation-link ""))
1376 (creator-info org-export-creator-string))
1377 (concat
1378 ;; begin postamble
1380 <div id=\"" (nth 2 org-e-html-divs) "\">"
1381 (cond
1382 ;; auto postamble
1383 ((eq (plist-get info :html-postamble) 'auto)
1384 (concat
1385 (when (plist-get info :time-stamp-file)
1386 (format "
1387 <p class=\"date\"> %s: %s </p> " (org-e-html--translate "Date" info) date))
1388 (when (and (plist-get info :with-author) author)
1389 (format "
1390 <p class=\"author\"> %s : %s</p>" (org-e-html--translate "Author" info) author))
1391 (when (and (plist-get info :with-email) email)
1392 (format "
1393 <p class=\"email\"> %s </p>" email))
1394 (when (plist-get info :with-creator)
1395 (format "
1396 <p class=\"creator\"> %s </p>" creator-info))
1397 html-validation-link "\n"))
1398 ;; postamble from a string
1399 ((stringp (plist-get info :html-postamble))
1400 (format-spec (plist-get info :html-postamble)
1401 `((?a . ,author) (?e . ,email)
1402 (?d . ,date) (?c . ,creator-info)
1403 (?v . ,html-validation-link))))
1405 ;; postamble from a function
1406 ((functionp (plist-get info :html-postamble))
1407 (with-temp-buffer
1408 (funcall (plist-get info :html-postamble))
1409 (buffer-string)))
1410 ;; default postamble
1412 (format-spec
1413 (or (cadr (assoc (plist-get info :language)
1414 org-e-html-postamble-format))
1415 (cadr (assoc "en" org-e-html-postamble-format)))
1416 `((?a . ,author) (?e . ,email)
1417 (?d . ,date) (?c . ,creator-info)
1418 (?v . ,html-validation-link)))))
1420 </div>")))
1421 ;; org-e-html-html-helper-timestamp
1424 (defun org-e-html-template (contents info)
1425 "Return complete document string after HTML conversion.
1426 CONTENTS is the transcoded contents string. RAW-DATA is the
1427 original parsed data. INFO is a plist holding export options."
1428 (concat
1429 (format
1430 (or (and (stringp org-e-html-xml-declaration)
1431 org-e-html-xml-declaration)
1432 (cdr (assoc (plist-get info :html-extension)
1433 org-e-html-xml-declaration))
1434 (cdr (assoc "html" org-e-html-xml-declaration))
1437 (or (and org-e-html-coding-system
1438 (fboundp 'coding-system-get)
1439 (coding-system-get org-e-html-coding-system
1440 'mime-charset))
1441 "iso-8859-1"))
1443 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1444 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1445 (format "
1446 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1447 (plist-get info :language) (plist-get info :language))
1449 <head>"
1450 (org-e-html-meta-info info) ; meta
1451 (org-e-html-style info) ; style
1452 (org-e-html-mathjax-config info) ; mathjax
1454 </head>"
1457 <body>"
1458 (let ((link-up (org-trim (plist-get info :link-up)))
1459 (link-home (org-trim (plist-get info :link-home))))
1460 (unless (and (string= link-up "") (string= link-up ""))
1461 (format org-e-html-home/up-format
1462 (or link-up link-home)
1463 (or link-home link-up))))
1464 ;; preamble
1465 (org-e-html-preamble info)
1466 ;; begin content
1467 (format "
1468 <div id=\"%s\">" (or org-e-html-content-div
1469 (nth 1 org-e-html-divs)))
1470 ;; document title
1471 (format "
1472 <h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info :title) info))
1473 ;; table of contents
1474 (let ((depth (plist-get info :with-toc)))
1475 (when depth (org-e-html-toc depth info)))
1476 ;; document contents
1477 contents
1478 ;; footnotes section
1479 (org-e-html-footnote-section info)
1480 ;; bibliography
1481 (org-e-html-bibliography)
1482 ;; end content
1483 (unless body-only
1485 </div>")
1487 ;; postamble
1488 (org-e-html-postamble info)
1490 (unless body-only
1492 </body>")
1494 </html>"))
1496 (defun org-e-html--translate (s info)
1497 "Transcode string S in to HTML.
1498 INFO is a plist used as a communication channel.
1500 Lookup utf-8 equivalent of S in `org-export-dictionary' and
1501 replace all non-ascii characters with its numeric reference."
1502 (let ((s (org-export-translate s :utf-8 info)))
1503 ;; Protect HTML metacharacters.
1504 (setq s (org-e-html-encode-plain-text s))
1505 ;; Replace non-ascii characters with their numeric equivalents.
1506 (replace-regexp-in-string
1507 "[[:nonascii:]]"
1508 (lambda (m) (format "&#%d;" (encode-char (string-to-char m) 'ucs)))
1509 s t t)))
1511 ;;;; Anchor
1513 (defun org-e-html--anchor (&optional id desc attributes)
1514 (let* ((name (and org-e-html-allow-name-attribute-in-anchors id))
1515 (attributes (concat (and id (format " id=\"%s\"" id))
1516 (and name (format " name=\"%s\"" name))
1517 attributes)))
1518 (format "<a%s>%s</a>" attributes (or desc ""))))
1520 ;;;; Todo
1522 (defun org-e-html--todo (todo)
1523 (when todo
1524 (format "<span class=\"%s %s%s\">%s</span>"
1525 (if (member todo org-done-keywords) "done" "todo")
1526 org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
1527 todo)))
1529 ;;;; Tags
1531 (defun org-e-html--tags (tags)
1532 (when tags
1533 (format "<span class=\"tag\">%s</span>"
1534 (mapconcat
1535 (lambda (tag)
1536 (format "<span class=\"%s\">%s</span>"
1537 (concat org-e-html-tag-class-prefix
1538 (org-e-html-fix-class-name tag))
1539 tag))
1540 tags "&nbsp;"))))
1542 ;;;; Headline
1544 (defun* org-e-html-format-headline
1545 (todo todo-type priority text tags
1546 &key level section-number headline-label &allow-other-keys)
1547 (let ((section-number
1548 (when section-number
1549 (format "<span class=\"section-number-%d\">%s</span> "
1550 level section-number)))
1551 (todo (org-e-html--todo todo))
1552 (tags (org-e-html--tags tags)))
1553 (concat section-number todo (and todo " ") text
1554 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1556 ;;;; Src Code
1558 (defun org-e-html-fontify-code (code lang)
1559 (when code
1560 (cond
1561 ;; Case 1: No lang. Possibly an example block.
1562 ((not lang)
1563 ;; Simple transcoding.
1564 (org-e-html-encode-plain-text code))
1565 ;; Case 2: No htmlize or an inferior version of htmlize
1566 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1567 ;; Emit a warning.
1568 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1569 ;; Simple transcoding.
1570 (org-e-html-encode-plain-text code))
1572 ;; Map language
1573 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1574 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1575 (cond
1576 ;; Case 1: Language is not associated with any Emacs mode
1577 ((not (functionp lang-mode))
1578 ;; Simple transcoding.
1579 (org-e-html-encode-plain-text code))
1580 ;; Case 2: Default. Fontify code.
1582 ;; htmlize
1583 (setq code (with-temp-buffer
1584 (insert code)
1585 ;; Switch to language-specific mode.
1586 (funcall lang-mode)
1587 ;; Fontify buffer.
1588 (font-lock-fontify-buffer)
1589 ;; Remove formatting on newline characters.
1590 (save-excursion
1591 (let ((beg (point-min))
1592 (end (point-max)))
1593 (goto-char beg)
1594 (while (progn (end-of-line) (< (point) end))
1595 (put-text-property (point) (1+ (point)) 'face nil)
1596 (forward-char 1))))
1597 (org-src-mode)
1598 (set-buffer-modified-p nil)
1599 ;; Htmlize region.
1600 (org-export-e-htmlize-region-for-paste
1601 (point-min) (point-max))))
1602 ;; Strip any encolosing <pre></pre> tags.
1603 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1604 (match-string 1 code)
1605 code))))))))
1607 (defun org-e-html-do-format-code
1608 (code &optional lang refs retain-labels num-start textarea-p)
1609 (when textarea-p
1610 (setq num-start nil refs nil lang nil))
1611 (let* ((code-lines (org-split-string code "\n"))
1612 (code-length (length code-lines))
1613 (num-fmt
1614 (and num-start
1615 (format "%%%ds: "
1616 (length (number-to-string (+ code-length num-start))))))
1617 (code (org-e-html-fontify-code code lang)))
1618 (assert (= code-length (length (org-split-string code "\n"))))
1619 (org-export-format-code
1620 code
1621 (lambda (loc line-num ref)
1622 (setq loc
1623 (concat
1624 ;; Add line number, if needed.
1625 (when num-start
1626 (format "<span class=\"linenr\">%s</span>"
1627 (format num-fmt line-num)))
1628 ;; Transcoded src line.
1630 ;; Add label, if needed.
1631 (when (and ref retain-labels) (format " (%s)" ref))))
1632 ;; Mark transcoded line as an anchor, if needed.
1633 (if (not ref) loc
1634 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1635 ref loc)))
1636 num-start refs)))
1638 (defun org-e-html-format-code (element info)
1639 (let* ((lang (org-element-property :language element))
1640 ;; (switches (org-element-property :switches element))
1641 (switches nil) ; FIXME
1642 (textarea-p (and switches (string-match "-t\\>" switches)))
1643 ;; Extract code and references.
1644 (code-info (org-export-unravel-code element))
1645 (code (car code-info))
1646 (refs (cdr code-info))
1647 ;; Does the src block contain labels?
1648 (retain-labels (org-element-property :retain-labels element))
1649 ;; Does it have line numbers?
1650 (num-start (case (org-element-property :number-lines element)
1651 (continued (org-export-get-loc element info))
1652 (new 0))))
1653 (org-e-html-do-format-code
1654 code lang refs retain-labels num-start textarea-p)))
1658 ;;; Transcode Functions
1660 ;;;; Bold
1662 (defun org-e-html-bold (bold contents info)
1663 "Transcode BOLD from Org to HTML.
1664 CONTENTS is the text with bold markup. INFO is a plist holding
1665 contextual information."
1666 (format (or (cdr (assq 'bold org-e-html-text-markup-alist)) "%s")
1667 contents))
1670 ;;;; Center Block
1672 (defun org-e-html-center-block (center-block contents info)
1673 "Transcode a CENTER-BLOCK element from Org to HTML.
1674 CONTENTS holds the contents of the block. INFO is a plist
1675 holding contextual information."
1676 (org-e-html--wrap-label
1677 center-block
1678 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
1681 ;;;; Clock
1683 (defun org-e-html-clock (clock contents info)
1684 "Transcode a CLOCK element from Org to HTML.
1685 CONTENTS is nil. INFO is a plist used as a communication
1686 channel."
1687 (format "<p>
1688 <span class=\"timestamp-wrapper\">
1689 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1690 </span>
1691 </p>"
1692 org-clock-string
1693 (org-translate-time (org-element-property :value clock))
1694 (let ((time (org-element-property :time clock)))
1695 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1698 ;;;; Code
1700 (defun org-e-html-code (code contents info)
1701 "Transcode CODE from Org to HTML.
1702 CONTENTS is nil. INFO is a plist holding contextual
1703 information."
1704 (format (or (cdr (assq 'code org-e-html-text-markup-alist)) "%s")
1705 (org-element-property :value code)))
1708 ;;;; Comment
1710 ;; Comments are ignored.
1713 ;;;; Comment Block
1715 ;; Comment Blocks are ignored.
1718 ;;;; Drawer
1720 (defun org-e-html-drawer (drawer contents info)
1721 "Transcode a DRAWER element from Org to HTML.
1722 CONTENTS holds the contents of the block. INFO is a plist
1723 holding contextual information."
1724 (let* ((name (org-element-property :drawer-name drawer))
1725 (output (if (functionp org-e-html-format-drawer-function)
1726 (funcall org-e-html-format-drawer-function
1727 name contents)
1728 ;; If there's no user defined function: simply
1729 ;; display contents of the drawer.
1730 contents)))
1731 (org-e-html--wrap-label drawer output)))
1734 ;;;; Dynamic Block
1736 (defun org-e-html-dynamic-block (dynamic-block contents info)
1737 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1738 CONTENTS holds the contents of the block. INFO is a plist
1739 holding contextual information. See `org-export-data'."
1740 (org-e-html--wrap-label dynamic-block contents))
1743 ;;;; Entity
1745 (defun org-e-html-entity (entity contents info)
1746 "Transcode an ENTITY object from Org to HTML.
1747 CONTENTS are the definition itself. INFO is a plist holding
1748 contextual information."
1749 (org-element-property :html entity))
1752 ;;;; Example Block
1754 (defun org-e-html-example-block (example-block contents info)
1755 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1756 CONTENTS is nil. INFO is a plist holding contextual information."
1757 (let* ((options (or (org-element-property :options example-block) ""))
1758 (lang (org-element-property :language example-block))
1759 (caption (org-element-property :caption example-block))
1760 (label (org-element-property :name example-block))
1761 (caption-str (org-e-html--caption/label-string caption label info))
1762 (attr (mapconcat #'identity
1763 (org-element-property :attr_html example-block)
1764 " "))
1765 ;; (switches (org-element-property :switches example-block))
1766 (switches nil) ; FIXME
1767 (textarea-p (and switches (string-match "-t\\>" switches)))
1768 (code (org-e-html-format-code example-block info)))
1769 (cond
1770 (textarea-p
1771 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
1772 80 (string-to-number (match-string 1 switches))))
1773 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
1774 (string-to-number (match-string 1 switches))
1775 (org-count-lines code))))
1776 (format
1777 "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
1778 cols rows code)))
1779 (t (format "<pre class=\"example\">\n%s</pre>" code)))))
1782 ;;;; Export Snippet
1784 (defun org-e-html-export-snippet (export-snippet contents info)
1785 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1786 CONTENTS is nil. INFO is a plist holding contextual information."
1787 (when (eq (org-export-snippet-backend export-snippet) 'e-html)
1788 (org-element-property :value export-snippet)))
1791 ;;;; Export Block
1793 (defun org-e-html-export-block (export-block contents info)
1794 "Transcode a EXPORT-BLOCK element from Org to HTML.
1795 CONTENTS is nil. INFO is a plist holding contextual information."
1796 (when (string= (org-element-property :type export-block) "HTML")
1797 (org-remove-indentation (org-element-property :value export-block))))
1800 ;;;; Fixed Width
1802 (defun org-e-html-fixed-width (fixed-width contents info)
1803 "Transcode a FIXED-WIDTH element from Org to HTML.
1804 CONTENTS is nil. INFO is a plist holding contextual information."
1805 (org-e-html--wrap-label
1806 fixed-width
1807 (format "<pre class=\"example\">\n%s</pre>"
1808 (org-e-html-do-format-code
1809 (org-remove-indentation
1810 (org-element-property :value fixed-width))))))
1813 ;;;; Footnote Definition
1815 ;; Footnote Definitions are ignored.
1818 ;;;; Footnote Reference
1820 (defun org-e-html-footnote-reference (footnote-reference contents info)
1821 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1822 CONTENTS is nil. INFO is a plist holding contextual information."
1823 (concat
1824 ;; Insert separator between two footnotes in a row.
1825 (let ((prev (org-export-get-previous-element footnote-reference info)))
1826 (when (eq (org-element-type prev) 'footnote-reference)
1827 org-e-html-footnote-separator))
1828 (cond
1829 ((not (org-export-footnote-first-reference-p footnote-reference info))
1830 (org-e-html-format-footnote-reference
1831 (org-export-get-footnote-number footnote-reference info)
1832 "IGNORED" 100))
1833 ;; Inline definitions are secondary strings.
1834 ((eq (org-element-property :type footnote-reference) 'inline)
1835 (org-e-html-format-footnote-reference
1836 (org-export-get-footnote-number footnote-reference info)
1837 "IGNORED" 1))
1838 ;; Non-inline footnotes definitions are full Org data.
1839 (t (org-e-html-format-footnote-reference
1840 (org-export-get-footnote-number footnote-reference info)
1841 "IGNORED" 1)))))
1844 ;;;; Headline
1846 (defun org-e-html-format-headline--wrap (headline info
1847 &optional format-function
1848 &rest extra-keys)
1849 "Transcode an HEADLINE element from Org to HTML.
1850 CONTENTS holds the contents of the headline. INFO is a plist
1851 holding contextual information."
1852 (let* ((level (+ (org-export-get-relative-level headline info)
1853 (1- org-e-html-toplevel-hlevel)))
1854 (headline-number (org-export-get-headline-number headline info))
1855 (section-number (and (org-export-numbered-headline-p headline info)
1856 (mapconcat 'number-to-string
1857 headline-number ".")))
1858 (todo (and (plist-get info :with-todo-keywords)
1859 (let ((todo (org-element-property :todo-keyword headline)))
1860 (and todo (org-export-data todo info)))))
1861 (todo-type (and todo (org-element-property :todo-type headline)))
1862 (priority (and (plist-get info :with-priority)
1863 (org-element-property :priority headline)))
1864 (text (org-export-data (org-element-property :title headline) info))
1865 (tags (and (plist-get info :with-tags)
1866 (org-export-get-tags headline info)))
1867 (headline-label (or (org-element-property :custom-id headline)
1868 (concat "sec-" (mapconcat 'number-to-string
1869 headline-number "-"))))
1870 (format-function (cond
1871 ((functionp format-function) format-function)
1872 ((functionp org-e-html-format-headline-function)
1873 (function*
1874 (lambda (todo todo-type priority text tags
1875 &allow-other-keys)
1876 (funcall org-e-html-format-headline-function
1877 todo todo-type priority text tags))))
1878 (t 'org-e-html-format-headline))))
1879 (apply format-function
1880 todo todo-type priority text tags
1881 :headline-label headline-label :level level
1882 :section-number section-number extra-keys)))
1884 (defun org-e-html-headline (headline contents info)
1885 "Transcode an HEADLINE element from Org to HTML.
1886 CONTENTS holds the contents of the headline. INFO is a plist
1887 holding contextual information."
1888 ;; Empty contents?
1889 (setq contents (or contents ""))
1890 (let* ((numberedp (org-export-numbered-headline-p headline info))
1891 (level (org-export-get-relative-level headline info))
1892 (text (org-export-data (org-element-property :title headline) info))
1893 (todo (and (plist-get info :with-todo-keywords)
1894 (let ((todo (org-element-property :todo-keyword headline)))
1895 (and todo (org-export-data todo info)))))
1896 (todo-type (and todo (org-element-property :todo-type headline)))
1897 (tags (and (plist-get info :with-tags)
1898 (org-export-get-tags headline info)))
1899 (priority (and (plist-get info :with-priority)
1900 (org-element-property :priority headline)))
1901 (section-number (and (org-export-numbered-headline-p headline info)
1902 (mapconcat 'number-to-string
1903 (org-export-get-headline-number
1904 headline info) ".")))
1905 ;; Create the headline text.
1906 (full-text (org-e-html-format-headline--wrap headline info)))
1907 (cond
1908 ;; Case 1: This is a footnote section: ignore it.
1909 ((org-element-property :footnote-section-p headline) nil)
1910 ;; Case 2. This is a deep sub-tree: export it as a list item.
1911 ;; Also export as items headlines for which no section
1912 ;; format has been found.
1913 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
1914 ;; Build the real contents of the sub-tree.
1915 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
1916 (itemized-body (org-e-html-format-list-item
1917 contents type nil nil full-text)))
1918 (concat
1919 (and (org-export-first-sibling-p headline info)
1920 (org-e-html-begin-plain-list type))
1921 itemized-body
1922 (and (org-export-last-sibling-p headline info)
1923 (org-e-html-end-plain-list type)))))
1924 ;; Case 3. Standard headline. Export it as a section.
1926 (let* ((section-number (mapconcat 'number-to-string
1927 (org-export-get-headline-number
1928 headline info) "-"))
1929 (ids (remove 'nil
1930 (list (org-element-property :custom-id headline)
1931 (concat "sec-" section-number)
1932 (org-element-property :id headline))))
1933 (preferred-id (car ids))
1934 (extra-ids (cdr ids))
1935 (extra-class (org-element-property :html-container-class headline))
1936 (level1 (+ level (1- org-e-html-toplevel-hlevel))))
1937 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
1938 (format "outline-container-%s"
1939 (or (org-element-property :custom-id headline)
1940 section-number))
1941 (concat (format "outline-%d" level1) (and extra-class " ")
1942 extra-class)
1943 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
1944 level1
1945 preferred-id
1946 (mapconcat
1947 (lambda (x)
1948 (let ((id (org-export-solidify-link-text
1949 (if (org-uuidgen-p x) (concat "ID-" x)
1950 x))))
1951 (org-e-html--anchor id)))
1952 extra-ids "")
1953 full-text
1954 level1)
1955 contents))))))
1958 ;;;; Horizontal Rule
1960 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
1961 "Transcode an HORIZONTAL-RULE object from Org to HTML.
1962 CONTENTS is nil. INFO is a plist holding contextual information."
1963 (let ((attr (mapconcat #'identity
1964 (org-element-property :attr_html horizontal-rule)
1965 " ")))
1966 (org-e-html--wrap-label horizontal-rule "<hr/>")))
1969 ;;;; Inline Babel Call
1971 ;; Inline Babel Calls are ignored.
1974 ;;;; Inline Src Block
1976 (defun org-e-html-inline-src-block (inline-src-block contents info)
1977 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
1978 CONTENTS holds the contents of the item. INFO is a plist holding
1979 contextual information."
1980 (let* ((org-lang (org-element-property :language inline-src-block))
1981 (code (org-element-property :value inline-src-block))
1982 (separator (org-e-html--find-verb-separator code)))
1983 (error "FIXME")))
1986 ;;;; Inlinetask
1988 (defun org-e-html-format-section (text class &optional id)
1989 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
1990 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
1992 (defun org-e-html-inlinetask (inlinetask contents info)
1993 "Transcode an INLINETASK element from Org to HTML.
1994 CONTENTS holds the contents of the block. INFO is a plist
1995 holding contextual information."
1996 (cond
1997 ;; If `org-e-html-format-inlinetask-function' is provided, call it
1998 ;; with appropriate arguments.
1999 ((functionp org-e-html-format-inlinetask-function)
2000 (let ((format-function
2001 (function*
2002 (lambda (todo todo-type priority text tags
2003 &key contents &allow-other-keys)
2004 (funcall org-e-html-format-inlinetask-function
2005 todo todo-type priority text tags contents)))))
2006 (org-e-html-format-headline--wrap
2007 inlinetask info format-function :contents contents)))
2008 ;; Otherwise, use a default template.
2009 (t (org-e-html--wrap-label
2010 inlinetask
2011 (format
2012 "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2013 (org-e-html-format-headline--wrap inlinetask info)
2014 contents)))))
2017 ;;;; Italic
2019 (defun org-e-html-italic (italic contents info)
2020 "Transcode ITALIC from Org to HTML.
2021 CONTENTS is the text with italic markup. INFO is a plist holding
2022 contextual information."
2023 (format (or (cdr (assq 'italic org-e-html-text-markup-alist)) "%s") contents))
2026 ;;;; Item
2028 (defun org-e-html-checkbox (checkbox)
2029 (case checkbox (on "<code>[X]</code>")
2030 (off "<code>[&nbsp;]</code>")
2031 (trans "<code>[-]</code>")
2032 (t "")))
2034 (defun org-e-html-format-list-item (contents type checkbox
2035 &optional term-counter-id
2036 headline)
2037 (let ((checkbox (concat (org-e-html-checkbox checkbox) (and checkbox " "))))
2038 (concat
2039 (case type
2040 (ordered
2041 (let* ((counter term-counter-id)
2042 (extra (if counter (format " value=\"%s\"" counter) "")))
2043 (format "<li%s>" extra)))
2044 (unordered
2045 (let* ((id term-counter-id)
2046 (extra (if id (format " id=\"%s\"" id) "")))
2047 (concat
2048 (format "<li%s>" extra)
2049 (when headline (concat headline "<br/>")))))
2050 (descriptive
2051 (let* ((term term-counter-id))
2052 (setq term (or term "(no term)"))
2053 ;; Check-boxes in descriptive lists are associated to tag.
2054 (concat (format "<dt> %s </dt>"
2055 (concat checkbox term))
2056 "<dd>"))))
2057 (unless (eq type 'descriptive) checkbox)
2058 contents
2059 (case type
2060 (ordered "</li>")
2061 (unordered "</li>")
2062 (descriptive "</dd>")))))
2064 (defun org-e-html-item (item contents info)
2065 "Transcode an ITEM element from Org to HTML.
2066 CONTENTS holds the contents of the item. INFO is a plist holding
2067 contextual information."
2068 (let* ((plain-list (org-export-get-parent item))
2069 (type (org-element-property :type plain-list))
2070 (counter (org-element-property :counter item))
2071 (checkbox (org-element-property :checkbox item))
2072 (tag (let ((tag (org-element-property :tag item)))
2073 (and tag (org-export-data tag info)))))
2074 (org-e-html-format-list-item
2075 contents type checkbox (or tag counter))))
2078 ;;;; Keyword
2080 (defun org-e-html-keyword (keyword contents info)
2081 "Transcode a KEYWORD element from Org to HTML.
2082 CONTENTS is nil. INFO is a plist holding contextual information."
2083 (let ((key (org-element-property :key keyword))
2084 (value (org-element-property :value keyword)))
2085 (cond
2086 ((string= key "HTML") value)
2087 ((string= key "INDEX") (format "\\index{%s}" value))
2088 ;; Invisible targets.
2089 ((string= key "TARGET") nil)
2090 ((string= key "TOC")
2091 (let ((value (downcase value)))
2092 (cond
2093 ((string-match "\\<headlines\\>" value)
2094 (let ((depth (or (and (string-match "[0-9]+" value)
2095 (string-to-number (match-string 0 value)))
2096 (plist-get info :with-toc))))
2097 (org-e-html-toc depth info)))
2098 ((string= "tables" value) "\\listoftables")
2099 ((string= "figures" value) "\\listoffigures")
2100 ((string= "listings" value)
2101 (cond
2102 ;; At the moment, src blocks with a caption are wrapped
2103 ;; into a figure environment.
2104 (t "\\listoffigures")))))))))
2107 ;;;; Latex Environment
2109 (defun org-e-html-format-latex (latex-frag processing-type)
2110 (let* ((cache-relpath
2111 (concat "ltxpng/" (file-name-sans-extension
2112 (file-name-nondirectory (buffer-file-name)))))
2113 (cache-dir (file-name-directory (buffer-file-name )))
2114 (display-msg "Creating LaTeX Image..."))
2116 (with-temp-buffer
2117 (insert latex-frag)
2118 (org-format-latex cache-relpath cache-dir nil display-msg
2119 nil nil processing-type)
2120 (buffer-string))))
2122 (defun org-e-html-latex-environment (latex-environment contents info)
2123 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2124 CONTENTS is nil. INFO is a plist holding contextual information."
2125 (org-e-html--wrap-label
2126 latex-environment
2127 (let ((processing-type (plist-get info :LaTeX-fragments))
2128 (latex-frag (org-remove-indentation
2129 (org-element-property :value latex-environment)))
2130 (caption (org-e-html--caption/label-string
2131 (org-element-property :caption latex-environment)
2132 (org-element-property :name latex-environment)
2133 info))
2134 (attr nil) ; FIXME
2135 (label (org-element-property :name latex-environment)))
2136 (cond
2137 ((memq processing-type '(t mathjax))
2138 (org-e-html-format-latex latex-frag 'mathjax))
2139 ((eq processing-type 'dvipng)
2140 (let* ((formula-link (org-e-html-format-latex
2141 latex-frag processing-type)))
2142 (when (and formula-link
2143 (string-match "file:\\([^]]*\\)" formula-link))
2144 (org-e-html-format-inline-image
2145 (match-string 1 formula-link) caption label attr t))))
2146 (t latex-frag)))))
2149 ;;;; Latex Fragment
2151 (defun org-e-html-latex-fragment (latex-fragment contents info)
2152 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2153 CONTENTS is nil. INFO is a plist holding contextual information."
2154 (let ((latex-frag (org-element-property :value latex-fragment))
2155 (processing-type (plist-get info :LaTeX-fragments)))
2156 (case processing-type
2157 ((t mathjax)
2158 (org-e-html-format-latex latex-frag 'mathjax))
2159 (dvipng
2160 (let* ((formula-link (org-e-html-format-latex
2161 latex-frag processing-type)))
2162 (when (and formula-link
2163 (string-match "file:\\([^]]*\\)" formula-link))
2164 (org-e-html-format-inline-image
2165 (match-string 1 formula-link)))))
2166 (t latex-frag))))
2168 ;;;; Line Break
2170 (defun org-e-html-line-break (line-break contents info)
2171 "Transcode a LINE-BREAK object from Org to HTML.
2172 CONTENTS is nil. INFO is a plist holding contextual information."
2173 "<br/>")
2176 ;;;; Link
2178 (defun org-e-html-link--inline-image (link desc info)
2179 "Return HTML code for an inline image.
2180 LINK is the link pointing to the inline image. INFO is a plist
2181 used as a communication channel."
2182 (let* ((type (org-element-property :type link))
2183 (raw-path (org-element-property :path link))
2184 (path (cond ((member type '("http" "https"))
2185 (concat type ":" raw-path))
2186 ((file-name-absolute-p raw-path)
2187 (expand-file-name raw-path))
2188 (t raw-path)))
2189 (parent (org-export-get-parent-element link))
2190 (caption (org-e-html--caption/label-string
2191 (org-element-property :caption parent)
2192 (org-element-property :name parent)
2193 info))
2194 (label (org-element-property :name parent))
2195 ;; Retrieve latex attributes from the element around.
2196 (attr (let ((raw-attr
2197 (mapconcat #'identity
2198 (org-element-property :attr_html parent)
2199 " ")))
2200 (unless (string= raw-attr "") raw-attr))))
2201 ;; Now clear ATTR from any special keyword and set a default
2202 ;; value if nothing is left.
2203 (setq attr (if (not attr) "" (org-trim attr)))
2204 ;; Return proper string, depending on DISPOSITION.
2205 (org-e-html-format-inline-image
2206 path caption label attr (org-e-html-standalone-image-p link info))))
2208 (defvar org-e-html-standalone-image-predicate)
2209 (defun org-e-html-standalone-image-p (element info &optional predicate)
2210 "Test if ELEMENT is a standalone image for the purpose HTML export.
2211 INFO is a plist holding contextual information.
2213 Return non-nil, if ELEMENT is of type paragraph and it's sole
2214 content, save for whitespaces, is a link that qualifies as an
2215 inline image.
2217 Return non-nil, if ELEMENT is of type link and it's containing
2218 paragraph has no other content save for leading and trailing
2219 whitespaces.
2221 Return nil, otherwise.
2223 Bind `org-e-html-standalone-image-predicate' to constrain
2224 paragraph further. For example, to check for only captioned
2225 standalone images, do the following.
2227 \(setq org-e-html-standalone-image-predicate
2228 \(lambda \(paragraph\)
2229 \(org-element-property :caption paragraph\)\)\)
2231 (let ((paragraph (case (org-element-type element)
2232 (paragraph element)
2233 (link (and (org-export-inline-image-p
2234 element org-e-html-inline-image-rules)
2235 (org-export-get-parent element)))
2236 (t nil))))
2237 (when paragraph
2238 (assert (eq (org-element-type paragraph) 'paragraph))
2239 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
2240 (functionp org-e-html-standalone-image-predicate)))
2241 (funcall org-e-html-standalone-image-predicate paragraph))
2242 (let ((contents (org-element-contents paragraph)))
2243 (loop for x in contents
2244 with inline-image-count = 0
2245 always (cond
2246 ((eq (org-element-type x) 'plain-text)
2247 (not (org-string-nw-p x)))
2248 ((eq (org-element-type x) 'link)
2249 (when (org-export-inline-image-p
2250 x org-e-html-inline-image-rules)
2251 (= (incf inline-image-count) 1)))
2252 (t nil))))))))
2254 (defun org-e-html-link (link desc info)
2255 "Transcode a LINK object from Org to HTML.
2257 DESC is the description part of the link, or the empty string.
2258 INFO is a plist holding contextual information. See
2259 `org-export-data'."
2260 (let* ((--link-org-files-as-html-maybe
2261 (function
2262 (lambda (raw-path info)
2263 "Treat links to `file.org' as links to `file.html', if needed.
2264 See `org-e-html-link-org-files-as-html'."
2265 (cond
2266 ((and org-e-html-link-org-files-as-html
2267 (string= ".org"
2268 (downcase (file-name-extension raw-path "."))))
2269 (concat (file-name-sans-extension raw-path) "."
2270 (plist-get info :html-extension)))
2271 (t raw-path)))))
2272 (type (org-element-property :type link))
2273 (raw-path (org-element-property :path link))
2274 ;; Ensure DESC really exists, or set it to nil.
2275 (desc (and (not (string= desc "")) desc))
2276 (path (cond
2277 ((member type '("http" "https" "ftp" "mailto"))
2278 (concat type ":" raw-path))
2279 ((string= type "file")
2280 ;; Extract just the file path and strip all other
2281 ;; components.
2282 (when (string-match "\\(.+\\)::.+" raw-path)
2283 (setq raw-path (match-string 1 raw-path)))
2284 ;; Treat links to ".org" files as ".html", if needed.
2285 (setq raw-path (funcall --link-org-files-as-html-maybe
2286 raw-path info))
2287 ;; If file path is absolute, prepend it with protocol
2288 ;; component - "file://".
2289 (if (not (file-name-absolute-p raw-path)) raw-path
2290 (concat "file://" (expand-file-name raw-path))))
2291 (t raw-path)))
2292 ;; Extract attributes from parent's paragraph.
2293 (attributes
2294 (let ((attr (mapconcat
2295 'identity
2296 (org-element-property
2297 :attr_html (org-export-get-parent-element link))
2298 " ")))
2299 (if attr (concat " " attr) "")))
2300 protocol)
2301 (cond
2302 ;; Image file.
2303 ((and (or (eq t org-e-html-inline-images)
2304 (and org-e-html-inline-images (not desc)))
2305 (org-export-inline-image-p link org-e-html-inline-image-rules))
2306 (org-e-html-link--inline-image link desc info))
2307 ;; Radio target: Transcode target's contents and use them as
2308 ;; link's description.
2309 ((string= type "radio")
2310 (let ((destination (org-export-resolve-radio-link link info)))
2311 (when destination
2312 (format "<a href=\"#%s\"%s>%s</a>"
2313 (org-export-solidify-link-text path)
2314 attributes
2315 (org-export-data (org-element-contents destination) info)))))
2316 ;; Links pointing to an headline: Find destination and build
2317 ;; appropriate referencing command.
2318 ((member type '("custom-id" "fuzzy" "id"))
2319 (let ((destination (if (string= type "fuzzy")
2320 (org-export-resolve-fuzzy-link link info)
2321 (org-export-resolve-id-link link info))))
2322 (case (org-element-type destination)
2323 ;; ID link points to an external file.
2324 (plain-text
2325 (assert (org-uuidgen-p path))
2326 (let ((fragment (concat "ID-" path))
2327 ;; Treat links to ".org" files as ".html", if needed.
2328 (path (funcall --link-org-files-as-html-maybe
2329 destination info)))
2330 (format "<a href=\"%s#%s\"%s>%s</a>"
2331 path fragment attributes (or desc destination))))
2332 ;; Fuzzy link points nowhere.
2333 ((nil)
2334 (format "<i>%s</i>"
2335 (or desc
2336 (org-export-data
2337 (org-element-property :raw-link link) info))))
2338 ;; Fuzzy link points to an invisible target.
2339 (keyword nil)
2340 ;; Link points to an headline.
2341 (headline
2342 (let ((href
2343 ;; What href to use?
2344 (cond
2345 ;; Case 1: Headline is linked via it's CUSTOM_ID
2346 ;; property. Use CUSTOM_ID.
2347 ((string= type "custom-id")
2348 (org-element-property :custom-id destination))
2349 ;; Case 2: Headline is linked via it's ID property
2350 ;; or through other means. Use the default href.
2351 ((member type '("id" "fuzzy"))
2352 (format "sec-%s"
2353 (mapconcat 'number-to-string
2354 (org-export-get-headline-number
2355 destination info) "-")))
2356 (t (error "Shouldn't reach here"))))
2357 ;; What description to use?
2358 (desc
2359 ;; Case 1: Headline is numbered and LINK has no
2360 ;; description or LINK's description matches
2361 ;; headline's title. Display section number.
2362 (if (and (org-export-numbered-headline-p destination info)
2363 (or (not desc)
2364 (string= desc (org-element-property
2365 :raw-value destination))))
2366 (mapconcat 'number-to-string
2367 (org-export-get-headline-number
2368 destination info) ".")
2369 ;; Case 2: Either the headline is un-numbered or
2370 ;; LINK has a custom description. Display LINK's
2371 ;; description or headline's title.
2372 (or desc (org-export-data (org-element-property
2373 :title destination) info)))))
2374 (format "<a href=\"#%s\"%s>%s</a>"
2375 (org-export-solidify-link-text href) attributes desc)))
2376 ;; Fuzzy link points to a target. Do as above.
2378 (let ((path (org-export-solidify-link-text path)) number)
2379 (unless desc
2380 (setq number (cond
2381 ((org-e-html-standalone-image-p destination info)
2382 (org-export-get-ordinal
2383 (assoc 'link (org-element-contents destination))
2384 info 'link 'org-e-html-standalone-image-p))
2385 (t (org-export-get-ordinal destination info))))
2386 (setq desc (when number
2387 (if (atom number) (number-to-string number)
2388 (mapconcat 'number-to-string number ".")))))
2389 (format "<a href=\"#%s\"%s>%s</a>"
2390 path attributes (or desc "FIXME")))))))
2391 ;; Coderef: replace link with the reference name or the
2392 ;; equivalent line number.
2393 ((string= type "coderef")
2394 (let ((fragment (concat "coderef-" path)))
2395 (format "<a href=\"#%s\" %s%s>%s</a>"
2396 fragment
2397 (format (concat "class=\"coderef\""
2398 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2399 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2400 fragment fragment)
2401 attributes
2402 (format (org-export-get-coderef-format path desc)
2403 (org-export-resolve-coderef path info)))))
2404 ;; Link type is handled by a special function.
2405 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2406 (funcall protocol (org-link-unescape path) desc 'html))
2407 ;; External link with a description part.
2408 ((and path desc) (format "<a href=\"%s\"%s>%s</a>" path attributes desc))
2409 ;; External link without a description part.
2410 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path))
2411 ;; No path, only description. Try to do something useful.
2412 (t (format "<i>%s</i>" desc)))))
2415 ;;;; Babel Call
2417 ;; Babel Calls are ignored.
2420 ;;;; Macro
2422 (defun org-e-html-macro (macro contents info)
2423 "Transcode a MACRO element from Org to HTML.
2424 CONTENTS is nil. INFO is a plist holding contextual information."
2425 ;; Use available tools.
2426 (org-export-expand-macro macro info))
2429 ;;;; Paragraph
2431 (defun org-e-html-paragraph (paragraph contents info)
2432 "Transcode a PARAGRAPH element from Org to HTML.
2433 CONTENTS is the contents of the paragraph, as a string. INFO is
2434 the plist used as a communication channel."
2435 (let* ((style nil) ; FIXME
2436 (class (cdr (assoc style '((footnote . "footnote")
2437 (verse . nil)))))
2438 (extra (if class (format " class=\"%s\"" class) ""))
2439 (parent (org-export-get-parent paragraph)))
2440 (cond
2441 ((and (eq (org-element-type parent) 'item)
2442 (= (org-element-property :begin paragraph)
2443 (org-element-property :contents-begin parent)))
2444 ;; leading paragraph in a list item have no tags
2445 contents)
2446 ((org-e-html-standalone-image-p paragraph info)
2447 ;; standalone image
2448 contents)
2449 (t (format "<p%s>\n%s</p>" extra contents)))))
2452 ;;;; Plain List
2454 (defun org-e-html-begin-plain-list (type &optional arg1)
2455 (case type
2456 (ordered
2457 (format "<ol%s>" (if arg1 ; FIXME
2458 (format " start=\"%d\"" arg1)
2459 "")))
2460 (unordered "<ul>")
2461 (descriptive "<dl>")))
2463 (defun org-e-html-end-plain-list (type)
2464 (case type
2465 (ordered "</ol>")
2466 (unordered "</ul>")
2467 (descriptive "</dl>")))
2469 (defun org-e-html-plain-list (plain-list contents info)
2470 "Transcode a PLAIN-LIST element from Org to HTML.
2471 CONTENTS is the contents of the list. INFO is a plist holding
2472 contextual information."
2473 (let* (arg1 ;; FIXME
2474 (type (org-element-property :type plain-list))
2475 (attr (mapconcat #'identity
2476 (org-element-property :attr_html plain-list)
2477 " ")))
2478 (org-e-html--wrap-label
2479 plain-list (format "%s\n%s%s"
2480 (org-e-html-begin-plain-list type)
2481 contents (org-e-html-end-plain-list type)))))
2483 ;;;; Plain Text
2485 (defun org-e-html-convert-special-strings (string)
2486 "Convert special characters in STRING to HTML."
2487 (let ((all org-e-html-special-string-regexps)
2488 e a re rpl start)
2489 (while (setq a (pop all))
2490 (setq re (car a) rpl (cdr a) start 0)
2491 (while (string-match re string start)
2492 (setq string (replace-match rpl t nil string))))
2493 string))
2495 (defun org-e-html-encode-plain-text (text)
2496 "Convert plain text characters to HTML equivalent.
2497 Possible conversions are set in `org-export-html-protect-char-alist'."
2498 (mapc
2499 (lambda (pair)
2500 (setq text (replace-regexp-in-string (car pair) (cdr pair) text t t)))
2501 org-e-html-protect-char-alist)
2502 text)
2504 (defun org-e-html-plain-text (text info)
2505 "Transcode a TEXT string from Org to HTML.
2506 TEXT is the string to transcode. INFO is a plist holding
2507 contextual information."
2508 ;; Protect following characters: <, >, &.
2509 (setq text (org-e-html-encode-plain-text text))
2510 ;; Handle quotation marks.
2511 (setq text (org-e-html--quotation-marks text info))
2512 ;; Handle special strings.
2513 (when (plist-get info :with-special-strings)
2514 (setq text (org-e-html-convert-special-strings text)))
2515 ;; Handle break preservation if required.
2516 (when (plist-get info :preserve-breaks)
2517 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2518 text)))
2519 ;; Return value.
2520 text)
2523 ;; Planning
2525 (defun org-e-html-planning (planning contents info)
2526 "Transcode a PLANNING element from Org to HTML.
2527 CONTENTS is nil. INFO is a plist used as a communication
2528 channel."
2529 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2530 (format
2531 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2532 (mapconcat
2533 'identity
2534 (delq nil
2535 (list
2536 (let ((closed (org-element-property :closed planning)))
2537 (when closed
2538 (format span-fmt org-closed-string
2539 (org-translate-time closed))))
2540 (let ((deadline (org-element-property :deadline planning)))
2541 (when deadline
2542 (format span-fmt org-deadline-string
2543 (org-translate-time deadline))))
2544 (let ((scheduled (org-element-property :scheduled planning)))
2545 (when scheduled
2546 (format span-fmt org-scheduled-string
2547 (org-translate-time scheduled))))))
2548 " "))))
2551 ;;;; Property Drawer
2553 (defun org-e-html-property-drawer (property-drawer contents info)
2554 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2555 CONTENTS is nil. INFO is a plist holding contextual
2556 information."
2557 ;; The property drawer isn't exported but we want separating blank
2558 ;; lines nonetheless.
2562 ;;;; Quote Block
2564 (defun org-e-html-quote-block (quote-block contents info)
2565 "Transcode a QUOTE-BLOCK element from Org to HTML.
2566 CONTENTS holds the contents of the block. INFO is a plist
2567 holding contextual information."
2568 (org-e-html--wrap-label
2569 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2572 ;;;; Quote Section
2574 (defun org-e-html-quote-section (quote-section contents info)
2575 "Transcode a QUOTE-SECTION element from Org to HTML.
2576 CONTENTS is nil. INFO is a plist holding contextual information."
2577 (let ((value (org-remove-indentation
2578 (org-element-property :value quote-section))))
2579 (when value (format "<pre>\n%s</pre>" value))))
2582 ;;;; Section
2584 (defun org-e-html-section (section contents info)
2585 "Transcode a SECTION element from Org to HTML.
2586 CONTENTS holds the contents of the section. INFO is a plist
2587 holding contextual information."
2588 (let ((parent (org-export-get-parent-headline section)))
2589 ;; Before first headline: no container, just return CONTENTS.
2590 (if (not parent) contents
2591 ;; Get div's class and id references.
2592 (let* ((class-num (+ (org-export-get-relative-level parent info)
2593 (1- org-e-html-toplevel-hlevel)))
2594 (section-number
2595 (mapconcat
2596 'number-to-string
2597 (org-export-get-headline-number parent info) "-")))
2598 ;; Build return value.
2599 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2600 class-num
2601 (or (org-element-property :custom-id parent) section-number)
2602 contents)))))
2604 ;;;; Radio Target
2606 (defun org-e-html-radio-target (radio-target text info)
2607 "Transcode a RADIO-TARGET object from Org to HTML.
2608 TEXT is the text of the target. INFO is a plist holding
2609 contextual information."
2610 (let ((id (org-export-solidify-link-text
2611 (org-element-property :value radio-target))))
2612 (org-e-html--anchor id text)))
2615 ;;;; Special Block
2617 (defun org-e-html-special-block (special-block contents info)
2618 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2619 CONTENTS holds the contents of the block. INFO is a plist
2620 holding contextual information."
2621 (let ((type (downcase (org-element-property :type special-block))))
2622 (org-e-html--wrap-label
2623 special-block
2624 (format "<div class=\"%s\">\n%s\n</div>" type contents))))
2627 ;;;; Src Block
2629 (defun org-e-html-src-block (src-block contents info)
2630 "Transcode a SRC-BLOCK element from Org to HTML.
2631 CONTENTS holds the contents of the item. INFO is a plist holding
2632 contextual information."
2633 (let* ((lang (org-element-property :language src-block))
2634 (caption (org-element-property :caption src-block))
2635 (label (org-element-property :name src-block))
2636 (caption-str (org-e-html--caption/label-string caption label info))
2637 (attr (mapconcat #'identity
2638 (org-element-property :attr_html src-block)
2639 " "))
2640 ;; (switches (org-element-property :switches src-block))
2641 (switches nil) ; FIXME
2642 (textarea-p (and switches (string-match "-t\\>" switches)))
2643 (code (org-e-html-format-code src-block info)))
2644 (cond
2645 (lang (format
2646 "<div class=\"org-src-container\">\n%s%s\n</div>"
2647 (if (not caption) ""
2648 (format "<label class=\"org-src-name\">%s</label>" caption-str))
2649 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code)))
2650 (textarea-p
2651 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
2652 80 (string-to-number (match-string 1 switches))))
2653 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
2654 (string-to-number (match-string 1 switches))
2655 (org-count-lines code))))
2656 (format
2657 "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
2658 cols rows code)))
2659 (t (format "<pre class=\"example\">\n%s</pre>" code)))))
2661 ;;;; Statistics Cookie
2663 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
2664 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2665 CONTENTS is nil. INFO is a plist holding contextual information."
2666 (let ((cookie-value (org-element-property :value statistics-cookie)))
2667 (format "<code>%s</code>" cookie-value)))
2670 ;;;; Strike-Through
2672 (defun org-e-html-strike-through (strike-through contents info)
2673 "Transcode STRIKE-THROUGH from Org to HTML.
2674 CONTENTS is the text with strike-through markup. INFO is a plist
2675 holding contextual information."
2676 (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist)) "%s")
2677 contents))
2680 ;;;; Subscript
2682 (defun org-e-html-subscript (subscript contents info)
2683 "Transcode a SUBSCRIPT object from Org to HTML.
2684 CONTENTS is the contents of the object. INFO is a plist holding
2685 contextual information."
2686 (format "<sub>%s</sub>" contents))
2689 ;;;; Superscript
2691 (defun org-e-html-superscript (superscript contents info)
2692 "Transcode a SUPERSCRIPT object from Org to HTML.
2693 CONTENTS is the contents of the object. INFO is a plist holding
2694 contextual information."
2695 (format "<sup>%s</sup>" contents))
2698 ;;;; Tabel Cell
2700 (defun org-e-html-table-cell (table-cell contents info)
2701 "Transcode a TABLE-CELL element from Org to HTML.
2702 CONTENTS is nil. INFO is a plist used as a communication
2703 channel."
2704 (let* ((table-row (org-export-get-parent table-cell))
2705 (table (org-export-get-parent-table table-cell))
2706 (cell-attrs
2707 (if (not org-e-html-table-align-individual-fields) ""
2708 (format (if (and (boundp 'org-e-html-format-table-no-css)
2709 org-e-html-format-table-no-css)
2710 " align=\"%s\"" " class=\"%s\"")
2711 (org-export-table-cell-alignment table-cell info)))))
2712 (when (or (not contents) (string= "" (org-trim contents)))
2713 (setq contents "&nbsp;"))
2714 (cond
2715 ((and (org-export-table-has-header-p table info)
2716 (= 1 (org-export-table-row-group table-row info)))
2717 (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
2718 contents (cdr org-e-html-table-header-tags)))
2719 ((and org-e-html-table-use-header-tags-for-first-column
2720 (zerop (cdr (org-export-table-cell-address table-cell info))))
2721 (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
2722 contents (cdr org-e-html-table-header-tags)))
2723 (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
2724 contents (cdr org-e-html-table-data-tags))))))
2727 ;;;; Table Row
2729 (defun org-e-html-table-row (table-row contents info)
2730 "Transcode a TABLE-ROW element from Org to HTML.
2731 CONTENTS is the contents of the row. INFO is a plist used as a
2732 communication channel."
2733 ;; Rules are ignored since table separators are deduced from
2734 ;; borders of the current row.
2735 (when (eq (org-element-property :type table-row) 'standard)
2736 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2737 (rowgroup-tags
2738 (cond
2739 ;; Case 1: Row belongs to second or subsequent rowgroups.
2740 ((not (= 1 (org-export-table-row-group table-row info)))
2741 '("<tbody>" . "\n</tbody>"))
2742 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2743 ((org-export-table-has-header-p
2744 (org-export-get-parent-table table-row) info)
2745 '("<thead>" . "\n</thead>"))
2746 ;; Case 2: Row is from first and only row group.
2747 (t '("<tbody>" . "\n</tbody>")))))
2748 (concat
2749 ;; Begin a rowgroup?
2750 (when (org-export-table-row-starts-rowgroup-p table-row info)
2751 (car rowgroup-tags))
2752 ;; Actual table row
2753 (concat "\n" (eval (car org-e-html-table-row-tags))
2754 contents
2755 "\n"
2756 (eval (cdr org-e-html-table-row-tags)))
2757 ;; End a rowgroup?
2758 (when (org-export-table-row-ends-rowgroup-p table-row info)
2759 (cdr rowgroup-tags))))))
2762 ;;;; Table
2764 (defun org-e-html-table-first-row-data-cells (table info)
2765 (let ((table-row
2766 (org-element-map
2767 table 'table-row
2768 (lambda (row)
2769 (unless (eq (org-element-property :type row) 'rule) row))
2770 info 'first-match))
2771 (special-column-p (org-export-table-has-special-column-p table)))
2772 (if (not special-column-p) (org-element-contents table-row)
2773 (cdr (org-element-contents table-row)))))
2775 (defun org-e-html-table--table.el-table (table info)
2776 (when (eq (org-element-property :type table) 'table.el)
2777 (require 'table)
2778 (let ((outbuf (with-current-buffer
2779 (get-buffer-create "*org-export-table*")
2780 (erase-buffer) (current-buffer))))
2781 (with-temp-buffer
2782 (insert (org-element-property :value table))
2783 (goto-char 1)
2784 (re-search-forward "^[ \t]*|[^|]" nil t)
2785 (table-generate-source 'html outbuf))
2786 (with-current-buffer outbuf
2787 (prog1 (org-trim (buffer-string))
2788 (kill-buffer) )))))
2790 (defun org-e-html-table (table contents info)
2791 "Transcode a TABLE element from Org to HTML.
2792 CONTENTS is the contents of the table. INFO is a plist holding
2793 contextual information."
2794 (case (org-element-property :type table)
2795 ;; Case 1: table.el table. Convert it using appropriate tools.
2796 (table.el (org-e-html-table--table.el-table table info))
2797 ;; Case 2: Standard table.
2799 (let* ((label (org-element-property :name table))
2800 (caption (org-e-html--caption/label-string
2801 (org-element-property :caption table) label info))
2802 (attributes (mapconcat #'identity
2803 (org-element-property :attr_html table)
2804 " "))
2805 (alignspec
2806 (if (and (boundp 'org-e-html-format-table-no-css)
2807 org-e-html-format-table-no-css)
2808 "align=\"%s\"" "class=\"%s\""))
2809 (table-column-specs
2810 (function
2811 (lambda (table info)
2812 (mapconcat
2813 (lambda (table-cell)
2814 (let ((alignment (org-export-table-cell-alignment
2815 table-cell info)))
2816 (concat
2817 ;; Begin a colgroup?
2818 (when (org-export-table-cell-starts-colgroup-p
2819 table-cell info)
2820 "\n<colgroup>")
2821 ;; Add a column. Also specify it's alignment.
2822 (format "\n<col %s/>" (format alignspec alignment))
2823 ;; End a colgroup?
2824 (when (org-export-table-cell-ends-colgroup-p
2825 table-cell info)
2826 "\n</colgroup>"))))
2827 (org-e-html-table-first-row-data-cells table info) "\n"))))
2828 (table-attributes
2829 (let ((table-tag (plist-get info :html-table-tag)))
2830 (concat
2831 (and (string-match "<table\\(.*\\)>" table-tag)
2832 (match-string 1 table-tag))
2833 (and label (format " id=\"%s\""
2834 (org-export-solidify-link-text label)))))))
2835 ;; Remove last blank line.
2836 (setq contents (substring contents 0 -1))
2837 (format "<table%s>\n%s\n%s\n%s\n</table>"
2838 table-attributes
2839 (if (not caption) "" (format "<caption>%s</caption>" caption))
2840 (funcall table-column-specs table info)
2841 contents)))))
2843 ;;;; Target
2845 (defun org-e-html-target (target contents info)
2846 "Transcode a TARGET object from Org to HTML.
2847 CONTENTS is nil. INFO is a plist holding contextual
2848 information."
2849 (let ((id (org-export-solidify-link-text
2850 (org-element-property :value target))))
2851 (org-e-html--anchor id)))
2854 ;;;; Timestamp
2856 (defun org-e-html-timestamp (timestamp contents info)
2857 "Transcode a TIMESTAMP object from Org to HTML.
2858 CONTENTS is nil. INFO is a plist holding contextual
2859 information."
2860 (let* ((f (if (eq (org-element-property :type timestamp) 'inactive) "[%s]" "<%s>"))
2861 (value (org-translate-time (format f (org-element-property :value timestamp))))
2862 (range-end (org-element-property :range-end timestamp)))
2863 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2864 (if (not range-end) value
2865 (concat value "&ndash;" (org-translate-time (format f range-end)))))))
2868 ;;;; Underline
2870 (defun org-e-html-underline (underline contents info)
2871 "Transcode UNDERLINE from Org to HTML.
2872 CONTENTS is the text with underline markup. INFO is a plist
2873 holding contextual information."
2874 (format (or (cdr (assq 'underline org-e-html-text-markup-alist)) "%s")
2875 contents))
2878 ;;;; Verbatim
2880 (defun org-e-html-verbatim (verbatim contents info)
2881 "Transcode VERBATIM from Org to HTML.
2882 CONTENTS is nil. INFO is a plist holding contextual
2883 information."
2884 (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist)) "%s")
2885 (org-element-property :value verbatim)))
2888 ;;;; Verse Block
2890 (defun org-e-html-verse-block (verse-block contents info)
2891 "Transcode a VERSE-BLOCK element from Org to HTML.
2892 CONTENTS is verse block contents. INFO is a plist holding
2893 contextual information."
2894 ;; Replace each newline character with line break. Also replace
2895 ;; each blank line with a line break.
2896 (setq contents (replace-regexp-in-string
2897 "^ *\\\\\\\\$" "<br/>\n"
2898 (replace-regexp-in-string
2899 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2900 ;; Replace each white space at beginning of a line with a
2901 ;; non-breaking space.
2902 (while (string-match "^[ \t]+" contents)
2903 (let* ((num-ws (length (match-string 0 contents)))
2904 (ws (let (out) (dotimes (i num-ws out)
2905 (setq out (concat out "&nbsp;"))))))
2906 (setq contents (replace-match ws nil t contents))))
2907 (org-e-html--wrap-label
2908 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
2913 ;;; Filter Functions
2915 (defun org-e-html-final-function (contents backend info)
2916 (if (not org-e-html-pretty-output) contents
2917 (with-temp-buffer
2918 (html-mode)
2919 (insert contents)
2920 (indent-region (point-min) (point-max))
2921 (buffer-substring-no-properties (point-min) (point-max)))))
2924 ;;; Interactive functions
2926 ;;;###autoload
2927 (defun org-e-html-export-as-html
2928 (&optional subtreep visible-only body-only ext-plist)
2929 "Export current buffer to an HTML buffer.
2931 If narrowing is active in the current buffer, only export its
2932 narrowed part.
2934 If a region is active, export that region.
2936 When optional argument SUBTREEP is non-nil, export the sub-tree
2937 at point, extracting information from the headline properties
2938 first.
2940 When optional argument VISIBLE-ONLY is non-nil, don't export
2941 contents of hidden elements.
2943 When optional argument BODY-ONLY is non-nil, only write code
2944 between \"<body>\" and \"</body>\" tags.
2946 EXT-PLIST, when provided, is a property list with external
2947 parameters overriding Org default settings, but still inferior to
2948 file-local settings.
2950 Export is done in a buffer named \"*Org E-HTML Export*\", which
2951 will be displayed when `org-export-show-temporary-export-buffer'
2952 is non-nil."
2953 (interactive)
2954 (let ((outbuf
2955 (org-export-to-buffer
2956 'e-html "*Org E-HTML Export*"
2957 subtreep visible-only body-only ext-plist)))
2958 ;; Set major mode.
2959 (with-current-buffer outbuf (nxml-mode))
2960 (when org-export-show-temporary-export-buffer
2961 (switch-to-buffer-other-window outbuf))))
2963 ;;;###autoload
2964 (defun org-e-html-export-to-html
2965 (&optional subtreep visible-only body-only ext-plist pub-dir)
2966 "Export current buffer to a HTML file.
2968 If narrowing is active in the current buffer, only export its
2969 narrowed part.
2971 If a region is active, export that region.
2973 When optional argument SUBTREEP is non-nil, export the sub-tree
2974 at point, extracting information from the headline properties
2975 first.
2977 When optional argument VISIBLE-ONLY is non-nil, don't export
2978 contents of hidden elements.
2980 When optional argument BODY-ONLY is non-nil, only write code
2981 between \"<body>\" and \"</body>\" tags.
2983 EXT-PLIST, when provided, is a property list with external
2984 parameters overriding Org default settings, but still inferior to
2985 file-local settings.
2987 When optional argument PUB-DIR is set, use it as the publishing
2988 directory.
2990 Return output file's name."
2991 (interactive)
2992 (let* ((extension (concat "." org-e-html-extension))
2993 (file (org-export-output-file-name extension subtreep pub-dir))
2994 (org-export-coding-system org-e-html-coding-system))
2995 (org-export-to-file
2996 'e-html file subtreep visible-only body-only ext-plist)))
3000 ;;; FIXME
3002 ;;;; org-format-table-html
3003 ;;;; org-format-org-table-html
3004 ;;;; org-format-table-table-html
3005 ;;;; org-table-number-fraction
3006 ;;;; org-table-number-regexp
3007 ;;;; org-e-html-table-caption-above
3009 ;;;; org-e-html-with-timestamp
3010 ;;;; org-e-html-html-helper-timestamp
3012 ;;;; org-export-as-html-and-open
3013 ;;;; org-export-as-html-batch
3014 ;;;; org-export-as-html-to-buffer
3015 ;;;; org-replace-region-by-html
3016 ;;;; org-export-region-as-html
3017 ;;;; org-export-as-html
3019 ;;;; (org-export-directory :html opt-plist)
3020 ;;;; (plist-get opt-plist :html-extension)
3021 ;;;; org-e-html-toplevel-hlevel
3022 ;;;; org-e-html-special-string-regexps
3023 ;;;; org-e-html-inline-images
3024 ;;;; org-e-html-inline-image-extensions
3025 ;;;; org-e-html-protect-char-alist
3026 ;;;; org-e-html-table-use-header-tags-for-first-column
3027 ;;;; org-e-html-todo-kwd-class-prefix
3028 ;;;; org-e-html-tag-class-prefix
3029 ;;;; org-e-html-footnote-separator
3031 ;;;; org-export-preferred-target-alist
3032 ;;;; org-export-solidify-link-text
3033 ;;;; class for anchors
3034 ;;;; org-export-with-section-numbers, body-only
3035 ;;;; org-export-mark-todo-in-toc
3037 ;;;; org-e-html-format-org-link
3038 ;;;; (caption (and caption (org-xml-encode-org-text caption)))
3039 ;;;; alt = (file-name-nondirectory path)
3041 ;;;; org-export-time-stamp-file'
3043 (provide 'org-e-html)
3044 ;;; org-e-html.el ends here