1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004-2012 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 (require 'format-spec
)
32 (eval-when-compile (require 'cl
))
34 (declare-function org-id-find-id-file
"org-id" (id))
35 (declare-function htmlize-region
"ext:htmlize" (beg end
))
36 (declare-function org-pop-to-buffer-same-window
37 "org-compat" (&optional buffer-or-name norecord label
))
39 (defgroup org-export-html nil
40 "Options specific for HTML export of Org-mode files."
41 :tag
"Org Export HTML"
44 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
45 <h2 class=\"footnotes\">%s: </h2>
46 <div id=\"text-footnotes\">
50 "Format for the footnotes section.
51 Should contain a two instances of %s. The first will be replaced with the
52 language-specific word for \"Footnotes\", the second one will be replaced
53 by the footnotes themselves."
54 :group
'org-export-html
57 (defcustom org-export-html-footnote-format
"<sup>%s</sup>"
58 "The format for the footnote reference.
59 %s will be replaced by the footnote reference itself."
60 :group
'org-export-html
64 (defcustom org-export-html-footnote-separator
"<sup>, </sup>"
65 "Text used to separate footnotes."
66 :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
257 :type
'(list :greedy t
258 (list :tag
"path (the path from where to load MathJax.js)"
259 (const :format
" " path
) (string))
260 (list :tag
"scale (scaling for the displayed math)"
261 (const :format
" " scale
) (string))
262 (list :tag
"align (alignment of displayed equations)"
263 (const :format
" " align
) (string))
264 (list :tag
"indent (indentation with left or right alignment)"
265 (const :format
" " indent
) (string))
266 (list :tag
"mathml (should MathML display be used is possible)"
267 (const :format
" " mathml
) (boolean))))
269 (defun org-export-html-mathjax-config (template options in-buffer
)
270 "Insert the user setup into the matchjax template."
271 (let (name val
(yes " ") (no "// ") x
)
274 (setq name
(car e
) val
(nth 1 e
))
275 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
276 (setq val
(car (read-from-string
277 (substring in-buffer
(match-end 0))))))
278 (if (not (stringp val
)) (setq val
(format "%s" val
)))
279 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
280 (setq template
(replace-match val t t template
))))
282 (setq val
(nth 1 (assq 'mathml options
)))
283 (if (string-match (concat "\\<mathml:") in-buffer
)
284 (setq val
(car (read-from-string
285 (substring in-buffer
(match-end 0))))))
286 ;; Exchange prefixes depending on mathml setting
287 (if (not val
) (setq x yes yes no no x
))
288 ;; Replace cookies to turn on or off the config/jax lines
289 (if (string-match ":MMLYES:" template
)
290 (setq template
(replace-match yes t t template
)))
291 (if (string-match ":MMLNO:" template
)
292 (setq template
(replace-match no t t template
)))
293 ;; Return the modified template
296 (defcustom org-export-html-mathjax-template
297 "<script type=\"text/javascript\" src=\"%PATH\">
298 <!--/*--><![CDATA[/*><!--*/
300 // Only one of the two following lines, depending on user settings
301 // First allows browser-native MathML display, second forces HTML/CSS
302 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
303 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
304 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
305 \"TeX/noUndefined.js\"],
307 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
308 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
309 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
310 ignoreClass: \"tex2jax_ignore\",
311 processEscapes: false,
312 processEnvironments: true,
315 showProcessingMessages: true,
316 displayAlign: \"%ALIGN\",
317 displayIndent: \"%INDENT\",
321 availableFonts: [\"STIX\",\"TeX\"],
322 preferredFont: \"TeX\",
338 "The MathJax setup for XHTML files."
339 :group
'org-export-html
343 (defcustom org-export-html-tag-class-prefix
""
344 "Prefix to class names for TODO keywords.
345 Each tag gets a class given by the tag itself, with this prefix.
346 The default prefix is empty because it is nice to just use the keyword
347 as a class name. But if you get into conflicts with other, existing
348 CSS classes, then this prefix can be very useful."
349 :group
'org-export-html
352 (defcustom org-export-html-todo-kwd-class-prefix
""
353 "Prefix to class names for TODO keywords.
354 Each TODO keyword gets a class given by the keyword itself, with this prefix.
355 The default prefix is empty because it is nice to just use the keyword
356 as a class name. But if you get into conflicts with other, existing
357 CSS classes, then this prefix can be very useful."
358 :group
'org-export-html
361 (defcustom org-export-html-headline-anchor-format
"<a name=\"%s\" id=\"%s\"></a>"
362 "Format for anchors in HTML headlines.
363 It requires to %s: both will be replaced by the anchor referring
364 to the headline (e.g. \"sec-2\"). When set to `nil', don't insert
365 HTML anchors in headlines."
366 :group
'org-export-html
370 (defcustom org-export-html-preamble t
371 "Non-nil means insert a preamble in HTML export.
373 When `t', insert a string as defined by one of the formatting
374 strings in `org-export-html-preamble-format'. When set to a
375 string, this string overrides `org-export-html-preamble-format'.
376 When set to a function, apply this function and insert the
377 returned string. The function takes no argument, but you can
378 use `opt-plist' to access the current export options.
380 Setting :html-preamble in publishing projects will take
381 precedence over this variable."
382 :group
'org-export-html
383 :type
'(choice (const :tag
"No preamble" nil
)
384 (const :tag
"Default preamble" t
)
385 (string :tag
"Custom format string")
386 (function :tag
"Function (must return a string)")))
388 (defcustom org-export-html-preamble-format
'(("en" ""))
389 "Alist of languages and format strings for the HTML preamble.
391 The first element of each list is the language code, as used for
392 the #+LANGUAGE keyword.
394 The second element of each list is a format string to format the
395 preamble itself. This format string can contain these elements:
397 %t stands for the title.
398 %a stands for the author's name.
399 %e stands for the author's email.
400 %d stands for the date.
402 If you need to use a \"%\" character, you need to escape it
404 :group
'org-export-html
408 (defcustom org-export-html-postamble
'auto
409 "Non-nil means insert a postamble in HTML export.
411 When `t', insert a string as defined by the formatting string in
412 `org-export-html-postamble-format'. When set to a string, this
413 string overrides `org-export-html-postamble-format'. When set to
414 'auto, discard `org-export-html-postamble-format' and honor
415 `org-export-author/email/creator-info' variables. When set to a
416 function, apply this function and insert the returned string.
417 The function takes no argument, but you can use `opt-plist' to
418 access the current export options.
420 Setting :html-postamble in publishing projects will take
421 precedence over this variable."
422 :group
'org-export-html
423 :type
'(choice (const :tag
"No postamble" nil
)
424 (const :tag
"Auto preamble" 'auto
)
425 (const :tag
"Default format string" t
)
426 (string :tag
"Custom format string")
427 (function :tag
"Function (must return a string)")))
429 (defcustom org-export-html-postamble-format
430 '(("en" "<p class=\"author\">Author: %a (%e)</p>
431 <p class=\"date\">Date: %d</p>
432 <p class=\"creator\">Generated by %c</p>
433 <p class=\"xhtml-validation\">%v</p>
435 "Alist of languages and format strings for the HTML postamble.
437 The first element of each list is the language code, as used for
438 the #+LANGUAGE keyword.
440 The second element of each list is a format string to format the
441 postamble itself. This format string can contain these elements:
443 %a stands for the author's name.
444 %e stands for the author's email.
445 %d stands for the date.
446 %c will be replaced by information about Org/Emacs versions.
447 %v will be replaced by `org-export-html-validation-link'.
449 If you need to use a \"%\" character, you need to escape it
451 :group
'org-export-html
455 (defcustom org-export-html-home
/up-format
456 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
457 <a accesskey=\"h\" href=\"%s\"> UP </a>
459 <a accesskey=\"H\" href=\"%s\"> HOME </a>
461 "Snippet used to insert the HOME and UP links.
462 This is a format string, the first %s will receive the UP link,
463 the second the HOME link. If both `org-export-html-link-up' and
464 `org-export-html-link-home' are empty, the entire snippet will be
466 :group
'org-export-html
469 (defcustom org-export-html-toplevel-hlevel
2
470 "The <H> level for level 1 headings in HTML export.
471 This is also important for the classes that will be wrapped around headlines
472 and outline structure. If this variable is 1, the top-level headlines will
473 be <h1>, and the corresponding classes will be outline-1, section-number-1,
474 and outline-text-1. If this is 2, all of these will get a 2 instead.
475 The default for this variable is 2, because we use <h1> for formatting the
477 :group
'org-export-html
480 (defcustom org-export-html-link-org-files-as-html t
481 "Non-nil means make file links to `file.org' point to `file.html'.
482 When org-mode is exporting an org-mode file to HTML, links to
483 non-html files are directly put into a href tag in HTML.
484 However, links to other Org-mode files (recognized by the
485 extension `.org.) should become links to the corresponding html
486 file, assuming that the linked org-mode file will also be
488 When nil, the links still point to the plain `.org' file."
489 :group
'org-export-html
492 (defcustom org-export-html-inline-images
'maybe
493 "Non-nil means inline images into exported HTML pages.
494 This is done using an <img> tag. When nil, an anchor with href is used to
495 link to the image. If this option is `maybe', then images in links with
496 an empty description will be inlined, while images with a description will
498 :group
'org-export-html
499 :type
'(choice (const :tag
"Never" nil
)
500 (const :tag
"Always" t
)
501 (const :tag
"When there is no description" maybe
)))
503 (defcustom org-export-html-inline-image-extensions
504 '("png" "jpeg" "jpg" "gif" "svg")
505 "Extensions of image files that can be inlined into HTML."
506 :group
'org-export-html
507 :type
'(repeat (string :tag
"Extension")))
509 (defcustom org-export-html-table-tag
510 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
511 "The HTML tag that is used to start a table.
512 This must be a <table> tag, but you may change the options like
513 borders and spacing."
514 :group
'org-export-html
517 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
518 "The opening tag for table header fields.
519 This is customizable so that alignment options can be specified.
520 The first %s will be filled with the scope of the field, either row or col.
521 The second %s will be replaced by a style entry to align the field.
522 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
523 See also the variable `org-export-html-table-align-individual-fields'."
524 :group
'org-export-tables
525 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
527 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
528 "The opening tag for table data fields.
529 This is customizable so that alignment options can be specified.
530 The first %s will be filled with the scope of the field, either row or col.
531 The second %s will be replaced by a style entry to align the field.
532 See also the variable `org-export-html-table-align-individual-fields'."
533 :group
'org-export-tables
534 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
536 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
537 "The opening tag for table data fields.
538 This is customizable so that alignment options can be specified.
539 Instead of strings, these can be Lisp forms that will be evaluated
540 for each row in order to construct the table row tags. During evaluation,
541 the variable `head' will be true when this is a header line, nil when this
542 is a body line. And the variable `nline' will contain the line number,
543 starting from 1 in the first header line. For example
545 (setq org-export-table-row-tags
548 (if (= (mod nline 2) 1)
549 \"<tr class=\\\"tr-odd\\\">\"
550 \"<tr class=\\\"tr-even\\\">\"))
553 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
554 :group
'org-export-tables
556 (choice :tag
"Opening tag"
557 (string :tag
"Specify")
559 (choice :tag
"Closing tag"
560 (string :tag
"Specify")
563 (defcustom org-export-html-table-align-individual-fields t
564 "Non-nil means attach style attributes for alignment to each table field.
565 When nil, alignment will only be specified in the column tags, but this
566 is ignored by some browsers (like Firefox, Safari). Opera does it right
568 :group
'org-export-tables
572 (defcustom org-export-html-table-use-header-tags-for-first-column nil
573 "Non-nil means format column one in tables with header tags.
574 When nil, also column one will use data tags."
575 :group
'org-export-tables
578 (defcustom org-export-html-validation-link
579 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
580 "Link to HTML validation service."
581 :group
'org-export-html
584 ;; FIXME Obsolete since Org 7.7
585 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
586 (defvar org-export-html-with-timestamp nil
587 "If non-nil, write container for HTML-helper-mode timestamp.")
589 ;; FIXME Obsolete since Org 7.7
590 (defvar org-export-html-html-helper-timestamp
591 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
592 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
594 (defcustom org-export-html-protect-char-alist
598 "Alist of characters to be converted by `org-html-protect'."
599 :group
'org-export-html
601 :type
'(repeat (cons (string :tag
"Character")
602 (string :tag
"HTML equivalent"))))
604 (defgroup org-export-htmlize nil
605 "Options for processing examples with htmlize.el."
606 :tag
"Org Export Htmlize"
607 :group
'org-export-html
)
609 (defcustom org-export-htmlize-output-type
'inline-css
610 "Output type to be used by htmlize when formatting code snippets.
611 Choices are `css', to export the CSS selectors only, or `inline-css', to
612 export the CSS attribute values inline in the HTML. We use as default
613 `inline-css', in order to make the resulting HTML self-containing.
615 However, this will fail when using Emacs in batch mode for export, because
616 then no rich font definitions are in place. It will also not be good if
617 people with different Emacs setup contribute HTML files to a website,
618 because the fonts will represent the individual setups. In these cases,
619 it is much better to let Org/Htmlize assign classes only, and to use
620 a style file to define the look of these classes.
621 To get a start for your css file, start Emacs session and make sure that
622 all the faces you are interested in are defined, for example by loading files
623 in all modes you want. Then, use the command
624 \\[org-export-htmlize-generate-css] to extract class definitions."
625 :group
'org-export-htmlize
626 :type
'(choice (const css
) (const inline-css
)))
628 (defcustom org-export-htmlize-css-font-prefix
"org-"
629 "The prefix for CSS class names for htmlize font specifications."
630 :group
'org-export-htmlize
633 (defcustom org-export-htmlized-org-css-url nil
634 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
635 Normally when creating an htmlized version of an Org buffer, htmlize will
636 create CSS to define the font colors. However, this does not work when
637 converting in batch mode, and it also can look bad if different people
638 with different fontification setup work on the same website.
639 When this variable is non-nil, creating an htmlized version of an Org buffer
640 using `org-export-as-org' will remove the internal CSS section and replace it
641 with a link to this URL."
642 :group
'org-export-htmlize
644 (const :tag
"Keep internal css" nil
)
645 (string :tag
"URL or local href")))
647 ;; FIXME: The following variable is obsolete since Org 7.7 but is
648 ;; still declared and checked within code for compatibility reasons.
649 ;; Use the custom variables `org-export-html-divs' instead.
650 (defvar org-export-html-content-div
"content"
651 "The name of the container DIV that holds all the page contents.
653 This variable is obsolete since Org version 7.7.
654 Please set `org-export-html-divs' instead.")
656 (defcustom org-export-html-divs
'("preamble" "content" "postamble")
657 "The name of the main divs for HTML export.
658 This is a list of three strings, the first one for the preamble
659 DIV, the second one for the content DIV and the third one for the
661 :group
'org-export-html
664 (string :tag
" Div for the preamble:")
665 (string :tag
" Div for the content:")
666 (string :tag
"Div for the postamble:")))
668 (defcustom org-export-html-date-format-string
"%Y-%m-%dT%R%z"
669 "Format string to format the date and time.
671 The default is an extended format of the ISO 8601 specification."
672 :group
'org-export-html
678 (defvar org-export-html-after-blockquotes-hook nil
679 "Hook run during HTML export, after blockquote, verse, center are done.")
681 (defvar org-export-html-final-hook nil
682 "Hook run at the end of HTML export, in the new buffer.")
686 (defun org-export-html-preprocess (parameters)
687 "Convert LaTeX fragments to images."
688 (when (and org-current-export-file
689 (plist-get parameters
:LaTeX-fragments
))
691 (concat "ltxpng/" (file-name-sans-extension
692 (file-name-nondirectory
693 org-current-export-file
)))
694 org-current-export-dir nil
"Creating LaTeX image %s"
697 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
698 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
699 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
700 ((eq (plist-get parameters
:LaTeX-fragments
) 'imagemagick
) 'imagemagick
)
701 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
703 (goto-char (point-min))
705 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
706 (org-if-unprotected-at (match-beginning 1)
707 (setq label
(match-string 1))
709 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
710 (setq l1
(substring label
(match-beginning 1)))
712 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
715 (defun org-export-as-html-and-open (arg)
716 "Export the outline as HTML and immediately open it with a browser.
717 If there is an active region, export only the region.
718 The prefix ARG specifies how many levels of the outline should become
719 headlines. The default is 3. Lower levels will become bulleted lists."
721 (org-export-as-html arg
'hidden
)
722 (org-open-file buffer-file-name
)
723 (when org-export-kill-product-buffer-when-displayed
724 (kill-buffer (current-buffer))))
727 (defun org-export-as-html-batch ()
728 "Call the function `org-export-as-html'.
729 This function can be used in batch processing as:
731 --load=$HOME/lib/emacs/org.el
732 --eval \"(setq org-export-headline-levels 2)\"
733 --visit=MyFile --funcall org-export-as-html-batch"
734 (org-export-as-html org-export-headline-levels
'hidden
))
737 (defun org-export-as-html-to-buffer (arg)
738 "Call `org-export-as-html` with output to a temporary buffer.
739 No file is created. The prefix ARG is passed through to `org-export-as-html'."
741 (org-export-as-html arg nil nil
"*Org HTML Export*")
742 (when org-export-show-temporary-export-buffer
743 (switch-to-buffer-other-window "*Org HTML Export*")))
746 (defun org-replace-region-by-html (beg end
)
747 "Assume the current region has org-mode syntax, and convert it to HTML.
748 This can be used in any buffer. For example, you could write an
749 itemized list in org-mode syntax in an HTML buffer and then use this
750 command to convert it."
752 (let (reg html buf pop-up-frames
)
753 (save-window-excursion
754 (if (derived-mode-p 'org-mode
)
755 (setq html
(org-export-region-as-html
757 (setq reg
(buffer-substring beg end
)
758 buf
(get-buffer-create "*Org tmp*"))
759 (with-current-buffer buf
763 (setq html
(org-export-region-as-html
764 (point-min) (point-max) t
'string
)))
766 (delete-region beg end
)
770 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
771 "Convert region from BEG to END in org-mode buffer to HTML.
772 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
773 contents, and only produce the region of converted text, useful for
774 cut-and-paste operations.
775 If BUFFER is a buffer or a string, use/create that buffer as a target
776 of the converted HTML. If BUFFER is the symbol `string', return the
777 produced HTML as a string and leave not buffer behind. For example,
778 a Lisp program could call this function in the following way:
780 (setq html (org-export-region-as-html beg end t 'string))
782 When called interactively, the output buffer is selected, and shown
783 in a window. A non-interactive call will only return the buffer."
785 (when (org-called-interactively-p 'any
)
786 (setq buffer
"*Org HTML Export*"))
787 (let ((transient-mark-mode t
) (zmacs-regions t
)
789 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
791 (set-mark (point)) ;; to activate the region
793 (setq rtn
(org-export-as-html
796 (if (fboundp 'deactivate-mark
) (deactivate-mark))
797 (if (and (org-called-interactively-p 'any
) (bufferp rtn
))
798 (switch-to-buffer-other-window rtn
)
801 (defvar html-table-tag nil
) ; dynamically scoped into this.
802 (defvar org-par-open nil
)
804 ;;; org-html-cvt-link-fn
805 (defconst org-html-cvt-link-fn
807 "Function to convert link URLs to exportable URLs.
808 Takes two arguments, TYPE and PATH.
809 Returns exportable url as (TYPE PATH), or nil to signal that it
810 didn't handle this case.
811 Intended to be locally bound around a call to `org-export-as-html'." )
813 (defun org-html-cvt-org-as-html (opt-plist type path
)
814 "Convert an org filename to an equivalent html filename.
815 If TYPE is not file, just return `nil'.
816 See variable `org-export-html-link-org-files-as-html'"
820 org-export-html-link-org-files-as-html
821 (string= type
"file")
822 (string-match "\\.org$" path
)
827 (substring path
0 (match-beginning 0))
829 (plist-get opt-plist
:html-extension
)))))))
832 ;;; org-html-should-inline-p
833 (defun org-html-should-inline-p (filename descp
)
834 "Return non-nil if link FILENAME should be inlined.
835 The decision to inline the FILENAME link is based on the current
836 settings. DESCP is the boolean of whether there was a link
837 description. See variables `org-export-html-inline-images' and
838 `org-export-html-inline-image-extensions'."
840 org-export-html-inline-images
841 org-export-html-inline-image-extensions
))
842 (and (or (eq t org-export-html-inline-images
)
843 (and org-export-html-inline-images
(not descp
)))
845 filename org-export-html-inline-image-extensions
)))
847 ;;; org-html-make-link
848 (defun org-html-make-link (opt-plist type path fragment desc attr
851 OPT-PLIST is an options list.
852 TYPE is the device-type of the link (THIS://foo.html).
853 PATH is the path of the link (http://THIS#location).
854 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
855 DESC is the link description, if any.
856 ATTR is a string of other attributes of the \"a\" element.
857 MAY-INLINE-P allows inlining it as an image."
859 (declare (special org-par-open
))
861 (let* ((filename path
)
862 ;;First pass. Just sanity stuff.
865 ((string= type
"file")
868 ;;Substitute just if original path was absolute.
869 ;;(Otherwise path must remain relative)
870 (if (file-name-absolute-p path
)
871 (concat "file://" (expand-file-name path
))
875 (t (list type path
))))
877 ;;Second pass. Components converted so they can refer
881 (and org-html-cvt-link-fn
882 (apply org-html-cvt-link-fn
883 opt-plist components-1
))
884 (apply #'org-html-cvt-org-as-html
885 opt-plist components-1
)
887 (type (first components-2
))
888 (thefile (second components-2
)))
891 ;;Third pass. Build final link except for leading type
896 (string= type
"http")
897 (string= type
"https")
898 (string= type
"file")
899 (string= type
"coderef"))
901 (setq thefile
(concat thefile
"#" fragment
))))
905 ;;Final URL-build, for all types.
908 ((str (org-export-html-format-href thefile
)))
909 (if (and type
(not (or (string= "file" type
)
910 (string= "coderef" type
))))
911 (concat type
":" str
)
916 ;;Can't inline a URL with a fragment.
919 (message "image %s %s" thefile org-par-open
)
920 (org-export-html-format-image thefile org-par-open
))
922 "<a href=\"" thefile
"\"" (if attr
(concat " " attr
)) ">"
923 (org-export-html-format-desc desc
)
926 (defun org-html-handle-links (org-line opt-plist
)
927 "Return ORG-LINE with markup of Org mode links.
928 OPT-PLIST is the export options list."
930 (current-dir (if buffer-file-name
931 (file-name-directory buffer-file-name
)
933 (link-validate (plist-get opt-plist
:link-validation-function
))
935 rpl path attr desc descp desc1 desc2 link
)
936 (while (string-match org-bracket-link-analytic-regexp
++ org-line start
)
937 (setq start
(match-beginning 0))
938 (setq path
(save-match-data (org-link-unescape
939 (match-string 3 org-line
))))
941 ((match-end 2) (match-string 2 org-line
))
943 (or (file-name-absolute-p path
)
944 (string-match "^\\.\\.?/" path
)))
947 (setq path
(org-extract-attributes path
))
948 (setq attr
(get-text-property 0 'org-attributes path
))
949 (setq desc1
(if (match-end 5) (match-string 5 org-line
))
950 desc2
(if (match-end 2) (concat type
":" path
) path
)
951 descp
(and desc1
(not (equal desc1 desc2
)))
952 desc
(or desc1 desc2
))
953 ;; Make an image out of the description if that is so wanted
954 (when (and descp
(org-file-image-p
955 desc org-export-html-inline-image-extensions
))
957 (if (string-match "^file:" desc
)
958 (setq desc
(substring desc
(match-end 0)))))
959 (setq desc
(org-add-props
960 (concat "<img src=\"" desc
"\" alt=\""
961 (file-name-nondirectory desc
) "\"/>")
962 '(org-protected t
))))
964 ((equal type
"internal")
967 (if (= (string-to-char path
) ?
#)
975 (org-solidify-link-text
976 (save-match-data (org-link-unescape frag-0
))
979 ((and (equal type
"id")
980 (setq id-file
(org-id-find-id-file path
)))
981 ;; This is an id: link to another file (if it was the same file,
982 ;; it would have become an internal link...)
984 (setq id-file
(file-relative-name
986 (file-name-directory org-current-export-file
)))
988 (org-html-make-link opt-plist
990 (concat (if (org-uuidgen-p path
) "ID-") path
)
994 ((member type
'("http" "https"))
995 ;; standard URL, can inline as image
997 (org-html-make-link opt-plist
1001 (org-html-should-inline-p path descp
))))
1002 ((member type
'("ftp" "mailto" "news"))
1003 ;; standard URL, can't inline as image
1005 (org-html-make-link opt-plist
1011 ((string= type
"coderef")
1013 ((coderef-str (format "coderef-%s" path
))
1015 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1016 coderef-str coderef-str
)))
1018 (org-html-make-link opt-plist
1021 (org-export-get-coderef-format
1024 (cdr (assoc path org-export-code-refs
)))
1028 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
1029 ;; The link protocol has a function for format the link
1032 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
1034 ((string= type
"file")
1040 (string-match "::\\(.*\\)" path
)
1042 (replace-match "" t nil path
)
1043 (match-string 1 path
))
1046 ;;The proper path, without a fragment
1052 (second components
))
1054 ;;Check the fragment. If it can't be used as
1055 ;;target fragment we'll pass nil instead.
1059 (not (string-match "^[0-9]*$" fragment-0
))
1060 (not (string-match "^\\*" fragment-0
))
1061 (not (string-match "^/.*/$" fragment-0
)))
1062 (org-solidify-link-text
1063 (org-link-unescape fragment-0
))
1066 ;;Description minus "file:" and ".org"
1067 (if (string-match "^file:" desc
)
1069 ((desc-1 (replace-match "" t t desc
)))
1070 (if (string-match "\\.org$" desc-1
)
1071 (replace-match "" t t desc-1
)
1078 (functionp link-validate
)
1079 (not (funcall link-validate path-1 current-dir
)))
1081 (org-html-make-link opt-plist
1082 "file" path-1 fragment-1 desc-2 attr
1083 (org-html-should-inline-p path-1 descp
)))))))
1086 ;; just publish the path, as default
1087 (setq rpl
(concat "<i><" type
":"
1088 (save-match-data (org-link-unescape path
))
1090 (setq org-line
(replace-match rpl t t org-line
)
1091 start
(+ start
(length rpl
))))
1094 ;;; org-export-as-html
1096 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1099 (defun org-export-as-html (arg &optional hidden ext-plist
1100 to-buffer body-only pub-dir
)
1101 "Export the outline as a pretty HTML file.
1102 If there is an active region, export only the region. The prefix
1103 ARG specifies how many levels of the outline should become
1104 headlines. The default is 3. Lower levels will become bulleted
1105 lists. HIDDEN is obsolete and does nothing.
1106 EXT-PLIST is a property list with external parameters overriding
1107 org-mode's default settings, but still inferior to file-local
1108 settings. When TO-BUFFER is non-nil, create a buffer with that
1109 name and export to that buffer. If TO-BUFFER is the symbol
1110 `string', don't leave any buffer behind but just return the
1111 resulting HTML as a string. When BODY-ONLY is set, don't produce
1112 the file header and footer, simply return the content of
1113 <body>...</body>, without even the body tags themselves. When
1114 PUB-DIR is set, use this as the publishing directory."
1116 (run-hooks 'org-export-first-hook
)
1118 ;; Make sure we have a file name when we need it.
1119 (when (and (not (or to-buffer body-only
))
1120 (not buffer-file-name
))
1121 (if (buffer-base-buffer)
1122 (org-set-local 'buffer-file-name
1123 (with-current-buffer (buffer-base-buffer)
1125 (error "Need a file name to be able to export")))
1127 (message "Exporting...")
1128 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1129 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1130 (setq-default org-done-keywords org-done-keywords
)
1131 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1133 (org-export-process-option-filters
1134 (org-combine-plists (org-default-export-plist)
1136 (org-infile-export-plist))))
1137 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1138 (style (concat (if (plist-get opt-plist
:style-include-default
)
1139 org-export-html-style-default
)
1140 (plist-get opt-plist
:style
)
1141 (plist-get opt-plist
:style-extra
)
1143 (if (plist-get opt-plist
:style-include-scripts
)
1144 org-export-html-scripts
)))
1145 (html-extension (plist-get opt-plist
:html-extension
))
1146 valid thetoc have-headings first-heading-pos
1147 (odd org-odd-levels-only
)
1148 (region-p (org-region-active-p))
1149 (rbeg (and region-p
(region-beginning)))
1150 (rend (and region-p
(region-end)))
1152 (if (plist-get opt-plist
:ignore-subtree-p
)
1157 (and (org-at-heading-p)
1158 (>= (org-end-of-subtree t t
) rend
))))))
1159 (level-offset (if subtree-p
1162 (+ (funcall outline-level
)
1163 (if org-odd-levels-only
1 0)))
1165 (opt-plist (setq org-export-opt-plist
1167 (org-export-add-subtree-options opt-plist rbeg
)
1169 ;; The following two are dynamically scoped into other
1171 (org-current-export-dir
1172 (or pub-dir
(org-export-directory :html opt-plist
)))
1173 (org-current-export-file buffer-file-name
)
1174 (level 0) (org-line "") (origline "") txt todo
1177 (filename (if to-buffer nil
1180 (file-name-sans-extension
1182 (org-entry-get (region-beginning)
1183 "EXPORT_FILE_NAME" t
))
1184 (file-name-nondirectory buffer-file-name
)))
1186 (file-name-as-directory
1187 (or pub-dir
(org-export-directory :html opt-plist
))))))
1188 (current-dir (if buffer-file-name
1189 (file-name-directory buffer-file-name
)
1191 (auto-insert nil
); Avoid any auto-insert stuff for the new file
1192 (buffer (if to-buffer
1194 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
1195 (t (get-buffer-create to-buffer
)))
1196 (find-file-noselect filename
)))
1197 (org-levels-open (make-vector org-level-max nil
))
1198 (date (org-html-expand (plist-get opt-plist
:date
)))
1199 (author (org-html-expand (plist-get opt-plist
:author
)))
1200 (html-validation-link (or org-export-html-validation-link
""))
1201 (title (org-html-expand
1202 (or (and subtree-p
(org-export-get-title-from-subtree))
1203 (plist-get opt-plist
:title
)
1204 (and (not body-only
)
1206 (plist-get opt-plist
:skip-before-1st-heading
))
1207 (org-export-grab-title-from-buffer))
1208 (and buffer-file-name
1209 (file-name-sans-extension
1210 (file-name-nondirectory buffer-file-name
)))
1212 (link-up (and (plist-get opt-plist
:link-up
)
1213 (string-match "\\S-" (plist-get opt-plist
:link-up
))
1214 (plist-get opt-plist
:link-up
)))
1215 (link-home (and (plist-get opt-plist
:link-home
)
1216 (string-match "\\S-" (plist-get opt-plist
:link-home
))
1217 (plist-get opt-plist
:link-home
)))
1218 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1219 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1220 (quote-re0 (concat "^ *" org-quote-string
"\\( +\\|[ \t]*$\\)"))
1221 (quote-re (format org-heading-keyword-regexp-format
1226 (email (plist-get opt-plist
:email
))
1227 (language (plist-get opt-plist
:language
))
1228 (keywords (org-html-expand (plist-get opt-plist
:keywords
)))
1229 (description (org-html-expand (plist-get opt-plist
:description
)))
1230 (num (plist-get opt-plist
:section-numbers
))
1234 (coding-system (and (boundp 'buffer-file-coding-system
)
1235 buffer-file-coding-system
))
1236 (coding-system-for-write (or org-export-html-coding-system
1238 (save-buffer-coding-system (or org-export-html-coding-system
1240 (charset (and coding-system-for-write
1241 (fboundp 'coding-system-get
)
1242 (coding-system-get coding-system-for-write
1246 (if region-p
(region-beginning) (point-min))
1247 (if region-p
(region-end) (point-max))))
1248 (org-export-have-math nil
)
1249 (org-export-footnotes-seen nil
)
1250 (org-export-footnotes-data (org-footnote-all-labels 'with-defs
))
1253 (org-export-preprocess-string
1257 :skip-before-1st-heading
1258 (plist-get opt-plist
:skip-before-1st-heading
)
1259 :drawers
(plist-get opt-plist
:drawers
)
1260 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1261 :tasks
(plist-get opt-plist
:tasks
)
1262 :tags
(plist-get opt-plist
:tags
)
1263 :priority
(plist-get opt-plist
:priority
)
1264 :footnotes
(plist-get opt-plist
:footnotes
)
1265 :timestamps
(plist-get opt-plist
:timestamps
)
1267 (plist-get opt-plist
:archived-trees
)
1268 :select-tags
(plist-get opt-plist
:select-tags
)
1269 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1271 (plist-get opt-plist
:text
)
1273 (plist-get opt-plist
:LaTeX-fragments
))
1276 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
1277 (and org-export-have-math
1278 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
1280 (org-export-html-mathjax-config
1281 org-export-html-mathjax-template
1282 org-export-html-mathjax-options
1283 (or (plist-get opt-plist
:mathjax
) ""))
1286 table-buffer table-orig-buffer
1288 rpl path attr desc descp desc1 desc2 link
1290 footnotes footref-seen
1294 (let ((inhibit-read-only t
))
1296 (remove-text-properties (point-min) (point-max)
1297 '(:org-license-to-kill t
))))
1299 (message "Exporting...")
1301 (setq org-min-level
(org-get-min-level lines level-offset
))
1302 (setq org-last-level org-min-level
)
1303 (org-init-section-numbers)
1306 ((and date
(string-match "%" date
))
1307 (setq date
(format-time-string date
)))
1309 (t (setq date
(format-time-string org-export-html-date-format-string
))))
1311 ;; Get the language-dependent settings
1312 (setq lang-words
(or (assoc language org-export-language-setup
)
1313 (assoc "en" org-export-language-setup
)))
1315 ;; Switch to the output buffer
1317 (let ((inhibit-read-only t
)) (erase-buffer))
1319 (org-install-letbind)
1321 (and (fboundp 'set-buffer-file-coding-system
)
1322 (set-buffer-file-coding-system coding-system-for-write
))
1324 (let ((case-fold-search nil
)
1325 (org-odd-levels-only odd
))
1326 ;; create local variables for all options, to make sure all called
1327 ;; functions get the correct information
1329 (set (make-local-variable (nth 2 x
))
1330 (plist-get opt-plist
(car x
))))
1331 org-export-plist-vars
)
1332 (setq umax
(if arg
(prefix-numeric-value arg
)
1333 org-export-headline-levels
))
1334 (setq umax-toc
(if (integerp org-export-with-toc
)
1335 (min org-export-with-toc umax
)
1341 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1342 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1343 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
1346 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1347 <meta name=\"title\" content=\"%s\"/>
1348 <meta name=\"generator\" content=\"Org-mode\"/>
1349 <meta name=\"generated\" content=\"%s\"/>
1350 <meta name=\"author\" content=\"%s\"/>
1351 <meta name=\"description\" content=\"%s\"/>
1352 <meta name=\"keywords\" content=\"%s\"/>
1360 (or (and (stringp org-export-html-xml-declaration
)
1361 org-export-html-xml-declaration
)
1362 (cdr (assoc html-extension org-export-html-xml-declaration
))
1363 (cdr (assoc "html" org-export-html-xml-declaration
))
1366 (or charset
"iso-8859-1"))
1369 (or charset
"iso-8859-1")
1370 title date author description keywords
1373 (if (or link-up link-home
)
1375 (format org-export-html-home
/up-format
1376 (or link-up link-home
)
1377 (or link-home link-up
))
1381 ;; insert html preamble
1382 (when (plist-get opt-plist
:html-preamble
)
1383 (let ((html-pre (plist-get opt-plist
:html-preamble
))
1384 (html-pre-real-contents ""))
1385 (cond ((stringp html-pre
)
1386 (setq html-pre-real-contents
1387 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
1388 (?d .
,date
) (?e .
,email
)))))
1389 ((functionp html-pre
)
1390 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1391 (if (stringp (funcall html-pre
)) (insert (funcall html-pre
)))
1392 (insert "\n</div>\n"))
1394 (setq html-pre-real-contents
1396 (or (cadr (assoc (nth 0 lang-words
)
1397 org-export-html-preamble-format
))
1398 (cadr (assoc "en" org-export-html-preamble-format
)))
1399 `((?t .
,title
) (?a .
,author
)
1400 (?d .
,date
) (?e .
,email
))))))
1401 ;; don't output an empty preamble DIV
1402 (unless (and (functionp html-pre
)
1403 (equal html-pre-real-contents
""))
1404 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1405 (insert html-pre-real-contents
)
1406 (insert "\n</div>\n"))))
1408 ;; begin wrap around body
1409 (insert (format "\n<div id=\"%s\">"
1410 ;; FIXME org-export-html-content-div is obsolete since 7.7
1411 (or org-export-html-content-div
1412 (nth 1 org-export-html-divs
)))
1413 ;; FIXME this should go in the preamble but is here so
1414 ;; that org-infojs can still find it
1415 "\n<h1 class=\"title\">" title
"</h1>\n"))
1418 (if org-export-with-toc
1420 (push (format "<h%d>%s</h%d>\n"
1421 org-export-html-toplevel-hlevel
1423 org-export-html-toplevel-hlevel
)
1425 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1426 (push "<ul>\n<li>" thetoc
)
1429 #'(lambda (org-line)
1430 (if (and (string-match org-todo-line-regexp org-line
)
1431 (not (get-text-property 0 'org-protected org-line
)))
1432 ;; This is a headline
1434 (setq have-headings t
)
1435 (setq level
(- (match-end 1) (match-beginning 1)
1437 level
(org-tr-level level
)
1438 txt
(save-match-data
1440 (org-export-cleanup-toc-line
1441 (match-string 3 org-line
))))
1443 (or (and org-export-mark-todo-in-toc
1445 (not (member (match-string 2 org-line
)
1446 org-done-keywords
)))
1448 (and org-export-mark-todo-in-toc
1450 (org-search-todo-below
1451 org-line lines level
))))
1453 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1454 (setq txt
(replace-match
1455 " <span class=\"tag\">\\1</span>" t nil txt
)))
1456 (if (string-match quote-re0 txt
)
1457 (setq txt
(replace-match "" t t txt
)))
1458 (setq snumber
(org-section-number level
))
1459 (if (and num
(if (integerp num
)
1462 (setq txt
(concat snumber
" " txt
)))
1463 (if (<= level
(max umax umax-toc
))
1464 (setq head-count
(+ head-count
1)))
1465 (if (<= level umax-toc
)
1467 (if (> level org-last-level
)
1469 (setq cnt
(- level org-last-level
))
1470 (while (>= (setq cnt
(1- cnt
)) 0)
1471 (push "\n<ul>\n<li>" thetoc
))
1472 (push "\n" thetoc
)))
1473 (if (< level org-last-level
)
1475 (setq cnt
(- org-last-level level
))
1476 (while (>= (setq cnt
(1- cnt
)) 0)
1477 (push "</li>\n</ul>" thetoc
))
1478 (push "\n" thetoc
)))
1479 ;; Check for targets
1480 (while (string-match org-any-target-regexp org-line
)
1481 (setq org-line
(replace-match
1482 (concat "@<span class=\"target\">"
1483 (match-string 1 org-line
) "@</span> ")
1485 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1486 (setq txt
(replace-match "" t t txt
)))
1488 (replace-regexp-in-string
1489 "\\." "-" (format "sec-%s" snumber
)))
1490 (setq href
(org-solidify-link-text
1491 (or (cdr (assoc href
1492 org-export-preferred-target-alist
)) href
)))
1496 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1497 "</li>\n<li><a href=\"#%s\">%s</a>")
1500 (setq org-last-level level
)))))
1503 (while (> org-last-level
(1- org-min-level
))
1504 (setq org-last-level
(1- org-last-level
))
1505 (push "</li>\n</ul>\n" thetoc
))
1506 (push "</div>\n" thetoc
)
1507 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1510 (org-init-section-numbers)
1514 (while (setq org-line
(pop lines
) origline org-line
)
1517 ;; end of quote section?
1518 (when (and inquote
(string-match org-outline-regexp-bol org-line
))
1522 ;; inside a quote section?
1524 (insert (org-html-protect org-line
) "\n")
1525 (throw 'nextline nil
))
1527 ;; Fixed-width, verbatim lines (examples)
1528 (when (and org-export-with-fixed-width
1529 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" org-line
))
1532 (org-close-par-maybe)
1534 (insert "<pre class=\"example\">\n"))
1535 (insert (org-html-protect (match-string 3 org-line
)) "\n")
1536 (when (or (not lines
)
1537 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1542 (throw 'nextline nil
))
1545 (when (and (get-text-property 0 'org-protected org-line
)
1546 ;; Make sure it is the entire line that is protected
1547 (not (< (or (next-single-property-change
1548 0 'org-protected org-line
) 10000)
1549 (length org-line
))))
1550 (let (par (ind (get-text-property 0 'original-indentation org-line
)))
1551 (when (re-search-backward
1552 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1553 (setq par
(match-string 1))
1554 (replace-match "\\2\n"))
1555 (insert org-line
"\n")
1557 (or (= (length (car lines
)) 0)
1559 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1560 (or (= (length (car lines
)) 0)
1561 (get-text-property 0 'org-protected
(car lines
))))
1562 (insert (pop lines
) "\n"))
1563 (and par
(insert "<p>\n")))
1564 (throw 'nextline nil
))
1566 ;; Blockquotes, verse, and center
1567 (when (equal "ORG-BLOCKQUOTE-START" org-line
)
1568 (org-close-par-maybe)
1569 (insert "<blockquote>\n")
1571 (throw 'nextline nil
))
1572 (when (equal "ORG-BLOCKQUOTE-END" org-line
)
1573 (org-close-par-maybe)
1574 (insert "\n</blockquote>\n")
1576 (throw 'nextline nil
))
1577 (when (equal "ORG-VERSE-START" org-line
)
1578 (org-close-par-maybe)
1579 (insert "\n<p class=\"verse\">\n")
1580 (setq org-par-open t
)
1582 (throw 'nextline nil
))
1583 (when (equal "ORG-VERSE-END" org-line
)
1585 (setq org-par-open nil
)
1588 (throw 'nextline nil
))
1589 (when (equal "ORG-CENTER-START" org-line
)
1590 (org-close-par-maybe)
1591 (insert "\n<div style=\"text-align: center\">")
1593 (throw 'nextline nil
))
1594 (when (equal "ORG-CENTER-END" org-line
)
1595 (org-close-par-maybe)
1598 (throw 'nextline nil
))
1599 (run-hooks 'org-export-html-after-blockquotes-hook
)
1601 (let ((i (org-get-string-indentation org-line
)))
1603 (setq org-line
(concat (mapconcat 'identity
1604 (make-list (* 2 i
) "\\nbsp") "")
1605 " " (org-trim org-line
))))
1606 (unless (string-match "\\\\\\\\[ \t]*$" org-line
)
1607 (setq org-line
(concat org-line
"\\\\")))))
1609 ;; make targets to anchors
1611 (while (string-match
1612 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" org-line start
)
1614 ((get-text-property (match-beginning 1) 'org-protected org-line
)
1615 (setq start
(match-end 1)))
1617 (setq org-line
(replace-match
1619 "@<a name=\"%s\" id=\"%s\">@</a>"
1620 (org-solidify-link-text (match-string 1 org-line
))
1621 (org-solidify-link-text (match-string 1 org-line
)))
1623 ((and org-export-with-toc
(equal (string-to-char org-line
) ?
*))
1624 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1625 (setq org-line
(replace-match
1626 (concat "@<span class=\"target\">"
1627 (match-string 1 org-line
) "@</span> ")
1628 ;; (concat "@<i>" (match-string 1 org-line) "@</i> ")
1631 (setq org-line
(replace-match
1632 (concat "@<a name=\""
1633 (org-solidify-link-text (match-string 1 org-line
))
1634 "\" class=\"target\">" (match-string 1 org-line
)
1638 (setq org-line
(org-html-handle-time-stamps org-line
))
1640 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1641 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1642 ;; Also handle sub_superscripts and checkboxes
1643 (or (string-match org-table-hline-regexp org-line
)
1644 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" org-line
)
1645 (setq org-line
(org-html-expand org-line
)))
1648 (setq org-line
(org-html-handle-links org-line opt-plist
))
1651 (if (and org-todo-line-regexp
1652 (string-match org-todo-line-regexp org-line
)
1653 (match-beginning 2))
1656 (concat (substring org-line
0 (match-beginning 2))
1658 (if (member (match-string 2 org-line
)
1661 " " (org-export-html-get-todo-kwd-class-name
1662 (match-string 2 org-line
))
1663 "\">" (match-string 2 org-line
)
1664 "</span>" (substring org-line
(match-end 2)))))
1666 ;; Does this contain a reference to a footnote?
1667 (when org-export-with-footnotes
1669 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" org-line start
)
1670 ;; Discard protected matches not clearly identified as
1671 ;; footnote markers.
1672 (if (or (get-text-property (match-beginning 2) 'org-protected org-line
)
1673 (not (get-text-property (match-beginning 2) 'org-footnote org-line
)))
1674 (setq start
(match-end 2))
1675 (let ((n (match-string 2 org-line
)) extra a
)
1676 (if (setq a
(assoc n footref-seen
))
1678 (setcdr a
(1+ (cdr a
)))
1679 (setq extra
(format ".%d" (cdr a
))))
1681 (push (cons n
1) footref-seen
))
1687 (format org-export-html-footnote-format
1688 (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
1689 (or (match-string 1 org-line
) "") n extra n n
)
1690 ;; If another footnote is following the
1691 ;; current one, add a separator.
1692 (if (save-match-data
1693 (string-match "\\`\\[[0-9]+\\]"
1694 (substring org-line
(match-end 0))))
1695 org-export-html-footnote-separator
1700 ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" org-line
)
1701 ;; This is a headline
1702 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1704 txt
(match-string 2 org-line
))
1705 (if (string-match quote-re0 txt
)
1706 (setq txt
(replace-match "" t t txt
)))
1707 (if (<= level
(max umax umax-toc
))
1708 (setq head-count
(+ head-count
1)))
1709 (setq first-heading-pos
(or first-heading-pos
(point)))
1710 (org-html-level-start level txt umax
1711 (and org-export-with-toc
(<= level umax
))
1712 head-count opt-plist
)
1715 (when (string-match quote-re org-line
)
1716 (org-close-par-maybe)
1720 ((and org-export-with-tables
1721 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" org-line
))
1722 (when (not table-open
)
1724 (setq table-open t table-buffer nil table-orig-buffer nil
))
1727 (setq table-buffer
(cons org-line table-buffer
)
1728 table-orig-buffer
(cons origline table-orig-buffer
))
1729 (when (or (not lines
)
1730 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1732 (setq table-open nil
1733 table-buffer
(nreverse table-buffer
)
1734 table-orig-buffer
(nreverse table-orig-buffer
))
1735 (org-close-par-maybe)
1736 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1741 ;; This line either is list item or end a list.
1742 (when (get-text-property 0 'list-item org-line
)
1743 (setq org-line
(org-html-export-list-line
1745 (get-text-property 0 'list-item org-line
)
1746 (get-text-property 0 'list-struct org-line
)
1747 (get-text-property 0 'list-prevs org-line
))))
1750 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" org-line
)
1752 (insert "\n</p>\n<hr/>\n<p>\n")
1753 (insert "\n<hr/>\n"))
1754 (throw 'nextline nil
))
1756 ;; Empty lines start a new paragraph. If hand-formatted lists
1757 ;; are not fully interpreted, lines starting with "-", "+", "*"
1758 ;; also start a new paragraph.
1759 (if (string-match "^ [-+*]-\\|^[ \t]*$" org-line
) (org-open-par))
1761 ;; Is this the start of a footnote?
1762 (when org-export-with-footnotes
1763 (when (and (boundp 'footnote-section-tag-regexp
)
1764 (string-match (concat "^" footnote-section-tag-regexp
)
1767 (throw 'nextline nil
))
1768 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" org-line
)
1769 (org-close-par-maybe)
1770 (let ((n (match-string 1 org-line
)))
1771 (setq org-par-open t
1772 org-line
(replace-match
1774 (concat "<p class=\"footnote\">"
1775 (format org-export-html-footnote-format
1776 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1777 n n n
) t t org-line
)))))
1778 ;; Check if the line break needs to be conserved
1780 ((string-match "\\\\\\\\[ \t]*$" org-line
)
1781 (setq org-line
(replace-match "<br/>" t t org-line
)))
1782 (org-export-preserve-breaks
1783 (setq org-line
(concat org-line
"<br/>"))))
1785 ;; Check if a paragraph should be started
1787 (while (and org-par-open
1788 (string-match "\\\\par\\>" org-line start
))
1789 ;; Leave a space in the </p> so that the footnote matcher
1790 ;; does not see this.
1791 (if (not (get-text-property (match-beginning 0)
1792 'org-protected org-line
))
1793 (setq org-line
(replace-match "</p ><p >" t t org-line
)))
1794 (setq start
(match-end 0))))
1796 (insert org-line
"\n")))))
1798 ;; Properly close all local lists and other lists
1803 (org-html-level-start 1 nil umax
1804 (and org-export-with-toc
(<= level umax
))
1805 head-count opt-plist
)
1806 ;; the </div> to close the last text-... div.
1807 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1810 (goto-char (point-min))
1811 (while (re-search-forward
1812 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1814 (push (match-string 1) footnotes
)
1815 (replace-match "\\4" t nil
)
1816 (goto-char (match-beginning 0))))
1818 (insert (format org-export-html-footnotes-section
1820 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1822 (let ((bib (org-export-html-get-bibliography)))
1824 (insert "\n" bib
"\n")))
1827 ;; end wrap around body
1830 ;; export html postamble
1831 (let ((html-post (plist-get opt-plist
:html-postamble
))
1833 (mapconcat (lambda(e)
1834 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1835 (split-string email
",+ *")
1838 (concat "Org version " org-version
" with Emacs version "
1839 (number-to-string emacs-major-version
))))
1841 (when (plist-get opt-plist
:html-postamble
)
1842 (insert "\n<div id=\"" (nth 2 org-export-html-divs
) "\">\n")
1843 (cond ((stringp html-post
)
1844 (insert (format-spec html-post
1845 `((?a .
,author
) (?e .
,email
)
1846 (?d .
,date
) (?c .
,creator-info
)
1847 (?v .
,html-validation-link
)))))
1848 ((functionp html-post
)
1849 (if (stringp (funcall html-post
)) (insert (funcall html-post
))))
1850 ((eq html-post
'auto
)
1851 ;; fall back on default postamble
1852 (when (plist-get opt-plist
:time-stamp-file
)
1853 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
1854 (when (and (plist-get opt-plist
:author-info
) author
)
1855 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
1856 (when (and (plist-get opt-plist
:email-info
) email
)
1857 (insert "<p class=\"email\">" email
"</p>\n"))
1858 (when (plist-get opt-plist
:creator-info
)
1859 (insert "<p class=\"creator\">"
1860 (concat "Org version " org-version
" with Emacs version "
1861 (number-to-string emacs-major-version
) "</p>\n")))
1862 (insert html-validation-link
"\n"))
1864 (insert (format-spec
1865 (or (cadr (assoc (nth 0 lang-words
)
1866 org-export-html-postamble-format
))
1867 (cadr (assoc "en" org-export-html-postamble-format
)))
1868 `((?a .
,author
) (?e .
,email
)
1869 (?d .
,date
) (?c .
,creator-info
)
1870 (?v .
,html-validation-link
))))))
1871 (insert "\n</div>"))))
1873 ;; FIXME `org-export-html-with-timestamp' has been declared
1874 ;; obsolete since Org 7.7 -- don't forget to remove this.
1875 (if org-export-html-with-timestamp
1876 (insert org-export-html-html-helper-timestamp
))
1878 (unless body-only
(insert "\n</body>\n</html>\n"))
1880 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1882 (if (eq major-mode
(default-value 'major-mode
))
1885 ;; insert the table of contents
1886 (goto-char (point-min))
1888 (if (or (re-search-forward
1889 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1891 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1893 (goto-char (match-beginning 0))
1895 (goto-char first-heading-pos
)
1896 (when (looking-at "\\s-*</p>")
1897 (goto-char (match-end 0))
1899 (insert "<div id=\"table-of-contents\">\n")
1900 (let ((beg (point)))
1901 (mapc 'insert thetoc
)
1903 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t
)
1904 (replace-match ""))))
1905 ;; remove empty paragraphs
1906 (goto-char (point-min))
1907 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1909 (goto-char (point-min))
1910 ;; Convert whitespace place holders
1911 (goto-char (point-min))
1913 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1914 (setq n
(get-text-property beg
'org-whitespace
)
1915 end
(next-single-property-change beg
'org-whitespace
))
1917 (delete-region beg end
)
1918 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1919 (make-string n ?x
)))))
1920 ;; Remove empty lines at the beginning of the file.
1921 (goto-char (point-min))
1922 (when (looking-at "\\s-+\n") (replace-match ""))
1923 ;; Remove display properties
1924 (remove-text-properties (point-min) (point-max) '(display t
))
1926 (run-hooks 'org-export-html-final-hook
)
1927 (or to-buffer
(save-buffer))
1928 (goto-char (point-min))
1929 (or (org-export-push-to-kill-ring "HTML")
1930 (message "Exporting... done"))
1931 (if (eq to-buffer
'string
)
1932 (prog1 (buffer-substring (point-min) (point-max))
1933 (kill-buffer (current-buffer)))
1934 (current-buffer)))))
1936 (defun org-export-html-format-href (s)
1937 "Make sure the S is valid as a href reference in an XHTML document."
1940 (while (string-match "&" s start
)
1941 (setq start
(+ (match-beginning 0) 3)
1942 s
(replace-match "&" t t s
)))))
1945 (defun org-export-html-format-desc (s)
1946 "Make sure the S is valid as a description in a link."
1947 (if (and s
(not (get-text-property 1 'org-protected s
)))
1949 (org-html-do-expand s
))
1952 (defun org-export-html-format-image (src par-open
)
1953 "Create image tag with source and attributes."
1955 (if (string-match "^ltxpng/" src
)
1956 (format "<img src=\"%s\" alt=\"%s\"/>"
1957 src
(org-find-text-property-in-string 'org-latex-src src
))
1958 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1959 (attr (org-find-text-property-in-string 'org-attributes src
))
1960 (label (org-find-text-property-in-string 'org-label src
)))
1961 (setq caption
(and caption
(org-html-do-expand caption
)))
1964 (format "%s<div %sclass=\"figure\">
1966 (if org-par-open
"</p>\n" "")
1967 (if label
(format "id=\"%s\" " (org-solidify-link-text label
)) "")))
1968 (format "<img src=\"%s\"%s />"
1970 (if (string-match "\\<alt=" (or attr
""))
1972 (concat " " attr
" alt=\"" src
"\"")))
1976 (concat "\n<p>" caption
"</p>")
1977 (if org-par-open
"\n<p>" ""))))))))
1979 (defun org-export-html-get-bibliography ()
1980 "Find bibliography, cut it out and return it."
1982 (let (beg end
(cnt 1) bib
)
1984 (goto-char (point-min))
1985 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1986 (setq beg
(match-beginning 0))
1987 (while (re-search-forward "</?div\\>" nil t
)
1988 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1990 (and (looking-at ">") (forward-char 1))
1991 (setq bib
(buffer-substring beg
(point)))
1992 (delete-region beg
(point))
1993 (throw 'exit bib
))))
1996 (defvar org-table-number-regexp
) ; defined in org-table.el
1997 (defun org-format-table-html (lines olines
&optional no-css
)
1998 "Find out which HTML converter to use and return the HTML code.
1999 NO-CSS is passed to the exporter."
2001 (setq lines
(org-split-string lines
"\n")))
2002 (if (string-match "^[ \t]*|" (car lines
))
2003 ;; A normal org table
2004 (org-format-org-table-html lines nil no-css
)
2005 ;; Table made by table.el
2006 (or (org-format-table-table-html-using-table-generate-source
2007 olines
(not org-export-prefer-native-exporter-for-tables
))
2008 ;; We are here only when table.el table has NO col or row
2009 ;; spanning and the user prefers using org's own converter for
2010 ;; exporting of such simple table.el tables.
2011 (org-format-table-table-html lines
))))
2013 (defvar org-table-number-fraction
) ; defined in org-table.el
2014 (defun org-format-org-table-html (lines &optional splice no-css
)
2015 "Format a table into HTML.
2016 LINES is a list of lines. Optional argument SPLICE means, do not
2017 insert header and surrounding <table> tags, just format the lines.
2018 Optional argument NO-CSS means use XHTML attributes instead of CSS
2019 for formatting. This is required for the DocBook exporter."
2020 (require 'org-table
)
2021 ;; Get rid of hlines at beginning and end
2022 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2023 (setq lines
(nreverse lines
))
2024 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2025 (setq lines
(nreverse lines
))
2026 (when org-export-table-remove-special-lines
2027 ;; Check if the table has a marking column. If yes remove the
2028 ;; column and the special lines
2029 (setq lines
(org-table-clean-before-export lines
)))
2031 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
2032 (label (org-find-text-property-in-string 'org-label
(car lines
)))
2033 (col-cookies (org-find-text-property-in-string 'org-col-cookies
2035 (attributes (org-find-text-property-in-string 'org-attributes
2037 (html-table-tag (org-export-splice-attributes
2038 html-table-tag attributes
))
2039 (head (and org-export-highlight-first-table-line
2041 (lambda (x) (string-match "^[ \t]*|-" x
))
2043 (nline 0) fnum nfields i
(cnt 0)
2044 tbopen org-line fields html gr colgropen rowstart rowend
2046 (setq caption
(and caption
(org-html-do-expand caption
)))
2047 (when (and col-cookies org-table-clean-did-remove-column
)
2049 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) col-cookies
)))
2050 (if splice
(setq head nil
))
2051 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
2053 (while (setq org-line
(pop lines
))
2055 (if (string-match "^[ \t]*|-" org-line
)
2058 (push (if head
"</thead>" "</tbody>") html
)
2059 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
2060 (setq head nil
) ;; head ends here, first time around
2062 (throw 'next-line t
)))
2063 ;; Break the line into fields
2064 (setq fields
(org-split-string org-line
"[ \t]*|[ \t]*"))
2065 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
2066 nfields
(length fnum
)))
2067 (setq nline
(1+ nline
) i -
1
2068 rowstart
(eval (car org-export-table-row-tags
))
2069 rowend
(eval (cdr org-export-table-row-tags
)))
2070 (push (concat rowstart
2073 (setq i
(1+ i
) ali
(format "@@class%03d@@" i
))
2074 (if (and (< i nfields
) ; make sure no rogue line causes an error here
2075 (string-match org-table-number-regexp x
))
2076 (incf (aref fnum i
)))
2080 (format (car org-export-table-header-tags
)
2083 (cdr org-export-table-header-tags
)))
2084 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
2086 (format (car org-export-table-header-tags
)
2089 (cdr org-export-table-header-tags
)))
2091 (concat (format (car org-export-table-data-tags
) ali
)
2093 (cdr org-export-table-data-tags
)))))
2097 (unless splice
(if tbopen
(push "</tbody>" html
)))
2098 (unless splice
(push "</table>\n" html
))
2099 (setq html
(nreverse html
))
2101 ;; Put in col tags with the alignment (unfortunately often ignored...)
2102 (unless (car org-table-colgroup-info
)
2103 (setq org-table-colgroup-info
2104 (cons :start
(cdr org-table-colgroup-info
))))
2108 (setq gr
(pop org-table-colgroup-info
)
2110 align
(if (nth 1 (assoc i col-cookies
))
2111 (cdr (assoc (nth 1 (assoc i col-cookies
))
2112 '(("l" .
"left") ("r" .
"right")
2114 (if (> (/ (float x
) nline
)
2115 org-table-number-fraction
)
2119 "%s<col align=\"%s\" />%s"
2120 "%s<col class=\"%s\" />%s")
2121 (if (memq gr
'(:start
:startend
))
2124 "</colgroup>\n<colgroup>"
2129 (if (memq gr
'(:end
:startend
))
2130 (progn (setq colgropen nil
) "</colgroup>")
2134 (setq aligns
(nreverse aligns
))
2135 (if colgropen
(setq html
(cons (car html
)
2136 (cons "</colgroup>" (cdr html
)))))
2137 ;; Since the output of HTML table formatter can also be used in
2138 ;; DocBook document, we want to always include the caption to make
2139 ;; DocBook XML file valid.
2140 (push (format "<caption>%s</caption>" (or caption
"")) html
)
2142 (setq html-table-tag
(org-export-splice-attributes html-table-tag
(format "id=\"%s\"" (org-solidify-link-text label
)))))
2143 (push html-table-tag html
))
2146 (replace-regexp-in-string
2147 "@@class\\([0-9]+\\)@@"
2149 (if (not org-export-html-table-align-individual-fields
)
2151 (setq n
(string-to-number (match-string 1 txt
)))
2152 (format (if no-css
" align=\"%s\"" " class=\"%s\"")
2153 (or (nth n aligns
) "left"))))
2156 (concat (mapconcat 'identity html
"\n") "\n")))
2158 (defun org-export-splice-attributes (tag attributes
)
2159 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2160 (if (not attributes
)
2162 (let (oldatt newatt
)
2163 (setq oldatt
(org-extract-attributes-from-string tag
)
2165 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2167 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2168 (if (string-match ">" tag
)
2170 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2174 (defun org-format-table-table-html (lines)
2175 "Format a table generated by table.el into HTML.
2176 This conversion does *not* use `table-generate-source' from table.el.
2177 This has the advantage that Org-mode's HTML conversions can be used.
2178 But it has the disadvantage, that no cell- or row-spanning is allowed."
2179 (let (org-line field-buffer
2180 (head org-export-highlight-first-table-line
)
2181 fields html empty i
)
2182 (setq html
(concat html-table-tag
"\n"))
2183 (while (setq org-line
(pop lines
))
2184 (setq empty
" ")
2186 (if (string-match "^[ \t]*\\+-" org-line
)
2197 (if (equal x
"") (setq x empty
))
2200 (format (car org-export-table-header-tags
) "col" "")
2202 (cdr org-export-table-header-tags
))
2203 (concat (format (car org-export-table-data-tags
) "") x
2204 (cdr org-export-table-data-tags
))))
2208 (setq field-buffer nil
)))
2210 (throw 'next-line t
)))
2211 ;; Break the line into fields and store the fields
2212 (setq fields
(org-split-string org-line
"[ \t]*|[ \t]*"))
2214 (setq field-buffer
(mapcar
2216 (concat x
"<br/>" (pop fields
)))
2218 (setq field-buffer fields
))))
2219 (setq html
(concat html
"</table>\n"))
2222 (defun org-format-table-table-html-using-table-generate-source (lines
2225 "Format a table into html, using `table-generate-source' from table.el.
2226 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2228 When SPANNED-ONLY is nil, all table.el tables are exported. When
2229 SPANNED-ONLY is non-nil, only tables with either row or column
2232 This routine returns the generated source or nil as appropriate.
2234 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2235 for further information."
2237 (with-current-buffer (get-buffer-create " org-tmp1 ")
2239 (insert (mapconcat 'identity lines
"\n"))
2240 (goto-char (point-min))
2241 (if (not (re-search-forward "|[^+]" nil t
))
2242 (error "Error processing table"))
2243 (table-recognize-table)
2244 (when (or (not spanned-only
)
2245 (let* ((dim (table-query-dimension))
2246 (c (nth 4 dim
)) (r (nth 5 dim
)) (cells (nth 6 dim
)))
2247 (not (= (* c r
) cells
))))
2248 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2249 (table-generate-source 'html
" org-tmp2 ")
2250 (set-buffer " org-tmp2 ")
2251 (buffer-substring (point-min) (point-max)))))
2253 (defun org-export-splice-style (style extra
)
2254 "Splice EXTRA into STYLE, just before \"</style>\"."
2255 (if (and (stringp extra
)
2256 (string-match "\\S-" extra
)
2257 (string-match "</style>" style
))
2258 (concat (substring style
0 (match-beginning 0))
2260 (substring style
(match-beginning 0)))
2263 (defun org-html-handle-time-stamps (s)
2264 "Format time stamps in string S, or remove them."
2267 (when org-maybe-keyword-time-regexp
2268 (while (string-match org-maybe-keyword-time-regexp s
)
2269 (or b
(setq b
(substring s
0 (match-beginning 0))))
2271 r
(substring s
0 (match-beginning 0))
2272 " @<span class=\"timestamp-wrapper\">"
2274 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2275 (match-string 1 s
)))
2276 (format " @<span class=\"timestamp\">%s@</span>"
2278 (org-translate-time (match-string 3 s
)) 1 -
1))
2280 s
(substring s
(match-end 0)))))
2281 ;; Line break if line started and ended with time stamp stuff
2284 (setq r
(concat r s
))
2285 (unless (string-match "\\S-" (concat b s
))
2286 (setq r
(concat r
"@<br/>")))
2289 (defvar htmlize-buffer-places
) ; from htmlize.el
2290 (defun org-export-htmlize-region-for-paste (beg end
)
2291 "Convert the region to HTML, using htmlize.el.
2292 This is much like `htmlize-region-for-paste', only that it uses
2293 the settings define in the org-... variables."
2294 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2295 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2296 (htmlbuf (htmlize-region beg end
)))
2298 (with-current-buffer htmlbuf
2299 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2300 (plist-get htmlize-buffer-places
'content-end
)))
2301 (kill-buffer htmlbuf
))))
2304 (defun org-export-htmlize-generate-css ()
2305 "Create the CSS for all font definitions in the current Emacs session.
2306 Use this to create face definitions in your CSS style file that can then
2307 be used by code snippets transformed by htmlize.
2308 This command just produces a buffer that contains class definitions for all
2309 faces used in the current Emacs session. You can copy and paste the ones you
2310 need into your CSS file.
2312 If you then set `org-export-htmlize-output-type' to `css', calls to
2313 the function `org-export-htmlize-region-for-paste' will produce code
2314 that uses these same face definitions."
2317 (and (get-buffer "*html*") (kill-buffer "*html*"))
2319 (let ((fl (face-list))
2320 (htmlize-css-name-prefix "org-")
2321 (htmlize-output-type 'css
)
2323 (while (setq f
(pop fl
)
2324 i
(and f
(face-attribute f
:inherit
)))
2325 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2326 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2327 (htmlize-region (point-min) (point-max))))
2328 (org-pop-to-buffer-same-window "*html*")
2329 (goto-char (point-min))
2330 (if (re-search-forward "<style" nil t
)
2331 (delete-region (point-min) (match-beginning 0)))
2332 (if (re-search-forward "</style>" nil t
)
2333 (delete-region (1+ (match-end 0)) (point-max)))
2334 (beginning-of-line 1)
2335 (if (looking-at " +") (replace-match ""))
2336 (goto-char (point-min)))
2338 (defun org-html-protect (s)
2339 "Convert characters to HTML equivalent.
2340 Possible conversions are set in `org-export-html-protect-char-alist'."
2341 (let ((cl org-export-html-protect-char-alist
) c
)
2342 (while (setq c
(pop cl
))
2344 (while (string-match (car c
) s start
)
2345 (setq s
(replace-match (cdr c
) t t s
)
2346 start
(1+ (match-beginning 0))))))
2349 (defun org-html-expand (string)
2350 "Prepare STRING for HTML export. Apply all active conversions.
2351 If there are links in the string, don't modify these. If STRING
2352 is nil, return nil."
2354 (let* ((re (concat org-bracket-link-regexp
"\\|"
2355 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2357 (while (setq m
(string-match re string
))
2358 (setq s
(substring string
0 m
)
2359 l
(match-string 0 string
)
2360 string
(substring string
(match-end 0)))
2361 (push (org-html-do-expand s
) res
)
2363 (push (org-html-do-expand string
) res
)
2364 (apply 'concat
(nreverse res
)))))
2366 (defun org-html-do-expand (s)
2367 "Apply all active conversions to translate special ASCII to HTML."
2368 (setq s
(org-html-protect s
))
2369 (if org-export-html-expand
2370 (while (string-match "@<\\([^&]*\\)>" s
)
2371 (setq s
(replace-match "<\\1>" t nil s
))))
2372 (if org-export-with-emphasize
2373 (setq s
(org-export-html-convert-emphasize s
)))
2374 (if org-export-with-special-strings
2375 (setq s
(org-export-html-convert-special-strings s
)))
2376 (if org-export-with-sub-superscripts
2377 (setq s
(org-export-html-convert-sub-super s
)))
2378 (if org-export-with-TeX-macros
2379 (let ((start 0) wd rep
)
2380 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2382 (if (get-text-property (match-beginning 0) 'org-protected s
)
2383 (setq start
(match-end 0))
2384 (setq wd
(match-string 1 s
))
2385 (if (setq rep
(org-entity-get-representation wd
'html
))
2386 (setq s
(replace-match rep t t s
))
2387 (setq start
(+ start
(length wd
))))))))
2390 (defun org-export-html-convert-special-strings (string)
2391 "Convert special characters in STRING to HTML."
2392 (let ((all org-export-html-special-string-regexps
)
2394 (while (setq a
(pop all
))
2395 (setq re
(car a
) rpl
(cdr a
) start
0)
2396 (while (string-match re string start
)
2397 (if (get-text-property (match-beginning 0) 'org-protected string
)
2398 (setq start
(match-end 0))
2399 (setq string
(replace-match rpl t nil string
)))))
2402 (defun org-export-html-convert-sub-super (string)
2403 "Convert sub- and superscripts in STRING to HTML."
2404 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2405 (while (string-match org-match-substring-regexp string s
)
2407 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2408 ((get-text-property (match-beginning 2) 'org-protected string
)
2409 (setq s
(match-end 2)))
2411 (setq s
(match-end 1)
2412 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2413 c
(or (match-string 8 string
)
2414 (match-string 6 string
)
2415 (match-string 5 string
))
2416 string
(replace-match
2417 (concat (match-string 1 string
)
2418 "<" key
">" c
"</" key
">")
2420 (while (string-match "\\\\\\([_^]\\)" string
)
2421 (setq string
(replace-match (match-string 1 string
) t t string
)))
2424 (defun org-export-html-convert-emphasize (string)
2427 (while (string-match org-emph-re string s
)
2429 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2430 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2431 (setq s
(match-beginning 0)
2434 (match-string 1 string
)
2435 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2436 (match-string 4 string
)
2437 (nth 3 (assoc (match-string 3 string
)
2438 org-emphasis-alist
))
2439 (match-string 5 string
))
2440 string
(replace-match rpl t t string
)
2441 s
(+ s
(- (length rpl
) 2)))
2445 (defun org-open-par ()
2446 "Insert <p>, but first close previous paragraph if any."
2447 (org-close-par-maybe)
2449 (setq org-par-open t
))
2450 (defun org-close-par-maybe ()
2451 "Close paragraph if there is one open."
2454 (setq org-par-open nil
)))
2455 (defun org-close-li (&optional type
)
2456 "Close <li> if necessary."
2457 (org-close-par-maybe)
2458 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2460 (defvar body-only
) ; dynamically scoped into this.
2461 (defun org-html-level-start (level title umax with-toc head-count
&optional opt-plist
)
2462 "Insert a new level in HTML export.
2463 When TITLE is nil, just close all open levels."
2464 (org-close-par-maybe)
2465 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2466 (extra-targets (and target
2467 (assoc target org-export-target-aliases
)))
2468 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2469 (preferred (and target
2470 (cdr (assoc target org-export-preferred-target-alist
))))
2472 (num (plist-get opt-plist
:section-numbers
))
2473 snumber snu href suffix
)
2474 (setq extra-targets
(remove (or preferred target
) extra-targets
))
2476 (mapconcat (lambda (x)
2477 (setq x
(org-solidify-link-text
2478 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2479 (if (stringp org-export-html-headline-anchor-format
)
2480 (format org-export-html-headline-anchor-format x x
)
2485 (if (aref org-levels-open
(1- l
))
2487 (org-html-level-close l umax
)
2488 (aset org-levels-open
(1- l
) nil
)))
2491 ;; If title is nil, this means this function is called to close
2492 ;; all levels, so the rest is done only if title is given
2493 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2494 (setq title
(replace-match
2495 (if org-export-with-tags
2498 " <span class=\"tag\">"
2501 (format "<span class=\"%s\">%s</span>"
2502 (org-export-html-get-tag-class-name x
)
2504 (org-split-string (match-string 1 title
) ":")
2511 (if (aref org-levels-open
(1- level
))
2515 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2516 extra-targets title
"<br/>\n")
2517 (insert "<li>" title
"<br/>\n")))
2518 (aset org-levels-open
(1- level
) t
)
2519 (org-close-par-maybe)
2521 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2522 extra-targets title
"<br/>\n")
2523 (insert "<ul>\n<li>" title
"<br/>\n"))))
2524 (aset org-levels-open
(1- level
) t
)
2525 (setq snumber
(org-section-number level
)
2526 snu
(replace-regexp-in-string "\\." "-" snumber
))
2527 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2528 (if (and num
(not body-only
))
2530 (format "<span class=\"section-number-%d\">%s</span>"
2534 ;; fix up num to take into
2535 ;; account the top-level
2537 (>= (+ num org-export-html-toplevel-hlevel -
1)
2543 (unless (= head-count
1) (insert "\n</div>\n"))
2544 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2545 (setq suffix
(org-solidify-link-text (or href snu
)))
2546 (setq href
(org-solidify-link-text (or href
(concat "sec-" snu
))))
2547 (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"
2548 suffix level
(if extra-class
(concat " " extra-class
) "")
2551 title level level suffix
))
2554 (defun org-export-html-get-tag-class-name (tag)
2555 "Turn tag into a valid class name.
2556 Replaces invalid characters with \"_\" and then prepends a prefix."
2558 (while (string-match "[^a-zA-Z0-9_]" tag
)
2559 (setq tag
(replace-match "_" t t tag
))))
2560 (concat org-export-html-tag-class-prefix tag
))
2562 (defun org-export-html-get-todo-kwd-class-name (kwd)
2563 "Turn todo keyword into a valid class name.
2564 Replaces invalid characters with \"_\" and then prepends a prefix."
2566 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2567 (setq kwd
(replace-match "_" t t kwd
))))
2568 (concat org-export-html-todo-kwd-class-prefix kwd
))
2570 (defun org-html-level-close (level max-outline-level
)
2571 "Terminate one level in HTML export."
2572 (if (<= level max-outline-level
)
2575 (insert "</ul>\n")))
2577 (defun org-html-export-list-line (org-line pos struct prevs
)
2578 "Insert list syntax in export buffer. Return ORG-LINE, maybe modified.
2580 POS is the item position or org-line position the org-line had before
2581 modifications to buffer. STRUCT is the list structure. PREVS is
2582 the alist of previous items."
2585 ;; Translate type of list containing POS to "d", "o" or
2587 (lambda (pos struct prevs
)
2588 (let ((type (org-list-get-list-type pos struct prevs
)))
2590 ((eq 'ordered type
) "o")
2591 ((eq 'descriptive type
) "d")
2595 ;; Return list of all items and sublists ending at POS, in
2601 (let ((end (nth 6 e
))
2604 ((= end pos
) (push item out
))
2605 ((>= item pos
) (throw 'exit nil
)))))
2608 ;; First close any previous item, or list, ending at POS.
2610 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2611 (first-item (org-list-get-list-begin e struct prevs
))
2612 (type (funcall get-type first-item struct prevs
)))
2613 (org-close-par-maybe)
2614 ;; Ending for every item
2616 ;; We're ending last item of the list: end list.
2618 (insert (format "</%sl>\n" type
))
2620 (funcall get-closings pos
))
2622 ;; At an item: insert appropriate tags in export buffer.
2625 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2626 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
2627 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2628 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2629 "\\(.*\\)") org-line
)
2630 (let* ((checkbox (match-string 3 org-line
))
2631 (desc-tag (or (match-string 4 org-line
) "???"))
2632 (body (or (match-string 5 org-line
) ""))
2633 (list-beg (org-list-get-list-begin pos struct prevs
))
2634 (firstp (= list-beg pos
))
2635 ;; Always refer to first item to determine list type, in
2636 ;; case list is ill-formed.
2637 (type (funcall get-type list-beg struct prevs
))
2638 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2640 ((not count-tmp
) nil
)
2641 ((string-match "[A-Za-z]" count-tmp
)
2642 (- (string-to-char (upcase count-tmp
)) 64))
2643 ((string-match "[0-9]+" count-tmp
)
2646 (org-close-par-maybe)
2647 (insert (format "<%sl>\n" type
)))
2650 (format "<dt>%s</dt><dd>" desc-tag
))
2651 ((and (equal type
"o") counter
)
2652 (format "<li value=\"%s\">" counter
))
2654 ;; If line had a checkbox, some additional modification is required.
2659 ((string-match "X" checkbox
) "<code>[X]</code> ")
2660 ((string-match " " checkbox
) "<code>[ ]</code> ")
2661 (t "<code>[-]</code> "))
2663 ;; Return modified line
2665 ;; At a list ender: go to next line (side-effects only).
2666 ((equal "ORG-LIST-END-MARKER" org-line
) (throw 'nextline nil
))
2667 ;; Not at an item: return line unchanged (side-effects only).
2672 ;;; org-html.el ends here