1 ;;; org-e-html.el --- HTML Back-End For Org Export Engine
3 ;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
5 ;; Author: Jambunathan K <kjambunathan at gmail dot com>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; This library implements a HTML back-end for Org generic exporter.
27 ;; M-: (org-export-to-buffer 'e-html "*Test e-HTML*") RET
29 ;; in an org-mode buffer then switch to the buffer to see the HTML
30 ;; export. See contrib/lisp/org-export.el for more details on how
31 ;; this exporter works.
38 (require 'format-spec
)
39 (eval-when-compile (require 'cl
) (require 'table
))
43 ;;; Function Declarations
45 (declare-function org-element-get-property
"org-element" (property element
))
46 (declare-function org-element-normalize-string
"org-element" (s))
47 (declare-function org-element-parse-secondary-string
48 "org-element" (string restriction
&optional buffer
))
49 (defvar org-element-string-restrictions
)
50 (defvar org-element-object-restrictions
)
52 (declare-function org-export-data
"org-export" (data info
))
53 (declare-function org-export-directory
"org-export" (type plist
))
54 (declare-function org-export-expand-macro
"org-export" (macro info
))
55 (declare-function org-export-first-sibling-p
"org-export" (headline info
))
56 (declare-function org-export-footnote-first-reference-p
"org-export"
57 (footnote-reference info
))
58 (declare-function org-export-get-coderef-format
"org-export" (path desc
))
59 (declare-function org-export-get-footnote-definition
"org-export"
60 (footnote-reference info
))
61 (declare-function org-export-get-footnote-number
"org-export" (footnote info
))
62 (declare-function org-export-get-previous-element
"org-export" (blob info
))
63 (declare-function org-export-get-relative-level
"org-export" (headline info
))
64 (declare-function org-export-handle-code
65 "org-export" (element info
&optional num-fmt ref-fmt delayed
))
66 (declare-function org-export-inline-image-p
"org-export"
67 (link &optional extensions
))
68 (declare-function org-export-last-sibling-p
"org-export" (headline info
))
69 (declare-function org-export-low-level-p
"org-export" (headline info
))
70 (declare-function org-export-output-file-name
71 "org-export" (extension &optional subtreep pub-dir
))
72 (declare-function org-export-resolve-coderef
"org-export" (ref info
))
73 (declare-function org-export-resolve-fuzzy-link
"org-export" (link info
))
74 (declare-function org-export-secondary-string
"org-export" (secondary info
))
75 (declare-function org-export-solidify-link-text
"org-export" (s))
77 org-export-to-buffer
"org-export"
78 (backend buffer
&optional subtreep visible-only body-only ext-plist
))
80 org-export-to-file
"org-export"
81 (backend file
&optional subtreep visible-only body-only ext-plist
))
83 (declare-function org-id-find-id-file
"org-id" (id))
84 (declare-function htmlize-region
"ext:htmlize" (beg end
))
85 (declare-function org-pop-to-buffer-same-window
86 "org-compat" (&optional buffer-or-name norecord label
))
91 ;;; Internal Variables
93 (defconst org-e-html-option-alist
94 '((:agenda-style nil nil org-agenda-export-html-style
)
95 (:convert-org-links nil nil org-e-html-link-org-files-as-html
)
96 ;; FIXME Use (org-xml-encode-org-text-skip-links s) ??
97 ;; (:expand-quoted-html nil "@" org-e-html-expand)
98 (:inline-images nil nil org-e-html-inline-images
)
99 ;; (:link-home nil nil org-e-html-link-home) FIXME
100 ;; (:link-up nil nil org-e-html-link-up) FIXME
101 (:style nil nil org-e-html-style
)
102 (:style-extra nil nil org-e-html-style-extra
)
103 (:style-include-default nil nil org-e-html-style-include-default
)
104 (:style-include-scripts nil nil org-e-html-style-include-scripts
)
105 ;; (:timestamp nil nil org-e-html-with-timestamp)
106 (:html-extension nil nil org-e-html-extension
)
107 (:html-postamble nil nil org-e-html-postamble
)
108 (:html-preamble nil nil org-e-html-preamble
)
109 (:html-table-tag nil nil org-e-html-table-tag
)
110 (:xml-declaration nil nil org-e-html-xml-declaration
)
111 (:LaTeX-fragments nil
"LaTeX" org-export-with-LaTeX-fragments
)
112 (:mathjax
"MATHJAX" nil
"" space
))
113 "Alist between export properties and ways to set them.
115 The car of the alist is the property name, and the cdr is a list
116 like \(KEYWORD OPTION DEFAULT BEHAVIOUR\) where:
118 KEYWORD is a string representing a buffer keyword, or nil.
119 OPTION is a string that could be found in an #+OPTIONS: line.
120 DEFAULT is the default value for the property.
121 BEHAVIOUR determine how Org should handle multiple keywords for
122 the same property. It is a symbol among:
123 nil Keep old value and discard the new one.
124 t Replace old value with the new one.
125 `space' Concatenate the values, separating them with a space.
126 `newline' Concatenate the values, separating them with
128 `split' Split values at white spaces, and cons them to the
131 KEYWORD and OPTION have precedence over DEFAULT.
133 All these properties should be back-end agnostic. For back-end
134 specific properties, define a similar variable named
135 `org-BACKEND-option-alist', replacing BACKEND with the name of
136 the appropriate back-end. You can also redefine properties
137 there, as they have precedence over these.")
139 ;; FIXME: it already exists in org-e-html.el
140 (defconst org-e-html-cvt-link-fn
142 "Function to convert link URLs to exportable URLs.
143 Takes two arguments, TYPE and PATH.
144 Returns exportable url as (TYPE PATH), or nil to signal that it
145 didn't handle this case.
146 Intended to be locally bound around a call to `org-export-as-html'." )
151 (defvar org-e-html-format-table-no-css
)
152 (defvar htmlize-buffer-places
) ; from htmlize.el
153 (defvar body-only
) ; dynamically scoped into this.
157 ;;; User Configuration Variables
159 (defgroup org-export-e-html nil
160 "Options for exporting Org mode files to HTML."
161 :tag
"Org Export HTML"
166 (defcustom org-e-html-pretty-output nil
167 "Enable this to generate pretty HTML."
168 :group
'org-export-e-html
174 (defcustom org-e-html-extension
"html"
175 "The extension for exported HTML files."
176 :group
'org-export-e-html
179 (defcustom org-e-html-xml-declaration
180 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
181 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
182 "The extension for exported HTML files.
183 %s will be replaced with the charset of the exported file.
184 This may be a string, or an alist with export extensions
185 and corresponding declarations."
186 :group
'org-export-e-html
188 (string :tag
"Single declaration")
189 (repeat :tag
"Dependent on extension"
190 (cons (string :tag
"Extension")
191 (string :tag
"Declaration")))))
193 ;; Use `org-export-coding-system' instead
194 ;; (defcustom org-e-html-coding-system nil
195 ;; "Coding system for HTML export, defaults to `buffer-file-coding-system'."
196 ;; :group 'org-export-e-html
197 ;; :type 'coding-system)
199 (defvar org-e-html-content-div
"content"
200 "The name of the container DIV that holds all the page contents.
202 This variable is obsolete since Org version 7.7.
203 Please set `org-e-html-divs' instead.")
205 (defcustom org-e-html-divs
'("preamble" "content" "postamble")
206 "The name of the main divs for HTML export.
207 This is a list of three strings, the first one for the preamble
208 DIV, the second one for the content DIV and the third one for the
210 :group
'org-export-e-html
212 (string :tag
" Div for the preamble:")
213 (string :tag
" Div for the content:")
214 (string :tag
"Div for the postamble:")))
217 ;;;; Document Header (Styles)
219 (defconst org-e-html-style-default
220 "<style type=\"text/css\">
221 <!--/*--><![CDATA[/*><!--*/
222 html { font-family: Times, serif; font-size: 12pt; }
223 .title { text-align: center; }
224 .todo { color: red; }
225 .done { color: green; }
226 .tag { background-color: #add8e6; font-weight:normal }
228 .timestamp { color: #bebebe; }
229 .timestamp-kwd { color: #5f9ea0; }
230 .right {margin-left:auto; margin-right:0px; text-align:right;}
231 .left {margin-left:0px; margin-right:auto; text-align:left;}
232 .center {margin-left:auto; margin-right:auto; text-align:center;}
233 p.verse { margin-left: 3% }
235 border: 1pt solid #AEBDCC;
236 background-color: #F3F5F7;
238 font-family: courier, monospace;
242 table { border-collapse: collapse; }
243 td, th { vertical-align: top; }
244 th.right { text-align:center; }
245 th.left { text-align:center; }
246 th.center { text-align:center; }
247 td.right { text-align:right; }
248 td.left { text-align:left; }
249 td.center { text-align:center; }
250 dt { font-weight: bold; }
251 div.figure { padding: 0.5em; }
252 div.figure p { text-align: center; }
255 border:2px solid gray;
259 textarea { overflow-x: auto; }
260 .linenr { font-size:smaller }
261 .code-highlighted {background-color:#ffff00;}
262 .org-info-js_info-navigation { border-style:none; }
263 #org-info-js_console-label { font-size:10px; font-weight:bold;
264 white-space:nowrap; }
265 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
269 "The default style specification for exported HTML files.
270 Please use the variables `org-e-html-style' and
271 `org-e-html-style-extra' to add to this style. If you wish to not
272 have the default style included, customize the variable
273 `org-e-html-style-include-default'.")
275 (defcustom org-e-html-style-include-default t
276 "Non-nil means include the default style in exported HTML files.
277 The actual style is defined in `org-e-html-style-default' and should
278 not be modified. Use the variables `org-e-html-style' to add
279 your own style information."
280 :group
'org-export-e-html
283 (put 'org-e-html-style-include-default
'safe-local-variable
'booleanp
)
285 (defcustom org-e-html-style
""
286 "Org-wide style definitions for exported HTML files.
288 This variable needs to contain the full HTML structure to provide a style,
289 including the surrounding HTML tags. If you set the value of this variable,
290 you should consider to include definitions for the following classes:
291 title, todo, done, timestamp, timestamp-kwd, tag, target.
293 For example, a valid value would be:
295 <style type=\"text/css\">
297 p { font-weight: normal; color: gray; }
299 .title { text-align: center; }
300 .todo, .timestamp-kwd { color: red; }
301 .done { color: green; }
305 If you'd like to refer to an external style file, use something like
307 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
309 As the value of this option simply gets inserted into the HTML <head> header,
310 you can \"misuse\" it to add arbitrary text to the header.
311 See also the variable `org-e-html-style-extra'."
312 :group
'org-export-e-html
315 (put 'org-e-html-style
'safe-local-variable
'stringp
)
317 (defcustom org-e-html-style-extra
""
318 "Additional style information for HTML export.
319 The value of this variable is inserted into the HTML buffer right after
320 the value of `org-e-html-style'. Use this variable for per-file
321 settings of style information, and do not forget to surround the style
322 settings with <style>...</style> tags."
323 :group
'org-export-e-html
326 (put 'org-e-html-style-extra
'safe-local-variable
'stringp
)
328 (defcustom org-e-html-mathjax-options
329 '((path "http://orgmode.org/mathjax/MathJax.js")
334 "Options for MathJax setup.
336 path The path where to find MathJax
337 scale Scaling for the HTML-CSS backend, usually between 100 and 133
338 align How to align display math: left, center, or right
339 indent If align is not center, how far from the left/right side?
340 mathml Should a MathML player be used if available?
341 This is faster and reduces bandwidth use, but currently
342 sometimes has lower spacing quality. Therefore, the default is
343 nil. When browsers get better, this switch can be flipped.
345 You can also customize this for each buffer, using something like
347 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
348 :group
'org-export-e-html
349 :type
'(list :greedy t
350 (list :tag
"path (the path from where to load MathJax.js)"
351 (const :format
" " path
) (string))
352 (list :tag
"scale (scaling for the displayed math)"
353 (const :format
" " scale
) (string))
354 (list :tag
"align (alignment of displayed equations)"
355 (const :format
" " align
) (string))
356 (list :tag
"indent (indentation with left or right alignment)"
357 (const :format
" " indent
) (string))
358 (list :tag
"mathml (should MathML display be used is possible)"
359 (const :format
" " mathml
) (boolean))))
362 ;;;; Document Header (Scripts)
364 (defcustom org-e-html-style-include-scripts t
365 "Non-nil means include the JavaScript snippets in exported HTML files.
366 The actual script is defined in `org-e-html-scripts' and should
368 :group
'org-export-e-html
371 (defconst org-e-html-scripts
372 "<script type=\"text/javascript\">
373 <!--/*--><![CDATA[/*><!--*/
374 function CodeHighlightOn(elem, id)
376 var target = document.getElementById(id);
378 elem.cacheClassElem = elem.className;
379 elem.cacheClassTarget = target.className;
380 target.className = \"code-highlighted\";
381 elem.className = \"code-highlighted\";
384 function CodeHighlightOff(elem, id)
386 var target = document.getElementById(id);
387 if(elem.cacheClassElem)
388 elem.className = elem.cacheClassElem;
389 if(elem.cacheClassTarget)
390 target.className = elem.cacheClassTarget;
394 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
397 ;;;; Document Header (Mathjax)
399 (defcustom org-e-html-mathjax-template
400 "<script type=\"text/javascript\" src=\"%PATH\">
401 <!--/*--><![CDATA[/*><!--*/
403 // Only one of the two following lines, depending on user settings
404 // First allows browser-native MathML display, second forces HTML/CSS
405 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
406 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
407 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
408 \"TeX/noUndefined.js\"],
410 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
411 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
412 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
413 ignoreClass: \"tex2jax_ignore\",
414 processEscapes: false,
415 processEnvironments: true,
418 showProcessingMessages: true,
419 displayAlign: \"%ALIGN\",
420 displayIndent: \"%INDENT\",
424 availableFonts: [\"STIX\",\"TeX\"],
425 preferredFont: \"TeX\",
441 "The MathJax setup for XHTML files."
442 :group
'org-export-e-html
448 (defcustom org-e-html-preamble t
449 "Non-nil means insert a preamble in HTML export.
451 When `t', insert a string as defined by one of the formatting
452 strings in `org-e-html-preamble-format'. When set to a
453 string, this string overrides `org-e-html-preamble-format'.
454 When set to a function, apply this function and insert the
455 returned string. The function takes the property list of export
456 options as its only argument.
458 Setting :html-preamble in publishing projects will take
459 precedence over this variable."
460 :group
'org-export-e-html
461 :type
'(choice (const :tag
"No preamble" nil
)
462 (const :tag
"Default preamble" t
)
463 (string :tag
"Custom formatting string")
464 (function :tag
"Function (must return a string)")))
466 (defcustom org-e-html-preamble-format
'(("en" ""))
467 "The format for the HTML preamble.
469 %t stands for the title.
470 %a stands for the author's name.
471 %e stands for the author's email.
472 %d stands for the date.
474 If you need to use a \"%\" character, you need to escape it
476 :group
'org-export-e-html
479 (defcustom org-e-html-home
/up-format
480 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
481 <a accesskey=\"h\" href=\"%s\"> UP </a>
483 <a accesskey=\"H\" href=\"%s\"> HOME </a>
485 "Snippet used to insert the HOME and UP links.
486 This is a format string, the first %s will receive the UP link,
487 the second the HOME link. If both `org-e-html-link-up' and
488 `org-e-html-link-home' are empty, the entire snippet will be
490 :group
'org-export-e-html
495 (defcustom org-e-html-postamble
'auto
496 "Non-nil means insert a postamble in HTML export.
498 When `t', insert a string as defined by the formatting string in
499 `org-e-html-postamble-format'. When set to a string, this
500 string overrides `org-e-html-postamble-format'. When set to
501 'auto, discard `org-e-html-postamble-format' and honor
502 `org-export-author/email/creator-info' variables. When set to a
503 function, apply this function and insert the returned string.
504 The function takes the property list of export options as its
507 Setting :html-postamble in publishing projects will take
508 precedence over this variable."
509 :group
'org-export-e-html
510 :type
'(choice (const :tag
"No postamble" nil
)
511 (const :tag
"Auto preamble" 'auto
)
512 (const :tag
"Default formatting string" t
)
513 (string :tag
"Custom formatting string")
514 (function :tag
"Function (must return a string)")))
516 (defcustom org-e-html-postamble-format
517 '(("en" "<p class=\"author\">Author: %a (%e)</p>
518 <p class=\"date\">Date: %d</p>
519 <p class=\"creator\">Generated by %c</p>
520 <p class=\"xhtml-validation\">%v</p>
522 "The format for the HTML postamble.
524 %a stands for the author's name.
525 %e stands for the author's email.
526 %d stands for the date.
527 %c will be replaced by information about Org/Emacs versions.
528 %v will be replaced by `org-e-html-validation-link'.
530 If you need to use a \"%\" character, you need to escape it
532 :group
'org-export-e-html
535 (defcustom org-e-html-validation-link
536 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
537 "Link to HTML validation service."
538 :group
'org-export-e-html
541 ;; FIXME Obsolete since Org 7.7
542 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
545 (defcustom org-e-html-protect-char-alist
549 "Alist of characters to be converted by `org-e-html-protect'."
550 :group
'org-export-e-html
551 :type
'(repeat (cons (string :tag
"Character")
552 (string :tag
"HTML equivalent"))))
554 (defconst org-e-html-special-string-regexps
555 '(("\\\\-" .
"­")
556 ("---\\([^-]\\)" .
"—\\1")
557 ("--\\([^-]\\)" .
"–\\1")
558 ("\\.\\.\\." .
"…"))
559 "Regular expressions for special string conversion.")
564 (defcustom org-e-html-todo-kwd-class-prefix
""
565 "Prefix to class names for TODO keywords.
566 Each TODO keyword gets a class given by the keyword itself, with this prefix.
567 The default prefix is empty because it is nice to just use the keyword
568 as a class name. But if you get into conflicts with other, existing
569 CSS classes, then this prefix can be very useful."
570 :group
'org-export-e-html
576 (defcustom org-e-html-tag-class-prefix
""
577 "Prefix to class names for TODO keywords.
578 Each tag gets a class given by the tag itself, with this prefix.
579 The default prefix is empty because it is nice to just use the keyword
580 as a class name. But if you get into conflicts with other, existing
581 CSS classes, then this prefix can be very useful."
582 :group
'org-export-e-html
586 ;;;; Statistics Cookie
592 (defcustom org-e-html-inline-images
'maybe
593 "Non-nil means inline images into exported HTML pages.
594 This is done using an <img> tag. When nil, an anchor with href is used to
595 link to the image. If this option is `maybe', then images in links with
596 an empty description will be inlined, while images with a description will
598 :group
'org-export-e-html
599 :type
'(choice (const :tag
"Never" nil
)
600 (const :tag
"Always" t
)
601 (const :tag
"When there is no description" maybe
)))
603 (defcustom org-e-html-inline-image-extensions
604 '("png" "jpeg" "jpg" "gif" "svg")
605 "Extensions of image files that can be inlined into HTML."
606 :group
'org-export-e-html
607 :type
'(repeat (string :tag
"Extension")))
623 (defcustom org-e-html-footnotes-section
"<div id=\"footnotes\">
624 <h2 class=\"footnotes\">%s: </h2>
625 <div id=\"text-footnotes\">
629 "Format for the footnotes section.
630 Should contain a two instances of %s. The first will be replaced with the
631 language-specific word for \"Footnotes\", the second one will be replaced
632 by the footnotes themselves."
633 :group
'org-export-e-html
636 (defcustom org-e-html-footnote-format
"<sup>%s</sup>"
637 "The format for the footnote reference.
638 %s will be replaced by the footnote reference itself."
639 :group
'org-export-e-html
642 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
643 "Text used to separate footnotes."
644 :group
'org-export-e-html
650 ;;;; Inline Babel Call
651 ;;;; Inline Src Block
655 ;;;; Latex Environment
672 (defgroup org-export-e-htmlize nil
673 "Options for processing examples with htmlize.el."
674 :tag
"Org Export Htmlize"
675 :group
'org-export-e-html
)
677 (defcustom org-export-e-htmlize-output-type
'inline-css
678 "Output type to be used by htmlize when formatting code snippets.
679 Choices are `css', to export the CSS selectors only, or `inline-css', to
680 export the CSS attribute values inline in the HTML. We use as default
681 `inline-css', in order to make the resulting HTML self-containing.
683 However, this will fail when using Emacs in batch mode for export, because
684 then no rich font definitions are in place. It will also not be good if
685 people with different Emacs setup contribute HTML files to a website,
686 because the fonts will represent the individual setups. In these cases,
687 it is much better to let Org/Htmlize assign classes only, and to use
688 a style file to define the look of these classes.
689 To get a start for your css file, start Emacs session and make sure that
690 all the faces you are interested in are defined, for example by loading files
691 in all modes you want. Then, use the command
692 \\[org-export-e-htmlize-generate-css] to extract class definitions."
693 :group
'org-export-e-htmlize
694 :type
'(choice (const css
) (const inline-css
)))
696 (defcustom org-export-e-htmlize-css-font-prefix
"org-"
697 "The prefix for CSS class names for htmlize font specifications."
698 :group
'org-export-e-htmlize
701 (defcustom org-export-e-htmlized-org-css-url nil
702 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
703 Normally when creating an htmlized version of an Org buffer, htmlize will
704 create CSS to define the font colors. However, this does not work when
705 converting in batch mode, and it also can look bad if different people
706 with different fontification setup work on the same website.
707 When this variable is non-nil, creating an htmlized version of an Org buffer
708 using `org-export-as-org' will remove the internal CSS section and replace it
709 with a link to this URL."
710 :group
'org-export-e-htmlize
712 (const :tag
"Keep internal css" nil
)
713 (string :tag
"URL or local href")))
718 (defcustom org-e-html-table-tag
719 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
720 "The HTML tag that is used to start a table.
721 This must be a <table> tag, but you may change the options like
722 borders and spacing."
723 :group
'org-export-e-html
726 (defcustom org-e-html-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
727 "The opening tag for table header fields.
728 This is customizable so that alignment options can be specified.
729 The first %s will be filled with the scope of the field, either row or col.
730 The second %s will be replaced by a style entry to align the field.
731 See also the variable `org-e-html-table-use-header-tags-for-first-column'.
732 See also the variable `org-e-html-table-align-individual-fields'."
733 :group
'org-export-tables
; FIXME: change group?
734 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
736 (defcustom org-e-html-table-data-tags
'("<td%s>" .
"</td>")
737 "The opening tag for table data fields.
738 This is customizable so that alignment options can be specified.
739 The first %s will be filled with the scope of the field, either row or col.
740 The second %s will be replaced by a style entry to align the field.
741 See also the variable `org-e-html-table-align-individual-fields'."
742 :group
'org-export-tables
743 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
745 (defcustom org-e-html-table-row-tags
'("<tr>" .
"</tr>")
746 "The opening tag for table data fields.
747 This is customizable so that alignment options can be specified.
748 Instead of strings, these can be Lisp forms that will be evaluated
749 for each row in order to construct the table row tags. During evaluation,
750 the variable `head' will be true when this is a header line, nil when this
751 is a body line. And the variable `nline' will contain the line number,
752 starting from 1 in the first header line. For example
754 (setq org-e-html-table-row-tags
757 (if (= (mod nline 2) 1)
758 \"<tr class=\\\"tr-odd\\\">\"
759 \"<tr class=\\\"tr-even\\\">\"))
762 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
763 :group
'org-export-tables
765 (choice :tag
"Opening tag"
766 (string :tag
"Specify")
768 (choice :tag
"Closing tag"
769 (string :tag
"Specify")
772 (defcustom org-e-html-table-align-individual-fields t
773 "Non-nil means attach style attributes for alignment to each table field.
774 When nil, alignment will only be specified in the column tags, but this
775 is ignored by some browsers (like Firefox, Safari). Opera does it right
777 :group
'org-export-tables
780 (defcustom org-e-html-table-use-header-tags-for-first-column nil
781 "Non-nil means format column one in tables with header tags.
782 When nil, also column one will use data tags."
783 :group
'org-export-tables
794 (defcustom org-e-html-toplevel-hlevel
2
795 "The <H> level for level 1 headings in HTML export.
796 This is also important for the classes that will be wrapped around headlines
797 and outline structure. If this variable is 1, the top-level headlines will
798 be <h1>, and the corresponding classes will be outline-1, section-number-1,
799 and outline-text-1. If this is 2, all of these will get a 2 instead.
800 The default for this variable is 2, because we use <h1> for formatting the
802 :group
'org-export-e-html
811 (defcustom org-e-html-link-org-files-as-html t
812 "Non-nil means make file links to `file.org' point to `file.html'.
813 When org-mode is exporting an org-mode file to HTML, links to
814 non-html files are directly put into a href tag in HTML.
815 However, links to other Org-mode files (recognized by the
816 extension `.org.) should become links to the corresponding html
817 file, assuming that the linked org-mode file will also be
819 When nil, the links still point to the plain `.org' file."
820 :group
'org-export-e-html
828 ;;; User Configurable Variables (MAYBE)
832 (defcustom org-e-html-date-format
834 "Format string for \\date{...}."
835 :group
'org-export-e-html
840 (defcustom org-e-html-format-headline-function nil
841 "Function to format headline text.
843 This function will be called with 5 arguments:
844 TODO the todo keyword \(string or nil\).
845 TODO-TYPE the type of todo \(symbol: `todo', `done', nil\)
846 PRIORITY the priority of the headline \(integer or nil\)
847 TEXT the main headline text \(string\).
848 TAGS the tags string, separated with colons \(string or nil\).
850 The function result will be used in the section format string.
852 As an example, one could set the variable to the following, in
853 order to reproduce the default set-up:
855 \(defun org-e-html-format-headline \(todo todo-type priority text tags\)
856 \"Default format function for an headline.\"
858 \(format \"\\\\textbf{\\\\textsc{\\\\textsf{%s}}} \" todo\)\)
860 \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
862 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)"
863 :group
'org-export-e-html
868 (defcustom org-e-html-emphasis-alist
869 '(("*" .
"<b>%s</b>")
871 ("_" .
"<span style=\"text-decoration:underline;\">%s</span>")
872 ("+" .
"<del>%s</del>")
873 ("=" .
"<code>%s</code>")
874 ("~" .
"<code>%s</code>"))
875 "Alist of HTML expressions to convert emphasis fontifiers.
877 The key is the character used as a marker for fontification. The
878 value is a formatting string to wrap fontified text with.
880 Value can also be set to the following symbols: `verb' and
881 `protectedtexttt'. For the former, Org will use \"\\verb\" to
882 create a format string and select a delimiter character that
883 isn't in the string. For the latter, Org will use \"\\texttt\"
884 to typeset and try to protect special characters."
885 :group
'org-export-e-html
891 (defcustom org-e-html-footnote-separator
"<sup>, </sup>"
892 "Text used to separate footnotes."
893 :group
'org-export-e-html
899 (defcustom org-e-html-active-timestamp-format
"\\textit{%s}"
900 "A printf format string to be applied to active time-stamps."
901 :group
'org-export-e-html
904 (defcustom org-e-html-inactive-timestamp-format
"\\textit{%s}"
905 "A printf format string to be applied to inactive time-stamps."
906 :group
'org-export-e-html
909 (defcustom org-e-html-diary-timestamp-format
"\\textit{%s}"
910 "A printf format string to be applied to diary time-stamps."
911 :group
'org-export-e-html
917 (defcustom org-e-html-inline-image-rules
918 '(("file" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
919 ("http" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'")
920 ("https" .
"\\.\\(jpeg\\|jpg\\|png\\|gif\\|svg\\)\\'"))
921 "Rules characterizing image files that can be inlined into HTML.
923 A rule consists in an association whose key is the type of link
924 to consider, and value is a regexp that will be matched against
927 Note that, by default, the image extension *actually* allowed
928 depend on the way the HTML file is processed. When used with
929 pdflatex, pdf, jpg and png images are OK. When processing
930 through dvi to Postscript, only ps and eps are allowed. The
931 default we use here encompasses both."
932 :group
'org-export-e-html
933 :type
'(alist :key-type
(string :tag
"Type")
934 :value-type
(regexp :tag
"Path")))
938 (defcustom org-e-html-table-caption-above t
939 "When non-nil, place caption string at the beginning of the table.
940 Otherwise, place it near the end."
941 :group
'org-export-e-html
946 (defcustom org-e-html-format-drawer-function nil
947 "Function called to format a drawer in HTML code.
949 The function must accept two parameters:
950 NAME the drawer name, like \"LOGBOOK\"
951 CONTENTS the contents of the drawer.
953 The function should return the string to be exported.
955 For example, the variable could be set to the following function
956 in order to mimic default behaviour:
958 \(defun org-e-html-format-drawer-default \(name contents\)
959 \"Format a drawer element for HTML export.\"
961 :group
'org-export-e-html
967 (defcustom org-e-html-format-inlinetask-function nil
968 "Function called to format an inlinetask in HTML code.
970 The function must accept six parameters:
971 TODO the todo keyword, as a string
972 TODO-TYPE the todo type, a symbol among `todo', `done' and nil.
973 PRIORITY the inlinetask priority, as a string
974 NAME the inlinetask name, as a string.
975 TAGS the inlinetask tags, as a string.
976 CONTENTS the contents of the inlinetask, as a string.
978 The function should return the string to be exported.
980 For example, the variable could be set to the following function
981 in order to mimic default behaviour:
983 \(defun org-e-html-format-inlinetask \(todo type priority name tags contents\)
984 \"Format an inline task element for HTML export.\"
988 \(format \"\\\\textbf{\\\\textsf{\\\\textsc{%s}}} \" todo\)\)
989 \(when priority \(format \"\\\\framebox{\\\\#%c} \" priority\)\)
991 \(when tags \(format \"\\\\hfill{}\\\\textsc{%s}\" tags\)\)\)\)\)
992 \(format \(concat \"\\\\begin{center}\\n\"
994 \"\\\\begin{minipage}[c]{.6\\\\textwidth}\\n\"
996 \"\\\\rule[.8em]{\\\\textwidth}{2pt}\\n\\n\"
998 \"\\\\end{minipage}}\"
999 \"\\\\end{center}\"\)
1000 full-title contents\)\)"
1001 :group
'org-export-e-html
1009 (defcustom org-e-html-quotes
1011 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"«~")
1012 ("\\(\\S-\\)\"" .
"~»")
1013 ("\\(\\s-\\|(\\|^\\)'" .
"'"))
1015 ("\\(\\s-\\|[[(]\\|^\\)\"" .
"``")
1016 ("\\(\\S-\\)\"" .
"''")
1017 ("\\(\\s-\\|(\\|^\\)'" .
"`")))
1018 "Alist for quotes to use when converting english double-quotes.
1020 The CAR of each item in this alist is the language code.
1021 The CDR of each item in this alist is a list of three CONS:
1022 - the first CONS defines the opening quote;
1023 - the second CONS defines the closing quote;
1024 - the last CONS defines single quotes.
1026 For each item in a CONS, the first string is a regexp
1027 for allowed characters before/after the quote, the second
1028 string defines the replacement string for this quote."
1029 :group
'org-export-e-html
1031 (cons :tag
"Opening quote"
1032 (string :tag
"Regexp for char before")
1033 (string :tag
"Replacement quote "))
1034 (cons :tag
"Closing quote"
1035 (string :tag
"Regexp for char after ")
1036 (string :tag
"Replacement quote "))
1037 (cons :tag
"Single quote"
1038 (string :tag
"Regexp for char before")
1039 (string :tag
"Replacement quote "))))
1045 ;;; Internal Functions (HTML)
1047 (defun org-e-html-cvt-org-as-html (opt-plist type path
)
1048 "Convert an org filename to an equivalent html filename.
1049 If TYPE is not file, just return `nil'.
1050 See variable `org-e-html-link-org-files-as-html'."
1053 org-e-html-link-org-files-as-html
1054 (string= type
"file")
1055 (string-match "\\.org$" path
)
1060 (substring path
0 (match-beginning 0))
1061 "." (plist-get opt-plist
:html-extension
)))))))
1063 (defun org-e-html-format-org-link (opt-plist type-1 path fragment desc attr
1066 OPT-PLIST is an options list.
1067 TYPE is the device-type of the link (THIS://foo.html).
1068 PATH is the path of the link (http://THIS#location).
1069 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
1070 DESC is the link description, if any.
1071 ATTR is a string of other attributes of the \"a\" element."
1072 (declare (special org-lparse-par-open
))
1074 (let* ((may-inline-p
1075 (and (member type-1
'("http" "https" "file"))
1076 (org-lparse-should-inline-p path descp
)
1078 (type (if (equal type-1
"id") "file" type-1
))
1080 ;;First pass. Just sanity stuff.
1083 ((string= type
"file")
1086 ;;Substitute just if original path was absolute.
1087 ;;(Otherwise path must remain relative)
1088 (if (file-name-absolute-p path
)
1089 (concat "file://" (expand-file-name path
))
1093 (t (list type path
))))
1095 ;;Second pass. Components converted so they can refer
1099 (and org-e-html-cvt-link-fn
1100 (apply org-e-html-cvt-link-fn
1101 opt-plist components-1
))
1102 (apply #'org-e-html-cvt-org-as-html
1103 opt-plist components-1
)
1105 (type (first components-2
))
1106 (thefile (second components-2
)))
1109 ;;Third pass. Build final link except for leading type
1114 (string= type
"http")
1115 (string= type
"https")
1116 (string= type
"file")
1117 (string= type
"coderef"))
1119 (setq thefile
(concat thefile
"#" fragment
))))
1123 ;;Final URL-build, for all types.
1126 ((str (org-xml-format-href thefile
)))
1127 (if (and type
(not (or (string= "file" type
)
1128 (string= "coderef" type
))))
1129 (concat type
":" str
)
1133 (ignore) ;; (org-e-html-format-image thefile)
1135 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
1137 ;; (caption (and caption (org-xml-encode-org-text caption)))
1138 ;; alt = (file-name-nondirectory path)
1140 (defun org-e-html-format-inline-image (src &optional
1141 caption label attr standalone-p
)
1142 (let* ((id (if (not label
) ""
1143 (format " id=\"%s\"" (org-export-solidify-link-text label
))))
1146 ((string-match "\\<alt=" (or attr
"")) "")
1147 ((string-match "^ltxpng/" src
)
1148 (format " alt=\"%s\""
1149 (org-e-html-encode-plain-text
1150 (org-find-text-property-in-string
1151 'org-latex-src src
))))
1152 (t (format " alt=\"%s\""
1153 (file-name-nondirectory src
)))))))
1156 (let ((img (format "<img src=\"%s\" %s/>" src attr
)))
1157 (format "\n<div%s class=\"figure\">%s%s\n</div>"
1158 id
(format "\n<p>%s</p>" img
)
1159 (when caption
(format "\n<p>%s</p>" caption
)))))
1160 (t (format "<img src=\"%s\" %s/>" src
(concat attr id
))))))
1164 (defun org-e-html-bibliography ()
1165 "Find bibliography, cut it out and return it."
1167 (let (beg end
(cnt 1) bib
)
1169 (goto-char (point-min))
1170 (when (re-search-forward
1171 "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1172 (setq beg
(match-beginning 0))
1173 (while (re-search-forward "</?div\\>" nil t
)
1174 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1176 (and (looking-at ">") (forward-char 1))
1177 (setq bib
(buffer-substring beg
(point)))
1178 (delete-region beg
(point))
1179 (throw 'exit bib
))))
1184 (defun org-e-html-format-table (lines olines
)
1185 (let ((org-e-html-format-table-no-css nil
))
1186 (org-lparse-format-table lines olines
)))
1188 (defun org-e-html-splice-attributes (tag attributes
)
1189 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1190 (if (not attributes
)
1192 (let (oldatt newatt
)
1193 (setq oldatt
(org-extract-attributes-from-string tag
)
1195 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1197 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1198 (if (string-match ">" tag
)
1200 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1204 (defun org-export-splice-style (style extra
)
1205 "Splice EXTRA into STYLE, just before \"</style>\"."
1206 (if (and (stringp extra
)
1207 (string-match "\\S-" extra
)
1208 (string-match "</style>" style
))
1209 (concat (substring style
0 (match-beginning 0))
1211 (substring style
(match-beginning 0)))
1214 (defun org-export-e-htmlize-region-for-paste (beg end
)
1215 "Convert the region to HTML, using htmlize.el.
1216 This is much like `htmlize-region-for-paste', only that it uses
1217 the settings define in the org-... variables."
1218 (let* ((htmlize-output-type org-export-e-htmlize-output-type
)
1219 (htmlize-css-name-prefix org-export-e-htmlize-css-font-prefix
)
1220 (htmlbuf (htmlize-region beg end
)))
1222 (with-current-buffer htmlbuf
1223 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1224 (plist-get htmlize-buffer-places
'content-end
)))
1225 (kill-buffer htmlbuf
))))
1228 (defun org-export-e-htmlize-generate-css ()
1229 "Create the CSS for all font definitions in the current Emacs session.
1230 Use this to create face definitions in your CSS style file that can then
1231 be used by code snippets transformed by htmlize.
1232 This command just produces a buffer that contains class definitions for all
1233 faces used in the current Emacs session. You can copy and paste the ones you
1234 need into your CSS file.
1236 If you then set `org-export-e-htmlize-output-type' to `css', calls to
1237 the function `org-export-e-htmlize-region-for-paste' will produce code
1238 that uses these same face definitions."
1241 (and (get-buffer "*html*") (kill-buffer "*html*"))
1243 (let ((fl (face-list))
1244 (htmlize-css-name-prefix "org-")
1245 (htmlize-output-type 'css
)
1247 (while (setq f
(pop fl
)
1248 i
(and f
(face-attribute f
:inherit
)))
1249 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1250 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1251 (htmlize-region (point-min) (point-max))))
1252 (org-pop-to-buffer-same-window "*html*")
1253 (goto-char (point-min))
1254 (if (re-search-forward "<style" nil t
)
1255 (delete-region (point-min) (match-beginning 0)))
1256 (if (re-search-forward "</style>" nil t
)
1257 (delete-region (1+ (match-end 0)) (point-max)))
1258 (beginning-of-line 1)
1259 (if (looking-at " +") (replace-match ""))
1260 (goto-char (point-min)))
1262 (defun org-e-html-make-string (n string
)
1263 (let (out) (dotimes (i n out
) (setq out
(concat string out
)))))
1265 (defun org-e-html-toc-text (toc-entries)
1266 (let* ((prev-level (1- (nth 1 (car toc-entries
))))
1267 (start-level prev-level
))
1271 (let ((headline (nth 0 entry
))
1272 (level (nth 1 entry
)))
1274 (let* ((cnt (- level prev-level
))
1275 (times (if (> cnt
0) (1- cnt
) (- cnt
)))
1277 (setq prev-level level
)
1279 (org-e-html-make-string
1280 times
(cond ((> cnt
0) "\n<ul>\n<li>")
1281 ((< cnt
0) "</li>\n</ul>\n")))
1282 (if (> cnt
0) "\n<ul>\n<li>" "</li>\n<li>")))
1285 (org-e-html-make-string
1286 (- prev-level start-level
) "</li>\n</ul>\n"))))
1288 (defun* org-e-html-format-toc-headline
1289 (todo todo-type priority text tags
1290 &key level section-number headline-label
&allow-other-keys
)
1291 (let ((headline (concat
1292 section-number
(and section-number
". ")
1294 (and tags
" ") (org-e-html--tags tags
))))
1295 (format "<a href=\"#%s\">%s</a>"
1297 (if (not nil
) headline
1298 (format "<span class=\"%s\">%s</span>" todo-type headline
)))))
1300 (defun org-e-html-toc (depth info
)
1301 (assert (wholenump depth
))
1302 (let* ((headlines (org-export-collect-headlines info depth
))
1304 (loop for headline in headlines collect
1305 (list (org-e-html-format-headline--wrap
1306 headline info
'org-e-html-format-toc-headline
)
1307 (org-export-get-relative-level headline info
)))))
1309 (let* ((lang-specific-heading
1310 (nth 3 (or (assoc (plist-get info
:language
)
1311 org-export-language-setup
)
1312 (assoc "en" org-export-language-setup
)))))
1314 "<div id=\"table-of-contents\">\n"
1315 (format "<h%d>%s</h%d>\n"
1316 org-e-html-toplevel-hlevel
1317 lang-specific-heading
1318 org-e-html-toplevel-hlevel
)
1319 "<div id=\"text-table-of-contents\">"
1320 (org-e-html-toc-text toc-entries
)
1324 ;; (defun org-e-html-format-line (line)
1325 ;; (case org-lparse-dyn-current-environment
1326 ;; ((quote fixedwidth) (concat (org-e-html-encode-plain-text line) "\n"))
1327 ;; (t (concat line "\n"))))
1329 (defun org-e-html-fix-class-name (kwd) ; audit callers of this function
1330 "Turn todo keyword into a valid class name.
1331 Replaces invalid characters with \"_\"."
1333 (while (string-match "[^a-zA-Z0-9_]" kwd
)
1334 (setq kwd
(replace-match "_" t t kwd
))))
1337 (defun org-e-html-format-footnote-reference (n def refcnt
)
1338 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1339 (format org-e-html-footnote-format
1341 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1344 (defun org-e-html-format-footnotes-section (section-name definitions
)
1345 (if (not definitions
) ""
1346 (format org-e-html-footnotes-section section-name definitions
)))
1348 (defun org-e-html-format-footnote-definition (fn)
1349 (let ((n (car fn
)) (def (cdr fn
)))
1351 "<tr>\n<td>%s</td>\n<td>%s</td>\n</tr>\n"
1353 (format org-e-html-footnote-format
1354 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1357 (defun org-e-html-footnote-section (info)
1358 (let* ((fn-alist (org-export-collect-footnote-definitions
1359 (plist-get info
:parse-tree
) info
))
1362 (loop for
(n type raw
) in fn-alist collect
1363 (cons n
(if (equal (org-element-type raw
) 'org-data
)
1364 (org-trim (org-export-data raw info
))
1367 (org-export-secondary-string raw info
))))))))
1369 (org-e-html-format-footnotes-section
1370 (nth 4 (or (assoc (plist-get info
:language
)
1371 org-export-language-setup
)
1372 (assoc "en" org-export-language-setup
)))
1374 "<table>\n%s\n</table>\n"
1375 (mapconcat 'org-e-html-format-footnote-definition fn-alist
"\n"))))))
1377 (defun org-e-html-format-date (info)
1378 (let ((date (plist-get info
:date
)))
1380 ((and date
(string-match "%" date
))
1381 (format-time-string date
))
1383 (t (format-time-string "%Y-%m-%d %T %Z")))))
1387 ;;; Internal Functions (Ngz)
1389 (defun org-e-html--caption/label-string
(caption label info
)
1390 "Return caption and label HTML string for floats.
1392 CAPTION is a cons cell of secondary strings, the car being the
1393 standard caption and the cdr its short form. LABEL is a string
1394 representing the label. INFO is a plist holding contextual
1397 If there's no caption nor label, return the empty string.
1399 For non-floats, see `org-e-html--wrap-label'."
1400 (setq label nil
) ;; FIXME
1402 (let ((label-str (if label
(format "\\label{%s}" label
) "")))
1404 ((and (not caption
) (not label
)) "")
1405 ((not caption
) (format "\\label{%s}\n" label
))
1406 ;; Option caption format with short name.
1408 (format "\\caption[%s]{%s%s}\n"
1409 (org-export-secondary-string (cdr caption
) info
)
1411 (org-export-secondary-string (car caption
) info
)))
1412 ;; Standard caption format.
1413 ;; (t (format "\\caption{%s%s}\n"
1415 ;; (org-export-secondary-string (car caption) info)))
1417 (t (org-export-secondary-string (car caption
) info
)))))
1419 (defun org-e-html--find-verb-separator (s)
1420 "Return a character not used in string S.
1421 This is used to choose a separator for constructs like \\verb."
1422 (let ((ll "~,./?;':\"|!@#%^&-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ<>()[]{}"))
1423 (loop for c across ll
1424 when
(not (string-match (regexp-quote (char-to-string c
)) s
))
1425 return
(char-to-string c
))))
1427 (defun org-e-html--quotation-marks (text info
)
1428 "Export quotation marks depending on language conventions.
1429 TEXT is a string containing quotation marks to be replaced. INFO
1430 is a plist used as a communication channel."
1433 (while (setq start
(string-match (car l
) text start
))
1434 (let ((new-quote (concat (match-string 1 text
) (cdr l
))))
1435 (setq text
(replace-match new-quote t t text
))))))
1436 (cdr (or (assoc (plist-get info
:language
) org-e-html-quotes
)
1437 ;; Falls back on English.
1438 (assoc "en" org-e-html-quotes
))))
1441 (defun org-e-html--wrap-label (element output
)
1442 "Wrap label associated to ELEMENT around OUTPUT, if appropriate.
1443 This function shouldn't be used for floats. See
1444 `org-e-html--caption/label-string'."
1445 ;; (let ((label (org-element-property :name element)))
1446 ;; (if (or (not output) (not label) (string= output "") (string= label ""))
1448 ;; (concat (format "\\label{%s}\n" label) output)))
1455 (defun org-e-html-meta-info (info)
1456 (let* ((title (org-export-secondary-string (plist-get info
:title
) info
))
1457 (author (and (plist-get info
:with-author
)
1458 (let ((auth (plist-get info
:author
)))
1459 (and auth
(org-export-secondary-string auth info
)))))
1460 (description (plist-get info
:description
))
1461 (keywords (plist-get info
:keywords
)))
1463 (format "\n<title>%s</title>\n" title
)
1465 "\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>"
1466 (or (and org-export-coding-system
1467 (fboundp 'coding-system-get
)
1468 (coding-system-get org-export-coding-system
1471 (format "\n<meta name=\"title\" content=\"%s\"/>" title
)
1472 (format "\n<meta name=\"generator\" content=\"Org-mode\"/>")
1473 (format "\n<meta name=\"generated\" content=\"%s\"/>"
1474 (org-e-html-format-date info
))
1475 (format "\n<meta name=\"author\" content=\"%s\"/>" author
)
1476 (format "\n<meta name=\"description\" content=\"%s\"/>" description
)
1477 (format "\n<meta name=\"keywords\" content=\"%s\"/>" keywords
))))
1479 (defun org-e-html-style (info)
1481 "\n" (when (plist-get info
:style-include-default
) org-e-html-style-default
)
1482 (plist-get info
:style
)
1483 (plist-get info
:style-extra
)
1485 (when (plist-get info
:style-include-scripts
)
1486 org-e-html-scripts
)))
1488 (defun org-e-html-mathjax-config (info)
1489 "Insert the user setup into the matchjax template."
1490 (when (member (plist-get info
:LaTeX-fragments
) '(mathjax t
))
1491 (let ((template org-e-html-mathjax-template
)
1492 (options org-e-html-mathjax-options
)
1493 (in-buffer (or (plist-get info
:mathjax
) ""))
1494 name val
(yes " ") (no "// ") x
)
1497 (setq name
(car e
) val
(nth 1 e
))
1498 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
1499 (setq val
(car (read-from-string
1500 (substring in-buffer
(match-end 0))))))
1501 (if (not (stringp val
)) (setq val
(format "%s" val
)))
1502 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
1503 (setq template
(replace-match val t t template
))))
1505 (setq val
(nth 1 (assq 'mathml options
)))
1506 (if (string-match (concat "\\<mathml:") in-buffer
)
1507 (setq val
(car (read-from-string
1508 (substring in-buffer
(match-end 0))))))
1509 ;; Exchange prefixes depending on mathml setting
1510 (if (not val
) (setq x yes yes no no x
))
1511 ;; Replace cookies to turn on or off the config/jax lines
1512 (if (string-match ":MMLYES:" template
)
1513 (setq template
(replace-match yes t t template
)))
1514 (if (string-match ":MMLNO:" template
)
1515 (setq template
(replace-match no t t template
)))
1516 ;; Return the modified template
1519 (defun org-e-html-preamble (info)
1520 (when (plist-get info
:html-preamble
)
1521 (let* ((title (org-export-secondary-string (plist-get info
:title
) info
))
1522 (date (org-e-html-format-date info
))
1523 (author (org-export-secondary-string (plist-get info
:author
) info
))
1524 (lang-words (or (assoc (plist-get info
:language
)
1525 org-export-language-setup
)
1526 (assoc "en" org-export-language-setup
)))
1527 (email (plist-get info
:email
))
1528 (html-pre-real-contents
1530 ((functionp (plist-get info
:html-preamble
))
1532 (funcall (plist-get info
:html-preamble
))
1534 ((stringp (plist-get info
:html-preamble
))
1535 (format-spec (plist-get info
:html-preamble
)
1536 `((?t .
,title
) (?a .
,author
)
1537 (?d .
,date
) (?e .
,email
))))
1540 (or (cadr (assoc (nth 0 lang-words
)
1541 org-e-html-preamble-format
))
1542 (cadr (assoc "en" org-e-html-preamble-format
)))
1543 `((?t .
,title
) (?a .
,author
)
1544 (?d .
,date
) (?e .
,email
)))))))
1545 (when (not (equal html-pre-real-contents
""))
1548 <div id=\"%s\"> " (nth 0 org-e-html-divs
))
1551 html-pre-real-contents
1555 (defun org-e-html-postamble (info)
1557 (when (and (not body-only
)
1558 (plist-get info
:html-postamble
))
1559 (let* ((html-post (plist-get info
:html-postamble
))
1560 (date (org-e-html-format-date info
))
1561 (author (plist-get info
:author
))
1562 (email (plist-get info
:email
))
1563 (lang-words (or (assoc (plist-get info
:language
)
1564 org-export-language-setup
)
1565 (assoc "en" org-export-language-setup
)))
1567 (mapconcat (lambda(e)
1568 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1569 (split-string email
",+ *")
1571 (html-validation-link (or org-e-html-validation-link
""))
1572 (creator-info org-export-creator-string
))
1576 <div id=\"" (nth 2 org-e-html-divs
) "\">"
1579 ((eq (plist-get info
:html-postamble
) 'auto
)
1581 (when (plist-get info
:time-stamp-file
)
1583 <p class=\"date\"> %s: %s </p> " (nth 2 lang-words
) date
))
1584 (when (and (plist-get info
:with-author
) author
)
1586 <p class=\"author\"> %s : %s</p>" (nth 1 lang-words
) author
))
1587 (when (and (plist-get info
:with-email
) email
)
1589 <p class=\"email\"> %s </p>" email
))
1590 (when (plist-get info
:with-creator
)
1592 <p class=\"creator\"> %s </p>" creator-info
))
1593 html-validation-link
"\n"))
1594 ;; postamble from a string
1595 ((stringp (plist-get info
:html-postamble
))
1596 (format-spec (plist-get info
:html-postamble
)
1597 `((?a .
,author
) (?e .
,email
)
1598 (?d .
,date
) (?c .
,creator-info
)
1599 (?v .
,html-validation-link
))))
1601 ;; postamble from a function
1602 ((functionp (plist-get info
:html-postamble
))
1604 (funcall (plist-get info
:html-postamble
))
1606 ;; default postamble
1609 (or (cadr (assoc (nth 0 lang-words
)
1610 org-e-html-postamble-format
))
1611 (cadr (assoc "en" org-e-html-postamble-format
)))
1612 `((?a .
,author
) (?e .
,email
)
1613 (?d .
,date
) (?c .
,creator-info
)
1614 (?v .
,html-validation-link
)))))
1617 ;; org-e-html-html-helper-timestamp
1620 (defun org-e-html-template (contents info
)
1621 "Return complete document string after HTML conversion.
1622 CONTENTS is the transcoded contents string. RAW-DATA is the
1623 original parsed data. INFO is a plist holding export options."
1626 (or (and (stringp org-e-html-xml-declaration
)
1627 org-e-html-xml-declaration
)
1628 (cdr (assoc (plist-get info
:html-extension
)
1629 org-e-html-xml-declaration
))
1630 (cdr (assoc "html" org-e-html-xml-declaration
))
1633 (or (and coding-system-for-write
1634 (fboundp 'coding-system-get
)
1635 (coding-system-get coding-system-for-write
1639 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1640 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"
1642 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\"> "
1643 (plist-get info
:language
) (plist-get info
:language
))
1646 (org-e-html-meta-info info
) ; meta
1647 (org-e-html-style info
) ; style
1648 (org-e-html-mathjax-config info
) ; mathjax
1654 (let ((link-up (and (plist-get info
:link-up
)
1655 (string-match "\\S-" (plist-get info
:link-up
))
1656 (plist-get info
:link-up
)))
1657 (link-home (and (plist-get info
:link-home
)
1658 (string-match "\\S-" (plist-get info
:link-home
))
1659 (plist-get info
:link-home
))))
1660 (when (or link-up link-home
)
1661 (format org-e-html-home
/up-format
1662 (or link-up link-home
)
1663 (or link-home link-up
))))
1665 (org-e-html-preamble info
)
1668 <div id=\"%s\">" (or org-e-html-content-div
1669 (nth 1 org-e-html-divs
)))
1672 <h1 class=\"title\">%s</h1>\n" (org-export-secondary-string
1673 (plist-get info
:title
) info
))
1674 ;; table of contents
1675 (let ((depth (plist-get info
:with-toc
)))
1676 (when (wholenump depth
) (org-e-html-toc depth info
)))
1677 ;; document contents
1679 ;; footnotes section
1680 (org-e-html-footnote-section info
)
1682 (org-e-html-bibliography)
1689 (org-e-html-postamble info
)
1699 ;;; Transcode Helpers
1703 (defun org-e-html--todo (todo)
1705 (format "<span class=\"%s %s%s\">%s</span>"
1706 (if (member todo org-done-keywords
) "done" "todo")
1707 org-e-html-todo-kwd-class-prefix
(org-e-html-fix-class-name todo
)
1712 (defun org-e-html--tags (tags)
1714 (format "<span class=\"tag\">%s</span>"
1717 (format "<span class=\"%s\">%s</span>"
1718 (concat org-e-html-tag-class-prefix
1719 (org-e-html-fix-class-name tag
))
1721 (org-split-string tags
":") " "))))
1725 (defun* org-e-html-format-headline
1726 (todo todo-type priority text tags
1727 &key level section-number headline-label
&allow-other-keys
)
1728 (let ((section-number
1729 (when section-number
1730 (format "<span class=\"section-number-%d\">%s</span> "
1731 level section-number
)))
1732 (todo (org-e-html--todo todo
))
1733 (tags (org-e-html--tags tags
)))
1734 (concat section-number todo
(and todo
" ") text
1735 (and tags
" ") tags
)))
1739 (defun org-e-html-fontify-code (code lang
)
1742 ;; Case 1: No lang. Possibly an example block.
1744 ;; Simple transcoding.
1745 (org-e-html-encode-plain-text code
))
1746 ;; Case 2: No htmlize or an inferior version of htmlize
1747 ((not (and (require 'htmlize nil t
) (fboundp 'htmlize-region-for-paste
)))
1749 (message "Cannot fontify src block (htmlize.el >= 1.34 required)")
1750 ;; Simple transcoding.
1751 (org-e-html-encode-plain-text code
))
1754 (setq lang
(or (assoc-default lang org-src-lang-modes
) lang
))
1755 (let* ((lang-mode (and lang
(intern (format "%s-mode" lang
)))))
1757 ;; Case 1: Language is not associated with any Emacs mode
1758 ((not (functionp lang-mode
))
1759 ;; Simple transcoding.
1760 (org-e-html-encode-plain-text code
))
1761 ;; Case 2: Default. Fotify code.
1764 (setq code
(with-temp-buffer
1767 (font-lock-fontify-buffer)
1768 ;; markup each line separately
1769 (org-remove-formatting-on-newlines-in-region
1770 (point-min) (point-max))
1772 (set-buffer-modified-p nil
)
1773 (org-export-e-htmlize-region-for-paste
1774 (point-min) (point-max))))
1775 ;; Strip any encolosing <pre></pre> tags
1776 (if (string-match "<pre[^>]*>\n*\\([^\000]*\\)</pre>" code
)
1777 (match-string 1 code
)
1780 (defun org-e-html-do-format-code
1781 (code &optional lang refs retain-labels num-start textarea-p
)
1783 (setq num-start nil refs nil lang nil
))
1784 (let* ((code-lines (org-split-string code
"\n"))
1785 (code-length (length code-lines
))
1789 (length (number-to-string (+ code-length num-start
))))))
1790 (code (org-e-html-fontify-code code lang
)))
1791 (assert (= code-length
(length (org-split-string code
"\n"))))
1792 (org-export-format-code
1794 (lambda (loc line-num ref
)
1797 ;; Add line number, if needed.
1799 (format "<span class=\"linenr\">%s</span>"
1800 (format num-fmt line-num
)))
1801 ;; Transcoded src line.
1803 ;; Add label, if needed.
1804 (when (and ref retain-labels
) (format " (%s)" ref
))))
1805 ;; Mark transcoded line as an anchor, if needed.
1807 (format "<span id=\"coderef-%s\" class=\"coderef-off\">%s</span>"
1811 (defun org-e-html-format-code (element info
)
1812 (let* ((lang (org-element-property :language element
))
1813 ;; (switches (org-element-property :switches element))
1814 (switches nil
) ; FIXME
1815 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1816 ;; Extract code and references.
1817 (code-info (org-export-unravel-code element
))
1818 (code (car code-info
))
1819 (refs (cdr code-info
))
1820 ;; Does the src block contain labels?
1821 (retain-labels (org-element-property :retain-labels element
))
1822 ;; Does it have line numbers?
1823 (num-start (case (org-element-property :number-lines element
)
1824 (continued (org-export-get-loc element info
))
1826 (org-e-html-do-format-code
1827 code lang refs retain-labels num-start textarea-p
)))
1831 ;;; Transcode Functions
1835 (defun org-e-html-center-block (center-block contents info
)
1836 "Transcode a CENTER-BLOCK element from Org to HTML.
1837 CONTENTS holds the contents of the block. INFO is a plist
1838 holding contextual information."
1839 (org-e-html--wrap-label
1841 (format "<div style=\"text-align: center\">\n%s</div>" contents
)))
1846 ;; Comments are ignored.
1851 ;; Comment Blocks are ignored.
1856 (defun org-e-html-drawer (drawer contents info
)
1857 "Transcode a DRAWER element from Org to HTML.
1858 CONTENTS holds the contents of the block. INFO is a plist
1859 holding contextual information."
1860 (let* ((name (org-element-property :drawer-name drawer
))
1861 (output (if (functionp org-e-html-format-drawer-function
)
1862 (funcall org-e-html-format-drawer-function
1864 ;; If there's no user defined function: simply
1865 ;; display contents of the drawer.
1867 (org-e-html--wrap-label drawer output
)))
1872 (defun org-e-html-dynamic-block (dynamic-block contents info
)
1873 "Transcode a DYNAMIC-BLOCK element from Org to HTML.
1874 CONTENTS holds the contents of the block. INFO is a plist
1875 holding contextual information. See `org-export-data'."
1876 (org-e-html--wrap-label dynamic-block contents
))
1881 (defun org-e-html-emphasis (emphasis contents info
)
1882 "Transcode EMPHASIS from Org to HTML.
1883 CONTENTS is the contents of the emphasized text. INFO is a plist
1884 holding contextual information.."
1885 (let* ((marker (org-element-property :marker emphasis
)))
1886 (format (cdr (assoc marker org-e-html-emphasis-alist
)) contents
)))
1891 (defun org-e-html-entity (entity contents info
)
1892 "Transcode an ENTITY object from Org to HTML.
1893 CONTENTS are the definition itself. INFO is a plist holding
1894 contextual information."
1895 (org-element-property :html entity
))
1900 (defun org-e-html-example-block (example-block contents info
)
1901 "Transcode a EXAMPLE-BLOCK element from Org to HTML.
1902 CONTENTS is nil. INFO is a plist holding contextual information."
1903 (let* ((options (or (org-element-property :options example-block
) ""))
1904 (lang (org-element-property :language example-block
))
1905 (caption (org-element-property :caption example-block
))
1906 (label (org-element-property :name example-block
))
1907 (caption-str (org-e-html--caption/label-string caption label info
))
1908 (attr (mapconcat #'identity
1909 (org-element-property :attr_html example-block
)
1911 ;; (switches (org-element-property :switches example-block))
1912 (switches nil
) ; FIXME
1913 (textarea-p (and switches
(string-match "-t\\>" switches
)))
1914 (code (org-e-html-format-code example-block info
)))
1917 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
1918 80 (string-to-number (match-string 1 switches
))))
1919 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
1920 (string-to-number (match-string 1 switches
))
1921 (org-count-lines code
))))
1923 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
1925 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
1930 (defun org-e-html-export-snippet (export-snippet contents info
)
1931 "Transcode a EXPORT-SNIPPET object from Org to HTML.
1932 CONTENTS is nil. INFO is a plist holding contextual information."
1933 (when (eq (org-export-snippet-backend export-snippet
) 'e-html
)
1934 (org-element-property :value export-snippet
)))
1939 (defun org-e-html-export-block (export-block contents info
)
1940 "Transcode a EXPORT-BLOCK element from Org to HTML.
1941 CONTENTS is nil. INFO is a plist holding contextual information."
1942 (when (string= (org-element-property :type export-block
) "latex")
1943 (org-remove-indentation (org-element-property :value export-block
))))
1948 (defun org-e-html-fixed-width (fixed-width contents info
)
1949 "Transcode a FIXED-WIDTH element from Org to HTML.
1950 CONTENTS is nil. INFO is a plist holding contextual information."
1951 (let* ((value (org-element-normalize-string
1952 (replace-regexp-in-string
1954 (org-element-property :value fixed-width
)))))
1955 (org-e-html--wrap-label
1956 fixed-width
(format "\n<pre class=\"example\">\n%s\n</pre>"
1957 (org-e-html-do-format-code value
)))))
1960 ;;;; Footnote Definition
1962 ;; Footnote Definitions are ignored.
1965 ;;;; Footnote Reference
1967 (defun org-e-html-footnote-reference (footnote-reference contents info
)
1968 "Transcode a FOOTNOTE-REFERENCE element from Org to HTML.
1969 CONTENTS is nil. INFO is a plist holding contextual information."
1971 ;; Insert separator between two footnotes in a row.
1972 (let ((prev (org-export-get-previous-element footnote-reference info
)))
1973 (when (eq (org-element-type prev
) 'footnote-reference
)
1974 org-e-html-footnote-separator
))
1976 ((not (org-export-footnote-first-reference-p footnote-reference info
))
1977 (org-e-html-format-footnote-reference
1978 (org-export-get-footnote-number footnote-reference info
)
1980 ;; Inline definitions are secondary strings.
1981 ((eq (org-element-property :type footnote-reference
) 'inline
)
1982 (org-e-html-format-footnote-reference
1983 (org-export-get-footnote-number footnote-reference info
)
1985 ;; Non-inline footnotes definitions are full Org data.
1986 (t (org-e-html-format-footnote-reference
1987 (org-export-get-footnote-number footnote-reference info
)
1993 (defun org-e-html-format-headline--wrap (headline info
1994 &optional format-function
1996 "Transcode an HEADLINE element from Org to HTML.
1997 CONTENTS holds the contents of the headline. INFO is a plist
1998 holding contextual information."
1999 (let* ((level (+ (org-export-get-relative-level headline info
)
2000 (1- org-e-html-toplevel-hlevel
)))
2001 (headline-number (org-export-get-headline-number headline info
))
2002 (section-number (and (org-export-numbered-headline-p headline info
)
2003 (mapconcat 'number-to-string
2004 headline-number
".")))
2005 (todo (and (plist-get info
:with-todo-keywords
)
2006 (let ((todo (org-element-property
2007 :todo-keyword headline
)))
2009 (org-export-secondary-string todo info
)))))
2010 (todo-type (and todo
(org-element-property :todo-type headline
)))
2011 (priority (and (plist-get info
:with-priority
)
2012 (org-element-property :priority headline
)))
2013 (text (org-export-secondary-string
2014 (org-element-property :title headline
) info
))
2015 (tags (and (plist-get info
:with-tags
)
2016 (org-element-property :tags headline
)))
2017 (headline-label (concat "sec-" (mapconcat 'number-to-string
2018 headline-number
"-")))
2019 (format-function (cond
2020 ((functionp format-function
) format-function
)
2021 ((functionp org-e-html-format-headline-function
)
2023 (lambda (todo todo-type priority text tags
2025 (funcall org-e-html-format-headline-function
2026 todo todo-type priority text tags
))))
2027 (t 'org-e-html-format-headline
))))
2028 (apply format-function
2029 todo todo-type priority text tags
2030 :headline-label headline-label
:level level
2031 :section-number section-number extra-keys
)))
2033 (defun org-e-html-headline (headline contents info
)
2034 "Transcode an HEADLINE element from Org to HTML.
2035 CONTENTS holds the contents of the headline. INFO is a plist
2036 holding contextual information."
2037 (let* ((numberedp (org-export-numbered-headline-p headline info
))
2038 (level (org-export-get-relative-level headline info
))
2039 (text (org-export-secondary-string
2040 (org-element-property :title headline
) info
))
2041 (todo (and (plist-get info
:with-todo-keywords
)
2042 (let ((todo (org-element-property
2043 :todo-keyword headline
)))
2044 (and todo
(org-export-secondary-string todo info
)))))
2045 (todo-type (and todo
(org-element-property :todo-type headline
)))
2046 (tags (and (plist-get info
:with-tags
)
2047 (org-element-property :tags headline
)))
2048 (priority (and (plist-get info
:with-priority
)
2049 (org-element-property :priority headline
)))
2050 (section-number (and (org-export-numbered-headline-p headline info
)
2051 (mapconcat 'number-to-string
2052 (org-export-get-headline-number
2053 headline info
) ".")))
2054 ;; Create the headline text.
2055 (full-text (org-e-html-format-headline--wrap headline info
)))
2057 ;; Case 1: This is a footnote section: ignore it.
2058 ((org-element-property :footnote-section-p headline
) nil
)
2059 ;; Case 2. This is a deep sub-tree: export it as a list item.
2060 ;; Also export as items headlines for which no section
2061 ;; format has been found.
2062 ((org-export-low-level-p headline info
) ; FIXME (or (not section-fmt))
2063 ;; Build the real contents of the sub-tree.
2064 (let* ((type (if numberedp
'unordered
'unordered
)) ; FIXME
2065 (itemized-body (org-e-html-format-list-item
2066 contents type nil nil full-text
)))
2068 (and (org-export-first-sibling-p headline info
)
2069 (org-e-html-begin-plain-list type
))
2071 (and (org-export-last-sibling-p headline info
)
2072 (org-e-html-end-plain-list type
)))))
2073 ;; Case 3. Standard headline. Export it as a section.
2075 (let* ((extra-class (org-element-property :html-container-class headline
))
2076 (extra-ids (list (org-element-property :custom-id headline
)
2077 (org-element-property :id headline
)))
2082 (let ((id (org-solidify-link-text
2083 (if (org-uuidgen-p x
) (concat "ID-" x
) x
))))
2084 (format "<a id=\"%s\" name=\"%s\"/>" id id
))))
2086 (level1 (+ level
(1- org-e-html-toplevel-hlevel
)))
2087 (id (mapconcat 'number-to-string
2088 (org-export-get-headline-number headline info
) "-")))
2089 (format "<div id=\"%s\" class=\"%s\">%s%s</div>\n"
2090 (format "outline-container-%s" id
)
2091 (concat (format "outline-%d" level1
) (and extra-class
" ")
2093 (format "\n<h%d id=\"sec-%s\">%s%s</h%d>\n"
2094 level1 id extra-ids full-text level1
)
2098 ;;;; Horizontal Rule
2100 (defun org-e-html-horizontal-rule (horizontal-rule contents info
)
2101 "Transcode an HORIZONTAL-RULE object from Org to HTML.
2102 CONTENTS is nil. INFO is a plist holding contextual information."
2103 (let ((attr (mapconcat #'identity
2104 (org-element-property :attr_html horizontal-rule
)
2106 (org-e-html--wrap-label horizontal-rule
"<hr/>\n")))
2109 ;;;; Inline Babel Call
2111 ;; Inline Babel Calls are ignored.
2114 ;;;; Inline Src Block
2116 (defun org-e-html-inline-src-block (inline-src-block contents info
)
2117 "Transcode an INLINE-SRC-BLOCK element from Org to HTML.
2118 CONTENTS holds the contents of the item. INFO is a plist holding
2119 contextual information."
2120 (let* ((org-lang (org-element-property :language inline-src-block
))
2121 (code (org-element-property :value inline-src-block
))
2122 (separator (org-e-html--find-verb-separator code
)))
2128 (defun org-e-html-format-section (text class
&optional id
)
2129 (let ((extra (concat (when id
(format " id=\"%s\"" id
)))))
2130 (concat (format "<div class=\"%s\"%s>\n" class extra
) text
"</div>\n")))
2132 (defun org-e-html-inlinetask (inlinetask contents info
)
2133 "Transcode an INLINETASK element from Org to HTML.
2134 CONTENTS holds the contents of the block. INFO is a plist
2135 holding contextual information."
2137 ;; If `org-e-html-format-inlinetask-function' is provided, call it
2138 ;; with appropriate arguments.
2139 ((functionp org-e-html-format-inlinetask-function
)
2140 (let ((format-function
2142 (lambda (todo todo-type priority text tags
2143 &key contents
&allow-other-keys
)
2144 (funcall org-e-html-format-inlinetask-function
2145 todo todo-type priority text tags contents
)))))
2146 (org-e-html-format-headline--wrap
2147 inlinetask info format-function
:contents contents
)))
2148 ;; Otherwise, use a default template.
2149 (t (org-e-html--wrap-label
2152 "\n<div class=\"inlinetask\">\n<b>%s</b><br/>\n%s\n</div>"
2153 (org-e-html-format-headline--wrap inlinetask info
)
2159 (defun org-e-html-checkbox (checkbox)
2160 (case checkbox
(on "<code>[X]</code>")
2161 (off "<code>[ ]</code>")
2162 (trans "<code>[-]</code>")
2165 (defun org-e-html-format-list-item (contents type checkbox
2166 &optional term-counter-id
2171 (let* ((counter term-counter-id
)
2172 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2173 (format "<li%s>" extra
)))
2175 (let* ((id term-counter-id
)
2176 (extra (if id
(format " id=\"%s\"" id
) "")))
2178 (format "<li%s>" extra
)
2179 (when headline
(concat headline
"<br/>")))))
2181 (let* ((term term-counter-id
))
2182 (setq term
(or term
"(no term)"))
2183 (concat (format "<dt> %s </dt>" term
) "<dd>"))))
2184 (org-e-html-checkbox checkbox
) (and checkbox
" ")
2189 (descriptive "</dd>"))))
2191 (defun org-e-html-item (item contents info
)
2192 "Transcode an ITEM element from Org to HTML.
2193 CONTENTS holds the contents of the item. INFO is a plist holding
2194 contextual information."
2195 ;; Grab `:level' from plain-list properties, which is always the
2196 ;; first element above current item.
2197 (let* ((plain-list (org-export-get-parent item info
))
2198 (type (org-element-property :type plain-list
))
2199 (level (org-element-property :level plain-list
))
2200 (counter (org-element-property :counter item
))
2201 (checkbox (org-element-property :checkbox item
))
2202 (tag (let ((tag (org-element-property :tag item
)))
2203 (and tag
(org-export-secondary-string tag info
)))))
2204 (org-e-html-format-list-item
2205 contents type checkbox
(or tag counter
))))
2210 (defun org-e-html-keyword (keyword contents info
)
2211 "Transcode a KEYWORD element from Org to HTML.
2212 CONTENTS is nil. INFO is a plist holding contextual information."
2213 (let ((key (org-element-property :key keyword
))
2214 (value (org-element-property :value keyword
)))
2216 ((string= key
"LATEX") value
)
2217 ((string= key
"INDEX") (format "\\index{%s}" value
))
2218 ;; Invisible targets.
2219 ((string= key
"TARGET") nil
) ; FIXME
2220 ((string= key
"TOC")
2221 (let ((value (downcase value
)))
2223 ((string-match "\\<headlines\\>" value
)
2224 (let ((depth (or (and (string-match "[0-9]+" value
)
2225 (string-to-number (match-string 0 value
)))
2226 (plist-get info
:with-toc
))))
2227 (when (wholenump depth
) (org-e-html-toc depth info
))))
2228 ((string= "tables" value
) "\\listoftables")
2229 ((string= "figures" value
) "\\listoffigures")
2230 ((string= "listings" value
)
2232 ;; At the moment, src blocks with a caption are wrapped
2233 ;; into a figure environment.
2234 (t "\\listoffigures")))))))))
2237 ;;;; Latex Environment
2239 (defun org-e-html-format-latex (latex-frag processing-type
)
2240 (let* ((cache-relpath
2241 (concat "ltxpng/" (file-name-sans-extension
2242 (file-name-nondirectory (buffer-file-name)))))
2243 (cache-dir (file-name-directory (buffer-file-name )))
2244 (display-msg "Creating LaTeX Image..."))
2248 (org-format-latex cache-relpath cache-dir nil display-msg
2249 nil nil processing-type
)
2252 (defun org-e-html-latex-environment (latex-environment contents info
)
2253 "Transcode a LATEX-ENVIRONMENT element from Org to HTML.
2254 CONTENTS is nil. INFO is a plist holding contextual information."
2255 (org-e-html--wrap-label
2257 (let ((processing-type (plist-get info
:LaTeX-fragments
))
2258 (latex-frag (org-remove-indentation
2259 (org-element-property :value latex-environment
)))
2260 (caption (org-e-html--caption/label-string
2261 (org-element-property :caption latex-environment
)
2262 (org-element-property :name latex-environment
)
2265 (label (org-element-property :name latex-environment
)))
2267 ((member processing-type
'(t mathjax
))
2268 (org-e-html-format-latex latex-frag
'mathjax
))
2269 ((equal processing-type
'dvipng
)
2270 (let* ((formula-link (org-e-html-format-latex
2271 latex-frag processing-type
)))
2272 (when (and formula-link
2273 (string-match "file:\\([^]]*\\)" formula-link
))
2274 (org-e-html-format-inline-image
2275 (match-string 1 formula-link
) caption label attr t
))))
2281 (defun org-e-html-latex-fragment (latex-fragment contents info
)
2282 "Transcode a LATEX-FRAGMENT object from Org to HTML.
2283 CONTENTS is nil. INFO is a plist holding contextual information."
2284 (let ((latex-frag (org-element-property :value latex-fragment
))
2285 (processing-type (plist-get info
:LaTeX-fragments
)))
2286 (case processing-type
2288 (org-e-html-format-latex latex-frag
'mathjax
))
2290 (let* ((formula-link (org-e-html-format-latex
2291 latex-frag processing-type
)))
2292 (when (and formula-link
2293 (string-match "file:\\([^]]*\\)" formula-link
))
2294 (org-e-html-format-inline-image
2295 (match-string 1 formula-link
)))))
2300 (defun org-e-html-line-break (line-break contents info
)
2301 "Transcode a LINE-BREAK object from Org to HTML.
2302 CONTENTS is nil. INFO is a plist holding contextual information."
2308 (defun org-e-html-link--inline-image (link desc info
)
2309 "Return HTML code for an inline image.
2310 LINK is the link pointing to the inline image. INFO is a plist
2311 used as a communication channel."
2312 (let* ((type (org-element-property :type link
))
2313 (raw-path (org-element-property :path link
))
2314 (path (cond ((member type
'("http" "https"))
2315 (concat type
":" raw-path
))
2316 ((file-name-absolute-p raw-path
)
2317 (expand-file-name raw-path
))
2319 (parent (org-export-get-parent-paragraph link info
))
2320 (caption (org-e-html--caption/label-string
2321 (org-element-property :caption parent
)
2322 (org-element-property :name parent
)
2324 (label (org-element-property :name parent
))
2325 ;; Retrieve latex attributes from the element around.
2326 (attr (let ((raw-attr
2327 (mapconcat #'identity
2328 (org-element-property :attr_html parent
)
2330 (unless (string= raw-attr
"") raw-attr
))))
2331 ;; Now clear ATTR from any special keyword and set a default
2332 ;; value if nothing is left.
2333 (setq attr
(if (not attr
) "" (org-trim attr
)))
2334 ;; Return proper string, depending on DISPOSITION.
2335 (org-e-html-format-inline-image
2336 path caption label attr
(org-e-html-standalone-image-p link info
))))
2338 (defvar org-e-html-standalone-image-predicate
)
2339 (defun org-e-html-standalone-image-p (element info
&optional predicate
)
2340 "Test if ELEMENT is a standalone image for the purpose HTML export.
2341 INFO is a plist holding contextual information.
2343 Return non-nil, if ELEMENT is of type paragraph and it's sole
2344 content, save for whitespaces, is a link that qualifies as an
2347 Return non-nil, if ELEMENT is of type link and it's containing
2348 paragraph has no other content save for leading and trailing
2351 Return nil, otherwise.
2353 Bind `org-e-html-standalone-image-predicate' to constrain
2354 paragraph further. For example, to check for only captioned
2355 standalone images, do the following.
2357 \(setq org-e-html-standalone-image-predicate
2358 \(lambda \(paragraph\)
2359 \(org-element-property :caption paragraph\)\)\)
2361 (let ((paragraph (case (org-element-type element
)
2363 (link (and (org-export-inline-image-p
2364 element org-e-html-inline-image-rules
)
2365 (org-export-get-parent element info
)))
2368 (assert (eq (org-element-type paragraph
) 'paragraph
))
2369 (when (or (not (and (boundp 'org-e-html-standalone-image-predicate
)
2370 (functionp org-e-html-standalone-image-predicate
)))
2371 (funcall org-e-html-standalone-image-predicate paragraph
))
2372 (let ((contents (org-element-contents paragraph
)))
2373 (loop for x in contents
2374 with inline-image-count
= 0
2376 ((eq (org-element-type x
) 'plain-text
)
2377 (not (org-string-nw-p x
)))
2378 ((eq (org-element-type x
) 'link
)
2379 (when (org-export-inline-image-p
2380 x org-e-html-inline-image-rules
)
2381 (= (incf inline-image-count
) 1)))
2384 (defun org-e-html-link (link desc info
)
2385 "Transcode a LINK object from Org to HTML.
2387 DESC is the description part of the link, or the empty string.
2388 INFO is a plist holding contextual information. See
2390 (let* ((type (org-element-property :type link
))
2391 (raw-path (org-element-property :path link
))
2392 ;; Ensure DESC really exists, or set it to nil.
2393 (desc (and (not (string= desc
"")) desc
))
2395 ((member type
'("http" "https" "ftp" "mailto"))
2396 (concat type
":" raw-path
))
2397 ((string= type
"file")
2398 (when (string-match "\\(.+\\)::.+" raw-path
)
2399 (setq raw-path
(match-string 1 raw-path
)))
2400 (if (file-name-absolute-p raw-path
)
2401 (concat "file://" (expand-file-name raw-path
))
2402 ;; TODO: Not implemented yet. Concat also:
2403 ;; (org-export-directory :HTML info)
2404 (concat "file://" raw-path
)))
2409 ((and (or (eq t org-e-html-inline-images
)
2410 (and org-e-html-inline-images
(not desc
)))
2411 (org-export-inline-image-p link org-e-html-inline-image-rules
))
2412 (org-e-html-link--inline-image link desc info
))
2413 ;; Radioed target: Target's name is obtained from original raw
2414 ;; link. Path is parsed and transcoded in order to have a proper
2415 ;; display of the contents.
2416 ((string= type
"radio")
2417 (format "<a href=\"#%s\">%s</a>"
2418 (org-export-solidify-link-text path
)
2419 (org-export-secondary-string
2420 (org-element-parse-secondary-string
2421 path
(org-element-restriction 'radio-target
))
2423 ;; Links pointing to an headline: Find destination and build
2424 ;; appropriate referencing command.
2425 ((member type
'("custom-id" "fuzzy" "id"))
2426 (let ((destination (if (string= type
"fuzzy")
2427 (org-export-resolve-fuzzy-link link info
)
2428 (org-export-resolve-id-link link info
))))
2429 (case (org-element-type destination
)
2430 ;; Fuzzy link points nowhere.
2434 (org-export-secondary-string
2435 (org-element-property :raw-link link
) info
))))
2436 ;; Fuzzy link points to an invisible target.
2438 ;; LINK points to an headline. If headlines are numbered
2439 ;; and the link has no description, display headline's
2440 ;; number. Otherwise, display description or headline's
2443 (let* ((headline-no (org-export-get-headline-number destination info
))
2444 (label (format "sec-%s" (mapconcat 'number-to-string
2446 (section-no (mapconcat 'number-to-string headline-no
".")))
2450 ((plist-get info
:section-numbers
) section-no
)
2451 (t (org-export-secondary-string
2452 (org-element-property :title destination
) info
))))
2453 (format "<a href=\"#%s\">%s</a>" label desc
)))
2454 ;; Fuzzy link points to a target. Do as above.
2456 (let ((path (org-export-solidify-link-text path
)) number
)
2459 ((org-e-html-standalone-image-p destination info
)
2460 (org-export-get-ordinal
2461 (assoc 'link
(org-element-contents destination
))
2462 info
'link
'org-e-html-standalone-image-p
))
2463 (t (org-export-get-ordinal destination info
))))
2464 (setq desc
(when number
2465 (if (atom number
) (number-to-string number
)
2466 (mapconcat 'number-to-string number
".")))))
2467 (format "<a href=\"#%s\">%s</a>" path
(or desc
"FIXME")))))))
2468 ;; Coderef: replace link with the reference name or the
2469 ;; equivalent line number.
2470 ((string= type
"coderef")
2471 (let ((fragment (concat "coderef-" path
)))
2472 (format "<a href=\"#%s\" %s>%s</a>" fragment
2473 (format (concat "class=\"coderef\""
2474 " onmouseover=\"CodeHighlightOn(this, '%s');\""
2475 " onmouseout=\"CodeHighlightOff(this, '%s');\"")
2477 (format (org-export-get-coderef-format path desc
)
2478 (org-export-resolve-coderef path info
)))))
2479 ;; Link type is handled by a special function.
2480 ((functionp (setq protocol
(nth 2 (assoc type org-link-protocols
))))
2481 (funcall protocol
(org-link-unescape path
) desc
'html
))
2482 ;; External link with a description part.
2483 ((and path desc
) (format "<a href=\"%s\">%s</a>" path desc
))
2484 ;; External link without a description part.
2485 (path (format "<a href=\"%s\">%s</a>" path path
))
2486 ;; No path, only description. Try to do something useful.
2487 (t (format "<i>%s</i>" desc
)))))
2492 ;; Babel Calls are ignored.
2497 (defun org-e-html-macro (macro contents info
)
2498 "Transcode a MACRO element from Org to HTML.
2499 CONTENTS is nil. INFO is a plist holding contextual information."
2500 ;; Use available tools.
2501 (org-export-expand-macro macro info
))
2506 (defun org-e-html-paragraph (paragraph contents info
)
2507 "Transcode a PARAGRAPH element from Org to HTML.
2508 CONTENTS is the contents of the paragraph, as a string. INFO is
2509 the plist used as a communication channel."
2510 (let* ((style nil
) ; FIXME
2511 (class (cdr (assoc style
'((footnote .
"footnote")
2513 (extra (if class
(format " class=\"%s\"" class
) ""))
2514 (parent (org-export-get-parent paragraph info
)))
2516 ((and (equal (car parent
) 'item
)
2517 (= (org-element-property :begin paragraph
)
2518 (org-element-property :contents-begin parent
)))
2519 ;; leading paragraph in a list item have no tags
2521 ((org-e-html-standalone-image-p paragraph info
)
2524 (t (format "\n<p%s>\n%s\n</p>" extra contents
)))))
2529 (defun org-e-html-begin-plain-list (type &optional arg1
)
2532 (format "<ol%s>" (if arg1
; FIXME
2533 (format " start=\"%d\"" arg1
)
2536 (descriptive "<dl>")))
2538 (defun org-e-html-end-plain-list (type)
2542 (descriptive "</dl>")))
2544 (defun org-e-html-plain-list (plain-list contents info
)
2545 "Transcode a PLAIN-LIST element from Org to HTML.
2546 CONTENTS is the contents of the list. INFO is a plist holding
2547 contextual information."
2548 (let* (arg1 ;; FIXME
2549 (type (org-element-property :type plain-list
))
2550 (attr (mapconcat #'identity
2551 (org-element-property :attr_html plain-list
)
2553 (org-e-html--wrap-label
2554 plain-list
(format "%s\n%s%s"
2555 (org-e-html-begin-plain-list type
)
2556 contents
(org-e-html-end-plain-list type
)))))
2560 (defun org-e-html-convert-special-strings (string)
2561 "Convert special characters in STRING to HTML."
2562 (let ((all org-e-html-special-string-regexps
)
2564 (while (setq a
(pop all
))
2565 (setq re
(car a
) rpl
(cdr a
) start
0)
2566 (while (string-match re string start
)
2567 (setq string
(replace-match rpl t nil string
))))
2570 (defun org-e-html-encode-plain-text (s)
2571 "Convert plain text characters to HTML equivalent.
2572 Possible conversions are set in `org-export-html-protect-char-alist'."
2573 (let ((cl org-e-html-protect-char-alist
) c
)
2574 (while (setq c
(pop cl
))
2576 (while (string-match (car c
) s start
)
2577 (setq s
(replace-match (cdr c
) t t s
)
2578 start
(1+ (match-beginning 0))))))
2581 (defun org-e-html-plain-text (text info
)
2582 "Transcode a TEXT string from Org to HTML.
2583 TEXT is the string to transcode. INFO is a plist holding
2584 contextual information."
2585 (setq text
(org-e-html-encode-plain-text text
))
2586 ;; Protect %, #, &, $, ~, ^, _, { and }.
2587 ;; (while (string-match "\\([^\\]\\|^\\)\\([%$#&{}~^_]\\)" text)
2589 ;; (replace-match (format "\\%s" (match-string 2 text)) nil t text 2)))
2591 ;; (setq text (replace-regexp-in-string
2592 ;; "\\(?:[^\\]\\|^\\)\\(\\\\\\)\\(?:[^%$#&{}~^_\\]\\|$\\)"
2593 ;; "$\\backslash$" text nil t 1))
2594 ;; HTML into \HTML{} and TeX into \TeX{}.
2595 ;; (let ((case-fold-search nil)
2597 ;; (while (string-match "\\<\\(\\(?:La\\)?TeX\\)\\>" text start)
2598 ;; (setq text (replace-match
2599 ;; (format "\\%s{}" (match-string 1 text)) nil t text)
2600 ;; start (match-end 0))))
2601 ;; Handle quotation marks
2602 ;; (setq text (org-e-html--quotation-marks text info))
2603 ;; Convert special strings.
2604 ;; (when (plist-get info :with-special-strings)
2605 ;; (while (string-match (regexp-quote "...") text)
2606 ;; (setq text (replace-match "\\ldots{}" nil t text))))
2607 (when (plist-get info
:with-special-strings
)
2608 (setq text
(org-e-html-convert-special-strings text
)))
2609 ;; Handle break preservation if required.
2610 (when (plist-get info
:preserve-breaks
)
2611 (setq text
(replace-regexp-in-string "\\(\\\\\\\\\\)?[ \t]*\n" " \\\\\\\\\n"
2617 ;;;; Property Drawer
2619 (defun org-e-html-property-drawer (property-drawer contents info
)
2620 "Transcode a PROPERTY-DRAWER element from Org to HTML.
2621 CONTENTS is nil. INFO is a plist holding contextual
2623 ;; The property drawer isn't exported but we want separating blank
2624 ;; lines nonetheless.
2630 (defun org-e-html-quote-block (quote-block contents info
)
2631 "Transcode a QUOTE-BLOCK element from Org to HTML.
2632 CONTENTS holds the contents of the block. INFO is a plist
2633 holding contextual information."
2634 (org-e-html--wrap-label
2635 quote-block
(format "<blockquote>\n%s</blockquote>" contents
)))
2640 (defun org-e-html-quote-section (quote-section contents info
)
2641 "Transcode a QUOTE-SECTION element from Org to HTML.
2642 CONTENTS is nil. INFO is a plist holding contextual information."
2643 (let ((value (org-remove-indentation
2644 (org-element-property :value quote-section
))))
2645 (when value
(format "<pre>\n%s</pre>" value
))))
2650 (defun org-e-html-section (section contents info
) ; FIXME
2651 "Transcode a SECTION element from Org to HTML.
2652 CONTENTS holds the contents of the section. INFO is a plist
2653 holding contextual information."
2654 (let ((parent (org-export-get-parent-headline section info
)))
2655 ;; Before first headline: no container, just return CONTENTS.
2656 (if (not parent
) contents
2657 ;; Get div's class and id references.
2658 (let ((class-num (+ (org-export-get-relative-level parent info
)
2659 (1- org-e-html-toplevel-hlevel
)))
2663 (org-export-get-headline-number parent info
) "-")))
2664 ;; Build return value.
2665 (format "<div class=\"outline-text-%d\" id=\"text-%s\">\n%s</div>"
2666 class-num id-num contents
)))))
2670 (defun org-e-html-radio-target (radio-target text info
)
2671 "Transcode a RADIO-TARGET object from Org to HTML.
2672 TEXT is the text of the target. INFO is a plist holding
2673 contextual information."
2674 (let ((id (org-export-solidify-link-text
2675 (org-element-property :value radio-target
))))
2676 (format "<a id=\"%s\" name=\"%s\">%s</a>" id id text
)))
2681 (defun org-e-html-special-block (special-block contents info
)
2682 "Transcode a SPECIAL-BLOCK element from Org to HTML.
2683 CONTENTS holds the contents of the block. INFO is a plist
2684 holding contextual information."
2685 (let ((type (downcase (org-element-property :type special-block
))))
2686 (org-e-html--wrap-label
2688 (format "\\begin{%s}\n%s\\end{%s}" type contents type
))))
2693 (defun org-e-html-src-block (src-block contents info
)
2694 "Transcode a SRC-BLOCK element from Org to HTML.
2695 CONTENTS holds the contents of the item. INFO is a plist holding
2696 contextual information."
2697 (let* ((lang (org-element-property :language src-block
))
2698 (caption (org-element-property :caption src-block
))
2699 (label (org-element-property :name src-block
))
2700 (caption-str (org-e-html--caption/label-string caption label info
))
2701 (attr (mapconcat #'identity
2702 (org-element-property :attr_html src-block
)
2704 ;; (switches (org-element-property :switches src-block))
2705 (switches nil
) ; FIXME
2706 (textarea-p (and switches
(string-match "-t\\>" switches
)))
2707 (code (org-e-html-format-code src-block info
)))
2710 "\n<div class=\"org-src-container\">\n%s%s\n</div>"
2711 (if (not caption
) ""
2712 (format "<label class=\"org-src-name\">%s</label>" caption-str
))
2713 (format "\n<pre class=\"src src-%s\">%s\n</pre>" lang code
)))
2715 (let ((cols (if (not (string-match "-w[ \t]+\\([0-9]+\\)" switches
))
2716 80 (string-to-number (match-string 1 switches
))))
2717 (rows (if (string-match "-h[ \t]+\\([0-9]+\\)" switches
)
2718 (string-to-number (match-string 1 switches
))
2719 (org-count-lines code
))))
2721 "\n<p>\n<textarea cols=\"%d\" rows=\"%d\">\n%s\n</textarea>\n</p>"
2723 (t (format "\n<pre class=\"example\">\n%s\n</pre>" code
)))))
2725 ;;;; Statistics Cookie
2727 (defun org-e-html-statistics-cookie (statistics-cookie contents info
)
2728 "Transcode a STATISTICS-COOKIE object from Org to HTML.
2729 CONTENTS is nil. INFO is a plist holding contextual information."
2730 (let ((cookie-value (org-element-property :value statistics-cookie
)))
2731 (format "<code>%s</code>" cookie-value
)))
2736 (defun org-e-html-subscript (subscript contents info
)
2737 "Transcode a SUBSCRIPT object from Org to HTML.
2738 CONTENTS is the contents of the object. INFO is a plist holding
2739 contextual information."
2740 (format "<sub>%s</sub>" contents
))
2745 (defun org-e-html-superscript (superscript contents info
)
2746 "Transcode a SUPERSCRIPT object from Org to HTML.
2747 CONTENTS is the contents of the object. INFO is a plist holding
2748 contextual information."
2749 (format "<sup>%s</sup>" contents
))
2754 (defun org-e-html-table-cell (table-cell contents info
)
2755 "Transcode a TABLE-CELL element from Org to HTML.
2756 CONTENTS is nil. INFO is a plist used as a communication
2758 (let* ((table-row (org-export-get-parent table-cell info
))
2759 (table (org-export-get-parent-table table-cell info
))
2761 (if (not org-e-html-table-align-individual-fields
) ""
2762 (format (if (and (boundp 'org-e-html-format-table-no-css
)
2763 org-e-html-format-table-no-css
)
2764 " align=\"%s\"" " class=\"%s\"")
2765 (org-export-table-cell-alignment table-cell info
)))))
2766 (when (or (not contents
) (string= "" (org-trim contents
)))
2767 (setq contents
" "))
2769 ((and (org-export-table-has-header-p table info
)
2770 (= 1 (org-export-table-row-group table-row info
)))
2771 (concat "\n" (format (car org-e-html-table-header-tags
) "col" cell-attrs
)
2772 contents
(cdr org-e-html-table-header-tags
)))
2773 ((and org-e-html-table-use-header-tags-for-first-column
2774 (zerop (cdr (org-export-table-cell-address table-cell info
))))
2775 (concat "\n" (format (car org-e-html-table-header-tags
) "row" cell-attrs
)
2776 contents
(cdr org-e-html-table-header-tags
)))
2777 (t (concat "\n" (format (car org-e-html-table-data-tags
) cell-attrs
)
2778 contents
(cdr org-e-html-table-data-tags
))))))
2783 (defun org-e-html-table-row (table-row contents info
)
2784 "Transcode a TABLE-ROW element from Org to HTML.
2785 CONTENTS is the contents of the row. INFO is a plist used as a
2786 communication channel."
2787 ;; Rules are ignored since table separators are deduced from
2788 ;; borders of the current row.
2789 (when (eq (org-element-property :type table-row
) 'standard
)
2790 (let* ((first-rowgroup-p (= 1 (org-export-table-row-group table-row info
)))
2793 ;; Case 1: Row belongs to second or subsequent rowgroups.
2794 ((not (= 1 (org-export-table-row-group table-row info
)))
2795 '("\n<tbody>" .
"\n</tbody>"))
2796 ;; Case 2: Row is from first rowgroup. Table has >=1 rowgroups.
2797 ((org-export-table-has-header-p
2798 (org-export-get-parent-table table-row info
) info
)
2799 '("\n<thead>" .
"\n</thead>"))
2800 ;; Case 2: Row is from first and only row group.
2801 (t '("\n<tbody>" .
"\n</tbody>")))))
2803 ;; Begin a rowgroup?
2804 (when (org-export-table-row-starts-rowgroup-p table-row info
)
2805 (car rowgroup-tags
))
2807 (concat "\n" (eval (car org-e-html-table-row-tags
))
2808 contents
(eval (cdr org-e-html-table-row-tags
)))
2810 (when (org-export-table-row-ends-rowgroup-p table-row info
)
2811 (cdr rowgroup-tags
))))))
2816 (defun org-e-html-table-first-row-data-cells (table info
)
2821 (unless (eq (org-element-property :type row
) 'rule
) row
))
2823 (special-column-p (org-export-table-has-special-column-p table
)))
2824 (if (not special-column-p
) (org-element-contents table-row
)
2825 (cdr (org-element-contents table-row
)))))
2827 (defun org-e-html-table--table.el-table
(table info
)
2828 (when (eq (org-element-property :type table
) 'table.el
)
2830 (let ((outbuf (with-current-buffer
2831 (get-buffer-create "*org-export-table*")
2832 (erase-buffer) (current-buffer))))
2834 (insert (org-element-property :value table
))
2836 (re-search-forward "^[ \t]*|[^|]" nil t
)
2837 (table-generate-source 'html outbuf
))
2838 (with-current-buffer outbuf
2839 (prog1 (org-trim (buffer-string))
2842 (defun org-e-html-table (table contents info
)
2843 "Transcode a TABLE element from Org to HTML.
2844 CONTENTS is nil. INFO is a plist holding contextual information."
2845 (case (org-element-property :type table
)
2846 ;; Case 1: table.el table. Convert it using appropriate tools.
2847 (table.el
(org-e-html-table--table.el-table table info
))
2848 ;; Case 2: Standard table.
2850 (let* ((label (org-element-property :name table
))
2851 (caption (org-e-html--caption/label-string
2852 (org-element-property :caption table
) label info
))
2853 (attributes (mapconcat #'identity
2854 (org-element-property :attr_html table
)
2857 (if (and (boundp 'org-e-html-format-table-no-css
)
2858 org-e-html-format-table-no-css
)
2859 "align=\"%s\"" "class=\"%s\""))
2862 (lambda (table info
)
2864 (lambda (table-cell)
2865 (let ((alignment (org-export-table-cell-alignment
2868 ;; Begin a colgroup?
2869 (when (org-export-table-cell-starts-colgroup-p
2872 ;; Add a column. Also specify it's alignment.
2873 (format "\n<col %s/>" (format alignspec alignment
))
2875 (when (org-export-table-cell-ends-colgroup-p
2878 (org-e-html-table-first-row-data-cells table info
) "\n"))))
2880 (let ((table-tag (plist-get info
:html-table-tag
)))
2882 (and (string-match "<table\\(.*\\)>" table-tag
)
2883 (match-string 1 table-tag
))
2884 (and label
(format " id=\"%s\""
2885 (org-solidify-link-text label
)))))))
2886 ;; Remove last blank line.
2887 (setq contents
(substring contents
0 -
1))
2889 (format "\n<table%s>\n<caption>%s</caption>\n%s\n%s\n</table>"
2892 (funcall table-column-specs table info
)
2897 (defun org-e-html-target (target contents info
)
2898 "Transcode a TARGET object from Org to HTML.
2899 CONTENTS is nil. INFO is a plist holding contextual
2901 (let ((id (org-export-solidify-link-text
2902 (org-element-property :value target
))))
2903 (format "<a id=\"%s\" name=\"%s\"/>" id id
)))
2908 (defun org-e-html-time-stamp (time-stamp contents info
)
2909 "Transcode a TIME-STAMP object from Org to HTML.
2910 CONTENTS is nil. INFO is a plist holding contextual
2912 (let ((value (org-element-property :value time-stamp
))
2913 (type (org-element-property :type time-stamp
))
2914 (appt-type (org-element-property :appt-type time-stamp
)))
2915 (setq value
(org-translate-time (org-export-secondary-string value info
)))
2916 (setq appt-type
(case appt-type
2917 (scheduled org-scheduled-string
)
2918 (deadline org-deadline-string
)
2919 (closed org-closed-string
)))
2920 (format "<span class=\"timestamp-wrapper\">%s%s</span>"
2921 (if (not appt-type
) ""
2922 (format "<span class=\"timestamp-kwd\">%s</span> " appt-type
))
2923 (format "<span class=\"timestamp\">%s</span>" value
))))
2928 (defun org-e-html-verbatim (verbatim contents info
)
2929 "Transcode a VERBATIM object from Org to HTML.
2930 CONTENTS is nil. INFO is a plist used as a communication
2932 (org-e-html-emphasis
2933 verbatim
(org-element-property :value verbatim
) info
))
2938 (defun org-e-html-verse-block (verse-block contents info
)
2939 "Transcode a VERSE-BLOCK element from Org to HTML.
2940 CONTENTS is verse block contents. INFO is a plist holding
2941 contextual information."
2942 ;; Replace each newline character with line break. Also replace
2943 ;; each blank line with a line break.
2944 (setq contents
(replace-regexp-in-string
2945 "^ *\\\\\\\\$" "<br/>\n"
2946 (replace-regexp-in-string
2947 "\\(\\\\\\\\\\)?[ \t]*\n" " <br/>\n" contents
)))
2948 ;; Replace each white space at beginning of a line with a
2949 ;; non-breaking space.
2950 (while (string-match "^[ \t]+" contents
)
2951 (let* ((num-ws (length (match-string 0 contents
)))
2952 (ws (let (out) (dotimes (i num-ws out
)
2953 (setq out
(concat out
" "))))))
2954 (setq contents
(replace-match ws nil t contents
))))
2955 (org-e-html--wrap-label
2956 verse-block
(format "<p class=\"verse\">\n%s</p>" contents
)))
2961 ;;; Filter Functions
2963 ;;;; Filter Settings
2965 (defconst org-e-html-filters-alist
2966 '((:filter-final-output . org-e-html-final-function
))
2967 "Alist between filters keywords and back-end specific filters.
2968 See `org-export-filters-alist' for more information.")
2973 (defun org-e-html-final-function (contents backend info
)
2974 (if (not org-e-html-pretty-output
) contents
2978 (indent-region (point-min) (point-max))
2979 (buffer-substring-no-properties (point-min) (point-max)))))
2982 ;;; Interactive functions
2984 (defun org-e-html-export-to-html
2985 (&optional subtreep visible-only body-only ext-plist pub-dir
)
2986 "Export current buffer to a HTML file.
2988 If narrowing is active in the current buffer, only export its
2991 If a region is active, export that region.
2993 When optional argument SUBTREEP is non-nil, export the sub-tree
2994 at point, extracting information from the headline properties
2997 When optional argument VISIBLE-ONLY is non-nil, don't export
2998 contents of hidden elements.
3000 When optional argument BODY-ONLY is non-nil, only write code
3001 between \"\\begin{document}\" and \"\\end{document}\".
3003 EXT-PLIST, when provided, is a property list with external
3004 parameters overriding Org default settings, but still inferior to
3005 file-local settings.
3007 When optional argument PUB-DIR is set, use it as the publishing
3010 Return output file's name."
3012 (setq debug-on-error t
) ; FIXME
3013 (let* ((extension (concat "." org-e-html-extension
))
3014 (file (org-export-output-file-name extension subtreep pub-dir
)))
3016 'e-html file subtreep visible-only body-only ext-plist
)))
3020 ;;; FIXMES, TODOS, FOR REVIEW etc
3022 ;;;; org-format-table-html
3023 ;;;; org-format-org-table-html
3024 ;;;; org-format-table-table-html
3025 ;;;; org-table-number-fraction
3026 ;;;; org-table-number-regexp
3027 ;;;; org-e-html-table-caption-above
3030 ;;;; "<span style=\"visibility:hidden;\">%s</span>"
3031 ;;;; Remove display properties
3033 ;;;; org-e-html-with-timestamp
3034 ;;;; org-e-html-html-helper-timestamp
3036 ;;;; org-export-as-html-and-open
3037 ;;;; org-export-as-html-batch
3038 ;;;; org-export-as-html-to-buffer
3039 ;;;; org-replace-region-by-html
3040 ;;;; org-export-region-as-html
3041 ;;;; org-export-as-html
3043 ;;;; (org-export-directory :html opt-plist)
3044 ;;;; (plist-get opt-plist :html-extension)
3045 ;;;; org-e-html-toplevel-hlevel
3046 ;;;; org-e-html-special-string-regexps
3047 ;;;; org-e-html-coding-system
3048 ;;;; org-e-html-coding-system
3049 ;;;; org-e-html-inline-images
3050 ;;;; org-e-html-inline-image-extensions
3051 ;;;; org-e-html-protect-char-alist
3052 ;;;; org-e-html-table-use-header-tags-for-first-column
3053 ;;;; org-e-html-todo-kwd-class-prefix
3054 ;;;; org-e-html-tag-class-prefix
3055 ;;;; org-e-html-footnote-separator
3057 ;;;; org-export-preferred-target-alist
3058 ;;;; org-solidify-link-text
3059 ;;;; class for anchors
3060 ;;;; org-export-with-section-numbers, body-only
3061 ;;;; org-export-mark-todo-in-toc
3063 (provide 'org-e-html
)
3064 ;;; org-e-html.el ends here