1 ;;; org-xhtml.el --- XHTML export for Org-mode (uses org-lparse)
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is not (yet) part of GNU Emacs.
12 ;; However, it is distributed under the same license.
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (require 'format-spec
)
37 (eval-when-compile (require 'cl
) (require 'table
) (require 'browse-url
))
39 (declare-function org-id-find-id-file
"org-id" (id))
40 (declare-function htmlize-region
"ext:htmlize" (beg end
))
42 (defgroup org-export-xhtml nil
43 "Options specific for HTML export of Org-mode files."
44 :tag
"Org Export HTML"
47 (defconst org-export-xhtml-special-string-regexps
49 ("---\\([^-]\\)" .
"—\\1")
50 ("--\\([^-]\\)" .
"–\\1")
51 ("\\.\\.\\." .
"…"))
52 "Regular expressions for special string conversion.")
54 (defcustom org-export-xhtml-footnotes-section
"<div id=\"footnotes\">
55 <h2 class=\"footnotes\">%s: </h2>
56 <div id=\"text-footnotes\">
60 "Format for the footnotes section.
61 Should contain a two instances of %s. The first will be replaced with the
62 language-specific word for \"Footnotes\", the second one will be replaced
63 by the footnotes themselves."
64 :group
'org-export-xhtml
67 (defcustom org-export-xhtml-footnote-format
"<sup>%s</sup>"
68 "The format for the footnote reference.
69 %s will be replaced by the footnote reference itself."
70 :group
'org-export-xhtml
74 (defcustom org-export-xhtml-footnote-separator
"<sup>, </sup>"
75 "Text used to separate footnotes."
76 :group
'org-export-xhtml
79 (defcustom org-export-xhtml-coding-system nil
80 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
81 :group
'org-export-xhtml
84 (defcustom org-export-xhtml-extension
"html"
85 "The extension for exported HTML files."
86 :group
'org-export-xhtml
89 (defcustom org-export-xhtml-xml-declaration
90 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
91 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
92 "The extension for exported HTML files.
93 %s will be replaced with the charset of the exported file.
94 This may be a string, or an alist with export extensions
95 and corresponding declarations."
96 :group
'org-export-xhtml
98 (string :tag
"Single declaration")
99 (repeat :tag
"Dependent on extension"
100 (cons (string :tag
"Extension")
101 (string :tag
"Declaration")))))
103 (defcustom org-export-xhtml-style-include-scripts t
104 "Non-nil means include the JavaScript snippets in exported HTML files.
105 The actual script is defined in `org-export-xhtml-scripts' and should
107 :group
'org-export-xhtml
110 (defconst org-export-xhtml-scripts
111 "<script type=\"text/javascript\">
112 <!--/*--><![CDATA[/*><!--*/
113 function CodeHighlightOn(elem, id)
115 var target = document.getElementById(id);
117 elem.cacheClassElem = elem.className;
118 elem.cacheClassTarget = target.className;
119 target.className = \"code-highlighted\";
120 elem.className = \"code-highlighted\";
123 function CodeHighlightOff(elem, id)
125 var target = document.getElementById(id);
126 if(elem.cacheClassElem)
127 elem.className = elem.cacheClassElem;
128 if(elem.cacheClassTarget)
129 target.className = elem.cacheClassTarget;
133 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
135 (defconst org-export-xhtml-style-default
136 "<style type=\"text/css\">
137 <!--/*--><![CDATA[/*><!--*/
138 html { font-family: Times, serif; font-size: 12pt; }
139 .title { text-align: center; }
140 .todo { color: red; }
141 .done { color: green; }
142 .tag { background-color: #add8e6; font-weight:normal }
144 .timestamp { color: #bebebe; }
145 .timestamp-kwd { color: #5f9ea0; }
146 .right {margin-left:auto; margin-right:0px; text-align:right;}
147 .left {margin-left:0px; margin-right:auto; text-align:left;}
148 .center {margin-left:auto; margin-right:auto; text-align:center;}
149 p.verse { margin-left: 3% }
151 border: 1pt solid #AEBDCC;
152 background-color: #F3F5F7;
154 font-family: courier, monospace;
158 table { border-collapse: collapse; }
159 td, th { vertical-align: top; }
160 th.right { text-align:center; }
161 th.left { text-align:center; }
162 th.center { text-align:center; }
163 td.right { text-align:right; }
164 td.left { text-align:left; }
165 td.center { text-align:center; }
166 dt { font-weight: bold; }
167 div.figure { padding: 0.5em; }
168 div.figure p { text-align: center; }
169 textarea { overflow-x: auto; }
170 .linenr { font-size:smaller }
171 .code-highlighted {background-color:#ffff00;}
172 .org-info-js_info-navigation { border-style:none; }
173 #org-info-js_console-label { font-size:10px; font-weight:bold;
174 white-space:nowrap; }
175 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
179 "The default style specification for exported HTML files.
180 Please use the variables `org-export-xhtml-style' and
181 `org-export-xhtml-style-extra' to add to this style. If you wish to not
182 have the default style included, customize the variable
183 `org-export-xhtml-style-include-default'.")
185 (defcustom org-export-xhtml-style-include-default t
186 "Non-nil means include the default style in exported HTML files.
187 The actual style is defined in `org-export-xhtml-style-default' and should
188 not be modified. Use the variables `org-export-xhtml-style' to add
189 your own style information."
190 :group
'org-export-xhtml
193 (put 'org-export-xhtml-style-include-default
'safe-local-variable
'booleanp
)
195 (defcustom org-export-xhtml-style
""
196 "Org-wide style definitions for exported HTML files.
198 This variable needs to contain the full HTML structure to provide a style,
199 including the surrounding HTML tags. If you set the value of this variable,
200 you should consider to include definitions for the following classes:
201 title, todo, done, timestamp, timestamp-kwd, tag, target.
203 For example, a valid value would be:
205 <style type=\"text/css\">
207 p { font-weight: normal; color: gray; }
209 .title { text-align: center; }
210 .todo, .timestamp-kwd { color: red; }
211 .done { color: green; }
215 If you'd like to refer to an external style file, use something like
217 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
219 As the value of this option simply gets inserted into the HTML <head> header,
220 you can \"misuse\" it to add arbitrary text to the header.
221 See also the variable `org-export-xhtml-style-extra'."
222 :group
'org-export-xhtml
225 (put 'org-export-xhtml-style
'safe-local-variable
'stringp
)
227 (defcustom org-export-xhtml-style-extra
""
228 "Additional style information for HTML export.
229 The value of this variable is inserted into the HTML buffer right after
230 the value of `org-export-xhtml-style'. Use this variable for per-file
231 settings of style information, and do not forget to surround the style
232 settings with <style>...</style> tags."
233 :group
'org-export-xhtml
236 (put 'org-export-xhtml-style-extra
'safe-local-variable
'stringp
)
238 (defcustom org-export-xhtml-mathjax-options
239 '((path "http://orgmode.org/mathjax/MathJax.js")
244 "Options for MathJax setup.
246 path The path where to find MathJax
247 scale Scaling for the HTML-CSS backend, usually between 100 and 133
248 align How to align display math: left, center, or right
249 indent If align is not center, how far from the left/right side?
250 mathml Should a MathML player be used if available?
251 This is faster and reduces bandwidth use, but currently
252 sometimes has lower spacing quality. Therefore, the default is
253 nil. When browsers get better, this switch can be flipped.
255 You can also customize this for each buffer, using something like
257 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
258 :group
'org-export-xhtml
259 :type
'(list :greedy t
260 (list :tag
"path (the path from where to load MathJax.js)"
261 (const :format
" " path
) (string))
262 (list :tag
"scale (scaling for the displayed math)"
263 (const :format
" " scale
) (string))
264 (list :tag
"align (alignment of displayed equations)"
265 (const :format
" " align
) (string))
266 (list :tag
"indent (indentation with left or right alignment)"
267 (const :format
" " indent
) (string))
268 (list :tag
"mathml (should MathML display be used is possible)"
269 (const :format
" " mathml
) (boolean))))
271 (defun org-export-xhtml-mathjax-config (template options in-buffer
)
272 "Insert the user setup into the matchjax template."
273 (let (name val
(yes " ") (no "// ") x
)
276 (setq name
(car e
) val
(nth 1 e
))
277 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
278 (setq val
(car (read-from-string
279 (substring in-buffer
(match-end 0))))))
280 (if (not (stringp val
)) (setq val
(format "%s" val
)))
281 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
282 (setq template
(replace-match val t t template
))))
284 (setq val
(nth 1 (assq 'mathml options
)))
285 (if (string-match (concat "\\<mathml:") in-buffer
)
286 (setq val
(car (read-from-string
287 (substring in-buffer
(match-end 0))))))
288 ;; Exchange prefixes depending on mathml setting
289 (if (not val
) (setq x yes yes no no x
))
290 ;; Replace cookies to turn on or off the config/jax lines
291 (if (string-match ":MMLYES:" template
)
292 (setq template
(replace-match yes t t template
)))
293 (if (string-match ":MMLNO:" template
)
294 (setq template
(replace-match no t t template
)))
295 ;; Return the modified template
298 (defcustom org-export-xhtml-mathjax-template
299 "<script type=\"text/javascript\" src=\"%PATH\">
300 <!--/*--><![CDATA[/*><!--*/
302 // Only one of the two following lines, depending on user settings
303 // First allows browser-native MathML display, second forces HTML/CSS
304 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
305 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
306 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
307 \"TeX/noUndefined.js\"],
309 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
310 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
311 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
312 ignoreClass: \"tex2jax_ignore\",
313 processEscapes: false,
314 processEnvironments: true,
317 showProcessingMessages: true,
318 displayAlign: \"%ALIGN\",
319 displayIndent: \"%INDENT\",
323 availableFonts: [\"STIX\",\"TeX\"],
324 preferredFont: \"TeX\",
340 "The MathJax setup for XHTML files."
341 :group
'org-export-xhtml
344 (defcustom org-export-xhtml-tag-class-prefix
""
345 "Prefix to class names for TODO keywords.
346 Each tag gets a class given by the tag itself, with this prefix.
347 The default prefix is empty because it is nice to just use the keyword
348 as a class name. But if you get into conflicts with other, existing
349 CSS classes, then this prefix can be very useful."
350 :group
'org-export-xhtml
353 (defcustom org-export-xhtml-todo-kwd-class-prefix
""
354 "Prefix to class names for TODO keywords.
355 Each TODO keyword gets a class given by the keyword itself, with this prefix.
356 The default prefix is empty because it is nice to just use the keyword
357 as a class name. But if you get into conflicts with other, existing
358 CSS classes, then this prefix can be very useful."
359 :group
'org-export-xhtml
362 (defcustom org-export-xhtml-preamble t
363 "Non-nil means insert a preamble in HTML export.
365 When `t', insert a string as defined by one of the formatting
366 strings in `org-export-xhtml-preamble-format'. When set to a
367 string, this string overrides `org-export-xhtml-preamble-format'.
368 When set to a function, apply this function and insert the
369 returned string. The function takes the property list of export
370 options as its only argument.
372 Setting :html-preamble in publishing projects will take
373 precedence over this variable."
374 :group
'org-export-xhtml
375 :type
'(choice (const :tag
"No preamble" nil
)
376 (const :tag
"Default preamble" t
)
377 (string :tag
"Custom formatting string")
378 (function :tag
"Function (must return a string)")))
380 (defcustom org-export-xhtml-preamble-format
381 '(("en" "<h1 class=\"title\">%t</h1>"))
382 "The format for the HTML preamble.
384 %t stands for the title.
386 If you need to use a \"%\" character, you need to escape it
388 :group
'org-export-xhtml
391 (defcustom org-export-xhtml-postamble
'auto
392 "Non-nil means insert a postamble in HTML export.
394 When `t', insert a string as defined by the formatting string in
395 `org-export-xhtml-postamble-format'. When set to a string, this
396 string overrides `org-export-xhtml-postamble-format'. When set to
397 'auto, discard `org-export-xhtml-postamble-format' and honor
398 `org-export-author/email/creator-info' variables. When set to a
399 function, apply this function and insert the returned string.
400 The function takes the property list of export options as its
403 Setting :html-postamble in publishing projects will take
404 precedence over this variable."
405 :group
'org-export-xhtml
406 :type
'(choice (const :tag
"No postamble" nil
)
407 (const :tag
"Auto preamble" 'auto
)
408 (const :tag
"Default formatting string" t
)
409 (string :tag
"Custom formatting string")
410 (function :tag
"Function (must return a string)")))
412 (defcustom org-export-xhtml-postamble-format
413 '(("en" "<p class=\"author\">Author: %a (%e)</p>
414 <p class=\"date\">Date: %d</p>
415 <p class=\"creator\">Generated by %c</p>
416 <p class=\"xhtml-validation\">%v</p>
418 "The format for the HTML postamble.
420 %a stands for the author.
421 %e stands for the email(s).
422 %d stands for the date.
423 %c will be replaced by information about Org/Emacs.
424 %v will be replaced by `org-export-xhtml-validation-link'.
426 If you need to use a \"%\" character, you need to escape it
428 :group
'org-export-xhtml
431 (defcustom org-export-xhtml-home
/up-format
432 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
433 <a accesskey=\"h\" href=\"%s\"> UP </a>
435 <a accesskey=\"H\" href=\"%s\"> HOME </a>
437 "Snippet used to insert the HOME and UP links.
438 This is a format string, the first %s will receive the UP link,
439 the second the HOME link. If both `org-export-xhtml-link-up' and
440 `org-export-xhtml-link-home' are empty, the entire snippet will be
442 :group
'org-export-xhtml
445 (defcustom org-export-xhtml-toplevel-hlevel
2
446 "The <H> level for level 1 headings in HTML export.
447 This is also important for the classes that will be wrapped around headlines
448 and outline structure. If this variable is 1, the top-level headlines will
449 be <h1>, and the corresponding classes will be outline-1, section-number-1,
450 and outline-text-1. If this is 2, all of these will get a 2 instead.
451 The default for this variable is 2, because we use <h1> for formatting the
453 :group
'org-export-xhtml
456 (defcustom org-export-xhtml-link-org-files-as-html t
457 "Non-nil means make file links to `file.org' point to `file.html'.
458 When org-mode is exporting an org-mode file to HTML, links to
459 non-html files are directly put into a href tag in HTML.
460 However, links to other Org-mode files (recognized by the
461 extension `.org.) should become links to the corresponding html
462 file, assuming that the linked org-mode file will also be
464 When nil, the links still point to the plain `.org' file."
465 :group
'org-export-xhtml
468 (defcustom org-export-xhtml-inline-images
'maybe
469 "Non-nil means inline images into exported HTML pages.
470 This is done using an <img> tag. When nil, an anchor with href is used to
471 link to the image. If this option is `maybe', then images in links with
472 an empty description will be inlined, while images with a description will
474 :group
'org-export-xhtml
475 :type
'(choice (const :tag
"Never" nil
)
476 (const :tag
"Always" t
)
477 (const :tag
"When there is no description" maybe
)))
479 (defcustom org-export-xhtml-inline-image-extensions
480 '("png" "jpeg" "jpg" "gif" "svg")
481 "Extensions of image files that can be inlined into HTML."
482 :group
'org-export-xhtml
483 :type
'(repeat (string :tag
"Extension")))
485 (defcustom org-export-xhtml-table-tag
486 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
487 "The HTML tag that is used to start a table.
488 This must be a <table> tag, but you may change the options like
489 borders and spacing."
490 :group
'org-export-xhtml
493 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
494 "The opening tag for table header fields.
495 This is customizable so that alignment options can be specified.
496 The first %s will be filled with the scope of the field, either row or col.
497 The second %s will be replaced by a style entry to align the field.
498 See also the variable `org-export-xhtml-table-use-header-tags-for-first-column'.
499 See also the variable `org-export-xhtml-table-align-individual-fields'."
500 :group
'org-export-tables
501 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
503 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
504 "The opening tag for table data fields.
505 This is customizable so that alignment options can be specified.
506 The first %s will be filled with the scope of the field, either row or col.
507 The second %s will be replaced by a style entry to align the field.
508 See also the variable `org-export-xhtml-table-align-individual-fields'."
509 :group
'org-export-tables
510 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
512 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
513 "The opening tag for table data fields.
514 This is customizable so that alignment options can be specified.
515 Instead of strings, these can be Lisp forms that will be evaluated
516 for each row in order to construct the table row tags. During evaluation,
517 the variable `head' will be true when this is a header line, nil when this
518 is a body line. And the variable `nline' will contain the line number,
519 starting from 1 in the first header line. For example
521 (setq org-export-table-row-tags
524 (if (= (mod nline 2) 1)
525 \"<tr class=\\\"tr-odd\\\">\"
526 \"<tr class=\\\"tr-even\\\">\"))
529 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
530 :group
'org-export-tables
532 (choice :tag
"Opening tag"
533 (string :tag
"Specify")
535 (choice :tag
"Closing tag"
536 (string :tag
"Specify")
539 (defcustom org-export-xhtml-table-align-individual-fields t
540 "Non-nil means attach style attributes for alignment to each table field.
541 When nil, alignment will only be specified in the column tags, but this
542 is ignored by some browsers (like Firefox, Safari). Opera does it right
544 :group
'org-export-tables
547 (defcustom org-export-xhtml-table-use-header-tags-for-first-column nil
548 "Non-nil means format column one in tables with header tags.
549 When nil, also column one will use data tags."
550 :group
'org-export-tables
553 (defcustom org-export-xhtml-validation-link
554 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
555 "Link to HTML validation service."
556 :group
'org-export-xhtml
559 (defcustom org-export-xhtml-with-timestamp nil
560 "If non-nil, write timestamp into the exported HTML text.
561 If non-nil, write `org-export-xhtml-html-helper-timestamp' into the
562 exported HTML text. Otherwise, the buffer will just be saved to
564 :group
'org-export-xhtml
567 (defcustom org-export-xhtml-html-helper-timestamp
568 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
569 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
570 :group
'org-export-xhtml
573 (defcustom org-export-xhtml-protect-char-alist
577 "Alist of characters to be converted by `org-html-protect'."
578 :type
'(repeat (cons (string :tag
"Character")
579 (string :tag
"HTML equivalent"))))
581 (defgroup org-export-xhtmlize nil
582 "Options for processing examples with htmlize.el."
583 :tag
"Org Export Htmlize"
584 :group
'org-export-xhtml
)
586 (defcustom org-export-xhtmlize-output-type
'inline-css
587 "Output type to be used by htmlize when formatting code snippets.
588 Choices are `css', to export the CSS selectors only, or `inline-css', to
589 export the CSS attribute values inline in the HTML. We use as default
590 `inline-css', in order to make the resulting HTML self-containing.
592 However, this will fail when using Emacs in batch mode for export, because
593 then no rich font definitions are in place. It will also not be good if
594 people with different Emacs setup contribute HTML files to a website,
595 because the fonts will represent the individual setups. In these cases,
596 it is much better to let Org/Htmlize assign classes only, and to use
597 a style file to define the look of these classes.
598 To get a start for your css file, start Emacs session and make sure that
599 all the faces you are interested in are defined, for example by loading files
600 in all modes you want. Then, use the command
601 \\[org-export-xhtmlize-generate-css] to extract class definitions."
602 :group
'org-export-xhtmlize
603 :type
'(choice (const css
) (const inline-css
)))
605 (defcustom org-export-xhtmlize-css-font-prefix
"org-"
606 "The prefix for CSS class names for htmlize font specifications."
607 :group
'org-export-xhtmlize
610 (defcustom org-export-xhtmlized-org-css-url nil
611 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
612 Normally when creating an htmlized version of an Org buffer, htmlize will
613 create CSS to define the font colors. However, this does not work when
614 converting in batch mode, and it also can look bad if different people
615 with different fontification setup work on the same website.
616 When this variable is non-nil, creating an htmlized version of an Org buffer
617 using `org-export-as-org' will remove the internal CSS section and replace it
618 with a link to this URL."
619 :group
'org-export-xhtmlize
621 (const :tag
"Keep internal css" nil
)
622 (string :tag
"URL or local href")))
626 (defvar org-export-xhtml-after-blockquotes-hook nil
627 "Hook run during HTML export, after blockquote, verse, center are done.")
629 (defvar org-export-xhtml-final-hook nil
630 "Hook run at the end of HTML export, in the new buffer.")
634 (defun org-export-xhtml-preprocess (parameters)
635 "Convert LaTeX fragments to images."
636 (when (and org-current-export-file
637 (plist-get parameters
:LaTeX-fragments
))
639 (concat "ltxpng/" (file-name-sans-extension
640 (file-name-nondirectory
641 org-current-export-file
)))
642 org-current-export-dir nil
"Creating LaTeX image %s"
645 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
646 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
647 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
648 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
650 (goto-char (point-min))
652 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
653 (org-if-unprotected-at (match-beginning 1)
654 (setq label
(match-string 1))
656 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
657 (setq l1
(substring label
(match-beginning 1)))
659 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
661 (defvar html-table-tag nil
) ; dynamically scoped into this.
664 ;; FIXME: it already exists in org-html.el
665 (defconst org-html-cvt-link-fn
667 "Function to convert link URLs to exportable URLs.
668 Takes two arguments, TYPE and PATH.
669 Returns exportable url as (TYPE PATH), or nil to signal that it
670 didn't handle this case.
671 Intended to be locally bound around a call to `org-export-as-html'." )
674 ;; FIXME: it already exists in org-html.el
675 (defun org-html-cvt-org-as-html (opt-plist type path
)
676 "Convert an org filename to an equivalent html filename.
677 If TYPE is not file, just return `nil'.
678 See variable `org-export-xhtml-link-org-files-as-html'"
682 org-export-xhtml-link-org-files-as-html
683 (string= type
"file")
684 (string-match "\\.org$" path
)
689 (substring path
0 (match-beginning 0))
691 (plist-get opt-plist
:html-extension
)))))))
693 ;;; org-xhtml-format-org-link
694 (defun org-xhtml-format-org-link (opt-plist type-1 path fragment desc attr
697 OPT-PLIST is an options list.
698 TYPE is the device-type of the link (THIS://foo.html)
699 PATH is the path of the link (http://THIS#locationx)
700 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
701 DESC is the link description, if any.
702 ATTR is a string of other attributes of the a element.
703 MAY-INLINE-P allows inlining it as an image."
704 (declare (special org-lparse-par-open
))
705 (when (string= type-1
"coderef")
707 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
711 (and (member type-1
'("http" "https" "file"))
712 (org-lparse-should-inline-p path descp
)
714 (type (if (equal type-1
"id") "file" type-1
))
716 ;;First pass. Just sanity stuff.
719 ((string= type
"file")
722 ;;Substitute just if original path was absolute.
723 ;;(Otherwise path must remain relative)
724 (if (file-name-absolute-p path
)
725 (concat "file://" (expand-file-name path
))
729 (t (list type path
))))
731 ;;Second pass. Components converted so they can refer
735 (and org-html-cvt-link-fn
736 (apply org-html-cvt-link-fn
737 opt-plist components-1
))
738 (apply #'org-html-cvt-org-as-html
739 opt-plist components-1
)
741 (type (first components-2
))
742 (thefile (second components-2
)))
745 ;;Third pass. Build final link except for leading type
750 (string= type
"http")
751 (string= type
"https")
752 (string= type
"file")
753 (string= type
"coderef"))
755 (setq thefile
(concat thefile
"#" fragment
))))
759 ;;Final URL-build, for all types.
762 ((str (org-xml-format-href thefile
)))
763 (if (and type
(not (or (string= "file" type
)
764 (string= "coderef" type
))))
765 (concat type
":" str
)
769 (org-xhtml-format-image thefile
)
771 'LINK
(org-xml-format-desc desc
) thefile attr
)))))
773 (defun org-xhtml-format-inline-image (desc)
774 ;; FIXME: alt text missing here?
775 (org-xhtml-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc
))
778 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
779 (defvar org-lparse-link-description-is-image
)
781 (defun org-xhtml-format-image (src)
782 "Create image tag with source and attributes."
784 (if (string-match "^ltxpng/" src
)
785 (format "<img src=\"%s\" alt=\"%s\"/>"
786 src
(org-find-text-property-in-string 'org-latex-src src
))
787 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
788 (attr (org-find-text-property-in-string 'org-attributes src
))
789 (label (org-find-text-property-in-string 'org-label src
))
790 (caption (and caption
(org-xml-encode-org-text caption
)))
791 (img (format "<img src=\"%s\"%s />"
793 (if (string-match "\\<alt=" (or attr
""))
795 (concat " " attr
" alt=\"" src
"\""))))
798 (format "id=\"%s\" " (org-solidify-link-text label
)))
799 "class=\"figure\"")))
802 (with-org-lparse-preserve-paragraph-state
805 '("<div %s>" .
"\n</div>")
807 (org-lparse-format '("\n<p>" .
"</p>") img
)
808 (org-lparse-format '("\n<p>" .
"</p>") caption
))
813 (defun org-export-xhtml-get-bibliography ()
814 "Find bibliography, cut it out and return it."
816 (let (beg end
(cnt 1) bib
)
818 (goto-char (point-min))
819 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
820 (setq beg
(match-beginning 0))
821 (while (re-search-forward "</?div\\>" nil t
)
822 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
824 (and (looking-at ">") (forward-char 1))
825 (setq bib
(buffer-substring beg
(point)))
826 (delete-region beg
(point))
830 (defun org-xhtml-format-table (lines olines
)
831 (let ((org-xhtml-format-table-no-css nil
))
832 (org-lparse-format-table lines olines
)))
834 ;; Following variable is defined for native tables i.e., when
835 ;; `org-lparse-table-is-styled' evals to t.
836 (defvar org-xhtml-format-table-no-css
)
837 (defvar org-table-number-regexp
) ; defined in org-table.el
839 ;; FIXME: This function is called from other modules. Use xhtml suffix
841 (defun org-format-table-xhtml (lines olines
&optional no-css
)
842 "Find out which HTML converter to use and return the HTML code.
843 NO-CSS is passed to the exporter."
844 (let* ((org-lparse-backend 'xhtml
)
845 (org-lparse-entity-control-callbacks-alist
846 (org-lparse-get 'ENTITY-CONTROL
))
847 (org-lparse-entity-format-callbacks-alist
848 (org-lparse-get 'ENTITY-FORMAT
))
849 (org-xhtml-format-table-no-css no-css
))
850 (org-lparse-format-table lines olines
)))
852 ;; FIXME: This function is called from other modules. Use xhtml suffix
854 (defun org-format-org-table-xhtml (lines &optional splice no-css
)
855 ;; This routine might get called outside of org-export-as-html. For
856 ;; example, this could happen as part of org-table-export or as part
857 ;; of org-export-as-docbook. Explicitly bind the parser callback to
858 ;; the html ones for the duration of the call.
859 (let* ((org-lparse-backend 'xhtml
)
860 (org-lparse-entity-control-callbacks-alist
861 (org-lparse-get 'ENTITY-CONTROL
))
862 (org-lparse-entity-format-callbacks-alist
863 (org-lparse-get 'ENTITY-FORMAT
))
864 (org-xhtml-format-table-no-css no-css
))
865 (org-lparse-format-org-table lines splice
)))
868 ;; FIXME: it already exists in org-html.el
869 (defun org-export-splice-attributes (tag attributes
)
870 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
874 (setq oldatt
(org-extract-attributes-from-string tag
)
876 newatt
(cdr (org-extract-attributes-from-string attributes
)))
878 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
879 (if (string-match ">" tag
)
881 (replace-match (concat (org-attributes-to-string oldatt
) ">")
885 ;; FIXME: This function is called from other modules. Use xhtml suffix
887 (defun org-format-table-table-xhtml (lines)
888 (let* ((org-lparse-get 'html
)
889 (org-lparse-entity-control-callbacks-alist
890 (org-lparse-get 'ENTITY-CONTROL
))
891 (org-lparse-entity-format-callbacks-alist
892 (org-lparse-get 'ENTITY-FORMAT
)))
893 (org-lparse-format-table-table lines
)))
896 ;; FIXME: it already exists in org-html.el
897 (defun org-export-splice-style (style extra
)
898 "Splice EXTRA into STYLE, just before \"</style>\"."
899 (if (and (stringp extra
)
900 (string-match "\\S-" extra
)
901 (string-match "</style>" style
))
902 (concat (substring style
0 (match-beginning 0))
904 (substring style
(match-beginning 0)))
907 (defvar htmlize-buffer-places
) ; from htmlize.el
908 (defun org-export-xhtmlize-region-for-paste (beg end
)
909 "Convert the region to HTML, using htmlize.el.
910 This is much like `htmlize-region-for-paste', only that it uses
911 the settings define in the org-... variables."
912 (let* ((htmlize-output-type org-export-xhtmlize-output-type
)
913 (htmlize-css-name-prefix org-export-xhtmlize-css-font-prefix
)
914 (htmlbuf (htmlize-region beg end
)))
916 (with-current-buffer htmlbuf
917 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
918 (plist-get htmlize-buffer-places
'content-end
)))
919 (kill-buffer htmlbuf
))))
922 (defun org-export-xhtmlize-generate-css ()
923 "Create the CSS for all font definitions in the current Emacs session.
924 Use this to create face definitions in your CSS style file that can then
925 be used by code snippets transformed by htmlize.
926 This command just produces a buffer that contains class definitions for all
927 faces used in the current Emacs session. You can copy and paste the ones you
928 need into your CSS file.
930 If you then set `org-export-xhtmlize-output-type' to `css', calls to
931 the function `org-export-xhtmlize-region-for-paste' will produce code
932 that uses these same face definitions."
935 (and (get-buffer "*html*") (kill-buffer "*html*"))
937 (let ((fl (face-list))
938 (htmlize-css-name-prefix "org-")
939 (htmlize-output-type 'css
)
941 (while (setq f
(pop fl
)
942 i
(and f
(face-attribute f
:inherit
)))
943 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
944 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
945 (htmlize-region (point-min) (point-max))))
946 (org-pop-to-buffer-same-window "*html*")
947 (goto-char (point-min))
948 (if (re-search-forward "<style" nil t
)
949 (delete-region (point-min) (match-beginning 0)))
950 (if (re-search-forward "</style>" nil t
)
951 (delete-region (1+ (match-end 0)) (point-max)))
952 (beginning-of-line 1)
953 (if (looking-at " +") (replace-match ""))
954 (goto-char (point-min)))
956 (defvar body-only
) ; dynamically scoped into this.
958 ;; Following variable is let bound when `org-do-lparse' is in
959 ;; progress. See org-lparse.el.
961 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
962 (defvar org-lparse-toc
)
963 (defvar org-lparse-footnote-buffer
)
964 (defvar org-lparse-footnote-definitions
)
965 (defvar org-lparse-dyn-first-heading-pos
)
967 (defun org-xhtml-end-export ()
968 ;; insert the table of contents
969 (when (and org-export-with-toc
(not body-only
) org-lparse-toc
)
970 (org-xhtml-insert-toc org-lparse-toc
))
972 ;; remove empty paragraphs
973 (goto-char (point-min))
974 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
977 ;; Convert whitespace place holders
978 (goto-char (point-min))
980 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
981 (setq n
(get-text-property beg
'org-whitespace
)
982 end
(next-single-property-change beg
'org-whitespace
))
984 (delete-region beg end
)
985 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
986 (make-string n ?x
)))))
988 ;; Remove empty lines at the beginning of the file.
989 (goto-char (point-min))
990 (when (looking-at "\\s-+\n") (replace-match ""))
992 ;; Remove display properties
993 (remove-text-properties (point-min) (point-max) '(display t
))
995 ;; kill temporary buffers
996 (when org-lparse-footnote-buffer
997 (kill-buffer org-lparse-footnote-buffer
))
1000 (run-hooks 'org-export-xhtml-final-hook
))
1002 (defun org-xhtml-format-toc-entry (snumber todo headline tags href
)
1003 (setq headline
(concat
1004 (and org-export-with-section-numbers
1005 (concat snumber
" "))
1009 (org-lparse-format 'SPACES
3)
1010 (org-lparse-format 'FONTIFY tags
"tag")))))
1012 (setq headline
(org-lparse-format 'FONTIFY headline
"todo")))
1013 (org-lparse-format 'LINK headline
(concat "#" href
)))
1015 (defun org-xhtml-format-toc-item (toc-entry level org-last-level
)
1016 (when (> level org-last-level
)
1017 (let ((cnt (- level org-last-level
)))
1018 (while (>= (setq cnt
(1- cnt
)) 0)
1019 (org-lparse-begin-list 'unordered
)
1020 (org-lparse-begin 'LIST-ITEM
'unordered
))))
1021 (when (< level org-last-level
)
1022 (let ((cnt (- org-last-level level
)))
1023 (while (>= (setq cnt
(1- cnt
)) 0)
1024 (org-lparse-end-list-item)
1025 (org-lparse-end-list 'unordered
))))
1027 (org-lparse-end-list-item)
1028 (org-lparse-begin 'LIST-ITEM
'unordered
)
1031 (defun org-xhtml-begin-toc (lang-specific-heading)
1032 (org-lparse-insert-tag "<div id=\"table-of-contents\">")
1034 (org-lparse-format 'HEADING lang-specific-heading
1035 (or (org-lparse-get 'TOPLEVEL-HLEVEL
) 1)))
1036 (org-lparse-insert-tag "<div id=\"text-table-of-contents\">")
1037 (org-lparse-begin-list 'unordered
)
1038 (org-lparse-begin 'LIST-ITEM
'unordered
))
1040 (defun org-xhtml-end-toc ()
1041 (while (> org-last-level
(1- org-min-level
))
1042 (setq org-last-level
(1- org-last-level
))
1043 (org-lparse-end-list-item)
1044 (org-lparse-end-list 'unordered
))
1045 (org-lparse-insert-tag "</div>")
1046 (org-lparse-insert-tag "</div>")
1048 ;; cleanup empty list items in toc
1049 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t
)
1050 (replace-match "")))
1053 (defun org-export-as-xhtml-and-open (arg)
1054 "Export the outline as HTML and immediately open it with a browser.
1055 If there is an active region, export only the region.
1056 The prefix ARG specifies how many levels of the outline should become
1057 headlines. The default is 3. Lower levels will become bulleted lists."
1059 (org-lparse-and-open "xhtml" "xhtml" arg
))
1062 (defun org-export-as-xhtml-batch ()
1063 "Call the function `org-lparse-batch'.
1064 This function can be used in batch processing as:
1066 --load=$HOME/lib/emacs/org.el
1067 --eval \"(setq org-export-headline-levels 2)\"
1068 --visit=MyFile --funcall org-export-as-html-batch"
1069 (org-lparse-batch "xhtml"))
1072 (defun org-export-as-xhtml-to-buffer (arg)
1073 "Call `org-lparse-to-buffer` with output to a temporary buffer.
1074 No file is created. The prefix ARG is passed through to `org-lparse-to-buffer'."
1076 (org-lparse-to-buffer "xhtml" arg
))
1079 (defun org-replace-region-by-xhtml (beg end
)
1080 "Assume the current region has org-mode syntax, and convert it to HTML.
1081 This can be used in any buffer. For example, you could write an
1082 itemized list in org-mode syntax in an HTML buffer and then use this
1083 command to convert it."
1085 (org-replace-region-by "xhtml" beg end
))
1088 (defun org-export-region-as-xhtml (beg end
&optional body-only buffer
)
1089 "Convert region from BEG to END in `org-mode' buffer to HTML.
1090 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
1091 contents, and only produce the region of converted text, useful for
1092 cut-and-paste operations.
1093 If BUFFER is a buffer or a string, use/create that buffer as a target
1094 of the converted HTML. If BUFFER is the symbol `string', return the
1095 produced HTML as a string and leave not buffer behind. For example,
1096 a Lisp program could call this function in the following way:
1098 (setq html (org-export-region-as-html beg end t 'string))
1100 When called interactively, the output buffer is selected, and shown
1101 in a window. A non-interactive call will only return the buffer."
1102 (interactive "r\nP")
1103 (org-lparse-region "xhtml" beg end body-only buffer
))
1105 ;;; org-export-as-xhtml
1107 (defun org-export-as-xhtml (arg &optional hidden ext-plist
1108 to-buffer body-only pub-dir
)
1109 "Export the outline as a pretty HTML file.
1110 Use `org-lparse' internally to perform the actual export. This
1111 routine merely binds the TARGET-BACKEND and NATIVE-BACKEND args
1112 of `org-lparse' to \"html\"."
1114 (org-lparse "xhtml" "xhtml" arg hidden ext-plist to-buffer body-only pub-dir
))
1116 (defvar org-xhtml-entity-control-callbacks-alist
1118 .
(org-xhtml-begin-export org-xhtml-end-export
))
1120 .
(org-xhtml-begin-document-content org-xhtml-end-document-content
))
1122 .
(org-xhtml-begin-document-body org-xhtml-end-document-body
))
1124 .
(org-xhtml-begin-toc org-xhtml-end-toc
))
1126 .
(org-xhtml-begin-environment org-xhtml-end-environment
))
1127 (FOOTNOTE-DEFINITION
1128 .
(org-xhtml-begin-footnote-definition org-xhtml-end-footnote-definition
))
1130 .
(org-xhtml-begin-table org-xhtml-end-table
))
1132 .
(org-xhtml-begin-table-rowgroup org-xhtml-end-table-rowgroup
))
1134 .
(org-xhtml-begin-list org-xhtml-end-list
))
1136 .
(org-xhtml-begin-list-item org-xhtml-end-list-item
))
1138 .
(org-xhtml-begin-outline org-xhtml-end-outline
))
1140 .
(org-xhtml-begin-outline-text org-xhtml-end-outline-text
))
1142 .
(org-xhtml-begin-paragraph org-xhtml-end-paragraph
)))
1143 "Alist of control callbacks registered with the exporter.
1144 Each element is of the form (ENTITY . (BEGIN-ENTITY-FUNCTION
1145 END-ENTITY-FUNCTION)). ENTITY is one of PARAGRAPH, LIST etc as
1146 seen above. BEGIN-ENTITY-FUNCTION and END-ENTITY-FUNCTION are
1147 functions that get called when the exporter needs to begin or end
1148 an entity in the currently exported file. The signatures of
1149 these callbacks are specific to the ENTITY being emitted. These
1150 callbacks always get called with exported file as the current
1151 buffer and need to insert the appropriate tags into the current
1152 buffer. For example, `org-xhtml-begin-paragraph' inserts <p> and
1153 `org-xhtml-end-paragraph' inserts </p> in to the current buffer.
1154 These callbacks are invoked via `org-lparse-begin' and
1157 (defvar org-xhtml-entity-format-callbacks-alist
1158 `((EXTRA-TARGETS . org-lparse-format-extra-targets
)
1159 (ORG-TAGS . org-lparse-format-org-tags
)
1160 (SECTION-NUMBER . org-lparse-format-section-number
)
1161 (HEADLINE . org-xhtml-format-headline
)
1162 (TOC-ENTRY . org-xhtml-format-toc-entry
)
1163 (TOC-ITEM . org-xhtml-format-toc-item
)
1164 (TAGS . org-xhtml-format-tags
)
1165 (SPACES . org-xhtml-format-spaces
)
1166 (TABS . org-xhtml-format-tabs
)
1167 (LINE-BREAK . org-xhtml-format-line-break
)
1168 (FONTIFY . org-xhtml-format-fontify
)
1169 (TODO . org-lparse-format-todo
)
1170 (ORG-LINK . org-xhtml-format-org-link
)
1171 (LINK . org-xhtml-format-link
)
1172 (INLINE-IMAGE . org-xhtml-format-inline-image
)
1173 (HEADING . org-xhtml-format-heading
)
1174 (ANCHOR . org-xhtml-format-anchor
)
1175 (TABLE . org-xhtml-format-table
)
1176 (TABLE-ROW . org-xhtml-format-table-row
)
1177 (TABLE-CELL . org-xhtml-format-table-cell
)
1178 (FOOTNOTES-SECTION . org-xhtml-format-footnotes-section
)
1179 (FOOTNOTE-REFERENCE . org-xhtml-format-footnote-reference
)
1180 (HORIZONTAL-LINE . org-xhtml-format-horizontal-line
)
1181 (LINE . org-xhtml-format-line
)
1182 (COMMENT . org-xhtml-format-comment
)
1183 (ORG-ENTITY . org-xhtml-format-org-entity
))
1184 "Alist of format callbacks registered with the exporter.
1185 Each element is of the form (ENTITY . ENTITY-FORMAT-FUNCTION).
1186 ENTITY is one of LINE, HEADING, COMMENT, LINK, TABLE-ROW etc as
1187 seen above. ENTITY-FORMAT-FUNCTION is a functions that gets
1188 called when the exporter needs to format a string in `org-mode'
1189 buffer in a backend specific way. The signatures of the
1190 formatting callback is specific to the ENTITY being passed in.
1191 These callbacks always need to encode the incoming entity in
1192 backend specific way and return the same. These callbacks do not
1193 make any modifications to the exporter file. For example,
1194 `org-xhtml-format-table-row' encloses incoming entity in <tr>
1195 </tr> tags and returns it. See also `org-lparse-format'.")
1197 ;; register the xhtml exporter with org-lparse library
1198 (org-lparse-register-backend 'xhtml
)
1200 (defun org-xhtml-unload-function ()
1201 ;; notify org-lparse library on unload
1202 (org-lparse-unregister-backend 'xhtml
)
1205 (defun org-xhtml-begin-document-body (opt-plist)
1206 (let ((link-up (and (plist-get opt-plist
:link-up
)
1207 (string-match "\\S-" (plist-get opt-plist
:link-up
))
1208 (plist-get opt-plist
:link-up
)))
1209 (link-home (and (plist-get opt-plist
:link-home
)
1210 (string-match "\\S-" (plist-get opt-plist
:link-home
))
1211 (plist-get opt-plist
:link-home
))))
1213 (org-lparse-insert-tag "<div id=\"content\">")
1215 (or (and (or link-up link-home
)
1216 (format org-export-xhtml-home
/up-format
1217 (or link-up link-home
)
1218 (or link-home link-up
))) "")
1220 (org-xhtml-insert-preamble opt-plist
))
1222 (defun org-xhtml-end-document-body (opt-plist)
1223 (org-xhtml-insert-postamble opt-plist
)
1225 (org-lparse-insert-tag "</div>")
1226 (insert "\n</body>")))
1228 (defun org-xhtml-begin-document-content (opt-plist)
1229 (let* ((language (plist-get opt-plist
:language
))
1230 (charset (or (and coding-system-for-write
1231 (fboundp 'coding-system-get
)
1232 (coding-system-get coding-system-for-write
1235 (style (concat (if (plist-get opt-plist
:style-include-default
)
1236 org-export-xhtml-style-default
)
1237 (plist-get opt-plist
:style
)
1238 (plist-get opt-plist
:style-extra
)
1240 (if (plist-get opt-plist
:style-include-scripts
)
1241 org-export-xhtml-scripts
)))
1243 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
1244 (and org-export-have-math
1245 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
1247 (org-export-xhtml-mathjax-config
1248 org-export-xhtml-mathjax-template
1249 org-export-xhtml-mathjax-options
1250 (or (plist-get opt-plist
:mathjax
) "")) "")))
1253 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1254 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1255 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1256 lang=\"%s\" xml:lang=\"%s\">
1259 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1260 <meta name=\"generator\" content=\"Org-mode\"/>
1261 <meta name=\"generated\" content=\"%s\"/>
1262 <meta name=\"author\" content=\"%s\"/>
1263 <meta name=\"description\" content=\"%s\"/>
1264 <meta name=\"keywords\" content=\"%s\"/>
1270 (or (and (stringp org-export-xhtml-xml-declaration
)
1271 org-export-xhtml-xml-declaration
)
1272 (cdr (assoc (plist-get opt-plist
:html-extension
)
1273 org-export-xhtml-xml-declaration
))
1274 (cdr (assoc "html" org-export-xhtml-xml-declaration
))
1279 (plist-get opt-plist
:title
)
1281 (plist-get opt-plist
:effective-date
)
1282 (plist-get opt-plist
:author
)
1283 (plist-get opt-plist
:description
)
1284 (plist-get opt-plist
:keywords
)
1288 (defun org-xhtml-end-document-content ()
1289 (insert "\n</html>\n"))
1291 (defun org-xhtml-begin-outline (level1 snumber title tags
1292 target extra-targets extra-class
)
1293 (let* ((class (format "outline-%d" level1
))
1294 (class (if extra-class
(concat class
" " extra-class
) class
))
1295 (id (format "outline-container-%s"
1296 (org-lparse-suffix-from-snumber snumber
)))
1297 (extra (concat (when id
(format " id=\"%s\"" id
))
1298 (when class
(format " class=\"%s\"" class
)))))
1299 (org-lparse-insert-tag "<div%s>" extra
)
1301 (org-lparse-format 'HEADING
1303 'HEADLINE title extra-targets tags snumber level1
)
1306 (defun org-xhtml-end-outline ()
1307 (org-lparse-insert-tag "</div>"))
1309 (defun org-xhtml-begin-outline-text (level1 snumber extra-class
)
1310 (let* ((class (format "outline-text-%d" level1
))
1311 (class (if extra-class
(concat class
" " extra-class
) class
))
1312 (id (format "text-%s" (org-lparse-suffix-from-snumber snumber
)))
1313 (extra (concat (when id
(format " id=\"%s\"" id
))
1314 (when class
(format " class=\"%s\"" class
)))))
1315 (org-lparse-insert-tag "<div%s>" extra
)))
1317 (defun org-xhtml-end-outline-text ()
1318 (org-lparse-insert-tag "</div>"))
1320 (defun org-xhtml-begin-paragraph (&optional style
)
1321 (let* ((class (cdr (assoc style
'((footnote .
"footnote")
1323 (extra (if class
(format " class=\"%s\"" class
) "")))
1324 (org-lparse-insert-tag "<p%s>" extra
)))
1326 (defun org-xhtml-end-paragraph ()
1329 (defun org-xhtml-format-environment (style beg-end
)
1330 (assert (memq style
'(blockquote center verse fixedwidth quote native
)) t
)
1335 (org-lparse-end-paragraph)
1336 (insert "<blockquote>\n")
1337 (org-lparse-begin-paragraph))
1339 (org-lparse-end-paragraph)
1340 (insert "\n</blockquote>\n")
1341 (org-lparse-begin-paragraph))))
1345 (org-lparse-end-paragraph)
1346 (insert "\n<p class=\"verse\">\n")
1347 (setq org-lparse-par-open t
))
1350 (setq org-lparse-par-open nil
)
1351 (org-lparse-begin-paragraph))))
1355 (org-lparse-end-paragraph)
1356 (insert "\n<div style=\"text-align: center\">")
1357 (org-lparse-begin-paragraph))
1359 (org-lparse-end-paragraph)
1361 (org-lparse-begin-paragraph))))
1365 (org-lparse-end-paragraph)
1366 (insert "<pre class=\"example\">\n"))
1369 (org-lparse-begin-paragraph))))
1373 (org-lparse-end-paragraph)
1377 (org-lparse-begin-paragraph))))
1380 (BEGIN (org-lparse-end-paragraph))
1381 (END (org-lparse-begin-paragraph))))
1382 (t (error "Unknown environment %s" style
))))
1384 (defun org-xhtml-begin-environment (style)
1385 (org-xhtml-format-environment style
'BEGIN
))
1387 (defun org-xhtml-end-environment (style)
1388 (org-xhtml-format-environment style
'END
))
1390 (defun org-xhtml-begin-list (ltype)
1391 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1394 (ordered (let* ((arg1 nil
)
1395 (extra (if arg1
(format " start=\"%d\"" arg1
) "")))
1396 (org-lparse-insert-tag "<ol%s>" extra
)))
1397 (unordered (org-lparse-insert-tag "<ul>"))
1398 (description (org-lparse-insert-tag "<dl>"))
1399 (t (error "Unknown list type: %s" ltype
))))
1401 (defun org-xhtml-end-list (ltype)
1402 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1405 (org-lparse-insert-tag
1409 (description "</dl>")
1410 (t (error "Unknown list type: %s" ltype
)))))
1412 (defun org-xhtml-begin-list-item (ltype &optional arg headline
)
1413 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1417 (assert (not headline
) t
)
1418 (let* ((counter arg
)
1419 (extra (if counter
(format " value=\"%s\"" counter
) "")))
1420 (org-lparse-insert-tag "<li%s>" extra
)))
1423 (extra (if id
(format " id=\"%s\"" id
) "")))
1424 (org-lparse-insert-tag "<li%s>" extra
)
1426 (insert headline
(org-lparse-format 'LINE-BREAK
) "\n"))))
1428 (assert (not headline
) t
)
1429 (let* ((desc-tag (or arg
"(no term)")))
1431 (org-xhtml-format-tags '("<dt>" .
"</dt>") desc-tag
))
1432 (org-lparse-insert-tag "<dd>")))
1433 (t (error "Unknown list type"))))
1435 (defun org-xhtml-end-list-item (ltype)
1436 (setq ltype
(or (org-lparse-html-list-type-to-canonical-list-type ltype
)
1439 (ordered (org-lparse-insert-tag "</li>"))
1440 (unordered (org-lparse-insert-tag "</li>"))
1441 (description (org-lparse-insert-tag "</dd>"))
1442 (t (error "Unknown list type"))))
1444 ;; Following variables are let bound when table emission is in
1445 ;; progress. See org-lparse.el.
1447 ;; FIXME: the org-lparse defvar belongs to org-lparse.el
1448 (defvar org-lparse-table-begin-marker
)
1449 (defvar org-lparse-table-ncols
)
1450 (defvar org-lparse-table-rowgrp-open
)
1451 (defvar org-lparse-table-rownum
)
1452 (defvar org-lparse-table-cur-rowgrp-is-hdr
)
1453 (defvar org-lparse-table-is-styled
)
1454 (defvar org-lparse-table-rowgrp-info
)
1455 (defvar org-lparse-table-colalign-vector
)
1456 (defvar org-lparse-table-num-numeric-items-per-column
)
1458 (defun org-xhtml-begin-table-rowgroup (&optional is-header-row
)
1459 (when org-lparse-table-rowgrp-open
1460 (org-lparse-end 'TABLE-ROWGROUP
))
1461 (org-lparse-insert-tag (if is-header-row
"<thead>" "<tbody>"))
1462 (setq org-lparse-table-rowgrp-open t
)
1463 (setq org-lparse-table-cur-rowgrp-is-hdr is-header-row
))
1465 (defun org-xhtml-end-table-rowgroup ()
1466 (when org-lparse-table-rowgrp-open
1467 (setq org-lparse-table-rowgrp-open nil
)
1468 (org-lparse-insert-tag
1469 (if org-lparse-table-cur-rowgrp-is-hdr
"</thead>" "</tbody>"))))
1471 (defun org-xhtml-begin-table (caption label attributes
)
1472 (let ((html-table-tag
1473 (org-export-splice-attributes html-table-tag attributes
)))
1475 (setq html-table-tag
1476 (org-export-splice-attributes
1478 (format "id=\"%s\"" (org-solidify-link-text label
)))))
1479 (org-lparse-insert-tag html-table-tag
))
1481 ;; Since the output of HTML table formatter can also be used in
1482 ;; DocBook document, we want to always include the caption to make
1483 ;; DocBook XML file valid.
1484 (insert (format "<caption>%s</caption>" (or caption
"")) "\n"))
1486 (defun org-xhtml-end-table ()
1487 (when org-lparse-table-is-styled
1488 (goto-char org-lparse-table-begin-marker
)
1489 (setq org-lparse-table-begin-marker nil
)
1491 (let ((c -
1) gr colgropen
)
1496 (setq gr
(pop org-table-colgroup-info
))
1499 (if (memq gr
'(:start
:startend
))
1502 "</colgroup>\n<colgroup>"
1507 (let* ((align (aref org-lparse-table-colalign-vector c
))
1508 (alignspec (if org-xhtml-format-table-no-css
1509 " align=\"%s\"" " class=\"%s\""))
1510 (extra (format alignspec align
)))
1511 (format "<col%s />" extra
))
1513 (if (memq gr
'(:end
:startend
))
1514 (progn (setq colgropen nil
) "</colgroup>")
1516 org-lparse-table-num-numeric-items-per-column
""))
1518 (if colgropen
(insert "</colgroup>")))
1520 ;; fill style attributes for table cells
1521 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t
)
1522 (let ((c (string-to-number (match-string 1))))
1524 (if org-export-xhtml-table-align-individual-fields
1525 (format (if org-xhtml-format-table-no-css
" align=\"%s\""
1527 (or (aref org-lparse-table-colalign-vector c
) "left")) "")
1529 (goto-char (point-max)))
1530 (org-lparse-insert-tag "</table>\n"))
1532 (defun org-xhtml-format-table-row (row)
1533 (org-xhtml-format-tags
1534 (cons (eval (car org-export-table-row-tags
))
1535 (eval (cdr org-export-table-row-tags
))) row
))
1537 (defun org-xhtml-format-table-cell (text r c
)
1538 (let ((cell-style-cookie (or (and org-lparse-table-is-styled
1539 (format "@@class%03d@@" c
)) "")))
1541 (org-lparse-table-cur-rowgrp-is-hdr
1542 (org-xhtml-format-tags
1543 org-export-table-header-tags text
"col" cell-style-cookie
))
1544 ((and (= c
0) org-export-xhtml-table-use-header-tags-for-first-column
)
1545 (org-xhtml-format-tags
1546 org-export-table-header-tags text
"row" cell-style-cookie
))
1548 (org-xhtml-format-tags
1549 org-export-table-data-tags text cell-style-cookie
)))))
1551 (defun org-xhtml-begin-footnote-definition (n)
1552 (org-lparse-begin-paragraph 'footnote
)
1555 (format org-export-xhtml-footnote-format
1556 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
1559 (defun org-xhtml-end-footnote-definition (n)
1560 (org-lparse-end-paragraph))
1562 (defun org-xhtml-format-spaces (n)
1563 (let ((space (or (and org-lparse-encode-pending
"\\nbsp") " ")) out
)
1565 (setq out
(concat out space
))
1566 (setq n
(1- n
))) out
))
1568 (defun org-xhtml-format-tabs (&optional n
)
1571 (defun org-xhtml-format-line-break ()
1572 (org-xhtml-format-tags "<br/>" ""))
1574 (defun org-xhtml-format-horizontal-line ()
1575 (concat "\n" "<hr/>" "\n"))
1577 (defun org-xhtml-format-line (line)
1578 (case org-lparse-dyn-current-environment
1579 ((quote fixedwidth
) (concat (org-xml-encode-plain-text line
) "\n"))
1580 (t (concat line
"\n"))))
1582 (defun org-xhtml-format-comment (fmt &rest args
)
1583 (let ((comment (apply 'format fmt args
)))
1584 (format "\n<!-- %s -->\n" comment
)))
1586 (defun org-xhtml-format-fontify (text style
&optional id
)
1587 (let (class extra how
)
1589 ((eq style
'underline
)
1590 (setq extra
" style=\"text-decoration:underline;\"" ))
1591 ((setq how
(cdr (assoc style
1592 '((bold .
("<b>" .
"</b>"))
1593 (emphasis .
("<i>" .
"</i>"))
1594 (code .
("<code>" .
"</code>"))
1595 (verbatim .
("<code>" .
"</code>"))
1596 (strike .
("<del>" .
"</del>"))
1597 (subscript .
("<sub>" .
"</sub>"))
1598 (superscript .
("<sup>" .
"</sup>")))))))
1600 (setq class
(mapconcat 'identity style
" ")))
1603 (t (error "Unknown style %S" style
)))
1605 (setq extra
(concat (when class
(format " class=\"%s\"" class
))
1606 (when id
(format " id=\"%s\"" id
))
1608 (org-xhtml-format-tags
1609 (or how
'("<span%s>" .
"</span>")) text extra
)))
1611 (defun org-xhtml-format-link (text href
&optional extra
)
1612 (let ((extra (concat (format " href=\"%s\"" href
)
1613 (and extra
(concat " " extra
)))))
1614 (org-xhtml-format-tags '("<a%s>" .
"</a>") text extra
)))
1616 (defun org-xhtml-format-heading (text level
&optional id
)
1617 (let* ((extra (concat (when id
(format " id=\"%s\"" id
)))))
1618 (concat (format "<h%d%s>" level extra
) text
(format "</h%d>" level
))))
1620 (defun org-xhtml-format-headline (title extra-targets tags
1621 &optional snumber level
)
1623 (org-lparse-format 'EXTRA-TARGETS extra-targets
)
1624 (concat (org-lparse-format 'SECTION-NUMBER snumber level
) " ")
1626 (and tags
(concat (org-lparse-format 'SPACES
3)
1627 (org-lparse-format 'ORG-TAGS tags
)))))
1629 (defun org-xhtml-format-anchor (text name
&optional class
)
1632 (when name
(format " name=\"%s\"" name
))
1633 (when id
(format " id=\"%s\"" id
))
1634 (when class
(format " class=\"%s\"" class
)))))
1635 (org-xhtml-format-tags '("<a%s>" .
"</a>") text extra
)))
1637 (defun org-xhtml-format-footnote-reference (n def refcnt
)
1638 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
1639 (format org-export-xhtml-footnote-format
1641 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
1644 (defun org-xhtml-format-footnotes-section (section-name definitions
)
1645 (if (not definitions
) ""
1646 (format org-export-xhtml-footnotes-section section-name definitions
)))
1648 (defun org-xhtml-format-org-entity (wd)
1649 (org-entity-get-representation wd
'html
))
1651 (defun org-xhtml-format-tags (tag text
&rest args
)
1652 (let ((prefix (when org-lparse-encode-pending
"@"))
1653 (suffix (when org-lparse-encode-pending
"@")))
1654 (apply 'org-lparse-format-tags tag text prefix suffix args
)))
1656 (defun org-xhtml-get (what &optional opt-plist
)
1661 (CLEANUP-METHOD nil
)
1663 ;; ;; There is a provision to register a per-backend converter and
1664 ;; ;; output formats. Refer `org-lparse-get-converter' and
1665 ;; ;; `org-lparse-get-other-backends'.
1667 ;; ;; The default behaviour is to use `org-lparse-convert-process'
1668 ;; ;; and `org-lparse-convert-capabilities'.
1671 ;; ;; See note above
1673 (EXPORT-DIR (org-export-directory :html opt-plist
))
1674 (FILE-NAME-EXTENSION (plist-get opt-plist
:html-extension
))
1675 (EXPORT-BUFFER-NAME "*Org HTML Export*")
1676 (ENTITY-CONTROL org-xhtml-entity-control-callbacks-alist
)
1677 (ENTITY-FORMAT org-xhtml-entity-format-callbacks-alist
)
1678 (TOPLEVEL-HLEVEL org-export-xhtml-toplevel-hlevel
)
1679 (SPECIAL-STRING-REGEXPS org-export-xhtml-special-string-regexps
)
1680 (CODING-SYSTEM-FOR-WRITE org-export-xhtml-coding-system
)
1681 (CODING-SYSTEM-FOR-SAVE org-export-xhtml-coding-system
)
1682 (INLINE-IMAGES org-export-xhtml-inline-images
)
1683 (INLINE-IMAGE-EXTENSIONS org-export-xhtml-inline-image-extensions
)
1684 (PLAIN-TEXT-MAP org-export-xhtml-protect-char-alist
)
1685 (TABLE-FIRST-COLUMN-AS-LABELS
1686 org-export-xhtml-table-use-header-tags-for-first-column
)
1687 (TODO-KWD-CLASS-PREFIX org-export-xhtml-todo-kwd-class-prefix
)
1688 (TAG-CLASS-PREFIX org-export-xhtml-tag-class-prefix
)
1689 (FOOTNOTE-SEPARATOR org-export-xhtml-footnote-separator
)
1690 (t (error "Unknown property: %s" what
))))
1692 (defun org-xhtml-get-coding-system-for-write ()
1693 (or org-export-xhtml-coding-system
1694 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1696 (defun org-xhtml-get-coding-system-for-save ()
1697 (or org-export-xhtml-coding-system
1698 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
1700 (defun org-xhtml-insert-toc (toc)
1701 ;; locate where toc needs to be inserted
1702 (goto-char (point-min))
1704 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1705 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t
))
1706 (goto-char (match-beginning 0))
1709 (org-lparse-dyn-first-heading-pos
1710 (goto-char org-lparse-dyn-first-heading-pos
)
1711 (when (looking-at "\\s-*</p>")
1712 (goto-char (match-end 0))
1717 (defun org-xhtml-insert-preamble (opt-plist)
1718 (when (plist-get opt-plist
:html-preamble
)
1719 (let ((html-pre (plist-get opt-plist
:html-preamble
))
1720 (title (plist-get opt-plist
:title
))
1721 (date (plist-get opt-plist
:effective-date
))
1722 (author (plist-get opt-plist
:author
))
1723 (lang-words (plist-get opt-plist
:lang-words
))
1724 (email (plist-get opt-plist
:email
)))
1725 (cond ((stringp html-pre
)
1727 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
1728 (?d .
,date
) (?e .
,email
)))))
1729 ((functionp html-pre
)
1730 (funcall html-pre opt-plist
))
1734 (or (cadr (assoc (nth 0 lang-words
)
1735 org-export-xhtml-preamble-format
))
1736 (cadr (assoc "en" org-export-xhtml-preamble-format
)))
1737 `((?t .
,title
) (?a .
,author
)
1738 (?d .
,date
) (?e .
,email
)))))))))
1740 (defun org-xhtml-insert-postamble (opt-plist)
1741 (when org-lparse-footnote-definitions
1744 'FOOTNOTES-SECTION
(nth 4 (plist-get opt-plist
:lang-words
))
1745 (mapconcat (lambda (x) (cdr x
))
1746 (nreverse org-lparse-footnote-definitions
) "\n"))))
1747 (let ((bib (org-export-xhtml-get-bibliography)))
1749 (insert "\n" bib
"\n")))
1751 ;; export html postamble
1753 (let* ((html-post (plist-get opt-plist
:html-postamble
))
1754 (date (plist-get opt-plist
:effective-date
))
1755 (author (plist-get opt-plist
:author
))
1756 (email (plist-get opt-plist
:email
))
1757 (lang-words (plist-get opt-plist
:lang-words
))
1758 (html-validation-link (or org-export-xhtml-validation-link
""))
1760 (mapconcat (lambda(e)
1761 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1762 (split-string email
",+ *")
1765 (concat "Org version " org-version
" with Emacs version "
1766 (number-to-string emacs-major-version
))))
1767 (when (plist-get opt-plist
:html-postamble
)
1768 (cond ((stringp html-post
)
1769 (insert "<div id=\"postamble\">\n")
1770 (insert (format-spec html-post
1771 `((?a .
,author
) (?e .
,email
)
1772 (?d .
,date
) (?c .
,creator-info
)
1773 (?v .
,html-validation-link
))))
1775 ((functionp html-post
)
1776 (funcall html-post opt-plist
))
1777 ((eq html-post
'auto
)
1778 ;; fall back on default postamble
1779 (insert "<div id=\"postamble\">\n")
1780 (when (plist-get opt-plist
:time-stamp-file
)
1781 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
1782 (when (and (plist-get opt-plist
:author-info
) author
)
1783 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
1784 (when (and (plist-get opt-plist
:email-info
) email
)
1785 (insert "<p class=\"email\">" email
"</p>\n"))
1786 (when (plist-get opt-plist
:creator-info
)
1787 (insert "<p class=\"creator\">"
1788 (concat "Org version " org-version
" with Emacs version "
1789 (number-to-string emacs-major-version
) "</p>\n")))
1790 (insert html-validation-link
"\n</div>"))
1792 (insert "<div id=\"postamble\">\n")
1793 (insert (format-spec
1794 (or (cadr (assoc (nth 0 lang-words
)
1795 org-export-xhtml-postamble-format
))
1796 (cadr (assoc "en" org-export-xhtml-postamble-format
)))
1797 `((?a .
,author
) (?e .
,email
)
1798 (?d .
,date
) (?c .
,creator-info
)
1799 (?v .
,html-validation-link
))))
1800 (insert "</div>"))))))
1802 (if org-export-xhtml-with-timestamp
1803 (insert org-export-xhtml-html-helper-timestamp
)))
1805 ;; There are references to org-html-expand, org-html-protect and
1806 ;; org-html-do-expand outside of org-html.el. For now provide a
1807 ;; migration path. Ultimately these functions have to be removed.
1809 ;; (defun org-html-expand (string)
1810 ;; "A simple wrapper around `org-xml-encode-org-text-skip-links'."
1811 ;; (org-xml-encode-org-text-skip-links string))
1813 ;; (defun org-html-protect (s)
1814 ;; "A simple wrapper around `org-xml-encode-plain-text'."
1815 ;; (org-xml-encode-plain-text s))
1817 ;; (defun org-html-do-expand (s)
1818 ;; "A simple wrapper around `org-xml-encode-org-text'."
1819 ;; (org-xml-encode-org-text s))
1821 ;; (defun org-export-xhtml-format-href (s)
1822 ;; "A simple wrapper around `org-xml-format-href'."
1823 ;; (org-xml-format-href s))
1825 ;; (defun org-export-xhtml-format-desc (s)
1826 ;; "A simple wrapper around `org-xml-format-desc'."
1827 ;; (org-xml-format-desc s))
1829 (provide 'org-xhtml
)
1831 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
1832 ;;; org-xhtml.el ends here