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
))
45 (defvar org-e-html-after-blockquotes-hook nil
46 "Hook run during HTML export, after blockquote, verse, center are done.")
48 (defvar org-e-html-final-hook nil
49 "Hook run at the end of HTML export, in the new buffer.")
51 ;; FIXME: it already exists in org-e-html.el
52 ;;; Function Declarations
54 (declare-function org-element-get-property
"org-element" (property element
))
55 (declare-function org-element-normalize-string
"org-element" (s))
56 (declare-function org-element-parse-secondary-string
57 "org-element" (string restriction
&optional buffer
))
58 (defvar org-element-string-restrictions
)
60 (declare-function org-export-clean-table
"org-export" (table specialp
))
61 (declare-function org-export-data
"org-export" (data backend info
))
62 (declare-function org-export-directory
"org-export" (type plist
))
63 (declare-function org-export-expand-macro
"org-export" (macro info
))
64 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
65 (declare-function org-export-footnote-first-reference-p
"org-export"
66 (footnote-reference info
))
67 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
68 (declare-function org-export-get-footnote-definition
"org-export"
69 (footnote-reference info
))
70 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
71 (declare-function org-export-get-previous-element
"org-export" (blob info
))
72 (declare-function org-export-get-relative-level
"org-export" (headline info
))
73 (declare-function org-export-handle-code
74 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
75 (declare-function org-export-included-file
"org-export" (keyword backend info
))
76 (declare-function org-export-inline-image-p
"org-export"
77 (link &optional extensions
))
78 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
79 (declare-function org-export-low-level-p
"org-export" (headline info
))
80 (declare-function org-export-output-file-name
81 "org-export" (extension &optional subtreep pub-dir
))
82 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
83 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
84 (declare-function org-export-secondary-string
"org-export"
85 (secondary backend info
))
86 (declare-function org-export-solidify-link-text
"org-export" (s))
87 (declare-function org-export-table-format-info
"org-export" (table))
89 org-export-to-buffer
"org-export"
90 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
92 org-export-to-file
"org-export"
93 (backend file
&optional subtreep visible-only body-only ext-plist
))
95 (declare-function org-id-find-id-file
"org-id" (id))
96 (declare-function htmlize-region
"ext:htmlize" (beg end
))
97 (declare-function org-pop-to-buffer-same-window
98 "org-compat" (&optional buffer-or-name norecord label
))
103 ;;; Internal Variables
105 (defconst org-e-html-option-alist
106 '((:agenda-style nil nil org-agenda-export-html-style
)
107 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
108 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
109 ;; (:expand-quoted-html nil "@" org-e-html-expand)
110 (:inline-images nil nil org-e-html-inline-images
)
111 ;; (:link-home nil nil org-e-html-link-home) FIXME
112 ;; (:link-up nil nil org-e-html-link-up) FIXME
113 (:style nil nil org-e-html-style
)
114 (:style-extra nil nil org-e-html-style-extra
)
115 (:style-include-default nil nil org-e-html-style-include-default
)
116 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
117 ;; (:timestamp nil nil org-e-html-with-timestamp)
118 (:html-extension nil nil org-e-html-extension
)
119 (:html-postamble nil nil org-e-html-postamble
)
120 (:html-preamble nil nil org-e-html-preamble
)
121 (:html-table-tag nil nil org-e-html-table-tag
)
122 (:xml-declaration nil nil org-e-html-xml-declaration
)
123 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
124 (:mathjax
"MATHJAX" nil
"" space
))
125 "Alist between export properties and ways to set them.
127 The car of the alist is the property name, and the cdr is a list
128 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
130 KEYWORD is a string representing a buffer keyword, or nil.
131 OPTION is a string that could be found in an #+OPTIONS: line.
132 DEFAULT is the default value for the property.
133 BEHAVIOUR determine how Org should handle multiple keywords for
134 the same property. It is a symbol among:
135 nil Keep old value and discard the new one.
136 t Replace old value with the new one.
137 `space' Concatenate the values, separating them with a space.
138 `newline' Concatenate the values, separating them with
140 `split' Split values at white spaces, and cons them to the
143 KEYWORD and OPTION have precedence over DEFAULT.
145 All these properties should be back-end agnostic. For back-end
146 specific properties, define a similar variable named
147 `org-BACKEND-option-alist', replacing BACKEND with the name of
148 the appropriate back-end. You can also redefine properties
149 there, as they have precedence over these.")
151 (defvar html-table-tag nil
) ; dynamically scoped into this.
153 ;; FIXME: it already exists in org-e-html.el
154 (defconst org-e-html-cvt-link-fn
156 "Function to convert link URLs to exportable URLs.
157 Takes two arguments, TYPE and PATH.
158 Returns exportable url as (TYPE PATH), or nil to signal that it
159 didn't handle this case.
160 Intended to be locally bound around a call to `org-export-as-html'." )
165 (defvar org-e-html-format-table-no-css
)
166 (defvar htmlize-buffer-places
) ; from htmlize.el
167 (defvar body-only
) ; dynamically scoped into this.
169 (defvar org-e-html-table-rowgrp-open
)
170 (defvar org-e-html-table-rownum
)
171 (defvar org-e-html-table-cur-rowgrp-is-hdr
)
172 (defvar org-lparse-table-is-styled
)
175 (defvar org-e-html-headline-formatter
176 (lambda (level snumber todo todo-type priority
177 title tags target extra-targets extra-class
)
178 (concat snumber
" " title
)))
182 ;;; User Configuration Variables
184 (defgroup org-export-e-html nil
185 "Options for exporting Org mode files to HTML."
186 :tag
"Org Export HTML"
191 (defcustom org-e-html-pretty-output t
192 "Enable this to generate pretty HTML."
193 :group
'org-export-e-html
199 (defcustom org-e-html-extension
"html"
200 "The extension for exported HTML files."
201 :group
'org-export-e-html
204 (defcustom org-e-html-xml-declaration
205 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
206 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
207 "The extension for exported HTML files.
208 %s will be replaced with the charset of the exported file.
209 This may be a string, or an alist with export extensions
210 and corresponding declarations."
211 :group
'org-export-e-html
213 (string :tag
"Single declaration")
214 (repeat :tag
"Dependent on extension"
215 (cons (string :tag
"Extension")
216 (string :tag
"Declaration")))))
218 (defcustom org-e-html-coding-system nil
219 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
220 :group
'org-export-e-html
221 :type
'coding-system
)
223 (defvar org-e-html-content-div
"content"
224 "The name of the container DIV that holds all the page contents.
226 This variable is obsolete since Org version 7.7.
227 Please set `org-e-html-divs' instead.")
229 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
230 "The name of the main divs for HTML export.
231 This is a list of three strings, the first one for the preamble
232 DIV, the second one for the content DIV and the third one for the
234 :group
'org-export-e-html
236 (string :tag
" Div for the preamble:")
237 (string :tag
" Div for the content:")
238 (string :tag
"Div for the postamble:")))
241 ;;;; Document Header (Styles)
243 (defconst org-e-html-style-default
244 "<style type=\"text/css\">
245 <!--/*--><![CDATA[/*><!--*/
246 html { font-family: Times, serif; font-size: 12pt; }
247 .title { text-align: center; }
248 .todo { color: red; }
249 .done { color: green; }
250 .tag { background-color: #add8e6; font-weight:normal }
252 .timestamp { color: #bebebe; }
253 .timestamp-kwd { color: #5f9ea0; }
254 .right {margin-left:auto; margin-right:0px; text-align:right;}
255 .left {margin-left:0px; margin-right:auto; text-align:left;}
256 .center {margin-left:auto; margin-right:auto; text-align:center;}
257 p.verse { margin-left: 3% }
259 border: 1pt solid #AEBDCC;
260 background-color: #F3F5F7;
262 font-family: courier, monospace;
266 table { border-collapse: collapse; }
267 td, th { vertical-align: top; }
268 th.right { text-align:center; }
269 th.left { text-align:center; }
270 th.center { text-align:center; }
271 td.right { text-align:right; }
272 td.left { text-align:left; }
273 td.center { text-align:center; }
274 dt { font-weight: bold; }
275 div.figure { padding: 0.5em; }
276 div.figure p { text-align: center; }
279 border:2px solid gray;
283 textarea { overflow-x: auto; }
284 .linenr { font-size:smaller }
285 .code-highlighted {background-color:#ffff00;}
286 .org-info-js_info-navigation { border-style:none; }
287 #org-info-js_console-label { font-size:10px; font-weight:bold;
288 white-space:nowrap; }
289 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
293 "The default style specification for exported HTML files.
294 Please use the variables `org-e-html-style' and
295 `org-e-html-style-extra' to add to this style. If you wish to not
296 have the default style included, customize the variable
297 `org-e-html-style-include-default'.")
299 (defcustom org-e-html-style-include-default t
300 "Non-nil means include the default style in exported HTML files.
301 The actual style is defined in `org-e-html-style-default' and should
302 not be modified. Use the variables `org-e-html-style' to add
303 your own style information."
304 :group
'org-export-e-html
307 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
309 (defcustom org-e-html-style
""
310 "Org-wide style definitions for exported HTML files.
312 This variable needs to contain the full HTML structure to provide a style,
313 including the surrounding HTML tags. If you set the value of this variable,
314 you should consider to include definitions for the following classes:
315 title, todo, done, timestamp, timestamp-kwd, tag, target.
317 For example, a valid value would be:
319 <style type=\"text/css\">
321 p { font-weight: normal; color: gray; }
323 .title { text-align: center; }
324 .todo, .timestamp-kwd { color: red; }
325 .done { color: green; }
329 If you'd like to refer to an external style file, use something like
331 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
333 As the value of this option simply gets inserted into the HTML <head> header,
334 you can \"misuse\" it to add arbitrary text to the header.
335 See also the variable `org-e-html-style-extra'."
336 :group
'org-export-e-html
339 (put 'org-e-html-style
'safe-local-variable
'stringp
)
341 (defcustom org-e-html-style-extra
""
342 "Additional style information for HTML export.
343 The value of this variable is inserted into the HTML buffer right after
344 the value of `org-e-html-style'. Use this variable for per-file
345 settings of style information, and do not forget to surround the style
346 settings with <style>...</style> tags."
347 :group
'org-export-e-html
350 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
352 (defcustom org-e-html-mathjax-options
353 '((path "http://orgmode.org/mathjax/MathJax.js")
358 "Options for MathJax setup.
360 path The path where to find MathJax
361 scale Scaling for the HTML-CSS backend, usually between 100 and 133
362 align How to align display math: left, center, or right
363 indent If align is not center, how far from the left/right side?
364 mathml Should a MathML player be used if available?
365 This is faster and reduces bandwidth use, but currently
366 sometimes has lower spacing quality. Therefore, the default is
367 nil. When browsers get better, this switch can be flipped.
369 You can also customize this for each buffer, using something like
371 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
372 :group
'org-export-e-html
373 :type
'(list :greedy t
374 (list :tag
"path (the path from where to load MathJax.js)"
375 (const :format
" " path
) (string))
376 (list :tag
"scale (scaling for the displayed math)"
377 (const :format
" " scale
) (string))
378 (list :tag
"align (alignment of displayed equations)"
379 (const :format
" " align
) (string))
380 (list :tag
"indent (indentation with left or right alignment)"
381 (const :format
" " indent
) (string))
382 (list :tag
"mathml (should MathML display be used is possible)"
383 (const :format
" " mathml
) (boolean))))
386 ;;;; Document Header (Scripts)
388 (defcustom org-e-html-style-include-scripts t
389 "Non-nil means include the JavaScript snippets in exported HTML files.
390 The actual script is defined in `org-e-html-scripts' and should
392 :group
'org-export-e-html
395 (defconst org-e-html-scripts
396 "<script type=\"text/javascript\">
397 <!--/*--><![CDATA[/*><!--*/
398 function CodeHighlightOn(elem, id)
400 var target = document.getElementById(id);
402 elem.cacheClassElem = elem.className;
403 elem.cacheClassTarget = target.className;
404 target.className = \"code-highlighted\";
405 elem.className = \"code-highlighted\";
408 function CodeHighlightOff(elem, id)
410 var target = document.getElementById(id);
411 if(elem.cacheClassElem)
412 elem.className = elem.cacheClassElem;
413 if(elem.cacheClassTarget)
414 target.className = elem.cacheClassTarget;
418 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
421 ;;;; Document Header (Mathjax)
423 (defcustom org-e-html-mathjax-template
424 "<script type=\"text/javascript\" src=\"%PATH\">
425 <!--/*--><![CDATA[/*><!--*/
427 // Only one of the two following lines, depending on user settings
428 // First allows browser-native MathML display, second forces HTML/CSS
429 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
430 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
431 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
432 \"TeX/noUndefined.js\"],
434 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
435 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
436 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
437 ignoreClass: \"tex2jax_ignore\",
438 processEscapes: false,
439 processEnvironments: true,
442 showProcessingMessages: true,
443 displayAlign: \"%ALIGN\",
444 displayIndent: \"%INDENT\",
448 availableFonts: [\"STIX\",\"TeX\"],
449 preferredFont: \"TeX\",
465 "The MathJax setup for XHTML files."
466 :group
'org-export-e-html
472 (defcustom org-e-html-preamble t
473 "Non-nil means insert a preamble in HTML export.
475 When `t', insert a string as defined by one of the formatting
476 strings in `org-e-html-preamble-format'. When set to a
477 string, this string overrides `org-e-html-preamble-format'.
478 When set to a function, apply this function and insert the
479 returned string. The function takes the property list of export
480 options as its only argument.
482 Setting :html-preamble in publishing projects will take
483 precedence over this variable."
484 :group
'org-export-e-html
485 :type
'(choice (const :tag
"No preamble" nil
)
486 (const :tag
"Default preamble" t
)
487 (string :tag
"Custom formatting string")
488 (function :tag
"Function (must return a string)")))
490 (defcustom org-e-html-preamble-format
'(("en" ""))
491 "The format for the HTML preamble.
493 %t stands for the title.
494 %a stands for the author's name.
495 %e stands for the author's email.
496 %d stands for the date.
498 If you need to use a \"%\" character, you need to escape it
500 :group
'org-export-e-html
503 (defcustom org-e-html-home
/up-format
504 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
505 <a accesskey=\"h\" href=\"%s\"> UP </a>
507 <a accesskey=\"H\" href=\"%s\"> HOME </a>
509 "Snippet used to insert the HOME and UP links.
510 This is a format string, the first %s will receive the UP link,
511 the second the HOME link. If both `org-e-html-link-up' and
512 `org-e-html-link-home' are empty, the entire snippet will be
514 :group
'org-export-e-html
519 (defcustom org-e-html-postamble
'auto
520 "Non-nil means insert a postamble in HTML export.
522 When `t', insert a string as defined by the formatting string in
523 `org-e-html-postamble-format'. When set to a string, this
524 string overrides `org-e-html-postamble-format'. When set to
525 'auto, discard `org-e-html-postamble-format' and honor
526 `org-export-author/email/creator-info' variables. When set to a
527 function, apply this function and insert the returned string.
528 The function takes the property list of export options as its
531 Setting :html-postamble in publishing projects will take
532 precedence over this variable."
533 :group
'org-export-e-html
534 :type
'(choice (const :tag
"No postamble" nil
)
535 (const :tag
"Auto preamble" 'auto
)
536 (const :tag
"Default formatting string" t
)
537 (string :tag
"Custom formatting string")
538 (function :tag
"Function (must return a string)")))
540 (defcustom org-e-html-postamble-format
541 '(("en" "<p class=\"author\">Author: %a (%e)</p>
542 <p class=\"date\">Date: %d</p>
543 <p class=\"creator\">Generated by %c</p>
544 <p class=\"xhtml-validation\">%v</p>
546 "The format for the HTML postamble.
548 %a stands for the author's name.
549 %e stands for the author's email.
550 %d stands for the date.
551 %c will be replaced by information about Org/Emacs versions.
552 %v will be replaced by `org-e-html-validation-link'.
554 If you need to use a \"%\" character, you need to escape it
556 :group
'org-export-e-html
559 (defcustom org-e-html-validation-link
560 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
561 "Link to HTML validation service."
562 :group
'org-export-e-html
565 ;; FIXME Obsolete since Org 7.7
566 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
569 (defcustom org-e-html-protect-char-alist
573 "Alist of characters to be converted by `org-e-html-protect'."
574 :group
'org-export-e-html
575 :type
'(repeat (cons (string :tag
"Character")
576 (string :tag
"HTML equivalent"))))
578 (defconst org-e-html-special-string-regexps
579 '(("\\\\-" .
"­")
580 ("---\\([^-]\\)" .
"—\\1")
581 ("--\\([^-]\\)" .
"–\\1")
582 ("\\.\\.\\." .
"…"))
583 "Regular expressions for special string conversion.")
588 (defcustom org-e-html-todo-kwd-class-prefix
""
589 "Prefix to class names for TODO keywords.
590 Each TODO keyword gets a class given by the keyword itself, with this prefix.
591 The default prefix is empty because it is nice to just use the keyword
592 as a class name. But if you get into conflicts with other, existing
593 CSS classes, then this prefix can be very useful."
594 :group
'org-export-e-html
600 (defcustom org-e-html-tag-class-prefix
""
601 "Prefix to class names for TODO keywords.
602 Each tag gets a class given by the tag itself, with this prefix.
603 The default prefix is empty because it is nice to just use the keyword
604 as a class name. But if you get into conflicts with other, existing
605 CSS classes, then this prefix can be very useful."
606 :group
'org-export-e-html
610 ;;;; Statistics Cookie
616 (defcustom org-e-html-inline-images
'maybe
617 "Non-nil means inline images into exported HTML pages.
618 This is done using an <img> tag. When nil, an anchor with href is used to
619 link to the image. If this option is `maybe', then images in links with
620 an empty description will be inlined, while images with a description will
622 :group
'org-export-e-html
623 :type
'(choice (const :tag
"Never" nil
)
624 (const :tag
"Always" t
)
625 (const :tag
"When there is no description" maybe
)))
627 (defcustom org-e-html-inline-image-extensions
628 '("png" "jpeg" "jpg" "gif" "svg")
629 "Extensions of image files that can be inlined into HTML."
630 :group
'org-export-e-html
631 :type
'(repeat (string :tag
"Extension")))
647 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
648 <h2 class=\"footnotes\">%s: </h2>
649 <div id=\"text-footnotes\">
653 "Format for the footnotes section.
654 Should contain a two instances of %s. The first will be replaced with the
655 language-specific word for \"Footnotes\", the second one will be replaced
656 by the footnotes themselves."
657 :group
'org-export-e-html
660 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
661 "The format for the footnote reference.
662 %s will be replaced by the footnote reference itself."
663 :group
'org-export-e-html
666 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
667 "Text used to separate footnotes."
668 :group
'org-export-e-html
674 ;;;; Inline Babel Call
675 ;;;; Inline Src Block
679 ;;;; Latex Environment
696 (defgroup org-export-e-htmlize nil
697 "Options for processing examples with htmlize.el."
698 :tag
"Org Export Htmlize"
699 :group
'org-export-e-html
)
701 (defcustom org-export-e-htmlize-output-type
'inline-css
702 "Output type to be used by htmlize when formatting code snippets.
703 Choices are `css', to export the CSS selectors only, or `inline-css', to
704 export the CSS attribute values inline in the HTML. We use as default
705 `inline-css', in order to make the resulting HTML self-containing.
707 However, this will fail when using Emacs in batch mode for export, because
708 then no rich font definitions are in place. It will also not be good if
709 people with different Emacs setup contribute HTML files to a website,
710 because the fonts will represent the individual setups. In these cases,
711 it is much better to let Org/Htmlize assign classes only, and to use
712 a style file to define the look of these classes.
713 To get a start for your css file, start Emacs session and make sure that
714 all the faces you are interested in are defined, for example by loading files
715 in all modes you want. Then, use the command
716 \\[org-export-e-htmlize-generate-css] to extract class definitions."
717 :group
'org-export-e-htmlize
718 :type
'(choice (const css
) (const inline-css
)))
720 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
721 "The prefix for CSS class names for htmlize font specifications."
722 :group
'org-export-e-htmlize
725 (defcustom org-export-e-htmlized-org-css-url nil
726 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
727 Normally when creating an htmlized version of an Org buffer, htmlize will
728 create CSS to define the font colors. However, this does not work when
729 converting in batch mode, and it also can look bad if different people
730 with different fontification setup work on the same website.
731 When this variable is non-nil, creating an htmlized version of an Org buffer
732 using `org-export-as-org' will remove the internal CSS section and replace it
733 with a link to this URL."
734 :group
'org-export-e-htmlize
736 (const :tag
"Keep internal css" nil
)
737 (string :tag
"URL or local href")))
742 (defcustom org-e-html-table-tag
743 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
744 "The HTML tag that is used to start a table.
745 This must be a <table> tag, but you may change the options like
746 borders and spacing."
747 :group
'org-export-e-html
750 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
751 "The opening tag for table header fields.
752 This is customizable so that alignment options can be specified.
753 The first %s will be filled with the scope of the field, either row or col.
754 The second %s will be replaced by a style entry to align the field.
755 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
756 See also the variable `org-e-html-table-align-individual-fields'."
757 :group
'org-export-tables
; FIXME: change group?
758 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
760 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
761 "The opening tag for table data fields.
762 This is customizable so that alignment options can be specified.
763 The first %s will be filled with the scope of the field, either row or col.
764 The second %s will be replaced by a style entry to align the field.
765 See also the variable `org-e-html-table-align-individual-fields'."
766 :group
'org-export-tables
767 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
769 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
770 "The opening tag for table data fields.
771 This is customizable so that alignment options can be specified.
772 Instead of strings, these can be Lisp forms that will be evaluated
773 for each row in order to construct the table row tags. During evaluation,
774 the variable `head' will be true when this is a header line, nil when this
775 is a body line. And the variable `nline' will contain the line number,
776 starting from 1 in the first header line. For example
778 (setq org-e-html-table-row-tags
781 (if (= (mod nline 2) 1)
782 \"<tr class=\\\"tr-odd\\\">\"
783 \"<tr class=\\\"tr-even\\\">\"))
786 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
787 :group
'org-export-tables
789 (choice :tag
"Opening tag"
790 (string :tag
"Specify")
792 (choice :tag
"Closing tag"
793 (string :tag
"Specify")
796 (defcustom org-e-html-table-align-individual-fields t
797 "Non-nil means attach style attributes for alignment to each table field.
798 When nil, alignment will only be specified in the column tags, but this
799 is ignored by some browsers (like Firefox, Safari). Opera does it right
801 :group
'org-export-tables
804 (defcustom org-e-html-table-use-header-tags-for-first-column nil
805 "Non-nil means format column one in tables with header tags.
806 When nil, also column one will use data tags."
807 :group
'org-export-tables
818 (defcustom org-e-html-toplevel-hlevel
2
819 "The <H> level for level 1 headings in HTML export.
820 This is also important for the classes that will be wrapped around headlines
821 and outline structure. If this variable is 1, the top-level headlines will
822 be <h1>, and the corresponding classes will be outline-1, section-number-1,
823 and outline-text-1. If this is 2, all of these will get a 2 instead.
824 The default for this variable is 2, because we use <h1> for formatting the
826 :group
'org-export-e-html
835 (defcustom org-e-html-link-org-files-as-html t
836 "Non-nil means make file links to `file.org' point to `file.html'.
837 When org-mode is exporting an org-mode file to HTML, links to
838 non-html files are directly put into a href tag in HTML.
839 However, links to other Org-mode files (recognized by the
840 extension `.org.) should become links to the corresponding html
841 file, assuming that the linked org-mode file will also be
843 When nil, the links still point to the plain `.org' file."
844 :group
'org-export-e-html
852 ;;; User Configurable Variables (MAYBE)
856 (defcustom org-e-html-date-format
858 "Format string for \\date{...}."
859 :group
'org-export-e-html
864 (defcustom org-e-html-format-headline-function nil
865 "Function to format headline text.
867 This function will be called with 5 arguments:
868 TODO the todo keyword \(string or nil\).
869 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
870 PRIORITY the priority of the headline \(integer or nil\)
871 TEXT the main headline text \(string\).
872 TAGS the tags string, separated with colons \(string or nil\).
874 The function result will be used in the section format string.
876 As an example, one could set the variable to the following, in
877 order to reproduce the default set-up:
879 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
880 \"Default format function for an headline.\"
882 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
884 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
886 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
887 :group
'org-export-e-html
893 (defcustom org-e-html-emphasis-alist
894 '(("*" .
"<b>%s</b>")
896 ("_" .
"<span style=\"text-decoration:underline;\">%s</span>")
897 ("+" .
"<del>%s</del>")
898 ("=" .
"<code>%s</code>")
899 ("~" .
"<code>%s</code>"))
900 "Alist of HTML expressions to convert emphasis fontifiers.
902 The key is the character used as a marker for fontification. The
903 value is a formatting string to wrap fontified text with.
905 Value can also be set to the following symbols: `verb' and
906 `protectedtexttt'. For the former, Org will use \"\\verb\" to
907 create a format string and select a delimiter character that
908 isn't in the string. For the latter, Org will use \"\\texttt\"
909 to typeset and try to protect special characters."
910 :group
'org-export-e-html
916 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
917 "Text used to separate footnotes."
918 :group
'org-export-e-html
924 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
925 "A printf format string to be applied to active time-stamps."
926 :group
'org-export-e-html
929 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
930 "A printf format string to be applied to inactive time-stamps."
931 :group
'org-export-e-html
934 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
935 "A printf format string to be applied to diary time-stamps."
936 :group
'org-export-e-html
942 (defcustom org-e-html-image-default-option
"width=.9\\linewidth"
943 "Default option for images."
944 :group
'org-export-e-html
947 (defcustom org-e-html-default-figure-position
"htb"
948 "Default position for latex figures."
949 :group
'org-export-e-html
952 (defcustom org-e-html-inline-image-rules
953 '(("file" .
"\\.\\(pdf\\|jpeg\\|jpg\\|png\\|ps\\|eps\\)\\'"))
954 "Rules characterizing image files that can be inlined into HTML.
956 A rule consists in an association whose key is the type of link
957 to consider, and value is a regexp that will be matched against
960 Note that, by default, the image extension *actually* allowed
961 depend on the way the HTML file is processed. When used with
962 pdflatex, pdf, jpg and png images are OK. When processing
963 through dvi to Postscript, only ps and eps are allowed. The
964 default we use here encompasses both."
965 :group
'org-export-e-html
966 :type
'(alist :key-type
(string :tag
"Type")
967 :value-type
(regexp :tag
"Path")))
971 (defcustom org-e-html-table-caption-above t
972 "When non-nil, place caption string at the beginning of the table.
973 Otherwise, place it near the end."
974 :group
'org-export-e-html
979 (defcustom org-e-html-format-drawer-function nil
980 "Function called to format a drawer in HTML code.
982 The function must accept two parameters:
983 NAME the drawer name, like \"LOGBOOK\"
984 CONTENTS the contents of the drawer.
986 The function should return the string to be exported.
988 For example, the variable could be set to the following function
989 in order to mimic default behaviour:
991 \(defun org-e-html-format-drawer-default \(name contents\)
992 \"Format a drawer element for HTML export.\"
994 :group
'org-export-e-html
1000 (defcustom org-e-html-format-inlinetask-function nil
1001 "Function called to format an inlinetask in HTML code.
1003 The function must accept six parameters:
1004 TODO the todo keyword, as a string
1005 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
1006 PRIORITY the inlinetask priority, as a string
1007 NAME the inlinetask name, as a string.
1008 TAGS the inlinetask tags, as a string.
1009 CONTENTS the contents of the inlinetask, as a string.
1011 The function should return the string to be exported.
1013 For example, the variable could be set to the following function
1014 in order to mimic default behaviour:
1016 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
1017 \"Format an inline task element for HTML export.\"
1018 \(let \(\(full-title
1021 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
1022 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
1024 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
1025 \(format \(concat \"\\\\begin{center}\\n\"
1027 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1029 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1031 \"\\\\end{minipage}}\"
1032 \"\\\\end{center}\"\)
1033 full-title contents\)\)"
1034 :group
'org-export-e-html
1042 (defcustom org-e-html-quotes
1043 '(("fr" ("\\(\\s-\\|[[(]\\)\"" .
"«~") ("\\(\\S-\\)\"" .
"~»") ("\\(\\s-\\|(\\)'" .
"'"))
1044 ("en" ("\\(\\s-\\|[[(]\\)\"" .
"``") ("\\(\\S-\\)\"" .
"''") ("\\(\\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
1054 for allowed characters before/after the quote, the second
1055 string defines the 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'"
1082 org-e-html-link-org-files-as-html
1083 (string= type
"file")
1084 (string-match "\\.org$" path
)
1089 (substring path
0 (match-beginning 0))
1091 (plist-get opt-plist
:html-extension
)))))))
1093 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1096 OPT-PLIST is an options list.
1097 TYPE is the device-type of the link (THIS://foo.html).
1098 PATH is the path of the link (http://THIS#location).
1099 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1100 DESC is the link description, if any.
1101 ATTR is a string of other attributes of the \"a\" element."
1102 (declare (special org-lparse-par-open
))
1104 (when (string= type-1
"coderef")
1105 (let ((ref fragment
))
1106 (setq desc
(format (org-export-get-coderef-format ref
(and descp desc
))
1107 (cdr (assoc ref org-export-code-refs
)))
1108 fragment
(concat "coderef-" ref
)
1109 attr
(format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1110 fragment fragment
))))
1111 (let* ((may-inline-p
1112 (and (member type-1
'("http" "https" "file"))
1113 (org-lparse-should-inline-p path descp
)
1115 (type (if (equal type-1
"id") "file" type-1
))
1117 ;;First pass. Just sanity stuff.
1120 ((string= type
"file")
1123 ;;Substitute just if original path was absolute.
1124 ;;(Otherwise path must remain relative)
1125 (if (file-name-absolute-p path
)
1126 (concat "file://" (expand-file-name path
))
1130 (t (list type path
))))
1132 ;;Second pass. Components converted so they can refer
1136 (and org-e-html-cvt-link-fn
1137 (apply org-e-html-cvt-link-fn
1138 opt-plist components-1
))
1139 (apply #'org-e-html-cvt-org-as-html
1140 opt-plist components-1
)
1142 (type (first components-2
))
1143 (thefile (second components-2
)))
1146 ;;Third pass. Build final link except for leading type
1151 (string= type
"http")
1152 (string= type
"https")
1153 (string= type
"file")
1154 (string= type
"coderef"))
1156 (setq thefile
(concat thefile
"#" fragment
))))
1160 ;;Final URL-build, for all types.
1163 ((str (org-xml-format-href thefile
)))
1164 (if (and type
(not (or (string= "file" type
)
1165 (string= "coderef" type
))))
1166 (concat type
":" str
)
1170 (org-e-html-format-image thefile
)
1172 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1174 (defun org-e-html-format-inline-image (path &optional caption label attr
)
1175 ;; FIXME: alt text missing here?
1176 (let ((inline-image (format "<img src=\"%s\" alt=\"%s\"/>"
1177 path
(file-name-nondirectory path
))))
1178 (if (not label
) inline-image
1179 (org-e-html-format-section inline-image
"figure" label
))))
1181 (defun org-e-html-format-image (src)
1182 "Create image tag with source and attributes."
1184 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1185 (attr (org-find-text-property-in-string 'org-attributes src
))
1186 (label (org-find-text-property-in-string 'org-label src
))
1187 (caption (and caption
(org-xml-encode-org-text caption
)))
1188 (img-extras (if (string-match "^ltxpng/" src
)
1189 (format " alt=\"%s\""
1190 (org-find-text-property-in-string
1191 'org-latex-src src
))
1192 (if (string-match "\\<alt=" (or attr
""))
1194 (concat " " attr
" alt=\"" src
"\""))))
1195 (img (format "<img src=\"%s\"%s />" src img-extras
))
1198 (format "id=\"%s\" " (org-solidify-link-text label
)))
1199 "class=\"figure\"")))
1202 (with-org-lparse-preserve-paragraph-state
1205 '("<div %s>" .
"\n</div>")
1207 (org-lparse-format '("\n<p>" .
"</p>") img
)
1208 (org-lparse-format '("\n<p>" .
"</p>") caption
))
1215 (defun org-e-html-bibliography ()
1216 "Find bibliography, cut it out and return it."
1218 (let (beg end
(cnt 1) bib
)
1220 (goto-char (point-min))
1221 (when (re-search-forward
1222 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1223 (setq beg
(match-beginning 0))
1224 (while (re-search-forward "</?div\\>" nil t
)
1225 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1227 (and (looking-at ">") (forward-char 1))
1228 (setq bib
(buffer-substring beg
(point)))
1229 (delete-region beg
(point))
1230 (throw 'exit bib
))))
1235 (defun org-e-html-format-table (lines olines
)
1236 (let ((org-e-html-format-table-no-css nil
))
1237 (org-lparse-format-table lines olines
)))
1239 (defun org-e-html-splice-attributes (tag attributes
)
1240 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1241 (if (not attributes
)
1243 (let (oldatt newatt
)
1244 (setq oldatt
(org-extract-attributes-from-string tag
)
1246 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1248 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1249 (if (string-match ">" tag
)
1251 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1255 (defun org-export-splice-style (style extra
)
1256 "Splice EXTRA into STYLE, just before \"</style>\"."
1257 (if (and (stringp extra
)
1258 (string-match "\\S-" extra
)
1259 (string-match "</style>" style
))
1260 (concat (substring style
0 (match-beginning 0))
1262 (substring style
(match-beginning 0)))
1265 (defun org-export-e-htmlize-region-for-paste (beg end
)
1266 "Convert the region to HTML, using htmlize.el.
1267 This is much like `htmlize-region-for-paste', only that it uses
1268 the settings define in the org-... variables."
1269 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1270 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1271 (htmlbuf (htmlize-region beg end
)))
1273 (with-current-buffer htmlbuf
1274 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1275 (plist-get htmlize-buffer-places
'content-end
)))
1276 (kill-buffer htmlbuf
))))
1279 (defun org-export-e-htmlize-generate-css ()
1280 "Create the CSS for all font definitions in the current Emacs session.
1281 Use this to create face definitions in your CSS style file that can then
1282 be used by code snippets transformed by htmlize.
1283 This command just produces a buffer that contains class definitions for all
1284 faces used in the current Emacs session. You can copy and paste the ones you
1285 need into your CSS file.
1287 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1288 the function `org-export-e-htmlize-region-for-paste' will produce code
1289 that uses these same face definitions."
1292 (and (get-buffer "*html*") (kill-buffer "*html*"))
1294 (let ((fl (face-list))
1295 (htmlize-css-name-prefix "org-")
1296 (htmlize-output-type 'css
)
1298 (while (setq f
(pop fl
)
1299 i
(and f
(face-attribute f
:inherit
)))
1300 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1301 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1302 (htmlize-region (point-min) (point-max))))
1303 (org-pop-to-buffer-same-window "*html*")
1304 (goto-char (point-min))
1305 (if (re-search-forward "<style" nil t
)
1306 (delete-region (point-min) (match-beginning 0)))
1307 (if (re-search-forward "</style>" nil t
)
1308 (delete-region (1+ (match-end 0)) (point-max)))
1309 (beginning-of-line 1)
1310 (if (looking-at " +") (replace-match ""))
1311 (goto-char (point-min)))
1313 (defun org-e-html-format-toc-entry (snumber todo headline tags href
)
1314 (setq headline
(concat
1316 (and org-export-with-section-numbers
(concat snumber
" "))
1321 " "
1322 (format "<span class=\"tag\">%s</span>" tags
)))))
1323 ;; fontify headline based on TODO keyword
1325 (setq headline
(format "<span class=\"todo\">%s</span>" headline
)))
1326 (format "<a href=\"#%s\">%s</a>" href headline
))
1328 (defun org-e-html-toc-entry-formatter
1329 (level snumber todo todo-type priority
1330 headline tags target extra-targets extra-class
)
1331 (org-e-html-format-toc-entry snumber todo headline tags target
))
1333 (defun org-e-html-make-string (n string
)
1334 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1336 (defun org-e-html-toc-text (toc-entries)
1337 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1338 (start-level prev-level
))
1342 (let ((headline (nth 0 entry
))
1343 (level (nth 1 entry
)))
1345 (let* ((cnt (- level prev-level
))
1346 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1348 (setq prev-level level
)
1350 (org-e-html-make-string
1351 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1352 ((< cnt
0) "</li>\n</ul>\n")))
1353 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1356 (org-e-html-make-string
1357 (- prev-level start-level
) "</li>\n</ul>\n"))))
1359 (defun org-e-html-toc (depth info
)
1360 (assert (wholenump depth
))
1361 (let* ((headlines (org-export-collect-headlines info depth
))
1363 (loop for headline in headlines collect
1364 (list (org-e-html-headline-text
1365 headline info
'org-e-html-toc-entry-formatter
)
1366 (org-export-get-relative-level headline info
)))))
1368 (let* ((lang-specific-heading
1369 (nth 3 (or (assoc (plist-get info
:language
)
1370 org-export-language-setup
)
1371 (assoc "en" org-export-language-setup
)))))
1373 "<div id=\"table-of-contents\">\n"
1374 (format "<h%d>%s</h%d>\n"
1375 org-e-html-toplevel-hlevel
1376 lang-specific-heading
1377 org-e-html-toplevel-hlevel
)
1378 "<div id=\"text-table-of-contents\">"
1379 (org-e-html-toc-text toc-entries
)
1383 ;; (defun org-e-html-format-line (line)
1384 ;; (case org-lparse-dyn-current-environment
1385 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1386 ;; (t (concat line "\n"))))
1388 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1389 "Turn todo keyword into a valid class name.
1390 Replaces invalid characters with \"_\"."
1392 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1393 (setq kwd
(replace-match "_" t t kwd
))))
1396 (defun org-e-html-format-footnote-reference (n def refcnt
)
1397 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1398 (format org-e-html-footnote-format
1400 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1403 (defun org-e-html-format-footnotes-section (section-name definitions
)
1404 (if (not definitions
) ""
1405 (format org-e-html-footnotes-section section-name definitions
)))
1407 (defun org-e-html-format-footnote-definition (fn)
1408 (let ((n (car fn
)) (def (cdr fn
)))
1410 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1412 (format org-e-html-footnote-format
1413 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1416 (defun org-e-html-footnote-section (info)
1417 (let* ((fn-alist (org-export-collect-footnote-definitions
1418 (plist-get info
:parse-tree
) info
))
1421 (loop for
(n type raw
) in fn-alist collect
1422 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1423 (org-trim (org-export-data raw
'e-html info
))
1425 (org-trim (org-export-secondary-string
1426 raw
'e-html info
))))))))
1428 (org-e-html-format-footnotes-section
1429 (nth 4 (or (assoc (plist-get info
:language
)
1430 org-export-language-setup
)
1431 (assoc "en" org-export-language-setup
)))
1433 "<table>\n%s\n</table>\n"
1434 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1436 (defun org-e-html-get-coding-system-for-write ()
1437 (or org-e-html-coding-system
1438 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1440 (defun org-e-html-get-coding-system-for-save ()
1441 (or org-e-html-coding-system
1442 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1444 (defun org-e-html-format-date (info)
1445 (let ((date (plist-get info
:date
)))
1447 ((and date
(string-match "%" date
))
1448 (format-time-string date
))
1450 (t (format-time-string "%Y-%m-%d %T %Z")))))
1454 ;;; Internal Functions (Ngz)
1456 (defun org-e-html--caption/label-string
(caption label info
)
1457 "Return caption and label HTML string for floats.
1459 CAPTION is a cons cell of secondary strings, the car being the
1460 standard caption and the cdr its short form. LABEL is a string
1461 representing the label. INFO is a plist holding contextual
1464 If there's no caption nor label, return the empty string.
1466 For non-floats, see `org-e-html--wrap-label'."
1467 (setq label nil
) ;; FIXME
1469 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1471 ((and (not caption
) (not label
)) "")
1472 ((not caption
) (format "\\label{%s}\n" label
))
1473 ;; Option caption format with short name.
1475 (format "\\caption[%s]{%s%s}\n"
1476 (org-export-secondary-string (cdr caption
) 'e-html info
)
1478 (org-export-secondary-string (car caption
) 'e-html info
)))
1479 ;; Standard caption format.
1480 ;; (t (format "\\caption{%s%s}\n"
1482 ;; (org-export-secondary-string (car caption) 'e-html info)))
1484 (t (org-export-secondary-string (car caption
) 'e-html info
)))))
1486 (defun org-e-html--find-verb-separator (s)
1487 "Return a character not used in string S.
1488 This is used to choose a separator for constructs like \\verb."
1489 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1490 (loop for c across ll
1491 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1492 return
(char-to-string c
))))
1494 (defun org-e-html--make-option-string (options)
1495 "Return a comma separated string of keywords and values.
1496 OPTIONS is an alist where the key is the options keyword as
1497 a string, and the value a list containing the keyword value, or
1499 (mapconcat (lambda (pair)
1500 (concat (first pair
)
1501 (when (> (length (second pair
)) 0)
1502 (concat "=" (second pair
)))))
1506 (defun org-e-html--quotation-marks (text info
)
1507 "Export quotation marks depending on language conventions.
1508 TEXT is a string containing quotation marks to be replaced. INFO
1509 is a plist used as a communication channel."
1512 (while (setq start
(string-match (car l
) text start
))
1513 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1514 (setq text
(replace-match new-quote t t text
))))))
1515 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1516 ;; Falls back on English.
1517 (assoc "en" org-e-html-quotes
))))
1520 (defun org-e-html--wrap-label (element output
)
1521 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1522 This function shouldn't be used for floats. See
1523 `org-e-html--caption/label-string'."
1524 ;; (let ((label (org-element-property :name element)))
1525 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1527 ;; (concat (format "\\label{%s}\n" label) output)))
1534 (defun org-e-html-meta-info (info)
1535 (let* ((title (org-export-secondary-string
1536 (plist-get info
:title
) 'e-html info
))
1537 (author (and (plist-get info
:with-author
)
1538 (let ((auth (plist-get info
:author
)))
1539 (and auth
(org-export-secondary-string
1540 auth
'e-html info
)))))
1541 (description (plist-get info
:description
))
1542 (keywords (plist-get info
:keywords
)))
1544 (format "<title>%s</title>\n" title
)
1546 "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>\n"
1547 (and coding-system-for-write
1548 (fboundp 'coding-system-get
)
1549 (coding-system-get coding-system-for-write
1551 (format "<meta name=\"title\" content=\"%s\"/>\n" title
)
1552 (format "<meta name=\"generator\" content=\"Org-mode\"/>")
1553 (format "<meta name=\"generated\" content=\"%s\"/>\n"
1554 (org-e-html-format-date info
))
1555 (format "<meta name=\"author\" content=\"%s\"/>\n" author
)
1556 (format "<meta name=\"description\" content=\"%s\"/>\n" description
)
1557 (format " <meta name=\"keywords\" content=\"%s\"/>\n" keywords
))))
1559 (defun org-e-html-style (info)
1561 (when (plist-get info
:style-include-default
)
1562 org-e-html-style-default
)
1563 (plist-get info
:style
)
1564 (plist-get info
:style-extra
)
1566 (when (plist-get info
:style-include-scripts
)
1567 org-e-html-scripts
)))
1569 (defun org-e-html-mathjax-config (template options in-buffer
)
1570 "Insert the user setup into the matchjax template."
1571 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1572 (let (name val
(yes " ") (no "// ") x
)
1575 (setq name
(car e
) val
(nth 1 e
))
1576 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1577 (setq val
(car (read-from-string
1578 (substring in-buffer
(match-end 0))))))
1579 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1580 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1581 (setq template
(replace-match val t t template
))))
1583 (setq val
(nth 1 (assq 'mathml options
)))
1584 (if (string-match (concat "\\<mathml:") in-buffer
)
1585 (setq val
(car (read-from-string
1586 (substring in-buffer
(match-end 0))))))
1587 ;; Exchange prefixes depending on mathml setting
1588 (if (not val
) (setq x yes yes no no x
))
1589 ;; Replace cookies to turn on or off the config/jax lines
1590 (if (string-match ":MMLYES:" template
)
1591 (setq template
(replace-match yes t t template
)))
1592 (if (string-match ":MMLNO:" template
)
1593 (setq template
(replace-match no t t template
)))
1594 ;; Return the modified template
1597 (defun org-e-html-preamble (info)
1598 (when (plist-get info
:html-preamble
)
1599 (let* ((title (plist-get info
:title
))
1600 (date (org-e-html-format-date info
))
1601 (author (plist-get info
:author
))
1602 (lang-words (or (assoc (plist-get info
:language
)
1603 org-export-language-setup
)
1604 (assoc "en" org-export-language-setup
)))
1605 (email (plist-get info
:email
))
1606 (html-pre-real-contents
1608 ((functionp (plist-get info
:html-preamble
))
1610 (funcall (plist-get info
:html-preamble
))
1612 ((stringp (plist-get info
:html-preamble
))
1613 (format-spec (plist-get info
:html-preamble
)
1614 `((?t .
,title
) (?a .
,author
)
1615 (?d .
,date
) (?e .
,email
))))
1618 (or (cadr (assoc (nth 0 lang-words
)
1619 org-e-html-preamble-format
))
1620 (cadr (assoc "en" org-e-html-preamble-format
)))
1621 `((?t .
,title
) (?a .
,author
)
1622 (?d .
,date
) (?e .
,email
)))))))
1623 (when (not (equal html-pre-real-contents
""))
1626 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1629 html-pre-real-contents
1633 (defun org-e-html-postamble (info)
1635 (when (and (not body-only
)
1636 (plist-get info
:html-postamble
))
1637 (let* ((html-post (plist-get info
:html-postamble
))
1638 (date (org-e-html-format-date info
))
1639 (author (plist-get info
:author
))
1640 (email (plist-get info
:email
))
1641 (lang-words (or (assoc (plist-get info
:language
)
1642 org-export-language-setup
)
1643 (assoc "en" org-export-language-setup
)))
1645 (mapconcat (lambda(e)
1646 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1647 (split-string email
",+ *")
1649 (html-validation-link (or org-e-html-validation-link
""))
1651 (concat "Org version " org-version
" with Emacs version "
1652 (number-to-string emacs-major-version
))))
1656 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1659 ((eq (plist-get info
:html-postamble
) 'auto
)
1661 (when (plist-get info
:time-stamp-file
)
1663 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1664 (when (and (plist-get info
:with-author
) author
)
1666 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1667 (when (and (plist-get info
:with-email
) email
)
1669 <p class=\"email\"> %s </p>" email
))
1670 (when (plist-get info
:with-creator
)
1672 <p class=\"creator\"> %s </p>" creator-info
))
1673 html-validation-link
"\n"))
1674 ;; postamble from a string
1675 ((stringp (plist-get info
:html-postamble
))
1676 (format-spec (plist-get info
:html-postamble
)
1677 `((?a .
,author
) (?e .
,email
)
1678 (?d .
,date
) (?c .
,creator-info
)
1679 (?v .
,html-validation-link
))))
1681 ;; postamble from a function
1682 ((functionp (plist-get info
:html-postamble
))
1684 (funcall (plist-get info
:html-postamble
))
1686 ;; default postamble
1689 (or (cadr (assoc (nth 0 lang-words
)
1690 org-e-html-postamble-format
))
1691 (cadr (assoc "en" org-e-html-postamble-format
)))
1692 `((?a .
,author
) (?e .
,email
)
1693 (?d .
,date
) (?c .
,creator-info
)
1694 (?v .
,html-validation-link
)))))
1697 ;; org-e-html-html-helper-timestamp
1700 (defun org-e-html-template (contents info
)
1701 "Return complete document string after HTML conversion.
1702 CONTENTS is the transcoded contents string. RAW-DATA is the
1703 original parsed data. INFO is a plist holding export options."
1706 (or (and (stringp org-e-html-xml-declaration
)
1707 org-e-html-xml-declaration
)
1708 (cdr (assoc (plist-get info
:html-extension
)
1709 org-e-html-xml-declaration
))
1710 (cdr (assoc "html" org-e-html-xml-declaration
))
1713 (or (and coding-system-for-write
1714 (fboundp 'coding-system-get
)
1715 (coding-system-get coding-system-for-write
1719 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1720 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1722 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1723 (plist-get info
:language
) (plist-get info
:language
))
1726 (org-e-html-meta-info info
) ; meta
1727 (org-e-html-style info
) ; style
1728 (org-e-html-mathjax-config ; mathjax
1729 org-e-html-mathjax-template org-e-html-mathjax-options
1730 (or (plist-get info
:mathjax
) ""))
1736 (let ((link-up (and (plist-get info
:link-up
)
1737 (string-match "\\S-" (plist-get info
:link-up
))
1738 (plist-get info
:link-up
)))
1739 (link-home (and (plist-get info
:link-home
)
1740 (string-match "\\S-" (plist-get info
:link-home
))
1741 (plist-get info
:link-home
))))
1742 (when (or link-up link-home
)
1743 (format org-e-html-home
/up-format
1744 (or link-up link-home
)
1745 (or link-home link-up
))))
1747 (org-e-html-preamble info
)
1750 <div id=\"%s\">" (or org-e-html-content-div
1751 (nth 1 org-e-html-divs
)))
1754 <h1 class=\"title\"> %s </h1>\n" (plist-get info
:title
))
1755 ;; table of contents
1756 (let ((depth (plist-get info
:with-toc
)))
1757 (when (wholenump depth
) (org-e-html-toc depth info
)))
1758 ;; document contents
1760 ;; footnotes section
1761 (org-e-html-footnote-section info
)
1763 (org-e-html-bibliography)
1770 (org-e-html-postamble info
)
1780 ;;; Transcode Functions
1784 (defun org-e-html-center-block (center-block contents info
)
1785 "Transcode a CENTER-BLOCK element from Org to HTML.
1786 CONTENTS holds the contents of the block. INFO is a plist
1787 holding contextual information."
1788 (org-e-html--wrap-label
1790 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1795 ;; Comments are ignored.
1800 ;; Comment Blocks are ignored.
1805 (defun org-e-html-drawer (drawer contents info
)
1806 "Transcode a DRAWER element from Org to HTML.
1807 CONTENTS holds the contents of the block. INFO is a plist
1808 holding contextual information."
1809 (let* ((name (org-element-property :drawer-name drawer
))
1810 (output (if (functionp org-e-html-format-drawer-function
)
1811 (funcall org-e-html-format-drawer-function
1813 ;; If there's no user defined function: simply
1814 ;; display contents of the drawer.
1816 (org-e-html--wrap-label drawer output
)))
1821 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1822 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1823 CONTENTS holds the contents of the block. INFO is a plist
1824 holding contextual information. See
1826 (org-e-html--wrap-label dynamic-block contents
))
1831 (defun org-e-html-emphasis (emphasis contents info
)
1832 "Transcode EMPHASIS from Org to HTML.
1833 CONTENTS is the contents of the emphasized text. INFO is a plist
1834 holding contextual information.."
1835 (let* ((marker (org-element-property :marker emphasis
)))
1836 (format (cdr (assoc marker org-e-html-emphasis-alist
)) contents
)))
1841 (defun org-e-html-entity (entity contents info
)
1842 "Transcode an ENTITY object from Org to HTML.
1843 CONTENTS are the definition itself. INFO is a plist holding
1844 contextual information."
1845 ;; (let ((ent (org-element-property :latex entity)))
1846 ;; (if (org-element-property :latex-math-p entity)
1847 ;; (format "$%s$" ent)
1849 (org-element-property :html entity
))
1855 ;; (defun org-odt-format-source-code-or-example-colored
1856 ;; (lines lang caption textareap cols rows num cont rpllbl fmt))
1858 (defun org-e-html-format-source-line-with-line-number-and-label (line)
1859 (let ((ref (org-find-text-property-in-string 'org-coderef line
))
1860 (num (org-find-text-property-in-string 'org-loc line
)))
1862 (setq line
(format "<span class=\"linenr\">%d: </span>%s (%s)"
1867 "<span id=\"coderef-%s\" class=\"coderef-off\">%s (%s)</span>"
1871 (defun org-e-html-format-source-code-or-example-plain
1872 (lines lang caption textareap cols rows num cont rpllbl fmt
)
1874 "\n<pre class=\"example\">\n%s\n</pre>"
1877 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\">%s\n</textarea>\n</p>\n"
1881 (org-e-html-format-source-line-with-line-number-and-label
1882 (org-e-html-encode-plain-text line
)))
1883 (org-split-string lines
"\n")
1886 (defun org-e-html-format-source-code-or-example-colored
1887 (lines lang caption textareap cols rows num cont rpllbl fmt
)
1888 (let* ((lang-m (when lang
1889 (or (cdr (assoc lang org-src-lang-modes
))
1891 (mode (and lang-m
(intern
1893 (if (symbolp lang-m
)
1894 (symbol-name lang-m
)
1897 (org-inhibit-startup t
)
1898 (org-startup-folded nil
))
1902 (if (functionp mode
)
1905 (font-lock-fontify-buffer)
1906 ;; markup each line separately
1907 (org-remove-formatting-on-newlines-in-region
1908 (point-min) (point-max))
1910 (set-buffer-modified-p nil
)
1911 (org-export-e-htmlize-region-for-paste
1912 (point-min) (point-max))))
1914 (when (string-match "<pre\\([^>]*\\)>\n*" lines
)
1915 (setq lines
(replace-match
1916 (format "<pre class=\"src src-%s\">\n" lang
) t t lines
)))
1921 "<div class=\"org-src-container\">"
1922 (format "<label class=\"org-src-name\">%s</label>" caption
)
1929 (org-e-html-format-source-line-with-line-number-and-label line
))
1930 (org-split-string lines
"\n") "\n")))
1932 ;; (when (string-match "\\(\\`<[^>]*>\\)\n" lines)
1933 ;; (setq lines (replace-match "\\1" t nil lines)))
1936 (defun org-e-html-format-source-code-or-example
1937 (lang code
&optional opts indent caption
)
1938 "Format CODE from language LANG and return it formatted for export.
1939 The CODE is marked up in `org-export-current-backend' format.
1941 Check if a function by name
1942 \"org-<backend>-format-source-code-or-example\" is bound. If yes,
1943 use it as the custom formatter. Otherwise, use the default
1944 formatter. Default formatters are provided for docbook, html,
1945 latex and ascii backends. For example, use
1946 `org-e-html-format-source-code-or-example' to provide a custom
1947 formatter for export to \"html\".
1949 If LANG is nil, do not add any fontification.
1950 OPTS contains formatting options, like `-n' for triggering numbering lines,
1951 and `+n' for continuing previous numbering.
1952 Code formatting according to language currently only works for HTML.
1953 Numbering lines works for all three major backends (html, latex, and ascii).
1954 INDENT was the original indentation of the block."
1956 (let* ((backend-formatter 'org-e-html-format-source-code-or-example-plain
)
1957 num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt
)
1958 (setq opts
(or opts
"")
1959 num
(string-match "[-+]n\\>" opts
)
1960 cont
(string-match "\\+n\\>" opts
)
1961 rpllbl
(string-match "-r\\>" opts
)
1962 keepp
(string-match "-k\\>" opts
)
1963 textareap
(string-match "-t\\>" opts
)
1964 preserve-indentp
(or org-src-preserve-indentation
1965 (string-match "-i\\>" opts
))
1966 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
1967 (string-to-number (match-string 1 opts
))
1969 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
1970 (string-to-number (match-string 1 opts
))
1971 (org-count-lines code
))
1972 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
1973 (match-string 1 opts
)))
1974 (when (and textareap
1975 ;; (eq org-export-current-backend 'html)
1977 ;; we cannot use numbering or highlighting.
1978 (setq num nil cont nil lang nil
))
1979 (if keepp
(setq rpllbl
'keep
))
1980 (setq rtn
(if preserve-indentp code
(org-remove-indentation code
)))
1981 (when (string-match "^," rtn
)
1982 (setq rtn
(with-temp-buffer
1984 ;; Free up the protected lines
1985 (goto-char (point-min))
1986 (while (re-search-forward "^," nil t
)
1987 (if (or (equal lang
"org")
1989 (looking-at "\\([*#]\\|[ \t]*#\\+\\)")))
1994 (if (featurep 'xemacs
)
1996 (require 'htmlize nil t
)))
1998 (setq backend-formatter
2000 ((fboundp 'htmlize-region-for-paste
)
2001 'org-e-html-format-source-code-or-example-colored
)
2004 "htmlize.el 1.34 or later is needed for source code formatting")
2005 'org-e-html-format-source-code-or-example-plain
)))
2006 (funcall backend-formatter rtn lang caption textareap cols rows
2007 num cont rpllbl fmt
))))
2009 (defun org-e-html-example-block (example-block contents info
)
2010 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
2011 CONTENTS is nil. INFO is a plist holding contextual information."
2012 (let* ((options (or (org-element-property :options example-block
) ""))
2013 (value (org-export-handle-code example-block info nil nil t
)))
2014 ;; (org-e-html--wrap-label
2015 ;; example-block (format "\\begin{verbatim}\n%s\\end{verbatim}" value))
2016 (org-e-html--wrap-label
2017 example-block
(org-e-html-format-source-code-or-example nil value
))))
2022 (defun org-e-html-export-snippet (export-snippet contents info
)
2023 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2024 CONTENTS is nil. INFO is a plist holding contextual information."
2025 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
2026 (org-element-property :value export-snippet
)))
2031 (defun org-e-html-export-block (export-block contents info
)
2032 "Transcode a EXPORT-BLOCK element from Org to HTML.
2033 CONTENTS is nil. INFO is a plist holding contextual information."
2034 (when (string= (org-element-property :type export-block
) "latex")
2035 (org-remove-indentation (org-element-property :value export-block
))))
2040 (defun org-e-html-fixed-width (fixed-width contents info
)
2041 "Transcode a FIXED-WIDTH element from Org to HTML.
2042 CONTENTS is nil. INFO is a plist holding contextual information."
2043 (let* ((value (org-element-normalize-string
2044 (replace-regexp-in-string
2046 (org-element-property :value fixed-width
)))))
2047 (org-e-html--wrap-label
2048 fixed-width
(org-e-html-format-source-code-or-example nil value
))))
2051 ;;;; Footnote Definition
2053 ;; Footnote Definitions are ignored.
2056 ;;;; Footnote Reference
2058 (defun org-e-html-footnote-reference (footnote-reference contents info
)
2059 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2060 CONTENTS is nil. INFO is a plist holding contextual information."
2062 ;; Insert separator between two footnotes in a row.
2063 (let ((prev (org-export-get-previous-element footnote-reference info
)))
2064 (when (and (listp prev
) (eq (car prev
) 'footnote-reference
))
2065 org-e-html-footnote-separator
))
2067 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2068 (org-e-html-format-footnote-reference
2069 (org-export-get-footnote-number footnote-reference info
)
2071 ;; Inline definitions are secondary strings.
2072 ((eq (org-element-property :type footnote-reference
) 'inline
)
2073 (org-e-html-format-footnote-reference
2074 (org-export-get-footnote-number footnote-reference info
)
2076 ;; Non-inline footnotes definitions are full Org data.
2077 (t (org-e-html-format-footnote-reference
2078 (org-export-get-footnote-number footnote-reference info
)
2084 (defun org-e-html-todo (todo)
2086 (format "<span class=\"%s %s%s\">%s</span>"
2087 (if (member todo org-done-keywords
) "done" "todo")
2088 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
2091 (defun org-e-html-headline-text (headline info
&optional formatter
)
2092 "Transcode an HEADLINE element from Org to HTML.
2093 CONTENTS holds the contents of the headline. INFO is a plist
2094 holding contextual information."
2095 (let* ((numberedp (plist-get info
:section-numbers
))
2096 (level (org-export-get-relative-level headline info
))
2097 (todo (and (plist-get info
:with-todo-keywords
)
2098 (let ((todo (org-element-property
2099 :todo-keyword headline
)))
2101 (org-export-secondary-string todo
'e-html info
)))))
2102 (todo-type (and todo
(org-element-property :todo-type headline
)))
2103 (priority (and (plist-get info
:with-priority
)
2104 (org-element-property :priority headline
)))
2105 (text (org-export-secondary-string
2106 (org-element-property :title headline
) 'e-html info
))
2107 (tags (and (plist-get info
:with-tags
)
2108 (org-element-property :tags headline
)))
2110 (headline-no (org-export-get-headline-number headline info
))
2112 (format "sec-%s" (mapconcat 'number-to-string headline-no
"-")))
2113 (headline-labels (list headline-label
))
2114 (headline-no (org-export-get-headline-number headline info
))
2115 (section-no (mapconcat 'number-to-string headline-no
"."))
2116 (primary-target (car (last headline-labels
)))
2117 (secondary-targets (butlast headline-labels
))
2119 (formatter (or (and (functionp formatter
) formatter
)
2120 org-e-html-headline-formatter
)))
2121 (funcall formatter level section-no todo todo-type priority
2122 text tags primary-target secondary-targets extra-class
)))
2124 (defun org-e-html-headline (headline contents info
)
2125 "Transcode an HEADLINE element from Org to HTML.
2126 CONTENTS holds the contents of the headline. INFO is a plist
2127 holding contextual information."
2128 (let* ((class (plist-get info
:latex-class
))
2129 (numberedp (plist-get info
:section-numbers
))
2130 ;; Get level relative to current parsed data.
2131 (level (org-export-get-relative-level headline info
))
2132 ;; (class-sectionning (assoc class org-e-html-classes))
2133 ;; Section formatting will set two placeholders: one for the
2134 ;; title and the other for the contents.
2136 ;; (let ((sec (if (and (symbolp (nth 2 class-sectionning))
2137 ;; (fboundp (nth 2 class-sectionning)))
2138 ;; (funcall (nth 2 class-sectionning) level numberedp)
2139 ;; (nth (1+ level) class-sectionning))))
2141 ;; ;; No section available for that LEVEL.
2143 ;; ;; Section format directly returned by a function.
2144 ;; ((stringp sec) sec)
2145 ;; ;; (numbered-section . unnumbered-section)
2146 ;; ((not (consp (cdr sec)))
2147 ;; (concat (funcall (if numberedp #'car #'cdr) sec) "\n%s"))
2148 ;; ;; (numbered-open numbered-close)
2149 ;; ((= (length sec) 2)
2150 ;; (when numberedp (concat (car sec) "\n%s" (nth 1 sec))))
2151 ;; ;; (num-in num-out no-num-in no-num-out)
2152 ;; ((= (length sec) 4)
2154 ;; (concat (car sec) "\n%s" (nth 1 sec))
2155 ;; (concat (nth 2 sec) "\n%s" (nth 3 sec)))))))
2156 (text (org-export-secondary-string
2157 (org-element-property :title headline
) 'e-html info
))
2158 (todo (and (plist-get info
:with-todo-keywords
)
2159 (let ((todo (org-element-property
2160 :todo-keyword headline
)))
2162 (org-export-secondary-string todo
'e-html info
)))))
2163 (todo-type (and todo
(org-element-property :todo-type headline
)))
2164 (tags (and (plist-get info
:with-tags
)
2165 (org-element-property :tags headline
)))
2166 (priority (and (plist-get info
:with-priority
)
2167 (org-element-property :priority headline
)))
2168 ;; Create the headline text.
2169 (full-text (if (functionp org-e-html-format-headline-function
)
2170 ;; User-defined formatting function.
2171 (funcall org-e-html-format-headline-function
2172 todo todo-type priority text tags
)
2173 ;; Default formatting.
2176 ;; (format "\\textbf{\\textsf{\\textsc{%s}}} " todo))
2177 (org-e-html-todo todo
) " "
2178 (when priority
(format "\\framebox{\\#%c} " priority
))
2180 ;; (when tags (format "\\hfill{}\\textsc{%s}" tags))
2182 ;; Associate some \label to the headline for internal links.
2184 ;; (format "\\label{sec-%s}\n"
2185 ;; (mapconcat 'number-to-string
2186 ;; (org-export-get-headline-number headline info)
2190 (headline-no (org-export-get-headline-number headline info
))
2192 (format "sec-%s" (mapconcat 'number-to-string headline-no
"-")))
2193 (headline-labels (list headline-label
))
2194 (headline-no (org-export-get-headline-number headline info
))
2195 (section-no (mapconcat 'number-to-string headline-no
"."))
2198 (pre-blanks (make-string
2199 (org-element-property :pre-blank headline
) 10)))
2201 ;; Case 1: This is a footnote section: ignore it.
2202 ((org-element-property :footnote-section-p headline
) nil
)
2203 ;; Case 2. This is a deep sub-tree: export it as a list item.
2204 ;; Also export as items headlines for which no section
2205 ;; format has been found.
2206 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2207 ;; Build the real contents of the sub-tree.
2208 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2209 (itemized-body (org-e-html-format-list-item
2210 contents type nil nil full-text
)))
2212 (and (org-export-first-sibling-p headline info
)
2213 (org-e-html-begin-plain-list type
))
2215 (and (org-export-last-sibling-p headline info
)
2216 (org-e-html-end-plain-list type
)))))
2217 ;; Case 3. Standard headline. Export it as a section.
2219 ;; (format section-fmt full-text
2220 ;; (concat headline-label pre-blanks contents))
2221 (let* ((extra-class nil
) ; FIXME
2222 (extra-ids nil
) ; FIXME
2223 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2230 (let ((id (org-solidify-link-text
2231 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2232 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2235 (and (plist-get info
:section-numbers
)
2236 (format "<span class=\"section-number-%d\">%s</span> "
2237 level1
(mapconcat 'number-to-string headline-no
2242 (and (plist-get info
:with-tags
) tags
2244 " "
2245 (format "<span class=\"tag\">%s</span>"
2248 (format "<span class=\"%s\">%s</span>"
2249 (concat org-e-html-tag-class-prefix
2250 (org-e-html-fix-class-name tag
))
2252 (org-split-string tags
":") " "))))))
2253 (id (mapconcat 'number-to-string headline-no
"-")))
2254 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2255 (format "outline-container-%s" id
)
2256 (concat (format "outline-%d" level1
) (and extra-class
" ")
2258 (format "\n<h%d id=\"sec-%s\">%s</h%d>\n" level1 id title level1
)
2262 ;;;; Horizontal Rule
2264 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2265 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2266 CONTENTS is nil. INFO is a plist holding contextual information."
2267 (let ((attr (mapconcat #'identity
2268 (org-element-property :attr_html horizontal-rule
)
2270 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2273 ;;;; Inline Babel Call
2275 ;; Inline Babel Calls are ignored.
2278 ;;;; Inline Src Block
2280 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2281 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2282 CONTENTS holds the contents of the item. INFO is a plist holding
2283 contextual information."
2284 (let* ((org-lang (org-element-property :language inline-src-block
))
2285 (code (org-element-property :value inline-src-block
))
2286 (separator (org-e-html--find-verb-separator code
)))
2292 (defun org-e-html-format-section (text class
&optional id
)
2293 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2294 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2296 (defun org-e-html-inlinetask (inlinetask contents info
)
2297 "Transcode an INLINETASK element from Org to HTML.
2298 CONTENTS holds the contents of the block. INFO is a plist
2299 holding contextual information."
2300 (let ((title (org-export-secondary-string
2301 (org-element-property :title inlinetask
) 'e-html info
))
2302 (todo (and (plist-get info
:with-todo-keywords
)
2303 (let ((todo (org-element-property
2304 :todo-keyword inlinetask
)))
2306 (org-export-secondary-string todo
'e-html info
)))))
2307 (todo-type (org-element-property :todo-type inlinetask
))
2308 (tags (and (plist-get info
:with-tags
)
2309 (org-element-property :tags inlinetask
)))
2310 (priority (and (plist-get info
:with-priority
)
2311 (org-element-property :priority inlinetask
))))
2312 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2313 ;; with appropriate arguments.
2314 (if (functionp org-e-html-format-inlinetask-function
)
2315 (funcall org-e-html-format-inlinetask-function
2316 todo todo-type priority title tags contents
)
2317 ;; Otherwise, use a default template.
2318 (org-e-html--wrap-label
2322 (when todo
(format "\\textbf{\\textsf{\\textsc{%s}}} " todo
))
2323 (when priority
(format "\\framebox{\\#%c} " priority
))
2325 (when tags
(format "\\hfill{}\\textsc{%s}" tags
)))))
2326 (format (concat "\\begin{center}\n"
2328 "\\begin{minipage}[c]{.6\\textwidth}\n"
2330 "\\rule[.8em]{\\textwidth}{2pt}\n\n"
2335 full-title contents
))))))
2340 (defun org-e-html-checkbox (checkbox)
2341 (case checkbox
(on "<code>[X]</code>")
2342 (off "<code>[ ]</code>")
2343 (trans "<code>[-]</code>")
2346 (defun org-e-html-format-list-item (contents type checkbox
2347 &optional term-counter-id
2352 (let* ((counter term-counter-id
)
2353 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2354 (format "<li%s>" extra
)))
2356 (let* ((id term-counter-id
)
2357 (extra (if id
(format " id=\"%s\"" id
) "")))
2359 (format "<li%s>" extra
)
2360 (when headline
(concat headline
"<br/>")))))
2362 (let* ((term term-counter-id
))
2363 (setq term
(or term
"(no term)"))
2364 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2365 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2370 (descriptive "</dd>"))))
2372 (defun org-e-html-item (item contents info
)
2373 "Transcode an ITEM element from Org to HTML.
2374 CONTENTS holds the contents of the item. INFO is a plist holding
2375 contextual information."
2376 ;; Grab `:level' from plain-list properties, which is always the
2377 ;; first element above current item.
2378 (let* ((plain-list (org-export-get-parent item info
))
2379 (type (org-element-property :type plain-list
))
2380 (level (org-element-property :level plain-list
))
2381 (counter (org-element-property :counter item
))
2382 (checkbox (org-element-property :checkbox item
))
2383 (tag (let ((tag (org-element-property :tag item
)))
2384 (and tag
(org-export-secondary-string tag
'e-html info
)))))
2385 (org-e-html-format-list-item
2386 contents type checkbox
(or tag counter
))))
2391 (defun org-e-html-keyword (keyword contents info
)
2392 "Transcode a KEYWORD element from Org to HTML.
2393 CONTENTS is nil. INFO is a plist holding contextual information."
2394 (let ((key (downcase (org-element-property :key keyword
)))
2395 (value (org-element-property :value keyword
)))
2397 ((string= key
"latex") value
)
2398 ((string= key
"index") (format "\\index{%s}" value
))
2399 ((string= key
"target")
2400 (format "\\label{%s}" (org-export-solidify-link-text value
)))
2401 ((string= key
"toc")
2402 (let ((value (downcase value
)))
2404 ((string-match "\\<headlines\\>" value
)
2405 (let ((depth (or (and (string-match "[0-9]+" value
)
2406 (string-to-number (match-string 0 value
)))
2407 (plist-get info
:with-toc
))))
2408 (when (wholenump depth
) (org-e-html-toc depth info
))))
2409 ((string= "tables" value
) "\\listoftables")
2410 ((string= "figures" value
) "\\listoffigures")
2411 ((string= "listings" value
)
2413 ;; At the moment, src blocks with a caption are wrapped
2414 ;; into a figure environment.
2415 (t "\\listoffigures")))))))))
2418 ;;;; Latex Environment
2420 (defun org-e-html-format-latex (latex-frag processing-type
)
2421 (let* ((cache-relpath
2422 (concat "ltxpng/" (file-name-sans-extension
2423 (file-name-nondirectory (buffer-file-name)))))
2424 (cache-dir (file-name-directory (buffer-file-name )))
2425 (display-msg "Creating LaTeX Image..."))
2429 (org-format-latex cache-relpath cache-dir nil display-msg
2430 nil nil processing-type
)
2433 (defun org-e-html-latex-environment (latex-environment contents info
)
2434 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2435 CONTENTS is nil. INFO is a plist holding contextual information."
2436 (org-e-html--wrap-label
2439 (org-remove-indentation
2440 (org-element-property :value latex-environment
)))
2441 (processing-type (plist-get info
:LaTeX-fragments
)))
2443 ((member processing-type
'(t mathjax
))
2444 (org-e-html-format-latex latex-frag
'mathjax
))
2445 ((equal processing-type
'dvipng
)
2446 (let* ((formula-link (org-e-html-format-latex
2447 latex-frag processing-type
)))
2448 (when (and formula-link
2449 (string-match "file:\\([^]]*\\)" formula-link
))
2450 (org-e-html-format-inline-image (match-string 1 formula-link
)))))
2457 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2458 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2459 CONTENTS is nil. INFO is a plist holding contextual information."
2460 ;; (org-element-property :value latex-fragment)
2461 (let* ((latex-frag (org-element-property :value latex-fragment
)))
2463 ((string-match "\\\\ref{\\([^{}\n]+\\)}" latex-frag
)
2464 (let* ((label (match-string 1 latex-frag
))
2465 (href (and label
(org-export-solidify-link-text label
)))
2466 (text (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
2467 (substring label
(match-beginning 1))
2469 (format "<a href=\"#%s\">%s</a>" href text
)))
2470 (t (let ((processing-type (plist-get info
:LaTeX-fragments
)))
2472 ((member processing-type
'(t mathjax
))
2473 (org-e-html-format-latex latex-frag
'mathjax
))
2474 ((equal processing-type
'dvipng
)
2475 (let* ((formula-link (org-e-html-format-latex
2476 latex-frag processing-type
)))
2477 (when (and formula-link
2478 (string-match "file:\\([^]]*\\)" formula-link
))
2479 (org-e-html-format-inline-image
2480 (match-string 1 formula-link
)))))
2481 (t latex-frag
)))))))
2486 (defun org-e-html-line-break (line-break contents info
)
2487 "Transcode a LINE-BREAK object from Org to HTML.
2488 CONTENTS is nil. INFO is a plist holding contextual information."
2494 (defun org-e-html-link--inline-image (link info
)
2495 "Return HTML code for an inline image.
2496 LINK is the link pointing to the inline image. INFO is a plist
2497 used as a communication channel."
2498 (let* ((parent (org-export-get-parent-paragraph link info
))
2499 (path (let ((raw-path (org-element-property :path link
)))
2500 (if (not (file-name-absolute-p raw-path
)) raw-path
2501 (expand-file-name raw-path
))))
2502 (caption (org-e-html--caption/label-string
2503 (org-element-property :caption parent
)
2504 (org-element-property :name parent
)
2506 (label (org-element-property :name parent
))
2507 ;; Retrieve latex attributes from the element around.
2508 (attr (let ((raw-attr
2509 (mapconcat #'identity
2510 (org-element-property :attr_html parent
)
2512 (unless (string= raw-attr
"") raw-attr
))))
2513 ;; Now clear ATTR from any special keyword and set a default
2514 ;; value if nothing is left.
2515 (setq attr
(if (not attr
) "" (org-trim attr
)))
2516 ;; Return proper string, depending on DISPOSITION.
2517 (let ((href (and label
(org-export-solidify-link-text label
))))
2518 (org-e-html-format-inline-image path caption href attr
))))
2520 (defun org-e-html-link (link desc info
)
2521 "Transcode a LINK object from Org to HTML.
2523 DESC is the description part of the link, or the empty string.
2524 INFO is a plist holding contextual information. See
2526 (let* ((type (org-element-property :type link
))
2527 (raw-path (org-element-property :path link
))
2528 ;; Ensure DESC really exists, or set it to nil.
2529 (desc (and (not (string= desc
"")) desc
))
2530 (imagep (org-export-inline-image-p
2531 link org-e-html-inline-image-rules
))
2533 ((member type
'("http" "https" "ftp" "mailto"))
2534 (concat type
":" raw-path
))
2535 ((string= type
"file")
2536 (when (string-match "\\(.+\\)::.+" raw-path
)
2537 (setq raw-path
(match-string 1 raw-path
)))
2538 (if (file-name-absolute-p raw-path
)
2539 (concat "file://" (expand-file-name raw-path
))
2540 ;; TODO: Not implemented yet. Concat also:
2541 ;; (org-export-directory :HTML info)
2542 (concat "file://" raw-path
)))
2547 (imagep (org-e-html-link--inline-image link info
))
2548 ;; Target or radioed target: replace link with the normalized
2549 ;; custom-id/target name.
2550 ((member type
'("target" "radio"))
2551 (format "<a href=\"#%s\">%s</a>"
2552 (org-export-solidify-link-text path
)
2553 (or desc
(org-export-secondary-string path
'e-html info
))))
2554 ;; Links pointing to an headline: Find destination and build
2555 ;; appropriate referencing commanding.
2556 ((member type
'("custom-id" "fuzzy" "id"))
2557 (let ((destination (if (string= type
"fuzzy")
2558 (org-export-resolve-fuzzy-link link info
)
2559 (org-export-resolve-id-link link info
))))
2560 ;; Fuzzy link points to a target. Do as above.
2561 (case (org-element-type destination
)
2563 (format "<a href=\"#%s\">%s</a>"
2564 (org-export-solidify-link-text (org-element-property
2565 :raw-value destination
))
2566 (or desc
(org-export-secondary-string
2567 (org-element-property :raw-link link
)
2569 ;; Fuzzy link points to an headline. If headlines are
2570 ;; numbered and the link has no description, display
2571 ;; headline's number. Otherwise, display description or
2572 ;; headline's title.
2578 (org-export-get-headline-number destination info
)
2580 (if (and (plist-get info
:section-numbers
) (not desc
))
2581 (format "\\ref{%s}" label
)
2582 (format "<a href=\"#%s\">%s</a>"
2584 (org-export-secondary-string
2585 (org-element-property :title destination
)
2587 ;; Fuzzy link points nowhere.
2589 (format "<i>%s</i>" (or desc
(org-export-secondary-string
2590 (org-element-property :raw-link link
)
2592 ;; Coderef: replace link with the reference name or the
2593 ;; equivalent line number.
2594 ((string= type
"coderef")
2595 (let ((fragment (concat "coderef-" path
)))
2596 (format "<a href=#%s %s>%s</a>" fragment
2597 (format (concat "class=\"coderef\""
2598 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2599 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2601 (format (org-export-get-coderef-format path
(or desc
"%s"))
2602 (org-export-resolve-coderef path info
)))))
2603 ;; Link type is handled by a special function.
2604 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2605 (funcall protocol
(org-link-unescape path
) desc
'html
))
2606 ;; External link with a description part.
2607 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2608 ;; External link without a description part.
2609 (path (format "<a href=\"%s\">%s</a>" path path
))
2610 ;; No path, only description. Try to do something useful.
2611 (t (format "<i>%s</i>" desc
)))))
2616 ;; Babel Calls are ignored.
2621 (defun org-e-html-macro (macro contents info
)
2622 "Transcode a MACRO element from Org to HTML.
2623 CONTENTS is nil. INFO is a plist holding contextual information."
2624 ;; Use available tools.
2625 (org-export-expand-macro macro info
))
2630 (defun org-e-html-paragraph (paragraph contents info
)
2631 "Transcode a PARAGRAPH element from Org to HTML.
2632 CONTENTS is the contents of the paragraph, as a string. INFO is
2633 the plist used as a communication channel."
2634 (let* ((style nil
) ; FIXME
2635 (class (cdr (assoc style
'((footnote .
"footnote")
2637 (extra (if class
(format " class=\"%s\"" class
) ""))
2638 (parent (car (org-export-get-genealogy paragraph info
))))
2640 ((and (equal (car parent
) 'item
)
2641 (= (org-element-property :begin paragraph
)
2642 (org-element-property :contents-begin parent
)))
2643 ;; leading paragraph in a list item have no tags
2645 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2650 (defun org-e-html-begin-plain-list (type &optional arg1
)
2653 (format "<ol%s>" (if arg1
; FIXME
2654 (format " start=\"%d\"" arg1
)
2657 (descriptive "<dl>")))
2659 (defun org-e-html-end-plain-list (type)
2663 (descriptive "</dl>")))
2665 (defun org-e-html-plain-list (plain-list contents info
)
2666 "Transcode a PLAIN-LIST element from Org to HTML.
2667 CONTENTS is the contents of the list. INFO is a plist holding
2668 contextual information."
2669 (let* (arg1 ;; FIXME
2670 (type (org-element-property :type plain-list
))
2671 (attr (mapconcat #'identity
2672 (org-element-property :attr_html plain-list
)
2674 (org-e-html--wrap-label
2675 plain-list
(format "%s\n%s%s"
2676 (org-e-html-begin-plain-list type
)
2677 contents
(org-e-html-end-plain-list type
)))))
2681 (defun org-e-html-convert-special-strings (string)
2682 "Convert special characters in STRING to HTML."
2683 (let ((all org-e-html-special-string-regexps
)
2685 (while (setq a
(pop all
))
2686 (setq re
(car a
) rpl
(cdr a
) start
0)
2687 (while (string-match re string start
)
2688 (setq string
(replace-match rpl t nil string
))))
2691 (defun org-e-html-encode-plain-text (s)
2692 "Convert plain text characters to HTML equivalent.
2693 Possible conversions are set in `org-export-html-protect-char-alist'."
2694 (let ((cl org-e-html-protect-char-alist
) c
)
2695 (while (setq c
(pop cl
))
2697 (while (string-match (car c
) s start
)
2698 (setq s
(replace-match (cdr c
) t t s
)
2699 start
(1+ (match-beginning 0))))))
2702 (defun org-e-html-plain-text (text info
)
2703 "Transcode a TEXT string from Org to HTML.
2704 TEXT is the string to transcode. INFO is a plist holding
2705 contextual information."
2706 (setq text
(org-e-html-encode-plain-text text
))
2707 ;; Protect %, #, &, $, ~, ^, _, { and }.
2708 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2710 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2712 ;; (setq text (replace-regexp-in-string
2713 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2714 ;; "$\\backslash$" text nil t 1))
2715 ;; HTML into \HTML{} and TeX into \TeX{}.
2716 ;; (let ((case-fold-search nil)
2718 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2719 ;; (setq text (replace-match
2720 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2721 ;; start (match-end 0))))
2722 ;; Handle quotation marks
2723 ;; (setq text (org-e-html--quotation-marks text info))
2724 ;; Convert special strings.
2725 ;; (when (plist-get info :with-special-strings)
2726 ;; (while (string-match (regexp-quote "...") text)
2727 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2728 (when (plist-get info
:with-special-strings
)
2729 (setq text
(org-e-html-convert-special-strings text
)))
2730 ;; Handle break preservation if required.
2731 (when (plist-get info
:preserve-breaks
)
2732 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2738 ;;;; Property Drawer
2740 (defun org-e-html-property-drawer (property-drawer contents info
)
2741 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2742 CONTENTS is nil. INFO is a plist holding contextual
2744 ;; The property drawer isn't exported but we want separating blank
2745 ;; lines nonetheless.
2751 (defun org-e-html-quote-block (quote-block contents info
)
2752 "Transcode a QUOTE-BLOCK element from Org to HTML.
2753 CONTENTS holds the contents of the block. INFO is a plist
2754 holding contextual information."
2755 (org-e-html--wrap-label
2756 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2761 (defun org-e-html-quote-section (quote-section contents info
)
2762 "Transcode a QUOTE-SECTION element from Org to HTML.
2763 CONTENTS is nil. INFO is a plist holding contextual information."
2764 (let ((value (org-remove-indentation
2765 (org-element-property :value quote-section
))))
2766 (when value
(format "<pre>\n%s</pre>" value
))))
2771 (defun org-e-html-section (section contents info
) ; FIXME
2772 "Transcode a SECTION element from Org to HTML.
2773 CONTENTS holds the contents of the section. INFO is a plist
2774 holding contextual information."
2775 (let ((parent (org-export-get-parent-headline section info
)))
2776 ;; Before first headline: no container, just return CONTENTS.
2777 (if (not parent
) contents
2778 ;; Get div's class and id references.
2779 (let ((class-num (+ (org-export-get-relative-level parent info
)
2780 (1- org-e-html-toplevel-hlevel
)))
2784 (org-export-get-headline-number parent info
) "-")))
2785 ;; Build return value.
2786 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2787 class-num id-num contents
)))))
2791 (defun org-e-html-radio-target (radio-target text info
)
2792 "Transcode a RADIO-TARGET object from Org to HTML.
2793 TEXT is the text of the target. INFO is a plist holding
2794 contextual information."
2795 (let ((id (org-export-solidify-link-text
2796 (org-element-property :raw-value radio-target
))))
2797 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2802 (defun org-e-html-special-block (special-block contents info
)
2803 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2804 CONTENTS holds the contents of the block. INFO is a plist
2805 holding contextual information."
2806 (let ((type (downcase (org-element-property :type special-block
))))
2807 (org-e-html--wrap-label
2809 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2814 (defun org-e-html-src-block (src-block contents info
)
2815 "Transcode a SRC-BLOCK element from Org to HTML.
2816 CONTENTS holds the contents of the item. INFO is a plist holding
2817 contextual information."
2818 (let* ((lang (org-element-property :language src-block
))
2819 (code (org-export-handle-code src-block info nil nil t
))
2820 (caption (org-element-property :caption src-block
))
2821 (label (org-element-property :name src-block
)))
2822 ;; FIXME: Handle caption
2824 ;; caption-str (when caption)
2825 ;; (main (org-export-secondary-string (car caption) 'e-html info))
2826 ;; (secondary (org-export-secondary-string (cdr caption) 'e-html info))
2827 ;; (caption-str (org-e-html--caption/label-string caption label info))
2828 (org-e-html-format-source-code-or-example lang code
)))
2831 ;;;; Statistics Cookie
2833 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2834 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2835 CONTENTS is nil. INFO is a plist holding contextual information."
2836 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2837 (format "<code>%s</code>" cookie-value
)))
2842 (defun org-e-html-subscript (subscript contents info
)
2843 "Transcode a SUBSCRIPT object from Org to HTML.
2844 CONTENTS is the contents of the object. INFO is a plist holding
2845 contextual information."
2846 (format "<sub>%s</sub>" contents
))
2851 (defun org-e-html-superscript (superscript contents info
)
2852 "Transcode a SUPERSCRIPT object from Org to HTML.
2853 CONTENTS is the contents of the object. INFO is a plist holding
2854 contextual information."
2855 (format "<sup>%s</sup>" contents
))
2860 (defun org-e-html-begin-table (caption label attributes
)
2861 (let* ((html-table-tag (or (plist-get info
:html-table-tag
) ; FIXME
2862 org-e-html-table-tag
))
2864 (org-e-html-splice-attributes html-table-tag attributes
)))
2866 (setq html-table-tag
2867 (org-e-html-splice-attributes
2869 (format "id=\"%s\"" (org-solidify-link-text label
)))))
2870 (concat "\n" html-table-tag
2871 (format "\n<caption>%s</caption>" (or caption
"")))))
2873 (defun org-e-html-end-table ()
2876 (defun org-e-html-format-table-cell (text r c horiz-span
)
2877 (let ((cell-style-cookie
2878 (if org-e-html-table-align-individual-fields
2879 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2880 org-e-html-format-table-no-css
)
2881 " align=\"%s\"" " class=\"%s\"")
2882 (or (aref (plist-get table-info
:alignment
) c
) "left")) ""))) ;; FIXME
2884 (org-e-html-table-cur-rowgrp-is-hdr
2886 (format (car org-e-html-table-header-tags
) "col" cell-style-cookie
)
2887 text
(cdr org-e-html-table-header-tags
)))
2888 ((and (= c
0) org-e-html-table-use-header-tags-for-first-column
)
2890 (format (car org-e-html-table-header-tags
) "row" cell-style-cookie
)
2891 text
(cdr org-e-html-table-header-tags
)))
2894 (format (car org-e-html-table-data-tags
) cell-style-cookie
)
2895 text
(cdr org-e-html-table-data-tags
))))))
2897 (defun org-e-html-format-table-row (row)
2898 (concat (eval (car org-e-html-table-row-tags
)) row
2899 (eval (cdr org-e-html-table-row-tags
))))
2901 (defun org-e-html-table-row (fields &optional text-for-empty-fields
)
2902 (incf org-e-html-table-rownum
)
2904 (org-e-html-format-table-row
2907 (when (and (string= x
"") text-for-empty-fields
)
2908 (setq x text-for-empty-fields
))
2911 (org-e-html-format-table-cell
2912 x org-e-html-table-rownum i
(or horiz-span
0))))
2915 (defun org-e-html-end-table-rowgroup ()
2916 (when org-e-html-table-rowgrp-open
2917 (setq org-e-html-table-rowgrp-open nil
)
2918 (if org-e-html-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>")))
2920 (defun org-e-html-begin-table-rowgroup (&optional is-header-row
)
2922 (when org-e-html-table-rowgrp-open
2923 (org-e-html-end-table-rowgroup))
2925 (setq org-e-html-table-rowgrp-open t
)
2926 (setq org-e-html-table-cur-rowgrp-is-hdr is-header-row
)
2927 (if is-header-row
"<thead>" "<tbody>"))))
2929 (defun org-e-html-table-preamble ()
2930 (let ((colgroup-vector (plist-get table-info
:column-groups
)) ;; FIXME
2931 c gr colgropen preamble
)
2932 (unless (aref colgroup-vector
0)
2933 (setf (aref colgroup-vector
0) 'start
))
2934 (dotimes (c columns-number preamble
)
2935 (setq gr
(aref colgroup-vector c
))
2939 (when (memq gr
'(start start-end
))
2940 (prog1 (if colgropen
"</colgroup>\n<colgroup>" "\n<colgroup>")
2941 (setq colgropen t
)))
2942 (let* ((colalign-vector (plist-get table-info
:alignment
)) ;; FIXME
2943 (align (cdr (assoc (aref colalign-vector c
)
2946 ("c" .
"center")))))
2947 (alignspec (if (and (boundp 'org-e-html-format-table-no-css
)
2948 org-e-html-format-table-no-css
)
2949 " align=\"%s\"" " class=\"%s\""))
2950 (extra (format alignspec align
)))
2951 (format "<col%s />" extra
))
2952 (when (memq gr
'(end start-end
))
2953 (setq colgropen nil
)
2955 (concat preamble
(if colgropen
"</colgroup>"))))
2957 (defun org-e-html-list-table (lines caption label attributes
)
2958 (setq lines
(org-e-html-org-table-to-list-table lines
))
2959 (let* ((splice nil
) head
2960 (org-e-html-table-rownum -
1)
2963 org-e-html-table-cur-rowgrp-is-hdr
2964 org-e-html-table-rowgrp-open
2966 (org-lparse-table-style 'org-table
)
2967 org-lparse-table-is-styled
)
2970 (setq org-lparse-table-is-styled nil
)
2971 (mapconcat 'org-e-html-table-row lines
"\n"))
2973 (setq org-lparse-table-is-styled t
)
2976 (org-e-html-begin-table caption label attributes
)
2977 (org-e-html-table-preamble)
2978 (org-e-html-begin-table-rowgroup head
)
2983 ((equal line
'hline
) (org-e-html-begin-table-rowgroup))
2984 (t (org-e-html-table-row line
))))
2987 (org-e-html-end-table-rowgroup)
2988 (org-e-html-end-table))))))
2990 (defun org-e-html-transcode-table-row (row)
2991 (if (string-match org-table-hline-regexp row
) 'hline
2994 (org-export-secondary-string
2995 (let ((cell (org-element-parse-secondary-string
2997 (cdr (assq 'table org-element-string-restrictions
)))))
3000 (org-split-string row
"[ \t]*|[ \t]*"))))
3002 (defun org-e-html-org-table-to-list-table (lines &optional splice
)
3003 "Convert org-table to list-table.
3004 LINES is a list of the form (ROW1 ROW2 ROW3 ...) where each
3005 element is a `string' representing a single row of org-table.
3006 Thus each ROW has vertical separators \"|\" separating the table
3007 fields. A ROW could also be a row-group separator of the form
3008 \"|---...|\". Return a list of the form (ROW1 ROW2 ROW3
3009 ...). ROW could either be symbol `'hline' or a list of the
3010 form (FIELD1 FIELD2 FIELD3 ...) as appropriate."
3014 (while (setq line
(pop lines
))
3015 (unless (string-match "^[ \t]*|-" line
)
3016 (push (org-e-html-transcode-table-row line
) lines-1
))))
3017 (t (while (setq line
(pop lines
))
3019 ((string-match "^[ \t]*|-" line
)
3020 (when lines
(push 'hline lines-1
)))
3021 (t (push (org-e-html-transcode-table-row line
) lines-1
))))))
3022 (nreverse lines-1
)))
3024 (defun org-e-html-table-table (raw-table)
3026 (with-current-buffer (get-buffer-create "*org-export-table*")
3028 (let ((output (with-temp-buffer
3031 (re-search-forward "^[ \t]*|[^|]" nil t
)
3032 (table-generate-source 'html
"*org-export-table*")
3033 (with-current-buffer "*org-export-table*"
3034 (org-trim (buffer-string))))))
3035 (kill-buffer (get-buffer "*org-export-table*"))
3038 (defun org-e-html-table (table contents info
)
3039 "Transcode a TABLE element from Org to HTML.
3040 CONTENTS is nil. INFO is a plist holding contextual information."
3041 (let* ((label (org-element-property :name table
))
3042 (caption (org-e-html--caption/label-string
3043 (org-element-property :caption table
) label info
))
3044 (attr (mapconcat #'identity
3045 (org-element-property :attr_html table
)
3047 (raw-table (org-element-property :raw-table table
))
3048 (table-type (org-element-property :type table
)))
3051 (org-e-html-table-table raw-table
))
3053 (let* ((table-info (org-export-table-format-info raw-table
))
3054 (columns-number (length (plist-get table-info
:alignment
)))
3055 (lines (org-split-string
3056 (org-export-clean-table
3057 raw-table
(plist-get table-info
:special-column-p
)) "\n")))
3058 (org-e-html-list-table lines caption label attr
))))))
3063 (defun org-e-html-target (target text info
)
3064 "Transcode a TARGET object from Org to HTML.
3065 TEXT is the text of the target. INFO is a plist holding
3066 contextual information."
3067 (let ((id (org-export-solidify-link-text
3068 (org-element-property :raw-value target
))))
3069 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
3074 (defun org-e-html-time-stamp (time-stamp contents info
)
3075 "Transcode a TIME-STAMP object from Org to HTML.
3076 CONTENTS is nil. INFO is a plist holding contextual
3078 (let ((value (org-element-property :value time-stamp
))
3079 (type (org-element-property :type time-stamp
))
3080 (appt-type (org-element-property :appt-type time-stamp
)))
3081 (setq value
(org-translate-time
3082 (org-export-secondary-string value
'e-html info
)))
3083 (setq appt-type
(case appt-type
3084 (scheduled org-scheduled-string
)
3085 (deadline org-deadline-string
)
3086 (closed org-closed-string
)))
3087 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
3088 (if (not appt-type
) ""
3089 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type
))
3090 (format "<span class=\"timestamp\">%s</span>" value
))))
3095 (defun org-e-html-verbatim (verbatim contents info
)
3096 "Transcode a VERBATIM object from Org to HTML.
3097 CONTENTS is nil. INFO is a plist used as a communication
3099 (org-e-html-emphasis
3100 verbatim
(org-element-property :value verbatim
) info
))
3105 (defun org-e-html-verse-block (verse-block contents info
)
3106 "Transcode a VERSE-BLOCK element from Org to HTML.
3107 CONTENTS is nil. INFO is a plist holding contextual information."
3108 ;; Replace each newline character with line break. Also replace
3109 ;; each blank line with a line break.
3110 (setq contents
(replace-regexp-in-string
3111 "^ *\\\\\\\\$" "<br/>\n"
3112 (replace-regexp-in-string
3113 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n"
3114 (org-remove-indentation
3115 (org-export-secondary-string
3116 (org-element-property :value verse-block
)
3118 ;; Replace each white space at beginning of a line with a
3119 ;; non-breaking space.
3120 (while (string-match "^[ \t]+" contents
)
3121 (let* ((num-ws (length (match-string 0 contents
)))
3122 (ws (let (out) (dotimes (i num-ws out
)
3123 (setq out
(concat out
" "))))))
3124 (setq contents
(replace-match ws nil t contents
))))
3125 (org-e-html--wrap-label
3126 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3131 ;;; Filter Functions
3133 ;;;; Filter Settings
3135 (defconst org-e-html-filters-alist
3136 '((:filter-final-output . org-e-html-final-function
))
3137 "Alist between filters keywords and back-end specific filters.
3138 See `org-export-filters-alist' for more information.")
3143 (defun org-e-html-final-function (contents backend info
)
3144 (if (not org-e-html-pretty-output
) contents
3148 (indent-region (point-min) (point-max))
3149 (buffer-substring-no-properties (point-min) (point-max)))))
3152 ;;; Interactive functions
3154 (defun org-e-html-export-to-html
3155 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3156 "Export current buffer to a HTML file.
3158 If narrowing is active in the current buffer, only export its
3161 If a region is active, export that region.
3163 When optional argument SUBTREEP is non-nil, export the sub-tree
3164 at point, extracting information from the headline properties
3167 When optional argument VISIBLE-ONLY is non-nil, don't export
3168 contents of hidden elements.
3170 When optional argument BODY-ONLY is non-nil, only write code
3171 between \"\\begin{document}\" and \"\\end{document}\".
3173 EXT-PLIST, when provided, is a property list with external
3174 parameters overriding Org default settings, but still inferior to
3175 file-local settings.
3177 When optional argument PUB-DIR is set, use it as the publishing
3180 Return output file's name."
3184 (with-current-buffer (get-buffer-create "*debug*")
3187 (let ((outfile (org-export-output-file-name ".html" subtreep pub-dir
)))
3189 'e-html outfile subtreep visible-only body-only ext-plist
)))
3193 ;;; FIXMES, TODOS, FOR REVIEW etc
3195 ;;;; org-format-table-html
3196 ;;;; org-format-org-table-html
3197 ;;;; org-format-table-table-html
3198 ;;;; org-table-number-fraction
3199 ;;;; org-table-number-regexp
3200 ;;;; org-e-html-table-caption-above
3203 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3204 ;;;; Remove display properties
3205 ;;;; org-e-html-final-hook
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