1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
68 (defcustom org-export-select-tags
'("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group
'org-export-general
75 :type
'(repeat (string :tag
"Tag")))
77 (defcustom org-export-exclude-tags
'("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without condition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group
'org-export-general
83 :type
'(repeat (string :tag
"Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
90 -----+----------+--------
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group
'org-export-translation
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
102 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
106 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "Índice" "Pies de página")
108 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
110 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
111 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis treści" "Przypis")
118 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group
'org-export-general
125 (string :tag
"HTML language tag")
126 (string :tag
"Author")
128 (string :tag
"Table of Contents")
129 (string :tag
"Footnotes"))))
131 (defcustom org-export-default-language
"en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group
'org-export-general
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group
'org-export-general
143 (defcustom org-export-headline-levels
3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group
'org-export-general
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group
'org-export-general
160 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
172 :group
'org-export-general
176 (string :tag
"Counter Type")
177 (string :tag
"Separator ")))
178 (string :tag
"Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
196 :group
'org-export-general
198 (const :tag
"No Table of Contents" nil
)
199 (const :tag
"Full Table of Contents" t
)
200 (integer :tag
"TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group
'org-export-general
207 (defcustom org-export-with-todo-keywords t
208 "Non-nil means, include TODO keywords in export.
209 When nil, remove all these keywords from the export."
210 :group
'org-export-general
213 (defcustom org-export-with-priority nil
214 "Non-nil means, include priority cookies in export.
215 When nil, remove priority cookies for export."
216 :group
'org-export-general
219 (defcustom org-export-preserve-breaks nil
220 "Non-nil means, preserve all line breaks when exporting.
221 Normally, in HTML output paragraphs will be reformatted. In ASCII
222 export, line breaks will always be preserved, regardless of this variable.
224 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
225 :group
'org-export-general
228 (defcustom org-export-with-archived-trees
'headline
229 "Whether subtrees with the ARCHIVE tag should be exported.
230 This can have three different values
231 nil Do not export, pretend this tree is not present
232 t Do export the entire tree
233 headline Only export the headline, but skip the tree below it."
234 :group
'org-export-general
237 (const :tag
"not at all" nil
)
238 (const :tag
"headline only" 'headline
)
239 (const :tag
"entirely" t
)))
241 (defcustom org-export-author-info t
242 "Non-nil means, insert author name and email into the exported file.
244 This option can also be set with the +OPTIONS line,
245 e.g. \"author-info:nil\"."
246 :group
'org-export-general
249 (defcustom org-export-creator-info t
250 "Non-nil means, the postamble should contain a creator sentence.
251 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
252 :group
'org-export-general
255 (defcustom org-export-time-stamp-file t
256 "Non-nil means, insert a time stamp into the exported file.
257 The time stamp shows when the file was created.
259 This option can also be set with the +OPTIONS line,
260 e.g. \"timestamp:nil\"."
261 :group
'org-export-general
264 (defcustom org-export-with-timestamps t
265 "If nil, do not export time stamps and associated keywords."
266 :group
'org-export-general
269 (defcustom org-export-remove-timestamps-from-toc t
270 "If nil, remove timestamps from the table of contents entries."
271 :group
'org-export-general
274 (defcustom org-export-with-tags
'not-in-toc
275 "If nil, do not export tags, just remove them from headlines.
276 If this is the symbol `not-in-toc', tags will be removed from table of
277 contents entries, but still be shown in the headlines of the document.
279 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
280 :group
'org-export-general
282 (const :tag
"Off" nil
)
283 (const :tag
"Not in TOC" not-in-toc
)
284 (const :tag
"On" t
)))
286 (defcustom org-export-with-drawers nil
287 "Non-nil means, export with drawers like the property drawer.
288 When t, all drawers are exported. This may also be a list of
289 drawer names to export."
290 :group
'org-export-general
292 (const :tag
"All drawers" t
)
293 (const :tag
"None" nil
)
294 (repeat :tag
"Selected drawers"
295 (string :tag
"Drawer name"))))
297 (defvar org-export-preprocess-hook nil
298 "Hook for preprocessing an export buffer.
299 Pretty much the first thing when exporting is running this hook.")
301 (defgroup org-export-translation nil
302 "Options for translating special ascii sequences for the export backends."
303 :tag
"Org Export Translation"
306 (defcustom org-export-with-emphasize t
307 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
308 If the export target supports emphasizing text, the word will be
309 typeset in bold, italic, or underlined, respectively. Works only for
310 single words, but you can say: I *really* *mean* *this*.
311 Not all export backends support this.
313 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
314 :group
'org-export-translation
317 (defcustom org-export-with-footnotes t
318 "If nil, export [1] as a footnote marker.
319 Lines starting with [1] will be formatted as footnotes.
321 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
322 :group
'org-export-translation
325 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
326 <h2 class=\"footnotes\">%s: </h2>
327 <div id=\"footnotes-text\">
331 "Format for the footnotes section.
332 Should contain a two instances of %s. The first will be replaced with the
333 language-specific word for \"Footnotes\", the second one will be replaced
334 by the footnotes themselves."
335 :group
'org-export-html
338 (defcustom org-export-with-sub-superscripts t
339 "Non-nil means, interpret \"_\" and \"^\" for export.
340 When this option is turned on, you can use TeX-like syntax for sub- and
341 superscripts. Several characters after \"_\" or \"^\" will be
342 considered as a single item - so grouping with {} is normally not
343 needed. For example, the following things will be parsed as single
344 sub- or superscripts.
346 10^24 or 10^tau several digits will be considered 1 item.
347 10^-12 or 10^-tau a leading sign with digits or a word
348 x^2-y^3 will be read as x^2 - y^3, because items are
349 terminated by almost any nonword/nondigit char.
350 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
352 Still, ambiguity is possible - so when in doubt use {} to enclose the
353 sub/superscript. If you set this variable to the symbol `{}',
354 the braces are *required* in order to trigger interpretations as
355 sub/superscript. This can be helpful in documents that need \"_\"
356 frequently in plain text.
358 Not all export backends support this, but HTML does.
360 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
361 :group
'org-export-translation
363 (const :tag
"Always interpret" t
)
364 (const :tag
"Only with braces" {})
365 (const :tag
"Never interpret" nil
)))
367 (defcustom org-export-with-special-strings t
368 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
369 When this option is turned on, these strings will be exported as:
375 Not all export backends support this, but HTML does.
377 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
378 :group
'org-export-translation
381 (defcustom org-export-with-TeX-macros t
382 "Non-nil means, interpret simple TeX-like macros when exporting.
383 For example, HTML export converts \\alpha to α and \\AA to Å.
384 No only real TeX macros will work here, but the standard HTML entities
385 for math can be used as macro names as well. For a list of supported
386 names in HTML export, see the constant `org-html-entities'.
387 Not all export backends support this.
389 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
390 :group
'org-export-translation
391 :group
'org-export-latex
394 (defcustom org-export-with-LaTeX-fragments nil
395 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
396 When set, the exporter will find LaTeX environments if the \\begin line is
397 the first non-white thing on a line. It will also find the math delimiters
398 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
401 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
402 :group
'org-export-translation
403 :group
'org-export-latex
406 (defcustom org-export-with-fixed-width t
407 "Non-nil means, lines starting with \":\" will be in fixed width font.
408 This can be used to have pre-formatted text, fragments of code etc. For
410 : ;; Some Lisp examples
413 will be looking just like this in also HTML. See also the QUOTE keyword.
414 Not all export backends support this.
416 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
417 :group
'org-export-translation
420 (defcustom org-match-sexp-depth
3
421 "Number of stacked braces for sub/superscript matching.
422 This has to be set before loading org.el to be effective."
423 :group
'org-export-translation
426 (defgroup org-export-tables nil
427 "Options for exporting tables in Org-mode."
428 :tag
"Org Export Tables"
431 (defcustom org-export-with-tables t
432 "If non-nil, lines starting with \"|\" define a table.
435 | Name | Address | Birthday |
436 |-------------+----------+-----------|
437 | Arthur Dent | England | 29.2.2100 |
439 Not all export backends support this.
441 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
442 :group
'org-export-tables
445 (defcustom org-export-highlight-first-table-line t
446 "Non-nil means, highlight the first table line.
447 In HTML export, this means use <th> instead of <td>.
448 In tables created with table.el, this applies to the first table line.
449 In Org-mode tables, all lines before the first horizontal separator
450 line will be formatted with <th> tags."
451 :group
'org-export-tables
454 (defcustom org-export-table-remove-special-lines t
455 "Remove special lines and marking characters in calculating tables.
456 This removes the special marking character column from tables that are set
457 up for spreadsheet calculations. It also removes the entire lines
458 marked with `!', `_', or `^'. The lines with `$' are kept, because
459 the values of constants may be useful to have."
460 :group
'org-export-tables
463 (defcustom org-export-prefer-native-exporter-for-tables nil
464 "Non-nil means, always export tables created with table.el natively.
465 Natively means, use the HTML code generator in table.el.
466 When nil, Org-mode's own HTML generator is used when possible (i.e. if
467 the table does not use row- or column-spanning). This has the
468 advantage, that the automatic HTML conversions for math symbols and
469 sub/superscripts can be applied. Org-mode's HTML generator is also
471 :group
'org-export-tables
474 (defgroup org-export-ascii nil
475 "Options specific for ASCII export of Org-mode files."
476 :tag
"Org Export ASCII"
479 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
480 "Characters for underlining headings in ASCII export.
481 In the given sequence, these characters will be used for level 1, 2, ..."
482 :group
'org-export-ascii
483 :type
'(repeat character
))
485 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
486 "Bullet characters for headlines converted to lists in ASCII export.
487 The first character is used for the first lest level generated in this
488 way, and so on. If there are more levels than characters given here,
489 the list will be repeated.
490 Note that plain lists will keep the same bullets as the have in the
492 :group
'org-export-ascii
493 :type
'(repeat character
))
495 (defgroup org-export-xml nil
496 "Options specific for XML export of Org-mode files."
497 :tag
"Org Export XML"
500 (defgroup org-export-html nil
501 "Options specific for HTML export of Org-mode files."
502 :tag
"Org Export HTML"
505 (defcustom org-export-html-coding-system nil
506 "Coding system for HTML export, defaults to buffer-file-coding-system."
507 :group
'org-export-html
508 :type
'coding-system
)
510 (defcustom org-export-html-extension
"html"
511 "The extension for exported HTML files."
512 :group
'org-export-html
515 (defcustom org-export-html-link-up
""
516 "Where should the \"UP\" link of exported HTML pages lead?"
517 :group
'org-export-html
518 :type
'(string :tag
"File or URL"))
520 (defcustom org-export-html-link-home
""
521 "Where should the \"HOME\" link of exported HTML pages lead?"
522 :group
'org-export-html
523 :type
'(string :tag
"File or URL"))
525 (defconst org-export-html-style-default
526 "<style type=\"text/css\">
527 <!--/*--><![CDATA[/*><!--*/
528 html { font-family: Times, serif; font-size: 12pt; }
529 .title { text-align: center; }
530 .todo { color: red; }
531 .done { color: green; }
532 .tag { background-color:lightblue; font-weight:normal }
534 .timestamp { color: grey }
535 .timestamp-kwd { color: CadetBlue }
536 p.verse { margin-left: 3% }
538 border: 1pt solid #AEBDCC;
539 background-color: #F3F5F7;
541 font-family: courier, monospace;
545 table { border-collapse: collapse; }
546 td, th { vertical-align: top; }
547 dt { font-weight: bold; }
548 div.figure { padding: 0.5em; }
549 div.figure p { text-align: center; }
550 .org-info-js_info-navigation { border-style:none; }
551 #org-info-js_console-label { font-size:10px; font-weight:bold;
552 white-space:nowrap; }
553 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
557 "The default style specification for exported HTML files.
558 Please use the variables `org-export-html-style' and
559 `org-export-html-style-extra' to add to this style. If you wish to not
560 have the default style included, customize the variable
561 `org-export-html-style-include-default'.")
563 (defcustom org-export-html-style-include-default t
564 "Non-nil means, include the default style in exported HTML files.
565 The actual style is defined in `org-export-html-style-default' and should
566 not be modified. Use the variables `org-export-html-style' to add
567 your own style information."
568 :group
'org-export-html
571 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
573 (defcustom org-export-html-style
""
574 "Org-wide style definitions for exported HTML files.
576 This variable needs to contain the full HTML structure to provide a style,
577 including the surrounding HTML tags. If you set the value of this variable,
578 you should consider to include definitions for the following classes:
579 title, todo, done, timestamp, timestamp-kwd, tag, target.
581 For example, a valid value would be:
583 <style type=\"text/css\">
585 p { font-weight: normal; color: gray; }
587 .title { text-align: center; }
588 .todo, .timestamp-kwd { color: red; }
589 .done { color: green; }
593 If you'd like to refer to en external style file, use something like
595 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
597 As the value of this option simply gets inserted into the HTML <head> header,
598 you can \"misuse\" it to add arbitrary text to the header.
599 See also the variable `org-export-html-style-extra'."
600 :group
'org-export-html
603 (put 'org-export-html-style
'safe-local-variable
'stringp
)
605 (defcustom org-export-html-style-extra
""
606 "Additional style information for HTML export.
607 The value of this variable is inserted into the HTML buffer right after
608 the value of `org-export-html-style'. Use this variable for per-file
609 settings of style information, and do not forget to surround the style
610 settings with <style>...</style> tags."
611 :group
'org-export-html
614 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
617 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
618 "Format for typesetting the document title in HTML export."
619 :group
'org-export-html
622 (defcustom org-export-html-toplevel-hlevel
2
623 "The <H> level for level 1 headings in HTML export."
624 :group
'org-export-html
627 (defcustom org-export-html-link-org-files-as-html t
628 "Non-nil means, make file links to `file.org' point to `file.html'.
629 When org-mode is exporting an org-mode file to HTML, links to
630 non-html files are directly put into a href tag in HTML.
631 However, links to other Org-mode files (recognized by the
632 extension `.org.) should become links to the corresponding html
633 file, assuming that the linked org-mode file will also be
635 When nil, the links still point to the plain `.org' file."
636 :group
'org-export-html
639 (defcustom org-export-html-inline-images
'maybe
640 "Non-nil means, inline images into exported HTML pages.
641 This is done using an <img> tag. When nil, an anchor with href is used to
642 link to the image. If this option is `maybe', then images in links with
643 an empty description will be inlined, while images with a description will
645 :group
'org-export-html
646 :type
'(choice (const :tag
"Never" nil
)
647 (const :tag
"Always" t
)
648 (const :tag
"When there is no description" maybe
)))
651 (defcustom org-export-html-expand t
652 "Non-nil means, for HTML export, treat @<...> as HTML tag.
653 When nil, these tags will be exported as plain text and therefore
654 not be interpreted by a browser.
656 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
657 :group
'org-export-html
660 (defcustom org-export-html-table-tag
661 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
662 "The HTML tag that is used to start a table.
663 This must be a <table> tag, but you may change the options like
664 borders and spacing."
665 :group
'org-export-html
668 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
669 "The opening tag for table header fields.
670 This is customizable so that alignment options can be specified."
671 :group
'org-export-tables
672 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
674 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
675 "The opening tag for table data fields.
676 This is customizable so that alignment options can be specified."
677 :group
'org-export-tables
678 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
680 (defcustom org-export-html-with-timestamp nil
681 "If non-nil, write `org-export-html-html-helper-timestamp'
682 into the exported HTML text. Otherwise, the buffer will just be saved
684 :group
'org-export-html
687 (defcustom org-export-html-html-helper-timestamp
688 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
689 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
690 :group
'org-export-html
693 (defgroup org-export-htmlize nil
694 "Options for processing examples with htmlize.el."
695 :tag
"Org Export Htmlize"
696 :group
'org-export-html
)
698 (defcustom org-export-htmlize-output-type
'inline-css
699 "Output type to be used by htmlize when formatting code snippets.
700 Normally this is `inline-css', but if you have defined to appropriate
701 classes in your css style file, setting this to `css' means that the
702 fontification will use the class names.
703 See also the function `org-export-htmlize-generate-css'."
704 :group
'org-export-htmlize
705 :type
'(choice (const css
) (const inline-css
)))
707 (defcustom org-export-htmlize-css-font-prefix
"org-"
708 "The prefix for CSS class names for htmlize font specifications."
709 :group
'org-export-htmlize
712 (defgroup org-export-icalendar nil
713 "Options specific for iCalendar export of Org-mode files."
714 :tag
"Org Export iCalendar"
717 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
718 "The file name for the iCalendar file covering all agenda files.
719 This file is created with the command \\[org-export-icalendar-all-agenda-files].
720 The file name should be absolute, the file will be overwritten without warning."
721 :group
'org-export-icalendar
724 (defcustom org-icalendar-combined-name
"OrgMode"
725 "Calendar name for the combined iCalendar representing all agenda files."
726 :group
'org-export-icalendar
729 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
730 "Contexts where iCalendar export should use a deadline time stamp.
731 This is a list with several symbols in it. Valid symbol are:
733 event-if-todo Deadlines in TODO entries become calendar events.
734 event-if-not-todo Deadlines in non-TODO entries become calendar events.
735 todo-due Use deadlines in TODO entries as due-dates"
736 :group
'org-export-icalendar
737 :type
'(set :greedy t
738 (const :tag
"Deadlines in non-TODO entries become events"
740 (const :tag
"Deadline in TODO entries become events"
742 (const :tag
"Deadlines in TODO entries become due-dates"
745 (defcustom org-icalendar-use-scheduled
'(todo-start)
746 "Contexts where iCalendar export should use a scheduling time stamp.
747 This is a list with several symbols in it. Valid symbol are:
749 event-if-todo Scheduling time stamps in TODO entries become an event.
750 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
751 todo-start Scheduling time stamps in TODO entries become start date.
752 Some calendar applications show TODO entries only after
754 :group
'org-export-icalendar
755 :type
'(set :greedy t
757 "SCHEDULED timestamps in non-TODO entries become events"
759 (const :tag
"SCHEDULED timestamps in TODO entries become events"
761 (const :tag
"SCHEDULED in TODO entries become start date"
764 (defcustom org-icalendar-categories
'(local-tags category
)
765 "Items that should be entered into the categories field.
766 This is a list of symbols, the following are valid:
768 category The Org-mode category of the current file or tree
769 todo-state The todo state, if any
770 local-tags The tags, defined in the current line
771 all-tags All tags, including inherited ones."
772 :group
'org-export-icalendar
775 (const :tag
"The file or tree category" category
)
776 (const :tag
"The TODO state" todo-state
)
777 (const :tag
"Tags defined in current line" local-tags
)
778 (const :tag
"All tags, including inherited ones" all-tags
))))
780 (defcustom org-icalendar-include-todo nil
781 "Non-nil means, export to iCalendar files should also cover TODO items."
782 :group
'org-export-icalendar
784 (const :tag
"None" nil
)
785 (const :tag
"Unfinished" t
)
786 (const :tag
"All" all
)))
788 (defcustom org-icalendar-include-sexps t
789 "Non-nil means, export to iCalendar files should also cover sexp entries.
790 These are entries like in the diary, but directly in an Org-mode file."
791 :group
'org-export-icalendar
794 (defcustom org-icalendar-include-body
100
795 "Amount of text below headline to be included in iCalendar export.
796 This is a number of characters that should maximally be included.
797 Properties, scheduling and clocking lines will always be removed.
798 The text will be inserted into the DESCRIPTION field."
799 :group
'org-export-icalendar
801 (const :tag
"Nothing" nil
)
802 (const :tag
"Everything" t
)
803 (integer :tag
"Max characters")))
805 (defcustom org-icalendar-store-UID nil
806 "Non-nil means, store any created UIDs in properties.
807 The iCalendar standard requires that all entries have a unique identifier.
808 Org will create these identifiers as needed. When this variable is non-nil,
809 the created UIDs will be stored in the ID property of the entry. Then the
810 next time this entry is exported, it will be exported with the same UID,
811 superceding the previous form of it. This is essential for
812 synchronization services.
813 This variable is not turned on by default because we want to avoid creating
814 a property drawer in every entry if people are only playing with this feature,
815 or if they are only using it locally."
816 :group
'org-export-icalendar
821 ;;; Variables, constants, and parameter plists
823 (defconst org-level-max
20)
825 (defvar org-export-html-preamble nil
826 "Preamble, to be inserted just before <body>. Set by publishing functions.")
827 (defvar org-export-html-postamble nil
828 "Preamble, to be inserted just after </body>. Set by publishing functions.")
829 (defvar org-export-html-auto-preamble t
830 "Should default preamble be inserted? Set by publishing functions.")
831 (defvar org-export-html-auto-postamble t
832 "Should default postamble be inserted? Set by publishing functions.")
833 (defvar org-current-export-file nil
) ; dynamically scoped parameter
834 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
836 (defconst org-export-plist-vars
837 '((:link-up nil org-export-html-link-up
)
838 (:link-home nil org-export-html-link-home
)
839 (:language nil org-export-default-language
)
840 (:customtime nil org-display-custom-times
)
841 (:headline-levels
"H" org-export-headline-levels
)
842 (:section-numbers
"num" org-export-with-section-numbers
)
843 (:section-number-format nil org-export-section-number-format
)
844 (:table-of-contents
"toc" org-export-with-toc
)
845 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
846 (:archived-trees nil org-export-with-archived-trees
)
847 (:emphasize
"*" org-export-with-emphasize
)
848 (:sub-superscript
"^" org-export-with-sub-superscripts
)
849 (:special-strings
"-" org-export-with-special-strings
)
850 (:footnotes
"f" org-export-with-footnotes
)
851 (:drawers
"d" org-export-with-drawers
)
852 (:tags
"tags" org-export-with-tags
)
853 (:todo-keywords
"todo" org-export-with-todo-keywords
)
854 (:priority
"pri" org-export-with-priority
)
855 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
856 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
857 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
858 (:fixed-width
":" org-export-with-fixed-width
)
859 (:timestamps
"<" org-export-with-timestamps
)
860 (:author-info
"author" org-export-author-info
)
861 (:creator-info
"creator" org-export-creator-info
)
862 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
863 (:tables
"|" org-export-with-tables
)
864 (:table-auto-headline nil org-export-highlight-first-table-line
)
865 (:style-include-default nil org-export-html-style-include-default
)
866 (:style nil org-export-html-style
)
867 (:style-extra nil org-export-html-style-extra
)
868 (:agenda-style nil org-agenda-export-html-style
)
869 (:convert-org-links nil org-export-html-link-org-files-as-html
)
870 (:inline-images nil org-export-html-inline-images
)
871 (:html-extension nil org-export-html-extension
)
872 (:html-table-tag nil org-export-html-table-tag
)
873 (:expand-quoted-html
"@" org-export-html-expand
)
874 (:timestamp nil org-export-html-with-timestamp
)
875 (:publishing-directory nil org-export-publishing-directory
)
876 (:preamble nil org-export-html-preamble
)
877 (:postamble nil org-export-html-postamble
)
878 (:auto-preamble nil org-export-html-auto-preamble
)
879 (:auto-postamble nil org-export-html-auto-postamble
)
880 (:author nil user-full-name
)
881 (:email nil user-mail-address
)
882 (:select-tags nil org-export-select-tags
)
883 (:exclude-tags nil org-export-exclude-tags
))
884 "List of properties that represent export/publishing variables.
885 Each element is a list of 3 items:
886 1. The property that is used internally, and also for org-publish-project-alist
887 2. The string that can be used in the OPTION lines to set this option,
888 or nil if this option cannot be changed in this way
889 3. The customization variable that sets the default for this option."
893 (defun org-default-export-plist ()
894 "Return the property list with default settings for the export variables."
895 (let ((l org-export-plist-vars
) rtn e
)
896 (while (setq e
(pop l
))
897 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
900 (defvar org-export-inbuffer-options-extra nil
901 "List of additional in-buffer options that should be detected.
902 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
903 etc. Extensions can add to this list to get their options detected, and they
904 can then add a function to `org-export-options-filters' to process these
906 Each element in this list must be a list, with the in-buffer keyword as car,
907 and a property (a symbol) as the next element. All occurrences of the
908 keyword will be found, the values concatenated with a space character
909 in between, and the result stored in the export options property list.")
911 (defvar org-export-options-filters nil
912 "Functions to be called to finalize the export/publishing options.
913 All these options are stored in a property list, and each of the functions
914 in this hook gets a chance to modify this property list. Each function
915 must accept the property list as an argument, and must return the (possibly
918 ;; FIXME: should we fold case here?
919 (defun org-infile-export-plist ()
920 "Return the property list with file-local settings for export."
924 (goto-char (point-min))
925 (let ((re (org-make-options-regexp
927 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
928 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
929 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
930 (mapcar 'car org-export-inbuffer-options-extra
))))
931 p key val text options js-up js-main js-css js-opt a pr style
933 ext-setup-or-nil setup-contents
(start 0))
934 (while (or (and ext-setup-or-nil
935 (string-match re ext-setup-or-nil start
)
936 (setq start
(match-end 0)))
937 (and (setq ext-setup-or-nil nil start
0)
938 (re-search-forward re nil t
)))
939 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
940 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
942 ((setq a
(assoc key org-export-inbuffer-options-extra
))
944 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
945 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
946 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
947 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
948 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
949 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
950 ((string-equal key
"STYLE")
951 (setq style
(concat style
"\n" val
)))
952 ((string-equal key
"LATEX_HEADER")
953 (setq latex-header
(concat latex-header
"\n" val
)))
954 ((string-equal key
"TEXT")
955 (setq text
(if text
(concat text
"\n" val
) val
)))
956 ((string-equal key
"OPTIONS")
957 (setq options
(concat val
" " options
)))
958 ((string-equal key
"LINK_UP")
959 (setq p
(plist-put p
:link-up val
)))
960 ((string-equal key
"LINK_HOME")
961 (setq p
(plist-put p
:link-home val
)))
962 ((string-equal key
"EXPORT_SELECT_TAGS")
963 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
964 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
965 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
966 ((equal key
"SETUPFILE")
967 (setq setup-contents
(org-file-contents
969 (org-remove-double-quotes
972 (if (not ext-setup-or-nil
)
973 (setq ext-setup-or-nil setup-contents start
0)
974 (setq ext-setup-or-nil
975 (concat (substring ext-setup-or-nil
0 start
)
976 "\n" setup-contents
"\n"
977 (substring ext-setup-or-nil start
)))))))
978 (setq p
(plist-put p
:text text
))
979 (when style
(setq p
(plist-put p
:style-extra style
)))
981 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
983 (setq p
(org-export-add-options-to-plist p options
)))
986 (defun org-export-add-options-to-plist (p options
)
987 "Parse an OPTIONS line and set values in the property list P."
990 (let ((op org-export-plist-vars
) a
)
991 (while (setq o
(pop op
))
993 (string-match (concat (regexp-quote (nth 1 o
))
994 ":\\([^ \t\n\r;,.]*\\)")
996 (setq p
(plist-put p
(car o
)
997 (car (read-from-string
998 (match-string 1 options
))))))))))
1001 (defun org-export-add-subtree-options (p pos
)
1002 "Add options in subtree at position POS to property list P."
1005 (when (org-at-heading-p)
1007 ;; This is actually read in `org-export-get-title-from-subtree'
1008 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1009 ;; (setq p (plist-put p :title a)))
1010 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1011 (setq p
(plist-put p
:text a
)))
1012 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1013 (setq p
(org-export-add-options-to-plist p a
)))))
1016 (defun org-export-directory (type plist
)
1017 (let* ((val (plist-get plist
:publishing-directory
))
1018 (dir (if (listp val
)
1019 (or (cdr (assoc type val
)) ".")
1023 (defun org-export-process-option-filters (plist)
1024 (let ((functions org-export-options-filters
) f
)
1025 (while (setq f
(pop functions
))
1026 (setq plist
(funcall f plist
))))
1030 (defun org-export (&optional arg
)
1031 "Export dispatcher for Org-mode.
1032 When `org-export-run-in-background' is non-nil, try to run the command
1033 in the background. This will be done only for commands that write
1034 to a file. For details see the docstring of `org-export-run-in-background'.
1036 The prefix argument ARG will be passed to the exporter. However, if
1037 ARG is a double universal prefix `C-u C-u', that means to inverse the
1038 value of `org-export-run-in-background'."
1040 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1041 (help "[t] insert the export option template
1042 \[v] limit export to visible part of outline tree
1044 \[a] export as ASCII
1047 \[H] export as HTML to temporary buffer
1048 \[R] export region as HTML
1049 \[b] export as HTML and browse immediately
1052 \[l] export as LaTeX
1053 \[p] export as LaTeX and process to PDF
1054 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1055 \[L] export as LaTeX to temporary buffer
1057 \[i] export current file as iCalendar file
1058 \[I] export all agenda files as iCalendar files
1059 \[c] export agenda files into combined iCalendar file
1061 \[F] publish current file
1062 \[P] publish current project
1063 \[X] publish... (project will be prompted for)
1064 \[A] publish all projects")
1066 '((?t org-insert-export-options-template nil
)
1067 (?v org-export-visible nil
)
1068 (?a org-export-as-ascii t
)
1069 (?h org-export-as-html t
)
1070 (?b org-export-as-html-and-open t
)
1071 (?H org-export-as-html-to-buffer nil
)
1072 (?R org-export-region-as-html nil
)
1073 (?x org-export-as-xoxo t
)
1074 (?l org-export-as-latex t
)
1075 (?p org-export-as-pdf t
)
1076 (?d org-export-as-pdf-and-open t
)
1077 (?L org-export-as-latex-to-buffer nil
)
1078 (?i org-export-icalendar-this-file t
)
1079 (?I org-export-icalendar-all-agenda-files t
)
1080 (?c org-export-icalendar-combine-agenda-files t
)
1081 (?F org-publish-current-file t
)
1082 (?P org-publish-current-project t
)
1084 (?A org-publish-all t
)))
1086 (save-window-excursion
1087 (delete-other-windows)
1088 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1090 (org-fit-window-to-buffer (get-buffer-window
1091 "*Org Export/Publishing Help*"))
1092 (message "Select command: ")
1093 (setq r1
(read-char-exclusive)))
1094 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1095 (unless (setq ass
(assq r2 cmds
))
1096 (error "No command associated with key %c" r1
))
1097 (if (and bg
(nth 2 ass
)
1098 (not (buffer-base-buffer))
1099 (not (org-region-active-p)))
1100 ;; execute in background
1101 (let ((p (start-process
1102 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1104 (expand-file-name invocation-name invocation-directory
)
1107 "--eval" "(require 'org-exp)"
1108 "--eval" "(setq org-wait .2)"
1110 "-f" (symbol-name (nth 1 ass
)))))
1111 (set-process-sentinel p
'org-export-process-sentinel
)
1112 (message "Background process \"%s\": started" p
))
1113 ;; background processing not requested, or not possible
1114 (call-interactively (nth 1 ass
)))))
1116 (defun org-export-process-sentinel (process status
)
1117 (if (string-match "\n+\\'" status
)
1118 (setq status
(substring status
0 -
1)))
1119 (message "Background process \"%s\": %s" process status
))
1121 (defconst org-html-entities
1162 ("Aring") ("AA".
"Å")
1251 ("varepsilon".
"ε")
1264 ("sigmaf") ("varsigma".
"ς")
1272 ("thetasym") ("vartheta".
"ϑ")
1275 ("bull") ("bullet".
"•")
1276 ("hellip") ("dots".
"…")
1286 ("larr") ("leftarrow".
"←") ("gets".
"←")
1287 ("uarr") ("uparrow".
"↑")
1288 ("rarr") ("to".
"→") ("rightarrow".
"→")
1289 ("darr")("downarrow".
"↓")
1290 ("harr") ("leftrightarrow".
"↔")
1291 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1292 ("lArr") ("Leftarrow".
"⇐")
1293 ("uArr") ("Uparrow".
"⇑")
1294 ("rArr") ("Rightarrow".
"⇒")
1295 ("dArr") ("Downarrow".
"⇓")
1296 ("hArr") ("Leftrightarrow".
"⇔")
1298 ("part") ("partial".
"∂")
1299 ("exist") ("exists".
"∃")
1300 ("empty") ("emptyset".
"∅")
1302 ("isin") ("in".
"∈")
1308 ("lowast") ("ast".
"∗")
1310 ("prop") ("proptp".
"∝")
1311 ("infin") ("infty".
"∞")
1312 ("ang") ("angle".
"∠")
1313 ("and") ("wedge".
"∧")
1314 ("or") ("vee".
"∨")
1320 ("cong") ("simeq".
"≅")
1321 ("asymp")("approx".
"≈")
1322 ("ne") ("neq".
"≠")
1326 ("sub") ("subset".
"⊂")
1327 ("sup") ("supset".
"⊃")
1334 ("sdot") ("cdot".
"⋅")
1341 ("loz") ("Diamond".
"◊")
1342 ("spades") ("spadesuit".
"♠")
1343 ("clubs") ("clubsuit".
"♣")
1344 ("hearts") ("diamondsuit".
"♥")
1345 ("diams") ("diamondsuit".
"♦")
1346 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1413 "Entities for TeX->HTML translation.
1414 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1415 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1416 In that case, \"\\ent\" will be translated to \"&other;\".
1417 The list contains HTML entities for Latin-1, Greek and other symbols.
1418 It is supplemented by a number of commonly used TeX macros with appropriate
1419 translations. There is currently no way for users to extend this.")
1421 ;;; General functions for all backends
1423 (defvar org-export-target-aliases nil
1424 "Alist of targets with invisible aliases.")
1426 (defun org-export-preprocess-string (string &rest parameters
)
1427 "Cleanup STRING so that that the true exported has a more consistent source.
1428 This function takes STRING, which should be a buffer-string of an org-file
1429 to export. It then creates a temporary buffer where it does its job.
1430 The result is then again returned as a string, and the exporter works
1431 on this string to produce the exported version."
1433 (let* ((htmlp (plist-get parameters
:for-html
))
1434 (asciip (plist-get parameters
:for-ascii
))
1435 (latexp (plist-get parameters
:for-LaTeX
))
1436 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1438 (archived-trees (plist-get parameters
:archived-trees
))
1439 (inhibit-read-only t
)
1440 (drawers org-drawers
)
1441 (outline-regexp "\\*+ ")
1444 (setq org-export-target-aliases nil
)
1446 (with-current-buffer (get-buffer-create " org-mode-tmp")
1449 (setq case-fold-search t
)
1451 (run-hooks 'org-export-preprocess-hook
)
1453 ;; Remove license-to-kill stuff
1454 ;; The caller marks some stuff for killing, stuff that has been
1455 ;; used to create the page title, for example.
1456 (org-export-kill-licensed-text)
1458 (let ((org-inhibit-startup t
)) (org-mode))
1459 (setq case-fold-search t
)
1460 (untabify (point-min) (point-max))
1462 ;; Handle include files
1463 (org-export-handle-include-files)
1465 ;; Get rid of excluded trees
1466 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1467 (plist-get parameters
:exclude-tags
))
1469 ;; Handle source code snippets
1470 (org-export-replace-src-segments)
1472 ;; Find all headings and compute the targets for them
1473 (setq target-alist
(org-export-define-heading-targets target-alist
))
1475 ;; Get rid of drawers
1476 (org-export-remove-or-extract-drawers drawers
1477 (plist-get parameters
:drawers
))
1479 ;; Get the correct stuff before the first headline
1480 (when (plist-get parameters
:skip-before-1st-heading
)
1481 (goto-char (point-min))
1482 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t
)
1483 (delete-region (point-min) (match-beginning 0))
1484 (goto-char (point-min))
1486 (when (plist-get parameters
:add-text
)
1487 (goto-char (point-min))
1488 (insert (plist-get parameters
:add-text
) "\n"))
1490 ;; Get rid of archived trees
1491 (org-export-remove-archived-trees archived-trees
)
1493 ;; Remove todo-keywords before exporting, if the user has requested so
1494 (org-export-remove-headline-metadata parameters
)
1496 ;; Find targets in comments and move them out of comments,
1497 ;; but mark them as targets that should be invisible
1498 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1501 (org-export-protect-examples (if asciip
'indent nil
))
1503 ;; Protect backend specific stuff, throw away the others.
1504 (org-export-select-backend-specific-text backend
)
1506 ;; Protect quoted subtrees
1507 (org-export-protect-quoted-subtrees)
1509 ;; Protect verbatim elements
1510 (org-export-protect-verbatim)
1512 ;; Blockquotes and verse
1513 (org-export-mark-blockquote-and-verse)
1515 ;; Attach captions to the correct object
1516 (setq target-alist
(org-export-attach-captions-and-attributes
1517 backend target-alist
))
1519 ;; Remove comment environment and comment subtrees
1520 (org-export-remove-comment-blocks-and-subtrees)
1522 ;; Find matches for radio targets and turn them into internal links
1523 (org-export-mark-radio-links)
1525 ;; Find all links that contain a newline and put them into a single line
1526 (org-export-concatenate-multiline-links)
1528 ;; Normalize links: Convert angle and plain links into bracket links
1529 ;; and expand link abbreviations
1530 (org-export-normalize-links)
1532 ;; Find all internal links. If they have a fuzzy match (i.e. not
1533 ;; a *dedicated* target match, let the link point to the
1534 ;; corresponding section.
1535 (org-export-target-internal-links target-alist
)
1537 ;; Find multiline emphasis and put them into single line
1538 (when (plist-get parameters
:emph-multiline
)
1539 (org-export-concatenate-multiline-emphasis))
1541 ;; Remove special table lines
1542 (when org-export-table-remove-special-lines
1543 (org-export-remove-special-table-lines))
1545 ;; Specific LaTeX stuff
1547 (require 'org-export-latex nil
)
1548 (org-export-latex-preprocess))
1550 ;; Specific ASCII stuff
1552 (org-export-ascii-preprocess))
1554 ;; Specific HTML stuff
1556 (org-export-html-preprocess parameters
))
1558 ;; Remove or replace comments
1559 (org-export-handle-comments (plist-get parameters
:comments
))
1561 (setq rtn
(buffer-string)))
1562 (kill-buffer " org-mode-tmp")
1565 (defun org-export-kill-licensed-text ()
1566 "Remove all text that is marked with a :org-license-to-kill property."
1568 (while (setq p
(text-property-any (point-min) (point-max)
1569 :org-license-to-kill t
))
1571 p
(or (next-single-property-change p
:org-license-to-kill
)
1574 (defun org-export-define-heading-targets (target-alist)
1575 "Find all headings and define the targets for them.
1576 The new targets are added to TARGET-ALIST, which is also returned."
1577 (goto-char (point-min))
1578 (org-init-section-numbers)
1579 (let ((re (concat "^" org-outline-regexp
1580 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1582 (while (re-search-forward re nil t
)
1584 (push (cons (org-match-string-no-properties 1)
1585 target
) target-alist
)
1586 (setq level
(org-reduced-level
1587 (save-excursion (goto-char (point-at-bol))
1588 (org-outline-level))))
1589 (setq target
(org-solidify-link-text
1590 (format "sec-%s" (org-section-number level
))))
1591 (push (cons target target
) target-alist
)
1592 (add-text-properties
1593 (point-at-bol) (point-at-eol)
1594 (list 'target target
)))))
1597 (defun org-export-handle-invisible-targets (target-alist)
1598 "Find targets in comments and move them out of comments.
1599 Mark them as invisible targets."
1601 (goto-char (point-min))
1602 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1603 ;; Check if the line before or after is a headline with a target
1604 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1605 (get-text-property (point-at-bol 2) 'target
)))
1607 ;; use the existing target in a neighboring line
1608 (setq tmp
(match-string 2))
1610 (and (looking-at "\n") (delete-char 1))
1611 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1613 (setq a
(or (assoc target org-export-target-aliases
)
1615 (push (list target
) org-export-target-aliases
)
1616 (car org-export-target-aliases
))))
1618 ;; Make an invisible target
1619 (replace-match "\\1(INVISIBLE)"))))
1622 (defun org-export-target-internal-links (target-alist)
1623 "Find all internal links and assign targets to them.
1624 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1625 let the link point to the corresponding section.
1626 This function also handles the id links, if they have a match in
1628 (goto-char (point-min))
1629 (while (re-search-forward org-bracket-link-regexp nil t
)
1631 (let* ((md (match-data))
1632 (desc (match-end 2))
1633 (link (org-link-unescape (match-string 1)))
1634 (slink (org-solidify-link-text link
))
1638 ((cdr (assoc slink target-alist
)))
1639 ((and (string-match "^id:" link
)
1640 (cdr (assoc (substring link
3) target-alist
))))
1641 ((string-match org-link-types-re link
) nil
)
1642 ((or (file-name-absolute-p link
)
1643 (string-match "^\\." link
))
1647 (setq found
(condition-case nil
(org-link-search link
)
1650 (or (org-on-heading-p)
1651 (not (eq found
'dedicated
))))
1652 (or (get-text-property (point) 'target
)
1655 (1- (or (previous-single-property-change
1656 (point) 'target
) 0)))
1660 (goto-char (match-beginning 1))
1661 (setq props
(text-properties-at (point)))
1662 (delete-region (match-beginning 1) (match-end 1))
1665 (unless desc
(insert "][" link
))
1666 (add-text-properties pos
(point) props
))))))
1668 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1669 "Remove drawers, or extract the content.
1670 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1671 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1672 whose content to keep."
1673 (unless (eq t exp-drawers
)
1674 (goto-char (point-min))
1675 (let ((re (concat "^[ \t]*:\\("
1678 (org-delete-all exp-drawers
1679 (copy-sequence all-drawers
))
1681 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1682 (while (re-search-forward re nil t
)
1683 (replace-match "")))))
1685 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1686 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1687 Both arguments are lists of tags.
1688 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1690 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1692 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1693 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1696 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1700 (goto-char (point-min))
1701 (when (and select-tags
1703 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1704 ;; At least one tree is marked for export, this means
1705 ;; all the unmarked stuff needs to go.
1706 ;; Dig out the trees that should be exported
1707 (goto-char (point-min))
1708 (outline-next-heading)
1710 (put-text-property beg
(point-max) :org-delete t
)
1711 (while (re-search-forward re-sel nil t
)
1712 (when (org-on-heading-p)
1713 (org-back-to-heading)
1714 (remove-text-properties
1715 (max (1- (point)) (point-min))
1716 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1718 (while (and (org-up-heading-safe)
1719 (get-text-property (point) :org-delete
))
1720 (remove-text-properties (max (1- (point)) (point-min))
1721 (point-at-eol) '(:org-delete t
)))
1723 ;; Remove the trees explicitly marked for noexport
1725 (goto-char (point-min))
1726 (while (re-search-forward re-excl nil t
)
1727 (when (org-at-heading-p)
1728 (org-back-to-heading t
)
1730 (org-end-of-subtree t
)
1731 (delete-region beg
(point)))))
1732 ;; Remove everything that is now still marked for deletion
1733 (goto-char (point-min))
1734 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1735 (setq end
(or (next-single-property-change beg
:org-delete
)
1737 (delete-region beg end
))))
1739 (defun org-export-remove-archived-trees (export-archived-trees)
1740 "Remove archived trees.
1741 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1742 When it is t, the entire archived tree will be exported.
1743 When it is nil the entire tree including the headline will be removed
1745 (let ((re-archive (concat ":" org-archive-tag
":"))
1747 (when (not (eq export-archived-trees t
))
1748 (goto-char (point-min))
1749 (while (re-search-forward re-archive nil t
)
1750 (if (not (org-on-heading-p t
))
1751 (org-end-of-subtree t
)
1752 (beginning-of-line 1)
1753 (setq a
(if export-archived-trees
1754 (1+ (point-at-eol)) (point))
1755 b
(org-end-of-subtree t
))
1756 (if (> b a
) (delete-region a b
)))))))
1758 (defun org-export-remove-headline-metadata (opts)
1759 "Remove meta data from the headline, according to user options."
1760 (let ((re org-complex-heading-regexp
)
1761 (todo (plist-get opts
:todo-keywords
))
1762 (tags (plist-get opts
:tags
))
1763 (pri (plist-get opts
:priority
))
1766 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1767 (when (or (not todo
) (not tags
) (not pri
))
1768 (goto-char (point-min))
1769 (while (re-search-forward re nil t
)
1770 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1772 (replace-match rpl t t
)))))
1774 (defun org-export-protect-quoted-subtrees ()
1775 "Mark quoted subtrees with the protection property."
1776 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1777 (goto-char (point-min))
1778 (while (re-search-forward re-quote nil t
)
1779 (goto-char (match-beginning 0))
1781 (add-text-properties (point) (org-end-of-subtree t
)
1782 '(org-protected t
)))))
1784 (defun org-export-protect-verbatim ()
1785 "Mark verbatim snippets with the protection property."
1786 (goto-char (point-min))
1787 (while (re-search-forward org-verbatim-re nil t
)
1788 (add-text-properties (match-beginning 4) (match-end 4)
1790 (goto-char (1+ (match-end 4)))))
1792 (defun org-export-protect-examples (&optional indent
)
1793 "Protect code that should be exported as monospaced examples."
1794 (goto-char (point-min))
1795 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1796 (goto-char (match-end 0))
1797 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1798 (insert (if indent
": " ":"))
1799 (beginning-of-line 2)))
1800 (goto-char (point-min))
1801 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1802 (add-text-properties (match-beginning 0) (match-end 0)
1803 '(org-protected t
))))
1805 (defun org-export-select-backend-specific-text (backend)
1807 '((html "HTML" "BEGIN_HTML" "END_HTML")
1808 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1809 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1813 (setq fmt
(pop formatters
))
1814 (when (eq (car fmt
) backend
)
1815 ;; This is selected code, put it into the file for real
1816 (goto-char (point-min))
1817 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1818 ":[ \t]*\\(.*\\)") nil t
)
1819 (replace-match "\\1" t
)
1820 (add-text-properties
1821 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1822 '(org-protected t
))))
1823 (goto-char (point-min))
1824 (while (re-search-forward
1826 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1827 (cadddr fmt
) "\\>.*\n?") nil t
)
1828 (if (eq (car fmt
) backend
)
1830 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1832 ;; No, this is for a different backend, kill it
1833 (delete-region (match-beginning 0) (match-end 0)))))))
1835 (defun org-export-mark-blockquote-and-verse ()
1836 "Mark block quote and verse environments with special cookies.
1837 These special cookies will later be interpreted by the backend."
1839 (goto-char (point-min))
1840 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1842 (replace-match (if (equal (downcase (match-string 1)) "end")
1843 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1846 (goto-char (point-min))
1847 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1848 (replace-match (if (equal (downcase (match-string 1)) "end")
1849 "ORG-VERSE-END" "ORG-VERSE-START")
1852 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1853 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1854 If the next thing following is a table, add the text properties to the first
1855 table line. If it is a link, add it to the line containing the link."
1856 (goto-char (point-min))
1857 (remove-text-properties (point-min) (point-max)
1858 '(org-caption nil org-attributes nil
))
1859 (let ((case-fold-search t
)
1860 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1862 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1864 "^#\\+label:[ \t]+\\(.*\\)"
1868 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1870 (while (re-search-forward re nil t
)
1873 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1875 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1877 (setq label
(org-trim (match-string 3))))
1879 (add-text-properties (point-at-bol) (point-at-eol)
1880 (list 'org-caption cap
1881 'org-attributes attr
1883 (if label
(push (cons label label
) target-alist
))
1884 (setq cap nil attr nil label nil
)))))
1887 (defun org-export-remove-comment-blocks-and-subtrees ()
1888 "Remove the comment environment, and also commented subtrees."
1889 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1890 (case-fold-search nil
))
1891 ;; Remove comment environment
1892 (goto-char (point-min))
1893 (while (re-search-forward
1894 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1895 (replace-match "" t t
))
1896 ;; Remove subtrees that are commented
1897 (goto-char (point-min))
1898 (while (re-search-forward re-commented nil t
)
1899 (goto-char (match-beginning 0))
1900 (delete-region (point) (org-end-of-subtree t
)))))
1902 (defun org-export-handle-comments (commentsp)
1903 "Remove comments, or convert to backend-specific format.
1904 COMMENTSP can be a format string for publishing comments.
1905 When it is nil, all comments will be removed."
1906 (let ((re "^#\\(.*\n?\\)")
1908 (goto-char (point-min))
1909 (while (or (looking-at re
)
1910 (re-search-forward re nil t
))
1911 (setq pos
(match-beginning 0))
1913 (progn (add-text-properties
1914 (match-beginning 0) (match-end 0) '(org-protected t
))
1915 (replace-match (format commentsp
(match-string 1)) t t
))
1916 (goto-char (1+ pos
))
1919 (goto-char (max (point-min) (1- pos
))))))))
1921 (defun org-export-mark-radio-links ()
1922 "Find all matches for radio targets and turn them into internal links."
1923 (let ((re-radio (and org-target-link-regexp
1924 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1925 (goto-char (point-min))
1927 (while (re-search-forward re-radio nil t
)
1929 (replace-match "\\1[[\\2]]"))))))
1931 (defun org-export-remove-special-table-lines ()
1932 "Remove tables lines that are used for internal purposes."
1933 (goto-char (point-min))
1934 (while (re-search-forward "^[ \t]*|" nil t
)
1935 (beginning-of-line 1)
1936 (if (or (looking-at "[ \t]*| *[!_^] *|")
1937 (and (looking-at ".*?| *<[0-9]+> *|")
1938 (not (looking-at ".*?| *[^ <|]"))))
1939 (delete-region (max (point-min) (1- (point-at-bol)))
1943 (defun org-export-normalize-links ()
1944 "Convert all links to bracket links, and expand link abbreviations."
1945 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1946 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1947 (goto-char (point-min))
1948 (while (re-search-forward re-plain-link nil t
)
1949 (goto-char (1- (match-end 0)))
1951 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1952 ":" (match-string 3) "]]")))
1953 ;; added 'org-link face to links
1954 (put-text-property 0 (length s
) 'face
'org-link s
)
1955 (replace-match s t t
))))
1956 (goto-char (point-min))
1957 (while (re-search-forward re-angle-link nil t
)
1958 (goto-char (1- (match-end 0)))
1960 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1961 ":" (match-string 3) "]]")))
1962 (put-text-property 0 (length s
) 'face
'org-link s
)
1963 (replace-match s t t
))))
1964 (goto-char (point-min))
1965 (while (re-search-forward org-bracket-link-regexp nil t
)
1966 (goto-char (1- (match-end 0)))
1968 (let* ((xx (save-match-data
1970 (org-link-expand-abbrev (match-string 1)))))
1975 (concat "[" xx
"]"))
1977 (put-text-property 0 (length s
) 'face
'org-link s
)
1978 (replace-match s t t
))))))
1980 (defun org-export-concatenate-multiline-links ()
1981 "Find multi-line links and put it all into a single line.
1982 This is to make sure that the line-processing export backends
1983 can work correctly."
1984 (goto-char (point-min))
1985 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1987 (replace-match "\\1 \\3")
1988 (goto-char (match-beginning 0)))))
1990 (defun org-export-concatenate-multiline-emphasis ()
1991 "Find multi-line emphasis and put it all into a single line.
1992 This is to make sure that the line-processing export backends
1993 can work correctly."
1994 (goto-char (point-min))
1995 (while (re-search-forward org-emph-re nil t
)
1996 (if (not (= (char-after (match-beginning 3))
1997 (char-after (match-beginning 4))))
1999 (subst-char-in-region (match-beginning 0) (match-end 0)
2001 (goto-char (1- (match-end 0))))
2002 (goto-char (1+ (match-beginning 0))))))
2004 (defun org-export-grab-title-from-buffer ()
2005 "Get a title for the current document, from looking at the buffer."
2006 (let ((inhibit-read-only t
))
2008 (goto-char (point-min))
2009 (let ((end (if (looking-at org-outline-regexp
)
2011 (save-excursion (outline-next-heading) (point)))))
2012 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2013 ;; Mark the line so that it will not be exported as normal text.
2015 (add-text-properties (match-beginning 0) (match-end 0)
2016 (list :org-license-to-kill t
)))
2017 ;; Return the title string
2018 (org-trim (match-string 0)))))))
2020 (defun org-export-get-title-from-subtree ()
2021 "Return subtree title and exclude it from export."
2022 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2025 (when (and (org-at-heading-p)
2026 (>= (org-end-of-subtree t t
) rend
))
2027 ;; This is a subtree, we take the title from the first heading
2029 (looking-at org-todo-line-regexp
)
2030 (setq title
(match-string 3))
2032 (add-text-properties (point) (1+ (point-at-eol))
2033 (list :org-license-to-kill t
)))
2034 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2037 (defun org-solidify-link-text (s &optional alist
)
2038 "Take link text and make a safe target out of it."
2043 (org-split-string s
"[ \t\r\n]+") "=="))
2044 (a (assoc rtn alist
)))
2047 (defun org-get-min-level (lines)
2048 "Get the minimum level in LINES."
2049 (let ((re "^\\(\\*+\\) ") l min
)
2051 (while (setq l
(pop lines
))
2052 (if (string-match re l
)
2053 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
2056 ;; Variable holding the vector with section numbers
2057 (defvar org-section-numbers
(make-vector org-level-max
0))
2059 (defun org-init-section-numbers ()
2060 "Initialize the vector for the section numbers."
2062 (numbers (nreverse (org-split-string "" "\\.")))
2063 (depth (1- (length org-section-numbers
)))
2064 (i depth
) number-string
)
2067 (aset org-section-numbers i
0)
2068 (setq number-string
(or (car numbers
) "0"))
2069 (if (string-match "\\`[A-Z]\\'" number-string
)
2070 (aset org-section-numbers i
2071 (- (string-to-char number-string
) ?A -
1))
2072 (aset org-section-numbers i
(string-to-number number-string
)))
2076 (defun org-section-number (&optional level
)
2077 "Return a string with the current section number.
2078 When LEVEL is non-nil, increase section numbers on that level."
2079 (let* ((depth (1- (length org-section-numbers
)))
2081 (fmts (car org-export-section-number-format
))
2082 (term (cdr org-export-section-number-format
))
2087 (aset org-section-numbers
2088 level
(1+ (aref org-section-numbers level
))))
2089 (setq idx
(1+ level
))
2090 (while (<= idx depth
)
2092 (aset org-section-numbers idx
0))
2093 (setq idx
(1+ idx
))))
2095 (while (<= idx depth
)
2096 (when (> (aref org-section-numbers idx
) 0)
2097 (setq fmt
(or (pop fmts
) fmt
)
2099 n
(aref org-section-numbers idx
)
2101 (concat string sep
(org-number-to-counter n ctype
))
2102 (concat string
".0"))
2104 (setq idx
(1+ idx
)))
2106 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2107 (setq string
(replace-match "" t nil string
)))
2108 (if (string-match "\\(\\.0\\)+\\'" string
)
2109 (setq string
(replace-match "" t nil string
))))
2110 (concat string term
)))
2112 (defun org-number-to-counter (n type
)
2113 "Concert number N to a string counter, according to TYPE.
2114 TYPE must be a string, any of:
2118 I upper case roman numeral
2119 i lower case roman numeral"
2121 ((equal type
"1") (number-to-string n
))
2122 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2123 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2124 ((equal type
"I") (org-number-to-roman n
))
2125 ((equal type
"i") (downcase (org-number-to-roman n
)))
2126 (t (error "Invalid counter type `%s'" type
))))
2128 (defun org-number-to-roman (n)
2129 "Convert integer N into a roman numeral."
2130 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2131 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2132 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2136 (number-to-string n
)
2138 (if (>= n
(caar roman
))
2139 (setq n
(- n
(caar roman
))
2140 res
(concat res
(cdar roman
)))
2144 (org-number-to-roman 1961)
2149 (defun org-export-handle-include-files ()
2150 "Include the contents of include files, with proper formatting."
2151 (let ((case-fold-search t
)
2152 params file markup lang start end prefix prefix1
)
2153 (goto-char (point-min))
2154 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2155 (setq params
(read (concat "(" (match-string 1) ")"))
2156 prefix
(org-get-and-remove-property 'params
:prefix
)
2157 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2158 file
(org-symname-or-string (pop params
))
2159 markup
(org-symname-or-string (pop params
))
2160 lang
(org-symname-or-string (pop params
)))
2161 (delete-region (match-beginning 0) (match-end 0))
2163 (not (file-exists-p file
))
2164 (not (file-readable-p file
)))
2165 (insert (format "CANNOT INCLUDE FILE %s" file
))
2167 (if (equal (downcase markup
) "src")
2168 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2170 (setq start
(format "#+begin_%s\n" markup
)
2171 end
(format "#+end_%s" markup
))))
2172 (insert (or start
""))
2173 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2174 (or (bolp) (newline))
2175 (insert (or end
""))))))
2177 (defun org-get-file-contents (file &optional prefix prefix1
)
2178 "Get the contents of FILE and return them as a string.
2179 If PREFIX is a string, prepend it to each line. If PREFIX1
2180 is a string, prepend it to the first line instead of PREFIX."
2182 (insert-file-contents file
)
2183 (when (or prefix prefix1
)
2184 (goto-char (point-min))
2186 (insert (or prefix1 prefix
))
2188 (beginning-of-line 2)))
2191 (defun org-get-and-remove-property (listvar prop
)
2192 "Check if the value of LISTVAR contains PROP as a property.
2193 If yes, return the value of that property (i.e. the element following
2194 in the list) and remove property and value from the list in LISTVAR."
2195 (let ((list (symbol-value listvar
)) m v
)
2196 (when (setq m
(member prop list
))
2198 (if (equal (car list
) prop
)
2199 (set listvar
(cddr list
))
2200 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2202 (set listvar list
)))
2205 (defun org-symname-or-string (s)
2207 (if s
(symbol-name s
) s
)
2210 ;;; Fontification of code
2211 ;; Currently only for the HTML backend, but who knows....
2212 (defun org-export-replace-src-segments ()
2213 "Replace source code segments with special code for export."
2214 (let ((case-fold-search t
)
2216 (goto-char (point-min))
2217 (while (re-search-forward
2218 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2220 (setq lang
(match-string 1) code
(match-string 2)
2221 trans
(org-export-format-source-code lang code
))
2222 (replace-match trans t t
))))
2224 (defvar htmlp
) ;; dynamically scoped from org-exp.el
2226 (defun org-export-format-source-code (lang code
)
2227 "Format CODE from language LANG and return it formatted for export.
2228 Currently, this only does something for HTML export, for all other
2229 backends, it converts the segment into an EXAMPLE segment."
2233 ;; We are exporting to HTML
2234 (require 'htmlize nil t
)
2235 (if (not (fboundp 'htmlize-region-for-paste
))
2237 ;; we do not have htmlize.el, or an old version of it
2239 "htmlize.el 1.34 or later is needed for source code formatting")
2240 (concat "#+BEGIN_EXAMPLE\n" code
2241 (if (string-match "\n\\'" code
) "" "\n")
2243 ;; ok, we are good to go
2244 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2245 (org-inhibit-startup t
)
2246 (org-startup-folded nil
)
2250 ;; Free up the protected stuff
2251 (goto-char (point-min))
2252 (while (re-search-forward "^," nil t
)
2255 (if (functionp mode
)
2258 (font-lock-fontify-buffer)
2259 (org-export-htmlize-region-for-paste
2260 (point-min) (point-max)))))
2261 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2262 (setq htmltext
(replace-match
2263 (format "<pre class=\"src src-%s\">" lang
)
2265 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2267 ;; This is not HTML, so just make it an example.
2268 (when (equal lang
"org")
2269 (while (string-match "^," code
)
2270 (setq code
(replace-match "" t t code
))))
2271 (concat "#+BEGIN_EXAMPLE\n" code
2272 (if (string-match "\n\\'" code
) "" "\n")
2273 "#+END_EXAMPLE\n")))))
2277 (defvar org-last-level nil
) ; dynamically scoped variable
2278 (defvar org-min-level nil
) ; dynamically scoped variable
2279 (defvar org-levels-open nil
) ; dynamically scoped parameter
2280 (defvar org-ascii-current-indentation nil
) ; For communication
2283 (defun org-export-as-ascii (arg)
2284 "Export the outline as a pretty ASCII file.
2285 If there is an active region, export only the region.
2286 The prefix ARG specifies how many levels of the outline should become
2287 underlined headlines. The default is 3."
2289 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2290 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2291 (org-infile-export-plist)))
2292 (region-p (org-region-active-p))
2293 (rbeg (and region-p
(region-beginning)))
2294 (rend (and region-p
(region-end)))
2299 (and (org-at-heading-p)
2300 (>= (org-end-of-subtree t t
) rend
)))))
2301 (opt-plist (if subtree-p
2302 (org-export-add-subtree-options opt-plist rbeg
)
2304 (custom-times org-display-custom-times
)
2305 (org-ascii-current-indentation '(0 .
0))
2309 (case-fold-search nil
)
2310 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2311 (filename (concat (file-name-as-directory
2312 (org-export-directory :ascii opt-plist
))
2313 (file-name-sans-extension
2315 (org-entry-get (region-beginning)
2316 "EXPORT_FILE_NAME" t
))
2317 (file-name-nondirectory bfname
)))
2319 (filename (if (equal (file-truename filename
)
2320 (file-truename bfname
))
2321 (concat filename
".txt")
2323 (buffer (find-file-noselect filename
))
2324 (org-levels-open (make-vector org-level-max nil
))
2325 (odd org-odd-levels-only
)
2326 (date (plist-get opt-plist
:date
))
2327 (author (plist-get opt-plist
:author
))
2328 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2329 (plist-get opt-plist
:title
)
2331 (plist-get opt-plist
:skip-before-1st-heading
))
2332 (org-export-grab-title-from-buffer))
2333 (file-name-sans-extension
2334 (file-name-nondirectory bfname
))))
2335 (email (plist-get opt-plist
:email
))
2336 (language (plist-get opt-plist
:language
))
2337 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2338 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2343 (if (org-region-active-p) (region-beginning) (point-min))
2344 (if (org-region-active-p) (region-end) (point-max))))
2345 (lines (org-split-string
2346 (org-export-preprocess-string
2349 :skip-before-1st-heading
2350 (plist-get opt-plist
:skip-before-1st-heading
)
2351 :drawers
(plist-get opt-plist
:drawers
)
2352 :tags
(plist-get opt-plist
:tags
)
2353 :priority
(plist-get opt-plist
:priority
)
2354 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2355 :verbatim-multiline t
2356 :select-tags
(plist-get opt-plist
:select-tags
)
2357 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2359 (plist-get opt-plist
:archived-trees
)
2360 :add-text
(plist-get opt-plist
:text
))
2362 thetoc have-headings first-heading-pos
2363 table-open table-buffer
)
2365 (let ((inhibit-read-only t
))
2367 (remove-text-properties (point-min) (point-max)
2368 '(:org-license-to-kill t
))))
2370 (setq org-min-level
(org-get-min-level lines
))
2371 (setq org-last-level org-min-level
)
2372 (org-init-section-numbers)
2374 (find-file-noselect filename
)
2376 (setq lang-words
(or (assoc language org-export-language-setup
)
2377 (assoc "en" org-export-language-setup
)))
2378 (switch-to-buffer-other-window buffer
)
2381 ;; create local variables for all options, to make sure all called
2382 ;; functions get the correct information
2384 (set (make-local-variable (nth 2 x
))
2385 (plist-get opt-plist
(car x
))))
2386 org-export-plist-vars
)
2387 (org-set-local 'org-odd-levels-only odd
)
2388 (setq umax
(if arg
(prefix-numeric-value arg
)
2389 org-export-headline-levels
))
2390 (setq umax-toc
(if (integerp org-export-with-toc
)
2391 (min org-export-with-toc umax
)
2395 (if title
(org-insert-centered title ?
=))
2397 (if (and (or author email
)
2398 org-export-author-info
)
2399 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2400 (if email
(concat " <" email
">") "")
2404 ((and date
(string-match "%" date
))
2405 (setq date
(format-time-string date
)))
2407 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2409 (if (and date org-export-time-stamp-file
)
2410 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2414 (if org-export-with-toc
2416 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2417 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2419 (mapc '(lambda (line)
2420 (if (string-match org-todo-line-regexp
2422 ;; This is a headline
2424 (setq have-headings t
)
2425 (setq level
(- (match-end 1) (match-beginning 1))
2426 level
(org-tr-level level
)
2427 txt
(match-string 3 line
)
2429 (or (and org-export-mark-todo-in-toc
2431 (not (member (match-string 2 line
)
2432 org-done-keywords
)))
2434 (and org-export-mark-todo-in-toc
2436 (org-search-todo-below
2437 line lines level
))))
2438 (setq txt
(org-html-expand-for-ascii txt
))
2440 (while (string-match org-bracket-link-regexp txt
)
2443 (match-string (if (match-end 2) 3 1) txt
)
2446 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2448 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2450 (setq txt
(replace-match "" t t txt
)))
2451 (if (string-match quote-re0 txt
)
2452 (setq txt
(replace-match "" t t txt
)))
2454 (if org-export-with-section-numbers
2455 (setq txt
(concat (org-section-number level
)
2457 (if (<= level umax-toc
)
2462 (* (max 0 (- level org-min-level
)) 4) ?\
)
2463 (format (if todo
"%s (*)\n" "%s\n") txt
))
2465 (setq org-last-level level
))
2468 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2470 (org-init-section-numbers)
2471 (while (setq line
(pop lines
))
2472 ;; Remove the quoted HTML tags.
2473 (setq line
(org-html-expand-for-ascii line
))
2474 ;; Replace links with the description when possible
2475 (while (string-match org-bracket-link-regexp line
)
2476 (setq line
(replace-match
2477 (if (match-end 3) "[\\3]" "[\\1]")
2480 (setq line
(org-translate-time line
)))
2482 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2484 (setq first-heading-pos
(or first-heading-pos
(point)))
2485 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2486 txt
(match-string 2 line
))
2487 (org-ascii-level-start level txt umax lines
))
2489 ((and org-export-with-tables
2490 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2491 (if (not table-open
)
2493 (setq table-open t table-buffer nil
))
2495 (setq table-buffer
(cons line table-buffer
))
2496 (when (or (not lines
)
2497 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2499 (setq table-open nil
2500 table-buffer
(nreverse table-buffer
))
2503 (org-fix-indentation x org-ascii-current-indentation
))
2504 (org-format-table-ascii table-buffer
)
2507 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2508 ;; Remove forced line breaks
2509 (if (string-match "\\\\\\\\[ \t]*$" line
)
2510 (setq line
(replace-match "" t t line
)))
2511 (if (and org-export-with-fixed-width
2512 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2513 (setq line
(replace-match "\\1" nil nil line
)))
2514 (insert line
"\n"))))
2518 ;; insert the table of contents
2520 (goto-char (point-min))
2521 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2523 (goto-char (match-beginning 0))
2525 (goto-char first-heading-pos
))
2526 (mapc 'insert thetoc
)
2527 (or (looking-at "[ \t]*\n[ \t]*\n")
2530 ;; Convert whitespace place holders
2531 (goto-char (point-min))
2533 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2534 (setq end
(next-single-property-change beg
'org-whitespace
))
2536 (delete-region beg end
)
2537 (insert (make-string (- end beg
) ?\
))))
2540 ;; remove display and invisible chars
2542 (goto-char (point-min))
2543 (while (setq beg
(next-single-property-change (point) 'display
))
2544 (setq end
(next-single-property-change beg
'display
))
2545 (delete-region beg end
)
2548 (goto-char (point-min))
2549 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2550 (setq end
(next-single-property-change beg
'org-cwidth
))
2551 (delete-region beg end
)
2553 (goto-char (point-min))))
2555 (defun org-export-ascii-preprocess ()
2556 "Do extra work for ASCII export"
2557 ;; Put quotes around verbatim text
2558 (goto-char (point-min))
2559 (while (re-search-forward org-verbatim-re nil t
)
2560 (goto-char (match-end 2))
2561 (backward-delete-char 1) (insert "'")
2562 (goto-char (match-beginning 2))
2563 (delete-char 1) (insert "`")
2564 (goto-char (match-end 2)))
2565 (goto-char (point-min))
2566 ;; Remove target markers
2567 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2568 (replace-match "\\1\\2")))
2570 (defun org-search-todo-below (line lines level
)
2571 "Search the subtree below LINE for any TODO entries."
2572 (let ((rest (cdr (memq line lines
)))
2573 (re org-todo-line-regexp
)
2576 (while (setq line
(pop rest
))
2577 (if (string-match re line
)
2579 (setq lv
(- (match-end 1) (match-beginning 1))
2580 todo
(and (match-beginning 2)
2581 (not (member (match-string 2 line
)
2582 org-done-keywords
))))
2584 (if (<= lv level
) (throw 'exit nil
))
2585 (if todo
(throw 'exit t
))))))))
2587 (defun org-html-expand-for-ascii (line)
2588 "Handle quoted HTML for ASCII export."
2589 (if org-export-html-expand
2590 (while (string-match "@<[^<>\n]*>" line
)
2591 ;; We just remove the tags for now.
2592 (setq line
(replace-match "" nil nil line
))))
2595 (defun org-insert-centered (s &optional underline
)
2596 "Insert the string S centered and underline it with character UNDERLINE."
2597 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2598 (insert (make-string ind ?\
) s
"\n")
2600 (insert (make-string ind ?\
)
2601 (make-string (string-width s
) underline
)
2604 (defun org-ascii-level-start (level title umax
&optional lines
)
2605 "Insert a new level in ASCII export."
2606 (let (char (n (- level umax
1)) (ind 0))
2609 (insert (make-string (* 2 n
) ?\
)
2610 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2611 org-export-ascii-bullets
))
2613 ;; find the indentation of the next non-empty line
2616 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2617 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2618 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2620 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2621 (if (or (not (equal (char-before) ?
\n))
2622 (not (equal (char-before (1- (point))) ?
\n)))
2624 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2625 (unless org-export-with-tags
2626 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2627 (setq title
(replace-match "" t t title
))))
2628 (if org-export-with-section-numbers
2629 (setq title
(concat (org-section-number level
) " " title
)))
2630 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2631 (setq org-ascii-current-indentation
'(0 .
0)))))
2634 (defun org-export-visible (type arg
)
2635 "Create a copy of the visible part of the current buffer, and export it.
2636 The copy is created in a temporary buffer and removed after use.
2637 TYPE is the final key (as a string) that also select the export command in
2638 the `C-c C-e' export dispatcher.
2639 As a special case, if the you type SPC at the prompt, the temporary
2640 org-mode file will not be removed but presented to you so that you can
2641 continue to use it. The prefix arg ARG is passed through to the exporting
2645 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2646 (read-char-exclusive))
2647 current-prefix-arg
))
2648 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2649 (error "Invalid export key"))
2650 (let* ((binding (cdr (assoc type
2651 '((?a . org-export-as-ascii
)
2652 (?\C-a . org-export-as-ascii
)
2653 (?b . org-export-as-html-and-open
)
2654 (?\C-b . org-export-as-html-and-open
)
2655 (?h . org-export-as-html
)
2656 (?H . org-export-as-html-to-buffer
)
2657 (?R . org-export-region-as-html
)
2658 (?x . org-export-as-xoxo
)))))
2659 (keepp (equal type ?\
))
2660 (file buffer-file-name
)
2661 (buffer (get-buffer-create "*Org Export Visible*"))
2663 ;; Need to hack the drawers here.
2665 (goto-char (point-min))
2666 (while (re-search-forward org-drawer-regexp nil t
)
2667 (goto-char (match-beginning 1))
2668 (or (org-invisible-p) (org-flag-drawer nil
))))
2669 (with-current-buffer buffer
(erase-buffer))
2671 (setq s
(goto-char (point-min)))
2672 (while (not (= (point) (point-max)))
2673 (goto-char (org-find-invisible))
2674 (append-to-buffer buffer s
(point))
2675 (setq s
(goto-char (org-find-visible))))
2676 (org-cycle-hide-drawers 'all
)
2677 (goto-char (point-min))
2679 ;; Copy all comment lines to the end, to make sure #+ settings are
2680 ;; still available for the second export step. Kind of a hack, but
2681 ;; does do the trick.
2682 (if (looking-at "#[^\r\n]*")
2683 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2684 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2685 (append-to-buffer buffer
(1+ (match-beginning 0))
2686 (min (point-max) (1+ (match-end 0))))))
2688 (let ((buffer-file-name file
)
2689 (org-inhibit-startup t
))
2692 (unless keepp
(funcall binding arg
))))
2694 (kill-buffer buffer
)
2695 (switch-to-buffer-other-window buffer
)
2696 (goto-char (point-min)))))
2698 (defun org-find-visible ()
2700 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2701 (get-char-property s
'invisible
)))
2703 (defun org-find-invisible ()
2705 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2706 (not (get-char-property s
'invisible
))))
2711 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2712 (defun org-get-current-options ()
2713 "Return a string with current options as keyword options.
2714 Does include HTML export options as well as TODO and CATEGORY stuff."
2715 (require 'org-archive
)
2722 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2724 #+EXPORT_SELECT_TAGS: %s
2725 #+EXPORT_EXCLUDE_TAGS: %s
2731 #+PRIORITIES: %c %c %c
2733 #+STARTUP: %s %s %s %s %s
2739 (buffer-name) (user-full-name) user-mail-address
2740 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2741 org-export-default-language
2742 org-export-headline-levels
2743 org-export-with-section-numbers
2745 org-export-preserve-breaks
2746 org-export-html-expand
2747 org-export-with-fixed-width
2748 org-export-with-tables
2749 org-export-with-sub-superscripts
2750 org-export-with-special-strings
2751 org-export-with-footnotes
2752 org-export-with-emphasize
2753 org-export-with-TeX-macros
2754 org-export-with-LaTeX-fragments
2755 org-export-skip-text-before-1st-heading
2756 org-export-with-drawers
2757 org-export-with-todo-keywords
2758 org-export-with-priority
2759 org-export-with-tags
2760 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2761 (mapconcat 'identity org-export-select-tags
" ")
2762 (mapconcat 'identity org-export-exclude-tags
" ")
2763 org-export-html-link-up
2764 org-export-html-link-home
2765 (file-name-nondirectory buffer-file-name
)
2766 "TODO FEEDBACK VERIFY DONE"
2767 "Me Jason Marie DONE"
2768 org-highest-priority org-lowest-priority org-default-priority
2769 (mapconcat 'identity org-drawers
" ")
2770 (cdr (assoc org-startup-folded
2771 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2772 (if org-odd-levels-only
"odd" "oddeven")
2773 (if org-hide-leading-stars
"hidestars" "showstars")
2774 (if org-startup-align-all-tables
"align" "noalign")
2775 (cond ((eq org-log-done t
) "logdone")
2776 ((equal org-log-done
'note
) "lognotedone")
2777 ((not org-log-done
) "nologdone"))
2778 (or (mapconcat (lambda (x)
2780 ((equal '(:startgroup
) x
) "{")
2781 ((equal '(:endgroup
) x
) "}")
2782 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2784 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2785 (mapconcat 'identity org-file-tags
" ")
2786 org-archive-location
2787 "org file:~/org/%s.org"
2790 (defun org-export-html-preprocess (parameters)
2791 ;; Convert LaTeX fragments to images
2792 (when (plist-get parameters
:LaTeX-fragments
)
2794 (concat "ltxpng/" (file-name-sans-extension
2795 (file-name-nondirectory
2796 org-current-export-file
)))
2797 org-current-export-dir nil
"Creating LaTeX image %s"))
2798 (message "Exporting..."))
2801 (defun org-insert-export-options-template ()
2802 "Insert into the buffer a template with information for exporting."
2804 (if (not (bolp)) (newline))
2805 (let ((s (org-get-current-options)))
2806 (and (string-match "#\\+CATEGORY" s
)
2807 (setq s
(substring s
0 (match-beginning 0))))
2811 (defun org-export-as-html-and-open (arg)
2812 "Export the outline as HTML and immediately open it with a browser.
2813 If there is an active region, export only the region.
2814 The prefix ARG specifies how many levels of the outline should become
2815 headlines. The default is 3. Lower levels will become bulleted lists."
2817 (org-export-as-html arg
'hidden
)
2818 (org-open-file buffer-file-name
))
2821 (defun org-export-as-html-batch ()
2822 "Call `org-export-as-html', may be used in batch processing as
2824 --load=$HOME/lib/emacs/org.el
2825 --eval \"(setq org-export-headline-levels 2)\"
2826 --visit=MyFile --funcall org-export-as-html-batch"
2827 (org-export-as-html org-export-headline-levels
'hidden
))
2830 (defun org-export-as-html-to-buffer (arg)
2831 "Call `org-export-as-html` with output to a temporary buffer.
2832 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2834 (org-export-as-html arg nil nil
"*Org HTML Export*")
2835 (switch-to-buffer-other-window "*Org HTML Export*"))
2838 (defun org-replace-region-by-html (beg end
)
2839 "Assume the current region has org-mode syntax, and convert it to HTML.
2840 This can be used in any buffer. For example, you could write an
2841 itemized list in org-mode syntax in an HTML buffer and then use this
2842 command to convert it."
2844 (let (reg html buf pop-up-frames
)
2845 (save-window-excursion
2847 (setq html
(org-export-region-as-html
2849 (setq reg
(buffer-substring beg end
)
2850 buf
(get-buffer-create "*Org tmp*"))
2851 (with-current-buffer buf
2855 (setq html
(org-export-region-as-html
2856 (point-min) (point-max) t
'string
)))
2858 (delete-region beg end
)
2862 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2863 "Convert region from BEG to END in org-mode buffer to HTML.
2864 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2865 contents, and only produce the region of converted text, useful for
2866 cut-and-paste operations.
2867 If BUFFER is a buffer or a string, use/create that buffer as a target
2868 of the converted HTML. If BUFFER is the symbol `string', return the
2869 produced HTML as a string and leave not buffer behind. For example,
2870 a Lisp program could call this function in the following way:
2872 (setq html (org-export-region-as-html beg end t 'string))
2874 When called interactively, the output buffer is selected, and shown
2875 in a window. A non-interactive call will only return the buffer."
2876 (interactive "r\nP")
2877 (when (interactive-p)
2878 (setq buffer
"*Org HTML Export*"))
2879 (let ((transient-mark-mode t
) (zmacs-regions t
)
2881 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2883 (set-mark (point)) ;; to activate the region
2885 (setq rtn
(org-export-as-html
2888 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2889 (if (and (interactive-p) (bufferp rtn
))
2890 (switch-to-buffer-other-window rtn
)
2893 (defvar html-table-tag nil
) ; dynamically scoped into this.
2894 (defvar org-par-open nil
)
2896 (defun org-export-as-html (arg &optional hidden ext-plist
2897 to-buffer body-only pub-dir
)
2898 "Export the outline as a pretty HTML file.
2899 If there is an active region, export only the region. The prefix
2900 ARG specifies how many levels of the outline should become
2901 headlines. The default is 3. Lower levels will become bulleted
2902 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2903 EXT-PLIST is a property list with external parameters overriding
2904 org-mode's default settings, but still inferior to file-local
2905 settings. When TO-BUFFER is non-nil, create a buffer with that
2906 name and export to that buffer. If TO-BUFFER is the symbol
2907 `string', don't leave any buffer behind but just return the
2908 resulting HTML as a string. When BODY-ONLY is set, don't produce
2909 the file header and footer, simply return the content of
2910 <body>...</body>, without even the body tags themselves. When
2911 PUB-DIR is set, use this as the publishing directory."
2914 ;; Make sure we have a file name when we need it.
2915 (when (and (not (or to-buffer body-only
))
2916 (not buffer-file-name
))
2917 (if (buffer-base-buffer)
2918 (org-set-local 'buffer-file-name
2919 (with-current-buffer (buffer-base-buffer)
2921 (error "Need a file name to be able to export.")))
2923 (message "Exporting...")
2924 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2925 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2926 (setq-default org-done-keywords org-done-keywords
)
2927 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2929 (org-export-process-option-filters
2930 (org-combine-plists (org-default-export-plist)
2932 (org-infile-export-plist))))
2933 (style (concat (if (plist-get opt-plist
:style-include-default
)
2934 org-export-html-style-default
)
2935 (plist-get opt-plist
:style
)
2936 (plist-get opt-plist
:style-extra
)))
2937 (html-extension (plist-get opt-plist
:html-extension
))
2938 (link-validate (plist-get opt-plist
:link-validation-function
))
2939 valid thetoc have-headings first-heading-pos
2940 (odd org-odd-levels-only
)
2941 (region-p (org-region-active-p))
2942 (rbeg (and region-p
(region-beginning)))
2943 (rend (and region-p
(region-end)))
2945 (if (plist-get opt-plist
:ignore-subree-p
)
2950 (and (org-at-heading-p)
2951 (>= (org-end-of-subtree t t
) rend
))))))
2952 (opt-plist (if subtree-p
2953 (org-export-add-subtree-options opt-plist rbeg
)
2955 ;; The following two are dynamically scoped into other
2957 (org-current-export-dir
2958 (or pub-dir
(org-export-directory :html opt-plist
)))
2959 (org-current-export-file buffer-file-name
)
2960 (level 0) (line "") (origline "") txt todo
2963 (filename (if to-buffer nil
2966 (file-name-sans-extension
2968 (org-entry-get (region-beginning)
2969 "EXPORT_FILE_NAME" t
))
2970 (file-name-nondirectory buffer-file-name
)))
2972 (file-name-as-directory
2973 (or pub-dir
(org-export-directory :html opt-plist
))))))
2974 (current-dir (if buffer-file-name
2975 (file-name-directory buffer-file-name
)
2977 (buffer (if to-buffer
2979 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2980 (t (get-buffer-create to-buffer
)))
2981 (find-file-noselect filename
)))
2982 (org-levels-open (make-vector org-level-max nil
))
2983 (date (plist-get opt-plist
:date
))
2984 (author (plist-get opt-plist
:author
))
2985 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2986 (plist-get opt-plist
:title
)
2988 (plist-get opt-plist
:skip-before-1st-heading
))
2989 (org-export-grab-title-from-buffer))
2990 (and buffer-file-name
2991 (file-name-sans-extension
2992 (file-name-nondirectory buffer-file-name
)))
2994 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2995 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2996 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3001 (local-list-type nil
)
3002 (local-list-indent nil
)
3003 (llt org-plain-list-ordered-item-terminator
)
3004 (email (plist-get opt-plist
:email
))
3005 (language (plist-get opt-plist
:language
))
3009 (coding-system (and (boundp 'buffer-file-coding-system
)
3010 buffer-file-coding-system
))
3011 (coding-system-for-write (or org-export-html-coding-system
3013 (save-buffer-coding-system (or org-export-html-coding-system
3015 (charset (and coding-system-for-write
3016 (fboundp 'coding-system-get
)
3017 (coding-system-get coding-system-for-write
3021 (if region-p
(region-beginning) (point-min))
3022 (if region-p
(region-end) (point-max))))
3025 (org-export-preprocess-string
3029 :skip-before-1st-heading
3030 (plist-get opt-plist
:skip-before-1st-heading
)
3031 :drawers
(plist-get opt-plist
:drawers
)
3032 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3033 :tags
(plist-get opt-plist
:tags
)
3034 :priority
(plist-get opt-plist
:priority
)
3036 (plist-get opt-plist
:archived-trees
)
3037 :select-tags
(plist-get opt-plist
:select-tags
)
3038 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3040 (plist-get opt-plist
:text
)
3042 (plist-get opt-plist
:LaTeX-fragments
))
3045 table-buffer table-orig-buffer
3046 ind item-type starter didclose
3047 rpl path attr desc descp desc1 desc2 link
3048 snumber fnc item-tag
3052 (let ((inhibit-read-only t
))
3054 (remove-text-properties (point-min) (point-max)
3055 '(:org-license-to-kill t
))))
3057 (message "Exporting...")
3059 (setq org-min-level
(org-get-min-level lines
))
3060 (setq org-last-level org-min-level
)
3061 (org-init-section-numbers)
3064 ((and date
(string-match "%" date
))
3065 (setq date
(format-time-string date
)))
3067 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3069 ;; Get the language-dependent settings
3070 (setq lang-words
(or (assoc language org-export-language-setup
)
3071 (assoc "en" org-export-language-setup
)))
3073 ;; Switch to the output buffer
3075 (let ((inhibit-read-only t
)) (erase-buffer))
3078 (and (fboundp 'set-buffer-file-coding-system
)
3079 (set-buffer-file-coding-system coding-system-for-write
))
3081 (let ((case-fold-search nil
)
3082 (org-odd-levels-only odd
))
3083 ;; create local variables for all options, to make sure all called
3084 ;; functions get the correct information
3086 (set (make-local-variable (nth 2 x
))
3087 (plist-get opt-plist
(car x
))))
3088 org-export-plist-vars
)
3089 (setq umax
(if arg
(prefix-numeric-value arg
)
3090 org-export-headline-levels
))
3091 (setq umax-toc
(if (integerp org-export-with-toc
)
3092 (min org-export-with-toc umax
)
3097 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3098 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3099 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3100 lang=\"%s\" xml:lang=\"%s\">
3103 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3104 <meta name=\"generator\" content=\"Org-mode\"/>
3105 <meta name=\"generated\" content=\"%s\"/>
3106 <meta name=\"author\" content=\"%s\"/>
3110 language language
(org-html-expand title
)
3111 (or charset
"iso-8859-1") date author style
))
3113 (insert (or (plist-get opt-plist
:preamble
) ""))
3115 (when (plist-get opt-plist
:auto-preamble
)
3116 (if title
(insert (format org-export-html-title-format
3117 (org-html-expand title
))))))
3119 (if (and org-export-with-toc
(not body-only
))
3121 (push (format "<h%d>%s</h%d>\n"
3122 org-export-html-toplevel-hlevel
3124 org-export-html-toplevel-hlevel
)
3126 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3127 (push "<ul>\n<li>" thetoc
)
3129 (mapcar '(lambda (line)
3130 (if (string-match org-todo-line-regexp line
)
3131 ;; This is a headline
3133 (setq have-headings t
)
3134 (setq level
(- (match-end 1) (match-beginning 1))
3135 level
(org-tr-level level
)
3136 txt
(save-match-data
3138 (org-export-cleanup-toc-line
3139 (match-string 3 line
))))
3141 (or (and org-export-mark-todo-in-toc
3143 (not (member (match-string 2 line
)
3144 org-done-keywords
)))
3146 (and org-export-mark-todo-in-toc
3148 (org-search-todo-below
3149 line lines level
))))
3151 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3152 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3153 (if (string-match quote-re0 txt
)
3154 (setq txt
(replace-match "" t t txt
)))
3155 (setq snumber
(org-section-number level
))
3156 (if org-export-with-section-numbers
3157 (setq txt
(concat snumber
" " txt
)))
3158 (if (<= level
(max umax umax-toc
))
3159 (setq head-count
(+ head-count
1)))
3160 (if (<= level umax-toc
)
3162 (if (> level org-last-level
)
3164 (setq cnt
(- level org-last-level
))
3165 (while (>= (setq cnt
(1- cnt
)) 0)
3166 (push "\n<ul>\n<li>" thetoc
))
3167 (push "\n" thetoc
)))
3168 (if (< level org-last-level
)
3170 (setq cnt
(- org-last-level level
))
3171 (while (>= (setq cnt
(1- cnt
)) 0)
3172 (push "</li>\n</ul>" thetoc
))
3173 (push "\n" thetoc
)))
3174 ;; Check for targets
3175 (while (string-match org-any-target-regexp line
)
3176 (setq line
(replace-match
3177 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3179 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3180 (setq txt
(replace-match "" t t txt
)))
3184 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3185 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3186 snumber txt
) thetoc
)
3188 (setq org-last-level level
))
3192 (while (> org-last-level
(1- org-min-level
))
3193 (setq org-last-level
(1- org-last-level
))
3194 (push "</li>\n</ul>\n" thetoc
))
3195 (push "</div>\n" thetoc
)
3196 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3199 (org-init-section-numbers)
3203 (while (setq line
(pop lines
) origline line
)
3206 ;; end of quote section?
3207 (when (and inquote
(string-match "^\\*+ " line
))
3210 ;; inside a quote section?
3212 (insert (org-html-protect line
) "\n")
3213 (throw 'nextline nil
))
3215 ;; Fixed-width, verbatim lines (examples)
3216 (when (and org-export-with-fixed-width
3217 (string-match "^[ \t]*:\\(.*\\)" line
))
3220 (org-close-par-maybe)
3221 (insert "<pre class=\"example\">\n"))
3222 (insert (org-html-protect (match-string 1 line
)) "\n")
3223 (when (or (not lines
)
3224 (not (string-match "^[ \t]*\\(:.*\\)"
3227 (insert "</pre>\n"))
3228 (throw 'nextline nil
))
3231 (when (get-text-property 0 'org-protected line
)
3233 (when (re-search-backward
3234 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3235 (setq par
(match-string 1))
3236 (replace-match "\\2\n"))
3239 (not (string-match "^[ \t]*:" (car lines
)))
3240 (or (= (length (car lines
)) 0)
3241 (get-text-property 0 'org-protected
(car lines
))))
3242 (insert (pop lines
) "\n"))
3243 (and par
(insert "<p>\n")))
3244 (throw 'nextline nil
))
3247 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3249 (insert "\n</p>\n<hr/>\n<p>\n")
3250 (insert "\n<hr/>\n"))
3251 (throw 'nextline nil
))
3253 ;; Blockquotes and verse
3254 (when (equal "ORG-BLOCKQUOTE-START" line
)
3255 (org-close-par-maybe)
3256 (insert "<blockquote>\n<p>\n")
3257 (throw 'nextline nil
))
3258 (when (equal "ORG-BLOCKQUOTE-END" line
)
3259 (insert "</p>\n</blockquote>\n")
3260 (throw 'nextline nil
))
3261 (when (equal "ORG-VERSE-START" line
)
3262 (org-close-par-maybe)
3263 (insert "\n<p class=\"verse\">\n")
3265 (throw 'nextline nil
))
3266 (when (equal "ORG-VERSE-END" line
)
3269 (throw 'nextline nil
))
3271 (let ((i (org-get-string-indentation line
)))
3273 (setq line
(concat (mapconcat 'identity
3274 (make-list (* 2 i
) "\\nbsp") "")
3275 " " (org-trim line
))))
3276 (setq line
(concat line
"\\\\"))))
3278 ;; make targets to anchors
3279 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3282 (setq line
(replace-match
3284 "@<a name=\"%s\" id=\"%s\">@</a>"
3285 (org-solidify-link-text (match-string 1 line
))
3286 (org-solidify-link-text (match-string 1 line
)))
3288 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3289 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3290 (setq line
(replace-match
3291 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3292 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3295 (setq line
(replace-match
3296 (concat "@<a name=\""
3297 (org-solidify-link-text (match-string 1 line
))
3298 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3301 (setq line
(org-html-handle-time-stamps line
))
3303 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3304 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3305 ;; Also handle sub_superscripts and checkboxes
3306 (or (string-match org-table-hline-regexp line
)
3307 (setq line
(org-html-expand line
)))
3311 (while (string-match org-bracket-link-analytic-regexp line start
)
3312 (setq start
(match-beginning 0))
3313 (setq path
(save-match-data (org-link-unescape
3314 (match-string 3 line
))))
3316 ((match-end 2) (match-string 2 line
))
3318 (or (file-name-absolute-p path
)
3319 (string-match "^\\.\\.?/" path
)))
3322 (setq path
(org-extract-attributes (org-link-unescape path
)))
3323 (setq attr
(get-text-property 0 'org-attributes path
))
3324 (setq desc1
(if (match-end 5) (match-string 5 line
))
3325 desc2
(if (match-end 2) (concat type
":" path
) path
)
3326 descp
(and desc1
(not (equal desc1 desc2
)))
3327 desc
(or desc1 desc2
))
3328 ;; Make an image out of the description if that is so wanted
3329 (when (and descp
(org-file-image-p desc
))
3331 (if (string-match "^file:" desc
)
3332 (setq desc
(substring desc
(match-end 0)))))
3333 (setq desc
(org-add-props
3334 (concat "<img src=\"" desc
"\"/>")
3335 '(org-protected t
))))
3336 ;; FIXME: do we need to unescape here somewhere?
3338 ((equal type
"internal")
3342 (org-solidify-link-text
3343 (save-match-data (org-link-unescape path
)) nil
)
3345 (org-export-html-format-desc desc
)
3347 ((member type
'("http" "https"))
3348 ;; standard URL, just check if we need to inline an image
3349 (if (and (or (eq t org-export-html-inline-images
)
3350 (and org-export-html-inline-images
(not descp
)))
3351 (org-file-image-p path
))
3352 (setq rpl
(org-export-html-format-image
3353 (concat type
":" path
)))
3354 (setq link
(concat type
":" path
))
3355 (setq rpl
(concat "<a href=\""
3356 (org-export-html-format-href link
)
3358 (org-export-html-format-desc desc
)
3360 ((member type
'("ftp" "mailto" "news"))
3362 (setq link
(concat type
":" path
))
3363 (setq rpl
(concat "<a href=\""
3364 (org-export-html-format-href link
)
3366 (org-export-html-format-desc desc
)
3369 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3370 ;; The link protocol has a function for format the link
3373 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3375 ((string= type
"file")
3377 (let* ((filename path
)
3378 (abs-p (file-name-absolute-p filename
))
3379 thefile file-is-image-p search
)
3381 (if (string-match "::\\(.*\\)" filename
)
3382 (setq search
(match-string 1 filename
)
3383 filename
(replace-match "" t nil filename
)))
3385 (if (functionp link-validate
)
3386 (funcall link-validate filename current-dir
)
3388 (setq file-is-image-p
(org-file-image-p filename
))
3389 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3390 (when (and org-export-html-link-org-files-as-html
3391 (string-match "\\.org$" thefile
))
3392 (setq thefile
(concat (substring thefile
0
3393 (match-beginning 0))
3394 "." html-extension
))
3396 ;; make sure this is can be used as target search
3397 (not (string-match "^[0-9]*$" search
))
3398 (not (string-match "^\\*" search
))
3399 (not (string-match "^/.*/$" search
)))
3400 (setq thefile
(concat thefile
"#"
3401 (org-solidify-link-text
3402 (org-link-unescape search
)))))
3403 (when (string-match "^file:" desc
)
3404 (setq desc
(replace-match "" t t desc
))
3405 (if (string-match "\\.org$" desc
)
3406 (setq desc
(replace-match "" t t desc
))))))
3407 (setq rpl
(if (and file-is-image-p
3408 (or (eq t org-export-html-inline-images
)
3409 (and org-export-html-inline-images
3411 (org-export-html-format-image thefile
)
3412 (concat "<a href=\"" thefile
"\"" attr
">"
3413 (org-export-html-format-desc desc
)
3415 (if (not valid
) (setq rpl desc
))))
3418 ;; just publish the path, as default
3419 (setq rpl
(concat "<i><" type
":"
3420 (save-match-data (org-link-unescape path
))
3422 (setq line
(replace-match rpl t t line
)
3423 start
(+ start
(length rpl
))))
3426 (if (and (string-match org-todo-line-regexp line
)
3427 (match-beginning 2))
3430 (concat (substring line
0 (match-beginning 2))
3432 (if (member (match-string 2 line
)
3435 "\">" (match-string 2 line
)
3436 "</span>" (substring line
(match-end 2)))))
3438 ;; Does this contain a reference to a footnote?
3439 (when org-export-with-footnotes
3441 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3442 (if (get-text-property (match-beginning 2) 'org-protected line
)
3443 (setq start
(match-end 2))
3444 (let ((n (match-string 2 line
)))
3448 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3449 (match-string 1 line
) n n n
)
3453 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3454 ;; This is a headline
3455 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3456 txt
(match-string 2 line
))
3457 (if (string-match quote-re0 txt
)
3458 (setq txt
(replace-match "" t t txt
)))
3459 (if (<= level
(max umax umax-toc
))
3460 (setq head-count
(+ head-count
1)))
3462 ;; Close any local lists before inserting a new header line
3463 (while local-list-type
3464 (org-close-li (car local-list-type
))
3465 (insert (format "</%sl>\n" (car local-list-type
)))
3466 (pop local-list-type
))
3467 (setq local-list-indent nil
3469 (setq first-heading-pos
(or first-heading-pos
(point)))
3470 (org-html-level-start level txt umax
3471 (and org-export-with-toc
(<= level umax
))
3474 (when (string-match quote-re line
)
3475 (org-close-par-maybe)
3479 ((and org-export-with-tables
3480 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3481 (if (not table-open
)
3483 (setq table-open t table-buffer nil table-orig-buffer nil
))
3485 (setq table-buffer
(cons line table-buffer
)
3486 table-orig-buffer
(cons origline table-orig-buffer
))
3487 (when (or (not lines
)
3488 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3490 (setq table-open nil
3491 table-buffer
(nreverse table-buffer
)
3492 table-orig-buffer
(nreverse table-orig-buffer
))
3493 (org-close-par-maybe)
3494 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3499 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3500 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3501 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3502 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3504 (setq ind
(org-get-string-indentation line
)
3505 item-type
(if (match-beginning 4) "o" "u")
3506 starter
(if (match-beginning 2)
3507 (substring (match-string 2 line
) 0 -
1))
3508 line
(substring line
(match-beginning 5))
3510 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3512 item-tag
(match-string 1 line
)
3513 line
(substring line
(match-end 0))))
3514 (when (and (not (equal item-type
"d"))
3515 (not (string-match "[^ \t]" line
)))
3516 ;; empty line. Pretend indentation is large.
3517 (setq ind
(if org-empty-line-terminates-plain-lists
3519 (1+ (or (car local-list-indent
) 1)))))
3521 (while (and in-local-list
3522 (or (and (= ind
(car local-list-indent
))
3524 (< ind
(car local-list-indent
))))
3526 (org-close-li (car local-list-type
))
3527 (insert (format "</%sl>\n" (car local-list-type
)))
3528 (pop local-list-type
) (pop local-list-indent
)
3529 (setq in-local-list local-list-indent
))
3532 (or (not in-local-list
)
3533 (> ind
(car local-list-indent
))))
3534 ;; Start new (level of) list
3535 (org-close-par-maybe)
3537 ((equal item-type
"u") "<ul>\n<li>\n")
3538 ((equal item-type
"o") "<ol>\n<li>\n")
3539 ((equal item-type
"d")
3540 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3541 (push item-type local-list-type
)
3542 (push ind local-list-indent
)
3543 (setq in-local-list t
))
3545 ;; continue current list
3546 (org-close-li (car local-list-type
))
3548 ((equal (car local-list-type
) "d")
3549 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3552 ;; we did close a list, normal text follows: need <p>
3554 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3557 (if (equal (match-string 1 line
) "X")
3559 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3562 ;; Empty lines start a new paragraph. If hand-formatted lists
3563 ;; are not fully interpreted, lines starting with "-", "+", "*"
3564 ;; also start a new paragraph.
3565 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3567 ;; Is this the start of a footnote?
3568 (when org-export-with-footnotes
3569 (when (and (boundp 'footnote-section-tag-regexp
)
3570 (string-match (concat "^" footnote-section-tag-regexp
)
3573 (throw 'nextline nil
))
3574 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3575 (org-close-par-maybe)
3576 (let ((n (match-string 1 line
)))
3577 (setq org-par-open t
3579 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3581 ;; Check if the line break needs to be conserved
3583 ((string-match "\\\\\\\\[ \t]*$" line
)
3584 (setq line
(replace-match "<br/>" t t line
)))
3585 (org-export-preserve-breaks
3586 (setq line
(concat line
"<br/>"))))
3588 (insert line
"\n")))))
3590 ;; Properly close all local lists and other lists
3595 ;; Close any local lists before inserting a new header line
3596 (while local-list-type
3597 (org-close-li (car local-list-type
))
3598 (insert (format "</%sl>\n" (car local-list-type
)))
3599 (pop local-list-type
))
3600 (setq local-list-indent nil
3602 (org-html-level-start 1 nil umax
3603 (and org-export-with-toc
(<= level umax
))
3605 ;; the </div> to close the last text-... div.
3606 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3609 (goto-char (point-min))
3610 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3611 (push (match-string 0) footnotes
)
3612 (replace-match "" t t
)))
3614 (insert (format org-export-html-footnotes-section
3615 (or (nth 4 lang-words
) "Footnotes")
3616 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3619 (when (plist-get opt-plist
:auto-postamble
)
3620 (insert "<div id=\"postamble\">")
3621 (when (and org-export-author-info author
)
3622 (insert "<p class=\"author\"> "
3623 (nth 1 lang-words
) ": " author
"\n")
3625 (if (listp (split-string email
",+ *"))
3627 (insert "<a href=\"mailto:" e
"\"><"
3629 (split-string email
",+ *"))
3630 (insert "<a href=\"mailto:" email
"\"><"
3631 email
"></a>\n")))
3633 (when (and date org-export-time-stamp-file
)
3634 (insert "<p class=\"date\"> "
3635 (nth 2 lang-words
) ": "
3637 (when org-export-creator-info
3638 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3639 org-version emacs-major-version
)))
3642 (if org-export-html-with-timestamp
3643 (insert org-export-html-html-helper-timestamp
))
3644 (insert (or (plist-get opt-plist
:postamble
) ""))
3645 (insert "</body>\n</html>\n"))
3647 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3649 (if (eq major-mode default-major-mode
) (html-mode)))
3651 ;; insert the table of contents
3652 (goto-char (point-min))
3654 (if (or (re-search-forward
3655 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3657 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3659 (goto-char (match-beginning 0))
3661 (goto-char first-heading-pos
)
3662 (when (looking-at "\\s-*</p>")
3663 (goto-char (match-end 0))
3665 (insert "<div id=\"table-of-contents\">\n")
3666 (mapc 'insert thetoc
)
3667 (insert "</div>\n"))
3668 ;; remove empty paragraphs and lists
3669 (goto-char (point-min))
3670 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3672 (goto-char (point-min))
3673 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3675 (goto-char (point-min))
3676 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3678 ;; Convert whitespace place holders
3679 (goto-char (point-min))
3681 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3682 (setq n
(get-text-property beg
'org-whitespace
)
3683 end
(next-single-property-change beg
'org-whitespace
))
3685 (delete-region beg end
)
3686 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3687 (make-string n ?x
)))))
3688 (or to-buffer
(save-buffer))
3689 (goto-char (point-min))
3690 (message "Exporting... done")
3691 (if (eq to-buffer
'string
)
3692 (prog1 (buffer-substring (point-min) (point-max))
3693 (kill-buffer (current-buffer)))
3694 (current-buffer)))))
3696 (defun org-export-html-format-href (s)
3697 "Make sure the S is valid as a href reference in an XHTML document."
3700 (while (string-match "&" s start
)
3701 (setq start
(+ (match-beginning 0) 3)
3702 s
(replace-match "&" t t s
)))))
3705 (defun org-export-html-format-desc (s)
3706 "Make sure the S is valid as a description in a link."
3707 (if (and s
(not (get-text-property 1 'org-protected s
)))
3709 (org-html-do-expand s
))
3712 (defun org-export-html-format-image (src)
3713 "Create image tag with source and attributes."
3715 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
3716 (attr (org-find-text-property-in-string 'org-attributes src
))
3717 (label (org-find-text-property-in-string 'org-label src
)))
3718 (format "<div %sclass=\"figure\">
3719 <p><img src=\"%s\"%s></p>%s
3721 (if label
(format "id=\"%s\" " label
) "")
3723 (if (string-match "\\<alt=" (or attr
""))
3725 (concat " " attr
" alt=\"" src
"\""))
3726 (if caption
(concat "\n<p>" caption
"</p>") "")))))
3728 (defvar org-table-colgroup-info nil
)
3729 (defun org-format-table-ascii (lines)
3730 "Format a table for ascii export."
3732 (setq lines
(org-split-string lines
"\n")))
3733 (if (not (string-match "^[ \t]*|" (car lines
)))
3734 ;; Table made by table.el - test for spanning
3737 ;; A normal org table
3738 ;; Get rid of hlines at beginning and end
3739 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3740 (setq lines
(nreverse lines
))
3741 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3742 (setq lines
(nreverse lines
))
3743 (when org-export-table-remove-special-lines
3744 ;; Check if the table has a marking column. If yes remove the
3745 ;; column and the special lines
3746 (setq lines
(org-table-clean-before-export lines
)))
3747 ;; Get rid of the vertical lines except for grouping
3748 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3750 (while (setq line
(pop lines
))
3751 (if (string-match org-table-hline-regexp line
)
3752 (and (string-match "|\\(.*\\)|" line
)
3753 (setq line
(replace-match " \\1" t nil line
)))
3754 (setq start
0 vl1 vl
)
3755 (while (string-match "|" line start
)
3756 (setq start
(match-end 0))
3757 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3761 (defun org-colgroup-info-to-vline-list (info)
3764 (setq last new new
(pop info
))
3765 (if (or (memq last
'(:end
:startend
))
3766 (memq new
'(:start
:startend
)))
3769 (setq vl
(nreverse vl
))
3770 (and vl
(setcar vl nil
))
3773 (defvar org-table-number-regexp
) ; defined in org-table.el
3774 (defun org-format-table-html (lines olines
)
3775 "Find out which HTML converter to use and return the HTML code."
3777 (setq lines
(org-split-string lines
"\n")))
3778 (if (string-match "^[ \t]*|" (car lines
))
3779 ;; A normal org table
3780 (org-format-org-table-html lines
)
3781 ;; Table made by table.el - test for spanning
3782 (let* ((hlines (delq nil
(mapcar
3784 (if (string-match "^[ \t]*\\+-" x
) x
3787 (first (car hlines
))
3788 (ll (and (string-match "\\S-+" first
)
3789 (match-string 0 first
)))
3790 (re (concat "^[ \t]*" (regexp-quote ll
)))
3791 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3793 (if (and (not spanning
)
3794 (not org-export-prefer-native-exporter-for-tables
))
3795 ;; We can use my own converter with HTML conversions
3796 (org-format-table-table-html lines
)
3797 ;; Need to use the code generator in table.el, with the original text.
3798 (org-format-table-table-html-using-table-generate-source olines
)))))
3800 (defvar org-table-number-fraction
) ; defined in org-table.el
3801 (defun org-format-org-table-html (lines &optional splice
)
3802 "Format a table into HTML."
3803 (require 'org-table
)
3804 ;; Get rid of hlines at beginning and end
3805 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3806 (setq lines
(nreverse lines
))
3807 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3808 (setq lines
(nreverse lines
))
3809 (when org-export-table-remove-special-lines
3810 ;; Check if the table has a marking column. If yes remove the
3811 ;; column and the special lines
3812 (setq lines
(org-table-clean-before-export lines
)))
3814 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
3815 (get-text-property (or (next-single-property-change
3816 0 'org-caption
(car lines
))
3818 'org-caption
(car lines
))))
3819 (head (and org-export-highlight-first-table-line
3821 (lambda (x) (string-match "^[ \t]*|-" x
))
3825 tbopen line fields html gr colgropen
)
3826 (if splice
(setq head nil
))
3827 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3829 (while (setq line
(pop lines
))
3831 (if (string-match "^[ \t]*|-" line
)
3834 (push (if head
"</thead>" "</tbody>") html
)
3835 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3836 (setq head nil
) ;; head ends here, first time around
3838 (throw 'next-line t
)))
3839 ;; Break the line into fields
3840 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3841 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3842 (setq nlines
(1+ nlines
) i -
1)
3843 (push (concat "<tr>"
3847 (if (and (< i nlines
)
3848 (string-match org-table-number-regexp x
))
3849 (incf (aref fnum i
)))
3851 (concat (car org-export-table-header-tags
) x
3852 (cdr org-export-table-header-tags
))
3853 (concat (car org-export-table-data-tags
) x
3854 (cdr org-export-table-data-tags
))))
3858 (unless splice
(if tbopen
(push "</tbody>" html
)))
3859 (unless splice
(push "</table>\n" html
))
3860 (setq html
(nreverse html
))
3862 ;; Put in col tags with the alignment (unfortunately often ignored...)
3865 (setq gr
(pop org-table-colgroup-info
))
3866 (format "%s<col align=\"%s\"></col>%s"
3867 (if (memq gr
'(:start
:startend
))
3869 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3872 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3874 (if (memq gr
'(:end
:startend
))
3875 (progn (setq colgropen nil
) "</colgroup>")
3879 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3880 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
3881 (push html-table-tag html
))
3882 (concat (mapconcat 'identity html
"\n") "\n")))
3884 (defun org-table-clean-before-export (lines)
3885 "Check if the table has a marking column.
3886 If yes remove the column and the special lines."
3887 (setq org-table-colgroup-info nil
)
3890 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3891 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3894 (setq org-table-clean-did-remove-column nil
)
3899 ((string-match "^[ \t]*| */ *|" x
)
3900 (setq org-table-colgroup-info
3902 (cond ((member x
'("<" "<")) :start
)
3903 ((member x
'(">" ">")) :end
)
3904 ((member x
'("<>" "<>")) :startend
)
3906 (org-split-string x
"[ \t]*|[ \t]*")))
3910 (setq org-table-clean-did-remove-column t
)
3915 ((string-match "^[ \t]*| */ *|" x
)
3916 (setq org-table-colgroup-info
3918 (cond ((member x
'("<" "<")) :start
)
3919 ((member x
'(">" ">")) :end
)
3920 ((member x
'("<>" "<>")) :startend
)
3922 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3924 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3925 nil
) ; ignore this line
3926 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3927 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3928 ;; remove the first column
3929 (replace-match "\\1|" t nil x
))))
3932 (defun org-format-table-table-html (lines)
3933 "Format a table generated by table.el into HTML.
3934 This conversion does *not* use `table-generate-source' from table.el.
3935 This has the advantage that Org-mode's HTML conversions can be used.
3936 But it has the disadvantage, that no cell- or row-spanning is allowed."
3937 (let (line field-buffer
3938 (head org-export-highlight-first-table-line
)
3940 (setq html
(concat html-table-tag
"\n"))
3941 (while (setq line
(pop lines
))
3942 (setq empty
" ")
3944 (if (string-match "^[ \t]*\\+-" line
)
3955 (if (equal x
"") (setq x empty
))
3957 (concat (car org-export-table-header-tags
) x
3958 (cdr org-export-table-header-tags
))
3959 (concat (car org-export-table-data-tags
) x
3960 (cdr org-export-table-data-tags
))))
3964 (setq field-buffer nil
)))
3966 (throw 'next-line t
)))
3967 ;; Break the line into fields and store the fields
3968 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3970 (setq field-buffer
(mapcar
3972 (concat x
"<br/>" (pop fields
)))
3974 (setq field-buffer fields
))))
3975 (setq html
(concat html
"</table>\n"))
3978 (defun org-format-table-table-html-using-table-generate-source (lines)
3979 "Format a table into html, using `table-generate-source' from table.el.
3980 This has the advantage that cell- or row-spanning is allowed.
3981 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3983 (with-current-buffer (get-buffer-create " org-tmp1 ")
3985 (insert (mapconcat 'identity lines
"\n"))
3986 (goto-char (point-min))
3987 (if (not (re-search-forward "|[^+]" nil t
))
3988 (error "Error processing table"))
3989 (table-recognize-table)
3990 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3991 (table-generate-source 'html
" org-tmp2 ")
3992 (set-buffer " org-tmp2 ")
3993 (buffer-substring (point-min) (point-max))))
3995 (defun org-export-splice-style (style extra
)
3996 "Splice EXTRA into STYLE, just before \"</style>\"."
3997 (if (and (stringp extra
)
3998 (string-match "\\S-" extra
)
3999 (string-match "</style>" style
))
4000 (concat (substring style
0 (match-beginning 0))
4002 (substring style
(match-beginning 0)))
4005 (defun org-html-handle-time-stamps (s)
4006 "Format time stamps in string S, or remove them."
4009 (while (string-match org-maybe-keyword-time-regexp s
)
4010 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
4011 ;; never export CLOCK
4013 (or b
(setq b
(substring s
0 (match-beginning 0))))
4014 (if (not org-export-with-timestamps
)
4015 (setq r
(concat r
(substring s
0 (match-beginning 0)))
4016 s
(substring s
(match-end 0)))
4018 r
(substring s
0 (match-beginning 0))
4020 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4021 (match-string 1 s
)))
4022 (format " @<span class=\"timestamp\">%s@</span>"
4024 (org-translate-time (match-string 3 s
)) 1 -
1)))
4025 s
(substring s
(match-end 0)))))
4026 ;; Line break if line started and ended with time stamp stuff
4029 (setq r
(concat r s
))
4030 (unless (string-match "\\S-" (concat b s
))
4031 (setq r
(concat r
"@<br/>")))
4034 (defun org-export-htmlize-region-for-paste (beg end
)
4035 "Convert the region to HTML, using htmlize.el.
4036 This is much like `htmlize-region-for-paste', only that it uses
4037 the settings define in the org-... variables."
4038 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4039 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4040 (htmlbuf (htmlize-region beg end
)))
4042 (with-current-buffer htmlbuf
4043 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4044 (plist-get htmlize-buffer-places
'content-end
)))
4045 (kill-buffer htmlbuf
))))
4048 (defun org-export-htmlize-generate-css ()
4049 "Create the CSS for all font definitions in the current Emacs session.
4050 Use this to create face definitions in your CSS style file that can then
4051 be used by code snippets transformed by htmlize.
4052 This command just produces a buffer that contains class definitions for all
4053 faces used in the current Emacs session. You can copy and paste the ones you
4054 need into your CSS file.
4056 If you then set `org-export-htmlize-output-type' to `css', calls to
4057 the function `org-export-htmlize-region-for-paste' will produce code
4058 that uses these same face definitions."
4061 (and (get-buffer "*html*") (kill-buffer "*html*"))
4063 (let ((fl (face-list))
4064 (htmlize-css-name-prefix "org-")
4065 (htmlize-output-type 'css
)
4067 (while (setq f
(pop fl
)
4068 i
(and f
(face-attribute f
:inherit
)))
4069 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4070 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4071 (htmlize-region (point-min) (point-max))))
4072 (switch-to-buffer "*html*")
4073 (goto-char (point-min))
4074 (if (re-search-forward "<style" nil t
)
4075 (delete-region (point-min) (match-beginning 0)))
4076 (if (re-search-forward "</style>" nil t
)
4077 (delete-region (1+ (match-end 0)) (point-max)))
4078 (beginning-of-line 1)
4079 (if (looking-at " +") (replace-match ""))
4080 (goto-char (point-min)))
4082 (defun org-html-protect (s)
4083 ;; convert & to &, < to < and > to >
4085 (while (string-match "&" s start
)
4086 (setq s
(replace-match "&" t t s
)
4087 start
(1+ (match-beginning 0))))
4088 (while (string-match "<" s
)
4089 (setq s
(replace-match "<" t t s
)))
4090 (while (string-match ">" s
)
4091 (setq s
(replace-match ">" t t s
)))
4092 ; (while (string-match "\"" s)
4093 ; (setq s (replace-match """ t t s)))
4097 (defun org-export-cleanup-toc-line (s)
4098 "Remove tags and timestamps from lines going into the toc."
4099 (when (memq org-export-with-tags
'(not-in-toc nil
))
4100 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4101 (setq s
(replace-match "" t t s
))))
4102 (when org-export-remove-timestamps-from-toc
4103 (while (string-match org-maybe-keyword-time-regexp s
)
4104 (setq s
(replace-match "" t t s
))))
4105 (while (string-match org-bracket-link-regexp s
)
4106 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4110 (defun org-html-expand (string)
4111 "Prepare STRING for HTML export. Applies all active conversions.
4112 If there are links in the string, don't modify these."
4113 (let* ((re (concat org-bracket-link-regexp
"\\|"
4114 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4116 (while (setq m
(string-match re string
))
4117 (setq s
(substring string
0 m
)
4118 l
(match-string 0 string
)
4119 string
(substring string
(match-end 0)))
4120 (push (org-html-do-expand s
) res
)
4122 (push (org-html-do-expand string
) res
)
4123 (apply 'concat
(nreverse res
))))
4125 (defun org-html-do-expand (s)
4126 "Apply all active conversions to translate special ASCII to HTML."
4127 (setq s
(org-html-protect s
))
4128 (if org-export-html-expand
4130 (while (string-match "@<\\([^&]*\\)>" s
)
4131 (setq s
(replace-match "<\\1>" t nil s
)))))
4132 (if org-export-with-emphasize
4133 (setq s
(org-export-html-convert-emphasize s
)))
4134 (if org-export-with-special-strings
4135 (setq s
(org-export-html-convert-special-strings s
)))
4136 (if org-export-with-sub-superscripts
4137 (setq s
(org-export-html-convert-sub-super s
)))
4138 (if org-export-with-TeX-macros
4139 (let ((start 0) wd ass
)
4140 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4142 (if (get-text-property (match-beginning 0) 'org-protected s
)
4143 (setq start
(match-end 0))
4144 (setq wd
(match-string 1 s
))
4145 (if (setq ass
(assoc wd org-html-entities
))
4146 (setq s
(replace-match (or (cdr ass
)
4147 (concat "&" (car ass
) ";"))
4149 (setq start
(+ start
(length wd
))))))))
4152 (defun org-create-multibrace-regexp (left right n
)
4153 "Create a regular expression which will match a balanced sexp.
4154 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4155 as single character strings.
4156 The regexp returned will match the entire expression including the
4157 delimiters. It will also define a single group which contains the
4158 match except for the outermost delimiters. The maximum depth of
4159 stacked delimiters is N. Escaping delimiters is not possible."
4160 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4163 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4166 re
(concat re or next
)
4167 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4168 (concat left
"\\(" re
"\\)" right
)))
4170 (defvar org-match-substring-regexp
4172 "\\([^\\]\\)\\([_^]\\)\\("
4173 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4175 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4177 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4178 "The regular expression matching a sub- or superscript.")
4180 (defvar org-match-substring-with-braces-regexp
4182 "\\([^\\]\\)\\([_^]\\)\\("
4183 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4185 "The regular expression matching a sub- or superscript, forcing braces.")
4187 (defconst org-export-html-special-string-regexps
4188 '(("\\\\-" .
"­")
4189 ("---\\([^-]\\)" .
"—\\1")
4190 ("--\\([^-]\\)" .
"–\\1")
4191 ("\\.\\.\\." .
"…"))
4192 "Regular expressions for special string conversion.")
4194 (defun org-export-html-convert-special-strings (string)
4195 "Convert special characters in STRING to HTML."
4196 (let ((all org-export-html-special-string-regexps
)
4198 (while (setq a
(pop all
))
4199 (setq re
(car a
) rpl
(cdr a
) start
0)
4200 (while (string-match re string start
)
4201 (if (get-text-property (match-beginning 0) 'org-protected string
)
4202 (setq start
(match-end 0))
4203 (setq string
(replace-match rpl t nil string
)))))
4206 (defun org-export-html-convert-sub-super (string)
4207 "Convert sub- and superscripts in STRING to HTML."
4208 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4209 (while (string-match org-match-substring-regexp string s
)
4211 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4212 ((get-text-property (match-beginning 2) 'org-protected string
)
4213 (setq s
(match-end 2)))
4215 (setq s
(match-end 1)
4216 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4217 c
(or (match-string 8 string
)
4218 (match-string 6 string
)
4219 (match-string 5 string
))
4220 string
(replace-match
4221 (concat (match-string 1 string
)
4222 "<" key
">" c
"</" key
">")
4224 (while (string-match "\\\\\\([_^]\\)" string
)
4225 (setq string
(replace-match (match-string 1 string
) t t string
)))
4228 (defun org-export-html-convert-emphasize (string)
4231 (while (string-match org-emph-re string s
)
4233 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4234 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4235 (setq s
(match-beginning 0)
4238 (match-string 1 string
)
4239 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4240 (match-string 4 string
)
4241 (nth 3 (assoc (match-string 3 string
)
4242 org-emphasis-alist
))
4243 (match-string 5 string
))
4244 string
(replace-match rpl t t string
)
4245 s
(+ s
(- (length rpl
) 2)))
4249 (defun org-open-par ()
4250 "Insert <p>, but first close previous paragraph if any."
4251 (org-close-par-maybe)
4253 (setq org-par-open t
))
4254 (defun org-close-par-maybe ()
4255 "Close paragraph if there is one open."
4258 (setq org-par-open nil
)))
4259 (defun org-close-li (&optional type
)
4260 "Close <li> if necessary."
4261 (org-close-par-maybe)
4262 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4264 (defvar body-only
) ; dynamically scoped into this.
4265 (defun org-html-level-start (level title umax with-toc head-count
)
4266 "Insert a new level in HTML export.
4267 When TITLE is nil, just close all open levels."
4268 (org-close-par-maybe)
4269 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4271 (mapconcat (lambda (x)
4272 (format "<a name=\"%s\" id=\"%s\"></a>"
4274 (cdr (assoc target org-export-target-aliases
))
4279 (if (aref org-levels-open
(1- l
))
4281 (org-html-level-close l umax
)
4282 (aset org-levels-open
(1- l
) nil
)))
4285 ;; If title is nil, this means this function is called to close
4286 ;; all levels, so the rest is done only if title is given
4287 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4288 (setq title
(replace-match
4289 (if org-export-with-tags
4292 " <span class=\"tag\">"
4293 (mapconcat 'identity
(org-split-string
4294 (match-string 1 title
) ":")
4301 (if (aref org-levels-open
(1- level
))
4305 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4306 (insert "<li>" title
"<br/>\n")))
4307 (aset org-levels-open
(1- level
) t
)
4308 (org-close-par-maybe)
4310 (insert (format "<ul>\n<li id=\"%s\">" target
)
4311 extra-targets title
"<br/>\n")
4312 (insert "<ul>\n<li>" title
"<br/>\n"))))
4313 (aset org-levels-open
(1- level
) t
)
4314 (setq snumber
(org-section-number level
))
4315 (if (and org-export-with-section-numbers
(not body-only
))
4316 (setq title
(concat snumber
" " title
)))
4317 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4318 (unless (= head-count
1) (insert "\n</div>\n"))
4319 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4320 snumber level level snumber extra-targets title level snumber
))
4323 (defun org-get-text-property-any (pos prop
&optional object
)
4324 (or (get-text-property pos prop object
)
4325 (and (setq pos
(next-single-property-change pos prop object
))
4326 (get-text-property pos prop object
))))
4328 (defun org-html-level-close (level max-outline-level
)
4329 "Terminate one level in HTML export."
4330 (if (<= level max-outline-level
)
4333 (insert "</ul>\n")))
4335 ;;; iCalendar export
4338 (defun org-export-icalendar-this-file ()
4339 "Export current file as an iCalendar file.
4340 The iCalendar file will be located in the same directory as the Org-mode
4341 file, but with extension `.ics'."
4343 (org-export-icalendar nil buffer-file-name
))
4346 (defun org-export-icalendar-all-agenda-files ()
4347 "Export all files in `org-agenda-files' to iCalendar .ics files.
4348 Each iCalendar file will be located in the same directory as the Org-mode
4349 file, but with extension `.ics'."
4351 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4354 (defun org-export-icalendar-combine-agenda-files ()
4355 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4356 The file is stored under the name `org-combined-agenda-icalendar-file'."
4358 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4360 (defun org-export-icalendar (combine &rest files
)
4361 "Create iCalendar files for all elements of FILES.
4362 If COMBINE is non-nil, combine all calendar entries into a single large
4363 file and store it under the name `org-combined-agenda-icalendar-file'."
4365 (org-prepare-agenda-buffers files
)
4366 (let* ((dir (org-export-directory
4367 :ical
(list :publishing-directory
4368 org-export-publishing-directory
)))
4369 file ical-file ical-buffer category started org-agenda-new-buffers
)
4370 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4373 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4374 org-combined-agenda-icalendar-file
4375 (expand-file-name org-combined-agenda-icalendar-file dir
))
4376 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4377 (set-buffer ical-buffer
) (erase-buffer))
4378 (while (setq file
(pop files
))
4380 (org-check-agenda-file file
)
4381 (set-buffer (org-get-agenda-file-buffer file
))
4383 (setq ical-file
(concat (file-name-as-directory dir
)
4384 (file-name-sans-extension
4385 (file-name-nondirectory buffer-file-name
))
4387 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4388 (with-current-buffer ical-buffer
(erase-buffer)))
4389 (setq category
(or org-category
4390 (file-name-sans-extension
4391 (file-name-nondirectory buffer-file-name
))))
4392 (if (symbolp category
) (setq category
(symbol-name category
)))
4393 (let ((standard-output ical-buffer
))
4395 (and (not started
) (setq started t
)
4396 (org-start-icalendar-file org-icalendar-combined-name
))
4397 (org-start-icalendar-file category
))
4398 (org-print-icalendar-entries combine
)
4399 (when (or (and combine
(not files
)) (not combine
))
4400 (org-finish-icalendar-file)
4401 (set-buffer ical-buffer
)
4402 (run-hooks 'org-before-save-iCalendar-file-hook
)
4404 (run-hooks 'org-after-save-iCalendar-file-hook
)
4405 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4407 (org-release-buffers org-agenda-new-buffers
))))
4409 (defvar org-before-save-iCalendar-file-hook nil
4410 "Hook run before an iCalendar file has been saved.
4411 This can be used to modify the result of the export.")
4413 (defvar org-after-save-iCalendar-file-hook nil
4414 "Hook run after an iCalendar file has been saved.
4415 The iCalendar buffer is still current when this hook is run.
4416 A good way to use this is to tell a desktop calendar application to re-read
4417 the iCalendar file.")
4419 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4420 (defun org-print-icalendar-entries (&optional combine
)
4421 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4422 When COMBINE is non nil, add the category to each line."
4423 (require 'org-agenda
)
4424 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4425 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4426 (dts (org-ical-ts-to-string
4427 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4429 hd ts ts2 state status
(inc t
) pos b sexp rrule
4430 scheduledp deadlinep todo prefix due start
4431 tmp pri categories entry location summary desc uid
4432 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4433 (org-refresh-category-properties)
4435 (goto-char (point-min))
4436 (while (re-search-forward re1 nil t
)
4439 (when (boundp 'org-icalendar-verify-function
)
4440 (unless (funcall org-icalendar-verify-function
)
4441 (outline-next-heading)
4444 (setq pos
(match-beginning 0)
4447 hd
(condition-case nil
4448 (org-icalendar-cleanup-string
4450 (error (throw :skip nil
)))
4451 summary
(org-icalendar-cleanup-string
4452 (org-entry-get nil
"SUMMARY"))
4453 desc
(org-icalendar-cleanup-string
4454 (or (org-entry-get nil
"DESCRIPTION")
4455 (and org-icalendar-include-body
(org-get-entry)))
4456 t org-icalendar-include-body
)
4457 location
(org-icalendar-cleanup-string
4458 (org-entry-get nil
"LOCATION" 'selective
))
4459 uid
(if org-icalendar-store-UID
4461 (or (org-id-get) (org-id-new)))
4462 categories
(org-export-get-categories)
4463 deadlinep nil scheduledp nil
)
4464 (if (looking-at re2
)
4466 (goto-char (match-end 0))
4467 (setq ts2
(match-string 1)
4468 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4469 (setq tmp
(buffer-substring (max (point-min)
4470 (- pos org-ds-keyword-length
))
4472 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4475 (replace-match "\\1" t nil ts
))
4477 deadlinep
(string-match org-deadline-regexp tmp
)
4478 scheduledp
(string-match org-scheduled-regexp tmp
)
4479 todo
(org-get-todo-state)
4480 ;; donep (org-entry-is-done-p)
4485 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4486 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4491 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4492 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4494 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4495 (if (or (string-match org-tr-regexp hd
)
4496 (string-match org-ts-regexp hd
))
4497 (setq hd
(replace-match "" t t hd
)))
4498 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4500 (concat "\nRRULE:FREQ="
4503 '(("d" .
"DAILY")("w" .
"WEEKLY")
4504 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4505 ";INTERVAL=" (match-string 1 ts
)))
4507 (setq summary
(or summary hd
))
4508 (if (string-match org-bracket-link-regexp summary
)
4510 (replace-match (if (match-end 3)
4511 (match-string 3 summary
)
4512 (match-string 1 summary
))
4514 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4515 (if scheduledp
(setq summary
(concat "S: " summary
)))
4516 (if (string-match "\\`<%%" ts
)
4517 (with-current-buffer sexp-buffer
4518 (insert (substring ts
1 -
1) " " summary
"\n"))
4519 (princ (format "BEGIN:VEVENT
4527 (org-ical-ts-to-string ts
"DTSTART")
4528 (org-ical-ts-to-string ts2
"DTEND" inc
)
4530 (if (and desc
(string-match "\\S-" desc
))
4531 (concat "\nDESCRIPTION: " desc
) "")
4532 (if (and location
(string-match "\\S-" location
))
4533 (concat "\nLOCATION: " location
) "")
4535 (when (and org-icalendar-include-sexps
4536 (condition-case nil
(require 'icalendar
) (error nil
))
4537 (fboundp 'icalendar-export-region
))
4538 ;; Get all the literal sexps
4539 (goto-char (point-min))
4540 (while (re-search-forward "^&?%%(" nil t
)
4543 (setq b
(match-beginning 0))
4544 (goto-char (1- (match-end 0)))
4547 (setq sexp
(buffer-substring b
(point)))
4548 (with-current-buffer sexp-buffer
4549 (insert sexp
"\n"))))
4550 (princ (org-diary-to-ical-string sexp-buffer
))
4551 (kill-buffer sexp-buffer
))
4553 (when org-icalendar-include-todo
4554 (setq prefix
"TODO-")
4555 (goto-char (point-min))
4556 (while (re-search-forward org-todo-line-regexp nil t
)
4559 (when (boundp 'org-icalendar-verify-function
)
4560 (unless (funcall org-icalendar-verify-function
)
4561 (outline-next-heading)
4564 (setq state
(match-string 2))
4565 (setq status
(if (member state org-done-keywords
)
4566 "COMPLETED" "NEEDS-ACTION"))
4568 (or (not (member state org-done-keywords
))
4569 (eq org-icalendar-include-todo
'all
))
4570 (not (member org-archive-tag
(org-get-tags-at)))
4572 (setq hd
(match-string 3)
4573 summary
(org-icalendar-cleanup-string
4574 (org-entry-get nil
"SUMMARY"))
4575 desc
(org-icalendar-cleanup-string
4576 (or (org-entry-get nil
"DESCRIPTION")
4577 (and org-icalendar-include-body
(org-get-entry)))
4578 t org-icalendar-include-body
)
4579 location
(org-icalendar-cleanup-string
4580 (org-entry-get nil
"LOCATION" 'selective
))
4581 due
(and (member 'todo-due org-icalendar-use-deadline
)
4582 (org-entry-get nil
"DEADLINE"))
4583 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4584 (org-entry-get nil
"SCHEDULED"))
4585 categories
(org-export-get-categories)
4586 uid
(if org-icalendar-store-UID
4588 (or (org-id-get) (org-id-new))))
4589 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4590 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4592 (if (string-match org-bracket-link-regexp hd
)
4593 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4594 (match-string 1 hd
))
4596 (if (string-match org-priority-regexp hd
)
4597 (setq pri
(string-to-char (match-string 2 hd
))
4598 hd
(concat (substring hd
0 (match-beginning 1))
4599 (substring hd
(match-end 1))))
4600 (setq pri org-default-priority
))
4601 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4602 (- org-lowest-priority org-highest-priority
))))))
4604 (princ (format "BEGIN:VTODO
4616 (if (and location
(string-match "\\S-" location
))
4617 (concat "\nLOCATION: " location
) "")
4618 (if (and desc
(string-match "\\S-" desc
))
4619 (concat "\nDESCRIPTION: " desc
) "")
4620 (if due
(concat "\n" due
) "")
4624 (defun org-export-get-categories ()
4625 "Get categories according to `org-icalendar-categories'."
4626 (let ((cs org-icalendar-categories
) c rtn tmp
)
4627 (while (setq c
(pop cs
))
4629 ((eq c
'category
) (push (org-get-category) rtn
))
4631 (setq tmp
(org-get-todo-state))
4632 (and tmp
(push tmp rtn
)))
4634 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4636 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4637 (mapconcat 'identity
(nreverse rtn
) ",")))
4639 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4640 "Take out stuff and quote what needs to be quoted.
4641 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4642 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4647 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4648 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4649 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4650 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4652 (while (string-match "\\([,;]\\)" s start
)
4653 (setq start
(+ (match-beginning 0) 2)
4654 s
(replace-match "\\\\\\1" nil nil s
))))
4655 (setq s
(org-trim s
))
4657 (while (string-match "[ \t]*\n[ \t]*" s
)
4658 (setq s
(replace-match "\\n" t t s
))))
4661 (if (and (numberp maxlength
)
4662 (> (length s
) maxlength
))
4663 (setq s
(substring s
0 maxlength
)))))
4666 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4667 "Take out stuff and quote what needs to be quoted.
4668 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4669 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4671 This seems to be more like RFC 2455, but it causes problems, so it is
4672 not used right now."
4676 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4677 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4678 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4679 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4680 (setq s
(org-trim s
))
4681 (while (string-match "[ \t]*\n[ \t]*" s
)
4682 (setq s
(replace-match "\\n" t t s
)))
4684 (if (and (numberp maxlength
)
4685 (> (length s
) maxlength
))
4686 (setq s
(substring s
0 maxlength
)))))
4687 (setq s
(org-trim s
)))
4688 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4689 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
4692 (defun org-get-entry ()
4693 "Clean-up description string."
4695 (org-back-to-heading t
)
4696 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4698 (defun org-start-icalendar-file (name)
4699 "Start an iCalendar file by inserting the header."
4700 (let ((user user-full-name
)
4701 (name (or name
"unknown"))
4702 (timezone (cadr (current-time-zone))))
4704 (format "BEGIN:VCALENDAR
4707 PRODID:-//%s//Emacs with Org-mode//EN
4709 CALSCALE:GREGORIAN\n" name user timezone
))))
4711 (defun org-finish-icalendar-file ()
4712 "Finish an iCalendar file by inserting the END statement."
4713 (princ "END:VCALENDAR\n"))
4715 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4716 "Take a time string S and convert it to iCalendar format.
4717 KEYWORD is added in front, to make a complete line like DTSTART....
4718 When INC is non-nil, increase the hour by two (if time string contains
4719 a time), or the day by one (if it does not contain a time)."
4720 (let ((t1 (org-parse-time-string s
'nodefault
))
4721 t2 fmt have-time time
)
4722 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4723 (setq t2 t1 have-time t
)
4724 (setq t2
(org-parse-time-string s
)))
4725 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4726 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4729 (if org-agenda-default-appointment-duration
4730 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4733 (setq time
(encode-time s mi h d m y
)))
4734 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4735 (concat keyword
(format-time-string fmt time
))))
4739 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4740 (with-current-buffer buffer
4741 (apply 'insert output
)))
4742 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4745 (defun org-export-as-xoxo (&optional buffer
)
4746 "Export the org buffer as XOXO.
4747 The XOXO buffer is named *xoxo-<source buffer name>*"
4748 (interactive (list (current-buffer)))
4749 ;; A quickie abstraction
4751 ;; Output everything as XOXO
4752 (with-current-buffer (get-buffer buffer
)
4753 (let* ((pos (point))
4754 (opt-plist (org-combine-plists (org-default-export-plist)
4755 (org-infile-export-plist)))
4756 (filename (concat (file-name-as-directory
4757 (org-export-directory :xoxo opt-plist
))
4758 (file-name-sans-extension
4759 (file-name-nondirectory buffer-file-name
))
4761 (out (find-file-noselect filename
))
4764 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4765 ;; Check the output buffer is empty.
4766 (with-current-buffer out
(erase-buffer))
4767 ;; Kick off the output
4768 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4769 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4770 (let* ((hd (match-string-no-properties 1))
4773 (match-string-no-properties 2)
4775 (goto-char (match-end 0))
4780 (if (looking-at "^[ \t]\\(.*\\)")
4781 (setq str
(concat str
(match-string-no-properties 1)))
4782 (throw 'loop str
)))))))))
4784 ;; Handle level rendering
4786 ((> level last-level
)
4787 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4789 ((< level last-level
)
4790 (dotimes (- (- last-level level
) 1)
4792 (org-export-as-xoxo-insert-into out
"</li>\n"))
4793 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4795 (org-export-as-xoxo-insert-into out
"</li>\n")
4796 (setq hanging-li nil
)))
4798 ((equal level last-level
)
4800 (org-export-as-xoxo-insert-into out
"</li>\n")))
4803 (setq last-level level
)
4805 ;; And output the new li
4806 (setq hanging-li
't
)
4807 (if (equal ?
+ (elt text
0))
4808 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4809 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4811 ;; Finally finish off the ol
4812 (dotimes (- last-level
1)
4814 (org-export-as-xoxo-insert-into out
"</li>\n"))
4815 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4818 ;; Finish the buffer off and clean it up.
4819 (switch-to-buffer-other-window out
)
4820 (indent-region (point-min) (point-max) nil
)
4822 (goto-char (point-min))
4827 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4829 ;;; org-exp.el ends here