1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 (require 'format-spec
)
33 (eval-when-compile (require 'cl
))
35 (declare-function org-id-find-id-file
"org-id" (id))
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (declare-function org-pop-to-buffer-same-window
38 "org-compat" (&optional buffer-or-name norecord label
))
40 (defgroup org-export-html nil
41 "Options specific for HTML export of Org-mode files."
42 :tag
"Org Export HTML"
45 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
46 <h2 class=\"footnotes\">%s: </h2>
47 <div id=\"text-footnotes\">
51 "Format for the footnotes section.
52 Should contain a two instances of %s. The first will be replaced with the
53 language-specific word for \"Footnotes\", the second one will be replaced
54 by the footnotes themselves."
55 :group
'org-export-html
58 (defcustom org-export-html-footnote-format
"<sup>%s</sup>"
59 "The format for the footnote reference.
60 %s will be replaced by the footnote reference itself."
61 :group
'org-export-html
65 (defcustom org-export-html-footnote-separator
"<sup>, </sup>"
66 "Text used to separate footnotes."
67 :group
'org-export-html
70 (defcustom org-export-html-coding-system nil
71 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
72 :group
'org-export-html
75 (defcustom org-export-html-extension
"html"
76 "The extension for exported HTML files."
77 :group
'org-export-html
80 (defcustom org-export-html-xml-declaration
81 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
82 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
83 "The extension for exported HTML files.
84 %s will be replaced with the charset of the exported file.
85 This may be a string, or an alist with export extensions
86 and corresponding declarations."
87 :group
'org-export-html
89 (string :tag
"Single declaration")
90 (repeat :tag
"Dependent on extension"
91 (cons (string :tag
"Extension")
92 (string :tag
"Declaration")))))
94 (defcustom org-export-html-style-include-scripts t
95 "Non-nil means include the JavaScript snippets in exported HTML files.
96 The actual script is defined in `org-export-html-scripts' and should
98 :group
'org-export-html
101 (defconst org-export-html-scripts
102 "<script type=\"text/javascript\">
103 <!--/*--><![CDATA[/*><!--*/
104 function CodeHighlightOn(elem, id)
106 var target = document.getElementById(id);
108 elem.cacheClassElem = elem.className;
109 elem.cacheClassTarget = target.className;
110 target.className = \"code-highlighted\";
111 elem.className = \"code-highlighted\";
114 function CodeHighlightOff(elem, id)
116 var target = document.getElementById(id);
117 if(elem.cacheClassElem)
118 elem.className = elem.cacheClassElem;
119 if(elem.cacheClassTarget)
120 target.className = elem.cacheClassTarget;
124 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
126 (defconst org-export-html-style-default
127 "<style type=\"text/css\">
128 <!--/*--><![CDATA[/*><!--*/
129 html { font-family: Times, serif; font-size: 12pt; }
130 .title { text-align: center; }
131 .todo { color: red; }
132 .done { color: green; }
133 .tag { background-color: #add8e6; font-weight:normal }
135 .timestamp { color: #bebebe; }
136 .timestamp-kwd { color: #5f9ea0; }
137 .right {margin-left:auto; margin-right:0px; text-align:right;}
138 .left {margin-left:0px; margin-right:auto; text-align:left;}
139 .center {margin-left:auto; margin-right:auto; text-align:center;}
140 p.verse { margin-left: 3% }
142 border: 1pt solid #AEBDCC;
143 background-color: #F3F5F7;
145 font-family: courier, monospace;
149 table { border-collapse: collapse; }
150 td, th { vertical-align: top; }
151 th.right { text-align:center; }
152 th.left { text-align:center; }
153 th.center { text-align:center; }
154 td.right { text-align:right; }
155 td.left { text-align:left; }
156 td.center { text-align:center; }
157 dt { font-weight: bold; }
158 div.figure { padding: 0.5em; }
159 div.figure p { text-align: center; }
162 border:2px solid gray;
166 textarea { overflow-x: auto; }
167 .linenr { font-size:smaller }
168 .code-highlighted {background-color:#ffff00;}
169 .org-info-js_info-navigation { border-style:none; }
170 #org-info-js_console-label { font-size:10px; font-weight:bold;
171 white-space:nowrap; }
172 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
176 "The default style specification for exported HTML files.
177 Please use the variables `org-export-html-style' and
178 `org-export-html-style-extra' to add to this style. If you wish to not
179 have the default style included, customize the variable
180 `org-export-html-style-include-default'.")
182 (defcustom org-export-html-style-include-default t
183 "Non-nil means include the default style in exported HTML files.
184 The actual style is defined in `org-export-html-style-default' and should
185 not be modified. Use the variables `org-export-html-style' to add
186 your own style information."
187 :group
'org-export-html
190 (put 'org-export-html-style-include-default
'safe-local-variable
'booleanp
)
192 (defcustom org-export-html-style
""
193 "Org-wide style definitions for exported HTML files.
195 This variable needs to contain the full HTML structure to provide a style,
196 including the surrounding HTML tags. If you set the value of this variable,
197 you should consider to include definitions for the following classes:
198 title, todo, done, timestamp, timestamp-kwd, tag, target.
200 For example, a valid value would be:
202 <style type=\"text/css\">
204 p { font-weight: normal; color: gray; }
206 .title { text-align: center; }
207 .todo, .timestamp-kwd { color: red; }
208 .done { color: green; }
212 If you'd like to refer to an external style file, use something like
214 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
216 As the value of this option simply gets inserted into the HTML <head> header,
217 you can \"misuse\" it to add arbitrary text to the header.
218 See also the variable `org-export-html-style-extra'."
219 :group
'org-export-html
222 (put 'org-export-html-style
'safe-local-variable
'stringp
)
224 (defcustom org-export-html-style-extra
""
225 "Additional style information for HTML export.
226 The value of this variable is inserted into the HTML buffer right after
227 the value of `org-export-html-style'. Use this variable for per-file
228 settings of style information, and do not forget to surround the style
229 settings with <style>...</style> tags."
230 :group
'org-export-html
233 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
235 (defcustom org-export-html-mathjax-options
236 '((path "http://orgmode.org/mathjax/MathJax.js")
241 "Options for MathJax setup.
243 path The path where to find MathJax
244 scale Scaling for the HTML-CSS backend, usually between 100 and 133
245 align How to align display math: left, center, or right
246 indent If align is not center, how far from the left/right side?
247 mathml Should a MathML player be used if available?
248 This is faster and reduces bandwidth use, but currently
249 sometimes has lower spacing quality. Therefore, the default is
250 nil. When browsers get better, this switch can be flipped.
252 You can also customize this for each buffer, using something like
254 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
255 :group
'org-export-html
256 :type
'(list :greedy t
257 (list :tag
"path (the path from where to load MathJax.js)"
258 (const :format
" " path
) (string))
259 (list :tag
"scale (scaling for the displayed math)"
260 (const :format
" " scale
) (string))
261 (list :tag
"align (alignment of displayed equations)"
262 (const :format
" " align
) (string))
263 (list :tag
"indent (indentation with left or right alignment)"
264 (const :format
" " indent
) (string))
265 (list :tag
"mathml (should MathML display be used is possible)"
266 (const :format
" " mathml
) (boolean))))
268 (defun org-export-html-mathjax-config (template options in-buffer
)
269 "Insert the user setup into the matchjax template."
270 (let (name val
(yes " ") (no "// ") x
)
273 (setq name
(car e
) val
(nth 1 e
))
274 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
275 (setq val
(car (read-from-string
276 (substring in-buffer
(match-end 0))))))
277 (if (not (stringp val
)) (setq val
(format "%s" val
)))
278 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
279 (setq template
(replace-match val t t template
))))
281 (setq val
(nth 1 (assq 'mathml options
)))
282 (if (string-match (concat "\\<mathml:") in-buffer
)
283 (setq val
(car (read-from-string
284 (substring in-buffer
(match-end 0))))))
285 ;; Exchange prefixes depending on mathml setting
286 (if (not val
) (setq x yes yes no no x
))
287 ;; Replace cookies to turn on or off the config/jax lines
288 (if (string-match ":MMLYES:" template
)
289 (setq template
(replace-match yes t t template
)))
290 (if (string-match ":MMLNO:" template
)
291 (setq template
(replace-match no t t template
)))
292 ;; Return the modified template
295 (defcustom org-export-html-mathjax-template
296 "<script type=\"text/javascript\" src=\"%PATH\">
297 <!--/*--><![CDATA[/*><!--*/
299 // Only one of the two following lines, depending on user settings
300 // First allows browser-native MathML display, second forces HTML/CSS
301 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
302 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
303 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
304 \"TeX/noUndefined.js\"],
306 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
307 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
308 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
309 ignoreClass: \"tex2jax_ignore\",
310 processEscapes: false,
311 processEnvironments: true,
314 showProcessingMessages: true,
315 displayAlign: \"%ALIGN\",
316 displayIndent: \"%INDENT\",
320 availableFonts: [\"STIX\",\"TeX\"],
321 preferredFont: \"TeX\",
337 "The MathJax setup for XHTML files."
338 :group
'org-export-html
341 (defcustom org-export-html-tag-class-prefix
""
342 "Prefix to class names for TODO keywords.
343 Each tag gets a class given by the tag itself, with this prefix.
344 The default prefix is empty because it is nice to just use the keyword
345 as a class name. But if you get into conflicts with other, existing
346 CSS classes, then this prefix can be very useful."
347 :group
'org-export-html
350 (defcustom org-export-html-todo-kwd-class-prefix
""
351 "Prefix to class names for TODO keywords.
352 Each TODO keyword gets a class given by the keyword itself, with this prefix.
353 The default prefix is empty because it is nice to just use the keyword
354 as a class name. But if you get into conflicts with other, existing
355 CSS classes, then this prefix can be very useful."
356 :group
'org-export-html
359 (defcustom org-export-html-preamble t
360 "Non-nil means insert a preamble in HTML export.
362 When `t', insert a string as defined by one of the formatting
363 strings in `org-export-html-preamble-format'. When set to a
364 string, this string overrides `org-export-html-preamble-format'.
365 When set to a function, apply this function and insert the
366 returned string. The function takes the property list of export
367 options as its only argument.
369 Setting :html-preamble in publishing projects will take
370 precedence over this variable."
371 :group
'org-export-html
372 :type
'(choice (const :tag
"No preamble" nil
)
373 (const :tag
"Default preamble" t
)
374 (string :tag
"Custom formatting string")
375 (function :tag
"Function (must return a string)")))
377 (defcustom org-export-html-preamble-format
'(("en" ""))
378 "The format for the HTML preamble.
380 %t stands for the title.
381 %a stands for the author's name.
382 %e stands for the author's email.
383 %d stands for the date.
385 If you need to use a \"%\" character, you need to escape it
387 :group
'org-export-html
390 (defcustom org-export-html-postamble
'auto
391 "Non-nil means insert a postamble in HTML export.
393 When `t', insert a string as defined by the formatting string in
394 `org-export-html-postamble-format'. When set to a string, this
395 string overrides `org-export-html-postamble-format'. When set to
396 'auto, discard `org-export-html-postamble-format' and honor
397 `org-export-author/email/creator-info' variables. When set to a
398 function, apply this function and insert the returned string.
399 The function takes the property list of export options as its
402 Setting :html-postamble in publishing projects will take
403 precedence over this variable."
404 :group
'org-export-html
405 :type
'(choice (const :tag
"No postamble" nil
)
406 (const :tag
"Auto preamble" 'auto
)
407 (const :tag
"Default formatting string" t
)
408 (string :tag
"Custom formatting string")
409 (function :tag
"Function (must return a string)")))
411 (defcustom org-export-html-postamble-format
412 '(("en" "<p class=\"author\">Author: %a (%e)</p>
413 <p class=\"date\">Date: %d</p>
414 <p class=\"creator\">Generated by %c</p>
415 <p class=\"xhtml-validation\">%v</p>
417 "The format for the HTML postamble.
419 %a stands for the author's name.
420 %e stands for the author's email.
421 %d stands for the date.
422 %c will be replaced by information about Org/Emacs versions.
423 %v will be replaced by `org-export-html-validation-link'.
425 If you need to use a \"%\" character, you need to escape it
427 :group
'org-export-html
430 (defcustom org-export-html-home
/up-format
431 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
432 <a accesskey=\"h\" href=\"%s\"> UP </a>
434 <a accesskey=\"H\" href=\"%s\"> HOME </a>
436 "Snippet used to insert the HOME and UP links.
437 This is a format string, the first %s will receive the UP link,
438 the second the HOME link. If both `org-export-html-link-up' and
439 `org-export-html-link-home' are empty, the entire snippet will be
441 :group
'org-export-html
444 (defcustom org-export-html-toplevel-hlevel
2
445 "The <H> level for level 1 headings in HTML export.
446 This is also important for the classes that will be wrapped around headlines
447 and outline structure. If this variable is 1, the top-level headlines will
448 be <h1>, and the corresponding classes will be outline-1, section-number-1,
449 and outline-text-1. If this is 2, all of these will get a 2 instead.
450 The default for this variable is 2, because we use <h1> for formatting the
452 :group
'org-export-html
455 (defcustom org-export-html-link-org-files-as-html t
456 "Non-nil means make file links to `file.org' point to `file.html'.
457 When org-mode is exporting an org-mode file to HTML, links to
458 non-html files are directly put into a href tag in HTML.
459 However, links to other Org-mode files (recognized by the
460 extension `.org.) should become links to the corresponding html
461 file, assuming that the linked org-mode file will also be
463 When nil, the links still point to the plain `.org' file."
464 :group
'org-export-html
467 (defcustom org-export-html-inline-images
'maybe
468 "Non-nil means inline images into exported HTML pages.
469 This is done using an <img> tag. When nil, an anchor with href is used to
470 link to the image. If this option is `maybe', then images in links with
471 an empty description will be inlined, while images with a description will
473 :group
'org-export-html
474 :type
'(choice (const :tag
"Never" nil
)
475 (const :tag
"Always" t
)
476 (const :tag
"When there is no description" maybe
)))
478 (defcustom org-export-html-inline-image-extensions
479 '("png" "jpeg" "jpg" "gif" "svg")
480 "Extensions of image files that can be inlined into HTML."
481 :group
'org-export-html
482 :type
'(repeat (string :tag
"Extension")))
484 (defcustom org-export-html-table-tag
485 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
486 "The HTML tag that is used to start a table.
487 This must be a <table> tag, but you may change the options like
488 borders and spacing."
489 :group
'org-export-html
492 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
493 "The opening tag for table header fields.
494 This is customizable so that alignment options can be specified.
495 The first %s will be filled with the scope of the field, either row or col.
496 The second %s will be replaced by a style entry to align the field.
497 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
498 See also the variable `org-export-html-table-align-individual-fields'."
499 :group
'org-export-tables
500 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
502 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
503 "The opening tag for table data fields.
504 This is customizable so that alignment options can be specified.
505 The first %s will be filled with the scope of the field, either row or col.
506 The second %s will be replaced by a style entry to align the field.
507 See also the variable `org-export-html-table-align-individual-fields'."
508 :group
'org-export-tables
509 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
511 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
512 "The opening tag for table data fields.
513 This is customizable so that alignment options can be specified.
514 Instead of strings, these can be Lisp forms that will be evaluated
515 for each row in order to construct the table row tags. During evaluation,
516 the variable `head' will be true when this is a header line, nil when this
517 is a body line. And the variable `nline' will contain the line number,
518 starting from 1 in the first header line. For example
520 (setq org-export-table-row-tags
523 (if (= (mod nline 2) 1)
524 \"<tr class=\\\"tr-odd\\\">\"
525 \"<tr class=\\\"tr-even\\\">\"))
528 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
529 :group
'org-export-tables
531 (choice :tag
"Opening tag"
532 (string :tag
"Specify")
534 (choice :tag
"Closing tag"
535 (string :tag
"Specify")
538 (defcustom org-export-html-table-align-individual-fields t
539 "Non-nil means attach style attributes for alignment to each table field.
540 When nil, alignment will only be specified in the column tags, but this
541 is ignored by some browsers (like Firefox, Safari). Opera does it right
543 :group
'org-export-tables
546 (defcustom org-export-html-table-use-header-tags-for-first-column nil
547 "Non-nil means format column one in tables with header tags.
548 When nil, also column one will use data tags."
549 :group
'org-export-tables
552 (defcustom org-export-html-validation-link
553 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
554 "Link to HTML validation service."
555 :group
'org-export-html
558 ;; FIXME Obsolete since Org 7.7
559 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
560 (defvar org-export-html-with-timestamp nil
561 "If non-nil, write container for HTML-helper-mode timestamp.")
563 ;; FIXME Obsolete since Org 7.7
564 (defvar org-export-html-html-helper-timestamp
565 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
566 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
568 (defcustom org-export-html-protect-char-alist
572 "Alist of characters to be converted by `org-html-protect'."
573 :group
'org-export-html
574 :type
'(repeat (cons (string :tag
"Character")
575 (string :tag
"HTML equivalent"))))
577 (defgroup org-export-htmlize nil
578 "Options for processing examples with htmlize.el."
579 :tag
"Org Export Htmlize"
580 :group
'org-export-html
)
582 (defcustom org-export-htmlize-output-type
'inline-css
583 "Output type to be used by htmlize when formatting code snippets.
584 Choices are `css', to export the CSS selectors only, or `inline-css', to
585 export the CSS attribute values inline in the HTML. We use as default
586 `inline-css', in order to make the resulting HTML self-containing.
588 However, this will fail when using Emacs in batch mode for export, because
589 then no rich font definitions are in place. It will also not be good if
590 people with different Emacs setup contribute HTML files to a website,
591 because the fonts will represent the individual setups. In these cases,
592 it is much better to let Org/Htmlize assign classes only, and to use
593 a style file to define the look of these classes.
594 To get a start for your css file, start Emacs session and make sure that
595 all the faces you are interested in are defined, for example by loading files
596 in all modes you want. Then, use the command
597 \\[org-export-htmlize-generate-css] to extract class definitions."
598 :group
'org-export-htmlize
599 :type
'(choice (const css
) (const inline-css
)))
601 (defcustom org-export-htmlize-css-font-prefix
"org-"
602 "The prefix for CSS class names for htmlize font specifications."
603 :group
'org-export-htmlize
606 (defcustom org-export-htmlized-org-css-url nil
607 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
608 Normally when creating an htmlized version of an Org buffer, htmlize will
609 create CSS to define the font colors. However, this does not work when
610 converting in batch mode, and it also can look bad if different people
611 with different fontification setup work on the same website.
612 When this variable is non-nil, creating an htmlized version of an Org buffer
613 using `org-export-as-org' will remove the internal CSS section and replace it
614 with a link to this URL."
615 :group
'org-export-htmlize
617 (const :tag
"Keep internal css" nil
)
618 (string :tag
"URL or local href")))
620 ;; FIXME: The following variable is obsolete since Org 7.7 but is
621 ;; still declared and checked within code for compatibility reasons.
622 ;; Use the custom variables `org-export-html-divs' instead.
623 (defvar org-export-html-content-div
"content"
624 "The name of the container DIV that holds all the page contents.
626 This variable is obsolete since Org version 7.7.
627 Please set `org-export-html-divs' instead.")
629 (defcustom org-export-html-divs
'("preamble" "content" "postamble")
630 "The name of the main divs for HTML export."
631 :group
'org-export-html
633 (string :tag
" Div for the preamble:")
634 (string :tag
" Div for the content:")
635 (string :tag
"Div for the postamble:")))
639 (defvar org-export-html-after-blockquotes-hook nil
640 "Hook run during HTML export, after blockquote, verse, center are done.")
642 (defvar org-export-html-final-hook nil
643 "Hook run at the end of HTML export, in the new buffer.")
647 (defun org-export-html-preprocess (parameters)
648 "Convert LaTeX fragments to images."
649 (when (and org-current-export-file
650 (plist-get parameters
:LaTeX-fragments
))
652 (concat "ltxpng/" (file-name-sans-extension
653 (file-name-nondirectory
654 org-current-export-file
)))
655 org-current-export-dir nil
"Creating LaTeX image %s"
658 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
659 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
660 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
661 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
663 (goto-char (point-min))
665 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
666 (org-if-unprotected-at (match-beginning 1)
667 (setq label
(match-string 1))
669 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
670 (setq l1
(substring label
(match-beginning 1)))
672 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
675 (defun org-export-as-html-and-open (arg)
676 "Export the outline as HTML and immediately open it with a browser.
677 If there is an active region, export only the region.
678 The prefix ARG specifies how many levels of the outline should become
679 headlines. The default is 3. Lower levels will become bulleted lists."
681 (org-export-as-html arg
'hidden
)
682 (org-open-file buffer-file-name
)
683 (when org-export-kill-product-buffer-when-displayed
684 (kill-buffer (current-buffer))))
687 (defun org-export-as-html-batch ()
688 "Call the function `org-export-as-html'.
689 This function can be used in batch processing as:
691 --load=$HOME/lib/emacs/org.el
692 --eval \"(setq org-export-headline-levels 2)\"
693 --visit=MyFile --funcall org-export-as-html-batch"
694 (org-export-as-html org-export-headline-levels
'hidden
))
697 (defun org-export-as-html-to-buffer (arg)
698 "Call `org-export-as-html` with output to a temporary buffer.
699 No file is created. The prefix ARG is passed through to `org-export-as-html'."
701 (org-export-as-html arg nil nil
"*Org HTML Export*")
702 (when org-export-show-temporary-export-buffer
703 (switch-to-buffer-other-window "*Org HTML Export*")))
706 (defun org-replace-region-by-html (beg end
)
707 "Assume the current region has org-mode syntax, and convert it to HTML.
708 This can be used in any buffer. For example, you could write an
709 itemized list in org-mode syntax in an HTML buffer and then use this
710 command to convert it."
712 (let (reg html buf pop-up-frames
)
713 (save-window-excursion
715 (setq html
(org-export-region-as-html
717 (setq reg
(buffer-substring beg end
)
718 buf
(get-buffer-create "*Org tmp*"))
719 (with-current-buffer buf
723 (setq html
(org-export-region-as-html
724 (point-min) (point-max) t
'string
)))
726 (delete-region beg end
)
730 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
731 "Convert region from BEG to END in org-mode buffer to HTML.
732 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
733 contents, and only produce the region of converted text, useful for
734 cut-and-paste operations.
735 If BUFFER is a buffer or a string, use/create that buffer as a target
736 of the converted HTML. If BUFFER is the symbol `string', return the
737 produced HTML as a string and leave not buffer behind. For example,
738 a Lisp program could call this function in the following way:
740 (setq html (org-export-region-as-html beg end t 'string))
742 When called interactively, the output buffer is selected, and shown
743 in a window. A non-interactive call will only return the buffer."
745 (when (org-called-interactively-p 'any
)
746 (setq buffer
"*Org HTML Export*"))
747 (let ((transient-mark-mode t
) (zmacs-regions t
)
749 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
751 (set-mark (point)) ;; to activate the region
753 (setq rtn
(org-export-as-html
756 (if (fboundp 'deactivate-mark
) (deactivate-mark))
757 (if (and (org-called-interactively-p 'any
) (bufferp rtn
))
758 (switch-to-buffer-other-window rtn
)
761 (defvar html-table-tag nil
) ; dynamically scoped into this.
762 (defvar org-par-open nil
)
764 ;;; org-html-cvt-link-fn
765 (defconst org-html-cvt-link-fn
767 "Function to convert link URLs to exportable URLs.
768 Takes two arguments, TYPE and PATH.
769 Returns exportable url as (TYPE PATH), or nil to signal that it
770 didn't handle this case.
771 Intended to be locally bound around a call to `org-export-as-html'." )
773 (defun org-html-cvt-org-as-html (opt-plist type path
)
774 "Convert an org filename to an equivalent html filename.
775 If TYPE is not file, just return `nil'.
776 See variable `org-export-html-link-org-files-as-html'"
780 org-export-html-link-org-files-as-html
781 (string= type
"file")
782 (string-match "\\.org$" path
)
787 (substring path
0 (match-beginning 0))
789 (plist-get opt-plist
:html-extension
)))))))
792 ;;; org-html-should-inline-p
793 (defun org-html-should-inline-p (filename descp
)
794 "Return non-nil if link FILENAME should be inlined.
795 The decision to inline the FILENAME link is based on the current
796 settings. DESCP is the boolean of whether there was a link
797 description. See variables `org-export-html-inline-images' and
798 `org-export-html-inline-image-extensions'."
800 org-export-html-inline-images
801 org-export-html-inline-image-extensions
))
802 (and (or (eq t org-export-html-inline-images
)
803 (and org-export-html-inline-images
(not descp
)))
805 filename org-export-html-inline-image-extensions
)))
807 ;;; org-html-make-link
808 (defun org-html-make-link (opt-plist type path fragment desc attr
811 OPT-PLIST is an options list.
812 TYPE is the device-type of the link (THIS://foo.html)
813 PATH is the path of the link (http://THIS#locationx)
814 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
815 DESC is the link description, if any.
816 ATTR is a string of other attributes of the a element.
817 MAY-INLINE-P allows inlining it as an image."
819 (declare (special org-par-open
))
821 (let* ((filename path
)
822 ;;First pass. Just sanity stuff.
825 ((string= type
"file")
828 ;;Substitute just if original path was absolute.
829 ;;(Otherwise path must remain relative)
830 (if (file-name-absolute-p path
)
831 (concat "file://" (expand-file-name path
))
835 (t (list type path
))))
837 ;;Second pass. Components converted so they can refer
841 (and org-html-cvt-link-fn
842 (apply org-html-cvt-link-fn
843 opt-plist components-1
))
844 (apply #'org-html-cvt-org-as-html
845 opt-plist components-1
)
847 (type (first components-2
))
848 (thefile (second components-2
)))
851 ;;Third pass. Build final link except for leading type
856 (string= type
"http")
857 (string= type
"https")
858 (string= type
"file")
859 (string= type
"coderef"))
861 (setq thefile
(concat thefile
"#" fragment
))))
865 ;;Final URL-build, for all types.
868 ((str (org-export-html-format-href thefile
)))
869 (if (and type
(not (or (string= "file" type
)
870 (string= "coderef" type
))))
871 (concat type
":" str
)
876 ;;Can't inline a URL with a fragment.
879 (message "image %s %s" thefile org-par-open
)
880 (org-export-html-format-image thefile org-par-open
))
882 "<a href=\"" thefile
"\"" (if attr
(concat " " attr
)) ">"
883 (org-export-html-format-desc desc
)
886 (defun org-html-handle-links (line opt-plist
)
887 "Return LINE with markup of Org mode links.
888 OPT-PLIST is the export options list."
890 (current-dir (if buffer-file-name
891 (file-name-directory buffer-file-name
)
893 (link-validate (plist-get opt-plist
:link-validation-function
))
895 rpl path attr desc descp desc1 desc2 link
)
896 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
897 (setq start
(match-beginning 0))
898 (setq path
(save-match-data (org-link-unescape
899 (match-string 3 line
))))
901 ((match-end 2) (match-string 2 line
))
903 (or (file-name-absolute-p path
)
904 (string-match "^\\.\\.?/" path
)))
907 (setq path
(org-extract-attributes (org-link-unescape path
)))
908 (setq attr
(get-text-property 0 'org-attributes path
))
909 (setq desc1
(if (match-end 5) (match-string 5 line
))
910 desc2
(if (match-end 2) (concat type
":" path
) path
)
911 descp
(and desc1
(not (equal desc1 desc2
)))
912 desc
(or desc1 desc2
))
913 ;; Make an image out of the description if that is so wanted
914 (when (and descp
(org-file-image-p
915 desc org-export-html-inline-image-extensions
))
917 (if (string-match "^file:" desc
)
918 (setq desc
(substring desc
(match-end 0)))))
919 (setq desc
(org-add-props
920 (concat "<img src=\"" desc
"\" alt=\""
921 (file-name-nondirectory desc
) "\"/>")
922 '(org-protected t
))))
924 ((equal type
"internal")
927 (if (= (string-to-char path
) ?
#)
935 (org-solidify-link-text
936 (save-match-data (org-link-unescape frag-0
))
939 ((and (equal type
"id")
940 (setq id-file
(org-id-find-id-file path
)))
941 ;; This is an id: link to another file (if it was the same file,
942 ;; it would have become an internal link...)
944 (setq id-file
(file-relative-name
946 (file-name-directory org-current-export-file
)))
948 (org-html-make-link opt-plist
950 (concat (if (org-uuidgen-p path
) "ID-") path
)
954 ((member type
'("http" "https"))
955 ;; standard URL, can inline as image
957 (org-html-make-link opt-plist
961 (org-html-should-inline-p path descp
))))
962 ((member type
'("ftp" "mailto" "news"))
963 ;; standard URL, can't inline as image
965 (org-html-make-link opt-plist
971 ((string= type
"coderef")
973 ((coderef-str (format "coderef-%s" path
))
975 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
976 coderef-str coderef-str
)))
978 (org-html-make-link opt-plist
981 (org-export-get-coderef-format
984 (cdr (assoc path org-export-code-refs
)))
988 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
989 ;; The link protocol has a function for format the link
992 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
994 ((string= type
"file")
1000 (string-match "::\\(.*\\)" path
)
1002 (replace-match "" t nil path
)
1003 (match-string 1 path
))
1006 ;;The proper path, without a fragment
1012 (second components
))
1014 ;;Check the fragment. If it can't be used as
1015 ;;target fragment we'll pass nil instead.
1019 (not (string-match "^[0-9]*$" fragment-0
))
1020 (not (string-match "^\\*" fragment-0
))
1021 (not (string-match "^/.*/$" fragment-0
)))
1022 (org-solidify-link-text
1023 (org-link-unescape fragment-0
))
1026 ;;Description minus "file:" and ".org"
1027 (if (string-match "^file:" desc
)
1029 ((desc-1 (replace-match "" t t desc
)))
1030 (if (string-match "\\.org$" desc-1
)
1031 (replace-match "" t t desc-1
)
1038 (functionp link-validate
)
1039 (not (funcall link-validate path-1 current-dir
)))
1041 (org-html-make-link opt-plist
1042 "file" path-1 fragment-1 desc-2 attr
1043 (org-html-should-inline-p path-1 descp
)))))))
1046 ;; just publish the path, as default
1047 (setq rpl
(concat "@<i><" type
":"
1048 (save-match-data (org-link-unescape path
))
1050 (setq line
(replace-match rpl t t line
)
1051 start
(+ start
(length rpl
))))
1054 ;;; org-export-as-html
1056 (defun org-export-as-html (arg &optional hidden ext-plist
1057 to-buffer body-only pub-dir
)
1058 "Export the outline as a pretty HTML file.
1059 If there is an active region, export only the region. The prefix
1060 ARG specifies how many levels of the outline should become
1061 headlines. The default is 3. Lower levels will become bulleted
1062 lists. HIDDEN is obsolete and does nothing.
1063 EXT-PLIST is a property list with external parameters overriding
1064 org-mode's default settings, but still inferior to file-local
1065 settings. When TO-BUFFER is non-nil, create a buffer with that
1066 name and export to that buffer. If TO-BUFFER is the symbol
1067 `string', don't leave any buffer behind but just return the
1068 resulting HTML as a string. When BODY-ONLY is set, don't produce
1069 the file header and footer, simply return the content of
1070 <body>...</body>, without even the body tags themselves. When
1071 PUB-DIR is set, use this as the publishing directory."
1073 (run-hooks 'org-export-first-hook
)
1075 ;; Make sure we have a file name when we need it.
1076 (when (and (not (or to-buffer body-only
))
1077 (not buffer-file-name
))
1078 (if (buffer-base-buffer)
1079 (org-set-local 'buffer-file-name
1080 (with-current-buffer (buffer-base-buffer)
1082 (error "Need a file name to be able to export")))
1084 (message "Exporting...")
1085 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1086 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1087 (setq-default org-done-keywords org-done-keywords
)
1088 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1090 (org-export-process-option-filters
1091 (org-combine-plists (org-default-export-plist)
1093 (org-infile-export-plist))))
1094 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1095 (style (concat (if (plist-get opt-plist
:style-include-default
)
1096 org-export-html-style-default
)
1097 (plist-get opt-plist
:style
)
1098 (plist-get opt-plist
:style-extra
)
1100 (if (plist-get opt-plist
:style-include-scripts
)
1101 org-export-html-scripts
)))
1102 (html-extension (plist-get opt-plist
:html-extension
))
1103 valid thetoc have-headings first-heading-pos
1104 (odd org-odd-levels-only
)
1105 (region-p (org-region-active-p))
1106 (rbeg (and region-p
(region-beginning)))
1107 (rend (and region-p
(region-end)))
1109 (if (plist-get opt-plist
:ignore-subtree-p
)
1114 (and (org-at-heading-p)
1115 (>= (org-end-of-subtree t t
) rend
))))))
1116 (level-offset (if subtree-p
1119 (+ (funcall outline-level
)
1120 (if org-odd-levels-only
1 0)))
1122 (opt-plist (setq org-export-opt-plist
1124 (org-export-add-subtree-options opt-plist rbeg
)
1126 ;; The following two are dynamically scoped into other
1128 (org-current-export-dir
1129 (or pub-dir
(org-export-directory :html opt-plist
)))
1130 (org-current-export-file buffer-file-name
)
1131 (level 0) (line "") (origline "") txt todo
1134 (filename (if to-buffer nil
1137 (file-name-sans-extension
1139 (org-entry-get (region-beginning)
1140 "EXPORT_FILE_NAME" t
))
1141 (file-name-nondirectory buffer-file-name
)))
1143 (file-name-as-directory
1144 (or pub-dir
(org-export-directory :html opt-plist
))))))
1145 (current-dir (if buffer-file-name
1146 (file-name-directory buffer-file-name
)
1148 (buffer (if to-buffer
1150 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
1151 (t (get-buffer-create to-buffer
)))
1152 (find-file-noselect filename
)))
1153 (org-levels-open (make-vector org-level-max nil
))
1154 (date (plist-get opt-plist
:date
))
1155 (author (plist-get opt-plist
:author
))
1156 (html-validation-link (or org-export-html-validation-link
""))
1157 (title (org-html-expand
1158 (or (and subtree-p
(org-export-get-title-from-subtree))
1159 (plist-get opt-plist
:title
)
1160 (and (not body-only
)
1162 (plist-get opt-plist
:skip-before-1st-heading
))
1163 (org-export-grab-title-from-buffer))
1164 (and buffer-file-name
1165 (file-name-sans-extension
1166 (file-name-nondirectory buffer-file-name
)))
1168 (link-up (and (plist-get opt-plist
:link-up
)
1169 (string-match "\\S-" (plist-get opt-plist
:link-up
))
1170 (plist-get opt-plist
:link-up
)))
1171 (link-home (and (plist-get opt-plist
:link-home
)
1172 (string-match "\\S-" (plist-get opt-plist
:link-home
))
1173 (plist-get opt-plist
:link-home
)))
1174 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1175 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1176 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1177 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
1181 (email (plist-get opt-plist
:email
))
1182 (language (plist-get opt-plist
:language
))
1183 (keywords (plist-get opt-plist
:keywords
))
1184 (description (plist-get opt-plist
:description
))
1185 (num (plist-get opt-plist
:section-numbers
))
1189 (coding-system (and (boundp 'buffer-file-coding-system
)
1190 buffer-file-coding-system
))
1191 (coding-system-for-write (or org-export-html-coding-system
1193 (save-buffer-coding-system (or org-export-html-coding-system
1195 (charset (and coding-system-for-write
1196 (fboundp 'coding-system-get
)
1197 (coding-system-get coding-system-for-write
1201 (if region-p
(region-beginning) (point-min))
1202 (if region-p
(region-end) (point-max))))
1203 (org-export-have-math nil
)
1204 (org-export-footnotes-seen nil
)
1205 (org-export-footnotes-data (org-footnote-all-labels 'with-defs
))
1208 (org-export-preprocess-string
1212 :skip-before-1st-heading
1213 (plist-get opt-plist
:skip-before-1st-heading
)
1214 :drawers
(plist-get opt-plist
:drawers
)
1215 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1216 :tasks
(plist-get opt-plist
:tasks
)
1217 :tags
(plist-get opt-plist
:tags
)
1218 :priority
(plist-get opt-plist
:priority
)
1219 :footnotes
(plist-get opt-plist
:footnotes
)
1220 :timestamps
(plist-get opt-plist
:timestamps
)
1222 (plist-get opt-plist
:archived-trees
)
1223 :select-tags
(plist-get opt-plist
:select-tags
)
1224 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1226 (plist-get opt-plist
:text
)
1228 (plist-get opt-plist
:LaTeX-fragments
))
1231 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
1232 (and org-export-have-math
1233 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
1235 (org-export-html-mathjax-config
1236 org-export-html-mathjax-template
1237 org-export-html-mathjax-options
1238 (or (plist-get opt-plist
:mathjax
) ""))
1241 table-buffer table-orig-buffer
1243 rpl path attr desc descp desc1 desc2 link
1245 footnotes footref-seen
1249 (let ((inhibit-read-only t
))
1251 (remove-text-properties (point-min) (point-max)
1252 '(:org-license-to-kill t
))))
1254 (message "Exporting...")
1256 (setq org-min-level
(org-get-min-level lines level-offset
))
1257 (setq org-last-level org-min-level
)
1258 (org-init-section-numbers)
1261 ((and date
(string-match "%" date
))
1262 (setq date
(format-time-string date
)))
1264 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
1266 ;; Get the language-dependent settings
1267 (setq lang-words
(or (assoc language org-export-language-setup
)
1268 (assoc "en" org-export-language-setup
)))
1270 ;; Switch to the output buffer
1272 (let ((inhibit-read-only t
)) (erase-buffer))
1274 (org-install-letbind)
1276 (and (fboundp 'set-buffer-file-coding-system
)
1277 (set-buffer-file-coding-system coding-system-for-write
))
1279 (let ((case-fold-search nil
)
1280 (org-odd-levels-only odd
))
1281 ;; create local variables for all options, to make sure all called
1282 ;; functions get the correct information
1284 (set (make-local-variable (nth 2 x
))
1285 (plist-get opt-plist
(car x
))))
1286 org-export-plist-vars
)
1287 (setq umax
(if arg
(prefix-numeric-value arg
)
1288 org-export-headline-levels
))
1289 (setq umax-toc
(if (integerp org-export-with-toc
)
1290 (min org-export-with-toc umax
)
1296 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1297 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1298 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1299 lang=\"%s\" xml:lang=\"%s\">
1302 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1303 <meta name=\"generator\" content=\"Org-mode\"/>
1304 <meta name=\"generated\" content=\"%s\"/>
1305 <meta name=\"author\" content=\"%s\"/>
1306 <meta name=\"description\" content=\"%s\"/>
1307 <meta name=\"keywords\" content=\"%s\"/>
1315 (or (and (stringp org-export-html-xml-declaration
)
1316 org-export-html-xml-declaration
)
1317 (cdr (assoc html-extension org-export-html-xml-declaration
))
1318 (cdr (assoc "html" org-export-html-xml-declaration
))
1321 (or charset
"iso-8859-1"))
1324 (or charset
"iso-8859-1")
1325 date author description keywords
1328 (if (or link-up link-home
)
1330 (format org-export-html-home
/up-format
1331 (or link-up link-home
)
1332 (or link-home link-up
))
1336 ;; insert html preamble
1337 (when (plist-get opt-plist
:html-preamble
)
1338 (let ((html-pre (plist-get opt-plist
:html-preamble
)))
1339 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1340 (cond ((stringp html-pre
)
1342 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
1343 (?d .
,date
) (?e .
,email
)))))
1344 ((functionp html-pre
)
1349 (or (cadr (assoc (nth 0 lang-words
)
1350 org-export-html-preamble-format
))
1351 (cadr (assoc "en" org-export-html-preamble-format
)))
1352 `((?t .
,title
) (?a .
,author
)
1353 (?d .
,date
) (?e .
,email
))))))
1354 (insert "\n</div>\n")))
1356 ;; begin wrap around body
1357 (insert (format "\n<div id=\"%s\">"
1358 ;; FIXME org-export-html-content-div is obsolete since 7.7
1359 (or org-export-html-content-div
1360 (nth 1 org-export-html-divs
)))
1361 ;; FIXME this should go in the preamble but is here so
1362 ;; that org-infojs can still find it
1363 "\n<h1 class=\"title\">" title
"</h1>\n"))
1366 (if (and org-export-with-toc
(not body-only
))
1368 (push (format "<h%d>%s</h%d>\n"
1369 org-export-html-toplevel-hlevel
1371 org-export-html-toplevel-hlevel
)
1373 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1374 (push "<ul>\n<li>" thetoc
)
1378 (if (and (string-match org-todo-line-regexp line
)
1379 (not (get-text-property 0 'org-protected line
)))
1380 ;; This is a headline
1382 (setq have-headings t
)
1383 (setq level
(- (match-end 1) (match-beginning 1)
1385 level
(org-tr-level level
)
1386 txt
(save-match-data
1388 (org-export-cleanup-toc-line
1389 (match-string 3 line
))))
1391 (or (and org-export-mark-todo-in-toc
1393 (not (member (match-string 2 line
)
1394 org-done-keywords
)))
1396 (and org-export-mark-todo-in-toc
1398 (org-search-todo-below
1399 line lines level
))))
1401 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1402 (setq txt
(replace-match
1403 " <span class=\"tag\"> \\1</span>" t nil txt
)))
1404 (if (string-match quote-re0 txt
)
1405 (setq txt
(replace-match "" t t txt
)))
1406 (setq snumber
(org-section-number level
))
1407 (if (and num
(if (integerp num
)
1410 (setq txt
(concat snumber
" " txt
)))
1411 (if (<= level
(max umax umax-toc
))
1412 (setq head-count
(+ head-count
1)))
1413 (if (<= level umax-toc
)
1415 (if (> level org-last-level
)
1417 (setq cnt
(- level org-last-level
))
1418 (while (>= (setq cnt
(1- cnt
)) 0)
1419 (push "\n<ul>\n<li>" thetoc
))
1420 (push "\n" thetoc
)))
1421 (if (< level org-last-level
)
1423 (setq cnt
(- org-last-level level
))
1424 (while (>= (setq cnt
(1- cnt
)) 0)
1425 (push "</li>\n</ul>" thetoc
))
1426 (push "\n" thetoc
)))
1427 ;; Check for targets
1428 (while (string-match org-any-target-regexp line
)
1429 (setq line
(replace-match
1430 (concat "@<span class=\"target\">"
1431 (match-string 1 line
) "@</span> ")
1433 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1434 (setq txt
(replace-match "" t t txt
)))
1436 (replace-regexp-in-string
1437 "\\." "-" (format "sec-%s" snumber
)))
1438 (setq href
(org-solidify-link-text
1439 (or (cdr (assoc href
1440 org-export-preferred-target-alist
)) href
)))
1444 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1445 "</li>\n<li><a href=\"#%s\">%s</a>")
1448 (setq org-last-level level
)))))
1451 (while (> org-last-level
(1- org-min-level
))
1452 (setq org-last-level
(1- org-last-level
))
1453 (push "</li>\n</ul>\n" thetoc
))
1454 (push "</div>\n" thetoc
)
1455 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1458 (org-init-section-numbers)
1462 (while (setq line
(pop lines
) origline line
)
1465 ;; end of quote section?
1466 (when (and inquote
(string-match org-outline-regexp-bol line
))
1470 ;; inside a quote section?
1472 (insert (org-html-protect line
) "\n")
1473 (throw 'nextline nil
))
1475 ;; Fixed-width, verbatim lines (examples)
1476 (when (and org-export-with-fixed-width
1477 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1480 (org-close-par-maybe)
1482 (insert "<pre class=\"example\">\n"))
1483 (insert (org-html-protect (match-string 3 line
)) "\n")
1484 (when (or (not lines
)
1485 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1490 (throw 'nextline nil
))
1493 (when (and (get-text-property 0 'org-protected line
)
1494 ;; Make sure it is the entire line that is protected
1495 (not (< (or (next-single-property-change
1496 0 'org-protected line
) 10000)
1498 (let (par (ind (get-text-property 0 'original-indentation line
)))
1499 (when (re-search-backward
1500 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1501 (setq par
(match-string 1))
1502 (replace-match "\\2\n"))
1505 (or (= (length (car lines
)) 0)
1507 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1508 (or (= (length (car lines
)) 0)
1509 (get-text-property 0 'org-protected
(car lines
))))
1510 (insert (pop lines
) "\n"))
1511 (and par
(insert "<p>\n")))
1512 (throw 'nextline nil
))
1514 ;; Blockquotes, verse, and center
1515 (when (equal "ORG-BLOCKQUOTE-START" line
)
1516 (org-close-par-maybe)
1517 (insert "<blockquote>\n")
1519 (throw 'nextline nil
))
1520 (when (equal "ORG-BLOCKQUOTE-END" line
)
1521 (org-close-par-maybe)
1522 (insert "\n</blockquote>\n")
1524 (throw 'nextline nil
))
1525 (when (equal "ORG-VERSE-START" line
)
1526 (org-close-par-maybe)
1527 (insert "\n<p class=\"verse\">\n")
1528 (setq org-par-open t
)
1530 (throw 'nextline nil
))
1531 (when (equal "ORG-VERSE-END" line
)
1533 (setq org-par-open nil
)
1536 (throw 'nextline nil
))
1537 (when (equal "ORG-CENTER-START" line
)
1538 (org-close-par-maybe)
1539 (insert "\n<div style=\"text-align: center\">")
1541 (throw 'nextline nil
))
1542 (when (equal "ORG-CENTER-END" line
)
1543 (org-close-par-maybe)
1546 (throw 'nextline nil
))
1547 (run-hooks 'org-export-html-after-blockquotes-hook
)
1549 (let ((i (org-get-string-indentation line
)))
1551 (setq line
(concat (mapconcat 'identity
1552 (make-list (* 2 i
) "\\nbsp") "")
1553 " " (org-trim line
))))
1554 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1555 (setq line
(concat line
"\\\\")))))
1557 ;; make targets to anchors
1559 (while (string-match
1560 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1562 ((get-text-property (match-beginning 1) 'org-protected line
)
1563 (setq start
(match-end 1)))
1565 (setq line
(replace-match
1567 "@<a name=\"%s\" id=\"%s\">@</a>"
1568 (org-solidify-link-text (match-string 1 line
))
1569 (org-solidify-link-text (match-string 1 line
)))
1571 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1572 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1573 (setq line
(replace-match
1574 (concat "@<span class=\"target\">"
1575 (match-string 1 line
) "@</span> ")
1576 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1579 (setq line
(replace-match
1580 (concat "@<a name=\""
1581 (org-solidify-link-text (match-string 1 line
))
1582 "\" class=\"target\">" (match-string 1 line
)
1586 (setq line
(org-html-handle-time-stamps line
))
1588 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1589 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1590 ;; Also handle sub_superscripts and checkboxes
1591 (or (string-match org-table-hline-regexp line
)
1592 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line
)
1593 (setq line
(org-html-expand line
)))
1596 (setq line
(org-html-handle-links line opt-plist
))
1599 (if (and (string-match org-todo-line-regexp line
)
1600 (match-beginning 2))
1603 (concat (substring line
0 (match-beginning 2))
1605 (if (member (match-string 2 line
)
1608 " " (match-string 2 line
)
1609 "\"> " (org-export-html-get-todo-kwd-class-name
1610 (match-string 2 line
))
1611 "</span>" (substring line
(match-end 2)))))
1613 ;; Does this contain a reference to a footnote?
1614 (when org-export-with-footnotes
1616 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
1617 ;; Discard protected matches not clearly identified as
1618 ;; footnote markers.
1619 (if (or (get-text-property (match-beginning 2) 'org-protected line
)
1620 (not (get-text-property (match-beginning 2) 'org-footnote line
)))
1621 (setq start
(match-end 2))
1622 (let ((n (match-string 2 line
)) extra a
)
1623 (if (setq a
(assoc n footref-seen
))
1625 (setcdr a
(1+ (cdr a
)))
1626 (setq extra
(format ".%d" (cdr a
))))
1628 (push (cons n
1) footref-seen
))
1634 (format org-export-html-footnote-format
1635 (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
1636 (or (match-string 1 line
) "") n extra n n
)
1637 ;; If another footnote is following the
1638 ;; current one, add a separator.
1639 (if (save-match-data
1640 (string-match "\\`\\[[0-9]+\\]"
1641 (substring line
(match-end 0))))
1642 org-export-html-footnote-separator
1647 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1648 ;; This is a headline
1649 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1651 txt
(match-string 2 line
))
1652 (if (string-match quote-re0 txt
)
1653 (setq txt
(replace-match "" t t txt
)))
1654 (if (<= level
(max umax umax-toc
))
1655 (setq head-count
(+ head-count
1)))
1656 (setq first-heading-pos
(or first-heading-pos
(point)))
1657 (org-html-level-start level txt umax
1658 (and org-export-with-toc
(<= level umax
))
1659 head-count opt-plist
)
1662 (when (string-match quote-re line
)
1663 (org-close-par-maybe)
1667 ((and org-export-with-tables
1668 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1669 (when (not table-open
)
1671 (setq table-open t table-buffer nil table-orig-buffer nil
))
1674 (setq table-buffer
(cons line table-buffer
)
1675 table-orig-buffer
(cons origline table-orig-buffer
))
1676 (when (or (not lines
)
1677 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1679 (setq table-open nil
1680 table-buffer
(nreverse table-buffer
)
1681 table-orig-buffer
(nreverse table-orig-buffer
))
1682 (org-close-par-maybe)
1683 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1688 ;; This line either is list item or end a list.
1689 (when (get-text-property 0 'list-item line
)
1690 (setq line
(org-html-export-list-line
1692 (get-text-property 0 'list-item line
)
1693 (get-text-property 0 'list-struct line
)
1694 (get-text-property 0 'list-prevs line
))))
1697 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1699 (insert "\n</p>\n<hr/>\n<p>\n")
1700 (insert "\n<hr/>\n"))
1701 (throw 'nextline nil
))
1703 ;; Empty lines start a new paragraph. If hand-formatted lists
1704 ;; are not fully interpreted, lines starting with "-", "+", "*"
1705 ;; also start a new paragraph.
1706 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
1708 ;; Is this the start of a footnote?
1709 (when org-export-with-footnotes
1710 (when (and (boundp 'footnote-section-tag-regexp
)
1711 (string-match (concat "^" footnote-section-tag-regexp
)
1714 (throw 'nextline nil
))
1715 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1716 (org-close-par-maybe)
1717 (let ((n (match-string 1 line
)))
1718 (setq org-par-open t
1721 (concat "<p class=\"footnote\">"
1722 (format org-export-html-footnote-format
1723 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1724 n n n
) t t line
)))))
1725 ;; Check if the line break needs to be conserved
1727 ((string-match "\\\\\\\\[ \t]*$" line
)
1728 (setq line
(replace-match "<br/>" t t line
)))
1729 (org-export-preserve-breaks
1730 (setq line
(concat line
"<br/>"))))
1732 ;; Check if a paragraph should be started
1734 (while (and org-par-open
1735 (string-match "\\\\par\\>" line start
))
1736 ;; Leave a space in the </p> so that the footnote matcher
1737 ;; does not see this.
1738 (if (not (get-text-property (match-beginning 0)
1739 'org-protected line
))
1740 (setq line
(replace-match "</p ><p >" t t line
)))
1741 (setq start
(match-end 0))))
1743 (insert line
"\n")))))
1745 ;; Properly close all local lists and other lists
1750 (org-html-level-start 1 nil umax
1751 (and org-export-with-toc
(<= level umax
))
1752 head-count opt-plist
)
1753 ;; the </div> to close the last text-... div.
1754 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1757 (goto-char (point-min))
1758 (while (re-search-forward
1759 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1761 (push (match-string 1) footnotes
)
1762 (replace-match "\\4" t nil
)
1763 (goto-char (match-beginning 0))))
1765 (insert (format org-export-html-footnotes-section
1767 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1769 (let ((bib (org-export-html-get-bibliography)))
1771 (insert "\n" bib
"\n")))
1774 ;; end wrap around body
1777 ;; export html postamble
1778 (let ((html-post (plist-get opt-plist
:html-postamble
))
1780 (mapconcat (lambda(e)
1781 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1782 (split-string email
",+ *")
1785 (concat "Org version " org-version
" with Emacs version "
1786 (number-to-string emacs-major-version
))))
1788 (when (plist-get opt-plist
:html-postamble
)
1789 (insert "\n<div id=\"" (nth 2 org-export-html-divs
) "\">\n")
1790 (cond ((stringp html-post
)
1791 (insert (format-spec html-post
1792 `((?a .
,author
) (?e .
,email
)
1793 (?d .
,date
) (?c .
,creator-info
)
1794 (?v .
,html-validation-link
)))))
1795 ((functionp html-post
)
1796 (funcall html-post
))
1797 ((eq html-post
'auto
)
1798 ;; fall back on default postamble
1799 (when (plist-get opt-plist
:time-stamp-file
)
1800 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
1801 (when (and (plist-get opt-plist
:author-info
) author
)
1802 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
1803 (when (and (plist-get opt-plist
:email-info
) email
)
1804 (insert "<p class=\"email\">" email
"</p>\n"))
1805 (when (plist-get opt-plist
:creator-info
)
1806 (insert "<p class=\"creator\">"
1807 (concat "Org version " org-version
" with Emacs version "
1808 (number-to-string emacs-major-version
) "</p>\n")))
1809 (insert html-validation-link
"\n"))
1811 (insert (format-spec
1812 (or (cadr (assoc (nth 0 lang-words
)
1813 org-export-html-postamble-format
))
1814 (cadr (assoc "en" org-export-html-postamble-format
)))
1815 `((?a .
,author
) (?e .
,email
)
1816 (?d .
,date
) (?c .
,creator-info
)
1817 (?v .
,html-validation-link
))))))
1818 (insert "\n</div>"))))
1820 ;; FIXME `org-export-html-with-timestamp' has been declared
1821 ;; obsolete since Org 7.7 -- don't forget to remove this.
1822 (if org-export-html-with-timestamp
1823 (insert org-export-html-html-helper-timestamp
))
1825 (unless body-only
(insert "\n</body>\n</html>\n"))
1827 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1829 (if (eq major-mode
(default-value 'major-mode
))
1832 ;; insert the table of contents
1833 (goto-char (point-min))
1835 (if (or (re-search-forward
1836 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1838 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1840 (goto-char (match-beginning 0))
1842 (goto-char first-heading-pos
)
1843 (when (looking-at "\\s-*</p>")
1844 (goto-char (match-end 0))
1846 (insert "<div id=\"table-of-contents\">\n")
1847 (let ((beg (point)))
1848 (mapc 'insert thetoc
)
1850 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t
)
1851 (replace-match ""))))
1852 ;; remove empty paragraphs
1853 (goto-char (point-min))
1854 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1856 (goto-char (point-min))
1857 ;; Convert whitespace place holders
1858 (goto-char (point-min))
1860 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1861 (setq n
(get-text-property beg
'org-whitespace
)
1862 end
(next-single-property-change beg
'org-whitespace
))
1864 (delete-region beg end
)
1865 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1866 (make-string n ?x
)))))
1867 ;; Remove empty lines at the beginning of the file.
1868 (goto-char (point-min))
1869 (when (looking-at "\\s-+\n") (replace-match ""))
1870 ;; Remove display properties
1871 (remove-text-properties (point-min) (point-max) '(display t
))
1873 (run-hooks 'org-export-html-final-hook
)
1874 (or to-buffer
(save-buffer))
1875 (goto-char (point-min))
1876 (or (org-export-push-to-kill-ring "HTML")
1877 (message "Exporting... done"))
1878 (if (eq to-buffer
'string
)
1879 (prog1 (buffer-substring (point-min) (point-max))
1880 (kill-buffer (current-buffer)))
1881 (current-buffer)))))
1883 (defun org-export-html-format-href (s)
1884 "Make sure the S is valid as a href reference in an XHTML document."
1887 (while (string-match "&" s start
)
1888 (setq start
(+ (match-beginning 0) 3)
1889 s
(replace-match "&" t t s
)))))
1892 (defun org-export-html-format-desc (s)
1893 "Make sure the S is valid as a description in a link."
1894 (if (and s
(not (get-text-property 1 'org-protected s
)))
1896 (org-html-do-expand s
))
1899 (defun org-export-html-format-image (src par-open
)
1900 "Create image tag with source and attributes."
1902 (if (string-match "^ltxpng/" src
)
1903 (format "<img src=\"%s\" alt=\"%s\"/>"
1904 src
(org-find-text-property-in-string 'org-latex-src src
))
1905 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1906 (attr (org-find-text-property-in-string 'org-attributes src
))
1907 (label (org-find-text-property-in-string 'org-label src
)))
1908 (setq caption
(and caption
(org-html-do-expand caption
)))
1911 (format "%s<div %sclass=\"figure\">
1913 (if org-par-open
"</p>\n" "")
1914 (if label
(format "id=\"%s\" " (org-solidify-link-text label
)) "")))
1915 (format "<img src=\"%s\"%s />"
1917 (if (string-match "\\<alt=" (or attr
""))
1919 (concat " " attr
" alt=\"" src
"\"")))
1923 (concat "\n<p>" caption
"</p>")
1924 (if org-par-open
"\n<p>" ""))))))))
1926 (defun org-export-html-get-bibliography ()
1927 "Find bibliography, cut it out and return it."
1929 (let (beg end
(cnt 1) bib
)
1931 (goto-char (point-min))
1932 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1933 (setq beg
(match-beginning 0))
1934 (while (re-search-forward "</?div\\>" nil t
)
1935 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1937 (and (looking-at ">") (forward-char 1))
1938 (setq bib
(buffer-substring beg
(point)))
1939 (delete-region beg
(point))
1940 (throw 'exit bib
))))
1943 (defvar org-table-number-regexp
) ; defined in org-table.el
1944 (defun org-format-table-html (lines olines
&optional no-css
)
1945 "Find out which HTML converter to use and return the HTML code.
1946 NO-CSS is passed to the exporter."
1948 (setq lines
(org-split-string lines
"\n")))
1949 (if (string-match "^[ \t]*|" (car lines
))
1950 ;; A normal org table
1951 (org-format-org-table-html lines nil no-css
)
1952 ;; Table made by table.el
1953 (or (org-format-table-table-html-using-table-generate-source
1954 olines
(not org-export-prefer-native-exporter-for-tables
))
1955 ;; We are here only when table.el table has NO col or row
1956 ;; spanning and the user prefers using org's own converter for
1957 ;; exporting of such simple table.el tables.
1958 (org-format-table-table-html lines
))))
1960 (defvar org-table-number-fraction
) ; defined in org-table.el
1961 (defun org-format-org-table-html (lines &optional splice no-css
)
1962 "Format a table into HTML.
1963 LINES is a list of lines. Optional argument SPLICE means, do not
1964 insert header and surrounding <table> tags, just format the lines.
1965 Optional argument NO-CSS means use XHTML attributes instead of CSS
1966 for formatting. This is required for the DocBook exporter."
1967 (require 'org-table
)
1968 ;; Get rid of hlines at beginning and end
1969 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1970 (setq lines
(nreverse lines
))
1971 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1972 (setq lines
(nreverse lines
))
1973 (when org-export-table-remove-special-lines
1974 ;; Check if the table has a marking column. If yes remove the
1975 ;; column and the special lines
1976 (setq lines
(org-table-clean-before-export lines
)))
1978 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1979 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1980 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
1982 (attributes (org-find-text-property-in-string 'org-attributes
1984 (html-table-tag (org-export-splice-attributes
1985 html-table-tag attributes
))
1986 (head (and org-export-highlight-first-table-line
1988 (lambda (x) (string-match "^[ \t]*|-" x
))
1990 (nline 0) fnum nfields i
(cnt 0)
1991 tbopen line fields html gr colgropen rowstart rowend
1993 (setq caption
(and caption
(org-html-do-expand caption
)))
1994 (when (and forced-aligns org-table-clean-did-remove-column
)
1996 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) forced-aligns
)))
1997 (if splice
(setq head nil
))
1998 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
2000 (while (setq line
(pop lines
))
2002 (if (string-match "^[ \t]*|-" line
)
2005 (push (if head
"</thead>" "</tbody>") html
)
2006 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
2007 (setq head nil
) ;; head ends here, first time around
2009 (throw 'next-line t
)))
2010 ;; Break the line into fields
2011 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2012 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
2013 nfields
(length fnum
)))
2014 (setq nline
(1+ nline
) i -
1
2015 rowstart
(eval (car org-export-table-row-tags
))
2016 rowend
(eval (cdr org-export-table-row-tags
)))
2017 (push (concat rowstart
2020 (setq i
(1+ i
) ali
(format "@@class%03d@@" i
))
2021 (if (and (< i nfields
) ; make sure no rogue line causes an error here
2022 (string-match org-table-number-regexp x
))
2023 (incf (aref fnum i
)))
2027 (format (car org-export-table-header-tags
)
2030 (cdr org-export-table-header-tags
)))
2031 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
2033 (format (car org-export-table-header-tags
)
2036 (cdr org-export-table-header-tags
)))
2038 (concat (format (car org-export-table-data-tags
) ali
)
2040 (cdr org-export-table-data-tags
)))))
2044 (unless splice
(if tbopen
(push "</tbody>" html
)))
2045 (unless splice
(push "</table>\n" html
))
2046 (setq html
(nreverse html
))
2048 ;; Put in col tags with the alignment (unfortunately often ignored...)
2049 (unless (car org-table-colgroup-info
)
2050 (setq org-table-colgroup-info
2051 (cons :start
(cdr org-table-colgroup-info
))))
2055 (setq gr
(pop org-table-colgroup-info
)
2057 align
(if (assoc i forced-aligns
)
2058 (cdr (assoc (cdr (assoc i forced-aligns
))
2059 '(("l" .
"left") ("r" .
"right")
2061 (if (> (/ (float x
) nline
)
2062 org-table-number-fraction
)
2066 "%s<col align=\"%s\" />%s"
2067 "%s<col class=\"%s\" />%s")
2068 (if (memq gr
'(:start
:startend
))
2071 "</colgroup>\n<colgroup>"
2076 (if (memq gr
'(:end
:startend
))
2077 (progn (setq colgropen nil
) "</colgroup>")
2081 (setq aligns
(nreverse aligns
))
2082 (if colgropen
(setq html
(cons (car html
)
2083 (cons "</colgroup>" (cdr html
)))))
2084 ;; Since the output of HTML table formatter can also be used in
2085 ;; DocBook document, we want to always include the caption to make
2086 ;; DocBook XML file valid.
2087 (push (format "<caption>%s</caption>" (or caption
"")) html
)
2089 (setq html-table-tag
(org-export-splice-attributes html-table-tag
(format "id=\"%s\"" (org-solidify-link-text label
)))))
2090 (push html-table-tag html
))
2093 (replace-regexp-in-string
2094 "@@class\\([0-9]+\\)@@"
2096 (if (not org-export-html-table-align-individual-fields
)
2098 (setq n
(string-to-number (match-string 1 txt
)))
2099 (format (if no-css
" align=\"%s\"" " class=\"%s\"")
2100 (or (nth n aligns
) "left"))))
2103 (concat (mapconcat 'identity html
"\n") "\n")))
2105 (defun org-export-splice-attributes (tag attributes
)
2106 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2107 (if (not attributes
)
2109 (let (oldatt newatt
)
2110 (setq oldatt
(org-extract-attributes-from-string tag
)
2112 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2114 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2115 (if (string-match ">" tag
)
2117 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2121 (defun org-format-table-table-html (lines)
2122 "Format a table generated by table.el into HTML.
2123 This conversion does *not* use `table-generate-source' from table.el.
2124 This has the advantage that Org-mode's HTML conversions can be used.
2125 But it has the disadvantage, that no cell- or row-spanning is allowed."
2126 (let (line field-buffer
2127 (head org-export-highlight-first-table-line
)
2128 fields html empty i
)
2129 (setq html
(concat html-table-tag
"\n"))
2130 (while (setq line
(pop lines
))
2131 (setq empty
" ")
2133 (if (string-match "^[ \t]*\\+-" line
)
2144 (if (equal x
"") (setq x empty
))
2147 (format (car org-export-table-header-tags
) "col" "")
2149 (cdr org-export-table-header-tags
))
2150 (concat (format (car org-export-table-data-tags
) "") x
2151 (cdr org-export-table-data-tags
))))
2155 (setq field-buffer nil
)))
2157 (throw 'next-line t
)))
2158 ;; Break the line into fields and store the fields
2159 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2161 (setq field-buffer
(mapcar
2163 (concat x
"<br/>" (pop fields
)))
2165 (setq field-buffer fields
))))
2166 (setq html
(concat html
"</table>\n"))
2169 (defun org-format-table-table-html-using-table-generate-source (lines
2172 "Format a table into html, using `table-generate-source' from table.el.
2173 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2175 When SPANNED-ONLY is nil, all table.el tables are exported. When
2176 SPANNED-ONLY is non-nil, only tables with either row or column
2179 This routine returns the generated source or nil as appropriate.
2181 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2182 for further information."
2184 (with-current-buffer (get-buffer-create " org-tmp1 ")
2186 (insert (mapconcat 'identity lines
"\n"))
2187 (goto-char (point-min))
2188 (if (not (re-search-forward "|[^+]" nil t
))
2189 (error "Error processing table"))
2190 (table-recognize-table)
2191 (when (or (not spanned-only
)
2192 (let* ((dim (table-query-dimension))
2193 (c (nth 4 dim
)) (r (nth 5 dim
)) (cells (nth 6 dim
)))
2194 (not (= (* c r
) cells
))))
2195 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2196 (table-generate-source 'html
" org-tmp2 ")
2197 (set-buffer " org-tmp2 ")
2198 (buffer-substring (point-min) (point-max)))))
2200 (defun org-export-splice-style (style extra
)
2201 "Splice EXTRA into STYLE, just before \"</style>\"."
2202 (if (and (stringp extra
)
2203 (string-match "\\S-" extra
)
2204 (string-match "</style>" style
))
2205 (concat (substring style
0 (match-beginning 0))
2207 (substring style
(match-beginning 0)))
2210 (defun org-html-handle-time-stamps (s)
2211 "Format time stamps in string S, or remove them."
2214 (while (string-match org-maybe-keyword-time-regexp s
)
2215 (or b
(setq b
(substring s
0 (match-beginning 0))))
2217 r
(substring s
0 (match-beginning 0))
2218 " @<span class=\"timestamp-wrapper\">"
2220 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2221 (match-string 1 s
)))
2222 (format " @<span class=\"timestamp\">%s@</span>"
2224 (org-translate-time (match-string 3 s
)) 1 -
1))
2226 s
(substring s
(match-end 0))))
2227 ;; Line break if line started and ended with time stamp stuff
2230 (setq r
(concat r s
))
2231 (unless (string-match "\\S-" (concat b s
))
2232 (setq r
(concat r
"@<br/>")))
2235 (defvar htmlize-buffer-places
) ; from htmlize.el
2236 (defun org-export-htmlize-region-for-paste (beg end
)
2237 "Convert the region to HTML, using htmlize.el.
2238 This is much like `htmlize-region-for-paste', only that it uses
2239 the settings define in the org-... variables."
2240 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2241 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2242 (htmlbuf (htmlize-region beg end
)))
2244 (with-current-buffer htmlbuf
2245 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2246 (plist-get htmlize-buffer-places
'content-end
)))
2247 (kill-buffer htmlbuf
))))
2250 (defun org-export-htmlize-generate-css ()
2251 "Create the CSS for all font definitions in the current Emacs session.
2252 Use this to create face definitions in your CSS style file that can then
2253 be used by code snippets transformed by htmlize.
2254 This command just produces a buffer that contains class definitions for all
2255 faces used in the current Emacs session. You can copy and paste the ones you
2256 need into your CSS file.
2258 If you then set `org-export-htmlize-output-type' to `css', calls to
2259 the function `org-export-htmlize-region-for-paste' will produce code
2260 that uses these same face definitions."
2263 (and (get-buffer "*html*") (kill-buffer "*html*"))
2265 (let ((fl (face-list))
2266 (htmlize-css-name-prefix "org-")
2267 (htmlize-output-type 'css
)
2269 (while (setq f
(pop fl
)
2270 i
(and f
(face-attribute f
:inherit
)))
2271 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2272 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2273 (htmlize-region (point-min) (point-max))))
2274 (org-pop-to-buffer-same-window "*html*")
2275 (goto-char (point-min))
2276 (if (re-search-forward "<style" nil t
)
2277 (delete-region (point-min) (match-beginning 0)))
2278 (if (re-search-forward "</style>" nil t
)
2279 (delete-region (1+ (match-end 0)) (point-max)))
2280 (beginning-of-line 1)
2281 (if (looking-at " +") (replace-match ""))
2282 (goto-char (point-min)))
2284 (defun org-html-protect (s)
2285 "Convert characters to HTML equivalent.
2286 Possible conversions are set in `org-export-html-protect-char-alist'."
2287 (let ((cl org-export-html-protect-char-alist
) c
)
2288 (while (setq c
(pop cl
))
2290 (while (string-match (car c
) s start
)
2291 (setq s
(replace-match (cdr c
) t t s
)
2292 start
(1+ (match-beginning 0))))))
2295 (defun org-html-expand (string)
2296 "Prepare STRING for HTML export. Apply all active conversions.
2297 If there are links in the string, don't modify these."
2298 (let* ((re (concat org-bracket-link-regexp
"\\|"
2299 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2301 (while (setq m
(string-match re string
))
2302 (setq s
(substring string
0 m
)
2303 l
(match-string 0 string
)
2304 string
(substring string
(match-end 0)))
2305 (push (org-html-do-expand s
) res
)
2307 (push (org-html-do-expand string
) res
)
2308 (apply 'concat
(nreverse res
))))
2310 (defun org-html-do-expand (s)
2311 "Apply all active conversions to translate special ASCII to HTML."
2312 (setq s
(org-html-protect s
))
2313 (if org-export-html-expand
2314 (while (string-match "@<\\([^&]*\\)>" s
)
2315 (setq s
(replace-match "<\\1>" t nil s
))))
2316 (if org-export-with-emphasize
2317 (setq s
(org-export-html-convert-emphasize s
)))
2318 (if org-export-with-special-strings
2319 (setq s
(org-export-html-convert-special-strings s
)))
2320 (if org-export-with-sub-superscripts
2321 (setq s
(org-export-html-convert-sub-super s
)))
2322 (if org-export-with-TeX-macros
2323 (let ((start 0) wd rep
)
2324 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2326 (if (get-text-property (match-beginning 0) 'org-protected s
)
2327 (setq start
(match-end 0))
2328 (setq wd
(match-string 1 s
))
2329 (if (setq rep
(org-entity-get-representation wd
'html
))
2330 (setq s
(replace-match rep t t s
))
2331 (setq start
(+ start
(length wd
))))))))
2334 (defun org-export-html-convert-special-strings (string)
2335 "Convert special characters in STRING to HTML."
2336 (let ((all org-export-html-special-string-regexps
)
2338 (while (setq a
(pop all
))
2339 (setq re
(car a
) rpl
(cdr a
) start
0)
2340 (while (string-match re string start
)
2341 (if (get-text-property (match-beginning 0) 'org-protected string
)
2342 (setq start
(match-end 0))
2343 (setq string
(replace-match rpl t nil string
)))))
2346 (defun org-export-html-convert-sub-super (string)
2347 "Convert sub- and superscripts in STRING to HTML."
2348 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2349 (while (string-match org-match-substring-regexp string s
)
2351 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2352 ((get-text-property (match-beginning 2) 'org-protected string
)
2353 (setq s
(match-end 2)))
2355 (setq s
(match-end 1)
2356 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2357 c
(or (match-string 8 string
)
2358 (match-string 6 string
)
2359 (match-string 5 string
))
2360 string
(replace-match
2361 (concat (match-string 1 string
)
2362 "<" key
">" c
"</" key
">")
2364 (while (string-match "\\\\\\([_^]\\)" string
)
2365 (setq string
(replace-match (match-string 1 string
) t t string
)))
2368 (defun org-export-html-convert-emphasize (string)
2371 (while (string-match org-emph-re string s
)
2373 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2374 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2375 (setq s
(match-beginning 0)
2378 (match-string 1 string
)
2379 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2380 (match-string 4 string
)
2381 (nth 3 (assoc (match-string 3 string
)
2382 org-emphasis-alist
))
2383 (match-string 5 string
))
2384 string
(replace-match rpl t t string
)
2385 s
(+ s
(- (length rpl
) 2)))
2389 (defun org-open-par ()
2390 "Insert <p>, but first close previous paragraph if any."
2391 (org-close-par-maybe)
2393 (setq org-par-open t
))
2394 (defun org-close-par-maybe ()
2395 "Close paragraph if there is one open."
2398 (setq org-par-open nil
)))
2399 (defun org-close-li (&optional type
)
2400 "Close <li> if necessary."
2401 (org-close-par-maybe)
2402 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2404 (defvar body-only
) ; dynamically scoped into this.
2405 (defun org-html-level-start (level title umax with-toc head-count
&optional opt-plist
)
2406 "Insert a new level in HTML export.
2407 When TITLE is nil, just close all open levels."
2408 (org-close-par-maybe)
2409 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2410 (extra-targets (and target
2411 (assoc target org-export-target-aliases
)))
2412 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2413 (preferred (and target
2414 (cdr (assoc target org-export-preferred-target-alist
))))
2416 (num (plist-get opt-plist
:section-numbers
))
2417 snumber snu href suffix
)
2418 (setq extra-targets
(remove (or preferred target
) extra-targets
))
2420 (mapconcat (lambda (x)
2421 (setq x
(org-solidify-link-text
2422 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2423 (format "<a name=\"%s\" id=\"%s\"></a>"
2428 (if (aref org-levels-open
(1- l
))
2430 (org-html-level-close l umax
)
2431 (aset org-levels-open
(1- l
) nil
)))
2434 ;; If title is nil, this means this function is called to close
2435 ;; all levels, so the rest is done only if title is given
2436 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2437 (setq title
(replace-match
2438 (if org-export-with-tags
2441 " <span class=\"tag\">"
2444 (format "<span class=\"%s\">%s</span>"
2445 (org-export-html-get-tag-class-name x
)
2447 (org-split-string (match-string 1 title
) ":")
2454 (if (aref org-levels-open
(1- level
))
2458 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2459 extra-targets title
"<br/>\n")
2460 (insert "<li>" title
"<br/>\n")))
2461 (aset org-levels-open
(1- level
) t
)
2462 (org-close-par-maybe)
2464 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2465 extra-targets title
"<br/>\n")
2466 (insert "<ul>\n<li>" title
"<br/>\n"))))
2467 (aset org-levels-open
(1- level
) t
)
2468 (setq snumber
(org-section-number level
)
2469 snu
(replace-regexp-in-string "\\." "-" snumber
))
2470 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2471 (if (and num
(not body-only
))
2473 (format "<span class=\"section-number-%d\">%s</span>"
2477 ;; fix up num to take into
2478 ;; account the top-level
2480 (>= (+ num org-export-html-toplevel-hlevel -
1)
2486 (unless (= head-count
1) (insert "\n</div>\n"))
2487 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2488 (setq suffix
(org-solidify-link-text (or href snu
)))
2489 (setq href
(org-solidify-link-text (or href
(concat "sec-" snu
))))
2490 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
2491 suffix level
(if extra-class
(concat " " extra-class
) "")
2494 title level level suffix
))
2497 (defun org-export-html-get-tag-class-name (tag)
2498 "Turn tag into a valid class name.
2499 Replaces invalid characters with \"_\" and then prepends a prefix."
2501 (while (string-match "[^a-zA-Z0-9_]" tag
)
2502 (setq tag
(replace-match "_" t t tag
))))
2503 (concat org-export-html-tag-class-prefix tag
))
2505 (defun org-export-html-get-todo-kwd-class-name (kwd)
2506 "Turn todo keyword into a valid class name.
2507 Replaces invalid characters with \"_\" and then prepends a prefix."
2509 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2510 (setq kwd
(replace-match "_" t t kwd
))))
2511 (concat org-export-html-todo-kwd-class-prefix kwd
))
2513 (defun org-html-level-close (level max-outline-level
)
2514 "Terminate one level in HTML export."
2515 (if (<= level max-outline-level
)
2518 (insert "</ul>\n")))
2520 (defun org-html-export-list-line (line pos struct prevs
)
2521 "Insert list syntax in export buffer. Return LINE, maybe modified.
2523 POS is the item position or line position the line had before
2524 modifications to buffer. STRUCT is the list structure. PREVS is
2525 the alist of previous items."
2528 ;; Translate type of list containing POS to "d", "o" or
2530 (lambda (pos struct prevs
)
2531 (let ((type (org-list-get-list-type pos struct prevs
)))
2533 ((eq 'ordered type
) "o")
2534 ((eq 'descriptive type
) "d")
2538 ;; Return list of all items and sublists ending at POS, in
2544 (let ((end (nth 6 e
))
2547 ((= end pos
) (push item out
))
2548 ((>= item pos
) (throw 'exit nil
)))))
2551 ;; First close any previous item, or list, ending at POS.
2553 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2554 (first-item (org-list-get-list-begin e struct prevs
))
2555 (type (funcall get-type first-item struct prevs
)))
2556 (org-close-par-maybe)
2557 ;; Ending for every item
2559 ;; We're ending last item of the list: end list.
2561 (insert (format "</%sl>\n" type
))
2563 (funcall get-closings pos
))
2565 ;; At an item: insert appropriate tags in export buffer.
2568 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2569 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
2570 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2571 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2573 (let* ((checkbox (match-string 3 line
))
2574 (desc-tag (or (match-string 4 line
) "???"))
2575 (body (or (match-string 5 line
) ""))
2576 (list-beg (org-list-get-list-begin pos struct prevs
))
2577 (firstp (= list-beg pos
))
2578 ;; Always refer to first item to determine list type, in
2579 ;; case list is ill-formed.
2580 (type (funcall get-type list-beg struct prevs
))
2581 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2583 ((not count-tmp
) nil
)
2584 ((string-match "[A-Za-z]" count-tmp
)
2585 (- (string-to-char (upcase count-tmp
)) 64))
2586 ((string-match "[0-9]+" count-tmp
)
2589 (org-close-par-maybe)
2590 (insert (format "<%sl>\n" type
)))
2593 (format "<dt>%s</dt><dd>" desc-tag
))
2594 ((and (equal type
"o") counter
)
2595 (format "<li value=\"%s\">" counter
))
2597 ;; If line had a checkbox, some additional modification is required.
2602 ((string-match "X" checkbox
) "<code>[X]</code> ")
2603 ((string-match " " checkbox
) "<code>[ ]</code> ")
2604 (t "<code>[-]</code> "))
2606 ;; Return modified line
2608 ;; At a list ender: go to next line (side-effects only).
2609 ((equal "ORG-LIST-END-MARKER" line
) (throw 'nextline nil
))
2610 ;; Not at an item: return line unchanged (side-effects only).
2616 ;;; org-html.el ends here