1 ;;; org-html.el --- HTML export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
) (require 'table
))
36 (declare-function org-id-find-id-file
"org-id" (id))
37 (declare-function htmlize-region
"ext:htmlize" (beg end
))
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
63 (defcustom org-export-html-coding-system nil
64 "Coding system for HTML export, defaults to `buffer-file-coding-system'."
65 :group
'org-export-html
68 (defcustom org-export-html-extension
"html"
69 "The extension for exported HTML files."
70 :group
'org-export-html
73 (defcustom org-export-html-xml-declaration
74 '(("html" .
"<?xml version=\"1.0\" encoding=\"%s\"?>")
75 ("php" .
"<?php echo \"<?xml version=\\\"1.0\\\" encoding=\\\"%s\\\" ?>\"; ?>"))
76 "The extension for exported HTML files.
77 %s will be replaced with the charset of the exported file.
78 This may be a string, or an alist with export extensions
79 and corresponding declarations."
80 :group
'org-export-html
82 (string :tag
"Single declaration")
83 (repeat :tag
"Dependent on extension"
84 (cons (string :tag
"Extension")
85 (string :tag
"Declaration")))))
87 (defcustom org-export-html-style-include-scripts t
88 "Non-nil means include the JavaScript snippets in exported HTML files.
89 The actual script is defined in `org-export-html-scripts' and should
91 :group
'org-export-html
94 (defconst org-export-html-scripts
95 "<script type=\"text/javascript\">
96 <!--/*--><![CDATA[/*><!--*/
97 function CodeHighlightOn(elem, id)
99 var target = document.getElementById(id);
101 elem.cacheClassElem = elem.className;
102 elem.cacheClassTarget = target.className;
103 target.className = \"code-highlighted\";
104 elem.className = \"code-highlighted\";
107 function CodeHighlightOff(elem, id)
109 var target = document.getElementById(id);
110 if(elem.cacheClassElem)
111 elem.className = elem.cacheClassElem;
112 if(elem.cacheClassTarget)
113 target.className = elem.cacheClassTarget;
117 "Basic JavaScript that is needed by HTML files produced by Org-mode.")
119 (defconst org-export-html-style-default
120 "<style type=\"text/css\">
121 <!--/*--><![CDATA[/*><!--*/
122 html { font-family: Times, serif; font-size: 12pt; }
123 .title { text-align: center; }
124 .todo { color: red; }
125 .done { color: green; }
126 .tag { background-color: #add8e6; font-weight:normal }
128 .timestamp { color: #bebebe; }
129 .timestamp-kwd { color: #5f9ea0; }
130 .right {margin-left:auto; margin-right:0px; text-align:right;}
131 .left {margin-left:0px; margin-right:auto; text-align:left;}
132 .center {margin-left:auto; margin-right:auto; text-align:center;}
133 p.verse { margin-left: 3% }
135 border: 1pt solid #AEBDCC;
136 background-color: #F3F5F7;
138 font-family: courier, monospace;
142 table { border-collapse: collapse; }
143 td, th { vertical-align: top; }
144 th.right { text-align:center; }
145 th.left { text-align:center; }
146 th.center { text-align:center; }
147 td.right { text-align:right; }
148 td.left { text-align:left; }
149 td.center { text-align:center; }
150 dt { font-weight: bold; }
151 div.figure { padding: 0.5em; }
152 div.figure p { text-align: center; }
153 textarea { overflow-x: auto; }
154 .linenr { font-size:smaller }
155 .code-highlighted {background-color:#ffff00;}
156 .org-info-js_info-navigation { border-style:none; }
157 #org-info-js_console-label { font-size:10px; font-weight:bold;
158 white-space:nowrap; }
159 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
163 "The default style specification for exported HTML files.
164 Please use the variables `org-export-html-style' and
165 `org-export-html-style-extra' to add to this style. If you wish to not
166 have the default style included, customize the variable
167 `org-export-html-style-include-default'.")
169 (defcustom org-export-html-style-include-default t
170 "Non-nil means include the default style in exported HTML files.
171 The actual style is defined in `org-export-html-style-default' and should
172 not be modified. Use the variables `org-export-html-style' to add
173 your own style information."
174 :group
'org-export-html
177 (put 'org-export-html-style-include-default
'safe-local-variable
'booleanp
)
179 (defcustom org-export-html-style
""
180 "Org-wide style definitions for exported HTML files.
182 This variable needs to contain the full HTML structure to provide a style,
183 including the surrounding HTML tags. If you set the value of this variable,
184 you should consider to include definitions for the following classes:
185 title, todo, done, timestamp, timestamp-kwd, tag, target.
187 For example, a valid value would be:
189 <style type=\"text/css\">
191 p { font-weight: normal; color: gray; }
193 .title { text-align: center; }
194 .todo, .timestamp-kwd { color: red; }
195 .done { color: green; }
199 If you'd like to refer to en external style file, use something like
201 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
203 As the value of this option simply gets inserted into the HTML <head> header,
204 you can \"misuse\" it to add arbitrary text to the header.
205 See also the variable `org-export-html-style-extra'."
206 :group
'org-export-html
209 (put 'org-export-html-style
'safe-local-variable
'stringp
)
211 (defcustom org-export-html-style-extra
""
212 "Additional style information for HTML export.
213 The value of this variable is inserted into the HTML buffer right after
214 the value of `org-export-html-style'. Use this variable for per-file
215 settings of style information, and do not forget to surround the style
216 settings with <style>...</style> tags."
217 :group
'org-export-html
220 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
222 (defcustom org-export-html-mathjax-options
223 '((path "http://orgmode.org/mathjax/MathJax.js")
228 "Options for MathJax setup.
230 path The path where to find MathJax
231 scale Scaling for the HTML-CSS backend, usually between 100 and 133
232 align How to align display math: left, center, or right
233 indent If align is not center, how far from the left/right side?
234 mathml Should a MathML player be used if available?
235 This is faster and reduces bandwidth use, but currently
236 sometimes has lower spacing quality. Therefore, the default is
237 nil. When browsers get better, this switch can be flipped.
239 You can also customize this for each buffer, using something like
241 #+MATHJAX: scale:\"133\" align:\"right\" mathml:t path:\"/MathJax/\""
242 :group
'org-export-html
243 :type
'(list :greedy t
244 (list :tag
"path (the path from where to load MathJax.js)"
245 (const :format
" " path
) (string))
246 (list :tag
"scale (scaling for the displayed math)"
247 (const :format
" " scale
) (string))
248 (list :tag
"align (alignment of displayed equations)"
249 (const :format
" " align
) (string))
250 (list :tag
"indent (indentation with left or right alignment)"
251 (const :format
" " indent
) (string))
252 (list :tag
"mathml (should MathML display be used is possible)"
253 (const :format
" " mathml
) (boolean))))
255 (defun org-export-html-mathjax-config (template options in-buffer
)
256 "Insert the user setup into the matchjax template."
257 (let (name val
(yes " ") (no "// ") x
)
260 (setq name
(car e
) val
(nth 1 e
))
261 (if (string-match (concat "\\<" (symbol-name name
) ":") in-buffer
)
262 (setq val
(car (read-from-string
263 (substring in-buffer
(match-end 0))))))
264 (if (not (stringp val
)) (setq val
(format "%s" val
)))
265 (if (string-match (concat "%" (upcase (symbol-name name
))) template
)
266 (setq template
(replace-match val t t template
))))
268 (setq val
(nth 1 (assq 'mathml options
)))
269 (if (string-match (concat "\\<mathml:") in-buffer
)
270 (setq val
(car (read-from-string
271 (substring in-buffer
(match-end 0))))))
272 ;; Exchange prefixes depending on mathml setting
273 (if (not val
) (setq x yes yes no no x
))
274 ;; Replace cookies to turn on or off the config/jax lines
275 (if (string-match ":MMLYES:" template
)
276 (setq template
(replace-match yes t t template
)))
277 (if (string-match ":MMLNO:" template
)
278 (setq template
(replace-match no t t template
)))
279 ;; Return the modified template
282 (defcustom org-export-html-mathjax-template
283 "<script type=\"text/javascript\" src=\"%PATH\">
284 <!--/*--><![CDATA[/*><!--*/
286 // Only one of the two following lines, depending on user settings
287 // First allows browser-native MathML display, second forces HTML/CSS
288 :MMLYES: config: [\"MMLorHTML.js\"], jax: [\"input/TeX\"],
289 :MMLNO: jax: [\"input/TeX\", \"output/HTML-CSS\"],
290 extensions: [\"tex2jax.js\",\"TeX/AMSmath.js\",\"TeX/AMSsymbols.js\",
291 \"TeX/noUndefined.js\"],
293 inlineMath: [ [\"\\\\(\",\"\\\\)\"] ],
294 displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"], [\"\\\\begin{displaymath}\",\"\\\\end{displaymath}\"] ],
295 skipTags: [\"script\",\"noscript\",\"style\",\"textarea\",\"pre\",\"code\"],
296 ignoreClass: \"tex2jax_ignore\",
297 processEscapes: false,
298 processEnvironments: true,
301 showProcessingMessages: true,
302 displayAlign: \"%ALIGN\",
303 displayIndent: \"%INDENT\",
307 availableFonts: [\"STIX\",\"TeX\"],
308 preferredFont: \"TeX\",
324 "The MathJax setup for XHTML files."
325 :group
'org-export-html
328 (defcustom org-export-html-tag-class-prefix
""
329 "Prefix to class names for TODO keywords.
330 Each tag gets a class given by the tag itself, with this prefix.
331 The default prefix is empty because it is nice to just use the keyword
332 as a class name. But if you get into conflicts with other, existing
333 CSS classes, then this prefix can be very useful."
334 :group
'org-export-html
337 (defcustom org-export-html-todo-kwd-class-prefix
""
338 "Prefix to class names for TODO keywords.
339 Each TODO keyword gets a class given by the keyword itself, with this prefix.
340 The default prefix is empty because it is nice to just use the keyword
341 as a class name. But if you get into conflicts with other, existing
342 CSS classes, then this prefix can be very useful."
343 :group
'org-export-html
346 (defcustom org-export-html-preamble t
347 "Non-nil means insert a preamble in HTML export.
349 When `t', insert a string as defined by one of the formatting
350 strings in `org-export-html-preamble-format'. When set to a
351 string, this string overrides `org-export-html-preamble-format'.
352 When set to a function, apply this function and insert the
353 returned string. The function takes the property list of export
354 options as its only argument.
356 Setting :html-preamble in publishing projects will take
357 precedence over this variable."
358 :group
'org-export-html
359 :type
'(choice (const :tag
"No preamble" nil
)
360 (const :tag
"Default preamble" t
)
361 (string :tag
"Custom formatting string")
362 (function :tag
"Function (must return a string)")))
364 (defcustom org-export-html-preamble-format
365 '(("en" "<h1 class=\"title\">%t</h1>"))
366 "The format for the HTML preamble.
368 %t stands for the title.
370 If you need to use a \"%\" character, you need to escape it
372 :group
'org-export-html
375 (defcustom org-export-html-postamble
'auto
376 "Non-nil means insert a postamble in HTML export.
378 When `t', insert a string as defined by the formatting string in
379 `org-export-html-postamble-format'. When set to a string, this
380 string overrides `org-export-html-postamble-format'. When set to
381 'auto, discard `org-export-html-postamble-format' and honor
382 `org-export-author/email/creator-info' variables. When set to a
383 function, apply this function and insert the returned string.
384 The function takes the property list of export options as its
387 Setting :html-postamble in publishing projects will take
388 precedence over this variable."
389 :group
'org-export-html
390 :type
'(choice (const :tag
"No postamble" nil
)
391 (const :tag
"Auto preamble" 'auto
)
392 (const :tag
"Default formatting string" t
)
393 (string :tag
"Custom formatting string")
394 (function :tag
"Function (must return a string)")))
396 (defcustom org-export-html-postamble-format
397 '(("en" "<p class=\"author\">Author: %a (%e)</p>
398 <p class=\"date\">Date: %d</p>
399 <p class=\"creator\">Generated by %c</p>
400 <p class=\"xhtml-validation\">%v</p>
402 "The format for the HTML postamble.
404 %a stands for the author.
405 %e stands for the email(s).
406 %d stands for the date.
407 %c will be replaced by information about Org/Emacs.
408 %v will be replaced by `org-export-html-validation-link'.
410 If you need to use a \"%\" character, you need to escape it
412 :group
'org-export-html
415 (defcustom org-export-html-home
/up-format
416 "<div id=\"org-div-home-and-up\" style=\"text-align:right;font-size:70%%;white-space:nowrap;\">
417 <a accesskey=\"h\" href=\"%s\"> UP </a>
419 <a accesskey=\"H\" href=\"%s\"> HOME </a>
421 "Snippet used to insert the HOME and UP links.
422 This is a format string, the first %s will receive the UP link,
423 the second the HOME link. If both `org-export-html-link-up' and
424 `org-export-html-link-home' are empty, the entire snippet will be
426 :group
'org-export-html
429 (defcustom org-export-html-toplevel-hlevel
2
430 "The <H> level for level 1 headings in HTML export.
431 This is also important for the classes that will be wrapped around headlines
432 and outline structure. If this variable is 1, the top-level headlines will
433 be <h1>, and the corresponding classes will be outline-1, section-number-1,
434 and outline-text-1. If this is 2, all of these will get a 2 instead.
435 The default for this variable is 2, because we use <h1> for formatting the
437 :group
'org-export-html
440 (defcustom org-export-html-link-org-files-as-html t
441 "Non-nil means make file links to `file.org' point to `file.html'.
442 When org-mode is exporting an org-mode file to HTML, links to
443 non-html files are directly put into a href tag in HTML.
444 However, links to other Org-mode files (recognized by the
445 extension `.org.) should become links to the corresponding html
446 file, assuming that the linked org-mode file will also be
448 When nil, the links still point to the plain `.org' file."
449 :group
'org-export-html
452 (defcustom org-export-html-inline-images
'maybe
453 "Non-nil means inline images into exported HTML pages.
454 This is done using an <img> tag. When nil, an anchor with href is used to
455 link to the image. If this option is `maybe', then images in links with
456 an empty description will be inlined, while images with a description will
458 :group
'org-export-html
459 :type
'(choice (const :tag
"Never" nil
)
460 (const :tag
"Always" t
)
461 (const :tag
"When there is no description" maybe
)))
463 (defcustom org-export-html-inline-image-extensions
464 '("png" "jpeg" "jpg" "gif" "svg")
465 "Extensions of image files that can be inlined into HTML."
466 :group
'org-export-html
467 :type
'(repeat (string :tag
"Extension")))
469 (defcustom org-export-html-table-tag
470 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
471 "The HTML tag that is used to start a table.
472 This must be a <table> tag, but you may change the options like
473 borders and spacing."
474 :group
'org-export-html
477 (defcustom org-export-table-header-tags
'("<th scope=\"%s\"%s>" .
"</th>")
478 "The opening tag for table header fields.
479 This is customizable so that alignment options can be specified.
480 The first %s will be filled with the scope of the field, either row or col.
481 The second %s will be replaced by a style entry to align the field.
482 See also the variable `org-export-html-table-use-header-tags-for-first-column'.
483 See also the variable `org-export-html-table-align-individual-fields'."
484 :group
'org-export-tables
485 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
487 (defcustom org-export-table-data-tags
'("<td%s>" .
"</td>")
488 "The opening tag for table data fields.
489 This is customizable so that alignment options can be specified.
490 The first %s will be filled with the scope of the field, either row or col.
491 The second %s will be replaced by a style entry to align the field.
492 See also the variable `org-export-html-table-align-individual-fields'."
493 :group
'org-export-tables
494 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
496 (defcustom org-export-table-row-tags
'("<tr>" .
"</tr>")
497 "The opening tag for table data fields.
498 This is customizable so that alignment options can be specified.
499 Instead of strings, these can be Lisp forms that will be evaluated
500 for each row in order to construct the table row tags. During evaluation,
501 the variable `head' will be true when this is a header line, nil when this
502 is a body line. And the variable `nline' will contain the line number,
503 starting from 1 in the first header line. For example
505 (setq org-export-table-row-tags
508 (if (= (mod nline 2) 1)
509 \"<tr class=\\\"tr-odd\\\">\"
510 \"<tr class=\\\"tr-even\\\">\"))
513 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
514 :group
'org-export-tables
516 (choice :tag
"Opening tag"
517 (string :tag
"Specify")
519 (choice :tag
"Closing tag"
520 (string :tag
"Specify")
523 (defcustom org-export-html-table-align-individual-fields t
524 "Non-nil means attach style attributes for alignment to each table field.
525 When nil, alignment will only be specified in the column tags, but this
526 is ignored by some browsers (like Firefox, Safari). Opera does it right
528 :group
'org-export-tables
531 (defcustom org-export-html-table-use-header-tags-for-first-column nil
532 "Non-nil means format column one in tables with header tags.
533 When nil, also column one will use data tags."
534 :group
'org-export-tables
537 (defcustom org-export-html-validation-link
538 "<a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a>"
539 "Link to HTML validation service."
540 :group
'org-export-html
543 (defcustom org-export-html-with-timestamp nil
544 "If non-nil, write timestamp into the exported HTML text.
545 If non-nil, write `org-export-html-html-helper-timestamp' into the
546 exported HTML text. Otherwise, the buffer will just be saved to
548 :group
'org-export-html
551 (defcustom org-export-html-html-helper-timestamp
552 "<br/><br/><hr/><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
553 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
554 :group
'org-export-html
557 (defcustom org-export-html-protect-char-alist
561 "Alist of characters to be converted by `org-html-protect'."
562 :type
'(repeat (cons (string :tag
"Character")
563 (string :tag
"HTML equivalent"))))
565 (defgroup org-export-htmlize nil
566 "Options for processing examples with htmlize.el."
567 :tag
"Org Export Htmlize"
568 :group
'org-export-html
)
570 (defcustom org-export-htmlize-output-type
'inline-css
571 "Output type to be used by htmlize when formatting code snippets.
572 Choices are `css', to export the CSS selectors only, or `inline-css', to
573 export the CSS attribute values inline in the HTML. We use as default
574 `inline-css', in order to make the resulting HTML self-containing.
576 However, this will fail when using Emacs in batch mode for export, because
577 then no rich font definitions are in place. It will also not be good if
578 people with different Emacs setup contribute HTML files to a website,
579 because the fonts will represent the individual setups. In these cases,
580 it is much better to let Org/Htmlize assign classes only, and to use
581 a style file to define the look of these classes.
582 To get a start for your css file, start Emacs session and make sure that
583 all the faces you are interested in are defined, for example by loading files
584 in all modes you want. Then, use the command
585 \\[org-export-htmlize-generate-css] to extract class definitions."
586 :group
'org-export-htmlize
587 :type
'(choice (const css
) (const inline-css
)))
589 (defcustom org-export-htmlize-css-font-prefix
"org-"
590 "The prefix for CSS class names for htmlize font specifications."
591 :group
'org-export-htmlize
594 (defcustom org-export-htmlized-org-css-url nil
595 "URL pointing to a CSS file defining text colors for htmlized Emacs buffers.
596 Normally when creating an htmlized version of an Org buffer, htmlize will
597 create CSS to define the font colors. However, this does not work when
598 converting in batch mode, and it also can look bad if different people
599 with different fontification setup work on the same website.
600 When this variable is non-nil, creating an htmlized version of an Org buffer
601 using `org-export-as-org' will remove the internal CSS section and replace it
602 with a link to this URL."
603 :group
'org-export-htmlize
605 (const :tag
"Keep internal css" nil
)
606 (string :tag
"URL or local href")))
610 (defvar org-export-html-after-blockquotes-hook nil
611 "Hook run during HTML export, after blockquote, verse, center are done.")
613 (defvar org-export-html-final-hook nil
614 "Hook run at the end of HTML export, in the new buffer.")
618 (defun org-export-html-preprocess (parameters)
619 "Convert LaTeX fragments to images."
620 (when (and org-current-export-file
621 (plist-get parameters
:LaTeX-fragments
))
623 (concat "ltxpng/" (file-name-sans-extension
624 (file-name-nondirectory
625 org-current-export-file
)))
626 org-current-export-dir nil
"Creating LaTeX image %s"
629 ((eq (plist-get parameters
:LaTeX-fragments
) 'verbatim
) 'verbatim
)
630 ((eq (plist-get parameters
:LaTeX-fragments
) 'mathjax
) 'mathjax
)
631 ((eq (plist-get parameters
:LaTeX-fragments
) t
) 'mathjax
)
632 ((eq (plist-get parameters
:LaTeX-fragments
) 'dvipng
) 'dvipng
)
634 (goto-char (point-min))
636 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t
)
637 (org-if-unprotected-at (match-beginning 1)
638 (setq label
(match-string 1))
640 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label
)
641 (setq l1
(substring label
(match-beginning 1)))
643 (replace-match (format "[[#%s][%s]]" label l1
) t t
)))))
646 (defun org-export-as-and-open (backend arg
)
647 "Export the outline as HTML and immediately open it with a browser.
648 If there is an active region, export only the region.
649 The prefix ARG specifies how many levels of the outline should become
650 headlines. The default is 3. Lower levels will become bulleted lists."
651 (interactive "Mbackend: \nP")
652 (org-export-as backend arg
'hidden
)
653 (message "Opening file %s" (buffer-file-name))
654 (org-open-file buffer-file-name
)
655 (when org-export-kill-product-buffer-when-displayed
656 (kill-buffer (current-buffer))))
659 (defun org-export-as-batch (backend)
660 "Call the function `org-export-as-html'.
661 This function can be used in batch processing as:
663 --load=$HOME/lib/emacs/org.el
664 --eval \"(setq org-export-headline-levels 2)\"
665 --visit=MyFile --funcall org-export-as-html-batch"
666 (org-export-as backend org-export-headline-levels
'hidden
))
669 (defun org-export-as-to-buffer (backend arg
)
670 "Call `org-export-as-html` with output to a temporary buffer.
671 No file is created. The prefix ARG is passed through to `org-export-as-html'."
672 (interactive "Mbackend: \nP")
673 (let ((tempbuf (format "*Org %s Export*" (upcase backend
))))
674 (org-export-as backend arg nil nil tempbuf
)
675 (when org-export-show-temporary-export-buffer
676 (switch-to-buffer-other-window tempbuf
))))
679 (defun org-replace-region-by (backend beg end
)
680 "Assume the current region has org-mode syntax, and convert it to HTML.
681 This can be used in any buffer. For example, you could write an
682 itemized list in org-mode syntax in an HTML buffer and then use this
683 command to convert it."
684 (interactive "Mbackend: \nr")
685 (let (reg backend-string buf pop-up-frames
)
686 (save-window-excursion
688 (setq backend-string
(org-export-region-as
689 backend beg end t
'string
))
690 (setq reg
(buffer-substring beg end
)
691 buf
(get-buffer-create "*Org tmp*"))
692 (with-current-buffer buf
696 (setq backend-string
(org-export-region-as
697 backend
(point-min) (point-max) t
'string
)))
699 (delete-region beg end
)
700 (insert backend-string
)))
703 (defun org-export-region-as (backend beg end
&optional body-only buffer
)
704 "Convert region from BEG to END in org-mode buffer to HTML.
705 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
706 contents, and only produce the region of converted text, useful for
707 cut-and-paste operations.
708 If BUFFER is a buffer or a string, use/create that buffer as a target
709 of the converted HTML. If BUFFER is the symbol `string', return the
710 produced HTML as a string and leave not buffer behind. For example,
711 a Lisp program could call this function in the following way:
713 (setq html (org-export-region-as-html beg end t 'string))
715 When called interactively, the output buffer is selected, and shown
716 in a window. A non-interactive call will only return the buffer."
717 (interactive "Mbackend: \nr\nP")
718 (when (interactive-p)
719 (setq buffer
(format "*Org %s Export*" (upcase backend
))))
720 (let ((transient-mark-mode t
) (zmacs-regions t
)
722 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
724 (set-mark (point)) ;; to activate the region
726 (setq rtn
(org-export-as backend nil nil ext-plist buffer body-only
))
727 (if (fboundp 'deactivate-mark
) (deactivate-mark))
728 (if (and (interactive-p) (bufferp rtn
))
729 (switch-to-buffer-other-window rtn
)
732 (defvar html-table-tag nil
) ; dynamically scoped into this.
733 (defvar org-par-open nil
)
735 ;;; org-html-cvt-link-fn
736 (defconst org-html-cvt-link-fn
738 "Function to convert link URLs to exportable URLs.
739 Takes two arguments, TYPE and PATH.
740 Returns exportable url as (TYPE PATH), or nil to signal that it
741 didn't handle this case.
742 Intended to be locally bound around a call to `org-export-as-html'." )
744 (defun org-html-cvt-org-as-html (opt-plist type path
)
745 "Convert an org filename to an equivalent html filename.
746 If TYPE is not file, just return `nil'.
747 See variable `org-export-html-link-org-files-as-html'"
751 org-export-html-link-org-files-as-html
752 (string= type
"file")
753 (string-match "\\.org$" path
)
758 (substring path
0 (match-beginning 0))
760 (plist-get opt-plist
:html-extension
)))))))
763 ;;; org-html-should-inline-p
764 (defun org-html-should-inline-p (filename descp
)
765 "Return non-nil if link FILENAME should be inlined.
766 The decision to inline the FILENAME link is based on the current
767 settings. DESCP is the boolean of whether there was a link
768 description. See variables `org-export-html-inline-images' and
769 `org-export-html-inline-image-extensions'."
771 org-export-html-inline-images
772 org-export-html-inline-image-extensions
))
773 (and (or (eq t org-export-html-inline-images
)
774 (and org-export-html-inline-images
(not descp
)))
776 filename org-export-html-inline-image-extensions
)))
778 ;;; org-html-format-org-link
779 (defun org-html-format-org-link (opt-plist type-1 path fragment desc attr
782 OPT-PLIST is an options list.
783 TYPE is the device-type of the link (THIS://foo.html)
784 PATH is the path of the link (http://THIS#locationx)
785 FRAGMENT is the fragment part of the link, if any (foo.html#THIS)
786 DESC is the link description, if any.
787 ATTR is a string of other attributes of the a element.
788 MAY-INLINE-P allows inlining it as an image."
789 (declare (special org-par-open
))
790 (when (string= type-1
"coderef")
792 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
796 (and (member type-1
'("http" "https" "file"))
797 (org-html-should-inline-p path descp
)
799 (type (if (equal type-1
"id") "file" type-1
))
801 ;;First pass. Just sanity stuff.
804 ((string= type
"file")
807 ;;Substitute just if original path was absolute.
808 ;;(Otherwise path must remain relative)
809 (if (file-name-absolute-p path
)
810 (concat "file://" (expand-file-name path
))
814 (t (list type path
))))
816 ;;Second pass. Components converted so they can refer
820 (and org-html-cvt-link-fn
821 (apply org-html-cvt-link-fn
822 opt-plist components-1
))
823 (apply #'org-html-cvt-org-as-html
824 opt-plist components-1
)
826 (type (first components-2
))
827 (thefile (second components-2
)))
830 ;;Third pass. Build final link except for leading type
835 (string= type
"http")
836 (string= type
"https")
837 (string= type
"file")
838 (string= type
"coderef"))
840 (setq thefile
(concat thefile
"#" fragment
))))
844 ;;Final URL-build, for all types.
847 ((str (org-export-html-format-href thefile
)))
848 (if (and type
(not (or (string= "file" type
)
849 (string= "coderef" type
))))
850 (concat type
":" str
)
854 (org-export-html-format-image thefile
)
856 'LINK
(org-export-html-format-desc desc
) thefile attr
)))))
858 (defun org-html-format-inline-image (desc)
859 ;; FIXME: alt text missing here?
860 (org-html-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc
))
862 (defvar org-parse-link-description-is-image
)
863 (defun org-parse-format-org-link (line opt-plist
)
864 "Return LINE with markup of Org mode links.
865 OPT-PLIST is the export options list."
867 (current-dir (if buffer-file-name
868 (file-name-directory buffer-file-name
)
870 (link-validate (plist-get opt-plist
:link-validation-function
))
872 rpl path attr desc descp desc1 desc2 link
873 org-parse-link-description-is-image
)
874 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
875 (setq org-parse-link-description-is-image nil
)
876 (setq start
(match-beginning 0))
877 (setq path
(save-match-data (org-link-unescape
878 (match-string 3 line
))))
880 ((match-end 2) (match-string 2 line
))
882 (or (file-name-absolute-p path
)
883 (string-match "^\\.\\.?/" path
)))
886 (setq path
(org-extract-attributes (org-link-unescape path
)))
887 (setq attr
(get-text-property 0 'org-attributes path
))
888 (setq desc1
(if (match-end 5) (match-string 5 line
))
889 desc2
(if (match-end 2) (concat type
":" path
) path
)
890 descp
(and desc1
(not (equal desc1 desc2
)))
891 desc
(or desc1 desc2
))
892 ;; Make an image out of the description if that is so wanted
893 (when (and descp
(org-file-image-p
894 desc org-export-html-inline-image-extensions
))
895 (setq org-parse-link-description-is-image t
)
897 (if (string-match "^file:" desc
)
898 (setq desc
(substring desc
(match-end 0)))))
900 (setq desc
(org-add-props
901 (org-parse-format 'INLINE-IMAGE desc
)
902 '(org-protected t
)))))
904 ((equal type
"internal")
907 (if (= (string-to-char path
) ?
#)
912 'ORG-LINK opt-plist
"" "" (org-solidify-link-text
914 (org-link-unescape frag-0
))
915 nil
) desc attr descp
))))
916 ((and (equal type
"id")
917 (setq id-file
(org-id-find-id-file path
)))
918 ;; This is an id: link to another file (if it was the same file,
919 ;; it would have become an internal link...)
921 (setq id-file
(file-relative-name
923 (file-name-directory org-current-export-file
)))
926 'ORG-LINK opt-plist type id-file
927 (concat (if (org-uuidgen-p path
) "ID-") path
)
929 ((member type
'("http" "https"))
930 ;; standard URL, can inline as image
933 'ORG-LINK opt-plist type path nil desc attr descp
)))
934 ((member type
'("ftp" "mailto" "news"))
935 ;; standard URL, can't inline as image
938 'ORG-LINK opt-plist type path nil desc attr descp
)))
940 ((string= type
"coderef")
943 'ORG-LINK opt-plist type
"" (format "coderef-%s" path
)
945 (org-export-get-coderef-format
948 (cdr (assoc path org-export-code-refs
))) nil descp
)))
950 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
951 ;; The link protocol has a function for format the link
954 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
956 ((string= type
"file")
962 (string-match "::\\(.*\\)" path
)
964 (replace-match "" t nil path
)
965 (match-string 1 path
))
968 ;;The proper path, without a fragment
976 ;;Check the fragment. If it can't be used as
977 ;;target fragment we'll pass nil instead.
981 (not (string-match "^[0-9]*$" fragment-0
))
982 (not (string-match "^\\*" fragment-0
))
983 (not (string-match "^/.*/$" fragment-0
)))
984 (org-solidify-link-text
985 (org-link-unescape fragment-0
))
988 ;;Description minus "file:" and ".org"
989 (if (string-match "^file:" desc
)
991 ((desc-1 (replace-match "" t t desc
)))
992 (if (string-match "\\.org$" desc-1
)
993 (replace-match "" t t desc-1
)
1000 (functionp link-validate
)
1001 (not (funcall link-validate path-1 current-dir
)))
1004 'ORG-LINK opt-plist
"file" path-1 fragment-1
1005 desc-2 attr descp
))))))
1008 ;; just publish the path, as default
1009 (setq rpl
(concat "<i><" type
":"
1010 (save-match-data (org-link-unescape path
))
1012 (setq line
(replace-match rpl t t line
)
1013 start
(+ start
(length rpl
))))
1016 (defmacro with-org-parse-preserve-paragraph-state
(&rest body
)
1017 `(let ((org-do-open-par org-par-open
))
1018 (org-parse-end-paragraph)
1020 (when org-do-open-par
1021 (org-parse-begin-paragraph))))
1023 (defvar org-export-backends-alist
1024 '((html . org-html-get
)
1025 (odt . org-odt-get
)))
1027 (defun org-export-as (backend arg
&optional hidden ext-plist
1028 to-buffer body-only pub-dir
)
1029 (interactive "Mbackend: \nP")
1030 (let* ((backend-desc (assoc-string backend org-export-backends-alist t
))
1031 (backend-get (cdr backend-desc
))
1032 (backend-get (and (functionp backend-get
) backend-get
)))
1034 (error "Don't know how to export to backend %s" backend
))
1035 (run-hooks 'org-export-first-hook
)
1036 (let* ((org-parse-get-callback backend-get
))
1037 (org-do-export arg hidden ext-plist to-buffer body-only pub-dir
))))
1039 (defvar org-html-insert-tag-with-newlines
'both
)
1041 ;; Following variables are let-bound while `org-do-export' is in
1043 (defvar org-html-dyn-first-heading-pos
)
1044 (defvar org-parse-table-of-contents
)
1045 (defvar org-parse-entity-control-callbacks-alist
)
1046 (defvar org-parse-entity-format-callbacks-alist
)
1047 (defvar org-parse-get-callback
)
1048 (defvar org-parse-backend
)
1049 (defvar org-parse-body-only
)
1050 (defvar org-parse-to-buffer
)
1051 (defun org-do-export (arg &optional hidden ext-plist
1052 to-buffer body-only pub-dir
)
1053 "Export the outline as a pretty HTML file."
1054 ;; Make sure we have a file name when we need it.
1055 (when (and (not (or to-buffer body-only
))
1056 (not buffer-file-name
))
1057 (if (buffer-base-buffer)
1058 (org-set-local 'buffer-file-name
1059 (with-current-buffer (buffer-base-buffer)
1061 (error "Need a file name to be able to export")))
1063 (message "Exporting...")
1064 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1065 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1066 (setq-default org-done-keywords org-done-keywords
)
1067 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1068 (let* (org-html-protect
1070 org-parse-outline-text-open
1071 (org-parse-latex-fragment-fallback ; currently used only by
1073 (or (ignore-errors (org-parse-get 'LATEX-FRAGMENT-FALLBACK
))
1074 (if (and (org-check-external-command "latex" "" t
)
1075 (org-check-external-command "dvipng" "" t
))
1078 (org-html-insert-tag-with-newlines 'both
)
1079 (org-parse-to-buffer to-buffer
)
1080 (org-parse-body-only body-only
)
1081 (org-export-html-special-string-regexps ; FIXME: genericize this
1082 (org-parse-get 'SPECIAL-STRING-REGEXPS
))
1083 (org-parse-entity-control-callbacks-alist
1084 (org-parse-get 'ENTITY-CONTROL
))
1085 (org-parse-entity-format-callbacks-alist
1086 (org-parse-get 'ENTITY-FORMAT
))
1088 (org-export-process-option-filters
1089 (org-combine-plists (org-default-export-plist)
1091 (org-infile-export-plist))))
1092 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1093 valid org-html-dyn-first-heading-pos
1094 (odd org-odd-levels-only
)
1095 (region-p (org-region-active-p))
1096 (rbeg (and region-p
(region-beginning)))
1097 (rend (and region-p
(region-end)))
1099 (if (plist-get opt-plist
:ignore-subtree-p
)
1104 (and (org-at-heading-p)
1105 (>= (org-end-of-subtree t t
) rend
))))))
1106 (level-offset (if subtree-p
1109 (+ (funcall outline-level
)
1110 (if org-odd-levels-only
1 0)))
1112 (opt-plist (setq org-export-opt-plist
1114 (org-export-add-subtree-options opt-plist rbeg
)
1116 ;; The following two are dynamically scoped into other
1118 (org-current-export-dir
1119 (or pub-dir
(org-parse-get 'EXPORT-DIR opt-plist
)))
1120 (org-current-export-file buffer-file-name
)
1121 (level 0) (line "") (origline "") txt todo
1124 (filename (if to-buffer nil
1127 (file-name-sans-extension
1129 (org-entry-get (region-beginning)
1130 "EXPORT_FILE_NAME" t
))
1131 (file-name-nondirectory buffer-file-name
)))
1132 "." (org-parse-get 'FILE-NAME-EXTENSION opt-plist
))
1133 (file-name-as-directory
1134 (or pub-dir
(org-parse-get 'EXPORT-DIR opt-plist
))))))
1135 (current-dir (if buffer-file-name
1136 (file-name-directory buffer-file-name
)
1138 (buffer (if to-buffer
1140 ((eq to-buffer
'string
)
1141 (get-buffer-create (org-parse-get 'EXPORT-BUFFER-NAME
)))
1142 (t (get-buffer-create to-buffer
)))
1144 (or (let ((f (org-parse-get 'INIT-METHOD
)))
1145 (and f
(functionp f
) (funcall f filename
)))
1147 (org-levels-open (make-vector org-level-max nil
))
1148 (date (plist-get opt-plist
:date
))
1150 ((and date
(string-match "%" date
))
1151 (format-time-string date
))
1153 (t (format-time-string "%Y-%m-%d %T %Z"))))
1154 (dummy (setq opt-plist
(plist-put opt-plist
:effective-date date
)))
1155 (title (org-html-expand
1156 (or (and subtree-p
(org-export-get-title-from-subtree))
1157 (plist-get opt-plist
:title
)
1158 (and (not body-only
)
1160 (plist-get opt-plist
:skip-before-1st-heading
))
1161 (org-export-grab-title-from-buffer))
1162 (and buffer-file-name
1163 (file-name-sans-extension
1164 (file-name-nondirectory buffer-file-name
)))
1166 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1167 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1168 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1169 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
1170 (org-parse-dyn-current-environment nil
)
1171 ;; Get the language-dependent settings
1172 (lang-words (or (assoc (plist-get opt-plist
:language
)
1173 org-export-language-setup
)
1174 (assoc "en" org-export-language-setup
)))
1175 (dummy (setq opt-plist
(plist-put opt-plist
:lang-words lang-words
)))
1178 (coding-system-for-write (org-html-get-coding-system-for-write))
1179 (save-buffer-coding-system (org-html-get-coding-system-for-save))
1182 (if region-p
(region-beginning) (point-min))
1183 (if region-p
(region-end) (point-max))))
1184 (org-export-have-math nil
)
1185 (insertion-point-for-normalized-footnotes 'point-min
)
1186 (org-parse-backend (org-parse-get 'BACKEND
))
1189 (org-export-preprocess-string
1192 :for-backend org-parse-backend
1193 :skip-before-1st-heading
1194 (plist-get opt-plist
:skip-before-1st-heading
)
1195 :drawers
(plist-get opt-plist
:drawers
)
1196 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1197 :tags
(plist-get opt-plist
:tags
)
1198 :priority
(plist-get opt-plist
:priority
)
1199 :footnotes
(plist-get opt-plist
:footnotes
)
1200 :timestamps
(plist-get opt-plist
:timestamps
)
1202 (plist-get opt-plist
:archived-trees
)
1203 :select-tags
(plist-get opt-plist
:select-tags
)
1204 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1206 (plist-get opt-plist
:text
)
1208 (plist-get opt-plist
:LaTeX-fragments
))
1211 table-buffer table-orig-buffer
1213 rpl path attr desc descp desc1 desc2 link
1215 footnotes footref-seen
1216 org-html-output-buffer
1217 org-html-footnote-definitions
1218 org-html-footnote-number
1219 org-html-footnote-buffer
1220 org-parse-table-of-contents
1224 (let ((inhibit-read-only t
))
1226 (remove-text-properties (point-min) (point-max)
1227 '(:org-license-to-kill t
))))
1229 (message "Exporting...")
1230 (org-init-section-numbers)
1232 ;; Switch to the output buffer
1233 (setq org-html-output-buffer buffer
)
1234 (set-buffer org-html-output-buffer
)
1235 (let ((inhibit-read-only t
)) (erase-buffer))
1237 (org-install-letbind)
1239 (and (fboundp 'set-buffer-file-coding-system
)
1240 (set-buffer-file-coding-system coding-system-for-write
))
1242 (let ((case-fold-search nil
)
1243 (org-odd-levels-only odd
))
1244 ;; create local variables for all options, to make sure all called
1245 ;; functions get the correct information
1247 (set (make-local-variable (nth 2 x
))
1248 (plist-get opt-plist
(car x
))))
1249 org-export-plist-vars
)
1250 (setq umax
(if arg
(prefix-numeric-value arg
)
1251 org-export-headline-levels
))
1252 (setq umax-toc
(if (integerp org-export-with-toc
)
1253 (min org-export-with-toc umax
)
1256 (when (and org-export-with-toc
(not body-only
))
1257 (setq lines
(org-parse-prepare-toc
1258 lines level-offset opt-plist umax-toc
)))
1261 (org-parse-begin 'DOCUMENT-CONTENT opt-plist
)
1262 (org-parse-begin 'DOCUMENT-BODY opt-plist
))
1265 (org-init-section-numbers)
1267 (org-parse-begin-paragraph)
1269 (while (setq line
(pop lines
) origline line
)
1271 (when (and (org-parse-current-environment-p 'quote
)
1272 (string-match "^\\*+ " line
))
1273 (org-parse-end-environment 'quote
))
1275 (when (org-parse-current-environment-p 'quote
)
1276 (insert (org-parse-format 'PLAIN line
))
1277 (throw 'nextline nil
))
1279 ;; Fixed-width, verbatim lines (examples)
1280 (when (and org-export-with-fixed-width
1281 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1282 (when (not (org-parse-current-environment-p 'fixedwidth
))
1283 (org-parse-begin-environment 'fixedwidth
))
1284 (insert (org-parse-format 'PLAIN
(match-string 3 line
)))
1285 (when (or (not lines
)
1286 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1288 (org-parse-end-environment 'fixedwidth
))
1289 (throw 'nextline nil
))
1291 ;; Notes: The baseline version of org-html.el (git commit
1292 ;; 3d802e), while encoutering a *line-long* protected text,
1293 ;; does one of the following two things based on the state
1294 ;; of the export buffer.
1296 ;; 1. If a paragraph element has just been opened and
1297 ;; contains only whitespace as content, insert the
1298 ;; protected text as part of the previous paragraph.
1300 ;; 2. If the paragraph element has already been opened and
1301 ;; contains some valid content insert the protected text
1302 ;; as part of the current paragraph.
1306 ;; Scenario 1 mentioned above kicks in when a block of
1307 ;; protected text has to be inserted enbloc. For example,
1308 ;; this happens, when inserting an source or example block
1309 ;; or preformatted content enclosed in #+backend,
1310 ;; #+begin_bakend ... #+end_backend)
1312 ;; Scenario 2 mentioned above kicks in when the protected
1313 ;; text is part of a running sentence. For example this
1314 ;; happens in the case of an *multiline* LaTeX equation that
1315 ;; needs to be inserted verbatim.
1317 ;; org-html.el in the master branch seems to do some
1318 ;; jugglery by moving paragraphs around. Inorder to make
1319 ;; these changes backend-agnostic introduce a new text
1320 ;; property org-native-text and impose the added semantics
1321 ;; that these protected blocks appear outside of a
1322 ;; conventional paragraph element.
1324 ;; Extra Note: Check whether org-example and org-native-text
1325 ;; are entirely equivalent.
1327 ;; Fixes bug reported by Christian Moe concerning verbatim
1329 ;; on git commit 533ba3f90250a1f25f494c390d639ea6274f235c
1330 ;; http://repo.or.cz/w/org-mode/org-jambu.git/shortlog/refs/heads/staging
1331 ;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01379.html
1334 (when (and (get-text-property 0 'org-native-text line
)
1335 ;; Make sure it is the entire line that is protected
1336 (not (< (or (next-single-property-change
1337 0 'org-native-text line
) 10000)
1339 (let ((ind (get-text-property 0 'original-indentation line
)))
1340 (org-parse-begin-environment 'native
)
1341 (insert (org-parse-format 'PLAIN line
))
1343 (or (= (length (car lines
)) 0)
1345 (equal ind
(get-text-property
1346 0 'original-indentation
(car lines
))))
1347 (or (= (length (car lines
)) 0)
1348 (get-text-property 0 'org-native-text
(car lines
))))
1349 (insert (org-parse-format 'PLAIN
(pop lines
))))
1350 (org-parse-end-environment 'native
))
1351 (throw 'nextline nil
))
1354 (when (and (get-text-property 0 'org-protected line
)
1355 ;; Make sure it is the entire line that is protected
1356 (not (< (or (next-single-property-change
1357 0 'org-protected line
) 10000)
1359 (let ((ind (get-text-property 0 'original-indentation line
)))
1360 (insert (org-parse-format 'PLAIN line
))
1362 (or (= (length (car lines
)) 0)
1364 (equal ind
(get-text-property
1365 0 'original-indentation
(car lines
))))
1366 (or (= (length (car lines
)) 0)
1367 (get-text-property 0 'org-protected
(car lines
))))
1368 (insert (org-parse-format 'PLAIN
(pop lines
)))))
1369 (throw 'nextline nil
))
1371 ;; Blockquotes, verse, and center
1372 (when (string-match "^ORG-\\(.+\\)-\\(START\\|END\\)$" line
)
1373 (let* ((style (intern (downcase (match-string 1 line
))))
1374 (f (cdr (assoc (match-string 2 line
)
1375 '(("START" . org-parse-begin-environment
)
1376 ("END" . org-parse-end-environment
))))))
1377 (when (memq style
'(blockquote verse center
))
1379 (throw 'nextline nil
))))
1381 (run-hooks 'org-export-html-after-blockquotes-hook
)
1382 (when (org-parse-current-environment-p 'verse
)
1383 (let ((i (org-get-string-indentation line
)))
1386 (let ((org-html-protect t
))
1387 (org-parse-format 'SPACES
(* 2 i
)))
1388 " " (org-trim line
))))
1389 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1390 (setq line
(concat line
"\\\\")))))
1392 ;; make targets to anchors
1394 (while (string-match
1395 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1397 ((get-text-property (match-beginning 1) 'org-protected line
)
1398 (setq start
(match-end 1)))
1400 (setq line
(replace-match
1401 (let ((org-html-protect t
))
1403 'ANCHOR
"" (org-solidify-link-text
1404 (match-string 1 line
))))
1406 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1407 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1408 (setq line
(replace-match
1409 (let ((org-html-protect t
))
1411 'FONTIFY
(match-string 1 line
) "target"))
1412 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1415 (setq line
(replace-match
1417 (let ((org-html-protect t
))
1419 'ANCHOR
(match-string 1 line
)
1420 (org-solidify-link-text (match-string 1 line
))
1424 (let ((org-html-protect t
))
1425 (setq line
(org-html-handle-time-stamps line
)))
1427 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1428 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1429 ;; Also handle sub_superscripts and checkboxes
1430 (or (string-match org-table-hline-regexp line
)
1431 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line
)
1432 (setq line
(org-html-expand line
)))
1434 (setq line
(org-parse-format-org-link line opt-plist
))
1437 (if (and (string-match org-todo-line-regexp line
)
1438 (match-beginning 2))
1440 (substring line
0 (match-beginning 2))
1441 (org-parse-format 'TODO
(match-string 2 line
))
1442 (substring line
(match-end 2)))))
1444 ;; Does this contain a reference to a footnote?
1445 (when org-export-with-footnotes
1447 (while (string-match "\\([^* \t].*?\\)[ \t]*\\[\\([0-9]+\\)\\]" line start
)
1448 (if (get-text-property (match-beginning 2) 'org-protected line
)
1449 (setq start
(match-end 2))
1450 (let ((n (match-string 2 line
)) refcnt a
)
1451 (if (setq a
(assoc n footref-seen
))
1453 (setcdr a
(1+ (cdr a
)))
1454 (setq refcnt
(cdr a
)))
1456 (push (cons n
1) footref-seen
))
1460 (or (match-string 1 line
) "")
1463 n
(cdr (assoc n org-html-footnote-definitions
))
1468 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1469 ;; This is a headline
1470 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1472 txt
(match-string 2 line
))
1473 (if (string-match quote-re0 txt
)
1474 (setq txt
(replace-match "" t t txt
)))
1475 (if (<= level
(max umax umax-toc
))
1476 (setq head-count
(+ head-count
1)))
1477 (unless org-html-dyn-first-heading-pos
1478 (setq org-html-dyn-first-heading-pos
(point)))
1479 (org-parse-begin-level level txt umax head-count
)
1482 (when (string-match quote-re line
)
1483 (org-parse-begin-environment 'quote
)))
1485 ((and org-export-with-tables
1486 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1487 (when (not table-open
)
1489 (setq table-open t table-buffer nil table-orig-buffer nil
))
1492 (setq table-buffer
(cons line table-buffer
)
1493 table-orig-buffer
(cons origline table-orig-buffer
))
1494 (when (or (not lines
)
1495 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1497 (setq table-open nil
1498 table-buffer
(nreverse table-buffer
)
1499 table-orig-buffer
(nreverse table-orig-buffer
))
1500 (org-parse-end-paragraph)
1501 (insert (org-parse-format 'TABLE table-buffer table-orig-buffer
))))
1506 ;; This line either is list item or end a list.
1507 (when (get-text-property 0 'list-item line
)
1508 (setq line
(org-html-export-list-line
1510 (get-text-property 0 'list-item line
)
1511 (get-text-property 0 'list-struct line
)
1512 (get-text-property 0 'list-prevs line
))))
1515 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1516 (with-org-parse-preserve-paragraph-state
1517 (insert (org-parse-format 'HORIZONTAL-LINE
)))
1518 (throw 'nextline nil
))
1520 ;; Empty lines start a new paragraph. If hand-formatted lists
1521 ;; are not fully interpreted, lines starting with "-", "+", "*"
1522 ;; also start a new paragraph.
1523 (when (string-match "^ [-+*]-\\|^[ \t]*$" line
)
1524 (when org-html-footnote-number
1525 (org-parse-end-footnote-definition org-html-footnote-number
)
1526 (setq org-html-footnote-number nil
))
1527 (org-parse-begin-paragraph))
1529 ;; Is this the start of a footnote?
1530 (when org-export-with-footnotes
1531 (when (and (boundp 'footnote-section-tag-regexp
)
1532 (string-match (concat "^" footnote-section-tag-regexp
)
1535 (throw 'nextline nil
))
1536 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1537 (org-parse-end-paragraph)
1538 (setq org-html-footnote-number
(match-string 1 line
))
1539 (setq line
(replace-match "" t t line
))
1540 (org-parse-begin-footnote-definition org-html-footnote-number
)))
1541 ;; Check if the line break needs to be conserved
1543 ((string-match "\\\\\\\\[ \t]*$" line
)
1544 (setq line
(replace-match
1545 (org-parse-format 'LINE-BREAK
)
1547 (org-export-preserve-breaks
1548 (setq line
(concat line
(org-parse-format 'LINE-BREAK
)))))
1550 ;; Check if a paragraph should be started
1552 (while (and org-par-open
1553 (string-match "\\\\par\\>" line start
))
1555 ;; Leave a space in the </p> so that the footnote matcher
1556 ;; does not see this.
1557 (if (not (get-text-property (match-beginning 0)
1558 'org-protected line
))
1559 (setq line
(replace-match "</p ><p >" t t line
)))
1560 (setq start
(match-end 0))))
1562 (insert (org-parse-format 'PLAIN line
))))))
1564 ;; Properly close all local lists and other lists
1565 (when (org-parse-current-environment-p 'quote
)
1566 (org-parse-end-environment 'quote
))
1568 (org-parse-end-level 1 umax
)
1570 ;; the </div> to close the last text-... div.
1571 (when (and (> umax
0) org-html-dyn-first-heading-pos
)
1572 (org-parse-end-outline-text-or-outline))
1574 (org-parse-end 'DOCUMENT-BODY opt-plist
)
1576 (org-parse-end 'DOCUMENT-CONTENT
))
1578 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1581 (org-parse-end 'EXPORT
)
1583 (goto-char (point-min))
1584 (or (org-export-push-to-kill-ring
1585 (upcase (symbol-name org-parse-backend
)))
1586 (message "Exporting... done"))
1590 (let ((f (org-parse-get 'SAVE-METHOD
)))
1591 (or (and f
(functionp f
) (funcall f filename opt-plist
))
1594 ((eq to-buffer
'string
)
1595 (prog1 (buffer-substring (point-min) (point-max))
1596 (kill-buffer (current-buffer))))
1597 (t (current-buffer))))))
1599 (defun org-export-html-format-href (s)
1600 "Make sure the S is valid as a href reference in an XHTML document."
1603 (while (string-match "&" s start
)
1604 (setq start
(+ (match-beginning 0) 3)
1605 s
(replace-match "&" t t s
)))))
1608 (defun org-export-html-format-desc (s)
1609 "Make sure the S is valid as a description in a link."
1610 (if (and s
(not (get-text-property 1 'org-protected s
)))
1612 (org-html-do-expand s
))
1615 (defun org-export-html-format-image (src)
1616 "Create image tag with source and attributes."
1618 (if (string-match "^ltxpng/" src
)
1619 (format "<img src=\"%s\" alt=\"%s\"/>"
1620 src
(org-find-text-property-in-string 'org-latex-src src
))
1621 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1622 (attr (org-find-text-property-in-string 'org-attributes src
))
1623 (label (org-find-text-property-in-string 'org-label src
))
1624 (caption (and caption
(org-html-do-expand caption
)))
1625 (img (format "<img src=\"%s\"%s />"
1627 (if (string-match "\\<alt=" (or attr
""))
1629 (concat " " attr
" alt=\"" src
"\""))))
1632 (format "id=\"%s\" " (org-solidify-link-text label
)))
1633 "class=\"figure\"")))
1636 (with-org-parse-preserve-paragraph-state
1639 '("<div %s>" .
"\n</div>")
1641 (org-parse-format '("\n<p>" .
"</p>") img
)
1642 (org-parse-format '("\n<p>" .
"</p>") caption
))
1647 (defun org-export-html-get-bibliography ()
1648 "Find bibliography, cut it out and return it."
1650 (let (beg end
(cnt 1) bib
)
1652 (goto-char (point-min))
1653 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1654 (setq beg
(match-beginning 0))
1655 (while (re-search-forward "</?div\\>" nil t
)
1656 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1658 (and (looking-at ">") (forward-char 1))
1659 (setq bib
(buffer-substring beg
(point)))
1660 (delete-region beg
(point))
1661 (throw 'exit bib
))))
1664 (defun org-html-format-table (lines olines
)
1665 (let ((org-html-format-table-no-css nil
))
1666 (org-parse-format-table lines olines
)))
1668 ;; Following variable is defined for native tables i.e., when
1669 ;; `org-table-is-styled' evals to t.
1670 (defvar org-html-format-table-no-css
)
1671 (defvar org-table-number-regexp
) ; defined in org-table.el
1672 (defun org-parse-format-table (lines olines
)
1673 "Retuns backend-specific code for org-type and table-type
1676 (setq lines
(org-split-string lines
"\n")))
1677 (if (string-match "^[ \t]*|" (car lines
))
1678 ;; A normal org table
1679 (org-parse-format-org-table lines nil
)
1680 ;; Table made by table.el
1681 (or (org-parse-format-table-table-using-table-generate-source
1682 org-parse-backend olines
1683 (not org-export-prefer-native-exporter-for-tables
))
1684 ;; We are here only when table.el table has NO col or row
1685 ;; spanning and the user prefers using org's own converter for
1686 ;; exporting of such simple table.el tables.
1687 (org-parse-format-table-table lines
))))
1689 (defun org-format-table-html (lines olines
&optional no-css
)
1690 "Find out which HTML converter to use and return the HTML code.
1691 NO-CSS is passed to the exporter."
1692 (let* ((org-parse-get-callback 'org-html-get
)
1693 (org-parse-entity-control-callbacks-alist
1694 (org-parse-get 'ENTITY-CONTROL
))
1695 (org-parse-entity-format-callbacks-alist
1696 (org-parse-get 'ENTITY-FORMAT
))
1697 (org-html-format-table-no-css no-css
))
1698 (org-parse-format-table lines olines
)))
1700 (defun org-table-get-colalign-info (lines)
1701 (let ((forced-aligns (org-find-text-property-in-string
1702 'org-forced-aligns
(car lines
))))
1703 (when (and forced-aligns org-table-clean-did-remove-column
)
1705 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) forced-aligns
)))
1709 (defvar org-table-style
)
1710 (defvar org-table-ncols
)
1711 (defvar org-table-rownum
)
1713 (defvar org-table-is-styled
)
1714 (defvar org-table-begin-marker
)
1715 (defvar org-table-num-numeric-items-per-column
)
1716 (defvar org-table-colalign-info
)
1717 (defvar org-table-colalign-vector
)
1718 (defvar org-table-number-fraction
) ; defined in org-table.el
1719 (defun org-parse-do-format-org-table (lines &optional splice
)
1720 "Format a org-type table into backend-specific code.
1721 LINES is a list of lines. Optional argument SPLICE means, do not
1722 insert header and surrounding <table> tags, just format the lines.
1723 Optional argument NO-CSS means use XHTML attributes instead of CSS
1724 for formatting. This is required for the DocBook exporter."
1725 (require 'org-table
)
1726 ;; Get rid of hlines at beginning and end
1727 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1728 (setq lines
(nreverse lines
))
1729 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1730 (setq lines
(nreverse lines
))
1731 (when org-export-table-remove-special-lines
1732 ;; Check if the table has a marking column. If yes remove the
1733 ;; column and the special lines
1734 (setq lines
(org-table-clean-before-export lines
)))
1736 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1737 (caption (and caption
(org-html-do-expand caption
)))
1738 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1739 (org-table-colalign-info (org-table-get-colalign-info lines
))
1740 (attributes (org-find-text-property-in-string 'org-attributes
1742 (head (and org-export-highlight-first-table-line
1744 (lambda (x) (string-match "^[ \t]*|-" x
))
1746 (org-table-rownum -
1) org-table-ncols i
(cnt 0)
1748 org-table-current-rowgroup-is-header
1749 org-table-rowgroup-open
1750 org-table-num-numeric-items-per-column
1751 org-table-colalign-vector n
1752 org-table-rowgroup-info
1753 org-table-begin-marker
1754 (org-table-style 'org-table
)
1755 org-table-is-styled
)
1758 (setq org-table-is-styled nil
)
1759 (while (setq line
(pop lines
))
1760 (unless (string-match "^[ \t]*|-" line
)
1762 (org-parse-format-table-row
1763 (org-split-string line
"[ \t]*|[ \t]*")) "\n"))))
1765 (setq org-table-is-styled t
)
1766 (org-parse-begin 'TABLE caption label attributes
)
1767 (setq org-table-begin-marker
(point))
1768 (org-parse-begin-table-rowgroup head
)
1769 (while (setq line
(pop lines
))
1771 ((string-match "^[ \t]*|-" line
)
1772 (when lines
(org-parse-begin-table-rowgroup)))
1775 (org-parse-format-table-row
1776 (org-split-string line
"[ \t]*|[ \t]*")) "\n"))))
1777 (org-parse-end 'TABLE-ROWGROUP
)
1778 (org-parse-end-table)))))
1780 (defun org-format-org-table-html (lines &optional splice no-css
)
1781 ;; This routine might get called outside of org-export-as-html. For
1782 ;; example, this could happen as part of org-table-export or as part
1783 ;; of org-export-as-docbook. Explicitly bind the parser callback to
1784 ;; the html ones for the duration of the call.
1785 (let* ((org-parse-get-callback 'org-html-get
)
1786 (org-parse-entity-control-callbacks-alist
1787 (org-parse-get 'ENTITY-CONTROL
))
1788 (org-parse-entity-format-callbacks-alist
1789 (org-parse-get 'ENTITY-FORMAT
))
1790 (org-html-format-table-no-css no-css
))
1791 (org-parse-format-org-table lines splice
)))
1793 (defun org-parse-format-org-table (lines &optional splice
)
1795 (org-parse-do-format-org-table lines splice
)
1796 (buffer-substring-no-properties (point-min) (point-max))))
1798 (defun org-export-splice-attributes (tag attributes
)
1799 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1800 (if (not attributes
)
1802 (let (oldatt newatt
)
1803 (setq oldatt
(org-extract-attributes-from-string tag
)
1805 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1807 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1808 (if (string-match ">" tag
)
1810 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1814 (defun org-parse-do-format-table-table (lines)
1815 "Format a table generated by table.el into backend-specific code.
1816 This conversion does *not* use `table-generate-source' from table.el.
1817 This has the advantage that Org-mode's HTML conversions can be used.
1818 But it has the disadvantage, that no cell- or row-spanning is allowed."
1819 (let (line field-buffer
1820 (org-table-current-rowgroup-is-header
1821 org-export-highlight-first-table-line
)
1825 (org-table-style 'table-table
)
1826 (org-table-is-styled nil
)
1827 fields org-table-ncols i
(org-table-rownum -
1)
1828 (empty (org-parse-format 'SPACES
1)))
1829 (org-parse-begin 'TABLE caption label attributes
)
1830 (while (setq line
(pop lines
))
1832 ((string-match "^[ \t]*\\+-" line
)
1834 (let ((org-export-table-row-tags '("<tr>" .
"</tr>"))
1835 (org-export-html-table-use-header-tags-for-first-column nil
))
1836 (insert (org-parse-format-table-row field-buffer empty
)))
1837 (setq org-table-current-rowgroup-is-header nil
)
1838 (setq field-buffer nil
)))
1840 ;; Break the line into fields and store the fields
1841 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1843 (setq field-buffer
(mapcar
1845 (concat x
(org-parse-format 'LINE-BREAK
)
1848 (setq field-buffer fields
)))))
1849 (org-parse-end-table)))
1851 (defun org-parse-format-table-table (lines)
1853 (org-parse-do-format-table-table lines
)
1854 (buffer-substring-no-properties (point-min) (point-max))))
1856 (defun org-format-table-table-html (lines)
1857 (let* ((org-parse-get-callback 'org-html-get
)
1858 (org-parse-entity-control-callbacks-alist
1859 (org-parse-get 'ENTITY-CONTROL
))
1860 (org-parse-entity-format-callbacks-alist
1861 (org-parse-get 'ENTITY-FORMAT
)))
1862 (org-parse-format-table-table lines
)))
1864 (defun org-parse-format-table-table-using-table-generate-source (backend
1868 "Format a table into BACKEND, using `table-generate-source' from table.el.
1869 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
1871 When SPANNED-ONLY is nil, all table.el tables are exported. When
1872 SPANNED-ONLY is non-nil, only tables with either row or column
1875 This routine returns the generated source or nil as appropriate.
1877 Refer docstring of `org-export-prefer-native-exporter-for-tables'
1878 for further information."
1880 (with-current-buffer (get-buffer-create " org-tmp1 ")
1882 (insert (mapconcat 'identity lines
"\n"))
1883 (goto-char (point-min))
1884 (if (not (re-search-forward "|[^+]" nil t
))
1885 (error "Error processing table"))
1886 (table-recognize-table)
1887 (when (or (not spanned-only
)
1888 (let* ((dim (table-query-dimension))
1889 (c (nth 4 dim
)) (r (nth 5 dim
)) (cells (nth 6 dim
)))
1890 (not (= (* c r
) cells
))))
1891 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1893 ((member backend table-source-languages
)
1894 (table-generate-source backend
" org-tmp2 ")
1895 (set-buffer " org-tmp2 ")
1896 (buffer-substring (point-min) (point-max)))
1898 ;; table.el doesn't support the given backend. Currently this
1899 ;; happens in case of odt export. Strip the table from the
1900 ;; generated document. A better alternative would be to embed
1901 ;; the table as ascii text in the output document.
1904 "Found table.el-type table in the source org file. "
1905 (format "table.el doesn't support %s backend. "
1906 (upcase (symbol-name backend
)))
1907 "Skipping ahead ..."))
1910 (defun org-export-splice-style (style extra
)
1911 "Splice EXTRA into STYLE, just before \"</style>\"."
1912 (if (and (stringp extra
)
1913 (string-match "\\S-" extra
)
1914 (string-match "</style>" style
))
1915 (concat (substring style
0 (match-beginning 0))
1917 (substring style
(match-beginning 0)))
1920 (defun org-html-handle-time-stamps (s)
1921 "Format time stamps in string S, or remove them."
1924 (while (string-match org-maybe-keyword-time-regexp s
)
1925 (or b
(setq b
(substring s
0 (match-beginning 0))))
1927 r
(substring s
0 (match-beginning 0))
1934 (match-string 1 s
) "timestamp-kwd"))
1937 (substring (org-translate-time (match-string 3 s
)) 1 -
1)
1939 "timestamp-wrapper"))
1940 s
(substring s
(match-end 0))))
1941 ;; Line break if line started and ended with time stamp stuff
1944 (setq r
(concat r s
))
1945 (unless (string-match "\\S-" (concat b s
))
1946 (setq r
(concat r
(org-parse-format 'LINE-BREAK
))))
1949 (defvar htmlize-buffer-places
) ; from htmlize.el
1950 (defun org-export-htmlize-region-for-paste (beg end
)
1951 "Convert the region to HTML, using htmlize.el.
1952 This is much like `htmlize-region-for-paste', only that it uses
1953 the settings define in the org-... variables."
1954 (let* ((htmlize-output-type org-export-htmlize-output-type
)
1955 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
1956 (htmlbuf (htmlize-region beg end
)))
1958 (with-current-buffer htmlbuf
1959 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1960 (plist-get htmlize-buffer-places
'content-end
)))
1961 (kill-buffer htmlbuf
))))
1964 (defun org-export-htmlize-generate-css ()
1965 "Create the CSS for all font definitions in the current Emacs session.
1966 Use this to create face definitions in your CSS style file that can then
1967 be used by code snippets transformed by htmlize.
1968 This command just produces a buffer that contains class definitions for all
1969 faces used in the current Emacs session. You can copy and paste the ones you
1970 need into your CSS file.
1972 If you then set `org-export-htmlize-output-type' to `css', calls to
1973 the function `org-export-htmlize-region-for-paste' will produce code
1974 that uses these same face definitions."
1977 (and (get-buffer "*html*") (kill-buffer "*html*"))
1979 (let ((fl (face-list))
1980 (htmlize-css-name-prefix "org-")
1981 (htmlize-output-type 'css
)
1983 (while (setq f
(pop fl
)
1984 i
(and f
(face-attribute f
:inherit
)))
1985 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1986 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1987 (htmlize-region (point-min) (point-max))))
1988 (switch-to-buffer "*html*")
1989 (goto-char (point-min))
1990 (if (re-search-forward "<style" nil t
)
1991 (delete-region (point-min) (match-beginning 0)))
1992 (if (re-search-forward "</style>" nil t
)
1993 (delete-region (1+ (match-end 0)) (point-max)))
1994 (beginning-of-line 1)
1995 (if (looking-at " +") (replace-match ""))
1996 (goto-char (point-min)))
1998 (defun org-html-protect (s)
1999 "Convert characters to HTML equivalent.
2000 Possible conversions are set in `org-export-html-protect-char-alist'."
2001 (let ((cl org-export-html-protect-char-alist
) c
)
2002 (while (setq c
(pop cl
))
2004 (while (string-match (car c
) s start
)
2005 (setq s
(replace-match (cdr c
) t t s
)
2006 start
(1+ (match-beginning 0))))))
2009 (defun org-html-expand (string)
2010 "Prepare STRING for HTML export. Apply all active conversions.
2011 If there are links in the string, don't modify these."
2012 (let* ((re (concat org-bracket-link-regexp
"\\|"
2013 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
2015 (while (setq m
(string-match re string
))
2016 (setq s
(substring string
0 m
)
2017 l
(match-string 0 string
)
2018 string
(substring string
(match-end 0)))
2019 (push (org-html-do-expand s
) res
)
2021 (push (org-html-do-expand string
) res
)
2022 (apply 'concat
(nreverse res
))))
2024 (defun org-html-do-expand (s)
2025 "Apply all active conversions to translate special ASCII to HTML."
2026 (setq s
(org-html-protect s
))
2027 (if org-export-html-expand
2028 (while (string-match "@<\\([^&]*\\)>" s
)
2029 (setq s
(replace-match "<\\1>" t nil s
))))
2030 (if org-export-with-emphasize
2031 (setq s
(org-export-html-convert-emphasize s
)))
2032 (if org-export-with-special-strings
2033 (setq s
(org-export-html-convert-special-strings s
)))
2034 (if org-export-with-sub-superscripts
2035 (setq s
(org-export-html-convert-sub-super s
)))
2036 (if org-export-with-TeX-macros
2037 (let ((start 0) wd rep
)
2038 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2040 (if (get-text-property (match-beginning 0) 'org-protected s
)
2041 (setq start
(match-end 0))
2042 (setq wd
(match-string 1 s
))
2043 (if (setq rep
(org-entity-get-representation wd
'html
))
2044 (setq s
(replace-match rep t t s
))
2045 (setq start
(+ start
(length wd
))))))))
2048 (defun org-export-html-convert-special-strings (string)
2049 "Convert special characters in STRING to HTML."
2050 (let ((all org-export-html-special-string-regexps
)
2052 (while (setq a
(pop all
))
2053 (setq re
(car a
) rpl
(cdr a
) start
0)
2054 (while (string-match re string start
)
2055 (if (get-text-property (match-beginning 0) 'org-protected string
)
2056 (setq start
(match-end 0))
2057 (setq string
(replace-match rpl t nil string
)))))
2060 (defun org-export-html-convert-sub-super (string)
2061 "Convert sub- and superscripts in STRING to HTML."
2062 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2063 (while (string-match org-match-substring-regexp string s
)
2065 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2066 ((get-text-property (match-beginning 2) 'org-protected string
)
2067 (setq s
(match-end 2)))
2069 (setq s
(match-end 1)
2070 key
(if (string= (match-string 2 string
) "_")
2071 'subscript
'superscript
)
2072 c
(or (match-string 8 string
)
2073 (match-string 6 string
)
2074 (match-string 5 string
))
2075 string
(replace-match
2076 (concat (match-string 1 string
)
2077 (org-parse-format 'FONTIFY c key
))
2079 (while (string-match "\\\\\\([_^]\\)" string
)
2080 (setq string
(replace-match (match-string 1 string
) t t string
)))
2083 (defconst org-html-emphasis-alist
2091 (defun org-export-html-convert-emphasize (string)
2094 (while (string-match org-emph-re string s
)
2096 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2097 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2098 (setq s
(match-beginning 0)
2101 (match-string 1 string
)
2103 'FONTIFY
(match-string 4 string
)
2104 (nth 1 (assoc (match-string 3 string
)
2105 org-html-emphasis-alist
)))
2106 (match-string 5 string
))
2107 string
(replace-match rpl t t string
)
2108 s
(+ s
(- (length rpl
) 2)))
2112 (defvar body-only
) ; dynamically scoped into this.
2113 (defun org-export-html-get-tag-class-name (tag)
2114 "Turn tag into a valid class name.
2115 Replaces invalid characters with \"_\" and then prepends a prefix."
2117 (while (string-match "[^a-zA-Z0-9_]" tag
)
2118 (setq tag
(replace-match "_" t t tag
))))
2119 (concat org-export-html-tag-class-prefix tag
))
2121 (defun org-export-html-get-todo-kwd-class-name (kwd)
2122 "Turn todo keyword into a valid class name.
2123 Replaces invalid characters with \"_\" and then prepends a prefix."
2125 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2126 (setq kwd
(replace-match "_" t t kwd
))))
2127 (concat org-export-html-todo-kwd-class-prefix kwd
))
2129 (defun org-html-export-list-line (line pos struct prevs
)
2130 "Insert list syntax in export buffer. Return LINE, maybe modified.
2132 POS is the item position or line position the line had before
2133 modifications to buffer. STRUCT is the list structure. PREVS is
2134 the alist of previous items."
2137 ;; Translate type of list containing POS to "d", "o" or
2139 (lambda (pos struct prevs
)
2140 (let ((type (org-list-get-list-type pos struct prevs
)))
2142 ((eq 'ordered type
) "o")
2143 ((eq 'descriptive type
) "d")
2147 ;; Return list of all items and sublists ending at POS, in
2153 (let ((end (nth 6 e
))
2156 ((= end pos
) (push item out
))
2157 ((>= item pos
) (throw 'exit nil
)))))
2160 ;; First close any previous item, or list, ending at POS.
2162 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2163 (first-item (org-list-get-list-begin e struct prevs
))
2164 (type (funcall get-type first-item struct prevs
)))
2165 (org-parse-end-paragraph)
2166 ;; Ending for every item
2168 ;; We're ending last item of the list: end list.
2170 (org-parse-end 'LIST type
)
2171 (org-parse-begin-paragraph))))
2172 (funcall get-closings pos
))
2174 ;; At an item: insert appropriate tags in export buffer.
2177 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2178 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2179 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2180 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2182 (let* ((checkbox (match-string 3 line
))
2183 (desc-tag (or (match-string 4 line
) "???"))
2184 (body (or (match-string 5 line
) ""))
2185 (list-beg (org-list-get-list-begin pos struct prevs
))
2186 (firstp (= list-beg pos
))
2187 ;; Always refer to first item to determine list type, in
2188 ;; case list is ill-formed.
2189 (type (funcall get-type list-beg struct prevs
))
2190 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2192 ((not count-tmp
) nil
)
2193 ((string-match "[A-Za-z]" count-tmp
)
2194 (- (string-to-char (upcase count-tmp
)) 64))
2195 ((string-match "[0-9]+" count-tmp
)
2198 (org-parse-end-paragraph)
2199 (org-parse-begin 'LIST type
))
2201 (let ((arg (cond ((equal type
"d") desc-tag
)
2202 ((equal type
"o") counter
))))
2203 (org-parse-begin 'LIST-ITEM type arg
))
2205 ;; If line had a checkbox, some additional modification is required.
2213 ((string-match "X" checkbox
) "X")
2214 ((string-match " " checkbox
)
2215 (org-parse-format 'SPACES
1))
2221 ;; Return modified line
2223 ;; At a list ender: go to next line (side-effects only).
2224 ((equal "ORG-LIST-END-MARKER" line
) (throw 'nextline nil
))
2225 ;; Not at an item: return line unchanged (side-effects only).
2230 (defun org-html-bind-local-variables (opt-plist)
2232 (set (make-local-variable (nth 2 x
))
2233 (plist-get opt-plist
(car x
))))
2234 org-export-plist-vars
))
2237 ;; This replaces org-emphasis-alist
2238 (defvar org-table-rowgroup-open
)
2239 (defvar org-table-current-rowgroup-is-header
)
2240 (defvar org-html-footnote-number
)
2241 (defvar org-html-footnote-definitions
)
2242 (defvar org-html-footnote-buffer
)
2243 (defvar org-html-output-buffer
)
2245 (defun org-html-end-export ()
2246 ;; insert the table of contents
2247 (when (and org-export-with-toc
(not body-only
) org-parse-table-of-contents
)
2248 (org-html-insert-toc org-parse-table-of-contents
))
2250 ;; remove empty paragraphs
2251 (goto-char (point-min))
2252 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2255 ;; Convert whitespace place holders
2256 (goto-char (point-min))
2258 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2259 (setq n
(get-text-property beg
'org-whitespace
)
2260 end
(next-single-property-change beg
'org-whitespace
))
2262 (delete-region beg end
)
2263 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2264 (make-string n ?x
)))))
2266 ;; Remove empty lines at the beginning of the file.
2267 (goto-char (point-min))
2268 (when (looking-at "\\s-+\n") (replace-match ""))
2270 ;; Remove display properties
2271 (remove-text-properties (point-min) (point-max) '(display t
))
2273 ;; kill temporary buffers
2274 (when org-html-footnote-buffer
2275 (kill-buffer org-html-footnote-buffer
))
2278 (run-hooks 'org-export-html-final-hook
))
2283 ;;;_ , user-specific
2284 ;;;_ . custom-settings
2285 (defcustom org-parse-debug nil
2294 ;;;_ . control callbacks
2296 (defun org-parse-begin (entity &rest args
)
2297 (when (and (member org-parse-debug
'(t control
))
2298 (not (eq entity
'DOCUMENT-CONTENT
)))
2299 (insert (org-parse-format 'COMMENT
"%s BEGIN %S" entity args
)))
2301 (let ((f (cadr (assoc entity org-parse-entity-control-callbacks-alist
))))
2302 (unless f
(error "Unknown entity: %s" entity
))
2305 (defun org-parse-end (entity &rest args
)
2306 (when (and (member org-parse-debug
'(t control
))
2307 (not (eq entity
'DOCUMENT-CONTENT
)))
2308 (insert (org-parse-format 'COMMENT
"%s END %S" entity args
)))
2310 (let ((f (caddr (assoc entity org-parse-entity-control-callbacks-alist
))))
2311 (unless f
(error "Unknown entity: %s" entity
))
2316 (defun org-parse-begin-paragraph (&optional style
)
2317 "Insert <p>, but first close previous paragraph if any."
2318 (org-parse-end-paragraph)
2319 (org-parse-begin 'PARAGRAPH style
)
2320 (setq org-par-open t
))
2322 (defun org-parse-end-paragraph ()
2323 "Close paragraph if there is one open."
2325 (org-parse-end 'PARAGRAPH
)
2326 (setq org-par-open nil
)))
2329 (defun org-close-li (&optional type
)
2330 "Close <li> if necessary."
2331 (org-parse-end-paragraph)
2332 (org-parse-end 'LIST-ITEM
(or type
"u")))
2336 (defvar org-parse-dyn-current-environment nil
)
2337 (defun org-parse-begin-environment (style)
2338 (assert (not org-parse-dyn-current-environment
) t
)
2339 (setq org-parse-dyn-current-environment style
)
2340 (org-parse-begin 'ENVIRONMENT style
))
2342 (defun org-parse-end-environment (style)
2343 (org-parse-end 'ENVIRONMENT style
)
2345 (assert (eq org-parse-dyn-current-environment style
) t
)
2346 (setq org-parse-dyn-current-environment nil
))
2348 (defun org-parse-current-environment-p (style)
2349 (eq org-parse-dyn-current-environment style
))
2352 ;;;_ , footnote definition
2353 (defun org-parse-begin-footnote-definition (n)
2354 (unless org-html-footnote-buffer
2355 (setq org-html-footnote-buffer
2356 (get-buffer-create "*Org HTML Export Footnotes*")))
2357 (set-buffer org-html-footnote-buffer
)
2359 (setq org-html-insert-tag-with-newlines nil
)
2360 (org-parse-begin 'FOOTNOTE-DEFINITION n
))
2362 (defun org-parse-end-footnote-definition (n)
2363 (org-parse-end 'FOOTNOTE-DEFINITION n
)
2364 (setq org-html-insert-tag-with-newlines
'both
)
2365 (push (cons n
(buffer-string)) org-html-footnote-definitions
)
2366 (set-buffer org-html-output-buffer
))
2371 ;;;_ . format callbacks
2373 (defun org-parse-format (entity &rest args
)
2374 (when (and (member org-parse-debug
'(t format
))
2375 (not (equal entity
'COMMENT
)))
2376 (insert (org-parse-format 'COMMENT
"%s: %S" entity args
)))
2379 (let ((text (pop args
)))
2380 (apply 'org-parse-format
'TAGS entity text args
)))
2382 (let ((f (cdr (assoc entity org-parse-entity-format-callbacks-alist
))))
2383 (unless f
(error "Unknown entity: %s" entity
))
2387 ;;;_ , toc (rename these routines)
2388 (defun org-html-format-toc-entry (snumber todo headline tags href
)
2389 (setq headline
(concat
2390 (and org-export-with-section-numbers
2391 (concat snumber
" "))
2395 (org-parse-format 'SPACES
3)
2396 (org-parse-format 'FONTIFY tags
"tag")))))
2398 (setq headline
(org-parse-format 'FONTIFY headline
"todo")))
2399 (org-parse-format 'LINK headline
(concat "#" href
)))
2401 (defun org-html-format-toc-item (toc-entry level org-last-level
)
2402 (when (> level org-last-level
)
2403 (let ((cnt (- level org-last-level
)))
2404 (while (>= (setq cnt
(1- cnt
)) 0)
2405 (org-parse-begin 'LIST
'unordered
)
2406 (org-parse-begin 'LIST-ITEM
'unordered
))))
2407 (when (< level org-last-level
)
2408 (let ((cnt (- org-last-level level
)))
2409 (while (>= (setq cnt
(1- cnt
)) 0)
2411 (org-parse-end 'LIST
'unordered
))))
2414 (org-parse-begin 'LIST-ITEM
'unordered
)
2417 (defun org-html-begin-toc (lang-specific-heading)
2418 (org-html-insert-tag "<div id=\"table-of-contents\">")
2420 (org-parse-format 'HEADING lang-specific-heading
2421 (or (org-parse-get 'TOPLEVEL-HLEVEL
) 1)))
2422 (org-html-insert-tag "<div id=\"text-table-of-contents\">")
2423 (org-parse-begin 'LIST
'unordered
)
2424 (org-parse-begin 'LIST-ITEM
'unordered
))
2426 (defun org-html-end-toc ()
2427 (while (> org-last-level
(1- org-min-level
))
2428 (setq org-last-level
(1- org-last-level
))
2430 (org-parse-end 'LIST
'unordered
))
2431 (org-html-insert-tag "</div>")
2432 (org-html-insert-tag "</div>")
2434 ;; cleanup empty list items in toc
2435 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t
)
2436 (replace-match "")))
2438 (defun org-parse-prepare-toc (lines level-offset opt-plist umax-toc
)
2439 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2440 (org-min-level (org-get-min-level lines level-offset
))
2441 (org-last-level org-min-level
)
2444 (org-html-bind-local-variables opt-plist
)
2446 (org-parse-begin 'TOC
(nth 3 (plist-get opt-plist
:lang-words
)))
2451 (when (and (string-match org-todo-line-regexp line
)
2452 (not (get-text-property 0 'org-protected line
))
2453 (<= (setq level
(org-tr-level
2454 (- (match-end 1) (match-beginning 1)
2457 (let ((txt (save-match-data
2459 (org-export-cleanup-toc-line
2460 (match-string 3 line
)))))
2462 org-export-mark-todo-in-toc
2463 (or (and (match-beginning 2)
2464 (not (member (match-string 2 line
)
2465 org-done-keywords
)))
2466 (and (= level umax-toc
)
2467 (org-search-todo-below
2468 line lines level
)))))
2470 ;; Check for targets
2471 (while (string-match org-any-target-regexp line
)
2474 (let ((org-html-protect t
))
2475 (org-parse-format 'FONTIFY
2476 (match-string 1 line
) "target"))
2479 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2480 (setq tags
(match-string 1 txt
)
2481 txt
(replace-match "" t nil txt
)))
2482 (when (string-match quote-re0 txt
)
2483 (setq txt
(replace-match "" t t txt
)))
2484 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2485 (setq txt
(replace-match "" t t txt
)))
2488 (let* ((snumber (org-section-number level
))
2489 (href (replace-regexp-in-string
2490 "\\." "_" (format "sec-%s" snumber
)))
2494 href org-export-preferred-target-alist
))
2496 (href (org-solidify-link-text href
)))
2497 (org-parse-format 'TOC-ENTRY snumber todo txt tags href
))
2498 level org-last-level
)
2499 (setq org-last-level level
)))
2502 (org-parse-end 'TOC
)
2503 (setq org-parse-table-of-contents
(buffer-string))))
2508 (defun org-parse-format-table-row (fields &optional text-for-empty-fields
)
2509 (unless org-table-ncols
2510 ;; first row of the table
2511 (setq org-table-ncols
(length fields
))
2512 (when org-table-is-styled
2513 (setq org-table-num-numeric-items-per-column
(make-vector org-table-ncols
0))
2514 (setq org-table-colalign-vector
(make-vector org-table-ncols nil
))
2516 (while (< (incf c
) org-table-ncols
)
2517 (let ((cookie (cdr (assoc (1+ c
) org-table-colalign-info
))))
2518 (setf (aref org-table-colalign-vector c
)
2520 ((string= cookie
"l") "left")
2521 ((string= cookie
"r") "right")
2522 ((string= cookie
"c") "center")
2524 (incf org-table-rownum
)
2531 (when (string= x
"")
2532 (setq x text-for-empty-fields
))
2534 (and org-table-is-styled
2535 (< i org-table-ncols
)
2536 (string-match org-table-number-regexp x
)
2537 (incf (aref org-table-num-numeric-items-per-column i
)))
2538 (org-parse-format 'TABLE-CELL x org-table-rownum i
))
2542 (defun org-parse-get (what &optional opt-plist
)
2543 (funcall org-parse-get-callback what opt-plist
))
2552 ;;;_. hacks (to be documented)
2554 ;; Refer `org-html-emphasis-alist'
2557 ;;;_ , custom settings
2558 ;;;_ . potential custom settings
2559 ;;;_ , interactive commands
2562 (defun org-export-as-html-and-open (arg)
2563 "Export the outline as HTML and immediately open it with a browser.
2564 If there is an active region, export only the region.
2565 The prefix ARG specifies how many levels of the outline should become
2566 headlines. The default is 3. Lower levels will become bulleted lists."
2568 (org-export-as-and-open "html" arg
))
2571 (defun org-export-as-html-batch ()
2572 "Call the function `org-export-as-html'.
2573 This function can be used in batch processing as:
2575 --load=$HOME/lib/emacs/org.el
2576 --eval \"(setq org-export-headline-levels 2)\"
2577 --visit=MyFile --funcall org-export-as-html-batch"
2578 (org-export-as-batch "html"))
2581 (defun org-export-as-html-to-buffer (arg)
2582 "Call `org-export-as-html` with output to a temporary buffer.
2583 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2585 (org-export-as-to-buffer "html" arg
))
2588 (defun org-replace-region-by-html (beg end
)
2589 "Assume the current region has org-mode syntax, and convert it to HTML.
2590 This can be used in any buffer. For example, you could write an
2591 itemized list in org-mode syntax in an HTML buffer and then use this
2592 command to convert it."
2594 (org-replace-region-by "html" beg end
))
2597 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2598 "Convert region from BEG to END in org-mode buffer to HTML.
2599 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2600 contents, and only produce the region of converted text, useful for
2601 cut-and-paste operations.
2602 If BUFFER is a buffer or a string, use/create that buffer as a target
2603 of the converted HTML. If BUFFER is the symbol `string', return the
2604 produced HTML as a string and leave not buffer behind. For example,
2605 a Lisp program could call this function in the following way:
2607 (setq html (org-export-region-as-html beg end t 'string))
2609 When called interactively, the output buffer is selected, and shown
2610 in a window. A non-interactive call will only return the buffer."
2611 (interactive "r\nP")
2612 (org-export-region-as "html" beg end body-only buffer
))
2614 ;;; org-export-as-html
2616 (defun org-export-as-html (arg &optional hidden ext-plist
2617 to-buffer body-only pub-dir
)
2618 "Export the outline as a pretty HTML file.
2619 If there is an active region, export only the region. The prefix
2620 ARG specifies how many levels of the outline should become
2621 headlines. The default is 3. Lower levels will become bulleted
2622 lists. HIDDEN is obsolete and does nothing.
2623 EXT-PLIST is a property list with external parameters overriding
2624 org-mode's default settings, but still inferior to file-local
2625 settings. When TO-BUFFER is non-nil, create a buffer with that
2626 name and export to that buffer. If TO-BUFFER is the symbol
2627 `string', don't leave any buffer behind but just return the
2628 resulting HTML as a string. When BODY-ONLY is set, don't produce
2629 the file header and footer, simply return the content of
2630 <body>...</body>, without even the body tags themselves. When
2631 PUB-DIR is set, use this as the publishing directory."
2633 (org-export-as "html" arg hidden ext-plist to-buffer body-only pub-dir
))
2636 ;;;_ , initialization
2637 (defvar org-html-entity-control-callbacks-alist
2639 .
(org-html-begin-export org-html-end-export
))
2641 .
(org-html-begin-document-content org-html-end-document-content
))
2643 .
(org-html-begin-document-body org-html-end-document-body
))
2645 .
(org-html-begin-toc org-html-end-toc
))
2647 .
(org-html-begin-environment org-html-end-environment
))
2648 (FOOTNOTE-DEFINITION
2649 .
(org-html-begin-footnote-definition org-html-end-footnote-definition
))
2651 .
(org-html-begin-table org-html-end-table
))
2653 .
(org-html-begin-table-rowgroup org-html-end-table-rowgroup
))
2655 .
(org-html-begin-list org-html-end-list
))
2657 .
(org-html-begin-list-item org-html-end-list-item
))
2659 .
(org-html-begin-outline org-html-end-outline
))
2661 .
(org-html-begin-outline-text org-html-end-outline-text
))
2663 .
(org-html-begin-paragraph org-html-end-paragraph
)))
2666 (defvar org-html-entity-format-callbacks-alist
2667 `((EXTRA-TARGETS . org-html-format-extra-targets
)
2668 (ORG-TAGS . org-html-format-org-tags
)
2669 (SECTION-NUMBER . org-html-format-section-number
)
2670 (HEADLINE . org-html-format-headline
)
2671 (TOC-ENTRY . org-html-format-toc-entry
)
2672 (TOC-ITEM . org-html-format-toc-item
)
2673 (TAGS . org-html-format-tags
)
2674 (SPACES . org-html-format-spaces
)
2675 (TABS . org-html-format-tabs
)
2676 (LINE-BREAK . org-html-format-line-break
)
2677 (FONTIFY . org-html-format-fontify
)
2678 (TODO . org-html-format-todo
)
2679 (ORG-LINK . org-html-format-org-link
)
2680 (LINK . org-html-format-link
)
2681 (INLINE-IMAGE . org-html-format-inline-image
)
2682 (HEADING . org-html-format-heading
)
2683 (ANCHOR . org-html-format-anchor
)
2684 (TABLE . org-html-format-table
)
2685 (TABLE-ROW . org-html-format-table-row
)
2686 (TABLE-CELL . org-html-format-table-cell
)
2687 (FOOTNOTES-SECTION . org-html-format-footnotes-section
)
2688 (FOOTNOTE-REFERENCE . org-html-format-footnote-reference
)
2689 (HORIZONTAL-LINE . org-html-format-horizontal-line
)
2690 (PLAIN . org-html-format-plain
)
2691 (COMMENT . org-html-format-comment
))
2695 ;;;_ . control callbacks
2697 (defun org-html-insert-tag (tag &rest args
)
2698 (when (member org-html-insert-tag-with-newlines
'(lead both
))
2700 (insert (apply 'format tag args
))
2701 (when (member org-html-insert-tag-with-newlines
'(trail both
))
2704 ;;;_ , document body
2705 (defun org-html-begin-document-body (opt-plist)
2706 (let ((link-up (and (plist-get opt-plist
:link-up
)
2707 (string-match "\\S-" (plist-get opt-plist
:link-up
))
2708 (plist-get opt-plist
:link-up
)))
2709 (link-home (and (plist-get opt-plist
:link-home
)
2710 (string-match "\\S-" (plist-get opt-plist
:link-home
))
2711 (plist-get opt-plist
:link-home
))))
2713 (org-html-insert-tag "<div id=\"content\">")
2715 (or (and (or link-up link-home
)
2716 (format org-export-html-home
/up-format
2717 (or link-up link-home
)
2718 (or link-home link-up
))) "")
2720 (org-html-insert-preamble opt-plist
))
2722 (defun org-html-end-document-body (opt-plist)
2723 (org-html-insert-postamble opt-plist
)
2725 (org-html-insert-tag "</div>")
2726 (insert "\n</body>")))
2729 ;;;_ , document content
2730 (defun org-html-begin-document-content (opt-plist)
2731 (let* ((language (plist-get opt-plist
:language
))
2732 (charset (or (and coding-system-for-write
2733 (fboundp 'coding-system-get
)
2734 (coding-system-get coding-system-for-write
2737 (style (concat (if (plist-get opt-plist
:style-include-default
)
2738 org-export-html-style-default
)
2739 (plist-get opt-plist
:style
)
2740 (plist-get opt-plist
:style-extra
)
2742 (if (plist-get opt-plist
:style-include-scripts
)
2743 org-export-html-scripts
)))
2745 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
2746 (and org-export-have-math
2747 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
2749 (org-export-html-mathjax-config
2750 org-export-html-mathjax-template
2751 org-export-html-mathjax-options
2752 (or (plist-get opt-plist
:mathjax
) "")) "")))
2755 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2756 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2757 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2758 lang=\"%s\" xml:lang=\"%s\">
2761 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2762 <meta name=\"generator\" content=\"Org-mode\"/>
2763 <meta name=\"generated\" content=\"%s\"/>
2764 <meta name=\"author\" content=\"%s\"/>
2765 <meta name=\"description\" content=\"%s\"/>
2766 <meta name=\"keywords\" content=\"%s\"/>
2772 (or (and (stringp org-export-html-xml-declaration
)
2773 org-export-html-xml-declaration
)
2774 (cdr (assoc (plist-get opt-plist
:html-extension
)
2775 org-export-html-xml-declaration
))
2776 (cdr (assoc "html" org-export-html-xml-declaration
))
2781 (plist-get opt-plist
:title
)
2783 (plist-get opt-plist
:effective-date
)
2784 (plist-get opt-plist
:author
)
2785 (plist-get opt-plist
:description
)
2786 (plist-get opt-plist
:keywords
)
2790 (defun org-html-end-document-content ()
2791 (insert "\n</html>\n"))
2793 (defun org-parse-target-from-snumber (snumber) ; can be removed
2794 (let* ((snu (replace-regexp-in-string "\\." "_" snumber
))
2795 (sec-snu (concat "sec-" snu
)))
2796 (org-solidify-link-text
2797 (or (cdr (assoc sec-snu org-export-preferred-target-alist
))
2800 (defun org-parse-get-targets-from-title (title)
2801 (let* ((target (org-get-text-property-any 0 'target title
))
2802 (extra-targets (assoc target org-export-target-aliases
))
2803 (target (or (cdr (assoc target org-export-preferred-target-alist
))
2805 (cons target
(remove target extra-targets
))))
2807 (defun org-parse-suffix-from-snumber (snumber)
2808 (let* ((snu (replace-regexp-in-string "\\." "_" snumber
))
2809 (href (cdr (assoc (concat "sec-" snu
)
2810 org-export-preferred-target-alist
))))
2811 (org-solidify-link-text (or href snu
))))
2814 (defun org-parse-begin-level (level title umax head-count
)
2815 "Insert a new level in HTML export.
2816 When TITLE is nil, just close all open levels."
2817 (org-parse-end-level level umax
)
2818 (unless title
(error "Why is heading nil"))
2819 (let* ((targets (org-parse-get-targets-from-title title
))
2820 (target (car targets
)) (extra-targets (cdr targets
))
2821 (target (and target
(org-solidify-link-text target
)))
2822 (extra-class (org-get-text-property-any 0 'html-container-class title
))
2823 snumber tags level1 class
)
2824 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2825 (setq tags
(and org-export-with-tags
(match-string 1 title
)))
2826 (setq title
(replace-match "" t t title
)))
2829 (if (aref org-levels-open
(1- level
))
2831 (aset org-levels-open
(1- level
) t
)
2832 (org-parse-end-paragraph)
2833 (org-parse-begin 'LIST
'unordered
))
2835 'LIST-ITEM
'unordered target
2836 (org-parse-format 'HEADLINE title extra-targets tags
)))
2837 (aset org-levels-open
(1- level
) t
)
2838 (setq snumber
(org-section-number level
))
2839 (setq level1
(+ level
(or (org-parse-get 'TOPLEVEL-HLEVEL
) 1) -
1))
2840 (unless (= head-count
1)
2841 (org-parse-end-outline-text-or-outline))
2842 (org-parse-begin-outline-and-outline-text
2843 level1 snumber title tags target extra-targets extra-class
)
2844 (org-parse-begin-paragraph))))
2846 (defun org-parse-end-level (level umax
)
2847 (org-parse-end-paragraph)
2848 (loop for l from org-level-max downto level
2849 do
(when (aref org-levels-open
(1- l
))
2850 ;; Terminate one level in HTML export
2852 (org-parse-end-outline-text-or-outline)
2854 (org-parse-end 'LIST
'unordered
))
2855 (aset org-levels-open
(1- l
) nil
))))
2858 ;;;_ , outline and outline text
2859 (defvar org-parse-outline-text-open
)
2860 (defun org-parse-begin-outline-and-outline-text (level1 snumber title tags
2861 target extra-targets
2864 'OUTLINE level1 snumber title tags target extra-targets extra-class
)
2865 (org-parse-begin-outline-text level1 snumber extra-class
))
2867 (defun org-parse-end-outline-text-or-outline ()
2869 (org-parse-outline-text-open
2870 (org-parse-end 'OUTLINE-TEXT
)
2871 (setq org-parse-outline-text-open nil
))
2872 (t (org-parse-end 'OUTLINE
))))
2874 (defun org-parse-begin-outline-text (level1 snumber extra-class
)
2875 (assert (not org-parse-outline-text-open
) t
)
2876 (setq org-parse-outline-text-open t
)
2877 (org-parse-begin 'OUTLINE-TEXT level1 snumber extra-class
))
2880 (defun org-html-begin-outline (level1 snumber title tags
2881 target extra-targets extra-class
)
2882 (let* ((class (format "outline-%d" level1
))
2883 (class (if extra-class
(concat class
" " extra-class
) class
))
2884 (id (format "outline-container-%s"
2885 (org-parse-suffix-from-snumber snumber
)))
2886 (extra (concat (when id
(format " id=\"%s\"" id
))
2887 (when class
(format " class=\"%s\"" class
)))))
2888 (org-html-insert-tag "<div%s>" extra
)
2890 (org-parse-format 'HEADING
2892 'HEADLINE title extra-targets tags snumber level1
)
2895 (defun org-html-end-outline ()
2896 (org-html-insert-tag "</div>"))
2899 (defun org-html-begin-outline-text (level1 snumber extra-class
)
2900 (let* ((class (format "outline-text-%d" level1
))
2901 (class (if extra-class
(concat class
" " extra-class
) class
))
2902 (id (format "text-%s" (org-parse-suffix-from-snumber snumber
)))
2903 (extra (concat (when id
(format " id=\"%s\"" id
))
2904 (when class
(format " class=\"%s\"" class
)))))
2905 (org-html-insert-tag "<div%s>" extra
)))
2907 (defun org-html-end-outline-text ()
2908 (org-html-insert-tag "</div>"))
2911 (defun org-html-begin-paragraph (&optional style
)
2912 (let* ((class (cdr (assoc style
'((footnote .
"footnote")
2914 (extra (if class
(format " class=\"%s\"" class
) "")))
2915 (org-html-insert-tag "<p%s>" extra
)))
2917 (defun org-html-end-paragraph ()
2921 (defun org-html-format-environment (style beg-end
)
2922 (assert (memq style
'(blockquote center verse fixedwidth quote native
)) t
)
2927 (org-parse-end-paragraph)
2928 (insert "<blockquote>\n")
2929 (org-parse-begin-paragraph))
2931 (org-parse-end-paragraph)
2932 (insert "\n</blockquote>\n")
2933 (org-parse-begin-paragraph))))
2937 (org-parse-end-paragraph)
2938 (insert "\n<p class=\"verse\">\n")
2939 (setq org-par-open t
))
2942 (setq org-par-open nil
)
2943 (org-parse-begin-paragraph))))
2947 (org-parse-end-paragraph)
2948 (insert "\n<div style=\"text-align: center\">")
2949 (org-parse-begin-paragraph))
2951 (org-parse-end-paragraph)
2953 (org-parse-begin-paragraph))))
2957 (org-parse-end-paragraph)
2958 (insert "<pre class=\"example\">\n"))
2961 (org-parse-begin-paragraph))))
2965 (org-parse-end-paragraph)
2969 (org-parse-begin-paragraph))))
2972 (BEGIN (org-parse-end-paragraph))
2973 (END (org-parse-begin-paragraph))))
2974 (t (error "Unknown environment %s" style
))))
2977 (defun org-html-begin-environment (style)
2978 (org-html-format-environment style
'BEGIN
))
2980 (defun org-html-end-environment (style)
2981 (org-html-format-environment style
'END
))
2985 (defun org-html-html-list-type-to-canonical-list-type (ltype)
2986 (cdr (assoc ltype
'(("o" . ordered
)
2988 ("d" . description
)))))
2990 (defun org-html-begin-list (ltype &optional arg1
)
2991 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
2995 (ordered (let ((extra (if arg1
(format " start=\"%d\"" arg1
) "")))
2996 (org-html-insert-tag "<ol%s>" extra
)))
2997 (unordered (org-html-insert-tag "<ul>"))
2998 (description (org-html-insert-tag "<dl>"))
2999 (t (error "Unknown list type: %s" ltype
))))
3001 (defun org-html-end-list (ltype)
3002 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
3005 (org-html-insert-tag
3009 (description "</dl>")
3010 (t (error "Unknown list type: %s" ltype
)))))
3012 (defun org-html-begin-list-item (ltype &optional arg headline
)
3013 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
3017 (assert (not headline
) t
)
3018 (let* ((counter arg
)
3019 (extra (if counter
(format " value=\"%s\"" counter
) "")))
3020 (org-html-insert-tag "<li%s>" extra
)))
3023 (extra (if id
(format " id=\"%s\"" id
) "")))
3024 (org-html-insert-tag "<li%s>" extra
)
3026 (insert headline
(org-parse-format 'LINE-BREAK
) "\n"))))
3028 (assert (not headline
) t
)
3029 (let* ((desc-tag (or arg
"(no term)")))
3031 (org-html-format-tags '("<dt>" .
"</dt>") desc-tag
))
3032 (org-html-insert-tag "<dd>")))
3033 (t (error "Unknown list type"))))
3035 (defun org-html-end-list-item (ltype)
3036 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
3039 (ordered (org-html-insert-tag "</li>"))
3040 (unordered (org-html-insert-tag "</li>"))
3041 (description (org-html-insert-tag "</dd>"))
3042 (t (error "Unknown list type"))))
3047 (defvar org-table-rowgroup-info
)
3048 (defun org-parse-begin-table-rowgroup (&optional is-header-row
)
3049 (push (cons (1+ org-table-rownum
) :start
) org-table-rowgroup-info
)
3050 (org-parse-begin 'TABLE-ROWGROUP is-header-row
))
3052 (defun org-html-begin-table-rowgroup (&optional is-header-row
)
3053 (when org-table-rowgroup-open
3054 (org-parse-end 'TABLE-ROWGROUP
))
3055 (org-html-insert-tag (if is-header-row
"<thead>" "<tbody>"))
3056 (setq org-table-rowgroup-open t
)
3057 (setq org-table-current-rowgroup-is-header is-header-row
))
3059 (defun org-html-end-table-rowgroup ()
3060 (when org-table-rowgroup-open
3061 (setq org-table-rowgroup-open nil
)
3062 (org-html-insert-tag
3063 (if org-table-current-rowgroup-is-header
"</thead>" "</tbody>"))))
3065 (defun org-html-begin-table (caption label attributes
)
3066 (let ((html-table-tag
3067 (org-export-splice-attributes html-table-tag attributes
)))
3069 (setq html-table-tag
3070 (org-export-splice-attributes
3072 (format "id=\"%s\"" (org-solidify-link-text label
)))))
3073 (org-html-insert-tag html-table-tag
))
3075 ;; Since the output of HTML table formatter can also be used in
3076 ;; DocBook document, we want to always include the caption to make
3077 ;; DocBook XML file valid.
3078 (insert (format "<caption>%s</caption>" (or caption
"")) "\n"))
3080 (defun org-parse-end-table ()
3081 (when org-table-is-styled
3083 (unless (car org-table-colgroup-info
)
3084 (setq org-table-colgroup-info
3085 (cons :start
(cdr org-table-colgroup-info
))))
3092 (setf (aref org-table-colalign-vector c
)
3093 (or (aref org-table-colalign-vector c
)
3094 (if (> (/ (float x
) (1+ org-table-rownum
))
3095 org-table-number-fraction
)
3097 org-table-num-numeric-items-per-column
)))
3098 (org-parse-end 'TABLE
))
3100 (defun org-html-end-table ()
3101 (when org-table-is-styled
3102 (goto-char org-table-begin-marker
)
3103 (setq org-table-begin-marker nil
)
3105 (let ((c -
1) gr colgropen
)
3110 (setq gr
(pop org-table-colgroup-info
))
3113 (if (memq gr
'(:start
:startend
))
3116 "</colgroup>\n<colgroup>"
3121 (let* ((align (aref org-table-colalign-vector c
))
3122 (alignspec (if org-html-format-table-no-css
3123 " align=\"%s\"" " class=\"%s\""))
3124 (extra (format alignspec align
)))
3125 (format "<col%s />" extra
))
3127 (if (memq gr
'(:end
:startend
))
3128 (progn (setq colgropen nil
) "</colgroup>")
3130 org-table-num-numeric-items-per-column
""))
3132 (if colgropen
(insert "</colgroup>")))
3134 ;; fill style attributes for table cells
3135 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t
)
3136 (let ((c (string-to-number (match-string 1))))
3138 (if org-export-html-table-align-individual-fields
3139 (format (if org-html-format-table-no-css
" align=\"%s\""
3141 (or (aref org-table-colalign-vector c
) "left")) "")
3143 (goto-char (point-max)))
3144 (org-html-insert-tag "</table>\n"))
3146 (defun org-html-format-table-row (row)
3147 (org-html-format-tags
3148 (cons (eval (car org-export-table-row-tags
))
3149 (eval (cdr org-export-table-row-tags
))) row
))
3151 (defun org-html-format-table-cell (text r c
)
3152 (let ((cell-style-cookie (or (and org-table-is-styled
3153 (format "@@class%03d@@" c
)) "")))
3155 (org-table-current-rowgroup-is-header
3156 (org-html-format-tags
3157 org-export-table-header-tags text
"col" cell-style-cookie
))
3158 ((and (= c
0) org-export-html-table-use-header-tags-for-first-column
)
3159 (org-html-format-tags
3160 org-export-table-header-tags text
"row" cell-style-cookie
))
3162 (org-html-format-tags
3163 org-export-table-data-tags text cell-style-cookie
)))))
3166 ;;;_ , footnote definition
3167 (defun org-html-begin-footnote-definition (n)
3168 (org-parse-begin-paragraph 'footnote
)
3171 (format org-export-html-footnote-format
3172 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
3175 (defun org-html-end-footnote-definition (n)
3176 (org-parse-end-paragraph))
3178 ;;;_ . format callbacks
3180 (defvar org-html-protect nil
)
3182 (defun org-html-format-spaces (n)
3183 (let ((space (or (and org-html-protect
"\\nbsp") " ")) out
)
3185 (setq out
(concat out space
))
3186 (setq n
(1- n
))) out
))
3189 (defun org-html-format-tabs (&optional n
)
3193 (defun org-html-format-line-break ()
3194 (org-html-format-tags "<br/>" ""))
3196 ;;;_ , horizontal line
3197 (defun org-html-format-horizontal-line ()
3198 (concat "\n" "<hr/>" "\n"))
3202 (defun org-html-format-plain (line)
3203 (case org-parse-dyn-current-environment
3204 ((quote fixedwidth
) (concat (org-html-protect line
) "\n"))
3205 (t (concat line
"\n"))))
3207 (defun org-html-format-comment (fmt &rest args
)
3208 (let ((comment (apply 'format fmt args
)))
3209 (format "\n<!-- %s -->\n" comment
)))
3212 ;;;_ , character styles
3213 (defun org-html-format-fontify (text style
&optional id
)
3214 (let (class extra how
)
3216 ((eq style
'underline
)
3217 (setq extra
" style=\"text-decoration:underline;\"" ))
3218 ((setq how
(cdr (assoc style
3219 '((bold .
("<b>" .
"</b>"))
3220 (emphasis .
("<i>" .
"</i>"))
3221 (code .
("<code>" .
"</code>"))
3222 (verbatim .
("<code>" .
"</code>"))
3223 (strike .
("<del>" .
"</del>"))
3224 (subscript .
("<sub>" .
"</sub>"))
3225 (superscript .
("<sup>" .
"</sup>")))))))
3227 (setq class
(mapconcat 'identity style
" ")))
3230 (t (error "Unknown style %S" style
)))
3232 (setq extra
(concat (when class
(format " class=\"%s\"" class
))
3233 (when id
(format " id=\"%s\"" id
))
3235 (org-html-format-tags
3236 (or how
'("<span%s>" .
"</span>")) text extra
)))
3239 (defun org-html-format-link (text href
&optional extra
)
3240 (let ((extra (concat (format " href=\"%s\"" href
)
3241 (and extra
(concat " " extra
)))))
3242 (org-html-format-tags '("<a%s>" .
"</a>") text extra
)))
3245 (defun org-html-format-heading (text level
&optional id
)
3246 (let* ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3247 (concat (format "<h%d%s>" level extra
) text
(format "</h%d>" level
))))
3250 (defun org-html-format-headline (title extra-targets tags
3251 &optional snumber level
)
3253 (org-parse-format 'EXTRA-TARGETS extra-targets
)
3254 (concat (org-parse-format 'SECTION-NUMBER snumber level
) " ")
3256 (and tags
(concat (org-parse-format 'SPACES
3)
3257 (org-parse-format 'ORG-TAGS tags
)))))
3260 (defun org-html-format-anchor (text name
&optional class
)
3263 (when name
(format " name=\"%s\"" name
))
3264 (when id
(format " id=\"%s\"" id
))
3265 (when class
(format " class=\"%s\"" class
)))))
3266 (org-html-format-tags '("<a%s>" .
"</a>") text extra
)))
3271 ;;;_ , footnote reference
3272 (defun org-html-format-footnote-reference (n def refcnt
)
3273 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
3274 (format org-export-html-footnote-format
3276 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
3281 ;;;_ , footnotes section
3282 (defun org-html-format-footnotes-section (section-name definitions
)
3283 (if (not definitions
) ""
3284 (format org-export-html-footnotes-section section-name definitions
)))
3289 (defun org-html-format-tags (tag text
&rest args
)
3290 (let ((prefix (when org-html-protect
"@"))
3291 (suffix (when org-html-protect
"@")))
3294 (concat prefix
(apply 'format
(car tag
) args
) text suffix
3295 (format (cdr tag
))))
3296 ((stringp tag
) ; singleton tag
3297 (concat prefix
(apply 'format tag args
) text
)))))
3299 ;;;_ . maintenance callbacks
3302 ;;;_ , cleanup method
3304 (defun org-html-get (what &optional opt-plist
)
3309 (CLEANUP-METHOD nil
)
3310 (EXPORT-DIR (org-export-directory :html opt-plist
))
3311 (FILE-NAME-EXTENSION (plist-get opt-plist
:html-extension
))
3312 (EXPORT-BUFFER-NAME "*Org HTML Export*")
3313 (ENTITY-CONTROL org-html-entity-control-callbacks-alist
)
3314 (ENTITY-FORMAT org-html-entity-format-callbacks-alist
)
3315 (TOPLEVEL-HLEVEL org-export-html-toplevel-hlevel
)
3316 (SPECIAL-STRING-REGEXPS org-export-html-special-string-regexps
)
3317 (t (error "Unknown property: %s" what
))))
3319 ;;;_ , coding system
3320 (defun org-html-get-coding-system-for-write ()
3321 (or org-export-html-coding-system
3322 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
3324 (defun org-html-get-coding-system-for-save ()
3325 (or org-export-html-coding-system
3326 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
3329 ;;;_. newhtml (non-parser & misc)
3330 (defun org-html-insert-toc (toc)
3331 ;; locate where toc needs to be inserted
3332 (goto-char (point-min))
3334 ((or (re-search-forward "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3335 (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t
))
3336 (goto-char (match-beginning 0))
3339 (org-html-dyn-first-heading-pos
3340 (goto-char org-html-dyn-first-heading-pos
)
3341 (when (looking-at "\\s-*</p>")
3342 (goto-char (match-end 0))
3347 (defun org-html-insert-preamble (opt-plist)
3348 (when (plist-get opt-plist
:html-preamble
)
3349 (let ((html-pre (plist-get opt-plist
:html-preamble
))
3350 (title (plist-get opt-plist
:title
))
3351 (date (plist-get opt-plist
:effective-date
))
3352 (author (plist-get opt-plist
:author
))
3353 (lang-words (plist-get opt-plist
:lang-words
))
3354 (email (plist-get opt-plist
:email
)))
3355 (cond ((stringp html-pre
)
3357 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
3358 (?d .
,date
) (?e .
,email
)))))
3359 ((functionp html-pre
)
3360 (funcall html-pre opt-plist
))
3364 (or (cadr (assoc (nth 0 lang-words
)
3365 org-export-html-preamble-format
))
3366 (cadr (assoc "en" org-export-html-preamble-format
)))
3367 `((?t .
,title
) (?a .
,author
)
3368 (?d .
,date
) (?e .
,email
)))))))))
3370 (defun org-html-insert-postamble (opt-plist)
3371 (when org-html-footnote-definitions
3374 'FOOTNOTES-SECTION
(nth 4 (plist-get opt-plist
:lang-words
))
3375 (mapconcat (lambda (x) (cdr x
))
3376 (nreverse org-html-footnote-definitions
) "\n"))))
3377 (let ((bib (org-export-html-get-bibliography)))
3379 (insert "\n" bib
"\n")))
3381 ;; export html postamble
3383 (let* ((html-post (plist-get opt-plist
:html-postamble
))
3384 (date (plist-get opt-plist
:effective-date
))
3385 (author (plist-get opt-plist
:author
))
3386 (email (plist-get opt-plist
:email
))
3387 (lang-words (plist-get opt-plist
:lang-words
))
3388 (html-validation-link (or org-export-html-validation-link
""))
3390 (mapconcat (lambda(e)
3391 (format "<a href=\"mailto:%s\">%s</a>" e e
))
3392 (split-string email
",+ *")
3395 (concat "Org version " org-version
" with Emacs version "
3396 (number-to-string emacs-major-version
))))
3397 (when (plist-get opt-plist
:html-postamble
)
3398 (cond ((stringp html-post
)
3399 (insert "<div id=\"postamble\">\n")
3400 (insert (format-spec html-post
3401 `((?a .
,author
) (?e .
,email
)
3402 (?d .
,date
) (?c .
,creator-info
)
3403 (?v .
,html-validation-link
))))
3405 ((functionp html-post
)
3406 (funcall html-post opt-plist
))
3407 ((eq html-post
'auto
)
3408 ;; fall back on default postamble
3409 (insert "<div id=\"postamble\">\n")
3410 (when (plist-get opt-plist
:time-stamp-file
)
3411 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
3412 (when (and (plist-get opt-plist
:author-info
) author
)
3413 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
3414 (when (and (plist-get opt-plist
:email-info
) email
)
3415 (insert "<p class=\"email\">" email
"</p>\n"))
3416 (when (plist-get opt-plist
:creator-info
)
3417 (insert "<p class=\"creator\">"
3418 (concat "Org version " org-version
" with Emacs version "
3419 (number-to-string emacs-major-version
) "</p>\n")))
3420 (insert html-validation-link
"\n</div>"))
3422 (insert "<div id=\"postamble\">\n")
3423 (insert (format-spec
3424 (or (cadr (assoc (nth 0 lang-words
)
3425 org-export-html-postamble-format
))
3426 (cadr (assoc "en" org-export-html-postamble-format
)))
3427 `((?a .
,author
) (?e .
,email
)
3428 (?d .
,date
) (?c .
,creator-info
)
3429 (?v .
,html-validation-link
))))
3430 (insert "</div>"))))))
3432 (if org-export-html-with-timestamp
3433 (insert org-export-html-html-helper-timestamp
)))
3435 (defun org-html-format-todo (todo)
3436 (org-parse-format 'FONTIFY
3437 (org-export-html-get-todo-kwd-class-name todo
)
3438 (list (if (member todo org-done-keywords
) "done" "todo")
3441 (defun org-html-format-extra-targets (extra-targets)
3442 (if (not extra-targets
) ""
3443 (mapconcat (lambda (x)
3444 (setq x
(org-solidify-link-text
3445 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
3446 (org-parse-format 'ANCHOR
"" x
))
3449 (defun org-html-format-org-tags (tags)
3455 'FONTIFY x
(org-export-html-get-tag-class-name x
)))
3456 (org-split-string tags
":")
3457 (org-parse-format 'SPACES
1)) "tag")))
3459 (defun org-html-format-section-number (&optional snumber level
)
3460 (and org-export-with-section-numbers
3461 (not body-only
) snumber level
3462 (org-parse-format 'FONTIFY snumber
(format "section-number-%d" level
))))
3464 (defun org-parse-warn (msg)
3465 (put-text-property 0 (length msg
) 'face
'font-lock-warning-face msg
)
3474 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
3475 ;;; org-html.el ends here