iCalendar and XOXO export: Functions moved to new files.
[org-mode.git] / lisp / org-exp.el
blob32dee8f708fc4e04a766c41022a9b02241860c2a
1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
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: 6.25trans
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 (require 'org)
30 (require 'org-agenda)
31 (eval-and-compile
32 (require 'cl))
34 (declare-function org-export-latex-preprocess "org-export-latex" (parameters))
35 (declare-function org-export-ascii-preprocess "org-ascii" (parameters))
36 (declare-function org-export-docbook-preprocess "org-docbook" (parameters))
37 (declare-function org-agenda-skip "org-agenda" ())
38 (declare-function org-infojs-options-inbuffer-template "org-jsinfo" ())
39 (declare-function htmlize-region "ext:htmlize" (beg end))
40 (declare-function org-id-find-id-file "org-id" (id))
41 (defvar htmlize-buffer-places) ; from htmlize.el
43 (defgroup org-export nil
44 "Options for exporting org-listings."
45 :tag "Org Export"
46 :group 'org)
48 (defgroup org-export-general nil
49 "General options for exporting Org-mode files."
50 :tag "Org Export General"
51 :group 'org-export)
53 ;; FIXME
54 (defvar org-export-publishing-directory nil)
56 (defcustom org-export-run-in-background nil
57 "Non-nil means export and publishing commands will run in background.
58 This works by starting up a separate Emacs process visiting the same file
59 and doing the export from there.
60 Not all export commands are affected by this - only the ones which
61 actually write to a file, and that do not depend on the buffer state.
63 If this option is nil, you can still get background export by calling
64 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
66 If this option is t, the double prefix can be used to exceptionally
67 force an export command into the current process."
68 :group 'org-export-general
69 :type 'boolean)
72 (defcustom org-export-select-tags '("export")
73 "Tags that select a tree for export.
74 If any such tag is found in a buffer, all trees that do not carry one
75 of these tags will be deleted before export.
76 Inside trees that are selected like this, you can still deselect a
77 subtree by tagging it with one of the `org-export-exclude-tags'."
78 :group 'org-export-general
79 :type '(repeat (string :tag "Tag")))
81 (defcustom org-export-exclude-tags '("noexport")
82 "Tags that exclude a tree from export.
83 All trees carrying any of these tags will be excluded from export.
84 This is without condition, so even subtrees inside that carry one of the
85 `org-export-select-tags' will be removed."
86 :group 'org-export-general
87 :type '(repeat (string :tag "Tag")))
89 (defcustom org-export-with-special-strings t
90 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
91 When this option is turned on, these strings will be exported as:
93 Org HTML LaTeX
94 -----+----------+--------
95 \\- &shy; \\-
96 -- &ndash; --
97 --- &mdash; ---
98 ... &hellip; \ldots
100 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
101 :group 'org-export-translation
102 :type 'boolean)
104 (defcustom org-export-language-setup
105 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
106 ("ca" "Autor" "Data" "&Iacute;ndex" "Peus de p&agrave;gina")
107 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
108 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
109 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fu&szlig;noten")
110 ("eo" "A&#365;toro" "Dato" "Enhavo" "Piednotoj")
111 ("es" "Autor" "Fecha" "&Iacute;ndice" "Pies de p&aacute;gina")
112 ("fi" "Tekij&auml;" "P&auml;iv&auml;m&auml;&auml;r&auml;" "Sis&auml;llysluettelo" "Alaviitteet")
113 ("fr" "Auteur" "Date" "Table des mati&egrave;res" "Notes de bas de page")
114 ("hu" "Szerz&otilde;" "D&aacute;tum" "Tartalomjegyz&eacute;k" "L&aacute;bjegyzet")
115 ("is" "H&ouml;fundur" "Dagsetning" "Efnisyfirlit" "Aftanm&aacute;lsgreinar")
116 ("it" "Autore" "Data" "Indice" "Note a pi&egrave; di pagina")
117 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
118 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
119 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
120 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
121 ("pl" "Autor" "Data" "Spis tre&sacute;ci" "Przypis")
122 ("sv" "F&ouml;rfattare" "Datum" "Inneh&aring;ll" "Fotnoter"))
123 "Terms used in export text, translated to different languages.
124 Use the variable `org-export-default-language' to set the language,
125 or use the +OPTION lines for a per-file setting."
126 :group 'org-export-general
127 :type '(repeat
128 (list
129 (string :tag "HTML language tag")
130 (string :tag "Author")
131 (string :tag "Date")
132 (string :tag "Table of Contents")
133 (string :tag "Footnotes"))))
135 (defcustom org-export-default-language "en"
136 "The default language of HTML export, as a string.
137 This should have an association in `org-export-language-setup'."
138 :group 'org-export-general
139 :type 'string)
141 (defvar org-export-page-description ""
142 "The page description, for the XHTML meta tag.
143 This is best set with the #+DESCRIPTION line in a file, it does not make
144 sense to set this globally.")
146 (defvar org-export-page-keywords ""
147 "The page description, for the XHTML meta tag.
148 This is best set with the #+KEYWORDS line in a file, it does not make
149 sense to set this globally.")
151 (defcustom org-export-skip-text-before-1st-heading nil
152 "Non-nil means, skip all text before the first headline when exporting.
153 When nil, that text is exported as well."
154 :group 'org-export-general
155 :type 'boolean)
157 (defcustom org-export-headline-levels 3
158 "The last level which is still exported as a headline.
159 Inferior levels will produce itemize lists when exported.
160 Note that a numeric prefix argument to an exporter function overrides
161 this setting.
163 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
164 :group 'org-export-general
165 :type 'integer)
167 (defcustom org-export-with-section-numbers t
168 "Non-nil means, add section numbers to headlines when exporting.
170 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
171 :group 'org-export-general
172 :type 'boolean)
174 (defcustom org-export-section-number-format '((("1" ".")) . "")
175 "Format of section numbers for export.
176 The variable has two components.
177 1. A list of lists, each indicating a counter type and a separator.
178 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
179 It causes causes numeric, alphabetic, or roman counters, respectively.
180 The separator is only used if another counter for a subsection is being
181 added.
182 If there are more numbered section levels than entries in this lists,
183 then the last entry will be reused.
184 2. A terminator string that will be added after the entire
185 section number."
186 :group 'org-export-general
187 :type '(cons
188 (repeat
189 (list
190 (string :tag "Counter Type")
191 (string :tag "Separator ")))
192 (string :tag "Terminator")))
194 (defcustom org-export-with-toc t
195 "Non-nil means, create a table of contents in exported files.
196 The TOC contains headlines with levels up to`org-export-headline-levels'.
197 When an integer, include levels up to N in the toc, this may then be
198 different from `org-export-headline-levels', but it will not be allowed
199 to be larger than the number of headline levels.
200 When nil, no table of contents is made.
202 Headlines which contain any TODO items will be marked with \"(*)\" in
203 ASCII export, and with red color in HTML output, if the option
204 `org-export-mark-todo-in-toc' is set.
206 In HTML output, the TOC will be clickable.
208 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
209 or \"toc:3\"."
210 :group 'org-export-general
211 :type '(choice
212 (const :tag "No Table of Contents" nil)
213 (const :tag "Full Table of Contents" t)
214 (integer :tag "TOC to level")))
216 (defcustom org-export-mark-todo-in-toc nil
217 "Non-nil means, mark TOC lines that contain any open TODO items."
218 :group 'org-export-general
219 :type 'boolean)
221 (defcustom org-export-with-todo-keywords t
222 "Non-nil means, include TODO keywords in export.
223 When nil, remove all these keywords from the export."
224 :group 'org-export-general
225 :type 'boolean)
227 (defcustom org-export-with-priority nil
228 "Non-nil means, include priority cookies in export.
229 When nil, remove priority cookies for export."
230 :group 'org-export-general
231 :type 'boolean)
233 (defcustom org-export-preserve-breaks nil
234 "Non-nil means, preserve all line breaks when exporting.
235 Normally, in HTML output paragraphs will be reformatted. In ASCII
236 export, line breaks will always be preserved, regardless of this variable.
238 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
239 :group 'org-export-general
240 :type 'boolean)
242 (defcustom org-export-with-archived-trees 'headline
243 "Whether subtrees with the ARCHIVE tag should be exported.
244 This can have three different values
245 nil Do not export, pretend this tree is not present
246 t Do export the entire tree
247 headline Only export the headline, but skip the tree below it."
248 :group 'org-export-general
249 :group 'org-archive
250 :type '(choice
251 (const :tag "not at all" nil)
252 (const :tag "headline only" 'headline)
253 (const :tag "entirely" t)))
255 (defcustom org-export-author-info t
256 "Non-nil means, insert author name and email into the exported file.
258 This option can also be set with the +OPTIONS line,
259 e.g. \"author-info:nil\"."
260 :group 'org-export-general
261 :type 'boolean)
263 (defcustom org-export-creator-info t
264 "Non-nil means, the postamble should contain a creator sentence.
265 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
266 :group 'org-export-general
267 :type 'boolean)
269 (defcustom org-export-time-stamp-file t
270 "Non-nil means, insert a time stamp into the exported file.
271 The time stamp shows when the file was created.
273 This option can also be set with the +OPTIONS line,
274 e.g. \"timestamp:nil\"."
275 :group 'org-export-general
276 :type 'boolean)
278 (defcustom org-export-with-timestamps t
279 "If nil, do not export time stamps and associated keywords."
280 :group 'org-export-general
281 :type 'boolean)
283 (defcustom org-export-remove-timestamps-from-toc t
284 "If nil, remove timestamps from the table of contents entries."
285 :group 'org-export-general
286 :type 'boolean)
288 (defcustom org-export-with-tags 'not-in-toc
289 "If nil, do not export tags, just remove them from headlines.
290 If this is the symbol `not-in-toc', tags will be removed from table of
291 contents entries, but still be shown in the headlines of the document.
293 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
294 :group 'org-export-general
295 :type '(choice
296 (const :tag "Off" nil)
297 (const :tag "Not in TOC" not-in-toc)
298 (const :tag "On" t)))
300 (defcustom org-export-with-drawers nil
301 "Non-nil means, export with drawers like the property drawer.
302 When t, all drawers are exported. This may also be a list of
303 drawer names to export."
304 :group 'org-export-general
305 :type '(choice
306 (const :tag "All drawers" t)
307 (const :tag "None" nil)
308 (repeat :tag "Selected drawers"
309 (string :tag "Drawer name"))))
311 (defvar org-export-preprocess-hook nil
312 "Hook for preprocessing an export buffer.
313 Pretty much the first thing when exporting is running this hook.")
315 (defvar org-export-preprocess-after-include-files-hook nil
316 "Hook for preprocessing an export buffer.
317 This is run after the contents of included files have been inserted.")
319 (defvar org-export-preprocess-after-tree-selection-hook nil
320 "Hook for preprocessing an export buffer.
321 This is run after selection of trees to be exported has happened.
322 This selection includes tags-based selection, as well as removal
323 of commented and archived trees.")
325 (defvar org-export-preprocess-before-backend-specifics-hook nil
326 "Hook run before backend-specific functions are called during preprocessing.")
328 (defvar org-export-preprocess-final-hook nil
329 "Hook for preprocessing an export buffer.
330 This is run as the last thing in the preprocessing buffer, just before
331 returning the buffer string to the backend.")
333 (defgroup org-export-translation nil
334 "Options for translating special ascii sequences for the export backends."
335 :tag "Org Export Translation"
336 :group 'org-export)
338 (defcustom org-export-with-emphasize t
339 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
340 If the export target supports emphasizing text, the word will be
341 typeset in bold, italic, or underlined, respectively. Works only for
342 single words, but you can say: I *really* *mean* *this*.
343 Not all export backends support this.
345 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
346 :group 'org-export-translation
347 :type 'boolean)
349 (defcustom org-export-with-footnotes t
350 "If nil, export [1] as a footnote marker.
351 Lines starting with [1] will be formatted as footnotes.
353 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
354 :group 'org-export-translation
355 :type 'boolean)
357 (defcustom org-export-html-footnotes-section "<div id=\"footnotes\">
358 <h2 class=\"footnotes\">%s: </h2>
359 <div id=\"text-footnotes\">
361 </div>
362 </div>"
363 "Format for the footnotes section.
364 Should contain a two instances of %s. The first will be replaced with the
365 language-specific word for \"Footnotes\", the second one will be replaced
366 by the footnotes themselves."
367 :group 'org-export-html
368 :type 'string)
370 (defcustom org-export-with-sub-superscripts t
371 "Non-nil means, interpret \"_\" and \"^\" for export.
372 When this option is turned on, you can use TeX-like syntax for sub- and
373 superscripts. Several characters after \"_\" or \"^\" will be
374 considered as a single item - so grouping with {} is normally not
375 needed. For example, the following things will be parsed as single
376 sub- or superscripts.
378 10^24 or 10^tau several digits will be considered 1 item.
379 10^-12 or 10^-tau a leading sign with digits or a word
380 x^2-y^3 will be read as x^2 - y^3, because items are
381 terminated by almost any nonword/nondigit char.
382 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
384 Still, ambiguity is possible - so when in doubt use {} to enclose the
385 sub/superscript. If you set this variable to the symbol `{}',
386 the braces are *required* in order to trigger interpretations as
387 sub/superscript. This can be helpful in documents that need \"_\"
388 frequently in plain text.
390 Not all export backends support this, but HTML does.
392 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
393 :group 'org-export-translation
394 :type '(choice
395 (const :tag "Always interpret" t)
396 (const :tag "Only with braces" {})
397 (const :tag "Never interpret" nil)))
399 (defcustom org-export-with-TeX-macros t
400 "Non-nil means, interpret simple TeX-like macros when exporting.
401 For example, HTML export converts \\alpha to &alpha; and \\AA to &Aring;.
402 Not only real TeX macros will work here, but the standard HTML entities
403 for math can be used as macro names as well. For a list of supported
404 names in HTML export, see the constant `org-html-entities'.
405 Not all export backends support this.
407 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
408 :group 'org-export-translation
409 :group 'org-export-latex
410 :type 'boolean)
412 (defcustom org-export-with-LaTeX-fragments nil
413 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
414 When set, the exporter will find LaTeX environments if the \\begin line is
415 the first non-white thing on a line. It will also find the math delimiters
416 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
417 display math.
419 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
420 :group 'org-export-translation
421 :group 'org-export-latex
422 :type 'boolean)
424 (defcustom org-export-with-fixed-width t
425 "Non-nil means, lines starting with \":\" will be in fixed width font.
426 This can be used to have pre-formatted text, fragments of code etc. For
427 example:
428 : ;; Some Lisp examples
429 : (while (defc cnt)
430 : (ding))
431 will be looking just like this in also HTML. See also the QUOTE keyword.
432 Not all export backends support this.
434 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
435 :group 'org-export-translation
436 :type 'boolean)
438 (defcustom org-match-sexp-depth 3
439 "Number of stacked braces for sub/superscript matching.
440 This has to be set before loading org.el to be effective."
441 :group 'org-export-translation
442 :type 'integer)
444 (defgroup org-export-tables nil
445 "Options for exporting tables in Org-mode."
446 :tag "Org Export Tables"
447 :group 'org-export)
449 (defcustom org-export-with-tables t
450 "If non-nil, lines starting with \"|\" define a table.
451 For example:
453 | Name | Address | Birthday |
454 |-------------+----------+-----------|
455 | Arthur Dent | England | 29.2.2100 |
457 Not all export backends support this.
459 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
460 :group 'org-export-tables
461 :type 'boolean)
463 (defcustom org-export-highlight-first-table-line t
464 "Non-nil means, highlight the first table line.
465 In HTML export, this means use <th> instead of <td>.
466 In tables created with table.el, this applies to the first table line.
467 In Org-mode tables, all lines before the first horizontal separator
468 line will be formatted with <th> tags."
469 :group 'org-export-tables
470 :type 'boolean)
472 (defcustom org-export-table-remove-special-lines t
473 "Remove special lines and marking characters in calculating tables.
474 This removes the special marking character column from tables that are set
475 up for spreadsheet calculations. It also removes the entire lines
476 marked with `!', `_', or `^'. The lines with `$' are kept, because
477 the values of constants may be useful to have."
478 :group 'org-export-tables
479 :type 'boolean)
481 (defcustom org-export-prefer-native-exporter-for-tables nil
482 "Non-nil means, always export tables created with table.el natively.
483 Natively means, use the HTML code generator in table.el.
484 When nil, Org-mode's own HTML generator is used when possible (i.e. if
485 the table does not use row- or column-spanning). This has the
486 advantage, that the automatic HTML conversions for math symbols and
487 sub/superscripts can be applied. Org-mode's HTML generator is also
488 much faster."
489 :group 'org-export-tables
490 :type 'boolean)
493 (defgroup org-export-xml nil
494 "Options specific for XML export of Org-mode files."
495 :tag "Org Export XML"
496 :group 'org-export)
498 (defgroup org-export-html nil
499 "Options specific for HTML export of Org-mode files."
500 :tag "Org Export HTML"
501 :group 'org-export)
503 (defcustom org-export-html-coding-system nil
504 "Coding system for HTML export, defaults to buffer-file-coding-system."
505 :group 'org-export-html
506 :type 'coding-system)
508 (defcustom org-export-html-extension "html"
509 "The extension for exported HTML files."
510 :group 'org-export-html
511 :type 'string)
513 (defcustom org-export-html-link-up ""
514 "Where should the \"UP\" link of exported HTML pages lead?"
515 :group 'org-export-html
516 :type '(string :tag "File or URL"))
518 (defcustom org-export-html-link-home ""
519 "Where should the \"HOME\" link of exported HTML pages lead?"
520 :group 'org-export-html
521 :type '(string :tag "File or URL"))
523 (defcustom org-export-html-style-include-scripts t
524 "Non-nil means, include the javascript snippets in exported HTML files.
525 The actual script is defined in `org-export-html-scripts' and should
526 not be modified."
527 :group 'org-export-html
528 :type 'boolean)
530 (defconst org-export-html-scripts
531 "<script type=\"text/javascript\">
532 <!--/*--><![CDATA[/*><!--*/
533 function CodeHighlightOn(elem, id)
535 var target = document.getElementById(id);
536 if(null != target) {
537 elem.cacheClassElem = elem.className;
538 elem.cacheClassTarget = target.className;
539 target.className = \"code-highlighted\";
540 elem.className = \"code-highlighted\";
543 function CodeHighlightOff(elem, id)
545 var target = document.getElementById(id);
546 if(elem.cacheClassElem)
547 elem.className = elem.cacheClassElem;
548 if(elem.cacheClassTarget)
549 target.className = elem.cacheClassTarget;
551 /*]]>*///-->
552 </script>"
553 "Basic javascript that is needed by HTML files produced by Org-mode.")
555 (defconst org-export-html-style-default
556 "<style type=\"text/css\">
557 <!--/*--><![CDATA[/*><!--*/
558 html { font-family: Times, serif; font-size: 12pt; }
559 .title { text-align: center; }
560 .todo { color: red; }
561 .done { color: green; }
562 .tag { background-color: #add8e6; font-weight:normal }
563 .target { }
564 .timestamp { color: #bebebe; }
565 .timestamp-kwd { color: #5f9ea0; }
566 p.verse { margin-left: 3% }
567 pre {
568 border: 1pt solid #AEBDCC;
569 background-color: #F3F5F7;
570 padding: 5pt;
571 font-family: courier, monospace;
572 font-size: 90%;
573 overflow:auto;
575 table { border-collapse: collapse; }
576 td, th { vertical-align: top; }
577 dt { font-weight: bold; }
578 div.figure { padding: 0.5em; }
579 div.figure p { text-align: center; }
580 .linenr { font-size:smaller }
581 .code-highlighted {background-color:#ffff00;}
582 .org-info-js_info-navigation { border-style:none; }
583 #org-info-js_console-label { font-size:10px; font-weight:bold;
584 white-space:nowrap; }
585 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
586 font-weight:bold; }
587 /*]]>*///-->
588 </style>"
589 "The default style specification for exported HTML files.
590 Please use the variables `org-export-html-style' and
591 `org-export-html-style-extra' to add to this style. If you wish to not
592 have the default style included, customize the variable
593 `org-export-html-style-include-default'.")
595 (defcustom org-export-html-style-include-default t
596 "Non-nil means, include the default style in exported HTML files.
597 The actual style is defined in `org-export-html-style-default' and should
598 not be modified. Use the variables `org-export-html-style' to add
599 your own style information."
600 :group 'org-export-html
601 :type 'boolean)
602 ;;;###autoload
603 (put 'org-export-html-style 'safe-local-variable 'booleanp)
605 (defcustom org-export-html-style ""
606 "Org-wide style definitions for exported HTML files.
608 This variable needs to contain the full HTML structure to provide a style,
609 including the surrounding HTML tags. If you set the value of this variable,
610 you should consider to include definitions for the following classes:
611 title, todo, done, timestamp, timestamp-kwd, tag, target.
613 For example, a valid value would be:
615 <style type=\"text/css\">
616 <![CDATA[
617 p { font-weight: normal; color: gray; }
618 h1 { color: black; }
619 .title { text-align: center; }
620 .todo, .timestamp-kwd { color: red; }
621 .done { color: green; }
623 </style>
625 If you'd like to refer to en external style file, use something like
627 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
629 As the value of this option simply gets inserted into the HTML <head> header,
630 you can \"misuse\" it to add arbitrary text to the header.
631 See also the variable `org-export-html-style-extra'."
632 :group 'org-export-html
633 :type 'string)
634 ;;;###autoload
635 (put 'org-export-html-style 'safe-local-variable 'stringp)
637 (defcustom org-export-html-style-extra ""
638 "Additional style information for HTML export.
639 The value of this variable is inserted into the HTML buffer right after
640 the value of `org-export-html-style'. Use this variable for per-file
641 settings of style information, and do not forget to surround the style
642 settings with <style>...</style> tags."
643 :group 'org-export-html
644 :type 'string)
645 ;;;###autoload
646 (put 'org-export-html-style-extra 'safe-local-variable 'stringp)
648 (defcustom org-export-html-tag-class-prefix ""
649 "Prefix to clas names for TODO keywords.
650 Each tag gets a class given by the tag itself, with this prefix.
651 The default prefix is empty because it is nice to just use the keyword
652 as a class name. But if you get into conflicts with other, existing
653 CSS classes, then this prefic can be very useful."
654 :group 'org-export-html
655 :type 'string)
657 (defcustom org-export-html-todo-kwd-class-prefix ""
658 "Prefix to clas names for TODO keywords.
659 Each TODO keyword gets a class given by the keyword itself, with this prefix.
660 The default prefix is empty because it is nice to just use the keyword
661 as a class name. But if you get into conflicts with other, existing
662 CSS classes, then this prefic can be very useful."
663 :group 'org-export-html
664 :type 'string)
666 (defcustom org-export-html-title-format "<h1 class=\"title\">%s</h1>\n"
667 "Format for typesetting the document title in HTML export."
668 :group 'org-export-html
669 :type 'string)
671 (defcustom org-export-html-toplevel-hlevel 2
672 "The <H> level for level 1 headings in HTML export.
673 This is also important for the classes that will be wrapped around headlines
674 and outline structure. If this variable is 1, the top-level headlines will
675 be <h1>, and the corresponding classes will be outline-1, section-number-1,
676 and outline-text-1. If this is 2, all of these will get a 2 instead.
677 The default for this variable is 2, because we use <h1> for formatting the
678 document title."
679 :group 'org-export-html
680 :type 'string)
682 (defcustom org-export-html-link-org-files-as-html t
683 "Non-nil means, make file links to `file.org' point to `file.html'.
684 When org-mode is exporting an org-mode file to HTML, links to
685 non-html files are directly put into a href tag in HTML.
686 However, links to other Org-mode files (recognized by the
687 extension `.org.) should become links to the corresponding html
688 file, assuming that the linked org-mode file will also be
689 converted to HTML.
690 When nil, the links still point to the plain `.org' file."
691 :group 'org-export-html
692 :type 'boolean)
694 (defcustom org-export-html-inline-images 'maybe
695 "Non-nil means, inline images into exported HTML pages.
696 This is done using an <img> tag. When nil, an anchor with href is used to
697 link to the image. If this option is `maybe', then images in links with
698 an empty description will be inlined, while images with a description will
699 be linked only."
700 :group 'org-export-html
701 :type '(choice (const :tag "Never" nil)
702 (const :tag "Always" t)
703 (const :tag "When there is no description" maybe)))
705 (defcustom org-export-html-inline-image-extensions
706 '("png" "jpeg" "jpg" "gif")
707 "Extensions of image files that can be inlined into HTML."
708 :group 'org-export-html
709 :type '(repeat (string :tag "Extension")))
711 ;; FIXME: rename
712 (defcustom org-export-html-expand t
713 "Non-nil means, for HTML export, treat @<...> as HTML tag.
714 When nil, these tags will be exported as plain text and therefore
715 not be interpreted by a browser.
717 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
718 :group 'org-export-html
719 :type 'boolean)
721 (defcustom org-export-html-table-tag
722 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
723 "The HTML tag that is used to start a table.
724 This must be a <table> tag, but you may change the options like
725 borders and spacing."
726 :group 'org-export-html
727 :type 'string)
729 (defcustom org-export-table-header-tags '("<th>" . "</th>")
730 "The opening tag for table header fields.
731 This is customizable so that alignment options can be specified."
732 :group 'org-export-tables
733 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
735 (defcustom org-export-table-data-tags '("<td>" . "</td>")
736 "The opening tag for table data fields.
737 This is customizable so that alignment options can be specified."
738 :group 'org-export-tables
739 :type '(cons (string :tag "Opening tag") (string :tag "Closing tag")))
741 (defcustom org-export-html-validation-link nil
742 "Non-nil means, add validationlink to postamble of HTML exported files."
743 :group 'org-export-html
744 :type '(choice
745 (const :tag "Nothing" nil)
746 (const :tag "XHTML 1.0" "<p class=\"xhtml-validation\"><a href=\"http://validator.w3.org/check?uri=referer\">Validate XHTML 1.0</a></p>")
747 (string :tag "Specify full HTML")))
750 (defcustom org-export-html-with-timestamp nil
751 "If non-nil, write `org-export-html-html-helper-timestamp'
752 into the exported HTML text. Otherwise, the buffer will just be saved
753 to a file."
754 :group 'org-export-html
755 :type 'boolean)
757 (defcustom org-export-html-html-helper-timestamp
758 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
759 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
760 :group 'org-export-html
761 :type 'string)
763 (defgroup org-export-htmlize nil
764 "Options for processing examples with htmlize.el."
765 :tag "Org Export Htmlize"
766 :group 'org-export-html)
768 (defcustom org-export-htmlize-output-type 'inline-css
769 "Output type to be used by htmlize when formatting code snippets.
770 We use as default `inline-css', in order to make the resulting
771 HTML self-containing.
772 However, this will fail when using Emacs in batch mode for export, because
773 then no rich font definitions are in place. It will also not be good if
774 people with different Emacs setup contribute HTML files to a website,
775 because the fonts will represent the individual setups. In these cases,
776 it is much better to let Org/Htmlize assign classes only, and to use
777 a style file to define the look of these classes.
778 To get a start for your css file, start Emacs session nnd make sure that
779 all the faces you are interested in are defined, for example by loading files
780 in all modes you want. Then, use the command
781 \\[org-export-htmlize-generate-css] to extract class definitions."
782 :group 'org-export-htmlize
783 :type '(choice (const css) (const inline-css)))
785 (defcustom org-export-htmlize-css-font-prefix "org-"
786 "The prefix for CSS class names for htmlize font specifications."
787 :group 'org-export-htmlize
788 :type 'string)
790 ;;;; Exporting
792 ;;; Variables, constants, and parameter plists
794 (defconst org-level-max 20)
796 (defvar org-export-html-preamble nil
797 "Preamble, to be inserted just before <body>. Set by publishing functions.")
798 (defvar org-export-html-postamble nil
799 "Preamble, to be inserted just after </body>. Set by publishing functions.")
800 (defvar org-export-html-auto-preamble t
801 "Should default preamble be inserted? Set by publishing functions.")
802 (defvar org-export-html-auto-postamble t
803 "Should default postamble be inserted? Set by publishing functions.")
804 (defvar org-current-export-file nil) ; dynamically scoped parameter
805 (defvar org-current-export-dir nil) ; dynamically scoped parameter
806 (defvar org-export-opt-plist nil
807 "Contains the current option plist.")
808 (defvar org-last-level nil) ; dynamically scoped variable
809 (defvar org-min-level nil) ; dynamically scoped variable
810 (defvar org-levels-open nil) ; dynamically scoped parameter
812 (defconst org-export-plist-vars
813 '((:link-up nil org-export-html-link-up)
814 (:link-home nil org-export-html-link-home)
815 (:language nil org-export-default-language)
816 (:keywords nil org-export-page-keywords)
817 (:description nil org-export-page-description)
818 (:customtime nil org-display-custom-times)
819 (:headline-levels "H" org-export-headline-levels)
820 (:section-numbers "num" org-export-with-section-numbers)
821 (:section-number-format nil org-export-section-number-format)
822 (:table-of-contents "toc" org-export-with-toc)
823 (:preserve-breaks "\\n" org-export-preserve-breaks)
824 (:archived-trees nil org-export-with-archived-trees)
825 (:emphasize "*" org-export-with-emphasize)
826 (:sub-superscript "^" org-export-with-sub-superscripts)
827 (:special-strings "-" org-export-with-special-strings)
828 (:footnotes "f" org-export-with-footnotes)
829 (:drawers "d" org-export-with-drawers)
830 (:tags "tags" org-export-with-tags)
831 (:todo-keywords "todo" org-export-with-todo-keywords)
832 (:priority "pri" org-export-with-priority)
833 (:TeX-macros "TeX" org-export-with-TeX-macros)
834 (:LaTeX-fragments "LaTeX" org-export-with-LaTeX-fragments)
835 (:skip-before-1st-heading "skip" org-export-skip-text-before-1st-heading)
836 (:fixed-width ":" org-export-with-fixed-width)
837 (:timestamps "<" org-export-with-timestamps)
838 (:author-info "author" org-export-author-info)
839 (:creator-info "creator" org-export-creator-info)
840 (:time-stamp-file "timestamp" org-export-time-stamp-file)
841 (:tables "|" org-export-with-tables)
842 (:table-auto-headline nil org-export-highlight-first-table-line)
843 (:style-include-default nil org-export-html-style-include-default)
844 (:style-include-scripts nil org-export-html-style-include-scripts)
845 (:style nil org-export-html-style)
846 (:style-extra nil org-export-html-style-extra)
847 (:agenda-style nil org-agenda-export-html-style)
848 (:convert-org-links nil org-export-html-link-org-files-as-html)
849 (:inline-images nil org-export-html-inline-images)
850 (:html-extension nil org-export-html-extension)
851 (:html-table-tag nil org-export-html-table-tag)
852 (:expand-quoted-html "@" org-export-html-expand)
853 (:timestamp nil org-export-html-with-timestamp)
854 (:publishing-directory nil org-export-publishing-directory)
855 (:preamble nil org-export-html-preamble)
856 (:postamble nil org-export-html-postamble)
857 (:auto-preamble nil org-export-html-auto-preamble)
858 (:auto-postamble nil org-export-html-auto-postamble)
859 (:author nil user-full-name)
860 (:email nil user-mail-address)
861 (:select-tags nil org-export-select-tags)
862 (:exclude-tags nil org-export-exclude-tags))
863 "List of properties that represent export/publishing variables.
864 Each element is a list of 3 items:
865 1. The property that is used internally, and also for org-publish-project-alist
866 2. The string that can be used in the OPTION lines to set this option,
867 or nil if this option cannot be changed in this way
868 3. The customization variable that sets the default for this option."
872 (defun org-default-export-plist ()
873 "Return the property list with default settings for the export variables."
874 (let ((l org-export-plist-vars) rtn e)
875 (while (setq e (pop l))
876 (setq rtn (cons (car e) (cons (symbol-value (nth 2 e)) rtn))))
877 rtn))
879 (defvar org-export-inbuffer-options-extra nil
880 "List of additional in-buffer options that should be detected.
881 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
882 etc. Extensions can add to this list to get their options detected, and they
883 can then add a function to `org-export-options-filters' to process these
884 options.
885 Each element in this list must be a list, with the in-buffer keyword as car,
886 and a property (a symbol) as the next element. All occurrences of the
887 keyword will be found, the values concatenated with a space character
888 in between, and the result stored in the export options property list.")
890 (defvar org-export-options-filters nil
891 "Functions to be called to finalize the export/publishing options.
892 All these options are stored in a property list, and each of the functions
893 in this hook gets a chance to modify this property list. Each function
894 must accept the property list as an argument, and must return the (possibly
895 modified) list.")
897 ;; FIXME: should we fold case here?
898 (defun org-infile-export-plist ()
899 "Return the property list with file-local settings for export."
900 (save-excursion
901 (save-restriction
902 (widen)
903 (goto-char (point-min))
904 (let ((re (org-make-options-regexp
905 (append
906 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
907 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
908 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS"
909 "KEYWORDS" "DESCRIPTION")
910 (mapcar 'car org-export-inbuffer-options-extra))))
911 p key val text options a pr style
912 latex-header
913 ext-setup-or-nil setup-contents (start 0))
914 (while (or (and ext-setup-or-nil
915 (string-match re ext-setup-or-nil start)
916 (setq start (match-end 0)))
917 (and (setq ext-setup-or-nil nil start 0)
918 (re-search-forward re nil t)))
919 (setq key (upcase (org-match-string-no-properties 1 ext-setup-or-nil))
920 val (org-match-string-no-properties 2 ext-setup-or-nil))
921 (cond
922 ((setq a (assoc key org-export-inbuffer-options-extra))
923 (setq pr (nth 1 a))
924 (setq p (plist-put p pr (concat (plist-get p pr) " " val))))
925 ((string-equal key "TITLE") (setq p (plist-put p :title val)))
926 ((string-equal key "AUTHOR")(setq p (plist-put p :author val)))
927 ((string-equal key "EMAIL") (setq p (plist-put p :email val)))
928 ((string-equal key "DATE") (setq p (plist-put p :date val)))
929 ((string-equal key "KEYWORDS") (setq p (plist-put p :keywords val)))
930 ((string-equal key "DESCRIPTION")
931 (setq p (plist-put p :description val)))
932 ((string-equal key "LANGUAGE") (setq p (plist-put p :language val)))
933 ((string-equal key "STYLE")
934 (setq style (concat style "\n" val)))
935 ((string-equal key "LATEX_HEADER")
936 (setq latex-header (concat latex-header "\n" val)))
937 ((string-equal key "TEXT")
938 (setq text (if text (concat text "\n" val) val)))
939 ((string-equal key "OPTIONS")
940 (setq options (concat val " " options)))
941 ((string-equal key "LINK_UP")
942 (setq p (plist-put p :link-up val)))
943 ((string-equal key "LINK_HOME")
944 (setq p (plist-put p :link-home val)))
945 ((string-equal key "EXPORT_SELECT_TAGS")
946 (setq p (plist-put p :select-tags (org-split-string val))))
947 ((string-equal key "EXPORT_EXCLUDE_TAGS")
948 (setq p (plist-put p :exclude-tags (org-split-string val))))
949 ((equal key "SETUPFILE")
950 (setq setup-contents (org-file-contents
951 (expand-file-name
952 (org-remove-double-quotes
953 (org-trim val)))
954 'noerror))
955 (if (not ext-setup-or-nil)
956 (setq ext-setup-or-nil setup-contents start 0)
957 (setq ext-setup-or-nil
958 (concat (substring ext-setup-or-nil 0 start)
959 "\n" setup-contents "\n"
960 (substring ext-setup-or-nil start)))))))
961 (setq p (plist-put p :text text))
962 (when style (setq p (plist-put p :style-extra style)))
963 (when latex-header
964 (setq p (plist-put p :latex-header-extra (substring latex-header 1))))
965 (when options
966 (setq p (org-export-add-options-to-plist p options)))
967 ;; Add macro definitions
968 (goto-char (point-min))
969 (while (re-search-forward
970 "^#\\+macro:[ \t]+\\([-a-zA-Z0-9_]+\\)[ \t]+\\(.*?[ \t]*$\\)"
971 nil t)
972 (setq p (plist-put p (intern (concat ":macro-"
973 (downcase (match-string 1))))
974 (match-string 2))))
975 p))))
977 (defun org-export-add-options-to-plist (p options)
978 "Parse an OPTIONS line and set values in the property list P."
979 (let (o)
980 (when options
981 (let ((op org-export-plist-vars))
982 (while (setq o (pop op))
983 (if (and (nth 1 o)
984 (string-match (concat (regexp-quote (nth 1 o))
985 ":\\([^ \t\n\r;,.]*\\)")
986 options))
987 (setq p (plist-put p (car o)
988 (car (read-from-string
989 (match-string 1 options))))))))))
992 (defun org-export-add-subtree-options (p pos)
993 "Add options in subtree at position POS to property list P."
994 (save-excursion
995 (goto-char pos)
996 (when (org-at-heading-p)
997 (let (a)
998 ;; This is actually read in `org-export-get-title-from-subtree'
999 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1000 ;; (setq p (plist-put p :title a)))
1001 (when (setq a (org-entry-get pos "EXPORT_TEXT"))
1002 (setq p (plist-put p :text a)))
1003 (when (setq a (org-entry-get pos "EXPORT_OPTIONS"))
1004 (setq p (org-export-add-options-to-plist p a)))))
1007 (defun org-export-directory (type plist)
1008 (let* ((val (plist-get plist :publishing-directory))
1009 (dir (if (listp val)
1010 (or (cdr (assoc type val)) ".")
1011 val)))
1012 dir))
1014 (defun org-export-process-option-filters (plist)
1015 (let ((functions org-export-options-filters) f)
1016 (while (setq f (pop functions))
1017 (setq plist (funcall f plist))))
1018 plist)
1020 ;;;###autoload
1021 (defun org-export (&optional arg)
1022 "Export dispatcher for Org-mode.
1023 When `org-export-run-in-background' is non-nil, try to run the command
1024 in the background. This will be done only for commands that write
1025 to a file. For details see the docstring of `org-export-run-in-background'.
1027 The prefix argument ARG will be passed to the exporter. However, if
1028 ARG is a double universal prefix `C-u C-u', that means to inverse the
1029 value of `org-export-run-in-background'."
1030 (interactive "P")
1031 (let* ((bg (org-xor (equal arg '(16)) org-export-run-in-background))
1032 (help "[t] insert the export option template
1033 \[v] limit export to visible part of outline tree
1035 \[a] export as ASCII
1037 \[h] export as HTML [H] to temporary buffer [R] export region
1038 \[b] export as HTML and open in browser
1040 \[l] export as LaTeX [L] to temporary buffer
1041 \[p] export as LaTeX and process to PDF
1042 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1044 \[D] export as DocBook
1045 \[V] export as DocBook, process to PDF, and open the resulting PDF document
1047 \[x] export as XOXO
1049 \[i] export current file as iCalendar file
1050 \[I] export all agenda files as iCalendar files
1051 \[c] export agenda files into combined iCalendar file
1053 \[F] publish current file [P] publish current project
1054 \[X] publish a project... [A] publish all projects")
1055 (cmds
1056 '((?t org-insert-export-options-template nil)
1057 (?v org-export-visible nil)
1058 (?a org-export-as-ascii t)
1059 (?h org-export-as-html t)
1060 (?b org-export-as-html-and-open t)
1061 (?H org-export-as-html-to-buffer nil)
1062 (?R org-export-region-as-html nil)
1063 (?x org-export-as-xoxo t)
1064 (?D org-export-as-docbook t)
1065 (?V org-export-as-docbook-pdf-and-open t)
1066 (?l org-export-as-latex t)
1067 (?p org-export-as-pdf t)
1068 (?d org-export-as-pdf-and-open t)
1069 (?L org-export-as-latex-to-buffer nil)
1070 (?i org-export-icalendar-this-file t)
1071 (?I org-export-icalendar-all-agenda-files t)
1072 (?c org-export-icalendar-combine-agenda-files t)
1073 (?F org-publish-current-file t)
1074 (?P org-publish-current-project t)
1075 (?X org-publish t)
1076 (?A org-publish-all t)))
1077 r1 r2 ass)
1078 (save-excursion
1079 (save-window-excursion
1080 (delete-other-windows)
1081 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1082 (princ help))
1083 (org-fit-window-to-buffer (get-buffer-window
1084 "*Org Export/Publishing Help*"))
1085 (message "Select command: ")
1086 (setq r1 (read-char-exclusive))))
1087 (setq r2 (if (< r1 27) (+ r1 96) r1))
1088 (unless (setq ass (assq r2 cmds))
1089 (error "No command associated with key %c" r1))
1090 (if (and bg (nth 2 ass)
1091 (not (buffer-base-buffer))
1092 (not (org-region-active-p)))
1093 ;; execute in background
1094 (let ((p (start-process
1095 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1096 "*Org Processes*"
1097 (expand-file-name invocation-name invocation-directory)
1098 "-batch"
1099 "-l" user-init-file
1100 "--eval" "(require 'org-exp)"
1101 "--eval" "(setq org-wait .2)"
1102 (buffer-file-name)
1103 "-f" (symbol-name (nth 1 ass)))))
1104 (set-process-sentinel p 'org-export-process-sentinel)
1105 (message "Background process \"%s\": started" p))
1106 ;; background processing not requested, or not possible
1107 (call-interactively (nth 1 ass)))))
1109 (defun org-export-process-sentinel (process status)
1110 (if (string-match "\n+\\'" status)
1111 (setq status (substring status 0 -1)))
1112 (message "Background process \"%s\": %s" process status))
1114 (defconst org-html-entities
1115 '(("nbsp")
1116 ("iexcl")
1117 ("cent")
1118 ("pound")
1119 ("curren")
1120 ("yen")
1121 ("brvbar")
1122 ("vert" . "&#124;")
1123 ("sect")
1124 ("uml")
1125 ("copy")
1126 ("ordf")
1127 ("laquo")
1128 ("not")
1129 ("shy")
1130 ("reg")
1131 ("macr")
1132 ("deg")
1133 ("plusmn")
1134 ("sup2")
1135 ("sup3")
1136 ("acute")
1137 ("micro")
1138 ("para")
1139 ("middot")
1140 ("odot"."o")
1141 ("star"."*")
1142 ("cedil")
1143 ("sup1")
1144 ("ordm")
1145 ("raquo")
1146 ("frac14")
1147 ("frac12")
1148 ("frac34")
1149 ("iquest")
1150 ("Agrave")
1151 ("Aacute")
1152 ("Acirc")
1153 ("Atilde")
1154 ("Auml")
1155 ("Aring") ("AA"."&Aring;")
1156 ("AElig")
1157 ("Ccedil")
1158 ("Egrave")
1159 ("Eacute")
1160 ("Ecirc")
1161 ("Euml")
1162 ("Igrave")
1163 ("Iacute")
1164 ("Icirc")
1165 ("Iuml")
1166 ("ETH")
1167 ("Ntilde")
1168 ("Ograve")
1169 ("Oacute")
1170 ("Ocirc")
1171 ("Otilde")
1172 ("Ouml")
1173 ("times")
1174 ("Oslash")
1175 ("Ugrave")
1176 ("Uacute")
1177 ("Ucirc")
1178 ("Uuml")
1179 ("Yacute")
1180 ("THORN")
1181 ("szlig")
1182 ("agrave")
1183 ("aacute")
1184 ("acirc")
1185 ("atilde")
1186 ("auml")
1187 ("aring")
1188 ("aelig")
1189 ("ccedil")
1190 ("egrave")
1191 ("eacute")
1192 ("ecirc")
1193 ("euml")
1194 ("igrave")
1195 ("iacute")
1196 ("icirc")
1197 ("iuml")
1198 ("eth")
1199 ("ntilde")
1200 ("ograve")
1201 ("oacute")
1202 ("ocirc")
1203 ("otilde")
1204 ("ouml")
1205 ("divide")
1206 ("oslash")
1207 ("ugrave")
1208 ("uacute")
1209 ("ucirc")
1210 ("uuml")
1211 ("yacute")
1212 ("thorn")
1213 ("yuml")
1214 ("fnof")
1215 ("Alpha")
1216 ("Beta")
1217 ("Gamma")
1218 ("Delta")
1219 ("Epsilon")
1220 ("Zeta")
1221 ("Eta")
1222 ("Theta")
1223 ("Iota")
1224 ("Kappa")
1225 ("Lambda")
1226 ("Mu")
1227 ("Nu")
1228 ("Xi")
1229 ("Omicron")
1230 ("Pi")
1231 ("Rho")
1232 ("Sigma")
1233 ("Tau")
1234 ("Upsilon")
1235 ("Phi")
1236 ("Chi")
1237 ("Psi")
1238 ("Omega")
1239 ("alpha")
1240 ("beta")
1241 ("gamma")
1242 ("delta")
1243 ("epsilon")
1244 ("varepsilon"."&epsilon;")
1245 ("zeta")
1246 ("eta")
1247 ("theta")
1248 ("iota")
1249 ("kappa")
1250 ("lambda")
1251 ("mu")
1252 ("nu")
1253 ("xi")
1254 ("omicron")
1255 ("pi")
1256 ("rho")
1257 ("sigmaf") ("varsigma"."&sigmaf;")
1258 ("sigma")
1259 ("tau")
1260 ("upsilon")
1261 ("phi")
1262 ("chi")
1263 ("psi")
1264 ("omega")
1265 ("thetasym") ("vartheta"."&thetasym;")
1266 ("upsih")
1267 ("piv")
1268 ("bull") ("bullet"."&bull;")
1269 ("hellip") ("dots"."&hellip;")
1270 ("prime")
1271 ("Prime")
1272 ("oline")
1273 ("frasl")
1274 ("weierp")
1275 ("image")
1276 ("real")
1277 ("trade")
1278 ("alefsym")
1279 ("larr") ("leftarrow"."&larr;") ("gets"."&larr;")
1280 ("uarr") ("uparrow"."&uarr;")
1281 ("rarr") ("to"."&rarr;") ("rightarrow"."&rarr;")
1282 ("darr")("downarrow"."&darr;")
1283 ("harr") ("leftrightarrow"."&harr;")
1284 ("crarr") ("hookleftarrow"."&crarr;") ; has round hook, not quite CR
1285 ("lArr") ("Leftarrow"."&lArr;")
1286 ("uArr") ("Uparrow"."&uArr;")
1287 ("rArr") ("Rightarrow"."&rArr;")
1288 ("dArr") ("Downarrow"."&dArr;")
1289 ("hArr") ("Leftrightarrow"."&hArr;")
1290 ("forall")
1291 ("part") ("partial"."&part;")
1292 ("exist") ("exists"."&exist;")
1293 ("empty") ("emptyset"."&empty;")
1294 ("nabla")
1295 ("isin") ("in"."&isin;")
1296 ("notin")
1297 ("ni")
1298 ("prod")
1299 ("sum")
1300 ("minus")
1301 ("lowast") ("ast"."&lowast;")
1302 ("radic")
1303 ("prop") ("proptp"."&prop;")
1304 ("infin") ("infty"."&infin;")
1305 ("ang") ("angle"."&ang;")
1306 ("and") ("wedge"."&and;")
1307 ("or") ("vee"."&or;")
1308 ("cap")
1309 ("cup")
1310 ("int")
1311 ("there4")
1312 ("sim")
1313 ("cong") ("simeq"."&cong;")
1314 ("asymp")("approx"."&asymp;")
1315 ("ne") ("neq"."&ne;")
1316 ("equiv")
1317 ("le")
1318 ("ge")
1319 ("sub") ("subset"."&sub;")
1320 ("sup") ("supset"."&sup;")
1321 ("nsub")
1322 ("sube")
1323 ("supe")
1324 ("oplus")
1325 ("otimes")
1326 ("perp")
1327 ("sdot") ("cdot"."&sdot;")
1328 ("lceil")
1329 ("rceil")
1330 ("lfloor")
1331 ("rfloor")
1332 ("lang")
1333 ("rang")
1334 ("loz") ("Diamond"."&loz;")
1335 ("spades") ("spadesuit"."&spades;")
1336 ("clubs") ("clubsuit"."&clubs;")
1337 ("hearts") ("diamondsuit"."&hearts;")
1338 ("diams") ("diamondsuit"."&diams;")
1339 ("smile"."&#9786;") ("blacksmile"."&#9787;") ("sad"."&#9785;")
1340 ("quot")
1341 ("amp")
1342 ("lt")
1343 ("gt")
1344 ("OElig")
1345 ("oelig")
1346 ("Scaron")
1347 ("scaron")
1348 ("Yuml")
1349 ("circ")
1350 ("tilde")
1351 ("ensp")
1352 ("emsp")
1353 ("thinsp")
1354 ("zwnj")
1355 ("zwj")
1356 ("lrm")
1357 ("rlm")
1358 ("ndash")
1359 ("mdash")
1360 ("lsquo")
1361 ("rsquo")
1362 ("sbquo")
1363 ("ldquo")
1364 ("rdquo")
1365 ("bdquo")
1366 ("dagger")
1367 ("Dagger")
1368 ("permil")
1369 ("lsaquo")
1370 ("rsaquo")
1371 ("euro")
1373 ("arccos"."arccos")
1374 ("arcsin"."arcsin")
1375 ("arctan"."arctan")
1376 ("arg"."arg")
1377 ("cos"."cos")
1378 ("cosh"."cosh")
1379 ("cot"."cot")
1380 ("coth"."coth")
1381 ("csc"."csc")
1382 ("deg"."deg")
1383 ("det"."det")
1384 ("dim"."dim")
1385 ("exp"."exp")
1386 ("gcd"."gcd")
1387 ("hom"."hom")
1388 ("inf"."inf")
1389 ("ker"."ker")
1390 ("lg"."lg")
1391 ("lim"."lim")
1392 ("liminf"."liminf")
1393 ("limsup"."limsup")
1394 ("ln"."ln")
1395 ("log"."log")
1396 ("max"."max")
1397 ("min"."min")
1398 ("Pr"."Pr")
1399 ("sec"."sec")
1400 ("sin"."sin")
1401 ("sinh"."sinh")
1402 ("sup"."sup")
1403 ("tan"."tan")
1404 ("tanh"."tanh")
1406 "Entities for TeX->HTML translation.
1407 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1408 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1409 In that case, \"\\ent\" will be translated to \"&other;\".
1410 The list contains HTML entities for Latin-1, Greek and other symbols.
1411 It is supplemented by a number of commonly used TeX macros with appropriate
1412 translations. There is currently no way for users to extend this.")
1414 ;;; General functions for all backends
1416 (defvar org-export-target-aliases nil
1417 "Alist of targets with invisible aliases.")
1418 (defvar org-export-code-refs nil
1419 "Alist of code references and line numbers")
1421 (defun org-export-preprocess-string (string &rest parameters)
1422 "Cleanup STRING so that that the true exported has a more consistent source.
1423 This function takes STRING, which should be a buffer-string of an org-file
1424 to export. It then creates a temporary buffer where it does its job.
1425 The result is then again returned as a string, and the exporter works
1426 on this string to produce the exported version."
1427 (interactive)
1428 (let* ((htmlp (plist-get parameters :for-html))
1429 (asciip (plist-get parameters :for-ascii))
1430 (latexp (plist-get parameters :for-LaTeX))
1431 (docbookp (plist-get parameters :for-docbook))
1432 (backend (cond (htmlp 'html)
1433 (latexp 'latex)
1434 (asciip 'ascii)
1435 (docbookp 'docbook)))
1436 (archived-trees (plist-get parameters :archived-trees))
1437 (inhibit-read-only t)
1438 (drawers org-drawers)
1439 (outline-regexp "\\*+ ")
1440 target-alist rtn)
1442 (setq org-export-target-aliases nil)
1443 (setq org-export-code-refs nil)
1445 (with-current-buffer (get-buffer-create " org-mode-tmp")
1446 (erase-buffer)
1447 (insert string)
1448 (setq case-fold-search t)
1450 ;; Remove license-to-kill stuff
1451 ;; The caller marks some stuff for killing, stuff that has been
1452 ;; used to create the page title, for example.
1453 (org-export-kill-licensed-text)
1455 (let ((org-inhibit-startup t)) (org-mode))
1456 (setq case-fold-search t)
1458 ;; Call the hook
1459 (run-hooks 'org-export-preprocess-hook)
1461 ;; Process the macros
1462 (org-export-preprocess-apply-macros)
1463 (run-hooks 'org-export-preprocess-after-macros-hook)
1465 (untabify (point-min) (point-max))
1467 ;; Handle include files, and call a hook
1468 (org-export-handle-include-files)
1469 (run-hooks 'org-export-preprocess-after-include-files-hook)
1471 ;; Get rid of archived trees
1472 (org-export-remove-archived-trees archived-trees)
1474 ;; Remove comment environment and comment subtrees
1475 (org-export-remove-comment-blocks-and-subtrees)
1477 ;; Get rid of excluded trees, and call a hook
1478 (org-export-handle-export-tags (plist-get parameters :select-tags)
1479 (plist-get parameters :exclude-tags))
1480 (run-hooks 'org-export-preprocess-after-tree-selection-hook)
1482 ;; Handle source code snippets
1483 (org-export-replace-src-segments-and-examples backend)
1485 ;; Protect short examples marked by a leading colon
1486 (org-export-protect-colon-examples)
1488 ;; Normalize footnotes
1489 (when (plist-get parameters :footnotes)
1490 (org-footnote-normalize nil t))
1492 ;; Find all headings and compute the targets for them
1493 (setq target-alist (org-export-define-heading-targets target-alist))
1495 ;; Get rid of drawers
1496 (org-export-remove-or-extract-drawers drawers
1497 (plist-get parameters :drawers))
1499 ;; Get the correct stuff before the first headline
1500 (when (plist-get parameters :skip-before-1st-heading)
1501 (goto-char (point-min))
1502 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t)
1503 (delete-region (point-min) (match-beginning 0))
1504 (goto-char (point-min))
1505 (insert "\n")))
1506 (when (plist-get parameters :add-text)
1507 (goto-char (point-min))
1508 (insert (plist-get parameters :add-text) "\n"))
1510 ;; Remove todo-keywords before exporting, if the user has requested so
1511 (org-export-remove-headline-metadata parameters)
1513 ;; Find targets in comments and move them out of comments,
1514 ;; but mark them as targets that should be invisible
1515 (setq target-alist (org-export-handle-invisible-targets target-alist))
1517 ;; Select and protect backend specific stuff, throw away stuff
1518 ;; that is specific for other backends
1519 (org-export-select-backend-specific-text backend)
1521 ;; Protect quoted subtrees
1522 (org-export-protect-quoted-subtrees)
1524 ;; Remove clock lines
1525 (org-export-remove-clock-lines)
1527 ;; Protect verbatim elements
1528 (org-export-protect-verbatim)
1530 ;; Blockquotes, verse, and center
1531 (org-export-mark-blockquote-verse-center)
1533 ;; Remove timestamps, if the user has requested so
1534 (unless (plist-get parameters :timestamps)
1535 (org-export-remove-timestamps))
1537 ;; Attach captions to the correct object
1538 (setq target-alist (org-export-attach-captions-and-attributes
1539 backend target-alist))
1541 ;; Find matches for radio targets and turn them into internal links
1542 (org-export-mark-radio-links)
1544 ;; Find all links that contain a newline and put them into a single line
1545 (org-export-concatenate-multiline-links)
1547 ;; Normalize links: Convert angle and plain links into bracket links
1548 ;; and expand link abbreviations
1549 (org-export-normalize-links)
1551 ;; Find all internal links. If they have a fuzzy match (i.e. not
1552 ;; a *dedicated* target match, let the link point to the
1553 ;; corresponding section.
1554 (org-export-target-internal-links target-alist)
1556 ;; Find multiline emphasis and put them into single line
1557 (when (plist-get parameters :emph-multiline)
1558 (org-export-concatenate-multiline-emphasis))
1560 ;; Remove special table lines
1561 (when org-export-table-remove-special-lines
1562 (org-export-remove-special-table-lines))
1564 ;; Another hook
1565 (run-hooks 'org-export-preprocess-before-backend-specifics-hook)
1567 ;; LaTeX-specific preprocessing
1568 (when latexp
1569 (require 'org-export-latex nil)
1570 (org-export-latex-preprocess parameters))
1572 ;; ASCII-specific preprocessing
1573 (when asciip
1574 (org-export-ascii-preprocess parameters))
1576 ;; HTML-specific preprocessing
1577 (when htmlp
1578 (org-export-html-preprocess parameters))
1580 ;; DocBook-specific preprocessing
1581 (when docbookp
1582 (require 'org-docbook nil)
1583 (org-export-docbook-preprocess parameters))
1585 ;; Remove or replace comments
1586 (org-export-handle-comments (plist-get parameters :comments))
1588 ;; Run the final hook
1589 (run-hooks 'org-export-preprocess-final-hook)
1591 (setq rtn (buffer-string)))
1592 (kill-buffer " org-mode-tmp")
1593 rtn))
1595 (defun org-export-kill-licensed-text ()
1596 "Remove all text that is marked with a :org-license-to-kill property."
1597 (let (p)
1598 (while (setq p (text-property-any (point-min) (point-max)
1599 :org-license-to-kill t))
1600 (delete-region
1601 p (or (next-single-property-change p :org-license-to-kill)
1602 (point-max))))))
1604 (defun org-export-define-heading-targets (target-alist)
1605 "Find all headings and define the targets for them.
1606 The new targets are added to TARGET-ALIST, which is also returned."
1607 (goto-char (point-min))
1608 (org-init-section-numbers)
1609 (let ((re (concat "^" org-outline-regexp
1610 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1611 level target last-section-target a)
1612 (while (re-search-forward re nil t)
1613 (if (match-end 1)
1614 (progn
1615 (push (cons (org-match-string-no-properties 1)
1616 target) target-alist)
1617 (setq a (or (assoc last-section-target org-export-target-aliases)
1618 (progn
1619 (push (list last-section-target)
1620 org-export-target-aliases)
1621 (car org-export-target-aliases))))
1622 (push (caar target-alist) (cdr a)))
1623 (setq level (org-reduced-level
1624 (save-excursion (goto-char (point-at-bol))
1625 (org-outline-level))))
1626 (setq target (org-solidify-link-text
1627 (format "sec-%s" (org-section-number level))))
1628 (setq last-section-target target)
1629 (push (cons target target) target-alist)
1630 (add-text-properties
1631 (point-at-bol) (point-at-eol)
1632 (list 'target target)))))
1633 target-alist)
1635 (defun org-export-handle-invisible-targets (target-alist)
1636 "Find targets in comments and move them out of comments.
1637 Mark them as invisible targets."
1638 (let (target tmp a)
1639 (goto-char (point-min))
1640 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t)
1641 ;; Check if the line before or after is a headline with a target
1642 (if (setq target (or (get-text-property (point-at-bol 0) 'target)
1643 (get-text-property (point-at-bol 2) 'target)))
1644 (progn
1645 ;; use the existing target in a neighboring line
1646 (setq tmp (match-string 2))
1647 (replace-match "")
1648 (and (looking-at "\n") (delete-char 1))
1649 (push (cons (setq tmp (org-solidify-link-text tmp)) target)
1650 target-alist)
1651 (setq a (or (assoc target org-export-target-aliases)
1652 (progn
1653 (push (list target) org-export-target-aliases)
1654 (car org-export-target-aliases))))
1655 (push tmp (cdr a)))
1656 ;; Make an invisible target
1657 (replace-match "\\1(INVISIBLE)"))))
1658 target-alist)
1660 (defun org-export-target-internal-links (target-alist)
1661 "Find all internal links and assign targets to them.
1662 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1663 let the link point to the corresponding section.
1664 This function also handles the id links, if they have a match in
1665 the current file."
1666 (goto-char (point-min))
1667 (while (re-search-forward org-bracket-link-regexp nil t)
1668 (org-if-unprotected
1669 (let* ((md (match-data))
1670 (desc (match-end 2))
1671 (link (org-link-unescape (match-string 1)))
1672 (slink (org-solidify-link-text link))
1673 found props pos cref
1674 (target
1675 (cond
1676 ((= (string-to-char link) ?#)
1677 ;; user wants exactly this link
1678 link)
1679 ((cdr (assoc slink target-alist)))
1680 ((and (string-match "^id:" link)
1681 (cdr (assoc (substring link 3) target-alist))))
1682 ((string-match "^(\\(.*\\))$" link)
1683 (setq cref (match-string 1 link))
1684 (concat "coderef:" cref))
1685 ((string-match org-link-types-re link) nil)
1686 ((or (file-name-absolute-p link)
1687 (string-match "^\\." link))
1688 nil)
1690 (save-excursion
1691 (setq found (condition-case nil (org-link-search link)
1692 (error nil)))
1693 (when (and found
1694 (or (org-on-heading-p)
1695 (not (eq found 'dedicated))))
1696 (or (get-text-property (point) 'target)
1697 (get-text-property
1698 (max (point-min)
1699 (1- (or (previous-single-property-change
1700 (point) 'target) 0)))
1701 'target))))))))
1702 (when target
1703 (set-match-data md)
1704 (goto-char (match-beginning 1))
1705 (setq props (text-properties-at (point)))
1706 (delete-region (match-beginning 1) (match-end 1))
1707 (setq pos (point))
1708 (insert target)
1709 (unless desc (insert "][" link))
1710 (add-text-properties pos (point) props))))))
1712 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers)
1713 "Remove drawers, or extract the content.
1714 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1715 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1716 whose content to keep."
1717 (unless (eq t exp-drawers)
1718 (goto-char (point-min))
1719 (let ((re (concat "^[ \t]*:\\("
1720 (mapconcat
1721 'identity
1722 (org-delete-all exp-drawers
1723 (copy-sequence all-drawers))
1724 "\\|")
1725 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1726 (while (re-search-forward re nil t)
1727 (org-if-unprotected
1728 (replace-match ""))))))
1730 (defun org-export-handle-export-tags (select-tags exclude-tags)
1731 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1732 Both arguments are lists of tags.
1733 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1734 will be removed.
1735 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1736 removed as well."
1737 (remove-text-properties (point-min) (point-max) '(:org-delete t))
1738 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1739 select-tags "\\|")
1740 "\\):"))
1741 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1742 exclude-tags "\\|")
1743 "\\):"))
1744 beg end cont)
1745 (goto-char (point-min))
1746 (when (and select-tags
1747 (re-search-forward
1748 (concat "^\\*+[ \t].*" re-sel "[^ \t\n]*[ \t]*$") nil t))
1749 ;; At least one tree is marked for export, this means
1750 ;; all the unmarked stuff needs to go.
1751 ;; Dig out the trees that should be exported
1752 (goto-char (point-min))
1753 (outline-next-heading)
1754 (setq beg (point))
1755 (put-text-property beg (point-max) :org-delete t)
1756 (while (re-search-forward re-sel nil t)
1757 (when (org-on-heading-p)
1758 (org-back-to-heading)
1759 (remove-text-properties
1760 (max (1- (point)) (point-min))
1761 (setq cont (save-excursion (org-end-of-subtree t t)))
1762 '(:org-delete t))
1763 (while (and (org-up-heading-safe)
1764 (get-text-property (point) :org-delete))
1765 (remove-text-properties (max (1- (point)) (point-min))
1766 (point-at-eol) '(:org-delete t)))
1767 (goto-char cont))))
1768 ;; Remove the trees explicitly marked for noexport
1769 (when exclude-tags
1770 (goto-char (point-min))
1771 (while (re-search-forward re-excl nil t)
1772 (when (org-at-heading-p)
1773 (org-back-to-heading t)
1774 (setq beg (point))
1775 (org-end-of-subtree t)
1776 (delete-region beg (point)))))
1777 ;; Remove everything that is now still marked for deletion
1778 (goto-char (point-min))
1779 (while (setq beg (text-property-any (point-min) (point-max) :org-delete t))
1780 (setq end (or (next-single-property-change beg :org-delete)
1781 (point-max)))
1782 (delete-region beg end))))
1784 (defun org-export-remove-archived-trees (export-archived-trees)
1785 "Remove archived trees.
1786 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1787 When it is t, the entire archived tree will be exported.
1788 When it is nil the entire tree including the headline will be removed
1789 from the buffer."
1790 (let ((re-archive (concat ":" org-archive-tag ":"))
1791 a b)
1792 (when (not (eq export-archived-trees t))
1793 (goto-char (point-min))
1794 (while (re-search-forward re-archive nil t)
1795 (if (not (org-on-heading-p t))
1796 (org-end-of-subtree t)
1797 (beginning-of-line 1)
1798 (setq a (if export-archived-trees
1799 (1+ (point-at-eol)) (point))
1800 b (org-end-of-subtree t))
1801 (if (> b a) (delete-region a b)))))))
1803 (defun org-export-remove-headline-metadata (opts)
1804 "Remove meta data from the headline, according to user options."
1805 (let ((re org-complex-heading-regexp)
1806 (todo (plist-get opts :todo-keywords))
1807 (tags (plist-get opts :tags))
1808 (pri (plist-get opts :priority))
1809 (elts '(1 2 3 4 5))
1810 rpl)
1811 (setq elts (delq nil (list 1 (if todo 2) (if pri 3) 4 (if tags 5))))
1812 (when (or (not todo) (not tags) (not pri))
1813 (goto-char (point-min))
1814 (while (re-search-forward re nil t)
1815 (org-if-unprotected
1816 (setq rpl (mapconcat (lambda (i) (if (match-end i) (match-string i) ""))
1817 elts " "))
1818 (replace-match rpl t t))))))
1820 (defun org-export-remove-timestamps ()
1821 "Remove timestamps and keywords for export."
1822 (while (re-search-forward org-maybe-keyword-time-regexp nil t)
1823 (backward-char 1)
1824 (org-if-unprotected
1825 (unless (save-match-data (org-at-table-p))
1826 (replace-match "")
1827 (beginning-of-line 1)
1828 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1829 (replace-match ""))))))
1831 (defun org-export-remove-clock-lines ()
1832 "Remove clock lines for export."
1833 (let ((re (concat "^[ \t]*" org-clock-string ".*\n?")))
1834 (while (re-search-forward re nil t)
1835 (org-if-unprotected
1836 (replace-match "")))))
1838 (defun org-export-protect-quoted-subtrees ()
1839 "Mark quoted subtrees with the protection property."
1840 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string "\\>")))
1841 (goto-char (point-min))
1842 (while (re-search-forward re-quote nil t)
1843 (goto-char (match-beginning 0))
1844 (end-of-line 1)
1845 (add-text-properties (point) (org-end-of-subtree t)
1846 '(org-protected t)))))
1848 (defun org-export-protect-verbatim ()
1849 "Mark verbatim snippets with the protection property."
1850 (goto-char (point-min))
1851 (while (re-search-forward org-verbatim-re nil t)
1852 (add-text-properties (match-beginning 4) (match-end 4)
1853 '(org-protected t))
1854 (goto-char (1+ (match-end 4)))))
1856 (defun org-export-protect-colon-examples ()
1857 "Protect lines starting with a colon."
1858 (goto-char (point-min))
1859 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg)
1860 (while (re-search-forward re nil t)
1861 (beginning-of-line 1)
1862 (setq beg (point))
1863 (while (looking-at re)
1864 (end-of-line 1)
1865 (or (eobp) (forward-char 1)))
1866 (add-text-properties beg (if (bolp) (1- (point)) (point))
1867 '(org-protected t)))))
1869 (defun org-export-select-backend-specific-text (backend)
1870 (let ((formatters
1871 '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK")
1872 (html "HTML" "BEGIN_HTML" "END_HTML")
1873 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1874 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1875 (case-fold-search t)
1876 fmt)
1878 (while formatters
1879 (setq fmt (pop formatters))
1880 (when (eq (car fmt) backend)
1881 ;; This is selected code, put it into the file for real
1882 (goto-char (point-min))
1883 (while (re-search-forward (concat "^#\\+" (cadr fmt)
1884 ":[ \t]*\\(.*\\)") nil t)
1885 (replace-match "\\1" t)
1886 (add-text-properties
1887 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1888 '(org-protected t))))
1889 (goto-char (point-min))
1890 (while (re-search-forward
1891 (concat "^#\\+"
1892 (caddr fmt) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1893 (cadddr fmt) "\\>.*\n?") nil t)
1894 (if (eq (car fmt) backend)
1895 ;; yes, keep this
1896 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1897 '(org-protected t))
1898 ;; No, this is for a different backend, kill it
1899 (delete-region (match-beginning 0) (match-end 0)))))))
1901 (defun org-export-mark-blockquote-verse-center ()
1902 "Mark block quote and verse environments with special cookies.
1903 These special cookies will later be interpreted by the backend."
1904 ;; Blockquotes
1905 (goto-char (point-min))
1906 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1907 nil t)
1908 (replace-match (if (equal (downcase (match-string 1)) "end")
1909 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1910 t t))
1911 ;; Verse
1912 (goto-char (point-min))
1913 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t)
1914 (replace-match (if (equal (downcase (match-string 1)) "end")
1915 "ORG-VERSE-END" "ORG-VERSE-START")
1916 t t))
1917 ;; Center
1918 (goto-char (point-min))
1919 (while (re-search-forward "^#\\+\\(begin\\|end\\)_center\\>.*" nil t)
1920 (replace-match (if (equal (downcase (match-string 1)) "end")
1921 "ORG-CENTER-END" "ORG-CENTER-START")
1922 t t)))
1924 (defun org-export-attach-captions-and-attributes (backend target-alist)
1925 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1926 If the next thing following is a table, add the text properties to the first
1927 table line. If it is a link, add it to the line containing the link."
1928 (goto-char (point-min))
1929 (remove-text-properties (point-min) (point-max)
1930 '(org-caption nil org-attributes nil))
1931 (let ((case-fold-search t)
1932 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1933 "\\|"
1934 "^#\\+attr_" (symbol-name backend) ":[ \t]+\\(.*\\)"
1935 "\\|"
1936 "^#\\+label:[ \t]+\\(.*\\)"
1937 "\\|"
1938 "^[ \t]*|[^-]"
1939 "\\|"
1940 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1941 cap attr label)
1942 (while (re-search-forward re nil t)
1943 (cond
1944 ((match-end 1)
1945 (setq cap (concat cap (if cap " " "") (org-trim (match-string 1)))))
1946 ((match-end 2)
1947 (setq attr (concat attr (if attr " " "") (org-trim (match-string 2)))))
1948 ((match-end 3)
1949 (setq label (org-trim (match-string 3))))
1951 (add-text-properties (point-at-bol) (point-at-eol)
1952 (list 'org-caption cap
1953 'org-attributes attr
1954 'org-label label))
1955 (if label (push (cons label label) target-alist))
1956 (setq cap nil attr nil label nil)))))
1957 target-alist)
1959 (defun org-export-remove-comment-blocks-and-subtrees ()
1960 "Remove the comment environment, and also commented subtrees."
1961 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string "\\>"))
1962 (case-fold-search nil))
1963 ;; Remove comment environment
1964 (goto-char (point-min))
1965 (while (re-search-forward
1966 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t)
1967 (replace-match "" t t))
1968 ;; Remove subtrees that are commented
1969 (goto-char (point-min))
1970 (while (re-search-forward re-commented nil t)
1971 (goto-char (match-beginning 0))
1972 (delete-region (point) (org-end-of-subtree t)))))
1974 (defun org-export-handle-comments (commentsp)
1975 "Remove comments, or convert to backend-specific format.
1976 COMMENTSP can be a format string for publishing comments.
1977 When it is nil, all comments will be removed."
1978 (let ((re "^#\\(.*\n?\\)")
1979 pos)
1980 (goto-char (point-min))
1981 (while (or (looking-at re)
1982 (re-search-forward re nil t))
1983 (setq pos (match-beginning 0))
1984 (if commentsp
1985 (progn (add-text-properties
1986 (match-beginning 0) (match-end 0) '(org-protected t))
1987 (replace-match (format commentsp (match-string 1)) t t))
1988 (goto-char (1+ pos))
1989 (org-if-unprotected
1990 (replace-match "")
1991 (goto-char (max (point-min) (1- pos))))))))
1993 (defun org-export-mark-radio-links ()
1994 "Find all matches for radio targets and turn them into internal links."
1995 (let ((re-radio (and org-target-link-regexp
1996 (concat "\\([^<]\\)\\(" org-target-link-regexp "\\)"))))
1997 (goto-char (point-min))
1998 (when re-radio
1999 (while (re-search-forward re-radio nil t)
2000 (org-if-unprotected
2001 (replace-match "\\1[[\\2]]"))))))
2003 (defun org-export-remove-special-table-lines ()
2004 "Remove tables lines that are used for internal purposes."
2005 (goto-char (point-min))
2006 (while (re-search-forward "^[ \t]*|" nil t)
2007 (beginning-of-line 1)
2008 (if (or (looking-at "[ \t]*| *[!_^] *|")
2009 (and (looking-at ".*?| *<[0-9]+> *|")
2010 (not (looking-at ".*?| *[^ <|]"))))
2011 (delete-region (max (point-min) (1- (point-at-bol)))
2012 (point-at-eol))
2013 (end-of-line 1))))
2015 (defun org-export-normalize-links ()
2016 "Convert all links to bracket links, and expand link abbreviations."
2017 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re))
2018 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re)))
2019 (goto-char (point-min))
2020 (while (re-search-forward re-plain-link nil t)
2021 (goto-char (1- (match-end 0)))
2022 (org-if-unprotected-at (1+ (match-beginning 0))
2023 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2024 ":" (match-string 3) "]]")))
2025 ;; added 'org-link face to links
2026 (put-text-property 0 (length s) 'face 'org-link s)
2027 (replace-match s t t))))
2028 (goto-char (point-min))
2029 (while (re-search-forward re-angle-link nil t)
2030 (goto-char (1- (match-end 0)))
2031 (org-if-unprotected
2032 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2033 ":" (match-string 3) "]]")))
2034 (put-text-property 0 (length s) 'face 'org-link s)
2035 (replace-match s t t))))
2036 (goto-char (point-min))
2037 (while (re-search-forward org-bracket-link-regexp nil t)
2038 (goto-char (1- (match-end 0)))
2039 (org-if-unprotected
2040 (let* ((xx (save-match-data
2041 (org-translate-link
2042 (org-link-expand-abbrev (match-string 1)))))
2043 (s (concat
2044 "[[" (org-add-props (copy-sequence xx)
2045 nil 'org-protected t)
2047 (if (match-end 3)
2048 (match-string 2)
2049 (concat "[" (org-add-props
2050 (copy-sequence xx)
2051 '(org-protected t))
2052 "]"))
2053 "]")))
2054 (put-text-property 0 (length s) 'face 'org-link s)
2055 (replace-match s t t))))))
2057 (defun org-export-concatenate-multiline-links ()
2058 "Find multi-line links and put it all into a single line.
2059 This is to make sure that the line-processing export backends
2060 can work correctly."
2061 (goto-char (point-min))
2062 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t)
2063 (org-if-unprotected
2064 (replace-match "\\1 \\3")
2065 (goto-char (match-beginning 0)))))
2067 (defun org-export-concatenate-multiline-emphasis ()
2068 "Find multi-line emphasis and put it all into a single line.
2069 This is to make sure that the line-processing export backends
2070 can work correctly."
2071 (goto-char (point-min))
2072 (while (re-search-forward org-emph-re nil t)
2073 (if (and (not (= (char-after (match-beginning 3))
2074 (char-after (match-beginning 4))))
2075 (save-excursion (goto-char (match-beginning 0))
2076 (save-match-data (not (org-at-table-p)))))
2077 (org-if-unprotected
2078 (subst-char-in-region (match-beginning 0) (match-end 0)
2079 ?\n ?\ t)
2080 (goto-char (1- (match-end 0))))
2081 (goto-char (1+ (match-beginning 0))))))
2083 (defun org-export-grab-title-from-buffer ()
2084 "Get a title for the current document, from looking at the buffer."
2085 (let ((inhibit-read-only t))
2086 (save-excursion
2087 (goto-char (point-min))
2088 (let ((end (if (looking-at org-outline-regexp)
2089 (point)
2090 (save-excursion (outline-next-heading) (point)))))
2091 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t)
2092 ;; Mark the line so that it will not be exported as normal text.
2093 (org-unmodified
2094 (add-text-properties (match-beginning 0) (match-end 0)
2095 (list :org-license-to-kill t)))
2096 ;; Return the title string
2097 (org-trim (match-string 0)))))))
2099 (defun org-export-get-title-from-subtree ()
2100 "Return subtree title and exclude it from export."
2101 (let (title (rbeg (region-beginning)) (rend (region-end)))
2102 (save-excursion
2103 (goto-char rbeg)
2104 (when (and (org-at-heading-p)
2105 (>= (org-end-of-subtree t t) rend))
2106 ;; This is a subtree, we take the title from the first heading
2107 (goto-char rbeg)
2108 (looking-at org-todo-line-regexp)
2109 (setq title (match-string 3))
2110 (org-unmodified
2111 (add-text-properties (point) (1+ (point-at-eol))
2112 (list :org-license-to-kill t)))
2113 (setq title (or (org-entry-get nil "EXPORT_TITLE") title))))
2114 title))
2116 (defun org-solidify-link-text (s &optional alist)
2117 "Take link text and make a safe target out of it."
2118 (save-match-data
2119 (let* ((rtn
2120 (mapconcat
2121 'identity
2122 (org-split-string s "[ \t\r\n]+") "=="))
2123 (a (assoc rtn alist)))
2124 (or (cdr a) rtn))))
2126 (defun org-get-min-level (lines &optional offset)
2127 "Get the minimum level in LINES."
2128 (let ((re "^\\(\\*+\\) ") l)
2129 (catch 'exit
2130 (while (setq l (pop lines))
2131 (if (string-match re l)
2132 (throw 'exit (org-tr-level (- (length (match-string 1 l))
2133 (or offset 0))))))
2134 1)))
2136 ;; Variable holding the vector with section numbers
2137 (defvar org-section-numbers (make-vector org-level-max 0))
2139 (defun org-init-section-numbers ()
2140 "Initialize the vector for the section numbers."
2141 (let* ((level -1)
2142 (numbers (nreverse (org-split-string "" "\\.")))
2143 (depth (1- (length org-section-numbers)))
2144 (i depth) number-string)
2145 (while (>= i 0)
2146 (if (> i level)
2147 (aset org-section-numbers i 0)
2148 (setq number-string (or (car numbers) "0"))
2149 (if (string-match "\\`[A-Z]\\'" number-string)
2150 (aset org-section-numbers i
2151 (- (string-to-char number-string) ?A -1))
2152 (aset org-section-numbers i (string-to-number number-string)))
2153 (pop numbers))
2154 (setq i (1- i)))))
2156 (defun org-section-number (&optional level)
2157 "Return a string with the current section number.
2158 When LEVEL is non-nil, increase section numbers on that level."
2159 (let* ((depth (1- (length org-section-numbers)))
2160 (string "")
2161 (fmts (car org-export-section-number-format))
2162 (term (cdr org-export-section-number-format))
2163 (sep "")
2164 ctype fmt idx n)
2165 (when level
2166 (when (> level -1)
2167 (aset org-section-numbers
2168 level (1+ (aref org-section-numbers level))))
2169 (setq idx (1+ level))
2170 (while (<= idx depth)
2171 (if (not (= idx 1))
2172 (aset org-section-numbers idx 0))
2173 (setq idx (1+ idx))))
2174 (setq idx 0)
2175 (while (<= idx depth)
2176 (when (> (aref org-section-numbers idx) 0)
2177 (setq fmt (or (pop fmts) fmt)
2178 ctype (car fmt)
2179 n (aref org-section-numbers idx)
2180 string (if (> n 0)
2181 (concat string sep (org-number-to-counter n ctype))
2182 (concat string ".0"))
2183 sep (nth 1 fmt)))
2184 (setq idx (1+ idx)))
2185 (save-match-data
2186 (if (string-match "\\`\\([@0]\\.\\)+" string)
2187 (setq string (replace-match "" t nil string)))
2188 (if (string-match "\\(\\.0\\)+\\'" string)
2189 (setq string (replace-match "" t nil string))))
2190 (concat string term)))
2192 (defun org-number-to-counter (n type)
2193 "Concert number N to a string counter, according to TYPE.
2194 TYPE must be a string, any of:
2195 1 number
2196 A A,B,....
2197 a a,b,....
2198 I upper case roman numeral
2199 i lower case roman numeral"
2200 (cond
2201 ((equal type "1") (number-to-string n))
2202 ((equal type "A") (char-to-string (+ ?A n -1)))
2203 ((equal type "a") (char-to-string (+ ?a n -1)))
2204 ((equal type "I") (org-number-to-roman n))
2205 ((equal type "i") (downcase (org-number-to-roman n)))
2206 (t (error "Invalid counter type `%s'" type))))
2208 (defun org-number-to-roman (n)
2209 "Convert integer N into a roman numeral."
2210 (let ((roman '((1000 . "M") (900 . "CM") (500 . "D") (400 . "CD")
2211 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
2212 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
2213 ( 1 . "I")))
2214 (res ""))
2215 (if (<= n 0)
2216 (number-to-string n)
2217 (while roman
2218 (if (>= n (caar roman))
2219 (setq n (- n (caar roman))
2220 res (concat res (cdar roman)))
2221 (pop roman)))
2222 res)))
2224 ;;; Macros
2226 (defun org-export-preprocess-apply-macros ()
2227 "Replace macro references."
2228 (goto-char (point-min))
2229 (let (sy val key)
2230 (while (re-search-forward "{{{\\([a-zA-Z][-a-zA-Z0-9_]*\\)}}}" nil t)
2231 (setq key (downcase (match-string 1)))
2232 (when (setq val (or (plist-get org-export-opt-plist
2233 (intern (concat ":macro-" key)))
2234 (plist-get org-export-opt-plist
2235 (intern (concat ":" key)))))
2236 (and (stringp val)
2237 (replace-match val t t))))))
2239 (defun org-export-apply-macros-in-string (s)
2240 "Apply the macros in string S."
2241 (when s
2242 (with-temp-buffer
2243 (insert s)
2244 (org-export-preprocess-apply-macros)
2245 (buffer-string))))
2247 ;;; Include files
2249 (defun org-export-handle-include-files ()
2250 "Include the contents of include files, with proper formatting."
2251 (let ((case-fold-search t)
2252 params file markup lang start end prefix prefix1 switches)
2253 (goto-char (point-min))
2254 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t)
2255 (setq params (read (concat "(" (match-string 1) ")"))
2256 prefix (org-get-and-remove-property 'params :prefix)
2257 prefix1 (org-get-and-remove-property 'params :prefix1)
2258 file (org-symname-or-string (pop params))
2259 markup (org-symname-or-string (pop params))
2260 lang (and (member markup '("src" "SRC"))
2261 (org-symname-or-string (pop params)))
2262 switches (mapconcat '(lambda (x) (format "%s" x)) params " "))
2263 (delete-region (match-beginning 0) (match-end 0))
2264 (if (or (not file)
2265 (not (file-exists-p file))
2266 (not (file-readable-p file)))
2267 (insert (format "CANNOT INCLUDE FILE %s" file))
2268 (when markup
2269 (if (equal (downcase markup) "src")
2270 (setq start (format "#+begin_src %s %s\n"
2271 (or lang "fundamental")
2272 (or switches ""))
2273 end "#+end_src")
2274 (setq start (format "#+begin_%s %s\n" markup switches)
2275 end (format "#+end_%s" markup))))
2276 (insert (or start ""))
2277 (insert (org-get-file-contents (expand-file-name file) prefix prefix1))
2278 (or (bolp) (newline))
2279 (insert (or end ""))))))
2281 (defun org-get-file-contents (file &optional prefix prefix1)
2282 "Get the contents of FILE and return them as a string.
2283 If PREFIX is a string, prepend it to each line. If PREFIX1
2284 is a string, prepend it to the first line instead of PREFIX."
2285 (with-temp-buffer
2286 (insert-file-contents file)
2287 (when (or prefix prefix1)
2288 (goto-char (point-min))
2289 (while (not (eobp))
2290 (insert (or prefix1 prefix))
2291 (setq prefix1 nil)
2292 (beginning-of-line 2)))
2293 (buffer-string)))
2295 (defun org-get-and-remove-property (listvar prop)
2296 "Check if the value of LISTVAR contains PROP as a property.
2297 If yes, return the value of that property (i.e. the element following
2298 in the list) and remove property and value from the list in LISTVAR."
2299 (let ((list (symbol-value listvar)) m v)
2300 (when (setq m (member prop list))
2301 (setq v (nth 1 m))
2302 (if (equal (car list) prop)
2303 (set listvar (cddr list))
2304 (setcdr (nthcdr (- (length list) (length m) 1) list)
2305 (cddr m))
2306 (set listvar list)))
2309 (defun org-symname-or-string (s)
2310 (if (symbolp s)
2311 (if s (symbol-name s) s)
2314 ;;; Fontification and line numbers for code examples
2316 (defvar org-export-last-code-line-counter-value 0)
2318 (defun org-export-replace-src-segments-and-examples (backend)
2319 "Replace source code segments with special code for export."
2320 (setq org-export-last-code-line-counter-value 0)
2321 (let ((case-fold-search t)
2322 lang code trans opts)
2323 (goto-char (point-min))
2324 (while (re-search-forward
2325 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2326 nil t)
2327 (if (match-end 1)
2328 ;; src segments
2329 (setq lang (match-string 2)
2330 opts (match-string 3)
2331 code (match-string 4))
2332 (setq lang nil
2333 opts (match-string 6)
2334 code (match-string 7)))
2336 (setq trans (org-export-format-source-code-or-example
2337 backend lang code opts))
2338 (replace-match trans t t))))
2340 (defvar htmlp) ;; dynamically scoped
2341 (defvar latexp) ;; dynamically scoped
2343 (defun org-export-format-source-code-or-example (backend
2344 lang code &optional opts)
2345 "Format CODE from language LANG and return it formatted for export.
2346 If LANG is nil, do not add any fontification.
2347 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2348 and `+n' for continuing previous numering.
2349 Code formatting according to language currently only works for HTML.
2350 Numbering lines works for all three major backends (html, latex, and ascii)."
2351 (save-match-data
2352 (let (num cont rtn rpllbl keepp textareap cols rows fmt)
2353 (setq opts (or opts "")
2354 num (string-match "[-+]n\\>" opts)
2355 cont (string-match "\\+n\\>" opts)
2356 rpllbl (string-match "-r\\>" opts)
2357 keepp (string-match "-k\\>" opts)
2358 textareap (string-match "-t\\>" opts)
2359 cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
2360 (string-to-number (match-string 1 opts))
2362 rows (if (string-match "-h[ \t]+\\([0-9]+\\)" opts)
2363 (string-to-number (match-string 1 opts))
2364 (org-count-lines code))
2365 fmt (if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts)
2366 (match-string 1 opts)))
2367 (when (and textareap (eq backend 'html))
2368 ;; we cannot use numbering or highlighting.
2369 (setq num nil cont nil lang nil))
2370 (if keepp (setq rpllbl 'keep))
2371 (setq rtn code)
2372 (when (equal lang "org")
2373 (setq rtn (with-temp-buffer
2374 (insert rtn)
2375 ;; Free up the protected lines
2376 (goto-char (point-min))
2377 (while (re-search-forward "^," nil t)
2378 (replace-match "")
2379 (end-of-line 1))
2380 (buffer-string))))
2381 ;; Now backend-specific coding
2382 (cond
2383 ((eq backend 'docbook)
2384 (setq rtn (org-export-number-lines rtn 'docbook 0 0 num cont rpllbl fmt))
2385 (concat "\n#+BEGIN_DOCBOOK\n"
2386 (org-add-props (concat "<programlisting><![CDATA["
2388 "]]>\n</programlisting>\n")
2389 '(org-protected t))
2390 "#+END_DOCBOOK\n"))
2391 ((eq backend 'html)
2392 ;; We are exporting to HTML
2393 (when lang
2394 (require 'htmlize nil t)
2395 (when (not (fboundp 'htmlize-region-for-paste))
2396 ;; we do not have htmlize.el, or an old version of it
2397 (setq lang nil)
2398 (message
2399 "htmlize.el 1.34 or later is needed for source code formatting")))
2401 (if lang
2402 (let* ((mode (and lang (intern (concat lang "-mode"))))
2403 (org-inhibit-startup t)
2404 (org-startup-folded nil))
2405 (setq rtn
2406 (with-temp-buffer
2407 (insert rtn)
2408 (if (functionp mode)
2409 (funcall mode)
2410 (fundamental-mode))
2411 (font-lock-fontify-buffer)
2412 (set-buffer-modified-p nil)
2413 (org-export-htmlize-region-for-paste
2414 (point-min) (point-max))))
2415 (if (string-match "<pre\\([^>]*\\)>\n?" rtn)
2416 (setq rtn (replace-match
2417 (format "<pre class=\"src src-%s\">\n" lang)
2418 t t rtn))))
2419 (if textareap
2420 (setq rtn (concat
2421 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2422 cols rows)
2423 rtn "</textarea>\n</p>\n"))
2424 (with-temp-buffer
2425 (insert rtn)
2426 (goto-char (point-min))
2427 (while (re-search-forward "[<>&]" nil t)
2428 (replace-match (cdr (assq (char-before)
2429 '((?&."&amp;")(?<."&lt;")(?>."&gt;"))))
2430 t t))
2431 (setq rtn (buffer-string)))
2432 (setq rtn (concat "<pre class=\"example\">\n" rtn "</pre>\n"))))
2433 (unless textareap
2434 (setq rtn (org-export-number-lines rtn 'html 1 1 num
2435 cont rpllbl fmt)))
2436 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn '(org-protected t)) "\n#+END_HTML\n\n"))
2437 ((eq backend 'latex)
2438 (setq rtn (org-export-number-lines rtn 'latex 0 0 num cont rpllbl fmt))
2439 (concat "\n#+BEGIN_LaTeX\n"
2440 (org-add-props (concat "\\begin{verbatim}\n" rtn "\n\\end{verbatim}\n")
2441 '(org-protected t))
2442 "#+END_LaTeX\n\n"))
2443 ((eq backend 'ascii)
2444 ;; This is not HTML or LaTeX, so just make it an example.
2445 (setq rtn (org-export-number-lines rtn 'ascii 0 0 num cont rpllbl fmt))
2446 (concat "#+BEGIN_ASCII\n"
2447 (org-add-props
2448 (concat
2449 (mapconcat
2450 (lambda (l) (concat " " l))
2451 (org-split-string rtn "\n")
2452 "\n")
2453 "\n")
2454 '(org-protected t))
2455 "#+END_ASCII\n"))))))
2457 (defun org-export-number-lines (text backend
2458 &optional skip1 skip2 number cont
2459 replace-labels label-format)
2460 (if (and (not number) (not (eq replace-labels 'keep)))
2461 (setq replace-labels nil)) ;; must use names if no numbers
2462 (setq skip1 (or skip1 0) skip2 (or skip2 0))
2463 (if (not cont) (setq org-export-last-code-line-counter-value 0))
2464 (with-temp-buffer
2465 (insert text)
2466 (goto-char (point-max))
2467 (skip-chars-backward " \t\n\r")
2468 (delete-region (point) (point-max))
2469 (beginning-of-line (- 1 skip2))
2470 (let* ((last (org-current-line))
2471 (n org-export-last-code-line-counter-value)
2472 (nmax (+ n (- last skip1)))
2473 (fmt (format "%%%dd: " (length (number-to-string nmax))))
2475 (cond
2476 ((eq backend 'html) (format "<span class=\"linenr\">%s</span>"
2477 fmt))
2478 ((eq backend 'ascii) fmt)
2479 ((eq backend 'latex) fmt)
2480 ((eq backend 'docbook) fmt)
2481 (t "")))
2482 (label-format (or label-format org-coderef-label-format))
2483 (label-pre (if (string-match "%s" label-format)
2484 (substring label-format 0 (match-beginning 0))
2485 label-format))
2486 (label-post (if (string-match "%s" label-format)
2487 (substring label-format (match-end 0))
2488 ""))
2489 (lbl-re
2490 (concat
2491 ".*?\\S-.*?\\([ \t]*\\("
2492 (regexp-quote label-pre)
2493 "\\([-a-zA-Z0-9_]+\\)"
2494 (regexp-quote label-post)
2495 "\\)\\)"))
2496 ref)
2498 (goto-line (1+ skip1))
2499 (while (and (re-search-forward "^" nil t) (not (eobp)) (< n nmax))
2500 (if number
2501 (insert (format fm (incf n)))
2502 (forward-char 1))
2503 (when (and (not (eq replace-labels 'keep))
2504 (looking-at lbl-re))
2505 (setq ref (match-string 3))
2506 (if replace-labels
2507 (progn
2508 (delete-region (match-beginning 1) (match-end 1))
2509 (push (cons ref n) org-export-code-refs))
2510 (goto-char (match-beginning 2))
2511 (delete-region (match-beginning 2) (match-end 2))
2512 (insert "(" ref ")")
2513 (push (cons ref (concat "(" ref ")")) org-export-code-refs))
2514 (when (eq backend 'html)
2515 (save-excursion
2516 (beginning-of-line 1)
2517 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2518 ref))
2519 (end-of-line 1)
2520 (insert "</span>")))))
2521 (setq org-export-last-code-line-counter-value n)
2522 (goto-char (point-max))
2523 (newline)
2524 (buffer-string))))
2526 (defun org-search-todo-below (line lines level)
2527 "Search the subtree below LINE for any TODO entries."
2528 (let ((rest (cdr (memq line lines)))
2529 (re org-todo-line-regexp)
2530 line lv todo)
2531 (catch 'exit
2532 (while (setq line (pop rest))
2533 (if (string-match re line)
2534 (progn
2535 (setq lv (- (match-end 1) (match-beginning 1))
2536 todo (and (match-beginning 2)
2537 (not (member (match-string 2 line)
2538 org-done-keywords))))
2539 ; TODO, not DONE
2540 (if (<= lv level) (throw 'exit nil))
2541 (if todo (throw 'exit t))))))))
2543 ;;;###autoload
2544 (defun org-export-visible (type arg)
2545 "Create a copy of the visible part of the current buffer, and export it.
2546 The copy is created in a temporary buffer and removed after use.
2547 TYPE is the final key (as a string) that also select the export command in
2548 the `C-c C-e' export dispatcher.
2549 As a special case, if the you type SPC at the prompt, the temporary
2550 org-mode file will not be removed but presented to you so that you can
2551 continue to use it. The prefix arg ARG is passed through to the exporting
2552 command."
2553 (interactive
2554 (list (progn
2555 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [D]ocBook [x]OXO [ ]keep buffer")
2556 (read-char-exclusive))
2557 current-prefix-arg))
2558 (if (not (member type '(?a ?\C-a ?b ?\C-b ?h ?D ?x ?\ )))
2559 (error "Invalid export key"))
2560 (let* ((binding (cdr (assoc type
2561 '((?a . org-export-as-ascii)
2562 (?\C-a . org-export-as-ascii)
2563 (?b . org-export-as-html-and-open)
2564 (?\C-b . org-export-as-html-and-open)
2565 (?h . org-export-as-html)
2566 (?H . org-export-as-html-to-buffer)
2567 (?R . org-export-region-as-html)
2568 (?D . org-export-as-docbook)
2569 (?x . org-export-as-xoxo)))))
2570 (keepp (equal type ?\ ))
2571 (file buffer-file-name)
2572 (buffer (get-buffer-create "*Org Export Visible*"))
2573 s e)
2574 ;; Need to hack the drawers here.
2575 (save-excursion
2576 (goto-char (point-min))
2577 (while (re-search-forward org-drawer-regexp nil t)
2578 (goto-char (match-beginning 1))
2579 (or (org-invisible-p) (org-flag-drawer nil))))
2580 (with-current-buffer buffer (erase-buffer))
2581 (save-excursion
2582 (setq s (goto-char (point-min)))
2583 (while (not (= (point) (point-max)))
2584 (goto-char (org-find-invisible))
2585 (append-to-buffer buffer s (point))
2586 (setq s (goto-char (org-find-visible))))
2587 (org-cycle-hide-drawers 'all)
2588 (goto-char (point-min))
2589 (unless keepp
2590 ;; Copy all comment lines to the end, to make sure #+ settings are
2591 ;; still available for the second export step. Kind of a hack, but
2592 ;; does do the trick.
2593 (if (looking-at "#[^\r\n]*")
2594 (append-to-buffer buffer (match-beginning 0) (1+ (match-end 0))))
2595 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t)
2596 (append-to-buffer buffer (1+ (match-beginning 0))
2597 (min (point-max) (1+ (match-end 0))))))
2598 (set-buffer buffer)
2599 (let ((buffer-file-name file)
2600 (org-inhibit-startup t))
2601 (org-mode)
2602 (show-all)
2603 (unless keepp (funcall binding arg))))
2604 (if (not keepp)
2605 (kill-buffer buffer)
2606 (switch-to-buffer-other-window buffer)
2607 (goto-char (point-min)))))
2609 (defun org-find-visible ()
2610 (let ((s (point)))
2611 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2612 (get-char-property s 'invisible)))
2614 (defun org-find-invisible ()
2615 (let ((s (point)))
2616 (while (and (not (= (point-max) (setq s (next-overlay-change s))))
2617 (not (get-char-property s 'invisible))))
2620 ;;; HTML export
2622 (defvar org-archive-location) ;; gets loaded with the org-archive require.
2623 (defun org-get-current-options ()
2624 "Return a string with current options as keyword options.
2625 Does include HTML export options as well as TODO and CATEGORY stuff."
2626 (require 'org-archive)
2627 (format
2628 "#+TITLE: %s
2629 #+AUTHOR: %s
2630 #+EMAIL: %s
2631 #+DATE: %s
2632 #+DESCRIPTION:
2633 #+KEYWORDS:
2634 #+LANGUAGE: %s
2635 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2636 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2638 #+EXPORT_SELECT_TAGS: %s
2639 #+EXPORT_EXCLUDE_TAGS: %s
2640 #+LINK_UP: %s
2641 #+LINK_HOME: %s
2642 #+CATEGORY: %s
2643 #+SEQ_TODO: %s
2644 #+TYP_TODO: %s
2645 #+PRIORITIES: %c %c %c
2646 #+DRAWERS: %s
2647 #+STARTUP: %s %s %s %s %s
2648 #+TAGS: %s
2649 #+FILETAGS: %s
2650 #+ARCHIVE: %s
2651 #+LINK: %s
2653 (buffer-name) (user-full-name) user-mail-address
2654 (format-time-string (substring (car org-time-stamp-formats) 1 -1))
2655 org-export-default-language
2656 org-export-headline-levels
2657 org-export-with-section-numbers
2658 org-export-with-toc
2659 org-export-preserve-breaks
2660 org-export-html-expand
2661 org-export-with-fixed-width
2662 org-export-with-tables
2663 org-export-with-sub-superscripts
2664 org-export-with-special-strings
2665 org-export-with-footnotes
2666 org-export-with-emphasize
2667 org-export-with-timestamps
2668 org-export-with-TeX-macros
2669 org-export-with-LaTeX-fragments
2670 org-export-skip-text-before-1st-heading
2671 org-export-with-drawers
2672 org-export-with-todo-keywords
2673 org-export-with-priority
2674 org-export-with-tags
2675 (if (featurep 'org-jsinfo) (org-infojs-options-inbuffer-template) "")
2676 (mapconcat 'identity org-export-select-tags " ")
2677 (mapconcat 'identity org-export-exclude-tags " ")
2678 org-export-html-link-up
2679 org-export-html-link-home
2680 (or (ignore-errors
2681 (file-name-sans-extension
2682 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
2683 "NOFILENAME")
2684 "TODO FEEDBACK VERIFY DONE"
2685 "Me Jason Marie DONE"
2686 org-highest-priority org-lowest-priority org-default-priority
2687 (mapconcat 'identity org-drawers " ")
2688 (cdr (assoc org-startup-folded
2689 '((nil . "showall") (t . "overview") (content . "content"))))
2690 (if org-odd-levels-only "odd" "oddeven")
2691 (if org-hide-leading-stars "hidestars" "showstars")
2692 (if org-startup-align-all-tables "align" "noalign")
2693 (cond ((eq org-log-done t) "logdone")
2694 ((equal org-log-done 'note) "lognotedone")
2695 ((not org-log-done) "nologdone"))
2696 (or (mapconcat (lambda (x)
2697 (cond
2698 ((equal '(:startgroup) x) "{")
2699 ((equal '(:endgroup) x) "}")
2700 ((cdr x) (format "%s(%c)" (car x) (cdr x)))
2701 (t (car x))))
2702 (or org-tag-alist (org-get-buffer-tags)) " ") "")
2703 (mapconcat 'identity org-file-tags " ")
2704 org-archive-location
2705 "org file:~/org/%s.org"
2708 (defun org-export-html-preprocess (parameters)
2709 ;; Convert LaTeX fragments to images
2710 (when (and org-current-export-file
2711 (plist-get parameters :LaTeX-fragments))
2712 (org-format-latex
2713 (concat "ltxpng/" (file-name-sans-extension
2714 (file-name-nondirectory
2715 org-current-export-file)))
2716 org-current-export-dir nil "Creating LaTeX image %s"))
2717 (message "Exporting..."))
2719 ;;;###autoload
2720 (defun org-insert-export-options-template ()
2721 "Insert into the buffer a template with information for exporting."
2722 (interactive)
2723 (if (not (bolp)) (newline))
2724 (let ((s (org-get-current-options)))
2725 (and (string-match "#\\+CATEGORY" s)
2726 (setq s (substring s 0 (match-beginning 0))))
2727 (insert s)))
2729 ;;;###autoload
2730 (defun org-export-as-html-and-open (arg)
2731 "Export the outline as HTML and immediately open it with a browser.
2732 If there is an active region, export only the region.
2733 The prefix ARG specifies how many levels of the outline should become
2734 headlines. The default is 3. Lower levels will become bulleted lists."
2735 (interactive "P")
2736 (org-export-as-html arg 'hidden)
2737 (org-open-file buffer-file-name))
2739 ;;;###autoload
2740 (defun org-export-as-html-batch ()
2741 "Call `org-export-as-html', may be used in batch processing as
2742 emacs --batch
2743 --load=$HOME/lib/emacs/org.el
2744 --eval \"(setq org-export-headline-levels 2)\"
2745 --visit=MyFile --funcall org-export-as-html-batch"
2746 (org-export-as-html org-export-headline-levels 'hidden))
2748 ;;;###autoload
2749 (defun org-export-as-html-to-buffer (arg)
2750 "Call `org-export-as-html` with output to a temporary buffer.
2751 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2752 (interactive "P")
2753 (org-export-as-html arg nil nil "*Org HTML Export*")
2754 (switch-to-buffer-other-window "*Org HTML Export*"))
2756 ;;;###autoload
2757 (defun org-replace-region-by-html (beg end)
2758 "Assume the current region has org-mode syntax, and convert it to HTML.
2759 This can be used in any buffer. For example, you could write an
2760 itemized list in org-mode syntax in an HTML buffer and then use this
2761 command to convert it."
2762 (interactive "r")
2763 (let (reg html buf pop-up-frames)
2764 (save-window-excursion
2765 (if (org-mode-p)
2766 (setq html (org-export-region-as-html
2767 beg end t 'string))
2768 (setq reg (buffer-substring beg end)
2769 buf (get-buffer-create "*Org tmp*"))
2770 (with-current-buffer buf
2771 (erase-buffer)
2772 (insert reg)
2773 (org-mode)
2774 (setq html (org-export-region-as-html
2775 (point-min) (point-max) t 'string)))
2776 (kill-buffer buf)))
2777 (delete-region beg end)
2778 (insert html)))
2780 ;;;###autoload
2781 (defun org-export-region-as-html (beg end &optional body-only buffer)
2782 "Convert region from BEG to END in org-mode buffer to HTML.
2783 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2784 contents, and only produce the region of converted text, useful for
2785 cut-and-paste operations.
2786 If BUFFER is a buffer or a string, use/create that buffer as a target
2787 of the converted HTML. If BUFFER is the symbol `string', return the
2788 produced HTML as a string and leave not buffer behind. For example,
2789 a Lisp program could call this function in the following way:
2791 (setq html (org-export-region-as-html beg end t 'string))
2793 When called interactively, the output buffer is selected, and shown
2794 in a window. A non-interactive call will only return the buffer."
2795 (interactive "r\nP")
2796 (when (interactive-p)
2797 (setq buffer "*Org HTML Export*"))
2798 (let ((transient-mark-mode t) (zmacs-regions t)
2799 ext-plist rtn)
2800 (setq ext-plist (plist-put ext-plist :ignore-subree-p t))
2801 (goto-char end)
2802 (set-mark (point)) ;; to activate the region
2803 (goto-char beg)
2804 (setq rtn (org-export-as-html
2805 nil nil ext-plist
2806 buffer body-only))
2807 (if (fboundp 'deactivate-mark) (deactivate-mark))
2808 (if (and (interactive-p) (bufferp rtn))
2809 (switch-to-buffer-other-window rtn)
2810 rtn)))
2812 (defvar html-table-tag nil) ; dynamically scoped into this.
2813 (defvar org-par-open nil)
2814 ;;;###autoload
2815 (defun org-export-as-html (arg &optional hidden ext-plist
2816 to-buffer body-only pub-dir)
2817 "Export the outline as a pretty HTML file.
2818 If there is an active region, export only the region. The prefix
2819 ARG specifies how many levels of the outline should become
2820 headlines. The default is 3. Lower levels will become bulleted
2821 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2822 EXT-PLIST is a property list with external parameters overriding
2823 org-mode's default settings, but still inferior to file-local
2824 settings. When TO-BUFFER is non-nil, create a buffer with that
2825 name and export to that buffer. If TO-BUFFER is the symbol
2826 `string', don't leave any buffer behind but just return the
2827 resulting HTML as a string. When BODY-ONLY is set, don't produce
2828 the file header and footer, simply return the content of
2829 <body>...</body>, without even the body tags themselves. When
2830 PUB-DIR is set, use this as the publishing directory."
2831 (interactive "P")
2833 ;; Make sure we have a file name when we need it.
2834 (when (and (not (or to-buffer body-only))
2835 (not buffer-file-name))
2836 (if (buffer-base-buffer)
2837 (org-set-local 'buffer-file-name
2838 (with-current-buffer (buffer-base-buffer)
2839 buffer-file-name))
2840 (error "Need a file name to be able to export.")))
2842 (message "Exporting...")
2843 (setq-default org-todo-line-regexp org-todo-line-regexp)
2844 (setq-default org-deadline-line-regexp org-deadline-line-regexp)
2845 (setq-default org-done-keywords org-done-keywords)
2846 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
2847 (let* ((opt-plist
2848 (org-export-process-option-filters
2849 (org-combine-plists (org-default-export-plist)
2850 ext-plist
2851 (org-infile-export-plist))))
2852 (style (concat (if (plist-get opt-plist :style-include-default)
2853 org-export-html-style-default)
2854 (plist-get opt-plist :style)
2855 (plist-get opt-plist :style-extra)
2856 "\n"
2857 (if (plist-get opt-plist :style-include-scripts)
2858 org-export-html-scripts)))
2859 (html-extension (plist-get opt-plist :html-extension))
2860 (link-validate (plist-get opt-plist :link-validation-function))
2861 valid thetoc have-headings first-heading-pos
2862 (odd org-odd-levels-only)
2863 (region-p (org-region-active-p))
2864 (rbeg (and region-p (region-beginning)))
2865 (rend (and region-p (region-end)))
2866 (subtree-p
2867 (if (plist-get opt-plist :ignore-subree-p)
2869 (when region-p
2870 (save-excursion
2871 (goto-char rbeg)
2872 (and (org-at-heading-p)
2873 (>= (org-end-of-subtree t t) rend))))))
2874 (level-offset (if subtree-p
2875 (save-excursion
2876 (goto-char rbeg)
2877 (+ (funcall outline-level)
2878 (if org-odd-levels-only 1 0)))
2880 (opt-plist (setq org-export-opt-plist
2881 (if subtree-p
2882 (org-export-add-subtree-options opt-plist rbeg)
2883 opt-plist)))
2884 ;; The following two are dynamically scoped into other
2885 ;; routines below.
2886 (org-current-export-dir
2887 (or pub-dir (org-export-directory :html opt-plist)))
2888 (org-current-export-file buffer-file-name)
2889 (level 0) (line "") (origline "") txt todo
2890 (umax nil)
2891 (umax-toc nil)
2892 (filename (if to-buffer nil
2893 (expand-file-name
2894 (concat
2895 (file-name-sans-extension
2896 (or (and subtree-p
2897 (org-entry-get (region-beginning)
2898 "EXPORT_FILE_NAME" t))
2899 (file-name-nondirectory buffer-file-name)))
2900 "." html-extension)
2901 (file-name-as-directory
2902 (or pub-dir (org-export-directory :html opt-plist))))))
2903 (current-dir (if buffer-file-name
2904 (file-name-directory buffer-file-name)
2905 default-directory))
2906 (buffer (if to-buffer
2907 (cond
2908 ((eq to-buffer 'string) (get-buffer-create "*Org HTML Export*"))
2909 (t (get-buffer-create to-buffer)))
2910 (find-file-noselect filename)))
2911 (org-levels-open (make-vector org-level-max nil))
2912 (date (plist-get opt-plist :date))
2913 (author (plist-get opt-plist :author))
2914 (title (or (and subtree-p (org-export-get-title-from-subtree))
2915 (plist-get opt-plist :title)
2916 (and (not
2917 (plist-get opt-plist :skip-before-1st-heading))
2918 (org-export-grab-title-from-buffer))
2919 (and buffer-file-name
2920 (file-name-sans-extension
2921 (file-name-nondirectory buffer-file-name)))
2922 "UNTITLED"))
2923 (html-table-tag (plist-get opt-plist :html-table-tag))
2924 (quote-re0 (concat "^[ \t]*" org-quote-string "\\>"))
2925 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\>\\)"))
2926 (inquote nil)
2927 (infixed nil)
2928 (inverse nil)
2929 (in-local-list nil)
2930 (local-list-type nil)
2931 (local-list-indent nil)
2932 (llt org-plain-list-ordered-item-terminator)
2933 (email (plist-get opt-plist :email))
2934 (language (plist-get opt-plist :language))
2935 (keywords (plist-get opt-plist :keywords))
2936 (description (plist-get opt-plist :description))
2937 (lang-words nil)
2938 (head-count 0) cnt
2939 (start 0)
2940 (coding-system (and (boundp 'buffer-file-coding-system)
2941 buffer-file-coding-system))
2942 (coding-system-for-write (or org-export-html-coding-system
2943 coding-system))
2944 (save-buffer-coding-system (or org-export-html-coding-system
2945 coding-system))
2946 (charset (and coding-system-for-write
2947 (fboundp 'coding-system-get)
2948 (coding-system-get coding-system-for-write
2949 'mime-charset)))
2950 (region
2951 (buffer-substring
2952 (if region-p (region-beginning) (point-min))
2953 (if region-p (region-end) (point-max))))
2954 (lines
2955 (org-split-string
2956 (org-export-preprocess-string
2957 region
2958 :emph-multiline t
2959 :for-html t
2960 :skip-before-1st-heading
2961 (plist-get opt-plist :skip-before-1st-heading)
2962 :drawers (plist-get opt-plist :drawers)
2963 :todo-keywords (plist-get opt-plist :todo-keywords)
2964 :tags (plist-get opt-plist :tags)
2965 :priority (plist-get opt-plist :priority)
2966 :footnotes (plist-get opt-plist :footnotes)
2967 :timestamps (plist-get opt-plist :timestamps)
2968 :archived-trees
2969 (plist-get opt-plist :archived-trees)
2970 :select-tags (plist-get opt-plist :select-tags)
2971 :exclude-tags (plist-get opt-plist :exclude-tags)
2972 :add-text
2973 (plist-get opt-plist :text)
2974 :LaTeX-fragments
2975 (plist-get opt-plist :LaTeX-fragments))
2976 "[\r\n]"))
2977 table-open type
2978 table-buffer table-orig-buffer
2979 ind item-type starter didclose
2980 rpl path attr desc descp desc1 desc2 link
2981 snumber fnc item-tag
2982 footnotes footref-seen
2983 id-file
2986 (let ((inhibit-read-only t))
2987 (org-unmodified
2988 (remove-text-properties (point-min) (point-max)
2989 '(:org-license-to-kill t))))
2991 (message "Exporting...")
2993 (setq org-min-level (org-get-min-level lines level-offset))
2994 (setq org-last-level org-min-level)
2995 (org-init-section-numbers)
2997 (cond
2998 ((and date (string-match "%" date))
2999 (setq date (format-time-string date)))
3000 (date)
3001 (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))
3003 ;; Get the language-dependent settings
3004 (setq lang-words (or (assoc language org-export-language-setup)
3005 (assoc "en" org-export-language-setup)))
3007 ;; Switch to the output buffer
3008 (set-buffer buffer)
3009 (let ((inhibit-read-only t)) (erase-buffer))
3010 (fundamental-mode)
3012 (and (fboundp 'set-buffer-file-coding-system)
3013 (set-buffer-file-coding-system coding-system-for-write))
3015 (let ((case-fold-search nil)
3016 (org-odd-levels-only odd))
3017 ;; create local variables for all options, to make sure all called
3018 ;; functions get the correct information
3019 (mapc (lambda (x)
3020 (set (make-local-variable (nth 2 x))
3021 (plist-get opt-plist (car x))))
3022 org-export-plist-vars)
3023 (setq umax (if arg (prefix-numeric-value arg)
3024 org-export-headline-levels))
3025 (setq umax-toc (if (integerp org-export-with-toc)
3026 (min org-export-with-toc umax)
3027 umax))
3028 (unless body-only
3029 ;; File header
3030 (insert (format
3031 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3032 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3033 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3034 lang=\"%s\" xml:lang=\"%s\">
3035 <head>
3036 <title>%s</title>
3037 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3038 <meta name=\"generator\" content=\"Org-mode\"/>
3039 <meta name=\"generated\" content=\"%s\"/>
3040 <meta name=\"author\" content=\"%s\"/>
3041 <meta name=\"description\" content=\"%s\"/>
3042 <meta name=\"keywords\" content=\"%s\"/>
3044 </head>
3045 <body>
3046 <div id=\"content\">
3048 language language (org-html-expand title)
3049 (or charset "iso-8859-1")
3050 date author description keywords
3051 style))
3053 (insert (or (plist-get opt-plist :preamble) ""))
3055 (when (plist-get opt-plist :auto-preamble)
3056 (if title (insert (format org-export-html-title-format
3057 (org-html-expand title))))))
3059 (if (and org-export-with-toc (not body-only))
3060 (progn
3061 (push (format "<h%d>%s</h%d>\n"
3062 org-export-html-toplevel-hlevel
3063 (nth 3 lang-words)
3064 org-export-html-toplevel-hlevel)
3065 thetoc)
3066 (push "<div id=\"text-table-of-contents\">\n" thetoc)
3067 (push "<ul>\n<li>" thetoc)
3068 (setq lines
3069 (mapcar '(lambda (line)
3070 (if (string-match org-todo-line-regexp line)
3071 ;; This is a headline
3072 (progn
3073 (setq have-headings t)
3074 (setq level (- (match-end 1) (match-beginning 1)
3075 level-offset)
3076 level (org-tr-level level)
3077 txt (save-match-data
3078 (org-html-expand
3079 (org-export-cleanup-toc-line
3080 (match-string 3 line))))
3081 todo
3082 (or (and org-export-mark-todo-in-toc
3083 (match-beginning 2)
3084 (not (member (match-string 2 line)
3085 org-done-keywords)))
3086 ; TODO, not DONE
3087 (and org-export-mark-todo-in-toc
3088 (= level umax-toc)
3089 (org-search-todo-below
3090 line lines level))))
3091 (if (string-match
3092 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt)
3093 (setq txt (replace-match "&nbsp;&nbsp;&nbsp;<span class=\"tag\"> \\1</span>" t nil txt)))
3094 (if (string-match quote-re0 txt)
3095 (setq txt (replace-match "" t t txt)))
3096 (setq snumber (org-section-number level))
3097 (if org-export-with-section-numbers
3098 (setq txt (concat snumber " " txt)))
3099 (if (<= level (max umax umax-toc))
3100 (setq head-count (+ head-count 1)))
3101 (if (<= level umax-toc)
3102 (progn
3103 (if (> level org-last-level)
3104 (progn
3105 (setq cnt (- level org-last-level))
3106 (while (>= (setq cnt (1- cnt)) 0)
3107 (push "\n<ul>\n<li>" thetoc))
3108 (push "\n" thetoc)))
3109 (if (< level org-last-level)
3110 (progn
3111 (setq cnt (- org-last-level level))
3112 (while (>= (setq cnt (1- cnt)) 0)
3113 (push "</li>\n</ul>" thetoc))
3114 (push "\n" thetoc)))
3115 ;; Check for targets
3116 (while (string-match org-any-target-regexp line)
3117 (setq line (replace-match
3118 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3119 t t line)))
3120 (while (string-match "&lt;\\(&lt;\\)+\\|&gt;\\(&gt;\\)+" txt)
3121 (setq txt (replace-match "" t t txt)))
3122 (push
3123 (format
3124 (if todo
3125 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3126 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3127 snumber txt) thetoc)
3129 (setq org-last-level level))
3131 line)
3132 lines))
3133 (while (> org-last-level (1- org-min-level))
3134 (setq org-last-level (1- org-last-level))
3135 (push "</li>\n</ul>\n" thetoc))
3136 (push "</div>\n" thetoc)
3137 (setq thetoc (if have-headings (nreverse thetoc) nil))))
3139 (setq head-count 0)
3140 (org-init-section-numbers)
3142 (org-open-par)
3144 (while (setq line (pop lines) origline line)
3145 (catch 'nextline
3147 ;; end of quote section?
3148 (when (and inquote (string-match "^\\*+ " line))
3149 (insert "</pre>\n")
3150 (setq inquote nil))
3151 ;; inside a quote section?
3152 (when inquote
3153 (insert (org-html-protect line) "\n")
3154 (throw 'nextline nil))
3156 ;; Fixed-width, verbatim lines (examples)
3157 (when (and org-export-with-fixed-width
3158 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
3159 (when (not infixed)
3160 (setq infixed t)
3161 (org-close-par-maybe)
3163 (insert "<pre class=\"example\">\n"))
3164 (insert (org-html-protect (match-string 3 line)) "\n")
3165 (when (or (not lines)
3166 (not (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)"
3167 (car lines))))
3168 (setq infixed nil)
3169 (insert "</pre>\n"))
3170 (throw 'nextline nil))
3172 ;; Protected HTML
3173 (when (get-text-property 0 'org-protected line)
3174 (let (par)
3175 (when (re-search-backward
3176 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
3177 (setq par (match-string 1))
3178 (replace-match "\\2\n"))
3179 (insert line "\n")
3180 (while (and lines
3181 (or (= (length (car lines)) 0)
3182 (get-text-property 0 'org-protected (car lines))))
3183 (insert (pop lines) "\n"))
3184 (and par (insert "<p>\n")))
3185 (throw 'nextline nil))
3187 ;; Horizontal line
3188 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line)
3189 (if org-par-open
3190 (insert "\n</p>\n<hr/>\n<p>\n")
3191 (insert "\n<hr/>\n"))
3192 (throw 'nextline nil))
3194 ;; Blockquotes, verse, and center
3195 (when (equal "ORG-BLOCKQUOTE-START" line)
3196 (org-close-par-maybe)
3197 (insert "<blockquote>\n")
3198 (org-open-par)
3199 (throw 'nextline nil))
3200 (when (equal "ORG-BLOCKQUOTE-END" line)
3201 (org-close-par-maybe)
3202 (insert "\n</blockquote>\n")
3203 (throw 'nextline nil))
3204 (when (equal "ORG-VERSE-START" line)
3205 (org-close-par-maybe)
3206 (insert "\n<p class=\"verse\">\n")
3207 (setq inverse t)
3208 (throw 'nextline nil))
3209 (when (equal "ORG-VERSE-END" line)
3210 (insert "</p>\n")
3211 (setq inverse nil)
3212 (throw 'nextline nil))
3213 (when (equal "ORG-CENTER-START" line)
3214 (org-close-par-maybe)
3215 (insert "\n<div style=\"text-align: center\">")
3216 (org-open-par)
3217 (throw 'nextline nil))
3218 (when (equal "ORG-CENTER-END" line)
3219 (org-close-par-maybe)
3220 (insert "\n</div>")
3221 (throw 'nextline nil))
3222 (when inverse
3223 (let ((i (org-get-string-indentation line)))
3224 (if (> i 0)
3225 (setq line (concat (mapconcat 'identity
3226 (make-list (* 2 i) "\\nbsp") "")
3227 " " (org-trim line))))
3228 (unless (string-match "\\\\\\\\[ \t]*$" line)
3229 (setq line (concat line "\\\\")))))
3231 ;; make targets to anchors
3232 (while (string-match
3233 "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line)
3234 (cond
3235 ((match-end 2)
3236 (setq line (replace-match
3237 (format
3238 "@<a name=\"%s\" id=\"%s\">@</a>"
3239 (org-solidify-link-text (match-string 1 line))
3240 (org-solidify-link-text (match-string 1 line)))
3241 t t line)))
3242 ((and org-export-with-toc (equal (string-to-char line) ?*))
3243 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3244 (setq line (replace-match
3245 (concat "@<span class=\"target\">" (match-string 1 line) "@</span> ")
3246 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3247 t t line)))
3249 (setq line (replace-match
3250 (concat "@<a name=\""
3251 (org-solidify-link-text (match-string 1 line))
3252 "\" class=\"target\">" (match-string 1 line) "@</a> ")
3253 t t line)))))
3255 (setq line (org-html-handle-time-stamps line))
3257 ;; replace "&" by "&amp;", "<" and ">" by "&lt;" and "&gt;"
3258 ;; handle @<..> HTML tags (replace "@&gt;..&lt;" by "<..>")
3259 ;; Also handle sub_superscripts and checkboxes
3260 (or (string-match org-table-hline-regexp line)
3261 (setq line (org-html-expand line)))
3263 ;; Format the links
3264 (setq start 0)
3265 (while (string-match org-bracket-link-analytic-regexp++ line start)
3266 (setq start (match-beginning 0))
3267 (setq path (save-match-data (org-link-unescape
3268 (match-string 3 line))))
3269 (setq type (cond
3270 ((match-end 2) (match-string 2 line))
3271 ((save-match-data
3272 (or (file-name-absolute-p path)
3273 (string-match "^\\.\\.?/" path)))
3274 "file")
3275 (t "internal")))
3276 (setq path (org-extract-attributes (org-link-unescape path)))
3277 (setq attr (get-text-property 0 'org-attributes path))
3278 (setq desc1 (if (match-end 5) (match-string 5 line))
3279 desc2 (if (match-end 2) (concat type ":" path) path)
3280 descp (and desc1 (not (equal desc1 desc2)))
3281 desc (or desc1 desc2))
3282 ;; Make an image out of the description if that is so wanted
3283 (when (and descp (org-file-image-p
3284 desc org-export-html-inline-image-extensions))
3285 (save-match-data
3286 (if (string-match "^file:" desc)
3287 (setq desc (substring desc (match-end 0)))))
3288 (setq desc (org-add-props
3289 (concat "<img src=\"" desc "\"/>")
3290 '(org-protected t))))
3291 ;; FIXME: do we need to unescape here somewhere?
3292 (cond
3293 ((equal type "internal")
3294 (setq rpl
3295 (concat
3296 "<a href=\""
3297 (if (= (string-to-char path) ?#) "" "#")
3298 (org-solidify-link-text
3299 (save-match-data (org-link-unescape path)) nil)
3300 "\"" attr ">"
3301 (org-export-html-format-desc desc)
3302 "</a>")))
3303 ((and (equal type "id")
3304 (setq id-file (org-id-find-id-file path)))
3305 ;; This is an id: link to another file (if it was the same file,
3306 ;; it would have become an internal link...)
3307 (setq id-file (file-relative-name
3308 id-file (file-name-directory org-current-export-file)))
3309 (setq id-file (concat (file-name-sans-extension id-file)
3310 "." html-extension))
3311 (setq rpl (concat "<a href=\"" id-file "#"
3312 (if (org-uuidgen-p path) "ID-")
3313 path "\""
3314 attr ">"
3315 (org-export-html-format-desc desc)
3316 "</a>")))
3317 ((member type '("http" "https"))
3318 ;; standard URL, just check if we need to inline an image
3319 (if (and (or (eq t org-export-html-inline-images)
3320 (and org-export-html-inline-images (not descp)))
3321 (org-file-image-p
3322 path org-export-html-inline-image-extensions))
3323 (setq rpl (org-export-html-format-image
3324 (concat type ":" path) org-par-open))
3325 (setq link (concat type ":" path))
3326 (setq rpl (concat "<a href=\""
3327 (org-export-html-format-href link)
3328 "\"" attr ">"
3329 (org-export-html-format-desc desc)
3330 "</a>"))))
3331 ((member type '("ftp" "mailto" "news"))
3332 ;; standard URL
3333 (setq link (concat type ":" path))
3334 (setq rpl (concat "<a href=\""
3335 (org-export-html-format-href link)
3336 "\"" attr ">"
3337 (org-export-html-format-desc desc)
3338 "</a>")))
3340 ((string= type "coderef")
3342 (setq rpl (format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3343 path path path
3344 (format (org-export-get-coderef-format path (and descp desc))
3345 (cdr (assoc path org-export-code-refs))))))
3347 ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
3348 ;; The link protocol has a function for format the link
3349 (setq rpl
3350 (save-match-data
3351 (funcall fnc (org-link-unescape path) desc1 'html))))
3353 ((string= type "file")
3354 ;; FILE link
3355 (let* ((filename path)
3356 (abs-p (file-name-absolute-p filename))
3357 thefile file-is-image-p search)
3358 (save-match-data
3359 (if (string-match "::\\(.*\\)" filename)
3360 (setq search (match-string 1 filename)
3361 filename (replace-match "" t nil filename)))
3362 (setq valid
3363 (if (functionp link-validate)
3364 (funcall link-validate filename current-dir)
3366 (setq file-is-image-p
3367 (org-file-image-p
3368 filename org-export-html-inline-image-extensions))
3369 (setq thefile (if abs-p (expand-file-name filename) filename))
3370 (when (and org-export-html-link-org-files-as-html
3371 (string-match "\\.org$" thefile))
3372 (setq thefile (concat (substring thefile 0
3373 (match-beginning 0))
3374 "." html-extension))
3375 (if (and search
3376 ;; make sure this is can be used as target search
3377 (not (string-match "^[0-9]*$" search))
3378 (not (string-match "^\\*" search))
3379 (not (string-match "^/.*/$" search)))
3380 (setq thefile (concat thefile "#"
3381 (org-solidify-link-text
3382 (org-link-unescape search)))))
3383 (when (string-match "^file:" desc)
3384 (setq desc (replace-match "" t t desc))
3385 (if (string-match "\\.org$" desc)
3386 (setq desc (replace-match "" t t desc))))))
3387 (setq rpl (if (and file-is-image-p
3388 (or (eq t org-export-html-inline-images)
3389 (and org-export-html-inline-images
3390 (not descp))))
3391 (progn
3392 (message "image %s %s" thefile org-par-open)
3393 (org-export-html-format-image thefile org-par-open))
3394 (concat "<a href=\"" thefile "\"" attr ">"
3395 (org-export-html-format-desc desc)
3396 "</a>")))
3397 (if (not valid) (setq rpl desc))))
3400 ;; just publish the path, as default
3401 (setq rpl (concat "<i>&lt;" type ":"
3402 (save-match-data (org-link-unescape path))
3403 "&gt;</i>"))))
3404 (setq line (replace-match rpl t t line)
3405 start (+ start (length rpl))))
3407 ;; TODO items
3408 (if (and (string-match org-todo-line-regexp line)
3409 (match-beginning 2))
3411 (setq line
3412 (concat (substring line 0 (match-beginning 2))
3413 "<span class=\""
3414 (if (member (match-string 2 line)
3415 org-done-keywords)
3416 "done" "todo")
3417 " " (match-string 2 line)
3418 "\"> " (org-export-html-get-todo-kwd-class-name
3419 (match-string 2 line))
3420 "</span>" (substring line (match-end 2)))))
3422 ;; Does this contain a reference to a footnote?
3423 (when org-export-with-footnotes
3424 (setq start 0)
3425 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
3426 (if (get-text-property (match-beginning 2) 'org-protected line)
3427 (setq start (match-end 2))
3428 (let ((n (match-string 2 line)) extra a)
3429 (if (setq a (assoc n footref-seen))
3430 (progn
3431 (setcdr a (1+ (cdr a)))
3432 (setq extra (format ".%d" (cdr a))))
3433 (setq extra "")
3434 (push (cons n 1) footref-seen))
3435 (setq line
3436 (replace-match
3437 (format
3438 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3439 (match-string 1 line) n extra n n)
3440 t t line))))))
3442 (cond
3443 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
3444 ;; This is a headline
3445 (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
3446 level-offset))
3447 txt (match-string 2 line))
3448 (if (string-match quote-re0 txt)
3449 (setq txt (replace-match "" t t txt)))
3450 (if (<= level (max umax umax-toc))
3451 (setq head-count (+ head-count 1)))
3452 (when in-local-list
3453 ;; Close any local lists before inserting a new header line
3454 (while local-list-type
3455 (org-close-li (car local-list-type))
3456 (insert (format "</%sl>\n" (car local-list-type)))
3457 (pop local-list-type))
3458 (setq local-list-indent nil
3459 in-local-list nil))
3460 (setq first-heading-pos (or first-heading-pos (point)))
3461 (org-html-level-start level txt umax
3462 (and org-export-with-toc (<= level umax))
3463 head-count)
3465 ;; QUOTES
3466 (when (string-match quote-re line)
3467 (org-close-par-maybe)
3468 (insert "<pre>")
3469 (setq inquote t)))
3471 ((string-match "^[ \t]*- __+[ \t]*$" line)
3472 ;; Explicit list closure
3473 (when local-list-type
3474 (let ((ind (org-get-indentation line)))
3475 (while (and local-list-indent
3476 (<= ind (car local-list-indent)))
3477 (org-close-li (car local-list-type))
3478 (insert (format "</%sl>\n" (car local-list-type)))
3479 (pop local-list-type)
3480 (pop local-list-indent))
3481 (or local-list-indent (setq in-local-list nil))))
3482 (throw 'nextline nil))
3484 ((and org-export-with-tables
3485 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
3486 (when (not table-open)
3487 ;; New table starts
3488 (setq table-open t table-buffer nil table-orig-buffer nil))
3490 ;; Accumulate lines
3491 (setq table-buffer (cons line table-buffer)
3492 table-orig-buffer (cons origline table-orig-buffer))
3493 (when (or (not lines)
3494 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3495 (car lines))))
3496 (setq table-open nil
3497 table-buffer (nreverse table-buffer)
3498 table-orig-buffer (nreverse table-orig-buffer))
3499 (org-close-par-maybe)
3500 (insert (org-format-table-html table-buffer table-orig-buffer))))
3502 ;; Normal lines
3503 (when (string-match
3504 (cond
3505 ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3506 ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3507 ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3508 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3509 line)
3510 (setq ind (org-get-string-indentation line)
3511 item-type (if (match-beginning 4) "o" "u")
3512 starter (if (match-beginning 2)
3513 (substring (match-string 2 line) 0 -1))
3514 line (substring line (match-beginning 5))
3515 item-tag nil)
3516 (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
3517 (setq item-type "d"
3518 item-tag (match-string 1 line)
3519 line (substring line (match-end 0))))
3520 (when (and (not (equal item-type "d"))
3521 (not (string-match "[^ \t]" line)))
3522 ;; empty line. Pretend indentation is large.
3523 (setq ind (if org-empty-line-terminates-plain-lists
3525 (1+ (or (car local-list-indent) 1)))))
3526 (setq didclose nil)
3527 (while (and in-local-list
3528 (or (and (= ind (car local-list-indent))
3529 (not starter))
3530 (< ind (car local-list-indent))))
3531 (setq didclose t)
3532 (org-close-li (car local-list-type))
3533 (insert (format "</%sl>\n" (car local-list-type)))
3534 (pop local-list-type) (pop local-list-indent)
3535 (setq in-local-list local-list-indent))
3536 (cond
3537 ((and starter
3538 (or (not in-local-list)
3539 (> ind (car local-list-indent))))
3540 ;; Start new (level of) list
3541 (org-close-par-maybe)
3542 (insert (cond
3543 ((equal item-type "u") "<ul>\n<li>\n")
3544 ((equal item-type "o") "<ol>\n<li>\n")
3545 ((equal item-type "d")
3546 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag))))
3547 (push item-type local-list-type)
3548 (push ind local-list-indent)
3549 (setq in-local-list t))
3550 (starter
3551 ;; continue current list
3552 (org-close-li (car local-list-type))
3553 (insert (cond
3554 ((equal (car local-list-type) "d")
3555 (format "<dt>%s</dt><dd>\n" (or item-tag "???")))
3556 (t "<li>\n"))))
3557 (didclose
3558 ;; we did close a list, normal text follows: need <p>
3559 (org-open-par)))
3560 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line)
3561 (setq line
3562 (replace-match
3563 (if (equal (match-string 1 line) "X")
3564 "<b>[X]</b>"
3565 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3566 t t line))))
3568 ;; Empty lines start a new paragraph. If hand-formatted lists
3569 ;; are not fully interpreted, lines starting with "-", "+", "*"
3570 ;; also start a new paragraph.
3571 (if (string-match "^ [-+*]-\\|^[ \t]*$" line) (org-open-par))
3573 ;; Is this the start of a footnote?
3574 (when org-export-with-footnotes
3575 (when (and (boundp 'footnote-section-tag-regexp)
3576 (string-match (concat "^" footnote-section-tag-regexp)
3577 line))
3578 ;; ignore this line
3579 (throw 'nextline nil))
3580 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
3581 (org-close-par-maybe)
3582 (let ((n (match-string 1 line)))
3583 (setq org-par-open t
3584 line (replace-match
3585 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n) t t line)))))
3587 ;; Check if the line break needs to be conserved
3588 (cond
3589 ((string-match "\\\\\\\\[ \t]*$" line)
3590 (setq line (replace-match "<br/>" t t line)))
3591 (org-export-preserve-breaks
3592 (setq line (concat line "<br/>"))))
3594 ;; Check if a paragraph should be started
3595 (let ((start 0))
3596 (while (and org-par-open
3597 (string-match "\\\\par\\>" line start))
3598 ;; Leave a space in the </p> so that the footnote matcher
3599 ;; does not see this.
3600 (if (not (get-text-property (match-beginning 0)
3601 'org-protected line))
3602 (setq line (replace-match "</p ><p >" t t line)))
3603 (setq start (match-end 0))))
3605 (insert line "\n")))))
3607 ;; Properly close all local lists and other lists
3608 (when inquote
3609 (insert "</pre>\n")
3610 (org-open-par))
3611 (when in-local-list
3612 ;; Close any local lists before inserting a new header line
3613 (while local-list-type
3614 (org-close-li (car local-list-type))
3615 (insert (format "</%sl>\n" (car local-list-type)))
3616 (pop local-list-type))
3617 (setq local-list-indent nil
3618 in-local-list nil))
3619 (org-html-level-start 1 nil umax
3620 (and org-export-with-toc (<= level umax))
3621 head-count)
3622 ;; the </div> to close the last text-... div.
3623 (when (and (> umax 0) first-heading-pos) (insert "</div>\n"))
3625 (save-excursion
3626 (goto-char (point-min))
3627 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t)
3628 (push (match-string 0) footnotes)
3629 (replace-match "" t t)))
3630 (when footnotes
3631 (insert (format org-export-html-footnotes-section
3632 (or (nth 4 lang-words) "Footnotes")
3633 (mapconcat 'identity (nreverse footnotes) "\n"))
3634 "\n"))
3635 (let ((bib (org-export-html-get-bibliography)))
3636 (when bib
3637 (insert "\n" bib "\n")))
3638 (unless body-only
3639 (when (plist-get opt-plist :auto-postamble)
3640 (insert "<div id=\"postamble\">\n")
3641 (when (and org-export-author-info author)
3642 (insert "<p class=\"author\"> "
3643 (nth 1 lang-words) ": " author "\n")
3644 (when email
3645 (if (listp (split-string email ",+ *"))
3646 (mapc (lambda(e)
3647 (insert "<a href=\"mailto:" e "\">&lt;"
3648 e "&gt;</a>\n"))
3649 (split-string email ",+ *"))
3650 (insert "<a href=\"mailto:" email "\">&lt;"
3651 email "&gt;</a>\n")))
3652 (insert "</p>\n"))
3653 (when (and date org-export-time-stamp-file)
3654 (insert "<p class=\"date\"> "
3655 (nth 2 lang-words) ": "
3656 date "</p>\n"))
3657 (when org-export-creator-info
3658 (insert (format "<p class=\"creator\">HTML generated by org-mode %s in emacs %s</p>\n"
3659 org-version emacs-major-version)))
3660 (when org-export-html-validation-link
3661 (insert org-export-html-validation-link "\n"))
3662 (insert "</div>"))
3664 (if org-export-html-with-timestamp
3665 (insert org-export-html-html-helper-timestamp))
3666 (insert (or (plist-get opt-plist :postamble) ""))
3667 (insert "\n</div>\n</body>\n</html>\n"))
3669 (unless (plist-get opt-plist :buffer-will-be-killed)
3670 (normal-mode)
3671 (if (eq major-mode default-major-mode) (html-mode)))
3673 ;; insert the table of contents
3674 (goto-char (point-min))
3675 (when thetoc
3676 (if (or (re-search-forward
3677 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t)
3678 (re-search-forward
3679 "\\[TABLE-OF-CONTENTS\\]" nil t))
3680 (progn
3681 (goto-char (match-beginning 0))
3682 (replace-match ""))
3683 (goto-char first-heading-pos)
3684 (when (looking-at "\\s-*</p>")
3685 (goto-char (match-end 0))
3686 (insert "\n")))
3687 (insert "<div id=\"table-of-contents\">\n")
3688 (mapc 'insert thetoc)
3689 (insert "</div>\n"))
3690 ;; remove empty paragraphs and lists
3691 (goto-char (point-min))
3692 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t)
3693 (replace-match ""))
3694 (goto-char (point-min))
3695 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t)
3696 (replace-match ""))
3697 (goto-char (point-min))
3698 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t)
3699 (replace-match ""))
3700 ;; Convert whitespace place holders
3701 (goto-char (point-min))
3702 (let (beg end n)
3703 (while (setq beg (next-single-property-change (point) 'org-whitespace))
3704 (setq n (get-text-property beg 'org-whitespace)
3705 end (next-single-property-change beg 'org-whitespace))
3706 (goto-char beg)
3707 (delete-region beg end)
3708 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3709 (make-string n ?x)))))
3710 (or to-buffer (save-buffer))
3711 (goto-char (point-min))
3712 (message "Exporting... done")
3713 (if (eq to-buffer 'string)
3714 (prog1 (buffer-substring (point-min) (point-max))
3715 (kill-buffer (current-buffer)))
3716 (current-buffer)))))
3718 (defun org-export-get-coderef-format (path desc)
3719 (save-match-data
3720 (if (and desc (string-match
3721 (regexp-quote (concat "(" path ")"))
3722 desc))
3723 (replace-match "%s" t t desc)
3724 "%s")))
3727 (defun org-export-html-format-href (s)
3728 "Make sure the S is valid as a href reference in an XHTML document."
3729 (save-match-data
3730 (let ((start 0))
3731 (while (string-match "&" s start)
3732 (setq start (+ (match-beginning 0) 3)
3733 s (replace-match "&amp;" t t s)))))
3736 (defun org-export-html-format-desc (s)
3737 "Make sure the S is valid as a description in a link."
3738 (if (and s (not (get-text-property 1 'org-protected s)))
3739 (save-match-data
3740 (org-html-do-expand s))
3743 (defun org-export-html-format-image (src par-open)
3744 "Create image tag with source and attributes."
3745 (save-match-data
3746 (if (string-match "^ltxpng/" src)
3747 (format "<img src=\"%s\"/>" src)
3748 (let* ((caption (org-find-text-property-in-string 'org-caption src))
3749 (attr (org-find-text-property-in-string 'org-attributes src))
3750 (label (org-find-text-property-in-string 'org-label src)))
3751 (format "%s<div %sclass=\"figure\">
3752 <p><img src=\"%s\"%s /></p>%s
3753 </div>%s"
3754 (if org-par-open "</p>\n" "")
3755 (if label (format "id=\"%s\" " label) "")
3757 (if (string-match "\\<alt=" (or attr ""))
3758 (concat " " attr )
3759 (concat " " attr " alt=\"" src "\""))
3760 (if caption (concat "\n<p>" caption "</p>") "")
3761 (if org-par-open "\n<p>" ""))))))
3763 (defun org-export-html-get-bibliography ()
3764 "Find bibliography, cut it out and return it."
3765 (catch 'exit
3766 (let (beg end (cnt 1) bib)
3767 (save-excursion
3768 (goto-char (point-min))
3769 (when (re-search-forward "^[ \t]*<div \\(id\\|class\\)=\"bibliography\"" nil t)
3770 (setq beg (match-beginning 0))
3771 (while (re-search-forward "</?div\\>" nil t)
3772 (setq cnt (+ cnt (if (string= (match-string 0) "<div") +1 -1)))
3773 (when (= cnt 0)
3774 (and (looking-at ">") (forward-char 1))
3775 (setq bib (buffer-substring beg (point)))
3776 (delete-region beg (point))
3777 (throw 'exit bib))))
3778 nil))))
3780 (defvar org-table-colgroup-info nil)
3782 (defvar org-table-number-regexp) ; defined in org-table.el
3783 (defun org-format-table-html (lines olines)
3784 "Find out which HTML converter to use and return the HTML code."
3785 (if (stringp lines)
3786 (setq lines (org-split-string lines "\n")))
3787 (if (string-match "^[ \t]*|" (car lines))
3788 ;; A normal org table
3789 (org-format-org-table-html lines)
3790 ;; Table made by table.el - test for spanning
3791 (let* ((hlines (delq nil (mapcar
3792 (lambda (x)
3793 (if (string-match "^[ \t]*\\+-" x) x
3794 nil))
3795 lines)))
3796 (first (car hlines))
3797 (ll (and (string-match "\\S-+" first)
3798 (match-string 0 first)))
3799 (re (concat "^[ \t]*" (regexp-quote ll)))
3800 (spanning (delq nil (mapcar (lambda (x) (not (string-match re x)))
3801 hlines))))
3802 (if (and (not spanning)
3803 (not org-export-prefer-native-exporter-for-tables))
3804 ;; We can use my own converter with HTML conversions
3805 (org-format-table-table-html lines)
3806 ;; Need to use the code generator in table.el, with the original text.
3807 (org-format-table-table-html-using-table-generate-source olines)))))
3809 (defvar org-table-number-fraction) ; defined in org-table.el
3810 (defun org-format-org-table-html (lines &optional splice)
3811 "Format a table into HTML."
3812 (require 'org-table)
3813 ;; Get rid of hlines at beginning and end
3814 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3815 (setq lines (nreverse lines))
3816 (if (string-match "^[ \t]*|-" (car lines)) (setq lines (cdr lines)))
3817 (setq lines (nreverse lines))
3818 (when org-export-table-remove-special-lines
3819 ;; Check if the table has a marking column. If yes remove the
3820 ;; column and the special lines
3821 (setq lines (org-table-clean-before-export lines)))
3823 (let* ((caption (or (get-text-property 0 'org-caption (car lines))
3824 (get-text-property (or (next-single-property-change
3825 0 'org-caption (car lines))
3827 'org-caption (car lines))))
3828 (attributes (or (get-text-property 0 'org-attributes (car lines))
3829 (get-text-property (or (next-single-property-change
3830 0 'org-attributes (car lines))
3832 'org-attributes (car lines))))
3833 (html-table-tag (org-export-splice-attributes
3834 html-table-tag attributes))
3835 (head (and org-export-highlight-first-table-line
3836 (delq nil (mapcar
3837 (lambda (x) (string-match "^[ \t]*|-" x))
3838 (cdr lines)))))
3840 (nlines 0) fnum i
3841 tbopen line fields html gr colgropen)
3842 (if splice (setq head nil))
3843 (unless splice (push (if head "<thead>" "<tbody>") html))
3844 (setq tbopen t)
3845 (while (setq line (pop lines))
3846 (catch 'next-line
3847 (if (string-match "^[ \t]*|-" line)
3848 (progn
3849 (unless splice
3850 (push (if head "</thead>" "</tbody>") html)
3851 (if lines (push "<tbody>" html) (setq tbopen nil)))
3852 (setq head nil) ;; head ends here, first time around
3853 ;; ignore this line
3854 (throw 'next-line t)))
3855 ;; Break the line into fields
3856 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
3857 (unless fnum (setq fnum (make-vector (length fields) 0)))
3858 (setq nlines (1+ nlines) i -1)
3859 (push (concat "<tr>"
3860 (mapconcat
3861 (lambda (x)
3862 (setq i (1+ i))
3863 (if (and (< i nlines)
3864 (string-match org-table-number-regexp x))
3865 (incf (aref fnum i)))
3866 (if head
3867 (concat (car org-export-table-header-tags) x
3868 (cdr org-export-table-header-tags))
3869 (concat (car org-export-table-data-tags) x
3870 (cdr org-export-table-data-tags))))
3871 fields "")
3872 "</tr>")
3873 html)))
3874 (unless splice (if tbopen (push "</tbody>" html)))
3875 (unless splice (push "</table>\n" html))
3876 (setq html (nreverse html))
3877 (unless splice
3878 ;; Put in col tags with the alignment (unfortunately often ignored...)
3879 (push (mapconcat
3880 (lambda (x)
3881 (setq gr (pop org-table-colgroup-info))
3882 (format "%s<col align=\"%s\"></col>%s"
3883 (if (memq gr '(:start :startend))
3884 (prog1
3885 (if colgropen "</colgroup>\n<colgroup>" "<colgroup>")
3886 (setq colgropen t))
3888 (if (> (/ (float x) nlines) org-table-number-fraction)
3889 "right" "left")
3890 (if (memq gr '(:end :startend))
3891 (progn (setq colgropen nil) "</colgroup>")
3892 "")))
3893 fnum "")
3894 html)
3895 (if colgropen (setq html (cons (car html) (cons "</colgroup>" (cdr html)))))
3896 ;; Since the output of HTML table formatter can also be used in
3897 ;; DocBook document, we want to always include the caption to make
3898 ;; DocBook XML file valid.
3899 (push (format "<caption>%s</caption>" (or caption "")) html)
3900 (push html-table-tag html))
3901 (concat (mapconcat 'identity html "\n") "\n")))
3903 (defun org-export-splice-attributes (tag attributes)
3904 "Read attributes in string ATTRIBUTES, add and replace in HTML tag TAG."
3905 (if (not attributes)
3907 (let (oldatt newatt)
3908 (setq oldatt (org-extract-attributes-from-string tag)
3909 tag (pop oldatt)
3910 newatt (cdr (org-extract-attributes-from-string attributes)))
3911 (while newatt
3912 (setq oldatt (plist-put oldatt (pop newatt) (pop newatt))))
3913 (if (string-match ">" tag)
3914 (setq tag
3915 (replace-match (concat (org-attributes-to-string oldatt) ">")
3916 t t tag)))
3917 tag)))
3919 (defun org-table-clean-before-export (lines &optional maybe-quoted)
3920 "Check if the table has a marking column.
3921 If yes remove the column and the special lines."
3922 (setq org-table-colgroup-info nil)
3923 (if (memq nil
3924 (mapcar
3925 (lambda (x) (or (string-match "^[ \t]*|-" x)
3926 (string-match
3927 (if maybe-quoted
3928 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
3929 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
3930 x)))
3931 lines))
3932 (progn
3933 (setq org-table-clean-did-remove-column nil)
3934 (delq nil
3935 (mapcar
3936 (lambda (x)
3937 (cond
3938 ((string-match "^[ \t]*| */ *|" x)
3939 (setq org-table-colgroup-info
3940 (mapcar (lambda (x)
3941 (cond ((member x '("<" "&lt;")) :start)
3942 ((member x '(">" "&gt;")) :end)
3943 ((member x '("<>" "&lt;&gt;")) :startend)
3944 (t nil)))
3945 (org-split-string x "[ \t]*|[ \t]*")))
3946 nil)
3947 (t x)))
3948 lines)))
3949 (setq org-table-clean-did-remove-column t)
3950 (delq nil
3951 (mapcar
3952 (lambda (x)
3953 (cond
3954 ((string-match "^[ \t]*| */ *|" x)
3955 (setq org-table-colgroup-info
3956 (mapcar (lambda (x)
3957 (cond ((member x '("<" "&lt;")) :start)
3958 ((member x '(">" "&gt;")) :end)
3959 ((member x '("<>" "&lt;&gt;")) :startend)
3960 (t nil)))
3961 (cdr (org-split-string x "[ \t]*|[ \t]*"))))
3962 nil)
3963 ((string-match "^[ \t]*| *[!_^/] *|" x)
3964 nil) ; ignore this line
3965 ((or (string-match "^\\([ \t]*\\)|-+\\+" x)
3966 (string-match "^\\([ \t]*\\)|[^|]*|" x))
3967 ;; remove the first column
3968 (replace-match "\\1|" t nil x))))
3969 lines))))
3971 (defun org-format-table-table-html (lines)
3972 "Format a table generated by table.el into HTML.
3973 This conversion does *not* use `table-generate-source' from table.el.
3974 This has the advantage that Org-mode's HTML conversions can be used.
3975 But it has the disadvantage, that no cell- or row-spanning is allowed."
3976 (let (line field-buffer
3977 (head org-export-highlight-first-table-line)
3978 fields html empty)
3979 (setq html (concat html-table-tag "\n"))
3980 (while (setq line (pop lines))
3981 (setq empty "&nbsp;")
3982 (catch 'next-line
3983 (if (string-match "^[ \t]*\\+-" line)
3984 (progn
3985 (if field-buffer
3986 (progn
3987 (setq
3988 html
3989 (concat
3990 html
3991 "<tr>"
3992 (mapconcat
3993 (lambda (x)
3994 (if (equal x "") (setq x empty))
3995 (if head
3996 (concat (car org-export-table-header-tags) x
3997 (cdr org-export-table-header-tags))
3998 (concat (car org-export-table-data-tags) x
3999 (cdr org-export-table-data-tags))))
4000 field-buffer "\n")
4001 "</tr>\n"))
4002 (setq head nil)
4003 (setq field-buffer nil)))
4004 ;; Ignore this line
4005 (throw 'next-line t)))
4006 ;; Break the line into fields and store the fields
4007 (setq fields (org-split-string line "[ \t]*|[ \t]*"))
4008 (if field-buffer
4009 (setq field-buffer (mapcar
4010 (lambda (x)
4011 (concat x "<br/>" (pop fields)))
4012 field-buffer))
4013 (setq field-buffer fields))))
4014 (setq html (concat html "</table>\n"))
4015 html))
4017 (defun org-format-table-table-html-using-table-generate-source (lines)
4018 "Format a table into html, using `table-generate-source' from table.el.
4019 This has the advantage that cell- or row-spanning is allowed.
4020 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4021 (require 'table)
4022 (with-current-buffer (get-buffer-create " org-tmp1 ")
4023 (erase-buffer)
4024 (insert (mapconcat 'identity lines "\n"))
4025 (goto-char (point-min))
4026 (if (not (re-search-forward "|[^+]" nil t))
4027 (error "Error processing table"))
4028 (table-recognize-table)
4029 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4030 (table-generate-source 'html " org-tmp2 ")
4031 (set-buffer " org-tmp2 ")
4032 (buffer-substring (point-min) (point-max))))
4034 (defun org-export-splice-style (style extra)
4035 "Splice EXTRA into STYLE, just before \"</style>\"."
4036 (if (and (stringp extra)
4037 (string-match "\\S-" extra)
4038 (string-match "</style>" style))
4039 (concat (substring style 0 (match-beginning 0))
4040 "\n" extra "\n"
4041 (substring style (match-beginning 0)))
4042 style))
4044 (defun org-html-handle-time-stamps (s)
4045 "Format time stamps in string S, or remove them."
4046 (catch 'exit
4047 (let (r b)
4048 (while (string-match org-maybe-keyword-time-regexp s)
4049 (or b (setq b (substring s 0 (match-beginning 0))))
4050 (setq r (concat
4051 r (substring s 0 (match-beginning 0))
4052 (if (match-end 1)
4053 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4054 (match-string 1 s)))
4055 (format " @<span class=\"timestamp\">%s@</span>"
4056 (substring
4057 (org-translate-time (match-string 3 s)) 1 -1)))
4058 s (substring s (match-end 0))))
4059 ;; Line break if line started and ended with time stamp stuff
4060 (if (not r)
4062 (setq r (concat r s))
4063 (unless (string-match "\\S-" (concat b s))
4064 (setq r (concat r "@<br/>")))
4065 r))))
4067 (defun org-export-htmlize-region-for-paste (beg end)
4068 "Convert the region to HTML, using htmlize.el.
4069 This is much like `htmlize-region-for-paste', only that it uses
4070 the settings define in the org-... variables."
4071 (let* ((htmlize-output-type org-export-htmlize-output-type)
4072 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix)
4073 (htmlbuf (htmlize-region beg end)))
4074 (unwind-protect
4075 (with-current-buffer htmlbuf
4076 (buffer-substring (plist-get htmlize-buffer-places 'content-start)
4077 (plist-get htmlize-buffer-places 'content-end)))
4078 (kill-buffer htmlbuf))))
4080 ;;;###autoload
4081 (defun org-export-htmlize-generate-css ()
4082 "Create the CSS for all font definitions in the current Emacs session.
4083 Use this to create face definitions in your CSS style file that can then
4084 be used by code snippets transformed by htmlize.
4085 This command just produces a buffer that contains class definitions for all
4086 faces used in the current Emacs session. You can copy and paste the ones you
4087 need into your CSS file.
4089 If you then set `org-export-htmlize-output-type' to `css', calls to
4090 the function `org-export-htmlize-region-for-paste' will produce code
4091 that uses these same face definitions."
4092 (interactive)
4093 (require 'htmlize)
4094 (and (get-buffer "*html*") (kill-buffer "*html*"))
4095 (with-temp-buffer
4096 (let ((fl (face-list))
4097 (htmlize-css-name-prefix "org-")
4098 (htmlize-output-type 'css)
4099 f i)
4100 (while (setq f (pop fl)
4101 i (and f (face-attribute f :inherit)))
4102 (when (and (symbolp f) (or (not i) (not (listp i))))
4103 (insert (org-add-props (copy-sequence "1") nil 'face f))))
4104 (htmlize-region (point-min) (point-max))))
4105 (switch-to-buffer "*html*")
4106 (goto-char (point-min))
4107 (if (re-search-forward "<style" nil t)
4108 (delete-region (point-min) (match-beginning 0)))
4109 (if (re-search-forward "</style>" nil t)
4110 (delete-region (1+ (match-end 0)) (point-max)))
4111 (beginning-of-line 1)
4112 (if (looking-at " +") (replace-match ""))
4113 (goto-char (point-min)))
4115 (defun org-html-protect (s)
4116 ;; convert & to &amp;, < to &lt; and > to &gt;
4117 (let ((start 0))
4118 (while (string-match "&" s start)
4119 (setq s (replace-match "&amp;" t t s)
4120 start (1+ (match-beginning 0))))
4121 (while (string-match "<" s)
4122 (setq s (replace-match "&lt;" t t s)))
4123 (while (string-match ">" s)
4124 (setq s (replace-match "&gt;" t t s)))
4125 ; (while (string-match "\"" s)
4126 ; (setq s (replace-match "&quot;" t t s)))
4130 (defun org-export-cleanup-toc-line (s)
4131 "Remove tags and timestamps from lines going into the toc."
4132 (when (memq org-export-with-tags '(not-in-toc nil))
4133 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s)
4134 (setq s (replace-match "" t t s))))
4135 (when org-export-remove-timestamps-from-toc
4136 (while (string-match org-maybe-keyword-time-regexp s)
4137 (setq s (replace-match "" t t s))))
4138 (while (string-match org-bracket-link-regexp s)
4139 (setq s (replace-match (match-string (if (match-end 3) 3 1) s)
4140 t t s)))
4143 (defun org-html-expand (string)
4144 "Prepare STRING for HTML export. Applies all active conversions.
4145 If there are links in the string, don't modify these."
4146 (let* ((re (concat org-bracket-link-regexp "\\|"
4147 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4148 m s l res)
4149 (while (setq m (string-match re string))
4150 (setq s (substring string 0 m)
4151 l (match-string 0 string)
4152 string (substring string (match-end 0)))
4153 (push (org-html-do-expand s) res)
4154 (push l res))
4155 (push (org-html-do-expand string) res)
4156 (apply 'concat (nreverse res))))
4158 (defun org-html-do-expand (s)
4159 "Apply all active conversions to translate special ASCII to HTML."
4160 (setq s (org-html-protect s))
4161 (if org-export-html-expand
4162 (while (string-match "@&lt;\\([^&]*\\)&gt;" s)
4163 (setq s (replace-match "<\\1>" t nil s))))
4164 (if org-export-with-emphasize
4165 (setq s (org-export-html-convert-emphasize s)))
4166 (if org-export-with-special-strings
4167 (setq s (org-export-html-convert-special-strings s)))
4168 (if org-export-with-sub-superscripts
4169 (setq s (org-export-html-convert-sub-super s)))
4170 (if org-export-with-TeX-macros
4171 (let ((start 0) wd ass)
4172 (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4173 s start))
4174 (if (get-text-property (match-beginning 0) 'org-protected s)
4175 (setq start (match-end 0))
4176 (setq wd (match-string 1 s))
4177 (if (setq ass (assoc wd org-html-entities))
4178 (setq s (replace-match (or (cdr ass)
4179 (concat "&" (car ass) ";"))
4180 t t s))
4181 (setq start (+ start (length wd))))))))
4184 (defun org-create-multibrace-regexp (left right n)
4185 "Create a regular expression which will match a balanced sexp.
4186 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4187 as single character strings.
4188 The regexp returned will match the entire expression including the
4189 delimiters. It will also define a single group which contains the
4190 match except for the outermost delimiters. The maximum depth of
4191 stacked delimiters is N. Escaping delimiters is not possible."
4192 (let* ((nothing (concat "[^" left right "]*?"))
4193 (or "\\|")
4194 (re nothing)
4195 (next (concat "\\(?:" nothing left nothing right "\\)+" nothing)))
4196 (while (> n 1)
4197 (setq n (1- n)
4198 re (concat re or next)
4199 next (concat "\\(?:" nothing left next right "\\)+" nothing)))
4200 (concat left "\\(" re "\\)" right)))
4202 (defvar org-match-substring-regexp
4203 (concat
4204 "\\([^\\]\\)\\([_^]\\)\\("
4205 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4206 "\\|"
4207 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth) "\\)"
4208 "\\|"
4209 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4210 "The regular expression matching a sub- or superscript.")
4212 (defvar org-match-substring-with-braces-regexp
4213 (concat
4214 "\\([^\\]\\)\\([_^]\\)\\("
4215 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth) "\\)"
4216 "\\)")
4217 "The regular expression matching a sub- or superscript, forcing braces.")
4219 (defconst org-export-html-special-string-regexps
4220 '(("\\\\-" . "&shy;")
4221 ("---\\([^-]\\)" . "&mdash;\\1")
4222 ("--\\([^-]\\)" . "&ndash;\\1")
4223 ("\\.\\.\\." . "&hellip;"))
4224 "Regular expressions for special string conversion.")
4226 (defun org-export-html-convert-special-strings (string)
4227 "Convert special characters in STRING to HTML."
4228 (let ((all org-export-html-special-string-regexps)
4229 e a re rpl start)
4230 (while (setq a (pop all))
4231 (setq re (car a) rpl (cdr a) start 0)
4232 (while (string-match re string start)
4233 (if (get-text-property (match-beginning 0) 'org-protected string)
4234 (setq start (match-end 0))
4235 (setq string (replace-match rpl t nil string)))))
4236 string))
4238 (defun org-export-html-convert-sub-super (string)
4239 "Convert sub- and superscripts in STRING to HTML."
4240 (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
4241 (while (string-match org-match-substring-regexp string s)
4242 (cond
4243 ((and requireb (match-end 8)) (setq s (match-end 2)))
4244 ((get-text-property (match-beginning 2) 'org-protected string)
4245 (setq s (match-end 2)))
4247 (setq s (match-end 1)
4248 key (if (string= (match-string 2 string) "_") "sub" "sup")
4249 c (or (match-string 8 string)
4250 (match-string 6 string)
4251 (match-string 5 string))
4252 string (replace-match
4253 (concat (match-string 1 string)
4254 "<" key ">" c "</" key ">")
4255 t t string)))))
4256 (while (string-match "\\\\\\([_^]\\)" string)
4257 (setq string (replace-match (match-string 1 string) t t string)))
4258 string))
4260 (defun org-export-html-convert-emphasize (string)
4261 "Apply emphasis."
4262 (let ((s 0) rpl)
4263 (while (string-match org-emph-re string s)
4264 (if (not (equal
4265 (substring string (match-beginning 3) (1+ (match-beginning 3)))
4266 (substring string (match-beginning 4) (1+ (match-beginning 4)))))
4267 (setq s (match-beginning 0)
4269 (concat
4270 (match-string 1 string)
4271 (nth 2 (assoc (match-string 3 string) org-emphasis-alist))
4272 (match-string 4 string)
4273 (nth 3 (assoc (match-string 3 string)
4274 org-emphasis-alist))
4275 (match-string 5 string))
4276 string (replace-match rpl t t string)
4277 s (+ s (- (length rpl) 2)))
4278 (setq s (1+ s))))
4279 string))
4281 (defun org-open-par ()
4282 "Insert <p>, but first close previous paragraph if any."
4283 (org-close-par-maybe)
4284 (insert "\n<p>")
4285 (setq org-par-open t))
4286 (defun org-close-par-maybe ()
4287 "Close paragraph if there is one open."
4288 (when org-par-open
4289 (insert "</p>")
4290 (setq org-par-open nil)))
4291 (defun org-close-li (&optional type)
4292 "Close <li> if necessary."
4293 (org-close-par-maybe)
4294 (insert (if (equal type "d") "</dd>\n" "</li>\n")))
4296 (defvar body-only) ; dynamically scoped into this.
4297 (defun org-html-level-start (level title umax with-toc head-count)
4298 "Insert a new level in HTML export.
4299 When TITLE is nil, just close all open levels."
4300 (org-close-par-maybe)
4301 (let* ((target (and title (org-get-text-property-any 0 'target title)))
4302 (extra-targets
4303 (mapconcat (lambda (x)
4304 (if (org-uuidgen-p x) (setq x (concat "ID-" x)))
4305 (format "<a name=\"%s\" id=\"%s\"></a>"
4306 x x))
4307 (cdr (assoc target org-export-target-aliases))
4308 ""))
4309 (l org-level-max)
4310 snumber)
4311 (while (>= l level)
4312 (if (aref org-levels-open (1- l))
4313 (progn
4314 (org-html-level-close l umax)
4315 (aset org-levels-open (1- l) nil)))
4316 (setq l (1- l)))
4317 (when title
4318 ;; If title is nil, this means this function is called to close
4319 ;; all levels, so the rest is done only if title is given
4320 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
4321 (setq title (replace-match
4322 (if org-export-with-tags
4323 (save-match-data
4324 (concat
4325 "&nbsp;&nbsp;&nbsp;<span class=\"tag\">"
4326 (mapconcat
4327 (lambda (x)
4328 (format "<span class=\"%s\">%s</span>"
4329 (org-export-html-get-tag-class-name x)
4331 (org-split-string (match-string 1 title) ":")
4332 "&nbsp;")
4333 "</span>"))
4335 t t title)))
4336 (if (> level umax)
4337 (progn
4338 (if (aref org-levels-open (1- level))
4339 (progn
4340 (org-close-li)
4341 (if target
4342 (insert (format "<li id=\"%s\">" target) extra-targets title "<br/>\n")
4343 (insert "<li>" title "<br/>\n")))
4344 (aset org-levels-open (1- level) t)
4345 (org-close-par-maybe)
4346 (if target
4347 (insert (format "<ul>\n<li id=\"%s\">" target)
4348 extra-targets title "<br/>\n")
4349 (insert "<ul>\n<li>" title "<br/>\n"))))
4350 (aset org-levels-open (1- level) t)
4351 (setq snumber (org-section-number level))
4352 (setq level (+ level org-export-html-toplevel-hlevel -1))
4353 (if (and org-export-with-section-numbers (not body-only))
4354 (setq title (concat
4355 (format "<span class=\"section-number-%d\">%s</span>"
4356 level snumber)
4357 " " title)))
4358 (unless (= head-count 1) (insert "\n</div>\n"))
4359 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
4360 snumber level level snumber extra-targets
4361 title level level snumber))
4362 (org-open-par)))))
4364 (defun org-get-text-property-any (pos prop &optional object)
4365 (or (get-text-property pos prop object)
4366 (and (setq pos (next-single-property-change pos prop object))
4367 (get-text-property pos prop object))))
4369 (defun org-export-html-get-tag-class-name (tag)
4370 "Turn tag into a valid class name.
4371 Replaces invalid characters with \"_\" and then prepends a prefix."
4372 (save-match-data
4373 (while (string-match "[^a-zA-Z0-9_]" tag)
4374 (setq tag (replace-match "_" t t tag))))
4375 (concat org-export-html-tag-class-prefix tag))
4377 (defun org-export-html-get-todo-kwd-class-name (kwd)
4378 "Turn todo keyword into a valid class name.
4379 Replaces invalid characters with \"_\" and then prepends a prefix."
4380 (save-match-data
4381 (while (string-match "[^a-zA-Z0-9_]" kwd)
4382 (setq kwd (replace-match "_" t t kwd))))
4383 (concat org-export-html-todo-kwd-class-prefix kwd))
4385 (defun org-html-level-close (level max-outline-level)
4386 "Terminate one level in HTML export."
4387 (if (<= level max-outline-level)
4388 (insert "</div>\n")
4389 (org-close-li)
4390 (insert "</ul>\n")))
4392 (provide 'org-exp)
4394 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4396 ;;; org-exp.el ends here