org-html.el, org-odt.el: Use lang-specific setting for TOC.
[org-mode/org-jambu.git] / lisp / org-html.el
blobe15d9b79d304b2a3107168a4ef4877fe3cb5a91e
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
9 ;; Version: 7.5
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
29 ;;; Code:
31 (require 'org-exp)
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"
42 :group 'org-export)
44 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
45 <h2 class=\"footnotes\">%s: </h2>
46 <div id=\"text-footnotes\">
48 </div>
49 </div>"
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
55 :type 'string)
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
61 :type 'string)
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
66 :type 'coding-system)
68 (defcustom org-export-html-extension "html"
69 "The extension for exported HTML files."
70 :group 'org-export-html
71 :type 'string)
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
81 :type '(choice
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
90 not be modified."
91 :group 'org-export-html
92 :type 'boolean)
94 (defconst org-export-html-scripts
95 "<script type=\"text/javascript\">
96 <!--/*--><![CDATA[/*><!--*/
97 function CodeHighlightOn(elem, id)
99 var target = document.getElementById(id);
100 if(null != target) {
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;
115 /*]]>*///-->
116 </script>"
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 }
127 .target { }
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% }
134 pre {
135 border: 1pt solid #AEBDCC;
136 background-color: #F3F5F7;
137 padding: 5pt;
138 font-family: courier, monospace;
139 font-size: 90%;
140 overflow:auto;
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;
160 font-weight:bold; }
161 /*]]>*/-->
162 </style>"
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
175 :type 'boolean)
176 ;;;###autoload
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\">
190 <![CDATA[
191 p { font-weight: normal; color: gray; }
192 h1 { color: black; }
193 .title { text-align: center; }
194 .todo, .timestamp-kwd { color: red; }
195 .done { color: green; }
197 </style>
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
207 :type 'string)
208 ;;;###autoload
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
218 :type 'string)
219 ;;;###autoload
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")
224 (scale "100")
225 (align "center")
226 (indent "2em")
227 (mathml nil))
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)
258 (mapc
259 (lambda (e)
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))))
267 options)
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
280 template))
282 (defcustom org-export-html-mathjax-template
283 "<script type=\"text/javascript\" src=\"%PATH\">
284 <!--/*--><![CDATA[/*><!--*/
285 MathJax.Hub.Config({
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\"],
292 tex2jax: {
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,
299 preview: \"TeX\"
301 showProcessingMessages: true,
302 displayAlign: \"%ALIGN\",
303 displayIndent: \"%INDENT\",
305 \"HTML-CSS\": {
306 scale: %SCALE,
307 availableFonts: [\"STIX\",\"TeX\"],
308 preferredFont: \"TeX\",
309 webFont: \"TeX\",
310 imageFont: \"TeX\",
311 showMathMenu: true,
313 MMLorHTML: {
314 prefer: {
315 MSIE: \"MML\",
316 Firefox: \"MML\",
317 Opera: \"HTML\",
318 other: \"HTML\"
322 /*]]>*///-->
323 </script>"
324 "The MathJax setup for XHTML files."
325 :group 'org-export-html
326 :type 'string)
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
335 :type 'string)
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
344 :type 'string)
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
371 like that: \"%%\"."
372 :group 'org-export-html
373 :type 'string)
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
385 only argument.
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
411 like that: \"%%\"."
412 :group 'org-export-html
413 :type 'string)
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>
420 </div>"
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
425 ignored."
426 :group 'org-export-html
427 :type 'string)
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
436 document title."
437 :group 'org-export-html
438 :type 'string)
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
447 converted to HTML.
448 When nil, the links still point to the plain `.org' file."
449 :group 'org-export-html
450 :type 'boolean)
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
457 be linked only."
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
475 :type 'string)
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
506 (cons '(if head
507 \"<tr>\"
508 (if (= (mod nline 2) 1)
509 \"<tr class=\\\"tr-odd\\\">\"
510 \"<tr class=\\\"tr-even\\\">\"))
511 \"</tr>\"))
513 will give even lines the class \"tr-even\" and odd lines the class \"tr-odd\"."
514 :group 'org-export-tables
515 :type '(cons
516 (choice :tag "Opening tag"
517 (string :tag "Specify")
518 (sexp))
519 (choice :tag "Closing tag"
520 (string :tag "Specify")
521 (sexp))))
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
527 though."
528 :group 'org-export-tables
529 :type 'boolean)
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
535 :type 'boolean)
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
541 :type 'string)
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
547 a file."
548 :group 'org-export-html
549 :type 'boolean)
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
555 :type 'string)
557 (defcustom org-export-html-protect-char-alist
558 '(("&" . "&amp;")
559 ("<" . "&lt;")
560 (">" . "&gt;"))
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
592 :type 'string)
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
604 :type '(choice
605 (const :tag "Keep internal css" nil)
606 (string :tag "URL or local href")))
608 ;;; Hooks
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.")
616 ;;; HTML export
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))
622 (org-format-latex
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"
627 nil nil
628 (cond
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)
633 (t nil))))
634 (goto-char (point-min))
635 (let (label l1)
636 (while (re-search-forward "\\\\ref{\\([^{}\n]+\\)}" nil t)
637 (org-if-unprotected-at (match-beginning 1)
638 (setq label (match-string 1))
639 (save-match-data
640 (if (string-match "\\`[a-z]\\{1,10\\}:\\(.+\\)" label)
641 (setq l1 (substring label (match-beginning 1)))
642 (setq l1 label)))
643 (replace-match (format "[[#%s][%s]]" label l1) t t)))))
645 ;;;###autoload
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."
651 (interactive "P")
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))))
657 ;;;###autoload
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:
661 emacs --batch
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))
667 ;;;###autoload
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'."
671 (interactive "P")
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*")))
676 ;;;###autoload
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."
682 (interactive "r")
683 (let (reg html buf pop-up-frames)
684 (save-window-excursion
685 (if (org-mode-p)
686 (setq html (org-export-region-as-html
687 beg end t 'string))
688 (setq reg (buffer-substring beg end)
689 buf (get-buffer-create "*Org tmp*"))
690 (with-current-buffer buf
691 (erase-buffer)
692 (insert reg)
693 (org-mode)
694 (setq html (org-export-region-as-html
695 (point-min) (point-max) t 'string)))
696 (kill-buffer buf)))
697 (delete-region beg end)
698 (insert html)))
700 ;;;###autoload
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."
715 (interactive "r\nP")
716 (when (interactive-p)
717 (setq buffer "*Org HTML Export*"))
718 (let ((transient-mark-mode t) (zmacs-regions t)
719 ext-plist rtn)
720 (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
721 (goto-char end)
722 (set-mark (point)) ;; to activate the region
723 (goto-char beg)
724 (setq rtn (org-export-as-html
725 nil nil ext-plist
726 buffer body-only))
727 (if (fboundp 'deactivate-mark) (deactivate-mark))
728 (if (and (interactive-p) (bufferp rtn))
729 (switch-to-buffer-other-window rtn)
730 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'"
749 (save-match-data
750 (and
751 org-export-html-link-org-files-as-html
752 (string= type "file")
753 (string-match "\\.org$" path)
754 (progn
755 (list
756 "file"
757 (concat
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'."
770 (declare (special
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)))
775 (org-file-image-p
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
780 descp)
781 "Make an HTML link.
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."
790 (declare (special org-par-open))
791 (save-match-data
792 (let* ((may-inline-p
793 (and (member type-1 '("http" "https" "file"))
794 (org-html-should-inline-p path descp)
795 (not fragment)))
796 (type (if (equal type-1 "id") "file" type-1))
797 (filename path)
798 ;;First pass. Just sanity stuff.
799 (components-1
800 (cond
801 ((string= type "file")
802 (list
803 type
804 ;;Substitute just if original path was absolute.
805 ;;(Otherwise path must remain relative)
806 (if (file-name-absolute-p path)
807 (concat "file://" (expand-file-name path))
808 path)))
809 ((string= type "")
810 (list nil path))
811 (t (list type path))))
813 ;;Second pass. Components converted so they can refer
814 ;;to a remote site.
815 (components-2
817 (and org-html-cvt-link-fn
818 (apply org-html-cvt-link-fn
819 opt-plist components-1))
820 (apply #'org-html-cvt-org-as-html
821 opt-plist components-1)
822 components-1))
823 (type (first components-2))
824 (thefile (second components-2)))
827 ;;Third pass. Build final link except for leading type
828 ;;spec.
829 (cond
830 ((or
831 (not type)
832 (string= type "http")
833 (string= type "https")
834 (string= type "file"))
835 (if fragment
836 (setq thefile (concat thefile "#" fragment))))
838 (t))
840 ;;Final URL-build, for all types.
841 (setq thefile
842 (let
843 ((str (org-export-html-format-href thefile)))
844 (if (and type (not (string= "file" type)))
845 (concat type ":" str)
846 str)))
848 (if may-inline-p
849 (org-export-html-format-image thefile)
850 (org-parse-format
851 'LINK (org-export-html-format-desc desc) thefile attr)))))
853 (defun org-html-format-inline-image (desc)
854 ;; FIXME: alt text missing here?
855 (org-html-format-tags '("<img src=\"%s\" alt=\"\">" . "</img>") "" desc))
857 (defvar org-parse-link-description-is-image)
858 (defun org-parse-format-org-link (line opt-plist)
859 "Return LINE with markup of Org mode links.
860 OPT-PLIST is the export options list."
861 (let ((start 0)
862 (current-dir (if buffer-file-name
863 (file-name-directory buffer-file-name)
864 default-directory))
865 (link-validate (plist-get opt-plist :link-validation-function))
866 type id-file fnc
867 rpl path attr desc descp desc1 desc2 link
868 org-parse-link-description-is-image)
869 (while (string-match org-bracket-link-analytic-regexp++ line start)
870 (setq org-parse-link-description-is-image nil)
871 (setq start (match-beginning 0))
872 (setq path (save-match-data (org-link-unescape
873 (match-string 3 line))))
874 (setq type (cond
875 ((match-end 2) (match-string 2 line))
876 ((save-match-data
877 (or (file-name-absolute-p path)
878 (string-match "^\\.\\.?/" path)))
879 "file")
880 (t "internal")))
881 (setq path (org-extract-attributes (org-link-unescape path)))
882 (setq attr (get-text-property 0 'org-attributes path))
883 (setq desc1 (if (match-end 5) (match-string 5 line))
884 desc2 (if (match-end 2) (concat type ":" path) path)
885 descp (and desc1 (not (equal desc1 desc2)))
886 desc (or desc1 desc2))
887 ;; Make an image out of the description if that is so wanted
888 (when (and descp (org-file-image-p
889 desc org-export-html-inline-image-extensions))
890 (setq org-parse-link-description-is-image t)
891 (save-match-data
892 (if (string-match "^file:" desc)
893 (setq desc (substring desc (match-end 0)))))
894 (save-match-data
895 (setq desc (org-add-props
896 (org-parse-format 'INLINE-IMAGE desc)
897 '(org-protected t)))))
898 (cond
899 ((equal type "internal")
900 (let
901 ((frag-0
902 (if (= (string-to-char path) ?#)
903 (substring path 1)
904 path)))
905 (setq rpl
906 (org-parse-format
907 'ORG-LINK opt-plist "" "" (org-solidify-link-text
908 (save-match-data
909 (org-link-unescape frag-0))
910 nil) desc attr descp))))
911 ((and (equal type "id")
912 (setq id-file (org-id-find-id-file path)))
913 ;; This is an id: link to another file (if it was the same file,
914 ;; it would have become an internal link...)
915 (save-match-data
916 (setq id-file (file-relative-name
917 id-file
918 (file-name-directory org-current-export-file)))
919 (setq rpl
920 (org-parse-format
921 'ORG-LINK opt-plist type id-file
922 (concat (if (org-uuidgen-p path) "ID-") path)
923 desc attr descp))))
924 ((member type '("http" "https"))
925 ;; standard URL, can inline as image
926 (setq rpl
927 (org-parse-format
928 'ORG-LINK opt-plist type path nil desc attr descp)))
929 ((member type '("ftp" "mailto" "news"))
930 ;; standard URL, can't inline as image
931 (setq rpl
932 (org-parse-format
933 'ORG-LINK opt-plist type path nil desc attr descp)))
935 ((string= type "coderef")
936 (let*
937 ((coderef-str (format "coderef-%s" path))
938 (attr-1
939 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
940 coderef-str coderef-str)))
941 (setq rpl
942 (org-parse-format
943 'ORG-LINK opt-plist type "" coderef-str
944 (format
945 (org-export-get-coderef-format
946 path
947 (and descp desc))
948 (cdr (assoc path org-export-code-refs))) attr-1 descp))))
950 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
951 ;; The link protocol has a function for format the link
952 (setq rpl
953 (save-match-data
954 (funcall fnc (org-link-unescape path) desc1 'html))))
956 ((string= type "file")
957 ;; FILE link
958 (save-match-data
959 (let*
960 ((components
962 (string-match "::\\(.*\\)" path)
963 (list
964 (replace-match "" t nil path)
965 (match-string 1 path))
966 (list path nil)))
968 ;;The proper path, without a fragment
969 (path-1
970 (first components))
972 ;;The raw fragment
973 (fragment-0
974 (second components))
976 ;;Check the fragment. If it can't be used as
977 ;;target fragment we'll pass nil instead.
978 (fragment-1
980 (and fragment-0
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))
986 nil))
987 (desc-2
988 ;;Description minus "file:" and ".org"
989 (if (string-match "^file:" desc)
990 (let
991 ((desc-1 (replace-match "" t t desc)))
992 (if (string-match "\\.org$" desc-1)
993 (replace-match "" t t desc-1)
994 desc-1))
995 desc)))
997 (setq rpl
999 (and
1000 (functionp link-validate)
1001 (not (funcall link-validate path-1 current-dir)))
1002 desc
1003 (org-parse-format
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>&lt;" type ":"
1010 (save-match-data (org-link-unescape path))
1011 "&gt;</i>"))))
1012 (setq line (replace-match rpl t t line)
1013 start (+ start (length rpl))))
1014 line))
1016 (defmacro with-org-parse-preserve-paragraph-state (&rest body)
1017 `(let ((org-do-open-par org-par-open))
1018 (org-parse-end-paragraph)
1019 ,@body
1020 (when org-do-open-par
1021 (org-parse-begin-paragraph))))
1023 ;;; org-export-as-html
1024 ;;;###autoload
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."
1041 (interactive "P")
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
1048 ;; progress
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)
1064 buffer-file-name))
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
1073 org-par-open
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))
1078 (opt-plist
1079 (org-export-process-option-filters
1080 (org-combine-plists (org-default-export-plist)
1081 ext-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)))
1089 (subtree-p
1090 (if (plist-get opt-plist :ignore-subtree-p)
1092 (when region-p
1093 (save-excursion
1094 (goto-char rbeg)
1095 (and (org-at-heading-p)
1096 (>= (org-end-of-subtree t t) rend))))))
1097 (level-offset (if subtree-p
1098 (save-excursion
1099 (goto-char rbeg)
1100 (+ (funcall outline-level)
1101 (if org-odd-levels-only 1 0)))
1103 (opt-plist (setq org-export-opt-plist
1104 (if subtree-p
1105 (org-export-add-subtree-options opt-plist rbeg)
1106 opt-plist)))
1107 ;; The following two are dynamically scoped into other
1108 ;; routines below.
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
1113 (umax nil)
1114 (umax-toc nil)
1115 (filename (if to-buffer nil
1116 (expand-file-name
1117 (concat
1118 (file-name-sans-extension
1119 (or (and subtree-p
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)
1128 default-directory))
1129 (buffer (if to-buffer
1130 (cond
1131 ((eq to-buffer 'string)
1132 (get-buffer-create (org-parse-get 'EXPORT-BUFFER-NAME)))
1133 (t (get-buffer-create to-buffer)))
1134 (find-file-noselect
1135 (or (let ((f (org-parse-get 'INIT-METHOD)))
1136 (and f (functionp f) (funcall f filename)))
1137 filename))))
1138 (org-levels-open (make-vector org-level-max nil))
1139 (date (plist-get opt-plist :date))
1140 (date (cond
1141 ((and date (string-match "%" date))
1142 (format-time-string date))
1143 (date 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)
1150 (not
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)))
1156 "UNTITLED")))
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)))
1167 (head-count 0) cnt
1168 (start 0)
1169 (coding-system-for-write (org-html-get-coding-system-for-write))
1170 (save-buffer-coding-system (org-html-get-coding-system-for-save))
1171 (region
1172 (buffer-substring
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))
1178 (lines
1179 (org-split-string
1180 (org-export-preprocess-string
1181 region
1182 :emph-multiline t
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)
1192 :archived-trees
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)
1196 :add-text
1197 (plist-get opt-plist :text)
1198 :LaTeX-fragments
1199 (plist-get opt-plist :LaTeX-fragments))
1200 "[\r\n]"))
1201 table-open
1202 table-buffer table-orig-buffer
1204 rpl path attr desc descp desc1 desc2 link
1205 snumber fnc
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
1212 href
1215 (let ((inhibit-read-only t))
1216 (org-unmodified
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))
1227 (fundamental-mode)
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
1237 (mapc (lambda (x)
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)
1245 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)))
1251 (unless body-only
1252 (org-parse-begin 'DOCUMENT-CONTENT opt-plist)
1253 (org-parse-begin 'DOCUMENT-BODY opt-plist))
1255 (setq head-count 0)
1256 (org-init-section-numbers)
1258 (org-parse-begin-paragraph)
1260 (while (setq line (pop lines) origline line)
1261 (catch 'nextline
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]\\|$\\)\\(.*\\)\\)"
1278 (car lines))))
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.
1295 ;; I think --->
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
1319 ;; LaTeX fragments.
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
1324 ;; Native Text
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)
1329 (length line))))
1330 (let ((ind (get-text-property 0 'original-indentation line)))
1331 (org-parse-begin-environment 'native)
1332 (insert (org-parse-format 'PLAIN line))
1333 (while (and lines
1334 (or (= (length (car lines)) 0)
1335 (not ind)
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))
1344 ;; Protected HTML
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)
1349 (length line))))
1350 (let ((ind (get-text-property 0 'original-indentation line)))
1351 (insert (org-parse-format 'PLAIN line))
1352 (while (and lines
1353 (or (= (length (car lines)) 0)
1354 (not ind)
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))
1369 (funcall f style)
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)))
1375 (if (> i 0)
1376 (setq line (concat
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
1384 (setq start 0)
1385 (while (string-match
1386 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
1387 (cond
1388 ((get-text-property (match-beginning 1) 'org-protected line)
1389 (setq start (match-end 1)))
1390 ((match-end 2)
1391 (setq line (replace-match
1392 (let ((org-html-protect t))
1393 (org-parse-format
1394 'ANCHOR "" (org-solidify-link-text
1395 (match-string 1 line))))
1396 t t 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))
1401 (org-parse-format
1402 'FONTIFY (match-string 1 line) "target"))
1403 ;; (concat "@<i>" (match-string 1 line) "@</i> ")
1404 t t line)))
1406 (setq line (replace-match
1407 (concat
1408 (let ((org-html-protect t))
1409 (org-parse-format
1410 'ANCHOR (match-string 1 line)
1411 (org-solidify-link-text (match-string 1 line))
1412 "target")) " ")
1413 t t line)))))
1415 (let ((org-html-protect t))
1416 (setq line (org-html-handle-time-stamps line)))
1418 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
1419 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" 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))
1426 ;; TODO items
1427 (if (and (string-match org-todo-line-regexp line)
1428 (match-beginning 2))
1429 (setq line (concat
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
1436 (setq start 0)
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))
1442 (progn
1443 (setcdr a (1+ (cdr a)))
1444 (setq refcnt (cdr a)))
1445 (setq refcnt 1)
1446 (push (cons n 1) footref-seen))
1447 (setq line
1448 (replace-match
1449 (concat
1450 (or (match-string 1 line) "")
1451 (org-parse-format
1452 'FOOTNOTE-REFERENCE
1453 n (cdr (assoc n org-html-footnote-definitions))
1454 refcnt))
1455 t t line))))))
1457 (cond
1458 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1459 ;; This is a headline
1460 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1461 level-offset))
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
1470 (and org-export-with-toc (<= level umax))
1471 head-count)
1473 ;; QUOTES
1474 (when (string-match quote-re line)
1475 (org-parse-begin-environment 'quote)))
1477 ((and org-export-with-tables
1478 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1479 (when (not table-open)
1480 ;; New table starts
1481 (setq table-open t table-buffer nil table-orig-buffer nil))
1483 ;; Accumulate lines
1484 (setq table-buffer (cons line table-buffer)
1485 table-orig-buffer (cons origline table-orig-buffer))
1486 (when (or (not lines)
1487 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1488 (car lines))))
1489 (setq table-open nil
1490 table-buffer (nreverse table-buffer)
1491 table-orig-buffer (nreverse table-orig-buffer))
1492 (org-parse-end-paragraph)
1493 (insert (org-format-table-html table-buffer table-orig-buffer))))
1495 ;; Normal lines
1498 ;; This line either is list item or end a list.
1499 (when (get-text-property 0 'list-item line)
1500 (setq line (org-html-export-list-line
1501 line
1502 (get-text-property 0 'list-item line)
1503 (get-text-property 0 'list-struct line)
1504 (get-text-property 0 'list-prevs line))))
1506 ;; Horizontal line
1507 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1508 (with-org-parse-preserve-paragraph-state
1509 (insert (org-parse-format 'HORIZONTAL-LINE)))
1510 (throw 'nextline nil))
1512 ;; Empty lines start a new paragraph. If hand-formatted lists
1513 ;; are not fully interpreted, lines starting with "-", "+", "*"
1514 ;; also start a new paragraph.
1515 (when (string-match "^ [-+*]-\\|^[ \t]*$" line)
1516 (when org-html-footnote-number
1517 (org-parse-end-footnote-definition org-html-footnote-number)
1518 (setq org-html-footnote-number nil))
1519 (org-parse-begin-paragraph))
1521 ;; Is this the start of a footnote?
1522 (when org-export-with-footnotes
1523 (when (and (boundp 'footnote-section-tag-regexp)
1524 (string-match (concat "^" footnote-section-tag-regexp)
1525 line))
1526 ;; ignore this line
1527 (throw 'nextline nil))
1528 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1529 (org-parse-end-paragraph)
1530 (setq org-html-footnote-number (match-string 1 line))
1531 (setq line (replace-match "" t t line))
1532 (org-parse-begin-footnote-definition org-html-footnote-number)))
1533 ;; Check if the line break needs to be conserved
1534 (cond
1535 ((string-match "\\\\\\\\[ \t]*$" line)
1536 (setq line (replace-match
1537 (org-parse-format 'LINE-BREAK)
1538 t t line)))
1539 (org-export-preserve-breaks
1540 (setq line (concat line (org-parse-format 'LINE-BREAK)))))
1542 ;; Check if a paragraph should be started
1543 (let ((start 0))
1544 (while (and org-par-open
1545 (string-match "\\\\par\\>" line start))
1546 (error "FIXME")
1547 ;; Leave a space in the </p> so that the footnote matcher
1548 ;; does not see this.
1549 (if (not (get-text-property (match-beginning 0)
1550 'org-protected line))
1551 (setq line (replace-match "</p ><p >" t t line)))
1552 (setq start (match-end 0))))
1554 (insert (org-parse-format 'PLAIN line))))))
1556 ;; Properly close all local lists and other lists
1557 (when (org-parse-current-environment-p 'quote)
1558 (org-parse-end-environment 'quote))
1560 (org-parse-end 'LEVEL 1 umax)
1562 ;; the </div> to close the last text-... div.
1563 (when (and (> umax 0) org-html-dyn-first-heading-pos)
1564 (org-parse-end 'SECTION))
1566 (org-parse-end 'DOCUMENT-BODY opt-plist)
1567 (unless body-only
1568 (org-parse-end 'DOCUMENT-CONTENT))
1570 (unless (plist-get opt-plist :buffer-will-be-killed)
1571 (set-auto-mode t))
1573 (org-parse-end 'EXPORT)
1575 (goto-char (point-min))
1576 (or (org-export-push-to-kill-ring
1577 (upcase (symbol-name org-parse-backend)))
1578 (message "Exporting... done"))
1580 (cond
1581 ((not to-buffer)
1582 (let ((f (org-parse-get 'SAVE-METHOD)))
1583 (or (and f (functionp f) (funcall f filename))
1584 (save-buffer)))
1585 (current-buffer))
1586 ((eq to-buffer 'string)
1587 (prog1 (buffer-substring (point-min) (point-max))
1588 (kill-buffer (current-buffer))))
1589 (t (current-buffer))))))
1591 (defun org-export-html-format-href (s)
1592 "Make sure the S is valid as a href reference in an XHTML document."
1593 (save-match-data
1594 (let ((start 0))
1595 (while (string-match "&" s start)
1596 (setq start (+ (match-beginning 0) 3)
1597 s (replace-match "&amp;" t t s)))))
1600 (defun org-export-html-format-desc (s)
1601 "Make sure the S is valid as a description in a link."
1602 (if (and s (not (get-text-property 1 'org-protected s)))
1603 (save-match-data
1604 (org-html-do-expand s))
1607 (defun org-export-html-format-image (src)
1608 "Create image tag with source and attributes."
1609 (save-match-data
1610 (if (string-match "^ltxpng/" src)
1611 (format "<img src=\"%s\" alt=\"%s\"/>"
1612 src (org-find-text-property-in-string 'org-latex-src src))
1613 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1614 (attr (org-find-text-property-in-string 'org-attributes src))
1615 (label (org-find-text-property-in-string 'org-label src))
1616 (caption (and caption (org-html-do-expand caption)))
1617 (img (format "<img src=\"%s\"%s />"
1619 (if (string-match "\\<alt=" (or attr ""))
1620 (concat " " attr )
1621 (concat " " attr " alt=\"" src "\""))))
1622 (extra (concat
1623 (and label
1624 (format "id=\"%s\" " (org-solidify-link-text label)))
1625 "class=\"figure\"")))
1626 (if caption
1627 (with-temp-buffer
1628 (with-org-parse-preserve-paragraph-state
1629 (insert
1630 (org-parse-format
1631 '("<div %s>" . "\n</div>")
1632 (concat
1633 (org-parse-format '("\n<p>" . "</p>") img)
1634 (org-parse-format '("\n<p>" . "</p>") caption))
1635 extra)))
1636 (buffer-string))
1637 img)))))
1639 (defun org-export-html-get-bibliography ()
1640 "Find bibliography, cut it out and return it."
1641 (catch 'exit
1642 (let (beg end (cnt 1) bib)
1643 (save-excursion
1644 (goto-char (point-min))
1645 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1646 (setq beg (match-beginning 0))
1647 (while (re-search-forward "</?div\\>" nil t)
1648 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1649 (when (= cnt 0)
1650 (and (looking-at ">") (forward-char 1))
1651 (setq bib (buffer-substring beg (point)))
1652 (delete-region beg (point))
1653 (throw 'exit bib))))
1654 nil))))
1656 ;; Following variable is defined for native tables i.e., when
1657 ;; `org-table-is-styled' evals to t.
1658 (defvar no-css)
1659 (defvar org-table-number-regexp) ; defined in org-table.el
1660 (defun org-format-table-html (lines olines &optional no-css)
1661 "Find out which HTML converter to use and return the HTML code.
1662 NO-CSS is passed to the exporter."
1663 (if (stringp lines)
1664 (setq lines (org-split-string lines "\n")))
1665 (if (string-match "^[ \t]*|" (car lines))
1666 ;; A normal org table
1667 (org-format-org-table-html lines nil no-css)
1668 ;; Table made by table.el - test for spanning
1669 (let* ((hlines (delq nil (mapcar
1670 (lambda (x)
1671 (if (string-match "^[ \t]*\\+-" x) x
1672 nil))
1673 lines)))
1674 (first (car hlines))
1675 (ll (and (string-match "\\S-+" first)
1676 (match-string 0 first)))
1677 (re (concat "^[ \t]*" (regexp-quote ll)))
1678 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
1679 hlines))))
1680 (if (and (not spanning)
1681 (not org-export-prefer-native-exporter-for-tables))
1682 ;; We can use my own converter with HTML conversions
1683 (org-format-table-table-html lines)
1684 ;; Need to use the code generator in table.el, with the original text.
1685 (org-format-table-table-html-using-table-generate-source olines)))))
1687 (defun org-table-get-colalign-info (lines)
1688 (let ((forced-aligns (org-find-text-property-in-string
1689 'org-forced-aligns (car lines))))
1690 (when (and forced-aligns org-table-clean-did-remove-column)
1691 (setq forced-aligns
1692 (mapcar (lambda (x) (cons (1- (car x)) (cdr x))) forced-aligns)))
1694 forced-aligns))
1696 (defvar org-table-style)
1697 (defvar org-table-ncols)
1698 (defvar org-table-rownum)
1700 (defvar org-table-is-styled)
1701 (defvar org-table-begin-marker)
1702 (defvar org-table-num-numeric-items-per-column)
1703 (defvar org-table-colalign-info)
1704 (defvar org-table-colalign-vector)
1705 (defvar org-table-number-fraction) ; defined in org-table.el
1706 (defun org-do-format-org-table-html (lines &optional splice no-css)
1707 "Format a table into HTML.
1708 LINES is a list of lines. Optional argument SPLICE means, do not
1709 insert header and surrounding <table> tags, just format the lines.
1710 Optional argument NO-CSS means use XHTML attributes instead of CSS
1711 for formatting. This is required for the DocBook exporter."
1712 (require 'org-table)
1713 ;; Get rid of hlines at beginning and end
1714 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1715 (setq lines (nreverse lines))
1716 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
1717 (setq lines (nreverse lines))
1718 (when org-export-table-remove-special-lines
1719 ;; Check if the table has a marking column. If yes remove the
1720 ;; column and the special lines
1721 (setq lines (org-table-clean-before-export lines)))
1723 (let* ((caption (org-find-text-property-in-string 'org-caption (car lines)))
1724 (caption (and caption (org-html-do-expand caption)))
1725 (label (org-find-text-property-in-string 'org-label (car lines)))
1726 (org-table-colalign-info (org-table-get-colalign-info lines))
1727 (attributes (org-find-text-property-in-string 'org-attributes
1728 (car lines)))
1729 (head (and org-export-highlight-first-table-line
1730 (delq nil (mapcar
1731 (lambda (x) (string-match "^[ \t]*|-" x))
1732 (cdr lines)))))
1733 (org-table-rownum -1) org-table-ncols i (cnt 0)
1734 tbopen line fields
1735 org-table-current-rowgroup-is-header
1736 org-table-rowgroup-open
1737 org-table-num-numeric-items-per-column
1738 org-table-colalign-vector n
1739 org-table-rowgroup-info
1740 org-table-begin-marker
1741 (org-table-style 'org-table)
1742 org-table-is-styled)
1743 (cond
1744 (splice
1745 (setq org-table-is-styled nil)
1746 (while (setq line (pop lines))
1747 (unless (string-match "^[ \t]*|-" line)
1748 (insert
1749 (org-parse-format-table-row
1750 (org-split-string line "[ \t]*|[ \t]*")) "\n"))))
1752 (setq org-table-is-styled t)
1753 (org-parse-begin 'TABLE caption label attributes)
1754 (setq org-table-begin-marker (point))
1755 (org-parse-begin-table-rowgroup head)
1756 (while (setq line (pop lines))
1757 (cond
1758 ((string-match "^[ \t]*|-" line)
1759 (when lines (org-parse-begin-table-rowgroup)))
1761 (insert
1762 (org-parse-format-table-row
1763 (org-split-string line "[ \t]*|[ \t]*")) "\n"))))
1764 (org-parse-end 'TABLE-ROWGROUP)
1765 (org-parse-end-table)))))
1767 (defun org-format-org-table-html (lines &optional splice no-css)
1768 (with-temp-buffer
1769 (org-do-format-org-table-html lines splice no-css)
1770 (buffer-substring-no-properties (point-min) (point-max))))
1772 (defun org-export-splice-attributes (tag attributes)
1773 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1774 (if (not attributes)
1776 (let (oldatt newatt)
1777 (setq oldatt (org-extract-attributes-from-string tag)
1778 tag (pop oldatt)
1779 newatt (cdr (org-extract-attributes-from-string attributes)))
1780 (while newatt
1781 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1782 (if (string-match ">" tag)
1783 (setq tag
1784 (replace-match (concat (org-attributes-to-string oldatt) ">")
1785 t t tag)))
1786 tag)))
1788 (defun org-do-format-table-table-html (lines)
1789 "Format a table generated by table.el into HTML.
1790 This conversion does *not* use `table-generate-source' from table.el.
1791 This has the advantage that Org-mode's HTML conversions can be used.
1792 But it has the disadvantage, that no cell- or row-spanning is allowed."
1793 (let (line field-buffer
1794 (org-table-current-rowgroup-is-header
1795 org-export-highlight-first-table-line)
1796 (caption nil)
1797 (attributes nil)
1798 (label nil)
1799 (org-table-style 'table-table)
1800 (org-table-is-styled nil)
1801 fields org-table-ncols i (org-table-rownum -1)
1802 (empty (org-parse-format 'SPACES 1)))
1803 (org-parse-begin 'TABLE caption label attributes)
1804 (while (setq line (pop lines))
1805 (cond
1806 ((string-match "^[ \t]*\\+-" line)
1807 (when field-buffer
1808 (let ((org-export-table-row-tags '("<tr>" . "</tr>"))
1809 (org-export-html-table-use-header-tags-for-first-column nil))
1810 (insert (org-parse-format-table-row field-buffer empty)))
1811 (setq org-table-current-rowgroup-is-header nil)
1812 (setq field-buffer nil)))
1814 ;; Break the line into fields and store the fields
1815 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1816 (if field-buffer
1817 (setq field-buffer (mapcar
1818 (lambda (x)
1819 (concat x (org-parse-format 'LINE-BREAK)
1820 (pop fields)))
1821 field-buffer))
1822 (setq field-buffer fields)))))
1823 (org-parse-end-table)))
1825 (defun org-format-table-table-html (lines)
1826 (with-temp-buffer
1827 (org-do-format-table-table-html lines)
1828 (buffer-substring-no-properties (point-min) (point-max))))
1830 (defun org-format-table-table-html-using-table-generate-source (lines)
1831 "Format a table into html, using `table-generate-source' from table.el.
1832 This has the advantage that cell- or row-spanning is allowed.
1833 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
1834 (require 'table)
1835 (with-current-buffer (get-buffer-create " org-tmp1 ")
1836 (erase-buffer)
1837 (insert (mapconcat 'identity lines "\n"))
1838 (goto-char (point-min))
1839 (if (not (re-search-forward "|[^+]" nil t))
1840 (error "Error processing table"))
1841 (table-recognize-table)
1842 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1843 (table-generate-source 'html " org-tmp2 ")
1844 (set-buffer " org-tmp2 ")
1845 (buffer-substring (point-min) (point-max))))
1847 (defun org-export-splice-style (style extra)
1848 "Splice EXTRA into STYLE, just before \"</style>\"."
1849 (if (and (stringp extra)
1850 (string-match "\\S-" extra)
1851 (string-match "</style>" style))
1852 (concat (substring style 0 (match-beginning 0))
1853 "\n" extra "\n"
1854 (substring style (match-beginning 0)))
1855 style))
1857 (defun org-html-handle-time-stamps (s)
1858 "Format time stamps in string S, or remove them."
1859 (catch 'exit
1860 (let (r b)
1861 (while (string-match org-maybe-keyword-time-regexp s)
1862 (or b (setq b (substring s 0 (match-beginning 0))))
1863 (setq r (concat
1864 r (substring s 0 (match-beginning 0))
1865 (org-parse-format
1866 'FONTIFY
1867 (concat
1868 (if (match-end 1)
1869 (org-parse-format
1870 'FONTIFY
1871 (match-string 1 s) "timestamp-kwd"))
1872 (org-parse-format
1873 'FONTIFY
1874 (substring (org-translate-time (match-string 3 s)) 1 -1)
1875 "timestamp"))
1876 "timestamp-wrapper"))
1877 s (substring s (match-end 0))))
1878 ;; Line break if line started and ended with time stamp stuff
1879 (if (not r)
1881 (setq r (concat r s))
1882 (unless (string-match "\\S-" (concat b s))
1883 (setq r (concat r (org-parse-format 'LINE-BREAK))))
1884 r))))
1886 (defvar htmlize-buffer-places) ; from htmlize.el
1887 (defun org-export-htmlize-region-for-paste (beg end)
1888 "Convert the region to HTML, using htmlize.el.
1889 This is much like `htmlize-region-for-paste', only that it uses
1890 the settings define in the org-... variables."
1891 (let* ((htmlize-output-type org-export-htmlize-output-type)
1892 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
1893 (htmlbuf (htmlize-region beg end)))
1894 (unwind-protect
1895 (with-current-buffer htmlbuf
1896 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1897 (plist-get htmlize-buffer-places 'content-end)))
1898 (kill-buffer htmlbuf))))
1900 ;;;###autoload
1901 (defun org-export-htmlize-generate-css ()
1902 "Create the CSS for all font definitions in the current Emacs session.
1903 Use this to create face definitions in your CSS style file that can then
1904 be used by code snippets transformed by htmlize.
1905 This command just produces a buffer that contains class definitions for all
1906 faces used in the current Emacs session. You can copy and paste the ones you
1907 need into your CSS file.
1909 If you then set `org-export-htmlize-output-type' to `css', calls to
1910 the function `org-export-htmlize-region-for-paste' will produce code
1911 that uses these same face definitions."
1912 (interactive)
1913 (require 'htmlize)
1914 (and (get-buffer "*html*") (kill-buffer "*html*"))
1915 (with-temp-buffer
1916 (let ((fl (face-list))
1917 (htmlize-css-name-prefix "org-")
1918 (htmlize-output-type 'css)
1919 f i)
1920 (while (setq f (pop fl)
1921 i (and f (face-attribute f :inherit)))
1922 (when (and (symbolp f) (or (not i) (not (listp i))))
1923 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1924 (htmlize-region (point-min) (point-max))))
1925 (switch-to-buffer "*html*")
1926 (goto-char (point-min))
1927 (if (re-search-forward "<style" nil t)
1928 (delete-region (point-min) (match-beginning 0)))
1929 (if (re-search-forward "</style>" nil t)
1930 (delete-region (1+ (match-end 0)) (point-max)))
1931 (beginning-of-line 1)
1932 (if (looking-at " +") (replace-match ""))
1933 (goto-char (point-min)))
1935 (defun org-html-protect (s)
1936 "Convert characters to HTML equivalent.
1937 Possible conversions are set in `org-export-html-protect-char-alist'."
1938 (let ((cl org-export-html-protect-char-alist) c)
1939 (while (setq c (pop cl))
1940 (let ((start 0))
1941 (while (string-match (car c) s start)
1942 (setq s (replace-match (cdr c) t t s)
1943 start (1+ (match-beginning 0))))))
1946 (defun org-html-expand (string)
1947 "Prepare STRING for HTML export. Apply all active conversions.
1948 If there are links in the string, don't modify these."
1949 (let* ((re (concat org-bracket-link-regexp "\\|"
1950 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1951 m s l res)
1952 (if (string-match "^[ \t]*\\+-[-+]*\\+[ \t]*$" string)
1953 string
1954 (while (setq m (string-match re string))
1955 (setq s (substring string 0 m)
1956 l (match-string 0 string)
1957 string (substring string (match-end 0)))
1958 (push (org-html-do-expand s) res)
1959 (push l res))
1960 (push (org-html-do-expand string) res)
1961 (apply 'concat (nreverse res)))))
1963 (defun org-html-do-expand (s)
1964 "Apply all active conversions to translate special ASCII to HTML."
1965 (setq s (org-html-protect s))
1966 (if org-export-html-expand
1967 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
1968 (setq s (replace-match "<\\1>" t nil s))))
1969 (if org-export-with-emphasize
1970 (setq s (org-export-html-convert-emphasize s)))
1971 (if org-export-with-special-strings
1972 (setq s (org-export-html-convert-special-strings s)))
1973 (if org-export-with-sub-superscripts
1974 (setq s (org-export-html-convert-sub-super s)))
1975 (if org-export-with-TeX-macros
1976 (let ((start 0) wd rep)
1977 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
1978 s start))
1979 (if (get-text-property (match-beginning 0) 'org-protected s)
1980 (setq start (match-end 0))
1981 (setq wd (match-string 1 s))
1982 (if (setq rep (org-entity-get-representation wd 'html))
1983 (setq s (replace-match rep t t s))
1984 (setq start (+ start (length wd))))))))
1987 (defun org-export-html-convert-special-strings (string)
1988 "Convert special characters in STRING to HTML."
1989 (let ((all org-export-html-special-string-regexps)
1990 e a re rpl start)
1991 (while (setq a (pop all))
1992 (setq re (car a) rpl (cdr a) start 0)
1993 (while (string-match re string start)
1994 (if (get-text-property (match-beginning 0) 'org-protected string)
1995 (setq start (match-end 0))
1996 (setq string (replace-match rpl t nil string)))))
1997 string))
1999 (defun org-export-html-convert-sub-super (string)
2000 "Convert sub- and superscripts in STRING to HTML."
2001 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2002 (while (string-match org-match-substring-regexp string s)
2003 (cond
2004 ((and requireb (match-end 8)) (setq s (match-end 2)))
2005 ((get-text-property (match-beginning 2) 'org-protected string)
2006 (setq s (match-end 2)))
2008 (setq s (match-end 1)
2009 key (if (string= (match-string 2 string) "_")
2010 'subscript 'superscript)
2011 c (or (match-string 8 string)
2012 (match-string 6 string)
2013 (match-string 5 string))
2014 string (replace-match
2015 (concat (match-string 1 string)
2016 (org-parse-format 'FONTIFY c key))
2017 t t string)))))
2018 (while (string-match "\\\\\\([_^]\\)" string)
2019 (setq string (replace-match (match-string 1 string) t t string)))
2020 string))
2022 (defconst org-html-emphasis-alist
2023 `(("*" bold)
2024 ("/" emphasis)
2025 ("_" underline)
2026 ("=" code)
2027 ("~" verbatim)
2028 ("+" strike)))
2030 (defun org-export-html-convert-emphasize (string)
2031 "Apply emphasis."
2032 (let ((s 0) rpl)
2033 (while (string-match org-emph-re string s)
2034 (if (not (equal
2035 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2036 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2037 (setq s (match-beginning 0)
2039 (concat
2040 (match-string 1 string)
2041 (org-parse-format
2042 'FONTIFY (match-string 4 string)
2043 (nth 1 (assoc (match-string 3 string)
2044 org-html-emphasis-alist)))
2045 (match-string 5 string))
2046 string (replace-match rpl t t string)
2047 s (+ s (- (length rpl) 2)))
2048 (setq s (1+ s))))
2049 string))
2051 (defvar body-only) ; dynamically scoped into this.
2052 (defun org-export-html-get-tag-class-name (tag)
2053 "Turn tag into a valid class name.
2054 Replaces invalid characters with \"_\" and then prepends a prefix."
2055 (save-match-data
2056 (while (string-match "[^a-zA-Z0-9_]" tag)
2057 (setq tag (replace-match "_" t t tag))))
2058 (concat org-export-html-tag-class-prefix tag))
2060 (defun org-export-html-get-todo-kwd-class-name (kwd)
2061 "Turn todo keyword into a valid class name.
2062 Replaces invalid characters with \"_\" and then prepends a prefix."
2063 (save-match-data
2064 (while (string-match "[^a-zA-Z0-9_]" kwd)
2065 (setq kwd (replace-match "_" t t kwd))))
2066 (concat org-export-html-todo-kwd-class-prefix kwd))
2068 (defun org-html-export-list-line (line pos struct prevs)
2069 "Insert list syntax in export buffer. Return LINE, maybe modified.
2071 POS is the item position or line position the line had before
2072 modifications to buffer. STRUCT is the list structure. PREVS is
2073 the alist of previous items."
2074 (let* ((get-type
2075 (function
2076 ;; Translate type of list containing POS to "d", "o" or
2077 ;; "u".
2078 (lambda (pos struct prevs)
2079 (let ((type (org-list-get-list-type pos struct prevs)))
2080 (cond
2081 ((eq 'ordered type) "o")
2082 ((eq 'descriptive type) "d")
2083 (t "u"))))))
2084 (get-closings
2085 (function
2086 ;; Return list of all items and sublists ending at POS, in
2087 ;; reverse order.
2088 (lambda (pos)
2089 (let (out)
2090 (catch 'exit
2091 (mapc (lambda (e)
2092 (let ((end (nth 6 e))
2093 (item (car e)))
2094 (cond
2095 ((= end pos) (push item out))
2096 ((>= item pos) (throw 'exit nil)))))
2097 struct))
2098 out)))))
2099 ;; First close any previous item, or list, ending at POS.
2100 (mapc (lambda (e)
2101 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2102 (first-item (org-list-get-list-begin e struct prevs))
2103 (type (funcall get-type first-item struct prevs)))
2104 (org-parse-end-paragraph)
2105 ;; Ending for every item
2106 (org-close-li type)
2107 ;; We're ending last item of the list: end list.
2108 (when lastp
2109 (org-parse-end 'LIST type)
2110 (org-parse-begin-paragraph))))
2111 (funcall get-closings pos))
2112 (cond
2113 ;; At an item: insert appropriate tags in export buffer.
2114 ((assq pos struct)
2115 (string-match
2116 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2117 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2118 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2119 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2120 "\\(.*\\)") line)
2121 (let* ((checkbox (match-string 3 line))
2122 (desc-tag (or (match-string 4 line) "???"))
2123 (body (or (match-string 5 line) ""))
2124 (list-beg (org-list-get-list-begin pos struct prevs))
2125 (firstp (= list-beg pos))
2126 ;; Always refer to first item to determine list type, in
2127 ;; case list is ill-formed.
2128 (type (funcall get-type list-beg struct prevs))
2129 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2130 (cond
2131 ((not count-tmp) nil)
2132 ((string-match "[A-Za-z]" count-tmp)
2133 (- (string-to-char (upcase count-tmp)) 64))
2134 ((string-match "[0-9]+" count-tmp)
2135 count-tmp)))))
2136 (when firstp
2137 (org-parse-end-paragraph)
2138 (org-parse-begin 'LIST type))
2140 (let ((arg (cond ((equal type "d") desc-tag)
2141 ((equal type "o") counter))))
2142 (org-parse-begin 'LIST-ITEM type arg))
2144 ;; If line had a checkbox, some additional modification is required.
2145 (when checkbox
2146 (setq body
2147 (concat
2148 (org-parse-format
2149 'FONTIFY (concat
2151 (cond
2152 ((string-match "X" checkbox) "X")
2153 ((string-match " " checkbox)
2154 (org-parse-format 'SPACES 1))
2155 (t "-"))
2156 "]")
2157 'code)
2159 body)))
2160 ;; Return modified line
2161 body))
2162 ;; At a list ender: go to next line (side-effects only).
2163 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2164 ;; Not at an item: return line unchanged (side-effects only).
2165 (t line))))
2167 ;; miscellaneous
2169 (defun org-html-bind-local-variables (opt-plist)
2170 (mapc (lambda (x)
2171 (set (make-local-variable (nth 2 x))
2172 (plist-get opt-plist (car x))))
2173 org-export-plist-vars))
2176 ;; This replaces org-emphasis-alist
2177 (defvar org-table-rowgroup-open)
2178 (defvar org-table-current-rowgroup-is-header)
2179 (defvar org-html-footnote-number)
2180 (defvar org-html-footnote-definitions)
2181 (defvar org-html-footnote-buffer)
2182 (defvar org-html-output-buffer)
2184 (defun org-html-end-export ()
2185 ;; insert the table of contents
2186 (when (and org-export-with-toc (not body-only) org-parse-table-of-contents)
2187 (org-html-insert-toc org-parse-table-of-contents))
2189 ;; remove empty paragraphs
2190 (goto-char (point-min))
2191 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2192 (replace-match ""))
2194 ;; Convert whitespace place holders
2195 (goto-char (point-min))
2196 (let (beg end n)
2197 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2198 (setq n (get-text-property beg 'org-whitespace)
2199 end (next-single-property-change beg 'org-whitespace))
2200 (goto-char beg)
2201 (delete-region beg end)
2202 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2203 (make-string n ?x)))))
2205 ;; Remove empty lines at the beginning of the file.
2206 (goto-char (point-min))
2207 (when (looking-at "\\s-+\n") (replace-match ""))
2209 ;; Remove display properties
2210 (remove-text-properties (point-min) (point-max) '(display t))
2212 ;; kill temporary buffers
2213 (when org-html-footnote-buffer
2214 (kill-buffer org-html-footnote-buffer))
2216 ;; Run the hook
2217 (run-hooks 'org-export-html-final-hook))
2220 ;;;_ org-parse.el
2221 ;;;_. preamble
2222 ;;;_ , user-specific
2223 ;;;_ . custom-settings
2224 (defcustom org-parse-debug nil
2226 :group 'org-parse
2227 :type 'boolean)
2232 ;;;_ , callbacks
2233 ;;;_ . control callbacks
2234 ;;;_ , generic
2235 (defun org-parse-begin (entity &rest args)
2236 (when (and (member org-parse-debug '(t control))
2237 (not (eq entity 'DOCUMENT-CONTENT)))
2238 (insert (org-parse-format 'COMMENT "%s BEGIN %S" entity args)))
2240 (let ((f (cadr (assoc entity org-parse-entity-control-callbacks-alist))))
2241 (unless f (error "Unknown entity: %s" entity))
2242 (apply f args)))
2244 (defun org-parse-end (entity &rest args)
2245 (when (and (member org-parse-debug '(t control))
2246 (not (eq entity 'DOCUMENT-CONTENT)))
2247 (insert (org-parse-format 'COMMENT "%s END %S" entity args)))
2249 (let ((f (caddr (assoc entity org-parse-entity-control-callbacks-alist))))
2250 (unless f (error "Unknown entity: %s" entity))
2251 (apply f args)))
2254 ;;;_ , paragraph
2255 (defun org-parse-begin-paragraph (&optional style)
2256 "Insert <p>, but first close previous paragraph if any."
2257 (org-parse-end-paragraph)
2258 (org-parse-begin 'PARAGRAPH style)
2259 (setq org-par-open t))
2261 (defun org-parse-end-paragraph ()
2262 "Close paragraph if there is one open."
2263 (when org-par-open
2264 (org-parse-end 'PARAGRAPH)
2265 (setq org-par-open nil)))
2267 ;;;_ , list
2268 (defun org-close-li (&optional type)
2269 "Close <li> if necessary."
2270 (org-parse-end-paragraph)
2271 (org-parse-end 'LIST-ITEM (or type "u")))
2274 ;;;_ , environment
2275 (defvar org-parse-dyn-current-environment nil)
2276 (defun org-parse-begin-environment (style)
2277 (assert (not org-parse-dyn-current-environment) t)
2278 (setq org-parse-dyn-current-environment style)
2279 (org-parse-begin 'ENVIRONMENT style))
2281 (defun org-parse-end-environment (style)
2282 (org-parse-end 'ENVIRONMENT style)
2284 (assert (eq org-parse-dyn-current-environment style) t)
2285 (setq org-parse-dyn-current-environment nil))
2287 (defun org-parse-current-environment-p (style)
2288 (eq org-parse-dyn-current-environment style))
2291 ;;;_ , footnote definition
2292 (defun org-parse-begin-footnote-definition (n)
2293 (unless org-html-footnote-buffer
2294 (setq org-html-footnote-buffer
2295 (get-buffer-create "*Org HTML Export Footnotes*")))
2296 (set-buffer org-html-footnote-buffer)
2297 (erase-buffer)
2298 (org-parse-begin 'FOOTNOTE-DEFINITION n))
2300 (defun org-parse-end-footnote-definition (n)
2301 (org-parse-end 'FOOTNOTE-DEFINITION n)
2302 (push (cons n (buffer-string)) org-html-footnote-definitions)
2303 (set-buffer org-html-output-buffer))
2308 ;;;_ . format callbacks
2309 ;;;_ , generic
2310 (defun org-parse-format (entity &rest args)
2311 (when (and (member org-parse-debug '(t format))
2312 (not (equal entity 'COMMENT)))
2313 (insert (org-parse-format 'COMMENT "%s: %S" entity args)))
2314 (cond
2315 ((consp entity)
2316 (let ((text (pop args)))
2317 (apply 'org-parse-format 'TAGS entity text args)))
2319 (let ((f (cdr (assoc entity org-parse-entity-format-callbacks-alist))))
2320 (unless f (error "Unknown entity: %s" entity))
2321 (apply f args)))))
2324 ;;;_ , toc (rename these routines)
2325 (defun org-html-format-toc-entry (snumber todo headline tags href)
2326 (setq headline (concat
2327 (and org-export-with-section-numbers
2328 (concat snumber " "))
2329 headline
2330 (and tags
2331 (concat
2332 (org-parse-format 'SPACES 3)
2333 (org-parse-format 'FONTIFY tags "tag")))))
2334 (when todo
2335 (setq headline (org-parse-format 'FONTIFY headline "todo")))
2336 (org-parse-format 'LINK headline (concat "#" href)))
2338 (defun org-html-format-toc-item (toc-entry level org-last-level)
2339 (when (> level org-last-level)
2340 (let ((cnt (- level org-last-level)))
2341 (while (>= (setq cnt (1- cnt)) 0)
2342 (org-parse-begin 'LIST 'unordered)
2343 (org-parse-begin 'LIST-ITEM 'unordered))))
2344 (when (< level org-last-level)
2345 (let ((cnt (- org-last-level level)))
2346 (while (>= (setq cnt (1- cnt)) 0)
2347 (org-close-li)
2348 (org-parse-end 'LIST 'unordered))))
2350 (org-close-li)
2351 (org-parse-begin 'LIST-ITEM 'unordered)
2352 (insert toc-entry))
2355 (defun org-html-begin-toc (lang-specific-heading)
2356 (org-parse-begin 'SECTION "table-of-contents")
2357 (insert
2358 (org-parse-format 'HEADING
2359 lang-specific-heading org-export-html-toplevel-hlevel))
2360 (org-parse-begin 'SECTION "text-table-of-contents")
2361 (org-parse-begin 'LIST 'unordered)
2362 (org-parse-begin 'LIST-ITEM 'unordered))
2364 (defun org-html-end-toc ()
2365 (while (> org-last-level (1- org-min-level))
2366 (setq org-last-level (1- org-last-level))
2367 (org-close-li)
2368 (org-parse-end 'LIST 'unordered))
2369 (org-parse-end 'SECTION)
2370 (org-parse-end 'SECTION)
2372 ;; cleanup empty list items in toc
2373 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
2374 (replace-match "")))
2376 (defun org-parse-prepare-toc (lines level-offset opt-plist umax-toc)
2377 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2378 (org-min-level (org-get-min-level lines level-offset))
2379 (org-last-level org-min-level)
2380 level)
2381 (with-temp-buffer
2382 (org-html-bind-local-variables opt-plist)
2383 (erase-buffer)
2384 (org-parse-begin 'TOC (nth 3 (plist-get opt-plist :lang-words)))
2385 (setq
2386 lines
2387 (mapcar
2388 '(lambda (line)
2389 (when (and (string-match org-todo-line-regexp line)
2390 (not (get-text-property 0 'org-protected line))
2391 (<= (setq level (org-tr-level
2392 (- (match-end 1) (match-beginning 1)
2393 level-offset)))
2394 umax-toc))
2395 (let ((txt (save-match-data
2396 (org-html-expand
2397 (org-export-cleanup-toc-line
2398 (match-string 3 line)))))
2399 (todo (and
2400 org-export-mark-todo-in-toc
2401 (or (and (match-beginning 2)
2402 (not (member (match-string 2 line)
2403 org-done-keywords)))
2404 (and (= level umax-toc)
2405 (org-search-todo-below
2406 line lines level)))))
2407 tags)
2408 ;; Check for targets
2409 (while (string-match org-any-target-regexp line)
2410 (setq line
2411 (replace-match
2412 (let ((org-html-protect t))
2413 (org-parse-format 'FONTIFY
2414 (match-string 1 line) "target"))
2415 t t line)))
2416 (when (string-match
2417 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2418 (setq txt (replace-match "" t nil txt)
2419 tags (match-string 1 txt)))
2420 (when (string-match quote-re0 txt)
2421 (setq txt (replace-match "" t t txt)))
2422 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2423 (setq txt (replace-match "" t t txt)))
2424 (org-parse-format
2425 'TOC-ITEM
2426 (let* ((snumber (org-section-number level))
2427 (href (replace-regexp-in-string
2428 "\\." "_" (format "sec-%s" snumber)))
2429 (href
2431 (cdr (assoc
2432 href org-export-preferred-target-alist))
2433 href))
2434 (href (org-solidify-link-text href)))
2435 (org-parse-format 'TOC-ENTRY snumber todo txt tags href))
2436 level org-last-level)
2437 (setq org-last-level level)))
2438 line)
2439 lines))
2440 (org-parse-end 'TOC)
2441 (setq org-parse-table-of-contents (buffer-string))))
2442 lines)
2445 ;;;_ , table row
2446 (defun org-parse-format-table-row (fields &optional text-for-empty-fields)
2447 (unless org-table-ncols
2448 ;; first row of the table
2449 (setq org-table-ncols (length fields))
2450 (when org-table-is-styled
2451 (setq org-table-num-numeric-items-per-column (make-vector org-table-ncols 0))
2452 (setq org-table-colalign-vector (make-vector org-table-ncols nil))
2453 (let ((c -1))
2454 (while (< (incf c) org-table-ncols)
2455 (let ((cookie (cdr (assoc (1+ c) org-table-colalign-info))))
2456 (setf (aref org-table-colalign-vector c)
2457 (cond
2458 ((string= cookie "l") "left")
2459 ((string= cookie "r") "right")
2460 ((string= cookie "c") "center")
2461 (t nil))))))))
2462 (incf org-table-rownum)
2464 (let ((i -1))
2465 (org-parse-format
2466 'TABLE-ROW
2467 (mapconcat
2468 (lambda (x)
2469 (when (string= x "")
2470 (setq x text-for-empty-fields))
2471 (incf i)
2472 (and org-table-is-styled
2473 (< i org-table-ncols)
2474 (string-match org-table-number-regexp x)
2475 (incf (aref org-table-num-numeric-items-per-column i)))
2476 (org-parse-format 'TABLE-CELL x org-table-rownum i))
2477 fields "\n"))))
2479 ;;;_ . get callback
2480 (defun org-parse-get (what &optional opt-plist)
2481 (funcall org-parse-get-callback what opt-plist))
2483 ;;;_. postamble
2486 ;;;_ org-newhtml.el
2487 ;;;_. preamble
2488 ;;;_. obsolete
2489 ;;;_. maybe
2490 ;;;_. hacks (to be documented)
2492 ;; Refer `org-html-emphasis-alist'
2494 ;;;_. user-specific
2495 ;;;_ , custom settings
2496 ;;;_ . potential custom settings
2497 ;;;_ , interactive commands
2498 ;;;_. parser
2499 ;;;_ , initialization
2500 (defvar org-html-entity-control-callbacks-alist
2501 `((EXPORT
2502 . (org-html-begin-export org-html-end-export))
2503 (DOCUMENT-CONTENT
2504 . (org-html-begin-document-content org-html-end-document-content))
2505 (DOCUMENT-BODY
2506 . (org-html-begin-document-body org-html-end-document-body))
2507 (TOC
2508 . (org-html-begin-toc org-html-end-toc))
2509 (ENVIRONMENT
2510 . (org-html-begin-environment org-html-end-environment))
2511 (LEVEL
2512 . (org-html-begin-level org-html-end-level))
2513 (FOOTNOTE-DEFINITION
2514 . (org-html-begin-footnote-definition org-html-end-footnote-definition))
2515 (TABLE
2516 . (org-html-begin-table org-html-end-table))
2517 (TABLE-ROWGROUP
2518 . (org-html-begin-table-rowgroup org-html-end-table-rowgroup))
2519 (LIST
2520 . (org-html-begin-list org-html-end-list))
2521 (LIST-ITEM
2522 . (org-html-begin-list-item org-html-end-list-item))
2523 (SECTION
2524 . (org-html-begin-section org-html-end-section))
2525 (PARAGRAPH
2526 . (org-html-begin-paragraph org-html-end-paragraph)))
2529 (defvar org-html-entity-format-callbacks-alist
2530 `((EXTRA-TARGETS . org-html-format-extra-targets)
2531 (ORG-TAGS . org-html-format-org-tags)
2532 (SECTION-NUMBER . org-html-format-section-number)
2533 (HEADLINE . org-html-format-headline)
2534 (TOC-ENTRY . org-html-format-toc-entry)
2535 (TOC-ITEM . org-html-format-toc-item)
2536 (TAGS . org-html-format-tags)
2537 (SPACES . org-html-format-spaces)
2538 (TABS . org-html-format-tabs)
2539 (LINE-BREAK . org-html-format-line-break)
2540 (FONTIFY . org-html-format-fontify)
2541 (TODO . org-html-format-todo)
2542 (ORG-LINK . org-html-format-org-link)
2543 (LINK . org-html-format-link)
2544 (INLINE-IMAGE . org-html-format-inline-image)
2545 (HEADING . org-html-format-heading)
2546 (ANCHOR . org-html-format-anchor)
2547 (TABLE-ROW . org-html-format-table-row)
2548 (TABLE-CELL . org-html-format-table-cell)
2549 (FOOTNOTES-SECTION . org-html-format-footnotes-section)
2550 (FOOTNOTE-REFERENCE . org-html-format-footnote-reference)
2551 (HORIZONTAL-LINE . org-html-format-horizontal-line)
2552 (PLAIN . org-html-format-plain)
2553 (COMMENT . org-html-format-comment))
2558 ;;;_ , callbacks
2559 ;;;_ . control callbacks
2560 ;;;_ , generic
2561 (defvar org-html-insert-tag-with-newlines 'both)
2563 (defun org-html-insert-tag (tag &rest args)
2564 (when (member org-html-insert-tag-with-newlines '(lead both))
2565 (insert "\n"))
2566 (insert (apply 'format tag args))
2567 (when (member org-html-insert-tag-with-newlines '(trail both))
2568 (insert "\n")))
2570 ;;;_ , document body
2571 (defun org-html-begin-document-body (opt-plist)
2572 (let ((link-up (and (plist-get opt-plist :link-up)
2573 (string-match "\\S-" (plist-get opt-plist :link-up))
2574 (plist-get opt-plist :link-up)))
2575 (link-home (and (plist-get opt-plist :link-home)
2576 (string-match "\\S-" (plist-get opt-plist :link-home))
2577 (plist-get opt-plist :link-home))))
2578 (insert "\n<body>")
2579 (org-parse-begin 'SECTION "content")
2580 (insert "\n"
2581 (or (and (or link-up link-home)
2582 (format org-export-html-home/up-format
2583 (or link-up link-home)
2584 (or link-home link-up))) "")
2585 "\n"))
2586 (org-html-insert-preamble opt-plist))
2588 (defun org-html-end-document-body (opt-plist)
2589 (org-html-insert-postamble opt-plist)
2590 (unless body-only
2591 (org-parse-end 'SECTION)
2592 (insert "\n</body>")))
2595 ;;;_ , document content
2596 (defun org-html-begin-document-content (opt-plist)
2597 (let* ((language (plist-get opt-plist :language))
2598 (charset (or (and coding-system-for-write
2599 (fboundp 'coding-system-get)
2600 (coding-system-get coding-system-for-write
2601 'mime-charset))
2602 "iso-8859-1"))
2603 (style (concat (if (plist-get opt-plist :style-include-default)
2604 org-export-html-style-default)
2605 (plist-get opt-plist :style)
2606 (plist-get opt-plist :style-extra)
2607 "\n"
2608 (if (plist-get opt-plist :style-include-scripts)
2609 org-export-html-scripts)))
2610 (mathjax
2611 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
2612 (and org-export-have-math
2613 (eq (plist-get opt-plist :LaTeX-fragments) t)))
2615 (org-export-html-mathjax-config
2616 org-export-html-mathjax-template
2617 org-export-html-mathjax-options
2618 (or (plist-get opt-plist :mathjax) "")) "")))
2619 (insert (format
2621 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2622 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2623 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2624 lang=\"%s\" xml:lang=\"%s\">
2625 <head>
2626 <title>%s</title>
2627 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2628 <meta name=\"generator\" content=\"Org-mode\"/>
2629 <meta name=\"generated\" content=\"%s\"/>
2630 <meta name=\"author\" content=\"%s\"/>
2631 <meta name=\"description\" content=\"%s\"/>
2632 <meta name=\"keywords\" content=\"%s\"/>
2635 </head>
2637 (format
2638 (or (and (stringp org-export-html-xml-declaration)
2639 org-export-html-xml-declaration)
2640 (cdr (assoc (plist-get opt-plist :html-extension)
2641 org-export-html-xml-declaration))
2642 (cdr (assoc "html" org-export-html-xml-declaration))
2645 charset)
2646 language language
2647 (plist-get opt-plist :title)
2648 charset
2649 (plist-get opt-plist :effective-date)
2650 (plist-get opt-plist :author)
2651 (plist-get opt-plist :description)
2652 (plist-get opt-plist :keywords)
2653 style
2654 mathjax))))
2656 (defun org-html-end-document-content ()
2657 (insert "\n</html>\n"))
2660 ;;;_ , level
2661 (defun org-html-begin-level (level title umax with-toc head-count)
2662 "Insert a new level in HTML export.
2663 When TITLE is nil, just close all open levels."
2664 (org-parse-end 'LEVEL level umax)
2665 (unless title (error "Why is heading nil"))
2666 (let* ((target (org-get-text-property-any 0 'target title))
2667 (extra-targets (and target
2668 (assoc target org-export-target-aliases)))
2669 (extra-class (org-get-text-property-any 0 'html-container-class title))
2670 (preferred (and target
2671 (cdr (assoc target org-export-preferred-target-alist))))
2672 snumber snu href suffix tags level1)
2673 (setq extra-targets (remove (or preferred target) extra-targets))
2674 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2675 (setq tags (and org-export-with-tags (match-string 1 title)))
2676 (setq title (replace-match "" t t title)))
2677 (if (> level umax)
2678 (progn
2679 (if (aref org-levels-open (1- level))
2680 (org-close-li)
2681 (aset org-levels-open (1- level) t)
2682 (org-parse-end-paragraph)
2683 (org-parse-begin 'LIST 'unordered))
2684 (org-parse-begin
2685 'LIST-ITEM 'unordered (and target (org-solidify-link-text
2686 (or preferred target))))
2687 (insert
2688 (org-parse-format 'HEADLINE title extra-targets tags)
2689 (org-parse-format 'LINE-BREAK) "\n"))
2690 (aset org-levels-open (1- level) t)
2691 (setq snumber (org-section-number level)
2692 snu (replace-regexp-in-string "\\." "_" snumber))
2693 (setq level1 (+ level org-export-html-toplevel-hlevel -1))
2694 (unless (= head-count 1)
2695 (org-parse-end 'SECTION))
2696 (setq href (cdr (assoc (concat "sec-" snu)
2697 org-export-preferred-target-alist)))
2698 (setq suffix (org-solidify-link-text (or href snu)))
2699 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2700 (let ((id (format "outline-container-%s" suffix))
2701 (class (format "outline-%d" level1)))
2702 (org-parse-begin 'SECTION id class extra-class))
2703 (insert
2704 (org-parse-format 'HEADING
2705 (org-parse-format
2706 'HEADLINE title extra-targets tags snumber level1)
2707 level1 href))
2708 (let ((id (format "text-%s" suffix))
2709 (class (format "outline-text-%d" level1)))
2710 (org-parse-begin 'SECTION id class))
2712 (org-parse-begin-paragraph))))
2714 (defun org-html-end-level (level umax)
2715 (org-parse-end-paragraph)
2716 (let* ((l org-level-max))
2717 (while (>= l level)
2718 (if (aref org-levels-open (1- l))
2719 (progn
2720 ;; Terminate one level in HTML export
2721 (if (<= l umax)
2722 (org-parse-end 'SECTION)
2723 (org-close-li)
2724 (org-parse-end 'LIST 'unordered))
2725 (aset org-levels-open (1- l) nil)))
2726 (setq l (1- l)))))
2729 ;;;_ , section
2730 (defun org-html-begin-section (&optional id class extra-class)
2731 (when extra-class
2732 (setq class (concat class " " extra-class)))
2733 (let ((extra (concat (when id (format " id=\"%s\"" id))
2734 (when class (format " class=\"%s\"" class)))))
2735 (org-html-insert-tag "<div%s>" extra)))
2737 (defun org-html-end-section ()
2738 (org-html-insert-tag "</div>"))
2742 ;;;_ , paragraph
2743 (defun org-html-begin-paragraph (&optional style)
2744 (let* ((class (cdr (assoc style '((footnote . "footnote")
2745 (verse . nil)))))
2746 (extra (if class (format " class=\"%s\"" class) "")))
2747 (org-html-insert-tag "<p%s>" extra)))
2749 (defun org-html-end-paragraph ()
2750 (insert "</p>"))
2753 ;;;_ , environment
2754 (defun org-html-format-environment (style beg-end)
2755 (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
2756 (case style
2757 (blockquote
2758 (case beg-end
2759 (BEGIN
2760 (org-parse-end-paragraph)
2761 (insert "<blockquote>\n")
2762 (org-parse-begin-paragraph))
2763 (END
2764 (org-parse-end-paragraph)
2765 (insert "\n</blockquote>\n")
2766 (org-parse-begin-paragraph))))
2767 (verse
2768 (case beg-end
2769 (BEGIN
2770 (org-parse-end-paragraph)
2771 (insert "\n<p class=\"verse\">\n")
2772 (setq org-par-open t))
2773 (END
2774 (insert "</p>\n")
2775 (setq org-par-open nil)
2776 (org-parse-begin-paragraph))))
2777 (center
2778 (case beg-end
2779 (BEGIN
2780 (org-parse-end-paragraph)
2781 (insert "\n<div style=\"text-align: center\">")
2782 (org-parse-begin-paragraph))
2783 (END
2784 (org-parse-end-paragraph)
2785 (insert "\n</div>")
2786 (org-parse-begin-paragraph))))
2787 (fixedwidth
2788 (case beg-end
2789 (BEGIN
2790 (org-parse-end-paragraph)
2791 (insert "<pre class=\"example\">\n"))
2792 (END
2793 (insert "</pre>\n")
2794 (org-parse-begin-paragraph))))
2795 (quote
2796 (case beg-end
2797 (BEGIN
2798 (org-parse-end-paragraph)
2799 (insert "<pre>"))
2800 (END
2801 (insert "</pre>\n")
2802 (org-parse-begin-paragraph))))
2803 (native
2804 (case beg-end
2805 (BEGIN (org-parse-end-paragraph))
2806 (END (org-parse-begin-paragraph))))
2807 (t (error "Unknown environment %s" style))))
2810 (defun org-html-begin-environment (style)
2811 (org-html-format-environment style 'BEGIN))
2813 (defun org-html-end-environment (style)
2814 (org-html-format-environment style 'END))
2817 ;;;_ , list
2818 (defun org-html-html-list-type-to-canonical-list-type (ltype)
2819 (cdr (assoc ltype '(("o" . ordered)
2820 ("u" . unordered)
2821 ("d" . description)))))
2823 (defun org-html-begin-list (ltype &optional arg1)
2824 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2825 ltype))
2827 (case ltype
2828 (ordered (let ((extra (if arg1 (format " start=\"%d\"" arg1) "")))
2829 (org-html-insert-tag "<ol%s>" extra)))
2830 (unordered (org-html-insert-tag "<ul>"))
2831 (description (org-html-insert-tag "<dl>"))
2832 (t (error "Unknown list type: %s" ltype))))
2834 (defun org-html-end-list (ltype)
2835 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2836 ltype))
2838 (org-html-insert-tag
2839 (case ltype
2840 (ordered "</ol>")
2841 (unordered "</ul>")
2842 (description "</dl>")
2843 (t (error "Unknown list type: %s" ltype)))))
2845 (defun org-html-begin-list-item (ltype &optional arg)
2846 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2847 ltype))
2848 (case ltype
2849 (ordered
2850 (let* ((counter arg)
2851 (extra (if counter (format " value=\"%s\"" counter) "")))
2852 (org-html-insert-tag "<li%s>" extra)))
2853 (unordered
2854 (let* ((id arg)
2855 (extra (if id (format " id=\"%s\"" id) "")))
2856 (org-html-insert-tag "<li%s>" extra)))
2857 (description
2858 (let* ((desc-tag (or arg "(no term)")))
2859 (insert
2860 (org-html-format-tags '("<dt>" . "</dt>") desc-tag))
2861 (org-html-insert-tag "<dd>")))
2862 (t (error "Unknown list type"))))
2864 (defun org-html-end-list-item (ltype)
2865 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2866 ltype))
2867 (case ltype
2868 (ordered (org-html-insert-tag "</li>"))
2869 (unordered (org-html-insert-tag "</li>"))
2870 (description (org-html-insert-tag "</dd>"))
2871 (t (error "Unknown list type"))))
2874 ;;;_ , table
2876 (defvar org-table-rowgroup-info)
2877 (defun org-parse-begin-table-rowgroup (&optional is-header-row)
2878 (push (cons (1+ org-table-rownum) :start) org-table-rowgroup-info)
2879 (org-parse-begin 'TABLE-ROWGROUP is-header-row))
2881 (defun org-html-begin-table-rowgroup (&optional is-header-row)
2882 (when org-table-rowgroup-open
2883 (org-parse-end 'TABLE-ROWGROUP))
2884 (org-html-insert-tag (if is-header-row "<thead>" "<tbody>"))
2885 (setq org-table-rowgroup-open t)
2886 (setq org-table-current-rowgroup-is-header is-header-row))
2888 (defun org-html-end-table-rowgroup ()
2889 (when org-table-rowgroup-open
2890 (setq org-table-rowgroup-open nil)
2891 (org-html-insert-tag
2892 (if org-table-current-rowgroup-is-header "</thead>" "</tbody>"))))
2894 (defun org-html-begin-table (caption label attributes)
2895 (let ((html-table-tag
2896 (org-export-splice-attributes html-table-tag attributes)))
2897 (when label
2898 (setq html-table-tag
2899 (org-export-splice-attributes
2900 html-table-tag
2901 (format "id=\"%s\"" (org-solidify-link-text label)))))
2902 (org-html-insert-tag html-table-tag))
2904 ;; Since the output of HTML table formatter can also be used in
2905 ;; DocBook document, we want to always include the caption to make
2906 ;; DocBook XML file valid.
2907 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
2909 (defun org-parse-end-table ()
2910 (when org-table-is-styled
2911 ;; column groups
2912 (unless (car org-table-colgroup-info)
2913 (setq org-table-colgroup-info
2914 (cons :start (cdr org-table-colgroup-info))))
2916 ;; column alignment
2917 (let ((c -1))
2918 (mapc
2919 (lambda (x)
2920 (incf c)
2921 (setf (aref org-table-colalign-vector c)
2922 (or (aref org-table-colalign-vector c)
2923 (if (> (/ (float x) (1+ org-table-rownum))
2924 org-table-number-fraction)
2925 "right" "left"))))
2926 org-table-num-numeric-items-per-column)))
2927 (org-parse-end 'TABLE))
2929 (defun org-html-end-table ()
2930 (when org-table-is-styled
2931 (goto-char org-table-begin-marker)
2932 (setq org-table-begin-marker nil)
2934 (let ((c -1) gr colgropen)
2935 (insert
2936 (mapconcat
2937 (lambda (x)
2938 (incf c)
2939 (setq gr (pop org-table-colgroup-info))
2941 (concat
2942 (if (memq gr '(:start :startend))
2943 (prog1
2944 (if colgropen
2945 "</colgroup>\n<colgroup>"
2946 "<colgroup>")
2947 (setq colgropen t))
2950 (let* ((align (aref org-table-colalign-vector c))
2951 (alignspec (if no-css " align=\"%s\"" " class=\"%s\""))
2952 (extra (format alignspec align)))
2953 (format "<col%s />" extra))
2955 (if (memq gr '(:end :startend))
2956 (progn (setq colgropen nil) "</colgroup>")
2957 "")))
2958 org-table-num-numeric-items-per-column ""))
2960 (if colgropen (insert "</colgroup>")))
2962 ;; fill style attributes for table cells
2963 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
2964 (let ((c (string-to-number (match-string 1))))
2965 (replace-match
2966 (if org-export-html-table-align-individual-fields
2967 (format (if no-css " align=\"%s\"" " class=\"%s\"")
2968 (or (aref org-table-colalign-vector c) "left")) "")
2969 t t)))
2970 (goto-char (point-max)))
2971 (org-html-insert-tag "</table>\n"))
2973 (defun org-html-format-table-row (row)
2974 (org-html-format-tags
2975 (cons (eval (car org-export-table-row-tags))
2976 (eval (cdr org-export-table-row-tags))) row))
2978 (defun org-html-format-table-cell (text r c)
2979 (let ((cell-style-cookie (or (and org-table-is-styled
2980 (format "@@class%03d@@" c)) "")))
2981 (cond
2982 (org-table-current-rowgroup-is-header
2983 (org-html-format-tags
2984 org-export-table-header-tags text "col" cell-style-cookie))
2985 ((and (= c 0) org-export-html-table-use-header-tags-for-first-column)
2986 (org-html-format-tags
2987 org-export-table-header-tags text "row" cell-style-cookie))
2989 (org-html-format-tags
2990 org-export-table-data-tags text cell-style-cookie)))))
2993 ;;;_ , footnote definition
2994 (defun org-html-begin-footnote-definition (n)
2995 (org-parse-begin-paragraph 'footnote)
2996 (insert
2997 (format
2998 (format org-export-html-footnote-format
2999 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
3000 n n n)))
3002 (defun org-html-end-footnote-definition (n)
3003 (org-parse-end-paragraph))
3007 ;;;_ . format callbacks
3009 (defvar org-html-protect nil)
3010 ;;;_ , spaces
3011 (defun org-html-format-spaces (n)
3012 (let ((space (or (and org-html-protect "\\nbsp") "&nbsp;")) out)
3013 (while (> n 0)
3014 (setq out (concat out space))
3015 (setq n (1- n))) out))
3017 ;;;_ , tabs
3018 (defun org-html-format-tabs (&optional n)
3019 (ignore))
3021 ;;;_ , line break
3022 (defun org-html-format-line-break ()
3023 (org-html-format-tags '("<br>" . "</br>") ""))
3025 ;;;_ , horizontal line
3026 (defun org-html-format-horizontal-line ()
3027 (concat "\n" "<hr/>" "\n"))
3029 ;;;_ , line
3031 (defun org-html-format-plain (line)
3032 (case org-parse-dyn-current-environment
3033 ((quote fixedwidth) (concat (org-html-protect line) "\n"))
3034 (t (concat line "\n"))))
3036 (defun org-html-format-comment (fmt &rest args)
3037 (let ((comment (apply 'format fmt args)))
3038 (format "\n<!-- %s -->\n" comment)))
3041 ;;;_ , character styles
3042 (defun org-html-format-fontify (text style &optional id)
3043 (let (class extra how)
3044 (cond
3045 ((eq style 'underline)
3046 (setq extra " style=\"text-decoration:underline;\"" ))
3047 ((setq how (cdr (assoc style
3048 '((bold . ("<b>" . "</b>"))
3049 (emphasis . ("<i>" . "</i>"))
3050 (code . ("<code>" . "</code>"))
3051 (verbatim . ("<code>" . "</code>"))
3052 (strike . ("<del>" . "</del>"))
3053 (subscript . ("<sub>" . "</sub>"))
3054 (superscript . ("<sup>" . "</sup>")))))))
3055 ((listp style)
3056 (setq class (mapconcat 'identity style " ")))
3057 ((stringp style)
3058 (setq class style))
3059 (t (error "Unknown style %S" style)))
3061 (setq extra (concat (when class (format " class=\"%s\"" class))
3062 (when id (format " id=\"%s\"" id))
3063 extra))
3064 (org-html-format-tags
3065 (or how '("<span%s>" . "</span>")) text extra)))
3067 ;;;_ , link
3068 (defun org-html-format-link (text href &optional extra)
3069 (let* ((extra (concat (format " href=\"%s\"" href) extra)))
3070 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
3072 ;;;_ , heading
3073 (defun org-html-format-heading (text level &optional id class)
3074 (let* ((extra (concat
3075 (when id (format " id=\"%s\"" id))
3076 (when class (format " class=\"%s\"" class)))))
3077 ;; (org-html-format-tags
3078 ;; text '("<h%d%s>" . "</h%d>") level extra)
3080 ;; Also look at org-export-html-preamble-format
3081 (concat
3082 (format "<h%d%s>" level extra) text (format "</h%d>" level))))
3084 ;;;_ , headline
3085 (defun org-html-format-headline (title extra-targets tags
3086 &optional snumber level)
3087 (concat
3088 (org-parse-format 'EXTRA-TARGETS extra-targets)
3089 (concat (org-parse-format 'SECTION-NUMBER snumber level) " ")
3090 title
3091 (and tags (concat (org-parse-format 'SPACES 3)
3092 (org-parse-format 'ORG-TAGS tags)))))
3094 ;;;_ , anchor
3095 (defun org-html-format-anchor (text name &optional class)
3096 (let* ((id name)
3097 (extra (concat
3098 (when name (format " name=\"%s\"" name))
3099 (when id (format " id=\"%s\"" id))
3100 (when class (format " class=\"%s\"" class)))))
3101 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
3105 ;;;_ , target
3106 ;;;_ , footnote reference
3107 (defun org-html-format-footnote-reference (n def refcnt)
3108 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
3109 (format org-export-html-footnote-format
3110 (format
3111 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
3112 n extra n n))))
3116 ;;;_ , footnotes section
3117 (defun org-html-format-footnotes-section (section-name definitions)
3118 (if (not definitions) ""
3119 (format org-export-html-footnotes-section section-name definitions)))
3122 ;;;_ , image
3123 ;;;_ , generic
3124 (defun org-html-format-tags (tag text &rest args)
3125 (let ((prefix (when org-html-protect "@"))
3126 (suffix (when org-html-protect "@")))
3127 (concat prefix (apply 'format (car tag) args)
3128 text
3129 suffix (format (cdr tag)))))
3132 ;;;_ . maintenance callbacks
3133 ;;;_ , init method
3134 ;;;_ , save method
3135 ;;;_ , cleanup method
3136 ;;;_ . get callback
3137 (defun org-html-get (what &optional opt-plist)
3138 (case what
3139 (BACKEND 'html)
3140 (INIT-METHOD nil)
3141 (SAVE-METHOD nil)
3142 (CLEANUP-METHOD nil)
3143 (EXPORT-DIR (org-export-directory :html opt-plist))
3144 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
3145 (EXPORT-BUFFER-NAME "*Org HTML Export*")
3146 (ENTITY-CONTROL org-html-entity-control-callbacks-alist)
3147 (ENTITY-FORMAT org-html-entity-format-callbacks-alist)
3148 (t (error "Unknown property: %s" what))))
3151 ;;;_ , coding system
3152 (defun org-html-get-coding-system-for-write ()
3153 (or org-export-html-coding-system
3154 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3156 (defun org-html-get-coding-system-for-save ()
3157 (or org-export-html-coding-system
3158 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3161 ;;;_. newhtml (non-parser & misc)
3162 (defun org-html-insert-toc (toc)
3163 ;; locate where toc needs to be inserted
3164 (goto-char (point-min))
3165 (if (or (re-search-forward
3166 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3167 (re-search-forward
3168 "\\[TABLE-OF-CONTENTS\\]" nil t))
3169 (progn
3170 (goto-char (match-beginning 0))
3171 (replace-match ""))
3172 (goto-char org-html-dyn-first-heading-pos)
3173 (when (looking-at "\\s-*</p>")
3174 (goto-char (match-end 0))
3175 (insert "\n")))
3176 (insert toc))
3178 (defun org-html-insert-preamble (opt-plist)
3179 (when (plist-get opt-plist :html-preamble)
3180 (let ((html-pre (plist-get opt-plist :html-preamble))
3181 (title (plist-get opt-plist :title))
3182 (date (plist-get opt-plist :effective-date))
3183 (author (plist-get opt-plist :author))
3184 (lang-words (plist-get opt-plist :lang-words))
3185 (email (plist-get opt-plist :email)))
3186 (cond ((stringp html-pre)
3187 (insert
3188 (format-spec html-pre `((?t . ,title) (?a . ,author)
3189 (?d . ,date) (?e . ,email)))))
3190 ((functionp html-pre)
3191 (funcall html-pre opt-plist))
3193 (insert
3194 (format-spec
3195 (or (cadr (assoc (nth 0 lang-words)
3196 org-export-html-preamble-format))
3197 (cadr (assoc "en" org-export-html-preamble-format)))
3198 `((?t . ,title) (?a . ,author)
3199 (?d . ,date) (?e . ,email)))))))))
3201 (defun org-html-insert-postamble (opt-plist)
3202 (when org-html-footnote-definitions
3203 (insert
3204 (org-parse-format
3205 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
3206 (mapconcat (lambda (x) (cdr x))
3207 (nreverse org-html-footnote-definitions) "\n"))))
3208 (let ((bib (org-export-html-get-bibliography)))
3209 (when bib
3210 (insert "\n" bib "\n")))
3212 ;; export html postamble
3213 (unless body-only
3214 (let* ((html-post (plist-get opt-plist :html-postamble))
3215 (date (plist-get opt-plist :effective-date))
3216 (author (plist-get opt-plist :author))
3217 (email (plist-get opt-plist :email))
3218 (lang-words (plist-get opt-plist :lang-words))
3219 (html-validation-link (or org-export-html-validation-link ""))
3220 (email
3221 (mapconcat (lambda(e)
3222 (format "<a href=\"mailto:%s\">%s</a>" e e))
3223 (split-string email ",+ *")
3224 ", "))
3225 (creator-info
3226 (concat "Org version " org-version " with Emacs version "
3227 (number-to-string emacs-major-version))))
3228 (when (plist-get opt-plist :html-postamble)
3229 (cond ((stringp html-post)
3230 (insert "<div id=\"postamble\">\n")
3231 (insert (format-spec html-post
3232 `((?a . ,author) (?e . ,email)
3233 (?d . ,date) (?c . ,creator-info)
3234 (?v . ,html-validation-link))))
3235 (insert "</div>"))
3236 ((functionp html-post)
3237 (funcall html-post opt-plist))
3238 ((eq html-post 'auto)
3239 ;; fall back on default postamble
3240 (insert "<div id=\"postamble\">\n")
3241 (when (plist-get opt-plist :time-stamp-file)
3242 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
3243 (when (and (plist-get opt-plist :author-info) author)
3244 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
3245 (when (and (plist-get opt-plist :email-info) email)
3246 (insert "<p class=\"email\">" email "</p>\n"))
3247 (when (plist-get opt-plist :creator-info)
3248 (insert "<p class=\"creator\">"
3249 (concat "Org version " org-version " with Emacs version "
3250 (number-to-string emacs-major-version) "</p>\n")))
3251 (insert html-validation-link "\n</div>"))
3253 (insert "<div id=\"postamble\">\n")
3254 (insert (format-spec
3255 (or (cadr (assoc (nth 0 lang-words)
3256 org-export-html-postamble-format))
3257 (cadr (assoc "en" org-export-html-postamble-format)))
3258 `((?a . ,author) (?e . ,email)
3259 (?d . ,date) (?c . ,creator-info)
3260 (?v . ,html-validation-link))))
3261 (insert "</div>"))))))
3263 (if org-export-html-with-timestamp
3264 (insert org-export-html-html-helper-timestamp)))
3267 (defun org-html-format-todo (todo)
3268 (org-parse-format 'FONTIFY
3269 (org-export-html-get-todo-kwd-class-name todo)
3270 (list (if (member todo org-done-keywords) "done" "todo")
3271 todo)))
3275 (defun org-html-format-extra-targets (extra-targets)
3276 (if (not extra-targets) ""
3277 (mapconcat (lambda (x)
3278 (setq x (org-solidify-link-text
3279 (if (org-uuidgen-p x) (concat "ID-" x) x)))
3280 (org-parse-format 'ANCHOR "" x))
3281 extra-targets "")))
3283 (defun org-html-format-org-tags (tags)
3284 (if (not tags) ""
3285 (org-parse-format
3286 'FONTIFY (mapconcat
3287 (lambda (x)
3288 (org-parse-format
3289 'FONTIFY x (org-export-html-get-tag-class-name x)))
3290 (org-split-string tags ":")
3291 (org-parse-format 'SPACES 1)) "tag")))
3293 (defun org-html-format-section-number (&optional snumber level)
3294 (and org-export-with-section-numbers
3295 (not body-only) snumber level
3296 (org-parse-format 'FONTIFY snumber (format "section-number-%d" level))))
3298 ;;;_. preprocessor
3299 ;;;_. postamble
3301 (provide 'org-html)
3303 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
3304 ;;; org-html.el ends here