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