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 contition, 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 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
103 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
104 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fussnoten")
105 ("es" "Autor" "Fecha" "\xcdndice" "Notas al pie de la p\xe1gina")
106 ("fr" "Auteur" "Date" "Table des mati\xe8res" "Notes de bas de page")
107 ("it" "Autore" "Data" "Indice" "Note a pi\xe8 di pagina")
108 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
109 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
110 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
111 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
112 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll" "Fotnoter"))
113 "Terms used in export text, translated to different languages.
114 Use the variable `org-export-default-language' to set the language,
115 or use the +OPTION lines for a per-file setting."
116 :group
'org-export-general
119 (string :tag
"HTML language tag")
120 (string :tag
"Author")
122 (string :tag
"Table of Contents")
123 (string :tag
"Footnotes"))))
125 (defcustom org-export-default-language
"en"
126 "The default language of HTML export, as a string.
127 This should have an association in `org-export-language-setup'."
128 :group
'org-export-general
131 (defcustom org-export-skip-text-before-1st-heading nil
132 "Non-nil means, skip all text before the first headline when exporting.
133 When nil, that text is exported as well."
134 :group
'org-export-general
137 (defcustom org-export-headline-levels
3
138 "The last level which is still exported as a headline.
139 Inferior levels will produce itemize lists when exported.
140 Note that a numeric prefix argument to an exporter function overrides
143 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
144 :group
'org-export-general
147 (defcustom org-export-with-section-numbers t
148 "Non-nil means, add section numbers to headlines when exporting.
150 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
151 :group
'org-export-general
154 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
155 "Format of section numbers for export.
156 The variable has two components.
157 1. A list of lists, each indicating a counter type and a separator.
158 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
159 It causes causes numeric, alphabetic, or roman counters, respectively.
160 The separator is only used if another counter for a subsection is being
162 If there are more numbered section levels than entries in this lists,
163 then the last entry will be reused.
164 2. A terminator string that will be added after the entire
166 :group
'org-export-general
170 (string :tag
"Counter Type")
171 (string :tag
"Separator ")))
172 (string :tag
"Terminator")))
174 (defcustom org-export-with-toc t
175 "Non-nil means, create a table of contents in exported files.
176 The TOC contains headlines with levels up to`org-export-headline-levels'.
177 When an integer, include levels up to N in the toc, this may then be
178 different from `org-export-headline-levels', but it will not be allowed
179 to be larger than the number of headline levels.
180 When nil, no table of contents is made.
182 Headlines which contain any TODO items will be marked with \"(*)\" in
183 ASCII export, and with red color in HTML output, if the option
184 `org-export-mark-todo-in-toc' is set.
186 In HTML output, the TOC will be clickable.
188 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
190 :group
'org-export-general
192 (const :tag
"No Table of Contents" nil
)
193 (const :tag
"Full Table of Contents" t
)
194 (integer :tag
"TOC to level")))
196 (defcustom org-export-mark-todo-in-toc nil
197 "Non-nil means, mark TOC lines that contain any open TODO items."
198 :group
'org-export-general
201 (defcustom org-export-preserve-breaks nil
202 "Non-nil means, preserve all line breaks when exporting.
203 Normally, in HTML output paragraphs will be reformatted. In ASCII
204 export, line breaks will always be preserved, regardless of this variable.
206 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
207 :group
'org-export-general
210 (defcustom org-export-with-archived-trees
'headline
211 "Whether subtrees with the ARCHIVE tag should be exported.
212 This can have three different values
213 nil Do not export, pretend this tree is not present
214 t Do export the entire tree
215 headline Only export the headline, but skip the tree below it."
216 :group
'org-export-general
219 (const :tag
"not at all" nil
)
220 (const :tag
"headline only" 'headline
)
221 (const :tag
"entirely" t
)))
223 (defcustom org-export-author-info t
224 "Non-nil means, insert author name and email into the exported file.
226 This option can also be set with the +OPTIONS line,
227 e.g. \"author-info:nil\"."
228 :group
'org-export-general
231 (defcustom org-export-creator-info t
232 "Non-nil means, the postamle should contain a creator sentence.
233 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
234 :group
'org-export-general
237 (defcustom org-export-time-stamp-file t
238 "Non-nil means, insert a time stamp into the exported file.
239 The time stamp shows when the file was created.
241 This option can also be set with the +OPTIONS line,
242 e.g. \"timestamp:nil\"."
243 :group
'org-export-general
246 (defcustom org-export-with-timestamps t
247 "If nil, do not export time stamps and associated keywords."
248 :group
'org-export-general
251 (defcustom org-export-remove-timestamps-from-toc t
252 "If nil, remove timestamps from the table of contents entries."
253 :group
'org-export-general
256 (defcustom org-export-with-tags
'not-in-toc
257 "If nil, do not export tags, just remove them from headlines.
258 If this is the symbol `not-in-toc', tags will be removed from table of
259 contents entries, but still be shown in the headlines of the document.
261 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
262 :group
'org-export-general
264 (const :tag
"Off" nil
)
265 (const :tag
"Not in TOC" not-in-toc
)
266 (const :tag
"On" t
)))
268 (defcustom org-export-with-drawers nil
269 "Non-nil means, export with drawers like the property drawer.
270 When t, all drawers are exported. This may also be a list of
271 drawer names to export."
272 :group
'org-export-general
274 (const :tag
"All drawers" t
)
275 (const :tag
"None" nil
)
276 (repeat :tag
"Selected drawers"
277 (string :tag
"Drawer name"))))
279 (defvar org-export-preprocess-hook nil
280 "Hook for preprocessing an export buffer.
281 Pretty much the first thing when exporting is running this hook.")
283 (defgroup org-export-translation nil
284 "Options for translating special ascii sequences for the export backends."
285 :tag
"Org Export Translation"
288 (defcustom org-export-with-emphasize t
289 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
290 If the export target supports emphasizing text, the word will be
291 typeset in bold, italic, or underlined, respectively. Works only for
292 single words, but you can say: I *really* *mean* *this*.
293 Not all export backends support this.
295 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
296 :group
'org-export-translation
299 (defcustom org-export-with-footnotes t
300 "If nil, export [1] as a footnote marker.
301 Lines starting with [1] will be formatted as footnotes.
303 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
304 :group
'org-export-translation
307 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
308 <h2 class=\"footnotes\">%s: </h2>
309 <div id=\"footnotes-text\">
313 "Format for the footnotes section.
314 Should contain a two instances of %s. The first will be replaced with the
315 language-specific word for \"Footnotes\", the second one will be replaced
316 by the footnotes themselves."
317 :group
'org-export-html
320 (defcustom org-export-with-sub-superscripts t
321 "Non-nil means, interpret \"_\" and \"^\" for export.
322 When this option is turned on, you can use TeX-like syntax for sub- and
323 superscripts. Several characters after \"_\" or \"^\" will be
324 considered as a single item - so grouping with {} is normally not
325 needed. For example, the following things will be parsed as single
326 sub- or superscripts.
328 10^24 or 10^tau several digits will be considered 1 item.
329 10^-12 or 10^-tau a leading sign with digits or a word
330 x^2-y^3 will be read as x^2 - y^3, because items are
331 terminated by almost any nonword/nondigit char.
332 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
334 Still, ambiguity is possible - so when in doubt use {} to enclose the
335 sub/superscript. If you set this variable to the symbol `{}',
336 the braces are *required* in order to trigger interpretations as
337 sub/superscript. This can be helpful in documents that need \"_\"
338 frequently in plain text.
340 Not all export backends support this, but HTML does.
342 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
343 :group
'org-export-translation
345 (const :tag
"Always interpret" t
)
346 (const :tag
"Only with braces" {})
347 (const :tag
"Never interpret" nil
)))
349 (defcustom org-export-with-special-strings t
350 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
351 When this option is turned on, these strings will be exported as:
357 Not all export backends support this, but HTML does.
359 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
360 :group
'org-export-translation
363 (defcustom org-export-with-TeX-macros t
364 "Non-nil means, interpret simple TeX-like macros when exporting.
365 For example, HTML export converts \\alpha to α and \\AA to Å.
366 No only real TeX macros will work here, but the standard HTML entities
367 for math can be used as macro names as well. For a list of supported
368 names in HTML export, see the constant `org-html-entities'.
369 Not all export backends support this.
371 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
372 :group
'org-export-translation
373 :group
'org-export-latex
376 (defcustom org-export-with-LaTeX-fragments nil
377 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
378 When set, the exporter will find LaTeX environments if the \\begin line is
379 the first non-white thing on a line. It will also find the math delimiters
380 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
383 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
384 :group
'org-export-translation
385 :group
'org-export-latex
388 (defcustom org-export-with-fixed-width t
389 "Non-nil means, lines starting with \":\" will be in fixed width font.
390 This can be used to have pre-formatted text, fragments of code etc. For
392 : ;; Some Lisp examples
395 will be looking just like this in also HTML. See also the QUOTE keyword.
396 Not all export backends support this.
398 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
399 :group
'org-export-translation
402 (defcustom org-match-sexp-depth
3
403 "Number of stacked braces for sub/superscript matching.
404 This has to be set before loading org.el to be effective."
405 :group
'org-export-translation
408 (defgroup org-export-tables nil
409 "Options for exporting tables in Org-mode."
410 :tag
"Org Export Tables"
413 (defcustom org-export-with-tables t
414 "If non-nil, lines starting with \"|\" define a table.
417 | Name | Address | Birthday |
418 |-------------+----------+-----------|
419 | Arthur Dent | England | 29.2.2100 |
421 Not all export backends support this.
423 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
424 :group
'org-export-tables
427 (defcustom org-export-highlight-first-table-line t
428 "Non-nil means, highlight the first table line.
429 In HTML export, this means use <th> instead of <td>.
430 In tables created with table.el, this applies to the first table line.
431 In Org-mode tables, all lines before the first horizontal separator
432 line will be formatted with <th> tags."
433 :group
'org-export-tables
436 (defcustom org-export-table-remove-special-lines t
437 "Remove special lines and marking characters in calculating tables.
438 This removes the special marking character column from tables that are set
439 up for spreadsheet calculations. It also removes the entire lines
440 marked with `!', `_', or `^'. The lines with `$' are kept, because
441 the values of constants may be useful to have."
442 :group
'org-export-tables
445 (defcustom org-export-prefer-native-exporter-for-tables nil
446 "Non-nil means, always export tables created with table.el natively.
447 Natively means, use the HTML code generator in table.el.
448 When nil, Org-mode's own HTML generator is used when possible (i.e. if
449 the table does not use row- or column-spanning). This has the
450 advantage, that the automatic HTML conversions for math symbols and
451 sub/superscripts can be applied. Org-mode's HTML generator is also
453 :group
'org-export-tables
456 (defgroup org-export-ascii nil
457 "Options specific for ASCII export of Org-mode files."
458 :tag
"Org Export ASCII"
461 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
462 "Characters for underlining headings in ASCII export.
463 In the given sequence, these characters will be used for level 1, 2, ..."
464 :group
'org-export-ascii
465 :type
'(repeat character
))
467 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
468 "Bullet characters for headlines converted to lists in ASCII export.
469 The first character is used for the first lest level generated in this
470 way, and so on. If there are more levels than characters given here,
471 the list will be repeated.
472 Note that plain lists will keep the same bullets as the have in the
474 :group
'org-export-ascii
475 :type
'(repeat character
))
477 (defgroup org-export-xml nil
478 "Options specific for XML export of Org-mode files."
479 :tag
"Org Export XML"
482 (defgroup org-export-html nil
483 "Options specific for HTML export of Org-mode files."
484 :tag
"Org Export HTML"
487 (defcustom org-export-html-coding-system nil
488 "Coding system for HTML export, defaults to buffer-file-coding-system."
489 :group
'org-export-html
490 :type
'coding-system
)
492 (defcustom org-export-html-extension
"html"
493 "The extension for exported HTML files."
494 :group
'org-export-html
497 (defcustom org-export-html-link-up
""
498 "Where should the \"UP\" link of exported HTML pages lead?"
499 :group
'org-export-html
500 :type
'(string :tag
"File or URL"))
502 (defcustom org-export-html-link-home
""
503 "Where should the \"HOME\" link of exported HTML pages lead?"
504 :group
'org-export-html
505 :type
'(string :tag
"File or URL"))
507 (defconst org-export-html-style-default
508 "<style type=\"text/css\">
510 html { font-family: Times, serif; font-size: 12pt; }
511 .title { text-align: center; }
512 .todo { color: red; }
513 .done { color: green; }
514 .tag { background-color:lightblue; font-weight:normal }
516 .timestamp { color: grey }
517 .timestamp-kwd { color: CadetBlue }
518 p.verse { margin-left: 3% }
520 border: 1pt solid #AEBDCC;
521 background-color: #F3F5F7;
523 font-family: courier, monospace;
527 table { border-collapse: collapse; }
528 td, th { vertical-align: top; }
529 dt { font-weight: bold; }
531 .org-info-js_info-navigation { border-style:none; }
532 #org-info-js_console-label { font-size:10px; font-weight:bold;
533 white-space:nowrap; }
534 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
538 "The default style specification for exported HTML files.
539 Please use the variables `org-export-html-style' and
540 `org-export-html-style-extra' to add to this style. If you wish to not
541 have the default style included, customize the variable
542 `org-export-html-style-include-default'.")
544 (defcustom org-export-html-style-include-default t
545 "Non-nil means, include the default style in exported HTML files.
546 The actualy style is defined in `org-export-html-style-default' and should
547 not be modified. Use the variables `org-export-html-style' to add
548 your own style information."
549 :group
'org-export-html
552 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
554 (defcustom org-export-html-style
""
555 "Org-wide style definitions for exported HTML files.
557 This variable needs to contain the full HTML structure to provide a style,
558 including the surrounding HTML tags. If you set the value of this variable,
559 you should consider to include definitions for the following classes:
560 title, todo, done, timestamp, timestamp-kwd, tag, target.
562 For example, a valid value would be:
564 <style type=\"text/css\">
566 p { font-weight: normal; color: gray; }
568 .title { text-align: center; }
569 .todo, .timestamp-kwd { color: red; }
570 .done { color: green; }
574 If you'd like to refer to en external style file, use something like
576 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
578 As the value of this option simply gets inserted into the HTML <head> header,
579 you can \"misuse\" it to add arbitrary text to the header.
580 See also the variable `org-export-html-style-extra'."
581 :group
'org-export-html
584 (put 'org-export-html-style
'safe-local-variable
'stringp
)
586 (defcustom org-export-html-style-extra
""
587 "Additional style information for HTML export.
588 The value of this variable is inserted into the HTML buffer right after
589 the value of `org-export-html-style'. Use this variable for per-file
590 settings of style information, and do not forget to surround the style
591 settings with <style>...</style> tags."
592 :group
'org-export-html
595 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
598 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
599 "Format for typesetting the document title in HTML export."
600 :group
'org-export-html
603 (defcustom org-export-html-toplevel-hlevel
2
604 "The <H> level for level 1 headings in HTML export."
605 :group
'org-export-html
608 (defcustom org-export-html-link-org-files-as-html t
609 "Non-nil means, make file links to `file.org' point to `file.html'.
610 When org-mode is exporting an org-mode file to HTML, links to
611 non-html files are directly put into a href tag in HTML.
612 However, links to other Org-mode files (recognized by the
613 extension `.org.) should become links to the corresponding html
614 file, assuming that the linked org-mode file will also be
616 When nil, the links still point to the plain `.org' file."
617 :group
'org-export-html
620 (defcustom org-export-html-inline-images
'maybe
621 "Non-nil means, inline images into exported HTML pages.
622 This is done using an <img> tag. When nil, an anchor with href is used to
623 link to the image. If this option is `maybe', then images in links with
624 an empty description will be inlined, while images with a description will
626 :group
'org-export-html
627 :type
'(choice (const :tag
"Never" nil
)
628 (const :tag
"Always" t
)
629 (const :tag
"When there is no description" maybe
)))
632 (defcustom org-export-html-expand t
633 "Non-nil means, for HTML export, treat @<...> as HTML tag.
634 When nil, these tags will be exported as plain text and therefore
635 not be interpreted by a browser.
637 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
638 :group
'org-export-html
641 (defcustom org-export-html-table-tag
642 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
643 "The HTML tag that is used to start a table.
644 This must be a <table> tag, but you may change the options like
645 borders and spacing."
646 :group
'org-export-html
649 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
650 "The opening tag for table header fields.
651 This is customizable so that alignment options can be specified."
652 :group
'org-export-tables
653 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
655 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
656 "The opening tag for table data fields.
657 This is customizable so that alignment options can be specified."
658 :group
'org-export-tables
659 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
661 (defcustom org-export-html-with-timestamp nil
662 "If non-nil, write `org-export-html-html-helper-timestamp'
663 into the exported HTML text. Otherwise, the buffer will just be saved
665 :group
'org-export-html
668 (defcustom org-export-html-html-helper-timestamp
669 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
670 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
671 :group
'org-export-html
674 (defgroup org-export-htmlize nil
675 "Options for processing examples with htmlize.el."
676 :tag
"Org Export Htmlize"
677 :group
'org-export-html
)
679 (defcustom org-export-htmlize-output-type
'inline-css
680 "Output type to be used by htmlize when formatting code snippets.
681 Normally this is `inline-css', but if you have defined to appropriate
682 classes in your css style file, setting this to `css' means that the
683 fontification will use the class names.
684 See also the function `org-export-htmlize-generate-css'."
685 :group
'org-export-htmlize
686 :type
'(choice (const css
) (const inline-css
)))
688 (defcustom org-export-htmlize-css-font-prefix
"org-"
689 "The prefix for CSS class names for htmlize font specifications."
690 :group
'org-export-htmlize
693 (defgroup org-export-icalendar nil
694 "Options specific for iCalendar export of Org-mode files."
695 :tag
"Org Export iCalendar"
698 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
699 "The file name for the iCalendar file covering all agenda files.
700 This file is created with the command \\[org-export-icalendar-all-agenda-files].
701 The file name should be absolute, the file will be overwritten without warning."
702 :group
'org-export-icalendar
705 (defcustom org-icalendar-combined-name
"OrgMode"
706 "Calendar name for the combined iCalendar representing all agenda files."
707 :group
'org-export-icalendar
710 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
711 "Contexts where iCalendar export should use a deadline time stamp.
712 This is a list with several symbols in it. Valid symbol are:
714 event-if-todo Deadlines in TODO entries become calendar events.
715 event-if-not-todo Deadlines in non-TODO entries become calendar events.
716 todo-due Use deadlines in TODO entries as due-dates"
717 :group
'org-export-icalendar
718 :type
'(set :greedy t
719 (const :tag
"Deadlines in non-TODO entries become events"
721 (const :tag
"Deadline in TODO entries become events"
723 (const :tag
"Deadlines in TODO entries become due-dates"
726 (defcustom org-icalendar-use-scheduled
'(todo-start)
727 "Contexts where iCalendar export should use a scheduling time stamp.
728 This is a list with several symbols in it. Valid symbol are:
730 event-if-todo Scheduling time stamps in TODO entries become an event.
731 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
732 todo-start Scheduling time stamps in TODO entries become start date.
733 Some calendar applications show TODO entries only after
735 :group
'org-export-icalendar
736 :type
'(set :greedy t
738 "SCHEDULED timestamps in non-TODO entries become events"
740 (const :tag
"SCHEDULED timestamps in TODO entries become events"
742 (const :tag
"SCHEDULED in TODO entries become start date"
745 (defcustom org-icalendar-categories
'(local-tags category
)
746 "Items that should be entered into the categories field.
747 This is a list of symbols, the following are valid:
749 category The Org-mode category of the current file or tree
750 todo-state The todo state, if any
751 local-tags The tags, defined in the current line
752 all-tags All tags, including inherited ones."
753 :group
'org-export-icalendar
756 (const :tag
"The file or tree category" category
)
757 (const :tag
"The TODO state" todo-state
)
758 (const :tag
"Tags defined in current line" local-tags
)
759 (const :tag
"All tags, including inherited ones" all-tags
))))
761 (defcustom org-icalendar-include-todo nil
762 "Non-nil means, export to iCalendar files should also cover TODO items."
763 :group
'org-export-icalendar
765 (const :tag
"None" nil
)
766 (const :tag
"Unfinished" t
)
767 (const :tag
"All" all
)))
769 (defcustom org-icalendar-include-sexps t
770 "Non-nil means, export to iCalendar files should also cover sexp entries.
771 These are entries like in the diary, but directly in an Org-mode file."
772 :group
'org-export-icalendar
775 (defcustom org-icalendar-include-body
100
776 "Amount of text below headline to be included in iCalendar export.
777 This is a number of characters that should maximally be included.
778 Properties, scheduling and clocking lines will always be removed.
779 The text will be inserted into the DESCRIPTION field."
780 :group
'org-export-icalendar
782 (const :tag
"Nothing" nil
)
783 (const :tag
"Everything" t
)
784 (integer :tag
"Max characters")))
786 (defcustom org-icalendar-store-UID nil
787 "Non-nil means, store any created UIDs in properties.
788 The iCalendar standard requires that all entries have a unique identifyer.
789 Org will create these identifiers as needed. When this variable is non-nil,
790 the created UIDs will be stored in the ID property of the entry. Then the
791 next time this entry is exported, it will be exported with the same UID,
792 superceeding the previous form of it. This is essential for
793 synchronization services.
794 This variable is not turned on by default because we want to avoid creating
795 a property drawer in every entry if people are only playing with this feature,
796 or if they are only using it locally."
797 :group
'org-export-icalendar
802 ;;; Variables, constants, and parameter plists
804 (defconst org-level-max
20)
806 (defvar org-export-html-preamble nil
807 "Preamble, to be inserted just before <body>. Set by publishing functions.")
808 (defvar org-export-html-postamble nil
809 "Preamble, to be inserted just after </body>. Set by publishing functions.")
810 (defvar org-export-html-auto-preamble t
811 "Should default preamble be inserted? Set by publishing functions.")
812 (defvar org-export-html-auto-postamble t
813 "Should default postamble be inserted? Set by publishing functions.")
814 (defvar org-current-export-file nil
) ; dynamically scoped parameter
815 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
817 (defconst org-export-plist-vars
818 '((:link-up . org-export-html-link-up
)
819 (:link-home . org-export-html-link-home
)
820 (:language . org-export-default-language
)
821 (:customtime . org-display-custom-times
)
822 (:headline-levels . org-export-headline-levels
)
823 (:section-numbers . org-export-with-section-numbers
)
824 (:section-number-format . org-export-section-number-format
)
825 (:table-of-contents . org-export-with-toc
)
826 (:preserve-breaks . org-export-preserve-breaks
)
827 (:archived-trees . org-export-with-archived-trees
)
828 (:emphasize . org-export-with-emphasize
)
829 (:sub-superscript . org-export-with-sub-superscripts
)
830 (:special-strings . org-export-with-special-strings
)
831 (:footnotes . org-export-with-footnotes
)
832 (:drawers . org-export-with-drawers
)
833 (:tags . org-export-with-tags
)
834 (:TeX-macros . org-export-with-TeX-macros
)
835 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
836 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
837 (:fixed-width . org-export-with-fixed-width
)
838 (:timestamps . org-export-with-timestamps
)
839 (:author-info . org-export-author-info
)
840 (:creator-info . org-export-creator-info
)
841 (:time-stamp-file . org-export-time-stamp-file
)
842 (:tables . org-export-with-tables
)
843 (:table-auto-headline . org-export-highlight-first-table-line
)
844 (:style-include-default . org-export-html-style-include-default
)
845 (:style . org-export-html-style
)
846 (:style-extra . org-export-html-style-extra
)
847 (:agenda-style . org-agenda-export-html-style
)
848 (:convert-org-links . org-export-html-link-org-files-as-html
)
849 (:inline-images . org-export-html-inline-images
)
850 (:html-extension . org-export-html-extension
)
851 (:html-table-tag . org-export-html-table-tag
)
852 (:expand-quoted-html . org-export-html-expand
)
853 (:timestamp . org-export-html-with-timestamp
)
854 (:publishing-directory . org-export-publishing-directory
)
855 (:preamble . org-export-html-preamble
)
856 (:postamble . org-export-html-postamble
)
857 (:auto-preamble . org-export-html-auto-preamble
)
858 (:auto-postamble . org-export-html-auto-postamble
)
859 (:author . user-full-name
)
860 (:email . user-mail-address
)
861 (:select-tags . org-export-select-tags
)
862 (:exclude-tags . org-export-exclude-tags
)))
864 (defun org-default-export-plist ()
865 "Return the property list with default settings for the export variables."
866 (let ((l org-export-plist-vars
) rtn e
)
867 (while (setq e
(pop l
))
868 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
871 (defvar org-export-inbuffer-options-extra nil
872 "List of additional in-buffer options that should be detected.
873 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
874 etc. Extensions can add to this list to get their options detected, and they
875 can then add a function to `org-export-options-filters' to process these
877 Each element in this list must be a list, with the in-buffer keyword as car,
878 and a property (a symbol) as the next element. All occurences of the
879 keyword will be found, the values concatenated with a space character
880 in between, and the result stored in the export options property list.")
882 (defvar org-export-options-filters nil
883 "Functions to be called to finalize the export/publishing options.
884 All these options are stored in a property list, and each of the functions
885 in this hook gets a chance to modify this property list. Each function
886 must accept the property list as an argument, and must return the (possibly
889 ;; FIXME: should we fold case here?
890 (defun org-infile-export-plist ()
891 "Return the property list with file-local settings for export."
895 (goto-char (point-min))
896 (let ((re (org-make-options-regexp
898 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
899 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
900 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
901 (mapcar 'car org-export-inbuffer-options-extra
))))
902 p key val text options js-up js-main js-css js-opt a pr style
904 ext-setup-or-nil setup-contents
(start 0))
905 (while (or (and ext-setup-or-nil
906 (string-match re ext-setup-or-nil start
)
907 (setq start
(match-end 0)))
908 (and (setq ext-setup-or-nil nil start
0)
909 (re-search-forward re nil t
)))
910 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
911 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
913 ((setq a
(assoc key org-export-inbuffer-options-extra
))
915 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
916 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
917 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
918 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
919 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
920 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
921 ((string-equal key
"STYLE")
922 (setq style
(concat style
"\n" val
)))
923 ((string-equal key
"LATEX_HEADER")
924 (setq latex-header
(concat latex-header
"\n" val
)))
925 ((string-equal key
"TEXT")
926 (setq text
(if text
(concat text
"\n" val
) val
)))
927 ((string-equal key
"OPTIONS")
928 (setq options
(concat val
" " options
)))
929 ((string-equal key
"LINK_UP")
930 (setq p
(plist-put p
:link-up val
)))
931 ((string-equal key
"LINK_HOME")
932 (setq p
(plist-put p
:link-home val
)))
933 ((string-equal key
"EXPORT_SELECT_TAGS")
934 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
935 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
936 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
937 ((equal key
"SETUPFILE")
938 (setq setup-contents
(org-file-contents
940 (org-remove-double-quotes
943 (if (not ext-setup-or-nil
)
944 (setq ext-setup-or-nil setup-contents start
0)
945 (setq ext-setup-or-nil
946 (concat (substring ext-setup-or-nil
0 start
)
947 "\n" setup-contents
"\n"
948 (substring ext-setup-or-nil start
)))))))
949 (setq p
(plist-put p
:text text
))
950 (when style
(setq p
(plist-put p
:style-extra style
)))
952 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
954 (setq p
(org-export-add-options-to-plist p options
)))
957 (defun org-export-add-options-to-plist (p options
)
958 "Parse an OPTONS line and set values in the property list P."
961 (let ((op '(("H" .
:headline-levels
)
962 ("num" .
:section-numbers
)
963 ("toc" .
:table-of-contents
)
964 ("\\n" .
:preserve-breaks
)
965 ("@" .
:expand-quoted-html
)
968 ("^" .
:sub-superscript
)
969 ("-" .
:special-strings
)
974 ("TeX" .
:TeX-macros
)
975 ("LaTeX" .
:LaTeX-fragments
)
976 ("skip" .
:skip-before-1st-heading
)
977 ("author" .
:author-info
)
978 ("creator" .
:creator-info
)
979 ("timestamp" .
:time-stamp-file
)))
981 (while (setq o
(pop op
))
982 (if (string-match (concat (regexp-quote (car o
))
983 ":\\([^ \t\n\r;,.]*\\)")
985 (setq p
(plist-put p
(cdr o
)
986 (car (read-from-string
987 (match-string 1 options
))))))))))
990 (defun org-export-add-subtree-options (p pos
)
991 "Add options in subtree at position POS to property list P."
994 (when (org-at-heading-p)
996 ;; This is actually read in `org-export-get-title-from-subtree'
997 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
998 ;; (setq p (plist-put p :title a)))
999 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1000 (setq p
(plist-put p
:text a
)))
1001 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1002 (setq p
(org-export-add-options-to-plist p a
)))))
1005 (defun org-export-directory (type plist
)
1006 (let* ((val (plist-get plist
:publishing-directory
))
1007 (dir (if (listp val
)
1008 (or (cdr (assoc type val
)) ".")
1012 (defun org-export-process-option-filters (plist)
1013 (let ((functions org-export-options-filters
) f
)
1014 (while (setq f
(pop functions
))
1015 (setq plist
(funcall f plist
))))
1019 (defun org-export (&optional arg
)
1020 "Export dispatcher for Org-mode.
1021 When `org-export-run-in-background' is non-nil, try to run the command
1022 in the background. This will be done only for commands that write
1023 to a file. For details see the docstring of `org-export-run-in-background'.
1025 The prefix argument ARG will be passed to the exporter. However, if
1026 ARG is a double universal prefix `C-u C-u', that means to inverse the
1027 value of `org-export-run-in-background'."
1029 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1030 (help "[t] insert the export option template
1031 \[v] limit export to visible part of outline tree
1033 \[a] export as ASCII
1036 \[H] export as HTML to temporary buffer
1037 \[R] export region as HTML
1038 \[b] export as HTML and browse immediately
1041 \[l] export as LaTeX
1042 \[p] export as LaTeX and process to PDF
1043 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1044 \[L] export as LaTeX to temporary buffer
1046 \[i] export current file as iCalendar file
1047 \[I] export all agenda files as iCalendar files
1048 \[c] export agenda files into combined iCalendar file
1050 \[F] publish current file
1051 \[P] publish current project
1052 \[X] publish... (project will be prompted for)
1053 \[A] publish all projects")
1055 '((?t org-insert-export-options-template nil
)
1056 (?v org-export-visible nil
)
1057 (?a org-export-as-ascii t
)
1058 (?h org-export-as-html t
)
1059 (?b org-export-as-html-and-open t
)
1060 (?H org-export-as-html-to-buffer nil
)
1061 (?R org-export-region-as-html nil
)
1062 (?x org-export-as-xoxo t
)
1063 (?l org-export-as-latex t
)
1064 (?p org-export-as-pdf t
)
1065 (?d org-export-as-pdf-and-open t
)
1066 (?L org-export-as-latex-to-buffer nil
)
1067 (?i org-export-icalendar-this-file t
)
1068 (?I org-export-icalendar-all-agenda-files t
)
1069 (?c org-export-icalendar-combine-agenda-files t
)
1070 (?F org-publish-current-file t
)
1071 (?P org-publish-current-project t
)
1073 (?A org-publish-all t
)))
1075 (save-window-excursion
1076 (delete-other-windows)
1077 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1079 (org-fit-window-to-buffer (get-buffer-window
1080 "*Org Export/Publishing Help*"))
1081 (message "Select command: ")
1082 (setq r1
(read-char-exclusive)))
1083 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1084 (unless (setq ass
(assq r2 cmds
))
1085 (error "No command associated with key %c" r1
))
1086 (if (and bg
(nth 2 ass
)
1087 (not (buffer-base-buffer))
1088 (not (org-region-active-p)))
1089 ;; execute in background
1090 (let ((p (start-process
1091 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1093 (expand-file-name invocation-name invocation-directory
)
1096 "--eval" "(require 'org-exp)"
1097 "--eval" "(setq org-wait .2)"
1099 "-f" (symbol-name (nth 1 ass
)))))
1100 (set-process-sentinel p
'org-export-process-sentinel
)
1101 (message "Background process \"%s\": started" p
))
1102 ;; background processing not requested, or not possible
1103 (call-interactively (nth 1 ass
)))))
1105 (defun org-export-process-sentinel (process status
)
1106 (if (string-match "\n+\\'" status
)
1107 (setq status
(substring status
0 -
1)))
1108 (message "Background process \"%s\": %s" process status
))
1110 (defconst org-html-entities
1151 ("Aring") ("AA".
"Å")
1240 ("varepsilon".
"ε")
1253 ("sigmaf") ("varsigma".
"ς")
1261 ("thetasym") ("vartheta".
"ϑ")
1264 ("bull") ("bullet".
"•")
1265 ("hellip") ("dots".
"…")
1275 ("larr") ("leftarrow".
"←") ("gets".
"←")
1276 ("uarr") ("uparrow".
"↑")
1277 ("rarr") ("to".
"→") ("rightarrow".
"→")
1278 ("darr")("downarrow".
"↓")
1279 ("harr") ("leftrightarrow".
"↔")
1280 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1281 ("lArr") ("Leftarrow".
"⇐")
1282 ("uArr") ("Uparrow".
"⇑")
1283 ("rArr") ("Rightarrow".
"⇒")
1284 ("dArr") ("Downarrow".
"⇓")
1285 ("hArr") ("Leftrightarrow".
"⇔")
1287 ("part") ("partial".
"∂")
1288 ("exist") ("exists".
"∃")
1289 ("empty") ("emptyset".
"∅")
1291 ("isin") ("in".
"∈")
1297 ("lowast") ("ast".
"∗")
1299 ("prop") ("proptp".
"∝")
1300 ("infin") ("infty".
"∞")
1301 ("ang") ("angle".
"∠")
1302 ("and") ("wedge".
"∧")
1303 ("or") ("vee".
"∨")
1309 ("cong") ("simeq".
"≅")
1310 ("asymp")("approx".
"≈")
1311 ("ne") ("neq".
"≠")
1315 ("sub") ("subset".
"⊂")
1316 ("sup") ("supset".
"⊃")
1323 ("sdot") ("cdot".
"⋅")
1330 ("loz") ("Diamond".
"◊")
1331 ("spades") ("spadesuit".
"♠")
1332 ("clubs") ("clubsuit".
"♣")
1333 ("hearts") ("diamondsuit".
"♥")
1334 ("diams") ("diamondsuit".
"♦")
1335 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1402 "Entities for TeX->HTML translation.
1403 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1404 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1405 In that case, \"\\ent\" will be translated to \"&other;\".
1406 The list contains HTML entities for Latin-1, Greek and other symbols.
1407 It is supplemented by a number of commonly used TeX macros with appropriate
1408 translations. There is currently no way for users to extend this.")
1410 ;;; General functions for all backends
1412 (defun org-export-preprocess-string (string &rest parameters
)
1413 "Cleanup STRING so that that the true exported has a more consistent source.
1414 This function takes STRING, which should be a buffer-string of an org-file
1415 to export. It then creates a temporary buffer where it does its job.
1416 The result is then again returned as a string, and the exporter works
1417 on this string to produce the exported version."
1419 (let* ((htmlp (plist-get parameters
:for-html
))
1420 (asciip (plist-get parameters
:for-ascii
))
1421 (latexp (plist-get parameters
:for-LaTeX
))
1422 (archived-trees (plist-get parameters
:archived-trees
))
1423 (inhibit-read-only t
)
1424 (drawers org-drawers
)
1425 (outline-regexp "\\*+ ")
1428 (with-current-buffer (get-buffer-create " org-mode-tmp")
1431 (setq case-fold-search t
)
1433 (run-hooks 'org-export-preprocess-hook
)
1435 ;; Remove license-to-kill stuff
1436 ;; The caller markes some stuff fo killing, stuff that has been
1437 ;; used to create the page title, for example.
1438 (org-export-kill-licensed-text)
1440 (let ((org-inhibit-startup t
)) (org-mode))
1441 (setq case-fold-search t
)
1442 (untabify (point-min) (point-max))
1444 ;; Handle include files
1445 (org-export-handle-include-files)
1447 ;; Get rid of excluded trees
1448 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1449 (plist-get parameters
:exclude-tags
))
1451 ;; Handle source code snippets
1452 (org-export-replace-src-segments)
1454 ;; Get rid of drawers
1455 (org-export-remove-or-extract-drawers drawers
1456 (plist-get parameters
:drawers
))
1458 ;; Get the correct stuff before the first headline
1459 (when (plist-get parameters
:skip-before-1st-heading
)
1460 (goto-char (point-min))
1461 (when (re-search-forward "^\\*+[ \t]" nil t
)
1462 (delete-region (point-min) (match-beginning 0))
1463 (goto-char (point-min))
1465 (when (plist-get parameters
:add-text
)
1466 (goto-char (point-min))
1467 (insert (plist-get parameters
:add-text
) "\n"))
1469 ;; Get rid of archived trees
1470 (org-export-remove-archived-trees archived-trees
)
1472 ;; Find all headings and compute the targets for them
1473 (setq target-alist
(org-export-define-heading-targets target-alist
))
1475 ;; Find targets in comments and move them out of comments,
1476 ;; but mark them as targets that should be invisible
1477 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1480 (org-export-protect-examples (if asciip
'indent nil
))
1482 ;; Protect backend specific stuff, throw away the others.
1483 (org-export-select-backend-specific-text
1484 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1486 ;; Protect quoted subtrees
1487 (org-export-protect-quoted-subtrees)
1489 ;; Protect verbatim elements
1490 (org-export-protect-verbatim)
1492 ;; Blockquotes and verse
1493 (org-export-mark-blockquote-and-verse)
1495 ;; Remove comment environment and comment subtrees
1496 (org-export-remove-comment-blocks-and-subtrees)
1499 ;; Find matches for radio targets and turn them into internal links
1500 (org-export-mark-radio-links)
1502 ;; Find all links that contain a newline and put them into a single line
1503 (org-export-concatenate-multiline-links)
1505 ;; Normalize links: Convert angle and plain links into bracket links
1506 ;; and expand link abbreviations
1507 (org-export-normalize-links)
1509 ;; Find all internal links. If they have a fuzzy match (i.e. not
1510 ;; a *dedicated* target match, let the link point to the
1511 ;; corresponding section.
1512 (org-export-target-internal-links target-alist
)
1514 ;; Find multiline emphasis and put them into single line
1515 (when (plist-get parameters
:emph-multiline
)
1516 (org-export-concatenate-multiline-emphasis))
1518 ;; Remove special table lines
1519 (when org-export-table-remove-special-lines
1520 (org-export-remove-special-table-lines))
1522 ;; Specific LaTeX stuff
1524 (require 'org-export-latex nil
)
1525 (org-export-latex-preprocess))
1527 ;; Specific ASCII stuff
1529 (org-export-ascii-preprocess))
1531 ;; Specific HTML stuff
1533 (org-export-html-preprocess parameters
))
1535 ;; Remove or replace comments
1536 (org-export-handle-comments (plist-get parameters
:comments
))
1538 (setq rtn
(buffer-string)))
1539 (kill-buffer " org-mode-tmp")
1542 (defun org-export-kill-licensed-text ()
1543 "Remove all text that is marked with a :org-license-to-kill property."
1545 (while (setq p
(text-property-any (point-min) (point-max)
1546 :org-license-to-kill t
))
1548 p
(or (next-single-property-change p
:org-license-to-kill
)
1551 (defun org-export-define-heading-targets (target-alist)
1552 "Find all headings and define the targets for them.
1553 The new targets are added to TARGET-ALIST, which is also returned."
1554 (goto-char (point-min))
1555 (org-init-section-numbers)
1556 (let ((re (concat "^" org-outline-regexp
))
1558 (while (re-search-forward re nil t
)
1559 (setq level
(org-reduced-level
1560 (save-excursion (goto-char (point-at-bol))
1561 (org-outline-level))))
1562 (setq target
(org-solidify-link-text
1563 (format "sec-%s" (org-section-number level
))))
1564 (push (cons target target
) target-alist
)
1565 (add-text-properties
1566 (point-at-bol) (point-at-eol)
1567 (list 'target target
))))
1570 (defun org-export-handle-invisible-targets (target-alist)
1571 "Find targets in comments and move them out of comments.
1572 Mark them as invisible targets."
1574 (goto-char (point-min))
1575 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1576 ;; Check if the line before or after is a headline with a target
1577 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1578 (get-text-property (point-at-bol 2) 'target
)))
1580 ;; use the existing target in a neighboring line
1581 (setq tmp
(match-string 2))
1583 (and (looking-at "\n") (delete-char 1))
1584 (push (cons (org-solidify-link-text tmp
) target
)
1586 ;; Make an invisible target
1587 (replace-match "\\1(INVISIBLE)"))))
1590 (defun org-export-target-internal-links (target-alist)
1591 "Find all internal links and assign target to them.
1592 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1593 let the link point to the corresponding section."
1594 (goto-char (point-min))
1595 (while (re-search-forward org-bracket-link-regexp nil t
)
1597 (let* ((md (match-data))
1598 (desc (match-end 2))
1599 (link (org-link-unescape (match-string 1)))
1600 (slink (org-solidify-link-text link
))
1604 ((cdr (assoc slink target-alist
)))
1605 ((string-match org-link-types-re link
) nil
)
1606 ((or (file-name-absolute-p link
)
1607 (string-match "^\\." link
))
1611 (setq found
(condition-case nil
(org-link-search link
)
1614 (or (org-on-heading-p)
1615 (not (eq found
'dedicated
))))
1616 (or (get-text-property (point) 'target
)
1619 (1- (previous-single-property-change
1624 (goto-char (match-beginning 1))
1625 (setq props
(text-properties-at (point)))
1626 (delete-region (match-beginning 1) (match-end 1))
1629 (unless desc
(insert "][" link
))
1630 (add-text-properties pos
(point) props
))))))
1632 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1633 "Remove drawers, or extract the content.
1634 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1635 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1636 whose content to keep."
1637 (unless (eq t exp-drawers
)
1638 (goto-char (point-min))
1639 (let ((re (concat "^[ \t]*:\\("
1642 (org-delete-all exp-drawers
1643 (copy-sequence all-drawers
))
1645 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1646 (while (re-search-forward re nil t
)
1647 (replace-match "")))))
1649 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1650 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1651 Both arguments are lists of tags.
1652 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1654 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1656 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1657 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1660 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1664 (goto-char (point-min))
1665 (when (and select-tags
1667 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1668 ;; At least one tree is marked for export, this means
1669 ;; all the unmarked stuff needs to go.
1670 ;; Dig out the trees that should be exported
1671 (goto-char (point-min))
1672 (outline-next-heading)
1674 (put-text-property beg
(point-max) :org-delete t
)
1675 (while (re-search-forward re-sel nil t
)
1676 (when (org-on-heading-p)
1677 (org-back-to-heading)
1678 (remove-text-properties
1679 (max (1- (point)) (point-min))
1680 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1682 (while (and (org-up-heading-safe)
1683 (get-text-property (point) :org-delete
))
1684 (remove-text-properties (max (1- (point)) (point-min))
1685 (point-at-eol) '(:org-delete t
)))
1687 ;; Remove the trees explicitly marked for noexport
1689 (goto-char (point-min))
1690 (while (re-search-forward re-excl nil t
)
1691 (when (org-at-heading-p)
1692 (org-back-to-heading t
)
1694 (org-end-of-subtree t
)
1695 (delete-region beg
(point)))))
1696 ;; Remove everything that is now still marked for deletion
1697 (goto-char (point-min))
1698 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1699 (setq end
(or (next-single-property-change beg
:org-delete
)
1701 (delete-region beg end
))))
1703 (defun org-export-remove-archived-trees (export-archived-trees)
1704 "Remove archived trees.
1705 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1706 When it is t, the entire archived tree will be exported.
1707 When it is nil the entire tree including the headline will be removed
1709 (let ((re-archive (concat ":" org-archive-tag
":"))
1711 (when (not (eq export-archived-trees t
))
1712 (goto-char (point-min))
1713 (while (re-search-forward re-archive nil t
)
1714 (if (not (org-on-heading-p t
))
1715 (org-end-of-subtree t
)
1716 (beginning-of-line 1)
1717 (setq a
(if export-archived-trees
1718 (1+ (point-at-eol)) (point))
1719 b
(org-end-of-subtree t
))
1720 (if (> b a
) (delete-region a b
)))))))
1722 (defun org-export-protect-quoted-subtrees ()
1723 "Mark quoted subtrees with the protection property."
1724 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1725 (goto-char (point-min))
1726 (while (re-search-forward re-quote nil t
)
1727 (goto-char (match-beginning 0))
1729 (add-text-properties (point) (org-end-of-subtree t
)
1730 '(org-protected t
)))))
1732 (defun org-export-protect-verbatim ()
1733 "Mark verbatim snippets with the protection property."
1734 (goto-char (point-min))
1735 (while (re-search-forward org-verbatim-re nil t
)
1736 (add-text-properties (match-beginning 4) (match-end 4)
1738 (goto-char (1+ (match-end 4)))))
1740 (defun org-export-protect-examples (&optional indent
)
1741 "Protect code that should be exported as monospaced examples."
1742 (goto-char (point-min))
1743 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1744 (goto-char (match-end 0))
1745 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1746 (insert (if indent
": " ":"))
1747 (beginning-of-line 2)))
1748 (goto-char (point-min))
1749 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1750 (add-text-properties (match-beginning 0) (match-end 0)
1751 '(org-protected t
))))
1753 (defun org-export-select-backend-specific-text (backend)
1755 '((html "HTML" "BEGIN_HTML" "END_HTML")
1756 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1757 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1761 (setq fmt
(pop formatters
))
1762 (when (eq (car fmt
) backend
)
1763 ;; This is selected code, put it into the file for real
1764 (goto-char (point-min))
1765 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1766 ":[ \t]*\\(.*\\)") nil t
)
1767 (replace-match "\\1" t
)
1768 (add-text-properties
1769 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1770 '(org-protected t
))))
1771 (goto-char (point-min))
1772 (while (re-search-forward
1774 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1775 (cadddr fmt
) "\\>.*\n?") nil t
)
1776 (if (eq (car fmt
) backend
)
1778 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1780 ;; No, this is for a different backend, kill it
1781 (delete-region (match-beginning 0) (match-end 0)))))))
1783 (defun org-export-mark-blockquote-and-verse ()
1784 "Mark block quote and verse environments with special cookies.
1785 These special cookies will later be interpreted by the backend."
1787 (goto-char (point-min))
1788 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1790 (replace-match (if (equal (downcase (match-string 1)) "end")
1791 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1794 (goto-char (point-min))
1795 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1796 (replace-match (if (equal (downcase (match-string 1)) "end")
1797 "ORG-VERSE-END" "ORG-VERSE-START")
1800 (defun org-export-remove-comment-blocks-and-subtrees ()
1801 "Remove the comment environment, and also commented subtrees."
1802 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1803 (case-fold-search nil
))
1804 ;; Remove comment environment
1805 (goto-char (point-min))
1806 (while (re-search-forward
1807 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1808 (replace-match "" t t
))
1809 ;; Remove subtrees that are commented
1810 (goto-char (point-min))
1811 (while (re-search-forward re-commented nil t
)
1812 (goto-char (match-beginning 0))
1813 (delete-region (point) (org-end-of-subtree t
)))))
1815 (defun org-export-handle-comments (commentsp)
1816 "Remove comments, or convert to backend-specific format.
1817 COMMENTSP can be a format string for publishing comments.
1818 When it is nil, all comments will be removed."
1819 (let ((re "^#\\(.*\n?\\)")
1821 (goto-char (point-min))
1822 (while (or (looking-at re
)
1823 (re-search-forward re nil t
))
1824 (setq pos
(match-beginning 0))
1826 (progn (add-text-properties
1827 (match-beginning 0) (match-end 0) '(org-protected t
))
1828 (replace-match (format commentsp
(match-string 1)) t t
))
1829 (goto-char (1+ pos
))
1832 (goto-char (max (point-min) (1- pos
))))))))
1834 (defun org-export-mark-radio-links ()
1835 "Find all matches for radio targets and turn them into internal links."
1836 (let ((re-radio (and org-target-link-regexp
1837 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1838 (goto-char (point-min))
1840 (while (re-search-forward re-radio nil t
)
1842 (replace-match "\\1[[\\2]]"))))))
1844 (defun org-export-remove-special-table-lines ()
1845 "Remove tables lines that are used for internal purposes."
1846 (goto-char (point-min))
1847 (while (re-search-forward "^[ \t]*|" nil t
)
1848 (beginning-of-line 1)
1849 (if (or (looking-at "[ \t]*| *[!_^] *|")
1850 (and (looking-at ".*?| *<[0-9]+> *|")
1851 (not (looking-at ".*?| *[^ <|]"))))
1852 (delete-region (max (point-min) (1- (point-at-bol)))
1856 (defun org-export-normalize-links ()
1857 "Convert all links to bracket links, and expand link abbreviations."
1858 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1859 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1860 (goto-char (point-min))
1861 (while (re-search-forward re-plain-link nil t
)
1862 (goto-char (1- (match-end 0)))
1864 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1865 ":" (match-string 3) "]]")))
1866 ;; added 'org-link face to links
1867 (put-text-property 0 (length s
) 'face
'org-link s
)
1868 (replace-match s t t
))))
1869 (goto-char (point-min))
1870 (while (re-search-forward re-angle-link nil t
)
1871 (goto-char (1- (match-end 0)))
1873 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1874 ":" (match-string 3) "]]")))
1875 (put-text-property 0 (length s
) 'face
'org-link s
)
1876 (replace-match s t t
))))
1877 (goto-char (point-min))
1878 (while (re-search-forward org-bracket-link-regexp nil t
)
1879 (goto-char (1- (match-end 0)))
1881 (let* ((xx (save-match-data
1882 (org-link-expand-abbrev (match-string 1))))
1887 (concat "[" xx
"]"))
1889 (put-text-property 0 (length s
) 'face
'org-link s
)
1890 (replace-match s t t
))))))
1892 (defun org-export-concatenate-multiline-links ()
1893 "Find multi-line links and put it all into a single line.
1894 This is to make sure that the line-processing export backends
1895 can work correctly."
1896 (goto-char (point-min))
1897 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1899 (replace-match "\\1 \\3")
1900 (goto-char (match-beginning 0)))))
1902 (defun org-export-concatenate-multiline-emphasis ()
1903 "Find multi-line emphasis and put it all into a single line.
1904 This is to make sure that the line-processing export backends
1905 can work correctly."
1906 (goto-char (point-min))
1907 (while (re-search-forward org-emph-re nil t
)
1908 (if (not (= (char-after (match-beginning 3))
1909 (char-after (match-beginning 4))))
1911 (subst-char-in-region (match-beginning 0) (match-end 0)
1913 (goto-char (1- (match-end 0))))
1914 (goto-char (1+ (match-beginning 0))))))
1916 (defun org-export-grab-title-from-buffer ()
1917 "Get a title for the current document, from looking at the buffer."
1918 (let ((inhibit-read-only t
))
1920 (goto-char (point-min))
1921 (let ((end (if (looking-at org-outline-regexp
)
1923 (save-excursion (outline-next-heading) (point)))))
1924 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1925 ;; Mark the line so that it will not be exported as normal text.
1927 (add-text-properties (match-beginning 0) (match-end 0)
1928 (list :org-license-to-kill t
)))
1929 ;; Return the title string
1930 (org-trim (match-string 0)))))))
1932 (defun org-export-get-title-from-subtree ()
1933 "Return subtree title and exclude it from export."
1934 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1937 (when (and (org-at-heading-p)
1938 (>= (org-end-of-subtree t t
) rend
))
1939 ;; This is a subtree, we take the title from the first heading
1941 (looking-at org-todo-line-regexp
)
1942 (setq title
(match-string 3))
1944 (add-text-properties (point) (1+ (point-at-eol))
1945 (list :org-license-to-kill t
)))
1946 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1949 (defun org-solidify-link-text (s &optional alist
)
1950 "Take link text and make a safe target out of it."
1955 (org-split-string s
"[ \t\r\n]+") "=="))
1956 (a (assoc rtn alist
)))
1959 (defun org-get-min-level (lines)
1960 "Get the minimum level in LINES."
1961 (let ((re "^\\(\\*+\\) ") l min
)
1963 (while (setq l
(pop lines
))
1964 (if (string-match re l
)
1965 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1968 ;; Variable holding the vector with section numbers
1969 (defvar org-section-numbers
(make-vector org-level-max
0))
1971 (defun org-init-section-numbers ()
1972 "Initialize the vector for the section numbers."
1974 (numbers (nreverse (org-split-string "" "\\.")))
1975 (depth (1- (length org-section-numbers
)))
1976 (i depth
) number-string
)
1979 (aset org-section-numbers i
0)
1980 (setq number-string
(or (car numbers
) "0"))
1981 (if (string-match "\\`[A-Z]\\'" number-string
)
1982 (aset org-section-numbers i
1983 (- (string-to-char number-string
) ?A -
1))
1984 (aset org-section-numbers i
(string-to-number number-string
)))
1988 (defun org-section-number (&optional level
)
1989 "Return a string with the current section number.
1990 When LEVEL is non-nil, increase section numbers on that level."
1991 (let* ((depth (1- (length org-section-numbers
)))
1993 (fmts (car org-export-section-number-format
))
1994 (term (cdr org-export-section-number-format
))
1999 (aset org-section-numbers
2000 level
(1+ (aref org-section-numbers level
))))
2001 (setq idx
(1+ level
))
2002 (while (<= idx depth
)
2004 (aset org-section-numbers idx
0))
2005 (setq idx
(1+ idx
))))
2007 (while (<= idx depth
)
2008 (when (> (aref org-section-numbers idx
) 0)
2009 (setq fmt
(or (pop fmts
) fmt
)
2011 n
(aref org-section-numbers idx
)
2013 (concat string sep
(org-number-to-counter n ctype
))
2014 (concat string
".0"))
2016 (setq idx
(1+ idx
)))
2018 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2019 (setq string
(replace-match "" t nil string
)))
2020 (if (string-match "\\(\\.0\\)+\\'" string
)
2021 (setq string
(replace-match "" t nil string
))))
2022 (concat string term
)))
2024 (defun org-number-to-counter (n type
)
2025 "Concert number N to a string counter, according to TYPE.
2026 TYPE must be a string, any of:
2030 I uppper case roman numeral
2031 i lower case roman numeral"
2033 ((equal type
"1") (number-to-string n
))
2034 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2035 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2036 ((equal type
"I") (org-number-to-roman n
))
2037 ((equal type
"i") (downcase (org-number-to-roman n
)))
2038 (t (error "Invalid counter type `%s'" type
))))
2040 (defun org-number-to-roman (n)
2041 "Convert integer N into a roman numeral."
2042 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2043 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2044 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2048 (number-to-string n
)
2050 (if (>= n
(caar roman
))
2051 (setq n
(- n
(caar roman
))
2052 res
(concat res
(cdar roman
)))
2056 (org-number-to-roman 1961)
2061 (defun org-export-handle-include-files ()
2062 "Include the contents of include files, with proper formatting."
2063 (let ((case-fold-search t
)
2064 params file markup lang start end prefix prefix1
)
2065 (goto-char (point-min))
2066 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2067 (setq params
(read (concat "(" (match-string 1) ")"))
2068 prefix
(org-get-and-remove-property 'params
:prefix
)
2069 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2070 file
(org-symname-or-string (pop params
))
2071 markup
(org-symname-or-string (pop params
))
2072 lang
(org-symname-or-string (pop params
)))
2073 (delete-region (match-beginning 0) (match-end 0))
2075 (not (file-exists-p file
))
2076 (not (file-readable-p file
)))
2077 (insert (format "CANNOT INCLUDE FILE %s" file
))
2079 (if (equal (downcase markup
) "src")
2080 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2082 (setq start
(format "#+begin_%s\n" markup
)
2083 end
(format "#+end_%s" markup
))))
2084 (insert (or start
""))
2085 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2086 (or (bolp) (newline))
2087 (insert (or end
""))))))
2089 (defun org-get-file-contents (file &optional prefix prefix1
)
2090 "Get the contents of FILE and return them as a string.
2091 If PREFIX is a string, prepend it to each line. If PREFIX1
2092 is a string, prepend it to the first line instead of PREFIX."
2094 (insert-file-contents file
)
2095 (when (or prefix prefix1
)
2096 (goto-char (point-min))
2098 (insert (or prefix1 prefix
))
2100 (beginning-of-line 2)))
2103 (defun org-get-and-remove-property (listvar prop
)
2104 "Check if the value of LISTVAR contains PROP as a property.
2105 If yes, return the value of that property (i.e. the element following
2106 in the list) and remove property and value from the list in LISTVAR."
2107 (let ((list (symbol-value listvar
)) m v
)
2108 (when (setq m
(member prop list
))
2110 (if (equal (car list
) prop
)
2111 (set listvar
(cddr list
))
2112 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2114 (set listvar list
)))
2117 (defun org-symname-or-string (s)
2119 (if s
(symbol-name s
) s
)
2122 ;;; Fontification of code
2123 ;; Currently only for the HTML backend, but who knows....
2124 (defun org-export-replace-src-segments ()
2125 "Replace source code segments with special code for export."
2126 (let ((case-fold-search t
)
2128 (goto-char (point-min))
2129 (while (re-search-forward
2130 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2132 (setq lang
(match-string 1) code
(match-string 2)
2133 trans
(org-export-format-source-code lang code
))
2134 (replace-match trans t t
))))
2136 (defvar htmlp
) ;; dynamically scoped from org-exp.el
2138 (defun org-export-format-source-code (lang code
)
2139 "Format CODE from language LANG and return it formatted for export.
2140 Currently, this only does something for HTML export, for all other
2141 backends, it converts the segment into an EXAMPLE segment."
2145 ;; We are exporting to HTML
2146 (condition-case nil
(require 'htmlize
) (nil t
))
2147 (if (not (fboundp 'htmlize-region-for-paste
))
2149 ;; we do not have htmlize.el, or an old version of it
2151 "htmlize.el 1.34 or later is needed for source code formatting")
2152 (concat "#+BEGIN_EXAMPLE\n" code
2153 (if (string-match "\n\\'" code
) "" "\n")
2155 ;; ok, we are good to go
2156 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2157 (org-inhibit-startup t
)
2158 (org-startup-folded nil
)
2162 ;; Free up the protected stuff
2163 (goto-char (point-min))
2164 (while (re-search-forward "^," nil t
)
2167 (if (functionp mode
)
2170 (font-lock-fontify-buffer)
2171 (org-export-htmlize-region-for-paste
2172 (point-min) (point-max)))))
2173 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2174 (setq htmltext
(replace-match
2175 (format "<pre class=\"src src-%s\">" lang
)
2177 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2179 ;; This is not HTML, so just make it an example.
2180 (when (equal lang
"org")
2181 (while (string-match "^," code
)
2182 (setq code
(replace-match "" t t code
))))
2183 (concat "#+BEGIN_EXAMPLE\n" code
2184 (if (string-match "\n\\'" code
) "" "\n")
2185 "#+END_EXAMPLE\n")))))
2189 (defvar org-last-level nil
) ; dynamically scoped variable
2190 (defvar org-min-level nil
) ; dynamically scoped variable
2191 (defvar org-levels-open nil
) ; dynamically scoped parameter
2192 (defvar org-ascii-current-indentation nil
) ; For communication
2195 (defun org-export-as-ascii (arg)
2196 "Export the outline as a pretty ASCII file.
2197 If there is an active region, export only the region.
2198 The prefix ARG specifies how many levels of the outline should become
2199 underlined headlines. The default is 3."
2201 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2202 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2203 (org-infile-export-plist)))
2204 (region-p (org-region-active-p))
2205 (rbeg (and region-p
(region-beginning)))
2206 (rend (and region-p
(region-end)))
2211 (and (org-at-heading-p)
2212 (>= (org-end-of-subtree t t
) rend
)))))
2213 (opt-plist (if subtree-p
2214 (org-export-add-subtree-options opt-plist rbeg
)
2216 (custom-times org-display-custom-times
)
2217 (org-ascii-current-indentation '(0 .
0))
2221 (case-fold-search nil
)
2222 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2223 (filename (concat (file-name-as-directory
2224 (org-export-directory :ascii opt-plist
))
2225 (file-name-sans-extension
2227 (org-entry-get (region-beginning)
2228 "EXPORT_FILE_NAME" t
))
2229 (file-name-nondirectory bfname
)))
2231 (filename (if (equal (file-truename filename
)
2232 (file-truename bfname
))
2233 (concat filename
".txt")
2235 (buffer (find-file-noselect filename
))
2236 (org-levels-open (make-vector org-level-max nil
))
2237 (odd org-odd-levels-only
)
2238 (date (plist-get opt-plist
:date
))
2239 (author (plist-get opt-plist
:author
))
2240 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2241 (plist-get opt-plist
:title
)
2243 (plist-get opt-plist
:skip-before-1st-heading
))
2244 (org-export-grab-title-from-buffer))
2245 (file-name-sans-extension
2246 (file-name-nondirectory bfname
))))
2247 (email (plist-get opt-plist
:email
))
2248 (language (plist-get opt-plist
:language
))
2249 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2250 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2255 (if (org-region-active-p) (region-beginning) (point-min))
2256 (if (org-region-active-p) (region-end) (point-max))))
2257 (lines (org-split-string
2258 (org-export-preprocess-string
2261 :skip-before-1st-heading
2262 (plist-get opt-plist
:skip-before-1st-heading
)
2263 :drawers
(plist-get opt-plist
:drawers
)
2264 :verbatim-multiline t
2265 :select-tags
(plist-get opt-plist
:select-tags
)
2266 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2268 (plist-get opt-plist
:archived-trees
)
2269 :add-text
(plist-get opt-plist
:text
))
2271 thetoc have-headings first-heading-pos
2272 table-open table-buffer
)
2274 (let ((inhibit-read-only t
))
2276 (remove-text-properties (point-min) (point-max)
2277 '(:org-license-to-kill t
))))
2279 (setq org-min-level
(org-get-min-level lines
))
2280 (setq org-last-level org-min-level
)
2281 (org-init-section-numbers)
2283 (find-file-noselect filename
)
2285 (setq lang-words
(or (assoc language org-export-language-setup
)
2286 (assoc "en" org-export-language-setup
)))
2287 (switch-to-buffer-other-window buffer
)
2290 ;; create local variables for all options, to make sure all called
2291 ;; functions get the correct information
2293 (set (make-local-variable (cdr x
))
2294 (plist-get opt-plist
(car x
))))
2295 org-export-plist-vars
)
2296 (org-set-local 'org-odd-levels-only odd
)
2297 (setq umax
(if arg
(prefix-numeric-value arg
)
2298 org-export-headline-levels
))
2299 (setq umax-toc
(if (integerp org-export-with-toc
)
2300 (min org-export-with-toc umax
)
2304 (if title
(org-insert-centered title ?
=))
2306 (if (and (or author email
)
2307 org-export-author-info
)
2308 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2309 (if email
(concat " <" email
">") "")
2313 ((and date
(string-match "%" date
))
2314 (setq date
(format-time-string date
)))
2316 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2318 (if (and date org-export-time-stamp-file
)
2319 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2323 (if org-export-with-toc
2325 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2326 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2328 (mapc '(lambda (line)
2329 (if (string-match org-todo-line-regexp
2331 ;; This is a headline
2333 (setq have-headings t
)
2334 (setq level
(- (match-end 1) (match-beginning 1))
2335 level
(org-tr-level level
)
2336 txt
(match-string 3 line
)
2338 (or (and org-export-mark-todo-in-toc
2340 (not (member (match-string 2 line
)
2341 org-done-keywords
)))
2343 (and org-export-mark-todo-in-toc
2345 (org-search-todo-below
2346 line lines level
))))
2347 (setq txt
(org-html-expand-for-ascii txt
))
2349 (while (string-match org-bracket-link-regexp txt
)
2352 (match-string (if (match-end 2) 3 1) txt
)
2355 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2357 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2359 (setq txt
(replace-match "" t t txt
)))
2360 (if (string-match quote-re0 txt
)
2361 (setq txt
(replace-match "" t t txt
)))
2363 (if org-export-with-section-numbers
2364 (setq txt
(concat (org-section-number level
)
2366 (if (<= level umax-toc
)
2371 (* (max 0 (- level org-min-level
)) 4) ?\
)
2372 (format (if todo
"%s (*)\n" "%s\n") txt
))
2374 (setq org-last-level level
))
2377 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2379 (org-init-section-numbers)
2380 (while (setq line
(pop lines
))
2381 ;; Remove the quoted HTML tags.
2382 (setq line
(org-html-expand-for-ascii line
))
2384 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2385 (setq line
(replace-match "" t t line
)))
2386 ;; Replace internal links
2387 (while (string-match org-bracket-link-regexp line
)
2388 (setq line
(replace-match
2389 (if (match-end 3) "[\\3]" "[\\1]")
2392 (setq line
(org-translate-time line
)))
2394 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2396 (setq first-heading-pos
(or first-heading-pos
(point)))
2397 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2398 txt
(match-string 2 line
))
2399 (org-ascii-level-start level txt umax lines
))
2401 ((and org-export-with-tables
2402 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2403 (if (not table-open
)
2405 (setq table-open t table-buffer nil
))
2407 (setq table-buffer
(cons line table-buffer
))
2408 (when (or (not lines
)
2409 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2411 (setq table-open nil
2412 table-buffer
(nreverse table-buffer
))
2415 (org-fix-indentation x org-ascii-current-indentation
))
2416 (org-format-table-ascii table-buffer
)
2419 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2420 (if (and org-export-with-fixed-width
2421 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2422 (setq line
(replace-match "\\1" nil nil line
)))
2423 (insert line
"\n"))))
2427 ;; insert the table of contents
2429 (goto-char (point-min))
2430 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2432 (goto-char (match-beginning 0))
2434 (goto-char first-heading-pos
))
2435 (mapc 'insert thetoc
)
2436 (or (looking-at "[ \t]*\n[ \t]*\n")
2439 ;; Convert whitespace place holders
2440 (goto-char (point-min))
2442 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2443 (setq end
(next-single-property-change beg
'org-whitespace
))
2445 (delete-region beg end
)
2446 (insert (make-string (- end beg
) ?\
))))
2449 ;; remove display and invisible chars
2451 (goto-char (point-min))
2452 (while (setq beg
(next-single-property-change (point) 'display
))
2453 (setq end
(next-single-property-change beg
'display
))
2454 (delete-region beg end
)
2457 (goto-char (point-min))
2458 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2459 (setq end
(next-single-property-change beg
'org-cwidth
))
2460 (delete-region beg end
)
2462 (goto-char (point-min))))
2464 (defun org-export-ascii-preprocess ()
2465 "Do extra work for ASCII export"
2466 (goto-char (point-min))
2467 (while (re-search-forward org-verbatim-re nil t
)
2468 (goto-char (match-end 2))
2469 (backward-delete-char 1) (insert "'")
2470 (goto-char (match-beginning 2))
2471 (delete-char 1) (insert "`")
2472 (goto-char (match-end 2))))
2474 (defun org-search-todo-below (line lines level
)
2475 "Search the subtree below LINE for any TODO entries."
2476 (let ((rest (cdr (memq line lines
)))
2477 (re org-todo-line-regexp
)
2480 (while (setq line
(pop rest
))
2481 (if (string-match re line
)
2483 (setq lv
(- (match-end 1) (match-beginning 1))
2484 todo
(and (match-beginning 2)
2485 (not (member (match-string 2 line
)
2486 org-done-keywords
))))
2488 (if (<= lv level
) (throw 'exit nil
))
2489 (if todo
(throw 'exit t
))))))))
2491 (defun org-html-expand-for-ascii (line)
2492 "Handle quoted HTML for ASCII export."
2493 (if org-export-html-expand
2494 (while (string-match "@<[^<>\n]*>" line
)
2495 ;; We just remove the tags for now.
2496 (setq line
(replace-match "" nil nil line
))))
2499 (defun org-insert-centered (s &optional underline
)
2500 "Insert the string S centered and underline it with character UNDERLINE."
2501 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2502 (insert (make-string ind ?\
) s
"\n")
2504 (insert (make-string ind ?\
)
2505 (make-string (string-width s
) underline
)
2508 (defun org-ascii-level-start (level title umax
&optional lines
)
2509 "Insert a new level in ASCII export."
2510 (let (char (n (- level umax
1)) (ind 0))
2513 (insert (make-string (* 2 n
) ?\
)
2514 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2515 org-export-ascii-bullets
))
2517 ;; find the indentation of the next non-empty line
2520 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2521 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2522 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2524 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2525 (if (or (not (equal (char-before) ?
\n))
2526 (not (equal (char-before (1- (point))) ?
\n)))
2528 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2529 (unless org-export-with-tags
2530 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2531 (setq title
(replace-match "" t t title
))))
2532 (if org-export-with-section-numbers
2533 (setq title
(concat (org-section-number level
) " " title
)))
2534 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2535 (setq org-ascii-current-indentation
'(0 .
0)))))
2538 (defun org-export-visible (type arg
)
2539 "Create a copy of the visible part of the current buffer, and export it.
2540 The copy is created in a temporary buffer and removed after use.
2541 TYPE is the final key (as a string) that also select the export command in
2542 the `C-c C-e' export dispatcher.
2543 As a special case, if the you type SPC at the prompt, the temporary
2544 org-mode file will not be removed but presented to you so that you can
2545 continue to use it. The prefix arg ARG is passed through to the exporting
2549 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2550 (read-char-exclusive))
2551 current-prefix-arg
))
2552 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2553 (error "Invalid export key"))
2554 (let* ((binding (cdr (assoc type
2555 '((?a . org-export-as-ascii
)
2556 (?\C-a . org-export-as-ascii
)
2557 (?b . org-export-as-html-and-open
)
2558 (?\C-b . org-export-as-html-and-open
)
2559 (?h . org-export-as-html
)
2560 (?H . org-export-as-html-to-buffer
)
2561 (?R . org-export-region-as-html
)
2562 (?x . org-export-as-xoxo
)))))
2563 (keepp (equal type ?\
))
2564 (file buffer-file-name
)
2565 (buffer (get-buffer-create "*Org Export Visible*"))
2567 ;; Need to hack the drawers here.
2569 (goto-char (point-min))
2570 (while (re-search-forward org-drawer-regexp nil t
)
2571 (goto-char (match-beginning 1))
2572 (or (org-invisible-p) (org-flag-drawer nil
))))
2573 (with-current-buffer buffer
(erase-buffer))
2575 (setq s
(goto-char (point-min)))
2576 (while (not (= (point) (point-max)))
2577 (goto-char (org-find-invisible))
2578 (append-to-buffer buffer s
(point))
2579 (setq s
(goto-char (org-find-visible))))
2580 (org-cycle-hide-drawers 'all
)
2581 (goto-char (point-min))
2583 ;; Copy all comment lines to the end, to make sure #+ settings are
2584 ;; still available for the second export step. Kind of a hack, but
2585 ;; does do the trick.
2586 (if (looking-at "#[^\r\n]*")
2587 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2588 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2589 (append-to-buffer buffer
(1+ (match-beginning 0))
2590 (min (point-max) (1+ (match-end 0))))))
2592 (let ((buffer-file-name file
)
2593 (org-inhibit-startup t
))
2596 (unless keepp
(funcall binding arg
))))
2598 (kill-buffer buffer
)
2599 (switch-to-buffer-other-window buffer
)
2600 (goto-char (point-min)))))
2602 (defun org-find-visible ()
2604 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2605 (get-char-property s
'invisible
)))
2607 (defun org-find-invisible ()
2609 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2610 (not (get-char-property s
'invisible
))))
2615 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2616 (defun org-get-current-options ()
2617 "Return a string with current options as keyword options.
2618 Does include HTML export options as well as TODO and CATEGORY stuff."
2619 (require 'org-archive
)
2626 #+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 tags:%s
2628 #+EXPORT_SELECT_TAGS: %s
2629 #+EXPORT_EXCLUDE_TAGS: %s
2635 #+PRIORITIES: %c %c %c
2637 #+STARTUP: %s %s %s %s %s
2643 (buffer-name) (user-full-name) user-mail-address
2644 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2645 org-export-default-language
2646 org-export-headline-levels
2647 org-export-with-section-numbers
2649 org-export-preserve-breaks
2650 org-export-html-expand
2651 org-export-with-fixed-width
2652 org-export-with-tables
2653 org-export-with-sub-superscripts
2654 org-export-with-special-strings
2655 org-export-with-footnotes
2656 org-export-with-emphasize
2657 org-export-with-TeX-macros
2658 org-export-with-LaTeX-fragments
2659 org-export-skip-text-before-1st-heading
2660 org-export-with-drawers
2661 org-export-with-tags
2662 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2663 (mapconcat 'identity org-export-select-tags
" ")
2664 (mapconcat 'identity org-export-exclude-tags
" ")
2665 org-export-html-link-up
2666 org-export-html-link-home
2667 (file-name-nondirectory buffer-file-name
)
2668 "TODO FEEDBACK VERIFY DONE"
2669 "Me Jason Marie DONE"
2670 org-highest-priority org-lowest-priority org-default-priority
2671 (mapconcat 'identity org-drawers
" ")
2672 (cdr (assoc org-startup-folded
2673 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2674 (if org-odd-levels-only
"odd" "oddeven")
2675 (if org-hide-leading-stars
"hidestars" "showstars")
2676 (if org-startup-align-all-tables
"align" "noalign")
2677 (cond ((eq org-log-done t
) "logdone")
2678 ((equal org-log-done
'note
) "lognotedone")
2679 ((not org-log-done
) "nologdone"))
2680 (or (mapconcat (lambda (x)
2682 ((equal '(:startgroup
) x
) "{")
2683 ((equal '(:endgroup
) x
) "}")
2684 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2686 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2687 (mapconcat 'identity org-file-tags
" ")
2688 org-archive-location
2689 "org file:~/org/%s.org"
2692 (defun org-export-html-preprocess (parameters)
2693 ;; Convert LaTeX fragments to images
2694 (when (plist-get parameters
:LaTeX-fragments
)
2696 (concat "ltxpng/" (file-name-sans-extension
2697 (file-name-nondirectory
2698 org-current-export-file
)))
2699 org-current-export-dir nil
"Creating LaTeX image %s"))
2700 (message "Exporting..."))
2703 (defun org-insert-export-options-template ()
2704 "Insert into the buffer a template with information for exporting."
2706 (if (not (bolp)) (newline))
2707 (let ((s (org-get-current-options)))
2708 (and (string-match "#\\+CATEGORY" s
)
2709 (setq s
(substring s
0 (match-beginning 0))))
2713 (defun org-export-as-html-and-open (arg)
2714 "Export the outline as HTML and immediately open it with a browser.
2715 If there is an active region, export only the region.
2716 The prefix ARG specifies how many levels of the outline should become
2717 headlines. The default is 3. Lower levels will become bulleted lists."
2719 (org-export-as-html arg
'hidden
)
2720 (org-open-file buffer-file-name
))
2723 (defun org-export-as-html-batch ()
2724 "Call `org-export-as-html', may be used in batch processing as
2726 --load=$HOME/lib/emacs/org.el
2727 --eval \"(setq org-export-headline-levels 2)\"
2728 --visit=MyFile --funcall org-export-as-html-batch"
2729 (org-export-as-html org-export-headline-levels
'hidden
))
2732 (defun org-export-as-html-to-buffer (arg)
2733 "Call `org-exort-as-html` with output to a temporary buffer.
2734 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2736 (org-export-as-html arg nil nil
"*Org HTML Export*")
2737 (switch-to-buffer-other-window "*Org HTML Export*"))
2740 (defun org-replace-region-by-html (beg end
)
2741 "Assume the current region has org-mode syntax, and convert it to HTML.
2742 This can be used in any buffer. For example, you could write an
2743 itemized list in org-mode syntax in an HTML buffer and then use this
2744 command to convert it."
2746 (let (reg html buf pop-up-frames
)
2747 (save-window-excursion
2749 (setq html
(org-export-region-as-html
2751 (setq reg
(buffer-substring beg end
)
2752 buf
(get-buffer-create "*Org tmp*"))
2753 (with-current-buffer buf
2757 (setq html
(org-export-region-as-html
2758 (point-min) (point-max) t
'string
)))
2760 (delete-region beg end
)
2764 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2765 "Convert region from BEG to END in org-mode buffer to HTML.
2766 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2767 contents, and only produce the region of converted text, useful for
2768 cut-and-paste operations.
2769 If BUFFER is a buffer or a string, use/create that buffer as a target
2770 of the converted HTML. If BUFFER is the symbol `string', return the
2771 produced HTML as a string and leave not buffer behind. For example,
2772 a Lisp program could call this function in the following way:
2774 (setq html (org-export-region-as-html beg end t 'string))
2776 When called interactively, the output buffer is selected, and shown
2777 in a window. A non-interactive call will only return the buffer."
2778 (interactive "r\nP")
2779 (when (interactive-p)
2780 (setq buffer
"*Org HTML Export*"))
2781 (let ((transient-mark-mode t
) (zmacs-regions t
)
2783 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2785 (set-mark (point)) ;; to activate the region
2787 (setq rtn
(org-export-as-html
2790 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2791 (if (and (interactive-p) (bufferp rtn
))
2792 (switch-to-buffer-other-window rtn
)
2795 (defvar html-table-tag nil
) ; dynamically scoped into this.
2796 (defvar org-par-open nil
)
2798 (defun org-export-as-html (arg &optional hidden ext-plist
2799 to-buffer body-only pub-dir
)
2800 "Export the outline as a pretty HTML file.
2801 If there is an active region, export only the region. The prefix
2802 ARG specifies how many levels of the outline should become
2803 headlines. The default is 3. Lower levels will become bulleted
2804 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2805 EXT-PLIST is a property list with external parameters overriding
2806 org-mode's default settings, but still inferior to file-local
2807 settings. When TO-BUFFER is non-nil, create a buffer with that
2808 name and export to that buffer. If TO-BUFFER is the symbol
2809 `string', don't leave any buffer behind but just return the
2810 resulting HTML as a string. When BODY-ONLY is set, don't produce
2811 the file header and footer, simply return the content of
2812 <body>...</body>, without even the body tags themselves. When
2813 PUB-DIR is set, use this as the publishing directory."
2816 ;; Make sure we have a file name when we need it.
2817 (when (and (not (or to-buffer body-only
))
2818 (not buffer-file-name
))
2819 (if (buffer-base-buffer)
2820 (org-set-local 'buffer-file-name
2821 (with-current-buffer (buffer-base-buffer)
2823 (error "Need a file name to be able to export.")))
2825 (message "Exporting...")
2826 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2827 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2828 (setq-default org-done-keywords org-done-keywords
)
2829 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2831 (org-export-process-option-filters
2832 (org-combine-plists (org-default-export-plist)
2834 (org-infile-export-plist))))
2835 (style (concat (if (plist-get opt-plist
:style-include-default
)
2836 org-export-html-style-default
)
2837 (plist-get opt-plist
:style
)
2838 (plist-get opt-plist
:style-extra
)))
2839 (html-extension (plist-get opt-plist
:html-extension
))
2840 (link-validate (plist-get opt-plist
:link-validation-function
))
2841 valid thetoc have-headings first-heading-pos
2842 (odd org-odd-levels-only
)
2843 (region-p (org-region-active-p))
2844 (rbeg (and region-p
(region-beginning)))
2845 (rend (and region-p
(region-end)))
2847 (if (plist-get opt-plist
:ignore-subree-p
)
2852 (and (org-at-heading-p)
2853 (>= (org-end-of-subtree t t
) rend
))))))
2854 (opt-plist (if subtree-p
2855 (org-export-add-subtree-options opt-plist rbeg
)
2857 ;; The following two are dynamically scoped into other
2859 (org-current-export-dir
2860 (or pub-dir
(org-export-directory :html opt-plist
)))
2861 (org-current-export-file buffer-file-name
)
2862 (level 0) (line "") (origline "") txt todo
2865 (filename (if to-buffer nil
2868 (file-name-sans-extension
2870 (org-entry-get (region-beginning)
2871 "EXPORT_FILE_NAME" t
))
2872 (file-name-nondirectory buffer-file-name
)))
2874 (file-name-as-directory
2875 (or pub-dir
(org-export-directory :html opt-plist
))))))
2876 (current-dir (if buffer-file-name
2877 (file-name-directory buffer-file-name
)
2879 (buffer (if to-buffer
2881 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2882 (t (get-buffer-create to-buffer
)))
2883 (find-file-noselect filename
)))
2884 (org-levels-open (make-vector org-level-max nil
))
2885 (date (plist-get opt-plist
:date
))
2886 (author (plist-get opt-plist
:author
))
2887 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2888 (plist-get opt-plist
:title
)
2890 (plist-get opt-plist
:skip-before-1st-heading
))
2891 (org-export-grab-title-from-buffer))
2892 (and buffer-file-name
2893 (file-name-sans-extension
2894 (file-name-nondirectory buffer-file-name
)))
2896 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2897 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2898 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2903 (local-list-type nil
)
2904 (local-list-indent nil
)
2905 (llt org-plain-list-ordered-item-terminator
)
2906 (email (plist-get opt-plist
:email
))
2907 (language (plist-get opt-plist
:language
))
2911 (coding-system (and (boundp 'buffer-file-coding-system
)
2912 buffer-file-coding-system
))
2913 (coding-system-for-write (or org-export-html-coding-system
2915 (save-buffer-coding-system (or org-export-html-coding-system
2917 (charset (and coding-system-for-write
2918 (fboundp 'coding-system-get
)
2919 (coding-system-get coding-system-for-write
2923 (if region-p
(region-beginning) (point-min))
2924 (if region-p
(region-end) (point-max))))
2927 (org-export-preprocess-string
2931 :skip-before-1st-heading
2932 (plist-get opt-plist
:skip-before-1st-heading
)
2933 :drawers
(plist-get opt-plist
:drawers
)
2935 (plist-get opt-plist
:archived-trees
)
2936 :select-tags
(plist-get opt-plist
:select-tags
)
2937 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2939 (plist-get opt-plist
:text
)
2941 (plist-get opt-plist
:LaTeX-fragments
))
2944 table-buffer table-orig-buffer
2945 ind item-type starter didclose
2946 rpl path attr desc descp desc1 desc2 link
2947 snumber fnc item-tag
2951 (let ((inhibit-read-only t
))
2953 (remove-text-properties (point-min) (point-max)
2954 '(:org-license-to-kill t
))))
2956 (message "Exporting...")
2958 (setq org-min-level
(org-get-min-level lines
))
2959 (setq org-last-level org-min-level
)
2960 (org-init-section-numbers)
2963 ((and date
(string-match "%" date
))
2964 (setq date
(format-time-string date
)))
2966 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2968 ;; Get the language-dependent settings
2969 (setq lang-words
(or (assoc language org-export-language-setup
)
2970 (assoc "en" org-export-language-setup
)))
2972 ;; Switch to the output buffer
2974 (let ((inhibit-read-only t
)) (erase-buffer))
2977 (and (fboundp 'set-buffer-file-coding-system
)
2978 (set-buffer-file-coding-system coding-system-for-write
))
2980 (let ((case-fold-search nil
)
2981 (org-odd-levels-only odd
))
2982 ;; create local variables for all options, to make sure all called
2983 ;; functions get the correct information
2985 (set (make-local-variable (cdr x
))
2986 (plist-get opt-plist
(car x
))))
2987 org-export-plist-vars
)
2988 (setq umax
(if arg
(prefix-numeric-value arg
)
2989 org-export-headline-levels
))
2990 (setq umax-toc
(if (integerp org-export-with-toc
)
2991 (min org-export-with-toc umax
)
2996 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2997 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2998 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2999 lang=\"%s\" xml:lang=\"%s\">
3002 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3003 <meta name=\"generator\" content=\"Org-mode\"/>
3004 <meta name=\"generated\" content=\"%s\"/>
3005 <meta name=\"author\" content=\"%s\"/>
3009 language language
(org-html-expand title
)
3010 (or charset
"iso-8859-1") date author style
))
3012 (insert (or (plist-get opt-plist
:preamble
) ""))
3014 (when (plist-get opt-plist
:auto-preamble
)
3015 (if title
(insert (format org-export-html-title-format
3016 (org-html-expand title
))))))
3018 (if (and org-export-with-toc
(not body-only
))
3020 (push (format "<h%d>%s</h%d>\n"
3021 org-export-html-toplevel-hlevel
3023 org-export-html-toplevel-hlevel
)
3025 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3026 (push "<ul>\n<li>" thetoc
)
3028 (mapcar '(lambda (line)
3029 (if (string-match org-todo-line-regexp line
)
3030 ;; This is a headline
3032 (setq have-headings t
)
3033 (setq level
(- (match-end 1) (match-beginning 1))
3034 level
(org-tr-level level
)
3035 txt
(save-match-data
3037 (org-export-cleanup-toc-line
3038 (match-string 3 line
))))
3040 (or (and org-export-mark-todo-in-toc
3042 (not (member (match-string 2 line
)
3043 org-done-keywords
)))
3045 (and org-export-mark-todo-in-toc
3047 (org-search-todo-below
3048 line lines level
))))
3050 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3051 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3052 (if (string-match quote-re0 txt
)
3053 (setq txt
(replace-match "" t t txt
)))
3054 (setq snumber
(org-section-number level
))
3055 (if org-export-with-section-numbers
3056 (setq txt
(concat snumber
" " txt
)))
3057 (if (<= level
(max umax umax-toc
))
3058 (setq head-count
(+ head-count
1)))
3059 (if (<= level umax-toc
)
3061 (if (> level org-last-level
)
3063 (setq cnt
(- level org-last-level
))
3064 (while (>= (setq cnt
(1- cnt
)) 0)
3065 (push "\n<ul>\n<li>" thetoc
))
3066 (push "\n" thetoc
)))
3067 (if (< level org-last-level
)
3069 (setq cnt
(- org-last-level level
))
3070 (while (>= (setq cnt
(1- cnt
)) 0)
3071 (push "</li>\n</ul>" thetoc
))
3072 (push "\n" thetoc
)))
3073 ;; Check for targets
3074 (while (string-match org-any-target-regexp line
)
3075 (setq line
(replace-match
3076 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3078 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3079 (setq txt
(replace-match "" t t txt
)))
3083 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3084 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3085 snumber txt
) thetoc
)
3087 (setq org-last-level level
))
3091 (while (> org-last-level
(1- org-min-level
))
3092 (setq org-last-level
(1- org-last-level
))
3093 (push "</li>\n</ul>\n" thetoc
))
3094 (push "</div>\n" thetoc
)
3095 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3098 (org-init-section-numbers)
3102 (while (setq line
(pop lines
) origline line
)
3105 ;; end of quote section?
3106 (when (and inquote
(string-match "^\\*+ " line
))
3109 ;; inside a quote section?
3111 (insert (org-html-protect line
) "\n")
3112 (throw 'nextline nil
))
3114 ;; Fixed-width, verbatim lines (examples)
3115 (when (and org-export-with-fixed-width
3116 (string-match "^[ \t]*:\\(.*\\)" line
))
3119 (org-close-par-maybe)
3120 (insert "<pre class=\"example\">\n"))
3121 (insert (org-html-protect (match-string 1 line
)) "\n")
3122 (when (or (not lines
)
3123 (not (string-match "^[ \t]*\\(:.*\\)"
3126 (insert "</pre>\n"))
3127 (throw 'nextline nil
))
3130 (when (get-text-property 0 'org-protected line
)
3132 (when (re-search-backward
3133 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3134 (setq par
(match-string 1))
3135 (replace-match "\\2\n"))
3138 (not (string-match "^[ \t]*:" (car lines
)))
3139 (or (= (length (car lines
)) 0)
3140 (get-text-property 0 'org-protected
(car lines
))))
3141 (insert (pop lines
) "\n"))
3142 (and par
(insert "<p>\n")))
3143 (throw 'nextline nil
))
3146 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3148 (insert "\n</p>\n<hr/>\n<p>\n")
3149 (insert "\n<hr/>\n"))
3150 (throw 'nextline nil
))
3152 ;; Blockquotes and verse
3153 (when (equal "ORG-BLOCKQUOTE-START" line
)
3154 (insert "<blockquote>\n<p>\n")
3155 (throw 'nextline nil
))
3156 (when (equal "ORG-BLOCKQUOTE-END" line
)
3157 (insert "</p>\n</blockquote>\n")
3158 (throw 'nextline nil
))
3159 (when (equal "ORG-VERSE-START" line
)
3160 (insert "\n<p class=\"verse\">\n")
3162 (throw 'nextline nil
))
3163 (when (equal "ORG-VERSE-END" line
)
3166 (throw 'nextline nil
))
3168 (let ((i (org-get-string-indentation line
)))
3170 (setq line
(concat (mapconcat 'identity
3171 (make-list (* 2 i
) "\\nbsp") "")
3172 " " (org-trim line
))))
3173 (setq line
(concat line
" \\\\"))))
3175 ;; make targets to anchors
3176 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3179 (setq line
(replace-match
3180 (concat "@<a name=\""
3181 (org-solidify-link-text (match-string 1 line
))
3184 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3185 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3186 (setq line
(replace-match
3187 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3188 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3191 (setq line
(replace-match
3192 (concat "@<a name=\""
3193 (org-solidify-link-text (match-string 1 line
))
3194 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3197 (setq line
(org-html-handle-time-stamps line
))
3199 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3200 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3201 ;; Also handle sub_superscripts and checkboxes
3202 (or (string-match org-table-hline-regexp line
)
3203 (setq line
(org-html-expand line
)))
3207 (while (string-match org-bracket-link-analytic-regexp line start
)
3208 (setq start
(match-beginning 0))
3209 (setq path
(save-match-data (org-link-unescape
3210 (match-string 3 line
))))
3212 ((match-end 2) (match-string 2 line
))
3214 (or (file-name-absolute-p path
)
3215 (string-match "^\\.\\.?/" path
)))
3218 (setq path
(org-extract-attributes path
))
3219 (setq attr
(org-attributes-to-string
3220 (get-text-property 0 'org-attributes path
)))
3221 (setq desc1
(if (match-end 5) (match-string 5 line
))
3222 desc2
(if (match-end 2) (concat type
":" path
) path
)
3223 descp
(and desc1
(not (equal desc1 desc2
)))
3224 desc
(or desc1 desc2
))
3225 ;; Make an image out of the description if that is so wanted
3226 (when (and descp
(org-file-image-p desc
))
3228 (if (string-match "^file:" desc
)
3229 (setq desc
(substring desc
(match-end 0)))))
3230 (setq desc
(concat "<img src=\"" desc
"\"/>")))
3231 ;; FIXME: do we need to unescape here somewhere?
3233 ((equal type
"internal")
3237 (org-solidify-link-text
3238 (save-match-data (org-link-unescape path
)) nil
)
3240 (org-export-html-format-desc desc
)
3242 ((member type
'("http" "https"))
3243 ;; standard URL, just check if we need to inline an image
3244 (if (and (or (eq t org-export-html-inline-images
)
3245 (and org-export-html-inline-images
(not descp
)))
3246 (org-file-image-p path
))
3247 (setq rpl
(concat "<img src=\"" type
":" path
"\"" attr
"/>"))
3248 (setq link
(concat type
":" path
))
3249 (setq rpl
(concat "<a href=\""
3250 (org-export-html-format-href link
)
3252 (org-export-html-format-desc desc
)
3254 ((member type
'("ftp" "mailto" "news"))
3256 (setq link
(concat type
":" path
))
3257 (setq rpl
(concat "<a href=\""
3258 (org-export-html-format-href link
)
3260 (org-export-html-format-desc desc
)
3263 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3264 ;; The link protocol has a function for format the link
3267 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3269 ((string= type
"file")
3271 (let* ((filename path
)
3272 (abs-p (file-name-absolute-p filename
))
3273 thefile file-is-image-p search
)
3275 (if (string-match "::\\(.*\\)" filename
)
3276 (setq search
(match-string 1 filename
)
3277 filename
(replace-match "" t nil filename
)))
3279 (if (functionp link-validate
)
3280 (funcall link-validate filename current-dir
)
3282 (setq file-is-image-p
(org-file-image-p filename
))
3283 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3284 (when (and org-export-html-link-org-files-as-html
3285 (string-match "\\.org$" thefile
))
3286 (setq thefile
(concat (substring thefile
0
3287 (match-beginning 0))
3288 "." html-extension
))
3290 ;; make sure this is can be used as target search
3291 (not (string-match "^[0-9]*$" search
))
3292 (not (string-match "^\\*" search
))
3293 (not (string-match "^/.*/$" search
)))
3294 (setq thefile
(concat thefile
"#"
3295 (org-solidify-link-text
3296 (org-link-unescape search
)))))
3297 (when (string-match "^file:" desc
)
3298 (setq desc
(replace-match "" t t desc
))
3299 (if (string-match "\\.org$" desc
)
3300 (setq desc
(replace-match "" t t desc
))))))
3301 (setq rpl
(if (and file-is-image-p
3302 (or (eq t org-export-html-inline-images
)
3303 (and org-export-html-inline-images
3305 (concat "<img src=\"" thefile
"\"" attr
"/>")
3306 (concat "<a href=\"" thefile
"\"" attr
">"
3307 (org-export-html-format-desc desc
)
3309 (if (not valid
) (setq rpl desc
))))
3312 ;; just publish the path, as default
3313 (setq rpl
(concat "<i><" type
":"
3314 (save-match-data (org-link-unescape path
))
3316 (setq line
(replace-match rpl t t line
)
3317 start
(+ start
(length rpl
))))
3320 (if (and (string-match org-todo-line-regexp line
)
3321 (match-beginning 2))
3324 (concat (substring line
0 (match-beginning 2))
3326 (if (member (match-string 2 line
)
3329 "\">" (match-string 2 line
)
3330 "</span>" (substring line
(match-end 2)))))
3332 ;; Does this contain a reference to a footnote?
3333 (when org-export-with-footnotes
3335 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3336 (if (get-text-property (match-beginning 2) 'org-protected line
)
3337 (setq start
(match-end 2))
3338 (let ((n (match-string 2 line
)))
3342 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3343 (match-string 1 line
) n n n
)
3347 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3348 ;; This is a headline
3349 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3350 txt
(match-string 2 line
))
3351 (if (string-match quote-re0 txt
)
3352 (setq txt
(replace-match "" t t txt
)))
3353 (if (<= level
(max umax umax-toc
))
3354 (setq head-count
(+ head-count
1)))
3356 ;; Close any local lists before inserting a new header line
3357 (while local-list-type
3358 (org-close-li (car local-list-type
))
3359 (insert (format "</%sl>\n" (car local-list-type
)))
3360 (pop local-list-type
))
3361 (setq local-list-indent nil
3363 (setq first-heading-pos
(or first-heading-pos
(point)))
3364 (org-html-level-start level txt umax
3365 (and org-export-with-toc
(<= level umax
))
3368 (when (string-match quote-re line
)
3369 (org-close-par-maybe)
3373 ((and org-export-with-tables
3374 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3375 (if (not table-open
)
3377 (setq table-open t table-buffer nil table-orig-buffer nil
))
3379 (setq table-buffer
(cons line table-buffer
)
3380 table-orig-buffer
(cons origline table-orig-buffer
))
3381 (when (or (not lines
)
3382 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3384 (setq table-open nil
3385 table-buffer
(nreverse table-buffer
)
3386 table-orig-buffer
(nreverse table-orig-buffer
))
3387 (org-close-par-maybe)
3388 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3393 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3394 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3395 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3396 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3398 (setq ind
(org-get-string-indentation line
)
3399 item-type
(if (match-beginning 4) "o" "u")
3400 starter
(if (match-beginning 2)
3401 (substring (match-string 2 line
) 0 -
1))
3402 line
(substring line
(match-beginning 5))
3404 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3406 item-tag
(match-string 1 line
)
3407 line
(substring line
(match-end 0))))
3408 (when (and (not (equal item-type
"d"))
3409 (not (string-match "[^ \t]" line
)))
3410 ;; empty line. Pretend indentation is large.
3411 (setq ind
(if org-empty-line-terminates-plain-lists
3413 (1+ (or (car local-list-indent
) 1)))))
3415 (while (and in-local-list
3416 (or (and (= ind
(car local-list-indent
))
3418 (< ind
(car local-list-indent
))))
3420 (org-close-li (car local-list-type
))
3421 (insert (format "</%sl>\n" (car local-list-type
)))
3422 (pop local-list-type
) (pop local-list-indent
)
3423 (setq in-local-list local-list-indent
))
3426 (or (not in-local-list
)
3427 (> ind
(car local-list-indent
))))
3428 ;; Start new (level of) list
3429 (org-close-par-maybe)
3431 ((equal item-type
"u") "<ul>\n<li>\n")
3432 ((equal item-type
"o") "<ol>\n<li>\n")
3433 ((equal item-type
"d")
3434 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3435 (push item-type local-list-type
)
3436 (push ind local-list-indent
)
3437 (setq in-local-list t
))
3439 ;; continue current list
3440 (org-close-li (car local-list-type
))
3442 ((equal (car local-list-type
) "d")
3443 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3446 ;; we did close a list, normal text follows: need <p>
3448 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3451 (if (equal (match-string 1 line
) "X")
3453 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3456 ;; Empty lines start a new paragraph. If hand-formatted lists
3457 ;; are not fully interpreted, lines starting with "-", "+", "*"
3458 ;; also start a new paragraph.
3459 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3461 ;; Is this the start of a footnote?
3462 (when org-export-with-footnotes
3463 (when (and (boundp 'footnote-section-tag-regexp
)
3464 (string-match (concat "^" footnote-section-tag-regexp
)
3467 (throw 'nextline nil
))
3468 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3469 (org-close-par-maybe)
3470 (let ((n (match-string 1 line
)))
3471 (setq org-par-open t
3473 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3475 ;; Check if the line break needs to be conserved
3477 ((string-match "\\\\\\\\[ \t]*$" line
)
3478 (setq line
(replace-match "<br/>" t t line
)))
3479 (org-export-preserve-breaks
3480 (setq line
(concat line
"<br/>"))))
3482 (insert line
"\n")))))
3484 ;; Properly close all local lists and other lists
3489 ;; Close any local lists before inserting a new header line
3490 (while local-list-type
3491 (org-close-li (car local-list-type
))
3492 (insert (format "</%sl>\n" (car local-list-type
)))
3493 (pop local-list-type
))
3494 (setq local-list-indent nil
3496 (org-html-level-start 1 nil umax
3497 (and org-export-with-toc
(<= level umax
))
3499 ;; the </div> to close the last text-... div.
3503 (goto-char (point-min))
3504 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3505 (push (match-string 0) footnotes
)
3506 (replace-match "" t t
)))
3508 (insert (format org-export-html-footnotes-section
3509 (or (nth 4 lang-words
) "Footnotes")
3510 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3513 (when (plist-get opt-plist
:auto-postamble
)
3514 (insert "<div id=\"postamble\">")
3515 (when (and org-export-author-info author
)
3516 (insert "<p class=\"author\"> "
3517 (nth 1 lang-words
) ": " author
"\n")
3519 (if (listp (split-string email
",+ *"))
3521 (insert "<a href=\"mailto:" e
"\"><"
3523 (split-string email
",+ *"))
3524 (insert "<a href=\"mailto:" email
"\"><"
3525 email
"></a>\n")))
3527 (when (and date org-export-time-stamp-file
)
3528 (insert "<p class=\"date\"> "
3529 (nth 2 lang-words
) ": "
3531 (when org-export-creator-info
3532 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3533 org-version emacs-major-version
)))
3536 (if org-export-html-with-timestamp
3537 (insert org-export-html-html-helper-timestamp
))
3538 (insert (or (plist-get opt-plist
:postamble
) ""))
3539 (insert "</body>\n</html>\n"))
3541 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3543 (if (eq major-mode default-major-mode
) (html-mode)))
3545 ;; insert the table of contents
3546 (goto-char (point-min))
3548 (if (or (re-search-forward
3549 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3551 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3553 (goto-char (match-beginning 0))
3555 (goto-char first-heading-pos
)
3556 (when (looking-at "\\s-*</p>")
3557 (goto-char (match-end 0))
3559 (insert "<div id=\"table-of-contents\">\n")
3560 (mapc 'insert thetoc
)
3561 (insert "</div>\n"))
3562 ;; remove empty paragraphs and lists
3563 (goto-char (point-min))
3564 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3566 (goto-char (point-min))
3567 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3569 (goto-char (point-min))
3570 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3572 ;; Convert whitespace place holders
3573 (goto-char (point-min))
3575 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3576 (setq n
(get-text-property beg
'org-whitespace
)
3577 end
(next-single-property-change beg
'org-whitespace
))
3579 (delete-region beg end
)
3580 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3581 (make-string n ?x
)))))
3582 (or to-buffer
(save-buffer))
3583 (goto-char (point-min))
3584 (message "Exporting... done")
3585 (if (eq to-buffer
'string
)
3586 (prog1 (buffer-substring (point-min) (point-max))
3587 (kill-buffer (current-buffer)))
3588 (current-buffer)))))
3590 (defun org-export-html-format-href (s)
3591 "Make sure the S is valid as a href reference in an XHTML document."
3594 (while (string-match "&" s start
)
3595 (setq start
(+ (match-beginning 0) 3)
3596 s
(replace-match "&" t t s
)))))
3599 (defun org-export-html-format-desc (s)
3600 "Make sure the S is valid as a description in a link."
3603 (org-html-do-expand s
))
3606 (defvar org-table-colgroup-info nil
)
3607 (defun org-format-table-ascii (lines)
3608 "Format a table for ascii export."
3610 (setq lines
(org-split-string lines
"\n")))
3611 (if (not (string-match "^[ \t]*|" (car lines
)))
3612 ;; Table made by table.el - test for spanning
3615 ;; A normal org table
3616 ;; Get rid of hlines at beginning and end
3617 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3618 (setq lines
(nreverse lines
))
3619 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3620 (setq lines
(nreverse lines
))
3621 (when org-export-table-remove-special-lines
3622 ;; Check if the table has a marking column. If yes remove the
3623 ;; column and the special lines
3624 (setq lines
(org-table-clean-before-export lines
)))
3625 ;; Get rid of the vertical lines except for grouping
3626 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3628 (while (setq line
(pop lines
))
3629 (if (string-match org-table-hline-regexp line
)
3630 (and (string-match "|\\(.*\\)|" line
)
3631 (setq line
(replace-match " \\1" t nil line
)))
3632 (setq start
0 vl1 vl
)
3633 (while (string-match "|" line start
)
3634 (setq start
(match-end 0))
3635 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3639 (defun org-colgroup-info-to-vline-list (info)
3642 (setq last new new
(pop info
))
3643 (if (or (memq last
'(:end
:startend
))
3644 (memq new
'(:start
:startend
)))
3647 (setq vl
(nreverse vl
))
3648 (and vl
(setcar vl nil
))
3651 (defvar org-table-number-regexp
) ; defined in org-table.el
3652 (defun org-format-table-html (lines olines
)
3653 "Find out which HTML converter to use and return the HTML code."
3655 (setq lines
(org-split-string lines
"\n")))
3656 (if (string-match "^[ \t]*|" (car lines
))
3657 ;; A normal org table
3658 (org-format-org-table-html lines
)
3659 ;; Table made by table.el - test for spanning
3660 (let* ((hlines (delq nil
(mapcar
3662 (if (string-match "^[ \t]*\\+-" x
) x
3665 (first (car hlines
))
3666 (ll (and (string-match "\\S-+" first
)
3667 (match-string 0 first
)))
3668 (re (concat "^[ \t]*" (regexp-quote ll
)))
3669 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3671 (if (and (not spanning
)
3672 (not org-export-prefer-native-exporter-for-tables
))
3673 ;; We can use my own converter with HTML conversions
3674 (org-format-table-table-html lines
)
3675 ;; Need to use the code generator in table.el, with the original text.
3676 (org-format-table-table-html-using-table-generate-source olines
)))))
3678 (defvar org-table-number-fraction
) ; defined in org-table.el
3679 (defun org-format-org-table-html (lines &optional splice
)
3680 "Format a table into HTML."
3681 (require 'org-table
)
3682 ;; Get rid of hlines at beginning and end
3683 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3684 (setq lines
(nreverse lines
))
3685 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3686 (setq lines
(nreverse lines
))
3687 (when org-export-table-remove-special-lines
3688 ;; Check if the table has a marking column. If yes remove the
3689 ;; column and the special lines
3690 (setq lines
(org-table-clean-before-export lines
)))
3692 (let ((head (and org-export-highlight-first-table-line
3694 (lambda (x) (string-match "^[ \t]*|-" x
))
3697 tbopen line fields html gr colgropen
)
3698 (if splice
(setq head nil
))
3699 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3701 (while (setq line
(pop lines
))
3703 (if (string-match "^[ \t]*|-" line
)
3706 (push (if head
"</thead>" "</tbody>") html
)
3707 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3708 (setq head nil
) ;; head ends here, first time around
3710 (throw 'next-line t
)))
3711 ;; Break the line into fields
3712 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3713 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3714 (setq nlines
(1+ nlines
) i -
1)
3715 (push (concat "<tr>"
3719 (if (and (< i nlines
)
3720 (string-match org-table-number-regexp x
))
3721 (incf (aref fnum i
)))
3723 (concat (car org-export-table-header-tags
) x
3724 (cdr org-export-table-header-tags
))
3725 (concat (car org-export-table-data-tags
) x
3726 (cdr org-export-table-data-tags
))))
3730 (unless splice
(if tbopen
(push "</tbody>" html
)))
3731 (unless splice
(push "</table>\n" html
))
3732 (setq html
(nreverse html
))
3734 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3737 (setq gr
(pop org-table-colgroup-info
))
3738 (format "%s<col align=\"%s\"></col>%s"
3739 (if (memq gr
'(:start
:startend
))
3741 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3744 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3746 (if (memq gr
'(:end
:startend
))
3747 (progn (setq colgropen nil
) "</colgroup>")
3751 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3752 (push html-table-tag html
))
3753 (concat (mapconcat 'identity html
"\n") "\n")))
3755 (defun org-table-clean-before-export (lines)
3756 "Check if the table has a marking column.
3757 If yes remove the column and the special lines."
3758 (setq org-table-colgroup-info nil
)
3761 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3762 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3765 (setq org-table-clean-did-remove-column nil
)
3770 ((string-match "^[ \t]*| */ *|" x
)
3771 (setq org-table-colgroup-info
3773 (cond ((member x
'("<" "<")) :start
)
3774 ((member x
'(">" ">")) :end
)
3775 ((member x
'("<>" "<>")) :startend
)
3777 (org-split-string x
"[ \t]*|[ \t]*")))
3781 (setq org-table-clean-did-remove-column t
)
3786 ((string-match "^[ \t]*| */ *|" x
)
3787 (setq org-table-colgroup-info
3789 (cond ((member x
'("<" "<")) :start
)
3790 ((member x
'(">" ">")) :end
)
3791 ((member x
'("<>" "<>")) :startend
)
3793 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3795 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3796 nil
) ; ignore this line
3797 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3798 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3799 ;; remove the first column
3800 (replace-match "\\1|" t nil x
))))
3803 (defun org-format-table-table-html (lines)
3804 "Format a table generated by table.el into HTML.
3805 This conversion does *not* use `table-generate-source' from table.el.
3806 This has the advantage that Org-mode's HTML conversions can be used.
3807 But it has the disadvantage, that no cell- or row-spanning is allowed."
3808 (let (line field-buffer
3809 (head org-export-highlight-first-table-line
)
3811 (setq html
(concat html-table-tag
"\n"))
3812 (while (setq line
(pop lines
))
3813 (setq empty
" ")
3815 (if (string-match "^[ \t]*\\+-" line
)
3826 (if (equal x
"") (setq x empty
))
3828 (concat (car org-export-table-header-tags
) x
3829 (cdr org-export-table-header-tags
))
3830 (concat (car org-export-table-data-tags
) x
3831 (cdr org-export-table-data-tags
))))
3835 (setq field-buffer nil
)))
3837 (throw 'next-line t
)))
3838 ;; Break the line into fields and store the fields
3839 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3841 (setq field-buffer
(mapcar
3843 (concat x
"<br/>" (pop fields
)))
3845 (setq field-buffer fields
))))
3846 (setq html
(concat html
"</table>\n"))
3849 (defun org-format-table-table-html-using-table-generate-source (lines)
3850 "Format a table into html, using `table-generate-source' from table.el.
3851 This has the advantage that cell- or row-spanning is allowed.
3852 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3854 (with-current-buffer (get-buffer-create " org-tmp1 ")
3856 (insert (mapconcat 'identity lines
"\n"))
3857 (goto-char (point-min))
3858 (if (not (re-search-forward "|[^+]" nil t
))
3859 (error "Error processing table"))
3860 (table-recognize-table)
3861 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3862 (table-generate-source 'html
" org-tmp2 ")
3863 (set-buffer " org-tmp2 ")
3864 (buffer-substring (point-min) (point-max))))
3866 (defun org-export-splice-style (style extra
)
3867 "Splice EXTRA into STYLE, just before \"</style>\"."
3868 (if (and (stringp extra
)
3869 (string-match "\\S-" extra
)
3870 (string-match "</style>" style
))
3871 (concat (substring style
0 (match-beginning 0))
3873 (substring style
(match-beginning 0)))
3876 (defun org-html-handle-time-stamps (s)
3877 "Format time stamps in string S, or remove them."
3880 (while (string-match org-maybe-keyword-time-regexp s
)
3881 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3882 ;; never export CLOCK
3884 (or b
(setq b
(substring s
0 (match-beginning 0))))
3885 (if (not org-export-with-timestamps
)
3886 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3887 s
(substring s
(match-end 0)))
3889 r
(substring s
0 (match-beginning 0))
3891 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3892 (match-string 1 s
)))
3893 (format " @<span class=\"timestamp\">%s@</span>"
3895 (org-translate-time (match-string 3 s
)) 1 -
1)))
3896 s
(substring s
(match-end 0)))))
3897 ;; Line break if line started and ended with time stamp stuff
3900 (setq r
(concat r s
))
3901 (unless (string-match "\\S-" (concat b s
))
3902 (setq r
(concat r
"@<br/>")))
3905 (defun org-export-htmlize-region-for-paste (beg end
)
3906 "Convert the region to HTML, using htmlize.el.
3907 This is much like `htmlize-region-for-paste', only that it uses
3908 the settings define in the org-... variables."
3909 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3910 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3911 (htmlbuf (htmlize-region beg end
)))
3913 (with-current-buffer htmlbuf
3914 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3915 (plist-get htmlize-buffer-places
'content-end
)))
3916 (kill-buffer htmlbuf
))))
3919 (defun org-export-htmlize-generate-css ()
3920 "Create the CSS for all font definitions in the current Emacs session.
3921 Use this to create face definitions in your CSS style file that can then
3922 be used by code snippets transformed by htmlize.
3923 This command just produces a buffer that contains class definitions for all
3924 faces used in the current Emacs session. You can copy and paste the ones you
3925 need into your CSS file.
3927 If you then set `org-export-htmlize-output-type' to `css', calls to
3928 the function `org-export-htmlize-region-for-paste' will produce code
3929 that uses these same face definitions."
3932 (and (get-buffer "*html*") (kill-buffer "*html*"))
3934 (let ((fl (face-list))
3935 (htmlize-css-name-prefix "org-")
3936 (htmlize-output-type 'css
)
3938 (while (setq f
(pop fl
)
3939 i
(and f
(face-attribute f
:inherit
)))
3940 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3941 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3942 (htmlize-region (point-min) (point-max))))
3943 (switch-to-buffer "*html*")
3944 (goto-char (point-min))
3945 (if (re-search-forward "<style" nil t
)
3946 (delete-region (point-min) (match-beginning 0)))
3947 (if (re-search-forward "</style>" nil t
)
3948 (delete-region (1+ (match-end 0)) (point-max)))
3949 (beginning-of-line 1)
3950 (if (looking-at " +") (replace-match ""))
3951 (goto-char (point-min)))
3953 (defun org-html-protect (s)
3954 ;; convert & to &, < to < and > to >
3956 (while (string-match "&" s start
)
3957 (setq s
(replace-match "&" t t s
)
3958 start
(1+ (match-beginning 0))))
3959 (while (string-match "<" s
)
3960 (setq s
(replace-match "<" t t s
)))
3961 (while (string-match ">" s
)
3962 (setq s
(replace-match ">" t t s
)))
3963 ; (while (string-match "\"" s)
3964 ; (setq s (replace-match """ t t s)))
3968 (defun org-export-cleanup-toc-line (s)
3969 "Remove tags and time staps from lines going into the toc."
3970 (when (memq org-export-with-tags
'(not-in-toc nil
))
3971 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3972 (setq s
(replace-match "" t t s
))))
3973 (when org-export-remove-timestamps-from-toc
3974 (while (string-match org-maybe-keyword-time-regexp s
)
3975 (setq s
(replace-match "" t t s
))))
3976 (while (string-match org-bracket-link-regexp s
)
3977 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3981 (defun org-html-expand (string)
3982 "Prepare STRING for HTML export. Applies all active conversions.
3983 If there are links in the string, don't modify these."
3984 (let* ((re (concat org-bracket-link-regexp
"\\|"
3985 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3987 (while (setq m
(string-match re string
))
3988 (setq s
(substring string
0 m
)
3989 l
(match-string 0 string
)
3990 string
(substring string
(match-end 0)))
3991 (push (org-html-do-expand s
) res
)
3993 (push (org-html-do-expand string
) res
)
3994 (apply 'concat
(nreverse res
))))
3996 (defun org-html-do-expand (s)
3997 "Apply all active conversions to translate special ASCII to HTML."
3998 (setq s
(org-html-protect s
))
3999 (if org-export-html-expand
4001 (while (string-match "@<\\([^&]*\\)>" s
)
4002 (setq s
(replace-match "<\\1>" t nil s
)))))
4003 (if org-export-with-emphasize
4004 (setq s
(org-export-html-convert-emphasize s
)))
4005 (if org-export-with-special-strings
4006 (setq s
(org-export-html-convert-special-strings s
)))
4007 (if org-export-with-sub-superscripts
4008 (setq s
(org-export-html-convert-sub-super s
)))
4009 (if org-export-with-TeX-macros
4010 (let ((start 0) wd ass
)
4011 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4013 (if (get-text-property (match-beginning 0) 'org-protected s
)
4014 (setq start
(match-end 0))
4015 (setq wd
(match-string 1 s
))
4016 (if (setq ass
(assoc wd org-html-entities
))
4017 (setq s
(replace-match (or (cdr ass
)
4018 (concat "&" (car ass
) ";"))
4020 (setq start
(+ start
(length wd
))))))))
4023 (defun org-create-multibrace-regexp (left right n
)
4024 "Create a regular expression which will match a balanced sexp.
4025 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4026 as single character strings.
4027 The regexp returned will match the entire expression including the
4028 delimiters. It will also define a single group which contains the
4029 match except for the outermost delimiters. The maximum depth of
4030 stacked delimiters is N. Escaping delimiters is not possible."
4031 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4034 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4037 re
(concat re or next
)
4038 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4039 (concat left
"\\(" re
"\\)" right
)))
4041 (defvar org-match-substring-regexp
4043 "\\([^\\]\\)\\([_^]\\)\\("
4044 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4046 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4048 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4049 "The regular expression matching a sub- or superscript.")
4051 (defvar org-match-substring-with-braces-regexp
4053 "\\([^\\]\\)\\([_^]\\)\\("
4054 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4056 "The regular expression matching a sub- or superscript, forcing braces.")
4058 (defconst org-export-html-special-string-regexps
4059 '(("\\\\-" .
"­")
4060 ("---\\([^-]\\)" .
"—\\1")
4061 ("--\\([^-]\\)" .
"–\\1")
4062 ("\\.\\.\\." .
"…"))
4063 "Regular expressions for special string conversion.")
4065 (defun org-export-html-convert-special-strings (string)
4066 "Convert special characters in STRING to HTML."
4067 (let ((all org-export-html-special-string-regexps
)
4069 (while (setq a
(pop all
))
4070 (setq re
(car a
) rpl
(cdr a
) start
0)
4071 (while (string-match re string start
)
4072 (if (get-text-property (match-beginning 0) 'org-protected string
)
4073 (setq start
(match-end 0))
4074 (setq string
(replace-match rpl t nil string
)))))
4077 (defun org-export-html-convert-sub-super (string)
4078 "Convert sub- and superscripts in STRING to HTML."
4079 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4080 (while (string-match org-match-substring-regexp string s
)
4082 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4083 ((get-text-property (match-beginning 2) 'org-protected string
)
4084 (setq s
(match-end 2)))
4086 (setq s
(match-end 1)
4087 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4088 c
(or (match-string 8 string
)
4089 (match-string 6 string
)
4090 (match-string 5 string
))
4091 string
(replace-match
4092 (concat (match-string 1 string
)
4093 "<" key
">" c
"</" key
">")
4095 (while (string-match "\\\\\\([_^]\\)" string
)
4096 (setq string
(replace-match (match-string 1 string
) t t string
)))
4099 (defun org-export-html-convert-emphasize (string)
4102 (while (string-match org-emph-re string s
)
4104 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4105 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4106 (setq s
(match-beginning 0)
4109 (match-string 1 string
)
4110 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4111 (match-string 4 string
)
4112 (nth 3 (assoc (match-string 3 string
)
4113 org-emphasis-alist
))
4114 (match-string 5 string
))
4115 string
(replace-match rpl t t string
)
4116 s
(+ s
(- (length rpl
) 2)))
4120 (defun org-open-par ()
4121 "Insert <p>, but first close previous paragraph if any."
4122 (org-close-par-maybe)
4124 (setq org-par-open t
))
4125 (defun org-close-par-maybe ()
4126 "Close paragraph if there is one open."
4129 (setq org-par-open nil
)))
4130 (defun org-close-li (&optional type
)
4131 "Close <li> if necessary."
4132 (org-close-par-maybe)
4133 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4135 (defvar body-only
) ; dynamically scoped into this.
4136 (defun org-html-level-start (level title umax with-toc head-count
)
4137 "Insert a new level in HTML export.
4138 When TITLE is nil, just close all open levels."
4139 (org-close-par-maybe)
4140 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
4144 (if (aref org-levels-open
(1- l
))
4146 (org-html-level-close l umax
)
4147 (aset org-levels-open
(1- l
) nil
)))
4150 ;; If title is nil, this means this function is called to close
4151 ;; all levels, so the rest is done only if title is given
4152 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4153 (setq title
(replace-match
4154 (if org-export-with-tags
4157 " <span class=\"tag\">"
4158 (mapconcat 'identity
(org-split-string
4159 (match-string 1 title
) ":")
4166 (if (aref org-levels-open
(1- level
))
4170 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
4171 (insert "<li>" title
"<br/>\n")))
4172 (aset org-levels-open
(1- level
) t
)
4173 (org-close-par-maybe)
4175 (insert (format "<ul>\n<li id=\"%s\">" target
)
4177 (insert "<ul>\n<li>" title
"<br/>\n"))))
4178 (aset org-levels-open
(1- level
) t
)
4179 (setq snumber
(org-section-number level
))
4180 (if (and org-export-with-section-numbers
(not body-only
))
4181 (setq title
(concat snumber
" " title
)))
4182 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4183 (unless (= head-count
1) (insert "\n</div>\n"))
4184 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
4185 snumber level level snumber title level snumber
))
4188 (defun org-get-text-property-any (pos prop
&optional object
)
4189 (or (get-text-property pos prop object
)
4190 (and (setq pos
(next-single-property-change pos prop object
))
4191 (get-text-property pos prop object
))))
4193 (defun org-html-level-close (level max-outline-level
)
4194 "Terminate one level in HTML export."
4195 (if (<= level max-outline-level
)
4198 (insert "</ul>\n")))
4200 ;;; iCalendar export
4203 (defun org-export-icalendar-this-file ()
4204 "Export current file as an iCalendar file.
4205 The iCalendar file will be located in the same directory as the Org-mode
4206 file, but with extension `.ics'."
4208 (org-export-icalendar nil buffer-file-name
))
4211 (defun org-export-icalendar-all-agenda-files ()
4212 "Export all files in `org-agenda-files' to iCalendar .ics files.
4213 Each iCalendar file will be located in the same directory as the Org-mode
4214 file, but with extension `.ics'."
4216 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4219 (defun org-export-icalendar-combine-agenda-files ()
4220 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4221 The file is stored under the name `org-combined-agenda-icalendar-file'."
4223 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4225 (defun org-export-icalendar (combine &rest files
)
4226 "Create iCalendar files for all elements of FILES.
4227 If COMBINE is non-nil, combine all calendar entries into a single large
4228 file and store it under the name `org-combined-agenda-icalendar-file'."
4230 (org-prepare-agenda-buffers files
)
4231 (let* ((dir (org-export-directory
4232 :ical
(list :publishing-directory
4233 org-export-publishing-directory
)))
4234 file ical-file ical-buffer category started org-agenda-new-buffers
)
4235 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4238 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4239 org-combined-agenda-icalendar-file
4240 (expand-file-name org-combined-agenda-icalendar-file dir
))
4241 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4242 (set-buffer ical-buffer
) (erase-buffer))
4243 (while (setq file
(pop files
))
4245 (org-check-agenda-file file
)
4246 (set-buffer (org-get-agenda-file-buffer file
))
4248 (setq ical-file
(concat (file-name-as-directory dir
)
4249 (file-name-sans-extension
4250 (file-name-nondirectory buffer-file-name
))
4252 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4253 (with-current-buffer ical-buffer
(erase-buffer)))
4254 (setq category
(or org-category
4255 (file-name-sans-extension
4256 (file-name-nondirectory buffer-file-name
))))
4257 (if (symbolp category
) (setq category
(symbol-name category
)))
4258 (let ((standard-output ical-buffer
))
4260 (and (not started
) (setq started t
)
4261 (org-start-icalendar-file org-icalendar-combined-name
))
4262 (org-start-icalendar-file category
))
4263 (org-print-icalendar-entries combine
)
4264 (when (or (and combine
(not files
)) (not combine
))
4265 (org-finish-icalendar-file)
4266 (set-buffer ical-buffer
)
4267 (run-hooks 'org-before-save-iCalendar-file-hook
)
4269 (run-hooks 'org-after-save-iCalendar-file-hook
)
4270 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4272 (org-release-buffers org-agenda-new-buffers
))))
4274 (defvar org-before-save-iCalendar-file-hook nil
4275 "Hook run before an iCalendar file has been saved.
4276 This can be used to modify the result of the export.")
4278 (defvar org-after-save-iCalendar-file-hook nil
4279 "Hook run after an iCalendar file has been saved.
4280 The iCalendar buffer is still current when this hook is run.
4281 A good way to use this is to tell a desktop calenndar application to re-read
4282 the iCalendar file.")
4284 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4285 (defun org-print-icalendar-entries (&optional combine
)
4286 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4287 When COMBINE is non nil, add the category to each line."
4288 (require 'org-agenda
)
4289 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4290 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4291 (dts (org-ical-ts-to-string
4292 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4294 hd ts ts2 state status
(inc t
) pos b sexp rrule
4295 scheduledp deadlinep todo prefix due start
4296 tmp pri categories entry location summary desc uid
4297 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4298 (org-refresh-category-properties)
4300 (goto-char (point-min))
4301 (while (re-search-forward re1 nil t
)
4304 (when (boundp 'org-icalendar-verify-function
)
4305 (unless (funcall org-icalendar-verify-function
)
4306 (outline-next-heading)
4309 (setq pos
(match-beginning 0)
4312 hd
(condition-case nil
4313 (org-icalendar-cleanup-string
4315 (error (throw :skip nil
)))
4316 summary
(org-icalendar-cleanup-string
4317 (org-entry-get nil
"SUMMARY"))
4318 desc
(org-icalendar-cleanup-string
4319 (or (org-entry-get nil
"DESCRIPTION")
4320 (and org-icalendar-include-body
(org-get-entry)))
4321 t org-icalendar-include-body
)
4322 location
(org-icalendar-cleanup-string
4323 (org-entry-get nil
"LOCATION"))
4324 uid
(if org-icalendar-store-UID
4326 (or (org-id-get) (org-id-new)))
4327 categories
(org-export-get-categories)
4328 deadlinep nil scheduledp nil
)
4329 (if (looking-at re2
)
4331 (goto-char (match-end 0))
4332 (setq ts2
(match-string 1)
4333 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4334 (setq tmp
(buffer-substring (max (point-min)
4335 (- pos org-ds-keyword-length
))
4337 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4340 (replace-match "\\1" t nil ts
))
4342 deadlinep
(string-match org-deadline-regexp tmp
)
4343 scheduledp
(string-match org-scheduled-regexp tmp
)
4344 todo
(org-get-todo-state)
4345 ;; donep (org-entry-is-done-p)
4350 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4351 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4356 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4357 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4359 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4360 (if (or (string-match org-tr-regexp hd
)
4361 (string-match org-ts-regexp hd
))
4362 (setq hd
(replace-match "" t t hd
)))
4363 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4365 (concat "\nRRULE:FREQ="
4368 '(("d" .
"DAILY")("w" .
"WEEKLY")
4369 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4370 ";INTERVAL=" (match-string 1 ts
)))
4372 (setq summary
(or summary hd
))
4373 (if (string-match org-bracket-link-regexp summary
)
4375 (replace-match (if (match-end 3)
4376 (match-string 3 summary
)
4377 (match-string 1 summary
))
4379 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4380 (if scheduledp
(setq summary
(concat "S: " summary
)))
4381 (if (string-match "\\`<%%" ts
)
4382 (with-current-buffer sexp-buffer
4383 (insert (substring ts
1 -
1) " " summary
"\n"))
4384 (princ (format "BEGIN:VEVENT
4392 (org-ical-ts-to-string ts
"DTSTART")
4393 (org-ical-ts-to-string ts2
"DTEND" inc
)
4395 (if (and desc
(string-match "\\S-" desc
))
4396 (concat "\nDESCRIPTION: " desc
) "")
4397 (if (and location
(string-match "\\S-" location
))
4398 (concat "\nLOCATION: " location
) "")
4400 (when (and org-icalendar-include-sexps
4401 (condition-case nil
(require 'icalendar
) (error nil
))
4402 (fboundp 'icalendar-export-region
))
4403 ;; Get all the literal sexps
4404 (goto-char (point-min))
4405 (while (re-search-forward "^&?%%(" nil t
)
4408 (setq b
(match-beginning 0))
4409 (goto-char (1- (match-end 0)))
4412 (setq sexp
(buffer-substring b
(point)))
4413 (with-current-buffer sexp-buffer
4414 (insert sexp
"\n"))))
4415 (princ (org-diary-to-ical-string sexp-buffer
))
4416 (kill-buffer sexp-buffer
))
4418 (when org-icalendar-include-todo
4419 (setq prefix
"TODO-")
4420 (goto-char (point-min))
4421 (while (re-search-forward org-todo-line-regexp nil t
)
4424 (when (boundp 'org-icalendar-verify-function
)
4425 (unless (funcall org-icalendar-verify-function
)
4426 (outline-next-heading)
4429 (setq state
(match-string 2))
4430 (setq status
(if (member state org-done-keywords
)
4431 "COMPLETED" "NEEDS-ACTION"))
4433 (or (not (member state org-done-keywords
))
4434 (eq org-icalendar-include-todo
'all
))
4435 (not (member org-archive-tag
(org-get-tags-at)))
4437 (setq hd
(match-string 3)
4438 summary
(org-icalendar-cleanup-string
4439 (org-entry-get nil
"SUMMARY"))
4440 desc
(org-icalendar-cleanup-string
4441 (or (org-entry-get nil
"DESCRIPTION")
4442 (and org-icalendar-include-body
(org-get-entry)))
4443 t org-icalendar-include-body
)
4444 location
(org-icalendar-cleanup-string
4445 (org-entry-get nil
"LOCATION"))
4446 due
(and (member 'todo-due org-icalendar-use-deadline
)
4447 (org-entry-get nil
"DEADLINE"))
4448 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4449 (org-entry-get nil
"SCHEDULED"))
4450 categories
(org-export-get-categories)
4451 uid
(if org-icalendar-store-UID
4453 (or (org-id-get) (org-id-new))))
4454 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4455 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4457 (if (string-match org-bracket-link-regexp hd
)
4458 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4459 (match-string 1 hd
))
4461 (if (string-match org-priority-regexp hd
)
4462 (setq pri
(string-to-char (match-string 2 hd
))
4463 hd
(concat (substring hd
0 (match-beginning 1))
4464 (substring hd
(match-end 1))))
4465 (setq pri org-default-priority
))
4466 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4467 (- org-lowest-priority org-highest-priority
))))))
4469 (princ (format "BEGIN:VTODO
4481 (if (and location
(string-match "\\S-" location
))
4482 (concat "\nLOCATION: " location
) "")
4483 (if (and desc
(string-match "\\S-" desc
))
4484 (concat "\nDESCRIPTION: " desc
) "")
4485 (if due
(concat "\n" due
) "")
4489 (defun org-export-get-categories ()
4490 "Get categories according to `org-icalendar-categories'."
4491 (let ((cs org-icalendar-categories
) c rtn tmp
)
4492 (while (setq c
(pop cs
))
4494 ((eq c
'category
) (push (org-get-category) rtn
))
4496 (setq tmp
(org-get-todo-state))
4497 (and tmp
(push tmp rtn
)))
4499 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4501 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4502 (mapconcat 'identity
(nreverse rtn
) ",")))
4504 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4505 "Take out stuff and quote what needs to be quoted.
4506 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4507 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4512 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4513 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4514 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4515 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4517 (while (string-match "\\([,;]\\)" s start
)
4518 (setq start
(+ (match-beginning 0) 2)
4519 s
(replace-match "\\\\\\1" nil nil s
))))
4521 (while (string-match "[ \t]*\n[ \t]*" s
)
4522 (setq s
(replace-match "\\n" t t s
))))
4523 (setq s
(org-trim s
))
4526 (if (and (numberp maxlength
)
4527 (> (length s
) maxlength
))
4528 (setq s
(substring s
0 maxlength
)))))
4531 (defun org-get-entry ()
4532 "Clean-up description string."
4534 (org-back-to-heading t
)
4535 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4537 (defun org-start-icalendar-file (name)
4538 "Start an iCalendar file by inserting the header."
4539 (let ((user user-full-name
)
4540 (name (or name
"unknown"))
4541 (timezone (cadr (current-time-zone))))
4543 (format "BEGIN:VCALENDAR
4546 PRODID:-//%s//Emacs with Org-mode//EN
4548 CALSCALE:GREGORIAN\n" name user timezone
))))
4550 (defun org-finish-icalendar-file ()
4551 "Finish an iCalendar file by inserting the END statement."
4552 (princ "END:VCALENDAR\n"))
4554 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4555 "Take a time string S and convert it to iCalendar format.
4556 KEYWORD is added in front, to make a complete line like DTSTART....
4557 When INC is non-nil, increase the hour by two (if time string contains
4558 a time), or the day by one (if it does not contain a time)."
4559 (let ((t1 (org-parse-time-string s
'nodefault
))
4560 t2 fmt have-time time
)
4561 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4562 (setq t2 t1 have-time t
)
4563 (setq t2
(org-parse-time-string s
)))
4564 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4565 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4568 (if org-agenda-default-appointment-duration
4569 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4572 (setq time
(encode-time s mi h d m y
)))
4573 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4574 (concat keyword
(format-time-string fmt time
))))
4578 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4579 (with-current-buffer buffer
4580 (apply 'insert output
)))
4581 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4584 (defun org-export-as-xoxo (&optional buffer
)
4585 "Export the org buffer as XOXO.
4586 The XOXO buffer is named *xoxo-<source buffer name>*"
4587 (interactive (list (current-buffer)))
4588 ;; A quickie abstraction
4590 ;; Output everything as XOXO
4591 (with-current-buffer (get-buffer buffer
)
4592 (let* ((pos (point))
4593 (opt-plist (org-combine-plists (org-default-export-plist)
4594 (org-infile-export-plist)))
4595 (filename (concat (file-name-as-directory
4596 (org-export-directory :xoxo opt-plist
))
4597 (file-name-sans-extension
4598 (file-name-nondirectory buffer-file-name
))
4600 (out (find-file-noselect filename
))
4603 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4604 ;; Check the output buffer is empty.
4605 (with-current-buffer out
(erase-buffer))
4606 ;; Kick off the output
4607 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4608 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4609 (let* ((hd (match-string-no-properties 1))
4612 (match-string-no-properties 2)
4614 (goto-char (match-end 0))
4619 (if (looking-at "^[ \t]\\(.*\\)")
4620 (setq str
(concat str
(match-string-no-properties 1)))
4621 (throw 'loop str
)))))))))
4623 ;; Handle level rendering
4625 ((> level last-level
)
4626 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4628 ((< level last-level
)
4629 (dotimes (- (- last-level level
) 1)
4631 (org-export-as-xoxo-insert-into out
"</li>\n"))
4632 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4634 (org-export-as-xoxo-insert-into out
"</li>\n")
4635 (setq hanging-li nil
)))
4637 ((equal level last-level
)
4639 (org-export-as-xoxo-insert-into out
"</li>\n")))
4642 (setq last-level level
)
4644 ;; And output the new li
4645 (setq hanging-li
't
)
4646 (if (equal ?
+ (elt text
0))
4647 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4648 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4650 ;; Finally finish off the ol
4651 (dotimes (- last-level
1)
4653 (org-export-as-xoxo-insert-into out
"</li>\n"))
4654 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4657 ;; Finish the buffer off and clean it up.
4658 (switch-to-buffer-other-window out
)
4659 (indent-region (point-min) (point-max) nil
)
4661 (goto-char (point-min))
4666 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4668 ;;; org-exp.el ends here