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-data
"org-export" (data info
))
53 (declare-function org-export-directory
"org-export" (type plist
))
54 (declare-function org-export-expand-macro
"org-export" (macro info
))
55 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
56 (declare-function org-export-footnote-first-reference-p
"org-export"
57 (footnote-reference info
))
58 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
59 (declare-function org-export-get-footnote-definition
"org-export"
60 (footnote-reference info
))
61 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
62 (declare-function org-export-get-previous-element
"org-export" (blob info
))
63 (declare-function org-export-get-relative-level
"org-export" (headline info
))
64 (declare-function org-export-handle-code
65 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
66 (declare-function org-export-inline-image-p
"org-export"
67 (link &optional extensions
))
68 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
69 (declare-function org-export-low-level-p
"org-export" (headline info
))
70 (declare-function org-export-output-file-name
71 "org-export" (extension &optional subtreep pub-dir
))
72 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
73 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
74 (declare-function org-export-solidify-link-text
"org-export" (s))
76 org-export-to-buffer
"org-export"
77 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
79 org-export-to-file
"org-export"
80 (backend file
&optional subtreep visible-only body-only ext-plist
))
82 (declare-function org-id-find-id-file
"org-id" (id))
83 (declare-function htmlize-region
"ext:htmlize" (beg end
))
84 (declare-function org-pop-to-buffer-same-window
85 "org-compat" (&optional buffer-or-name norecord label
))
90 ;;; Internal Variables
92 (defconst org-e-html-option-alist
93 '((:agenda-style nil nil org-agenda-export-html-style
)
94 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
95 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
96 ;; (:expand-quoted-html nil "@" org-e-html-expand)
97 (:inline-images nil nil org-e-html-inline-images
)
98 ;; (:link-home nil nil org-e-html-link-home) FIXME
99 ;; (:link-up nil nil org-e-html-link-up) FIXME
100 (:style nil nil org-e-html-style
)
101 (:style-extra nil nil org-e-html-style-extra
)
102 (:style-include-default nil nil org-e-html-style-include-default
)
103 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
104 ;; (:timestamp nil nil org-e-html-with-timestamp)
105 (:html-extension nil nil org-e-html-extension
)
106 (:html-postamble nil nil org-e-html-postamble
)
107 (:html-preamble nil nil org-e-html-preamble
)
108 (:html-table-tag nil nil org-e-html-table-tag
)
109 (:xml-declaration nil nil org-e-html-xml-declaration
)
110 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
111 (:mathjax
"MATHJAX" nil
"" space
))
112 "Alist between export properties and ways to set them.
114 The car of the alist is the property name, and the cdr is a list
115 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
117 KEYWORD is a string representing a buffer keyword, or nil.
118 OPTION is a string that could be found in an #+OPTIONS: line.
119 DEFAULT is the default value for the property.
120 BEHAVIOUR determine how Org should handle multiple keywords for
121 the same property. It is a symbol among:
122 nil Keep old value and discard the new one.
123 t Replace old value with the new one.
124 `space' Concatenate the values, separating them with a space.
125 `newline' Concatenate the values, separating them with
127 `split' Split values at white spaces, and cons them to the
130 KEYWORD and OPTION have precedence over DEFAULT.
132 All these properties should be back-end agnostic. For back-end
133 specific properties, define a similar variable named
134 `org-BACKEND-option-alist', replacing BACKEND with the name of
135 the appropriate back-end. You can also redefine properties
136 there, as they have precedence over these.")
138 ;; FIXME: it already exists in org-e-html.el
139 (defconst org-e-html-cvt-link-fn
141 "Function to convert link URLs to exportable URLs.
142 Takes two arguments, TYPE and PATH.
143 Returns exportable url as (TYPE PATH), or nil to signal that it
144 didn't handle this case.
145 Intended to be locally bound around a call to `org-export-as-html'." )
150 (defvar org-e-html-format-table-no-css
)
151 (defvar htmlize-buffer-places
) ; from htmlize.el
152 (defvar body-only
) ; dynamically scoped into this.
156 ;;; User Configuration Variables
158 (defgroup org-export-e-html nil
159 "Options for exporting Org mode files to HTML."
160 :tag
"Org Export HTML"
165 (defcustom org-e-html-pretty-output nil
166 "Enable this to generate pretty HTML."
167 :group
'org-export-e-html
173 (defcustom org-e-html-extension
"html"
174 "The extension for exported HTML files."
175 :group
'org-export-e-html
178 (defcustom org-e-html-xml-declaration
179 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
180 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
181 "The extension for exported HTML files.
182 %s will be replaced with the charset of the exported file.
183 This may be a string, or an alist with export extensions
184 and corresponding declarations."
185 :group
'org-export-e-html
187 (string :tag
"Single declaration")
188 (repeat :tag
"Dependent on extension"
189 (cons (string :tag
"Extension")
190 (string :tag
"Declaration")))))
192 ;; Use `org-export-coding-system' instead
193 ;; (defcustom org-e-html-coding-system nil
194 ;; "Coding system for HTML export, defaults to `buffer-file-coding-system'."
195 ;; :group 'org-export-e-html
196 ;; :type 'coding-system)
198 (defvar org-e-html-content-div
"content"
199 "The name of the container DIV that holds all the page contents.
201 This variable is obsolete since Org version 7.7.
202 Please set `org-e-html-divs' instead.")
204 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
205 "The name of the main divs for HTML export.
206 This is a list of three strings, the first one for the preamble
207 DIV, the second one for the content DIV and the third one for the
209 :group
'org-export-e-html
211 (string :tag
" Div for the preamble:")
212 (string :tag
" Div for the content:")
213 (string :tag
"Div for the postamble:")))
216 ;;;; Document Header (Styles)
218 (defconst org-e-html-style-default
219 "<style type=\"text/css\">
220 <!--/*--><![CDATA[/*><!--*/
221 html { font-family: Times, serif; font-size: 12pt; }
222 .title { text-align: center; }
223 .todo { color: red; }
224 .done { color: green; }
225 .tag { background-color: #add8e6; font-weight:normal }
227 .timestamp { color: #bebebe; }
228 .timestamp-kwd { color: #5f9ea0; }
229 .right {margin-left:auto; margin-right:0px; text-align:right;}
230 .left {margin-left:0px; margin-right:auto; text-align:left;}
231 .center {margin-left:auto; margin-right:auto; text-align:center;}
232 p.verse { margin-left: 3% }
234 border: 1pt solid #AEBDCC;
235 background-color: #F3F5F7;
237 font-family: courier, monospace;
241 table { border-collapse: collapse; }
242 td, th { vertical-align: top; }
243 th.right { text-align:center; }
244 th.left { text-align:center; }
245 th.center { text-align:center; }
246 td.right { text-align:right; }
247 td.left { text-align:left; }
248 td.center { text-align:center; }
249 dt { font-weight: bold; }
250 div.figure { padding: 0.5em; }
251 div.figure p { text-align: center; }
254 border:2px solid gray;
258 textarea { overflow-x: auto; }
259 .linenr { font-size:smaller }
260 .code-highlighted {background-color:#ffff00;}
261 .org-info-js_info-navigation { border-style:none; }
262 #org-info-js_console-label { font-size:10px; font-weight:bold;
263 white-space:nowrap; }
264 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
268 "The default style specification for exported HTML files.
269 Please use the variables `org-e-html-style' and
270 `org-e-html-style-extra' to add to this style. If you wish to not
271 have the default style included, customize the variable
272 `org-e-html-style-include-default'.")
274 (defcustom org-e-html-style-include-default t
275 "Non-nil means include the default style in exported HTML files.
276 The actual style is defined in `org-e-html-style-default' and should
277 not be modified. Use the variables `org-e-html-style' to add
278 your own style information."
279 :group
'org-export-e-html
282 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
284 (defcustom org-e-html-style
""
285 "Org-wide style definitions for exported HTML files.
287 This variable needs to contain the full HTML structure to provide a style,
288 including the surrounding HTML tags. If you set the value of this variable,
289 you should consider to include definitions for the following classes:
290 title, todo, done, timestamp, timestamp-kwd, tag, target.
292 For example, a valid value would be:
294 <style type=\"text/css\">
296 p { font-weight: normal; color: gray; }
298 .title { text-align: center; }
299 .todo, .timestamp-kwd { color: red; }
300 .done { color: green; }
304 If you'd like to refer to an external style file, use something like
306 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
308 As the value of this option simply gets inserted into the HTML <head> header,
309 you can \"misuse\" it to add arbitrary text to the header.
310 See also the variable `org-e-html-style-extra'."
311 :group
'org-export-e-html
314 (put 'org-e-html-style
'safe-local-variable
'stringp
)
316 (defcustom org-e-html-style-extra
""
317 "Additional style information for HTML export.
318 The value of this variable is inserted into the HTML buffer right after
319 the value of `org-e-html-style'. Use this variable for per-file
320 settings of style information, and do not forget to surround the style
321 settings with <style>...</style> tags."
322 :group
'org-export-e-html
325 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
327 (defcustom org-e-html-mathjax-options
328 '((path "http://orgmode.org/mathjax/MathJax.js")
333 "Options for MathJax setup.
335 path The path where to find MathJax
336 scale Scaling for the HTML-CSS backend, usually between 100 and 133
337 align How to align display math: left, center, or right
338 indent If align is not center, how far from the left/right side?
339 mathml Should a MathML player be used if available?
340 This is faster and reduces bandwidth use, but currently
341 sometimes has lower spacing quality. Therefore, the default is
342 nil. When browsers get better, this switch can be flipped.
344 You can also customize this for each buffer, using something like
346 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
347 :group
'org-export-e-html
348 :type
'(list :greedy t
349 (list :tag
"path (the path from where to load MathJax.js)"
350 (const :format
" " path
) (string))
351 (list :tag
"scale (scaling for the displayed math)"
352 (const :format
" " scale
) (string))
353 (list :tag
"align (alignment of displayed equations)"
354 (const :format
" " align
) (string))
355 (list :tag
"indent (indentation with left or right alignment)"
356 (const :format
" " indent
) (string))
357 (list :tag
"mathml (should MathML display be used is possible)"
358 (const :format
" " mathml
) (boolean))))
361 ;;;; Document Header (Scripts)
363 (defcustom org-e-html-style-include-scripts t
364 "Non-nil means include the JavaScript snippets in exported HTML files.
365 The actual script is defined in `org-e-html-scripts' and should
367 :group
'org-export-e-html
370 (defconst org-e-html-scripts
371 "<script type=\"text/javascript\">
372 <!--/*--><![CDATA[/*><!--*/
373 function CodeHighlightOn(elem, id)
375 var target = document.getElementById(id);
377 elem.cacheClassElem = elem.className;
378 elem.cacheClassTarget = target.className;
379 target.className = \"code-highlighted\";
380 elem.className = \"code-highlighted\";
383 function CodeHighlightOff(elem, id)
385 var target = document.getElementById(id);
386 if(elem.cacheClassElem)
387 elem.className = elem.cacheClassElem;
388 if(elem.cacheClassTarget)
389 target.className = elem.cacheClassTarget;
393 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
396 ;;;; Document Header (Mathjax)
398 (defcustom org-e-html-mathjax-template
399 "<script type=\"text/javascript\" src=\"%PATH\">
400 <!--/*--><![CDATA[/*><!--*/
402 // Only one of the two following lines, depending on user settings
403 // First allows browser-native MathML display, second forces HTML/CSS
404 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
405 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
406 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
407 \"TeX/noUndefined.js\"],
409 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
410 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
411 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
412 ignoreClass: \"tex2jax_ignore\",
413 processEscapes: false,
414 processEnvironments: true,
417 showProcessingMessages: true,
418 displayAlign: \"%ALIGN\",
419 displayIndent: \"%INDENT\",
423 availableFonts: [\"STIX\",\"TeX\"],
424 preferredFont: \"TeX\",
440 "The MathJax setup for XHTML files."
441 :group
'org-export-e-html
447 (defcustom org-e-html-preamble t
448 "Non-nil means insert a preamble in HTML export.
450 When `t', insert a string as defined by one of the formatting
451 strings in `org-e-html-preamble-format'. When set to a
452 string, this string overrides `org-e-html-preamble-format'.
453 When set to a function, apply this function and insert the
454 returned string. The function takes the property list of export
455 options as its only argument.
457 Setting :html-preamble in publishing projects will take
458 precedence over this variable."
459 :group
'org-export-e-html
460 :type
'(choice (const :tag
"No preamble" nil
)
461 (const :tag
"Default preamble" t
)
462 (string :tag
"Custom formatting string")
463 (function :tag
"Function (must return a string)")))
465 (defcustom org-e-html-preamble-format
'(("en" ""))
466 "The format for the HTML preamble.
468 %t stands for the title.
469 %a stands for the author's name.
470 %e stands for the author's email.
471 %d stands for the date.
473 If you need to use a \"%\" character, you need to escape it
475 :group
'org-export-e-html
478 (defcustom org-e-html-home
/up-format
479 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
480 <a accesskey=\"h\" href=\"%s\"> UP </a>
482 <a accesskey=\"H\" href=\"%s\"> HOME </a>
484 "Snippet used to insert the HOME and UP links.
485 This is a format string, the first %s will receive the UP link,
486 the second the HOME link. If both `org-e-html-link-up' and
487 `org-e-html-link-home' are empty, the entire snippet will be
489 :group
'org-export-e-html
494 (defcustom org-e-html-postamble
'auto
495 "Non-nil means insert a postamble in HTML export.
497 When `t', insert a string as defined by the formatting string in
498 `org-e-html-postamble-format'. When set to a string, this
499 string overrides `org-e-html-postamble-format'. When set to
500 'auto, discard `org-e-html-postamble-format' and honor
501 `org-export-author/email/creator-info' variables. When set to a
502 function, apply this function and insert the returned string.
503 The function takes the property list of export options as its
506 Setting :html-postamble in publishing projects will take
507 precedence over this variable."
508 :group
'org-export-e-html
509 :type
'(choice (const :tag
"No postamble" nil
)
510 (const :tag
"Auto preamble" 'auto
)
511 (const :tag
"Default formatting string" t
)
512 (string :tag
"Custom formatting string")
513 (function :tag
"Function (must return a string)")))
515 (defcustom org-e-html-postamble-format
516 '(("en" "<p class=\"author\">Author: %a (%e)</p>
517 <p class=\"date\">Date: %d</p>
518 <p class=\"creator\">Generated by %c</p>
519 <p class=\"xhtml-validation\">%v</p>
521 "The format for the HTML postamble.
523 %a stands for the author's name.
524 %e stands for the author's email.
525 %d stands for the date.
526 %c will be replaced by information about Org/Emacs versions.
527 %v will be replaced by `org-e-html-validation-link'.
529 If you need to use a \"%\" character, you need to escape it
531 :group
'org-export-e-html
534 (defcustom org-e-html-validation-link
535 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
536 "Link to HTML validation service."
537 :group
'org-export-e-html
540 ;; FIXME Obsolete since Org 7.7
541 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
544 (defcustom org-e-html-protect-char-alist
548 "Alist of characters to be converted by `org-e-html-protect'."
549 :group
'org-export-e-html
550 :type
'(repeat (cons (string :tag
"Character")
551 (string :tag
"HTML equivalent"))))
553 (defconst org-e-html-special-string-regexps
554 '(("\\\\-" .
"­")
555 ("---\\([^-]\\)" .
"—\\1")
556 ("--\\([^-]\\)" .
"–\\1")
557 ("\\.\\.\\." .
"…"))
558 "Regular expressions for special string conversion.")
563 (defcustom org-e-html-todo-kwd-class-prefix
""
564 "Prefix to class names for TODO keywords.
565 Each TODO keyword gets a class given by the keyword itself, with this prefix.
566 The default prefix is empty because it is nice to just use the keyword
567 as a class name. But if you get into conflicts with other, existing
568 CSS classes, then this prefix can be very useful."
569 :group
'org-export-e-html
575 (defcustom org-e-html-tag-class-prefix
""
576 "Prefix to class names for TODO keywords.
577 Each tag gets a class given by the tag itself, with this prefix.
578 The default prefix is empty because it is nice to just use the keyword
579 as a class name. But if you get into conflicts with other, existing
580 CSS classes, then this prefix can be very useful."
581 :group
'org-export-e-html
585 ;;;; Statistics Cookie
591 (defcustom org-e-html-inline-images
'maybe
592 "Non-nil means inline images into exported HTML pages.
593 This is done using an <img> tag. When nil, an anchor with href is used to
594 link to the image. If this option is `maybe', then images in links with
595 an empty description will be inlined, while images with a description will
597 :group
'org-export-e-html
598 :type
'(choice (const :tag
"Never" nil
)
599 (const :tag
"Always" t
)
600 (const :tag
"When there is no description" maybe
)))
602 (defcustom org-e-html-inline-image-extensions
603 '("png" "jpeg" "jpg" "gif" "svg")
604 "Extensions of image files that can be inlined into HTML."
605 :group
'org-export-e-html
606 :type
'(repeat (string :tag
"Extension")))
622 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
623 <h2 class=\"footnotes\">%s: </h2>
624 <div id=\"text-footnotes\">
628 "Format for the footnotes section.
629 Should contain a two instances of %s. The first will be replaced with the
630 language-specific word for \"Footnotes\", the second one will be replaced
631 by the footnotes themselves."
632 :group
'org-export-e-html
635 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
636 "The format for the footnote reference.
637 %s will be replaced by the footnote reference itself."
638 :group
'org-export-e-html
641 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
642 "Text used to separate footnotes."
643 :group
'org-export-e-html
649 ;;;; Inline Babel Call
650 ;;;; Inline Src Block
654 ;;;; Latex Environment
671 (defgroup org-export-e-htmlize nil
672 "Options for processing examples with htmlize.el."
673 :tag
"Org Export Htmlize"
674 :group
'org-export-e-html
)
676 (defcustom org-export-e-htmlize-output-type
'inline-css
677 "Output type to be used by htmlize when formatting code snippets.
678 Choices are `css', to export the CSS selectors only, or `inline-css', to
679 export the CSS attribute values inline in the HTML. We use as default
680 `inline-css', in order to make the resulting HTML self-containing.
682 However, this will fail when using Emacs in batch mode for export, because
683 then no rich font definitions are in place. It will also not be good if
684 people with different Emacs setup contribute HTML files to a website,
685 because the fonts will represent the individual setups. In these cases,
686 it is much better to let Org/Htmlize assign classes only, and to use
687 a style file to define the look of these classes.
688 To get a start for your css file, start Emacs session and make sure that
689 all the faces you are interested in are defined, for example by loading files
690 in all modes you want. Then, use the command
691 \\[org-export-e-htmlize-generate-css] to extract class definitions."
692 :group
'org-export-e-htmlize
693 :type
'(choice (const css
) (const inline-css
)))
695 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
696 "The prefix for CSS class names for htmlize font specifications."
697 :group
'org-export-e-htmlize
700 (defcustom org-export-e-htmlized-org-css-url nil
701 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
702 Normally when creating an htmlized version of an Org buffer, htmlize will
703 create CSS to define the font colors. However, this does not work when
704 converting in batch mode, and it also can look bad if different people
705 with different fontification setup work on the same website.
706 When this variable is non-nil, creating an htmlized version of an Org buffer
707 using `org-export-as-org' will remove the internal CSS section and replace it
708 with a link to this URL."
709 :group
'org-export-e-htmlize
711 (const :tag
"Keep internal css" nil
)
712 (string :tag
"URL or local href")))
717 (defcustom org-e-html-table-tag
718 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
719 "The HTML tag that is used to start a table.
720 This must be a <table> tag, but you may change the options like
721 borders and spacing."
722 :group
'org-export-e-html
725 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
726 "The opening tag for table header fields.
727 This is customizable so that alignment options can be specified.
728 The first %s will be filled with the scope of the field, either row or col.
729 The second %s will be replaced by a style entry to align the field.
730 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
731 See also the variable `org-e-html-table-align-individual-fields'."
732 :group
'org-export-tables
; FIXME: change group?
733 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
735 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
736 "The opening tag for table data fields.
737 This is customizable so that alignment options can be specified.
738 The first %s will be filled with the scope of the field, either row or col.
739 The second %s will be replaced by a style entry to align the field.
740 See also the variable `org-e-html-table-align-individual-fields'."
741 :group
'org-export-tables
742 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
744 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
745 "The opening tag for table data fields.
746 This is customizable so that alignment options can be specified.
747 Instead of strings, these can be Lisp forms that will be evaluated
748 for each row in order to construct the table row tags. During evaluation,
749 the variable `head' will be true when this is a header line, nil when this
750 is a body line. And the variable `nline' will contain the line number,
751 starting from 1 in the first header line. For example
753 (setq org-e-html-table-row-tags
756 (if (= (mod nline 2) 1)
757 \"<tr class=\\\"tr-odd\\\">\"
758 \"<tr class=\\\"tr-even\\\">\"))
761 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
762 :group
'org-export-tables
764 (choice :tag
"Opening tag"
765 (string :tag
"Specify")
767 (choice :tag
"Closing tag"
768 (string :tag
"Specify")
771 (defcustom org-e-html-table-align-individual-fields t
772 "Non-nil means attach style attributes for alignment to each table field.
773 When nil, alignment will only be specified in the column tags, but this
774 is ignored by some browsers (like Firefox, Safari). Opera does it right
776 :group
'org-export-tables
779 (defcustom org-e-html-table-use-header-tags-for-first-column nil
780 "Non-nil means format column one in tables with header tags.
781 When nil, also column one will use data tags."
782 :group
'org-export-tables
793 (defcustom org-e-html-toplevel-hlevel
2
794 "The <H> level for level 1 headings in HTML export.
795 This is also important for the classes that will be wrapped around headlines
796 and outline structure. If this variable is 1, the top-level headlines will
797 be <h1>, and the corresponding classes will be outline-1, section-number-1,
798 and outline-text-1. If this is 2, all of these will get a 2 instead.
799 The default for this variable is 2, because we use <h1> for formatting the
801 :group
'org-export-e-html
810 (defcustom org-e-html-link-org-files-as-html t
811 "Non-nil means make file links to `file.org' point to `file.html'.
812 When org-mode is exporting an org-mode file to HTML, links to
813 non-html files are directly put into a href tag in HTML.
814 However, links to other Org-mode files (recognized by the
815 extension `.org.) should become links to the corresponding html
816 file, assuming that the linked org-mode file will also be
818 When nil, the links still point to the plain `.org' file."
819 :group
'org-export-e-html
827 ;;; User Configurable Variables (MAYBE)
831 (defcustom org-e-html-date-format
833 "Format string for \\date{...}."
834 :group
'org-export-e-html
839 (defcustom org-e-html-format-headline-function nil
840 "Function to format headline text.
842 This function will be called with 5 arguments:
843 TODO the todo keyword (string or nil).
844 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
845 PRIORITY the priority of the headline (integer or nil)
846 TEXT the main headline text (string).
847 TAGS the tags (string or nil).
849 The function result will be used in the section format string.
851 As an example, one could set the variable to the following, in
852 order to reproduce the default set-up:
854 \(defun org-e-html-format-headline \(todo todo-type priority text tags)
855 \"Default format function for an headline.\"
857 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
859 \(format \"\\\\framebox{\\\\#%c} \" priority))
861 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
862 :group
'org-export-e-html
868 (defcustom org-e-html-text-markup-alist
869 '((bold .
"<b>%s</b>")
870 (code .
"<code>%s</code>")
871 (italic .
"<i>%s</i>")
872 (strike-through .
"<del>%s</del>")
873 (underline .
"<span style=\"text-decoration:underline;\">%s</span>")
874 (verbatim .
"<code>%s</code>"))
875 "Alist of HTML expressions to convert text markup
877 The key must be a symbol among `bold', `code', `italic',
878 `strike-through', `underline' and `verbatim'. The value is
879 a formatting string to wrap fontified text with.
881 If no association can be found for a given markup, text will be
883 :group
'org-export-e-html
884 :type
'(alist :key-type
(symbol :tag
"Markup type")
885 :value-type
(string :tag
"Format string"))
886 :options
'(bold code italic strike-through underline verbatim
))
891 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
892 "Text used to separate footnotes."
893 :group
'org-export-e-html
899 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
900 "A printf format string to be applied to active timestamps."
901 :group
'org-export-e-html
904 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
905 "A printf format string to be applied to inactive timestamps."
906 :group
'org-export-e-html
909 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
910 "A printf format string to be applied to diary timestamps."
911 :group
'org-export-e-html
917 (defcustom org-e-html-inline-image-rules
918 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
919 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
920 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
921 "Rules characterizing image files that can be inlined into HTML.
923 A rule consists in an association whose key is the type of link
924 to consider, and value is a regexp that will be matched against
927 Note that, by default, the image extension *actually* allowed
928 depend on the way the HTML file is processed. When used with
929 pdflatex, pdf, jpg and png images are OK. When processing
930 through dvi to Postscript, only ps and eps are allowed. The
931 default we use here encompasses both."
932 :group
'org-export-e-html
933 :type
'(alist :key-type
(string :tag
"Type")
934 :value-type
(regexp :tag
"Path")))
938 (defcustom org-e-html-table-caption-above t
939 "When non-nil, place caption string at the beginning of the table.
940 Otherwise, place it near the end."
941 :group
'org-export-e-html
946 (defcustom org-e-html-format-drawer-function nil
947 "Function called to format a drawer in HTML code.
949 The function must accept two parameters:
950 NAME the drawer name, like \"LOGBOOK\"
951 CONTENTS the contents of the drawer.
953 The function should return the string to be exported.
955 For example, the variable could be set to the following function
956 in order to mimic default behaviour:
958 \(defun org-e-html-format-drawer-default \(name contents\)
959 \"Format a drawer element for HTML export.\"
961 :group
'org-export-e-html
967 (defcustom org-e-html-format-inlinetask-function nil
968 "Function called to format an inlinetask in HTML code.
970 The function must accept six parameters:
971 TODO the todo keyword, as a string
972 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
973 PRIORITY the inlinetask priority, as a string
974 NAME the inlinetask name, as a string.
975 TAGS the inlinetask tags, as a list of strings.
976 CONTENTS the contents of the inlinetask, as a string.
978 The function should return the string to be exported.
980 For example, the variable could be set to the following function
981 in order to mimic default behaviour:
983 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
984 \"Format an inline task element for HTML export.\"
988 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
989 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
991 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
992 \(format (concat \"\\\\begin{center}\\n\"
994 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
996 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
998 \"\\\\end{minipage}}\"
1000 full-title contents))"
1001 :group
'org-export-e-html
1009 (defcustom org-e-html-quotes
1011 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"«~")
1012 ("\\(\\S-\\)\"" .
"~»")
1013 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
1015 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"``")
1016 ("\\(\\S-\\)\"" .
"''")
1017 ("\\(\\s-\\|(\\|^\\)'" .
"`")))
1018 "Alist for quotes to use when converting english double-quotes.
1020 The CAR of each item in this alist is the language code.
1021 The CDR of each item in this alist is a list of three CONS:
1022 - the first CONS defines the opening quote;
1023 - the second CONS defines the closing quote;
1024 - the last CONS defines single quotes.
1026 For each item in a CONS, the first string is a regexp
1027 for allowed characters before/after the quote, the second
1028 string defines the replacement string for this quote."
1029 :group
'org-export-e-html
1031 (cons :tag
"Opening quote"
1032 (string :tag
"Regexp for char before")
1033 (string :tag
"Replacement quote "))
1034 (cons :tag
"Closing quote"
1035 (string :tag
"Regexp for char after ")
1036 (string :tag
"Replacement quote "))
1037 (cons :tag
"Single quote"
1038 (string :tag
"Regexp for char before")
1039 (string :tag
"Replacement quote "))))
1045 ;;; Internal Functions (HTML)
1047 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1048 "Convert an org filename to an equivalent html filename.
1049 If TYPE is not file, just return `nil'.
1050 See variable `org-e-html-link-org-files-as-html'."
1053 org-e-html-link-org-files-as-html
1054 (string= type
"file")
1055 (string-match "\\.org$" path
)
1060 (substring path
0 (match-beginning 0))
1061 "." (plist-get opt-plist
:html-extension
)))))))
1063 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1066 OPT-PLIST is an options list.
1067 TYPE is the device-type of the link (THIS://foo.html).
1068 PATH is the path of the link (http://THIS#location).
1069 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1070 DESC is the link description, if any.
1071 ATTR is a string of other attributes of the \"a\" element."
1072 (declare (special org-lparse-par-open
))
1074 (let* ((may-inline-p
1075 (and (member type-1
'("http" "https" "file"))
1076 (org-lparse-should-inline-p path descp
)
1078 (type (if (equal type-1
"id") "file" type-1
))
1080 ;;First pass. Just sanity stuff.
1083 ((string= type
"file")
1086 ;;Substitute just if original path was absolute.
1087 ;;(Otherwise path must remain relative)
1088 (if (file-name-absolute-p path
)
1089 (concat "file://" (expand-file-name path
))
1093 (t (list type path
))))
1095 ;;Second pass. Components converted so they can refer
1099 (and org-e-html-cvt-link-fn
1100 (apply org-e-html-cvt-link-fn
1101 opt-plist components-1
))
1102 (apply #'org-e-html-cvt-org-as-html
1103 opt-plist components-1
)
1105 (type (first components-2
))
1106 (thefile (second components-2
)))
1109 ;;Third pass. Build final link except for leading type
1114 (string= type
"http")
1115 (string= type
"https")
1116 (string= type
"file")
1117 (string= type
"coderef"))
1119 (setq thefile
(concat thefile
"#" fragment
))))
1123 ;;Final URL-build, for all types.
1126 ((str (org-xml-format-href thefile
)))
1127 (if (and type
(not (or (string= "file" type
)
1128 (string= "coderef" type
))))
1129 (concat type
":" str
)
1133 (ignore) ;; (org-e-html-format-image thefile)
1135 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1137 ;; (caption (and caption (org-xml-encode-org-text caption)))
1138 ;; alt = (file-name-nondirectory path)
1140 (defun org-e-html-format-inline-image (src &optional
1141 caption label attr standalone-p
)
1142 (let* ((id (if (not label
) ""
1143 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1146 ((string-match "\\<alt=" (or attr
"")) "")
1147 ((string-match "^ltxpng/" src
)
1148 (format " alt=\"%s\""
1149 (org-e-html-encode-plain-text
1150 (org-find-text-property-in-string
1151 'org-latex-src src
))))
1152 (t (format " alt=\"%s\""
1153 (file-name-nondirectory src
)))))))
1156 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1157 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1158 id
(format "\n<p>%s</p>" img
)
1159 (when caption
(format "\n<p>%s</p>" caption
)))))
1160 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1164 (defun org-e-html-bibliography ()
1165 "Find bibliography, cut it out and return it."
1167 (let (beg end
(cnt 1) bib
)
1169 (goto-char (point-min))
1170 (when (re-search-forward
1171 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1172 (setq beg
(match-beginning 0))
1173 (while (re-search-forward "</?div\\>" nil t
)
1174 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1176 (and (looking-at ">") (forward-char 1))
1177 (setq bib
(buffer-substring beg
(point)))
1178 (delete-region beg
(point))
1179 (throw 'exit bib
))))
1184 (defun org-e-html-format-table (lines olines
)
1185 (let ((org-e-html-format-table-no-css nil
))
1186 (org-lparse-format-table lines olines
)))
1188 (defun org-e-html-splice-attributes (tag attributes
)
1189 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1190 (if (not attributes
)
1192 (let (oldatt newatt
)
1193 (setq oldatt
(org-extract-attributes-from-string tag
)
1195 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1197 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1198 (if (string-match ">" tag
)
1200 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1204 (defun org-export-splice-style (style extra
)
1205 "Splice EXTRA into STYLE, just before \"</style>\"."
1206 (if (and (stringp extra
)
1207 (string-match "\\S-" extra
)
1208 (string-match "</style>" style
))
1209 (concat (substring style
0 (match-beginning 0))
1211 (substring style
(match-beginning 0)))
1214 (defun org-export-e-htmlize-region-for-paste (beg end
)
1215 "Convert the region to HTML, using htmlize.el.
1216 This is much like `htmlize-region-for-paste', only that it uses
1217 the settings define in the org-... variables."
1218 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1219 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1220 (htmlbuf (htmlize-region beg end
)))
1222 (with-current-buffer htmlbuf
1223 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1224 (plist-get htmlize-buffer-places
'content-end
)))
1225 (kill-buffer htmlbuf
))))
1228 (defun org-export-e-htmlize-generate-css ()
1229 "Create the CSS for all font definitions in the current Emacs session.
1230 Use this to create face definitions in your CSS style file that can then
1231 be used by code snippets transformed by htmlize.
1232 This command just produces a buffer that contains class definitions for all
1233 faces used in the current Emacs session. You can copy and paste the ones you
1234 need into your CSS file.
1236 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1237 the function `org-export-e-htmlize-region-for-paste' will produce code
1238 that uses these same face definitions."
1241 (and (get-buffer "*html*") (kill-buffer "*html*"))
1243 (let ((fl (face-list))
1244 (htmlize-css-name-prefix "org-")
1245 (htmlize-output-type 'css
)
1247 (while (setq f
(pop fl
)
1248 i
(and f
(face-attribute f
:inherit
)))
1249 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1250 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1251 (htmlize-region (point-min) (point-max))))
1252 (org-pop-to-buffer-same-window "*html*")
1253 (goto-char (point-min))
1254 (if (re-search-forward "<style" nil t
)
1255 (delete-region (point-min) (match-beginning 0)))
1256 (if (re-search-forward "</style>" nil t
)
1257 (delete-region (1+ (match-end 0)) (point-max)))
1258 (beginning-of-line 1)
1259 (if (looking-at " +") (replace-match ""))
1260 (goto-char (point-min)))
1262 (defun org-e-html-make-string (n string
)
1263 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1265 (defun org-e-html-toc-text (toc-entries)
1266 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1267 (start-level prev-level
))
1271 (let ((headline (nth 0 entry
))
1272 (level (nth 1 entry
)))
1274 (let* ((cnt (- level prev-level
))
1275 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1277 (setq prev-level level
)
1279 (org-e-html-make-string
1280 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1281 ((< cnt
0) "</li>\n</ul>\n")))
1282 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1285 (org-e-html-make-string
1286 (- prev-level start-level
) "</li>\n</ul>\n"))))
1288 (defun* org-e-html-format-toc-headline
1289 (todo todo-type priority text tags
1290 &key level section-number headline-label
&allow-other-keys
)
1291 (let ((headline (concat
1292 section-number
(and section-number
". ")
1294 (and tags
" ") (org-e-html--tags tags
))))
1295 (format "<a href=\"#%s\">%s</a>"
1297 (if (not nil
) headline
1298 (format "<span class=\"%s\">%s</span>" todo-type headline
)))))
1300 (defun org-e-html-toc (depth info
)
1301 (assert (wholenump depth
))
1302 (let* ((headlines (org-export-collect-headlines info depth
))
1304 (loop for headline in headlines collect
1305 (list (org-e-html-format-headline--wrap
1306 headline info
'org-e-html-format-toc-headline
)
1307 (org-export-get-relative-level headline info
)))))
1309 (let* ((lang-specific-heading
1310 (nth 3 (or (assoc (plist-get info
:language
)
1311 org-export-language-setup
)
1312 (assoc "en" org-export-language-setup
)))))
1314 "<div id=\"table-of-contents\">\n"
1315 (format "<h%d>%s</h%d>\n"
1316 org-e-html-toplevel-hlevel
1317 lang-specific-heading
1318 org-e-html-toplevel-hlevel
)
1319 "<div id=\"text-table-of-contents\">"
1320 (org-e-html-toc-text toc-entries
)
1324 ;; (defun org-e-html-format-line (line)
1325 ;; (case org-lparse-dyn-current-environment
1326 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1327 ;; (t (concat line "\n"))))
1329 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1330 "Turn todo keyword into a valid class name.
1331 Replaces invalid characters with \"_\"."
1333 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1334 (setq kwd
(replace-match "_" t t kwd
))))
1337 (defun org-e-html-format-footnote-reference (n def refcnt
)
1338 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1339 (format org-e-html-footnote-format
1341 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1344 (defun org-e-html-format-footnotes-section (section-name definitions
)
1345 (if (not definitions
) ""
1346 (format org-e-html-footnotes-section section-name definitions
)))
1348 (defun org-e-html-format-footnote-definition (fn)
1349 (let ((n (car fn
)) (def (cdr fn
)))
1351 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1353 (format org-e-html-footnote-format
1354 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1357 (defun org-e-html-footnote-section (info)
1358 (let* ((fn-alist (org-export-collect-footnote-definitions
1359 (plist-get info
:parse-tree
) info
))
1362 (loop for
(n type raw
) in fn-alist collect
1363 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1364 (org-trim (org-export-data raw info
))
1366 (org-trim (org-export-data raw info
))))))))
1368 (org-e-html-format-footnotes-section
1369 (nth 4 (or (assoc (plist-get info
:language
)
1370 org-export-language-setup
)
1371 (assoc "en" org-export-language-setup
)))
1373 "<table>\n%s\n</table>\n"
1374 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1376 (defun org-e-html-format-date (info)
1377 (let ((date (plist-get info
:date
)))
1379 ((and date
(string-match "%" date
))
1380 (format-time-string date
))
1382 (t (format-time-string "%Y-%m-%d %T %Z")))))
1386 ;;; Internal Functions (Ngz)
1388 (defun org-e-html--caption/label-string
(caption label info
)
1389 "Return caption and label HTML string for floats.
1391 CAPTION is a cons cell of secondary strings, the car being the
1392 standard caption and the cdr its short form. LABEL is a string
1393 representing the label. INFO is a plist holding contextual
1396 If there's no caption nor label, return the empty string.
1398 For non-floats, see `org-e-html--wrap-label'."
1399 (setq label nil
) ;; FIXME
1401 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1403 ((and (not caption
) (not label
)) "")
1404 ((not caption
) (format "\\label{%s}\n" label
))
1405 ;; Option caption format with short name.
1407 (format "\\caption[%s]{%s%s}\n"
1408 (org-export-data (cdr caption
) info
)
1410 (org-export-data (car caption
) info
)))
1411 ;; Standard caption format.
1412 ;; (t (format "\\caption{%s%s}\n"
1414 ;; (org-export-data (car caption) info)))
1415 (t (org-export-data (car caption
) info
)))))
1417 (defun org-e-html--find-verb-separator (s)
1418 "Return a character not used in string S.
1419 This is used to choose a separator for constructs like \\verb."
1420 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1421 (loop for c across ll
1422 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1423 return
(char-to-string c
))))
1425 (defun org-e-html--quotation-marks (text info
)
1426 "Export quotation marks depending on language conventions.
1427 TEXT is a string containing quotation marks to be replaced. INFO
1428 is a plist used as a communication channel."
1431 (while (setq start
(string-match (car l
) text start
))
1432 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1433 (setq text
(replace-match new-quote t t text
))))))
1434 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1435 ;; Falls back on English.
1436 (assoc "en" org-e-html-quotes
))))
1439 (defun org-e-html--wrap-label (element output
)
1440 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1441 This function shouldn't be used for floats. See
1442 `org-e-html--caption/label-string'."
1443 ;; (let ((label (org-element-property :name element)))
1444 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1446 ;; (concat (format "\\label{%s}\n" label) output)))
1453 (defun org-e-html-meta-info (info)
1454 (let* ((title (org-export-data (plist-get info
:title
) info
))
1455 (author (and (plist-get info
:with-author
)
1456 (let ((auth (plist-get info
:author
)))
1457 (and auth
(org-export-data auth info
)))))
1458 (description (plist-get info
:description
))
1459 (keywords (plist-get info
:keywords
)))
1461 (format "\n<title>%s</title>\n" title
)
1463 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1464 (or (and org-export-coding-system
1465 (fboundp 'coding-system-get
)
1466 (coding-system-get org-export-coding-system
1469 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1470 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1471 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1472 (org-e-html-format-date info
))
1473 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1474 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1475 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1477 (defun org-e-html-style (info)
1479 "\n" (when (plist-get info
:style-include-default
) org-e-html-style-default
)
1480 (plist-get info
:style
)
1481 (plist-get info
:style-extra
)
1483 (when (plist-get info
:style-include-scripts
)
1484 org-e-html-scripts
)))
1486 (defun org-e-html-mathjax-config (info)
1487 "Insert the user setup into the matchjax template."
1488 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1489 (let ((template org-e-html-mathjax-template
)
1490 (options org-e-html-mathjax-options
)
1491 (in-buffer (or (plist-get info
:mathjax
) ""))
1492 name val
(yes " ") (no "// ") x
)
1495 (setq name
(car e
) val
(nth 1 e
))
1496 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1497 (setq val
(car (read-from-string
1498 (substring in-buffer
(match-end 0))))))
1499 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1500 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1501 (setq template
(replace-match val t t template
))))
1503 (setq val
(nth 1 (assq 'mathml options
)))
1504 (if (string-match (concat "\\<mathml:") in-buffer
)
1505 (setq val
(car (read-from-string
1506 (substring in-buffer
(match-end 0))))))
1507 ;; Exchange prefixes depending on mathml setting
1508 (if (not val
) (setq x yes yes no no x
))
1509 ;; Replace cookies to turn on or off the config/jax lines
1510 (if (string-match ":MMLYES:" template
)
1511 (setq template
(replace-match yes t t template
)))
1512 (if (string-match ":MMLNO:" template
)
1513 (setq template
(replace-match no t t template
)))
1514 ;; Return the modified template
1517 (defun org-e-html-preamble (info)
1518 (when (plist-get info
:html-preamble
)
1519 (let* ((title (org-export-data (plist-get info
:title
) info
))
1520 (date (org-e-html-format-date info
))
1521 (author (org-export-data (plist-get info
:author
) info
))
1522 (lang-words (or (assoc (plist-get info
:language
)
1523 org-export-language-setup
)
1524 (assoc "en" org-export-language-setup
)))
1525 (email (plist-get info
:email
))
1526 (html-pre-real-contents
1528 ((functionp (plist-get info
:html-preamble
))
1530 (funcall (plist-get info
:html-preamble
))
1532 ((stringp (plist-get info
:html-preamble
))
1533 (format-spec (plist-get info
:html-preamble
)
1534 `((?t .
,title
) (?a .
,author
)
1535 (?d .
,date
) (?e .
,email
))))
1538 (or (cadr (assoc (nth 0 lang-words
)
1539 org-e-html-preamble-format
))
1540 (cadr (assoc "en" org-e-html-preamble-format
)))
1541 `((?t .
,title
) (?a .
,author
)
1542 (?d .
,date
) (?e .
,email
)))))))
1543 (when (not (equal html-pre-real-contents
""))
1546 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1549 html-pre-real-contents
1553 (defun org-e-html-postamble (info)
1555 (when (and (not body-only
)
1556 (plist-get info
:html-postamble
))
1557 (let* ((html-post (plist-get info
:html-postamble
))
1558 (date (org-e-html-format-date info
))
1559 (author (plist-get info
:author
))
1560 (email (plist-get info
:email
))
1561 (lang-words (or (assoc (plist-get info
:language
)
1562 org-export-language-setup
)
1563 (assoc "en" org-export-language-setup
)))
1565 (mapconcat (lambda(e)
1566 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1567 (split-string email
",+ *")
1569 (html-validation-link (or org-e-html-validation-link
""))
1570 (creator-info org-export-creator-string
))
1574 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1577 ((eq (plist-get info
:html-postamble
) 'auto
)
1579 (when (plist-get info
:time-stamp-file
)
1581 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1582 (when (and (plist-get info
:with-author
) author
)
1584 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1585 (when (and (plist-get info
:with-email
) email
)
1587 <p class=\"email\"> %s </p>" email
))
1588 (when (plist-get info
:with-creator
)
1590 <p class=\"creator\"> %s </p>" creator-info
))
1591 html-validation-link
"\n"))
1592 ;; postamble from a string
1593 ((stringp (plist-get info
:html-postamble
))
1594 (format-spec (plist-get info
:html-postamble
)
1595 `((?a .
,author
) (?e .
,email
)
1596 (?d .
,date
) (?c .
,creator-info
)
1597 (?v .
,html-validation-link
))))
1599 ;; postamble from a function
1600 ((functionp (plist-get info
:html-postamble
))
1602 (funcall (plist-get info
:html-postamble
))
1604 ;; default postamble
1607 (or (cadr (assoc (nth 0 lang-words
)
1608 org-e-html-postamble-format
))
1609 (cadr (assoc "en" org-e-html-postamble-format
)))
1610 `((?a .
,author
) (?e .
,email
)
1611 (?d .
,date
) (?c .
,creator-info
)
1612 (?v .
,html-validation-link
)))))
1615 ;; org-e-html-html-helper-timestamp
1618 (defun org-e-html-template (contents info
)
1619 "Return complete document string after HTML conversion.
1620 CONTENTS is the transcoded contents string. RAW-DATA is the
1621 original parsed data. INFO is a plist holding export options."
1624 (or (and (stringp org-e-html-xml-declaration
)
1625 org-e-html-xml-declaration
)
1626 (cdr (assoc (plist-get info
:html-extension
)
1627 org-e-html-xml-declaration
))
1628 (cdr (assoc "html" org-e-html-xml-declaration
))
1631 (or (and coding-system-for-write
1632 (fboundp 'coding-system-get
)
1633 (coding-system-get coding-system-for-write
1637 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1638 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1640 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1641 (plist-get info
:language
) (plist-get info
:language
))
1644 (org-e-html-meta-info info
) ; meta
1645 (org-e-html-style info
) ; style
1646 (org-e-html-mathjax-config info
) ; mathjax
1652 (let ((link-up (and (plist-get info
:link-up
)
1653 (string-match "\\S-" (plist-get info
:link-up
))
1654 (plist-get info
:link-up
)))
1655 (link-home (and (plist-get info
:link-home
)
1656 (string-match "\\S-" (plist-get info
:link-home
))
1657 (plist-get info
:link-home
))))
1658 (when (or link-up link-home
)
1659 (format org-e-html-home
/up-format
1660 (or link-up link-home
)
1661 (or link-home link-up
))))
1663 (org-e-html-preamble info
)
1666 <div id=\"%s\">" (or org-e-html-content-div
1667 (nth 1 org-e-html-divs
)))
1670 <h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info
:title
) info
))
1671 ;; table of contents
1672 (let ((depth (plist-get info
:with-toc
)))
1673 (when (wholenump depth
) (org-e-html-toc depth info
)))
1674 ;; document contents
1676 ;; footnotes section
1677 (org-e-html-footnote-section info
)
1679 (org-e-html-bibliography)
1686 (org-e-html-postamble info
)
1696 ;;; Transcode Helpers
1700 (defun org-e-html--todo (todo)
1702 (format "<span class=\"%s %s%s\">%s</span>"
1703 (if (member todo org-done-keywords
) "done" "todo")
1704 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
1709 (defun org-e-html--tags (tags)
1711 (format "<span class=\"tag\">%s</span>"
1714 (format "<span class=\"%s\">%s</span>"
1715 (concat org-e-html-tag-class-prefix
1716 (org-e-html-fix-class-name tag
))
1722 (defun* org-e-html-format-headline
1723 (todo todo-type priority text tags
1724 &key level section-number headline-label
&allow-other-keys
)
1725 (let ((section-number
1726 (when section-number
1727 (format "<span class=\"section-number-%d\">%s</span> "
1728 level section-number
)))
1729 (todo (org-e-html--todo todo
))
1730 (tags (org-e-html--tags tags
)))
1731 (concat section-number todo
(and todo
" ") text
1732 (and tags
" ") tags
)))
1736 (defun org-e-html-fontify-code (code lang
)
1739 ;; Case 1: No lang. Possibly an example block.
1741 ;; Simple transcoding.
1742 (org-e-html-encode-plain-text code
))
1743 ;; Case 2: No htmlize or an inferior version of htmlize
1744 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1746 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1747 ;; Simple transcoding.
1748 (org-e-html-encode-plain-text code
))
1751 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1752 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1754 ;; Case 1: Language is not associated with any Emacs mode
1755 ((not (functionp lang-mode
))
1756 ;; Simple transcoding.
1757 (org-e-html-encode-plain-text code
))
1758 ;; Case 2: Default. Fotify code.
1761 (setq code
(with-temp-buffer
1764 (font-lock-fontify-buffer)
1765 ;; markup each line separately
1766 (org-remove-formatting-on-newlines-in-region
1767 (point-min) (point-max))
1769 (set-buffer-modified-p nil
)
1770 (org-export-e-htmlize-region-for-paste
1771 (point-min) (point-max))))
1772 ;; Strip any encolosing <pre></pre> tags
1773 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code
)
1774 (match-string 1 code
)
1777 (defun org-e-html-do-format-code
1778 (code &optional lang refs retain-labels num-start textarea-p
)
1780 (setq num-start nil refs nil lang nil
))
1781 (let* ((code-lines (org-split-string code
"\n"))
1782 (code-length (length code-lines
))
1786 (length (number-to-string (+ code-length num-start
))))))
1787 (code (org-e-html-fontify-code code lang
)))
1788 (assert (= code-length
(length (org-split-string code
"\n"))))
1789 (org-export-format-code
1791 (lambda (loc line-num ref
)
1794 ;; Add line number, if needed.
1796 (format "<span class=\"linenr\">%s</span>"
1797 (format num-fmt line-num
)))
1798 ;; Transcoded src line.
1800 ;; Add label, if needed.
1801 (when (and ref retain-labels
) (format " (%s)" ref
))))
1802 ;; Mark transcoded line as an anchor, if needed.
1804 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1808 (defun org-e-html-format-code (element info
)
1809 (let* ((lang (org-element-property :language element
))
1810 ;; (switches (org-element-property :switches element))
1811 (switches nil
) ; FIXME
1812 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1813 ;; Extract code and references.
1814 (code-info (org-export-unravel-code element
))
1815 (code (car code-info
))
1816 (refs (cdr code-info
))
1817 ;; Does the src block contain labels?
1818 (retain-labels (org-element-property :retain-labels element
))
1819 ;; Does it have line numbers?
1820 (num-start (case (org-element-property :number-lines element
)
1821 (continued (org-export-get-loc element info
))
1823 (org-e-html-do-format-code
1824 code lang refs retain-labels num-start textarea-p
)))
1828 ;;; Transcode Functions
1832 (defun org-e-html-bold (bold contents info
)
1833 "Transcode BOLD from Org to HTML.
1834 CONTENTS is the text with bold markup. INFO is a plist holding
1835 contextual information."
1836 (format (or (cdr (assq 'bold org-e-html-text-markup-alist
)) "%s")
1842 (defun org-e-html-center-block (center-block contents info
)
1843 "Transcode a CENTER-BLOCK element from Org to HTML.
1844 CONTENTS holds the contents of the block. INFO is a plist
1845 holding contextual information."
1846 (org-e-html--wrap-label
1848 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1853 (defun org-e-html-clock (clock contents info
)
1854 "Transcode a CLOCK element from Org to HTML.
1855 CONTENTS is nil. INFO is a plist used as a communication
1858 <span class=\"timestamp-wrapper\">
1859 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1863 (org-translate-time (org-element-property :value clock
))
1864 (let ((time (org-element-property :time clock
)))
1865 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1870 (defun org-e-html-code (code contents info
)
1871 "Transcode CODE from Org to HTML.
1872 CONTENTS is nil. INFO is a plist holding contextual
1874 (format (or (cdr (assq 'code org-e-html-text-markup-alist
)) "%s")
1875 (org-element-property :value code
)))
1880 ;; Comments are ignored.
1885 ;; Comment Blocks are ignored.
1890 (defun org-e-html-drawer (drawer contents info
)
1891 "Transcode a DRAWER element from Org to HTML.
1892 CONTENTS holds the contents of the block. INFO is a plist
1893 holding contextual information."
1894 (let* ((name (org-element-property :drawer-name drawer
))
1895 (output (if (functionp org-e-html-format-drawer-function
)
1896 (funcall org-e-html-format-drawer-function
1898 ;; If there's no user defined function: simply
1899 ;; display contents of the drawer.
1901 (org-e-html--wrap-label drawer output
)))
1906 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1907 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1908 CONTENTS holds the contents of the block. INFO is a plist
1909 holding contextual information. See `org-export-data'."
1910 (org-e-html--wrap-label dynamic-block contents
))
1915 (defun org-e-html-entity (entity contents info
)
1916 "Transcode an ENTITY object from Org to HTML.
1917 CONTENTS are the definition itself. INFO is a plist holding
1918 contextual information."
1919 (org-element-property :html entity
))
1924 (defun org-e-html-example-block (example-block contents info
)
1925 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1926 CONTENTS is nil. INFO is a plist holding contextual information."
1927 (let* ((options (or (org-element-property :options example-block
) ""))
1928 (lang (org-element-property :language example-block
))
1929 (caption (org-element-property :caption example-block
))
1930 (label (org-element-property :name example-block
))
1931 (caption-str (org-e-html--caption/label-string caption label info
))
1932 (attr (mapconcat #'identity
1933 (org-element-property :attr_html example-block
)
1935 ;; (switches (org-element-property :switches example-block))
1936 (switches nil
) ; FIXME
1937 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1938 (code (org-e-html-format-code example-block info
)))
1941 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
1942 80 (string-to-number (match-string 1 switches
))))
1943 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
1944 (string-to-number (match-string 1 switches
))
1945 (org-count-lines code
))))
1947 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1949 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
1954 (defun org-e-html-export-snippet (export-snippet contents info
)
1955 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1956 CONTENTS is nil. INFO is a plist holding contextual information."
1957 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
1958 (org-element-property :value export-snippet
)))
1963 (defun org-e-html-export-block (export-block contents info
)
1964 "Transcode a EXPORT-BLOCK element from Org to HTML.
1965 CONTENTS is nil. INFO is a plist holding contextual information."
1966 (when (string= (org-element-property :type export-block
) "latex")
1967 (org-remove-indentation (org-element-property :value export-block
))))
1972 (defun org-e-html-fixed-width (fixed-width contents info
)
1973 "Transcode a FIXED-WIDTH element from Org to HTML.
1974 CONTENTS is nil. INFO is a plist holding contextual information."
1975 (org-e-html--wrap-label
1977 (format "\n<pre class=\"example\">\n%s</pre>"
1978 (org-e-html-do-format-code
1979 (org-remove-indentation
1980 (org-element-property :value fixed-width
))))))
1983 ;;;; Footnote Definition
1985 ;; Footnote Definitions are ignored.
1988 ;;;; Footnote Reference
1990 (defun org-e-html-footnote-reference (footnote-reference contents info
)
1991 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1992 CONTENTS is nil. INFO is a plist holding contextual information."
1994 ;; Insert separator between two footnotes in a row.
1995 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1996 (when (eq (org-element-type prev
) 'footnote-reference
)
1997 org-e-html-footnote-separator
))
1999 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2000 (org-e-html-format-footnote-reference
2001 (org-export-get-footnote-number footnote-reference info
)
2003 ;; Inline definitions are secondary strings.
2004 ((eq (org-element-property :type footnote-reference
) 'inline
)
2005 (org-e-html-format-footnote-reference
2006 (org-export-get-footnote-number footnote-reference info
)
2008 ;; Non-inline footnotes definitions are full Org data.
2009 (t (org-e-html-format-footnote-reference
2010 (org-export-get-footnote-number footnote-reference info
)
2016 (defun org-e-html-format-headline--wrap (headline info
2017 &optional format-function
2019 "Transcode an HEADLINE element from Org to HTML.
2020 CONTENTS holds the contents of the headline. INFO is a plist
2021 holding contextual information."
2022 (let* ((level (+ (org-export-get-relative-level headline info
)
2023 (1- org-e-html-toplevel-hlevel
)))
2024 (headline-number (org-export-get-headline-number headline info
))
2025 (section-number (and (org-export-numbered-headline-p headline info
)
2026 (mapconcat 'number-to-string
2027 headline-number
".")))
2028 (todo (and (plist-get info
:with-todo-keywords
)
2029 (let ((todo (org-element-property :todo-keyword headline
)))
2030 (and todo
(org-export-data todo info
)))))
2031 (todo-type (and todo
(org-element-property :todo-type headline
)))
2032 (priority (and (plist-get info
:with-priority
)
2033 (org-element-property :priority headline
)))
2034 (text (org-export-data (org-element-property :title headline
) info
))
2035 (tags (and (plist-get info
:with-tags
)
2036 (org-element-property :tags headline
)))
2037 (headline-label (concat "sec-" (mapconcat 'number-to-string
2038 headline-number
"-")))
2039 (format-function (cond
2040 ((functionp format-function
) format-function
)
2041 ((functionp org-e-html-format-headline-function
)
2043 (lambda (todo todo-type priority text tags
2045 (funcall org-e-html-format-headline-function
2046 todo todo-type priority text tags
))))
2047 (t 'org-e-html-format-headline
))))
2048 (apply format-function
2049 todo todo-type priority text tags
2050 :headline-label headline-label
:level level
2051 :section-number section-number extra-keys
)))
2053 (defun org-e-html-headline (headline contents info
)
2054 "Transcode an HEADLINE element from Org to HTML.
2055 CONTENTS holds the contents of the headline. INFO is a plist
2056 holding contextual information."
2057 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2058 (level (org-export-get-relative-level headline info
))
2059 (text (org-export-data (org-element-property :title headline
) info
))
2060 (todo (and (plist-get info
:with-todo-keywords
)
2061 (let ((todo (org-element-property :todo-keyword headline
)))
2062 (and todo
(org-export-data todo info
)))))
2063 (todo-type (and todo
(org-element-property :todo-type headline
)))
2064 (tags (and (plist-get info
:with-tags
)
2065 (org-element-property :tags headline
)))
2066 (priority (and (plist-get info
:with-priority
)
2067 (org-element-property :priority headline
)))
2068 (section-number (and (org-export-numbered-headline-p headline info
)
2069 (mapconcat 'number-to-string
2070 (org-export-get-headline-number
2071 headline info
) ".")))
2072 ;; Create the headline text.
2073 (full-text (org-e-html-format-headline--wrap headline info
)))
2075 ;; Case 1: This is a footnote section: ignore it.
2076 ((org-element-property :footnote-section-p headline
) nil
)
2077 ;; Case 2. This is a deep sub-tree: export it as a list item.
2078 ;; Also export as items headlines for which no section
2079 ;; format has been found.
2080 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2081 ;; Build the real contents of the sub-tree.
2082 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2083 (itemized-body (org-e-html-format-list-item
2084 contents type nil nil full-text
)))
2086 (and (org-export-first-sibling-p headline info
)
2087 (org-e-html-begin-plain-list type
))
2089 (and (org-export-last-sibling-p headline info
)
2090 (org-e-html-end-plain-list type
)))))
2091 ;; Case 3. Standard headline. Export it as a section.
2093 (let* ((extra-class (org-element-property :html-container-class headline
))
2094 (extra-ids (list (org-element-property :custom-id headline
)
2095 (org-element-property :id headline
)))
2100 (let ((id (org-solidify-link-text
2101 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2102 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2104 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2105 (id (mapconcat 'number-to-string
2106 (org-export-get-headline-number headline info
) "-")))
2107 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2108 (format "outline-container-%s" id
)
2109 (concat (format "outline-%d" level1
) (and extra-class
" ")
2111 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2112 level1 id extra-ids full-text level1
)
2116 ;;;; Horizontal Rule
2118 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2119 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2120 CONTENTS is nil. INFO is a plist holding contextual information."
2121 (let ((attr (mapconcat #'identity
2122 (org-element-property :attr_html horizontal-rule
)
2124 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2127 ;;;; Inline Babel Call
2129 ;; Inline Babel Calls are ignored.
2132 ;;;; Inline Src Block
2134 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2135 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2136 CONTENTS holds the contents of the item. INFO is a plist holding
2137 contextual information."
2138 (let* ((org-lang (org-element-property :language inline-src-block
))
2139 (code (org-element-property :value inline-src-block
))
2140 (separator (org-e-html--find-verb-separator code
)))
2146 (defun org-e-html-format-section (text class
&optional id
)
2147 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2148 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2150 (defun org-e-html-inlinetask (inlinetask contents info
)
2151 "Transcode an INLINETASK element from Org to HTML.
2152 CONTENTS holds the contents of the block. INFO is a plist
2153 holding contextual information."
2155 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2156 ;; with appropriate arguments.
2157 ((functionp org-e-html-format-inlinetask-function
)
2158 (let ((format-function
2160 (lambda (todo todo-type priority text tags
2161 &key contents
&allow-other-keys
)
2162 (funcall org-e-html-format-inlinetask-function
2163 todo todo-type priority text tags contents
)))))
2164 (org-e-html-format-headline--wrap
2165 inlinetask info format-function
:contents contents
)))
2166 ;; Otherwise, use a default template.
2167 (t (org-e-html--wrap-label
2170 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2171 (org-e-html-format-headline--wrap inlinetask info
)
2177 (defun org-e-html-italic (italic contents info
)
2178 "Transcode ITALIC from Org to HTML.
2179 CONTENTS is the text with italic markup. INFO is a plist holding
2180 contextual information."
2181 (format (or (cdr (assq 'italic org-e-html-text-markup-alist
)) "%s") contents
))
2186 (defun org-e-html-checkbox (checkbox)
2187 (case checkbox
(on "<code>[X]</code>")
2188 (off "<code>[ ]</code>")
2189 (trans "<code>[-]</code>")
2192 (defun org-e-html-format-list-item (contents type checkbox
2193 &optional term-counter-id
2198 (let* ((counter term-counter-id
)
2199 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2200 (format "<li%s>" extra
)))
2202 (let* ((id term-counter-id
)
2203 (extra (if id
(format " id=\"%s\"" id
) "")))
2205 (format "<li%s>" extra
)
2206 (when headline
(concat headline
"<br/>")))))
2208 (let* ((term term-counter-id
))
2209 (setq term
(or term
"(no term)"))
2210 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2211 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2216 (descriptive "</dd>"))))
2218 (defun org-e-html-item (item contents info
)
2219 "Transcode an ITEM element from Org to HTML.
2220 CONTENTS holds the contents of the item. INFO is a plist holding
2221 contextual information."
2222 ;; Grab `:level' from plain-list properties, which is always the
2223 ;; first element above current item.
2224 (let* ((plain-list (org-export-get-parent item info
))
2225 (type (org-element-property :type plain-list
))
2226 (level (org-element-property :level plain-list
))
2227 (counter (org-element-property :counter item
))
2228 (checkbox (org-element-property :checkbox item
))
2229 (tag (let ((tag (org-element-property :tag item
)))
2230 (and tag
(org-export-data tag info
)))))
2231 (org-e-html-format-list-item
2232 contents type checkbox
(or tag counter
))))
2237 (defun org-e-html-keyword (keyword contents info
)
2238 "Transcode a KEYWORD element from Org to HTML.
2239 CONTENTS is nil. INFO is a plist holding contextual information."
2240 (let ((key (org-element-property :key keyword
))
2241 (value (org-element-property :value keyword
)))
2243 ((string= key
"LATEX") value
)
2244 ((string= key
"INDEX") (format "\\index{%s}" value
))
2245 ;; Invisible targets.
2246 ((string= key
"TARGET") nil
) ; FIXME
2247 ((string= key
"TOC")
2248 (let ((value (downcase value
)))
2250 ((string-match "\\<headlines\\>" value
)
2251 (let ((depth (or (and (string-match "[0-9]+" value
)
2252 (string-to-number (match-string 0 value
)))
2253 (plist-get info
:with-toc
))))
2254 (when (wholenump depth
) (org-e-html-toc depth info
))))
2255 ((string= "tables" value
) "\\listoftables")
2256 ((string= "figures" value
) "\\listoffigures")
2257 ((string= "listings" value
)
2259 ;; At the moment, src blocks with a caption are wrapped
2260 ;; into a figure environment.
2261 (t "\\listoffigures")))))))))
2264 ;;;; Latex Environment
2266 (defun org-e-html-format-latex (latex-frag processing-type
)
2267 (let* ((cache-relpath
2268 (concat "ltxpng/" (file-name-sans-extension
2269 (file-name-nondirectory (buffer-file-name)))))
2270 (cache-dir (file-name-directory (buffer-file-name )))
2271 (display-msg "Creating LaTeX Image..."))
2275 (org-format-latex cache-relpath cache-dir nil display-msg
2276 nil nil processing-type
)
2279 (defun org-e-html-latex-environment (latex-environment contents info
)
2280 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2281 CONTENTS is nil. INFO is a plist holding contextual information."
2282 (org-e-html--wrap-label
2284 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2285 (latex-frag (org-remove-indentation
2286 (org-element-property :value latex-environment
)))
2287 (caption (org-e-html--caption/label-string
2288 (org-element-property :caption latex-environment
)
2289 (org-element-property :name latex-environment
)
2292 (label (org-element-property :name latex-environment
)))
2294 ((member processing-type
'(t mathjax
))
2295 (org-e-html-format-latex latex-frag
'mathjax
))
2296 ((equal processing-type
'dvipng
)
2297 (let* ((formula-link (org-e-html-format-latex
2298 latex-frag processing-type
)))
2299 (when (and formula-link
2300 (string-match "file:\\([^]]*\\)" formula-link
))
2301 (org-e-html-format-inline-image
2302 (match-string 1 formula-link
) caption label attr t
))))
2308 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2309 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2310 CONTENTS is nil. INFO is a plist holding contextual information."
2311 (let ((latex-frag (org-element-property :value latex-fragment
))
2312 (processing-type (plist-get info
:LaTeX-fragments
)))
2313 (case processing-type
2315 (org-e-html-format-latex latex-frag
'mathjax
))
2317 (let* ((formula-link (org-e-html-format-latex
2318 latex-frag processing-type
)))
2319 (when (and formula-link
2320 (string-match "file:\\([^]]*\\)" formula-link
))
2321 (org-e-html-format-inline-image
2322 (match-string 1 formula-link
)))))
2327 (defun org-e-html-line-break (line-break contents info
)
2328 "Transcode a LINE-BREAK object from Org to HTML.
2329 CONTENTS is nil. INFO is a plist holding contextual information."
2335 (defun org-e-html-link--inline-image (link desc info
)
2336 "Return HTML code for an inline image.
2337 LINK is the link pointing to the inline image. INFO is a plist
2338 used as a communication channel."
2339 (let* ((type (org-element-property :type link
))
2340 (raw-path (org-element-property :path link
))
2341 (path (cond ((member type
'("http" "https"))
2342 (concat type
":" raw-path
))
2343 ((file-name-absolute-p raw-path
)
2344 (expand-file-name raw-path
))
2346 (parent (org-export-get-parent-paragraph link info
))
2347 (caption (org-e-html--caption/label-string
2348 (org-element-property :caption parent
)
2349 (org-element-property :name parent
)
2351 (label (org-element-property :name parent
))
2352 ;; Retrieve latex attributes from the element around.
2353 (attr (let ((raw-attr
2354 (mapconcat #'identity
2355 (org-element-property :attr_html parent
)
2357 (unless (string= raw-attr
"") raw-attr
))))
2358 ;; Now clear ATTR from any special keyword and set a default
2359 ;; value if nothing is left.
2360 (setq attr
(if (not attr
) "" (org-trim attr
)))
2361 ;; Return proper string, depending on DISPOSITION.
2362 (org-e-html-format-inline-image
2363 path caption label attr
(org-e-html-standalone-image-p link info
))))
2365 (defvar org-e-html-standalone-image-predicate
)
2366 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2367 "Test if ELEMENT is a standalone image for the purpose HTML export.
2368 INFO is a plist holding contextual information.
2370 Return non-nil, if ELEMENT is of type paragraph and it's sole
2371 content, save for whitespaces, is a link that qualifies as an
2374 Return non-nil, if ELEMENT is of type link and it's containing
2375 paragraph has no other content save for leading and trailing
2378 Return nil, otherwise.
2380 Bind `org-e-html-standalone-image-predicate' to constrain
2381 paragraph further. For example, to check for only captioned
2382 standalone images, do the following.
2384 \(setq org-e-html-standalone-image-predicate
2385 \(lambda \(paragraph\)
2386 \(org-element-property :caption paragraph\)\)\)
2388 (let ((paragraph (case (org-element-type element
)
2390 (link (and (org-export-inline-image-p
2391 element org-e-html-inline-image-rules
)
2392 (org-export-get-parent element info
)))
2395 (assert (eq (org-element-type paragraph
) 'paragraph
))
2396 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2397 (functionp org-e-html-standalone-image-predicate
)))
2398 (funcall org-e-html-standalone-image-predicate paragraph
))
2399 (let ((contents (org-element-contents paragraph
)))
2400 (loop for x in contents
2401 with inline-image-count
= 0
2403 ((eq (org-element-type x
) 'plain-text
)
2404 (not (org-string-nw-p x
)))
2405 ((eq (org-element-type x
) 'link
)
2406 (when (org-export-inline-image-p
2407 x org-e-html-inline-image-rules
)
2408 (= (incf inline-image-count
) 1)))
2411 (defun org-e-html-link (link desc info
)
2412 "Transcode a LINK object from Org to HTML.
2414 DESC is the description part of the link, or the empty string.
2415 INFO is a plist holding contextual information. See
2417 (let* ((type (org-element-property :type link
))
2418 (raw-path (org-element-property :path link
))
2419 ;; Ensure DESC really exists, or set it to nil.
2420 (desc (and (not (string= desc
"")) desc
))
2422 ((member type
'("http" "https" "ftp" "mailto"))
2423 (concat type
":" raw-path
))
2424 ((string= type
"file")
2425 (when (string-match "\\(.+\\)::.+" raw-path
)
2426 (setq raw-path
(match-string 1 raw-path
)))
2427 (if (file-name-absolute-p raw-path
)
2428 (concat "file://" (expand-file-name raw-path
))
2429 ;; TODO: Not implemented yet. Concat also:
2430 ;; (org-export-directory :HTML info)
2431 (concat "file://" raw-path
)))
2436 ((and (or (eq t org-e-html-inline-images
)
2437 (and org-e-html-inline-images
(not desc
)))
2438 (org-export-inline-image-p link org-e-html-inline-image-rules
))
2439 (org-e-html-link--inline-image link desc info
))
2440 ;; Radioed target: Target's name is obtained from original raw
2441 ;; link. Path is parsed and transcoded in order to have a proper
2442 ;; display of the contents.
2443 ((string= type
"radio")
2444 (format "<a href=\"#%s\">%s</a>"
2445 (org-export-solidify-link-text path
)
2447 (org-element-parse-secondary-string
2448 path
(org-element-restriction 'radio-target
))
2450 ;; Links pointing to an headline: Find destination and build
2451 ;; appropriate referencing command.
2452 ((member type
'("custom-id" "fuzzy" "id"))
2453 (let ((destination (if (string= type
"fuzzy")
2454 (org-export-resolve-fuzzy-link link info
)
2455 (org-export-resolve-id-link link info
))))
2456 (case (org-element-type destination
)
2457 ;; Fuzzy link points nowhere.
2462 (org-element-property :raw-link link
) info
))))
2463 ;; Fuzzy link points to an invisible target.
2465 ;; LINK points to an headline. If headlines are numbered
2466 ;; and the link has no description, display headline's
2467 ;; number. Otherwise, display description or headline's
2470 (let* ((headline-no (org-export-get-headline-number destination info
))
2471 (label (format "sec-%s" (mapconcat 'number-to-string
2473 (section-no (mapconcat 'number-to-string headline-no
".")))
2477 ((plist-get info
:section-numbers
) section-no
)
2479 (org-element-property :title destination
) info
))))
2480 (format "<a href=\"#%s\">%s</a>" label desc
)))
2481 ;; Fuzzy link points to a target. Do as above.
2483 (let ((path (org-export-solidify-link-text path
)) number
)
2486 ((org-e-html-standalone-image-p destination info
)
2487 (org-export-get-ordinal
2488 (assoc 'link
(org-element-contents destination
))
2489 info
'link
'org-e-html-standalone-image-p
))
2490 (t (org-export-get-ordinal destination info
))))
2491 (setq desc
(when number
2492 (if (atom number
) (number-to-string number
)
2493 (mapconcat 'number-to-string number
".")))))
2494 (format "<a href=\"#%s\">%s</a>" path
(or desc
"FIXME")))))))
2495 ;; Coderef: replace link with the reference name or the
2496 ;; equivalent line number.
2497 ((string= type
"coderef")
2498 (let ((fragment (concat "coderef-" path
)))
2499 (format "<a href=\"#%s\" %s>%s</a>" fragment
2500 (format (concat "class=\"coderef\""
2501 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2502 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2504 (format (org-export-get-coderef-format path desc
)
2505 (org-export-resolve-coderef path info
)))))
2506 ;; Link type is handled by a special function.
2507 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2508 (funcall protocol
(org-link-unescape path
) desc
'html
))
2509 ;; External link with a description part.
2510 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2511 ;; External link without a description part.
2512 (path (format "<a href=\"%s\">%s</a>" path path
))
2513 ;; No path, only description. Try to do something useful.
2514 (t (format "<i>%s</i>" desc
)))))
2519 ;; Babel Calls are ignored.
2524 (defun org-e-html-macro (macro contents info
)
2525 "Transcode a MACRO element from Org to HTML.
2526 CONTENTS is nil. INFO is a plist holding contextual information."
2527 ;; Use available tools.
2528 (org-export-expand-macro macro info
))
2533 (defun org-e-html-paragraph (paragraph contents info
)
2534 "Transcode a PARAGRAPH element from Org to HTML.
2535 CONTENTS is the contents of the paragraph, as a string. INFO is
2536 the plist used as a communication channel."
2537 (let* ((style nil
) ; FIXME
2538 (class (cdr (assoc style
'((footnote .
"footnote")
2540 (extra (if class
(format " class=\"%s\"" class
) ""))
2541 (parent (org-export-get-parent paragraph info
)))
2543 ((and (equal (car parent
) 'item
)
2544 (= (org-element-property :begin paragraph
)
2545 (org-element-property :contents-begin parent
)))
2546 ;; leading paragraph in a list item have no tags
2548 ((org-e-html-standalone-image-p paragraph info
)
2551 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2556 (defun org-e-html-begin-plain-list (type &optional arg1
)
2559 (format "<ol%s>" (if arg1
; FIXME
2560 (format " start=\"%d\"" arg1
)
2563 (descriptive "<dl>")))
2565 (defun org-e-html-end-plain-list (type)
2569 (descriptive "</dl>")))
2571 (defun org-e-html-plain-list (plain-list contents info
)
2572 "Transcode a PLAIN-LIST element from Org to HTML.
2573 CONTENTS is the contents of the list. INFO is a plist holding
2574 contextual information."
2575 (let* (arg1 ;; FIXME
2576 (type (org-element-property :type plain-list
))
2577 (attr (mapconcat #'identity
2578 (org-element-property :attr_html plain-list
)
2580 (org-e-html--wrap-label
2581 plain-list
(format "%s\n%s%s"
2582 (org-e-html-begin-plain-list type
)
2583 contents
(org-e-html-end-plain-list type
)))))
2587 (defun org-e-html-convert-special-strings (string)
2588 "Convert special characters in STRING to HTML."
2589 (let ((all org-e-html-special-string-regexps
)
2591 (while (setq a
(pop all
))
2592 (setq re
(car a
) rpl
(cdr a
) start
0)
2593 (while (string-match re string start
)
2594 (setq string
(replace-match rpl t nil string
))))
2597 (defun org-e-html-encode-plain-text (s)
2598 "Convert plain text characters to HTML equivalent.
2599 Possible conversions are set in `org-export-html-protect-char-alist'."
2600 (let ((cl org-e-html-protect-char-alist
) c
)
2601 (while (setq c
(pop cl
))
2603 (while (string-match (car c
) s start
)
2604 (setq s
(replace-match (cdr c
) t t s
)
2605 start
(1+ (match-beginning 0))))))
2608 (defun org-e-html-plain-text (text info
)
2609 "Transcode a TEXT string from Org to HTML.
2610 TEXT is the string to transcode. INFO is a plist holding
2611 contextual information."
2612 (setq text
(org-e-html-encode-plain-text text
))
2613 ;; Protect %, #, &, $, ~, ^, _, { and }.
2614 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2616 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2618 ;; (setq text (replace-regexp-in-string
2619 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2620 ;; "$\\backslash$" text nil t 1))
2621 ;; HTML into \HTML{} and TeX into \TeX{}.
2622 ;; (let ((case-fold-search nil)
2624 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2625 ;; (setq text (replace-match
2626 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2627 ;; start (match-end 0))))
2628 ;; Handle quotation marks
2629 ;; (setq text (org-e-html--quotation-marks text info))
2630 ;; Convert special strings.
2631 ;; (when (plist-get info :with-special-strings)
2632 ;; (while (string-match (regexp-quote "...") text)
2633 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2634 (when (plist-get info
:with-special-strings
)
2635 (setq text
(org-e-html-convert-special-strings text
)))
2636 ;; Handle break preservation if required.
2637 (when (plist-get info
:preserve-breaks
)
2638 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2646 (defun org-e-html-planning (planning contents info
)
2647 "Transcode a PLANNING element from Org to HTML.
2648 CONTENTS is nil. INFO is a plist used as a communication
2650 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2652 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2657 (let ((closed (org-element-property :closed planning
)))
2659 (format span-fmt org-closed-string
2660 (org-translate-time closed
))))
2661 (let ((deadline (org-element-property :deadline planning
)))
2663 (format span-fmt org-deadline-string
2664 (org-translate-time deadline
))))
2665 (let ((scheduled (org-element-property :scheduled planning
)))
2667 (format span-fmt org-scheduled-string
2668 (org-translate-time scheduled
))))))
2672 ;;;; Property Drawer
2674 (defun org-e-html-property-drawer (property-drawer contents info
)
2675 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2676 CONTENTS is nil. INFO is a plist holding contextual
2678 ;; The property drawer isn't exported but we want separating blank
2679 ;; lines nonetheless.
2685 (defun org-e-html-quote-block (quote-block contents info
)
2686 "Transcode a QUOTE-BLOCK element from Org to HTML.
2687 CONTENTS holds the contents of the block. INFO is a plist
2688 holding contextual information."
2689 (org-e-html--wrap-label
2690 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2695 (defun org-e-html-quote-section (quote-section contents info
)
2696 "Transcode a QUOTE-SECTION element from Org to HTML.
2697 CONTENTS is nil. INFO is a plist holding contextual information."
2698 (let ((value (org-remove-indentation
2699 (org-element-property :value quote-section
))))
2700 (when value
(format "<pre>\n%s</pre>" value
))))
2705 (defun org-e-html-section (section contents info
) ; FIXME
2706 "Transcode a SECTION element from Org to HTML.
2707 CONTENTS holds the contents of the section. INFO is a plist
2708 holding contextual information."
2709 (let ((parent (org-export-get-parent-headline section info
)))
2710 ;; Before first headline: no container, just return CONTENTS.
2711 (if (not parent
) contents
2712 ;; Get div's class and id references.
2713 (let ((class-num (+ (org-export-get-relative-level parent info
)
2714 (1- org-e-html-toplevel-hlevel
)))
2718 (org-export-get-headline-number parent info
) "-")))
2719 ;; Build return value.
2720 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2721 class-num id-num contents
)))))
2725 (defun org-e-html-radio-target (radio-target text info
)
2726 "Transcode a RADIO-TARGET object from Org to HTML.
2727 TEXT is the text of the target. INFO is a plist holding
2728 contextual information."
2729 (let ((id (org-export-solidify-link-text
2730 (org-element-property :value radio-target
))))
2731 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2736 (defun org-e-html-special-block (special-block contents info
)
2737 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2738 CONTENTS holds the contents of the block. INFO is a plist
2739 holding contextual information."
2740 (let ((type (downcase (org-element-property :type special-block
))))
2741 (org-e-html--wrap-label
2743 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2748 (defun org-e-html-src-block (src-block contents info
)
2749 "Transcode a SRC-BLOCK element from Org to HTML.
2750 CONTENTS holds the contents of the item. INFO is a plist holding
2751 contextual information."
2752 (let* ((lang (org-element-property :language src-block
))
2753 (caption (org-element-property :caption src-block
))
2754 (label (org-element-property :name src-block
))
2755 (caption-str (org-e-html--caption/label-string caption label info
))
2756 (attr (mapconcat #'identity
2757 (org-element-property :attr_html src-block
)
2759 ;; (switches (org-element-property :switches src-block))
2760 (switches nil
) ; FIXME
2761 (textarea-p (and switches
(string-match "-t\\>" switches
)))
2762 (code (org-e-html-format-code src-block info
)))
2765 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2766 (if (not caption
) ""
2767 (format "<label class=\"org-src-name\">%s</label>" caption-str
))
2768 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code
)))
2770 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2771 80 (string-to-number (match-string 1 switches
))))
2772 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2773 (string-to-number (match-string 1 switches
))
2774 (org-count-lines code
))))
2776 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2778 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
2780 ;;;; Statistics Cookie
2782 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2783 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2784 CONTENTS is nil. INFO is a plist holding contextual information."
2785 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2786 (format "<code>%s</code>" cookie-value
)))
2791 (defun org-e-html-strike-through (strike-through contents info
)
2792 "Transcode STRIKE-THROUGH from Org to HTML.
2793 CONTENTS is the text with strike-through markup. INFO is a plist
2794 holding contextual information."
2795 (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist
)) "%s")
2801 (defun org-e-html-subscript (subscript contents info
)
2802 "Transcode a SUBSCRIPT object from Org to HTML.
2803 CONTENTS is the contents of the object. INFO is a plist holding
2804 contextual information."
2805 (format "<sub>%s</sub>" contents
))
2810 (defun org-e-html-superscript (superscript contents info
)
2811 "Transcode a SUPERSCRIPT object from Org to HTML.
2812 CONTENTS is the contents of the object. INFO is a plist holding
2813 contextual information."
2814 (format "<sup>%s</sup>" contents
))
2819 (defun org-e-html-table-cell (table-cell contents info
)
2820 "Transcode a TABLE-CELL element from Org to HTML.
2821 CONTENTS is nil. INFO is a plist used as a communication
2823 (let* ((table-row (org-export-get-parent table-cell info
))
2824 (table (org-export-get-parent-table table-cell info
))
2826 (if (not org-e-html-table-align-individual-fields
) ""
2827 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2828 org-e-html-format-table-no-css
)
2829 " align=\"%s\"" " class=\"%s\"")
2830 (org-export-table-cell-alignment table-cell info
)))))
2831 (when (or (not contents
) (string= "" (org-trim contents
)))
2832 (setq contents
" "))
2834 ((and (org-export-table-has-header-p table info
)
2835 (= 1 (org-export-table-row-group table-row info
)))
2836 (concat "\n" (format (car org-e-html-table-header-tags
) "col" cell-attrs
)
2837 contents
(cdr org-e-html-table-header-tags
)))
2838 ((and org-e-html-table-use-header-tags-for-first-column
2839 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2840 (concat "\n" (format (car org-e-html-table-header-tags
) "row" cell-attrs
)
2841 contents
(cdr org-e-html-table-header-tags
)))
2842 (t (concat "\n" (format (car org-e-html-table-data-tags
) cell-attrs
)
2843 contents
(cdr org-e-html-table-data-tags
))))))
2848 (defun org-e-html-table-row (table-row contents info
)
2849 "Transcode a TABLE-ROW element from Org to HTML.
2850 CONTENTS is the contents of the row. INFO is a plist used as a
2851 communication channel."
2852 ;; Rules are ignored since table separators are deduced from
2853 ;; borders of the current row.
2854 (when (eq (org-element-property :type table-row
) 'standard
)
2855 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2858 ;; Case 1: Row belongs to second or subsequent rowgroups.
2859 ((not (= 1 (org-export-table-row-group table-row info
)))
2860 '("\n<tbody>" .
"\n</tbody>"))
2861 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2862 ((org-export-table-has-header-p
2863 (org-export-get-parent-table table-row info
) info
)
2864 '("\n<thead>" .
"\n</thead>"))
2865 ;; Case 2: Row is from first and only row group.
2866 (t '("\n<tbody>" .
"\n</tbody>")))))
2868 ;; Begin a rowgroup?
2869 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2870 (car rowgroup-tags
))
2872 (concat "\n" (eval (car org-e-html-table-row-tags
))
2873 contents
(eval (cdr org-e-html-table-row-tags
)))
2875 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2876 (cdr rowgroup-tags
))))))
2881 (defun org-e-html-table-first-row-data-cells (table info
)
2886 (unless (eq (org-element-property :type row
) 'rule
) row
))
2888 (special-column-p (org-export-table-has-special-column-p table
)))
2889 (if (not special-column-p
) (org-element-contents table-row
)
2890 (cdr (org-element-contents table-row
)))))
2892 (defun org-e-html-table--table.el-table
(table info
)
2893 (when (eq (org-element-property :type table
) 'table.el
)
2895 (let ((outbuf (with-current-buffer
2896 (get-buffer-create "*org-export-table*")
2897 (erase-buffer) (current-buffer))))
2899 (insert (org-element-property :value table
))
2901 (re-search-forward "^[ \t]*|[^|]" nil t
)
2902 (table-generate-source 'html outbuf
))
2903 (with-current-buffer outbuf
2904 (prog1 (org-trim (buffer-string))
2907 (defun org-e-html-table (table contents info
)
2908 "Transcode a TABLE element from Org to HTML.
2909 CONTENTS is nil. INFO is a plist holding contextual information."
2910 (case (org-element-property :type table
)
2911 ;; Case 1: table.el table. Convert it using appropriate tools.
2912 (table.el
(org-e-html-table--table.el-table table info
))
2913 ;; Case 2: Standard table.
2915 (let* ((label (org-element-property :name table
))
2916 (caption (org-e-html--caption/label-string
2917 (org-element-property :caption table
) label info
))
2918 (attributes (mapconcat #'identity
2919 (org-element-property :attr_html table
)
2922 (if (and (boundp 'org-e-html-format-table-no-css
)
2923 org-e-html-format-table-no-css
)
2924 "align=\"%s\"" "class=\"%s\""))
2927 (lambda (table info
)
2929 (lambda (table-cell)
2930 (let ((alignment (org-export-table-cell-alignment
2933 ;; Begin a colgroup?
2934 (when (org-export-table-cell-starts-colgroup-p
2937 ;; Add a column. Also specify it's alignment.
2938 (format "\n<col %s/>" (format alignspec alignment
))
2940 (when (org-export-table-cell-ends-colgroup-p
2943 (org-e-html-table-first-row-data-cells table info
) "\n"))))
2945 (let ((table-tag (plist-get info
:html-table-tag
)))
2947 (and (string-match "<table\\(.*\\)>" table-tag
)
2948 (match-string 1 table-tag
))
2949 (and label
(format " id=\"%s\""
2950 (org-solidify-link-text label
)))))))
2951 ;; Remove last blank line.
2952 (setq contents
(substring contents
0 -
1))
2954 (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
2957 (funcall table-column-specs table info
)
2962 (defun org-e-html-target (target contents info
)
2963 "Transcode a TARGET object from Org to HTML.
2964 CONTENTS is nil. INFO is a plist holding contextual
2966 (let ((id (org-export-solidify-link-text
2967 (org-element-property :value target
))))
2968 (format "<a id=\"%s\" name=\"%s\"/>" id id
)))
2973 (defun org-e-html-timestamp (timestamp contents info
)
2974 "Transcode a TIMESTAMP object from Org to HTML.
2975 CONTENTS is nil. INFO is a plist holding contextual
2977 (let ((value (org-translate-time (org-element-property :value timestamp
))))
2978 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
2984 (defun org-e-html-underline (underline contents info
)
2985 "Transcode UNDERLINE from Org to HTML.
2986 CONTENTS is the text with underline markup. INFO is a plist
2987 holding contextual information."
2988 (format (or (cdr (assq 'underline org-e-html-text-markup-alist
)) "%s")
2994 (defun org-e-html-verbatim (verbatim contents info
)
2995 "Transcode VERBATIM from Org to HTML.
2996 CONTENTS is nil. INFO is a plist holding contextual
2998 (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist
)) "%s")
2999 (org-element-property :value verbatim
)))
3004 (defun org-e-html-verse-block (verse-block contents info
)
3005 "Transcode a VERSE-BLOCK element from Org to HTML.
3006 CONTENTS is verse block contents. INFO is a plist holding
3007 contextual information."
3008 ;; Replace each newline character with line break. Also replace
3009 ;; each blank line with a line break.
3010 (setq contents
(replace-regexp-in-string
3011 "^ *\\\\\\\\$" "<br/>\n"
3012 (replace-regexp-in-string
3013 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3014 ;; Replace each white space at beginning of a line with a
3015 ;; non-breaking space.
3016 (while (string-match "^[ \t]+" contents
)
3017 (let* ((num-ws (length (match-string 0 contents
)))
3018 (ws (let (out) (dotimes (i num-ws out
)
3019 (setq out
(concat out
" "))))))
3020 (setq contents
(replace-match ws nil t contents
))))
3021 (org-e-html--wrap-label
3022 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3027 ;;; Filter Functions
3029 ;;;; Filter Settings
3031 (defconst org-e-html-filters-alist
3032 '((:filter-final-output . org-e-html-final-function
))
3033 "Alist between filters keywords and back-end specific filters.
3034 See `org-export-filters-alist' for more information.")
3039 (defun org-e-html-final-function (contents backend info
)
3040 (if (not org-e-html-pretty-output
) contents
3044 (indent-region (point-min) (point-max))
3045 (buffer-substring-no-properties (point-min) (point-max)))))
3048 ;;; Interactive functions
3050 (defun org-e-html-export-to-html
3051 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3052 "Export current buffer to a HTML file.
3054 If narrowing is active in the current buffer, only export its
3057 If a region is active, export that region.
3059 When optional argument SUBTREEP is non-nil, export the sub-tree
3060 at point, extracting information from the headline properties
3063 When optional argument VISIBLE-ONLY is non-nil, don't export
3064 contents of hidden elements.
3066 When optional argument BODY-ONLY is non-nil, only write code
3067 between \"\\begin{document}\" and \"\\end{document}\".
3069 EXT-PLIST, when provided, is a property list with external
3070 parameters overriding Org default settings, but still inferior to
3071 file-local settings.
3073 When optional argument PUB-DIR is set, use it as the publishing
3076 Return output file's name."
3078 (setq debug-on-error t
) ; FIXME
3079 (let* ((extension (concat "." org-e-html-extension
))
3080 (file (org-export-output-file-name extension subtreep pub-dir
)))
3082 'e-html file subtreep visible-only body-only ext-plist
)))
3086 ;;; FIXMES, TODOS, FOR REVIEW etc
3088 ;;;; org-format-table-html
3089 ;;;; org-format-org-table-html
3090 ;;;; org-format-table-table-html
3091 ;;;; org-table-number-fraction
3092 ;;;; org-table-number-regexp
3093 ;;;; org-e-html-table-caption-above
3096 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3097 ;;;; Remove display properties
3099 ;;;; org-e-html-with-timestamp
3100 ;;;; org-e-html-html-helper-timestamp
3102 ;;;; org-export-as-html-and-open
3103 ;;;; org-export-as-html-batch
3104 ;;;; org-export-as-html-to-buffer
3105 ;;;; org-replace-region-by-html
3106 ;;;; org-export-region-as-html
3107 ;;;; org-export-as-html
3109 ;;;; (org-export-directory :html opt-plist)
3110 ;;;; (plist-get opt-plist :html-extension)
3111 ;;;; org-e-html-toplevel-hlevel
3112 ;;;; org-e-html-special-string-regexps
3113 ;;;; org-e-html-coding-system
3114 ;;;; org-e-html-coding-system
3115 ;;;; org-e-html-inline-images
3116 ;;;; org-e-html-inline-image-extensions
3117 ;;;; org-e-html-protect-char-alist
3118 ;;;; org-e-html-table-use-header-tags-for-first-column
3119 ;;;; org-e-html-todo-kwd-class-prefix
3120 ;;;; org-e-html-tag-class-prefix
3121 ;;;; org-e-html-footnote-separator
3123 ;;;; org-export-preferred-target-alist
3124 ;;;; org-solidify-link-text
3125 ;;;; class for anchors
3126 ;;;; org-export-with-section-numbers, body-only
3127 ;;;; org-export-mark-todo-in-toc
3129 (provide 'org-e-html
)
3130 ;;; org-e-html.el ends here