1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
68 (defcustom org-export-select-tags
'("export")
69 "Tags that select a tree for export.
70 If any such tag is found in a buffer, all trees that do not carry one
71 of these tags will be deleted before export.
72 Inside trees that are selected like this, you can still deselect a
73 subtree by tagging it with one of the `org-export-exclude-tags'."
74 :group
'org-export-general
75 :type
'(repeat (string :tag
"Tag")))
77 (defcustom org-export-exclude-tags
'("noexport")
78 "Tags that exclude a tree from export.
79 All trees carrying any of these tags will be excluded from export.
80 This is without condition, so even subtrees inside that carry one of the
81 `org-export-select-tags' will be removed."
82 :group
'org-export-general
83 :type
'(repeat (string :tag
"Tag")))
85 (defcustom org-export-with-special-strings t
86 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
87 When this option is turned on, these strings will be exported as:
90 -----+----------+--------
96 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
97 :group
'org-export-translation
100 (defcustom org-export-language-setup
101 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
102 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
103 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
104 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
105 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
106 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
107 ("es" "Autor" "Fecha" "Índice" "Pies de página")
108 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
109 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
110 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
111 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
112 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
113 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
114 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
115 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
116 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
117 ("pl" "Autor" "Data" "Spis treści" "Przypis")
118 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
119 "Terms used in export text, translated to different languages.
120 Use the variable `org-export-default-language' to set the language,
121 or use the +OPTION lines for a per-file setting."
122 :group
'org-export-general
125 (string :tag
"HTML language tag")
126 (string :tag
"Author")
128 (string :tag
"Table of Contents")
129 (string :tag
"Footnotes"))))
131 (defcustom org-export-default-language
"en"
132 "The default language of HTML export, as a string.
133 This should have an association in `org-export-language-setup'."
134 :group
'org-export-general
137 (defcustom org-export-skip-text-before-1st-heading nil
138 "Non-nil means, skip all text before the first headline when exporting.
139 When nil, that text is exported as well."
140 :group
'org-export-general
143 (defcustom org-export-headline-levels
3
144 "The last level which is still exported as a headline.
145 Inferior levels will produce itemize lists when exported.
146 Note that a numeric prefix argument to an exporter function overrides
149 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
150 :group
'org-export-general
153 (defcustom org-export-with-section-numbers t
154 "Non-nil means, add section numbers to headlines when exporting.
156 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
157 :group
'org-export-general
160 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
161 "Format of section numbers for export.
162 The variable has two components.
163 1. A list of lists, each indicating a counter type and a separator.
164 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
165 It causes causes numeric, alphabetic, or roman counters, respectively.
166 The separator is only used if another counter for a subsection is being
168 If there are more numbered section levels than entries in this lists,
169 then the last entry will be reused.
170 2. A terminator string that will be added after the entire
172 :group
'org-export-general
176 (string :tag
"Counter Type")
177 (string :tag
"Separator ")))
178 (string :tag
"Terminator")))
180 (defcustom org-export-with-toc t
181 "Non-nil means, create a table of contents in exported files.
182 The TOC contains headlines with levels up to`org-export-headline-levels'.
183 When an integer, include levels up to N in the toc, this may then be
184 different from `org-export-headline-levels', but it will not be allowed
185 to be larger than the number of headline levels.
186 When nil, no table of contents is made.
188 Headlines which contain any TODO items will be marked with \"(*)\" in
189 ASCII export, and with red color in HTML output, if the option
190 `org-export-mark-todo-in-toc' is set.
192 In HTML output, the TOC will be clickable.
194 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
196 :group
'org-export-general
198 (const :tag
"No Table of Contents" nil
)
199 (const :tag
"Full Table of Contents" t
)
200 (integer :tag
"TOC to level")))
202 (defcustom org-export-mark-todo-in-toc nil
203 "Non-nil means, mark TOC lines that contain any open TODO items."
204 :group
'org-export-general
207 (defcustom org-export-with-todo-keywords t
208 "Non-nil means, include TODO keywords in export.
209 When nil, remove all these keywords from the export."
210 :group
'org-export-general
213 (defcustom org-export-with-priority nil
214 "Non-nil means, include priority cookies in export.
215 When nil, remove priority cookies for export."
216 :group
'org-export-general
219 (defcustom org-export-preserve-breaks nil
220 "Non-nil means, preserve all line breaks when exporting.
221 Normally, in HTML output paragraphs will be reformatted. In ASCII
222 export, line breaks will always be preserved, regardless of this variable.
224 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
225 :group
'org-export-general
228 (defcustom org-export-with-archived-trees
'headline
229 "Whether subtrees with the ARCHIVE tag should be exported.
230 This can have three different values
231 nil Do not export, pretend this tree is not present
232 t Do export the entire tree
233 headline Only export the headline, but skip the tree below it."
234 :group
'org-export-general
237 (const :tag
"not at all" nil
)
238 (const :tag
"headline only" 'headline
)
239 (const :tag
"entirely" t
)))
241 (defcustom org-export-author-info t
242 "Non-nil means, insert author name and email into the exported file.
244 This option can also be set with the +OPTIONS line,
245 e.g. \"author-info:nil\"."
246 :group
'org-export-general
249 (defcustom org-export-creator-info t
250 "Non-nil means, the postamble should contain a creator sentence.
251 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
252 :group
'org-export-general
255 (defcustom org-export-time-stamp-file t
256 "Non-nil means, insert a time stamp into the exported file.
257 The time stamp shows when the file was created.
259 This option can also be set with the +OPTIONS line,
260 e.g. \"timestamp:nil\"."
261 :group
'org-export-general
264 (defcustom org-export-with-timestamps t
265 "If nil, do not export time stamps and associated keywords."
266 :group
'org-export-general
269 (defcustom org-export-remove-timestamps-from-toc t
270 "If nil, remove timestamps from the table of contents entries."
271 :group
'org-export-general
274 (defcustom org-export-with-tags
'not-in-toc
275 "If nil, do not export tags, just remove them from headlines.
276 If this is the symbol `not-in-toc', tags will be removed from table of
277 contents entries, but still be shown in the headlines of the document.
279 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
280 :group
'org-export-general
282 (const :tag
"Off" nil
)
283 (const :tag
"Not in TOC" not-in-toc
)
284 (const :tag
"On" t
)))
286 (defcustom org-export-with-drawers nil
287 "Non-nil means, export with drawers like the property drawer.
288 When t, all drawers are exported. This may also be a list of
289 drawer names to export."
290 :group
'org-export-general
292 (const :tag
"All drawers" t
)
293 (const :tag
"None" nil
)
294 (repeat :tag
"Selected drawers"
295 (string :tag
"Drawer name"))))
297 (defvar org-export-preprocess-hook nil
298 "Hook for preprocessing an export buffer.
299 Pretty much the first thing when exporting is running this hook.")
301 (defgroup org-export-translation nil
302 "Options for translating special ascii sequences for the export backends."
303 :tag
"Org Export Translation"
306 (defcustom org-export-with-emphasize t
307 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
308 If the export target supports emphasizing text, the word will be
309 typeset in bold, italic, or underlined, respectively. Works only for
310 single words, but you can say: I *really* *mean* *this*.
311 Not all export backends support this.
313 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
314 :group
'org-export-translation
317 (defcustom org-export-with-footnotes t
318 "If nil, export [1] as a footnote marker.
319 Lines starting with [1] will be formatted as footnotes.
321 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
322 :group
'org-export-translation
325 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
326 <h2 class=\"footnotes\">%s: </h2>
327 <div id=\"footnotes-text\">
331 "Format for the footnotes section.
332 Should contain a two instances of %s. The first will be replaced with the
333 language-specific word for \"Footnotes\", the second one will be replaced
334 by the footnotes themselves."
335 :group
'org-export-html
338 (defcustom org-export-with-sub-superscripts t
339 "Non-nil means, interpret \"_\" and \"^\" for export.
340 When this option is turned on, you can use TeX-like syntax for sub- and
341 superscripts. Several characters after \"_\" or \"^\" will be
342 considered as a single item - so grouping with {} is normally not
343 needed. For example, the following things will be parsed as single
344 sub- or superscripts.
346 10^24 or 10^tau several digits will be considered 1 item.
347 10^-12 or 10^-tau a leading sign with digits or a word
348 x^2-y^3 will be read as x^2 - y^3, because items are
349 terminated by almost any nonword/nondigit char.
350 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
352 Still, ambiguity is possible - so when in doubt use {} to enclose the
353 sub/superscript. If you set this variable to the symbol `{}',
354 the braces are *required* in order to trigger interpretations as
355 sub/superscript. This can be helpful in documents that need \"_\"
356 frequently in plain text.
358 Not all export backends support this, but HTML does.
360 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
361 :group
'org-export-translation
363 (const :tag
"Always interpret" t
)
364 (const :tag
"Only with braces" {})
365 (const :tag
"Never interpret" nil
)))
367 (defcustom org-export-with-special-strings t
368 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
369 When this option is turned on, these strings will be exported as:
375 Not all export backends support this, but HTML does.
377 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
378 :group
'org-export-translation
381 (defcustom org-export-with-TeX-macros t
382 "Non-nil means, interpret simple TeX-like macros when exporting.
383 For example, HTML export converts \\alpha to α and \\AA to Å.
384 No only real TeX macros will work here, but the standard HTML entities
385 for math can be used as macro names as well. For a list of supported
386 names in HTML export, see the constant `org-html-entities'.
387 Not all export backends support this.
389 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
390 :group
'org-export-translation
391 :group
'org-export-latex
394 (defcustom org-export-with-LaTeX-fragments nil
395 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
396 When set, the exporter will find LaTeX environments if the \\begin line is
397 the first non-white thing on a line. It will also find the math delimiters
398 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
401 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
402 :group
'org-export-translation
403 :group
'org-export-latex
406 (defcustom org-export-with-fixed-width t
407 "Non-nil means, lines starting with \":\" will be in fixed width font.
408 This can be used to have pre-formatted text, fragments of code etc. For
410 : ;; Some Lisp examples
413 will be looking just like this in also HTML. See also the QUOTE keyword.
414 Not all export backends support this.
416 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
417 :group
'org-export-translation
420 (defcustom org-match-sexp-depth
3
421 "Number of stacked braces for sub/superscript matching.
422 This has to be set before loading org.el to be effective."
423 :group
'org-export-translation
426 (defgroup org-export-tables nil
427 "Options for exporting tables in Org-mode."
428 :tag
"Org Export Tables"
431 (defcustom org-export-with-tables t
432 "If non-nil, lines starting with \"|\" define a table.
435 | Name | Address | Birthday |
436 |-------------+----------+-----------|
437 | Arthur Dent | England | 29.2.2100 |
439 Not all export backends support this.
441 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
442 :group
'org-export-tables
445 (defcustom org-export-highlight-first-table-line t
446 "Non-nil means, highlight the first table line.
447 In HTML export, this means use <th> instead of <td>.
448 In tables created with table.el, this applies to the first table line.
449 In Org-mode tables, all lines before the first horizontal separator
450 line will be formatted with <th> tags."
451 :group
'org-export-tables
454 (defcustom org-export-table-remove-special-lines t
455 "Remove special lines and marking characters in calculating tables.
456 This removes the special marking character column from tables that are set
457 up for spreadsheet calculations. It also removes the entire lines
458 marked with `!', `_', or `^'. The lines with `$' are kept, because
459 the values of constants may be useful to have."
460 :group
'org-export-tables
463 (defcustom org-export-prefer-native-exporter-for-tables nil
464 "Non-nil means, always export tables created with table.el natively.
465 Natively means, use the HTML code generator in table.el.
466 When nil, Org-mode's own HTML generator is used when possible (i.e. if
467 the table does not use row- or column-spanning). This has the
468 advantage, that the automatic HTML conversions for math symbols and
469 sub/superscripts can be applied. Org-mode's HTML generator is also
471 :group
'org-export-tables
474 (defgroup org-export-ascii nil
475 "Options specific for ASCII export of Org-mode files."
476 :tag
"Org Export ASCII"
479 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
480 "Characters for underlining headings in ASCII export.
481 In the given sequence, these characters will be used for level 1, 2, ..."
482 :group
'org-export-ascii
483 :type
'(repeat character
))
485 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
486 "Bullet characters for headlines converted to lists in ASCII export.
487 The first character is used for the first lest level generated in this
488 way, and so on. If there are more levels than characters given here,
489 the list will be repeated.
490 Note that plain lists will keep the same bullets as the have in the
492 :group
'org-export-ascii
493 :type
'(repeat character
))
495 (defgroup org-export-xml nil
496 "Options specific for XML export of Org-mode files."
497 :tag
"Org Export XML"
500 (defgroup org-export-html nil
501 "Options specific for HTML export of Org-mode files."
502 :tag
"Org Export HTML"
505 (defcustom org-export-html-coding-system nil
506 "Coding system for HTML export, defaults to buffer-file-coding-system."
507 :group
'org-export-html
508 :type
'coding-system
)
510 (defcustom org-export-html-extension
"html"
511 "The extension for exported HTML files."
512 :group
'org-export-html
515 (defcustom org-export-html-link-up
""
516 "Where should the \"UP\" link of exported HTML pages lead?"
517 :group
'org-export-html
518 :type
'(string :tag
"File or URL"))
520 (defcustom org-export-html-link-home
""
521 "Where should the \"HOME\" link of exported HTML pages lead?"
522 :group
'org-export-html
523 :type
'(string :tag
"File or URL"))
525 (defconst org-export-html-scripts
526 "<script language=\"javascript\" type=\"text/javascript\">
527 <!--/*--><![CDATA[/*><!--*/
528 function CodeHighlightOn(elem, id)
530 var target = document.getElementById(id);
532 elem.cacheClassElem = elem.className;
533 elem.cacheClassTarget = target.className;
534 target.className = \"code-highlighted\";
535 elem.className = \"code-highlighted\";
538 function CodeHighlightOff(elem, id)
540 var target = document.getElementById(id);
541 if(elem.cacheClassElem)
542 elem.className = elem.cacheClassElem;
543 if(elem.cacheClassTarget)
544 target.className = elem.cacheClassTarget;
548 "Basic javascript that is needed by HTML files produced by Org-mode.")
550 (defconst org-export-html-style-default
551 "<style type=\"text/css\">
552 <!--/*--><![CDATA[/*><!--*/
553 html { font-family: Times, serif; font-size: 12pt; }
554 .title { text-align: center; }
555 .todo { color: red; }
556 .done { color: green; }
557 .tag { background-color:lightblue; font-weight:normal }
559 .timestamp { color: grey }
560 .timestamp-kwd { color: CadetBlue }
561 p.verse { margin-left: 3% }
563 border: 1pt solid #AEBDCC;
564 background-color: #F3F5F7;
566 font-family: courier, monospace;
570 table { border-collapse: collapse; }
571 td, th { vertical-align: top; }
572 dt { font-weight: bold; }
573 div.figure { padding: 0.5em; }
574 div.figure p { text-align: center; }
575 .linenr { font-size:smaller }
576 .code-highlighted {background-color:#ffff00;}
577 .org-info-js_info-navigation { border-style:none; }
578 #org-info-js_console-label { font-size:10px; font-weight:bold;
579 white-space:nowrap; }
580 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
584 "The default style specification for exported HTML files.
585 Please use the variables `org-export-html-style' and
586 `org-export-html-style-extra' to add to this style. If you wish to not
587 have the default style included, customize the variable
588 `org-export-html-style-include-default'.")
590 (defcustom org-export-html-style-include-default t
591 "Non-nil means, include the default style in exported HTML files.
592 The actual style is defined in `org-export-html-style-default' and should
593 not be modified. Use the variables `org-export-html-style' to add
594 your own style information."
595 :group
'org-export-html
598 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
600 (defcustom org-export-html-style
""
601 "Org-wide style definitions for exported HTML files.
603 This variable needs to contain the full HTML structure to provide a style,
604 including the surrounding HTML tags. If you set the value of this variable,
605 you should consider to include definitions for the following classes:
606 title, todo, done, timestamp, timestamp-kwd, tag, target.
608 For example, a valid value would be:
610 <style type=\"text/css\">
612 p { font-weight: normal; color: gray; }
614 .title { text-align: center; }
615 .todo, .timestamp-kwd { color: red; }
616 .done { color: green; }
620 If you'd like to refer to en external style file, use something like
622 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
624 As the value of this option simply gets inserted into the HTML <head> header,
625 you can \"misuse\" it to add arbitrary text to the header.
626 See also the variable `org-export-html-style-extra'."
627 :group
'org-export-html
630 (put 'org-export-html-style
'safe-local-variable
'stringp
)
632 (defcustom org-export-html-style-extra
""
633 "Additional style information for HTML export.
634 The value of this variable is inserted into the HTML buffer right after
635 the value of `org-export-html-style'. Use this variable for per-file
636 settings of style information, and do not forget to surround the style
637 settings with <style>...</style> tags."
638 :group
'org-export-html
641 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
644 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
645 "Format for typesetting the document title in HTML export."
646 :group
'org-export-html
649 (defcustom org-export-html-toplevel-hlevel
2
650 "The <H> level for level 1 headings in HTML export."
651 :group
'org-export-html
654 (defcustom org-export-html-link-org-files-as-html t
655 "Non-nil means, make file links to `file.org' point to `file.html'.
656 When org-mode is exporting an org-mode file to HTML, links to
657 non-html files are directly put into a href tag in HTML.
658 However, links to other Org-mode files (recognized by the
659 extension `.org.) should become links to the corresponding html
660 file, assuming that the linked org-mode file will also be
662 When nil, the links still point to the plain `.org' file."
663 :group
'org-export-html
666 (defcustom org-export-html-inline-images
'maybe
667 "Non-nil means, inline images into exported HTML pages.
668 This is done using an <img> tag. When nil, an anchor with href is used to
669 link to the image. If this option is `maybe', then images in links with
670 an empty description will be inlined, while images with a description will
672 :group
'org-export-html
673 :type
'(choice (const :tag
"Never" nil
)
674 (const :tag
"Always" t
)
675 (const :tag
"When there is no description" maybe
)))
678 (defcustom org-export-html-expand t
679 "Non-nil means, for HTML export, treat @<...> as HTML tag.
680 When nil, these tags will be exported as plain text and therefore
681 not be interpreted by a browser.
683 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
684 :group
'org-export-html
687 (defcustom org-export-html-table-tag
688 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
689 "The HTML tag that is used to start a table.
690 This must be a <table> tag, but you may change the options like
691 borders and spacing."
692 :group
'org-export-html
695 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
696 "The opening tag for table header fields.
697 This is customizable so that alignment options can be specified."
698 :group
'org-export-tables
699 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
701 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
702 "The opening tag for table data fields.
703 This is customizable so that alignment options can be specified."
704 :group
'org-export-tables
705 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
707 (defcustom org-export-html-with-timestamp nil
708 "If non-nil, write `org-export-html-html-helper-timestamp'
709 into the exported HTML text. Otherwise, the buffer will just be saved
711 :group
'org-export-html
714 (defcustom org-export-html-html-helper-timestamp
715 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
716 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
717 :group
'org-export-html
720 (defgroup org-export-htmlize nil
721 "Options for processing examples with htmlize.el."
722 :tag
"Org Export Htmlize"
723 :group
'org-export-html
)
725 (defcustom org-export-htmlize-output-type
'inline-css
726 "Output type to be used by htmlize when formatting code snippets.
727 Normally this is `inline-css', but if you have defined to appropriate
728 classes in your css style file, setting this to `css' means that the
729 fontification will use the class names.
730 See also the function `org-export-htmlize-generate-css'."
731 :group
'org-export-htmlize
732 :type
'(choice (const css
) (const inline-css
)))
734 (defcustom org-export-htmlize-css-font-prefix
"org-"
735 "The prefix for CSS class names for htmlize font specifications."
736 :group
'org-export-htmlize
739 (defgroup org-export-icalendar nil
740 "Options specific for iCalendar export of Org-mode files."
741 :tag
"Org Export iCalendar"
744 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
745 "The file name for the iCalendar file covering all agenda files.
746 This file is created with the command \\[org-export-icalendar-all-agenda-files].
747 The file name should be absolute, the file will be overwritten without warning."
748 :group
'org-export-icalendar
751 (defcustom org-icalendar-combined-name
"OrgMode"
752 "Calendar name for the combined iCalendar representing all agenda files."
753 :group
'org-export-icalendar
756 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
757 "Contexts where iCalendar export should use a deadline time stamp.
758 This is a list with several symbols in it. Valid symbol are:
760 event-if-todo Deadlines in TODO entries become calendar events.
761 event-if-not-todo Deadlines in non-TODO entries become calendar events.
762 todo-due Use deadlines in TODO entries as due-dates"
763 :group
'org-export-icalendar
764 :type
'(set :greedy t
765 (const :tag
"Deadlines in non-TODO entries become events"
767 (const :tag
"Deadline in TODO entries become events"
769 (const :tag
"Deadlines in TODO entries become due-dates"
772 (defcustom org-icalendar-use-scheduled
'(todo-start)
773 "Contexts where iCalendar export should use a scheduling time stamp.
774 This is a list with several symbols in it. Valid symbol are:
776 event-if-todo Scheduling time stamps in TODO entries become an event.
777 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
778 todo-start Scheduling time stamps in TODO entries become start date.
779 Some calendar applications show TODO entries only after
781 :group
'org-export-icalendar
782 :type
'(set :greedy t
784 "SCHEDULED timestamps in non-TODO entries become events"
786 (const :tag
"SCHEDULED timestamps in TODO entries become events"
788 (const :tag
"SCHEDULED in TODO entries become start date"
791 (defcustom org-icalendar-categories
'(local-tags category
)
792 "Items that should be entered into the categories field.
793 This is a list of symbols, the following are valid:
795 category The Org-mode category of the current file or tree
796 todo-state The todo state, if any
797 local-tags The tags, defined in the current line
798 all-tags All tags, including inherited ones."
799 :group
'org-export-icalendar
802 (const :tag
"The file or tree category" category
)
803 (const :tag
"The TODO state" todo-state
)
804 (const :tag
"Tags defined in current line" local-tags
)
805 (const :tag
"All tags, including inherited ones" all-tags
))))
807 (defcustom org-icalendar-include-todo nil
808 "Non-nil means, export to iCalendar files should also cover TODO items."
809 :group
'org-export-icalendar
811 (const :tag
"None" nil
)
812 (const :tag
"Unfinished" t
)
813 (const :tag
"All" all
)))
815 (defcustom org-icalendar-include-sexps t
816 "Non-nil means, export to iCalendar files should also cover sexp entries.
817 These are entries like in the diary, but directly in an Org-mode file."
818 :group
'org-export-icalendar
821 (defcustom org-icalendar-include-body
100
822 "Amount of text below headline to be included in iCalendar export.
823 This is a number of characters that should maximally be included.
824 Properties, scheduling and clocking lines will always be removed.
825 The text will be inserted into the DESCRIPTION field."
826 :group
'org-export-icalendar
828 (const :tag
"Nothing" nil
)
829 (const :tag
"Everything" t
)
830 (integer :tag
"Max characters")))
832 (defcustom org-icalendar-store-UID nil
833 "Non-nil means, store any created UIDs in properties.
834 The iCalendar standard requires that all entries have a unique identifier.
835 Org will create these identifiers as needed. When this variable is non-nil,
836 the created UIDs will be stored in the ID property of the entry. Then the
837 next time this entry is exported, it will be exported with the same UID,
838 superceding the previous form of it. This is essential for
839 synchronization services.
840 This variable is not turned on by default because we want to avoid creating
841 a property drawer in every entry if people are only playing with this feature,
842 or if they are only using it locally."
843 :group
'org-export-icalendar
848 ;;; Variables, constants, and parameter plists
850 (defconst org-level-max
20)
852 (defvar org-export-html-preamble nil
853 "Preamble, to be inserted just before <body>. Set by publishing functions.")
854 (defvar org-export-html-postamble nil
855 "Preamble, to be inserted just after </body>. Set by publishing functions.")
856 (defvar org-export-html-auto-preamble t
857 "Should default preamble be inserted? Set by publishing functions.")
858 (defvar org-export-html-auto-postamble t
859 "Should default postamble be inserted? Set by publishing functions.")
860 (defvar org-current-export-file nil
) ; dynamically scoped parameter
861 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
863 (defconst org-export-plist-vars
864 '((:link-up nil org-export-html-link-up
)
865 (:link-home nil org-export-html-link-home
)
866 (:language nil org-export-default-language
)
867 (:customtime nil org-display-custom-times
)
868 (:headline-levels
"H" org-export-headline-levels
)
869 (:section-numbers
"num" org-export-with-section-numbers
)
870 (:section-number-format nil org-export-section-number-format
)
871 (:table-of-contents
"toc" org-export-with-toc
)
872 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
873 (:archived-trees nil org-export-with-archived-trees
)
874 (:emphasize
"*" org-export-with-emphasize
)
875 (:sub-superscript
"^" org-export-with-sub-superscripts
)
876 (:special-strings
"-" org-export-with-special-strings
)
877 (:footnotes
"f" org-export-with-footnotes
)
878 (:drawers
"d" org-export-with-drawers
)
879 (:tags
"tags" org-export-with-tags
)
880 (:todo-keywords
"todo" org-export-with-todo-keywords
)
881 (:priority
"pri" org-export-with-priority
)
882 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
883 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
884 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
885 (:fixed-width
":" org-export-with-fixed-width
)
886 (:timestamps
"<" org-export-with-timestamps
)
887 (:author-info
"author" org-export-author-info
)
888 (:creator-info
"creator" org-export-creator-info
)
889 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
890 (:tables
"|" org-export-with-tables
)
891 (:table-auto-headline nil org-export-highlight-first-table-line
)
892 (:style-include-default nil org-export-html-style-include-default
)
893 (:style nil org-export-html-style
)
894 (:style-extra nil org-export-html-style-extra
)
895 (:agenda-style nil org-agenda-export-html-style
)
896 (:convert-org-links nil org-export-html-link-org-files-as-html
)
897 (:inline-images nil org-export-html-inline-images
)
898 (:html-extension nil org-export-html-extension
)
899 (:html-table-tag nil org-export-html-table-tag
)
900 (:expand-quoted-html
"@" org-export-html-expand
)
901 (:timestamp nil org-export-html-with-timestamp
)
902 (:publishing-directory nil org-export-publishing-directory
)
903 (:preamble nil org-export-html-preamble
)
904 (:postamble nil org-export-html-postamble
)
905 (:auto-preamble nil org-export-html-auto-preamble
)
906 (:auto-postamble nil org-export-html-auto-postamble
)
907 (:author nil user-full-name
)
908 (:email nil user-mail-address
)
909 (:select-tags nil org-export-select-tags
)
910 (:exclude-tags nil org-export-exclude-tags
))
911 "List of properties that represent export/publishing variables.
912 Each element is a list of 3 items:
913 1. The property that is used internally, and also for org-publish-project-alist
914 2. The string that can be used in the OPTION lines to set this option,
915 or nil if this option cannot be changed in this way
916 3. The customization variable that sets the default for this option."
920 (defun org-default-export-plist ()
921 "Return the property list with default settings for the export variables."
922 (let ((l org-export-plist-vars
) rtn e
)
923 (while (setq e
(pop l
))
924 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
927 (defvar org-export-inbuffer-options-extra nil
928 "List of additional in-buffer options that should be detected.
929 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
930 etc. Extensions can add to this list to get their options detected, and they
931 can then add a function to `org-export-options-filters' to process these
933 Each element in this list must be a list, with the in-buffer keyword as car,
934 and a property (a symbol) as the next element. All occurrences of the
935 keyword will be found, the values concatenated with a space character
936 in between, and the result stored in the export options property list.")
938 (defvar org-export-options-filters nil
939 "Functions to be called to finalize the export/publishing options.
940 All these options are stored in a property list, and each of the functions
941 in this hook gets a chance to modify this property list. Each function
942 must accept the property list as an argument, and must return the (possibly
945 ;; FIXME: should we fold case here?
946 (defun org-infile-export-plist ()
947 "Return the property list with file-local settings for export."
951 (goto-char (point-min))
952 (let ((re (org-make-options-regexp
954 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
955 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
956 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
957 (mapcar 'car org-export-inbuffer-options-extra
))))
958 p key val text options js-up js-main js-css js-opt a pr style
960 ext-setup-or-nil setup-contents
(start 0))
961 (while (or (and ext-setup-or-nil
962 (string-match re ext-setup-or-nil start
)
963 (setq start
(match-end 0)))
964 (and (setq ext-setup-or-nil nil start
0)
965 (re-search-forward re nil t
)))
966 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
967 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
969 ((setq a
(assoc key org-export-inbuffer-options-extra
))
971 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
972 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
973 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
974 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
975 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
976 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
977 ((string-equal key
"STYLE")
978 (setq style
(concat style
"\n" val
)))
979 ((string-equal key
"LATEX_HEADER")
980 (setq latex-header
(concat latex-header
"\n" val
)))
981 ((string-equal key
"TEXT")
982 (setq text
(if text
(concat text
"\n" val
) val
)))
983 ((string-equal key
"OPTIONS")
984 (setq options
(concat val
" " options
)))
985 ((string-equal key
"LINK_UP")
986 (setq p
(plist-put p
:link-up val
)))
987 ((string-equal key
"LINK_HOME")
988 (setq p
(plist-put p
:link-home val
)))
989 ((string-equal key
"EXPORT_SELECT_TAGS")
990 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
991 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
992 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
993 ((equal key
"SETUPFILE")
994 (setq setup-contents
(org-file-contents
996 (org-remove-double-quotes
999 (if (not ext-setup-or-nil
)
1000 (setq ext-setup-or-nil setup-contents start
0)
1001 (setq ext-setup-or-nil
1002 (concat (substring ext-setup-or-nil
0 start
)
1003 "\n" setup-contents
"\n"
1004 (substring ext-setup-or-nil start
)))))))
1005 (setq p
(plist-put p
:text text
))
1006 (when style
(setq p
(plist-put p
:style-extra style
)))
1008 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1010 (setq p
(org-export-add-options-to-plist p options
)))
1013 (defun org-export-add-options-to-plist (p options
)
1014 "Parse an OPTIONS line and set values in the property list P."
1017 (let ((op org-export-plist-vars
) a
)
1018 (while (setq o
(pop op
))
1020 (string-match (concat (regexp-quote (nth 1 o
))
1021 ":\\([^ \t\n\r;,.]*\\)")
1023 (setq p
(plist-put p
(car o
)
1024 (car (read-from-string
1025 (match-string 1 options
))))))))))
1028 (defun org-export-add-subtree-options (p pos
)
1029 "Add options in subtree at position POS to property list P."
1032 (when (org-at-heading-p)
1034 ;; This is actually read in `org-export-get-title-from-subtree'
1035 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1036 ;; (setq p (plist-put p :title a)))
1037 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1038 (setq p
(plist-put p
:text a
)))
1039 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1040 (setq p
(org-export-add-options-to-plist p a
)))))
1043 (defun org-export-directory (type plist
)
1044 (let* ((val (plist-get plist
:publishing-directory
))
1045 (dir (if (listp val
)
1046 (or (cdr (assoc type val
)) ".")
1050 (defun org-export-process-option-filters (plist)
1051 (let ((functions org-export-options-filters
) f
)
1052 (while (setq f
(pop functions
))
1053 (setq plist
(funcall f plist
))))
1057 (defun org-export (&optional arg
)
1058 "Export dispatcher for Org-mode.
1059 When `org-export-run-in-background' is non-nil, try to run the command
1060 in the background. This will be done only for commands that write
1061 to a file. For details see the docstring of `org-export-run-in-background'.
1063 The prefix argument ARG will be passed to the exporter. However, if
1064 ARG is a double universal prefix `C-u C-u', that means to inverse the
1065 value of `org-export-run-in-background'."
1067 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1068 (help "[t] insert the export option template
1069 \[v] limit export to visible part of outline tree
1071 \[a] export as ASCII
1074 \[H] export as HTML to temporary buffer
1075 \[R] export region as HTML
1076 \[b] export as HTML and browse immediately
1079 \[l] export as LaTeX
1080 \[p] export as LaTeX and process to PDF
1081 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1082 \[L] export as LaTeX to temporary buffer
1084 \[i] export current file as iCalendar file
1085 \[I] export all agenda files as iCalendar files
1086 \[c] export agenda files into combined iCalendar file
1088 \[F] publish current file
1089 \[P] publish current project
1090 \[X] publish... (project will be prompted for)
1091 \[A] publish all projects")
1093 '((?t org-insert-export-options-template nil
)
1094 (?v org-export-visible nil
)
1095 (?a org-export-as-ascii t
)
1096 (?h org-export-as-html t
)
1097 (?b org-export-as-html-and-open t
)
1098 (?H org-export-as-html-to-buffer nil
)
1099 (?R org-export-region-as-html nil
)
1100 (?x org-export-as-xoxo t
)
1101 (?l org-export-as-latex t
)
1102 (?p org-export-as-pdf t
)
1103 (?d org-export-as-pdf-and-open t
)
1104 (?L org-export-as-latex-to-buffer nil
)
1105 (?i org-export-icalendar-this-file t
)
1106 (?I org-export-icalendar-all-agenda-files t
)
1107 (?c org-export-icalendar-combine-agenda-files t
)
1108 (?F org-publish-current-file t
)
1109 (?P org-publish-current-project t
)
1111 (?A org-publish-all t
)))
1113 (save-window-excursion
1114 (delete-other-windows)
1115 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1117 (org-fit-window-to-buffer (get-buffer-window
1118 "*Org Export/Publishing Help*"))
1119 (message "Select command: ")
1120 (setq r1
(read-char-exclusive)))
1121 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1122 (unless (setq ass
(assq r2 cmds
))
1123 (error "No command associated with key %c" r1
))
1124 (if (and bg
(nth 2 ass
)
1125 (not (buffer-base-buffer))
1126 (not (org-region-active-p)))
1127 ;; execute in background
1128 (let ((p (start-process
1129 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1131 (expand-file-name invocation-name invocation-directory
)
1134 "--eval" "(require 'org-exp)"
1135 "--eval" "(setq org-wait .2)"
1137 "-f" (symbol-name (nth 1 ass
)))))
1138 (set-process-sentinel p
'org-export-process-sentinel
)
1139 (message "Background process \"%s\": started" p
))
1140 ;; background processing not requested, or not possible
1141 (call-interactively (nth 1 ass
)))))
1143 (defun org-export-process-sentinel (process status
)
1144 (if (string-match "\n+\\'" status
)
1145 (setq status
(substring status
0 -
1)))
1146 (message "Background process \"%s\": %s" process status
))
1148 (defconst org-html-entities
1189 ("Aring") ("AA".
"Å")
1278 ("varepsilon".
"ε")
1291 ("sigmaf") ("varsigma".
"ς")
1299 ("thetasym") ("vartheta".
"ϑ")
1302 ("bull") ("bullet".
"•")
1303 ("hellip") ("dots".
"…")
1313 ("larr") ("leftarrow".
"←") ("gets".
"←")
1314 ("uarr") ("uparrow".
"↑")
1315 ("rarr") ("to".
"→") ("rightarrow".
"→")
1316 ("darr")("downarrow".
"↓")
1317 ("harr") ("leftrightarrow".
"↔")
1318 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1319 ("lArr") ("Leftarrow".
"⇐")
1320 ("uArr") ("Uparrow".
"⇑")
1321 ("rArr") ("Rightarrow".
"⇒")
1322 ("dArr") ("Downarrow".
"⇓")
1323 ("hArr") ("Leftrightarrow".
"⇔")
1325 ("part") ("partial".
"∂")
1326 ("exist") ("exists".
"∃")
1327 ("empty") ("emptyset".
"∅")
1329 ("isin") ("in".
"∈")
1335 ("lowast") ("ast".
"∗")
1337 ("prop") ("proptp".
"∝")
1338 ("infin") ("infty".
"∞")
1339 ("ang") ("angle".
"∠")
1340 ("and") ("wedge".
"∧")
1341 ("or") ("vee".
"∨")
1347 ("cong") ("simeq".
"≅")
1348 ("asymp")("approx".
"≈")
1349 ("ne") ("neq".
"≠")
1353 ("sub") ("subset".
"⊂")
1354 ("sup") ("supset".
"⊃")
1361 ("sdot") ("cdot".
"⋅")
1368 ("loz") ("Diamond".
"◊")
1369 ("spades") ("spadesuit".
"♠")
1370 ("clubs") ("clubsuit".
"♣")
1371 ("hearts") ("diamondsuit".
"♥")
1372 ("diams") ("diamondsuit".
"♦")
1373 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1440 "Entities for TeX->HTML translation.
1441 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1442 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1443 In that case, \"\\ent\" will be translated to \"&other;\".
1444 The list contains HTML entities for Latin-1, Greek and other symbols.
1445 It is supplemented by a number of commonly used TeX macros with appropriate
1446 translations. There is currently no way for users to extend this.")
1448 ;;; General functions for all backends
1450 (defvar org-export-target-aliases nil
1451 "Alist of targets with invisible aliases.")
1452 (defvar org-export-code-refs nil
1453 "Alist of code references and line numbers")
1455 (defun org-export-preprocess-string (string &rest parameters
)
1456 "Cleanup STRING so that that the true exported has a more consistent source.
1457 This function takes STRING, which should be a buffer-string of an org-file
1458 to export. It then creates a temporary buffer where it does its job.
1459 The result is then again returned as a string, and the exporter works
1460 on this string to produce the exported version."
1462 (let* ((htmlp (plist-get parameters
:for-html
))
1463 (asciip (plist-get parameters
:for-ascii
))
1464 (latexp (plist-get parameters
:for-LaTeX
))
1465 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1467 (archived-trees (plist-get parameters
:archived-trees
))
1468 (inhibit-read-only t
)
1469 (drawers org-drawers
)
1470 (outline-regexp "\\*+ ")
1473 (setq org-export-target-aliases nil
)
1474 (setq org-export-code-refs nil
)
1476 (with-current-buffer (get-buffer-create " org-mode-tmp")
1479 (setq case-fold-search t
)
1481 (run-hooks 'org-export-preprocess-hook
)
1483 ;; Remove license-to-kill stuff
1484 ;; The caller marks some stuff for killing, stuff that has been
1485 ;; used to create the page title, for example.
1486 (org-export-kill-licensed-text)
1488 (let ((org-inhibit-startup t
)) (org-mode))
1489 (setq case-fold-search t
)
1490 (untabify (point-min) (point-max))
1492 ;; Handle include files
1493 (org-export-handle-include-files)
1495 ;; Get rid of excluded trees
1496 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1497 (plist-get parameters
:exclude-tags
))
1499 ;; Handle source code snippets
1500 (org-export-replace-src-segments-and-examples backend
)
1502 ;; Normalize footnotes
1503 (when (plist-get parameters
:footnotes
)
1504 (org-footnote-normalize nil t
))
1506 ;; Find all headings and compute the targets for them
1507 (setq target-alist
(org-export-define-heading-targets target-alist
))
1509 ;; Get rid of drawers
1510 (org-export-remove-or-extract-drawers drawers
1511 (plist-get parameters
:drawers
))
1513 ;; Get the correct stuff before the first headline
1514 (when (plist-get parameters
:skip-before-1st-heading
)
1515 (goto-char (point-min))
1516 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t
)
1517 (delete-region (point-min) (match-beginning 0))
1518 (goto-char (point-min))
1520 (when (plist-get parameters
:add-text
)
1521 (goto-char (point-min))
1522 (insert (plist-get parameters
:add-text
) "\n"))
1524 ;; Get rid of archived trees
1525 (org-export-remove-archived-trees archived-trees
)
1527 ;; Remove todo-keywords before exporting, if the user has requested so
1528 (org-export-remove-headline-metadata parameters
)
1530 ;; Find targets in comments and move them out of comments,
1531 ;; but mark them as targets that should be invisible
1532 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1534 ;; Protect backend specific stuff, throw away the others.
1535 (org-export-select-backend-specific-text backend
)
1537 ;; Protect quoted subtrees
1538 (org-export-protect-quoted-subtrees)
1540 ;; Protect verbatim elements
1541 (org-export-protect-verbatim)
1543 ;; Blockquotes and verse
1544 (org-export-mark-blockquote-and-verse)
1546 ;; Attach captions to the correct object
1547 (setq target-alist
(org-export-attach-captions-and-attributes
1548 backend target-alist
))
1550 ;; Remove comment environment and comment subtrees
1551 (org-export-remove-comment-blocks-and-subtrees)
1553 ;; Find matches for radio targets and turn them into internal links
1554 (org-export-mark-radio-links)
1556 ;; Find all links that contain a newline and put them into a single line
1557 (org-export-concatenate-multiline-links)
1559 ;; Normalize links: Convert angle and plain links into bracket links
1560 ;; and expand link abbreviations
1561 (org-export-normalize-links)
1563 ;; Find all internal links. If they have a fuzzy match (i.e. not
1564 ;; a *dedicated* target match, let the link point to the
1565 ;; corresponding section.
1566 (org-export-target-internal-links target-alist
)
1568 ;; Find multiline emphasis and put them into single line
1569 (when (plist-get parameters
:emph-multiline
)
1570 (org-export-concatenate-multiline-emphasis))
1572 ;; Remove special table lines
1573 (when org-export-table-remove-special-lines
1574 (org-export-remove-special-table-lines))
1576 ;; Specific LaTeX stuff
1578 (require 'org-export-latex nil
)
1579 (org-export-latex-preprocess))
1581 ;; Specific ASCII stuff
1583 (org-export-ascii-preprocess))
1585 ;; Specific HTML stuff
1587 (org-export-html-preprocess parameters
))
1589 ;; Remove or replace comments
1590 (org-export-handle-comments (plist-get parameters
:comments
))
1592 (setq rtn
(buffer-string)))
1593 (kill-buffer " org-mode-tmp")
1596 (defun org-export-kill-licensed-text ()
1597 "Remove all text that is marked with a :org-license-to-kill property."
1599 (while (setq p
(text-property-any (point-min) (point-max)
1600 :org-license-to-kill t
))
1602 p
(or (next-single-property-change p
:org-license-to-kill
)
1605 (defun org-export-define-heading-targets (target-alist)
1606 "Find all headings and define the targets for them.
1607 The new targets are added to TARGET-ALIST, which is also returned."
1608 (goto-char (point-min))
1609 (org-init-section-numbers)
1610 (let ((re (concat "^" org-outline-regexp
1611 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1613 (while (re-search-forward re nil t
)
1615 (push (cons (org-match-string-no-properties 1)
1616 target
) target-alist
)
1617 (setq level
(org-reduced-level
1618 (save-excursion (goto-char (point-at-bol))
1619 (org-outline-level))))
1620 (setq target
(org-solidify-link-text
1621 (format "sec-%s" (org-section-number level
))))
1622 (push (cons target target
) target-alist
)
1623 (add-text-properties
1624 (point-at-bol) (point-at-eol)
1625 (list 'target target
)))))
1628 (defun org-export-handle-invisible-targets (target-alist)
1629 "Find targets in comments and move them out of comments.
1630 Mark them as invisible targets."
1632 (goto-char (point-min))
1633 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1634 ;; Check if the line before or after is a headline with a target
1635 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1636 (get-text-property (point-at-bol 2) 'target
)))
1638 ;; use the existing target in a neighboring line
1639 (setq tmp
(match-string 2))
1641 (and (looking-at "\n") (delete-char 1))
1642 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1644 (setq a
(or (assoc target org-export-target-aliases
)
1646 (push (list target
) org-export-target-aliases
)
1647 (car org-export-target-aliases
))))
1649 ;; Make an invisible target
1650 (replace-match "\\1(INVISIBLE)"))))
1653 (defun org-export-target-internal-links (target-alist)
1654 "Find all internal links and assign targets to them.
1655 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1656 let the link point to the corresponding section.
1657 This function also handles the id links, if they have a match in
1659 (goto-char (point-min))
1660 (while (re-search-forward org-bracket-link-regexp nil t
)
1662 (let* ((md (match-data))
1663 (desc (match-end 2))
1664 (link (org-link-unescape (match-string 1)))
1665 (slink (org-solidify-link-text link
))
1666 found props pos cref
1669 ((cdr (assoc slink target-alist
)))
1670 ((and (string-match "^id:" link
)
1671 (cdr (assoc (substring link
3) target-alist
))))
1672 ((string-match "^((\\(.*\\)))$" link
)
1673 (setq cref
(match-string 1 link
))
1674 (concat "coderef:" cref
))
1675 ((string-match org-link-types-re link
) nil
)
1676 ((or (file-name-absolute-p link
)
1677 (string-match "^\\." link
))
1681 (setq found
(condition-case nil
(org-link-search link
)
1684 (or (org-on-heading-p)
1685 (not (eq found
'dedicated
))))
1686 (or (get-text-property (point) 'target
)
1689 (1- (or (previous-single-property-change
1690 (point) 'target
) 0)))
1694 (goto-char (match-beginning 1))
1695 (setq props
(text-properties-at (point)))
1696 (delete-region (match-beginning 1) (match-end 1))
1699 (unless desc
(insert "][" link
))
1700 (add-text-properties pos
(point) props
))))))
1702 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1703 "Remove drawers, or extract the content.
1704 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1705 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1706 whose content to keep."
1707 (unless (eq t exp-drawers
)
1708 (goto-char (point-min))
1709 (let ((re (concat "^[ \t]*:\\("
1712 (org-delete-all exp-drawers
1713 (copy-sequence all-drawers
))
1715 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1716 (while (re-search-forward re nil t
)
1717 (replace-match "")))))
1719 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1720 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1721 Both arguments are lists of tags.
1722 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1724 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1726 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1727 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1730 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1734 (goto-char (point-min))
1735 (when (and select-tags
1737 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1738 ;; At least one tree is marked for export, this means
1739 ;; all the unmarked stuff needs to go.
1740 ;; Dig out the trees that should be exported
1741 (goto-char (point-min))
1742 (outline-next-heading)
1744 (put-text-property beg
(point-max) :org-delete t
)
1745 (while (re-search-forward re-sel nil t
)
1746 (when (org-on-heading-p)
1747 (org-back-to-heading)
1748 (remove-text-properties
1749 (max (1- (point)) (point-min))
1750 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1752 (while (and (org-up-heading-safe)
1753 (get-text-property (point) :org-delete
))
1754 (remove-text-properties (max (1- (point)) (point-min))
1755 (point-at-eol) '(:org-delete t
)))
1757 ;; Remove the trees explicitly marked for noexport
1759 (goto-char (point-min))
1760 (while (re-search-forward re-excl nil t
)
1761 (when (org-at-heading-p)
1762 (org-back-to-heading t
)
1764 (org-end-of-subtree t
)
1765 (delete-region beg
(point)))))
1766 ;; Remove everything that is now still marked for deletion
1767 (goto-char (point-min))
1768 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1769 (setq end
(or (next-single-property-change beg
:org-delete
)
1771 (delete-region beg end
))))
1773 (defun org-export-remove-archived-trees (export-archived-trees)
1774 "Remove archived trees.
1775 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1776 When it is t, the entire archived tree will be exported.
1777 When it is nil the entire tree including the headline will be removed
1779 (let ((re-archive (concat ":" org-archive-tag
":"))
1781 (when (not (eq export-archived-trees t
))
1782 (goto-char (point-min))
1783 (while (re-search-forward re-archive nil t
)
1784 (if (not (org-on-heading-p t
))
1785 (org-end-of-subtree t
)
1786 (beginning-of-line 1)
1787 (setq a
(if export-archived-trees
1788 (1+ (point-at-eol)) (point))
1789 b
(org-end-of-subtree t
))
1790 (if (> b a
) (delete-region a b
)))))))
1792 (defun org-export-remove-headline-metadata (opts)
1793 "Remove meta data from the headline, according to user options."
1794 (let ((re org-complex-heading-regexp
)
1795 (todo (plist-get opts
:todo-keywords
))
1796 (tags (plist-get opts
:tags
))
1797 (pri (plist-get opts
:priority
))
1800 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1801 (when (or (not todo
) (not tags
) (not pri
))
1802 (goto-char (point-min))
1803 (while (re-search-forward re nil t
)
1804 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1806 (replace-match rpl t t
)))))
1808 (defun org-export-protect-quoted-subtrees ()
1809 "Mark quoted subtrees with the protection property."
1810 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1811 (goto-char (point-min))
1812 (while (re-search-forward re-quote nil t
)
1813 (goto-char (match-beginning 0))
1815 (add-text-properties (point) (org-end-of-subtree t
)
1816 '(org-protected t
)))))
1818 (defun org-export-protect-verbatim ()
1819 "Mark verbatim snippets with the protection property."
1820 (goto-char (point-min))
1821 (while (re-search-forward org-verbatim-re nil t
)
1822 (add-text-properties (match-beginning 4) (match-end 4)
1824 (goto-char (1+ (match-end 4)))))
1826 (defun org-export-protect-examples (&optional indent
)
1827 "Protect code that should be exported as monospaced examples."
1828 (goto-char (point-min))
1829 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1830 (goto-char (match-end 0))
1831 (while (and (not (looking-at "#\\+END_EXAMPLE")) (not (eobp)))
1832 (insert (if indent
": " ":"))
1833 (beginning-of-line 2)))
1834 (goto-char (point-min))
1835 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1836 (add-text-properties (match-beginning 0) (match-end 0)
1837 '(org-protected t
))))
1839 (defun org-export-select-backend-specific-text (backend)
1841 '((html "HTML" "BEGIN_HTML" "END_HTML")
1842 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1843 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1844 (case-fold-search t
)
1848 (setq fmt
(pop formatters
))
1849 (when (eq (car fmt
) backend
)
1850 ;; This is selected code, put it into the file for real
1851 (goto-char (point-min))
1852 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1853 ":[ \t]*\\(.*\\)") nil t
)
1854 (replace-match "\\1" t
)
1855 (add-text-properties
1856 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1857 '(org-protected t
))))
1858 (goto-char (point-min))
1859 (while (re-search-forward
1861 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1862 (cadddr fmt
) "\\>.*\n?") nil t
)
1863 (if (eq (car fmt
) backend
)
1865 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1867 ;; No, this is for a different backend, kill it
1868 (delete-region (match-beginning 0) (match-end 0)))))))
1870 (defun org-export-mark-blockquote-and-verse ()
1871 "Mark block quote and verse environments with special cookies.
1872 These special cookies will later be interpreted by the backend."
1874 (goto-char (point-min))
1875 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1877 (replace-match (if (equal (downcase (match-string 1)) "end")
1878 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1881 (goto-char (point-min))
1882 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1883 (replace-match (if (equal (downcase (match-string 1)) "end")
1884 "ORG-VERSE-END" "ORG-VERSE-START")
1887 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1888 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1889 If the next thing following is a table, add the text properties to the first
1890 table line. If it is a link, add it to the line containing the link."
1891 (goto-char (point-min))
1892 (remove-text-properties (point-min) (point-max)
1893 '(org-caption nil org-attributes nil
))
1894 (let ((case-fold-search t
)
1895 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1897 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1899 "^#\\+label:[ \t]+\\(.*\\)"
1903 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1905 (while (re-search-forward re nil t
)
1908 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1910 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1912 (setq label
(org-trim (match-string 3))))
1914 (add-text-properties (point-at-bol) (point-at-eol)
1915 (list 'org-caption cap
1916 'org-attributes attr
1918 (if label
(push (cons label label
) target-alist
))
1919 (setq cap nil attr nil label nil
)))))
1922 (defun org-export-remove-comment-blocks-and-subtrees ()
1923 "Remove the comment environment, and also commented subtrees."
1924 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1925 (case-fold-search nil
))
1926 ;; Remove comment environment
1927 (goto-char (point-min))
1928 (while (re-search-forward
1929 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1930 (replace-match "" t t
))
1931 ;; Remove subtrees that are commented
1932 (goto-char (point-min))
1933 (while (re-search-forward re-commented nil t
)
1934 (goto-char (match-beginning 0))
1935 (delete-region (point) (org-end-of-subtree t
)))))
1937 (defun org-export-handle-comments (commentsp)
1938 "Remove comments, or convert to backend-specific format.
1939 COMMENTSP can be a format string for publishing comments.
1940 When it is nil, all comments will be removed."
1941 (let ((re "^#\\(.*\n?\\)")
1943 (goto-char (point-min))
1944 (while (or (looking-at re
)
1945 (re-search-forward re nil t
))
1946 (setq pos
(match-beginning 0))
1948 (progn (add-text-properties
1949 (match-beginning 0) (match-end 0) '(org-protected t
))
1950 (replace-match (format commentsp
(match-string 1)) t t
))
1951 (goto-char (1+ pos
))
1954 (goto-char (max (point-min) (1- pos
))))))))
1956 (defun org-export-mark-radio-links ()
1957 "Find all matches for radio targets and turn them into internal links."
1958 (let ((re-radio (and org-target-link-regexp
1959 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1960 (goto-char (point-min))
1962 (while (re-search-forward re-radio nil t
)
1964 (replace-match "\\1[[\\2]]"))))))
1966 (defun org-export-remove-special-table-lines ()
1967 "Remove tables lines that are used for internal purposes."
1968 (goto-char (point-min))
1969 (while (re-search-forward "^[ \t]*|" nil t
)
1970 (beginning-of-line 1)
1971 (if (or (looking-at "[ \t]*| *[!_^] *|")
1972 (and (looking-at ".*?| *<[0-9]+> *|")
1973 (not (looking-at ".*?| *[^ <|]"))))
1974 (delete-region (max (point-min) (1- (point-at-bol)))
1978 (defun org-export-normalize-links ()
1979 "Convert all links to bracket links, and expand link abbreviations."
1980 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1981 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
1982 (goto-char (point-min))
1983 (while (re-search-forward re-plain-link nil t
)
1984 (goto-char (1- (match-end 0)))
1986 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1987 ":" (match-string 3) "]]")))
1988 ;; added 'org-link face to links
1989 (put-text-property 0 (length s
) 'face
'org-link s
)
1990 (replace-match s t t
))))
1991 (goto-char (point-min))
1992 (while (re-search-forward re-angle-link nil t
)
1993 (goto-char (1- (match-end 0)))
1995 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1996 ":" (match-string 3) "]]")))
1997 (put-text-property 0 (length s
) 'face
'org-link s
)
1998 (replace-match s t t
))))
1999 (goto-char (point-min))
2000 (while (re-search-forward org-bracket-link-regexp nil t
)
2001 (goto-char (1- (match-end 0)))
2003 (let* ((xx (save-match-data
2005 (org-link-expand-abbrev (match-string 1)))))
2010 (concat "[" xx
"]"))
2012 (put-text-property 0 (length s
) 'face
'org-link s
)
2013 (replace-match s t t
))))))
2015 (defun org-export-concatenate-multiline-links ()
2016 "Find multi-line links and put it all into a single line.
2017 This is to make sure that the line-processing export backends
2018 can work correctly."
2019 (goto-char (point-min))
2020 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2022 (replace-match "\\1 \\3")
2023 (goto-char (match-beginning 0)))))
2025 (defun org-export-concatenate-multiline-emphasis ()
2026 "Find multi-line emphasis and put it all into a single line.
2027 This is to make sure that the line-processing export backends
2028 can work correctly."
2029 (goto-char (point-min))
2030 (while (re-search-forward org-emph-re nil t
)
2031 (if (not (= (char-after (match-beginning 3))
2032 (char-after (match-beginning 4))))
2034 (subst-char-in-region (match-beginning 0) (match-end 0)
2036 (goto-char (1- (match-end 0))))
2037 (goto-char (1+ (match-beginning 0))))))
2039 (defun org-export-grab-title-from-buffer ()
2040 "Get a title for the current document, from looking at the buffer."
2041 (let ((inhibit-read-only t
))
2043 (goto-char (point-min))
2044 (let ((end (if (looking-at org-outline-regexp
)
2046 (save-excursion (outline-next-heading) (point)))))
2047 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2048 ;; Mark the line so that it will not be exported as normal text.
2050 (add-text-properties (match-beginning 0) (match-end 0)
2051 (list :org-license-to-kill t
)))
2052 ;; Return the title string
2053 (org-trim (match-string 0)))))))
2055 (defun org-export-get-title-from-subtree ()
2056 "Return subtree title and exclude it from export."
2057 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2060 (when (and (org-at-heading-p)
2061 (>= (org-end-of-subtree t t
) rend
))
2062 ;; This is a subtree, we take the title from the first heading
2064 (looking-at org-todo-line-regexp
)
2065 (setq title
(match-string 3))
2067 (add-text-properties (point) (1+ (point-at-eol))
2068 (list :org-license-to-kill t
)))
2069 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2072 (defun org-solidify-link-text (s &optional alist
)
2073 "Take link text and make a safe target out of it."
2078 (org-split-string s
"[ \t\r\n]+") "=="))
2079 (a (assoc rtn alist
)))
2082 (defun org-get-min-level (lines)
2083 "Get the minimum level in LINES."
2084 (let ((re "^\\(\\*+\\) ") l min
)
2086 (while (setq l
(pop lines
))
2087 (if (string-match re l
)
2088 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
2091 ;; Variable holding the vector with section numbers
2092 (defvar org-section-numbers
(make-vector org-level-max
0))
2094 (defun org-init-section-numbers ()
2095 "Initialize the vector for the section numbers."
2097 (numbers (nreverse (org-split-string "" "\\.")))
2098 (depth (1- (length org-section-numbers
)))
2099 (i depth
) number-string
)
2102 (aset org-section-numbers i
0)
2103 (setq number-string
(or (car numbers
) "0"))
2104 (if (string-match "\\`[A-Z]\\'" number-string
)
2105 (aset org-section-numbers i
2106 (- (string-to-char number-string
) ?A -
1))
2107 (aset org-section-numbers i
(string-to-number number-string
)))
2111 (defun org-section-number (&optional level
)
2112 "Return a string with the current section number.
2113 When LEVEL is non-nil, increase section numbers on that level."
2114 (let* ((depth (1- (length org-section-numbers
)))
2116 (fmts (car org-export-section-number-format
))
2117 (term (cdr org-export-section-number-format
))
2122 (aset org-section-numbers
2123 level
(1+ (aref org-section-numbers level
))))
2124 (setq idx
(1+ level
))
2125 (while (<= idx depth
)
2127 (aset org-section-numbers idx
0))
2128 (setq idx
(1+ idx
))))
2130 (while (<= idx depth
)
2131 (when (> (aref org-section-numbers idx
) 0)
2132 (setq fmt
(or (pop fmts
) fmt
)
2134 n
(aref org-section-numbers idx
)
2136 (concat string sep
(org-number-to-counter n ctype
))
2137 (concat string
".0"))
2139 (setq idx
(1+ idx
)))
2141 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2142 (setq string
(replace-match "" t nil string
)))
2143 (if (string-match "\\(\\.0\\)+\\'" string
)
2144 (setq string
(replace-match "" t nil string
))))
2145 (concat string term
)))
2147 (defun org-number-to-counter (n type
)
2148 "Concert number N to a string counter, according to TYPE.
2149 TYPE must be a string, any of:
2153 I upper case roman numeral
2154 i lower case roman numeral"
2156 ((equal type
"1") (number-to-string n
))
2157 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2158 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2159 ((equal type
"I") (org-number-to-roman n
))
2160 ((equal type
"i") (downcase (org-number-to-roman n
)))
2161 (t (error "Invalid counter type `%s'" type
))))
2163 (defun org-number-to-roman (n)
2164 "Convert integer N into a roman numeral."
2165 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2166 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2167 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2171 (number-to-string n
)
2173 (if (>= n
(caar roman
))
2174 (setq n
(- n
(caar roman
))
2175 res
(concat res
(cdar roman
)))
2179 (org-number-to-roman 1961)
2184 (defun org-export-handle-include-files ()
2185 "Include the contents of include files, with proper formatting."
2186 (let ((case-fold-search t
)
2187 params file markup lang start end prefix prefix1
)
2188 (goto-char (point-min))
2189 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2190 (setq params
(read (concat "(" (match-string 1) ")"))
2191 prefix
(org-get-and-remove-property 'params
:prefix
)
2192 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2193 file
(org-symname-or-string (pop params
))
2194 markup
(org-symname-or-string (pop params
))
2195 lang
(org-symname-or-string (pop params
)))
2196 (delete-region (match-beginning 0) (match-end 0))
2198 (not (file-exists-p file
))
2199 (not (file-readable-p file
)))
2200 (insert (format "CANNOT INCLUDE FILE %s" file
))
2202 (if (equal (downcase markup
) "src")
2203 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2205 (setq start
(format "#+begin_%s\n" markup
)
2206 end
(format "#+end_%s" markup
))))
2207 (insert (or start
""))
2208 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2209 (or (bolp) (newline))
2210 (insert (or end
""))))))
2212 (defun org-get-file-contents (file &optional prefix prefix1
)
2213 "Get the contents of FILE and return them as a string.
2214 If PREFIX is a string, prepend it to each line. If PREFIX1
2215 is a string, prepend it to the first line instead of PREFIX."
2217 (insert-file-contents file
)
2218 (when (or prefix prefix1
)
2219 (goto-char (point-min))
2221 (insert (or prefix1 prefix
))
2223 (beginning-of-line 2)))
2226 (defun org-get-and-remove-property (listvar prop
)
2227 "Check if the value of LISTVAR contains PROP as a property.
2228 If yes, return the value of that property (i.e. the element following
2229 in the list) and remove property and value from the list in LISTVAR."
2230 (let ((list (symbol-value listvar
)) m v
)
2231 (when (setq m
(member prop list
))
2233 (if (equal (car list
) prop
)
2234 (set listvar
(cddr list
))
2235 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2237 (set listvar list
)))
2240 (defun org-symname-or-string (s)
2242 (if s
(symbol-name s
) s
)
2245 ;;; Fontification and line numbers for code examples
2247 (defvar org-export-last-code-line-counter-value
0)
2249 ;; Currently only for the HTML backend, but who knows....
2250 (defun org-export-replace-src-segments-and-examples (backend)
2251 "Replace source code segments with special code for export."
2252 (setq org-export-last-code-line-counter-value
0)
2253 (let ((case-fold-search t
)
2254 lang code trans opts
)
2255 (goto-char (point-min))
2256 (while (re-search-forward
2257 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2261 (setq lang
(match-string 2)
2262 opts
(match-string 3)
2263 code
(match-string 4))
2265 opts
(match-string 6)
2266 code
(match-string 7)))
2268 (setq trans
(org-export-format-source-code-or-example
2269 backend lang code opts
))
2270 (replace-match trans t t
))))
2272 (defvar htmlp
) ;; dynamically scoped
2273 (defvar latexp
) ;; dynamically scoped
2275 (defun org-export-format-source-code-or-example (backend
2276 lang code
&optional opts
)
2277 "Format CODE from language LANG and return it formatted for export.
2278 If LANG is nil, do not add any fontification.
2279 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2280 and `+n' for continuing previous numering.
2281 Code formatting according to language currently only works for HTML.
2282 Numbering lines works for all three major backends (html, latex, and ascii)."
2284 (let (num cont rtn named rpllbl keepp
)
2285 (setq num
(string-match "[-+]n\\>" (or opts
""))
2286 cont
(string-match "\\+n\\>" (or opts
""))
2287 rpllbl
(string-match "-r\\>" (or opts
""))
2288 keepp
(string-match "-k\\>" (or opts
"")))
2289 (if keepp
(setq rpllbl
'keep
))
2291 (when (equal lang
"org")
2292 (setq rtn
(with-temp-buffer
2294 ;; Free up the protected lines
2295 (goto-char (point-min))
2296 (while (re-search-forward "^," nil t
)
2300 ;; Now backend-specific coding
2303 ;; We are exporting to HTML
2305 (require 'htmlize nil t
)
2306 (when (not (fboundp 'htmlize-region-for-paste
))
2307 ;; we do not have htmlize.el, or an old version of it
2309 "htmlize.el 1.34 or later is needed for source code formatting")))
2312 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2313 (org-inhibit-startup t
)
2314 (org-startup-folded nil
))
2318 (if (functionp mode
)
2321 (font-lock-fontify-buffer)
2322 (org-export-htmlize-region-for-paste
2323 (point-min) (point-max))))
2324 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2325 (setq rtn
(replace-match
2326 (format "<pre class=\"src src-%s\">\n" lang
)
2328 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n")))
2329 (setq rtn
(org-export-number-lines rtn
'html
1 1 num cont rpllbl
))
2330 (concat "\n#+BEGIN_HTML\n" rtn
"\n#+END_HTML\n\n"))
2331 ((eq backend
'latex
)
2332 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl
))
2333 (concat "\n#+BEGIN_LaTeX\n\\begin{verbatim}\n" rtn
2334 "\n\\end{verbatim}\n#+END_LaTeX\n\n"))
2335 ((eq backend
'ascii
)
2336 ;; This is not HTML or LaTeX, so just make it an example.
2337 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl
))
2338 (concat "#+BEGIN_ASCII\n"
2340 (lambda (l) (concat " " l
))
2341 (org-split-string rtn
"\n")
2343 "\n#+END_ASCII\n"))))))
2345 (defun org-export-number-lines (text backend
2346 &optional skip1 skip2 number cont
2348 (if (and (not number
) (not (eq replace-labels
'keep
)))
2349 (setq replace-labels nil
)) ;; must use names if no numbers
2350 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2351 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2354 (goto-char (point-max))
2355 (skip-chars-backward " \t\n\r")
2356 (delete-region (point) (point-max))
2357 (beginning-of-line (- 1 skip2
))
2358 (let* ((last (org-current-line))
2359 (n org-export-last-code-line-counter-value
)
2360 (nmax (+ n
(- last skip1
)))
2361 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2364 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2366 ((eq backend
'ascii
) fmt
)
2367 ((eq backend
'latex
) fmt
)
2371 (goto-line (1+ skip1
))
2372 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2374 (insert (format fm
(incf n
)))
2376 (when (and (not (eq replace-labels
'keep
))
2377 (looking-at ".*?\\([ \t]+\\(((\\(.*?\\)))\\)\\)"))
2378 (setq ref
(match-string 3))
2381 (delete-region (match-beginning 1) (match-end 1))
2382 (push (cons ref n
) org-export-code-refs
))
2383 (goto-char (match-beginning 2))
2384 (delete-region (match-beginning 2) (match-end 2))
2385 (insert "(" ref
")")
2386 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2387 (when (eq backend
'html
)
2389 (beginning-of-line 1)
2390 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2393 (insert "</span>")))))
2394 (setq org-export-last-code-line-counter-value n
)
2395 (goto-char (point-max))
2401 (defvar org-last-level nil
) ; dynamically scoped variable
2402 (defvar org-min-level nil
) ; dynamically scoped variable
2403 (defvar org-levels-open nil
) ; dynamically scoped parameter
2404 (defvar org-ascii-current-indentation nil
) ; For communication
2407 (defun org-export-as-ascii (arg)
2408 "Export the outline as a pretty ASCII file.
2409 If there is an active region, export only the region.
2410 The prefix ARG specifies how many levels of the outline should become
2411 underlined headlines. The default is 3."
2413 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2414 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2415 (org-infile-export-plist)))
2416 (region-p (org-region-active-p))
2417 (rbeg (and region-p
(region-beginning)))
2418 (rend (and region-p
(region-end)))
2423 (and (org-at-heading-p)
2424 (>= (org-end-of-subtree t t
) rend
)))))
2425 (opt-plist (if subtree-p
2426 (org-export-add-subtree-options opt-plist rbeg
)
2428 (custom-times org-display-custom-times
)
2429 (org-ascii-current-indentation '(0 .
0))
2433 (case-fold-search nil
)
2434 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2435 (filename (concat (file-name-as-directory
2436 (org-export-directory :ascii opt-plist
))
2437 (file-name-sans-extension
2439 (org-entry-get (region-beginning)
2440 "EXPORT_FILE_NAME" t
))
2441 (file-name-nondirectory bfname
)))
2443 (filename (if (equal (file-truename filename
)
2444 (file-truename bfname
))
2445 (concat filename
".txt")
2447 (buffer (find-file-noselect filename
))
2448 (org-levels-open (make-vector org-level-max nil
))
2449 (odd org-odd-levels-only
)
2450 (date (plist-get opt-plist
:date
))
2451 (author (plist-get opt-plist
:author
))
2452 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2453 (plist-get opt-plist
:title
)
2455 (plist-get opt-plist
:skip-before-1st-heading
))
2456 (org-export-grab-title-from-buffer))
2457 (file-name-sans-extension
2458 (file-name-nondirectory bfname
))))
2459 (email (plist-get opt-plist
:email
))
2460 (language (plist-get opt-plist
:language
))
2461 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2462 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2467 (if (org-region-active-p) (region-beginning) (point-min))
2468 (if (org-region-active-p) (region-end) (point-max))))
2469 (lines (org-split-string
2470 (org-export-preprocess-string
2473 :skip-before-1st-heading
2474 (plist-get opt-plist
:skip-before-1st-heading
)
2475 :drawers
(plist-get opt-plist
:drawers
)
2476 :tags
(plist-get opt-plist
:tags
)
2477 :priority
(plist-get opt-plist
:priority
)
2478 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2479 :verbatim-multiline t
2480 :select-tags
(plist-get opt-plist
:select-tags
)
2481 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2483 (plist-get opt-plist
:archived-trees
)
2484 :add-text
(plist-get opt-plist
:text
))
2486 thetoc have-headings first-heading-pos
2487 table-open table-buffer link desc
)
2489 (let ((inhibit-read-only t
))
2491 (remove-text-properties (point-min) (point-max)
2492 '(:org-license-to-kill t
))))
2494 (setq org-min-level
(org-get-min-level lines
))
2495 (setq org-last-level org-min-level
)
2496 (org-init-section-numbers)
2498 (find-file-noselect filename
)
2500 (setq lang-words
(or (assoc language org-export-language-setup
)
2501 (assoc "en" org-export-language-setup
)))
2502 (switch-to-buffer-other-window buffer
)
2505 ;; create local variables for all options, to make sure all called
2506 ;; functions get the correct information
2508 (set (make-local-variable (nth 2 x
))
2509 (plist-get opt-plist
(car x
))))
2510 org-export-plist-vars
)
2511 (org-set-local 'org-odd-levels-only odd
)
2512 (setq umax
(if arg
(prefix-numeric-value arg
)
2513 org-export-headline-levels
))
2514 (setq umax-toc
(if (integerp org-export-with-toc
)
2515 (min org-export-with-toc umax
)
2519 (if title
(org-insert-centered title ?
=))
2521 (if (and (or author email
)
2522 org-export-author-info
)
2523 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2524 (if email
(concat " <" email
">") "")
2528 ((and date
(string-match "%" date
))
2529 (setq date
(format-time-string date
)))
2531 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2533 (if (and date org-export-time-stamp-file
)
2534 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2538 (if org-export-with-toc
2540 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2541 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2543 (mapc '(lambda (line)
2544 (if (string-match org-todo-line-regexp
2546 ;; This is a headline
2548 (setq have-headings t
)
2549 (setq level
(- (match-end 1) (match-beginning 1))
2550 level
(org-tr-level level
)
2551 txt
(match-string 3 line
)
2553 (or (and org-export-mark-todo-in-toc
2555 (not (member (match-string 2 line
)
2556 org-done-keywords
)))
2558 (and org-export-mark-todo-in-toc
2560 (org-search-todo-below
2561 line lines level
))))
2562 (setq txt
(org-html-expand-for-ascii txt
))
2564 (while (string-match org-bracket-link-regexp txt
)
2567 (match-string (if (match-end 2) 3 1) txt
)
2570 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2572 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2574 (setq txt
(replace-match "" t t txt
)))
2575 (if (string-match quote-re0 txt
)
2576 (setq txt
(replace-match "" t t txt
)))
2578 (if org-export-with-section-numbers
2579 (setq txt
(concat (org-section-number level
)
2581 (if (<= level umax-toc
)
2586 (* (max 0 (- level org-min-level
)) 4) ?\
)
2587 (format (if todo
"%s (*)\n" "%s\n") txt
))
2589 (setq org-last-level level
))
2592 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2594 (org-init-section-numbers)
2595 (while (setq line
(pop lines
))
2596 ;; Remove the quoted HTML tags.
2597 (setq line
(org-html-expand-for-ascii line
))
2598 ;; Replace links with the description when possible
2599 (while (string-match org-bracket-link-regexp line
)
2600 (setq link
(match-string 1 line
)
2601 desc
(match-string (if (match-end 3) 3 1) line
))
2602 (if (and (> (length link
) 8)
2603 (equal (substring link
0 8) "coderef:"))
2604 (setq line
(replace-match
2605 (format (org-export-get-coderef-format (substring link
8) desc
)
2608 org-export-code-refs
)))
2610 (setq line
(replace-match
2611 (if (match-end 3) "[\\3]" "[\\1]")
2614 (setq line
(org-translate-time line
)))
2616 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2618 (setq first-heading-pos
(or first-heading-pos
(point)))
2619 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2620 txt
(match-string 2 line
))
2621 (org-ascii-level-start level txt umax lines
))
2623 ((and org-export-with-tables
2624 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2625 (if (not table-open
)
2627 (setq table-open t table-buffer nil
))
2629 (setq table-buffer
(cons line table-buffer
))
2630 (when (or (not lines
)
2631 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2633 (setq table-open nil
2634 table-buffer
(nreverse table-buffer
))
2637 (org-fix-indentation x org-ascii-current-indentation
))
2638 (org-format-table-ascii table-buffer
)
2641 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2642 ;; Remove forced line breaks
2643 (if (string-match "\\\\\\\\[ \t]*$" line
)
2644 (setq line
(replace-match "" t t line
)))
2645 (if (and org-export-with-fixed-width
2646 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2647 (setq line
(replace-match "\\1" nil nil line
)))
2648 (insert line
"\n"))))
2652 ;; insert the table of contents
2654 (goto-char (point-min))
2655 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2657 (goto-char (match-beginning 0))
2659 (goto-char first-heading-pos
))
2660 (mapc 'insert thetoc
)
2661 (or (looking-at "[ \t]*\n[ \t]*\n")
2664 ;; Convert whitespace place holders
2665 (goto-char (point-min))
2667 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2668 (setq end
(next-single-property-change beg
'org-whitespace
))
2670 (delete-region beg end
)
2671 (insert (make-string (- end beg
) ?\
))))
2674 ;; remove display and invisible chars
2676 (goto-char (point-min))
2677 (while (setq beg
(next-single-property-change (point) 'display
))
2678 (setq end
(next-single-property-change beg
'display
))
2679 (delete-region beg end
)
2682 (goto-char (point-min))
2683 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2684 (setq end
(next-single-property-change beg
'org-cwidth
))
2685 (delete-region beg end
)
2687 (goto-char (point-min))))
2689 (defun org-export-ascii-preprocess ()
2690 "Do extra work for ASCII export"
2691 ;; Put quotes around verbatim text
2692 (goto-char (point-min))
2693 (while (re-search-forward org-verbatim-re nil t
)
2694 (goto-char (match-end 2))
2695 (backward-delete-char 1) (insert "'")
2696 (goto-char (match-beginning 2))
2697 (delete-char 1) (insert "`")
2698 (goto-char (match-end 2)))
2699 (goto-char (point-min))
2700 ;; Remove target markers
2701 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2702 (replace-match "\\1\\2")))
2704 (defun org-search-todo-below (line lines level
)
2705 "Search the subtree below LINE for any TODO entries."
2706 (let ((rest (cdr (memq line lines
)))
2707 (re org-todo-line-regexp
)
2710 (while (setq line
(pop rest
))
2711 (if (string-match re line
)
2713 (setq lv
(- (match-end 1) (match-beginning 1))
2714 todo
(and (match-beginning 2)
2715 (not (member (match-string 2 line
)
2716 org-done-keywords
))))
2718 (if (<= lv level
) (throw 'exit nil
))
2719 (if todo
(throw 'exit t
))))))))
2721 (defun org-html-expand-for-ascii (line)
2722 "Handle quoted HTML for ASCII export."
2723 (if org-export-html-expand
2724 (while (string-match "@<[^<>\n]*>" line
)
2725 ;; We just remove the tags for now.
2726 (setq line
(replace-match "" nil nil line
))))
2729 (defun org-insert-centered (s &optional underline
)
2730 "Insert the string S centered and underline it with character UNDERLINE."
2731 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2732 (insert (make-string ind ?\
) s
"\n")
2734 (insert (make-string ind ?\
)
2735 (make-string (string-width s
) underline
)
2738 (defun org-ascii-level-start (level title umax
&optional lines
)
2739 "Insert a new level in ASCII export."
2740 (let (char (n (- level umax
1)) (ind 0))
2743 (insert (make-string (* 2 n
) ?\
)
2744 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2745 org-export-ascii-bullets
))
2747 ;; find the indentation of the next non-empty line
2750 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2751 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2752 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2754 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2755 (if (or (not (equal (char-before) ?
\n))
2756 (not (equal (char-before (1- (point))) ?
\n)))
2758 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2759 (unless org-export-with-tags
2760 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2761 (setq title
(replace-match "" t t title
))))
2762 (if org-export-with-section-numbers
2763 (setq title
(concat (org-section-number level
) " " title
)))
2764 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2765 (setq org-ascii-current-indentation
'(0 .
0)))))
2768 (defun org-export-visible (type arg
)
2769 "Create a copy of the visible part of the current buffer, and export it.
2770 The copy is created in a temporary buffer and removed after use.
2771 TYPE is the final key (as a string) that also select the export command in
2772 the `C-c C-e' export dispatcher.
2773 As a special case, if the you type SPC at the prompt, the temporary
2774 org-mode file will not be removed but presented to you so that you can
2775 continue to use it. The prefix arg ARG is passed through to the exporting
2779 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2780 (read-char-exclusive))
2781 current-prefix-arg
))
2782 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2783 (error "Invalid export key"))
2784 (let* ((binding (cdr (assoc type
2785 '((?a . org-export-as-ascii
)
2786 (?\C-a . org-export-as-ascii
)
2787 (?b . org-export-as-html-and-open
)
2788 (?\C-b . org-export-as-html-and-open
)
2789 (?h . org-export-as-html
)
2790 (?H . org-export-as-html-to-buffer
)
2791 (?R . org-export-region-as-html
)
2792 (?x . org-export-as-xoxo
)))))
2793 (keepp (equal type ?\
))
2794 (file buffer-file-name
)
2795 (buffer (get-buffer-create "*Org Export Visible*"))
2797 ;; Need to hack the drawers here.
2799 (goto-char (point-min))
2800 (while (re-search-forward org-drawer-regexp nil t
)
2801 (goto-char (match-beginning 1))
2802 (or (org-invisible-p) (org-flag-drawer nil
))))
2803 (with-current-buffer buffer
(erase-buffer))
2805 (setq s
(goto-char (point-min)))
2806 (while (not (= (point) (point-max)))
2807 (goto-char (org-find-invisible))
2808 (append-to-buffer buffer s
(point))
2809 (setq s
(goto-char (org-find-visible))))
2810 (org-cycle-hide-drawers 'all
)
2811 (goto-char (point-min))
2813 ;; Copy all comment lines to the end, to make sure #+ settings are
2814 ;; still available for the second export step. Kind of a hack, but
2815 ;; does do the trick.
2816 (if (looking-at "#[^\r\n]*")
2817 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2818 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2819 (append-to-buffer buffer
(1+ (match-beginning 0))
2820 (min (point-max) (1+ (match-end 0))))))
2822 (let ((buffer-file-name file
)
2823 (org-inhibit-startup t
))
2826 (unless keepp
(funcall binding arg
))))
2828 (kill-buffer buffer
)
2829 (switch-to-buffer-other-window buffer
)
2830 (goto-char (point-min)))))
2832 (defun org-find-visible ()
2834 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2835 (get-char-property s
'invisible
)))
2837 (defun org-find-invisible ()
2839 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2840 (not (get-char-property s
'invisible
))))
2845 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2846 (defun org-get-current-options ()
2847 "Return a string with current options as keyword options.
2848 Does include HTML export options as well as TODO and CATEGORY stuff."
2849 (require 'org-archive
)
2856 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2858 #+EXPORT_SELECT_TAGS: %s
2859 #+EXPORT_EXCLUDE_TAGS: %s
2865 #+PRIORITIES: %c %c %c
2867 #+STARTUP: %s %s %s %s %s
2873 (buffer-name) (user-full-name) user-mail-address
2874 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2875 org-export-default-language
2876 org-export-headline-levels
2877 org-export-with-section-numbers
2879 org-export-preserve-breaks
2880 org-export-html-expand
2881 org-export-with-fixed-width
2882 org-export-with-tables
2883 org-export-with-sub-superscripts
2884 org-export-with-special-strings
2885 org-export-with-footnotes
2886 org-export-with-emphasize
2887 org-export-with-TeX-macros
2888 org-export-with-LaTeX-fragments
2889 org-export-skip-text-before-1st-heading
2890 org-export-with-drawers
2891 org-export-with-todo-keywords
2892 org-export-with-priority
2893 org-export-with-tags
2894 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2895 (mapconcat 'identity org-export-select-tags
" ")
2896 (mapconcat 'identity org-export-exclude-tags
" ")
2897 org-export-html-link-up
2898 org-export-html-link-home
2899 (file-name-nondirectory buffer-file-name
)
2900 "TODO FEEDBACK VERIFY DONE"
2901 "Me Jason Marie DONE"
2902 org-highest-priority org-lowest-priority org-default-priority
2903 (mapconcat 'identity org-drawers
" ")
2904 (cdr (assoc org-startup-folded
2905 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2906 (if org-odd-levels-only
"odd" "oddeven")
2907 (if org-hide-leading-stars
"hidestars" "showstars")
2908 (if org-startup-align-all-tables
"align" "noalign")
2909 (cond ((eq org-log-done t
) "logdone")
2910 ((equal org-log-done
'note
) "lognotedone")
2911 ((not org-log-done
) "nologdone"))
2912 (or (mapconcat (lambda (x)
2914 ((equal '(:startgroup
) x
) "{")
2915 ((equal '(:endgroup
) x
) "}")
2916 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2918 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2919 (mapconcat 'identity org-file-tags
" ")
2920 org-archive-location
2921 "org file:~/org/%s.org"
2924 (defun org-export-html-preprocess (parameters)
2925 ;; Convert LaTeX fragments to images
2926 (when (plist-get parameters
:LaTeX-fragments
)
2928 (concat "ltxpng/" (file-name-sans-extension
2929 (file-name-nondirectory
2930 org-current-export-file
)))
2931 org-current-export-dir nil
"Creating LaTeX image %s"))
2932 (message "Exporting..."))
2935 (defun org-insert-export-options-template ()
2936 "Insert into the buffer a template with information for exporting."
2938 (if (not (bolp)) (newline))
2939 (let ((s (org-get-current-options)))
2940 (and (string-match "#\\+CATEGORY" s
)
2941 (setq s
(substring s
0 (match-beginning 0))))
2945 (defun org-export-as-html-and-open (arg)
2946 "Export the outline as HTML and immediately open it with a browser.
2947 If there is an active region, export only the region.
2948 The prefix ARG specifies how many levels of the outline should become
2949 headlines. The default is 3. Lower levels will become bulleted lists."
2951 (org-export-as-html arg
'hidden
)
2952 (org-open-file buffer-file-name
))
2955 (defun org-export-as-html-batch ()
2956 "Call `org-export-as-html', may be used in batch processing as
2958 --load=$HOME/lib/emacs/org.el
2959 --eval \"(setq org-export-headline-levels 2)\"
2960 --visit=MyFile --funcall org-export-as-html-batch"
2961 (org-export-as-html org-export-headline-levels
'hidden
))
2964 (defun org-export-as-html-to-buffer (arg)
2965 "Call `org-export-as-html` with output to a temporary buffer.
2966 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2968 (org-export-as-html arg nil nil
"*Org HTML Export*")
2969 (switch-to-buffer-other-window "*Org HTML Export*"))
2972 (defun org-replace-region-by-html (beg end
)
2973 "Assume the current region has org-mode syntax, and convert it to HTML.
2974 This can be used in any buffer. For example, you could write an
2975 itemized list in org-mode syntax in an HTML buffer and then use this
2976 command to convert it."
2978 (let (reg html buf pop-up-frames
)
2979 (save-window-excursion
2981 (setq html
(org-export-region-as-html
2983 (setq reg
(buffer-substring beg end
)
2984 buf
(get-buffer-create "*Org tmp*"))
2985 (with-current-buffer buf
2989 (setq html
(org-export-region-as-html
2990 (point-min) (point-max) t
'string
)))
2992 (delete-region beg end
)
2996 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2997 "Convert region from BEG to END in org-mode buffer to HTML.
2998 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2999 contents, and only produce the region of converted text, useful for
3000 cut-and-paste operations.
3001 If BUFFER is a buffer or a string, use/create that buffer as a target
3002 of the converted HTML. If BUFFER is the symbol `string', return the
3003 produced HTML as a string and leave not buffer behind. For example,
3004 a Lisp program could call this function in the following way:
3006 (setq html (org-export-region-as-html beg end t 'string))
3008 When called interactively, the output buffer is selected, and shown
3009 in a window. A non-interactive call will only return the buffer."
3010 (interactive "r\nP")
3011 (when (interactive-p)
3012 (setq buffer
"*Org HTML Export*"))
3013 (let ((transient-mark-mode t
) (zmacs-regions t
)
3015 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3017 (set-mark (point)) ;; to activate the region
3019 (setq rtn
(org-export-as-html
3022 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3023 (if (and (interactive-p) (bufferp rtn
))
3024 (switch-to-buffer-other-window rtn
)
3027 (defvar html-table-tag nil
) ; dynamically scoped into this.
3028 (defvar org-par-open nil
)
3030 (defun org-export-as-html (arg &optional hidden ext-plist
3031 to-buffer body-only pub-dir
)
3032 "Export the outline as a pretty HTML file.
3033 If there is an active region, export only the region. The prefix
3034 ARG specifies how many levels of the outline should become
3035 headlines. The default is 3. Lower levels will become bulleted
3036 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3037 EXT-PLIST is a property list with external parameters overriding
3038 org-mode's default settings, but still inferior to file-local
3039 settings. When TO-BUFFER is non-nil, create a buffer with that
3040 name and export to that buffer. If TO-BUFFER is the symbol
3041 `string', don't leave any buffer behind but just return the
3042 resulting HTML as a string. When BODY-ONLY is set, don't produce
3043 the file header and footer, simply return the content of
3044 <body>...</body>, without even the body tags themselves. When
3045 PUB-DIR is set, use this as the publishing directory."
3048 ;; Make sure we have a file name when we need it.
3049 (when (and (not (or to-buffer body-only
))
3050 (not buffer-file-name
))
3051 (if (buffer-base-buffer)
3052 (org-set-local 'buffer-file-name
3053 (with-current-buffer (buffer-base-buffer)
3055 (error "Need a file name to be able to export.")))
3057 (message "Exporting...")
3058 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3059 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3060 (setq-default org-done-keywords org-done-keywords
)
3061 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3063 (org-export-process-option-filters
3064 (org-combine-plists (org-default-export-plist)
3066 (org-infile-export-plist))))
3067 (style (concat (if (plist-get opt-plist
:style-include-default
)
3068 org-export-html-style-default
)
3069 (plist-get opt-plist
:style
)
3070 (plist-get opt-plist
:style-extra
)
3071 "\n" org-export-html-scripts
))
3072 (html-extension (plist-get opt-plist
:html-extension
))
3073 (link-validate (plist-get opt-plist
:link-validation-function
))
3074 valid thetoc have-headings first-heading-pos
3075 (odd org-odd-levels-only
)
3076 (region-p (org-region-active-p))
3077 (rbeg (and region-p
(region-beginning)))
3078 (rend (and region-p
(region-end)))
3080 (if (plist-get opt-plist
:ignore-subree-p
)
3085 (and (org-at-heading-p)
3086 (>= (org-end-of-subtree t t
) rend
))))))
3087 (opt-plist (if subtree-p
3088 (org-export-add-subtree-options opt-plist rbeg
)
3090 ;; The following two are dynamically scoped into other
3092 (org-current-export-dir
3093 (or pub-dir
(org-export-directory :html opt-plist
)))
3094 (org-current-export-file buffer-file-name
)
3095 (level 0) (line "") (origline "") txt todo
3098 (filename (if to-buffer nil
3101 (file-name-sans-extension
3103 (org-entry-get (region-beginning)
3104 "EXPORT_FILE_NAME" t
))
3105 (file-name-nondirectory buffer-file-name
)))
3107 (file-name-as-directory
3108 (or pub-dir
(org-export-directory :html opt-plist
))))))
3109 (current-dir (if buffer-file-name
3110 (file-name-directory buffer-file-name
)
3112 (buffer (if to-buffer
3114 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3115 (t (get-buffer-create to-buffer
)))
3116 (find-file-noselect filename
)))
3117 (org-levels-open (make-vector org-level-max nil
))
3118 (date (plist-get opt-plist
:date
))
3119 (author (plist-get opt-plist
:author
))
3120 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3121 (plist-get opt-plist
:title
)
3123 (plist-get opt-plist
:skip-before-1st-heading
))
3124 (org-export-grab-title-from-buffer))
3125 (and buffer-file-name
3126 (file-name-sans-extension
3127 (file-name-nondirectory buffer-file-name
)))
3129 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3130 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3131 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3136 (local-list-type nil
)
3137 (local-list-indent nil
)
3138 (llt org-plain-list-ordered-item-terminator
)
3139 (email (plist-get opt-plist
:email
))
3140 (language (plist-get opt-plist
:language
))
3144 (coding-system (and (boundp 'buffer-file-coding-system
)
3145 buffer-file-coding-system
))
3146 (coding-system-for-write (or org-export-html-coding-system
3148 (save-buffer-coding-system (or org-export-html-coding-system
3150 (charset (and coding-system-for-write
3151 (fboundp 'coding-system-get
)
3152 (coding-system-get coding-system-for-write
3156 (if region-p
(region-beginning) (point-min))
3157 (if region-p
(region-end) (point-max))))
3160 (org-export-preprocess-string
3164 :skip-before-1st-heading
3165 (plist-get opt-plist
:skip-before-1st-heading
)
3166 :drawers
(plist-get opt-plist
:drawers
)
3167 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3168 :tags
(plist-get opt-plist
:tags
)
3169 :priority
(plist-get opt-plist
:priority
)
3171 (plist-get opt-plist
:archived-trees
)
3172 :select-tags
(plist-get opt-plist
:select-tags
)
3173 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3175 (plist-get opt-plist
:text
)
3177 (plist-get opt-plist
:LaTeX-fragments
))
3180 table-buffer table-orig-buffer
3181 ind item-type starter didclose
3182 rpl path attr desc descp desc1 desc2 link
3183 snumber fnc item-tag
3187 (let ((inhibit-read-only t
))
3189 (remove-text-properties (point-min) (point-max)
3190 '(:org-license-to-kill t
))))
3192 (message "Exporting...")
3194 (setq org-min-level
(org-get-min-level lines
))
3195 (setq org-last-level org-min-level
)
3196 (org-init-section-numbers)
3199 ((and date
(string-match "%" date
))
3200 (setq date
(format-time-string date
)))
3202 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3204 ;; Get the language-dependent settings
3205 (setq lang-words
(or (assoc language org-export-language-setup
)
3206 (assoc "en" org-export-language-setup
)))
3208 ;; Switch to the output buffer
3210 (let ((inhibit-read-only t
)) (erase-buffer))
3213 (and (fboundp 'set-buffer-file-coding-system
)
3214 (set-buffer-file-coding-system coding-system-for-write
))
3216 (let ((case-fold-search nil
)
3217 (org-odd-levels-only odd
))
3218 ;; create local variables for all options, to make sure all called
3219 ;; functions get the correct information
3221 (set (make-local-variable (nth 2 x
))
3222 (plist-get opt-plist
(car x
))))
3223 org-export-plist-vars
)
3224 (setq umax
(if arg
(prefix-numeric-value arg
)
3225 org-export-headline-levels
))
3226 (setq umax-toc
(if (integerp org-export-with-toc
)
3227 (min org-export-with-toc umax
)
3232 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3233 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3234 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3235 lang=\"%s\" xml:lang=\"%s\">
3238 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3239 <meta name=\"generator\" content=\"Org-mode\"/>
3240 <meta name=\"generated\" content=\"%s\"/>
3241 <meta name=\"author\" content=\"%s\"/>
3245 language language
(org-html-expand title
)
3246 (or charset
"iso-8859-1") date author style
))
3248 (insert (or (plist-get opt-plist
:preamble
) ""))
3250 (when (plist-get opt-plist
:auto-preamble
)
3251 (if title
(insert (format org-export-html-title-format
3252 (org-html-expand title
))))))
3254 (if (and org-export-with-toc
(not body-only
))
3256 (push (format "<h%d>%s</h%d>\n"
3257 org-export-html-toplevel-hlevel
3259 org-export-html-toplevel-hlevel
)
3261 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3262 (push "<ul>\n<li>" thetoc
)
3264 (mapcar '(lambda (line)
3265 (if (string-match org-todo-line-regexp line
)
3266 ;; This is a headline
3268 (setq have-headings t
)
3269 (setq level
(- (match-end 1) (match-beginning 1))
3270 level
(org-tr-level level
)
3271 txt
(save-match-data
3273 (org-export-cleanup-toc-line
3274 (match-string 3 line
))))
3276 (or (and org-export-mark-todo-in-toc
3278 (not (member (match-string 2 line
)
3279 org-done-keywords
)))
3281 (and org-export-mark-todo-in-toc
3283 (org-search-todo-below
3284 line lines level
))))
3286 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3287 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3288 (if (string-match quote-re0 txt
)
3289 (setq txt
(replace-match "" t t txt
)))
3290 (setq snumber
(org-section-number level
))
3291 (if org-export-with-section-numbers
3292 (setq txt
(concat snumber
" " txt
)))
3293 (if (<= level
(max umax umax-toc
))
3294 (setq head-count
(+ head-count
1)))
3295 (if (<= level umax-toc
)
3297 (if (> level org-last-level
)
3299 (setq cnt
(- level org-last-level
))
3300 (while (>= (setq cnt
(1- cnt
)) 0)
3301 (push "\n<ul>\n<li>" thetoc
))
3302 (push "\n" thetoc
)))
3303 (if (< level org-last-level
)
3305 (setq cnt
(- org-last-level level
))
3306 (while (>= (setq cnt
(1- cnt
)) 0)
3307 (push "</li>\n</ul>" thetoc
))
3308 (push "\n" thetoc
)))
3309 ;; Check for targets
3310 (while (string-match org-any-target-regexp line
)
3311 (setq line
(replace-match
3312 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3314 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3315 (setq txt
(replace-match "" t t txt
)))
3319 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3320 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3321 snumber txt
) thetoc
)
3323 (setq org-last-level level
))
3327 (while (> org-last-level
(1- org-min-level
))
3328 (setq org-last-level
(1- org-last-level
))
3329 (push "</li>\n</ul>\n" thetoc
))
3330 (push "</div>\n" thetoc
)
3331 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3334 (org-init-section-numbers)
3338 (while (setq line
(pop lines
) origline line
)
3341 ;; end of quote section?
3342 (when (and inquote
(string-match "^\\*+ " line
))
3345 ;; inside a quote section?
3347 (insert (org-html-protect line
) "\n")
3348 (throw 'nextline nil
))
3350 ;; Fixed-width, verbatim lines (examples)
3351 (when (and org-export-with-fixed-width
3352 (string-match "^[ \t]*:\\(.*\\)" line
))
3355 (org-close-par-maybe)
3356 (insert "<pre class=\"example\">\n"))
3357 (insert (org-html-protect (match-string 1 line
)) "\n")
3358 (when (or (not lines
)
3359 (not (string-match "^[ \t]*\\(:.*\\)"
3362 (insert "</pre>\n"))
3363 (throw 'nextline nil
))
3366 (when (get-text-property 0 'org-protected line
)
3368 (when (re-search-backward
3369 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3370 (setq par
(match-string 1))
3371 (replace-match "\\2\n"))
3374 (not (string-match "^[ \t]*:" (car lines
)))
3375 (or (= (length (car lines
)) 0)
3376 (get-text-property 0 'org-protected
(car lines
))))
3377 (insert (pop lines
) "\n"))
3378 (and par
(insert "<p>\n")))
3379 (throw 'nextline nil
))
3382 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3384 (insert "\n</p>\n<hr/>\n<p>\n")
3385 (insert "\n<hr/>\n"))
3386 (throw 'nextline nil
))
3388 ;; Blockquotes and verse
3389 (when (equal "ORG-BLOCKQUOTE-START" line
)
3390 (org-close-par-maybe)
3391 (insert "<blockquote>\n<p>\n")
3392 (throw 'nextline nil
))
3393 (when (equal "ORG-BLOCKQUOTE-END" line
)
3394 (insert "</p>\n</blockquote>\n")
3395 (throw 'nextline nil
))
3396 (when (equal "ORG-VERSE-START" line
)
3397 (org-close-par-maybe)
3398 (insert "\n<p class=\"verse\">\n")
3400 (throw 'nextline nil
))
3401 (when (equal "ORG-VERSE-END" line
)
3404 (throw 'nextline nil
))
3406 (let ((i (org-get-string-indentation line
)))
3408 (setq line
(concat (mapconcat 'identity
3409 (make-list (* 2 i
) "\\nbsp") "")
3410 " " (org-trim line
))))
3411 (setq line
(concat line
"\\\\"))))
3413 ;; make targets to anchors
3414 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3417 (setq line
(replace-match
3419 "@<a name=\"%s\" id=\"%s\">@</a>"
3420 (org-solidify-link-text (match-string 1 line
))
3421 (org-solidify-link-text (match-string 1 line
)))
3423 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3424 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3425 (setq line
(replace-match
3426 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3427 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3430 (setq line
(replace-match
3431 (concat "@<a name=\""
3432 (org-solidify-link-text (match-string 1 line
))
3433 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3436 (setq line
(org-html-handle-time-stamps line
))
3438 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3439 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3440 ;; Also handle sub_superscripts and checkboxes
3441 (or (string-match org-table-hline-regexp line
)
3442 (setq line
(org-html-expand line
)))
3446 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3447 (setq start
(match-beginning 0))
3448 (setq path
(save-match-data (org-link-unescape
3449 (match-string 3 line
))))
3451 ((match-end 2) (match-string 2 line
))
3453 (or (file-name-absolute-p path
)
3454 (string-match "^\\.\\.?/" path
)))
3457 (setq path
(org-extract-attributes (org-link-unescape path
)))
3458 (setq attr
(get-text-property 0 'org-attributes path
))
3459 (setq desc1
(if (match-end 5) (match-string 5 line
))
3460 desc2
(if (match-end 2) (concat type
":" path
) path
)
3461 descp
(and desc1
(not (equal desc1 desc2
)))
3462 desc
(or desc1 desc2
))
3463 ;; Make an image out of the description if that is so wanted
3464 (when (and descp
(org-file-image-p desc
))
3466 (if (string-match "^file:" desc
)
3467 (setq desc
(substring desc
(match-end 0)))))
3468 (setq desc
(org-add-props
3469 (concat "<img src=\"" desc
"\"/>")
3470 '(org-protected t
))))
3471 ;; FIXME: do we need to unescape here somewhere?
3473 ((equal type
"internal")
3477 (org-solidify-link-text
3478 (save-match-data (org-link-unescape path
)) nil
)
3480 (org-export-html-format-desc desc
)
3482 ((member type
'("http" "https"))
3483 ;; standard URL, just check if we need to inline an image
3484 (if (and (or (eq t org-export-html-inline-images
)
3485 (and org-export-html-inline-images
(not descp
)))
3486 (org-file-image-p path
))
3487 (setq rpl
(org-export-html-format-image
3488 (concat type
":" path
)))
3489 (setq link
(concat type
":" path
))
3490 (setq rpl
(concat "<a href=\""
3491 (org-export-html-format-href link
)
3493 (org-export-html-format-desc desc
)
3495 ((member type
'("ftp" "mailto" "news"))
3497 (setq link
(concat type
":" path
))
3498 (setq rpl
(concat "<a href=\""
3499 (org-export-html-format-href link
)
3501 (org-export-html-format-desc desc
)
3504 ((string= type
"coderef")
3506 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3508 (format (org-export-get-coderef-format path
(and descp desc
))
3509 (cdr (assoc path org-export-code-refs
))))))
3511 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3512 ;; The link protocol has a function for format the link
3515 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3517 ((string= type
"file")
3519 (let* ((filename path
)
3520 (abs-p (file-name-absolute-p filename
))
3521 thefile file-is-image-p search
)
3523 (if (string-match "::\\(.*\\)" filename
)
3524 (setq search
(match-string 1 filename
)
3525 filename
(replace-match "" t nil filename
)))
3527 (if (functionp link-validate
)
3528 (funcall link-validate filename current-dir
)
3530 (setq file-is-image-p
(org-file-image-p filename
))
3531 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3532 (when (and org-export-html-link-org-files-as-html
3533 (string-match "\\.org$" thefile
))
3534 (setq thefile
(concat (substring thefile
0
3535 (match-beginning 0))
3536 "." html-extension
))
3538 ;; make sure this is can be used as target search
3539 (not (string-match "^[0-9]*$" search
))
3540 (not (string-match "^\\*" search
))
3541 (not (string-match "^/.*/$" search
)))
3542 (setq thefile
(concat thefile
"#"
3543 (org-solidify-link-text
3544 (org-link-unescape search
)))))
3545 (when (string-match "^file:" desc
)
3546 (setq desc
(replace-match "" t t desc
))
3547 (if (string-match "\\.org$" desc
)
3548 (setq desc
(replace-match "" t t desc
))))))
3549 (setq rpl
(if (and file-is-image-p
3550 (or (eq t org-export-html-inline-images
)
3551 (and org-export-html-inline-images
3553 (org-export-html-format-image thefile
)
3554 (concat "<a href=\"" thefile
"\"" attr
">"
3555 (org-export-html-format-desc desc
)
3557 (if (not valid
) (setq rpl desc
))))
3560 ;; just publish the path, as default
3561 (setq rpl
(concat "<i><" type
":"
3562 (save-match-data (org-link-unescape path
))
3564 (setq line
(replace-match rpl t t line
)
3565 start
(+ start
(length rpl
))))
3568 (if (and (string-match org-todo-line-regexp line
)
3569 (match-beginning 2))
3572 (concat (substring line
0 (match-beginning 2))
3574 (if (member (match-string 2 line
)
3577 "\">" (match-string 2 line
)
3578 "</span>" (substring line
(match-end 2)))))
3580 ;; Does this contain a reference to a footnote?
3581 (when org-export-with-footnotes
3583 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3584 (if (get-text-property (match-beginning 2) 'org-protected line
)
3585 (setq start
(match-end 2))
3586 (let ((n (match-string 2 line
)))
3590 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
3591 (match-string 1 line
) n n n
)
3595 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3596 ;; This is a headline
3597 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3598 txt
(match-string 2 line
))
3599 (if (string-match quote-re0 txt
)
3600 (setq txt
(replace-match "" t t txt
)))
3601 (if (<= level
(max umax umax-toc
))
3602 (setq head-count
(+ head-count
1)))
3604 ;; Close any local lists before inserting a new header line
3605 (while local-list-type
3606 (org-close-li (car local-list-type
))
3607 (insert (format "</%sl>\n" (car local-list-type
)))
3608 (pop local-list-type
))
3609 (setq local-list-indent nil
3611 (setq first-heading-pos
(or first-heading-pos
(point)))
3612 (org-html-level-start level txt umax
3613 (and org-export-with-toc
(<= level umax
))
3616 (when (string-match quote-re line
)
3617 (org-close-par-maybe)
3621 ((and org-export-with-tables
3622 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3623 (if (not table-open
)
3625 (setq table-open t table-buffer nil table-orig-buffer nil
))
3627 (setq table-buffer
(cons line table-buffer
)
3628 table-orig-buffer
(cons origline table-orig-buffer
))
3629 (when (or (not lines
)
3630 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3632 (setq table-open nil
3633 table-buffer
(nreverse table-buffer
)
3634 table-orig-buffer
(nreverse table-orig-buffer
))
3635 (org-close-par-maybe)
3636 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3641 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3642 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3643 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3644 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3646 (setq ind
(org-get-string-indentation line
)
3647 item-type
(if (match-beginning 4) "o" "u")
3648 starter
(if (match-beginning 2)
3649 (substring (match-string 2 line
) 0 -
1))
3650 line
(substring line
(match-beginning 5))
3652 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3654 item-tag
(match-string 1 line
)
3655 line
(substring line
(match-end 0))))
3656 (when (and (not (equal item-type
"d"))
3657 (not (string-match "[^ \t]" line
)))
3658 ;; empty line. Pretend indentation is large.
3659 (setq ind
(if org-empty-line-terminates-plain-lists
3661 (1+ (or (car local-list-indent
) 1)))))
3663 (while (and in-local-list
3664 (or (and (= ind
(car local-list-indent
))
3666 (< ind
(car local-list-indent
))))
3668 (org-close-li (car local-list-type
))
3669 (insert (format "</%sl>\n" (car local-list-type
)))
3670 (pop local-list-type
) (pop local-list-indent
)
3671 (setq in-local-list local-list-indent
))
3674 (or (not in-local-list
)
3675 (> ind
(car local-list-indent
))))
3676 ;; Start new (level of) list
3677 (org-close-par-maybe)
3679 ((equal item-type
"u") "<ul>\n<li>\n")
3680 ((equal item-type
"o") "<ol>\n<li>\n")
3681 ((equal item-type
"d")
3682 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3683 (push item-type local-list-type
)
3684 (push ind local-list-indent
)
3685 (setq in-local-list t
))
3687 ;; continue current list
3688 (org-close-li (car local-list-type
))
3690 ((equal (car local-list-type
) "d")
3691 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3694 ;; we did close a list, normal text follows: need <p>
3696 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3699 (if (equal (match-string 1 line
) "X")
3701 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3704 ;; Empty lines start a new paragraph. If hand-formatted lists
3705 ;; are not fully interpreted, lines starting with "-", "+", "*"
3706 ;; also start a new paragraph.
3707 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3709 ;; Is this the start of a footnote?
3710 (when org-export-with-footnotes
3711 (when (and (boundp 'footnote-section-tag-regexp
)
3712 (string-match (concat "^" footnote-section-tag-regexp
)
3715 (throw 'nextline nil
))
3716 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3717 (org-close-par-maybe)
3718 (let ((n (match-string 1 line
)))
3719 (setq org-par-open t
3721 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3723 ;; Check if the line break needs to be conserved
3725 ((string-match "\\\\\\\\[ \t]*$" line
)
3726 (setq line
(replace-match "<br/>" t t line
)))
3727 (org-export-preserve-breaks
3728 (setq line
(concat line
"<br/>"))))
3730 (insert line
"\n")))))
3732 ;; Properly close all local lists and other lists
3737 ;; Close any local lists before inserting a new header line
3738 (while local-list-type
3739 (org-close-li (car local-list-type
))
3740 (insert (format "</%sl>\n" (car local-list-type
)))
3741 (pop local-list-type
))
3742 (setq local-list-indent nil
3744 (org-html-level-start 1 nil umax
3745 (and org-export-with-toc
(<= level umax
))
3747 ;; the </div> to close the last text-... div.
3748 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3751 (goto-char (point-min))
3752 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3753 (push (match-string 0) footnotes
)
3754 (replace-match "" t t
)))
3756 (insert (format org-export-html-footnotes-section
3757 (or (nth 4 lang-words
) "Footnotes")
3758 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3761 (when (plist-get opt-plist
:auto-postamble
)
3762 (insert "<div id=\"postamble\">")
3763 (when (and org-export-author-info author
)
3764 (insert "<p class=\"author\"> "
3765 (nth 1 lang-words
) ": " author
"\n")
3767 (if (listp (split-string email
",+ *"))
3769 (insert "<a href=\"mailto:" e
"\"><"
3771 (split-string email
",+ *"))
3772 (insert "<a href=\"mailto:" email
"\"><"
3773 email
"></a>\n")))
3775 (when (and date org-export-time-stamp-file
)
3776 (insert "<p class=\"date\"> "
3777 (nth 2 lang-words
) ": "
3779 (when org-export-creator-info
3780 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3781 org-version emacs-major-version
)))
3784 (if org-export-html-with-timestamp
3785 (insert org-export-html-html-helper-timestamp
))
3786 (insert (or (plist-get opt-plist
:postamble
) ""))
3787 (insert "</body>\n</html>\n"))
3789 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3791 (if (eq major-mode default-major-mode
) (html-mode)))
3793 ;; insert the table of contents
3794 (goto-char (point-min))
3796 (if (or (re-search-forward
3797 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3799 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3801 (goto-char (match-beginning 0))
3803 (goto-char first-heading-pos
)
3804 (when (looking-at "\\s-*</p>")
3805 (goto-char (match-end 0))
3807 (insert "<div id=\"table-of-contents\">\n")
3808 (mapc 'insert thetoc
)
3809 (insert "</div>\n"))
3810 ;; remove empty paragraphs and lists
3811 (goto-char (point-min))
3812 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3814 (goto-char (point-min))
3815 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3817 (goto-char (point-min))
3818 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3820 ;; Convert whitespace place holders
3821 (goto-char (point-min))
3823 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3824 (setq n
(get-text-property beg
'org-whitespace
)
3825 end
(next-single-property-change beg
'org-whitespace
))
3827 (delete-region beg end
)
3828 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3829 (make-string n ?x
)))))
3830 (or to-buffer
(save-buffer))
3831 (goto-char (point-min))
3832 (message "Exporting... done")
3833 (if (eq to-buffer
'string
)
3834 (prog1 (buffer-substring (point-min) (point-max))
3835 (kill-buffer (current-buffer)))
3836 (current-buffer)))))
3838 (defun org-export-get-coderef-format (path desc
)
3840 (if (and desc
(string-match
3841 (regexp-quote (concat "((" path
"))"))
3843 (replace-match "%s" t t desc
)
3847 (defun org-export-html-format-href (s)
3848 "Make sure the S is valid as a href reference in an XHTML document."
3851 (while (string-match "&" s start
)
3852 (setq start
(+ (match-beginning 0) 3)
3853 s
(replace-match "&" t t s
)))))
3856 (defun org-export-html-format-desc (s)
3857 "Make sure the S is valid as a description in a link."
3858 (if (and s
(not (get-text-property 1 'org-protected s
)))
3860 (org-html-do-expand s
))
3863 (defun org-export-html-format-image (src)
3864 "Create image tag with source and attributes."
3866 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
3867 (attr (org-find-text-property-in-string 'org-attributes src
))
3868 (label (org-find-text-property-in-string 'org-label src
)))
3869 (format "<div %sclass=\"figure\">
3870 <p><img src=\"%s\"%s /></p>%s
3872 (if label
(format "id=\"%s\" " label
) "")
3874 (if (string-match "\\<alt=" (or attr
""))
3876 (concat " " attr
" alt=\"" src
"\""))
3877 (if caption
(concat "\n<p>" caption
"</p>") "")))))
3879 (defvar org-table-colgroup-info nil
)
3880 (defun org-format-table-ascii (lines)
3881 "Format a table for ascii export."
3883 (setq lines
(org-split-string lines
"\n")))
3884 (if (not (string-match "^[ \t]*|" (car lines
)))
3885 ;; Table made by table.el - test for spanning
3888 ;; A normal org table
3889 ;; Get rid of hlines at beginning and end
3890 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3891 (setq lines
(nreverse lines
))
3892 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3893 (setq lines
(nreverse lines
))
3894 (when org-export-table-remove-special-lines
3895 ;; Check if the table has a marking column. If yes remove the
3896 ;; column and the special lines
3897 (setq lines
(org-table-clean-before-export lines
)))
3898 ;; Get rid of the vertical lines except for grouping
3899 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3901 (while (setq line
(pop lines
))
3902 (if (string-match org-table-hline-regexp line
)
3903 (and (string-match "|\\(.*\\)|" line
)
3904 (setq line
(replace-match " \\1" t nil line
)))
3905 (setq start
0 vl1 vl
)
3906 (while (string-match "|" line start
)
3907 (setq start
(match-end 0))
3908 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3912 (defun org-colgroup-info-to-vline-list (info)
3915 (setq last new new
(pop info
))
3916 (if (or (memq last
'(:end
:startend
))
3917 (memq new
'(:start
:startend
)))
3920 (setq vl
(nreverse vl
))
3921 (and vl
(setcar vl nil
))
3924 (defvar org-table-number-regexp
) ; defined in org-table.el
3925 (defun org-format-table-html (lines olines
)
3926 "Find out which HTML converter to use and return the HTML code."
3928 (setq lines
(org-split-string lines
"\n")))
3929 (if (string-match "^[ \t]*|" (car lines
))
3930 ;; A normal org table
3931 (org-format-org-table-html lines
)
3932 ;; Table made by table.el - test for spanning
3933 (let* ((hlines (delq nil
(mapcar
3935 (if (string-match "^[ \t]*\\+-" x
) x
3938 (first (car hlines
))
3939 (ll (and (string-match "\\S-+" first
)
3940 (match-string 0 first
)))
3941 (re (concat "^[ \t]*" (regexp-quote ll
)))
3942 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3944 (if (and (not spanning
)
3945 (not org-export-prefer-native-exporter-for-tables
))
3946 ;; We can use my own converter with HTML conversions
3947 (org-format-table-table-html lines
)
3948 ;; Need to use the code generator in table.el, with the original text.
3949 (org-format-table-table-html-using-table-generate-source olines
)))))
3951 (defvar org-table-number-fraction
) ; defined in org-table.el
3952 (defun org-format-org-table-html (lines &optional splice
)
3953 "Format a table into HTML."
3954 (require 'org-table
)
3955 ;; Get rid of hlines at beginning and end
3956 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3957 (setq lines
(nreverse lines
))
3958 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3959 (setq lines
(nreverse lines
))
3960 (when org-export-table-remove-special-lines
3961 ;; Check if the table has a marking column. If yes remove the
3962 ;; column and the special lines
3963 (setq lines
(org-table-clean-before-export lines
)))
3965 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
3966 (get-text-property (or (next-single-property-change
3967 0 'org-caption
(car lines
))
3969 'org-caption
(car lines
))))
3970 (head (and org-export-highlight-first-table-line
3972 (lambda (x) (string-match "^[ \t]*|-" x
))
3976 tbopen line fields html gr colgropen
)
3977 (if splice
(setq head nil
))
3978 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3980 (while (setq line
(pop lines
))
3982 (if (string-match "^[ \t]*|-" line
)
3985 (push (if head
"</thead>" "</tbody>") html
)
3986 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3987 (setq head nil
) ;; head ends here, first time around
3989 (throw 'next-line t
)))
3990 ;; Break the line into fields
3991 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3992 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3993 (setq nlines
(1+ nlines
) i -
1)
3994 (push (concat "<tr>"
3998 (if (and (< i nlines
)
3999 (string-match org-table-number-regexp x
))
4000 (incf (aref fnum i
)))
4002 (concat (car org-export-table-header-tags
) x
4003 (cdr org-export-table-header-tags
))
4004 (concat (car org-export-table-data-tags
) x
4005 (cdr org-export-table-data-tags
))))
4009 (unless splice
(if tbopen
(push "</tbody>" html
)))
4010 (unless splice
(push "</table>\n" html
))
4011 (setq html
(nreverse html
))
4013 ;; Put in col tags with the alignment (unfortunately often ignored...)
4016 (setq gr
(pop org-table-colgroup-info
))
4017 (format "%s<col align=\"%s\"></col>%s"
4018 (if (memq gr
'(:start
:startend
))
4020 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4023 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4025 (if (memq gr
'(:end
:startend
))
4026 (progn (setq colgropen nil
) "</colgroup>")
4030 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4031 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4032 (push html-table-tag html
))
4033 (concat (mapconcat 'identity html
"\n") "\n")))
4035 (defun org-table-clean-before-export (lines)
4036 "Check if the table has a marking column.
4037 If yes remove the column and the special lines."
4038 (setq org-table-colgroup-info nil
)
4041 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4042 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
4045 (setq org-table-clean-did-remove-column nil
)
4050 ((string-match "^[ \t]*| */ *|" x
)
4051 (setq org-table-colgroup-info
4053 (cond ((member x
'("<" "<")) :start
)
4054 ((member x
'(">" ">")) :end
)
4055 ((member x
'("<>" "<>")) :startend
)
4057 (org-split-string x
"[ \t]*|[ \t]*")))
4061 (setq org-table-clean-did-remove-column t
)
4066 ((string-match "^[ \t]*| */ *|" x
)
4067 (setq org-table-colgroup-info
4069 (cond ((member x
'("<" "<")) :start
)
4070 ((member x
'(">" ">")) :end
)
4071 ((member x
'("<>" "<>")) :startend
)
4073 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4075 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4076 nil
) ; ignore this line
4077 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4078 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4079 ;; remove the first column
4080 (replace-match "\\1|" t nil x
))))
4083 (defun org-format-table-table-html (lines)
4084 "Format a table generated by table.el into HTML.
4085 This conversion does *not* use `table-generate-source' from table.el.
4086 This has the advantage that Org-mode's HTML conversions can be used.
4087 But it has the disadvantage, that no cell- or row-spanning is allowed."
4088 (let (line field-buffer
4089 (head org-export-highlight-first-table-line
)
4091 (setq html
(concat html-table-tag
"\n"))
4092 (while (setq line
(pop lines
))
4093 (setq empty
" ")
4095 (if (string-match "^[ \t]*\\+-" line
)
4106 (if (equal x
"") (setq x empty
))
4108 (concat (car org-export-table-header-tags
) x
4109 (cdr org-export-table-header-tags
))
4110 (concat (car org-export-table-data-tags
) x
4111 (cdr org-export-table-data-tags
))))
4115 (setq field-buffer nil
)))
4117 (throw 'next-line t
)))
4118 ;; Break the line into fields and store the fields
4119 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4121 (setq field-buffer
(mapcar
4123 (concat x
"<br/>" (pop fields
)))
4125 (setq field-buffer fields
))))
4126 (setq html
(concat html
"</table>\n"))
4129 (defun org-format-table-table-html-using-table-generate-source (lines)
4130 "Format a table into html, using `table-generate-source' from table.el.
4131 This has the advantage that cell- or row-spanning is allowed.
4132 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4134 (with-current-buffer (get-buffer-create " org-tmp1 ")
4136 (insert (mapconcat 'identity lines
"\n"))
4137 (goto-char (point-min))
4138 (if (not (re-search-forward "|[^+]" nil t
))
4139 (error "Error processing table"))
4140 (table-recognize-table)
4141 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4142 (table-generate-source 'html
" org-tmp2 ")
4143 (set-buffer " org-tmp2 ")
4144 (buffer-substring (point-min) (point-max))))
4146 (defun org-export-splice-style (style extra
)
4147 "Splice EXTRA into STYLE, just before \"</style>\"."
4148 (if (and (stringp extra
)
4149 (string-match "\\S-" extra
)
4150 (string-match "</style>" style
))
4151 (concat (substring style
0 (match-beginning 0))
4153 (substring style
(match-beginning 0)))
4156 (defun org-html-handle-time-stamps (s)
4157 "Format time stamps in string S, or remove them."
4160 (while (string-match org-maybe-keyword-time-regexp s
)
4161 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
4162 ;; never export CLOCK
4164 (or b
(setq b
(substring s
0 (match-beginning 0))))
4165 (if (not org-export-with-timestamps
)
4166 (setq r
(concat r
(substring s
0 (match-beginning 0)))
4167 s
(substring s
(match-end 0)))
4169 r
(substring s
0 (match-beginning 0))
4171 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4172 (match-string 1 s
)))
4173 (format " @<span class=\"timestamp\">%s@</span>"
4175 (org-translate-time (match-string 3 s
)) 1 -
1)))
4176 s
(substring s
(match-end 0)))))
4177 ;; Line break if line started and ended with time stamp stuff
4180 (setq r
(concat r s
))
4181 (unless (string-match "\\S-" (concat b s
))
4182 (setq r
(concat r
"@<br/>")))
4185 (defun org-export-htmlize-region-for-paste (beg end
)
4186 "Convert the region to HTML, using htmlize.el.
4187 This is much like `htmlize-region-for-paste', only that it uses
4188 the settings define in the org-... variables."
4189 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4190 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4191 (htmlbuf (htmlize-region beg end
)))
4193 (with-current-buffer htmlbuf
4194 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4195 (plist-get htmlize-buffer-places
'content-end
)))
4196 (kill-buffer htmlbuf
))))
4199 (defun org-export-htmlize-generate-css ()
4200 "Create the CSS for all font definitions in the current Emacs session.
4201 Use this to create face definitions in your CSS style file that can then
4202 be used by code snippets transformed by htmlize.
4203 This command just produces a buffer that contains class definitions for all
4204 faces used in the current Emacs session. You can copy and paste the ones you
4205 need into your CSS file.
4207 If you then set `org-export-htmlize-output-type' to `css', calls to
4208 the function `org-export-htmlize-region-for-paste' will produce code
4209 that uses these same face definitions."
4212 (and (get-buffer "*html*") (kill-buffer "*html*"))
4214 (let ((fl (face-list))
4215 (htmlize-css-name-prefix "org-")
4216 (htmlize-output-type 'css
)
4218 (while (setq f
(pop fl
)
4219 i
(and f
(face-attribute f
:inherit
)))
4220 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4221 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4222 (htmlize-region (point-min) (point-max))))
4223 (switch-to-buffer "*html*")
4224 (goto-char (point-min))
4225 (if (re-search-forward "<style" nil t
)
4226 (delete-region (point-min) (match-beginning 0)))
4227 (if (re-search-forward "</style>" nil t
)
4228 (delete-region (1+ (match-end 0)) (point-max)))
4229 (beginning-of-line 1)
4230 (if (looking-at " +") (replace-match ""))
4231 (goto-char (point-min)))
4233 (defun org-html-protect (s)
4234 ;; convert & to &, < to < and > to >
4236 (while (string-match "&" s start
)
4237 (setq s
(replace-match "&" t t s
)
4238 start
(1+ (match-beginning 0))))
4239 (while (string-match "<" s
)
4240 (setq s
(replace-match "<" t t s
)))
4241 (while (string-match ">" s
)
4242 (setq s
(replace-match ">" t t s
)))
4243 ; (while (string-match "\"" s)
4244 ; (setq s (replace-match """ t t s)))
4248 (defun org-export-cleanup-toc-line (s)
4249 "Remove tags and timestamps from lines going into the toc."
4250 (when (memq org-export-with-tags
'(not-in-toc nil
))
4251 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4252 (setq s
(replace-match "" t t s
))))
4253 (when org-export-remove-timestamps-from-toc
4254 (while (string-match org-maybe-keyword-time-regexp s
)
4255 (setq s
(replace-match "" t t s
))))
4256 (while (string-match org-bracket-link-regexp s
)
4257 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4261 (defun org-html-expand (string)
4262 "Prepare STRING for HTML export. Applies all active conversions.
4263 If there are links in the string, don't modify these."
4264 (let* ((re (concat org-bracket-link-regexp
"\\|"
4265 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4267 (while (setq m
(string-match re string
))
4268 (setq s
(substring string
0 m
)
4269 l
(match-string 0 string
)
4270 string
(substring string
(match-end 0)))
4271 (push (org-html-do-expand s
) res
)
4273 (push (org-html-do-expand string
) res
)
4274 (apply 'concat
(nreverse res
))))
4276 (defun org-html-do-expand (s)
4277 "Apply all active conversions to translate special ASCII to HTML."
4278 (setq s
(org-html-protect s
))
4279 (if org-export-html-expand
4281 (while (string-match "@<\\([^&]*\\)>" s
)
4282 (setq s
(replace-match "<\\1>" t nil s
)))))
4283 (if org-export-with-emphasize
4284 (setq s
(org-export-html-convert-emphasize s
)))
4285 (if org-export-with-special-strings
4286 (setq s
(org-export-html-convert-special-strings s
)))
4287 (if org-export-with-sub-superscripts
4288 (setq s
(org-export-html-convert-sub-super s
)))
4289 (if org-export-with-TeX-macros
4290 (let ((start 0) wd ass
)
4291 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4293 (if (get-text-property (match-beginning 0) 'org-protected s
)
4294 (setq start
(match-end 0))
4295 (setq wd
(match-string 1 s
))
4296 (if (setq ass
(assoc wd org-html-entities
))
4297 (setq s
(replace-match (or (cdr ass
)
4298 (concat "&" (car ass
) ";"))
4300 (setq start
(+ start
(length wd
))))))))
4303 (defun org-create-multibrace-regexp (left right n
)
4304 "Create a regular expression which will match a balanced sexp.
4305 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4306 as single character strings.
4307 The regexp returned will match the entire expression including the
4308 delimiters. It will also define a single group which contains the
4309 match except for the outermost delimiters. The maximum depth of
4310 stacked delimiters is N. Escaping delimiters is not possible."
4311 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4314 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4317 re
(concat re or next
)
4318 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4319 (concat left
"\\(" re
"\\)" right
)))
4321 (defvar org-match-substring-regexp
4323 "\\([^\\]\\)\\([_^]\\)\\("
4324 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4326 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4328 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4329 "The regular expression matching a sub- or superscript.")
4331 (defvar org-match-substring-with-braces-regexp
4333 "\\([^\\]\\)\\([_^]\\)\\("
4334 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4336 "The regular expression matching a sub- or superscript, forcing braces.")
4338 (defconst org-export-html-special-string-regexps
4339 '(("\\\\-" .
"­")
4340 ("---\\([^-]\\)" .
"—\\1")
4341 ("--\\([^-]\\)" .
"–\\1")
4342 ("\\.\\.\\." .
"…"))
4343 "Regular expressions for special string conversion.")
4345 (defun org-export-html-convert-special-strings (string)
4346 "Convert special characters in STRING to HTML."
4347 (let ((all org-export-html-special-string-regexps
)
4349 (while (setq a
(pop all
))
4350 (setq re
(car a
) rpl
(cdr a
) start
0)
4351 (while (string-match re string start
)
4352 (if (get-text-property (match-beginning 0) 'org-protected string
)
4353 (setq start
(match-end 0))
4354 (setq string
(replace-match rpl t nil string
)))))
4357 (defun org-export-html-convert-sub-super (string)
4358 "Convert sub- and superscripts in STRING to HTML."
4359 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4360 (while (string-match org-match-substring-regexp string s
)
4362 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4363 ((get-text-property (match-beginning 2) 'org-protected string
)
4364 (setq s
(match-end 2)))
4366 (setq s
(match-end 1)
4367 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4368 c
(or (match-string 8 string
)
4369 (match-string 6 string
)
4370 (match-string 5 string
))
4371 string
(replace-match
4372 (concat (match-string 1 string
)
4373 "<" key
">" c
"</" key
">")
4375 (while (string-match "\\\\\\([_^]\\)" string
)
4376 (setq string
(replace-match (match-string 1 string
) t t string
)))
4379 (defun org-export-html-convert-emphasize (string)
4382 (while (string-match org-emph-re string s
)
4384 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4385 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4386 (setq s
(match-beginning 0)
4389 (match-string 1 string
)
4390 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4391 (match-string 4 string
)
4392 (nth 3 (assoc (match-string 3 string
)
4393 org-emphasis-alist
))
4394 (match-string 5 string
))
4395 string
(replace-match rpl t t string
)
4396 s
(+ s
(- (length rpl
) 2)))
4400 (defun org-open-par ()
4401 "Insert <p>, but first close previous paragraph if any."
4402 (org-close-par-maybe)
4404 (setq org-par-open t
))
4405 (defun org-close-par-maybe ()
4406 "Close paragraph if there is one open."
4409 (setq org-par-open nil
)))
4410 (defun org-close-li (&optional type
)
4411 "Close <li> if necessary."
4412 (org-close-par-maybe)
4413 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4415 (defvar body-only
) ; dynamically scoped into this.
4416 (defun org-html-level-start (level title umax with-toc head-count
)
4417 "Insert a new level in HTML export.
4418 When TITLE is nil, just close all open levels."
4419 (org-close-par-maybe)
4420 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4422 (mapconcat (lambda (x)
4423 (format "<a name=\"%s\" id=\"%s\"></a>"
4425 (cdr (assoc target org-export-target-aliases
))
4430 (if (aref org-levels-open
(1- l
))
4432 (org-html-level-close l umax
)
4433 (aset org-levels-open
(1- l
) nil
)))
4436 ;; If title is nil, this means this function is called to close
4437 ;; all levels, so the rest is done only if title is given
4438 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4439 (setq title
(replace-match
4440 (if org-export-with-tags
4443 " <span class=\"tag\">"
4444 (mapconcat 'identity
(org-split-string
4445 (match-string 1 title
) ":")
4452 (if (aref org-levels-open
(1- level
))
4456 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4457 (insert "<li>" title
"<br/>\n")))
4458 (aset org-levels-open
(1- level
) t
)
4459 (org-close-par-maybe)
4461 (insert (format "<ul>\n<li id=\"%s\">" target
)
4462 extra-targets title
"<br/>\n")
4463 (insert "<ul>\n<li>" title
"<br/>\n"))))
4464 (aset org-levels-open
(1- level
) t
)
4465 (setq snumber
(org-section-number level
))
4466 (if (and org-export-with-section-numbers
(not body-only
))
4467 (setq title
(concat snumber
" " title
)))
4468 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4469 (unless (= head-count
1) (insert "\n</div>\n"))
4470 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s%s</h%d>\n<div id=\"text-%s\">\n"
4471 snumber level level snumber extra-targets title level snumber
))
4474 (defun org-get-text-property-any (pos prop
&optional object
)
4475 (or (get-text-property pos prop object
)
4476 (and (setq pos
(next-single-property-change pos prop object
))
4477 (get-text-property pos prop object
))))
4479 (defun org-html-level-close (level max-outline-level
)
4480 "Terminate one level in HTML export."
4481 (if (<= level max-outline-level
)
4484 (insert "</ul>\n")))
4486 ;;; iCalendar export
4489 (defun org-export-icalendar-this-file ()
4490 "Export current file as an iCalendar file.
4491 The iCalendar file will be located in the same directory as the Org-mode
4492 file, but with extension `.ics'."
4494 (org-export-icalendar nil buffer-file-name
))
4497 (defun org-export-icalendar-all-agenda-files ()
4498 "Export all files in `org-agenda-files' to iCalendar .ics files.
4499 Each iCalendar file will be located in the same directory as the Org-mode
4500 file, but with extension `.ics'."
4502 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4505 (defun org-export-icalendar-combine-agenda-files ()
4506 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4507 The file is stored under the name `org-combined-agenda-icalendar-file'."
4509 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4511 (defun org-export-icalendar (combine &rest files
)
4512 "Create iCalendar files for all elements of FILES.
4513 If COMBINE is non-nil, combine all calendar entries into a single large
4514 file and store it under the name `org-combined-agenda-icalendar-file'."
4516 (org-prepare-agenda-buffers files
)
4517 (let* ((dir (org-export-directory
4518 :ical
(list :publishing-directory
4519 org-export-publishing-directory
)))
4520 file ical-file ical-buffer category started org-agenda-new-buffers
)
4521 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4524 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4525 org-combined-agenda-icalendar-file
4526 (expand-file-name org-combined-agenda-icalendar-file dir
))
4527 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4528 (set-buffer ical-buffer
) (erase-buffer))
4529 (while (setq file
(pop files
))
4531 (org-check-agenda-file file
)
4532 (set-buffer (org-get-agenda-file-buffer file
))
4534 (setq ical-file
(concat (file-name-as-directory dir
)
4535 (file-name-sans-extension
4536 (file-name-nondirectory buffer-file-name
))
4538 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4539 (with-current-buffer ical-buffer
(erase-buffer)))
4540 (setq category
(or org-category
4541 (file-name-sans-extension
4542 (file-name-nondirectory buffer-file-name
))))
4543 (if (symbolp category
) (setq category
(symbol-name category
)))
4544 (let ((standard-output ical-buffer
))
4546 (and (not started
) (setq started t
)
4547 (org-start-icalendar-file org-icalendar-combined-name
))
4548 (org-start-icalendar-file category
))
4549 (org-print-icalendar-entries combine
)
4550 (when (or (and combine
(not files
)) (not combine
))
4551 (org-finish-icalendar-file)
4552 (set-buffer ical-buffer
)
4553 (run-hooks 'org-before-save-iCalendar-file-hook
)
4555 (run-hooks 'org-after-save-iCalendar-file-hook
)
4556 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4558 (org-release-buffers org-agenda-new-buffers
))))
4560 (defvar org-before-save-iCalendar-file-hook nil
4561 "Hook run before an iCalendar file has been saved.
4562 This can be used to modify the result of the export.")
4564 (defvar org-after-save-iCalendar-file-hook nil
4565 "Hook run after an iCalendar file has been saved.
4566 The iCalendar buffer is still current when this hook is run.
4567 A good way to use this is to tell a desktop calendar application to re-read
4568 the iCalendar file.")
4570 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4571 (defun org-print-icalendar-entries (&optional combine
)
4572 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4573 When COMBINE is non nil, add the category to each line."
4574 (require 'org-agenda
)
4575 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4576 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4577 (dts (org-ical-ts-to-string
4578 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4580 hd ts ts2 state status
(inc t
) pos b sexp rrule
4581 scheduledp deadlinep todo prefix due start
4582 tmp pri categories entry location summary desc uid
4583 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4584 (org-refresh-category-properties)
4586 (goto-char (point-min))
4587 (while (re-search-forward re1 nil t
)
4590 (when (boundp 'org-icalendar-verify-function
)
4591 (unless (funcall org-icalendar-verify-function
)
4592 (outline-next-heading)
4595 (setq pos
(match-beginning 0)
4598 hd
(condition-case nil
4599 (org-icalendar-cleanup-string
4601 (error (throw :skip nil
)))
4602 summary
(org-icalendar-cleanup-string
4603 (org-entry-get nil
"SUMMARY"))
4604 desc
(org-icalendar-cleanup-string
4605 (or (org-entry-get nil
"DESCRIPTION")
4606 (and org-icalendar-include-body
(org-get-entry)))
4607 t org-icalendar-include-body
)
4608 location
(org-icalendar-cleanup-string
4609 (org-entry-get nil
"LOCATION" 'selective
))
4610 uid
(if org-icalendar-store-UID
4612 (or (org-id-get) (org-id-new)))
4613 categories
(org-export-get-categories)
4614 deadlinep nil scheduledp nil
)
4615 (if (looking-at re2
)
4617 (goto-char (match-end 0))
4618 (setq ts2
(match-string 1)
4619 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4620 (setq tmp
(buffer-substring (max (point-min)
4621 (- pos org-ds-keyword-length
))
4623 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4626 (replace-match "\\1" t nil ts
))
4628 deadlinep
(string-match org-deadline-regexp tmp
)
4629 scheduledp
(string-match org-scheduled-regexp tmp
)
4630 todo
(org-get-todo-state)
4631 ;; donep (org-entry-is-done-p)
4636 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4637 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4642 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4643 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4645 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4646 (if (or (string-match org-tr-regexp hd
)
4647 (string-match org-ts-regexp hd
))
4648 (setq hd
(replace-match "" t t hd
)))
4649 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4651 (concat "\nRRULE:FREQ="
4654 '(("d" .
"DAILY")("w" .
"WEEKLY")
4655 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4656 ";INTERVAL=" (match-string 1 ts
)))
4658 (setq summary
(or summary hd
))
4659 (if (string-match org-bracket-link-regexp summary
)
4661 (replace-match (if (match-end 3)
4662 (match-string 3 summary
)
4663 (match-string 1 summary
))
4665 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4666 (if scheduledp
(setq summary
(concat "S: " summary
)))
4667 (if (string-match "\\`<%%" ts
)
4668 (with-current-buffer sexp-buffer
4669 (insert (substring ts
1 -
1) " " summary
"\n"))
4670 (princ (format "BEGIN:VEVENT
4678 (org-ical-ts-to-string ts
"DTSTART")
4679 (org-ical-ts-to-string ts2
"DTEND" inc
)
4681 (if (and desc
(string-match "\\S-" desc
))
4682 (concat "\nDESCRIPTION: " desc
) "")
4683 (if (and location
(string-match "\\S-" location
))
4684 (concat "\nLOCATION: " location
) "")
4686 (when (and org-icalendar-include-sexps
4687 (condition-case nil
(require 'icalendar
) (error nil
))
4688 (fboundp 'icalendar-export-region
))
4689 ;; Get all the literal sexps
4690 (goto-char (point-min))
4691 (while (re-search-forward "^&?%%(" nil t
)
4694 (setq b
(match-beginning 0))
4695 (goto-char (1- (match-end 0)))
4698 (setq sexp
(buffer-substring b
(point)))
4699 (with-current-buffer sexp-buffer
4700 (insert sexp
"\n"))))
4701 (princ (org-diary-to-ical-string sexp-buffer
))
4702 (kill-buffer sexp-buffer
))
4704 (when org-icalendar-include-todo
4705 (setq prefix
"TODO-")
4706 (goto-char (point-min))
4707 (while (re-search-forward org-todo-line-regexp nil t
)
4710 (when (boundp 'org-icalendar-verify-function
)
4711 (unless (funcall org-icalendar-verify-function
)
4712 (outline-next-heading)
4715 (setq state
(match-string 2))
4716 (setq status
(if (member state org-done-keywords
)
4717 "COMPLETED" "NEEDS-ACTION"))
4719 (or (not (member state org-done-keywords
))
4720 (eq org-icalendar-include-todo
'all
))
4721 (not (member org-archive-tag
(org-get-tags-at)))
4723 (setq hd
(match-string 3)
4724 summary
(org-icalendar-cleanup-string
4725 (org-entry-get nil
"SUMMARY"))
4726 desc
(org-icalendar-cleanup-string
4727 (or (org-entry-get nil
"DESCRIPTION")
4728 (and org-icalendar-include-body
(org-get-entry)))
4729 t org-icalendar-include-body
)
4730 location
(org-icalendar-cleanup-string
4731 (org-entry-get nil
"LOCATION" 'selective
))
4732 due
(and (member 'todo-due org-icalendar-use-deadline
)
4733 (org-entry-get nil
"DEADLINE"))
4734 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4735 (org-entry-get nil
"SCHEDULED"))
4736 categories
(org-export-get-categories)
4737 uid
(if org-icalendar-store-UID
4739 (or (org-id-get) (org-id-new))))
4740 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4741 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4743 (if (string-match org-bracket-link-regexp hd
)
4744 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4745 (match-string 1 hd
))
4747 (if (string-match org-priority-regexp hd
)
4748 (setq pri
(string-to-char (match-string 2 hd
))
4749 hd
(concat (substring hd
0 (match-beginning 1))
4750 (substring hd
(match-end 1))))
4751 (setq pri org-default-priority
))
4752 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4753 (- org-lowest-priority org-highest-priority
))))))
4755 (princ (format "BEGIN:VTODO
4767 (if (and location
(string-match "\\S-" location
))
4768 (concat "\nLOCATION: " location
) "")
4769 (if (and desc
(string-match "\\S-" desc
))
4770 (concat "\nDESCRIPTION: " desc
) "")
4771 (if due
(concat "\n" due
) "")
4775 (defun org-export-get-categories ()
4776 "Get categories according to `org-icalendar-categories'."
4777 (let ((cs org-icalendar-categories
) c rtn tmp
)
4778 (while (setq c
(pop cs
))
4780 ((eq c
'category
) (push (org-get-category) rtn
))
4782 (setq tmp
(org-get-todo-state))
4783 (and tmp
(push tmp rtn
)))
4785 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4787 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4788 (mapconcat 'identity
(nreverse rtn
) ",")))
4790 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4791 "Take out stuff and quote what needs to be quoted.
4792 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4793 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4798 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4799 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4800 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4801 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4803 (while (string-match "\\([,;]\\)" s start
)
4804 (setq start
(+ (match-beginning 0) 2)
4805 s
(replace-match "\\\\\\1" nil nil s
))))
4806 (setq s
(org-trim s
))
4808 (while (string-match "[ \t]*\n[ \t]*" s
)
4809 (setq s
(replace-match "\\n" t t s
))))
4812 (if (and (numberp maxlength
)
4813 (> (length s
) maxlength
))
4814 (setq s
(substring s
0 maxlength
)))))
4817 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4818 "Take out stuff and quote what needs to be quoted.
4819 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4820 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4822 This seems to be more like RFC 2455, but it causes problems, so it is
4823 not used right now."
4827 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4828 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4829 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4830 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4831 (setq s
(org-trim s
))
4832 (while (string-match "[ \t]*\n[ \t]*" s
)
4833 (setq s
(replace-match "\\n" t t s
)))
4835 (if (and (numberp maxlength
)
4836 (> (length s
) maxlength
))
4837 (setq s
(substring s
0 maxlength
)))))
4838 (setq s
(org-trim s
)))
4839 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4840 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
4843 (defun org-get-entry ()
4844 "Clean-up description string."
4846 (org-back-to-heading t
)
4847 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4849 (defun org-start-icalendar-file (name)
4850 "Start an iCalendar file by inserting the header."
4851 (let ((user user-full-name
)
4852 (name (or name
"unknown"))
4853 (timezone (cadr (current-time-zone))))
4855 (format "BEGIN:VCALENDAR
4858 PRODID:-//%s//Emacs with Org-mode//EN
4860 CALSCALE:GREGORIAN\n" name user timezone
))))
4862 (defun org-finish-icalendar-file ()
4863 "Finish an iCalendar file by inserting the END statement."
4864 (princ "END:VCALENDAR\n"))
4866 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4867 "Take a time string S and convert it to iCalendar format.
4868 KEYWORD is added in front, to make a complete line like DTSTART....
4869 When INC is non-nil, increase the hour by two (if time string contains
4870 a time), or the day by one (if it does not contain a time)."
4871 (let ((t1 (org-parse-time-string s
'nodefault
))
4872 t2 fmt have-time time
)
4873 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4874 (setq t2 t1 have-time t
)
4875 (setq t2
(org-parse-time-string s
)))
4876 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4877 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4880 (if org-agenda-default-appointment-duration
4881 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4884 (setq time
(encode-time s mi h d m y
)))
4885 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4886 (concat keyword
(format-time-string fmt time
))))
4890 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4891 (with-current-buffer buffer
4892 (apply 'insert output
)))
4893 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4896 (defun org-export-as-xoxo (&optional buffer
)
4897 "Export the org buffer as XOXO.
4898 The XOXO buffer is named *xoxo-<source buffer name>*"
4899 (interactive (list (current-buffer)))
4900 ;; A quickie abstraction
4902 ;; Output everything as XOXO
4903 (with-current-buffer (get-buffer buffer
)
4904 (let* ((pos (point))
4905 (opt-plist (org-combine-plists (org-default-export-plist)
4906 (org-infile-export-plist)))
4907 (filename (concat (file-name-as-directory
4908 (org-export-directory :xoxo opt-plist
))
4909 (file-name-sans-extension
4910 (file-name-nondirectory buffer-file-name
))
4912 (out (find-file-noselect filename
))
4915 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4916 ;; Check the output buffer is empty.
4917 (with-current-buffer out
(erase-buffer))
4918 ;; Kick off the output
4919 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4920 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4921 (let* ((hd (match-string-no-properties 1))
4924 (match-string-no-properties 2)
4926 (goto-char (match-end 0))
4931 (if (looking-at "^[ \t]\\(.*\\)")
4932 (setq str
(concat str
(match-string-no-properties 1)))
4933 (throw 'loop str
)))))))))
4935 ;; Handle level rendering
4937 ((> level last-level
)
4938 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4940 ((< level last-level
)
4941 (dotimes (- (- last-level level
) 1)
4943 (org-export-as-xoxo-insert-into out
"</li>\n"))
4944 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4946 (org-export-as-xoxo-insert-into out
"</li>\n")
4947 (setq hanging-li nil
)))
4949 ((equal level last-level
)
4951 (org-export-as-xoxo-insert-into out
"</li>\n")))
4954 (setq last-level level
)
4956 ;; And output the new li
4957 (setq hanging-li
't
)
4958 (if (equal ?
+ (elt text
0))
4959 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4960 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4962 ;; Finally finish off the ol
4963 (dotimes (- last-level
1)
4965 (org-export-as-xoxo-insert-into out
"</li>\n"))
4966 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4969 ;; Finish the buffer off and clean it up.
4970 (switch-to-buffer-other-window out
)
4971 (indent-region (point-min) (point-max) nil
)
4973 (goto-char (point-min))
4978 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4980 ;;; org-exp.el ends here