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