1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
32 (require 'format-spec
)
34 (eval-when-compile (require 'cl
))
36 (declare-function org-id-find-id-file
"org-id" (id))
37 (declare-function htmlize-region
"ext:htmlize" (beg end
))
38 (declare-function org-pop-to-buffer-same-window
39 "org-compat" (&optional buffer-or-name norecord label
))
41 (defgroup org-export-html nil
42 "Options specific for HTML export of Org-mode files."
43 :tag
"Org Export HTML"
46 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
47 <h2 class=\"footnotes\">%s: </h2>
48 <div id=\"text-footnotes\">
52 "Format for the footnotes section.
53 Should contain a two instances of %s. The first will be replaced with the
54 language-specific word for \"Footnotes\", the second one will be replaced
55 by the footnotes themselves."
56 :group
'org-export-html
59 (defcustom org-export-html-footnote-format
"<sup>%s</sup>"
60 "The format for the footnote reference.
61 %s will be replaced by the footnote reference itself."
62 :group
'org-export-html
66 (defcustom org-export-html-footnote-separator
"<sup>, </sup>"
67 "Text used to separate footnotes."
68 :group
'org-export-html
71 (defcustom org-export-html-coding-system nil
72 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
73 :group
'org-export-html
76 (defcustom org-export-html-extension
"html"
77 "The extension for exported HTML files."
78 :group
'org-export-html
81 (defcustom org-export-html-xml-declaration
82 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
83 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
84 "The extension for exported HTML files.
85 %s will be replaced with the charset of the exported file.
86 This may be a string, or an alist with export extensions
87 and corresponding declarations."
88 :group
'org-export-html
90 (string :tag
"Single declaration")
91 (repeat :tag
"Dependent on extension"
92 (cons (string :tag
"Extension")
93 (string :tag
"Declaration")))))
95 (defcustom org-export-html-style-include-scripts t
96 "Non-nil means include the JavaScript snippets in exported HTML files.
97 The actual script is defined in `org-export-html-scripts' and should
99 :group
'org-export-html
102 (defconst org-export-html-scripts
103 "<script type=\"text/javascript\">
104 <!--/*--><![CDATA[/*><!--*/
105 function CodeHighlightOn(elem, id)
107 var target = document.getElementById(id);
109 elem.cacheClassElem = elem.className;
110 elem.cacheClassTarget = target.className;
111 target.className = \"code-highlighted\";
112 elem.className = \"code-highlighted\";
115 function CodeHighlightOff(elem, id)
117 var target = document.getElementById(id);
118 if(elem.cacheClassElem)
119 elem.className = elem.cacheClassElem;
120 if(elem.cacheClassTarget)
121 target.className = elem.cacheClassTarget;
125 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
127 (defconst org-export-html-style-default
128 "<style type=\"text/css\">
129 <!--/*--><![CDATA[/*><!--*/
130 html { font-family: Times, serif; font-size: 12pt; }
131 .title { text-align: center; }
132 .todo { color: red; }
133 .done { color: green; }
134 .tag { background-color: #add8e6; font-weight:normal }
136 .timestamp { color: #bebebe; }
137 .timestamp-kwd { color: #5f9ea0; }
138 .right {margin-left:auto; margin-right:0px; text-align:right;}
139 .left {margin-left:0px; margin-right:auto; text-align:left;}
140 .center {margin-left:auto; margin-right:auto; text-align:center;}
141 p.verse { margin-left: 3% }
143 border: 1pt solid #AEBDCC;
144 background-color: #F3F5F7;
146 font-family: courier, monospace;
150 table { border-collapse: collapse; }
151 td, th { vertical-align: top; }
152 th.right { text-align:center; }
153 th.left { text-align:center; }
154 th.center { text-align:center; }
155 td.right { text-align:right; }
156 td.left { text-align:left; }
157 td.center { text-align:center; }
158 dt { font-weight: bold; }
159 div.figure { padding: 0.5em; }
160 div.figure p { text-align: center; }
161 textarea { overflow-x: auto; }
162 .linenr { font-size:smaller }
163 .code-highlighted {background-color:#ffff00;}
164 .org-info-js_info-navigation { border-style:none; }
165 #org-info-js_console-label { font-size:10px; font-weight:bold;
166 white-space:nowrap; }
167 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
171 "The default style specification for exported HTML files.
172 Please use the variables `org-export-html-style' and
173 `org-export-html-style-extra' to add to this style. If you wish to not
174 have the default style included, customize the variable
175 `org-export-html-style-include-default'.")
177 (defcustom org-export-html-style-include-default t
178 "Non-nil means include the default style in exported HTML files.
179 The actual style is defined in `org-export-html-style-default' and should
180 not be modified. Use the variables `org-export-html-style' to add
181 your own style information."
182 :group
'org-export-html
185 (put 'org-export-html-style-include-default
'safe-local-variable
'booleanp
)
187 (defcustom org-export-html-style
""
188 "Org-wide style definitions for exported HTML files.
190 This variable needs to contain the full HTML structure to provide a style,
191 including the surrounding HTML tags. If you set the value of this variable,
192 you should consider to include definitions for the following classes:
193 title, todo, done, timestamp, timestamp-kwd, tag, target.
195 For example, a valid value would be:
197 <style type=\"text/css\">
199 p { font-weight: normal; color: gray; }
201 .title { text-align: center; }
202 .todo, .timestamp-kwd { color: red; }
203 .done { color: green; }
207 If you'd like to refer to an external style file, use something like
209 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
211 As the value of this option simply gets inserted into the HTML <head> header,
212 you can \"misuse\" it to add arbitrary text to the header.
213 See also the variable `org-export-html-style-extra'."
214 :group
'org-export-html
217 (put 'org-export-html-style
'safe-local-variable
'stringp
)
219 (defcustom org-export-html-style-extra
""
220 "Additional style information for HTML export.
221 The value of this variable is inserted into the HTML buffer right after
222 the value of `org-export-html-style'. Use this variable for per-file
223 settings of style information, and do not forget to surround the style
224 settings with <style>...</style> tags."
225 :group
'org-export-html
228 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
230 (defcustom org-export-html-mathjax-options
231 '((path "http://orgmode.org/mathjax/MathJax.js")
236 "Options for MathJax setup.
238 path The path where to find MathJax
239 scale Scaling for the HTML-CSS backend, usually between 100 and 133
240 align How to align display math: left, center, or right
241 indent If align is not center, how far from the left/right side?
242 mathml Should a MathML player be used if available?
243 This is faster and reduces bandwidth use, but currently
244 sometimes has lower spacing quality. Therefore, the default is
245 nil. When browsers get better, this switch can be flipped.
247 You can also customize this for each buffer, using something like
249 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
250 :group
'org-export-html
251 :type
'(list :greedy t
252 (list :tag
"path (the path from where to load MathJax.js)"
253 (const :format
" " path
) (string))
254 (list :tag
"scale (scaling for the displayed math)"
255 (const :format
" " scale
) (string))
256 (list :tag
"align (alignment of displayed equations)"
257 (const :format
" " align
) (string))
258 (list :tag
"indent (indentation with left or right alignment)"
259 (const :format
" " indent
) (string))
260 (list :tag
"mathml (should MathML display be used is possible)"
261 (const :format
" " mathml
) (boolean))))
263 (defun org-export-html-mathjax-config (template options in-buffer
)
264 "Insert the user setup into the matchjax template."
265 (let (name val
(yes " ") (no "// ") x
)
268 (setq name
(car e
) val
(nth 1 e
))
269 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
270 (setq val
(car (read-from-string
271 (substring in-buffer
(match-end 0))))))
272 (if (not (stringp val
)) (setq val
(format "%s" val
)))
273 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
274 (setq template
(replace-match val t t template
))))
276 (setq val
(nth 1 (assq 'mathml options
)))
277 (if (string-match (concat "\\<mathml:") in-buffer
)
278 (setq val
(car (read-from-string
279 (substring in-buffer
(match-end 0))))))
280 ;; Exchange prefixes depending on mathml setting
281 (if (not val
) (setq x yes yes no no x
))
282 ;; Replace cookies to turn on or off the config/jax lines
283 (if (string-match ":MMLYES:" template
)
284 (setq template
(replace-match yes t t template
)))
285 (if (string-match ":MMLNO:" template
)
286 (setq template
(replace-match no t t template
)))
287 ;; Return the modified template
290 (defcustom org-export-html-mathjax-template
291 "<script type=\"text/javascript\" src=\"%PATH\">
292 <!--/*--><![CDATA[/*><!--*/
294 // Only one of the two following lines, depending on user settings
295 // First allows browser-native MathML display, second forces HTML/CSS
296 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
297 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
298 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
299 \"TeX/noUndefined.js\"],
301 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
302 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
303 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
304 ignoreClass: \"tex2jax_ignore\",
305 processEscapes: false,
306 processEnvironments: true,
309 showProcessingMessages: true,
310 displayAlign: \"%ALIGN\",
311 displayIndent: \"%INDENT\",
315 availableFonts: [\"STIX\",\"TeX\"],
316 preferredFont: \"TeX\",
332 "The MathJax setup for XHTML files."
333 :group
'org-export-html
336 (defcustom org-export-html-tag-class-prefix
""
337 "Prefix to class names for TODO keywords.
338 Each tag gets a class given by the tag itself, with this prefix.
339 The default prefix is empty because it is nice to just use the keyword
340 as a class name. But if you get into conflicts with other, existing
341 CSS classes, then this prefix can be very useful."
342 :group
'org-export-html
345 (defcustom org-export-html-todo-kwd-class-prefix
""
346 "Prefix to class names for TODO keywords.
347 Each TODO keyword gets a class given by the keyword itself, with this prefix.
348 The default prefix is empty because it is nice to just use the keyword
349 as a class name. But if you get into conflicts with other, existing
350 CSS classes, then this prefix can be very useful."
351 :group
'org-export-html
354 (defcustom org-export-html-preamble t
355 "Non-nil means insert a preamble in HTML export.
357 When `t', insert a string as defined by one of the formatting
358 strings in `org-export-html-preamble-format'. When set to a
359 string, this string overrides `org-export-html-preamble-format'.
360 When set to a function, apply this function and insert the
361 returned string. The function takes the property list of export
362 options as its only argument.
364 Setting :html-preamble in publishing projects will take
365 precedence over this variable."
366 :group
'org-export-html
367 :type
'(choice (const :tag
"No preamble" nil
)
368 (const :tag
"Default preamble" t
)
369 (string :tag
"Custom formatting string")
370 (function :tag
"Function (must return a string)")))
372 (defcustom org-export-html-preamble-format
373 '(("en" "<h1 class=\"title\">%t</h1>"))
374 "The format for the HTML preamble.
376 %t stands for the title.
378 If you need to use a \"%\" character, you need to escape it
380 :group
'org-export-html
383 (defcustom org-export-html-postamble
'auto
384 "Non-nil means insert a postamble in HTML export.
386 When `t', insert a string as defined by the formatting string in
387 `org-export-html-postamble-format'. When set to a string, this
388 string overrides `org-export-html-postamble-format'. When set to
389 'auto, discard `org-export-html-postamble-format' and honor
390 `org-export-author/email/creator-info' variables. When set to a
391 function, apply this function and insert the returned string.
392 The function takes the property list of export options as its
395 Setting :html-postamble in publishing projects will take
396 precedence over this variable."
397 :group
'org-export-html
398 :type
'(choice (const :tag
"No postamble" nil
)
399 (const :tag
"Auto preamble" 'auto
)
400 (const :tag
"Default formatting string" t
)
401 (string :tag
"Custom formatting string")
402 (function :tag
"Function (must return a string)")))
404 (defcustom org-export-html-postamble-format
405 '(("en" "<p class=\"author\">Author: %a (%e)</p>
406 <p class=\"date\">Date: %d</p>
407 <p class=\"creator\">Generated by %c</p>
408 <p class=\"xhtml-validation\">%v</p>
410 "The format for the HTML postamble.
412 %a stands for the author.
413 %e stands for the email(s).
414 %d stands for the date.
415 %c will be replaced by information about Org/Emacs.
416 %v will be replaced by `org-export-html-validation-link'.
418 If you need to use a \"%\" character, you need to escape it
420 :group
'org-export-html
423 (defcustom org-export-html-home
/up-format
424 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
425 <a accesskey=\"h\" href=\"%s\"> UP </a>
427 <a accesskey=\"H\" href=\"%s\"> HOME </a>
429 "Snippet used to insert the HOME and UP links.
430 This is a format string, the first %s will receive the UP link,
431 the second the HOME link. If both `org-export-html-link-up' and
432 `org-export-html-link-home' are empty, the entire snippet will be
434 :group
'org-export-html
437 (defcustom org-export-html-toplevel-hlevel
2
438 "The <H> level for level 1 headings in HTML export.
439 This is also important for the classes that will be wrapped around headlines
440 and outline structure. If this variable is 1, the top-level headlines will
441 be <h1>, and the corresponding classes will be outline-1, section-number-1,
442 and outline-text-1. If this is 2, all of these will get a 2 instead.
443 The default for this variable is 2, because we use <h1> for formatting the
445 :group
'org-export-html
448 (defcustom org-export-html-link-org-files-as-html t
449 "Non-nil means make file links to `file.org' point to `file.html'.
450 When org-mode is exporting an org-mode file to HTML, links to
451 non-html files are directly put into a href tag in HTML.
452 However, links to other Org-mode files (recognized by the
453 extension `.org.) should become links to the corresponding html
454 file, assuming that the linked org-mode file will also be
456 When nil, the links still point to the plain `.org' file."
457 :group
'org-export-html
460 (defcustom org-export-html-inline-images
'maybe
461 "Non-nil means inline images into exported HTML pages.
462 This is done using an <img> tag. When nil, an anchor with href is used to
463 link to the image. If this option is `maybe', then images in links with
464 an empty description will be inlined, while images with a description will
466 :group
'org-export-html
467 :type
'(choice (const :tag
"Never" nil
)
468 (const :tag
"Always" t
)
469 (const :tag
"When there is no description" maybe
)))
471 (defcustom org-export-html-inline-image-extensions
472 '("png" "jpeg" "jpg" "gif" "svg")
473 "Extensions of image files that can be inlined into HTML."
474 :group
'org-export-html
475 :type
'(repeat (string :tag
"Extension")))
477 (defcustom org-export-html-table-tag
478 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
479 "The HTML tag that is used to start a table.
480 This must be a <table> tag, but you may change the options like
481 borders and spacing."
482 :group
'org-export-html
485 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
486 "The opening tag for table header fields.
487 This is customizable so that alignment options can be specified.
488 The first %s will be filled with the scope of the field, either row or col.
489 The second %s will be replaced by a style entry to align the field.
490 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
491 See also the variable `org-export-html-table-align-individual-fields'."
492 :group
'org-export-tables
493 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
495 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
496 "The opening tag for table data fields.
497 This is customizable so that alignment options can be specified.
498 The first %s will be filled with the scope of the field, either row or col.
499 The second %s will be replaced by a style entry to align the field.
500 See also the variable `org-export-html-table-align-individual-fields'."
501 :group
'org-export-tables
502 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
504 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
505 "The opening tag for table data fields.
506 This is customizable so that alignment options can be specified.
507 Instead of strings, these can be Lisp forms that will be evaluated
508 for each row in order to construct the table row tags. During evaluation,
509 the variable `head' will be true when this is a header line, nil when this
510 is a body line. And the variable `nline' will contain the line number,
511 starting from 1 in the first header line. For example
513 (setq org-export-table-row-tags
516 (if (= (mod nline 2) 1)
517 \"<tr class=\\\"tr-odd\\\">\"
518 \"<tr class=\\\"tr-even\\\">\"))
521 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
522 :group
'org-export-tables
524 (choice :tag
"Opening tag"
525 (string :tag
"Specify")
527 (choice :tag
"Closing tag"
528 (string :tag
"Specify")
531 (defcustom org-export-html-table-align-individual-fields t
532 "Non-nil means attach style attributes for alignment to each table field.
533 When nil, alignment will only be specified in the column tags, but this
534 is ignored by some browsers (like Firefox, Safari). Opera does it right
536 :group
'org-export-tables
539 (defcustom org-export-html-table-use-header-tags-for-first-column nil
540 "Non-nil means format column one in tables with header tags.
541 When nil, also column one will use data tags."
542 :group
'org-export-tables
545 (defcustom org-export-html-validation-link
546 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
547 "Link to HTML validation service."
548 :group
'org-export-html
551 ;; FIXME Obsolete since Org 7.7
552 ;; Use the :timestamp option or `org-export-time-stamp-file' instead
553 (defvar org-export-html-with-timestamp nil
554 "If non-nil, write container for HTML-helper-mode timestamp.")
556 ;; FIXME Obsolete since Org 7.7
557 (defvar org-export-html-html-helper-timestamp
558 "\n<p><br/><br/>\n<!-- hhmts start --> <!-- hhmts end --></p>\n"
559 "The HTML tag used as timestamp delimiter for HTML-helper-mode.")
561 (defcustom org-export-html-protect-char-alist
565 "Alist of characters to be converted by `org-html-protect'."
566 :group
'org-export-html
567 :type
'(repeat (cons (string :tag
"Character")
568 (string :tag
"HTML equivalent"))))
570 (defgroup org-export-htmlize nil
571 "Options for processing examples with htmlize.el."
572 :tag
"Org Export Htmlize"
573 :group
'org-export-html
)
575 (defcustom org-export-htmlize-output-type
'inline-css
576 "Output type to be used by htmlize when formatting code snippets.
577 Choices are `css', to export the CSS selectors only, or `inline-css', to
578 export the CSS attribute values inline in the HTML. We use as default
579 `inline-css', in order to make the resulting HTML self-containing.
581 However, this will fail when using Emacs in batch mode for export, because
582 then no rich font definitions are in place. It will also not be good if
583 people with different Emacs setup contribute HTML files to a website,
584 because the fonts will represent the individual setups. In these cases,
585 it is much better to let Org/Htmlize assign classes only, and to use
586 a style file to define the look of these classes.
587 To get a start for your css file, start Emacs session and make sure that
588 all the faces you are interested in are defined, for example by loading files
589 in all modes you want. Then, use the command
590 \\[org-export-htmlize-generate-css] to extract class definitions."
591 :group
'org-export-htmlize
592 :type
'(choice (const css
) (const inline-css
)))
594 (defcustom org-export-htmlize-css-font-prefix
"org-"
595 "The prefix for CSS class names for htmlize font specifications."
596 :group
'org-export-htmlize
599 (defcustom org-export-htmlized-org-css-url nil
600 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
601 Normally when creating an htmlized version of an Org buffer, htmlize will
602 create CSS to define the font colors. However, this does not work when
603 converting in batch mode, and it also can look bad if different people
604 with different fontification setup work on the same website.
605 When this variable is non-nil, creating an htmlized version of an Org buffer
606 using `org-export-as-org' will remove the internal CSS section and replace it
607 with a link to this URL."
608 :group
'org-export-htmlize
610 (const :tag
"Keep internal css" nil
)
611 (string :tag
"URL or local href")))
613 ;; FIXME: The following variable is obsolete since Org 7.7 but is
614 ;; still declared and checked within code for compatibility reasons.
615 ;; Use the custom variables `org-export-html-divs' instead.
616 (defvar org-export-html-content-div
"content"
617 "The name of the container DIV that holds all the page contents.
619 This variable is obsolete since Org version 7.7.
620 Please set `org-export-html-divs' instead.")
622 (defcustom org-export-html-divs
'("preamble" "content" "postamble")
623 "The name of the main divs for HTML export."
624 :group
'org-export-html
626 (string :tag
" Div for the preamble:")
627 (string :tag
" Div for the content:")
628 (string :tag
"Div for the postamble:")))
632 (defvar org-export-html-after-blockquotes-hook nil
633 "Hook run during HTML export, after blockquote, verse, center are done.")
635 (defvar org-export-html-final-hook nil
636 "Hook run at the end of HTML export, in the new buffer.")
640 (defun org-export-html-preprocess (parameters)
641 "Convert LaTeX fragments to images."
642 (when (and org-current-export-file
643 (plist-get parameters
:LaTeX-fragments
))
645 (concat "ltxpng/" (file-name-sans-extension
646 (file-name-nondirectory
647 org-current-export-file
)))
648 org-current-export-dir nil
"Creating LaTeX image %s"
651 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
652 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
653 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
654 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
656 (goto-char (point-min))
658 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
659 (org-if-unprotected-at (match-beginning 1)
660 (setq label
(match-string 1))
662 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
663 (setq l1
(substring label
(match-beginning 1)))
665 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
668 (defun org-export-as-html-and-open (arg)
669 "Export the outline as HTML and immediately open it with a browser.
670 If there is an active region, export only the region.
671 The prefix ARG specifies how many levels of the outline should become
672 headlines. The default is 3. Lower levels will become bulleted lists."
674 (org-export-as-html arg
'hidden
)
675 (org-open-file buffer-file-name
)
676 (when org-export-kill-product-buffer-when-displayed
677 (kill-buffer (current-buffer))))
680 (defun org-export-as-html-batch ()
681 "Call the function `org-export-as-html'.
682 This function can be used in batch processing as:
684 --load=$HOME/lib/emacs/org.el
685 --eval \"(setq org-export-headline-levels 2)\"
686 --visit=MyFile --funcall org-export-as-html-batch"
687 (org-export-as-html org-export-headline-levels
'hidden
))
690 (defun org-export-as-html-to-buffer (arg)
691 "Call `org-export-as-html` with output to a temporary buffer.
692 No file is created. The prefix ARG is passed through to `org-export-as-html'."
694 (org-export-as-html arg nil nil
"*Org HTML Export*")
695 (when org-export-show-temporary-export-buffer
696 (switch-to-buffer-other-window "*Org HTML Export*")))
699 (defun org-replace-region-by-html (beg end
)
700 "Assume the current region has org-mode syntax, and convert it to HTML.
701 This can be used in any buffer. For example, you could write an
702 itemized list in org-mode syntax in an HTML buffer and then use this
703 command to convert it."
705 (let (reg html buf pop-up-frames
)
706 (save-window-excursion
708 (setq html
(org-export-region-as-html
710 (setq reg
(buffer-substring beg end
)
711 buf
(get-buffer-create "*Org tmp*"))
712 (with-current-buffer buf
716 (setq html
(org-export-region-as-html
717 (point-min) (point-max) t
'string
)))
719 (delete-region beg end
)
723 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
724 "Convert region from BEG to END in org-mode buffer to HTML.
725 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
726 contents, and only produce the region of converted text, useful for
727 cut-and-paste operations.
728 If BUFFER is a buffer or a string, use/create that buffer as a target
729 of the converted HTML. If BUFFER is the symbol `string', return the
730 produced HTML as a string and leave not buffer behind. For example,
731 a Lisp program could call this function in the following way:
733 (setq html (org-export-region-as-html beg end t 'string))
735 When called interactively, the output buffer is selected, and shown
736 in a window. A non-interactive call will only return the buffer."
738 (when (org-called-interactively-p 'any
)
739 (setq buffer
"*Org HTML Export*"))
740 (let ((transient-mark-mode t
) (zmacs-regions t
)
742 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
744 (set-mark (point)) ;; to activate the region
746 (setq rtn
(org-export-as-html
749 (if (fboundp 'deactivate-mark
) (deactivate-mark))
750 (if (and (org-called-interactively-p 'any
) (bufferp rtn
))
751 (switch-to-buffer-other-window rtn
)
754 (defvar html-table-tag nil
) ; dynamically scoped into this.
755 (defvar org-par-open nil
)
757 ;;; org-html-cvt-link-fn
758 (defconst org-html-cvt-link-fn
760 "Function to convert link URLs to exportable URLs.
761 Takes two arguments, TYPE and PATH.
762 Returns exportable url as (TYPE PATH), or nil to signal that it
763 didn't handle this case.
764 Intended to be locally bound around a call to `org-export-as-html'." )
766 (defun org-html-cvt-org-as-html (opt-plist type path
)
767 "Convert an org filename to an equivalent html filename.
768 If TYPE is not file, just return `nil'.
769 See variable `org-export-html-link-org-files-as-html'"
773 org-export-html-link-org-files-as-html
774 (string= type
"file")
775 (string-match "\\.org$" path
)
780 (substring path
0 (match-beginning 0))
782 (plist-get opt-plist
:html-extension
)))))))
785 ;;; org-html-should-inline-p
786 (defun org-html-should-inline-p (filename descp
)
787 "Return non-nil if link FILENAME should be inlined.
788 The decision to inline the FILENAME link is based on the current
789 settings. DESCP is the boolean of whether there was a link
790 description. See variables `org-export-html-inline-images' and
791 `org-export-html-inline-image-extensions'."
793 org-export-html-inline-images
794 org-export-html-inline-image-extensions
))
795 (and (or (eq t org-export-html-inline-images
)
796 (and org-export-html-inline-images
(not descp
)))
798 filename org-export-html-inline-image-extensions
)))
800 ;;; org-html-make-link
801 (defun org-html-make-link (opt-plist type path fragment desc attr
804 OPT-PLIST is an options list.
805 TYPE is the device-type of the link (THIS://foo.html)
806 PATH is the path of the link (http://THIS#locationx)
807 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
808 DESC is the link description, if any.
809 ATTR is a string of other attributes of the a element.
810 MAY-INLINE-P allows inlining it as an image."
812 (declare (special org-par-open
))
814 (let* ((filename path
)
815 ;;First pass. Just sanity stuff.
818 ((string= type
"file")
821 ;;Substitute just if original path was absolute.
822 ;;(Otherwise path must remain relative)
823 (if (file-name-absolute-p path
)
824 (concat "file://" (expand-file-name path
))
828 (t (list type path
))))
830 ;;Second pass. Components converted so they can refer
834 (and org-html-cvt-link-fn
835 (apply org-html-cvt-link-fn
836 opt-plist components-1
))
837 (apply #'org-html-cvt-org-as-html
838 opt-plist components-1
)
840 (type (first components-2
))
841 (thefile (second components-2
)))
844 ;;Third pass. Build final link except for leading type
849 (string= type
"http")
850 (string= type
"https")
851 (string= type
"file")
852 (string= type
"coderef"))
854 (setq thefile
(concat thefile
"#" fragment
))))
858 ;;Final URL-build, for all types.
861 ((str (org-export-html-format-href thefile
)))
862 (if (and type
(not (or (string= "file" type
)
863 (string= "coderef" type
))))
864 (concat type
":" str
)
869 ;;Can't inline a URL with a fragment.
872 (message "image %s %s" thefile org-par-open
)
873 (org-export-html-format-image thefile org-par-open
))
875 "<a href=\"" thefile
"\"" (if attr
(concat " " attr
)) ">"
876 (org-export-html-format-desc desc
)
879 (defun org-html-handle-links (line opt-plist
)
880 "Return LINE with markup of Org mode links.
881 OPT-PLIST is the export options list."
883 (current-dir (if buffer-file-name
884 (file-name-directory buffer-file-name
)
886 (link-validate (plist-get opt-plist
:link-validation-function
))
888 rpl path attr desc descp desc1 desc2 link
)
889 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
890 (setq start
(match-beginning 0))
891 (setq path
(save-match-data (org-link-unescape
892 (match-string 3 line
))))
894 ((match-end 2) (match-string 2 line
))
896 (or (file-name-absolute-p path
)
897 (string-match "^\\.\\.?/" path
)))
900 (setq path
(org-extract-attributes (org-link-unescape path
)))
901 (setq attr
(get-text-property 0 'org-attributes path
))
902 (setq desc1
(if (match-end 5) (match-string 5 line
))
903 desc2
(if (match-end 2) (concat type
":" path
) path
)
904 descp
(and desc1
(not (equal desc1 desc2
)))
905 desc
(or desc1 desc2
))
906 ;; Make an image out of the description if that is so wanted
907 (when (and descp
(org-file-image-p
908 desc org-export-html-inline-image-extensions
))
910 (if (string-match "^file:" desc
)
911 (setq desc
(substring desc
(match-end 0)))))
912 (setq desc
(org-add-props
913 (concat "<img src=\"" desc
"\" alt=\""
914 (file-name-nondirectory desc
) "\"/>")
915 '(org-protected t
))))
917 ((equal type
"internal")
920 (if (= (string-to-char path
) ?
#)
928 (org-solidify-link-text
929 (save-match-data (org-link-unescape frag-0
))
932 ((and (equal type
"id")
933 (setq id-file
(org-id-find-id-file path
)))
934 ;; This is an id: link to another file (if it was the same file,
935 ;; it would have become an internal link...)
937 (setq id-file
(file-relative-name
939 (file-name-directory org-current-export-file
)))
941 (org-html-make-link opt-plist
943 (concat (if (org-uuidgen-p path
) "ID-") path
)
947 ((member type
'("http" "https"))
948 ;; standard URL, can inline as image
950 (org-html-make-link opt-plist
954 (org-html-should-inline-p path descp
))))
955 ((member type
'("ftp" "mailto" "news"))
956 ;; standard URL, can't inline as image
958 (org-html-make-link opt-plist
964 ((string= type
"coderef")
966 ((coderef-str (format "coderef-%s" path
))
968 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
969 coderef-str coderef-str
)))
971 (org-html-make-link opt-plist
974 (org-export-get-coderef-format
977 (cdr (assoc path org-export-code-refs
)))
981 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
982 ;; The link protocol has a function for format the link
985 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
987 ((string= type
"file")
993 (string-match "::\\(.*\\)" path
)
995 (replace-match "" t nil path
)
996 (match-string 1 path
))
999 ;;The proper path, without a fragment
1005 (second components
))
1007 ;;Check the fragment. If it can't be used as
1008 ;;target fragment we'll pass nil instead.
1012 (not (string-match "^[0-9]*$" fragment-0
))
1013 (not (string-match "^\\*" fragment-0
))
1014 (not (string-match "^/.*/$" fragment-0
)))
1015 (org-solidify-link-text
1016 (org-link-unescape fragment-0
))
1019 ;;Description minus "file:" and ".org"
1020 (if (string-match "^file:" desc
)
1022 ((desc-1 (replace-match "" t t desc
)))
1023 (if (string-match "\\.org$" desc-1
)
1024 (replace-match "" t t desc-1
)
1031 (functionp link-validate
)
1032 (not (funcall link-validate path-1 current-dir
)))
1034 (org-html-make-link opt-plist
1035 "file" path-1 fragment-1 desc-2 attr
1036 (org-html-should-inline-p path-1 descp
)))))))
1039 ;; just publish the path, as default
1040 (setq rpl
(concat "@<i><" type
":"
1041 (save-match-data (org-link-unescape path
))
1043 (setq line
(replace-match rpl t t line
)
1044 start
(+ start
(length rpl
))))
1047 ;;; org-export-as-html
1049 (defun org-export-as-html (arg &optional hidden ext-plist
1050 to-buffer body-only pub-dir
)
1051 "Export the outline as a pretty HTML file.
1052 If there is an active region, export only the region. The prefix
1053 ARG specifies how many levels of the outline should become
1054 headlines. The default is 3. Lower levels will become bulleted
1055 lists. HIDDEN is obsolete and does nothing.
1056 EXT-PLIST is a property list with external parameters overriding
1057 org-mode's default settings, but still inferior to file-local
1058 settings. When TO-BUFFER is non-nil, create a buffer with that
1059 name and export to that buffer. If TO-BUFFER is the symbol
1060 `string', don't leave any buffer behind but just return the
1061 resulting HTML as a string. When BODY-ONLY is set, don't produce
1062 the file header and footer, simply return the content of
1063 <body>...</body>, without even the body tags themselves. When
1064 PUB-DIR is set, use this as the publishing directory."
1066 (run-hooks 'org-export-first-hook
)
1068 ;; Make sure we have a file name when we need it.
1069 (when (and (not (or to-buffer body-only
))
1070 (not buffer-file-name
))
1071 (if (buffer-base-buffer)
1072 (org-set-local 'buffer-file-name
1073 (with-current-buffer (buffer-base-buffer)
1075 (error "Need a file name to be able to export")))
1077 (message "Exporting...")
1078 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1079 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1080 (setq-default org-done-keywords org-done-keywords
)
1081 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1083 (org-export-process-option-filters
1084 (org-combine-plists (org-default-export-plist)
1086 (org-infile-export-plist))))
1087 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1088 (style (concat (if (plist-get opt-plist
:style-include-default
)
1089 org-export-html-style-default
)
1090 (plist-get opt-plist
:style
)
1091 (plist-get opt-plist
:style-extra
)
1093 (if (plist-get opt-plist
:style-include-scripts
)
1094 org-export-html-scripts
)))
1095 (html-extension (plist-get opt-plist
:html-extension
))
1096 valid thetoc have-headings first-heading-pos
1097 (odd org-odd-levels-only
)
1098 (region-p (org-region-active-p))
1099 (rbeg (and region-p
(region-beginning)))
1100 (rend (and region-p
(region-end)))
1102 (if (plist-get opt-plist
:ignore-subtree-p
)
1107 (and (org-at-heading-p)
1108 (>= (org-end-of-subtree t t
) rend
))))))
1109 (level-offset (if subtree-p
1112 (+ (funcall outline-level
)
1113 (if org-odd-levels-only
1 0)))
1115 (opt-plist (setq org-export-opt-plist
1117 (org-export-add-subtree-options opt-plist rbeg
)
1119 ;; The following two are dynamically scoped into other
1121 (org-current-export-dir
1122 (or pub-dir
(org-export-directory :html opt-plist
)))
1123 (org-current-export-file buffer-file-name
)
1124 (level 0) (line "") (origline "") txt todo
1127 (filename (if to-buffer nil
1130 (file-name-sans-extension
1132 (org-entry-get (region-beginning)
1133 "EXPORT_FILE_NAME" t
))
1134 (file-name-nondirectory buffer-file-name
)))
1136 (file-name-as-directory
1137 (or pub-dir
(org-export-directory :html opt-plist
))))))
1138 (current-dir (if buffer-file-name
1139 (file-name-directory buffer-file-name
)
1141 (buffer (if to-buffer
1143 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
1144 (t (get-buffer-create to-buffer
)))
1145 (find-file-noselect filename
)))
1146 (org-levels-open (make-vector org-level-max nil
))
1147 (date (plist-get opt-plist
:date
))
1148 (author (plist-get opt-plist
:author
))
1149 (html-validation-link (or org-export-html-validation-link
""))
1150 (title (org-html-expand
1151 (or (and subtree-p
(org-export-get-title-from-subtree))
1152 (plist-get opt-plist
:title
)
1153 (and (not body-only
)
1155 (plist-get opt-plist
:skip-before-1st-heading
))
1156 (org-export-grab-title-from-buffer))
1157 (and buffer-file-name
1158 (file-name-sans-extension
1159 (file-name-nondirectory buffer-file-name
)))
1161 (link-up (and (plist-get opt-plist
:link-up
)
1162 (string-match "\\S-" (plist-get opt-plist
:link-up
))
1163 (plist-get opt-plist
:link-up
)))
1164 (link-home (and (plist-get opt-plist
:link-home
)
1165 (string-match "\\S-" (plist-get opt-plist
:link-home
))
1166 (plist-get opt-plist
:link-home
)))
1167 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1168 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1169 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1170 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
1174 (email (plist-get opt-plist
:email
))
1175 (language (plist-get opt-plist
:language
))
1176 (keywords (plist-get opt-plist
:keywords
))
1177 (description (plist-get opt-plist
:description
))
1178 (num (plist-get opt-plist
:section-numbers
))
1182 (coding-system (and (boundp 'buffer-file-coding-system
)
1183 buffer-file-coding-system
))
1184 (coding-system-for-write (or org-export-html-coding-system
1186 (save-buffer-coding-system (or org-export-html-coding-system
1188 (charset (and coding-system-for-write
1189 (fboundp 'coding-system-get
)
1190 (coding-system-get coding-system-for-write
1194 (if region-p
(region-beginning) (point-min))
1195 (if region-p
(region-end) (point-max))))
1196 (org-export-have-math nil
)
1197 (org-export-footnotes-seen nil
)
1198 (org-export-footnotes-data (org-footnote-all-labels 'with-defs
))
1201 (org-export-preprocess-string
1205 :skip-before-1st-heading
1206 (plist-get opt-plist
:skip-before-1st-heading
)
1207 :drawers
(plist-get opt-plist
:drawers
)
1208 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1209 :tasks
(plist-get opt-plist
:tasks
)
1210 :tags
(plist-get opt-plist
:tags
)
1211 :priority
(plist-get opt-plist
:priority
)
1212 :footnotes
(plist-get opt-plist
:footnotes
)
1213 :timestamps
(plist-get opt-plist
:timestamps
)
1215 (plist-get opt-plist
:archived-trees
)
1216 :select-tags
(plist-get opt-plist
:select-tags
)
1217 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1219 (plist-get opt-plist
:text
)
1221 (plist-get opt-plist
:LaTeX-fragments
))
1224 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
1225 (and org-export-have-math
1226 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
1228 (org-export-html-mathjax-config
1229 org-export-html-mathjax-template
1230 org-export-html-mathjax-options
1231 (or (plist-get opt-plist
:mathjax
) ""))
1234 table-buffer table-orig-buffer
1236 rpl path attr desc descp desc1 desc2 link
1238 footnotes footref-seen
1242 (let ((inhibit-read-only t
))
1244 (remove-text-properties (point-min) (point-max)
1245 '(:org-license-to-kill t
))))
1247 (message "Exporting...")
1249 (setq org-min-level
(org-get-min-level lines level-offset
))
1250 (setq org-last-level org-min-level
)
1251 (org-init-section-numbers)
1254 ((and date
(string-match "%" date
))
1255 (setq date
(format-time-string date
)))
1257 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
1259 ;; Get the language-dependent settings
1260 (setq lang-words
(or (assoc language org-export-language-setup
)
1261 (assoc "en" org-export-language-setup
)))
1263 ;; Switch to the output buffer
1265 (let ((inhibit-read-only t
)) (erase-buffer))
1267 (org-install-letbind)
1269 (and (fboundp 'set-buffer-file-coding-system
)
1270 (set-buffer-file-coding-system coding-system-for-write
))
1272 (let ((case-fold-search nil
)
1273 (org-odd-levels-only odd
))
1274 ;; create local variables for all options, to make sure all called
1275 ;; functions get the correct information
1277 (set (make-local-variable (nth 2 x
))
1278 (plist-get opt-plist
(car x
))))
1279 org-export-plist-vars
)
1280 (setq umax
(if arg
(prefix-numeric-value arg
)
1281 org-export-headline-levels
))
1282 (setq umax-toc
(if (integerp org-export-with-toc
)
1283 (min org-export-with-toc umax
)
1289 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
1290 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
1291 <html xmlns=\"http://www.w3.org/1999/xhtml\"
1292 lang=\"%s\" xml:lang=\"%s\">
1295 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
1296 <meta name=\"generator\" content=\"Org-mode\"/>
1297 <meta name=\"generated\" content=\"%s\"/>
1298 <meta name=\"author\" content=\"%s\"/>
1299 <meta name=\"description\" content=\"%s\"/>
1300 <meta name=\"keywords\" content=\"%s\"/>
1308 (or (and (stringp org-export-html-xml-declaration
)
1309 org-export-html-xml-declaration
)
1310 (cdr (assoc html-extension org-export-html-xml-declaration
))
1311 (cdr (assoc "html" org-export-html-xml-declaration
))
1314 (or charset
"iso-8859-1"))
1317 (or charset
"iso-8859-1")
1318 date author description keywords
1321 (if (or link-up link-home
)
1323 (format org-export-html-home
/up-format
1324 (or link-up link-home
)
1325 (or link-home link-up
))
1329 ;; insert html preamble
1330 (when (plist-get opt-plist
:html-preamble
)
1331 (let ((html-pre (plist-get opt-plist
:html-preamble
)))
1332 (insert "<div id=\"" (nth 0 org-export-html-divs
) "\">\n")
1333 (cond ((stringp html-pre
)
1335 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
1336 (?d .
,date
) (?e .
,email
)))))
1337 ((functionp html-pre
)
1342 (or (cadr (assoc (nth 0 lang-words
)
1343 org-export-html-preamble-format
))
1344 (cadr (assoc "en" org-export-html-preamble-format
)))
1345 `((?t .
,title
) (?a .
,author
)
1346 (?d .
,date
) (?e .
,email
))))))
1347 (insert "\n</div>\n")))
1349 ;; begin wrap around body
1350 (insert (format "\n<div id=\"%s\">"
1351 (or org-export-html-content-div
; <= FIXME obsolete since 7.7
1352 (nth 1 org-export-html-divs
)))))
1355 (if (and org-export-with-toc
(not body-only
))
1357 (push (format "<h%d>%s</h%d>\n"
1358 org-export-html-toplevel-hlevel
1360 org-export-html-toplevel-hlevel
)
1362 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
1363 (push "<ul>\n<li>" thetoc
)
1365 (mapcar #'(lambda (line)
1366 (if (and (string-match org-todo-line-regexp line
)
1367 (not (get-text-property 0 'org-protected line
)))
1368 ;; This is a headline
1370 (setq have-headings t
)
1371 (setq level
(- (match-end 1) (match-beginning 1)
1373 level
(org-tr-level level
)
1374 txt
(save-match-data
1376 (org-export-cleanup-toc-line
1377 (match-string 3 line
))))
1379 (or (and org-export-mark-todo-in-toc
1381 (not (member (match-string 2 line
)
1382 org-done-keywords
)))
1384 (and org-export-mark-todo-in-toc
1386 (org-search-todo-below
1387 line lines level
))))
1389 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
1390 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
1391 (if (string-match quote-re0 txt
)
1392 (setq txt
(replace-match "" t t txt
)))
1393 (setq snumber
(org-section-number level
))
1394 (if (and num
(if (integerp num
)
1397 (setq txt
(concat snumber
" " txt
)))
1398 (if (<= level
(max umax umax-toc
))
1399 (setq head-count
(+ head-count
1)))
1400 (if (<= level umax-toc
)
1402 (if (> level org-last-level
)
1404 (setq cnt
(- level org-last-level
))
1405 (while (>= (setq cnt
(1- cnt
)) 0)
1406 (push "\n<ul>\n<li>" thetoc
))
1407 (push "\n" thetoc
)))
1408 (if (< level org-last-level
)
1410 (setq cnt
(- org-last-level level
))
1411 (while (>= (setq cnt
(1- cnt
)) 0)
1412 (push "</li>\n</ul>" thetoc
))
1413 (push "\n" thetoc
)))
1414 ;; Check for targets
1415 (while (string-match org-any-target-regexp line
)
1416 (setq line
(replace-match
1417 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
1419 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
1420 (setq txt
(replace-match "" t t txt
)))
1422 (replace-regexp-in-string
1423 "\\." "-" (format "sec-%s" snumber
)))
1424 (setq href
(org-solidify-link-text (or (cdr (assoc href org-export-preferred-target-alist
)) href
)))
1428 "</li>\n<li><a href=\"#%s\"><span class=\"todo\">%s</span></a>"
1429 "</li>\n<li><a href=\"#%s\">%s</a>")
1432 (setq org-last-level level
))
1436 (while (> org-last-level
(1- org-min-level
))
1437 (setq org-last-level
(1- org-last-level
))
1438 (push "</li>\n</ul>\n" thetoc
))
1439 (push "</div>\n" thetoc
)
1440 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1443 (org-init-section-numbers)
1447 (while (setq line
(pop lines
) origline line
)
1450 ;; end of quote section?
1451 (when (and inquote
(string-match org-outline-regexp-bol line
))
1455 ;; inside a quote section?
1457 (insert (org-html-protect line
) "\n")
1458 (throw 'nextline nil
))
1460 ;; Fixed-width, verbatim lines (examples)
1461 (when (and org-export-with-fixed-width
1462 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1465 (org-close-par-maybe)
1467 (insert "<pre class=\"example\">\n"))
1468 (insert (org-html-protect (match-string 3 line
)) "\n")
1469 (when (or (not lines
)
1470 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1475 (throw 'nextline nil
))
1478 (when (and (get-text-property 0 'org-protected line
)
1479 ;; Make sure it is the entire line that is protected
1480 (not (< (or (next-single-property-change
1481 0 'org-protected line
) 10000)
1483 (let (par (ind (get-text-property 0 'original-indentation line
)))
1484 (when (re-search-backward
1485 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
1486 (setq par
(match-string 1))
1487 (replace-match "\\2\n"))
1490 (or (= (length (car lines
)) 0)
1492 (equal ind
(get-text-property 0 'original-indentation
(car lines
))))
1493 (or (= (length (car lines
)) 0)
1494 (get-text-property 0 'org-protected
(car lines
))))
1495 (insert (pop lines
) "\n"))
1496 (and par
(insert "<p>\n")))
1497 (throw 'nextline nil
))
1499 ;; Blockquotes, verse, and center
1500 (when (equal "ORG-BLOCKQUOTE-START" line
)
1501 (org-close-par-maybe)
1502 (insert "<blockquote>\n")
1504 (throw 'nextline nil
))
1505 (when (equal "ORG-BLOCKQUOTE-END" line
)
1506 (org-close-par-maybe)
1507 (insert "\n</blockquote>\n")
1509 (throw 'nextline nil
))
1510 (when (equal "ORG-VERSE-START" line
)
1511 (org-close-par-maybe)
1512 (insert "\n<p class=\"verse\">\n")
1513 (setq org-par-open t
)
1515 (throw 'nextline nil
))
1516 (when (equal "ORG-VERSE-END" line
)
1518 (setq org-par-open nil
)
1521 (throw 'nextline nil
))
1522 (when (equal "ORG-CENTER-START" line
)
1523 (org-close-par-maybe)
1524 (insert "\n<div style=\"text-align: center\">")
1526 (throw 'nextline nil
))
1527 (when (equal "ORG-CENTER-END" line
)
1528 (org-close-par-maybe)
1531 (throw 'nextline nil
))
1532 (run-hooks 'org-export-html-after-blockquotes-hook
)
1534 (let ((i (org-get-string-indentation line
)))
1536 (setq line
(concat (mapconcat 'identity
1537 (make-list (* 2 i
) "\\nbsp") "")
1538 " " (org-trim line
))))
1539 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1540 (setq line
(concat line
"\\\\")))))
1542 ;; make targets to anchors
1544 (while (string-match
1545 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1547 ((get-text-property (match-beginning 1) 'org-protected line
)
1548 (setq start
(match-end 1)))
1550 (setq line
(replace-match
1552 "@<a name=\"%s\" id=\"%s\">@</a>"
1553 (org-solidify-link-text (match-string 1 line
))
1554 (org-solidify-link-text (match-string 1 line
)))
1556 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1557 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1558 (setq line
(replace-match
1559 (concat "@<span class=\"target\">"
1560 (match-string 1 line
) "@</span> ")
1561 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1564 (setq line
(replace-match
1565 (concat "@<a name=\""
1566 (org-solidify-link-text (match-string 1 line
))
1567 "\" class=\"target\">" (match-string 1 line
)
1571 (setq line
(org-html-handle-time-stamps line
))
1573 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1574 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1575 ;; Also handle sub_superscripts and checkboxes
1576 (or (string-match org-table-hline-regexp line
)
1577 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line
)
1578 (setq line
(org-html-expand line
)))
1581 (setq line
(org-html-handle-links line opt-plist
))
1584 (if (and (string-match org-todo-line-regexp line
)
1585 (match-beginning 2))
1588 (concat (substring line
0 (match-beginning 2))
1590 (if (member (match-string 2 line
)
1593 " " (match-string 2 line
)
1594 "\"> " (org-export-html-get-todo-kwd-class-name
1595 (match-string 2 line
))
1596 "</span>" (substring line
(match-end 2)))))
1598 ;; Does this contain a reference to a footnote?
1599 (when org-export-with-footnotes
1601 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
1602 ;; Discard protected matches not clearly identified as
1603 ;; footnote markers.
1604 (if (or (get-text-property (match-beginning 2) 'org-protected line
)
1605 (not (get-text-property (match-beginning 2) 'org-footnote line
)))
1606 (setq start
(match-end 2))
1607 (let ((n (match-string 2 line
)) extra a
)
1608 (if (setq a
(assoc n footref-seen
))
1610 (setcdr a
(1+ (cdr a
)))
1611 (setq extra
(format ".%d" (cdr a
))))
1613 (push (cons n
1) footref-seen
))
1619 (format org-export-html-footnote-format
1620 (concat "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>")))
1621 (or (match-string 1 line
) "") n extra n n
)
1622 ;; If another footnote is following the
1623 ;; current one, add a separator.
1624 (if (save-match-data
1625 (string-match "\\`\\[[0-9]+\\]"
1626 (substring line
(match-end 0))))
1627 org-export-html-footnote-separator
1632 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1633 ;; This is a headline
1634 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1636 txt
(match-string 2 line
))
1637 (if (string-match quote-re0 txt
)
1638 (setq txt
(replace-match "" t t txt
)))
1639 (if (<= level
(max umax umax-toc
))
1640 (setq head-count
(+ head-count
1)))
1641 (setq first-heading-pos
(or first-heading-pos
(point)))
1642 (org-html-level-start level txt umax
1643 (and org-export-with-toc
(<= level umax
))
1644 head-count opt-plist
)
1647 (when (string-match quote-re line
)
1648 (org-close-par-maybe)
1652 ((and org-export-with-tables
1653 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1654 (when (not table-open
)
1656 (setq table-open t table-buffer nil table-orig-buffer nil
))
1659 (setq table-buffer
(cons line table-buffer
)
1660 table-orig-buffer
(cons origline table-orig-buffer
))
1661 (when (or (not lines
)
1662 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1664 (setq table-open nil
1665 table-buffer
(nreverse table-buffer
)
1666 table-orig-buffer
(nreverse table-orig-buffer
))
1667 (org-close-par-maybe)
1668 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1673 ;; This line either is list item or end a list.
1674 (when (get-text-property 0 'list-item line
)
1675 (setq line
(org-html-export-list-line
1677 (get-text-property 0 'list-item line
)
1678 (get-text-property 0 'list-struct line
)
1679 (get-text-property 0 'list-prevs line
))))
1682 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1684 (insert "\n</p>\n<hr/>\n<p>\n")
1685 (insert "\n<hr/>\n"))
1686 (throw 'nextline nil
))
1688 ;; Empty lines start a new paragraph. If hand-formatted lists
1689 ;; are not fully interpreted, lines starting with "-", "+", "*"
1690 ;; also start a new paragraph.
1691 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
1693 ;; Is this the start of a footnote?
1694 (when org-export-with-footnotes
1695 (when (and (boundp 'footnote-section-tag-regexp
)
1696 (string-match (concat "^" footnote-section-tag-regexp
)
1699 (throw 'nextline nil
))
1700 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1701 (org-close-par-maybe)
1702 (let ((n (match-string 1 line
)))
1703 (setq org-par-open t
1706 (concat "<p class=\"footnote\">"
1707 (format org-export-html-footnote-format
1708 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>"))
1709 n n n
) t t line
)))))
1710 ;; Check if the line break needs to be conserved
1712 ((string-match "\\\\\\\\[ \t]*$" line
)
1713 (setq line
(replace-match "<br/>" t t line
)))
1714 (org-export-preserve-breaks
1715 (setq line
(concat line
"<br/>"))))
1717 ;; Check if a paragraph should be started
1719 (while (and org-par-open
1720 (string-match "\\\\par\\>" line start
))
1721 ;; Leave a space in the </p> so that the footnote matcher
1722 ;; does not see this.
1723 (if (not (get-text-property (match-beginning 0)
1724 'org-protected line
))
1725 (setq line
(replace-match "</p ><p >" t t line
)))
1726 (setq start
(match-end 0))))
1728 (insert line
"\n")))))
1730 ;; Properly close all local lists and other lists
1735 (org-html-level-start 1 nil umax
1736 (and org-export-with-toc
(<= level umax
))
1737 head-count opt-plist
)
1738 ;; the </div> to close the last text-... div.
1739 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
1742 (goto-char (point-min))
1743 (while (re-search-forward
1744 "\\(\\(<p class=\"footnote\">\\)[^\000]*?\\)\\(\\(\\2\\)\\|\\'\\)"
1746 (push (match-string 1) footnotes
)
1747 (replace-match "\\4" t nil
)
1748 (goto-char (match-beginning 0))))
1750 (insert (format org-export-html-footnotes-section
1752 (mapconcat 'identity
(nreverse footnotes
) "\n"))
1754 (let ((bib (org-export-html-get-bibliography)))
1756 (insert "\n" bib
"\n")))
1759 ;; end wrap around body
1762 ;; export html postamble
1763 (let ((html-post (plist-get opt-plist
:html-postamble
))
1765 (mapconcat (lambda(e)
1766 (format "<a href=\"mailto:%s\">%s</a>" e e
))
1767 (split-string email
",+ *")
1770 (concat "Org version " org-version
" with Emacs version "
1771 (number-to-string emacs-major-version
))))
1773 (when (plist-get opt-plist
:html-postamble
)
1774 (insert "\n<div id=\"" (nth 2 org-export-html-divs
) "\">\n")
1775 (cond ((stringp html-post
)
1776 (insert (format-spec html-post
1777 `((?a .
,author
) (?e .
,email
)
1778 (?d .
,date
) (?c .
,creator-info
)
1779 (?v .
,html-validation-link
)))))
1780 ((functionp html-post
)
1781 (funcall html-post
))
1782 ((eq html-post
'auto
)
1783 ;; fall back on default postamble
1784 (when (plist-get opt-plist
:time-stamp-file
)
1785 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
1786 (when (and (plist-get opt-plist
:author-info
) author
)
1787 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
1788 (when (and (plist-get opt-plist
:email-info
) email
)
1789 (insert "<p class=\"email\">" email
"</p>\n"))
1790 (when (plist-get opt-plist
:creator-info
)
1791 (insert "<p class=\"creator\">"
1792 (concat "Org version " org-version
" with Emacs version "
1793 (number-to-string emacs-major-version
) "</p>\n")))
1794 (insert html-validation-link
"\n"))
1796 (insert (format-spec
1797 (or (cadr (assoc (nth 0 lang-words
)
1798 org-export-html-postamble-format
))
1799 (cadr (assoc "en" org-export-html-postamble-format
)))
1800 `((?a .
,author
) (?e .
,email
)
1801 (?d .
,date
) (?c .
,creator-info
)
1802 (?v .
,html-validation-link
))))))
1803 (insert "\n</div>"))))
1805 ;; FIXME `org-export-html-with-timestamp' has been declared
1806 ;; obsolete since Org 7.7 -- don't forget to remove this.
1807 (if org-export-html-with-timestamp
1808 (insert org-export-html-html-helper-timestamp
))
1810 (unless body-only
(insert "\n</body>\n</html>\n"))
1812 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1814 (if (eq major-mode
(default-value 'major-mode
))
1817 ;; insert the table of contents
1818 (goto-char (point-min))
1820 (if (or (re-search-forward
1821 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
1823 "\\[TABLE-OF-CONTENTS\\]" nil t
))
1825 (goto-char (match-beginning 0))
1827 (goto-char first-heading-pos
)
1828 (when (looking-at "\\s-*</p>")
1829 (goto-char (match-end 0))
1831 (insert "<div id=\"table-of-contents\">\n")
1832 (let ((beg (point)))
1833 (mapc 'insert thetoc
)
1835 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" beg t
)
1836 (replace-match ""))))
1837 ;; remove empty paragraphs
1838 (goto-char (point-min))
1839 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
1841 (goto-char (point-min))
1842 ;; Convert whitespace place holders
1843 (goto-char (point-min))
1845 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1846 (setq n
(get-text-property beg
'org-whitespace
)
1847 end
(next-single-property-change beg
'org-whitespace
))
1849 (delete-region beg end
)
1850 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
1851 (make-string n ?x
)))))
1852 ;; Remove empty lines at the beginning of the file.
1853 (goto-char (point-min))
1854 (when (looking-at "\\s-+\n") (replace-match ""))
1855 ;; Remove display properties
1856 (remove-text-properties (point-min) (point-max) '(display t
))
1858 (run-hooks 'org-export-html-final-hook
)
1859 (or to-buffer
(save-buffer))
1860 (goto-char (point-min))
1861 (or (org-export-push-to-kill-ring "HTML")
1862 (message "Exporting... done"))
1863 (if (eq to-buffer
'string
)
1864 (prog1 (buffer-substring (point-min) (point-max))
1865 (kill-buffer (current-buffer)))
1866 (current-buffer)))))
1868 (defun org-export-html-format-href (s)
1869 "Make sure the S is valid as a href reference in an XHTML document."
1872 (while (string-match "&" s start
)
1873 (setq start
(+ (match-beginning 0) 3)
1874 s
(replace-match "&" t t s
)))))
1877 (defun org-export-html-format-desc (s)
1878 "Make sure the S is valid as a description in a link."
1879 (if (and s
(not (get-text-property 1 'org-protected s
)))
1881 (org-html-do-expand s
))
1884 (defun org-export-html-format-image (src par-open
)
1885 "Create image tag with source and attributes."
1887 (if (string-match "^ltxpng/" src
)
1888 (format "<img src=\"%s\" alt=\"%s\"/>"
1889 src
(org-find-text-property-in-string 'org-latex-src src
))
1890 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1891 (attr (org-find-text-property-in-string 'org-attributes src
))
1892 (label (org-find-text-property-in-string 'org-label src
)))
1893 (setq caption
(and caption
(org-html-do-expand caption
)))
1896 (format "%s<div %sclass=\"figure\">
1898 (if org-par-open
"</p>\n" "")
1899 (if label
(format "id=\"%s\" " (org-solidify-link-text label
)) "")))
1900 (format "<img src=\"%s\"%s />"
1902 (if (string-match "\\<alt=" (or attr
""))
1904 (concat " " attr
" alt=\"" src
"\"")))
1908 (concat "\n<p>" caption
"</p>")
1909 (if org-par-open
"\n<p>" ""))))))))
1911 (defun org-export-html-get-bibliography ()
1912 "Find bibliography, cut it out and return it."
1914 (let (beg end
(cnt 1) bib
)
1916 (goto-char (point-min))
1917 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1918 (setq beg
(match-beginning 0))
1919 (while (re-search-forward "</?div\\>" nil t
)
1920 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1922 (and (looking-at ">") (forward-char 1))
1923 (setq bib
(buffer-substring beg
(point)))
1924 (delete-region beg
(point))
1925 (throw 'exit bib
))))
1928 (defvar org-table-number-regexp
) ; defined in org-table.el
1929 (defun org-format-table-html (lines olines
&optional no-css
)
1930 "Find out which HTML converter to use and return the HTML code.
1931 NO-CSS is passed to the exporter."
1933 (setq lines
(org-split-string lines
"\n")))
1934 (if (string-match "^[ \t]*|" (car lines
))
1935 ;; A normal org table
1936 (org-format-org-table-html lines nil no-css
)
1937 ;; Table made by table.el
1938 (or (org-format-table-table-html-using-table-generate-source
1939 olines
(not org-export-prefer-native-exporter-for-tables
))
1940 ;; We are here only when table.el table has NO col or row
1941 ;; spanning and the user prefers using org's own converter for
1942 ;; exporting of such simple table.el tables.
1943 (org-format-table-table-html lines
))))
1945 (defvar org-table-number-fraction
) ; defined in org-table.el
1946 (defun org-format-org-table-html (lines &optional splice no-css
)
1947 "Format a table into HTML.
1948 LINES is a list of lines. Optional argument SPLICE means, do not
1949 insert header and surrounding <table> tags, just format the lines.
1950 Optional argument NO-CSS means use XHTML attributes instead of CSS
1951 for formatting. This is required for the DocBook exporter."
1952 (require 'org-table
)
1953 ;; Get rid of hlines at beginning and end
1954 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1955 (setq lines
(nreverse lines
))
1956 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1957 (setq lines
(nreverse lines
))
1958 (when org-export-table-remove-special-lines
1959 ;; Check if the table has a marking column. If yes remove the
1960 ;; column and the special lines
1961 (setq lines
(org-table-clean-before-export lines
)))
1963 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1964 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1965 (forced-aligns (org-find-text-property-in-string 'org-forced-aligns
1967 (attributes (org-find-text-property-in-string 'org-attributes
1969 (html-table-tag (org-export-splice-attributes
1970 html-table-tag attributes
))
1971 (head (and org-export-highlight-first-table-line
1973 (lambda (x) (string-match "^[ \t]*|-" x
))
1975 (nline 0) fnum nfields i
(cnt 0)
1976 tbopen line fields html gr colgropen rowstart rowend
1978 (setq caption
(and caption
(org-html-do-expand caption
)))
1979 (when (and forced-aligns org-table-clean-did-remove-column
)
1981 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) forced-aligns
)))
1982 (if splice
(setq head nil
))
1983 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
1985 (while (setq line
(pop lines
))
1987 (if (string-match "^[ \t]*|-" line
)
1990 (push (if head
"</thead>" "</tbody>") html
)
1991 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
1992 (setq head nil
) ;; head ends here, first time around
1994 (throw 'next-line t
)))
1995 ;; Break the line into fields
1996 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1997 (unless fnum
(setq fnum
(make-vector (length fields
) 0)
1998 nfields
(length fnum
)))
1999 (setq nline
(1+ nline
) i -
1
2000 rowstart
(eval (car org-export-table-row-tags
))
2001 rowend
(eval (cdr org-export-table-row-tags
)))
2002 (push (concat rowstart
2005 (setq i
(1+ i
) ali
(format "@@class%03d@@" i
))
2006 (if (and (< i nfields
) ; make sure no rogue line causes an error here
2007 (string-match org-table-number-regexp x
))
2008 (incf (aref fnum i
)))
2012 (format (car org-export-table-header-tags
)
2015 (cdr org-export-table-header-tags
)))
2016 ((and (= i
0) org-export-html-table-use-header-tags-for-first-column
)
2018 (format (car org-export-table-header-tags
)
2021 (cdr org-export-table-header-tags
)))
2023 (concat (format (car org-export-table-data-tags
) ali
)
2025 (cdr org-export-table-data-tags
)))))
2029 (unless splice
(if tbopen
(push "</tbody>" html
)))
2030 (unless splice
(push "</table>\n" html
))
2031 (setq html
(nreverse html
))
2033 ;; Put in col tags with the alignment (unfortunately often ignored...)
2034 (unless (car org-table-colgroup-info
)
2035 (setq org-table-colgroup-info
2036 (cons :start
(cdr org-table-colgroup-info
))))
2040 (setq gr
(pop org-table-colgroup-info
)
2042 align
(if (assoc i forced-aligns
)
2043 (cdr (assoc (cdr (assoc i forced-aligns
))
2044 '(("l" .
"left") ("r" .
"right")
2046 (if (> (/ (float x
) nline
)
2047 org-table-number-fraction
)
2051 "%s<col align=\"%s\" />%s"
2052 "%s<col class=\"%s\" />%s")
2053 (if (memq gr
'(:start
:startend
))
2056 "</colgroup>\n<colgroup>"
2061 (if (memq gr
'(:end
:startend
))
2062 (progn (setq colgropen nil
) "</colgroup>")
2066 (setq aligns
(nreverse aligns
))
2067 (if colgropen
(setq html
(cons (car html
)
2068 (cons "</colgroup>" (cdr html
)))))
2069 ;; Since the output of HTML table formatter can also be used in
2070 ;; DocBook document, we want to always include the caption to make
2071 ;; DocBook XML file valid.
2072 (push (format "<caption>%s</caption>" (or caption
"")) html
)
2074 (setq html-table-tag
(org-export-splice-attributes html-table-tag
(format "id=\"%s\"" (org-solidify-link-text label
)))))
2075 (push html-table-tag html
))
2078 (replace-regexp-in-string
2079 "@@class\\([0-9]+\\)@@"
2081 (if (not org-export-html-table-align-individual-fields
)
2083 (setq n
(string-to-number (match-string 1 txt
)))
2084 (format (if no-css
" align=\"%s\"" " class=\"%s\"")
2085 (or (nth n aligns
) "left"))))
2088 (concat (mapconcat 'identity html
"\n") "\n")))
2090 (defun org-export-splice-attributes (tag attributes
)
2091 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
2092 (if (not attributes
)
2094 (let (oldatt newatt
)
2095 (setq oldatt
(org-extract-attributes-from-string tag
)
2097 newatt
(cdr (org-extract-attributes-from-string attributes
)))
2099 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
2100 (if (string-match ">" tag
)
2102 (replace-match (concat (org-attributes-to-string oldatt
) ">")
2106 (defun org-format-table-table-html (lines)
2107 "Format a table generated by table.el into HTML.
2108 This conversion does *not* use `table-generate-source' from table.el.
2109 This has the advantage that Org-mode's HTML conversions can be used.
2110 But it has the disadvantage, that no cell- or row-spanning is allowed."
2111 (let (line field-buffer
2112 (head org-export-highlight-first-table-line
)
2113 fields html empty i
)
2114 (setq html
(concat html-table-tag
"\n"))
2115 (while (setq line
(pop lines
))
2116 (setq empty
" ")
2118 (if (string-match "^[ \t]*\\+-" line
)
2129 (if (equal x
"") (setq x empty
))
2132 (format (car org-export-table-header-tags
) "col" "")
2134 (cdr org-export-table-header-tags
))
2135 (concat (format (car org-export-table-data-tags
) "") x
2136 (cdr org-export-table-data-tags
))))
2140 (setq field-buffer nil
)))
2142 (throw 'next-line t
)))
2143 ;; Break the line into fields and store the fields
2144 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2146 (setq field-buffer
(mapcar
2148 (concat x
"<br/>" (pop fields
)))
2150 (setq field-buffer fields
))))
2151 (setq html
(concat html
"</table>\n"))
2154 (defun org-format-table-table-html-using-table-generate-source (lines
2157 "Format a table into html, using `table-generate-source' from table.el.
2158 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
2160 When SPANNED-ONLY is nil, all table.el tables are exported. When
2161 SPANNED-ONLY is non-nil, only tables with either row or column
2164 This routine returns the generated source or nil as appropriate.
2166 Refer docstring of `org-export-prefer-native-exporter-for-tables'
2167 for further information."
2169 (with-current-buffer (get-buffer-create " org-tmp1 ")
2171 (insert (mapconcat 'identity lines
"\n"))
2172 (goto-char (point-min))
2173 (if (not (re-search-forward "|[^+]" nil t
))
2174 (error "Error processing table"))
2175 (table-recognize-table)
2176 (when (or (not spanned-only
)
2177 (let* ((dim (table-query-dimension))
2178 (c (nth 4 dim
)) (r (nth 5 dim
)) (cells (nth 6 dim
)))
2179 (not (= (* c r
) cells
))))
2180 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
2181 (table-generate-source 'html
" org-tmp2 ")
2182 (set-buffer " org-tmp2 ")
2183 (buffer-substring (point-min) (point-max)))))
2185 (defun org-export-splice-style (style extra
)
2186 "Splice EXTRA into STYLE, just before \"</style>\"."
2187 (if (and (stringp extra
)
2188 (string-match "\\S-" extra
)
2189 (string-match "</style>" style
))
2190 (concat (substring style
0 (match-beginning 0))
2192 (substring style
(match-beginning 0)))
2195 (defun org-html-handle-time-stamps (s)
2196 "Format time stamps in string S, or remove them."
2199 (while (string-match org-maybe-keyword-time-regexp s
)
2200 (or b
(setq b
(substring s
0 (match-beginning 0))))
2202 r
(substring s
0 (match-beginning 0))
2203 " @<span class=\"timestamp-wrapper\">"
2205 (format "@<span class=\"timestamp-kwd\">%s @</span>"
2206 (match-string 1 s
)))
2207 (format " @<span class=\"timestamp\">%s@</span>"
2209 (org-translate-time (match-string 3 s
)) 1 -
1))
2211 s
(substring s
(match-end 0))))
2212 ;; Line break if line started and ended with time stamp stuff
2215 (setq r
(concat r s
))
2216 (unless (string-match "\\S-" (concat b s
))
2217 (setq r
(concat r
"@<br/>")))
2220 (defvar htmlize-buffer-places
) ; from htmlize.el
2221 (defun org-export-htmlize-region-for-paste (beg end
)
2222 "Convert the region to HTML, using htmlize.el.
2223 This is much like `htmlize-region-for-paste', only that it uses
2224 the settings define in the org-... variables."
2225 (let* ((htmlize-output-type org-export-htmlize-output-type
)
2226 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
2227 (htmlbuf (htmlize-region beg end
)))
2229 (with-current-buffer htmlbuf
2230 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
2231 (plist-get htmlize-buffer-places
'content-end
)))
2232 (kill-buffer htmlbuf
))))
2235 (defun org-export-htmlize-generate-css ()
2236 "Create the CSS for all font definitions in the current Emacs session.
2237 Use this to create face definitions in your CSS style file that can then
2238 be used by code snippets transformed by htmlize.
2239 This command just produces a buffer that contains class definitions for all
2240 faces used in the current Emacs session. You can copy and paste the ones you
2241 need into your CSS file.
2243 If you then set `org-export-htmlize-output-type' to `css', calls to
2244 the function `org-export-htmlize-region-for-paste' will produce code
2245 that uses these same face definitions."
2248 (and (get-buffer "*html*") (kill-buffer "*html*"))
2250 (let ((fl (face-list))
2251 (htmlize-css-name-prefix "org-")
2252 (htmlize-output-type 'css
)
2254 (while (setq f
(pop fl
)
2255 i
(and f
(face-attribute f
:inherit
)))
2256 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
2257 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
2258 (htmlize-region (point-min) (point-max))))
2259 (org-pop-to-buffer-same-window "*html*")
2260 (goto-char (point-min))
2261 (if (re-search-forward "<style" nil t
)
2262 (delete-region (point-min) (match-beginning 0)))
2263 (if (re-search-forward "</style>" nil t
)
2264 (delete-region (1+ (match-end 0)) (point-max)))
2265 (beginning-of-line 1)
2266 (if (looking-at " +") (replace-match ""))
2267 (goto-char (point-min)))
2269 (defun org-html-protect (s)
2270 "Convert characters to HTML equivalent.
2271 Possible conversions are set in `org-export-html-protect-char-alist'."
2272 (let ((cl org-export-html-protect-char-alist
) c
)
2273 (while (setq c
(pop cl
))
2275 (while (string-match (car c
) s start
)
2276 (setq s
(replace-match (cdr c
) t t s
)
2277 start
(1+ (match-beginning 0))))))
2280 (defun org-html-expand (string)
2281 "Prepare STRING for HTML export. Apply all active conversions.
2282 If there are links in the string, don't modify these."
2283 (let* ((re (concat org-bracket-link-regexp
"\\|"
2284 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2286 (while (setq m
(string-match re string
))
2287 (setq s
(substring string
0 m
)
2288 l
(match-string 0 string
)
2289 string
(substring string
(match-end 0)))
2290 (push (org-html-do-expand s
) res
)
2292 (push (org-html-do-expand string
) res
)
2293 (apply 'concat
(nreverse res
))))
2295 (defun org-html-do-expand (s)
2296 "Apply all active conversions to translate special ASCII to HTML."
2297 (setq s
(org-html-protect s
))
2298 (if org-export-html-expand
2299 (while (string-match "@<\\([^&]*\\)>" s
)
2300 (setq s
(replace-match "<\\1>" t nil s
))))
2301 (if org-export-with-emphasize
2302 (setq s
(org-export-html-convert-emphasize s
)))
2303 (if org-export-with-special-strings
2304 (setq s
(org-export-html-convert-special-strings s
)))
2305 (if org-export-with-sub-superscripts
2306 (setq s
(org-export-html-convert-sub-super s
)))
2307 (if org-export-with-TeX-macros
2308 (let ((start 0) wd rep
)
2309 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2311 (if (get-text-property (match-beginning 0) 'org-protected s
)
2312 (setq start
(match-end 0))
2313 (setq wd
(match-string 1 s
))
2314 (if (setq rep
(org-entity-get-representation wd
'html
))
2315 (setq s
(replace-match rep t t s
))
2316 (setq start
(+ start
(length wd
))))))))
2319 (defun org-export-html-convert-special-strings (string)
2320 "Convert special characters in STRING to HTML."
2321 (let ((all org-export-html-special-string-regexps
)
2323 (while (setq a
(pop all
))
2324 (setq re
(car a
) rpl
(cdr a
) start
0)
2325 (while (string-match re string start
)
2326 (if (get-text-property (match-beginning 0) 'org-protected string
)
2327 (setq start
(match-end 0))
2328 (setq string
(replace-match rpl t nil string
)))))
2331 (defun org-export-html-convert-sub-super (string)
2332 "Convert sub- and superscripts in STRING to HTML."
2333 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2334 (while (string-match org-match-substring-regexp string s
)
2336 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2337 ((get-text-property (match-beginning 2) 'org-protected string
)
2338 (setq s
(match-end 2)))
2340 (setq s
(match-end 1)
2341 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
2342 c
(or (match-string 8 string
)
2343 (match-string 6 string
)
2344 (match-string 5 string
))
2345 string
(replace-match
2346 (concat (match-string 1 string
)
2347 "<" key
">" c
"</" key
">")
2349 (while (string-match "\\\\\\([_^]\\)" string
)
2350 (setq string
(replace-match (match-string 1 string
) t t string
)))
2353 (defun org-export-html-convert-emphasize (string)
2356 (while (string-match org-emph-re string s
)
2358 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2359 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2360 (setq s
(match-beginning 0)
2363 (match-string 1 string
)
2364 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
2365 (match-string 4 string
)
2366 (nth 3 (assoc (match-string 3 string
)
2367 org-emphasis-alist
))
2368 (match-string 5 string
))
2369 string
(replace-match rpl t t string
)
2370 s
(+ s
(- (length rpl
) 2)))
2374 (defun org-open-par ()
2375 "Insert <p>, but first close previous paragraph if any."
2376 (org-close-par-maybe)
2378 (setq org-par-open t
))
2379 (defun org-close-par-maybe ()
2380 "Close paragraph if there is one open."
2383 (setq org-par-open nil
)))
2384 (defun org-close-li (&optional type
)
2385 "Close <li> if necessary."
2386 (org-close-par-maybe)
2387 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
2389 (defvar body-only
) ; dynamically scoped into this.
2390 (defun org-html-level-start (level title umax with-toc head-count
&optional opt-plist
)
2391 "Insert a new level in HTML export.
2392 When TITLE is nil, just close all open levels."
2393 (org-close-par-maybe)
2394 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
2395 (extra-targets (and target
2396 (assoc target org-export-target-aliases
)))
2397 (extra-class (and title
(org-get-text-property-any 0 'html-container-class title
)))
2398 (preferred (and target
2399 (cdr (assoc target org-export-preferred-target-alist
))))
2401 (num (plist-get opt-plist
:section-numbers
))
2402 snumber snu href suffix
)
2403 (setq extra-targets
(remove (or preferred target
) extra-targets
))
2405 (mapconcat (lambda (x)
2406 (setq x
(org-solidify-link-text
2407 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
2408 (format "<a name=\"%s\" id=\"%s\"></a>"
2413 (if (aref org-levels-open
(1- l
))
2415 (org-html-level-close l umax
)
2416 (aset org-levels-open
(1- l
) nil
)))
2419 ;; If title is nil, this means this function is called to close
2420 ;; all levels, so the rest is done only if title is given
2421 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2422 (setq title
(replace-match
2423 (if org-export-with-tags
2426 " <span class=\"tag\">"
2429 (format "<span class=\"%s\">%s</span>"
2430 (org-export-html-get-tag-class-name x
)
2432 (org-split-string (match-string 1 title
) ":")
2439 (if (aref org-levels-open
(1- level
))
2443 (insert (format "<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2444 extra-targets title
"<br/>\n")
2445 (insert "<li>" title
"<br/>\n")))
2446 (aset org-levels-open
(1- level
) t
)
2447 (org-close-par-maybe)
2449 (insert (format "<ul>\n<li id=\"%s\">" (org-solidify-link-text (or preferred target
)))
2450 extra-targets title
"<br/>\n")
2451 (insert "<ul>\n<li>" title
"<br/>\n"))))
2452 (aset org-levels-open
(1- level
) t
)
2453 (setq snumber
(org-section-number level
)
2454 snu
(replace-regexp-in-string "\\." "-" snumber
))
2455 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
2456 (if (and num
(not body-only
))
2458 (format "<span class=\"section-number-%d\">%s</span>"
2462 ;; fix up num to take into
2463 ;; account the top-level
2465 (>= (+ num org-export-html-toplevel-hlevel -
1)
2471 (unless (= head-count
1) (insert "\n</div>\n"))
2472 (setq href
(cdr (assoc (concat "sec-" snu
) org-export-preferred-target-alist
)))
2473 (setq suffix
(org-solidify-link-text (or href snu
)))
2474 (setq href
(org-solidify-link-text (or href
(concat "sec-" snu
))))
2475 (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"
2476 suffix level
(if extra-class
(concat " " extra-class
) "")
2479 title level level suffix
))
2482 (defun org-export-html-get-tag-class-name (tag)
2483 "Turn tag into a valid class name.
2484 Replaces invalid characters with \"_\" and then prepends a prefix."
2486 (while (string-match "[^a-zA-Z0-9_]" tag
)
2487 (setq tag
(replace-match "_" t t tag
))))
2488 (concat org-export-html-tag-class-prefix tag
))
2490 (defun org-export-html-get-todo-kwd-class-name (kwd)
2491 "Turn todo keyword into a valid class name.
2492 Replaces invalid characters with \"_\" and then prepends a prefix."
2494 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2495 (setq kwd
(replace-match "_" t t kwd
))))
2496 (concat org-export-html-todo-kwd-class-prefix kwd
))
2498 (defun org-html-level-close (level max-outline-level
)
2499 "Terminate one level in HTML export."
2500 (if (<= level max-outline-level
)
2503 (insert "</ul>\n")))
2505 (defun org-html-export-list-line (line pos struct prevs
)
2506 "Insert list syntax in export buffer. Return LINE, maybe modified.
2508 POS is the item position or line position the line had before
2509 modifications to buffer. STRUCT is the list structure. PREVS is
2510 the alist of previous items."
2513 ;; Translate type of list containing POS to "d", "o" or
2515 (lambda (pos struct prevs
)
2516 (let ((type (org-list-get-list-type pos struct prevs
)))
2518 ((eq 'ordered type
) "o")
2519 ((eq 'descriptive type
) "d")
2523 ;; Return list of all items and sublists ending at POS, in
2529 (let ((end (nth 6 e
))
2532 ((= end pos
) (push item out
))
2533 ((>= item pos
) (throw 'exit nil
)))))
2536 ;; First close any previous item, or list, ending at POS.
2538 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2539 (first-item (org-list-get-list-begin e struct prevs
))
2540 (type (funcall get-type first-item struct prevs
)))
2541 (org-close-par-maybe)
2542 ;; Ending for every item
2544 ;; We're ending last item of the list: end list.
2546 (insert (format "</%sl>\n" type
))
2548 (funcall get-closings pos
))
2550 ;; At an item: insert appropriate tags in export buffer.
2553 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2554 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\][ \t]*\\)?"
2555 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2556 "\\(?:\\(.*\\)[ \t]+::\\(?:[ \t]+\\|$\\)\\)?"
2558 (let* ((checkbox (match-string 3 line
))
2559 (desc-tag (or (match-string 4 line
) "???"))
2560 (body (or (match-string 5 line
) ""))
2561 (list-beg (org-list-get-list-begin pos struct prevs
))
2562 (firstp (= list-beg pos
))
2563 ;; Always refer to first item to determine list type, in
2564 ;; case list is ill-formed.
2565 (type (funcall get-type list-beg struct prevs
))
2566 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2568 ((not count-tmp
) nil
)
2569 ((string-match "[A-Za-z]" count-tmp
)
2570 (- (string-to-char (upcase count-tmp
)) 64))
2571 ((string-match "[0-9]+" count-tmp
)
2574 (org-close-par-maybe)
2575 (insert (format "<%sl>\n" type
)))
2578 (format "<dt>%s</dt><dd>" desc-tag
))
2579 ((and (equal type
"o") counter
)
2580 (format "<li value=\"%s\">" counter
))
2582 ;; If line had a checkbox, some additional modification is required.
2587 ((string-match "X" checkbox
) "<code>[X]</code> ")
2588 ((string-match " " checkbox
) "<code>[ ]</code> ")
2589 (t "<code>[-]</code> "))
2591 ;; Return modified line
2593 ;; At a list ender: go to next line (side-effects only).
2594 ((equal "ORG-LIST-END-MARKER" line
) (throw 'nextline nil
))
2595 ;; Not at an item: return line unchanged (side-effects only).
2600 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
2601 ;;; org-html.el ends here