1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <carsten at orgmode dot org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; Homepage: http://orgmode.org
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (declare-function org-export-latex-preprocess
"org-export-latex" ())
35 (declare-function org-agenda-skip
"org-agenda" ())
36 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
37 (declare-function htmlize-region
"ext:htmlize" (beg end
))
38 (declare-function org-id-find-id-file
"org-id" (id))
39 (defvar htmlize-buffer-places
) ; from htmlize.el
41 (defgroup org-export nil
42 "Options for exporting org-listings."
46 (defgroup org-export-general nil
47 "General options for exporting Org-mode files."
48 :tag
"Org Export General"
52 (defvar org-export-publishing-directory nil
)
54 (defcustom org-export-run-in-background nil
55 "Non-nil means export and publishing commands will run in background.
56 This works by starting up a separate Emacs process visiting the same file
57 and doing the export from there.
58 Not all export commands are affected by this - only the ones which
59 actually write to a file, and that do not depend on the buffer state.
61 If this option is nil, you can still get background export by calling
62 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
64 If this option is t, the double prefix can be used to exceptionally
65 force an export command into the current process."
66 :group
'org-export-general
70 (defcustom org-export-select-tags
'("export")
71 "Tags that select a tree for export.
72 If any such tag is found in a buffer, all trees that do not carry one
73 of these tags will be deleted before export.
74 Inside trees that are selected like this, you can still deselect a
75 subtree by tagging it with one of the `org-export-exclude-tags'."
76 :group
'org-export-general
77 :type
'(repeat (string :tag
"Tag")))
79 (defcustom org-export-exclude-tags
'("noexport")
80 "Tags that exclude a tree from export.
81 All trees carrying any of these tags will be excluded from export.
82 This is without condition, so even subtrees inside that carry one of the
83 `org-export-select-tags' will be removed."
84 :group
'org-export-general
85 :type
'(repeat (string :tag
"Tag")))
87 (defcustom org-export-with-special-strings t
88 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
89 When this option is turned on, these strings will be exported as:
92 -----+----------+--------
98 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
99 :group
'org-export-translation
102 (defcustom org-export-language-setup
103 '(("en" "Author" "Date" "Table of Contents" "Footnotes")
104 ("ca" "Autor" "Data" "Índex" "Peus de pàgina")
105 ("cs" "Autor" "Datum" "Obsah" "Pozn\xe1mky pod carou")
106 ("da" "Ophavsmand" "Dato" "Indhold" "Fodnoter")
107 ("de" "Autor" "Datum" "Inhaltsverzeichnis" "Fußnoten")
108 ("eo" "Aŭtoro" "Dato" "Enhavo" "Piednotoj")
109 ("es" "Autor" "Fecha" "Índice" "Pies de página")
110 ("fi" "Tekijä" "Päivämäärä" "Sisällysluettelo" "Alaviitteet")
111 ("fr" "Auteur" "Date" "Table des matières" "Notes de bas de page")
112 ("hu" "Szerzõ" "Dátum" "Tartalomjegyzék" "Lábjegyzet")
113 ("is" "Höfundur" "Dagsetning" "Efnisyfirlit" "Aftanmálsgreinar")
114 ("it" "Autore" "Data" "Indice" "Note a piè di pagina")
115 ("nl" "Auteur" "Datum" "Inhoudsopgave" "Voetnoten")
116 ("no" "Forfatter" "Dato" "Innhold" "Fotnoter")
117 ("nb" "Forfatter" "Dato" "Innhold" "Fotnoter") ;; nb = Norsk (bokm.l)
118 ("nn" "Forfattar" "Dato" "Innhald" "Fotnotar") ;; nn = Norsk (nynorsk)
119 ("pl" "Autor" "Data" "Spis treści" "Przypis")
120 ("sv" "Författare" "Datum" "Innehåll" "Fotnoter"))
121 "Terms used in export text, translated to different languages.
122 Use the variable `org-export-default-language' to set the language,
123 or use the +OPTION lines for a per-file setting."
124 :group
'org-export-general
127 (string :tag
"HTML language tag")
128 (string :tag
"Author")
130 (string :tag
"Table of Contents")
131 (string :tag
"Footnotes"))))
133 (defcustom org-export-default-language
"en"
134 "The default language of HTML export, as a string.
135 This should have an association in `org-export-language-setup'."
136 :group
'org-export-general
139 (defcustom org-export-skip-text-before-1st-heading nil
140 "Non-nil means, skip all text before the first headline when exporting.
141 When nil, that text is exported as well."
142 :group
'org-export-general
145 (defcustom org-export-headline-levels
3
146 "The last level which is still exported as a headline.
147 Inferior levels will produce itemize lists when exported.
148 Note that a numeric prefix argument to an exporter function overrides
151 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
152 :group
'org-export-general
155 (defcustom org-export-with-section-numbers t
156 "Non-nil means, add section numbers to headlines when exporting.
158 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
159 :group
'org-export-general
162 (defcustom org-export-section-number-format
'((("1" ".")) .
"")
163 "Format of section numbers for export.
164 The variable has two components.
165 1. A list of lists, each indicating a counter type and a separator.
166 The counter type can be any of \"1\", \"A\", \"a\", \"I\", or \"a\".
167 It causes causes numeric, alphabetic, or roman counters, respectively.
168 The separator is only used if another counter for a subsection is being
170 If there are more numbered section levels than entries in this lists,
171 then the last entry will be reused.
172 2. A terminator string that will be added after the entire
174 :group
'org-export-general
178 (string :tag
"Counter Type")
179 (string :tag
"Separator ")))
180 (string :tag
"Terminator")))
182 (defcustom org-export-with-toc t
183 "Non-nil means, create a table of contents in exported files.
184 The TOC contains headlines with levels up to`org-export-headline-levels'.
185 When an integer, include levels up to N in the toc, this may then be
186 different from `org-export-headline-levels', but it will not be allowed
187 to be larger than the number of headline levels.
188 When nil, no table of contents is made.
190 Headlines which contain any TODO items will be marked with \"(*)\" in
191 ASCII export, and with red color in HTML output, if the option
192 `org-export-mark-todo-in-toc' is set.
194 In HTML output, the TOC will be clickable.
196 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
198 :group
'org-export-general
200 (const :tag
"No Table of Contents" nil
)
201 (const :tag
"Full Table of Contents" t
)
202 (integer :tag
"TOC to level")))
204 (defcustom org-export-mark-todo-in-toc nil
205 "Non-nil means, mark TOC lines that contain any open TODO items."
206 :group
'org-export-general
209 (defcustom org-export-with-todo-keywords t
210 "Non-nil means, include TODO keywords in export.
211 When nil, remove all these keywords from the export."
212 :group
'org-export-general
215 (defcustom org-export-with-priority nil
216 "Non-nil means, include priority cookies in export.
217 When nil, remove priority cookies for export."
218 :group
'org-export-general
221 (defcustom org-export-preserve-breaks nil
222 "Non-nil means, preserve all line breaks when exporting.
223 Normally, in HTML output paragraphs will be reformatted. In ASCII
224 export, line breaks will always be preserved, regardless of this variable.
226 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
227 :group
'org-export-general
230 (defcustom org-export-with-archived-trees
'headline
231 "Whether subtrees with the ARCHIVE tag should be exported.
232 This can have three different values
233 nil Do not export, pretend this tree is not present
234 t Do export the entire tree
235 headline Only export the headline, but skip the tree below it."
236 :group
'org-export-general
239 (const :tag
"not at all" nil
)
240 (const :tag
"headline only" 'headline
)
241 (const :tag
"entirely" t
)))
243 (defcustom org-export-author-info t
244 "Non-nil means, insert author name and email into the exported file.
246 This option can also be set with the +OPTIONS line,
247 e.g. \"author-info:nil\"."
248 :group
'org-export-general
251 (defcustom org-export-creator-info t
252 "Non-nil means, the postamble should contain a creator sentence.
253 This sentence is \"HTML generated by org-mode XX in emacs XXX\"."
254 :group
'org-export-general
257 (defcustom org-export-time-stamp-file t
258 "Non-nil means, insert a time stamp into the exported file.
259 The time stamp shows when the file was created.
261 This option can also be set with the +OPTIONS line,
262 e.g. \"timestamp:nil\"."
263 :group
'org-export-general
266 (defcustom org-export-with-timestamps t
267 "If nil, do not export time stamps and associated keywords."
268 :group
'org-export-general
271 (defcustom org-export-remove-timestamps-from-toc t
272 "If nil, remove timestamps from the table of contents entries."
273 :group
'org-export-general
276 (defcustom org-export-with-tags
'not-in-toc
277 "If nil, do not export tags, just remove them from headlines.
278 If this is the symbol `not-in-toc', tags will be removed from table of
279 contents entries, but still be shown in the headlines of the document.
281 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
282 :group
'org-export-general
284 (const :tag
"Off" nil
)
285 (const :tag
"Not in TOC" not-in-toc
)
286 (const :tag
"On" t
)))
288 (defcustom org-export-with-drawers nil
289 "Non-nil means, export with drawers like the property drawer.
290 When t, all drawers are exported. This may also be a list of
291 drawer names to export."
292 :group
'org-export-general
294 (const :tag
"All drawers" t
)
295 (const :tag
"None" nil
)
296 (repeat :tag
"Selected drawers"
297 (string :tag
"Drawer name"))))
299 (defvar org-export-preprocess-hook nil
300 "Hook for preprocessing an export buffer.
301 Pretty much the first thing when exporting is running this hook.")
303 (defvar org-export-preprocess-after-include-files-hook nil
304 "Hook for preprocessing an export buffer.
305 This is run after the contents of included files have been inserted.")
307 (defvar org-export-preprocess-after-tree-selection-hook nil
308 "Hook for preprocessing an export buffer.
309 This is run after selection of trees to be exported has happened.
310 This selection includes tags-based selection, as well as removal
311 of commented and archived trees.")
313 (defvar org-export-preprocess-before-backend-specifics-hook nil
314 "Hook run before backend-specific functions are called during preprocessing.")
316 (defvar org-export-preprocess-final-hook nil
317 "Hook for preprocessing an export buffer.
318 This is run as the last thing in the preprocessing buffer, just before
319 returning the buffer string to the backend.")
321 (defgroup org-export-translation nil
322 "Options for translating special ascii sequences for the export backends."
323 :tag
"Org Export Translation"
326 (defcustom org-export-with-emphasize t
327 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
328 If the export target supports emphasizing text, the word will be
329 typeset in bold, italic, or underlined, respectively. Works only for
330 single words, but you can say: I *really* *mean* *this*.
331 Not all export backends support this.
333 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
334 :group
'org-export-translation
337 (defcustom org-export-with-footnotes t
338 "If nil, export [1] as a footnote marker.
339 Lines starting with [1] will be formatted as footnotes.
341 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
342 :group
'org-export-translation
345 (defcustom org-export-html-footnotes-section
"<div id=\"footnotes\">
346 <h2 class=\"footnotes\">%s: </h2>
347 <div id=\"text-footnotes\">
351 "Format for the footnotes section.
352 Should contain a two instances of %s. The first will be replaced with the
353 language-specific word for \"Footnotes\", the second one will be replaced
354 by the footnotes themselves."
355 :group
'org-export-html
358 (defcustom org-export-with-sub-superscripts t
359 "Non-nil means, interpret \"_\" and \"^\" for export.
360 When this option is turned on, you can use TeX-like syntax for sub- and
361 superscripts. Several characters after \"_\" or \"^\" will be
362 considered as a single item - so grouping with {} is normally not
363 needed. For example, the following things will be parsed as single
364 sub- or superscripts.
366 10^24 or 10^tau several digits will be considered 1 item.
367 10^-12 or 10^-tau a leading sign with digits or a word
368 x^2-y^3 will be read as x^2 - y^3, because items are
369 terminated by almost any nonword/nondigit char.
370 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
372 Still, ambiguity is possible - so when in doubt use {} to enclose the
373 sub/superscript. If you set this variable to the symbol `{}',
374 the braces are *required* in order to trigger interpretations as
375 sub/superscript. This can be helpful in documents that need \"_\"
376 frequently in plain text.
378 Not all export backends support this, but HTML does.
380 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
381 :group
'org-export-translation
383 (const :tag
"Always interpret" t
)
384 (const :tag
"Only with braces" {})
385 (const :tag
"Never interpret" nil
)))
387 (defcustom org-export-with-TeX-macros t
388 "Non-nil means, interpret simple TeX-like macros when exporting.
389 For example, HTML export converts \\alpha to α and \\AA to Å.
390 Not only real TeX macros will work here, but the standard HTML entities
391 for math can be used as macro names as well. For a list of supported
392 names in HTML export, see the constant `org-html-entities'.
393 Not all export backends support this.
395 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
396 :group
'org-export-translation
397 :group
'org-export-latex
400 (defcustom org-export-with-LaTeX-fragments nil
401 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
402 When set, the exporter will find LaTeX environments if the \\begin line is
403 the first non-white thing on a line. It will also find the math delimiters
404 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
407 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
408 :group
'org-export-translation
409 :group
'org-export-latex
412 (defcustom org-export-with-fixed-width t
413 "Non-nil means, lines starting with \":\" will be in fixed width font.
414 This can be used to have pre-formatted text, fragments of code etc. For
416 : ;; Some Lisp examples
419 will be looking just like this in also HTML. See also the QUOTE keyword.
420 Not all export backends support this.
422 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
423 :group
'org-export-translation
426 (defcustom org-match-sexp-depth
3
427 "Number of stacked braces for sub/superscript matching.
428 This has to be set before loading org.el to be effective."
429 :group
'org-export-translation
432 (defgroup org-export-tables nil
433 "Options for exporting tables in Org-mode."
434 :tag
"Org Export Tables"
437 (defcustom org-export-with-tables t
438 "If non-nil, lines starting with \"|\" define a table.
441 | Name | Address | Birthday |
442 |-------------+----------+-----------|
443 | Arthur Dent | England | 29.2.2100 |
445 Not all export backends support this.
447 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
448 :group
'org-export-tables
451 (defcustom org-export-highlight-first-table-line t
452 "Non-nil means, highlight the first table line.
453 In HTML export, this means use <th> instead of <td>.
454 In tables created with table.el, this applies to the first table line.
455 In Org-mode tables, all lines before the first horizontal separator
456 line will be formatted with <th> tags."
457 :group
'org-export-tables
460 (defcustom org-export-table-remove-special-lines t
461 "Remove special lines and marking characters in calculating tables.
462 This removes the special marking character column from tables that are set
463 up for spreadsheet calculations. It also removes the entire lines
464 marked with `!', `_', or `^'. The lines with `$' are kept, because
465 the values of constants may be useful to have."
466 :group
'org-export-tables
469 (defcustom org-export-prefer-native-exporter-for-tables nil
470 "Non-nil means, always export tables created with table.el natively.
471 Natively means, use the HTML code generator in table.el.
472 When nil, Org-mode's own HTML generator is used when possible (i.e. if
473 the table does not use row- or column-spanning). This has the
474 advantage, that the automatic HTML conversions for math symbols and
475 sub/superscripts can be applied. Org-mode's HTML generator is also
477 :group
'org-export-tables
480 (defgroup org-export-ascii nil
481 "Options specific for ASCII export of Org-mode files."
482 :tag
"Org Export ASCII"
485 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
486 "Characters for underlining headings in ASCII export.
487 In the given sequence, these characters will be used for level 1, 2, ..."
488 :group
'org-export-ascii
489 :type
'(repeat character
))
491 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
492 "Bullet characters for headlines converted to lists in ASCII export.
493 The first character is used for the first lest level generated in this
494 way, and so on. If there are more levels than characters given here,
495 the list will be repeated.
496 Note that plain lists will keep the same bullets as the have in the
498 :group
'org-export-ascii
499 :type
'(repeat character
))
501 (defgroup org-export-xml nil
502 "Options specific for XML export of Org-mode files."
503 :tag
"Org Export XML"
506 (defgroup org-export-html nil
507 "Options specific for HTML export of Org-mode files."
508 :tag
"Org Export HTML"
511 (defcustom org-export-html-coding-system nil
512 "Coding system for HTML export, defaults to buffer-file-coding-system."
513 :group
'org-export-html
514 :type
'coding-system
)
516 (defcustom org-export-html-extension
"html"
517 "The extension for exported HTML files."
518 :group
'org-export-html
521 (defcustom org-export-html-link-up
""
522 "Where should the \"UP\" link of exported HTML pages lead?"
523 :group
'org-export-html
524 :type
'(string :tag
"File or URL"))
526 (defcustom org-export-html-link-home
""
527 "Where should the \"HOME\" link of exported HTML pages lead?"
528 :group
'org-export-html
529 :type
'(string :tag
"File or URL"))
531 (defconst org-export-html-scripts
532 "<script type=\"text/javascript\">
533 <!--/*--><![CDATA[/*><!--*/
534 function CodeHighlightOn(elem, id)
536 var target = document.getElementById(id);
538 elem.cacheClassElem = elem.className;
539 elem.cacheClassTarget = target.className;
540 target.className = \"code-highlighted\";
541 elem.className = \"code-highlighted\";
544 function CodeHighlightOff(elem, id)
546 var target = document.getElementById(id);
547 if(elem.cacheClassElem)
548 elem.className = elem.cacheClassElem;
549 if(elem.cacheClassTarget)
550 target.className = elem.cacheClassTarget;
554 "Basic javascript that is needed by HTML files produced by Org-mode.")
556 (defconst org-export-html-style-default
557 "<style type=\"text/css\">
558 <!--/*--><![CDATA[/*><!--*/
559 html { font-family: Times, serif; font-size: 12pt; }
560 .title { text-align: center; }
561 .todo { color: red; }
562 .done { color: green; }
563 .tag { background-color: #add8e6; font-weight:normal }
565 .timestamp { color: #bebebe; }
566 .timestamp-kwd { color: #5f9ea0; }
567 p.verse { margin-left: 3% }
569 border: 1pt solid #AEBDCC;
570 background-color: #F3F5F7;
572 font-family: courier, monospace;
576 table { border-collapse: collapse; }
577 td, th { vertical-align: top; }
578 dt { font-weight: bold; }
579 div.figure { padding: 0.5em; }
580 div.figure p { text-align: center; }
581 .linenr { font-size:smaller }
582 .code-highlighted {background-color:#ffff00;}
583 .org-info-js_info-navigation { border-style:none; }
584 #org-info-js_console-label { font-size:10px; font-weight:bold;
585 white-space:nowrap; }
586 .org-info-js_search-highlight {background-color:#ffff00; color:#000000;
590 "The default style specification for exported HTML files.
591 Please use the variables `org-export-html-style' and
592 `org-export-html-style-extra' to add to this style. If you wish to not
593 have the default style included, customize the variable
594 `org-export-html-style-include-default'.")
596 (defcustom org-export-html-style-include-default t
597 "Non-nil means, include the default style in exported HTML files.
598 The actual style is defined in `org-export-html-style-default' and should
599 not be modified. Use the variables `org-export-html-style' to add
600 your own style information."
601 :group
'org-export-html
604 (put 'org-export-html-style
'safe-local-variable
'booleanp
)
606 (defcustom org-export-html-style
""
607 "Org-wide style definitions for exported HTML files.
609 This variable needs to contain the full HTML structure to provide a style,
610 including the surrounding HTML tags. If you set the value of this variable,
611 you should consider to include definitions for the following classes:
612 title, todo, done, timestamp, timestamp-kwd, tag, target.
614 For example, a valid value would be:
616 <style type=\"text/css\">
618 p { font-weight: normal; color: gray; }
620 .title { text-align: center; }
621 .todo, .timestamp-kwd { color: red; }
622 .done { color: green; }
626 If you'd like to refer to en external style file, use something like
628 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
630 As the value of this option simply gets inserted into the HTML <head> header,
631 you can \"misuse\" it to add arbitrary text to the header.
632 See also the variable `org-export-html-style-extra'."
633 :group
'org-export-html
636 (put 'org-export-html-style
'safe-local-variable
'stringp
)
638 (defcustom org-export-html-style-extra
""
639 "Additional style information for HTML export.
640 The value of this variable is inserted into the HTML buffer right after
641 the value of `org-export-html-style'. Use this variable for per-file
642 settings of style information, and do not forget to surround the style
643 settings with <style>...</style> tags."
644 :group
'org-export-html
647 (put 'org-export-html-style-extra
'safe-local-variable
'stringp
)
650 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
651 "Format for typesetting the document title in HTML export."
652 :group
'org-export-html
655 (defcustom org-export-html-toplevel-hlevel
2
656 "The <H> level for level 1 headings in HTML export."
657 :group
'org-export-html
660 (defcustom org-export-html-link-org-files-as-html t
661 "Non-nil means, make file links to `file.org' point to `file.html'.
662 When org-mode is exporting an org-mode file to HTML, links to
663 non-html files are directly put into a href tag in HTML.
664 However, links to other Org-mode files (recognized by the
665 extension `.org.) should become links to the corresponding html
666 file, assuming that the linked org-mode file will also be
668 When nil, the links still point to the plain `.org' file."
669 :group
'org-export-html
672 (defcustom org-export-html-inline-images
'maybe
673 "Non-nil means, inline images into exported HTML pages.
674 This is done using an <img> tag. When nil, an anchor with href is used to
675 link to the image. If this option is `maybe', then images in links with
676 an empty description will be inlined, while images with a description will
678 :group
'org-export-html
679 :type
'(choice (const :tag
"Never" nil
)
680 (const :tag
"Always" t
)
681 (const :tag
"When there is no description" maybe
)))
683 (defcustom org-export-html-inline-image-extensions
684 '("png" "jpeg" "jpg" "gif")
685 "Extensions of image files that can be inlined into HTML."
686 :group
'org-export-html
687 :type
'(repeat (string :tag
"Extension")))
690 (defcustom org-export-html-expand t
691 "Non-nil means, for HTML export, treat @<...> as HTML tag.
692 When nil, these tags will be exported as plain text and therefore
693 not be interpreted by a browser.
695 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
696 :group
'org-export-html
699 (defcustom org-export-html-table-tag
700 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
701 "The HTML tag that is used to start a table.
702 This must be a <table> tag, but you may change the options like
703 borders and spacing."
704 :group
'org-export-html
707 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
708 "The opening tag for table header fields.
709 This is customizable so that alignment options can be specified."
710 :group
'org-export-tables
711 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
713 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
714 "The opening tag for table data 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-html-with-timestamp nil
720 "If non-nil, write `org-export-html-html-helper-timestamp'
721 into the exported HTML text. Otherwise, the buffer will just be saved
723 :group
'org-export-html
726 (defcustom org-export-html-html-helper-timestamp
727 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
728 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
729 :group
'org-export-html
732 (defgroup org-export-htmlize nil
733 "Options for processing examples with htmlize.el."
734 :tag
"Org Export Htmlize"
735 :group
'org-export-html
)
737 (defcustom org-export-htmlize-output-type
'inline-css
738 "Output type to be used by htmlize when formatting code snippets.
739 Normally this is `inline-css', but if you have defined to appropriate
740 classes in your css style file, setting this to `css' means that the
741 fontification will use the class names.
742 See also the function `org-export-htmlize-generate-css'."
743 :group
'org-export-htmlize
744 :type
'(choice (const css
) (const inline-css
)))
746 (defcustom org-export-htmlize-css-font-prefix
"org-"
747 "The prefix for CSS class names for htmlize font specifications."
748 :group
'org-export-htmlize
751 (defgroup org-export-icalendar nil
752 "Options specific for iCalendar export of Org-mode files."
753 :tag
"Org Export iCalendar"
756 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
757 "The file name for the iCalendar file covering all agenda files.
758 This file is created with the command \\[org-export-icalendar-all-agenda-files].
759 The file name should be absolute, the file will be overwritten without warning."
760 :group
'org-export-icalendar
763 (defcustom org-icalendar-combined-name
"OrgMode"
764 "Calendar name for the combined iCalendar representing all agenda files."
765 :group
'org-export-icalendar
768 (defcustom org-icalendar-use-deadline
'(event-if-not-todo todo-due
)
769 "Contexts where iCalendar export should use a deadline time stamp.
770 This is a list with several symbols in it. Valid symbol are:
772 event-if-todo Deadlines in TODO entries become calendar events.
773 event-if-not-todo Deadlines in non-TODO entries become calendar events.
774 todo-due Use deadlines in TODO entries as due-dates"
775 :group
'org-export-icalendar
776 :type
'(set :greedy t
777 (const :tag
"Deadlines in non-TODO entries become events"
779 (const :tag
"Deadline in TODO entries become events"
781 (const :tag
"Deadlines in TODO entries become due-dates"
784 (defcustom org-icalendar-use-scheduled
'(todo-start)
785 "Contexts where iCalendar export should use a scheduling time stamp.
786 This is a list with several symbols in it. Valid symbol are:
788 event-if-todo Scheduling time stamps in TODO entries become an event.
789 event-if-not-todo Scheduling time stamps in non-TODO entries become an event.
790 todo-start Scheduling time stamps in TODO entries become start date.
791 Some calendar applications show TODO entries only after
793 :group
'org-export-icalendar
794 :type
'(set :greedy t
796 "SCHEDULED timestamps in non-TODO entries become events"
798 (const :tag
"SCHEDULED timestamps in TODO entries become events"
800 (const :tag
"SCHEDULED in TODO entries become start date"
803 (defcustom org-icalendar-categories
'(local-tags category
)
804 "Items that should be entered into the categories field.
805 This is a list of symbols, the following are valid:
807 category The Org-mode category of the current file or tree
808 todo-state The todo state, if any
809 local-tags The tags, defined in the current line
810 all-tags All tags, including inherited ones."
811 :group
'org-export-icalendar
814 (const :tag
"The file or tree category" category
)
815 (const :tag
"The TODO state" todo-state
)
816 (const :tag
"Tags defined in current line" local-tags
)
817 (const :tag
"All tags, including inherited ones" all-tags
))))
819 (defcustom org-icalendar-include-todo nil
820 "Non-nil means, export to iCalendar files should also cover TODO items."
821 :group
'org-export-icalendar
823 (const :tag
"None" nil
)
824 (const :tag
"Unfinished" t
)
825 (const :tag
"All" all
)))
827 (defcustom org-icalendar-include-sexps t
828 "Non-nil means, export to iCalendar files should also cover sexp entries.
829 These are entries like in the diary, but directly in an Org-mode file."
830 :group
'org-export-icalendar
833 (defcustom org-icalendar-include-body
100
834 "Amount of text below headline to be included in iCalendar export.
835 This is a number of characters that should maximally be included.
836 Properties, scheduling and clocking lines will always be removed.
837 The text will be inserted into the DESCRIPTION field."
838 :group
'org-export-icalendar
840 (const :tag
"Nothing" nil
)
841 (const :tag
"Everything" t
)
842 (integer :tag
"Max characters")))
844 (defcustom org-icalendar-store-UID nil
845 "Non-nil means, store any created UIDs in properties.
846 The iCalendar standard requires that all entries have a unique identifier.
847 Org will create these identifiers as needed. When this variable is non-nil,
848 the created UIDs will be stored in the ID property of the entry. Then the
849 next time this entry is exported, it will be exported with the same UID,
850 superceding the previous form of it. This is essential for
851 synchronization services.
852 This variable is not turned on by default because we want to avoid creating
853 a property drawer in every entry if people are only playing with this feature,
854 or if they are only using it locally."
855 :group
'org-export-icalendar
860 ;;; Variables, constants, and parameter plists
862 (defconst org-level-max
20)
864 (defvar org-export-html-preamble nil
865 "Preamble, to be inserted just before <body>. Set by publishing functions.")
866 (defvar org-export-html-postamble nil
867 "Preamble, to be inserted just after </body>. Set by publishing functions.")
868 (defvar org-export-html-auto-preamble t
869 "Should default preamble be inserted? Set by publishing functions.")
870 (defvar org-export-html-auto-postamble t
871 "Should default postamble be inserted? Set by publishing functions.")
872 (defvar org-current-export-file nil
) ; dynamically scoped parameter
873 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
875 (defconst org-export-plist-vars
876 '((:link-up nil org-export-html-link-up
)
877 (:link-home nil org-export-html-link-home
)
878 (:language nil org-export-default-language
)
879 (:customtime nil org-display-custom-times
)
880 (:headline-levels
"H" org-export-headline-levels
)
881 (:section-numbers
"num" org-export-with-section-numbers
)
882 (:section-number-format nil org-export-section-number-format
)
883 (:table-of-contents
"toc" org-export-with-toc
)
884 (:preserve-breaks
"\\n" org-export-preserve-breaks
)
885 (:archived-trees nil org-export-with-archived-trees
)
886 (:emphasize
"*" org-export-with-emphasize
)
887 (:sub-superscript
"^" org-export-with-sub-superscripts
)
888 (:special-strings
"-" org-export-with-special-strings
)
889 (:footnotes
"f" org-export-with-footnotes
)
890 (:drawers
"d" org-export-with-drawers
)
891 (:tags
"tags" org-export-with-tags
)
892 (:todo-keywords
"todo" org-export-with-todo-keywords
)
893 (:priority
"pri" org-export-with-priority
)
894 (:TeX-macros
"TeX" org-export-with-TeX-macros
)
895 (:LaTeX-fragments
"LaTeX" org-export-with-LaTeX-fragments
)
896 (:skip-before-1st-heading
"skip" org-export-skip-text-before-1st-heading
)
897 (:fixed-width
":" org-export-with-fixed-width
)
898 (:timestamps
"<" org-export-with-timestamps
)
899 (:author-info
"author" org-export-author-info
)
900 (:creator-info
"creator" org-export-creator-info
)
901 (:time-stamp-file
"timestamp" org-export-time-stamp-file
)
902 (:tables
"|" org-export-with-tables
)
903 (:table-auto-headline nil org-export-highlight-first-table-line
)
904 (:style-include-default nil org-export-html-style-include-default
)
905 (:style nil org-export-html-style
)
906 (:style-extra nil org-export-html-style-extra
)
907 (:agenda-style nil org-agenda-export-html-style
)
908 (:convert-org-links nil org-export-html-link-org-files-as-html
)
909 (:inline-images nil org-export-html-inline-images
)
910 (:html-extension nil org-export-html-extension
)
911 (:html-table-tag nil org-export-html-table-tag
)
912 (:expand-quoted-html
"@" org-export-html-expand
)
913 (:timestamp nil org-export-html-with-timestamp
)
914 (:publishing-directory nil org-export-publishing-directory
)
915 (:preamble nil org-export-html-preamble
)
916 (:postamble nil org-export-html-postamble
)
917 (:auto-preamble nil org-export-html-auto-preamble
)
918 (:auto-postamble nil org-export-html-auto-postamble
)
919 (:author nil user-full-name
)
920 (:email nil user-mail-address
)
921 (:select-tags nil org-export-select-tags
)
922 (:exclude-tags nil org-export-exclude-tags
))
923 "List of properties that represent export/publishing variables.
924 Each element is a list of 3 items:
925 1. The property that is used internally, and also for org-publish-project-alist
926 2. The string that can be used in the OPTION lines to set this option,
927 or nil if this option cannot be changed in this way
928 3. The customization variable that sets the default for this option."
932 (defun org-default-export-plist ()
933 "Return the property list with default settings for the export variables."
934 (let ((l org-export-plist-vars
) rtn e
)
935 (while (setq e
(pop l
))
936 (setq rtn
(cons (car e
) (cons (symbol-value (nth 2 e
)) rtn
))))
939 (defvar org-export-inbuffer-options-extra nil
940 "List of additional in-buffer options that should be detected.
941 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
942 etc. Extensions can add to this list to get their options detected, and they
943 can then add a function to `org-export-options-filters' to process these
945 Each element in this list must be a list, with the in-buffer keyword as car,
946 and a property (a symbol) as the next element. All occurrences of the
947 keyword will be found, the values concatenated with a space character
948 in between, and the result stored in the export options property list.")
950 (defvar org-export-options-filters nil
951 "Functions to be called to finalize the export/publishing options.
952 All these options are stored in a property list, and each of the functions
953 in this hook gets a chance to modify this property list. Each function
954 must accept the property list as an argument, and must return the (possibly
957 ;; FIXME: should we fold case here?
958 (defun org-infile-export-plist ()
959 "Return the property list with file-local settings for export."
963 (goto-char (point-min))
964 (let ((re (org-make-options-regexp
966 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
967 "LINK_UP" "LINK_HOME" "SETUPFILE" "STYLE" "LATEX_HEADER"
968 "EXPORT_SELECT_TAGS" "EXPORT_EXCLUDE_TAGS")
969 (mapcar 'car org-export-inbuffer-options-extra
))))
970 p key val text options a pr style
972 ext-setup-or-nil setup-contents
(start 0))
973 (while (or (and ext-setup-or-nil
974 (string-match re ext-setup-or-nil start
)
975 (setq start
(match-end 0)))
976 (and (setq ext-setup-or-nil nil start
0)
977 (re-search-forward re nil t
)))
978 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
979 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
981 ((setq a
(assoc key org-export-inbuffer-options-extra
))
983 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
984 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
985 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
986 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
987 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
988 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
989 ((string-equal key
"STYLE")
990 (setq style
(concat style
"\n" val
)))
991 ((string-equal key
"LATEX_HEADER")
992 (setq latex-header
(concat latex-header
"\n" val
)))
993 ((string-equal key
"TEXT")
994 (setq text
(if text
(concat text
"\n" val
) val
)))
995 ((string-equal key
"OPTIONS")
996 (setq options
(concat val
" " options
)))
997 ((string-equal key
"LINK_UP")
998 (setq p
(plist-put p
:link-up val
)))
999 ((string-equal key
"LINK_HOME")
1000 (setq p
(plist-put p
:link-home val
)))
1001 ((string-equal key
"EXPORT_SELECT_TAGS")
1002 (setq p
(plist-put p
:select-tags
(org-split-string val
))))
1003 ((string-equal key
"EXPORT_EXCLUDE_TAGS")
1004 (setq p
(plist-put p
:exclude-tags
(org-split-string val
))))
1005 ((equal key
"SETUPFILE")
1006 (setq setup-contents
(org-file-contents
1008 (org-remove-double-quotes
1011 (if (not ext-setup-or-nil
)
1012 (setq ext-setup-or-nil setup-contents start
0)
1013 (setq ext-setup-or-nil
1014 (concat (substring ext-setup-or-nil
0 start
)
1015 "\n" setup-contents
"\n"
1016 (substring ext-setup-or-nil start
)))))))
1017 (setq p
(plist-put p
:text text
))
1018 (when style
(setq p
(plist-put p
:style-extra style
)))
1020 (setq p
(plist-put p
:latex-header-extra
(substring latex-header
1))))
1022 (setq p
(org-export-add-options-to-plist p options
)))
1025 (defun org-export-add-options-to-plist (p options
)
1026 "Parse an OPTIONS line and set values in the property list P."
1029 (let ((op org-export-plist-vars
))
1030 (while (setq o
(pop op
))
1032 (string-match (concat (regexp-quote (nth 1 o
))
1033 ":\\([^ \t\n\r;,.]*\\)")
1035 (setq p
(plist-put p
(car o
)
1036 (car (read-from-string
1037 (match-string 1 options
))))))))))
1040 (defun org-export-add-subtree-options (p pos
)
1041 "Add options in subtree at position POS to property list P."
1044 (when (org-at-heading-p)
1046 ;; This is actually read in `org-export-get-title-from-subtree'
1047 ;; (when (setq a (org-entry-get pos "EXPORT_TITLE"))
1048 ;; (setq p (plist-put p :title a)))
1049 (when (setq a
(org-entry-get pos
"EXPORT_TEXT"))
1050 (setq p
(plist-put p
:text a
)))
1051 (when (setq a
(org-entry-get pos
"EXPORT_OPTIONS"))
1052 (setq p
(org-export-add-options-to-plist p a
)))))
1055 (defun org-export-directory (type plist
)
1056 (let* ((val (plist-get plist
:publishing-directory
))
1057 (dir (if (listp val
)
1058 (or (cdr (assoc type val
)) ".")
1062 (defun org-export-process-option-filters (plist)
1063 (let ((functions org-export-options-filters
) f
)
1064 (while (setq f
(pop functions
))
1065 (setq plist
(funcall f plist
))))
1069 (defun org-export (&optional arg
)
1070 "Export dispatcher for Org-mode.
1071 When `org-export-run-in-background' is non-nil, try to run the command
1072 in the background. This will be done only for commands that write
1073 to a file. For details see the docstring of `org-export-run-in-background'.
1075 The prefix argument ARG will be passed to the exporter. However, if
1076 ARG is a double universal prefix `C-u C-u', that means to inverse the
1077 value of `org-export-run-in-background'."
1079 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
1080 (help "[t] insert the export option template
1081 \[v] limit export to visible part of outline tree
1083 \[a] export as ASCII
1086 \[H] export as HTML to temporary buffer
1087 \[R] export region as HTML
1088 \[b] export as HTML and browse immediately
1091 \[l] export as LaTeX
1092 \[p] export as LaTeX and process to PDF
1093 \[d] export as LaTeX, process to PDF, and open the resulting PDF document
1094 \[L] export as LaTeX to temporary buffer
1096 \[i] export current file as iCalendar file
1097 \[I] export all agenda files as iCalendar files
1098 \[c] export agenda files into combined iCalendar file
1100 \[F] publish current file
1101 \[P] publish current project
1102 \[X] publish... (project will be prompted for)
1103 \[A] publish all projects")
1105 '((?t org-insert-export-options-template nil
)
1106 (?v org-export-visible nil
)
1107 (?a org-export-as-ascii t
)
1108 (?h org-export-as-html t
)
1109 (?b org-export-as-html-and-open t
)
1110 (?H org-export-as-html-to-buffer nil
)
1111 (?R org-export-region-as-html nil
)
1112 (?x org-export-as-xoxo t
)
1113 (?l org-export-as-latex t
)
1114 (?p org-export-as-pdf t
)
1115 (?d org-export-as-pdf-and-open t
)
1116 (?L org-export-as-latex-to-buffer nil
)
1117 (?i org-export-icalendar-this-file t
)
1118 (?I org-export-icalendar-all-agenda-files t
)
1119 (?c org-export-icalendar-combine-agenda-files t
)
1120 (?F org-publish-current-file t
)
1121 (?P org-publish-current-project t
)
1123 (?A org-publish-all t
)))
1126 (save-window-excursion
1127 (delete-other-windows)
1128 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
1130 (org-fit-window-to-buffer (get-buffer-window
1131 "*Org Export/Publishing Help*"))
1132 (message "Select command: ")
1133 (setq r1
(read-char-exclusive))))
1134 (setq r2
(if (< r1
27) (+ r1
96) r1
))
1135 (unless (setq ass
(assq r2 cmds
))
1136 (error "No command associated with key %c" r1
))
1137 (if (and bg
(nth 2 ass
)
1138 (not (buffer-base-buffer))
1139 (not (org-region-active-p)))
1140 ;; execute in background
1141 (let ((p (start-process
1142 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
1144 (expand-file-name invocation-name invocation-directory
)
1147 "--eval" "(require 'org-exp)"
1148 "--eval" "(setq org-wait .2)"
1150 "-f" (symbol-name (nth 1 ass
)))))
1151 (set-process-sentinel p
'org-export-process-sentinel
)
1152 (message "Background process \"%s\": started" p
))
1153 ;; background processing not requested, or not possible
1154 (call-interactively (nth 1 ass
)))))
1156 (defun org-export-process-sentinel (process status
)
1157 (if (string-match "\n+\\'" status
)
1158 (setq status
(substring status
0 -
1)))
1159 (message "Background process \"%s\": %s" process status
))
1161 (defconst org-html-entities
1202 ("Aring") ("AA".
"Å")
1291 ("varepsilon".
"ε")
1304 ("sigmaf") ("varsigma".
"ς")
1312 ("thetasym") ("vartheta".
"ϑ")
1315 ("bull") ("bullet".
"•")
1316 ("hellip") ("dots".
"…")
1326 ("larr") ("leftarrow".
"←") ("gets".
"←")
1327 ("uarr") ("uparrow".
"↑")
1328 ("rarr") ("to".
"→") ("rightarrow".
"→")
1329 ("darr")("downarrow".
"↓")
1330 ("harr") ("leftrightarrow".
"↔")
1331 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1332 ("lArr") ("Leftarrow".
"⇐")
1333 ("uArr") ("Uparrow".
"⇑")
1334 ("rArr") ("Rightarrow".
"⇒")
1335 ("dArr") ("Downarrow".
"⇓")
1336 ("hArr") ("Leftrightarrow".
"⇔")
1338 ("part") ("partial".
"∂")
1339 ("exist") ("exists".
"∃")
1340 ("empty") ("emptyset".
"∅")
1342 ("isin") ("in".
"∈")
1348 ("lowast") ("ast".
"∗")
1350 ("prop") ("proptp".
"∝")
1351 ("infin") ("infty".
"∞")
1352 ("ang") ("angle".
"∠")
1353 ("and") ("wedge".
"∧")
1354 ("or") ("vee".
"∨")
1360 ("cong") ("simeq".
"≅")
1361 ("asymp")("approx".
"≈")
1362 ("ne") ("neq".
"≠")
1366 ("sub") ("subset".
"⊂")
1367 ("sup") ("supset".
"⊃")
1374 ("sdot") ("cdot".
"⋅")
1381 ("loz") ("Diamond".
"◊")
1382 ("spades") ("spadesuit".
"♠")
1383 ("clubs") ("clubsuit".
"♣")
1384 ("hearts") ("diamondsuit".
"♥")
1385 ("diams") ("diamondsuit".
"♦")
1386 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1453 "Entities for TeX->HTML translation.
1454 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1455 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1456 In that case, \"\\ent\" will be translated to \"&other;\".
1457 The list contains HTML entities for Latin-1, Greek and other symbols.
1458 It is supplemented by a number of commonly used TeX macros with appropriate
1459 translations. There is currently no way for users to extend this.")
1461 ;;; General functions for all backends
1463 (defvar org-export-target-aliases nil
1464 "Alist of targets with invisible aliases.")
1465 (defvar org-export-code-refs nil
1466 "Alist of code references and line numbers")
1468 (defun org-export-preprocess-string (string &rest parameters
)
1469 "Cleanup STRING so that that the true exported has a more consistent source.
1470 This function takes STRING, which should be a buffer-string of an org-file
1471 to export. It then creates a temporary buffer where it does its job.
1472 The result is then again returned as a string, and the exporter works
1473 on this string to produce the exported version."
1475 (let* ((htmlp (plist-get parameters
:for-html
))
1476 (asciip (plist-get parameters
:for-ascii
))
1477 (latexp (plist-get parameters
:for-LaTeX
))
1478 (backend (cond (htmlp 'html
) (latexp 'latex
) (asciip 'ascii
)))
1480 (archived-trees (plist-get parameters
:archived-trees
))
1481 (inhibit-read-only t
)
1482 (drawers org-drawers
)
1483 (outline-regexp "\\*+ ")
1486 (setq org-export-target-aliases nil
)
1487 (setq org-export-code-refs nil
)
1489 (with-current-buffer (get-buffer-create " org-mode-tmp")
1492 (setq case-fold-search t
)
1494 ;; Remove license-to-kill stuff
1495 ;; The caller marks some stuff for killing, stuff that has been
1496 ;; used to create the page title, for example.
1497 (org-export-kill-licensed-text)
1499 (let ((org-inhibit-startup t
)) (org-mode))
1500 (setq case-fold-search t
)
1503 (run-hooks 'org-export-preprocess-hook
)
1505 (untabify (point-min) (point-max))
1507 ;; Handle include files, and call a hook
1508 (org-export-handle-include-files)
1509 (run-hooks 'org-export-preprocess-after-include-files-hook
)
1511 ;; Get rid of archived trees
1512 (org-export-remove-archived-trees archived-trees
)
1514 ;; Remove comment environment and comment subtrees
1515 (org-export-remove-comment-blocks-and-subtrees)
1517 ;; Get rid of excluded trees, and call a hook
1518 (org-export-handle-export-tags (plist-get parameters
:select-tags
)
1519 (plist-get parameters
:exclude-tags
))
1520 (run-hooks 'org-export-preprocess-after-tree-selection-hook
)
1522 ;; Handle source code snippets
1523 (org-export-replace-src-segments-and-examples backend
)
1525 ;; Protect short examples marked by a leading colon
1526 (org-export-protect-colon-examples)
1528 ;; Normalize footnotes
1529 (when (plist-get parameters
:footnotes
)
1530 (org-footnote-normalize nil t
))
1532 ;; Find all headings and compute the targets for them
1533 (setq target-alist
(org-export-define-heading-targets target-alist
))
1535 ;; Get rid of drawers
1536 (org-export-remove-or-extract-drawers drawers
1537 (plist-get parameters
:drawers
))
1539 ;; Get the correct stuff before the first headline
1540 (when (plist-get parameters
:skip-before-1st-heading
)
1541 (goto-char (point-min))
1542 (when (re-search-forward "^\\(#.*\n\\)?\\*+[ \t]" nil t
)
1543 (delete-region (point-min) (match-beginning 0))
1544 (goto-char (point-min))
1546 (when (plist-get parameters
:add-text
)
1547 (goto-char (point-min))
1548 (insert (plist-get parameters
:add-text
) "\n"))
1550 ;; Remove todo-keywords before exporting, if the user has requested so
1551 (org-export-remove-headline-metadata parameters
)
1553 ;; Find targets in comments and move them out of comments,
1554 ;; but mark them as targets that should be invisible
1555 (setq target-alist
(org-export-handle-invisible-targets target-alist
))
1557 ;; Select and protect backend specific stuff, throw away stuff
1558 ;; that is specific for other backends
1559 (org-export-select-backend-specific-text backend
)
1561 ;; Protect quoted subtrees
1562 (org-export-protect-quoted-subtrees)
1564 ;; Remove clock lines
1565 (org-export-remove-clock-lines)
1567 ;; Protect verbatim elements
1568 (org-export-protect-verbatim)
1570 ;; Blockquotes and verse
1571 (org-export-mark-blockquote-and-verse)
1573 ;; Remove timestamps, if the user has requested so
1574 (unless (plist-get parameters
:timestamps
)
1575 (org-export-remove-timestamps))
1577 ;; Attach captions to the correct object
1578 (setq target-alist
(org-export-attach-captions-and-attributes
1579 backend target-alist
))
1581 ;; Find matches for radio targets and turn them into internal links
1582 (org-export-mark-radio-links)
1584 ;; Find all links that contain a newline and put them into a single line
1585 (org-export-concatenate-multiline-links)
1587 ;; Normalize links: Convert angle and plain links into bracket links
1588 ;; and expand link abbreviations
1589 (org-export-normalize-links)
1591 ;; Find all internal links. If they have a fuzzy match (i.e. not
1592 ;; a *dedicated* target match, let the link point to the
1593 ;; corresponding section.
1594 (org-export-target-internal-links target-alist
)
1596 ;; Find multiline emphasis and put them into single line
1597 (when (plist-get parameters
:emph-multiline
)
1598 (org-export-concatenate-multiline-emphasis))
1600 ;; Remove special table lines
1601 (when org-export-table-remove-special-lines
1602 (org-export-remove-special-table-lines))
1605 (run-hooks 'org-export-preprocess-before-backend-specifics-hook
)
1607 ;; LaTeX-specific preprocessing
1609 (require 'org-export-latex nil
)
1610 (org-export-latex-preprocess))
1612 ;; ASCII-specific preprocessing
1614 (org-export-ascii-preprocess))
1616 ;; HTML-specific preprocessing
1618 (org-export-html-preprocess parameters
))
1620 ;; Remove or replace comments
1621 (org-export-handle-comments (plist-get parameters
:comments
))
1623 ;; Run the final hook
1624 (run-hooks 'org-export-preprocess-final-hook
)
1626 (setq rtn
(buffer-string)))
1627 (kill-buffer " org-mode-tmp")
1630 (defun org-export-kill-licensed-text ()
1631 "Remove all text that is marked with a :org-license-to-kill property."
1633 (while (setq p
(text-property-any (point-min) (point-max)
1634 :org-license-to-kill t
))
1636 p
(or (next-single-property-change p
:org-license-to-kill
)
1639 (defun org-export-define-heading-targets (target-alist)
1640 "Find all headings and define the targets for them.
1641 The new targets are added to TARGET-ALIST, which is also returned."
1642 (goto-char (point-min))
1643 (org-init-section-numbers)
1644 (let ((re (concat "^" org-outline-regexp
1645 "\\| [ \t]*:ID:[ \t]*\\([^ \t\r\n]+\\)"))
1646 level target last-section-target a
)
1647 (while (re-search-forward re nil t
)
1650 (push (cons (org-match-string-no-properties 1)
1651 target
) target-alist
)
1652 (setq a
(or (assoc last-section-target org-export-target-aliases
)
1654 (push (list last-section-target
)
1655 org-export-target-aliases
)
1656 (car org-export-target-aliases
))))
1657 (push (caar target-alist
) (cdr a
)))
1658 (setq level
(org-reduced-level
1659 (save-excursion (goto-char (point-at-bol))
1660 (org-outline-level))))
1661 (setq target
(org-solidify-link-text
1662 (format "sec-%s" (org-section-number level
))))
1663 (setq last-section-target target
)
1664 (push (cons target target
) target-alist
)
1665 (add-text-properties
1666 (point-at-bol) (point-at-eol)
1667 (list 'target target
)))))
1670 (defun org-export-handle-invisible-targets (target-alist)
1671 "Find targets in comments and move them out of comments.
1672 Mark them as invisible targets."
1674 (goto-char (point-min))
1675 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1676 ;; Check if the line before or after is a headline with a target
1677 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1678 (get-text-property (point-at-bol 2) 'target
)))
1680 ;; use the existing target in a neighboring line
1681 (setq tmp
(match-string 2))
1683 (and (looking-at "\n") (delete-char 1))
1684 (push (cons (setq tmp
(org-solidify-link-text tmp
)) target
)
1686 (setq a
(or (assoc target org-export-target-aliases
)
1688 (push (list target
) org-export-target-aliases
)
1689 (car org-export-target-aliases
))))
1691 ;; Make an invisible target
1692 (replace-match "\\1(INVISIBLE)"))))
1695 (defun org-export-target-internal-links (target-alist)
1696 "Find all internal links and assign targets to them.
1697 If a link has a fuzzy match (i.e. not a *dedicated* target match),
1698 let the link point to the corresponding section.
1699 This function also handles the id links, if they have a match in
1701 (goto-char (point-min))
1702 (while (re-search-forward org-bracket-link-regexp nil t
)
1704 (let* ((md (match-data))
1705 (desc (match-end 2))
1706 (link (org-link-unescape (match-string 1)))
1707 (slink (org-solidify-link-text link
))
1708 found props pos cref
1711 ((cdr (assoc slink target-alist
)))
1712 ((and (string-match "^id:" link
)
1713 (cdr (assoc (substring link
3) target-alist
))))
1714 ((string-match "^(\\(.*\\))$" link
)
1715 (setq cref
(match-string 1 link
))
1716 (concat "coderef:" cref
))
1717 ((string-match org-link-types-re link
) nil
)
1718 ((or (file-name-absolute-p link
)
1719 (string-match "^\\." link
))
1723 (setq found
(condition-case nil
(org-link-search link
)
1726 (or (org-on-heading-p)
1727 (not (eq found
'dedicated
))))
1728 (or (get-text-property (point) 'target
)
1731 (1- (or (previous-single-property-change
1732 (point) 'target
) 0)))
1736 (goto-char (match-beginning 1))
1737 (setq props
(text-properties-at (point)))
1738 (delete-region (match-beginning 1) (match-end 1))
1741 (unless desc
(insert "][" link
))
1742 (add-text-properties pos
(point) props
))))))
1744 (defun org-export-remove-or-extract-drawers (all-drawers exp-drawers
)
1745 "Remove drawers, or extract the content.
1746 ALL-DRAWERS is a list of all drawer names valid in the current buffer.
1747 EXP-DRAWERS can be t to keep all drawer contents, or a list of drawers
1748 whose content to keep."
1749 (unless (eq t exp-drawers
)
1750 (goto-char (point-min))
1751 (let ((re (concat "^[ \t]*:\\("
1754 (org-delete-all exp-drawers
1755 (copy-sequence all-drawers
))
1757 "\\):[ \t]*\n\\([^\000]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1758 (while (re-search-forward re nil t
)
1760 (replace-match ""))))))
1762 (defun org-export-handle-export-tags (select-tags exclude-tags
)
1763 "Modify the buffer, honoring SELECT-TAGS and EXCLUDE-TAGS.
1764 Both arguments are lists of tags.
1765 If any of SELECT-TAGS is found, all trees not marked by a SELECT-TAG
1767 After that, all subtrees that are marked by EXCLUDE-TAGS will be
1769 (remove-text-properties (point-min) (point-max) '(:org-delete t
))
1770 (let* ((re-sel (concat ":\\(" (mapconcat 'regexp-quote
1773 (re-excl (concat ":\\(" (mapconcat 'regexp-quote
1777 (goto-char (point-min))
1778 (when (and select-tags
1780 (concat "^\\*+[ \t].*" re-sel
"[^ \t\n]*[ \t]*$") nil t
))
1781 ;; At least one tree is marked for export, this means
1782 ;; all the unmarked stuff needs to go.
1783 ;; Dig out the trees that should be exported
1784 (goto-char (point-min))
1785 (outline-next-heading)
1787 (put-text-property beg
(point-max) :org-delete t
)
1788 (while (re-search-forward re-sel nil t
)
1789 (when (org-on-heading-p)
1790 (org-back-to-heading)
1791 (remove-text-properties
1792 (max (1- (point)) (point-min))
1793 (setq cont
(save-excursion (org-end-of-subtree t t
)))
1795 (while (and (org-up-heading-safe)
1796 (get-text-property (point) :org-delete
))
1797 (remove-text-properties (max (1- (point)) (point-min))
1798 (point-at-eol) '(:org-delete t
)))
1800 ;; Remove the trees explicitly marked for noexport
1802 (goto-char (point-min))
1803 (while (re-search-forward re-excl nil t
)
1804 (when (org-at-heading-p)
1805 (org-back-to-heading t
)
1807 (org-end-of-subtree t
)
1808 (delete-region beg
(point)))))
1809 ;; Remove everything that is now still marked for deletion
1810 (goto-char (point-min))
1811 (while (setq beg
(text-property-any (point-min) (point-max) :org-delete t
))
1812 (setq end
(or (next-single-property-change beg
:org-delete
)
1814 (delete-region beg end
))))
1816 (defun org-export-remove-archived-trees (export-archived-trees)
1817 "Remove archived trees.
1818 When EXPORT-ARCHIVED-TREES is `headline;, only the headline will be exported.
1819 When it is t, the entire archived tree will be exported.
1820 When it is nil the entire tree including the headline will be removed
1822 (let ((re-archive (concat ":" org-archive-tag
":"))
1824 (when (not (eq export-archived-trees t
))
1825 (goto-char (point-min))
1826 (while (re-search-forward re-archive nil t
)
1827 (if (not (org-on-heading-p t
))
1828 (org-end-of-subtree t
)
1829 (beginning-of-line 1)
1830 (setq a
(if export-archived-trees
1831 (1+ (point-at-eol)) (point))
1832 b
(org-end-of-subtree t
))
1833 (if (> b a
) (delete-region a b
)))))))
1835 (defun org-export-remove-headline-metadata (opts)
1836 "Remove meta data from the headline, according to user options."
1837 (let ((re org-complex-heading-regexp
)
1838 (todo (plist-get opts
:todo-keywords
))
1839 (tags (plist-get opts
:tags
))
1840 (pri (plist-get opts
:priority
))
1843 (setq elts
(delq nil
(list 1 (if todo
2) (if pri
3) 4 (if tags
5))))
1844 (when (or (not todo
) (not tags
) (not pri
))
1845 (goto-char (point-min))
1846 (while (re-search-forward re nil t
)
1848 (setq rpl
(mapconcat (lambda (i) (if (match-end i
) (match-string i
) ""))
1850 (replace-match rpl t t
))))))
1852 (defun org-export-remove-timestamps ()
1853 "Remove timestamps and keywords for export."
1854 (while (re-search-forward org-maybe-keyword-time-regexp nil t
)
1857 (unless (save-match-data (org-at-table-p))
1859 (beginning-of-line 1)
1860 (if (looking-at "[- \t]*\\(=>[- \t0-9:]*\\)?[ \t]*\n")
1861 (replace-match ""))))))
1863 (defun org-export-remove-clock-lines ()
1864 "Remove timestamps and keywords for export."
1865 (let ((re (concat "^[ \t]*" org-clock-string
".*\n?")))
1866 (while (re-search-forward re nil t
)
1868 (replace-match "")))))
1870 (defun org-export-protect-quoted-subtrees ()
1871 "Mark quoted subtrees with the protection property."
1872 (let ((re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>")))
1873 (goto-char (point-min))
1874 (while (re-search-forward re-quote nil t
)
1875 (goto-char (match-beginning 0))
1877 (add-text-properties (point) (org-end-of-subtree t
)
1878 '(org-protected t
)))))
1880 (defun org-export-protect-verbatim ()
1881 "Mark verbatim snippets with the protection property."
1882 (goto-char (point-min))
1883 (while (re-search-forward org-verbatim-re nil t
)
1884 (add-text-properties (match-beginning 4) (match-end 4)
1886 (goto-char (1+ (match-end 4)))))
1888 (defun org-export-protect-colon-examples ()
1889 "Protect lines starting with a colon."
1890 (goto-char (point-min))
1891 (let ((re "^[ \t]*:\\([ \t]\\|$\\)") beg
)
1892 (while (re-search-forward re nil t
)
1893 (beginning-of-line 1)
1895 (while (looking-at re
)
1897 (or (eobp) (forward-char 1)))
1898 (add-text-properties beg
(if (bolp) (1- (point)) (point))
1899 '(org-protected t
)))))
1901 (defun org-export-select-backend-specific-text (backend)
1903 '((html "HTML" "BEGIN_HTML" "END_HTML")
1904 (ascii "ASCII" "BEGIN_ASCII" "END_ASCII")
1905 (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1906 (case-fold-search t
)
1910 (setq fmt
(pop formatters
))
1911 (when (eq (car fmt
) backend
)
1912 ;; This is selected code, put it into the file for real
1913 (goto-char (point-min))
1914 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1915 ":[ \t]*\\(.*\\)") nil t
)
1916 (replace-match "\\1" t
)
1917 (add-text-properties
1918 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1919 '(org-protected t
))))
1920 (goto-char (point-min))
1921 (while (re-search-forward
1923 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1924 (cadddr fmt
) "\\>.*\n?") nil t
)
1925 (if (eq (car fmt
) backend
)
1927 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1929 ;; No, this is for a different backend, kill it
1930 (delete-region (match-beginning 0) (match-end 0)))))))
1932 (defun org-export-mark-blockquote-and-verse ()
1933 "Mark block quote and verse environments with special cookies.
1934 These special cookies will later be interpreted by the backend."
1936 (goto-char (point-min))
1937 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*"
1939 (replace-match (if (equal (downcase (match-string 1)) "end")
1940 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1943 (goto-char (point-min))
1944 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1945 (replace-match (if (equal (downcase (match-string 1)) "end")
1946 "ORG-VERSE-END" "ORG-VERSE-START")
1949 (defun org-export-attach-captions-and-attributes (backend target-alist
)
1950 "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
1951 If the next thing following is a table, add the text properties to the first
1952 table line. If it is a link, add it to the line containing the link."
1953 (goto-char (point-min))
1954 (remove-text-properties (point-min) (point-max)
1955 '(org-caption nil org-attributes nil
))
1956 (let ((case-fold-search t
)
1957 (re (concat "^#\\+caption:[ \t]+\\(.*\\)"
1959 "^#\\+attr_" (symbol-name backend
) ":[ \t]+\\(.*\\)"
1961 "^#\\+label:[ \t]+\\(.*\\)"
1965 "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
1967 (while (re-search-forward re nil t
)
1970 (setq cap
(concat cap
(if cap
" " "") (org-trim (match-string 1)))))
1972 (setq attr
(concat attr
(if attr
" " "") (org-trim (match-string 2)))))
1974 (setq label
(org-trim (match-string 3))))
1976 (add-text-properties (point-at-bol) (point-at-eol)
1977 (list 'org-caption cap
1978 'org-attributes attr
1980 (if label
(push (cons label label
) target-alist
))
1981 (setq cap nil attr nil label nil
)))))
1984 (defun org-export-remove-comment-blocks-and-subtrees ()
1985 "Remove the comment environment, and also commented subtrees."
1986 (let ((re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1987 (case-fold-search nil
))
1988 ;; Remove comment environment
1989 (goto-char (point-min))
1990 (while (re-search-forward
1991 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1992 (replace-match "" t t
))
1993 ;; Remove subtrees that are commented
1994 (goto-char (point-min))
1995 (while (re-search-forward re-commented nil t
)
1996 (goto-char (match-beginning 0))
1997 (delete-region (point) (org-end-of-subtree t
)))))
1999 (defun org-export-handle-comments (commentsp)
2000 "Remove comments, or convert to backend-specific format.
2001 COMMENTSP can be a format string for publishing comments.
2002 When it is nil, all comments will be removed."
2003 (let ((re "^#\\(.*\n?\\)")
2005 (goto-char (point-min))
2006 (while (or (looking-at re
)
2007 (re-search-forward re nil t
))
2008 (setq pos
(match-beginning 0))
2010 (progn (add-text-properties
2011 (match-beginning 0) (match-end 0) '(org-protected t
))
2012 (replace-match (format commentsp
(match-string 1)) t t
))
2013 (goto-char (1+ pos
))
2016 (goto-char (max (point-min) (1- pos
))))))))
2018 (defun org-export-mark-radio-links ()
2019 "Find all matches for radio targets and turn them into internal links."
2020 (let ((re-radio (and org-target-link-regexp
2021 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)"))))
2022 (goto-char (point-min))
2024 (while (re-search-forward re-radio nil t
)
2026 (replace-match "\\1[[\\2]]"))))))
2028 (defun org-export-remove-special-table-lines ()
2029 "Remove tables lines that are used for internal purposes."
2030 (goto-char (point-min))
2031 (while (re-search-forward "^[ \t]*|" nil t
)
2032 (beginning-of-line 1)
2033 (if (or (looking-at "[ \t]*| *[!_^] *|")
2034 (and (looking-at ".*?| *<[0-9]+> *|")
2035 (not (looking-at ".*?| *[^ <|]"))))
2036 (delete-region (max (point-min) (1- (point-at-bol)))
2040 (defun org-export-normalize-links ()
2041 "Convert all links to bracket links, and expand link abbreviations."
2042 (let ((re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
2043 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
)))
2044 (goto-char (point-min))
2045 (while (re-search-forward re-plain-link nil t
)
2046 (goto-char (1- (match-end 0)))
2048 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2049 ":" (match-string 3) "]]")))
2050 ;; added 'org-link face to links
2051 (put-text-property 0 (length s
) 'face
'org-link s
)
2052 (replace-match s t t
))))
2053 (goto-char (point-min))
2054 (while (re-search-forward re-angle-link nil t
)
2055 (goto-char (1- (match-end 0)))
2057 (let* ((s (concat (match-string 1) "[[" (match-string 2)
2058 ":" (match-string 3) "]]")))
2059 (put-text-property 0 (length s
) 'face
'org-link s
)
2060 (replace-match s t t
))))
2061 (goto-char (point-min))
2062 (while (re-search-forward org-bracket-link-regexp nil t
)
2063 (goto-char (1- (match-end 0)))
2065 (let* ((xx (save-match-data
2067 (org-link-expand-abbrev (match-string 1)))))
2069 "[[" (org-add-props (copy-sequence xx
)
2070 nil
'org-protected t
)
2074 (concat "[" (org-add-props
2079 (put-text-property 0 (length s
) 'face
'org-link s
)
2080 (replace-match s t t
))))))
2082 (defun org-export-concatenate-multiline-links ()
2083 "Find multi-line links and put it all into a single line.
2084 This is to make sure that the line-processing export backends
2085 can work correctly."
2086 (goto-char (point-min))
2087 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
2089 (replace-match "\\1 \\3")
2090 (goto-char (match-beginning 0)))))
2092 (defun org-export-concatenate-multiline-emphasis ()
2093 "Find multi-line emphasis and put it all into a single line.
2094 This is to make sure that the line-processing export backends
2095 can work correctly."
2096 (goto-char (point-min))
2097 (while (re-search-forward org-emph-re nil t
)
2098 (if (and (not (= (char-after (match-beginning 3))
2099 (char-after (match-beginning 4))))
2100 (save-excursion (goto-char (match-beginning 0))
2101 (save-match-data (not (org-at-table-p)))))
2103 (subst-char-in-region (match-beginning 0) (match-end 0)
2105 (goto-char (1- (match-end 0))))
2106 (goto-char (1+ (match-beginning 0))))))
2108 (defun org-export-grab-title-from-buffer ()
2109 "Get a title for the current document, from looking at the buffer."
2110 (let ((inhibit-read-only t
))
2112 (goto-char (point-min))
2113 (let ((end (if (looking-at org-outline-regexp
)
2115 (save-excursion (outline-next-heading) (point)))))
2116 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
2117 ;; Mark the line so that it will not be exported as normal text.
2119 (add-text-properties (match-beginning 0) (match-end 0)
2120 (list :org-license-to-kill t
)))
2121 ;; Return the title string
2122 (org-trim (match-string 0)))))))
2124 (defun org-export-get-title-from-subtree ()
2125 "Return subtree title and exclude it from export."
2126 (let (title (rbeg (region-beginning)) (rend (region-end)))
2129 (when (and (org-at-heading-p)
2130 (>= (org-end-of-subtree t t
) rend
))
2131 ;; This is a subtree, we take the title from the first heading
2133 (looking-at org-todo-line-regexp
)
2134 (setq title
(match-string 3))
2136 (add-text-properties (point) (1+ (point-at-eol))
2137 (list :org-license-to-kill t
)))
2138 (setq title
(or (org-entry-get nil
"EXPORT_TITLE") title
))))
2141 (defun org-solidify-link-text (s &optional alist
)
2142 "Take link text and make a safe target out of it."
2147 (org-split-string s
"[ \t\r\n]+") "=="))
2148 (a (assoc rtn alist
)))
2151 (defun org-get-min-level (lines &optional offset
)
2152 "Get the minimum level in LINES."
2153 (let ((re "^\\(\\*+\\) ") l
)
2155 (while (setq l
(pop lines
))
2156 (if (string-match re l
)
2157 (throw 'exit
(org-tr-level (- (length (match-string 1 l
))
2161 ;; Variable holding the vector with section numbers
2162 (defvar org-section-numbers
(make-vector org-level-max
0))
2164 (defun org-init-section-numbers ()
2165 "Initialize the vector for the section numbers."
2167 (numbers (nreverse (org-split-string "" "\\.")))
2168 (depth (1- (length org-section-numbers
)))
2169 (i depth
) number-string
)
2172 (aset org-section-numbers i
0)
2173 (setq number-string
(or (car numbers
) "0"))
2174 (if (string-match "\\`[A-Z]\\'" number-string
)
2175 (aset org-section-numbers i
2176 (- (string-to-char number-string
) ?A -
1))
2177 (aset org-section-numbers i
(string-to-number number-string
)))
2181 (defun org-section-number (&optional level
)
2182 "Return a string with the current section number.
2183 When LEVEL is non-nil, increase section numbers on that level."
2184 (let* ((depth (1- (length org-section-numbers
)))
2186 (fmts (car org-export-section-number-format
))
2187 (term (cdr org-export-section-number-format
))
2192 (aset org-section-numbers
2193 level
(1+ (aref org-section-numbers level
))))
2194 (setq idx
(1+ level
))
2195 (while (<= idx depth
)
2197 (aset org-section-numbers idx
0))
2198 (setq idx
(1+ idx
))))
2200 (while (<= idx depth
)
2201 (when (> (aref org-section-numbers idx
) 0)
2202 (setq fmt
(or (pop fmts
) fmt
)
2204 n
(aref org-section-numbers idx
)
2206 (concat string sep
(org-number-to-counter n ctype
))
2207 (concat string
".0"))
2209 (setq idx
(1+ idx
)))
2211 (if (string-match "\\`\\([@0]\\.\\)+" string
)
2212 (setq string
(replace-match "" t nil string
)))
2213 (if (string-match "\\(\\.0\\)+\\'" string
)
2214 (setq string
(replace-match "" t nil string
))))
2215 (concat string term
)))
2217 (defun org-number-to-counter (n type
)
2218 "Concert number N to a string counter, according to TYPE.
2219 TYPE must be a string, any of:
2223 I upper case roman numeral
2224 i lower case roman numeral"
2226 ((equal type
"1") (number-to-string n
))
2227 ((equal type
"A") (char-to-string (+ ?A n -
1)))
2228 ((equal type
"a") (char-to-string (+ ?a n -
1)))
2229 ((equal type
"I") (org-number-to-roman n
))
2230 ((equal type
"i") (downcase (org-number-to-roman n
)))
2231 (t (error "Invalid counter type `%s'" type
))))
2233 (defun org-number-to-roman (n)
2234 "Convert integer N into a roman numeral."
2235 (let ((roman '((1000 .
"M") (900 .
"CM") (500 .
"D") (400 .
"CD")
2236 ( 100 .
"C") ( 90 .
"XC") ( 50 .
"L") ( 40 .
"XL")
2237 ( 10 .
"X") ( 9 .
"IX") ( 5 .
"V") ( 4 .
"IV")
2241 (number-to-string n
)
2243 (if (>= n
(caar roman
))
2244 (setq n
(- n
(caar roman
))
2245 res
(concat res
(cdar roman
)))
2249 (org-number-to-roman 1961)
2254 (defun org-export-handle-include-files ()
2255 "Include the contents of include files, with proper formatting."
2256 (let ((case-fold-search t
)
2257 params file markup lang start end prefix prefix1 switches
)
2258 (goto-char (point-min))
2259 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
2260 (setq params
(read (concat "(" (match-string 1) ")"))
2261 prefix
(org-get-and-remove-property 'params
:prefix
)
2262 prefix1
(org-get-and-remove-property 'params
:prefix1
)
2263 file
(org-symname-or-string (pop params
))
2264 markup
(org-symname-or-string (pop params
))
2265 lang
(and (member markup
'("src" "SRC"))
2266 (org-symname-or-string (pop params
)))
2267 switches
(mapconcat '(lambda (x) (format "%s" x
)) params
" "))
2268 (delete-region (match-beginning 0) (match-end 0))
2270 (not (file-exists-p file
))
2271 (not (file-readable-p file
)))
2272 (insert (format "CANNOT INCLUDE FILE %s" file
))
2274 (if (equal (downcase markup
) "src")
2275 (setq start
(format "#+begin_src %s %s\n"
2276 (or lang
"fundamental")
2279 (setq start
(format "#+begin_%s %s\n" markup switches
)
2280 end
(format "#+end_%s" markup
))))
2281 (insert (or start
""))
2282 (insert (org-get-file-contents (expand-file-name file
) prefix prefix1
))
2283 (or (bolp) (newline))
2284 (insert (or end
""))))))
2286 (defun org-get-file-contents (file &optional prefix prefix1
)
2287 "Get the contents of FILE and return them as a string.
2288 If PREFIX is a string, prepend it to each line. If PREFIX1
2289 is a string, prepend it to the first line instead of PREFIX."
2291 (insert-file-contents file
)
2292 (when (or prefix prefix1
)
2293 (goto-char (point-min))
2295 (insert (or prefix1 prefix
))
2297 (beginning-of-line 2)))
2300 (defun org-get-and-remove-property (listvar prop
)
2301 "Check if the value of LISTVAR contains PROP as a property.
2302 If yes, return the value of that property (i.e. the element following
2303 in the list) and remove property and value from the list in LISTVAR."
2304 (let ((list (symbol-value listvar
)) m v
)
2305 (when (setq m
(member prop list
))
2307 (if (equal (car list
) prop
)
2308 (set listvar
(cddr list
))
2309 (setcdr (nthcdr (- (length list
) (length m
) 1) list
)
2311 (set listvar list
)))
2314 (defun org-symname-or-string (s)
2316 (if s
(symbol-name s
) s
)
2319 ;;; Fontification and line numbers for code examples
2321 (defvar org-export-last-code-line-counter-value
0)
2323 (defun org-export-replace-src-segments-and-examples (backend)
2324 "Replace source code segments with special code for export."
2325 (setq org-export-last-code-line-counter-value
0)
2326 (let ((case-fold-search t
)
2327 lang code trans opts
)
2328 (goto-char (point-min))
2329 (while (re-search-forward
2330 "\\(^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)\\(.*\\)\n\\([^\000]+?\n\\)#\\+END_SRC.*\\)\\|\\(^#\\+BEGIN_EXAMPLE:?\\(?:[ \t]+\\(.*\\)\\)?\n\\([^\000]+?\n\\)#\\+END_EXAMPLE.*\\)"
2334 (setq lang
(match-string 2)
2335 opts
(match-string 3)
2336 code
(match-string 4))
2338 opts
(match-string 6)
2339 code
(match-string 7)))
2341 (setq trans
(org-export-format-source-code-or-example
2342 backend lang code opts
))
2343 (replace-match trans t t
))))
2345 (defvar htmlp
) ;; dynamically scoped
2346 (defvar latexp
) ;; dynamically scoped
2348 (defun org-export-format-source-code-or-example (backend
2349 lang code
&optional opts
)
2350 "Format CODE from language LANG and return it formatted for export.
2351 If LANG is nil, do not add any fontification.
2352 OPTS contains formatting optons, like `-n' for triggering numbering lines,
2353 and `+n' for continuing previous numering.
2354 Code formatting according to language currently only works for HTML.
2355 Numbering lines works for all three major backends (html, latex, and ascii)."
2357 (let (num cont rtn rpllbl keepp textareap cols rows fmt
)
2358 (setq opts
(or opts
"")
2359 num
(string-match "[-+]n\\>" opts
)
2360 cont
(string-match "\\+n\\>" opts
)
2361 rpllbl
(string-match "-r\\>" opts
)
2362 keepp
(string-match "-k\\>" opts
)
2363 textareap
(string-match "-t\\>" opts
)
2364 cols
(if (string-match "-w[ \t]+\\([0-9]+\\)" opts
)
2365 (string-to-number (match-string 1 opts
))
2367 rows
(if (string-match "-h[ \t]+\\([0-9]+\\)" opts
)
2368 (string-to-number (match-string 1 opts
))
2369 (org-count-lines code
))
2370 fmt
(if (string-match "-l[ \t]+\"\\([^\"\n]+\\)\"" opts
)
2371 (match-string 1 opts
)))
2372 (when (and textareap
(eq backend
'html
))
2373 ;; we cannot use numbering or highlighting.
2374 (setq num nil cont nil lang nil
))
2375 (if keepp
(setq rpllbl
'keep
))
2377 (when (equal lang
"org")
2378 (setq rtn
(with-temp-buffer
2380 ;; Free up the protected lines
2381 (goto-char (point-min))
2382 (while (re-search-forward "^," nil t
)
2386 ;; Now backend-specific coding
2389 ;; We are exporting to HTML
2391 (require 'htmlize nil t
)
2392 (when (not (fboundp 'htmlize-region-for-paste
))
2393 ;; we do not have htmlize.el, or an old version of it
2396 "htmlize.el 1.34 or later is needed for source code formatting")))
2399 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
2400 (org-inhibit-startup t
)
2401 (org-startup-folded nil
))
2405 (if (functionp mode
)
2408 (font-lock-fontify-buffer)
2409 (org-export-htmlize-region-for-paste
2410 (point-min) (point-max))))
2411 (if (string-match "<pre\\([^>]*\\)>\n?" rtn
)
2412 (setq rtn
(replace-match
2413 (format "<pre class=\"src src-%s\">\n" lang
)
2417 (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"
2419 rtn
"</textarea>\n</p>\n"))
2422 (goto-char (point-min))
2423 (while (re-search-forward "[<>&]" nil t
)
2424 (replace-match (cdr (assq (char-before)
2425 '((?
&.
"&")(?
<.
"<")(?
>.
">"))))
2427 (setq rtn
(buffer-string)))
2428 (setq rtn
(concat "<pre class=\"example\">\n" rtn
"</pre>\n"))))
2430 (setq rtn
(org-export-number-lines rtn
'html
1 1 num
2432 (concat "\n#+BEGIN_HTML\n" (org-add-props rtn
'(org-protected t
)) "\n#+END_HTML\n\n"))
2433 ((eq backend
'latex
)
2434 (setq rtn
(org-export-number-lines rtn
'latex
0 0 num cont rpllbl fmt
))
2435 (concat "\n#+BEGIN_LaTeX\n"
2436 (org-add-props (concat "\\begin{verbatim}\n" rtn
"\n\\end{verbatim}\n")
2439 ((eq backend
'ascii
)
2440 ;; This is not HTML or LaTeX, so just make it an example.
2441 (setq rtn
(org-export-number-lines rtn
'ascii
0 0 num cont rpllbl fmt
))
2442 (concat "#+BEGIN_ASCII\n"
2446 (lambda (l) (concat " " l
))
2447 (org-split-string rtn
"\n")
2451 "#+END_ASCII\n"))))))
2453 (defun org-export-number-lines (text backend
2454 &optional skip1 skip2 number cont
2455 replace-labels label-format
)
2456 (if (and (not number
) (not (eq replace-labels
'keep
)))
2457 (setq replace-labels nil
)) ;; must use names if no numbers
2458 (setq skip1
(or skip1
0) skip2
(or skip2
0))
2459 (if (not cont
) (setq org-export-last-code-line-counter-value
0))
2462 (goto-char (point-max))
2463 (skip-chars-backward " \t\n\r")
2464 (delete-region (point) (point-max))
2465 (beginning-of-line (- 1 skip2
))
2466 (let* ((last (org-current-line))
2467 (n org-export-last-code-line-counter-value
)
2468 (nmax (+ n
(- last skip1
)))
2469 (fmt (format "%%%dd: " (length (number-to-string nmax
))))
2472 ((eq backend
'html
) (format "<span class=\"linenr\">%s</span>"
2474 ((eq backend
'ascii
) fmt
)
2475 ((eq backend
'latex
) fmt
)
2477 (label-format (or label-format org-coderef-label-format
))
2478 (label-pre (if (string-match "%s" label-format
)
2479 (substring label-format
0 (match-beginning 0))
2481 (label-post (if (string-match "%s" label-format
)
2482 (substring label-format
(match-end 0))
2486 ".*?\\S-.*?\\([ \t]*\\("
2487 (regexp-quote label-pre
)
2488 "\\([-a-zA-Z0-9_]+\\)"
2489 (regexp-quote label-post
)
2493 (goto-line (1+ skip1
))
2494 (while (and (re-search-forward "^" nil t
) (not (eobp)) (< n nmax
))
2496 (insert (format fm
(incf n
)))
2498 (when (and (not (eq replace-labels
'keep
))
2499 (looking-at lbl-re
))
2500 (setq ref
(match-string 3))
2503 (delete-region (match-beginning 1) (match-end 1))
2504 (push (cons ref n
) org-export-code-refs
))
2505 (goto-char (match-beginning 2))
2506 (delete-region (match-beginning 2) (match-end 2))
2507 (insert "(" ref
")")
2508 (push (cons ref
(concat "(" ref
")")) org-export-code-refs
))
2509 (when (eq backend
'html
)
2511 (beginning-of-line 1)
2512 (insert (format "<span id=\"coderef-%s\" class=\"coderef-off\">"
2515 (insert "</span>")))))
2516 (setq org-export-last-code-line-counter-value n
)
2517 (goto-char (point-max))
2523 (defvar org-last-level nil
) ; dynamically scoped variable
2524 (defvar org-min-level nil
) ; dynamically scoped variable
2525 (defvar org-levels-open nil
) ; dynamically scoped parameter
2526 (defvar org-ascii-current-indentation nil
) ; For communication
2529 (defun org-export-as-ascii (arg)
2530 "Export the outline as a pretty ASCII file.
2531 If there is an active region, export only the region.
2532 The prefix ARG specifies how many levels of the outline should become
2533 underlined headlines. The default is 3."
2535 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2536 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
2537 (org-infile-export-plist)))
2538 (region-p (org-region-active-p))
2539 (rbeg (and region-p
(region-beginning)))
2540 (rend (and region-p
(region-end)))
2545 (and (org-at-heading-p)
2546 (>= (org-end-of-subtree t t
) rend
)))))
2547 (level-offset (if subtree-p
2550 (+ (funcall outline-level
)
2551 (if org-odd-levels-only
1 0)))
2553 (opt-plist (if subtree-p
2554 (org-export-add-subtree-options opt-plist rbeg
)
2556 (custom-times org-display-custom-times
)
2557 (org-ascii-current-indentation '(0 .
0))
2561 (case-fold-search nil
)
2562 (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
2563 (filename (concat (file-name-as-directory
2564 (org-export-directory :ascii opt-plist
))
2565 (file-name-sans-extension
2567 (org-entry-get (region-beginning)
2568 "EXPORT_FILE_NAME" t
))
2569 (file-name-nondirectory bfname
)))
2571 (filename (if (equal (file-truename filename
)
2572 (file-truename bfname
))
2573 (concat filename
".txt")
2575 (buffer (find-file-noselect filename
))
2576 (org-levels-open (make-vector org-level-max nil
))
2577 (odd org-odd-levels-only
)
2578 (date (plist-get opt-plist
:date
))
2579 (author (plist-get opt-plist
:author
))
2580 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2581 (plist-get opt-plist
:title
)
2583 (plist-get opt-plist
:skip-before-1st-heading
))
2584 (org-export-grab-title-from-buffer))
2585 (file-name-sans-extension
2586 (file-name-nondirectory bfname
))))
2587 (email (plist-get opt-plist
:email
))
2588 (language (plist-get opt-plist
:language
))
2589 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2590 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
2595 (if (org-region-active-p) (region-beginning) (point-min))
2596 (if (org-region-active-p) (region-end) (point-max))))
2597 (lines (org-split-string
2598 (org-export-preprocess-string
2601 :skip-before-1st-heading
2602 (plist-get opt-plist
:skip-before-1st-heading
)
2603 :drawers
(plist-get opt-plist
:drawers
)
2604 :tags
(plist-get opt-plist
:tags
)
2605 :priority
(plist-get opt-plist
:priority
)
2606 :footnotes
(plist-get opt-plist
:footnotes
)
2607 :timestamps
(plist-get opt-plist
:timestamps
)
2608 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
2609 :verbatim-multiline t
2610 :select-tags
(plist-get opt-plist
:select-tags
)
2611 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
2613 (plist-get opt-plist
:archived-trees
)
2614 :add-text
(plist-get opt-plist
:text
))
2616 thetoc have-headings first-heading-pos
2617 table-open table-buffer link desc
)
2618 (let ((inhibit-read-only t
))
2620 (remove-text-properties (point-min) (point-max)
2621 '(:org-license-to-kill t
))))
2623 (setq org-min-level
(org-get-min-level lines level-offset
))
2624 (setq org-last-level org-min-level
)
2625 (org-init-section-numbers)
2627 (find-file-noselect filename
)
2629 (setq lang-words
(or (assoc language org-export-language-setup
)
2630 (assoc "en" org-export-language-setup
)))
2631 (switch-to-buffer-other-window buffer
)
2634 ;; create local variables for all options, to make sure all called
2635 ;; functions get the correct information
2637 (set (make-local-variable (nth 2 x
))
2638 (plist-get opt-plist
(car x
))))
2639 org-export-plist-vars
)
2640 (org-set-local 'org-odd-levels-only odd
)
2641 (setq umax
(if arg
(prefix-numeric-value arg
)
2642 org-export-headline-levels
))
2643 (setq umax-toc
(if (integerp org-export-with-toc
)
2644 (min org-export-with-toc umax
)
2648 (if title
(org-insert-centered title ?
=))
2650 (if (and (or author email
)
2651 org-export-author-info
)
2652 (insert (concat (nth 1 lang-words
) ": " (or author
"")
2653 (if email
(concat " <" email
">") "")
2657 ((and date
(string-match "%" date
))
2658 (setq date
(format-time-string date
)))
2660 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
2662 (if (and date org-export-time-stamp-file
)
2663 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
2667 (if org-export-with-toc
2669 (push (concat (nth 3 lang-words
) "\n") thetoc
)
2670 (push (concat (make-string (string-width (nth 3 lang-words
)) ?
=)
2672 (mapc '(lambda (line)
2673 (if (string-match org-todo-line-regexp
2675 ;; This is a headline
2677 (setq have-headings t
)
2678 (setq level
(- (match-end 1) (match-beginning 1)
2680 level
(org-tr-level level
)
2681 txt
(match-string 3 line
)
2683 (or (and org-export-mark-todo-in-toc
2685 (not (member (match-string 2 line
)
2686 org-done-keywords
)))
2688 (and org-export-mark-todo-in-toc
2690 (org-search-todo-below
2691 line lines level
))))
2692 (setq txt
(org-html-expand-for-ascii txt
))
2694 (while (string-match org-bracket-link-regexp txt
)
2697 (match-string (if (match-end 2) 3 1) txt
)
2700 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
2702 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
2704 (setq txt
(replace-match "" t t txt
)))
2705 (if (string-match quote-re0 txt
)
2706 (setq txt
(replace-match "" t t txt
)))
2708 (if org-export-with-section-numbers
2709 (setq txt
(concat (org-section-number level
)
2711 (if (<= level umax-toc
)
2716 (* (max 0 (- level org-min-level
)) 4) ?\
)
2717 (format (if todo
"%s (*)\n" "%s\n") txt
))
2719 (setq org-last-level level
))
2722 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2724 (org-init-section-numbers)
2725 (while (setq line
(pop lines
))
2726 ;; Remove the quoted HTML tags.
2727 (setq line
(org-html-expand-for-ascii line
))
2728 ;; Replace links with the description when possible
2729 (while (string-match org-bracket-link-regexp line
)
2730 (setq link
(match-string 1 line
)
2731 desc
(match-string (if (match-end 3) 3 1) line
))
2732 (if (and (> (length link
) 8)
2733 (equal (substring link
0 8) "coderef:"))
2734 (setq line
(replace-match
2735 (format (org-export-get-coderef-format (substring link
8) desc
)
2738 org-export-code-refs
)))
2740 (setq line
(replace-match
2741 (if (match-end 3) "[\\3]" "[\\1]")
2744 (setq line
(org-translate-time line
)))
2746 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2748 (setq first-heading-pos
(or first-heading-pos
(point)))
2749 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
2751 txt
(match-string 2 line
))
2752 (org-ascii-level-start level txt umax lines
))
2754 ((and org-export-with-tables
2755 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2756 (if (not table-open
)
2758 (setq table-open t table-buffer nil
))
2760 (setq table-buffer
(cons line table-buffer
))
2761 (when (or (not lines
)
2762 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2764 (setq table-open nil
2765 table-buffer
(nreverse table-buffer
))
2768 (org-fix-indentation x org-ascii-current-indentation
))
2769 (org-format-table-ascii table-buffer
)
2772 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
2773 ;; Remove forced line breaks
2774 (if (string-match "\\\\\\\\[ \t]*$" line
)
2775 (setq line
(replace-match "" t t line
)))
2776 (if (and org-export-with-fixed-width
2777 (string-match "^\\([ \t]*\\)\\(:\\( \\|$\\)\\)" line
))
2778 (setq line
(replace-match "\\1" nil nil line
)))
2779 (insert line
"\n"))))
2783 ;; insert the table of contents
2785 (goto-char (point-min))
2786 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
2788 (goto-char (match-beginning 0))
2790 (goto-char first-heading-pos
))
2791 (mapc 'insert thetoc
)
2792 (or (looking-at "[ \t]*\n[ \t]*\n")
2795 ;; Convert whitespace place holders
2796 (goto-char (point-min))
2798 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2799 (setq end
(next-single-property-change beg
'org-whitespace
))
2801 (delete-region beg end
)
2802 (insert (make-string (- end beg
) ?\
))))
2805 ;; remove display and invisible chars
2807 (goto-char (point-min))
2808 (while (setq beg
(next-single-property-change (point) 'display
))
2809 (setq end
(next-single-property-change beg
'display
))
2810 (delete-region beg end
)
2813 (goto-char (point-min))
2814 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
2815 (setq end
(next-single-property-change beg
'org-cwidth
))
2816 (delete-region beg end
)
2818 (goto-char (point-min))))
2820 (defun org-export-ascii-preprocess ()
2821 "Do extra work for ASCII export"
2822 ;; Put quotes around verbatim text
2823 (goto-char (point-min))
2824 (while (re-search-forward org-verbatim-re nil t
)
2825 (goto-char (match-end 2))
2826 (backward-delete-char 1) (insert "'")
2827 (goto-char (match-beginning 2))
2828 (delete-char 1) (insert "`")
2829 (goto-char (match-end 2)))
2830 (goto-char (point-min))
2831 ;; Remove target markers
2832 (while (re-search-forward "<<<?\\([^<>]*\\)>>>?\\([ \t]*\\)" nil t
)
2833 (replace-match "\\1\\2")))
2835 (defun org-search-todo-below (line lines level
)
2836 "Search the subtree below LINE for any TODO entries."
2837 (let ((rest (cdr (memq line lines
)))
2838 (re org-todo-line-regexp
)
2841 (while (setq line
(pop rest
))
2842 (if (string-match re line
)
2844 (setq lv
(- (match-end 1) (match-beginning 1))
2845 todo
(and (match-beginning 2)
2846 (not (member (match-string 2 line
)
2847 org-done-keywords
))))
2849 (if (<= lv level
) (throw 'exit nil
))
2850 (if todo
(throw 'exit t
))))))))
2852 (defun org-html-expand-for-ascii (line)
2853 "Handle quoted HTML for ASCII export."
2854 (if org-export-html-expand
2855 (while (string-match "@<[^<>\n]*>" line
)
2856 ;; We just remove the tags for now.
2857 (setq line
(replace-match "" nil nil line
))))
2860 (defun org-insert-centered (s &optional underline
)
2861 "Insert the string S centered and underline it with character UNDERLINE."
2862 (let ((ind (max (/ (- fill-column
(string-width s
)) 2) 0)))
2863 (insert (make-string ind ?\
) s
"\n")
2865 (insert (make-string ind ?\
)
2866 (make-string (string-width s
) underline
)
2869 (defun org-ascii-level-start (level title umax
&optional lines
)
2870 "Insert a new level in ASCII export."
2871 (let (char (n (- level umax
1)) (ind 0))
2874 (insert (make-string (* 2 n
) ?\
)
2875 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2876 org-export-ascii-bullets
))
2878 ;; find the indentation of the next non-empty line
2881 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2882 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2883 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2885 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2886 (if (or (not (equal (char-before) ?
\n))
2887 (not (equal (char-before (1- (point))) ?
\n)))
2889 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2890 (unless org-export-with-tags
2891 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2892 (setq title
(replace-match "" t t title
))))
2893 (if org-export-with-section-numbers
2894 (setq title
(concat (org-section-number level
) " " title
)))
2895 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2896 (setq org-ascii-current-indentation
'(0 .
0)))))
2899 (defun org-export-visible (type arg
)
2900 "Create a copy of the visible part of the current buffer, and export it.
2901 The copy is created in a temporary buffer and removed after use.
2902 TYPE is the final key (as a string) that also select the export command in
2903 the `C-c C-e' export dispatcher.
2904 As a special case, if the you type SPC at the prompt, the temporary
2905 org-mode file will not be removed but presented to you so that you can
2906 continue to use it. The prefix arg ARG is passed through to the exporting
2910 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2911 (read-char-exclusive))
2912 current-prefix-arg
))
2913 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2914 (error "Invalid export key"))
2915 (let* ((binding (cdr (assoc type
2916 '((?a . org-export-as-ascii
)
2917 (?\C-a . org-export-as-ascii
)
2918 (?b . org-export-as-html-and-open
)
2919 (?\C-b . org-export-as-html-and-open
)
2920 (?h . org-export-as-html
)
2921 (?H . org-export-as-html-to-buffer
)
2922 (?R . org-export-region-as-html
)
2923 (?x . org-export-as-xoxo
)))))
2924 (keepp (equal type ?\
))
2925 (file buffer-file-name
)
2926 (buffer (get-buffer-create "*Org Export Visible*"))
2928 ;; Need to hack the drawers here.
2930 (goto-char (point-min))
2931 (while (re-search-forward org-drawer-regexp nil t
)
2932 (goto-char (match-beginning 1))
2933 (or (org-invisible-p) (org-flag-drawer nil
))))
2934 (with-current-buffer buffer
(erase-buffer))
2936 (setq s
(goto-char (point-min)))
2937 (while (not (= (point) (point-max)))
2938 (goto-char (org-find-invisible))
2939 (append-to-buffer buffer s
(point))
2940 (setq s
(goto-char (org-find-visible))))
2941 (org-cycle-hide-drawers 'all
)
2942 (goto-char (point-min))
2944 ;; Copy all comment lines to the end, to make sure #+ settings are
2945 ;; still available for the second export step. Kind of a hack, but
2946 ;; does do the trick.
2947 (if (looking-at "#[^\r\n]*")
2948 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2949 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2950 (append-to-buffer buffer
(1+ (match-beginning 0))
2951 (min (point-max) (1+ (match-end 0))))))
2953 (let ((buffer-file-name file
)
2954 (org-inhibit-startup t
))
2957 (unless keepp
(funcall binding arg
))))
2959 (kill-buffer buffer
)
2960 (switch-to-buffer-other-window buffer
)
2961 (goto-char (point-min)))))
2963 (defun org-find-visible ()
2965 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2966 (get-char-property s
'invisible
)))
2968 (defun org-find-invisible ()
2970 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2971 (not (get-char-property s
'invisible
))))
2976 (defvar org-archive-location
) ;; gets loaded with the org-archive require.
2977 (defun org-get-current-options ()
2978 "Return a string with current options as keyword options.
2979 Does include HTML export options as well as TODO and CATEGORY stuff."
2980 (require 'org-archive
)
2987 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
2988 #+OPTIONS: TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
2990 #+EXPORT_SELECT_TAGS: %s
2991 #+EXPORT_EXCLUDE_TAGS: %s
2997 #+PRIORITIES: %c %c %c
2999 #+STARTUP: %s %s %s %s %s
3005 (buffer-name) (user-full-name) user-mail-address
3006 (format-time-string (substring (car org-time-stamp-formats
) 1 -
1))
3007 org-export-default-language
3008 org-export-headline-levels
3009 org-export-with-section-numbers
3011 org-export-preserve-breaks
3012 org-export-html-expand
3013 org-export-with-fixed-width
3014 org-export-with-tables
3015 org-export-with-sub-superscripts
3016 org-export-with-special-strings
3017 org-export-with-footnotes
3018 org-export-with-emphasize
3019 org-export-with-timestamps
3020 org-export-with-TeX-macros
3021 org-export-with-LaTeX-fragments
3022 org-export-skip-text-before-1st-heading
3023 org-export-with-drawers
3024 org-export-with-todo-keywords
3025 org-export-with-priority
3026 org-export-with-tags
3027 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
3028 (mapconcat 'identity org-export-select-tags
" ")
3029 (mapconcat 'identity org-export-exclude-tags
" ")
3030 org-export-html-link-up
3031 org-export-html-link-home
3033 (file-name-sans-extension
3034 (file-name-nondirectory (buffer-file-name (buffer-base-buffer)))))
3036 "TODO FEEDBACK VERIFY DONE"
3037 "Me Jason Marie DONE"
3038 org-highest-priority org-lowest-priority org-default-priority
3039 (mapconcat 'identity org-drawers
" ")
3040 (cdr (assoc org-startup-folded
3041 '((nil .
"showall") (t .
"overview") (content .
"content"))))
3042 (if org-odd-levels-only
"odd" "oddeven")
3043 (if org-hide-leading-stars
"hidestars" "showstars")
3044 (if org-startup-align-all-tables
"align" "noalign")
3045 (cond ((eq org-log-done t
) "logdone")
3046 ((equal org-log-done
'note
) "lognotedone")
3047 ((not org-log-done
) "nologdone"))
3048 (or (mapconcat (lambda (x)
3050 ((equal '(:startgroup
) x
) "{")
3051 ((equal '(:endgroup
) x
) "}")
3052 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
3054 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
3055 (mapconcat 'identity org-file-tags
" ")
3056 org-archive-location
3057 "org file:~/org/%s.org"
3060 (defun org-export-html-preprocess (parameters)
3061 ;; Convert LaTeX fragments to images
3062 (when (plist-get parameters
:LaTeX-fragments
)
3064 (concat "ltxpng/" (file-name-sans-extension
3065 (file-name-nondirectory
3066 org-current-export-file
)))
3067 org-current-export-dir nil
"Creating LaTeX image %s"))
3068 (message "Exporting..."))
3071 (defun org-insert-export-options-template ()
3072 "Insert into the buffer a template with information for exporting."
3074 (if (not (bolp)) (newline))
3075 (let ((s (org-get-current-options)))
3076 (and (string-match "#\\+CATEGORY" s
)
3077 (setq s
(substring s
0 (match-beginning 0))))
3081 (defun org-export-as-html-and-open (arg)
3082 "Export the outline as HTML and immediately open it with a browser.
3083 If there is an active region, export only the region.
3084 The prefix ARG specifies how many levels of the outline should become
3085 headlines. The default is 3. Lower levels will become bulleted lists."
3087 (org-export-as-html arg
'hidden
)
3088 (org-open-file buffer-file-name
))
3091 (defun org-export-as-html-batch ()
3092 "Call `org-export-as-html', may be used in batch processing as
3094 --load=$HOME/lib/emacs/org.el
3095 --eval \"(setq org-export-headline-levels 2)\"
3096 --visit=MyFile --funcall org-export-as-html-batch"
3097 (org-export-as-html org-export-headline-levels
'hidden
))
3100 (defun org-export-as-html-to-buffer (arg)
3101 "Call `org-export-as-html` with output to a temporary buffer.
3102 No file is created. The prefix ARG is passed through to `org-export-as-html'."
3104 (org-export-as-html arg nil nil
"*Org HTML Export*")
3105 (switch-to-buffer-other-window "*Org HTML Export*"))
3108 (defun org-replace-region-by-html (beg end
)
3109 "Assume the current region has org-mode syntax, and convert it to HTML.
3110 This can be used in any buffer. For example, you could write an
3111 itemized list in org-mode syntax in an HTML buffer and then use this
3112 command to convert it."
3114 (let (reg html buf pop-up-frames
)
3115 (save-window-excursion
3117 (setq html
(org-export-region-as-html
3119 (setq reg
(buffer-substring beg end
)
3120 buf
(get-buffer-create "*Org tmp*"))
3121 (with-current-buffer buf
3125 (setq html
(org-export-region-as-html
3126 (point-min) (point-max) t
'string
)))
3128 (delete-region beg end
)
3132 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
3133 "Convert region from BEG to END in org-mode buffer to HTML.
3134 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
3135 contents, and only produce the region of converted text, useful for
3136 cut-and-paste operations.
3137 If BUFFER is a buffer or a string, use/create that buffer as a target
3138 of the converted HTML. If BUFFER is the symbol `string', return the
3139 produced HTML as a string and leave not buffer behind. For example,
3140 a Lisp program could call this function in the following way:
3142 (setq html (org-export-region-as-html beg end t 'string))
3144 When called interactively, the output buffer is selected, and shown
3145 in a window. A non-interactive call will only return the buffer."
3146 (interactive "r\nP")
3147 (when (interactive-p)
3148 (setq buffer
"*Org HTML Export*"))
3149 (let ((transient-mark-mode t
) (zmacs-regions t
)
3151 (setq ext-plist
(plist-put ext-plist
:ignore-subree-p t
))
3153 (set-mark (point)) ;; to activate the region
3155 (setq rtn
(org-export-as-html
3158 (if (fboundp 'deactivate-mark
) (deactivate-mark))
3159 (if (and (interactive-p) (bufferp rtn
))
3160 (switch-to-buffer-other-window rtn
)
3163 (defvar html-table-tag nil
) ; dynamically scoped into this.
3164 (defvar org-par-open nil
)
3166 (defun org-export-as-html (arg &optional hidden ext-plist
3167 to-buffer body-only pub-dir
)
3168 "Export the outline as a pretty HTML file.
3169 If there is an active region, export only the region. The prefix
3170 ARG specifies how many levels of the outline should become
3171 headlines. The default is 3. Lower levels will become bulleted
3172 lists. When HIDDEN is non-nil, don't display the HTML buffer.
3173 EXT-PLIST is a property list with external parameters overriding
3174 org-mode's default settings, but still inferior to file-local
3175 settings. When TO-BUFFER is non-nil, create a buffer with that
3176 name and export to that buffer. If TO-BUFFER is the symbol
3177 `string', don't leave any buffer behind but just return the
3178 resulting HTML as a string. When BODY-ONLY is set, don't produce
3179 the file header and footer, simply return the content of
3180 <body>...</body>, without even the body tags themselves. When
3181 PUB-DIR is set, use this as the publishing directory."
3184 ;; Make sure we have a file name when we need it.
3185 (when (and (not (or to-buffer body-only
))
3186 (not buffer-file-name
))
3187 (if (buffer-base-buffer)
3188 (org-set-local 'buffer-file-name
3189 (with-current-buffer (buffer-base-buffer)
3191 (error "Need a file name to be able to export.")))
3193 (message "Exporting...")
3194 (setq-default org-todo-line-regexp org-todo-line-regexp
)
3195 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
3196 (setq-default org-done-keywords org-done-keywords
)
3197 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
3199 (org-export-process-option-filters
3200 (org-combine-plists (org-default-export-plist)
3202 (org-infile-export-plist))))
3203 (style (concat (if (plist-get opt-plist
:style-include-default
)
3204 org-export-html-style-default
)
3205 (plist-get opt-plist
:style
)
3206 (plist-get opt-plist
:style-extra
)
3207 "\n" org-export-html-scripts
))
3208 (html-extension (plist-get opt-plist
:html-extension
))
3209 (link-validate (plist-get opt-plist
:link-validation-function
))
3210 valid thetoc have-headings first-heading-pos
3211 (odd org-odd-levels-only
)
3212 (region-p (org-region-active-p))
3213 (rbeg (and region-p
(region-beginning)))
3214 (rend (and region-p
(region-end)))
3216 (if (plist-get opt-plist
:ignore-subree-p
)
3221 (and (org-at-heading-p)
3222 (>= (org-end-of-subtree t t
) rend
))))))
3223 (level-offset (if subtree-p
3226 (+ (funcall outline-level
)
3227 (if org-odd-levels-only
1 0)))
3229 (opt-plist (if subtree-p
3230 (org-export-add-subtree-options opt-plist rbeg
)
3232 ;; The following two are dynamically scoped into other
3234 (org-current-export-dir
3235 (or pub-dir
(org-export-directory :html opt-plist
)))
3236 (org-current-export-file buffer-file-name
)
3237 (level 0) (line "") (origline "") txt todo
3240 (filename (if to-buffer nil
3243 (file-name-sans-extension
3245 (org-entry-get (region-beginning)
3246 "EXPORT_FILE_NAME" t
))
3247 (file-name-nondirectory buffer-file-name
)))
3249 (file-name-as-directory
3250 (or pub-dir
(org-export-directory :html opt-plist
))))))
3251 (current-dir (if buffer-file-name
3252 (file-name-directory buffer-file-name
)
3254 (buffer (if to-buffer
3256 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
3257 (t (get-buffer-create to-buffer
)))
3258 (find-file-noselect filename
)))
3259 (org-levels-open (make-vector org-level-max nil
))
3260 (date (plist-get opt-plist
:date
))
3261 (author (plist-get opt-plist
:author
))
3262 (title (or (and subtree-p
(org-export-get-title-from-subtree))
3263 (plist-get opt-plist
:title
)
3265 (plist-get opt-plist
:skip-before-1st-heading
))
3266 (org-export-grab-title-from-buffer))
3267 (and buffer-file-name
3268 (file-name-sans-extension
3269 (file-name-nondirectory buffer-file-name
)))
3271 (html-table-tag (plist-get opt-plist
:html-table-tag
))
3272 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
3273 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
3278 (local-list-type nil
)
3279 (local-list-indent nil
)
3280 (llt org-plain-list-ordered-item-terminator
)
3281 (email (plist-get opt-plist
:email
))
3282 (language (plist-get opt-plist
:language
))
3286 (coding-system (and (boundp 'buffer-file-coding-system
)
3287 buffer-file-coding-system
))
3288 (coding-system-for-write (or org-export-html-coding-system
3290 (save-buffer-coding-system (or org-export-html-coding-system
3292 (charset (and coding-system-for-write
3293 (fboundp 'coding-system-get
)
3294 (coding-system-get coding-system-for-write
3298 (if region-p
(region-beginning) (point-min))
3299 (if region-p
(region-end) (point-max))))
3302 (org-export-preprocess-string
3306 :skip-before-1st-heading
3307 (plist-get opt-plist
:skip-before-1st-heading
)
3308 :drawers
(plist-get opt-plist
:drawers
)
3309 :todo-keywords
(plist-get opt-plist
:todo-keywords
)
3310 :tags
(plist-get opt-plist
:tags
)
3311 :priority
(plist-get opt-plist
:priority
)
3312 :footnotes
(plist-get opt-plist
:footnotes
)
3313 :timestamps
(plist-get opt-plist
:timestamps
)
3315 (plist-get opt-plist
:archived-trees
)
3316 :select-tags
(plist-get opt-plist
:select-tags
)
3317 :exclude-tags
(plist-get opt-plist
:exclude-tags
)
3319 (plist-get opt-plist
:text
)
3321 (plist-get opt-plist
:LaTeX-fragments
))
3324 table-buffer table-orig-buffer
3325 ind item-type starter didclose
3326 rpl path attr desc descp desc1 desc2 link
3327 snumber fnc item-tag
3328 footnotes footref-seen
3332 (let ((inhibit-read-only t
))
3334 (remove-text-properties (point-min) (point-max)
3335 '(:org-license-to-kill t
))))
3337 (message "Exporting...")
3339 (setq org-min-level
(org-get-min-level lines level-offset
))
3340 (setq org-last-level org-min-level
)
3341 (org-init-section-numbers)
3344 ((and date
(string-match "%" date
))
3345 (setq date
(format-time-string date
)))
3347 (t (setq date
(format-time-string "%Y-%m-%d %T %Z"))))
3349 ;; Get the language-dependent settings
3350 (setq lang-words
(or (assoc language org-export-language-setup
)
3351 (assoc "en" org-export-language-setup
)))
3353 ;; Switch to the output buffer
3355 (let ((inhibit-read-only t
)) (erase-buffer))
3358 (and (fboundp 'set-buffer-file-coding-system
)
3359 (set-buffer-file-coding-system coding-system-for-write
))
3361 (let ((case-fold-search nil
)
3362 (org-odd-levels-only odd
))
3363 ;; create local variables for all options, to make sure all called
3364 ;; functions get the correct information
3366 (set (make-local-variable (nth 2 x
))
3367 (plist-get opt-plist
(car x
))))
3368 org-export-plist-vars
)
3369 (setq umax
(if arg
(prefix-numeric-value arg
)
3370 org-export-headline-levels
))
3371 (setq umax-toc
(if (integerp org-export-with-toc
)
3372 (min org-export-with-toc umax
)
3377 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
3378 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
3379 <html xmlns=\"http://www.w3.org/1999/xhtml\"
3380 lang=\"%s\" xml:lang=\"%s\">
3383 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
3384 <meta name=\"generator\" content=\"Org-mode\"/>
3385 <meta name=\"generated\" content=\"%s\"/>
3386 <meta name=\"author\" content=\"%s\"/>
3390 language language
(org-html-expand title
)
3391 (or charset
"iso-8859-1") date author style
))
3393 (insert (or (plist-get opt-plist
:preamble
) ""))
3395 (when (plist-get opt-plist
:auto-preamble
)
3396 (if title
(insert (format org-export-html-title-format
3397 (org-html-expand title
))))))
3399 (if (and org-export-with-toc
(not body-only
))
3401 (push (format "<h%d>%s</h%d>\n"
3402 org-export-html-toplevel-hlevel
3404 org-export-html-toplevel-hlevel
)
3406 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
3407 (push "<ul>\n<li>" thetoc
)
3409 (mapcar '(lambda (line)
3410 (if (string-match org-todo-line-regexp line
)
3411 ;; This is a headline
3413 (setq have-headings t
)
3414 (setq level
(- (match-end 1) (match-beginning 1)
3416 level
(org-tr-level level
)
3417 txt
(save-match-data
3419 (org-export-cleanup-toc-line
3420 (match-string 3 line
))))
3422 (or (and org-export-mark-todo-in-toc
3424 (not (member (match-string 2 line
)
3425 org-done-keywords
)))
3427 (and org-export-mark-todo-in-toc
3429 (org-search-todo-below
3430 line lines level
))))
3432 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
3433 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
3434 (if (string-match quote-re0 txt
)
3435 (setq txt
(replace-match "" t t txt
)))
3436 (setq snumber
(org-section-number level
))
3437 (if org-export-with-section-numbers
3438 (setq txt
(concat snumber
" " txt
)))
3439 (if (<= level
(max umax umax-toc
))
3440 (setq head-count
(+ head-count
1)))
3441 (if (<= level umax-toc
)
3443 (if (> level org-last-level
)
3445 (setq cnt
(- level org-last-level
))
3446 (while (>= (setq cnt
(1- cnt
)) 0)
3447 (push "\n<ul>\n<li>" thetoc
))
3448 (push "\n" thetoc
)))
3449 (if (< level org-last-level
)
3451 (setq cnt
(- org-last-level level
))
3452 (while (>= (setq cnt
(1- cnt
)) 0)
3453 (push "</li>\n</ul>" thetoc
))
3454 (push "\n" thetoc
)))
3455 ;; Check for targets
3456 (while (string-match org-any-target-regexp line
)
3457 (setq line
(replace-match
3458 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3460 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
3461 (setq txt
(replace-match "" t t txt
)))
3465 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
3466 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
3467 snumber txt
) thetoc
)
3469 (setq org-last-level level
))
3473 (while (> org-last-level
(1- org-min-level
))
3474 (setq org-last-level
(1- org-last-level
))
3475 (push "</li>\n</ul>\n" thetoc
))
3476 (push "</div>\n" thetoc
)
3477 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
3480 (org-init-section-numbers)
3484 (while (setq line
(pop lines
) origline line
)
3487 ;; end of quote section?
3488 (when (and inquote
(string-match "^\\*+ " line
))
3491 ;; inside a quote section?
3493 (insert (org-html-protect line
) "\n")
3494 (throw 'nextline nil
))
3496 ;; Fixed-width, verbatim lines (examples)
3497 (when (and org-export-with-fixed-width
3498 (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line
))
3501 (org-close-par-maybe)
3502 (insert "<pre class=\"example\">\n"))
3503 (insert (org-html-protect (match-string 3 line
)) "\n")
3504 (when (or (not lines
)
3505 (not (string-match "^[ \t]*\\(:.*\\)"
3508 (insert "</pre>\n"))
3509 (throw 'nextline nil
))
3512 (when (get-text-property 0 'org-protected line
)
3514 (when (re-search-backward
3515 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
3516 (setq par
(match-string 1))
3517 (replace-match "\\2\n"))
3520 (or (= (length (car lines
)) 0)
3521 (get-text-property 0 'org-protected
(car lines
))))
3522 (insert (pop lines
) "\n"))
3523 (and par
(insert "<p>\n")))
3524 (throw 'nextline nil
))
3527 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
3529 (insert "\n</p>\n<hr/>\n<p>\n")
3530 (insert "\n<hr/>\n"))
3531 (throw 'nextline nil
))
3533 ;; Blockquotes and verse
3534 (when (equal "ORG-BLOCKQUOTE-START" line
)
3535 (org-close-par-maybe)
3536 (insert "<blockquote>\n<p>\n")
3537 (throw 'nextline nil
))
3538 (when (equal "ORG-BLOCKQUOTE-END" line
)
3539 (insert "</p>\n</blockquote>\n")
3540 (throw 'nextline nil
))
3541 (when (equal "ORG-VERSE-START" line
)
3542 (org-close-par-maybe)
3543 (insert "\n<p class=\"verse\">\n")
3545 (throw 'nextline nil
))
3546 (when (equal "ORG-VERSE-END" line
)
3549 (throw 'nextline nil
))
3551 (let ((i (org-get-string-indentation line
)))
3553 (setq line
(concat (mapconcat 'identity
3554 (make-list (* 2 i
) "\\nbsp") "")
3555 " " (org-trim line
))))
3556 (setq line
(concat line
"\\\\"))))
3558 ;; make targets to anchors
3559 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
3562 (setq line
(replace-match
3564 "@<a name=\"%s\" id=\"%s\">@</a>"
3565 (org-solidify-link-text (match-string 1 line
))
3566 (org-solidify-link-text (match-string 1 line
)))
3568 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
3569 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
3570 (setq line
(replace-match
3571 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
3572 ; (concat "@<i>" (match-string 1 line) "@</i> ")
3575 (setq line
(replace-match
3576 (concat "@<a name=\""
3577 (org-solidify-link-text (match-string 1 line
))
3578 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
3581 (setq line
(org-html-handle-time-stamps line
))
3583 ;; replace "&" by "&", "<" and ">" by "<" and ">"
3584 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
3585 ;; Also handle sub_superscripts and checkboxes
3586 (or (string-match org-table-hline-regexp line
)
3587 (setq line
(org-html-expand line
)))
3591 (while (string-match org-bracket-link-analytic-regexp
++ line start
)
3592 (setq start
(match-beginning 0))
3593 (setq path
(save-match-data (org-link-unescape
3594 (match-string 3 line
))))
3596 ((match-end 2) (match-string 2 line
))
3598 (or (file-name-absolute-p path
)
3599 (string-match "^\\.\\.?/" path
)))
3602 (setq path
(org-extract-attributes (org-link-unescape path
)))
3603 (setq attr
(get-text-property 0 'org-attributes path
))
3604 (setq desc1
(if (match-end 5) (match-string 5 line
))
3605 desc2
(if (match-end 2) (concat type
":" path
) path
)
3606 descp
(and desc1
(not (equal desc1 desc2
)))
3607 desc
(or desc1 desc2
))
3608 ;; Make an image out of the description if that is so wanted
3609 (when (and descp
(org-file-image-p
3610 desc org-export-html-inline-image-extensions
))
3612 (if (string-match "^file:" desc
)
3613 (setq desc
(substring desc
(match-end 0)))))
3614 (setq desc
(org-add-props
3615 (concat "<img src=\"" desc
"\"/>")
3616 '(org-protected t
))))
3617 ;; FIXME: do we need to unescape here somewhere?
3619 ((equal type
"internal")
3623 (org-solidify-link-text
3624 (save-match-data (org-link-unescape path
)) nil
)
3626 (org-export-html-format-desc desc
)
3628 ((and (equal type
"id")
3629 (setq id-file
(org-id-find-id-file path
)))
3630 ;; This is an id: link to another file (if it was the same file,
3631 ;; it would have become an internal link...)
3632 (setq id-file
(file-relative-name
3633 id-file
(file-name-directory org-current-export-file
)))
3634 (setq id-file
(concat (file-name-sans-extension id-file
)
3635 "." html-extension
))
3636 (setq rpl
(concat "<a href=\"" id-file
"#" path
"\""
3638 (org-export-html-format-desc desc
)
3640 ((member type
'("http" "https"))
3641 ;; standard URL, just check if we need to inline an image
3642 (if (and (or (eq t org-export-html-inline-images
)
3643 (and org-export-html-inline-images
(not descp
)))
3645 path org-export-html-inline-image-extensions
))
3646 (setq rpl
(org-export-html-format-image
3647 (concat type
":" path
) org-par-open
))
3648 (setq link
(concat type
":" path
))
3649 (setq rpl
(concat "<a href=\""
3650 (org-export-html-format-href link
)
3652 (org-export-html-format-desc desc
)
3654 ((member type
'("ftp" "mailto" "news"))
3656 (setq link
(concat type
":" path
))
3657 (setq rpl
(concat "<a href=\""
3658 (org-export-html-format-href link
)
3660 (org-export-html-format-desc desc
)
3663 ((string= type
"coderef")
3665 (setq rpl
(format "<a href=\"#coderef-%s\" class=\"coderef\" onmouseover=\"CodeHighlightOn(this, 'coderef-%s');\" onmouseout=\"CodeHighlightOff(this, 'coderef-%s');\">%s</a>"
3667 (format (org-export-get-coderef-format path
(and descp desc
))
3668 (cdr (assoc path org-export-code-refs
))))))
3670 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
3671 ;; The link protocol has a function for format the link
3674 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
3676 ((string= type
"file")
3678 (let* ((filename path
)
3679 (abs-p (file-name-absolute-p filename
))
3680 thefile file-is-image-p search
)
3682 (if (string-match "::\\(.*\\)" filename
)
3683 (setq search
(match-string 1 filename
)
3684 filename
(replace-match "" t nil filename
)))
3686 (if (functionp link-validate
)
3687 (funcall link-validate filename current-dir
)
3689 (setq file-is-image-p
3691 filename org-export-html-inline-image-extensions
))
3692 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
3693 (when (and org-export-html-link-org-files-as-html
3694 (string-match "\\.org$" thefile
))
3695 (setq thefile
(concat (substring thefile
0
3696 (match-beginning 0))
3697 "." html-extension
))
3699 ;; make sure this is can be used as target search
3700 (not (string-match "^[0-9]*$" search
))
3701 (not (string-match "^\\*" search
))
3702 (not (string-match "^/.*/$" search
)))
3703 (setq thefile
(concat thefile
"#"
3704 (org-solidify-link-text
3705 (org-link-unescape search
)))))
3706 (when (string-match "^file:" desc
)
3707 (setq desc
(replace-match "" t t desc
))
3708 (if (string-match "\\.org$" desc
)
3709 (setq desc
(replace-match "" t t desc
))))))
3710 (setq rpl
(if (and file-is-image-p
3711 (or (eq t org-export-html-inline-images
)
3712 (and org-export-html-inline-images
3715 (message "image %s %s" thefile org-par-open
)
3716 (org-export-html-format-image thefile org-par-open
))
3717 (concat "<a href=\"" thefile
"\"" attr
">"
3718 (org-export-html-format-desc desc
)
3720 (if (not valid
) (setq rpl desc
))))
3723 ;; just publish the path, as default
3724 (setq rpl
(concat "<i><" type
":"
3725 (save-match-data (org-link-unescape path
))
3727 (setq line
(replace-match rpl t t line
)
3728 start
(+ start
(length rpl
))))
3731 (if (and (string-match org-todo-line-regexp line
)
3732 (match-beginning 2))
3735 (concat (substring line
0 (match-beginning 2))
3737 (if (member (match-string 2 line
)
3740 "\">" (match-string 2 line
)
3741 "</span>" (substring line
(match-end 2)))))
3743 ;; Does this contain a reference to a footnote?
3744 (when org-export-with-footnotes
3746 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
3747 (if (get-text-property (match-beginning 2) 'org-protected line
)
3748 (setq start
(match-end 2))
3749 (let ((n (match-string 2 line
)) extra a
)
3750 (if (setq a
(assoc n footref-seen
))
3752 (setcdr a
(1+ (cdr a
)))
3753 (setq extra
(format ".%d" (cdr a
))))
3755 (push (cons n
1) footref-seen
))
3759 "%s<sup><a class=\"footref\" name=\"fnr.%s%s\" href=\"#fn.%s\">%s</a></sup>"
3760 (match-string 1 line
) n extra n n
)
3764 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
3765 ;; This is a headline
3766 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)
3768 txt
(match-string 2 line
))
3769 (if (string-match quote-re0 txt
)
3770 (setq txt
(replace-match "" t t txt
)))
3771 (if (<= level
(max umax umax-toc
))
3772 (setq head-count
(+ head-count
1)))
3774 ;; Close any local lists before inserting a new header line
3775 (while local-list-type
3776 (org-close-li (car local-list-type
))
3777 (insert (format "</%sl>\n" (car local-list-type
)))
3778 (pop local-list-type
))
3779 (setq local-list-indent nil
3781 (setq first-heading-pos
(or first-heading-pos
(point)))
3782 (org-html-level-start level txt umax
3783 (and org-export-with-toc
(<= level umax
))
3786 (when (string-match quote-re line
)
3787 (org-close-par-maybe)
3791 ((and org-export-with-tables
3792 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
3793 (if (not table-open
)
3795 (setq table-open t table-buffer nil table-orig-buffer nil
))
3797 (setq table-buffer
(cons line table-buffer
)
3798 table-orig-buffer
(cons origline table-orig-buffer
))
3799 (when (or (not lines
)
3800 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
3802 (setq table-open nil
3803 table-buffer
(nreverse table-buffer
)
3804 table-orig-buffer
(nreverse table-orig-buffer
))
3805 (org-close-par-maybe)
3806 (insert (org-format-table-html table-buffer table-orig-buffer
))))
3811 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3812 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3813 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
3814 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
3816 (setq ind
(org-get-string-indentation line
)
3817 item-type
(if (match-beginning 4) "o" "u")
3818 starter
(if (match-beginning 2)
3819 (substring (match-string 2 line
) 0 -
1))
3820 line
(substring line
(match-beginning 5))
3822 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
3824 item-tag
(match-string 1 line
)
3825 line
(substring line
(match-end 0))))
3826 (when (and (not (equal item-type
"d"))
3827 (not (string-match "[^ \t]" line
)))
3828 ;; empty line. Pretend indentation is large.
3829 (setq ind
(if org-empty-line-terminates-plain-lists
3831 (1+ (or (car local-list-indent
) 1)))))
3833 (while (and in-local-list
3834 (or (and (= ind
(car local-list-indent
))
3836 (< ind
(car local-list-indent
))))
3838 (org-close-li (car local-list-type
))
3839 (insert (format "</%sl>\n" (car local-list-type
)))
3840 (pop local-list-type
) (pop local-list-indent
)
3841 (setq in-local-list local-list-indent
))
3844 (or (not in-local-list
)
3845 (> ind
(car local-list-indent
))))
3846 ;; Start new (level of) list
3847 (org-close-par-maybe)
3849 ((equal item-type
"u") "<ul>\n<li>\n")
3850 ((equal item-type
"o") "<ol>\n<li>\n")
3851 ((equal item-type
"d")
3852 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
3853 (push item-type local-list-type
)
3854 (push ind local-list-indent
)
3855 (setq in-local-list t
))
3857 ;; continue current list
3858 (org-close-li (car local-list-type
))
3860 ((equal (car local-list-type
) "d")
3861 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
3864 ;; we did close a list, normal text follows: need <p>
3866 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
3869 (if (equal (match-string 1 line
) "X")
3871 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
3874 ;; Empty lines start a new paragraph. If hand-formatted lists
3875 ;; are not fully interpreted, lines starting with "-", "+", "*"
3876 ;; also start a new paragraph.
3877 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
3879 ;; Is this the start of a footnote?
3880 (when org-export-with-footnotes
3881 (when (and (boundp 'footnote-section-tag-regexp
)
3882 (string-match (concat "^" footnote-section-tag-regexp
)
3885 (throw 'nextline nil
))
3886 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
3887 (org-close-par-maybe)
3888 (let ((n (match-string 1 line
)))
3889 (setq org-par-open t
3891 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
3893 ;; Check if the line break needs to be conserved
3895 ((string-match "\\\\\\\\[ \t]*$" line
)
3896 (setq line
(replace-match "<br/>" t t line
)))
3897 (org-export-preserve-breaks
3898 (setq line
(concat line
"<br/>"))))
3900 ;; Check if a paragraph should be started
3902 (while (and org-par-open
3903 (string-match "\\\\par\\>" line start
))
3904 ;; Leave a space in the </p> so that the footnote matcher
3905 ;; does not see this.
3906 (if (not (get-text-property (match-beginning 0)
3907 'org-protected line
))
3908 (setq line
(replace-match "</p ><p >" t t line
)))
3909 (setq start
(match-end 0))))
3911 (insert line
"\n")))))
3913 ;; Properly close all local lists and other lists
3918 ;; Close any local lists before inserting a new header line
3919 (while local-list-type
3920 (org-close-li (car local-list-type
))
3921 (insert (format "</%sl>\n" (car local-list-type
)))
3922 (pop local-list-type
))
3923 (setq local-list-indent nil
3925 (org-html-level-start 1 nil umax
3926 (and org-export-with-toc
(<= level umax
))
3928 ;; the </div> to close the last text-... div.
3929 (when (and (> umax
0) first-heading-pos
) (insert "</div>\n"))
3932 (goto-char (point-min))
3933 (while (re-search-forward "<p class=\"footnote\">[^\000]*?\\(</p>\\|\\'\\)" nil t
)
3934 (push (match-string 0) footnotes
)
3935 (replace-match "" t t
)))
3937 (insert (format org-export-html-footnotes-section
3938 (or (nth 4 lang-words
) "Footnotes")
3939 (mapconcat 'identity
(nreverse footnotes
) "\n"))
3942 (when (plist-get opt-plist
:auto-postamble
)
3943 (insert "<div id=\"postamble\">")
3944 (when (and org-export-author-info author
)
3945 (insert "<p class=\"author\"> "
3946 (nth 1 lang-words
) ": " author
"\n")
3948 (if (listp (split-string email
",+ *"))
3950 (insert "<a href=\"mailto:" e
"\"><"
3952 (split-string email
",+ *"))
3953 (insert "<a href=\"mailto:" email
"\"><"
3954 email
"></a>\n")))
3956 (when (and date org-export-time-stamp-file
)
3957 (insert "<p class=\"date\"> "
3958 (nth 2 lang-words
) ": "
3960 (when org-export-creator-info
3961 (insert (format "<p>HTML generated by org-mode %s in emacs %s</p>\n"
3962 org-version emacs-major-version
)))
3965 (if org-export-html-with-timestamp
3966 (insert org-export-html-html-helper-timestamp
))
3967 (insert (or (plist-get opt-plist
:postamble
) ""))
3968 (insert "</body>\n</html>\n"))
3970 (unless (plist-get opt-plist
:buffer-will-be-killed
)
3972 (if (eq major-mode default-major-mode
) (html-mode)))
3974 ;; insert the table of contents
3975 (goto-char (point-min))
3977 (if (or (re-search-forward
3978 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
3980 "\\[TABLE-OF-CONTENTS\\]" nil t
))
3982 (goto-char (match-beginning 0))
3984 (goto-char first-heading-pos
)
3985 (when (looking-at "\\s-*</p>")
3986 (goto-char (match-end 0))
3988 (insert "<div id=\"table-of-contents\">\n")
3989 (mapc 'insert thetoc
)
3990 (insert "</div>\n"))
3991 ;; remove empty paragraphs and lists
3992 (goto-char (point-min))
3993 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3995 (goto-char (point-min))
3996 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3998 (goto-char (point-min))
3999 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
4001 ;; Convert whitespace place holders
4002 (goto-char (point-min))
4004 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
4005 (setq n
(get-text-property beg
'org-whitespace
)
4006 end
(next-single-property-change beg
'org-whitespace
))
4008 (delete-region beg end
)
4009 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
4010 (make-string n ?x
)))))
4011 (or to-buffer
(save-buffer))
4012 (goto-char (point-min))
4013 (message "Exporting... done")
4014 (if (eq to-buffer
'string
)
4015 (prog1 (buffer-substring (point-min) (point-max))
4016 (kill-buffer (current-buffer)))
4017 (current-buffer)))))
4019 (defun org-export-get-coderef-format (path desc
)
4021 (if (and desc
(string-match
4022 (regexp-quote (concat "(" path
")"))
4024 (replace-match "%s" t t desc
)
4028 (defun org-export-html-format-href (s)
4029 "Make sure the S is valid as a href reference in an XHTML document."
4032 (while (string-match "&" s start
)
4033 (setq start
(+ (match-beginning 0) 3)
4034 s
(replace-match "&" t t s
)))))
4037 (defun org-export-html-format-desc (s)
4038 "Make sure the S is valid as a description in a link."
4039 (if (and s
(not (get-text-property 1 'org-protected s
)))
4041 (org-html-do-expand s
))
4044 (defun org-export-html-format-image (src par-open
)
4045 "Create image tag with source and attributes."
4047 (if (string-match "^ltxpng/" src
)
4048 (format "<img src=\"%s\"/>" src
)
4049 (let* ((caption (org-find-text-property-in-string 'org-caption src
))
4050 (attr (org-find-text-property-in-string 'org-attributes src
))
4051 (label (org-find-text-property-in-string 'org-label src
)))
4052 (format "%s<div %sclass=\"figure\">
4053 <p><img src=\"%s\"%s /></p>%s
4055 (if org-par-open
"</p>\n" "")
4056 (if label
(format "id=\"%s\" " label
) "")
4058 (if (string-match "\\<alt=" (or attr
""))
4060 (concat " " attr
" alt=\"" src
"\""))
4061 (if caption
(concat "\n<p>" caption
"</p>") "")
4062 (if org-par-open
"\n<p>" ""))))))
4065 (defvar org-table-colgroup-info nil
)
4066 (defun org-format-table-ascii (lines)
4067 "Format a table for ascii export."
4069 (setq lines
(org-split-string lines
"\n")))
4070 (if (not (string-match "^[ \t]*|" (car lines
)))
4071 ;; Table made by table.el - test for spanning
4074 ;; A normal org table
4075 ;; Get rid of hlines at beginning and end
4076 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4077 (setq lines
(nreverse lines
))
4078 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4079 (setq lines
(nreverse lines
))
4080 (when org-export-table-remove-special-lines
4081 ;; Check if the table has a marking column. If yes remove the
4082 ;; column and the special lines
4083 (setq lines
(org-table-clean-before-export lines
)))
4084 ;; Get rid of the vertical lines except for grouping
4085 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
4087 (while (setq line
(pop lines
))
4088 (if (string-match org-table-hline-regexp line
)
4089 (and (string-match "|\\(.*\\)|" line
)
4090 (setq line
(replace-match " \\1" t nil line
)))
4091 (setq start
0 vl1 vl
)
4092 (while (string-match "|" line start
)
4093 (setq start
(match-end 0))
4094 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
4098 (defun org-colgroup-info-to-vline-list (info)
4101 (setq last new new
(pop info
))
4102 (if (or (memq last
'(:end
:startend
))
4103 (memq new
'(:start
:startend
)))
4106 (setq vl
(nreverse vl
))
4107 (and vl
(setcar vl nil
))
4110 (defvar org-table-number-regexp
) ; defined in org-table.el
4111 (defun org-format-table-html (lines olines
)
4112 "Find out which HTML converter to use and return the HTML code."
4114 (setq lines
(org-split-string lines
"\n")))
4115 (if (string-match "^[ \t]*|" (car lines
))
4116 ;; A normal org table
4117 (org-format-org-table-html lines
)
4118 ;; Table made by table.el - test for spanning
4119 (let* ((hlines (delq nil
(mapcar
4121 (if (string-match "^[ \t]*\\+-" x
) x
4124 (first (car hlines
))
4125 (ll (and (string-match "\\S-+" first
)
4126 (match-string 0 first
)))
4127 (re (concat "^[ \t]*" (regexp-quote ll
)))
4128 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
4130 (if (and (not spanning
)
4131 (not org-export-prefer-native-exporter-for-tables
))
4132 ;; We can use my own converter with HTML conversions
4133 (org-format-table-table-html lines
)
4134 ;; Need to use the code generator in table.el, with the original text.
4135 (org-format-table-table-html-using-table-generate-source olines
)))))
4137 (defvar org-table-number-fraction
) ; defined in org-table.el
4138 (defun org-format-org-table-html (lines &optional splice
)
4139 "Format a table into HTML."
4140 (require 'org-table
)
4141 ;; Get rid of hlines at beginning and end
4142 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4143 (setq lines
(nreverse lines
))
4144 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
4145 (setq lines
(nreverse lines
))
4146 (when org-export-table-remove-special-lines
4147 ;; Check if the table has a marking column. If yes remove the
4148 ;; column and the special lines
4149 (setq lines
(org-table-clean-before-export lines
)))
4151 (let ((caption (or (get-text-property 0 'org-caption
(car lines
))
4152 (get-text-property (or (next-single-property-change
4153 0 'org-caption
(car lines
))
4155 'org-caption
(car lines
))))
4156 (head (and org-export-highlight-first-table-line
4158 (lambda (x) (string-match "^[ \t]*|-" x
))
4162 tbopen line fields html gr colgropen
)
4163 (if splice
(setq head nil
))
4164 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
4166 (while (setq line
(pop lines
))
4168 (if (string-match "^[ \t]*|-" line
)
4171 (push (if head
"</thead>" "</tbody>") html
)
4172 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
4173 (setq head nil
) ;; head ends here, first time around
4175 (throw 'next-line t
)))
4176 ;; Break the line into fields
4177 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4178 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
4179 (setq nlines
(1+ nlines
) i -
1)
4180 (push (concat "<tr>"
4184 (if (and (< i nlines
)
4185 (string-match org-table-number-regexp x
))
4186 (incf (aref fnum i
)))
4188 (concat (car org-export-table-header-tags
) x
4189 (cdr org-export-table-header-tags
))
4190 (concat (car org-export-table-data-tags
) x
4191 (cdr org-export-table-data-tags
))))
4195 (unless splice
(if tbopen
(push "</tbody>" html
)))
4196 (unless splice
(push "</table>\n" html
))
4197 (setq html
(nreverse html
))
4199 ;; Put in col tags with the alignment (unfortunately often ignored...)
4202 (setq gr
(pop org-table-colgroup-info
))
4203 (format "%s<col align=\"%s\"></col>%s"
4204 (if (memq gr
'(:start
:startend
))
4206 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
4209 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
4211 (if (memq gr
'(:end
:startend
))
4212 (progn (setq colgropen nil
) "</colgroup>")
4216 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
4217 (if caption
(push (format "<caption>%s</caption>" caption
) html
))
4218 (push html-table-tag html
))
4219 (concat (mapconcat 'identity html
"\n") "\n")))
4221 (defun org-table-clean-before-export (lines &optional maybe-quoted
)
4222 "Check if the table has a marking column.
4223 If yes remove the column and the special lines."
4224 (setq org-table-colgroup-info nil
)
4227 (lambda (x) (or (string-match "^[ \t]*|-" x
)
4230 "^[ \t]*| *\\\\?\\([\#!$*_^ /]\\) *|"
4231 "^[ \t]*| *\\([\#!$*_^ /]\\) *|")
4235 (setq org-table-clean-did-remove-column nil
)
4240 ((string-match "^[ \t]*| */ *|" x
)
4241 (setq org-table-colgroup-info
4243 (cond ((member x
'("<" "<")) :start
)
4244 ((member x
'(">" ">")) :end
)
4245 ((member x
'("<>" "<>")) :startend
)
4247 (org-split-string x
"[ \t]*|[ \t]*")))
4251 (setq org-table-clean-did-remove-column t
)
4256 ((string-match "^[ \t]*| */ *|" x
)
4257 (setq org-table-colgroup-info
4259 (cond ((member x
'("<" "<")) :start
)
4260 ((member x
'(">" ">")) :end
)
4261 ((member x
'("<>" "<>")) :startend
)
4263 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
4265 ((string-match "^[ \t]*| *[!_^/] *|" x
)
4266 nil
) ; ignore this line
4267 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
4268 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
4269 ;; remove the first column
4270 (replace-match "\\1|" t nil x
))))
4273 (defun org-format-table-table-html (lines)
4274 "Format a table generated by table.el into HTML.
4275 This conversion does *not* use `table-generate-source' from table.el.
4276 This has the advantage that Org-mode's HTML conversions can be used.
4277 But it has the disadvantage, that no cell- or row-spanning is allowed."
4278 (let (line field-buffer
4279 (head org-export-highlight-first-table-line
)
4281 (setq html
(concat html-table-tag
"\n"))
4282 (while (setq line
(pop lines
))
4283 (setq empty
" ")
4285 (if (string-match "^[ \t]*\\+-" line
)
4296 (if (equal x
"") (setq x empty
))
4298 (concat (car org-export-table-header-tags
) x
4299 (cdr org-export-table-header-tags
))
4300 (concat (car org-export-table-data-tags
) x
4301 (cdr org-export-table-data-tags
))))
4305 (setq field-buffer nil
)))
4307 (throw 'next-line t
)))
4308 ;; Break the line into fields and store the fields
4309 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
4311 (setq field-buffer
(mapcar
4313 (concat x
"<br/>" (pop fields
)))
4315 (setq field-buffer fields
))))
4316 (setq html
(concat html
"</table>\n"))
4319 (defun org-format-table-table-html-using-table-generate-source (lines)
4320 "Format a table into html, using `table-generate-source' from table.el.
4321 This has the advantage that cell- or row-spanning is allowed.
4322 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
4324 (with-current-buffer (get-buffer-create " org-tmp1 ")
4326 (insert (mapconcat 'identity lines
"\n"))
4327 (goto-char (point-min))
4328 (if (not (re-search-forward "|[^+]" nil t
))
4329 (error "Error processing table"))
4330 (table-recognize-table)
4331 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
4332 (table-generate-source 'html
" org-tmp2 ")
4333 (set-buffer " org-tmp2 ")
4334 (buffer-substring (point-min) (point-max))))
4336 (defun org-export-splice-style (style extra
)
4337 "Splice EXTRA into STYLE, just before \"</style>\"."
4338 (if (and (stringp extra
)
4339 (string-match "\\S-" extra
)
4340 (string-match "</style>" style
))
4341 (concat (substring style
0 (match-beginning 0))
4343 (substring style
(match-beginning 0)))
4346 (defun org-html-handle-time-stamps (s)
4347 "Format time stamps in string S, or remove them."
4350 (while (string-match org-maybe-keyword-time-regexp s
)
4351 (or b
(setq b
(substring s
0 (match-beginning 0))))
4353 r
(substring s
0 (match-beginning 0))
4355 (format "@<span class=\"timestamp-kwd\">%s @</span>"
4356 (match-string 1 s
)))
4357 (format " @<span class=\"timestamp\">%s@</span>"
4359 (org-translate-time (match-string 3 s
)) 1 -
1)))
4360 s
(substring s
(match-end 0))))
4361 ;; Line break if line started and ended with time stamp stuff
4364 (setq r
(concat r s
))
4365 (unless (string-match "\\S-" (concat b s
))
4366 (setq r
(concat r
"@<br/>")))
4369 (defun org-export-htmlize-region-for-paste (beg end
)
4370 "Convert the region to HTML, using htmlize.el.
4371 This is much like `htmlize-region-for-paste', only that it uses
4372 the settings define in the org-... variables."
4373 (let* ((htmlize-output-type org-export-htmlize-output-type
)
4374 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
4375 (htmlbuf (htmlize-region beg end
)))
4377 (with-current-buffer htmlbuf
4378 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
4379 (plist-get htmlize-buffer-places
'content-end
)))
4380 (kill-buffer htmlbuf
))))
4383 (defun org-export-htmlize-generate-css ()
4384 "Create the CSS for all font definitions in the current Emacs session.
4385 Use this to create face definitions in your CSS style file that can then
4386 be used by code snippets transformed by htmlize.
4387 This command just produces a buffer that contains class definitions for all
4388 faces used in the current Emacs session. You can copy and paste the ones you
4389 need into your CSS file.
4391 If you then set `org-export-htmlize-output-type' to `css', calls to
4392 the function `org-export-htmlize-region-for-paste' will produce code
4393 that uses these same face definitions."
4396 (and (get-buffer "*html*") (kill-buffer "*html*"))
4398 (let ((fl (face-list))
4399 (htmlize-css-name-prefix "org-")
4400 (htmlize-output-type 'css
)
4402 (while (setq f
(pop fl
)
4403 i
(and f
(face-attribute f
:inherit
)))
4404 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
4405 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
4406 (htmlize-region (point-min) (point-max))))
4407 (switch-to-buffer "*html*")
4408 (goto-char (point-min))
4409 (if (re-search-forward "<style" nil t
)
4410 (delete-region (point-min) (match-beginning 0)))
4411 (if (re-search-forward "</style>" nil t
)
4412 (delete-region (1+ (match-end 0)) (point-max)))
4413 (beginning-of-line 1)
4414 (if (looking-at " +") (replace-match ""))
4415 (goto-char (point-min)))
4417 (defun org-html-protect (s)
4418 ;; convert & to &, < to < and > to >
4420 (while (string-match "&" s start
)
4421 (setq s
(replace-match "&" t t s
)
4422 start
(1+ (match-beginning 0))))
4423 (while (string-match "<" s
)
4424 (setq s
(replace-match "<" t t s
)))
4425 (while (string-match ">" s
)
4426 (setq s
(replace-match ">" t t s
)))
4427 ; (while (string-match "\"" s)
4428 ; (setq s (replace-match """ t t s)))
4432 (defun org-export-cleanup-toc-line (s)
4433 "Remove tags and timestamps from lines going into the toc."
4434 (when (memq org-export-with-tags
'(not-in-toc nil
))
4435 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
4436 (setq s
(replace-match "" t t s
))))
4437 (when org-export-remove-timestamps-from-toc
4438 (while (string-match org-maybe-keyword-time-regexp s
)
4439 (setq s
(replace-match "" t t s
))))
4440 (while (string-match org-bracket-link-regexp s
)
4441 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
4445 (defun org-html-expand (string)
4446 "Prepare STRING for HTML export. Applies all active conversions.
4447 If there are links in the string, don't modify these."
4448 (let* ((re (concat org-bracket-link-regexp
"\\|"
4449 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
4451 (while (setq m
(string-match re string
))
4452 (setq s
(substring string
0 m
)
4453 l
(match-string 0 string
)
4454 string
(substring string
(match-end 0)))
4455 (push (org-html-do-expand s
) res
)
4457 (push (org-html-do-expand string
) res
)
4458 (apply 'concat
(nreverse res
))))
4460 (defun org-html-do-expand (s)
4461 "Apply all active conversions to translate special ASCII to HTML."
4462 (setq s
(org-html-protect s
))
4463 (if org-export-html-expand
4464 (while (string-match "@<\\([^&]*\\)>" s
)
4465 (setq s
(replace-match "<\\1>" t nil s
))))
4466 (if org-export-with-emphasize
4467 (setq s
(org-export-html-convert-emphasize s
)))
4468 (if org-export-with-special-strings
4469 (setq s
(org-export-html-convert-special-strings s
)))
4470 (if org-export-with-sub-superscripts
4471 (setq s
(org-export-html-convert-sub-super s
)))
4472 (if org-export-with-TeX-macros
4473 (let ((start 0) wd ass
)
4474 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
4476 (if (get-text-property (match-beginning 0) 'org-protected s
)
4477 (setq start
(match-end 0))
4478 (setq wd
(match-string 1 s
))
4479 (if (setq ass
(assoc wd org-html-entities
))
4480 (setq s
(replace-match (or (cdr ass
)
4481 (concat "&" (car ass
) ";"))
4483 (setq start
(+ start
(length wd
))))))))
4486 (defun org-create-multibrace-regexp (left right n
)
4487 "Create a regular expression which will match a balanced sexp.
4488 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
4489 as single character strings.
4490 The regexp returned will match the entire expression including the
4491 delimiters. It will also define a single group which contains the
4492 match except for the outermost delimiters. The maximum depth of
4493 stacked delimiters is N. Escaping delimiters is not possible."
4494 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
4497 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
4500 re
(concat re or next
)
4501 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
4502 (concat left
"\\(" re
"\\)" right
)))
4504 (defvar org-match-substring-regexp
4506 "\\([^\\]\\)\\([_^]\\)\\("
4507 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4509 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
4511 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
4512 "The regular expression matching a sub- or superscript.")
4514 (defvar org-match-substring-with-braces-regexp
4516 "\\([^\\]\\)\\([_^]\\)\\("
4517 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
4519 "The regular expression matching a sub- or superscript, forcing braces.")
4521 (defconst org-export-html-special-string-regexps
4522 '(("\\\\-" .
"­")
4523 ("---\\([^-]\\)" .
"—\\1")
4524 ("--\\([^-]\\)" .
"–\\1")
4525 ("\\.\\.\\." .
"…"))
4526 "Regular expressions for special string conversion.")
4528 (defun org-export-html-convert-special-strings (string)
4529 "Convert special characters in STRING to HTML."
4530 (let ((all org-export-html-special-string-regexps
)
4532 (while (setq a
(pop all
))
4533 (setq re
(car a
) rpl
(cdr a
) start
0)
4534 (while (string-match re string start
)
4535 (if (get-text-property (match-beginning 0) 'org-protected string
)
4536 (setq start
(match-end 0))
4537 (setq string
(replace-match rpl t nil string
)))))
4540 (defun org-export-html-convert-sub-super (string)
4541 "Convert sub- and superscripts in STRING to HTML."
4542 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
4543 (while (string-match org-match-substring-regexp string s
)
4545 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
4546 ((get-text-property (match-beginning 2) 'org-protected string
)
4547 (setq s
(match-end 2)))
4549 (setq s
(match-end 1)
4550 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
4551 c
(or (match-string 8 string
)
4552 (match-string 6 string
)
4553 (match-string 5 string
))
4554 string
(replace-match
4555 (concat (match-string 1 string
)
4556 "<" key
">" c
"</" key
">")
4558 (while (string-match "\\\\\\([_^]\\)" string
)
4559 (setq string
(replace-match (match-string 1 string
) t t string
)))
4562 (defun org-export-html-convert-emphasize (string)
4565 (while (string-match org-emph-re string s
)
4567 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
4568 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
4569 (setq s
(match-beginning 0)
4572 (match-string 1 string
)
4573 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
4574 (match-string 4 string
)
4575 (nth 3 (assoc (match-string 3 string
)
4576 org-emphasis-alist
))
4577 (match-string 5 string
))
4578 string
(replace-match rpl t t string
)
4579 s
(+ s
(- (length rpl
) 2)))
4583 (defun org-open-par ()
4584 "Insert <p>, but first close previous paragraph if any."
4585 (org-close-par-maybe)
4587 (setq org-par-open t
))
4588 (defun org-close-par-maybe ()
4589 "Close paragraph if there is one open."
4592 (setq org-par-open nil
)))
4593 (defun org-close-li (&optional type
)
4594 "Close <li> if necessary."
4595 (org-close-par-maybe)
4596 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
4598 (defvar body-only
) ; dynamically scoped into this.
4599 (defun org-html-level-start (level title umax with-toc head-count
)
4600 "Insert a new level in HTML export.
4601 When TITLE is nil, just close all open levels."
4602 (org-close-par-maybe)
4603 (let* ((target (and title
(org-get-text-property-any 0 'target title
)))
4605 (mapconcat (lambda (x)
4606 (format "<a name=\"%s\" id=\"%s\"></a>"
4608 (cdr (assoc target org-export-target-aliases
))
4613 (if (aref org-levels-open
(1- l
))
4615 (org-html-level-close l umax
)
4616 (aset org-levels-open
(1- l
) nil
)))
4619 ;; If title is nil, this means this function is called to close
4620 ;; all levels, so the rest is done only if title is given
4621 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
4622 (setq title
(replace-match
4623 (if org-export-with-tags
4626 " <span class=\"tag\">"
4627 (mapconcat 'identity
(org-split-string
4628 (match-string 1 title
) ":")
4635 (if (aref org-levels-open
(1- level
))
4639 (insert (format "<li id=\"%s\">" target
) extra-targets title
"<br/>\n")
4640 (insert "<li>" title
"<br/>\n")))
4641 (aset org-levels-open
(1- level
) t
)
4642 (org-close-par-maybe)
4644 (insert (format "<ul>\n<li id=\"%s\">" target
)
4645 extra-targets title
"<br/>\n")
4646 (insert "<ul>\n<li>" title
"<br/>\n"))))
4647 (aset org-levels-open
(1- level
) t
)
4648 (setq snumber
(org-section-number level
))
4649 (if (and org-export-with-section-numbers
(not body-only
))
4650 (setq title
(concat snumber
" " title
)))
4651 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
4652 (unless (= head-count
1) (insert "\n</div>\n"))
4653 (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"
4654 snumber level level snumber extra-targets title level snumber
))
4657 (defun org-get-text-property-any (pos prop
&optional object
)
4658 (or (get-text-property pos prop object
)
4659 (and (setq pos
(next-single-property-change pos prop object
))
4660 (get-text-property pos prop object
))))
4662 (defun org-html-level-close (level max-outline-level
)
4663 "Terminate one level in HTML export."
4664 (if (<= level max-outline-level
)
4667 (insert "</ul>\n")))
4669 ;;; iCalendar export
4672 (defun org-export-icalendar-this-file ()
4673 "Export current file as an iCalendar file.
4674 The iCalendar file will be located in the same directory as the Org-mode
4675 file, but with extension `.ics'."
4677 (org-export-icalendar nil buffer-file-name
))
4680 (defun org-export-icalendar-all-agenda-files ()
4681 "Export all files in `org-agenda-files' to iCalendar .ics files.
4682 Each iCalendar file will be located in the same directory as the Org-mode
4683 file, but with extension `.ics'."
4685 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
4688 (defun org-export-icalendar-combine-agenda-files ()
4689 "Export all files in `org-agenda-files' to a single combined iCalendar file.
4690 The file is stored under the name `org-combined-agenda-icalendar-file'."
4692 (apply 'org-export-icalendar t
(org-agenda-files t
)))
4694 (defun org-export-icalendar (combine &rest files
)
4695 "Create iCalendar files for all elements of FILES.
4696 If COMBINE is non-nil, combine all calendar entries into a single large
4697 file and store it under the name `org-combined-agenda-icalendar-file'."
4699 (org-prepare-agenda-buffers files
)
4700 (let* ((dir (org-export-directory
4701 :ical
(list :publishing-directory
4702 org-export-publishing-directory
)))
4703 file ical-file ical-buffer category started org-agenda-new-buffers
)
4704 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
4707 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
4708 org-combined-agenda-icalendar-file
4709 (expand-file-name org-combined-agenda-icalendar-file dir
))
4710 ical-buffer
(org-get-agenda-file-buffer ical-file
))
4711 (set-buffer ical-buffer
) (erase-buffer))
4712 (while (setq file
(pop files
))
4714 (org-check-agenda-file file
)
4715 (set-buffer (org-get-agenda-file-buffer file
))
4717 (setq ical-file
(concat (file-name-as-directory dir
)
4718 (file-name-sans-extension
4719 (file-name-nondirectory buffer-file-name
))
4721 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
4722 (with-current-buffer ical-buffer
(erase-buffer)))
4723 (setq category
(or org-category
4724 (file-name-sans-extension
4725 (file-name-nondirectory buffer-file-name
))))
4726 (if (symbolp category
) (setq category
(symbol-name category
)))
4727 (let ((standard-output ical-buffer
))
4729 (and (not started
) (setq started t
)
4730 (org-start-icalendar-file org-icalendar-combined-name
))
4731 (org-start-icalendar-file category
))
4732 (org-print-icalendar-entries combine
)
4733 (when (or (and combine
(not files
)) (not combine
))
4734 (org-finish-icalendar-file)
4735 (set-buffer ical-buffer
)
4736 (run-hooks 'org-before-save-iCalendar-file-hook
)
4738 (run-hooks 'org-after-save-iCalendar-file-hook
)
4739 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
4741 (org-release-buffers org-agenda-new-buffers
))))
4743 (defvar org-before-save-iCalendar-file-hook nil
4744 "Hook run before an iCalendar file has been saved.
4745 This can be used to modify the result of the export.")
4747 (defvar org-after-save-iCalendar-file-hook nil
4748 "Hook run after an iCalendar file has been saved.
4749 The iCalendar buffer is still current when this hook is run.
4750 A good way to use this is to tell a desktop calendar application to re-read
4751 the iCalendar file.")
4753 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
4754 (defun org-print-icalendar-entries (&optional combine
)
4755 "Print iCalendar entries for the current Org-mode file to `standard-output'.
4756 When COMBINE is non nil, add the category to each line."
4757 (require 'org-agenda
)
4758 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
4759 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
4760 (dts (org-ical-ts-to-string
4761 (format-time-string (cdr org-time-stamp-formats
) (current-time))
4763 hd ts ts2 state status
(inc t
) pos b sexp rrule
4764 scheduledp deadlinep todo prefix due start
4765 tmp pri categories location summary desc uid
4766 (sexp-buffer (get-buffer-create "*ical-tmp*")))
4767 (org-refresh-category-properties)
4769 (goto-char (point-min))
4770 (while (re-search-forward re1 nil t
)
4773 (when (boundp 'org-icalendar-verify-function
)
4774 (unless (funcall org-icalendar-verify-function
)
4775 (outline-next-heading)
4778 (setq pos
(match-beginning 0)
4781 hd
(condition-case nil
4782 (org-icalendar-cleanup-string
4784 (error (throw :skip nil
)))
4785 summary
(org-icalendar-cleanup-string
4786 (org-entry-get nil
"SUMMARY"))
4787 desc
(org-icalendar-cleanup-string
4788 (or (org-entry-get nil
"DESCRIPTION")
4789 (and org-icalendar-include-body
(org-get-entry)))
4790 t org-icalendar-include-body
)
4791 location
(org-icalendar-cleanup-string
4792 (org-entry-get nil
"LOCATION" 'selective
))
4793 uid
(if org-icalendar-store-UID
4795 (or (org-id-get) (org-id-new)))
4796 categories
(org-export-get-categories)
4797 deadlinep nil scheduledp nil
)
4798 (if (looking-at re2
)
4800 (goto-char (match-end 0))
4801 (setq ts2
(match-string 1)
4802 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
4803 (setq tmp
(buffer-substring (max (point-min)
4804 (- pos org-ds-keyword-length
))
4806 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
4809 (replace-match "\\1" t nil ts
))
4811 deadlinep
(string-match org-deadline-regexp tmp
)
4812 scheduledp
(string-match org-scheduled-regexp tmp
)
4813 todo
(org-get-todo-state)
4814 ;; donep (org-entry-is-done-p)
4819 (not (memq 'event-if-todo org-icalendar-use-deadline
))
4820 (not (memq 'event-if-not-todo org-icalendar-use-deadline
))))
4825 (not (memq 'event-if-todo org-icalendar-use-scheduled
))
4826 (not (memq 'event-if-not-todo org-icalendar-use-scheduled
))))
4828 (setq prefix
(if deadlinep
"DL-" (if scheduledp
"SC-" "TS-")))
4829 (if (or (string-match org-tr-regexp hd
)
4830 (string-match org-ts-regexp hd
))
4831 (setq hd
(replace-match "" t t hd
)))
4832 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
4834 (concat "\nRRULE:FREQ="
4837 '(("d" .
"DAILY")("w" .
"WEEKLY")
4838 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
4839 ";INTERVAL=" (match-string 1 ts
)))
4841 (setq summary
(or summary hd
))
4842 (if (string-match org-bracket-link-regexp summary
)
4844 (replace-match (if (match-end 3)
4845 (match-string 3 summary
)
4846 (match-string 1 summary
))
4848 (if deadlinep
(setq summary
(concat "DL: " summary
)))
4849 (if scheduledp
(setq summary
(concat "S: " summary
)))
4850 (if (string-match "\\`<%%" ts
)
4851 (with-current-buffer sexp-buffer
4852 (insert (substring ts
1 -
1) " " summary
"\n"))
4853 (princ (format "BEGIN:VEVENT
4861 (org-ical-ts-to-string ts
"DTSTART")
4862 (org-ical-ts-to-string ts2
"DTEND" inc
)
4864 (if (and desc
(string-match "\\S-" desc
))
4865 (concat "\nDESCRIPTION: " desc
) "")
4866 (if (and location
(string-match "\\S-" location
))
4867 (concat "\nLOCATION: " location
) "")
4869 (when (and org-icalendar-include-sexps
4870 (condition-case nil
(require 'icalendar
) (error nil
))
4871 (fboundp 'icalendar-export-region
))
4872 ;; Get all the literal sexps
4873 (goto-char (point-min))
4874 (while (re-search-forward "^&?%%(" nil t
)
4877 (setq b
(match-beginning 0))
4878 (goto-char (1- (match-end 0)))
4881 (setq sexp
(buffer-substring b
(point)))
4882 (with-current-buffer sexp-buffer
4883 (insert sexp
"\n"))))
4884 (princ (org-diary-to-ical-string sexp-buffer
))
4885 (kill-buffer sexp-buffer
))
4887 (when org-icalendar-include-todo
4888 (setq prefix
"TODO-")
4889 (goto-char (point-min))
4890 (while (re-search-forward org-todo-line-regexp nil t
)
4893 (when (boundp 'org-icalendar-verify-function
)
4894 (unless (funcall org-icalendar-verify-function
)
4895 (outline-next-heading)
4898 (setq state
(match-string 2))
4899 (setq status
(if (member state org-done-keywords
)
4900 "COMPLETED" "NEEDS-ACTION"))
4902 (or (not (member state org-done-keywords
))
4903 (eq org-icalendar-include-todo
'all
))
4904 (not (member org-archive-tag
(org-get-tags-at)))
4906 (setq hd
(match-string 3)
4907 summary
(org-icalendar-cleanup-string
4908 (org-entry-get nil
"SUMMARY"))
4909 desc
(org-icalendar-cleanup-string
4910 (or (org-entry-get nil
"DESCRIPTION")
4911 (and org-icalendar-include-body
(org-get-entry)))
4912 t org-icalendar-include-body
)
4913 location
(org-icalendar-cleanup-string
4914 (org-entry-get nil
"LOCATION" 'selective
))
4915 due
(and (member 'todo-due org-icalendar-use-deadline
)
4916 (org-entry-get nil
"DEADLINE"))
4917 start
(and (member 'todo-start org-icalendar-use-scheduled
)
4918 (org-entry-get nil
"SCHEDULED"))
4919 categories
(org-export-get-categories)
4920 uid
(if org-icalendar-store-UID
4922 (or (org-id-get) (org-id-new))))
4923 (and due
(setq due
(org-ical-ts-to-string due
"DUE")))
4924 (and start
(setq start
(org-ical-ts-to-string start
"DTSTART")))
4926 (if (string-match org-bracket-link-regexp hd
)
4927 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
4928 (match-string 1 hd
))
4930 (if (string-match org-priority-regexp hd
)
4931 (setq pri
(string-to-char (match-string 2 hd
))
4932 hd
(concat (substring hd
0 (match-beginning 1))
4933 (substring hd
(match-end 1))))
4934 (setq pri org-default-priority
))
4935 (setq pri
(floor (- 9 (* 8.
(/ (float (- org-lowest-priority pri
))
4936 (- org-lowest-priority org-highest-priority
))))))
4938 (princ (format "BEGIN:VTODO
4950 (if (and location
(string-match "\\S-" location
))
4951 (concat "\nLOCATION: " location
) "")
4952 (if (and desc
(string-match "\\S-" desc
))
4953 (concat "\nDESCRIPTION: " desc
) "")
4954 (if due
(concat "\n" due
) "")
4958 (defun org-export-get-categories ()
4959 "Get categories according to `org-icalendar-categories'."
4960 (let ((cs org-icalendar-categories
) c rtn tmp
)
4961 (while (setq c
(pop cs
))
4963 ((eq c
'category
) (push (org-get-category) rtn
))
4965 (setq tmp
(org-get-todo-state))
4966 (and tmp
(push tmp rtn
)))
4968 (setq rtn
(append (nreverse (org-get-local-tags-at (point))) rtn
)))
4970 (setq rtn
(append (nreverse (org-get-tags-at (point))) rtn
)))))
4971 (mapconcat 'identity
(nreverse rtn
) ",")))
4973 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
4974 "Take out stuff and quote what needs to be quoted.
4975 When IS-BODY is non-nil, assume that this is the body of an item, clean up
4976 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
4981 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
4982 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
4983 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
4984 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
4986 (while (string-match "\\([,;]\\)" s start
)
4987 (setq start
(+ (match-beginning 0) 2)
4988 s
(replace-match "\\\\\\1" nil nil s
))))
4989 (setq s
(org-trim s
))
4991 (while (string-match "[ \t]*\n[ \t]*" s
)
4992 (setq s
(replace-match "\\n" t t s
))))
4995 (if (and (numberp maxlength
)
4996 (> (length s
) maxlength
))
4997 (setq s
(substring s
0 maxlength
)))))
5000 (defun org-icalendar-cleanup-string-rfc2455 (s &optional is-body maxlength
)
5001 "Take out stuff and quote what needs to be quoted.
5002 When IS-BODY is non-nil, assume that this is the body of an item, clean up
5003 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
5005 This seems to be more like RFC 2455, but it causes problems, so it is
5006 not used right now."
5010 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
5011 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
5012 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
5013 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))
5014 (setq s
(org-trim s
))
5015 (while (string-match "[ \t]*\n[ \t]*" s
)
5016 (setq s
(replace-match "\\n" t t s
)))
5018 (if (and (numberp maxlength
)
5019 (> (length s
) maxlength
))
5020 (setq s
(substring s
0 maxlength
)))))
5021 (setq s
(org-trim s
)))
5022 (while (string-match "\"" s
) (setq s
(replace-match "''" t t s
)))
5023 (when (string-match "[;,:]" s
) (setq s
(concat "\"" s
"\"")))
5026 (defun org-get-entry ()
5027 "Clean-up description string."
5029 (org-back-to-heading t
)
5030 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
5032 (defun org-start-icalendar-file (name)
5033 "Start an iCalendar file by inserting the header."
5034 (let ((user user-full-name
)
5035 (name (or name
"unknown"))
5036 (timezone (cadr (current-time-zone))))
5038 (format "BEGIN:VCALENDAR
5041 PRODID:-//%s//Emacs with Org-mode//EN
5043 CALSCALE:GREGORIAN\n" name user timezone
))))
5045 (defun org-finish-icalendar-file ()
5046 "Finish an iCalendar file by inserting the END statement."
5047 (princ "END:VCALENDAR\n"))
5049 (defun org-ical-ts-to-string (s keyword
&optional inc
)
5050 "Take a time string S and convert it to iCalendar format.
5051 KEYWORD is added in front, to make a complete line like DTSTART....
5052 When INC is non-nil, increase the hour by two (if time string contains
5053 a time), or the day by one (if it does not contain a time)."
5054 (let ((t1 (org-parse-time-string s
'nodefault
))
5055 t2 fmt have-time time
)
5056 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
5057 (setq t2 t1 have-time t
)
5058 (setq t2
(org-parse-time-string s
)))
5059 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
5060 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
5063 (if org-agenda-default-appointment-duration
5064 (setq mi
(+ org-agenda-default-appointment-duration mi
))
5067 (setq time
(encode-time s mi h d m y
)))
5068 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
5069 (concat keyword
(format-time-string fmt time
))))
5073 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
5074 (with-current-buffer buffer
5075 (apply 'insert output
)))
5076 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
5079 (defun org-export-as-xoxo (&optional buffer
)
5080 "Export the org buffer as XOXO.
5081 The XOXO buffer is named *xoxo-<source buffer name>*"
5082 (interactive (list (current-buffer)))
5083 ;; A quickie abstraction
5085 ;; Output everything as XOXO
5086 (with-current-buffer (get-buffer buffer
)
5087 (let* ((pos (point))
5088 (opt-plist (org-combine-plists (org-default-export-plist)
5089 (org-infile-export-plist)))
5090 (filename (concat (file-name-as-directory
5091 (org-export-directory :xoxo opt-plist
))
5092 (file-name-sans-extension
5093 (file-name-nondirectory buffer-file-name
))
5095 (out (find-file-noselect filename
))
5098 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
5099 ;; Check the output buffer is empty.
5100 (with-current-buffer out
(erase-buffer))
5101 ;; Kick off the output
5102 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
5103 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
5104 (let* ((hd (match-string-no-properties 1))
5107 (match-string-no-properties 2)
5109 (goto-char (match-end 0))
5114 (if (looking-at "^[ \t]\\(.*\\)")
5115 (setq str
(concat str
(match-string-no-properties 1)))
5116 (throw 'loop str
)))))))))
5118 ;; Handle level rendering
5120 ((> level last-level
)
5121 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
5123 ((< level last-level
)
5124 (dotimes (- (- last-level level
) 1)
5126 (org-export-as-xoxo-insert-into out
"</li>\n"))
5127 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5129 (org-export-as-xoxo-insert-into out
"</li>\n")
5130 (setq hanging-li nil
)))
5132 ((equal level last-level
)
5134 (org-export-as-xoxo-insert-into out
"</li>\n")))
5137 (setq last-level level
)
5139 ;; And output the new li
5140 (setq hanging-li
't
)
5141 (if (equal ?
+ (elt text
0))
5142 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
5143 (org-export-as-xoxo-insert-into out
"<li>" text
))))
5145 ;; Finally finish off the ol
5146 (dotimes (- last-level
1)
5148 (org-export-as-xoxo-insert-into out
"</li>\n"))
5149 (org-export-as-xoxo-insert-into out
"</ol>\n"))
5152 ;; Finish the buffer off and clean it up.
5153 (switch-to-buffer-other-window out
)
5154 (indent-region (point-min) (point-max) nil
)
5156 (goto-char (point-min))
5161 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
5163 ;;; org-exp.el ends here