org-html.el: Handle org-table-export and org-export-as-docbook.
[org-mode/org-jambu.git] / lisp / org-html.el
blobe4891eb0125567951e215e4231c403008bd83d19
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."
789 (declare (special org-par-open))
790 (when (string= type-1 "coderef")
791 (setq attr
792 (format "class=\"coderef\" onmouseover=\"CodeHighlightOn(this, '%s');\" onmouseout=\"CodeHighlightOff(this, '%s');\""
793 fragment fragment)))
794 (save-match-data
795 (let* ((may-inline-p
796 (and (member type-1 '("http" "https" "file"))
797 (org-html-should-inline-p path descp)
798 (not fragment)))
799 (type (if (equal type-1 "id") "file" type-1))
800 (filename path)
801 ;;First pass. Just sanity stuff.
802 (components-1
803 (cond
804 ((string= type "file")
805 (list
806 type
807 ;;Substitute just if original path was absolute.
808 ;;(Otherwise path must remain relative)
809 (if (file-name-absolute-p path)
810 (concat "file://" (expand-file-name path))
811 path)))
812 ((string= type "")
813 (list nil path))
814 (t (list type path))))
816 ;;Second pass. Components converted so they can refer
817 ;;to a remote site.
818 (components-2
820 (and org-html-cvt-link-fn
821 (apply org-html-cvt-link-fn
822 opt-plist components-1))
823 (apply #'org-html-cvt-org-as-html
824 opt-plist components-1)
825 components-1))
826 (type (first components-2))
827 (thefile (second components-2)))
830 ;;Third pass. Build final link except for leading type
831 ;;spec.
832 (cond
833 ((or
834 (not type)
835 (string= type "http")
836 (string= type "https")
837 (string= type "file")
838 (string= type "coderef"))
839 (if fragment
840 (setq thefile (concat thefile "#" fragment))))
842 (t))
844 ;;Final URL-build, for all types.
845 (setq thefile
846 (let
847 ((str (org-export-html-format-href thefile)))
848 (if (and type (not (or (string= "file" type)
849 (string= "coderef" type))))
850 (concat type ":" str)
851 str)))
853 (if may-inline-p
854 (org-export-html-format-image thefile)
855 (org-parse-format
856 'LINK (org-export-html-format-desc desc) thefile attr)))))
858 (defun org-html-format-inline-image (desc)
859 ;; FIXME: alt text missing here?
860 (org-html-format-tags "<img src=\"%s\" alt=\"\"/>" "" desc))
862 (defvar org-parse-link-description-is-image)
863 (defun org-parse-format-org-link (line opt-plist)
864 "Return LINE with markup of Org mode links.
865 OPT-PLIST is the export options list."
866 (let ((start 0)
867 (current-dir (if buffer-file-name
868 (file-name-directory buffer-file-name)
869 default-directory))
870 (link-validate (plist-get opt-plist :link-validation-function))
871 type id-file fnc
872 rpl path attr desc descp desc1 desc2 link
873 org-parse-link-description-is-image)
874 (while (string-match org-bracket-link-analytic-regexp++ line start)
875 (setq org-parse-link-description-is-image nil)
876 (setq start (match-beginning 0))
877 (setq path (save-match-data (org-link-unescape
878 (match-string 3 line))))
879 (setq type (cond
880 ((match-end 2) (match-string 2 line))
881 ((save-match-data
882 (or (file-name-absolute-p path)
883 (string-match "^\\.\\.?/" path)))
884 "file")
885 (t "internal")))
886 (setq path (org-extract-attributes (org-link-unescape path)))
887 (setq attr (get-text-property 0 'org-attributes path))
888 (setq desc1 (if (match-end 5) (match-string 5 line))
889 desc2 (if (match-end 2) (concat type ":" path) path)
890 descp (and desc1 (not (equal desc1 desc2)))
891 desc (or desc1 desc2))
892 ;; Make an image out of the description if that is so wanted
893 (when (and descp (org-file-image-p
894 desc org-export-html-inline-image-extensions))
895 (setq org-parse-link-description-is-image t)
896 (save-match-data
897 (if (string-match "^file:" desc)
898 (setq desc (substring desc (match-end 0)))))
899 (save-match-data
900 (setq desc (org-add-props
901 (org-parse-format 'INLINE-IMAGE desc)
902 '(org-protected t)))))
903 (cond
904 ((equal type "internal")
905 (let
906 ((frag-0
907 (if (= (string-to-char path) ?#)
908 (substring path 1)
909 path)))
910 (setq rpl
911 (org-parse-format
912 'ORG-LINK opt-plist "" "" (org-solidify-link-text
913 (save-match-data
914 (org-link-unescape frag-0))
915 nil) desc attr descp))))
916 ((and (equal type "id")
917 (setq id-file (org-id-find-id-file path)))
918 ;; This is an id: link to another file (if it was the same file,
919 ;; it would have become an internal link...)
920 (save-match-data
921 (setq id-file (file-relative-name
922 id-file
923 (file-name-directory org-current-export-file)))
924 (setq rpl
925 (org-parse-format
926 'ORG-LINK opt-plist type id-file
927 (concat (if (org-uuidgen-p path) "ID-") path)
928 desc attr descp))))
929 ((member type '("http" "https"))
930 ;; standard URL, can inline as image
931 (setq rpl
932 (org-parse-format
933 'ORG-LINK opt-plist type path nil desc attr descp)))
934 ((member type '("ftp" "mailto" "news"))
935 ;; standard URL, can't inline as image
936 (setq rpl
937 (org-parse-format
938 'ORG-LINK opt-plist type path nil desc attr descp)))
940 ((string= type "coderef")
941 (setq rpl
942 (org-parse-format
943 'ORG-LINK opt-plist type "" (format "coderef-%s" path)
944 (format
945 (org-export-get-coderef-format
946 path
947 (and descp desc))
948 (cdr (assoc path org-export-code-refs))) nil descp)))
950 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
951 ;; The link protocol has a function for format the link
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 (string-match "^[ \t]*\\([+]-\\||[ ]\\)[-+ |]*[+|][ \t]*$" line)
1423 (setq line (org-html-expand line)))
1425 (setq line (org-parse-format-org-link line opt-plist))
1427 ;; TODO items
1428 (if (and (string-match org-todo-line-regexp line)
1429 (match-beginning 2))
1430 (setq line (concat
1431 (substring line 0 (match-beginning 2))
1432 (org-parse-format 'TODO (match-string 2 line))
1433 (substring line (match-end 2)))))
1435 ;; Does this contain a reference to a footnote?
1436 (when org-export-with-footnotes
1437 (setq start 0)
1438 (while (string-match "\\([^* \t].*?\\)[ \t]*\\[\\([0-9]+\\)\\]" line start)
1439 (if (get-text-property (match-beginning 2) 'org-protected line)
1440 (setq start (match-end 2))
1441 (let ((n (match-string 2 line)) refcnt a)
1442 (if (setq a (assoc n footref-seen))
1443 (progn
1444 (setcdr a (1+ (cdr a)))
1445 (setq refcnt (cdr a)))
1446 (setq refcnt 1)
1447 (push (cons n 1) footref-seen))
1448 (setq line
1449 (replace-match
1450 (concat
1451 (or (match-string 1 line) "")
1452 (org-parse-format
1453 'FOOTNOTE-REFERENCE
1454 n (cdr (assoc n org-html-footnote-definitions))
1455 refcnt))
1456 t t line))))))
1458 (cond
1459 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
1460 ;; This is a headline
1461 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
1462 level-offset))
1463 txt (match-string 2 line))
1464 (if (string-match quote-re0 txt)
1465 (setq txt (replace-match "" t t txt)))
1466 (if (<= level (max umax umax-toc))
1467 (setq head-count (+ head-count 1)))
1468 (unless org-html-dyn-first-heading-pos
1469 (setq org-html-dyn-first-heading-pos (point)))
1470 (org-parse-begin 'LEVEL level txt umax head-count)
1472 ;; QUOTES
1473 (when (string-match quote-re line)
1474 (org-parse-begin-environment 'quote)))
1476 ((and org-export-with-tables
1477 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
1478 (when (not table-open)
1479 ;; New table starts
1480 (setq table-open t table-buffer nil table-orig-buffer nil))
1482 ;; Accumulate lines
1483 (setq table-buffer (cons line table-buffer)
1484 table-orig-buffer (cons origline table-orig-buffer))
1485 (when (or (not lines)
1486 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1487 (car lines))))
1488 (setq table-open nil
1489 table-buffer (nreverse table-buffer)
1490 table-orig-buffer (nreverse table-orig-buffer))
1491 (org-parse-end-paragraph)
1492 (insert (org-parse-format-table table-buffer table-orig-buffer))))
1494 ;; Normal lines
1497 ;; This line either is list item or end a list.
1498 (when (get-text-property 0 'list-item line)
1499 (setq line (org-html-export-list-line
1500 line
1501 (get-text-property 0 'list-item line)
1502 (get-text-property 0 'list-struct line)
1503 (get-text-property 0 'list-prevs line))))
1505 ;; Horizontal line
1506 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
1507 (with-org-parse-preserve-paragraph-state
1508 (insert (org-parse-format 'HORIZONTAL-LINE)))
1509 (throw 'nextline nil))
1511 ;; Empty lines start a new paragraph. If hand-formatted lists
1512 ;; are not fully interpreted, lines starting with "-", "+", "*"
1513 ;; also start a new paragraph.
1514 (when (string-match "^ [-+*]-\\|^[ \t]*$" line)
1515 (when org-html-footnote-number
1516 (org-parse-end-footnote-definition org-html-footnote-number)
1517 (setq org-html-footnote-number nil))
1518 (org-parse-begin-paragraph))
1520 ;; Is this the start of a footnote?
1521 (when org-export-with-footnotes
1522 (when (and (boundp 'footnote-section-tag-regexp)
1523 (string-match (concat "^" footnote-section-tag-regexp)
1524 line))
1525 ;; ignore this line
1526 (throw 'nextline nil))
1527 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
1528 (org-parse-end-paragraph)
1529 (setq org-html-footnote-number (match-string 1 line))
1530 (setq line (replace-match "" t t line))
1531 (org-parse-begin-footnote-definition org-html-footnote-number)))
1532 ;; Check if the line break needs to be conserved
1533 (cond
1534 ((string-match "\\\\\\\\[ \t]*$" line)
1535 (setq line (replace-match
1536 (org-parse-format 'LINE-BREAK)
1537 t t line)))
1538 (org-export-preserve-breaks
1539 (setq line (concat line (org-parse-format 'LINE-BREAK)))))
1541 ;; Check if a paragraph should be started
1542 (let ((start 0))
1543 (while (and org-par-open
1544 (string-match "\\\\par\\>" line start))
1545 (error "FIXME")
1546 ;; Leave a space in the </p> so that the footnote matcher
1547 ;; does not see this.
1548 (if (not (get-text-property (match-beginning 0)
1549 'org-protected line))
1550 (setq line (replace-match "</p ><p >" t t line)))
1551 (setq start (match-end 0))))
1553 (insert (org-parse-format 'PLAIN line))))))
1555 ;; Properly close all local lists and other lists
1556 (when (org-parse-current-environment-p 'quote)
1557 (org-parse-end-environment 'quote))
1559 (org-parse-end 'LEVEL 1 umax)
1561 ;; the </div> to close the last text-... div.
1562 (when (and (> umax 0) org-html-dyn-first-heading-pos)
1563 (org-parse-end 'SECTION))
1565 (org-parse-end 'DOCUMENT-BODY opt-plist)
1566 (unless body-only
1567 (org-parse-end 'DOCUMENT-CONTENT))
1569 (unless (plist-get opt-plist :buffer-will-be-killed)
1570 (set-auto-mode t))
1572 (org-parse-end 'EXPORT)
1574 (goto-char (point-min))
1575 (or (org-export-push-to-kill-ring
1576 (upcase (symbol-name org-parse-backend)))
1577 (message "Exporting... done"))
1579 (cond
1580 ((not to-buffer)
1581 (let ((f (org-parse-get 'SAVE-METHOD)))
1582 (or (and f (functionp f) (funcall f filename))
1583 (save-buffer)))
1584 (current-buffer))
1585 ((eq to-buffer 'string)
1586 (prog1 (buffer-substring (point-min) (point-max))
1587 (kill-buffer (current-buffer))))
1588 (t (current-buffer))))))
1590 (defun org-export-html-format-href (s)
1591 "Make sure the S is valid as a href reference in an XHTML document."
1592 (save-match-data
1593 (let ((start 0))
1594 (while (string-match "&" s start)
1595 (setq start (+ (match-beginning 0) 3)
1596 s (replace-match "&amp;" t t s)))))
1599 (defun org-export-html-format-desc (s)
1600 "Make sure the S is valid as a description in a link."
1601 (if (and s (not (get-text-property 1 'org-protected s)))
1602 (save-match-data
1603 (org-html-do-expand s))
1606 (defun org-export-html-format-image (src)
1607 "Create image tag with source and attributes."
1608 (save-match-data
1609 (if (string-match "^ltxpng/" src)
1610 (format "<img src=\"%s\" alt=\"%s\"/>"
1611 src (org-find-text-property-in-string 'org-latex-src src))
1612 (let* ((caption (org-find-text-property-in-string 'org-caption src))
1613 (attr (org-find-text-property-in-string 'org-attributes src))
1614 (label (org-find-text-property-in-string 'org-label src))
1615 (caption (and caption (org-html-do-expand caption)))
1616 (img (format "<img src=\"%s\"%s />"
1618 (if (string-match "\\<alt=" (or attr ""))
1619 (concat " " attr )
1620 (concat " " attr " alt=\"" src "\""))))
1621 (extra (concat
1622 (and label
1623 (format "id=\"%s\" " (org-solidify-link-text label)))
1624 "class=\"figure\"")))
1625 (if caption
1626 (with-temp-buffer
1627 (with-org-parse-preserve-paragraph-state
1628 (insert
1629 (org-parse-format
1630 '("<div %s>" . "\n</div>")
1631 (concat
1632 (org-parse-format '("\n<p>" . "</p>") img)
1633 (org-parse-format '("\n<p>" . "</p>") caption))
1634 extra)))
1635 (buffer-string))
1636 img)))))
1638 (defun org-export-html-get-bibliography ()
1639 "Find bibliography, cut it out and return it."
1640 (catch 'exit
1641 (let (beg end (cnt 1) bib)
1642 (save-excursion
1643 (goto-char (point-min))
1644 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
1645 (setq beg (match-beginning 0))
1646 (while (re-search-forward "</?div\\>" nil t)
1647 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
1648 (when (= cnt 0)
1649 (and (looking-at ">") (forward-char 1))
1650 (setq bib (buffer-substring beg (point)))
1651 (delete-region beg (point))
1652 (throw 'exit bib))))
1653 nil))))
1655 ;; Following variable is defined for native tables i.e., when
1656 ;; `org-table-is-styled' evals to t.
1657 (defvar org-html-format-table-no-css)
1658 (defvar org-table-number-regexp) ; defined in org-table.el
1659 (defun org-parse-format-table (lines olines)
1660 "Retuns backend-specific code for org-type and table-type
1661 tables."
1662 (if (stringp lines)
1663 (setq lines (org-split-string lines "\n")))
1664 (if (string-match "^[ \t]*|" (car lines))
1665 ;; A normal org table
1666 (org-parse-format-org-table lines nil)
1667 ;; Table made by table.el
1668 (or (org-parse-format-table-table-using-table-generate-source
1669 org-export-current-backend olines
1670 (not org-export-prefer-native-exporter-for-tables))
1671 ;; We are here only when table.el table has NO col or row
1672 ;; spanning and the user prefers using org's own converter for
1673 ;; exporting of such simple table.el tables.
1674 (org-parse-format-table-table lines))))
1676 (defun org-format-table-html (lines olines &optional no-css)
1677 "Find out which HTML converter to use and return the HTML code.
1678 NO-CSS is passed to the exporter."
1679 (let* ((org-parse-get-callback 'org-html-get)
1680 (org-parse-entity-control-callbacks-alist
1681 (org-parse-get 'ENTITY-CONTROL))
1682 (org-parse-entity-format-callbacks-alist
1683 (org-parse-get 'ENTITY-FORMAT))
1684 (org-html-format-table-no-css no-css))
1685 (org-parse-format-table lines 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-parse-do-format-org-table (lines &optional splice)
1707 "Format a org-type table into backend-specific code.
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 ;; This routine might get called outside of org-export-as-html. For
1769 ;; example, this could happen as part of org-table-export or as part
1770 ;; of org-export-as-docbook. Explicitly bind the parser callback to
1771 ;; the html ones for the duration of the call.
1772 (let* ((org-parse-get-callback 'org-html-get)
1773 (org-parse-entity-control-callbacks-alist
1774 (org-parse-get 'ENTITY-CONTROL))
1775 (org-parse-entity-format-callbacks-alist
1776 (org-parse-get 'ENTITY-FORMAT))
1777 (org-html-format-table-no-css no-css))
1778 (org-parse-format-org-table lines splice)))
1780 (defun org-parse-format-org-table (lines &optional splice)
1781 (with-temp-buffer
1782 (org-parse-do-format-org-table lines splice)
1783 (buffer-substring-no-properties (point-min) (point-max))))
1785 (defun org-export-splice-attributes (tag attributes)
1786 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
1787 (if (not attributes)
1789 (let (oldatt newatt)
1790 (setq oldatt (org-extract-attributes-from-string tag)
1791 tag (pop oldatt)
1792 newatt (cdr (org-extract-attributes-from-string attributes)))
1793 (while newatt
1794 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
1795 (if (string-match ">" tag)
1796 (setq tag
1797 (replace-match (concat (org-attributes-to-string oldatt) ">")
1798 t t tag)))
1799 tag)))
1801 (defun org-parse-do-format-table-table (lines)
1802 "Format a table generated by table.el into backend-specific code.
1803 This conversion does *not* use `table-generate-source' from table.el.
1804 This has the advantage that Org-mode's HTML conversions can be used.
1805 But it has the disadvantage, that no cell- or row-spanning is allowed."
1806 (let (line field-buffer
1807 (org-table-current-rowgroup-is-header
1808 org-export-highlight-first-table-line)
1809 (caption nil)
1810 (attributes nil)
1811 (label nil)
1812 (org-table-style 'table-table)
1813 (org-table-is-styled nil)
1814 fields org-table-ncols i (org-table-rownum -1)
1815 (empty (org-parse-format 'SPACES 1)))
1816 (org-parse-begin 'TABLE caption label attributes)
1817 (while (setq line (pop lines))
1818 (cond
1819 ((string-match "^[ \t]*\\+-" line)
1820 (when field-buffer
1821 (let ((org-export-table-row-tags '("<tr>" . "</tr>"))
1822 (org-export-html-table-use-header-tags-for-first-column nil))
1823 (insert (org-parse-format-table-row field-buffer empty)))
1824 (setq org-table-current-rowgroup-is-header nil)
1825 (setq field-buffer nil)))
1827 ;; Break the line into fields and store the fields
1828 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
1829 (if field-buffer
1830 (setq field-buffer (mapcar
1831 (lambda (x)
1832 (concat x (org-parse-format 'LINE-BREAK)
1833 (pop fields)))
1834 field-buffer))
1835 (setq field-buffer fields)))))
1836 (org-parse-end-table)))
1838 (defun org-parse-format-table-table (lines)
1839 (with-temp-buffer
1840 (org-parse-do-format-table-table lines)
1841 (buffer-substring-no-properties (point-min) (point-max))))
1843 (defun org-format-table-table-html (lines)
1844 (let* ((org-parse-get-callback 'org-html-get)
1845 (org-parse-entity-control-callbacks-alist
1846 (org-parse-get 'ENTITY-CONTROL))
1847 (org-parse-entity-format-callbacks-alist
1848 (org-parse-get 'ENTITY-FORMAT)))
1849 (org-parse-format-table-table lines)))
1851 (defun org-parse-format-table-table-using-table-generate-source (backend
1852 lines
1853 &optional
1854 spanned-only)
1855 "Format a table into BACKEND, using `table-generate-source' from table.el.
1856 Use SPANNED-ONLY to suppress exporting of simple table.el tables.
1858 When SPANNED-ONLY is nil, all table.el tables are exported. When
1859 SPANNED-ONLY is non-nil, only tables with either row or column
1860 spans are exported.
1862 This routine returns the generated source or nil as appropriate.
1864 Refer docstring of `org-export-prefer-native-exporter-for-tables'
1865 for further information."
1866 (require 'table)
1867 (with-current-buffer (get-buffer-create " org-tmp1 ")
1868 (erase-buffer)
1869 (insert (mapconcat 'identity lines "\n"))
1870 (goto-char (point-min))
1871 (if (not (re-search-forward "|[^+]" nil t))
1872 (error "Error processing table"))
1873 (table-recognize-table)
1874 (when (or (not spanned-only)
1875 (let* ((dim (table-query-dimension))
1876 (c (nth 4 dim)) (r (nth 5 dim)) (cells (nth 6 dim)))
1877 (not (= (* c r) cells))))
1878 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
1879 (cond
1880 ((member backend table-source-languages)
1881 (table-generate-source backend " org-tmp2 ")
1882 (set-buffer " org-tmp2 ")
1883 (buffer-substring (point-min) (point-max)))
1885 ;; table.el doesn't support the given backend. Currently this
1886 ;; happens in case of odt export. Strip the table from the
1887 ;; generated document. A better alternative would be to embed
1888 ;; the table as ascii text in the output document.
1889 (org-odt-warn "Don't know how to export table.el table!")
1890 "")))))
1892 (defun org-export-splice-style (style extra)
1893 "Splice EXTRA into STYLE, just before \"</style>\"."
1894 (if (and (stringp extra)
1895 (string-match "\\S-" extra)
1896 (string-match "</style>" style))
1897 (concat (substring style 0 (match-beginning 0))
1898 "\n" extra "\n"
1899 (substring style (match-beginning 0)))
1900 style))
1902 (defun org-html-handle-time-stamps (s)
1903 "Format time stamps in string S, or remove them."
1904 (catch 'exit
1905 (let (r b)
1906 (while (string-match org-maybe-keyword-time-regexp s)
1907 (or b (setq b (substring s 0 (match-beginning 0))))
1908 (setq r (concat
1909 r (substring s 0 (match-beginning 0))
1910 (org-parse-format
1911 'FONTIFY
1912 (concat
1913 (if (match-end 1)
1914 (org-parse-format
1915 'FONTIFY
1916 (match-string 1 s) "timestamp-kwd"))
1917 (org-parse-format
1918 'FONTIFY
1919 (substring (org-translate-time (match-string 3 s)) 1 -1)
1920 "timestamp"))
1921 "timestamp-wrapper"))
1922 s (substring s (match-end 0))))
1923 ;; Line break if line started and ended with time stamp stuff
1924 (if (not r)
1926 (setq r (concat r s))
1927 (unless (string-match "\\S-" (concat b s))
1928 (setq r (concat r (org-parse-format 'LINE-BREAK))))
1929 r))))
1931 (defvar htmlize-buffer-places) ; from htmlize.el
1932 (defun org-export-htmlize-region-for-paste (beg end)
1933 "Convert the region to HTML, using htmlize.el.
1934 This is much like `htmlize-region-for-paste', only that it uses
1935 the settings define in the org-... variables."
1936 (let* ((htmlize-output-type org-export-htmlize-output-type)
1937 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
1938 (htmlbuf (htmlize-region beg end)))
1939 (unwind-protect
1940 (with-current-buffer htmlbuf
1941 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
1942 (plist-get htmlize-buffer-places 'content-end)))
1943 (kill-buffer htmlbuf))))
1945 ;;;###autoload
1946 (defun org-export-htmlize-generate-css ()
1947 "Create the CSS for all font definitions in the current Emacs session.
1948 Use this to create face definitions in your CSS style file that can then
1949 be used by code snippets transformed by htmlize.
1950 This command just produces a buffer that contains class definitions for all
1951 faces used in the current Emacs session. You can copy and paste the ones you
1952 need into your CSS file.
1954 If you then set `org-export-htmlize-output-type' to `css', calls to
1955 the function `org-export-htmlize-region-for-paste' will produce code
1956 that uses these same face definitions."
1957 (interactive)
1958 (require 'htmlize)
1959 (and (get-buffer "*html*") (kill-buffer "*html*"))
1960 (with-temp-buffer
1961 (let ((fl (face-list))
1962 (htmlize-css-name-prefix "org-")
1963 (htmlize-output-type 'css)
1964 f i)
1965 (while (setq f (pop fl)
1966 i (and f (face-attribute f :inherit)))
1967 (when (and (symbolp f) (or (not i) (not (listp i))))
1968 (insert (org-add-props (copy-sequence "1") nil 'face f))))
1969 (htmlize-region (point-min) (point-max))))
1970 (switch-to-buffer "*html*")
1971 (goto-char (point-min))
1972 (if (re-search-forward "<style" nil t)
1973 (delete-region (point-min) (match-beginning 0)))
1974 (if (re-search-forward "</style>" nil t)
1975 (delete-region (1+ (match-end 0)) (point-max)))
1976 (beginning-of-line 1)
1977 (if (looking-at " +") (replace-match ""))
1978 (goto-char (point-min)))
1980 (defun org-html-protect (s)
1981 "Convert characters to HTML equivalent.
1982 Possible conversions are set in `org-export-html-protect-char-alist'."
1983 (let ((cl org-export-html-protect-char-alist) c)
1984 (while (setq c (pop cl))
1985 (let ((start 0))
1986 (while (string-match (car c) s start)
1987 (setq s (replace-match (cdr c) t t s)
1988 start (1+ (match-beginning 0))))))
1991 (defun org-html-expand (string)
1992 "Prepare STRING for HTML export. Apply all active conversions.
1993 If there are links in the string, don't modify these."
1994 (let* ((re (concat org-bracket-link-regexp "\\|"
1995 (org-re "[ \t]+\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$")))
1996 m s l res)
1997 (while (setq m (string-match re string))
1998 (setq s (substring string 0 m)
1999 l (match-string 0 string)
2000 string (substring string (match-end 0)))
2001 (push (org-html-do-expand s) res)
2002 (push l res))
2003 (push (org-html-do-expand string) res)
2004 (apply 'concat (nreverse res))))
2006 (defun org-html-do-expand (s)
2007 "Apply all active conversions to translate special ASCII to HTML."
2008 (setq s (org-html-protect s))
2009 (if org-export-html-expand
2010 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
2011 (setq s (replace-match "<\\1>" t nil s))))
2012 (if org-export-with-emphasize
2013 (setq s (org-export-html-convert-emphasize s)))
2014 (if org-export-with-special-strings
2015 (setq s (org-export-html-convert-special-strings s)))
2016 (if org-export-with-sub-superscripts
2017 (setq s (org-export-html-convert-sub-super s)))
2018 (if org-export-with-TeX-macros
2019 (let ((start 0) wd rep)
2020 (while (setq start (string-match "\\\\\\([a-zA-Z]+[0-9]*\\)\\({}\\)?"
2021 s start))
2022 (if (get-text-property (match-beginning 0) 'org-protected s)
2023 (setq start (match-end 0))
2024 (setq wd (match-string 1 s))
2025 (if (setq rep (org-entity-get-representation wd 'html))
2026 (setq s (replace-match rep t t s))
2027 (setq start (+ start (length wd))))))))
2030 (defun org-export-html-convert-special-strings (string)
2031 "Convert special characters in STRING to HTML."
2032 (let ((all org-export-html-special-string-regexps)
2033 e a re rpl start)
2034 (while (setq a (pop all))
2035 (setq re (car a) rpl (cdr a) start 0)
2036 (while (string-match re string start)
2037 (if (get-text-property (match-beginning 0) 'org-protected string)
2038 (setq start (match-end 0))
2039 (setq string (replace-match rpl t nil string)))))
2040 string))
2042 (defun org-export-html-convert-sub-super (string)
2043 "Convert sub- and superscripts in STRING to HTML."
2044 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
2045 (while (string-match org-match-substring-regexp string s)
2046 (cond
2047 ((and requireb (match-end 8)) (setq s (match-end 2)))
2048 ((get-text-property (match-beginning 2) 'org-protected string)
2049 (setq s (match-end 2)))
2051 (setq s (match-end 1)
2052 key (if (string= (match-string 2 string) "_")
2053 'subscript 'superscript)
2054 c (or (match-string 8 string)
2055 (match-string 6 string)
2056 (match-string 5 string))
2057 string (replace-match
2058 (concat (match-string 1 string)
2059 (org-parse-format 'FONTIFY c key))
2060 t t string)))))
2061 (while (string-match "\\\\\\([_^]\\)" string)
2062 (setq string (replace-match (match-string 1 string) t t string)))
2063 string))
2065 (defconst org-html-emphasis-alist
2066 `(("*" bold)
2067 ("/" emphasis)
2068 ("_" underline)
2069 ("=" code)
2070 ("~" verbatim)
2071 ("+" strike)))
2073 (defun org-export-html-convert-emphasize (string)
2074 "Apply emphasis."
2075 (let ((s 0) rpl)
2076 (while (string-match org-emph-re string s)
2077 (if (not (equal
2078 (substring string (match-beginning 3) (1+ (match-beginning 3)))
2079 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
2080 (setq s (match-beginning 0)
2082 (concat
2083 (match-string 1 string)
2084 (org-parse-format
2085 'FONTIFY (match-string 4 string)
2086 (nth 1 (assoc (match-string 3 string)
2087 org-html-emphasis-alist)))
2088 (match-string 5 string))
2089 string (replace-match rpl t t string)
2090 s (+ s (- (length rpl) 2)))
2091 (setq s (1+ s))))
2092 string))
2094 (defvar body-only) ; dynamically scoped into this.
2095 (defun org-export-html-get-tag-class-name (tag)
2096 "Turn tag into a valid class name.
2097 Replaces invalid characters with \"_\" and then prepends a prefix."
2098 (save-match-data
2099 (while (string-match "[^a-zA-Z0-9_]" tag)
2100 (setq tag (replace-match "_" t t tag))))
2101 (concat org-export-html-tag-class-prefix tag))
2103 (defun org-export-html-get-todo-kwd-class-name (kwd)
2104 "Turn todo keyword into a valid class name.
2105 Replaces invalid characters with \"_\" and then prepends a prefix."
2106 (save-match-data
2107 (while (string-match "[^a-zA-Z0-9_]" kwd)
2108 (setq kwd (replace-match "_" t t kwd))))
2109 (concat org-export-html-todo-kwd-class-prefix kwd))
2111 (defun org-html-export-list-line (line pos struct prevs)
2112 "Insert list syntax in export buffer. Return LINE, maybe modified.
2114 POS is the item position or line position the line had before
2115 modifications to buffer. STRUCT is the list structure. PREVS is
2116 the alist of previous items."
2117 (let* ((get-type
2118 (function
2119 ;; Translate type of list containing POS to "d", "o" or
2120 ;; "u".
2121 (lambda (pos struct prevs)
2122 (let ((type (org-list-get-list-type pos struct prevs)))
2123 (cond
2124 ((eq 'ordered type) "o")
2125 ((eq 'descriptive type) "d")
2126 (t "u"))))))
2127 (get-closings
2128 (function
2129 ;; Return list of all items and sublists ending at POS, in
2130 ;; reverse order.
2131 (lambda (pos)
2132 (let (out)
2133 (catch 'exit
2134 (mapc (lambda (e)
2135 (let ((end (nth 6 e))
2136 (item (car e)))
2137 (cond
2138 ((= end pos) (push item out))
2139 ((>= item pos) (throw 'exit nil)))))
2140 struct))
2141 out)))))
2142 ;; First close any previous item, or list, ending at POS.
2143 (mapc (lambda (e)
2144 (let* ((lastp (= (org-list-get-last-item e struct prevs) e))
2145 (first-item (org-list-get-list-begin e struct prevs))
2146 (type (funcall get-type first-item struct prevs)))
2147 (org-parse-end-paragraph)
2148 ;; Ending for every item
2149 (org-close-li type)
2150 ;; We're ending last item of the list: end list.
2151 (when lastp
2152 (org-parse-end 'LIST type)
2153 (org-parse-begin-paragraph))))
2154 (funcall get-closings pos))
2155 (cond
2156 ;; At an item: insert appropriate tags in export buffer.
2157 ((assq pos struct)
2158 (string-match
2159 (concat "[ \t]*\\(\\S-+[ \t]*\\)"
2160 "\\(?:\\[@\\(?:start:\\)?\\([0-9]+\\|[A-Za-z]\\)\\]\\)?"
2161 "\\(?:\\(\\[[ X-]\\]\\)[ \t]+\\)?"
2162 "\\(?:\\(.*\\)[ \t]+::[ \t]+\\)?"
2163 "\\(.*\\)") line)
2164 (let* ((checkbox (match-string 3 line))
2165 (desc-tag (or (match-string 4 line) "???"))
2166 (body (or (match-string 5 line) ""))
2167 (list-beg (org-list-get-list-begin pos struct prevs))
2168 (firstp (= list-beg pos))
2169 ;; Always refer to first item to determine list type, in
2170 ;; case list is ill-formed.
2171 (type (funcall get-type list-beg struct prevs))
2172 (counter (let ((count-tmp (org-list-get-counter pos struct)))
2173 (cond
2174 ((not count-tmp) nil)
2175 ((string-match "[A-Za-z]" count-tmp)
2176 (- (string-to-char (upcase count-tmp)) 64))
2177 ((string-match "[0-9]+" count-tmp)
2178 count-tmp)))))
2179 (when firstp
2180 (org-parse-end-paragraph)
2181 (org-parse-begin 'LIST type))
2183 (let ((arg (cond ((equal type "d") desc-tag)
2184 ((equal type "o") counter))))
2185 (org-parse-begin 'LIST-ITEM type arg))
2187 ;; If line had a checkbox, some additional modification is required.
2188 (when checkbox
2189 (setq body
2190 (concat
2191 (org-parse-format
2192 'FONTIFY (concat
2194 (cond
2195 ((string-match "X" checkbox) "X")
2196 ((string-match " " checkbox)
2197 (org-parse-format 'SPACES 1))
2198 (t "-"))
2199 "]")
2200 'code)
2202 body)))
2203 ;; Return modified line
2204 body))
2205 ;; At a list ender: go to next line (side-effects only).
2206 ((equal "ORG-LIST-END-MARKER" line) (throw 'nextline nil))
2207 ;; Not at an item: return line unchanged (side-effects only).
2208 (t line))))
2210 ;; miscellaneous
2212 (defun org-html-bind-local-variables (opt-plist)
2213 (mapc (lambda (x)
2214 (set (make-local-variable (nth 2 x))
2215 (plist-get opt-plist (car x))))
2216 org-export-plist-vars))
2219 ;; This replaces org-emphasis-alist
2220 (defvar org-table-rowgroup-open)
2221 (defvar org-table-current-rowgroup-is-header)
2222 (defvar org-html-footnote-number)
2223 (defvar org-html-footnote-definitions)
2224 (defvar org-html-footnote-buffer)
2225 (defvar org-html-output-buffer)
2227 (defun org-html-end-export ()
2228 ;; insert the table of contents
2229 (when (and org-export-with-toc (not body-only) org-parse-table-of-contents)
2230 (org-html-insert-toc org-parse-table-of-contents))
2232 ;; remove empty paragraphs
2233 (goto-char (point-min))
2234 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
2235 (replace-match ""))
2237 ;; Convert whitespace place holders
2238 (goto-char (point-min))
2239 (let (beg end n)
2240 (while (setq beg (next-single-property-change (point) 'org-whitespace))
2241 (setq n (get-text-property beg 'org-whitespace)
2242 end (next-single-property-change beg 'org-whitespace))
2243 (goto-char beg)
2244 (delete-region beg end)
2245 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2246 (make-string n ?x)))))
2248 ;; Remove empty lines at the beginning of the file.
2249 (goto-char (point-min))
2250 (when (looking-at "\\s-+\n") (replace-match ""))
2252 ;; Remove display properties
2253 (remove-text-properties (point-min) (point-max) '(display t))
2255 ;; kill temporary buffers
2256 (when org-html-footnote-buffer
2257 (kill-buffer org-html-footnote-buffer))
2259 ;; Run the hook
2260 (run-hooks 'org-export-html-final-hook))
2263 ;;;_ org-parse.el
2264 ;;;_. preamble
2265 ;;;_ , user-specific
2266 ;;;_ . custom-settings
2267 (defcustom org-parse-debug nil
2269 :group 'org-parse
2270 :type 'boolean)
2275 ;;;_ , callbacks
2276 ;;;_ . control callbacks
2277 ;;;_ , generic
2278 (defun org-parse-begin (entity &rest args)
2279 (when (and (member org-parse-debug '(t control))
2280 (not (eq entity 'DOCUMENT-CONTENT)))
2281 (insert (org-parse-format 'COMMENT "%s BEGIN %S" entity args)))
2283 (let ((f (cadr (assoc entity org-parse-entity-control-callbacks-alist))))
2284 (unless f (error "Unknown entity: %s" entity))
2285 (apply f args)))
2287 (defun org-parse-end (entity &rest args)
2288 (when (and (member org-parse-debug '(t control))
2289 (not (eq entity 'DOCUMENT-CONTENT)))
2290 (insert (org-parse-format 'COMMENT "%s END %S" entity args)))
2292 (let ((f (caddr (assoc entity org-parse-entity-control-callbacks-alist))))
2293 (unless f (error "Unknown entity: %s" entity))
2294 (apply f args)))
2297 ;;;_ , paragraph
2298 (defun org-parse-begin-paragraph (&optional style)
2299 "Insert <p>, but first close previous paragraph if any."
2300 (org-parse-end-paragraph)
2301 (org-parse-begin 'PARAGRAPH style)
2302 (setq org-par-open t))
2304 (defun org-parse-end-paragraph ()
2305 "Close paragraph if there is one open."
2306 (when org-par-open
2307 (org-parse-end 'PARAGRAPH)
2308 (setq org-par-open nil)))
2310 ;;;_ , list
2311 (defun org-close-li (&optional type)
2312 "Close <li> if necessary."
2313 (org-parse-end-paragraph)
2314 (org-parse-end 'LIST-ITEM (or type "u")))
2317 ;;;_ , environment
2318 (defvar org-parse-dyn-current-environment nil)
2319 (defun org-parse-begin-environment (style)
2320 (assert (not org-parse-dyn-current-environment) t)
2321 (setq org-parse-dyn-current-environment style)
2322 (org-parse-begin 'ENVIRONMENT style))
2324 (defun org-parse-end-environment (style)
2325 (org-parse-end 'ENVIRONMENT style)
2327 (assert (eq org-parse-dyn-current-environment style) t)
2328 (setq org-parse-dyn-current-environment nil))
2330 (defun org-parse-current-environment-p (style)
2331 (eq org-parse-dyn-current-environment style))
2334 ;;;_ , footnote definition
2335 (defun org-parse-begin-footnote-definition (n)
2336 (unless org-html-footnote-buffer
2337 (setq org-html-footnote-buffer
2338 (get-buffer-create "*Org HTML Export Footnotes*")))
2339 (set-buffer org-html-footnote-buffer)
2340 (erase-buffer)
2341 (org-parse-begin 'FOOTNOTE-DEFINITION n))
2343 (defun org-parse-end-footnote-definition (n)
2344 (org-parse-end 'FOOTNOTE-DEFINITION n)
2345 (push (cons n (buffer-string)) org-html-footnote-definitions)
2346 (set-buffer org-html-output-buffer))
2351 ;;;_ . format callbacks
2352 ;;;_ , generic
2353 (defun org-parse-format (entity &rest args)
2354 (when (and (member org-parse-debug '(t format))
2355 (not (equal entity 'COMMENT)))
2356 (insert (org-parse-format 'COMMENT "%s: %S" entity args)))
2357 (cond
2358 ((consp entity)
2359 (let ((text (pop args)))
2360 (apply 'org-parse-format 'TAGS entity text args)))
2362 (let ((f (cdr (assoc entity org-parse-entity-format-callbacks-alist))))
2363 (unless f (error "Unknown entity: %s" entity))
2364 (apply f args)))))
2367 ;;;_ , toc (rename these routines)
2368 (defun org-html-format-toc-entry (snumber todo headline tags href)
2369 (setq headline (concat
2370 (and org-export-with-section-numbers
2371 (concat snumber " "))
2372 headline
2373 (and tags
2374 (concat
2375 (org-parse-format 'SPACES 3)
2376 (org-parse-format 'FONTIFY tags "tag")))))
2377 (when todo
2378 (setq headline (org-parse-format 'FONTIFY headline "todo")))
2379 (org-parse-format 'LINK headline (concat "#" href)))
2381 (defun org-html-format-toc-item (toc-entry level org-last-level)
2382 (when (> level org-last-level)
2383 (let ((cnt (- level org-last-level)))
2384 (while (>= (setq cnt (1- cnt)) 0)
2385 (org-parse-begin 'LIST 'unordered)
2386 (org-parse-begin 'LIST-ITEM 'unordered))))
2387 (when (< level org-last-level)
2388 (let ((cnt (- org-last-level level)))
2389 (while (>= (setq cnt (1- cnt)) 0)
2390 (org-close-li)
2391 (org-parse-end 'LIST 'unordered))))
2393 (org-close-li)
2394 (org-parse-begin 'LIST-ITEM 'unordered)
2395 (insert toc-entry))
2397 (defun org-html-begin-toc (lang-specific-heading)
2398 (org-parse-begin 'SECTION "table-of-contents")
2399 (insert
2400 (org-parse-format 'HEADING lang-specific-heading
2401 (or (org-parse-get 'TOPLEVEL-HLEVEL) 1)))
2402 (org-parse-begin 'SECTION "text-table-of-contents")
2403 (org-parse-begin 'LIST 'unordered)
2404 (org-parse-begin 'LIST-ITEM 'unordered))
2406 (defun org-html-end-toc ()
2407 (while (> org-last-level (1- org-min-level))
2408 (setq org-last-level (1- org-last-level))
2409 (org-close-li)
2410 (org-parse-end 'LIST 'unordered))
2411 (org-parse-end 'SECTION)
2412 (org-parse-end 'SECTION)
2414 ;; cleanup empty list items in toc
2415 (while (re-search-backward "<li>[ \r\n\t]*</li>\n?" (point-min) t)
2416 (replace-match "")))
2418 (defun org-parse-prepare-toc (lines level-offset opt-plist umax-toc)
2419 (let* ((quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2420 (org-min-level (org-get-min-level lines level-offset))
2421 (org-last-level org-min-level)
2422 level)
2423 (with-temp-buffer
2424 (org-html-bind-local-variables opt-plist)
2425 (erase-buffer)
2426 (org-parse-begin 'TOC (nth 3 (plist-get opt-plist :lang-words)))
2427 (setq
2428 lines
2429 (mapcar
2430 '(lambda (line)
2431 (when (and (string-match org-todo-line-regexp line)
2432 (not (get-text-property 0 'org-protected line))
2433 (<= (setq level (org-tr-level
2434 (- (match-end 1) (match-beginning 1)
2435 level-offset)))
2436 umax-toc))
2437 (let ((txt (save-match-data
2438 (org-html-expand
2439 (org-export-cleanup-toc-line
2440 (match-string 3 line)))))
2441 (todo (and
2442 org-export-mark-todo-in-toc
2443 (or (and (match-beginning 2)
2444 (not (member (match-string 2 line)
2445 org-done-keywords)))
2446 (and (= level umax-toc)
2447 (org-search-todo-below
2448 line lines level)))))
2449 tags)
2450 ;; Check for targets
2451 (while (string-match org-any-target-regexp line)
2452 (setq line
2453 (replace-match
2454 (let ((org-html-protect t))
2455 (org-parse-format 'FONTIFY
2456 (match-string 1 line) "target"))
2457 t t line)))
2458 (when (string-match
2459 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
2460 (setq txt (replace-match "" t nil txt)
2461 tags (match-string 1 txt)))
2462 (when (string-match quote-re0 txt)
2463 (setq txt (replace-match "" t t txt)))
2464 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
2465 (setq txt (replace-match "" t t txt)))
2466 (org-parse-format
2467 'TOC-ITEM
2468 (let* ((snumber (org-section-number level))
2469 (href (replace-regexp-in-string
2470 "\\." "_" (format "sec-%s" snumber)))
2471 (href
2473 (cdr (assoc
2474 href org-export-preferred-target-alist))
2475 href))
2476 (href (org-solidify-link-text href)))
2477 (org-parse-format 'TOC-ENTRY snumber todo txt tags href))
2478 level org-last-level)
2479 (setq org-last-level level)))
2480 line)
2481 lines))
2482 (org-parse-end 'TOC)
2483 (setq org-parse-table-of-contents (buffer-string))))
2484 lines)
2487 ;;;_ , table row
2488 (defun org-parse-format-table-row (fields &optional text-for-empty-fields)
2489 (unless org-table-ncols
2490 ;; first row of the table
2491 (setq org-table-ncols (length fields))
2492 (when org-table-is-styled
2493 (setq org-table-num-numeric-items-per-column (make-vector org-table-ncols 0))
2494 (setq org-table-colalign-vector (make-vector org-table-ncols nil))
2495 (let ((c -1))
2496 (while (< (incf c) org-table-ncols)
2497 (let ((cookie (cdr (assoc (1+ c) org-table-colalign-info))))
2498 (setf (aref org-table-colalign-vector c)
2499 (cond
2500 ((string= cookie "l") "left")
2501 ((string= cookie "r") "right")
2502 ((string= cookie "c") "center")
2503 (t nil))))))))
2504 (incf org-table-rownum)
2506 (let ((i -1))
2507 (org-parse-format
2508 'TABLE-ROW
2509 (mapconcat
2510 (lambda (x)
2511 (when (string= x "")
2512 (setq x text-for-empty-fields))
2513 (incf i)
2514 (and org-table-is-styled
2515 (< i org-table-ncols)
2516 (string-match org-table-number-regexp x)
2517 (incf (aref org-table-num-numeric-items-per-column i)))
2518 (org-parse-format 'TABLE-CELL x org-table-rownum i))
2519 fields "\n"))))
2521 ;;;_ . get callback
2522 (defun org-parse-get (what &optional opt-plist)
2523 (funcall org-parse-get-callback what opt-plist))
2525 ;;;_. postamble
2528 ;;;_ org-newhtml.el
2529 ;;;_. preamble
2530 ;;;_. obsolete
2531 ;;;_. maybe
2532 ;;;_. hacks (to be documented)
2534 ;; Refer `org-html-emphasis-alist'
2536 ;;;_. user-specific
2537 ;;;_ , custom settings
2538 ;;;_ . potential custom settings
2539 ;;;_ , interactive commands
2540 ;;;_. parser
2541 ;;;_ , initialization
2542 (defvar org-html-entity-control-callbacks-alist
2543 `((EXPORT
2544 . (org-html-begin-export org-html-end-export))
2545 (DOCUMENT-CONTENT
2546 . (org-html-begin-document-content org-html-end-document-content))
2547 (DOCUMENT-BODY
2548 . (org-html-begin-document-body org-html-end-document-body))
2549 (TOC
2550 . (org-html-begin-toc org-html-end-toc))
2551 (ENVIRONMENT
2552 . (org-html-begin-environment org-html-end-environment))
2553 (LEVEL
2554 . (org-html-begin-level org-html-end-level))
2555 (FOOTNOTE-DEFINITION
2556 . (org-html-begin-footnote-definition org-html-end-footnote-definition))
2557 (TABLE
2558 . (org-html-begin-table org-html-end-table))
2559 (TABLE-ROWGROUP
2560 . (org-html-begin-table-rowgroup org-html-end-table-rowgroup))
2561 (LIST
2562 . (org-html-begin-list org-html-end-list))
2563 (LIST-ITEM
2564 . (org-html-begin-list-item org-html-end-list-item))
2565 (SECTION
2566 . (org-html-begin-section org-html-end-section))
2567 (PARAGRAPH
2568 . (org-html-begin-paragraph org-html-end-paragraph)))
2571 (defvar org-html-entity-format-callbacks-alist
2572 `((EXTRA-TARGETS . org-html-format-extra-targets)
2573 (ORG-TAGS . org-html-format-org-tags)
2574 (SECTION-NUMBER . org-html-format-section-number)
2575 (HEADLINE . org-html-format-headline)
2576 (TOC-ENTRY . org-html-format-toc-entry)
2577 (TOC-ITEM . org-html-format-toc-item)
2578 (TAGS . org-html-format-tags)
2579 (SPACES . org-html-format-spaces)
2580 (TABS . org-html-format-tabs)
2581 (LINE-BREAK . org-html-format-line-break)
2582 (FONTIFY . org-html-format-fontify)
2583 (TODO . org-html-format-todo)
2584 (ORG-LINK . org-html-format-org-link)
2585 (LINK . org-html-format-link)
2586 (INLINE-IMAGE . org-html-format-inline-image)
2587 (HEADING . org-html-format-heading)
2588 (ANCHOR . org-html-format-anchor)
2589 (TABLE-ROW . org-html-format-table-row)
2590 (TABLE-CELL . org-html-format-table-cell)
2591 (FOOTNOTES-SECTION . org-html-format-footnotes-section)
2592 (FOOTNOTE-REFERENCE . org-html-format-footnote-reference)
2593 (HORIZONTAL-LINE . org-html-format-horizontal-line)
2594 (PLAIN . org-html-format-plain)
2595 (COMMENT . org-html-format-comment))
2600 ;;;_ , callbacks
2601 ;;;_ . control callbacks
2602 ;;;_ , generic
2603 (defvar org-html-insert-tag-with-newlines nil) ; un-uglifies exported
2604 ; xml. CAUTION: Not
2605 ; meant for production
2606 ; use.
2608 (defun org-html-insert-tag (tag &rest args)
2609 (when (member org-html-insert-tag-with-newlines '(lead both))
2610 (insert "\n"))
2611 (insert (apply 'format tag args))
2612 (when (member org-html-insert-tag-with-newlines '(trail both))
2613 (insert "\n")))
2615 ;;;_ , document body
2616 (defun org-html-begin-document-body (opt-plist)
2617 (let ((link-up (and (plist-get opt-plist :link-up)
2618 (string-match "\\S-" (plist-get opt-plist :link-up))
2619 (plist-get opt-plist :link-up)))
2620 (link-home (and (plist-get opt-plist :link-home)
2621 (string-match "\\S-" (plist-get opt-plist :link-home))
2622 (plist-get opt-plist :link-home))))
2623 (insert "\n<body>")
2624 (org-parse-begin 'SECTION "content")
2625 (insert "\n"
2626 (or (and (or link-up link-home)
2627 (format org-export-html-home/up-format
2628 (or link-up link-home)
2629 (or link-home link-up))) "")
2630 "\n"))
2631 (org-html-insert-preamble opt-plist))
2633 (defun org-html-end-document-body (opt-plist)
2634 (org-html-insert-postamble opt-plist)
2635 (unless body-only
2636 (org-parse-end 'SECTION)
2637 (insert "\n</body>")))
2640 ;;;_ , document content
2641 (defun org-html-begin-document-content (opt-plist)
2642 (let* ((language (plist-get opt-plist :language))
2643 (charset (or (and coding-system-for-write
2644 (fboundp 'coding-system-get)
2645 (coding-system-get coding-system-for-write
2646 'mime-charset))
2647 "iso-8859-1"))
2648 (style (concat (if (plist-get opt-plist :style-include-default)
2649 org-export-html-style-default)
2650 (plist-get opt-plist :style)
2651 (plist-get opt-plist :style-extra)
2652 "\n"
2653 (if (plist-get opt-plist :style-include-scripts)
2654 org-export-html-scripts)))
2655 (mathjax
2656 (if (or (eq (plist-get opt-plist :LaTeX-fragments) 'mathjax)
2657 (and org-export-have-math
2658 (eq (plist-get opt-plist :LaTeX-fragments) t)))
2660 (org-export-html-mathjax-config
2661 org-export-html-mathjax-template
2662 org-export-html-mathjax-options
2663 (or (plist-get opt-plist :mathjax) "")) "")))
2664 (insert (format
2666 <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2667 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2668 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2669 lang=\"%s\" xml:lang=\"%s\">
2670 <head>
2671 <title>%s</title>
2672 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2673 <meta name=\"generator\" content=\"Org-mode\"/>
2674 <meta name=\"generated\" content=\"%s\"/>
2675 <meta name=\"author\" content=\"%s\"/>
2676 <meta name=\"description\" content=\"%s\"/>
2677 <meta name=\"keywords\" content=\"%s\"/>
2680 </head>
2682 (format
2683 (or (and (stringp org-export-html-xml-declaration)
2684 org-export-html-xml-declaration)
2685 (cdr (assoc (plist-get opt-plist :html-extension)
2686 org-export-html-xml-declaration))
2687 (cdr (assoc "html" org-export-html-xml-declaration))
2690 charset)
2691 language language
2692 (plist-get opt-plist :title)
2693 charset
2694 (plist-get opt-plist :effective-date)
2695 (plist-get opt-plist :author)
2696 (plist-get opt-plist :description)
2697 (plist-get opt-plist :keywords)
2698 style
2699 mathjax))))
2701 (defun org-html-end-document-content ()
2702 (insert "\n</html>\n"))
2705 ;;;_ , level
2706 (defun org-html-begin-level (level title umax head-count)
2707 "Insert a new level in HTML export.
2708 When TITLE is nil, just close all open levels."
2709 (org-parse-end 'LEVEL level umax)
2710 (unless title (error "Why is heading nil"))
2711 (let* ((target (org-get-text-property-any 0 'target title))
2712 (extra-targets (and target
2713 (assoc target org-export-target-aliases)))
2714 (extra-class (org-get-text-property-any 0 'html-container-class title))
2715 (preferred (and target
2716 (cdr (assoc target org-export-preferred-target-alist))))
2717 snumber snu href suffix tags level1)
2718 (setq extra-targets (remove (or preferred target) extra-targets))
2719 (when (string-match (org-re "\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") title)
2720 (setq tags (and org-export-with-tags (match-string 1 title)))
2721 (setq title (replace-match "" t t title)))
2722 (if (> level umax)
2723 (progn
2724 (if (aref org-levels-open (1- level))
2725 (org-close-li)
2726 (aset org-levels-open (1- level) t)
2727 (org-parse-end-paragraph)
2728 (org-parse-begin 'LIST 'unordered))
2729 (org-parse-begin
2730 'LIST-ITEM 'unordered
2731 (and target (org-solidify-link-text (or preferred target))) ;id
2732 (org-parse-format 'HEADLINE title extra-targets tags)))
2733 (aset org-levels-open (1- level) t)
2734 (setq snumber (org-section-number level)
2735 snu (replace-regexp-in-string "\\." "_" snumber))
2736 (setq level1 (+ level (or (org-parse-get 'TOPLEVEL-HLEVEL) 1) -1))
2737 (unless (= head-count 1)
2738 (org-parse-end 'SECTION))
2739 (setq href (cdr (assoc (concat "sec-" snu)
2740 org-export-preferred-target-alist)))
2741 (setq suffix (org-solidify-link-text (or href snu)))
2742 (setq href (org-solidify-link-text (or href (concat "sec-" snu))))
2743 (let ((id (format "outline-container-%s" suffix))
2744 (class (format "outline-%d" level1)))
2745 (org-parse-begin 'SECTION id class extra-class))
2746 (insert
2747 (org-parse-format 'HEADING
2748 (org-parse-format
2749 'HEADLINE title extra-targets tags snumber level1)
2750 level1 href))
2751 (let ((id (format "text-%s" suffix))
2752 (class (format "outline-text-%d" level1)))
2753 (org-parse-begin 'SECTION id class))
2755 (org-parse-begin-paragraph))))
2757 (defun org-html-end-level (level umax)
2758 (org-parse-end-paragraph)
2759 (let* ((l org-level-max))
2760 (while (>= l level)
2761 (if (aref org-levels-open (1- l))
2762 (progn
2763 ;; Terminate one level in HTML export
2764 (if (<= l umax)
2765 (org-parse-end 'SECTION)
2766 (org-close-li)
2767 (org-parse-end 'LIST 'unordered))
2768 (aset org-levels-open (1- l) nil)))
2769 (setq l (1- l)))))
2772 ;;;_ , section
2773 (defun org-html-begin-section (&optional id class extra-class)
2774 (when extra-class
2775 (setq class (concat class " " extra-class)))
2776 (let ((extra (concat (when id (format " id=\"%s\"" id))
2777 (when class (format " class=\"%s\"" class)))))
2778 (org-html-insert-tag "<div%s>" extra)))
2780 (defun org-html-end-section ()
2781 (org-html-insert-tag "</div>"))
2785 ;;;_ , paragraph
2786 (defun org-html-begin-paragraph (&optional style)
2787 (let* ((class (cdr (assoc style '((footnote . "footnote")
2788 (verse . nil)))))
2789 (extra (if class (format " class=\"%s\"" class) "")))
2790 (org-html-insert-tag "<p%s>" extra)))
2792 (defun org-html-end-paragraph ()
2793 (insert "</p>"))
2796 ;;;_ , environment
2797 (defun org-html-format-environment (style beg-end)
2798 (assert (memq style '(blockquote center verse fixedwidth quote native)) t)
2799 (case style
2800 (blockquote
2801 (case beg-end
2802 (BEGIN
2803 (org-parse-end-paragraph)
2804 (insert "<blockquote>\n")
2805 (org-parse-begin-paragraph))
2806 (END
2807 (org-parse-end-paragraph)
2808 (insert "\n</blockquote>\n")
2809 (org-parse-begin-paragraph))))
2810 (verse
2811 (case beg-end
2812 (BEGIN
2813 (org-parse-end-paragraph)
2814 (insert "\n<p class=\"verse\">\n")
2815 (setq org-par-open t))
2816 (END
2817 (insert "</p>\n")
2818 (setq org-par-open nil)
2819 (org-parse-begin-paragraph))))
2820 (center
2821 (case beg-end
2822 (BEGIN
2823 (org-parse-end-paragraph)
2824 (insert "\n<div style=\"text-align: center\">")
2825 (org-parse-begin-paragraph))
2826 (END
2827 (org-parse-end-paragraph)
2828 (insert "\n</div>")
2829 (org-parse-begin-paragraph))))
2830 (fixedwidth
2831 (case beg-end
2832 (BEGIN
2833 (org-parse-end-paragraph)
2834 (insert "<pre class=\"example\">\n"))
2835 (END
2836 (insert "</pre>\n")
2837 (org-parse-begin-paragraph))))
2838 (quote
2839 (case beg-end
2840 (BEGIN
2841 (org-parse-end-paragraph)
2842 (insert "<pre>"))
2843 (END
2844 (insert "</pre>\n")
2845 (org-parse-begin-paragraph))))
2846 (native
2847 (case beg-end
2848 (BEGIN (org-parse-end-paragraph))
2849 (END (org-parse-begin-paragraph))))
2850 (t (error "Unknown environment %s" style))))
2853 (defun org-html-begin-environment (style)
2854 (org-html-format-environment style 'BEGIN))
2856 (defun org-html-end-environment (style)
2857 (org-html-format-environment style 'END))
2860 ;;;_ , list
2861 (defun org-html-html-list-type-to-canonical-list-type (ltype)
2862 (cdr (assoc ltype '(("o" . ordered)
2863 ("u" . unordered)
2864 ("d" . description)))))
2866 (defun org-html-begin-list (ltype &optional arg1)
2867 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2868 ltype))
2870 (case ltype
2871 (ordered (let ((extra (if arg1 (format " start=\"%d\"" arg1) "")))
2872 (org-html-insert-tag "<ol%s>" extra)))
2873 (unordered (org-html-insert-tag "<ul>"))
2874 (description (org-html-insert-tag "<dl>"))
2875 (t (error "Unknown list type: %s" ltype))))
2877 (defun org-html-end-list (ltype)
2878 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2879 ltype))
2881 (org-html-insert-tag
2882 (case ltype
2883 (ordered "</ol>")
2884 (unordered "</ul>")
2885 (description "</dl>")
2886 (t (error "Unknown list type: %s" ltype)))))
2888 (defun org-html-begin-list-item (ltype &optional arg headline)
2889 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2890 ltype))
2891 (case ltype
2892 (ordered
2893 (assert (not headline) t)
2894 (let* ((counter arg)
2895 (extra (if counter (format " value=\"%s\"" counter) "")))
2896 (org-html-insert-tag "<li%s>" extra)))
2897 (unordered
2898 (let* ((id arg)
2899 (extra (if id (format " id=\"%s\"" id) "")))
2900 (org-html-insert-tag "<li%s>" extra)
2901 (when headline
2902 (insert headline (org-parse-format 'LINE-BREAK) "\n"))))
2903 (description
2904 (assert (not headline) t)
2905 (let* ((desc-tag (or arg "(no term)")))
2906 (insert
2907 (org-html-format-tags '("<dt>" . "</dt>") desc-tag))
2908 (org-html-insert-tag "<dd>")))
2909 (t (error "Unknown list type"))))
2911 (defun org-html-end-list-item (ltype)
2912 (setq ltype (or (org-html-html-list-type-to-canonical-list-type ltype)
2913 ltype))
2914 (case ltype
2915 (ordered (org-html-insert-tag "</li>"))
2916 (unordered (org-html-insert-tag "</li>"))
2917 (description (org-html-insert-tag "</dd>"))
2918 (t (error "Unknown list type"))))
2921 ;;;_ , table
2923 (defvar org-table-rowgroup-info)
2924 (defun org-parse-begin-table-rowgroup (&optional is-header-row)
2925 (push (cons (1+ org-table-rownum) :start) org-table-rowgroup-info)
2926 (org-parse-begin 'TABLE-ROWGROUP is-header-row))
2928 (defun org-html-begin-table-rowgroup (&optional is-header-row)
2929 (when org-table-rowgroup-open
2930 (org-parse-end 'TABLE-ROWGROUP))
2931 (org-html-insert-tag (if is-header-row "<thead>" "<tbody>"))
2932 (setq org-table-rowgroup-open t)
2933 (setq org-table-current-rowgroup-is-header is-header-row))
2935 (defun org-html-end-table-rowgroup ()
2936 (when org-table-rowgroup-open
2937 (setq org-table-rowgroup-open nil)
2938 (org-html-insert-tag
2939 (if org-table-current-rowgroup-is-header "</thead>" "</tbody>"))))
2941 (defun org-html-begin-table (caption label attributes)
2942 (let ((html-table-tag
2943 (org-export-splice-attributes html-table-tag attributes)))
2944 (when label
2945 (setq html-table-tag
2946 (org-export-splice-attributes
2947 html-table-tag
2948 (format "id=\"%s\"" (org-solidify-link-text label)))))
2949 (org-html-insert-tag html-table-tag))
2951 ;; Since the output of HTML table formatter can also be used in
2952 ;; DocBook document, we want to always include the caption to make
2953 ;; DocBook XML file valid.
2954 (insert (format "<caption>%s</caption>" (or caption "")) "\n"))
2956 (defun org-parse-end-table ()
2957 (when org-table-is-styled
2958 ;; column groups
2959 (unless (car org-table-colgroup-info)
2960 (setq org-table-colgroup-info
2961 (cons :start (cdr org-table-colgroup-info))))
2963 ;; column alignment
2964 (let ((c -1))
2965 (mapc
2966 (lambda (x)
2967 (incf c)
2968 (setf (aref org-table-colalign-vector c)
2969 (or (aref org-table-colalign-vector c)
2970 (if (> (/ (float x) (1+ org-table-rownum))
2971 org-table-number-fraction)
2972 "right" "left"))))
2973 org-table-num-numeric-items-per-column)))
2974 (org-parse-end 'TABLE))
2976 (defun org-html-end-table ()
2977 (when org-table-is-styled
2978 (goto-char org-table-begin-marker)
2979 (setq org-table-begin-marker nil)
2981 (let ((c -1) gr colgropen)
2982 (insert
2983 (mapconcat
2984 (lambda (x)
2985 (incf c)
2986 (setq gr (pop org-table-colgroup-info))
2988 (concat
2989 (if (memq gr '(:start :startend))
2990 (prog1
2991 (if colgropen
2992 "</colgroup>\n<colgroup>"
2993 "<colgroup>")
2994 (setq colgropen t))
2997 (let* ((align (aref org-table-colalign-vector c))
2998 (alignspec (if org-html-format-table-no-css
2999 " align=\"%s\"" " class=\"%s\""))
3000 (extra (format alignspec align)))
3001 (format "<col%s />" extra))
3003 (if (memq gr '(:end :startend))
3004 (progn (setq colgropen nil) "</colgroup>")
3005 "")))
3006 org-table-num-numeric-items-per-column ""))
3008 (if colgropen (insert "</colgroup>")))
3010 ;; fill style attributes for table cells
3011 (while (re-search-forward "@@class\\([0-9]+\\)@@" nil t)
3012 (let ((c (string-to-number (match-string 1))))
3013 (replace-match
3014 (if org-export-html-table-align-individual-fields
3015 (format (if org-html-format-table-no-css " align=\"%s\""
3016 " class=\"%s\"")
3017 (or (aref org-table-colalign-vector c) "left")) "")
3018 t t)))
3019 (goto-char (point-max)))
3020 (org-html-insert-tag "</table>\n"))
3022 (defun org-html-format-table-row (row)
3023 (org-html-format-tags
3024 (cons (eval (car org-export-table-row-tags))
3025 (eval (cdr org-export-table-row-tags))) row))
3027 (defun org-html-format-table-cell (text r c)
3028 (let ((cell-style-cookie (or (and org-table-is-styled
3029 (format "@@class%03d@@" c)) "")))
3030 (cond
3031 (org-table-current-rowgroup-is-header
3032 (org-html-format-tags
3033 org-export-table-header-tags text "col" cell-style-cookie))
3034 ((and (= c 0) org-export-html-table-use-header-tags-for-first-column)
3035 (org-html-format-tags
3036 org-export-table-header-tags text "row" cell-style-cookie))
3038 (org-html-format-tags
3039 org-export-table-data-tags text cell-style-cookie)))))
3042 ;;;_ , footnote definition
3043 (defun org-html-begin-footnote-definition (n)
3044 (org-parse-begin-paragraph 'footnote)
3045 (insert
3046 (format
3047 (format org-export-html-footnote-format
3048 "<a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a>")
3049 n n n)))
3051 (defun org-html-end-footnote-definition (n)
3052 (org-parse-end-paragraph))
3056 ;;;_ . format callbacks
3058 (defvar org-html-protect nil)
3059 ;;;_ , spaces
3060 (defun org-html-format-spaces (n)
3061 (let ((space (or (and org-html-protect "\\nbsp") "&nbsp;")) out)
3062 (while (> n 0)
3063 (setq out (concat out space))
3064 (setq n (1- n))) out))
3066 ;;;_ , tabs
3067 (defun org-html-format-tabs (&optional n)
3068 (ignore))
3070 ;;;_ , line break
3071 (defun org-html-format-line-break ()
3072 (org-html-format-tags "<br/>" ""))
3074 ;;;_ , horizontal line
3075 (defun org-html-format-horizontal-line ()
3076 (concat "\n" "<hr/>" "\n"))
3078 ;;;_ , line
3080 (defun org-html-format-plain (line)
3081 (case org-parse-dyn-current-environment
3082 ((quote fixedwidth) (concat (org-html-protect line) "\n"))
3083 (t (concat line "\n"))))
3085 (defun org-html-format-comment (fmt &rest args)
3086 (let ((comment (apply 'format fmt args)))
3087 (format "\n<!-- %s -->\n" comment)))
3090 ;;;_ , character styles
3091 (defun org-html-format-fontify (text style &optional id)
3092 (let (class extra how)
3093 (cond
3094 ((eq style 'underline)
3095 (setq extra " style=\"text-decoration:underline;\"" ))
3096 ((setq how (cdr (assoc style
3097 '((bold . ("<b>" . "</b>"))
3098 (emphasis . ("<i>" . "</i>"))
3099 (code . ("<code>" . "</code>"))
3100 (verbatim . ("<code>" . "</code>"))
3101 (strike . ("<del>" . "</del>"))
3102 (subscript . ("<sub>" . "</sub>"))
3103 (superscript . ("<sup>" . "</sup>")))))))
3104 ((listp style)
3105 (setq class (mapconcat 'identity style " ")))
3106 ((stringp style)
3107 (setq class style))
3108 (t (error "Unknown style %S" style)))
3110 (setq extra (concat (when class (format " class=\"%s\"" class))
3111 (when id (format " id=\"%s\"" id))
3112 extra))
3113 (org-html-format-tags
3114 (or how '("<span%s>" . "</span>")) text extra)))
3116 ;;;_ , link
3117 (defun org-html-format-link (text href &optional extra)
3118 (let ((extra (concat (format " href=\"%s\"" href)
3119 (and extra (concat " " extra)))))
3120 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
3122 ;;;_ , heading
3123 (defun org-html-format-heading (text level &optional id)
3124 (let* ((extra (concat (when id (format " id=\"%s\"" id)))))
3125 (concat (format "<h%d%s>" level extra) text (format "</h%d>" level))))
3127 ;;;_ , headline
3128 (defun org-html-format-headline (title extra-targets tags
3129 &optional snumber level)
3130 (concat
3131 (org-parse-format 'EXTRA-TARGETS extra-targets)
3132 (concat (org-parse-format 'SECTION-NUMBER snumber level) " ")
3133 title
3134 (and tags (concat (org-parse-format 'SPACES 3)
3135 (org-parse-format 'ORG-TAGS tags)))))
3137 ;;;_ , anchor
3138 (defun org-html-format-anchor (text name &optional class)
3139 (let* ((id name)
3140 (extra (concat
3141 (when name (format " name=\"%s\"" name))
3142 (when id (format " id=\"%s\"" id))
3143 (when class (format " class=\"%s\"" class)))))
3144 (org-html-format-tags '("<a%s>" . "</a>") text extra)))
3148 ;;;_ , target
3149 ;;;_ , footnote reference
3150 (defun org-html-format-footnote-reference (n def refcnt)
3151 (let ((extra (if (= refcnt 1) "" (format ".%d" refcnt))))
3152 (format org-export-html-footnote-format
3153 (format
3154 "<a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a>"
3155 n extra n n))))
3159 ;;;_ , footnotes section
3160 (defun org-html-format-footnotes-section (section-name definitions)
3161 (if (not definitions) ""
3162 (format org-export-html-footnotes-section section-name definitions)))
3165 ;;;_ , image
3166 ;;;_ , generic
3167 (defun org-html-format-tags (tag text &rest args)
3168 (let ((prefix (when org-html-protect "@"))
3169 (suffix (when org-html-protect "@")))
3170 (cond
3171 ((consp tag)
3172 (concat prefix (apply 'format (car tag) args) text suffix
3173 (format (cdr tag))))
3174 ((stringp tag) ; singleton tag
3175 (concat prefix (apply 'format tag args) text)))))
3177 ;;;_ . maintenance callbacks
3178 ;;;_ , init method
3179 ;;;_ , save method
3180 ;;;_ , cleanup method
3181 ;;;_ . get callback
3182 (defun org-html-get (what &optional opt-plist)
3183 (case what
3184 (BACKEND 'html)
3185 (INIT-METHOD nil)
3186 (SAVE-METHOD nil)
3187 (CLEANUP-METHOD nil)
3188 (EXPORT-DIR (org-export-directory :html opt-plist))
3189 (FILE-NAME-EXTENSION (plist-get opt-plist :html-extension))
3190 (EXPORT-BUFFER-NAME "*Org HTML Export*")
3191 (ENTITY-CONTROL org-html-entity-control-callbacks-alist)
3192 (ENTITY-FORMAT org-html-entity-format-callbacks-alist)
3193 (TOPLEVEL-HLEVEL org-export-html-toplevel-hlevel)
3194 (t (error "Unknown property: %s" what))))
3197 ;;;_ , coding system
3198 (defun org-html-get-coding-system-for-write ()
3199 (or org-export-html-coding-system
3200 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3202 (defun org-html-get-coding-system-for-save ()
3203 (or org-export-html-coding-system
3204 (and (boundp 'buffer-file-coding-system) buffer-file-coding-system)))
3207 ;;;_. newhtml (non-parser & misc)
3208 (defun org-html-insert-toc (toc)
3209 ;; locate where toc needs to be inserted
3210 (goto-char (point-min))
3211 (if (or (re-search-forward
3212 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3213 (re-search-forward
3214 "\\[TABLE-OF-CONTENTS\\]" nil t))
3215 (progn
3216 (goto-char (match-beginning 0))
3217 (replace-match ""))
3218 (goto-char org-html-dyn-first-heading-pos)
3219 (when (looking-at "\\s-*</p>")
3220 (goto-char (match-end 0))
3221 (insert "\n")))
3222 (insert toc))
3224 (defun org-html-insert-preamble (opt-plist)
3225 (when (plist-get opt-plist :html-preamble)
3226 (let ((html-pre (plist-get opt-plist :html-preamble))
3227 (title (plist-get opt-plist :title))
3228 (date (plist-get opt-plist :effective-date))
3229 (author (plist-get opt-plist :author))
3230 (lang-words (plist-get opt-plist :lang-words))
3231 (email (plist-get opt-plist :email)))
3232 (cond ((stringp html-pre)
3233 (insert
3234 (format-spec html-pre `((?t . ,title) (?a . ,author)
3235 (?d . ,date) (?e . ,email)))))
3236 ((functionp html-pre)
3237 (funcall html-pre opt-plist))
3239 (insert
3240 (format-spec
3241 (or (cadr (assoc (nth 0 lang-words)
3242 org-export-html-preamble-format))
3243 (cadr (assoc "en" org-export-html-preamble-format)))
3244 `((?t . ,title) (?a . ,author)
3245 (?d . ,date) (?e . ,email)))))))))
3247 (defun org-html-insert-postamble (opt-plist)
3248 (when org-html-footnote-definitions
3249 (insert
3250 (org-parse-format
3251 'FOOTNOTES-SECTION (nth 4 (plist-get opt-plist :lang-words))
3252 (mapconcat (lambda (x) (cdr x))
3253 (nreverse org-html-footnote-definitions) "\n"))))
3254 (let ((bib (org-export-html-get-bibliography)))
3255 (when bib
3256 (insert "\n" bib "\n")))
3258 ;; export html postamble
3259 (unless body-only
3260 (let* ((html-post (plist-get opt-plist :html-postamble))
3261 (date (plist-get opt-plist :effective-date))
3262 (author (plist-get opt-plist :author))
3263 (email (plist-get opt-plist :email))
3264 (lang-words (plist-get opt-plist :lang-words))
3265 (html-validation-link (or org-export-html-validation-link ""))
3266 (email
3267 (mapconcat (lambda(e)
3268 (format "<a href=\"mailto:%s\">%s</a>" e e))
3269 (split-string email ",+ *")
3270 ", "))
3271 (creator-info
3272 (concat "Org version " org-version " with Emacs version "
3273 (number-to-string emacs-major-version))))
3274 (when (plist-get opt-plist :html-postamble)
3275 (cond ((stringp html-post)
3276 (insert "<div id=\"postamble\">\n")
3277 (insert (format-spec html-post
3278 `((?a . ,author) (?e . ,email)
3279 (?d . ,date) (?c . ,creator-info)
3280 (?v . ,html-validation-link))))
3281 (insert "</div>"))
3282 ((functionp html-post)
3283 (funcall html-post opt-plist))
3284 ((eq html-post 'auto)
3285 ;; fall back on default postamble
3286 (insert "<div id=\"postamble\">\n")
3287 (when (plist-get opt-plist :time-stamp-file)
3288 (insert "<p class=\"date\">" (nth 2 lang-words) ": " date "</p>\n"))
3289 (when (and (plist-get opt-plist :author-info) author)
3290 (insert "<p class=\"author\">" (nth 1 lang-words) ": " author "</p>\n"))
3291 (when (and (plist-get opt-plist :email-info) email)
3292 (insert "<p class=\"email\">" email "</p>\n"))
3293 (when (plist-get opt-plist :creator-info)
3294 (insert "<p class=\"creator\">"
3295 (concat "Org version " org-version " with Emacs version "
3296 (number-to-string emacs-major-version) "</p>\n")))
3297 (insert html-validation-link "\n</div>"))
3299 (insert "<div id=\"postamble\">\n")
3300 (insert (format-spec
3301 (or (cadr (assoc (nth 0 lang-words)
3302 org-export-html-postamble-format))
3303 (cadr (assoc "en" org-export-html-postamble-format)))
3304 `((?a . ,author) (?e . ,email)
3305 (?d . ,date) (?c . ,creator-info)
3306 (?v . ,html-validation-link))))
3307 (insert "</div>"))))))
3309 (if org-export-html-with-timestamp
3310 (insert org-export-html-html-helper-timestamp)))
3312 (defun org-html-format-todo (todo)
3313 (org-parse-format 'FONTIFY
3314 (org-export-html-get-todo-kwd-class-name todo)
3315 (list (if (member todo org-done-keywords) "done" "todo")
3316 todo)))
3318 (defun org-html-format-extra-targets (extra-targets)
3319 (if (not extra-targets) ""
3320 (mapconcat (lambda (x)
3321 (setq x (org-solidify-link-text
3322 (if (org-uuidgen-p x) (concat "ID-" x) x)))
3323 (org-parse-format 'ANCHOR "" x))
3324 extra-targets "")))
3326 (defun org-html-format-org-tags (tags)
3327 (if (not tags) ""
3328 (org-parse-format
3329 'FONTIFY (mapconcat
3330 (lambda (x)
3331 (org-parse-format
3332 'FONTIFY x (org-export-html-get-tag-class-name x)))
3333 (org-split-string tags ":")
3334 (org-parse-format 'SPACES 1)) "tag")))
3336 (defun org-html-format-section-number (&optional snumber level)
3337 (and org-export-with-section-numbers
3338 (not body-only) snumber level
3339 (org-parse-format 'FONTIFY snumber (format "section-number-%d" level))))
3341 ;;;_. preprocessor
3342 ;;;_. postamble
3344 (provide 'org-html)
3346 ;; arch-tag: 8109d84d-eb8f-460b-b1a8-f45f3a6c7ea1
3347 ;;; org-html.el ends here