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 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
106 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "Índice" "Pies de página")
108 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
110 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
111 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis treści" "Przypis")
118 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group
'org-export-general
125 (string :tag
"HTML language tag")
126 (string :tag
"Author")
128 (string :tag
"Table of Contents")
129 (string :tag
"Footnotes"))))
131 (defcustom org-export-default-language
"en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group
'org-export-general
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group
'org-export-general
143 (defcustom org-export-headline-levels
3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group
'org-export-general
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group
'org-export-general
160 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
172 :group
'org-export-general
176 (string :tag
"Counter Type")
177 (string :tag
"Separator ")))
178 (string :tag
"Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
196 :group
'org-export-general
198 (const :tag
"No Table of Contents" nil
)
199 (const :tag
"Full Table of Contents" t
)
200 (integer :tag
"TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group
'org-export-general
207 (defcustom org-export-preserve-breaks nil
208 "Non-nil means, preserve all line breaks when exporting.
209 Normally, in HTML output paragraphs will be reformatted. In ASCII
210 export, line breaks will always be preserved, regardless of this variable.
212 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
213 :group
'org-export-general
216 (defcustom org-export-with-archived-trees
'headline
217 "Whether subtrees with the ARCHIVE tag should be exported.
218 This can have three different values
219 nil Do not export, pretend this tree is not present
220 t Do export the entire tree
221 headline Only export the headline, but skip the tree below it."
222 :group
'org-export-general
225 (const :tag
"not at all" nil
)
226 (const :tag
"headline only" 'headline
)
227 (const :tag
"entirely" t
)))
229 (defcustom org-export-author-info t
230 "Non-nil means, insert author name and email into the exported file.
232 This option can also be set with the +OPTIONS line,
233 e.g. \"author-info:nil\"."
234 :group
'org-export-general
237 (defcustom org-export-creator-info t
238 "Non-nil means, the postamle should contain a creator sentence.
239 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
240 :group
'org-export-general
243 (defcustom org-export-time-stamp-file t
244 "Non-nil means, insert a time stamp into the exported file.
245 The time stamp shows when the file was created.
247 This option can also be set with the +OPTIONS line,
248 e.g. \"timestamp:nil\"."
249 :group
'org-export-general
252 (defcustom org-export-with-timestamps t
253 "If nil, do not export time stamps and associated keywords."
254 :group
'org-export-general
257 (defcustom org-export-remove-timestamps-from-toc t
258 "If nil, remove timestamps from the table of contents entries."
259 :group
'org-export-general
262 (defcustom org-export-with-tags
'not-in-toc
263 "If nil, do not export tags, just remove them from headlines.
264 If this is the symbol `not-in-toc', tags will be removed from table of
265 contents entries, but still be shown in the headlines of the document.
267 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
268 :group
'org-export-general
270 (const :tag
"Off" nil
)
271 (const :tag
"Not in TOC" not-in-toc
)
272 (const :tag
"On" t
)))
274 (defcustom org-export-with-drawers nil
275 "Non-nil means, export with drawers like the property drawer.
276 When t, all drawers are exported. This may also be a list of
277 drawer names to export."
278 :group
'org-export-general
280 (const :tag
"All drawers" t
)
281 (const :tag
"None" nil
)
282 (repeat :tag
"Selected drawers"
283 (string :tag
"Drawer name"))))
285 (defvar org-export-preprocess-hook nil
286 "Hook for preprocessing an export buffer.
287 Pretty much the first thing when exporting is running this hook.")
289 (defgroup org-export-translation nil
290 "Options for translating special ascii sequences for the export backends."
291 :tag
"Org Export Translation"
294 (defcustom org-export-with-emphasize t
295 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
296 If the export target supports emphasizing text, the word will be
297 typeset in bold, italic, or underlined, respectively. Works only for
298 single words, but you can say: I *really* *mean* *this*.
299 Not all export backends support this.
301 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
302 :group
'org-export-translation
305 (defcustom org-export-with-footnotes t
306 "If nil, export [1] as a footnote marker.
307 Lines starting with [1] will be formatted as footnotes.
309 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
310 :group
'org-export-translation
313 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
314 <h2 class=\"footnotes\">%s: </h2>
315 <div id=\"footnotes-text\">
319 "Format for the footnotes section.
320 Should contain a two instances of %s. The first will be replaced with the
321 language-specific word for \"Footnotes\", the second one will be replaced
322 by the footnotes themselves."
323 :group
'org-export-html
326 (defcustom org-export-with-sub-superscripts t
327 "Non-nil means, interpret \"_\" and \"^\" for export.
328 When this option is turned on, you can use TeX-like syntax for sub- and
329 superscripts. Several characters after \"_\" or \"^\" will be
330 considered as a single item - so grouping with {} is normally not
331 needed. For example, the following things will be parsed as single
332 sub- or superscripts.
334 10^24 or 10^tau several digits will be considered 1 item.
335 10^-12 or 10^-tau a leading sign with digits or a word
336 x^2-y^3 will be read as x^2 - y^3, because items are
337 terminated by almost any nonword/nondigit char.
338 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
340 Still, ambiguity is possible - so when in doubt use {} to enclose the
341 sub/superscript. If you set this variable to the symbol `{}',
342 the braces are *required* in order to trigger interpretations as
343 sub/superscript. This can be helpful in documents that need \"_\"
344 frequently in plain text.
346 Not all export backends support this, but HTML does.
348 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
349 :group
'org-export-translation
351 (const :tag
"Always interpret" t
)
352 (const :tag
"Only with braces" {})
353 (const :tag
"Never interpret" nil
)))
355 (defcustom org-export-with-special-strings t
356 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
357 When this option is turned on, these strings will be exported as:
363 Not all export backends support this, but HTML does.
365 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
366 :group
'org-export-translation
369 (defcustom org-export-with-TeX-macros t
370 "Non-nil means, interpret simple TeX-like macros when exporting.
371 For example, HTML export converts \\alpha to α and \\AA to Å.
372 No only real TeX macros will work here, but the standard HTML entities
373 for math can be used as macro names as well. For a list of supported
374 names in HTML export, see the constant `org-html-entities'.
375 Not all export backends support this.
377 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
378 :group
'org-export-translation
379 :group
'org-export-latex
382 (defcustom org-export-with-LaTeX-fragments nil
383 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
384 When set, the exporter will find LaTeX environments if the \\begin line is
385 the first non-white thing on a line. It will also find the math delimiters
386 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
389 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
390 :group
'org-export-translation
391 :group
'org-export-latex
394 (defcustom org-export-with-fixed-width t
395 "Non-nil means, lines starting with \":\" will be in fixed width font.
396 This can be used to have pre-formatted text, fragments of code etc. For
398 : ;; Some Lisp examples
401 will be looking just like this in also HTML. See also the QUOTE keyword.
402 Not all export backends support this.
404 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
405 :group
'org-export-translation
408 (defcustom org-match-sexp-depth
3
409 "Number of stacked braces for sub/superscript matching.
410 This has to be set before loading org.el to be effective."
411 :group
'org-export-translation
414 (defgroup org-export-tables nil
415 "Options for exporting tables in Org-mode."
416 :tag
"Org Export Tables"
419 (defcustom org-export-with-tables t
420 "If non-nil, lines starting with \"|\" define a table.
423 | Name | Address | Birthday |
424 |-------------+----------+-----------|
425 | Arthur Dent | England | 29.2.2100 |
427 Not all export backends support this.
429 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
430 :group
'org-export-tables
433 (defcustom org-export-highlight-first-table-line t
434 "Non-nil means, highlight the first table line.
435 In HTML export, this means use <th> instead of <td>.
436 In tables created with table.el, this applies to the first table line.
437 In Org-mode tables, all lines before the first horizontal separator
438 line will be formatted with <th> tags."
439 :group
'org-export-tables
442 (defcustom org-export-table-remove-special-lines t
443 "Remove special lines and marking characters in calculating tables.
444 This removes the special marking character column from tables that are set
445 up for spreadsheet calculations. It also removes the entire lines
446 marked with `!', `_', or `^'. The lines with `$' are kept, because
447 the values of constants may be useful to have."
448 :group
'org-export-tables
451 (defcustom org-export-prefer-native-exporter-for-tables nil
452 "Non-nil means, always export tables created with table.el natively.
453 Natively means, use the HTML code generator in table.el.
454 When nil, Org-mode's own HTML generator is used when possible (i.e. if
455 the table does not use row- or column-spanning). This has the
456 advantage, that the automatic HTML conversions for math symbols and
457 sub/superscripts can be applied. Org-mode's HTML generator is also
459 :group
'org-export-tables
462 (defgroup org-export-ascii nil
463 "Options specific for ASCII export of Org-mode files."
464 :tag
"Org Export ASCII"
467 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
468 "Characters for underlining headings in ASCII export.
469 In the given sequence, these characters will be used for level 1, 2, ..."
470 :group
'org-export-ascii
471 :type
'(repeat character
))
473 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
474 "Bullet characters for headlines converted to lists in ASCII export.
475 The first character is used for the first lest level generated in this
476 way, and so on. If there are more levels than characters given here,
477 the list will be repeated.
478 Note that plain lists will keep the same bullets as the have in the
480 :group
'org-export-ascii
481 :type
'(repeat character
))
483 (defgroup org-export-xml nil
484 "Options specific for XML export of Org-mode files."
485 :tag
"Org Export XML"
488 (defgroup org-export-html nil
489 "Options specific for HTML export of Org-mode files."
490 :tag
"Org Export HTML"
493 (defcustom org-export-html-coding-system nil
494 "Coding system for HTML export, defaults to buffer-file-coding-system."
495 :group
'org-export-html
496 :type
'coding-system
)
498 (defcustom org-export-html-extension
"html"
499 "The extension for exported HTML files."
500 :group
'org-export-html
503 (defcustom org-export-html-link-up
""
504 "Where should the \"UP\" link of exported HTML pages lead?"
505 :group
'org-export-html
506 :type
'(string :tag
"File or URL"))
508 (defcustom org-export-html-link-home
""
509 "Where should the \"HOME\" link of exported HTML pages lead?"
510 :group
'org-export-html
511 :type
'(string :tag
"File or URL"))
513 (defconst org-export-html-style-default
514 "<style type=\"text/css\">
516 html { font-family: Times, serif; font-size: 12pt; }
517 .title { text-align: center; }
518 .todo { color: red; }
519 .done { color: green; }
520 .tag { background-color:lightblue; font-weight:normal }
522 .timestamp { color: grey }
523 .timestamp-kwd { color: CadetBlue }
524 p.verse { margin-left: 3% }
526 border: 1pt solid #AEBDCC;
527 background-color: #F3F5F7;
529 font-family: courier, monospace;
533 table { border-collapse: collapse; }
534 td, th { vertical-align: top; }
535 dt { font-weight: bold; }
537 .org-info-js_info-navigation { border-style:none; }
538 #org-info-js_console-label { font-size:10px; font-weight:bold;
539 white-space:nowrap; }
540 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
544 "The default style specification for exported HTML files.
545 Please use the variables `org-export-html-style' and
546 `org-export-html-style-extra' to add to this style. If you wish to not
547 have the default style included, customize the variable
548 `org-export-html-style-include-default'.")
550 (defcustom org-export-html-style-include-default t
551 "Non-nil means, include the default style in exported HTML files.
552 The actualy style is defined in `org-export-html-style-default' and should
553 not be modified. Use the variables `org-export-html-style' to add
554 your own style information."
555 :group
'org-export-html
558 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
560 (defcustom org-export-html-style
""
561 "Org-wide style definitions for exported HTML files.
563 This variable needs to contain the full HTML structure to provide a style,
564 including the surrounding HTML tags. If you set the value of this variable,
565 you should consider to include definitions for the following classes:
566 title, todo, done, timestamp, timestamp-kwd, tag, target.
568 For example, a valid value would be:
570 <style type=\"text/css\">
572 p { font-weight: normal; color: gray; }
574 .title { text-align: center; }
575 .todo, .timestamp-kwd { color: red; }
576 .done { color: green; }
580 If you'd like to refer to en external style file, use something like
582 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
584 As the value of this option simply gets inserted into the HTML <head> header,
585 you can \"misuse\" it to add arbitrary text to the header.
586 See also the variable `org-export-html-style-extra'."
587 :group
'org-export-html
590 (put 'org-export-html-style
'safe-local-variable
'stringp
)
592 (defcustom org-export-html-style-extra
""
593 "Additional style information for HTML export.
594 The value of this variable is inserted into the HTML buffer right after
595 the value of `org-export-html-style'. Use this variable for per-file
596 settings of style information, and do not forget to surround the style
597 settings with <style>...</style> tags."
598 :group
'org-export-html
601 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
604 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
605 "Format for typesetting the document title in HTML export."
606 :group
'org-export-html
609 (defcustom org-export-html-toplevel-hlevel
2
610 "The <H> level for level 1 headings in HTML export."
611 :group
'org-export-html
614 (defcustom org-export-html-link-org-files-as-html t
615 "Non-nil means, make file links to `file.org' point to `file.html'.
616 When org-mode is exporting an org-mode file to HTML, links to
617 non-html files are directly put into a href tag in HTML.
618 However, links to other Org-mode files (recognized by the
619 extension `.org.) should become links to the corresponding html
620 file, assuming that the linked org-mode file will also be
622 When nil, the links still point to the plain `.org' file."
623 :group
'org-export-html
626 (defcustom org-export-html-inline-images
'maybe
627 "Non-nil means, inline images into exported HTML pages.
628 This is done using an <img> tag. When nil, an anchor with href is used to
629 link to the image. If this option is `maybe', then images in links with
630 an empty description will be inlined, while images with a description will
632 :group
'org-export-html
633 :type
'(choice (const :tag
"Never" nil
)
634 (const :tag
"Always" t
)
635 (const :tag
"When there is no description" maybe
)))
638 (defcustom org-export-html-expand t
639 "Non-nil means, for HTML export, treat @<...> as HTML tag.
640 When nil, these tags will be exported as plain text and therefore
641 not be interpreted by a browser.
643 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
644 :group
'org-export-html
647 (defcustom org-export-html-table-tag
648 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
649 "The HTML tag that is used to start a table.
650 This must be a <table> tag, but you may change the options like
651 borders and spacing."
652 :group
'org-export-html
655 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
656 "The opening tag for table header 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-table-data-tags
'("<td>" .
"</td>")
662 "The opening tag for table data fields.
663 This is customizable so that alignment options can be specified."
664 :group
'org-export-tables
665 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
667 (defcustom org-export-html-with-timestamp nil
668 "If non-nil, write `org-export-html-html-helper-timestamp'
669 into the exported HTML text. Otherwise, the buffer will just be saved
671 :group
'org-export-html
674 (defcustom org-export-html-html-helper-timestamp
675 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
676 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
677 :group
'org-export-html
680 (defgroup org-export-htmlize nil
681 "Options for processing examples with htmlize.el."
682 :tag
"Org Export Htmlize"
683 :group
'org-export-html
)
685 (defcustom org-export-htmlize-output-type
'inline-css
686 "Output type to be used by htmlize when formatting code snippets.
687 Normally this is `inline-css', but if you have defined to appropriate
688 classes in your css style file, setting this to `css' means that the
689 fontification will use the class names.
690 See also the function `org-export-htmlize-generate-css'."
691 :group
'org-export-htmlize
692 :type
'(choice (const css
) (const inline-css
)))
694 (defcustom org-export-htmlize-css-font-prefix
"org-"
695 "The prefix for CSS class names for htmlize font specifications."
696 :group
'org-export-htmlize
699 (defgroup org-export-icalendar nil
700 "Options specific for iCalendar export of Org-mode files."
701 :tag
"Org Export iCalendar"
704 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
705 "The file name for the iCalendar file covering all agenda files.
706 This file is created with the command \\[org-export-icalendar-all-agenda-files].
707 The file name should be absolute, the file will be overwritten without warning."
708 :group
'org-export-icalendar
711 (defcustom org-icalendar-combined-name
"OrgMode"
712 "Calendar name for the combined iCalendar representing all agenda files."
713 :group
'org-export-icalendar
716 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
717 "Contexts where iCalendar export should use a deadline time stamp.
718 This is a list with several symbols in it. Valid symbol are:
720 event-if-todo Deadlines in TODO entries become calendar events.
721 event-if-not-todo Deadlines in non-TODO entries become calendar events.
722 todo-due Use deadlines in TODO entries as due-dates"
723 :group
'org-export-icalendar
724 :type
'(set :greedy t
725 (const :tag
"Deadlines in non-TODO entries become events"
727 (const :tag
"Deadline in TODO entries become events"
729 (const :tag
"Deadlines in TODO entries become due-dates"
732 (defcustom org-icalendar-use-scheduled
'(todo-start)
733 "Contexts where iCalendar export should use a scheduling time stamp.
734 This is a list with several symbols in it. Valid symbol are:
736 event-if-todo Scheduling time stamps in TODO entries become an event.
737 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
738 todo-start Scheduling time stamps in TODO entries become start date.
739 Some calendar applications show TODO entries only after
741 :group
'org-export-icalendar
742 :type
'(set :greedy t
744 "SCHEDULED timestamps in non-TODO entries become events"
746 (const :tag
"SCHEDULED timestamps in TODO entries become events"
748 (const :tag
"SCHEDULED in TODO entries become start date"
751 (defcustom org-icalendar-categories
'(local-tags category
)
752 "Items that should be entered into the categories field.
753 This is a list of symbols, the following are valid:
755 category The Org-mode category of the current file or tree
756 todo-state The todo state, if any
757 local-tags The tags, defined in the current line
758 all-tags All tags, including inherited ones."
759 :group
'org-export-icalendar
762 (const :tag
"The file or tree category" category
)
763 (const :tag
"The TODO state" todo-state
)
764 (const :tag
"Tags defined in current line" local-tags
)
765 (const :tag
"All tags, including inherited ones" all-tags
))))
767 (defcustom org-icalendar-include-todo nil
768 "Non-nil means, export to iCalendar files should also cover TODO items."
769 :group
'org-export-icalendar
771 (const :tag
"None" nil
)
772 (const :tag
"Unfinished" t
)
773 (const :tag
"All" all
)))
775 (defcustom org-icalendar-include-sexps t
776 "Non-nil means, export to iCalendar files should also cover sexp entries.
777 These are entries like in the diary, but directly in an Org-mode file."
778 :group
'org-export-icalendar
781 (defcustom org-icalendar-include-body
100
782 "Amount of text below headline to be included in iCalendar export.
783 This is a number of characters that should maximally be included.
784 Properties, scheduling and clocking lines will always be removed.
785 The text will be inserted into the DESCRIPTION field."
786 :group
'org-export-icalendar
788 (const :tag
"Nothing" nil
)
789 (const :tag
"Everything" t
)
790 (integer :tag
"Max characters")))
792 (defcustom org-icalendar-store-UID nil
793 "Non-nil means, store any created UIDs in properties.
794 The iCalendar standard requires that all entries have a unique identifyer.
795 Org will create these identifiers as needed. When this variable is non-nil,
796 the created UIDs will be stored in the ID property of the entry. Then the
797 next time this entry is exported, it will be exported with the same UID,
798 superceeding the previous form of it. This is essential for
799 synchronization services.
800 This variable is not turned on by default because we want to avoid creating
801 a property drawer in every entry if people are only playing with this feature,
802 or if they are only using it locally."
803 :group
'org-export-icalendar
808 ;;; Variables, constants, and parameter plists
810 (defconst org-level-max
20)
812 (defvar org-export-html-preamble nil
813 "Preamble, to be inserted just before <body>. Set by publishing functions.")
814 (defvar org-export-html-postamble nil
815 "Preamble, to be inserted just after </body>. Set by publishing functions.")
816 (defvar org-export-html-auto-preamble t
817 "Should default preamble be inserted? Set by publishing functions.")
818 (defvar org-export-html-auto-postamble t
819 "Should default postamble be inserted? Set by publishing functions.")
820 (defvar org-current-export-file nil
) ; dynamically scoped parameter
821 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
823 (defconst org-export-plist-vars
824 '((:link-up . org-export-html-link-up
)
825 (:link-home . org-export-html-link-home
)
826 (:language . org-export-default-language
)
827 (:customtime . org-display-custom-times
)
828 (:headline-levels . org-export-headline-levels
)
829 (:section-numbers . org-export-with-section-numbers
)
830 (:section-number-format . org-export-section-number-format
)
831 (:table-of-contents . org-export-with-toc
)
832 (:preserve-breaks . org-export-preserve-breaks
)
833 (:archived-trees . org-export-with-archived-trees
)
834 (:emphasize . org-export-with-emphasize
)
835 (:sub-superscript . org-export-with-sub-superscripts
)
836 (:special-strings . org-export-with-special-strings
)
837 (:footnotes . org-export-with-footnotes
)
838 (:drawers . org-export-with-drawers
)
839 (:tags . org-export-with-tags
)
840 (:TeX-macros . org-export-with-TeX-macros
)
841 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
842 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
843 (:fixed-width . org-export-with-fixed-width
)
844 (:timestamps . org-export-with-timestamps
)
845 (:author-info . org-export-author-info
)
846 (:creator-info . org-export-creator-info
)
847 (:time-stamp-file . org-export-time-stamp-file
)
848 (:tables . org-export-with-tables
)
849 (:table-auto-headline . org-export-highlight-first-table-line
)
850 (:style-include-default . org-export-html-style-include-default
)
851 (:style . org-export-html-style
)
852 (:style-extra . org-export-html-style-extra
)
853 (:agenda-style . org-agenda-export-html-style
)
854 (:convert-org-links . org-export-html-link-org-files-as-html
)
855 (:inline-images . org-export-html-inline-images
)
856 (:html-extension . org-export-html-extension
)
857 (:html-table-tag . org-export-html-table-tag
)
858 (:expand-quoted-html . org-export-html-expand
)
859 (:timestamp . org-export-html-with-timestamp
)
860 (:publishing-directory . org-export-publishing-directory
)
861 (:preamble . org-export-html-preamble
)
862 (:postamble . org-export-html-postamble
)
863 (:auto-preamble . org-export-html-auto-preamble
)
864 (:auto-postamble . org-export-html-auto-postamble
)
865 (:author . user-full-name
)
866 (:email . user-mail-address
)
867 (:select-tags . org-export-select-tags
)
868 (:exclude-tags . org-export-exclude-tags
)))
870 (defun org-default-export-plist ()
871 "Return the property list with default settings for the export variables."
872 (let ((l org-export-plist-vars
) rtn e
)
873 (while (setq e
(pop l
))
874 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
877 (defvar org-export-inbuffer-options-extra nil
878 "List of additional in-buffer options that should be detected.
879 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
880 etc. Extensions can add to this list to get their options detected, and they
881 can then add a function to `org-export-options-filters' to process these
883 Each element in this list must be a list, with the in-buffer keyword as car,
884 and a property (a symbol) as the next element. All occurences of the
885 keyword will be found, the values concatenated with a space character
886 in between, and the result stored in the export options property list.")
888 (defvar org-export-options-filters nil
889 "Functions to be called to finalize the export/publishing options.
890 All these options are stored in a property list, and each of the functions
891 in this hook gets a chance to modify this property list. Each function
892 must accept the property list as an argument, and must return the (possibly
895 ;; FIXME: should we fold case here?
896 (defun org-infile-export-plist ()
897 "Return the property list with file-local settings for export."
901 (goto-char (point-min))
902 (let ((re (org-make-options-regexp
904 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
905 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
906 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
907 (mapcar 'car org-export-inbuffer-options-extra
))))
908 p key val text options js-up js-main js-css js-opt a pr style
910 ext-setup-or-nil setup-contents
(start 0))
911 (while (or (and ext-setup-or-nil
912 (string-match re ext-setup-or-nil start
)
913 (setq start
(match-end 0)))
914 (and (setq ext-setup-or-nil nil start
0)
915 (re-search-forward re nil t
)))
916 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
917 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
919 ((setq a
(assoc key org-export-inbuffer-options-extra
))
921 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
922 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
923 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
924 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
925 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
926 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
927 ((string-equal key
"STYLE")
928 (setq style
(concat style
"\n" val
)))
929 ((string-equal key
"LATEX_HEADER")
930 (setq latex-header
(concat latex-header
"\n" val
)))
931 ((string-equal key
"TEXT")
932 (setq text
(if text
(concat text
"\n" val
) val
)))
933 ((string-equal key
"OPTIONS")
934 (setq options
(concat val
" " options
)))
935 ((string-equal key
"LINK_UP")
936 (setq p
(plist-put p
:link-up val
)))
937 ((string-equal key
"LINK_HOME")
938 (setq p
(plist-put p
:link-home val
)))
939 ((string-equal key
"EXPORT_SELECT_TAGS")
940 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
941 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
942 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
943 ((equal key
"SETUPFILE")
944 (setq setup-contents
(org-file-contents
946 (org-remove-double-quotes
949 (if (not ext-setup-or-nil
)
950 (setq ext-setup-or-nil setup-contents start
0)
951 (setq ext-setup-or-nil
952 (concat (substring ext-setup-or-nil
0 start
)
953 "\n" setup-contents
"\n"
954 (substring ext-setup-or-nil start
)))))))
955 (setq p
(plist-put p
:text text
))
956 (when style
(setq p
(plist-put p
:style-extra style
)))
958 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
960 (setq p
(org-export-add-options-to-plist p options
)))
963 (defun org-export-add-options-to-plist (p options
)
964 "Parse an OPTONS line and set values in the property list P."
967 (let ((op '(("H" .
:headline-levels
)
968 ("num" .
:section-numbers
)
969 ("toc" .
:table-of-contents
)
970 ("\\n" .
:preserve-breaks
)
971 ("@" .
:expand-quoted-html
)
974 ("^" .
:sub-superscript
)
975 ("-" .
:special-strings
)
980 ("TeX" .
:TeX-macros
)
981 ("LaTeX" .
:LaTeX-fragments
)
982 ("skip" .
:skip-before-1st-heading
)
983 ("author" .
:author-info
)
984 ("creator" .
:creator-info
)
985 ("timestamp" .
:time-stamp-file
)))
987 (while (setq o
(pop op
))
988 (if (string-match (concat (regexp-quote (car o
))
989 ":\\([^ \t\n\r;,.]*\\)")
991 (setq p
(plist-put p
(cdr o
)
992 (car (read-from-string
993 (match-string 1 options
))))))))))
996 (defun org-export-add-subtree-options (p pos
)
997 "Add options in subtree at position POS to property list P."
1000 (when (org-at-heading-p)
1002 ;; This is actually read in `org-export-get-title-from-subtree'
1003 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1004 ;; (setq p (plist-put p :title a)))
1005 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1006 (setq p
(plist-put p
:text a
)))
1007 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1008 (setq p
(org-export-add-options-to-plist p a
)))))
1011 (defun org-export-directory (type plist
)
1012 (let* ((val (plist-get plist
:publishing-directory
))
1013 (dir (if (listp val
)
1014 (or (cdr (assoc type val
)) ".")
1018 (defun org-export-process-option-filters (plist)
1019 (let ((functions org-export-options-filters
) f
)
1020 (while (setq f
(pop functions
))
1021 (setq plist
(funcall f plist
))))
1025 (defun org-export (&optional arg
)
1026 "Export dispatcher for Org-mode.
1027 When `org-export-run-in-background' is non-nil, try to run the command
1028 in the background. This will be done only for commands that write
1029 to a file. For details see the docstring of `org-export-run-in-background'.
1031 The prefix argument ARG will be passed to the exporter. However, if
1032 ARG is a double universal prefix `C-u C-u', that means to inverse the
1033 value of `org-export-run-in-background'."
1035 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1036 (help "[t] insert the export option template
1037 \[v] limit export to visible part of outline tree
1039 \[a] export as ASCII
1042 \[H] export as HTML to temporary buffer
1043 \[R] export region as HTML
1044 \[b] export as HTML and browse immediately
1047 \[l] export as LaTeX
1048 \[p] export as LaTeX and process to PDF
1049 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1050 \[L] export as LaTeX to temporary buffer
1052 \[i] export current file as iCalendar file
1053 \[I] export all agenda files as iCalendar files
1054 \[c] export agenda files into combined iCalendar file
1056 \[F] publish current file
1057 \[P] publish current project
1058 \[X] publish... (project will be prompted for)
1059 \[A] publish all projects")
1061 '((?t org-insert-export-options-template nil
)
1062 (?v org-export-visible nil
)
1063 (?a org-export-as-ascii t
)
1064 (?h org-export-as-html t
)
1065 (?b org-export-as-html-and-open t
)
1066 (?H org-export-as-html-to-buffer nil
)
1067 (?R org-export-region-as-html nil
)
1068 (?x org-export-as-xoxo t
)
1069 (?l org-export-as-latex t
)
1070 (?p org-export-as-pdf t
)
1071 (?d org-export-as-pdf-and-open t
)
1072 (?L org-export-as-latex-to-buffer nil
)
1073 (?i org-export-icalendar-this-file t
)
1074 (?I org-export-icalendar-all-agenda-files t
)
1075 (?c org-export-icalendar-combine-agenda-files t
)
1076 (?F org-publish-current-file t
)
1077 (?P org-publish-current-project t
)
1079 (?A org-publish-all t
)))
1081 (save-window-excursion
1082 (delete-other-windows)
1083 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1085 (org-fit-window-to-buffer (get-buffer-window
1086 "*Org Export/Publishing Help*"))
1087 (message "Select command: ")
1088 (setq r1
(read-char-exclusive)))
1089 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1090 (unless (setq ass
(assq r2 cmds
))
1091 (error "No command associated with key %c" r1
))
1092 (if (and bg
(nth 2 ass
)
1093 (not (buffer-base-buffer))
1094 (not (org-region-active-p)))
1095 ;; execute in background
1096 (let ((p (start-process
1097 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1099 (expand-file-name invocation-name invocation-directory
)
1102 "--eval" "(require 'org-exp)"
1103 "--eval" "(setq org-wait .2)"
1105 "-f" (symbol-name (nth 1 ass
)))))
1106 (set-process-sentinel p
'org-export-process-sentinel
)
1107 (message "Background process \"%s\": started" p
))
1108 ;; background processing not requested, or not possible
1109 (call-interactively (nth 1 ass
)))))
1111 (defun org-export-process-sentinel (process status
)
1112 (if (string-match "\n+\\'" status
)
1113 (setq status
(substring status
0 -
1)))
1114 (message "Background process \"%s\": %s" process status
))
1116 (defconst org-html-entities
1157 ("Aring") ("AA".
"Å")
1246 ("varepsilon".
"ε")
1259 ("sigmaf") ("varsigma".
"ς")
1267 ("thetasym") ("vartheta".
"ϑ")
1270 ("bull") ("bullet".
"•")
1271 ("hellip") ("dots".
"…")
1281 ("larr") ("leftarrow".
"←") ("gets".
"←")
1282 ("uarr") ("uparrow".
"↑")
1283 ("rarr") ("to".
"→") ("rightarrow".
"→")
1284 ("darr")("downarrow".
"↓")
1285 ("harr") ("leftrightarrow".
"↔")
1286 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1287 ("lArr") ("Leftarrow".
"⇐")
1288 ("uArr") ("Uparrow".
"⇑")
1289 ("rArr") ("Rightarrow".
"⇒")
1290 ("dArr") ("Downarrow".
"⇓")
1291 ("hArr") ("Leftrightarrow".
"⇔")
1293 ("part") ("partial".
"∂")
1294 ("exist") ("exists".
"∃")
1295 ("empty") ("emptyset".
"∅")
1297 ("isin") ("in".
"∈")
1303 ("lowast") ("ast".
"∗")
1305 ("prop") ("proptp".
"∝")
1306 ("infin") ("infty".
"∞")
1307 ("ang") ("angle".
"∠")
1308 ("and") ("wedge".
"∧")
1309 ("or") ("vee".
"∨")
1315 ("cong") ("simeq".
"≅")
1316 ("asymp")("approx".
"≈")
1317 ("ne") ("neq".
"≠")
1321 ("sub") ("subset".
"⊂")
1322 ("sup") ("supset".
"⊃")
1329 ("sdot") ("cdot".
"⋅")
1336 ("loz") ("Diamond".
"◊")
1337 ("spades") ("spadesuit".
"♠")
1338 ("clubs") ("clubsuit".
"♣")
1339 ("hearts") ("diamondsuit".
"♥")
1340 ("diams") ("diamondsuit".
"♦")
1341 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1408 "Entities for TeX->HTML translation.
1409 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1410 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1411 In that case, \"\\ent\" will be translated to \"&other;\".
1412 The list contains HTML entities for Latin-1, Greek and other symbols.
1413 It is supplemented by a number of commonly used TeX macros with appropriate
1414 translations. There is currently no way for users to extend this.")
1416 ;;; General functions for all backends
1418 (defun org-export-preprocess-string (string &rest parameters
)
1419 "Cleanup STRING so that that the true exported has a more consistent source.
1420 This function takes STRING, which should be a buffer-string of an org-file
1421 to export. It then creates a temporary buffer where it does its job.
1422 The result is then again returned as a string, and the exporter works
1423 on this string to produce the exported version."
1425 (let* ((htmlp (plist-get parameters
:for-html
))
1426 (asciip (plist-get parameters
:for-ascii
))
1427 (latexp (plist-get parameters
:for-LaTeX
))
1428 (archived-trees (plist-get parameters
:archived-trees
))
1429 (inhibit-read-only t
)
1430 (drawers org-drawers
)
1431 (outline-regexp "\\*+ ")
1434 (with-current-buffer (get-buffer-create " org-mode-tmp")
1437 (setq case-fold-search t
)
1439 (run-hooks 'org-export-preprocess-hook
)
1441 ;; Remove license-to-kill stuff
1442 ;; The caller markes some stuff fo killing, stuff that has been
1443 ;; used to create the page title, for example.
1444 (org-export-kill-licensed-text)
1446 (let ((org-inhibit-startup t
)) (org-mode))
1447 (setq case-fold-search t
)
1448 (untabify (point-min) (point-max))
1450 ;; Handle include files
1451 (org-export-handle-include-files)
1453 ;; Get rid of excluded trees
1454 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1455 (plist-get parameters
:exclude-tags
))
1457 ;; Handle source code snippets
1458 (org-export-replace-src-segments)
1460 ;; Get rid of drawers
1461 (org-export-remove-or-extract-drawers drawers
1462 (plist-get parameters
:drawers
))
1464 ;; Get the correct stuff before the first headline
1465 (when (plist-get parameters
:skip-before-1st-heading
)
1466 (goto-char (point-min))
1467 (when (re-search-forward "^\\*+[ \t]" nil t
)
1468 (delete-region (point-min) (match-beginning 0))
1469 (goto-char (point-min))
1471 (when (plist-get parameters
:add-text
)
1472 (goto-char (point-min))
1473 (insert (plist-get parameters
:add-text
) "\n"))
1475 ;; Get rid of archived trees
1476 (org-export-remove-archived-trees archived-trees
)
1478 ;; Find all headings and compute the targets for them
1479 (setq target-alist
(org-export-define-heading-targets target-alist
))
1481 ;; Find targets in comments and move them out of comments,
1482 ;; but mark them as targets that should be invisible
1483 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1486 (org-export-protect-examples (if asciip
'indent nil
))
1488 ;; Protect backend specific stuff, throw away the others.
1489 (org-export-select-backend-specific-text
1490 (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1492 ;; Protect quoted subtrees
1493 (org-export-protect-quoted-subtrees)
1495 ;; Protect verbatim elements
1496 (org-export-protect-verbatim)
1498 ;; Blockquotes and verse
1499 (org-export-mark-blockquote-and-verse)
1501 ;; Remove comment environment and comment subtrees
1502 (org-export-remove-comment-blocks-and-subtrees)
1505 ;; Find matches for radio targets and turn them into internal links
1506 (org-export-mark-radio-links)
1508 ;; Find all links that contain a newline and put them into a single line
1509 (org-export-concatenate-multiline-links)
1511 ;; Normalize links: Convert angle and plain links into bracket links
1512 ;; and expand link abbreviations
1513 (org-export-normalize-links)
1515 ;; Find all internal links. If they have a fuzzy match (i.e. not
1516 ;; a *dedicated* target match, let the link point to the
1517 ;; corresponding section.
1518 (org-export-target-internal-links target-alist
)
1520 ;; Find multiline emphasis and put them into single line
1521 (when (plist-get parameters
:emph-multiline
)
1522 (org-export-concatenate-multiline-emphasis))
1524 ;; Remove special table lines
1525 (when org-export-table-remove-special-lines
1526 (org-export-remove-special-table-lines))
1528 ;; Specific LaTeX stuff
1530 (require 'org-export-latex nil
)
1531 (org-export-latex-preprocess))
1533 ;; Specific ASCII stuff
1535 (org-export-ascii-preprocess))
1537 ;; Specific HTML stuff
1539 (org-export-html-preprocess parameters
))
1541 ;; Remove or replace comments
1542 (org-export-handle-comments (plist-get parameters
:comments
))
1544 (setq rtn
(buffer-string)))
1545 (kill-buffer " org-mode-tmp")
1548 (defun org-export-kill-licensed-text ()
1549 "Remove all text that is marked with a :org-license-to-kill property."
1551 (while (setq p
(text-property-any (point-min) (point-max)
1552 :org-license-to-kill t
))
1554 p
(or (next-single-property-change p
:org-license-to-kill
)
1557 (defun org-export-define-heading-targets (target-alist)
1558 "Find all headings and define the targets for them.
1559 The new targets are added to TARGET-ALIST, which is also returned."
1560 (goto-char (point-min))
1561 (org-init-section-numbers)
1562 (let ((re (concat "^" org-outline-regexp
))
1564 (while (re-search-forward re nil t
)
1565 (setq level
(org-reduced-level
1566 (save-excursion (goto-char (point-at-bol))
1567 (org-outline-level))))
1568 (setq target
(org-solidify-link-text
1569 (format "sec-%s" (org-section-number level
))))
1570 (push (cons target target
) target-alist
)
1571 (add-text-properties
1572 (point-at-bol) (point-at-eol)
1573 (list 'target target
))))
1576 (defun org-export-handle-invisible-targets (target-alist)
1577 "Find targets in comments and move them out of comments.
1578 Mark them as invisible targets."
1580 (goto-char (point-min))
1581 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1582 ;; Check if the line before or after is a headline with a target
1583 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1584 (get-text-property (point-at-bol 2) 'target
)))
1586 ;; use the existing target in a neighboring line
1587 (setq tmp
(match-string 2))
1589 (and (looking-at "\n") (delete-char 1))
1590 (push (cons (org-solidify-link-text tmp
) target
)
1592 ;; Make an invisible target
1593 (replace-match "\\1(INVISIBLE)"))))
1596 (defun org-export-target-internal-links (target-alist)
1597 "Find all internal links and assign target to them.
1598 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1599 let the link point to the corresponding section."
1600 (goto-char (point-min))
1601 (while (re-search-forward org-bracket-link-regexp nil t
)
1603 (let* ((md (match-data))
1604 (desc (match-end 2))
1605 (link (org-link-unescape (match-string 1)))
1606 (slink (org-solidify-link-text link
))
1610 ((cdr (assoc slink target-alist
)))
1611 ((string-match org-link-types-re link
) nil
)
1612 ((or (file-name-absolute-p link
)
1613 (string-match "^\\." link
))
1617 (setq found
(condition-case nil
(org-link-search link
)
1620 (or (org-on-heading-p)
1621 (not (eq found
'dedicated
))))
1622 (or (get-text-property (point) 'target
)
1625 (1- (previous-single-property-change
1630 (goto-char (match-beginning 1))
1631 (setq props
(text-properties-at (point)))
1632 (delete-region (match-beginning 1) (match-end 1))
1635 (unless desc
(insert "][" link
))
1636 (add-text-properties pos
(point) props
))))))
1638 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1639 "Remove drawers, or extract the content.
1640 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1641 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1642 whose content to keep."
1643 (unless (eq t exp-drawers
)
1644 (goto-char (point-min))
1645 (let ((re (concat "^[ \t]*:\\("
1648 (org-delete-all exp-drawers
1649 (copy-sequence all-drawers
))
1651 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1652 (while (re-search-forward re nil t
)
1653 (replace-match "")))))
1655 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1656 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1657 Both arguments are lists of tags.
1658 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1660 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1662 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1663 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1666 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1670 (goto-char (point-min))
1671 (when (and select-tags
1673 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1674 ;; At least one tree is marked for export, this means
1675 ;; all the unmarked stuff needs to go.
1676 ;; Dig out the trees that should be exported
1677 (goto-char (point-min))
1678 (outline-next-heading)
1680 (put-text-property beg
(point-max) :org-delete t
)
1681 (while (re-search-forward re-sel nil t
)
1682 (when (org-on-heading-p)
1683 (org-back-to-heading)
1684 (remove-text-properties
1685 (max (1- (point)) (point-min))
1686 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1688 (while (and (org-up-heading-safe)
1689 (get-text-property (point) :org-delete
))
1690 (remove-text-properties (max (1- (point)) (point-min))
1691 (point-at-eol) '(:org-delete t
)))
1693 ;; Remove the trees explicitly marked for noexport
1695 (goto-char (point-min))
1696 (while (re-search-forward re-excl nil t
)
1697 (when (org-at-heading-p)
1698 (org-back-to-heading t
)
1700 (org-end-of-subtree t
)
1701 (delete-region beg
(point)))))
1702 ;; Remove everything that is now still marked for deletion
1703 (goto-char (point-min))
1704 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1705 (setq end
(or (next-single-property-change beg
:org-delete
)
1707 (delete-region beg end
))))
1709 (defun org-export-remove-archived-trees (export-archived-trees)
1710 "Remove archived trees.
1711 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1712 When it is t, the entire archived tree will be exported.
1713 When it is nil the entire tree including the headline will be removed
1715 (let ((re-archive (concat ":" org-archive-tag
":"))
1717 (when (not (eq export-archived-trees t
))
1718 (goto-char (point-min))
1719 (while (re-search-forward re-archive nil t
)
1720 (if (not (org-on-heading-p t
))
1721 (org-end-of-subtree t
)
1722 (beginning-of-line 1)
1723 (setq a
(if export-archived-trees
1724 (1+ (point-at-eol)) (point))
1725 b
(org-end-of-subtree t
))
1726 (if (> b a
) (delete-region a b
)))))))
1728 (defun org-export-protect-quoted-subtrees ()
1729 "Mark quoted subtrees with the protection property."
1730 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1731 (goto-char (point-min))
1732 (while (re-search-forward re-quote nil t
)
1733 (goto-char (match-beginning 0))
1735 (add-text-properties (point) (org-end-of-subtree t
)
1736 '(org-protected t
)))))
1738 (defun org-export-protect-verbatim ()
1739 "Mark verbatim snippets with the protection property."
1740 (goto-char (point-min))
1741 (while (re-search-forward org-verbatim-re nil t
)
1742 (add-text-properties (match-beginning 4) (match-end 4)
1744 (goto-char (1+ (match-end 4)))))
1746 (defun org-export-protect-examples (&optional indent
)
1747 "Protect code that should be exported as monospaced examples."
1748 (goto-char (point-min))
1749 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1750 (goto-char (match-end 0))
1751 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1752 (insert (if indent
": " ":"))
1753 (beginning-of-line 2)))
1754 (goto-char (point-min))
1755 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1756 (add-text-properties (match-beginning 0) (match-end 0)
1757 '(org-protected t
))))
1759 (defun org-export-select-backend-specific-text (backend)
1761 '((html "HTML" "BEGIN_HTML" "END_HTML")
1762 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1763 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1767 (setq fmt
(pop formatters
))
1768 (when (eq (car fmt
) backend
)
1769 ;; This is selected code, put it into the file for real
1770 (goto-char (point-min))
1771 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1772 ":[ \t]*\\(.*\\)") nil t
)
1773 (replace-match "\\1" t
)
1774 (add-text-properties
1775 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1776 '(org-protected t
))))
1777 (goto-char (point-min))
1778 (while (re-search-forward
1780 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1781 (cadddr fmt
) "\\>.*\n?") nil t
)
1782 (if (eq (car fmt
) backend
)
1784 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1786 ;; No, this is for a different backend, kill it
1787 (delete-region (match-beginning 0) (match-end 0)))))))
1789 (defun org-export-mark-blockquote-and-verse ()
1790 "Mark block quote and verse environments with special cookies.
1791 These special cookies will later be interpreted by the backend."
1793 (goto-char (point-min))
1794 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1796 (replace-match (if (equal (downcase (match-string 1)) "end")
1797 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1800 (goto-char (point-min))
1801 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1802 (replace-match (if (equal (downcase (match-string 1)) "end")
1803 "ORG-VERSE-END" "ORG-VERSE-START")
1806 (defun org-export-remove-comment-blocks-and-subtrees ()
1807 "Remove the comment environment, and also commented subtrees."
1808 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1809 (case-fold-search nil
))
1810 ;; Remove comment environment
1811 (goto-char (point-min))
1812 (while (re-search-forward
1813 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1814 (replace-match "" t t
))
1815 ;; Remove subtrees that are commented
1816 (goto-char (point-min))
1817 (while (re-search-forward re-commented nil t
)
1818 (goto-char (match-beginning 0))
1819 (delete-region (point) (org-end-of-subtree t
)))))
1821 (defun org-export-handle-comments (commentsp)
1822 "Remove comments, or convert to backend-specific format.
1823 COMMENTSP can be a format string for publishing comments.
1824 When it is nil, all comments will be removed."
1825 (let ((re "^#\\(.*\n?\\)")
1827 (goto-char (point-min))
1828 (while (or (looking-at re
)
1829 (re-search-forward re nil t
))
1830 (setq pos
(match-beginning 0))
1832 (progn (add-text-properties
1833 (match-beginning 0) (match-end 0) '(org-protected t
))
1834 (replace-match (format commentsp
(match-string 1)) t t
))
1835 (goto-char (1+ pos
))
1838 (goto-char (max (point-min) (1- pos
))))))))
1840 (defun org-export-mark-radio-links ()
1841 "Find all matches for radio targets and turn them into internal links."
1842 (let ((re-radio (and org-target-link-regexp
1843 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1844 (goto-char (point-min))
1846 (while (re-search-forward re-radio nil t
)
1848 (replace-match "\\1[[\\2]]"))))))
1850 (defun org-export-remove-special-table-lines ()
1851 "Remove tables lines that are used for internal purposes."
1852 (goto-char (point-min))
1853 (while (re-search-forward "^[ \t]*|" nil t
)
1854 (beginning-of-line 1)
1855 (if (or (looking-at "[ \t]*| *[!_^] *|")
1856 (and (looking-at ".*?| *<[0-9]+> *|")
1857 (not (looking-at ".*?| *[^ <|]"))))
1858 (delete-region (max (point-min) (1- (point-at-bol)))
1862 (defun org-export-normalize-links ()
1863 "Convert all links to bracket links, and expand link abbreviations."
1864 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1865 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1866 (goto-char (point-min))
1867 (while (re-search-forward re-plain-link nil t
)
1868 (goto-char (1- (match-end 0)))
1870 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1871 ":" (match-string 3) "]]")))
1872 ;; added 'org-link face to links
1873 (put-text-property 0 (length s
) 'face
'org-link s
)
1874 (replace-match s t t
))))
1875 (goto-char (point-min))
1876 (while (re-search-forward re-angle-link nil t
)
1877 (goto-char (1- (match-end 0)))
1879 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1880 ":" (match-string 3) "]]")))
1881 (put-text-property 0 (length s
) 'face
'org-link s
)
1882 (replace-match s t t
))))
1883 (goto-char (point-min))
1884 (while (re-search-forward org-bracket-link-regexp nil t
)
1885 (goto-char (1- (match-end 0)))
1887 (let* ((xx (save-match-data
1889 (org-link-expand-abbrev (match-string 1)))))
1894 (concat "[" xx
"]"))
1896 (put-text-property 0 (length s
) 'face
'org-link s
)
1897 (replace-match s t t
))))))
1899 (defun org-export-concatenate-multiline-links ()
1900 "Find multi-line links and put it all into a single line.
1901 This is to make sure that the line-processing export backends
1902 can work correctly."
1903 (goto-char (point-min))
1904 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1906 (replace-match "\\1 \\3")
1907 (goto-char (match-beginning 0)))))
1909 (defun org-export-concatenate-multiline-emphasis ()
1910 "Find multi-line emphasis and put it all into a single line.
1911 This is to make sure that the line-processing export backends
1912 can work correctly."
1913 (goto-char (point-min))
1914 (while (re-search-forward org-emph-re nil t
)
1915 (if (not (= (char-after (match-beginning 3))
1916 (char-after (match-beginning 4))))
1918 (subst-char-in-region (match-beginning 0) (match-end 0)
1920 (goto-char (1- (match-end 0))))
1921 (goto-char (1+ (match-beginning 0))))))
1923 (defun org-export-grab-title-from-buffer ()
1924 "Get a title for the current document, from looking at the buffer."
1925 (let ((inhibit-read-only t
))
1927 (goto-char (point-min))
1928 (let ((end (if (looking-at org-outline-regexp
)
1930 (save-excursion (outline-next-heading) (point)))))
1931 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1932 ;; Mark the line so that it will not be exported as normal text.
1934 (add-text-properties (match-beginning 0) (match-end 0)
1935 (list :org-license-to-kill t
)))
1936 ;; Return the title string
1937 (org-trim (match-string 0)))))))
1939 (defun org-export-get-title-from-subtree ()
1940 "Return subtree title and exclude it from export."
1941 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
1944 (when (and (org-at-heading-p)
1945 (>= (org-end-of-subtree t t
) rend
))
1946 ;; This is a subtree, we take the title from the first heading
1948 (looking-at org-todo-line-regexp
)
1949 (setq title
(match-string 3))
1951 (add-text-properties (point) (1+ (point-at-eol))
1952 (list :org-license-to-kill t
)))
1953 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
1956 (defun org-solidify-link-text (s &optional alist
)
1957 "Take link text and make a safe target out of it."
1962 (org-split-string s
"[ \t\r\n]+") "=="))
1963 (a (assoc rtn alist
)))
1966 (defun org-get-min-level (lines)
1967 "Get the minimum level in LINES."
1968 (let ((re "^\\(\\*+\\) ") l min
)
1970 (while (setq l
(pop lines
))
1971 (if (string-match re l
)
1972 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1975 ;; Variable holding the vector with section numbers
1976 (defvar org-section-numbers
(make-vector org-level-max
0))
1978 (defun org-init-section-numbers ()
1979 "Initialize the vector for the section numbers."
1981 (numbers (nreverse (org-split-string "" "\\.")))
1982 (depth (1- (length org-section-numbers
)))
1983 (i depth
) number-string
)
1986 (aset org-section-numbers i
0)
1987 (setq number-string
(or (car numbers
) "0"))
1988 (if (string-match "\\`[A-Z]\\'" number-string
)
1989 (aset org-section-numbers i
1990 (- (string-to-char number-string
) ?A -
1))
1991 (aset org-section-numbers i
(string-to-number number-string
)))
1995 (defun org-section-number (&optional level
)
1996 "Return a string with the current section number.
1997 When LEVEL is non-nil, increase section numbers on that level."
1998 (let* ((depth (1- (length org-section-numbers
)))
2000 (fmts (car org-export-section-number-format
))
2001 (term (cdr org-export-section-number-format
))
2006 (aset org-section-numbers
2007 level
(1+ (aref org-section-numbers level
))))
2008 (setq idx
(1+ level
))
2009 (while (<= idx depth
)
2011 (aset org-section-numbers idx
0))
2012 (setq idx
(1+ idx
))))
2014 (while (<= idx depth
)
2015 (when (> (aref org-section-numbers idx
) 0)
2016 (setq fmt
(or (pop fmts
) fmt
)
2018 n
(aref org-section-numbers idx
)
2020 (concat string sep
(org-number-to-counter n ctype
))
2021 (concat string
".0"))
2023 (setq idx
(1+ idx
)))
2025 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2026 (setq string
(replace-match "" t nil string
)))
2027 (if (string-match "\\(\\.0\\)+\\'" string
)
2028 (setq string
(replace-match "" t nil string
))))
2029 (concat string term
)))
2031 (defun org-number-to-counter (n type
)
2032 "Concert number N to a string counter, according to TYPE.
2033 TYPE must be a string, any of:
2037 I uppper case roman numeral
2038 i lower case roman numeral"
2040 ((equal type
"1") (number-to-string n
))
2041 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2042 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2043 ((equal type
"I") (org-number-to-roman n
))
2044 ((equal type
"i") (downcase (org-number-to-roman n
)))
2045 (t (error "Invalid counter type `%s'" type
))))
2047 (defun org-number-to-roman (n)
2048 "Convert integer N into a roman numeral."
2049 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2050 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2051 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2055 (number-to-string n
)
2057 (if (>= n
(caar roman
))
2058 (setq n
(- n
(caar roman
))
2059 res
(concat res
(cdar roman
)))
2063 (org-number-to-roman 1961)
2068 (defun org-export-handle-include-files ()
2069 "Include the contents of include files, with proper formatting."
2070 (let ((case-fold-search t
)
2071 params file markup lang start end prefix prefix1
)
2072 (goto-char (point-min))
2073 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2074 (setq params
(read (concat "(" (match-string 1) ")"))
2075 prefix
(org-get-and-remove-property 'params
:prefix
)
2076 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2077 file
(org-symname-or-string (pop params
))
2078 markup
(org-symname-or-string (pop params
))
2079 lang
(org-symname-or-string (pop params
)))
2080 (delete-region (match-beginning 0) (match-end 0))
2082 (not (file-exists-p file
))
2083 (not (file-readable-p file
)))
2084 (insert (format "CANNOT INCLUDE FILE %s" file
))
2086 (if (equal (downcase markup
) "src")
2087 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2089 (setq start
(format "#+begin_%s\n" markup
)
2090 end
(format "#+end_%s" markup
))))
2091 (insert (or start
""))
2092 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2093 (or (bolp) (newline))
2094 (insert (or end
""))))))
2096 (defun org-get-file-contents (file &optional prefix prefix1
)
2097 "Get the contents of FILE and return them as a string.
2098 If PREFIX is a string, prepend it to each line. If PREFIX1
2099 is a string, prepend it to the first line instead of PREFIX."
2101 (insert-file-contents file
)
2102 (when (or prefix prefix1
)
2103 (goto-char (point-min))
2105 (insert (or prefix1 prefix
))
2107 (beginning-of-line 2)))
2110 (defun org-get-and-remove-property (listvar prop
)
2111 "Check if the value of LISTVAR contains PROP as a property.
2112 If yes, return the value of that property (i.e. the element following
2113 in the list) and remove property and value from the list in LISTVAR."
2114 (let ((list (symbol-value listvar
)) m v
)
2115 (when (setq m
(member prop list
))
2117 (if (equal (car list
) prop
)
2118 (set listvar
(cddr list
))
2119 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2121 (set listvar list
)))
2124 (defun org-symname-or-string (s)
2126 (if s
(symbol-name s
) s
)
2129 ;;; Fontification of code
2130 ;; Currently only for the HTML backend, but who knows....
2131 (defun org-export-replace-src-segments ()
2132 "Replace source code segments with special code for export."
2133 (let ((case-fold-search t
)
2135 (goto-char (point-min))
2136 (while (re-search-forward
2137 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
2139 (setq lang
(match-string 1) code
(match-string 2)
2140 trans
(org-export-format-source-code lang code
))
2141 (replace-match trans t t
))))
2143 (defvar htmlp
) ;; dynamically scoped from org-exp.el
2145 (defun org-export-format-source-code (lang code
)
2146 "Format CODE from language LANG and return it formatted for export.
2147 Currently, this only does something for HTML export, for all other
2148 backends, it converts the segment into an EXAMPLE segment."
2152 ;; We are exporting to HTML
2153 (condition-case nil
(require 'htmlize
) (nil t
))
2154 (if (not (fboundp 'htmlize-region-for-paste
))
2156 ;; we do not have htmlize.el, or an old version of it
2158 "htmlize.el 1.34 or later is needed for source code formatting")
2159 (concat "#+BEGIN_EXAMPLE\n" code
2160 (if (string-match "\n\\'" code
) "" "\n")
2162 ;; ok, we are good to go
2163 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2164 (org-inhibit-startup t
)
2165 (org-startup-folded nil
)
2169 ;; Free up the protected stuff
2170 (goto-char (point-min))
2171 (while (re-search-forward "^," nil t
)
2174 (if (functionp mode
)
2177 (font-lock-fontify-buffer)
2178 (org-export-htmlize-region-for-paste
2179 (point-min) (point-max)))))
2180 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
2181 (setq htmltext
(replace-match
2182 (format "<pre class=\"src src-%s\">" lang
)
2184 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
2186 ;; This is not HTML, so just make it an example.
2187 (when (equal lang
"org")
2188 (while (string-match "^," code
)
2189 (setq code
(replace-match "" t t code
))))
2190 (concat "#+BEGIN_EXAMPLE\n" code
2191 (if (string-match "\n\\'" code
) "" "\n")
2192 "#+END_EXAMPLE\n")))))
2196 (defvar org-last-level nil
) ; dynamically scoped variable
2197 (defvar org-min-level nil
) ; dynamically scoped variable
2198 (defvar org-levels-open nil
) ; dynamically scoped parameter
2199 (defvar org-ascii-current-indentation nil
) ; For communication
2202 (defun org-export-as-ascii (arg)
2203 "Export the outline as a pretty ASCII file.
2204 If there is an active region, export only the region.
2205 The prefix ARG specifies how many levels of the outline should become
2206 underlined headlines. The default is 3."
2208 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2209 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2210 (org-infile-export-plist)))
2211 (region-p (org-region-active-p))
2212 (rbeg (and region-p
(region-beginning)))
2213 (rend (and region-p
(region-end)))
2218 (and (org-at-heading-p)
2219 (>= (org-end-of-subtree t t
) rend
)))))
2220 (opt-plist (if subtree-p
2221 (org-export-add-subtree-options opt-plist rbeg
)
2223 (custom-times org-display-custom-times
)
2224 (org-ascii-current-indentation '(0 .
0))
2228 (case-fold-search nil
)
2229 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2230 (filename (concat (file-name-as-directory
2231 (org-export-directory :ascii opt-plist
))
2232 (file-name-sans-extension
2234 (org-entry-get (region-beginning)
2235 "EXPORT_FILE_NAME" t
))
2236 (file-name-nondirectory bfname
)))
2238 (filename (if (equal (file-truename filename
)
2239 (file-truename bfname
))
2240 (concat filename
".txt")
2242 (buffer (find-file-noselect filename
))
2243 (org-levels-open (make-vector org-level-max nil
))
2244 (odd org-odd-levels-only
)
2245 (date (plist-get opt-plist
:date
))
2246 (author (plist-get opt-plist
:author
))
2247 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2248 (plist-get opt-plist
:title
)
2250 (plist-get opt-plist
:skip-before-1st-heading
))
2251 (org-export-grab-title-from-buffer))
2252 (file-name-sans-extension
2253 (file-name-nondirectory bfname
))))
2254 (email (plist-get opt-plist
:email
))
2255 (language (plist-get opt-plist
:language
))
2256 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2257 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2262 (if (org-region-active-p) (region-beginning) (point-min))
2263 (if (org-region-active-p) (region-end) (point-max))))
2264 (lines (org-split-string
2265 (org-export-preprocess-string
2268 :skip-before-1st-heading
2269 (plist-get opt-plist
:skip-before-1st-heading
)
2270 :drawers
(plist-get opt-plist
:drawers
)
2271 :verbatim-multiline t
2272 :select-tags
(plist-get opt-plist
:select-tags
)
2273 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2275 (plist-get opt-plist
:archived-trees
)
2276 :add-text
(plist-get opt-plist
:text
))
2278 thetoc have-headings first-heading-pos
2279 table-open table-buffer
)
2281 (let ((inhibit-read-only t
))
2283 (remove-text-properties (point-min) (point-max)
2284 '(:org-license-to-kill t
))))
2286 (setq org-min-level
(org-get-min-level lines
))
2287 (setq org-last-level org-min-level
)
2288 (org-init-section-numbers)
2290 (find-file-noselect filename
)
2292 (setq lang-words
(or (assoc language org-export-language-setup
)
2293 (assoc "en" org-export-language-setup
)))
2294 (switch-to-buffer-other-window buffer
)
2297 ;; create local variables for all options, to make sure all called
2298 ;; functions get the correct information
2300 (set (make-local-variable (cdr x
))
2301 (plist-get opt-plist
(car x
))))
2302 org-export-plist-vars
)
2303 (org-set-local 'org-odd-levels-only odd
)
2304 (setq umax
(if arg
(prefix-numeric-value arg
)
2305 org-export-headline-levels
))
2306 (setq umax-toc
(if (integerp org-export-with-toc
)
2307 (min org-export-with-toc umax
)
2311 (if title
(org-insert-centered title ?
=))
2313 (if (and (or author email
)
2314 org-export-author-info
)
2315 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2316 (if email
(concat " <" email
">") "")
2320 ((and date
(string-match "%" date
))
2321 (setq date
(format-time-string date
)))
2323 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2325 (if (and date org-export-time-stamp-file
)
2326 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2330 (if org-export-with-toc
2332 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2333 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2335 (mapc '(lambda (line)
2336 (if (string-match org-todo-line-regexp
2338 ;; This is a headline
2340 (setq have-headings t
)
2341 (setq level
(- (match-end 1) (match-beginning 1))
2342 level
(org-tr-level level
)
2343 txt
(match-string 3 line
)
2345 (or (and org-export-mark-todo-in-toc
2347 (not (member (match-string 2 line
)
2348 org-done-keywords
)))
2350 (and org-export-mark-todo-in-toc
2352 (org-search-todo-below
2353 line lines level
))))
2354 (setq txt
(org-html-expand-for-ascii txt
))
2356 (while (string-match org-bracket-link-regexp txt
)
2359 (match-string (if (match-end 2) 3 1) txt
)
2362 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2364 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2366 (setq txt
(replace-match "" t t txt
)))
2367 (if (string-match quote-re0 txt
)
2368 (setq txt
(replace-match "" t t txt
)))
2370 (if org-export-with-section-numbers
2371 (setq txt
(concat (org-section-number level
)
2373 (if (<= level umax-toc
)
2378 (* (max 0 (- level org-min-level
)) 4) ?\
)
2379 (format (if todo
"%s (*)\n" "%s\n") txt
))
2381 (setq org-last-level level
))
2384 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2386 (org-init-section-numbers)
2387 (while (setq line
(pop lines
))
2388 ;; Remove the quoted HTML tags.
2389 (setq line
(org-html-expand-for-ascii line
))
2391 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
2392 (setq line
(replace-match "" t t line
)))
2393 ;; Replace internal links
2394 (while (string-match org-bracket-link-regexp line
)
2395 (setq line
(replace-match
2396 (if (match-end 3) "[\\3]" "[\\1]")
2399 (setq line
(org-translate-time line
)))
2401 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2403 (setq first-heading-pos
(or first-heading-pos
(point)))
2404 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2405 txt
(match-string 2 line
))
2406 (org-ascii-level-start level txt umax lines
))
2408 ((and org-export-with-tables
2409 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2410 (if (not table-open
)
2412 (setq table-open t table-buffer nil
))
2414 (setq table-buffer
(cons line table-buffer
))
2415 (when (or (not lines
)
2416 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2418 (setq table-open nil
2419 table-buffer
(nreverse table-buffer
))
2422 (org-fix-indentation x org-ascii-current-indentation
))
2423 (org-format-table-ascii table-buffer
)
2426 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2427 (if (and org-export-with-fixed-width
2428 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2429 (setq line
(replace-match "\\1" nil nil line
)))
2430 (insert line
"\n"))))
2434 ;; insert the table of contents
2436 (goto-char (point-min))
2437 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2439 (goto-char (match-beginning 0))
2441 (goto-char first-heading-pos
))
2442 (mapc 'insert thetoc
)
2443 (or (looking-at "[ \t]*\n[ \t]*\n")
2446 ;; Convert whitespace place holders
2447 (goto-char (point-min))
2449 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2450 (setq end
(next-single-property-change beg
'org-whitespace
))
2452 (delete-region beg end
)
2453 (insert (make-string (- end beg
) ?\
))))
2456 ;; remove display and invisible chars
2458 (goto-char (point-min))
2459 (while (setq beg
(next-single-property-change (point) 'display
))
2460 (setq end
(next-single-property-change beg
'display
))
2461 (delete-region beg end
)
2464 (goto-char (point-min))
2465 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2466 (setq end
(next-single-property-change beg
'org-cwidth
))
2467 (delete-region beg end
)
2469 (goto-char (point-min))))
2471 (defun org-export-ascii-preprocess ()
2472 "Do extra work for ASCII export"
2473 (goto-char (point-min))
2474 (while (re-search-forward org-verbatim-re nil t
)
2475 (goto-char (match-end 2))
2476 (backward-delete-char 1) (insert "'")
2477 (goto-char (match-beginning 2))
2478 (delete-char 1) (insert "`")
2479 (goto-char (match-end 2))))
2481 (defun org-search-todo-below (line lines level
)
2482 "Search the subtree below LINE for any TODO entries."
2483 (let ((rest (cdr (memq line lines
)))
2484 (re org-todo-line-regexp
)
2487 (while (setq line
(pop rest
))
2488 (if (string-match re line
)
2490 (setq lv
(- (match-end 1) (match-beginning 1))
2491 todo
(and (match-beginning 2)
2492 (not (member (match-string 2 line
)
2493 org-done-keywords
))))
2495 (if (<= lv level
) (throw 'exit nil
))
2496 (if todo
(throw 'exit t
))))))))
2498 (defun org-html-expand-for-ascii (line)
2499 "Handle quoted HTML for ASCII export."
2500 (if org-export-html-expand
2501 (while (string-match "@<[^<>\n]*>" line
)
2502 ;; We just remove the tags for now.
2503 (setq line
(replace-match "" nil nil line
))))
2506 (defun org-insert-centered (s &optional underline
)
2507 "Insert the string S centered and underline it with character UNDERLINE."
2508 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2509 (insert (make-string ind ?\
) s
"\n")
2511 (insert (make-string ind ?\
)
2512 (make-string (string-width s
) underline
)
2515 (defun org-ascii-level-start (level title umax
&optional lines
)
2516 "Insert a new level in ASCII export."
2517 (let (char (n (- level umax
1)) (ind 0))
2520 (insert (make-string (* 2 n
) ?\
)
2521 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2522 org-export-ascii-bullets
))
2524 ;; find the indentation of the next non-empty line
2527 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2528 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2529 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2531 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2532 (if (or (not (equal (char-before) ?
\n))
2533 (not (equal (char-before (1- (point))) ?
\n)))
2535 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2536 (unless org-export-with-tags
2537 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2538 (setq title
(replace-match "" t t title
))))
2539 (if org-export-with-section-numbers
2540 (setq title
(concat (org-section-number level
) " " title
)))
2541 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2542 (setq org-ascii-current-indentation
'(0 .
0)))))
2545 (defun org-export-visible (type arg
)
2546 "Create a copy of the visible part of the current buffer, and export it.
2547 The copy is created in a temporary buffer and removed after use.
2548 TYPE is the final key (as a string) that also select the export command in
2549 the `C-c C-e' export dispatcher.
2550 As a special case, if the you type SPC at the prompt, the temporary
2551 org-mode file will not be removed but presented to you so that you can
2552 continue to use it. The prefix arg ARG is passed through to the exporting
2556 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2557 (read-char-exclusive))
2558 current-prefix-arg
))
2559 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2560 (error "Invalid export key"))
2561 (let* ((binding (cdr (assoc type
2562 '((?a . org-export-as-ascii
)
2563 (?\C-a . org-export-as-ascii
)
2564 (?b . org-export-as-html-and-open
)
2565 (?\C-b . org-export-as-html-and-open
)
2566 (?h . org-export-as-html
)
2567 (?H . org-export-as-html-to-buffer
)
2568 (?R . org-export-region-as-html
)
2569 (?x . org-export-as-xoxo
)))))
2570 (keepp (equal type ?\
))
2571 (file buffer-file-name
)
2572 (buffer (get-buffer-create "*Org Export Visible*"))
2574 ;; Need to hack the drawers here.
2576 (goto-char (point-min))
2577 (while (re-search-forward org-drawer-regexp nil t
)
2578 (goto-char (match-beginning 1))
2579 (or (org-invisible-p) (org-flag-drawer nil
))))
2580 (with-current-buffer buffer
(erase-buffer))
2582 (setq s
(goto-char (point-min)))
2583 (while (not (= (point) (point-max)))
2584 (goto-char (org-find-invisible))
2585 (append-to-buffer buffer s
(point))
2586 (setq s
(goto-char (org-find-visible))))
2587 (org-cycle-hide-drawers 'all
)
2588 (goto-char (point-min))
2590 ;; Copy all comment lines to the end, to make sure #+ settings are
2591 ;; still available for the second export step. Kind of a hack, but
2592 ;; does do the trick.
2593 (if (looking-at "#[^\r\n]*")
2594 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2595 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2596 (append-to-buffer buffer
(1+ (match-beginning 0))
2597 (min (point-max) (1+ (match-end 0))))))
2599 (let ((buffer-file-name file
)
2600 (org-inhibit-startup t
))
2603 (unless keepp
(funcall binding arg
))))
2605 (kill-buffer buffer
)
2606 (switch-to-buffer-other-window buffer
)
2607 (goto-char (point-min)))))
2609 (defun org-find-visible ()
2611 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2612 (get-char-property s
'invisible
)))
2614 (defun org-find-invisible ()
2616 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2617 (not (get-char-property s
'invisible
))))
2622 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2623 (defun org-get-current-options ()
2624 "Return a string with current options as keyword options.
2625 Does include HTML export options as well as TODO and CATEGORY stuff."
2626 (require 'org-archive
)
2633 #+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
2635 #+EXPORT_SELECT_TAGS: %s
2636 #+EXPORT_EXCLUDE_TAGS: %s
2642 #+PRIORITIES: %c %c %c
2644 #+STARTUP: %s %s %s %s %s
2650 (buffer-name) (user-full-name) user-mail-address
2651 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2652 org-export-default-language
2653 org-export-headline-levels
2654 org-export-with-section-numbers
2656 org-export-preserve-breaks
2657 org-export-html-expand
2658 org-export-with-fixed-width
2659 org-export-with-tables
2660 org-export-with-sub-superscripts
2661 org-export-with-special-strings
2662 org-export-with-footnotes
2663 org-export-with-emphasize
2664 org-export-with-TeX-macros
2665 org-export-with-LaTeX-fragments
2666 org-export-skip-text-before-1st-heading
2667 org-export-with-drawers
2668 org-export-with-tags
2669 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2670 (mapconcat 'identity org-export-select-tags
" ")
2671 (mapconcat 'identity org-export-exclude-tags
" ")
2672 org-export-html-link-up
2673 org-export-html-link-home
2674 (file-name-nondirectory buffer-file-name
)
2675 "TODO FEEDBACK VERIFY DONE"
2676 "Me Jason Marie DONE"
2677 org-highest-priority org-lowest-priority org-default-priority
2678 (mapconcat 'identity org-drawers
" ")
2679 (cdr (assoc org-startup-folded
2680 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2681 (if org-odd-levels-only
"odd" "oddeven")
2682 (if org-hide-leading-stars
"hidestars" "showstars")
2683 (if org-startup-align-all-tables
"align" "noalign")
2684 (cond ((eq org-log-done t
) "logdone")
2685 ((equal org-log-done
'note
) "lognotedone")
2686 ((not org-log-done
) "nologdone"))
2687 (or (mapconcat (lambda (x)
2689 ((equal '(:startgroup
) x
) "{")
2690 ((equal '(:endgroup
) x
) "}")
2691 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2693 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2694 (mapconcat 'identity org-file-tags
" ")
2695 org-archive-location
2696 "org file:~/org/%s.org"
2699 (defun org-export-html-preprocess (parameters)
2700 ;; Convert LaTeX fragments to images
2701 (when (plist-get parameters
:LaTeX-fragments
)
2703 (concat "ltxpng/" (file-name-sans-extension
2704 (file-name-nondirectory
2705 org-current-export-file
)))
2706 org-current-export-dir nil
"Creating LaTeX image %s"))
2707 (message "Exporting..."))
2710 (defun org-insert-export-options-template ()
2711 "Insert into the buffer a template with information for exporting."
2713 (if (not (bolp)) (newline))
2714 (let ((s (org-get-current-options)))
2715 (and (string-match "#\\+CATEGORY" s
)
2716 (setq s
(substring s
0 (match-beginning 0))))
2720 (defun org-export-as-html-and-open (arg)
2721 "Export the outline as HTML and immediately open it with a browser.
2722 If there is an active region, export only the region.
2723 The prefix ARG specifies how many levels of the outline should become
2724 headlines. The default is 3. Lower levels will become bulleted lists."
2726 (org-export-as-html arg
'hidden
)
2727 (org-open-file buffer-file-name
))
2730 (defun org-export-as-html-batch ()
2731 "Call `org-export-as-html', may be used in batch processing as
2733 --load=$HOME/lib/emacs/org.el
2734 --eval \"(setq org-export-headline-levels 2)\"
2735 --visit=MyFile --funcall org-export-as-html-batch"
2736 (org-export-as-html org-export-headline-levels
'hidden
))
2739 (defun org-export-as-html-to-buffer (arg)
2740 "Call `org-exort-as-html` with output to a temporary buffer.
2741 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2743 (org-export-as-html arg nil nil
"*Org HTML Export*")
2744 (switch-to-buffer-other-window "*Org HTML Export*"))
2747 (defun org-replace-region-by-html (beg end
)
2748 "Assume the current region has org-mode syntax, and convert it to HTML.
2749 This can be used in any buffer. For example, you could write an
2750 itemized list in org-mode syntax in an HTML buffer and then use this
2751 command to convert it."
2753 (let (reg html buf pop-up-frames
)
2754 (save-window-excursion
2756 (setq html
(org-export-region-as-html
2758 (setq reg
(buffer-substring beg end
)
2759 buf
(get-buffer-create "*Org tmp*"))
2760 (with-current-buffer buf
2764 (setq html
(org-export-region-as-html
2765 (point-min) (point-max) t
'string
)))
2767 (delete-region beg end
)
2771 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2772 "Convert region from BEG to END in org-mode buffer to HTML.
2773 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2774 contents, and only produce the region of converted text, useful for
2775 cut-and-paste operations.
2776 If BUFFER is a buffer or a string, use/create that buffer as a target
2777 of the converted HTML. If BUFFER is the symbol `string', return the
2778 produced HTML as a string and leave not buffer behind. For example,
2779 a Lisp program could call this function in the following way:
2781 (setq html (org-export-region-as-html beg end t 'string))
2783 When called interactively, the output buffer is selected, and shown
2784 in a window. A non-interactive call will only return the buffer."
2785 (interactive "r\nP")
2786 (when (interactive-p)
2787 (setq buffer
"*Org HTML Export*"))
2788 (let ((transient-mark-mode t
) (zmacs-regions t
)
2790 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
2792 (set-mark (point)) ;; to activate the region
2794 (setq rtn
(org-export-as-html
2797 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2798 (if (and (interactive-p) (bufferp rtn
))
2799 (switch-to-buffer-other-window rtn
)
2802 (defvar html-table-tag nil
) ; dynamically scoped into this.
2803 (defvar org-par-open nil
)
2805 (defun org-export-as-html (arg &optional hidden ext-plist
2806 to-buffer body-only pub-dir
)
2807 "Export the outline as a pretty HTML file.
2808 If there is an active region, export only the region. The prefix
2809 ARG specifies how many levels of the outline should become
2810 headlines. The default is 3. Lower levels will become bulleted
2811 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2812 EXT-PLIST is a property list with external parameters overriding
2813 org-mode's default settings, but still inferior to file-local
2814 settings. When TO-BUFFER is non-nil, create a buffer with that
2815 name and export to that buffer. If TO-BUFFER is the symbol
2816 `string', don't leave any buffer behind but just return the
2817 resulting HTML as a string. When BODY-ONLY is set, don't produce
2818 the file header and footer, simply return the content of
2819 <body>...</body>, without even the body tags themselves. When
2820 PUB-DIR is set, use this as the publishing directory."
2823 ;; Make sure we have a file name when we need it.
2824 (when (and (not (or to-buffer body-only
))
2825 (not buffer-file-name
))
2826 (if (buffer-base-buffer)
2827 (org-set-local 'buffer-file-name
2828 (with-current-buffer (buffer-base-buffer)
2830 (error "Need a file name to be able to export.")))
2832 (message "Exporting...")
2833 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2834 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2835 (setq-default org-done-keywords org-done-keywords
)
2836 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2838 (org-export-process-option-filters
2839 (org-combine-plists (org-default-export-plist)
2841 (org-infile-export-plist))))
2842 (style (concat (if (plist-get opt-plist
:style-include-default
)
2843 org-export-html-style-default
)
2844 (plist-get opt-plist
:style
)
2845 (plist-get opt-plist
:style-extra
)))
2846 (html-extension (plist-get opt-plist
:html-extension
))
2847 (link-validate (plist-get opt-plist
:link-validation-function
))
2848 valid thetoc have-headings first-heading-pos
2849 (odd org-odd-levels-only
)
2850 (region-p (org-region-active-p))
2851 (rbeg (and region-p
(region-beginning)))
2852 (rend (and region-p
(region-end)))
2854 (if (plist-get opt-plist
:ignore-subree-p
)
2859 (and (org-at-heading-p)
2860 (>= (org-end-of-subtree t t
) rend
))))))
2861 (opt-plist (if subtree-p
2862 (org-export-add-subtree-options opt-plist rbeg
)
2864 ;; The following two are dynamically scoped into other
2866 (org-current-export-dir
2867 (or pub-dir
(org-export-directory :html opt-plist
)))
2868 (org-current-export-file buffer-file-name
)
2869 (level 0) (line "") (origline "") txt todo
2872 (filename (if to-buffer nil
2875 (file-name-sans-extension
2877 (org-entry-get (region-beginning)
2878 "EXPORT_FILE_NAME" t
))
2879 (file-name-nondirectory buffer-file-name
)))
2881 (file-name-as-directory
2882 (or pub-dir
(org-export-directory :html opt-plist
))))))
2883 (current-dir (if buffer-file-name
2884 (file-name-directory buffer-file-name
)
2886 (buffer (if to-buffer
2888 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2889 (t (get-buffer-create to-buffer
)))
2890 (find-file-noselect filename
)))
2891 (org-levels-open (make-vector org-level-max nil
))
2892 (date (plist-get opt-plist
:date
))
2893 (author (plist-get opt-plist
:author
))
2894 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2895 (plist-get opt-plist
:title
)
2897 (plist-get opt-plist
:skip-before-1st-heading
))
2898 (org-export-grab-title-from-buffer))
2899 (and buffer-file-name
2900 (file-name-sans-extension
2901 (file-name-nondirectory buffer-file-name
)))
2903 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2904 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2905 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2910 (local-list-type nil
)
2911 (local-list-indent nil
)
2912 (llt org-plain-list-ordered-item-terminator
)
2913 (email (plist-get opt-plist
:email
))
2914 (language (plist-get opt-plist
:language
))
2918 (coding-system (and (boundp 'buffer-file-coding-system
)
2919 buffer-file-coding-system
))
2920 (coding-system-for-write (or org-export-html-coding-system
2922 (save-buffer-coding-system (or org-export-html-coding-system
2924 (charset (and coding-system-for-write
2925 (fboundp 'coding-system-get
)
2926 (coding-system-get coding-system-for-write
2930 (if region-p
(region-beginning) (point-min))
2931 (if region-p
(region-end) (point-max))))
2934 (org-export-preprocess-string
2938 :skip-before-1st-heading
2939 (plist-get opt-plist
:skip-before-1st-heading
)
2940 :drawers
(plist-get opt-plist
:drawers
)
2942 (plist-get opt-plist
:archived-trees
)
2943 :select-tags
(plist-get opt-plist
:select-tags
)
2944 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2946 (plist-get opt-plist
:text
)
2948 (plist-get opt-plist
:LaTeX-fragments
))
2951 table-buffer table-orig-buffer
2952 ind item-type starter didclose
2953 rpl path attr desc descp desc1 desc2 link
2954 snumber fnc item-tag
2958 (let ((inhibit-read-only t
))
2960 (remove-text-properties (point-min) (point-max)
2961 '(:org-license-to-kill t
))))
2963 (message "Exporting...")
2965 (setq org-min-level
(org-get-min-level lines
))
2966 (setq org-last-level org-min-level
)
2967 (org-init-section-numbers)
2970 ((and date
(string-match "%" date
))
2971 (setq date
(format-time-string date
)))
2973 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2975 ;; Get the language-dependent settings
2976 (setq lang-words
(or (assoc language org-export-language-setup
)
2977 (assoc "en" org-export-language-setup
)))
2979 ;; Switch to the output buffer
2981 (let ((inhibit-read-only t
)) (erase-buffer))
2984 (and (fboundp 'set-buffer-file-coding-system
)
2985 (set-buffer-file-coding-system coding-system-for-write
))
2987 (let ((case-fold-search nil
)
2988 (org-odd-levels-only odd
))
2989 ;; create local variables for all options, to make sure all called
2990 ;; functions get the correct information
2992 (set (make-local-variable (cdr x
))
2993 (plist-get opt-plist
(car x
))))
2994 org-export-plist-vars
)
2995 (setq umax
(if arg
(prefix-numeric-value arg
)
2996 org-export-headline-levels
))
2997 (setq umax-toc
(if (integerp org-export-with-toc
)
2998 (min org-export-with-toc umax
)
3003 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3004 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3005 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3006 lang=\"%s\" xml:lang=\"%s\">
3009 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3010 <meta name=\"generator\" content=\"Org-mode\"/>
3011 <meta name=\"generated\" content=\"%s\"/>
3012 <meta name=\"author\" content=\"%s\"/>
3016 language language
(org-html-expand title
)
3017 (or charset
"iso-8859-1") date author style
))
3019 (insert (or (plist-get opt-plist
:preamble
) ""))
3021 (when (plist-get opt-plist
:auto-preamble
)
3022 (if title
(insert (format org-export-html-title-format
3023 (org-html-expand title
))))))
3025 (if (and org-export-with-toc
(not body-only
))
3027 (push (format "<h%d>%s</h%d>\n"
3028 org-export-html-toplevel-hlevel
3030 org-export-html-toplevel-hlevel
)
3032 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3033 (push "<ul>\n<li>" thetoc
)
3035 (mapcar '(lambda (line)
3036 (if (string-match org-todo-line-regexp line
)
3037 ;; This is a headline
3039 (setq have-headings t
)
3040 (setq level
(- (match-end 1) (match-beginning 1))
3041 level
(org-tr-level level
)
3042 txt
(save-match-data
3044 (org-export-cleanup-toc-line
3045 (match-string 3 line
))))
3047 (or (and org-export-mark-todo-in-toc
3049 (not (member (match-string 2 line
)
3050 org-done-keywords
)))
3052 (and org-export-mark-todo-in-toc
3054 (org-search-todo-below
3055 line lines level
))))
3057 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3058 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3059 (if (string-match quote-re0 txt
)
3060 (setq txt
(replace-match "" t t txt
)))
3061 (setq snumber
(org-section-number level
))
3062 (if org-export-with-section-numbers
3063 (setq txt
(concat snumber
" " txt
)))
3064 (if (<= level
(max umax umax-toc
))
3065 (setq head-count
(+ head-count
1)))
3066 (if (<= level umax-toc
)
3068 (if (> level org-last-level
)
3070 (setq cnt
(- level org-last-level
))
3071 (while (>= (setq cnt
(1- cnt
)) 0)
3072 (push "\n<ul>\n<li>" thetoc
))
3073 (push "\n" thetoc
)))
3074 (if (< level org-last-level
)
3076 (setq cnt
(- org-last-level level
))
3077 (while (>= (setq cnt
(1- cnt
)) 0)
3078 (push "</li>\n</ul>" thetoc
))
3079 (push "\n" thetoc
)))
3080 ;; Check for targets
3081 (while (string-match org-any-target-regexp line
)
3082 (setq line
(replace-match
3083 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3085 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3086 (setq txt
(replace-match "" t t txt
)))
3090 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3091 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3092 snumber txt
) thetoc
)
3094 (setq org-last-level level
))
3098 (while (> org-last-level
(1- org-min-level
))
3099 (setq org-last-level
(1- org-last-level
))
3100 (push "</li>\n</ul>\n" thetoc
))
3101 (push "</div>\n" thetoc
)
3102 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3105 (org-init-section-numbers)
3109 (while (setq line
(pop lines
) origline line
)
3112 ;; end of quote section?
3113 (when (and inquote
(string-match "^\\*+ " line
))
3116 ;; inside a quote section?
3118 (insert (org-html-protect line
) "\n")
3119 (throw 'nextline nil
))
3121 ;; Fixed-width, verbatim lines (examples)
3122 (when (and org-export-with-fixed-width
3123 (string-match "^[ \t]*:\\(.*\\)" line
))
3126 (org-close-par-maybe)
3127 (insert "<pre class=\"example\">\n"))
3128 (insert (org-html-protect (match-string 1 line
)) "\n")
3129 (when (or (not lines
)
3130 (not (string-match "^[ \t]*\\(:.*\\)"
3133 (insert "</pre>\n"))
3134 (throw 'nextline nil
))
3137 (when (get-text-property 0 'org-protected line
)
3139 (when (re-search-backward
3140 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3141 (setq par
(match-string 1))
3142 (replace-match "\\2\n"))
3145 (not (string-match "^[ \t]*:" (car lines
)))
3146 (or (= (length (car lines
)) 0)
3147 (get-text-property 0 'org-protected
(car lines
))))
3148 (insert (pop lines
) "\n"))
3149 (and par
(insert "<p>\n")))
3150 (throw 'nextline nil
))
3153 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3155 (insert "\n</p>\n<hr/>\n<p>\n")
3156 (insert "\n<hr/>\n"))
3157 (throw 'nextline nil
))
3159 ;; Blockquotes and verse
3160 (when (equal "ORG-BLOCKQUOTE-START" line
)
3161 (insert "<blockquote>\n<p>\n")
3162 (throw 'nextline nil
))
3163 (when (equal "ORG-BLOCKQUOTE-END" line
)
3164 (insert "</p>\n</blockquote>\n")
3165 (throw 'nextline nil
))
3166 (when (equal "ORG-VERSE-START" line
)
3167 (insert "\n<p class=\"verse\">\n")
3169 (throw 'nextline nil
))
3170 (when (equal "ORG-VERSE-END" line
)
3173 (throw 'nextline nil
))
3175 (let ((i (org-get-string-indentation line
)))
3177 (setq line
(concat (mapconcat 'identity
3178 (make-list (* 2 i
) "\\nbsp") "")
3179 " " (org-trim line
))))
3180 (setq line
(concat line
" \\\\"))))
3182 ;; make targets to anchors
3183 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3186 (setq line
(replace-match
3187 (concat "@<a name=\""
3188 (org-solidify-link-text (match-string 1 line
))
3191 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3192 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3193 (setq line
(replace-match
3194 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3195 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3198 (setq line
(replace-match
3199 (concat "@<a name=\""
3200 (org-solidify-link-text (match-string 1 line
))
3201 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3204 (setq line
(org-html-handle-time-stamps line
))
3206 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3207 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3208 ;; Also handle sub_superscripts and checkboxes
3209 (or (string-match org-table-hline-regexp line
)
3210 (setq line
(org-html-expand line
)))
3214 (while (string-match org-bracket-link-analytic-regexp line start
)
3215 (setq start
(match-beginning 0))
3216 (setq path
(save-match-data (org-link-unescape
3217 (match-string 3 line
))))
3219 ((match-end 2) (match-string 2 line
))
3221 (or (file-name-absolute-p path
)
3222 (string-match "^\\.\\.?/" path
)))
3225 (setq path
(org-extract-attributes path
))
3226 (setq attr
(org-attributes-to-string
3227 (get-text-property 0 'org-attributes path
)))
3228 (setq desc1
(if (match-end 5) (match-string 5 line
))
3229 desc2
(if (match-end 2) (concat type
":" path
) path
)
3230 descp
(and desc1
(not (equal desc1 desc2
)))
3231 desc
(or desc1 desc2
))
3232 ;; Make an image out of the description if that is so wanted
3233 (when (and descp
(org-file-image-p desc
))
3235 (if (string-match "^file:" desc
)
3236 (setq desc
(substring desc
(match-end 0)))))
3237 (setq desc
(concat "<img src=\"" desc
"\"/>")))
3238 ;; FIXME: do we need to unescape here somewhere?
3240 ((equal type
"internal")
3244 (org-solidify-link-text
3245 (save-match-data (org-link-unescape path
)) nil
)
3247 (org-export-html-format-desc desc
)
3249 ((member type
'("http" "https"))
3250 ;; standard URL, just check if we need to inline an image
3251 (if (and (or (eq t org-export-html-inline-images
)
3252 (and org-export-html-inline-images
(not descp
)))
3253 (org-file-image-p path
))
3254 (setq rpl
(concat "<img src=\"" type
":" path
"\""
3255 (if (string-match "\\<alt=" attr
)
3256 attr
(concat attr
" alt=\"" path
"\""))
3258 (setq link
(concat type
":" path
))
3259 (setq rpl
(concat "<a href=\""
3260 (org-export-html-format-href link
)
3262 (org-export-html-format-desc desc
)
3264 ((member type
'("ftp" "mailto" "news"))
3266 (setq link
(concat type
":" path
))
3267 (setq rpl
(concat "<a href=\""
3268 (org-export-html-format-href link
)
3270 (org-export-html-format-desc desc
)
3273 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3274 ;; The link protocol has a function for format the link
3277 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3279 ((string= type
"file")
3281 (let* ((filename path
)
3282 (abs-p (file-name-absolute-p filename
))
3283 thefile file-is-image-p search
)
3285 (if (string-match "::\\(.*\\)" filename
)
3286 (setq search
(match-string 1 filename
)
3287 filename
(replace-match "" t nil filename
)))
3289 (if (functionp link-validate
)
3290 (funcall link-validate filename current-dir
)
3292 (setq file-is-image-p
(org-file-image-p filename
))
3293 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3294 (when (and org-export-html-link-org-files-as-html
3295 (string-match "\\.org$" thefile
))
3296 (setq thefile
(concat (substring thefile
0
3297 (match-beginning 0))
3298 "." html-extension
))
3300 ;; make sure this is can be used as target search
3301 (not (string-match "^[0-9]*$" search
))
3302 (not (string-match "^\\*" search
))
3303 (not (string-match "^/.*/$" search
)))
3304 (setq thefile
(concat thefile
"#"
3305 (org-solidify-link-text
3306 (org-link-unescape search
)))))
3307 (when (string-match "^file:" desc
)
3308 (setq desc
(replace-match "" t t desc
))
3309 (if (string-match "\\.org$" desc
)
3310 (setq desc
(replace-match "" t t desc
))))))
3311 (setq rpl
(if (and file-is-image-p
3312 (or (eq t org-export-html-inline-images
)
3313 (and org-export-html-inline-images
3315 (concat "<img src=\"" thefile
"\""
3316 (if (string-match "alt=" attr
)
3318 (concat attr
" alt=\""
3319 thefile
"\"")) "/>")
3320 (concat "<a href=\"" thefile
"\"" attr
">"
3321 (org-export-html-format-desc desc
)
3323 (if (not valid
) (setq rpl desc
))))
3326 ;; just publish the path, as default
3327 (setq rpl
(concat "<i><" type
":"
3328 (save-match-data (org-link-unescape path
))
3330 (setq line
(replace-match rpl t t line
)
3331 start
(+ start
(length rpl
))))
3334 (if (and (string-match org-todo-line-regexp line
)
3335 (match-beginning 2))
3338 (concat (substring line
0 (match-beginning 2))
3340 (if (member (match-string 2 line
)
3343 "\">" (match-string 2 line
)
3344 "</span>" (substring line
(match-end 2)))))
3346 ;; Does this contain a reference to a footnote?
3347 (when org-export-with-footnotes
3349 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3350 (if (get-text-property (match-beginning 2) 'org-protected line
)
3351 (setq start
(match-end 2))
3352 (let ((n (match-string 2 line
)))
3356 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3357 (match-string 1 line
) n n n
)
3361 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3362 ;; This is a headline
3363 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3364 txt
(match-string 2 line
))
3365 (if (string-match quote-re0 txt
)
3366 (setq txt
(replace-match "" t t txt
)))
3367 (if (<= level
(max umax umax-toc
))
3368 (setq head-count
(+ head-count
1)))
3370 ;; Close any local lists before inserting a new header line
3371 (while local-list-type
3372 (org-close-li (car local-list-type
))
3373 (insert (format "</%sl>\n" (car local-list-type
)))
3374 (pop local-list-type
))
3375 (setq local-list-indent nil
3377 (setq first-heading-pos
(or first-heading-pos
(point)))
3378 (org-html-level-start level txt umax
3379 (and org-export-with-toc
(<= level umax
))
3382 (when (string-match quote-re line
)
3383 (org-close-par-maybe)
3387 ((and org-export-with-tables
3388 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3389 (if (not table-open
)
3391 (setq table-open t table-buffer nil table-orig-buffer nil
))
3393 (setq table-buffer
(cons line table-buffer
)
3394 table-orig-buffer
(cons origline table-orig-buffer
))
3395 (when (or (not lines
)
3396 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3398 (setq table-open nil
3399 table-buffer
(nreverse table-buffer
)
3400 table-orig-buffer
(nreverse table-orig-buffer
))
3401 (org-close-par-maybe)
3402 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3407 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3408 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3409 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3410 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3412 (setq ind
(org-get-string-indentation line
)
3413 item-type
(if (match-beginning 4) "o" "u")
3414 starter
(if (match-beginning 2)
3415 (substring (match-string 2 line
) 0 -
1))
3416 line
(substring line
(match-beginning 5))
3418 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3420 item-tag
(match-string 1 line
)
3421 line
(substring line
(match-end 0))))
3422 (when (and (not (equal item-type
"d"))
3423 (not (string-match "[^ \t]" line
)))
3424 ;; empty line. Pretend indentation is large.
3425 (setq ind
(if org-empty-line-terminates-plain-lists
3427 (1+ (or (car local-list-indent
) 1)))))
3429 (while (and in-local-list
3430 (or (and (= ind
(car local-list-indent
))
3432 (< ind
(car local-list-indent
))))
3434 (org-close-li (car local-list-type
))
3435 (insert (format "</%sl>\n" (car local-list-type
)))
3436 (pop local-list-type
) (pop local-list-indent
)
3437 (setq in-local-list local-list-indent
))
3440 (or (not in-local-list
)
3441 (> ind
(car local-list-indent
))))
3442 ;; Start new (level of) list
3443 (org-close-par-maybe)
3445 ((equal item-type
"u") "<ul>\n<li>\n")
3446 ((equal item-type
"o") "<ol>\n<li>\n")
3447 ((equal item-type
"d")
3448 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3449 (push item-type local-list-type
)
3450 (push ind local-list-indent
)
3451 (setq in-local-list t
))
3453 ;; continue current list
3454 (org-close-li (car local-list-type
))
3456 ((equal (car local-list-type
) "d")
3457 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3460 ;; we did close a list, normal text follows: need <p>
3462 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3465 (if (equal (match-string 1 line
) "X")
3467 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3470 ;; Empty lines start a new paragraph. If hand-formatted lists
3471 ;; are not fully interpreted, lines starting with "-", "+", "*"
3472 ;; also start a new paragraph.
3473 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3475 ;; Is this the start of a footnote?
3476 (when org-export-with-footnotes
3477 (when (and (boundp 'footnote-section-tag-regexp
)
3478 (string-match (concat "^" footnote-section-tag-regexp
)
3481 (throw 'nextline nil
))
3482 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3483 (org-close-par-maybe)
3484 (let ((n (match-string 1 line
)))
3485 (setq org-par-open t
3487 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3489 ;; Check if the line break needs to be conserved
3491 ((string-match "\\\\\\\\[ \t]*$" line
)
3492 (setq line
(replace-match "<br/>" t t line
)))
3493 (org-export-preserve-breaks
3494 (setq line
(concat line
"<br/>"))))
3496 (insert line
"\n")))))
3498 ;; Properly close all local lists and other lists
3503 ;; Close any local lists before inserting a new header line
3504 (while local-list-type
3505 (org-close-li (car local-list-type
))
3506 (insert (format "</%sl>\n" (car local-list-type
)))
3507 (pop local-list-type
))
3508 (setq local-list-indent nil
3510 (org-html-level-start 1 nil umax
3511 (and org-export-with-toc
(<= level umax
))
3513 ;; the </div> to close the last text-... div.
3517 (goto-char (point-min))
3518 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3519 (push (match-string 0) footnotes
)
3520 (replace-match "" t t
)))
3522 (insert (format org-export-html-footnotes-section
3523 (or (nth 4 lang-words
) "Footnotes")
3524 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3527 (when (plist-get opt-plist
:auto-postamble
)
3528 (insert "<div id=\"postamble\">")
3529 (when (and org-export-author-info author
)
3530 (insert "<p class=\"author\"> "
3531 (nth 1 lang-words
) ": " author
"\n")
3533 (if (listp (split-string email
",+ *"))
3535 (insert "<a href=\"mailto:" e
"\"><"
3537 (split-string email
",+ *"))
3538 (insert "<a href=\"mailto:" email
"\"><"
3539 email
"></a>\n")))
3541 (when (and date org-export-time-stamp-file
)
3542 (insert "<p class=\"date\"> "
3543 (nth 2 lang-words
) ": "
3545 (when org-export-creator-info
3546 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3547 org-version emacs-major-version
)))
3550 (if org-export-html-with-timestamp
3551 (insert org-export-html-html-helper-timestamp
))
3552 (insert (or (plist-get opt-plist
:postamble
) ""))
3553 (insert "</body>\n</html>\n"))
3555 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3557 (if (eq major-mode default-major-mode
) (html-mode)))
3559 ;; insert the table of contents
3560 (goto-char (point-min))
3562 (if (or (re-search-forward
3563 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3565 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3567 (goto-char (match-beginning 0))
3569 (goto-char first-heading-pos
)
3570 (when (looking-at "\\s-*</p>")
3571 (goto-char (match-end 0))
3573 (insert "<div id=\"table-of-contents\">\n")
3574 (mapc 'insert thetoc
)
3575 (insert "</div>\n"))
3576 ;; remove empty paragraphs and lists
3577 (goto-char (point-min))
3578 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3580 (goto-char (point-min))
3581 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3583 (goto-char (point-min))
3584 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3586 ;; Convert whitespace place holders
3587 (goto-char (point-min))
3589 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3590 (setq n
(get-text-property beg
'org-whitespace
)
3591 end
(next-single-property-change beg
'org-whitespace
))
3593 (delete-region beg end
)
3594 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3595 (make-string n ?x
)))))
3596 (or to-buffer
(save-buffer))
3597 (goto-char (point-min))
3598 (message "Exporting... done")
3599 (if (eq to-buffer
'string
)
3600 (prog1 (buffer-substring (point-min) (point-max))
3601 (kill-buffer (current-buffer)))
3602 (current-buffer)))))
3604 (defun org-export-html-format-href (s)
3605 "Make sure the S is valid as a href reference in an XHTML document."
3608 (while (string-match "&" s start
)
3609 (setq start
(+ (match-beginning 0) 3)
3610 s
(replace-match "&" t t s
)))))
3613 (defun org-export-html-format-desc (s)
3614 "Make sure the S is valid as a description in a link."
3617 (org-html-do-expand s
))
3620 (defvar org-table-colgroup-info nil
)
3621 (defun org-format-table-ascii (lines)
3622 "Format a table for ascii export."
3624 (setq lines
(org-split-string lines
"\n")))
3625 (if (not (string-match "^[ \t]*|" (car lines
)))
3626 ;; Table made by table.el - test for spanning
3629 ;; A normal org table
3630 ;; Get rid of hlines at beginning and end
3631 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3632 (setq lines
(nreverse lines
))
3633 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3634 (setq lines
(nreverse lines
))
3635 (when org-export-table-remove-special-lines
3636 ;; Check if the table has a marking column. If yes remove the
3637 ;; column and the special lines
3638 (setq lines
(org-table-clean-before-export lines
)))
3639 ;; Get rid of the vertical lines except for grouping
3640 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3642 (while (setq line
(pop lines
))
3643 (if (string-match org-table-hline-regexp line
)
3644 (and (string-match "|\\(.*\\)|" line
)
3645 (setq line
(replace-match " \\1" t nil line
)))
3646 (setq start
0 vl1 vl
)
3647 (while (string-match "|" line start
)
3648 (setq start
(match-end 0))
3649 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3653 (defun org-colgroup-info-to-vline-list (info)
3656 (setq last new new
(pop info
))
3657 (if (or (memq last
'(:end
:startend
))
3658 (memq new
'(:start
:startend
)))
3661 (setq vl
(nreverse vl
))
3662 (and vl
(setcar vl nil
))
3665 (defvar org-table-number-regexp
) ; defined in org-table.el
3666 (defun org-format-table-html (lines olines
)
3667 "Find out which HTML converter to use and return the HTML code."
3669 (setq lines
(org-split-string lines
"\n")))
3670 (if (string-match "^[ \t]*|" (car lines
))
3671 ;; A normal org table
3672 (org-format-org-table-html lines
)
3673 ;; Table made by table.el - test for spanning
3674 (let* ((hlines (delq nil
(mapcar
3676 (if (string-match "^[ \t]*\\+-" x
) x
3679 (first (car hlines
))
3680 (ll (and (string-match "\\S-+" first
)
3681 (match-string 0 first
)))
3682 (re (concat "^[ \t]*" (regexp-quote ll
)))
3683 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3685 (if (and (not spanning
)
3686 (not org-export-prefer-native-exporter-for-tables
))
3687 ;; We can use my own converter with HTML conversions
3688 (org-format-table-table-html lines
)
3689 ;; Need to use the code generator in table.el, with the original text.
3690 (org-format-table-table-html-using-table-generate-source olines
)))))
3692 (defvar org-table-number-fraction
) ; defined in org-table.el
3693 (defun org-format-org-table-html (lines &optional splice
)
3694 "Format a table into HTML."
3695 (require 'org-table
)
3696 ;; Get rid of hlines at beginning and end
3697 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3698 (setq lines
(nreverse lines
))
3699 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3700 (setq lines
(nreverse lines
))
3701 (when org-export-table-remove-special-lines
3702 ;; Check if the table has a marking column. If yes remove the
3703 ;; column and the special lines
3704 (setq lines
(org-table-clean-before-export lines
)))
3706 (let ((head (and org-export-highlight-first-table-line
3708 (lambda (x) (string-match "^[ \t]*|-" x
))
3711 tbopen line fields html gr colgropen
)
3712 (if splice
(setq head nil
))
3713 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3715 (while (setq line
(pop lines
))
3717 (if (string-match "^[ \t]*|-" line
)
3720 (push (if head
"</thead>" "</tbody>") html
)
3721 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3722 (setq head nil
) ;; head ends here, first time around
3724 (throw 'next-line t
)))
3725 ;; Break the line into fields
3726 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3727 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3728 (setq nlines
(1+ nlines
) i -
1)
3729 (push (concat "<tr>"
3733 (if (and (< i nlines
)
3734 (string-match org-table-number-regexp x
))
3735 (incf (aref fnum i
)))
3737 (concat (car org-export-table-header-tags
) x
3738 (cdr org-export-table-header-tags
))
3739 (concat (car org-export-table-data-tags
) x
3740 (cdr org-export-table-data-tags
))))
3744 (unless splice
(if tbopen
(push "</tbody>" html
)))
3745 (unless splice
(push "</table>\n" html
))
3746 (setq html
(nreverse html
))
3748 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3751 (setq gr
(pop org-table-colgroup-info
))
3752 (format "%s<col align=\"%s\"></col>%s"
3753 (if (memq gr
'(:start
:startend
))
3755 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3758 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3760 (if (memq gr
'(:end
:startend
))
3761 (progn (setq colgropen nil
) "</colgroup>")
3765 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3766 (push html-table-tag html
))
3767 (concat (mapconcat 'identity html
"\n") "\n")))
3769 (defun org-table-clean-before-export (lines)
3770 "Check if the table has a marking column.
3771 If yes remove the column and the special lines."
3772 (setq org-table-colgroup-info nil
)
3775 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3776 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3779 (setq org-table-clean-did-remove-column nil
)
3784 ((string-match "^[ \t]*| */ *|" x
)
3785 (setq org-table-colgroup-info
3787 (cond ((member x
'("<" "<")) :start
)
3788 ((member x
'(">" ">")) :end
)
3789 ((member x
'("<>" "<>")) :startend
)
3791 (org-split-string x
"[ \t]*|[ \t]*")))
3795 (setq org-table-clean-did-remove-column t
)
3800 ((string-match "^[ \t]*| */ *|" x
)
3801 (setq org-table-colgroup-info
3803 (cond ((member x
'("<" "<")) :start
)
3804 ((member x
'(">" ">")) :end
)
3805 ((member x
'("<>" "<>")) :startend
)
3807 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3809 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3810 nil
) ; ignore this line
3811 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3812 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3813 ;; remove the first column
3814 (replace-match "\\1|" t nil x
))))
3817 (defun org-format-table-table-html (lines)
3818 "Format a table generated by table.el into HTML.
3819 This conversion does *not* use `table-generate-source' from table.el.
3820 This has the advantage that Org-mode's HTML conversions can be used.
3821 But it has the disadvantage, that no cell- or row-spanning is allowed."
3822 (let (line field-buffer
3823 (head org-export-highlight-first-table-line
)
3825 (setq html
(concat html-table-tag
"\n"))
3826 (while (setq line
(pop lines
))
3827 (setq empty
" ")
3829 (if (string-match "^[ \t]*\\+-" line
)
3840 (if (equal x
"") (setq x empty
))
3842 (concat (car org-export-table-header-tags
) x
3843 (cdr org-export-table-header-tags
))
3844 (concat (car org-export-table-data-tags
) x
3845 (cdr org-export-table-data-tags
))))
3849 (setq field-buffer nil
)))
3851 (throw 'next-line t
)))
3852 ;; Break the line into fields and store the fields
3853 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3855 (setq field-buffer
(mapcar
3857 (concat x
"<br/>" (pop fields
)))
3859 (setq field-buffer fields
))))
3860 (setq html
(concat html
"</table>\n"))
3863 (defun org-format-table-table-html-using-table-generate-source (lines)
3864 "Format a table into html, using `table-generate-source' from table.el.
3865 This has the advantage that cell- or row-spanning is allowed.
3866 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3868 (with-current-buffer (get-buffer-create " org-tmp1 ")
3870 (insert (mapconcat 'identity lines
"\n"))
3871 (goto-char (point-min))
3872 (if (not (re-search-forward "|[^+]" nil t
))
3873 (error "Error processing table"))
3874 (table-recognize-table)
3875 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3876 (table-generate-source 'html
" org-tmp2 ")
3877 (set-buffer " org-tmp2 ")
3878 (buffer-substring (point-min) (point-max))))
3880 (defun org-export-splice-style (style extra
)
3881 "Splice EXTRA into STYLE, just before \"</style>\"."
3882 (if (and (stringp extra
)
3883 (string-match "\\S-" extra
)
3884 (string-match "</style>" style
))
3885 (concat (substring style
0 (match-beginning 0))
3887 (substring style
(match-beginning 0)))
3890 (defun org-html-handle-time-stamps (s)
3891 "Format time stamps in string S, or remove them."
3894 (while (string-match org-maybe-keyword-time-regexp s
)
3895 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3896 ;; never export CLOCK
3898 (or b
(setq b
(substring s
0 (match-beginning 0))))
3899 (if (not org-export-with-timestamps
)
3900 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3901 s
(substring s
(match-end 0)))
3903 r
(substring s
0 (match-beginning 0))
3905 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3906 (match-string 1 s
)))
3907 (format " @<span class=\"timestamp\">%s@</span>"
3909 (org-translate-time (match-string 3 s
)) 1 -
1)))
3910 s
(substring s
(match-end 0)))))
3911 ;; Line break if line started and ended with time stamp stuff
3914 (setq r
(concat r s
))
3915 (unless (string-match "\\S-" (concat b s
))
3916 (setq r
(concat r
"@<br/>")))
3919 (defun org-export-htmlize-region-for-paste (beg end
)
3920 "Convert the region to HTML, using htmlize.el.
3921 This is much like `htmlize-region-for-paste', only that it uses
3922 the settings define in the org-... variables."
3923 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3924 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3925 (htmlbuf (htmlize-region beg end
)))
3927 (with-current-buffer htmlbuf
3928 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3929 (plist-get htmlize-buffer-places
'content-end
)))
3930 (kill-buffer htmlbuf
))))
3933 (defun org-export-htmlize-generate-css ()
3934 "Create the CSS for all font definitions in the current Emacs session.
3935 Use this to create face definitions in your CSS style file that can then
3936 be used by code snippets transformed by htmlize.
3937 This command just produces a buffer that contains class definitions for all
3938 faces used in the current Emacs session. You can copy and paste the ones you
3939 need into your CSS file.
3941 If you then set `org-export-htmlize-output-type' to `css', calls to
3942 the function `org-export-htmlize-region-for-paste' will produce code
3943 that uses these same face definitions."
3946 (and (get-buffer "*html*") (kill-buffer "*html*"))
3948 (let ((fl (face-list))
3949 (htmlize-css-name-prefix "org-")
3950 (htmlize-output-type 'css
)
3952 (while (setq f
(pop fl
)
3953 i
(and f
(face-attribute f
:inherit
)))
3954 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3955 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3956 (htmlize-region (point-min) (point-max))))
3957 (switch-to-buffer "*html*")
3958 (goto-char (point-min))
3959 (if (re-search-forward "<style" nil t
)
3960 (delete-region (point-min) (match-beginning 0)))
3961 (if (re-search-forward "</style>" nil t
)
3962 (delete-region (1+ (match-end 0)) (point-max)))
3963 (beginning-of-line 1)
3964 (if (looking-at " +") (replace-match ""))
3965 (goto-char (point-min)))
3967 (defun org-html-protect (s)
3968 ;; convert & to &, < to < and > to >
3970 (while (string-match "&" s start
)
3971 (setq s
(replace-match "&" t t s
)
3972 start
(1+ (match-beginning 0))))
3973 (while (string-match "<" s
)
3974 (setq s
(replace-match "<" t t s
)))
3975 (while (string-match ">" s
)
3976 (setq s
(replace-match ">" t t s
)))
3977 ; (while (string-match "\"" s)
3978 ; (setq s (replace-match """ t t s)))
3982 (defun org-export-cleanup-toc-line (s)
3983 "Remove tags and time staps from lines going into the toc."
3984 (when (memq org-export-with-tags
'(not-in-toc nil
))
3985 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3986 (setq s
(replace-match "" t t s
))))
3987 (when org-export-remove-timestamps-from-toc
3988 (while (string-match org-maybe-keyword-time-regexp s
)
3989 (setq s
(replace-match "" t t s
))))
3990 (while (string-match org-bracket-link-regexp s
)
3991 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3995 (defun org-html-expand (string)
3996 "Prepare STRING for HTML export. Applies all active conversions.
3997 If there are links in the string, don't modify these."
3998 (let* ((re (concat org-bracket-link-regexp
"\\|"
3999 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4001 (while (setq m
(string-match re string
))
4002 (setq s
(substring string
0 m
)
4003 l
(match-string 0 string
)
4004 string
(substring string
(match-end 0)))
4005 (push (org-html-do-expand s
) res
)
4007 (push (org-html-do-expand string
) res
)
4008 (apply 'concat
(nreverse res
))))
4010 (defun org-html-do-expand (s)
4011 "Apply all active conversions to translate special ASCII to HTML."
4012 (setq s
(org-html-protect s
))
4013 (if org-export-html-expand
4015 (while (string-match "@<\\([^&]*\\)>" s
)
4016 (setq s
(replace-match "<\\1>" t nil s
)))))
4017 (if org-export-with-emphasize
4018 (setq s
(org-export-html-convert-emphasize s
)))
4019 (if org-export-with-special-strings
4020 (setq s
(org-export-html-convert-special-strings s
)))
4021 (if org-export-with-sub-superscripts
4022 (setq s
(org-export-html-convert-sub-super s
)))
4023 (if org-export-with-TeX-macros
4024 (let ((start 0) wd ass
)
4025 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4027 (if (get-text-property (match-beginning 0) 'org-protected s
)
4028 (setq start
(match-end 0))
4029 (setq wd
(match-string 1 s
))
4030 (if (setq ass
(assoc wd org-html-entities
))
4031 (setq s
(replace-match (or (cdr ass
)
4032 (concat "&" (car ass
) ";"))
4034 (setq start
(+ start
(length wd
))))))))
4037 (defun org-create-multibrace-regexp (left right n
)
4038 "Create a regular expression which will match a balanced sexp.
4039 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4040 as single character strings.
4041 The regexp returned will match the entire expression including the
4042 delimiters. It will also define a single group which contains the
4043 match except for the outermost delimiters. The maximum depth of
4044 stacked delimiters is N. Escaping delimiters is not possible."
4045 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4048 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4051 re
(concat re or next
)
4052 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4053 (concat left
"\\(" re
"\\)" right
)))
4055 (defvar org-match-substring-regexp
4057 "\\([^\\]\\)\\([_^]\\)\\("
4058 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4060 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4062 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4063 "The regular expression matching a sub- or superscript.")
4065 (defvar org-match-substring-with-braces-regexp
4067 "\\([^\\]\\)\\([_^]\\)\\("
4068 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4070 "The regular expression matching a sub- or superscript, forcing braces.")
4072 (defconst org-export-html-special-string-regexps
4073 '(("\\\\-" .
"­")
4074 ("---\\([^-]\\)" .
"—\\1")
4075 ("--\\([^-]\\)" .
"–\\1")
4076 ("\\.\\.\\." .
"…"))
4077 "Regular expressions for special string conversion.")
4079 (defun org-export-html-convert-special-strings (string)
4080 "Convert special characters in STRING to HTML."
4081 (let ((all org-export-html-special-string-regexps
)
4083 (while (setq a
(pop all
))
4084 (setq re
(car a
) rpl
(cdr a
) start
0)
4085 (while (string-match re string start
)
4086 (if (get-text-property (match-beginning 0) 'org-protected string
)
4087 (setq start
(match-end 0))
4088 (setq string
(replace-match rpl t nil string
)))))
4091 (defun org-export-html-convert-sub-super (string)
4092 "Convert sub- and superscripts in STRING to HTML."
4093 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4094 (while (string-match org-match-substring-regexp string s
)
4096 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4097 ((get-text-property (match-beginning 2) 'org-protected string
)
4098 (setq s
(match-end 2)))
4100 (setq s
(match-end 1)
4101 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4102 c
(or (match-string 8 string
)
4103 (match-string 6 string
)
4104 (match-string 5 string
))
4105 string
(replace-match
4106 (concat (match-string 1 string
)
4107 "<" key
">" c
"</" key
">")
4109 (while (string-match "\\\\\\([_^]\\)" string
)
4110 (setq string
(replace-match (match-string 1 string
) t t string
)))
4113 (defun org-export-html-convert-emphasize (string)
4116 (while (string-match org-emph-re string s
)
4118 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4119 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4120 (setq s
(match-beginning 0)
4123 (match-string 1 string
)
4124 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4125 (match-string 4 string
)
4126 (nth 3 (assoc (match-string 3 string
)
4127 org-emphasis-alist
))
4128 (match-string 5 string
))
4129 string
(replace-match rpl t t string
)
4130 s
(+ s
(- (length rpl
) 2)))
4134 (defun org-open-par ()
4135 "Insert <p>, but first close previous paragraph if any."
4136 (org-close-par-maybe)
4138 (setq org-par-open t
))
4139 (defun org-close-par-maybe ()
4140 "Close paragraph if there is one open."
4143 (setq org-par-open nil
)))
4144 (defun org-close-li (&optional type
)
4145 "Close <li> if necessary."
4146 (org-close-par-maybe)
4147 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4149 (defvar body-only
) ; dynamically scoped into this.
4150 (defun org-html-level-start (level title umax with-toc head-count
)
4151 "Insert a new level in HTML export.
4152 When TITLE is nil, just close all open levels."
4153 (org-close-par-maybe)
4154 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
4158 (if (aref org-levels-open
(1- l
))
4160 (org-html-level-close l umax
)
4161 (aset org-levels-open
(1- l
) nil
)))
4164 ;; If title is nil, this means this function is called to close
4165 ;; all levels, so the rest is done only if title is given
4166 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4167 (setq title
(replace-match
4168 (if org-export-with-tags
4171 " <span class=\"tag\">"
4172 (mapconcat 'identity
(org-split-string
4173 (match-string 1 title
) ":")
4180 (if (aref org-levels-open
(1- level
))
4184 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
4185 (insert "<li>" title
"<br/>\n")))
4186 (aset org-levels-open
(1- level
) t
)
4187 (org-close-par-maybe)
4189 (insert (format "<ul>\n<li id=\"%s\">" target
)
4191 (insert "<ul>\n<li>" title
"<br/>\n"))))
4192 (aset org-levels-open
(1- level
) t
)
4193 (setq snumber
(org-section-number level
))
4194 (if (and org-export-with-section-numbers
(not body-only
))
4195 (setq title
(concat snumber
" " title
)))
4196 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4197 (unless (= head-count
1) (insert "\n</div>\n"))
4198 (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"
4199 snumber level level snumber title level snumber
))
4202 (defun org-get-text-property-any (pos prop
&optional object
)
4203 (or (get-text-property pos prop object
)
4204 (and (setq pos
(next-single-property-change pos prop object
))
4205 (get-text-property pos prop object
))))
4207 (defun org-html-level-close (level max-outline-level
)
4208 "Terminate one level in HTML export."
4209 (if (<= level max-outline-level
)
4212 (insert "</ul>\n")))
4214 ;;; iCalendar export
4217 (defun org-export-icalendar-this-file ()
4218 "Export current file as an iCalendar file.
4219 The iCalendar file will be located in the same directory as the Org-mode
4220 file, but with extension `.ics'."
4222 (org-export-icalendar nil buffer-file-name
))
4225 (defun org-export-icalendar-all-agenda-files ()
4226 "Export all files in `org-agenda-files' to iCalendar .ics files.
4227 Each iCalendar file will be located in the same directory as the Org-mode
4228 file, but with extension `.ics'."
4230 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4233 (defun org-export-icalendar-combine-agenda-files ()
4234 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4235 The file is stored under the name `org-combined-agenda-icalendar-file'."
4237 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4239 (defun org-export-icalendar (combine &rest files
)
4240 "Create iCalendar files for all elements of FILES.
4241 If COMBINE is non-nil, combine all calendar entries into a single large
4242 file and store it under the name `org-combined-agenda-icalendar-file'."
4244 (org-prepare-agenda-buffers files
)
4245 (let* ((dir (org-export-directory
4246 :ical
(list :publishing-directory
4247 org-export-publishing-directory
)))
4248 file ical-file ical-buffer category started org-agenda-new-buffers
)
4249 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4252 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4253 org-combined-agenda-icalendar-file
4254 (expand-file-name org-combined-agenda-icalendar-file dir
))
4255 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4256 (set-buffer ical-buffer
) (erase-buffer))
4257 (while (setq file
(pop files
))
4259 (org-check-agenda-file file
)
4260 (set-buffer (org-get-agenda-file-buffer file
))
4262 (setq ical-file
(concat (file-name-as-directory dir
)
4263 (file-name-sans-extension
4264 (file-name-nondirectory buffer-file-name
))
4266 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4267 (with-current-buffer ical-buffer
(erase-buffer)))
4268 (setq category
(or org-category
4269 (file-name-sans-extension
4270 (file-name-nondirectory buffer-file-name
))))
4271 (if (symbolp category
) (setq category
(symbol-name category
)))
4272 (let ((standard-output ical-buffer
))
4274 (and (not started
) (setq started t
)
4275 (org-start-icalendar-file org-icalendar-combined-name
))
4276 (org-start-icalendar-file category
))
4277 (org-print-icalendar-entries combine
)
4278 (when (or (and combine
(not files
)) (not combine
))
4279 (org-finish-icalendar-file)
4280 (set-buffer ical-buffer
)
4281 (run-hooks 'org-before-save-iCalendar-file-hook
)
4283 (run-hooks 'org-after-save-iCalendar-file-hook
)
4284 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4286 (org-release-buffers org-agenda-new-buffers
))))
4288 (defvar org-before-save-iCalendar-file-hook nil
4289 "Hook run before an iCalendar file has been saved.
4290 This can be used to modify the result of the export.")
4292 (defvar org-after-save-iCalendar-file-hook nil
4293 "Hook run after an iCalendar file has been saved.
4294 The iCalendar buffer is still current when this hook is run.
4295 A good way to use this is to tell a desktop calenndar application to re-read
4296 the iCalendar file.")
4298 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4299 (defun org-print-icalendar-entries (&optional combine
)
4300 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4301 When COMBINE is non nil, add the category to each line."
4302 (require 'org-agenda
)
4303 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4304 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4305 (dts (org-ical-ts-to-string
4306 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4308 hd ts ts2 state status
(inc t
) pos b sexp rrule
4309 scheduledp deadlinep todo prefix due start
4310 tmp pri categories entry location summary desc uid
4311 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4312 (org-refresh-category-properties)
4314 (goto-char (point-min))
4315 (while (re-search-forward re1 nil t
)
4318 (when (boundp 'org-icalendar-verify-function
)
4319 (unless (funcall org-icalendar-verify-function
)
4320 (outline-next-heading)
4323 (setq pos
(match-beginning 0)
4326 hd
(condition-case nil
4327 (org-icalendar-cleanup-string
4329 (error (throw :skip nil
)))
4330 summary
(org-icalendar-cleanup-string
4331 (org-entry-get nil
"SUMMARY"))
4332 desc
(org-icalendar-cleanup-string
4333 (or (org-entry-get nil
"DESCRIPTION")
4334 (and org-icalendar-include-body
(org-get-entry)))
4335 t org-icalendar-include-body
)
4336 location
(org-icalendar-cleanup-string
4337 (org-entry-get nil
"LOCATION"))
4338 uid
(if org-icalendar-store-UID
4340 (or (org-id-get) (org-id-new)))
4341 categories
(org-export-get-categories)
4342 deadlinep nil scheduledp nil
)
4343 (if (looking-at re2
)
4345 (goto-char (match-end 0))
4346 (setq ts2
(match-string 1)
4347 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4348 (setq tmp
(buffer-substring (max (point-min)
4349 (- pos org-ds-keyword-length
))
4351 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4354 (replace-match "\\1" t nil ts
))
4356 deadlinep
(string-match org-deadline-regexp tmp
)
4357 scheduledp
(string-match org-scheduled-regexp tmp
)
4358 todo
(org-get-todo-state)
4359 ;; donep (org-entry-is-done-p)
4364 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4365 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4370 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4371 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4373 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4374 (if (or (string-match org-tr-regexp hd
)
4375 (string-match org-ts-regexp hd
))
4376 (setq hd
(replace-match "" t t hd
)))
4377 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4379 (concat "\nRRULE:FREQ="
4382 '(("d" .
"DAILY")("w" .
"WEEKLY")
4383 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4384 ";INTERVAL=" (match-string 1 ts
)))
4386 (setq summary
(or summary hd
))
4387 (if (string-match org-bracket-link-regexp summary
)
4389 (replace-match (if (match-end 3)
4390 (match-string 3 summary
)
4391 (match-string 1 summary
))
4393 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4394 (if scheduledp
(setq summary
(concat "S: " summary
)))
4395 (if (string-match "\\`<%%" ts
)
4396 (with-current-buffer sexp-buffer
4397 (insert (substring ts
1 -
1) " " summary
"\n"))
4398 (princ (format "BEGIN:VEVENT
4406 (org-ical-ts-to-string ts
"DTSTART")
4407 (org-ical-ts-to-string ts2
"DTEND" inc
)
4409 (if (and desc
(string-match "\\S-" desc
))
4410 (concat "\nDESCRIPTION: " desc
) "")
4411 (if (and location
(string-match "\\S-" location
))
4412 (concat "\nLOCATION: " location
) "")
4414 (when (and org-icalendar-include-sexps
4415 (condition-case nil
(require 'icalendar
) (error nil
))
4416 (fboundp 'icalendar-export-region
))
4417 ;; Get all the literal sexps
4418 (goto-char (point-min))
4419 (while (re-search-forward "^&?%%(" nil t
)
4422 (setq b
(match-beginning 0))
4423 (goto-char (1- (match-end 0)))
4426 (setq sexp
(buffer-substring b
(point)))
4427 (with-current-buffer sexp-buffer
4428 (insert sexp
"\n"))))
4429 (princ (org-diary-to-ical-string sexp-buffer
))
4430 (kill-buffer sexp-buffer
))
4432 (when org-icalendar-include-todo
4433 (setq prefix
"TODO-")
4434 (goto-char (point-min))
4435 (while (re-search-forward org-todo-line-regexp nil t
)
4438 (when (boundp 'org-icalendar-verify-function
)
4439 (unless (funcall org-icalendar-verify-function
)
4440 (outline-next-heading)
4443 (setq state
(match-string 2))
4444 (setq status
(if (member state org-done-keywords
)
4445 "COMPLETED" "NEEDS-ACTION"))
4447 (or (not (member state org-done-keywords
))
4448 (eq org-icalendar-include-todo
'all
))
4449 (not (member org-archive-tag
(org-get-tags-at)))
4451 (setq hd
(match-string 3)
4452 summary
(org-icalendar-cleanup-string
4453 (org-entry-get nil
"SUMMARY"))
4454 desc
(org-icalendar-cleanup-string
4455 (or (org-entry-get nil
"DESCRIPTION")
4456 (and org-icalendar-include-body
(org-get-entry)))
4457 t org-icalendar-include-body
)
4458 location
(org-icalendar-cleanup-string
4459 (org-entry-get nil
"LOCATION"))
4460 due
(and (member 'todo-due org-icalendar-use-deadline
)
4461 (org-entry-get nil
"DEADLINE"))
4462 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4463 (org-entry-get nil
"SCHEDULED"))
4464 categories
(org-export-get-categories)
4465 uid
(if org-icalendar-store-UID
4467 (or (org-id-get) (org-id-new))))
4468 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4469 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4471 (if (string-match org-bracket-link-regexp hd
)
4472 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4473 (match-string 1 hd
))
4475 (if (string-match org-priority-regexp hd
)
4476 (setq pri
(string-to-char (match-string 2 hd
))
4477 hd
(concat (substring hd
0 (match-beginning 1))
4478 (substring hd
(match-end 1))))
4479 (setq pri org-default-priority
))
4480 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4481 (- org-lowest-priority org-highest-priority
))))))
4483 (princ (format "BEGIN:VTODO
4495 (if (and location
(string-match "\\S-" location
))
4496 (concat "\nLOCATION: " location
) "")
4497 (if (and desc
(string-match "\\S-" desc
))
4498 (concat "\nDESCRIPTION: " desc
) "")
4499 (if due
(concat "\n" due
) "")
4503 (defun org-export-get-categories ()
4504 "Get categories according to `org-icalendar-categories'."
4505 (let ((cs org-icalendar-categories
) c rtn tmp
)
4506 (while (setq c
(pop cs
))
4508 ((eq c
'category
) (push (org-get-category) rtn
))
4510 (setq tmp
(org-get-todo-state))
4511 (and tmp
(push tmp rtn
)))
4513 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4515 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4516 (mapconcat 'identity
(nreverse rtn
) ",")))
4518 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4519 "Take out stuff and quote what needs to be quoted.
4520 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4521 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4526 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4527 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4528 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4529 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4531 (while (string-match "\\([,;]\\)" s start
)
4532 (setq start
(+ (match-beginning 0) 2)
4533 s
(replace-match "\\\\\\1" nil nil s
))))
4534 (setq s
(org-trim s
))
4536 (while (string-match "[ \t]*\n[ \t]*" s
)
4537 (setq s
(replace-match "\\n" t t s
))))
4540 (if (and (numberp maxlength
)
4541 (> (length s
) maxlength
))
4542 (setq s
(substring s
0 maxlength
)))))
4545 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4546 "Take out stuff and quote what needs to be quoted.
4547 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4548 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4550 This seems to be more like RFC 2455, but it causes problems, so it is
4551 not used right now."
4555 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4556 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4557 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4558 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4559 (setq s
(org-trim s
))
4560 (while (string-match "[ \t]*\n[ \t]*" s
)
4561 (setq s
(replace-match "\\n" t t s
)))
4563 (if (and (numberp maxlength
)
4564 (> (length s
) maxlength
))
4565 (setq s
(substring s
0 maxlength
)))))
4566 (setq s
(org-trim s
)))
4567 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4568 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
4571 (defun org-get-entry ()
4572 "Clean-up description string."
4574 (org-back-to-heading t
)
4575 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4577 (defun org-start-icalendar-file (name)
4578 "Start an iCalendar file by inserting the header."
4579 (let ((user user-full-name
)
4580 (name (or name
"unknown"))
4581 (timezone (cadr (current-time-zone))))
4583 (format "BEGIN:VCALENDAR
4586 PRODID:-//%s//Emacs with Org-mode//EN
4588 CALSCALE:GREGORIAN\n" name user timezone
))))
4590 (defun org-finish-icalendar-file ()
4591 "Finish an iCalendar file by inserting the END statement."
4592 (princ "END:VCALENDAR\n"))
4594 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4595 "Take a time string S and convert it to iCalendar format.
4596 KEYWORD is added in front, to make a complete line like DTSTART....
4597 When INC is non-nil, increase the hour by two (if time string contains
4598 a time), or the day by one (if it does not contain a time)."
4599 (let ((t1 (org-parse-time-string s
'nodefault
))
4600 t2 fmt have-time time
)
4601 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4602 (setq t2 t1 have-time t
)
4603 (setq t2
(org-parse-time-string s
)))
4604 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4605 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4608 (if org-agenda-default-appointment-duration
4609 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4612 (setq time
(encode-time s mi h d m y
)))
4613 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4614 (concat keyword
(format-time-string fmt time
))))
4618 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4619 (with-current-buffer buffer
4620 (apply 'insert output
)))
4621 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4624 (defun org-export-as-xoxo (&optional buffer
)
4625 "Export the org buffer as XOXO.
4626 The XOXO buffer is named *xoxo-<source buffer name>*"
4627 (interactive (list (current-buffer)))
4628 ;; A quickie abstraction
4630 ;; Output everything as XOXO
4631 (with-current-buffer (get-buffer buffer
)
4632 (let* ((pos (point))
4633 (opt-plist (org-combine-plists (org-default-export-plist)
4634 (org-infile-export-plist)))
4635 (filename (concat (file-name-as-directory
4636 (org-export-directory :xoxo opt-plist
))
4637 (file-name-sans-extension
4638 (file-name-nondirectory buffer-file-name
))
4640 (out (find-file-noselect filename
))
4643 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4644 ;; Check the output buffer is empty.
4645 (with-current-buffer out
(erase-buffer))
4646 ;; Kick off the output
4647 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4648 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4649 (let* ((hd (match-string-no-properties 1))
4652 (match-string-no-properties 2)
4654 (goto-char (match-end 0))
4659 (if (looking-at "^[ \t]\\(.*\\)")
4660 (setq str
(concat str
(match-string-no-properties 1)))
4661 (throw 'loop str
)))))))))
4663 ;; Handle level rendering
4665 ((> level last-level
)
4666 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4668 ((< level last-level
)
4669 (dotimes (- (- last-level level
) 1)
4671 (org-export-as-xoxo-insert-into out
"</li>\n"))
4672 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4674 (org-export-as-xoxo-insert-into out
"</li>\n")
4675 (setq hanging-li nil
)))
4677 ((equal level last-level
)
4679 (org-export-as-xoxo-insert-into out
"</li>\n")))
4682 (setq last-level level
)
4684 ;; And output the new li
4685 (setq hanging-li
't
)
4686 (if (equal ?
+ (elt text
0))
4687 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4688 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4690 ;; Finally finish off the ol
4691 (dotimes (- last-level
1)
4693 (org-export-as-xoxo-insert-into out
"</li>\n"))
4694 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4697 ;; Finish the buffer off and clean it up.
4698 (switch-to-buffer-other-window out
)
4699 (indent-region (point-min) (point-max) nil
)
4701 (goto-char (point-min))
4706 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4708 ;;; org-exp.el ends here