org-e-odt: Few cleanups
[org-mode.git] / EXPERIMENTAL / org-e-html.el
blobcb39e12eb67f7b95df4392338091db536a6eae19
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 ;;; Hooks
45 (defvar org-e-html-after-blockquotes-hook nil
46 "Hook run during HTML export, after blockquote, verse, center are done.")
48 (defvar org-e-html-final-hook nil
49 "Hook run at the end of HTML export, in the new buffer.")
51 ;; FIXME: it already exists in org-e-html.el
52 ;;; Function Declarations
54 (declare-function org-element-get-property "org-element" (property element))
55 (declare-function org-element-normalize-string "org-element" (s))
56 (declare-function org-element-parse-secondary-string
57 "org-element" (string restriction &optional buffer))
58 (defvar org-element-string-restrictions)
60 (declare-function org-export-clean-table "org-export" (table specialp))
61 (declare-function org-export-data "org-export" (data backend info))
62 (declare-function org-export-directory "org-export" (type plist))
63 (declare-function org-export-expand-macro "org-export" (macro info))
64 (declare-function org-export-first-sibling-p "org-export" (headline info))
65 (declare-function org-export-footnote-first-reference-p "org-export"
66 (footnote-reference info))
67 (declare-function org-export-get-coderef-format "org-export" (path desc))
68 (declare-function org-export-get-footnote-definition "org-export"
69 (footnote-reference info))
70 (declare-function org-export-get-footnote-number "org-export" (footnote info))
71 (declare-function org-export-get-previous-element "org-export" (blob info))
72 (declare-function org-export-get-relative-level "org-export" (headline info))
73 (declare-function org-export-handle-code
74 "org-export" (element info &optional num-fmt ref-fmt delayed))
75 (declare-function org-export-included-file "org-export" (keyword backend info))
76 (declare-function org-export-inline-image-p "org-export"
77 (link &optional extensions))
78 (declare-function org-export-last-sibling-p "org-export" (headline info))
79 (declare-function org-export-low-level-p "org-export" (headline info))
80 (declare-function org-export-output-file-name
81 "org-export" (extension &optional subtreep pub-dir))
82 (declare-function org-export-resolve-coderef "org-export" (ref info))
83 (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
84 (declare-function org-export-secondary-string "org-export"
85 (secondary backend info))
86 (declare-function org-export-solidify-link-text "org-export" (s))
87 (declare-function org-export-table-format-info "org-export" (table))
88 (declare-function
89 org-export-to-buffer "org-export"
90 (backend buffer &optional subtreep visible-only body-only ext-plist))
91 (declare-function
92 org-export-to-file "org-export"
93 (backend file &optional subtreep visible-only body-only ext-plist))
95 (declare-function org-id-find-id-file "org-id" (id))
96 (declare-function htmlize-region "ext:htmlize" (beg end))
97 (declare-function org-pop-to-buffer-same-window
98 "org-compat" (&optional buffer-or-name norecord label))
103 ;;; Internal Variables
105 (defconst org-e-html-option-alist
106 '((:agenda-style nil nil org-agenda-export-html-style)
107 (:convert-org-links nil nil org-e-html-link-org-files-as-html)
108 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
109 ;; (:expand-quoted-html nil "@" org-e-html-expand)
110 (:inline-images nil nil org-e-html-inline-images)
111 ;; (:link-home nil nil org-e-html-link-home) FIXME
112 ;; (:link-up nil nil org-e-html-link-up) FIXME
113 (:style nil nil org-e-html-style)
114 (:style-extra nil nil org-e-html-style-extra)
115 (:style-include-default nil nil org-e-html-style-include-default)
116 (:style-include-scripts nil nil org-e-html-style-include-scripts)
117 ;; (:timestamp nil nil org-e-html-with-timestamp)
118 (:html-extension nil nil org-e-html-extension)
119 (:html-postamble nil nil org-e-html-postamble)
120 (:html-preamble nil nil org-e-html-preamble)
121 (:html-table-tag nil nil org-e-html-table-tag)
122 (:xml-declaration nil nil org-e-html-xml-declaration)
123 (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
124 "Alist between export properties and ways to set them.
126 The car of the alist is the property name, and the cdr is a list
127 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
129 KEYWORD is a string representing a buffer keyword, or nil.
130 OPTION is a string that could be found in an #+OPTIONS: line.
131 DEFAULT is the default value for the property.
132 BEHAVIOUR determine how Org should handle multiple keywords for
133 the same property. It is a symbol among:
134 nil Keep old value and discard the new one.
135 t Replace old value with the new one.
136 `space' Concatenate the values, separating them with a space.
137 `newline' Concatenate the values, separating them with
138 a newline.
139 `split' Split values at white spaces, and cons them to the
140 previous list.
142 KEYWORD and OPTION have precedence over DEFAULT.
144 All these properties should be back-end agnostic. For back-end
145 specific properties, define a similar variable named
146 `org-BACKEND-option-alist', replacing BACKEND with the name of
147 the appropriate back-end. You can also redefine properties
148 there, as they have precedence over these.")
150 (defvar html-table-tag nil) ; dynamically scoped into this.
152 ;; FIXME: it already exists in org-e-html.el
153 (defconst org-e-html-cvt-link-fn
155 "Function to convert link URLs to exportable URLs.
156 Takes two arguments, TYPE and PATH.
157 Returns exportable url as (TYPE PATH), or nil to signal that it
158 didn't handle this case.
159 Intended to be locally bound around a call to `org-export-as-html'." )
164 (defvar org-e-html-format-table-no-css)
165 (defvar htmlize-buffer-places) ; from htmlize.el
166 (defvar body-only) ; dynamically scoped into this.
168 (defvar org-e-html-table-rowgrp-open)
169 (defvar org-e-html-table-rownum)
170 (defvar org-e-html-table-cur-rowgrp-is-hdr)
171 (defvar org-lparse-table-is-styled)
174 (defvar org-e-html-headline-formatter
175 (lambda (level snumber todo todo-type priority
176 title tags target extra-targets extra-class)
177 (concat snumber " " title)))
181 ;;; User Configuration Variables
183 (defgroup org-export-e-html nil
184 "Options for exporting Org mode files to HTML."
185 :tag "Org Export HTML"
186 :group 'org-export)
188 ;;;; Debugging
190 (defcustom org-e-html-pretty-output t
191 "Enable this to generate pretty HTML."
192 :group 'org-export-e-html
193 :type 'boolean)
196 ;;;; Document
198 (defcustom org-e-html-extension "html"
199 "The extension for exported HTML files."
200 :group 'org-export-e-html
201 :type 'string)
203 (defcustom org-e-html-xml-declaration
204 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
205 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
206 "The extension for exported HTML files.
207 %s will be replaced with the charset of the exported file.
208 This may be a string, or an alist with export extensions
209 and corresponding declarations."
210 :group 'org-export-e-html
211 :type '(choice
212 (string :tag "Single declaration")
213 (repeat :tag "Dependent on extension"
214 (cons (string :tag "Extension")
215 (string :tag "Declaration")))))
217 (defcustom org-e-html-coding-system nil
218 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
219 :group 'org-export-e-html
220 :type 'coding-system)
222 (defvar org-e-html-content-div "content"
223 "The name of the container DIV that holds all the page contents.
225 This variable is obsolete since Org version 7.7.
226 Please set `org-e-html-divs' instead.")
228 (defcustom org-e-html-divs '("preamble" "content" "postamble")
229 "The name of the main divs for HTML export.
230 This is a list of three strings, the first one for the preamble
231 DIV, the second one for the content DIV and the third one for the
232 postamble DIV."
233 :group 'org-export-e-html
234 :type '(list
235 (string :tag " Div for the preamble:")
236 (string :tag " Div for the content:")
237 (string :tag "Div for the postamble:")))
240 ;;;; Document Header (Styles)
242 (defconst org-e-html-style-default
243 "<style type=\"text/css\">
244 <!--/*--><![CDATA[/*><!--*/
245 html { font-family: Times, serif; font-size: 12pt; }
246 .title { text-align: center; }
247 .todo { color: red; }
248 .done { color: green; }
249 .tag { background-color: #add8e6; font-weight:normal }
250 .target { }
251 .timestamp { color: #bebebe; }
252 .timestamp-kwd { color: #5f9ea0; }
253 .right {margin-left:auto; margin-right:0px; text-align:right;}
254 .left {margin-left:0px; margin-right:auto; text-align:left;}
255 .center {margin-left:auto; margin-right:auto; text-align:center;}
256 p.verse { margin-left: 3% }
257 pre {
258 border: 1pt solid #AEBDCC;
259 background-color: #F3F5F7;
260 padding: 5pt;
261 font-family: courier, monospace;
262 font-size: 90%;
263 overflow:auto;
265 table { border-collapse: collapse; }
266 td, th { vertical-align: top; }
267 th.right { text-align:center; }
268 th.left { text-align:center; }
269 th.center { text-align:center; }
270 td.right { text-align:right; }
271 td.left { text-align:left; }
272 td.center { text-align:center; }
273 dt { font-weight: bold; }
274 div.figure { padding: 0.5em; }
275 div.figure p { text-align: center; }
276 div.inlinetask {
277 padding:10px;
278 border:2px solid gray;
279 margin:10px;
280 background: #ffffcc;
282 textarea { overflow-x: auto; }
283 .linenr { font-size:smaller }
284 .code-highlighted {background-color:#ffff00;}
285 .org-info-js_info-navigation { border-style:none; }
286 #org-info-js_console-label { font-size:10px; font-weight:bold;
287 white-space:nowrap; }
288 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
289 font-weight:bold; }
290 /*]]>*/-->
291 </style>"
292 "The default style specification for exported HTML files.
293 Please use the variables `org-e-html-style' and
294 `org-e-html-style-extra' to add to this style. If you wish to not
295 have the default style included, customize the variable
296 `org-e-html-style-include-default'.")
298 (defcustom org-e-html-style-include-default t
299 "Non-nil means include the default style in exported HTML files.
300 The actual style is defined in `org-e-html-style-default' and should
301 not be modified. Use the variables `org-e-html-style' to add
302 your own style information."
303 :group 'org-export-e-html
304 :type 'boolean)
305 ;;;###autoload
306 (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
308 (defcustom org-e-html-style ""
309 "Org-wide style definitions for exported HTML files.
311 This variable needs to contain the full HTML structure to provide a style,
312 including the surrounding HTML tags. If you set the value of this variable,
313 you should consider to include definitions for the following classes:
314 title, todo, done, timestamp, timestamp-kwd, tag, target.
316 For example, a valid value would be:
318 <style type=\"text/css\">
319 <![CDATA[
320 p { font-weight: normal; color: gray; }
321 h1 { color: black; }
322 .title { text-align: center; }
323 .todo, .timestamp-kwd { color: red; }
324 .done { color: green; }
326 </style>
328 If you'd like to refer to an external style file, use something like
330 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
332 As the value of this option simply gets inserted into the HTML <head> header,
333 you can \"misuse\" it to add arbitrary text to the header.
334 See also the variable `org-e-html-style-extra'."
335 :group 'org-export-e-html
336 :type 'string)
337 ;;;###autoload
338 (put 'org-e-html-style 'safe-local-variable 'stringp)
340 (defcustom org-e-html-style-extra ""
341 "Additional style information for HTML export.
342 The value of this variable is inserted into the HTML buffer right after
343 the value of `org-e-html-style'. Use this variable for per-file
344 settings of style information, and do not forget to surround the style
345 settings with <style>...</style> tags."
346 :group 'org-export-e-html
347 :type 'string)
348 ;;;###autoload
349 (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
351 (defcustom org-e-html-mathjax-options
352 '((path "http://orgmode.org/mathjax/MathJax.js")
353 (scale "100")
354 (align "center")
355 (indent "2em")
356 (mathml nil))
357 "Options for MathJax setup.
359 path The path where to find MathJax
360 scale Scaling for the HTML-CSS backend, usually between 100 and 133
361 align How to align display math: left, center, or right
362 indent If align is not center, how far from the left/right side?
363 mathml Should a MathML player be used if available?
364 This is faster and reduces bandwidth use, but currently
365 sometimes has lower spacing quality. Therefore, the default is
366 nil. When browsers get better, this switch can be flipped.
368 You can also customize this for each buffer, using something like
370 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
371 :group 'org-export-e-html
372 :type '(list :greedy t
373 (list :tag "path (the path from where to load MathJax.js)"
374 (const :format " " path) (string))
375 (list :tag "scale (scaling for the displayed math)"
376 (const :format " " scale) (string))
377 (list :tag "align (alignment of displayed equations)"
378 (const :format " " align) (string))
379 (list :tag "indent (indentation with left or right alignment)"
380 (const :format " " indent) (string))
381 (list :tag "mathml (should MathML display be used is possible)"
382 (const :format " " mathml) (boolean))))
385 ;;;; Document Header (Scripts)
387 (defcustom org-e-html-style-include-scripts t
388 "Non-nil means include the JavaScript snippets in exported HTML files.
389 The actual script is defined in `org-e-html-scripts' and should
390 not be modified."
391 :group 'org-export-e-html
392 :type 'boolean)
394 (defconst org-e-html-scripts
395 "<script type=\"text/javascript\">
396 <!--/*--><![CDATA[/*><!--*/
397 function CodeHighlightOn(elem, id)
399 var target = document.getElementById(id);
400 if(null != target) {
401 elem.cacheClassElem = elem.className;
402 elem.cacheClassTarget = target.className;
403 target.className = \"code-highlighted\";
404 elem.className = \"code-highlighted\";
407 function CodeHighlightOff(elem, id)
409 var target = document.getElementById(id);
410 if(elem.cacheClassElem)
411 elem.className = elem.cacheClassElem;
412 if(elem.cacheClassTarget)
413 target.className = elem.cacheClassTarget;
415 /*]]>*///-->
416 </script>"
417 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
420 ;;;; Document Header (Mathjax)
422 (defcustom org-e-html-mathjax-template
423 "<script type=\"text/javascript\" src=\"%PATH\">
424 <!--/*--><![CDATA[/*><!--*/
425 MathJax.Hub.Config({
426 // Only one of the two following lines, depending on user settings
427 // First allows browser-native MathML display, second forces HTML/CSS
428 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
429 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
430 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
431 \"TeX/noUndefined.js\"],
432 tex2jax: {
433 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
434 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
435 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
436 ignoreClass: \"tex2jax_ignore\",
437 processEscapes: false,
438 processEnvironments: true,
439 preview: \"TeX\"
441 showProcessingMessages: true,
442 displayAlign: \"%ALIGN\",
443 displayIndent: \"%INDENT\",
445 \"HTML-CSS\": {
446 scale: %SCALE,
447 availableFonts: [\"STIX\",\"TeX\"],
448 preferredFont: \"TeX\",
449 webFont: \"TeX\",
450 imageFont: \"TeX\",
451 showMathMenu: true,
453 MMLorHTML: {
454 prefer: {
455 MSIE: \"MML\",
456 Firefox: \"MML\",
457 Opera: \"HTML\",
458 other: \"HTML\"
462 /*]]>*///-->
463 </script>"
464 "The MathJax setup for XHTML files."
465 :group 'org-export-e-html
466 :type 'string)
469 ;;;; Preamble
471 (defcustom org-e-html-preamble t
472 "Non-nil means insert a preamble in HTML export.
474 When `t', insert a string as defined by one of the formatting
475 strings in `org-e-html-preamble-format'. When set to a
476 string, this string overrides `org-e-html-preamble-format'.
477 When set to a function, apply this function and insert the
478 returned string. The function takes the property list of export
479 options as its only argument.
481 Setting :html-preamble in publishing projects will take
482 precedence over this variable."
483 :group 'org-export-e-html
484 :type '(choice (const :tag "No preamble" nil)
485 (const :tag "Default preamble" t)
486 (string :tag "Custom formatting string")
487 (function :tag "Function (must return a string)")))
489 (defcustom org-e-html-preamble-format '(("en" ""))
490 "The format for the HTML preamble.
492 %t stands for the title.
493 %a stands for the author's name.
494 %e stands for the author's email.
495 %d stands for the date.
497 If you need to use a \"%\" character, you need to escape it
498 like that: \"%%\"."
499 :group 'org-export-e-html
500 :type 'string)
502 (defcustom org-e-html-home/up-format
503 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
504 <a accesskey=\"h\" href=\"%s\"> UP </a>
506 <a accesskey=\"H\" href=\"%s\"> HOME </a>
507 </div>"
508 "Snippet used to insert the HOME and UP links.
509 This is a format string, the first %s will receive the UP link,
510 the second the HOME link. If both `org-e-html-link-up' and
511 `org-e-html-link-home' are empty, the entire snippet will be
512 ignored."
513 :group 'org-export-e-html
514 :type 'string)
516 ;;;; Postamble
518 (defcustom org-e-html-postamble 'auto
519 "Non-nil means insert a postamble in HTML export.
521 When `t', insert a string as defined by the formatting string in
522 `org-e-html-postamble-format'. When set to a string, this
523 string overrides `org-e-html-postamble-format'. When set to
524 'auto, discard `org-e-html-postamble-format' and honor
525 `org-export-author/email/creator-info' variables. When set to a
526 function, apply this function and insert the returned string.
527 The function takes the property list of export options as its
528 only argument.
530 Setting :html-postamble in publishing projects will take
531 precedence over this variable."
532 :group 'org-export-e-html
533 :type '(choice (const :tag "No postamble" nil)
534 (const :tag "Auto preamble" 'auto)
535 (const :tag "Default formatting string" t)
536 (string :tag "Custom formatting string")
537 (function :tag "Function (must return a string)")))
539 (defcustom org-e-html-postamble-format
540 '(("en" "<p class=\"author\">Author: %a (%e)</p>
541 <p class=\"date\">Date: %d</p>
542 <p class=\"creator\">Generated by %c</p>
543 <p class=\"xhtml-validation\">%v</p>
545 "The format for the HTML postamble.
547 %a stands for the author's name.
548 %e stands for the author's email.
549 %d stands for the date.
550 %c will be replaced by information about Org/Emacs versions.
551 %v will be replaced by `org-e-html-validation-link'.
553 If you need to use a \"%\" character, you need to escape it
554 like that: \"%%\"."
555 :group 'org-export-e-html
556 :type 'string)
558 (defcustom org-e-html-validation-link
559 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
560 "Link to HTML validation service."
561 :group 'org-export-e-html
562 :type 'string)
564 ;; FIXME Obsolete since Org 7.7
565 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
566 ;;;; Emphasis
568 (defcustom org-e-html-protect-char-alist
569 '(("&" . "&amp;")
570 ("<" . "&lt;")
571 (">" . "&gt;"))
572 "Alist of characters to be converted by `org-e-html-protect'."
573 :group 'org-export-e-html
574 :type '(repeat (cons (string :tag "Character")
575 (string :tag "HTML equivalent"))))
577 (defconst org-e-html-special-string-regexps
578 '(("\\\\-" . "&shy;")
579 ("---\\([^-]\\)" . "&mdash;\\1")
580 ("--\\([^-]\\)" . "&ndash;\\1")
581 ("\\.\\.\\." . "&hellip;"))
582 "Regular expressions for special string conversion.")
585 ;;;; Todos
587 (defcustom org-e-html-todo-kwd-class-prefix ""
588 "Prefix to class names for TODO keywords.
589 Each TODO keyword gets a class given by the keyword itself, with this prefix.
590 The default prefix is empty because it is nice to just use the keyword
591 as a class name. But if you get into conflicts with other, existing
592 CSS classes, then this prefix can be very useful."
593 :group 'org-export-e-html
594 :type 'string)
597 ;;;; Tags
599 (defcustom org-e-html-tag-class-prefix ""
600 "Prefix to class names for TODO keywords.
601 Each tag gets a class given by the tag itself, with this prefix.
602 The default prefix is empty because it is nice to just use the keyword
603 as a class name. But if you get into conflicts with other, existing
604 CSS classes, then this prefix can be very useful."
605 :group 'org-export-e-html
606 :type 'string)
608 ;;;; Time-stamps
609 ;;;; Statistics Cookie
610 ;;;; Subscript
611 ;;;; Superscript
613 ;;;; Inline images
615 (defcustom org-e-html-inline-images 'maybe
616 "Non-nil means inline images into exported HTML pages.
617 This is done using an <img> tag. When nil, an anchor with href is used to
618 link to the image. If this option is `maybe', then images in links with
619 an empty description will be inlined, while images with a description will
620 be linked only."
621 :group 'org-export-e-html
622 :type '(choice (const :tag "Never" nil)
623 (const :tag "Always" t)
624 (const :tag "When there is no description" maybe)))
626 (defcustom org-e-html-inline-image-extensions
627 '("png" "jpeg" "jpg" "gif" "svg")
628 "Extensions of image files that can be inlined into HTML."
629 :group 'org-export-e-html
630 :type '(repeat (string :tag "Extension")))
633 ;;;; Block
634 ;;;; Comment
635 ;;;; Comment Block
636 ;;;; Drawer
637 ;;;; Dynamic Block
638 ;;;; Emphasis
639 ;;;; Entity
640 ;;;; Example Block
641 ;;;; Export Snippet
642 ;;;; Export Block
643 ;;;; Fixed Width
644 ;;;; Footnotes
646 (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
647 <h2 class=\"footnotes\">%s: </h2>
648 <div id=\"text-footnotes\">
650 </div>
651 </div>"
652 "Format for the footnotes section.
653 Should contain a two instances of %s. The first will be replaced with the
654 language-specific word for \"Footnotes\", the second one will be replaced
655 by the footnotes themselves."
656 :group 'org-export-e-html
657 :type 'string)
659 (defcustom org-e-html-footnote-format "<sup>%s</sup>"
660 "The format for the footnote reference.
661 %s will be replaced by the footnote reference itself."
662 :group 'org-export-e-html
663 :type 'string)
665 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
666 "Text used to separate footnotes."
667 :group 'org-export-e-html
668 :type 'string)
671 ;;;; Headline
672 ;;;; Horizontal Rule
673 ;;;; Inline Babel Call
674 ;;;; Inline Src Block
675 ;;;; Inlinetask
676 ;;;; Item
677 ;;;; Keyword
678 ;;;; Latex Environment
679 ;;;; Latex Fragment
680 ;;;; Line Break
681 ;;;; Link
682 ;;;; Babel Call
683 ;;;; Macro
684 ;;;; Paragraph
685 ;;;; Plain List
686 ;;;; Plain Text
687 ;;;; Property Drawer
688 ;;;; Quote Block
689 ;;;; Quote Section
690 ;;;; Section
691 ;;;; Radio Target
692 ;;;; Special Block
693 ;;;; Src Block
695 (defgroup org-export-e-htmlize nil
696 "Options for processing examples with htmlize.el."
697 :tag "Org Export Htmlize"
698 :group 'org-export-e-html)
700 (defcustom org-export-e-htmlize-output-type 'inline-css
701 "Output type to be used by htmlize when formatting code snippets.
702 Choices are `css', to export the CSS selectors only, or `inline-css', to
703 export the CSS attribute values inline in the HTML. We use as default
704 `inline-css', in order to make the resulting HTML self-containing.
706 However, this will fail when using Emacs in batch mode for export, because
707 then no rich font definitions are in place. It will also not be good if
708 people with different Emacs setup contribute HTML files to a website,
709 because the fonts will represent the individual setups. In these cases,
710 it is much better to let Org/Htmlize assign classes only, and to use
711 a style file to define the look of these classes.
712 To get a start for your css file, start Emacs session and make sure that
713 all the faces you are interested in are defined, for example by loading files
714 in all modes you want. Then, use the command
715 \\[org-export-e-htmlize-generate-css] to extract class definitions."
716 :group 'org-export-e-htmlize
717 :type '(choice (const css) (const inline-css)))
719 (defcustom org-export-e-htmlize-css-font-prefix "org-"
720 "The prefix for CSS class names for htmlize font specifications."
721 :group 'org-export-e-htmlize
722 :type 'string)
724 (defcustom org-export-e-htmlized-org-css-url nil
725 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
726 Normally when creating an htmlized version of an Org buffer, htmlize will
727 create CSS to define the font colors. However, this does not work when
728 converting in batch mode, and it also can look bad if different people
729 with different fontification setup work on the same website.
730 When this variable is non-nil, creating an htmlized version of an Org buffer
731 using `org-export-as-org' will remove the internal CSS section and replace it
732 with a link to this URL."
733 :group 'org-export-e-htmlize
734 :type '(choice
735 (const :tag "Keep internal css" nil)
736 (string :tag "URL or local href")))
739 ;;;; Table
741 (defcustom org-e-html-table-tag
742 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
743 "The HTML tag that is used to start a table.
744 This must be a <table> tag, but you may change the options like
745 borders and spacing."
746 :group 'org-export-e-html
747 :type 'string)
749 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
750 "The opening tag for table header fields.
751 This is customizable so that alignment options can be specified.
752 The first %s will be filled with the scope of the field, either row or col.
753 The second %s will be replaced by a style entry to align the field.
754 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
755 See also the variable `org-e-html-table-align-individual-fields'."
756 :group 'org-export-tables
757 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
759 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
760 "The opening tag for table data fields.
761 This is customizable so that alignment options can be specified.
762 The first %s will be filled with the scope of the field, either row or col.
763 The second %s will be replaced by a style entry to align the field.
764 See also the variable `org-e-html-table-align-individual-fields'."
765 :group 'org-export-tables
766 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
768 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
769 "The opening tag for table data fields.
770 This is customizable so that alignment options can be specified.
771 Instead of strings, these can be Lisp forms that will be evaluated
772 for each row in order to construct the table row tags. During evaluation,
773 the variable `head' will be true when this is a header line, nil when this
774 is a body line. And the variable `nline' will contain the line number,
775 starting from 1 in the first header line. For example
777 (setq org-export-table-row-tags
778 (cons '(if head
779 \"<tr>\"
780 (if (= (mod nline 2) 1)
781 \"<tr class=\\\"tr-odd\\\">\"
782 \"<tr class=\\\"tr-even\\\">\"))
783 \"</tr>\"))
785 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
786 :group 'org-export-tables
787 :type '(cons
788 (choice :tag "Opening tag"
789 (string :tag "Specify")
790 (sexp))
791 (choice :tag "Closing tag"
792 (string :tag "Specify")
793 (sexp))))
795 (defcustom org-e-html-table-align-individual-fields t
796 "Non-nil means attach style attributes for alignment to each table field.
797 When nil, alignment will only be specified in the column tags, but this
798 is ignored by some browsers (like Firefox, Safari). Opera does it right
799 though."
800 :group 'org-export-tables
801 :type 'boolean)
803 (defcustom org-e-html-table-use-header-tags-for-first-column nil
804 "Non-nil means format column one in tables with header tags.
805 When nil, also column one will use data tags."
806 :group 'org-export-tables
807 :type 'boolean)
810 ;;;; Target
811 ;;;; Time-stamp
813 ;;;; Verbatim
814 ;;;; Verse Block
815 ;;;; Headline
817 (defcustom org-e-html-toplevel-hlevel 2
818 "The <H> level for level 1 headings in HTML export.
819 This is also important for the classes that will be wrapped around headlines
820 and outline structure. If this variable is 1, the top-level headlines will
821 be <h1>, and the corresponding classes will be outline-1, section-number-1,
822 and outline-text-1. If this is 2, all of these will get a 2 instead.
823 The default for this variable is 2, because we use <h1> for formatting the
824 document title."
825 :group 'org-export-e-html
826 :type 'string)
829 ;;;; Links
830 ;;;; Drawers
831 ;;;; Inlinetasks
832 ;;;; Publishing
834 (defcustom org-e-html-link-org-files-as-html t
835 "Non-nil means make file links to `file.org' point to `file.html'.
836 When org-mode is exporting an org-mode file to HTML, links to
837 non-html files are directly put into a href tag in HTML.
838 However, links to other Org-mode files (recognized by the
839 extension `.org.) should become links to the corresponding html
840 file, assuming that the linked org-mode file will also be
841 converted to HTML.
842 When nil, the links still point to the plain `.org' file."
843 :group 'org-export-e-html
844 :type 'boolean)
847 ;;;; Compilation
851 ;;; User Configurable Variables (MAYBE)
853 ;;;; Preamble
855 (defcustom org-e-html-date-format
856 "\\today"
857 "Format string for \\date{...}."
858 :group 'org-export-e-html
859 :type 'boolean)
861 ;;;; Headline
863 (defcustom org-e-html-format-headline-function nil
864 "Function to format headline text.
866 This function will be called with 5 arguments:
867 TODO the todo keyword \(string or nil\).
868 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
869 PRIORITY the priority of the headline \(integer or nil\)
870 TEXT the main headline text \(string\).
871 TAGS the tags string, separated with colons \(string or nil\).
873 The function result will be used in the section format string.
875 As an example, one could set the variable to the following, in
876 order to reproduce the default set-up:
878 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
879 \"Default format function for an headline.\"
880 \(concat \(when todo
881 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
882 \(when priority
883 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
884 text
885 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
886 :group 'org-export-e-html
887 :type 'function)
890 ;;;; Emphasis
892 (defcustom org-e-html-emphasis-alist
893 '(("*" . "<b>%s</b>")
894 ("/" . "<i>%s</i>")
895 ("_" . "<span style=\"text-decoration:underline;\">%s</span>")
896 ("+" . "<del>%s</del>")
897 ("=" . "<code>%s</code>")
898 ("~" . "<code>%s</code>"))
899 "Alist of HTML expressions to convert emphasis fontifiers.
901 The key is the character used as a marker for fontification. The
902 value is a formatting string to wrap fontified text with.
904 Value can also be set to the following symbols: `verb' and
905 `protectedtexttt'. For the former, Org will use \"\\verb\" to
906 create a format string and select a delimiter character that
907 isn't in the string. For the latter, Org will use \"\\texttt\"
908 to typeset and try to protect special characters."
909 :group 'org-export-e-html
910 :type 'alist)
913 ;;;; Footnotes
915 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
916 "Text used to separate footnotes."
917 :group 'org-export-e-html
918 :type 'string)
921 ;;;; Time-stamps
923 (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
924 "A printf format string to be applied to active time-stamps."
925 :group 'org-export-e-html
926 :type 'string)
928 (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
929 "A printf format string to be applied to inactive time-stamps."
930 :group 'org-export-e-html
931 :type 'string)
933 (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
934 "A printf format string to be applied to diary time-stamps."
935 :group 'org-export-e-html
936 :type 'string)
939 ;;;; Links
941 (defcustom org-e-html-image-default-option "width=.9\\linewidth"
942 "Default option for images."
943 :group 'org-export-e-html
944 :type 'string)
946 (defcustom org-e-html-default-figure-position "htb"
947 "Default position for latex figures."
948 :group 'org-export-e-html
949 :type 'string)
951 (defcustom org-e-html-inline-image-rules
952 '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
953 "Rules characterizing image files that can be inlined into HTML.
955 A rule consists in an association whose key is the type of link
956 to consider, and value is a regexp that will be matched against
957 link's path.
959 Note that, by default, the image extension *actually* allowed
960 depend on the way the HTML file is processed. When used with
961 pdflatex, pdf, jpg and png images are OK. When processing
962 through dvi to Postscript, only ps and eps are allowed. The
963 default we use here encompasses both."
964 :group 'org-export-e-html
965 :type '(alist :key-type (string :tag "Type")
966 :value-type (regexp :tag "Path")))
968 ;;;; Tables
970 (defcustom org-e-html-table-caption-above t
971 "When non-nil, place caption string at the beginning of the table.
972 Otherwise, place it near the end."
973 :group 'org-export-e-html
974 :type 'boolean)
976 ;;;; Drawers
978 (defcustom org-e-html-format-drawer-function nil
979 "Function called to format a drawer in HTML code.
981 The function must accept two parameters:
982 NAME the drawer name, like \"LOGBOOK\"
983 CONTENTS the contents of the drawer.
985 The function should return the string to be exported.
987 For example, the variable could be set to the following function
988 in order to mimic default behaviour:
990 \(defun org-e-html-format-drawer-default \(name contents\)
991 \"Format a drawer element for HTML export.\"
992 contents\)"
993 :group 'org-export-e-html
994 :type 'function)
997 ;;;; Inlinetasks
999 (defcustom org-e-html-format-inlinetask-function nil
1000 "Function called to format an inlinetask in HTML code.
1002 The function must accept six parameters:
1003 TODO the todo keyword, as a string
1004 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
1005 PRIORITY the inlinetask priority, as a string
1006 NAME the inlinetask name, as a string.
1007 TAGS the inlinetask tags, as a string.
1008 CONTENTS the contents of the inlinetask, as a string.
1010 The function should return the string to be exported.
1012 For example, the variable could be set to the following function
1013 in order to mimic default behaviour:
1015 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
1016 \"Format an inline task element for HTML export.\"
1017 \(let \(\(full-title
1018 \(concat
1019 \(when todo
1020 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
1021 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1022 title
1023 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1024 \(format \(concat \"\\\\begin{center}\\n\"
1025 \"\\\\fbox{\\n\"
1026 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1027 \"%s\\n\\n\"
1028 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1029 \"%s\"
1030 \"\\\\end{minipage}}\"
1031 \"\\\\end{center}\"\)
1032 full-title contents\)\)"
1033 :group 'org-export-e-html
1034 :type 'function)
1037 ;; Src blocks
1039 ;;;; Plain text
1041 (defcustom org-e-html-quotes
1042 '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
1043 ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
1044 "Alist for quotes to use when converting english double-quotes.
1046 The CAR of each item in this alist is the language code.
1047 The CDR of each item in this alist is a list of three CONS:
1048 - the first CONS defines the opening quote;
1049 - the second CONS defines the closing quote;
1050 - the last CONS defines single quotes.
1052 For each item in a CONS, the first string is a regexp
1053 for allowed characters before/after the quote, the second
1054 string defines the replacement string for this quote."
1055 :group 'org-export-e-html
1056 :type '(list
1057 (cons :tag "Opening quote"
1058 (string :tag "Regexp for char before")
1059 (string :tag "Replacement quote "))
1060 (cons :tag "Closing quote"
1061 (string :tag "Regexp for char after ")
1062 (string :tag "Replacement quote "))
1063 (cons :tag "Single quote"
1064 (string :tag "Regexp for char before")
1065 (string :tag "Replacement quote "))))
1068 ;;;; Compilation
1072 ;;; Internal Functions (HTML)
1074 (defun org-e-html-cvt-org-as-html (opt-plist type path)
1075 "Convert an org filename to an equivalent html filename.
1076 If TYPE is not file, just return `nil'.
1077 See variable `org-e-html-link-org-files-as-html'"
1079 (save-match-data
1080 (and
1081 org-e-html-link-org-files-as-html
1082 (string= type "file")
1083 (string-match "\\.org$" path)
1084 (progn
1085 (list
1086 "file"
1087 (concat
1088 (substring path 0 (match-beginning 0))
1090 (plist-get opt-plist :html-extension)))))))
1092 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1093 descp)
1094 "Make an HTML link.
1095 OPT-PLIST is an options list.
1096 TYPE is the device-type of the link (THIS://foo.html).
1097 PATH is the path of the link (http://THIS#location).
1098 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1099 DESC is the link description, if any.
1100 ATTR is a string of other attributes of the \"a\" element."
1101 (declare (special org-lparse-par-open))
1102 (save-match-data
1103 (when (string= type-1 "coderef")
1104 (let ((ref fragment))
1105 (setq desc (format (org-export-get-coderef-format ref (and descp desc))
1106 (cdr (assoc ref org-export-code-refs)))
1107 fragment (concat "coderef-" ref)
1108 attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1109 fragment fragment))))
1110 (let* ((may-inline-p
1111 (and (member type-1 '("http" "https" "file"))
1112 (org-lparse-should-inline-p path descp)
1113 (not fragment)))
1114 (type (if (equal type-1 "id") "file" type-1))
1115 (filename path)
1116 ;;First pass. Just sanity stuff.
1117 (components-1
1118 (cond
1119 ((string= type "file")
1120 (list
1121 type
1122 ;;Substitute just if original path was absolute.
1123 ;;(Otherwise path must remain relative)
1124 (if (file-name-absolute-p path)
1125 (concat "file://" (expand-file-name path))
1126 path)))
1127 ((string= type "")
1128 (list nil path))
1129 (t (list type path))))
1131 ;;Second pass. Components converted so they can refer
1132 ;;to a remote site.
1133 (components-2
1135 (and org-e-html-cvt-link-fn
1136 (apply org-e-html-cvt-link-fn
1137 opt-plist components-1))
1138 (apply #'org-e-html-cvt-org-as-html
1139 opt-plist components-1)
1140 components-1))
1141 (type (first components-2))
1142 (thefile (second components-2)))
1145 ;;Third pass. Build final link except for leading type
1146 ;;spec.
1147 (cond
1148 ((or
1149 (not type)
1150 (string= type "http")
1151 (string= type "https")
1152 (string= type "file")
1153 (string= type "coderef"))
1154 (if fragment
1155 (setq thefile (concat thefile "#" fragment))))
1157 (t))
1159 ;;Final URL-build, for all types.
1160 (setq thefile
1161 (let
1162 ((str (org-xml-format-href thefile)))
1163 (if (and type (not (or (string= "file" type)
1164 (string= "coderef" type))))
1165 (concat type ":" str)
1166 str)))
1168 (if may-inline-p
1169 (org-e-html-format-image thefile)
1170 (org-lparse-format
1171 'LINK (org-xml-format-desc desc) thefile attr)))))
1173 (defun org-e-html-format-inline-image (path &optional caption label attr)
1174 ;; FIXME: alt text missing here?
1175 (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
1176 path (file-name-nondirectory path))))
1177 (if (not label) inline-image
1178 (org-e-html-format-section inline-image "figure" label))))
1180 (defun org-e-html-format-image (src)
1181 "Create image tag with source and attributes."
1182 (save-match-data
1183 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1184 (attr (org-find-text-property-in-string 'org-attributes src))
1185 (label (org-find-text-property-in-string 'org-label src))
1186 (caption (and caption (org-xml-encode-org-text caption)))
1187 (img-extras (if (string-match "^ltxpng/" src)
1188 (format " alt=\"%s\""
1189 (org-find-text-property-in-string
1190 'org-latex-src src))
1191 (if (string-match "\\<alt=" (or attr ""))
1192 (concat " " attr )
1193 (concat " " attr " alt=\"" src "\""))))
1194 (img (format "<img src=\"%s\"%s />" src img-extras))
1195 (extra (concat
1196 (and label
1197 (format "id=\"%s\" " (org-solidify-link-text label)))
1198 "class=\"figure\"")))
1199 (if caption
1200 (with-temp-buffer
1201 (with-org-lparse-preserve-paragraph-state
1202 (insert
1203 (org-lparse-format
1204 '("<div %s>" . "\n</div>")
1205 (concat
1206 (org-lparse-format '("\n<p>" . "</p>") img)
1207 (org-lparse-format '("\n<p>" . "</p>") caption))
1208 extra)))
1209 (buffer-string))
1210 img))))
1212 ;;;; Bibliography
1214 (defun org-e-html-bibliography ()
1215 "Find bibliography, cut it out and return it."
1216 (catch 'exit
1217 (let (beg end (cnt 1) bib)
1218 (save-excursion
1219 (goto-char (point-min))
1220 (when (re-search-forward
1221 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1222 (setq beg (match-beginning 0))
1223 (while (re-search-forward "</?div\\>" nil t)
1224 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1225 (when (= cnt 0)
1226 (and (looking-at ">") (forward-char 1))
1227 (setq bib (buffer-substring beg (point)))
1228 (delete-region beg (point))
1229 (throw 'exit bib))))
1230 nil))))
1232 ;;;; Table
1234 (defun org-e-html-format-table (lines olines)
1235 (let ((org-e-html-format-table-no-css nil))
1236 (org-lparse-format-table lines olines)))
1238 (defun org-e-html-splice-attributes (tag attributes)
1239 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1240 (if (not attributes)
1242 (let (oldatt newatt)
1243 (setq oldatt (org-extract-attributes-from-string tag)
1244 tag (pop oldatt)
1245 newatt (cdr (org-extract-attributes-from-string attributes)))
1246 (while newatt
1247 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1248 (if (string-match ">" tag)
1249 (setq tag
1250 (replace-match (concat (org-attributes-to-string oldatt) ">")
1251 t t tag)))
1252 tag)))
1254 (defun org-export-splice-style (style extra)
1255 "Splice EXTRA into STYLE, just before \"</style>\"."
1256 (if (and (stringp extra)
1257 (string-match "\\S-" extra)
1258 (string-match "</style>" style))
1259 (concat (substring style 0 (match-beginning 0))
1260 "\n" extra "\n"
1261 (substring style (match-beginning 0)))
1262 style))
1264 (defun org-export-e-htmlize-region-for-paste (beg end)
1265 "Convert the region to HTML, using htmlize.el.
1266 This is much like `htmlize-region-for-paste', only that it uses
1267 the settings define in the org-... variables."
1268 (let* ((htmlize-output-type org-export-e-htmlize-output-type)
1269 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
1270 (htmlbuf (htmlize-region beg end)))
1271 (unwind-protect
1272 (with-current-buffer htmlbuf
1273 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1274 (plist-get htmlize-buffer-places 'content-end)))
1275 (kill-buffer htmlbuf))))
1277 ;;;###autoload
1278 (defun org-export-e-htmlize-generate-css ()
1279 "Create the CSS for all font definitions in the current Emacs session.
1280 Use this to create face definitions in your CSS style file that can then
1281 be used by code snippets transformed by htmlize.
1282 This command just produces a buffer that contains class definitions for all
1283 faces used in the current Emacs session. You can copy and paste the ones you
1284 need into your CSS file.
1286 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1287 the function `org-export-e-htmlize-region-for-paste' will produce code
1288 that uses these same face definitions."
1289 (interactive)
1290 (require 'htmlize)
1291 (and (get-buffer "*html*") (kill-buffer "*html*"))
1292 (with-temp-buffer
1293 (let ((fl (face-list))
1294 (htmlize-css-name-prefix "org-")
1295 (htmlize-output-type 'css)
1296 f i)
1297 (while (setq f (pop fl)
1298 i (and f (face-attribute f :inherit)))
1299 (when (and (symbolp f) (or (not i) (not (listp i))))
1300 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1301 (htmlize-region (point-min) (point-max))))
1302 (org-pop-to-buffer-same-window "*html*")
1303 (goto-char (point-min))
1304 (if (re-search-forward "<style" nil t)
1305 (delete-region (point-min) (match-beginning 0)))
1306 (if (re-search-forward "</style>" nil t)
1307 (delete-region (1+ (match-end 0)) (point-max)))
1308 (beginning-of-line 1)
1309 (if (looking-at " +") (replace-match ""))
1310 (goto-char (point-min)))
1312 (defun org-e-html-format-toc-entry (snumber todo headline tags href)
1313 (setq headline (concat
1314 ;; section number
1315 (and org-export-with-section-numbers (concat snumber " "))
1316 ;; headline
1317 headline
1318 ;; tags
1319 (and tags (concat
1320 "&nbsp;&nbsp;&nbsp;"
1321 (org-e-html-format-fontify tags "tag")))))
1322 ;; fontify headline based on TODO keyword
1323 (when todo (setq headline (org-e-html-format-fontify headline "todo")))
1324 (org-e-html-format-link headline (concat "#" href)))
1326 (defun org-e-html-toc-entry-formatter
1327 (level snumber todo todo-type priority
1328 headline tags target extra-targets extra-class)
1329 (org-e-html-format-toc-entry snumber todo headline tags target))
1331 (defun org-e-html-make-string (n string)
1332 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1334 (defun org-e-html-toc-text (toc-entries)
1335 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1336 (start-level prev-level))
1337 (concat
1338 (mapconcat
1339 (lambda (entry)
1340 (let ((headline (nth 0 entry))
1341 (level (nth 1 entry)))
1342 (concat
1343 (let* ((cnt (- level prev-level))
1344 (times (if (> cnt 0) (1- cnt) (- cnt)))
1345 rtn)
1346 (setq prev-level level)
1347 (concat
1348 (org-e-html-make-string
1349 times (cond ((> cnt 0) "<ul>\n<li>\n")
1350 ((< cnt 0) "</li>\n</ul>\n")))
1351 (if (> cnt 0) "<ul>\n<li>\n" "</li>\n<li>\n")))
1352 headline)))
1353 toc-entries "")
1354 (org-e-html-make-string
1355 (- prev-level start-level) "</li>\n</ul>\n"))))
1357 (defun org-e-html-toc (depth info)
1358 (assert (wholenump depth))
1359 (let* ((headlines (org-export-collect-headlines info depth))
1360 (toc-entries
1361 (loop for headline in headlines collect
1362 (list (org-e-html-headline-text
1363 headline info 'org-e-html-toc-entry-formatter)
1364 (org-export-get-relative-level headline info)))))
1365 (when toc-entries
1366 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
1367 (concat
1368 "<div id=\"table-of-contents\">\n"
1369 (org-e-html-format-heading lang-specific-heading
1370 (or org-e-html-toplevel-hlevel 1))
1371 "<div id=\"text-table-of-contents\">"
1372 (org-e-html-toc-text toc-entries)
1373 "</div>\n"
1374 "</div>\n")))))
1376 (defun org-e-html-begin-outline (level1 snumber title tags
1377 target extra-targets extra-class)
1378 (let* ((class (format "outline-%d" level1))
1379 (class (if extra-class (concat class " " extra-class) class))
1380 (id (format "outline-container-%s"
1381 (org-lparse-suffix-from-snumber snumber)))
1382 (extra (concat (when id (format " id=\"%s\"" id))
1383 (when class (format " class=\"%s\"" class)))))
1384 (org-lparse-insert-tag "<div%s>" extra)
1385 (insert
1386 (org-lparse-format 'HEADING
1387 (org-lparse-format
1388 'HEADLINE title extra-targets tags snumber level1)
1389 level1 target))))
1391 (defun org-e-html-end-outline ()
1392 (org-lparse-insert-tag "</div>"))
1395 ;; (defun org-e-html-format-heading (text level &optional id)
1396 ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1397 ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1399 (defun org-e-html-suffix-from-snumber (snumber)
1400 (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
1401 (href (cdr (assoc (concat "sec-" snu)
1402 org-export-preferred-target-alist))))
1403 (org-solidify-link-text (or href snu))))
1405 (defun org-e-html-format-outline (contents level1 snumber title
1406 tags target extra-targets extra-class)
1407 (let* ((class (format "outline-%d" level1))
1408 (class (if extra-class (concat class " " extra-class) class))
1409 (id (and snumber ;; FIXME
1410 (format "outline-container-%s"
1411 (org-e-html-suffix-from-snumber snumber))))
1412 (extra (concat (when id (format " id=\"%s\"" id))
1413 (when class (format " class=\"%s\"" class)))))
1414 (concat
1415 (format "<div%s>\n" extra)
1416 (org-e-html-format-heading
1417 (org-e-html-format-headline title extra-targets tags snumber level1)
1418 level1 target)
1419 contents
1420 "</div>")))
1422 (defun org-e-html-begin-outline-text (level1 snumber extra-class)
1423 (let* ((class (format "outline-text-%d" level1))
1424 (class (if extra-class (concat class " " extra-class) class))
1425 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
1426 (extra (concat (when id (format " id=\"%s\"" id))
1427 (when class (format " class=\"%s\"" class)))))
1428 (org-lparse-insert-tag "<div%s>" extra)))
1430 (defun org-e-html-end-outline-text ()
1431 (org-lparse-insert-tag "</div>"))
1433 ;; (defun org-e-html-format-line (line)
1434 ;; (case org-lparse-dyn-current-environment
1435 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1436 ;; (t (concat line "\n"))))
1438 (defun org-e-html-format-comment (fmt &rest args)
1439 (let ((comment (apply 'format fmt args)))
1440 (format "\n<!-- %s -->\n" comment)))
1442 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1443 "Turn todo keyword into a valid class name.
1444 Replaces invalid characters with \"_\"."
1445 (save-match-data
1446 (while (string-match "[^a-zA-Z0-9_]" kwd)
1447 (setq kwd (replace-match "_" t t kwd))))
1448 kwd)
1450 (defun org-e-html-format-fontify (text style &optional id)
1451 (let (class extra how)
1452 (cond
1453 ((eq style 'underline)
1454 (setq extra " style=\"text-decoration:underline;\"" ))
1455 ((setq how (cdr (assoc style
1456 '((bold . ("<b>" . "</b>"))
1457 (emphasis . ("<i>" . "</i>"))
1458 (code . ("<code>" . "</code>"))
1459 (verbatim . ("<code>" . "</code>"))
1460 (strike . ("<del>" . "</del>"))
1461 (subscript . ("<sub>" . "</sub>"))
1462 (superscript . ("<sup>" . "</sup>")))))))
1463 ((listp style)
1464 (setq class (mapconcat 'identity style " ")))
1465 ((stringp style)
1466 (setq class style))
1467 (t (error "Unknown style %S" style)))
1469 (setq extra (concat (when class (format " class=\"%s\"" class))
1470 (when id (format " id=\"%s\"" id))
1471 extra))
1473 (let ((tags (or how '("<span%s>" . "</span>"))))
1474 (concat (format (car tags) extra) text (cdr tags)))))
1476 (defun org-e-html-format-link (text href &optional extra)
1477 (let ((extra (concat (format " href=\"%s\"" href)
1478 (and extra (concat " " extra)))))
1479 (format "<a%s>%s</a>" extra text)))
1481 (defun org-e-html-format-internal-link (text href &optional extra)
1482 (org-e-html-format-link text (concat "#" href) extra))
1484 (defun org-e-html-format-heading (text level &optional id)
1485 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1486 (concat (format "<h%d%s>" level extra) text (format "</h%d>\n" level))))
1488 (defun org-e-html-format-anchor (text name &optional class)
1489 (let* ((id name)
1490 (extra (concat
1491 (when name (format " name=\"%s\"" name))
1492 (when id (format " id=\"%s\"" id))
1493 (when class (format " class=\"%s\"" class)))))
1494 (format "<a%s>%s</a>" extra text)))
1496 (defun org-e-html-format-extra-targets (extra-targets)
1497 (if (not extra-targets) ""
1498 (mapconcat (lambda (x)
1499 (when x
1500 (setq x (org-solidify-link-text
1501 (if (org-uuidgen-p x) (concat "ID-" x) x)))
1502 (org-e-html-format-anchor "" x))) extra-targets "")))
1504 (defun org-e-html-format-org-tags (tags)
1505 (if (not tags) ""
1506 (org-e-html-format-fontify
1507 (mapconcat
1508 (lambda (x)
1509 (org-e-html-format-fontify
1510 x (concat org-e-html-tag-class-prefix
1511 (org-e-html-fix-class-name x))))
1512 (org-split-string tags ":")
1513 "&nbsp;") "tag")))
1515 (defun org-e-html-format-section-number (&optional snumber level)
1516 ;; FIXME
1517 (and org-export-with-section-numbers
1518 ;; (not org-lparse-body-only)
1519 snumber level
1520 (org-e-html-format-fontify snumber (format "section-number-%d" level))))
1522 (defun org-e-html-format-headline (title extra-targets tags
1523 &optional snumber level)
1524 (concat
1525 (org-e-html-format-extra-targets extra-targets)
1526 (concat (org-e-html-format-section-number snumber level) " ")
1527 title
1528 (and tags (concat "&nbsp;&nbsp;&nbsp;"
1529 (org-e-html-format-org-tags tags)))))
1531 (defun org-e-html-format-footnote-reference (n def refcnt)
1532 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1533 (format org-e-html-footnote-format
1534 (format
1535 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1536 n extra n n))))
1538 (defun org-e-html-format-footnotes-section (section-name definitions)
1539 (if (not definitions) ""
1540 (format org-e-html-footnotes-section section-name definitions)))
1542 (defun org-e-html-format-footnote-definition (fn)
1543 (let ((n (car fn)) (def (cdr fn)))
1544 (format
1545 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1546 (format
1547 (format org-e-html-footnote-format
1548 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1549 n n n) def)))
1551 (defun org-e-html-footnote-section (info)
1552 (let* ((fn-alist (org-export-collect-footnote-definitions
1553 (plist-get info :parse-tree) info))
1555 (fn-alist
1556 (loop for (n type raw) in fn-alist collect
1557 (cons n (if (equal (org-element-type raw) 'org-data)
1558 (org-trim (org-export-data raw 'e-html info))
1559 (format "<p>%s</p>"
1560 (org-trim (org-export-secondary-string
1561 raw 'e-html info))))))))
1562 (when fn-alist
1563 (org-e-html-format-footnotes-section
1564 (nth 4 (or (assoc (plist-get info :language)
1565 org-export-language-setup)
1566 (assoc "en" org-export-language-setup)))
1568 (format
1569 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">\n%s\n</table>\n"
1570 (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
1572 (defun org-e-html-format-org-entity (wd)
1573 (org-entity-get-representation wd 'html))
1575 (defun org-e-html-get-coding-system-for-write ()
1576 (or org-e-html-coding-system
1577 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1579 (defun org-e-html-get-coding-system-for-save ()
1580 (or org-e-html-coding-system
1581 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1583 (defun org-e-html-format-date (info)
1584 (let ((date (plist-get info :date)))
1585 (cond
1586 ((and date (string-match "%" date))
1587 (format-time-string date))
1588 (date date)
1589 (t (format-time-string "%Y-%m-%d %T %Z")))))
1593 ;;; Internal Functions (Ngz)
1595 (defun org-e-html--caption/label-string (caption label info)
1596 "Return caption and label HTML string for floats.
1598 CAPTION is a cons cell of secondary strings, the car being the
1599 standard caption and the cdr its short form. LABEL is a string
1600 representing the label. INFO is a plist holding contextual
1601 information.
1603 If there's no caption nor label, return the empty string.
1605 For non-floats, see `org-e-html--wrap-label'."
1606 (setq label nil) ;; FIXME
1608 (let ((label-str (if label (format "\\label{%s}" label) "")))
1609 (cond
1610 ((and (not caption) (not label)) "")
1611 ((not caption) (format "\\label{%s}\n" label))
1612 ;; Option caption format with short name.
1613 ((cdr caption)
1614 (format "\\caption[%s]{%s%s}\n"
1615 (org-export-secondary-string (cdr caption) 'e-html info)
1616 label-str
1617 (org-export-secondary-string (car caption) 'e-html info)))
1618 ;; Standard caption format.
1619 ;; (t (format "\\caption{%s%s}\n"
1620 ;; label-str
1621 ;; (org-export-secondary-string (car caption) 'e-html info)))
1623 (t (org-export-secondary-string (car caption) 'e-html info)))))
1625 (defun org-e-html--find-verb-separator (s)
1626 "Return a character not used in string S.
1627 This is used to choose a separator for constructs like \\verb."
1628 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1629 (loop for c across ll
1630 when (not (string-match (regexp-quote (char-to-string c)) s))
1631 return (char-to-string c))))
1633 (defun org-e-html--make-option-string (options)
1634 "Return a comma separated string of keywords and values.
1635 OPTIONS is an alist where the key is the options keyword as
1636 a string, and the value a list containing the keyword value, or
1637 nil."
1638 (mapconcat (lambda (pair)
1639 (concat (first pair)
1640 (when (> (length (second pair)) 0)
1641 (concat "=" (second pair)))))
1642 options
1643 ","))
1645 (defun org-e-html--quotation-marks (text info)
1646 "Export quotation marks depending on language conventions.
1647 TEXT is a string containing quotation marks to be replaced. INFO
1648 is a plist used as a communication channel."
1649 (mapc (lambda(l)
1650 (let ((start 0))
1651 (while (setq start (string-match (car l) text start))
1652 (let ((new-quote (concat (match-string 1 text) (cdr l))))
1653 (setq text (replace-match new-quote t t text))))))
1654 (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
1655 ;; Falls back on English.
1656 (assoc "en" org-e-html-quotes))))
1657 text)
1659 (defun org-e-html--wrap-label (element output)
1660 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1661 This function shouldn't be used for floats. See
1662 `org-e-html--caption/label-string'."
1663 ;; (let ((label (org-element-property :name element)))
1664 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1665 ;; output
1666 ;; (concat (format "\\label{%s}\n" label) output)))
1667 output)
1671 ;;; Template
1673 (defun org-e-html-meta-info (info)
1674 (let* ((title (org-export-secondary-string
1675 (plist-get info :title) 'e-html info))
1676 (author (and (plist-get info :with-author)
1677 (let ((auth (plist-get info :author)))
1678 (and auth (org-export-secondary-string
1679 auth 'e-html info)))))
1680 (description (plist-get info :description))
1681 (keywords (plist-get info :keywords)))
1682 (concat
1683 (format "<title>%s</title>\n" title)
1684 (format
1685 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1686 (and coding-system-for-write
1687 (fboundp 'coding-system-get)
1688 (coding-system-get coding-system-for-write
1689 'mime-charset)))
1690 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1691 (format "<meta name=\"generator\" content=\"Org-mode\"/>")
1692 (format "<meta name=\"generated\" content=\"%s\"/>\n"
1693 (org-e-html-format-date info))
1694 (format "<meta name=\"author\" content=\"%s\"/>\n" author)
1695 (format "<meta name=\"description\" content=\"%s\"/>\n" description)
1696 (format " <meta name=\"keywords\" content=\"%s\"/>\n" keywords))))
1698 (defun org-e-html-style (info)
1699 (concat
1700 (when (plist-get info :style-include-default)
1701 org-e-html-style-default)
1702 (plist-get info :style)
1703 (plist-get info :style-extra)
1704 "\n"
1705 (when (plist-get info :style-include-scripts)
1706 org-e-html-scripts)))
1708 (defun org-e-html-mathjax-config (template options in-buffer)
1709 "Insert the user setup into the matchjax template."
1710 (let (name val (yes " ") (no "// ") x)
1711 (mapc
1712 (lambda (e)
1713 (setq name (car e) val (nth 1 e))
1714 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1715 (setq val (car (read-from-string
1716 (substring in-buffer (match-end 0))))))
1717 (if (not (stringp val)) (setq val (format "%s" val)))
1718 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1719 (setq template (replace-match val t t template))))
1720 options)
1721 (setq val (nth 1 (assq 'mathml options)))
1722 (if (string-match (concat "\\<mathml:") in-buffer)
1723 (setq val (car (read-from-string
1724 (substring in-buffer (match-end 0))))))
1725 ;; Exchange prefixes depending on mathml setting
1726 (if (not val) (setq x yes yes no no x))
1727 ;; Replace cookies to turn on or off the config/jax lines
1728 (if (string-match ":MMLYES:" template)
1729 (setq template (replace-match yes t t template)))
1730 (if (string-match ":MMLNO:" template)
1731 (setq template (replace-match no t t template)))
1732 ;; Return the modified template
1733 template))
1735 (defun org-e-html-mathjax (info)
1736 (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
1737 (and org-export-have-math
1738 (eq (plist-get info :HTML-fragments) t)))
1739 (org-e-html-mathjax-config
1740 org-e-html-mathjax-template
1741 org-e-html-mathjax-options
1742 (or (plist-get info :mathjax) ""))))
1744 (defun org-e-html-preamble (info)
1745 (when (plist-get info :html-preamble)
1746 (let* ((title (plist-get info :title))
1747 (date (org-e-html-format-date info))
1748 (author (plist-get info :author))
1749 (lang-words (or (assoc (plist-get info :language)
1750 org-export-language-setup)
1751 (assoc "en" org-export-language-setup)))
1752 (email (plist-get info :email))
1753 (html-pre-real-contents
1754 (cond
1755 ((functionp (plist-get info :html-preamble))
1756 (with-temp-buffer
1757 (funcall (plist-get info :html-preamble))
1758 (buffer-string)))
1759 ((stringp (plist-get info :html-preamble))
1760 (format-spec (plist-get info :html-preamble)
1761 `((?t . ,title) (?a . ,author)
1762 (?d . ,date) (?e . ,email))))
1764 (format-spec
1765 (or (cadr (assoc (nth 0 lang-words)
1766 org-e-html-preamble-format))
1767 (cadr (assoc "en" org-e-html-preamble-format)))
1768 `((?t . ,title) (?a . ,author)
1769 (?d . ,date) (?e . ,email)))))))
1770 (when (not (equal html-pre-real-contents ""))
1771 (concat
1772 (format "
1773 <div id=\"%s\"> " (nth 0 org-e-html-divs))
1776 html-pre-real-contents
1778 </div>")))))
1780 (defun org-e-html-postamble (info)
1781 (concat
1782 (when (and (not body-only)
1783 (plist-get info :html-postamble))
1784 (let* ((html-post (plist-get info :html-postamble))
1785 (date (org-e-html-format-date info))
1786 (author (plist-get info :author))
1787 (email (plist-get info :email))
1788 (lang-words (or (assoc (plist-get info :language)
1789 org-export-language-setup)
1790 (assoc "en" org-export-language-setup)))
1791 (email
1792 (mapconcat (lambda(e)
1793 (format "<a href=\"mailto:%s\">%s</a>" e e))
1794 (split-string email ",+ *")
1795 ", "))
1796 (html-validation-link (or org-e-html-validation-link ""))
1797 (creator-info
1798 (concat "Org version " org-version " with Emacs version "
1799 (number-to-string emacs-major-version))))
1800 (concat
1801 ;; begin postamble
1803 <div id=\"" (nth 2 org-e-html-divs) "\">"
1804 (cond
1805 ;; auto postamble
1806 ((eq (plist-get info :html-postamble) 'auto)
1807 (concat
1808 (when (plist-get info :time-stamp-file)
1809 (format "
1810 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
1811 (when (and (plist-get info :with-author) author)
1812 (format "
1813 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
1814 (when (and (plist-get info :with-email) email)
1815 (format "
1816 <p class=\"email\"> %s </p>" email))
1817 (when (plist-get info :with-creator)
1818 (format "
1819 <p class=\"creator\"> %s </p>" creator-info))
1820 html-validation-link "\n"))
1821 ;; postamble from a string
1822 ((stringp (plist-get info :html-postamble))
1823 (format-spec (plist-get info :html-postamble)
1824 `((?a . ,author) (?e . ,email)
1825 (?d . ,date) (?c . ,creator-info)
1826 (?v . ,html-validation-link))))
1828 ;; postamble from a function
1829 ((functionp (plist-get info :html-postamble))
1830 (with-temp-buffer
1831 (funcall (plist-get info :html-postamble))
1832 (buffer-string)))
1833 ;; default postamble
1835 (format-spec
1836 (or (cadr (assoc (nth 0 lang-words)
1837 org-e-html-postamble-format))
1838 (cadr (assoc "en" org-e-html-postamble-format)))
1839 `((?a . ,author) (?e . ,email)
1840 (?d . ,date) (?c . ,creator-info)
1841 (?v . ,html-validation-link)))))
1843 </div>")))
1844 ;; org-e-html-html-helper-timestamp
1847 (defun org-e-html-template (contents info)
1848 "Return complete document string after HTML conversion.
1849 CONTENTS is the transcoded contents string. RAW-DATA is the
1850 original parsed data. INFO is a plist holding export options."
1851 (concat
1852 (format
1853 (or (and (stringp org-e-html-xml-declaration)
1854 org-e-html-xml-declaration)
1855 (cdr (assoc (plist-get info :html-extension)
1856 org-e-html-xml-declaration))
1857 (cdr (assoc "html" org-e-html-xml-declaration))
1860 (or (and coding-system-for-write
1861 (fboundp 'coding-system-get)
1862 (coding-system-get coding-system-for-write
1863 'mime-charset))
1864 "iso-8859-1"))
1866 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1867 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1868 (format "
1869 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1870 (plist-get info :language) (plist-get info :language))
1872 <head>"
1873 (org-e-html-meta-info info) ; meta
1874 (org-e-html-style info) ; style
1875 (org-e-html-mathjax info) ; mathjax
1877 </head>"
1880 <body>"
1881 (let ((link-up (and (plist-get info :link-up)
1882 (string-match "\\S-" (plist-get info :link-up))
1883 (plist-get info :link-up)))
1884 (link-home (and (plist-get info :link-home)
1885 (string-match "\\S-" (plist-get info :link-home))
1886 (plist-get info :link-home))))
1887 (when (or link-up link-home)
1888 (format org-e-html-home/up-format
1889 (or link-up link-home)
1890 (or link-home link-up))))
1891 ;; preamble
1892 (org-e-html-preamble info)
1893 ;; begin content
1894 (format "
1895 <div id=\"%s\">" (or org-e-html-content-div
1896 (nth 1 org-e-html-divs)))
1897 ;; document title
1898 (format "
1899 <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
1900 ;; table of contents
1901 (let ((depth (plist-get info :with-toc)))
1902 (when (wholenump depth) (org-e-html-toc depth info)))
1903 ;; document contents
1904 contents
1905 ;; footnotes section
1906 (org-e-html-footnote-section info)
1907 ;; bibliography
1908 (org-e-html-bibliography)
1909 ;; end content
1910 (unless body-only
1912 </div>")
1914 ;; postamble
1915 (org-e-html-postamble info)
1917 (unless body-only
1919 </body>")
1921 </html>"))
1925 ;;; Transcode Functions
1927 ;;;; Block
1929 (defun org-e-html-center-block (center-block contents info)
1930 "Transcode a CENTER-BLOCK element from Org to HTML.
1931 CONTENTS holds the contents of the block. INFO is a plist
1932 holding contextual information."
1933 (org-e-html--wrap-label
1934 center-block
1935 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
1938 ;;;; Comment
1940 ;; Comments are ignored.
1943 ;;;; Comment Block
1945 ;; Comment Blocks are ignored.
1948 ;;;; Drawer
1950 (defun org-e-html-drawer (drawer contents info)
1951 "Transcode a DRAWER element from Org to HTML.
1952 CONTENTS holds the contents of the block. INFO is a plist
1953 holding contextual information."
1954 (let* ((name (org-element-property :drawer-name drawer))
1955 (output (if (functionp org-e-html-format-drawer-function)
1956 (funcall org-e-html-format-drawer-function
1957 name contents)
1958 ;; If there's no user defined function: simply
1959 ;; display contents of the drawer.
1960 contents)))
1961 (org-e-html--wrap-label drawer output)))
1964 ;;;; Dynamic Block
1966 (defun org-e-html-dynamic-block (dynamic-block contents info)
1967 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1968 CONTENTS holds the contents of the block. INFO is a plist
1969 holding contextual information. See
1970 `org-export-data'."
1971 (org-e-html--wrap-label dynamic-block contents))
1974 ;;;; Emphasis
1976 (defun org-e-html-emphasis (emphasis contents info)
1977 "Transcode EMPHASIS from Org to HTML.
1978 CONTENTS is the contents of the emphasized text. INFO is a plist
1979 holding contextual information.."
1980 (let* ((marker (org-element-property :marker emphasis)))
1981 (format (cdr (assoc marker org-e-html-emphasis-alist)) contents)))
1984 ;;;; Entity
1986 (defun org-e-html-entity (entity contents info)
1987 "Transcode an ENTITY object from Org to HTML.
1988 CONTENTS are the definition itself. INFO is a plist holding
1989 contextual information."
1990 ;; (let ((ent (org-element-property :latex entity)))
1991 ;; (if (org-element-property :latex-math-p entity)
1992 ;; (format "$%s$" ent)
1993 ;; ent))
1994 (org-element-property :html entity))
1997 ;;;; Example Block
2000 ;; (defun org-odt-format-source-code-or-example-colored
2001 ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
2003 (defun org-e-html-format-source-code-or-example-plain
2004 (lines lang caption textareap cols rows num cont rpllbl fmt)
2005 (setq lines
2006 (concat
2007 "<pre class=\"example\">\n"
2008 (cond
2009 (textareap
2010 (concat
2011 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2012 cols rows)
2013 lines "</textarea>\n</p>\n"))
2015 (with-temp-buffer
2016 (insert lines)
2017 (goto-char (point-min))
2018 (while (re-search-forward "[<>&]" nil t)
2019 (replace-match (cdr (assq (char-before)
2020 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2021 t t))
2022 (buffer-string))))
2023 "</pre>\n"))
2025 (unless textareap
2026 (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
2028 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
2029 ;; (setq lines (replace-match "\\1" t nil lines)))
2031 lines)
2033 (defun org-e-html-format-source-code-or-example-colored
2034 (lines lang caption textareap cols rows num cont rpllbl fmt)
2035 (let* ((lang-m (when lang
2036 (or (cdr (assoc lang org-src-lang-modes))
2037 lang)))
2038 (mode (and lang-m (intern
2039 (concat
2040 (if (symbolp lang-m)
2041 (symbol-name lang-m)
2042 lang-m)
2043 "-mode"))))
2044 (org-inhibit-startup t)
2045 (org-startup-folded nil))
2046 (setq lines
2047 (with-temp-buffer
2048 (insert lines)
2049 (if (functionp mode)
2050 (funcall mode)
2051 (fundamental-mode))
2052 (font-lock-fontify-buffer)
2053 ;; markup each line separately
2054 (org-remove-formatting-on-newlines-in-region
2055 (point-min) (point-max))
2056 (org-src-mode)
2057 (set-buffer-modified-p nil)
2058 (org-export-e-htmlize-region-for-paste
2059 (point-min) (point-max))))
2061 (when (string-match "<pre\\([^>]*\\)>\n*" lines)
2062 (setq lines (replace-match
2063 (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
2065 (when caption
2066 (setq lines
2067 (concat
2068 "<div class=\"org-src-container\">"
2069 (format "<label class=\"org-src-name\">%s</label>" caption)
2070 lines "</div>")))
2072 (unless textareap
2073 (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
2075 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
2076 ;; (setq lines (replace-match "\\1" t nil lines)))
2077 lines))
2079 (defun org-e-html-format-source-code-or-example
2080 (lang code &optional opts indent caption)
2081 "Format CODE from language LANG and return it formatted for export.
2082 The CODE is marked up in `org-export-current-backend' format.
2084 Check if a function by name
2085 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2086 use it as the custom formatter. Otherwise, use the default
2087 formatter. Default formatters are provided for docbook, html,
2088 latex and ascii backends. For example, use
2089 `org-e-html-format-source-code-or-example' to provide a custom
2090 formatter for export to \"html\".
2092 If LANG is nil, do not add any fontification.
2093 OPTS contains formatting options, like `-n' for triggering numbering lines,
2094 and `+n' for continuing previous numbering.
2095 Code formatting according to language currently only works for HTML.
2096 Numbering lines works for all three major backends (html, latex, and ascii).
2097 INDENT was the original indentation of the block."
2098 (save-match-data
2099 (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain)
2100 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2101 (setq opts (or opts "")
2102 num (string-match "[-+]n\\>" opts)
2103 cont (string-match "\\+n\\>" opts)
2104 rpllbl (string-match "-r\\>" opts)
2105 keepp (string-match "-k\\>" opts)
2106 textareap (string-match "-t\\>" opts)
2107 preserve-indentp (or org-src-preserve-indentation
2108 (string-match "-i\\>" opts))
2109 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2110 (string-to-number (match-string 1 opts))
2112 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2113 (string-to-number (match-string 1 opts))
2114 (org-count-lines code))
2115 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2116 (match-string 1 opts)))
2117 (when (and textareap
2118 ;; (eq org-export-current-backend 'html)
2120 ;; we cannot use numbering or highlighting.
2121 (setq num nil cont nil lang nil))
2122 (if keepp (setq rpllbl 'keep))
2123 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2124 (when (string-match "^," rtn)
2125 (setq rtn (with-temp-buffer
2126 (insert rtn)
2127 ;; Free up the protected lines
2128 (goto-char (point-min))
2129 (while (re-search-forward "^," nil t)
2130 (if (or (equal lang "org")
2131 (save-match-data
2132 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2133 (replace-match ""))
2134 (end-of-line 1))
2135 (buffer-string))))
2136 (when lang
2137 (if (featurep 'xemacs)
2138 (require 'htmlize)
2139 (require 'htmlize nil t)))
2141 (setq backend-formatter
2142 (cond
2143 ((fboundp 'htmlize-region-for-paste)
2144 'org-e-html-format-source-code-or-example-colored)
2146 (message
2147 "htmlize.el 1.34 or later is needed for source code formatting")
2148 'org-e-html-format-source-code-or-example-plain)))
2149 (funcall backend-formatter rtn lang caption textareap cols rows
2150 num cont rpllbl fmt))))
2152 (defun org-e-html-example-block (example-block contents info)
2153 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2154 CONTENTS is nil. INFO is a plist holding contextual information."
2155 (let* ((options (or (org-element-property :options example-block) ""))
2156 (value (org-export-handle-code example-block info)))
2157 ;; (org-e-html--wrap-label
2158 ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
2159 (org-e-html--wrap-label
2160 example-block (org-e-html-format-source-code-or-example nil value))))
2163 ;;;; Export Snippet
2165 (defun org-e-html-export-snippet (export-snippet contents info)
2166 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2167 CONTENTS is nil. INFO is a plist holding contextual information."
2168 (when (eq (org-export-snippet-backend export-snippet) 'e-html)
2169 (org-element-property :value export-snippet)))
2172 ;;;; Export Block
2174 (defun org-e-html-export-block (export-block contents info)
2175 "Transcode a EXPORT-BLOCK element from Org to HTML.
2176 CONTENTS is nil. INFO is a plist holding contextual information."
2177 (when (string= (org-element-property :type export-block) "latex")
2178 (org-remove-indentation (org-element-property :value export-block))))
2181 ;;;; Fixed Width
2183 (defun org-e-html-fixed-width (fixed-width contents info)
2184 "Transcode a FIXED-WIDTH element from Org to HTML.
2185 CONTENTS is nil. INFO is a plist holding contextual information."
2186 (let* ((value (org-element-normalize-string
2187 (replace-regexp-in-string
2188 "^[ \t]*: ?" ""
2189 (org-element-property :value fixed-width)))))
2190 (org-e-html--wrap-label
2191 fixed-width (org-e-html-format-source-code-or-example nil value))))
2194 ;;;; Footnote Definition
2196 ;; Footnote Definitions are ignored.
2199 ;;;; Footnote Reference
2201 (defun org-e-html-footnote-reference (footnote-reference contents info)
2202 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2203 CONTENTS is nil. INFO is a plist holding contextual information."
2204 (concat
2205 ;; Insert separator between two footnotes in a row.
2206 (let ((prev (org-export-get-previous-element footnote-reference info)))
2207 (when (and (listp prev) (eq (car prev) 'footnote-reference))
2208 org-e-html-footnote-separator))
2209 (cond
2210 ((not (org-export-footnote-first-reference-p footnote-reference info))
2211 (org-e-html-format-footnote-reference
2212 (org-export-get-footnote-number footnote-reference info)
2213 "IGNORED" 100))
2214 ;; Inline definitions are secondary strings.
2215 ((eq (org-element-property :type footnote-reference) 'inline)
2216 (org-e-html-format-footnote-reference
2217 (org-export-get-footnote-number footnote-reference info)
2218 "IGNORED" 1))
2219 ;; Non-inline footnotes definitions are full Org data.
2220 (t (org-e-html-format-footnote-reference
2221 (org-export-get-footnote-number footnote-reference info)
2222 "IGNORED" 1)))))
2225 ;;;; Headline
2227 (defun org-e-html-todo (todo)
2228 (when todo
2229 (org-e-html-format-fontify
2230 (concat
2231 org-e-html-todo-kwd-class-prefix
2232 (org-e-html-fix-class-name todo))
2233 (list (if (member todo org-done-keywords) "done" "todo")
2234 todo))))
2236 (defun org-e-html-headline-text (headline info &optional formatter)
2237 "Transcode an HEADLINE element from Org to HTML.
2238 CONTENTS holds the contents of the headline. INFO is a plist
2239 holding contextual information."
2240 (let* ((numberedp (plist-get info :section-numbers))
2241 (level (org-export-get-relative-level headline info))
2242 (todo (and (plist-get info :with-todo-keywords)
2243 (let ((todo (org-element-property
2244 :todo-keyword headline)))
2245 (and todo
2246 (org-export-secondary-string todo 'e-html info)))))
2247 (todo-type (and todo (org-element-property :todo-type headline)))
2248 (priority (and (plist-get info :with-priority)
2249 (org-element-property :priority headline)))
2250 (text (org-export-secondary-string
2251 (org-element-property :title headline) 'e-html info))
2252 (tags (and (plist-get info :with-tags)
2253 (org-element-property :tags headline)))
2255 (headline-no (org-export-get-headline-number headline info))
2256 (headline-label
2257 (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
2258 (headline-labels (list headline-label))
2259 (headline-no (org-export-get-headline-number headline info))
2260 (section-no (mapconcat 'number-to-string headline-no "."))
2261 (primary-target (car (last headline-labels)))
2262 (secondary-targets (butlast headline-labels))
2263 (extra-class nil)
2264 (formatter (or (and (functionp formatter) formatter)
2265 org-e-html-headline-formatter)))
2266 (funcall formatter level section-no todo todo-type priority
2267 text tags primary-target secondary-targets extra-class)))
2269 (defun org-e-html-headline (headline contents info)
2270 "Transcode an HEADLINE element from Org to HTML.
2271 CONTENTS holds the contents of the headline. INFO is a plist
2272 holding contextual information."
2273 (let* ((class (plist-get info :latex-class))
2274 (numberedp (plist-get info :section-numbers))
2275 ;; Get level relative to current parsed data.
2276 (level (org-export-get-relative-level headline info))
2277 ;; (class-sectionning (assoc class org-e-html-classes))
2278 ;; Section formatting will set two placeholders: one for the
2279 ;; title and the other for the contents.
2280 ;; (section-fmt
2281 ;; (let ((sec (if (and (symbolp (nth 2 class-sectionning))
2282 ;; (fboundp (nth 2 class-sectionning)))
2283 ;; (funcall (nth 2 class-sectionning) level numberedp)
2284 ;; (nth (1+ level) class-sectionning))))
2285 ;; (cond
2286 ;; ;; No section available for that LEVEL.
2287 ;; ((not sec) nil)
2288 ;; ;; Section format directly returned by a function.
2289 ;; ((stringp sec) sec)
2290 ;; ;; (numbered-section . unnumbered-section)
2291 ;; ((not (consp (cdr sec)))
2292 ;; (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
2293 ;; ;; (numbered-open numbered-close)
2294 ;; ((= (length sec) 2)
2295 ;; (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
2296 ;; ;; (num-in num-out no-num-in no-num-out)
2297 ;; ((= (length sec) 4)
2298 ;; (if numberedp
2299 ;; (concat (car sec) "\n%s" (nth 1 sec))
2300 ;; (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
2301 (text (org-export-secondary-string
2302 (org-element-property :title headline) 'e-html info))
2303 (todo (and (plist-get info :with-todo-keywords)
2304 (let ((todo (org-element-property
2305 :todo-keyword headline)))
2306 (and todo
2307 (org-export-secondary-string todo 'e-html info)))))
2308 (todo-type (and todo (org-element-property :todo-type headline)))
2309 (tags (and (plist-get info :with-tags)
2310 (org-element-property :tags headline)))
2311 (priority (and (plist-get info :with-priority)
2312 (org-element-property :priority headline)))
2313 ;; Create the headline text.
2314 (full-text (if (functionp org-e-html-format-headline-function)
2315 ;; User-defined formatting function.
2316 (funcall org-e-html-format-headline-function
2317 todo todo-type priority text tags)
2318 ;; Default formatting.
2319 (concat
2320 ;; (when todo
2321 ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2322 (org-e-html-todo todo) " "
2323 (when priority (format "\\framebox{\\#%c} " priority))
2324 text
2325 ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
2327 ;; Associate some \label to the headline for internal links.
2328 ;; (headline-label
2329 ;; (format "\\label{sec-%s}\n"
2330 ;; (mapconcat 'number-to-string
2331 ;; (org-export-get-headline-number headline info)
2332 ;; "-")))
2334 ;; FIXME - begin
2335 (headline-no (org-export-get-headline-number headline info))
2336 (headline-label
2337 (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
2338 (headline-labels (list headline-label))
2339 (headline-no (org-export-get-headline-number headline info))
2340 (section-no (mapconcat 'number-to-string headline-no "."))
2341 ;; FIXME - end
2343 (pre-blanks (make-string
2344 (org-element-property :pre-blank headline) 10)))
2345 (cond
2346 ;; Case 1: This is a footnote section: ignore it.
2347 ((org-element-property :footnote-section-p headline) nil)
2348 ;; Case 2. This is a deep sub-tree: export it as a list item.
2349 ;; Also export as items headlines for which no section
2350 ;; format has been found.
2351 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
2352 ;; Build the real contents of the sub-tree.
2353 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
2354 (itemized-body (org-e-html-format-list-item
2355 contents type nil nil full-text)))
2356 (concat
2357 (and (org-export-first-sibling-p headline info)
2358 (org-e-html-begin-plain-list type))
2359 itemized-body
2360 (and (org-export-last-sibling-p headline info)
2361 (org-e-html-end-plain-list type)))))
2362 ;; Case 3. Standard headline. Export it as a section.
2364 ;; (format section-fmt full-text
2365 ;; (concat headline-label pre-blanks contents))
2367 (org-e-html-format-outline contents level section-no full-text tags
2368 (car (last headline-labels))
2369 (butlast headline-labels) nil)))))
2372 ;;;; Horizontal Rule
2374 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
2375 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2376 CONTENTS is nil. INFO is a plist holding contextual information."
2377 (let ((attr (mapconcat #'identity
2378 (org-element-property :attr_html horizontal-rule)
2379 " ")))
2380 (org-e-html--wrap-label horizontal-rule "<hr/>\n")))
2383 ;;;; Inline Babel Call
2385 ;; Inline Babel Calls are ignored.
2388 ;;;; Inline Src Block
2390 (defun org-e-html-inline-src-block (inline-src-block contents info)
2391 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2392 CONTENTS holds the contents of the item. INFO is a plist holding
2393 contextual information."
2394 (let* ((org-lang (org-element-property :language inline-src-block))
2395 (code (org-element-property :value inline-src-block))
2396 (separator (org-e-html--find-verb-separator code)))
2397 (error "FIXME")))
2400 ;;;; Inlinetask
2402 (defun org-e-html-format-section (text class &optional id)
2403 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2404 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2406 (defun org-e-html-inlinetask (inlinetask contents info)
2407 "Transcode an INLINETASK element from Org to HTML.
2408 CONTENTS holds the contents of the block. INFO is a plist
2409 holding contextual information."
2410 (let ((title (org-export-secondary-string
2411 (org-element-property :title inlinetask) 'e-html info))
2412 (todo (and (plist-get info :with-todo-keywords)
2413 (let ((todo (org-element-property
2414 :todo-keyword inlinetask)))
2415 (and todo
2416 (org-export-secondary-string todo 'e-html info)))))
2417 (todo-type (org-element-property :todo-type inlinetask))
2418 (tags (and (plist-get info :with-tags)
2419 (org-element-property :tags inlinetask)))
2420 (priority (and (plist-get info :with-priority)
2421 (org-element-property :priority inlinetask))))
2422 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2423 ;; with appropriate arguments.
2424 (if (functionp org-e-html-format-inlinetask-function)
2425 (funcall org-e-html-format-inlinetask-function
2426 todo todo-type priority title tags contents)
2427 ;; Otherwise, use a default template.
2428 (org-e-html--wrap-label
2429 inlinetask
2430 (let ((full-title
2431 (concat
2432 (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2433 (when priority (format "\\framebox{\\#%c} " priority))
2434 title
2435 (when tags (format "\\hfill{}\\textsc{%s}" tags)))))
2436 (format (concat "\\begin{center}\n"
2437 "\\fbox{\n"
2438 "\\begin{minipage}[c]{.6\\textwidth}\n"
2439 "%s\n\n"
2440 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
2441 "%s"
2442 "\\end{minipage}\n"
2443 "}\n"
2444 "\\end{center}")
2445 full-title contents))))))
2448 ;;;; Item
2450 (defun org-e-html-format-list-item (contents type checkbox
2451 &optional term-counter-id
2452 headline)
2453 (when checkbox
2454 (setq checkbox
2455 (org-e-html-format-fontify (case checkbox
2456 (on "[X]")
2457 (off "[&nbsp;]")
2458 (trans "[-]")) 'code)))
2459 (concat
2460 (case type
2461 (ordered
2462 (let* ((counter term-counter-id)
2463 (extra (if counter (format " value=\"%s\"" counter) "")))
2464 (format "<li%s>" extra)))
2465 (unordered
2466 (let* ((id term-counter-id)
2467 (extra (if id (format " id=\"%s\"" id) "")))
2468 (concat
2469 (format "<li%s>" extra)
2470 (when headline (concat headline "<br/>")))))
2471 (descriptive
2472 (let* ((term term-counter-id))
2473 (setq term (or term "(no term)"))
2474 (concat (format "<dt> %s </dt>" term) "<dd>"))))
2475 checkbox (and checkbox " ") contents
2476 (case type
2477 (ordered "</li>")
2478 (unordered "</li>")
2479 (descriptive "</dd>"))))
2481 (defun org-e-html-item (item contents info)
2482 "Transcode an ITEM element from Org to HTML.
2483 CONTENTS holds the contents of the item. INFO is a plist holding
2484 contextual information."
2485 ;; Grab `:level' from plain-list properties, which is always the
2486 ;; first element above current item.
2487 (let* ((plain-list (org-export-get-parent item info))
2488 (type (org-element-property :type plain-list))
2489 (level (org-element-property :level plain-list))
2490 (counter (org-element-property :counter item))
2491 (checkbox (org-element-property :checkbox item))
2492 (tag (let ((tag (org-element-property :tag item)))
2493 (and tag (org-export-secondary-string tag 'e-html info)))))
2494 (org-e-html-format-list-item
2495 contents type checkbox (or tag counter))))
2498 ;;;; Keyword
2500 (defun org-e-html-keyword (keyword contents info)
2501 "Transcode a KEYWORD element from Org to HTML.
2502 CONTENTS is nil. INFO is a plist holding contextual information."
2503 (let ((key (downcase (org-element-property :key keyword)))
2504 (value (org-element-property :value keyword)))
2505 (cond
2506 ((string= key "latex") value)
2507 ((string= key "index") (format "\\index{%s}" value))
2508 ((string= key "target")
2509 (format "\\label{%s}" (org-export-solidify-link-text value)))
2510 ((string= key "toc")
2511 (let ((value (downcase value)))
2512 (cond
2513 ((string-match "\\<headlines\\>" value)
2514 (let ((depth (or (and (string-match "[0-9]+" value)
2515 (string-to-number (match-string 0 value)))
2516 (plist-get info :with-toc))))
2517 (when (wholenump depth) (org-e-html-toc depth info))))
2518 ((string= "tables" value) "\\listoftables")
2519 ((string= "figures" value) "\\listoffigures")
2520 ((string= "listings" value)
2521 (cond
2522 ;; At the moment, src blocks with a caption are wrapped
2523 ;; into a figure environment.
2524 (t "\\listoffigures")))))))))
2527 ;;;; Latex Environment
2529 (defun org-e-html-format-latex (latex-frag processing-type)
2530 (let* ((cache-relpath
2531 (concat "ltxpng/" (file-name-sans-extension
2532 (file-name-nondirectory (buffer-file-name)))))
2533 (cache-dir (file-name-directory (buffer-file-name )))
2534 (display-msg "Creating LaTeX Image..."))
2536 (with-temp-buffer
2537 (insert latex-frag)
2538 (org-format-latex cache-relpath cache-dir nil display-msg
2539 nil nil processing-type)
2540 (buffer-string))))
2542 (defun org-e-html-latex-environment (latex-environment contents info)
2543 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2544 CONTENTS is nil. INFO is a plist holding contextual information."
2545 (org-e-html--wrap-label
2546 latex-environment
2547 (let ((latex-frag
2548 (org-remove-indentation
2549 (org-element-property :value latex-environment)))
2550 (processing-type (plist-get info :LaTeX-fragments)))
2551 (cond
2552 ((member processing-type '(t mathjax))
2553 (org-e-html-format-latex latex-frag 'mathjax))
2554 ((equal processing-type 'dvipng)
2555 (let* ((formula-link (org-e-html-format-latex
2556 latex-frag processing-type)))
2557 (when (and formula-link
2558 (string-match "file:\\([^]]*\\)" formula-link))
2559 (org-e-html-format-inline-image (match-string 1 formula-link)))))
2561 latex-frag)))))
2564 ;;;; Latex Fragment
2566 (defun org-e-html-latex-fragment (latex-fragment contents info)
2567 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2568 CONTENTS is nil. INFO is a plist holding contextual information."
2569 ;; (org-element-property :value latex-fragment)
2570 (let* ((latex-frag (org-element-property :value latex-fragment)))
2571 (cond
2572 ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag)
2573 (let* ((label (match-string 1 latex-frag))
2574 (href (and label (org-export-solidify-link-text label)))
2575 (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
2576 (substring label (match-beginning 1))
2577 label)))
2578 (org-e-html-format-internal-link text href)))
2579 (t (let ((processing-type (plist-get info :LaTeX-fragments)))
2580 (cond
2581 ((member processing-type '(t mathjax))
2582 (org-e-html-format-latex latex-frag 'mathjax))
2583 ((equal processing-type 'dvipng)
2584 (let* ((formula-link (org-e-html-format-latex
2585 latex-frag processing-type)))
2586 (when (and formula-link
2587 (string-match "file:\\([^]]*\\)" formula-link))
2588 (org-e-html-format-inline-image
2589 (match-string 1 formula-link)))))
2590 (t latex-frag)))))))
2593 ;;;; Line Break
2595 (defun org-e-html-line-break (line-break contents info)
2596 "Transcode a LINE-BREAK object from Org to HTML.
2597 CONTENTS is nil. INFO is a plist holding contextual information."
2598 "<br/>")
2601 ;;;; Link
2603 (defun org-e-html-link--inline-image (link info)
2604 "Return HTML code for an inline image.
2605 LINK is the link pointing to the inline image. INFO is a plist
2606 used as a communication channel."
2607 (let* ((parent (org-export-get-parent-paragraph link info))
2608 (path (let ((raw-path (org-element-property :path link)))
2609 (if (not (file-name-absolute-p raw-path)) raw-path
2610 (expand-file-name raw-path))))
2611 (caption (org-e-html--caption/label-string
2612 (org-element-property :caption parent)
2613 (org-element-property :name parent)
2614 info))
2615 (label (org-element-property :name parent))
2616 ;; Retrieve latex attributes from the element around.
2617 (attr (let ((raw-attr
2618 (mapconcat #'identity
2619 (org-element-property :attr_html parent)
2620 " ")))
2621 (unless (string= raw-attr "") raw-attr))))
2622 ;; Now clear ATTR from any special keyword and set a default
2623 ;; value if nothing is left.
2624 (setq attr (if (not attr) "" (org-trim attr)))
2625 ;; Return proper string, depending on DISPOSITION.
2626 (let ((href (and label (org-export-solidify-link-text label))))
2627 (org-e-html-format-inline-image path caption href attr))))
2629 (defun org-e-html-link (link desc info)
2630 "Transcode a LINK object from Org to HTML.
2632 DESC is the description part of the link, or the empty string.
2633 INFO is a plist holding contextual information. See
2634 `org-export-data'."
2635 (let* ((type (org-element-property :type link))
2636 (raw-path (org-element-property :path link))
2637 ;; Ensure DESC really exists, or set it to nil.
2638 (desc (and (not (string= desc "")) desc))
2639 (imagep (org-export-inline-image-p
2640 link org-e-html-inline-image-rules))
2641 (path (cond
2642 ((member type '("http" "https" "ftp" "mailto"))
2643 (concat type ":" raw-path))
2644 ((string= type "file")
2645 (when (string-match "\\(.+\\)::.+" raw-path)
2646 (setq raw-path (match-string 1 raw-path)))
2647 (if (file-name-absolute-p raw-path)
2648 (concat "file://" (expand-file-name raw-path))
2649 ;; TODO: Not implemented yet. Concat also:
2650 ;; (org-export-directory :HTML info)
2651 (concat "file://" raw-path)))
2652 (t raw-path)))
2653 protocol)
2654 (cond
2655 ;; Image file.
2656 (imagep (org-e-html-link--inline-image link info))
2657 ;; Target or radioed target: replace link with the normalized
2658 ;; custom-id/target name.
2659 ((member type '("target" "radio"))
2660 (org-e-html-format-internal-link
2661 (or desc (org-export-secondary-string path 'e-html info))
2662 (org-export-solidify-link-text path)))
2663 ;; Links pointing to an headline: Find destination and build
2664 ;; appropriate referencing commanding.
2665 ((member type '("custom-id" "fuzzy" "id"))
2666 (let ((destination (if (string= type "fuzzy")
2667 (org-export-resolve-fuzzy-link link info)
2668 (org-export-resolve-id-link link info))))
2669 ;; Fuzzy link points to a target. Do as above.
2670 (case (org-element-type destination)
2671 (target
2672 (org-e-html-format-internal-link
2673 (or desc
2674 (org-export-secondary-string
2675 (org-element-property :raw-link link)
2676 'e-html info))
2677 (org-export-solidify-link-text
2678 (org-element-property :raw-value destination))))
2679 ;; Fuzzy link points to an headline. If headlines are
2680 ;; numbered and the link has no description, display
2681 ;; headline's number. Otherwise, display description or
2682 ;; headline's title.
2683 (headline
2684 (let ((label
2685 (format "sec-%s"
2686 (mapconcat
2687 'number-to-string
2688 (org-export-get-headline-number destination info)
2689 "-"))))
2690 (if (and (plist-get info :section-numbers) (not desc))
2691 (format "\\ref{%s}" label)
2692 (org-e-html-format-internal-link
2693 (or desc
2694 (org-export-secondary-string
2695 (org-element-property :title destination)
2696 'e-html info)) label))))
2697 ;; Fuzzy link points nowhere.
2698 (otherwise
2699 (org-e-html-format-fontify
2700 (or desc
2701 (org-export-secondary-string
2702 (org-element-property :raw-link link)
2703 'e-html info)) 'emphasis)))))
2704 ;; Coderef: replace link with the reference name or the
2705 ;; equivalent line number.
2706 ((string= type "coderef")
2707 (format (org-export-get-coderef-format path (or desc ""))
2708 (org-export-resolve-coderef path info)))
2709 ;; Link type is handled by a special function.
2710 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2711 (funcall protocol (org-link-unescape path) desc 'html))
2712 ;; External link with a description part.
2713 ((and path desc) (org-e-html-format-link desc path))
2714 ;; External link without a description part.
2715 (path (org-e-html-format-link path path))
2716 ;; No path, only description. Try to do something useful.
2717 (t (org-e-html-format-fontify desc 'emphasis)))))
2720 ;;;; Babel Call
2722 ;; Babel Calls are ignored.
2725 ;;;; Macro
2727 (defun org-e-html-macro (macro contents info)
2728 "Transcode a MACRO element from Org to HTML.
2729 CONTENTS is nil. INFO is a plist holding contextual information."
2730 ;; Use available tools.
2731 (org-export-expand-macro macro info))
2734 ;;;; Paragraph
2736 (defun org-e-html-paragraph (paragraph contents info)
2737 "Transcode a PARAGRAPH element from Org to HTML.
2738 CONTENTS is the contents of the paragraph, as a string. INFO is
2739 the plist used as a communication channel."
2740 (let* ((style nil) ; FIXME
2741 (class (cdr (assoc style '((footnote . "footnote")
2742 (verse . nil)))))
2743 (extra (if class (format " class=\"%s\"" class) ""))
2744 (parent (car (org-export-get-genealogy paragraph info))))
2745 (cond
2746 ((and (equal (car parent) 'item)
2747 (= (org-element-property :begin paragraph)
2748 (org-element-property :contents-begin parent)))
2749 ;; leading paragraph in a list item have no tags
2750 contents)
2751 (t (concat (format "<p%s> " extra) contents "</p>")))))
2754 ;;;; Plain List
2756 (defun org-e-html-begin-plain-list (type &optional arg1)
2757 (case type
2758 (ordered
2759 (format "<ol%s>" (if arg1 ; FIXME
2760 (format " start=\"%d\"" arg1)
2761 "")))
2762 (unordered "<ul>")
2763 (descriptive "<dl>")))
2765 (defun org-e-html-end-plain-list (type)
2766 (case type
2767 (ordered "</ol>")
2768 (unordered "</ul>")
2769 (descriptive "</dl>")))
2771 (defun org-e-html-plain-list (plain-list contents info)
2772 "Transcode a PLAIN-LIST element from Org to HTML.
2773 CONTENTS is the contents of the list. INFO is a plist holding
2774 contextual information."
2775 (let* (arg1 ;; FIXME
2776 (type (org-element-property :type plain-list))
2777 (attr (mapconcat #'identity
2778 (org-element-property :attr_html plain-list)
2779 " ")))
2780 (org-e-html--wrap-label
2781 plain-list (format "%s\n%s%s"
2782 (org-e-html-begin-plain-list type)
2783 contents (org-e-html-end-plain-list type)))))
2785 ;;;; Plain Text
2787 (defun org-e-html-convert-special-strings (string)
2788 "Convert special characters in STRING to HTML."
2789 (let ((all org-e-html-special-string-regexps)
2790 e a re rpl start)
2791 (while (setq a (pop all))
2792 (setq re (car a) rpl (cdr a) start 0)
2793 (while (string-match re string start)
2794 (setq string (replace-match rpl t nil string))))
2795 string))
2797 (defun org-e-html-encode-plain-text (s)
2798 "Convert plain text characters to HTML equivalent.
2799 Possible conversions are set in `org-export-html-protect-char-alist'."
2800 (let ((cl org-e-html-protect-char-alist) c)
2801 (while (setq c (pop cl))
2802 (let ((start 0))
2803 (while (string-match (car c) s start)
2804 (setq s (replace-match (cdr c) t t s)
2805 start (1+ (match-beginning 0))))))
2808 (defun org-e-html-plain-text (text info)
2809 "Transcode a TEXT string from Org to HTML.
2810 TEXT is the string to transcode. INFO is a plist holding
2811 contextual information."
2812 (setq text (org-e-html-encode-plain-text text))
2813 ;; Protect %, #, &, $, ~, ^, _, { and }.
2814 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2815 ;; (setq text
2816 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2817 ;; Protect \
2818 ;; (setq text (replace-regexp-in-string
2819 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2820 ;; "$\\backslash$" text nil t 1))
2821 ;; HTML into \HTML{} and TeX into \TeX{}.
2822 ;; (let ((case-fold-search nil)
2823 ;; (start 0))
2824 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2825 ;; (setq text (replace-match
2826 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2827 ;; start (match-end 0))))
2828 ;; Handle quotation marks
2829 ;; (setq text (org-e-html--quotation-marks text info))
2830 ;; Convert special strings.
2831 ;; (when (plist-get info :with-special-strings)
2832 ;; (while (string-match (regexp-quote "...") text)
2833 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2834 (when (plist-get info :with-special-strings)
2835 (setq text (org-e-html-convert-special-strings text)))
2836 ;; Handle break preservation if required.
2837 (when (plist-get info :preserve-breaks)
2838 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2839 text)))
2840 ;; Return value.
2841 text)
2844 ;;;; Property Drawer
2846 (defun org-e-html-property-drawer (property-drawer contents info)
2847 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2848 CONTENTS is nil. INFO is a plist holding contextual
2849 information."
2850 ;; The property drawer isn't exported but we want separating blank
2851 ;; lines nonetheless.
2855 ;;;; Quote Block
2857 (defun org-e-html-quote-block (quote-block contents info)
2858 "Transcode a QUOTE-BLOCK element from Org to HTML.
2859 CONTENTS holds the contents of the block. INFO is a plist
2860 holding contextual information."
2861 (org-e-html--wrap-label
2862 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2865 ;;;; Quote Section
2867 (defun org-e-html-quote-section (quote-section contents info)
2868 "Transcode a QUOTE-SECTION element from Org to HTML.
2869 CONTENTS is nil. INFO is a plist holding contextual information."
2870 (let ((value (org-remove-indentation
2871 (org-element-property :value quote-section))))
2872 (when value (format "<pre>\n%s</pre>" value))))
2875 ;;;; Section
2877 (defun org-e-html-section (section contents info) ; FIXME
2878 "Transcode a SECTION element from Org to HTML.
2879 CONTENTS holds the contents of the section. INFO is a plist
2880 holding contextual information."
2881 (let ((parent (org-export-get-parent-headline section info)))
2882 ;; Before first headline: no container, just return CONTENTS.
2883 (if (not parent) contents
2884 ;; Get div's class and id references.
2885 (let ((class-num (org-export-get-relative-level parent info))
2886 (id-num
2887 (mapconcat
2888 'number-to-string
2889 (org-export-get-headline-number parent info) "-")))
2890 ;; Build return value.
2891 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2892 class-num id-num contents)))))
2894 ;;;; Radio Target
2896 (defun org-e-html-radio-target (radio-target text info)
2897 "Transcode a RADIO-TARGET object from Org to HTML.
2898 TEXT is the text of the target. INFO is a plist holding
2899 contextual information."
2900 (org-e-html-format-anchor
2901 text (org-export-solidify-link-text
2902 (org-element-property :raw-value radio-target))))
2905 ;;;; Special Block
2907 (defun org-e-html-special-block (special-block contents info)
2908 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2909 CONTENTS holds the contents of the block. INFO is a plist
2910 holding contextual information."
2911 (let ((type (downcase (org-element-property :type special-block))))
2912 (org-e-html--wrap-label
2913 special-block
2914 (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
2917 ;;;; Src Block
2919 (defun org-e-html-src-block (src-block contents info)
2920 "Transcode a SRC-BLOCK element from Org to HTML.
2921 CONTENTS holds the contents of the item. INFO is a plist holding
2922 contextual information."
2923 (let* ((lang (org-element-property :language src-block))
2924 (code (org-export-handle-code src-block info))
2925 (caption (org-element-property :caption src-block))
2926 (label (org-element-property :name src-block)))
2927 ;; FIXME: Handle caption
2929 ;; caption-str (when caption)
2930 ;; (main (org-export-secondary-string (car caption) 'e-html info))
2931 ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
2932 ;; (caption-str (org-e-html--caption/label-string caption label info))
2933 (org-e-html-format-source-code-or-example lang code)))
2936 ;;;; Statistics Cookie
2938 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
2939 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2940 CONTENTS is nil. INFO is a plist holding contextual information."
2941 (let ((cookie-value (org-element-property :value statistics-cookie)))
2942 (org-e-html-format-fontify cookie-value 'code)))
2945 ;;;; Subscript
2947 (defun org-e-html-subscript (subscript contents info)
2948 "Transcode a SUBSCRIPT object from Org to HTML.
2949 CONTENTS is the contents of the object. INFO is a plist holding
2950 contextual information."
2951 (format "<sub>%s</sub>" contents))
2954 ;;;; Superscript
2956 (defun org-e-html-superscript (superscript contents info)
2957 "Transcode a SUPERSCRIPT object from Org to HTML.
2958 CONTENTS is the contents of the object. INFO is a plist holding
2959 contextual information."
2960 (format "<sup>%s</sup>" contents))
2963 ;;;; Table
2965 (defun org-e-html-begin-table (caption label attributes)
2966 (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
2967 org-e-html-table-tag))
2968 (html-table-tag
2969 (org-e-html-splice-attributes html-table-tag attributes)))
2970 (when label
2971 (setq html-table-tag
2972 (org-e-html-splice-attributes
2973 html-table-tag
2974 (format "id=\"%s\"" (org-solidify-link-text label)))))
2975 (concat "\n" html-table-tag
2976 (format "\n<caption>%s</caption>" (or caption "")))))
2978 (defun org-e-html-end-table ()
2979 "</table>\n")
2981 (defun org-e-html-format-table-cell (text r c horiz-span)
2982 (let ((cell-style-cookie
2983 (if org-e-html-table-align-individual-fields
2984 (format (if (and (boundp 'org-e-html-format-table-no-css)
2985 org-e-html-format-table-no-css)
2986 " align=\"%s\"" " class=\"%s\"")
2987 (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
2988 (cond
2989 (org-e-html-table-cur-rowgrp-is-hdr
2990 (concat
2991 (format (car org-export-table-header-tags) "col" cell-style-cookie)
2992 text (cdr org-export-table-header-tags)))
2993 ((and (= c 0) org-e-html-table-use-header-tags-for-first-column)
2994 (concat
2995 (format (car org-export-table-header-tags) "row" cell-style-cookie)
2996 text (cdr org-export-table-header-tags)))
2998 (concat
2999 (format (car org-export-table-data-tags) cell-style-cookie)
3000 text (cdr org-export-table-data-tags))))))
3002 (defun org-e-html-format-table-row (row)
3003 (concat (eval (car org-export-table-row-tags)) row
3004 (eval (cdr org-export-table-row-tags))))
3006 (defun org-e-html-table-row (fields &optional text-for-empty-fields)
3007 (incf org-e-html-table-rownum)
3008 (let ((i -1))
3009 (org-e-html-format-table-row
3010 (mapconcat
3011 (lambda (x)
3012 (when (and (string= x "") text-for-empty-fields)
3013 (setq x text-for-empty-fields))
3014 (incf i)
3015 (let (horiz-span)
3016 (org-e-html-format-table-cell
3017 x org-e-html-table-rownum i (or horiz-span 0))))
3018 fields "\n"))))
3020 (defun org-e-html-end-table-rowgroup ()
3021 (when org-e-html-table-rowgrp-open
3022 (setq org-e-html-table-rowgrp-open nil)
3023 (if org-e-html-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
3025 (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
3026 (concat
3027 (when org-e-html-table-rowgrp-open
3028 (org-e-html-end-table-rowgroup))
3029 (progn
3030 (setq org-e-html-table-rowgrp-open t)
3031 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row)
3032 (if is-header-row "<thead>" "<tbody>"))))
3034 (defun org-e-html-table-preamble ()
3035 (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
3036 c gr colgropen preamble)
3037 (unless (aref colgroup-vector 0)
3038 (setf (aref colgroup-vector 0) 'start))
3039 (dotimes (c columns-number preamble)
3040 (setq gr (aref colgroup-vector c))
3041 (setq preamble
3042 (concat
3043 preamble
3044 (when (memq gr '(start start-end))
3045 (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
3046 (setq colgropen t)))
3047 (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
3048 (align (cdr (assoc (aref colalign-vector c)
3049 '(("l" . "left")
3050 ("r" . "right")
3051 ("c" . "center")))))
3052 (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
3053 org-e-html-format-table-no-css)
3054 " align=\"%s\"" " class=\"%s\""))
3055 (extra (format alignspec align)))
3056 (format "<col%s />" extra))
3057 (when (memq gr '(end start-end))
3058 (setq colgropen nil)
3059 "</colgroup>"))))
3060 (concat preamble (if colgropen "</colgroup>"))))
3062 (defun org-e-html-list-table (lines caption label attributes)
3063 (setq lines (org-e-html-org-table-to-list-table lines))
3064 (let* ((splice nil) head
3065 (org-e-html-table-rownum -1)
3066 i (cnt 0)
3067 fields line
3068 org-e-html-table-cur-rowgrp-is-hdr
3069 org-e-html-table-rowgrp-open
3071 (org-lparse-table-style 'org-table)
3072 org-lparse-table-is-styled)
3073 (cond
3074 (splice
3075 (setq org-lparse-table-is-styled nil)
3076 (mapconcat 'org-e-html-table-row lines "\n"))
3078 (setq org-lparse-table-is-styled t)
3080 (concat
3081 (org-e-html-begin-table caption label attributes)
3082 (org-e-html-table-preamble)
3083 (org-e-html-begin-table-rowgroup head)
3085 (mapconcat
3086 (lambda (line)
3087 (cond
3088 ((equal line 'hline) (org-e-html-begin-table-rowgroup))
3089 (t (org-e-html-table-row line))))
3090 lines "\n")
3092 (org-e-html-end-table-rowgroup)
3093 (org-e-html-end-table))))))
3095 (defun org-e-html-transcode-table-row (row)
3096 (if (string-match org-table-hline-regexp row) 'hline
3097 (mapcar
3098 (lambda (cell)
3099 (org-export-secondary-string
3100 (let ((cell (org-element-parse-secondary-string
3101 cell
3102 (cdr (assq 'table org-element-string-restrictions)))))
3103 cell)
3104 'e-html info))
3105 (org-split-string row "[ \t]*|[ \t]*"))))
3107 (defun org-e-html-org-table-to-list-table (lines &optional splice)
3108 "Convert org-table to list-table.
3109 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
3110 element is a `string' representing a single row of org-table.
3111 Thus each ROW has vertical separators \"|\" separating the table
3112 fields. A ROW could also be a row-group separator of the form
3113 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
3114 ...). ROW could either be symbol `'hline' or a list of the
3115 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
3116 (let (line lines-1)
3117 (cond
3118 (splice
3119 (while (setq line (pop lines))
3120 (unless (string-match "^[ \t]*|-" line)
3121 (push (org-e-html-transcode-table-row line) lines-1))))
3122 (t (while (setq line (pop lines))
3123 (cond
3124 ((string-match "^[ \t]*|-" line)
3125 (when lines (push 'hline lines-1)))
3126 (t (push (org-e-html-transcode-table-row line) lines-1))))))
3127 (nreverse lines-1)))
3129 (defun org-e-html-table-table (raw-table)
3130 (require 'table)
3131 (with-current-buffer (get-buffer-create "*org-export-table*")
3132 (erase-buffer))
3133 (let ((output (with-temp-buffer
3134 (insert raw-table)
3135 (goto-char 1)
3136 (re-search-forward "^[ \t]*|[^|]" nil t)
3137 (table-generate-source 'html "*org-export-table*")
3138 (with-current-buffer "*org-export-table*"
3139 (org-trim (buffer-string))))))
3140 (kill-buffer (get-buffer "*org-export-table*"))
3141 output))
3143 (defun org-e-html-table (table contents info)
3144 "Transcode a TABLE element from Org to HTML.
3145 CONTENTS is nil. INFO is a plist holding contextual information."
3146 (let* ((label (org-element-property :name table))
3147 (caption (org-e-html--caption/label-string
3148 (org-element-property :caption table) label info))
3149 (attr (mapconcat #'identity
3150 (org-element-property :attr_html table)
3151 " "))
3152 (raw-table (org-element-property :raw-table table))
3153 (table-type (org-element-property :type table)))
3154 (case table-type
3155 (table.el
3156 (org-e-html-table-table raw-table))
3158 (let* ((table-info (org-export-table-format-info raw-table))
3159 (columns-number (length (plist-get table-info :alignment)))
3160 (lines (org-split-string
3161 (org-export-clean-table
3162 raw-table (plist-get table-info :special-column-p)) "\n")))
3163 (org-e-html-list-table lines caption label attr))))))
3166 ;;;; Target
3168 (defun org-e-html-target (target text info)
3169 "Transcode a TARGET object from Org to HTML.
3170 TEXT is the text of the target. INFO is a plist holding
3171 contextual information."
3172 (org-e-html-format-anchor
3173 text (org-export-solidify-link-text
3174 (org-element-property :raw-value target))))
3177 ;;;; Time-stamp
3179 (defun org-e-html-time-stamp (time-stamp contents info)
3180 "Transcode a TIME-STAMP object from Org to HTML.
3181 CONTENTS is nil. INFO is a plist holding contextual
3182 information."
3183 ;; (let ((value (org-element-property :value time-stamp))
3184 ;; (type (org-element-property :type time-stamp))
3185 ;; (appt-type (org-element-property :appt-type time-stamp)))
3186 ;; (concat (cond ((eq appt-type 'scheduled)
3187 ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
3188 ;; ((eq appt-type 'deadline)
3189 ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
3190 ;; ((eq appt-type 'closed)
3191 ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
3192 ;; (cond ((memq type '(active active-range))
3193 ;; (format org-e-html-active-timestamp-format value))
3194 ;; ((memq type '(inactive inactive-range))
3195 ;; (format org-e-html-inactive-timestamp-format value))
3196 ;; (t
3197 ;; (format org-e-html-diary-timestamp-format value)))))
3198 (let ((value (org-element-property :value time-stamp))
3199 (type (org-element-property :type time-stamp))
3200 (appt-type (org-element-property :appt-type time-stamp)))
3201 (setq value (org-export-secondary-string value 'e-html info))
3202 (org-e-html-format-fontify
3203 (concat
3204 (org-e-html-format-fontify
3205 (cond ((eq appt-type 'scheduled) org-scheduled-string)
3206 ((eq appt-type 'deadline) org-deadline-string)
3207 ((eq appt-type 'closed) org-closed-string)) "timestamp-kwd")
3208 ;; FIXME: (org-translate-time value)
3209 (org-e-html-format-fontify value "timestamp"))
3210 "timestamp-wrapper")))
3213 ;;;; Verbatim
3215 (defun org-e-html-verbatim (verbatim contents info)
3216 "Transcode a VERBATIM object from Org to HTML.
3217 CONTENTS is nil. INFO is a plist used as a communication
3218 channel."
3219 (org-e-html-emphasis
3220 verbatim (org-element-property :value verbatim) info))
3223 ;;;; Verse Block
3225 (defun org-e-html-verse-block (verse-block contents info)
3226 "Transcode a VERSE-BLOCK element from Org to HTML.
3227 CONTENTS is nil. INFO is a plist holding contextual information."
3228 ;; Replace each newline character with line break. Also replace
3229 ;; each blank line with a line break.
3230 (setq contents (replace-regexp-in-string
3231 "^ *\\\\\\\\$" "<br/>\n"
3232 (replace-regexp-in-string
3233 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3234 (org-remove-indentation
3235 (org-export-secondary-string
3236 (org-element-property :value verse-block)
3237 'e-html info)))))
3238 ;; Replace each white space at beginning of a line with a
3239 ;; non-breaking space.
3240 (while (string-match "^[ \t]+" contents)
3241 (let* ((num-ws (length (match-string 0 contents)))
3242 (ws (let (out) (dotimes (i num-ws out)
3243 (setq out (concat out "&nbsp;"))))))
3244 (setq contents (replace-match ws nil t contents))))
3245 (org-e-html--wrap-label
3246 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
3251 ;;; Filter Functions
3253 ;;;; Filter Settings
3255 (defconst org-e-html-filters-alist
3256 '((:filter-final-output . org-e-html-final-function))
3257 "Alist between filters keywords and back-end specific filters.
3258 See `org-export-filters-alist' for more information.")
3261 ;;;; Filters
3263 (defun org-e-html-final-function (contents backend info)
3264 (if (not org-e-html-pretty-output) contents
3265 (with-temp-buffer
3266 (nxml-mode)
3267 (insert contents)
3268 (indent-region (point-min) (point-max))
3269 (buffer-substring-no-properties (point-min) (point-max)))))
3272 ;;; Interactive functions
3274 (defun org-e-html-export-to-html
3275 (&optional subtreep visible-only body-only ext-plist pub-dir)
3276 "Export current buffer to a HTML file.
3278 If narrowing is active in the current buffer, only export its
3279 narrowed part.
3281 If a region is active, export that region.
3283 When optional argument SUBTREEP is non-nil, export the sub-tree
3284 at point, extracting information from the headline properties
3285 first.
3287 When optional argument VISIBLE-ONLY is non-nil, don't export
3288 contents of hidden elements.
3290 When optional argument BODY-ONLY is non-nil, only write code
3291 between \"\\begin{document}\" and \"\\end{document}\".
3293 EXT-PLIST, when provided, is a property list with external
3294 parameters overriding Org default settings, but still inferior to
3295 file-local settings.
3297 When optional argument PUB-DIR is set, use it as the publishing
3298 directory.
3300 Return output file's name."
3301 (interactive)
3303 ;; FIXME
3304 (with-current-buffer (get-buffer-create "*debug*")
3305 (erase-buffer))
3307 (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
3308 (org-export-to-file
3309 'e-html outfile subtreep visible-only body-only ext-plist)))
3313 ;;; FIXMES, TODOS, FOR REVIEW etc
3315 ;;;; org-format-table-html
3316 ;;;; org-format-org-table-html
3317 ;;;; org-format-table-table-html
3318 ;;;; org-table-number-fraction
3319 ;;;; org-table-number-regexp
3320 ;;;; org-e-html-table-caption-above
3322 ;;;; org-whitespace
3323 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3324 ;;;; Remove display properties
3325 ;;;; org-e-html-final-hook
3327 ;;;; org-e-html-with-timestamp
3328 ;;;; org-e-html-html-helper-timestamp
3330 ;;;; org-export-as-html-and-open
3331 ;;;; org-export-as-html-batch
3332 ;;;; org-export-as-html-to-buffer
3333 ;;;; org-replace-region-by-html
3334 ;;;; org-export-region-as-html
3335 ;;;; org-export-as-html
3337 ;;;; (org-export-directory :html opt-plist)
3338 ;;;; (plist-get opt-plist :html-extension)
3339 ;;;; org-e-html-toplevel-hlevel
3340 ;;;; org-e-html-special-string-regexps
3341 ;;;; org-e-html-coding-system
3342 ;;;; org-e-html-coding-system
3343 ;;;; org-e-html-inline-images
3344 ;;;; org-e-html-inline-image-extensions
3345 ;;;; org-e-html-protect-char-alist
3346 ;;;; org-e-html-table-use-header-tags-for-first-column
3347 ;;;; org-e-html-todo-kwd-class-prefix
3348 ;;;; org-e-html-tag-class-prefix
3349 ;;;; org-e-html-footnote-separator
3351 (provide 'org-e-html)
3352 ;;; org-e-html.el ends here