1 ;;; org-e-html.el --- HTML Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
29 ;; in an org-mode buffer then switch to the buffer to see the HTML
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
38 (require 'format-spec
)
39 (eval-when-compile (require 'cl
) (require 'table
))
43 ;;; Function Declarations
45 (declare-function org-element-get-property
"org-element" (property element
))
46 (declare-function org-element-normalize-string
"org-element" (s))
47 (declare-function org-element-parse-secondary-string
48 "org-element" (string restriction
&optional buffer
))
49 (defvar org-element-string-restrictions
)
50 (defvar org-element-object-restrictions
)
52 (declare-function org-export-clean-table
"org-export" (table specialp
))
53 (declare-function org-export-data
"org-export" (data backend info
))
54 (declare-function org-export-directory
"org-export" (type plist
))
55 (declare-function org-export-expand-macro
"org-export" (macro info
))
56 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
57 (declare-function org-export-footnote-first-reference-p
"org-export"
58 (footnote-reference info
))
59 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
60 (declare-function org-export-get-footnote-definition
"org-export"
61 (footnote-reference info
))
62 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
63 (declare-function org-export-get-previous-element
"org-export" (blob info
))
64 (declare-function org-export-get-relative-level
"org-export" (headline info
))
65 (declare-function org-export-handle-code
66 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
67 (declare-function org-export-included-file
"org-export" (keyword backend info
))
68 (declare-function org-export-inline-image-p
"org-export"
69 (link &optional extensions
))
70 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
71 (declare-function org-export-low-level-p
"org-export" (headline info
))
72 (declare-function org-export-output-file-name
73 "org-export" (extension &optional subtreep pub-dir
))
74 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
75 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
76 (declare-function org-export-secondary-string
"org-export"
77 (secondary backend info
))
78 (declare-function org-export-solidify-link-text
"org-export" (s))
79 (declare-function org-export-table-format-info
"org-export" (table))
81 org-export-to-buffer
"org-export"
82 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
84 org-export-to-file
"org-export"
85 (backend file
&optional subtreep visible-only body-only ext-plist
))
87 (declare-function org-id-find-id-file
"org-id" (id))
88 (declare-function htmlize-region
"ext:htmlize" (beg end
))
89 (declare-function org-pop-to-buffer-same-window
90 "org-compat" (&optional buffer-or-name norecord label
))
95 ;;; Internal Variables
97 (defconst org-e-html-option-alist
98 '((:agenda-style nil nil org-agenda-export-html-style
)
99 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
100 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
101 ;; (:expand-quoted-html nil "@" org-e-html-expand)
102 (:inline-images nil nil org-e-html-inline-images
)
103 ;; (:link-home nil nil org-e-html-link-home) FIXME
104 ;; (:link-up nil nil org-e-html-link-up) FIXME
105 (:style nil nil org-e-html-style
)
106 (:style-extra nil nil org-e-html-style-extra
)
107 (:style-include-default nil nil org-e-html-style-include-default
)
108 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
109 ;; (:timestamp nil nil org-e-html-with-timestamp)
110 (:html-extension nil nil org-e-html-extension
)
111 (:html-postamble nil nil org-e-html-postamble
)
112 (:html-preamble nil nil org-e-html-preamble
)
113 (:html-table-tag nil nil org-e-html-table-tag
)
114 (:xml-declaration nil nil org-e-html-xml-declaration
)
115 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
116 (:mathjax
"MATHJAX" nil
"" space
))
117 "Alist between export properties and ways to set them.
119 The car of the alist is the property name, and the cdr is a list
120 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
122 KEYWORD is a string representing a buffer keyword, or nil.
123 OPTION is a string that could be found in an #+OPTIONS: line.
124 DEFAULT is the default value for the property.
125 BEHAVIOUR determine how Org should handle multiple keywords for
126 the same property. It is a symbol among:
127 nil Keep old value and discard the new one.
128 t Replace old value with the new one.
129 `space' Concatenate the values, separating them with a space.
130 `newline' Concatenate the values, separating them with
132 `split' Split values at white spaces, and cons them to the
135 KEYWORD and OPTION have precedence over DEFAULT.
137 All these properties should be back-end agnostic. For back-end
138 specific properties, define a similar variable named
139 `org-BACKEND-option-alist', replacing BACKEND with the name of
140 the appropriate back-end. You can also redefine properties
141 there, as they have precedence over these.")
143 (defvar html-table-tag nil
) ; dynamically scoped into this.
145 ;; FIXME: it already exists in org-e-html.el
146 (defconst org-e-html-cvt-link-fn
148 "Function to convert link URLs to exportable URLs.
149 Takes two arguments, TYPE and PATH.
150 Returns exportable url as (TYPE PATH), or nil to signal that it
151 didn't handle this case.
152 Intended to be locally bound around a call to `org-export-as-html'." )
157 (defvar org-e-html-format-table-no-css
)
158 (defvar htmlize-buffer-places
) ; from htmlize.el
159 (defvar body-only
) ; dynamically scoped into this.
161 (defvar org-e-html-table-rowgrp-open
)
162 (defvar org-e-html-table-rownum
)
163 (defvar org-e-html-table-cur-rowgrp-is-hdr
)
164 (defvar org-lparse-table-is-styled
)
168 ;;; User Configuration Variables
170 (defgroup org-export-e-html nil
171 "Options for exporting Org mode files to HTML."
172 :tag
"Org Export HTML"
177 (defcustom org-e-html-pretty-output nil
178 "Enable this to generate pretty HTML."
179 :group
'org-export-e-html
185 (defcustom org-e-html-extension
"html"
186 "The extension for exported HTML files."
187 :group
'org-export-e-html
190 (defcustom org-e-html-xml-declaration
191 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
192 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
193 "The extension for exported HTML files.
194 %s will be replaced with the charset of the exported file.
195 This may be a string, or an alist with export extensions
196 and corresponding declarations."
197 :group
'org-export-e-html
199 (string :tag
"Single declaration")
200 (repeat :tag
"Dependent on extension"
201 (cons (string :tag
"Extension")
202 (string :tag
"Declaration")))))
204 ;; Use `org-export-coding-system' instead
205 ;; (defcustom org-e-html-coding-system nil
206 ;; "Coding system for HTML export, defaults to `buffer-file-coding-system'."
207 ;; :group 'org-export-e-html
208 ;; :type 'coding-system)
210 (defvar org-e-html-content-div
"content"
211 "The name of the container DIV that holds all the page contents.
213 This variable is obsolete since Org version 7.7.
214 Please set `org-e-html-divs' instead.")
216 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
217 "The name of the main divs for HTML export.
218 This is a list of three strings, the first one for the preamble
219 DIV, the second one for the content DIV and the third one for the
221 :group
'org-export-e-html
223 (string :tag
" Div for the preamble:")
224 (string :tag
" Div for the content:")
225 (string :tag
"Div for the postamble:")))
228 ;;;; Document Header (Styles)
230 (defconst org-e-html-style-default
231 "<style type=\"text/css\">
232 <!--/*--><![CDATA[/*><!--*/
233 html { font-family: Times, serif; font-size: 12pt; }
234 .title { text-align: center; }
235 .todo { color: red; }
236 .done { color: green; }
237 .tag { background-color: #add8e6; font-weight:normal }
239 .timestamp { color: #bebebe; }
240 .timestamp-kwd { color: #5f9ea0; }
241 .right {margin-left:auto; margin-right:0px; text-align:right;}
242 .left {margin-left:0px; margin-right:auto; text-align:left;}
243 .center {margin-left:auto; margin-right:auto; text-align:center;}
244 p.verse { margin-left: 3% }
246 border: 1pt solid #AEBDCC;
247 background-color: #F3F5F7;
249 font-family: courier, monospace;
253 table { border-collapse: collapse; }
254 td, th { vertical-align: top; }
255 th.right { text-align:center; }
256 th.left { text-align:center; }
257 th.center { text-align:center; }
258 td.right { text-align:right; }
259 td.left { text-align:left; }
260 td.center { text-align:center; }
261 dt { font-weight: bold; }
262 div.figure { padding: 0.5em; }
263 div.figure p { text-align: center; }
266 border:2px solid gray;
270 textarea { overflow-x: auto; }
271 .linenr { font-size:smaller }
272 .code-highlighted {background-color:#ffff00;}
273 .org-info-js_info-navigation { border-style:none; }
274 #org-info-js_console-label { font-size:10px; font-weight:bold;
275 white-space:nowrap; }
276 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
280 "The default style specification for exported HTML files.
281 Please use the variables `org-e-html-style' and
282 `org-e-html-style-extra' to add to this style. If you wish to not
283 have the default style included, customize the variable
284 `org-e-html-style-include-default'.")
286 (defcustom org-e-html-style-include-default t
287 "Non-nil means include the default style in exported HTML files.
288 The actual style is defined in `org-e-html-style-default' and should
289 not be modified. Use the variables `org-e-html-style' to add
290 your own style information."
291 :group
'org-export-e-html
294 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
296 (defcustom org-e-html-style
""
297 "Org-wide style definitions for exported HTML files.
299 This variable needs to contain the full HTML structure to provide a style,
300 including the surrounding HTML tags. If you set the value of this variable,
301 you should consider to include definitions for the following classes:
302 title, todo, done, timestamp, timestamp-kwd, tag, target.
304 For example, a valid value would be:
306 <style type=\"text/css\">
308 p { font-weight: normal; color: gray; }
310 .title { text-align: center; }
311 .todo, .timestamp-kwd { color: red; }
312 .done { color: green; }
316 If you'd like to refer to an external style file, use something like
318 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
320 As the value of this option simply gets inserted into the HTML <head> header,
321 you can \"misuse\" it to add arbitrary text to the header.
322 See also the variable `org-e-html-style-extra'."
323 :group
'org-export-e-html
326 (put 'org-e-html-style
'safe-local-variable
'stringp
)
328 (defcustom org-e-html-style-extra
""
329 "Additional style information for HTML export.
330 The value of this variable is inserted into the HTML buffer right after
331 the value of `org-e-html-style'. Use this variable for per-file
332 settings of style information, and do not forget to surround the style
333 settings with <style>...</style> tags."
334 :group
'org-export-e-html
337 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
339 (defcustom org-e-html-mathjax-options
340 '((path "http://orgmode.org/mathjax/MathJax.js")
345 "Options for MathJax setup.
347 path The path where to find MathJax
348 scale Scaling for the HTML-CSS backend, usually between 100 and 133
349 align How to align display math: left, center, or right
350 indent If align is not center, how far from the left/right side?
351 mathml Should a MathML player be used if available?
352 This is faster and reduces bandwidth use, but currently
353 sometimes has lower spacing quality. Therefore, the default is
354 nil. When browsers get better, this switch can be flipped.
356 You can also customize this for each buffer, using something like
358 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
359 :group
'org-export-e-html
360 :type
'(list :greedy t
361 (list :tag
"path (the path from where to load MathJax.js)"
362 (const :format
" " path
) (string))
363 (list :tag
"scale (scaling for the displayed math)"
364 (const :format
" " scale
) (string))
365 (list :tag
"align (alignment of displayed equations)"
366 (const :format
" " align
) (string))
367 (list :tag
"indent (indentation with left or right alignment)"
368 (const :format
" " indent
) (string))
369 (list :tag
"mathml (should MathML display be used is possible)"
370 (const :format
" " mathml
) (boolean))))
373 ;;;; Document Header (Scripts)
375 (defcustom org-e-html-style-include-scripts t
376 "Non-nil means include the JavaScript snippets in exported HTML files.
377 The actual script is defined in `org-e-html-scripts' and should
379 :group
'org-export-e-html
382 (defconst org-e-html-scripts
383 "<script type=\"text/javascript\">
384 <!--/*--><![CDATA[/*><!--*/
385 function CodeHighlightOn(elem, id)
387 var target = document.getElementById(id);
389 elem.cacheClassElem = elem.className;
390 elem.cacheClassTarget = target.className;
391 target.className = \"code-highlighted\";
392 elem.className = \"code-highlighted\";
395 function CodeHighlightOff(elem, id)
397 var target = document.getElementById(id);
398 if(elem.cacheClassElem)
399 elem.className = elem.cacheClassElem;
400 if(elem.cacheClassTarget)
401 target.className = elem.cacheClassTarget;
405 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
408 ;;;; Document Header (Mathjax)
410 (defcustom org-e-html-mathjax-template
411 "<script type=\"text/javascript\" src=\"%PATH\">
412 <!--/*--><![CDATA[/*><!--*/
414 // Only one of the two following lines, depending on user settings
415 // First allows browser-native MathML display, second forces HTML/CSS
416 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
417 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
418 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
419 \"TeX/noUndefined.js\"],
421 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
422 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
423 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
424 ignoreClass: \"tex2jax_ignore\",
425 processEscapes: false,
426 processEnvironments: true,
429 showProcessingMessages: true,
430 displayAlign: \"%ALIGN\",
431 displayIndent: \"%INDENT\",
435 availableFonts: [\"STIX\",\"TeX\"],
436 preferredFont: \"TeX\",
452 "The MathJax setup for XHTML files."
453 :group
'org-export-e-html
459 (defcustom org-e-html-preamble t
460 "Non-nil means insert a preamble in HTML export.
462 When `t', insert a string as defined by one of the formatting
463 strings in `org-e-html-preamble-format'. When set to a
464 string, this string overrides `org-e-html-preamble-format'.
465 When set to a function, apply this function and insert the
466 returned string. The function takes the property list of export
467 options as its only argument.
469 Setting :html-preamble in publishing projects will take
470 precedence over this variable."
471 :group
'org-export-e-html
472 :type
'(choice (const :tag
"No preamble" nil
)
473 (const :tag
"Default preamble" t
)
474 (string :tag
"Custom formatting string")
475 (function :tag
"Function (must return a string)")))
477 (defcustom org-e-html-preamble-format
'(("en" ""))
478 "The format for the HTML preamble.
480 %t stands for the title.
481 %a stands for the author's name.
482 %e stands for the author's email.
483 %d stands for the date.
485 If you need to use a \"%\" character, you need to escape it
487 :group
'org-export-e-html
490 (defcustom org-e-html-home
/up-format
491 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
492 <a accesskey=\"h\" href=\"%s\"> UP </a>
494 <a accesskey=\"H\" href=\"%s\"> HOME </a>
496 "Snippet used to insert the HOME and UP links.
497 This is a format string, the first %s will receive the UP link,
498 the second the HOME link. If both `org-e-html-link-up' and
499 `org-e-html-link-home' are empty, the entire snippet will be
501 :group
'org-export-e-html
506 (defcustom org-e-html-postamble
'auto
507 "Non-nil means insert a postamble in HTML export.
509 When `t', insert a string as defined by the formatting string in
510 `org-e-html-postamble-format'. When set to a string, this
511 string overrides `org-e-html-postamble-format'. When set to
512 'auto, discard `org-e-html-postamble-format' and honor
513 `org-export-author/email/creator-info' variables. When set to a
514 function, apply this function and insert the returned string.
515 The function takes the property list of export options as its
518 Setting :html-postamble in publishing projects will take
519 precedence over this variable."
520 :group
'org-export-e-html
521 :type
'(choice (const :tag
"No postamble" nil
)
522 (const :tag
"Auto preamble" 'auto
)
523 (const :tag
"Default formatting string" t
)
524 (string :tag
"Custom formatting string")
525 (function :tag
"Function (must return a string)")))
527 (defcustom org-e-html-postamble-format
528 '(("en" "<p class=\"author\">Author: %a (%e)</p>
529 <p class=\"date\">Date: %d</p>
530 <p class=\"creator\">Generated by %c</p>
531 <p class=\"xhtml-validation\">%v</p>
533 "The format for the HTML postamble.
535 %a stands for the author's name.
536 %e stands for the author's email.
537 %d stands for the date.
538 %c will be replaced by information about Org/Emacs versions.
539 %v will be replaced by `org-e-html-validation-link'.
541 If you need to use a \"%\" character, you need to escape it
543 :group
'org-export-e-html
546 (defcustom org-e-html-validation-link
547 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
548 "Link to HTML validation service."
549 :group
'org-export-e-html
552 ;; FIXME Obsolete since Org 7.7
553 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
556 (defcustom org-e-html-protect-char-alist
560 "Alist of characters to be converted by `org-e-html-protect'."
561 :group
'org-export-e-html
562 :type
'(repeat (cons (string :tag
"Character")
563 (string :tag
"HTML equivalent"))))
565 (defconst org-e-html-special-string-regexps
566 '(("\\\\-" .
"­")
567 ("---\\([^-]\\)" .
"—\\1")
568 ("--\\([^-]\\)" .
"–\\1")
569 ("\\.\\.\\." .
"…"))
570 "Regular expressions for special string conversion.")
575 (defcustom org-e-html-todo-kwd-class-prefix
""
576 "Prefix to class names for TODO keywords.
577 Each TODO keyword gets a class given by the keyword 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
587 (defcustom org-e-html-tag-class-prefix
""
588 "Prefix to class names for TODO keywords.
589 Each tag gets a class given by the tag itself, with this prefix.
590 The default prefix is empty because it is nice to just use the keyword
591 as a class name. But if you get into conflicts with other, existing
592 CSS classes, then this prefix can be very useful."
593 :group
'org-export-e-html
597 ;;;; Statistics Cookie
603 (defcustom org-e-html-inline-images
'maybe
604 "Non-nil means inline images into exported HTML pages.
605 This is done using an <img> tag. When nil, an anchor with href is used to
606 link to the image. If this option is `maybe', then images in links with
607 an empty description will be inlined, while images with a description will
609 :group
'org-export-e-html
610 :type
'(choice (const :tag
"Never" nil
)
611 (const :tag
"Always" t
)
612 (const :tag
"When there is no description" maybe
)))
614 (defcustom org-e-html-inline-image-extensions
615 '("png" "jpeg" "jpg" "gif" "svg")
616 "Extensions of image files that can be inlined into HTML."
617 :group
'org-export-e-html
618 :type
'(repeat (string :tag
"Extension")))
634 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
635 <h2 class=\"footnotes\">%s: </h2>
636 <div id=\"text-footnotes\">
640 "Format for the footnotes section.
641 Should contain a two instances of %s. The first will be replaced with the
642 language-specific word for \"Footnotes\", the second one will be replaced
643 by the footnotes themselves."
644 :group
'org-export-e-html
647 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
648 "The format for the footnote reference.
649 %s will be replaced by the footnote reference itself."
650 :group
'org-export-e-html
653 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
654 "Text used to separate footnotes."
655 :group
'org-export-e-html
661 ;;;; Inline Babel Call
662 ;;;; Inline Src Block
666 ;;;; Latex Environment
683 (defgroup org-export-e-htmlize nil
684 "Options for processing examples with htmlize.el."
685 :tag
"Org Export Htmlize"
686 :group
'org-export-e-html
)
688 (defcustom org-export-e-htmlize-output-type
'inline-css
689 "Output type to be used by htmlize when formatting code snippets.
690 Choices are `css', to export the CSS selectors only, or `inline-css', to
691 export the CSS attribute values inline in the HTML. We use as default
692 `inline-css', in order to make the resulting HTML self-containing.
694 However, this will fail when using Emacs in batch mode for export, because
695 then no rich font definitions are in place. It will also not be good if
696 people with different Emacs setup contribute HTML files to a website,
697 because the fonts will represent the individual setups. In these cases,
698 it is much better to let Org/Htmlize assign classes only, and to use
699 a style file to define the look of these classes.
700 To get a start for your css file, start Emacs session and make sure that
701 all the faces you are interested in are defined, for example by loading files
702 in all modes you want. Then, use the command
703 \\[org-export-e-htmlize-generate-css] to extract class definitions."
704 :group
'org-export-e-htmlize
705 :type
'(choice (const css
) (const inline-css
)))
707 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
708 "The prefix for CSS class names for htmlize font specifications."
709 :group
'org-export-e-htmlize
712 (defcustom org-export-e-htmlized-org-css-url nil
713 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
714 Normally when creating an htmlized version of an Org buffer, htmlize will
715 create CSS to define the font colors. However, this does not work when
716 converting in batch mode, and it also can look bad if different people
717 with different fontification setup work on the same website.
718 When this variable is non-nil, creating an htmlized version of an Org buffer
719 using `org-export-as-org' will remove the internal CSS section and replace it
720 with a link to this URL."
721 :group
'org-export-e-htmlize
723 (const :tag
"Keep internal css" nil
)
724 (string :tag
"URL or local href")))
729 (defcustom org-e-html-table-tag
730 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
731 "The HTML tag that is used to start a table.
732 This must be a <table> tag, but you may change the options like
733 borders and spacing."
734 :group
'org-export-e-html
737 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
738 "The opening tag for table header fields.
739 This is customizable so that alignment options can be specified.
740 The first %s will be filled with the scope of the field, either row or col.
741 The second %s will be replaced by a style entry to align the field.
742 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
743 See also the variable `org-e-html-table-align-individual-fields'."
744 :group
'org-export-tables
; FIXME: change group?
745 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
747 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
748 "The opening tag for table data fields.
749 This is customizable so that alignment options can be specified.
750 The first %s will be filled with the scope of the field, either row or col.
751 The second %s will be replaced by a style entry to align the field.
752 See also the variable `org-e-html-table-align-individual-fields'."
753 :group
'org-export-tables
754 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
756 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
757 "The opening tag for table data fields.
758 This is customizable so that alignment options can be specified.
759 Instead of strings, these can be Lisp forms that will be evaluated
760 for each row in order to construct the table row tags. During evaluation,
761 the variable `head' will be true when this is a header line, nil when this
762 is a body line. And the variable `nline' will contain the line number,
763 starting from 1 in the first header line. For example
765 (setq org-e-html-table-row-tags
768 (if (= (mod nline 2) 1)
769 \"<tr class=\\\"tr-odd\\\">\"
770 \"<tr class=\\\"tr-even\\\">\"))
773 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
774 :group
'org-export-tables
776 (choice :tag
"Opening tag"
777 (string :tag
"Specify")
779 (choice :tag
"Closing tag"
780 (string :tag
"Specify")
783 (defcustom org-e-html-table-align-individual-fields t
784 "Non-nil means attach style attributes for alignment to each table field.
785 When nil, alignment will only be specified in the column tags, but this
786 is ignored by some browsers (like Firefox, Safari). Opera does it right
788 :group
'org-export-tables
791 (defcustom org-e-html-table-use-header-tags-for-first-column nil
792 "Non-nil means format column one in tables with header tags.
793 When nil, also column one will use data tags."
794 :group
'org-export-tables
805 (defcustom org-e-html-toplevel-hlevel
2
806 "The <H> level for level 1 headings in HTML export.
807 This is also important for the classes that will be wrapped around headlines
808 and outline structure. If this variable is 1, the top-level headlines will
809 be <h1>, and the corresponding classes will be outline-1, section-number-1,
810 and outline-text-1. If this is 2, all of these will get a 2 instead.
811 The default for this variable is 2, because we use <h1> for formatting the
813 :group
'org-export-e-html
822 (defcustom org-e-html-link-org-files-as-html t
823 "Non-nil means make file links to `file.org' point to `file.html'.
824 When org-mode is exporting an org-mode file to HTML, links to
825 non-html files are directly put into a href tag in HTML.
826 However, links to other Org-mode files (recognized by the
827 extension `.org.) should become links to the corresponding html
828 file, assuming that the linked org-mode file will also be
830 When nil, the links still point to the plain `.org' file."
831 :group
'org-export-e-html
839 ;;; User Configurable Variables (MAYBE)
843 (defcustom org-e-html-date-format
845 "Format string for \\date{...}."
846 :group
'org-export-e-html
851 (defcustom org-e-html-format-headline-function nil
852 "Function to format headline text.
854 This function will be called with 5 arguments:
855 TODO the todo keyword \(string or nil\).
856 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
857 PRIORITY the priority of the headline \(integer or nil\)
858 TEXT the main headline text \(string\).
859 TAGS the tags string, separated with colons \(string or nil\).
861 The function result will be used in the section format string.
863 As an example, one could set the variable to the following, in
864 order to reproduce the default set-up:
866 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
867 \"Default format function for an headline.\"
869 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
871 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
873 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
874 :group
'org-export-e-html
879 (defcustom org-e-html-emphasis-alist
880 '(("*" .
"<b>%s</b>")
882 ("_" .
"<span style=\"text-decoration:underline;\">%s</span>")
883 ("+" .
"<del>%s</del>")
884 ("=" .
"<code>%s</code>")
885 ("~" .
"<code>%s</code>"))
886 "Alist of HTML expressions to convert emphasis fontifiers.
888 The key is the character used as a marker for fontification. The
889 value is a formatting string to wrap fontified text with.
891 Value can also be set to the following symbols: `verb' and
892 `protectedtexttt'. For the former, Org will use \"\\verb\" to
893 create a format string and select a delimiter character that
894 isn't in the string. For the latter, Org will use \"\\texttt\"
895 to typeset and try to protect special characters."
896 :group
'org-export-e-html
902 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
903 "Text used to separate footnotes."
904 :group
'org-export-e-html
910 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
911 "A printf format string to be applied to active time-stamps."
912 :group
'org-export-e-html
915 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
916 "A printf format string to be applied to inactive time-stamps."
917 :group
'org-export-e-html
920 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
921 "A printf format string to be applied to diary time-stamps."
922 :group
'org-export-e-html
928 (defcustom org-e-html-inline-image-rules
929 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
930 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
931 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
932 "Rules characterizing image files that can be inlined into HTML.
934 A rule consists in an association whose key is the type of link
935 to consider, and value is a regexp that will be matched against
938 Note that, by default, the image extension *actually* allowed
939 depend on the way the HTML file is processed. When used with
940 pdflatex, pdf, jpg and png images are OK. When processing
941 through dvi to Postscript, only ps and eps are allowed. The
942 default we use here encompasses both."
943 :group
'org-export-e-html
944 :type
'(alist :key-type
(string :tag
"Type")
945 :value-type
(regexp :tag
"Path")))
949 (defcustom org-e-html-table-caption-above t
950 "When non-nil, place caption string at the beginning of the table.
951 Otherwise, place it near the end."
952 :group
'org-export-e-html
957 (defcustom org-e-html-format-drawer-function nil
958 "Function called to format a drawer in HTML code.
960 The function must accept two parameters:
961 NAME the drawer name, like \"LOGBOOK\"
962 CONTENTS the contents of the drawer.
964 The function should return the string to be exported.
966 For example, the variable could be set to the following function
967 in order to mimic default behaviour:
969 \(defun org-e-html-format-drawer-default \(name contents\)
970 \"Format a drawer element for HTML export.\"
972 :group
'org-export-e-html
978 (defcustom org-e-html-format-inlinetask-function nil
979 "Function called to format an inlinetask in HTML code.
981 The function must accept six parameters:
982 TODO the todo keyword, as a string
983 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
984 PRIORITY the inlinetask priority, as a string
985 NAME the inlinetask name, as a string.
986 TAGS the inlinetask tags, as a string.
987 CONTENTS the contents of the inlinetask, as a string.
989 The function should return the string to be exported.
991 For example, the variable could be set to the following function
992 in order to mimic default behaviour:
994 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
995 \"Format an inline task element for HTML export.\"
999 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
1000 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1002 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1003 \(format \(concat \"\\\\begin{center}\\n\"
1005 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1007 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1009 \"\\\\end{minipage}}\"
1010 \"\\\\end{center}\"\)
1011 full-title contents\)\)"
1012 :group
'org-export-e-html
1020 (defcustom org-e-html-quotes
1022 ("\\(\\s-\\|[[(]\\)\"" .
"«~")
1023 ("\\(\\S-\\)\"" .
"~»")
1024 ("\\(\\s-\\|(\\)'" .
"'"))
1026 ("\\(\\s-\\|[[(]\\)\"" .
"``")
1027 ("\\(\\S-\\)\"" .
"''")
1028 ("\\(\\s-\\|(\\)'" .
"`")))
1029 "Alist for quotes to use when converting english double-quotes.
1031 The CAR of each item in this alist is the language code.
1032 The CDR of each item in this alist is a list of three CONS.
1033 - the first CONS defines the opening quote
1034 - the second CONS defines the closing quote
1035 - the last CONS defines single quotes
1037 For each item in a CONS, the first string is a regexp for allowed
1038 characters before/after the quote, the second string defines the
1039 replacement string for this quote."
1040 :group
'org-export-e-html
1042 (cons :tag
"Opening quote"
1043 (string :tag
"Regexp for char before")
1044 (string :tag
"Replacement quote "))
1045 (cons :tag
"Closing quote"
1046 (string :tag
"Regexp for char after ")
1047 (string :tag
"Replacement quote "))
1048 (cons :tag
"Single quote"
1049 (string :tag
"Regexp for char before")
1050 (string :tag
"Replacement quote "))))
1057 ;;; Internal Functions (HTML)
1059 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1060 "Convert an org filename to an equivalent html filename.
1061 If TYPE is not file, just return `nil'.
1062 See variable `org-e-html-link-org-files-as-html'."
1065 org-e-html-link-org-files-as-html
1066 (string= type
"file")
1067 (string-match "\\.org$" path
)
1072 (substring path
0 (match-beginning 0))
1073 "." (plist-get opt-plist
:html-extension
)))))))
1075 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1078 OPT-PLIST is an options list.
1079 TYPE is the device-type of the link (THIS://foo.html).
1080 PATH is the path of the link (http://THIS#location).
1081 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1082 DESC is the link description, if any.
1083 ATTR is a string of other attributes of the \"a\" element."
1084 (declare (special org-lparse-par-open
))
1086 (when (string= type-1
"coderef")
1087 (let ((ref fragment
))
1088 (setq desc
(format (org-export-get-coderef-format ref
(and descp desc
))
1089 (cdr (assoc ref org-export-code-refs
)))
1090 fragment
(concat "coderef-" ref
)
1091 attr
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1092 fragment fragment
))))
1093 (let* ((may-inline-p
1094 (and (member type-1
'("http" "https" "file"))
1095 (org-lparse-should-inline-p path descp
)
1097 (type (if (equal type-1
"id") "file" type-1
))
1099 ;;First pass. Just sanity stuff.
1102 ((string= type
"file")
1105 ;;Substitute just if original path was absolute.
1106 ;;(Otherwise path must remain relative)
1107 (if (file-name-absolute-p path
)
1108 (concat "file://" (expand-file-name path
))
1112 (t (list type path
))))
1114 ;;Second pass. Components converted so they can refer
1118 (and org-e-html-cvt-link-fn
1119 (apply org-e-html-cvt-link-fn
1120 opt-plist components-1
))
1121 (apply #'org-e-html-cvt-org-as-html
1122 opt-plist components-1
)
1124 (type (first components-2
))
1125 (thefile (second components-2
)))
1128 ;;Third pass. Build final link except for leading type
1133 (string= type
"http")
1134 (string= type
"https")
1135 (string= type
"file")
1136 (string= type
"coderef"))
1138 (setq thefile
(concat thefile
"#" fragment
))))
1142 ;;Final URL-build, for all types.
1145 ((str (org-xml-format-href thefile
)))
1146 (if (and type
(not (or (string= "file" type
)
1147 (string= "coderef" type
))))
1148 (concat type
":" str
)
1152 (ignore) ;; (org-e-html-format-image thefile)
1154 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1156 ;; (caption (and caption (org-xml-encode-org-text caption)))
1157 ;; alt = (file-name-nondirectory path)
1159 (defun org-e-html-format-inline-image (src &optional
1160 caption label attr standalone-p
)
1161 (let* ((id (if (not label
) ""
1162 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1165 ((string-match "\\<alt=" (or attr
"")) "")
1166 ((string-match "^ltxpng/" src
)
1167 (format " alt=\"%s\""
1168 (org-e-html-encode-plain-text
1169 (org-find-text-property-in-string
1170 'org-latex-src src
))))
1171 (t (format " alt=\"%s\""
1172 (file-name-nondirectory src
)))))))
1175 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1176 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1177 id
(format "\n<p>%s</p>" img
)
1178 (when caption
(format "\n<p>%s</p>" caption
)))))
1179 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1183 (defun org-e-html-bibliography ()
1184 "Find bibliography, cut it out and return it."
1186 (let (beg end
(cnt 1) bib
)
1188 (goto-char (point-min))
1189 (when (re-search-forward
1190 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1191 (setq beg
(match-beginning 0))
1192 (while (re-search-forward "</?div\\>" nil t
)
1193 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1195 (and (looking-at ">") (forward-char 1))
1196 (setq bib
(buffer-substring beg
(point)))
1197 (delete-region beg
(point))
1198 (throw 'exit bib
))))
1203 (defun org-e-html-format-table (lines olines
)
1204 (let ((org-e-html-format-table-no-css nil
))
1205 (org-lparse-format-table lines olines
)))
1207 (defun org-e-html-splice-attributes (tag attributes
)
1208 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1209 (if (not attributes
)
1211 (let (oldatt newatt
)
1212 (setq oldatt
(org-extract-attributes-from-string tag
)
1214 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1216 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1217 (if (string-match ">" tag
)
1219 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1223 (defun org-export-splice-style (style extra
)
1224 "Splice EXTRA into STYLE, just before \"</style>\"."
1225 (if (and (stringp extra
)
1226 (string-match "\\S-" extra
)
1227 (string-match "</style>" style
))
1228 (concat (substring style
0 (match-beginning 0))
1230 (substring style
(match-beginning 0)))
1233 (defun org-export-e-htmlize-region-for-paste (beg end
)
1234 "Convert the region to HTML, using htmlize.el.
1235 This is much like `htmlize-region-for-paste', only that it uses
1236 the settings define in the org-... variables."
1237 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1238 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1239 (htmlbuf (htmlize-region beg end
)))
1241 (with-current-buffer htmlbuf
1242 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1243 (plist-get htmlize-buffer-places
'content-end
)))
1244 (kill-buffer htmlbuf
))))
1247 (defun org-export-e-htmlize-generate-css ()
1248 "Create the CSS for all font definitions in the current Emacs session.
1249 Use this to create face definitions in your CSS style file that can then
1250 be used by code snippets transformed by htmlize.
1251 This command just produces a buffer that contains class definitions for all
1252 faces used in the current Emacs session. You can copy and paste the ones you
1253 need into your CSS file.
1255 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1256 the function `org-export-e-htmlize-region-for-paste' will produce code
1257 that uses these same face definitions."
1260 (and (get-buffer "*html*") (kill-buffer "*html*"))
1262 (let ((fl (face-list))
1263 (htmlize-css-name-prefix "org-")
1264 (htmlize-output-type 'css
)
1266 (while (setq f
(pop fl
)
1267 i
(and f
(face-attribute f
:inherit
)))
1268 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1269 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1270 (htmlize-region (point-min) (point-max))))
1271 (org-pop-to-buffer-same-window "*html*")
1272 (goto-char (point-min))
1273 (if (re-search-forward "<style" nil t
)
1274 (delete-region (point-min) (match-beginning 0)))
1275 (if (re-search-forward "</style>" nil t
)
1276 (delete-region (1+ (match-end 0)) (point-max)))
1277 (beginning-of-line 1)
1278 (if (looking-at " +") (replace-match ""))
1279 (goto-char (point-min)))
1281 (defun org-e-html-make-string (n string
)
1282 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1284 (defun org-e-html-toc-text (toc-entries)
1285 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1286 (start-level prev-level
))
1290 (let ((headline (nth 0 entry
))
1291 (level (nth 1 entry
)))
1293 (let* ((cnt (- level prev-level
))
1294 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1296 (setq prev-level level
)
1298 (org-e-html-make-string
1299 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1300 ((< cnt
0) "</li>\n</ul>\n")))
1301 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1304 (org-e-html-make-string
1305 (- prev-level start-level
) "</li>\n</ul>\n"))))
1307 (defun* org-e-html-format-toc-headline
1308 (todo todo-type priority text tags
1309 &key level section-number headline-label
&allow-other-keys
)
1310 (let ((headline (concat
1311 section-number
(and section-number
". ")
1313 (and tags
" ") (org-e-html--tags tags
))))
1314 (format "<a href=\"#%s\">%s</a>"
1316 (if (not nil
) headline
1317 (format "<span class=\"%s\">%s</span>" todo-type headline
)))))
1319 (defun org-e-html-toc (depth info
)
1320 (assert (wholenump depth
))
1321 (let* ((headlines (org-export-collect-headlines info depth
))
1323 (loop for headline in headlines collect
1324 (list (org-e-html-format-headline--wrap
1325 headline info
'org-e-html-format-toc-headline
)
1326 (org-export-get-relative-level headline info
)))))
1328 (let* ((lang-specific-heading
1329 (nth 3 (or (assoc (plist-get info
:language
)
1330 org-export-language-setup
)
1331 (assoc "en" org-export-language-setup
)))))
1333 "<div id=\"table-of-contents\">\n"
1334 (format "<h%d>%s</h%d>\n"
1335 org-e-html-toplevel-hlevel
1336 lang-specific-heading
1337 org-e-html-toplevel-hlevel
)
1338 "<div id=\"text-table-of-contents\">"
1339 (org-e-html-toc-text toc-entries
)
1343 ;; (defun org-e-html-format-line (line)
1344 ;; (case org-lparse-dyn-current-environment
1345 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1346 ;; (t (concat line "\n"))))
1348 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1349 "Turn todo keyword into a valid class name.
1350 Replaces invalid characters with \"_\"."
1352 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1353 (setq kwd
(replace-match "_" t t kwd
))))
1356 (defun org-e-html-format-footnote-reference (n def refcnt
)
1357 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1358 (format org-e-html-footnote-format
1360 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1363 (defun org-e-html-format-footnotes-section (section-name definitions
)
1364 (if (not definitions
) ""
1365 (format org-e-html-footnotes-section section-name definitions
)))
1367 (defun org-e-html-format-footnote-definition (fn)
1368 (let ((n (car fn
)) (def (cdr fn
)))
1370 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1372 (format org-e-html-footnote-format
1373 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1376 (defun org-e-html-footnote-section (info)
1377 (let* ((fn-alist (org-export-collect-footnote-definitions
1378 (plist-get info
:parse-tree
) info
))
1381 (loop for
(n type raw
) in fn-alist collect
1382 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1383 (org-trim (org-export-data raw
'e-html info
))
1385 (org-trim (org-export-secondary-string
1386 raw
'e-html info
))))))))
1388 (org-e-html-format-footnotes-section
1389 (nth 4 (or (assoc (plist-get info
:language
)
1390 org-export-language-setup
)
1391 (assoc "en" org-export-language-setup
)))
1393 "<table>\n%s\n</table>\n"
1394 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1396 (defun org-e-html-get-coding-system-for-write ()
1397 (or org-e-html-coding-system
1398 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1400 (defun org-e-html-get-coding-system-for-save ()
1401 (or org-e-html-coding-system
1402 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1404 (defun org-e-html-format-date (info)
1405 (let ((date (plist-get info
:date
)))
1407 ((and date
(string-match "%" date
))
1408 (format-time-string date
))
1410 (t (format-time-string "%Y-%m-%d %T %Z")))))
1414 ;;; Internal Functions (Ngz)
1416 (defun org-e-html--caption/label-string
(caption label info
)
1417 "Return caption and label HTML string for floats.
1419 CAPTION is a cons cell of secondary strings, the car being the
1420 standard caption and the cdr its short form. LABEL is a string
1421 representing the label. INFO is a plist holding contextual
1424 If there's no caption nor label, return the empty string.
1426 For non-floats, see `org-e-html--wrap-label'."
1427 (setq label nil
) ;; FIXME
1429 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1431 ((and (not caption
) (not label
)) "")
1432 ((not caption
) (format "\\label{%s}\n" label
))
1433 ;; Option caption format with short name.
1435 (format "\\caption[%s]{%s%s}\n"
1436 (org-export-secondary-string (cdr caption
) 'e-html info
)
1438 (org-export-secondary-string (car caption
) 'e-html info
)))
1439 ;; Standard caption format.
1440 ;; (t (format "\\caption{%s%s}\n"
1442 ;; (org-export-secondary-string (car caption) 'e-html info)))
1444 (t (org-export-secondary-string (car caption
) 'e-html info
)))))
1446 (defun org-e-html--find-verb-separator (s)
1447 "Return a character not used in string S.
1448 This is used to choose a separator for constructs like \\verb."
1449 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1450 (loop for c across ll
1451 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1452 return
(char-to-string c
))))
1454 (defun org-e-html--quotation-marks (text info
)
1455 "Export quotation marks depending on language conventions.
1456 TEXT is a string containing quotation marks to be replaced. INFO
1457 is a plist used as a communication channel."
1460 (while (setq start
(string-match (car l
) text start
))
1461 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1462 (setq text
(replace-match new-quote t t text
))))))
1463 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1464 ;; Falls back on English.
1465 (assoc "en" org-e-html-quotes
))))
1468 (defun org-e-html--wrap-label (element output
)
1469 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1470 This function shouldn't be used for floats. See
1471 `org-e-html--caption/label-string'."
1472 ;; (let ((label (org-element-property :name element)))
1473 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1475 ;; (concat (format "\\label{%s}\n" label) output)))
1482 (defun org-e-html-meta-info (info)
1483 (let* ((title (org-export-secondary-string
1484 (plist-get info
:title
) 'e-html info
))
1485 (author (and (plist-get info
:with-author
)
1486 (let ((auth (plist-get info
:author
)))
1487 (and auth
(org-export-secondary-string
1488 auth
'e-html info
)))))
1489 (description (plist-get info
:description
))
1490 (keywords (plist-get info
:keywords
)))
1492 (format "\n<title>%s</title>\n" title
)
1494 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1495 (or (and org-export-coding-system
1496 (fboundp 'coding-system-get
)
1497 (coding-system-get org-export-coding-system
1500 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1501 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1502 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1503 (org-e-html-format-date info
))
1504 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1505 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1506 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1508 (defun org-e-html-style (info)
1510 "\n" (when (plist-get info
:style-include-default
) org-e-html-style-default
)
1511 (plist-get info
:style
)
1512 (plist-get info
:style-extra
)
1514 (when (plist-get info
:style-include-scripts
)
1515 org-e-html-scripts
)))
1517 (defun org-e-html-mathjax-config (info)
1518 "Insert the user setup into the matchjax template."
1519 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1520 (let ((template org-e-html-mathjax-template
)
1521 (options org-e-html-mathjax-options
)
1522 (in-buffer (or (plist-get info
:mathjax
) ""))
1523 name val
(yes " ") (no "// ") x
)
1526 (setq name
(car e
) val
(nth 1 e
))
1527 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1528 (setq val
(car (read-from-string
1529 (substring in-buffer
(match-end 0))))))
1530 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1531 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1532 (setq template
(replace-match val t t template
))))
1534 (setq val
(nth 1 (assq 'mathml options
)))
1535 (if (string-match (concat "\\<mathml:") in-buffer
)
1536 (setq val
(car (read-from-string
1537 (substring in-buffer
(match-end 0))))))
1538 ;; Exchange prefixes depending on mathml setting
1539 (if (not val
) (setq x yes yes no no x
))
1540 ;; Replace cookies to turn on or off the config/jax lines
1541 (if (string-match ":MMLYES:" template
)
1542 (setq template
(replace-match yes t t template
)))
1543 (if (string-match ":MMLNO:" template
)
1544 (setq template
(replace-match no t t template
)))
1545 ;; Return the modified template
1548 (defun org-e-html-preamble (info)
1549 (when (plist-get info
:html-preamble
)
1550 (let* ((title (org-export-secondary-string
1551 (plist-get info
:title
) 'e-html info
))
1552 (date (org-e-html-format-date info
))
1553 (author (org-export-secondary-string
1554 (plist-get info
:author
) 'e-html info
))
1555 (lang-words (or (assoc (plist-get info
:language
)
1556 org-export-language-setup
)
1557 (assoc "en" org-export-language-setup
)))
1558 (email (plist-get info
:email
))
1559 (html-pre-real-contents
1561 ((functionp (plist-get info
:html-preamble
))
1563 (funcall (plist-get info
:html-preamble
))
1565 ((stringp (plist-get info
:html-preamble
))
1566 (format-spec (plist-get info
:html-preamble
)
1567 `((?t .
,title
) (?a .
,author
)
1568 (?d .
,date
) (?e .
,email
))))
1571 (or (cadr (assoc (nth 0 lang-words
)
1572 org-e-html-preamble-format
))
1573 (cadr (assoc "en" org-e-html-preamble-format
)))
1574 `((?t .
,title
) (?a .
,author
)
1575 (?d .
,date
) (?e .
,email
)))))))
1576 (when (not (equal html-pre-real-contents
""))
1579 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1582 html-pre-real-contents
1586 (defun org-e-html-postamble (info)
1588 (when (and (not body-only
)
1589 (plist-get info
:html-postamble
))
1590 (let* ((html-post (plist-get info
:html-postamble
))
1591 (date (org-e-html-format-date info
))
1592 (author (plist-get info
:author
))
1593 (email (plist-get info
:email
))
1594 (lang-words (or (assoc (plist-get info
:language
)
1595 org-export-language-setup
)
1596 (assoc "en" org-export-language-setup
)))
1598 (mapconcat (lambda(e)
1599 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1600 (split-string email
",+ *")
1602 (html-validation-link (or org-e-html-validation-link
""))
1604 (concat "Org version " org-version
" with Emacs version "
1605 (number-to-string emacs-major-version
))))
1609 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1612 ((eq (plist-get info
:html-postamble
) 'auto
)
1614 (when (plist-get info
:time-stamp-file
)
1616 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1617 (when (and (plist-get info
:with-author
) author
)
1619 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1620 (when (and (plist-get info
:with-email
) email
)
1622 <p class=\"email\"> %s </p>" email
))
1623 (when (plist-get info
:with-creator
)
1625 <p class=\"creator\"> %s </p>" creator-info
))
1626 html-validation-link
"\n"))
1627 ;; postamble from a string
1628 ((stringp (plist-get info
:html-postamble
))
1629 (format-spec (plist-get info
:html-postamble
)
1630 `((?a .
,author
) (?e .
,email
)
1631 (?d .
,date
) (?c .
,creator-info
)
1632 (?v .
,html-validation-link
))))
1634 ;; postamble from a function
1635 ((functionp (plist-get info
:html-postamble
))
1637 (funcall (plist-get info
:html-postamble
))
1639 ;; default postamble
1642 (or (cadr (assoc (nth 0 lang-words
)
1643 org-e-html-postamble-format
))
1644 (cadr (assoc "en" org-e-html-postamble-format
)))
1645 `((?a .
,author
) (?e .
,email
)
1646 (?d .
,date
) (?c .
,creator-info
)
1647 (?v .
,html-validation-link
)))))
1650 ;; org-e-html-html-helper-timestamp
1653 (defun org-e-html-template (contents info
)
1654 "Return complete document string after HTML conversion.
1655 CONTENTS is the transcoded contents string. RAW-DATA is the
1656 original parsed data. INFO is a plist holding export options."
1659 (or (and (stringp org-e-html-xml-declaration
)
1660 org-e-html-xml-declaration
)
1661 (cdr (assoc (plist-get info
:html-extension
)
1662 org-e-html-xml-declaration
))
1663 (cdr (assoc "html" org-e-html-xml-declaration
))
1666 (or (and coding-system-for-write
1667 (fboundp 'coding-system-get
)
1668 (coding-system-get coding-system-for-write
1672 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1673 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1675 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1676 (plist-get info
:language
) (plist-get info
:language
))
1679 (org-e-html-meta-info info
) ; meta
1680 (org-e-html-style info
) ; style
1681 (org-e-html-mathjax-config info
) ; mathjax
1687 (let ((link-up (and (plist-get info
:link-up
)
1688 (string-match "\\S-" (plist-get info
:link-up
))
1689 (plist-get info
:link-up
)))
1690 (link-home (and (plist-get info
:link-home
)
1691 (string-match "\\S-" (plist-get info
:link-home
))
1692 (plist-get info
:link-home
))))
1693 (when (or link-up link-home
)
1694 (format org-e-html-home
/up-format
1695 (or link-up link-home
)
1696 (or link-home link-up
))))
1698 (org-e-html-preamble info
)
1701 <div id=\"%s\">" (or org-e-html-content-div
1702 (nth 1 org-e-html-divs
)))
1705 <h1 class=\"title\">%s</h1>\n" (org-export-secondary-string
1706 (plist-get info
:title
) 'e-html info
))
1707 ;; table of contents
1708 (let ((depth (plist-get info
:with-toc
)))
1709 (when (wholenump depth
) (org-e-html-toc depth info
)))
1710 ;; document contents
1712 ;; footnotes section
1713 (org-e-html-footnote-section info
)
1715 (org-e-html-bibliography)
1722 (org-e-html-postamble info
)
1732 ;;; Transcode Helpers
1736 (defun org-e-html--todo (todo)
1738 (format "<span class=\"%s %s%s\">%s</span>"
1739 (if (member todo org-done-keywords
) "done" "todo")
1740 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
1745 (defun org-e-html--tags (tags)
1747 (format "<span class=\"tag\">%s</span>"
1750 (format "<span class=\"%s\">%s</span>"
1751 (concat org-e-html-tag-class-prefix
1752 (org-e-html-fix-class-name tag
))
1754 (org-split-string tags
":") " "))))
1758 (defun* org-e-html-format-headline
1759 (todo todo-type priority text tags
1760 &key level section-number headline-label
&allow-other-keys
)
1761 (let ((section-number
1762 (when section-number
1763 (format "<span class=\"section-number-%d\">%s</span> "
1764 level section-number
)))
1765 (todo (org-e-html--todo todo
))
1766 (tags (org-e-html--tags tags
)))
1767 (concat section-number todo
(and todo
" ") text
1768 (and tags
" ") tags
)))
1772 (defun org-e-html-fontify-code (code lang
)
1775 ;; Case 1: No lang. Possibly an example block.
1777 ;; Simple transcoding.
1778 (org-e-html-encode-plain-text code
))
1779 ;; Case 2: No htmlize or an inferior version of htmlize
1780 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1782 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1783 ;; Simple transcoding.
1784 (org-e-html-encode-plain-text code
))
1787 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1788 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1790 ;; Case 1: Language is not associated with any Emacs mode
1791 ((not (functionp lang-mode
))
1792 ;; Simple transcoding.
1793 (org-e-html-encode-plain-text code
))
1794 ;; Case 2: Default. Fotify code.
1797 (setq code
(with-temp-buffer
1800 (font-lock-fontify-buffer)
1801 ;; markup each line separately
1802 (org-remove-formatting-on-newlines-in-region
1803 (point-min) (point-max))
1805 (set-buffer-modified-p nil
)
1806 (org-export-e-htmlize-region-for-paste
1807 (point-min) (point-max))))
1808 ;; Strip any encolosing <pre></pre> tags
1809 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code
)
1810 (match-string 1 code
)
1813 (defun org-e-html-do-format-code
1814 (code &optional lang refs retain-labels num-start textarea-p
)
1816 (setq num-start nil refs nil lang nil
))
1817 (let* ((code-lines (org-split-string code
"\n"))
1818 (code-length (length code-lines
))
1822 (length (number-to-string (+ code-length num-start
))))))
1823 (code (org-e-html-fontify-code code lang
)))
1824 (assert (= code-length
(length (org-split-string code
"\n"))))
1825 (org-export-format-code
1827 (lambda (loc line-num ref
)
1830 ;; Add line number, if needed.
1832 (format "<span class=\"linenr\">%s</span>"
1833 (format num-fmt line-num
)))
1834 ;; Transcoded src line.
1836 ;; Add label, if needed.
1837 (when (and ref retain-labels
) (format " (%s)" ref
))))
1838 ;; Mark transcoded line as an anchor, if needed.
1840 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1844 (defun org-e-html-format-code (element info
)
1845 (let* ((lang (org-element-property :language element
))
1846 ;; (switches (org-element-property :switches element))
1847 (switches nil
) ; FIXME
1848 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1849 ;; Extract code and references.
1850 (code-info (org-export-unravel-code element
))
1851 (code (car code-info
))
1852 (refs (cdr code-info
))
1853 ;; Does the src block contain labels?
1854 (retain-labels (org-element-property :retain-labels element
))
1855 ;; Does it have line numbers?
1856 (num-start (case (org-element-property :number-lines element
)
1857 (continued (org-export-get-loc element info
))
1859 (org-e-html-do-format-code
1860 code lang refs retain-labels num-start textarea-p
)))
1864 ;;; Transcode Functions
1868 (defun org-e-html-center-block (center-block contents info
)
1869 "Transcode a CENTER-BLOCK element from Org to HTML.
1870 CONTENTS holds the contents of the block. INFO is a plist
1871 holding contextual information."
1872 (org-e-html--wrap-label
1874 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1879 ;; Comments are ignored.
1884 ;; Comment Blocks are ignored.
1889 (defun org-e-html-drawer (drawer contents info
)
1890 "Transcode a DRAWER element from Org to HTML.
1891 CONTENTS holds the contents of the block. INFO is a plist
1892 holding contextual information."
1893 (let* ((name (org-element-property :drawer-name drawer
))
1894 (output (if (functionp org-e-html-format-drawer-function
)
1895 (funcall org-e-html-format-drawer-function
1897 ;; If there's no user defined function: simply
1898 ;; display contents of the drawer.
1900 (org-e-html--wrap-label drawer output
)))
1905 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1906 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1907 CONTENTS holds the contents of the block. INFO is a plist
1908 holding contextual information. See
1910 (org-e-html--wrap-label dynamic-block contents
))
1915 (defun org-e-html-emphasis (emphasis contents info
)
1916 "Transcode EMPHASIS from Org to HTML.
1917 CONTENTS is the contents of the emphasized text. INFO is a plist
1918 holding contextual information.."
1919 (let* ((marker (org-element-property :marker emphasis
)))
1920 (format (cdr (assoc marker org-e-html-emphasis-alist
)) contents
)))
1925 (defun org-e-html-entity (entity contents info
)
1926 "Transcode an ENTITY object from Org to HTML.
1927 CONTENTS are the definition itself. INFO is a plist holding
1928 contextual information."
1929 (org-element-property :html entity
))
1934 (defun org-e-html-example-block (example-block contents info
)
1935 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1936 CONTENTS is nil. INFO is a plist holding contextual information."
1937 (let* ((options (or (org-element-property :options example-block
) ""))
1938 (lang (org-element-property :language example-block
))
1939 (caption (org-element-property :caption example-block
))
1940 (label (org-element-property :name example-block
))
1941 (caption-str (org-e-html--caption/label-string caption label info
))
1942 (attr (mapconcat #'identity
1943 (org-element-property :attr_html example-block
)
1945 ;; (switches (org-element-property :switches example-block))
1946 (switches nil
) ; FIXME
1947 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1948 (code (org-e-html-format-code example-block info
)))
1951 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
1952 80 (string-to-number (match-string 1 switches
))))
1953 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
1954 (string-to-number (match-string 1 switches
))
1955 (org-count-lines code
))))
1957 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1959 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
1964 (defun org-e-html-export-snippet (export-snippet contents info
)
1965 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1966 CONTENTS is nil. INFO is a plist holding contextual information."
1967 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
1968 (org-element-property :value export-snippet
)))
1973 (defun org-e-html-export-block (export-block contents info
)
1974 "Transcode a EXPORT-BLOCK element from Org to HTML.
1975 CONTENTS is nil. INFO is a plist holding contextual information."
1976 (when (string= (org-element-property :type export-block
) "latex")
1977 (org-remove-indentation (org-element-property :value export-block
))))
1982 (defun org-e-html-fixed-width (fixed-width contents info
)
1983 "Transcode a FIXED-WIDTH element from Org to HTML.
1984 CONTENTS is nil. INFO is a plist holding contextual information."
1985 (let* ((value (org-element-normalize-string
1986 (replace-regexp-in-string
1988 (org-element-property :value fixed-width
)))))
1989 (org-e-html--wrap-label
1990 fixed-width
(format "\n<pre class=\"example\">\n%s\n</pre>"
1991 (org-e-html-do-format-code value
)))))
1994 ;;;; Footnote Definition
1996 ;; Footnote Definitions are ignored.
1999 ;;;; Footnote Reference
2001 (defun org-e-html-footnote-reference (footnote-reference contents info
)
2002 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2003 CONTENTS is nil. INFO is a plist holding contextual information."
2005 ;; Insert separator between two footnotes in a row.
2006 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2007 (when (eq (org-element-type prev
) 'footnote-reference
)
2008 org-e-html-footnote-separator
))
2010 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2011 (org-e-html-format-footnote-reference
2012 (org-export-get-footnote-number footnote-reference info
)
2014 ;; Inline definitions are secondary strings.
2015 ((eq (org-element-property :type footnote-reference
) 'inline
)
2016 (org-e-html-format-footnote-reference
2017 (org-export-get-footnote-number footnote-reference info
)
2019 ;; Non-inline footnotes definitions are full Org data.
2020 (t (org-e-html-format-footnote-reference
2021 (org-export-get-footnote-number footnote-reference info
)
2027 (defun org-e-html-format-headline--wrap (headline info
2028 &optional format-function
2030 "Transcode an HEADLINE element from Org to HTML.
2031 CONTENTS holds the contents of the headline. INFO is a plist
2032 holding contextual information."
2033 (let* ((level (+ (org-export-get-relative-level headline info
)
2034 (1- org-e-html-toplevel-hlevel
)))
2035 (headline-number (org-export-get-headline-number headline info
))
2036 (section-number (and (org-export-numbered-headline-p headline info
)
2037 (mapconcat 'number-to-string
2038 headline-number
".")))
2039 (todo (and (plist-get info
:with-todo-keywords
)
2040 (let ((todo (org-element-property
2041 :todo-keyword headline
)))
2043 (org-export-secondary-string todo
'e-html info
)))))
2044 (todo-type (and todo
(org-element-property :todo-type headline
)))
2045 (priority (and (plist-get info
:with-priority
)
2046 (org-element-property :priority headline
)))
2047 (text (org-export-secondary-string
2048 (org-element-property :title headline
) 'e-html info
))
2049 (tags (and (plist-get info
:with-tags
)
2050 (org-element-property :tags headline
)))
2051 (headline-label (concat "sec-" (mapconcat 'number-to-string
2052 headline-number
"-")))
2053 (format-function (cond
2054 ((functionp format-function
) format-function
)
2055 ((functionp org-e-html-format-headline-function
)
2057 (lambda (todo todo-type priority text tags
2059 (funcall org-e-html-format-headline-function
2060 todo todo-type priority text tags
))))
2061 (t 'org-e-html-format-headline
))))
2062 (apply format-function
2063 todo todo-type priority text tags
2064 :headline-label headline-label
:level level
2065 :section-number section-number extra-keys
)))
2067 (defun org-e-html-headline (headline contents info
)
2068 "Transcode an HEADLINE element from Org to HTML.
2069 CONTENTS holds the contents of the headline. INFO is a plist
2070 holding contextual information."
2071 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2072 (level (org-export-get-relative-level headline info
))
2073 (text (org-export-secondary-string
2074 (org-element-property :title headline
) 'e-html info
))
2075 (todo (and (plist-get info
:with-todo-keywords
)
2076 (let ((todo (org-element-property
2077 :todo-keyword headline
)))
2079 (org-export-secondary-string todo
'e-html info
)))))
2080 (todo-type (and todo
(org-element-property :todo-type headline
)))
2081 (tags (and (plist-get info
:with-tags
)
2082 (org-element-property :tags headline
)))
2083 (priority (and (plist-get info
:with-priority
)
2084 (org-element-property :priority headline
)))
2085 (section-number (and (org-export-numbered-headline-p headline info
)
2086 (mapconcat 'number-to-string
2087 (org-export-get-headline-number
2088 headline info
) ".")))
2089 ;; Create the headline text.
2090 (full-text (org-e-html-format-headline--wrap headline info
)))
2092 ;; Case 1: This is a footnote section: ignore it.
2093 ((org-element-property :footnote-section-p headline
) nil
)
2094 ;; Case 2. This is a deep sub-tree: export it as a list item.
2095 ;; Also export as items headlines for which no section
2096 ;; format has been found.
2097 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2098 ;; Build the real contents of the sub-tree.
2099 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2100 (itemized-body (org-e-html-format-list-item
2101 contents type nil nil full-text
)))
2103 (and (org-export-first-sibling-p headline info
)
2104 (org-e-html-begin-plain-list type
))
2106 (and (org-export-last-sibling-p headline info
)
2107 (org-e-html-end-plain-list type
)))))
2108 ;; Case 3. Standard headline. Export it as a section.
2110 (let* ((extra-class (org-element-property :html-container-class headline
))
2111 (extra-ids (list (org-element-property :custom-id headline
)
2112 (org-element-property :id headline
)))
2117 (let ((id (org-solidify-link-text
2118 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2119 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2121 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2122 (id (mapconcat 'number-to-string
2123 (org-export-get-headline-number headline info
) "-")))
2124 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2125 (format "outline-container-%s" id
)
2126 (concat (format "outline-%d" level1
) (and extra-class
" ")
2128 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2129 level1 id extra-ids full-text level1
)
2133 ;;;; Horizontal Rule
2135 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2136 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2137 CONTENTS is nil. INFO is a plist holding contextual information."
2138 (let ((attr (mapconcat #'identity
2139 (org-element-property :attr_html horizontal-rule
)
2141 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2144 ;;;; Inline Babel Call
2146 ;; Inline Babel Calls are ignored.
2149 ;;;; Inline Src Block
2151 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2152 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2153 CONTENTS holds the contents of the item. INFO is a plist holding
2154 contextual information."
2155 (let* ((org-lang (org-element-property :language inline-src-block
))
2156 (code (org-element-property :value inline-src-block
))
2157 (separator (org-e-html--find-verb-separator code
)))
2163 (defun org-e-html-format-section (text class
&optional id
)
2164 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2165 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2167 (defun org-e-html-inlinetask (inlinetask contents info
)
2168 "Transcode an INLINETASK element from Org to HTML.
2169 CONTENTS holds the contents of the block. INFO is a plist
2170 holding contextual information."
2172 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2173 ;; with appropriate arguments.
2174 ((functionp org-e-html-format-inlinetask-function
)
2175 (let ((format-function
2177 (lambda (todo todo-type priority text tags
2178 &key contents
&allow-other-keys
)
2179 (funcall org-e-html-format-inlinetask-function
2180 todo todo-type priority text tags contents
)))))
2181 (org-e-html-format-headline--wrap
2182 inlinetask info format-function
:contents contents
)))
2183 ;; Otherwise, use a default template.
2184 (t (org-e-html--wrap-label
2187 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2188 (org-e-html-format-headline--wrap inlinetask info
)
2194 (defun org-e-html-checkbox (checkbox)
2195 (case checkbox
(on "<code>[X]</code>")
2196 (off "<code>[ ]</code>")
2197 (trans "<code>[-]</code>")
2200 (defun org-e-html-format-list-item (contents type checkbox
2201 &optional term-counter-id
2206 (let* ((counter term-counter-id
)
2207 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2208 (format "<li%s>" extra
)))
2210 (let* ((id term-counter-id
)
2211 (extra (if id
(format " id=\"%s\"" id
) "")))
2213 (format "<li%s>" extra
)
2214 (when headline
(concat headline
"<br/>")))))
2216 (let* ((term term-counter-id
))
2217 (setq term
(or term
"(no term)"))
2218 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2219 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2224 (descriptive "</dd>"))))
2226 (defun org-e-html-item (item contents info
)
2227 "Transcode an ITEM element from Org to HTML.
2228 CONTENTS holds the contents of the item. INFO is a plist holding
2229 contextual information."
2230 ;; Grab `:level' from plain-list properties, which is always the
2231 ;; first element above current item.
2232 (let* ((plain-list (org-export-get-parent item info
))
2233 (type (org-element-property :type plain-list
))
2234 (level (org-element-property :level plain-list
))
2235 (counter (org-element-property :counter item
))
2236 (checkbox (org-element-property :checkbox item
))
2237 (tag (let ((tag (org-element-property :tag item
)))
2238 (and tag
(org-export-secondary-string tag
'e-html info
)))))
2239 (org-e-html-format-list-item
2240 contents type checkbox
(or tag counter
))))
2245 (defun org-e-html-keyword (keyword contents info
)
2246 "Transcode a KEYWORD element from Org to HTML.
2247 CONTENTS is nil. INFO is a plist holding contextual information."
2248 (let ((key (org-element-property :key keyword
))
2249 (value (org-element-property :value keyword
)))
2251 ((string= key
"LATEX") value
)
2252 ((string= key
"INDEX") (format "\\index{%s}" value
))
2253 ;; Invisible targets.
2254 ((string= key
"TARGET") nil
) ; FIXME
2255 ((string= key
"TOC")
2256 (let ((value (downcase value
)))
2258 ((string-match "\\<headlines\\>" value
)
2259 (let ((depth (or (and (string-match "[0-9]+" value
)
2260 (string-to-number (match-string 0 value
)))
2261 (plist-get info
:with-toc
))))
2262 (when (wholenump depth
) (org-e-html-toc depth info
))))
2263 ((string= "tables" value
) "\\listoftables")
2264 ((string= "figures" value
) "\\listoffigures")
2265 ((string= "listings" value
)
2267 ;; At the moment, src blocks with a caption are wrapped
2268 ;; into a figure environment.
2269 (t "\\listoffigures")))))))))
2272 ;;;; Latex Environment
2274 (defun org-e-html-format-latex (latex-frag processing-type
)
2275 (let* ((cache-relpath
2276 (concat "ltxpng/" (file-name-sans-extension
2277 (file-name-nondirectory (buffer-file-name)))))
2278 (cache-dir (file-name-directory (buffer-file-name )))
2279 (display-msg "Creating LaTeX Image..."))
2283 (org-format-latex cache-relpath cache-dir nil display-msg
2284 nil nil processing-type
)
2287 (defun org-e-html-latex-environment (latex-environment contents info
)
2288 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2289 CONTENTS is nil. INFO is a plist holding contextual information."
2290 (org-e-html--wrap-label
2292 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2293 (latex-frag (org-remove-indentation
2294 (org-element-property :value latex-environment
)))
2295 (caption (org-e-html--caption/label-string
2296 (org-element-property :caption latex-environment
)
2297 (org-element-property :name latex-environment
)
2300 (label (org-element-property :name latex-environment
)))
2302 ((member processing-type
'(t mathjax
))
2303 (org-e-html-format-latex latex-frag
'mathjax
))
2304 ((equal processing-type
'dvipng
)
2305 (let* ((formula-link (org-e-html-format-latex
2306 latex-frag processing-type
)))
2307 (when (and formula-link
2308 (string-match "file:\\([^]]*\\)" formula-link
))
2309 (org-e-html-format-inline-image
2310 (match-string 1 formula-link
) caption label attr t
))))
2316 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2317 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2318 CONTENTS is nil. INFO is a plist holding contextual information."
2319 (let ((latex-frag (org-element-property :value latex-fragment
))
2320 (processing-type (plist-get info
:LaTeX-fragments
)))
2321 (case processing-type
2323 (org-e-html-format-latex latex-frag
'mathjax
))
2325 (let* ((formula-link (org-e-html-format-latex
2326 latex-frag processing-type
)))
2327 (when (and formula-link
2328 (string-match "file:\\([^]]*\\)" formula-link
))
2329 (org-e-html-format-inline-image
2330 (match-string 1 formula-link
)))))
2335 (defun org-e-html-line-break (line-break contents info
)
2336 "Transcode a LINE-BREAK object from Org to HTML.
2337 CONTENTS is nil. INFO is a plist holding contextual information."
2343 (defun org-e-html-link--inline-image (link desc info
)
2344 "Return HTML code for an inline image.
2345 LINK is the link pointing to the inline image. INFO is a plist
2346 used as a communication channel."
2347 (let* ((type (org-element-property :type link
))
2348 (raw-path (org-element-property :path link
))
2349 (path (cond ((member type
'("http" "https"))
2350 (concat type
":" raw-path
))
2351 ((file-name-absolute-p raw-path
)
2352 (expand-file-name raw-path
))
2354 (parent (org-export-get-parent-paragraph link info
))
2355 (caption (org-e-html--caption/label-string
2356 (org-element-property :caption parent
)
2357 (org-element-property :name parent
)
2359 (label (org-element-property :name parent
))
2360 ;; Retrieve latex attributes from the element around.
2361 (attr (let ((raw-attr
2362 (mapconcat #'identity
2363 (org-element-property :attr_html parent
)
2365 (unless (string= raw-attr
"") raw-attr
))))
2366 ;; Now clear ATTR from any special keyword and set a default
2367 ;; value if nothing is left.
2368 (setq attr
(if (not attr
) "" (org-trim attr
)))
2369 ;; Return proper string, depending on DISPOSITION.
2370 (org-e-html-format-inline-image
2371 path caption label attr
(org-e-html-standalone-image-p link info
))))
2373 (defvar org-e-html-standalone-image-predicate
)
2374 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2375 "Test if ELEMENT is a standalone image for the purpose HTML export.
2376 INFO is a plist holding contextual information.
2378 Return non-nil, if ELEMENT is of type paragraph and it's sole
2379 content, save for whitespaces, is a link that qualifies as an
2382 Return non-nil, if ELEMENT is of type link and it's containing
2383 paragraph has no other content save for leading and trailing
2386 Return nil, otherwise.
2388 Bind `org-e-html-standalone-image-predicate' to constrain
2389 paragraph further. For example, to check for only captioned
2390 standalone images, do the following.
2392 \(setq org-e-html-standalone-image-predicate
2393 \(lambda \(paragraph\)
2394 \(org-element-property :caption paragraph\)\)\)
2396 (let ((paragraph (case (org-element-type element
)
2398 (link (and (org-export-inline-image-p
2399 element org-e-html-inline-image-rules
)
2400 (org-export-get-parent element info
)))
2403 (assert (eq (org-element-type paragraph
) 'paragraph
))
2404 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2405 (functionp org-e-html-standalone-image-predicate
)))
2406 (funcall org-e-html-standalone-image-predicate paragraph
))
2407 (let ((contents (org-element-contents paragraph
)))
2408 (loop for x in contents
2409 with inline-image-count
= 0
2411 ((eq (org-element-type x
) 'plain-text
)
2412 (not (org-string-nw-p x
)))
2413 ((eq (org-element-type x
) 'link
)
2414 (when (org-export-inline-image-p
2415 x org-e-html-inline-image-rules
)
2416 (= (incf inline-image-count
) 1)))
2419 (defun org-e-html-link (link desc info
)
2420 "Transcode a LINK object from Org to HTML.
2422 DESC is the description part of the link, or the empty string.
2423 INFO is a plist holding contextual information. See
2425 (let* ((type (org-element-property :type link
))
2426 (raw-path (org-element-property :path link
))
2427 ;; Ensure DESC really exists, or set it to nil.
2428 (desc (and (not (string= desc
"")) desc
))
2430 ((member type
'("http" "https" "ftp" "mailto"))
2431 (concat type
":" raw-path
))
2432 ((string= type
"file")
2433 (when (string-match "\\(.+\\)::.+" raw-path
)
2434 (setq raw-path
(match-string 1 raw-path
)))
2435 (if (file-name-absolute-p raw-path
)
2436 (concat "file://" (expand-file-name raw-path
))
2437 ;; TODO: Not implemented yet. Concat also:
2438 ;; (org-export-directory :HTML info)
2439 (concat "file://" raw-path
)))
2444 ((and (or (eq t org-e-html-inline-images
)
2445 (and org-e-html-inline-images
(not desc
)))
2446 (org-export-inline-image-p link org-e-html-inline-image-rules
))
2447 (org-e-html-link--inline-image link desc info
))
2448 ;; Radioed target: Target's name is obtained from original raw
2449 ;; link. Path is parsed and transcoded in order to have a proper
2450 ;; display of the contents.
2451 ((string= type
"radio")
2452 (format "<a href=\"#%s\">%s</a>"
2453 (org-export-solidify-link-text path
)
2454 (org-export-secondary-string
2455 (org-element-parse-secondary-string
2456 path
(cdr (assq 'radio-target org-element-object-restrictions
)))
2458 ;; Links pointing to an headline: Find destination and build
2459 ;; appropriate referencing command.
2460 ((member type
'("custom-id" "fuzzy" "id"))
2461 (let ((destination (if (string= type
"fuzzy")
2462 (org-export-resolve-fuzzy-link link info
)
2463 (org-export-resolve-id-link link info
))))
2464 (case (org-element-type destination
)
2465 ;; Fuzzy link points nowhere.
2468 (or desc
(org-export-secondary-string
2469 (org-element-property :raw-link link
)
2471 ;; Fuzzy link points to an invisible target.
2473 ;; LINK points to an headline. If headlines are numbered
2474 ;; and the link has no description, display headline's
2475 ;; number. Otherwise, display description or headline's
2478 (let* ((headline-no (org-export-get-headline-number destination info
))
2479 (label (format "sec-%s" (mapconcat 'number-to-string
2481 (section-no (mapconcat 'number-to-string headline-no
".")))
2485 ((plist-get info
:section-numbers
) section-no
)
2486 (t (org-export-secondary-string
2487 (org-element-property :title destination
)
2489 (format "<a href=\"#%s\">%s</a>" label desc
)))
2490 ;; Fuzzy link points to a target. Do as above.
2492 (let ((path (org-export-solidify-link-text path
)) number
)
2495 ((org-e-html-standalone-image-p destination info
)
2496 (org-export-get-ordinal
2497 (assoc 'link
(org-element-contents destination
))
2498 info
'link
'org-e-html-standalone-image-p
))
2499 (t (org-export-get-ordinal destination info
))))
2500 (setq desc
(when number
2501 (if (atom number
) (number-to-string number
)
2502 (mapconcat 'number-to-string number
".")))))
2503 (format "<a href=\"#%s\">%s</a>" path
(or desc
"FIXME")))))))
2504 ;; Coderef: replace link with the reference name or the
2505 ;; equivalent line number.
2506 ((string= type
"coderef")
2507 (let ((fragment (concat "coderef-" path
)))
2508 (format "<a href=\"#%s\" %s>%s</a>" fragment
2509 (format (concat "class=\"coderef\""
2510 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2511 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2513 (format (org-export-get-coderef-format path
(or desc
"%s"))
2514 (org-export-resolve-coderef path info
)))))
2515 ;; Link type is handled by a special function.
2516 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2517 (funcall protocol
(org-link-unescape path
) desc
'html
))
2518 ;; External link with a description part.
2519 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2520 ;; External link without a description part.
2521 (path (format "<a href=\"%s\">%s</a>" path path
))
2522 ;; No path, only description. Try to do something useful.
2523 (t (format "<i>%s</i>" desc
)))))
2528 ;; Babel Calls are ignored.
2533 (defun org-e-html-macro (macro contents info
)
2534 "Transcode a MACRO element from Org to HTML.
2535 CONTENTS is nil. INFO is a plist holding contextual information."
2536 ;; Use available tools.
2537 (org-export-expand-macro macro info
))
2542 (defun org-e-html-paragraph (paragraph contents info
)
2543 "Transcode a PARAGRAPH element from Org to HTML.
2544 CONTENTS is the contents of the paragraph, as a string. INFO is
2545 the plist used as a communication channel."
2546 (let* ((style nil
) ; FIXME
2547 (class (cdr (assoc style
'((footnote .
"footnote")
2549 (extra (if class
(format " class=\"%s\"" class
) ""))
2550 (parent (org-export-get-parent paragraph info
)))
2552 ((and (equal (car parent
) 'item
)
2553 (= (org-element-property :begin paragraph
)
2554 (org-element-property :contents-begin parent
)))
2555 ;; leading paragraph in a list item have no tags
2557 ((org-e-html-standalone-image-p paragraph info
)
2560 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2565 (defun org-e-html-begin-plain-list (type &optional arg1
)
2568 (format "<ol%s>" (if arg1
; FIXME
2569 (format " start=\"%d\"" arg1
)
2572 (descriptive "<dl>")))
2574 (defun org-e-html-end-plain-list (type)
2578 (descriptive "</dl>")))
2580 (defun org-e-html-plain-list (plain-list contents info
)
2581 "Transcode a PLAIN-LIST element from Org to HTML.
2582 CONTENTS is the contents of the list. INFO is a plist holding
2583 contextual information."
2584 (let* (arg1 ;; FIXME
2585 (type (org-element-property :type plain-list
))
2586 (attr (mapconcat #'identity
2587 (org-element-property :attr_html plain-list
)
2589 (org-e-html--wrap-label
2590 plain-list
(format "%s\n%s%s"
2591 (org-e-html-begin-plain-list type
)
2592 contents
(org-e-html-end-plain-list type
)))))
2596 (defun org-e-html-convert-special-strings (string)
2597 "Convert special characters in STRING to HTML."
2598 (let ((all org-e-html-special-string-regexps
)
2600 (while (setq a
(pop all
))
2601 (setq re
(car a
) rpl
(cdr a
) start
0)
2602 (while (string-match re string start
)
2603 (setq string
(replace-match rpl t nil string
))))
2606 (defun org-e-html-encode-plain-text (s)
2607 "Convert plain text characters to HTML equivalent.
2608 Possible conversions are set in `org-export-html-protect-char-alist'."
2609 (let ((cl org-e-html-protect-char-alist
) c
)
2610 (while (setq c
(pop cl
))
2612 (while (string-match (car c
) s start
)
2613 (setq s
(replace-match (cdr c
) t t s
)
2614 start
(1+ (match-beginning 0))))))
2617 (defun org-e-html-plain-text (text info
)
2618 "Transcode a TEXT string from Org to HTML.
2619 TEXT is the string to transcode. INFO is a plist holding
2620 contextual information."
2621 (setq text
(org-e-html-encode-plain-text text
))
2622 ;; Protect %, #, &, $, ~, ^, _, { and }.
2623 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2625 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2627 ;; (setq text (replace-regexp-in-string
2628 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2629 ;; "$\\backslash$" text nil t 1))
2630 ;; HTML into \HTML{} and TeX into \TeX{}.
2631 ;; (let ((case-fold-search nil)
2633 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2634 ;; (setq text (replace-match
2635 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2636 ;; start (match-end 0))))
2637 ;; Handle quotation marks
2638 ;; (setq text (org-e-html--quotation-marks text info))
2639 ;; Convert special strings.
2640 ;; (when (plist-get info :with-special-strings)
2641 ;; (while (string-match (regexp-quote "...") text)
2642 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2643 (when (plist-get info
:with-special-strings
)
2644 (setq text
(org-e-html-convert-special-strings text
)))
2645 ;; Handle break preservation if required.
2646 (when (plist-get info
:preserve-breaks
)
2647 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2653 ;;;; Property Drawer
2655 (defun org-e-html-property-drawer (property-drawer contents info
)
2656 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2657 CONTENTS is nil. INFO is a plist holding contextual
2659 ;; The property drawer isn't exported but we want separating blank
2660 ;; lines nonetheless.
2666 (defun org-e-html-quote-block (quote-block contents info
)
2667 "Transcode a QUOTE-BLOCK element from Org to HTML.
2668 CONTENTS holds the contents of the block. INFO is a plist
2669 holding contextual information."
2670 (org-e-html--wrap-label
2671 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2676 (defun org-e-html-quote-section (quote-section contents info
)
2677 "Transcode a QUOTE-SECTION element from Org to HTML.
2678 CONTENTS is nil. INFO is a plist holding contextual information."
2679 (let ((value (org-remove-indentation
2680 (org-element-property :value quote-section
))))
2681 (when value
(format "<pre>\n%s</pre>" value
))))
2686 (defun org-e-html-section (section contents info
) ; FIXME
2687 "Transcode a SECTION element from Org to HTML.
2688 CONTENTS holds the contents of the section. INFO is a plist
2689 holding contextual information."
2690 (let ((parent (org-export-get-parent-headline section info
)))
2691 ;; Before first headline: no container, just return CONTENTS.
2692 (if (not parent
) contents
2693 ;; Get div's class and id references.
2694 (let ((class-num (+ (org-export-get-relative-level parent info
)
2695 (1- org-e-html-toplevel-hlevel
)))
2699 (org-export-get-headline-number parent info
) "-")))
2700 ;; Build return value.
2701 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2702 class-num id-num contents
)))))
2706 (defun org-e-html-radio-target (radio-target text info
)
2707 "Transcode a RADIO-TARGET object from Org to HTML.
2708 TEXT is the text of the target. INFO is a plist holding
2709 contextual information."
2710 (let ((id (org-export-solidify-link-text
2711 (org-element-property :value radio-target
))))
2712 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2717 (defun org-e-html-special-block (special-block contents info
)
2718 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2719 CONTENTS holds the contents of the block. INFO is a plist
2720 holding contextual information."
2721 (let ((type (downcase (org-element-property :type special-block
))))
2722 (org-e-html--wrap-label
2724 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2729 (defun org-e-html-src-block (src-block contents info
)
2730 "Transcode a SRC-BLOCK element from Org to HTML.
2731 CONTENTS holds the contents of the item. INFO is a plist holding
2732 contextual information."
2733 (let* ((lang (org-element-property :language src-block
))
2734 (caption (org-element-property :caption src-block
))
2735 (label (org-element-property :name src-block
))
2736 (caption-str (org-e-html--caption/label-string caption label info
))
2737 (attr (mapconcat #'identity
2738 (org-element-property :attr_html src-block
)
2740 ;; (switches (org-element-property :switches src-block))
2741 (switches nil
) ; FIXME
2742 (textarea-p (and switches
(string-match "-t\\>" switches
)))
2743 (code (org-e-html-format-code src-block info
)))
2746 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2747 (if (not caption
) ""
2748 (format "<label class=\"org-src-name\">%s</label>" caption-str
))
2749 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code
)))
2751 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2752 80 (string-to-number (match-string 1 switches
))))
2753 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2754 (string-to-number (match-string 1 switches
))
2755 (org-count-lines code
))))
2757 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2759 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
2761 ;;;; Statistics Cookie
2763 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2764 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2765 CONTENTS is nil. INFO is a plist holding contextual information."
2766 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2767 (format "<code>%s</code>" cookie-value
)))
2772 (defun org-e-html-subscript (subscript contents info
)
2773 "Transcode a SUBSCRIPT object from Org to HTML.
2774 CONTENTS is the contents of the object. INFO is a plist holding
2775 contextual information."
2776 (format "<sub>%s</sub>" contents
))
2781 (defun org-e-html-superscript (superscript contents info
)
2782 "Transcode a SUPERSCRIPT object from Org to HTML.
2783 CONTENTS is the contents of the object. INFO is a plist holding
2784 contextual information."
2785 (format "<sup>%s</sup>" contents
))
2790 (defun org-e-html-begin-table (caption label attributes
)
2791 (let* ((html-table-tag (or (plist-get info
:html-table-tag
) ; FIXME
2792 org-e-html-table-tag
))
2794 (org-e-html-splice-attributes html-table-tag attributes
)))
2796 (setq html-table-tag
2797 (org-e-html-splice-attributes
2799 (format "id=\"%s\"" (org-solidify-link-text label
)))))
2800 (concat "\n" html-table-tag
2801 (format "\n<caption>%s</caption>" (or caption
"")))))
2803 (defun org-e-html-end-table ()
2806 (defun org-e-html-format-table-cell (text r c horiz-span
)
2807 (let ((cell-style-cookie
2808 (if org-e-html-table-align-individual-fields
2809 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2810 org-e-html-format-table-no-css
)
2811 " align=\"%s\"" " class=\"%s\"")
2812 (or (aref (plist-get table-info
:alignment
) c
) "left")) ""))) ;; FIXME
2814 (org-e-html-table-cur-rowgrp-is-hdr
2816 (format (car org-e-html-table-header-tags
) "col" cell-style-cookie
)
2817 text
(cdr org-e-html-table-header-tags
)))
2818 ((and (= c
0) org-e-html-table-use-header-tags-for-first-column
)
2820 (format (car org-e-html-table-header-tags
) "row" cell-style-cookie
)
2821 text
(cdr org-e-html-table-header-tags
)))
2824 (format (car org-e-html-table-data-tags
) cell-style-cookie
)
2825 text
(cdr org-e-html-table-data-tags
))))))
2827 (defun org-e-html-format-table-row (row)
2828 (concat (eval (car org-e-html-table-row-tags
)) row
2829 (eval (cdr org-e-html-table-row-tags
))))
2831 (defun org-e-html-table-row (fields &optional text-for-empty-fields
)
2832 (incf org-e-html-table-rownum
)
2834 (org-e-html-format-table-row
2837 (when (and (string= x
"") text-for-empty-fields
)
2838 (setq x text-for-empty-fields
))
2841 (org-e-html-format-table-cell
2842 x org-e-html-table-rownum i
(or horiz-span
0))))
2845 (defun org-e-html-end-table-rowgroup ()
2846 (when org-e-html-table-rowgrp-open
2847 (setq org-e-html-table-rowgrp-open nil
)
2848 (if org-e-html-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>")))
2850 (defun org-e-html-begin-table-rowgroup (&optional is-header-row
)
2852 (when org-e-html-table-rowgrp-open
2853 (org-e-html-end-table-rowgroup))
2855 (setq org-e-html-table-rowgrp-open t
)
2856 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row
)
2857 (if is-header-row
"<thead>" "<tbody>"))))
2859 (defun org-e-html-table-preamble ()
2860 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
2861 c gr colgropen preamble
)
2862 (unless (aref colgroup-vector
0)
2863 (setf (aref colgroup-vector
0) 'start
))
2864 (dotimes (c columns-number preamble
)
2865 (setq gr
(aref colgroup-vector c
))
2869 (when (memq gr
'(start start-end
))
2870 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
2871 (setq colgropen t
)))
2872 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
2873 (align (cdr (assoc (aref colalign-vector c
)
2876 ("c" .
"center")))))
2877 (alignspec (if (and (boundp 'org-e-html-format-table-no-css
)
2878 org-e-html-format-table-no-css
)
2879 " align=\"%s\"" " class=\"%s\""))
2880 (extra (format alignspec align
)))
2881 (format "<col%s />" extra
))
2882 (when (memq gr
'(end start-end
))
2883 (setq colgropen nil
)
2885 (concat preamble
(if colgropen
"</colgroup>"))))
2887 (defun org-e-html-list-table (lines caption label attributes
)
2888 (setq lines
(org-e-html-org-table-to-list-table lines
))
2889 (let* ((splice nil
) head
2890 (org-e-html-table-rownum -
1)
2893 org-e-html-table-cur-rowgrp-is-hdr
2894 org-e-html-table-rowgrp-open
2896 (org-lparse-table-style 'org-table
)
2897 org-lparse-table-is-styled
)
2900 (setq org-lparse-table-is-styled nil
)
2901 (mapconcat 'org-e-html-table-row lines
"\n"))
2903 (setq org-lparse-table-is-styled t
)
2906 (org-e-html-begin-table caption label attributes
)
2907 (org-e-html-table-preamble)
2908 (org-e-html-begin-table-rowgroup head
)
2913 ((equal line
'hline
) (org-e-html-begin-table-rowgroup))
2914 (t (org-e-html-table-row line
))))
2917 (org-e-html-end-table-rowgroup)
2918 (org-e-html-end-table))))))
2920 (defun org-e-html-transcode-table-row (row)
2921 (if (string-match org-table-hline-regexp row
) 'hline
2924 (org-export-secondary-string
2925 (let ((cell (org-element-parse-secondary-string
2927 (cdr (assq 'table org-element-string-restrictions
)))))
2930 (org-split-string row
"[ \t]*|[ \t]*"))))
2932 (defun org-e-html-org-table-to-list-table (lines &optional splice
)
2933 "Convert org-table to list-table.
2934 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
2935 element is a `string' representing a single row of org-table.
2936 Thus each ROW has vertical separators \"|\" separating the table
2937 fields. A ROW could also be a row-group separator of the form
2938 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
2939 ...). ROW could either be symbol `'hline' or a list of the
2940 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
2944 (while (setq line
(pop lines
))
2945 (unless (string-match "^[ \t]*|-" line
)
2946 (push (org-e-html-transcode-table-row line
) lines-1
))))
2947 (t (while (setq line
(pop lines
))
2949 ((string-match "^[ \t]*|-" line
)
2950 (when lines
(push 'hline lines-1
)))
2951 (t (push (org-e-html-transcode-table-row line
) lines-1
))))))
2952 (nreverse lines-1
)))
2954 (defun org-e-html-table-table (raw-table)
2956 (with-current-buffer (get-buffer-create "*org-export-table*")
2958 (let ((output (with-temp-buffer
2961 (re-search-forward "^[ \t]*|[^|]" nil t
)
2962 (table-generate-source 'html
"*org-export-table*")
2963 (with-current-buffer "*org-export-table*"
2964 (org-trim (buffer-string))))))
2965 (kill-buffer (get-buffer "*org-export-table*"))
2968 (defun org-e-html-table (table contents info
)
2969 "Transcode a TABLE element from Org to HTML.
2970 CONTENTS is nil. INFO is a plist holding contextual information."
2971 (let* ((label (org-element-property :name table
))
2972 (caption (org-e-html--caption/label-string
2973 (org-element-property :caption table
) label info
))
2974 (attr (mapconcat #'identity
2975 (org-element-property :attr_html table
)
2977 (raw-table (org-element-property :raw-table table
))
2978 (table-type (org-element-property :type table
)))
2981 (org-e-html-table-table raw-table
))
2983 (let* ((table-info (org-export-table-format-info raw-table
))
2984 (columns-number (length (plist-get table-info
:alignment
)))
2985 (lines (org-split-string
2986 (org-export-clean-table
2987 raw-table
(plist-get table-info
:special-column-p
)) "\n")))
2988 (org-e-html-list-table lines caption label attr
))))))
2993 (defun org-e-html-target (target contents info
)
2994 "Transcode a TARGET object from Org to HTML.
2995 CONTENTS is nil. INFO is a plist holding contextual
2997 (let ((id (org-export-solidify-link-text
2998 (org-element-property :value target
))))
2999 (format "<a id=\"%s\" name=\"%s\"/>" id id
)))
3004 (defun org-e-html-time-stamp (time-stamp contents info
)
3005 "Transcode a TIME-STAMP object from Org to HTML.
3006 CONTENTS is nil. INFO is a plist holding contextual
3008 (let ((value (org-element-property :value time-stamp
))
3009 (type (org-element-property :type time-stamp
))
3010 (appt-type (org-element-property :appt-type time-stamp
)))
3011 (setq value
(org-translate-time
3012 (org-export-secondary-string value
'e-html info
)))
3013 (setq appt-type
(case appt-type
3014 (scheduled org-scheduled-string
)
3015 (deadline org-deadline-string
)
3016 (closed org-closed-string
)))
3017 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
3018 (if (not appt-type
) ""
3019 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type
))
3020 (format "<span class=\"timestamp\">%s</span>" value
))))
3025 (defun org-e-html-verbatim (verbatim contents info
)
3026 "Transcode a VERBATIM object from Org to HTML.
3027 CONTENTS is nil. INFO is a plist used as a communication
3029 (org-e-html-emphasis
3030 verbatim
(org-element-property :value verbatim
) info
))
3035 (defun org-e-html-verse-block (verse-block contents info
)
3036 "Transcode a VERSE-BLOCK element from Org to HTML.
3037 CONTENTS is nil. INFO is a plist holding contextual information."
3038 ;; Replace each newline character with line break. Also replace
3039 ;; each blank line with a line break.
3040 (setq contents
(replace-regexp-in-string
3041 "^ *\\\\\\\\$" "<br/>\n"
3042 (replace-regexp-in-string
3043 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3044 (org-remove-indentation
3045 (org-export-secondary-string
3046 (org-element-property :value verse-block
)
3048 ;; Replace each white space at beginning of a line with a
3049 ;; non-breaking space.
3050 (while (string-match "^[ \t]+" contents
)
3051 (let* ((num-ws (length (match-string 0 contents
)))
3052 (ws (let (out) (dotimes (i num-ws out
)
3053 (setq out
(concat out
" "))))))
3054 (setq contents
(replace-match ws nil t contents
))))
3055 (org-e-html--wrap-label
3056 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3061 ;;; Filter Functions
3063 ;;;; Filter Settings
3065 (defconst org-e-html-filters-alist
3066 '((:filter-final-output . org-e-html-final-function
))
3067 "Alist between filters keywords and back-end specific filters.
3068 See `org-export-filters-alist' for more information.")
3073 (defun org-e-html-final-function (contents backend info
)
3074 (if (not org-e-html-pretty-output
) contents
3078 (indent-region (point-min) (point-max))
3079 (buffer-substring-no-properties (point-min) (point-max)))))
3082 ;;; Interactive functions
3084 (defun org-e-html-export-to-html
3085 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3086 "Export current buffer to a HTML file.
3088 If narrowing is active in the current buffer, only export its
3091 If a region is active, export that region.
3093 When optional argument SUBTREEP is non-nil, export the sub-tree
3094 at point, extracting information from the headline properties
3097 When optional argument VISIBLE-ONLY is non-nil, don't export
3098 contents of hidden elements.
3100 When optional argument BODY-ONLY is non-nil, only write code
3101 between \"\\begin{document}\" and \"\\end{document}\".
3103 EXT-PLIST, when provided, is a property list with external
3104 parameters overriding Org default settings, but still inferior to
3105 file-local settings.
3107 When optional argument PUB-DIR is set, use it as the publishing
3110 Return output file's name."
3112 (let* ((extension (concat "." org-e-html-extension
))
3113 (file (org-export-output-file-name extension subtreep pub-dir
)))
3115 'e-html file subtreep visible-only body-only ext-plist
)))
3119 ;;; FIXMES, TODOS, FOR REVIEW etc
3121 ;;;; org-format-table-html
3122 ;;;; org-format-org-table-html
3123 ;;;; org-format-table-table-html
3124 ;;;; org-table-number-fraction
3125 ;;;; org-table-number-regexp
3126 ;;;; org-e-html-table-caption-above
3129 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3130 ;;;; Remove display properties
3132 ;;;; org-e-html-with-timestamp
3133 ;;;; org-e-html-html-helper-timestamp
3135 ;;;; org-export-as-html-and-open
3136 ;;;; org-export-as-html-batch
3137 ;;;; org-export-as-html-to-buffer
3138 ;;;; org-replace-region-by-html
3139 ;;;; org-export-region-as-html
3140 ;;;; org-export-as-html
3142 ;;;; (org-export-directory :html opt-plist)
3143 ;;;; (plist-get opt-plist :html-extension)
3144 ;;;; org-e-html-toplevel-hlevel
3145 ;;;; org-e-html-special-string-regexps
3146 ;;;; org-e-html-coding-system
3147 ;;;; org-e-html-coding-system
3148 ;;;; org-e-html-inline-images
3149 ;;;; org-e-html-inline-image-extensions
3150 ;;;; org-e-html-protect-char-alist
3151 ;;;; org-e-html-table-use-header-tags-for-first-column
3152 ;;;; org-e-html-todo-kwd-class-prefix
3153 ;;;; org-e-html-tag-class-prefix
3154 ;;;; org-e-html-footnote-separator
3156 ;;;; org-export-preferred-target-alist
3157 ;;;; org-solidify-link-text
3158 ;;;; class for anchors
3159 ;;;; org-export-with-section-numbers, body-only
3160 ;;;; org-export-mark-todo-in-toc
3162 (provide 'org-e-html
)
3163 ;;; org-e-html.el ends here