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