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