org-export: Secondary strings are transcoded with `org-export-data'
[org-mode/org-mode-NeilSmithlineMods.git] / contrib / lisp / org-e-html.el
blob88b35410141b450f98c8cca0a2fec11c0c2d7c20
1 ;;; org-e-html.el --- HTML Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ;;; Commentary:
23 ;; This library implements a HTML back-end for Org generic exporter.
25 ;; To test it, run
27 ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
29 ;; in an org-mode buffer then switch to the buffer to see the HTML
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
33 ;;; Code:
35 ;;; org-e-html.el
36 ;;; Dependencies
38 (require 'format-spec)
39 (eval-when-compile (require 'cl) (require 'table))
43 ;;; Function Declarations
45 (declare-function org-element-get-property "org-element" (property element))
46 (declare-function org-element-normalize-string "org-element" (s))
47 (declare-function org-element-parse-secondary-string
48 "org-element" (string restriction &optional buffer))
49 (defvar org-element-string-restrictions)
50 (defvar org-element-object-restrictions)
52 (declare-function org-export-data "org-export" (data info))
53 (declare-function org-export-directory "org-export" (type plist))
54 (declare-function org-export-expand-macro "org-export" (macro info))
55 (declare-function org-export-first-sibling-p "org-export" (headline info))
56 (declare-function org-export-footnote-first-reference-p "org-export"
57 (footnote-reference info))
58 (declare-function org-export-get-coderef-format "org-export" (path desc))
59 (declare-function org-export-get-footnote-definition "org-export"
60 (footnote-reference info))
61 (declare-function org-export-get-footnote-number "org-export" (footnote info))
62 (declare-function org-export-get-previous-element "org-export" (blob info))
63 (declare-function org-export-get-relative-level "org-export" (headline info))
64 (declare-function org-export-handle-code
65 "org-export" (element info &optional num-fmt ref-fmt delayed))
66 (declare-function org-export-inline-image-p "org-export"
67 (link &optional extensions))
68 (declare-function org-export-last-sibling-p "org-export" (headline info))
69 (declare-function org-export-low-level-p "org-export" (headline info))
70 (declare-function org-export-output-file-name
71 "org-export" (extension &optional subtreep pub-dir))
72 (declare-function org-export-resolve-coderef "org-export" (ref info))
73 (declare-function org-export-resolve-fuzzy-link "org-export" (link info))
74 (declare-function org-export-solidify-link-text "org-export" (s))
75 (declare-function
76 org-export-to-buffer "org-export"
77 (backend buffer &optional subtreep visible-only body-only ext-plist))
78 (declare-function
79 org-export-to-file "org-export"
80 (backend file &optional subtreep visible-only body-only ext-plist))
82 (declare-function org-id-find-id-file "org-id" (id))
83 (declare-function htmlize-region "ext:htmlize" (beg end))
84 (declare-function org-pop-to-buffer-same-window
85 "org-compat" (&optional buffer-or-name norecord label))
90 ;;; Internal Variables
92 (defconst org-e-html-option-alist
93 '((:agenda-style nil nil org-agenda-export-html-style)
94 (:convert-org-links nil nil org-e-html-link-org-files-as-html)
95 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
96 ;; (:expand-quoted-html nil "@" org-e-html-expand)
97 (:inline-images nil nil org-e-html-inline-images)
98 ;; (:link-home nil nil org-e-html-link-home) FIXME
99 ;; (:link-up nil nil org-e-html-link-up) FIXME
100 (:style nil nil org-e-html-style)
101 (:style-extra nil nil org-e-html-style-extra)
102 (:style-include-default nil nil org-e-html-style-include-default)
103 (:style-include-scripts nil nil org-e-html-style-include-scripts)
104 ;; (:timestamp nil nil org-e-html-with-timestamp)
105 (:html-extension nil nil org-e-html-extension)
106 (:html-postamble nil nil org-e-html-postamble)
107 (:html-preamble nil nil org-e-html-preamble)
108 (:html-table-tag nil nil org-e-html-table-tag)
109 (:xml-declaration nil nil org-e-html-xml-declaration)
110 (:LaTeX-fragments nil "LaTeX" org-export-with-LaTeX-fragments)
111 (:mathjax "MATHJAX" nil "" space))
112 "Alist between export properties and ways to set them.
114 The car of the alist is the property name, and the cdr is a list
115 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
117 KEYWORD is a string representing a buffer keyword, or nil.
118 OPTION is a string that could be found in an #+OPTIONS: line.
119 DEFAULT is the default value for the property.
120 BEHAVIOUR determine how Org should handle multiple keywords for
121 the same property. It is a symbol among:
122 nil Keep old value and discard the new one.
123 t Replace old value with the new one.
124 `space' Concatenate the values, separating them with a space.
125 `newline' Concatenate the values, separating them with
126 a newline.
127 `split' Split values at white spaces, and cons them to the
128 previous list.
130 KEYWORD and OPTION have precedence over DEFAULT.
132 All these properties should be back-end agnostic. For back-end
133 specific properties, define a similar variable named
134 `org-BACKEND-option-alist', replacing BACKEND with the name of
135 the appropriate back-end. You can also redefine properties
136 there, as they have precedence over these.")
138 ;; FIXME: it already exists in org-e-html.el
139 (defconst org-e-html-cvt-link-fn
141 "Function to convert link URLs to exportable URLs.
142 Takes two arguments, TYPE and PATH.
143 Returns exportable url as (TYPE PATH), or nil to signal that it
144 didn't handle this case.
145 Intended to be locally bound around a call to `org-export-as-html'." )
150 (defvar org-e-html-format-table-no-css)
151 (defvar htmlize-buffer-places) ; from htmlize.el
152 (defvar body-only) ; dynamically scoped into this.
156 ;;; User Configuration Variables
158 (defgroup org-export-e-html nil
159 "Options for exporting Org mode files to HTML."
160 :tag "Org Export HTML"
161 :group 'org-export)
163 ;;;; Debugging
165 (defcustom org-e-html-pretty-output nil
166 "Enable this to generate pretty HTML."
167 :group 'org-export-e-html
168 :type 'boolean)
171 ;;;; Document
173 (defcustom org-e-html-extension "html"
174 "The extension for exported HTML files."
175 :group 'org-export-e-html
176 :type 'string)
178 (defcustom org-e-html-xml-declaration
179 '(("html" . "<?xml version=\"1.0\" encoding=\"%s\"?>")
180 ("php" . "<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
181 "The extension for exported HTML files.
182 %s will be replaced with the charset of the exported file.
183 This may be a string, or an alist with export extensions
184 and corresponding declarations."
185 :group 'org-export-e-html
186 :type '(choice
187 (string :tag "Single declaration")
188 (repeat :tag "Dependent on extension"
189 (cons (string :tag "Extension")
190 (string :tag "Declaration")))))
192 ;; Use `org-export-coding-system' instead
193 ;; (defcustom org-e-html-coding-system nil
194 ;; "Coding system for HTML export, defaults to `buffer-file-coding-system'."
195 ;; :group 'org-export-e-html
196 ;; :type 'coding-system)
198 (defvar org-e-html-content-div "content"
199 "The name of the container DIV that holds all the page contents.
201 This variable is obsolete since Org version 7.7.
202 Please set `org-e-html-divs' instead.")
204 (defcustom org-e-html-divs '("preamble" "content" "postamble")
205 "The name of the main divs for HTML export.
206 This is a list of three strings, the first one for the preamble
207 DIV, the second one for the content DIV and the third one for the
208 postamble DIV."
209 :group 'org-export-e-html
210 :type '(list
211 (string :tag " Div for the preamble:")
212 (string :tag " Div for the content:")
213 (string :tag "Div for the postamble:")))
216 ;;;; Document Header (Styles)
218 (defconst org-e-html-style-default
219 "<style type=\"text/css\">
220 <!--/*--><![CDATA[/*><!--*/
221 html { font-family: Times, serif; font-size: 12pt; }
222 .title { text-align: center; }
223 .todo { color: red; }
224 .done { color: green; }
225 .tag { background-color: #add8e6; font-weight:normal }
226 .target { }
227 .timestamp { color: #bebebe; }
228 .timestamp-kwd { color: #5f9ea0; }
229 .right {margin-left:auto; margin-right:0px; text-align:right;}
230 .left {margin-left:0px; margin-right:auto; text-align:left;}
231 .center {margin-left:auto; margin-right:auto; text-align:center;}
232 p.verse { margin-left: 3% }
233 pre {
234 border: 1pt solid #AEBDCC;
235 background-color: #F3F5F7;
236 padding: 5pt;
237 font-family: courier, monospace;
238 font-size: 90%;
239 overflow:auto;
241 table { border-collapse: collapse; }
242 td, th { vertical-align: top; }
243 th.right { text-align:center; }
244 th.left { text-align:center; }
245 th.center { text-align:center; }
246 td.right { text-align:right; }
247 td.left { text-align:left; }
248 td.center { text-align:center; }
249 dt { font-weight: bold; }
250 div.figure { padding: 0.5em; }
251 div.figure p { text-align: center; }
252 div.inlinetask {
253 padding:10px;
254 border:2px solid gray;
255 margin:10px;
256 background: #ffffcc;
258 textarea { overflow-x: auto; }
259 .linenr { font-size:smaller }
260 .code-highlighted {background-color:#ffff00;}
261 .org-info-js_info-navigation { border-style:none; }
262 #org-info-js_console-label { font-size:10px; font-weight:bold;
263 white-space:nowrap; }
264 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
265 font-weight:bold; }
266 /*]]>*/-->
267 </style>"
268 "The default style specification for exported HTML files.
269 Please use the variables `org-e-html-style' and
270 `org-e-html-style-extra' to add to this style. If you wish to not
271 have the default style included, customize the variable
272 `org-e-html-style-include-default'.")
274 (defcustom org-e-html-style-include-default t
275 "Non-nil means include the default style in exported HTML files.
276 The actual style is defined in `org-e-html-style-default' and should
277 not be modified. Use the variables `org-e-html-style' to add
278 your own style information."
279 :group 'org-export-e-html
280 :type 'boolean)
281 ;;;###autoload
282 (put 'org-e-html-style-include-default 'safe-local-variable 'booleanp)
284 (defcustom org-e-html-style ""
285 "Org-wide style definitions for exported HTML files.
287 This variable needs to contain the full HTML structure to provide a style,
288 including the surrounding HTML tags. If you set the value of this variable,
289 you should consider to include definitions for the following classes:
290 title, todo, done, timestamp, timestamp-kwd, tag, target.
292 For example, a valid value would be:
294 <style type=\"text/css\">
295 <![CDATA[
296 p { font-weight: normal; color: gray; }
297 h1 { color: black; }
298 .title { text-align: center; }
299 .todo, .timestamp-kwd { color: red; }
300 .done { color: green; }
302 </style>
304 If you'd like to refer to an external style file, use something like
306 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
308 As the value of this option simply gets inserted into the HTML <head> header,
309 you can \"misuse\" it to add arbitrary text to the header.
310 See also the variable `org-e-html-style-extra'."
311 :group 'org-export-e-html
312 :type 'string)
313 ;;;###autoload
314 (put 'org-e-html-style 'safe-local-variable 'stringp)
316 (defcustom org-e-html-style-extra ""
317 "Additional style information for HTML export.
318 The value of this variable is inserted into the HTML buffer right after
319 the value of `org-e-html-style'. Use this variable for per-file
320 settings of style information, and do not forget to surround the style
321 settings with <style>...</style> tags."
322 :group 'org-export-e-html
323 :type 'string)
324 ;;;###autoload
325 (put 'org-e-html-style-extra 'safe-local-variable 'stringp)
327 (defcustom org-e-html-mathjax-options
328 '((path "http://orgmode.org/mathjax/MathJax.js")
329 (scale "100")
330 (align "center")
331 (indent "2em")
332 (mathml nil))
333 "Options for MathJax setup.
335 path The path where to find MathJax
336 scale Scaling for the HTML-CSS backend, usually between 100 and 133
337 align How to align display math: left, center, or right
338 indent If align is not center, how far from the left/right side?
339 mathml Should a MathML player be used if available?
340 This is faster and reduces bandwidth use, but currently
341 sometimes has lower spacing quality. Therefore, the default is
342 nil. When browsers get better, this switch can be flipped.
344 You can also customize this for each buffer, using something like
346 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
347 :group 'org-export-e-html
348 :type '(list :greedy t
349 (list :tag "path (the path from where to load MathJax.js)"
350 (const :format " " path) (string))
351 (list :tag "scale (scaling for the displayed math)"
352 (const :format " " scale) (string))
353 (list :tag "align (alignment of displayed equations)"
354 (const :format " " align) (string))
355 (list :tag "indent (indentation with left or right alignment)"
356 (const :format " " indent) (string))
357 (list :tag "mathml (should MathML display be used is possible)"
358 (const :format " " mathml) (boolean))))
361 ;;;; Document Header (Scripts)
363 (defcustom org-e-html-style-include-scripts t
364 "Non-nil means include the JavaScript snippets in exported HTML files.
365 The actual script is defined in `org-e-html-scripts' and should
366 not be modified."
367 :group 'org-export-e-html
368 :type 'boolean)
370 (defconst org-e-html-scripts
371 "<script type=\"text/javascript\">
372 <!--/*--><![CDATA[/*><!--*/
373 function CodeHighlightOn(elem, id)
375 var target = document.getElementById(id);
376 if(null != target) {
377 elem.cacheClassElem = elem.className;
378 elem.cacheClassTarget = target.className;
379 target.className = \"code-highlighted\";
380 elem.className = \"code-highlighted\";
383 function CodeHighlightOff(elem, id)
385 var target = document.getElementById(id);
386 if(elem.cacheClassElem)
387 elem.className = elem.cacheClassElem;
388 if(elem.cacheClassTarget)
389 target.className = elem.cacheClassTarget;
391 /*]]>*///-->
392 </script>"
393 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
396 ;;;; Document Header (Mathjax)
398 (defcustom org-e-html-mathjax-template
399 "<script type=\"text/javascript\" src=\"%PATH\">
400 <!--/*--><![CDATA[/*><!--*/
401 MathJax.Hub.Config({
402 // Only one of the two following lines, depending on user settings
403 // First allows browser-native MathML display, second forces HTML/CSS
404 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
405 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
406 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
407 \"TeX/noUndefined.js\"],
408 tex2jax: {
409 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
410 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
411 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
412 ignoreClass: \"tex2jax_ignore\",
413 processEscapes: false,
414 processEnvironments: true,
415 preview: \"TeX\"
417 showProcessingMessages: true,
418 displayAlign: \"%ALIGN\",
419 displayIndent: \"%INDENT\",
421 \"HTML-CSS\": {
422 scale: %SCALE,
423 availableFonts: [\"STIX\",\"TeX\"],
424 preferredFont: \"TeX\",
425 webFont: \"TeX\",
426 imageFont: \"TeX\",
427 showMathMenu: true,
429 MMLorHTML: {
430 prefer: {
431 MSIE: \"MML\",
432 Firefox: \"MML\",
433 Opera: \"HTML\",
434 other: \"HTML\"
438 /*]]>*///-->
439 </script>"
440 "The MathJax setup for XHTML files."
441 :group 'org-export-e-html
442 :type 'string)
445 ;;;; Preamble
447 (defcustom org-e-html-preamble t
448 "Non-nil means insert a preamble in HTML export.
450 When `t', insert a string as defined by one of the formatting
451 strings in `org-e-html-preamble-format'. When set to a
452 string, this string overrides `org-e-html-preamble-format'.
453 When set to a function, apply this function and insert the
454 returned string. The function takes the property list of export
455 options as its only argument.
457 Setting :html-preamble in publishing projects will take
458 precedence over this variable."
459 :group 'org-export-e-html
460 :type '(choice (const :tag "No preamble" nil)
461 (const :tag "Default preamble" t)
462 (string :tag "Custom formatting string")
463 (function :tag "Function (must return a string)")))
465 (defcustom org-e-html-preamble-format '(("en" ""))
466 "The format for the HTML preamble.
468 %t stands for the title.
469 %a stands for the author's name.
470 %e stands for the author's email.
471 %d stands for the date.
473 If you need to use a \"%\" character, you need to escape it
474 like that: \"%%\"."
475 :group 'org-export-e-html
476 :type 'string)
478 (defcustom org-e-html-home/up-format
479 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
480 <a accesskey=\"h\" href=\"%s\"> UP </a>
482 <a accesskey=\"H\" href=\"%s\"> HOME </a>
483 </div>"
484 "Snippet used to insert the HOME and UP links.
485 This is a format string, the first %s will receive the UP link,
486 the second the HOME link. If both `org-e-html-link-up' and
487 `org-e-html-link-home' are empty, the entire snippet will be
488 ignored."
489 :group 'org-export-e-html
490 :type 'string)
492 ;;;; Postamble
494 (defcustom org-e-html-postamble 'auto
495 "Non-nil means insert a postamble in HTML export.
497 When `t', insert a string as defined by the formatting string in
498 `org-e-html-postamble-format'. When set to a string, this
499 string overrides `org-e-html-postamble-format'. When set to
500 'auto, discard `org-e-html-postamble-format' and honor
501 `org-export-author/email/creator-info' variables. When set to a
502 function, apply this function and insert the returned string.
503 The function takes the property list of export options as its
504 only argument.
506 Setting :html-postamble in publishing projects will take
507 precedence over this variable."
508 :group 'org-export-e-html
509 :type '(choice (const :tag "No postamble" nil)
510 (const :tag "Auto preamble" 'auto)
511 (const :tag "Default formatting string" t)
512 (string :tag "Custom formatting string")
513 (function :tag "Function (must return a string)")))
515 (defcustom org-e-html-postamble-format
516 '(("en" "<p class=\"author\">Author: %a (%e)</p>
517 <p class=\"date\">Date: %d</p>
518 <p class=\"creator\">Generated by %c</p>
519 <p class=\"xhtml-validation\">%v</p>
521 "The format for the HTML postamble.
523 %a stands for the author's name.
524 %e stands for the author's email.
525 %d stands for the date.
526 %c will be replaced by information about Org/Emacs versions.
527 %v will be replaced by `org-e-html-validation-link'.
529 If you need to use a \"%\" character, you need to escape it
530 like that: \"%%\"."
531 :group 'org-export-e-html
532 :type 'string)
534 (defcustom org-e-html-validation-link
535 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
536 "Link to HTML validation service."
537 :group 'org-export-e-html
538 :type 'string)
540 ;; FIXME Obsolete since Org 7.7
541 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
542 ;;;; Emphasis
544 (defcustom org-e-html-protect-char-alist
545 '(("&" . "&amp;")
546 ("<" . "&lt;")
547 (">" . "&gt;"))
548 "Alist of characters to be converted by `org-e-html-protect'."
549 :group 'org-export-e-html
550 :type '(repeat (cons (string :tag "Character")
551 (string :tag "HTML equivalent"))))
553 (defconst org-e-html-special-string-regexps
554 '(("\\\\-" . "&shy;")
555 ("---\\([^-]\\)" . "&mdash;\\1")
556 ("--\\([^-]\\)" . "&ndash;\\1")
557 ("\\.\\.\\." . "&hellip;"))
558 "Regular expressions for special string conversion.")
561 ;;;; Todos
563 (defcustom org-e-html-todo-kwd-class-prefix ""
564 "Prefix to class names for TODO keywords.
565 Each TODO keyword gets a class given by the keyword itself, with this prefix.
566 The default prefix is empty because it is nice to just use the keyword
567 as a class name. But if you get into conflicts with other, existing
568 CSS classes, then this prefix can be very useful."
569 :group 'org-export-e-html
570 :type 'string)
573 ;;;; Tags
575 (defcustom org-e-html-tag-class-prefix ""
576 "Prefix to class names for TODO keywords.
577 Each tag gets a class given by the tag itself, with this prefix.
578 The default prefix is empty because it is nice to just use the keyword
579 as a class name. But if you get into conflicts with other, existing
580 CSS classes, then this prefix can be very useful."
581 :group 'org-export-e-html
582 :type 'string)
584 ;;;; Timestamps
585 ;;;; Statistics Cookie
586 ;;;; Subscript
587 ;;;; Superscript
589 ;;;; Inline images
591 (defcustom org-e-html-inline-images 'maybe
592 "Non-nil means inline images into exported HTML pages.
593 This is done using an <img> tag. When nil, an anchor with href is used to
594 link to the image. If this option is `maybe', then images in links with
595 an empty description will be inlined, while images with a description will
596 be linked only."
597 :group 'org-export-e-html
598 :type '(choice (const :tag "Never" nil)
599 (const :tag "Always" t)
600 (const :tag "When there is no description" maybe)))
602 (defcustom org-e-html-inline-image-extensions
603 '("png" "jpeg" "jpg" "gif" "svg")
604 "Extensions of image files that can be inlined into HTML."
605 :group 'org-export-e-html
606 :type '(repeat (string :tag "Extension")))
609 ;;;; Block
610 ;;;; Comment
611 ;;;; Comment Block
612 ;;;; Drawer
613 ;;;; Dynamic Block
614 ;;;; Emphasis
615 ;;;; Entity
616 ;;;; Example Block
617 ;;;; Export Snippet
618 ;;;; Export Block
619 ;;;; Fixed Width
620 ;;;; Footnotes
622 (defcustom org-e-html-footnotes-section "<div id=\"footnotes\">
623 <h2 class=\"footnotes\">%s: </h2>
624 <div id=\"text-footnotes\">
626 </div>
627 </div>"
628 "Format for the footnotes section.
629 Should contain a two instances of %s. The first will be replaced with the
630 language-specific word for \"Footnotes\", the second one will be replaced
631 by the footnotes themselves."
632 :group 'org-export-e-html
633 :type 'string)
635 (defcustom org-e-html-footnote-format "<sup>%s</sup>"
636 "The format for the footnote reference.
637 %s will be replaced by the footnote reference itself."
638 :group 'org-export-e-html
639 :type 'string)
641 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
642 "Text used to separate footnotes."
643 :group 'org-export-e-html
644 :type 'string)
647 ;;;; Headline
648 ;;;; Horizontal Rule
649 ;;;; Inline Babel Call
650 ;;;; Inline Src Block
651 ;;;; Inlinetask
652 ;;;; Item
653 ;;;; Keyword
654 ;;;; Latex Environment
655 ;;;; Latex Fragment
656 ;;;; Line Break
657 ;;;; Link
658 ;;;; Babel Call
659 ;;;; Macro
660 ;;;; Paragraph
661 ;;;; Plain List
662 ;;;; Plain Text
663 ;;;; Property Drawer
664 ;;;; Quote Block
665 ;;;; Quote Section
666 ;;;; Section
667 ;;;; Radio Target
668 ;;;; Special Block
669 ;;;; Src Block
671 (defgroup org-export-e-htmlize nil
672 "Options for processing examples with htmlize.el."
673 :tag "Org Export Htmlize"
674 :group 'org-export-e-html)
676 (defcustom org-export-e-htmlize-output-type 'inline-css
677 "Output type to be used by htmlize when formatting code snippets.
678 Choices are `css', to export the CSS selectors only, or `inline-css', to
679 export the CSS attribute values inline in the HTML. We use as default
680 `inline-css', in order to make the resulting HTML self-containing.
682 However, this will fail when using Emacs in batch mode for export, because
683 then no rich font definitions are in place. It will also not be good if
684 people with different Emacs setup contribute HTML files to a website,
685 because the fonts will represent the individual setups. In these cases,
686 it is much better to let Org/Htmlize assign classes only, and to use
687 a style file to define the look of these classes.
688 To get a start for your css file, start Emacs session and make sure that
689 all the faces you are interested in are defined, for example by loading files
690 in all modes you want. Then, use the command
691 \\[org-export-e-htmlize-generate-css] to extract class definitions."
692 :group 'org-export-e-htmlize
693 :type '(choice (const css) (const inline-css)))
695 (defcustom org-export-e-htmlize-css-font-prefix "org-"
696 "The prefix for CSS class names for htmlize font specifications."
697 :group 'org-export-e-htmlize
698 :type 'string)
700 (defcustom org-export-e-htmlized-org-css-url nil
701 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
702 Normally when creating an htmlized version of an Org buffer, htmlize will
703 create CSS to define the font colors. However, this does not work when
704 converting in batch mode, and it also can look bad if different people
705 with different fontification setup work on the same website.
706 When this variable is non-nil, creating an htmlized version of an Org buffer
707 using `org-export-as-org' will remove the internal CSS section and replace it
708 with a link to this URL."
709 :group 'org-export-e-htmlize
710 :type '(choice
711 (const :tag "Keep internal css" nil)
712 (string :tag "URL or local href")))
715 ;;;; Table
717 (defcustom org-e-html-table-tag
718 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
719 "The HTML tag that is used to start a table.
720 This must be a <table> tag, but you may change the options like
721 borders and spacing."
722 :group 'org-export-e-html
723 :type 'string)
725 (defcustom org-e-html-table-header-tags '("<th scope=\"%s\"%s>" . "</th>")
726 "The opening tag for table header fields.
727 This is customizable so that alignment options can be specified.
728 The first %s will be filled with the scope of the field, either row or col.
729 The second %s will be replaced by a style entry to align the field.
730 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
731 See also the variable `org-e-html-table-align-individual-fields'."
732 :group 'org-export-tables ; FIXME: change group?
733 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
735 (defcustom org-e-html-table-data-tags '("<td%s>" . "</td>")
736 "The opening tag for table data fields.
737 This is customizable so that alignment options can be specified.
738 The first %s will be filled with the scope of the field, either row or col.
739 The second %s will be replaced by a style entry to align the field.
740 See also the variable `org-e-html-table-align-individual-fields'."
741 :group 'org-export-tables
742 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
744 (defcustom org-e-html-table-row-tags '("<tr>" . "</tr>")
745 "The opening tag for table data fields.
746 This is customizable so that alignment options can be specified.
747 Instead of strings, these can be Lisp forms that will be evaluated
748 for each row in order to construct the table row tags. During evaluation,
749 the variable `head' will be true when this is a header line, nil when this
750 is a body line. And the variable `nline' will contain the line number,
751 starting from 1 in the first header line. For example
753 (setq org-e-html-table-row-tags
754 (cons '(if head
755 \"<tr>\"
756 (if (= (mod nline 2) 1)
757 \"<tr class=\\\"tr-odd\\\">\"
758 \"<tr class=\\\"tr-even\\\">\"))
759 \"</tr>\"))
761 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
762 :group 'org-export-tables
763 :type '(cons
764 (choice :tag "Opening tag"
765 (string :tag "Specify")
766 (sexp))
767 (choice :tag "Closing tag"
768 (string :tag "Specify")
769 (sexp))))
771 (defcustom org-e-html-table-align-individual-fields t
772 "Non-nil means attach style attributes for alignment to each table field.
773 When nil, alignment will only be specified in the column tags, but this
774 is ignored by some browsers (like Firefox, Safari). Opera does it right
775 though."
776 :group 'org-export-tables
777 :type 'boolean)
779 (defcustom org-e-html-table-use-header-tags-for-first-column nil
780 "Non-nil means format column one in tables with header tags.
781 When nil, also column one will use data tags."
782 :group 'org-export-tables
783 :type 'boolean)
786 ;;;; Target
787 ;;;; Timestamp
789 ;;;; Verbatim
790 ;;;; Verse Block
791 ;;;; Headline
793 (defcustom org-e-html-toplevel-hlevel 2
794 "The <H> level for level 1 headings in HTML export.
795 This is also important for the classes that will be wrapped around headlines
796 and outline structure. If this variable is 1, the top-level headlines will
797 be <h1>, and the corresponding classes will be outline-1, section-number-1,
798 and outline-text-1. If this is 2, all of these will get a 2 instead.
799 The default for this variable is 2, because we use <h1> for formatting the
800 document title."
801 :group 'org-export-e-html
802 :type 'string)
805 ;;;; Links
806 ;;;; Drawers
807 ;;;; Inlinetasks
808 ;;;; Publishing
810 (defcustom org-e-html-link-org-files-as-html t
811 "Non-nil means make file links to `file.org' point to `file.html'.
812 When org-mode is exporting an org-mode file to HTML, links to
813 non-html files are directly put into a href tag in HTML.
814 However, links to other Org-mode files (recognized by the
815 extension `.org.) should become links to the corresponding html
816 file, assuming that the linked org-mode file will also be
817 converted to HTML.
818 When nil, the links still point to the plain `.org' file."
819 :group 'org-export-e-html
820 :type 'boolean)
823 ;;;; Compilation
827 ;;; User Configurable Variables (MAYBE)
829 ;;;; Preamble
831 (defcustom org-e-html-date-format
832 "\\today"
833 "Format string for \\date{...}."
834 :group 'org-export-e-html
835 :type 'boolean)
837 ;;;; Headline
839 (defcustom org-e-html-format-headline-function nil
840 "Function to format headline text.
842 This function will be called with 5 arguments:
843 TODO the todo keyword \(string or nil\).
844 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
845 PRIORITY the priority of the headline \(integer or nil\)
846 TEXT the main headline text \(string\).
847 TAGS the tags string, separated with colons \(string or nil\).
849 The function result will be used in the section format string.
851 As an example, one could set the variable to the following, in
852 order to reproduce the default set-up:
854 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
855 \"Default format function for an headline.\"
856 \(concat \(when todo
857 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
858 \(when priority
859 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
860 text
861 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
862 :group 'org-export-e-html
863 :type 'function)
866 ;;;; Text Markup
868 (defcustom org-e-html-text-markup-alist
869 '((bold . "<b>%s</b>")
870 (code . "<code>%s</code>")
871 (italic . "<i>%s</i>")
872 (strike-through . "<del>%s</del>")
873 (underline . "<span style=\"text-decoration:underline;\">%s</span>")
874 (verbatim . "<code>%s</code>"))
875 "Alist of HTML expressions to convert text markup
877 The key must be a symbol among `bold', `code', `italic',
878 `strike-through', `underline' and `verbatim'. The value is
879 a formatting string to wrap fontified text with.
881 If no association can be found for a given markup, text will be
882 returned as-is."
883 :group 'org-export-e-html
884 :type '(alist :key-type (symbol :tag "Markup type")
885 :value-type (string :tag "Format string"))
886 :options '(bold code italic strike-through underline verbatim))
889 ;;;; Footnotes
891 (defcustom org-e-html-footnote-separator "<sup>, </sup>"
892 "Text used to separate footnotes."
893 :group 'org-export-e-html
894 :type 'string)
897 ;;;; Timestamps
899 (defcustom org-e-html-active-timestamp-format "\\textit{%s}"
900 "A printf format string to be applied to active timestamps."
901 :group 'org-export-e-html
902 :type 'string)
904 (defcustom org-e-html-inactive-timestamp-format "\\textit{%s}"
905 "A printf format string to be applied to inactive timestamps."
906 :group 'org-export-e-html
907 :type 'string)
909 (defcustom org-e-html-diary-timestamp-format "\\textit{%s}"
910 "A printf format string to be applied to diary timestamps."
911 :group 'org-export-e-html
912 :type 'string)
915 ;;;; Links
917 (defcustom org-e-html-inline-image-rules
918 '(("file" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
919 ("http" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
920 ("https" . "\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
921 "Rules characterizing image files that can be inlined into HTML.
923 A rule consists in an association whose key is the type of link
924 to consider, and value is a regexp that will be matched against
925 link's path.
927 Note that, by default, the image extension *actually* allowed
928 depend on the way the HTML file is processed. When used with
929 pdflatex, pdf, jpg and png images are OK. When processing
930 through dvi to Postscript, only ps and eps are allowed. The
931 default we use here encompasses both."
932 :group 'org-export-e-html
933 :type '(alist :key-type (string :tag "Type")
934 :value-type (regexp :tag "Path")))
936 ;;;; Tables
938 (defcustom org-e-html-table-caption-above t
939 "When non-nil, place caption string at the beginning of the table.
940 Otherwise, place it near the end."
941 :group 'org-export-e-html
942 :type 'boolean)
944 ;;;; Drawers
946 (defcustom org-e-html-format-drawer-function nil
947 "Function called to format a drawer in HTML code.
949 The function must accept two parameters:
950 NAME the drawer name, like \"LOGBOOK\"
951 CONTENTS the contents of the drawer.
953 The function should return the string to be exported.
955 For example, the variable could be set to the following function
956 in order to mimic default behaviour:
958 \(defun org-e-html-format-drawer-default \(name contents\)
959 \"Format a drawer element for HTML export.\"
960 contents\)"
961 :group 'org-export-e-html
962 :type 'function)
965 ;;;; Inlinetasks
967 (defcustom org-e-html-format-inlinetask-function nil
968 "Function called to format an inlinetask in HTML code.
970 The function must accept six parameters:
971 TODO the todo keyword, as a string
972 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
973 PRIORITY the inlinetask priority, as a string
974 NAME the inlinetask name, as a string.
975 TAGS the inlinetask tags, as a string.
976 CONTENTS the contents of the inlinetask, as a string.
978 The function should return the string to be exported.
980 For example, the variable could be set to the following function
981 in order to mimic default behaviour:
983 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
984 \"Format an inline task element for HTML export.\"
985 \(let \(\(full-title
986 \(concat
987 \(when todo
988 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
989 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
990 title
991 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
992 \(format \(concat \"\\\\begin{center}\\n\"
993 \"\\\\fbox{\\n\"
994 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
995 \"%s\\n\\n\"
996 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
997 \"%s\"
998 \"\\\\end{minipage}}\"
999 \"\\\\end{center}\"\)
1000 full-title contents\)\)"
1001 :group 'org-export-e-html
1002 :type 'function)
1005 ;; Src blocks
1007 ;;;; Plain text
1009 (defcustom org-e-html-quotes
1010 '(("fr"
1011 ("\\(\\s-\\|[[(]\\|^\\)\"" . "«~")
1012 ("\\(\\S-\\)\"" . "~»")
1013 ("\\(\\s-\\|(\\|^\\)'" . "'"))
1014 ("en"
1015 ("\\(\\s-\\|[[(]\\|^\\)\"" . "``")
1016 ("\\(\\S-\\)\"" . "''")
1017 ("\\(\\s-\\|(\\|^\\)'" . "`")))
1018 "Alist for quotes to use when converting english double-quotes.
1020 The CAR of each item in this alist is the language code.
1021 The CDR of each item in this alist is a list of three CONS:
1022 - the first CONS defines the opening quote;
1023 - the second CONS defines the closing quote;
1024 - the last CONS defines single quotes.
1026 For each item in a CONS, the first string is a regexp
1027 for allowed characters before/after the quote, the second
1028 string defines the replacement string for this quote."
1029 :group 'org-export-e-html
1030 :type '(list
1031 (cons :tag "Opening quote"
1032 (string :tag "Regexp for char before")
1033 (string :tag "Replacement quote "))
1034 (cons :tag "Closing quote"
1035 (string :tag "Regexp for char after ")
1036 (string :tag "Replacement quote "))
1037 (cons :tag "Single quote"
1038 (string :tag "Regexp for char before")
1039 (string :tag "Replacement quote "))))
1041 ;;;; Compilation
1045 ;;; Internal Functions (HTML)
1047 (defun org-e-html-cvt-org-as-html (opt-plist type path)
1048 "Convert an org filename to an equivalent html filename.
1049 If TYPE is not file, just return `nil'.
1050 See variable `org-e-html-link-org-files-as-html'."
1051 (save-match-data
1052 (and
1053 org-e-html-link-org-files-as-html
1054 (string= type "file")
1055 (string-match "\\.org$" path)
1056 (progn
1057 (list
1058 "file"
1059 (concat
1060 (substring path 0 (match-beginning 0))
1061 "." (plist-get opt-plist :html-extension)))))))
1063 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1064 descp)
1065 "Make an HTML link.
1066 OPT-PLIST is an options list.
1067 TYPE is the device-type of the link (THIS://foo.html).
1068 PATH is the path of the link (http://THIS#location).
1069 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1070 DESC is the link description, if any.
1071 ATTR is a string of other attributes of the \"a\" element."
1072 (declare (special org-lparse-par-open))
1073 (save-match-data
1074 (let* ((may-inline-p
1075 (and (member type-1 '("http" "https" "file"))
1076 (org-lparse-should-inline-p path descp)
1077 (not fragment)))
1078 (type (if (equal type-1 "id") "file" type-1))
1079 (filename path)
1080 ;;First pass. Just sanity stuff.
1081 (components-1
1082 (cond
1083 ((string= type "file")
1084 (list
1085 type
1086 ;;Substitute just if original path was absolute.
1087 ;;(Otherwise path must remain relative)
1088 (if (file-name-absolute-p path)
1089 (concat "file://" (expand-file-name path))
1090 path)))
1091 ((string= type "")
1092 (list nil path))
1093 (t (list type path))))
1095 ;;Second pass. Components converted so they can refer
1096 ;;to a remote site.
1097 (components-2
1099 (and org-e-html-cvt-link-fn
1100 (apply org-e-html-cvt-link-fn
1101 opt-plist components-1))
1102 (apply #'org-e-html-cvt-org-as-html
1103 opt-plist components-1)
1104 components-1))
1105 (type (first components-2))
1106 (thefile (second components-2)))
1109 ;;Third pass. Build final link except for leading type
1110 ;;spec.
1111 (cond
1112 ((or
1113 (not type)
1114 (string= type "http")
1115 (string= type "https")
1116 (string= type "file")
1117 (string= type "coderef"))
1118 (if fragment
1119 (setq thefile (concat thefile "#" fragment))))
1121 (t))
1123 ;;Final URL-build, for all types.
1124 (setq thefile
1125 (let
1126 ((str (org-xml-format-href thefile)))
1127 (if (and type (not (or (string= "file" type)
1128 (string= "coderef" type))))
1129 (concat type ":" str)
1130 str)))
1132 (if may-inline-p
1133 (ignore) ;; (org-e-html-format-image thefile)
1134 (org-lparse-format
1135 'LINK (org-xml-format-desc desc) thefile attr)))))
1137 ;; (caption (and caption (org-xml-encode-org-text caption)))
1138 ;; alt = (file-name-nondirectory path)
1140 (defun org-e-html-format-inline-image (src &optional
1141 caption label attr standalone-p)
1142 (let* ((id (if (not label) ""
1143 (format " id=\"%s\"" (org-export-solidify-link-text label))))
1144 (attr (concat attr
1145 (cond
1146 ((string-match "\\<alt=" (or attr "")) "")
1147 ((string-match "^ltxpng/" src)
1148 (format " alt=\"%s\""
1149 (org-e-html-encode-plain-text
1150 (org-find-text-property-in-string
1151 'org-latex-src src))))
1152 (t (format " alt=\"%s\""
1153 (file-name-nondirectory src)))))))
1154 (cond
1155 (standalone-p
1156 (let ((img (format "<img src=\"%s\" %s/>" src attr)))
1157 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1158 id (format "\n<p>%s</p>" img)
1159 (when caption (format "\n<p>%s</p>" caption)))))
1160 (t (format "<img src=\"%s\" %s/>" src (concat attr id))))))
1162 ;;;; Bibliography
1164 (defun org-e-html-bibliography ()
1165 "Find bibliography, cut it out and return it."
1166 (catch 'exit
1167 (let (beg end (cnt 1) bib)
1168 (save-excursion
1169 (goto-char (point-min))
1170 (when (re-search-forward
1171 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1172 (setq beg (match-beginning 0))
1173 (while (re-search-forward "</?div\\>" nil t)
1174 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1175 (when (= cnt 0)
1176 (and (looking-at ">") (forward-char 1))
1177 (setq bib (buffer-substring beg (point)))
1178 (delete-region beg (point))
1179 (throw 'exit bib))))
1180 nil))))
1182 ;;;; Table
1184 (defun org-e-html-format-table (lines olines)
1185 (let ((org-e-html-format-table-no-css nil))
1186 (org-lparse-format-table lines olines)))
1188 (defun org-e-html-splice-attributes (tag attributes)
1189 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1190 (if (not attributes)
1192 (let (oldatt newatt)
1193 (setq oldatt (org-extract-attributes-from-string tag)
1194 tag (pop oldatt)
1195 newatt (cdr (org-extract-attributes-from-string attributes)))
1196 (while newatt
1197 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1198 (if (string-match ">" tag)
1199 (setq tag
1200 (replace-match (concat (org-attributes-to-string oldatt) ">")
1201 t t tag)))
1202 tag)))
1204 (defun org-export-splice-style (style extra)
1205 "Splice EXTRA into STYLE, just before \"</style>\"."
1206 (if (and (stringp extra)
1207 (string-match "\\S-" extra)
1208 (string-match "</style>" style))
1209 (concat (substring style 0 (match-beginning 0))
1210 "\n" extra "\n"
1211 (substring style (match-beginning 0)))
1212 style))
1214 (defun org-export-e-htmlize-region-for-paste (beg end)
1215 "Convert the region to HTML, using htmlize.el.
1216 This is much like `htmlize-region-for-paste', only that it uses
1217 the settings define in the org-... variables."
1218 (let* ((htmlize-output-type org-export-e-htmlize-output-type)
1219 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix)
1220 (htmlbuf (htmlize-region beg end)))
1221 (unwind-protect
1222 (with-current-buffer htmlbuf
1223 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1224 (plist-get htmlize-buffer-places 'content-end)))
1225 (kill-buffer htmlbuf))))
1227 ;;;###autoload
1228 (defun org-export-e-htmlize-generate-css ()
1229 "Create the CSS for all font definitions in the current Emacs session.
1230 Use this to create face definitions in your CSS style file that can then
1231 be used by code snippets transformed by htmlize.
1232 This command just produces a buffer that contains class definitions for all
1233 faces used in the current Emacs session. You can copy and paste the ones you
1234 need into your CSS file.
1236 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1237 the function `org-export-e-htmlize-region-for-paste' will produce code
1238 that uses these same face definitions."
1239 (interactive)
1240 (require 'htmlize)
1241 (and (get-buffer "*html*") (kill-buffer "*html*"))
1242 (with-temp-buffer
1243 (let ((fl (face-list))
1244 (htmlize-css-name-prefix "org-")
1245 (htmlize-output-type 'css)
1246 f i)
1247 (while (setq f (pop fl)
1248 i (and f (face-attribute f :inherit)))
1249 (when (and (symbolp f) (or (not i) (not (listp i))))
1250 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1251 (htmlize-region (point-min) (point-max))))
1252 (org-pop-to-buffer-same-window "*html*")
1253 (goto-char (point-min))
1254 (if (re-search-forward "<style" nil t)
1255 (delete-region (point-min) (match-beginning 0)))
1256 (if (re-search-forward "</style>" nil t)
1257 (delete-region (1+ (match-end 0)) (point-max)))
1258 (beginning-of-line 1)
1259 (if (looking-at " +") (replace-match ""))
1260 (goto-char (point-min)))
1262 (defun org-e-html-make-string (n string)
1263 (let (out) (dotimes (i n out) (setq out (concat string out)))))
1265 (defun org-e-html-toc-text (toc-entries)
1266 (let* ((prev-level (1- (nth 1 (car toc-entries))))
1267 (start-level prev-level))
1268 (concat
1269 (mapconcat
1270 (lambda (entry)
1271 (let ((headline (nth 0 entry))
1272 (level (nth 1 entry)))
1273 (concat
1274 (let* ((cnt (- level prev-level))
1275 (times (if (> cnt 0) (1- cnt) (- cnt)))
1276 rtn)
1277 (setq prev-level level)
1278 (concat
1279 (org-e-html-make-string
1280 times (cond ((> cnt 0) "\n<ul>\n<li>")
1281 ((< cnt 0) "</li>\n</ul>\n")))
1282 (if (> cnt 0) "\n<ul>\n<li>" "</li>\n<li>")))
1283 headline)))
1284 toc-entries "")
1285 (org-e-html-make-string
1286 (- prev-level start-level) "</li>\n</ul>\n"))))
1288 (defun* org-e-html-format-toc-headline
1289 (todo todo-type priority text tags
1290 &key level section-number headline-label &allow-other-keys)
1291 (let ((headline (concat
1292 section-number (and section-number ". ")
1293 text
1294 (and tags "&nbsp;&nbsp;&nbsp;") (org-e-html--tags tags))))
1295 (format "<a href=\"#%s\">%s</a>"
1296 headline-label
1297 (if (not nil) headline
1298 (format "<span class=\"%s\">%s</span>" todo-type headline)))))
1300 (defun org-e-html-toc (depth info)
1301 (assert (wholenump depth))
1302 (let* ((headlines (org-export-collect-headlines info depth))
1303 (toc-entries
1304 (loop for headline in headlines collect
1305 (list (org-e-html-format-headline--wrap
1306 headline info 'org-e-html-format-toc-headline)
1307 (org-export-get-relative-level headline info)))))
1308 (when toc-entries
1309 (let* ((lang-specific-heading
1310 (nth 3 (or (assoc (plist-get info :language)
1311 org-export-language-setup)
1312 (assoc "en" org-export-language-setup)))))
1313 (concat
1314 "<div id=\"table-of-contents\">\n"
1315 (format "<h%d>%s</h%d>\n"
1316 org-e-html-toplevel-hlevel
1317 lang-specific-heading
1318 org-e-html-toplevel-hlevel)
1319 "<div id=\"text-table-of-contents\">"
1320 (org-e-html-toc-text toc-entries)
1321 "</div>\n"
1322 "</div>\n")))))
1324 ;; (defun org-e-html-format-line (line)
1325 ;; (case org-lparse-dyn-current-environment
1326 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1327 ;; (t (concat line "\n"))))
1329 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1330 "Turn todo keyword into a valid class name.
1331 Replaces invalid characters with \"_\"."
1332 (save-match-data
1333 (while (string-match "[^a-zA-Z0-9_]" kwd)
1334 (setq kwd (replace-match "_" t t kwd))))
1335 kwd)
1337 (defun org-e-html-format-footnote-reference (n def refcnt)
1338 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
1339 (format org-e-html-footnote-format
1340 (format
1341 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1342 n extra n n))))
1344 (defun org-e-html-format-footnotes-section (section-name definitions)
1345 (if (not definitions) ""
1346 (format org-e-html-footnotes-section section-name definitions)))
1348 (defun org-e-html-format-footnote-definition (fn)
1349 (let ((n (car fn)) (def (cdr fn)))
1350 (format
1351 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1352 (format
1353 (format org-e-html-footnote-format
1354 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1355 n n n) def)))
1357 (defun org-e-html-footnote-section (info)
1358 (let* ((fn-alist (org-export-collect-footnote-definitions
1359 (plist-get info :parse-tree) info))
1361 (fn-alist
1362 (loop for (n type raw) in fn-alist collect
1363 (cons n (if (equal (org-element-type raw) 'org-data)
1364 (org-trim (org-export-data raw info))
1365 (format "<p>%s</p>"
1366 (org-trim (org-export-data raw info))))))))
1367 (when fn-alist
1368 (org-e-html-format-footnotes-section
1369 (nth 4 (or (assoc (plist-get info :language)
1370 org-export-language-setup)
1371 (assoc "en" org-export-language-setup)))
1372 (format
1373 "<table>\n%s\n</table>\n"
1374 (mapconcat 'org-e-html-format-footnote-definition fn-alist "\n"))))))
1376 (defun org-e-html-format-date (info)
1377 (let ((date (plist-get info :date)))
1378 (cond
1379 ((and date (string-match "%" date))
1380 (format-time-string date))
1381 (date date)
1382 (t (format-time-string "%Y-%m-%d %T %Z")))))
1386 ;;; Internal Functions (Ngz)
1388 (defun org-e-html--caption/label-string (caption label info)
1389 "Return caption and label HTML string for floats.
1391 CAPTION is a cons cell of secondary strings, the car being the
1392 standard caption and the cdr its short form. LABEL is a string
1393 representing the label. INFO is a plist holding contextual
1394 information.
1396 If there's no caption nor label, return the empty string.
1398 For non-floats, see `org-e-html--wrap-label'."
1399 (setq label nil) ;; FIXME
1401 (let ((label-str (if label (format "\\label{%s}" label) "")))
1402 (cond
1403 ((and (not caption) (not label)) "")
1404 ((not caption) (format "\\label{%s}\n" label))
1405 ;; Option caption format with short name.
1406 ((cdr caption)
1407 (format "\\caption[%s]{%s%s}\n"
1408 (org-export-data (cdr caption) info)
1409 label-str
1410 (org-export-data (car caption) info)))
1411 ;; Standard caption format.
1412 ;; (t (format "\\caption{%s%s}\n"
1413 ;; label-str
1414 ;; (org-export-data (car caption) info)))
1415 (t (org-export-data (car caption) info)))))
1417 (defun org-e-html--find-verb-separator (s)
1418 "Return a character not used in string S.
1419 This is used to choose a separator for constructs like \\verb."
1420 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1421 (loop for c across ll
1422 when (not (string-match (regexp-quote (char-to-string c)) s))
1423 return (char-to-string c))))
1425 (defun org-e-html--quotation-marks (text info)
1426 "Export quotation marks depending on language conventions.
1427 TEXT is a string containing quotation marks to be replaced. INFO
1428 is a plist used as a communication channel."
1429 (mapc (lambda(l)
1430 (let ((start 0))
1431 (while (setq start (string-match (car l) text start))
1432 (let ((new-quote (concat (match-string 1 text) (cdr l))))
1433 (setq text (replace-match new-quote t t text))))))
1434 (cdr (or (assoc (plist-get info :language) org-e-html-quotes)
1435 ;; Falls back on English.
1436 (assoc "en" org-e-html-quotes))))
1437 text)
1439 (defun org-e-html--wrap-label (element output)
1440 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1441 This function shouldn't be used for floats. See
1442 `org-e-html--caption/label-string'."
1443 ;; (let ((label (org-element-property :name element)))
1444 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1445 ;; output
1446 ;; (concat (format "\\label{%s}\n" label) output)))
1447 output)
1451 ;;; Template
1453 (defun org-e-html-meta-info (info)
1454 (let* ((title (org-export-data (plist-get info :title) info))
1455 (author (and (plist-get info :with-author)
1456 (let ((auth (plist-get info :author)))
1457 (and auth (org-export-data auth info)))))
1458 (description (plist-get info :description))
1459 (keywords (plist-get info :keywords)))
1460 (concat
1461 (format "\n<title>%s</title>\n" title)
1462 (format
1463 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1464 (or (and org-export-coding-system
1465 (fboundp 'coding-system-get)
1466 (coding-system-get org-export-coding-system
1467 'mime-charset))
1468 "iso-8859-1"))
1469 (format "\n<meta name=\"title\" content=\"%s\"/>" title)
1470 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1471 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1472 (org-e-html-format-date info))
1473 (format "\n<meta name=\"author\" content=\"%s\"/>" author)
1474 (format "\n<meta name=\"description\" content=\"%s\"/>" description)
1475 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords))))
1477 (defun org-e-html-style (info)
1478 (concat
1479 "\n" (when (plist-get info :style-include-default) org-e-html-style-default)
1480 (plist-get info :style)
1481 (plist-get info :style-extra)
1482 "\n"
1483 (when (plist-get info :style-include-scripts)
1484 org-e-html-scripts)))
1486 (defun org-e-html-mathjax-config (info)
1487 "Insert the user setup into the matchjax template."
1488 (when (member (plist-get info :LaTeX-fragments) '(mathjax t))
1489 (let ((template org-e-html-mathjax-template)
1490 (options org-e-html-mathjax-options)
1491 (in-buffer (or (plist-get info :mathjax) ""))
1492 name val (yes " ") (no "// ") x)
1493 (mapc
1494 (lambda (e)
1495 (setq name (car e) val (nth 1 e))
1496 (if (string-match (concat "\\<" (symbol-name name) ":") in-buffer)
1497 (setq val (car (read-from-string
1498 (substring in-buffer (match-end 0))))))
1499 (if (not (stringp val)) (setq val (format "%s" val)))
1500 (if (string-match (concat "%" (upcase (symbol-name name))) template)
1501 (setq template (replace-match val t t template))))
1502 options)
1503 (setq val (nth 1 (assq 'mathml options)))
1504 (if (string-match (concat "\\<mathml:") in-buffer)
1505 (setq val (car (read-from-string
1506 (substring in-buffer (match-end 0))))))
1507 ;; Exchange prefixes depending on mathml setting
1508 (if (not val) (setq x yes yes no no x))
1509 ;; Replace cookies to turn on or off the config/jax lines
1510 (if (string-match ":MMLYES:" template)
1511 (setq template (replace-match yes t t template)))
1512 (if (string-match ":MMLNO:" template)
1513 (setq template (replace-match no t t template)))
1514 ;; Return the modified template
1515 template)))
1517 (defun org-e-html-preamble (info)
1518 (when (plist-get info :html-preamble)
1519 (let* ((title (org-export-data (plist-get info :title) info))
1520 (date (org-e-html-format-date info))
1521 (author (org-export-data (plist-get info :author) info))
1522 (lang-words (or (assoc (plist-get info :language)
1523 org-export-language-setup)
1524 (assoc "en" org-export-language-setup)))
1525 (email (plist-get info :email))
1526 (html-pre-real-contents
1527 (cond
1528 ((functionp (plist-get info :html-preamble))
1529 (with-temp-buffer
1530 (funcall (plist-get info :html-preamble))
1531 (buffer-string)))
1532 ((stringp (plist-get info :html-preamble))
1533 (format-spec (plist-get info :html-preamble)
1534 `((?t . ,title) (?a . ,author)
1535 (?d . ,date) (?e . ,email))))
1537 (format-spec
1538 (or (cadr (assoc (nth 0 lang-words)
1539 org-e-html-preamble-format))
1540 (cadr (assoc "en" org-e-html-preamble-format)))
1541 `((?t . ,title) (?a . ,author)
1542 (?d . ,date) (?e . ,email)))))))
1543 (when (not (equal html-pre-real-contents ""))
1544 (concat
1545 (format "
1546 <div id=\"%s\"> " (nth 0 org-e-html-divs))
1549 html-pre-real-contents
1551 </div>")))))
1553 (defun org-e-html-postamble (info)
1554 (concat
1555 (when (and (not body-only)
1556 (plist-get info :html-postamble))
1557 (let* ((html-post (plist-get info :html-postamble))
1558 (date (org-e-html-format-date info))
1559 (author (plist-get info :author))
1560 (email (plist-get info :email))
1561 (lang-words (or (assoc (plist-get info :language)
1562 org-export-language-setup)
1563 (assoc "en" org-export-language-setup)))
1564 (email
1565 (mapconcat (lambda(e)
1566 (format "<a href=\"mailto:%s\">%s</a>" e e))
1567 (split-string email ",+ *")
1568 ", "))
1569 (html-validation-link (or org-e-html-validation-link ""))
1570 (creator-info org-export-creator-string))
1571 (concat
1572 ;; begin postamble
1574 <div id=\"" (nth 2 org-e-html-divs) "\">"
1575 (cond
1576 ;; auto postamble
1577 ((eq (plist-get info :html-postamble) 'auto)
1578 (concat
1579 (when (plist-get info :time-stamp-file)
1580 (format "
1581 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words) date))
1582 (when (and (plist-get info :with-author) author)
1583 (format "
1584 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words) author))
1585 (when (and (plist-get info :with-email) email)
1586 (format "
1587 <p class=\"email\"> %s </p>" email))
1588 (when (plist-get info :with-creator)
1589 (format "
1590 <p class=\"creator\"> %s </p>" creator-info))
1591 html-validation-link "\n"))
1592 ;; postamble from a string
1593 ((stringp (plist-get info :html-postamble))
1594 (format-spec (plist-get info :html-postamble)
1595 `((?a . ,author) (?e . ,email)
1596 (?d . ,date) (?c . ,creator-info)
1597 (?v . ,html-validation-link))))
1599 ;; postamble from a function
1600 ((functionp (plist-get info :html-postamble))
1601 (with-temp-buffer
1602 (funcall (plist-get info :html-postamble))
1603 (buffer-string)))
1604 ;; default postamble
1606 (format-spec
1607 (or (cadr (assoc (nth 0 lang-words)
1608 org-e-html-postamble-format))
1609 (cadr (assoc "en" org-e-html-postamble-format)))
1610 `((?a . ,author) (?e . ,email)
1611 (?d . ,date) (?c . ,creator-info)
1612 (?v . ,html-validation-link)))))
1614 </div>")))
1615 ;; org-e-html-html-helper-timestamp
1618 (defun org-e-html-template (contents info)
1619 "Return complete document string after HTML conversion.
1620 CONTENTS is the transcoded contents string. RAW-DATA is the
1621 original parsed data. INFO is a plist holding export options."
1622 (concat
1623 (format
1624 (or (and (stringp org-e-html-xml-declaration)
1625 org-e-html-xml-declaration)
1626 (cdr (assoc (plist-get info :html-extension)
1627 org-e-html-xml-declaration))
1628 (cdr (assoc "html" org-e-html-xml-declaration))
1631 (or (and coding-system-for-write
1632 (fboundp 'coding-system-get)
1633 (coding-system-get coding-system-for-write
1634 'mime-charset))
1635 "iso-8859-1"))
1637 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1638 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1639 (format "
1640 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1641 (plist-get info :language) (plist-get info :language))
1643 <head>"
1644 (org-e-html-meta-info info) ; meta
1645 (org-e-html-style info) ; style
1646 (org-e-html-mathjax-config info) ; mathjax
1648 </head>"
1651 <body>"
1652 (let ((link-up (and (plist-get info :link-up)
1653 (string-match "\\S-" (plist-get info :link-up))
1654 (plist-get info :link-up)))
1655 (link-home (and (plist-get info :link-home)
1656 (string-match "\\S-" (plist-get info :link-home))
1657 (plist-get info :link-home))))
1658 (when (or link-up link-home)
1659 (format org-e-html-home/up-format
1660 (or link-up link-home)
1661 (or link-home link-up))))
1662 ;; preamble
1663 (org-e-html-preamble info)
1664 ;; begin content
1665 (format "
1666 <div id=\"%s\">" (or org-e-html-content-div
1667 (nth 1 org-e-html-divs)))
1668 ;; document title
1669 (format "
1670 <h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info :title) info))
1671 ;; table of contents
1672 (let ((depth (plist-get info :with-toc)))
1673 (when (wholenump depth) (org-e-html-toc depth info)))
1674 ;; document contents
1675 contents
1676 ;; footnotes section
1677 (org-e-html-footnote-section info)
1678 ;; bibliography
1679 (org-e-html-bibliography)
1680 ;; end content
1681 (unless body-only
1683 </div>")
1685 ;; postamble
1686 (org-e-html-postamble info)
1688 (unless body-only
1690 </body>")
1692 </html>"))
1696 ;;; Transcode Helpers
1698 ;;;; Todo
1700 (defun org-e-html--todo (todo)
1701 (when todo
1702 (format "<span class=\"%s %s%s\">%s</span>"
1703 (if (member todo org-done-keywords) "done" "todo")
1704 org-e-html-todo-kwd-class-prefix (org-e-html-fix-class-name todo)
1705 todo)))
1707 ;;;; Tags
1709 (defun org-e-html--tags (tags)
1710 (when tags
1711 (format "<span class=\"tag\">%s</span>"
1712 (mapconcat
1713 (lambda (tag)
1714 (format "<span class=\"%s\">%s</span>"
1715 (concat org-e-html-tag-class-prefix
1716 (org-e-html-fix-class-name tag))
1717 tag))
1718 (org-split-string tags ":") "&nbsp;"))))
1720 ;;;; Headline
1722 (defun* org-e-html-format-headline
1723 (todo todo-type priority text tags
1724 &key level section-number headline-label &allow-other-keys)
1725 (let ((section-number
1726 (when section-number
1727 (format "<span class=\"section-number-%d\">%s</span> "
1728 level section-number)))
1729 (todo (org-e-html--todo todo))
1730 (tags (org-e-html--tags tags)))
1731 (concat section-number todo (and todo " ") text
1732 (and tags "&nbsp;&nbsp;&nbsp;") tags)))
1734 ;;;; Src Code
1736 (defun org-e-html-fontify-code (code lang)
1737 (when code
1738 (cond
1739 ;; Case 1: No lang. Possibly an example block.
1740 ((not lang)
1741 ;; Simple transcoding.
1742 (org-e-html-encode-plain-text code))
1743 ;; Case 2: No htmlize or an inferior version of htmlize
1744 ((not (and (require 'htmlize nil t) (fboundp 'htmlize-region-for-paste)))
1745 ;; Emit a warning.
1746 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1747 ;; Simple transcoding.
1748 (org-e-html-encode-plain-text code))
1750 ;; Map language
1751 (setq lang (or (assoc-default lang org-src-lang-modes) lang))
1752 (let* ((lang-mode (and lang (intern (format "%s-mode" lang)))))
1753 (cond
1754 ;; Case 1: Language is not associated with any Emacs mode
1755 ((not (functionp lang-mode))
1756 ;; Simple transcoding.
1757 (org-e-html-encode-plain-text code))
1758 ;; Case 2: Default. Fotify code.
1760 ;; htmlize
1761 (setq code (with-temp-buffer
1762 (insert code)
1763 (funcall lang-mode)
1764 (font-lock-fontify-buffer)
1765 ;; markup each line separately
1766 (org-remove-formatting-on-newlines-in-region
1767 (point-min) (point-max))
1768 (org-src-mode)
1769 (set-buffer-modified-p nil)
1770 (org-export-e-htmlize-region-for-paste
1771 (point-min) (point-max))))
1772 ;; Strip any encolosing <pre></pre> tags
1773 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code)
1774 (match-string 1 code)
1775 code))))))))
1777 (defun org-e-html-do-format-code
1778 (code &optional lang refs retain-labels num-start textarea-p)
1779 (when textarea-p
1780 (setq num-start nil refs nil lang nil))
1781 (let* ((code-lines (org-split-string code "\n"))
1782 (code-length (length code-lines))
1783 (num-fmt
1784 (and num-start
1785 (format "%%%ds: "
1786 (length (number-to-string (+ code-length num-start))))))
1787 (code (org-e-html-fontify-code code lang)))
1788 (assert (= code-length (length (org-split-string code "\n"))))
1789 (org-export-format-code
1790 code
1791 (lambda (loc line-num ref)
1792 (setq loc
1793 (concat
1794 ;; Add line number, if needed.
1795 (when num-start
1796 (format "<span class=\"linenr\">%s</span>"
1797 (format num-fmt line-num)))
1798 ;; Transcoded src line.
1800 ;; Add label, if needed.
1801 (when (and ref retain-labels) (format " (%s)" ref))))
1802 ;; Mark transcoded line as an anchor, if needed.
1803 (if (not ref) loc
1804 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1805 ref loc)))
1806 num-start refs)))
1808 (defun org-e-html-format-code (element info)
1809 (let* ((lang (org-element-property :language element))
1810 ;; (switches (org-element-property :switches element))
1811 (switches nil) ; FIXME
1812 (textarea-p (and switches (string-match "-t\\>" switches)))
1813 ;; Extract code and references.
1814 (code-info (org-export-unravel-code element))
1815 (code (car code-info))
1816 (refs (cdr code-info))
1817 ;; Does the src block contain labels?
1818 (retain-labels (org-element-property :retain-labels element))
1819 ;; Does it have line numbers?
1820 (num-start (case (org-element-property :number-lines element)
1821 (continued (org-export-get-loc element info))
1822 (new 0))))
1823 (org-e-html-do-format-code
1824 code lang refs retain-labels num-start textarea-p)))
1828 ;;; Transcode Functions
1830 ;;;; Bold
1832 (defun org-e-html-bold (bold contents info)
1833 "Transcode BOLD from Org to HTML.
1834 CONTENTS is the text with bold markup. INFO is a plist holding
1835 contextual information."
1836 (format (or (cdr (assq 'bold org-e-html-text-markup-alist)) "%s")
1837 contents))
1840 ;;;; Center Block
1842 (defun org-e-html-center-block (center-block contents info)
1843 "Transcode a CENTER-BLOCK element from Org to HTML.
1844 CONTENTS holds the contents of the block. INFO is a plist
1845 holding contextual information."
1846 (org-e-html--wrap-label
1847 center-block
1848 (format "<div style=\"text-align: center\">\n%s</div>" contents)))
1851 ;;;; Clock
1853 (defun org-e-html-clock (clock contents info)
1854 "Transcode a CLOCK element from Org to HTML.
1855 CONTENTS is nil. INFO is a plist used as a communication
1856 channel."
1857 (format "<p>
1858 <span class=\"timestamp-wrapper\">
1859 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1860 </span>
1861 </p>"
1862 org-clock-string
1863 (org-translate-time (org-element-property :value clock))
1864 (let ((time (org-element-property :time clock)))
1865 (and time (format " <span class=\"timestamp\">(%s)</span>" time)))))
1868 ;;;; Code
1870 (defun org-e-html-code (code contents info)
1871 "Transcode CODE from Org to HTML.
1872 CONTENTS is nil. INFO is a plist holding contextual
1873 information."
1874 (format (or (cdr (assq 'code org-e-html-text-markup-alist)) "%s")
1875 (org-element-property :value code)))
1878 ;;;; Comment
1880 ;; Comments are ignored.
1883 ;;;; Comment Block
1885 ;; Comment Blocks are ignored.
1888 ;;;; Drawer
1890 (defun org-e-html-drawer (drawer contents info)
1891 "Transcode a DRAWER element from Org to HTML.
1892 CONTENTS holds the contents of the block. INFO is a plist
1893 holding contextual information."
1894 (let* ((name (org-element-property :drawer-name drawer))
1895 (output (if (functionp org-e-html-format-drawer-function)
1896 (funcall org-e-html-format-drawer-function
1897 name contents)
1898 ;; If there's no user defined function: simply
1899 ;; display contents of the drawer.
1900 contents)))
1901 (org-e-html--wrap-label drawer output)))
1904 ;;;; Dynamic Block
1906 (defun org-e-html-dynamic-block (dynamic-block contents info)
1907 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1908 CONTENTS holds the contents of the block. INFO is a plist
1909 holding contextual information. See `org-export-data'."
1910 (org-e-html--wrap-label dynamic-block contents))
1913 ;;;; Entity
1915 (defun org-e-html-entity (entity contents info)
1916 "Transcode an ENTITY object from Org to HTML.
1917 CONTENTS are the definition itself. INFO is a plist holding
1918 contextual information."
1919 (org-element-property :html entity))
1922 ;;;; Example Block
1924 (defun org-e-html-example-block (example-block contents info)
1925 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1926 CONTENTS is nil. INFO is a plist holding contextual information."
1927 (let* ((options (or (org-element-property :options example-block) ""))
1928 (lang (org-element-property :language example-block))
1929 (caption (org-element-property :caption example-block))
1930 (label (org-element-property :name example-block))
1931 (caption-str (org-e-html--caption/label-string caption label info))
1932 (attr (mapconcat #'identity
1933 (org-element-property :attr_html example-block)
1934 " "))
1935 ;; (switches (org-element-property :switches example-block))
1936 (switches nil) ; FIXME
1937 (textarea-p (and switches (string-match "-t\\>" switches)))
1938 (code (org-e-html-format-code example-block info)))
1939 (cond
1940 (textarea-p
1941 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
1942 80 (string-to-number (match-string 1 switches))))
1943 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
1944 (string-to-number (match-string 1 switches))
1945 (org-count-lines code))))
1946 (format
1947 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1948 cols rows code)))
1949 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
1952 ;;;; Export Snippet
1954 (defun org-e-html-export-snippet (export-snippet contents info)
1955 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1956 CONTENTS is nil. INFO is a plist holding contextual information."
1957 (when (eq (org-export-snippet-backend export-snippet) 'e-html)
1958 (org-element-property :value export-snippet)))
1961 ;;;; Export Block
1963 (defun org-e-html-export-block (export-block contents info)
1964 "Transcode a EXPORT-BLOCK element from Org to HTML.
1965 CONTENTS is nil. INFO is a plist holding contextual information."
1966 (when (string= (org-element-property :type export-block) "latex")
1967 (org-remove-indentation (org-element-property :value export-block))))
1970 ;;;; Fixed Width
1972 (defun org-e-html-fixed-width (fixed-width contents info)
1973 "Transcode a FIXED-WIDTH element from Org to HTML.
1974 CONTENTS is nil. INFO is a plist holding contextual information."
1975 (let* ((value (org-element-normalize-string
1976 (replace-regexp-in-string
1977 "^[ \t]*: ?" ""
1978 (org-element-property :value fixed-width)))))
1979 (org-e-html--wrap-label
1980 fixed-width (format "\n<pre class=\"example\">\n%s\n</pre>"
1981 (org-e-html-do-format-code value)))))
1984 ;;;; Footnote Definition
1986 ;; Footnote Definitions are ignored.
1989 ;;;; Footnote Reference
1991 (defun org-e-html-footnote-reference (footnote-reference contents info)
1992 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1993 CONTENTS is nil. INFO is a plist holding contextual information."
1994 (concat
1995 ;; Insert separator between two footnotes in a row.
1996 (let ((prev (org-export-get-previous-element footnote-reference info)))
1997 (when (eq (org-element-type prev) 'footnote-reference)
1998 org-e-html-footnote-separator))
1999 (cond
2000 ((not (org-export-footnote-first-reference-p footnote-reference info))
2001 (org-e-html-format-footnote-reference
2002 (org-export-get-footnote-number footnote-reference info)
2003 "IGNORED" 100))
2004 ;; Inline definitions are secondary strings.
2005 ((eq (org-element-property :type footnote-reference) 'inline)
2006 (org-e-html-format-footnote-reference
2007 (org-export-get-footnote-number footnote-reference info)
2008 "IGNORED" 1))
2009 ;; Non-inline footnotes definitions are full Org data.
2010 (t (org-e-html-format-footnote-reference
2011 (org-export-get-footnote-number footnote-reference info)
2012 "IGNORED" 1)))))
2015 ;;;; Headline
2017 (defun org-e-html-format-headline--wrap (headline info
2018 &optional format-function
2019 &rest extra-keys)
2020 "Transcode an HEADLINE element from Org to HTML.
2021 CONTENTS holds the contents of the headline. INFO is a plist
2022 holding contextual information."
2023 (let* ((level (+ (org-export-get-relative-level headline info)
2024 (1- org-e-html-toplevel-hlevel)))
2025 (headline-number (org-export-get-headline-number headline info))
2026 (section-number (and (org-export-numbered-headline-p headline info)
2027 (mapconcat 'number-to-string
2028 headline-number ".")))
2029 (todo (and (plist-get info :with-todo-keywords)
2030 (let ((todo (org-element-property :todo-keyword headline)))
2031 (and todo (org-export-data todo info)))))
2032 (todo-type (and todo (org-element-property :todo-type headline)))
2033 (priority (and (plist-get info :with-priority)
2034 (org-element-property :priority headline)))
2035 (text (org-export-data (org-element-property :title headline) info))
2036 (tags (and (plist-get info :with-tags)
2037 (org-element-property :tags headline)))
2038 (headline-label (concat "sec-" (mapconcat 'number-to-string
2039 headline-number "-")))
2040 (format-function (cond
2041 ((functionp format-function) format-function)
2042 ((functionp org-e-html-format-headline-function)
2043 (function*
2044 (lambda (todo todo-type priority text tags
2045 &allow-other-keys)
2046 (funcall org-e-html-format-headline-function
2047 todo todo-type priority text tags))))
2048 (t 'org-e-html-format-headline))))
2049 (apply format-function
2050 todo todo-type priority text tags
2051 :headline-label headline-label :level level
2052 :section-number section-number extra-keys)))
2054 (defun org-e-html-headline (headline contents info)
2055 "Transcode an HEADLINE element from Org to HTML.
2056 CONTENTS holds the contents of the headline. INFO is a plist
2057 holding contextual information."
2058 (let* ((numberedp (org-export-numbered-headline-p headline info))
2059 (level (org-export-get-relative-level headline info))
2060 (text (org-export-data (org-element-property :title headline) info))
2061 (todo (and (plist-get info :with-todo-keywords)
2062 (let ((todo (org-element-property :todo-keyword headline)))
2063 (and todo (org-export-data todo info)))))
2064 (todo-type (and todo (org-element-property :todo-type headline)))
2065 (tags (and (plist-get info :with-tags)
2066 (org-element-property :tags headline)))
2067 (priority (and (plist-get info :with-priority)
2068 (org-element-property :priority headline)))
2069 (section-number (and (org-export-numbered-headline-p headline info)
2070 (mapconcat 'number-to-string
2071 (org-export-get-headline-number
2072 headline info) ".")))
2073 ;; Create the headline text.
2074 (full-text (org-e-html-format-headline--wrap headline info)))
2075 (cond
2076 ;; Case 1: This is a footnote section: ignore it.
2077 ((org-element-property :footnote-section-p headline) nil)
2078 ;; Case 2. This is a deep sub-tree: export it as a list item.
2079 ;; Also export as items headlines for which no section
2080 ;; format has been found.
2081 ((org-export-low-level-p headline info) ; FIXME (or (not section-fmt))
2082 ;; Build the real contents of the sub-tree.
2083 (let* ((type (if numberedp 'unordered 'unordered)) ; FIXME
2084 (itemized-body (org-e-html-format-list-item
2085 contents type nil nil full-text)))
2086 (concat
2087 (and (org-export-first-sibling-p headline info)
2088 (org-e-html-begin-plain-list type))
2089 itemized-body
2090 (and (org-export-last-sibling-p headline info)
2091 (org-e-html-end-plain-list type)))))
2092 ;; Case 3. Standard headline. Export it as a section.
2094 (let* ((extra-class (org-element-property :html-container-class headline))
2095 (extra-ids (list (org-element-property :custom-id headline)
2096 (org-element-property :id headline)))
2097 (extra-ids
2098 (mapconcat
2099 (lambda (x)
2100 (when x
2101 (let ((id (org-solidify-link-text
2102 (if (org-uuidgen-p x) (concat "ID-" x) x))))
2103 (format "<a id=\"%s\" name=\"%s\"/>" id id))))
2104 extra-ids ""))
2105 (level1 (+ level (1- org-e-html-toplevel-hlevel)))
2106 (id (mapconcat 'number-to-string
2107 (org-export-get-headline-number headline info) "-")))
2108 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2109 (format "outline-container-%s" id)
2110 (concat (format "outline-%d" level1) (and extra-class " ")
2111 extra-class)
2112 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2113 level1 id extra-ids full-text level1)
2114 contents))))))
2117 ;;;; Horizontal Rule
2119 (defun org-e-html-horizontal-rule (horizontal-rule contents info)
2120 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2121 CONTENTS is nil. INFO is a plist holding contextual information."
2122 (let ((attr (mapconcat #'identity
2123 (org-element-property :attr_html horizontal-rule)
2124 " ")))
2125 (org-e-html--wrap-label horizontal-rule "<hr/>\n")))
2128 ;;;; Inline Babel Call
2130 ;; Inline Babel Calls are ignored.
2133 ;;;; Inline Src Block
2135 (defun org-e-html-inline-src-block (inline-src-block contents info)
2136 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2137 CONTENTS holds the contents of the item. INFO is a plist holding
2138 contextual information."
2139 (let* ((org-lang (org-element-property :language inline-src-block))
2140 (code (org-element-property :value inline-src-block))
2141 (separator (org-e-html--find-verb-separator code)))
2142 (error "FIXME")))
2145 ;;;; Inlinetask
2147 (defun org-e-html-format-section (text class &optional id)
2148 (let ((extra (concat (when id (format " id=\"%s\"" id)))))
2149 (concat (format "<div class=\"%s\"%s>\n" class extra) text "</div>\n")))
2151 (defun org-e-html-inlinetask (inlinetask contents info)
2152 "Transcode an INLINETASK element from Org to HTML.
2153 CONTENTS holds the contents of the block. INFO is a plist
2154 holding contextual information."
2155 (cond
2156 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2157 ;; with appropriate arguments.
2158 ((functionp org-e-html-format-inlinetask-function)
2159 (let ((format-function
2160 (function*
2161 (lambda (todo todo-type priority text tags
2162 &key contents &allow-other-keys)
2163 (funcall org-e-html-format-inlinetask-function
2164 todo todo-type priority text tags contents)))))
2165 (org-e-html-format-headline--wrap
2166 inlinetask info format-function :contents contents)))
2167 ;; Otherwise, use a default template.
2168 (t (org-e-html--wrap-label
2169 inlinetask
2170 (format
2171 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2172 (org-e-html-format-headline--wrap inlinetask info)
2173 contents)))))
2176 ;;;; Italic
2178 (defun org-e-html-italic (italic contents info)
2179 "Transcode ITALIC from Org to HTML.
2180 CONTENTS is the text with italic markup. INFO is a plist holding
2181 contextual information."
2182 (format (or (cdr (assq 'italic org-e-html-text-markup-alist)) "%s") contents))
2185 ;;;; Item
2187 (defun org-e-html-checkbox (checkbox)
2188 (case checkbox (on "<code>[X]</code>")
2189 (off "<code>[&nbsp;]</code>")
2190 (trans "<code>[-]</code>")
2191 (t "")))
2193 (defun org-e-html-format-list-item (contents type checkbox
2194 &optional term-counter-id
2195 headline)
2196 (concat
2197 (case type
2198 (ordered
2199 (let* ((counter term-counter-id)
2200 (extra (if counter (format " value=\"%s\"" counter) "")))
2201 (format "<li%s>" extra)))
2202 (unordered
2203 (let* ((id term-counter-id)
2204 (extra (if id (format " id=\"%s\"" id) "")))
2205 (concat
2206 (format "<li%s>" extra)
2207 (when headline (concat headline "<br/>")))))
2208 (descriptive
2209 (let* ((term term-counter-id))
2210 (setq term (or term "(no term)"))
2211 (concat (format "<dt> %s </dt>" term) "<dd>"))))
2212 (org-e-html-checkbox checkbox) (and checkbox " ")
2213 contents
2214 (case type
2215 (ordered "</li>")
2216 (unordered "</li>")
2217 (descriptive "</dd>"))))
2219 (defun org-e-html-item (item contents info)
2220 "Transcode an ITEM element from Org to HTML.
2221 CONTENTS holds the contents of the item. INFO is a plist holding
2222 contextual information."
2223 ;; Grab `:level' from plain-list properties, which is always the
2224 ;; first element above current item.
2225 (let* ((plain-list (org-export-get-parent item info))
2226 (type (org-element-property :type plain-list))
2227 (level (org-element-property :level plain-list))
2228 (counter (org-element-property :counter item))
2229 (checkbox (org-element-property :checkbox item))
2230 (tag (let ((tag (org-element-property :tag item)))
2231 (and tag (org-export-data tag info)))))
2232 (org-e-html-format-list-item
2233 contents type checkbox (or tag counter))))
2236 ;;;; Keyword
2238 (defun org-e-html-keyword (keyword contents info)
2239 "Transcode a KEYWORD element from Org to HTML.
2240 CONTENTS is nil. INFO is a plist holding contextual information."
2241 (let ((key (org-element-property :key keyword))
2242 (value (org-element-property :value keyword)))
2243 (cond
2244 ((string= key "LATEX") value)
2245 ((string= key "INDEX") (format "\\index{%s}" value))
2246 ;; Invisible targets.
2247 ((string= key "TARGET") nil) ; FIXME
2248 ((string= key "TOC")
2249 (let ((value (downcase value)))
2250 (cond
2251 ((string-match "\\<headlines\\>" value)
2252 (let ((depth (or (and (string-match "[0-9]+" value)
2253 (string-to-number (match-string 0 value)))
2254 (plist-get info :with-toc))))
2255 (when (wholenump depth) (org-e-html-toc depth info))))
2256 ((string= "tables" value) "\\listoftables")
2257 ((string= "figures" value) "\\listoffigures")
2258 ((string= "listings" value)
2259 (cond
2260 ;; At the moment, src blocks with a caption are wrapped
2261 ;; into a figure environment.
2262 (t "\\listoffigures")))))))))
2265 ;;;; Latex Environment
2267 (defun org-e-html-format-latex (latex-frag processing-type)
2268 (let* ((cache-relpath
2269 (concat "ltxpng/" (file-name-sans-extension
2270 (file-name-nondirectory (buffer-file-name)))))
2271 (cache-dir (file-name-directory (buffer-file-name )))
2272 (display-msg "Creating LaTeX Image..."))
2274 (with-temp-buffer
2275 (insert latex-frag)
2276 (org-format-latex cache-relpath cache-dir nil display-msg
2277 nil nil processing-type)
2278 (buffer-string))))
2280 (defun org-e-html-latex-environment (latex-environment contents info)
2281 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2282 CONTENTS is nil. INFO is a plist holding contextual information."
2283 (org-e-html--wrap-label
2284 latex-environment
2285 (let ((processing-type (plist-get info :LaTeX-fragments))
2286 (latex-frag (org-remove-indentation
2287 (org-element-property :value latex-environment)))
2288 (caption (org-e-html--caption/label-string
2289 (org-element-property :caption latex-environment)
2290 (org-element-property :name latex-environment)
2291 info))
2292 (attr nil) ; FIXME
2293 (label (org-element-property :name latex-environment)))
2294 (cond
2295 ((member processing-type '(t mathjax))
2296 (org-e-html-format-latex latex-frag 'mathjax))
2297 ((equal processing-type 'dvipng)
2298 (let* ((formula-link (org-e-html-format-latex
2299 latex-frag processing-type)))
2300 (when (and formula-link
2301 (string-match "file:\\([^]]*\\)" formula-link))
2302 (org-e-html-format-inline-image
2303 (match-string 1 formula-link) caption label attr t))))
2304 (t latex-frag)))))
2307 ;;;; Latex Fragment
2309 (defun org-e-html-latex-fragment (latex-fragment contents info)
2310 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2311 CONTENTS is nil. INFO is a plist holding contextual information."
2312 (let ((latex-frag (org-element-property :value latex-fragment))
2313 (processing-type (plist-get info :LaTeX-fragments)))
2314 (case processing-type
2315 ((t mathjax)
2316 (org-e-html-format-latex latex-frag 'mathjax))
2317 (dvipng
2318 (let* ((formula-link (org-e-html-format-latex
2319 latex-frag processing-type)))
2320 (when (and formula-link
2321 (string-match "file:\\([^]]*\\)" formula-link))
2322 (org-e-html-format-inline-image
2323 (match-string 1 formula-link)))))
2324 (t latex-frag))))
2326 ;;;; Line Break
2328 (defun org-e-html-line-break (line-break contents info)
2329 "Transcode a LINE-BREAK object from Org to HTML.
2330 CONTENTS is nil. INFO is a plist holding contextual information."
2331 "<br/>")
2334 ;;;; Link
2336 (defun org-e-html-link--inline-image (link desc info)
2337 "Return HTML code for an inline image.
2338 LINK is the link pointing to the inline image. INFO is a plist
2339 used as a communication channel."
2340 (let* ((type (org-element-property :type link))
2341 (raw-path (org-element-property :path link))
2342 (path (cond ((member type '("http" "https"))
2343 (concat type ":" raw-path))
2344 ((file-name-absolute-p raw-path)
2345 (expand-file-name raw-path))
2346 (t raw-path)))
2347 (parent (org-export-get-parent-paragraph link info))
2348 (caption (org-e-html--caption/label-string
2349 (org-element-property :caption parent)
2350 (org-element-property :name parent)
2351 info))
2352 (label (org-element-property :name parent))
2353 ;; Retrieve latex attributes from the element around.
2354 (attr (let ((raw-attr
2355 (mapconcat #'identity
2356 (org-element-property :attr_html parent)
2357 " ")))
2358 (unless (string= raw-attr "") raw-attr))))
2359 ;; Now clear ATTR from any special keyword and set a default
2360 ;; value if nothing is left.
2361 (setq attr (if (not attr) "" (org-trim attr)))
2362 ;; Return proper string, depending on DISPOSITION.
2363 (org-e-html-format-inline-image
2364 path caption label attr (org-e-html-standalone-image-p link info))))
2366 (defvar org-e-html-standalone-image-predicate)
2367 (defun org-e-html-standalone-image-p (element info &optional predicate)
2368 "Test if ELEMENT is a standalone image for the purpose HTML export.
2369 INFO is a plist holding contextual information.
2371 Return non-nil, if ELEMENT is of type paragraph and it's sole
2372 content, save for whitespaces, is a link that qualifies as an
2373 inline image.
2375 Return non-nil, if ELEMENT is of type link and it's containing
2376 paragraph has no other content save for leading and trailing
2377 whitespaces.
2379 Return nil, otherwise.
2381 Bind `org-e-html-standalone-image-predicate' to constrain
2382 paragraph further. For example, to check for only captioned
2383 standalone images, do the following.
2385 \(setq org-e-html-standalone-image-predicate
2386 \(lambda \(paragraph\)
2387 \(org-element-property :caption paragraph\)\)\)
2389 (let ((paragraph (case (org-element-type element)
2390 (paragraph element)
2391 (link (and (org-export-inline-image-p
2392 element org-e-html-inline-image-rules)
2393 (org-export-get-parent element info)))
2394 (t nil))))
2395 (when paragraph
2396 (assert (eq (org-element-type paragraph) 'paragraph))
2397 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate)
2398 (functionp org-e-html-standalone-image-predicate)))
2399 (funcall org-e-html-standalone-image-predicate paragraph))
2400 (let ((contents (org-element-contents paragraph)))
2401 (loop for x in contents
2402 with inline-image-count = 0
2403 always (cond
2404 ((eq (org-element-type x) 'plain-text)
2405 (not (org-string-nw-p x)))
2406 ((eq (org-element-type x) 'link)
2407 (when (org-export-inline-image-p
2408 x org-e-html-inline-image-rules)
2409 (= (incf inline-image-count) 1)))
2410 (t nil))))))))
2412 (defun org-e-html-link (link desc info)
2413 "Transcode a LINK object from Org to HTML.
2415 DESC is the description part of the link, or the empty string.
2416 INFO is a plist holding contextual information. See
2417 `org-export-data'."
2418 (let* ((type (org-element-property :type link))
2419 (raw-path (org-element-property :path link))
2420 ;; Ensure DESC really exists, or set it to nil.
2421 (desc (and (not (string= desc "")) desc))
2422 (path (cond
2423 ((member type '("http" "https" "ftp" "mailto"))
2424 (concat type ":" raw-path))
2425 ((string= type "file")
2426 (when (string-match "\\(.+\\)::.+" raw-path)
2427 (setq raw-path (match-string 1 raw-path)))
2428 (if (file-name-absolute-p raw-path)
2429 (concat "file://" (expand-file-name raw-path))
2430 ;; TODO: Not implemented yet. Concat also:
2431 ;; (org-export-directory :HTML info)
2432 (concat "file://" raw-path)))
2433 (t raw-path)))
2434 protocol)
2435 (cond
2436 ;; Image file.
2437 ((and (or (eq t org-e-html-inline-images)
2438 (and org-e-html-inline-images (not desc)))
2439 (org-export-inline-image-p link org-e-html-inline-image-rules))
2440 (org-e-html-link--inline-image link desc info))
2441 ;; Radioed target: Target's name is obtained from original raw
2442 ;; link. Path is parsed and transcoded in order to have a proper
2443 ;; display of the contents.
2444 ((string= type "radio")
2445 (format "<a href=\"#%s\">%s</a>"
2446 (org-export-solidify-link-text path)
2447 (org-export-data
2448 (org-element-parse-secondary-string
2449 path (org-element-restriction 'radio-target))
2450 info)))
2451 ;; Links pointing to an headline: Find destination and build
2452 ;; appropriate referencing command.
2453 ((member type '("custom-id" "fuzzy" "id"))
2454 (let ((destination (if (string= type "fuzzy")
2455 (org-export-resolve-fuzzy-link link info)
2456 (org-export-resolve-id-link link info))))
2457 (case (org-element-type destination)
2458 ;; Fuzzy link points nowhere.
2459 ('nil
2460 (format "<i>%s</i>"
2461 (or desc
2462 (org-export-data
2463 (org-element-property :raw-link link) info))))
2464 ;; Fuzzy link points to an invisible target.
2465 (keyword nil)
2466 ;; LINK points to an headline. If headlines are numbered
2467 ;; and the link has no description, display headline's
2468 ;; number. Otherwise, display description or headline's
2469 ;; title.
2470 (headline
2471 (let* ((headline-no (org-export-get-headline-number destination info))
2472 (label (format "sec-%s" (mapconcat 'number-to-string
2473 headline-no "-")))
2474 (section-no (mapconcat 'number-to-string headline-no ".")))
2475 (setq desc
2476 (cond
2477 (desc desc)
2478 ((plist-get info :section-numbers) section-no)
2479 (t (org-export-data
2480 (org-element-property :title destination) info))))
2481 (format "<a href=\"#%s\">%s</a>" label desc)))
2482 ;; Fuzzy link points to a target. Do as above.
2483 (otherwise
2484 (let ((path (org-export-solidify-link-text path)) number)
2485 (unless desc
2486 (setq number (cond
2487 ((org-e-html-standalone-image-p destination info)
2488 (org-export-get-ordinal
2489 (assoc 'link (org-element-contents destination))
2490 info 'link 'org-e-html-standalone-image-p))
2491 (t (org-export-get-ordinal destination info))))
2492 (setq desc (when number
2493 (if (atom number) (number-to-string number)
2494 (mapconcat 'number-to-string number ".")))))
2495 (format "<a href=\"#%s\">%s</a>" path (or desc "FIXME")))))))
2496 ;; Coderef: replace link with the reference name or the
2497 ;; equivalent line number.
2498 ((string= type "coderef")
2499 (let ((fragment (concat "coderef-" path)))
2500 (format "<a href=\"#%s\" %s>%s</a>" fragment
2501 (format (concat "class=\"coderef\""
2502 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2503 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2504 fragment fragment)
2505 (format (org-export-get-coderef-format path desc)
2506 (org-export-resolve-coderef path info)))))
2507 ;; Link type is handled by a special function.
2508 ((functionp (setq protocol (nth 2 (assoc type org-link-protocols))))
2509 (funcall protocol (org-link-unescape path) desc 'html))
2510 ;; External link with a description part.
2511 ((and path desc) (format "<a href=\"%s\">%s</a>" path desc))
2512 ;; External link without a description part.
2513 (path (format "<a href=\"%s\">%s</a>" path path))
2514 ;; No path, only description. Try to do something useful.
2515 (t (format "<i>%s</i>" desc)))))
2518 ;;;; Babel Call
2520 ;; Babel Calls are ignored.
2523 ;;;; Macro
2525 (defun org-e-html-macro (macro contents info)
2526 "Transcode a MACRO element from Org to HTML.
2527 CONTENTS is nil. INFO is a plist holding contextual information."
2528 ;; Use available tools.
2529 (org-export-expand-macro macro info))
2532 ;;;; Paragraph
2534 (defun org-e-html-paragraph (paragraph contents info)
2535 "Transcode a PARAGRAPH element from Org to HTML.
2536 CONTENTS is the contents of the paragraph, as a string. INFO is
2537 the plist used as a communication channel."
2538 (let* ((style nil) ; FIXME
2539 (class (cdr (assoc style '((footnote . "footnote")
2540 (verse . nil)))))
2541 (extra (if class (format " class=\"%s\"" class) ""))
2542 (parent (org-export-get-parent paragraph info)))
2543 (cond
2544 ((and (equal (car parent) 'item)
2545 (= (org-element-property :begin paragraph)
2546 (org-element-property :contents-begin parent)))
2547 ;; leading paragraph in a list item have no tags
2548 contents)
2549 ((org-e-html-standalone-image-p paragraph info)
2550 ;; standalone image
2551 contents)
2552 (t (format "\n<p%s>\n%s\n</p>" extra contents)))))
2555 ;;;; Plain List
2557 (defun org-e-html-begin-plain-list (type &optional arg1)
2558 (case type
2559 (ordered
2560 (format "<ol%s>" (if arg1 ; FIXME
2561 (format " start=\"%d\"" arg1)
2562 "")))
2563 (unordered "<ul>")
2564 (descriptive "<dl>")))
2566 (defun org-e-html-end-plain-list (type)
2567 (case type
2568 (ordered "</ol>")
2569 (unordered "</ul>")
2570 (descriptive "</dl>")))
2572 (defun org-e-html-plain-list (plain-list contents info)
2573 "Transcode a PLAIN-LIST element from Org to HTML.
2574 CONTENTS is the contents of the list. INFO is a plist holding
2575 contextual information."
2576 (let* (arg1 ;; FIXME
2577 (type (org-element-property :type plain-list))
2578 (attr (mapconcat #'identity
2579 (org-element-property :attr_html plain-list)
2580 " ")))
2581 (org-e-html--wrap-label
2582 plain-list (format "%s\n%s%s"
2583 (org-e-html-begin-plain-list type)
2584 contents (org-e-html-end-plain-list type)))))
2586 ;;;; Plain Text
2588 (defun org-e-html-convert-special-strings (string)
2589 "Convert special characters in STRING to HTML."
2590 (let ((all org-e-html-special-string-regexps)
2591 e a re rpl start)
2592 (while (setq a (pop all))
2593 (setq re (car a) rpl (cdr a) start 0)
2594 (while (string-match re string start)
2595 (setq string (replace-match rpl t nil string))))
2596 string))
2598 (defun org-e-html-encode-plain-text (s)
2599 "Convert plain text characters to HTML equivalent.
2600 Possible conversions are set in `org-export-html-protect-char-alist'."
2601 (let ((cl org-e-html-protect-char-alist) c)
2602 (while (setq c (pop cl))
2603 (let ((start 0))
2604 (while (string-match (car c) s start)
2605 (setq s (replace-match (cdr c) t t s)
2606 start (1+ (match-beginning 0))))))
2609 (defun org-e-html-plain-text (text info)
2610 "Transcode a TEXT string from Org to HTML.
2611 TEXT is the string to transcode. INFO is a plist holding
2612 contextual information."
2613 (setq text (org-e-html-encode-plain-text text))
2614 ;; Protect %, #, &, $, ~, ^, _, { and }.
2615 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2616 ;; (setq text
2617 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2618 ;; Protect \
2619 ;; (setq text (replace-regexp-in-string
2620 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2621 ;; "$\\backslash$" text nil t 1))
2622 ;; HTML into \HTML{} and TeX into \TeX{}.
2623 ;; (let ((case-fold-search nil)
2624 ;; (start 0))
2625 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2626 ;; (setq text (replace-match
2627 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2628 ;; start (match-end 0))))
2629 ;; Handle quotation marks
2630 ;; (setq text (org-e-html--quotation-marks text info))
2631 ;; Convert special strings.
2632 ;; (when (plist-get info :with-special-strings)
2633 ;; (while (string-match (regexp-quote "...") text)
2634 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2635 (when (plist-get info :with-special-strings)
2636 (setq text (org-e-html-convert-special-strings text)))
2637 ;; Handle break preservation if required.
2638 (when (plist-get info :preserve-breaks)
2639 (setq text (replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2640 text)))
2641 ;; Return value.
2642 text)
2645 ;; Planning
2647 (defun org-e-html-planning (planning contents info)
2648 "Transcode a PLANNING element from Org to HTML.
2649 CONTENTS is nil. INFO is a plist used as a communication
2650 channel."
2651 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2652 (format
2653 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2654 (mapconcat
2655 'identity
2656 (delq nil
2657 (list
2658 (let ((closed (org-element-property :closed planning)))
2659 (when closed
2660 (format span-fmt org-closed-string
2661 (org-translate-time closed))))
2662 (let ((deadline (org-element-property :deadline planning)))
2663 (when deadline
2664 (format span-fmt org-deadline-string
2665 (org-translate-time deadline))))
2666 (let ((scheduled (org-element-property :scheduled planning)))
2667 (when scheduled
2668 (format span-fmt org-scheduled-string
2669 (org-translate-time scheduled))))))
2670 " "))))
2673 ;;;; Property Drawer
2675 (defun org-e-html-property-drawer (property-drawer contents info)
2676 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2677 CONTENTS is nil. INFO is a plist holding contextual
2678 information."
2679 ;; The property drawer isn't exported but we want separating blank
2680 ;; lines nonetheless.
2684 ;;;; Quote Block
2686 (defun org-e-html-quote-block (quote-block contents info)
2687 "Transcode a QUOTE-BLOCK element from Org to HTML.
2688 CONTENTS holds the contents of the block. INFO is a plist
2689 holding contextual information."
2690 (org-e-html--wrap-label
2691 quote-block (format "<blockquote>\n%s</blockquote>" contents)))
2694 ;;;; Quote Section
2696 (defun org-e-html-quote-section (quote-section contents info)
2697 "Transcode a QUOTE-SECTION element from Org to HTML.
2698 CONTENTS is nil. INFO is a plist holding contextual information."
2699 (let ((value (org-remove-indentation
2700 (org-element-property :value quote-section))))
2701 (when value (format "<pre>\n%s</pre>" value))))
2704 ;;;; Section
2706 (defun org-e-html-section (section contents info) ; FIXME
2707 "Transcode a SECTION element from Org to HTML.
2708 CONTENTS holds the contents of the section. INFO is a plist
2709 holding contextual information."
2710 (let ((parent (org-export-get-parent-headline section info)))
2711 ;; Before first headline: no container, just return CONTENTS.
2712 (if (not parent) contents
2713 ;; Get div's class and id references.
2714 (let ((class-num (+ (org-export-get-relative-level parent info)
2715 (1- org-e-html-toplevel-hlevel)))
2716 (id-num
2717 (mapconcat
2718 'number-to-string
2719 (org-export-get-headline-number parent info) "-")))
2720 ;; Build return value.
2721 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2722 class-num id-num contents)))))
2724 ;;;; Radio Target
2726 (defun org-e-html-radio-target (radio-target text info)
2727 "Transcode a RADIO-TARGET object from Org to HTML.
2728 TEXT is the text of the target. INFO is a plist holding
2729 contextual information."
2730 (let ((id (org-export-solidify-link-text
2731 (org-element-property :value radio-target))))
2732 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text)))
2735 ;;;; Special Block
2737 (defun org-e-html-special-block (special-block contents info)
2738 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2739 CONTENTS holds the contents of the block. INFO is a plist
2740 holding contextual information."
2741 (let ((type (downcase (org-element-property :type special-block))))
2742 (org-e-html--wrap-label
2743 special-block
2744 (format "\\begin{%s}\n%s\\end{%s}" type contents type))))
2747 ;;;; Src Block
2749 (defun org-e-html-src-block (src-block contents info)
2750 "Transcode a SRC-BLOCK element from Org to HTML.
2751 CONTENTS holds the contents of the item. INFO is a plist holding
2752 contextual information."
2753 (let* ((lang (org-element-property :language src-block))
2754 (caption (org-element-property :caption src-block))
2755 (label (org-element-property :name src-block))
2756 (caption-str (org-e-html--caption/label-string caption label info))
2757 (attr (mapconcat #'identity
2758 (org-element-property :attr_html src-block)
2759 " "))
2760 ;; (switches (org-element-property :switches src-block))
2761 (switches nil) ; FIXME
2762 (textarea-p (and switches (string-match "-t\\>" switches)))
2763 (code (org-e-html-format-code src-block info)))
2764 (cond
2765 (lang (format
2766 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2767 (if (not caption) ""
2768 (format "<label class=\"org-src-name\">%s</label>" caption-str))
2769 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code)))
2770 (textarea-p
2771 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches))
2772 80 (string-to-number (match-string 1 switches))))
2773 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches)
2774 (string-to-number (match-string 1 switches))
2775 (org-count-lines code))))
2776 (format
2777 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2778 cols rows code)))
2779 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code)))))
2781 ;;;; Statistics Cookie
2783 (defun org-e-html-statistics-cookie (statistics-cookie contents info)
2784 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2785 CONTENTS is nil. INFO is a plist holding contextual information."
2786 (let ((cookie-value (org-element-property :value statistics-cookie)))
2787 (format "<code>%s</code>" cookie-value)))
2790 ;;;; Strike-Through
2792 (defun org-e-html-strike-through (strike-through contents info)
2793 "Transcode STRIKE-THROUGH from Org to HTML.
2794 CONTENTS is the text with strike-through markup. INFO is a plist
2795 holding contextual information."
2796 (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist)) "%s")
2797 contents))
2800 ;;;; Subscript
2802 (defun org-e-html-subscript (subscript contents info)
2803 "Transcode a SUBSCRIPT object from Org to HTML.
2804 CONTENTS is the contents of the object. INFO is a plist holding
2805 contextual information."
2806 (format "<sub>%s</sub>" contents))
2809 ;;;; Superscript
2811 (defun org-e-html-superscript (superscript contents info)
2812 "Transcode a SUPERSCRIPT object from Org to HTML.
2813 CONTENTS is the contents of the object. INFO is a plist holding
2814 contextual information."
2815 (format "<sup>%s</sup>" contents))
2818 ;;;; Tabel Cell
2820 (defun org-e-html-table-cell (table-cell contents info)
2821 "Transcode a TABLE-CELL element from Org to HTML.
2822 CONTENTS is nil. INFO is a plist used as a communication
2823 channel."
2824 (let* ((table-row (org-export-get-parent table-cell info))
2825 (table (org-export-get-parent-table table-cell info))
2826 (cell-attrs
2827 (if (not org-e-html-table-align-individual-fields) ""
2828 (format (if (and (boundp 'org-e-html-format-table-no-css)
2829 org-e-html-format-table-no-css)
2830 " align=\"%s\"" " class=\"%s\"")
2831 (org-export-table-cell-alignment table-cell info)))))
2832 (when (or (not contents) (string= "" (org-trim contents)))
2833 (setq contents "&nbsp;"))
2834 (cond
2835 ((and (org-export-table-has-header-p table info)
2836 (= 1 (org-export-table-row-group table-row info)))
2837 (concat "\n" (format (car org-e-html-table-header-tags) "col" cell-attrs)
2838 contents (cdr org-e-html-table-header-tags)))
2839 ((and org-e-html-table-use-header-tags-for-first-column
2840 (zerop (cdr (org-export-table-cell-address table-cell info))))
2841 (concat "\n" (format (car org-e-html-table-header-tags) "row" cell-attrs)
2842 contents (cdr org-e-html-table-header-tags)))
2843 (t (concat "\n" (format (car org-e-html-table-data-tags) cell-attrs)
2844 contents (cdr org-e-html-table-data-tags))))))
2847 ;;;; Table Row
2849 (defun org-e-html-table-row (table-row contents info)
2850 "Transcode a TABLE-ROW element from Org to HTML.
2851 CONTENTS is the contents of the row. INFO is a plist used as a
2852 communication channel."
2853 ;; Rules are ignored since table separators are deduced from
2854 ;; borders of the current row.
2855 (when (eq (org-element-property :type table-row) 'standard)
2856 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info)))
2857 (rowgroup-tags
2858 (cond
2859 ;; Case 1: Row belongs to second or subsequent rowgroups.
2860 ((not (= 1 (org-export-table-row-group table-row info)))
2861 '("\n<tbody>" . "\n</tbody>"))
2862 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2863 ((org-export-table-has-header-p
2864 (org-export-get-parent-table table-row info) info)
2865 '("\n<thead>" . "\n</thead>"))
2866 ;; Case 2: Row is from first and only row group.
2867 (t '("\n<tbody>" . "\n</tbody>")))))
2868 (concat
2869 ;; Begin a rowgroup?
2870 (when (org-export-table-row-starts-rowgroup-p table-row info)
2871 (car rowgroup-tags))
2872 ;; Actual table row
2873 (concat "\n" (eval (car org-e-html-table-row-tags))
2874 contents (eval (cdr org-e-html-table-row-tags)))
2875 ;; End a rowgroup?
2876 (when (org-export-table-row-ends-rowgroup-p table-row info)
2877 (cdr rowgroup-tags))))))
2880 ;;;; Table
2882 (defun org-e-html-table-first-row-data-cells (table info)
2883 (let ((table-row
2884 (org-element-map
2885 table 'table-row
2886 (lambda (row)
2887 (unless (eq (org-element-property :type row) 'rule) row))
2888 info 'first-match))
2889 (special-column-p (org-export-table-has-special-column-p table)))
2890 (if (not special-column-p) (org-element-contents table-row)
2891 (cdr (org-element-contents table-row)))))
2893 (defun org-e-html-table--table.el-table (table info)
2894 (when (eq (org-element-property :type table) 'table.el)
2895 (require 'table)
2896 (let ((outbuf (with-current-buffer
2897 (get-buffer-create "*org-export-table*")
2898 (erase-buffer) (current-buffer))))
2899 (with-temp-buffer
2900 (insert (org-element-property :value table))
2901 (goto-char 1)
2902 (re-search-forward "^[ \t]*|[^|]" nil t)
2903 (table-generate-source 'html outbuf))
2904 (with-current-buffer outbuf
2905 (prog1 (org-trim (buffer-string))
2906 (kill-buffer) )))))
2908 (defun org-e-html-table (table contents info)
2909 "Transcode a TABLE element from Org to HTML.
2910 CONTENTS is nil. INFO is a plist holding contextual information."
2911 (case (org-element-property :type table)
2912 ;; Case 1: table.el table. Convert it using appropriate tools.
2913 (table.el (org-e-html-table--table.el-table table info))
2914 ;; Case 2: Standard table.
2916 (let* ((label (org-element-property :name table))
2917 (caption (org-e-html--caption/label-string
2918 (org-element-property :caption table) label info))
2919 (attributes (mapconcat #'identity
2920 (org-element-property :attr_html table)
2921 " "))
2922 (alignspec
2923 (if (and (boundp 'org-e-html-format-table-no-css)
2924 org-e-html-format-table-no-css)
2925 "align=\"%s\"" "class=\"%s\""))
2926 (table-column-specs
2927 (function
2928 (lambda (table info)
2929 (mapconcat
2930 (lambda (table-cell)
2931 (let ((alignment (org-export-table-cell-alignment
2932 table-cell info)))
2933 (concat
2934 ;; Begin a colgroup?
2935 (when (org-export-table-cell-starts-colgroup-p
2936 table-cell info)
2937 "\n<colgroup>")
2938 ;; Add a column. Also specify it's alignment.
2939 (format "\n<col %s/>" (format alignspec alignment))
2940 ;; End a colgroup?
2941 (when (org-export-table-cell-ends-colgroup-p
2942 table-cell info)
2943 "\n</colgroup>"))))
2944 (org-e-html-table-first-row-data-cells table info) "\n"))))
2945 (table-attributes
2946 (let ((table-tag (plist-get info :html-table-tag)))
2947 (concat
2948 (and (string-match "<table\\(.*\\)>" table-tag)
2949 (match-string 1 table-tag))
2950 (and label (format " id=\"%s\""
2951 (org-solidify-link-text label)))))))
2952 ;; Remove last blank line.
2953 (setq contents (substring contents 0 -1))
2954 ;; FIXME: splice
2955 (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
2956 table-attributes
2957 (or caption "")
2958 (funcall table-column-specs table info)
2959 contents)))))
2961 ;;;; Target
2963 (defun org-e-html-target (target contents info)
2964 "Transcode a TARGET object from Org to HTML.
2965 CONTENTS is nil. INFO is a plist holding contextual
2966 information."
2967 (let ((id (org-export-solidify-link-text
2968 (org-element-property :value target))))
2969 (format "<a id=\"%s\" name=\"%s\"/>" id id)))
2972 ;;;; Timestamp
2974 (defun org-e-html-timestamp (timestamp contents info)
2975 "Transcode a TIMESTAMP object from Org to HTML.
2976 CONTENTS is nil. INFO is a plist holding contextual
2977 information."
2978 (let ((value (org-translate-time (org-element-property :value timestamp))))
2979 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2980 value)))
2983 ;;;; Underline
2985 (defun org-e-html-underline (underline contents info)
2986 "Transcode UNDERLINE from Org to HTML.
2987 CONTENTS is the text with underline markup. INFO is a plist
2988 holding contextual information."
2989 (format (or (cdr (assq 'underline org-e-html-text-markup-alist)) "%s")
2990 contents))
2993 ;;;; Verbatim
2995 (defun org-e-html-verbatim (verbatim contents info)
2996 "Transcode VERBATIM from Org to HTML.
2997 CONTENTS is nil. INFO is a plist holding contextual
2998 information."
2999 (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist)) "%s")
3000 (org-element-property :value verbatim)))
3003 ;;;; Verse Block
3005 (defun org-e-html-verse-block (verse-block contents info)
3006 "Transcode a VERSE-BLOCK element from Org to HTML.
3007 CONTENTS is verse block contents. INFO is a plist holding
3008 contextual information."
3009 ;; Replace each newline character with line break. Also replace
3010 ;; each blank line with a line break.
3011 (setq contents (replace-regexp-in-string
3012 "^ *\\\\\\\\$" "<br/>\n"
3013 (replace-regexp-in-string
3014 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents)))
3015 ;; Replace each white space at beginning of a line with a
3016 ;; non-breaking space.
3017 (while (string-match "^[ \t]+" contents)
3018 (let* ((num-ws (length (match-string 0 contents)))
3019 (ws (let (out) (dotimes (i num-ws out)
3020 (setq out (concat out "&nbsp;"))))))
3021 (setq contents (replace-match ws nil t contents))))
3022 (org-e-html--wrap-label
3023 verse-block (format "<p class=\"verse\">\n%s</p>" contents)))
3028 ;;; Filter Functions
3030 ;;;; Filter Settings
3032 (defconst org-e-html-filters-alist
3033 '((:filter-final-output . org-e-html-final-function))
3034 "Alist between filters keywords and back-end specific filters.
3035 See `org-export-filters-alist' for more information.")
3038 ;;;; Filters
3040 (defun org-e-html-final-function (contents backend info)
3041 (if (not org-e-html-pretty-output) contents
3042 (with-temp-buffer
3043 (nxml-mode)
3044 (insert contents)
3045 (indent-region (point-min) (point-max))
3046 (buffer-substring-no-properties (point-min) (point-max)))))
3049 ;;; Interactive functions
3051 (defun org-e-html-export-to-html
3052 (&optional subtreep visible-only body-only ext-plist pub-dir)
3053 "Export current buffer to a HTML file.
3055 If narrowing is active in the current buffer, only export its
3056 narrowed part.
3058 If a region is active, export that region.
3060 When optional argument SUBTREEP is non-nil, export the sub-tree
3061 at point, extracting information from the headline properties
3062 first.
3064 When optional argument VISIBLE-ONLY is non-nil, don't export
3065 contents of hidden elements.
3067 When optional argument BODY-ONLY is non-nil, only write code
3068 between \"\\begin{document}\" and \"\\end{document}\".
3070 EXT-PLIST, when provided, is a property list with external
3071 parameters overriding Org default settings, but still inferior to
3072 file-local settings.
3074 When optional argument PUB-DIR is set, use it as the publishing
3075 directory.
3077 Return output file's name."
3078 (interactive)
3079 (setq debug-on-error t) ; FIXME
3080 (let* ((extension (concat "." org-e-html-extension))
3081 (file (org-export-output-file-name extension subtreep pub-dir)))
3082 (org-export-to-file
3083 'e-html file subtreep visible-only body-only ext-plist)))
3087 ;;; FIXMES, TODOS, FOR REVIEW etc
3089 ;;;; org-format-table-html
3090 ;;;; org-format-org-table-html
3091 ;;;; org-format-table-table-html
3092 ;;;; org-table-number-fraction
3093 ;;;; org-table-number-regexp
3094 ;;;; org-e-html-table-caption-above
3096 ;;;; org-whitespace
3097 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3098 ;;;; Remove display properties
3100 ;;;; org-e-html-with-timestamp
3101 ;;;; org-e-html-html-helper-timestamp
3103 ;;;; org-export-as-html-and-open
3104 ;;;; org-export-as-html-batch
3105 ;;;; org-export-as-html-to-buffer
3106 ;;;; org-replace-region-by-html
3107 ;;;; org-export-region-as-html
3108 ;;;; org-export-as-html
3110 ;;;; (org-export-directory :html opt-plist)
3111 ;;;; (plist-get opt-plist :html-extension)
3112 ;;;; org-e-html-toplevel-hlevel
3113 ;;;; org-e-html-special-string-regexps
3114 ;;;; org-e-html-coding-system
3115 ;;;; org-e-html-coding-system
3116 ;;;; org-e-html-inline-images
3117 ;;;; org-e-html-inline-image-extensions
3118 ;;;; org-e-html-protect-char-alist
3119 ;;;; org-e-html-table-use-header-tags-for-first-column
3120 ;;;; org-e-html-todo-kwd-class-prefix
3121 ;;;; org-e-html-tag-class-prefix
3122 ;;;; org-e-html-footnote-separator
3124 ;;;; org-export-preferred-target-alist
3125 ;;;; org-solidify-link-text
3126 ;;;; class for anchors
3127 ;;;; org-export-with-section-numbers, body-only
3128 ;;;; org-export-mark-todo-in-toc
3130 (provide 'org-e-html)
3131 ;;; org-e-html.el ends here