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 (defvar org-export-preprocess-after-include-files-hook nil
302 "Hook for preprocessing an export buffer.
303 This is run after the contents of included files have been inserted.")
305 (defvar org-export-preprocess-after-tree-selection-hook nil
306 "Hook for preprocessing an export buffer.
307 This is run after selection of trees to be exported has happened.
308 This selection includes tags-based selection, as well as removal
309 of commented and archived trees.")
311 (defvar org-export-preprocess-before-backend-specifics-hook nil
312 "Hook run before backend-specific functions are called during preprocessing.")
314 (defvar org-export-preprocess-final-hook nil
315 "Hook for preprocessing an export buffer.
316 This is run as the last thing in the preprocessing buffer, just before
317 returning the buffer string to the backend.")
319 (defgroup org-export-translation nil
320 "Options for translating special ascii sequences for the export backends."
321 :tag
"Org Export Translation"
324 (defcustom org-export-with-emphasize t
325 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
326 If the export target supports emphasizing text, the word will be
327 typeset in bold, italic, or underlined, respectively. Works only for
328 single words, but you can say: I *really* *mean* *this*.
329 Not all export backends support this.
331 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
332 :group
'org-export-translation
335 (defcustom org-export-with-footnotes t
336 "If nil, export [1] as a footnote marker.
337 Lines starting with [1] will be formatted as footnotes.
339 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
340 :group
'org-export-translation
343 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
344 <h2 class=\"footnotes\">%s: </h2>
345 <div id=\"footnotes-text\">
349 "Format for the footnotes section.
350 Should contain a two instances of %s. The first will be replaced with the
351 language-specific word for \"Footnotes\", the second one will be replaced
352 by the footnotes themselves."
353 :group
'org-export-html
356 (defcustom org-export-with-sub-superscripts t
357 "Non-nil means, interpret \"_\" and \"^\" for export.
358 When this option is turned on, you can use TeX-like syntax for sub- and
359 superscripts. Several characters after \"_\" or \"^\" will be
360 considered as a single item - so grouping with {} is normally not
361 needed. For example, the following things will be parsed as single
362 sub- or superscripts.
364 10^24 or 10^tau several digits will be considered 1 item.
365 10^-12 or 10^-tau a leading sign with digits or a word
366 x^2-y^3 will be read as x^2 - y^3, because items are
367 terminated by almost any nonword/nondigit char.
368 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
370 Still, ambiguity is possible - so when in doubt use {} to enclose the
371 sub/superscript. If you set this variable to the symbol `{}',
372 the braces are *required* in order to trigger interpretations as
373 sub/superscript. This can be helpful in documents that need \"_\"
374 frequently in plain text.
376 Not all export backends support this, but HTML does.
378 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
379 :group
'org-export-translation
381 (const :tag
"Always interpret" t
)
382 (const :tag
"Only with braces" {})
383 (const :tag
"Never interpret" nil
)))
385 (defcustom org-export-with-special-strings t
386 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
387 When this option is turned on, these strings will be exported as:
393 Not all export backends support this, but HTML does.
395 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
396 :group
'org-export-translation
399 (defcustom org-export-with-TeX-macros t
400 "Non-nil means, interpret simple TeX-like macros when exporting.
401 For example, HTML export converts \\alpha to α and \\AA to Å.
402 No only real TeX macros will work here, but the standard HTML entities
403 for math can be used as macro names as well. For a list of supported
404 names in HTML export, see the constant `org-html-entities'.
405 Not all export backends support this.
407 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
408 :group
'org-export-translation
409 :group
'org-export-latex
412 (defcustom org-export-with-LaTeX-fragments nil
413 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
414 When set, the exporter will find LaTeX environments if the \\begin line is
415 the first non-white thing on a line. It will also find the math delimiters
416 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
419 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
420 :group
'org-export-translation
421 :group
'org-export-latex
424 (defcustom org-export-with-fixed-width t
425 "Non-nil means, lines starting with \":\" will be in fixed width font.
426 This can be used to have pre-formatted text, fragments of code etc. For
428 : ;; Some Lisp examples
431 will be looking just like this in also HTML. See also the QUOTE keyword.
432 Not all export backends support this.
434 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
435 :group
'org-export-translation
438 (defcustom org-match-sexp-depth
3
439 "Number of stacked braces for sub/superscript matching.
440 This has to be set before loading org.el to be effective."
441 :group
'org-export-translation
444 (defgroup org-export-tables nil
445 "Options for exporting tables in Org-mode."
446 :tag
"Org Export Tables"
449 (defcustom org-export-with-tables t
450 "If non-nil, lines starting with \"|\" define a table.
453 | Name | Address | Birthday |
454 |-------------+----------+-----------|
455 | Arthur Dent | England | 29.2.2100 |
457 Not all export backends support this.
459 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
460 :group
'org-export-tables
463 (defcustom org-export-highlight-first-table-line t
464 "Non-nil means, highlight the first table line.
465 In HTML export, this means use <th> instead of <td>.
466 In tables created with table.el, this applies to the first table line.
467 In Org-mode tables, all lines before the first horizontal separator
468 line will be formatted with <th> tags."
469 :group
'org-export-tables
472 (defcustom org-export-table-remove-special-lines t
473 "Remove special lines and marking characters in calculating tables.
474 This removes the special marking character column from tables that are set
475 up for spreadsheet calculations. It also removes the entire lines
476 marked with `!', `_', or `^'. The lines with `$' are kept, because
477 the values of constants may be useful to have."
478 :group
'org-export-tables
481 (defcustom org-export-prefer-native-exporter-for-tables nil
482 "Non-nil means, always export tables created with table.el natively.
483 Natively means, use the HTML code generator in table.el.
484 When nil, Org-mode's own HTML generator is used when possible (i.e. if
485 the table does not use row- or column-spanning). This has the
486 advantage, that the automatic HTML conversions for math symbols and
487 sub/superscripts can be applied. Org-mode's HTML generator is also
489 :group
'org-export-tables
492 (defgroup org-export-ascii nil
493 "Options specific for ASCII export of Org-mode files."
494 :tag
"Org Export ASCII"
497 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
498 "Characters for underlining headings in ASCII export.
499 In the given sequence, these characters will be used for level 1, 2, ..."
500 :group
'org-export-ascii
501 :type
'(repeat character
))
503 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
504 "Bullet characters for headlines converted to lists in ASCII export.
505 The first character is used for the first lest level generated in this
506 way, and so on. If there are more levels than characters given here,
507 the list will be repeated.
508 Note that plain lists will keep the same bullets as the have in the
510 :group
'org-export-ascii
511 :type
'(repeat character
))
513 (defgroup org-export-xml nil
514 "Options specific for XML export of Org-mode files."
515 :tag
"Org Export XML"
518 (defgroup org-export-html nil
519 "Options specific for HTML export of Org-mode files."
520 :tag
"Org Export HTML"
523 (defcustom org-export-html-coding-system nil
524 "Coding system for HTML export, defaults to buffer-file-coding-system."
525 :group
'org-export-html
526 :type
'coding-system
)
528 (defcustom org-export-html-extension
"html"
529 "The extension for exported HTML files."
530 :group
'org-export-html
533 (defcustom org-export-html-link-up
""
534 "Where should the \"UP\" link of exported HTML pages lead?"
535 :group
'org-export-html
536 :type
'(string :tag
"File or URL"))
538 (defcustom org-export-html-link-home
""
539 "Where should the \"HOME\" link of exported HTML pages lead?"
540 :group
'org-export-html
541 :type
'(string :tag
"File or URL"))
543 (defconst org-export-html-scripts
544 "<script language=\"javascript\" type=\"text/javascript\">
545 <!--/*--><![CDATA[/*><!--*/
546 function CodeHighlightOn(elem, id)
548 var target = document.getElementById(id);
550 elem.cacheClassElem = elem.className;
551 elem.cacheClassTarget = target.className;
552 target.className = \"code-highlighted\";
553 elem.className = \"code-highlighted\";
556 function CodeHighlightOff(elem, id)
558 var target = document.getElementById(id);
559 if(elem.cacheClassElem)
560 elem.className = elem.cacheClassElem;
561 if(elem.cacheClassTarget)
562 target.className = elem.cacheClassTarget;
566 "Basic javascript that is needed by HTML files produced by Org-mode.")
568 (defconst org-export-html-style-default
569 "<style type=\"text/css\">
570 <!--/*--><![CDATA[/*><!--*/
571 html { font-family: Times, serif; font-size: 12pt; }
572 .title { text-align: center; }
573 .todo { color: red; }
574 .done { color: green; }
575 .tag { background-color:lightblue; font-weight:normal }
577 .timestamp { color: grey }
578 .timestamp-kwd { color: CadetBlue }
579 p.verse { margin-left: 3% }
581 border: 1pt solid #AEBDCC;
582 background-color: #F3F5F7;
584 font-family: courier, monospace;
588 table { border-collapse: collapse; }
589 td, th { vertical-align: top; }
590 dt { font-weight: bold; }
591 div.figure { padding: 0.5em; }
592 div.figure p { text-align: center; }
593 .linenr { font-size:smaller }
594 .code-highlighted {background-color:#ffff00;}
595 .org-info-js_info-navigation { border-style:none; }
596 #org-info-js_console-label { font-size:10px; font-weight:bold;
597 white-space:nowrap; }
598 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
602 "The default style specification for exported HTML files.
603 Please use the variables `org-export-html-style' and
604 `org-export-html-style-extra' to add to this style. If you wish to not
605 have the default style included, customize the variable
606 `org-export-html-style-include-default'.")
608 (defcustom org-export-html-style-include-default t
609 "Non-nil means, include the default style in exported HTML files.
610 The actual style is defined in `org-export-html-style-default' and should
611 not be modified. Use the variables `org-export-html-style' to add
612 your own style information."
613 :group
'org-export-html
616 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
618 (defcustom org-export-html-style
""
619 "Org-wide style definitions for exported HTML files.
621 This variable needs to contain the full HTML structure to provide a style,
622 including the surrounding HTML tags. If you set the value of this variable,
623 you should consider to include definitions for the following classes:
624 title, todo, done, timestamp, timestamp-kwd, tag, target.
626 For example, a valid value would be:
628 <style type=\"text/css\">
630 p { font-weight: normal; color: gray; }
632 .title { text-align: center; }
633 .todo, .timestamp-kwd { color: red; }
634 .done { color: green; }
638 If you'd like to refer to en external style file, use something like
640 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
642 As the value of this option simply gets inserted into the HTML <head> header,
643 you can \"misuse\" it to add arbitrary text to the header.
644 See also the variable `org-export-html-style-extra'."
645 :group
'org-export-html
648 (put 'org-export-html-style
'safe-local-variable
'stringp
)
650 (defcustom org-export-html-style-extra
""
651 "Additional style information for HTML export.
652 The value of this variable is inserted into the HTML buffer right after
653 the value of `org-export-html-style'. Use this variable for per-file
654 settings of style information, and do not forget to surround the style
655 settings with <style>...</style> tags."
656 :group
'org-export-html
659 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
662 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
663 "Format for typesetting the document title in HTML export."
664 :group
'org-export-html
667 (defcustom org-export-html-toplevel-hlevel
2
668 "The <H> level for level 1 headings in HTML export."
669 :group
'org-export-html
672 (defcustom org-export-html-link-org-files-as-html t
673 "Non-nil means, make file links to `file.org' point to `file.html'.
674 When org-mode is exporting an org-mode file to HTML, links to
675 non-html files are directly put into a href tag in HTML.
676 However, links to other Org-mode files (recognized by the
677 extension `.org.) should become links to the corresponding html
678 file, assuming that the linked org-mode file will also be
680 When nil, the links still point to the plain `.org' file."
681 :group
'org-export-html
684 (defcustom org-export-html-inline-images
'maybe
685 "Non-nil means, inline images into exported HTML pages.
686 This is done using an <img> tag. When nil, an anchor with href is used to
687 link to the image. If this option is `maybe', then images in links with
688 an empty description will be inlined, while images with a description will
690 :group
'org-export-html
691 :type
'(choice (const :tag
"Never" nil
)
692 (const :tag
"Always" t
)
693 (const :tag
"When there is no description" maybe
)))
696 (defcustom org-export-html-expand t
697 "Non-nil means, for HTML export, treat @<...> as HTML tag.
698 When nil, these tags will be exported as plain text and therefore
699 not be interpreted by a browser.
701 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
702 :group
'org-export-html
705 (defcustom org-export-html-table-tag
706 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
707 "The HTML tag that is used to start a table.
708 This must be a <table> tag, but you may change the options like
709 borders and spacing."
710 :group
'org-export-html
713 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
714 "The opening tag for table header fields.
715 This is customizable so that alignment options can be specified."
716 :group
'org-export-tables
717 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
719 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
720 "The opening tag for table data fields.
721 This is customizable so that alignment options can be specified."
722 :group
'org-export-tables
723 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
725 (defcustom org-export-html-with-timestamp nil
726 "If non-nil, write `org-export-html-html-helper-timestamp'
727 into the exported HTML text. Otherwise, the buffer will just be saved
729 :group
'org-export-html
732 (defcustom org-export-html-html-helper-timestamp
733 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
734 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
735 :group
'org-export-html
738 (defgroup org-export-htmlize nil
739 "Options for processing examples with htmlize.el."
740 :tag
"Org Export Htmlize"
741 :group
'org-export-html
)
743 (defcustom org-export-htmlize-output-type
'inline-css
744 "Output type to be used by htmlize when formatting code snippets.
745 Normally this is `inline-css', but if you have defined to appropriate
746 classes in your css style file, setting this to `css' means that the
747 fontification will use the class names.
748 See also the function `org-export-htmlize-generate-css'."
749 :group
'org-export-htmlize
750 :type
'(choice (const css
) (const inline-css
)))
752 (defcustom org-export-htmlize-css-font-prefix
"org-"
753 "The prefix for CSS class names for htmlize font specifications."
754 :group
'org-export-htmlize
757 (defgroup org-export-icalendar nil
758 "Options specific for iCalendar export of Org-mode files."
759 :tag
"Org Export iCalendar"
762 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
763 "The file name for the iCalendar file covering all agenda files.
764 This file is created with the command \\[org-export-icalendar-all-agenda-files].
765 The file name should be absolute, the file will be overwritten without warning."
766 :group
'org-export-icalendar
769 (defcustom org-icalendar-combined-name
"OrgMode"
770 "Calendar name for the combined iCalendar representing all agenda files."
771 :group
'org-export-icalendar
774 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
775 "Contexts where iCalendar export should use a deadline time stamp.
776 This is a list with several symbols in it. Valid symbol are:
778 event-if-todo Deadlines in TODO entries become calendar events.
779 event-if-not-todo Deadlines in non-TODO entries become calendar events.
780 todo-due Use deadlines in TODO entries as due-dates"
781 :group
'org-export-icalendar
782 :type
'(set :greedy t
783 (const :tag
"Deadlines in non-TODO entries become events"
785 (const :tag
"Deadline in TODO entries become events"
787 (const :tag
"Deadlines in TODO entries become due-dates"
790 (defcustom org-icalendar-use-scheduled
'(todo-start)
791 "Contexts where iCalendar export should use a scheduling time stamp.
792 This is a list with several symbols in it. Valid symbol are:
794 event-if-todo Scheduling time stamps in TODO entries become an event.
795 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
796 todo-start Scheduling time stamps in TODO entries become start date.
797 Some calendar applications show TODO entries only after
799 :group
'org-export-icalendar
800 :type
'(set :greedy t
802 "SCHEDULED timestamps in non-TODO entries become events"
804 (const :tag
"SCHEDULED timestamps in TODO entries become events"
806 (const :tag
"SCHEDULED in TODO entries become start date"
809 (defcustom org-icalendar-categories
'(local-tags category
)
810 "Items that should be entered into the categories field.
811 This is a list of symbols, the following are valid:
813 category The Org-mode category of the current file or tree
814 todo-state The todo state, if any
815 local-tags The tags, defined in the current line
816 all-tags All tags, including inherited ones."
817 :group
'org-export-icalendar
820 (const :tag
"The file or tree category" category
)
821 (const :tag
"The TODO state" todo-state
)
822 (const :tag
"Tags defined in current line" local-tags
)
823 (const :tag
"All tags, including inherited ones" all-tags
))))
825 (defcustom org-icalendar-include-todo nil
826 "Non-nil means, export to iCalendar files should also cover TODO items."
827 :group
'org-export-icalendar
829 (const :tag
"None" nil
)
830 (const :tag
"Unfinished" t
)
831 (const :tag
"All" all
)))
833 (defcustom org-icalendar-include-sexps t
834 "Non-nil means, export to iCalendar files should also cover sexp entries.
835 These are entries like in the diary, but directly in an Org-mode file."
836 :group
'org-export-icalendar
839 (defcustom org-icalendar-include-body
100
840 "Amount of text below headline to be included in iCalendar export.
841 This is a number of characters that should maximally be included.
842 Properties, scheduling and clocking lines will always be removed.
843 The text will be inserted into the DESCRIPTION field."
844 :group
'org-export-icalendar
846 (const :tag
"Nothing" nil
)
847 (const :tag
"Everything" t
)
848 (integer :tag
"Max characters")))
850 (defcustom org-icalendar-store-UID nil
851 "Non-nil means, store any created UIDs in properties.
852 The iCalendar standard requires that all entries have a unique identifier.
853 Org will create these identifiers as needed. When this variable is non-nil,
854 the created UIDs will be stored in the ID property of the entry. Then the
855 next time this entry is exported, it will be exported with the same UID,
856 superceding the previous form of it. This is essential for
857 synchronization services.
858 This variable is not turned on by default because we want to avoid creating
859 a property drawer in every entry if people are only playing with this feature,
860 or if they are only using it locally."
861 :group
'org-export-icalendar
866 ;;; Variables, constants, and parameter plists
868 (defconst org-level-max
20)
870 (defvar org-export-html-preamble nil
871 "Preamble, to be inserted just before <body>. Set by publishing functions.")
872 (defvar org-export-html-postamble nil
873 "Preamble, to be inserted just after </body>. Set by publishing functions.")
874 (defvar org-export-html-auto-preamble t
875 "Should default preamble be inserted? Set by publishing functions.")
876 (defvar org-export-html-auto-postamble t
877 "Should default postamble be inserted? Set by publishing functions.")
878 (defvar org-current-export-file nil
) ; dynamically scoped parameter
879 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
881 (defconst org-export-plist-vars
882 '((:link-up nil org-export-html-link-up
)
883 (:link-home nil org-export-html-link-home
)
884 (:language nil org-export-default-language
)
885 (:customtime nil org-display-custom-times
)
886 (:headline-levels
"H" org-export-headline-levels
)
887 (:section-numbers
"num" org-export-with-section-numbers
)
888 (:section-number-format nil org-export-section-number-format
)
889 (:table-of-contents
"toc" org-export-with-toc
)
890 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
891 (:archived-trees nil org-export-with-archived-trees
)
892 (:emphasize
"*" org-export-with-emphasize
)
893 (:sub-superscript
"^" org-export-with-sub-superscripts
)
894 (:special-strings
"-" org-export-with-special-strings
)
895 (:footnotes
"f" org-export-with-footnotes
)
896 (:drawers
"d" org-export-with-drawers
)
897 (:tags
"tags" org-export-with-tags
)
898 (:todo-keywords
"todo" org-export-with-todo-keywords
)
899 (:priority
"pri" org-export-with-priority
)
900 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
901 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
902 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
903 (:fixed-width
":" org-export-with-fixed-width
)
904 (:timestamps
"<" org-export-with-timestamps
)
905 (:author-info
"author" org-export-author-info
)
906 (:creator-info
"creator" org-export-creator-info
)
907 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
908 (:tables
"|" org-export-with-tables
)
909 (:table-auto-headline nil org-export-highlight-first-table-line
)
910 (:style-include-default nil org-export-html-style-include-default
)
911 (:style nil org-export-html-style
)
912 (:style-extra nil org-export-html-style-extra
)
913 (:agenda-style nil org-agenda-export-html-style
)
914 (:convert-org-links nil org-export-html-link-org-files-as-html
)
915 (:inline-images nil org-export-html-inline-images
)
916 (:html-extension nil org-export-html-extension
)
917 (:html-table-tag nil org-export-html-table-tag
)
918 (:expand-quoted-html
"@" org-export-html-expand
)
919 (:timestamp nil org-export-html-with-timestamp
)
920 (:publishing-directory nil org-export-publishing-directory
)
921 (:preamble nil org-export-html-preamble
)
922 (:postamble nil org-export-html-postamble
)
923 (:auto-preamble nil org-export-html-auto-preamble
)
924 (:auto-postamble nil org-export-html-auto-postamble
)
925 (:author nil user-full-name
)
926 (:email nil user-mail-address
)
927 (:select-tags nil org-export-select-tags
)
928 (:exclude-tags nil org-export-exclude-tags
))
929 "List of properties that represent export/publishing variables.
930 Each element is a list of 3 items:
931 1. The property that is used internally, and also for org-publish-project-alist
932 2. The string that can be used in the OPTION lines to set this option,
933 or nil if this option cannot be changed in this way
934 3. The customization variable that sets the default for this option."
938 (defun org-default-export-plist ()
939 "Return the property list with default settings for the export variables."
940 (let ((l org-export-plist-vars
) rtn e
)
941 (while (setq e
(pop l
))
942 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
945 (defvar org-export-inbuffer-options-extra nil
946 "List of additional in-buffer options that should be detected.
947 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
948 etc. Extensions can add to this list to get their options detected, and they
949 can then add a function to `org-export-options-filters' to process these
951 Each element in this list must be a list, with the in-buffer keyword as car,
952 and a property (a symbol) as the next element. All occurrences of the
953 keyword will be found, the values concatenated with a space character
954 in between, and the result stored in the export options property list.")
956 (defvar org-export-options-filters nil
957 "Functions to be called to finalize the export/publishing options.
958 All these options are stored in a property list, and each of the functions
959 in this hook gets a chance to modify this property list. Each function
960 must accept the property list as an argument, and must return the (possibly
963 ;; FIXME: should we fold case here?
964 (defun org-infile-export-plist ()
965 "Return the property list with file-local settings for export."
969 (goto-char (point-min))
970 (let ((re (org-make-options-regexp
972 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
973 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
974 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
975 (mapcar 'car org-export-inbuffer-options-extra
))))
976 p key val text options js-up js-main js-css js-opt a pr style
978 ext-setup-or-nil setup-contents
(start 0))
979 (while (or (and ext-setup-or-nil
980 (string-match re ext-setup-or-nil start
)
981 (setq start
(match-end 0)))
982 (and (setq ext-setup-or-nil nil start
0)
983 (re-search-forward re nil t
)))
984 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
985 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
987 ((setq a
(assoc key org-export-inbuffer-options-extra
))
989 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
990 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
991 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
992 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
993 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
994 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
995 ((string-equal key
"STYLE")
996 (setq style
(concat style
"\n" val
)))
997 ((string-equal key
"LATEX_HEADER")
998 (setq latex-header
(concat latex-header
"\n" val
)))
999 ((string-equal key
"TEXT")
1000 (setq text
(if text
(concat text
"\n" val
) val
)))
1001 ((string-equal key
"OPTIONS")
1002 (setq options
(concat val
" " options
)))
1003 ((string-equal key
"LINK_UP")
1004 (setq p
(plist-put p
:link-up val
)))
1005 ((string-equal key
"LINK_HOME")
1006 (setq p
(plist-put p
:link-home val
)))
1007 ((string-equal key
"EXPORT_SELECT_TAGS")
1008 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
1009 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
1010 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
1011 ((equal key
"SETUPFILE")
1012 (setq setup-contents
(org-file-contents
1014 (org-remove-double-quotes
1017 (if (not ext-setup-or-nil
)
1018 (setq ext-setup-or-nil setup-contents start
0)
1019 (setq ext-setup-or-nil
1020 (concat (substring ext-setup-or-nil
0 start
)
1021 "\n" setup-contents
"\n"
1022 (substring ext-setup-or-nil start
)))))))
1023 (setq p
(plist-put p
:text text
))
1024 (when style
(setq p
(plist-put p
:style-extra style
)))
1026 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1028 (setq p
(org-export-add-options-to-plist p options
)))
1031 (defun org-export-add-options-to-plist (p options
)
1032 "Parse an OPTIONS line and set values in the property list P."
1035 (let ((op org-export-plist-vars
) a
)
1036 (while (setq o
(pop op
))
1038 (string-match (concat (regexp-quote (nth 1 o
))
1039 ":\\([^ \t\n\r;,.]*\\)")
1041 (setq p
(plist-put p
(car o
)
1042 (car (read-from-string
1043 (match-string 1 options
))))))))))
1046 (defun org-export-add-subtree-options (p pos
)
1047 "Add options in subtree at position POS to property list P."
1050 (when (org-at-heading-p)
1052 ;; This is actually read in `org-export-get-title-from-subtree'
1053 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1054 ;; (setq p (plist-put p :title a)))
1055 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1056 (setq p
(plist-put p
:text a
)))
1057 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1058 (setq p
(org-export-add-options-to-plist p a
)))))
1061 (defun org-export-directory (type plist
)
1062 (let* ((val (plist-get plist
:publishing-directory
))
1063 (dir (if (listp val
)
1064 (or (cdr (assoc type val
)) ".")
1068 (defun org-export-process-option-filters (plist)
1069 (let ((functions org-export-options-filters
) f
)
1070 (while (setq f
(pop functions
))
1071 (setq plist
(funcall f plist
))))
1075 (defun org-export (&optional arg
)
1076 "Export dispatcher for Org-mode.
1077 When `org-export-run-in-background' is non-nil, try to run the command
1078 in the background. This will be done only for commands that write
1079 to a file. For details see the docstring of `org-export-run-in-background'.
1081 The prefix argument ARG will be passed to the exporter. However, if
1082 ARG is a double universal prefix `C-u C-u', that means to inverse the
1083 value of `org-export-run-in-background'."
1085 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1086 (help "[t] insert the export option template
1087 \[v] limit export to visible part of outline tree
1089 \[a] export as ASCII
1092 \[H] export as HTML to temporary buffer
1093 \[R] export region as HTML
1094 \[b] export as HTML and browse immediately
1097 \[l] export as LaTeX
1098 \[p] export as LaTeX and process to PDF
1099 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1100 \[L] export as LaTeX to temporary buffer
1102 \[i] export current file as iCalendar file
1103 \[I] export all agenda files as iCalendar files
1104 \[c] export agenda files into combined iCalendar file
1106 \[F] publish current file
1107 \[P] publish current project
1108 \[X] publish... (project will be prompted for)
1109 \[A] publish all projects")
1111 '((?t org-insert-export-options-template nil
)
1112 (?v org-export-visible nil
)
1113 (?a org-export-as-ascii t
)
1114 (?h org-export-as-html t
)
1115 (?b org-export-as-html-and-open t
)
1116 (?H org-export-as-html-to-buffer nil
)
1117 (?R org-export-region-as-html nil
)
1118 (?x org-export-as-xoxo t
)
1119 (?l org-export-as-latex t
)
1120 (?p org-export-as-pdf t
)
1121 (?d org-export-as-pdf-and-open t
)
1122 (?L org-export-as-latex-to-buffer nil
)
1123 (?i org-export-icalendar-this-file t
)
1124 (?I org-export-icalendar-all-agenda-files t
)
1125 (?c org-export-icalendar-combine-agenda-files t
)
1126 (?F org-publish-current-file t
)
1127 (?P org-publish-current-project t
)
1129 (?A org-publish-all t
)))
1131 (save-window-excursion
1132 (delete-other-windows)
1133 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1135 (org-fit-window-to-buffer (get-buffer-window
1136 "*Org Export/Publishing Help*"))
1137 (message "Select command: ")
1138 (setq r1
(read-char-exclusive)))
1139 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1140 (unless (setq ass
(assq r2 cmds
))
1141 (error "No command associated with key %c" r1
))
1142 (if (and bg
(nth 2 ass
)
1143 (not (buffer-base-buffer))
1144 (not (org-region-active-p)))
1145 ;; execute in background
1146 (let ((p (start-process
1147 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1149 (expand-file-name invocation-name invocation-directory
)
1152 "--eval" "(require 'org-exp)"
1153 "--eval" "(setq org-wait .2)"
1155 "-f" (symbol-name (nth 1 ass
)))))
1156 (set-process-sentinel p
'org-export-process-sentinel
)
1157 (message "Background process \"%s\": started" p
))
1158 ;; background processing not requested, or not possible
1159 (call-interactively (nth 1 ass
)))))
1161 (defun org-export-process-sentinel (process status
)
1162 (if (string-match "\n+\\'" status
)
1163 (setq status
(substring status
0 -
1)))
1164 (message "Background process \"%s\": %s" process status
))
1166 (defconst org-html-entities
1207 ("Aring") ("AA".
"Å")
1296 ("varepsilon".
"ε")
1309 ("sigmaf") ("varsigma".
"ς")
1317 ("thetasym") ("vartheta".
"ϑ")
1320 ("bull") ("bullet".
"•")
1321 ("hellip") ("dots".
"…")
1331 ("larr") ("leftarrow".
"←") ("gets".
"←")
1332 ("uarr") ("uparrow".
"↑")
1333 ("rarr") ("to".
"→") ("rightarrow".
"→")
1334 ("darr")("downarrow".
"↓")
1335 ("harr") ("leftrightarrow".
"↔")
1336 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1337 ("lArr") ("Leftarrow".
"⇐")
1338 ("uArr") ("Uparrow".
"⇑")
1339 ("rArr") ("Rightarrow".
"⇒")
1340 ("dArr") ("Downarrow".
"⇓")
1341 ("hArr") ("Leftrightarrow".
"⇔")
1343 ("part") ("partial".
"∂")
1344 ("exist") ("exists".
"∃")
1345 ("empty") ("emptyset".
"∅")
1347 ("isin") ("in".
"∈")
1353 ("lowast") ("ast".
"∗")
1355 ("prop") ("proptp".
"∝")
1356 ("infin") ("infty".
"∞")
1357 ("ang") ("angle".
"∠")
1358 ("and") ("wedge".
"∧")
1359 ("or") ("vee".
"∨")
1365 ("cong") ("simeq".
"≅")
1366 ("asymp")("approx".
"≈")
1367 ("ne") ("neq".
"≠")
1371 ("sub") ("subset".
"⊂")
1372 ("sup") ("supset".
"⊃")
1379 ("sdot") ("cdot".
"⋅")
1386 ("loz") ("Diamond".
"◊")
1387 ("spades") ("spadesuit".
"♠")
1388 ("clubs") ("clubsuit".
"♣")
1389 ("hearts") ("diamondsuit".
"♥")
1390 ("diams") ("diamondsuit".
"♦")
1391 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1458 "Entities for TeX->HTML translation.
1459 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1460 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1461 In that case, \"\\ent\" will be translated to \"&other;\".
1462 The list contains HTML entities for Latin-1, Greek and other symbols.
1463 It is supplemented by a number of commonly used TeX macros with appropriate
1464 translations. There is currently no way for users to extend this.")
1466 ;;; General functions for all backends
1468 (defvar org-export-target-aliases nil
1469 "Alist of targets with invisible aliases.")
1470 (defvar org-export-code-refs nil
1471 "Alist of code references and line numbers")
1473 (defun org-export-preprocess-string (string &rest parameters
)
1474 "Cleanup STRING so that that the true exported has a more consistent source.
1475 This function takes STRING, which should be a buffer-string of an org-file
1476 to export. It then creates a temporary buffer where it does its job.
1477 The result is then again returned as a string, and the exporter works
1478 on this string to produce the exported version."
1480 (let* ((htmlp (plist-get parameters
:for-html
))
1481 (asciip (plist-get parameters
:for-ascii
))
1482 (latexp (plist-get parameters
:for-LaTeX
))
1483 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1485 (archived-trees (plist-get parameters
:archived-trees
))
1486 (inhibit-read-only t
)
1487 (drawers org-drawers
)
1488 (outline-regexp "\\*+ ")
1491 (setq org-export-target-aliases nil
)
1492 (setq org-export-code-refs nil
)
1494 (with-current-buffer (get-buffer-create " org-mode-tmp")
1497 (setq case-fold-search t
)
1499 ;; Remove license-to-kill stuff
1500 ;; The caller marks some stuff for killing, stuff that has been
1501 ;; used to create the page title, for example.
1502 (org-export-kill-licensed-text)
1504 (let ((org-inhibit-startup t
)) (org-mode))
1505 (setq case-fold-search t
)
1508 (run-hooks 'org-export-preprocess-hook
)
1510 (untabify (point-min) (point-max))
1512 ;; Handle include files, and call a hook
1513 (org-export-handle-include-files)
1514 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1516 ;; Get rid of archived trees
1517 (org-export-remove-archived-trees archived-trees
)
1519 ;; Remove comment environment and comment subtrees
1520 (org-export-remove-comment-blocks-and-subtrees)
1522 ;; Get rid of excluded trees, and call a hook
1523 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1524 (plist-get parameters
:exclude-tags
))
1525 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1527 ;; Handle source code snippets
1528 (org-export-replace-src-segments-and-examples backend
)
1530 ;; Normalize footnotes
1531 (when (plist-get parameters
:footnotes
)
1532 (org-footnote-normalize nil t
))
1534 ;; Find all headings and compute the targets for them
1535 (setq target-alist
(org-export-define-heading-targets target-alist
))
1537 ;; Get rid of drawers
1538 (org-export-remove-or-extract-drawers drawers
1539 (plist-get parameters
:drawers
))
1541 ;; Get the correct stuff before the first headline
1542 (when (plist-get parameters
:skip-before-1st-heading
)
1543 (goto-char (point-min))
1544 (when (re-search-forward "\\(^#.*\n\\)^\\*+[ \t]" nil t
)
1545 (delete-region (point-min) (match-beginning 0))
1546 (goto-char (point-min))
1548 (when (plist-get parameters
:add-text
)
1549 (goto-char (point-min))
1550 (insert (plist-get parameters
:add-text
) "\n"))
1552 ;; Remove todo-keywords before exporting, if the user has requested so
1553 (org-export-remove-headline-metadata parameters
)
1555 ;; Find targets in comments and move them out of comments,
1556 ;; but mark them as targets that should be invisible
1557 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1559 ;; Protect short examples
1560 (org-export-protect-colon-examples)
1562 ;; Protect backend specific stuff, throw away the others.
1563 (org-export-select-backend-specific-text backend
)
1565 ;; Protect quoted subtrees
1566 (org-export-protect-quoted-subtrees)
1568 ;; Protect verbatim elements
1569 (org-export-protect-verbatim)
1571 ;; Blockquotes and verse
1572 (org-export-mark-blockquote-and-verse)
1574 ;; Attach captions to the correct object
1575 (setq target-alist
(org-export-attach-captions-and-attributes
1576 backend target-alist
))
1578 ;; Find matches for radio targets and turn them into internal links
1579 (org-export-mark-radio-links)
1581 ;; Find all links that contain a newline and put them into a single line
1582 (org-export-concatenate-multiline-links)
1584 ;; Normalize links: Convert angle and plain links into bracket links
1585 ;; and expand link abbreviations
1586 (org-export-normalize-links)
1588 ;; Find all internal links. If they have a fuzzy match (i.e. not
1589 ;; a *dedicated* target match, let the link point to the
1590 ;; corresponding section.
1591 (org-export-target-internal-links target-alist
)
1593 ;; Find multiline emphasis and put them into single line
1594 (when (plist-get parameters
:emph-multiline
)
1595 (org-export-concatenate-multiline-emphasis))
1597 ;; Remove special table lines
1598 (when org-export-table-remove-special-lines
1599 (org-export-remove-special-table-lines))
1602 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1604 ;; Specific LaTeX stuff
1606 (require 'org-export-latex nil
)
1607 (org-export-latex-preprocess))
1609 ;; Specific ASCII stuff
1611 (org-export-ascii-preprocess))
1613 ;; Specific HTML stuff
1615 (org-export-html-preprocess parameters
))
1617 ;; Remove or replace comments
1618 (org-export-handle-comments (plist-get parameters
:comments
))
1620 ;; Run the final hook
1621 (run-hooks 'org-export-preprocess-final-hook
)
1623 (setq rtn
(buffer-string)))
1624 (kill-buffer " org-mode-tmp")
1627 (defun org-export-kill-licensed-text ()
1628 "Remove all text that is marked with a :org-license-to-kill property."
1630 (while (setq p
(text-property-any (point-min) (point-max)
1631 :org-license-to-kill t
))
1633 p
(or (next-single-property-change p
:org-license-to-kill
)
1636 (defun org-export-define-heading-targets (target-alist)
1637 "Find all headings and define the targets for them.
1638 The new targets are added to TARGET-ALIST, which is also returned."
1639 (goto-char (point-min))
1640 (org-init-section-numbers)
1641 (let ((re (concat "^" org-outline-regexp
1642 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1644 (while (re-search-forward re nil t
)
1646 (push (cons (org-match-string-no-properties 1)
1647 target
) target-alist
)
1648 (setq level
(org-reduced-level
1649 (save-excursion (goto-char (point-at-bol))
1650 (org-outline-level))))
1651 (setq target
(org-solidify-link-text
1652 (format "sec-%s" (org-section-number level
))))
1653 (push (cons target target
) target-alist
)
1654 (add-text-properties
1655 (point-at-bol) (point-at-eol)
1656 (list 'target target
)))))
1659 (defun org-export-handle-invisible-targets (target-alist)
1660 "Find targets in comments and move them out of comments.
1661 Mark them as invisible targets."
1663 (goto-char (point-min))
1664 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1665 ;; Check if the line before or after is a headline with a target
1666 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1667 (get-text-property (point-at-bol 2) 'target
)))
1669 ;; use the existing target in a neighboring line
1670 (setq tmp
(match-string 2))
1672 (and (looking-at "\n") (delete-char 1))
1673 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1675 (setq a
(or (assoc target org-export-target-aliases
)
1677 (push (list target
) org-export-target-aliases
)
1678 (car org-export-target-aliases
))))
1680 ;; Make an invisible target
1681 (replace-match "\\1(INVISIBLE)"))))
1684 (defun org-export-target-internal-links (target-alist)
1685 "Find all internal links and assign targets to them.
1686 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1687 let the link point to the corresponding section.
1688 This function also handles the id links, if they have a match in
1690 (goto-char (point-min))
1691 (while (re-search-forward org-bracket-link-regexp nil t
)
1693 (let* ((md (match-data))
1694 (desc (match-end 2))
1695 (link (org-link-unescape (match-string 1)))
1696 (slink (org-solidify-link-text link
))
1697 found props pos cref
1700 ((cdr (assoc slink target-alist
)))
1701 ((and (string-match "^id:" link
)
1702 (cdr (assoc (substring link
3) target-alist
))))
1703 ((string-match "^((\\(.*\\)))$" link
)
1704 (setq cref
(match-string 1 link
))
1705 (concat "coderef:" cref
))
1706 ((string-match org-link-types-re link
) nil
)
1707 ((or (file-name-absolute-p link
)
1708 (string-match "^\\." link
))
1712 (setq found
(condition-case nil
(org-link-search link
)
1715 (or (org-on-heading-p)
1716 (not (eq found
'dedicated
))))
1717 (or (get-text-property (point) 'target
)
1720 (1- (or (previous-single-property-change
1721 (point) 'target
) 0)))
1725 (goto-char (match-beginning 1))
1726 (setq props
(text-properties-at (point)))
1727 (delete-region (match-beginning 1) (match-end 1))
1730 (unless desc
(insert "][" link
))
1731 (add-text-properties pos
(point) props
))))))
1733 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1734 "Remove drawers, or extract the content.
1735 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1736 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1737 whose content to keep."
1738 (unless (eq t exp-drawers
)
1739 (goto-char (point-min))
1740 (let ((re (concat "^[ \t]*:\\("
1743 (org-delete-all exp-drawers
1744 (copy-sequence all-drawers
))
1746 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1747 (while (re-search-forward re nil t
)
1748 (replace-match "")))))
1750 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1751 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1752 Both arguments are lists of tags.
1753 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1755 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1757 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1758 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1761 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1765 (goto-char (point-min))
1766 (when (and select-tags
1768 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1769 ;; At least one tree is marked for export, this means
1770 ;; all the unmarked stuff needs to go.
1771 ;; Dig out the trees that should be exported
1772 (goto-char (point-min))
1773 (outline-next-heading)
1775 (put-text-property beg
(point-max) :org-delete t
)
1776 (while (re-search-forward re-sel nil t
)
1777 (when (org-on-heading-p)
1778 (org-back-to-heading)
1779 (remove-text-properties
1780 (max (1- (point)) (point-min))
1781 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1783 (while (and (org-up-heading-safe)
1784 (get-text-property (point) :org-delete
))
1785 (remove-text-properties (max (1- (point)) (point-min))
1786 (point-at-eol) '(:org-delete t
)))
1788 ;; Remove the trees explicitly marked for noexport
1790 (goto-char (point-min))
1791 (while (re-search-forward re-excl nil t
)
1792 (when (org-at-heading-p)
1793 (org-back-to-heading t
)
1795 (org-end-of-subtree t
)
1796 (delete-region beg
(point)))))
1797 ;; Remove everything that is now still marked for deletion
1798 (goto-char (point-min))
1799 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1800 (setq end
(or (next-single-property-change beg
:org-delete
)
1802 (delete-region beg end
))))
1804 (defun org-export-remove-archived-trees (export-archived-trees)
1805 "Remove archived trees.
1806 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1807 When it is t, the entire archived tree will be exported.
1808 When it is nil the entire tree including the headline will be removed
1810 (let ((re-archive (concat ":" org-archive-tag
":"))
1812 (when (not (eq export-archived-trees t
))
1813 (goto-char (point-min))
1814 (while (re-search-forward re-archive nil t
)
1815 (if (not (org-on-heading-p t
))
1816 (org-end-of-subtree t
)
1817 (beginning-of-line 1)
1818 (setq a
(if export-archived-trees
1819 (1+ (point-at-eol)) (point))
1820 b
(org-end-of-subtree t
))
1821 (if (> b a
) (delete-region a b
)))))))
1823 (defun org-export-remove-headline-metadata (opts)
1824 "Remove meta data from the headline, according to user options."
1825 (let ((re org-complex-heading-regexp
)
1826 (todo (plist-get opts
:todo-keywords
))
1827 (tags (plist-get opts
:tags
))
1828 (pri (plist-get opts
:priority
))
1831 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1832 (when (or (not todo
) (not tags
) (not pri
))
1833 (goto-char (point-min))
1834 (while (re-search-forward re nil t
)
1835 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1837 (replace-match rpl t t
)))))
1839 (defun org-export-protect-quoted-subtrees ()
1840 "Mark quoted subtrees with the protection property."
1841 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1842 (goto-char (point-min))
1843 (while (re-search-forward re-quote nil t
)
1844 (goto-char (match-beginning 0))
1846 (add-text-properties (point) (org-end-of-subtree t
)
1847 '(org-protected t
)))))
1849 (defun org-export-protect-verbatim ()
1850 "Mark verbatim snippets with the protection property."
1851 (goto-char (point-min))
1852 (while (re-search-forward org-verbatim-re nil t
)
1853 (add-text-properties (match-beginning 4) (match-end 4)
1855 (goto-char (1+ (match-end 4)))))
1857 (defun org-export-protect-colon-examples ()
1858 "Protect lines starting with a colon."
1859 (goto-char (point-min))
1860 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1861 (add-text-properties (match-beginning 0) (match-end 0)
1862 '(org-protected t
))))
1864 (defun org-export-select-backend-specific-text (backend)
1866 '((html "HTML" "BEGIN_HTML" "END_HTML")
1867 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1868 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1869 (case-fold-search t
)
1873 (setq fmt
(pop formatters
))
1874 (when (eq (car fmt
) backend
)
1875 ;; This is selected code, put it into the file for real
1876 (goto-char (point-min))
1877 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1878 ":[ \t]*\\(.*\\)") nil t
)
1879 (replace-match "\\1" t
)
1880 (add-text-properties
1881 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1882 '(org-protected t
))))
1883 (goto-char (point-min))
1884 (while (re-search-forward
1886 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1887 (cadddr fmt
) "\\>.*\n?") nil t
)
1888 (if (eq (car fmt
) backend
)
1890 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1892 ;; No, this is for a different backend, kill it
1893 (delete-region (match-beginning 0) (match-end 0)))))))
1895 (defun org-export-mark-blockquote-and-verse ()
1896 "Mark block quote and verse environments with special cookies.
1897 These special cookies will later be interpreted by the backend."
1899 (goto-char (point-min))
1900 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1902 (replace-match (if (equal (downcase (match-string 1)) "end")
1903 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1906 (goto-char (point-min))
1907 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1908 (replace-match (if (equal (downcase (match-string 1)) "end")
1909 "ORG-VERSE-END" "ORG-VERSE-START")
1912 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1913 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1914 If the next thing following is a table, add the text properties to the first
1915 table line. If it is a link, add it to the line containing the link."
1916 (goto-char (point-min))
1917 (remove-text-properties (point-min) (point-max)
1918 '(org-caption nil org-attributes nil
))
1919 (let ((case-fold-search t
)
1920 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1922 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1924 "^#\\+label:[ \t]+\\(.*\\)"
1928 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1930 (while (re-search-forward re nil t
)
1933 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1935 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1937 (setq label
(org-trim (match-string 3))))
1939 (add-text-properties (point-at-bol) (point-at-eol)
1940 (list 'org-caption cap
1941 'org-attributes attr
1943 (if label
(push (cons label label
) target-alist
))
1944 (setq cap nil attr nil label nil
)))))
1947 (defun org-export-remove-comment-blocks-and-subtrees ()
1948 "Remove the comment environment, and also commented subtrees."
1949 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1950 (case-fold-search nil
))
1951 ;; Remove comment environment
1952 (goto-char (point-min))
1953 (while (re-search-forward
1954 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1955 (replace-match "" t t
))
1956 ;; Remove subtrees that are commented
1957 (goto-char (point-min))
1958 (while (re-search-forward re-commented nil t
)
1959 (goto-char (match-beginning 0))
1960 (delete-region (point) (org-end-of-subtree t
)))))
1962 (defun org-export-handle-comments (commentsp)
1963 "Remove comments, or convert to backend-specific format.
1964 COMMENTSP can be a format string for publishing comments.
1965 When it is nil, all comments will be removed."
1966 (let ((re "^#\\(.*\n?\\)")
1968 (goto-char (point-min))
1969 (while (or (looking-at re
)
1970 (re-search-forward re nil t
))
1971 (setq pos
(match-beginning 0))
1973 (progn (add-text-properties
1974 (match-beginning 0) (match-end 0) '(org-protected t
))
1975 (replace-match (format commentsp
(match-string 1)) t t
))
1976 (goto-char (1+ pos
))
1979 (goto-char (max (point-min) (1- pos
))))))))
1981 (defun org-export-mark-radio-links ()
1982 "Find all matches for radio targets and turn them into internal links."
1983 (let ((re-radio (and org-target-link-regexp
1984 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
1985 (goto-char (point-min))
1987 (while (re-search-forward re-radio nil t
)
1989 (replace-match "\\1[[\\2]]"))))))
1991 (defun org-export-remove-special-table-lines ()
1992 "Remove tables lines that are used for internal purposes."
1993 (goto-char (point-min))
1994 (while (re-search-forward "^[ \t]*|" nil t
)
1995 (beginning-of-line 1)
1996 (if (or (looking-at "[ \t]*| *[!_^] *|")
1997 (and (looking-at ".*?| *<[0-9]+> *|")
1998 (not (looking-at ".*?| *[^ <|]"))))
1999 (delete-region (max (point-min) (1- (point-at-bol)))
2003 (defun org-export-normalize-links ()
2004 "Convert all links to bracket links, and expand link abbreviations."
2005 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2006 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2007 (goto-char (point-min))
2008 (while (re-search-forward re-plain-link nil t
)
2009 (goto-char (1- (match-end 0)))
2011 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2012 ":" (match-string 3) "]]")))
2013 ;; added 'org-link face to links
2014 (put-text-property 0 (length s
) 'face
'org-link s
)
2015 (replace-match s t t
))))
2016 (goto-char (point-min))
2017 (while (re-search-forward re-angle-link nil t
)
2018 (goto-char (1- (match-end 0)))
2020 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2021 ":" (match-string 3) "]]")))
2022 (put-text-property 0 (length s
) 'face
'org-link s
)
2023 (replace-match s t t
))))
2024 (goto-char (point-min))
2025 (while (re-search-forward org-bracket-link-regexp nil t
)
2026 (goto-char (1- (match-end 0)))
2028 (let* ((xx (save-match-data
2030 (org-link-expand-abbrev (match-string 1)))))
2035 (concat "[" xx
"]"))
2037 (put-text-property 0 (length s
) 'face
'org-link s
)
2038 (replace-match s t t
))))))
2040 (defun org-export-concatenate-multiline-links ()
2041 "Find multi-line links and put it all into a single line.
2042 This is to make sure that the line-processing export backends
2043 can work correctly."
2044 (goto-char (point-min))
2045 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2047 (replace-match "\\1 \\3")
2048 (goto-char (match-beginning 0)))))
2050 (defun org-export-concatenate-multiline-emphasis ()
2051 "Find multi-line emphasis and put it all into a single line.
2052 This is to make sure that the line-processing export backends
2053 can work correctly."
2054 (goto-char (point-min))
2055 (while (re-search-forward org-emph-re nil t
)
2056 (if (not (= (char-after (match-beginning 3))
2057 (char-after (match-beginning 4))))
2059 (subst-char-in-region (match-beginning 0) (match-end 0)
2061 (goto-char (1- (match-end 0))))
2062 (goto-char (1+ (match-beginning 0))))))
2064 (defun org-export-grab-title-from-buffer ()
2065 "Get a title for the current document, from looking at the buffer."
2066 (let ((inhibit-read-only t
))
2068 (goto-char (point-min))
2069 (let ((end (if (looking-at org-outline-regexp
)
2071 (save-excursion (outline-next-heading) (point)))))
2072 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2073 ;; Mark the line so that it will not be exported as normal text.
2075 (add-text-properties (match-beginning 0) (match-end 0)
2076 (list :org-license-to-kill t
)))
2077 ;; Return the title string
2078 (org-trim (match-string 0)))))))
2080 (defun org-export-get-title-from-subtree ()
2081 "Return subtree title and exclude it from export."
2082 (let (title (m (mark)) (rbeg (region-beginning)) (rend (region-end)))
2085 (when (and (org-at-heading-p)
2086 (>= (org-end-of-subtree t t
) rend
))
2087 ;; This is a subtree, we take the title from the first heading
2089 (looking-at org-todo-line-regexp
)
2090 (setq title
(match-string 3))
2092 (add-text-properties (point) (1+ (point-at-eol))
2093 (list :org-license-to-kill t
)))
2094 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2097 (defun org-solidify-link-text (s &optional alist
)
2098 "Take link text and make a safe target out of it."
2103 (org-split-string s
"[ \t\r\n]+") "=="))
2104 (a (assoc rtn alist
)))
2107 (defun org-get-min-level (lines)
2108 "Get the minimum level in LINES."
2109 (let ((re "^\\(\\*+\\) ") l min
)
2111 (while (setq l
(pop lines
))
2112 (if (string-match re l
)
2113 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
2116 ;; Variable holding the vector with section numbers
2117 (defvar org-section-numbers
(make-vector org-level-max
0))
2119 (defun org-init-section-numbers ()
2120 "Initialize the vector for the section numbers."
2122 (numbers (nreverse (org-split-string "" "\\.")))
2123 (depth (1- (length org-section-numbers
)))
2124 (i depth
) number-string
)
2127 (aset org-section-numbers i
0)
2128 (setq number-string
(or (car numbers
) "0"))
2129 (if (string-match "\\`[A-Z]\\'" number-string
)
2130 (aset org-section-numbers i
2131 (- (string-to-char number-string
) ?A -
1))
2132 (aset org-section-numbers i
(string-to-number number-string
)))
2136 (defun org-section-number (&optional level
)
2137 "Return a string with the current section number.
2138 When LEVEL is non-nil, increase section numbers on that level."
2139 (let* ((depth (1- (length org-section-numbers
)))
2141 (fmts (car org-export-section-number-format
))
2142 (term (cdr org-export-section-number-format
))
2147 (aset org-section-numbers
2148 level
(1+ (aref org-section-numbers level
))))
2149 (setq idx
(1+ level
))
2150 (while (<= idx depth
)
2152 (aset org-section-numbers idx
0))
2153 (setq idx
(1+ idx
))))
2155 (while (<= idx depth
)
2156 (when (> (aref org-section-numbers idx
) 0)
2157 (setq fmt
(or (pop fmts
) fmt
)
2159 n
(aref org-section-numbers idx
)
2161 (concat string sep
(org-number-to-counter n ctype
))
2162 (concat string
".0"))
2164 (setq idx
(1+ idx
)))
2166 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2167 (setq string
(replace-match "" t nil string
)))
2168 (if (string-match "\\(\\.0\\)+\\'" string
)
2169 (setq string
(replace-match "" t nil string
))))
2170 (concat string term
)))
2172 (defun org-number-to-counter (n type
)
2173 "Concert number N to a string counter, according to TYPE.
2174 TYPE must be a string, any of:
2178 I upper case roman numeral
2179 i lower case roman numeral"
2181 ((equal type
"1") (number-to-string n
))
2182 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2183 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2184 ((equal type
"I") (org-number-to-roman n
))
2185 ((equal type
"i") (downcase (org-number-to-roman n
)))
2186 (t (error "Invalid counter type `%s'" type
))))
2188 (defun org-number-to-roman (n)
2189 "Convert integer N into a roman numeral."
2190 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2191 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2192 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2196 (number-to-string n
)
2198 (if (>= n
(caar roman
))
2199 (setq n
(- n
(caar roman
))
2200 res
(concat res
(cdar roman
)))
2204 (org-number-to-roman 1961)
2209 (defun org-export-handle-include-files ()
2210 "Include the contents of include files, with proper formatting."
2211 (let ((case-fold-search t
)
2212 params file markup lang start end prefix prefix1
)
2213 (goto-char (point-min))
2214 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2215 (setq params
(read (concat "(" (match-string 1) ")"))
2216 prefix
(org-get-and-remove-property 'params
:prefix
)
2217 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2218 file
(org-symname-or-string (pop params
))
2219 markup
(org-symname-or-string (pop params
))
2220 lang
(org-symname-or-string (pop params
)))
2221 (delete-region (match-beginning 0) (match-end 0))
2223 (not (file-exists-p file
))
2224 (not (file-readable-p file
)))
2225 (insert (format "CANNOT INCLUDE FILE %s" file
))
2227 (if (equal (downcase markup
) "src")
2228 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
2230 (setq start
(format "#+begin_%s\n" markup
)
2231 end
(format "#+end_%s" markup
))))
2232 (insert (or start
""))
2233 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2234 (or (bolp) (newline))
2235 (insert (or end
""))))))
2237 (defun org-get-file-contents (file &optional prefix prefix1
)
2238 "Get the contents of FILE and return them as a string.
2239 If PREFIX is a string, prepend it to each line. If PREFIX1
2240 is a string, prepend it to the first line instead of PREFIX."
2242 (insert-file-contents file
)
2243 (when (or prefix prefix1
)
2244 (goto-char (point-min))
2246 (insert (or prefix1 prefix
))
2248 (beginning-of-line 2)))
2251 (defun org-get-and-remove-property (listvar prop
)
2252 "Check if the value of LISTVAR contains PROP as a property.
2253 If yes, return the value of that property (i.e. the element following
2254 in the list) and remove property and value from the list in LISTVAR."
2255 (let ((list (symbol-value listvar
)) m v
)
2256 (when (setq m
(member prop list
))
2258 (if (equal (car list
) prop
)
2259 (set listvar
(cddr list
))
2260 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2262 (set listvar list
)))
2265 (defun org-symname-or-string (s)
2267 (if s
(symbol-name s
) s
)
2270 ;;; Fontification and line numbers for code examples
2272 (defvar org-export-last-code-line-counter-value
0)
2274 ;; Currently only for the HTML backend, but who knows....
2275 (defun org-export-replace-src-segments-and-examples (backend)
2276 "Replace source code segments with special code for export."
2277 (setq org-export-last-code-line-counter-value
0)
2278 (let ((case-fold-search t
)
2279 lang code trans opts
)
2280 (goto-char (point-min))
2281 (while (re-search-forward
2282 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2286 (setq lang
(match-string 2)
2287 opts
(match-string 3)
2288 code
(match-string 4))
2290 opts
(match-string 6)
2291 code
(match-string 7)))
2293 (setq trans
(org-export-format-source-code-or-example
2294 backend lang code opts
))
2295 (replace-match trans t t
))))
2297 (defvar htmlp
) ;; dynamically scoped
2298 (defvar latexp
) ;; dynamically scoped
2300 (defun org-export-format-source-code-or-example (backend
2301 lang code
&optional opts
)
2302 "Format CODE from language LANG and return it formatted for export.
2303 If LANG is nil, do not add any fontification.
2304 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2305 and `+n' for continuing previous numering.
2306 Code formatting according to language currently only works for HTML.
2307 Numbering lines works for all three major backends (html, latex, and ascii)."
2309 (let (num cont rtn named rpllbl keepp
)
2310 (setq num
(string-match "[-+]n\\>" (or opts
""))
2311 cont
(string-match "\\+n\\>" (or opts
""))
2312 rpllbl
(string-match "-r\\>" (or opts
""))
2313 keepp
(string-match "-k\\>" (or opts
"")))
2314 (if keepp
(setq rpllbl
'keep
))
2316 (when (equal lang
"org")
2317 (setq rtn
(with-temp-buffer
2319 ;; Free up the protected lines
2320 (goto-char (point-min))
2321 (while (re-search-forward "^," nil t
)
2325 ;; Now backend-specific coding
2328 ;; We are exporting to HTML
2330 (require 'htmlize nil t
)
2331 (when (not (fboundp 'htmlize-region-for-paste
))
2332 ;; we do not have htmlize.el, or an old version of it
2334 "htmlize.el 1.34 or later is needed for source code formatting")))
2337 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2338 (org-inhibit-startup t
)
2339 (org-startup-folded nil
))
2343 (if (functionp mode
)
2346 (font-lock-fontify-buffer)
2347 (org-export-htmlize-region-for-paste
2348 (point-min) (point-max))))
2349 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2350 (setq rtn
(replace-match
2351 (format "<pre class=\"src src-%s\">\n" lang
)
2353 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n")))
2354 (setq rtn
(org-export-number-lines rtn
'html
1 1 num cont rpllbl
))
2355 (concat "\n#+BEGIN_HTML\n" rtn
"\n#+END_HTML\n\n"))
2356 ((eq backend
'latex
)
2357 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl
))
2358 (concat "\n#+BEGIN_LaTeX\n\\begin{verbatim}\n" rtn
2359 "\n\\end{verbatim}\n#+END_LaTeX\n\n"))
2360 ((eq backend
'ascii
)
2361 ;; This is not HTML or LaTeX, so just make it an example.
2362 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl
))
2363 (concat "#+BEGIN_ASCII\n"
2365 (lambda (l) (concat " " l
))
2366 (org-split-string rtn
"\n")
2368 "\n#+END_ASCII\n"))))))
2370 (defun org-export-number-lines (text backend
2371 &optional skip1 skip2 number cont
2373 (if (and (not number
) (not (eq replace-labels
'keep
)))
2374 (setq replace-labels nil
)) ;; must use names if no numbers
2375 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2376 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2379 (goto-char (point-max))
2380 (skip-chars-backward " \t\n\r")
2381 (delete-region (point) (point-max))
2382 (beginning-of-line (- 1 skip2
))
2383 (let* ((last (org-current-line))
2384 (n org-export-last-code-line-counter-value
)
2385 (nmax (+ n
(- last skip1
)))
2386 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2389 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2391 ((eq backend
'ascii
) fmt
)
2392 ((eq backend
'latex
) fmt
)
2396 (goto-line (1+ skip1
))
2397 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2399 (insert (format fm
(incf n
)))
2401 (when (and (not (eq replace-labels
'keep
))
2402 (looking-at ".*?\\([ \t]+\\(((\\(.*?\\)))\\)\\)"))
2403 (setq ref
(match-string 3))
2406 (delete-region (match-beginning 1) (match-end 1))
2407 (push (cons ref n
) org-export-code-refs
))
2408 (goto-char (match-beginning 2))
2409 (delete-region (match-beginning 2) (match-end 2))
2410 (insert "(" ref
")")
2411 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2412 (when (eq backend
'html
)
2414 (beginning-of-line 1)
2415 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2418 (insert "</span>")))))
2419 (setq org-export-last-code-line-counter-value n
)
2420 (goto-char (point-max))
2426 (defvar org-last-level nil
) ; dynamically scoped variable
2427 (defvar org-min-level nil
) ; dynamically scoped variable
2428 (defvar org-levels-open nil
) ; dynamically scoped parameter
2429 (defvar org-ascii-current-indentation nil
) ; For communication
2432 (defun org-export-as-ascii (arg)
2433 "Export the outline as a pretty ASCII file.
2434 If there is an active region, export only the region.
2435 The prefix ARG specifies how many levels of the outline should become
2436 underlined headlines. The default is 3."
2438 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2439 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2440 (org-infile-export-plist)))
2441 (region-p (org-region-active-p))
2442 (rbeg (and region-p
(region-beginning)))
2443 (rend (and region-p
(region-end)))
2448 (and (org-at-heading-p)
2449 (>= (org-end-of-subtree t t
) rend
)))))
2450 (opt-plist (if subtree-p
2451 (org-export-add-subtree-options opt-plist rbeg
)
2453 (custom-times org-display-custom-times
)
2454 (org-ascii-current-indentation '(0 .
0))
2458 (case-fold-search nil
)
2459 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2460 (filename (concat (file-name-as-directory
2461 (org-export-directory :ascii opt-plist
))
2462 (file-name-sans-extension
2464 (org-entry-get (region-beginning)
2465 "EXPORT_FILE_NAME" t
))
2466 (file-name-nondirectory bfname
)))
2468 (filename (if (equal (file-truename filename
)
2469 (file-truename bfname
))
2470 (concat filename
".txt")
2472 (buffer (find-file-noselect filename
))
2473 (org-levels-open (make-vector org-level-max nil
))
2474 (odd org-odd-levels-only
)
2475 (date (plist-get opt-plist
:date
))
2476 (author (plist-get opt-plist
:author
))
2477 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2478 (plist-get opt-plist
:title
)
2480 (plist-get opt-plist
:skip-before-1st-heading
))
2481 (org-export-grab-title-from-buffer))
2482 (file-name-sans-extension
2483 (file-name-nondirectory bfname
))))
2484 (email (plist-get opt-plist
:email
))
2485 (language (plist-get opt-plist
:language
))
2486 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2487 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2492 (if (org-region-active-p) (region-beginning) (point-min))
2493 (if (org-region-active-p) (region-end) (point-max))))
2494 (lines (org-split-string
2495 (org-export-preprocess-string
2498 :skip-before-1st-heading
2499 (plist-get opt-plist
:skip-before-1st-heading
)
2500 :drawers
(plist-get opt-plist
:drawers
)
2501 :tags
(plist-get opt-plist
:tags
)
2502 :priority
(plist-get opt-plist
:priority
)
2503 :footnotes
(plist-get opt-plist
:footnotes
)
2504 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2505 :verbatim-multiline t
2506 :select-tags
(plist-get opt-plist
:select-tags
)
2507 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2509 (plist-get opt-plist
:archived-trees
)
2510 :add-text
(plist-get opt-plist
:text
))
2512 thetoc have-headings first-heading-pos
2513 table-open table-buffer link desc
)
2515 (let ((inhibit-read-only t
))
2517 (remove-text-properties (point-min) (point-max)
2518 '(:org-license-to-kill t
))))
2520 (setq org-min-level
(org-get-min-level lines
))
2521 (setq org-last-level org-min-level
)
2522 (org-init-section-numbers)
2524 (find-file-noselect filename
)
2526 (setq lang-words
(or (assoc language org-export-language-setup
)
2527 (assoc "en" org-export-language-setup
)))
2528 (switch-to-buffer-other-window buffer
)
2531 ;; create local variables for all options, to make sure all called
2532 ;; functions get the correct information
2534 (set (make-local-variable (nth 2 x
))
2535 (plist-get opt-plist
(car x
))))
2536 org-export-plist-vars
)
2537 (org-set-local 'org-odd-levels-only odd
)
2538 (setq umax
(if arg
(prefix-numeric-value arg
)
2539 org-export-headline-levels
))
2540 (setq umax-toc
(if (integerp org-export-with-toc
)
2541 (min org-export-with-toc umax
)
2545 (if title
(org-insert-centered title ?
=))
2547 (if (and (or author email
)
2548 org-export-author-info
)
2549 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2550 (if email
(concat " <" email
">") "")
2554 ((and date
(string-match "%" date
))
2555 (setq date
(format-time-string date
)))
2557 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2559 (if (and date org-export-time-stamp-file
)
2560 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2564 (if org-export-with-toc
2566 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2567 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2569 (mapc '(lambda (line)
2570 (if (string-match org-todo-line-regexp
2572 ;; This is a headline
2574 (setq have-headings t
)
2575 (setq level
(- (match-end 1) (match-beginning 1))
2576 level
(org-tr-level level
)
2577 txt
(match-string 3 line
)
2579 (or (and org-export-mark-todo-in-toc
2581 (not (member (match-string 2 line
)
2582 org-done-keywords
)))
2584 (and org-export-mark-todo-in-toc
2586 (org-search-todo-below
2587 line lines level
))))
2588 (setq txt
(org-html-expand-for-ascii txt
))
2590 (while (string-match org-bracket-link-regexp txt
)
2593 (match-string (if (match-end 2) 3 1) txt
)
2596 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2598 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2600 (setq txt
(replace-match "" t t txt
)))
2601 (if (string-match quote-re0 txt
)
2602 (setq txt
(replace-match "" t t txt
)))
2604 (if org-export-with-section-numbers
2605 (setq txt
(concat (org-section-number level
)
2607 (if (<= level umax-toc
)
2612 (* (max 0 (- level org-min-level
)) 4) ?\
)
2613 (format (if todo
"%s (*)\n" "%s\n") txt
))
2615 (setq org-last-level level
))
2618 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2620 (org-init-section-numbers)
2621 (while (setq line
(pop lines
))
2622 ;; Remove the quoted HTML tags.
2623 (setq line
(org-html-expand-for-ascii line
))
2624 ;; Replace links with the description when possible
2625 (while (string-match org-bracket-link-regexp line
)
2626 (setq link
(match-string 1 line
)
2627 desc
(match-string (if (match-end 3) 3 1) line
))
2628 (if (and (> (length link
) 8)
2629 (equal (substring link
0 8) "coderef:"))
2630 (setq line
(replace-match
2631 (format (org-export-get-coderef-format (substring link
8) desc
)
2634 org-export-code-refs
)))
2636 (setq line
(replace-match
2637 (if (match-end 3) "[\\3]" "[\\1]")
2640 (setq line
(org-translate-time line
)))
2642 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2644 (setq first-heading-pos
(or first-heading-pos
(point)))
2645 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2646 txt
(match-string 2 line
))
2647 (org-ascii-level-start level txt umax lines
))
2649 ((and org-export-with-tables
2650 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2651 (if (not table-open
)
2653 (setq table-open t table-buffer nil
))
2655 (setq table-buffer
(cons line table-buffer
))
2656 (when (or (not lines
)
2657 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2659 (setq table-open nil
2660 table-buffer
(nreverse table-buffer
))
2663 (org-fix-indentation x org-ascii-current-indentation
))
2664 (org-format-table-ascii table-buffer
)
2667 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2668 ;; Remove forced line breaks
2669 (if (string-match "\\\\\\\\[ \t]*$" line
)
2670 (setq line
(replace-match "" t t line
)))
2671 (if (and org-export-with-fixed-width
2672 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
2673 (setq line
(replace-match "\\1" nil nil line
)))
2674 (insert line
"\n"))))
2678 ;; insert the table of contents
2680 (goto-char (point-min))
2681 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2683 (goto-char (match-beginning 0))
2685 (goto-char first-heading-pos
))
2686 (mapc 'insert thetoc
)
2687 (or (looking-at "[ \t]*\n[ \t]*\n")
2690 ;; Convert whitespace place holders
2691 (goto-char (point-min))
2693 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2694 (setq end
(next-single-property-change beg
'org-whitespace
))
2696 (delete-region beg end
)
2697 (insert (make-string (- end beg
) ?\
))))
2700 ;; remove display and invisible chars
2702 (goto-char (point-min))
2703 (while (setq beg
(next-single-property-change (point) 'display
))
2704 (setq end
(next-single-property-change beg
'display
))
2705 (delete-region beg end
)
2708 (goto-char (point-min))
2709 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2710 (setq end
(next-single-property-change beg
'org-cwidth
))
2711 (delete-region beg end
)
2713 (goto-char (point-min))))
2715 (defun org-export-ascii-preprocess ()
2716 "Do extra work for ASCII export"
2717 ;; Put quotes around verbatim text
2718 (goto-char (point-min))
2719 (while (re-search-forward org-verbatim-re nil t
)
2720 (goto-char (match-end 2))
2721 (backward-delete-char 1) (insert "'")
2722 (goto-char (match-beginning 2))
2723 (delete-char 1) (insert "`")
2724 (goto-char (match-end 2)))
2725 (goto-char (point-min))
2726 ;; Remove target markers
2727 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2728 (replace-match "\\1\\2")))
2730 (defun org-search-todo-below (line lines level
)
2731 "Search the subtree below LINE for any TODO entries."
2732 (let ((rest (cdr (memq line lines
)))
2733 (re org-todo-line-regexp
)
2736 (while (setq line
(pop rest
))
2737 (if (string-match re line
)
2739 (setq lv
(- (match-end 1) (match-beginning 1))
2740 todo
(and (match-beginning 2)
2741 (not (member (match-string 2 line
)
2742 org-done-keywords
))))
2744 (if (<= lv level
) (throw 'exit nil
))
2745 (if todo
(throw 'exit t
))))))))
2747 (defun org-html-expand-for-ascii (line)
2748 "Handle quoted HTML for ASCII export."
2749 (if org-export-html-expand
2750 (while (string-match "@<[^<>\n]*>" line
)
2751 ;; We just remove the tags for now.
2752 (setq line
(replace-match "" nil nil line
))))
2755 (defun org-insert-centered (s &optional underline
)
2756 "Insert the string S centered and underline it with character UNDERLINE."
2757 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2758 (insert (make-string ind ?\
) s
"\n")
2760 (insert (make-string ind ?\
)
2761 (make-string (string-width s
) underline
)
2764 (defun org-ascii-level-start (level title umax
&optional lines
)
2765 "Insert a new level in ASCII export."
2766 (let (char (n (- level umax
1)) (ind 0))
2769 (insert (make-string (* 2 n
) ?\
)
2770 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2771 org-export-ascii-bullets
))
2773 ;; find the indentation of the next non-empty line
2776 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2777 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2778 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2780 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2781 (if (or (not (equal (char-before) ?
\n))
2782 (not (equal (char-before (1- (point))) ?
\n)))
2784 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2785 (unless org-export-with-tags
2786 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2787 (setq title
(replace-match "" t t title
))))
2788 (if org-export-with-section-numbers
2789 (setq title
(concat (org-section-number level
) " " title
)))
2790 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2791 (setq org-ascii-current-indentation
'(0 .
0)))))
2794 (defun org-export-visible (type arg
)
2795 "Create a copy of the visible part of the current buffer, and export it.
2796 The copy is created in a temporary buffer and removed after use.
2797 TYPE is the final key (as a string) that also select the export command in
2798 the `C-c C-e' export dispatcher.
2799 As a special case, if the you type SPC at the prompt, the temporary
2800 org-mode file will not be removed but presented to you so that you can
2801 continue to use it. The prefix arg ARG is passed through to the exporting
2805 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2806 (read-char-exclusive))
2807 current-prefix-arg
))
2808 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2809 (error "Invalid export key"))
2810 (let* ((binding (cdr (assoc type
2811 '((?a . org-export-as-ascii
)
2812 (?\C-a . org-export-as-ascii
)
2813 (?b . org-export-as-html-and-open
)
2814 (?\C-b . org-export-as-html-and-open
)
2815 (?h . org-export-as-html
)
2816 (?H . org-export-as-html-to-buffer
)
2817 (?R . org-export-region-as-html
)
2818 (?x . org-export-as-xoxo
)))))
2819 (keepp (equal type ?\
))
2820 (file buffer-file-name
)
2821 (buffer (get-buffer-create "*Org Export Visible*"))
2823 ;; Need to hack the drawers here.
2825 (goto-char (point-min))
2826 (while (re-search-forward org-drawer-regexp nil t
)
2827 (goto-char (match-beginning 1))
2828 (or (org-invisible-p) (org-flag-drawer nil
))))
2829 (with-current-buffer buffer
(erase-buffer))
2831 (setq s
(goto-char (point-min)))
2832 (while (not (= (point) (point-max)))
2833 (goto-char (org-find-invisible))
2834 (append-to-buffer buffer s
(point))
2835 (setq s
(goto-char (org-find-visible))))
2836 (org-cycle-hide-drawers 'all
)
2837 (goto-char (point-min))
2839 ;; Copy all comment lines to the end, to make sure #+ settings are
2840 ;; still available for the second export step. Kind of a hack, but
2841 ;; does do the trick.
2842 (if (looking-at "#[^\r\n]*")
2843 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2844 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2845 (append-to-buffer buffer
(1+ (match-beginning 0))
2846 (min (point-max) (1+ (match-end 0))))))
2848 (let ((buffer-file-name file
)
2849 (org-inhibit-startup t
))
2852 (unless keepp
(funcall binding arg
))))
2854 (kill-buffer buffer
)
2855 (switch-to-buffer-other-window buffer
)
2856 (goto-char (point-min)))))
2858 (defun org-find-visible ()
2860 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2861 (get-char-property s
'invisible
)))
2863 (defun org-find-invisible ()
2865 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2866 (not (get-char-property s
'invisible
))))
2871 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2872 (defun org-get-current-options ()
2873 "Return a string with current options as keyword options.
2874 Does include HTML export options as well as TODO and CATEGORY stuff."
2875 (require 'org-archive
)
2882 #+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
2884 #+EXPORT_SELECT_TAGS: %s
2885 #+EXPORT_EXCLUDE_TAGS: %s
2891 #+PRIORITIES: %c %c %c
2893 #+STARTUP: %s %s %s %s %s
2899 (buffer-name) (user-full-name) user-mail-address
2900 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
2901 org-export-default-language
2902 org-export-headline-levels
2903 org-export-with-section-numbers
2905 org-export-preserve-breaks
2906 org-export-html-expand
2907 org-export-with-fixed-width
2908 org-export-with-tables
2909 org-export-with-sub-superscripts
2910 org-export-with-special-strings
2911 org-export-with-footnotes
2912 org-export-with-emphasize
2913 org-export-with-TeX-macros
2914 org-export-with-LaTeX-fragments
2915 org-export-skip-text-before-1st-heading
2916 org-export-with-drawers
2917 org-export-with-todo-keywords
2918 org-export-with-priority
2919 org-export-with-tags
2920 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2921 (mapconcat 'identity org-export-select-tags
" ")
2922 (mapconcat 'identity org-export-exclude-tags
" ")
2923 org-export-html-link-up
2924 org-export-html-link-home
2925 (file-name-nondirectory buffer-file-name
)
2926 "TODO FEEDBACK VERIFY DONE"
2927 "Me Jason Marie DONE"
2928 org-highest-priority org-lowest-priority org-default-priority
2929 (mapconcat 'identity org-drawers
" ")
2930 (cdr (assoc org-startup-folded
2931 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2932 (if org-odd-levels-only
"odd" "oddeven")
2933 (if org-hide-leading-stars
"hidestars" "showstars")
2934 (if org-startup-align-all-tables
"align" "noalign")
2935 (cond ((eq org-log-done t
) "logdone")
2936 ((equal org-log-done
'note
) "lognotedone")
2937 ((not org-log-done
) "nologdone"))
2938 (or (mapconcat (lambda (x)
2940 ((equal '(:startgroup
) x
) "{")
2941 ((equal '(:endgroup
) x
) "}")
2942 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2944 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2945 (mapconcat 'identity org-file-tags
" ")
2946 org-archive-location
2947 "org file:~/org/%s.org"
2950 (defun org-export-html-preprocess (parameters)
2951 ;; Convert LaTeX fragments to images
2952 (when (plist-get parameters
:LaTeX-fragments
)
2954 (concat "ltxpng/" (file-name-sans-extension
2955 (file-name-nondirectory
2956 org-current-export-file
)))
2957 org-current-export-dir nil
"Creating LaTeX image %s"))
2958 (message "Exporting..."))
2961 (defun org-insert-export-options-template ()
2962 "Insert into the buffer a template with information for exporting."
2964 (if (not (bolp)) (newline))
2965 (let ((s (org-get-current-options)))
2966 (and (string-match "#\\+CATEGORY" s
)
2967 (setq s
(substring s
0 (match-beginning 0))))
2971 (defun org-export-as-html-and-open (arg)
2972 "Export the outline as HTML and immediately open it with a browser.
2973 If there is an active region, export only the region.
2974 The prefix ARG specifies how many levels of the outline should become
2975 headlines. The default is 3. Lower levels will become bulleted lists."
2977 (org-export-as-html arg
'hidden
)
2978 (org-open-file buffer-file-name
))
2981 (defun org-export-as-html-batch ()
2982 "Call `org-export-as-html', may be used in batch processing as
2984 --load=$HOME/lib/emacs/org.el
2985 --eval \"(setq org-export-headline-levels 2)\"
2986 --visit=MyFile --funcall org-export-as-html-batch"
2987 (org-export-as-html org-export-headline-levels
'hidden
))
2990 (defun org-export-as-html-to-buffer (arg)
2991 "Call `org-export-as-html` with output to a temporary buffer.
2992 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2994 (org-export-as-html arg nil nil
"*Org HTML Export*")
2995 (switch-to-buffer-other-window "*Org HTML Export*"))
2998 (defun org-replace-region-by-html (beg end
)
2999 "Assume the current region has org-mode syntax, and convert it to HTML.
3000 This can be used in any buffer. For example, you could write an
3001 itemized list in org-mode syntax in an HTML buffer and then use this
3002 command to convert it."
3004 (let (reg html buf pop-up-frames
)
3005 (save-window-excursion
3007 (setq html
(org-export-region-as-html
3009 (setq reg
(buffer-substring beg end
)
3010 buf
(get-buffer-create "*Org tmp*"))
3011 (with-current-buffer buf
3015 (setq html
(org-export-region-as-html
3016 (point-min) (point-max) t
'string
)))
3018 (delete-region beg end
)
3022 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3023 "Convert region from BEG to END in org-mode buffer to HTML.
3024 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3025 contents, and only produce the region of converted text, useful for
3026 cut-and-paste operations.
3027 If BUFFER is a buffer or a string, use/create that buffer as a target
3028 of the converted HTML. If BUFFER is the symbol `string', return the
3029 produced HTML as a string and leave not buffer behind. For example,
3030 a Lisp program could call this function in the following way:
3032 (setq html (org-export-region-as-html beg end t 'string))
3034 When called interactively, the output buffer is selected, and shown
3035 in a window. A non-interactive call will only return the buffer."
3036 (interactive "r\nP")
3037 (when (interactive-p)
3038 (setq buffer
"*Org HTML Export*"))
3039 (let ((transient-mark-mode t
) (zmacs-regions t
)
3041 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3043 (set-mark (point)) ;; to activate the region
3045 (setq rtn
(org-export-as-html
3048 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3049 (if (and (interactive-p) (bufferp rtn
))
3050 (switch-to-buffer-other-window rtn
)
3053 (defvar html-table-tag nil
) ; dynamically scoped into this.
3054 (defvar org-par-open nil
)
3056 (defun org-export-as-html (arg &optional hidden ext-plist
3057 to-buffer body-only pub-dir
)
3058 "Export the outline as a pretty HTML file.
3059 If there is an active region, export only the region. The prefix
3060 ARG specifies how many levels of the outline should become
3061 headlines. The default is 3. Lower levels will become bulleted
3062 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3063 EXT-PLIST is a property list with external parameters overriding
3064 org-mode's default settings, but still inferior to file-local
3065 settings. When TO-BUFFER is non-nil, create a buffer with that
3066 name and export to that buffer. If TO-BUFFER is the symbol
3067 `string', don't leave any buffer behind but just return the
3068 resulting HTML as a string. When BODY-ONLY is set, don't produce
3069 the file header and footer, simply return the content of
3070 <body>...</body>, without even the body tags themselves. When
3071 PUB-DIR is set, use this as the publishing directory."
3074 ;; Make sure we have a file name when we need it.
3075 (when (and (not (or to-buffer body-only
))
3076 (not buffer-file-name
))
3077 (if (buffer-base-buffer)
3078 (org-set-local 'buffer-file-name
3079 (with-current-buffer (buffer-base-buffer)
3081 (error "Need a file name to be able to export.")))
3083 (message "Exporting...")
3084 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3085 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3086 (setq-default org-done-keywords org-done-keywords
)
3087 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3089 (org-export-process-option-filters
3090 (org-combine-plists (org-default-export-plist)
3092 (org-infile-export-plist))))
3093 (style (concat (if (plist-get opt-plist
:style-include-default
)
3094 org-export-html-style-default
)
3095 (plist-get opt-plist
:style
)
3096 (plist-get opt-plist
:style-extra
)
3097 "\n" org-export-html-scripts
))
3098 (html-extension (plist-get opt-plist
:html-extension
))
3099 (link-validate (plist-get opt-plist
:link-validation-function
))
3100 valid thetoc have-headings first-heading-pos
3101 (odd org-odd-levels-only
)
3102 (region-p (org-region-active-p))
3103 (rbeg (and region-p
(region-beginning)))
3104 (rend (and region-p
(region-end)))
3106 (if (plist-get opt-plist
:ignore-subree-p
)
3111 (and (org-at-heading-p)
3112 (>= (org-end-of-subtree t t
) rend
))))))
3113 (opt-plist (if subtree-p
3114 (org-export-add-subtree-options opt-plist rbeg
)
3116 ;; The following two are dynamically scoped into other
3118 (org-current-export-dir
3119 (or pub-dir
(org-export-directory :html opt-plist
)))
3120 (org-current-export-file buffer-file-name
)
3121 (level 0) (line "") (origline "") txt todo
3124 (filename (if to-buffer nil
3127 (file-name-sans-extension
3129 (org-entry-get (region-beginning)
3130 "EXPORT_FILE_NAME" t
))
3131 (file-name-nondirectory buffer-file-name
)))
3133 (file-name-as-directory
3134 (or pub-dir
(org-export-directory :html opt-plist
))))))
3135 (current-dir (if buffer-file-name
3136 (file-name-directory buffer-file-name
)
3138 (buffer (if to-buffer
3140 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3141 (t (get-buffer-create to-buffer
)))
3142 (find-file-noselect filename
)))
3143 (org-levels-open (make-vector org-level-max nil
))
3144 (date (plist-get opt-plist
:date
))
3145 (author (plist-get opt-plist
:author
))
3146 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3147 (plist-get opt-plist
:title
)
3149 (plist-get opt-plist
:skip-before-1st-heading
))
3150 (org-export-grab-title-from-buffer))
3151 (and buffer-file-name
3152 (file-name-sans-extension
3153 (file-name-nondirectory buffer-file-name
)))
3155 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3156 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3157 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3162 (local-list-type nil
)
3163 (local-list-indent nil
)
3164 (llt org-plain-list-ordered-item-terminator
)
3165 (email (plist-get opt-plist
:email
))
3166 (language (plist-get opt-plist
:language
))
3170 (coding-system (and (boundp 'buffer-file-coding-system
)
3171 buffer-file-coding-system
))
3172 (coding-system-for-write (or org-export-html-coding-system
3174 (save-buffer-coding-system (or org-export-html-coding-system
3176 (charset (and coding-system-for-write
3177 (fboundp 'coding-system-get
)
3178 (coding-system-get coding-system-for-write
3182 (if region-p
(region-beginning) (point-min))
3183 (if region-p
(region-end) (point-max))))
3186 (org-export-preprocess-string
3190 :skip-before-1st-heading
3191 (plist-get opt-plist
:skip-before-1st-heading
)
3192 :drawers
(plist-get opt-plist
:drawers
)
3193 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3194 :tags
(plist-get opt-plist
:tags
)
3195 :priority
(plist-get opt-plist
:priority
)
3196 :footnotes
(plist-get opt-plist
:footnotes
)
3198 (plist-get opt-plist
:archived-trees
)
3199 :select-tags
(plist-get opt-plist
:select-tags
)
3200 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3202 (plist-get opt-plist
:text
)
3204 (plist-get opt-plist
:LaTeX-fragments
))
3207 table-buffer table-orig-buffer
3208 ind item-type starter didclose
3209 rpl path attr desc descp desc1 desc2 link
3210 snumber fnc item-tag
3211 footnotes footref-seen
3214 (let ((inhibit-read-only t
))
3216 (remove-text-properties (point-min) (point-max)
3217 '(:org-license-to-kill t
))))
3219 (message "Exporting...")
3221 (setq org-min-level
(org-get-min-level lines
))
3222 (setq org-last-level org-min-level
)
3223 (org-init-section-numbers)
3226 ((and date
(string-match "%" date
))
3227 (setq date
(format-time-string date
)))
3229 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3231 ;; Get the language-dependent settings
3232 (setq lang-words
(or (assoc language org-export-language-setup
)
3233 (assoc "en" org-export-language-setup
)))
3235 ;; Switch to the output buffer
3237 (let ((inhibit-read-only t
)) (erase-buffer))
3240 (and (fboundp 'set-buffer-file-coding-system
)
3241 (set-buffer-file-coding-system coding-system-for-write
))
3243 (let ((case-fold-search nil
)
3244 (org-odd-levels-only odd
))
3245 ;; create local variables for all options, to make sure all called
3246 ;; functions get the correct information
3248 (set (make-local-variable (nth 2 x
))
3249 (plist-get opt-plist
(car x
))))
3250 org-export-plist-vars
)
3251 (setq umax
(if arg
(prefix-numeric-value arg
)
3252 org-export-headline-levels
))
3253 (setq umax-toc
(if (integerp org-export-with-toc
)
3254 (min org-export-with-toc umax
)
3259 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3260 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3261 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3262 lang=\"%s\" xml:lang=\"%s\">
3265 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3266 <meta name=\"generator\" content=\"Org-mode\"/>
3267 <meta name=\"generated\" content=\"%s\"/>
3268 <meta name=\"author\" content=\"%s\"/>
3272 language language
(org-html-expand title
)
3273 (or charset
"iso-8859-1") date author style
))
3275 (insert (or (plist-get opt-plist
:preamble
) ""))
3277 (when (plist-get opt-plist
:auto-preamble
)
3278 (if title
(insert (format org-export-html-title-format
3279 (org-html-expand title
))))))
3281 (if (and org-export-with-toc
(not body-only
))
3283 (push (format "<h%d>%s</h%d>\n"
3284 org-export-html-toplevel-hlevel
3286 org-export-html-toplevel-hlevel
)
3288 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3289 (push "<ul>\n<li>" thetoc
)
3291 (mapcar '(lambda (line)
3292 (if (string-match org-todo-line-regexp line
)
3293 ;; This is a headline
3295 (setq have-headings t
)
3296 (setq level
(- (match-end 1) (match-beginning 1))
3297 level
(org-tr-level level
)
3298 txt
(save-match-data
3300 (org-export-cleanup-toc-line
3301 (match-string 3 line
))))
3303 (or (and org-export-mark-todo-in-toc
3305 (not (member (match-string 2 line
)
3306 org-done-keywords
)))
3308 (and org-export-mark-todo-in-toc
3310 (org-search-todo-below
3311 line lines level
))))
3313 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3314 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3315 (if (string-match quote-re0 txt
)
3316 (setq txt
(replace-match "" t t txt
)))
3317 (setq snumber
(org-section-number level
))
3318 (if org-export-with-section-numbers
3319 (setq txt
(concat snumber
" " txt
)))
3320 (if (<= level
(max umax umax-toc
))
3321 (setq head-count
(+ head-count
1)))
3322 (if (<= level umax-toc
)
3324 (if (> level org-last-level
)
3326 (setq cnt
(- level org-last-level
))
3327 (while (>= (setq cnt
(1- cnt
)) 0)
3328 (push "\n<ul>\n<li>" thetoc
))
3329 (push "\n" thetoc
)))
3330 (if (< level org-last-level
)
3332 (setq cnt
(- org-last-level level
))
3333 (while (>= (setq cnt
(1- cnt
)) 0)
3334 (push "</li>\n</ul>" thetoc
))
3335 (push "\n" thetoc
)))
3336 ;; Check for targets
3337 (while (string-match org-any-target-regexp line
)
3338 (setq line
(replace-match
3339 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3341 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3342 (setq txt
(replace-match "" t t txt
)))
3346 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3347 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3348 snumber txt
) thetoc
)
3350 (setq org-last-level level
))
3354 (while (> org-last-level
(1- org-min-level
))
3355 (setq org-last-level
(1- org-last-level
))
3356 (push "</li>\n</ul>\n" thetoc
))
3357 (push "</div>\n" thetoc
)
3358 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3361 (org-init-section-numbers)
3365 (while (setq line
(pop lines
) origline line
)
3368 ;; end of quote section?
3369 (when (and inquote
(string-match "^\\*+ " line
))
3372 ;; inside a quote section?
3374 (insert (org-html-protect line
) "\n")
3375 (throw 'nextline nil
))
3377 ;; Fixed-width, verbatim lines (examples)
3378 (when (and org-export-with-fixed-width
3379 (string-match "^[ \t]*:\\(.*\\)" line
))
3382 (org-close-par-maybe)
3383 (insert "<pre class=\"example\">\n"))
3384 (insert (org-html-protect (match-string 1 line
)) "\n")
3385 (when (or (not lines
)
3386 (not (string-match "^[ \t]*\\(:.*\\)"
3389 (insert "</pre>\n"))
3390 (throw 'nextline nil
))
3393 (when (get-text-property 0 'org-protected line
)
3395 (when (re-search-backward
3396 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3397 (setq par
(match-string 1))
3398 (replace-match "\\2\n"))
3401 (or (= (length (car lines
)) 0)
3402 (get-text-property 0 'org-protected
(car lines
))))
3403 (insert (pop lines
) "\n"))
3404 (and par
(insert "<p>\n")))
3405 (throw 'nextline nil
))
3408 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3410 (insert "\n</p>\n<hr/>\n<p>\n")
3411 (insert "\n<hr/>\n"))
3412 (throw 'nextline nil
))
3414 ;; Blockquotes and verse
3415 (when (equal "ORG-BLOCKQUOTE-START" line
)
3416 (org-close-par-maybe)
3417 (insert "<blockquote>\n<p>\n")
3418 (throw 'nextline nil
))
3419 (when (equal "ORG-BLOCKQUOTE-END" line
)
3420 (insert "</p>\n</blockquote>\n")
3421 (throw 'nextline nil
))
3422 (when (equal "ORG-VERSE-START" line
)
3423 (org-close-par-maybe)
3424 (insert "\n<p class=\"verse\">\n")
3426 (throw 'nextline nil
))
3427 (when (equal "ORG-VERSE-END" line
)
3430 (throw 'nextline nil
))
3432 (let ((i (org-get-string-indentation line
)))
3434 (setq line
(concat (mapconcat 'identity
3435 (make-list (* 2 i
) "\\nbsp") "")
3436 " " (org-trim line
))))
3437 (setq line
(concat line
"\\\\"))))
3439 ;; make targets to anchors
3440 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3443 (setq line
(replace-match
3445 "@<a name=\"%s\" id=\"%s\">@</a>"
3446 (org-solidify-link-text (match-string 1 line
))
3447 (org-solidify-link-text (match-string 1 line
)))
3449 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3450 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3451 (setq line
(replace-match
3452 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3453 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3456 (setq line
(replace-match
3457 (concat "@<a name=\""
3458 (org-solidify-link-text (match-string 1 line
))
3459 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3462 (setq line
(org-html-handle-time-stamps line
))
3464 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3465 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3466 ;; Also handle sub_superscripts and checkboxes
3467 (or (string-match org-table-hline-regexp line
)
3468 (setq line
(org-html-expand line
)))
3472 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3473 (setq start
(match-beginning 0))
3474 (setq path
(save-match-data (org-link-unescape
3475 (match-string 3 line
))))
3477 ((match-end 2) (match-string 2 line
))
3479 (or (file-name-absolute-p path
)
3480 (string-match "^\\.\\.?/" path
)))
3483 (setq path
(org-extract-attributes (org-link-unescape path
)))
3484 (setq attr
(get-text-property 0 'org-attributes path
))
3485 (setq desc1
(if (match-end 5) (match-string 5 line
))
3486 desc2
(if (match-end 2) (concat type
":" path
) path
)
3487 descp
(and desc1
(not (equal desc1 desc2
)))
3488 desc
(or desc1 desc2
))
3489 ;; Make an image out of the description if that is so wanted
3490 (when (and descp
(org-file-image-p desc
))
3492 (if (string-match "^file:" desc
)
3493 (setq desc
(substring desc
(match-end 0)))))
3494 (setq desc
(org-add-props
3495 (concat "<img src=\"" desc
"\"/>")
3496 '(org-protected t
))))
3497 ;; FIXME: do we need to unescape here somewhere?
3499 ((equal type
"internal")
3503 (org-solidify-link-text
3504 (save-match-data (org-link-unescape path
)) nil
)
3506 (org-export-html-format-desc desc
)
3508 ((member type
'("http" "https"))
3509 ;; standard URL, just check if we need to inline an image
3510 (if (and (or (eq t org-export-html-inline-images
)
3511 (and org-export-html-inline-images
(not descp
)))
3512 (org-file-image-p path
))
3513 (setq rpl
(org-export-html-format-image
3514 (concat type
":" path
)))
3515 (setq link
(concat type
":" path
))
3516 (setq rpl
(concat "<a href=\""
3517 (org-export-html-format-href link
)
3519 (org-export-html-format-desc desc
)
3521 ((member type
'("ftp" "mailto" "news"))
3523 (setq link
(concat type
":" path
))
3524 (setq rpl
(concat "<a href=\""
3525 (org-export-html-format-href link
)
3527 (org-export-html-format-desc desc
)
3530 ((string= type
"coderef")
3532 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3534 (format (org-export-get-coderef-format path
(and descp desc
))
3535 (cdr (assoc path org-export-code-refs
))))))
3537 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3538 ;; The link protocol has a function for format the link
3541 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3543 ((string= type
"file")
3545 (let* ((filename path
)
3546 (abs-p (file-name-absolute-p filename
))
3547 thefile file-is-image-p search
)
3549 (if (string-match "::\\(.*\\)" filename
)
3550 (setq search
(match-string 1 filename
)
3551 filename
(replace-match "" t nil filename
)))
3553 (if (functionp link-validate
)
3554 (funcall link-validate filename current-dir
)
3556 (setq file-is-image-p
(org-file-image-p filename
))
3557 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3558 (when (and org-export-html-link-org-files-as-html
3559 (string-match "\\.org$" thefile
))
3560 (setq thefile
(concat (substring thefile
0
3561 (match-beginning 0))
3562 "." html-extension
))
3564 ;; make sure this is can be used as target search
3565 (not (string-match "^[0-9]*$" search
))
3566 (not (string-match "^\\*" search
))
3567 (not (string-match "^/.*/$" search
)))
3568 (setq thefile
(concat thefile
"#"
3569 (org-solidify-link-text
3570 (org-link-unescape search
)))))
3571 (when (string-match "^file:" desc
)
3572 (setq desc
(replace-match "" t t desc
))
3573 (if (string-match "\\.org$" desc
)
3574 (setq desc
(replace-match "" t t desc
))))))
3575 (setq rpl
(if (and file-is-image-p
3576 (or (eq t org-export-html-inline-images
)
3577 (and org-export-html-inline-images
3579 (org-export-html-format-image thefile
)
3580 (concat "<a href=\"" thefile
"\"" attr
">"
3581 (org-export-html-format-desc desc
)
3583 (if (not valid
) (setq rpl desc
))))
3586 ;; just publish the path, as default
3587 (setq rpl
(concat "<i><" type
":"
3588 (save-match-data (org-link-unescape path
))
3590 (setq line
(replace-match rpl t t line
)
3591 start
(+ start
(length rpl
))))
3594 (if (and (string-match org-todo-line-regexp line
)
3595 (match-beginning 2))
3598 (concat (substring line
0 (match-beginning 2))
3600 (if (member (match-string 2 line
)
3603 "\">" (match-string 2 line
)
3604 "</span>" (substring line
(match-end 2)))))
3606 ;; Does this contain a reference to a footnote?
3607 (when org-export-with-footnotes
3609 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3610 (if (get-text-property (match-beginning 2) 'org-protected line
)
3611 (setq start
(match-end 2))
3612 (let ((n (match-string 2 line
)) extra a
)
3613 (if (setq a
(assoc n footref-seen
))
3615 (setcdr a
(1+ (cdr a
)))
3616 (setq extra
(format ".%d" (cdr a
))))
3618 (push (cons n
1) footref-seen
))
3622 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3623 (match-string 1 line
) n extra n n
)
3627 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3628 ;; This is a headline
3629 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
3630 txt
(match-string 2 line
))
3631 (if (string-match quote-re0 txt
)
3632 (setq txt
(replace-match "" t t txt
)))
3633 (if (<= level
(max umax umax-toc
))
3634 (setq head-count
(+ head-count
1)))
3636 ;; Close any local lists before inserting a new header line
3637 (while local-list-type
3638 (org-close-li (car local-list-type
))
3639 (insert (format "</%sl>\n" (car local-list-type
)))
3640 (pop local-list-type
))
3641 (setq local-list-indent nil
3643 (setq first-heading-pos
(or first-heading-pos
(point)))
3644 (org-html-level-start level txt umax
3645 (and org-export-with-toc
(<= level umax
))
3648 (when (string-match quote-re line
)
3649 (org-close-par-maybe)
3653 ((and org-export-with-tables
3654 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3655 (if (not table-open
)
3657 (setq table-open t table-buffer nil table-orig-buffer nil
))
3659 (setq table-buffer
(cons line table-buffer
)
3660 table-orig-buffer
(cons origline table-orig-buffer
))
3661 (when (or (not lines
)
3662 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3664 (setq table-open nil
3665 table-buffer
(nreverse table-buffer
)
3666 table-orig-buffer
(nreverse table-orig-buffer
))
3667 (org-close-par-maybe)
3668 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3673 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3674 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3675 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3676 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3678 (setq ind
(org-get-string-indentation line
)
3679 item-type
(if (match-beginning 4) "o" "u")
3680 starter
(if (match-beginning 2)
3681 (substring (match-string 2 line
) 0 -
1))
3682 line
(substring line
(match-beginning 5))
3684 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3686 item-tag
(match-string 1 line
)
3687 line
(substring line
(match-end 0))))
3688 (when (and (not (equal item-type
"d"))
3689 (not (string-match "[^ \t]" line
)))
3690 ;; empty line. Pretend indentation is large.
3691 (setq ind
(if org-empty-line-terminates-plain-lists
3693 (1+ (or (car local-list-indent
) 1)))))
3695 (while (and in-local-list
3696 (or (and (= ind
(car local-list-indent
))
3698 (< ind
(car local-list-indent
))))
3700 (org-close-li (car local-list-type
))
3701 (insert (format "</%sl>\n" (car local-list-type
)))
3702 (pop local-list-type
) (pop local-list-indent
)
3703 (setq in-local-list local-list-indent
))
3706 (or (not in-local-list
)
3707 (> ind
(car local-list-indent
))))
3708 ;; Start new (level of) list
3709 (org-close-par-maybe)
3711 ((equal item-type
"u") "<ul>\n<li>\n")
3712 ((equal item-type
"o") "<ol>\n<li>\n")
3713 ((equal item-type
"d")
3714 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3715 (push item-type local-list-type
)
3716 (push ind local-list-indent
)
3717 (setq in-local-list t
))
3719 ;; continue current list
3720 (org-close-li (car local-list-type
))
3722 ((equal (car local-list-type
) "d")
3723 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3726 ;; we did close a list, normal text follows: need <p>
3728 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3731 (if (equal (match-string 1 line
) "X")
3733 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3736 ;; Empty lines start a new paragraph. If hand-formatted lists
3737 ;; are not fully interpreted, lines starting with "-", "+", "*"
3738 ;; also start a new paragraph.
3739 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3741 ;; Is this the start of a footnote?
3742 (when org-export-with-footnotes
3743 (when (and (boundp 'footnote-section-tag-regexp
)
3744 (string-match (concat "^" footnote-section-tag-regexp
)
3747 (throw 'nextline nil
))
3748 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3749 (org-close-par-maybe)
3750 (let ((n (match-string 1 line
)))
3751 (setq org-par-open t
3753 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3755 ;; Check if the line break needs to be conserved
3757 ((string-match "\\\\\\\\[ \t]*$" line
)
3758 (setq line
(replace-match "<br/>" t t line
)))
3759 (org-export-preserve-breaks
3760 (setq line
(concat line
"<br/>"))))
3762 (insert line
"\n")))))
3764 ;; Properly close all local lists and other lists
3769 ;; Close any local lists before inserting a new header line
3770 (while local-list-type
3771 (org-close-li (car local-list-type
))
3772 (insert (format "</%sl>\n" (car local-list-type
)))
3773 (pop local-list-type
))
3774 (setq local-list-indent nil
3776 (org-html-level-start 1 nil umax
3777 (and org-export-with-toc
(<= level umax
))
3779 ;; the </div> to close the last text-... div.
3780 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3783 (goto-char (point-min))
3784 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3785 (push (match-string 0) footnotes
)
3786 (replace-match "" t t
)))
3788 (insert (format org-export-html-footnotes-section
3789 (or (nth 4 lang-words
) "Footnotes")
3790 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3793 (when (plist-get opt-plist
:auto-postamble
)
3794 (insert "<div id=\"postamble\">")
3795 (when (and org-export-author-info author
)
3796 (insert "<p class=\"author\"> "
3797 (nth 1 lang-words
) ": " author
"\n")
3799 (if (listp (split-string email
",+ *"))
3801 (insert "<a href=\"mailto:" e
"\"><"
3803 (split-string email
",+ *"))
3804 (insert "<a href=\"mailto:" email
"\"><"
3805 email
"></a>\n")))
3807 (when (and date org-export-time-stamp-file
)
3808 (insert "<p class=\"date\"> "
3809 (nth 2 lang-words
) ": "
3811 (when org-export-creator-info
3812 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3813 org-version emacs-major-version
)))
3816 (if org-export-html-with-timestamp
3817 (insert org-export-html-html-helper-timestamp
))
3818 (insert (or (plist-get opt-plist
:postamble
) ""))
3819 (insert "</body>\n</html>\n"))
3821 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3823 (if (eq major-mode default-major-mode
) (html-mode)))
3825 ;; insert the table of contents
3826 (goto-char (point-min))
3828 (if (or (re-search-forward
3829 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3831 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3833 (goto-char (match-beginning 0))
3835 (goto-char first-heading-pos
)
3836 (when (looking-at "\\s-*</p>")
3837 (goto-char (match-end 0))
3839 (insert "<div id=\"table-of-contents\">\n")
3840 (mapc 'insert thetoc
)
3841 (insert "</div>\n"))
3842 ;; remove empty paragraphs and lists
3843 (goto-char (point-min))
3844 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3846 (goto-char (point-min))
3847 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3849 (goto-char (point-min))
3850 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3852 ;; Convert whitespace place holders
3853 (goto-char (point-min))
3855 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3856 (setq n
(get-text-property beg
'org-whitespace
)
3857 end
(next-single-property-change beg
'org-whitespace
))
3859 (delete-region beg end
)
3860 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3861 (make-string n ?x
)))))
3862 (or to-buffer
(save-buffer))
3863 (goto-char (point-min))
3864 (message "Exporting... done")
3865 (if (eq to-buffer
'string
)
3866 (prog1 (buffer-substring (point-min) (point-max))
3867 (kill-buffer (current-buffer)))
3868 (current-buffer)))))
3870 (defun org-export-get-coderef-format (path desc
)
3872 (if (and desc
(string-match
3873 (regexp-quote (concat "((" path
"))"))
3875 (replace-match "%s" t t desc
)
3879 (defun org-export-html-format-href (s)
3880 "Make sure the S is valid as a href reference in an XHTML document."
3883 (while (string-match "&" s start
)
3884 (setq start
(+ (match-beginning 0) 3)
3885 s
(replace-match "&" t t s
)))))
3888 (defun org-export-html-format-desc (s)
3889 "Make sure the S is valid as a description in a link."
3890 (if (and s
(not (get-text-property 1 'org-protected s
)))
3892 (org-html-do-expand s
))
3895 (defun org-export-html-format-image (src)
3896 "Create image tag with source and attributes."
3898 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
3899 (attr (org-find-text-property-in-string 'org-attributes src
))
3900 (label (org-find-text-property-in-string 'org-label src
)))
3901 (format "<div %sclass=\"figure\">
3902 <p><img src=\"%s\"%s /></p>%s
3904 (if label
(format "id=\"%s\" " label
) "")
3906 (if (string-match "\\<alt=" (or attr
""))
3908 (concat " " attr
" alt=\"" src
"\""))
3909 (if caption
(concat "\n<p>" caption
"</p>") "")))))
3911 (defvar org-table-colgroup-info nil
)
3912 (defun org-format-table-ascii (lines)
3913 "Format a table for ascii export."
3915 (setq lines
(org-split-string lines
"\n")))
3916 (if (not (string-match "^[ \t]*|" (car lines
)))
3917 ;; Table made by table.el - test for spanning
3920 ;; A normal org table
3921 ;; Get rid of hlines at beginning and end
3922 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3923 (setq lines
(nreverse lines
))
3924 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3925 (setq lines
(nreverse lines
))
3926 (when org-export-table-remove-special-lines
3927 ;; Check if the table has a marking column. If yes remove the
3928 ;; column and the special lines
3929 (setq lines
(org-table-clean-before-export lines
)))
3930 ;; Get rid of the vertical lines except for grouping
3931 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3933 (while (setq line
(pop lines
))
3934 (if (string-match org-table-hline-regexp line
)
3935 (and (string-match "|\\(.*\\)|" line
)
3936 (setq line
(replace-match " \\1" t nil line
)))
3937 (setq start
0 vl1 vl
)
3938 (while (string-match "|" line start
)
3939 (setq start
(match-end 0))
3940 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3944 (defun org-colgroup-info-to-vline-list (info)
3947 (setq last new new
(pop info
))
3948 (if (or (memq last
'(:end
:startend
))
3949 (memq new
'(:start
:startend
)))
3952 (setq vl
(nreverse vl
))
3953 (and vl
(setcar vl nil
))
3956 (defvar org-table-number-regexp
) ; defined in org-table.el
3957 (defun org-format-table-html (lines olines
)
3958 "Find out which HTML converter to use and return the HTML code."
3960 (setq lines
(org-split-string lines
"\n")))
3961 (if (string-match "^[ \t]*|" (car lines
))
3962 ;; A normal org table
3963 (org-format-org-table-html lines
)
3964 ;; Table made by table.el - test for spanning
3965 (let* ((hlines (delq nil
(mapcar
3967 (if (string-match "^[ \t]*\\+-" x
) x
3970 (first (car hlines
))
3971 (ll (and (string-match "\\S-+" first
)
3972 (match-string 0 first
)))
3973 (re (concat "^[ \t]*" (regexp-quote ll
)))
3974 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3976 (if (and (not spanning
)
3977 (not org-export-prefer-native-exporter-for-tables
))
3978 ;; We can use my own converter with HTML conversions
3979 (org-format-table-table-html lines
)
3980 ;; Need to use the code generator in table.el, with the original text.
3981 (org-format-table-table-html-using-table-generate-source olines
)))))
3983 (defvar org-table-number-fraction
) ; defined in org-table.el
3984 (defun org-format-org-table-html (lines &optional splice
)
3985 "Format a table into HTML."
3986 (require 'org-table
)
3987 ;; Get rid of hlines at beginning and end
3988 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3989 (setq lines
(nreverse lines
))
3990 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3991 (setq lines
(nreverse lines
))
3992 (when org-export-table-remove-special-lines
3993 ;; Check if the table has a marking column. If yes remove the
3994 ;; column and the special lines
3995 (setq lines
(org-table-clean-before-export lines
)))
3997 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
3998 (get-text-property (or (next-single-property-change
3999 0 'org-caption
(car lines
))
4001 'org-caption
(car lines
))))
4002 (head (and org-export-highlight-first-table-line
4004 (lambda (x) (string-match "^[ \t]*|-" x
))
4008 tbopen line fields html gr colgropen
)
4009 (if splice
(setq head nil
))
4010 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4012 (while (setq line
(pop lines
))
4014 (if (string-match "^[ \t]*|-" line
)
4017 (push (if head
"</thead>" "</tbody>") html
)
4018 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4019 (setq head nil
) ;; head ends here, first time around
4021 (throw 'next-line t
)))
4022 ;; Break the line into fields
4023 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4024 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4025 (setq nlines
(1+ nlines
) i -
1)
4026 (push (concat "<tr>"
4030 (if (and (< i nlines
)
4031 (string-match org-table-number-regexp x
))
4032 (incf (aref fnum i
)))
4034 (concat (car org-export-table-header-tags
) x
4035 (cdr org-export-table-header-tags
))
4036 (concat (car org-export-table-data-tags
) x
4037 (cdr org-export-table-data-tags
))))
4041 (unless splice
(if tbopen
(push "</tbody>" html
)))
4042 (unless splice
(push "</table>\n" html
))
4043 (setq html
(nreverse html
))
4045 ;; Put in col tags with the alignment (unfortunately often ignored...)
4048 (setq gr
(pop org-table-colgroup-info
))
4049 (format "%s<col align=\"%s\"></col>%s"
4050 (if (memq gr
'(:start
:startend
))
4052 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4055 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4057 (if (memq gr
'(:end
:startend
))
4058 (progn (setq colgropen nil
) "</colgroup>")
4062 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4063 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4064 (push html-table-tag html
))
4065 (concat (mapconcat 'identity html
"\n") "\n")))
4067 (defun org-table-clean-before-export (lines)
4068 "Check if the table has a marking column.
4069 If yes remove the column and the special lines."
4070 (setq org-table-colgroup-info nil
)
4073 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4074 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
4077 (setq org-table-clean-did-remove-column nil
)
4082 ((string-match "^[ \t]*| */ *|" x
)
4083 (setq org-table-colgroup-info
4085 (cond ((member x
'("<" "<")) :start
)
4086 ((member x
'(">" ">")) :end
)
4087 ((member x
'("<>" "<>")) :startend
)
4089 (org-split-string x
"[ \t]*|[ \t]*")))
4093 (setq org-table-clean-did-remove-column t
)
4098 ((string-match "^[ \t]*| */ *|" x
)
4099 (setq org-table-colgroup-info
4101 (cond ((member x
'("<" "<")) :start
)
4102 ((member x
'(">" ">")) :end
)
4103 ((member x
'("<>" "<>")) :startend
)
4105 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4107 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4108 nil
) ; ignore this line
4109 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4110 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4111 ;; remove the first column
4112 (replace-match "\\1|" t nil x
))))
4115 (defun org-format-table-table-html (lines)
4116 "Format a table generated by table.el into HTML.
4117 This conversion does *not* use `table-generate-source' from table.el.
4118 This has the advantage that Org-mode's HTML conversions can be used.
4119 But it has the disadvantage, that no cell- or row-spanning is allowed."
4120 (let (line field-buffer
4121 (head org-export-highlight-first-table-line
)
4123 (setq html
(concat html-table-tag
"\n"))
4124 (while (setq line
(pop lines
))
4125 (setq empty
" ")
4127 (if (string-match "^[ \t]*\\+-" line
)
4138 (if (equal x
"") (setq x empty
))
4140 (concat (car org-export-table-header-tags
) x
4141 (cdr org-export-table-header-tags
))
4142 (concat (car org-export-table-data-tags
) x
4143 (cdr org-export-table-data-tags
))))
4147 (setq field-buffer nil
)))
4149 (throw 'next-line t
)))
4150 ;; Break the line into fields and store the fields
4151 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4153 (setq field-buffer
(mapcar
4155 (concat x
"<br/>" (pop fields
)))
4157 (setq field-buffer fields
))))
4158 (setq html
(concat html
"</table>\n"))
4161 (defun org-format-table-table-html-using-table-generate-source (lines)
4162 "Format a table into html, using `table-generate-source' from table.el.
4163 This has the advantage that cell- or row-spanning is allowed.
4164 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4166 (with-current-buffer (get-buffer-create " org-tmp1 ")
4168 (insert (mapconcat 'identity lines
"\n"))
4169 (goto-char (point-min))
4170 (if (not (re-search-forward "|[^+]" nil t
))
4171 (error "Error processing table"))
4172 (table-recognize-table)
4173 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4174 (table-generate-source 'html
" org-tmp2 ")
4175 (set-buffer " org-tmp2 ")
4176 (buffer-substring (point-min) (point-max))))
4178 (defun org-export-splice-style (style extra
)
4179 "Splice EXTRA into STYLE, just before \"</style>\"."
4180 (if (and (stringp extra
)
4181 (string-match "\\S-" extra
)
4182 (string-match "</style>" style
))
4183 (concat (substring style
0 (match-beginning 0))
4185 (substring style
(match-beginning 0)))
4188 (defun org-html-handle-time-stamps (s)
4189 "Format time stamps in string S, or remove them."
4192 (while (string-match org-maybe-keyword-time-regexp s
)
4193 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
4194 ;; never export CLOCK
4196 (or b
(setq b
(substring s
0 (match-beginning 0))))
4197 (if (not org-export-with-timestamps
)
4198 (setq r
(concat r
(substring s
0 (match-beginning 0)))
4199 s
(substring s
(match-end 0)))
4201 r
(substring s
0 (match-beginning 0))
4203 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4204 (match-string 1 s
)))
4205 (format " @<span class=\"timestamp\">%s@</span>"
4207 (org-translate-time (match-string 3 s
)) 1 -
1)))
4208 s
(substring s
(match-end 0)))))
4209 ;; Line break if line started and ended with time stamp stuff
4212 (setq r
(concat r s
))
4213 (unless (string-match "\\S-" (concat b s
))
4214 (setq r
(concat r
"@<br/>")))
4217 (defun org-export-htmlize-region-for-paste (beg end
)
4218 "Convert the region to HTML, using htmlize.el.
4219 This is much like `htmlize-region-for-paste', only that it uses
4220 the settings define in the org-... variables."
4221 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4222 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4223 (htmlbuf (htmlize-region beg end
)))
4225 (with-current-buffer htmlbuf
4226 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4227 (plist-get htmlize-buffer-places
'content-end
)))
4228 (kill-buffer htmlbuf
))))
4231 (defun org-export-htmlize-generate-css ()
4232 "Create the CSS for all font definitions in the current Emacs session.
4233 Use this to create face definitions in your CSS style file that can then
4234 be used by code snippets transformed by htmlize.
4235 This command just produces a buffer that contains class definitions for all
4236 faces used in the current Emacs session. You can copy and paste the ones you
4237 need into your CSS file.
4239 If you then set `org-export-htmlize-output-type' to `css', calls to
4240 the function `org-export-htmlize-region-for-paste' will produce code
4241 that uses these same face definitions."
4244 (and (get-buffer "*html*") (kill-buffer "*html*"))
4246 (let ((fl (face-list))
4247 (htmlize-css-name-prefix "org-")
4248 (htmlize-output-type 'css
)
4250 (while (setq f
(pop fl
)
4251 i
(and f
(face-attribute f
:inherit
)))
4252 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4253 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4254 (htmlize-region (point-min) (point-max))))
4255 (switch-to-buffer "*html*")
4256 (goto-char (point-min))
4257 (if (re-search-forward "<style" nil t
)
4258 (delete-region (point-min) (match-beginning 0)))
4259 (if (re-search-forward "</style>" nil t
)
4260 (delete-region (1+ (match-end 0)) (point-max)))
4261 (beginning-of-line 1)
4262 (if (looking-at " +") (replace-match ""))
4263 (goto-char (point-min)))
4265 (defun org-html-protect (s)
4266 ;; convert & to &, < to < and > to >
4268 (while (string-match "&" s start
)
4269 (setq s
(replace-match "&" t t s
)
4270 start
(1+ (match-beginning 0))))
4271 (while (string-match "<" s
)
4272 (setq s
(replace-match "<" t t s
)))
4273 (while (string-match ">" s
)
4274 (setq s
(replace-match ">" t t s
)))
4275 ; (while (string-match "\"" s)
4276 ; (setq s (replace-match """ t t s)))
4280 (defun org-export-cleanup-toc-line (s)
4281 "Remove tags and timestamps from lines going into the toc."
4282 (when (memq org-export-with-tags
'(not-in-toc nil
))
4283 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4284 (setq s
(replace-match "" t t s
))))
4285 (when org-export-remove-timestamps-from-toc
4286 (while (string-match org-maybe-keyword-time-regexp s
)
4287 (setq s
(replace-match "" t t s
))))
4288 (while (string-match org-bracket-link-regexp s
)
4289 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4293 (defun org-html-expand (string)
4294 "Prepare STRING for HTML export. Applies all active conversions.
4295 If there are links in the string, don't modify these."
4296 (let* ((re (concat org-bracket-link-regexp
"\\|"
4297 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4299 (while (setq m
(string-match re string
))
4300 (setq s
(substring string
0 m
)
4301 l
(match-string 0 string
)
4302 string
(substring string
(match-end 0)))
4303 (push (org-html-do-expand s
) res
)
4305 (push (org-html-do-expand string
) res
)
4306 (apply 'concat
(nreverse res
))))
4308 (defun org-html-do-expand (s)
4309 "Apply all active conversions to translate special ASCII to HTML."
4310 (setq s
(org-html-protect s
))
4311 (if org-export-html-expand
4313 (while (string-match "@<\\([^&]*\\)>" s
)
4314 (setq s
(replace-match "<\\1>" t nil s
)))))
4315 (if org-export-with-emphasize
4316 (setq s
(org-export-html-convert-emphasize s
)))
4317 (if org-export-with-special-strings
4318 (setq s
(org-export-html-convert-special-strings s
)))
4319 (if org-export-with-sub-superscripts
4320 (setq s
(org-export-html-convert-sub-super s
)))
4321 (if org-export-with-TeX-macros
4322 (let ((start 0) wd ass
)
4323 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4325 (if (get-text-property (match-beginning 0) 'org-protected s
)
4326 (setq start
(match-end 0))
4327 (setq wd
(match-string 1 s
))
4328 (if (setq ass
(assoc wd org-html-entities
))
4329 (setq s
(replace-match (or (cdr ass
)
4330 (concat "&" (car ass
) ";"))
4332 (setq start
(+ start
(length wd
))))))))
4335 (defun org-create-multibrace-regexp (left right n
)
4336 "Create a regular expression which will match a balanced sexp.
4337 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4338 as single character strings.
4339 The regexp returned will match the entire expression including the
4340 delimiters. It will also define a single group which contains the
4341 match except for the outermost delimiters. The maximum depth of
4342 stacked delimiters is N. Escaping delimiters is not possible."
4343 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4346 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4349 re
(concat re or next
)
4350 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4351 (concat left
"\\(" re
"\\)" right
)))
4353 (defvar org-match-substring-regexp
4355 "\\([^\\]\\)\\([_^]\\)\\("
4356 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4358 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4360 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4361 "The regular expression matching a sub- or superscript.")
4363 (defvar org-match-substring-with-braces-regexp
4365 "\\([^\\]\\)\\([_^]\\)\\("
4366 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4368 "The regular expression matching a sub- or superscript, forcing braces.")
4370 (defconst org-export-html-special-string-regexps
4371 '(("\\\\-" .
"­")
4372 ("---\\([^-]\\)" .
"—\\1")
4373 ("--\\([^-]\\)" .
"–\\1")
4374 ("\\.\\.\\." .
"…"))
4375 "Regular expressions for special string conversion.")
4377 (defun org-export-html-convert-special-strings (string)
4378 "Convert special characters in STRING to HTML."
4379 (let ((all org-export-html-special-string-regexps
)
4381 (while (setq a
(pop all
))
4382 (setq re
(car a
) rpl
(cdr a
) start
0)
4383 (while (string-match re string start
)
4384 (if (get-text-property (match-beginning 0) 'org-protected string
)
4385 (setq start
(match-end 0))
4386 (setq string
(replace-match rpl t nil string
)))))
4389 (defun org-export-html-convert-sub-super (string)
4390 "Convert sub- and superscripts in STRING to HTML."
4391 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4392 (while (string-match org-match-substring-regexp string s
)
4394 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4395 ((get-text-property (match-beginning 2) 'org-protected string
)
4396 (setq s
(match-end 2)))
4398 (setq s
(match-end 1)
4399 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4400 c
(or (match-string 8 string
)
4401 (match-string 6 string
)
4402 (match-string 5 string
))
4403 string
(replace-match
4404 (concat (match-string 1 string
)
4405 "<" key
">" c
"</" key
">")
4407 (while (string-match "\\\\\\([_^]\\)" string
)
4408 (setq string
(replace-match (match-string 1 string
) t t string
)))
4411 (defun org-export-html-convert-emphasize (string)
4414 (while (string-match org-emph-re string s
)
4416 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4417 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4418 (setq s
(match-beginning 0)
4421 (match-string 1 string
)
4422 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4423 (match-string 4 string
)
4424 (nth 3 (assoc (match-string 3 string
)
4425 org-emphasis-alist
))
4426 (match-string 5 string
))
4427 string
(replace-match rpl t t string
)
4428 s
(+ s
(- (length rpl
) 2)))
4432 (defun org-open-par ()
4433 "Insert <p>, but first close previous paragraph if any."
4434 (org-close-par-maybe)
4436 (setq org-par-open t
))
4437 (defun org-close-par-maybe ()
4438 "Close paragraph if there is one open."
4441 (setq org-par-open nil
)))
4442 (defun org-close-li (&optional type
)
4443 "Close <li> if necessary."
4444 (org-close-par-maybe)
4445 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4447 (defvar body-only
) ; dynamically scoped into this.
4448 (defun org-html-level-start (level title umax with-toc head-count
)
4449 "Insert a new level in HTML export.
4450 When TITLE is nil, just close all open levels."
4451 (org-close-par-maybe)
4452 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4454 (mapconcat (lambda (x)
4455 (format "<a name=\"%s\" id=\"%s\"></a>"
4457 (cdr (assoc target org-export-target-aliases
))
4462 (if (aref org-levels-open
(1- l
))
4464 (org-html-level-close l umax
)
4465 (aset org-levels-open
(1- l
) nil
)))
4468 ;; If title is nil, this means this function is called to close
4469 ;; all levels, so the rest is done only if title is given
4470 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4471 (setq title
(replace-match
4472 (if org-export-with-tags
4475 " <span class=\"tag\">"
4476 (mapconcat 'identity
(org-split-string
4477 (match-string 1 title
) ":")
4484 (if (aref org-levels-open
(1- level
))
4488 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4489 (insert "<li>" title
"<br/>\n")))
4490 (aset org-levels-open
(1- level
) t
)
4491 (org-close-par-maybe)
4493 (insert (format "<ul>\n<li id=\"%s\">" target
)
4494 extra-targets title
"<br/>\n")
4495 (insert "<ul>\n<li>" title
"<br/>\n"))))
4496 (aset org-levels-open
(1- level
) t
)
4497 (setq snumber
(org-section-number level
))
4498 (if (and org-export-with-section-numbers
(not body-only
))
4499 (setq title
(concat snumber
" " title
)))
4500 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4501 (unless (= head-count
1) (insert "\n</div>\n"))
4502 (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"
4503 snumber level level snumber extra-targets title level snumber
))
4506 (defun org-get-text-property-any (pos prop
&optional object
)
4507 (or (get-text-property pos prop object
)
4508 (and (setq pos
(next-single-property-change pos prop object
))
4509 (get-text-property pos prop object
))))
4511 (defun org-html-level-close (level max-outline-level
)
4512 "Terminate one level in HTML export."
4513 (if (<= level max-outline-level
)
4516 (insert "</ul>\n")))
4518 ;;; iCalendar export
4521 (defun org-export-icalendar-this-file ()
4522 "Export current file as an iCalendar file.
4523 The iCalendar file will be located in the same directory as the Org-mode
4524 file, but with extension `.ics'."
4526 (org-export-icalendar nil buffer-file-name
))
4529 (defun org-export-icalendar-all-agenda-files ()
4530 "Export all files in `org-agenda-files' to iCalendar .ics files.
4531 Each iCalendar file will be located in the same directory as the Org-mode
4532 file, but with extension `.ics'."
4534 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4537 (defun org-export-icalendar-combine-agenda-files ()
4538 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4539 The file is stored under the name `org-combined-agenda-icalendar-file'."
4541 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4543 (defun org-export-icalendar (combine &rest files
)
4544 "Create iCalendar files for all elements of FILES.
4545 If COMBINE is non-nil, combine all calendar entries into a single large
4546 file and store it under the name `org-combined-agenda-icalendar-file'."
4548 (org-prepare-agenda-buffers files
)
4549 (let* ((dir (org-export-directory
4550 :ical
(list :publishing-directory
4551 org-export-publishing-directory
)))
4552 file ical-file ical-buffer category started org-agenda-new-buffers
)
4553 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4556 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4557 org-combined-agenda-icalendar-file
4558 (expand-file-name org-combined-agenda-icalendar-file dir
))
4559 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4560 (set-buffer ical-buffer
) (erase-buffer))
4561 (while (setq file
(pop files
))
4563 (org-check-agenda-file file
)
4564 (set-buffer (org-get-agenda-file-buffer file
))
4566 (setq ical-file
(concat (file-name-as-directory dir
)
4567 (file-name-sans-extension
4568 (file-name-nondirectory buffer-file-name
))
4570 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4571 (with-current-buffer ical-buffer
(erase-buffer)))
4572 (setq category
(or org-category
4573 (file-name-sans-extension
4574 (file-name-nondirectory buffer-file-name
))))
4575 (if (symbolp category
) (setq category
(symbol-name category
)))
4576 (let ((standard-output ical-buffer
))
4578 (and (not started
) (setq started t
)
4579 (org-start-icalendar-file org-icalendar-combined-name
))
4580 (org-start-icalendar-file category
))
4581 (org-print-icalendar-entries combine
)
4582 (when (or (and combine
(not files
)) (not combine
))
4583 (org-finish-icalendar-file)
4584 (set-buffer ical-buffer
)
4585 (run-hooks 'org-before-save-iCalendar-file-hook
)
4587 (run-hooks 'org-after-save-iCalendar-file-hook
)
4588 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4590 (org-release-buffers org-agenda-new-buffers
))))
4592 (defvar org-before-save-iCalendar-file-hook nil
4593 "Hook run before an iCalendar file has been saved.
4594 This can be used to modify the result of the export.")
4596 (defvar org-after-save-iCalendar-file-hook nil
4597 "Hook run after an iCalendar file has been saved.
4598 The iCalendar buffer is still current when this hook is run.
4599 A good way to use this is to tell a desktop calendar application to re-read
4600 the iCalendar file.")
4602 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4603 (defun org-print-icalendar-entries (&optional combine
)
4604 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4605 When COMBINE is non nil, add the category to each line."
4606 (require 'org-agenda
)
4607 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4608 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4609 (dts (org-ical-ts-to-string
4610 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4612 hd ts ts2 state status
(inc t
) pos b sexp rrule
4613 scheduledp deadlinep todo prefix due start
4614 tmp pri categories entry location summary desc uid
4615 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4616 (org-refresh-category-properties)
4618 (goto-char (point-min))
4619 (while (re-search-forward re1 nil t
)
4622 (when (boundp 'org-icalendar-verify-function
)
4623 (unless (funcall org-icalendar-verify-function
)
4624 (outline-next-heading)
4627 (setq pos
(match-beginning 0)
4630 hd
(condition-case nil
4631 (org-icalendar-cleanup-string
4633 (error (throw :skip nil
)))
4634 summary
(org-icalendar-cleanup-string
4635 (org-entry-get nil
"SUMMARY"))
4636 desc
(org-icalendar-cleanup-string
4637 (or (org-entry-get nil
"DESCRIPTION")
4638 (and org-icalendar-include-body
(org-get-entry)))
4639 t org-icalendar-include-body
)
4640 location
(org-icalendar-cleanup-string
4641 (org-entry-get nil
"LOCATION" 'selective
))
4642 uid
(if org-icalendar-store-UID
4644 (or (org-id-get) (org-id-new)))
4645 categories
(org-export-get-categories)
4646 deadlinep nil scheduledp nil
)
4647 (if (looking-at re2
)
4649 (goto-char (match-end 0))
4650 (setq ts2
(match-string 1)
4651 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4652 (setq tmp
(buffer-substring (max (point-min)
4653 (- pos org-ds-keyword-length
))
4655 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4658 (replace-match "\\1" t nil ts
))
4660 deadlinep
(string-match org-deadline-regexp tmp
)
4661 scheduledp
(string-match org-scheduled-regexp tmp
)
4662 todo
(org-get-todo-state)
4663 ;; donep (org-entry-is-done-p)
4668 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4669 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4674 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4675 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4677 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4678 (if (or (string-match org-tr-regexp hd
)
4679 (string-match org-ts-regexp hd
))
4680 (setq hd
(replace-match "" t t hd
)))
4681 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4683 (concat "\nRRULE:FREQ="
4686 '(("d" .
"DAILY")("w" .
"WEEKLY")
4687 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4688 ";INTERVAL=" (match-string 1 ts
)))
4690 (setq summary
(or summary hd
))
4691 (if (string-match org-bracket-link-regexp summary
)
4693 (replace-match (if (match-end 3)
4694 (match-string 3 summary
)
4695 (match-string 1 summary
))
4697 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4698 (if scheduledp
(setq summary
(concat "S: " summary
)))
4699 (if (string-match "\\`<%%" ts
)
4700 (with-current-buffer sexp-buffer
4701 (insert (substring ts
1 -
1) " " summary
"\n"))
4702 (princ (format "BEGIN:VEVENT
4710 (org-ical-ts-to-string ts
"DTSTART")
4711 (org-ical-ts-to-string ts2
"DTEND" inc
)
4713 (if (and desc
(string-match "\\S-" desc
))
4714 (concat "\nDESCRIPTION: " desc
) "")
4715 (if (and location
(string-match "\\S-" location
))
4716 (concat "\nLOCATION: " location
) "")
4718 (when (and org-icalendar-include-sexps
4719 (condition-case nil
(require 'icalendar
) (error nil
))
4720 (fboundp 'icalendar-export-region
))
4721 ;; Get all the literal sexps
4722 (goto-char (point-min))
4723 (while (re-search-forward "^&?%%(" nil t
)
4726 (setq b
(match-beginning 0))
4727 (goto-char (1- (match-end 0)))
4730 (setq sexp
(buffer-substring b
(point)))
4731 (with-current-buffer sexp-buffer
4732 (insert sexp
"\n"))))
4733 (princ (org-diary-to-ical-string sexp-buffer
))
4734 (kill-buffer sexp-buffer
))
4736 (when org-icalendar-include-todo
4737 (setq prefix
"TODO-")
4738 (goto-char (point-min))
4739 (while (re-search-forward org-todo-line-regexp nil t
)
4742 (when (boundp 'org-icalendar-verify-function
)
4743 (unless (funcall org-icalendar-verify-function
)
4744 (outline-next-heading)
4747 (setq state
(match-string 2))
4748 (setq status
(if (member state org-done-keywords
)
4749 "COMPLETED" "NEEDS-ACTION"))
4751 (or (not (member state org-done-keywords
))
4752 (eq org-icalendar-include-todo
'all
))
4753 (not (member org-archive-tag
(org-get-tags-at)))
4755 (setq hd
(match-string 3)
4756 summary
(org-icalendar-cleanup-string
4757 (org-entry-get nil
"SUMMARY"))
4758 desc
(org-icalendar-cleanup-string
4759 (or (org-entry-get nil
"DESCRIPTION")
4760 (and org-icalendar-include-body
(org-get-entry)))
4761 t org-icalendar-include-body
)
4762 location
(org-icalendar-cleanup-string
4763 (org-entry-get nil
"LOCATION" 'selective
))
4764 due
(and (member 'todo-due org-icalendar-use-deadline
)
4765 (org-entry-get nil
"DEADLINE"))
4766 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4767 (org-entry-get nil
"SCHEDULED"))
4768 categories
(org-export-get-categories)
4769 uid
(if org-icalendar-store-UID
4771 (or (org-id-get) (org-id-new))))
4772 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4773 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4775 (if (string-match org-bracket-link-regexp hd
)
4776 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4777 (match-string 1 hd
))
4779 (if (string-match org-priority-regexp hd
)
4780 (setq pri
(string-to-char (match-string 2 hd
))
4781 hd
(concat (substring hd
0 (match-beginning 1))
4782 (substring hd
(match-end 1))))
4783 (setq pri org-default-priority
))
4784 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4785 (- org-lowest-priority org-highest-priority
))))))
4787 (princ (format "BEGIN:VTODO
4799 (if (and location
(string-match "\\S-" location
))
4800 (concat "\nLOCATION: " location
) "")
4801 (if (and desc
(string-match "\\S-" desc
))
4802 (concat "\nDESCRIPTION: " desc
) "")
4803 (if due
(concat "\n" due
) "")
4807 (defun org-export-get-categories ()
4808 "Get categories according to `org-icalendar-categories'."
4809 (let ((cs org-icalendar-categories
) c rtn tmp
)
4810 (while (setq c
(pop cs
))
4812 ((eq c
'category
) (push (org-get-category) rtn
))
4814 (setq tmp
(org-get-todo-state))
4815 (and tmp
(push tmp rtn
)))
4817 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4819 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4820 (mapconcat 'identity
(nreverse rtn
) ",")))
4822 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4823 "Take out stuff and quote what needs to be quoted.
4824 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4825 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4830 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4831 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4832 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4833 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4835 (while (string-match "\\([,;]\\)" s start
)
4836 (setq start
(+ (match-beginning 0) 2)
4837 s
(replace-match "\\\\\\1" nil nil s
))))
4838 (setq s
(org-trim s
))
4840 (while (string-match "[ \t]*\n[ \t]*" s
)
4841 (setq s
(replace-match "\\n" t t s
))))
4844 (if (and (numberp maxlength
)
4845 (> (length s
) maxlength
))
4846 (setq s
(substring s
0 maxlength
)))))
4849 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
4850 "Take out stuff and quote what needs to be quoted.
4851 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4852 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4854 This seems to be more like RFC 2455, but it causes problems, so it is
4855 not used right now."
4859 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4860 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4861 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4862 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
4863 (setq s
(org-trim s
))
4864 (while (string-match "[ \t]*\n[ \t]*" s
)
4865 (setq s
(replace-match "\\n" t t s
)))
4867 (if (and (numberp maxlength
)
4868 (> (length s
) maxlength
))
4869 (setq s
(substring s
0 maxlength
)))))
4870 (setq s
(org-trim s
)))
4871 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
4872 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
4875 (defun org-get-entry ()
4876 "Clean-up description string."
4878 (org-back-to-heading t
)
4879 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
4881 (defun org-start-icalendar-file (name)
4882 "Start an iCalendar file by inserting the header."
4883 (let ((user user-full-name
)
4884 (name (or name
"unknown"))
4885 (timezone (cadr (current-time-zone))))
4887 (format "BEGIN:VCALENDAR
4890 PRODID:-//%s//Emacs with Org-mode//EN
4892 CALSCALE:GREGORIAN\n" name user timezone
))))
4894 (defun org-finish-icalendar-file ()
4895 "Finish an iCalendar file by inserting the END statement."
4896 (princ "END:VCALENDAR\n"))
4898 (defun org-ical-ts-to-string (s keyword
&optional inc
)
4899 "Take a time string S and convert it to iCalendar format.
4900 KEYWORD is added in front, to make a complete line like DTSTART....
4901 When INC is non-nil, increase the hour by two (if time string contains
4902 a time), or the day by one (if it does not contain a time)."
4903 (let ((t1 (org-parse-time-string s
'nodefault
))
4904 t2 fmt have-time time
)
4905 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
4906 (setq t2 t1 have-time t
)
4907 (setq t2
(org-parse-time-string s
)))
4908 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
4909 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
4912 (if org-agenda-default-appointment-duration
4913 (setq mi
(+ org-agenda-default-appointment-duration mi
))
4916 (setq time
(encode-time s mi h d m y
)))
4917 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
4918 (concat keyword
(format-time-string fmt time
))))
4922 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
4923 (with-current-buffer buffer
4924 (apply 'insert output
)))
4925 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
4928 (defun org-export-as-xoxo (&optional buffer
)
4929 "Export the org buffer as XOXO.
4930 The XOXO buffer is named *xoxo-<source buffer name>*"
4931 (interactive (list (current-buffer)))
4932 ;; A quickie abstraction
4934 ;; Output everything as XOXO
4935 (with-current-buffer (get-buffer buffer
)
4936 (let* ((pos (point))
4937 (opt-plist (org-combine-plists (org-default-export-plist)
4938 (org-infile-export-plist)))
4939 (filename (concat (file-name-as-directory
4940 (org-export-directory :xoxo opt-plist
))
4941 (file-name-sans-extension
4942 (file-name-nondirectory buffer-file-name
))
4944 (out (find-file-noselect filename
))
4947 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
4948 ;; Check the output buffer is empty.
4949 (with-current-buffer out
(erase-buffer))
4950 ;; Kick off the output
4951 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
4952 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
4953 (let* ((hd (match-string-no-properties 1))
4956 (match-string-no-properties 2)
4958 (goto-char (match-end 0))
4963 (if (looking-at "^[ \t]\\(.*\\)")
4964 (setq str
(concat str
(match-string-no-properties 1)))
4965 (throw 'loop str
)))))))))
4967 ;; Handle level rendering
4969 ((> level last-level
)
4970 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
4972 ((< level last-level
)
4973 (dotimes (- (- last-level level
) 1)
4975 (org-export-as-xoxo-insert-into out
"</li>\n"))
4976 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4978 (org-export-as-xoxo-insert-into out
"</li>\n")
4979 (setq hanging-li nil
)))
4981 ((equal level last-level
)
4983 (org-export-as-xoxo-insert-into out
"</li>\n")))
4986 (setq last-level level
)
4988 ;; And output the new li
4989 (setq hanging-li
't
)
4990 (if (equal ?
+ (elt text
0))
4991 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4992 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4994 ;; Finally finish off the ol
4995 (dotimes (- last-level
1)
4997 (org-export-as-xoxo-insert-into out
"</li>\n"))
4998 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5001 ;; Finish the buffer off and clean it up.
5002 (switch-to-buffer-other-window out
)
5003 (indent-region (point-min) (point-max) nil
)
5005 (goto-char (point-min))
5010 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5012 ;;; org-exp.el ends here