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/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
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.
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-clean-table
"org-export" (table specialp
))
53 (declare-function org-export-data
"org-export" (data backend info
))
54 (declare-function org-export-directory
"org-export" (type plist
))
55 (declare-function org-export-expand-macro
"org-export" (macro info
))
56 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
57 (declare-function org-export-footnote-first-reference-p
"org-export"
58 (footnote-reference info
))
59 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
60 (declare-function org-export-get-footnote-definition
"org-export"
61 (footnote-reference info
))
62 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
63 (declare-function org-export-get-previous-element
"org-export" (blob info
))
64 (declare-function org-export-get-relative-level
"org-export" (headline info
))
65 (declare-function org-export-handle-code
66 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
67 (declare-function org-export-included-file
"org-export" (keyword backend info
))
68 (declare-function org-export-inline-image-p
"org-export"
69 (link &optional extensions
))
70 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
71 (declare-function org-export-low-level-p
"org-export" (headline info
))
72 (declare-function org-export-output-file-name
73 "org-export" (extension &optional subtreep pub-dir
))
74 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
75 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
76 (declare-function org-export-secondary-string
"org-export"
77 (secondary backend info
))
78 (declare-function org-export-solidify-link-text
"org-export" (s))
79 (declare-function org-export-table-format-info
"org-export" (table))
81 org-export-to-buffer
"org-export"
82 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
84 org-export-to-file
"org-export"
85 (backend file
&optional subtreep visible-only body-only ext-plist
))
87 (declare-function org-id-find-id-file
"org-id" (id))
88 (declare-function htmlize-region
"ext:htmlize" (beg end
))
89 (declare-function org-pop-to-buffer-same-window
90 "org-compat" (&optional buffer-or-name norecord label
))
95 ;;; Internal Variables
97 (defconst org-e-html-option-alist
98 '((:agenda-style nil nil org-agenda-export-html-style
)
99 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
100 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
101 ;; (:expand-quoted-html nil "@" org-e-html-expand)
102 (:inline-images nil nil org-e-html-inline-images
)
103 ;; (:link-home nil nil org-e-html-link-home) FIXME
104 ;; (:link-up nil nil org-e-html-link-up) FIXME
105 (:style nil nil org-e-html-style
)
106 (:style-extra nil nil org-e-html-style-extra
)
107 (:style-include-default nil nil org-e-html-style-include-default
)
108 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
109 ;; (:timestamp nil nil org-e-html-with-timestamp)
110 (:html-extension nil nil org-e-html-extension
)
111 (:html-postamble nil nil org-e-html-postamble
)
112 (:html-preamble nil nil org-e-html-preamble
)
113 (:html-table-tag nil nil org-e-html-table-tag
)
114 (:xml-declaration nil nil org-e-html-xml-declaration
)
115 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
116 (:mathjax
"MATHJAX" nil
"" space
))
117 "Alist between export properties and ways to set them.
119 The car of the alist is the property name, and the cdr is a list
120 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
122 KEYWORD is a string representing a buffer keyword, or nil.
123 OPTION is a string that could be found in an #+OPTIONS: line.
124 DEFAULT is the default value for the property.
125 BEHAVIOUR determine how Org should handle multiple keywords for
126 the same property. It is a symbol among:
127 nil Keep old value and discard the new one.
128 t Replace old value with the new one.
129 `space' Concatenate the values, separating them with a space.
130 `newline' Concatenate the values, separating them with
132 `split' Split values at white spaces, and cons them to the
135 KEYWORD and OPTION have precedence over DEFAULT.
137 All these properties should be back-end agnostic. For back-end
138 specific properties, define a similar variable named
139 `org-BACKEND-option-alist', replacing BACKEND with the name of
140 the appropriate back-end. You can also redefine properties
141 there, as they have precedence over these.")
143 (defvar html-table-tag nil
) ; dynamically scoped into this.
145 ;; FIXME: it already exists in org-e-html.el
146 (defconst org-e-html-cvt-link-fn
148 "Function to convert link URLs to exportable URLs.
149 Takes two arguments, TYPE and PATH.
150 Returns exportable url as (TYPE PATH), or nil to signal that it
151 didn't handle this case.
152 Intended to be locally bound around a call to `org-export-as-html'." )
157 (defvar org-e-html-format-table-no-css
)
158 (defvar htmlize-buffer-places
) ; from htmlize.el
159 (defvar body-only
) ; dynamically scoped into this.
161 (defvar org-e-html-table-rowgrp-open
)
162 (defvar org-e-html-table-rownum
)
163 (defvar org-e-html-table-cur-rowgrp-is-hdr
)
164 (defvar org-lparse-table-is-styled
)
168 ;;; User Configuration Variables
170 (defgroup org-export-e-html nil
171 "Options for exporting Org mode files to HTML."
172 :tag
"Org Export HTML"
177 (defcustom org-e-html-pretty-output t
178 "Enable this to generate pretty HTML."
179 :group
'org-export-e-html
185 (defcustom org-e-html-extension
"html"
186 "The extension for exported HTML files."
187 :group
'org-export-e-html
190 (defcustom org-e-html-xml-declaration
191 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
192 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
193 "The extension for exported HTML files.
194 %s will be replaced with the charset of the exported file.
195 This may be a string, or an alist with export extensions
196 and corresponding declarations."
197 :group
'org-export-e-html
199 (string :tag
"Single declaration")
200 (repeat :tag
"Dependent on extension"
201 (cons (string :tag
"Extension")
202 (string :tag
"Declaration")))))
204 (defcustom org-e-html-coding-system nil
205 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
206 :group
'org-export-e-html
207 :type
'coding-system
)
209 (defvar org-e-html-content-div
"content"
210 "The name of the container DIV that holds all the page contents.
212 This variable is obsolete since Org version 7.7.
213 Please set `org-e-html-divs' instead.")
215 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
216 "The name of the main divs for HTML export.
217 This is a list of three strings, the first one for the preamble
218 DIV, the second one for the content DIV and the third one for the
220 :group
'org-export-e-html
222 (string :tag
" Div for the preamble:")
223 (string :tag
" Div for the content:")
224 (string :tag
"Div for the postamble:")))
227 ;;;; Document Header (Styles)
229 (defconst org-e-html-style-default
230 "<style type=\"text/css\">
231 <!--/*--><![CDATA[/*><!--*/
232 html { font-family: Times, serif; font-size: 12pt; }
233 .title { text-align: center; }
234 .todo { color: red; }
235 .done { color: green; }
236 .tag { background-color: #add8e6; font-weight:normal }
238 .timestamp { color: #bebebe; }
239 .timestamp-kwd { color: #5f9ea0; }
240 .right {margin-left:auto; margin-right:0px; text-align:right;}
241 .left {margin-left:0px; margin-right:auto; text-align:left;}
242 .center {margin-left:auto; margin-right:auto; text-align:center;}
243 p.verse { margin-left: 3% }
245 border: 1pt solid #AEBDCC;
246 background-color: #F3F5F7;
248 font-family: courier, monospace;
252 table { border-collapse: collapse; }
253 td, th { vertical-align: top; }
254 th.right { text-align:center; }
255 th.left { text-align:center; }
256 th.center { text-align:center; }
257 td.right { text-align:right; }
258 td.left { text-align:left; }
259 td.center { text-align:center; }
260 dt { font-weight: bold; }
261 div.figure { padding: 0.5em; }
262 div.figure p { text-align: center; }
265 border:2px solid gray;
269 textarea { overflow-x: auto; }
270 .linenr { font-size:smaller }
271 .code-highlighted {background-color:#ffff00;}
272 .org-info-js_info-navigation { border-style:none; }
273 #org-info-js_console-label { font-size:10px; font-weight:bold;
274 white-space:nowrap; }
275 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
279 "The default style specification for exported HTML files.
280 Please use the variables `org-e-html-style' and
281 `org-e-html-style-extra' to add to this style. If you wish to not
282 have the default style included, customize the variable
283 `org-e-html-style-include-default'.")
285 (defcustom org-e-html-style-include-default t
286 "Non-nil means include the default style in exported HTML files.
287 The actual style is defined in `org-e-html-style-default' and should
288 not be modified. Use the variables `org-e-html-style' to add
289 your own style information."
290 :group
'org-export-e-html
293 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
295 (defcustom org-e-html-style
""
296 "Org-wide style definitions for exported HTML files.
298 This variable needs to contain the full HTML structure to provide a style,
299 including the surrounding HTML tags. If you set the value of this variable,
300 you should consider to include definitions for the following classes:
301 title, todo, done, timestamp, timestamp-kwd, tag, target.
303 For example, a valid value would be:
305 <style type=\"text/css\">
307 p { font-weight: normal; color: gray; }
309 .title { text-align: center; }
310 .todo, .timestamp-kwd { color: red; }
311 .done { color: green; }
315 If you'd like to refer to an external style file, use something like
317 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
319 As the value of this option simply gets inserted into the HTML <head> header,
320 you can \"misuse\" it to add arbitrary text to the header.
321 See also the variable `org-e-html-style-extra'."
322 :group
'org-export-e-html
325 (put 'org-e-html-style
'safe-local-variable
'stringp
)
327 (defcustom org-e-html-style-extra
""
328 "Additional style information for HTML export.
329 The value of this variable is inserted into the HTML buffer right after
330 the value of `org-e-html-style'. Use this variable for per-file
331 settings of style information, and do not forget to surround the style
332 settings with <style>...</style> tags."
333 :group
'org-export-e-html
336 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
338 (defcustom org-e-html-mathjax-options
339 '((path "http://orgmode.org/mathjax/MathJax.js")
344 "Options for MathJax setup.
346 path The path where to find MathJax
347 scale Scaling for the HTML-CSS backend, usually between 100 and 133
348 align How to align display math: left, center, or right
349 indent If align is not center, how far from the left/right side?
350 mathml Should a MathML player be used if available?
351 This is faster and reduces bandwidth use, but currently
352 sometimes has lower spacing quality. Therefore, the default is
353 nil. When browsers get better, this switch can be flipped.
355 You can also customize this for each buffer, using something like
357 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
358 :group
'org-export-e-html
359 :type
'(list :greedy t
360 (list :tag
"path (the path from where to load MathJax.js)"
361 (const :format
" " path
) (string))
362 (list :tag
"scale (scaling for the displayed math)"
363 (const :format
" " scale
) (string))
364 (list :tag
"align (alignment of displayed equations)"
365 (const :format
" " align
) (string))
366 (list :tag
"indent (indentation with left or right alignment)"
367 (const :format
" " indent
) (string))
368 (list :tag
"mathml (should MathML display be used is possible)"
369 (const :format
" " mathml
) (boolean))))
372 ;;;; Document Header (Scripts)
374 (defcustom org-e-html-style-include-scripts t
375 "Non-nil means include the JavaScript snippets in exported HTML files.
376 The actual script is defined in `org-e-html-scripts' and should
378 :group
'org-export-e-html
381 (defconst org-e-html-scripts
382 "<script type=\"text/javascript\">
383 <!--/*--><![CDATA[/*><!--*/
384 function CodeHighlightOn(elem, id)
386 var target = document.getElementById(id);
388 elem.cacheClassElem = elem.className;
389 elem.cacheClassTarget = target.className;
390 target.className = \"code-highlighted\";
391 elem.className = \"code-highlighted\";
394 function CodeHighlightOff(elem, id)
396 var target = document.getElementById(id);
397 if(elem.cacheClassElem)
398 elem.className = elem.cacheClassElem;
399 if(elem.cacheClassTarget)
400 target.className = elem.cacheClassTarget;
404 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
407 ;;;; Document Header (Mathjax)
409 (defcustom org-e-html-mathjax-template
410 "<script type=\"text/javascript\" src=\"%PATH\">
411 <!--/*--><![CDATA[/*><!--*/
413 // Only one of the two following lines, depending on user settings
414 // First allows browser-native MathML display, second forces HTML/CSS
415 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
416 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
417 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
418 \"TeX/noUndefined.js\"],
420 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
421 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
422 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
423 ignoreClass: \"tex2jax_ignore\",
424 processEscapes: false,
425 processEnvironments: true,
428 showProcessingMessages: true,
429 displayAlign: \"%ALIGN\",
430 displayIndent: \"%INDENT\",
434 availableFonts: [\"STIX\",\"TeX\"],
435 preferredFont: \"TeX\",
451 "The MathJax setup for XHTML files."
452 :group
'org-export-e-html
458 (defcustom org-e-html-preamble t
459 "Non-nil means insert a preamble in HTML export.
461 When `t', insert a string as defined by one of the formatting
462 strings in `org-e-html-preamble-format'. When set to a
463 string, this string overrides `org-e-html-preamble-format'.
464 When set to a function, apply this function and insert the
465 returned string. The function takes the property list of export
466 options as its only argument.
468 Setting :html-preamble in publishing projects will take
469 precedence over this variable."
470 :group
'org-export-e-html
471 :type
'(choice (const :tag
"No preamble" nil
)
472 (const :tag
"Default preamble" t
)
473 (string :tag
"Custom formatting string")
474 (function :tag
"Function (must return a string)")))
476 (defcustom org-e-html-preamble-format
'(("en" ""))
477 "The format for the HTML preamble.
479 %t stands for the title.
480 %a stands for the author's name.
481 %e stands for the author's email.
482 %d stands for the date.
484 If you need to use a \"%\" character, you need to escape it
486 :group
'org-export-e-html
489 (defcustom org-e-html-home
/up-format
490 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
491 <a accesskey=\"h\" href=\"%s\"> UP </a>
493 <a accesskey=\"H\" href=\"%s\"> HOME </a>
495 "Snippet used to insert the HOME and UP links.
496 This is a format string, the first %s will receive the UP link,
497 the second the HOME link. If both `org-e-html-link-up' and
498 `org-e-html-link-home' are empty, the entire snippet will be
500 :group
'org-export-e-html
505 (defcustom org-e-html-postamble
'auto
506 "Non-nil means insert a postamble in HTML export.
508 When `t', insert a string as defined by the formatting string in
509 `org-e-html-postamble-format'. When set to a string, this
510 string overrides `org-e-html-postamble-format'. When set to
511 'auto, discard `org-e-html-postamble-format' and honor
512 `org-export-author/email/creator-info' variables. When set to a
513 function, apply this function and insert the returned string.
514 The function takes the property list of export options as its
517 Setting :html-postamble in publishing projects will take
518 precedence over this variable."
519 :group
'org-export-e-html
520 :type
'(choice (const :tag
"No postamble" nil
)
521 (const :tag
"Auto preamble" 'auto
)
522 (const :tag
"Default formatting string" t
)
523 (string :tag
"Custom formatting string")
524 (function :tag
"Function (must return a string)")))
526 (defcustom org-e-html-postamble-format
527 '(("en" "<p class=\"author\">Author: %a (%e)</p>
528 <p class=\"date\">Date: %d</p>
529 <p class=\"creator\">Generated by %c</p>
530 <p class=\"xhtml-validation\">%v</p>
532 "The format for the HTML postamble.
534 %a stands for the author's name.
535 %e stands for the author's email.
536 %d stands for the date.
537 %c will be replaced by information about Org/Emacs versions.
538 %v will be replaced by `org-e-html-validation-link'.
540 If you need to use a \"%\" character, you need to escape it
542 :group
'org-export-e-html
545 (defcustom org-e-html-validation-link
546 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
547 "Link to HTML validation service."
548 :group
'org-export-e-html
551 ;; FIXME Obsolete since Org 7.7
552 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
555 (defcustom org-e-html-protect-char-alist
559 "Alist of characters to be converted by `org-e-html-protect'."
560 :group
'org-export-e-html
561 :type
'(repeat (cons (string :tag
"Character")
562 (string :tag
"HTML equivalent"))))
564 (defconst org-e-html-special-string-regexps
565 '(("\\\\-" .
"­")
566 ("---\\([^-]\\)" .
"—\\1")
567 ("--\\([^-]\\)" .
"–\\1")
568 ("\\.\\.\\." .
"…"))
569 "Regular expressions for special string conversion.")
574 (defcustom org-e-html-todo-kwd-class-prefix
""
575 "Prefix to class names for TODO keywords.
576 Each TODO keyword gets a class given by the keyword itself, with this prefix.
577 The default prefix is empty because it is nice to just use the keyword
578 as a class name. But if you get into conflicts with other, existing
579 CSS classes, then this prefix can be very useful."
580 :group
'org-export-e-html
586 (defcustom org-e-html-tag-class-prefix
""
587 "Prefix to class names for TODO keywords.
588 Each tag gets a class given by the tag itself, with this prefix.
589 The default prefix is empty because it is nice to just use the keyword
590 as a class name. But if you get into conflicts with other, existing
591 CSS classes, then this prefix can be very useful."
592 :group
'org-export-e-html
596 ;;;; Statistics Cookie
602 (defcustom org-e-html-inline-images
'maybe
603 "Non-nil means inline images into exported HTML pages.
604 This is done using an <img> tag. When nil, an anchor with href is used to
605 link to the image. If this option is `maybe', then images in links with
606 an empty description will be inlined, while images with a description will
608 :group
'org-export-e-html
609 :type
'(choice (const :tag
"Never" nil
)
610 (const :tag
"Always" t
)
611 (const :tag
"When there is no description" maybe
)))
613 (defcustom org-e-html-inline-image-extensions
614 '("png" "jpeg" "jpg" "gif" "svg")
615 "Extensions of image files that can be inlined into HTML."
616 :group
'org-export-e-html
617 :type
'(repeat (string :tag
"Extension")))
633 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
634 <h2 class=\"footnotes\">%s: </h2>
635 <div id=\"text-footnotes\">
639 "Format for the footnotes section.
640 Should contain a two instances of %s. The first will be replaced with the
641 language-specific word for \"Footnotes\", the second one will be replaced
642 by the footnotes themselves."
643 :group
'org-export-e-html
646 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
647 "The format for the footnote reference.
648 %s will be replaced by the footnote reference itself."
649 :group
'org-export-e-html
652 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
653 "Text used to separate footnotes."
654 :group
'org-export-e-html
660 ;;;; Inline Babel Call
661 ;;;; Inline Src Block
665 ;;;; Latex Environment
682 (defgroup org-export-e-htmlize nil
683 "Options for processing examples with htmlize.el."
684 :tag
"Org Export Htmlize"
685 :group
'org-export-e-html
)
687 (defcustom org-export-e-htmlize-output-type
'inline-css
688 "Output type to be used by htmlize when formatting code snippets.
689 Choices are `css', to export the CSS selectors only, or `inline-css', to
690 export the CSS attribute values inline in the HTML. We use as default
691 `inline-css', in order to make the resulting HTML self-containing.
693 However, this will fail when using Emacs in batch mode for export, because
694 then no rich font definitions are in place. It will also not be good if
695 people with different Emacs setup contribute HTML files to a website,
696 because the fonts will represent the individual setups. In these cases,
697 it is much better to let Org/Htmlize assign classes only, and to use
698 a style file to define the look of these classes.
699 To get a start for your css file, start Emacs session and make sure that
700 all the faces you are interested in are defined, for example by loading files
701 in all modes you want. Then, use the command
702 \\[org-export-e-htmlize-generate-css] to extract class definitions."
703 :group
'org-export-e-htmlize
704 :type
'(choice (const css
) (const inline-css
)))
706 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
707 "The prefix for CSS class names for htmlize font specifications."
708 :group
'org-export-e-htmlize
711 (defcustom org-export-e-htmlized-org-css-url nil
712 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
713 Normally when creating an htmlized version of an Org buffer, htmlize will
714 create CSS to define the font colors. However, this does not work when
715 converting in batch mode, and it also can look bad if different people
716 with different fontification setup work on the same website.
717 When this variable is non-nil, creating an htmlized version of an Org buffer
718 using `org-export-as-org' will remove the internal CSS section and replace it
719 with a link to this URL."
720 :group
'org-export-e-htmlize
722 (const :tag
"Keep internal css" nil
)
723 (string :tag
"URL or local href")))
728 (defcustom org-e-html-table-tag
729 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
730 "The HTML tag that is used to start a table.
731 This must be a <table> tag, but you may change the options like
732 borders and spacing."
733 :group
'org-export-e-html
736 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
737 "The opening tag for table header fields.
738 This is customizable so that alignment options can be specified.
739 The first %s will be filled with the scope of the field, either row or col.
740 The second %s will be replaced by a style entry to align the field.
741 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
742 See also the variable `org-e-html-table-align-individual-fields'."
743 :group
'org-export-tables
; FIXME: change group?
744 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
746 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
747 "The opening tag for table data fields.
748 This is customizable so that alignment options can be specified.
749 The first %s will be filled with the scope of the field, either row or col.
750 The second %s will be replaced by a style entry to align the field.
751 See also the variable `org-e-html-table-align-individual-fields'."
752 :group
'org-export-tables
753 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
755 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
756 "The opening tag for table data fields.
757 This is customizable so that alignment options can be specified.
758 Instead of strings, these can be Lisp forms that will be evaluated
759 for each row in order to construct the table row tags. During evaluation,
760 the variable `head' will be true when this is a header line, nil when this
761 is a body line. And the variable `nline' will contain the line number,
762 starting from 1 in the first header line. For example
764 (setq org-e-html-table-row-tags
767 (if (= (mod nline 2) 1)
768 \"<tr class=\\\"tr-odd\\\">\"
769 \"<tr class=\\\"tr-even\\\">\"))
772 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
773 :group
'org-export-tables
775 (choice :tag
"Opening tag"
776 (string :tag
"Specify")
778 (choice :tag
"Closing tag"
779 (string :tag
"Specify")
782 (defcustom org-e-html-table-align-individual-fields t
783 "Non-nil means attach style attributes for alignment to each table field.
784 When nil, alignment will only be specified in the column tags, but this
785 is ignored by some browsers (like Firefox, Safari). Opera does it right
787 :group
'org-export-tables
790 (defcustom org-e-html-table-use-header-tags-for-first-column nil
791 "Non-nil means format column one in tables with header tags.
792 When nil, also column one will use data tags."
793 :group
'org-export-tables
804 (defcustom org-e-html-toplevel-hlevel
2
805 "The <H> level for level 1 headings in HTML export.
806 This is also important for the classes that will be wrapped around headlines
807 and outline structure. If this variable is 1, the top-level headlines will
808 be <h1>, and the corresponding classes will be outline-1, section-number-1,
809 and outline-text-1. If this is 2, all of these will get a 2 instead.
810 The default for this variable is 2, because we use <h1> for formatting the
812 :group
'org-export-e-html
821 (defcustom org-e-html-link-org-files-as-html t
822 "Non-nil means make file links to `file.org' point to `file.html'.
823 When org-mode is exporting an org-mode file to HTML, links to
824 non-html files are directly put into a href tag in HTML.
825 However, links to other Org-mode files (recognized by the
826 extension `.org.) should become links to the corresponding html
827 file, assuming that the linked org-mode file will also be
829 When nil, the links still point to the plain `.org' file."
830 :group
'org-export-e-html
838 ;;; User Configurable Variables (MAYBE)
842 (defcustom org-e-html-date-format
844 "Format string for \\date{...}."
845 :group
'org-export-e-html
850 (defcustom org-e-html-format-headline-function nil
851 "Function to format headline text.
853 This function will be called with 5 arguments:
854 TODO the todo keyword \(string or nil\).
855 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
856 PRIORITY the priority of the headline \(integer or nil\)
857 TEXT the main headline text \(string\).
858 TAGS the tags string, separated with colons \(string or nil\).
860 The function result will be used in the section format string.
862 As an example, one could set the variable to the following, in
863 order to reproduce the default set-up:
865 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
866 \"Default format function for an headline.\"
868 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
870 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
872 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
873 :group
'org-export-e-html
878 (defcustom org-e-html-emphasis-alist
879 '(("*" .
"<b>%s</b>")
881 ("_" .
"<span style=\"text-decoration:underline;\">%s</span>")
882 ("+" .
"<del>%s</del>")
883 ("=" .
"<code>%s</code>")
884 ("~" .
"<code>%s</code>"))
885 "Alist of HTML expressions to convert emphasis fontifiers.
887 The key is the character used as a marker for fontification. The
888 value is a formatting string to wrap fontified text with.
890 Value can also be set to the following symbols: `verb' and
891 `protectedtexttt'. For the former, Org will use \"\\verb\" to
892 create a format string and select a delimiter character that
893 isn't in the string. For the latter, Org will use \"\\texttt\"
894 to typeset and try to protect special characters."
895 :group
'org-export-e-html
901 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
902 "Text used to separate footnotes."
903 :group
'org-export-e-html
909 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
910 "A printf format string to be applied to active time-stamps."
911 :group
'org-export-e-html
914 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
915 "A printf format string to be applied to inactive time-stamps."
916 :group
'org-export-e-html
919 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
920 "A printf format string to be applied to diary time-stamps."
921 :group
'org-export-e-html
927 (defcustom org-e-html-inline-image-rules
928 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
929 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
930 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
931 "Rules characterizing image files that can be inlined into HTML.
933 A rule consists in an association whose key is the type of link
934 to consider, and value is a regexp that will be matched against
937 Note that, by default, the image extension *actually* allowed
938 depend on the way the HTML file is processed. When used with
939 pdflatex, pdf, jpg and png images are OK. When processing
940 through dvi to Postscript, only ps and eps are allowed. The
941 default we use here encompasses both."
942 :group
'org-export-e-html
943 :type
'(alist :key-type
(string :tag
"Type")
944 :value-type
(regexp :tag
"Path")))
948 (defcustom org-e-html-table-caption-above t
949 "When non-nil, place caption string at the beginning of the table.
950 Otherwise, place it near the end."
951 :group
'org-export-e-html
956 (defcustom org-e-html-format-drawer-function nil
957 "Function called to format a drawer in HTML code.
959 The function must accept two parameters:
960 NAME the drawer name, like \"LOGBOOK\"
961 CONTENTS the contents of the drawer.
963 The function should return the string to be exported.
965 For example, the variable could be set to the following function
966 in order to mimic default behaviour:
968 \(defun org-e-html-format-drawer-default \(name contents\)
969 \"Format a drawer element for HTML export.\"
971 :group
'org-export-e-html
977 (defcustom org-e-html-format-inlinetask-function nil
978 "Function called to format an inlinetask in HTML code.
980 The function must accept six parameters:
981 TODO the todo keyword, as a string
982 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
983 PRIORITY the inlinetask priority, as a string
984 NAME the inlinetask name, as a string.
985 TAGS the inlinetask tags, as a string.
986 CONTENTS the contents of the inlinetask, as a string.
988 The function should return the string to be exported.
990 For example, the variable could be set to the following function
991 in order to mimic default behaviour:
993 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
994 \"Format an inline task element for HTML export.\"
998 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
999 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1001 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1002 \(format \(concat \"\\\\begin{center}\\n\"
1004 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1006 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1008 \"\\\\end{minipage}}\"
1009 \"\\\\end{center}\"\)
1010 full-title contents\)\)"
1011 :group
'org-export-e-html
1019 (defcustom org-e-html-quotes
1021 ("\\(\\s-\\|[[(]\\)\"" .
"«~")
1022 ("\\(\\S-\\)\"" .
"~»")
1023 ("\\(\\s-\\|(\\)'" .
"'"))
1025 ("\\(\\s-\\|[[(]\\)\"" .
"``")
1026 ("\\(\\S-\\)\"" .
"''")
1027 ("\\(\\s-\\|(\\)'" .
"`")))
1028 "Alist for quotes to use when converting english double-quotes.
1030 The CAR of each item in this alist is the language code.
1031 The CDR of each item in this alist is a list of three CONS.
1032 - the first CONS defines the opening quote
1033 - the second CONS defines the closing quote
1034 - the last CONS defines single quotes
1036 For each item in a CONS, the first string is a regexp for allowed
1037 characters before/after the quote, the second string defines the
1038 replacement string for this quote."
1039 :group
'org-export-e-html
1041 (cons :tag
"Opening quote"
1042 (string :tag
"Regexp for char before")
1043 (string :tag
"Replacement quote "))
1044 (cons :tag
"Closing quote"
1045 (string :tag
"Regexp for char after ")
1046 (string :tag
"Replacement quote "))
1047 (cons :tag
"Single quote"
1048 (string :tag
"Regexp for char before")
1049 (string :tag
"Replacement quote "))))
1056 ;;; Internal Functions (HTML)
1058 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1059 "Convert an org filename to an equivalent html filename.
1060 If TYPE is not file, just return `nil'.
1061 See variable `org-e-html-link-org-files-as-html'."
1064 org-e-html-link-org-files-as-html
1065 (string= type
"file")
1066 (string-match "\\.org$" path
)
1071 (substring path
0 (match-beginning 0))
1072 "." (plist-get opt-plist
:html-extension
)))))))
1074 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1077 OPT-PLIST is an options list.
1078 TYPE is the device-type of the link (THIS://foo.html).
1079 PATH is the path of the link (http://THIS#location).
1080 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1081 DESC is the link description, if any.
1082 ATTR is a string of other attributes of the \"a\" element."
1083 (declare (special org-lparse-par-open
))
1085 (when (string= type-1
"coderef")
1086 (let ((ref fragment
))
1087 (setq desc
(format (org-export-get-coderef-format ref
(and descp desc
))
1088 (cdr (assoc ref org-export-code-refs
)))
1089 fragment
(concat "coderef-" ref
)
1090 attr
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1091 fragment fragment
))))
1092 (let* ((may-inline-p
1093 (and (member type-1
'("http" "https" "file"))
1094 (org-lparse-should-inline-p path descp
)
1096 (type (if (equal type-1
"id") "file" type-1
))
1098 ;;First pass. Just sanity stuff.
1101 ((string= type
"file")
1104 ;;Substitute just if original path was absolute.
1105 ;;(Otherwise path must remain relative)
1106 (if (file-name-absolute-p path
)
1107 (concat "file://" (expand-file-name path
))
1111 (t (list type path
))))
1113 ;;Second pass. Components converted so they can refer
1117 (and org-e-html-cvt-link-fn
1118 (apply org-e-html-cvt-link-fn
1119 opt-plist components-1
))
1120 (apply #'org-e-html-cvt-org-as-html
1121 opt-plist components-1
)
1123 (type (first components-2
))
1124 (thefile (second components-2
)))
1127 ;;Third pass. Build final link except for leading type
1132 (string= type
"http")
1133 (string= type
"https")
1134 (string= type
"file")
1135 (string= type
"coderef"))
1137 (setq thefile
(concat thefile
"#" fragment
))))
1141 ;;Final URL-build, for all types.
1144 ((str (org-xml-format-href thefile
)))
1145 (if (and type
(not (or (string= "file" type
)
1146 (string= "coderef" type
))))
1147 (concat type
":" str
)
1151 (ignore) ;; (org-e-html-format-image thefile)
1153 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1155 ;; (caption (and caption (org-xml-encode-org-text caption)))
1156 ;; alt = (file-name-nondirectory path)
1158 (defun org-e-html-format-inline-image (src &optional
1159 caption label attr standalone-p
)
1160 (let* ((id (if (not label
) ""
1161 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1164 ((string-match "\\<alt=" (or attr
"")) "")
1165 ((string-match "^ltxpng/" src
)
1166 (format " alt=\"%s\""
1167 (org-e-html-encode-plain-text
1168 (org-find-text-property-in-string
1169 'org-latex-src src
))))
1170 (t (format " alt=\"%s\""
1171 (file-name-nondirectory src
)))))))
1174 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1175 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1176 id
(format "\n<p>%s</p>" img
)
1177 (when caption
(format "\n<p>%s</p>" caption
)))))
1178 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1182 (defun org-e-html-bibliography ()
1183 "Find bibliography, cut it out and return it."
1185 (let (beg end
(cnt 1) bib
)
1187 (goto-char (point-min))
1188 (when (re-search-forward
1189 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1190 (setq beg
(match-beginning 0))
1191 (while (re-search-forward "</?div\\>" nil t
)
1192 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1194 (and (looking-at ">") (forward-char 1))
1195 (setq bib
(buffer-substring beg
(point)))
1196 (delete-region beg
(point))
1197 (throw 'exit bib
))))
1202 (defun org-e-html-format-table (lines olines
)
1203 (let ((org-e-html-format-table-no-css nil
))
1204 (org-lparse-format-table lines olines
)))
1206 (defun org-e-html-splice-attributes (tag attributes
)
1207 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1208 (if (not attributes
)
1210 (let (oldatt newatt
)
1211 (setq oldatt
(org-extract-attributes-from-string tag
)
1213 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1215 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1216 (if (string-match ">" tag
)
1218 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1222 (defun org-export-splice-style (style extra
)
1223 "Splice EXTRA into STYLE, just before \"</style>\"."
1224 (if (and (stringp extra
)
1225 (string-match "\\S-" extra
)
1226 (string-match "</style>" style
))
1227 (concat (substring style
0 (match-beginning 0))
1229 (substring style
(match-beginning 0)))
1232 (defun org-export-e-htmlize-region-for-paste (beg end
)
1233 "Convert the region to HTML, using htmlize.el.
1234 This is much like `htmlize-region-for-paste', only that it uses
1235 the settings define in the org-... variables."
1236 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1237 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1238 (htmlbuf (htmlize-region beg end
)))
1240 (with-current-buffer htmlbuf
1241 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1242 (plist-get htmlize-buffer-places
'content-end
)))
1243 (kill-buffer htmlbuf
))))
1246 (defun org-export-e-htmlize-generate-css ()
1247 "Create the CSS for all font definitions in the current Emacs session.
1248 Use this to create face definitions in your CSS style file that can then
1249 be used by code snippets transformed by htmlize.
1250 This command just produces a buffer that contains class definitions for all
1251 faces used in the current Emacs session. You can copy and paste the ones you
1252 need into your CSS file.
1254 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1255 the function `org-export-e-htmlize-region-for-paste' will produce code
1256 that uses these same face definitions."
1259 (and (get-buffer "*html*") (kill-buffer "*html*"))
1261 (let ((fl (face-list))
1262 (htmlize-css-name-prefix "org-")
1263 (htmlize-output-type 'css
)
1265 (while (setq f
(pop fl
)
1266 i
(and f
(face-attribute f
:inherit
)))
1267 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1268 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1269 (htmlize-region (point-min) (point-max))))
1270 (org-pop-to-buffer-same-window "*html*")
1271 (goto-char (point-min))
1272 (if (re-search-forward "<style" nil t
)
1273 (delete-region (point-min) (match-beginning 0)))
1274 (if (re-search-forward "</style>" nil t
)
1275 (delete-region (1+ (match-end 0)) (point-max)))
1276 (beginning-of-line 1)
1277 (if (looking-at " +") (replace-match ""))
1278 (goto-char (point-min)))
1280 (defun org-e-html-make-string (n string
)
1281 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1283 (defun org-e-html-toc-text (toc-entries)
1284 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1285 (start-level prev-level
))
1289 (let ((headline (nth 0 entry
))
1290 (level (nth 1 entry
)))
1292 (let* ((cnt (- level prev-level
))
1293 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1295 (setq prev-level level
)
1297 (org-e-html-make-string
1298 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1299 ((< cnt
0) "</li>\n</ul>\n")))
1300 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1303 (org-e-html-make-string
1304 (- prev-level start-level
) "</li>\n</ul>\n"))))
1306 (defun* org-e-html-format-toc-headline
1307 (todo todo-type priority text tags
1308 &key level section-number headline-label
&allow-other-keys
)
1309 (let ((headline (concat
1310 section-number
(and section-number
". ")
1312 (and tags
" ") (org-e-html--tags tags
))))
1313 (format "<a href=\"#%s\">%s</a>"
1315 (if (not nil
) headline
1316 (format "<span class=\"%s\">%s</span>" todo-type headline
)))))
1318 (defun org-e-html-toc (depth info
)
1319 (assert (wholenump depth
))
1320 (let* ((headlines (org-export-collect-headlines info depth
))
1322 (loop for headline in headlines collect
1323 (list (org-e-html-format-headline--wrap
1324 headline info
'org-e-html-format-toc-headline
)
1325 (org-export-get-relative-level headline info
)))))
1327 (let* ((lang-specific-heading
1328 (nth 3 (or (assoc (plist-get info
:language
)
1329 org-export-language-setup
)
1330 (assoc "en" org-export-language-setup
)))))
1332 "<div id=\"table-of-contents\">\n"
1333 (format "<h%d>%s</h%d>\n"
1334 org-e-html-toplevel-hlevel
1335 lang-specific-heading
1336 org-e-html-toplevel-hlevel
)
1337 "<div id=\"text-table-of-contents\">"
1338 (org-e-html-toc-text toc-entries
)
1342 ;; (defun org-e-html-format-line (line)
1343 ;; (case org-lparse-dyn-current-environment
1344 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1345 ;; (t (concat line "\n"))))
1347 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1348 "Turn todo keyword into a valid class name.
1349 Replaces invalid characters with \"_\"."
1351 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1352 (setq kwd
(replace-match "_" t t kwd
))))
1355 (defun org-e-html-format-footnote-reference (n def refcnt
)
1356 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1357 (format org-e-html-footnote-format
1359 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1362 (defun org-e-html-format-footnotes-section (section-name definitions
)
1363 (if (not definitions
) ""
1364 (format org-e-html-footnotes-section section-name definitions
)))
1366 (defun org-e-html-format-footnote-definition (fn)
1367 (let ((n (car fn
)) (def (cdr fn
)))
1369 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1371 (format org-e-html-footnote-format
1372 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1375 (defun org-e-html-footnote-section (info)
1376 (let* ((fn-alist (org-export-collect-footnote-definitions
1377 (plist-get info
:parse-tree
) info
))
1380 (loop for
(n type raw
) in fn-alist collect
1381 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1382 (org-trim (org-export-data raw
'e-html info
))
1384 (org-trim (org-export-secondary-string
1385 raw
'e-html info
))))))))
1387 (org-e-html-format-footnotes-section
1388 (nth 4 (or (assoc (plist-get info
:language
)
1389 org-export-language-setup
)
1390 (assoc "en" org-export-language-setup
)))
1392 "<table>\n%s\n</table>\n"
1393 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1395 (defun org-e-html-get-coding-system-for-write ()
1396 (or org-e-html-coding-system
1397 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1399 (defun org-e-html-get-coding-system-for-save ()
1400 (or org-e-html-coding-system
1401 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1403 (defun org-e-html-format-date (info)
1404 (let ((date (plist-get info
:date
)))
1406 ((and date
(string-match "%" date
))
1407 (format-time-string date
))
1409 (t (format-time-string "%Y-%m-%d %T %Z")))))
1413 ;;; Internal Functions (Ngz)
1415 (defun org-e-html--caption/label-string
(caption label info
)
1416 "Return caption and label HTML string for floats.
1418 CAPTION is a cons cell of secondary strings, the car being the
1419 standard caption and the cdr its short form. LABEL is a string
1420 representing the label. INFO is a plist holding contextual
1423 If there's no caption nor label, return the empty string.
1425 For non-floats, see `org-e-html--wrap-label'."
1426 (setq label nil
) ;; FIXME
1428 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1430 ((and (not caption
) (not label
)) "")
1431 ((not caption
) (format "\\label{%s}\n" label
))
1432 ;; Option caption format with short name.
1434 (format "\\caption[%s]{%s%s}\n"
1435 (org-export-secondary-string (cdr caption
) 'e-html info
)
1437 (org-export-secondary-string (car caption
) 'e-html info
)))
1438 ;; Standard caption format.
1439 ;; (t (format "\\caption{%s%s}\n"
1441 ;; (org-export-secondary-string (car caption) 'e-html info)))
1443 (t (org-export-secondary-string (car caption
) 'e-html info
)))))
1445 (defun org-e-html--find-verb-separator (s)
1446 "Return a character not used in string S.
1447 This is used to choose a separator for constructs like \\verb."
1448 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1449 (loop for c across ll
1450 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1451 return
(char-to-string c
))))
1453 (defun org-e-html--quotation-marks (text info
)
1454 "Export quotation marks depending on language conventions.
1455 TEXT is a string containing quotation marks to be replaced. INFO
1456 is a plist used as a communication channel."
1459 (while (setq start
(string-match (car l
) text start
))
1460 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1461 (setq text
(replace-match new-quote t t text
))))))
1462 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1463 ;; Falls back on English.
1464 (assoc "en" org-e-html-quotes
))))
1467 (defun org-e-html--wrap-label (element output
)
1468 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1469 This function shouldn't be used for floats. See
1470 `org-e-html--caption/label-string'."
1471 ;; (let ((label (org-element-property :name element)))
1472 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1474 ;; (concat (format "\\label{%s}\n" label) output)))
1481 (defun org-e-html-meta-info (info)
1482 (let* ((title (org-export-secondary-string
1483 (plist-get info
:title
) 'e-html info
))
1484 (author (and (plist-get info
:with-author
)
1485 (let ((auth (plist-get info
:author
)))
1486 (and auth
(org-export-secondary-string
1487 auth
'e-html info
)))))
1488 (description (plist-get info
:description
))
1489 (keywords (plist-get info
:keywords
)))
1491 (format "\n<title>%s</title>\n" title
)
1493 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1494 (and coding-system-for-write
1495 (fboundp 'coding-system-get
)
1496 (coding-system-get coding-system-for-write
1498 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1499 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1500 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1501 (org-e-html-format-date info
))
1502 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1503 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1504 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1506 (defun org-e-html-style (info)
1508 "\n" (when (plist-get info
:style-include-default
) org-e-html-style-default
)
1509 (plist-get info
:style
)
1510 (plist-get info
:style-extra
)
1512 (when (plist-get info
:style-include-scripts
)
1513 org-e-html-scripts
)))
1515 (defun org-e-html-mathjax-config (info)
1516 "Insert the user setup into the matchjax template."
1517 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1518 (let ((template org-e-html-mathjax-template
)
1519 (options org-e-html-mathjax-options
)
1520 (in-buffer (or (plist-get info
:mathjax
) ""))
1521 name val
(yes " ") (no "// ") x
)
1524 (setq name
(car e
) val
(nth 1 e
))
1525 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1526 (setq val
(car (read-from-string
1527 (substring in-buffer
(match-end 0))))))
1528 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1529 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1530 (setq template
(replace-match val t t template
))))
1532 (setq val
(nth 1 (assq 'mathml options
)))
1533 (if (string-match (concat "\\<mathml:") in-buffer
)
1534 (setq val
(car (read-from-string
1535 (substring in-buffer
(match-end 0))))))
1536 ;; Exchange prefixes depending on mathml setting
1537 (if (not val
) (setq x yes yes no no x
))
1538 ;; Replace cookies to turn on or off the config/jax lines
1539 (if (string-match ":MMLYES:" template
)
1540 (setq template
(replace-match yes t t template
)))
1541 (if (string-match ":MMLNO:" template
)
1542 (setq template
(replace-match no t t template
)))
1543 ;; Return the modified template
1546 (defun org-e-html-preamble (info)
1547 (when (plist-get info
:html-preamble
)
1548 (let* ((title (plist-get info
:title
))
1549 (date (org-e-html-format-date info
))
1550 (author (plist-get info
:author
))
1551 (lang-words (or (assoc (plist-get info
:language
)
1552 org-export-language-setup
)
1553 (assoc "en" org-export-language-setup
)))
1554 (email (plist-get info
:email
))
1555 (html-pre-real-contents
1557 ((functionp (plist-get info
:html-preamble
))
1559 (funcall (plist-get info
:html-preamble
))
1561 ((stringp (plist-get info
:html-preamble
))
1562 (format-spec (plist-get info
:html-preamble
)
1563 `((?t .
,title
) (?a .
,author
)
1564 (?d .
,date
) (?e .
,email
))))
1567 (or (cadr (assoc (nth 0 lang-words
)
1568 org-e-html-preamble-format
))
1569 (cadr (assoc "en" org-e-html-preamble-format
)))
1570 `((?t .
,title
) (?a .
,author
)
1571 (?d .
,date
) (?e .
,email
)))))))
1572 (when (not (equal html-pre-real-contents
""))
1575 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1578 html-pre-real-contents
1582 (defun org-e-html-postamble (info)
1584 (when (and (not body-only
)
1585 (plist-get info
:html-postamble
))
1586 (let* ((html-post (plist-get info
:html-postamble
))
1587 (date (org-e-html-format-date info
))
1588 (author (plist-get info
:author
))
1589 (email (plist-get info
:email
))
1590 (lang-words (or (assoc (plist-get info
:language
)
1591 org-export-language-setup
)
1592 (assoc "en" org-export-language-setup
)))
1594 (mapconcat (lambda(e)
1595 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1596 (split-string email
",+ *")
1598 (html-validation-link (or org-e-html-validation-link
""))
1600 (concat "Org version " org-version
" with Emacs version "
1601 (number-to-string emacs-major-version
))))
1605 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1608 ((eq (plist-get info
:html-postamble
) 'auto
)
1610 (when (plist-get info
:time-stamp-file
)
1612 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1613 (when (and (plist-get info
:with-author
) author
)
1615 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1616 (when (and (plist-get info
:with-email
) email
)
1618 <p class=\"email\"> %s </p>" email
))
1619 (when (plist-get info
:with-creator
)
1621 <p class=\"creator\"> %s </p>" creator-info
))
1622 html-validation-link
"\n"))
1623 ;; postamble from a string
1624 ((stringp (plist-get info
:html-postamble
))
1625 (format-spec (plist-get info
:html-postamble
)
1626 `((?a .
,author
) (?e .
,email
)
1627 (?d .
,date
) (?c .
,creator-info
)
1628 (?v .
,html-validation-link
))))
1630 ;; postamble from a function
1631 ((functionp (plist-get info
:html-postamble
))
1633 (funcall (plist-get info
:html-postamble
))
1635 ;; default postamble
1638 (or (cadr (assoc (nth 0 lang-words
)
1639 org-e-html-postamble-format
))
1640 (cadr (assoc "en" org-e-html-postamble-format
)))
1641 `((?a .
,author
) (?e .
,email
)
1642 (?d .
,date
) (?c .
,creator-info
)
1643 (?v .
,html-validation-link
)))))
1646 ;; org-e-html-html-helper-timestamp
1649 (defun org-e-html-template (contents info
)
1650 "Return complete document string after HTML conversion.
1651 CONTENTS is the transcoded contents string. RAW-DATA is the
1652 original parsed data. INFO is a plist holding export options."
1655 (or (and (stringp org-e-html-xml-declaration
)
1656 org-e-html-xml-declaration
)
1657 (cdr (assoc (plist-get info
:html-extension
)
1658 org-e-html-xml-declaration
))
1659 (cdr (assoc "html" org-e-html-xml-declaration
))
1662 (or (and coding-system-for-write
1663 (fboundp 'coding-system-get
)
1664 (coding-system-get coding-system-for-write
1668 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1669 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1671 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1672 (plist-get info
:language
) (plist-get info
:language
))
1675 (org-e-html-meta-info info
) ; meta
1676 (org-e-html-style info
) ; style
1677 (org-e-html-mathjax-config info
) ; mathjax
1683 (let ((link-up (and (plist-get info
:link-up
)
1684 (string-match "\\S-" (plist-get info
:link-up
))
1685 (plist-get info
:link-up
)))
1686 (link-home (and (plist-get info
:link-home
)
1687 (string-match "\\S-" (plist-get info
:link-home
))
1688 (plist-get info
:link-home
))))
1689 (when (or link-up link-home
)
1690 (format org-e-html-home
/up-format
1691 (or link-up link-home
)
1692 (or link-home link-up
))))
1694 (org-e-html-preamble info
)
1697 <div id=\"%s\">" (or org-e-html-content-div
1698 (nth 1 org-e-html-divs
)))
1701 <h1 class=\"title\"> %s </h1>\n" (plist-get info
:title
))
1702 ;; table of contents
1703 (let ((depth (plist-get info
:with-toc
)))
1704 (when (wholenump depth
) (org-e-html-toc depth info
)))
1705 ;; document contents
1707 ;; footnotes section
1708 (org-e-html-footnote-section info
)
1710 (org-e-html-bibliography)
1717 (org-e-html-postamble info
)
1727 ;;; Transcode Helpers
1731 (defun org-e-html--todo (todo)
1733 (format "<span class=\"%s %s%s\">%s</span>"
1734 (if (member todo org-done-keywords
) "done" "todo")
1735 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
1740 (defun org-e-html--tags (tags)
1742 (format "<span class=\"tag\">%s</span>"
1745 (format "<span class=\"%s\">%s</span>"
1746 (concat org-e-html-tag-class-prefix
1747 (org-e-html-fix-class-name tag
))
1749 (org-split-string tags
":") " "))))
1753 (defun* org-e-html-format-headline
1754 (todo todo-type priority text tags
1755 &key level section-number headline-label
&allow-other-keys
)
1756 (let ((section-number
1757 (when section-number
1758 (format "<span class=\"section-number-%d\">%s</span> "
1759 level section-number
)))
1760 (todo (org-e-html--todo todo
))
1761 (tags (org-e-html--tags tags
)))
1762 (concat section-number todo
(and todo
" ") text
1763 (and tags
" ") tags
)))
1767 (defun org-e-html-fontify-code (code lang
)
1770 ;; Case 1: No lang. Possibly an example block.
1772 ;; Simple transcoding.
1773 (org-e-html-encode-plain-text code
))
1774 ;; Case 2: No htmlize or an inferior version of htmlize
1775 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1777 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1778 ;; Simple transcoding.
1779 (org-e-html-encode-plain-text code
))
1782 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1783 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1785 ;; Case 1: Language is not associated with any Emacs mode
1786 ((not (functionp lang-mode
))
1787 ;; Simple transcoding.
1788 (org-e-html-encode-plain-text code
))
1789 ;; Case 2: Default. Fotify code.
1792 (setq code
(with-temp-buffer
1795 (font-lock-fontify-buffer)
1796 ;; markup each line separately
1797 (org-remove-formatting-on-newlines-in-region
1798 (point-min) (point-max))
1800 (set-buffer-modified-p nil
)
1801 (org-export-e-htmlize-region-for-paste
1802 (point-min) (point-max))))
1803 ;; Strip any encolosing <pre></pre> tags
1804 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code
)
1805 (match-string 1 code
)
1808 (defun org-e-html-do-format-code
1809 (code &optional lang refs retain-labels num-start textarea-p
)
1811 (setq num-start nil refs nil lang nil
))
1812 (let* ((code-lines (org-split-string code
"\n"))
1813 (code-length (length code-lines
))
1817 (length (number-to-string (+ code-length num-start
))))))
1818 (code (org-e-html-fontify-code code lang
)))
1819 (assert (= code-length
(length (org-split-string code
"\n"))))
1820 (org-export-format-code
1822 (lambda (loc line-num ref
)
1825 ;; Add line number, if needed.
1827 (format "<span class=\"linenr\">%s</span>"
1828 (format num-fmt line-num
)))
1829 ;; Transcoded src line.
1831 ;; Add label, if needed.
1832 (when (and ref retain-labels
) (format " (%s)" ref
))))
1833 ;; Mark transcoded line as an anchor, if needed.
1835 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1839 (defun org-e-html-format-code (element info
)
1840 (let* ((lang (org-element-property :language element
))
1841 ;; (switches (org-element-property :switches element))
1842 (switches nil
) ; FIXME
1843 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1844 ;; Extract code and references.
1845 (code-info (org-export-unravel-code element
))
1846 (code (car code-info
))
1847 (refs (cdr code-info
))
1848 ;; Does the src block contain labels?
1849 (retain-labels (org-element-property :retain-labels element
))
1850 ;; Does it have line numbers?
1851 (num-start (case (org-element-property :number-lines element
)
1852 (continued (org-export-get-loc element info
))
1854 (org-e-html-do-format-code
1855 code lang refs retain-labels num-start textarea-p
)))
1859 ;;; Transcode Functions
1863 (defun org-e-html-center-block (center-block contents info
)
1864 "Transcode a CENTER-BLOCK element from Org to HTML.
1865 CONTENTS holds the contents of the block. INFO is a plist
1866 holding contextual information."
1867 (org-e-html--wrap-label
1869 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1874 ;; Comments are ignored.
1879 ;; Comment Blocks are ignored.
1884 (defun org-e-html-drawer (drawer contents info
)
1885 "Transcode a DRAWER element from Org to HTML.
1886 CONTENTS holds the contents of the block. INFO is a plist
1887 holding contextual information."
1888 (let* ((name (org-element-property :drawer-name drawer
))
1889 (output (if (functionp org-e-html-format-drawer-function
)
1890 (funcall org-e-html-format-drawer-function
1892 ;; If there's no user defined function: simply
1893 ;; display contents of the drawer.
1895 (org-e-html--wrap-label drawer output
)))
1900 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1901 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1902 CONTENTS holds the contents of the block. INFO is a plist
1903 holding contextual information. See
1905 (org-e-html--wrap-label dynamic-block contents
))
1910 (defun org-e-html-emphasis (emphasis contents info
)
1911 "Transcode EMPHASIS from Org to HTML.
1912 CONTENTS is the contents of the emphasized text. INFO is a plist
1913 holding contextual information.."
1914 (let* ((marker (org-element-property :marker emphasis
)))
1915 (format (cdr (assoc marker org-e-html-emphasis-alist
)) contents
)))
1920 (defun org-e-html-entity (entity contents info
)
1921 "Transcode an ENTITY object from Org to HTML.
1922 CONTENTS are the definition itself. INFO is a plist holding
1923 contextual information."
1924 (org-element-property :html entity
))
1929 (defun org-e-html-example-block (example-block contents info
)
1930 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1931 CONTENTS is nil. INFO is a plist holding contextual information."
1932 (let* ((options (or (org-element-property :options example-block
) ""))
1933 (lang (org-element-property :language example-block
))
1934 (caption (org-element-property :caption example-block
))
1935 (label (org-element-property :name example-block
))
1936 (caption-str (org-e-html--caption/label-string caption label info
))
1937 (attr (mapconcat #'identity
1938 (org-element-property :attr_html example-block
)
1940 ;; (switches (org-element-property :switches example-block))
1941 (switches nil
) ; FIXME
1942 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1943 (code (org-e-html-format-code example-block info
)))
1946 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
1947 80 (string-to-number (match-string 1 switches
))))
1948 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
1949 (string-to-number (match-string 1 switches
))
1950 (org-count-lines code
))))
1952 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1954 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
1959 (defun org-e-html-export-snippet (export-snippet contents info
)
1960 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1961 CONTENTS is nil. INFO is a plist holding contextual information."
1962 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
1963 (org-element-property :value export-snippet
)))
1968 (defun org-e-html-export-block (export-block contents info
)
1969 "Transcode a EXPORT-BLOCK element from Org to HTML.
1970 CONTENTS is nil. INFO is a plist holding contextual information."
1971 (when (string= (org-element-property :type export-block
) "latex")
1972 (org-remove-indentation (org-element-property :value export-block
))))
1977 (defun org-e-html-fixed-width (fixed-width contents info
)
1978 "Transcode a FIXED-WIDTH element from Org to HTML.
1979 CONTENTS is nil. INFO is a plist holding contextual information."
1980 (let* ((value (org-element-normalize-string
1981 (replace-regexp-in-string
1983 (org-element-property :value fixed-width
)))))
1984 (org-e-html--wrap-label
1985 fixed-width
(format "\n<pre class=\"example\">\n%s\n</pre>"
1986 (org-e-html-do-format-code value
)))))
1989 ;;;; Footnote Definition
1991 ;; Footnote Definitions are ignored.
1994 ;;;; Footnote Reference
1996 (defun org-e-html-footnote-reference (footnote-reference contents info
)
1997 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1998 CONTENTS is nil. INFO is a plist holding contextual information."
2000 ;; Insert separator between two footnotes in a row.
2001 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2002 (when (eq (org-element-type prev
) 'footnote-reference
)
2003 org-e-html-footnote-separator
))
2005 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2006 (org-e-html-format-footnote-reference
2007 (org-export-get-footnote-number footnote-reference info
)
2009 ;; Inline definitions are secondary strings.
2010 ((eq (org-element-property :type footnote-reference
) 'inline
)
2011 (org-e-html-format-footnote-reference
2012 (org-export-get-footnote-number footnote-reference info
)
2014 ;; Non-inline footnotes definitions are full Org data.
2015 (t (org-e-html-format-footnote-reference
2016 (org-export-get-footnote-number footnote-reference info
)
2022 (defun org-e-html-format-headline--wrap (headline info
2023 &optional format-function
2025 "Transcode an HEADLINE element from Org to HTML.
2026 CONTENTS holds the contents of the headline. INFO is a plist
2027 holding contextual information."
2028 (let* ((level (+ (org-export-get-relative-level headline info
)
2029 (1- org-e-html-toplevel-hlevel
)))
2030 (headline-number (org-export-get-headline-number headline info
))
2031 (section-number (and (org-export-numbered-headline-p headline info
)
2032 (mapconcat 'number-to-string
2033 headline-number
".")))
2034 (todo (and (plist-get info
:with-todo-keywords
)
2035 (let ((todo (org-element-property
2036 :todo-keyword headline
)))
2038 (org-export-secondary-string todo
'e-html info
)))))
2039 (todo-type (and todo
(org-element-property :todo-type headline
)))
2040 (priority (and (plist-get info
:with-priority
)
2041 (org-element-property :priority headline
)))
2042 (text (org-export-secondary-string
2043 (org-element-property :title headline
) 'e-html info
))
2044 (tags (and (plist-get info
:with-tags
)
2045 (org-element-property :tags headline
)))
2046 (headline-label (concat "sec-" (mapconcat 'number-to-string
2047 headline-number
"-")))
2048 (format-function (cond
2049 ((functionp format-function
) format-function
)
2050 ((functionp org-e-html-format-headline-function
)
2052 (lambda (todo todo-type priority text tags
2054 (funcall org-e-html-format-headline-function
2055 todo todo-type priority text tags
))))
2056 (t 'org-e-html-format-headline
))))
2057 (apply format-function
2058 todo todo-type priority text tags
2059 :headline-label headline-label
:level level
2060 :section-number section-number extra-keys
)))
2062 (defun org-e-html-headline (headline contents info
)
2063 "Transcode an HEADLINE element from Org to HTML.
2064 CONTENTS holds the contents of the headline. INFO is a plist
2065 holding contextual information."
2066 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2067 (level (org-export-get-relative-level headline info
))
2068 (text (org-export-secondary-string
2069 (org-element-property :title headline
) 'e-html info
))
2070 (todo (and (plist-get info
:with-todo-keywords
)
2071 (let ((todo (org-element-property
2072 :todo-keyword headline
)))
2074 (org-export-secondary-string todo
'e-html info
)))))
2075 (todo-type (and todo
(org-element-property :todo-type headline
)))
2076 (tags (and (plist-get info
:with-tags
)
2077 (org-element-property :tags headline
)))
2078 (priority (and (plist-get info
:with-priority
)
2079 (org-element-property :priority headline
)))
2080 (section-number (and (org-export-numbered-headline-p headline info
)
2081 (mapconcat 'number-to-string
2082 (org-export-get-headline-number
2083 headline info
) ".")))
2084 ;; Create the headline text.
2085 (full-text (org-e-html-format-headline--wrap headline info
)))
2087 ;; Case 1: This is a footnote section: ignore it.
2088 ((org-element-property :footnote-section-p headline
) nil
)
2089 ;; Case 2. This is a deep sub-tree: export it as a list item.
2090 ;; Also export as items headlines for which no section
2091 ;; format has been found.
2092 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2093 ;; Build the real contents of the sub-tree.
2094 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2095 (itemized-body (org-e-html-format-list-item
2096 contents type nil nil full-text
)))
2098 (and (org-export-first-sibling-p headline info
)
2099 (org-e-html-begin-plain-list type
))
2101 (and (org-export-last-sibling-p headline info
)
2102 (org-e-html-end-plain-list type
)))))
2103 ;; Case 3. Standard headline. Export it as a section.
2105 (let* ((extra-class (org-element-property :html-container-class headline
))
2106 (extra-ids (list (org-element-property :custom-id headline
)
2107 (org-element-property :id headline
)))
2112 (let ((id (org-solidify-link-text
2113 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2114 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2116 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2117 (id (mapconcat 'number-to-string
2118 (org-export-get-headline-number headline info
) "-")))
2119 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2120 (format "outline-container-%s" id
)
2121 (concat (format "outline-%d" level1
) (and extra-class
" ")
2123 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2124 level1 id extra-ids full-text level1
)
2128 ;;;; Horizontal Rule
2130 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2131 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2132 CONTENTS is nil. INFO is a plist holding contextual information."
2133 (let ((attr (mapconcat #'identity
2134 (org-element-property :attr_html horizontal-rule
)
2136 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2139 ;;;; Inline Babel Call
2141 ;; Inline Babel Calls are ignored.
2144 ;;;; Inline Src Block
2146 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2147 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2148 CONTENTS holds the contents of the item. INFO is a plist holding
2149 contextual information."
2150 (let* ((org-lang (org-element-property :language inline-src-block
))
2151 (code (org-element-property :value inline-src-block
))
2152 (separator (org-e-html--find-verb-separator code
)))
2158 (defun org-e-html-format-section (text class
&optional id
)
2159 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2160 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2162 (defun org-e-html-inlinetask (inlinetask contents info
)
2163 "Transcode an INLINETASK element from Org to HTML.
2164 CONTENTS holds the contents of the block. INFO is a plist
2165 holding contextual information."
2167 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2168 ;; with appropriate arguments.
2169 ((functionp org-e-html-format-inlinetask-function
)
2170 (let ((format-function
2172 (lambda (todo todo-type priority text tags
2173 &key contents
&allow-other-keys
)
2174 (funcall org-e-html-format-inlinetask-function
2175 todo todo-type priority text tags contents
)))))
2176 (org-e-html-format-headline--wrap
2177 inlinetask info format-function
:contents contents
)))
2178 ;; Otherwise, use a default template.
2179 (t (org-e-html--wrap-label
2182 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2183 (org-e-html-format-headline--wrap inlinetask info
)
2189 (defun org-e-html-checkbox (checkbox)
2190 (case checkbox
(on "<code>[X]</code>")
2191 (off "<code>[ ]</code>")
2192 (trans "<code>[-]</code>")
2195 (defun org-e-html-format-list-item (contents type checkbox
2196 &optional term-counter-id
2201 (let* ((counter term-counter-id
)
2202 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2203 (format "<li%s>" extra
)))
2205 (let* ((id term-counter-id
)
2206 (extra (if id
(format " id=\"%s\"" id
) "")))
2208 (format "<li%s>" extra
)
2209 (when headline
(concat headline
"<br/>")))))
2211 (let* ((term term-counter-id
))
2212 (setq term
(or term
"(no term)"))
2213 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2214 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2219 (descriptive "</dd>"))))
2221 (defun org-e-html-item (item contents info
)
2222 "Transcode an ITEM element from Org to HTML.
2223 CONTENTS holds the contents of the item. INFO is a plist holding
2224 contextual information."
2225 ;; Grab `:level' from plain-list properties, which is always the
2226 ;; first element above current item.
2227 (let* ((plain-list (org-export-get-parent item info
))
2228 (type (org-element-property :type plain-list
))
2229 (level (org-element-property :level plain-list
))
2230 (counter (org-element-property :counter item
))
2231 (checkbox (org-element-property :checkbox item
))
2232 (tag (let ((tag (org-element-property :tag item
)))
2233 (and tag
(org-export-secondary-string tag
'e-html info
)))))
2234 (org-e-html-format-list-item
2235 contents type checkbox
(or tag counter
))))
2240 (defun org-e-html-keyword (keyword contents info
)
2241 "Transcode a KEYWORD element from Org to HTML.
2242 CONTENTS is nil. INFO is a plist holding contextual information."
2243 (let ((key (downcase (org-element-property :key keyword
)))
2244 (value (org-element-property :value keyword
)))
2246 ((string= key
"latex") value
)
2247 ((string= key
"index") (format "\\index{%s}" value
))
2248 ;; Invisible targets.
2249 ((string= key
"target") nil
) ; FIXME
2250 ((string= key
"toc")
2251 (let ((value (downcase value
)))
2253 ((string-match "\\<headlines\\>" value
)
2254 (let ((depth (or (and (string-match "[0-9]+" value
)
2255 (string-to-number (match-string 0 value
)))
2256 (plist-get info
:with-toc
))))
2257 (when (wholenump depth
) (org-e-html-toc depth info
))))
2258 ((string= "tables" value
) "\\listoftables")
2259 ((string= "figures" value
) "\\listoffigures")
2260 ((string= "listings" value
)
2262 ;; At the moment, src blocks with a caption are wrapped
2263 ;; into a figure environment.
2264 (t "\\listoffigures")))))))))
2267 ;;;; Latex Environment
2269 (defun org-e-html-format-latex (latex-frag processing-type
)
2270 (let* ((cache-relpath
2271 (concat "ltxpng/" (file-name-sans-extension
2272 (file-name-nondirectory (buffer-file-name)))))
2273 (cache-dir (file-name-directory (buffer-file-name )))
2274 (display-msg "Creating LaTeX Image..."))
2278 (org-format-latex cache-relpath cache-dir nil display-msg
2279 nil nil processing-type
)
2282 (defun org-e-html-latex-environment (latex-environment contents info
)
2283 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2284 CONTENTS is nil. INFO is a plist holding contextual information."
2285 (org-e-html--wrap-label
2287 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2288 (latex-frag (org-remove-indentation
2289 (org-element-property :value latex-environment
)))
2290 (caption (org-e-html--caption/label-string
2291 (org-element-property :caption latex-environment
)
2292 (org-element-property :name latex-environment
)
2295 (label (org-element-property :name latex-environment
)))
2297 ((member processing-type
'(t mathjax
))
2298 (org-e-html-format-latex latex-frag
'mathjax
))
2299 ((equal processing-type
'dvipng
)
2300 (let* ((formula-link (org-e-html-format-latex
2301 latex-frag processing-type
)))
2302 (when (and formula-link
2303 (string-match "file:\\([^]]*\\)" formula-link
))
2304 (org-e-html-format-inline-image
2305 (match-string 1 formula-link
) caption label attr t
))))
2311 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2312 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2313 CONTENTS is nil. INFO is a plist holding contextual information."
2314 (let ((latex-frag (org-element-property :value latex-fragment
))
2315 (processing-type (plist-get info
:LaTeX-fragments
)))
2316 (case processing-type
2318 (org-e-html-format-latex latex-frag
'mathjax
))
2320 (let* ((formula-link (org-e-html-format-latex
2321 latex-frag processing-type
)))
2322 (when (and formula-link
2323 (string-match "file:\\([^]]*\\)" formula-link
))
2324 (org-e-html-format-inline-image
2325 (match-string 1 formula-link
)))))
2330 (defun org-e-html-line-break (line-break contents info
)
2331 "Transcode a LINE-BREAK object from Org to HTML.
2332 CONTENTS is nil. INFO is a plist holding contextual information."
2338 (defun org-e-html-link--inline-image (link desc info
)
2339 "Return HTML code for an inline image.
2340 LINK is the link pointing to the inline image. INFO is a plist
2341 used as a communication channel."
2342 (let* ((type (org-element-property :type link
))
2343 (raw-path (org-element-property :path link
))
2344 (path (cond ((member type
'("http" "https"))
2345 (concat type
":" raw-path
))
2346 ((file-name-absolute-p raw-path
)
2347 (expand-file-name raw-path
))
2349 (parent (org-export-get-parent-paragraph link info
))
2350 (caption (org-e-html--caption/label-string
2351 (org-element-property :caption parent
)
2352 (org-element-property :name parent
)
2354 (label (org-element-property :name parent
))
2355 ;; Retrieve latex attributes from the element around.
2356 (attr (let ((raw-attr
2357 (mapconcat #'identity
2358 (org-element-property :attr_html parent
)
2360 (unless (string= raw-attr
"") raw-attr
))))
2361 ;; Now clear ATTR from any special keyword and set a default
2362 ;; value if nothing is left.
2363 (setq attr
(if (not attr
) "" (org-trim attr
)))
2364 ;; Return proper string, depending on DISPOSITION.
2365 (org-e-html-format-inline-image
2366 path caption label attr
(org-e-html-standalone-image-p link info
))))
2368 (defvar org-e-html-standalone-image-predicate
)
2369 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2370 "Test if ELEMENT is a standalone image for the purpose HTML export.
2371 INFO is a plist holding contextual information.
2373 Return non-nil, if ELEMENT is of type paragraph and it's sole
2374 content, save for whitespaces, is a link that qualifies as an
2377 Return non-nil, if ELEMENT is of type link and it's containing
2378 paragraph has no other content save for leading and trailing
2381 Return nil, otherwise.
2383 Bind `org-e-html-standalone-image-predicate' to constrain
2384 paragraph further. For example, to check for only captioned
2385 standalone images, do the following.
2387 \(setq org-e-html-standalone-image-predicate
2388 \(lambda \(paragraph\)
2389 \(org-element-property :caption paragraph\)\)\)
2391 (let ((paragraph (case (org-element-type element
)
2393 (link (and (org-export-inline-image-p
2394 element org-e-html-inline-image-rules
)
2395 (org-export-get-parent element info
)))
2398 (assert (eq (org-element-type paragraph
) 'paragraph
))
2399 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2400 (functionp org-e-html-standalone-image-predicate
)))
2401 (funcall org-e-html-standalone-image-predicate paragraph
))
2402 (let ((contents (org-element-contents paragraph
)))
2403 (loop for x in contents
2404 with inline-image-count
= 0
2406 ((eq (org-element-type x
) 'plain-text
)
2407 (not (org-string-nw-p x
)))
2408 ((eq (org-element-type x
) 'link
)
2409 (when (org-export-inline-image-p
2410 x org-e-html-inline-image-rules
)
2411 (= (incf inline-image-count
) 1)))
2414 (defun org-e-html-link (link desc info
)
2415 "Transcode a LINK object from Org to HTML.
2417 DESC is the description part of the link, or the empty string.
2418 INFO is a plist holding contextual information. See
2420 (let* ((type (org-element-property :type link
))
2421 (raw-path (org-element-property :path link
))
2422 ;; Ensure DESC really exists, or set it to nil.
2423 (desc (and (not (string= desc
"")) desc
))
2425 ((member type
'("http" "https" "ftp" "mailto"))
2426 (concat type
":" raw-path
))
2427 ((string= type
"file")
2428 (when (string-match "\\(.+\\)::.+" raw-path
)
2429 (setq raw-path
(match-string 1 raw-path
)))
2430 (if (file-name-absolute-p raw-path
)
2431 (concat "file://" (expand-file-name raw-path
))
2432 ;; TODO: Not implemented yet. Concat also:
2433 ;; (org-export-directory :HTML info)
2434 (concat "file://" raw-path
)))
2439 ((and (or (eq t org-e-html-inline-images
)
2440 (and org-e-html-inline-images
(not desc
)))
2441 (org-export-inline-image-p link org-e-html-inline-image-rules
))
2442 (org-e-html-link--inline-image link desc info
))
2443 ;; Radioed target: Target's name is obtained from original raw
2444 ;; link. Path is parsed and transcoded in order to have a proper
2445 ;; display of the contents.
2446 ((string= type
"radio")
2447 (format "<a href=\"#%s\">%s</a>"
2448 (org-export-solidify-link-text path
)
2449 (org-export-secondary-string
2450 (org-element-parse-secondary-string
2451 path
(cdr (assq 'radio-target org-element-object-restrictions
)))
2453 ;; Links pointing to an headline: Find destination and build
2454 ;; appropriate referencing command.
2455 ((member type
'("custom-id" "fuzzy" "id"))
2456 (let ((destination (if (string= type
"fuzzy")
2457 (org-export-resolve-fuzzy-link link info
)
2458 (org-export-resolve-id-link link info
))))
2459 (case (org-element-type destination
)
2460 ;; Fuzzy link points nowhere.
2463 (or desc
(org-export-secondary-string
2464 (org-element-property :raw-link link
)
2466 ;; Fuzzy link points to an invisible target.
2468 ;; LINK points to an headline. If headlines are numbered
2469 ;; and the link has no description, display headline's
2470 ;; number. Otherwise, display description or headline's
2473 (let* ((headline-no (org-export-get-headline-number destination info
))
2474 (label (format "sec-%s" (mapconcat 'number-to-string
2476 (section-no (mapconcat 'number-to-string headline-no
".")))
2480 ((plist-get info
:section-numbers
) section-no
)
2481 (t (org-export-secondary-string
2482 (org-element-property :title destination
)
2484 (format "<a href=\"#%s\">%s</a>" label desc
)))
2485 ;; Fuzzy link points to a target. Do as above.
2487 (let ((path (org-export-solidify-link-text path
)) number
)
2490 ((org-e-html-standalone-image-p destination info
)
2491 (org-export-get-ordinal
2492 (assoc 'link
(org-element-contents destination
))
2493 info
'link
'org-e-html-standalone-image-p
))
2494 (t (org-export-get-ordinal destination info
))))
2495 (setq desc
(when number
2496 (if (atom number
) (number-to-string number
)
2497 (mapconcat 'number-to-string number
".")))))
2498 (format "<a href=\"#%s\">%s</a>" path
(or desc
"FIXME")))))))
2499 ;; Coderef: replace link with the reference name or the
2500 ;; equivalent line number.
2501 ((string= type
"coderef")
2502 (let ((fragment (concat "coderef-" path
)))
2503 (format "<a href=\"#%s\" %s>%s</a>" fragment
2504 (format (concat "class=\"coderef\""
2505 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2506 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2508 (format (org-export-get-coderef-format path
(or desc
"%s"))
2509 (org-export-resolve-coderef path info
)))))
2510 ;; Link type is handled by a special function.
2511 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2512 (funcall protocol
(org-link-unescape path
) desc
'html
))
2513 ;; External link with a description part.
2514 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2515 ;; External link without a description part.
2516 (path (format "<a href=\"%s\">%s</a>" path path
))
2517 ;; No path, only description. Try to do something useful.
2518 (t (format "<i>%s</i>" desc
)))))
2523 ;; Babel Calls are ignored.
2528 (defun org-e-html-macro (macro contents info
)
2529 "Transcode a MACRO element from Org to HTML.
2530 CONTENTS is nil. INFO is a plist holding contextual information."
2531 ;; Use available tools.
2532 (org-export-expand-macro macro info
))
2537 (defun org-e-html-paragraph (paragraph contents info
)
2538 "Transcode a PARAGRAPH element from Org to HTML.
2539 CONTENTS is the contents of the paragraph, as a string. INFO is
2540 the plist used as a communication channel."
2541 (let* ((style nil
) ; FIXME
2542 (class (cdr (assoc style
'((footnote .
"footnote")
2544 (extra (if class
(format " class=\"%s\"" class
) ""))
2545 (parent (org-export-get-parent paragraph info
)))
2547 ((and (equal (car parent
) 'item
)
2548 (= (org-element-property :begin paragraph
)
2549 (org-element-property :contents-begin parent
)))
2550 ;; leading paragraph in a list item have no tags
2552 ((org-e-html-standalone-image-p paragraph info
)
2555 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2560 (defun org-e-html-begin-plain-list (type &optional arg1
)
2563 (format "<ol%s>" (if arg1
; FIXME
2564 (format " start=\"%d\"" arg1
)
2567 (descriptive "<dl>")))
2569 (defun org-e-html-end-plain-list (type)
2573 (descriptive "</dl>")))
2575 (defun org-e-html-plain-list (plain-list contents info
)
2576 "Transcode a PLAIN-LIST element from Org to HTML.
2577 CONTENTS is the contents of the list. INFO is a plist holding
2578 contextual information."
2579 (let* (arg1 ;; FIXME
2580 (type (org-element-property :type plain-list
))
2581 (attr (mapconcat #'identity
2582 (org-element-property :attr_html plain-list
)
2584 (org-e-html--wrap-label
2585 plain-list
(format "%s\n%s%s"
2586 (org-e-html-begin-plain-list type
)
2587 contents
(org-e-html-end-plain-list type
)))))
2591 (defun org-e-html-convert-special-strings (string)
2592 "Convert special characters in STRING to HTML."
2593 (let ((all org-e-html-special-string-regexps
)
2595 (while (setq a
(pop all
))
2596 (setq re
(car a
) rpl
(cdr a
) start
0)
2597 (while (string-match re string start
)
2598 (setq string
(replace-match rpl t nil string
))))
2601 (defun org-e-html-encode-plain-text (s)
2602 "Convert plain text characters to HTML equivalent.
2603 Possible conversions are set in `org-export-html-protect-char-alist'."
2604 (let ((cl org-e-html-protect-char-alist
) c
)
2605 (while (setq c
(pop cl
))
2607 (while (string-match (car c
) s start
)
2608 (setq s
(replace-match (cdr c
) t t s
)
2609 start
(1+ (match-beginning 0))))))
2612 (defun org-e-html-plain-text (text info
)
2613 "Transcode a TEXT string from Org to HTML.
2614 TEXT is the string to transcode. INFO is a plist holding
2615 contextual information."
2616 (setq text
(org-e-html-encode-plain-text text
))
2617 ;; Protect %, #, &, $, ~, ^, _, { and }.
2618 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2620 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2622 ;; (setq text (replace-regexp-in-string
2623 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2624 ;; "$\\backslash$" text nil t 1))
2625 ;; HTML into \HTML{} and TeX into \TeX{}.
2626 ;; (let ((case-fold-search nil)
2628 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2629 ;; (setq text (replace-match
2630 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2631 ;; start (match-end 0))))
2632 ;; Handle quotation marks
2633 ;; (setq text (org-e-html--quotation-marks text info))
2634 ;; Convert special strings.
2635 ;; (when (plist-get info :with-special-strings)
2636 ;; (while (string-match (regexp-quote "...") text)
2637 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2638 (when (plist-get info
:with-special-strings
)
2639 (setq text
(org-e-html-convert-special-strings text
)))
2640 ;; Handle break preservation if required.
2641 (when (plist-get info
:preserve-breaks
)
2642 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2648 ;;;; Property Drawer
2650 (defun org-e-html-property-drawer (property-drawer contents info
)
2651 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2652 CONTENTS is nil. INFO is a plist holding contextual
2654 ;; The property drawer isn't exported but we want separating blank
2655 ;; lines nonetheless.
2661 (defun org-e-html-quote-block (quote-block contents info
)
2662 "Transcode a QUOTE-BLOCK element from Org to HTML.
2663 CONTENTS holds the contents of the block. INFO is a plist
2664 holding contextual information."
2665 (org-e-html--wrap-label
2666 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2671 (defun org-e-html-quote-section (quote-section contents info
)
2672 "Transcode a QUOTE-SECTION element from Org to HTML.
2673 CONTENTS is nil. INFO is a plist holding contextual information."
2674 (let ((value (org-remove-indentation
2675 (org-element-property :value quote-section
))))
2676 (when value
(format "<pre>\n%s</pre>" value
))))
2681 (defun org-e-html-section (section contents info
) ; FIXME
2682 "Transcode a SECTION element from Org to HTML.
2683 CONTENTS holds the contents of the section. INFO is a plist
2684 holding contextual information."
2685 (let ((parent (org-export-get-parent-headline section info
)))
2686 ;; Before first headline: no container, just return CONTENTS.
2687 (if (not parent
) contents
2688 ;; Get div's class and id references.
2689 (let ((class-num (+ (org-export-get-relative-level parent info
)
2690 (1- org-e-html-toplevel-hlevel
)))
2694 (org-export-get-headline-number parent info
) "-")))
2695 ;; Build return value.
2696 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2697 class-num id-num contents
)))))
2701 (defun org-e-html-radio-target (radio-target text info
)
2702 "Transcode a RADIO-TARGET object from Org to HTML.
2703 TEXT is the text of the target. INFO is a plist holding
2704 contextual information."
2705 (let ((id (org-export-solidify-link-text
2706 (org-element-property :raw-value radio-target
))))
2707 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2712 (defun org-e-html-special-block (special-block contents info
)
2713 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2714 CONTENTS holds the contents of the block. INFO is a plist
2715 holding contextual information."
2716 (let ((type (downcase (org-element-property :type special-block
))))
2717 (org-e-html--wrap-label
2719 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2724 (defun org-e-html-src-block (src-block contents info
)
2725 "Transcode a SRC-BLOCK element from Org to HTML.
2726 CONTENTS holds the contents of the item. INFO is a plist holding
2727 contextual information."
2728 (let* ((lang (org-element-property :language src-block
))
2729 (caption (org-element-property :caption src-block
))
2730 (label (org-element-property :name src-block
))
2731 (caption-str (org-e-html--caption/label-string caption label info
))
2732 (attr (mapconcat #'identity
2733 (org-element-property :attr_html src-block
)
2735 ;; (switches (org-element-property :switches src-block))
2736 (switches nil
) ; FIXME
2737 (textarea-p (and switches
(string-match "-t\\>" switches
)))
2738 (code (org-e-html-format-code src-block info
)))
2741 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2742 (if (not caption
) ""
2743 (format "<label class=\"org-src-name\">%s</label>" caption-str
))
2744 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code
)))
2746 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2747 80 (string-to-number (match-string 1 switches
))))
2748 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2749 (string-to-number (match-string 1 switches
))
2750 (org-count-lines code
))))
2752 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2754 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
2756 ;;;; Statistics Cookie
2758 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2759 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2760 CONTENTS is nil. INFO is a plist holding contextual information."
2761 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2762 (format "<code>%s</code>" cookie-value
)))
2767 (defun org-e-html-subscript (subscript contents info
)
2768 "Transcode a SUBSCRIPT object from Org to HTML.
2769 CONTENTS is the contents of the object. INFO is a plist holding
2770 contextual information."
2771 (format "<sub>%s</sub>" contents
))
2776 (defun org-e-html-superscript (superscript contents info
)
2777 "Transcode a SUPERSCRIPT object from Org to HTML.
2778 CONTENTS is the contents of the object. INFO is a plist holding
2779 contextual information."
2780 (format "<sup>%s</sup>" contents
))
2785 (defun org-e-html-begin-table (caption label attributes
)
2786 (let* ((html-table-tag (or (plist-get info
:html-table-tag
) ; FIXME
2787 org-e-html-table-tag
))
2789 (org-e-html-splice-attributes html-table-tag attributes
)))
2791 (setq html-table-tag
2792 (org-e-html-splice-attributes
2794 (format "id=\"%s\"" (org-solidify-link-text label
)))))
2795 (concat "\n" html-table-tag
2796 (format "\n<caption>%s</caption>" (or caption
"")))))
2798 (defun org-e-html-end-table ()
2801 (defun org-e-html-format-table-cell (text r c horiz-span
)
2802 (let ((cell-style-cookie
2803 (if org-e-html-table-align-individual-fields
2804 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2805 org-e-html-format-table-no-css
)
2806 " align=\"%s\"" " class=\"%s\"")
2807 (or (aref (plist-get table-info
:alignment
) c
) "left")) ""))) ;; FIXME
2809 (org-e-html-table-cur-rowgrp-is-hdr
2811 (format (car org-e-html-table-header-tags
) "col" cell-style-cookie
)
2812 text
(cdr org-e-html-table-header-tags
)))
2813 ((and (= c
0) org-e-html-table-use-header-tags-for-first-column
)
2815 (format (car org-e-html-table-header-tags
) "row" cell-style-cookie
)
2816 text
(cdr org-e-html-table-header-tags
)))
2819 (format (car org-e-html-table-data-tags
) cell-style-cookie
)
2820 text
(cdr org-e-html-table-data-tags
))))))
2822 (defun org-e-html-format-table-row (row)
2823 (concat (eval (car org-e-html-table-row-tags
)) row
2824 (eval (cdr org-e-html-table-row-tags
))))
2826 (defun org-e-html-table-row (fields &optional text-for-empty-fields
)
2827 (incf org-e-html-table-rownum
)
2829 (org-e-html-format-table-row
2832 (when (and (string= x
"") text-for-empty-fields
)
2833 (setq x text-for-empty-fields
))
2836 (org-e-html-format-table-cell
2837 x org-e-html-table-rownum i
(or horiz-span
0))))
2840 (defun org-e-html-end-table-rowgroup ()
2841 (when org-e-html-table-rowgrp-open
2842 (setq org-e-html-table-rowgrp-open nil
)
2843 (if org-e-html-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>")))
2845 (defun org-e-html-begin-table-rowgroup (&optional is-header-row
)
2847 (when org-e-html-table-rowgrp-open
2848 (org-e-html-end-table-rowgroup))
2850 (setq org-e-html-table-rowgrp-open t
)
2851 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row
)
2852 (if is-header-row
"<thead>" "<tbody>"))))
2854 (defun org-e-html-table-preamble ()
2855 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
2856 c gr colgropen preamble
)
2857 (unless (aref colgroup-vector
0)
2858 (setf (aref colgroup-vector
0) 'start
))
2859 (dotimes (c columns-number preamble
)
2860 (setq gr
(aref colgroup-vector c
))
2864 (when (memq gr
'(start start-end
))
2865 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
2866 (setq colgropen t
)))
2867 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
2868 (align (cdr (assoc (aref colalign-vector c
)
2871 ("c" .
"center")))))
2872 (alignspec (if (and (boundp 'org-e-html-format-table-no-css
)
2873 org-e-html-format-table-no-css
)
2874 " align=\"%s\"" " class=\"%s\""))
2875 (extra (format alignspec align
)))
2876 (format "<col%s />" extra
))
2877 (when (memq gr
'(end start-end
))
2878 (setq colgropen nil
)
2880 (concat preamble
(if colgropen
"</colgroup>"))))
2882 (defun org-e-html-list-table (lines caption label attributes
)
2883 (setq lines
(org-e-html-org-table-to-list-table lines
))
2884 (let* ((splice nil
) head
2885 (org-e-html-table-rownum -
1)
2888 org-e-html-table-cur-rowgrp-is-hdr
2889 org-e-html-table-rowgrp-open
2891 (org-lparse-table-style 'org-table
)
2892 org-lparse-table-is-styled
)
2895 (setq org-lparse-table-is-styled nil
)
2896 (mapconcat 'org-e-html-table-row lines
"\n"))
2898 (setq org-lparse-table-is-styled t
)
2901 (org-e-html-begin-table caption label attributes
)
2902 (org-e-html-table-preamble)
2903 (org-e-html-begin-table-rowgroup head
)
2908 ((equal line
'hline
) (org-e-html-begin-table-rowgroup))
2909 (t (org-e-html-table-row line
))))
2912 (org-e-html-end-table-rowgroup)
2913 (org-e-html-end-table))))))
2915 (defun org-e-html-transcode-table-row (row)
2916 (if (string-match org-table-hline-regexp row
) 'hline
2919 (org-export-secondary-string
2920 (let ((cell (org-element-parse-secondary-string
2922 (cdr (assq 'table org-element-string-restrictions
)))))
2925 (org-split-string row
"[ \t]*|[ \t]*"))))
2927 (defun org-e-html-org-table-to-list-table (lines &optional splice
)
2928 "Convert org-table to list-table.
2929 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
2930 element is a `string' representing a single row of org-table.
2931 Thus each ROW has vertical separators \"|\" separating the table
2932 fields. A ROW could also be a row-group separator of the form
2933 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
2934 ...). ROW could either be symbol `'hline' or a list of the
2935 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
2939 (while (setq line
(pop lines
))
2940 (unless (string-match "^[ \t]*|-" line
)
2941 (push (org-e-html-transcode-table-row line
) lines-1
))))
2942 (t (while (setq line
(pop lines
))
2944 ((string-match "^[ \t]*|-" line
)
2945 (when lines
(push 'hline lines-1
)))
2946 (t (push (org-e-html-transcode-table-row line
) lines-1
))))))
2947 (nreverse lines-1
)))
2949 (defun org-e-html-table-table (raw-table)
2951 (with-current-buffer (get-buffer-create "*org-export-table*")
2953 (let ((output (with-temp-buffer
2956 (re-search-forward "^[ \t]*|[^|]" nil t
)
2957 (table-generate-source 'html
"*org-export-table*")
2958 (with-current-buffer "*org-export-table*"
2959 (org-trim (buffer-string))))))
2960 (kill-buffer (get-buffer "*org-export-table*"))
2963 (defun org-e-html-table (table contents info
)
2964 "Transcode a TABLE element from Org to HTML.
2965 CONTENTS is nil. INFO is a plist holding contextual information."
2966 (let* ((label (org-element-property :name table
))
2967 (caption (org-e-html--caption/label-string
2968 (org-element-property :caption table
) label info
))
2969 (attr (mapconcat #'identity
2970 (org-element-property :attr_html table
)
2972 (raw-table (org-element-property :raw-table table
))
2973 (table-type (org-element-property :type table
)))
2976 (org-e-html-table-table raw-table
))
2978 (let* ((table-info (org-export-table-format-info raw-table
))
2979 (columns-number (length (plist-get table-info
:alignment
)))
2980 (lines (org-split-string
2981 (org-export-clean-table
2982 raw-table
(plist-get table-info
:special-column-p
)) "\n")))
2983 (org-e-html-list-table lines caption label attr
))))))
2988 (defun org-e-html-target (target contents info
)
2989 "Transcode a TARGET object from Org to HTML.
2990 CONTENTS is nil. INFO is a plist holding contextual
2992 (let ((id (org-export-solidify-link-text
2993 (org-element-property :value target
))))
2994 (format "<a id=\"%s\" name=\"%s\"/>" id id
)))
2999 (defun org-e-html-time-stamp (time-stamp contents info
)
3000 "Transcode a TIME-STAMP object from Org to HTML.
3001 CONTENTS is nil. INFO is a plist holding contextual
3003 (let ((value (org-element-property :value time-stamp
))
3004 (type (org-element-property :type time-stamp
))
3005 (appt-type (org-element-property :appt-type time-stamp
)))
3006 (setq value
(org-translate-time
3007 (org-export-secondary-string value
'e-html info
)))
3008 (setq appt-type
(case appt-type
3009 (scheduled org-scheduled-string
)
3010 (deadline org-deadline-string
)
3011 (closed org-closed-string
)))
3012 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
3013 (if (not appt-type
) ""
3014 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type
))
3015 (format "<span class=\"timestamp\">%s</span>" value
))))
3020 (defun org-e-html-verbatim (verbatim contents info
)
3021 "Transcode a VERBATIM object from Org to HTML.
3022 CONTENTS is nil. INFO is a plist used as a communication
3024 (org-e-html-emphasis
3025 verbatim
(org-element-property :value verbatim
) info
))
3030 (defun org-e-html-verse-block (verse-block contents info
)
3031 "Transcode a VERSE-BLOCK element from Org to HTML.
3032 CONTENTS is nil. INFO is a plist holding contextual information."
3033 ;; Replace each newline character with line break. Also replace
3034 ;; each blank line with a line break.
3035 (setq contents
(replace-regexp-in-string
3036 "^ *\\\\\\\\$" "<br/>\n"
3037 (replace-regexp-in-string
3038 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3039 (org-remove-indentation
3040 (org-export-secondary-string
3041 (org-element-property :value verse-block
)
3043 ;; Replace each white space at beginning of a line with a
3044 ;; non-breaking space.
3045 (while (string-match "^[ \t]+" contents
)
3046 (let* ((num-ws (length (match-string 0 contents
)))
3047 (ws (let (out) (dotimes (i num-ws out
)
3048 (setq out
(concat out
" "))))))
3049 (setq contents
(replace-match ws nil t contents
))))
3050 (org-e-html--wrap-label
3051 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3056 ;;; Filter Functions
3058 ;;;; Filter Settings
3060 (defconst org-e-html-filters-alist
3061 '((:filter-final-output . org-e-html-final-function
))
3062 "Alist between filters keywords and back-end specific filters.
3063 See `org-export-filters-alist' for more information.")
3068 (defun org-e-html-final-function (contents backend info
)
3069 (if (not org-e-html-pretty-output
) contents
3073 (indent-region (point-min) (point-max))
3074 (buffer-substring-no-properties (point-min) (point-max)))))
3077 ;;; Interactive functions
3079 (defun org-e-html-export-to-html
3080 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3081 "Export current buffer to a HTML file.
3083 If narrowing is active in the current buffer, only export its
3086 If a region is active, export that region.
3088 When optional argument SUBTREEP is non-nil, export the sub-tree
3089 at point, extracting information from the headline properties
3092 When optional argument VISIBLE-ONLY is non-nil, don't export
3093 contents of hidden elements.
3095 When optional argument BODY-ONLY is non-nil, only write code
3096 between \"\\begin{document}\" and \"\\end{document}\".
3098 EXT-PLIST, when provided, is a property list with external
3099 parameters overriding Org default settings, but still inferior to
3100 file-local settings.
3102 When optional argument PUB-DIR is set, use it as the publishing
3105 Return output file's name."
3109 (with-current-buffer (get-buffer-create "*debug*")
3111 (let* ((extension (concat "." org-e-html-extension
))
3112 (file (org-export-output-file-name extension subtreep pub-dir
)))
3114 'e-html file subtreep visible-only body-only ext-plist
)))
3118 ;;; FIXMES, TODOS, FOR REVIEW etc
3120 ;;;; org-format-table-html
3121 ;;;; org-format-org-table-html
3122 ;;;; org-format-table-table-html
3123 ;;;; org-table-number-fraction
3124 ;;;; org-table-number-regexp
3125 ;;;; org-e-html-table-caption-above
3128 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3129 ;;;; Remove display properties
3131 ;;;; org-e-html-with-timestamp
3132 ;;;; org-e-html-html-helper-timestamp
3134 ;;;; org-export-as-html-and-open
3135 ;;;; org-export-as-html-batch
3136 ;;;; org-export-as-html-to-buffer
3137 ;;;; org-replace-region-by-html
3138 ;;;; org-export-region-as-html
3139 ;;;; org-export-as-html
3141 ;;;; (org-export-directory :html opt-plist)
3142 ;;;; (plist-get opt-plist :html-extension)
3143 ;;;; org-e-html-toplevel-hlevel
3144 ;;;; org-e-html-special-string-regexps
3145 ;;;; org-e-html-coding-system
3146 ;;;; org-e-html-coding-system
3147 ;;;; org-e-html-inline-images
3148 ;;;; org-e-html-inline-image-extensions
3149 ;;;; org-e-html-protect-char-alist
3150 ;;;; org-e-html-table-use-header-tags-for-first-column
3151 ;;;; org-e-html-todo-kwd-class-prefix
3152 ;;;; org-e-html-tag-class-prefix
3153 ;;;; org-e-html-footnote-separator
3155 ;;;; org-export-preferred-target-alist
3156 ;;;; org-solidify-link-text
3157 ;;;; class for anchors
3158 ;;;; org-export-with-section-numbers, body-only
3159 ;;;; org-export-mark-todo-in-toc
3161 (provide 'org-e-html
)
3162 ;;; org-e-html.el ends here