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
))
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-html-and-open (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."
652 (org-export-as-html arg
'hidden
)
653 (org-open-file buffer-file-name
)
654 (when org-export-kill-product-buffer-when-displayed
655 (kill-buffer (current-buffer))))
658 (defun org-export-as-html-batch ()
659 "Call the function `org-export-as-html'.
660 This function can be used in batch processing as:
662 --load=$HOME/lib/emacs/org.el
663 --eval \"(setq org-export-headline-levels 2)\"
664 --visit=MyFile --funcall org-export-as-html-batch"
665 (org-export-as-html org-export-headline-levels
'hidden
))
668 (defun org-export-as-html-to-buffer (arg)
669 "Call `org-export-as-html` with output to a temporary buffer.
670 No file is created. The prefix ARG is passed through to `org-export-as-html'."
672 (org-export-as-html arg nil nil
"*Org HTML Export*")
673 (when org-export-show-temporary-export-buffer
674 (switch-to-buffer-other-window "*Org HTML Export*")))
677 (defun org-replace-region-by-html (beg end
)
678 "Assume the current region has org-mode syntax, and convert it to HTML.
679 This can be used in any buffer. For example, you could write an
680 itemized list in org-mode syntax in an HTML buffer and then use this
681 command to convert it."
683 (let (reg html buf pop-up-frames
)
684 (save-window-excursion
686 (setq html
(org-export-region-as-html
688 (setq reg
(buffer-substring beg end
)
689 buf
(get-buffer-create "*Org tmp*"))
690 (with-current-buffer buf
694 (setq html
(org-export-region-as-html
695 (point-min) (point-max) t
'string
)))
697 (delete-region beg end
)
701 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
702 "Convert region from BEG to END in org-mode buffer to HTML.
703 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
704 contents, and only produce the region of converted text, useful for
705 cut-and-paste operations.
706 If BUFFER is a buffer or a string, use/create that buffer as a target
707 of the converted HTML. If BUFFER is the symbol `string', return the
708 produced HTML as a string and leave not buffer behind. For example,
709 a Lisp program could call this function in the following way:
711 (setq html (org-export-region-as-html beg end t 'string))
713 When called interactively, the output buffer is selected, and shown
714 in a window. A non-interactive call will only return the buffer."
716 (when (interactive-p)
717 (setq buffer
"*Org HTML Export*"))
718 (let ((transient-mark-mode t
) (zmacs-regions t
)
720 (setq ext-plist
(plist-put ext-plist
:ignore-subtree-p t
))
722 (set-mark (point)) ;; to activate the region
724 (setq rtn
(org-export-as-html
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 ;;; org-export-as-html
1025 (defun org-export-as-html (arg &optional hidden ext-plist
1026 to-buffer body-only pub-dir
)
1027 "Export the outline as a pretty HTML file.
1028 If there is an active region, export only the region. The prefix
1029 ARG specifies how many levels of the outline should become
1030 headlines. The default is 3. Lower levels will become bulleted
1031 lists. HIDDEN is obsolete and does nothing.
1032 EXT-PLIST is a property list with external parameters overriding
1033 org-mode's default settings, but still inferior to file-local
1034 settings. When TO-BUFFER is non-nil, create a buffer with that
1035 name and export to that buffer. If TO-BUFFER is the symbol
1036 `string', don't leave any buffer behind but just return the
1037 resulting HTML as a string. When BODY-ONLY is set, don't produce
1038 the file header and footer, simply return the content of
1039 <body>...</body>, without even the body tags themselves. When
1040 PUB-DIR is set, use this as the publishing directory."
1042 (run-hooks 'org-export-first-hook
)
1044 (let* ((org-parse-get-callback 'org-html-get
))
1045 (org-do-export arg hidden ext-plist to-buffer body-only pub-dir
)))
1047 ;; Following variables are let-bound while `org-do-export' is in
1049 (defvar org-html-dyn-first-heading-pos
)
1050 (defvar org-parse-table-of-contents
)
1051 (defvar org-parse-entity-control-callbacks-alist
)
1052 (defvar org-parse-entity-format-callbacks-alist
)
1053 (defvar org-parse-get-callback
)
1055 (defun org-do-export (arg &optional hidden ext-plist
1056 to-buffer body-only pub-dir
)
1057 "Export the outline as a pretty HTML file."
1058 ;; Make sure we have a file name when we need it.
1059 (when (and (not (or to-buffer body-only
))
1060 (not buffer-file-name
))
1061 (if (buffer-base-buffer)
1062 (org-set-local 'buffer-file-name
1063 (with-current-buffer (buffer-base-buffer)
1065 (error "Need a file name to be able to export")))
1067 (message "Exporting...")
1068 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1069 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
1070 (setq-default org-done-keywords org-done-keywords
)
1071 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
1072 (let* (org-html-protect
1074 (org-parse-entity-control-callbacks-alist
1075 (org-parse-get 'ENTITY-CONTROL
))
1076 (org-parse-entity-format-callbacks-alist
1077 (org-parse-get 'ENTITY-FORMAT
))
1079 (org-export-process-option-filters
1080 (org-combine-plists (org-default-export-plist)
1082 (org-infile-export-plist))))
1083 (body-only (or body-only
(plist-get opt-plist
:body-only
)))
1084 valid org-html-dyn-first-heading-pos
1085 (odd org-odd-levels-only
)
1086 (region-p (org-region-active-p))
1087 (rbeg (and region-p
(region-beginning)))
1088 (rend (and region-p
(region-end)))
1090 (if (plist-get opt-plist
:ignore-subtree-p
)
1095 (and (org-at-heading-p)
1096 (>= (org-end-of-subtree t t
) rend
))))))
1097 (level-offset (if subtree-p
1100 (+ (funcall outline-level
)
1101 (if org-odd-levels-only
1 0)))
1103 (opt-plist (setq org-export-opt-plist
1105 (org-export-add-subtree-options opt-plist rbeg
)
1107 ;; The following two are dynamically scoped into other
1109 (org-current-export-dir
1110 (or pub-dir
(org-parse-get 'EXPORT-DIR opt-plist
)))
1111 (org-current-export-file buffer-file-name
)
1112 (level 0) (line "") (origline "") txt todo
1115 (filename (if to-buffer nil
1118 (file-name-sans-extension
1120 (org-entry-get (region-beginning)
1121 "EXPORT_FILE_NAME" t
))
1122 (file-name-nondirectory buffer-file-name
)))
1123 "." (org-parse-get 'FILE-NAME-EXTENSION opt-plist
))
1124 (file-name-as-directory
1125 (or pub-dir
(org-parse-get 'EXPORT-DIR opt-plist
))))))
1126 (current-dir (if buffer-file-name
1127 (file-name-directory buffer-file-name
)
1129 (buffer (if to-buffer
1131 ((eq to-buffer
'string
)
1132 (get-buffer-create (org-parse-get 'EXPORT-BUFFER-NAME
)))
1133 (t (get-buffer-create to-buffer
)))
1135 (or (let ((f (org-parse-get 'INIT-METHOD
)))
1136 (and f
(functionp f
) (funcall f filename
)))
1138 (org-levels-open (make-vector org-level-max nil
))
1139 (date (plist-get opt-plist
:date
))
1141 ((and date
(string-match "%" date
))
1142 (format-time-string date
))
1144 (t (format-time-string "%Y-%m-%d %T %Z"))))
1145 (dummy (setq opt-plist
(plist-put opt-plist
:effective-date date
)))
1146 (title (org-html-expand
1147 (or (and subtree-p
(org-export-get-title-from-subtree))
1148 (plist-get opt-plist
:title
)
1149 (and (not body-only
)
1151 (plist-get opt-plist
:skip-before-1st-heading
))
1152 (org-export-grab-title-from-buffer))
1153 (and buffer-file-name
1154 (file-name-sans-extension
1155 (file-name-nondirectory buffer-file-name
)))
1157 (dummy (setq opt-plist
(plist-put opt-plist
:title title
)))
1158 (html-table-tag (plist-get opt-plist
:html-table-tag
))
1159 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1160 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
1161 (org-parse-dyn-current-environment nil
)
1162 ;; Get the language-dependent settings
1163 (lang-words (or (assoc (plist-get opt-plist
:language
)
1164 org-export-language-setup
)
1165 (assoc "en" org-export-language-setup
)))
1166 (dummy (setq opt-plist
(plist-put opt-plist
:lang-words lang-words
)))
1169 (coding-system-for-write (org-html-get-coding-system-for-write))
1170 (save-buffer-coding-system (org-html-get-coding-system-for-save))
1173 (if region-p
(region-beginning) (point-min))
1174 (if region-p
(region-end) (point-max))))
1175 (org-export-have-math nil
)
1176 (insertion-point-for-normalized-footnotes 'point-min
)
1177 (org-parse-backend (org-parse-get 'BACKEND
))
1180 (org-export-preprocess-string
1183 :for-backend org-parse-backend
1184 :skip-before-1st-heading
1185 (plist-get opt-plist
:skip-before-1st-heading
)
1186 :drawers
(plist-get opt-plist
:drawers
)
1187 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
1188 :tags
(plist-get opt-plist
:tags
)
1189 :priority
(plist-get opt-plist
:priority
)
1190 :footnotes
(plist-get opt-plist
:footnotes
)
1191 :timestamps
(plist-get opt-plist
:timestamps
)
1193 (plist-get opt-plist
:archived-trees
)
1194 :select-tags
(plist-get opt-plist
:select-tags
)
1195 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
1197 (plist-get opt-plist
:text
)
1199 (plist-get opt-plist
:LaTeX-fragments
))
1202 table-buffer table-orig-buffer
1204 rpl path attr desc descp desc1 desc2 link
1206 footnotes footref-seen
1207 org-html-output-buffer
1208 org-html-footnote-definitions
1209 org-html-footnote-number
1210 org-html-footnote-buffer
1211 org-parse-table-of-contents
1215 (let ((inhibit-read-only t
))
1217 (remove-text-properties (point-min) (point-max)
1218 '(:org-license-to-kill t
))))
1220 (message "Exporting...")
1221 (org-init-section-numbers)
1223 ;; Switch to the output buffer
1224 (setq org-html-output-buffer buffer
)
1225 (set-buffer org-html-output-buffer
)
1226 (let ((inhibit-read-only t
)) (erase-buffer))
1228 (org-install-letbind)
1230 (and (fboundp 'set-buffer-file-coding-system
)
1231 (set-buffer-file-coding-system coding-system-for-write
))
1233 (let ((case-fold-search nil
)
1234 (org-odd-levels-only odd
))
1235 ;; create local variables for all options, to make sure all called
1236 ;; functions get the correct information
1238 (set (make-local-variable (nth 2 x
))
1239 (plist-get opt-plist
(car x
))))
1240 org-export-plist-vars
)
1241 (setq umax
(if arg
(prefix-numeric-value arg
)
1242 org-export-headline-levels
))
1243 (setq umax-toc
(if (integerp org-export-with-toc
)
1244 (min org-export-with-toc umax
)
1247 (when (and org-export-with-toc
(not body-only
))
1248 (setq lines
(org-parse-prepare-toc
1249 lines level-offset opt-plist umax-toc
)))
1252 (org-parse-begin 'DOCUMENT-CONTENT opt-plist
)
1253 (org-parse-begin 'DOCUMENT-BODY opt-plist
))
1256 (org-init-section-numbers)
1258 (org-parse-begin-paragraph)
1260 (while (setq line
(pop lines
) origline line
)
1262 (when (and (org-parse-current-environment-p 'quote
)
1263 (string-match "^\\*+ " line
))
1264 (org-parse-end-environment 'quote
))
1266 (when (org-parse-current-environment-p 'quote
)
1267 (insert (org-parse-format 'PLAIN line
))
1268 (throw 'nextline nil
))
1270 ;; Fixed-width, verbatim lines (examples)
1271 (when (and org-export-with-fixed-width
1272 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
1273 (when (not (org-parse-current-environment-p 'fixedwidth
))
1274 (org-parse-begin-environment 'fixedwidth
))
1275 (insert (org-parse-format 'PLAIN
(match-string 3 line
)))
1276 (when (or (not lines
)
1277 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
1279 (org-parse-end-environment 'fixedwidth
))
1280 (throw 'nextline nil
))
1282 ;; Notes: The baseline version of org-html.el (git commit
1283 ;; 3d802e), while encoutering a *line-long* protected text,
1284 ;; does one of the following two things based on the state
1285 ;; of the export buffer.
1287 ;; 1. If a paragraph element has just been opened and
1288 ;; contains only whitespace as content, insert the
1289 ;; protected text as part of the previous paragraph.
1291 ;; 2. If the paragraph element has already been opened and
1292 ;; contains some valid content insert the protected text
1293 ;; as part of the current paragraph.
1297 ;; Scenario 1 mentioned above kicks in when a block of
1298 ;; protected text has to be inserted enbloc. For example,
1299 ;; this happens, when inserting an source or example block
1300 ;; or preformatted content enclosed in #+backend,
1301 ;; #+begin_bakend ... #+end_backend)
1303 ;; Scenario 2 mentioned above kicks in when the protected
1304 ;; text is part of a running sentence. For example this
1305 ;; happens in the case of an *multiline* LaTeX equation that
1306 ;; needs to be inserted verbatim.
1308 ;; org-html.el in the master branch seems to do some
1309 ;; jugglery by moving paragraphs around. Inorder to make
1310 ;; these changes backend-agnostic introduce a new text
1311 ;; property org-native-text and impose the added semantics
1312 ;; that these protected blocks appear outside of a
1313 ;; conventional paragraph element.
1315 ;; Extra Note: Check whether org-example and org-native-text
1316 ;; are entirely equivalent.
1318 ;; Fixes bug reported by Christian Moe concerning verbatim
1320 ;; on git commit 533ba3f90250a1f25f494c390d639ea6274f235c
1321 ;; http://repo.or.cz/w/org-mode/org-jambu.git/shortlog/refs/heads/staging
1322 ;; See http://lists.gnu.org/archive/html/emacs-orgmode/2011-03/msg01379.html
1325 (when (and (get-text-property 0 'org-native-text line
)
1326 ;; Make sure it is the entire line that is protected
1327 (not (< (or (next-single-property-change
1328 0 'org-native-text line
) 10000)
1330 (let ((ind (get-text-property 0 'original-indentation line
)))
1331 (org-parse-begin-environment 'native
)
1332 (insert (org-parse-format 'PLAIN line
))
1334 (or (= (length (car lines
)) 0)
1336 (equal ind
(get-text-property
1337 0 'original-indentation
(car lines
))))
1338 (or (= (length (car lines
)) 0)
1339 (get-text-property 0 'org-native-text
(car lines
))))
1340 (insert (org-parse-format 'PLAIN
(pop lines
))))
1341 (org-parse-end-environment 'native
))
1342 (throw 'nextline nil
))
1345 (when (and (get-text-property 0 'org-protected line
)
1346 ;; Make sure it is the entire line that is protected
1347 (not (< (or (next-single-property-change
1348 0 'org-protected line
) 10000)
1350 (let ((ind (get-text-property 0 'original-indentation line
)))
1351 (insert (org-parse-format 'PLAIN line
))
1353 (or (= (length (car lines
)) 0)
1355 (equal ind
(get-text-property
1356 0 'original-indentation
(car lines
))))
1357 (or (= (length (car lines
)) 0)
1358 (get-text-property 0 'org-protected
(car lines
))))
1359 (insert (org-parse-format 'PLAIN
(pop lines
)))))
1360 (throw 'nextline nil
))
1362 ;; Blockquotes, verse, and center
1363 (when (string-match "^ORG-\\(.+\\)-\\(START\\|END\\)$" line
)
1364 (let* ((style (intern (downcase (match-string 1 line
))))
1365 (f (cdr (assoc (match-string 2 line
)
1366 '(("START" . org-parse-begin-environment
)
1367 ("END" . org-parse-end-environment
))))))
1368 (when (memq style
'(blockquote verse center
))
1370 (throw 'nextline nil
))))
1372 (run-hooks 'org-export-html-after-blockquotes-hook
)
1373 (when (org-parse-current-environment-p 'verse
)
1374 (let ((i (org-get-string-indentation line
)))
1377 (let ((org-html-protect t
))
1378 (org-parse-format 'SPACES
(* 2 i
)))
1379 " " (org-trim line
))))
1380 (unless (string-match "\\\\\\\\[ \t]*$" line
)
1381 (setq line
(concat line
"\\\\")))))
1383 ;; make targets to anchors
1385 (while (string-match
1386 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start
)
1388 ((get-text-property (match-beginning 1) 'org-protected line
)
1389 (setq start
(match-end 1)))
1391 (setq line
(replace-match
1392 (let ((org-html-protect t
))
1394 'ANCHOR
"" (org-solidify-link-text
1395 (match-string 1 line
))))
1397 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
1398 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
1399 (setq line
(replace-match
1400 (let ((org-html-protect t
))
1402 'FONTIFY
(match-string 1 line
) "target"))
1403 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1406 (setq line
(replace-match
1408 (let ((org-html-protect t
))
1410 'ANCHOR
(match-string 1 line
)
1411 (org-solidify-link-text (match-string 1 line
))
1415 (let ((org-html-protect t
))
1416 (setq line
(org-html-handle-time-stamps line
)))
1418 ;; replace "&" by "&", "<" and ">" by "<" and ">"
1419 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
1420 ;; Also handle sub_superscripts and checkboxes
1421 (or (string-match org-table-hline-regexp line
)
1422 (setq line
(org-html-expand line
)))
1424 (setq line
(org-parse-format-org-link line opt-plist
))
1427 (if (and (string-match org-todo-line-regexp line
)
1428 (match-beginning 2))
1430 (substring line
0 (match-beginning 2))
1431 (org-parse-format 'TODO
(match-string 2 line
))
1432 (substring line
(match-end 2)))))
1434 ;; Does this contain a reference to a footnote?
1435 (when org-export-with-footnotes
1437 (while (string-match "\\([^* \t].*?\\)[ \t]*\\[\\([0-9]+\\)\\]" line start
)
1438 (if (get-text-property (match-beginning 2) 'org-protected line
)
1439 (setq start
(match-end 2))
1440 (let ((n (match-string 2 line
)) refcnt a
)
1441 (if (setq a
(assoc n footref-seen
))
1443 (setcdr a
(1+ (cdr a
)))
1444 (setq refcnt
(cdr a
)))
1446 (push (cons n
1) footref-seen
))
1450 (or (match-string 1 line
) "")
1453 n
(cdr (assoc n org-html-footnote-definitions
))
1458 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1459 ;; This is a headline
1460 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
1462 txt
(match-string 2 line
))
1463 (if (string-match quote-re0 txt
)
1464 (setq txt
(replace-match "" t t txt
)))
1465 (if (<= level
(max umax umax-toc
))
1466 (setq head-count
(+ head-count
1)))
1467 (unless org-html-dyn-first-heading-pos
1468 (setq org-html-dyn-first-heading-pos
(point)))
1469 (org-parse-begin 'LEVEL level txt umax head-count
)
1472 (when (string-match quote-re line
)
1473 (org-parse-begin-environment 'quote
)))
1475 ((and org-export-with-tables
1476 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1477 (when (not table-open
)
1479 (setq table-open t table-buffer nil table-orig-buffer nil
))
1482 (setq table-buffer
(cons line table-buffer
)
1483 table-orig-buffer
(cons origline table-orig-buffer
))
1484 (when (or (not lines
)
1485 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1487 (setq table-open nil
1488 table-buffer
(nreverse table-buffer
)
1489 table-orig-buffer
(nreverse table-orig-buffer
))
1490 (org-parse-end-paragraph)
1491 (insert (org-format-table-html table-buffer table-orig-buffer
))))
1496 ;; This line either is list item or end a list.
1497 (when (get-text-property 0 'list-item line
)
1498 (setq line
(org-html-export-list-line
1500 (get-text-property 0 'list-item line
)
1501 (get-text-property 0 'list-struct line
)
1502 (get-text-property 0 'list-prevs line
))))
1505 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
1506 (with-org-parse-preserve-paragraph-state
1507 (insert (org-parse-format 'HORIZONTAL-LINE
)))
1508 (throw 'nextline nil
))
1510 ;; Empty lines start a new paragraph. If hand-formatted lists
1511 ;; are not fully interpreted, lines starting with "-", "+", "*"
1512 ;; also start a new paragraph.
1513 (when (string-match "^ [-+*]-\\|^[ \t]*$" line
)
1514 (when org-html-footnote-number
1515 (org-parse-end-footnote-definition org-html-footnote-number
)
1516 (setq org-html-footnote-number nil
))
1517 (org-parse-begin-paragraph))
1519 ;; Is this the start of a footnote?
1520 (when org-export-with-footnotes
1521 (when (and (boundp 'footnote-section-tag-regexp
)
1522 (string-match (concat "^" footnote-section-tag-regexp
)
1525 (throw 'nextline nil
))
1526 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
1527 (org-parse-end-paragraph)
1528 (setq org-html-footnote-number
(match-string 1 line
))
1529 (setq line
(replace-match "" t t line
))
1530 (org-parse-begin-footnote-definition org-html-footnote-number
)))
1531 ;; Check if the line break needs to be conserved
1533 ((string-match "\\\\\\\\[ \t]*$" line
)
1534 (setq line
(replace-match
1535 (org-parse-format 'LINE-BREAK
)
1537 (org-export-preserve-breaks
1538 (setq line
(concat line
(org-parse-format 'LINE-BREAK
)))))
1540 ;; Check if a paragraph should be started
1542 (while (and org-par-open
1543 (string-match "\\\\par\\>" line start
))
1545 ;; Leave a space in the </p> so that the footnote matcher
1546 ;; does not see this.
1547 (if (not (get-text-property (match-beginning 0)
1548 'org-protected line
))
1549 (setq line
(replace-match "</p ><p >" t t line
)))
1550 (setq start
(match-end 0))))
1552 (insert (org-parse-format 'PLAIN line
))))))
1554 ;; Properly close all local lists and other lists
1555 (when (org-parse-current-environment-p 'quote
)
1556 (org-parse-end-environment 'quote
))
1558 (org-parse-end 'LEVEL
1 umax
)
1560 ;; the </div> to close the last text-... div.
1561 (when (and (> umax
0) org-html-dyn-first-heading-pos
)
1562 (org-parse-end 'SECTION
))
1564 (org-parse-end 'DOCUMENT-BODY opt-plist
)
1566 (org-parse-end 'DOCUMENT-CONTENT
))
1568 (unless (plist-get opt-plist
:buffer-will-be-killed
)
1571 (org-parse-end 'EXPORT
)
1573 (goto-char (point-min))
1574 (or (org-export-push-to-kill-ring
1575 (upcase (symbol-name org-parse-backend
)))
1576 (message "Exporting... done"))
1580 (let ((f (org-parse-get 'SAVE-METHOD
)))
1581 (or (and f
(functionp f
) (funcall f filename
))
1584 ((eq to-buffer
'string
)
1585 (prog1 (buffer-substring (point-min) (point-max))
1586 (kill-buffer (current-buffer))))
1587 (t (current-buffer))))))
1589 (defun org-export-html-format-href (s)
1590 "Make sure the S is valid as a href reference in an XHTML document."
1593 (while (string-match "&" s start
)
1594 (setq start
(+ (match-beginning 0) 3)
1595 s
(replace-match "&" t t s
)))))
1598 (defun org-export-html-format-desc (s)
1599 "Make sure the S is valid as a description in a link."
1600 (if (and s
(not (get-text-property 1 'org-protected s
)))
1602 (org-html-do-expand s
))
1605 (defun org-export-html-format-image (src)
1606 "Create image tag with source and attributes."
1608 (if (string-match "^ltxpng/" src
)
1609 (format "<img src=\"%s\" alt=\"%s\"/>"
1610 src
(org-find-text-property-in-string 'org-latex-src src
))
1611 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
1612 (attr (org-find-text-property-in-string 'org-attributes src
))
1613 (label (org-find-text-property-in-string 'org-label src
))
1614 (caption (and caption
(org-html-do-expand caption
)))
1615 (img (format "<img src=\"%s\"%s />"
1617 (if (string-match "\\<alt=" (or attr
""))
1619 (concat " " attr
" alt=\"" src
"\""))))
1622 (format "id=\"%s\" " (org-solidify-link-text label
)))
1623 "class=\"figure\"")))
1626 (with-org-parse-preserve-paragraph-state
1629 '("<div %s>" .
"\n</div>")
1631 (org-parse-format '("\n<p>" .
"</p>") img
)
1632 (org-parse-format '("\n<p>" .
"</p>") caption
))
1637 (defun org-export-html-get-bibliography ()
1638 "Find bibliography, cut it out and return it."
1640 (let (beg end
(cnt 1) bib
)
1642 (goto-char (point-min))
1643 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t
)
1644 (setq beg
(match-beginning 0))
1645 (while (re-search-forward "</?div\\>" nil t
)
1646 (setq cnt
(+ cnt
(if (string= (match-string 0) "<div") +1 -
1)))
1648 (and (looking-at ">") (forward-char 1))
1649 (setq bib
(buffer-substring beg
(point)))
1650 (delete-region beg
(point))
1651 (throw 'exit bib
))))
1654 ;; Following variable is defined for native tables i.e., when
1655 ;; `org-table-is-styled' evals to t.
1657 (defvar org-table-number-regexp
) ; defined in org-table.el
1658 (defun org-format-table-html (lines olines
&optional no-css
)
1659 "Find out which HTML converter to use and return the HTML code.
1660 NO-CSS is passed to the exporter."
1662 (setq lines
(org-split-string lines
"\n")))
1663 (if (string-match "^[ \t]*|" (car lines
))
1664 ;; A normal org table
1665 (org-format-org-table-html lines nil no-css
)
1666 ;; Table made by table.el - test for spanning
1667 (let* ((hlines (delq nil
(mapcar
1669 (if (string-match "^[ \t]*\\+-" x
) x
1672 (first (car hlines
))
1673 (ll (and (string-match "\\S-+" first
)
1674 (match-string 0 first
)))
1675 (re (concat "^[ \t]*" (regexp-quote ll
)))
1676 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
1678 (if (and (not spanning
)
1679 (not org-export-prefer-native-exporter-for-tables
))
1680 ;; We can use my own converter with HTML conversions
1681 (org-format-table-table-html lines
)
1682 ;; Need to use the code generator in table.el, with the original text.
1683 (org-format-table-table-html-using-table-generate-source olines
)))))
1685 (defun org-table-get-colalign-info (lines)
1686 (let ((forced-aligns (org-find-text-property-in-string
1687 'org-forced-aligns
(car lines
))))
1688 (when (and forced-aligns org-table-clean-did-remove-column
)
1690 (mapcar (lambda (x) (cons (1- (car x
)) (cdr x
))) forced-aligns
)))
1694 (defvar org-table-style
)
1695 (defvar org-table-ncols
)
1696 (defvar org-table-rownum
)
1698 (defvar org-table-is-styled
)
1699 (defvar org-table-begin-marker
)
1700 (defvar org-table-num-numeric-items-per-column
)
1701 (defvar org-table-colalign-info
)
1702 (defvar org-table-colalign-vector
)
1703 (defvar org-table-number-fraction
) ; defined in org-table.el
1704 (defun org-do-format-org-table-html (lines &optional splice no-css
)
1705 "Format a table into HTML.
1706 LINES is a list of lines. Optional argument SPLICE means, do not
1707 insert header and surrounding <table> tags, just format the lines.
1708 Optional argument NO-CSS means use XHTML attributes instead of CSS
1709 for formatting. This is required for the DocBook exporter."
1710 (require 'org-table
)
1711 ;; Get rid of hlines at beginning and end
1712 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1713 (setq lines
(nreverse lines
))
1714 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
1715 (setq lines
(nreverse lines
))
1716 (when org-export-table-remove-special-lines
1717 ;; Check if the table has a marking column. If yes remove the
1718 ;; column and the special lines
1719 (setq lines
(org-table-clean-before-export lines
)))
1721 (let* ((caption (org-find-text-property-in-string 'org-caption
(car lines
)))
1722 (caption (and caption
(org-html-do-expand caption
)))
1723 (label (org-find-text-property-in-string 'org-label
(car lines
)))
1724 (org-table-colalign-info (org-table-get-colalign-info lines
))
1725 (attributes (org-find-text-property-in-string 'org-attributes
1727 (head (and org-export-highlight-first-table-line
1729 (lambda (x) (string-match "^[ \t]*|-" x
))
1731 (org-table-rownum -
1) org-table-ncols i
(cnt 0)
1733 org-table-current-rowgroup-is-header
1734 org-table-rowgroup-open
1735 org-table-num-numeric-items-per-column
1736 org-table-colalign-vector n
1737 org-table-rowgroup-info
1738 org-table-begin-marker
1739 (org-table-style 'org-table
)
1740 org-table-is-styled
)
1743 (setq org-table-is-styled nil
)
1744 (while (setq line
(pop lines
))
1745 (unless (string-match "^[ \t]*|-" line
)
1747 (org-parse-format-table-row
1748 (org-split-string line
"[ \t]*|[ \t]*")) "\n"))))
1750 (setq org-table-is-styled t
)
1751 (org-parse-begin 'TABLE caption label attributes
)
1752 (setq org-table-begin-marker
(point))
1753 (org-parse-begin-table-rowgroup head
)
1754 (while (setq line
(pop lines
))
1756 ((string-match "^[ \t]*|-" line
)
1757 (when lines
(org-parse-begin-table-rowgroup)))
1760 (org-parse-format-table-row
1761 (org-split-string line
"[ \t]*|[ \t]*")) "\n"))))
1762 (org-parse-end 'TABLE-ROWGROUP
)
1763 (org-parse-end-table)))))
1765 (defun org-format-org-table-html (lines &optional splice no-css
)
1767 (org-do-format-org-table-html lines splice no-css
)
1768 (buffer-substring-no-properties (point-min) (point-max))))
1770 (defun org-export-splice-attributes (tag attributes
)
1771 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1772 (if (not attributes
)
1774 (let (oldatt newatt
)
1775 (setq oldatt
(org-extract-attributes-from-string tag
)
1777 newatt
(cdr (org-extract-attributes-from-string attributes
)))
1779 (setq oldatt
(plist-put oldatt
(pop newatt
) (pop newatt
))))
1780 (if (string-match ">" tag
)
1782 (replace-match (concat (org-attributes-to-string oldatt
) ">")
1786 (defun org-do-format-table-table-html (lines)
1787 "Format a table generated by table.el into HTML.
1788 This conversion does *not* use `table-generate-source' from table.el.
1789 This has the advantage that Org-mode's HTML conversions can be used.
1790 But it has the disadvantage, that no cell- or row-spanning is allowed."
1791 (let (line field-buffer
1792 (org-table-current-rowgroup-is-header
1793 org-export-highlight-first-table-line
)
1797 (org-table-style 'table-table
)
1798 (org-table-is-styled nil
)
1799 fields org-table-ncols i
(org-table-rownum -
1)
1800 (empty (org-parse-format 'SPACES
1)))
1801 (org-parse-begin 'TABLE caption label attributes
)
1802 (while (setq line
(pop lines
))
1804 ((string-match "^[ \t]*\\+-" line
)
1806 (let ((org-export-table-row-tags '("<tr>" .
"</tr>"))
1807 (org-export-html-table-use-header-tags-for-first-column nil
))
1808 (insert (org-parse-format-table-row field-buffer empty
)))
1809 (setq org-table-current-rowgroup-is-header nil
)
1810 (setq field-buffer nil
)))
1812 ;; Break the line into fields and store the fields
1813 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
1815 (setq field-buffer
(mapcar
1817 (concat x
(org-parse-format 'LINE-BREAK
)
1820 (setq field-buffer fields
)))))
1821 (org-parse-end-table)))
1823 (defun org-format-table-table-html (lines)
1825 (org-do-format-table-table-html lines
)
1826 (buffer-substring-no-properties (point-min) (point-max))))
1828 (defun org-format-table-table-html-using-table-generate-source (lines)
1829 "Format a table into html, using `table-generate-source' from table.el.
1830 This has the advantage that cell- or row-spanning is allowed.
1831 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
1833 (with-current-buffer (get-buffer-create " org-tmp1 ")
1835 (insert (mapconcat 'identity lines
"\n"))
1836 (goto-char (point-min))
1837 (if (not (re-search-forward "|[^+]" nil t
))
1838 (error "Error processing table"))
1839 (table-recognize-table)
1840 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1841 (table-generate-source 'html
" org-tmp2 ")
1842 (set-buffer " org-tmp2 ")
1843 (buffer-substring (point-min) (point-max))))
1845 (defun org-export-splice-style (style extra
)
1846 "Splice EXTRA into STYLE, just before \"</style>\"."
1847 (if (and (stringp extra
)
1848 (string-match "\\S-" extra
)
1849 (string-match "</style>" style
))
1850 (concat (substring style
0 (match-beginning 0))
1852 (substring style
(match-beginning 0)))
1855 (defun org-html-handle-time-stamps (s)
1856 "Format time stamps in string S, or remove them."
1859 (while (string-match org-maybe-keyword-time-regexp s
)
1860 (or b
(setq b
(substring s
0 (match-beginning 0))))
1862 r
(substring s
0 (match-beginning 0))
1869 (match-string 1 s
) "timestamp-kwd"))
1872 (substring (org-translate-time (match-string 3 s
)) 1 -
1)
1874 "timestamp-wrapper"))
1875 s
(substring s
(match-end 0))))
1876 ;; Line break if line started and ended with time stamp stuff
1879 (setq r
(concat r s
))
1880 (unless (string-match "\\S-" (concat b s
))
1881 (setq r
(concat r
(org-parse-format 'LINE-BREAK
))))
1884 (defvar htmlize-buffer-places
) ; from htmlize.el
1885 (defun org-export-htmlize-region-for-paste (beg end
)
1886 "Convert the region to HTML, using htmlize.el.
1887 This is much like `htmlize-region-for-paste', only that it uses
1888 the settings define in the org-... variables."
1889 (let* ((htmlize-output-type org-export-htmlize-output-type
)
1890 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
1891 (htmlbuf (htmlize-region beg end
)))
1893 (with-current-buffer htmlbuf
1894 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
1895 (plist-get htmlize-buffer-places
'content-end
)))
1896 (kill-buffer htmlbuf
))))
1899 (defun org-export-htmlize-generate-css ()
1900 "Create the CSS for all font definitions in the current Emacs session.
1901 Use this to create face definitions in your CSS style file that can then
1902 be used by code snippets transformed by htmlize.
1903 This command just produces a buffer that contains class definitions for all
1904 faces used in the current Emacs session. You can copy and paste the ones you
1905 need into your CSS file.
1907 If you then set `org-export-htmlize-output-type' to `css', calls to
1908 the function `org-export-htmlize-region-for-paste' will produce code
1909 that uses these same face definitions."
1912 (and (get-buffer "*html*") (kill-buffer "*html*"))
1914 (let ((fl (face-list))
1915 (htmlize-css-name-prefix "org-")
1916 (htmlize-output-type 'css
)
1918 (while (setq f
(pop fl
)
1919 i
(and f
(face-attribute f
:inherit
)))
1920 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
1921 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
1922 (htmlize-region (point-min) (point-max))))
1923 (switch-to-buffer "*html*")
1924 (goto-char (point-min))
1925 (if (re-search-forward "<style" nil t
)
1926 (delete-region (point-min) (match-beginning 0)))
1927 (if (re-search-forward "</style>" nil t
)
1928 (delete-region (1+ (match-end 0)) (point-max)))
1929 (beginning-of-line 1)
1930 (if (looking-at " +") (replace-match ""))
1931 (goto-char (point-min)))
1933 (defun org-html-protect (s)
1934 "Convert characters to HTML equivalent.
1935 Possible conversions are set in `org-export-html-protect-char-alist'."
1936 (let ((cl org-export-html-protect-char-alist
) c
)
1937 (while (setq c
(pop cl
))
1939 (while (string-match (car c
) s start
)
1940 (setq s
(replace-match (cdr c
) t t s
)
1941 start
(1+ (match-beginning 0))))))
1944 (defun org-html-expand (string)
1945 "Prepare STRING for HTML export. Apply all active conversions.
1946 If there are links in the string, don't modify these."
1947 (let* ((re (concat org-bracket-link-regexp
"\\|"
1948 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1950 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string
)
1952 (while (setq m
(string-match re string
))
1953 (setq s
(substring string
0 m
)
1954 l
(match-string 0 string
)
1955 string
(substring string
(match-end 0)))
1956 (push (org-html-do-expand s
) res
)
1958 (push (org-html-do-expand string
) res
)
1959 (apply 'concat
(nreverse res
)))))
1961 (defun org-html-do-expand (s)
1962 "Apply all active conversions to translate special ASCII to HTML."
1963 (setq s
(org-html-protect s
))
1964 (if org-export-html-expand
1965 (while (string-match "@<\\([^&]*\\)>" s
)
1966 (setq s
(replace-match "<\\1>" t nil s
))))
1967 (if org-export-with-emphasize
1968 (setq s
(org-export-html-convert-emphasize s
)))
1969 (if org-export-with-special-strings
1970 (setq s
(org-export-html-convert-special-strings s
)))
1971 (if org-export-with-sub-superscripts
1972 (setq s
(org-export-html-convert-sub-super s
)))
1973 (if org-export-with-TeX-macros
1974 (let ((start 0) wd rep
)
1975 (while (setq start
(string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
1977 (if (get-text-property (match-beginning 0) 'org-protected s
)
1978 (setq start
(match-end 0))
1979 (setq wd
(match-string 1 s
))
1980 (if (setq rep
(org-entity-get-representation wd
'html
))
1981 (setq s
(replace-match rep t t s
))
1982 (setq start
(+ start
(length wd
))))))))
1985 (defun org-export-html-convert-special-strings (string)
1986 "Convert special characters in STRING to HTML."
1987 (let ((all org-export-html-special-string-regexps
)
1989 (while (setq a
(pop all
))
1990 (setq re
(car a
) rpl
(cdr a
) start
0)
1991 (while (string-match re string start
)
1992 (if (get-text-property (match-beginning 0) 'org-protected string
)
1993 (setq start
(match-end 0))
1994 (setq string
(replace-match rpl t nil string
)))))
1997 (defun org-export-html-convert-sub-super (string)
1998 "Convert sub- and superscripts in STRING to HTML."
1999 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
2000 (while (string-match org-match-substring-regexp string s
)
2002 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
2003 ((get-text-property (match-beginning 2) 'org-protected string
)
2004 (setq s
(match-end 2)))
2006 (setq s
(match-end 1)
2007 key
(if (string= (match-string 2 string
) "_")
2008 'subscript
'superscript
)
2009 c
(or (match-string 8 string
)
2010 (match-string 6 string
)
2011 (match-string 5 string
))
2012 string
(replace-match
2013 (concat (match-string 1 string
)
2014 (org-parse-format 'FONTIFY c key
))
2016 (while (string-match "\\\\\\([_^]\\)" string
)
2017 (setq string
(replace-match (match-string 1 string
) t t string
)))
2020 (defconst org-html-emphasis-alist
2028 (defun org-export-html-convert-emphasize (string)
2031 (while (string-match org-emph-re string s
)
2033 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
2034 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
2035 (setq s
(match-beginning 0)
2038 (match-string 1 string
)
2040 'FONTIFY
(match-string 4 string
)
2041 (nth 1 (assoc (match-string 3 string
)
2042 org-html-emphasis-alist
)))
2043 (match-string 5 string
))
2044 string
(replace-match rpl t t string
)
2045 s
(+ s
(- (length rpl
) 2)))
2049 (defvar body-only
) ; dynamically scoped into this.
2050 (defun org-export-html-get-tag-class-name (tag)
2051 "Turn tag into a valid class name.
2052 Replaces invalid characters with \"_\" and then prepends a prefix."
2054 (while (string-match "[^a-zA-Z0-9_]" tag
)
2055 (setq tag
(replace-match "_" t t tag
))))
2056 (concat org-export-html-tag-class-prefix tag
))
2058 (defun org-export-html-get-todo-kwd-class-name (kwd)
2059 "Turn todo keyword into a valid class name.
2060 Replaces invalid characters with \"_\" and then prepends a prefix."
2062 (while (string-match "[^a-zA-Z0-9_]" kwd
)
2063 (setq kwd
(replace-match "_" t t kwd
))))
2064 (concat org-export-html-todo-kwd-class-prefix kwd
))
2066 (defun org-html-export-list-line (line pos struct prevs
)
2067 "Insert list syntax in export buffer. Return LINE, maybe modified.
2069 POS is the item position or line position the line had before
2070 modifications to buffer. STRUCT is the list structure. PREVS is
2071 the alist of previous items."
2074 ;; Translate type of list containing POS to "d", "o" or
2076 (lambda (pos struct prevs
)
2077 (let ((type (org-list-get-list-type pos struct prevs
)))
2079 ((eq 'ordered type
) "o")
2080 ((eq 'descriptive type
) "d")
2084 ;; Return list of all items and sublists ending at POS, in
2090 (let ((end (nth 6 e
))
2093 ((= end pos
) (push item out
))
2094 ((>= item pos
) (throw 'exit nil
)))))
2097 ;; First close any previous item, or list, ending at POS.
2099 (let* ((lastp (= (org-list-get-last-item e struct prevs
) e
))
2100 (first-item (org-list-get-list-begin e struct prevs
))
2101 (type (funcall get-type first-item struct prevs
)))
2102 (org-parse-end-paragraph)
2103 ;; Ending for every item
2105 ;; We're ending last item of the list: end list.
2107 (org-parse-end 'LIST type
)
2108 (org-parse-begin-paragraph))))
2109 (funcall get-closings pos
))
2111 ;; At an item: insert appropriate tags in export buffer.
2114 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2115 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2116 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2117 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2119 (let* ((checkbox (match-string 3 line
))
2120 (desc-tag (or (match-string 4 line
) "???"))
2121 (body (or (match-string 5 line
) ""))
2122 (list-beg (org-list-get-list-begin pos struct prevs
))
2123 (firstp (= list-beg pos
))
2124 ;; Always refer to first item to determine list type, in
2125 ;; case list is ill-formed.
2126 (type (funcall get-type list-beg struct prevs
))
2127 (counter (let ((count-tmp (org-list-get-counter pos struct
)))
2129 ((not count-tmp
) nil
)
2130 ((string-match "[A-Za-z]" count-tmp
)
2131 (- (string-to-char (upcase count-tmp
)) 64))
2132 ((string-match "[0-9]+" count-tmp
)
2135 (org-parse-end-paragraph)
2136 (org-parse-begin 'LIST type
))
2138 (let ((arg (cond ((equal type
"d") desc-tag
)
2139 ((equal type
"o") counter
))))
2140 (org-parse-begin 'LIST-ITEM type arg
))
2142 ;; If line had a checkbox, some additional modification is required.
2150 ((string-match "X" checkbox
) "X")
2151 ((string-match " " checkbox
)
2152 (org-parse-format 'SPACES
1))
2158 ;; Return modified line
2160 ;; At a list ender: go to next line (side-effects only).
2161 ((equal "ORG-LIST-END-MARKER" line
) (throw 'nextline nil
))
2162 ;; Not at an item: return line unchanged (side-effects only).
2167 (defun org-html-bind-local-variables (opt-plist)
2169 (set (make-local-variable (nth 2 x
))
2170 (plist-get opt-plist
(car x
))))
2171 org-export-plist-vars
))
2174 ;; This replaces org-emphasis-alist
2175 (defvar org-table-rowgroup-open
)
2176 (defvar org-table-current-rowgroup-is-header
)
2177 (defvar org-html-footnote-number
)
2178 (defvar org-html-footnote-definitions
)
2179 (defvar org-html-footnote-buffer
)
2180 (defvar org-html-output-buffer
)
2182 (defun org-html-end-export ()
2183 ;; insert the table of contents
2184 (when (and org-export-with-toc
(not body-only
) org-parse-table-of-contents
)
2185 (org-html-insert-toc org-parse-table-of-contents
))
2187 ;; remove empty paragraphs
2188 (goto-char (point-min))
2189 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2192 ;; Convert whitespace place holders
2193 (goto-char (point-min))
2195 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2196 (setq n
(get-text-property beg
'org-whitespace
)
2197 end
(next-single-property-change beg
'org-whitespace
))
2199 (delete-region beg end
)
2200 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2201 (make-string n ?x
)))))
2203 ;; Remove empty lines at the beginning of the file.
2204 (goto-char (point-min))
2205 (when (looking-at "\\s-+\n") (replace-match ""))
2207 ;; Remove display properties
2208 (remove-text-properties (point-min) (point-max) '(display t
))
2210 ;; kill temporary buffers
2211 (when org-html-footnote-buffer
2212 (kill-buffer org-html-footnote-buffer
))
2215 (run-hooks 'org-export-html-final-hook
))
2220 ;;;_ , user-specific
2221 ;;;_ . custom-settings
2222 (defcustom org-parse-debug nil
2231 ;;;_ . control callbacks
2233 (defun org-parse-begin (entity &rest args
)
2234 (when (and (member org-parse-debug
'(t control
))
2235 (not (eq entity
'DOCUMENT-CONTENT
)))
2236 (insert (org-parse-format 'COMMENT
"%s BEGIN %S" entity args
)))
2238 (let ((f (cadr (assoc entity org-parse-entity-control-callbacks-alist
))))
2239 (unless f
(error "Unknown entity: %s" entity
))
2242 (defun org-parse-end (entity &rest args
)
2243 (when (and (member org-parse-debug
'(t control
))
2244 (not (eq entity
'DOCUMENT-CONTENT
)))
2245 (insert (org-parse-format 'COMMENT
"%s END %S" entity args
)))
2247 (let ((f (caddr (assoc entity org-parse-entity-control-callbacks-alist
))))
2248 (unless f
(error "Unknown entity: %s" entity
))
2253 (defun org-parse-begin-paragraph (&optional style
)
2254 "Insert <p>, but first close previous paragraph if any."
2255 (org-parse-end-paragraph)
2256 (org-parse-begin 'PARAGRAPH style
)
2257 (setq org-par-open t
))
2259 (defun org-parse-end-paragraph ()
2260 "Close paragraph if there is one open."
2262 (org-parse-end 'PARAGRAPH
)
2263 (setq org-par-open nil
)))
2266 (defun org-close-li (&optional type
)
2267 "Close <li> if necessary."
2268 (org-parse-end-paragraph)
2269 (org-parse-end 'LIST-ITEM
(or type
"u")))
2273 (defvar org-parse-dyn-current-environment nil
)
2274 (defun org-parse-begin-environment (style)
2275 (assert (not org-parse-dyn-current-environment
) t
)
2276 (setq org-parse-dyn-current-environment style
)
2277 (org-parse-begin 'ENVIRONMENT style
))
2279 (defun org-parse-end-environment (style)
2280 (org-parse-end 'ENVIRONMENT style
)
2282 (assert (eq org-parse-dyn-current-environment style
) t
)
2283 (setq org-parse-dyn-current-environment nil
))
2285 (defun org-parse-current-environment-p (style)
2286 (eq org-parse-dyn-current-environment style
))
2289 ;;;_ , footnote definition
2290 (defun org-parse-begin-footnote-definition (n)
2291 (unless org-html-footnote-buffer
2292 (setq org-html-footnote-buffer
2293 (get-buffer-create "*Org HTML Export Footnotes*")))
2294 (set-buffer org-html-footnote-buffer
)
2296 (org-parse-begin 'FOOTNOTE-DEFINITION n
))
2298 (defun org-parse-end-footnote-definition (n)
2299 (org-parse-end 'FOOTNOTE-DEFINITION n
)
2300 (push (cons n
(buffer-string)) org-html-footnote-definitions
)
2301 (set-buffer org-html-output-buffer
))
2306 ;;;_ . format callbacks
2308 (defun org-parse-format (entity &rest args
)
2309 (when (and (member org-parse-debug
'(t format
))
2310 (not (equal entity
'COMMENT
)))
2311 (insert (org-parse-format 'COMMENT
"%s: %S" entity args
)))
2314 (let ((text (pop args
)))
2315 (apply 'org-parse-format
'TAGS entity text args
)))
2317 (let ((f (cdr (assoc entity org-parse-entity-format-callbacks-alist
))))
2318 (unless f
(error "Unknown entity: %s" entity
))
2322 ;;;_ , toc (rename these routines)
2323 (defun org-html-format-toc-entry (snumber todo headline tags href
)
2324 (setq headline
(concat
2325 (and org-export-with-section-numbers
2326 (concat snumber
" "))
2330 (org-parse-format 'SPACES
3)
2331 (org-parse-format 'FONTIFY tags
"tag")))))
2333 (setq headline
(org-parse-format 'FONTIFY headline
"todo")))
2334 (org-parse-format 'LINK headline
(concat "#" href
)))
2336 (defun org-html-format-toc-item (toc-entry level org-last-level
)
2337 (when (> level org-last-level
)
2338 (let ((cnt (- level org-last-level
)))
2339 (while (>= (setq cnt
(1- cnt
)) 0)
2340 (org-parse-begin 'LIST
'unordered
)
2341 (org-parse-begin 'LIST-ITEM
'unordered
))))
2342 (when (< level org-last-level
)
2343 (let ((cnt (- org-last-level level
)))
2344 (while (>= (setq cnt
(1- cnt
)) 0)
2346 (org-parse-end 'LIST
'unordered
))))
2349 (org-parse-begin 'LIST-ITEM
'unordered
)
2352 (defun org-html-begin-toc (lang-specific-heading)
2353 (org-parse-begin 'SECTION
"table-of-contents")
2355 (org-parse-format 'HEADING lang-specific-heading
2356 (or (org-parse-get 'TOPLEVEL-HLEVEL
) 1)))
2357 (org-parse-begin 'SECTION
"text-table-of-contents")
2358 (org-parse-begin 'LIST
'unordered
)
2359 (org-parse-begin 'LIST-ITEM
'unordered
))
2361 (defun org-html-end-toc ()
2362 (while (> org-last-level
(1- org-min-level
))
2363 (setq org-last-level
(1- org-last-level
))
2365 (org-parse-end 'LIST
'unordered
))
2366 (org-parse-end 'SECTION
)
2367 (org-parse-end 'SECTION
)
2369 ;; cleanup empty list items in toc
2370 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t
)
2371 (replace-match "")))
2373 (defun org-parse-prepare-toc (lines level-offset opt-plist umax-toc
)
2374 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2375 (org-min-level (org-get-min-level lines level-offset
))
2376 (org-last-level org-min-level
)
2379 (org-html-bind-local-variables opt-plist
)
2381 (org-parse-begin 'TOC
(nth 3 (plist-get opt-plist
:lang-words
)))
2386 (when (and (string-match org-todo-line-regexp line
)
2387 (not (get-text-property 0 'org-protected line
))
2388 (<= (setq level
(org-tr-level
2389 (- (match-end 1) (match-beginning 1)
2392 (let ((txt (save-match-data
2394 (org-export-cleanup-toc-line
2395 (match-string 3 line
)))))
2397 org-export-mark-todo-in-toc
2398 (or (and (match-beginning 2)
2399 (not (member (match-string 2 line
)
2400 org-done-keywords
)))
2401 (and (= level umax-toc
)
2402 (org-search-todo-below
2403 line lines level
)))))
2405 ;; Check for targets
2406 (while (string-match org-any-target-regexp line
)
2409 (let ((org-html-protect t
))
2410 (org-parse-format 'FONTIFY
2411 (match-string 1 line
) "target"))
2414 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2415 (setq txt
(replace-match "" t nil txt
)
2416 tags
(match-string 1 txt
)))
2417 (when (string-match quote-re0 txt
)
2418 (setq txt
(replace-match "" t t txt
)))
2419 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2420 (setq txt
(replace-match "" t t txt
)))
2423 (let* ((snumber (org-section-number level
))
2424 (href (replace-regexp-in-string
2425 "\\." "_" (format "sec-%s" snumber
)))
2429 href org-export-preferred-target-alist
))
2431 (href (org-solidify-link-text href
)))
2432 (org-parse-format 'TOC-ENTRY snumber todo txt tags href
))
2433 level org-last-level
)
2434 (setq org-last-level level
)))
2437 (org-parse-end 'TOC
)
2438 (setq org-parse-table-of-contents
(buffer-string))))
2443 (defun org-parse-format-table-row (fields &optional text-for-empty-fields
)
2444 (unless org-table-ncols
2445 ;; first row of the table
2446 (setq org-table-ncols
(length fields
))
2447 (when org-table-is-styled
2448 (setq org-table-num-numeric-items-per-column
(make-vector org-table-ncols
0))
2449 (setq org-table-colalign-vector
(make-vector org-table-ncols nil
))
2451 (while (< (incf c
) org-table-ncols
)
2452 (let ((cookie (cdr (assoc (1+ c
) org-table-colalign-info
))))
2453 (setf (aref org-table-colalign-vector c
)
2455 ((string= cookie
"l") "left")
2456 ((string= cookie
"r") "right")
2457 ((string= cookie
"c") "center")
2459 (incf org-table-rownum
)
2466 (when (string= x
"")
2467 (setq x text-for-empty-fields
))
2469 (and org-table-is-styled
2470 (< i org-table-ncols
)
2471 (string-match org-table-number-regexp x
)
2472 (incf (aref org-table-num-numeric-items-per-column i
)))
2473 (org-parse-format 'TABLE-CELL x org-table-rownum i
))
2477 (defun org-parse-get (what &optional opt-plist
)
2478 (funcall org-parse-get-callback what opt-plist
))
2487 ;;;_. hacks (to be documented)
2489 ;; Refer `org-html-emphasis-alist'
2492 ;;;_ , custom settings
2493 ;;;_ . potential custom settings
2494 ;;;_ , interactive commands
2496 ;;;_ , initialization
2497 (defvar org-html-entity-control-callbacks-alist
2499 .
(org-html-begin-export org-html-end-export
))
2501 .
(org-html-begin-document-content org-html-end-document-content
))
2503 .
(org-html-begin-document-body org-html-end-document-body
))
2505 .
(org-html-begin-toc org-html-end-toc
))
2507 .
(org-html-begin-environment org-html-end-environment
))
2509 .
(org-html-begin-level org-html-end-level
))
2510 (FOOTNOTE-DEFINITION
2511 .
(org-html-begin-footnote-definition org-html-end-footnote-definition
))
2513 .
(org-html-begin-table org-html-end-table
))
2515 .
(org-html-begin-table-rowgroup org-html-end-table-rowgroup
))
2517 .
(org-html-begin-list org-html-end-list
))
2519 .
(org-html-begin-list-item org-html-end-list-item
))
2521 .
(org-html-begin-section org-html-end-section
))
2523 .
(org-html-begin-paragraph org-html-end-paragraph
)))
2526 (defvar org-html-entity-format-callbacks-alist
2527 `((EXTRA-TARGETS . org-html-format-extra-targets
)
2528 (ORG-TAGS . org-html-format-org-tags
)
2529 (SECTION-NUMBER . org-html-format-section-number
)
2530 (HEADLINE . org-html-format-headline
)
2531 (TOC-ENTRY . org-html-format-toc-entry
)
2532 (TOC-ITEM . org-html-format-toc-item
)
2533 (TAGS . org-html-format-tags
)
2534 (SPACES . org-html-format-spaces
)
2535 (TABS . org-html-format-tabs
)
2536 (LINE-BREAK . org-html-format-line-break
)
2537 (FONTIFY . org-html-format-fontify
)
2538 (TODO . org-html-format-todo
)
2539 (ORG-LINK . org-html-format-org-link
)
2540 (LINK . org-html-format-link
)
2541 (INLINE-IMAGE . org-html-format-inline-image
)
2542 (HEADING . org-html-format-heading
)
2543 (ANCHOR . org-html-format-anchor
)
2544 (TABLE-ROW . org-html-format-table-row
)
2545 (TABLE-CELL . org-html-format-table-cell
)
2546 (FOOTNOTES-SECTION . org-html-format-footnotes-section
)
2547 (FOOTNOTE-REFERENCE . org-html-format-footnote-reference
)
2548 (HORIZONTAL-LINE . org-html-format-horizontal-line
)
2549 (PLAIN . org-html-format-plain
)
2550 (COMMENT . org-html-format-comment
))
2556 ;;;_ . control callbacks
2558 (defvar org-html-insert-tag-with-newlines
'both
)
2560 (defun org-html-insert-tag (tag &rest args
)
2561 (when (member org-html-insert-tag-with-newlines
'(lead both
))
2563 (insert (apply 'format tag args
))
2564 (when (member org-html-insert-tag-with-newlines
'(trail both
))
2567 ;;;_ , document body
2568 (defun org-html-begin-document-body (opt-plist)
2569 (let ((link-up (and (plist-get opt-plist
:link-up
)
2570 (string-match "\\S-" (plist-get opt-plist
:link-up
))
2571 (plist-get opt-plist
:link-up
)))
2572 (link-home (and (plist-get opt-plist
:link-home
)
2573 (string-match "\\S-" (plist-get opt-plist
:link-home
))
2574 (plist-get opt-plist
:link-home
))))
2576 (org-parse-begin 'SECTION
"content")
2578 (or (and (or link-up link-home
)
2579 (format org-export-html-home
/up-format
2580 (or link-up link-home
)
2581 (or link-home link-up
))) "")
2583 (org-html-insert-preamble opt-plist
))
2585 (defun org-html-end-document-body (opt-plist)
2586 (org-html-insert-postamble opt-plist
)
2588 (org-parse-end 'SECTION
)
2589 (insert "\n</body>")))
2592 ;;;_ , document content
2593 (defun org-html-begin-document-content (opt-plist)
2594 (let* ((language (plist-get opt-plist
:language
))
2595 (charset (or (and coding-system-for-write
2596 (fboundp 'coding-system-get
)
2597 (coding-system-get coding-system-for-write
2600 (style (concat (if (plist-get opt-plist
:style-include-default
)
2601 org-export-html-style-default
)
2602 (plist-get opt-plist
:style
)
2603 (plist-get opt-plist
:style-extra
)
2605 (if (plist-get opt-plist
:style-include-scripts
)
2606 org-export-html-scripts
)))
2608 (if (or (eq (plist-get opt-plist
:LaTeX-fragments
) 'mathjax
)
2609 (and org-export-have-math
2610 (eq (plist-get opt-plist
:LaTeX-fragments
) t
)))
2612 (org-export-html-mathjax-config
2613 org-export-html-mathjax-template
2614 org-export-html-mathjax-options
2615 (or (plist-get opt-plist
:mathjax
) "")) "")))
2618 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2619 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2620 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2621 lang=\"%s\" xml:lang=\"%s\">
2624 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2625 <meta name=\"generator\" content=\"Org-mode\"/>
2626 <meta name=\"generated\" content=\"%s\"/>
2627 <meta name=\"author\" content=\"%s\"/>
2628 <meta name=\"description\" content=\"%s\"/>
2629 <meta name=\"keywords\" content=\"%s\"/>
2635 (or (and (stringp org-export-html-xml-declaration
)
2636 org-export-html-xml-declaration
)
2637 (cdr (assoc (plist-get opt-plist
:html-extension
)
2638 org-export-html-xml-declaration
))
2639 (cdr (assoc "html" org-export-html-xml-declaration
))
2644 (plist-get opt-plist
:title
)
2646 (plist-get opt-plist
:effective-date
)
2647 (plist-get opt-plist
:author
)
2648 (plist-get opt-plist
:description
)
2649 (plist-get opt-plist
:keywords
)
2653 (defun org-html-end-document-content ()
2654 (insert "\n</html>\n"))
2658 (defun org-html-begin-level (level title umax head-count
)
2659 "Insert a new level in HTML export.
2660 When TITLE is nil, just close all open levels."
2661 (org-parse-end 'LEVEL level umax
)
2662 (unless title
(error "Why is heading nil"))
2663 (let* ((target (org-get-text-property-any 0 'target title
))
2664 (extra-targets (and target
2665 (assoc target org-export-target-aliases
)))
2666 (extra-class (org-get-text-property-any 0 'html-container-class title
))
2667 (preferred (and target
2668 (cdr (assoc target org-export-preferred-target-alist
))))
2669 snumber snu href suffix tags level1
)
2670 (setq extra-targets
(remove (or preferred target
) extra-targets
))
2671 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title
)
2672 (setq tags
(and org-export-with-tags
(match-string 1 title
)))
2673 (setq title
(replace-match "" t t title
)))
2676 (if (aref org-levels-open
(1- level
))
2678 (aset org-levels-open
(1- level
) t
)
2679 (org-parse-end-paragraph)
2680 (org-parse-begin 'LIST
'unordered
))
2682 'LIST-ITEM
'unordered
2683 (and target
(org-solidify-link-text (or preferred target
))) ;id
2684 (org-parse-format 'HEADLINE title extra-targets tags
)))
2685 (aset org-levels-open
(1- level
) t
)
2686 (setq snumber
(org-section-number level
)
2687 snu
(replace-regexp-in-string "\\." "_" snumber
))
2688 (setq level1
(+ level
(or (org-parse-get 'TOPLEVEL-HLEVEL
) 1) -
1))
2689 (unless (= head-count
1)
2690 (org-parse-end 'SECTION
))
2691 (setq href
(cdr (assoc (concat "sec-" snu
)
2692 org-export-preferred-target-alist
)))
2693 (setq suffix
(org-solidify-link-text (or href snu
)))
2694 (setq href
(org-solidify-link-text (or href
(concat "sec-" snu
))))
2695 (let ((id (format "outline-container-%s" suffix
))
2696 (class (format "outline-%d" level1
)))
2697 (org-parse-begin 'SECTION id class extra-class
))
2699 (org-parse-format 'HEADING
2701 'HEADLINE title extra-targets tags snumber level1
)
2703 (let ((id (format "text-%s" suffix
))
2704 (class (format "outline-text-%d" level1
)))
2705 (org-parse-begin 'SECTION id class
))
2707 (org-parse-begin-paragraph))))
2709 (defun org-html-end-level (level umax
)
2710 (org-parse-end-paragraph)
2711 (let* ((l org-level-max
))
2713 (if (aref org-levels-open
(1- l
))
2715 ;; Terminate one level in HTML export
2717 (org-parse-end 'SECTION
)
2719 (org-parse-end 'LIST
'unordered
))
2720 (aset org-levels-open
(1- l
) nil
)))
2725 (defun org-html-begin-section (&optional id class extra-class
)
2727 (setq class
(concat class
" " extra-class
)))
2728 (let ((extra (concat (when id
(format " id=\"%s\"" id
))
2729 (when class
(format " class=\"%s\"" class
)))))
2730 (org-html-insert-tag "<div%s>" extra
)))
2732 (defun org-html-end-section ()
2733 (org-html-insert-tag "</div>"))
2738 (defun org-html-begin-paragraph (&optional style
)
2739 (let* ((class (cdr (assoc style
'((footnote .
"footnote")
2741 (extra (if class
(format " class=\"%s\"" class
) "")))
2742 (org-html-insert-tag "<p%s>" extra
)))
2744 (defun org-html-end-paragraph ()
2749 (defun org-html-format-environment (style beg-end
)
2750 (assert (memq style
'(blockquote center verse fixedwidth quote native
)) t
)
2755 (org-parse-end-paragraph)
2756 (insert "<blockquote>\n")
2757 (org-parse-begin-paragraph))
2759 (org-parse-end-paragraph)
2760 (insert "\n</blockquote>\n")
2761 (org-parse-begin-paragraph))))
2765 (org-parse-end-paragraph)
2766 (insert "\n<p class=\"verse\">\n")
2767 (setq org-par-open t
))
2770 (setq org-par-open nil
)
2771 (org-parse-begin-paragraph))))
2775 (org-parse-end-paragraph)
2776 (insert "\n<div style=\"text-align: center\">")
2777 (org-parse-begin-paragraph))
2779 (org-parse-end-paragraph)
2781 (org-parse-begin-paragraph))))
2785 (org-parse-end-paragraph)
2786 (insert "<pre class=\"example\">\n"))
2789 (org-parse-begin-paragraph))))
2793 (org-parse-end-paragraph)
2797 (org-parse-begin-paragraph))))
2800 (BEGIN (org-parse-end-paragraph))
2801 (END (org-parse-begin-paragraph))))
2802 (t (error "Unknown environment %s" style
))))
2805 (defun org-html-begin-environment (style)
2806 (org-html-format-environment style
'BEGIN
))
2808 (defun org-html-end-environment (style)
2809 (org-html-format-environment style
'END
))
2813 (defun org-html-html-list-type-to-canonical-list-type (ltype)
2814 (cdr (assoc ltype
'(("o" . ordered
)
2816 ("d" . description
)))))
2818 (defun org-html-begin-list (ltype &optional arg1
)
2819 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
2823 (ordered (let ((extra (if arg1
(format " start=\"%d\"" arg1
) "")))
2824 (org-html-insert-tag "<ol%s>" extra
)))
2825 (unordered (org-html-insert-tag "<ul>"))
2826 (description (org-html-insert-tag "<dl>"))
2827 (t (error "Unknown list type: %s" ltype
))))
2829 (defun org-html-end-list (ltype)
2830 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
2833 (org-html-insert-tag
2837 (description "</dl>")
2838 (t (error "Unknown list type: %s" ltype
)))))
2840 (defun org-html-begin-list-item (ltype &optional arg headline
)
2841 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
2845 (assert (not headline
) t
)
2846 (let* ((counter arg
)
2847 (extra (if counter
(format " value=\"%s\"" counter
) "")))
2848 (org-html-insert-tag "<li%s>" extra
)))
2851 (extra (if id
(format " id=\"%s\"" id
) "")))
2852 (org-html-insert-tag "<li%s>" extra
)
2854 (insert headline
(org-parse-format 'LINE-BREAK
) "\n"))))
2856 (assert (not headline
) t
)
2857 (let* ((desc-tag (or arg
"(no term)")))
2859 (org-html-format-tags '("<dt>" .
"</dt>") desc-tag
))
2860 (org-html-insert-tag "<dd>")))
2861 (t (error "Unknown list type"))))
2863 (defun org-html-end-list-item (ltype)
2864 (setq ltype
(or (org-html-html-list-type-to-canonical-list-type ltype
)
2867 (ordered (org-html-insert-tag "</li>"))
2868 (unordered (org-html-insert-tag "</li>"))
2869 (description (org-html-insert-tag "</dd>"))
2870 (t (error "Unknown list type"))))
2875 (defvar org-table-rowgroup-info
)
2876 (defun org-parse-begin-table-rowgroup (&optional is-header-row
)
2877 (push (cons (1+ org-table-rownum
) :start
) org-table-rowgroup-info
)
2878 (org-parse-begin 'TABLE-ROWGROUP is-header-row
))
2880 (defun org-html-begin-table-rowgroup (&optional is-header-row
)
2881 (when org-table-rowgroup-open
2882 (org-parse-end 'TABLE-ROWGROUP
))
2883 (org-html-insert-tag (if is-header-row
"<thead>" "<tbody>"))
2884 (setq org-table-rowgroup-open t
)
2885 (setq org-table-current-rowgroup-is-header is-header-row
))
2887 (defun org-html-end-table-rowgroup ()
2888 (when org-table-rowgroup-open
2889 (setq org-table-rowgroup-open nil
)
2890 (org-html-insert-tag
2891 (if org-table-current-rowgroup-is-header
"</thead>" "</tbody>"))))
2893 (defun org-html-begin-table (caption label attributes
)
2894 (let ((html-table-tag
2895 (org-export-splice-attributes html-table-tag attributes
)))
2897 (setq html-table-tag
2898 (org-export-splice-attributes
2900 (format "id=\"%s\"" (org-solidify-link-text label
)))))
2901 (org-html-insert-tag html-table-tag
))
2903 ;; Since the output of HTML table formatter can also be used in
2904 ;; DocBook document, we want to always include the caption to make
2905 ;; DocBook XML file valid.
2906 (insert (format "<caption>%s</caption>" (or caption
"")) "\n"))
2908 (defun org-parse-end-table ()
2909 (when org-table-is-styled
2911 (unless (car org-table-colgroup-info
)
2912 (setq org-table-colgroup-info
2913 (cons :start
(cdr org-table-colgroup-info
))))
2920 (setf (aref org-table-colalign-vector c
)
2921 (or (aref org-table-colalign-vector c
)
2922 (if (> (/ (float x
) (1+ org-table-rownum
))
2923 org-table-number-fraction
)
2925 org-table-num-numeric-items-per-column
)))
2926 (org-parse-end 'TABLE
))
2928 (defun org-html-end-table ()
2929 (when org-table-is-styled
2930 (goto-char org-table-begin-marker
)
2931 (setq org-table-begin-marker nil
)
2933 (let ((c -
1) gr colgropen
)
2938 (setq gr
(pop org-table-colgroup-info
))
2941 (if (memq gr
'(:start
:startend
))
2944 "</colgroup>\n<colgroup>"
2949 (let* ((align (aref org-table-colalign-vector c
))
2950 (alignspec (if no-css
" align=\"%s\"" " class=\"%s\""))
2951 (extra (format alignspec align
)))
2952 (format "<col%s />" extra
))
2954 (if (memq gr
'(:end
:startend
))
2955 (progn (setq colgropen nil
) "</colgroup>")
2957 org-table-num-numeric-items-per-column
""))
2959 (if colgropen
(insert "</colgroup>")))
2961 ;; fill style attributes for table cells
2962 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t
)
2963 (let ((c (string-to-number (match-string 1))))
2965 (if org-export-html-table-align-individual-fields
2966 (format (if no-css
" align=\"%s\"" " class=\"%s\"")
2967 (or (aref org-table-colalign-vector c
) "left")) "")
2969 (goto-char (point-max)))
2970 (org-html-insert-tag "</table>\n"))
2972 (defun org-html-format-table-row (row)
2973 (org-html-format-tags
2974 (cons (eval (car org-export-table-row-tags
))
2975 (eval (cdr org-export-table-row-tags
))) row
))
2977 (defun org-html-format-table-cell (text r c
)
2978 (let ((cell-style-cookie (or (and org-table-is-styled
2979 (format "@@class%03d@@" c
)) "")))
2981 (org-table-current-rowgroup-is-header
2982 (org-html-format-tags
2983 org-export-table-header-tags text
"col" cell-style-cookie
))
2984 ((and (= c
0) org-export-html-table-use-header-tags-for-first-column
)
2985 (org-html-format-tags
2986 org-export-table-header-tags text
"row" cell-style-cookie
))
2988 (org-html-format-tags
2989 org-export-table-data-tags text cell-style-cookie
)))))
2992 ;;;_ , footnote definition
2993 (defun org-html-begin-footnote-definition (n)
2994 (org-parse-begin-paragraph 'footnote
)
2997 (format org-export-html-footnote-format
2998 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
3001 (defun org-html-end-footnote-definition (n)
3002 (org-parse-end-paragraph))
3006 ;;;_ . format callbacks
3008 (defvar org-html-protect nil
)
3010 (defun org-html-format-spaces (n)
3011 (let ((space (or (and org-html-protect
"\\nbsp") " ")) out
)
3013 (setq out
(concat out space
))
3014 (setq n
(1- n
))) out
))
3017 (defun org-html-format-tabs (&optional n
)
3021 (defun org-html-format-line-break ()
3022 (org-html-format-tags "<br/>" ""))
3024 ;;;_ , horizontal line
3025 (defun org-html-format-horizontal-line ()
3026 (concat "\n" "<hr/>" "\n"))
3030 (defun org-html-format-plain (line)
3031 (case org-parse-dyn-current-environment
3032 ((quote fixedwidth
) (concat (org-html-protect line
) "\n"))
3033 (t (concat line
"\n"))))
3035 (defun org-html-format-comment (fmt &rest args
)
3036 (let ((comment (apply 'format fmt args
)))
3037 (format "\n<!-- %s -->\n" comment
)))
3040 ;;;_ , character styles
3041 (defun org-html-format-fontify (text style
&optional id
)
3042 (let (class extra how
)
3044 ((eq style
'underline
)
3045 (setq extra
" style=\"text-decoration:underline;\"" ))
3046 ((setq how
(cdr (assoc style
3047 '((bold .
("<b>" .
"</b>"))
3048 (emphasis .
("<i>" .
"</i>"))
3049 (code .
("<code>" .
"</code>"))
3050 (verbatim .
("<code>" .
"</code>"))
3051 (strike .
("<del>" .
"</del>"))
3052 (subscript .
("<sub>" .
"</sub>"))
3053 (superscript .
("<sup>" .
"</sup>")))))))
3055 (setq class
(mapconcat 'identity style
" ")))
3058 (t (error "Unknown style %S" style
)))
3060 (setq extra
(concat (when class
(format " class=\"%s\"" class
))
3061 (when id
(format " id=\"%s\"" id
))
3063 (org-html-format-tags
3064 (or how
'("<span%s>" .
"</span>")) text extra
)))
3067 (defun org-html-format-link (text href
&optional extra
)
3068 (let ((extra (concat (format " href=\"%s\"" href
)
3069 (and extra
(concat " " extra
)))))
3070 (org-html-format-tags '("<a%s>" .
"</a>") text extra
)))
3073 (defun org-html-format-heading (text level
&optional id
)
3074 (let* ((extra (concat (when id
(format " id=\"%s\"" id
)))))
3075 (concat (format "<h%d%s>" level extra
) text
(format "</h%d>" level
))))
3078 (defun org-html-format-headline (title extra-targets tags
3079 &optional snumber level
)
3081 (org-parse-format 'EXTRA-TARGETS extra-targets
)
3082 (concat (org-parse-format 'SECTION-NUMBER snumber level
) " ")
3084 (and tags
(concat (org-parse-format 'SPACES
3)
3085 (org-parse-format 'ORG-TAGS tags
)))))
3088 (defun org-html-format-anchor (text name
&optional class
)
3091 (when name
(format " name=\"%s\"" name
))
3092 (when id
(format " id=\"%s\"" id
))
3093 (when class
(format " class=\"%s\"" class
)))))
3094 (org-html-format-tags '("<a%s>" .
"</a>") text extra
)))
3099 ;;;_ , footnote reference
3100 (defun org-html-format-footnote-reference (n def refcnt
)
3101 (let ((extra (if (= refcnt
1) "" (format ".%d" refcnt
))))
3102 (format org-export-html-footnote-format
3104 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
3109 ;;;_ , footnotes section
3110 (defun org-html-format-footnotes-section (section-name definitions
)
3111 (if (not definitions
) ""
3112 (format org-export-html-footnotes-section section-name definitions
)))
3117 (defun org-html-format-tags (tag text
&rest args
)
3118 (let ((prefix (when org-html-protect
"@"))
3119 (suffix (when org-html-protect
"@")))
3122 (concat prefix
(apply 'format
(car tag
) args
) text suffix
3123 (format (cdr tag
))))
3124 ((stringp tag
) ; singleton tag
3125 (concat prefix
(apply 'format tag args
) text
)))))
3127 ;;;_ . maintenance callbacks
3130 ;;;_ , cleanup method
3132 (defun org-html-get (what &optional opt-plist
)
3137 (CLEANUP-METHOD nil
)
3138 (EXPORT-DIR (org-export-directory :html opt-plist
))
3139 (FILE-NAME-EXTENSION (plist-get opt-plist
:html-extension
))
3140 (EXPORT-BUFFER-NAME "*Org HTML Export*")
3141 (ENTITY-CONTROL org-html-entity-control-callbacks-alist
)
3142 (ENTITY-FORMAT org-html-entity-format-callbacks-alist
)
3143 (TOPLEVEL-HLEVEL org-export-html-toplevel-hlevel
)
3144 (t (error "Unknown property: %s" what
))))
3147 ;;;_ , coding system
3148 (defun org-html-get-coding-system-for-write ()
3149 (or org-export-html-coding-system
3150 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
3152 (defun org-html-get-coding-system-for-save ()
3153 (or org-export-html-coding-system
3154 (and (boundp 'buffer-file-coding-system
) buffer-file-coding-system
)))
3157 ;;;_. newhtml (non-parser & misc)
3158 (defun org-html-insert-toc (toc)
3159 ;; locate where toc needs to be inserted
3160 (goto-char (point-min))
3161 (if (or (re-search-forward
3162 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3164 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3166 (goto-char (match-beginning 0))
3168 (goto-char org-html-dyn-first-heading-pos
)
3169 (when (looking-at "\\s-*</p>")
3170 (goto-char (match-end 0))
3174 (defun org-html-insert-preamble (opt-plist)
3175 (when (plist-get opt-plist
:html-preamble
)
3176 (let ((html-pre (plist-get opt-plist
:html-preamble
))
3177 (title (plist-get opt-plist
:title
))
3178 (date (plist-get opt-plist
:effective-date
))
3179 (author (plist-get opt-plist
:author
))
3180 (lang-words (plist-get opt-plist
:lang-words
))
3181 (email (plist-get opt-plist
:email
)))
3182 (cond ((stringp html-pre
)
3184 (format-spec html-pre
`((?t .
,title
) (?a .
,author
)
3185 (?d .
,date
) (?e .
,email
)))))
3186 ((functionp html-pre
)
3187 (funcall html-pre opt-plist
))
3191 (or (cadr (assoc (nth 0 lang-words
)
3192 org-export-html-preamble-format
))
3193 (cadr (assoc "en" org-export-html-preamble-format
)))
3194 `((?t .
,title
) (?a .
,author
)
3195 (?d .
,date
) (?e .
,email
)))))))))
3197 (defun org-html-insert-postamble (opt-plist)
3198 (when org-html-footnote-definitions
3201 'FOOTNOTES-SECTION
(nth 4 (plist-get opt-plist
:lang-words
))
3202 (mapconcat (lambda (x) (cdr x
))
3203 (nreverse org-html-footnote-definitions
) "\n"))))
3204 (let ((bib (org-export-html-get-bibliography)))
3206 (insert "\n" bib
"\n")))
3208 ;; export html postamble
3210 (let* ((html-post (plist-get opt-plist
:html-postamble
))
3211 (date (plist-get opt-plist
:effective-date
))
3212 (author (plist-get opt-plist
:author
))
3213 (email (plist-get opt-plist
:email
))
3214 (lang-words (plist-get opt-plist
:lang-words
))
3215 (html-validation-link (or org-export-html-validation-link
""))
3217 (mapconcat (lambda(e)
3218 (format "<a href=\"mailto:%s\">%s</a>" e e
))
3219 (split-string email
",+ *")
3222 (concat "Org version " org-version
" with Emacs version "
3223 (number-to-string emacs-major-version
))))
3224 (when (plist-get opt-plist
:html-postamble
)
3225 (cond ((stringp html-post
)
3226 (insert "<div id=\"postamble\">\n")
3227 (insert (format-spec html-post
3228 `((?a .
,author
) (?e .
,email
)
3229 (?d .
,date
) (?c .
,creator-info
)
3230 (?v .
,html-validation-link
))))
3232 ((functionp html-post
)
3233 (funcall html-post opt-plist
))
3234 ((eq html-post
'auto
)
3235 ;; fall back on default postamble
3236 (insert "<div id=\"postamble\">\n")
3237 (when (plist-get opt-plist
:time-stamp-file
)
3238 (insert "<p class=\"date\">" (nth 2 lang-words
) ": " date
"</p>\n"))
3239 (when (and (plist-get opt-plist
:author-info
) author
)
3240 (insert "<p class=\"author\">" (nth 1 lang-words
) ": " author
"</p>\n"))
3241 (when (and (plist-get opt-plist
:email-info
) email
)
3242 (insert "<p class=\"email\">" email
"</p>\n"))
3243 (when (plist-get opt-plist
:creator-info
)
3244 (insert "<p class=\"creator\">"
3245 (concat "Org version " org-version
" with Emacs version "
3246 (number-to-string emacs-major-version
) "</p>\n")))
3247 (insert html-validation-link
"\n</div>"))
3249 (insert "<div id=\"postamble\">\n")
3250 (insert (format-spec
3251 (or (cadr (assoc (nth 0 lang-words
)
3252 org-export-html-postamble-format
))
3253 (cadr (assoc "en" org-export-html-postamble-format
)))
3254 `((?a .
,author
) (?e .
,email
)
3255 (?d .
,date
) (?c .
,creator-info
)
3256 (?v .
,html-validation-link
))))
3257 (insert "</div>"))))))
3259 (if org-export-html-with-timestamp
3260 (insert org-export-html-html-helper-timestamp
)))
3262 (defun org-html-format-todo (todo)
3263 (org-parse-format 'FONTIFY
3264 (org-export-html-get-todo-kwd-class-name todo
)
3265 (list (if (member todo org-done-keywords
) "done" "todo")
3268 (defun org-html-format-extra-targets (extra-targets)
3269 (if (not extra-targets
) ""
3270 (mapconcat (lambda (x)
3271 (setq x
(org-solidify-link-text
3272 (if (org-uuidgen-p x
) (concat "ID-" x
) x
)))
3273 (org-parse-format 'ANCHOR
"" x
))
3276 (defun org-html-format-org-tags (tags)
3282 'FONTIFY x
(org-export-html-get-tag-class-name x
)))
3283 (org-split-string tags
":")
3284 (org-parse-format 'SPACES
1)) "tag")))
3286 (defun org-html-format-section-number (&optional snumber level
)
3287 (and org-export-with-section-numbers
3288 (not body-only
) snumber level
3289 (org-parse-format 'FONTIFY snumber
(format "section-number-%d" level
))))
3296 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
3297 ;;; org-html.el ends here