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.
39 (require 'format-spec
)
40 (eval-when-compile (require 'cl
) (require 'table
))
44 ;;; Function Declarations
46 (declare-function org-id-find-id-file
"org-id" (id))
47 (declare-function htmlize-region
"ext:htmlize" (beg end
))
48 (declare-function org-pop-to-buffer-same-window
49 "org-compat" (&optional buffer-or-name norecord label
))
54 (defvar org-e-html-translate-alist
55 '((babel-call . org-e-html-babel-call
)
56 (bold . org-e-html-bold
)
57 (center-block . org-e-html-center-block
)
58 (clock . org-e-html-clock
)
59 (code . org-e-html-code
)
60 (comment . org-e-html-comment
)
61 (comment-block . org-e-html-comment-block
)
62 (drawer . org-e-html-drawer
)
63 (dynamic-block . org-e-html-dynamic-block
)
64 (entity . org-e-html-entity
)
65 (example-block . org-e-html-example-block
)
66 (export-block . org-e-html-export-block
)
67 (export-snippet . org-e-html-export-snippet
)
68 (fixed-width . org-e-html-fixed-width
)
69 (footnote-definition . org-e-html-footnote-definition
)
70 (footnote-reference . org-e-html-footnote-reference
)
71 (headline . org-e-html-headline
)
72 (horizontal-rule . org-e-html-horizontal-rule
)
73 (inline-babel-call . org-e-html-inline-babel-call
)
74 (inline-src-block . org-e-html-inline-src-block
)
75 (inlinetask . org-e-html-inlinetask
)
76 (italic . org-e-html-italic
)
77 (item . org-e-html-item
)
78 (keyword . org-e-html-keyword
)
79 (latex-environment . org-e-html-latex-environment
)
80 (latex-fragment . org-e-html-latex-fragment
)
81 (line-break . org-e-html-line-break
)
82 (link . org-e-html-link
)
83 (macro . org-e-html-macro
)
84 (paragraph . org-e-html-paragraph
)
85 (plain-list . org-e-html-plain-list
)
86 (plain-text . org-e-html-plain-text
)
87 (planning . org-e-html-planning
)
88 (property-drawer . org-e-html-property-drawer
)
89 (quote-block . org-e-html-quote-block
)
90 (quote-section . org-e-html-quote-section
)
91 (radio-target . org-e-html-radio-target
)
92 (section . org-e-html-section
)
93 (special-block . org-e-html-special-block
)
94 (src-block . org-e-html-src-block
)
95 (statistics-cookie . org-e-html-statistics-cookie
)
96 (strike-through . org-e-html-strike-through
)
97 (subscript . org-e-html-subscript
)
98 (superscript . org-e-html-superscript
)
99 (table . org-e-html-table
)
100 (table-cell . org-e-html-table-cell
)
101 (table-row . org-e-html-table-row
)
102 (target . org-e-html-target
)
103 (template . org-e-html-template
)
104 (timestamp . org-e-html-timestamp
)
105 (underline . org-e-html-underline
)
106 (verbatim . org-e-html-verbatim
)
107 (verse-block . org-e-html-verse-block
))
108 "Alist between element or object types and translators.")
110 ;; FIXME (`org-e-html-options-alist'): Prefix KEYWORD and OPTION with
111 ;; "HTML_". Prefix corresponding properties with `:html-". If such a
112 ;; renaming is taken up, some changes will be required in
113 ;; `org-jsinfo.el', I think. So defer renaming for now.
115 (defconst org-e-html-options-alist
116 '((:agenda-style nil nil org-agenda-export-html-style
)
117 (:creator
"CREATOR" nil org-e-html-creator-string
)
118 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
119 ;; (:expand-quoted-html nil "@" org-e-html-expand)
120 (:inline-images nil nil org-e-html-inline-images
)
121 (:link-home
"LINK_HOME" nil org-e-html-link-home
)
122 (:link-up
"LINK_UP" nil org-e-html-link-up
)
123 (:style nil nil org-e-html-style
)
124 (:style-extra
"STYLE" nil org-e-html-style-extra newline
)
125 (:style-include-default nil nil org-e-html-style-include-default
)
126 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
127 ;; (:timestamp nil nil org-e-html-with-timestamp)
128 (:html-extension nil nil org-e-html-extension
)
129 (:html-postamble nil nil org-e-html-postamble
)
130 (:html-preamble nil nil org-e-html-preamble
)
131 (:html-table-tag nil nil org-e-html-table-tag
)
132 (:xml-declaration nil nil org-e-html-xml-declaration
)
133 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
134 (:mathjax
"MATHJAX" nil
"" space
))
135 "Alist between HTML export properties and ways to set them.
136 This variable is the HTML-specific counterpart of
137 `org-export-options-alist'.
139 The CAR of the alist is the property name, and the CDR is a list
140 like (KEYWORD OPTION DEFAULT BEHAVIOUR) where:
142 KEYWORD is a string representing a buffer keyword, or nil.
143 OPTION is a string that could be found in an #+OPTIONS: line.
144 DEFAULT is the default value for the property.
145 BEHAVIOUR determine how Org should handle multiple keywords for
146 the same property. It is a symbol among:
147 nil Keep old value and discard the new one.
148 t Replace old value with the new one.
149 `space' Concatenate the values, separating them with a space.
150 `newline' Concatenate the values, separating them with
152 `split' Split values at white spaces, and cons them to the
155 KEYWORD and OPTION have precedence over DEFAULT.")
157 (defconst org-e-html-filters-alist
158 '((:filter-final-output . org-e-html-final-function
))
159 "Alist between filters keywords and back-end specific filters.
160 See `org-export-filters-alist' for more information.")
164 ;;; Internal Variables
166 ;; FIXME: it already exists in org-e-html.el
167 (defconst org-e-html-cvt-link-fn
169 "Function to convert link URLs to exportable URLs.
170 Takes two arguments, TYPE and PATH.
171 Returns exportable url as (TYPE PATH), or nil to signal that it
172 didn't handle this case.
173 Intended to be locally bound around a call to `org-export-as-html'." )
178 (defvar org-e-html-format-table-no-css
)
179 (defvar htmlize-buffer-places
) ; from htmlize.el
180 (defvar body-only
) ; dynamically scoped into this.
184 ;;; User Configuration Variables
186 (defgroup org-export-e-html nil
187 "Options for exporting Org mode files to HTML."
188 :tag
"Org Export HTML"
193 (defcustom org-e-html-pretty-output nil
194 "Enable this to generate pretty HTML."
195 :group
'org-export-e-html
200 (defcustom org-e-html-allow-name-attribute-in-anchors t
201 "When nil, do not set \"name\" attribute in anchors.
202 By default, anchors are formatted with both \"id\" and \"name\"
203 attributes, when appropriate."
204 :group
'org-export-e-html
209 (defcustom org-e-html-extension
"html"
210 "The extension for exported HTML files."
211 :group
'org-export-e-html
214 (defcustom org-e-html-xml-declaration
215 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
216 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
217 "The extension for exported HTML files.
218 %s will be replaced with the charset of the exported file.
219 This may be a string, or an alist with export extensions
220 and corresponding declarations."
221 :group
'org-export-e-html
223 (string :tag
"Single declaration")
224 (repeat :tag
"Dependent on extension"
225 (cons (string :tag
"Extension")
226 (string :tag
"Declaration")))))
228 (defcustom org-e-html-coding-system org-export-coding-system
229 "Coding system for HTML export.
230 Use `org-export-coding-system' as the default value."
231 :group
'org-export-e-html
232 :type
'coding-system
)
234 (defvar org-e-html-content-div
"content"
235 "The name of the container DIV that holds all the page contents.
237 This variable is obsolete since Org version 7.7.
238 Please set `org-e-html-divs' instead.")
240 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
241 "The name of the main divs for HTML export.
242 This is a list of three strings, the first one for the preamble
243 DIV, the second one for the content DIV and the third one for the
245 :group
'org-export-e-html
247 (string :tag
" Div for the preamble:")
248 (string :tag
" Div for the content:")
249 (string :tag
"Div for the postamble:")))
252 ;;;; Document Header (Styles)
254 (defconst org-e-html-style-default
255 "<style type=\"text/css\">
256 <!--/*--><![CDATA[/*><!--*/
257 html { font-family: Times, serif; font-size: 12pt; }
258 .title { text-align: center; }
259 .todo { color: red; }
260 .done { color: green; }
261 .tag { background-color: #add8e6; font-weight:normal }
263 .timestamp { color: #bebebe; }
264 .timestamp-kwd { color: #5f9ea0; }
265 .right {margin-left:auto; margin-right:0px; text-align:right;}
266 .left {margin-left:0px; margin-right:auto; text-align:left;}
267 .center {margin-left:auto; margin-right:auto; text-align:center;}
268 p.verse { margin-left: 3% }
270 border: 1pt solid #AEBDCC;
271 background-color: #F3F5F7;
273 font-family: courier, monospace;
277 table { border-collapse: collapse; }
278 td, th { vertical-align: top; }
279 th.right { text-align:center; }
280 th.left { text-align:center; }
281 th.center { text-align:center; }
282 td.right { text-align:right; }
283 td.left { text-align:left; }
284 td.center { text-align:center; }
285 dt { font-weight: bold; }
286 div.figure { padding: 0.5em; }
287 div.figure p { text-align: center; }
290 border:2px solid gray;
294 textarea { overflow-x: auto; }
295 .linenr { font-size:smaller }
296 .code-highlighted {background-color:#ffff00;}
297 .org-info-js_info-navigation { border-style:none; }
298 #org-info-js_console-label { font-size:10px; font-weight:bold;
299 white-space:nowrap; }
300 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
304 "The default style specification for exported HTML files.
305 Please use the variables `org-e-html-style' and
306 `org-e-html-style-extra' to add to this style. If you wish to not
307 have the default style included, customize the variable
308 `org-e-html-style-include-default'.")
310 (defcustom org-e-html-style-include-default t
311 "Non-nil means include the default style in exported HTML files.
312 The actual style is defined in `org-e-html-style-default' and should
313 not be modified. Use the variables `org-e-html-style' to add
314 your own style information."
315 :group
'org-export-e-html
318 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
320 (defcustom org-e-html-style
""
321 "Org-wide style definitions for exported HTML files.
323 This variable needs to contain the full HTML structure to provide a style,
324 including the surrounding HTML tags. If you set the value of this variable,
325 you should consider to include definitions for the following classes:
326 title, todo, done, timestamp, timestamp-kwd, tag, target.
328 For example, a valid value would be:
330 <style type=\"text/css\">
332 p { font-weight: normal; color: gray; }
334 .title { text-align: center; }
335 .todo, .timestamp-kwd { color: red; }
336 .done { color: green; }
340 If you'd like to refer to an external style file, use something like
342 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
344 As the value of this option simply gets inserted into the HTML <head> header,
345 you can \"misuse\" it to add arbitrary text to the header.
346 See also the variable `org-e-html-style-extra'."
347 :group
'org-export-e-html
350 (put 'org-e-html-style
'safe-local-variable
'stringp
)
352 (defcustom org-e-html-style-extra
""
353 "Additional style information for HTML export.
354 The value of this variable is inserted into the HTML buffer right after
355 the value of `org-e-html-style'. Use this variable for per-file
356 settings of style information, and do not forget to surround the style
357 settings with <style>...</style> tags."
358 :group
'org-export-e-html
361 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
363 (defcustom org-e-html-mathjax-options
364 '((path "http://orgmode.org/mathjax/MathJax.js")
369 "Options for MathJax setup.
371 path The path where to find MathJax
372 scale Scaling for the HTML-CSS backend, usually between 100 and 133
373 align How to align display math: left, center, or right
374 indent If align is not center, how far from the left/right side?
375 mathml Should a MathML player be used if available?
376 This is faster and reduces bandwidth use, but currently
377 sometimes has lower spacing quality. Therefore, the default is
378 nil. When browsers get better, this switch can be flipped.
380 You can also customize this for each buffer, using something like
382 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
383 :group
'org-export-e-html
384 :type
'(list :greedy t
385 (list :tag
"path (the path from where to load MathJax.js)"
386 (const :format
" " path
) (string))
387 (list :tag
"scale (scaling for the displayed math)"
388 (const :format
" " scale
) (string))
389 (list :tag
"align (alignment of displayed equations)"
390 (const :format
" " align
) (string))
391 (list :tag
"indent (indentation with left or right alignment)"
392 (const :format
" " indent
) (string))
393 (list :tag
"mathml (should MathML display be used is possible)"
394 (const :format
" " mathml
) (boolean))))
397 ;;;; Document Header (Scripts)
399 (defcustom org-e-html-style-include-scripts t
400 "Non-nil means include the JavaScript snippets in exported HTML files.
401 The actual script is defined in `org-e-html-scripts' and should
403 :group
'org-export-e-html
406 (defconst org-e-html-scripts
407 "<script type=\"text/javascript\">
408 <!--/*--><![CDATA[/*><!--*/
409 function CodeHighlightOn(elem, id)
411 var target = document.getElementById(id);
413 elem.cacheClassElem = elem.className;
414 elem.cacheClassTarget = target.className;
415 target.className = \"code-highlighted\";
416 elem.className = \"code-highlighted\";
419 function CodeHighlightOff(elem, id)
421 var target = document.getElementById(id);
422 if(elem.cacheClassElem)
423 elem.className = elem.cacheClassElem;
424 if(elem.cacheClassTarget)
425 target.className = elem.cacheClassTarget;
429 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
432 ;;;; Document Header (Mathjax)
434 (defcustom org-e-html-mathjax-template
435 "<script type=\"text/javascript\" src=\"%PATH\">
436 <!--/*--><![CDATA[/*><!--*/
438 // Only one of the two following lines, depending on user settings
439 // First allows browser-native MathML display, second forces HTML/CSS
440 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
441 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
442 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
443 \"TeX/noUndefined.js\"],
445 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
446 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
447 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
448 ignoreClass: \"tex2jax_ignore\",
449 processEscapes: false,
450 processEnvironments: true,
453 showProcessingMessages: true,
454 displayAlign: \"%ALIGN\",
455 displayIndent: \"%INDENT\",
459 availableFonts: [\"STIX\",\"TeX\"],
460 preferredFont: \"TeX\",
476 "The MathJax setup for XHTML files."
477 :group
'org-export-e-html
483 (defcustom org-e-html-preamble t
484 "Non-nil means insert a preamble in HTML export.
486 When `t', insert a string as defined by one of the formatting
487 strings in `org-e-html-preamble-format'. When set to a
488 string, this string overrides `org-e-html-preamble-format'.
489 When set to a function, apply this function and insert the
490 returned string. The function takes the property list of export
491 options as its only argument.
493 Setting :html-preamble in publishing projects will take
494 precedence over this variable."
495 :group
'org-export-e-html
496 :type
'(choice (const :tag
"No preamble" nil
)
497 (const :tag
"Default preamble" t
)
498 (string :tag
"Custom formatting string")
499 (function :tag
"Function (must return a string)")))
501 (defcustom org-e-html-preamble-format
'(("en" ""))
502 "The format for the HTML preamble.
504 %t stands for the title.
505 %a stands for the author's name.
506 %e stands for the author's email.
507 %d stands for the date.
509 If you need to use a \"%\" character, you need to escape it
511 :group
'org-export-e-html
514 (defcustom org-e-html-link-up
""
515 "Where should the \"UP\" link of exported HTML pages lead?"
516 :group
'org-export-e-html
517 :type
'(string :tag
"File or URL"))
519 (defcustom org-e-html-link-home
""
520 "Where should the \"HOME\" link of exported HTML pages lead?"
521 :group
'org-export-e-html
522 :type
'(string :tag
"File or URL"))
524 (defcustom org-e-html-home
/up-format
525 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
526 <a accesskey=\"h\" href=\"%s\"> UP </a>
528 <a accesskey=\"H\" href=\"%s\"> HOME </a>
530 "Snippet used to insert the HOME and UP links.
531 This is a format string, the first %s will receive the UP link,
532 the second the HOME link. If both `org-e-html-link-up' and
533 `org-e-html-link-home' are empty, the entire snippet will be
535 :group
'org-export-e-html
540 (defcustom org-e-html-postamble
'auto
541 "Non-nil means insert a postamble in HTML export.
543 When `t', insert a string as defined by the formatting string in
544 `org-e-html-postamble-format'. When set to a string, this
545 string overrides `org-e-html-postamble-format'. When set to
546 'auto, discard `org-e-html-postamble-format' and honor
547 `org-export-author/email/creator-info' variables. When set to a
548 function, apply this function and insert the returned string.
549 The function takes the property list of export options as its
552 Setting :html-postamble in publishing projects will take
553 precedence over this variable."
554 :group
'org-export-e-html
555 :type
'(choice (const :tag
"No postamble" nil
)
556 (const :tag
"Auto preamble" 'auto
)
557 (const :tag
"Default formatting string" t
)
558 (string :tag
"Custom formatting string")
559 (function :tag
"Function (must return a string)")))
561 (defcustom org-e-html-postamble-format
562 '(("en" "<p class=\"author\">Author: %a (%e)</p>
563 <p class=\"date\">Date: %d</p>
564 <p class=\"creator\">Generated by %c</p>
565 <p class=\"xhtml-validation\">%v</p>
567 "The format for the HTML postamble.
569 %a stands for the author's name.
570 %e stands for the author's email.
571 %d stands for the date.
572 %c will be replaced by information about Org/Emacs versions.
573 %v will be replaced by `org-e-html-validation-link'.
575 If you need to use a \"%\" character, you need to escape it
577 :group
'org-export-e-html
580 (defcustom org-e-html-validation-link
581 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
582 "Link to HTML validation service."
583 :group
'org-export-e-html
586 ;; FIXME Obsolete since Org 7.7
587 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
590 (defcustom org-e-html-protect-char-alist
594 "Alist of characters to be converted by `org-e-html-protect'."
595 :group
'org-export-e-html
596 :type
'(repeat (cons (string :tag
"Character")
597 (string :tag
"HTML equivalent"))))
599 (defconst org-e-html-special-string-regexps
600 '(("\\\\-" .
"­")
601 ("---\\([^-]\\)" .
"—\\1")
602 ("--\\([^-]\\)" .
"–\\1")
603 ("\\.\\.\\." .
"…"))
604 "Regular expressions for special string conversion.")
609 (defcustom org-e-html-todo-kwd-class-prefix
""
610 "Prefix to class names for TODO keywords.
611 Each TODO keyword gets a class given by the keyword itself, with this prefix.
612 The default prefix is empty because it is nice to just use the keyword
613 as a class name. But if you get into conflicts with other, existing
614 CSS classes, then this prefix can be very useful."
615 :group
'org-export-e-html
621 (defcustom org-e-html-tag-class-prefix
""
622 "Prefix to class names for TODO keywords.
623 Each tag gets a class given by the tag itself, with this prefix.
624 The default prefix is empty because it is nice to just use the keyword
625 as a class name. But if you get into conflicts with other, existing
626 CSS classes, then this prefix can be very useful."
627 :group
'org-export-e-html
631 ;;;; Statistics Cookie
637 (defcustom org-e-html-inline-images
'maybe
638 "Non-nil means inline images into exported HTML pages.
639 This is done using an <img> tag. When nil, an anchor with href is used to
640 link to the image. If this option is `maybe', then images in links with
641 an empty description will be inlined, while images with a description will
643 :group
'org-export-e-html
644 :type
'(choice (const :tag
"Never" nil
)
645 (const :tag
"Always" t
)
646 (const :tag
"When there is no description" maybe
)))
648 (defcustom org-e-html-inline-image-extensions
649 '("png" "jpeg" "jpg" "gif" "svg")
650 "Extensions of image files that can be inlined into HTML."
651 :group
'org-export-e-html
652 :type
'(repeat (string :tag
"Extension")))
668 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
669 <h2 class=\"footnotes\">%s: </h2>
670 <div id=\"text-footnotes\">
674 "Format for the footnotes section.
675 Should contain a two instances of %s. The first will be replaced with the
676 language-specific word for \"Footnotes\", the second one will be replaced
677 by the footnotes themselves."
678 :group
'org-export-e-html
681 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
682 "The format for the footnote reference.
683 %s will be replaced by the footnote reference itself."
684 :group
'org-export-e-html
687 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
688 "Text used to separate footnotes."
689 :group
'org-export-e-html
695 ;;;; Inline Babel Call
696 ;;;; Inline Src Block
700 ;;;; Latex Environment
717 (defgroup org-export-e-htmlize nil
718 "Options for processing examples with htmlize.el."
719 :tag
"Org Export Htmlize"
720 :group
'org-export-e-html
)
722 (defcustom org-export-e-htmlize-output-type
'inline-css
723 "Output type to be used by htmlize when formatting code snippets.
724 Choices are `css', to export the CSS selectors only, or `inline-css', to
725 export the CSS attribute values inline in the HTML. We use as default
726 `inline-css', in order to make the resulting HTML self-containing.
728 However, this will fail when using Emacs in batch mode for export, because
729 then no rich font definitions are in place. It will also not be good if
730 people with different Emacs setup contribute HTML files to a website,
731 because the fonts will represent the individual setups. In these cases,
732 it is much better to let Org/Htmlize assign classes only, and to use
733 a style file to define the look of these classes.
734 To get a start for your css file, start Emacs session and make sure that
735 all the faces you are interested in are defined, for example by loading files
736 in all modes you want. Then, use the command
737 \\[org-export-e-htmlize-generate-css] to extract class definitions."
738 :group
'org-export-e-htmlize
739 :type
'(choice (const css
) (const inline-css
)))
741 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
742 "The prefix for CSS class names for htmlize font specifications."
743 :group
'org-export-e-htmlize
746 (defcustom org-export-e-htmlized-org-css-url nil
747 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
748 Normally when creating an htmlized version of an Org buffer, htmlize will
749 create CSS to define the font colors. However, this does not work when
750 converting in batch mode, and it also can look bad if different people
751 with different fontification setup work on the same website.
752 When this variable is non-nil, creating an htmlized version of an Org buffer
753 using `org-export-as-org' will remove the internal CSS section and replace it
754 with a link to this URL."
755 :group
'org-export-e-htmlize
757 (const :tag
"Keep internal css" nil
)
758 (string :tag
"URL or local href")))
763 (defcustom org-e-html-table-tag
764 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
765 "The HTML tag that is used to start a table.
766 This must be a <table> tag, but you may change the options like
767 borders and spacing."
768 :group
'org-export-e-html
771 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
772 "The opening tag for table header fields.
773 This is customizable so that alignment options can be specified.
774 The first %s will be filled with the scope of the field, either row or col.
775 The second %s will be replaced by a style entry to align the field.
776 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
777 See also the variable `org-e-html-table-align-individual-fields'."
778 :group
'org-export-tables
; FIXME: change group?
779 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
781 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
782 "The opening tag for table data fields.
783 This is customizable so that alignment options can be specified.
784 The first %s will be filled with the scope of the field, either row or col.
785 The second %s will be replaced by a style entry to align the field.
786 See also the variable `org-e-html-table-align-individual-fields'."
787 :group
'org-export-tables
788 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
790 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
791 "The opening tag for table data fields.
792 This is customizable so that alignment options can be specified.
793 Instead of strings, these can be Lisp forms that will be evaluated
794 for each row in order to construct the table row tags. During evaluation,
795 the variable `head' will be true when this is a header line, nil when this
796 is a body line. And the variable `nline' will contain the line number,
797 starting from 1 in the first header line. For example
799 (setq org-e-html-table-row-tags
802 (if (= (mod nline 2) 1)
803 \"<tr class=\\\"tr-odd\\\">\"
804 \"<tr class=\\\"tr-even\\\">\"))
807 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
808 :group
'org-export-tables
810 (choice :tag
"Opening tag"
811 (string :tag
"Specify")
813 (choice :tag
"Closing tag"
814 (string :tag
"Specify")
817 (defcustom org-e-html-table-align-individual-fields t
818 "Non-nil means attach style attributes for alignment to each table field.
819 When nil, alignment will only be specified in the column tags, but this
820 is ignored by some browsers (like Firefox, Safari). Opera does it right
822 :group
'org-export-tables
825 (defcustom org-e-html-table-use-header-tags-for-first-column nil
826 "Non-nil means format column one in tables with header tags.
827 When nil, also column one will use data tags."
828 :group
'org-export-tables
839 (defcustom org-e-html-toplevel-hlevel
2
840 "The <H> level for level 1 headings in HTML export.
841 This is also important for the classes that will be wrapped around headlines
842 and outline structure. If this variable is 1, the top-level headlines will
843 be <h1>, and the corresponding classes will be outline-1, section-number-1,
844 and outline-text-1. If this is 2, all of these will get a 2 instead.
845 The default for this variable is 2, because we use <h1> for formatting the
847 :group
'org-export-e-html
856 (defcustom org-e-html-link-org-files-as-html t
857 "Non-nil means make file links to `file.org' point to `file.html'.
858 When org-mode is exporting an org-mode file to HTML, links to
859 non-html files are directly put into a href tag in HTML.
860 However, links to other Org-mode files (recognized by the
861 extension `.org.) should become links to the corresponding html
862 file, assuming that the linked org-mode file will also be
864 When nil, the links still point to the plain `.org' file."
865 :group
'org-export-e-html
873 ;;; User Configurable Variables (MAYBE)
877 (defcustom org-e-html-date-format
879 "Format string for \\date{...}."
880 :group
'org-export-e-html
883 (defcustom org-e-html-creator-string
884 (format "Generated by <a href=\"http://orgmode.org\">Org</a> mode %s in <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> %s."
885 (if (fboundp 'org-version
) (org-version) "(Unknown)")
887 "String to insert at the end of the HTML document."
888 :group
'org-export-e-html
889 :type
'(string :tag
"Creator string"))
893 (defcustom org-e-html-format-headline-function nil
894 "Function to format headline text.
896 This function will be called with 5 arguments:
897 TODO the todo keyword (string or nil).
898 TODO-TYPE the type of todo (symbol: `todo', `done', nil)
899 PRIORITY the priority of the headline (integer or nil)
900 TEXT the main headline text (string).
901 TAGS the tags (string or nil).
903 The function result will be used in the section format string.
905 As an example, one could set the variable to the following, in
906 order to reproduce the default set-up:
908 \(defun org-e-html-format-headline \(todo todo-type priority text tags)
909 \"Default format function for an headline.\"
911 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo))
913 \(format \"\\\\framebox{\\\\#%c} \" priority))
915 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags))))"
916 :group
'org-export-e-html
922 (defcustom org-e-html-text-markup-alist
923 '((bold .
"<b>%s</b>")
924 (code .
"<code>%s</code>")
925 (italic .
"<i>%s</i>")
926 (strike-through .
"<del>%s</del>")
927 (underline .
"<span style=\"text-decoration:underline;\">%s</span>")
928 (verbatim .
"<code>%s</code>"))
929 "Alist of HTML expressions to convert text markup
931 The key must be a symbol among `bold', `code', `italic',
932 `strike-through', `underline' and `verbatim'. The value is
933 a formatting string to wrap fontified text with.
935 If no association can be found for a given markup, text will be
937 :group
'org-export-e-html
938 :type
'(alist :key-type
(symbol :tag
"Markup type")
939 :value-type
(string :tag
"Format string"))
940 :options
'(bold code italic strike-through underline verbatim
))
945 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
946 "Text used to separate footnotes."
947 :group
'org-export-e-html
953 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
954 "A printf format string to be applied to active timestamps."
955 :group
'org-export-e-html
958 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
959 "A printf format string to be applied to inactive timestamps."
960 :group
'org-export-e-html
963 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
964 "A printf format string to be applied to diary timestamps."
965 :group
'org-export-e-html
971 (defcustom org-e-html-inline-image-rules
972 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
973 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
974 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
975 "Rules characterizing image files that can be inlined into HTML.
977 A rule consists in an association whose key is the type of link
978 to consider, and value is a regexp that will be matched against
981 Note that, by default, the image extension *actually* allowed
982 depend on the way the HTML file is processed. When used with
983 pdflatex, pdf, jpg and png images are OK. When processing
984 through dvi to Postscript, only ps and eps are allowed. The
985 default we use here encompasses both."
986 :group
'org-export-e-html
987 :type
'(alist :key-type
(string :tag
"Type")
988 :value-type
(regexp :tag
"Path")))
992 (defcustom org-e-html-table-caption-above t
993 "When non-nil, place caption string at the beginning of the table.
994 Otherwise, place it near the end."
995 :group
'org-export-e-html
1000 (defcustom org-e-html-format-drawer-function nil
1001 "Function called to format a drawer in HTML code.
1003 The function must accept two parameters:
1004 NAME the drawer name, like \"LOGBOOK\"
1005 CONTENTS the contents of the drawer.
1007 The function should return the string to be exported.
1009 For example, the variable could be set to the following function
1010 in order to mimic default behaviour:
1012 \(defun org-e-html-format-drawer-default \(name contents\)
1013 \"Format a drawer element for HTML export.\"
1015 :group
'org-export-e-html
1021 (defcustom org-e-html-format-inlinetask-function nil
1022 "Function called to format an inlinetask in HTML code.
1024 The function must accept six parameters:
1025 TODO the todo keyword, as a string
1026 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
1027 PRIORITY the inlinetask priority, as a string
1028 NAME the inlinetask name, as a string.
1029 TAGS the inlinetask tags, as a list of strings.
1030 CONTENTS the contents of the inlinetask, as a string.
1032 The function should return the string to be exported.
1034 For example, the variable could be set to the following function
1035 in order to mimic default behaviour:
1037 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
1038 \"Format an inline task element for HTML export.\"
1039 \(let \(\(full-title
1042 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo))
1043 \(when priority (format \"\\\\framebox{\\\\#%c} \" priority))
1045 \(when tags (format \"\\\\hfill{}\\\\textsc{%s}\" tags)))))
1046 \(format (concat \"\\\\begin{center}\\n\"
1048 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
1050 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
1052 \"\\\\end{minipage}}\"
1053 \"\\\\end{center}\")
1054 full-title contents))"
1055 :group
'org-export-e-html
1063 (defcustom org-e-html-quotes
1065 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"«~")
1066 ("\\(\\S-\\)\"" .
"~»")
1067 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
1069 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"``")
1070 ("\\(\\S-\\)\"" .
"''")
1071 ("\\(\\s-\\|(\\|^\\)'" .
"`")))
1072 "Alist for quotes to use when converting english double-quotes.
1074 The CAR of each item in this alist is the language code.
1075 The CDR of each item in this alist is a list of three CONS:
1076 - the first CONS defines the opening quote;
1077 - the second CONS defines the closing quote;
1078 - the last CONS defines single quotes.
1080 For each item in a CONS, the first string is a regexp
1081 for allowed characters before/after the quote, the second
1082 string defines the replacement string for this quote."
1083 :group
'org-export-e-html
1085 (cons :tag
"Opening quote"
1086 (string :tag
"Regexp for char before")
1087 (string :tag
"Replacement quote "))
1088 (cons :tag
"Closing quote"
1089 (string :tag
"Regexp for char after ")
1090 (string :tag
"Replacement quote "))
1091 (cons :tag
"Single quote"
1092 (string :tag
"Regexp for char before")
1093 (string :tag
"Replacement quote "))))
1099 ;;; Internal Functions (HTML)
1101 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1102 "Convert an org filename to an equivalent html filename.
1103 If TYPE is not file, just return `nil'.
1104 See variable `org-e-html-link-org-files-as-html'."
1107 org-e-html-link-org-files-as-html
1108 (string= type
"file")
1109 (string-match "\\.org$" path
)
1114 (substring path
0 (match-beginning 0))
1115 "." (plist-get opt-plist
:html-extension
)))))))
1117 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1120 OPT-PLIST is an options list.
1121 TYPE is the device-type of the link (THIS://foo.html).
1122 PATH is the path of the link (http://THIS#location).
1123 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1124 DESC is the link description, if any.
1125 ATTR is a string of other attributes of the \"a\" element."
1126 (declare (special org-lparse-par-open
))
1128 (let* ((may-inline-p
1129 (and (member type-1
'("http" "https" "file"))
1130 (org-lparse-should-inline-p path descp
)
1132 (type (if (equal type-1
"id") "file" type-1
))
1134 ;;First pass. Just sanity stuff.
1137 ((string= type
"file")
1140 ;;Substitute just if original path was absolute.
1141 ;;(Otherwise path must remain relative)
1142 (if (file-name-absolute-p path
)
1143 (concat "file://" (expand-file-name path
))
1147 (t (list type path
))))
1149 ;;Second pass. Components converted so they can refer
1153 (and org-e-html-cvt-link-fn
1154 (apply org-e-html-cvt-link-fn
1155 opt-plist components-1
))
1156 (apply #'org-e-html-cvt-org-as-html
1157 opt-plist components-1
)
1159 (type (first components-2
))
1160 (thefile (second components-2
)))
1163 ;;Third pass. Build final link except for leading type
1168 (string= type
"http")
1169 (string= type
"https")
1170 (string= type
"file")
1171 (string= type
"coderef"))
1173 (setq thefile
(concat thefile
"#" fragment
))))
1177 ;;Final URL-build, for all types.
1180 ((str (org-xml-format-href thefile
)))
1181 (if (and type
(not (or (string= "file" type
)
1182 (string= "coderef" type
))))
1183 (concat type
":" str
)
1187 (ignore) ;; (org-e-html-format-image thefile)
1189 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1191 ;; (caption (and caption (org-xml-encode-org-text caption)))
1192 ;; alt = (file-name-nondirectory path)
1194 (defun org-e-html-format-inline-image (src &optional
1195 caption label attr standalone-p
)
1196 (let* ((id (if (not label
) ""
1197 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1200 ((string-match "\\<alt=" (or attr
"")) "")
1201 ((string-match "^ltxpng/" src
)
1202 (format " alt=\"%s\""
1203 (org-e-html-encode-plain-text
1204 (org-find-text-property-in-string
1205 'org-latex-src src
))))
1206 (t (format " alt=\"%s\""
1207 (file-name-nondirectory src
)))))))
1210 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1211 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1212 id
(format "\n<p>%s</p>" img
)
1213 (when caption
(format "\n<p>%s</p>" caption
)))))
1214 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1218 (defun org-e-html-bibliography ()
1219 "Find bibliography, cut it out and return it."
1221 (let (beg end
(cnt 1) bib
)
1223 (goto-char (point-min))
1224 (when (re-search-forward
1225 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1226 (setq beg
(match-beginning 0))
1227 (while (re-search-forward "</?div\\>" nil t
)
1228 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1230 (and (looking-at ">") (forward-char 1))
1231 (setq bib
(buffer-substring beg
(point)))
1232 (delete-region beg
(point))
1233 (throw 'exit bib
))))
1238 (defun org-e-html-splice-attributes (tag attributes
)
1239 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1240 (if (not attributes
)
1242 (let (oldatt newatt
)
1243 (setq oldatt
(org-extract-attributes-from-string tag
)
1245 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1247 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1248 (if (string-match ">" tag
)
1250 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1254 (defun org-export-splice-style (style extra
)
1255 "Splice EXTRA into STYLE, just before \"</style>\"."
1256 (if (and (stringp extra
)
1257 (string-match "\\S-" extra
)
1258 (string-match "</style>" style
))
1259 (concat (substring style
0 (match-beginning 0))
1261 (substring style
(match-beginning 0)))
1264 (defun org-export-e-htmlize-region-for-paste (beg end
)
1265 "Convert the region to HTML, using htmlize.el.
1266 This is much like `htmlize-region-for-paste', only that it uses
1267 the settings define in the org-... variables."
1268 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1269 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1270 (htmlbuf (htmlize-region beg end
)))
1272 (with-current-buffer htmlbuf
1273 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1274 (plist-get htmlize-buffer-places
'content-end
)))
1275 (kill-buffer htmlbuf
))))
1278 (defun org-export-e-htmlize-generate-css ()
1279 "Create the CSS for all font definitions in the current Emacs session.
1280 Use this to create face definitions in your CSS style file that can then
1281 be used by code snippets transformed by htmlize.
1282 This command just produces a buffer that contains class definitions for all
1283 faces used in the current Emacs session. You can copy and paste the ones you
1284 need into your CSS file.
1286 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1287 the function `org-export-e-htmlize-region-for-paste' will produce code
1288 that uses these same face definitions."
1291 (and (get-buffer "*html*") (kill-buffer "*html*"))
1293 (let ((fl (face-list))
1294 (htmlize-css-name-prefix "org-")
1295 (htmlize-output-type 'css
)
1297 (while (setq f
(pop fl
)
1298 i
(and f
(face-attribute f
:inherit
)))
1299 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1300 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1301 (htmlize-region (point-min) (point-max))))
1302 (org-pop-to-buffer-same-window "*html*")
1303 (goto-char (point-min))
1304 (if (re-search-forward "<style" nil t
)
1305 (delete-region (point-min) (match-beginning 0)))
1306 (if (re-search-forward "</style>" nil t
)
1307 (delete-region (1+ (match-end 0)) (point-max)))
1308 (beginning-of-line 1)
1309 (if (looking-at " +") (replace-match ""))
1310 (goto-char (point-min)))
1312 (defun org-e-html-make-string (n string
)
1313 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1315 (defun org-e-html-toc-text (toc-entries)
1316 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1317 (start-level prev-level
))
1321 (let ((headline (nth 0 entry
))
1322 (level (nth 1 entry
)))
1324 (let* ((cnt (- level prev-level
))
1325 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1327 (setq prev-level level
)
1329 (org-e-html-make-string
1330 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1331 ((< cnt
0) "</li>\n</ul>\n")))
1332 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1335 (org-e-html-make-string
1336 (- prev-level start-level
) "</li>\n</ul>\n"))))
1338 (defun* org-e-html-format-toc-headline
1339 (todo todo-type priority text tags
1340 &key level section-number headline-label
&allow-other-keys
)
1341 (let ((headline (concat
1342 section-number
(and section-number
". ")
1344 (and tags
" ") (org-e-html--tags tags
))))
1345 (format "<a href=\"#%s\">%s</a>"
1346 (org-export-solidify-link-text headline-label
)
1347 (if (not nil
) headline
1348 (format "<span class=\"%s\">%s</span>" todo-type headline
)))))
1350 (defun org-e-html-toc (depth info
)
1351 (assert (wholenump depth
))
1352 (let* ((headlines (org-export-collect-headlines info depth
))
1354 (loop for headline in headlines collect
1355 (list (org-e-html-format-headline--wrap
1356 headline info
'org-e-html-format-toc-headline
)
1357 (org-export-get-relative-level headline info
)))))
1359 (let* ((lang-specific-heading
1360 (nth 3 (or (assoc (plist-get info
:language
)
1361 org-export-language-setup
)
1362 (assoc "en" org-export-language-setup
)))))
1364 "<div id=\"table-of-contents\">\n"
1365 (format "<h%d>%s</h%d>\n"
1366 org-e-html-toplevel-hlevel
1367 lang-specific-heading
1368 org-e-html-toplevel-hlevel
)
1369 "<div id=\"text-table-of-contents\">"
1370 (org-e-html-toc-text toc-entries
)
1374 ;; (defun org-e-html-format-line (line)
1375 ;; (case org-lparse-dyn-current-environment
1376 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1377 ;; (t (concat line "\n"))))
1379 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1380 "Turn todo keyword into a valid class name.
1381 Replaces invalid characters with \"_\"."
1383 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1384 (setq kwd
(replace-match "_" t t kwd
))))
1387 (defun org-e-html-format-footnote-reference (n def refcnt
)
1388 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1389 (format org-e-html-footnote-format
1390 (let* ((id (format "fnr.%s%s" n extra
))
1391 (href (format " href=\"#fn.%s\"" n
))
1392 (attributes (concat " class=\"footref\"" href
)))
1393 (org-e-html--anchor id n attributes
)))))
1395 (defun org-e-html-format-footnotes-section (section-name definitions
)
1396 (if (not definitions
) ""
1397 (format org-e-html-footnotes-section section-name definitions
)))
1399 (defun org-e-html-format-footnote-definition (fn)
1400 (let ((n (car fn
)) (def (cdr fn
)))
1402 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1403 (format org-e-html-footnote-format
1404 (let* ((id (format "fn.%s" n
))
1405 (href (format " href=\"#fnr.%s\"" n
))
1406 (attributes (concat " class=\"footnum\"" href
)))
1407 (org-e-html--anchor id n attributes
)))
1410 (defun org-e-html-footnote-section (info)
1411 (let* ((fn-alist (org-export-collect-footnote-definitions
1412 (plist-get info
:parse-tree
) info
))
1415 (loop for
(n type raw
) in fn-alist collect
1416 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1417 (org-trim (org-export-data raw info
))
1419 (org-trim (org-export-data raw info
))))))))
1421 (org-e-html-format-footnotes-section
1422 (nth 4 (or (assoc (plist-get info
:language
)
1423 org-export-language-setup
)
1424 (assoc "en" org-export-language-setup
)))
1426 "<table>\n%s\n</table>\n"
1427 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1429 (defun org-e-html-format-date (info)
1430 (let ((date (org-export-data (plist-get info
:date
) info
)))
1432 ((and date
(string-match "%" date
))
1433 (format-time-string date
))
1435 (t (format-time-string "%Y-%m-%d %T %Z")))))
1439 ;;; Internal Functions (Ngz)
1441 (defun org-e-html--caption/label-string
(caption label info
)
1442 "Return caption and label HTML string for floats.
1444 CAPTION is a cons cell of secondary strings, the car being the
1445 standard caption and the cdr its short form. LABEL is a string
1446 representing the label. INFO is a plist holding contextual
1449 If there's no caption nor label, return the empty string.
1451 For non-floats, see `org-e-html--wrap-label'."
1452 (setq label nil
) ;; FIXME
1454 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1456 ((and (not caption
) (not label
)) "")
1457 ((not caption
) (format "\\label{%s}\n" label
))
1458 ;; Option caption format with short name.
1460 (format "\\caption[%s]{%s%s}\n"
1461 (org-export-data (cdr caption
) info
)
1463 (org-export-data (car caption
) info
)))
1464 ;; Standard caption format.
1465 ;; (t (format "\\caption{%s%s}\n"
1467 ;; (org-export-data (car caption) info)))
1468 (t (org-export-data (car caption
) info
)))))
1470 (defun org-e-html--find-verb-separator (s)
1471 "Return a character not used in string S.
1472 This is used to choose a separator for constructs like \\verb."
1473 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1474 (loop for c across ll
1475 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1476 return
(char-to-string c
))))
1478 (defun org-e-html--quotation-marks (text info
)
1479 "Export quotation marks depending on language conventions.
1480 TEXT is a string containing quotation marks to be replaced. INFO
1481 is a plist used as a communication channel."
1484 (while (setq start
(string-match (car l
) text start
))
1485 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1486 (setq text
(replace-match new-quote t t text
))))))
1487 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1488 ;; Falls back on English.
1489 (assoc "en" org-e-html-quotes
))))
1492 (defun org-e-html--wrap-label (element output
)
1493 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1494 This function shouldn't be used for floats. See
1495 `org-e-html--caption/label-string'."
1496 ;; (let ((label (org-element-property :name element)))
1497 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1499 ;; (concat (format "\\label{%s}\n" label) output)))
1506 (defun org-e-html-meta-info (info)
1507 (let* ((title (org-export-data (plist-get info
:title
) info
))
1508 (author (and (plist-get info
:with-author
)
1509 (let ((auth (plist-get info
:author
)))
1510 (and auth
(org-export-data auth info
)))))
1511 (description (plist-get info
:description
))
1512 (keywords (plist-get info
:keywords
)))
1514 (format "\n<title>%s</title>\n" title
)
1516 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1517 (or (and org-e-html-coding-system
1518 (fboundp 'coding-system-get
)
1519 (coding-system-get org-e-html-coding-system
1522 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1523 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1524 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1525 (org-e-html-format-date info
))
1526 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1527 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1528 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1530 (defun org-e-html-style (info)
1532 "\n" (when (plist-get info
:style-include-default
) org-e-html-style-default
)
1533 (plist-get info
:style
)
1534 (plist-get info
:style-extra
)
1536 (when (plist-get info
:style-include-scripts
)
1537 org-e-html-scripts
)))
1539 (defun org-e-html-mathjax-config (info)
1540 "Insert the user setup into the matchjax template."
1541 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1542 (let ((template org-e-html-mathjax-template
)
1543 (options org-e-html-mathjax-options
)
1544 (in-buffer (or (plist-get info
:mathjax
) ""))
1545 name val
(yes " ") (no "// ") x
)
1548 (setq name
(car e
) val
(nth 1 e
))
1549 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1550 (setq val
(car (read-from-string
1551 (substring in-buffer
(match-end 0))))))
1552 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1553 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1554 (setq template
(replace-match val t t template
))))
1556 (setq val
(nth 1 (assq 'mathml options
)))
1557 (if (string-match (concat "\\<mathml:") in-buffer
)
1558 (setq val
(car (read-from-string
1559 (substring in-buffer
(match-end 0))))))
1560 ;; Exchange prefixes depending on mathml setting
1561 (if (not val
) (setq x yes yes no no x
))
1562 ;; Replace cookies to turn on or off the config/jax lines
1563 (if (string-match ":MMLYES:" template
)
1564 (setq template
(replace-match yes t t template
)))
1565 (if (string-match ":MMLNO:" template
)
1566 (setq template
(replace-match no t t template
)))
1567 ;; Return the modified template
1570 (defun org-e-html-preamble (info)
1571 (when (plist-get info
:html-preamble
)
1572 (let* ((title (org-export-data (plist-get info
:title
) info
))
1573 (date (org-e-html-format-date info
))
1574 (author (org-export-data (plist-get info
:author
) info
))
1575 (lang-words (or (assoc (plist-get info
:language
)
1576 org-export-language-setup
)
1577 (assoc "en" org-export-language-setup
)))
1578 (email (plist-get info
:email
))
1579 (html-pre-real-contents
1581 ((functionp (plist-get info
:html-preamble
))
1583 (funcall (plist-get info
:html-preamble
))
1585 ((stringp (plist-get info
:html-preamble
))
1586 (format-spec (plist-get info
:html-preamble
)
1587 `((?t .
,title
) (?a .
,author
)
1588 (?d .
,date
) (?e .
,email
))))
1591 (or (cadr (assoc (nth 0 lang-words
)
1592 org-e-html-preamble-format
))
1593 (cadr (assoc "en" org-e-html-preamble-format
)))
1594 `((?t .
,title
) (?a .
,author
)
1595 (?d .
,date
) (?e .
,email
)))))))
1596 (when (not (equal html-pre-real-contents
""))
1599 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1602 html-pre-real-contents
1606 (defun org-e-html-postamble (info)
1608 (when (and (not body-only
)
1609 (plist-get info
:html-postamble
))
1610 (let* ((html-post (plist-get info
:html-postamble
))
1611 (date (org-e-html-format-date info
))
1612 (author (let ((author (plist-get info
:author
)))
1613 (and author
(org-export-data author info
))))
1614 (email (plist-get info
:email
))
1615 (lang-words (or (assoc (plist-get info
:language
)
1616 org-export-language-setup
)
1617 (assoc "en" org-export-language-setup
)))
1619 (mapconcat (lambda(e)
1620 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1621 (split-string email
",+ *")
1623 (html-validation-link (or org-e-html-validation-link
""))
1624 (creator-info org-export-creator-string
))
1628 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1631 ((eq (plist-get info
:html-postamble
) 'auto
)
1633 (when (plist-get info
:time-stamp-file
)
1635 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1636 (when (and (plist-get info
:with-author
) author
)
1638 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1639 (when (and (plist-get info
:with-email
) email
)
1641 <p class=\"email\"> %s </p>" email
))
1642 (when (plist-get info
:with-creator
)
1644 <p class=\"creator\"> %s </p>" creator-info
))
1645 html-validation-link
"\n"))
1646 ;; postamble from a string
1647 ((stringp (plist-get info
:html-postamble
))
1648 (format-spec (plist-get info
:html-postamble
)
1649 `((?a .
,author
) (?e .
,email
)
1650 (?d .
,date
) (?c .
,creator-info
)
1651 (?v .
,html-validation-link
))))
1653 ;; postamble from a function
1654 ((functionp (plist-get info
:html-postamble
))
1656 (funcall (plist-get info
:html-postamble
))
1658 ;; default postamble
1661 (or (cadr (assoc (nth 0 lang-words
)
1662 org-e-html-postamble-format
))
1663 (cadr (assoc "en" org-e-html-postamble-format
)))
1664 `((?a .
,author
) (?e .
,email
)
1665 (?d .
,date
) (?c .
,creator-info
)
1666 (?v .
,html-validation-link
)))))
1669 ;; org-e-html-html-helper-timestamp
1672 (defun org-e-html-template (contents info
)
1673 "Return complete document string after HTML conversion.
1674 CONTENTS is the transcoded contents string. RAW-DATA is the
1675 original parsed data. INFO is a plist holding export options."
1678 (or (and (stringp org-e-html-xml-declaration
)
1679 org-e-html-xml-declaration
)
1680 (cdr (assoc (plist-get info
:html-extension
)
1681 org-e-html-xml-declaration
))
1682 (cdr (assoc "html" org-e-html-xml-declaration
))
1685 (or (and org-e-html-coding-system
1686 (fboundp 'coding-system-get
)
1687 (coding-system-get org-e-html-coding-system
1691 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1692 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1694 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1695 (plist-get info
:language
) (plist-get info
:language
))
1698 (org-e-html-meta-info info
) ; meta
1699 (org-e-html-style info
) ; style
1700 (org-e-html-mathjax-config info
) ; mathjax
1706 (let ((link-up (org-trim (plist-get info
:link-up
)))
1707 (link-home (org-trim (plist-get info
:link-home
))))
1708 (unless (and (string= link-up
"") (string= link-up
""))
1709 (format org-e-html-home
/up-format
1710 (or link-up link-home
)
1711 (or link-home link-up
))))
1713 (org-e-html-preamble info
)
1716 <div id=\"%s\">" (or org-e-html-content-div
1717 (nth 1 org-e-html-divs
)))
1720 <h1 class=\"title\">%s</h1>\n" (org-export-data (plist-get info
:title
) info
))
1721 ;; table of contents
1722 (let ((depth (plist-get info
:with-toc
)))
1723 (when (wholenump depth
) (org-e-html-toc depth info
)))
1724 ;; document contents
1726 ;; footnotes section
1727 (org-e-html-footnote-section info
)
1729 (org-e-html-bibliography)
1736 (org-e-html-postamble info
)
1746 ;;; Transcode Helpers
1750 (defun org-e-html--anchor (&optional id desc attributes
)
1751 (let* ((name (and org-e-html-allow-name-attribute-in-anchors id
))
1752 (attributes (concat (and id
(format " id=\"%s\"" id
))
1753 (and name
(format " name=\"%s\"" name
))
1755 (format "<a%s>%s</a>" attributes
(or desc
""))))
1759 (defun org-e-html--todo (todo)
1761 (format "<span class=\"%s %s%s\">%s</span>"
1762 (if (member todo org-done-keywords
) "done" "todo")
1763 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
1768 (defun org-e-html--tags (tags)
1770 (format "<span class=\"tag\">%s</span>"
1773 (format "<span class=\"%s\">%s</span>"
1774 (concat org-e-html-tag-class-prefix
1775 (org-e-html-fix-class-name tag
))
1781 (defun* org-e-html-format-headline
1782 (todo todo-type priority text tags
1783 &key level section-number headline-label
&allow-other-keys
)
1784 (let ((section-number
1785 (when section-number
1786 (format "<span class=\"section-number-%d\">%s</span> "
1787 level section-number
)))
1788 (todo (org-e-html--todo todo
))
1789 (tags (org-e-html--tags tags
)))
1790 (concat section-number todo
(and todo
" ") text
1791 (and tags
" ") tags
)))
1795 (defun org-e-html-fontify-code (code lang
)
1798 ;; Case 1: No lang. Possibly an example block.
1800 ;; Simple transcoding.
1801 (org-e-html-encode-plain-text code
))
1802 ;; Case 2: No htmlize or an inferior version of htmlize
1803 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1805 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1806 ;; Simple transcoding.
1807 (org-e-html-encode-plain-text code
))
1810 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1811 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1813 ;; Case 1: Language is not associated with any Emacs mode
1814 ((not (functionp lang-mode
))
1815 ;; Simple transcoding.
1816 (org-e-html-encode-plain-text code
))
1817 ;; Case 2: Default. Fotify code.
1820 (setq code
(with-temp-buffer
1823 (font-lock-fontify-buffer)
1824 ;; markup each line separately
1825 (org-remove-formatting-on-newlines-in-region
1826 (point-min) (point-max))
1828 (set-buffer-modified-p nil
)
1829 (org-export-e-htmlize-region-for-paste
1830 (point-min) (point-max))))
1831 ;; Strip any encolosing <pre></pre> tags
1832 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code
)
1833 (match-string 1 code
)
1836 (defun org-e-html-do-format-code
1837 (code &optional lang refs retain-labels num-start textarea-p
)
1839 (setq num-start nil refs nil lang nil
))
1840 (let* ((code-lines (org-split-string code
"\n"))
1841 (code-length (length code-lines
))
1845 (length (number-to-string (+ code-length num-start
))))))
1846 (code (org-e-html-fontify-code code lang
)))
1847 (assert (= code-length
(length (org-split-string code
"\n"))))
1848 (org-export-format-code
1850 (lambda (loc line-num ref
)
1853 ;; Add line number, if needed.
1855 (format "<span class=\"linenr\">%s</span>"
1856 (format num-fmt line-num
)))
1857 ;; Transcoded src line.
1859 ;; Add label, if needed.
1860 (when (and ref retain-labels
) (format " (%s)" ref
))))
1861 ;; Mark transcoded line as an anchor, if needed.
1863 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1867 (defun org-e-html-format-code (element info
)
1868 (let* ((lang (org-element-property :language element
))
1869 ;; (switches (org-element-property :switches element))
1870 (switches nil
) ; FIXME
1871 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1872 ;; Extract code and references.
1873 (code-info (org-export-unravel-code element
))
1874 (code (car code-info
))
1875 (refs (cdr code-info
))
1876 ;; Does the src block contain labels?
1877 (retain-labels (org-element-property :retain-labels element
))
1878 ;; Does it have line numbers?
1879 (num-start (case (org-element-property :number-lines element
)
1880 (continued (org-export-get-loc element info
))
1882 (org-e-html-do-format-code
1883 code lang refs retain-labels num-start textarea-p
)))
1887 ;;; Transcode Functions
1891 (defun org-e-html-bold (bold contents info
)
1892 "Transcode BOLD from Org to HTML.
1893 CONTENTS is the text with bold markup. INFO is a plist holding
1894 contextual information."
1895 (format (or (cdr (assq 'bold org-e-html-text-markup-alist
)) "%s")
1901 (defun org-e-html-center-block (center-block contents info
)
1902 "Transcode a CENTER-BLOCK element from Org to HTML.
1903 CONTENTS holds the contents of the block. INFO is a plist
1904 holding contextual information."
1905 (org-e-html--wrap-label
1907 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1912 (defun org-e-html-clock (clock contents info
)
1913 "Transcode a CLOCK element from Org to HTML.
1914 CONTENTS is nil. INFO is a plist used as a communication
1917 <span class=\"timestamp-wrapper\">
1918 <span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>%s
1922 (org-translate-time (org-element-property :value clock
))
1923 (let ((time (org-element-property :time clock
)))
1924 (and time
(format " <span class=\"timestamp\">(%s)</span>" time
)))))
1929 (defun org-e-html-code (code contents info
)
1930 "Transcode CODE from Org to HTML.
1931 CONTENTS is nil. INFO is a plist holding contextual
1933 (format (or (cdr (assq 'code org-e-html-text-markup-alist
)) "%s")
1934 (org-element-property :value code
)))
1939 ;; Comments are ignored.
1944 ;; Comment Blocks are ignored.
1949 (defun org-e-html-drawer (drawer contents info
)
1950 "Transcode a DRAWER element from Org to HTML.
1951 CONTENTS holds the contents of the block. INFO is a plist
1952 holding contextual information."
1953 (let* ((name (org-element-property :drawer-name drawer
))
1954 (output (if (functionp org-e-html-format-drawer-function
)
1955 (funcall org-e-html-format-drawer-function
1957 ;; If there's no user defined function: simply
1958 ;; display contents of the drawer.
1960 (org-e-html--wrap-label drawer output
)))
1965 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1966 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1967 CONTENTS holds the contents of the block. INFO is a plist
1968 holding contextual information. See `org-export-data'."
1969 (org-e-html--wrap-label dynamic-block contents
))
1974 (defun org-e-html-entity (entity contents info
)
1975 "Transcode an ENTITY object from Org to HTML.
1976 CONTENTS are the definition itself. INFO is a plist holding
1977 contextual information."
1978 (org-element-property :html entity
))
1983 (defun org-e-html-example-block (example-block contents info
)
1984 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1985 CONTENTS is nil. INFO is a plist holding contextual information."
1986 (let* ((options (or (org-element-property :options example-block
) ""))
1987 (lang (org-element-property :language example-block
))
1988 (caption (org-element-property :caption example-block
))
1989 (label (org-element-property :name example-block
))
1990 (caption-str (org-e-html--caption/label-string caption label info
))
1991 (attr (mapconcat #'identity
1992 (org-element-property :attr_html example-block
)
1994 ;; (switches (org-element-property :switches example-block))
1995 (switches nil
) ; FIXME
1996 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1997 (code (org-e-html-format-code example-block info
)))
2000 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2001 80 (string-to-number (match-string 1 switches
))))
2002 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2003 (string-to-number (match-string 1 switches
))
2004 (org-count-lines code
))))
2006 "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
2008 (t (format "<pre class=\"example\">\n%s</pre>" code
)))))
2013 (defun org-e-html-export-snippet (export-snippet contents info
)
2014 "Transcode a EXPORT-SNIPPET object from Org to HTML.
2015 CONTENTS is nil. INFO is a plist holding contextual information."
2016 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
2017 (org-element-property :value export-snippet
)))
2022 (defun org-e-html-export-block (export-block contents info
)
2023 "Transcode a EXPORT-BLOCK element from Org to HTML.
2024 CONTENTS is nil. INFO is a plist holding contextual information."
2025 (when (string= (org-element-property :type export-block
) "HTML")
2026 (org-remove-indentation (org-element-property :value export-block
))))
2031 (defun org-e-html-fixed-width (fixed-width contents info
)
2032 "Transcode a FIXED-WIDTH element from Org to HTML.
2033 CONTENTS is nil. INFO is a plist holding contextual information."
2034 (org-e-html--wrap-label
2036 (format "<pre class=\"example\">\n%s</pre>"
2037 (org-e-html-do-format-code
2038 (org-remove-indentation
2039 (org-element-property :value fixed-width
))))))
2042 ;;;; Footnote Definition
2044 ;; Footnote Definitions are ignored.
2047 ;;;; Footnote Reference
2049 (defun org-e-html-footnote-reference (footnote-reference contents info
)
2050 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
2051 CONTENTS is nil. INFO is a plist holding contextual information."
2053 ;; Insert separator between two footnotes in a row.
2054 (let ((prev (org-export-get-previous-element footnote-reference
)))
2055 (when (eq (org-element-type prev
) 'footnote-reference
)
2056 org-e-html-footnote-separator
))
2058 ((not (org-export-footnote-first-reference-p footnote-reference info
))
2059 (org-e-html-format-footnote-reference
2060 (org-export-get-footnote-number footnote-reference info
)
2062 ;; Inline definitions are secondary strings.
2063 ((eq (org-element-property :type footnote-reference
) 'inline
)
2064 (org-e-html-format-footnote-reference
2065 (org-export-get-footnote-number footnote-reference info
)
2067 ;; Non-inline footnotes definitions are full Org data.
2068 (t (org-e-html-format-footnote-reference
2069 (org-export-get-footnote-number footnote-reference info
)
2075 (defun org-e-html-format-headline--wrap (headline info
2076 &optional format-function
2078 "Transcode an HEADLINE element from Org to HTML.
2079 CONTENTS holds the contents of the headline. INFO is a plist
2080 holding contextual information."
2081 (let* ((level (+ (org-export-get-relative-level headline info
)
2082 (1- org-e-html-toplevel-hlevel
)))
2083 (headline-number (org-export-get-headline-number headline info
))
2084 (section-number (and (org-export-numbered-headline-p headline info
)
2085 (mapconcat 'number-to-string
2086 headline-number
".")))
2087 (todo (and (plist-get info
:with-todo-keywords
)
2088 (let ((todo (org-element-property :todo-keyword headline
)))
2089 (and todo
(org-export-data todo info
)))))
2090 (todo-type (and todo
(org-element-property :todo-type headline
)))
2091 (priority (and (plist-get info
:with-priority
)
2092 (org-element-property :priority headline
)))
2093 (text (org-export-data (org-element-property :title headline
) info
))
2094 (tags (and (plist-get info
:with-tags
)
2095 (org-export-get-tags headline info
)))
2096 (headline-label (or (org-element-property :custom-id headline
)
2097 (concat "sec-" (mapconcat 'number-to-string
2098 headline-number
"-"))))
2099 (format-function (cond
2100 ((functionp format-function
) format-function
)
2101 ((functionp org-e-html-format-headline-function
)
2103 (lambda (todo todo-type priority text tags
2105 (funcall org-e-html-format-headline-function
2106 todo todo-type priority text tags
))))
2107 (t 'org-e-html-format-headline
))))
2108 (apply format-function
2109 todo todo-type priority text tags
2110 :headline-label headline-label
:level level
2111 :section-number section-number extra-keys
)))
2113 (defun org-e-html-headline (headline contents info
)
2114 "Transcode an HEADLINE element from Org to HTML.
2115 CONTENTS holds the contents of the headline. INFO is a plist
2116 holding contextual information."
2118 (setq contents
(or contents
""))
2119 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2120 (level (org-export-get-relative-level headline info
))
2121 (text (org-export-data (org-element-property :title headline
) info
))
2122 (todo (and (plist-get info
:with-todo-keywords
)
2123 (let ((todo (org-element-property :todo-keyword headline
)))
2124 (and todo
(org-export-data todo info
)))))
2125 (todo-type (and todo
(org-element-property :todo-type headline
)))
2126 (tags (and (plist-get info
:with-tags
)
2127 (org-export-get-tags headline info
)))
2128 (priority (and (plist-get info
:with-priority
)
2129 (org-element-property :priority headline
)))
2130 (section-number (and (org-export-numbered-headline-p headline info
)
2131 (mapconcat 'number-to-string
2132 (org-export-get-headline-number
2133 headline info
) ".")))
2134 ;; Create the headline text.
2135 (full-text (org-e-html-format-headline--wrap headline info
)))
2137 ;; Case 1: This is a footnote section: ignore it.
2138 ((org-element-property :footnote-section-p headline
) nil
)
2139 ;; Case 2. This is a deep sub-tree: export it as a list item.
2140 ;; Also export as items headlines for which no section
2141 ;; format has been found.
2142 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2143 ;; Build the real contents of the sub-tree.
2144 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2145 (itemized-body (org-e-html-format-list-item
2146 contents type nil nil full-text
)))
2148 (and (org-export-first-sibling-p headline
)
2149 (org-e-html-begin-plain-list type
))
2151 (and (org-export-last-sibling-p headline
)
2152 (org-e-html-end-plain-list type
)))))
2153 ;; Case 3. Standard headline. Export it as a section.
2155 (let* ((section-number (mapconcat 'number-to-string
2156 (org-export-get-headline-number
2157 headline info
) "-"))
2159 (list (org-element-property :custom-id headline
)
2160 (concat "sec-" section-number
)
2161 (org-element-property :id headline
))))
2162 (preferred-id (car ids
))
2163 (extra-ids (cdr ids
))
2164 (extra-class (org-element-property :html-container-class headline
))
2165 (level1 (+ level
(1- org-e-html-toplevel-hlevel
))))
2166 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2167 (format "outline-container-%s"
2168 (or (org-element-property :custom-id headline
)
2170 (concat (format "outline-%d" level1
) (and extra-class
" ")
2172 (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
2177 (let ((id (org-solidify-link-text
2178 (if (org-uuidgen-p x
) (concat "ID-" x
)
2180 (org-e-html--anchor id
)))
2187 ;;;; Horizontal Rule
2189 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2190 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2191 CONTENTS is nil. INFO is a plist holding contextual information."
2192 (let ((attr (mapconcat #'identity
2193 (org-element-property :attr_html horizontal-rule
)
2195 (org-e-html--wrap-label horizontal-rule
"<hr/>")))
2198 ;;;; Inline Babel Call
2200 ;; Inline Babel Calls are ignored.
2203 ;;;; Inline Src Block
2205 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2206 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2207 CONTENTS holds the contents of the item. INFO is a plist holding
2208 contextual information."
2209 (let* ((org-lang (org-element-property :language inline-src-block
))
2210 (code (org-element-property :value inline-src-block
))
2211 (separator (org-e-html--find-verb-separator code
)))
2217 (defun org-e-html-format-section (text class
&optional id
)
2218 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2219 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2221 (defun org-e-html-inlinetask (inlinetask contents info
)
2222 "Transcode an INLINETASK element from Org to HTML.
2223 CONTENTS holds the contents of the block. INFO is a plist
2224 holding contextual information."
2226 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2227 ;; with appropriate arguments.
2228 ((functionp org-e-html-format-inlinetask-function
)
2229 (let ((format-function
2231 (lambda (todo todo-type priority text tags
2232 &key contents
&allow-other-keys
)
2233 (funcall org-e-html-format-inlinetask-function
2234 todo todo-type priority text tags contents
)))))
2235 (org-e-html-format-headline--wrap
2236 inlinetask info format-function
:contents contents
)))
2237 ;; Otherwise, use a default template.
2238 (t (org-e-html--wrap-label
2241 "<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s</div>"
2242 (org-e-html-format-headline--wrap inlinetask info
)
2248 (defun org-e-html-italic (italic contents info
)
2249 "Transcode ITALIC from Org to HTML.
2250 CONTENTS is the text with italic markup. INFO is a plist holding
2251 contextual information."
2252 (format (or (cdr (assq 'italic org-e-html-text-markup-alist
)) "%s") contents
))
2257 (defun org-e-html-checkbox (checkbox)
2258 (case checkbox
(on "<code>[X]</code>")
2259 (off "<code>[ ]</code>")
2260 (trans "<code>[-]</code>")
2263 (defun org-e-html-format-list-item (contents type checkbox
2264 &optional term-counter-id
2266 (let ((checkbox (concat (org-e-html-checkbox checkbox
) (and checkbox
" "))))
2270 (let* ((counter term-counter-id
)
2271 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2272 (format "<li%s>" extra
)))
2274 (let* ((id term-counter-id
)
2275 (extra (if id
(format " id=\"%s\"" id
) "")))
2277 (format "<li%s>" extra
)
2278 (when headline
(concat headline
"<br/>")))))
2280 (let* ((term term-counter-id
))
2281 (setq term
(or term
"(no term)"))
2282 ;; Check-boxes in descriptive lists are associated to tag.
2283 (concat (format "<dt> %s </dt>"
2284 (concat checkbox term
))
2286 (unless (eq type
'descriptive
) checkbox
)
2291 (descriptive "</dd>")))))
2293 (defun org-e-html-item (item contents info
)
2294 "Transcode an ITEM element from Org to HTML.
2295 CONTENTS holds the contents of the item. INFO is a plist holding
2296 contextual information."
2297 (let* ((plain-list (org-export-get-parent item
))
2298 (type (org-element-property :type plain-list
))
2299 (counter (org-element-property :counter item
))
2300 (checkbox (org-element-property :checkbox item
))
2301 (tag (let ((tag (org-element-property :tag item
)))
2302 (and tag
(org-export-data tag info
)))))
2303 (org-e-html-format-list-item
2304 contents type checkbox
(or tag counter
))))
2309 (defun org-e-html-keyword (keyword contents info
)
2310 "Transcode a KEYWORD element from Org to HTML.
2311 CONTENTS is nil. INFO is a plist holding contextual information."
2312 (let ((key (org-element-property :key keyword
))
2313 (value (org-element-property :value keyword
)))
2315 ((string= key
"LATEX") value
)
2316 ((string= key
"INDEX") (format "\\index{%s}" value
))
2317 ;; Invisible targets.
2318 ((string= key
"TARGET") nil
) ; FIXME
2319 ((string= key
"TOC")
2320 (let ((value (downcase value
)))
2322 ((string-match "\\<headlines\\>" value
)
2323 (let ((depth (or (and (string-match "[0-9]+" value
)
2324 (string-to-number (match-string 0 value
)))
2325 (plist-get info
:with-toc
))))
2326 (when (wholenump depth
) (org-e-html-toc depth info
))))
2327 ((string= "tables" value
) "\\listoftables")
2328 ((string= "figures" value
) "\\listoffigures")
2329 ((string= "listings" value
)
2331 ;; At the moment, src blocks with a caption are wrapped
2332 ;; into a figure environment.
2333 (t "\\listoffigures")))))))))
2336 ;;;; Latex Environment
2338 (defun org-e-html-format-latex (latex-frag processing-type
)
2339 (let* ((cache-relpath
2340 (concat "ltxpng/" (file-name-sans-extension
2341 (file-name-nondirectory (buffer-file-name)))))
2342 (cache-dir (file-name-directory (buffer-file-name )))
2343 (display-msg "Creating LaTeX Image..."))
2347 (org-format-latex cache-relpath cache-dir nil display-msg
2348 nil nil processing-type
)
2351 (defun org-e-html-latex-environment (latex-environment contents info
)
2352 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2353 CONTENTS is nil. INFO is a plist holding contextual information."
2354 (org-e-html--wrap-label
2356 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2357 (latex-frag (org-remove-indentation
2358 (org-element-property :value latex-environment
)))
2359 (caption (org-e-html--caption/label-string
2360 (org-element-property :caption latex-environment
)
2361 (org-element-property :name latex-environment
)
2364 (label (org-element-property :name latex-environment
)))
2366 ((member processing-type
'(t mathjax
))
2367 (org-e-html-format-latex latex-frag
'mathjax
))
2368 ((equal processing-type
'dvipng
)
2369 (let* ((formula-link (org-e-html-format-latex
2370 latex-frag processing-type
)))
2371 (when (and formula-link
2372 (string-match "file:\\([^]]*\\)" formula-link
))
2373 (org-e-html-format-inline-image
2374 (match-string 1 formula-link
) caption label attr t
))))
2380 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2381 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2382 CONTENTS is nil. INFO is a plist holding contextual information."
2383 (let ((latex-frag (org-element-property :value latex-fragment
))
2384 (processing-type (plist-get info
:LaTeX-fragments
)))
2385 (case processing-type
2387 (org-e-html-format-latex latex-frag
'mathjax
))
2389 (let* ((formula-link (org-e-html-format-latex
2390 latex-frag processing-type
)))
2391 (when (and formula-link
2392 (string-match "file:\\([^]]*\\)" formula-link
))
2393 (org-e-html-format-inline-image
2394 (match-string 1 formula-link
)))))
2399 (defun org-e-html-line-break (line-break contents info
)
2400 "Transcode a LINE-BREAK object from Org to HTML.
2401 CONTENTS is nil. INFO is a plist holding contextual information."
2407 (defun org-e-html-link--inline-image (link desc info
)
2408 "Return HTML code for an inline image.
2409 LINK is the link pointing to the inline image. INFO is a plist
2410 used as a communication channel."
2411 (let* ((type (org-element-property :type link
))
2412 (raw-path (org-element-property :path link
))
2413 (path (cond ((member type
'("http" "https"))
2414 (concat type
":" raw-path
))
2415 ((file-name-absolute-p raw-path
)
2416 (expand-file-name raw-path
))
2418 (parent (org-export-get-parent-element link
))
2419 (caption (org-e-html--caption/label-string
2420 (org-element-property :caption parent
)
2421 (org-element-property :name parent
)
2423 (label (org-element-property :name parent
))
2424 ;; Retrieve latex attributes from the element around.
2425 (attr (let ((raw-attr
2426 (mapconcat #'identity
2427 (org-element-property :attr_html parent
)
2429 (unless (string= raw-attr
"") raw-attr
))))
2430 ;; Now clear ATTR from any special keyword and set a default
2431 ;; value if nothing is left.
2432 (setq attr
(if (not attr
) "" (org-trim attr
)))
2433 ;; Return proper string, depending on DISPOSITION.
2434 (org-e-html-format-inline-image
2435 path caption label attr
(org-e-html-standalone-image-p link info
))))
2437 (defvar org-e-html-standalone-image-predicate
)
2438 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2439 "Test if ELEMENT is a standalone image for the purpose HTML export.
2440 INFO is a plist holding contextual information.
2442 Return non-nil, if ELEMENT is of type paragraph and it's sole
2443 content, save for whitespaces, is a link that qualifies as an
2446 Return non-nil, if ELEMENT is of type link and it's containing
2447 paragraph has no other content save for leading and trailing
2450 Return nil, otherwise.
2452 Bind `org-e-html-standalone-image-predicate' to constrain
2453 paragraph further. For example, to check for only captioned
2454 standalone images, do the following.
2456 \(setq org-e-html-standalone-image-predicate
2457 \(lambda \(paragraph\)
2458 \(org-element-property :caption paragraph\)\)\)
2460 (let ((paragraph (case (org-element-type element
)
2462 (link (and (org-export-inline-image-p
2463 element org-e-html-inline-image-rules
)
2464 (org-export-get-parent element
)))
2467 (assert (eq (org-element-type paragraph
) 'paragraph
))
2468 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2469 (functionp org-e-html-standalone-image-predicate
)))
2470 (funcall org-e-html-standalone-image-predicate paragraph
))
2471 (let ((contents (org-element-contents paragraph
)))
2472 (loop for x in contents
2473 with inline-image-count
= 0
2475 ((eq (org-element-type x
) 'plain-text
)
2476 (not (org-string-nw-p x
)))
2477 ((eq (org-element-type x
) 'link
)
2478 (when (org-export-inline-image-p
2479 x org-e-html-inline-image-rules
)
2480 (= (incf inline-image-count
) 1)))
2483 (defun org-e-html-link (link desc info
)
2484 "Transcode a LINK object from Org to HTML.
2486 DESC is the description part of the link, or the empty string.
2487 INFO is a plist holding contextual information. See
2489 (let* ((--link-org-files-as-html-maybe
2491 (lambda (raw-path info
)
2492 "Treat links to `file.org' as links to `file.html', if needed.
2493 See `org-e-html-link-org-files-as-html'."
2495 ((and org-e-html-link-org-files-as-html
2497 (downcase (file-name-extension raw-path
"."))))
2498 (concat (file-name-sans-extension raw-path
) "."
2499 (plist-get info
:html-extension
)))
2501 (type (org-element-property :type link
))
2502 (raw-path (org-element-property :path link
))
2503 ;; Ensure DESC really exists, or set it to nil.
2504 (desc (and (not (string= desc
"")) desc
))
2506 ((member type
'("http" "https" "ftp" "mailto"))
2507 (concat type
":" raw-path
))
2508 ((string= type
"file")
2509 ;; Extract just the file path and strip all other
2511 (when (string-match "\\(.+\\)::.+" raw-path
)
2512 (setq raw-path
(match-string 1 raw-path
)))
2513 ;; Treat links to ".org" files as ".html", if needed.
2514 (setq raw-path
(funcall --link-org-files-as-html-maybe
2516 ;; If file path is absolute, prepend it with protocol
2517 ;; component - "file://".
2518 (if (not (file-name-absolute-p raw-path
)) raw-path
2519 (concat "file://" (expand-file-name raw-path
))))
2521 ;; Extract attributes from parent's paragraph.
2523 (let ((attr (mapconcat
2525 (org-element-property
2526 :attr_html
(org-export-get-parent-element link
))
2528 (if attr
(concat " " attr
) "")))
2532 ((and (or (eq t org-e-html-inline-images
)
2533 (and org-e-html-inline-images
(not desc
)))
2534 (org-export-inline-image-p link org-e-html-inline-image-rules
))
2535 (org-e-html-link--inline-image link desc info
))
2536 ;; Radio target: Transcode target's contents and use them as
2537 ;; link's description.
2538 ((string= type
"radio")
2539 (let ((destination (org-export-resolve-radio-link link info
)))
2541 (format "<a href=\"#%s\"%s>%s</a>"
2542 (org-export-solidify-link-text path
)
2544 (org-export-data (org-element-contents destination
) info
)))))
2545 ;; Links pointing to an headline: Find destination and build
2546 ;; appropriate referencing command.
2547 ((member type
'("custom-id" "fuzzy" "id"))
2548 (let ((destination (if (string= type
"fuzzy")
2549 (org-export-resolve-fuzzy-link link info
)
2550 (org-export-resolve-id-link link info
))))
2551 (case (org-element-type destination
)
2552 ;; ID link points to an external file.
2554 (assert (org-uuidgen-p path
))
2555 (let ((fragment (concat "ID-" path
))
2556 ;; Treat links to ".org" files as ".html", if needed.
2557 (path (funcall --link-org-files-as-html-maybe
2559 (format "<a href=\"%s#%s\"%s>%s</a>"
2560 path fragment attributes
(or desc destination
))))
2561 ;; Fuzzy link points nowhere.
2566 (org-element-property :raw-link link
) info
))))
2567 ;; Fuzzy link points to an invisible target.
2569 ;; Link points to an headline.
2572 ;; What href to use?
2574 ;; Case 1: Headline is linked via it's CUSTOM_ID
2575 ;; property. Use CUSTOM_ID.
2576 ((string= type
"custom-id")
2577 (org-element-property :custom-id destination
))
2578 ;; Case 2: Headline is linked via it's ID property
2579 ;; or through other means. Use the default href.
2580 ((member type
'("id" "fuzzy"))
2582 (mapconcat 'number-to-string
2583 (org-export-get-headline-number
2584 destination info
) "-")))
2585 (t (error "Shouldn't reach here"))))
2586 ;; What description to use?
2588 ;; Case 1: Headline is numbered and LINK has no
2589 ;; description or LINK's description matches
2590 ;; headline's title. Display section number.
2591 (if (and (org-export-numbered-headline-p destination info
)
2593 (string= desc
(org-element-property
2594 :raw-value destination
))))
2595 (mapconcat 'number-to-string
2596 (org-export-get-headline-number
2597 destination info
) ".")
2598 ;; Case 2: Either the headline is un-numbered or
2599 ;; LINK has a custom description. Display LINK's
2600 ;; description or headline's title.
2601 (or desc
(org-export-data (org-element-property
2602 :title destination
) info
)))))
2603 (format "<a href=\"#%s\"%s>%s</a>"
2604 (org-solidify-link-text href
) attributes desc
)))
2605 ;; Fuzzy link points to a target. Do as above.
2607 (let ((path (org-export-solidify-link-text path
)) number
)
2610 ((org-e-html-standalone-image-p destination info
)
2611 (org-export-get-ordinal
2612 (assoc 'link
(org-element-contents destination
))
2613 info
'link
'org-e-html-standalone-image-p
))
2614 (t (org-export-get-ordinal destination info
))))
2615 (setq desc
(when number
2616 (if (atom number
) (number-to-string number
)
2617 (mapconcat 'number-to-string number
".")))))
2618 (format "<a href=\"#%s\"%s>%s</a>"
2619 path attributes
(or desc
"FIXME")))))))
2620 ;; Coderef: replace link with the reference name or the
2621 ;; equivalent line number.
2622 ((string= type
"coderef")
2623 (let ((fragment (concat "coderef-" path
)))
2624 (format "<a href=\"#%s\" %s%s>%s</a>"
2626 (format (concat "class=\"coderef\""
2627 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2628 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2631 (format (org-export-get-coderef-format path desc
)
2632 (org-export-resolve-coderef path info
)))))
2633 ;; Link type is handled by a special function.
2634 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2635 (funcall protocol
(org-link-unescape path
) desc
'html
))
2636 ;; External link with a description part.
2637 ((and path desc
) (format "<a href=\"%s\"%s>%s</a>" path attributes desc
))
2638 ;; External link without a description part.
2639 (path (format "<a href=\"%s\"%s>%s</a>" path attributes path
))
2640 ;; No path, only description. Try to do something useful.
2641 (t (format "<i>%s</i>" desc
)))))
2646 ;; Babel Calls are ignored.
2651 (defun org-e-html-macro (macro contents info
)
2652 "Transcode a MACRO element from Org to HTML.
2653 CONTENTS is nil. INFO is a plist holding contextual information."
2654 ;; Use available tools.
2655 (org-export-expand-macro macro info
))
2660 (defun org-e-html-paragraph (paragraph contents info
)
2661 "Transcode a PARAGRAPH element from Org to HTML.
2662 CONTENTS is the contents of the paragraph, as a string. INFO is
2663 the plist used as a communication channel."
2664 (let* ((style nil
) ; FIXME
2665 (class (cdr (assoc style
'((footnote .
"footnote")
2667 (extra (if class
(format " class=\"%s\"" class
) ""))
2668 (parent (org-export-get-parent paragraph
)))
2670 ((and (equal (org-element-type parent
) 'item
)
2671 (= (org-element-property :begin paragraph
)
2672 (org-element-property :contents-begin parent
)))
2673 ;; leading paragraph in a list item have no tags
2675 ((org-e-html-standalone-image-p paragraph info
)
2678 (t (format "<p%s>\n%s</p>" extra contents
)))))
2683 (defun org-e-html-begin-plain-list (type &optional arg1
)
2686 (format "<ol%s>" (if arg1
; FIXME
2687 (format " start=\"%d\"" arg1
)
2690 (descriptive "<dl>")))
2692 (defun org-e-html-end-plain-list (type)
2696 (descriptive "</dl>")))
2698 (defun org-e-html-plain-list (plain-list contents info
)
2699 "Transcode a PLAIN-LIST element from Org to HTML.
2700 CONTENTS is the contents of the list. INFO is a plist holding
2701 contextual information."
2702 (let* (arg1 ;; FIXME
2703 (type (org-element-property :type plain-list
))
2704 (attr (mapconcat #'identity
2705 (org-element-property :attr_html plain-list
)
2707 (org-e-html--wrap-label
2708 plain-list
(format "%s\n%s%s"
2709 (org-e-html-begin-plain-list type
)
2710 contents
(org-e-html-end-plain-list type
)))))
2714 (defun org-e-html-convert-special-strings (string)
2715 "Convert special characters in STRING to HTML."
2716 (let ((all org-e-html-special-string-regexps
)
2718 (while (setq a
(pop all
))
2719 (setq re
(car a
) rpl
(cdr a
) start
0)
2720 (while (string-match re string start
)
2721 (setq string
(replace-match rpl t nil string
))))
2724 (defun org-e-html-encode-plain-text (s)
2725 "Convert plain text characters to HTML equivalent.
2726 Possible conversions are set in `org-export-html-protect-char-alist'."
2727 (let ((cl org-e-html-protect-char-alist
) c
)
2728 (while (setq c
(pop cl
))
2730 (while (string-match (car c
) s start
)
2731 (setq s
(replace-match (cdr c
) t t s
)
2732 start
(1+ (match-beginning 0))))))
2735 (defun org-e-html-plain-text (text info
)
2736 "Transcode a TEXT string from Org to HTML.
2737 TEXT is the string to transcode. INFO is a plist holding
2738 contextual information."
2739 (setq text
(org-e-html-encode-plain-text text
))
2740 ;; Protect %, #, &, $, ~, ^, _, { and }.
2741 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2743 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2745 ;; (setq text (replace-regexp-in-string
2746 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2747 ;; "$\\backslash$" text nil t 1))
2748 ;; HTML into \HTML{} and TeX into \TeX{}.
2749 ;; (let ((case-fold-search nil)
2751 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2752 ;; (setq text (replace-match
2753 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2754 ;; start (match-end 0))))
2755 ;; Handle quotation marks
2756 ;; (setq text (org-e-html--quotation-marks text info))
2757 ;; Convert special strings.
2758 ;; (when (plist-get info :with-special-strings)
2759 ;; (while (string-match (regexp-quote "...") text)
2760 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2761 (when (plist-get info
:with-special-strings
)
2762 (setq text
(org-e-html-convert-special-strings text
)))
2763 ;; Handle break preservation if required.
2764 (when (plist-get info
:preserve-breaks
)
2765 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2773 (defun org-e-html-planning (planning contents info
)
2774 "Transcode a PLANNING element from Org to HTML.
2775 CONTENTS is nil. INFO is a plist used as a communication
2777 (let ((span-fmt "<span class=\"timestamp-kwd\">%s</span> <span class=\"timestamp\">%s</span>"))
2779 "<p><span class=\"timestamp-wrapper\">%s</span></p>"
2784 (let ((closed (org-element-property :closed planning
)))
2786 (format span-fmt org-closed-string
2787 (org-translate-time closed
))))
2788 (let ((deadline (org-element-property :deadline planning
)))
2790 (format span-fmt org-deadline-string
2791 (org-translate-time deadline
))))
2792 (let ((scheduled (org-element-property :scheduled planning
)))
2794 (format span-fmt org-scheduled-string
2795 (org-translate-time scheduled
))))))
2799 ;;;; Property Drawer
2801 (defun org-e-html-property-drawer (property-drawer contents info
)
2802 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2803 CONTENTS is nil. INFO is a plist holding contextual
2805 ;; The property drawer isn't exported but we want separating blank
2806 ;; lines nonetheless.
2812 (defun org-e-html-quote-block (quote-block contents info
)
2813 "Transcode a QUOTE-BLOCK element from Org to HTML.
2814 CONTENTS holds the contents of the block. INFO is a plist
2815 holding contextual information."
2816 (org-e-html--wrap-label
2817 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2822 (defun org-e-html-quote-section (quote-section contents info
)
2823 "Transcode a QUOTE-SECTION element from Org to HTML.
2824 CONTENTS is nil. INFO is a plist holding contextual information."
2825 (let ((value (org-remove-indentation
2826 (org-element-property :value quote-section
))))
2827 (when value
(format "<pre>\n%s</pre>" value
))))
2832 (defun org-e-html-section (section contents info
)
2833 "Transcode a SECTION element from Org to HTML.
2834 CONTENTS holds the contents of the section. INFO is a plist
2835 holding contextual information."
2836 (let ((parent (org-export-get-parent-headline section
)))
2837 ;; Before first headline: no container, just return CONTENTS.
2838 (if (not parent
) contents
2839 ;; Get div's class and id references.
2840 (let* ((class-num (+ (org-export-get-relative-level parent info
)
2841 (1- org-e-html-toplevel-hlevel
)))
2845 (org-export-get-headline-number parent info
) "-")))
2846 ;; Build return value.
2847 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2849 (or (org-element-property :custom-id parent
) section-number
)
2854 (defun org-e-html-radio-target (radio-target text info
)
2855 "Transcode a RADIO-TARGET object from Org to HTML.
2856 TEXT is the text of the target. INFO is a plist holding
2857 contextual information."
2858 (let ((id (org-export-solidify-link-text
2859 (org-element-property :value radio-target
))))
2860 (org-e-html--anchor id text
)))
2865 (defun org-e-html-special-block (special-block contents info
)
2866 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2867 CONTENTS holds the contents of the block. INFO is a plist
2868 holding contextual information."
2869 (let ((type (downcase (org-element-property :type special-block
))))
2870 (org-e-html--wrap-label
2872 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2877 (defun org-e-html-src-block (src-block contents info
)
2878 "Transcode a SRC-BLOCK element from Org to HTML.
2879 CONTENTS holds the contents of the item. INFO is a plist holding
2880 contextual information."
2881 (let* ((lang (org-element-property :language src-block
))
2882 (caption (org-element-property :caption src-block
))
2883 (label (org-element-property :name src-block
))
2884 (caption-str (org-e-html--caption/label-string caption label info
))
2885 (attr (mapconcat #'identity
2886 (org-element-property :attr_html src-block
)
2888 ;; (switches (org-element-property :switches src-block))
2889 (switches nil
) ; FIXME
2890 (textarea-p (and switches
(string-match "-t\\>" switches
)))
2891 (code (org-e-html-format-code src-block info
)))
2894 "<div class=\"org-src-container\">\n%s%s\n</div>"
2895 (if (not caption
) ""
2896 (format "<label class=\"org-src-name\">%s</label>" caption-str
))
2897 (format "\n<pre class=\"src src-%s\">%s</pre>" lang code
)))
2899 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2900 80 (string-to-number (match-string 1 switches
))))
2901 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2902 (string-to-number (match-string 1 switches
))
2903 (org-count-lines code
))))
2905 "<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s</textarea>\n</p>"
2907 (t (format "<pre class=\"example\">\n%s</pre>" code
)))))
2909 ;;;; Statistics Cookie
2911 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2912 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2913 CONTENTS is nil. INFO is a plist holding contextual information."
2914 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2915 (format "<code>%s</code>" cookie-value
)))
2920 (defun org-e-html-strike-through (strike-through contents info
)
2921 "Transcode STRIKE-THROUGH from Org to HTML.
2922 CONTENTS is the text with strike-through markup. INFO is a plist
2923 holding contextual information."
2924 (format (or (cdr (assq 'strike-through org-e-html-text-markup-alist
)) "%s")
2930 (defun org-e-html-subscript (subscript contents info
)
2931 "Transcode a SUBSCRIPT object from Org to HTML.
2932 CONTENTS is the contents of the object. INFO is a plist holding
2933 contextual information."
2934 (format "<sub>%s</sub>" contents
))
2939 (defun org-e-html-superscript (superscript contents info
)
2940 "Transcode a SUPERSCRIPT object from Org to HTML.
2941 CONTENTS is the contents of the object. INFO is a plist holding
2942 contextual information."
2943 (format "<sup>%s</sup>" contents
))
2948 (defun org-e-html-table-cell (table-cell contents info
)
2949 "Transcode a TABLE-CELL element from Org to HTML.
2950 CONTENTS is nil. INFO is a plist used as a communication
2952 (let* ((table-row (org-export-get-parent table-cell
))
2953 (table (org-export-get-parent-table table-cell
))
2955 (if (not org-e-html-table-align-individual-fields
) ""
2956 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2957 org-e-html-format-table-no-css
)
2958 " align=\"%s\"" " class=\"%s\"")
2959 (org-export-table-cell-alignment table-cell info
)))))
2960 (when (or (not contents
) (string= "" (org-trim contents
)))
2961 (setq contents
" "))
2963 ((and (org-export-table-has-header-p table info
)
2964 (= 1 (org-export-table-row-group table-row info
)))
2965 (concat "\n" (format (car org-e-html-table-header-tags
) "col" cell-attrs
)
2966 contents
(cdr org-e-html-table-header-tags
)))
2967 ((and org-e-html-table-use-header-tags-for-first-column
2968 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2969 (concat "\n" (format (car org-e-html-table-header-tags
) "row" cell-attrs
)
2970 contents
(cdr org-e-html-table-header-tags
)))
2971 (t (concat "\n" (format (car org-e-html-table-data-tags
) cell-attrs
)
2972 contents
(cdr org-e-html-table-data-tags
))))))
2977 (defun org-e-html-table-row (table-row contents info
)
2978 "Transcode a TABLE-ROW element from Org to HTML.
2979 CONTENTS is the contents of the row. INFO is a plist used as a
2980 communication channel."
2981 ;; Rules are ignored since table separators are deduced from
2982 ;; borders of the current row.
2983 (when (eq (org-element-property :type table-row
) 'standard
)
2984 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2987 ;; Case 1: Row belongs to second or subsequent rowgroups.
2988 ((not (= 1 (org-export-table-row-group table-row info
)))
2989 '("<tbody>" .
"\n</tbody>"))
2990 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2991 ((org-export-table-has-header-p
2992 (org-export-get-parent-table table-row
) info
)
2993 '("<thead>" .
"\n</thead>"))
2994 ;; Case 2: Row is from first and only row group.
2995 (t '("<tbody>" .
"\n</tbody>")))))
2997 ;; Begin a rowgroup?
2998 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2999 (car rowgroup-tags
))
3001 (concat "\n" (eval (car org-e-html-table-row-tags
))
3004 (eval (cdr org-e-html-table-row-tags
)))
3006 (when (org-export-table-row-ends-rowgroup-p table-row info
)
3007 (cdr rowgroup-tags
))))))
3012 (defun org-e-html-table-first-row-data-cells (table info
)
3017 (unless (eq (org-element-property :type row
) 'rule
) row
))
3019 (special-column-p (org-export-table-has-special-column-p table
)))
3020 (if (not special-column-p
) (org-element-contents table-row
)
3021 (cdr (org-element-contents table-row
)))))
3023 (defun org-e-html-table--table.el-table
(table info
)
3024 (when (eq (org-element-property :type table
) 'table.el
)
3026 (let ((outbuf (with-current-buffer
3027 (get-buffer-create "*org-export-table*")
3028 (erase-buffer) (current-buffer))))
3030 (insert (org-element-property :value table
))
3032 (re-search-forward "^[ \t]*|[^|]" nil t
)
3033 (table-generate-source 'html outbuf
))
3034 (with-current-buffer outbuf
3035 (prog1 (org-trim (buffer-string))
3038 (defun org-e-html-table (table contents info
)
3039 "Transcode a TABLE element from Org to HTML.
3040 CONTENTS is the contents of the table. INFO is a plist holding
3041 contextual information."
3042 (case (org-element-property :type table
)
3043 ;; Case 1: table.el table. Convert it using appropriate tools.
3044 (table.el
(org-e-html-table--table.el-table table info
))
3045 ;; Case 2: Standard table.
3047 (let* ((label (org-element-property :name table
))
3048 (caption (org-e-html--caption/label-string
3049 (org-element-property :caption table
) label info
))
3050 (attributes (mapconcat #'identity
3051 (org-element-property :attr_html table
)
3054 (if (and (boundp 'org-e-html-format-table-no-css
)
3055 org-e-html-format-table-no-css
)
3056 "align=\"%s\"" "class=\"%s\""))
3059 (lambda (table info
)
3061 (lambda (table-cell)
3062 (let ((alignment (org-export-table-cell-alignment
3065 ;; Begin a colgroup?
3066 (when (org-export-table-cell-starts-colgroup-p
3069 ;; Add a column. Also specify it's alignment.
3070 (format "\n<col %s/>" (format alignspec alignment
))
3072 (when (org-export-table-cell-ends-colgroup-p
3075 (org-e-html-table-first-row-data-cells table info
) "\n"))))
3077 (let ((table-tag (plist-get info
:html-table-tag
)))
3079 (and (string-match "<table\\(.*\\)>" table-tag
)
3080 (match-string 1 table-tag
))
3081 (and label
(format " id=\"%s\""
3082 (org-solidify-link-text label
)))))))
3083 ;; Remove last blank line.
3084 (setq contents
(substring contents
0 -
1))
3086 (format "<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
3089 (funcall table-column-specs table info
)
3094 (defun org-e-html-target (target contents info
)
3095 "Transcode a TARGET object from Org to HTML.
3096 CONTENTS is nil. INFO is a plist holding contextual
3098 (let ((id (org-export-solidify-link-text
3099 (org-element-property :value target
))))
3100 (org-e-html--anchor id
)))
3105 (defun org-e-html-timestamp (timestamp contents info
)
3106 "Transcode a TIMESTAMP object from Org to HTML.
3107 CONTENTS is nil. INFO is a plist holding contextual
3109 (let ((value (org-translate-time (org-element-property :value timestamp
))))
3110 (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
3116 (defun org-e-html-underline (underline contents info
)
3117 "Transcode UNDERLINE from Org to HTML.
3118 CONTENTS is the text with underline markup. INFO is a plist
3119 holding contextual information."
3120 (format (or (cdr (assq 'underline org-e-html-text-markup-alist
)) "%s")
3126 (defun org-e-html-verbatim (verbatim contents info
)
3127 "Transcode VERBATIM from Org to HTML.
3128 CONTENTS is nil. INFO is a plist holding contextual
3130 (format (or (cdr (assq 'verbatim org-e-html-text-markup-alist
)) "%s")
3131 (org-element-property :value verbatim
)))
3136 (defun org-e-html-verse-block (verse-block contents info
)
3137 "Transcode a VERSE-BLOCK element from Org to HTML.
3138 CONTENTS is verse block contents. INFO is a plist holding
3139 contextual information."
3140 ;; Replace each newline character with line break. Also replace
3141 ;; each blank line with a line break.
3142 (setq contents
(replace-regexp-in-string
3143 "^ *\\\\\\\\$" "<br/>\n"
3144 (replace-regexp-in-string
3145 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
3146 ;; Replace each white space at beginning of a line with a
3147 ;; non-breaking space.
3148 (while (string-match "^[ \t]+" contents
)
3149 (let* ((num-ws (length (match-string 0 contents
)))
3150 (ws (let (out) (dotimes (i num-ws out
)
3151 (setq out
(concat out
" "))))))
3152 (setq contents
(replace-match ws nil t contents
))))
3153 (org-e-html--wrap-label
3154 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
3159 ;;; Filter Functions
3161 (defun org-e-html-final-function (contents backend info
)
3162 (if (not org-e-html-pretty-output
) contents
3166 (indent-region (point-min) (point-max))
3167 (buffer-substring-no-properties (point-min) (point-max)))))
3170 ;;; Interactive functions
3173 (defun org-e-html-export-to-html
3174 (&optional subtreep visible-only body-only ext-plist pub-dir
)
3175 "Export current buffer to a HTML file.
3177 If narrowing is active in the current buffer, only export its
3180 If a region is active, export that region.
3182 When optional argument SUBTREEP is non-nil, export the sub-tree
3183 at point, extracting information from the headline properties
3186 When optional argument VISIBLE-ONLY is non-nil, don't export
3187 contents of hidden elements.
3189 When optional argument BODY-ONLY is non-nil, only write code
3190 between \"\\begin{document}\" and \"\\end{document}\".
3192 EXT-PLIST, when provided, is a property list with external
3193 parameters overriding Org default settings, but still inferior to
3194 file-local settings.
3196 When optional argument PUB-DIR is set, use it as the publishing
3199 Return output file's name."
3201 (setq debug-on-error t
) ; FIXME
3202 (let* ((extension (concat "." org-e-html-extension
))
3203 (file (org-export-output-file-name extension subtreep pub-dir
))
3204 (org-export-coding-system org-e-html-coding-system
))
3206 'e-html file subtreep visible-only body-only ext-plist
)))
3210 ;;; FIXMES, TODOS, FOR REVIEW etc
3212 ;;;; org-format-table-html
3213 ;;;; org-format-org-table-html
3214 ;;;; org-format-table-table-html
3215 ;;;; org-table-number-fraction
3216 ;;;; org-table-number-regexp
3217 ;;;; org-e-html-table-caption-above
3220 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3221 ;;;; Remove display properties
3223 ;;;; org-e-html-with-timestamp
3224 ;;;; org-e-html-html-helper-timestamp
3226 ;;;; org-export-as-html-and-open
3227 ;;;; org-export-as-html-batch
3228 ;;;; org-export-as-html-to-buffer
3229 ;;;; org-replace-region-by-html
3230 ;;;; org-export-region-as-html
3231 ;;;; org-export-as-html
3233 ;;;; (org-export-directory :html opt-plist)
3234 ;;;; (plist-get opt-plist :html-extension)
3235 ;;;; org-e-html-toplevel-hlevel
3236 ;;;; org-e-html-special-string-regexps
3237 ;;;; org-e-html-inline-images
3238 ;;;; org-e-html-inline-image-extensions
3239 ;;;; org-e-html-protect-char-alist
3240 ;;;; org-e-html-table-use-header-tags-for-first-column
3241 ;;;; org-e-html-todo-kwd-class-prefix
3242 ;;;; org-e-html-tag-class-prefix
3243 ;;;; org-e-html-footnote-separator
3245 ;;;; org-export-preferred-target-alist
3246 ;;;; org-solidify-link-text
3247 ;;;; class for anchors
3248 ;;;; org-export-with-section-numbers, body-only
3249 ;;;; org-export-mark-todo-in-toc
3251 (provide 'org-e-html
)
3252 ;;; org-e-html.el ends here