org-element: Verse blocks now contain objects
[org-mode/org-mode-NeilSmithlineMods.git] / contrib / lisp / org-e-html.el
blobd9350ff1afc4052d525785c0fdfb30d87b0e6e48
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 org-export-creator-string))
1581 (concat
1582 ;; begin postamble
1584 <div id=\"" (nth 2 org-e-html-divs) "\">"
1585 (cond
1586 ;; auto postamble
1587 ((eq (plist-get info :html-postamble) 'auto)
1588 (concat
1589 (when (plist-get info :time-stamp-file)
1590 (format "
1591 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
1592 (when (and (plist-get info :with-author) author)
1593 (format "
1594 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
1595 (when (and (plist-get info :with-email) email)
1596 (format "
1597 <p class=\"email\"> %s </p>" email))
1598 (when (plist-get info :with-creator)
1599 (format "
1600 <p class=\"creator\"> %s </p>" creator-info))
1601 html-validation-link "\n"))
1602 ;; postamble from a string
1603 ((stringp (plist-get info :html-postamble))
1604 (format-spec (plist-get info :html-postamble)
1605 `((?a . ,author) (?e . ,email)
1606 (?d . ,date) (?c . ,creator-info)
1607 (?v . ,html-validation-link))))
1609 ;; postamble from a function
1610 ((functionp (plist-get info :html-postamble))
1611 (with-temp-buffer
1612 (funcall (plist-get info :html-postamble))
1613 (buffer-string)))
1614 ;; default postamble
1616 (format-spec
1617 (or (cadr (assoc (nth 0 lang-words)
1618 org-e-html-postamble-format))
1619 (cadr (assoc "en" org-e-html-postamble-format)))
1620 `((?a . ,author) (?e . ,email)
1621 (?d . ,date) (?c . ,creator-info)
1622 (?v . ,html-validation-link)))))
1624 </div>")))
1625 ;; org-e-html-html-helper-timestamp
1628 (defun org-e-html-template (contents info)
1629 "Return complete document string after HTML conversion.
1630 CONTENTS is the transcoded contents string. RAW-DATA is the
1631 original parsed data. INFO is a plist holding export options."
1632 (concat
1633 (format
1634 (or (and (stringp org-e-html-xml-declaration)
1635 org-e-html-xml-declaration)
1636 (cdr (assoc (plist-get info :html-extension)
1637 org-e-html-xml-declaration))
1638 (cdr (assoc "html" org-e-html-xml-declaration))
1641 (or (and coding-system-for-write
1642 (fboundp 'coding-system-get)
1643 (coding-system-get coding-system-for-write
1644 'mime-charset))
1645 "iso-8859-1"))
1647 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1648 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1649 (format "
1650 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1651 (plist-get info :language) (plist-get info :language))
1653 <head>"
1654 (org-e-html-meta-info info) ; meta
1655 (org-e-html-style info) ; style
1656 (org-e-html-mathjax-config info) ; mathjax
1658 </head>"
1661 <body>"
1662 (let ((link-up (and (plist-get info :link-up)
1663 (string-match "\\S-" (plist-get info :link-up))
1664 (plist-get info :link-up)))
1665 (link-home (and (plist-get info :link-home)
1666 (string-match "\\S-" (plist-get info :link-home))
1667 (plist-get info :link-home))))
1668 (when (or link-up link-home)
1669 (format org-e-html-home/up-format
1670 (or link-up link-home)
1671 (or link-home link-up))))
1672 ;; preamble
1673 (org-e-html-preamble info)
1674 ;; begin content
1675 (format "
1676 <div id=\"%s\">" (or org-e-html-content-div
1677 (nth 1 org-e-html-divs)))
1678 ;; document title
1679 (format "
1680 <h1 class=\"title\">%s</h1>\n" (org-export-secondary-string
1681 (plist-get info :title) 'e-html info))
1682 ;; table of contents
1683 (let ((depth (plist-get info :with-toc)))
1684 (when (wholenump depth) (org-e-html-toc depth info)))
1685 ;; document contents
1686 contents
1687 ;; footnotes section
1688 (org-e-html-footnote-section info)
1689 ;; bibliography
1690 (org-e-html-bibliography)
1691 ;; end content
1692 (unless body-only
1694 </div>")
1696 ;; postamble
1697 (org-e-html-postamble info)
1699 (unless body-only
1701 </body>")
1703 </html>"))
1707 ;;; Transcode Helpers
1709 ;;;; Todo
1711 (defun org-e-html--todo (todo)
1712 (when todo
1713 (format "<span class=\"%s %s%s\">%s</span>"
1714 (if (member todo org-done-keywords) "done" "todo")
1715 org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
1716 todo)))
1718 ;;;; Tags
1720 (defun org-e-html--tags (tags)
1721 (when tags
1722 (format "<span class=\"tag\">%s</span>"
1723 (mapconcat
1724 (lambda (tag)
1725 (format "<span class=\"%s\">%s</span>"
1726 (concat org-e-html-tag-class-prefix
1727 (org-e-html-fix-class-name tag))
1728 tag))
1729 (org-split-string tags ":") "&nbsp;"))))
1731 ;;;; Headline
1733 (defun* org-e-html-format-headline
1734 (todo todo-type priority text tags
1735 &key level section-number headline-label &allow-other-keys)
1736 (let ((section-number
1737 (when section-number
1738 (format "<span class=\"section-number-%d\">%s</span> "
1739 level section-number)))
1740 (todo (org-e-html--todo todo))
1741 (tags (org-e-html--tags tags)))
1742 (concat section-number todo (and todo " ") text
1743 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1745 ;;;; Src Code
1747 (defun org-e-html-fontify-code (code lang)
1748 (when code
1749 (cond
1750 ;; Case 1: No lang. Possibly an example block.
1751 ((not lang)
1752 ;; Simple transcoding.
1753 (org-e-html-encode-plain-text code))
1754 ;; Case 2: No htmlize or an inferior version of htmlize
1755 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1756 ;; Emit a warning.
1757 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1758 ;; Simple transcoding.
1759 (org-e-html-encode-plain-text code))
1761 ;; Map language
1762 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1763 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1764 (cond
1765 ;; Case 1: Language is not associated with any Emacs mode
1766 ((not (functionp lang-mode))
1767 ;; Simple transcoding.
1768 (org-e-html-encode-plain-text code))
1769 ;; Case 2: Default. Fotify code.
1771 ;; htmlize
1772 (setq code (with-temp-buffer
1773 (insert code)
1774 (funcall lang-mode)
1775 (font-lock-fontify-buffer)
1776 ;; markup each line separately
1777 (org-remove-formatting-on-newlines-in-region
1778 (point-min) (point-max))
1779 (org-src-mode)
1780 (set-buffer-modified-p nil)
1781 (org-export-e-htmlize-region-for-paste
1782 (point-min) (point-max))))
1783 ;; Strip any encolosing <pre></pre> tags
1784 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1785 (match-string 1 code)
1786 code))))))))
1788 (defun org-e-html-do-format-code
1789 (code &optional lang refs retain-labels num-start textarea-p)
1790 (when textarea-p
1791 (setq num-start nil refs nil lang nil))
1792 (let* ((code-lines (org-split-string code "\n"))
1793 (code-length (length code-lines))
1794 (num-fmt
1795 (and num-start
1796 (format "%%%ds: "
1797 (length (number-to-string (+ code-length num-start))))))
1798 (code (org-e-html-fontify-code code lang)))
1799 (assert (= code-length (length (org-split-string code "\n"))))
1800 (org-export-format-code
1801 code
1802 (lambda (loc line-num ref)
1803 (setq loc
1804 (concat
1805 ;; Add line number, if needed.
1806 (when num-start
1807 (format "<span class=\"linenr\">%s</span>"
1808 (format num-fmt line-num)))
1809 ;; Transcoded src line.
1811 ;; Add label, if needed.
1812 (when (and ref retain-labels) (format " (%s)" ref))))
1813 ;; Mark transcoded line as an anchor, if needed.
1814 (if (not ref) loc
1815 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1816 ref loc)))
1817 num-start refs)))
1819 (defun org-e-html-format-code (element info)
1820 (let* ((lang (org-element-property :language element))
1821 ;; (switches (org-element-property :switches element))
1822 (switches nil) ; FIXME
1823 (textarea-p (and switches (string-match "-t\\>" switches)))
1824 ;; Extract code and references.
1825 (code-info (org-export-unravel-code element))
1826 (code (car code-info))
1827 (refs (cdr code-info))
1828 ;; Does the src block contain labels?
1829 (retain-labels (org-element-property :retain-labels element))
1830 ;; Does it have line numbers?
1831 (num-start (case (org-element-property :number-lines element)
1832 (continued (org-export-get-loc element info))
1833 (new 0))))
1834 (org-e-html-do-format-code
1835 code lang refs retain-labels num-start textarea-p)))
1839 ;;; Transcode Functions
1841 ;;;; Block
1843 (defun org-e-html-center-block (center-block contents info)
1844 "Transcode a CENTER-BLOCK element from Org to HTML.
1845 CONTENTS holds the contents of the block. INFO is a plist
1846 holding contextual information."
1847 (org-e-html--wrap-label
1848 center-block
1849 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
1852 ;;;; Comment
1854 ;; Comments are ignored.
1857 ;;;; Comment Block
1859 ;; Comment Blocks are ignored.
1862 ;;;; Drawer
1864 (defun org-e-html-drawer (drawer contents info)
1865 "Transcode a DRAWER element from Org to HTML.
1866 CONTENTS holds the contents of the block. INFO is a plist
1867 holding contextual information."
1868 (let* ((name (org-element-property :drawer-name drawer))
1869 (output (if (functionp org-e-html-format-drawer-function)
1870 (funcall org-e-html-format-drawer-function
1871 name contents)
1872 ;; If there's no user defined function: simply
1873 ;; display contents of the drawer.
1874 contents)))
1875 (org-e-html--wrap-label drawer output)))
1878 ;;;; Dynamic Block
1880 (defun org-e-html-dynamic-block (dynamic-block contents info)
1881 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1882 CONTENTS holds the contents of the block. INFO is a plist
1883 holding contextual information. See
1884 `org-export-data'."
1885 (org-e-html--wrap-label dynamic-block contents))
1888 ;;;; Emphasis
1890 (defun org-e-html-emphasis (emphasis contents info)
1891 "Transcode EMPHASIS from Org to HTML.
1892 CONTENTS is the contents of the emphasized text. INFO is a plist
1893 holding contextual information.."
1894 (let* ((marker (org-element-property :marker emphasis)))
1895 (format (cdr (assoc marker org-e-html-emphasis-alist)) contents)))
1898 ;;;; Entity
1900 (defun org-e-html-entity (entity contents info)
1901 "Transcode an ENTITY object from Org to HTML.
1902 CONTENTS are the definition itself. INFO is a plist holding
1903 contextual information."
1904 (org-element-property :html entity))
1907 ;;;; Example Block
1909 (defun org-e-html-example-block (example-block contents info)
1910 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1911 CONTENTS is nil. INFO is a plist holding contextual information."
1912 (let* ((options (or (org-element-property :options example-block) ""))
1913 (lang (org-element-property :language example-block))
1914 (caption (org-element-property :caption example-block))
1915 (label (org-element-property :name example-block))
1916 (caption-str (org-e-html--caption/label-string caption label info))
1917 (attr (mapconcat #'identity
1918 (org-element-property :attr_html example-block)
1919 " "))
1920 ;; (switches (org-element-property :switches example-block))
1921 (switches nil) ; FIXME
1922 (textarea-p (and switches (string-match "-t\\>" switches)))
1923 (code (org-e-html-format-code example-block info)))
1924 (cond
1925 (textarea-p
1926 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
1927 80 (string-to-number (match-string 1 switches))))
1928 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
1929 (string-to-number (match-string 1 switches))
1930 (org-count-lines code))))
1931 (format
1932 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1933 cols rows code)))
1934 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
1937 ;;;; Export Snippet
1939 (defun org-e-html-export-snippet (export-snippet contents info)
1940 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1941 CONTENTS is nil. INFO is a plist holding contextual information."
1942 (when (eq (org-export-snippet-backend export-snippet) 'e-html)
1943 (org-element-property :value export-snippet)))
1946 ;;;; Export Block
1948 (defun org-e-html-export-block (export-block contents info)
1949 "Transcode a EXPORT-BLOCK element from Org to HTML.
1950 CONTENTS is nil. INFO is a plist holding contextual information."
1951 (when (string= (org-element-property :type export-block) "latex")
1952 (org-remove-indentation (org-element-property :value export-block))))
1955 ;;;; Fixed Width
1957 (defun org-e-html-fixed-width (fixed-width contents info)
1958 "Transcode a FIXED-WIDTH element from Org to HTML.
1959 CONTENTS is nil. INFO is a plist holding contextual information."
1960 (let* ((value (org-element-normalize-string
1961 (replace-regexp-in-string
1962 "^[ \t]*: ?" ""
1963 (org-element-property :value fixed-width)))))
1964 (org-e-html--wrap-label
1965 fixed-width (format "\n<pre class=\"example\">\n%s\n</pre>"
1966 (org-e-html-do-format-code value)))))
1969 ;;;; Footnote Definition
1971 ;; Footnote Definitions are ignored.
1974 ;;;; Footnote Reference
1976 (defun org-e-html-footnote-reference (footnote-reference contents info)
1977 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1978 CONTENTS is nil. INFO is a plist holding contextual information."
1979 (concat
1980 ;; Insert separator between two footnotes in a row.
1981 (let ((prev (org-export-get-previous-element footnote-reference info)))
1982 (when (eq (org-element-type prev) 'footnote-reference)
1983 org-e-html-footnote-separator))
1984 (cond
1985 ((not (org-export-footnote-first-reference-p footnote-reference info))
1986 (org-e-html-format-footnote-reference
1987 (org-export-get-footnote-number footnote-reference info)
1988 "IGNORED" 100))
1989 ;; Inline definitions are secondary strings.
1990 ((eq (org-element-property :type footnote-reference) 'inline)
1991 (org-e-html-format-footnote-reference
1992 (org-export-get-footnote-number footnote-reference info)
1993 "IGNORED" 1))
1994 ;; Non-inline footnotes definitions are full Org data.
1995 (t (org-e-html-format-footnote-reference
1996 (org-export-get-footnote-number footnote-reference info)
1997 "IGNORED" 1)))))
2000 ;;;; Headline
2002 (defun org-e-html-format-headline--wrap (headline info
2003 &optional format-function
2004 &rest extra-keys)
2005 "Transcode an HEADLINE element from Org to HTML.
2006 CONTENTS holds the contents of the headline. INFO is a plist
2007 holding contextual information."
2008 (let* ((level (+ (org-export-get-relative-level headline info)
2009 (1- org-e-html-toplevel-hlevel)))
2010 (headline-number (org-export-get-headline-number headline info))
2011 (section-number (and (org-export-numbered-headline-p headline info)
2012 (mapconcat 'number-to-string
2013 headline-number ".")))
2014 (todo (and (plist-get info :with-todo-keywords)
2015 (let ((todo (org-element-property
2016 :todo-keyword headline)))
2017 (and todo
2018 (org-export-secondary-string todo 'e-html info)))))
2019 (todo-type (and todo (org-element-property :todo-type headline)))
2020 (priority (and (plist-get info :with-priority)
2021 (org-element-property :priority headline)))
2022 (text (org-export-secondary-string
2023 (org-element-property :title headline) 'e-html info))
2024 (tags (and (plist-get info :with-tags)
2025 (org-element-property :tags headline)))
2026 (headline-label (concat "sec-" (mapconcat 'number-to-string
2027 headline-number "-")))
2028 (format-function (cond
2029 ((functionp format-function) format-function)
2030 ((functionp org-e-html-format-headline-function)
2031 (function*
2032 (lambda (todo todo-type priority text tags
2033 &allow-other-keys)
2034 (funcall org-e-html-format-headline-function
2035 todo todo-type priority text tags))))
2036 (t 'org-e-html-format-headline))))
2037 (apply format-function
2038 todo todo-type priority text tags
2039 :headline-label headline-label :level level
2040 :section-number section-number extra-keys)))
2042 (defun org-e-html-headline (headline contents info)
2043 "Transcode an HEADLINE element from Org to HTML.
2044 CONTENTS holds the contents of the headline. INFO is a plist
2045 holding contextual information."
2046 (let* ((numberedp (org-export-numbered-headline-p headline info))
2047 (level (org-export-get-relative-level headline info))
2048 (text (org-export-secondary-string
2049 (org-element-property :title headline) 'e-html info))
2050 (todo (and (plist-get info :with-todo-keywords)
2051 (let ((todo (org-element-property
2052 :todo-keyword headline)))
2053 (and todo
2054 (org-export-secondary-string todo 'e-html info)))))
2055 (todo-type (and todo (org-element-property :todo-type headline)))
2056 (tags (and (plist-get info :with-tags)
2057 (org-element-property :tags headline)))
2058 (priority (and (plist-get info :with-priority)
2059 (org-element-property :priority headline)))
2060 (section-number (and (org-export-numbered-headline-p headline info)
2061 (mapconcat 'number-to-string
2062 (org-export-get-headline-number
2063 headline info) ".")))
2064 ;; Create the headline text.
2065 (full-text (org-e-html-format-headline--wrap headline info)))
2066 (cond
2067 ;; Case 1: This is a footnote section: ignore it.
2068 ((org-element-property :footnote-section-p headline) nil)
2069 ;; Case 2. This is a deep sub-tree: export it as a list item.
2070 ;; Also export as items headlines for which no section
2071 ;; format has been found.
2072 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
2073 ;; Build the real contents of the sub-tree.
2074 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
2075 (itemized-body (org-e-html-format-list-item
2076 contents type nil nil full-text)))
2077 (concat
2078 (and (org-export-first-sibling-p headline info)
2079 (org-e-html-begin-plain-list type))
2080 itemized-body
2081 (and (org-export-last-sibling-p headline info)
2082 (org-e-html-end-plain-list type)))))
2083 ;; Case 3. Standard headline. Export it as a section.
2085 (let* ((extra-class (org-element-property :html-container-class headline))
2086 (extra-ids (list (org-element-property :custom-id headline)
2087 (org-element-property :id headline)))
2088 (extra-ids
2089 (mapconcat
2090 (lambda (x)
2091 (when x
2092 (let ((id (org-solidify-link-text
2093 (if (org-uuidgen-p x) (concat "ID-" x) x))))
2094 (format "<a id=\"%s\" name=\"%s\"/>" id id))))
2095 extra-ids ""))
2096 (level1 (+ level (1- org-e-html-toplevel-hlevel)))
2097 (id (mapconcat 'number-to-string
2098 (org-export-get-headline-number headline info) "-")))
2099 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2100 (format "outline-container-%s" id)
2101 (concat (format "outline-%d" level1) (and extra-class " ")
2102 extra-class)
2103 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2104 level1 id extra-ids full-text level1)
2105 contents))))))
2108 ;;;; Horizontal Rule
2110 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
2111 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2112 CONTENTS is nil. INFO is a plist holding contextual information."
2113 (let ((attr (mapconcat #'identity
2114 (org-element-property :attr_html horizontal-rule)
2115 " ")))
2116 (org-e-html--wrap-label horizontal-rule "<hr/>\n")))
2119 ;;;; Inline Babel Call
2121 ;; Inline Babel Calls are ignored.
2124 ;;;; Inline Src Block
2126 (defun org-e-html-inline-src-block (inline-src-block contents info)
2127 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2128 CONTENTS holds the contents of the item. INFO is a plist holding
2129 contextual information."
2130 (let* ((org-lang (org-element-property :language inline-src-block))
2131 (code (org-element-property :value inline-src-block))
2132 (separator (org-e-html--find-verb-separator code)))
2133 (error "FIXME")))
2136 ;;;; Inlinetask
2138 (defun org-e-html-format-section (text class &optional id)
2139 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2140 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2142 (defun org-e-html-inlinetask (inlinetask contents info)
2143 "Transcode an INLINETASK element from Org to HTML.
2144 CONTENTS holds the contents of the block. INFO is a plist
2145 holding contextual information."
2146 (cond
2147 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2148 ;; with appropriate arguments.
2149 ((functionp org-e-html-format-inlinetask-function)
2150 (let ((format-function
2151 (function*
2152 (lambda (todo todo-type priority text tags
2153 &key contents &allow-other-keys)
2154 (funcall org-e-html-format-inlinetask-function
2155 todo todo-type priority text tags contents)))))
2156 (org-e-html-format-headline--wrap
2157 inlinetask info format-function :contents contents)))
2158 ;; Otherwise, use a default template.
2159 (t (org-e-html--wrap-label
2160 inlinetask
2161 (format
2162 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2163 (org-e-html-format-headline--wrap inlinetask info)
2164 contents)))))
2167 ;;;; Item
2169 (defun org-e-html-checkbox (checkbox)
2170 (case checkbox (on "<code>[X]</code>")
2171 (off "<code>[&nbsp;]</code>")
2172 (trans "<code>[-]</code>")
2173 (t "")))
2175 (defun org-e-html-format-list-item (contents type checkbox
2176 &optional term-counter-id
2177 headline)
2178 (concat
2179 (case type
2180 (ordered
2181 (let* ((counter term-counter-id)
2182 (extra (if counter (format " value=\"%s\"" counter) "")))
2183 (format "<li%s>" extra)))
2184 (unordered
2185 (let* ((id term-counter-id)
2186 (extra (if id (format " id=\"%s\"" id) "")))
2187 (concat
2188 (format "<li%s>" extra)
2189 (when headline (concat headline "<br/>")))))
2190 (descriptive
2191 (let* ((term term-counter-id))
2192 (setq term (or term "(no term)"))
2193 (concat (format "<dt> %s </dt>" term) "<dd>"))))
2194 (org-e-html-checkbox checkbox) (and checkbox " ")
2195 contents
2196 (case type
2197 (ordered "</li>")
2198 (unordered "</li>")
2199 (descriptive "</dd>"))))
2201 (defun org-e-html-item (item contents info)
2202 "Transcode an ITEM element from Org to HTML.
2203 CONTENTS holds the contents of the item. INFO is a plist holding
2204 contextual information."
2205 ;; Grab `:level' from plain-list properties, which is always the
2206 ;; first element above current item.
2207 (let* ((plain-list (org-export-get-parent item info))
2208 (type (org-element-property :type plain-list))
2209 (level (org-element-property :level plain-list))
2210 (counter (org-element-property :counter item))
2211 (checkbox (org-element-property :checkbox item))
2212 (tag (let ((tag (org-element-property :tag item)))
2213 (and tag (org-export-secondary-string tag 'e-html info)))))
2214 (org-e-html-format-list-item
2215 contents type checkbox (or tag counter))))
2218 ;;;; Keyword
2220 (defun org-e-html-keyword (keyword contents info)
2221 "Transcode a KEYWORD element from Org to HTML.
2222 CONTENTS is nil. INFO is a plist holding contextual information."
2223 (let ((key (org-element-property :key keyword))
2224 (value (org-element-property :value keyword)))
2225 (cond
2226 ((string= key "LATEX") value)
2227 ((string= key "INDEX") (format "\\index{%s}" value))
2228 ;; Invisible targets.
2229 ((string= key "TARGET") nil) ; FIXME
2230 ((string= key "TOC")
2231 (let ((value (downcase value)))
2232 (cond
2233 ((string-match "\\<headlines\\>" value)
2234 (let ((depth (or (and (string-match "[0-9]+" value)
2235 (string-to-number (match-string 0 value)))
2236 (plist-get info :with-toc))))
2237 (when (wholenump depth) (org-e-html-toc depth info))))
2238 ((string= "tables" value) "\\listoftables")
2239 ((string= "figures" value) "\\listoffigures")
2240 ((string= "listings" value)
2241 (cond
2242 ;; At the moment, src blocks with a caption are wrapped
2243 ;; into a figure environment.
2244 (t "\\listoffigures")))))))))
2247 ;;;; Latex Environment
2249 (defun org-e-html-format-latex (latex-frag processing-type)
2250 (let* ((cache-relpath
2251 (concat "ltxpng/" (file-name-sans-extension
2252 (file-name-nondirectory (buffer-file-name)))))
2253 (cache-dir (file-name-directory (buffer-file-name )))
2254 (display-msg "Creating LaTeX Image..."))
2256 (with-temp-buffer
2257 (insert latex-frag)
2258 (org-format-latex cache-relpath cache-dir nil display-msg
2259 nil nil processing-type)
2260 (buffer-string))))
2262 (defun org-e-html-latex-environment (latex-environment contents info)
2263 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2264 CONTENTS is nil. INFO is a plist holding contextual information."
2265 (org-e-html--wrap-label
2266 latex-environment
2267 (let ((processing-type (plist-get info :LaTeX-fragments))
2268 (latex-frag (org-remove-indentation
2269 (org-element-property :value latex-environment)))
2270 (caption (org-e-html--caption/label-string
2271 (org-element-property :caption latex-environment)
2272 (org-element-property :name latex-environment)
2273 info))
2274 (attr nil) ; FIXME
2275 (label (org-element-property :name latex-environment)))
2276 (cond
2277 ((member processing-type '(t mathjax))
2278 (org-e-html-format-latex latex-frag 'mathjax))
2279 ((equal processing-type 'dvipng)
2280 (let* ((formula-link (org-e-html-format-latex
2281 latex-frag processing-type)))
2282 (when (and formula-link
2283 (string-match "file:\\([^]]*\\)" formula-link))
2284 (org-e-html-format-inline-image
2285 (match-string 1 formula-link) caption label attr t))))
2286 (t latex-frag)))))
2289 ;;;; Latex Fragment
2291 (defun org-e-html-latex-fragment (latex-fragment contents info)
2292 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2293 CONTENTS is nil. INFO is a plist holding contextual information."
2294 (let ((latex-frag (org-element-property :value latex-fragment))
2295 (processing-type (plist-get info :LaTeX-fragments)))
2296 (case processing-type
2297 ((t mathjax)
2298 (org-e-html-format-latex latex-frag 'mathjax))
2299 (dvipng
2300 (let* ((formula-link (org-e-html-format-latex
2301 latex-frag processing-type)))
2302 (when (and formula-link
2303 (string-match "file:\\([^]]*\\)" formula-link))
2304 (org-e-html-format-inline-image
2305 (match-string 1 formula-link)))))
2306 (t latex-frag))))
2308 ;;;; Line Break
2310 (defun org-e-html-line-break (line-break contents info)
2311 "Transcode a LINE-BREAK object from Org to HTML.
2312 CONTENTS is nil. INFO is a plist holding contextual information."
2313 "<br/>")
2316 ;;;; Link
2318 (defun org-e-html-link--inline-image (link desc info)
2319 "Return HTML code for an inline image.
2320 LINK is the link pointing to the inline image. INFO is a plist
2321 used as a communication channel."
2322 (let* ((type (org-element-property :type link))
2323 (raw-path (org-element-property :path link))
2324 (path (cond ((member type '("http" "https"))
2325 (concat type ":" raw-path))
2326 ((file-name-absolute-p raw-path)
2327 (expand-file-name raw-path))
2328 (t raw-path)))
2329 (parent (org-export-get-parent-paragraph link info))
2330 (caption (org-e-html--caption/label-string
2331 (org-element-property :caption parent)
2332 (org-element-property :name parent)
2333 info))
2334 (label (org-element-property :name parent))
2335 ;; Retrieve latex attributes from the element around.
2336 (attr (let ((raw-attr
2337 (mapconcat #'identity
2338 (org-element-property :attr_html parent)
2339 " ")))
2340 (unless (string= raw-attr "") raw-attr))))
2341 ;; Now clear ATTR from any special keyword and set a default
2342 ;; value if nothing is left.
2343 (setq attr (if (not attr) "" (org-trim attr)))
2344 ;; Return proper string, depending on DISPOSITION.
2345 (org-e-html-format-inline-image
2346 path caption label attr (org-e-html-standalone-image-p link info))))
2348 (defvar org-e-html-standalone-image-predicate)
2349 (defun org-e-html-standalone-image-p (element info &optional predicate)
2350 "Test if ELEMENT is a standalone image for the purpose HTML export.
2351 INFO is a plist holding contextual information.
2353 Return non-nil, if ELEMENT is of type paragraph and it's sole
2354 content, save for whitespaces, is a link that qualifies as an
2355 inline image.
2357 Return non-nil, if ELEMENT is of type link and it's containing
2358 paragraph has no other content save for leading and trailing
2359 whitespaces.
2361 Return nil, otherwise.
2363 Bind `org-e-html-standalone-image-predicate' to constrain
2364 paragraph further. For example, to check for only captioned
2365 standalone images, do the following.
2367 \(setq org-e-html-standalone-image-predicate
2368 \(lambda \(paragraph\)
2369 \(org-element-property :caption paragraph\)\)\)
2371 (let ((paragraph (case (org-element-type element)
2372 (paragraph element)
2373 (link (and (org-export-inline-image-p
2374 element org-e-html-inline-image-rules)
2375 (org-export-get-parent element info)))
2376 (t nil))))
2377 (when paragraph
2378 (assert (eq (org-element-type paragraph) 'paragraph))
2379 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
2380 (functionp org-e-html-standalone-image-predicate)))
2381 (funcall org-e-html-standalone-image-predicate paragraph))
2382 (let ((contents (org-element-contents paragraph)))
2383 (loop for x in contents
2384 with inline-image-count = 0
2385 always (cond
2386 ((eq (org-element-type x) 'plain-text)
2387 (not (org-string-nw-p x)))
2388 ((eq (org-element-type x) 'link)
2389 (when (org-export-inline-image-p
2390 x org-e-html-inline-image-rules)
2391 (= (incf inline-image-count) 1)))
2392 (t nil))))))))
2394 (defun org-e-html-link (link desc info)
2395 "Transcode a LINK object from Org to HTML.
2397 DESC is the description part of the link, or the empty string.
2398 INFO is a plist holding contextual information. See
2399 `org-export-data'."
2400 (let* ((type (org-element-property :type link))
2401 (raw-path (org-element-property :path link))
2402 ;; Ensure DESC really exists, or set it to nil.
2403 (desc (and (not (string= desc "")) desc))
2404 (path (cond
2405 ((member type '("http" "https" "ftp" "mailto"))
2406 (concat type ":" raw-path))
2407 ((string= type "file")
2408 (when (string-match "\\(.+\\)::.+" raw-path)
2409 (setq raw-path (match-string 1 raw-path)))
2410 (if (file-name-absolute-p raw-path)
2411 (concat "file://" (expand-file-name raw-path))
2412 ;; TODO: Not implemented yet. Concat also:
2413 ;; (org-export-directory :HTML info)
2414 (concat "file://" raw-path)))
2415 (t raw-path)))
2416 protocol)
2417 (cond
2418 ;; Image file.
2419 ((and (or (eq t org-e-html-inline-images)
2420 (and org-e-html-inline-images (not desc)))
2421 (org-export-inline-image-p link org-e-html-inline-image-rules))
2422 (org-e-html-link--inline-image link desc info))
2423 ;; Radioed target: Target's name is obtained from original raw
2424 ;; link. Path is parsed and transcoded in order to have a proper
2425 ;; display of the contents.
2426 ((string= type "radio")
2427 (format "<a href=\"#%s\">%s</a>"
2428 (org-export-solidify-link-text path)
2429 (org-export-secondary-string
2430 (org-element-parse-secondary-string
2431 path (org-element-restriction 'radio-target))
2432 'e-html info)))
2433 ;; Links pointing to an headline: Find destination and build
2434 ;; appropriate referencing command.
2435 ((member type '("custom-id" "fuzzy" "id"))
2436 (let ((destination (if (string= type "fuzzy")
2437 (org-export-resolve-fuzzy-link link info)
2438 (org-export-resolve-id-link link info))))
2439 (case (org-element-type destination)
2440 ;; Fuzzy link points nowhere.
2441 ('nil
2442 (format "<i>%s</i>"
2443 (or desc (org-export-secondary-string
2444 (org-element-property :raw-link link)
2445 'e-html info))))
2446 ;; Fuzzy link points to an invisible target.
2447 (keyword nil)
2448 ;; LINK points to an headline. If headlines are numbered
2449 ;; and the link has no description, display headline's
2450 ;; number. Otherwise, display description or headline's
2451 ;; title.
2452 (headline
2453 (let* ((headline-no (org-export-get-headline-number destination info))
2454 (label (format "sec-%s" (mapconcat 'number-to-string
2455 headline-no "-")))
2456 (section-no (mapconcat 'number-to-string headline-no ".")))
2457 (setq desc
2458 (cond
2459 (desc desc)
2460 ((plist-get info :section-numbers) section-no)
2461 (t (org-export-secondary-string
2462 (org-element-property :title destination)
2463 'e-html info))))
2464 (format "<a href=\"#%s\">%s</a>" label desc)))
2465 ;; Fuzzy link points to a target. Do as above.
2466 (otherwise
2467 (let ((path (org-export-solidify-link-text path)) number)
2468 (unless desc
2469 (setq number (cond
2470 ((org-e-html-standalone-image-p destination info)
2471 (org-export-get-ordinal
2472 (assoc 'link (org-element-contents destination))
2473 info 'link 'org-e-html-standalone-image-p))
2474 (t (org-export-get-ordinal destination info))))
2475 (setq desc (when number
2476 (if (atom number) (number-to-string number)
2477 (mapconcat 'number-to-string number ".")))))
2478 (format "<a href=\"#%s\">%s</a>" path (or desc "FIXME")))))))
2479 ;; Coderef: replace link with the reference name or the
2480 ;; equivalent line number.
2481 ((string= type "coderef")
2482 (let ((fragment (concat "coderef-" path)))
2483 (format "<a href=\"#%s\" %s>%s</a>" fragment
2484 (format (concat "class=\"coderef\""
2485 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2486 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2487 fragment fragment)
2488 (format (org-export-get-coderef-format path desc)
2489 (org-export-resolve-coderef path info)))))
2490 ;; Link type is handled by a special function.
2491 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2492 (funcall protocol (org-link-unescape path) desc 'html))
2493 ;; External link with a description part.
2494 ((and path desc) (format "<a href=\"%s\">%s</a>" path desc))
2495 ;; External link without a description part.
2496 (path (format "<a href=\"%s\">%s</a>" path path))
2497 ;; No path, only description. Try to do something useful.
2498 (t (format "<i>%s</i>" desc)))))
2501 ;;;; Babel Call
2503 ;; Babel Calls are ignored.
2506 ;;;; Macro
2508 (defun org-e-html-macro (macro contents info)
2509 "Transcode a MACRO element from Org to HTML.
2510 CONTENTS is nil. INFO is a plist holding contextual information."
2511 ;; Use available tools.
2512 (org-export-expand-macro macro info))
2515 ;;;; Paragraph
2517 (defun org-e-html-paragraph (paragraph contents info)
2518 "Transcode a PARAGRAPH element from Org to HTML.
2519 CONTENTS is the contents of the paragraph, as a string. INFO is
2520 the plist used as a communication channel."
2521 (let* ((style nil) ; FIXME
2522 (class (cdr (assoc style '((footnote . "footnote")
2523 (verse . nil)))))
2524 (extra (if class (format " class=\"%s\"" class) ""))
2525 (parent (org-export-get-parent paragraph info)))
2526 (cond
2527 ((and (equal (car parent) 'item)
2528 (= (org-element-property :begin paragraph)
2529 (org-element-property :contents-begin parent)))
2530 ;; leading paragraph in a list item have no tags
2531 contents)
2532 ((org-e-html-standalone-image-p paragraph info)
2533 ;; standalone image
2534 contents)
2535 (t (format "\n<p%s>\n%s\n</p>" extra contents)))))
2538 ;;;; Plain List
2540 (defun org-e-html-begin-plain-list (type &optional arg1)
2541 (case type
2542 (ordered
2543 (format "<ol%s>" (if arg1 ; FIXME
2544 (format " start=\"%d\"" arg1)
2545 "")))
2546 (unordered "<ul>")
2547 (descriptive "<dl>")))
2549 (defun org-e-html-end-plain-list (type)
2550 (case type
2551 (ordered "</ol>")
2552 (unordered "</ul>")
2553 (descriptive "</dl>")))
2555 (defun org-e-html-plain-list (plain-list contents info)
2556 "Transcode a PLAIN-LIST element from Org to HTML.
2557 CONTENTS is the contents of the list. INFO is a plist holding
2558 contextual information."
2559 (let* (arg1 ;; FIXME
2560 (type (org-element-property :type plain-list))
2561 (attr (mapconcat #'identity
2562 (org-element-property :attr_html plain-list)
2563 " ")))
2564 (org-e-html--wrap-label
2565 plain-list (format "%s\n%s%s"
2566 (org-e-html-begin-plain-list type)
2567 contents (org-e-html-end-plain-list type)))))
2569 ;;;; Plain Text
2571 (defun org-e-html-convert-special-strings (string)
2572 "Convert special characters in STRING to HTML."
2573 (let ((all org-e-html-special-string-regexps)
2574 e a re rpl start)
2575 (while (setq a (pop all))
2576 (setq re (car a) rpl (cdr a) start 0)
2577 (while (string-match re string start)
2578 (setq string (replace-match rpl t nil string))))
2579 string))
2581 (defun org-e-html-encode-plain-text (s)
2582 "Convert plain text characters to HTML equivalent.
2583 Possible conversions are set in `org-export-html-protect-char-alist'."
2584 (let ((cl org-e-html-protect-char-alist) c)
2585 (while (setq c (pop cl))
2586 (let ((start 0))
2587 (while (string-match (car c) s start)
2588 (setq s (replace-match (cdr c) t t s)
2589 start (1+ (match-beginning 0))))))
2592 (defun org-e-html-plain-text (text info)
2593 "Transcode a TEXT string from Org to HTML.
2594 TEXT is the string to transcode. INFO is a plist holding
2595 contextual information."
2596 (setq text (org-e-html-encode-plain-text text))
2597 ;; Protect %, #, &, $, ~, ^, _, { and }.
2598 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2599 ;; (setq text
2600 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2601 ;; Protect \
2602 ;; (setq text (replace-regexp-in-string
2603 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2604 ;; "$\\backslash$" text nil t 1))
2605 ;; HTML into \HTML{} and TeX into \TeX{}.
2606 ;; (let ((case-fold-search nil)
2607 ;; (start 0))
2608 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2609 ;; (setq text (replace-match
2610 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2611 ;; start (match-end 0))))
2612 ;; Handle quotation marks
2613 ;; (setq text (org-e-html--quotation-marks text info))
2614 ;; Convert special strings.
2615 ;; (when (plist-get info :with-special-strings)
2616 ;; (while (string-match (regexp-quote "...") text)
2617 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2618 (when (plist-get info :with-special-strings)
2619 (setq text (org-e-html-convert-special-strings text)))
2620 ;; Handle break preservation if required.
2621 (when (plist-get info :preserve-breaks)
2622 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2623 text)))
2624 ;; Return value.
2625 text)
2628 ;;;; Property Drawer
2630 (defun org-e-html-property-drawer (property-drawer contents info)
2631 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2632 CONTENTS is nil. INFO is a plist holding contextual
2633 information."
2634 ;; The property drawer isn't exported but we want separating blank
2635 ;; lines nonetheless.
2639 ;;;; Quote Block
2641 (defun org-e-html-quote-block (quote-block contents info)
2642 "Transcode a QUOTE-BLOCK element from Org to HTML.
2643 CONTENTS holds the contents of the block. INFO is a plist
2644 holding contextual information."
2645 (org-e-html--wrap-label
2646 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2649 ;;;; Quote Section
2651 (defun org-e-html-quote-section (quote-section contents info)
2652 "Transcode a QUOTE-SECTION element from Org to HTML.
2653 CONTENTS is nil. INFO is a plist holding contextual information."
2654 (let ((value (org-remove-indentation
2655 (org-element-property :value quote-section))))
2656 (when value (format "<pre>\n%s</pre>" value))))
2659 ;;;; Section
2661 (defun org-e-html-section (section contents info) ; FIXME
2662 "Transcode a SECTION element from Org to HTML.
2663 CONTENTS holds the contents of the section. INFO is a plist
2664 holding contextual information."
2665 (let ((parent (org-export-get-parent-headline section info)))
2666 ;; Before first headline: no container, just return CONTENTS.
2667 (if (not parent) contents
2668 ;; Get div's class and id references.
2669 (let ((class-num (+ (org-export-get-relative-level parent info)
2670 (1- org-e-html-toplevel-hlevel)))
2671 (id-num
2672 (mapconcat
2673 'number-to-string
2674 (org-export-get-headline-number parent info) "-")))
2675 ;; Build return value.
2676 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2677 class-num id-num contents)))))
2679 ;;;; Radio Target
2681 (defun org-e-html-radio-target (radio-target text info)
2682 "Transcode a RADIO-TARGET object from Org to HTML.
2683 TEXT is the text of the target. INFO is a plist holding
2684 contextual information."
2685 (let ((id (org-export-solidify-link-text
2686 (org-element-property :value radio-target))))
2687 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
2690 ;;;; Special Block
2692 (defun org-e-html-special-block (special-block contents info)
2693 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2694 CONTENTS holds the contents of the block. INFO is a plist
2695 holding contextual information."
2696 (let ((type (downcase (org-element-property :type special-block))))
2697 (org-e-html--wrap-label
2698 special-block
2699 (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
2702 ;;;; Src Block
2704 (defun org-e-html-src-block (src-block contents info)
2705 "Transcode a SRC-BLOCK element from Org to HTML.
2706 CONTENTS holds the contents of the item. INFO is a plist holding
2707 contextual information."
2708 (let* ((lang (org-element-property :language src-block))
2709 (caption (org-element-property :caption src-block))
2710 (label (org-element-property :name src-block))
2711 (caption-str (org-e-html--caption/label-string caption label info))
2712 (attr (mapconcat #'identity
2713 (org-element-property :attr_html src-block)
2714 " "))
2715 ;; (switches (org-element-property :switches src-block))
2716 (switches nil) ; FIXME
2717 (textarea-p (and switches (string-match "-t\\>" switches)))
2718 (code (org-e-html-format-code src-block info)))
2719 (cond
2720 (lang (format
2721 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2722 (if (not caption) ""
2723 (format "<label class=\"org-src-name\">%s</label>" caption-str))
2724 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code)))
2725 (textarea-p
2726 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
2727 80 (string-to-number (match-string 1 switches))))
2728 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
2729 (string-to-number (match-string 1 switches))
2730 (org-count-lines code))))
2731 (format
2732 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2733 cols rows code)))
2734 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
2736 ;;;; Statistics Cookie
2738 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
2739 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2740 CONTENTS is nil. INFO is a plist holding contextual information."
2741 (let ((cookie-value (org-element-property :value statistics-cookie)))
2742 (format "<code>%s</code>" cookie-value)))
2745 ;;;; Subscript
2747 (defun org-e-html-subscript (subscript contents info)
2748 "Transcode a SUBSCRIPT object from Org to HTML.
2749 CONTENTS is the contents of the object. INFO is a plist holding
2750 contextual information."
2751 (format "<sub>%s</sub>" contents))
2754 ;;;; Superscript
2756 (defun org-e-html-superscript (superscript contents info)
2757 "Transcode a SUPERSCRIPT object from Org to HTML.
2758 CONTENTS is the contents of the object. INFO is a plist holding
2759 contextual information."
2760 (format "<sup>%s</sup>" contents))
2763 ;;;; Tabel Cell
2765 (defun org-e-html-table-cell (table-cell contents info)
2766 "Transcode a TABLE-CELL element from Org to HTML.
2767 CONTENTS is nil. INFO is a plist used as a communication
2768 channel."
2769 (let* ((table-row (org-export-get-parent table-cell info))
2770 (table (org-export-get-parent-table table-cell info))
2771 (cell-attrs
2772 (if (not org-e-html-table-align-individual-fields) ""
2773 (format (if (and (boundp 'org-e-html-format-table-no-css)
2774 org-e-html-format-table-no-css)
2775 " align=\"%s\"" " class=\"%s\"")
2776 (org-export-table-cell-alignment table-cell info)))))
2777 (when (or (not contents) (string= "" (org-trim contents)))
2778 (setq contents "&nbsp;"))
2779 (cond
2780 ((and (org-export-table-has-header-p table info)
2781 (= 1 (org-export-table-row-group table-row info)))
2782 (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
2783 contents (cdr org-e-html-table-header-tags)))
2784 ((and org-e-html-table-use-header-tags-for-first-column
2785 (zerop (cdr (org-export-table-cell-address table-cell info))))
2786 (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
2787 contents (cdr org-e-html-table-header-tags)))
2788 (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
2789 contents (cdr org-e-html-table-data-tags))))))
2792 ;;;; Table Row
2794 (defun org-e-html-table-row (table-row contents info)
2795 "Transcode a TABLE-ROW element from Org to HTML.
2796 CONTENTS is the contents of the row. INFO is a plist used as a
2797 communication channel."
2798 ;; Rules are ignored since table separators are deduced from
2799 ;; borders of the current row.
2800 (when (eq (org-element-property :type table-row) 'standard)
2801 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2802 (rowgroup-tags
2803 (cond
2804 ;; Case 1: Row belongs to second or subsequent rowgroups.
2805 ((not (= 1 (org-export-table-row-group table-row info)))
2806 '("\n<tbody>" . "\n</tbody>"))
2807 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2808 ((org-export-table-has-header-p
2809 (org-export-get-parent-table table-row info) info)
2810 '("\n<thead>" . "\n</thead>"))
2811 ;; Case 2: Row is from first and only row group.
2812 (t '("\n<tbody>" . "\n</tbody>")))))
2813 (concat
2814 ;; Begin a rowgroup?
2815 (when (org-export-table-row-starts-rowgroup-p table-row info)
2816 (car rowgroup-tags))
2817 ;; Actual table row
2818 (concat "\n" (eval (car org-e-html-table-row-tags))
2819 contents (eval (cdr org-e-html-table-row-tags)))
2820 ;; End a rowgroup?
2821 (when (org-export-table-row-ends-rowgroup-p table-row info)
2822 (cdr rowgroup-tags))))))
2825 ;;;; Table
2827 (defun org-e-html-table-first-row-data-cells (table info)
2828 (let ((table-row
2829 (org-element-map
2830 table 'table-row
2831 (lambda (row)
2832 (unless (eq (org-element-property :type row) 'rule) row))
2833 info 'first-match))
2834 (special-column-p (org-export-table-has-special-column-p table)))
2835 (if (not special-column-p) (org-element-contents table-row)
2836 (cdr (org-element-contents table-row)))))
2838 (defun org-e-html-table--table.el-table (table info)
2839 (when (eq (org-element-property :type table) 'table.el)
2840 (require 'table)
2841 (let ((outbuf (with-current-buffer
2842 (get-buffer-create "*org-export-table*")
2843 (erase-buffer) (current-buffer))))
2844 (with-temp-buffer
2845 (insert (org-element-property :value table))
2846 (goto-char 1)
2847 (re-search-forward "^[ \t]*|[^|]" nil t)
2848 (table-generate-source 'html outbuf))
2849 (with-current-buffer outbuf
2850 (prog1 (org-trim (buffer-string))
2851 (kill-buffer) )))))
2853 (defun org-e-html-table (table contents info)
2854 "Transcode a TABLE element from Org to HTML.
2855 CONTENTS is nil. INFO is a plist holding contextual information."
2856 (case (org-element-property :type table)
2857 ;; Case 1: table.el table. Convert it using appropriate tools.
2858 (table.el (org-e-html-table--table.el-table table info))
2859 ;; Case 2: Standard table.
2861 (let* ((label (org-element-property :name table))
2862 (caption (org-e-html--caption/label-string
2863 (org-element-property :caption table) label info))
2864 (attributes (mapconcat #'identity
2865 (org-element-property :attr_html table)
2866 " "))
2867 (alignspec
2868 (if (and (boundp 'org-e-html-format-table-no-css)
2869 org-e-html-format-table-no-css)
2870 "align=\"%s\"" "class=\"%s\""))
2871 (table-column-specs
2872 (function
2873 (lambda (table info)
2874 (mapconcat
2875 (lambda (table-cell)
2876 (let ((alignment (org-export-table-cell-alignment
2877 table-cell info)))
2878 (concat
2879 ;; Begin a colgroup?
2880 (when (org-export-table-cell-starts-colgroup-p
2881 table-cell info)
2882 "\n<colgroup>")
2883 ;; Add a column. Also specify it's alignment.
2884 (format "\n<col %s/>" (format alignspec alignment))
2885 ;; End a colgroup?
2886 (when (org-export-table-cell-ends-colgroup-p
2887 table-cell info)
2888 "\n</colgroup>"))))
2889 (org-e-html-table-first-row-data-cells table info) "\n"))))
2890 (table-attributes
2891 (let ((table-tag (plist-get info :html-table-tag)))
2892 (concat
2893 (and (string-match "<table\\(.*\\)>" table-tag)
2894 (match-string 1 table-tag))
2895 (and label (format " id=\"%s\""
2896 (org-solidify-link-text label)))))))
2897 ;; Remove last blank line.
2898 (setq contents (substring contents 0 -1))
2899 ;; FIXME: splice
2900 (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
2901 table-attributes
2902 (or caption "")
2903 (funcall table-column-specs table info)
2904 contents)))))
2906 ;;;; Target
2908 (defun org-e-html-target (target contents info)
2909 "Transcode a TARGET object from Org to HTML.
2910 CONTENTS is nil. INFO is a plist holding contextual
2911 information."
2912 (let ((id (org-export-solidify-link-text
2913 (org-element-property :value target))))
2914 (format "<a id=\"%s\" name=\"%s\"/>" id id)))
2917 ;;;; Time-stamp
2919 (defun org-e-html-time-stamp (time-stamp contents info)
2920 "Transcode a TIME-STAMP object from Org to HTML.
2921 CONTENTS is nil. INFO is a plist holding contextual
2922 information."
2923 (let ((value (org-element-property :value time-stamp))
2924 (type (org-element-property :type time-stamp))
2925 (appt-type (org-element-property :appt-type time-stamp)))
2926 (setq value (org-translate-time
2927 (org-export-secondary-string value 'e-html info)))
2928 (setq appt-type (case appt-type
2929 (scheduled org-scheduled-string)
2930 (deadline org-deadline-string)
2931 (closed org-closed-string)))
2932 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
2933 (if (not appt-type) ""
2934 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type))
2935 (format "<span class=\"timestamp\">%s</span>" value))))
2938 ;;;; Verbatim
2940 (defun org-e-html-verbatim (verbatim contents info)
2941 "Transcode a VERBATIM object from Org to HTML.
2942 CONTENTS is nil. INFO is a plist used as a communication
2943 channel."
2944 (org-e-html-emphasis
2945 verbatim (org-element-property :value verbatim) info))
2948 ;;;; Verse Block
2950 (defun org-e-html-verse-block (verse-block contents info)
2951 "Transcode a VERSE-BLOCK element from Org to HTML.
2952 CONTENTS is verse block contents. INFO is a plist holding
2953 contextual information."
2954 ;; Replace each newline character with line break. Also replace
2955 ;; each blank line with a line break.
2956 (setq contents (replace-regexp-in-string
2957 "^ *\\\\\\\\$" "<br/>\n"
2958 (replace-regexp-in-string
2959 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
2960 ;; Replace each white space at beginning of a line with a
2961 ;; non-breaking space.
2962 (while (string-match "^[ \t]+" contents)
2963 (let* ((num-ws (length (match-string 0 contents)))
2964 (ws (let (out) (dotimes (i num-ws out)
2965 (setq out (concat out "&nbsp;"))))))
2966 (setq contents (replace-match ws nil t contents))))
2967 (org-e-html--wrap-label
2968 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
2973 ;;; Filter Functions
2975 ;;;; Filter Settings
2977 (defconst org-e-html-filters-alist
2978 '((:filter-final-output . org-e-html-final-function))
2979 "Alist between filters keywords and back-end specific filters.
2980 See `org-export-filters-alist' for more information.")
2983 ;;;; Filters
2985 (defun org-e-html-final-function (contents backend info)
2986 (if (not org-e-html-pretty-output) contents
2987 (with-temp-buffer
2988 (nxml-mode)
2989 (insert contents)
2990 (indent-region (point-min) (point-max))
2991 (buffer-substring-no-properties (point-min) (point-max)))))
2994 ;;; Interactive functions
2996 (defun org-e-html-export-to-html
2997 (&optional subtreep visible-only body-only ext-plist pub-dir)
2998 "Export current buffer to a HTML file.
3000 If narrowing is active in the current buffer, only export its
3001 narrowed part.
3003 If a region is active, export that region.
3005 When optional argument SUBTREEP is non-nil, export the sub-tree
3006 at point, extracting information from the headline properties
3007 first.
3009 When optional argument VISIBLE-ONLY is non-nil, don't export
3010 contents of hidden elements.
3012 When optional argument BODY-ONLY is non-nil, only write code
3013 between \"\\begin{document}\" and \"\\end{document}\".
3015 EXT-PLIST, when provided, is a property list with external
3016 parameters overriding Org default settings, but still inferior to
3017 file-local settings.
3019 When optional argument PUB-DIR is set, use it as the publishing
3020 directory.
3022 Return output file's name."
3023 (interactive)
3024 (setq debug-on-error t) ; FIXME
3025 (let* ((extension (concat "." org-e-html-extension))
3026 (file (org-export-output-file-name extension subtreep pub-dir)))
3027 (org-export-to-file
3028 'e-html file subtreep visible-only body-only ext-plist)))
3032 ;;; FIXMES, TODOS, FOR REVIEW etc
3034 ;;;; org-format-table-html
3035 ;;;; org-format-org-table-html
3036 ;;;; org-format-table-table-html
3037 ;;;; org-table-number-fraction
3038 ;;;; org-table-number-regexp
3039 ;;;; org-e-html-table-caption-above
3041 ;;;; org-whitespace
3042 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3043 ;;;; Remove display properties
3045 ;;;; org-e-html-with-timestamp
3046 ;;;; org-e-html-html-helper-timestamp
3048 ;;;; org-export-as-html-and-open
3049 ;;;; org-export-as-html-batch
3050 ;;;; org-export-as-html-to-buffer
3051 ;;;; org-replace-region-by-html
3052 ;;;; org-export-region-as-html
3053 ;;;; org-export-as-html
3055 ;;;; (org-export-directory :html opt-plist)
3056 ;;;; (plist-get opt-plist :html-extension)
3057 ;;;; org-e-html-toplevel-hlevel
3058 ;;;; org-e-html-special-string-regexps
3059 ;;;; org-e-html-coding-system
3060 ;;;; org-e-html-coding-system
3061 ;;;; org-e-html-inline-images
3062 ;;;; org-e-html-inline-image-extensions
3063 ;;;; org-e-html-protect-char-alist
3064 ;;;; org-e-html-table-use-header-tags-for-first-column
3065 ;;;; org-e-html-todo-kwd-class-prefix
3066 ;;;; org-e-html-tag-class-prefix
3067 ;;;; org-e-html-footnote-separator
3069 ;;;; org-export-preferred-target-alist
3070 ;;;; org-solidify-link-text
3071 ;;;; class for anchors
3072 ;;;; org-export-with-section-numbers, body-only
3073 ;;;; org-export-mark-todo-in-toc
3075 (provide 'org-e-html)
3076 ;;; org-e-html.el ends here