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