org-e-html: Improve lists, support listified headlines
[org-mode/org-mode-NeilSmithlineMods.git] / EXPERIMENTAL / org-e-html.el
blob43ed6560f0d0a3f3ab6a3b4c3a98ea1dc1fd668f
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 ;;; Debugging
45 (defvar org-e-html-debug nil)
46 (defvar org-e-html-pp t)
48 (defvar org-elements-debug-depth 0)
49 (defun org-e-html-debug (fmt &rest args)
50 (when org-e-html-debug
51 (with-current-buffer (get-buffer "*debug*")
52 (insert "\n" (apply 'format fmt args)))))
54 (defun org-element-debug (header text)
55 (insert "\n" "===== [" header "] =====")
56 (insert "\n" (pp-to-string text)))
58 (defun org-elements-debug (args)
59 (with-current-buffer "*debug*"
60 (insert "\n\n\n\n\n-------------------------\n")
61 (while args
62 (let* ((header (pop args))
63 (text (pop args)))
64 (org-element-debug (format "%s" header) text)))
65 (insert "\n--------------------------\n")))
67 (defmacro org-e-html-pp (&rest args)
68 (if org-e-html-pp
69 (let ((newargs))
70 (while args
71 (let ((e (pop args)))
72 (setq newargs (append newargs (list e (eval e))))))
73 ;; (pp-eval-expression 'newargs)
75 `(org-elements-debug (quote ,newargs)))
76 (list 'ignore)))
80 ;;; Hooks
82 (defvar org-e-html-after-blockquotes-hook nil
83 "Hook run during HTML export, after blockquote, verse, center are done.")
85 (defvar org-e-html-final-hook nil
86 "Hook run at the end of HTML export, in the new buffer.")
88 ;; FIXME: it already exists in org-e-html.el
89 ;;; Function Declarations
91 (declare-function org-element-get-property "org-element" (property element))
92 (declare-function org-element-normalize-string "org-element" (s))
93 (declare-function org-element-parse-secondary-string
94 "org-element" (string restriction &optional buffer))
95 (defvar org-element-string-restrictions)
97 (declare-function org-export-clean-table "org-export" (table specialp))
98 (declare-function org-export-data "org-export" (data backend info))
99 (declare-function org-export-directory "org-export" (type plist))
100 (declare-function org-export-expand-macro "org-export" (macro info))
101 (declare-function org-export-first-sibling-p "org-export" (headline info))
102 (declare-function org-export-footnote-first-reference-p "org-export"
103 (footnote-reference info))
104 (declare-function org-export-get-coderef-format "org-export" (path desc))
105 (declare-function org-export-get-footnote-definition "org-export"
106 (footnote-reference info))
107 (declare-function org-export-get-footnote-number "org-export" (footnote info))
108 (declare-function org-export-get-previous-element "org-export" (blob info))
109 (declare-function org-export-get-relative-level "org-export" (headline info))
110 (declare-function org-export-handle-code
111 "org-export" (element info &optional num-fmt ref-fmt delayed))
112 (declare-function org-export-included-file "org-export" (keyword backend info))
113 (declare-function org-export-inline-image-p "org-export"
114 (link &optional extensions))
115 (declare-function org-export-last-sibling-p "org-export" (headline info))
116 (declare-function org-export-low-level-p "org-export" (headline info))
117 (declare-function org-export-output-file-name
118 "org-export" (extension &optional subtreep pub-dir))
119 (declare-function org-export-resolve-coderef "org-export" (ref info))
120 (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
121 (declare-function org-export-secondary-string "org-export"
122 (secondary backend info))
123 (declare-function org-export-solidify-link-text "org-export" (s))
124 (declare-function org-export-table-format-info "org-export" (table))
125 (declare-function
126 org-export-to-buffer "org-export"
127 (backend buffer &optional subtreep visible-only body-only ext-plist))
128 (declare-function
129 org-export-to-file "org-export"
130 (backend file &optional subtreep visible-only body-only ext-plist))
132 (declare-function org-id-find-id-file "org-id" (id))
133 (declare-function htmlize-region "ext:htmlize" (beg end))
134 (declare-function org-pop-to-buffer-same-window
135 "org-compat" (&optional buffer-or-name norecord label))
140 ;;; Internal Variables
142 (defconst org-e-html-option-alist
143 '((:agenda-style nil nil org-agenda-export-html-style)
144 (:convert-org-links nil nil org-e-html-link-org-files-as-html)
145 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
146 ;; (:expand-quoted-html nil "@" org-e-html-expand)
147 (:inline-images nil nil org-e-html-inline-images)
148 ;; (:link-home nil nil org-e-html-link-home) FIXME
149 ;; (:link-up nil nil org-e-html-link-up) FIXME
150 (:style nil nil org-e-html-style)
151 (:style-extra nil nil org-e-html-style-extra)
152 (:style-include-default nil nil org-e-html-style-include-default)
153 (:style-include-scripts nil nil org-e-html-style-include-scripts)
154 ;; (:timestamp nil nil org-e-html-with-timestamp)
155 (:html-extension nil nil org-e-html-extension)
156 (:html-postamble nil nil org-e-html-postamble)
157 (:html-preamble nil nil org-e-html-preamble)
158 (:html-table-tag nil nil org-e-html-table-tag)
159 (:xml-declaration nil nil org-e-html-xml-declaration)
160 (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments))
161 "Alist between export properties and ways to set them.
163 The car of the alist is the property name, and the cdr is a list
164 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
166 KEYWORD is a string representing a buffer keyword, or nil.
167 OPTION is a string that could be found in an #+OPTIONS: line.
168 DEFAULT is the default value for the property.
169 BEHAVIOUR determine how Org should handle multiple keywords for
170 the same property. It is a symbol among:
171 nil Keep old value and discard the new one.
172 t Replace old value with the new one.
173 `space' Concatenate the values, separating them with a space.
174 `newline' Concatenate the values, separating them with
175 a newline.
176 `split' Split values at white spaces, and cons them to the
177 previous list.
179 KEYWORD and OPTION have precedence over DEFAULT.
181 All these properties should be back-end agnostic. For back-end
182 specific properties, define a similar variable named
183 `org-BACKEND-option-alist', replacing BACKEND with the name of
184 the appropriate back-end. You can also redefine properties
185 there, as they have precedence over these.")
188 (defvar html-table-tag nil) ; dynamically scoped into this.
190 ;; FIXME: it already exists in org-e-html.el
191 (defconst org-e-html-cvt-link-fn
193 "Function to convert link URLs to exportable URLs.
194 Takes two arguments, TYPE and PATH.
195 Returns exportable url as (TYPE PATH), or nil to signal that it
196 didn't handle this case.
197 Intended to be locally bound around a call to `org-export-as-html'." )
201 (defvar org-e-html-format-table-no-css)
202 (defvar org-table-number-regexp) ; defined in org-table.el
203 (defvar htmlize-buffer-places) ; from htmlize.el
204 (defvar body-only) ; dynamically scoped into this.
206 (defvar org-e-html-table-rowgrp-open)
207 (defvar org-e-html-table-rownum)
208 (defvar org-e-html-table-cur-rowgrp-is-hdr)
209 (defvar org-lparse-table-is-styled)
212 (defvar org-e-html-headline-formatter
213 (lambda (level snumber todo todo-type priority
214 title tags target extra-targets extra-class)
215 (concat snumber " " title)))
219 ;;; User Configuration Variables
221 (defgroup org-export-e-html nil
222 "Options for exporting Org mode files to HTML."
223 :tag "Org Export HTML"
224 :group 'org-export)
227 ;;;; Document
229 (defcustom org-e-html-extension "html"
230 "The extension for exported HTML files."
231 :group 'org-export-e-html
232 :type 'string)
234 (defcustom org-e-html-xml-declaration
235 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
236 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
237 "The extension for exported HTML files.
238 %s will be replaced with the charset of the exported file.
239 This may be a string, or an alist with export extensions
240 and corresponding declarations."
241 :group 'org-export-e-html
242 :type '(choice
243 (string :tag "Single declaration")
244 (repeat :tag "Dependent on extension"
245 (cons (string :tag "Extension")
246 (string :tag "Declaration")))))
248 (defcustom org-e-html-coding-system nil
249 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
250 :group 'org-export-e-html
251 :type 'coding-system)
253 (defvar org-e-html-content-div "content"
254 "The name of the container DIV that holds all the page contents.
256 This variable is obsolete since Org version 7.7.
257 Please set `org-e-html-divs' instead.")
259 (defcustom org-e-html-divs '("preamble" "content" "postamble")
260 "The name of the main divs for HTML export.
261 This is a list of three strings, the first one for the preamble
262 DIV, the second one for the content DIV and the third one for the
263 postamble DIV."
264 :group 'org-export-e-html
265 :type '(list
266 (string :tag " Div for the preamble:")
267 (string :tag " Div for the content:")
268 (string :tag "Div for the postamble:")))
271 ;;;; Document Header (Styles)
273 (defconst org-e-html-style-default
274 "<style type=\"text/css\">
275 <!--/*--><![CDATA[/*><!--*/
276 html { font-family: Times, serif; font-size: 12pt; }
277 .title { text-align: center; }
278 .todo { color: red; }
279 .done { color: green; }
280 .tag { background-color: #add8e6; font-weight:normal }
281 .target { }
282 .timestamp { color: #bebebe; }
283 .timestamp-kwd { color: #5f9ea0; }
284 .right {margin-left:auto; margin-right:0px; text-align:right;}
285 .left {margin-left:0px; margin-right:auto; text-align:left;}
286 .center {margin-left:auto; margin-right:auto; text-align:center;}
287 p.verse { margin-left: 3% }
288 pre {
289 border: 1pt solid #AEBDCC;
290 background-color: #F3F5F7;
291 padding: 5pt;
292 font-family: courier, monospace;
293 font-size: 90%;
294 overflow:auto;
296 table { border-collapse: collapse; }
297 td, th { vertical-align: top; }
298 th.right { text-align:center; }
299 th.left { text-align:center; }
300 th.center { text-align:center; }
301 td.right { text-align:right; }
302 td.left { text-align:left; }
303 td.center { text-align:center; }
304 dt { font-weight: bold; }
305 div.figure { padding: 0.5em; }
306 div.figure p { text-align: center; }
307 div.inlinetask {
308 padding:10px;
309 border:2px solid gray;
310 margin:10px;
311 background: #ffffcc;
313 textarea { overflow-x: auto; }
314 .linenr { font-size:smaller }
315 .code-highlighted {background-color:#ffff00;}
316 .org-info-js_info-navigation { border-style:none; }
317 #org-info-js_console-label { font-size:10px; font-weight:bold;
318 white-space:nowrap; }
319 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
320 font-weight:bold; }
321 /*]]>*/-->
322 </style>"
323 "The default style specification for exported HTML files.
324 Please use the variables `org-e-html-style' and
325 `org-e-html-style-extra' to add to this style. If you wish to not
326 have the default style included, customize the variable
327 `org-e-html-style-include-default'.")
329 (defcustom org-e-html-style-include-default t
330 "Non-nil means include the default style in exported HTML files.
331 The actual style is defined in `org-e-html-style-default' and should
332 not be modified. Use the variables `org-e-html-style' to add
333 your own style information."
334 :group 'org-export-e-html
335 :type 'boolean)
336 ;;;###autoload
337 (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
339 (defcustom org-e-html-style ""
340 "Org-wide style definitions for exported HTML files.
342 This variable needs to contain the full HTML structure to provide a style,
343 including the surrounding HTML tags. If you set the value of this variable,
344 you should consider to include definitions for the following classes:
345 title, todo, done, timestamp, timestamp-kwd, tag, target.
347 For example, a valid value would be:
349 <style type=\"text/css\">
350 <![CDATA[
351 p { font-weight: normal; color: gray; }
352 h1 { color: black; }
353 .title { text-align: center; }
354 .todo, .timestamp-kwd { color: red; }
355 .done { color: green; }
357 </style>
359 If you'd like to refer to an external style file, use something like
361 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
363 As the value of this option simply gets inserted into the HTML <head> header,
364 you can \"misuse\" it to add arbitrary text to the header.
365 See also the variable `org-e-html-style-extra'."
366 :group 'org-export-e-html
367 :type 'string)
368 ;;;###autoload
369 (put 'org-e-html-style 'safe-local-variable 'stringp)
371 (defcustom org-e-html-style-extra ""
372 "Additional style information for HTML export.
373 The value of this variable is inserted into the HTML buffer right after
374 the value of `org-e-html-style'. Use this variable for per-file
375 settings of style information, and do not forget to surround the style
376 settings with <style>...</style> tags."
377 :group 'org-export-e-html
378 :type 'string)
379 ;;;###autoload
380 (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
382 (defcustom org-e-html-mathjax-options
383 '((path "http://orgmode.org/mathjax/MathJax.js")
384 (scale "100")
385 (align "center")
386 (indent "2em")
387 (mathml nil))
388 "Options for MathJax setup.
390 path The path where to find MathJax
391 scale Scaling for the HTML-CSS backend, usually between 100 and 133
392 align How to align display math: left, center, or right
393 indent If align is not center, how far from the left/right side?
394 mathml Should a MathML player be used if available?
395 This is faster and reduces bandwidth use, but currently
396 sometimes has lower spacing quality. Therefore, the default is
397 nil. When browsers get better, this switch can be flipped.
399 You can also customize this for each buffer, using something like
401 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
402 :group 'org-export-e-html
403 :type '(list :greedy t
404 (list :tag "path (the path from where to load MathJax.js)"
405 (const :format " " path) (string))
406 (list :tag "scale (scaling for the displayed math)"
407 (const :format " " scale) (string))
408 (list :tag "align (alignment of displayed equations)"
409 (const :format " " align) (string))
410 (list :tag "indent (indentation with left or right alignment)"
411 (const :format " " indent) (string))
412 (list :tag "mathml (should MathML display be used is possible)"
413 (const :format " " mathml) (boolean))))
416 ;;;; Document Header (Scripts)
418 (defcustom org-e-html-style-include-scripts t
419 "Non-nil means include the JavaScript snippets in exported HTML files.
420 The actual script is defined in `org-e-html-scripts' and should
421 not be modified."
422 :group 'org-export-e-html
423 :type 'boolean)
425 (defconst org-e-html-scripts
426 "<script type=\"text/javascript\">
427 <!--/*--><![CDATA[/*><!--*/
428 function CodeHighlightOn(elem, id)
430 var target = document.getElementById(id);
431 if(null != target) {
432 elem.cacheClassElem = elem.className;
433 elem.cacheClassTarget = target.className;
434 target.className = \"code-highlighted\";
435 elem.className = \"code-highlighted\";
438 function CodeHighlightOff(elem, id)
440 var target = document.getElementById(id);
441 if(elem.cacheClassElem)
442 elem.className = elem.cacheClassElem;
443 if(elem.cacheClassTarget)
444 target.className = elem.cacheClassTarget;
446 /*]]>*///-->
447 </script>"
448 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
451 ;;;; Document Header (Mathjax)
453 (defcustom org-e-html-mathjax-template
454 "<script type=\"text/javascript\" src=\"%PATH\">
455 <!--/*--><![CDATA[/*><!--*/
456 MathJax.Hub.Config({
457 // Only one of the two following lines, depending on user settings
458 // First allows browser-native MathML display, second forces HTML/CSS
459 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
460 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
461 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
462 \"TeX/noUndefined.js\"],
463 tex2jax: {
464 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
465 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
466 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
467 ignoreClass: \"tex2jax_ignore\",
468 processEscapes: false,
469 processEnvironments: true,
470 preview: \"TeX\"
472 showProcessingMessages: true,
473 displayAlign: \"%ALIGN\",
474 displayIndent: \"%INDENT\",
476 \"HTML-CSS\": {
477 scale: %SCALE,
478 availableFonts: [\"STIX\",\"TeX\"],
479 preferredFont: \"TeX\",
480 webFont: \"TeX\",
481 imageFont: \"TeX\",
482 showMathMenu: true,
484 MMLorHTML: {
485 prefer: {
486 MSIE: \"MML\",
487 Firefox: \"MML\",
488 Opera: \"HTML\",
489 other: \"HTML\"
493 /*]]>*///-->
494 </script>"
495 "The MathJax setup for XHTML files."
496 :group 'org-export-e-html
497 :type 'string)
500 ;;;; Preamble
502 (defcustom org-e-html-preamble t
503 "Non-nil means insert a preamble in HTML export.
505 When `t', insert a string as defined by one of the formatting
506 strings in `org-e-html-preamble-format'. When set to a
507 string, this string overrides `org-e-html-preamble-format'.
508 When set to a function, apply this function and insert the
509 returned string. The function takes the property list of export
510 options as its only argument.
512 Setting :html-preamble in publishing projects will take
513 precedence over this variable."
514 :group 'org-export-e-html
515 :type '(choice (const :tag "No preamble" nil)
516 (const :tag "Default preamble" t)
517 (string :tag "Custom formatting string")
518 (function :tag "Function (must return a string)")))
520 (defcustom org-e-html-preamble-format '(("en" ""))
521 "The format for the HTML preamble.
523 %t stands for the title.
524 %a stands for the author's name.
525 %e stands for the author's email.
526 %d stands for the date.
528 If you need to use a \"%\" character, you need to escape it
529 like that: \"%%\"."
530 :group 'org-export-e-html
531 :type 'string)
533 (defcustom org-e-html-home/up-format
534 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
535 <a accesskey=\"h\" href=\"%s\"> UP </a>
537 <a accesskey=\"H\" href=\"%s\"> HOME </a>
538 </div>"
539 "Snippet used to insert the HOME and UP links.
540 This is a format string, the first %s will receive the UP link,
541 the second the HOME link. If both `org-e-html-link-up' and
542 `org-e-html-link-home' are empty, the entire snippet will be
543 ignored."
544 :group 'org-export-e-html
545 :type 'string)
547 ;;;; Postamble
549 (defcustom org-e-html-postamble 'auto
550 "Non-nil means insert a postamble in HTML export.
552 When `t', insert a string as defined by the formatting string in
553 `org-e-html-postamble-format'. When set to a string, this
554 string overrides `org-e-html-postamble-format'. When set to
555 'auto, discard `org-e-html-postamble-format' and honor
556 `org-export-author/email/creator-info' variables. When set to a
557 function, apply this function and insert the returned string.
558 The function takes the property list of export options as its
559 only argument.
561 Setting :html-postamble in publishing projects will take
562 precedence over this variable."
563 :group 'org-export-e-html
564 :type '(choice (const :tag "No postamble" nil)
565 (const :tag "Auto preamble" 'auto)
566 (const :tag "Default formatting string" t)
567 (string :tag "Custom formatting string")
568 (function :tag "Function (must return a string)")))
570 (defcustom org-e-html-postamble-format
571 '(("en" "<p class=\"author\">Author: %a (%e)</p>
572 <p class=\"date\">Date: %d</p>
573 <p class=\"creator\">Generated by %c</p>
574 <p class=\"xhtml-validation\">%v</p>
576 "The format for the HTML postamble.
578 %a stands for the author's name.
579 %e stands for the author's email.
580 %d stands for the date.
581 %c will be replaced by information about Org/Emacs versions.
582 %v will be replaced by `org-e-html-validation-link'.
584 If you need to use a \"%\" character, you need to escape it
585 like that: \"%%\"."
586 :group 'org-export-e-html
587 :type 'string)
589 (defcustom org-e-html-validation-link
590 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
591 "Link to HTML validation service."
592 :group 'org-export-e-html
593 :type 'string)
595 ;; FIXME Obsolete since Org 7.7
596 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
597 ;;;; Emphasis
599 (defcustom org-e-html-protect-char-alist
600 '(("&" . "&amp;")
601 ("<" . "&lt;")
602 (">" . "&gt;"))
603 "Alist of characters to be converted by `org-e-html-protect'."
604 :group 'org-export-e-html
605 :type '(repeat (cons (string :tag "Character")
606 (string :tag "HTML equivalent"))))
608 (defconst org-e-html-special-string-regexps
609 '(("\\\\-" . "&shy;")
610 ("---\\([^-]\\)" . "&mdash;\\1")
611 ("--\\([^-]\\)" . "&ndash;\\1")
612 ("\\.\\.\\." . "&hellip;"))
613 "Regular expressions for special string conversion.")
616 ;;;; Todos
618 (defcustom org-e-html-todo-kwd-class-prefix ""
619 "Prefix to class names for TODO keywords.
620 Each TODO keyword gets a class given by the keyword itself, with this prefix.
621 The default prefix is empty because it is nice to just use the keyword
622 as a class name. But if you get into conflicts with other, existing
623 CSS classes, then this prefix can be very useful."
624 :group 'org-export-e-html
625 :type 'string)
628 ;;;; Tags
630 (defcustom org-e-html-tag-class-prefix ""
631 "Prefix to class names for TODO keywords.
632 Each tag gets a class given by the tag itself, with this prefix.
633 The default prefix is empty because it is nice to just use the keyword
634 as a class name. But if you get into conflicts with other, existing
635 CSS classes, then this prefix can be very useful."
636 :group 'org-export-e-html
637 :type 'string)
639 ;;;; Time-stamps
640 ;;;; Statistics Cookie
641 ;;;; Subscript
642 ;;;; Superscript
644 ;;;; Inline images
646 (defcustom org-e-html-inline-images 'maybe
647 "Non-nil means inline images into exported HTML pages.
648 This is done using an <img> tag. When nil, an anchor with href is used to
649 link to the image. If this option is `maybe', then images in links with
650 an empty description will be inlined, while images with a description will
651 be linked only."
652 :group 'org-export-e-html
653 :type '(choice (const :tag "Never" nil)
654 (const :tag "Always" t)
655 (const :tag "When there is no description" maybe)))
657 (defcustom org-e-html-inline-image-extensions
658 '("png" "jpeg" "jpg" "gif" "svg")
659 "Extensions of image files that can be inlined into HTML."
660 :group 'org-export-e-html
661 :type '(repeat (string :tag "Extension")))
664 ;;;; Block
665 ;;;; Comment
666 ;;;; Comment Block
667 ;;;; Drawer
668 ;;;; Dynamic Block
669 ;;;; Emphasis
670 ;;;; Entity
671 ;;;; Example Block
672 ;;;; Export Snippet
673 ;;;; Export Block
674 ;;;; Fixed Width
675 ;;;; Footnotes
677 (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
678 <h2 class=\"footnotes\">%s: </h2>
679 <div id=\"text-footnotes\">
681 </div>
682 </div>"
683 "Format for the footnotes section.
684 Should contain a two instances of %s. The first will be replaced with the
685 language-specific word for \"Footnotes\", the second one will be replaced
686 by the footnotes themselves."
687 :group 'org-export-e-html
688 :type 'string)
690 (defcustom org-e-html-footnote-format "<sup>%s</sup>"
691 "The format for the footnote reference.
692 %s will be replaced by the footnote reference itself."
693 :group 'org-export-e-html
694 :type 'string)
696 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
697 "Text used to separate footnotes."
698 :group 'org-export-e-html
699 :type 'string)
702 ;;;; Headline
703 ;;;; Horizontal Rule
704 ;;;; Inline Babel Call
705 ;;;; Inline Src Block
706 ;;;; Inlinetask
707 ;;;; Item
708 ;;;; Keyword
709 ;;;; Latex Environment
710 ;;;; Latex Fragment
711 ;;;; Line Break
712 ;;;; Link
713 ;;;; Babel Call
714 ;;;; Macro
715 ;;;; Paragraph
716 ;;;; Plain List
717 ;;;; Plain Text
718 ;;;; Property Drawer
719 ;;;; Quote Block
720 ;;;; Quote Section
721 ;;;; Section
722 ;;;; Radio Target
723 ;;;; Special Block
724 ;;;; Src Block
726 (defgroup org-export-e-htmlize nil
727 "Options for processing examples with htmlize.el."
728 :tag "Org Export Htmlize"
729 :group 'org-export-e-html)
731 (defcustom org-export-e-htmlize-output-type 'inline-css
732 "Output type to be used by htmlize when formatting code snippets.
733 Choices are `css', to export the CSS selectors only, or `inline-css', to
734 export the CSS attribute values inline in the HTML. We use as default
735 `inline-css', in order to make the resulting HTML self-containing.
737 However, this will fail when using Emacs in batch mode for export, because
738 then no rich font definitions are in place. It will also not be good if
739 people with different Emacs setup contribute HTML files to a website,
740 because the fonts will represent the individual setups. In these cases,
741 it is much better to let Org/Htmlize assign classes only, and to use
742 a style file to define the look of these classes.
743 To get a start for your css file, start Emacs session and make sure that
744 all the faces you are interested in are defined, for example by loading files
745 in all modes you want. Then, use the command
746 \\[org-export-e-htmlize-generate-css] to extract class definitions."
747 :group 'org-export-e-htmlize
748 :type '(choice (const css) (const inline-css)))
750 (defcustom org-export-e-htmlize-css-font-prefix "org-"
751 "The prefix for CSS class names for htmlize font specifications."
752 :group 'org-export-e-htmlize
753 :type 'string)
755 (defcustom org-export-e-htmlized-org-css-url nil
756 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
757 Normally when creating an htmlized version of an Org buffer, htmlize will
758 create CSS to define the font colors. However, this does not work when
759 converting in batch mode, and it also can look bad if different people
760 with different fontification setup work on the same website.
761 When this variable is non-nil, creating an htmlized version of an Org buffer
762 using `org-export-as-org' will remove the internal CSS section and replace it
763 with a link to this URL."
764 :group 'org-export-e-htmlize
765 :type '(choice
766 (const :tag "Keep internal css" nil)
767 (string :tag "URL or local href")))
770 ;;;; Table
772 (defcustom org-e-html-table-tag
773 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
774 "The HTML tag that is used to start a table.
775 This must be a <table> tag, but you may change the options like
776 borders and spacing."
777 :group 'org-export-e-html
778 :type 'string)
780 (defcustom org-export-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
781 "The opening tag for table header fields.
782 This is customizable so that alignment options can be specified.
783 The first %s will be filled with the scope of the field, either row or col.
784 The second %s will be replaced by a style entry to align the field.
785 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
786 See also the variable `org-e-html-table-align-individual-fields'."
787 :group 'org-export-tables
788 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
790 (defcustom org-export-table-data-tags '("<td%s>" . "</td>")
791 "The opening tag for table data fields.
792 This is customizable so that alignment options can be specified.
793 The first %s will be filled with the scope of the field, either row or col.
794 The second %s will be replaced by a style entry to align the field.
795 See also the variable `org-e-html-table-align-individual-fields'."
796 :group 'org-export-tables
797 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
799 (defcustom org-export-table-row-tags '("<tr>" . "</tr>")
800 "The opening tag for table data fields.
801 This is customizable so that alignment options can be specified.
802 Instead of strings, these can be Lisp forms that will be evaluated
803 for each row in order to construct the table row tags. During evaluation,
804 the variable `head' will be true when this is a header line, nil when this
805 is a body line. And the variable `nline' will contain the line number,
806 starting from 1 in the first header line. For example
808 (setq org-export-table-row-tags
809 (cons '(if head
810 \"<tr>\"
811 (if (= (mod nline 2) 1)
812 \"<tr class=\\\"tr-odd\\\">\"
813 \"<tr class=\\\"tr-even\\\">\"))
814 \"</tr>\"))
816 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
817 :group 'org-export-tables
818 :type '(cons
819 (choice :tag "Opening tag"
820 (string :tag "Specify")
821 (sexp))
822 (choice :tag "Closing tag"
823 (string :tag "Specify")
824 (sexp))))
826 (defcustom org-e-html-table-align-individual-fields t
827 "Non-nil means attach style attributes for alignment to each table field.
828 When nil, alignment will only be specified in the column tags, but this
829 is ignored by some browsers (like Firefox, Safari). Opera does it right
830 though."
831 :group 'org-export-tables
832 :type 'boolean)
834 (defcustom org-e-html-table-use-header-tags-for-first-column nil
835 "Non-nil means format column one in tables with header tags.
836 When nil, also column one will use data tags."
837 :group 'org-export-tables
838 :type 'boolean)
841 ;;;; Target
842 ;;;; Time-stamp
844 ;;;; Verbatim
845 ;;;; Verse Block
846 ;;;; Headline
848 (defcustom org-e-html-toplevel-hlevel 2
849 "The <H> level for level 1 headings in HTML export.
850 This is also important for the classes that will be wrapped around headlines
851 and outline structure. If this variable is 1, the top-level headlines will
852 be <h1>, and the corresponding classes will be outline-1, section-number-1,
853 and outline-text-1. If this is 2, all of these will get a 2 instead.
854 The default for this variable is 2, because we use <h1> for formatting the
855 document title."
856 :group 'org-export-e-html
857 :type 'string)
860 ;;;; Links
861 ;;;; Drawers
862 ;;;; Inlinetasks
863 ;;;; Publishing
865 (defcustom org-e-html-link-org-files-as-html t
866 "Non-nil means make file links to `file.org' point to `file.html'.
867 When org-mode is exporting an org-mode file to HTML, links to
868 non-html files are directly put into a href tag in HTML.
869 However, links to other Org-mode files (recognized by the
870 extension `.org.) should become links to the corresponding html
871 file, assuming that the linked org-mode file will also be
872 converted to HTML.
873 When nil, the links still point to the plain `.org' file."
874 :group 'org-export-e-html
875 :type 'boolean)
878 ;;;; Compilation
882 ;;; User Configurable Variables (MAYBE)
884 ;;;; Preamble
886 (defcustom org-e-html-inputenc-alist nil
887 "Alist of inputenc coding system names, and what should really be used.
888 For example, adding an entry
890 (\"utf8\" . \"utf8x\")
892 will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
893 are written as utf8 files."
894 :group 'org-export-e-html
895 :type '(repeat
896 (cons
897 (string :tag "Derived from buffer")
898 (string :tag "Use this instead"))))
900 (defcustom org-e-html-date-format
901 "\\today"
902 "Format string for \\date{...}."
903 :group 'org-export-e-html
904 :type 'boolean)
906 (defcustom org-e-html-title-command "\\maketitle"
907 "The command used to insert the title just after \\begin{document}.
908 If this string contains the formatting specification \"%s\" then
909 it will be used as a formatting string, passing the title as an
910 argument."
911 :group 'org-export-e-html
912 :type 'string)
915 ;;;; Headline
917 (defcustom org-e-html-format-headline-function nil
918 "Function to format headline text.
920 This function will be called with 5 arguments:
921 TODO the todo keyword \(string or nil\).
922 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
923 PRIORITY the priority of the headline \(integer or nil\)
924 TEXT the main headline text \(string\).
925 TAGS the tags string, separated with colons \(string or nil\).
927 The function result will be used in the section format string.
929 As an example, one could set the variable to the following, in
930 order to reproduce the default set-up:
932 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
933 \"Default format function for an headline.\"
934 \(concat \(when todo
935 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
936 \(when priority
937 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
938 text
939 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
940 :group 'org-export-e-html
941 :type 'function)
944 ;;;; Emphasis
946 (defcustom org-e-html-emphasis-alist
947 '(("*" . "\\textbf{%s}")
948 ("/" . "\\emph{%s}")
949 ("_" . "\\underline{%s}")
950 ("+" . "\\st{%s}")
951 ("=" . protectedtexttt)
952 ("~" . verb))
953 "Alist of HTML expressions to convert emphasis fontifiers.
955 The key is the character used as a marker for fontification. The
956 value is a formatting string to wrap fontified text with.
958 Value can also be set to the following symbols: `verb' and
959 `protectedtexttt'. For the former, Org will use \"\\verb\" to
960 create a format string and select a delimiter character that
961 isn't in the string. For the latter, Org will use \"\\texttt\"
962 to typeset and try to protect special characters."
963 :group 'org-export-e-html
964 :type 'alist)
967 ;;;; Footnotes
969 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
970 "Text used to separate footnotes."
971 :group 'org-export-e-html
972 :type 'string)
975 ;;;; Time-stamps
977 (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
978 "A printf format string to be applied to active time-stamps."
979 :group 'org-export-e-html
980 :type 'string)
982 (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
983 "A printf format string to be applied to inactive time-stamps."
984 :group 'org-export-e-html
985 :type 'string)
987 (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
988 "A printf format string to be applied to diary time-stamps."
989 :group 'org-export-e-html
990 :type 'string)
993 ;;;; Links
995 (defcustom org-e-html-image-default-option "width=.9\\linewidth"
996 "Default option for images."
997 :group 'org-export-e-html
998 :type 'string)
1000 (defcustom org-e-html-default-figure-position "htb"
1001 "Default position for latex figures."
1002 :group 'org-export-e-html
1003 :type 'string)
1005 (defcustom org-e-html-inline-image-rules
1006 '(("file" . "\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
1007 "Rules characterizing image files that can be inlined into HTML.
1009 A rule consists in an association whose key is the type of link
1010 to consider, and value is a regexp that will be matched against
1011 link's path.
1013 Note that, by default, the image extension *actually* allowed
1014 depend on the way the HTML file is processed. When used with
1015 pdflatex, pdf, jpg and png images are OK. When processing
1016 through dvi to Postscript, only ps and eps are allowed. The
1017 default we use here encompasses both."
1018 :group 'org-export-e-html
1019 :type '(alist :key-type (string :tag "Type")
1020 :value-type (regexp :tag "Path")))
1023 ;;;; Tables
1025 (defcustom org-e-html-default-table-environment "tabular"
1026 "Default environment used to build tables."
1027 :group 'org-export-e-html
1028 :type 'string)
1030 (defcustom org-e-html-tables-centered t
1031 "When non-nil, tables are exported in a center environment."
1032 :group 'org-export-e-html
1033 :type 'boolean)
1035 (defcustom org-e-html-tables-verbatim nil
1036 "When non-nil, tables are exported verbatim."
1037 :group 'org-export-e-html
1038 :type 'boolean)
1040 (defcustom org-e-html-table-caption-above t
1041 "When non-nil, place caption string at the beginning of the table.
1042 Otherwise, place it near the end."
1043 :group 'org-export-e-html
1044 :type 'boolean)
1047 ;;;; Drawers
1049 (defcustom org-e-html-format-drawer-function nil
1050 "Function called to format a drawer in HTML code.
1052 The function must accept two parameters:
1053 NAME the drawer name, like \"LOGBOOK\"
1054 CONTENTS the contents of the drawer.
1056 The function should return the string to be exported.
1058 For example, the variable could be set to the following function
1059 in order to mimic default behaviour:
1061 \(defun org-e-html-format-drawer-default \(name contents\)
1062 \"Format a drawer element for HTML export.\"
1063 contents\)"
1064 :group 'org-export-e-html
1065 :type 'function)
1068 ;;;; Inlinetasks
1070 (defcustom org-e-html-format-inlinetask-function nil
1071 "Function called to format an inlinetask in HTML code.
1073 The function must accept six parameters:
1074 TODO the todo keyword, as a string
1075 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
1076 PRIORITY the inlinetask priority, as a string
1077 NAME the inlinetask name, as a string.
1078 TAGS the inlinetask tags, as a string.
1079 CONTENTS the contents of the inlinetask, as a string.
1081 The function should return the string to be exported.
1083 For example, the variable could be set to the following function
1084 in order to mimic default behaviour:
1086 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
1087 \"Format an inline task element for HTML export.\"
1088 \(let \(\(full-title
1089 \(concat
1090 \(when todo
1091 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
1092 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1093 title
1094 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1095 \(format \(concat \"\\\\begin{center}\\n\"
1096 \"\\\\fbox{\\n\"
1097 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1098 \"%s\\n\\n\"
1099 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1100 \"%s\"
1101 \"\\\\end{minipage}}\"
1102 \"\\\\end{center}\"\)
1103 full-title contents\)\)"
1104 :group 'org-export-e-html
1105 :type 'function)
1108 ;; Src blocks
1110 ;;;; Plain text
1112 (defcustom org-e-html-quotes
1113 '(("fr" ("\\(\\s-\\|[[(]\\)\"" . "«~") ("\\(\\S-\\)\"" . "~»") ("\\(\\s-\\|(\\)'" . "'"))
1114 ("en" ("\\(\\s-\\|[[(]\\)\"" . "``") ("\\(\\S-\\)\"" . "''") ("\\(\\s-\\|(\\)'" . "`")))
1115 "Alist for quotes to use when converting english double-quotes.
1117 The CAR of each item in this alist is the language code.
1118 The CDR of each item in this alist is a list of three CONS:
1119 - the first CONS defines the opening quote;
1120 - the second CONS defines the closing quote;
1121 - the last CONS defines single quotes.
1123 For each item in a CONS, the first string is a regexp
1124 for allowed characters before/after the quote, the second
1125 string defines the replacement string for this quote."
1126 :group 'org-export-e-html
1127 :type '(list
1128 (cons :tag "Opening quote"
1129 (string :tag "Regexp for char before")
1130 (string :tag "Replacement quote "))
1131 (cons :tag "Closing quote"
1132 (string :tag "Regexp for char after ")
1133 (string :tag "Replacement quote "))
1134 (cons :tag "Single quote"
1135 (string :tag "Regexp for char before")
1136 (string :tag "Replacement quote "))))
1139 ;;;; Compilation
1143 ;;; Internal Functions (HTML)
1145 (defun org-e-html-cvt-org-as-html (opt-plist type path)
1146 "Convert an org filename to an equivalent html filename.
1147 If TYPE is not file, just return `nil'.
1148 See variable `org-e-html-link-org-files-as-html'"
1150 (save-match-data
1151 (and
1152 org-e-html-link-org-files-as-html
1153 (string= type "file")
1154 (string-match "\\.org$" path)
1155 (progn
1156 (list
1157 "file"
1158 (concat
1159 (substring path 0 (match-beginning 0))
1161 (plist-get opt-plist :html-extension)))))))
1163 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1164 descp)
1165 "Make an HTML link.
1166 OPT-PLIST is an options list.
1167 TYPE is the device-type of the link (THIS://foo.html).
1168 PATH is the path of the link (http://THIS#location).
1169 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1170 DESC is the link description, if any.
1171 ATTR is a string of other attributes of the \"a\" element."
1172 (declare (special org-lparse-par-open))
1173 (save-match-data
1174 (when (string= type-1 "coderef")
1175 (let ((ref fragment))
1176 (setq desc (format (org-export-get-coderef-format ref (and descp desc))
1177 (cdr (assoc ref org-export-code-refs)))
1178 fragment (concat "coderef-" ref)
1179 attr (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1180 fragment fragment))))
1181 (let* ((may-inline-p
1182 (and (member type-1 '("http" "https" "file"))
1183 (org-lparse-should-inline-p path descp)
1184 (not fragment)))
1185 (type (if (equal type-1 "id") "file" type-1))
1186 (filename path)
1187 ;;First pass. Just sanity stuff.
1188 (components-1
1189 (cond
1190 ((string= type "file")
1191 (list
1192 type
1193 ;;Substitute just if original path was absolute.
1194 ;;(Otherwise path must remain relative)
1195 (if (file-name-absolute-p path)
1196 (concat "file://" (expand-file-name path))
1197 path)))
1198 ((string= type "")
1199 (list nil path))
1200 (t (list type path))))
1202 ;;Second pass. Components converted so they can refer
1203 ;;to a remote site.
1204 (components-2
1206 (and org-e-html-cvt-link-fn
1207 (apply org-e-html-cvt-link-fn
1208 opt-plist components-1))
1209 (apply #'org-e-html-cvt-org-as-html
1210 opt-plist components-1)
1211 components-1))
1212 (type (first components-2))
1213 (thefile (second components-2)))
1216 ;;Third pass. Build final link except for leading type
1217 ;;spec.
1218 (cond
1219 ((or
1220 (not type)
1221 (string= type "http")
1222 (string= type "https")
1223 (string= type "file")
1224 (string= type "coderef"))
1225 (if fragment
1226 (setq thefile (concat thefile "#" fragment))))
1228 (t))
1230 ;;Final URL-build, for all types.
1231 (setq thefile
1232 (let
1233 ((str (org-xml-format-href thefile)))
1234 (if (and type (not (or (string= "file" type)
1235 (string= "coderef" type))))
1236 (concat type ":" str)
1237 str)))
1239 (if may-inline-p
1240 (org-e-html-format-image thefile)
1241 (org-lparse-format
1242 'LINK (org-xml-format-desc desc) thefile attr)))))
1244 (defun org-e-html-format-inline-image (path &optional caption label attr)
1245 ;; FIXME: alt text missing here?
1246 (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
1247 path (file-name-nondirectory path))))
1248 (if (not label) inline-image
1249 (org-e-html-format-section inline-image "figure" label))))
1251 (defun org-e-html-format-image (src)
1252 "Create image tag with source and attributes."
1253 (save-match-data
1254 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1255 (attr (org-find-text-property-in-string 'org-attributes src))
1256 (label (org-find-text-property-in-string 'org-label src))
1257 (caption (and caption (org-xml-encode-org-text caption)))
1258 (img-extras (if (string-match "^ltxpng/" src)
1259 (format " alt=\"%s\""
1260 (org-find-text-property-in-string
1261 'org-latex-src src))
1262 (if (string-match "\\<alt=" (or attr ""))
1263 (concat " " attr )
1264 (concat " " attr " alt=\"" src "\""))))
1265 (img (format "<img src=\"%s\"%s />" src img-extras))
1266 (extra (concat
1267 (and label
1268 (format "id=\"%s\" " (org-solidify-link-text label)))
1269 "class=\"figure\"")))
1270 (if caption
1271 (with-temp-buffer
1272 (with-org-lparse-preserve-paragraph-state
1273 (insert
1274 (org-lparse-format
1275 '("<div %s>" . "\n</div>")
1276 (concat
1277 (org-lparse-format '("\n<p>" . "</p>") img)
1278 (org-lparse-format '("\n<p>" . "</p>") caption))
1279 extra)))
1280 (buffer-string))
1281 img))))
1283 ;;;; Bibliography
1285 (defun org-e-html-bibliography ()
1286 "Find bibliography, cut it out and return it."
1287 (catch 'exit
1288 (let (beg end (cnt 1) bib)
1289 (save-excursion
1290 (goto-char (point-min))
1291 (when (re-search-forward
1292 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1293 (setq beg (match-beginning 0))
1294 (while (re-search-forward "</?div\\>" nil t)
1295 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1296 (when (= cnt 0)
1297 (and (looking-at ">") (forward-char 1))
1298 (setq bib (buffer-substring beg (point)))
1299 (delete-region beg (point))
1300 (throw 'exit bib))))
1301 nil))))
1303 ;;;; Table
1305 (defun org-e-html-format-table (lines olines)
1306 (let ((org-e-html-format-table-no-css nil))
1307 (org-lparse-format-table lines olines)))
1309 (defun org-e-html-splice-attributes (tag attributes)
1310 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1311 (if (not attributes)
1313 (let (oldatt newatt)
1314 (setq oldatt (org-extract-attributes-from-string tag)
1315 tag (pop oldatt)
1316 newatt (cdr (org-extract-attributes-from-string attributes)))
1317 (while newatt
1318 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1319 (if (string-match ">" tag)
1320 (setq tag
1321 (replace-match (concat (org-attributes-to-string oldatt) ">")
1322 t t tag)))
1323 tag)))
1325 (defun org-export-splice-style (style extra)
1326 "Splice EXTRA into STYLE, just before \"</style>\"."
1327 (if (and (stringp extra)
1328 (string-match "\\S-" extra)
1329 (string-match "</style>" style))
1330 (concat (substring style 0 (match-beginning 0))
1331 "\n" extra "\n"
1332 (substring style (match-beginning 0)))
1333 style))
1335 (defun org-export-e-htmlize-region-for-paste (beg end)
1336 "Convert the region to HTML, using htmlize.el.
1337 This is much like `htmlize-region-for-paste', only that it uses
1338 the settings define in the org-... variables."
1339 (let* ((htmlize-output-type org-export-e-htmlize-output-type)
1340 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
1341 (htmlbuf (htmlize-region beg end)))
1342 (unwind-protect
1343 (with-current-buffer htmlbuf
1344 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1345 (plist-get htmlize-buffer-places 'content-end)))
1346 (kill-buffer htmlbuf))))
1348 ;;;###autoload
1349 (defun org-export-e-htmlize-generate-css ()
1350 "Create the CSS for all font definitions in the current Emacs session.
1351 Use this to create face definitions in your CSS style file that can then
1352 be used by code snippets transformed by htmlize.
1353 This command just produces a buffer that contains class definitions for all
1354 faces used in the current Emacs session. You can copy and paste the ones you
1355 need into your CSS file.
1357 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1358 the function `org-export-e-htmlize-region-for-paste' will produce code
1359 that uses these same face definitions."
1360 (interactive)
1361 (require 'htmlize)
1362 (and (get-buffer "*html*") (kill-buffer "*html*"))
1363 (with-temp-buffer
1364 (let ((fl (face-list))
1365 (htmlize-css-name-prefix "org-")
1366 (htmlize-output-type 'css)
1367 f i)
1368 (while (setq f (pop fl)
1369 i (and f (face-attribute f :inherit)))
1370 (when (and (symbolp f) (or (not i) (not (listp i))))
1371 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1372 (htmlize-region (point-min) (point-max))))
1373 (org-pop-to-buffer-same-window "*html*")
1374 (goto-char (point-min))
1375 (if (re-search-forward "<style" nil t)
1376 (delete-region (point-min) (match-beginning 0)))
1377 (if (re-search-forward "</style>" nil t)
1378 (delete-region (1+ (match-end 0)) (point-max)))
1379 (beginning-of-line 1)
1380 (if (looking-at " +") (replace-match ""))
1381 (goto-char (point-min)))
1383 (defun org-e-html-format-toc-entry (snumber todo headline tags href)
1384 (setq headline (concat
1385 ;; section number
1386 (and org-export-with-section-numbers (concat snumber " "))
1387 ;; headline
1388 headline
1389 ;; tags
1390 (and tags (concat
1391 (org-e-html-format-spaces 3)
1392 (org-e-html-format-fontify tags "tag")))))
1393 ;; fontify headline based on TODO keyword
1394 (when todo (setq headline (org-e-html-format-fontify headline "todo")))
1395 (org-e-html-format-link headline (concat "#" href)))
1397 (defun org-e-html-toc-entry-formatter
1398 (level snumber todo todo-type priority
1399 headline tags target extra-targets extra-class)
1400 (org-e-html-format-toc-entry snumber todo headline tags target))
1402 (defun org-e-html-make-string (n string)
1403 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1405 (defun org-e-html-toc-text (toc-entries)
1406 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1407 (start-level prev-level))
1408 (concat
1409 (mapconcat
1410 (lambda (entry)
1411 (let ((headline (nth 0 entry))
1412 (level (nth 1 entry)))
1413 (concat
1414 (let* ((cnt (- level prev-level))
1415 (times (if (> cnt 0) (1- cnt) (- cnt)))
1416 rtn)
1417 (setq prev-level level)
1418 (concat
1419 (org-e-html-make-string
1420 times (cond ((> cnt 0) "<ul>\n<li>\n")
1421 ((< cnt 0) "</li>\n</ul>\n")))
1422 (if (> cnt 0) "<ul>\n<li>\n" "</li>\n<li>\n")))
1423 headline)))
1424 toc-entries "")
1425 (org-e-html-make-string
1426 (- prev-level start-level) "</li>\n</ul>\n"))))
1428 (defun org-e-html-toc (depth info)
1429 (assert (wholenump depth))
1430 (let* ((headlines (org-export-collect-headlines info depth))
1431 (toc-entries
1432 (loop for headline in headlines collect
1433 (list (org-e-html-headline-text
1434 headline info 'org-e-html-toc-entry-formatter)
1435 (org-export-get-relative-level headline info)))))
1436 (when toc-entries
1437 (let* ((lang-specific-heading "Table of Contents")) ; FIXME
1438 (concat
1439 "<div id=\"table-of-contents\">\n"
1440 (org-e-html-format-heading lang-specific-heading
1441 (or org-e-html-toplevel-hlevel 1))
1442 "<div id=\"text-table-of-contents\">"
1443 (org-e-html-toc-text toc-entries)
1444 "</div>\n"
1445 "</div>\n")))))
1447 (defun org-e-html-begin-outline (level1 snumber title tags
1448 target extra-targets extra-class)
1449 (let* ((class (format "outline-%d" level1))
1450 (class (if extra-class (concat class " " extra-class) class))
1451 (id (format "outline-container-%s"
1452 (org-lparse-suffix-from-snumber snumber)))
1453 (extra (concat (when id (format " id=\"%s\"" id))
1454 (when class (format " class=\"%s\"" class)))))
1455 (org-lparse-insert-tag "<div%s>" extra)
1456 (insert
1457 (org-lparse-format 'HEADING
1458 (org-lparse-format
1459 'HEADLINE title extra-targets tags snumber level1)
1460 level1 target))))
1462 (defun org-e-html-end-outline ()
1463 (org-lparse-insert-tag "</div>"))
1466 ;; (defun org-e-html-format-heading (text level &optional id)
1467 ;; (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1468 ;; (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
1470 (defun org-e-html-suffix-from-snumber (snumber)
1471 (let* ((snu (replace-regexp-in-string "\\." "-" snumber))
1472 (href (cdr (assoc (concat "sec-" snu)
1473 org-export-preferred-target-alist))))
1474 (org-solidify-link-text (or href snu))))
1476 (defun org-e-html-format-outline (contents level1 snumber title
1477 tags target extra-targets extra-class)
1478 (let* ((class (format "outline-%d" level1))
1479 (class (if extra-class (concat class " " extra-class) class))
1480 (id (and snumber ;; FIXME
1481 (format "outline-container-%s"
1482 (org-e-html-suffix-from-snumber snumber))))
1483 (extra (concat (when id (format " id=\"%s\"" id))
1484 (when class (format " class=\"%s\"" class)))))
1485 (concat
1486 (format "<div%s>\n" extra)
1487 (org-e-html-format-heading
1488 (org-e-html-format-headline title extra-targets tags snumber level1)
1489 level1 target)
1490 contents
1491 "</div>")))
1493 (defun org-e-html-begin-outline-text (level1 snumber extra-class)
1494 (let* ((class (format "outline-text-%d" level1))
1495 (class (if extra-class (concat class " " extra-class) class))
1496 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber)))
1497 (extra (concat (when id (format " id=\"%s\"" id))
1498 (when class (format " class=\"%s\"" class)))))
1499 (org-lparse-insert-tag "<div%s>" extra)))
1501 (defun org-e-html-end-outline-text ()
1502 (org-lparse-insert-tag "</div>"))
1504 (defun org-e-html-format-spaces (n)
1505 (let (out) (dotimes (i n out) (setq out (concat out "&nbsp;")))))
1507 (defun org-e-html-format-tabs (&optional n)
1508 (ignore))
1510 (defun org-e-html-format-line-break ()
1511 "<br/>\n")
1513 (defun org-e-html-format-horizontal-line ()
1514 "<hr/>\n")
1516 ;; (defun org-e-html-format-line (line)
1517 ;; (case org-lparse-dyn-current-environment
1518 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1519 ;; (t (concat line "\n"))))
1521 (defun org-e-html-format-comment (fmt &rest args)
1522 (let ((comment (apply 'format fmt args)))
1523 (format "\n<!-- %s -->\n" comment)))
1525 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1526 "Turn todo keyword into a valid class name.
1527 Replaces invalid characters with \"_\"."
1528 (save-match-data
1529 (while (string-match "[^a-zA-Z0-9_]" kwd)
1530 (setq kwd (replace-match "_" t t kwd))))
1531 kwd)
1533 (defun org-e-html-format-fontify (text style &optional id)
1534 (let (class extra how)
1535 (cond
1536 ((eq style 'underline)
1537 (setq extra " style=\"text-decoration:underline;\"" ))
1538 ((setq how (cdr (assoc style
1539 '((bold . ("<b>" . "</b>"))
1540 (emphasis . ("<i>" . "</i>"))
1541 (code . ("<code>" . "</code>"))
1542 (verbatim . ("<code>" . "</code>"))
1543 (strike . ("<del>" . "</del>"))
1544 (subscript . ("<sub>" . "</sub>"))
1545 (superscript . ("<sup>" . "</sup>")))))))
1546 ((listp style)
1547 (setq class (mapconcat 'identity style " ")))
1548 ((stringp style)
1549 (setq class style))
1550 (t (error "Unknown style %S" style)))
1552 (setq extra (concat (when class (format " class=\"%s\"" class))
1553 (when id (format " id=\"%s\"" id))
1554 extra))
1556 (let ((tags (or how '("<span%s>" . "</span>"))))
1557 (concat (format (car tags) extra) text (cdr tags)))))
1559 (defun org-e-html-format-link (text href &optional extra)
1560 (let ((extra (concat (format " href=\"%s\"" href)
1561 (and extra (concat " " extra)))))
1562 (format "<a%s>%s</a>" extra text)))
1564 (defun org-e-html-format-internal-link (text href &optional extra)
1565 (org-e-html-format-link text (concat "#" href) extra))
1567 (defun org-e-html-format-heading (text level &optional id)
1568 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
1569 (concat (format "<h%d%s>" level extra) text (format "</h%d>\n" level))))
1571 (defun org-e-html-format-anchor (text name &optional class)
1572 (let* ((id name)
1573 (extra (concat
1574 (when name (format " name=\"%s\"" name))
1575 (when id (format " id=\"%s\"" id))
1576 (when class (format " class=\"%s\"" class)))))
1577 (format "<a%s>%s</a>" extra text)))
1579 (defun org-e-html-format-extra-targets (extra-targets)
1580 (if (not extra-targets) ""
1581 (mapconcat (lambda (x)
1582 (when x
1583 (setq x (org-solidify-link-text
1584 (if (org-uuidgen-p x) (concat "ID-" x) x)))
1585 (org-e-html-format-anchor "" x))) extra-targets "")))
1587 (defun org-e-html-format-org-tags (tags)
1588 (if (not tags) ""
1589 (org-e-html-format-fontify
1590 (mapconcat
1591 (lambda (x)
1592 (org-e-html-format-fontify
1593 x (concat org-e-html-tag-class-prefix
1594 (org-e-html-fix-class-name x))))
1595 (org-split-string tags ":")
1596 (org-e-html-format-spaces 1)) "tag")))
1598 (defun org-e-html-format-section-number (&optional snumber level)
1599 ;; FIXME
1600 (and org-export-with-section-numbers
1601 ;; (not org-lparse-body-only)
1602 snumber level
1603 (org-e-html-format-fontify snumber (format "section-number-%d" level))))
1605 (defun org-e-html-format-headline (title extra-targets tags
1606 &optional snumber level)
1607 (concat
1608 (org-e-html-format-extra-targets extra-targets)
1609 (concat (org-e-html-format-section-number snumber level) " ")
1610 title
1611 (and tags (concat (org-e-html-format-spaces 3)
1612 (org-e-html-format-org-tags tags)))))
1614 (defun org-e-html-format-footnote-reference (n def refcnt)
1615 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1616 (format org-e-html-footnote-format
1617 (format
1618 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1619 n extra n n))))
1621 (defun org-e-html-format-footnotes-section (section-name definitions)
1622 (if (not definitions) ""
1623 (format org-e-html-footnotes-section section-name definitions)))
1625 (defun org-e-html-format-footnote-definition (fn)
1626 (let ((n (car fn)) (def (cdr fn)))
1627 (format
1628 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1629 (format
1630 (format org-e-html-footnote-format
1631 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1632 n n n) def)))
1634 (defun org-e-html-footnote-section (info)
1635 (let* ((fn-alist (org-export-collect-footnote-definitions
1636 (plist-get info :parse-tree) info))
1638 (fn-alist
1639 (loop for (n type raw) in fn-alist collect
1640 (cons n (if (equal (car raw) 'org-data)
1641 (org-trim (org-export-data raw 'e-html info))
1642 (format "<p>%s</p>"
1643 (org-trim (org-export-secondary-string
1644 raw 'e-html info))))))))
1645 (when fn-alist
1646 (org-e-html-format-footnotes-section
1647 (nth 4 (or (assoc (plist-get info :language)
1648 org-export-language-setup)
1649 (assoc "en" org-export-language-setup)))
1651 (format
1652 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">\n%s\n</table>\n"
1653 (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
1655 (defun org-e-html-format-org-entity (wd)
1656 (org-entity-get-representation wd 'html))
1658 (defun org-e-html-get-coding-system-for-write ()
1659 (or org-e-html-coding-system
1660 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1662 (defun org-e-html-get-coding-system-for-save ()
1663 (or org-e-html-coding-system
1664 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
1666 (defun org-e-html-format-date (info)
1667 (let ((date (plist-get info :date)))
1668 (cond
1669 ((and date (string-match "%" date))
1670 (format-time-string date))
1671 (date date)
1672 (t (format-time-string "%Y-%m-%d %T %Z")))))
1676 ;;; Internal Functions (Ngz)
1678 (defun org-e-html--caption/label-string (caption label info)
1679 "Return caption and label HTML string for floats.
1681 CAPTION is a cons cell of secondary strings, the car being the
1682 standard caption and the cdr its short form. LABEL is a string
1683 representing the label. INFO is a plist holding contextual
1684 information.
1686 If there's no caption nor label, return the empty string.
1688 For non-floats, see `org-e-html--wrap-label'."
1689 (setq label nil) ;; FIXME
1691 (let ((label-str (if label (format "\\label{%s}" label) "")))
1692 (cond
1693 ((and (not caption) (not label)) "")
1694 ((not caption) (format "\\label{%s}\n" label))
1695 ;; Option caption format with short name.
1696 ((cdr caption)
1697 (format "\\caption[%s]{%s%s}\n"
1698 (org-export-secondary-string (cdr caption) 'e-html info)
1699 label-str
1700 (org-export-secondary-string (car caption) 'e-html info)))
1701 ;; Standard caption format.
1702 ;; (t (format "\\caption{%s%s}\n"
1703 ;; label-str
1704 ;; (org-export-secondary-string (car caption) 'e-html info)))
1706 (t (org-export-secondary-string (car caption) 'e-html info)))))
1708 (defun org-e-html--find-verb-separator (s)
1709 "Return a character not used in string S.
1710 This is used to choose a separator for constructs like \\verb."
1711 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1712 (loop for c across ll
1713 when (not (string-match (regexp-quote (char-to-string c)) s))
1714 return (char-to-string c))))
1716 (defun org-e-html--make-option-string (options)
1717 "Return a comma separated string of keywords and values.
1718 OPTIONS is an alist where the key is the options keyword as
1719 a string, and the value a list containing the keyword value, or
1720 nil."
1721 (mapconcat (lambda (pair)
1722 (concat (first pair)
1723 (when (> (length (second pair)) 0)
1724 (concat "=" (second pair)))))
1725 options
1726 ","))
1728 (defun org-e-html--quotation-marks (text info)
1729 "Export quotation marks depending on language conventions.
1730 TEXT is a string containing quotation marks to be replaced. INFO
1731 is a plist used as a communication channel."
1732 (mapc (lambda(l)
1733 (let ((start 0))
1734 (while (setq start (string-match (car l) text start))
1735 (let ((new-quote (concat (match-string 1 text) (cdr l))))
1736 (setq text (replace-match new-quote t t text))))))
1737 (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
1738 ;; Falls back on English.
1739 (assoc "en" org-e-html-quotes))))
1740 text)
1742 (defun org-e-html--wrap-label (element output)
1743 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1744 This function shouldn't be used for floats. See
1745 `org-e-html--caption/label-string'."
1746 ;; (let ((label (org-element-get-property :name element)))
1747 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1748 ;; output
1749 ;; (concat (format "\\label{%s}\n" label) output)))
1750 output)
1754 ;;; Template
1756 (defun org-e-html-meta-info (info)
1757 (let* ((title (org-export-secondary-string
1758 (plist-get info :title) 'e-html info))
1759 (author (and (plist-get info :with-author)
1760 (let ((auth (plist-get info :author)))
1761 (and auth (org-export-secondary-string
1762 auth 'e-html info)))))
1763 (description (plist-get info :description))
1764 (keywords (plist-get info :keywords)))
1765 (concat
1766 (format "<title>%s</title>\n" title)
1767 (format
1768 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1769 (and coding-system-for-write
1770 (fboundp 'coding-system-get)
1771 (coding-system-get coding-system-for-write
1772 'mime-charset)))
1773 (format "<meta name=\"title\" content=\"%s\"/>\n" title)
1774 (format "<meta name=\"generator\" content=\"Org-mode\"/>")
1775 (format "<meta name=\"generated\" content=\"%s\"/>\n"
1776 (org-e-html-format-date info))
1777 (format "<meta name=\"author\" content=\"%s\"/>\n" author)
1778 (format "<meta name=\"description\" content=\"%s\"/>\n" description)
1779 (format " <meta name=\"keywords\" content=\"%s\"/>\n" keywords))))
1781 (defun org-e-html-style (info)
1782 (concat
1783 (when (plist-get info :style-include-default)
1784 org-e-html-style-default)
1785 (plist-get info :style)
1786 (plist-get info :style-extra)
1787 "\n"
1788 (when (plist-get info :style-include-scripts)
1789 org-e-html-scripts)))
1791 (defun org-e-html-mathjax-config (template options in-buffer)
1792 "Insert the user setup into the matchjax template."
1793 (let (name val (yes " ") (no "// ") x)
1794 (mapc
1795 (lambda (e)
1796 (setq name (car e) val (nth 1 e))
1797 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1798 (setq val (car (read-from-string
1799 (substring in-buffer (match-end 0))))))
1800 (if (not (stringp val)) (setq val (format "%s" val)))
1801 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1802 (setq template (replace-match val t t template))))
1803 options)
1804 (setq val (nth 1 (assq 'mathml options)))
1805 (if (string-match (concat "\\<mathml:") in-buffer)
1806 (setq val (car (read-from-string
1807 (substring in-buffer (match-end 0))))))
1808 ;; Exchange prefixes depending on mathml setting
1809 (if (not val) (setq x yes yes no no x))
1810 ;; Replace cookies to turn on or off the config/jax lines
1811 (if (string-match ":MMLYES:" template)
1812 (setq template (replace-match yes t t template)))
1813 (if (string-match ":MMLNO:" template)
1814 (setq template (replace-match no t t template)))
1815 ;; Return the modified template
1816 template))
1818 (defun org-e-html-mathjax (info)
1819 (when (or (eq (plist-get info :HTML-fragments) 'mathjax)
1820 (and org-export-have-math
1821 (eq (plist-get info :HTML-fragments) t)))
1822 (org-e-html-mathjax-config
1823 org-e-html-mathjax-template
1824 org-e-html-mathjax-options
1825 (or (plist-get info :mathjax) ""))))
1827 (defun org-e-html-preamble (info)
1828 (when (plist-get info :html-preamble)
1829 (let* ((title (plist-get info :title))
1830 (date (org-e-html-format-date info))
1831 (author (plist-get info :author))
1832 (lang-words (or (assoc (plist-get info :language)
1833 org-export-language-setup)
1834 (assoc "en" org-export-language-setup)))
1835 (email (plist-get info :email))
1836 (html-pre-real-contents
1837 (cond
1838 ((functionp (plist-get info :html-preamble))
1839 (with-temp-buffer
1840 (funcall (plist-get info :html-preamble))
1841 (buffer-string)))
1842 ((stringp (plist-get info :html-preamble))
1843 (format-spec (plist-get info :html-preamble)
1844 `((?t . ,title) (?a . ,author)
1845 (?d . ,date) (?e . ,email))))
1847 (format-spec
1848 (or (cadr (assoc (nth 0 lang-words)
1849 org-e-html-preamble-format))
1850 (cadr (assoc "en" org-e-html-preamble-format)))
1851 `((?t . ,title) (?a . ,author)
1852 (?d . ,date) (?e . ,email)))))))
1853 (when (not (equal html-pre-real-contents ""))
1854 (concat
1855 (format "
1856 <div id=\"%s\"> " (nth 0 org-e-html-divs))
1859 html-pre-real-contents
1861 </div>")))))
1863 (defun org-e-html-postamble (info)
1864 (concat
1865 (when (and (not body-only)
1866 (plist-get info :html-postamble))
1867 (let* ((html-post (plist-get info :html-postamble))
1868 (date (org-e-html-format-date info))
1869 (author (plist-get info :author))
1870 (email (plist-get info :email))
1871 (lang-words (or (assoc (plist-get info :language)
1872 org-export-language-setup)
1873 (assoc "en" org-export-language-setup)))
1874 (email
1875 (mapconcat (lambda(e)
1876 (format "<a href=\"mailto:%s\">%s</a>" e e))
1877 (split-string email ",+ *")
1878 ", "))
1879 (html-validation-link (or org-e-html-validation-link ""))
1880 (creator-info
1881 (concat "Org version " org-version " with Emacs version "
1882 (number-to-string emacs-major-version))))
1883 (concat
1884 ;; begin postamble
1886 <div id=\"" (nth 2 org-e-html-divs) "\">"
1887 (cond
1888 ;; auto postamble
1889 ((eq (plist-get info :html-postamble) 'auto)
1890 (concat
1891 (when (plist-get info :time-stamp-file)
1892 (format "
1893 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
1894 (when (and (plist-get info :with-author) author)
1895 (format "
1896 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
1897 (when (and (plist-get info :with-email) email)
1898 (format "
1899 <p class=\"email\"> %s </p>" email))
1900 (when (plist-get info :with-creator)
1901 (format "
1902 <p class=\"creator\"> %s </p>" creator-info))
1903 html-validation-link "\n"))
1904 ;; postamble from a string
1905 ((stringp (plist-get info :html-postamble))
1906 (format-spec (plist-get info :html-postamble)
1907 `((?a . ,author) (?e . ,email)
1908 (?d . ,date) (?c . ,creator-info)
1909 (?v . ,html-validation-link))))
1911 ;; postamble from a function
1912 ((functionp (plist-get info :html-postamble))
1913 (with-temp-buffer
1914 (funcall (plist-get info :html-postamble))
1915 (buffer-string)))
1916 ;; default postamble
1918 (format-spec
1919 (or (cadr (assoc (nth 0 lang-words)
1920 org-e-html-postamble-format))
1921 (cadr (assoc "en" org-e-html-postamble-format)))
1922 `((?a . ,author) (?e . ,email)
1923 (?d . ,date) (?c . ,creator-info)
1924 (?v . ,html-validation-link)))))
1926 </div>")))
1927 ;; org-e-html-html-helper-timestamp
1930 (defun org-e-html-template (contents info)
1931 "Return complete document string after HTML conversion.
1932 CONTENTS is the transcoded contents string. RAW-DATA is the
1933 original parsed data. INFO is a plist holding export options."
1934 (concat
1935 (format
1936 (or (and (stringp org-e-html-xml-declaration)
1937 org-e-html-xml-declaration)
1938 (cdr (assoc (plist-get info :html-extension)
1939 org-e-html-xml-declaration))
1940 (cdr (assoc "html" org-e-html-xml-declaration))
1943 (or (and coding-system-for-write
1944 (fboundp 'coding-system-get)
1945 (coding-system-get coding-system-for-write
1946 'mime-charset))
1947 "iso-8859-1"))
1949 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1950 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1951 (format "
1952 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1953 (plist-get info :language) (plist-get info :language))
1955 <head>"
1956 (org-e-html-meta-info info) ; meta
1957 (org-e-html-style info) ; style
1958 (org-e-html-mathjax info) ; mathjax
1960 </head>"
1963 <body>"
1964 (let ((link-up (and (plist-get info :link-up)
1965 (string-match "\\S-" (plist-get info :link-up))
1966 (plist-get info :link-up)))
1967 (link-home (and (plist-get info :link-home)
1968 (string-match "\\S-" (plist-get info :link-home))
1969 (plist-get info :link-home))))
1970 (when (or link-up link-home)
1971 (format org-e-html-home/up-format
1972 (or link-up link-home)
1973 (or link-home link-up))))
1974 ;; preamble
1975 (org-e-html-preamble info)
1976 ;; begin content
1977 (format "
1978 <div id=\"%s\">" (or org-e-html-content-div
1979 (nth 1 org-e-html-divs)))
1980 ;; document title
1981 (format "
1982 <h1 class=\"title\"> %s </h1>\n" (plist-get info :title))
1983 ;; table of contents
1984 (let ((depth (plist-get info :with-toc)))
1985 (when (wholenump depth) (org-e-html-toc depth info)))
1986 ;; document contents
1987 contents
1988 ;; footnotes section
1989 (org-e-html-footnote-section info)
1990 ;; bibliography
1991 (org-e-html-bibliography)
1992 ;; end content
1993 (unless body-only
1995 </div>")
1997 ;; postamble
1998 (org-e-html-postamble info)
2000 (unless body-only
2002 </body>")
2004 </html>"))
2008 ;;; Transcode Functions
2010 ;;;; Block
2012 (defun org-e-html-center-block (center-block contents info)
2013 "Transcode a CENTER-BLOCK element from Org to HTML.
2014 CONTENTS holds the contents of the block. INFO is a plist
2015 holding contextual information."
2016 (org-e-html--wrap-label
2017 center-block
2018 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
2021 ;;;; Comment
2023 ;; Comments are ignored.
2026 ;;;; Comment Block
2028 ;; Comment Blocks are ignored.
2031 ;;;; Drawer
2033 (defun org-e-html-drawer (drawer contents info)
2034 "Transcode a DRAWER element from Org to HTML.
2035 CONTENTS holds the contents of the block. INFO is a plist
2036 holding contextual information."
2037 (let* ((name (org-element-get-property :drawer-name drawer))
2038 (output (if (functionp org-e-html-format-drawer-function)
2039 (funcall org-e-html-format-drawer-function
2040 name contents)
2041 ;; If there's no user defined function: simply
2042 ;; display contents of the drawer.
2043 contents)))
2044 (org-e-html--wrap-label drawer output)))
2047 ;;;; Dynamic Block
2049 (defun org-e-html-dynamic-block (dynamic-block contents info)
2050 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
2051 CONTENTS holds the contents of the block. INFO is a plist
2052 holding contextual information. See
2053 `org-export-data'."
2054 (org-e-html--wrap-label dynamic-block contents))
2057 ;;;; Emphasis
2059 (defun org-e-html-emphasis (emphasis contents info)
2060 "Transcode EMPHASIS from Org to HTML.
2061 CONTENTS is the contents of the emphasized text. INFO is a plist
2062 holding contextual information.."
2063 ;; (format (cdr (assoc (org-element-get-property :marker emphasis)
2064 ;; org-e-html-emphasis-alist))
2065 ;; contents)
2066 (org-e-html-format-fontify
2067 contents (cadr (assoc
2068 (org-element-get-property :marker emphasis)
2069 '(("*" bold)
2070 ("/" emphasis)
2071 ("_" underline)
2072 ("=" code)
2073 ("~" verbatim)
2074 ("+" strike))))))
2077 ;;;; Entity
2079 (defun org-e-html-entity (entity contents info)
2080 "Transcode an ENTITY object from Org to HTML.
2081 CONTENTS are the definition itself. INFO is a plist holding
2082 contextual information."
2083 ;; (let ((ent (org-element-get-property :latex entity)))
2084 ;; (if (org-element-get-property :latex-math-p entity)
2085 ;; (format "$%s$" ent)
2086 ;; ent))
2087 (org-element-get-property :html entity))
2090 ;;;; Example Block
2093 ;; (defun org-odt-format-source-code-or-example-colored
2094 ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
2096 (defun org-e-html-format-source-code-or-example-plain
2097 (lines lang caption textareap cols rows num cont rpllbl fmt)
2098 (setq lines
2099 (concat
2100 "<pre class=\"example\">\n"
2101 (cond
2102 (textareap
2103 (concat
2104 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">"
2105 cols rows)
2106 lines "</textarea>\n</p>\n"))
2108 (with-temp-buffer
2109 (insert lines)
2110 (goto-char (point-min))
2111 (while (re-search-forward "[<>&]" nil t)
2112 (replace-match (cdr (assq (char-before)
2113 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2114 t t))
2115 (buffer-string))))
2116 "</pre>\n"))
2118 (unless textareap
2119 (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
2121 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
2122 ;; (setq lines (replace-match "\\1" t nil lines)))
2124 lines)
2126 (defun org-e-html-format-source-code-or-example-colored
2127 (lines lang caption textareap cols rows num cont rpllbl fmt)
2128 (let* ((lang-m (when lang
2129 (or (cdr (assoc lang org-src-lang-modes))
2130 lang)))
2131 (mode (and lang-m (intern
2132 (concat
2133 (if (symbolp lang-m)
2134 (symbol-name lang-m)
2135 lang-m)
2136 "-mode"))))
2137 (org-inhibit-startup t)
2138 (org-startup-folded nil))
2139 (setq lines
2140 (with-temp-buffer
2141 (insert lines)
2142 (if (functionp mode)
2143 (funcall mode)
2144 (fundamental-mode))
2145 (font-lock-fontify-buffer)
2146 ;; markup each line separately
2147 (org-remove-formatting-on-newlines-in-region
2148 (point-min) (point-max))
2149 (org-src-mode)
2150 (set-buffer-modified-p nil)
2151 (org-export-e-htmlize-region-for-paste
2152 (point-min) (point-max))))
2154 (when (string-match "<pre\\([^>]*\\)>\n*" lines)
2155 (setq lines (replace-match
2156 (format "<pre class=\"src src-%s\">\n" lang) t t lines)))
2158 (when caption
2159 (setq lines
2160 (concat
2161 "<div class=\"org-src-container\">"
2162 (format "<label class=\"org-src-name\">%s</label>" caption)
2163 lines "</div>")))
2165 (unless textareap
2166 (setq lines (org-export-number-lines lines 1 1 num cont rpllbl fmt)))
2168 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
2169 ;; (setq lines (replace-match "\\1" t nil lines)))
2170 lines))
2172 (defun org-e-html-format-source-code-or-example
2173 (lang code &optional opts indent caption)
2174 "Format CODE from language LANG and return it formatted for export.
2175 The CODE is marked up in `org-export-current-backend' format.
2177 Check if a function by name
2178 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
2179 use it as the custom formatter. Otherwise, use the default
2180 formatter. Default formatters are provided for docbook, html,
2181 latex and ascii backends. For example, use
2182 `org-e-html-format-source-code-or-example' to provide a custom
2183 formatter for export to \"html\".
2185 If LANG is nil, do not add any fontification.
2186 OPTS contains formatting options, like `-n' for triggering numbering lines,
2187 and `+n' for continuing previous numbering.
2188 Code formatting according to language currently only works for HTML.
2189 Numbering lines works for all three major backends (html, latex, and ascii).
2190 INDENT was the original indentation of the block."
2191 (save-match-data
2192 (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain)
2193 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
2194 (setq opts (or opts "")
2195 num (string-match "[-+]n\\>" opts)
2196 cont (string-match "\\+n\\>" opts)
2197 rpllbl (string-match "-r\\>" opts)
2198 keepp (string-match "-k\\>" opts)
2199 textareap (string-match "-t\\>" opts)
2200 preserve-indentp (or org-src-preserve-indentation
2201 (string-match "-i\\>" opts))
2202 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2203 (string-to-number (match-string 1 opts))
2205 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2206 (string-to-number (match-string 1 opts))
2207 (org-count-lines code))
2208 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2209 (match-string 1 opts)))
2210 (when (and textareap
2211 ;; (eq org-export-current-backend 'html)
2213 ;; we cannot use numbering or highlighting.
2214 (setq num nil cont nil lang nil))
2215 (if keepp (setq rpllbl 'keep))
2216 (setq rtn (if preserve-indentp code (org-remove-indentation code)))
2217 (when (string-match "^," rtn)
2218 (setq rtn (with-temp-buffer
2219 (insert rtn)
2220 ;; Free up the protected lines
2221 (goto-char (point-min))
2222 (while (re-search-forward "^," nil t)
2223 (if (or (equal lang "org")
2224 (save-match-data
2225 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
2226 (replace-match ""))
2227 (end-of-line 1))
2228 (buffer-string))))
2229 (when lang
2230 (if (featurep 'xemacs)
2231 (require 'htmlize)
2232 (require 'htmlize nil t)))
2234 (setq backend-formatter
2235 (cond
2236 ((fboundp 'htmlize-region-for-paste)
2237 'org-e-html-format-source-code-or-example-colored)
2239 (message
2240 "htmlize.el 1.34 or later is needed for source code formatting")
2241 'org-e-html-format-source-code-or-example-plain)))
2242 (funcall backend-formatter rtn lang caption textareap cols rows
2243 num cont rpllbl fmt))))
2245 (defun org-e-html-example-block (example-block contents info)
2246 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2247 CONTENTS is nil. INFO is a plist holding contextual information."
2248 (let* ((options (or (org-element-get-property :options example-block) ""))
2249 (value (org-export-handle-code example-block info)))
2250 ;; (org-e-html--wrap-label
2251 ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
2252 (org-e-html--wrap-label
2253 example-block (org-e-html-format-source-code-or-example nil value))))
2256 ;;;; Export Snippet
2258 (defun org-e-html-export-snippet (export-snippet contents info)
2259 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2260 CONTENTS is nil. INFO is a plist holding contextual information."
2261 (org-element-get-property :value export-snippet))
2264 ;;;; Export Block
2266 (defun org-e-html-export-block (export-block contents info)
2267 "Transcode a EXPORT-BLOCK element from Org to HTML.
2268 CONTENTS is nil. INFO is a plist holding contextual information."
2269 (when (string= (org-element-get-property :type export-block) "latex")
2270 (org-remove-indentation (org-element-get-property :value export-block))))
2273 ;;;; Fixed Width
2275 (defun org-e-html-fixed-width (fixed-width contents info)
2276 "Transcode a FIXED-WIDTH element from Org to HTML.
2277 CONTENTS is nil. INFO is a plist holding contextual information."
2278 (let* ((value (org-element-normalize-string
2279 (replace-regexp-in-string
2280 "^[ \t]*: ?" ""
2281 (org-element-get-property :value fixed-width)))))
2282 (org-e-html--wrap-label
2283 fixed-width (org-e-html-format-source-code-or-example nil value))))
2286 ;;;; Footnote Definition
2288 ;; Footnote Definitions are ignored.
2291 ;;;; Footnote Reference
2293 (defun org-e-html-footnote-reference (footnote-reference contents info)
2294 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2295 CONTENTS is nil. INFO is a plist holding contextual information."
2296 (concat
2297 ;; Insert separator between two footnotes in a row.
2298 (let ((prev (org-export-get-previous-element footnote-reference info)))
2299 (when (and (listp prev) (eq (car prev) 'footnote-reference))
2300 org-e-html-footnote-separator))
2301 (cond
2302 ((not (org-export-footnote-first-reference-p footnote-reference info))
2303 (org-e-html-format-footnote-reference
2304 (org-export-get-footnote-number footnote-reference info)
2305 "IGNORED" 100))
2306 ;; Inline definitions are secondary strings.
2307 ((eq (org-element-get-property :type footnote-reference) 'inline)
2308 (org-e-html-format-footnote-reference
2309 (org-export-get-footnote-number footnote-reference info)
2310 "IGNORED" 1))
2311 ;; Non-inline footnotes definitions are full Org data.
2312 (t (org-e-html-format-footnote-reference
2313 (org-export-get-footnote-number footnote-reference info)
2314 "IGNORED" 1)))))
2317 ;;;; Headline
2319 (defun org-e-html-todo (todo)
2320 (when todo
2321 (org-e-html-format-fontify
2322 (concat
2323 org-e-html-todo-kwd-class-prefix
2324 (org-e-html-fix-class-name todo))
2325 (list (if (member todo org-done-keywords) "done" "todo")
2326 todo))))
2328 (defun org-e-html-headline-text (headline info &optional formatter)
2329 "Transcode an HEADLINE element from Org to HTML.
2330 CONTENTS holds the contents of the headline. INFO is a plist
2331 holding contextual information."
2332 (let* ((numberedp (plist-get info :section-numbers))
2333 (level (org-export-get-relative-level headline info))
2334 (todo (and (plist-get info :with-todo-keywords)
2335 (let ((todo (org-element-get-property
2336 :todo-keyword headline)))
2337 (and todo
2338 (org-export-secondary-string todo 'e-html info)))))
2339 (todo-type (and todo (org-element-get-property :todo-type headline)))
2340 (priority (and (plist-get info :with-priority)
2341 (org-element-get-property :priority headline)))
2342 (text (org-export-secondary-string
2343 (org-element-get-property :title headline) 'e-html info))
2344 (tags (and (plist-get info :with-tags)
2345 (org-element-get-property :tags headline)))
2347 (headline-no (org-export-get-headline-number headline info))
2348 (headline-label
2349 (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
2350 (headline-labels (list headline-label))
2351 (headline-no (org-export-get-headline-number headline info))
2352 (section-no (mapconcat 'number-to-string headline-no "."))
2353 (primary-target (car (last headline-labels)))
2354 (secondary-targets (butlast headline-labels))
2355 (extra-class nil)
2356 (formatter (or (and (functionp formatter) formatter)
2357 org-e-html-headline-formatter)))
2358 (funcall formatter level section-no todo todo-type priority
2359 text tags primary-target secondary-targets extra-class)))
2361 (defun org-e-html-headline (headline contents info)
2362 "Transcode an HEADLINE element from Org to HTML.
2363 CONTENTS holds the contents of the headline. INFO is a plist
2364 holding contextual information."
2365 (let* ((class (plist-get info :latex-class))
2366 (numberedp (plist-get info :section-numbers))
2367 ;; Get level relative to current parsed data.
2368 (level (org-export-get-relative-level headline info))
2369 ;; (class-sectionning (assoc class org-e-html-classes))
2370 ;; Section formatting will set two placeholders: one for the
2371 ;; title and the other for the contents.
2372 ;; (section-fmt
2373 ;; (let ((sec (if (and (symbolp (nth 2 class-sectionning))
2374 ;; (fboundp (nth 2 class-sectionning)))
2375 ;; (funcall (nth 2 class-sectionning) level numberedp)
2376 ;; (nth (1+ level) class-sectionning))))
2377 ;; (cond
2378 ;; ;; No section available for that LEVEL.
2379 ;; ((not sec) nil)
2380 ;; ;; Section format directly returned by a function.
2381 ;; ((stringp sec) sec)
2382 ;; ;; (numbered-section . unnumbered-section)
2383 ;; ((not (consp (cdr sec)))
2384 ;; (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
2385 ;; ;; (numbered-open numbered-close)
2386 ;; ((= (length sec) 2)
2387 ;; (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
2388 ;; ;; (num-in num-out no-num-in no-num-out)
2389 ;; ((= (length sec) 4)
2390 ;; (if numberedp
2391 ;; (concat (car sec) "\n%s" (nth 1 sec))
2392 ;; (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
2393 (text (org-export-secondary-string
2394 (org-element-get-property :title headline) 'e-html info))
2395 (todo (and (plist-get info :with-todo-keywords)
2396 (let ((todo (org-element-get-property
2397 :todo-keyword headline)))
2398 (and todo
2399 (org-export-secondary-string todo 'e-html info)))))
2400 (todo-type (and todo (org-element-get-property :todo-type headline)))
2401 (tags (and (plist-get info :with-tags)
2402 (org-element-get-property :tags headline)))
2403 (priority (and (plist-get info :with-priority)
2404 (org-element-get-property :priority headline)))
2405 ;; Create the headline text.
2406 (full-text (if (functionp org-e-html-format-headline-function)
2407 ;; User-defined formatting function.
2408 (funcall org-e-html-format-headline-function
2409 todo todo-type priority text tags)
2410 ;; Default formatting.
2411 (concat
2412 ;; (when todo
2413 ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2414 (org-e-html-todo todo) " "
2415 (when priority (format "\\framebox{\\#%c} " priority))
2416 text
2417 ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
2419 ;; Associate some \label to the headline for internal links.
2420 ;; (headline-label
2421 ;; (format "\\label{sec-%s}\n"
2422 ;; (mapconcat 'number-to-string
2423 ;; (org-export-get-headline-number headline info)
2424 ;; "-")))
2426 ;; FIXME - begin
2427 (headline-no (org-export-get-headline-number headline info))
2428 (headline-label
2429 (format "sec-%s" (mapconcat 'number-to-string headline-no "-")))
2430 (headline-labels (list headline-label))
2431 (headline-no (org-export-get-headline-number headline info))
2432 (section-no (mapconcat 'number-to-string headline-no "."))
2433 ;; FIXME - end
2435 (pre-blanks (make-string
2436 (org-element-get-property :pre-blank headline) 10)))
2437 (cond
2438 ;; Case 1: This is a footnote section: ignore it.
2439 ((org-element-get-property :footnote-section-p headline) nil)
2440 ;; Case 2. This is a deep sub-tree: export it as a list item.
2441 ;; Also export as items headlines for which no section
2442 ;; format has been found.
2443 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
2444 ;; Build the real contents of the sub-tree.
2445 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
2446 (itemized-body (org-e-html-format-list-item
2447 contents type nil nil full-text)))
2448 (concat
2449 (and (org-export-first-sibling-p headline info)
2450 (org-e-html-begin-plain-list type))
2451 itemized-body
2452 (and (org-export-last-sibling-p headline info)
2453 (org-e-html-end-plain-list type)))))
2454 ;; Case 3. Standard headline. Export it as a section.
2456 ;; (format section-fmt full-text
2457 ;; (concat headline-label pre-blanks contents))
2459 (org-e-html-format-outline contents level section-no full-text tags
2460 (car (last headline-labels))
2461 (butlast headline-labels) nil)))))
2464 ;;;; Horizontal Rule
2466 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
2467 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2468 CONTENTS is nil. INFO is a plist holding contextual information."
2469 (let ((attr (mapconcat #'identity
2470 (org-element-get-property :attr_html horizontal-rule)
2471 " ")))
2472 (org-e-html--wrap-label horizontal-rule
2473 (org-e-html-format-horizontal-line))))
2476 ;;;; Inline Babel Call
2478 ;; Inline Babel Calls are ignored.
2481 ;;;; Inline Src Block
2483 (defun org-e-html-inline-src-block (inline-src-block contents info)
2484 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2485 CONTENTS holds the contents of the item. INFO is a plist holding
2486 contextual information."
2487 (let* ((org-lang (org-element-get-property :language inline-src-block))
2488 (code (org-element-get-property :value inline-src-block))
2489 (separator (org-e-html--find-verb-separator code)))
2490 (error "FIXME")))
2493 ;;;; Inlinetask
2495 (defun org-e-html-format-section (text class &optional id)
2496 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2497 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2499 (defun org-e-html-inlinetask (inlinetask contents info)
2500 "Transcode an INLINETASK element from Org to HTML.
2501 CONTENTS holds the contents of the block. INFO is a plist
2502 holding contextual information."
2503 (let ((title (org-export-secondary-string
2504 (org-element-get-property :title inlinetask) 'e-html info))
2505 (todo (and (plist-get info :with-todo-keywords)
2506 (let ((todo (org-element-get-property
2507 :todo-keyword inlinetask)))
2508 (and todo
2509 (org-export-secondary-string todo 'e-html info)))))
2510 (todo-type (org-element-get-property :todo-type inlinetask))
2511 (tags (and (plist-get info :with-tags)
2512 (org-element-get-property :tags inlinetask)))
2513 (priority (and (plist-get info :with-priority)
2514 (org-element-get-property :priority inlinetask))))
2515 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2516 ;; with appropriate arguments.
2517 (if (functionp org-e-html-format-inlinetask-function)
2518 (funcall org-e-html-format-inlinetask-function
2519 todo todo-type priority title tags contents)
2520 ;; Otherwise, use a default template.
2521 (org-e-html--wrap-label
2522 inlinetask
2523 (let ((full-title
2524 (concat
2525 (when todo (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2526 (when priority (format "\\framebox{\\#%c} " priority))
2527 title
2528 (when tags (format "\\hfill{}\\textsc{%s}" tags)))))
2529 (format (concat "\\begin{center}\n"
2530 "\\fbox{\n"
2531 "\\begin{minipage}[c]{.6\\textwidth}\n"
2532 "%s\n\n"
2533 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
2534 "%s"
2535 "\\end{minipage}\n"
2536 "}\n"
2537 "\\end{center}")
2538 full-title contents))))))
2541 ;;;; Item
2543 (defun org-e-html-format-list-item (contents type checkbox
2544 &optional term-counter-id
2545 headline)
2546 (when checkbox
2547 (setq checkbox
2548 (org-e-html-format-fontify (case checkbox
2549 (on "[X]")
2550 (off "[&nbsp;]")
2551 (trans "[-]")) 'code)))
2552 (concat
2553 (case type
2554 (ordered
2555 (let* ((counter term-counter-id)
2556 (extra (if counter (format " value=\"%s\"" counter) "")))
2557 (format "<li%s>" extra)))
2558 (unordered
2559 (let* ((id term-counter-id)
2560 (extra (if id (format " id=\"%s\"" id) "")))
2561 (concat
2562 (format "<li%s>" extra)
2563 (when headline (concat headline "<br/>")))))
2564 (descriptive
2565 (let* ((term term-counter-id))
2566 (setq term (or term "(no term)"))
2567 (concat (format "<dt> %s </dt>" term) "<dd>"))))
2568 checkbox (and checkbox " ") contents
2569 (case type
2570 (ordered "</li>")
2571 (unordered "</li>")
2572 (descriptive "</dd>"))))
2574 (defun org-e-html-item (item contents info)
2575 "Transcode an ITEM element from Org to HTML.
2576 CONTENTS holds the contents of the item. INFO is a plist holding
2577 contextual information."
2578 ;; Grab `:level' from plain-list properties, which is always the
2579 ;; first element above current item.
2580 (let* ((plain-list (car (org-export-get-genealogy item info)))
2581 (type (org-element-get-property :type plain-list))
2582 (level (org-element-get-property
2583 :level (car (plist-get info :genealogy))))
2584 (counter (org-element-get-property :counter item))
2585 (checkbox (org-element-get-property :checkbox item))
2586 (tag (let ((tag (org-element-get-property :tag item)))
2587 (and tag (org-export-secondary-string tag 'e-html info)))))
2588 (org-e-html-format-list-item
2589 contents type checkbox (or tag counter))))
2592 ;;;; Keyword
2594 (defun org-e-html-keyword (keyword contents info)
2595 "Transcode a KEYWORD element from Org to HTML.
2596 CONTENTS is nil. INFO is a plist holding contextual information."
2597 (let ((key (downcase (org-element-get-property :key keyword)))
2598 (value (org-element-get-property :value keyword)))
2599 (cond
2600 ((string= key "latex") value)
2601 ((string= key "index") (format "\\index{%s}" value))
2602 ((string= key "target")
2603 (format "\\label{%s}" (org-export-solidify-link-text value)))
2604 ((string= key "toc")
2605 (let ((value (downcase value)))
2606 (cond
2607 ((string-match "\\<headlines\\>" value)
2608 (let ((depth (or (and (string-match "[0-9]+" value)
2609 (string-to-number (match-string 0 value)))
2610 (plist-get info :with-toc))))
2611 (when (wholenump depth) (org-e-html-toc depth info))))
2612 ((string= "tables" value) "\\listoftables")
2613 ((string= "figures" value) "\\listoffigures")
2614 ((string= "listings" value)
2615 (cond
2616 ;; At the moment, src blocks with a caption are wrapped
2617 ;; into a figure environment.
2618 (t "\\listoffigures")))))))))
2621 ;;;; Latex Environment
2623 (defun org-e-html-format-latex (latex-frag processing-type)
2624 (let* ((cache-relpath
2625 (concat "ltxpng/" (file-name-sans-extension
2626 (file-name-nondirectory (buffer-file-name)))))
2627 (cache-dir (file-name-directory (buffer-file-name )))
2628 (display-msg "Creating LaTeX Image..."))
2630 (with-temp-buffer
2631 (insert latex-frag)
2632 (org-format-latex cache-relpath cache-dir nil display-msg
2633 nil nil processing-type)
2634 (buffer-string))))
2636 (defun org-e-html-latex-environment (latex-environment contents info)
2637 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2638 CONTENTS is nil. INFO is a plist holding contextual information."
2639 (org-e-html--wrap-label
2640 latex-environment
2641 (let ((latex-frag
2642 (org-remove-indentation
2643 (org-element-get-property :value latex-environment)))
2644 (processing-type (plist-get info :LaTeX-fragments)))
2645 (cond
2646 ((member processing-type '(t mathjax))
2647 (org-e-html-format-latex latex-frag 'mathjax))
2648 ((equal processing-type 'dvipng)
2649 (let* ((formula-link (org-e-html-format-latex
2650 latex-frag processing-type)))
2651 (when (and formula-link
2652 (string-match "file:\\([^]]*\\)" formula-link))
2653 (org-e-html-format-inline-image (match-string 1 formula-link)))))
2655 latex-frag)))))
2658 ;;;; Latex Fragment
2660 (defun org-e-html-latex-fragment (latex-fragment contents info)
2661 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2662 CONTENTS is nil. INFO is a plist holding contextual information."
2663 ;; (org-element-get-property :value latex-fragment)
2664 (let* ((latex-frag (org-element-get-property :value latex-fragment)))
2665 (cond
2666 ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag)
2667 (let* ((label (match-string 1 latex-frag))
2668 (href (and label (org-export-solidify-link-text label)))
2669 (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
2670 (substring label (match-beginning 1))
2671 label)))
2672 (org-e-html-format-internal-link text href)))
2673 (t (let ((processing-type (plist-get info :LaTeX-fragments)))
2674 (cond
2675 ((member processing-type '(t mathjax))
2676 (org-e-html-format-latex latex-frag 'mathjax))
2677 ((equal processing-type 'dvipng)
2678 (let* ((formula-link (org-e-html-format-latex
2679 latex-frag processing-type)))
2680 (when (and formula-link
2681 (string-match "file:\\([^]]*\\)" formula-link))
2682 (org-e-html-format-inline-image
2683 (match-string 1 formula-link)))))
2684 (t latex-frag)))))))
2687 ;;;; Line Break
2689 (defun org-e-html-line-break (line-break contents info)
2690 "Transcode a LINE-BREAK object from Org to HTML.
2691 CONTENTS is nil. INFO is a plist holding contextual information."
2692 "<br/>")
2695 ;;;; Link
2697 (defun org-e-html-link--inline-image (link info)
2698 "Return HTML code for an inline image.
2699 LINK is the link pointing to the inline image. INFO is a plist
2700 used as a communication channel."
2701 (let* ((parent (org-export-get-parent-paragraph link info))
2702 (path (let ((raw-path (org-element-get-property :path link)))
2703 (if (not (file-name-absolute-p raw-path)) raw-path
2704 (expand-file-name raw-path))))
2705 (caption (org-e-html--caption/label-string
2706 (org-element-get-property :caption parent)
2707 (org-element-get-property :name parent)
2708 info))
2709 (label (org-element-get-property :name parent))
2710 ;; Retrieve latex attributes from the element around.
2711 (attr (let ((raw-attr
2712 (mapconcat #'identity
2713 (org-element-get-property :attr_html parent)
2714 " ")))
2715 (unless (string= raw-attr "") raw-attr))))
2716 ;; Now clear ATTR from any special keyword and set a default
2717 ;; value if nothing is left.
2718 (setq attr (if (not attr) "" (org-trim attr)))
2719 ;; Return proper string, depending on DISPOSITION.
2720 (let ((href (and label (org-export-solidify-link-text label))))
2721 (org-e-html-format-inline-image path caption href attr))))
2723 (defun org-e-html-link (link desc info)
2724 "Transcode a LINK object from Org to HTML.
2726 DESC is the description part of the link, or the empty string.
2727 INFO is a plist holding contextual information. See
2728 `org-export-data'."
2729 (let* ((type (org-element-get-property :type link))
2730 (raw-path (org-element-get-property :path link))
2731 ;; Ensure DESC really exists, or set it to nil.
2732 (desc (and (not (string= desc "")) desc))
2733 (imagep (org-export-inline-image-p
2734 link org-e-html-inline-image-rules))
2735 (path (cond
2736 ((member type '("http" "https" "ftp" "mailto"))
2737 (concat type ":" raw-path))
2738 ((string= type "file")
2739 (when (string-match "\\(.+\\)::.+" raw-path)
2740 (setq raw-path (match-string 1 raw-path)))
2741 (if (file-name-absolute-p raw-path)
2742 (concat "file://" (expand-file-name raw-path))
2743 ;; TODO: Not implemented yet. Concat also:
2744 ;; (org-export-directory :HTML info)
2745 (concat "file://" raw-path)))
2746 (t raw-path)))
2747 protocol)
2748 (cond
2749 ;; Image file.
2750 (imagep (org-e-html-link--inline-image link info))
2751 ;; Target or radioed target: replace link with the normalized
2752 ;; custom-id/target name.
2753 ((member type '("target" "radio"))
2754 (org-e-html-format-internal-link
2755 (or desc (org-export-secondary-string path 'e-html info))
2756 (org-export-solidify-link-text path)))
2757 ;; Links pointing to an headline: Find destination and build
2758 ;; appropriate referencing commanding.
2759 ((member type '("custom-id" "fuzzy" "id"))
2760 (let ((destination (if (string= type "fuzzy")
2761 (org-export-resolve-fuzzy-link link info)
2762 (org-export-resolve-id-link link info))))
2763 ;; Fuzzy link points to a target. Do as above.
2764 (case (car destination)
2765 (target
2766 (org-e-html-format-internal-link
2767 (or desc
2768 (org-export-secondary-string
2769 (org-element-get-property :raw-link link)
2770 'e-html info))
2771 (org-export-solidify-link-text
2772 (org-element-get-property :raw-value destination))))
2773 ;; Fuzzy link points to an headline. If headlines are
2774 ;; numbered and the link has no description, display
2775 ;; headline's number. Otherwise, display description or
2776 ;; headline's title.
2777 (headline
2778 (let ((label
2779 (format "sec-%s"
2780 (mapconcat
2781 'number-to-string
2782 (org-export-get-headline-number destination info)
2783 "-"))))
2784 (if (and (plist-get info :section-numbers) (not desc))
2785 (format "\\ref{%s}" label)
2786 (org-e-html-format-internal-link
2787 (or desc
2788 (org-export-secondary-string
2789 (org-element-get-property :title destination)
2790 'e-html info)) label))))
2791 ;; Fuzzy link points nowhere.
2792 (otherwise
2793 (org-e-html-format-fontify
2794 (or desc
2795 (org-export-secondary-string
2796 (org-element-get-property :raw-link link)
2797 'e-html info)) 'emphasis)))))
2798 ;; Coderef: replace link with the reference name or the
2799 ;; equivalent line number.
2800 ((string= type "coderef")
2801 (format (org-export-get-coderef-format path (or desc ""))
2802 (org-export-resolve-coderef path info)))
2803 ;; Link type is handled by a special function.
2804 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2805 (funcall protocol (org-link-unescape path) desc 'html))
2806 ;; External link with a description part.
2807 ((and path desc) (org-e-html-format-link desc path))
2808 ;; External link without a description part.
2809 (path (org-e-html-format-link path path))
2810 ;; No path, only description. Try to do something useful.
2811 (t (org-e-html-format-fontify desc 'emphasis)))))
2814 ;;;; Babel Call
2816 ;; Babel Calls are ignored.
2819 ;;;; Macro
2821 (defun org-e-html-macro (macro contents info)
2822 "Transcode a MACRO element from Org to HTML.
2823 CONTENTS is nil. INFO is a plist holding contextual information."
2824 ;; Use available tools.
2825 (org-export-expand-macro macro info))
2828 ;;;; Paragraph
2830 (defun org-e-html-paragraph (paragraph contents info)
2831 "Transcode a PARAGRAPH element from Org to HTML.
2832 CONTENTS is the contents of the paragraph, as a string. INFO is
2833 the plist used as a communication channel."
2834 (let* ((style nil) ; FIXME
2835 (class (cdr (assoc style '((footnote . "footnote")
2836 (verse . nil)))))
2837 (extra (if class (format " class=\"%s\"" class) ""))
2838 (parent (car (org-export-get-genealogy paragraph info))))
2839 (cond
2840 ((and (equal (car parent) 'item)
2841 (= (org-element-get-property :begin paragraph)
2842 (org-element-get-property :contents-begin parent)))
2843 ;; leading paragraph in a list item have no tags
2844 contents)
2845 (t (concat (format "<p%s> " extra) contents "</p>")))))
2848 ;;;; Plain List
2850 (defun org-e-html-begin-plain-list (type &optional arg1)
2851 (case type
2852 (ordered
2853 (format "<ol%s>" (if arg1 ; FIXME
2854 (format " start=\"%d\"" arg1)
2855 "")))
2856 (unordered "<ul>")
2857 (descriptive "<dl>")))
2859 (defun org-e-html-end-plain-list (type)
2860 (case type
2861 (ordered "</ol>")
2862 (unordered "</ul>")
2863 (descriptive "</dl>")))
2865 (defun org-e-html-plain-list (plain-list contents info)
2866 "Transcode a PLAIN-LIST element from Org to HTML.
2867 CONTENTS is the contents of the list. INFO is a plist holding
2868 contextual information."
2869 (let* (arg1 ;; FIXME
2870 (type (org-element-get-property :type plain-list))
2871 (attr (mapconcat #'identity
2872 (org-element-get-property :attr_html plain-list)
2873 " ")))
2874 (org-e-html--wrap-label
2875 plain-list (format "%s\n%s%s"
2876 (org-e-html-begin-plain-list type)
2877 contents (org-e-html-end-plain-list type)))))
2879 ;;;; Plain Text
2881 (defun org-e-html-convert-special-strings (string)
2882 "Convert special characters in STRING to HTML."
2883 (let ((all org-e-html-special-string-regexps)
2884 e a re rpl start)
2885 (while (setq a (pop all))
2886 (setq re (car a) rpl (cdr a) start 0)
2887 (while (string-match re string start)
2888 (setq string (replace-match rpl t nil string))))
2889 string))
2891 (defun org-e-html-encode-plain-text (s)
2892 "Convert plain text characters to HTML equivalent.
2893 Possible conversions are set in `org-export-html-protect-char-alist'."
2894 (let ((cl org-e-html-protect-char-alist) c)
2895 (while (setq c (pop cl))
2896 (let ((start 0))
2897 (while (string-match (car c) s start)
2898 (setq s (replace-match (cdr c) t t s)
2899 start (1+ (match-beginning 0))))))
2902 (defun org-e-html-plain-text (text info)
2903 "Transcode a TEXT string from Org to HTML.
2904 TEXT is the string to transcode. INFO is a plist holding
2905 contextual information."
2906 (setq text (org-e-html-encode-plain-text text))
2907 ;; Protect %, #, &, $, ~, ^, _, { and }.
2908 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2909 ;; (setq text
2910 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2911 ;; Protect \
2912 ;; (setq text (replace-regexp-in-string
2913 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2914 ;; "$\\backslash$" text nil t 1))
2915 ;; HTML into \HTML{} and TeX into \TeX{}.
2916 ;; (let ((case-fold-search nil)
2917 ;; (start 0))
2918 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2919 ;; (setq text (replace-match
2920 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2921 ;; start (match-end 0))))
2922 ;; Handle quotation marks
2923 ;; (setq text (org-e-html--quotation-marks text info))
2924 ;; Convert special strings.
2925 ;; (when (plist-get info :with-special-strings)
2926 ;; (while (string-match (regexp-quote "...") text)
2927 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2928 (when (plist-get info :with-special-strings)
2929 (setq text (org-e-html-convert-special-strings text)))
2930 ;; Handle break preservation if required.
2931 (when (plist-get info :preserve-breaks)
2932 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2933 text)))
2934 ;; Return value.
2935 text)
2938 ;;;; Property Drawer
2940 (defun org-e-html-property-drawer (property-drawer contents info)
2941 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2942 CONTENTS is nil. INFO is a plist holding contextual
2943 information."
2944 ;; The property drawer isn't exported but we want separating blank
2945 ;; lines nonetheless.
2949 ;;;; Quote Block
2951 (defun org-e-html-quote-block (quote-block contents info)
2952 "Transcode a QUOTE-BLOCK element from Org to HTML.
2953 CONTENTS holds the contents of the block. INFO is a plist
2954 holding contextual information."
2955 (org-e-html--wrap-label
2956 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2959 ;;;; Quote Section
2961 (defun org-e-html-quote-section (quote-section contents info)
2962 "Transcode a QUOTE-SECTION element from Org to HTML.
2963 CONTENTS is nil. INFO is a plist holding contextual information."
2964 (let ((value (org-remove-indentation
2965 (org-element-get-property :value quote-section))))
2966 (when value (format "<pre>\n%s</pre>" value))))
2969 ;;;; Section
2971 (defun org-e-html-section (section contents info)
2972 "Transcode a SECTION element from Org to HTML.
2973 CONTENTS holds the contents of the section. INFO is a plist
2974 holding contextual information."
2975 contents)
2978 ;;;; Radio Target
2980 (defun org-e-html-radio-target (radio-target text info)
2981 "Transcode a RADIO-TARGET object from Org to HTML.
2982 TEXT is the text of the target. INFO is a plist holding
2983 contextual information."
2984 (org-e-html-format-anchor
2985 text (org-export-solidify-link-text
2986 (org-element-get-property :raw-value radio-target))))
2989 ;;;; Special Block
2991 (defun org-e-html-special-block (special-block contents info)
2992 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2993 CONTENTS holds the contents of the block. INFO is a plist
2994 holding contextual information."
2995 (let ((type (downcase (org-element-get-property :type special-block))))
2996 (org-e-html--wrap-label
2997 special-block
2998 (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
3001 ;;;; Src Block
3003 (defun org-e-html-src-block (src-block contents info)
3004 "Transcode a SRC-BLOCK element from Org to HTML.
3005 CONTENTS holds the contents of the item. INFO is a plist holding
3006 contextual information."
3007 (let* ((lang (org-element-get-property :language src-block))
3008 (code (org-export-handle-code src-block info))
3009 (caption (org-element-get-property :caption src-block))
3010 (label (org-element-get-property :name src-block)))
3011 ;; FIXME: Handle caption
3013 ;; caption-str (when caption)
3014 ;; (main (org-export-secondary-string (car caption) 'e-html info))
3015 ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
3016 ;; (caption-str (org-e-html--caption/label-string caption label info))
3017 (org-e-html-format-source-code-or-example lang code)))
3020 ;;;; Statistics Cookie
3022 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
3023 "Transcode a STATISTICS-COOKIE object from Org to HTML.
3024 CONTENTS is nil. INFO is a plist holding contextual information."
3025 (let ((cookie-value (org-element-get-property :value statistics-cookie)))
3026 (org-e-html-format-fontify cookie-value 'code)))
3029 ;;;; Subscript
3031 (defun org-e-html-subscript (subscript contents info)
3032 "Transcode a SUBSCRIPT object from Org to HTML.
3033 CONTENTS is the contents of the object. INFO is a plist holding
3034 contextual information."
3035 ;; (format (if (= (length contents) 1) "$_%s$" "$_{\\mathrm{%s}}$") contents)
3036 (org-e-html-format-fontify contents 'subscript))
3039 ;;;; Superscript
3041 (defun org-e-html-superscript (superscript contents info)
3042 "Transcode a SUPERSCRIPT object from Org to HTML.
3043 CONTENTS is the contents of the object. INFO is a plist holding
3044 contextual information."
3045 ;; (format (if (= (length contents) 1) "$^%s$" "$^{\\mathrm{%s}}$") contents)
3046 (org-e-html-format-fontify contents 'superscript))
3049 ;;;; Table
3051 (defun org-e-html-begin-table (caption label attributes)
3052 (let* ((html-table-tag (or (plist-get info :html-table-tag) ; FIXME
3053 org-e-html-table-tag))
3054 (html-table-tag
3055 (org-e-html-splice-attributes html-table-tag attributes)))
3056 (when label
3057 (setq html-table-tag
3058 (org-e-html-splice-attributes
3059 html-table-tag
3060 (format "id=\"%s\"" (org-solidify-link-text label)))))
3061 (concat "\n" html-table-tag
3062 (format "\n<caption>%s</caption>" (or caption "")))))
3064 (defun org-e-html-end-table ()
3065 "</table>\n")
3067 (defun org-e-html-format-table-cell (text r c horiz-span)
3068 (let ((cell-style-cookie
3069 (if org-e-html-table-align-individual-fields
3070 (format (if (and (boundp 'org-e-html-format-table-no-css)
3071 org-e-html-format-table-no-css)
3072 " align=\"%s\"" " class=\"%s\"")
3073 (or (aref (plist-get table-info :alignment) c) "left")) ""))) ;; FIXME
3074 (cond
3075 (org-e-html-table-cur-rowgrp-is-hdr
3076 (concat
3077 (format (car org-export-table-header-tags) "col" cell-style-cookie)
3078 text (cdr org-export-table-header-tags)))
3079 ((and (= c 0) org-e-html-table-use-header-tags-for-first-column)
3080 (concat
3081 (format (car org-export-table-header-tags) "row" cell-style-cookie)
3082 text (cdr org-export-table-header-tags)))
3084 (concat
3085 (format (car org-export-table-data-tags) cell-style-cookie)
3086 text (cdr org-export-table-data-tags))))))
3088 (defun org-e-html-format-table-row (row)
3089 (concat (eval (car org-export-table-row-tags)) row
3090 (eval (cdr org-export-table-row-tags))))
3092 (defun org-e-html-table-row (fields &optional text-for-empty-fields)
3093 (incf org-e-html-table-rownum)
3094 (let ((i -1))
3095 (org-e-html-format-table-row
3096 (mapconcat
3097 (lambda (x)
3098 (when (and (string= x "") text-for-empty-fields)
3099 (setq x text-for-empty-fields))
3100 (incf i)
3101 (let (horiz-span)
3102 (org-e-html-format-table-cell
3103 x org-e-html-table-rownum i (or horiz-span 0))))
3104 fields "\n"))))
3106 (defun org-e-html-end-table-rowgroup ()
3107 (when org-e-html-table-rowgrp-open
3108 (setq org-e-html-table-rowgrp-open nil)
3109 (if org-e-html-table-cur-rowgrp-is-hdr "</thead>" "</tbody>")))
3111 (defun org-e-html-begin-table-rowgroup (&optional is-header-row)
3112 (concat
3113 (when org-e-html-table-rowgrp-open
3114 (org-e-html-end-table-rowgroup))
3115 (progn
3116 (setq org-e-html-table-rowgrp-open t)
3117 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row)
3118 (if is-header-row "<thead>" "<tbody>"))))
3120 (defun org-e-html-table-preamble ()
3121 (let ((colgroup-vector (plist-get table-info :column-groups)) ;; FIXME
3122 c gr colgropen preamble)
3123 (unless (aref colgroup-vector 0)
3124 (setf (aref colgroup-vector 0) 'start))
3125 (dotimes (c columns-number preamble)
3126 (setq gr (aref colgroup-vector c))
3127 (setq preamble
3128 (concat
3129 preamble
3130 (when (memq gr '(start start-end))
3131 (prog1 (if colgropen "</colgroup>\n<colgroup>" "\n<colgroup>")
3132 (setq colgropen t)))
3133 (let* ((colalign-vector (plist-get table-info :alignment)) ;; FIXME
3134 (align (cdr (assoc (aref colalign-vector c)
3135 '(("l" . "left")
3136 ("r" . "right")
3137 ("c" . "center")))))
3138 (alignspec (if (and (boundp 'org-e-html-format-table-no-css)
3139 org-e-html-format-table-no-css)
3140 " align=\"%s\"" " class=\"%s\""))
3141 (extra (format alignspec align)))
3142 (format "<col%s />" extra))
3143 (when (memq gr '(end start-end))
3144 (setq colgropen nil)
3145 "</colgroup>"))))
3146 (concat preamble (if colgropen "</colgroup>"))))
3148 (defun org-e-html-list-table (lines &optional splice
3149 caption label attributes head)
3150 (or (featurep 'org-table) ; required for
3151 (require 'org-table)) ; `org-table-number-regexp'
3152 (let* ((org-e-html-table-rownum -1)
3153 i (cnt 0)
3154 fields line
3155 org-e-html-table-cur-rowgrp-is-hdr
3156 org-e-html-table-rowgrp-open
3158 (org-lparse-table-style 'org-table)
3159 org-lparse-table-is-styled)
3160 (cond
3161 (splice
3162 (setq org-lparse-table-is-styled nil)
3163 (mapconcat 'org-e-html-table-row lines "\n"))
3165 (setq org-lparse-table-is-styled t)
3167 (concat
3168 (org-e-html-begin-table caption label attributes)
3169 (org-e-html-table-preamble)
3170 (org-e-html-begin-table-rowgroup head)
3172 (mapconcat
3173 (lambda (line)
3174 (cond
3175 ((equal line :hrule) (org-e-html-begin-table-rowgroup))
3176 (t (org-e-html-table-row line))))
3177 lines "\n")
3179 (org-e-html-end-table-rowgroup)
3180 (org-e-html-end-table))))))
3182 (defun org-e-html-org-table-to-list-table (lines &optional splice)
3183 "Convert org-table to list-table.
3184 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
3185 element is a `string' representing a single row of org-table.
3186 Thus each ROW has vertical separators \"|\" separating the table
3187 fields. A ROW could also be a row-group separator of the form
3188 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
3189 ...). ROW could either be symbol `:hrule' or a list of the
3190 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
3191 (let (line lines-1)
3192 (cond
3193 (splice
3194 (while (setq line (pop lines))
3195 (unless (string-match "^[ \t]*|-" line)
3196 (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))
3198 (while (setq line (pop lines))
3199 (cond
3200 ((string-match "^[ \t]*|-" line)
3201 (when lines
3202 (push :hrule lines-1)))
3204 (push (org-split-string line "[ \t]*|[ \t]*") lines-1))))))
3205 (nreverse lines-1)))
3207 (defun org-e-html-table (table contents info)
3208 "Transcode a TABLE element from Org to HTML.
3209 CONTENTS is nil. INFO is a plist holding contextual information."
3210 (let* ((label (org-element-get-property :name table))
3211 (caption (org-e-html--caption/label-string
3212 (org-element-get-property :caption table) label info))
3214 ;; FIXME
3215 ;; org-e-html-table-caption-above
3216 ;; (string= "" caption) (org-trim caption)
3218 (attr (mapconcat #'identity
3219 (org-element-get-property :attr_html table)
3220 " "))
3221 (raw-table (org-element-get-property :raw-table table)))
3222 (cond
3223 ;; Case 1: verbatim table.
3224 ((or org-e-html-tables-verbatim
3225 (and attr (string-match "\\<verbatim\\>" attr)))
3226 (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
3227 (org-export-clean-table
3228 raw-table
3229 (plist-get (org-export-table-format-info raw-table)
3230 :special-column-p))))
3231 ;; Case 2: table.el table. Convert it using appropriate tools.
3232 ((eq (org-element-get-property :type table) 'table.el)
3233 (require 'table)
3234 ;; Ensure "*org-export-table*" buffer is empty.
3235 (with-current-buffer (get-buffer-create "*org-export-table*")
3236 (erase-buffer))
3237 (let ((output (with-temp-buffer
3238 (insert raw-table)
3239 (goto-char 1)
3240 (re-search-forward "^[ \t]*|[^|]" nil t)
3241 (table-generate-source 'html "*org-export-table*")
3242 (with-current-buffer "*org-export-table*"
3243 (org-trim (buffer-string))))))
3244 (kill-buffer (get-buffer "*org-export-table*"))
3245 output))
3246 ;; Case 3: Standard table.
3248 (let* ((table-info (org-export-table-format-info raw-table))
3249 ;; (alignment (org-e-html-table--align-string attr table-info))
3250 (columns-number (length (plist-get table-info :alignment)))
3251 ;; CLEAN-TABLE is a table turned into a list, much like
3252 ;; `org-table-to-lisp', with special column and
3253 ;; formatting cookies removed, and cells already
3254 ;; transcoded.
3255 (lines (org-split-string
3256 (org-export-clean-table
3257 raw-table (plist-get table-info :special-column-p)) "\n"))
3258 clean-table)
3260 ;; (setq clean-table
3261 ;; (mapcar
3262 ;; (lambda (row)
3263 ;; (if (string-match org-table-hline-regexp row) 'hline
3264 ;; (mapcar
3265 ;; (lambda (cell)
3266 ;; (org-export-secondary-string
3267 ;; (org-element-parse-secondary-string
3268 ;; cell
3269 ;; (cdr (assq 'table org-element-string-restrictions)))
3270 ;; 'e-html info))
3271 ;; (org-split-string row "[ \t]*|[ \t]*"))))
3272 ;; lines))
3274 ;; Convert ROWS to send them to `orgtbl-to-latex'. In
3275 ;; particular, send each cell to
3276 ;; `org-element-parse-secondary-string' to expand any Org
3277 ;; object within. Eventually, flesh the format string out
3278 ;; with the table.
3279 ;; (format
3280 ;; (org-e-html-table--format-string table table-info info)
3281 ;; (orgtbl-to-latex clean-table params))
3283 (let ((splice nil) head)
3284 (setq lines (org-e-html-org-table-to-list-table lines splice))
3285 (org-e-html-list-table lines splice caption label attr head)))))))
3288 ;;;; Target
3290 (defun org-e-html-target (target text info)
3291 "Transcode a TARGET object from Org to HTML.
3292 TEXT is the text of the target. INFO is a plist holding
3293 contextual information."
3294 (org-e-html-format-anchor
3295 text (org-export-solidify-link-text
3296 (org-element-get-property :raw-value target))))
3299 ;;;; Time-stamp
3301 (defun org-e-html-time-stamp (time-stamp contents info)
3302 "Transcode a TIME-STAMP object from Org to HTML.
3303 CONTENTS is nil. INFO is a plist holding contextual
3304 information."
3305 ;; (let ((value (org-element-get-property :value time-stamp))
3306 ;; (type (org-element-get-property :type time-stamp))
3307 ;; (appt-type (org-element-get-property :appt-type time-stamp)))
3308 ;; (concat (cond ((eq appt-type 'scheduled)
3309 ;; (format "\\textbf{\\textsc{%s}} " org-scheduled-string))
3310 ;; ((eq appt-type 'deadline)
3311 ;; (format "\\textbf{\\textsc{%s}} " org-deadline-string))
3312 ;; ((eq appt-type 'closed)
3313 ;; (format "\\textbf{\\textsc{%s}} " org-closed-string)))
3314 ;; (cond ((memq type '(active active-range))
3315 ;; (format org-e-html-active-timestamp-format value))
3316 ;; ((memq type '(inactive inactive-range))
3317 ;; (format org-e-html-inactive-timestamp-format value))
3318 ;; (t
3319 ;; (format org-e-html-diary-timestamp-format value)))))
3320 (let ((value (org-element-get-property :value time-stamp))
3321 (type (org-element-get-property :type time-stamp))
3322 (appt-type (org-element-get-property :appt-type time-stamp)))
3323 (setq value (org-export-secondary-string value 'e-html info))
3324 (org-e-html-format-fontify
3325 (concat
3326 (org-e-html-format-fontify
3327 (cond ((eq appt-type 'scheduled) org-scheduled-string)
3328 ((eq appt-type 'deadline) org-deadline-string)
3329 ((eq appt-type 'closed) org-closed-string)) "timestamp-kwd")
3330 ;; FIXME: (org-translate-time value)
3331 (org-e-html-format-fontify value "timestamp"))
3332 "timestamp-wrapper")))
3335 ;;;; Verbatim
3337 (defun org-e-html-verbatim (verbatim contents info)
3338 "Transcode a VERBATIM object from Org to HTML.
3339 CONTENTS is nil. INFO is a plist used as a communication
3340 channel."
3341 (org-e-html-emphasis
3342 verbatim (org-element-get-property :value verbatim) info))
3345 ;;;; Verse Block
3347 (defun org-e-html-verse-block (verse-block contents info)
3348 "Transcode a VERSE-BLOCK element from Org to HTML.
3349 CONTENTS is nil. INFO is a plist holding contextual information."
3350 ;; Replace each newline character with line break. Also replace
3351 ;; each blank line with a line break.
3352 (setq contents (replace-regexp-in-string
3353 "^ *\\\\\\\\$" "<br/>\n"
3354 (replace-regexp-in-string
3355 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3356 (org-remove-indentation
3357 (org-export-secondary-string
3358 (org-element-get-property :value verse-block)
3359 'e-html info)))))
3361 ;; Replace each white space at beginning of a line with a
3362 ;; non-breaking space.
3363 (while (string-match "^[ \t]+" contents)
3364 (let ((new-str (org-e-html-format-spaces
3365 (length (match-string 0 contents)))))
3366 (setq contents (replace-match new-str nil t contents))))
3368 (org-e-html--wrap-label
3369 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
3373 ;;; Interactive functions
3375 (defun org-e-html-export-to-html
3376 (&optional subtreep visible-only body-only ext-plist pub-dir)
3377 "Export current buffer to a HTML file.
3379 If narrowing is active in the current buffer, only export its
3380 narrowed part.
3382 If a region is active, export that region.
3384 When optional argument SUBTREEP is non-nil, export the sub-tree
3385 at point, extracting information from the headline properties
3386 first.
3388 When optional argument VISIBLE-ONLY is non-nil, don't export
3389 contents of hidden elements.
3391 When optional argument BODY-ONLY is non-nil, only write code
3392 between \"\\begin{document}\" and \"\\end{document}\".
3394 EXT-PLIST, when provided, is a property list with external
3395 parameters overriding Org default settings, but still inferior to
3396 file-local settings.
3398 When optional argument PUB-DIR is set, use it as the publishing
3399 directory.
3401 Return output file's name."
3402 (interactive)
3404 ;; FIXME
3405 (with-current-buffer (get-buffer-create "*debug*")
3406 (erase-buffer))
3408 (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir)))
3409 (org-export-to-file
3410 'e-html outfile subtreep visible-only body-only ext-plist)))
3414 ;;; FIXMES, TODOS, FOR REVIEW etc
3416 ;;;; org-format-table-html
3417 ;;;; org-format-org-table-html
3418 ;;;; org-format-table-table-html
3419 ;;;; org-table-number-fraction
3421 ;;;; org-whitespace
3422 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3423 ;;;; Remove display properties
3424 ;;;; org-e-html-final-hook
3426 ;;;; org-e-html-with-timestamp
3427 ;;;; org-e-html-html-helper-timestamp
3429 ;;;; org-export-as-html-and-open
3430 ;;;; org-export-as-html-batch
3431 ;;;; org-export-as-html-to-buffer
3432 ;;;; org-replace-region-by-html
3433 ;;;; org-export-region-as-html
3434 ;;;; org-export-as-html
3436 ;;;; (org-export-directory :html opt-plist)
3437 ;;;; (plist-get opt-plist :html-extension)
3438 ;;;; org-e-html-toplevel-hlevel
3439 ;;;; org-e-html-special-string-regexps
3440 ;;;; org-e-html-coding-system
3441 ;;;; org-e-html-coding-system
3442 ;;;; org-e-html-inline-images
3443 ;;;; org-e-html-inline-image-extensions
3444 ;;;; org-e-html-protect-char-alist
3445 ;;;; org-e-html-table-use-header-tags-for-first-column
3446 ;;;; org-e-html-todo-kwd-class-prefix
3447 ;;;; org-e-html-tag-class-prefix
3448 ;;;; org-e-html-footnote-separator
3450 (provide 'org-e-html)
3451 ;;; org-e-html.el ends here