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 format 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
))))
702 (goto-char (point-min))
704 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
705 (org-if-unprotected-at (match-beginning 1)
706 (setq label
(match-string 1))
708 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
709 (setq l1
(substring label
(match-beginning 1)))
711 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
714 (defun org-export-as-html-and-open (arg)
715 "Export the outline as HTML and immediately open it with a browser.
716 If there is an active region, export only the region.
717 The prefix ARG specifies how many levels of the outline should become
718 headlines. The default is 3. Lower levels will become bulleted lists."
720 (org-export-as-html arg
'hidden
)
721 (org-open-file buffer-file-name
)
722 (when org-export-kill-product-buffer-when-displayed
723 (kill-buffer (current-buffer))))
726 (defun org-export-as-html-batch ()
727 "Call the function `org-export-as-html'.
728 This function can be used in batch processing as:
730 --load=$HOME/lib/emacs/org.el
731 --eval \"(setq org-export-headline-levels 2)\"
732 --visit=MyFile --funcall org-export-as-html-batch"
733 (org-export-as-html org-export-headline-levels
'hidden
))
736 (defun org-export-as-html-to-buffer (arg)
737 "Call `org-export-as-html` with output to a temporary buffer.
738 No file is created. The prefix ARG is passed through to `org-export-as-html'."
740 (org-export-as-html arg nil nil
"*Org HTML Export*")
741 (when org-export-show-temporary-export-buffer
742 (switch-to-buffer-other-window "*Org HTML Export*")))
745 (defun org-replace-region-by-html (beg end
)
746 "Assume the current region has org-mode syntax, and convert it to HTML.
747 This can be used in any buffer. For example, you could write an
748 itemized list in org-mode syntax in an HTML buffer and then use this
749 command to convert it."
751 (let (reg html buf pop-up-frames
)
752 (save-window-excursion
753 (if (derived-mode-p 'org-mode
)
754 (setq html
(org-export-region-as-html
756 (setq reg
(buffer-substring beg end
)
757 buf
(get-buffer-create "*Org tmp*"))
758 (with-current-buffer buf
762 (setq html
(org-export-region-as-html
763 (point-min) (point-max) t
'string
)))
765 (delete-region beg end
)
769 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
770 "Convert region from BEG to END in org-mode buffer to HTML.
771 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
772 contents, and only produce the region of converted text, useful for
773 cut-and-paste operations.
774 If BUFFER is a buffer or a string, use/create that buffer as a target
775 of the converted HTML. If BUFFER is the symbol `string', return the
776 produced HTML as a string and leave not buffer behind. For example,
777 a Lisp program could call this function in the following way:
779 (setq html (org-export-region-as-html beg end t 'string))
781 When called interactively, the output buffer is selected, and shown
782 in a window. A non-interactive call will only return the buffer."
784 (when (org-called-interactively-p 'any
)
785 (setq buffer
"*Org HTML Export*"))
786 (let ((transient-mark-mode t
) (zmacs-regions t
)
788 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
790 (set-mark (point)) ;; to activate the region
792 (setq rtn
(org-export-as-html
795 (if (fboundp 'deactivate-mark
) (deactivate-mark))
796 (if (and (org-called-interactively-p 'any
) (bufferp rtn
))
797 (switch-to-buffer-other-window rtn
)
800 (defvar html-table-tag nil
) ; dynamically scoped into this.
801 (defvar org-par-open nil
)
803 ;;; org-html-cvt-link-fn
804 (defconst org-html-cvt-link-fn
806 "Function to convert link URLs to exportable URLs.
807 Takes two arguments, TYPE and PATH.
808 Returns exportable url as (TYPE PATH), or nil to signal that it
809 didn't handle this case.
810 Intended to be locally bound around a call to `org-export-as-html'." )
812 (defun org-html-cvt-org-as-html (opt-plist type path
)
813 "Convert an org filename to an equivalent html filename.
814 If TYPE is not file, just return `nil'.
815 See variable `org-export-html-link-org-files-as-html'"
819 org-export-html-link-org-files-as-html
820 (string= type
"file")
821 (string-match "\\.org$" path
)
826 (substring path
0 (match-beginning 0))
828 (plist-get opt-plist
:html-extension
)))))))
831 ;;; org-html-should-inline-p
832 (defun org-html-should-inline-p (filename descp
)
833 "Return non-nil if link FILENAME should be inlined.
834 The decision to inline the FILENAME link is based on the current
835 settings. DESCP is the boolean of whether there was a link
836 description. See variables `org-export-html-inline-images' and
837 `org-export-html-inline-image-extensions'."
839 org-export-html-inline-images
840 org-export-html-inline-image-extensions
))
841 (and (or (eq t org-export-html-inline-images
)
842 (and org-export-html-inline-images
(not descp
)))
844 filename org-export-html-inline-image-extensions
)))
846 ;;; org-html-make-link
847 (defun org-html-make-link (opt-plist type path fragment desc attr
850 OPT-PLIST is an options list.
851 TYPE is the device-type of the link (THIS://foo.html).
852 PATH is the path of the link (http://THIS#location).
853 FRAGMENT is the fragment part of the link, if any (foo.html#THIS).
854 DESC is the link description, if any.
855 ATTR is a string of other attributes of the \"a\" element.
856 MAY-INLINE-P allows inlining it as an image."
858 (declare (special org-par-open
))
860 (let* ((filename path
)
861 ;;First pass. Just sanity stuff.
864 ((string= type
"file")
867 ;;Substitute just if original path was absolute.
868 ;;(Otherwise path must remain relative)
869 (if (file-name-absolute-p path
)
870 (concat "file://" (expand-file-name path
))
874 (t (list type path
))))
876 ;;Second pass. Components converted so they can refer
880 (and org-html-cvt-link-fn
881 (apply org-html-cvt-link-fn
882 opt-plist components-1
))
883 (apply #'org-html-cvt-org-as-html
884 opt-plist components-1
)
886 (type (first components-2
))
887 (thefile (second components-2
)))
890 ;;Third pass. Build final link except for leading type
895 (string= type
"http")
896 (string= type
"https")
897 (string= type
"file")
898 (string= type
"coderef"))
900 (setq thefile
(concat thefile
"#" fragment
))))
904 ;;Final URL-build, for all types.
907 ((str (org-export-html-format-href thefile
)))
908 (if (and type
(not (or (string= "file" type
)
909 (string= "coderef" type
))))
910 (concat type
":" str
)
915 ;;Can't inline a URL with a fragment.
918 (message "image %s %s" thefile org-par-open
)
919 (org-export-html-format-image thefile org-par-open
))
921 "<a href=\"" thefile
"\"" (if attr
(concat " " attr
)) ">"
922 (org-export-html-format-desc desc
)
925 (defun org-html-handle-links (org-line opt-plist
)
926 "Return ORG-LINE with markup of Org mode links.
927 OPT-PLIST is the export options list."
929 (current-dir (if buffer-file-name
930 (file-name-directory buffer-file-name
)
932 (link-validate (plist-get opt-plist
:link-validation-function
))
934 rpl path attr desc descp desc1 desc2 link
)
935 (while (string-match org-bracket-link-analytic-regexp
++ org-line start
)
936 (setq start
(match-beginning 0))
937 (setq path
(save-match-data (org-link-unescape
938 (match-string 3 org-line
))))
940 ((match-end 2) (match-string 2 org-line
))
942 (or (file-name-absolute-p path
)
943 (string-match "^\\.\\.?/" path
)))
946 (setq path
(org-extract-attributes path
))
947 (setq attr
(get-text-property 0 'org-attributes path
))
948 (setq desc1
(if (match-end 5) (match-string 5 org-line
))
949 desc2
(if (match-end 2) (concat type
":" path
) path
)
950 descp
(and desc1
(not (equal desc1 desc2
)))
951 desc
(or desc1 desc2
))
952 ;; Make an image out of the description if that is so wanted
953 (when (and descp
(org-file-image-p
954 desc org-export-html-inline-image-extensions
))
956 (if (string-match "^file:" desc
)
957 (setq desc
(substring desc
(match-end 0)))))
958 (setq desc
(org-add-props
959 (concat "<img src=\"" desc
"\" alt=\""
960 (file-name-nondirectory desc
) "\"/>")
961 '(org-protected t
))))
963 ((equal type
"internal")
966 (if (= (string-to-char path
) ?
#)
974 (org-solidify-link-text
975 (save-match-data (org-link-unescape frag-0
))
978 ((and (equal type
"id")
979 (setq id-file
(org-id-find-id-file path
)))
980 ;; This is an id: link to another file (if it was the same file,
981 ;; it would have become an internal link...)
983 (setq id-file
(file-relative-name
985 (file-name-directory org-current-export-file
)))
987 (org-html-make-link opt-plist
989 (concat (if (org-uuidgen-p path
) "ID-") path
)
993 ((member type
'("http" "https"))
994 ;; standard URL, can inline as image
996 (org-html-make-link opt-plist
1000 (org-html-should-inline-p path descp
))))
1001 ((member type
'("ftp" "mailto" "news"))
1002 ;; standard URL, can't inline as image
1004 (org-html-make-link opt-plist
1010 ((string= type
"coderef")
1012 ((coderef-str (format "coderef-%s" path
))
1014 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
1015 coderef-str coderef-str
)))
1017 (org-html-make-link opt-plist
1020 (org-export-get-coderef-format
1023 (cdr (assoc path org-export-code-refs
)))
1027 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
1028 ;; The link protocol has a function for format the link
1031 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
1033 ((string= type
"file")
1039 (string-match "::\\(.*\\)" path
)
1041 (replace-match "" t nil path
)
1042 (match-string 1 path
))
1045 ;;The proper path, without a fragment
1051 (second components
))
1053 ;;Check the fragment. If it can't be used as
1054 ;;target fragment we'll pass nil instead.
1058 (not (string-match "^[0-9]*$" fragment-0
))
1059 (not (string-match "^\\*" fragment-0
))
1060 (not (string-match "^/.*/$" fragment-0
)))
1061 (org-solidify-link-text
1062 (org-link-unescape fragment-0
))
1065 ;;Description minus "file:" and ".org"
1066 (if (string-match "^file:" desc
)
1068 ((desc-1 (replace-match "" t t desc
)))
1069 (if (string-match "\\.org$" desc-1
)
1070 (replace-match "" t t desc-1
)
1077 (functionp link-validate
)
1078 (not (funcall link-validate path-1 current-dir
)))
1080 (org-html-make-link opt-plist
1081 "file" path-1 fragment-1 desc-2 attr
1082 (org-html-should-inline-p path-1 descp
)))))))
1085 ;; just publish the path, as default
1086 (setq rpl
(concat "<i><" type
":"
1087 (save-match-data (org-link-unescape path
))
1089 (setq org-line
(replace-match rpl t t org-line
)
1090 start
(+ start
(length rpl
))))
1093 ;;; org-export-as-html
1095 (defvar org-heading-keyword-regexp-format
) ; defined in org.el
1098 (defun org-export-as-html (arg &optional hidden ext-plist
1099 to-buffer body-only pub-dir
)
1100 "Export the outline as a pretty HTML file.
1101 If there is an active region, export only the region. The prefix
1102 ARG specifies how many levels of the outline should become
1103 headlines. The default is 3. Lower levels will become bulleted
1104 lists. HIDDEN is obsolete and does nothing.
1105 EXT-PLIST is a property list with external parameters overriding
1106 org-mode's default settings, but still inferior to file-local
1107 settings. When TO-BUFFER is non-nil, create a buffer with that
1108 name and export to that buffer. If TO-BUFFER is the symbol
1109 `string', don't leave any buffer behind but just return the
1110 resulting HTML as a string. When BODY-ONLY is set, don't produce
1111 the file header and footer, simply return the content of
1112 <body>...</body>, without even the body tags themselves. When
1113 PUB-DIR is set, use this as the publishing directory."
1115 (run-hooks 'org-export-first-hook
)
1117 ;; Make sure we have a file name when we need it.
1118 (when (and (not (or to-buffer body-only
))
1119 (not buffer-file-name
))
1120 (if (buffer-base-buffer)
1121 (org-set-local 'buffer-file-name
1122 (with-current-buffer (buffer-base-buffer)
1124 (error "Need a file name to be able to export")))
1126 (message "Exporting...")
1127 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1128 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1129 (setq-default org-done-keywords org-done-keywords
)
1130 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1132 (org-export-process-option-filters
1133 (org-combine-plists (org-default-export-plist)
1135 (org-infile-export-plist))))
1136 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1137 (style (concat (if (plist-get opt-plist
:style-include-default
)
1138 org-export-html-style-default
)
1139 (plist-get opt-plist
:style
)
1140 (plist-get opt-plist
:style-extra
)
1142 (if (plist-get opt-plist
:style-include-scripts
)
1143 org-export-html-scripts
)))
1144 (html-extension (plist-get opt-plist
:html-extension
))
1145 valid thetoc have-headings first-heading-pos
1146 (odd org-odd-levels-only
)
1147 (region-p (org-region-active-p))
1148 (rbeg (and region-p
(region-beginning)))
1149 (rend (and region-p
(region-end)))
1151 (if (plist-get opt-plist
:ignore-subtree-p
)
1156 (and (org-at-heading-p)
1157 (>= (org-end-of-subtree t t
) rend
))))))
1158 (level-offset (if subtree-p
1161 (+ (funcall outline-level
)
1162 (if org-odd-levels-only
1 0)))
1164 (opt-plist (setq org-export-opt-plist
1166 (org-export-add-subtree-options opt-plist rbeg
)
1168 ;; The following two are dynamically scoped into other
1170 (org-current-export-dir
1171 (or pub-dir
(org-export-directory :html opt-plist
)))
1172 (org-current-export-file buffer-file-name
)
1173 (level 0) (org-line "") (origline "") txt todo
1176 (filename (if to-buffer nil
1179 (file-name-sans-extension
1181 (org-entry-get (region-beginning)
1182 "EXPORT_FILE_NAME" t
))
1183 (file-name-nondirectory buffer-file-name
)))
1185 (file-name-as-directory
1186 (or pub-dir
(org-export-directory :html opt-plist
))))))
1187 (current-dir (if buffer-file-name
1188 (file-name-directory buffer-file-name
)
1190 (auto-insert nil
); Avoid any auto-insert stuff for the new file
1191 (buffer (if to-buffer
1193 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
1194 (t (get-buffer-create to-buffer
)))
1195 (find-file-noselect filename
)))
1196 (org-levels-open (make-vector org-level-max nil
))
1197 (date (org-html-expand (plist-get opt-plist
:date
)))
1198 (author (org-html-expand (plist-get opt-plist
:author
)))
1199 (html-validation-link (or org-export-html-validation-link
""))
1200 (title (org-html-expand
1201 (or (and subtree-p
(org-export-get-title-from-subtree))
1202 (plist-get opt-plist
:title
)
1203 (and (not body-only
)
1205 (plist-get opt-plist
:skip-before-1st-heading
))
1206 (org-export-grab-title-from-buffer))
1207 (and buffer-file-name
1208 (file-name-sans-extension
1209 (file-name-nondirectory buffer-file-name
)))
1211 (link-up (and (plist-get opt-plist
:link-up
)
1212 (string-match "\\S-" (plist-get opt-plist
:link-up
))
1213 (plist-get opt-plist
:link-up
)))
1214 (link-home (and (plist-get opt-plist
:link-home
)
1215 (string-match "\\S-" (plist-get opt-plist
:link-home
))
1216 (plist-get opt-plist
:link-home
)))
1217 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1218 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1219 (quote-re0 (concat "^ *" org-quote-string
"\\( +\\|[ \t]*$\\)"))
1220 (quote-re (format org-heading-keyword-regexp-format
1225 (email (plist-get opt-plist
:email
))
1226 (language (plist-get opt-plist
:language
))
1227 (keywords (org-html-expand (plist-get opt-plist
:keywords
)))
1228 (description (org-html-expand (plist-get opt-plist
:description
)))
1229 (num (plist-get opt-plist
:section-numbers
))
1233 (coding-system (and (boundp 'buffer-file-coding-system
)
1234 buffer-file-coding-system
))
1235 (coding-system-for-write (or org-export-html-coding-system
1237 (save-buffer-coding-system (or org-export-html-coding-system
1239 (charset (and coding-system-for-write
1240 (fboundp 'coding-system-get
)
1241 (coding-system-get coding-system-for-write
1245 (if region-p
(region-beginning) (point-min))
1246 (if region-p
(region-end) (point-max))))
1247 (org-export-have-math nil
)
1248 (org-export-footnotes-seen nil
)
1249 (org-export-footnotes-data (org-footnote-all-labels 'with-defs
))
1250 (custom-id (or (org-entry-get nil
"CUSTOM_ID" t
) ""))
1251 (footnote-def-prefix (format "fn-%s" custom-id
))
1252 (footnote-ref-prefix (format "fnr-%s" custom-id
))
1255 (org-export-preprocess-string
1259 :skip-before-1st-heading
1260 (plist-get opt-plist
:skip-before-1st-heading
)
1261 :drawers
(plist-get opt-plist
:drawers
)
1262 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1263 :tasks
(plist-get opt-plist
:tasks
)
1264 :tags
(plist-get opt-plist
:tags
)
1265 :priority
(plist-get opt-plist
:priority
)
1266 :footnotes
(plist-get opt-plist
:footnotes
)
1267 :timestamps
(plist-get opt-plist
:timestamps
)
1269 (plist-get opt-plist
:archived-trees
)
1270 :select-tags
(plist-get opt-plist
:select-tags
)
1271 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1273 (plist-get opt-plist
:text
)
1275 (plist-get opt-plist
:LaTeX-fragments
))
1278 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
1279 (and org-export-have-math
1280 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
1282 (org-export-html-mathjax-config
1283 org-export-html-mathjax-template
1284 org-export-html-mathjax-options
1285 (or (plist-get opt-plist
:mathjax
) ""))
1288 table-buffer table-orig-buffer
1290 rpl path attr desc descp desc1 desc2 link
1292 footnotes footref-seen
1296 (let ((inhibit-read-only t
))
1298 (remove-text-properties (point-min) (point-max)
1299 '(:org-license-to-kill t
))))
1301 (message "Exporting...")
1303 (setq org-min-level
(org-get-min-level lines level-offset
))
1304 (setq org-last-level org-min-level
)
1305 (org-init-section-numbers)
1308 ((and date
(string-match "%" date
))
1309 (setq date
(format-time-string date
)))
1311 (t (setq date
(format-time-string org-export-html-date-format-string
))))
1313 ;; Get the language-dependent settings
1314 (setq lang-words
(or (assoc language org-export-language-setup
)
1315 (assoc "en" org-export-language-setup
)))
1317 ;; Switch to the output buffer
1319 (let ((inhibit-read-only t
)) (erase-buffer))
1321 (org-install-letbind)
1323 (and (fboundp 'set-buffer-file-coding-system
)
1324 (set-buffer-file-coding-system coding-system-for-write
))
1326 (let ((case-fold-search nil
)
1327 (org-odd-levels-only odd
))
1328 ;; create local variables for all options, to make sure all called
1329 ;; functions get the correct information
1331 (set (make-local-variable (nth 2 x
))
1332 (plist-get opt-plist
(car x
))))
1333 org-export-plist-vars
)
1334 (setq umax
(if arg
(prefix-numeric-value arg
)
1335 org-export-headline-levels
))
1336 (setq umax-toc
(if (integerp org-export-with-toc
)
1337 (min org-export-with-toc umax
)
1343 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1344 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1345 <html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\" xml:lang=\"%s\">
1348 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1349 <meta name=\"title\" content=\"%s\"/>
1350 <meta name=\"generator\" content=\"Org-mode\"/>
1351 <meta name=\"generated\" content=\"%s\"/>
1352 <meta name=\"author\" content=\"%s\"/>
1353 <meta name=\"description\" content=\"%s\"/>
1354 <meta name=\"keywords\" content=\"%s\"/>
1362 (or (and (stringp org-export-html-xml-declaration
)
1363 org-export-html-xml-declaration
)
1364 (cdr (assoc html-extension org-export-html-xml-declaration
))
1365 (cdr (assoc "html" org-export-html-xml-declaration
))
1368 (or charset
"iso-8859-1"))
1371 (or charset
"iso-8859-1")
1372 title date author description keywords
1375 (if (or link-up link-home
)
1377 (format org-export-html-home
/up-format
1378 (or link-up link-home
)
1379 (or link-home link-up
))
1383 ;; insert html preamble
1384 (when (plist-get opt-plist
:html-preamble
)
1385 (let ((html-pre (plist-get opt-plist
:html-preamble
))
1386 (html-pre-real-contents ""))
1387 (cond ((stringp html-pre
)
1388 (setq html-pre-real-contents
1389 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
1390 (?d .
,date
) (?e .
,email
)))))
1391 ((functionp html-pre
)
1392 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1393 (if (stringp (funcall html-pre
)) (insert (funcall html-pre
)))
1394 (insert "\n</div>\n"))
1396 (setq html-pre-real-contents
1398 (or (cadr (assoc (nth 0 lang-words
)
1399 org-export-html-preamble-format
))
1400 (cadr (assoc "en" org-export-html-preamble-format
)))
1401 `((?t .
,title
) (?a .
,author
)
1402 (?d .
,date
) (?e .
,email
))))))
1403 ;; don't output an empty preamble DIV
1404 (unless (and (functionp html-pre
)
1405 (equal html-pre-real-contents
""))
1406 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1407 (insert html-pre-real-contents
)
1408 (insert "\n</div>\n"))))
1410 ;; begin wrap around body
1411 (insert (format "\n<div id=\"%s\">"
1412 ;; FIXME org-export-html-content-div is obsolete since 7.7
1413 (or org-export-html-content-div
1414 (nth 1 org-export-html-divs
)))
1415 ;; FIXME this should go in the preamble but is here so
1416 ;; that org-infojs can still find it
1417 "\n<h1 class=\"title\">" title
"</h1>\n"))
1420 (if org-export-with-toc
1422 (push (format "<h%d>%s</h%d>\n"
1423 org-export-html-toplevel-hlevel
1425 org-export-html-toplevel-hlevel
)
1427 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1428 (push "<ul>\n<li>" thetoc
)
1431 #'(lambda (org-line)
1432 (if (and (string-match org-todo-line-regexp org-line
)
1433 (not (get-text-property 0 'org-protected org-line
)))
1434 ;; This is a headline
1436 (setq have-headings t
)
1437 (setq level
(- (match-end 1) (match-beginning 1)
1439 level
(org-tr-level level
)
1440 txt
(save-match-data
1442 (org-export-cleanup-toc-line
1443 (match-string 3 org-line
))))
1445 (or (and org-export-mark-todo-in-toc
1447 (not (member (match-string 2 org-line
)
1448 org-done-keywords
)))
1450 (and org-export-mark-todo-in-toc
1452 (org-search-todo-below
1453 org-line lines level
))))
1455 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1456 (setq txt
(replace-match
1457 " <span class=\"tag\">\\1</span>" t nil txt
)))
1458 (if (string-match quote-re0 txt
)
1459 (setq txt
(replace-match "" t t txt
)))
1460 (setq snumber
(org-section-number level
))
1461 (if (and num
(if (integerp num
)
1464 (setq txt
(concat snumber
" " txt
)))
1465 (if (<= level
(max umax umax-toc
))
1466 (setq head-count
(+ head-count
1)))
1467 (if (<= level umax-toc
)
1469 (if (> level org-last-level
)
1471 (setq cnt
(- level org-last-level
))
1472 (while (>= (setq cnt
(1- cnt
)) 0)
1473 (push "\n<ul>\n<li>" thetoc
))
1474 (push "\n" thetoc
)))
1475 (if (< level org-last-level
)
1477 (setq cnt
(- org-last-level level
))
1478 (while (>= (setq cnt
(1- cnt
)) 0)
1479 (push "</li>\n</ul>" thetoc
))
1480 (push "\n" thetoc
)))
1481 ;; Check for targets
1482 (while (string-match org-any-target-regexp org-line
)
1483 (setq org-line
(replace-match
1484 (concat "@<span class=\"target\">"
1485 (match-string 1 org-line
) "@</span> ")
1487 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1488 (setq txt
(replace-match "" t t txt
)))
1490 (replace-regexp-in-string
1491 "\\." "-" (format "sec-%s" snumber
)))
1492 (setq href
(org-solidify-link-text
1493 (or (cdr (assoc href
1494 org-export-preferred-target-alist
)) href
)))
1498 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1499 "</li>\n<li><a href=\"#%s\">%s</a>")
1502 (setq org-last-level level
)))))
1505 (while (> org-last-level
(1- org-min-level
))
1506 (setq org-last-level
(1- org-last-level
))
1507 (push "</li>\n</ul>\n" thetoc
))
1508 (push "</div>\n" thetoc
)
1509 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1512 (org-init-section-numbers)
1516 (while (setq org-line
(pop lines
) origline org-line
)
1519 ;; end of quote section?
1520 (when (and inquote
(string-match org-outline-regexp-bol org-line
))
1524 ;; inside a quote section?
1526 (insert (org-html-protect org-line
) "\n")
1527 (throw 'nextline nil
))
1529 ;; Fixed-width, verbatim lines (examples)
1530 (when (and org-export-with-fixed-width
1531 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" org-line
))
1534 (org-close-par-maybe)
1536 (insert "<pre class=\"example\">\n"))
1537 (insert (org-html-protect (match-string 3 org-line
)) "\n")
1538 (when (or (not lines
)
1539 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1544 (throw 'nextline nil
))
1547 (when (and (get-text-property 0 'org-protected org-line
)
1548 ;; Make sure it is the entire line that is protected
1549 (not (< (or (next-single-property-change
1550 0 'org-protected org-line
) 10000)
1551 (length org-line
))))
1552 (let (par (ind (get-text-property 0 'original-indentation org-line
)))
1553 (when (re-search-backward
1554 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1555 (setq par
(match-string 1))
1556 (replace-match "\\2\n"))
1557 (insert org-line
"\n")
1559 (or (= (length (car lines
)) 0)
1561 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1562 (or (= (length (car lines
)) 0)
1563 (get-text-property 0 'org-protected
(car lines
))))
1564 (insert (pop lines
) "\n"))
1565 (and par
(insert "<p>\n")))
1566 (throw 'nextline nil
))
1568 ;; Blockquotes, verse, and center
1569 (when (equal "ORG-BLOCKQUOTE-START" org-line
)
1570 (org-close-par-maybe)
1571 (insert "<blockquote>\n")
1573 (throw 'nextline nil
))
1574 (when (equal "ORG-BLOCKQUOTE-END" org-line
)
1575 (org-close-par-maybe)
1576 (insert "\n</blockquote>\n")
1578 (throw 'nextline nil
))
1579 (when (equal "ORG-VERSE-START" org-line
)
1580 (org-close-par-maybe)
1581 (insert "\n<p class=\"verse\">\n")
1582 (setq org-par-open t
)
1584 (throw 'nextline nil
))
1585 (when (equal "ORG-VERSE-END" org-line
)
1587 (setq org-par-open nil
)
1590 (throw 'nextline nil
))
1591 (when (equal "ORG-CENTER-START" org-line
)
1592 (org-close-par-maybe)
1593 (insert "\n<div style=\"text-align: center\">")
1595 (throw 'nextline nil
))
1596 (when (equal "ORG-CENTER-END" org-line
)
1597 (org-close-par-maybe)
1600 (throw 'nextline nil
))
1601 (run-hooks 'org-export-html-after-blockquotes-hook
)
1603 (let ((i (org-get-string-indentation org-line
)))
1605 (setq org-line
(concat (mapconcat 'identity
1606 (make-list (* 2 i
) "\\nbsp") "")
1607 " " (org-trim org-line
))))
1608 (unless (string-match "\\\\\\\\[ \t]*$" org-line
)
1609 (setq org-line
(concat org-line
"\\\\")))))
1611 ;; make targets to anchors
1613 (while (string-match
1614 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" org-line start
)
1616 ((get-text-property (match-beginning 1) 'org-protected org-line
)
1617 (setq start
(match-end 1)))
1619 (setq org-line
(replace-match
1621 "@<a name=\"%s\" id=\"%s\">@</a>"
1622 (org-solidify-link-text (match-string 1 org-line
))
1623 (org-solidify-link-text (match-string 1 org-line
)))
1625 ((and org-export-with-toc
(equal (string-to-char org-line
) ?
*))
1626 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1627 (setq org-line
(replace-match
1628 (concat "@<span class=\"target\">"
1629 (match-string 1 org-line
) "@</span> ")
1630 ;; (concat "@<i>" (match-string 1 org-line) "@</i> ")
1633 (setq org-line
(replace-match
1634 (concat "@<a name=\""
1635 (org-solidify-link-text (match-string 1 org-line
))
1636 "\" class=\"target\">" (match-string 1 org-line
)
1640 (setq org-line
(org-html-handle-time-stamps org-line
))
1642 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1643 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1644 ;; Also handle sub_superscripts and checkboxes
1645 (or (string-match org-table-hline-regexp org-line
)
1646 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" org-line
)
1647 (setq org-line
(org-html-expand org-line
)))
1650 (setq org-line
(org-html-handle-links org-line opt-plist
))
1653 (if (and org-todo-line-regexp
1654 (string-match org-todo-line-regexp org-line
)
1655 (match-beginning 2))
1658 (concat (substring org-line
0 (match-beginning 2))
1660 (if (member (match-string 2 org-line
)
1663 " " (org-export-html-get-todo-kwd-class-name
1664 (match-string 2 org-line
))
1665 "\">" (match-string 2 org-line
)
1666 "</span>" (substring org-line
(match-end 2)))))
1668 ;; Does this contain a reference to a footnote?
1669 (when org-export-with-footnotes
1671 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" org-line start
)
1672 ;; Discard protected matches not clearly identified as
1673 ;; footnote markers.
1674 (if (or (get-text-property (match-beginning 2) 'org-protected org-line
)
1675 (not (get-text-property (match-beginning 2) 'org-footnote org-line
)))
1676 (setq start
(match-end 2))
1677 (let ((n (match-string 2 org-line
)) extra a
)
1678 (if (setq a
(assoc n footref-seen
))
1680 (setcdr a
(1+ (cdr a
)))
1681 (setq extra
(format ".%d" (cdr a
))))
1683 (push (cons n
1) footref-seen
))
1689 (format org-export-html-footnote-format
1690 (concat "<a class=\"footref\" name=\"" footnote-ref-prefix
".%s%s\" href=\"#" footnote-def-prefix
".%s\">%s</a>")))
1691 (or (match-string 1 org-line
) "") n extra n n
)
1692 ;; If another footnote is following the
1693 ;; current one, add a separator.
1694 (if (save-match-data
1695 (string-match "\\`\\[[0-9]+\\]"
1696 (substring org-line
(match-end 0))))
1697 org-export-html-footnote-separator
1702 ((string-match "^\\(\\*+\\)\\(?: +\\(.*?\\)\\)?[ \t]*$" org-line
)
1703 ;; This is a headline
1704 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1706 txt
(or (match-string 2 org-line
) ""))
1707 (if (string-match quote-re0 txt
)
1708 (setq txt
(replace-match "" t t txt
)))
1709 (if (<= level
(max umax umax-toc
))
1710 (setq head-count
(+ head-count
1)))
1711 (setq first-heading-pos
(or first-heading-pos
(point)))
1712 (org-html-level-start level txt umax
1713 (and org-export-with-toc
(<= level umax
))
1714 head-count opt-plist
)
1717 (when (string-match quote-re org-line
)
1718 (org-close-par-maybe)
1722 ((and org-export-with-tables
1723 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" org-line
))
1724 (when (not table-open
)
1726 (setq table-open t table-buffer nil table-orig-buffer nil
))
1729 (setq table-buffer
(cons org-line table-buffer
)
1730 table-orig-buffer
(cons origline table-orig-buffer
))
1731 (when (or (not lines
)
1732 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1734 (setq table-open nil
1735 table-buffer
(nreverse table-buffer
)
1736 table-orig-buffer
(nreverse table-orig-buffer
))
1737 (org-close-par-maybe)
1738 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1743 ;; This line either is list item or end a list.
1744 (when (get-text-property 0 'list-item org-line
)
1745 (setq org-line
(org-html-export-list-line
1747 (get-text-property 0 'list-item org-line
)
1748 (get-text-property 0 'list-struct org-line
)
1749 (get-text-property 0 'list-prevs org-line
))))
1752 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" org-line
)
1754 (insert "\n</p>\n<hr/>\n<p>\n")
1755 (insert "\n<hr/>\n"))
1756 (throw 'nextline nil
))
1758 ;; Empty lines start a new paragraph. If hand-formatted lists
1759 ;; are not fully interpreted, lines starting with "-", "+", "*"
1760 ;; also start a new paragraph.
1761 (if (string-match "^ [-+*]-\\|^[ \t]*$" org-line
) (org-open-par))
1763 ;; Is this the start of a footnote?
1764 (when org-export-with-footnotes
1765 (when (and (boundp 'footnote-section-tag-regexp
)
1766 (string-match (concat "^" footnote-section-tag-regexp
)
1769 (throw 'nextline nil
))
1770 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" org-line
)
1771 (org-close-par-maybe)
1772 (let ((n (match-string 1 org-line
)))
1773 (setq org-par-open t
1774 org-line
(replace-match
1776 (concat "<p class=\"footnote\">"
1777 (format org-export-html-footnote-format
1779 "<a class=\"footnum\" name=\"" footnote-def-prefix
".%s\" href=\"#" footnote-ref-prefix
".%s\">%s</a>")))
1780 n n n
) t t org-line
)))))
1781 ;; Check if the line break needs to be conserved
1783 ((string-match "\\\\\\\\[ \t]*$" org-line
)
1784 (setq org-line
(replace-match "<br/>" t t org-line
)))
1785 (org-export-preserve-breaks
1786 (setq org-line
(concat org-line
"<br/>"))))
1788 ;; Check if a paragraph should be started
1790 (while (and org-par-open
1791 (string-match "\\\\par\\>" org-line start
))
1792 ;; Leave a space in the </p> so that the footnote matcher
1793 ;; does not see this.
1794 (if (not (get-text-property (match-beginning 0)
1795 'org-protected org-line
))
1796 (setq org-line
(replace-match "</p ><p >" t t org-line
)))
1797 (setq start
(match-end 0))))
1799 (insert org-line
"\n")))))
1801 ;; Properly close all local lists and other lists
1806 (org-html-level-start 1 nil umax
1807 (and org-export-with-toc
(<= level umax
))
1808 head-count opt-plist
)
1809 ;; the </div> to close the last text-... div.
1810 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1813 (goto-char (point-min))
1814 (while (re-search-forward
1815 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1817 (push (match-string 1) footnotes
)
1818 (replace-match "\\4" t nil
)
1819 (goto-char (match-beginning 0))))
1821 (insert (format org-export-html-footnotes-section
1823 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1825 (let ((bib (org-export-html-get-bibliography)))
1827 (insert "\n" bib
"\n")))
1830 ;; end wrap around body
1833 ;; export html postamble
1834 (let ((html-post (plist-get opt-plist
:html-postamble
))
1836 (mapconcat (lambda(e)
1837 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1838 (split-string email
",+ *")
1841 (concat "<a href=\"http://orgmode.org\">Org</a> version "
1842 (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
1843 (number-to-string emacs-major-version
))))
1845 (when (plist-get opt-plist
:html-postamble
)
1846 (insert "\n<div id=\"" (nth 2 org-export-html-divs
) "\">\n")
1847 (cond ((stringp html-post
)
1848 (insert (format-spec html-post
1849 `((?a .
,author
) (?e .
,email
)
1850 (?d .
,date
) (?c .
,creator-info
)
1851 (?v .
,html-validation-link
)))))
1852 ((functionp html-post
)
1853 (if (stringp (funcall html-post
)) (insert (funcall html-post
))))
1854 ((eq html-post
'auto
)
1855 ;; fall back on default postamble
1856 (when (plist-get opt-plist
:time-stamp-file
)
1857 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
1858 (when (and (plist-get opt-plist
:author-info
) author
)
1859 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
1860 (when (and (plist-get opt-plist
:email-info
) email
)
1861 (insert "<p class=\"email\">" email
"</p>\n"))
1862 (when (plist-get opt-plist
:creator-info
)
1863 (insert "<p class=\"creator\">"
1864 (concat "<a href=\"http://orgmode.org\">Org</a> version "
1865 (org-version) " with <a href=\"http://www.gnu.org/software/emacs/\">Emacs</a> version "
1866 (number-to-string emacs-major-version
) "</p>\n")))
1867 (insert html-validation-link
"\n"))
1869 (insert (format-spec
1870 (or (cadr (assoc (nth 0 lang-words
)
1871 org-export-html-postamble-format
))
1872 (cadr (assoc "en" org-export-html-postamble-format
)))
1873 `((?a .
,author
) (?e .
,email
)
1874 (?d .
,date
) (?c .
,creator-info
)
1875 (?v .
,html-validation-link
))))))
1876 (insert "\n</div>"))))
1878 ;; FIXME `org-export-html-with-timestamp' has been declared
1879 ;; obsolete since Org 7.7 -- don't forget to remove this.
1880 (if org-export-html-with-timestamp
1881 (insert org-export-html-html-helper-timestamp
))
1883 (unless body-only
(insert "\n</body>\n</html>\n"))
1885 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1887 (if (eq major-mode
(default-value 'major-mode
))
1890 ;; insert the table of contents
1891 (goto-char (point-min))
1893 (if (or (re-search-forward
1894 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1896 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1898 (goto-char (match-beginning 0))
1900 (goto-char first-heading-pos
)
1901 (when (looking-at "\\s-*</p>")
1902 (goto-char (match-end 0))
1904 (insert "<div id=\"table-of-contents\">\n")
1905 (let ((beg (point)))
1906 (mapc 'insert thetoc
)
1908 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t
)
1909 (replace-match ""))))
1910 ;; remove empty paragraphs
1911 (goto-char (point-min))
1912 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1914 (goto-char (point-min))
1915 ;; Convert whitespace place holders
1916 (goto-char (point-min))
1918 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1919 (setq n
(get-text-property beg
'org-whitespace
)
1920 end
(next-single-property-change beg
'org-whitespace
))
1922 (delete-region beg end
)
1923 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1924 (make-string n ?x
)))))
1925 ;; Remove empty lines at the beginning of the file.
1926 (goto-char (point-min))
1927 (when (looking-at "\\s-+\n") (replace-match ""))
1928 ;; Remove display properties
1929 (remove-text-properties (point-min) (point-max) '(display t
))
1931 (run-hooks 'org-export-html-final-hook
)
1932 (or to-buffer
(save-buffer))
1933 (goto-char (point-min))
1934 (or (org-export-push-to-kill-ring "HTML")
1935 (message "Exporting... done"))
1936 (if (eq to-buffer
'string
)
1937 (prog1 (buffer-substring (point-min) (point-max))
1938 (kill-buffer (current-buffer)))
1939 (current-buffer)))))
1941 (defun org-export-html-format-href (s)
1942 "Make sure the S is valid as a href reference in an XHTML document."
1945 (while (string-match "&" s start
)
1946 (setq start
(+ (match-beginning 0) 3)
1947 s
(replace-match "&" t t s
)))))
1950 (defun org-export-html-format-desc (s)
1951 "Make sure the S is valid as a description in a link."
1952 (if (and s
(not (get-text-property 1 'org-protected s
)))
1954 (org-html-do-expand s
))
1957 (defun org-export-html-format-image (src par-open
)
1958 "Create image tag with source and attributes."
1960 (if (string-match "^ltxpng/" src
)
1961 (format "<img src=\"%s\" alt=\"%s\"/>"
1962 src
(org-find-text-property-in-string 'org-latex-src src
))
1963 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1964 (attr (org-find-text-property-in-string 'org-attributes src
))
1965 (label (org-find-text-property-in-string 'org-label src
)))
1966 (setq caption
(and caption
(org-html-do-expand caption
)))
1969 (format "%s<div %sclass=\"figure\">
1971 (if org-par-open
"</p>\n" "")
1972 (if label
(format "id=\"%s\" " (org-solidify-link-text label
)) "")))
1973 (format "<img src=\"%s\"%s />"
1975 (if (string-match "\\<alt=" (or attr
""))
1977 (concat " " attr
" alt=\"" src
"\"")))
1981 (concat "\n<p>" caption
"</p>")
1982 (if org-par-open
"\n<p>" ""))))))))
1984 (defun org-export-html-get-bibliography ()
1985 "Find bibliography, cut it out and return it."
1987 (let (beg end
(cnt 1) bib
)
1989 (goto-char (point-min))
1990 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1991 (setq beg
(match-beginning 0))
1992 (while (re-search-forward "</?div\\>" nil t
)
1993 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1995 (and (looking-at ">") (forward-char 1))
1996 (setq bib
(buffer-substring beg
(point)))
1997 (delete-region beg
(point))
1998 (throw 'exit bib
))))
2001 (defvar org-table-number-regexp
) ; defined in org-table.el
2002 (defun org-format-table-html (lines olines
&optional no-css
)
2003 "Find out which HTML converter to use and return the HTML code.
2004 NO-CSS is passed to the exporter."
2006 (setq lines
(org-split-string lines
"\n")))
2007 (if (string-match "^[ \t]*|" (car lines
))
2008 ;; A normal org table
2009 (org-format-org-table-html lines nil no-css
)
2010 ;; Table made by table.el
2011 (or (org-format-table-table-html-using-table-generate-source
2012 olines
(not org-export-prefer-native-exporter-for-tables
))
2013 ;; We are here only when table.el table has NO col or row
2014 ;; spanning and the user prefers using org's own converter for
2015 ;; exporting of such simple table.el tables.
2016 (org-format-table-table-html lines
))))
2018 (defvar org-table-number-fraction
) ; defined in org-table.el
2019 (defun org-format-org-table-html (lines &optional splice no-css
)
2020 "Format a table into HTML.
2021 LINES is a list of lines. Optional argument SPLICE means, do not
2022 insert header and surrounding <table> tags, just format the lines.
2023 Optional argument NO-CSS means use XHTML attributes instead of CSS
2024 for formatting. This is required for the DocBook exporter."
2025 (require 'org-table
)
2026 ;; Get rid of hlines at beginning and end
2027 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2028 (setq lines
(nreverse lines
))
2029 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2030 (setq lines
(nreverse lines
))
2031 (when org-export-table-remove-special-lines
2032 ;; Check if the table has a marking column. If yes remove the
2033 ;; column and the special lines
2034 (setq lines
(org-table-clean-before-export lines
)))
2036 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
2037 (label (org-find-text-property-in-string 'org-label
(car lines
)))
2038 (col-cookies (org-find-text-property-in-string 'org-col-cookies
2040 (attributes (org-find-text-property-in-string 'org-attributes
2042 (html-table-tag (org-export-splice-attributes
2043 html-table-tag attributes
))
2044 (head (and org-export-highlight-first-table-line
2046 (lambda (x) (string-match "^[ \t]*|-" x
))
2048 (nline 0) fnum nfields i
(cnt 0)
2049 tbopen org-line fields html gr colgropen rowstart rowend
2051 (setq caption
(and caption
(org-html-do-expand caption
)))
2052 (when (and col-cookies org-table-clean-did-remove-column
)
2054 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) col-cookies
)))
2055 (if splice
(setq head nil
))
2056 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
2058 (while (setq org-line
(pop lines
))
2060 (if (string-match "^[ \t]*|-" org-line
)
2063 (push (if head
"</thead>" "</tbody>") html
)
2064 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
2065 (setq head nil
) ;; head ends here, first time around
2067 (throw 'next-line t
)))
2068 ;; Break the line into fields
2069 (setq fields
(org-split-string org-line
"[ \t]*|[ \t]*"))
2070 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
2071 nfields
(length fnum
)))
2072 (setq nline
(1+ nline
) i -
1
2073 rowstart
(eval (car org-export-table-row-tags
))
2074 rowend
(eval (cdr org-export-table-row-tags
)))
2075 (push (concat rowstart
2078 (setq i
(1+ i
) ali
(format "@@class%03d@@" i
))
2079 (if (and (< i nfields
) ; make sure no rogue line causes an error here
2080 (string-match org-table-number-regexp x
))
2081 (incf (aref fnum i
)))
2085 (format (car org-export-table-header-tags
)
2088 (cdr org-export-table-header-tags
)))
2089 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
2091 (format (car org-export-table-header-tags
)
2094 (cdr org-export-table-header-tags
)))
2096 (concat (format (car org-export-table-data-tags
) ali
)
2098 (cdr org-export-table-data-tags
)))))
2102 (unless splice
(if tbopen
(push "</tbody>" html
)))
2103 (unless splice
(push "</table>\n" html
))
2104 (setq html
(nreverse html
))
2106 ;; Put in col tags with the alignment (unfortunately often ignored...)
2107 (unless (car org-table-colgroup-info
)
2108 (setq org-table-colgroup-info
2109 (cons :start
(cdr org-table-colgroup-info
))))
2113 (setq gr
(pop org-table-colgroup-info
)
2115 align
(if (nth 1 (assoc i col-cookies
))
2116 (cdr (assoc (nth 1 (assoc i col-cookies
))
2117 '(("l" .
"left") ("r" .
"right")
2119 (if (> (/ (float x
) nline
)
2120 org-table-number-fraction
)
2124 "%s<col align=\"%s\" />%s"
2125 "%s<col class=\"%s\" />%s")
2126 (if (memq gr
'(:start
:startend
))
2129 "</colgroup>\n<colgroup>"
2134 (if (memq gr
'(:end
:startend
))
2135 (progn (setq colgropen nil
) "</colgroup>")
2139 (setq aligns
(nreverse aligns
))
2140 (if colgropen
(setq html
(cons (car html
)
2141 (cons "</colgroup>" (cdr html
)))))
2142 ;; Since the output of HTML table formatter can also be used in
2143 ;; DocBook document, include empty captions for the DocBook
2144 ;; export only so that it produces valid XML.
2145 (when (or caption
(eq org-export-current-backend
'docbook
))
2146 (push (format "<caption>%s</caption>" (or caption
"")) html
))
2148 (setq html-table-tag
(org-export-splice-attributes html-table-tag
(format "id=\"%s\"" (org-solidify-link-text label
)))))
2149 (push html-table-tag html
))
2152 (replace-regexp-in-string
2153 "@@class\\([0-9]+\\)@@"
2155 (if (not org-export-html-table-align-individual-fields
)
2157 (setq n
(string-to-number (match-string 1 txt
)))
2158 (format (if no-css
" align=\"%s\"" " class=\"%s\"")
2159 (or (nth n aligns
) "left"))))
2162 (concat (mapconcat 'identity html
"\n") "\n")))
2164 (defun org-export-splice-attributes (tag attributes
)
2165 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2166 (if (not attributes
)
2168 (let (oldatt newatt
)
2169 (setq oldatt
(org-extract-attributes-from-string tag
)
2171 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2173 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2174 (if (string-match ">" tag
)
2176 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2180 (defun org-format-table-table-html (lines)
2181 "Format a table generated by table.el into HTML.
2182 This conversion does *not* use `table-generate-source' from table.el.
2183 This has the advantage that Org-mode's HTML conversions can be used.
2184 But it has the disadvantage, that no cell- or row-spanning is allowed."
2185 (let (org-line field-buffer
2186 (head org-export-highlight-first-table-line
)
2187 fields html empty i
)
2188 (setq html
(concat html-table-tag
"\n"))
2189 (while (setq org-line
(pop lines
))
2190 (setq empty
" ")
2192 (if (string-match "^[ \t]*\\+-" org-line
)
2203 (if (equal x
"") (setq x empty
))
2206 (format (car org-export-table-header-tags
) "col" "")
2208 (cdr org-export-table-header-tags
))
2209 (concat (format (car org-export-table-data-tags
) "") x
2210 (cdr org-export-table-data-tags
))))
2214 (setq field-buffer nil
)))
2216 (throw 'next-line t
)))
2217 ;; Break the line into fields and store the fields
2218 (setq fields
(org-split-string org-line
"[ \t]*|[ \t]*"))
2220 (setq field-buffer
(mapcar
2222 (concat x
"<br/>" (pop fields
)))
2224 (setq field-buffer fields
))))
2225 (setq html
(concat html
"</table>\n"))
2228 (defun org-format-table-table-html-using-table-generate-source (lines
2231 "Format a table into html, using `table-generate-source' from table.el.
2232 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2234 When SPANNED-ONLY is nil, all table.el tables are exported. When
2235 SPANNED-ONLY is non-nil, only tables with either row or column
2238 This routine returns the generated source or nil as appropriate.
2240 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2241 for further information."
2243 (with-current-buffer (get-buffer-create " org-tmp1 ")
2245 (insert (mapconcat 'identity lines
"\n"))
2246 (goto-char (point-min))
2247 (if (not (re-search-forward "|[^+]" nil t
))
2248 (error "Error processing table"))
2249 (table-recognize-table)
2250 (when (or (not spanned-only
)
2251 (let* ((dim (table-query-dimension))
2252 (c (nth 4 dim
)) (r (nth 5 dim
)) (cells (nth 6 dim
)))
2253 (not (= (* c r
) cells
))))
2254 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2255 (table-generate-source 'html
" org-tmp2 ")
2256 (set-buffer " org-tmp2 ")
2257 (buffer-substring (point-min) (point-max)))))
2259 (defun org-export-splice-style (style extra
)
2260 "Splice EXTRA into STYLE, just before \"</style>\"."
2261 (if (and (stringp extra
)
2262 (string-match "\\S-" extra
)
2263 (string-match "</style>" style
))
2264 (concat (substring style
0 (match-beginning 0))
2266 (substring style
(match-beginning 0)))
2269 (defun org-html-handle-time-stamps (s)
2270 "Format time stamps in string S, or remove them."
2273 (when org-maybe-keyword-time-regexp
2274 (while (string-match org-maybe-keyword-time-regexp s
)
2275 (or b
(setq b
(substring s
0 (match-beginning 0))))
2277 r
(substring s
0 (match-beginning 0))
2278 " @<span class=\"timestamp-wrapper\">"
2280 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2281 (match-string 1 s
)))
2282 (format " @<span class=\"timestamp\">%s@</span>"
2284 (org-translate-time (match-string 3 s
)) 1 -
1))
2286 s
(substring s
(match-end 0)))))
2287 ;; Line break if line started and ended with time stamp stuff
2290 (setq r
(concat r s
))
2291 (unless (string-match "\\S-" (concat b s
))
2292 (setq r
(concat r
"@<br/>")))
2295 (defvar htmlize-buffer-places
) ; from htmlize.el
2296 (defun org-export-htmlize-region-for-paste (beg end
)
2297 "Convert the region to HTML, using htmlize.el.
2298 This is much like `htmlize-region-for-paste', only that it uses
2299 the settings define in the org-... variables."
2300 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2301 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2302 (htmlbuf (htmlize-region beg end
)))
2304 (with-current-buffer htmlbuf
2305 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2306 (plist-get htmlize-buffer-places
'content-end
)))
2307 (kill-buffer htmlbuf
))))
2310 (defun org-export-htmlize-generate-css ()
2311 "Create the CSS for all font definitions in the current Emacs session.
2312 Use this to create face definitions in your CSS style file that can then
2313 be used by code snippets transformed by htmlize.
2314 This command just produces a buffer that contains class definitions for all
2315 faces used in the current Emacs session. You can copy and paste the ones you
2316 need into your CSS file.
2318 If you then set `org-export-htmlize-output-type' to `css', calls to
2319 the function `org-export-htmlize-region-for-paste' will produce code
2320 that uses these same face definitions."
2323 (and (get-buffer "*html*") (kill-buffer "*html*"))
2325 (let ((fl (face-list))
2326 (htmlize-css-name-prefix "org-")
2327 (htmlize-output-type 'css
)
2329 (while (setq f
(pop fl
)
2330 i
(and f
(face-attribute f
:inherit
)))
2331 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2332 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2333 (htmlize-region (point-min) (point-max))))
2334 (org-pop-to-buffer-same-window "*html*")
2335 (goto-char (point-min))
2336 (if (re-search-forward "<style" nil t
)
2337 (delete-region (point-min) (match-beginning 0)))
2338 (if (re-search-forward "</style>" nil t
)
2339 (delete-region (1+ (match-end 0)) (point-max)))
2340 (beginning-of-line 1)
2341 (if (looking-at " +") (replace-match ""))
2342 (goto-char (point-min)))
2344 (defun org-html-protect (s)
2345 "Convert characters to HTML equivalent.
2346 Possible conversions are set in `org-export-html-protect-char-alist'."
2347 (let ((cl org-export-html-protect-char-alist
) c
)
2348 (while (setq c
(pop cl
))
2350 (while (string-match (car c
) s start
)
2351 (setq s
(replace-match (cdr c
) t t s
)
2352 start
(1+ (match-beginning 0))))))
2355 (defun org-html-expand (string)
2356 "Prepare STRING for HTML export. Apply all active conversions.
2357 If there are links in the string, don't modify these. If STRING
2358 is nil, return nil."
2360 (let* ((re (concat org-bracket-link-regexp
"\\|"
2361 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2363 (while (setq m
(string-match re string
))
2364 (setq s
(substring string
0 m
)
2365 l
(match-string 0 string
)
2366 string
(substring string
(match-end 0)))
2367 (push (org-html-do-expand s
) res
)
2369 (push (org-html-do-expand string
) res
)
2370 (apply 'concat
(nreverse res
)))))
2372 (defun org-html-do-expand (s)
2373 "Apply all active conversions to translate special ASCII to HTML."
2374 (setq s
(org-html-protect s
))
2375 (if org-export-html-expand
2376 (while (string-match "@<\\([^&]*\\)>" s
)
2377 (setq s
(replace-match "<\\1>" t nil s
))))
2378 (if org-export-with-emphasize
2379 (setq s
(org-export-html-convert-emphasize s
)))
2380 (if org-export-with-special-strings
2381 (setq s
(org-export-html-convert-special-strings s
)))
2382 (if org-export-with-sub-superscripts
2383 (setq s
(org-export-html-convert-sub-super s
)))
2384 (if org-export-with-TeX-macros
2385 (let ((start 0) wd rep
)
2386 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2388 (if (get-text-property (match-beginning 0) 'org-protected s
)
2389 (setq start
(match-end 0))
2390 (setq wd
(match-string 1 s
))
2391 (if (setq rep
(org-entity-get-representation wd
'html
))
2392 (setq s
(replace-match rep t t s
))
2393 (setq start
(+ start
(length wd
))))))))
2396 (defun org-export-html-convert-special-strings (string)
2397 "Convert special characters in STRING to HTML."
2398 (let ((all org-export-html-special-string-regexps
)
2400 (while (setq a
(pop all
))
2401 (setq re
(car a
) rpl
(cdr a
) start
0)
2402 (while (string-match re string start
)
2403 (if (get-text-property (match-beginning 0) 'org-protected string
)
2404 (setq start
(match-end 0))
2405 (setq string
(replace-match rpl t nil string
)))))
2408 (defun org-export-html-convert-sub-super (string)
2409 "Convert sub- and superscripts in STRING to HTML."
2410 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2411 (while (string-match org-match-substring-regexp string s
)
2413 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2414 ((get-text-property (match-beginning 2) 'org-protected string
)
2415 (setq s
(match-end 2)))
2417 (setq s
(match-end 1)
2418 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2419 c
(or (match-string 8 string
)
2420 (match-string 6 string
)
2421 (match-string 5 string
))
2422 string
(replace-match
2423 (concat (match-string 1 string
)
2424 "<" key
">" c
"</" key
">")
2426 (while (string-match "\\\\\\([_^]\\)" string
)
2427 (setq string
(replace-match (match-string 1 string
) t t string
)))
2430 (defun org-export-html-convert-emphasize (string)
2433 (while (string-match org-emph-re string s
)
2435 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2436 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2437 (setq s
(match-beginning 0)
2440 (match-string 1 string
)
2441 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2442 (match-string 4 string
)
2443 (nth 3 (assoc (match-string 3 string
)
2444 org-emphasis-alist
))
2445 (match-string 5 string
))
2446 string
(replace-match rpl t t string
)
2447 s
(+ s
(- (length rpl
) 2)))
2451 (defun org-open-par ()
2452 "Insert <p>, but first close previous paragraph if any."
2453 (org-close-par-maybe)
2455 (setq org-par-open t
))
2456 (defun org-close-par-maybe ()
2457 "Close paragraph if there is one open."
2460 (setq org-par-open nil
)))
2461 (defun org-close-li (&optional type
)
2462 "Close <li> if necessary."
2463 (org-close-par-maybe)
2464 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2466 (defvar body-only
) ; dynamically scoped into this.
2467 (defun org-html-level-start (level title umax with-toc head-count
&optional opt-plist
)
2468 "Insert a new level in HTML export.
2469 When TITLE is nil, just close all open levels."
2470 (org-close-par-maybe)
2471 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2472 (extra-targets (and target
2473 (assoc target org-export-target-aliases
)))
2474 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2475 (preferred (and target
2476 (cdr (assoc target org-export-preferred-target-alist
))))
2478 (num (plist-get opt-plist
:section-numbers
))
2479 snumber snu href suffix
)
2480 (setq extra-targets
(remove (or preferred target
) extra-targets
))
2482 (mapconcat (lambda (x)
2483 (setq x
(org-solidify-link-text
2484 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2485 (if (stringp org-export-html-headline-anchor-format
)
2486 (format org-export-html-headline-anchor-format x x
)
2491 (if (aref org-levels-open
(1- l
))
2493 (org-html-level-close l umax
)
2494 (aset org-levels-open
(1- l
) nil
)))
2497 ;; If title is nil, this means this function is called to close
2498 ;; all levels, so the rest is done only if title is given
2499 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2500 (setq title
(replace-match
2501 (if org-export-with-tags
2504 " <span class=\"tag\">"
2507 (format "<span class=\"%s\">%s</span>"
2508 (org-export-html-get-tag-class-name x
)
2510 (org-split-string (match-string 1 title
) ":")
2517 (if (aref org-levels-open
(1- level
))
2521 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2522 extra-targets title
"<br/>\n")
2523 (insert "<li>" title
"<br/>\n")))
2524 (aset org-levels-open
(1- level
) t
)
2525 (org-close-par-maybe)
2527 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2528 extra-targets title
"<br/>\n")
2529 (insert "<ul>\n<li>" title
"<br/>\n"))))
2530 (aset org-levels-open
(1- level
) t
)
2531 (setq snumber
(org-section-number level
)
2532 snu
(replace-regexp-in-string "\\." "-" snumber
))
2533 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2534 (if (and num
(not body-only
))
2536 (format "<span class=\"section-number-%d\">%s</span>"
2540 ;; fix up num to take into
2541 ;; account the top-level
2543 (>= (+ num org-export-html-toplevel-hlevel -
1)
2549 (unless (= head-count
1) (insert "\n</div>\n"))
2550 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2551 (setq suffix
(org-solidify-link-text (or href snu
)))
2552 (setq href
(org-solidify-link-text (or href
(concat "sec-" snu
))))
2553 (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"
2554 suffix level
(if extra-class
(concat " " extra-class
) "")
2557 title level level suffix
))
2560 (defun org-export-html-get-tag-class-name (tag)
2561 "Turn tag into a valid class name.
2562 Replaces invalid characters with \"_\" and then prepends a prefix."
2564 (while (string-match "[^a-zA-Z0-9_]" tag
)
2565 (setq tag
(replace-match "_" t t tag
))))
2566 (concat org-export-html-tag-class-prefix tag
))
2568 (defun org-export-html-get-todo-kwd-class-name (kwd)
2569 "Turn todo keyword into a valid class name.
2570 Replaces invalid characters with \"_\" and then prepends a prefix."
2572 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2573 (setq kwd
(replace-match "_" t t kwd
))))
2574 (concat org-export-html-todo-kwd-class-prefix kwd
))
2576 (defun org-html-level-close (level max-outline-level
)
2577 "Terminate one level in HTML export."
2578 (if (<= level max-outline-level
)
2581 (insert "</ul>\n")))
2583 (defun org-html-export-list-line (org-line pos struct prevs
)
2584 "Insert list syntax in export buffer. Return ORG-LINE, maybe modified.
2586 POS is the item position or org-line position the org-line had before
2587 modifications to buffer. STRUCT is the list structure. PREVS is
2588 the alist of previous items."
2591 ;; Translate type of list containing POS to "d", "o" or
2593 (lambda (pos struct prevs
)
2594 (let ((type (org-list-get-list-type pos struct prevs
)))
2596 ((eq 'ordered type
) "o")
2597 ((eq 'descriptive type
) "d")
2601 ;; Return list of all items and sublists ending at POS, in
2607 (let ((end (nth 6 e
))
2610 ((= end pos
) (push item out
))
2611 ((>= item pos
) (throw 'exit nil
)))))
2614 ;; First close any previous item, or list, ending at POS.
2616 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2617 (first-item (org-list-get-list-begin e struct prevs
))
2618 (type (funcall get-type first-item struct prevs
)))
2619 (org-close-par-maybe)
2620 ;; Ending for every item
2622 ;; We're ending last item of the list: end list.
2624 (insert (format "</%sl>\n" type
))
2626 (funcall get-closings pos
))
2628 ;; At an item: insert appropriate tags in export buffer.
2631 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2632 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
2633 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2634 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2635 "\\(.*\\)") org-line
)
2636 (let* ((checkbox (match-string 3 org-line
))
2637 (desc-tag (or (match-string 4 org-line
) "???"))
2638 (body (or (match-string 5 org-line
) ""))
2639 (list-beg (org-list-get-list-begin pos struct prevs
))
2640 (firstp (= list-beg pos
))
2641 ;; Always refer to first item to determine list type, in
2642 ;; case list is ill-formed.
2643 (type (funcall get-type list-beg struct prevs
))
2644 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2646 ((not count-tmp
) nil
)
2647 ((string-match "[A-Za-z]" count-tmp
)
2648 (- (string-to-char (upcase count-tmp
)) 64))
2649 ((string-match "[0-9]+" count-tmp
)
2652 (org-close-par-maybe)
2653 (insert (format "<%sl>\n" type
)))
2656 (format "<dt>%s</dt><dd>" desc-tag
))
2657 ((and (equal type
"o") counter
)
2658 (format "<li value=\"%s\">" counter
))
2660 ;; If line had a checkbox, some additional modification is required.
2665 ((string-match "X" checkbox
) "<code>[X]</code> ")
2666 ((string-match " " checkbox
) "<code>[ ]</code> ")
2667 (t "<code>[-]</code> "))
2669 ;; Return modified line
2671 ;; At a list ender: go to next line (side-effects only).
2672 ((equal "ORG-LIST-END-MARKER" org-line
) (throw 'nextline nil
))
2673 ;; Not at an item: return line unchanged (side-effects only).
2678 ;;; org-html.el ends here