org-e-html/org-e-odt: Use new table infrastructure. First cut and slightly broken.
[org-mode.git] / EXPERIMENTAL / org-e-html.el
blob35f28323c0b44ced0b9f577c6ba3b5d8c88cf5df
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 'format-spec)
39 (eval-when-compile (require 'cl) (require 'table))
43 ;;; Function Declarations
45 (declare-function org-element-get-property "org-element" (property element))
46 (declare-function org-element-normalize-string "org-element" (s))
47 (declare-function org-element-parse-secondary-string
48 "org-element" (string restriction &optional buffer))
49 (defvar org-element-string-restrictions)
50 (defvar org-element-object-restrictions)
52 (declare-function org-export-clean-table "org-export" (table specialp))
53 (declare-function org-export-data "org-export" (data backend info))
54 (declare-function org-export-directory "org-export" (type plist))
55 (declare-function org-export-expand-macro "org-export" (macro info))
56 (declare-function org-export-first-sibling-p "org-export" (headline info))
57 (declare-function org-export-footnote-first-reference-p "org-export"
58 (footnote-reference info))
59 (declare-function org-export-get-coderef-format "org-export" (path desc))
60 (declare-function org-export-get-footnote-definition "org-export"
61 (footnote-reference info))
62 (declare-function org-export-get-footnote-number "org-export" (footnote info))
63 (declare-function org-export-get-previous-element "org-export" (blob info))
64 (declare-function org-export-get-relative-level "org-export" (headline info))
65 (declare-function org-export-handle-code
66 "org-export" (element info &optional num-fmt ref-fmt delayed))
67 (declare-function org-export-included-file "org-export" (keyword backend info))
68 (declare-function org-export-inline-image-p "org-export"
69 (link &optional extensions))
70 (declare-function org-export-last-sibling-p "org-export" (headline info))
71 (declare-function org-export-low-level-p "org-export" (headline info))
72 (declare-function org-export-output-file-name
73 "org-export" (extension &optional subtreep pub-dir))
74 (declare-function org-export-resolve-coderef "org-export" (ref info))
75 (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
76 (declare-function org-export-secondary-string "org-export"
77 (secondary backend info))
78 (declare-function org-export-solidify-link-text "org-export" (s))
79 (declare-function org-export-table-format-info "org-export" (table))
80 (declare-function
81 org-export-to-buffer "org-export"
82 (backend buffer &optional subtreep visible-only body-only ext-plist))
83 (declare-function
84 org-export-to-file "org-export"
85 (backend file &optional subtreep visible-only body-only ext-plist))
87 (declare-function org-id-find-id-file "org-id" (id))
88 (declare-function htmlize-region "ext:htmlize" (beg end))
89 (declare-function org-pop-to-buffer-same-window
90 "org-compat" (&optional buffer-or-name norecord label))
95 ;;; Internal Variables
97 (defconst org-e-html-option-alist
98 '((:agenda-style nil nil org-agenda-export-html-style)
99 (:convert-org-links nil nil org-e-html-link-org-files-as-html)
100 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
101 ;; (:expand-quoted-html nil "@" org-e-html-expand)
102 (:inline-images nil nil org-e-html-inline-images)
103 ;; (:link-home nil nil org-e-html-link-home) FIXME
104 ;; (:link-up nil nil org-e-html-link-up) FIXME
105 (:style nil nil org-e-html-style)
106 (:style-extra nil nil org-e-html-style-extra)
107 (:style-include-default nil nil org-e-html-style-include-default)
108 (:style-include-scripts nil nil org-e-html-style-include-scripts)
109 ;; (:timestamp nil nil org-e-html-with-timestamp)
110 (:html-extension nil nil org-e-html-extension)
111 (:html-postamble nil nil org-e-html-postamble)
112 (:html-preamble nil nil org-e-html-preamble)
113 (:html-table-tag nil nil org-e-html-table-tag)
114 (:xml-declaration nil nil org-e-html-xml-declaration)
115 (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)
116 (:mathjax "MATHJAX" nil "" space))
117 "Alist between export properties and ways to set them.
119 The car of the alist is the property name, and the cdr is a list
120 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
122 KEYWORD is a string representing a buffer keyword, or nil.
123 OPTION is a string that could be found in an #+OPTIONS: line.
124 DEFAULT is the default value for the property.
125 BEHAVIOUR determine how Org should handle multiple keywords for
126 the same property. It is a symbol among:
127 nil Keep old value and discard the new one.
128 t Replace old value with the new one.
129 `space' Concatenate the values, separating them with a space.
130 `newline' Concatenate the values, separating them with
131 a newline.
132 `split' Split values at white spaces, and cons them to the
133 previous list.
135 KEYWORD and OPTION have precedence over DEFAULT.
137 All these properties should be back-end agnostic. For back-end
138 specific properties, define a similar variable named
139 `org-BACKEND-option-alist', replacing BACKEND with the name of
140 the appropriate back-end. You can also redefine properties
141 there, as they have precedence over these.")
143 ;; FIXME: it already exists in org-e-html.el
144 (defconst org-e-html-cvt-link-fn
146 "Function to convert link URLs to exportable URLs.
147 Takes two arguments, TYPE and PATH.
148 Returns exportable url as (TYPE PATH), or nil to signal that it
149 didn't handle this case.
150 Intended to be locally bound around a call to `org-export-as-html'." )
155 (defvar org-e-html-format-table-no-css)
156 (defvar htmlize-buffer-places) ; from htmlize.el
157 (defvar body-only) ; dynamically scoped into this.
161 ;;; User Configuration Variables
163 (defgroup org-export-e-html nil
164 "Options for exporting Org mode files to HTML."
165 :tag "Org Export HTML"
166 :group 'org-export)
168 ;;;; Debugging
170 (defcustom org-e-html-pretty-output nil
171 "Enable this to generate pretty HTML."
172 :group 'org-export-e-html
173 :type 'boolean)
176 ;;;; Document
178 (defcustom org-e-html-extension "html"
179 "The extension for exported HTML files."
180 :group 'org-export-e-html
181 :type 'string)
183 (defcustom org-e-html-xml-declaration
184 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
185 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
186 "The extension for exported HTML files.
187 %s will be replaced with the charset of the exported file.
188 This may be a string, or an alist with export extensions
189 and corresponding declarations."
190 :group 'org-export-e-html
191 :type '(choice
192 (string :tag "Single declaration")
193 (repeat :tag "Dependent on extension"
194 (cons (string :tag "Extension")
195 (string :tag "Declaration")))))
197 ;; Use `org-export-coding-system' instead
198 ;; (defcustom org-e-html-coding-system nil
199 ;; "Coding system for HTML export, defaults to `buffer-file-coding-system'."
200 ;; :group 'org-export-e-html
201 ;; :type 'coding-system)
203 (defvar org-e-html-content-div "content"
204 "The name of the container DIV that holds all the page contents.
206 This variable is obsolete since Org version 7.7.
207 Please set `org-e-html-divs' instead.")
209 (defcustom org-e-html-divs '("preamble" "content" "postamble")
210 "The name of the main divs for HTML export.
211 This is a list of three strings, the first one for the preamble
212 DIV, the second one for the content DIV and the third one for the
213 postamble DIV."
214 :group 'org-export-e-html
215 :type '(list
216 (string :tag " Div for the preamble:")
217 (string :tag " Div for the content:")
218 (string :tag "Div for the postamble:")))
221 ;;;; Document Header (Styles)
223 (defconst org-e-html-style-default
224 "<style type=\"text/css\">
225 <!--/*--><![CDATA[/*><!--*/
226 html { font-family: Times, serif; font-size: 12pt; }
227 .title { text-align: center; }
228 .todo { color: red; }
229 .done { color: green; }
230 .tag { background-color: #add8e6; font-weight:normal }
231 .target { }
232 .timestamp { color: #bebebe; }
233 .timestamp-kwd { color: #5f9ea0; }
234 .right {margin-left:auto; margin-right:0px; text-align:right;}
235 .left {margin-left:0px; margin-right:auto; text-align:left;}
236 .center {margin-left:auto; margin-right:auto; text-align:center;}
237 p.verse { margin-left: 3% }
238 pre {
239 border: 1pt solid #AEBDCC;
240 background-color: #F3F5F7;
241 padding: 5pt;
242 font-family: courier, monospace;
243 font-size: 90%;
244 overflow:auto;
246 table { border-collapse: collapse; }
247 td, th { vertical-align: top; }
248 th.right { text-align:center; }
249 th.left { text-align:center; }
250 th.center { text-align:center; }
251 td.right { text-align:right; }
252 td.left { text-align:left; }
253 td.center { text-align:center; }
254 dt { font-weight: bold; }
255 div.figure { padding: 0.5em; }
256 div.figure p { text-align: center; }
257 div.inlinetask {
258 padding:10px;
259 border:2px solid gray;
260 margin:10px;
261 background: #ffffcc;
263 textarea { overflow-x: auto; }
264 .linenr { font-size:smaller }
265 .code-highlighted {background-color:#ffff00;}
266 .org-info-js_info-navigation { border-style:none; }
267 #org-info-js_console-label { font-size:10px; font-weight:bold;
268 white-space:nowrap; }
269 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
270 font-weight:bold; }
271 /*]]>*/-->
272 </style>"
273 "The default style specification for exported HTML files.
274 Please use the variables `org-e-html-style' and
275 `org-e-html-style-extra' to add to this style. If you wish to not
276 have the default style included, customize the variable
277 `org-e-html-style-include-default'.")
279 (defcustom org-e-html-style-include-default t
280 "Non-nil means include the default style in exported HTML files.
281 The actual style is defined in `org-e-html-style-default' and should
282 not be modified. Use the variables `org-e-html-style' to add
283 your own style information."
284 :group 'org-export-e-html
285 :type 'boolean)
286 ;;;###autoload
287 (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
289 (defcustom org-e-html-style ""
290 "Org-wide style definitions for exported HTML files.
292 This variable needs to contain the full HTML structure to provide a style,
293 including the surrounding HTML tags. If you set the value of this variable,
294 you should consider to include definitions for the following classes:
295 title, todo, done, timestamp, timestamp-kwd, tag, target.
297 For example, a valid value would be:
299 <style type=\"text/css\">
300 <![CDATA[
301 p { font-weight: normal; color: gray; }
302 h1 { color: black; }
303 .title { text-align: center; }
304 .todo, .timestamp-kwd { color: red; }
305 .done { color: green; }
307 </style>
309 If you'd like to refer to an external style file, use something like
311 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
313 As the value of this option simply gets inserted into the HTML <head> header,
314 you can \"misuse\" it to add arbitrary text to the header.
315 See also the variable `org-e-html-style-extra'."
316 :group 'org-export-e-html
317 :type 'string)
318 ;;;###autoload
319 (put 'org-e-html-style 'safe-local-variable 'stringp)
321 (defcustom org-e-html-style-extra ""
322 "Additional style information for HTML export.
323 The value of this variable is inserted into the HTML buffer right after
324 the value of `org-e-html-style'. Use this variable for per-file
325 settings of style information, and do not forget to surround the style
326 settings with <style>...</style> tags."
327 :group 'org-export-e-html
328 :type 'string)
329 ;;;###autoload
330 (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
332 (defcustom org-e-html-mathjax-options
333 '((path "http://orgmode.org/mathjax/MathJax.js")
334 (scale "100")
335 (align "center")
336 (indent "2em")
337 (mathml nil))
338 "Options for MathJax setup.
340 path The path where to find MathJax
341 scale Scaling for the HTML-CSS backend, usually between 100 and 133
342 align How to align display math: left, center, or right
343 indent If align is not center, how far from the left/right side?
344 mathml Should a MathML player be used if available?
345 This is faster and reduces bandwidth use, but currently
346 sometimes has lower spacing quality. Therefore, the default is
347 nil. When browsers get better, this switch can be flipped.
349 You can also customize this for each buffer, using something like
351 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
352 :group 'org-export-e-html
353 :type '(list :greedy t
354 (list :tag "path (the path from where to load MathJax.js)"
355 (const :format " " path) (string))
356 (list :tag "scale (scaling for the displayed math)"
357 (const :format " " scale) (string))
358 (list :tag "align (alignment of displayed equations)"
359 (const :format " " align) (string))
360 (list :tag "indent (indentation with left or right alignment)"
361 (const :format " " indent) (string))
362 (list :tag "mathml (should MathML display be used is possible)"
363 (const :format " " mathml) (boolean))))
366 ;;;; Document Header (Scripts)
368 (defcustom org-e-html-style-include-scripts t
369 "Non-nil means include the JavaScript snippets in exported HTML files.
370 The actual script is defined in `org-e-html-scripts' and should
371 not be modified."
372 :group 'org-export-e-html
373 :type 'boolean)
375 (defconst org-e-html-scripts
376 "<script type=\"text/javascript\">
377 <!--/*--><![CDATA[/*><!--*/
378 function CodeHighlightOn(elem, id)
380 var target = document.getElementById(id);
381 if(null != target) {
382 elem.cacheClassElem = elem.className;
383 elem.cacheClassTarget = target.className;
384 target.className = \"code-highlighted\";
385 elem.className = \"code-highlighted\";
388 function CodeHighlightOff(elem, id)
390 var target = document.getElementById(id);
391 if(elem.cacheClassElem)
392 elem.className = elem.cacheClassElem;
393 if(elem.cacheClassTarget)
394 target.className = elem.cacheClassTarget;
396 /*]]>*///-->
397 </script>"
398 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
401 ;;;; Document Header (Mathjax)
403 (defcustom org-e-html-mathjax-template
404 "<script type=\"text/javascript\" src=\"%PATH\">
405 <!--/*--><![CDATA[/*><!--*/
406 MathJax.Hub.Config({
407 // Only one of the two following lines, depending on user settings
408 // First allows browser-native MathML display, second forces HTML/CSS
409 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
410 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
411 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
412 \"TeX/noUndefined.js\"],
413 tex2jax: {
414 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
415 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
416 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
417 ignoreClass: \"tex2jax_ignore\",
418 processEscapes: false,
419 processEnvironments: true,
420 preview: \"TeX\"
422 showProcessingMessages: true,
423 displayAlign: \"%ALIGN\",
424 displayIndent: \"%INDENT\",
426 \"HTML-CSS\": {
427 scale: %SCALE,
428 availableFonts: [\"STIX\",\"TeX\"],
429 preferredFont: \"TeX\",
430 webFont: \"TeX\",
431 imageFont: \"TeX\",
432 showMathMenu: true,
434 MMLorHTML: {
435 prefer: {
436 MSIE: \"MML\",
437 Firefox: \"MML\",
438 Opera: \"HTML\",
439 other: \"HTML\"
443 /*]]>*///-->
444 </script>"
445 "The MathJax setup for XHTML files."
446 :group 'org-export-e-html
447 :type 'string)
450 ;;;; Preamble
452 (defcustom org-e-html-preamble t
453 "Non-nil means insert a preamble in HTML export.
455 When `t', insert a string as defined by one of the formatting
456 strings in `org-e-html-preamble-format'. When set to a
457 string, this string overrides `org-e-html-preamble-format'.
458 When set to a function, apply this function and insert the
459 returned string. The function takes the property list of export
460 options as its only argument.
462 Setting :html-preamble in publishing projects will take
463 precedence over this variable."
464 :group 'org-export-e-html
465 :type '(choice (const :tag "No preamble" nil)
466 (const :tag "Default preamble" t)
467 (string :tag "Custom formatting string")
468 (function :tag "Function (must return a string)")))
470 (defcustom org-e-html-preamble-format '(("en" ""))
471 "The format for the HTML preamble.
473 %t stands for the title.
474 %a stands for the author's name.
475 %e stands for the author's email.
476 %d stands for the date.
478 If you need to use a \"%\" character, you need to escape it
479 like that: \"%%\"."
480 :group 'org-export-e-html
481 :type 'string)
483 (defcustom org-e-html-home/up-format
484 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
485 <a accesskey=\"h\" href=\"%s\"> UP </a>
487 <a accesskey=\"H\" href=\"%s\"> HOME </a>
488 </div>"
489 "Snippet used to insert the HOME and UP links.
490 This is a format string, the first %s will receive the UP link,
491 the second the HOME link. If both `org-e-html-link-up' and
492 `org-e-html-link-home' are empty, the entire snippet will be
493 ignored."
494 :group 'org-export-e-html
495 :type 'string)
497 ;;;; Postamble
499 (defcustom org-e-html-postamble 'auto
500 "Non-nil means insert a postamble in HTML export.
502 When `t', insert a string as defined by the formatting string in
503 `org-e-html-postamble-format'. When set to a string, this
504 string overrides `org-e-html-postamble-format'. When set to
505 'auto, discard `org-e-html-postamble-format' and honor
506 `org-export-author/email/creator-info' variables. When set to a
507 function, apply this function and insert the returned string.
508 The function takes the property list of export options as its
509 only argument.
511 Setting :html-postamble in publishing projects will take
512 precedence over this variable."
513 :group 'org-export-e-html
514 :type '(choice (const :tag "No postamble" nil)
515 (const :tag "Auto preamble" 'auto)
516 (const :tag "Default formatting string" t)
517 (string :tag "Custom formatting string")
518 (function :tag "Function (must return a string)")))
520 (defcustom org-e-html-postamble-format
521 '(("en" "<p class=\"author\">Author: %a (%e)</p>
522 <p class=\"date\">Date: %d</p>
523 <p class=\"creator\">Generated by %c</p>
524 <p class=\"xhtml-validation\">%v</p>
526 "The format for the HTML postamble.
528 %a stands for the author's name.
529 %e stands for the author's email.
530 %d stands for the date.
531 %c will be replaced by information about Org/Emacs versions.
532 %v will be replaced by `org-e-html-validation-link'.
534 If you need to use a \"%\" character, you need to escape it
535 like that: \"%%\"."
536 :group 'org-export-e-html
537 :type 'string)
539 (defcustom org-e-html-validation-link
540 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
541 "Link to HTML validation service."
542 :group 'org-export-e-html
543 :type 'string)
545 ;; FIXME Obsolete since Org 7.7
546 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
547 ;;;; Emphasis
549 (defcustom org-e-html-protect-char-alist
550 '(("&" . "&amp;")
551 ("<" . "&lt;")
552 (">" . "&gt;"))
553 "Alist of characters to be converted by `org-e-html-protect'."
554 :group 'org-export-e-html
555 :type '(repeat (cons (string :tag "Character")
556 (string :tag "HTML equivalent"))))
558 (defconst org-e-html-special-string-regexps
559 '(("\\\\-" . "&shy;")
560 ("---\\([^-]\\)" . "&mdash;\\1")
561 ("--\\([^-]\\)" . "&ndash;\\1")
562 ("\\.\\.\\." . "&hellip;"))
563 "Regular expressions for special string conversion.")
566 ;;;; Todos
568 (defcustom org-e-html-todo-kwd-class-prefix ""
569 "Prefix to class names for TODO keywords.
570 Each TODO keyword gets a class given by the keyword itself, with this prefix.
571 The default prefix is empty because it is nice to just use the keyword
572 as a class name. But if you get into conflicts with other, existing
573 CSS classes, then this prefix can be very useful."
574 :group 'org-export-e-html
575 :type 'string)
578 ;;;; Tags
580 (defcustom org-e-html-tag-class-prefix ""
581 "Prefix to class names for TODO keywords.
582 Each tag gets a class given by the tag itself, with this prefix.
583 The default prefix is empty because it is nice to just use the keyword
584 as a class name. But if you get into conflicts with other, existing
585 CSS classes, then this prefix can be very useful."
586 :group 'org-export-e-html
587 :type 'string)
589 ;;;; Time-stamps
590 ;;;; Statistics Cookie
591 ;;;; Subscript
592 ;;;; Superscript
594 ;;;; Inline images
596 (defcustom org-e-html-inline-images 'maybe
597 "Non-nil means inline images into exported HTML pages.
598 This is done using an <img> tag. When nil, an anchor with href is used to
599 link to the image. If this option is `maybe', then images in links with
600 an empty description will be inlined, while images with a description will
601 be linked only."
602 :group 'org-export-e-html
603 :type '(choice (const :tag "Never" nil)
604 (const :tag "Always" t)
605 (const :tag "When there is no description" maybe)))
607 (defcustom org-e-html-inline-image-extensions
608 '("png" "jpeg" "jpg" "gif" "svg")
609 "Extensions of image files that can be inlined into HTML."
610 :group 'org-export-e-html
611 :type '(repeat (string :tag "Extension")))
614 ;;;; Block
615 ;;;; Comment
616 ;;;; Comment Block
617 ;;;; Drawer
618 ;;;; Dynamic Block
619 ;;;; Emphasis
620 ;;;; Entity
621 ;;;; Example Block
622 ;;;; Export Snippet
623 ;;;; Export Block
624 ;;;; Fixed Width
625 ;;;; Footnotes
627 (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
628 <h2 class=\"footnotes\">%s: </h2>
629 <div id=\"text-footnotes\">
631 </div>
632 </div>"
633 "Format for the footnotes section.
634 Should contain a two instances of %s. The first will be replaced with the
635 language-specific word for \"Footnotes\", the second one will be replaced
636 by the footnotes themselves."
637 :group 'org-export-e-html
638 :type 'string)
640 (defcustom org-e-html-footnote-format "<sup>%s</sup>"
641 "The format for the footnote reference.
642 %s will be replaced by the footnote reference itself."
643 :group 'org-export-e-html
644 :type 'string)
646 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
647 "Text used to separate footnotes."
648 :group 'org-export-e-html
649 :type 'string)
652 ;;;; Headline
653 ;;;; Horizontal Rule
654 ;;;; Inline Babel Call
655 ;;;; Inline Src Block
656 ;;;; Inlinetask
657 ;;;; Item
658 ;;;; Keyword
659 ;;;; Latex Environment
660 ;;;; Latex Fragment
661 ;;;; Line Break
662 ;;;; Link
663 ;;;; Babel Call
664 ;;;; Macro
665 ;;;; Paragraph
666 ;;;; Plain List
667 ;;;; Plain Text
668 ;;;; Property Drawer
669 ;;;; Quote Block
670 ;;;; Quote Section
671 ;;;; Section
672 ;;;; Radio Target
673 ;;;; Special Block
674 ;;;; Src Block
676 (defgroup org-export-e-htmlize nil
677 "Options for processing examples with htmlize.el."
678 :tag "Org Export Htmlize"
679 :group 'org-export-e-html)
681 (defcustom org-export-e-htmlize-output-type 'inline-css
682 "Output type to be used by htmlize when formatting code snippets.
683 Choices are `css', to export the CSS selectors only, or `inline-css', to
684 export the CSS attribute values inline in the HTML. We use as default
685 `inline-css', in order to make the resulting HTML self-containing.
687 However, this will fail when using Emacs in batch mode for export, because
688 then no rich font definitions are in place. It will also not be good if
689 people with different Emacs setup contribute HTML files to a website,
690 because the fonts will represent the individual setups. In these cases,
691 it is much better to let Org/Htmlize assign classes only, and to use
692 a style file to define the look of these classes.
693 To get a start for your css file, start Emacs session and make sure that
694 all the faces you are interested in are defined, for example by loading files
695 in all modes you want. Then, use the command
696 \\[org-export-e-htmlize-generate-css] to extract class definitions."
697 :group 'org-export-e-htmlize
698 :type '(choice (const css) (const inline-css)))
700 (defcustom org-export-e-htmlize-css-font-prefix "org-"
701 "The prefix for CSS class names for htmlize font specifications."
702 :group 'org-export-e-htmlize
703 :type 'string)
705 (defcustom org-export-e-htmlized-org-css-url nil
706 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
707 Normally when creating an htmlized version of an Org buffer, htmlize will
708 create CSS to define the font colors. However, this does not work when
709 converting in batch mode, and it also can look bad if different people
710 with different fontification setup work on the same website.
711 When this variable is non-nil, creating an htmlized version of an Org buffer
712 using `org-export-as-org' will remove the internal CSS section and replace it
713 with a link to this URL."
714 :group 'org-export-e-htmlize
715 :type '(choice
716 (const :tag "Keep internal css" nil)
717 (string :tag "URL or local href")))
720 ;;;; Table
722 (defcustom org-e-html-table-tag
723 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
724 "The HTML tag that is used to start a table.
725 This must be a <table> tag, but you may change the options like
726 borders and spacing."
727 :group 'org-export-e-html
728 :type 'string)
730 (defcustom org-e-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
731 "The opening tag for table header fields.
732 This is customizable so that alignment options can be specified.
733 The first %s will be filled with the scope of the field, either row or col.
734 The second %s will be replaced by a style entry to align the field.
735 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
736 See also the variable `org-e-html-table-align-individual-fields'."
737 :group 'org-export-tables ; FIXME: change group?
738 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
740 (defcustom org-e-html-table-data-tags '("<td%s>" . "</td>")
741 "The opening tag for table data fields.
742 This is customizable so that alignment options can be specified.
743 The first %s will be filled with the scope of the field, either row or col.
744 The second %s will be replaced by a style entry to align the field.
745 See also the variable `org-e-html-table-align-individual-fields'."
746 :group 'org-export-tables
747 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
749 (defcustom org-e-html-table-row-tags '("<tr>" . "</tr>")
750 "The opening tag for table data fields.
751 This is customizable so that alignment options can be specified.
752 Instead of strings, these can be Lisp forms that will be evaluated
753 for each row in order to construct the table row tags. During evaluation,
754 the variable `head' will be true when this is a header line, nil when this
755 is a body line. And the variable `nline' will contain the line number,
756 starting from 1 in the first header line. For example
758 (setq org-e-html-table-row-tags
759 (cons '(if head
760 \"<tr>\"
761 (if (= (mod nline 2) 1)
762 \"<tr class=\\\"tr-odd\\\">\"
763 \"<tr class=\\\"tr-even\\\">\"))
764 \"</tr>\"))
766 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
767 :group 'org-export-tables
768 :type '(cons
769 (choice :tag "Opening tag"
770 (string :tag "Specify")
771 (sexp))
772 (choice :tag "Closing tag"
773 (string :tag "Specify")
774 (sexp))))
776 (defcustom org-e-html-table-align-individual-fields t
777 "Non-nil means attach style attributes for alignment to each table field.
778 When nil, alignment will only be specified in the column tags, but this
779 is ignored by some browsers (like Firefox, Safari). Opera does it right
780 though."
781 :group 'org-export-tables
782 :type 'boolean)
784 (defcustom org-e-html-table-use-header-tags-for-first-column nil
785 "Non-nil means format column one in tables with header tags.
786 When nil, also column one will use data tags."
787 :group 'org-export-tables
788 :type 'boolean)
791 ;;;; Target
792 ;;;; Time-stamp
794 ;;;; Verbatim
795 ;;;; Verse Block
796 ;;;; Headline
798 (defcustom org-e-html-toplevel-hlevel 2
799 "The <H> level for level 1 headings in HTML export.
800 This is also important for the classes that will be wrapped around headlines
801 and outline structure. If this variable is 1, the top-level headlines will
802 be <h1>, and the corresponding classes will be outline-1, section-number-1,
803 and outline-text-1. If this is 2, all of these will get a 2 instead.
804 The default for this variable is 2, because we use <h1> for formatting the
805 document title."
806 :group 'org-export-e-html
807 :type 'string)
810 ;;;; Links
811 ;;;; Drawers
812 ;;;; Inlinetasks
813 ;;;; Publishing
815 (defcustom org-e-html-link-org-files-as-html t
816 "Non-nil means make file links to `file.org' point to `file.html'.
817 When org-mode is exporting an org-mode file to HTML, links to
818 non-html files are directly put into a href tag in HTML.
819 However, links to other Org-mode files (recognized by the
820 extension `.org.) should become links to the corresponding html
821 file, assuming that the linked org-mode file will also be
822 converted to HTML.
823 When nil, the links still point to the plain `.org' file."
824 :group 'org-export-e-html
825 :type 'boolean)
828 ;;;; Compilation
832 ;;; User Configurable Variables (MAYBE)
834 ;;;; Preamble
836 (defcustom org-e-html-date-format
837 "\\today"
838 "Format string for \\date{...}."
839 :group 'org-export-e-html
840 :type 'boolean)
842 ;;;; Headline
844 (defcustom org-e-html-format-headline-function nil
845 "Function to format headline text.
847 This function will be called with 5 arguments:
848 TODO the todo keyword \(string or nil\).
849 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
850 PRIORITY the priority of the headline \(integer or nil\)
851 TEXT the main headline text \(string\).
852 TAGS the tags string, separated with colons \(string or nil\).
854 The function result will be used in the section format string.
856 As an example, one could set the variable to the following, in
857 order to reproduce the default set-up:
859 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
860 \"Default format function for an headline.\"
861 \(concat \(when todo
862 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
863 \(when priority
864 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
865 text
866 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
867 :group 'org-export-e-html
868 :type 'function)
870 ;;;; Emphasis
872 (defcustom org-e-html-emphasis-alist
873 '(("*" . "<b>%s</b>")
874 ("/" . "<i>%s</i>")
875 ("_" . "<span style=\"text-decoration:underline;\">%s</span>")
876 ("+" . "<del>%s</del>")
877 ("=" . "<code>%s</code>")
878 ("~" . "<code>%s</code>"))
879 "Alist of HTML expressions to convert emphasis fontifiers.
881 The key is the character used as a marker for fontification. The
882 value is a formatting string to wrap fontified text with.
884 Value can also be set to the following symbols: `verb' and
885 `protectedtexttt'. For the former, Org will use \"\\verb\" to
886 create a format string and select a delimiter character that
887 isn't in the string. For the latter, Org will use \"\\texttt\"
888 to typeset and try to protect special characters."
889 :group 'org-export-e-html
890 :type 'alist)
893 ;;;; Footnotes
895 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
896 "Text used to separate footnotes."
897 :group 'org-export-e-html
898 :type 'string)
901 ;;;; Time-stamps
903 (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
904 "A printf format string to be applied to active time-stamps."
905 :group 'org-export-e-html
906 :type 'string)
908 (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
909 "A printf format string to be applied to inactive time-stamps."
910 :group 'org-export-e-html
911 :type 'string)
913 (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
914 "A printf format string to be applied to diary time-stamps."
915 :group 'org-export-e-html
916 :type 'string)
919 ;;;; Links
921 (defcustom org-e-html-inline-image-rules
922 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
923 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
924 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
925 "Rules characterizing image files that can be inlined into HTML.
927 A rule consists in an association whose key is the type of link
928 to consider, and value is a regexp that will be matched against
929 link's path.
931 Note that, by default, the image extension *actually* allowed
932 depend on the way the HTML file is processed. When used with
933 pdflatex, pdf, jpg and png images are OK. When processing
934 through dvi to Postscript, only ps and eps are allowed. The
935 default we use here encompasses both."
936 :group 'org-export-e-html
937 :type '(alist :key-type (string :tag "Type")
938 :value-type (regexp :tag "Path")))
940 ;;;; Tables
942 (defcustom org-e-html-table-caption-above t
943 "When non-nil, place caption string at the beginning of the table.
944 Otherwise, place it near the end."
945 :group 'org-export-e-html
946 :type 'boolean)
948 ;;;; Drawers
950 (defcustom org-e-html-format-drawer-function nil
951 "Function called to format a drawer in HTML code.
953 The function must accept two parameters:
954 NAME the drawer name, like \"LOGBOOK\"
955 CONTENTS the contents of the drawer.
957 The function should return the string to be exported.
959 For example, the variable could be set to the following function
960 in order to mimic default behaviour:
962 \(defun org-e-html-format-drawer-default \(name contents\)
963 \"Format a drawer element for HTML export.\"
964 contents\)"
965 :group 'org-export-e-html
966 :type 'function)
969 ;;;; Inlinetasks
971 (defcustom org-e-html-format-inlinetask-function nil
972 "Function called to format an inlinetask in HTML code.
974 The function must accept six parameters:
975 TODO the todo keyword, as a string
976 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
977 PRIORITY the inlinetask priority, as a string
978 NAME the inlinetask name, as a string.
979 TAGS the inlinetask tags, as a string.
980 CONTENTS the contents of the inlinetask, as a string.
982 The function should return the string to be exported.
984 For example, the variable could be set to the following function
985 in order to mimic default behaviour:
987 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
988 \"Format an inline task element for HTML export.\"
989 \(let \(\(full-title
990 \(concat
991 \(when todo
992 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
993 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
994 title
995 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
996 \(format \(concat \"\\\\begin{center}\\n\"
997 \"\\\\fbox{\\n\"
998 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
999 \"%s\\n\\n\"
1000 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1001 \"%s\"
1002 \"\\\\end{minipage}}\"
1003 \"\\\\end{center}\"\)
1004 full-title contents\)\)"
1005 :group 'org-export-e-html
1006 :type 'function)
1009 ;; Src blocks
1011 ;;;; Plain text
1013 (defcustom org-e-html-quotes
1014 '(("fr"
1015 ("\\(\\s-\\|[[(]\\|^\\)\"" . "«~")
1016 ("\\(\\S-\\)\"" . "~»")
1017 ("\\(\\s-\\|(\\|^\\)'" . "'"))
1018 ("en"
1019 ("\\(\\s-\\|[[(]\\|^\\)\"" . "``")
1020 ("\\(\\S-\\)\"" . "''")
1021 ("\\(\\s-\\|(\\|^\\)'" . "`")))
1022 "Alist for quotes to use when converting english double-quotes.
1024 The CAR of each item in this alist is the language code.
1025 The CDR of each item in this alist is a list of three CONS:
1026 - the first CONS defines the opening quote;
1027 - the second CONS defines the closing quote;
1028 - the last CONS defines single quotes.
1030 For each item in a CONS, the first string is a regexp
1031 for allowed characters before/after the quote, the second
1032 string defines the replacement string for this quote."
1033 :group 'org-export-e-html
1034 :type '(list
1035 (cons :tag "Opening quote"
1036 (string :tag "Regexp for char before")
1037 (string :tag "Replacement quote "))
1038 (cons :tag "Closing quote"
1039 (string :tag "Regexp for char after ")
1040 (string :tag "Replacement quote "))
1041 (cons :tag "Single quote"
1042 (string :tag "Regexp for char before")
1043 (string :tag "Replacement quote "))))
1045 ;;;; Compilation
1049 ;;; Internal Functions (HTML)
1051 (defun org-e-html-cvt-org-as-html (opt-plist type path)
1052 "Convert an org filename to an equivalent html filename.
1053 If TYPE is not file, just return `nil'.
1054 See variable `org-e-html-link-org-files-as-html'."
1055 (save-match-data
1056 (and
1057 org-e-html-link-org-files-as-html
1058 (string= type "file")
1059 (string-match "\\.org$" path)
1060 (progn
1061 (list
1062 "file"
1063 (concat
1064 (substring path 0 (match-beginning 0))
1065 "." (plist-get opt-plist :html-extension)))))))
1067 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1068 descp)
1069 "Make an HTML link.
1070 OPT-PLIST is an options list.
1071 TYPE is the device-type of the link (THIS://foo.html).
1072 PATH is the path of the link (http://THIS#location).
1073 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1074 DESC is the link description, if any.
1075 ATTR is a string of other attributes of the \"a\" element."
1076 (declare (special org-lparse-par-open))
1077 (save-match-data
1078 (let* ((may-inline-p
1079 (and (member type-1 '("http" "https" "file"))
1080 (org-lparse-should-inline-p path descp)
1081 (not fragment)))
1082 (type (if (equal type-1 "id") "file" type-1))
1083 (filename path)
1084 ;;First pass. Just sanity stuff.
1085 (components-1
1086 (cond
1087 ((string= type "file")
1088 (list
1089 type
1090 ;;Substitute just if original path was absolute.
1091 ;;(Otherwise path must remain relative)
1092 (if (file-name-absolute-p path)
1093 (concat "file://" (expand-file-name path))
1094 path)))
1095 ((string= type "")
1096 (list nil path))
1097 (t (list type path))))
1099 ;;Second pass. Components converted so they can refer
1100 ;;to a remote site.
1101 (components-2
1103 (and org-e-html-cvt-link-fn
1104 (apply org-e-html-cvt-link-fn
1105 opt-plist components-1))
1106 (apply #'org-e-html-cvt-org-as-html
1107 opt-plist components-1)
1108 components-1))
1109 (type (first components-2))
1110 (thefile (second components-2)))
1113 ;;Third pass. Build final link except for leading type
1114 ;;spec.
1115 (cond
1116 ((or
1117 (not type)
1118 (string= type "http")
1119 (string= type "https")
1120 (string= type "file")
1121 (string= type "coderef"))
1122 (if fragment
1123 (setq thefile (concat thefile "#" fragment))))
1125 (t))
1127 ;;Final URL-build, for all types.
1128 (setq thefile
1129 (let
1130 ((str (org-xml-format-href thefile)))
1131 (if (and type (not (or (string= "file" type)
1132 (string= "coderef" type))))
1133 (concat type ":" str)
1134 str)))
1136 (if may-inline-p
1137 (ignore) ;; (org-e-html-format-image thefile)
1138 (org-lparse-format
1139 'LINK (org-xml-format-desc desc) thefile attr)))))
1141 ;; (caption (and caption (org-xml-encode-org-text caption)))
1142 ;; alt = (file-name-nondirectory path)
1144 (defun org-e-html-format-inline-image (src &optional
1145 caption label attr standalone-p)
1146 (let* ((id (if (not label) ""
1147 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1148 (attr (concat attr
1149 (cond
1150 ((string-match "\\<alt=" (or attr "")) "")
1151 ((string-match "^ltxpng/" src)
1152 (format " alt=\"%s\""
1153 (org-e-html-encode-plain-text
1154 (org-find-text-property-in-string
1155 'org-latex-src src))))
1156 (t (format " alt=\"%s\""
1157 (file-name-nondirectory src)))))))
1158 (cond
1159 (standalone-p
1160 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1161 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1162 id (format "\n<p>%s</p>" img)
1163 (when caption (format "\n<p>%s</p>" caption)))))
1164 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1166 ;;;; Bibliography
1168 (defun org-e-html-bibliography ()
1169 "Find bibliography, cut it out and return it."
1170 (catch 'exit
1171 (let (beg end (cnt 1) bib)
1172 (save-excursion
1173 (goto-char (point-min))
1174 (when (re-search-forward
1175 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1176 (setq beg (match-beginning 0))
1177 (while (re-search-forward "</?div\\>" nil t)
1178 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1179 (when (= cnt 0)
1180 (and (looking-at ">") (forward-char 1))
1181 (setq bib (buffer-substring beg (point)))
1182 (delete-region beg (point))
1183 (throw 'exit bib))))
1184 nil))))
1186 ;;;; Table
1188 (defun org-e-html-format-table (lines olines)
1189 (let ((org-e-html-format-table-no-css nil))
1190 (org-lparse-format-table lines olines)))
1192 (defun org-e-html-splice-attributes (tag attributes)
1193 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1194 (if (not attributes)
1196 (let (oldatt newatt)
1197 (setq oldatt (org-extract-attributes-from-string tag)
1198 tag (pop oldatt)
1199 newatt (cdr (org-extract-attributes-from-string attributes)))
1200 (while newatt
1201 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1202 (if (string-match ">" tag)
1203 (setq tag
1204 (replace-match (concat (org-attributes-to-string oldatt) ">")
1205 t t tag)))
1206 tag)))
1208 (defun org-export-splice-style (style extra)
1209 "Splice EXTRA into STYLE, just before \"</style>\"."
1210 (if (and (stringp extra)
1211 (string-match "\\S-" extra)
1212 (string-match "</style>" style))
1213 (concat (substring style 0 (match-beginning 0))
1214 "\n" extra "\n"
1215 (substring style (match-beginning 0)))
1216 style))
1218 (defun org-export-e-htmlize-region-for-paste (beg end)
1219 "Convert the region to HTML, using htmlize.el.
1220 This is much like `htmlize-region-for-paste', only that it uses
1221 the settings define in the org-... variables."
1222 (let* ((htmlize-output-type org-export-e-htmlize-output-type)
1223 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
1224 (htmlbuf (htmlize-region beg end)))
1225 (unwind-protect
1226 (with-current-buffer htmlbuf
1227 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1228 (plist-get htmlize-buffer-places 'content-end)))
1229 (kill-buffer htmlbuf))))
1231 ;;;###autoload
1232 (defun org-export-e-htmlize-generate-css ()
1233 "Create the CSS for all font definitions in the current Emacs session.
1234 Use this to create face definitions in your CSS style file that can then
1235 be used by code snippets transformed by htmlize.
1236 This command just produces a buffer that contains class definitions for all
1237 faces used in the current Emacs session. You can copy and paste the ones you
1238 need into your CSS file.
1240 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1241 the function `org-export-e-htmlize-region-for-paste' will produce code
1242 that uses these same face definitions."
1243 (interactive)
1244 (require 'htmlize)
1245 (and (get-buffer "*html*") (kill-buffer "*html*"))
1246 (with-temp-buffer
1247 (let ((fl (face-list))
1248 (htmlize-css-name-prefix "org-")
1249 (htmlize-output-type 'css)
1250 f i)
1251 (while (setq f (pop fl)
1252 i (and f (face-attribute f :inherit)))
1253 (when (and (symbolp f) (or (not i) (not (listp i))))
1254 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1255 (htmlize-region (point-min) (point-max))))
1256 (org-pop-to-buffer-same-window "*html*")
1257 (goto-char (point-min))
1258 (if (re-search-forward "<style" nil t)
1259 (delete-region (point-min) (match-beginning 0)))
1260 (if (re-search-forward "</style>" nil t)
1261 (delete-region (1+ (match-end 0)) (point-max)))
1262 (beginning-of-line 1)
1263 (if (looking-at " +") (replace-match ""))
1264 (goto-char (point-min)))
1266 (defun org-e-html-make-string (n string)
1267 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1269 (defun org-e-html-toc-text (toc-entries)
1270 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1271 (start-level prev-level))
1272 (concat
1273 (mapconcat
1274 (lambda (entry)
1275 (let ((headline (nth 0 entry))
1276 (level (nth 1 entry)))
1277 (concat
1278 (let* ((cnt (- level prev-level))
1279 (times (if (> cnt 0) (1- cnt) (- cnt)))
1280 rtn)
1281 (setq prev-level level)
1282 (concat
1283 (org-e-html-make-string
1284 times (cond ((> cnt 0) "\n<ul>\n<li>")
1285 ((< cnt 0) "</li>\n</ul>\n")))
1286 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1287 headline)))
1288 toc-entries "")
1289 (org-e-html-make-string
1290 (- prev-level start-level) "</li>\n</ul>\n"))))
1292 (defun* org-e-html-format-toc-headline
1293 (todo todo-type priority text tags
1294 &key level section-number headline-label &allow-other-keys)
1295 (let ((headline (concat
1296 section-number (and section-number ". ")
1297 text
1298 (and tags "&nbsp;&nbsp;&nbsp;") (org-e-html--tags tags))))
1299 (format "<a href=\"#%s\">%s</a>"
1300 headline-label
1301 (if (not nil) headline
1302 (format "<span class=\"%s\">%s</span>" todo-type headline)))))
1304 (defun org-e-html-toc (depth info)
1305 (assert (wholenump depth))
1306 (let* ((headlines (org-export-collect-headlines info depth))
1307 (toc-entries
1308 (loop for headline in headlines collect
1309 (list (org-e-html-format-headline--wrap
1310 headline info 'org-e-html-format-toc-headline)
1311 (org-export-get-relative-level headline info)))))
1312 (when toc-entries
1313 (let* ((lang-specific-heading
1314 (nth 3 (or (assoc (plist-get info :language)
1315 org-export-language-setup)
1316 (assoc "en" org-export-language-setup)))))
1317 (concat
1318 "<div id=\"table-of-contents\">\n"
1319 (format "<h%d>%s</h%d>\n"
1320 org-e-html-toplevel-hlevel
1321 lang-specific-heading
1322 org-e-html-toplevel-hlevel)
1323 "<div id=\"text-table-of-contents\">"
1324 (org-e-html-toc-text toc-entries)
1325 "</div>\n"
1326 "</div>\n")))))
1328 ;; (defun org-e-html-format-line (line)
1329 ;; (case org-lparse-dyn-current-environment
1330 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1331 ;; (t (concat line "\n"))))
1333 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1334 "Turn todo keyword into a valid class name.
1335 Replaces invalid characters with \"_\"."
1336 (save-match-data
1337 (while (string-match "[^a-zA-Z0-9_]" kwd)
1338 (setq kwd (replace-match "_" t t kwd))))
1339 kwd)
1341 (defun org-e-html-format-footnote-reference (n def refcnt)
1342 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1343 (format org-e-html-footnote-format
1344 (format
1345 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1346 n extra n n))))
1348 (defun org-e-html-format-footnotes-section (section-name definitions)
1349 (if (not definitions) ""
1350 (format org-e-html-footnotes-section section-name definitions)))
1352 (defun org-e-html-format-footnote-definition (fn)
1353 (let ((n (car fn)) (def (cdr fn)))
1354 (format
1355 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1356 (format
1357 (format org-e-html-footnote-format
1358 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1359 n n n) def)))
1361 (defun org-e-html-footnote-section (info)
1362 (let* ((fn-alist (org-export-collect-footnote-definitions
1363 (plist-get info :parse-tree) info))
1365 (fn-alist
1366 (loop for (n type raw) in fn-alist collect
1367 (cons n (if (equal (org-element-type raw) 'org-data)
1368 (org-trim (org-export-data raw 'e-html info))
1369 (format "<p>%s</p>"
1370 (org-trim (org-export-secondary-string
1371 raw 'e-html info))))))))
1372 (when fn-alist
1373 (org-e-html-format-footnotes-section
1374 (nth 4 (or (assoc (plist-get info :language)
1375 org-export-language-setup)
1376 (assoc "en" org-export-language-setup)))
1377 (format
1378 "<table>\n%s\n</table>\n"
1379 (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
1381 (defun org-e-html-format-date (info)
1382 (let ((date (plist-get info :date)))
1383 (cond
1384 ((and date (string-match "%" date))
1385 (format-time-string date))
1386 (date date)
1387 (t (format-time-string "%Y-%m-%d %T %Z")))))
1391 ;;; Internal Functions (Ngz)
1393 (defun org-e-html--caption/label-string (caption label info)
1394 "Return caption and label HTML string for floats.
1396 CAPTION is a cons cell of secondary strings, the car being the
1397 standard caption and the cdr its short form. LABEL is a string
1398 representing the label. INFO is a plist holding contextual
1399 information.
1401 If there's no caption nor label, return the empty string.
1403 For non-floats, see `org-e-html--wrap-label'."
1404 (setq label nil) ;; FIXME
1406 (let ((label-str (if label (format "\\label{%s}" label) "")))
1407 (cond
1408 ((and (not caption) (not label)) "")
1409 ((not caption) (format "\\label{%s}\n" label))
1410 ;; Option caption format with short name.
1411 ((cdr caption)
1412 (format "\\caption[%s]{%s%s}\n"
1413 (org-export-secondary-string (cdr caption) 'e-html info)
1414 label-str
1415 (org-export-secondary-string (car caption) 'e-html info)))
1416 ;; Standard caption format.
1417 ;; (t (format "\\caption{%s%s}\n"
1418 ;; label-str
1419 ;; (org-export-secondary-string (car caption) 'e-html info)))
1421 (t (org-export-secondary-string (car caption) 'e-html info)))))
1423 (defun org-e-html--find-verb-separator (s)
1424 "Return a character not used in string S.
1425 This is used to choose a separator for constructs like \\verb."
1426 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1427 (loop for c across ll
1428 when (not (string-match (regexp-quote (char-to-string c)) s))
1429 return (char-to-string c))))
1431 (defun org-e-html--quotation-marks (text info)
1432 "Export quotation marks depending on language conventions.
1433 TEXT is a string containing quotation marks to be replaced. INFO
1434 is a plist used as a communication channel."
1435 (mapc (lambda(l)
1436 (let ((start 0))
1437 (while (setq start (string-match (car l) text start))
1438 (let ((new-quote (concat (match-string 1 text) (cdr l))))
1439 (setq text (replace-match new-quote t t text))))))
1440 (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
1441 ;; Falls back on English.
1442 (assoc "en" org-e-html-quotes))))
1443 text)
1445 (defun org-e-html--wrap-label (element output)
1446 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1447 This function shouldn't be used for floats. See
1448 `org-e-html--caption/label-string'."
1449 ;; (let ((label (org-element-property :name element)))
1450 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1451 ;; output
1452 ;; (concat (format "\\label{%s}\n" label) output)))
1453 output)
1457 ;;; Template
1459 (defun org-e-html-meta-info (info)
1460 (let* ((title (org-export-secondary-string
1461 (plist-get info :title) 'e-html info))
1462 (author (and (plist-get info :with-author)
1463 (let ((auth (plist-get info :author)))
1464 (and auth (org-export-secondary-string
1465 auth 'e-html info)))))
1466 (description (plist-get info :description))
1467 (keywords (plist-get info :keywords)))
1468 (concat
1469 (format "\n<title>%s</title>\n" title)
1470 (format
1471 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1472 (or (and org-export-coding-system
1473 (fboundp 'coding-system-get)
1474 (coding-system-get org-export-coding-system
1475 'mime-charset))
1476 "iso-8859-1"))
1477 (format "\n<meta name=\"title\" content=\"%s\"/>" title)
1478 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1479 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1480 (org-e-html-format-date info))
1481 (format "\n<meta name=\"author\" content=\"%s\"/>" author)
1482 (format "\n<meta name=\"description\" content=\"%s\"/>" description)
1483 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords))))
1485 (defun org-e-html-style (info)
1486 (concat
1487 "\n" (when (plist-get info :style-include-default) org-e-html-style-default)
1488 (plist-get info :style)
1489 (plist-get info :style-extra)
1490 "\n"
1491 (when (plist-get info :style-include-scripts)
1492 org-e-html-scripts)))
1494 (defun org-e-html-mathjax-config (info)
1495 "Insert the user setup into the matchjax template."
1496 (when (member (plist-get info :LaTeX-fragments) '(mathjax t))
1497 (let ((template org-e-html-mathjax-template)
1498 (options org-e-html-mathjax-options)
1499 (in-buffer (or (plist-get info :mathjax) ""))
1500 name val (yes " ") (no "// ") x)
1501 (mapc
1502 (lambda (e)
1503 (setq name (car e) val (nth 1 e))
1504 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1505 (setq val (car (read-from-string
1506 (substring in-buffer (match-end 0))))))
1507 (if (not (stringp val)) (setq val (format "%s" val)))
1508 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1509 (setq template (replace-match val t t template))))
1510 options)
1511 (setq val (nth 1 (assq 'mathml options)))
1512 (if (string-match (concat "\\<mathml:") in-buffer)
1513 (setq val (car (read-from-string
1514 (substring in-buffer (match-end 0))))))
1515 ;; Exchange prefixes depending on mathml setting
1516 (if (not val) (setq x yes yes no no x))
1517 ;; Replace cookies to turn on or off the config/jax lines
1518 (if (string-match ":MMLYES:" template)
1519 (setq template (replace-match yes t t template)))
1520 (if (string-match ":MMLNO:" template)
1521 (setq template (replace-match no t t template)))
1522 ;; Return the modified template
1523 template)))
1525 (defun org-e-html-preamble (info)
1526 (when (plist-get info :html-preamble)
1527 (let* ((title (org-export-secondary-string
1528 (plist-get info :title) 'e-html info))
1529 (date (org-e-html-format-date info))
1530 (author (org-export-secondary-string
1531 (plist-get info :author) 'e-html info))
1532 (lang-words (or (assoc (plist-get info :language)
1533 org-export-language-setup)
1534 (assoc "en" org-export-language-setup)))
1535 (email (plist-get info :email))
1536 (html-pre-real-contents
1537 (cond
1538 ((functionp (plist-get info :html-preamble))
1539 (with-temp-buffer
1540 (funcall (plist-get info :html-preamble))
1541 (buffer-string)))
1542 ((stringp (plist-get info :html-preamble))
1543 (format-spec (plist-get info :html-preamble)
1544 `((?t . ,title) (?a . ,author)
1545 (?d . ,date) (?e . ,email))))
1547 (format-spec
1548 (or (cadr (assoc (nth 0 lang-words)
1549 org-e-html-preamble-format))
1550 (cadr (assoc "en" org-e-html-preamble-format)))
1551 `((?t . ,title) (?a . ,author)
1552 (?d . ,date) (?e . ,email)))))))
1553 (when (not (equal html-pre-real-contents ""))
1554 (concat
1555 (format "
1556 <div id=\"%s\"> " (nth 0 org-e-html-divs))
1559 html-pre-real-contents
1561 </div>")))))
1563 (defun org-e-html-postamble (info)
1564 (concat
1565 (when (and (not body-only)
1566 (plist-get info :html-postamble))
1567 (let* ((html-post (plist-get info :html-postamble))
1568 (date (org-e-html-format-date info))
1569 (author (plist-get info :author))
1570 (email (plist-get info :email))
1571 (lang-words (or (assoc (plist-get info :language)
1572 org-export-language-setup)
1573 (assoc "en" org-export-language-setup)))
1574 (email
1575 (mapconcat (lambda(e)
1576 (format "<a href=\"mailto:%s\">%s</a>" e e))
1577 (split-string email ",+ *")
1578 ", "))
1579 (html-validation-link (or org-e-html-validation-link ""))
1580 (creator-info
1581 (concat "Org version " org-version " with Emacs version "
1582 (number-to-string emacs-major-version))))
1583 (concat
1584 ;; begin postamble
1586 <div id=\"" (nth 2 org-e-html-divs) "\">"
1587 (cond
1588 ;; auto postamble
1589 ((eq (plist-get info :html-postamble) 'auto)
1590 (concat
1591 (when (plist-get info :time-stamp-file)
1592 (format "
1593 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
1594 (when (and (plist-get info :with-author) author)
1595 (format "
1596 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
1597 (when (and (plist-get info :with-email) email)
1598 (format "
1599 <p class=\"email\"> %s </p>" email))
1600 (when (plist-get info :with-creator)
1601 (format "
1602 <p class=\"creator\"> %s </p>" creator-info))
1603 html-validation-link "\n"))
1604 ;; postamble from a string
1605 ((stringp (plist-get info :html-postamble))
1606 (format-spec (plist-get info :html-postamble)
1607 `((?a . ,author) (?e . ,email)
1608 (?d . ,date) (?c . ,creator-info)
1609 (?v . ,html-validation-link))))
1611 ;; postamble from a function
1612 ((functionp (plist-get info :html-postamble))
1613 (with-temp-buffer
1614 (funcall (plist-get info :html-postamble))
1615 (buffer-string)))
1616 ;; default postamble
1618 (format-spec
1619 (or (cadr (assoc (nth 0 lang-words)
1620 org-e-html-postamble-format))
1621 (cadr (assoc "en" org-e-html-postamble-format)))
1622 `((?a . ,author) (?e . ,email)
1623 (?d . ,date) (?c . ,creator-info)
1624 (?v . ,html-validation-link)))))
1626 </div>")))
1627 ;; org-e-html-html-helper-timestamp
1630 (defun org-e-html-template (contents info)
1631 "Return complete document string after HTML conversion.
1632 CONTENTS is the transcoded contents string. RAW-DATA is the
1633 original parsed data. INFO is a plist holding export options."
1634 (concat
1635 (format
1636 (or (and (stringp org-e-html-xml-declaration)
1637 org-e-html-xml-declaration)
1638 (cdr (assoc (plist-get info :html-extension)
1639 org-e-html-xml-declaration))
1640 (cdr (assoc "html" org-e-html-xml-declaration))
1643 (or (and coding-system-for-write
1644 (fboundp 'coding-system-get)
1645 (coding-system-get coding-system-for-write
1646 'mime-charset))
1647 "iso-8859-1"))
1649 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1650 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1651 (format "
1652 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1653 (plist-get info :language) (plist-get info :language))
1655 <head>"
1656 (org-e-html-meta-info info) ; meta
1657 (org-e-html-style info) ; style
1658 (org-e-html-mathjax-config info) ; mathjax
1660 </head>"
1663 <body>"
1664 (let ((link-up (and (plist-get info :link-up)
1665 (string-match "\\S-" (plist-get info :link-up))
1666 (plist-get info :link-up)))
1667 (link-home (and (plist-get info :link-home)
1668 (string-match "\\S-" (plist-get info :link-home))
1669 (plist-get info :link-home))))
1670 (when (or link-up link-home)
1671 (format org-e-html-home/up-format
1672 (or link-up link-home)
1673 (or link-home link-up))))
1674 ;; preamble
1675 (org-e-html-preamble info)
1676 ;; begin content
1677 (format "
1678 <div id=\"%s\">" (or org-e-html-content-div
1679 (nth 1 org-e-html-divs)))
1680 ;; document title
1681 (format "
1682 <h1 class=\"title\">%s</h1>\n" (org-export-secondary-string
1683 (plist-get info :title) 'e-html info))
1684 ;; table of contents
1685 (let ((depth (plist-get info :with-toc)))
1686 (when (wholenump depth) (org-e-html-toc depth info)))
1687 ;; document contents
1688 contents
1689 ;; footnotes section
1690 (org-e-html-footnote-section info)
1691 ;; bibliography
1692 (org-e-html-bibliography)
1693 ;; end content
1694 (unless body-only
1696 </div>")
1698 ;; postamble
1699 (org-e-html-postamble info)
1701 (unless body-only
1703 </body>")
1705 </html>"))
1709 ;;; Transcode Helpers
1711 ;;;; Todo
1713 (defun org-e-html--todo (todo)
1714 (when todo
1715 (format "<span class=\"%s %s%s\">%s</span>"
1716 (if (member todo org-done-keywords) "done" "todo")
1717 org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
1718 todo)))
1720 ;;;; Tags
1722 (defun org-e-html--tags (tags)
1723 (when tags
1724 (format "<span class=\"tag\">%s</span>"
1725 (mapconcat
1726 (lambda (tag)
1727 (format "<span class=\"%s\">%s</span>"
1728 (concat org-e-html-tag-class-prefix
1729 (org-e-html-fix-class-name tag))
1730 tag))
1731 (org-split-string tags ":") "&nbsp;"))))
1733 ;;;; Headline
1735 (defun* org-e-html-format-headline
1736 (todo todo-type priority text tags
1737 &key level section-number headline-label &allow-other-keys)
1738 (let ((section-number
1739 (when section-number
1740 (format "<span class=\"section-number-%d\">%s</span> "
1741 level section-number)))
1742 (todo (org-e-html--todo todo))
1743 (tags (org-e-html--tags tags)))
1744 (concat section-number todo (and todo " ") text
1745 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1747 ;;;; Src Code
1749 (defun org-e-html-fontify-code (code lang)
1750 (when code
1751 (cond
1752 ;; Case 1: No lang. Possibly an example block.
1753 ((not lang)
1754 ;; Simple transcoding.
1755 (org-e-html-encode-plain-text code))
1756 ;; Case 2: No htmlize or an inferior version of htmlize
1757 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1758 ;; Emit a warning.
1759 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1760 ;; Simple transcoding.
1761 (org-e-html-encode-plain-text code))
1763 ;; Map language
1764 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1765 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1766 (cond
1767 ;; Case 1: Language is not associated with any Emacs mode
1768 ((not (functionp lang-mode))
1769 ;; Simple transcoding.
1770 (org-e-html-encode-plain-text code))
1771 ;; Case 2: Default. Fotify code.
1773 ;; htmlize
1774 (setq code (with-temp-buffer
1775 (insert code)
1776 (funcall lang-mode)
1777 (font-lock-fontify-buffer)
1778 ;; markup each line separately
1779 (org-remove-formatting-on-newlines-in-region
1780 (point-min) (point-max))
1781 (org-src-mode)
1782 (set-buffer-modified-p nil)
1783 (org-export-e-htmlize-region-for-paste
1784 (point-min) (point-max))))
1785 ;; Strip any encolosing <pre></pre> tags
1786 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1787 (match-string 1 code)
1788 code))))))))
1790 (defun org-e-html-do-format-code
1791 (code &optional lang refs retain-labels num-start textarea-p)
1792 (when textarea-p
1793 (setq num-start nil refs nil lang nil))
1794 (let* ((code-lines (org-split-string code "\n"))
1795 (code-length (length code-lines))
1796 (num-fmt
1797 (and num-start
1798 (format "%%%ds: "
1799 (length (number-to-string (+ code-length num-start))))))
1800 (code (org-e-html-fontify-code code lang)))
1801 (assert (= code-length (length (org-split-string code "\n"))))
1802 (org-export-format-code
1803 code
1804 (lambda (loc line-num ref)
1805 (setq loc
1806 (concat
1807 ;; Add line number, if needed.
1808 (when num-start
1809 (format "<span class=\"linenr\">%s</span>"
1810 (format num-fmt line-num)))
1811 ;; Transcoded src line.
1813 ;; Add label, if needed.
1814 (when (and ref retain-labels) (format " (%s)" ref))))
1815 ;; Mark transcoded line as an anchor, if needed.
1816 (if (not ref) loc
1817 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1818 ref loc)))
1819 num-start refs)))
1821 (defun org-e-html-format-code (element info)
1822 (let* ((lang (org-element-property :language element))
1823 ;; (switches (org-element-property :switches element))
1824 (switches nil) ; FIXME
1825 (textarea-p (and switches (string-match "-t\\>" switches)))
1826 ;; Extract code and references.
1827 (code-info (org-export-unravel-code element))
1828 (code (car code-info))
1829 (refs (cdr code-info))
1830 ;; Does the src block contain labels?
1831 (retain-labels (org-element-property :retain-labels element))
1832 ;; Does it have line numbers?
1833 (num-start (case (org-element-property :number-lines element)
1834 (continued (org-export-get-loc element info))
1835 (new 0))))
1836 (org-e-html-do-format-code
1837 code lang refs retain-labels num-start textarea-p)))
1841 ;;; Transcode Functions
1843 ;;;; Block
1845 (defun org-e-html-center-block (center-block contents info)
1846 "Transcode a CENTER-BLOCK element from Org to HTML.
1847 CONTENTS holds the contents of the block. INFO is a plist
1848 holding contextual information."
1849 (org-e-html--wrap-label
1850 center-block
1851 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
1854 ;;;; Comment
1856 ;; Comments are ignored.
1859 ;;;; Comment Block
1861 ;; Comment Blocks are ignored.
1864 ;;;; Drawer
1866 (defun org-e-html-drawer (drawer contents info)
1867 "Transcode a DRAWER element from Org to HTML.
1868 CONTENTS holds the contents of the block. INFO is a plist
1869 holding contextual information."
1870 (let* ((name (org-element-property :drawer-name drawer))
1871 (output (if (functionp org-e-html-format-drawer-function)
1872 (funcall org-e-html-format-drawer-function
1873 name contents)
1874 ;; If there's no user defined function: simply
1875 ;; display contents of the drawer.
1876 contents)))
1877 (org-e-html--wrap-label drawer output)))
1880 ;;;; Dynamic Block
1882 (defun org-e-html-dynamic-block (dynamic-block contents info)
1883 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1884 CONTENTS holds the contents of the block. INFO is a plist
1885 holding contextual information. See
1886 `org-export-data'."
1887 (org-e-html--wrap-label dynamic-block contents))
1890 ;;;; Emphasis
1892 (defun org-e-html-emphasis (emphasis contents info)
1893 "Transcode EMPHASIS from Org to HTML.
1894 CONTENTS is the contents of the emphasized text. INFO is a plist
1895 holding contextual information.."
1896 (let* ((marker (org-element-property :marker emphasis)))
1897 (format (cdr (assoc marker org-e-html-emphasis-alist)) contents)))
1900 ;;;; Entity
1902 (defun org-e-html-entity (entity contents info)
1903 "Transcode an ENTITY object from Org to HTML.
1904 CONTENTS are the definition itself. INFO is a plist holding
1905 contextual information."
1906 (org-element-property :html entity))
1909 ;;;; Example Block
1911 (defun org-e-html-example-block (example-block contents info)
1912 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1913 CONTENTS is nil. INFO is a plist holding contextual information."
1914 (let* ((options (or (org-element-property :options example-block) ""))
1915 (lang (org-element-property :language example-block))
1916 (caption (org-element-property :caption example-block))
1917 (label (org-element-property :name example-block))
1918 (caption-str (org-e-html--caption/label-string caption label info))
1919 (attr (mapconcat #'identity
1920 (org-element-property :attr_html example-block)
1921 " "))
1922 ;; (switches (org-element-property :switches example-block))
1923 (switches nil) ; FIXME
1924 (textarea-p (and switches (string-match "-t\\>" switches)))
1925 (code (org-e-html-format-code example-block info)))
1926 (cond
1927 (textarea-p
1928 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
1929 80 (string-to-number (match-string 1 switches))))
1930 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
1931 (string-to-number (match-string 1 switches))
1932 (org-count-lines code))))
1933 (format
1934 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1935 cols rows code)))
1936 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
1939 ;;;; Export Snippet
1941 (defun org-e-html-export-snippet (export-snippet contents info)
1942 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1943 CONTENTS is nil. INFO is a plist holding contextual information."
1944 (when (eq (org-export-snippet-backend export-snippet) 'e-html)
1945 (org-element-property :value export-snippet)))
1948 ;;;; Export Block
1950 (defun org-e-html-export-block (export-block contents info)
1951 "Transcode a EXPORT-BLOCK element from Org to HTML.
1952 CONTENTS is nil. INFO is a plist holding contextual information."
1953 (when (string= (org-element-property :type export-block) "latex")
1954 (org-remove-indentation (org-element-property :value export-block))))
1957 ;;;; Fixed Width
1959 (defun org-e-html-fixed-width (fixed-width contents info)
1960 "Transcode a FIXED-WIDTH element from Org to HTML.
1961 CONTENTS is nil. INFO is a plist holding contextual information."
1962 (let* ((value (org-element-normalize-string
1963 (replace-regexp-in-string
1964 "^[ \t]*: ?" ""
1965 (org-element-property :value fixed-width)))))
1966 (org-e-html--wrap-label
1967 fixed-width (format "\n<pre class=\"example\">\n%s\n</pre>"
1968 (org-e-html-do-format-code value)))))
1971 ;;;; Footnote Definition
1973 ;; Footnote Definitions are ignored.
1976 ;;;; Footnote Reference
1978 (defun org-e-html-footnote-reference (footnote-reference contents info)
1979 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1980 CONTENTS is nil. INFO is a plist holding contextual information."
1981 (concat
1982 ;; Insert separator between two footnotes in a row.
1983 (let ((prev (org-export-get-previous-element footnote-reference info)))
1984 (when (eq (org-element-type prev) 'footnote-reference)
1985 org-e-html-footnote-separator))
1986 (cond
1987 ((not (org-export-footnote-first-reference-p footnote-reference info))
1988 (org-e-html-format-footnote-reference
1989 (org-export-get-footnote-number footnote-reference info)
1990 "IGNORED" 100))
1991 ;; Inline definitions are secondary strings.
1992 ((eq (org-element-property :type footnote-reference) 'inline)
1993 (org-e-html-format-footnote-reference
1994 (org-export-get-footnote-number footnote-reference info)
1995 "IGNORED" 1))
1996 ;; Non-inline footnotes definitions are full Org data.
1997 (t (org-e-html-format-footnote-reference
1998 (org-export-get-footnote-number footnote-reference info)
1999 "IGNORED" 1)))))
2002 ;;;; Headline
2004 (defun org-e-html-format-headline--wrap (headline info
2005 &optional format-function
2006 &rest extra-keys)
2007 "Transcode an HEADLINE element from Org to HTML.
2008 CONTENTS holds the contents of the headline. INFO is a plist
2009 holding contextual information."
2010 (let* ((level (+ (org-export-get-relative-level headline info)
2011 (1- org-e-html-toplevel-hlevel)))
2012 (headline-number (org-export-get-headline-number headline info))
2013 (section-number (and (org-export-numbered-headline-p headline info)
2014 (mapconcat 'number-to-string
2015 headline-number ".")))
2016 (todo (and (plist-get info :with-todo-keywords)
2017 (let ((todo (org-element-property
2018 :todo-keyword headline)))
2019 (and todo
2020 (org-export-secondary-string todo 'e-html info)))))
2021 (todo-type (and todo (org-element-property :todo-type headline)))
2022 (priority (and (plist-get info :with-priority)
2023 (org-element-property :priority headline)))
2024 (text (org-export-secondary-string
2025 (org-element-property :title headline) 'e-html info))
2026 (tags (and (plist-get info :with-tags)
2027 (org-element-property :tags headline)))
2028 (headline-label (concat "sec-" (mapconcat 'number-to-string
2029 headline-number "-")))
2030 (format-function (cond
2031 ((functionp format-function) format-function)
2032 ((functionp org-e-html-format-headline-function)
2033 (function*
2034 (lambda (todo todo-type priority text tags
2035 &allow-other-keys)
2036 (funcall org-e-html-format-headline-function
2037 todo todo-type priority text tags))))
2038 (t 'org-e-html-format-headline))))
2039 (apply format-function
2040 todo todo-type priority text tags
2041 :headline-label headline-label :level level
2042 :section-number section-number extra-keys)))
2044 (defun org-e-html-headline (headline contents info)
2045 "Transcode an HEADLINE element from Org to HTML.
2046 CONTENTS holds the contents of the headline. INFO is a plist
2047 holding contextual information."
2048 (let* ((numberedp (org-export-numbered-headline-p headline info))
2049 (level (org-export-get-relative-level headline info))
2050 (text (org-export-secondary-string
2051 (org-element-property :title headline) 'e-html info))
2052 (todo (and (plist-get info :with-todo-keywords)
2053 (let ((todo (org-element-property
2054 :todo-keyword headline)))
2055 (and todo
2056 (org-export-secondary-string todo 'e-html info)))))
2057 (todo-type (and todo (org-element-property :todo-type headline)))
2058 (tags (and (plist-get info :with-tags)
2059 (org-element-property :tags headline)))
2060 (priority (and (plist-get info :with-priority)
2061 (org-element-property :priority headline)))
2062 (section-number (and (org-export-numbered-headline-p headline info)
2063 (mapconcat 'number-to-string
2064 (org-export-get-headline-number
2065 headline info) ".")))
2066 ;; Create the headline text.
2067 (full-text (org-e-html-format-headline--wrap headline info)))
2068 (cond
2069 ;; Case 1: This is a footnote section: ignore it.
2070 ((org-element-property :footnote-section-p headline) nil)
2071 ;; Case 2. This is a deep sub-tree: export it as a list item.
2072 ;; Also export as items headlines for which no section
2073 ;; format has been found.
2074 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
2075 ;; Build the real contents of the sub-tree.
2076 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
2077 (itemized-body (org-e-html-format-list-item
2078 contents type nil nil full-text)))
2079 (concat
2080 (and (org-export-first-sibling-p headline info)
2081 (org-e-html-begin-plain-list type))
2082 itemized-body
2083 (and (org-export-last-sibling-p headline info)
2084 (org-e-html-end-plain-list type)))))
2085 ;; Case 3. Standard headline. Export it as a section.
2087 (let* ((extra-class (org-element-property :html-container-class headline))
2088 (extra-ids (list (org-element-property :custom-id headline)
2089 (org-element-property :id headline)))
2090 (extra-ids
2091 (mapconcat
2092 (lambda (x)
2093 (when x
2094 (let ((id (org-solidify-link-text
2095 (if (org-uuidgen-p x) (concat "ID-" x) x))))
2096 (format "<a id=\"%s\" name=\"%s\"/>" id id))))
2097 extra-ids ""))
2098 (level1 (+ level (1- org-e-html-toplevel-hlevel)))
2099 (id (mapconcat 'number-to-string
2100 (org-export-get-headline-number headline info) "-")))
2101 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2102 (format "outline-container-%s" id)
2103 (concat (format "outline-%d" level1) (and extra-class " ")
2104 extra-class)
2105 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2106 level1 id extra-ids full-text level1)
2107 contents))))))
2110 ;;;; Horizontal Rule
2112 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
2113 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2114 CONTENTS is nil. INFO is a plist holding contextual information."
2115 (let ((attr (mapconcat #'identity
2116 (org-element-property :attr_html horizontal-rule)
2117 " ")))
2118 (org-e-html--wrap-label horizontal-rule "<hr/>\n")))
2121 ;;;; Inline Babel Call
2123 ;; Inline Babel Calls are ignored.
2126 ;;;; Inline Src Block
2128 (defun org-e-html-inline-src-block (inline-src-block contents info)
2129 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2130 CONTENTS holds the contents of the item. INFO is a plist holding
2131 contextual information."
2132 (let* ((org-lang (org-element-property :language inline-src-block))
2133 (code (org-element-property :value inline-src-block))
2134 (separator (org-e-html--find-verb-separator code)))
2135 (error "FIXME")))
2138 ;;;; Inlinetask
2140 (defun org-e-html-format-section (text class &optional id)
2141 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2142 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2144 (defun org-e-html-inlinetask (inlinetask contents info)
2145 "Transcode an INLINETASK element from Org to HTML.
2146 CONTENTS holds the contents of the block. INFO is a plist
2147 holding contextual information."
2148 (cond
2149 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2150 ;; with appropriate arguments.
2151 ((functionp org-e-html-format-inlinetask-function)
2152 (let ((format-function
2153 (function*
2154 (lambda (todo todo-type priority text tags
2155 &key contents &allow-other-keys)
2156 (funcall org-e-html-format-inlinetask-function
2157 todo todo-type priority text tags contents)))))
2158 (org-e-html-format-headline--wrap
2159 inlinetask info format-function :contents contents)))
2160 ;; Otherwise, use a default template.
2161 (t (org-e-html--wrap-label
2162 inlinetask
2163 (format
2164 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2165 (org-e-html-format-headline--wrap inlinetask info)
2166 contents)))))
2169 ;;;; Item
2171 (defun org-e-html-checkbox (checkbox)
2172 (case checkbox (on "<code>[X]</code>")
2173 (off "<code>[&nbsp;]</code>")
2174 (trans "<code>[-]</code>")
2175 (t "")))
2177 (defun org-e-html-format-list-item (contents type checkbox
2178 &optional term-counter-id
2179 headline)
2180 (concat
2181 (case type
2182 (ordered
2183 (let* ((counter term-counter-id)
2184 (extra (if counter (format " value=\"%s\"" counter) "")))
2185 (format "<li%s>" extra)))
2186 (unordered
2187 (let* ((id term-counter-id)
2188 (extra (if id (format " id=\"%s\"" id) "")))
2189 (concat
2190 (format "<li%s>" extra)
2191 (when headline (concat headline "<br/>")))))
2192 (descriptive
2193 (let* ((term term-counter-id))
2194 (setq term (or term "(no term)"))
2195 (concat (format "<dt> %s </dt>" term) "<dd>"))))
2196 (org-e-html-checkbox checkbox) (and checkbox " ")
2197 contents
2198 (case type
2199 (ordered "</li>")
2200 (unordered "</li>")
2201 (descriptive "</dd>"))))
2203 (defun org-e-html-item (item contents info)
2204 "Transcode an ITEM element from Org to HTML.
2205 CONTENTS holds the contents of the item. INFO is a plist holding
2206 contextual information."
2207 ;; Grab `:level' from plain-list properties, which is always the
2208 ;; first element above current item.
2209 (let* ((plain-list (org-export-get-parent item info))
2210 (type (org-element-property :type plain-list))
2211 (level (org-element-property :level plain-list))
2212 (counter (org-element-property :counter item))
2213 (checkbox (org-element-property :checkbox item))
2214 (tag (let ((tag (org-element-property :tag item)))
2215 (and tag (org-export-secondary-string tag 'e-html info)))))
2216 (org-e-html-format-list-item
2217 contents type checkbox (or tag counter))))
2220 ;;;; Keyword
2222 (defun org-e-html-keyword (keyword contents info)
2223 "Transcode a KEYWORD element from Org to HTML.
2224 CONTENTS is nil. INFO is a plist holding contextual information."
2225 (let ((key (org-element-property :key keyword))
2226 (value (org-element-property :value keyword)))
2227 (cond
2228 ((string= key "LATEX") value)
2229 ((string= key "INDEX") (format "\\index{%s}" value))
2230 ;; Invisible targets.
2231 ((string= key "TARGET") nil) ; FIXME
2232 ((string= key "TOC")
2233 (let ((value (downcase value)))
2234 (cond
2235 ((string-match "\\<headlines\\>" value)
2236 (let ((depth (or (and (string-match "[0-9]+" value)
2237 (string-to-number (match-string 0 value)))
2238 (plist-get info :with-toc))))
2239 (when (wholenump depth) (org-e-html-toc depth info))))
2240 ((string= "tables" value) "\\listoftables")
2241 ((string= "figures" value) "\\listoffigures")
2242 ((string= "listings" value)
2243 (cond
2244 ;; At the moment, src blocks with a caption are wrapped
2245 ;; into a figure environment.
2246 (t "\\listoffigures")))))))))
2249 ;;;; Latex Environment
2251 (defun org-e-html-format-latex (latex-frag processing-type)
2252 (let* ((cache-relpath
2253 (concat "ltxpng/" (file-name-sans-extension
2254 (file-name-nondirectory (buffer-file-name)))))
2255 (cache-dir (file-name-directory (buffer-file-name )))
2256 (display-msg "Creating LaTeX Image..."))
2258 (with-temp-buffer
2259 (insert latex-frag)
2260 (org-format-latex cache-relpath cache-dir nil display-msg
2261 nil nil processing-type)
2262 (buffer-string))))
2264 (defun org-e-html-latex-environment (latex-environment contents info)
2265 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2266 CONTENTS is nil. INFO is a plist holding contextual information."
2267 (org-e-html--wrap-label
2268 latex-environment
2269 (let ((processing-type (plist-get info :LaTeX-fragments))
2270 (latex-frag (org-remove-indentation
2271 (org-element-property :value latex-environment)))
2272 (caption (org-e-html--caption/label-string
2273 (org-element-property :caption latex-environment)
2274 (org-element-property :name latex-environment)
2275 info))
2276 (attr nil) ; FIXME
2277 (label (org-element-property :name latex-environment)))
2278 (cond
2279 ((member processing-type '(t mathjax))
2280 (org-e-html-format-latex latex-frag 'mathjax))
2281 ((equal processing-type 'dvipng)
2282 (let* ((formula-link (org-e-html-format-latex
2283 latex-frag processing-type)))
2284 (when (and formula-link
2285 (string-match "file:\\([^]]*\\)" formula-link))
2286 (org-e-html-format-inline-image
2287 (match-string 1 formula-link) caption label attr t))))
2288 (t latex-frag)))))
2291 ;;;; Latex Fragment
2293 (defun org-e-html-latex-fragment (latex-fragment contents info)
2294 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2295 CONTENTS is nil. INFO is a plist holding contextual information."
2296 (let ((latex-frag (org-element-property :value latex-fragment))
2297 (processing-type (plist-get info :LaTeX-fragments)))
2298 (case processing-type
2299 ((t mathjax)
2300 (org-e-html-format-latex latex-frag 'mathjax))
2301 (dvipng
2302 (let* ((formula-link (org-e-html-format-latex
2303 latex-frag processing-type)))
2304 (when (and formula-link
2305 (string-match "file:\\([^]]*\\)" formula-link))
2306 (org-e-html-format-inline-image
2307 (match-string 1 formula-link)))))
2308 (t latex-frag))))
2310 ;;;; Line Break
2312 (defun org-e-html-line-break (line-break contents info)
2313 "Transcode a LINE-BREAK object from Org to HTML.
2314 CONTENTS is nil. INFO is a plist holding contextual information."
2315 "<br/>")
2318 ;;;; Link
2320 (defun org-e-html-link--inline-image (link desc info)
2321 "Return HTML code for an inline image.
2322 LINK is the link pointing to the inline image. INFO is a plist
2323 used as a communication channel."
2324 (let* ((type (org-element-property :type link))
2325 (raw-path (org-element-property :path link))
2326 (path (cond ((member type '("http" "https"))
2327 (concat type ":" raw-path))
2328 ((file-name-absolute-p raw-path)
2329 (expand-file-name raw-path))
2330 (t raw-path)))
2331 (parent (org-export-get-parent-paragraph link info))
2332 (caption (org-e-html--caption/label-string
2333 (org-element-property :caption parent)
2334 (org-element-property :name parent)
2335 info))
2336 (label (org-element-property :name parent))
2337 ;; Retrieve latex attributes from the element around.
2338 (attr (let ((raw-attr
2339 (mapconcat #'identity
2340 (org-element-property :attr_html parent)
2341 " ")))
2342 (unless (string= raw-attr "") raw-attr))))
2343 ;; Now clear ATTR from any special keyword and set a default
2344 ;; value if nothing is left.
2345 (setq attr (if (not attr) "" (org-trim attr)))
2346 ;; Return proper string, depending on DISPOSITION.
2347 (org-e-html-format-inline-image
2348 path caption label attr (org-e-html-standalone-image-p link info))))
2350 (defvar org-e-html-standalone-image-predicate)
2351 (defun org-e-html-standalone-image-p (element info &optional predicate)
2352 "Test if ELEMENT is a standalone image for the purpose HTML export.
2353 INFO is a plist holding contextual information.
2355 Return non-nil, if ELEMENT is of type paragraph and it's sole
2356 content, save for whitespaces, is a link that qualifies as an
2357 inline image.
2359 Return non-nil, if ELEMENT is of type link and it's containing
2360 paragraph has no other content save for leading and trailing
2361 whitespaces.
2363 Return nil, otherwise.
2365 Bind `org-e-html-standalone-image-predicate' to constrain
2366 paragraph further. For example, to check for only captioned
2367 standalone images, do the following.
2369 \(setq org-e-html-standalone-image-predicate
2370 \(lambda \(paragraph\)
2371 \(org-element-property :caption paragraph\)\)\)
2373 (let ((paragraph (case (org-element-type element)
2374 (paragraph element)
2375 (link (and (org-export-inline-image-p
2376 element org-e-html-inline-image-rules)
2377 (org-export-get-parent element info)))
2378 (t nil))))
2379 (when paragraph
2380 (assert (eq (org-element-type paragraph) 'paragraph))
2381 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
2382 (functionp org-e-html-standalone-image-predicate)))
2383 (funcall org-e-html-standalone-image-predicate paragraph))
2384 (let ((contents (org-element-contents paragraph)))
2385 (loop for x in contents
2386 with inline-image-count = 0
2387 always (cond
2388 ((eq (org-element-type x) 'plain-text)
2389 (not (org-string-nw-p x)))
2390 ((eq (org-element-type x) 'link)
2391 (when (org-export-inline-image-p
2392 x org-e-html-inline-image-rules)
2393 (= (incf inline-image-count) 1)))
2394 (t nil))))))))
2396 (defun org-e-html-link (link desc info)
2397 "Transcode a LINK object from Org to HTML.
2399 DESC is the description part of the link, or the empty string.
2400 INFO is a plist holding contextual information. See
2401 `org-export-data'."
2402 (let* ((type (org-element-property :type link))
2403 (raw-path (org-element-property :path link))
2404 ;; Ensure DESC really exists, or set it to nil.
2405 (desc (and (not (string= desc "")) desc))
2406 (path (cond
2407 ((member type '("http" "https" "ftp" "mailto"))
2408 (concat type ":" raw-path))
2409 ((string= type "file")
2410 (when (string-match "\\(.+\\)::.+" raw-path)
2411 (setq raw-path (match-string 1 raw-path)))
2412 (if (file-name-absolute-p raw-path)
2413 (concat "file://" (expand-file-name raw-path))
2414 ;; TODO: Not implemented yet. Concat also:
2415 ;; (org-export-directory :HTML info)
2416 (concat "file://" raw-path)))
2417 (t raw-path)))
2418 protocol)
2419 (cond
2420 ;; Image file.
2421 ((and (or (eq t org-e-html-inline-images)
2422 (and org-e-html-inline-images (not desc)))
2423 (org-export-inline-image-p link org-e-html-inline-image-rules))
2424 (org-e-html-link--inline-image link desc info))
2425 ;; Radioed target: Target's name is obtained from original raw
2426 ;; link. Path is parsed and transcoded in order to have a proper
2427 ;; display of the contents.
2428 ((string= type "radio")
2429 (format "<a href=\"#%s\">%s</a>"
2430 (org-export-solidify-link-text path)
2431 (org-export-secondary-string
2432 (org-element-parse-secondary-string
2433 path (cdr (assq 'radio-target org-element-object-restrictions)))
2434 'e-html info)))
2435 ;; Links pointing to an headline: Find destination and build
2436 ;; appropriate referencing command.
2437 ((member type '("custom-id" "fuzzy" "id"))
2438 (let ((destination (if (string= type "fuzzy")
2439 (org-export-resolve-fuzzy-link link info)
2440 (org-export-resolve-id-link link info))))
2441 (case (org-element-type destination)
2442 ;; Fuzzy link points nowhere.
2443 ('nil
2444 (format "<i>%s</i>"
2445 (or desc (org-export-secondary-string
2446 (org-element-property :raw-link link)
2447 'e-html info))))
2448 ;; Fuzzy link points to an invisible target.
2449 (keyword nil)
2450 ;; LINK points to an headline. If headlines are numbered
2451 ;; and the link has no description, display headline's
2452 ;; number. Otherwise, display description or headline's
2453 ;; title.
2454 (headline
2455 (let* ((headline-no (org-export-get-headline-number destination info))
2456 (label (format "sec-%s" (mapconcat 'number-to-string
2457 headline-no "-")))
2458 (section-no (mapconcat 'number-to-string headline-no ".")))
2459 (setq desc
2460 (cond
2461 (desc desc)
2462 ((plist-get info :section-numbers) section-no)
2463 (t (org-export-secondary-string
2464 (org-element-property :title destination)
2465 'e-html info))))
2466 (format "<a href=\"#%s\">%s</a>" label desc)))
2467 ;; Fuzzy link points to a target. Do as above.
2468 (otherwise
2469 (let ((path (org-export-solidify-link-text path)) number)
2470 (unless desc
2471 (setq number (cond
2472 ((org-e-html-standalone-image-p destination info)
2473 (org-export-get-ordinal
2474 (assoc 'link (org-element-contents destination))
2475 info 'link 'org-e-html-standalone-image-p))
2476 (t (org-export-get-ordinal destination info))))
2477 (setq desc (when number
2478 (if (atom number) (number-to-string number)
2479 (mapconcat 'number-to-string number ".")))))
2480 (format "<a href=\"#%s\">%s</a>" path (or desc "FIXME")))))))
2481 ;; Coderef: replace link with the reference name or the
2482 ;; equivalent line number.
2483 ((string= type "coderef")
2484 (let ((fragment (concat "coderef-" path)))
2485 (format "<a href=\"#%s\" %s>%s</a>" fragment
2486 (format (concat "class=\"coderef\""
2487 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2488 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2489 fragment fragment)
2490 (format (org-export-get-coderef-format path (or desc "%s"))
2491 (org-export-resolve-coderef path info)))))
2492 ;; Link type is handled by a special function.
2493 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2494 (funcall protocol (org-link-unescape path) desc 'html))
2495 ;; External link with a description part.
2496 ((and path desc) (format "<a href=\"%s\">%s</a>" path desc))
2497 ;; External link without a description part.
2498 (path (format "<a href=\"%s\">%s</a>" path path))
2499 ;; No path, only description. Try to do something useful.
2500 (t (format "<i>%s</i>" desc)))))
2503 ;;;; Babel Call
2505 ;; Babel Calls are ignored.
2508 ;;;; Macro
2510 (defun org-e-html-macro (macro contents info)
2511 "Transcode a MACRO element from Org to HTML.
2512 CONTENTS is nil. INFO is a plist holding contextual information."
2513 ;; Use available tools.
2514 (org-export-expand-macro macro info))
2517 ;;;; Paragraph
2519 (defun org-e-html-paragraph (paragraph contents info)
2520 "Transcode a PARAGRAPH element from Org to HTML.
2521 CONTENTS is the contents of the paragraph, as a string. INFO is
2522 the plist used as a communication channel."
2523 (let* ((style nil) ; FIXME
2524 (class (cdr (assoc style '((footnote . "footnote")
2525 (verse . nil)))))
2526 (extra (if class (format " class=\"%s\"" class) ""))
2527 (parent (org-export-get-parent paragraph info)))
2528 (cond
2529 ((and (equal (car parent) 'item)
2530 (= (org-element-property :begin paragraph)
2531 (org-element-property :contents-begin parent)))
2532 ;; leading paragraph in a list item have no tags
2533 contents)
2534 ((org-e-html-standalone-image-p paragraph info)
2535 ;; standalone image
2536 contents)
2537 (t (format "\n<p%s>\n%s\n</p>" extra contents)))))
2540 ;;;; Plain List
2542 (defun org-e-html-begin-plain-list (type &optional arg1)
2543 (case type
2544 (ordered
2545 (format "<ol%s>" (if arg1 ; FIXME
2546 (format " start=\"%d\"" arg1)
2547 "")))
2548 (unordered "<ul>")
2549 (descriptive "<dl>")))
2551 (defun org-e-html-end-plain-list (type)
2552 (case type
2553 (ordered "</ol>")
2554 (unordered "</ul>")
2555 (descriptive "</dl>")))
2557 (defun org-e-html-plain-list (plain-list contents info)
2558 "Transcode a PLAIN-LIST element from Org to HTML.
2559 CONTENTS is the contents of the list. INFO is a plist holding
2560 contextual information."
2561 (let* (arg1 ;; FIXME
2562 (type (org-element-property :type plain-list))
2563 (attr (mapconcat #'identity
2564 (org-element-property :attr_html plain-list)
2565 " ")))
2566 (org-e-html--wrap-label
2567 plain-list (format "%s\n%s%s"
2568 (org-e-html-begin-plain-list type)
2569 contents (org-e-html-end-plain-list type)))))
2571 ;;;; Plain Text
2573 (defun org-e-html-convert-special-strings (string)
2574 "Convert special characters in STRING to HTML."
2575 (let ((all org-e-html-special-string-regexps)
2576 e a re rpl start)
2577 (while (setq a (pop all))
2578 (setq re (car a) rpl (cdr a) start 0)
2579 (while (string-match re string start)
2580 (setq string (replace-match rpl t nil string))))
2581 string))
2583 (defun org-e-html-encode-plain-text (s)
2584 "Convert plain text characters to HTML equivalent.
2585 Possible conversions are set in `org-export-html-protect-char-alist'."
2586 (let ((cl org-e-html-protect-char-alist) c)
2587 (while (setq c (pop cl))
2588 (let ((start 0))
2589 (while (string-match (car c) s start)
2590 (setq s (replace-match (cdr c) t t s)
2591 start (1+ (match-beginning 0))))))
2594 (defun org-e-html-plain-text (text info)
2595 "Transcode a TEXT string from Org to HTML.
2596 TEXT is the string to transcode. INFO is a plist holding
2597 contextual information."
2598 (setq text (org-e-html-encode-plain-text text))
2599 ;; Protect %, #, &, $, ~, ^, _, { and }.
2600 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2601 ;; (setq text
2602 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2603 ;; Protect \
2604 ;; (setq text (replace-regexp-in-string
2605 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2606 ;; "$\\backslash$" text nil t 1))
2607 ;; HTML into \HTML{} and TeX into \TeX{}.
2608 ;; (let ((case-fold-search nil)
2609 ;; (start 0))
2610 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2611 ;; (setq text (replace-match
2612 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2613 ;; start (match-end 0))))
2614 ;; Handle quotation marks
2615 ;; (setq text (org-e-html--quotation-marks text info))
2616 ;; Convert special strings.
2617 ;; (when (plist-get info :with-special-strings)
2618 ;; (while (string-match (regexp-quote "...") text)
2619 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2620 (when (plist-get info :with-special-strings)
2621 (setq text (org-e-html-convert-special-strings text)))
2622 ;; Handle break preservation if required.
2623 (when (plist-get info :preserve-breaks)
2624 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2625 text)))
2626 ;; Return value.
2627 text)
2630 ;;;; Property Drawer
2632 (defun org-e-html-property-drawer (property-drawer contents info)
2633 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2634 CONTENTS is nil. INFO is a plist holding contextual
2635 information."
2636 ;; The property drawer isn't exported but we want separating blank
2637 ;; lines nonetheless.
2641 ;;;; Quote Block
2643 (defun org-e-html-quote-block (quote-block contents info)
2644 "Transcode a QUOTE-BLOCK element from Org to HTML.
2645 CONTENTS holds the contents of the block. INFO is a plist
2646 holding contextual information."
2647 (org-e-html--wrap-label
2648 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2651 ;;;; Quote Section
2653 (defun org-e-html-quote-section (quote-section contents info)
2654 "Transcode a QUOTE-SECTION element from Org to HTML.
2655 CONTENTS is nil. INFO is a plist holding contextual information."
2656 (let ((value (org-remove-indentation
2657 (org-element-property :value quote-section))))
2658 (when value (format "<pre>\n%s</pre>" value))))
2661 ;;;; Section
2663 (defun org-e-html-section (section contents info) ; FIXME
2664 "Transcode a SECTION element from Org to HTML.
2665 CONTENTS holds the contents of the section. INFO is a plist
2666 holding contextual information."
2667 (let ((parent (org-export-get-parent-headline section info)))
2668 ;; Before first headline: no container, just return CONTENTS.
2669 (if (not parent) contents
2670 ;; Get div's class and id references.
2671 (let ((class-num (+ (org-export-get-relative-level parent info)
2672 (1- org-e-html-toplevel-hlevel)))
2673 (id-num
2674 (mapconcat
2675 'number-to-string
2676 (org-export-get-headline-number parent info) "-")))
2677 ;; Build return value.
2678 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2679 class-num id-num contents)))))
2681 ;;;; Radio Target
2683 (defun org-e-html-radio-target (radio-target text info)
2684 "Transcode a RADIO-TARGET object from Org to HTML.
2685 TEXT is the text of the target. INFO is a plist holding
2686 contextual information."
2687 (let ((id (org-export-solidify-link-text
2688 (org-element-property :value radio-target))))
2689 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
2692 ;;;; Special Block
2694 (defun org-e-html-special-block (special-block contents info)
2695 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2696 CONTENTS holds the contents of the block. INFO is a plist
2697 holding contextual information."
2698 (let ((type (downcase (org-element-property :type special-block))))
2699 (org-e-html--wrap-label
2700 special-block
2701 (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
2704 ;;;; Src Block
2706 (defun org-e-html-src-block (src-block contents info)
2707 "Transcode a SRC-BLOCK element from Org to HTML.
2708 CONTENTS holds the contents of the item. INFO is a plist holding
2709 contextual information."
2710 (let* ((lang (org-element-property :language src-block))
2711 (caption (org-element-property :caption src-block))
2712 (label (org-element-property :name src-block))
2713 (caption-str (org-e-html--caption/label-string caption label info))
2714 (attr (mapconcat #'identity
2715 (org-element-property :attr_html src-block)
2716 " "))
2717 ;; (switches (org-element-property :switches src-block))
2718 (switches nil) ; FIXME
2719 (textarea-p (and switches (string-match "-t\\>" switches)))
2720 (code (org-e-html-format-code src-block info)))
2721 (cond
2722 (lang (format
2723 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2724 (if (not caption) ""
2725 (format "<label class=\"org-src-name\">%s</label>" caption-str))
2726 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code)))
2727 (textarea-p
2728 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
2729 80 (string-to-number (match-string 1 switches))))
2730 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
2731 (string-to-number (match-string 1 switches))
2732 (org-count-lines code))))
2733 (format
2734 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2735 cols rows code)))
2736 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
2738 ;;;; Statistics Cookie
2740 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
2741 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2742 CONTENTS is nil. INFO is a plist holding contextual information."
2743 (let ((cookie-value (org-element-property :value statistics-cookie)))
2744 (format "<code>%s</code>" cookie-value)))
2747 ;;;; Subscript
2749 (defun org-e-html-subscript (subscript contents info)
2750 "Transcode a SUBSCRIPT object from Org to HTML.
2751 CONTENTS is the contents of the object. INFO is a plist holding
2752 contextual information."
2753 (format "<sub>%s</sub>" contents))
2756 ;;;; Superscript
2758 (defun org-e-html-superscript (superscript contents info)
2759 "Transcode a SUPERSCRIPT object from Org to HTML.
2760 CONTENTS is the contents of the object. INFO is a plist holding
2761 contextual information."
2762 (format "<sup>%s</sup>" contents))
2765 ;;;; Tabel Cell
2767 (defun org-e-html-table-cell (table-cell contents info)
2768 "Transcode a TABLE-CELL element from Org to HTML.
2769 CONTENTS is nil. INFO is a plist used as a communication
2770 channel."
2771 (let* ((value (org-export-secondary-string
2772 (org-element-property :value table-cell) 'e-html info))
2773 (value (if (string= "" (org-trim value)) "&nbsp;" value))
2774 (table-row (org-export-get-parent table-cell info))
2775 (cell-attrs
2776 (if (not org-e-html-table-align-individual-fields) ""
2777 (format (if (and (boundp 'org-e-html-format-table-no-css)
2778 org-e-html-format-table-no-css)
2779 " align=\"%s\"" " class=\"%s\"")
2780 (org-export-table-cell-alignment table-cell info)))))
2781 (cond
2782 ((= 1 (org-export-table-row-group table-row info))
2783 (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
2784 value (cdr org-e-html-table-header-tags)))
2785 ((and org-e-html-table-use-header-tags-for-first-column
2786 (zerop (cdr (org-export-table-cell-address table-cell info))))
2787 (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
2788 value (cdr org-e-html-table-header-tags)))
2789 (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
2790 value (cdr org-e-html-table-data-tags))))))
2793 ;;;; Table Row
2795 (defun org-e-html-table-row (table-row contents info)
2796 "Transcode a TABLE-ROW element from Org to HTML.
2797 CONTENTS is the contents of the row. INFO is a plist used as a
2798 communication channel."
2799 ;; Rules are ignored since table separators are deduced from
2800 ;; borders of the current row.
2801 (when (eq (org-element-property :type table-row) 'standard)
2802 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2803 (rowgroup-tags
2804 (cond
2805 ;; Case 1: Row belongs to second or subsequent rowgroups.
2806 ((not (= 1 (org-export-table-row-group table-row info)))
2807 '("\n<tbody>" . "\n</tbody>"))
2808 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2809 ((org-export-table-has-header-p
2810 (org-export-get-parent-table table-row info) info)
2811 '("\n<thead>" . "\n</thead>"))
2812 ;; Case 2: Row is from first and only row group.
2813 (t '("\n<tbody>" . "\n</tbody>")))))
2814 (concat
2815 ;; Begin a rowgroup?
2816 (when (org-export-table-row-starts-rowgroup-p table-row info)
2817 (car rowgroup-tags))
2818 ;; Actual table row
2819 (concat "\n" (eval (car org-e-html-table-row-tags))
2820 contents (eval (cdr org-e-html-table-row-tags)))
2821 ;; End a rowgroup?
2822 (when (org-export-table-row-ends-rowgroup-p table-row info)
2823 (cdr rowgroup-tags))))))
2826 ;;;; Table
2828 (defun org-export-table-sample-row (table info)
2829 "A sample row from TABLE."
2830 (let ((table-row
2831 (org-element-map
2832 table 'table-row
2833 (lambda (row)
2834 (unless (eq (org-element-property :type row) 'rule) row))
2835 info 'first-match))
2836 (special-column-p (org-export-table-has-special-column-p table)))
2837 (if (not special-column-p) (org-element-contents table-row)
2838 (cdr (org-element-contents table-row)))))
2840 (defun org-e-html-table--table.el-table (table info)
2841 (when (eq (org-element-property :type table) 'table.el)
2842 (require 'table)
2843 (let ((outbuf (with-current-buffer
2844 (get-buffer-create "*org-export-table*")
2845 (erase-buffer) (current-buffer))))
2846 (with-temp-buffer
2847 (insert (org-element-property :value table))
2848 (goto-char 1)
2849 (re-search-forward "^[ \t]*|[^|]" nil t)
2850 (table-generate-source 'html outbuf))
2851 (with-current-buffer outbuf
2852 (prog1 (org-trim (buffer-string))
2853 (kill-buffer) )))))
2855 (defun org-e-html-table (table contents info)
2856 "Transcode a TABLE element from Org to HTML.
2857 CONTENTS is nil. INFO is a plist holding contextual information."
2858 (case (org-element-property :type table)
2859 ;; Case 1: table.el table. Convert it using appropriate tools.
2860 (table.el (org-e-html-table--table.el-table table info))
2861 ;; Case 2: Standard table.
2863 (let* ((label (org-element-property :name table))
2864 (caption (org-e-html--caption/label-string
2865 (org-element-property :caption table) label info))
2866 (attributes (mapconcat #'identity
2867 (org-element-property :attr_html table)
2868 " "))
2869 (alignspec
2870 (if (and (boundp 'org-e-html-format-table-no-css)
2871 org-e-html-format-table-no-css)
2872 "align=\"%s\"" "class=\"%s\""))
2873 (table-column-specs
2874 (function
2875 (lambda (table info)
2876 (mapconcat
2877 (lambda (table-cell)
2878 (let ((alignment (org-export-table-cell-alignment
2879 table-cell info)))
2880 (concat
2881 ;; Begin a colgroup?
2882 (when (org-export-table-cell-starts-colgroup-p
2883 table-cell info)
2884 "\n<colgroup>")
2885 ;; Add a column. Also specify it's alignment.
2886 (format "\n<col %s/>" (format alignspec alignment))
2887 ;; End a colgroup?
2888 (when (org-export-table-cell-ends-colgroup-p
2889 table-cell info)
2890 "\n</colgroup>"))))
2891 (org-export-table-sample-row table info) "\n"))))
2892 (table-attributes
2893 (let ((table-tag (plist-get info :html-table-tag)))
2894 (concat
2895 (and (string-match "<table\\(.*\\)>" table-tag)
2896 (match-string 1 table-tag))
2897 (and label (format " id=\"%s\""
2898 (org-solidify-link-text label)))))))
2899 ;; Remove last blank line.
2900 (setq contents (substring contents 0 -1))
2901 ;; FIXME: splice
2902 (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
2903 table-attributes
2904 (or caption "")
2905 (funcall table-column-specs table info)
2906 contents)))))
2908 ;;;; Target
2910 (defun org-e-html-target (target contents info)
2911 "Transcode a TARGET object from Org to HTML.
2912 CONTENTS is nil. INFO is a plist holding contextual
2913 information."
2914 (let ((id (org-export-solidify-link-text
2915 (org-element-property :value target))))
2916 (format "<a id=\"%s\" name=\"%s\"/>" id id)))
2919 ;;;; Time-stamp
2921 (defun org-e-html-time-stamp (time-stamp contents info)
2922 "Transcode a TIME-STAMP object from Org to HTML.
2923 CONTENTS is nil. INFO is a plist holding contextual
2924 information."
2925 (let ((value (org-element-property :value time-stamp))
2926 (type (org-element-property :type time-stamp))
2927 (appt-type (org-element-property :appt-type time-stamp)))
2928 (setq value (org-translate-time
2929 (org-export-secondary-string value 'e-html info)))
2930 (setq appt-type (case appt-type
2931 (scheduled org-scheduled-string)
2932 (deadline org-deadline-string)
2933 (closed org-closed-string)))
2934 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
2935 (if (not appt-type) ""
2936 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type))
2937 (format "<span class=\"timestamp\">%s</span>" value))))
2940 ;;;; Verbatim
2942 (defun org-e-html-verbatim (verbatim contents info)
2943 "Transcode a VERBATIM object from Org to HTML.
2944 CONTENTS is nil. INFO is a plist used as a communication
2945 channel."
2946 (org-e-html-emphasis
2947 verbatim (org-element-property :value verbatim) info))
2950 ;;;; Verse Block
2952 (defun org-e-html-verse-block (verse-block contents info)
2953 "Transcode a VERSE-BLOCK element from Org to HTML.
2954 CONTENTS is nil. INFO is a plist holding contextual information."
2955 ;; Replace each newline character with line break. Also replace
2956 ;; each blank line with a line break.
2957 (setq contents (replace-regexp-in-string
2958 "^ *\\\\\\\\$" "<br/>\n"
2959 (replace-regexp-in-string
2960 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
2961 (org-remove-indentation
2962 (org-export-secondary-string
2963 (org-element-property :value verse-block)
2964 'e-html info)))))
2965 ;; Replace each white space at beginning of a line with a
2966 ;; non-breaking space.
2967 (while (string-match "^[ \t]+" contents)
2968 (let* ((num-ws (length (match-string 0 contents)))
2969 (ws (let (out) (dotimes (i num-ws out)
2970 (setq out (concat out "&nbsp;"))))))
2971 (setq contents (replace-match ws nil t contents))))
2972 (org-e-html--wrap-label
2973 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
2978 ;;; Filter Functions
2980 ;;;; Filter Settings
2982 (defconst org-e-html-filters-alist
2983 '((:filter-final-output . org-e-html-final-function))
2984 "Alist between filters keywords and back-end specific filters.
2985 See `org-export-filters-alist' for more information.")
2988 ;;;; Filters
2990 (defun org-e-html-final-function (contents backend info)
2991 (if (not org-e-html-pretty-output) contents
2992 (with-temp-buffer
2993 (nxml-mode)
2994 (insert contents)
2995 (indent-region (point-min) (point-max))
2996 (buffer-substring-no-properties (point-min) (point-max)))))
2999 ;;; Interactive functions
3001 (defun org-e-html-export-to-html
3002 (&optional subtreep visible-only body-only ext-plist pub-dir)
3003 "Export current buffer to a HTML file.
3005 If narrowing is active in the current buffer, only export its
3006 narrowed part.
3008 If a region is active, export that region.
3010 When optional argument SUBTREEP is non-nil, export the sub-tree
3011 at point, extracting information from the headline properties
3012 first.
3014 When optional argument VISIBLE-ONLY is non-nil, don't export
3015 contents of hidden elements.
3017 When optional argument BODY-ONLY is non-nil, only write code
3018 between \"\\begin{document}\" and \"\\end{document}\".
3020 EXT-PLIST, when provided, is a property list with external
3021 parameters overriding Org default settings, but still inferior to
3022 file-local settings.
3024 When optional argument PUB-DIR is set, use it as the publishing
3025 directory.
3027 Return output file's name."
3028 (interactive)
3029 (setq debug-on-error t) ; FIXME
3030 (let* ((extension (concat "." org-e-html-extension))
3031 (file (org-export-output-file-name extension subtreep pub-dir)))
3032 (org-export-to-file
3033 'e-html file subtreep visible-only body-only ext-plist)))
3037 ;;; FIXMES, TODOS, FOR REVIEW etc
3039 ;;;; org-format-table-html
3040 ;;;; org-format-org-table-html
3041 ;;;; org-format-table-table-html
3042 ;;;; org-table-number-fraction
3043 ;;;; org-table-number-regexp
3044 ;;;; org-e-html-table-caption-above
3046 ;;;; org-whitespace
3047 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3048 ;;;; Remove display properties
3050 ;;;; org-e-html-with-timestamp
3051 ;;;; org-e-html-html-helper-timestamp
3053 ;;;; org-export-as-html-and-open
3054 ;;;; org-export-as-html-batch
3055 ;;;; org-export-as-html-to-buffer
3056 ;;;; org-replace-region-by-html
3057 ;;;; org-export-region-as-html
3058 ;;;; org-export-as-html
3060 ;;;; (org-export-directory :html opt-plist)
3061 ;;;; (plist-get opt-plist :html-extension)
3062 ;;;; org-e-html-toplevel-hlevel
3063 ;;;; org-e-html-special-string-regexps
3064 ;;;; org-e-html-coding-system
3065 ;;;; org-e-html-coding-system
3066 ;;;; org-e-html-inline-images
3067 ;;;; org-e-html-inline-image-extensions
3068 ;;;; org-e-html-protect-char-alist
3069 ;;;; org-e-html-table-use-header-tags-for-first-column
3070 ;;;; org-e-html-todo-kwd-class-prefix
3071 ;;;; org-e-html-tag-class-prefix
3072 ;;;; org-e-html-footnote-separator
3074 ;;;; org-export-preferred-target-alist
3075 ;;;; org-solidify-link-text
3076 ;;;; class for anchors
3077 ;;;; org-export-with-section-numbers, body-only
3078 ;;;; org-export-mark-todo-in-toc
3080 (provide 'org-e-html)
3081 ;;; org-e-html.el ends here