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
)
167 (defvar org-e-html-headline-formatter
168 (lambda (level snumber todo todo-type priority
169 title tags target extra-targets extra-class
)
170 (concat snumber
" " title
)))
174 ;;; User Configuration Variables
176 (defgroup org-export-e-html nil
177 "Options for exporting Org mode files to HTML."
178 :tag
"Org Export HTML"
183 (defcustom org-e-html-pretty-output t
184 "Enable this to generate pretty HTML."
185 :group
'org-export-e-html
191 (defcustom org-e-html-extension
"html"
192 "The extension for exported HTML files."
193 :group
'org-export-e-html
196 (defcustom org-e-html-xml-declaration
197 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
198 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
199 "The extension for exported HTML files.
200 %s will be replaced with the charset of the exported file.
201 This may be a string, or an alist with export extensions
202 and corresponding declarations."
203 :group
'org-export-e-html
205 (string :tag
"Single declaration")
206 (repeat :tag
"Dependent on extension"
207 (cons (string :tag
"Extension")
208 (string :tag
"Declaration")))))
210 (defcustom org-e-html-coding-system nil
211 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
212 :group
'org-export-e-html
213 :type
'coding-system
)
215 (defvar org-e-html-content-div
"content"
216 "The name of the container DIV that holds all the page contents.
218 This variable is obsolete since Org version 7.7.
219 Please set `org-e-html-divs' instead.")
221 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
222 "The name of the main divs for HTML export.
223 This is a list of three strings, the first one for the preamble
224 DIV, the second one for the content DIV and the third one for the
226 :group
'org-export-e-html
228 (string :tag
" Div for the preamble:")
229 (string :tag
" Div for the content:")
230 (string :tag
"Div for the postamble:")))
233 ;;;; Document Header (Styles)
235 (defconst org-e-html-style-default
236 "<style type=\"text/css\">
237 <!--/*--><![CDATA[/*><!--*/
238 html { font-family: Times, serif; font-size: 12pt; }
239 .title { text-align: center; }
240 .todo { color: red; }
241 .done { color: green; }
242 .tag { background-color: #add8e6; font-weight:normal }
244 .timestamp { color: #bebebe; }
245 .timestamp-kwd { color: #5f9ea0; }
246 .right {margin-left:auto; margin-right:0px; text-align:right;}
247 .left {margin-left:0px; margin-right:auto; text-align:left;}
248 .center {margin-left:auto; margin-right:auto; text-align:center;}
249 p.verse { margin-left: 3% }
251 border: 1pt solid #AEBDCC;
252 background-color: #F3F5F7;
254 font-family: courier, monospace;
258 table { border-collapse: collapse; }
259 td, th { vertical-align: top; }
260 th.right { text-align:center; }
261 th.left { text-align:center; }
262 th.center { text-align:center; }
263 td.right { text-align:right; }
264 td.left { text-align:left; }
265 td.center { text-align:center; }
266 dt { font-weight: bold; }
267 div.figure { padding: 0.5em; }
268 div.figure p { text-align: center; }
271 border:2px solid gray;
275 textarea { overflow-x: auto; }
276 .linenr { font-size:smaller }
277 .code-highlighted {background-color:#ffff00;}
278 .org-info-js_info-navigation { border-style:none; }
279 #org-info-js_console-label { font-size:10px; font-weight:bold;
280 white-space:nowrap; }
281 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
285 "The default style specification for exported HTML files.
286 Please use the variables `org-e-html-style' and
287 `org-e-html-style-extra' to add to this style. If you wish to not
288 have the default style included, customize the variable
289 `org-e-html-style-include-default'.")
291 (defcustom org-e-html-style-include-default t
292 "Non-nil means include the default style in exported HTML files.
293 The actual style is defined in `org-e-html-style-default' and should
294 not be modified. Use the variables `org-e-html-style' to add
295 your own style information."
296 :group
'org-export-e-html
299 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
301 (defcustom org-e-html-style
""
302 "Org-wide style definitions for exported HTML files.
304 This variable needs to contain the full HTML structure to provide a style,
305 including the surrounding HTML tags. If you set the value of this variable,
306 you should consider to include definitions for the following classes:
307 title, todo, done, timestamp, timestamp-kwd, tag, target.
309 For example, a valid value would be:
311 <style type=\"text/css\">
313 p { font-weight: normal; color: gray; }
315 .title { text-align: center; }
316 .todo, .timestamp-kwd { color: red; }
317 .done { color: green; }
321 If you'd like to refer to an external style file, use something like
323 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
325 As the value of this option simply gets inserted into the HTML <head> header,
326 you can \"misuse\" it to add arbitrary text to the header.
327 See also the variable `org-e-html-style-extra'."
328 :group
'org-export-e-html
331 (put 'org-e-html-style
'safe-local-variable
'stringp
)
333 (defcustom org-e-html-style-extra
""
334 "Additional style information for HTML export.
335 The value of this variable is inserted into the HTML buffer right after
336 the value of `org-e-html-style'. Use this variable for per-file
337 settings of style information, and do not forget to surround the style
338 settings with <style>...</style> tags."
339 :group
'org-export-e-html
342 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
344 (defcustom org-e-html-mathjax-options
345 '((path "http://orgmode.org/mathjax/MathJax.js")
350 "Options for MathJax setup.
352 path The path where to find MathJax
353 scale Scaling for the HTML-CSS backend, usually between 100 and 133
354 align How to align display math: left, center, or right
355 indent If align is not center, how far from the left/right side?
356 mathml Should a MathML player be used if available?
357 This is faster and reduces bandwidth use, but currently
358 sometimes has lower spacing quality. Therefore, the default is
359 nil. When browsers get better, this switch can be flipped.
361 You can also customize this for each buffer, using something like
363 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
364 :group
'org-export-e-html
365 :type
'(list :greedy t
366 (list :tag
"path (the path from where to load MathJax.js)"
367 (const :format
" " path
) (string))
368 (list :tag
"scale (scaling for the displayed math)"
369 (const :format
" " scale
) (string))
370 (list :tag
"align (alignment of displayed equations)"
371 (const :format
" " align
) (string))
372 (list :tag
"indent (indentation with left or right alignment)"
373 (const :format
" " indent
) (string))
374 (list :tag
"mathml (should MathML display be used is possible)"
375 (const :format
" " mathml
) (boolean))))
378 ;;;; Document Header (Scripts)
380 (defcustom org-e-html-style-include-scripts t
381 "Non-nil means include the JavaScript snippets in exported HTML files.
382 The actual script is defined in `org-e-html-scripts' and should
384 :group
'org-export-e-html
387 (defconst org-e-html-scripts
388 "<script type=\"text/javascript\">
389 <!--/*--><![CDATA[/*><!--*/
390 function CodeHighlightOn(elem, id)
392 var target = document.getElementById(id);
394 elem.cacheClassElem = elem.className;
395 elem.cacheClassTarget = target.className;
396 target.className = \"code-highlighted\";
397 elem.className = \"code-highlighted\";
400 function CodeHighlightOff(elem, id)
402 var target = document.getElementById(id);
403 if(elem.cacheClassElem)
404 elem.className = elem.cacheClassElem;
405 if(elem.cacheClassTarget)
406 target.className = elem.cacheClassTarget;
410 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
413 ;;;; Document Header (Mathjax)
415 (defcustom org-e-html-mathjax-template
416 "<script type=\"text/javascript\" src=\"%PATH\">
417 <!--/*--><![CDATA[/*><!--*/
419 // Only one of the two following lines, depending on user settings
420 // First allows browser-native MathML display, second forces HTML/CSS
421 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
422 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
423 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
424 \"TeX/noUndefined.js\"],
426 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
427 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
428 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
429 ignoreClass: \"tex2jax_ignore\",
430 processEscapes: false,
431 processEnvironments: true,
434 showProcessingMessages: true,
435 displayAlign: \"%ALIGN\",
436 displayIndent: \"%INDENT\",
440 availableFonts: [\"STIX\",\"TeX\"],
441 preferredFont: \"TeX\",
457 "The MathJax setup for XHTML files."
458 :group
'org-export-e-html
464 (defcustom org-e-html-preamble t
465 "Non-nil means insert a preamble in HTML export.
467 When `t', insert a string as defined by one of the formatting
468 strings in `org-e-html-preamble-format'. When set to a
469 string, this string overrides `org-e-html-preamble-format'.
470 When set to a function, apply this function and insert the
471 returned string. The function takes the property list of export
472 options as its only argument.
474 Setting :html-preamble in publishing projects will take
475 precedence over this variable."
476 :group
'org-export-e-html
477 :type
'(choice (const :tag
"No preamble" nil
)
478 (const :tag
"Default preamble" t
)
479 (string :tag
"Custom formatting string")
480 (function :tag
"Function (must return a string)")))
482 (defcustom org-e-html-preamble-format
'(("en" ""))
483 "The format for the HTML preamble.
485 %t stands for the title.
486 %a stands for the author's name.
487 %e stands for the author's email.
488 %d stands for the date.
490 If you need to use a \"%\" character, you need to escape it
492 :group
'org-export-e-html
495 (defcustom org-e-html-home
/up-format
496 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
497 <a accesskey=\"h\" href=\"%s\"> UP </a>
499 <a accesskey=\"H\" href=\"%s\"> HOME </a>
501 "Snippet used to insert the HOME and UP links.
502 This is a format string, the first %s will receive the UP link,
503 the second the HOME link. If both `org-e-html-link-up' and
504 `org-e-html-link-home' are empty, the entire snippet will be
506 :group
'org-export-e-html
511 (defcustom org-e-html-postamble
'auto
512 "Non-nil means insert a postamble in HTML export.
514 When `t', insert a string as defined by the formatting string in
515 `org-e-html-postamble-format'. When set to a string, this
516 string overrides `org-e-html-postamble-format'. When set to
517 'auto, discard `org-e-html-postamble-format' and honor
518 `org-export-author/email/creator-info' variables. When set to a
519 function, apply this function and insert the returned string.
520 The function takes the property list of export options as its
523 Setting :html-postamble in publishing projects will take
524 precedence over this variable."
525 :group
'org-export-e-html
526 :type
'(choice (const :tag
"No postamble" nil
)
527 (const :tag
"Auto preamble" 'auto
)
528 (const :tag
"Default formatting string" t
)
529 (string :tag
"Custom formatting string")
530 (function :tag
"Function (must return a string)")))
532 (defcustom org-e-html-postamble-format
533 '(("en" "<p class=\"author\">Author: %a (%e)</p>
534 <p class=\"date\">Date: %d</p>
535 <p class=\"creator\">Generated by %c</p>
536 <p class=\"xhtml-validation\">%v</p>
538 "The format for the HTML postamble.
540 %a stands for the author's name.
541 %e stands for the author's email.
542 %d stands for the date.
543 %c will be replaced by information about Org/Emacs versions.
544 %v will be replaced by `org-e-html-validation-link'.
546 If you need to use a \"%\" character, you need to escape it
548 :group
'org-export-e-html
551 (defcustom org-e-html-validation-link
552 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
553 "Link to HTML validation service."
554 :group
'org-export-e-html
557 ;; FIXME Obsolete since Org 7.7
558 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
561 (defcustom org-e-html-protect-char-alist
565 "Alist of characters to be converted by `org-e-html-protect'."
566 :group
'org-export-e-html
567 :type
'(repeat (cons (string :tag
"Character")
568 (string :tag
"HTML equivalent"))))
570 (defconst org-e-html-special-string-regexps
571 '(("\\\\-" .
"­")
572 ("---\\([^-]\\)" .
"—\\1")
573 ("--\\([^-]\\)" .
"–\\1")
574 ("\\.\\.\\." .
"…"))
575 "Regular expressions for special string conversion.")
580 (defcustom org-e-html-todo-kwd-class-prefix
""
581 "Prefix to class names for TODO keywords.
582 Each TODO keyword gets a class given by the keyword itself, with this prefix.
583 The default prefix is empty because it is nice to just use the keyword
584 as a class name. But if you get into conflicts with other, existing
585 CSS classes, then this prefix can be very useful."
586 :group
'org-export-e-html
592 (defcustom org-e-html-tag-class-prefix
""
593 "Prefix to class names for TODO keywords.
594 Each tag gets a class given by the tag itself, with this prefix.
595 The default prefix is empty because it is nice to just use the keyword
596 as a class name. But if you get into conflicts with other, existing
597 CSS classes, then this prefix can be very useful."
598 :group
'org-export-e-html
602 ;;;; Statistics Cookie
608 (defcustom org-e-html-inline-images
'maybe
609 "Non-nil means inline images into exported HTML pages.
610 This is done using an <img> tag. When nil, an anchor with href is used to
611 link to the image. If this option is `maybe', then images in links with
612 an empty description will be inlined, while images with a description will
614 :group
'org-export-e-html
615 :type
'(choice (const :tag
"Never" nil
)
616 (const :tag
"Always" t
)
617 (const :tag
"When there is no description" maybe
)))
619 (defcustom org-e-html-inline-image-extensions
620 '("png" "jpeg" "jpg" "gif" "svg")
621 "Extensions of image files that can be inlined into HTML."
622 :group
'org-export-e-html
623 :type
'(repeat (string :tag
"Extension")))
639 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
640 <h2 class=\"footnotes\">%s: </h2>
641 <div id=\"text-footnotes\">
645 "Format for the footnotes section.
646 Should contain a two instances of %s. The first will be replaced with the
647 language-specific word for \"Footnotes\", the second one will be replaced
648 by the footnotes themselves."
649 :group
'org-export-e-html
652 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
653 "The format for the footnote reference.
654 %s will be replaced by the footnote reference itself."
655 :group
'org-export-e-html
658 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
659 "Text used to separate footnotes."
660 :group
'org-export-e-html
666 ;;;; Inline Babel Call
667 ;;;; Inline Src Block
671 ;;;; Latex Environment
688 (defgroup org-export-e-htmlize nil
689 "Options for processing examples with htmlize.el."
690 :tag
"Org Export Htmlize"
691 :group
'org-export-e-html
)
693 (defcustom org-export-e-htmlize-output-type
'inline-css
694 "Output type to be used by htmlize when formatting code snippets.
695 Choices are `css', to export the CSS selectors only, or `inline-css', to
696 export the CSS attribute values inline in the HTML. We use as default
697 `inline-css', in order to make the resulting HTML self-containing.
699 However, this will fail when using Emacs in batch mode for export, because
700 then no rich font definitions are in place. It will also not be good if
701 people with different Emacs setup contribute HTML files to a website,
702 because the fonts will represent the individual setups. In these cases,
703 it is much better to let Org/Htmlize assign classes only, and to use
704 a style file to define the look of these classes.
705 To get a start for your css file, start Emacs session and make sure that
706 all the faces you are interested in are defined, for example by loading files
707 in all modes you want. Then, use the command
708 \\[org-export-e-htmlize-generate-css] to extract class definitions."
709 :group
'org-export-e-htmlize
710 :type
'(choice (const css
) (const inline-css
)))
712 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
713 "The prefix for CSS class names for htmlize font specifications."
714 :group
'org-export-e-htmlize
717 (defcustom org-export-e-htmlized-org-css-url nil
718 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
719 Normally when creating an htmlized version of an Org buffer, htmlize will
720 create CSS to define the font colors. However, this does not work when
721 converting in batch mode, and it also can look bad if different people
722 with different fontification setup work on the same website.
723 When this variable is non-nil, creating an htmlized version of an Org buffer
724 using `org-export-as-org' will remove the internal CSS section and replace it
725 with a link to this URL."
726 :group
'org-export-e-htmlize
728 (const :tag
"Keep internal css" nil
)
729 (string :tag
"URL or local href")))
734 (defcustom org-e-html-table-tag
735 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
736 "The HTML tag that is used to start a table.
737 This must be a <table> tag, but you may change the options like
738 borders and spacing."
739 :group
'org-export-e-html
742 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
743 "The opening tag for table header fields.
744 This is customizable so that alignment options can be specified.
745 The first %s will be filled with the scope of the field, either row or col.
746 The second %s will be replaced by a style entry to align the field.
747 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
748 See also the variable `org-e-html-table-align-individual-fields'."
749 :group
'org-export-tables
; FIXME: change group?
750 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
752 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
753 "The opening tag for table data fields.
754 This is customizable so that alignment options can be specified.
755 The first %s will be filled with the scope of the field, either row or col.
756 The second %s will be replaced by a style entry to align the field.
757 See also the variable `org-e-html-table-align-individual-fields'."
758 :group
'org-export-tables
759 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
761 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
762 "The opening tag for table data fields.
763 This is customizable so that alignment options can be specified.
764 Instead of strings, these can be Lisp forms that will be evaluated
765 for each row in order to construct the table row tags. During evaluation,
766 the variable `head' will be true when this is a header line, nil when this
767 is a body line. And the variable `nline' will contain the line number,
768 starting from 1 in the first header line. For example
770 (setq org-e-html-table-row-tags
773 (if (= (mod nline 2) 1)
774 \"<tr class=\\\"tr-odd\\\">\"
775 \"<tr class=\\\"tr-even\\\">\"))
778 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
779 :group
'org-export-tables
781 (choice :tag
"Opening tag"
782 (string :tag
"Specify")
784 (choice :tag
"Closing tag"
785 (string :tag
"Specify")
788 (defcustom org-e-html-table-align-individual-fields t
789 "Non-nil means attach style attributes for alignment to each table field.
790 When nil, alignment will only be specified in the column tags, but this
791 is ignored by some browsers (like Firefox, Safari). Opera does it right
793 :group
'org-export-tables
796 (defcustom org-e-html-table-use-header-tags-for-first-column nil
797 "Non-nil means format column one in tables with header tags.
798 When nil, also column one will use data tags."
799 :group
'org-export-tables
810 (defcustom org-e-html-toplevel-hlevel
2
811 "The <H> level for level 1 headings in HTML export.
812 This is also important for the classes that will be wrapped around headlines
813 and outline structure. If this variable is 1, the top-level headlines will
814 be <h1>, and the corresponding classes will be outline-1, section-number-1,
815 and outline-text-1. If this is 2, all of these will get a 2 instead.
816 The default for this variable is 2, because we use <h1> for formatting the
818 :group
'org-export-e-html
827 (defcustom org-e-html-link-org-files-as-html t
828 "Non-nil means make file links to `file.org' point to `file.html'.
829 When org-mode is exporting an org-mode file to HTML, links to
830 non-html files are directly put into a href tag in HTML.
831 However, links to other Org-mode files (recognized by the
832 extension `.org.) should become links to the corresponding html
833 file, assuming that the linked org-mode file will also be
835 When nil, the links still point to the plain `.org' file."
836 :group
'org-export-e-html
844 ;;; User Configurable Variables (MAYBE)
848 (defcustom org-e-html-date-format
850 "Format string for \\date{...}."
851 :group
'org-export-e-html
856 (defcustom org-e-html-format-headline-function nil
857 "Function to format headline text.
859 This function will be called with 5 arguments:
860 TODO the todo keyword \(string or nil\).
861 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
862 PRIORITY the priority of the headline \(integer or nil\)
863 TEXT the main headline text \(string\).
864 TAGS the tags string, separated with colons \(string or nil\).
866 The function result will be used in the section format string.
868 As an example, one could set the variable to the following, in
869 order to reproduce the default set-up:
871 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
872 \"Default format function for an headline.\"
874 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
876 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
878 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
879 :group
'org-export-e-html
885 (defcustom org-e-html-emphasis-alist
886 '(("*" .
"<b>%s</b>")
888 ("_" .
"<span style=\"text-decoration:underline;\">%s</span>")
889 ("+" .
"<del>%s</del>")
890 ("=" .
"<code>%s</code>")
891 ("~" .
"<code>%s</code>"))
892 "Alist of HTML expressions to convert emphasis fontifiers.
894 The key is the character used as a marker for fontification. The
895 value is a formatting string to wrap fontified text with.
897 Value can also be set to the following symbols: `verb' and
898 `protectedtexttt'. For the former, Org will use \"\\verb\" to
899 create a format string and select a delimiter character that
900 isn't in the string. For the latter, Org will use \"\\texttt\"
901 to typeset and try to protect special characters."
902 :group
'org-export-e-html
908 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
909 "Text used to separate footnotes."
910 :group
'org-export-e-html
916 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
917 "A printf format string to be applied to active time-stamps."
918 :group
'org-export-e-html
921 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
922 "A printf format string to be applied to inactive time-stamps."
923 :group
'org-export-e-html
926 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
927 "A printf format string to be applied to diary time-stamps."
928 :group
'org-export-e-html
934 (defcustom org-e-html-image-default-option
"width=.9\\linewidth"
935 "Default option for images."
936 :group
'org-export-e-html
939 (defcustom org-e-html-default-figure-position
"htb"
940 "Default position for latex figures."
941 :group
'org-export-e-html
944 (defcustom org-e-html-inline-image-rules
945 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
946 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
947 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
948 "Rules characterizing image files that can be inlined into HTML.
950 A rule consists in an association whose key is the type of link
951 to consider, and value is a regexp that will be matched against
954 Note that, by default, the image extension *actually* allowed
955 depend on the way the HTML file is processed. When used with
956 pdflatex, pdf, jpg and png images are OK. When processing
957 through dvi to Postscript, only ps and eps are allowed. The
958 default we use here encompasses both."
959 :group
'org-export-e-html
960 :type
'(alist :key-type
(string :tag
"Type")
961 :value-type
(regexp :tag
"Path")))
965 (defcustom org-e-html-table-caption-above t
966 "When non-nil, place caption string at the beginning of the table.
967 Otherwise, place it near the end."
968 :group
'org-export-e-html
973 (defcustom org-e-html-format-drawer-function nil
974 "Function called to format a drawer in HTML code.
976 The function must accept two parameters:
977 NAME the drawer name, like \"LOGBOOK\"
978 CONTENTS the contents of the drawer.
980 The function should return the string to be exported.
982 For example, the variable could be set to the following function
983 in order to mimic default behaviour:
985 \(defun org-e-html-format-drawer-default \(name contents\)
986 \"Format a drawer element for HTML export.\"
988 :group
'org-export-e-html
994 (defcustom org-e-html-format-inlinetask-function nil
995 "Function called to format an inlinetask in HTML code.
997 The function must accept six parameters:
998 TODO the todo keyword, as a string
999 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
1000 PRIORITY the inlinetask priority, as a string
1001 NAME the inlinetask name, as a string.
1002 TAGS the inlinetask tags, as a string.
1003 CONTENTS the contents of the inlinetask, as a string.
1005 The function should return the string to be exported.
1007 For example, the variable could be set to the following function
1008 in order to mimic default behaviour:
1010 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
1011 \"Format an inline task element for HTML export.\"
1012 \(let \(\(full-title
1015 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
1016 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1018 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1019 \(format \(concat \"\\\\begin{center}\\n\"
1021 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1023 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1025 \"\\\\end{minipage}}\"
1026 \"\\\\end{center}\"\)
1027 full-title contents\)\)"
1028 :group
'org-export-e-html
1036 (defcustom org-e-html-quotes
1038 ("\\(\\s-\\|[[(]\\)\"" .
"«~")
1039 ("\\(\\S-\\)\"" .
"~»")
1040 ("\\(\\s-\\|(\\)'" .
"'"))
1042 ("\\(\\s-\\|[[(]\\)\"" .
"``")
1043 ("\\(\\S-\\)\"" .
"''")
1044 ("\\(\\s-\\|(\\)'" .
"`")))
1045 "Alist for quotes to use when converting english double-quotes.
1047 The CAR of each item in this alist is the language code.
1048 The CDR of each item in this alist is a list of three CONS.
1049 - the first CONS defines the opening quote
1050 - the second CONS defines the closing quote
1051 - the last CONS defines single quotes
1053 For each item in a CONS, the first string is a regexp for allowed
1054 characters before/after the quote, the second string defines the
1055 replacement string for this quote."
1056 :group
'org-export-e-html
1058 (cons :tag
"Opening quote"
1059 (string :tag
"Regexp for char before")
1060 (string :tag
"Replacement quote "))
1061 (cons :tag
"Closing quote"
1062 (string :tag
"Regexp for char after ")
1063 (string :tag
"Replacement quote "))
1064 (cons :tag
"Single quote"
1065 (string :tag
"Regexp for char before")
1066 (string :tag
"Replacement quote "))))
1073 ;;; Internal Functions (HTML)
1075 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1076 "Convert an org filename to an equivalent html filename.
1077 If TYPE is not file, just return `nil'.
1078 See variable `org-e-html-link-org-files-as-html'."
1081 org-e-html-link-org-files-as-html
1082 (string= type
"file")
1083 (string-match "\\.org$" path
)
1088 (substring path
0 (match-beginning 0))
1089 "." (plist-get opt-plist
:html-extension
)))))))
1091 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1094 OPT-PLIST is an options list.
1095 TYPE is the device-type of the link (THIS://foo.html).
1096 PATH is the path of the link (http://THIS#location).
1097 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1098 DESC is the link description, if any.
1099 ATTR is a string of other attributes of the \"a\" element."
1100 (declare (special org-lparse-par-open
))
1102 (when (string= type-1
"coderef")
1103 (let ((ref fragment
))
1104 (setq desc
(format (org-export-get-coderef-format ref
(and descp desc
))
1105 (cdr (assoc ref org-export-code-refs
)))
1106 fragment
(concat "coderef-" ref
)
1107 attr
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1108 fragment fragment
))))
1109 (let* ((may-inline-p
1110 (and (member type-1
'("http" "https" "file"))
1111 (org-lparse-should-inline-p path descp
)
1113 (type (if (equal type-1
"id") "file" type-1
))
1115 ;;First pass. Just sanity stuff.
1118 ((string= type
"file")
1121 ;;Substitute just if original path was absolute.
1122 ;;(Otherwise path must remain relative)
1123 (if (file-name-absolute-p path
)
1124 (concat "file://" (expand-file-name path
))
1128 (t (list type path
))))
1130 ;;Second pass. Components converted so they can refer
1134 (and org-e-html-cvt-link-fn
1135 (apply org-e-html-cvt-link-fn
1136 opt-plist components-1
))
1137 (apply #'org-e-html-cvt-org-as-html
1138 opt-plist components-1
)
1140 (type (first components-2
))
1141 (thefile (second components-2
)))
1144 ;;Third pass. Build final link except for leading type
1149 (string= type
"http")
1150 (string= type
"https")
1151 (string= type
"file")
1152 (string= type
"coderef"))
1154 (setq thefile
(concat thefile
"#" fragment
))))
1158 ;;Final URL-build, for all types.
1161 ((str (org-xml-format-href thefile
)))
1162 (if (and type
(not (or (string= "file" type
)
1163 (string= "coderef" type
))))
1164 (concat type
":" str
)
1168 (ignore) ;; (org-e-html-format-image thefile)
1170 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1172 ;; (caption (and caption (org-xml-encode-org-text caption)))
1173 ;; alt = (file-name-nondirectory path)
1175 (defun org-e-html-format-inline-image (src &optional
1176 caption label attr standalone-p
)
1177 "Create image tag with source and attributes."
1178 (let* ((caption (or caption
(org-find-text-property-in-string
1180 (label (or label
(org-find-text-property-in-string
1182 (attr (or attr
(org-find-text-property-in-string
1183 'org-attributes src
)))
1184 (img-extras (if (string-match "^ltxpng/" src
)
1185 (format " alt=\"%s\""
1186 (org-find-text-property-in-string
1187 'org-latex-src src
))
1188 (if (string-match "\\<alt=" (or attr
""))
1190 (concat " " attr
" alt=\"" src
"\"")))))
1191 (let ((img (format "<img src=\"%s\"%s />" src img-extras
)))
1194 (format "\n<div%s class=\"figure\">%s\n</div>"
1196 (format " id=\"%s\"" (org-export-solidify-link-text label
)))
1197 (concat (format "\n<p>%s</p>" img
)
1198 (when caption
(format "\n<p>%s</p>" caption
)))))
1203 (defun org-e-html-bibliography ()
1204 "Find bibliography, cut it out and return it."
1206 (let (beg end
(cnt 1) bib
)
1208 (goto-char (point-min))
1209 (when (re-search-forward
1210 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1211 (setq beg
(match-beginning 0))
1212 (while (re-search-forward "</?div\\>" nil t
)
1213 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1215 (and (looking-at ">") (forward-char 1))
1216 (setq bib
(buffer-substring beg
(point)))
1217 (delete-region beg
(point))
1218 (throw 'exit bib
))))
1223 (defun org-e-html-format-table (lines olines
)
1224 (let ((org-e-html-format-table-no-css nil
))
1225 (org-lparse-format-table lines olines
)))
1227 (defun org-e-html-splice-attributes (tag attributes
)
1228 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1229 (if (not attributes
)
1231 (let (oldatt newatt
)
1232 (setq oldatt
(org-extract-attributes-from-string tag
)
1234 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1236 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1237 (if (string-match ">" tag
)
1239 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1243 (defun org-export-splice-style (style extra
)
1244 "Splice EXTRA into STYLE, just before \"</style>\"."
1245 (if (and (stringp extra
)
1246 (string-match "\\S-" extra
)
1247 (string-match "</style>" style
))
1248 (concat (substring style
0 (match-beginning 0))
1250 (substring style
(match-beginning 0)))
1253 (defun org-export-e-htmlize-region-for-paste (beg end
)
1254 "Convert the region to HTML, using htmlize.el.
1255 This is much like `htmlize-region-for-paste', only that it uses
1256 the settings define in the org-... variables."
1257 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1258 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1259 (htmlbuf (htmlize-region beg end
)))
1261 (with-current-buffer htmlbuf
1262 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1263 (plist-get htmlize-buffer-places
'content-end
)))
1264 (kill-buffer htmlbuf
))))
1267 (defun org-export-e-htmlize-generate-css ()
1268 "Create the CSS for all font definitions in the current Emacs session.
1269 Use this to create face definitions in your CSS style file that can then
1270 be used by code snippets transformed by htmlize.
1271 This command just produces a buffer that contains class definitions for all
1272 faces used in the current Emacs session. You can copy and paste the ones you
1273 need into your CSS file.
1275 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1276 the function `org-export-e-htmlize-region-for-paste' will produce code
1277 that uses these same face definitions."
1280 (and (get-buffer "*html*") (kill-buffer "*html*"))
1282 (let ((fl (face-list))
1283 (htmlize-css-name-prefix "org-")
1284 (htmlize-output-type 'css
)
1286 (while (setq f
(pop fl
)
1287 i
(and f
(face-attribute f
:inherit
)))
1288 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1289 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1290 (htmlize-region (point-min) (point-max))))
1291 (org-pop-to-buffer-same-window "*html*")
1292 (goto-char (point-min))
1293 (if (re-search-forward "<style" nil t
)
1294 (delete-region (point-min) (match-beginning 0)))
1295 (if (re-search-forward "</style>" nil t
)
1296 (delete-region (1+ (match-end 0)) (point-max)))
1297 (beginning-of-line 1)
1298 (if (looking-at " +") (replace-match ""))
1299 (goto-char (point-min)))
1301 (defun org-e-html-format-toc-entry (snumber todo headline tags href
)
1302 (setq headline
(concat
1304 (and org-export-with-section-numbers
(concat snumber
" "))
1309 " "
1310 (format "<span class=\"tag\">%s</span>" tags
)))))
1311 ;; fontify headline based on TODO keyword
1313 (setq headline
(format "<span class=\"todo\">%s</span>" headline
)))
1314 (format "<a href=\"#%s\">%s</a>" href headline
))
1316 (defun org-e-html-toc-entry-formatter
1317 (level snumber todo todo-type priority
1318 headline tags target extra-targets extra-class
)
1319 (org-e-html-format-toc-entry snumber todo headline tags target
))
1321 (defun org-e-html-make-string (n string
)
1322 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1324 (defun org-e-html-toc-text (toc-entries)
1325 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1326 (start-level prev-level
))
1330 (let ((headline (nth 0 entry
))
1331 (level (nth 1 entry
)))
1333 (let* ((cnt (- level prev-level
))
1334 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1336 (setq prev-level level
)
1338 (org-e-html-make-string
1339 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1340 ((< cnt
0) "</li>\n</ul>\n")))
1341 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1344 (org-e-html-make-string
1345 (- prev-level start-level
) "</li>\n</ul>\n"))))
1347 (defun org-e-html-toc (depth info
)
1348 (assert (wholenump depth
))
1349 (let* ((headlines (org-export-collect-headlines info depth
))
1351 (loop for headline in headlines collect
1352 (list (org-e-html-headline-text
1353 headline info
'org-e-html-toc-entry-formatter
)
1354 (org-export-get-relative-level headline info
)))))
1356 (let* ((lang-specific-heading
1357 (nth 3 (or (assoc (plist-get info
:language
)
1358 org-export-language-setup
)
1359 (assoc "en" org-export-language-setup
)))))
1361 "<div id=\"table-of-contents\">\n"
1362 (format "<h%d>%s</h%d>\n"
1363 org-e-html-toplevel-hlevel
1364 lang-specific-heading
1365 org-e-html-toplevel-hlevel
)
1366 "<div id=\"text-table-of-contents\">"
1367 (org-e-html-toc-text toc-entries
)
1371 ;; (defun org-e-html-format-line (line)
1372 ;; (case org-lparse-dyn-current-environment
1373 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1374 ;; (t (concat line "\n"))))
1376 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1377 "Turn todo keyword into a valid class name.
1378 Replaces invalid characters with \"_\"."
1380 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1381 (setq kwd
(replace-match "_" t t kwd
))))
1384 (defun org-e-html-format-footnote-reference (n def refcnt
)
1385 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1386 (format org-e-html-footnote-format
1388 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1391 (defun org-e-html-format-footnotes-section (section-name definitions
)
1392 (if (not definitions
) ""
1393 (format org-e-html-footnotes-section section-name definitions
)))
1395 (defun org-e-html-format-footnote-definition (fn)
1396 (let ((n (car fn
)) (def (cdr fn
)))
1398 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1400 (format org-e-html-footnote-format
1401 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1404 (defun org-e-html-footnote-section (info)
1405 (let* ((fn-alist (org-export-collect-footnote-definitions
1406 (plist-get info
:parse-tree
) info
))
1409 (loop for
(n type raw
) in fn-alist collect
1410 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1411 (org-trim (org-export-data raw
'e-html info
))
1413 (org-trim (org-export-secondary-string
1414 raw
'e-html info
))))))))
1416 (org-e-html-format-footnotes-section
1417 (nth 4 (or (assoc (plist-get info
:language
)
1418 org-export-language-setup
)
1419 (assoc "en" org-export-language-setup
)))
1421 "<table>\n%s\n</table>\n"
1422 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1424 (defun org-e-html-get-coding-system-for-write ()
1425 (or org-e-html-coding-system
1426 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1428 (defun org-e-html-get-coding-system-for-save ()
1429 (or org-e-html-coding-system
1430 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1432 (defun org-e-html-format-date (info)
1433 (let ((date (plist-get info
:date
)))
1435 ((and date
(string-match "%" date
))
1436 (format-time-string date
))
1438 (t (format-time-string "%Y-%m-%d %T %Z")))))
1442 ;;; Internal Functions (Ngz)
1444 (defun org-e-html--caption/label-string
(caption label info
)
1445 "Return caption and label HTML string for floats.
1447 CAPTION is a cons cell of secondary strings, the car being the
1448 standard caption and the cdr its short form. LABEL is a string
1449 representing the label. INFO is a plist holding contextual
1452 If there's no caption nor label, return the empty string.
1454 For non-floats, see `org-e-html--wrap-label'."
1455 (setq label nil
) ;; FIXME
1457 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1459 ((and (not caption
) (not label
)) "")
1460 ((not caption
) (format "\\label{%s}\n" label
))
1461 ;; Option caption format with short name.
1463 (format "\\caption[%s]{%s%s}\n"
1464 (org-export-secondary-string (cdr caption
) 'e-html info
)
1466 (org-export-secondary-string (car caption
) 'e-html info
)))
1467 ;; Standard caption format.
1468 ;; (t (format "\\caption{%s%s}\n"
1470 ;; (org-export-secondary-string (car caption) 'e-html info)))
1472 (t (org-export-secondary-string (car caption
) 'e-html info
)))))
1474 (defun org-e-html--find-verb-separator (s)
1475 "Return a character not used in string S.
1476 This is used to choose a separator for constructs like \\verb."
1477 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1478 (loop for c across ll
1479 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1480 return
(char-to-string c
))))
1482 (defun org-e-html--make-option-string (options)
1483 "Return a comma separated string of keywords and values.
1484 OPTIONS is an alist where the key is the options keyword as
1485 a string, and the value a list containing the keyword value, or
1487 (mapconcat (lambda (pair)
1488 (concat (first pair
)
1489 (when (> (length (second pair
)) 0)
1490 (concat "=" (second pair
)))))
1494 (defun org-e-html--quotation-marks (text info
)
1495 "Export quotation marks depending on language conventions.
1496 TEXT is a string containing quotation marks to be replaced. INFO
1497 is a plist used as a communication channel."
1500 (while (setq start
(string-match (car l
) text start
))
1501 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1502 (setq text
(replace-match new-quote t t text
))))))
1503 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1504 ;; Falls back on English.
1505 (assoc "en" org-e-html-quotes
))))
1508 (defun org-e-html--wrap-label (element output
)
1509 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1510 This function shouldn't be used for floats. See
1511 `org-e-html--caption/label-string'."
1512 ;; (let ((label (org-element-property :name element)))
1513 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1515 ;; (concat (format "\\label{%s}\n" label) output)))
1522 (defun org-e-html-meta-info (info)
1523 (let* ((title (org-export-secondary-string
1524 (plist-get info
:title
) 'e-html info
))
1525 (author (and (plist-get info
:with-author
)
1526 (let ((auth (plist-get info
:author
)))
1527 (and auth
(org-export-secondary-string
1528 auth
'e-html info
)))))
1529 (description (plist-get info
:description
))
1530 (keywords (plist-get info
:keywords
)))
1532 (format "\n<title>%s</title>\n" title
)
1534 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1535 (and coding-system-for-write
1536 (fboundp 'coding-system-get
)
1537 (coding-system-get coding-system-for-write
1539 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1540 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1541 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1542 (org-e-html-format-date info
))
1543 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1544 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1545 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1547 (defun org-e-html-style (info)
1549 (when (plist-get info
:style-include-default
)
1550 org-e-html-style-default
)
1551 (plist-get info
:style
)
1552 (plist-get info
:style-extra
)
1554 (when (plist-get info
:style-include-scripts
)
1555 org-e-html-scripts
)))
1557 (defun org-e-html-mathjax-config (info)
1558 "Insert the user setup into the matchjax template."
1559 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1560 (let ((template org-e-html-mathjax-template
)
1561 (options org-e-html-mathjax-options
)
1562 (in-buffer (or (plist-get info
:mathjax
) ""))
1563 name val
(yes " ") (no "// ") x
)
1566 (setq name
(car e
) val
(nth 1 e
))
1567 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1568 (setq val
(car (read-from-string
1569 (substring in-buffer
(match-end 0))))))
1570 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1571 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1572 (setq template
(replace-match val t t template
))))
1574 (setq val
(nth 1 (assq 'mathml options
)))
1575 (if (string-match (concat "\\<mathml:") in-buffer
)
1576 (setq val
(car (read-from-string
1577 (substring in-buffer
(match-end 0))))))
1578 ;; Exchange prefixes depending on mathml setting
1579 (if (not val
) (setq x yes yes no no x
))
1580 ;; Replace cookies to turn on or off the config/jax lines
1581 (if (string-match ":MMLYES:" template
)
1582 (setq template
(replace-match yes t t template
)))
1583 (if (string-match ":MMLNO:" template
)
1584 (setq template
(replace-match no t t template
)))
1585 ;; Return the modified template
1588 (defun org-e-html-preamble (info)
1589 (when (plist-get info
:html-preamble
)
1590 (let* ((title (plist-get info
:title
))
1591 (date (org-e-html-format-date info
))
1592 (author (plist-get info
:author
))
1593 (lang-words (or (assoc (plist-get info
:language
)
1594 org-export-language-setup
)
1595 (assoc "en" org-export-language-setup
)))
1596 (email (plist-get info
:email
))
1597 (html-pre-real-contents
1599 ((functionp (plist-get info
:html-preamble
))
1601 (funcall (plist-get info
:html-preamble
))
1603 ((stringp (plist-get info
:html-preamble
))
1604 (format-spec (plist-get info
:html-preamble
)
1605 `((?t .
,title
) (?a .
,author
)
1606 (?d .
,date
) (?e .
,email
))))
1609 (or (cadr (assoc (nth 0 lang-words
)
1610 org-e-html-preamble-format
))
1611 (cadr (assoc "en" org-e-html-preamble-format
)))
1612 `((?t .
,title
) (?a .
,author
)
1613 (?d .
,date
) (?e .
,email
)))))))
1614 (when (not (equal html-pre-real-contents
""))
1617 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1620 html-pre-real-contents
1624 (defun org-e-html-postamble (info)
1626 (when (and (not body-only
)
1627 (plist-get info
:html-postamble
))
1628 (let* ((html-post (plist-get info
:html-postamble
))
1629 (date (org-e-html-format-date info
))
1630 (author (plist-get info
:author
))
1631 (email (plist-get info
:email
))
1632 (lang-words (or (assoc (plist-get info
:language
)
1633 org-export-language-setup
)
1634 (assoc "en" org-export-language-setup
)))
1636 (mapconcat (lambda(e)
1637 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1638 (split-string email
",+ *")
1640 (html-validation-link (or org-e-html-validation-link
""))
1642 (concat "Org version " org-version
" with Emacs version "
1643 (number-to-string emacs-major-version
))))
1647 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1650 ((eq (plist-get info
:html-postamble
) 'auto
)
1652 (when (plist-get info
:time-stamp-file
)
1654 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1655 (when (and (plist-get info
:with-author
) author
)
1657 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1658 (when (and (plist-get info
:with-email
) email
)
1660 <p class=\"email\"> %s </p>" email
))
1661 (when (plist-get info
:with-creator
)
1663 <p class=\"creator\"> %s </p>" creator-info
))
1664 html-validation-link
"\n"))
1665 ;; postamble from a string
1666 ((stringp (plist-get info
:html-postamble
))
1667 (format-spec (plist-get info
:html-postamble
)
1668 `((?a .
,author
) (?e .
,email
)
1669 (?d .
,date
) (?c .
,creator-info
)
1670 (?v .
,html-validation-link
))))
1672 ;; postamble from a function
1673 ((functionp (plist-get info
:html-postamble
))
1675 (funcall (plist-get info
:html-postamble
))
1677 ;; default postamble
1680 (or (cadr (assoc (nth 0 lang-words
)
1681 org-e-html-postamble-format
))
1682 (cadr (assoc "en" org-e-html-postamble-format
)))
1683 `((?a .
,author
) (?e .
,email
)
1684 (?d .
,date
) (?c .
,creator-info
)
1685 (?v .
,html-validation-link
)))))
1688 ;; org-e-html-html-helper-timestamp
1691 (defun org-e-html-template (contents info
)
1692 "Return complete document string after HTML conversion.
1693 CONTENTS is the transcoded contents string. RAW-DATA is the
1694 original parsed data. INFO is a plist holding export options."
1697 (or (and (stringp org-e-html-xml-declaration
)
1698 org-e-html-xml-declaration
)
1699 (cdr (assoc (plist-get info
:html-extension
)
1700 org-e-html-xml-declaration
))
1701 (cdr (assoc "html" org-e-html-xml-declaration
))
1704 (or (and coding-system-for-write
1705 (fboundp 'coding-system-get
)
1706 (coding-system-get coding-system-for-write
1710 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1711 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1713 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1714 (plist-get info
:language
) (plist-get info
:language
))
1717 (org-e-html-meta-info info
) ; meta
1718 (org-e-html-style info
) ; style
1719 (org-e-html-mathjax-config info
) ; mathjax
1725 (let ((link-up (and (plist-get info
:link-up
)
1726 (string-match "\\S-" (plist-get info
:link-up
))
1727 (plist-get info
:link-up
)))
1728 (link-home (and (plist-get info
:link-home
)
1729 (string-match "\\S-" (plist-get info
:link-home
))
1730 (plist-get info
:link-home
))))
1731 (when (or link-up link-home
)
1732 (format org-e-html-home
/up-format
1733 (or link-up link-home
)
1734 (or link-home link-up
))))
1736 (org-e-html-preamble info
)
1739 <div id=\"%s\">" (or org-e-html-content-div
1740 (nth 1 org-e-html-divs
)))
1743 <h1 class=\"title\"> %s </h1>\n" (plist-get info
:title
))
1744 ;; table of contents
1745 (let ((depth (plist-get info
:with-toc
)))
1746 (when (wholenump depth
) (org-e-html-toc depth info
)))
1747 ;; document contents
1749 ;; footnotes section
1750 (org-e-html-footnote-section info
)
1752 (org-e-html-bibliography)
1759 (org-e-html-postamble info
)
1769 ;;; Transcode Functions
1773 (defun org-e-html-center-block (center-block contents info
)
1774 "Transcode a CENTER-BLOCK element from Org to HTML.
1775 CONTENTS holds the contents of the block. INFO is a plist
1776 holding contextual information."
1777 (org-e-html--wrap-label
1779 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1784 ;; Comments are ignored.
1789 ;; Comment Blocks are ignored.
1794 (defun org-e-html-drawer (drawer contents info
)
1795 "Transcode a DRAWER element from Org to HTML.
1796 CONTENTS holds the contents of the block. INFO is a plist
1797 holding contextual information."
1798 (let* ((name (org-element-property :drawer-name drawer
))
1799 (output (if (functionp org-e-html-format-drawer-function
)
1800 (funcall org-e-html-format-drawer-function
1802 ;; If there's no user defined function: simply
1803 ;; display contents of the drawer.
1805 (org-e-html--wrap-label drawer output
)))
1810 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1811 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1812 CONTENTS holds the contents of the block. INFO is a plist
1813 holding contextual information. See
1815 (org-e-html--wrap-label dynamic-block contents
))
1820 (defun org-e-html-emphasis (emphasis contents info
)
1821 "Transcode EMPHASIS from Org to HTML.
1822 CONTENTS is the contents of the emphasized text. INFO is a plist
1823 holding contextual information.."
1824 (let* ((marker (org-element-property :marker emphasis
)))
1825 (format (cdr (assoc marker org-e-html-emphasis-alist
)) contents
)))
1830 (defun org-e-html-entity (entity contents info
)
1831 "Transcode an ENTITY object from Org to HTML.
1832 CONTENTS are the definition itself. INFO is a plist holding
1833 contextual information."
1834 ;; (let ((ent (org-element-property :latex entity)))
1835 ;; (if (org-element-property :latex-math-p entity)
1836 ;; (format "$%s$" ent)
1838 (org-element-property :html entity
))
1843 (defun org-e-html-format-source-line-with-line-number-and-label (line)
1844 (let ((ref (org-find-text-property-in-string 'org-coderef line
))
1845 (num (org-find-text-property-in-string 'org-loc line
)))
1847 (setq line
(format "<span class=\"linenr\">%d: </span>%s (%s)"
1852 "<span id=\"coderef-%s\" class=\"coderef-off\">%s (%s)</span>"
1856 (defun org-e-html-format-source-code-or-example-plain
1857 (lines lang caption textareap cols rows num cont rpllbl fmt
)
1859 "\n<pre class=\"example\">\n%s\n</pre>"
1862 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">%s\n</textarea>\n</p>\n"
1866 (org-e-html-format-source-line-with-line-number-and-label
1867 (org-e-html-encode-plain-text line
)))
1868 (org-split-string lines
"\n")
1871 (defun org-e-html-format-source-code-or-example-colored
1872 (lines lang caption textareap cols rows num cont rpllbl fmt
)
1873 (let* ((lang-m (when lang
1874 (or (cdr (assoc lang org-src-lang-modes
))
1876 (mode (and lang-m
(intern
1878 (if (symbolp lang-m
)
1879 (symbol-name lang-m
)
1882 (org-inhibit-startup t
)
1883 (org-startup-folded nil
))
1887 (if (functionp mode
)
1890 (font-lock-fontify-buffer)
1891 ;; markup each line separately
1892 (org-remove-formatting-on-newlines-in-region
1893 (point-min) (point-max))
1895 (set-buffer-modified-p nil
)
1896 (org-export-e-htmlize-region-for-paste
1897 (point-min) (point-max))))
1899 (when (string-match "<pre\\([^>]*\\)>\n*" lines
)
1900 (setq lines
(replace-match
1901 (format "<pre class=\"src src-%s\">\n" lang
) t t lines
)))
1906 "<div class=\"org-src-container\">"
1907 (format "<label class=\"org-src-name\">%s</label>" caption
)
1914 (org-e-html-format-source-line-with-line-number-and-label line
))
1915 (org-split-string lines
"\n") "\n")))
1917 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
1918 ;; (setq lines (replace-match "\\1" t nil lines)))
1921 (defun org-e-html-format-source-code-or-example
1922 (lang code
&optional opts indent caption
)
1923 "Format CODE from language LANG and return it formatted for export.
1924 The CODE is marked up in `org-export-current-backend' format.
1926 Check if a function by name
1927 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
1928 use it as the custom formatter. Otherwise, use the default
1929 formatter. Default formatters are provided for docbook, html,
1930 latex and ascii backends. For example, use
1931 `org-e-html-format-source-code-or-example' to provide a custom
1932 formatter for export to \"html\".
1934 If LANG is nil, do not add any fontification.
1935 OPTS contains formatting options, like `-n' for triggering numbering lines,
1936 and `+n' for continuing previous numbering.
1937 Code formatting according to language currently only works for HTML.
1938 Numbering lines works for all three major backends (html, latex, and ascii).
1939 INDENT was the original indentation of the block."
1941 (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain
)
1942 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
1943 (setq opts
(or opts
"")
1944 num
(string-match "[-+]n\\>" opts
)
1945 cont
(string-match "\\+n\\>" opts
)
1946 rpllbl
(string-match "-r\\>" opts
)
1947 keepp
(string-match "-k\\>" opts
)
1948 textareap
(string-match "-t\\>" opts
)
1949 preserve-indentp
(or org-src-preserve-indentation
1950 (string-match "-i\\>" opts
))
1951 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
1952 (string-to-number (match-string 1 opts
))
1954 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
1955 (string-to-number (match-string 1 opts
))
1956 (org-count-lines code
))
1957 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
1958 (match-string 1 opts
)))
1959 (when (and textareap
1960 ;; (eq org-export-current-backend 'html)
1962 ;; we cannot use numbering or highlighting.
1963 (setq num nil cont nil lang nil
))
1964 (if keepp
(setq rpllbl
'keep
))
1965 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
1966 (when (string-match "^," rtn
)
1967 (setq rtn
(with-temp-buffer
1969 ;; Free up the protected lines
1970 (goto-char (point-min))
1971 (while (re-search-forward "^," nil t
)
1972 (if (or (equal lang
"org")
1974 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
1979 (if (featurep 'xemacs
)
1981 (require 'htmlize nil t
)))
1983 (setq backend-formatter
1985 ((fboundp 'htmlize-region-for-paste
)
1986 'org-e-html-format-source-code-or-example-colored
)
1989 "htmlize.el 1.34 or later is needed for source code formatting")
1990 'org-e-html-format-source-code-or-example-plain
)))
1991 (funcall backend-formatter rtn lang caption textareap cols rows
1992 num cont rpllbl fmt
))))
1994 (defun org-e-html-example-block (example-block contents info
)
1995 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1996 CONTENTS is nil. INFO is a plist holding contextual information."
1997 (let* ((options (or (org-element-property :options example-block
) ""))
1998 (value (org-export-handle-code example-block info nil nil t
)))
1999 ;; (org-e-html--wrap-label
2000 ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
2001 (org-e-html--wrap-label
2002 example-block
(org-e-html-format-source-code-or-example nil value
))))
2007 (defun org-e-html-export-snippet (export-snippet contents info
)
2008 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2009 CONTENTS is nil. INFO is a plist holding contextual information."
2010 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
2011 (org-element-property :value export-snippet
)))
2016 (defun org-e-html-export-block (export-block contents info
)
2017 "Transcode a EXPORT-BLOCK element from Org to HTML.
2018 CONTENTS is nil. INFO is a plist holding contextual information."
2019 (when (string= (org-element-property :type export-block
) "latex")
2020 (org-remove-indentation (org-element-property :value export-block
))))
2025 (defun org-e-html-fixed-width (fixed-width contents info
)
2026 "Transcode a FIXED-WIDTH element from Org to HTML.
2027 CONTENTS is nil. INFO is a plist holding contextual information."
2028 (let* ((value (org-element-normalize-string
2029 (replace-regexp-in-string
2031 (org-element-property :value fixed-width
)))))
2032 (org-e-html--wrap-label
2033 fixed-width
(org-e-html-format-source-code-or-example nil value
))))
2036 ;;;; Footnote Definition
2038 ;; Footnote Definitions are ignored.
2041 ;;;; Footnote Reference
2043 (defun org-e-html-footnote-reference (footnote-reference contents info
)
2044 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2045 CONTENTS is nil. INFO is a plist holding contextual information."
2047 ;; Insert separator between two footnotes in a row.
2048 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2049 (when (eq (org-element-type prev
) 'footnote-reference
)
2050 org-e-html-footnote-separator
))
2052 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2053 (org-e-html-format-footnote-reference
2054 (org-export-get-footnote-number footnote-reference info
)
2056 ;; Inline definitions are secondary strings.
2057 ((eq (org-element-property :type footnote-reference
) 'inline
)
2058 (org-e-html-format-footnote-reference
2059 (org-export-get-footnote-number footnote-reference info
)
2061 ;; Non-inline footnotes definitions are full Org data.
2062 (t (org-e-html-format-footnote-reference
2063 (org-export-get-footnote-number footnote-reference info
)
2069 (defun org-e-html-todo (todo)
2071 (format "<span class=\"%s %s%s\">%s</span>"
2072 (if (member todo org-done-keywords
) "done" "todo")
2073 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
2076 (defun org-e-html-headline-text (headline info
&optional formatter
)
2077 "Transcode an HEADLINE element from Org to HTML.
2078 CONTENTS holds the contents of the headline. INFO is a plist
2079 holding contextual information."
2080 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2081 (level (org-export-get-relative-level headline info
))
2082 (todo (and (plist-get info
:with-todo-keywords
)
2083 (let ((todo (org-element-property
2084 :todo-keyword headline
)))
2086 (org-export-secondary-string todo
'e-html info
)))))
2087 (todo-type (and todo
(org-element-property :todo-type headline
)))
2088 (priority (and (plist-get info
:with-priority
)
2089 (org-element-property :priority headline
)))
2090 (text (org-export-secondary-string
2091 (org-element-property :title headline
) 'e-html info
))
2092 (tags (and (plist-get info
:with-tags
)
2093 (org-element-property :tags headline
)))
2095 (headline-no (org-export-get-headline-number headline info
))
2097 (format "sec-%s" (mapconcat 'number-to-string headline-no
"-")))
2098 (headline-labels (list headline-label
))
2099 (headline-no (org-export-get-headline-number headline info
))
2100 (section-no (mapconcat 'number-to-string headline-no
"."))
2101 (primary-target (car (last headline-labels
)))
2102 (secondary-targets (butlast headline-labels
))
2104 (formatter (or (and (functionp formatter
) formatter
)
2105 org-e-html-headline-formatter
)))
2106 (funcall formatter level section-no todo todo-type priority
2107 text tags primary-target secondary-targets extra-class
)))
2109 (defun org-e-html-headline (headline contents info
)
2110 "Transcode an HEADLINE element from Org to HTML.
2111 CONTENTS holds the contents of the headline. INFO is a plist
2112 holding contextual information."
2113 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2114 (level (org-export-get-relative-level headline info
))
2115 (text (org-export-secondary-string
2116 (org-element-property :title headline
) 'e-html info
))
2117 (todo (and (plist-get info
:with-todo-keywords
)
2118 (let ((todo (org-element-property
2119 :todo-keyword headline
)))
2121 (org-export-secondary-string todo
'e-html info
)))))
2122 (todo-type (and todo
(org-element-property :todo-type headline
)))
2123 (tags (and (plist-get info
:with-tags
)
2124 (org-element-property :tags headline
)))
2125 (priority (and (plist-get info
:with-priority
)
2126 (org-element-property :priority headline
)))
2127 ;; Create the headline text.
2128 (full-text (if (functionp org-e-html-format-headline-function
)
2129 ;; User-defined formatting function.
2130 (funcall org-e-html-format-headline-function
2131 todo todo-type priority text tags
)
2132 ;; Default formatting.
2135 ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2136 (org-e-html-todo todo
) " "
2137 (when priority
(format "\\framebox{\\#%c} " priority
))
2139 ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
2142 ;; Case 1: This is a footnote section: ignore it.
2143 ((org-element-property :footnote-section-p headline
) nil
)
2144 ;; Case 2. This is a deep sub-tree: export it as a list item.
2145 ;; Also export as items headlines for which no section
2146 ;; format has been found.
2147 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2148 ;; Build the real contents of the sub-tree.
2149 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2150 (itemized-body (org-e-html-format-list-item
2151 contents type nil nil full-text
)))
2153 (and (org-export-first-sibling-p headline info
)
2154 (org-e-html-begin-plain-list type
))
2156 (and (org-export-last-sibling-p headline info
)
2157 (org-e-html-end-plain-list type
)))))
2158 ;; Case 3. Standard headline. Export it as a section.
2160 (let* ((extra-class (org-element-property :html-container-class headline
))
2161 (extra-ids (list (org-element-property :custom-id headline
)
2162 (org-element-property :id headline
)))
2163 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2170 (let ((id (org-solidify-link-text
2171 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2172 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2175 (and (org-export-numbered-headline-p headline info
)
2176 (format "<span class=\"section-number-%d\">%s</span> "
2180 (org-export-get-headline-number headline info
) ".")))
2184 (and (plist-get info
:with-tags
) tags
2186 " "
2187 (format "<span class=\"tag\">%s</span>"
2190 (format "<span class=\"%s\">%s</span>"
2191 (concat org-e-html-tag-class-prefix
2192 (org-e-html-fix-class-name tag
))
2194 (org-split-string tags
":") " "))))))
2195 (id (mapconcat 'number-to-string
2196 (org-export-get-headline-number headline info
) "-")))
2197 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2198 (format "outline-container-%s" id
)
2199 (concat (format "outline-%d" level1
) (and extra-class
" ")
2201 (format "\n<h%d id=\"sec-%s\">%s</h%d>\n" level1 id title level1
)
2205 ;;;; Horizontal Rule
2207 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2208 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2209 CONTENTS is nil. INFO is a plist holding contextual information."
2210 (let ((attr (mapconcat #'identity
2211 (org-element-property :attr_html horizontal-rule
)
2213 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2216 ;;;; Inline Babel Call
2218 ;; Inline Babel Calls are ignored.
2221 ;;;; Inline Src Block
2223 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2224 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2225 CONTENTS holds the contents of the item. INFO is a plist holding
2226 contextual information."
2227 (let* ((org-lang (org-element-property :language inline-src-block
))
2228 (code (org-element-property :value inline-src-block
))
2229 (separator (org-e-html--find-verb-separator code
)))
2235 (defun org-e-html-format-section (text class
&optional id
)
2236 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2237 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2239 (defun org-e-html-inlinetask (inlinetask contents info
)
2240 "Transcode an INLINETASK element from Org to HTML.
2241 CONTENTS holds the contents of the block. INFO is a plist
2242 holding contextual information."
2243 (let ((title (org-export-secondary-string
2244 (org-element-property :title inlinetask
) 'e-html info
))
2245 (todo (and (plist-get info
:with-todo-keywords
)
2246 (let ((todo (org-element-property
2247 :todo-keyword inlinetask
)))
2249 (org-export-secondary-string todo
'e-html info
)))))
2250 (todo-type (org-element-property :todo-type inlinetask
))
2251 (tags (and (plist-get info
:with-tags
)
2252 (org-element-property :tags inlinetask
)))
2253 (priority (and (plist-get info
:with-priority
)
2254 (org-element-property :priority inlinetask
))))
2255 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2256 ;; with appropriate arguments.
2257 (if (functionp org-e-html-format-inlinetask-function
)
2258 (funcall org-e-html-format-inlinetask-function
2259 todo todo-type priority title tags contents
)
2260 ;; Otherwise, use a default template.
2261 (org-e-html--wrap-label
2265 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
2266 (when priority
(format "\\framebox{\\#%c} " priority
))
2268 (when tags
(format "\\hfill{}\\textsc{%s}" tags
)))))
2269 (format (concat "\\begin{center}\n"
2271 "\\begin{minipage}[c]{.6\\textwidth}\n"
2273 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
2278 full-title contents
))))))
2283 (defun org-e-html-checkbox (checkbox)
2284 (case checkbox
(on "<code>[X]</code>")
2285 (off "<code>[ ]</code>")
2286 (trans "<code>[-]</code>")
2289 (defun org-e-html-format-list-item (contents type checkbox
2290 &optional term-counter-id
2295 (let* ((counter term-counter-id
)
2296 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2297 (format "<li%s>" extra
)))
2299 (let* ((id term-counter-id
)
2300 (extra (if id
(format " id=\"%s\"" id
) "")))
2302 (format "<li%s>" extra
)
2303 (when headline
(concat headline
"<br/>")))))
2305 (let* ((term term-counter-id
))
2306 (setq term
(or term
"(no term)"))
2307 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2308 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2313 (descriptive "</dd>"))))
2315 (defun org-e-html-item (item contents info
)
2316 "Transcode an ITEM element from Org to HTML.
2317 CONTENTS holds the contents of the item. INFO is a plist holding
2318 contextual information."
2319 ;; Grab `:level' from plain-list properties, which is always the
2320 ;; first element above current item.
2321 (let* ((plain-list (org-export-get-parent item info
))
2322 (type (org-element-property :type plain-list
))
2323 (level (org-element-property :level plain-list
))
2324 (counter (org-element-property :counter item
))
2325 (checkbox (org-element-property :checkbox item
))
2326 (tag (let ((tag (org-element-property :tag item
)))
2327 (and tag
(org-export-secondary-string tag
'e-html info
)))))
2328 (org-e-html-format-list-item
2329 contents type checkbox
(or tag counter
))))
2334 (defun org-e-html-keyword (keyword contents info
)
2335 "Transcode a KEYWORD element from Org to HTML.
2336 CONTENTS is nil. INFO is a plist holding contextual information."
2337 (let ((key (downcase (org-element-property :key keyword
)))
2338 (value (org-element-property :value keyword
)))
2340 ((string= key
"latex") value
)
2341 ((string= key
"index") (format "\\index{%s}" value
))
2342 ;; Invisible targets.
2343 ((string= key
"target") nil
) ; FIXME
2344 ((string= key
"toc")
2345 (let ((value (downcase value
)))
2347 ((string-match "\\<headlines\\>" value
)
2348 (let ((depth (or (and (string-match "[0-9]+" value
)
2349 (string-to-number (match-string 0 value
)))
2350 (plist-get info
:with-toc
))))
2351 (when (wholenump depth
) (org-e-html-toc depth info
))))
2352 ((string= "tables" value
) "\\listoftables")
2353 ((string= "figures" value
) "\\listoffigures")
2354 ((string= "listings" value
)
2356 ;; At the moment, src blocks with a caption are wrapped
2357 ;; into a figure environment.
2358 (t "\\listoffigures")))))))))
2361 ;;;; Latex Environment
2363 (defun org-e-html-format-latex (latex-frag processing-type
)
2364 (let* ((cache-relpath
2365 (concat "ltxpng/" (file-name-sans-extension
2366 (file-name-nondirectory (buffer-file-name)))))
2367 (cache-dir (file-name-directory (buffer-file-name )))
2368 (display-msg "Creating LaTeX Image..."))
2372 (org-format-latex cache-relpath cache-dir nil display-msg
2373 nil nil processing-type
)
2376 (defun org-e-html-latex-environment (latex-environment contents info
)
2377 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2378 CONTENTS is nil. INFO is a plist holding contextual information."
2379 (org-e-html--wrap-label
2381 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2382 (latex-frag (org-remove-indentation
2383 (org-element-property :value latex-environment
)))
2384 (caption (org-e-html--caption/label-string
2385 (org-element-property :caption latex-environment
)
2386 (org-element-property :name latex-environment
)
2388 (label (org-element-property :name latex-environment
))
2391 ((member processing-type
'(t mathjax
))
2392 (org-e-html-format-latex latex-frag
'mathjax
))
2393 ((equal processing-type
'dvipng
)
2394 (let* ((formula-link (org-e-html-format-latex
2395 latex-frag processing-type
)))
2396 (when (and formula-link
2397 (string-match "file:\\([^]]*\\)" formula-link
))
2398 (org-e-html-format-inline-image
2399 (match-string 1 formula-link
) caption label attr t
))))
2406 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2407 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2408 CONTENTS is nil. INFO is a plist holding contextual information."
2409 (let ((latex-frag (org-element-property :value latex-fragment
))
2410 (processing-type (plist-get info
:LaTeX-fragments
)))
2411 (case processing-type
2413 (org-e-html-format-latex latex-frag
'mathjax
))
2415 (let* ((formula-link (org-e-html-format-latex
2416 latex-frag processing-type
)))
2417 (when (and formula-link
2418 (string-match "file:\\([^]]*\\)" formula-link
))
2419 (org-e-html-format-inline-image
2420 (match-string 1 formula-link
)))))
2425 (defun org-e-html-line-break (line-break contents info
)
2426 "Transcode a LINE-BREAK object from Org to HTML.
2427 CONTENTS is nil. INFO is a plist holding contextual information."
2433 (defun org-e-html-link--inline-image (link info
)
2434 "Return HTML code for an inline image.
2435 LINK is the link pointing to the inline image. INFO is a plist
2436 used as a communication channel."
2437 (let* ((parent (org-export-get-parent-paragraph link info
))
2438 (path (let ((raw-path (org-element-property :path link
)))
2439 (if (not (file-name-absolute-p raw-path
)) raw-path
2440 (expand-file-name raw-path
))))
2441 (caption (org-e-html--caption/label-string
2442 (org-element-property :caption parent
)
2443 (org-element-property :name parent
)
2445 (label (org-element-property :name parent
))
2446 ;; Retrieve latex attributes from the element around.
2447 (attr (let ((raw-attr
2448 (mapconcat #'identity
2449 (org-element-property :attr_html parent
)
2451 (unless (string= raw-attr
"") raw-attr
))))
2452 ;; Now clear ATTR from any special keyword and set a default
2453 ;; value if nothing is left.
2454 (setq attr
(if (not attr
) "" (org-trim attr
)))
2455 ;; Return proper string, depending on DISPOSITION.
2456 (let ((href (and label
(org-export-solidify-link-text label
))))
2457 (org-e-html-format-inline-image
2458 path caption href attr
(org-e-html-standalone-image-p link info
)))))
2460 (defvar org-e-html-standalone-image-predicate
)
2461 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2462 "Test if ELEMENT is a standalone image for the purpose HTML export.
2463 INFO is a plist holding contextual information.
2465 Return non-nil, if ELEMENT is of type paragraph and it's sole
2466 content, save for whitespaces, is a link that qualifies as an
2469 Return non-nil, if ELEMENT is of type link and it's containing
2470 paragraph has no other content save for leading and trailing
2473 Return nil, otherwise.
2475 Bind `org-e-html-standalone-image-predicate' to constrain
2476 paragraph further. For example, to check for only captioned
2477 standalone images, do the following.
2479 \(setq org-e-html-standalone-image-predicate
2480 \(lambda \(paragraph\)
2481 \(org-element-property :caption paragraph\)\)\)
2483 (let ((paragraph (case (org-element-type element
)
2485 (link (and (org-export-inline-image-p
2486 element org-e-html-inline-image-rules
)
2487 (org-export-get-parent element info
)))
2490 (assert (eq (org-element-type paragraph
) 'paragraph
))
2491 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2492 (functionp org-e-html-standalone-image-predicate
)))
2493 (funcall org-e-html-standalone-image-predicate paragraph
))
2494 (let ((contents (org-element-contents paragraph
)))
2495 (loop for x in contents
2496 with inline-image-count
= 0
2498 ((eq (org-element-type x
) 'plain-text
)
2499 (not (org-string-nw-p x
)))
2500 ((eq (org-element-type x
) 'link
)
2501 (when (org-export-inline-image-p
2502 x org-e-html-inline-image-rules
)
2503 (= (incf inline-image-count
) 1)))
2506 (defun org-e-html-link (link desc info
)
2507 "Transcode a LINK object from Org to HTML.
2509 DESC is the description part of the link, or the empty string.
2510 INFO is a plist holding contextual information. See
2512 (let* ((type (org-element-property :type link
))
2513 (raw-path (org-element-property :path link
))
2514 ;; Ensure DESC really exists, or set it to nil.
2515 (desc (and (not (string= desc
"")) desc
))
2516 (imagep (org-export-inline-image-p
2517 link org-e-html-inline-image-rules
))
2519 ((member type
'("http" "https" "ftp" "mailto"))
2520 (concat type
":" raw-path
))
2521 ((string= type
"file")
2522 (when (string-match "\\(.+\\)::.+" raw-path
)
2523 (setq raw-path
(match-string 1 raw-path
)))
2524 (if (file-name-absolute-p raw-path
)
2525 (concat "file://" (expand-file-name raw-path
))
2526 ;; TODO: Not implemented yet. Concat also:
2527 ;; (org-export-directory :HTML info)
2528 (concat "file://" raw-path
)))
2533 (imagep (org-e-html-link--inline-image link info
))
2534 ;; Radioed target: Target's name is obtained from original raw
2535 ;; link. Path is parsed and transcoded in order to have a proper
2536 ;; display of the contents.
2537 ((string= type
"radio")
2538 (format "<a href=\"#%s\">%s</a>"
2539 (org-export-solidify-link-text path
)
2540 (org-export-secondary-string
2541 (org-element-parse-secondary-string
2542 path
(cdr (assq 'radio-target org-element-object-restrictions
)))
2544 ;; Links pointing to an headline: Find destination and build
2545 ;; appropriate referencing command.
2546 ((member type
'("custom-id" "fuzzy" "id"))
2547 (let ((destination (if (string= type
"fuzzy")
2548 (org-export-resolve-fuzzy-link link info
)
2549 (org-export-resolve-id-link link info
))))
2550 (case (org-element-type destination
)
2551 ;; Fuzzy link points nowhere.
2554 (or desc
(org-export-secondary-string
2555 (org-element-property :raw-link link
)
2557 ;; Fuzzy link points to an invisible target.
2559 ;; LINK points to an headline. If headlines are numbered
2560 ;; and the link has no description, display headline's
2561 ;; number. Otherwise, display description or headline's
2564 (let* ((headline-no (org-export-get-headline-number destination info
))
2565 (label (format "sec-%s" (mapconcat 'number-to-string
2567 (section-no (mapconcat 'number-to-string headline-no
".")))
2571 ((plist-get info
:section-numbers
) section-no
)
2572 (t (org-export-secondary-string
2573 (org-element-property :title destination
)
2575 (format "<a href=\"#%s\">%s</a>" label desc
)))
2576 ;; Fuzzy link points to a target. Do as above.
2578 (let ((path (org-export-solidify-link-text path
)) number
)
2581 ((org-e-html-standalone-image-p destination info
)
2582 (org-export-get-ordinal
2583 (assoc 'link
(org-element-contents destination
))
2584 info
'link nil
'org-e-html-standalone-image-p
))
2585 (t (org-export-get-ordinal destination info
))))
2586 (setq desc
(when number
2587 (if (atom number
) (number-to-string number
)
2588 (mapconcat 'number-to-string number
".")))))
2589 (format "<a href=\"#%s\">%s</a>" path
(or desc
"FIXME")))))))
2590 ;; Coderef: replace link with the reference name or the
2591 ;; equivalent line number.
2592 ((string= type
"coderef")
2593 (let ((fragment (concat "coderef-" path
)))
2594 (format "<a href=#%s %s>%s</a>" fragment
2595 (format (concat "class=\"coderef\""
2596 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2597 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2599 (format (org-export-get-coderef-format path
(or desc
"%s"))
2600 (org-export-resolve-coderef path info
)))))
2601 ;; Link type is handled by a special function.
2602 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2603 (funcall protocol
(org-link-unescape path
) desc
'html
))
2604 ;; External link with a description part.
2605 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2606 ;; External link without a description part.
2607 (path (format "<a href=\"%s\">%s</a>" path path
))
2608 ;; No path, only description. Try to do something useful.
2609 (t (format "<i>%s</i>" desc
)))))
2614 ;; Babel Calls are ignored.
2619 (defun org-e-html-macro (macro contents info
)
2620 "Transcode a MACRO element from Org to HTML.
2621 CONTENTS is nil. INFO is a plist holding contextual information."
2622 ;; Use available tools.
2623 (org-export-expand-macro macro info
))
2628 (defun org-e-html-paragraph (paragraph contents info
)
2629 "Transcode a PARAGRAPH element from Org to HTML.
2630 CONTENTS is the contents of the paragraph, as a string. INFO is
2631 the plist used as a communication channel."
2632 (let* ((style nil
) ; FIXME
2633 (class (cdr (assoc style
'((footnote .
"footnote")
2635 (extra (if class
(format " class=\"%s\"" class
) ""))
2636 (parent (org-export-get-parent paragraph info
)))
2638 ((and (equal (car parent
) 'item
)
2639 (= (org-element-property :begin paragraph
)
2640 (org-element-property :contents-begin parent
)))
2641 ;; leading paragraph in a list item have no tags
2643 ((org-e-html-standalone-image-p paragraph info
)
2646 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2651 (defun org-e-html-begin-plain-list (type &optional arg1
)
2654 (format "<ol%s>" (if arg1
; FIXME
2655 (format " start=\"%d\"" arg1
)
2658 (descriptive "<dl>")))
2660 (defun org-e-html-end-plain-list (type)
2664 (descriptive "</dl>")))
2666 (defun org-e-html-plain-list (plain-list contents info
)
2667 "Transcode a PLAIN-LIST element from Org to HTML.
2668 CONTENTS is the contents of the list. INFO is a plist holding
2669 contextual information."
2670 (let* (arg1 ;; FIXME
2671 (type (org-element-property :type plain-list
))
2672 (attr (mapconcat #'identity
2673 (org-element-property :attr_html plain-list
)
2675 (org-e-html--wrap-label
2676 plain-list
(format "%s\n%s%s"
2677 (org-e-html-begin-plain-list type
)
2678 contents
(org-e-html-end-plain-list type
)))))
2682 (defun org-e-html-convert-special-strings (string)
2683 "Convert special characters in STRING to HTML."
2684 (let ((all org-e-html-special-string-regexps
)
2686 (while (setq a
(pop all
))
2687 (setq re
(car a
) rpl
(cdr a
) start
0)
2688 (while (string-match re string start
)
2689 (setq string
(replace-match rpl t nil string
))))
2692 (defun org-e-html-encode-plain-text (s)
2693 "Convert plain text characters to HTML equivalent.
2694 Possible conversions are set in `org-export-html-protect-char-alist'."
2695 (let ((cl org-e-html-protect-char-alist
) c
)
2696 (while (setq c
(pop cl
))
2698 (while (string-match (car c
) s start
)
2699 (setq s
(replace-match (cdr c
) t t s
)
2700 start
(1+ (match-beginning 0))))))
2703 (defun org-e-html-plain-text (text info
)
2704 "Transcode a TEXT string from Org to HTML.
2705 TEXT is the string to transcode. INFO is a plist holding
2706 contextual information."
2707 (setq text
(org-e-html-encode-plain-text text
))
2708 ;; Protect %, #, &, $, ~, ^, _, { and }.
2709 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2711 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2713 ;; (setq text (replace-regexp-in-string
2714 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2715 ;; "$\\backslash$" text nil t 1))
2716 ;; HTML into \HTML{} and TeX into \TeX{}.
2717 ;; (let ((case-fold-search nil)
2719 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2720 ;; (setq text (replace-match
2721 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2722 ;; start (match-end 0))))
2723 ;; Handle quotation marks
2724 ;; (setq text (org-e-html--quotation-marks text info))
2725 ;; Convert special strings.
2726 ;; (when (plist-get info :with-special-strings)
2727 ;; (while (string-match (regexp-quote "...") text)
2728 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2729 (when (plist-get info
:with-special-strings
)
2730 (setq text
(org-e-html-convert-special-strings text
)))
2731 ;; Handle break preservation if required.
2732 (when (plist-get info
:preserve-breaks
)
2733 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2739 ;;;; Property Drawer
2741 (defun org-e-html-property-drawer (property-drawer contents info
)
2742 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2743 CONTENTS is nil. INFO is a plist holding contextual
2745 ;; The property drawer isn't exported but we want separating blank
2746 ;; lines nonetheless.
2752 (defun org-e-html-quote-block (quote-block contents info
)
2753 "Transcode a QUOTE-BLOCK element from Org to HTML.
2754 CONTENTS holds the contents of the block. INFO is a plist
2755 holding contextual information."
2756 (org-e-html--wrap-label
2757 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2762 (defun org-e-html-quote-section (quote-section contents info
)
2763 "Transcode a QUOTE-SECTION element from Org to HTML.
2764 CONTENTS is nil. INFO is a plist holding contextual information."
2765 (let ((value (org-remove-indentation
2766 (org-element-property :value quote-section
))))
2767 (when value
(format "<pre>\n%s</pre>" value
))))
2772 (defun org-e-html-section (section contents info
) ; FIXME
2773 "Transcode a SECTION element from Org to HTML.
2774 CONTENTS holds the contents of the section. INFO is a plist
2775 holding contextual information."
2776 (let ((parent (org-export-get-parent-headline section info
)))
2777 ;; Before first headline: no container, just return CONTENTS.
2778 (if (not parent
) contents
2779 ;; Get div's class and id references.
2780 (let ((class-num (+ (org-export-get-relative-level parent info
)
2781 (1- org-e-html-toplevel-hlevel
)))
2785 (org-export-get-headline-number parent info
) "-")))
2786 ;; Build return value.
2787 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2788 class-num id-num contents
)))))
2792 (defun org-e-html-radio-target (radio-target text info
)
2793 "Transcode a RADIO-TARGET object from Org to HTML.
2794 TEXT is the text of the target. INFO is a plist holding
2795 contextual information."
2796 (let ((id (org-export-solidify-link-text
2797 (org-element-property :raw-value radio-target
))))
2798 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2803 (defun org-e-html-special-block (special-block contents info
)
2804 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2805 CONTENTS holds the contents of the block. INFO is a plist
2806 holding contextual information."
2807 (let ((type (downcase (org-element-property :type special-block
))))
2808 (org-e-html--wrap-label
2810 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2815 (defun org-e-html-src-block (src-block contents info
)
2816 "Transcode a SRC-BLOCK element from Org to HTML.
2817 CONTENTS holds the contents of the item. INFO is a plist holding
2818 contextual information."
2819 (let* ((lang (org-element-property :language src-block
))
2820 (code (org-export-handle-code src-block info nil nil t
))
2821 (caption (org-element-property :caption src-block
))
2822 (label (org-element-property :name src-block
)))
2823 ;; FIXME: Handle caption
2825 ;; caption-str (when caption)
2826 ;; (main (org-export-secondary-string (car caption) 'e-html info))
2827 ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
2828 ;; (caption-str (org-e-html--caption/label-string caption label info))
2829 (org-e-html-format-source-code-or-example lang code
)))
2832 ;;;; Statistics Cookie
2834 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2835 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2836 CONTENTS is nil. INFO is a plist holding contextual information."
2837 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2838 (format "<code>%s</code>" cookie-value
)))
2843 (defun org-e-html-subscript (subscript contents info
)
2844 "Transcode a SUBSCRIPT object from Org to HTML.
2845 CONTENTS is the contents of the object. INFO is a plist holding
2846 contextual information."
2847 (format "<sub>%s</sub>" contents
))
2852 (defun org-e-html-superscript (superscript contents info
)
2853 "Transcode a SUPERSCRIPT object from Org to HTML.
2854 CONTENTS is the contents of the object. INFO is a plist holding
2855 contextual information."
2856 (format "<sup>%s</sup>" contents
))
2861 (defun org-e-html-begin-table (caption label attributes
)
2862 (let* ((html-table-tag (or (plist-get info
:html-table-tag
) ; FIXME
2863 org-e-html-table-tag
))
2865 (org-e-html-splice-attributes html-table-tag attributes
)))
2867 (setq html-table-tag
2868 (org-e-html-splice-attributes
2870 (format "id=\"%s\"" (org-solidify-link-text label
)))))
2871 (concat "\n" html-table-tag
2872 (format "\n<caption>%s</caption>" (or caption
"")))))
2874 (defun org-e-html-end-table ()
2877 (defun org-e-html-format-table-cell (text r c horiz-span
)
2878 (let ((cell-style-cookie
2879 (if org-e-html-table-align-individual-fields
2880 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2881 org-e-html-format-table-no-css
)
2882 " align=\"%s\"" " class=\"%s\"")
2883 (or (aref (plist-get table-info
:alignment
) c
) "left")) ""))) ;; FIXME
2885 (org-e-html-table-cur-rowgrp-is-hdr
2887 (format (car org-e-html-table-header-tags
) "col" cell-style-cookie
)
2888 text
(cdr org-e-html-table-header-tags
)))
2889 ((and (= c
0) org-e-html-table-use-header-tags-for-first-column
)
2891 (format (car org-e-html-table-header-tags
) "row" cell-style-cookie
)
2892 text
(cdr org-e-html-table-header-tags
)))
2895 (format (car org-e-html-table-data-tags
) cell-style-cookie
)
2896 text
(cdr org-e-html-table-data-tags
))))))
2898 (defun org-e-html-format-table-row (row)
2899 (concat (eval (car org-e-html-table-row-tags
)) row
2900 (eval (cdr org-e-html-table-row-tags
))))
2902 (defun org-e-html-table-row (fields &optional text-for-empty-fields
)
2903 (incf org-e-html-table-rownum
)
2905 (org-e-html-format-table-row
2908 (when (and (string= x
"") text-for-empty-fields
)
2909 (setq x text-for-empty-fields
))
2912 (org-e-html-format-table-cell
2913 x org-e-html-table-rownum i
(or horiz-span
0))))
2916 (defun org-e-html-end-table-rowgroup ()
2917 (when org-e-html-table-rowgrp-open
2918 (setq org-e-html-table-rowgrp-open nil
)
2919 (if org-e-html-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>")))
2921 (defun org-e-html-begin-table-rowgroup (&optional is-header-row
)
2923 (when org-e-html-table-rowgrp-open
2924 (org-e-html-end-table-rowgroup))
2926 (setq org-e-html-table-rowgrp-open t
)
2927 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row
)
2928 (if is-header-row
"<thead>" "<tbody>"))))
2930 (defun org-e-html-table-preamble ()
2931 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
2932 c gr colgropen preamble
)
2933 (unless (aref colgroup-vector
0)
2934 (setf (aref colgroup-vector
0) 'start
))
2935 (dotimes (c columns-number preamble
)
2936 (setq gr
(aref colgroup-vector c
))
2940 (when (memq gr
'(start start-end
))
2941 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
2942 (setq colgropen t
)))
2943 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
2944 (align (cdr (assoc (aref colalign-vector c
)
2947 ("c" .
"center")))))
2948 (alignspec (if (and (boundp 'org-e-html-format-table-no-css
)
2949 org-e-html-format-table-no-css
)
2950 " align=\"%s\"" " class=\"%s\""))
2951 (extra (format alignspec align
)))
2952 (format "<col%s />" extra
))
2953 (when (memq gr
'(end start-end
))
2954 (setq colgropen nil
)
2956 (concat preamble
(if colgropen
"</colgroup>"))))
2958 (defun org-e-html-list-table (lines caption label attributes
)
2959 (setq lines
(org-e-html-org-table-to-list-table lines
))
2960 (let* ((splice nil
) head
2961 (org-e-html-table-rownum -
1)
2964 org-e-html-table-cur-rowgrp-is-hdr
2965 org-e-html-table-rowgrp-open
2967 (org-lparse-table-style 'org-table
)
2968 org-lparse-table-is-styled
)
2971 (setq org-lparse-table-is-styled nil
)
2972 (mapconcat 'org-e-html-table-row lines
"\n"))
2974 (setq org-lparse-table-is-styled t
)
2977 (org-e-html-begin-table caption label attributes
)
2978 (org-e-html-table-preamble)
2979 (org-e-html-begin-table-rowgroup head
)
2984 ((equal line
'hline
) (org-e-html-begin-table-rowgroup))
2985 (t (org-e-html-table-row line
))))
2988 (org-e-html-end-table-rowgroup)
2989 (org-e-html-end-table))))))
2991 (defun org-e-html-transcode-table-row (row)
2992 (if (string-match org-table-hline-regexp row
) 'hline
2995 (org-export-secondary-string
2996 (let ((cell (org-element-parse-secondary-string
2998 (cdr (assq 'table org-element-string-restrictions
)))))
3001 (org-split-string row
"[ \t]*|[ \t]*"))))
3003 (defun org-e-html-org-table-to-list-table (lines &optional splice
)
3004 "Convert org-table to list-table.
3005 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
3006 element is a `string' representing a single row of org-table.
3007 Thus each ROW has vertical separators \"|\" separating the table
3008 fields. A ROW could also be a row-group separator of the form
3009 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
3010 ...). ROW could either be symbol `'hline' or a list of the
3011 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
3015 (while (setq line
(pop lines
))
3016 (unless (string-match "^[ \t]*|-" line
)
3017 (push (org-e-html-transcode-table-row line
) lines-1
))))
3018 (t (while (setq line
(pop lines
))
3020 ((string-match "^[ \t]*|-" line
)
3021 (when lines
(push 'hline lines-1
)))
3022 (t (push (org-e-html-transcode-table-row line
) lines-1
))))))
3023 (nreverse lines-1
)))
3025 (defun org-e-html-table-table (raw-table)
3027 (with-current-buffer (get-buffer-create "*org-export-table*")
3029 (let ((output (with-temp-buffer
3032 (re-search-forward "^[ \t]*|[^|]" nil t
)
3033 (table-generate-source 'html
"*org-export-table*")
3034 (with-current-buffer "*org-export-table*"
3035 (org-trim (buffer-string))))))
3036 (kill-buffer (get-buffer "*org-export-table*"))
3039 (defun org-e-html-table (table contents info
)
3040 "Transcode a TABLE element from Org to HTML.
3041 CONTENTS is nil. INFO is a plist holding contextual information."
3042 (let* ((label (org-element-property :name table
))
3043 (caption (org-e-html--caption/label-string
3044 (org-element-property :caption table
) label info
))
3045 (attr (mapconcat #'identity
3046 (org-element-property :attr_html table
)
3048 (raw-table (org-element-property :raw-table table
))
3049 (table-type (org-element-property :type table
)))
3052 (org-e-html-table-table raw-table
))
3054 (let* ((table-info (org-export-table-format-info raw-table
))
3055 (columns-number (length (plist-get table-info
:alignment
)))
3056 (lines (org-split-string
3057 (org-export-clean-table
3058 raw-table
(plist-get table-info
:special-column-p
)) "\n")))
3059 (org-e-html-list-table lines caption label attr
))))))
3064 (defun org-e-html-target (target contents info
)
3065 "Transcode a TARGET object from Org to HTML.
3066 CONTENTS is nil. INFO is a plist holding contextual
3068 (let ((id (org-export-solidify-link-text
3069 (org-element-property :value target
))))
3070 (format "<a id=\"%s\" name=\"%s\"/>" id id
)))
3075 (defun org-e-html-time-stamp (time-stamp contents info
)
3076 "Transcode a TIME-STAMP object from Org to HTML.
3077 CONTENTS is nil. INFO is a plist holding contextual
3079 (let ((value (org-element-property :value time-stamp
))
3080 (type (org-element-property :type time-stamp
))
3081 (appt-type (org-element-property :appt-type time-stamp
)))
3082 (setq value
(org-translate-time
3083 (org-export-secondary-string value
'e-html info
)))
3084 (setq appt-type
(case appt-type
3085 (scheduled org-scheduled-string
)
3086 (deadline org-deadline-string
)
3087 (closed org-closed-string
)))
3088 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
3089 (if (not appt-type
) ""
3090 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type
))
3091 (format "<span class=\"timestamp\">%s</span>" value
))))
3096 (defun org-e-html-verbatim (verbatim contents info
)
3097 "Transcode a VERBATIM object from Org to HTML.
3098 CONTENTS is nil. INFO is a plist used as a communication
3100 (org-e-html-emphasis
3101 verbatim
(org-element-property :value verbatim
) info
))
3106 (defun org-e-html-verse-block (verse-block contents info
)
3107 "Transcode a VERSE-BLOCK element from Org to HTML.
3108 CONTENTS is nil. INFO is a plist holding contextual information."
3109 ;; Replace each newline character with line break. Also replace
3110 ;; each blank line with a line break.
3111 (setq contents
(replace-regexp-in-string
3112 "^ *\\\\\\\\$" "<br/>\n"
3113 (replace-regexp-in-string
3114 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3115 (org-remove-indentation
3116 (org-export-secondary-string
3117 (org-element-property :value verse-block
)
3119 ;; Replace each white space at beginning of a line with a
3120 ;; non-breaking space.
3121 (while (string-match "^[ \t]+" contents
)
3122 (let* ((num-ws (length (match-string 0 contents
)))
3123 (ws (let (out) (dotimes (i num-ws out
)
3124 (setq out
(concat out
" "))))))
3125 (setq contents
(replace-match ws nil t contents
))))
3126 (org-e-html--wrap-label
3127 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3132 ;;; Filter Functions
3134 ;;;; Filter Settings
3136 (defconst org-e-html-filters-alist
3137 '((:filter-final-output . org-e-html-final-function
))
3138 "Alist between filters keywords and back-end specific filters.
3139 See `org-export-filters-alist' for more information.")
3144 (defun org-e-html-final-function (contents backend info
)
3145 (if (not org-e-html-pretty-output
) contents
3149 (indent-region (point-min) (point-max))
3150 (buffer-substring-no-properties (point-min) (point-max)))))
3153 ;;; Interactive functions
3155 (defun org-e-html-export-to-html
3156 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3157 "Export current buffer to a HTML file.
3159 If narrowing is active in the current buffer, only export its
3162 If a region is active, export that region.
3164 When optional argument SUBTREEP is non-nil, export the sub-tree
3165 at point, extracting information from the headline properties
3168 When optional argument VISIBLE-ONLY is non-nil, don't export
3169 contents of hidden elements.
3171 When optional argument BODY-ONLY is non-nil, only write code
3172 between \"\\begin{document}\" and \"\\end{document}\".
3174 EXT-PLIST, when provided, is a property list with external
3175 parameters overriding Org default settings, but still inferior to
3176 file-local settings.
3178 When optional argument PUB-DIR is set, use it as the publishing
3181 Return output file's name."
3185 (with-current-buffer (get-buffer-create "*debug*")
3187 (let* ((extension (concat "." org-e-html-extension
))
3188 (file (org-export-output-file-name extension subtreep pub-dir
)))
3190 'e-html file subtreep visible-only body-only ext-plist
)))
3194 ;;; FIXMES, TODOS, FOR REVIEW etc
3196 ;;;; org-format-table-html
3197 ;;;; org-format-org-table-html
3198 ;;;; org-format-table-table-html
3199 ;;;; org-table-number-fraction
3200 ;;;; org-table-number-regexp
3201 ;;;; org-e-html-table-caption-above
3204 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3205 ;;;; Remove display properties
3207 ;;;; org-e-html-with-timestamp
3208 ;;;; org-e-html-html-helper-timestamp
3210 ;;;; org-export-as-html-and-open
3211 ;;;; org-export-as-html-batch
3212 ;;;; org-export-as-html-to-buffer
3213 ;;;; org-replace-region-by-html
3214 ;;;; org-export-region-as-html
3215 ;;;; org-export-as-html
3217 ;;;; (org-export-directory :html opt-plist)
3218 ;;;; (plist-get opt-plist :html-extension)
3219 ;;;; org-e-html-toplevel-hlevel
3220 ;;;; org-e-html-special-string-regexps
3221 ;;;; org-e-html-coding-system
3222 ;;;; org-e-html-coding-system
3223 ;;;; org-e-html-inline-images
3224 ;;;; org-e-html-inline-image-extensions
3225 ;;;; org-e-html-protect-char-alist
3226 ;;;; org-e-html-table-use-header-tags-for-first-column
3227 ;;;; org-e-html-todo-kwd-class-prefix
3228 ;;;; org-e-html-tag-class-prefix
3229 ;;;; org-e-html-footnote-separator
3231 ;;;; org-export-preferred-target-alist
3232 ;;;; org-solidify-link-text
3233 ;;;; class for anchors
3234 ;;;; org-export-with-section-numbers, body-only
3236 (provide 'org-e-html
)
3237 ;;; org-e-html.el ends here