1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35 (declare-function org-export-latex-preprocess
"org-export-latex" ())
36 (declare-function org-agenda-skip
"org-agenda" ())
37 (declare-function org-infojs-options-inbuffer-template
"org-infojs" ())
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-with-special-strings t
53 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
54 When this option is turned on, these strings will be exported as:
57 -----+----------+--------
63 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
64 :group
'org-export-translation
67 (defcustom org-export-language-setup
68 '(("en" "Author" "Date" "Table of Contents")
69 ("cs" "Autor" "Datum" "Obsah")
70 ("da" "Ophavsmand" "Dato" "Indhold")
71 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
72 ("es" "Autor" "Fecha" "\xcdndice")
73 ("fr" "Auteur" "Date" "Table des mati\xe8res")
74 ("it" "Autore" "Data" "Indice")
75 ("nl" "Auteur" "Datum" "Inhoudsopgave")
76 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
77 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
78 "Terms used in export text, translated to different languages.
79 Use the variable `org-export-default-language' to set the language,
80 or use the +OPTION lines for a per-file setting."
81 :group
'org-export-general
84 (string :tag
"HTML language tag")
85 (string :tag
"Author")
87 (string :tag
"Table of Contents"))))
89 (defcustom org-export-default-language
"en"
90 "The default language of HTML export, as a string.
91 This should have an association in `org-export-language-setup'."
92 :group
'org-export-general
95 (defcustom org-export-skip-text-before-1st-heading t
96 "Non-nil means, skip all text before the first headline when exporting.
97 When nil, that text is exported as well."
98 :group
'org-export-general
101 (defcustom org-export-headline-levels
3
102 "The last level which is still exported as a headline.
103 Inferior levels will produce itemize lists when exported.
104 Note that a numeric prefix argument to an exporter function overrides
107 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
108 :group
'org-export-general
111 (defcustom org-export-with-section-numbers t
112 "Non-nil means, add section numbers to headlines when exporting.
114 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
115 :group
'org-export-general
118 (defcustom org-export-with-toc t
119 "Non-nil means, create a table of contents in exported files.
120 The TOC contains headlines with levels up to`org-export-headline-levels'.
121 When an integer, include levels up to N in the toc, this may then be
122 different from `org-export-headline-levels', but it will not be allowed
123 to be larger than the number of headline levels.
124 When nil, no table of contents is made.
126 Headlines which contain any TODO items will be marked with \"(*)\" in
127 ASCII export, and with red color in HTML output, if the option
128 `org-export-mark-todo-in-toc' is set.
130 In HTML output, the TOC will be clickable.
132 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
134 :group
'org-export-general
136 (const :tag
"No Table of Contents" nil
)
137 (const :tag
"Full Table of Contents" t
)
138 (integer :tag
"TOC to level")))
140 (defcustom org-export-mark-todo-in-toc nil
141 "Non-nil means, mark TOC lines that contain any open TODO items."
142 :group
'org-export-general
145 (defcustom org-export-preserve-breaks nil
146 "Non-nil means, preserve all line breaks when exporting.
147 Normally, in HTML output paragraphs will be reformatted. In ASCII
148 export, line breaks will always be preserved, regardless of this variable.
150 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
151 :group
'org-export-general
154 (defcustom org-export-with-archived-trees
'headline
155 "Whether subtrees with the ARCHIVE tag should be exported.
156 This can have three different values
157 nil Do not export, pretend this tree is not present
158 t Do export the entire tree
159 headline Only export the headline, but skip the tree below it."
160 :group
'org-export-general
163 (const :tag
"not at all" nil
)
164 (const :tag
"headline only" 'headline
)
165 (const :tag
"entirely" t
)))
167 (defcustom org-export-author-info t
168 "Non-nil means, insert author name and email into the exported file.
170 This option can also be set with the +OPTIONS line,
171 e.g. \"author-info:nil\"."
172 :group
'org-export-general
175 (defcustom org-export-time-stamp-file t
176 "Non-nil means, insert a time stamp into the exported file.
177 The time stamp shows when the file was created.
179 This option can also be set with the +OPTIONS line,
180 e.g. \"timestamp:nil\"."
181 :group
'org-export-general
184 (defcustom org-export-with-timestamps t
185 "If nil, do not export time stamps and associated keywords."
186 :group
'org-export-general
189 (defcustom org-export-remove-timestamps-from-toc t
190 "If nil, remove timestamps from the table of contents entries."
191 :group
'org-export-general
194 (defcustom org-export-with-tags
'not-in-toc
195 "If nil, do not export tags, just remove them from headlines.
196 If this is the symbol `not-in-toc', tags will be removed from table of
197 contents entries, but still be shown in the headlines of the document.
199 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
200 :group
'org-export-general
202 (const :tag
"Off" nil
)
203 (const :tag
"Not in TOC" not-in-toc
)
204 (const :tag
"On" t
)))
206 (defcustom org-export-with-drawers nil
207 "Non-nil means, export with drawers like the property drawer.
208 When t, all drawers are exported. This may also be a list of
209 drawer names to export."
210 :group
'org-export-general
212 (const :tag
"All drawers" t
)
213 (const :tag
"None" nil
)
214 (repeat :tag
"Selected drawers"
215 (string :tag
"Drawer name"))))
217 (defgroup org-export-translation nil
218 "Options for translating special ascii sequences for the export backends."
219 :tag
"Org Export Translation"
222 (defcustom org-export-with-emphasize t
223 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
224 If the export target supports emphasizing text, the word will be
225 typeset in bold, italic, or underlined, respectively. Works only for
226 single words, but you can say: I *really* *mean* *this*.
227 Not all export backends support this.
229 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
230 :group
'org-export-translation
233 (defcustom org-export-with-footnotes t
234 "If nil, export [1] as a footnote marker.
235 Lines starting with [1] will be formatted as footnotes.
237 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
238 :group
'org-export-translation
241 (defcustom org-export-with-sub-superscripts t
242 "Non-nil means, interpret \"_\" and \"^\" for export.
243 When this option is turned on, you can use TeX-like syntax for sub- and
244 superscripts. Several characters after \"_\" or \"^\" will be
245 considered as a single item - so grouping with {} is normally not
246 needed. For example, the following things will be parsed as single
247 sub- or superscripts.
249 10^24 or 10^tau several digits will be considered 1 item.
250 10^-12 or 10^-tau a leading sign with digits or a word
251 x^2-y^3 will be read as x^2 - y^3, because items are
252 terminated by almost any nonword/nondigit char.
253 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
255 Still, ambiguity is possible - so when in doubt use {} to enclose the
256 sub/superscript. If you set this variable to the symbol `{}',
257 the braces are *required* in order to trigger interpretations as
258 sub/superscript. This can be helpful in documents that need \"_\"
259 frequently in plain text.
261 Not all export backends support this, but HTML does.
263 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
264 :group
'org-export-translation
266 (const :tag
"Always interpret" t
)
267 (const :tag
"Only with braces" {})
268 (const :tag
"Never interpret" nil
)))
270 (defcustom org-export-with-special-strings t
271 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
272 When this option is turned on, these strings will be exported as:
278 Not all export backends support this, but HTML does.
280 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
281 :group
'org-export-translation
284 (defcustom org-export-with-TeX-macros t
285 "Non-nil means, interpret simple TeX-like macros when exporting.
286 For example, HTML export converts \\alpha to α and \\AA to Å.
287 No only real TeX macros will work here, but the standard HTML entities
288 for math can be used as macro names as well. For a list of supported
289 names in HTML export, see the constant `org-html-entities'.
290 Not all export backends support this.
292 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
293 :group
'org-export-translation
294 :group
'org-export-latex
297 (defcustom org-export-with-LaTeX-fragments nil
298 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
299 When set, the exporter will find LaTeX environments if the \\begin line is
300 the first non-white thing on a line. It will also find the math delimiters
301 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
304 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
305 :group
'org-export-translation
306 :group
'org-export-latex
309 (defcustom org-export-with-fixed-width t
310 "Non-nil means, lines starting with \":\" will be in fixed width font.
311 This can be used to have pre-formatted text, fragments of code etc. For
313 : ;; Some Lisp examples
316 will be looking just like this in also HTML. See also the QUOTE keyword.
317 Not all export backends support this.
319 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
320 :group
'org-export-translation
323 (defcustom org-match-sexp-depth
3
324 "Number of stacked braces for sub/superscript matching.
325 This has to be set before loading org.el to be effective."
326 :group
'org-export-translation
329 (defgroup org-export-tables nil
330 "Options for exporting tables in Org-mode."
331 :tag
"Org Export Tables"
334 (defcustom org-export-with-tables t
335 "If non-nil, lines starting with \"|\" define a table.
338 | Name | Address | Birthday |
339 |-------------+----------+-----------|
340 | Arthur Dent | England | 29.2.2100 |
342 Not all export backends support this.
344 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
345 :group
'org-export-tables
348 (defcustom org-export-highlight-first-table-line t
349 "Non-nil means, highlight the first table line.
350 In HTML export, this means use <th> instead of <td>.
351 In tables created with table.el, this applies to the first table line.
352 In Org-mode tables, all lines before the first horizontal separator
353 line will be formatted with <th> tags."
354 :group
'org-export-tables
357 (defcustom org-export-table-remove-special-lines t
358 "Remove special lines and marking characters in calculating tables.
359 This removes the special marking character column from tables that are set
360 up for spreadsheet calculations. It also removes the entire lines
361 marked with `!', `_', or `^'. The lines with `$' are kept, because
362 the values of constants may be useful to have."
363 :group
'org-export-tables
366 (defcustom org-export-prefer-native-exporter-for-tables nil
367 "Non-nil means, always export tables created with table.el natively.
368 Natively means, use the HTML code generator in table.el.
369 When nil, Org-mode's own HTML generator is used when possible (i.e. if
370 the table does not use row- or column-spanning). This has the
371 advantage, that the automatic HTML conversions for math symbols and
372 sub/superscripts can be applied. Org-mode's HTML generator is also
374 :group
'org-export-tables
377 (defgroup org-export-ascii nil
378 "Options specific for ASCII export of Org-mode files."
379 :tag
"Org Export ASCII"
382 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
383 "Characters for underlining headings in ASCII export.
384 In the given sequence, these characters will be used for level 1, 2, ..."
385 :group
'org-export-ascii
386 :type
'(repeat character
))
388 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
389 "Bullet characters for headlines converted to lists in ASCII export.
390 The first character is used for the first lest level generated in this
391 way, and so on. If there are more levels than characters given here,
392 the list will be repeated.
393 Note that plain lists will keep the same bullets as the have in the
395 :group
'org-export-ascii
396 :type
'(repeat character
))
398 (defgroup org-export-xml nil
399 "Options specific for XML export of Org-mode files."
400 :tag
"Org Export XML"
403 (defgroup org-export-html nil
404 "Options specific for HTML export of Org-mode files."
405 :tag
"Org Export HTML"
408 (defcustom org-export-html-coding-system nil
409 "Coding system for HTML export, defaults to buffer-file-coding-system."
410 :group
'org-export-html
411 :type
'coding-system
)
413 (defcustom org-export-html-extension
"html"
414 "The extension for exported HTML files."
415 :group
'org-export-html
418 (defcustom org-export-html-link-up
""
419 "Where should the \"UP\" link of exported HTML pages lead?"
420 :group
'org-export-html
421 :type
'(string :tag
"File or URL"))
423 (defcustom org-export-html-link-home
""
424 "Where should the \"HOME\" link of exported HTML pages lead?"
425 :group
'org-export-html
426 :type
'(string :tag
"File or URL"))
428 (defcustom org-export-html-style
429 "<style type=\"text/css\">
431 font-family: Times, serif;
434 .title { text-align: center; }
435 .todo { color: red; }
436 .done { color: green; }
437 .timestamp { color: grey }
438 .timestamp-kwd { color: CadetBlue }
439 .tag { background-color:lightblue; font-weight:normal }
442 border: 1pt solid #AEBDCC;
443 background-color: #F3F5F7;
445 font-family: courier, monospace;
447 table { border-collapse: collapse; }
450 <!--border: 1pt solid #ADB9CC;-->
453 "The default style specification for exported HTML files.
454 Since there are different ways of setting style information, this variable
455 needs to contain the full HTML structure to provide a style, including the
456 surrounding HTML tags. The style specifications should include definitions
457 for new classes todo, done, title, and deadline. For example, valid values
460 <style type=\"text/css\">
461 p { font-weight: normal; color: gray; }
463 .title { text-align: center; }
464 .todo, .deadline { color: red; }
465 .done { color: green; }
468 or, if you want to keep the style in a file,
470 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
472 As the value of this option simply gets inserted into the HTML <head> header,
473 you can \"misuse\" it to add arbitrary text to the header."
474 :group
'org-export-html
478 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
479 "Format for typesetting the document title in HTML export."
480 :group
'org-export-html
483 (defcustom org-export-html-toplevel-hlevel
2
484 "The <H> level for level 1 headings in HTML export."
485 :group
'org-export-html
488 (defcustom org-export-html-link-org-files-as-html t
489 "Non-nil means, make file links to `file.org' point to `file.html'.
490 When org-mode is exporting an org-mode file to HTML, links to
491 non-html files are directly put into a href tag in HTML.
492 However, links to other Org-mode files (recognized by the
493 extension `.org.) should become links to the corresponding html
494 file, assuming that the linked org-mode file will also be
496 When nil, the links still point to the plain `.org' file."
497 :group
'org-export-html
500 (defcustom org-export-html-inline-images
'maybe
501 "Non-nil means, inline images into exported HTML pages.
502 This is done using an <img> tag. When nil, an anchor with href is used to
503 link to the image. If this option is `maybe', then images in links with
504 an empty description will be inlined, while images with a description will
506 :group
'org-export-html
507 :type
'(choice (const :tag
"Never" nil
)
508 (const :tag
"Always" t
)
509 (const :tag
"When there is no description" maybe
)))
512 (defcustom org-export-html-expand t
513 "Non-nil means, for HTML export, treat @<...> as HTML tag.
514 When nil, these tags will be exported as plain text and therefore
515 not be interpreted by a browser.
517 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
518 :group
'org-export-html
521 (defcustom org-export-html-table-tag
522 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
523 "The HTML tag that is used to start a table.
524 This must be a <table> tag, but you may change the options like
525 borders and spacing."
526 :group
'org-export-html
529 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
530 "The opening tag for table header fields.
531 This is customizable so that alignment options can be specified."
532 :group
'org-export-tables
533 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
535 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
536 "The opening tag for table data fields.
537 This is customizable so that alignment options can be specified."
538 :group
'org-export-tables
539 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
541 (defcustom org-export-html-with-timestamp nil
542 "If non-nil, write `org-export-html-html-helper-timestamp'
543 into the exported HTML text. Otherwise, the buffer will just be saved
545 :group
'org-export-html
548 (defcustom org-export-html-html-helper-timestamp
549 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
550 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
551 :group
'org-export-html
554 (defgroup org-export-icalendar nil
555 "Options specific for iCalendar export of Org-mode files."
556 :tag
"Org Export iCalendar"
559 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
560 "The file name for the iCalendar file covering all agenda files.
561 This file is created with the command \\[org-export-icalendar-all-agenda-files].
562 The file name should be absolute, the file will be overwritten without warning."
563 :group
'org-export-icalendar
566 (defcustom org-icalendar-include-todo nil
567 "Non-nil means, export to iCalendar files should also cover TODO items."
568 :group
'org-export-icalendar
570 (const :tag
"None" nil
)
571 (const :tag
"Unfinished" t
)
572 (const :tag
"All" all
)))
574 (defcustom org-icalendar-include-sexps t
575 "Non-nil means, export to iCalendar files should also cover sexp entries.
576 These are entries like in the diary, but directly in an Org-mode file."
577 :group
'org-export-icalendar
580 (defcustom org-icalendar-include-body
100
581 "Amount of text below headline to be included in iCalendar export.
582 This is a number of characters that should maximally be included.
583 Properties, scheduling and clocking lines will always be removed.
584 The text will be inserted into the DESCRIPTION field."
585 :group
'org-export-icalendar
587 (const :tag
"Nothing" nil
)
588 (const :tag
"Everything" t
)
589 (integer :tag
"Max characters")))
591 (defcustom org-icalendar-combined-name
"OrgMode"
592 "Calendar name for the combined iCalendar representing all agenda files."
593 :group
'org-export-icalendar
598 ;;; Variables, constants, and parameter plists
600 (defconst org-level-max
20)
602 (defvar org-export-html-preamble nil
603 "Preamble, to be inserted just after <body>. Set by publishing functions.")
604 (defvar org-export-html-postamble nil
605 "Preamble, to be inserted just before </body>. Set by publishing functions.")
606 (defvar org-export-html-auto-preamble t
607 "Should default preamble be inserted? Set by publishing functions.")
608 (defvar org-export-html-auto-postamble t
609 "Should default postamble be inserted? Set by publishing functions.")
610 (defvar org-current-export-file nil
) ; dynamically scoped parameter
611 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
613 (defconst org-export-plist-vars
614 '((:link-up . org-export-html-link-up
)
615 (:link-home . org-export-html-link-home
)
616 (:language . org-export-default-language
)
617 (:customtime . org-display-custom-times
)
618 (:headline-levels . org-export-headline-levels
)
619 (:section-numbers . org-export-with-section-numbers
)
620 (:table-of-contents . org-export-with-toc
)
621 (:preserve-breaks . org-export-preserve-breaks
)
622 (:archived-trees . org-export-with-archived-trees
)
623 (:emphasize . org-export-with-emphasize
)
624 (:sub-superscript . org-export-with-sub-superscripts
)
625 (:special-strings . org-export-with-special-strings
)
626 (:footnotes . org-export-with-footnotes
)
627 (:drawers . org-export-with-drawers
)
628 (:tags . org-export-with-tags
)
629 (:TeX-macros . org-export-with-TeX-macros
)
630 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
631 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
632 (:fixed-width . org-export-with-fixed-width
)
633 (:timestamps . org-export-with-timestamps
)
634 (:author-info . org-export-author-info
)
635 (:time-stamp-file . org-export-time-stamp-file
)
636 (:tables . org-export-with-tables
)
637 (:table-auto-headline . org-export-highlight-first-table-line
)
638 (:style . org-export-html-style
)
639 (:agenda-style . org-agenda-export-html-style
)
640 (:convert-org-links . org-export-html-link-org-files-as-html
)
641 (:inline-images . org-export-html-inline-images
)
642 (:html-extension . org-export-html-extension
)
643 (:html-table-tag . org-export-html-table-tag
)
644 (:expand-quoted-html . org-export-html-expand
)
645 (:timestamp . org-export-html-with-timestamp
)
646 (:publishing-directory . org-export-publishing-directory
)
647 (:preamble . org-export-html-preamble
)
648 (:postamble . org-export-html-postamble
)
649 (:auto-preamble . org-export-html-auto-preamble
)
650 (:auto-postamble . org-export-html-auto-postamble
)
651 (:author . user-full-name
)
652 (:email . user-mail-address
)))
654 (defun org-default-export-plist ()
655 "Return the property list with default settings for the export variables."
656 (let ((l org-export-plist-vars
) rtn e
)
657 (while (setq e
(pop l
))
658 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
661 (defvar org-export-inbuffer-options-extra nil
662 "List of additional in-buffer options that should be detected.
663 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
664 etc. Extensions can add to this list to get their options detected, and they
665 can then add a function to `org-export-options-filters' to process these
667 Each element in this list must be a list, with the in-buffer keyword as car,
668 and a property (a symbol) as the next element. All occurences of the
669 keyword will be found, the values concatenated with a space character
670 in between, and the result stored in the export options property list.")
672 (defvar org-export-options-filters nil
673 "Functions to be called to finalize the export/publishing options.
674 All these options are stored in a property list, and each of the functions
675 in this hook gets a chance to modify this property list. Each function
676 must accept the property list as an argument, and must return the (possibly
679 (defun org-infile-export-plist ()
680 "Return the property list with file-local settings for export."
685 (let ((re (org-make-options-regexp
687 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
688 "LINK_UP" "LINK_HOME")
689 (mapcar 'car org-export-inbuffer-options-extra
))))
690 p key val text options js-up js-main js-css js-opt a pr
)
691 (while (re-search-forward re nil t
)
692 (setq key
(org-match-string-no-properties 1)
693 val
(org-match-string-no-properties 2))
695 ((setq a
(assoc key org-export-inbuffer-options-extra
))
697 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
698 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
699 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
700 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
701 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
702 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
703 ((string-equal key
"TEXT")
704 (setq text
(if text
(concat text
"\n" val
) val
)))
705 ((string-equal key
"OPTIONS")
706 (setq options
(concat options
" " val
)))
707 ((string-equal key
"LINK_UP")
708 (setq p
(plist-put p
:link-up val
)))
709 ((string-equal key
"LINK_HOME")
710 (setq p
(plist-put p
:link-home val
)))))
711 (setq p
(plist-put p
:text text
))
713 (let ((op '(("H" .
:headline-levels
)
714 ("num" .
:section-numbers
)
715 ("toc" .
:table-of-contents
)
716 ("\\n" .
:preserve-breaks
)
717 ("@" .
:expand-quoted-html
)
720 ("^" .
:sub-superscript
)
721 ("-" .
:special-strings
)
726 ("TeX" .
:TeX-macros
)
727 ("LaTeX" .
:LaTeX-fragments
)
728 ("skip" .
:skip-before-1st-heading
)
729 ("author" .
:author-info
)
730 ("timestamp" .
:time-stamp-file
)))
732 (while (setq o
(pop op
))
733 (if (string-match (concat (regexp-quote (car o
))
734 ":\\([^ \t\n\r;,.]*\\)")
736 (setq p
(plist-put p
(cdr o
)
737 (car (read-from-string
738 (match-string 1 options
)))))))))
741 (defun org-export-directory (type plist
)
742 (let* ((val (plist-get plist
:publishing-directory
))
744 (or (cdr (assoc type val
)) ".")
749 (defun org-export (&optional arg
)
750 "Export dispatcher for Org-mode."
752 (let ((help "[t] insert the export option template
753 \[v] limit export to visible part of outline tree
758 \[H] export as HTML to temporary buffer
759 \[R] export region as HTML
760 \[b] export as HTML and browse immediately
764 \[L] export as LaTeX to temporary buffer
766 \[i] export current file as iCalendar file
767 \[I] export all agenda files as iCalendar files
768 \[c] export agenda files into combined iCalendar file
770 \[F] publish current file
771 \[P] publish current project
772 \[X] publish... (project will be prompted for)
773 \[A] publish all projects")
775 '((?t org-insert-export-options-template nil
)
776 (?v org-export-visible nil
)
777 (?a org-export-as-ascii t
)
778 (?h org-export-as-html t
)
779 (?b org-export-as-html-and-open t
)
780 (?H org-export-as-html-to-buffer nil
)
781 (?R org-export-region-as-html t
)
782 (?x org-export-as-xoxo t
)
783 (?l org-export-as-latex t
)
784 (?L org-export-as-latex-to-buffer nil
)
785 (?i org-export-icalendar-this-file t
)
786 (?I org-export-icalendar-all-agenda-files t
)
787 (?c org-export-icalendar-combine-agenda-files t
)
788 (?F org-publish-current-file t
)
789 (?P org-publish-current-project t
)
791 (?A org-publish-all t
)))
793 (save-window-excursion
794 (delete-other-windows)
795 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
797 (message "Select command: ")
798 (setq r1
(read-char-exclusive)))
799 (setq r2
(if (< r1
27) (+ r1
96) r1
))
800 (unless (setq ass
(assq r2 cmds
))
801 (error "No command associated with key %c" r1
))
803 ((and (equal arg
'(16)) (nth 2 ass
))
804 (let ((p (start-process
805 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
806 "*Org Export Processes*"
809 "--eval" "(require 'org-exp)"
811 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
812 "-f" (symbol-name (nth 1 ass
)))))
813 (set-process-sentinel p
'org-export-process-sentinel
)
814 (message "Process \"%s\": started in background" p
)))
816 (error "Background processing for export command `%c' is not allowed"
819 (call-interactively (nth 1 ass
))))))
821 (defun org-export-process-sentinel (process status
)
822 (if (string-match "\n+\\'" status
)
823 (setq status
(substring status
0 -
1)))
824 (message "Process \"%s\": %s" process status
))
826 (defconst org-html-entities
867 ("Aring") ("AA".
"Å")
956 ("varepsilon".
"ε")
969 ("sigmaf") ("varsigma".
"ς")
977 ("thetasym") ("vartheta".
"ϑ")
980 ("bull") ("bullet".
"•")
981 ("hellip") ("dots".
"…")
991 ("larr") ("leftarrow".
"←") ("gets".
"←")
992 ("uarr") ("uparrow".
"↑")
993 ("rarr") ("to".
"→") ("rightarrow".
"→")
994 ("darr")("downarrow".
"↓")
995 ("harr") ("leftrightarrow".
"↔")
996 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
997 ("lArr") ("Leftarrow".
"⇐")
998 ("uArr") ("Uparrow".
"⇑")
999 ("rArr") ("Rightarrow".
"⇒")
1000 ("dArr") ("Downarrow".
"⇓")
1001 ("hArr") ("Leftrightarrow".
"⇔")
1003 ("part") ("partial".
"∂")
1004 ("exist") ("exists".
"∃")
1005 ("empty") ("emptyset".
"∅")
1007 ("isin") ("in".
"∈")
1013 ("lowast") ("ast".
"∗")
1015 ("prop") ("proptp".
"∝")
1016 ("infin") ("infty".
"∞")
1017 ("ang") ("angle".
"∠")
1018 ("and") ("wedge".
"∧")
1019 ("or") ("vee".
"∨")
1025 ("cong") ("simeq".
"≅")
1026 ("asymp")("approx".
"≈")
1027 ("ne") ("neq".
"≠")
1031 ("sub") ("subset".
"⊂")
1032 ("sup") ("supset".
"⊃")
1039 ("sdot") ("cdot".
"⋅")
1046 ("loz") ("Diamond".
"◊")
1047 ("spades") ("spadesuit".
"♠")
1048 ("clubs") ("clubsuit".
"♣")
1049 ("hearts") ("diamondsuit".
"♥")
1050 ("diams") ("diamondsuit".
"♦")
1051 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1118 "Entities for TeX->HTML translation.
1119 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1120 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1121 In that case, \"\\ent\" will be translated to \"&other;\".
1122 The list contains HTML entities for Latin-1, Greek and other symbols.
1123 It is supplemented by a number of commonly used TeX macros with appropriate
1124 translations. There is currently no way for users to extend this.")
1126 ;;; General functions for all backends
1128 (defun org-export-preprocess-string (string &rest parameters
)
1129 "Cleanup STRING so that that the true exported has a more consistent source.
1130 This function takes STRING, which should be a buffer-string of an org-file
1131 to export. It then creates a temporary buffer where it does its job.
1132 The result is then again returned as a string, and the exporter works
1133 on this string to produce the exported version."
1135 (let* ((re-radio (and org-target-link-regexp
1136 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1137 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1138 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1139 (re-archive (concat ":" org-archive-tag
":"))
1140 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1141 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1142 (htmlp (plist-get parameters
:for-html
))
1143 (asciip (plist-get parameters
:for-ascii
))
1144 (latexp (plist-get parameters
:for-LaTeX
))
1145 (commentsp (plist-get parameters
:comments
))
1146 (archived-trees (plist-get parameters
:archived-trees
))
1147 (inhibit-read-only t
)
1148 (drawers org-drawers
)
1149 (exp-drawers (plist-get parameters
:drawers
))
1150 (outline-regexp "\\*+ ")
1151 target-alist tmp target level
1154 (with-current-buffer (get-buffer-create " org-mode-tmp")
1157 ;; Remove license-to-kill stuff
1158 ;; The caller markes some stuff fo killing, stuff that has been
1159 ;; used to create the page title, for example.
1160 (while (setq p
(text-property-any (point-min) (point-max)
1161 :org-license-to-kill t
))
1162 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1164 (let ((org-inhibit-startup t
)) (org-mode))
1165 (untabify (point-min) (point-max))
1167 ;; Get rid of drawers
1168 (unless (eq t exp-drawers
)
1169 (goto-char (point-min))
1170 (let ((re (concat "^[ \t]*:\\("
1173 (org-delete-all exp-drawers
1174 (copy-sequence drawers
))
1176 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1177 (while (re-search-forward re nil t
)
1178 (replace-match ""))))
1180 ;; Get the correct stuff before the first headline
1181 (when (plist-get parameters
:skip-before-1st-heading
)
1182 (goto-char (point-min))
1183 (when (re-search-forward "^\\*+[ \t]" nil t
)
1184 (delete-region (point-min) (match-beginning 0))
1185 (goto-char (point-min))
1187 (when (plist-get parameters
:add-text
)
1188 (goto-char (point-min))
1189 (insert (plist-get parameters
:add-text
) "\n"))
1191 ;; Get rid of archived trees
1192 (when (not (eq archived-trees t
))
1193 (goto-char (point-min))
1194 (while (re-search-forward re-archive nil t
)
1195 (if (not (org-on-heading-p t
))
1196 (org-end-of-subtree t
)
1197 (beginning-of-line 1)
1198 (setq a
(if archived-trees
1199 (1+ (point-at-eol)) (point))
1200 b
(org-end-of-subtree t
))
1201 (if (> b a
) (delete-region a b
)))))
1203 ;; Find all headings and compute the targets for them
1204 (goto-char (point-min))
1205 (org-init-section-numbers)
1206 (let ((re (concat "^" org-outline-regexp
)))
1207 (while (re-search-forward re nil t
)
1208 (setq level
(org-reduced-level
1209 (save-excursion (goto-char (point-at-bol))
1210 (org-outline-level))))
1211 (setq target
(org-solidify-link-text
1212 (format "sec-%s" (org-section-number level
))))
1213 (push (cons target target
) target-alist
)
1214 (add-text-properties
1215 (point-at-bol) (point-at-eol)
1216 (list 'target target
))))
1218 ;; Find targets in comments and move them out of comments,
1219 ;; but mark them as targets that should be invisible
1220 (goto-char (point-min))
1221 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1222 ;; Check if the line before or after is a headline with a target
1223 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1224 (get-text-property (point-at-bol 2) 'target
)))
1226 ;; use the existing target in a neighboring line
1227 (setq tmp
(match-string 2))
1229 (and (looking-at "\n") (delete-char 1))
1230 (push (cons (org-solidify-link-text tmp
) target
)
1232 ;; Make an invisible target
1233 (replace-match "\\1(INVISIBLE)")))
1235 ;; Protect backend specific stuff, throw away the others.
1237 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1238 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1239 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1241 (goto-char (point-min))
1242 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1243 (goto-char (match-end 0))
1244 (while (not (looking-at "#\\+END_EXAMPLE"))
1246 (beginning-of-line 2)))
1247 (goto-char (point-min))
1248 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1249 (add-text-properties (match-beginning 0) (match-end 0)
1250 '(org-protected t
)))
1252 (setq fmt
(pop formatters
))
1254 (goto-char (point-min))
1255 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1256 ":[ \t]*\\(.*\\)") nil t
)
1257 (replace-match "\\1" t
)
1258 (add-text-properties
1259 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1260 '(org-protected t
))))
1261 (goto-char (point-min))
1262 (while (re-search-forward
1264 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1265 (cadddr fmt
) "\\>.*\n?") nil t
)
1267 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1269 (delete-region (match-beginning 0) (match-end 0))))))
1271 ;; Protect quoted subtrees
1272 (goto-char (point-min))
1273 (while (re-search-forward re-quote nil t
)
1274 (goto-char (match-beginning 0))
1276 (add-text-properties (point) (org-end-of-subtree t
)
1277 '(org-protected t
)))
1279 ;; Protect verbatim elements
1280 (goto-char (point-min))
1281 (while (re-search-forward org-verbatim-re nil t
)
1282 (add-text-properties (match-beginning 4) (match-end 4)
1284 (goto-char (1+ (match-end 4))))
1286 ;; Remove subtrees that are commented
1287 (goto-char (point-min))
1288 (while (re-search-forward re-commented nil t
)
1289 (goto-char (match-beginning 0))
1290 (delete-region (point) (org-end-of-subtree t
)))
1292 ;; Remove special table lines
1293 (when org-export-table-remove-special-lines
1294 (goto-char (point-min))
1295 (while (re-search-forward "^[ \t]*|" nil t
)
1296 (beginning-of-line 1)
1297 (if (or (looking-at "[ \t]*| *[!_^] *|")
1298 (and (looking-at ".*?| *<[0-9]+> *|")
1299 (not (looking-at ".*?| *[^ <|]"))))
1300 (delete-region (max (point-min) (1- (point-at-bol)))
1304 ;; Specific LaTeX stuff
1306 (require 'org-export-latex nil
)
1307 (org-export-latex-preprocess))
1310 (org-export-ascii-clean-string))
1312 ;; Specific HTML stuff
1314 ;; Convert LaTeX fragments to images
1315 (when (plist-get parameters
:LaTeX-fragments
)
1317 (concat "ltxpng/" (file-name-sans-extension
1318 (file-name-nondirectory
1319 org-current-export-file
)))
1320 org-current-export-dir nil
"Creating LaTeX image %s"))
1321 (message "Exporting..."))
1323 ;; Remove or replace comments
1324 (goto-char (point-min))
1325 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1327 (progn (add-text-properties
1328 (match-beginning 0) (match-end 0) '(org-protected t
))
1329 (replace-match (format commentsp
(match-string 1)) t t
))
1330 (replace-match "")))
1332 ;; Find matches for radio targets and turn them into internal links
1333 (goto-char (point-min))
1335 (while (re-search-forward re-radio nil t
)
1337 (replace-match "\\1[[\\2]]"))))
1339 ;; Find all links that contain a newline and put them into a single line
1340 (goto-char (point-min))
1341 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1343 (replace-match "\\1 \\3")
1344 (goto-char (match-beginning 0))))
1346 ;; Find all internal links. If they have a fuzzy match (i.e. not
1347 ;; a *dedicated* target match, let the link point to the
1348 ;; correspinding section.
1350 (goto-char (point-min))
1351 (while (re-search-forward org-bracket-link-regexp nil t
)
1353 (let* ((md (match-data))
1354 (desc (match-end 2))
1355 (link (org-link-unescape (match-string 1)))
1356 (slink (org-solidify-link-text link
))
1359 (or (cdr (assoc slink target-alist
))
1361 (unless (string-match org-link-types-re link
)
1362 (setq found
(condition-case nil
(org-link-search link
)
1365 (or (org-on-heading-p)
1366 (not (eq found
'dedicated
))))
1367 (or (get-text-property (point) 'target
)
1370 (1- (previous-single-property-change
1375 (goto-char (match-beginning 1))
1376 (setq props
(text-properties-at (point)))
1377 (delete-region (match-beginning 1) (match-end 1))
1380 (unless desc
(insert "][" link
))
1381 (add-text-properties pos
(point) props
)))))
1383 ;; Normalize links: Convert angle and plain links into bracket links
1384 ;; Expand link abbreviations
1385 (goto-char (point-min))
1386 (while (re-search-forward re-plain-link nil t
)
1387 (goto-char (1- (match-end 0)))
1389 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1390 ":" (match-string 3) "]]")))
1391 ;; added 'org-link face to links
1392 (put-text-property 0 (length s
) 'face
'org-link s
)
1393 (replace-match s t t
))))
1394 (goto-char (point-min))
1395 (while (re-search-forward re-angle-link nil t
)
1396 (goto-char (1- (match-end 0)))
1398 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1399 ":" (match-string 3) "]]")))
1400 (put-text-property 0 (length s
) 'face
'org-link s
)
1401 (replace-match s t t
))))
1402 (goto-char (point-min))
1403 (while (re-search-forward org-bracket-link-regexp nil t
)
1405 (let* ((s (concat "[[" (setq xx
(save-match-data
1406 (org-link-expand-abbrev (match-string 1))))
1410 (concat "[" xx
"]"))
1412 (put-text-property 0 (length s
) 'face
'org-link s
)
1413 (replace-match s t t
))))
1415 ;; Find multiline emphasis and put them into single line
1416 (when (plist-get parameters
:emph-multiline
)
1417 (goto-char (point-min))
1418 (while (re-search-forward org-emph-re nil t
)
1419 (if (not (= (char-after (match-beginning 3))
1420 (char-after (match-beginning 4))))
1422 (subst-char-in-region (match-beginning 0) (match-end 0)
1424 (goto-char (1- (match-end 0))))
1425 (goto-char (1+ (match-beginning 0))))))
1427 (setq rtn
(buffer-string)))
1428 (kill-buffer " org-mode-tmp")
1431 (defun org-export-grab-title-from-buffer ()
1432 "Get a title for the current document, from looking at the buffer."
1433 (let ((inhibit-read-only t
))
1435 (goto-char (point-min))
1436 (let ((end (save-excursion (outline-next-heading) (point))))
1437 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1438 ;; Mark the line so that it will not be exported as normal text.
1440 (add-text-properties (match-beginning 0) (match-end 0)
1441 (list :org-license-to-kill t
)))
1442 ;; Return the title string
1443 (org-trim (match-string 0)))))))
1445 (defun org-export-get-title-from-subtree ()
1446 "Return subtree title and exclude it from export."
1447 (let (title (m (mark)))
1449 (goto-char (region-beginning))
1450 (when (and (org-at-heading-p)
1451 (>= (org-end-of-subtree t t
) (region-end)))
1452 ;; This is a subtree, we take the title from the first heading
1453 (goto-char (region-beginning))
1454 (looking-at org-todo-line-regexp
)
1455 (setq title
(match-string 3))
1457 (add-text-properties (point) (1+ (point-at-eol))
1458 (list :org-license-to-kill t
)))))
1461 (defun org-solidify-link-text (s &optional alist
)
1462 "Take link text and make a safe target out of it."
1467 (org-split-string s
"[ \t\r\n]+") "=="))
1468 (a (assoc rtn alist
)))
1471 (defun org-get-min-level (lines)
1472 "Get the minimum level in LINES."
1473 (let ((re "^\\(\\*+\\) ") l min
)
1475 (while (setq l
(pop lines
))
1476 (if (string-match re l
)
1477 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1480 ;; Variable holding the vector with section numbers
1481 (defvar org-section-numbers
(make-vector org-level-max
0))
1483 (defun org-init-section-numbers ()
1484 "Initialize the vector for the section numbers."
1486 (numbers (nreverse (org-split-string "" "\\.")))
1487 (depth (1- (length org-section-numbers
)))
1488 (i depth
) number-string
)
1491 (aset org-section-numbers i
0)
1492 (setq number-string
(or (car numbers
) "0"))
1493 (if (string-match "\\`[A-Z]\\'" number-string
)
1494 (aset org-section-numbers i
1495 (- (string-to-char number-string
) ?A -
1))
1496 (aset org-section-numbers i
(string-to-number number-string
)))
1500 (defun org-section-number (&optional level
)
1501 "Return a string with the current section number.
1502 When LEVEL is non-nil, increase section numbers on that level."
1503 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1506 (aset org-section-numbers
1507 level
(1+ (aref org-section-numbers level
))))
1508 (setq idx
(1+ level
))
1509 (while (<= idx depth
)
1511 (aset org-section-numbers idx
0))
1512 (setq idx
(1+ idx
))))
1514 (while (<= idx depth
)
1515 (setq n
(aref org-section-numbers idx
))
1516 (setq string
(concat string
(if (not (string= string
"")) "." "")
1518 (setq idx
(1+ idx
)))
1520 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1521 (setq string
(replace-match "" t nil string
)))
1522 (if (string-match "\\(\\.0\\)+\\'" string
)
1523 (setq string
(replace-match "" t nil string
))))
1528 (defvar org-last-level nil
) ; dynamically scoped variable
1529 (defvar org-min-level nil
) ; dynamically scoped variable
1530 (defvar org-levels-open nil
) ; dynamically scoped parameter
1531 (defvar org-ascii-current-indentation nil
) ; For communication
1534 (defun org-export-as-ascii (arg)
1535 "Export the outline as a pretty ASCII file.
1536 If there is an active region, export only the region.
1537 The prefix ARG specifies how many levels of the outline should become
1538 underlined headlines. The default is 3."
1540 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1541 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1542 (org-infile-export-plist)))
1543 (region-p (org-region-active-p))
1547 (goto-char (region-beginning))
1548 (and (org-at-heading-p)
1549 (>= (org-end-of-subtree t t
) (region-end))))))
1550 (custom-times org-display-custom-times
)
1551 (org-ascii-current-indentation '(0 .
0))
1555 (case-fold-search nil
)
1556 (filename (concat (file-name-as-directory
1557 (org-export-directory :ascii opt-plist
))
1558 (file-name-sans-extension
1560 (org-entry-get (region-beginning)
1561 "EXPORT_FILE_NAME" t
))
1562 (file-name-nondirectory buffer-file-name
)))
1564 (filename (if (equal (file-truename filename
)
1565 (file-truename buffer-file-name
))
1566 (concat filename
".txt")
1568 (buffer (find-file-noselect filename
))
1569 (org-levels-open (make-vector org-level-max nil
))
1570 (odd org-odd-levels-only
)
1571 (date (plist-get opt-plist
:date
))
1572 (author (plist-get opt-plist
:author
))
1573 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1574 (plist-get opt-plist
:title
)
1576 (plist-get opt-plist
:skip-before-1st-heading
))
1577 (org-export-grab-title-from-buffer))
1578 (file-name-sans-extension
1579 (file-name-nondirectory buffer-file-name
))))
1580 (email (plist-get opt-plist
:email
))
1581 (language (plist-get opt-plist
:language
))
1582 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1583 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1588 (if (org-region-active-p) (region-beginning) (point-min))
1589 (if (org-region-active-p) (region-end) (point-max))))
1590 (lines (org-split-string
1591 (org-export-preprocess-string
1594 :skip-before-1st-heading
1595 (plist-get opt-plist
:skip-before-1st-heading
)
1596 :drawers
(plist-get opt-plist
:drawers
)
1597 :verbatim-multiline t
1599 (plist-get opt-plist
:archived-trees
)
1600 :add-text
(plist-get opt-plist
:text
))
1602 thetoc have-headings first-heading-pos
1603 table-open table-buffer
)
1605 (let ((inhibit-read-only t
))
1607 (remove-text-properties (point-min) (point-max)
1608 '(:org-license-to-kill t
))))
1610 (setq org-min-level
(org-get-min-level lines
))
1611 (setq org-last-level org-min-level
)
1612 (org-init-section-numbers)
1614 (find-file-noselect filename
)
1616 (setq lang-words
(or (assoc language org-export-language-setup
)
1617 (assoc "en" org-export-language-setup
)))
1618 (switch-to-buffer-other-window buffer
)
1621 ;; create local variables for all options, to make sure all called
1622 ;; functions get the correct information
1624 (set (make-local-variable (cdr x
))
1625 (plist-get opt-plist
(car x
))))
1626 org-export-plist-vars
)
1627 (org-set-local 'org-odd-levels-only odd
)
1628 (setq umax
(if arg
(prefix-numeric-value arg
)
1629 org-export-headline-levels
))
1630 (setq umax-toc
(if (integerp org-export-with-toc
)
1631 (min org-export-with-toc umax
)
1635 (if title
(org-insert-centered title ?
=))
1637 (if (and (or author email
)
1638 org-export-author-info
)
1639 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1640 (if email
(concat " <" email
">") "")
1644 ((and date
(string-match "%" date
))
1645 (setq date
(format-time-string date
)))
1647 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1649 (if (and date org-export-time-stamp-file
)
1650 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1654 (if org-export-with-toc
1656 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1657 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1658 (mapc '(lambda (line)
1659 (if (string-match org-todo-line-regexp
1661 ;; This is a headline
1663 (setq have-headings t
)
1664 (setq level
(- (match-end 1) (match-beginning 1))
1665 level
(org-tr-level level
)
1666 txt
(match-string 3 line
)
1668 (or (and org-export-mark-todo-in-toc
1670 (not (member (match-string 2 line
)
1671 org-done-keywords
)))
1673 (and org-export-mark-todo-in-toc
1675 (org-search-todo-below
1676 line lines level
))))
1677 (setq txt
(org-html-expand-for-ascii txt
))
1679 (while (string-match org-bracket-link-regexp txt
)
1682 (match-string (if (match-end 2) 3 1) txt
)
1685 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1687 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1689 (setq txt
(replace-match "" t t txt
)))
1690 (if (string-match quote-re0 txt
)
1691 (setq txt
(replace-match "" t t txt
)))
1693 (if org-export-with-section-numbers
1694 (setq txt
(concat (org-section-number level
)
1696 (if (<= level umax-toc
)
1701 (* (max 0 (- level org-min-level
)) 4) ?\
)
1702 (format (if todo
"%s (*)\n" "%s\n") txt
))
1704 (setq org-last-level level
))
1707 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1709 (org-init-section-numbers)
1710 (while (setq line
(pop lines
))
1711 ;; Remove the quoted HTML tags.
1712 (setq line
(org-html-expand-for-ascii line
))
1714 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1715 (setq line
(replace-match "" t t line
)))
1716 ;; Replace internal links
1717 (while (string-match org-bracket-link-regexp line
)
1718 (setq line
(replace-match
1719 (if (match-end 3) "[\\3]" "[\\1]")
1722 (setq line
(org-translate-time line
)))
1724 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1726 (setq first-heading-pos
(or first-heading-pos
(point)))
1727 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1728 txt
(match-string 2 line
))
1729 (org-ascii-level-start level txt umax lines
))
1731 ((and org-export-with-tables
1732 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1733 (if (not table-open
)
1735 (setq table-open t table-buffer nil
))
1737 (setq table-buffer
(cons line table-buffer
))
1738 (when (or (not lines
)
1739 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1741 (setq table-open nil
1742 table-buffer
(nreverse table-buffer
))
1745 (org-fix-indentation x org-ascii-current-indentation
))
1746 (org-format-table-ascii table-buffer
)
1749 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1750 (if (and org-export-with-fixed-width
1751 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1752 (setq line
(replace-match "\\1" nil nil line
)))
1753 (insert line
"\n"))))
1757 ;; insert the table of contents
1759 (goto-char (point-min))
1760 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1762 (goto-char (match-beginning 0))
1764 (goto-char first-heading-pos
))
1765 (mapc 'insert thetoc
)
1766 (or (looking-at "[ \t]*\n[ \t]*\n")
1769 ;; Convert whitespace place holders
1770 (goto-char (point-min))
1772 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1773 (setq end
(next-single-property-change beg
'org-whitespace
))
1775 (delete-region beg end
)
1776 (insert (make-string (- end beg
) ?\
))))
1779 ;; remove display and invisible chars
1781 (goto-char (point-min))
1782 (while (setq beg
(next-single-property-change (point) 'display
))
1783 (setq end
(next-single-property-change beg
'display
))
1784 (delete-region beg end
)
1787 (goto-char (point-min))
1788 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1789 (setq end
(next-single-property-change beg
'org-cwidth
))
1790 (delete-region beg end
)
1792 (goto-char (point-min))))
1794 (defun org-export-ascii-clean-string ()
1795 "Do extra work for ASCII export"
1796 (goto-char (point-min))
1797 (while (re-search-forward org-verbatim-re nil t
)
1798 (goto-char (match-end 2))
1799 (backward-delete-char 1) (insert "'")
1800 (goto-char (match-beginning 2))
1801 (delete-char 1) (insert "`")
1802 (goto-char (match-end 2))))
1804 (defun org-search-todo-below (line lines level
)
1805 "Search the subtree below LINE for any TODO entries."
1806 (let ((rest (cdr (memq line lines
)))
1807 (re org-todo-line-regexp
)
1810 (while (setq line
(pop rest
))
1811 (if (string-match re line
)
1813 (setq lv
(- (match-end 1) (match-beginning 1))
1814 todo
(and (match-beginning 2)
1815 (not (member (match-string 2 line
)
1816 org-done-keywords
))))
1818 (if (<= lv level
) (throw 'exit nil
))
1819 (if todo
(throw 'exit t
))))))))
1821 (defun org-html-expand-for-ascii (line)
1822 "Handle quoted HTML for ASCII export."
1823 (if org-export-html-expand
1824 (while (string-match "@<[^<>\n]*>" line
)
1825 ;; We just remove the tags for now.
1826 (setq line
(replace-match "" nil nil line
))))
1829 (defun org-insert-centered (s &optional underline
)
1830 "Insert the string S centered and underline it with character UNDERLINE."
1831 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
1832 (insert (make-string ind ?\
) s
"\n")
1834 (insert (make-string ind ?\
)
1835 (make-string (string-width s
) underline
)
1838 (defun org-ascii-level-start (level title umax
&optional lines
)
1839 "Insert a new level in ASCII export."
1840 (let (char (n (- level umax
1)) (ind 0))
1843 (insert (make-string (* 2 n
) ?\
)
1844 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
1845 org-export-ascii-bullets
))
1847 ;; find the indentation of the next non-empty line
1850 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
1851 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
1852 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
1854 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
1855 (if (or (not (equal (char-before) ?
\n))
1856 (not (equal (char-before (1- (point))) ?
\n)))
1858 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
1859 (unless org-export-with-tags
1860 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
1861 (setq title
(replace-match "" t t title
))))
1862 (if org-export-with-section-numbers
1863 (setq title
(concat (org-section-number level
) " " title
)))
1864 (insert title
"\n" (make-string (string-width title
) char
) "\n")
1865 (setq org-ascii-current-indentation
'(0 .
0)))))
1868 (defun org-export-visible (type arg
)
1869 "Create a copy of the visible part of the current buffer, and export it.
1870 The copy is created in a temporary buffer and removed after use.
1871 TYPE is the final key (as a string) that also select the export command in
1872 the `C-c C-e' export dispatcher.
1873 As a special case, if the you type SPC at the prompt, the temporary
1874 org-mode file will not be removed but presented to you so that you can
1875 continue to use it. The prefix arg ARG is passed through to the exporting
1879 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
1880 (read-char-exclusive))
1881 current-prefix-arg
))
1882 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
1883 (error "Invalid export key"))
1884 (let* ((binding (cdr (assoc type
1885 '((?a . org-export-as-ascii
)
1886 (?\C-a . org-export-as-ascii
)
1887 (?b . org-export-as-html-and-open
)
1888 (?\C-b . org-export-as-html-and-open
)
1889 (?h . org-export-as-html
)
1890 (?H . org-export-as-html-to-buffer
)
1891 (?R . org-export-region-as-html
)
1892 (?x . org-export-as-xoxo
)))))
1893 (keepp (equal type ?\
))
1894 (file buffer-file-name
)
1895 (buffer (get-buffer-create "*Org Export Visible*"))
1897 ;; Need to hack the drawers here.
1899 (goto-char (point-min))
1900 (while (re-search-forward org-drawer-regexp nil t
)
1901 (goto-char (match-beginning 1))
1902 (or (org-invisible-p) (org-flag-drawer nil
))))
1903 (with-current-buffer buffer
(erase-buffer))
1905 (setq s
(goto-char (point-min)))
1906 (while (not (= (point) (point-max)))
1907 (goto-char (org-find-invisible))
1908 (append-to-buffer buffer s
(point))
1909 (setq s
(goto-char (org-find-visible))))
1910 (org-cycle-hide-drawers 'all
)
1911 (goto-char (point-min))
1913 ;; Copy all comment lines to the end, to make sure #+ settings are
1914 ;; still available for the second export step. Kind of a hack, but
1915 ;; does do the trick.
1916 (if (looking-at "#[^\r\n]*")
1917 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
1918 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
1919 (append-to-buffer buffer
(1+ (match-beginning 0))
1920 (min (point-max) (1+ (match-end 0))))))
1922 (let ((buffer-file-name file
)
1923 (org-inhibit-startup t
))
1926 (unless keepp
(funcall binding arg
))))
1928 (kill-buffer buffer
)
1929 (switch-to-buffer-other-window buffer
)
1930 (goto-char (point-min)))))
1932 (defun org-find-visible ()
1934 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
1935 (get-char-property s
'invisible
)))
1937 (defun org-find-invisible ()
1939 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
1940 (not (get-char-property s
'invisible
))))
1945 (defvar org-archive-location
) ;; gets loades with the org-archive require.
1946 (defun org-get-current-options ()
1947 "Return a string with current options as keyword options.
1948 Does include HTML export options as well as TODO and CATEGORY stuff."
1949 (require 'org-archive
)
1956 #+TEXT: Some descriptive text to be emitted. Several lines OK.
1957 #+OPTIONS: H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s TeX:%s LaTeX:%s skip:%s d:%s tags:%s
1964 #+PRIORITIES: %c %c %c
1966 #+STARTUP: %s %s %s %s %s
1971 (buffer-name) (user-full-name) user-mail-address
1972 (format-time-string (car org-time-stamp-formats
))
1973 org-export-default-language
1974 org-export-headline-levels
1975 org-export-with-section-numbers
1977 org-export-preserve-breaks
1978 org-export-html-expand
1979 org-export-with-fixed-width
1980 org-export-with-tables
1981 org-export-with-sub-superscripts
1982 org-export-with-special-strings
1983 org-export-with-footnotes
1984 org-export-with-emphasize
1985 org-export-with-TeX-macros
1986 org-export-with-LaTeX-fragments
1987 org-export-skip-text-before-1st-heading
1988 org-export-with-drawers
1989 org-export-with-tags
1990 (if (featurep 'org-infojs
) (org-infojs-options-inbuffer-template) "")
1991 org-export-html-link-up
1992 org-export-html-link-home
1993 (file-name-nondirectory buffer-file-name
)
1994 "TODO FEEDBACK VERIFY DONE"
1995 "Me Jason Marie DONE"
1996 org-highest-priority org-lowest-priority org-default-priority
1997 (mapconcat 'identity org-drawers
" ")
1998 (cdr (assoc org-startup-folded
1999 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2000 (if org-odd-levels-only
"odd" "oddeven")
2001 (if org-hide-leading-stars
"hidestars" "showstars")
2002 (if org-startup-align-all-tables
"align" "noalign")
2003 (cond ((eq org-log-done t
) "logdone")
2004 ((equal org-log-done
'note
) "lognotedone")
2005 ((not org-log-done
) "nologdone"))
2006 (or (mapconcat (lambda (x)
2008 ((equal '(:startgroup
) x
) "{")
2009 ((equal '(:endgroup
) x
) "}")
2010 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2012 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2013 org-archive-location
2014 "org file:~/org/%s.org"
2018 (defun org-insert-export-options-template ()
2019 "Insert into the buffer a template with information for exporting."
2021 (if (not (bolp)) (newline))
2022 (let ((s (org-get-current-options)))
2023 (and (string-match "#\\+CATEGORY" s
)
2024 (setq s
(substring s
0 (match-beginning 0))))
2028 (defun org-export-as-html-and-open (arg)
2029 "Export the outline as HTML and immediately open it with a browser.
2030 If there is an active region, export only the region.
2031 The prefix ARG specifies how many levels of the outline should become
2032 headlines. The default is 3. Lower levels will become bulleted lists."
2034 (org-export-as-html arg
'hidden
)
2035 (org-open-file buffer-file-name
))
2038 (defun org-export-as-html-batch ()
2039 "Call `org-export-as-html', may be used in batch processing as
2041 --load=$HOME/lib/emacs/org.el
2042 --eval \"(setq org-export-headline-levels 2)\"
2043 --visit=MyFile --funcall org-export-as-html-batch"
2044 (org-export-as-html org-export-headline-levels
'hidden
))
2047 (defun org-export-as-html-to-buffer (arg)
2048 "Call `org-exort-as-html` with output to a temporary buffer.
2049 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2051 (org-export-as-html arg nil nil
"*Org HTML Export*")
2052 (switch-to-buffer-other-window "*Org HTML Export*"))
2055 (defun org-replace-region-by-html (beg end
)
2056 "Assume the current region has org-mode syntax, and convert it to HTML.
2057 This can be used in any buffer. For example, you could write an
2058 itemized list in org-mode syntax in an HTML buffer and then use this
2059 command to convert it."
2061 (let (reg html buf pop-up-frames
)
2062 (save-window-excursion
2064 (setq html
(org-export-region-as-html
2066 (setq reg
(buffer-substring beg end
)
2067 buf
(get-buffer-create "*Org tmp*"))
2068 (with-current-buffer buf
2072 (setq html
(org-export-region-as-html
2073 (point-min) (point-max) t
'string
)))
2075 (delete-region beg end
)
2079 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2080 "Convert region from BEG to END in org-mode buffer to HTML.
2081 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2082 contents, and only produce the region of converted text, useful for
2083 cut-and-paste operations.
2084 If BUFFER is a buffer or a string, use/create that buffer as a target
2085 of the converted HTML. If BUFFER is the symbol `string', return the
2086 produced HTML as a string and leave not buffer behind. For example,
2087 a Lisp program could call this function in the following way:
2089 (setq html (org-export-region-as-html beg end t 'string))
2091 When called interactively, the output buffer is selected, and shown
2092 in a window. A non-interactive call will only retunr the buffer."
2093 (interactive "r\nP")
2094 (when (interactive-p)
2095 (setq buffer
"*Org HTML Export*"))
2096 (let ((transient-mark-mode t
) (zmacs-regions t
)
2099 (set-mark (point)) ;; to activate the region
2101 (setq rtn
(org-export-as-html
2104 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2105 (if (and (interactive-p) (bufferp rtn
))
2106 (switch-to-buffer-other-window rtn
)
2109 (defvar html-table-tag nil
) ; dynamically scoped into this.
2111 (defun org-export-as-html (arg &optional hidden ext-plist
2112 to-buffer body-only pub-dir
)
2113 "Export the outline as a pretty HTML file.
2114 If there is an active region, export only the region. The prefix
2115 ARG specifies how many levels of the outline should become
2116 headlines. The default is 3. Lower levels will become bulleted
2117 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2118 EXT-PLIST is a property list with external parameters overriding
2119 org-mode's default settings, but still inferior to file-local
2120 settings. When TO-BUFFER is non-nil, create a buffer with that
2121 name and export to that buffer. If TO-BUFFER is the symbol
2122 `string', don't leave any buffer behind but just return the
2123 resulting HTML as a string. When BODY-ONLY is set, don't produce
2124 the file header and footer, simply return the content of
2125 <body>...</body>, without even the body tags themselves. When
2126 PUB-DIR is set, use this as the publishing directory."
2129 ;; Make sure we have a file name when we need it.
2130 (when (and (not (or to-buffer body-only
))
2131 (not buffer-file-name
))
2132 (if (buffer-base-buffer)
2133 (org-set-local 'buffer-file-name
2134 (with-current-buffer (buffer-base-buffer)
2136 (error "Need a file name to be able to export.")))
2138 (message "Exporting...")
2139 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2140 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2141 (setq-default org-done-keywords org-done-keywords
)
2142 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2144 (org-export-process-option-filters
2145 (org-combine-plists (org-default-export-plist)
2147 (org-infile-export-plist))))
2149 (style (plist-get opt-plist
:style
))
2150 (html-extension (plist-get opt-plist
:html-extension
))
2151 (link-validate (plist-get opt-plist
:link-validation-function
))
2152 valid thetoc have-headings first-heading-pos
2153 (odd org-odd-levels-only
)
2154 (region-p (org-region-active-p))
2158 (goto-char (region-beginning))
2159 (and (org-at-heading-p)
2160 (>= (org-end-of-subtree t t
) (region-end))))))
2161 ;; The following two are dynamically scoped into other
2163 (org-current-export-dir
2164 (or pub-dir
(org-export-directory :html opt-plist
)))
2165 (org-current-export-file buffer-file-name
)
2166 (level 0) (line "") (origline "") txt todo
2169 (filename (if to-buffer nil
2172 (file-name-sans-extension
2174 (org-entry-get (region-beginning)
2175 "EXPORT_FILE_NAME" t
))
2176 (file-name-nondirectory buffer-file-name
)))
2178 (file-name-as-directory
2179 (or pub-dir
(org-export-directory :html opt-plist
))))))
2180 (current-dir (if buffer-file-name
2181 (file-name-directory buffer-file-name
)
2183 (buffer (if to-buffer
2185 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2186 (t (get-buffer-create to-buffer
)))
2187 (find-file-noselect filename
)))
2188 (org-levels-open (make-vector org-level-max nil
))
2189 (date (plist-get opt-plist
:date
))
2190 (author (plist-get opt-plist
:author
))
2191 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2192 (plist-get opt-plist
:title
)
2194 (plist-get opt-plist
:skip-before-1st-heading
))
2195 (org-export-grab-title-from-buffer))
2196 (and buffer-file-name
2197 (file-name-sans-extension
2198 (file-name-nondirectory buffer-file-name
)))
2200 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2201 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2202 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2206 (local-list-num nil
)
2207 (local-list-indent nil
)
2208 (llt org-plain-list-ordered-item-terminator
)
2209 (email (plist-get opt-plist
:email
))
2210 (language (plist-get opt-plist
:language
))
2214 (coding-system (and (boundp 'buffer-file-coding-system
)
2215 buffer-file-coding-system
))
2216 (coding-system-for-write (or org-export-html-coding-system
2218 (save-buffer-coding-system (or org-export-html-coding-system
2220 (charset (and coding-system-for-write
2221 (fboundp 'coding-system-get
)
2222 (coding-system-get coding-system-for-write
2226 (if region-p
(region-beginning) (point-min))
2227 (if region-p
(region-end) (point-max))))
2230 (org-export-preprocess-string
2234 :skip-before-1st-heading
2235 (plist-get opt-plist
:skip-before-1st-heading
)
2236 :drawers
(plist-get opt-plist
:drawers
)
2238 (plist-get opt-plist
:archived-trees
)
2240 (plist-get opt-plist
:text
)
2242 (plist-get opt-plist
:LaTeX-fragments
))
2245 table-buffer table-orig-buffer
2246 ind start-is-num starter didclose
2247 rpl path desc descp desc1 desc2 link
2251 (let ((inhibit-read-only t
))
2253 (remove-text-properties (point-min) (point-max)
2254 '(:org-license-to-kill t
))))
2256 (message "Exporting...")
2258 (setq org-min-level
(org-get-min-level lines
))
2259 (setq org-last-level org-min-level
)
2260 (org-init-section-numbers)
2263 ((and date
(string-match "%" date
))
2264 (setq date
(format-time-string date
)))
2266 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2268 ;; Get the language-dependent settings
2269 (setq lang-words
(or (assoc language org-export-language-setup
)
2270 (assoc "en" org-export-language-setup
)))
2272 ;; Switch to the output buffer
2274 (let ((inhibit-read-only t
)) (erase-buffer))
2277 (and (fboundp 'set-buffer-file-coding-system
)
2278 (set-buffer-file-coding-system coding-system-for-write
))
2280 (let ((case-fold-search nil
)
2281 (org-odd-levels-only odd
))
2282 ;; create local variables for all options, to make sure all called
2283 ;; functions get the correct information
2285 (set (make-local-variable (cdr x
))
2286 (plist-get opt-plist
(car x
))))
2287 org-export-plist-vars
)
2288 (setq umax
(if arg
(prefix-numeric-value arg
)
2289 org-export-headline-levels
))
2290 (setq umax-toc
(if (integerp org-export-with-toc
)
2291 (min org-export-with-toc umax
)
2296 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2297 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2298 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2299 lang=\"%s\" xml:lang=\"%s\">
2302 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2303 <meta name=\"generator\" content=\"Org-mode\"/>
2304 <meta name=\"generated\" content=\"%s\"/>
2305 <meta name=\"author\" content=\"%s\"/>
2309 language language
(org-html-expand title
)
2310 (or charset
"iso-8859-1") date author style
))
2312 (insert (or (plist-get opt-plist
:preamble
) ""))
2314 (when (plist-get opt-plist
:auto-preamble
)
2315 (if title
(insert (format org-export-html-title-format
2316 (org-html-expand title
))))))
2318 (if (and org-export-with-toc
(not body-only
))
2320 (push (format "<h%d>%s</h%d>\n"
2321 org-export-html-toplevel-hlevel
2323 org-export-html-toplevel-hlevel
)
2325 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2326 (push "<ul>\n<li>" thetoc
)
2328 (mapcar '(lambda (line)
2329 (if (string-match org-todo-line-regexp line
)
2330 ;; This is a headline
2332 (setq have-headings t
)
2333 (setq level
(- (match-end 1) (match-beginning 1))
2334 level
(org-tr-level level
)
2335 txt
(save-match-data
2337 (org-export-cleanup-toc-line
2338 (match-string 3 line
))))
2340 (or (and org-export-mark-todo-in-toc
2342 (not (member (match-string 2 line
)
2343 org-done-keywords
)))
2345 (and org-export-mark-todo-in-toc
2347 (org-search-todo-below
2348 line lines level
))))
2350 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2351 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2352 (if (string-match quote-re0 txt
)
2353 (setq txt
(replace-match "" t t txt
)))
2354 (setq snumber
(org-section-number level
))
2355 (if org-export-with-section-numbers
2356 (setq txt
(concat snumber
" " txt
)))
2357 (if (<= level
(max umax umax-toc
))
2358 (setq head-count
(+ head-count
1)))
2359 (if (<= level umax-toc
)
2361 (if (> level org-last-level
)
2363 (setq cnt
(- level org-last-level
))
2364 (while (>= (setq cnt
(1- cnt
)) 0)
2365 (push "\n<ul>\n<li>" thetoc
))
2366 (push "\n" thetoc
)))
2367 (if (< level org-last-level
)
2369 (setq cnt
(- org-last-level level
))
2370 (while (>= (setq cnt
(1- cnt
)) 0)
2371 (push "</li>\n</ul>" thetoc
))
2372 (push "\n" thetoc
)))
2373 ;; Check for targets
2374 (while (string-match org-any-target-regexp line
)
2375 (setq line
(replace-match
2376 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2378 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2379 (setq txt
(replace-match "" t t txt
)))
2383 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2384 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2385 snumber txt
) thetoc
)
2387 (setq org-last-level level
))
2391 (while (> org-last-level
(1- org-min-level
))
2392 (setq org-last-level
(1- org-last-level
))
2393 (push "</li>\n</ul>\n" thetoc
))
2394 (push "</div>\n" thetoc
)
2395 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2398 (org-init-section-numbers)
2400 (while (setq line
(pop lines
) origline line
)
2403 ;; end of quote section?
2404 (when (and inquote
(string-match "^\\*+ " line
))
2407 ;; inside a quote section?
2409 (insert (org-html-protect line
) "\n")
2410 (throw 'nextline nil
))
2413 (when (and org-export-with-fixed-width
2414 (string-match "^[ \t]*:\\(.*\\)" line
))
2418 (insert (org-html-protect (match-string 1 line
)) "\n")
2420 (not (string-match "^[ \t]*\\(:.*\\)"
2423 (insert "</pre>\n"))
2424 (throw 'nextline nil
))
2427 (when (get-text-property 0 'org-protected line
)
2429 (when (re-search-backward
2430 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2431 (setq par
(match-string 1))
2432 (replace-match "\\2\n"))
2435 (or (= (length (car lines
)) 0)
2436 (get-text-property 0 'org-protected
(car lines
))))
2437 (insert (pop lines
) "\n"))
2438 (and par
(insert "<p>\n")))
2439 (throw 'nextline nil
))
2442 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2443 (insert "\n<hr/>\n")
2444 (throw 'nextline nil
))
2446 ;; make targets to anchors
2447 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2450 (setq line
(replace-match
2451 (concat "@<a name=\""
2452 (org-solidify-link-text (match-string 1 line
))
2455 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2456 (setq line
(replace-match
2457 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2458 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2461 (setq line
(replace-match
2462 (concat "@<a name=\""
2463 (org-solidify-link-text (match-string 1 line
))
2464 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2467 (setq line
(org-html-handle-time-stamps line
))
2469 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2470 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2471 ;; Also handle sub_superscripts and checkboxes
2472 (or (string-match org-table-hline-regexp line
)
2473 (setq line
(org-html-expand line
)))
2477 (while (string-match org-bracket-link-analytic-regexp line start
)
2478 (setq start
(match-beginning 0))
2479 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2480 (setq path
(match-string 3 line
))
2481 (setq desc1
(if (match-end 5) (match-string 5 line
))
2482 desc2
(if (match-end 2) (concat type
":" path
) path
)
2483 descp
(and desc1
(not (equal desc1 desc2
)))
2484 desc
(or desc1 desc2
))
2485 ;; Make an image out of the description if that is so wanted
2486 (when (and descp
(org-file-image-p desc
))
2488 (if (string-match "^file:" desc
)
2489 (setq desc
(substring desc
(match-end 0)))))
2490 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2491 ;; FIXME: do we need to unescape here somewhere?
2493 ((equal type
"internal")
2497 (org-solidify-link-text
2498 (save-match-data (org-link-unescape path
)) nil
)
2499 "\">" desc
"</a>")))
2500 ((member type
'("http" "https"))
2501 ;; standard URL, just check if we need to inline an image
2502 (if (and (or (eq t org-export-html-inline-images
)
2503 (and org-export-html-inline-images
(not descp
)))
2504 (org-file-image-p path
))
2505 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2506 (setq link
(concat type
":" path
))
2507 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2508 ((member type
'("ftp" "mailto" "news"))
2510 (setq link
(concat type
":" path
))
2511 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2512 ((string= type
"file")
2514 (let* ((filename path
)
2515 (abs-p (file-name-absolute-p filename
))
2516 thefile file-is-image-p search
)
2518 (if (string-match "::\\(.*\\)" filename
)
2519 (setq search
(match-string 1 filename
)
2520 filename
(replace-match "" t nil filename
)))
2522 (if (functionp link-validate
)
2523 (funcall link-validate filename current-dir
)
2525 (setq file-is-image-p
(org-file-image-p filename
))
2526 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2527 (when (and org-export-html-link-org-files-as-html
2528 (string-match "\\.org$" thefile
))
2529 (setq thefile
(concat (substring thefile
0
2530 (match-beginning 0))
2531 "." html-extension
))
2533 ;; make sure this is can be used as target search
2534 (not (string-match "^[0-9]*$" search
))
2535 (not (string-match "^\\*" search
))
2536 (not (string-match "^/.*/$" search
)))
2537 (setq thefile
(concat thefile
"#"
2538 (org-solidify-link-text
2539 (org-link-unescape search
)))))
2540 (when (string-match "^file:" desc
)
2541 (setq desc
(replace-match "" t t desc
))
2542 (if (string-match "\\.org$" desc
)
2543 (setq desc
(replace-match "" t t desc
))))))
2544 (setq rpl
(if (and file-is-image-p
2545 (or (eq t org-export-html-inline-images
)
2546 (and org-export-html-inline-images
2548 (concat "<img src=\"" thefile
"\"/>")
2549 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2550 (if (not valid
) (setq rpl desc
))))
2552 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2555 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2558 ;; just publish the path, as default
2559 (setq rpl
(concat "<i><" type
":"
2560 (save-match-data (org-link-unescape path
))
2562 (setq line
(replace-match rpl t t line
)
2563 start
(+ start
(length rpl
))))
2566 (if (and (string-match org-todo-line-regexp line
)
2567 (match-beginning 2))
2570 (concat (substring line
0 (match-beginning 2))
2572 (if (member (match-string 2 line
)
2575 "\">" (match-string 2 line
)
2576 "</span>" (substring line
(match-end 2)))))
2578 ;; Does this contain a reference to a footnote?
2579 (when org-export-with-footnotes
2581 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2582 (if (get-text-property (match-beginning 2) 'org-protected line
)
2583 (setq start
(match-end 2))
2584 (let ((n (match-string 2 line
)))
2588 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2589 (match-string 1 line
) n n n
)
2593 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2594 ;; This is a headline
2595 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2596 txt
(match-string 2 line
))
2597 (if (string-match quote-re0 txt
)
2598 (setq txt
(replace-match "" t t txt
)))
2599 (if (<= level
(max umax umax-toc
))
2600 (setq head-count
(+ head-count
1)))
2602 ;; Close any local lists before inserting a new header line
2603 (while local-list-num
2605 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2606 (pop local-list-num
))
2607 (setq local-list-indent nil
2609 (setq first-heading-pos
(or first-heading-pos
(point)))
2610 (org-html-level-start level txt umax
2611 (and org-export-with-toc
(<= level umax
))
2614 (when (string-match quote-re line
)
2618 ((and org-export-with-tables
2619 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2620 (if (not table-open
)
2622 (setq table-open t table-buffer nil table-orig-buffer nil
))
2624 (setq table-buffer
(cons line table-buffer
)
2625 table-orig-buffer
(cons origline table-orig-buffer
))
2626 (when (or (not lines
)
2627 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2629 (setq table-open nil
2630 table-buffer
(nreverse table-buffer
)
2631 table-orig-buffer
(nreverse table-orig-buffer
))
2632 (org-close-par-maybe)
2633 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2638 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2639 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2640 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2641 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2643 (setq ind
(org-get-string-indentation line
)
2644 start-is-num
(match-beginning 4)
2645 starter
(if (match-beginning 2)
2646 (substring (match-string 2 line
) 0 -
1))
2647 line
(substring line
(match-beginning 5)))
2648 (unless (string-match "[^ \t]" line
)
2649 ;; empty line. Pretend indentation is large.
2650 (setq ind
(if org-empty-line-terminates-plain-lists
2652 (1+ (or (car local-list-indent
) 1)))))
2654 (while (and in-local-list
2655 (or (and (= ind
(car local-list-indent
))
2657 (< ind
(car local-list-indent
))))
2660 (insert (if (car local-list-num
) "</ol>\n" "</ul>"))
2661 (pop local-list-num
) (pop local-list-indent
)
2662 (setq in-local-list local-list-indent
))
2665 (or (not in-local-list
)
2666 (> ind
(car local-list-indent
))))
2667 ;; Start new (level of) list
2668 (org-close-par-maybe)
2669 (insert (if start-is-num
"<ol>\n<li>\n" "<ul>\n<li>\n"))
2670 (push start-is-num local-list-num
)
2671 (push ind local-list-indent
)
2672 (setq in-local-list t
))
2674 ;; continue current list
2678 ;; we did close a list, normal text follows: need <p>
2680 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2683 (if (equal (match-string 1 line
) "X")
2685 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2688 ;; Empty lines start a new paragraph. If hand-formatted lists
2689 ;; are not fully interpreted, lines starting with "-", "+", "*"
2690 ;; also start a new paragraph.
2691 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2693 ;; Is this the start of a footnote?
2694 (when org-export-with-footnotes
2695 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2696 (org-close-par-maybe)
2697 (let ((n (match-string 1 line
)))
2698 (setq line
(replace-match
2699 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2701 ;; Check if the line break needs to be conserved
2703 ((string-match "\\\\\\\\[ \t]*$" line
)
2704 (setq line
(replace-match "<br/>" t t line
)))
2705 (org-export-preserve-breaks
2706 (setq line
(concat line
"<br/>"))))
2708 (insert line
"\n")))))
2710 ;; Properly close all local lists and other lists
2711 (when inquote
(insert "</pre>\n"))
2713 ;; Close any local lists before inserting a new header line
2714 (while local-list-num
2716 (insert (if (car local-list-num
) "</ol>\n" "</ul>\n"))
2717 (pop local-list-num
))
2718 (setq local-list-indent nil
2720 (org-html-level-start 1 nil umax
2721 (and org-export-with-toc
(<= level umax
))
2723 ;; the </div> to lose the last text-... div.
2727 (when (plist-get opt-plist
:auto-postamble
)
2728 (insert "<div id=\"postamble\">")
2729 (when (and org-export-author-info author
)
2730 (insert "<p class=\"author\"> "
2731 (nth 1 lang-words
) ": " author
"\n")
2733 (if (listp (split-string email
",+ *"))
2735 (insert "<a href=\"mailto:" e
"\"><"
2737 (split-string email
",+ *"))
2738 (insert "<a href=\"mailto:" email
"\"><"
2739 email
"></a>\n")))
2741 (when (and date org-export-time-stamp-file
)
2742 (insert "<p class=\"date\"> "
2743 (nth 2 lang-words
) ": "
2747 (if org-export-html-with-timestamp
2748 (insert org-export-html-html-helper-timestamp
))
2749 (insert (or (plist-get opt-plist
:postamble
) ""))
2750 (insert "</body>\n</html>\n"))
2753 (if (eq major-mode default-major-mode
) (html-mode))
2755 ;; insert the table of contents
2756 (goto-char (point-min))
2758 (if (or (re-search-forward
2759 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2761 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2763 (goto-char (match-beginning 0))
2765 (goto-char first-heading-pos
)
2766 (when (looking-at "\\s-*</p>")
2767 (goto-char (match-end 0))
2769 (insert "<div id=\"table-of-contents\">\n")
2770 (mapc 'insert thetoc
)
2771 (insert "</div>\n"))
2772 ;; remove empty paragraphs and lists
2773 (goto-char (point-min))
2774 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2776 (goto-char (point-min))
2777 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2779 (goto-char (point-min))
2780 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2782 ;; Convert whitespace place holders
2783 (goto-char (point-min))
2785 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2786 (setq n
(get-text-property beg
'org-whitespace
)
2787 end
(next-single-property-change beg
'org-whitespace
))
2789 (delete-region beg end
)
2790 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2791 (make-string n ?x
)))))
2792 (or to-buffer
(save-buffer))
2793 (goto-char (point-min))
2794 (message "Exporting... done")
2795 (if (eq to-buffer
'string
)
2796 (prog1 (buffer-substring (point-min) (point-max))
2797 (kill-buffer (current-buffer)))
2798 (current-buffer)))))
2800 (defvar org-table-colgroup-info nil
)
2801 (defun org-format-table-ascii (lines)
2802 "Format a table for ascii export."
2804 (setq lines
(org-split-string lines
"\n")))
2805 (if (not (string-match "^[ \t]*|" (car lines
)))
2806 ;; Table made by table.el - test for spanning
2809 ;; A normal org table
2810 ;; Get rid of hlines at beginning and end
2811 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2812 (setq lines
(nreverse lines
))
2813 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2814 (setq lines
(nreverse lines
))
2815 (when org-export-table-remove-special-lines
2816 ;; Check if the table has a marking column. If yes remove the
2817 ;; column and the special lines
2818 (setq lines
(org-table-clean-before-export lines
)))
2819 ;; Get rid of the vertical lines except for grouping
2820 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
2822 (while (setq line
(pop lines
))
2823 (if (string-match org-table-hline-regexp line
)
2824 (and (string-match "|\\(.*\\)|" line
)
2825 (setq line
(replace-match " \\1" t nil line
)))
2826 (setq start
0 vl1 vl
)
2827 (while (string-match "|" line start
)
2828 (setq start
(match-end 0))
2829 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
2833 (defun org-colgroup-info-to-vline-list (info)
2836 (setq last new new
(pop info
))
2837 (if (or (memq last
'(:end
:startend
))
2838 (memq new
'(:start
:startend
)))
2841 (setq vl
(nreverse vl
))
2842 (and vl
(setcar vl nil
))
2845 (defvar org-table-number-regexp
) ; defined in org-table.el
2846 (defun org-format-table-html (lines olines
)
2847 "Find out which HTML converter to use and return the HTML code."
2849 (setq lines
(org-split-string lines
"\n")))
2850 (if (string-match "^[ \t]*|" (car lines
))
2851 ;; A normal org table
2852 (org-format-org-table-html lines
)
2853 ;; Table made by table.el - test for spanning
2854 (let* ((hlines (delq nil
(mapcar
2856 (if (string-match "^[ \t]*\\+-" x
) x
2859 (first (car hlines
))
2860 (ll (and (string-match "\\S-+" first
)
2861 (match-string 0 first
)))
2862 (re (concat "^[ \t]*" (regexp-quote ll
)))
2863 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
2865 (if (and (not spanning
)
2866 (not org-export-prefer-native-exporter-for-tables
))
2867 ;; We can use my own converter with HTML conversions
2868 (org-format-table-table-html lines
)
2869 ;; Need to use the code generator in table.el, with the original text.
2870 (org-format-table-table-html-using-table-generate-source olines
)))))
2872 (defvar org-table-number-fraction
) ; defined in org-table.el
2873 (defun org-format-org-table-html (lines &optional splice
)
2874 "Format a table into HTML."
2875 (require 'org-table
)
2876 ;; Get rid of hlines at beginning and end
2877 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2878 (setq lines
(nreverse lines
))
2879 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
2880 (setq lines
(nreverse lines
))
2881 (when org-export-table-remove-special-lines
2882 ;; Check if the table has a marking column. If yes remove the
2883 ;; column and the special lines
2884 (setq lines
(org-table-clean-before-export lines
)))
2886 (let ((head (and org-export-highlight-first-table-line
2888 (lambda (x) (string-match "^[ \t]*|-" x
))
2891 tbopen line fields html gr colgropen
)
2892 (if splice
(setq head nil
))
2893 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
2895 (while (setq line
(pop lines
))
2897 (if (string-match "^[ \t]*|-" line
)
2900 (push (if head
"</thead>" "</tbody>") html
)
2901 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
2902 (setq head nil
) ;; head ends here, first time around
2904 (throw 'next-line t
)))
2905 ;; Break the line into fields
2906 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
2907 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
2908 (setq nlines
(1+ nlines
) i -
1)
2909 (push (concat "<tr>"
2913 (if (and (< i nlines
)
2914 (string-match org-table-number-regexp x
))
2915 (incf (aref fnum i
)))
2917 (concat (car org-export-table-header-tags
) x
2918 (cdr org-export-table-header-tags
))
2919 (concat (car org-export-table-data-tags
) x
2920 (cdr org-export-table-data-tags
))))
2924 (unless splice
(if tbopen
(push "</tbody>" html
)))
2925 (unless splice
(push "</table>\n" html
))
2926 (setq html
(nreverse html
))
2928 ;; Put in col tags with the alignment (unfortuntely often ignored...)
2931 (setq gr
(pop org-table-colgroup-info
))
2932 (format "%s<col align=\"%s\"></col>%s"
2933 (if (memq gr
'(:start
:startend
))
2935 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
2938 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
2940 (if (memq gr
'(:end
:startend
))
2941 (progn (setq colgropen nil
) "</colgroup>")
2945 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
2946 (push html-table-tag html
))
2947 (concat (mapconcat 'identity html
"\n") "\n")))
2949 (defun org-table-clean-before-export (lines)
2950 "Check if the table has a marking column.
2951 If yes remove the column and the special lines."
2952 (setq org-table-colgroup-info nil
)
2955 (lambda (x) (or (string-match "^[ \t]*|-" x
)
2956 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
2959 (setq org-table-clean-did-remove-column nil
)
2964 ((string-match "^[ \t]*| */ *|" x
)
2965 (setq org-table-colgroup-info
2967 (cond ((member x
'("<" "<")) :start
)
2968 ((member x
'(">" ">")) :end
)
2969 ((member x
'("<>" "<>")) :startend
)
2971 (org-split-string x
"[ \t]*|[ \t]*")))
2975 (setq org-table-clean-did-remove-column t
)
2980 ((string-match "^[ \t]*| */ *|" x
)
2981 (setq org-table-colgroup-info
2983 (cond ((member x
'("<" "<")) :start
)
2984 ((member x
'(">" ">")) :end
)
2985 ((member x
'("<>" "<>")) :startend
)
2987 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
2989 ((string-match "^[ \t]*| *[!_^/] *|" x
)
2990 nil
) ; ignore this line
2991 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
2992 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
2993 ;; remove the first column
2994 (replace-match "\\1|" t nil x
))))
2997 (defun org-format-table-table-html (lines)
2998 "Format a table generated by table.el into HTML.
2999 This conversion does *not* use `table-generate-source' from table.el.
3000 This has the advantage that Org-mode's HTML conversions can be used.
3001 But it has the disadvantage, that no cell- or row-spanning is allowed."
3002 (let (line field-buffer
3003 (head org-export-highlight-first-table-line
)
3005 (setq html
(concat html-table-tag
"\n"))
3006 (while (setq line
(pop lines
))
3007 (setq empty
" ")
3009 (if (string-match "^[ \t]*\\+-" line
)
3020 (if (equal x
"") (setq x empty
))
3022 (concat (car org-export-table-header-tags
) x
3023 (cdr org-export-table-header-tags
))
3024 (concat (car org-export-table-data-tags
) x
3025 (cdr org-export-table-data-tags
))))
3029 (setq field-buffer nil
)))
3031 (throw 'next-line t
)))
3032 ;; Break the line into fields and store the fields
3033 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3035 (setq field-buffer
(mapcar
3037 (concat x
"<br/>" (pop fields
)))
3039 (setq field-buffer fields
))))
3040 (setq html
(concat html
"</table>\n"))
3043 (defun org-format-table-table-html-using-table-generate-source (lines)
3044 "Format a table into html, using `table-generate-source' from table.el.
3045 This has the advantage that cell- or row-spanning is allowed.
3046 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3048 (with-current-buffer (get-buffer-create " org-tmp1 ")
3050 (insert (mapconcat 'identity lines
"\n"))
3051 (goto-char (point-min))
3052 (if (not (re-search-forward "|[^+]" nil t
))
3053 (error "Error processing table"))
3054 (table-recognize-table)
3055 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3056 (table-generate-source 'html
" org-tmp2 ")
3057 (set-buffer " org-tmp2 ")
3058 (buffer-substring (point-min) (point-max))))
3060 (defun org-html-handle-time-stamps (s)
3061 "Format time stamps in string S, or remove them."
3064 (while (string-match org-maybe-keyword-time-regexp s
)
3065 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3066 ;; never export CLOCK
3068 (or b
(setq b
(substring s
0 (match-beginning 0))))
3069 (if (not org-export-with-timestamps
)
3070 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3071 s
(substring s
(match-end 0)))
3073 r
(substring s
0 (match-beginning 0))
3075 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3076 (match-string 1 s
)))
3077 (format " @<span class=\"timestamp\">%s@</span>"
3079 (org-translate-time (match-string 3 s
)) 1 -
1)))
3080 s
(substring s
(match-end 0)))))
3081 ;; Line break if line started and ended with time stamp stuff
3084 (setq r
(concat r s
))
3085 (unless (string-match "\\S-" (concat b s
))
3086 (setq r
(concat r
"@<br/>")))
3089 (defun org-html-protect (s)
3090 ;; convert & to &, < to < and > to >
3092 (while (string-match "&" s start
)
3093 (setq s
(replace-match "&" t t s
)
3094 start
(1+ (match-beginning 0))))
3095 (while (string-match "<" s
)
3096 (setq s
(replace-match "<" t t s
)))
3097 (while (string-match ">" s
)
3098 (setq s
(replace-match ">" t t s
))))
3101 (defun org-export-cleanup-toc-line (s)
3102 "Remove tags and time staps from lines going into the toc."
3103 (when (memq org-export-with-tags
'(not-in-toc nil
))
3104 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3105 (setq s
(replace-match "" t t s
))))
3106 (when org-export-remove-timestamps-from-toc
3107 (while (string-match org-maybe-keyword-time-regexp s
)
3108 (setq s
(replace-match "" t t s
))))
3109 (while (string-match org-bracket-link-regexp s
)
3110 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3114 (defun org-html-expand (string)
3115 "Prepare STRING for HTML export. Applies all active conversions.
3116 If there are links in the string, don't modify these."
3117 (let* ((re (concat org-bracket-link-regexp
"\\|"
3118 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3120 (while (setq m
(string-match re string
))
3121 (setq s
(substring string
0 m
)
3122 l
(match-string 0 string
)
3123 string
(substring string
(match-end 0)))
3124 (push (org-html-do-expand s
) res
)
3126 (push (org-html-do-expand string
) res
)
3127 (apply 'concat
(nreverse res
))))
3129 (defun org-html-do-expand (s)
3130 "Apply all active conversions to translate special ASCII to HTML."
3131 (setq s
(org-html-protect s
))
3132 (if org-export-html-expand
3134 (while (string-match "@<\\([^&]*\\)>" s
)
3135 (setq s
(replace-match "<\\1>" t nil s
)))))
3136 (if org-export-with-emphasize
3137 (setq s
(org-export-html-convert-emphasize s
)))
3138 (if org-export-with-special-strings
3139 (setq s
(org-export-html-convert-special-strings s
)))
3140 (if org-export-with-sub-superscripts
3141 (setq s
(org-export-html-convert-sub-super s
)))
3142 (if org-export-with-TeX-macros
3143 (let ((start 0) wd ass
)
3144 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3145 (if (get-text-property (match-beginning 0) 'org-protected s
)
3146 (setq start
(match-end 0))
3147 (setq wd
(match-string 1 s
))
3148 (if (setq ass
(assoc wd org-html-entities
))
3149 (setq s
(replace-match (or (cdr ass
)
3150 (concat "&" (car ass
) ";"))
3152 (setq start
(+ start
(length wd
))))))))
3155 (defun org-create-multibrace-regexp (left right n
)
3156 "Create a regular expression which will match a balanced sexp.
3157 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3158 as single character strings.
3159 The regexp returned will match the entire expression including the
3160 delimiters. It will also define a single group which contains the
3161 match except for the outermost delimiters. The maximum depth of
3162 stacked delimiters is N. Escaping delimiters is not possible."
3163 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3166 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3169 re
(concat re or next
)
3170 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3171 (concat left
"\\(" re
"\\)" right
)))
3173 (defvar org-match-substring-regexp
3175 "\\([^\\]\\)\\([_^]\\)\\("
3176 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3178 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3180 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3181 "The regular expression matching a sub- or superscript.")
3183 (defvar org-match-substring-with-braces-regexp
3185 "\\([^\\]\\)\\([_^]\\)\\("
3186 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3188 "The regular expression matching a sub- or superscript, forcing braces.")
3190 (defconst org-export-html-special-string-regexps
3191 '(("\\\\-" .
"­")
3192 ("---\\([^-]\\)" .
"—\\1")
3193 ("--\\([^-]\\)" .
"–\\1")
3194 ("\\.\\.\\." .
"…"))
3195 "Regular expressions for special string conversion.")
3197 (defun org-export-html-convert-special-strings (string)
3198 "Convert special characters in STRING to HTML."
3199 (let ((all org-export-html-special-string-regexps
)
3201 (while (setq a
(pop all
))
3202 (setq re
(car a
) rpl
(cdr a
) start
0)
3203 (while (string-match re string start
)
3204 (if (get-text-property (match-beginning 0) 'org-protected string
)
3205 (setq start
(match-end 0))
3206 (setq string
(replace-match rpl t nil string
)))))
3209 (defun org-export-html-convert-sub-super (string)
3210 "Convert sub- and superscripts in STRING to HTML."
3211 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3212 (while (string-match org-match-substring-regexp string s
)
3214 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3215 ((get-text-property (match-beginning 2) 'org-protected string
)
3216 (setq s
(match-end 2)))
3218 (setq s
(match-end 1)
3219 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3220 c
(or (match-string 8 string
)
3221 (match-string 6 string
)
3222 (match-string 5 string
))
3223 string
(replace-match
3224 (concat (match-string 1 string
)
3225 "<" key
">" c
"</" key
">")
3227 (while (string-match "\\\\\\([_^]\\)" string
)
3228 (setq string
(replace-match (match-string 1 string
) t t string
)))
3231 (defun org-export-html-convert-emphasize (string)
3234 (while (string-match org-emph-re string s
)
3236 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3237 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3238 (setq s
(match-beginning 0)
3241 (match-string 1 string
)
3242 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3243 (match-string 4 string
)
3244 (nth 3 (assoc (match-string 3 string
)
3245 org-emphasis-alist
))
3246 (match-string 5 string
))
3247 string
(replace-match rpl t t string
)
3248 s
(+ s
(- (length rpl
) 2)))
3252 (defvar org-par-open nil
)
3253 (defun org-open-par ()
3254 "Insert <p>, but first close previous paragraph if any."
3255 (org-close-par-maybe)
3257 (setq org-par-open t
))
3258 (defun org-close-par-maybe ()
3259 "Close paragraph if there is one open."
3262 (setq org-par-open nil
)))
3263 (defun org-close-li ()
3264 "Close <li> if necessary."
3265 (org-close-par-maybe)
3268 (defvar body-only
) ; dynamically scoped into this.
3269 (defun org-html-level-start (level title umax with-toc head-count
)
3270 "Insert a new level in HTML export.
3271 When TITLE is nil, just close all open levels."
3272 (org-close-par-maybe)
3273 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3277 (if (aref org-levels-open
(1- l
))
3279 (org-html-level-close l umax
)
3280 (aset org-levels-open
(1- l
) nil
)))
3283 ;; If title is nil, this means this function is called to close
3284 ;; all levels, so the rest is done only if title is given
3285 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3286 (setq title
(replace-match
3287 (if org-export-with-tags
3290 " <span class=\"tag\">"
3291 (mapconcat 'identity
(org-split-string
3292 (match-string 1 title
) ":")
3299 (if (aref org-levels-open
(1- level
))
3303 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3304 (insert "<li>" title
"<br/>\n")))
3305 (aset org-levels-open
(1- level
) t
)
3306 (org-close-par-maybe)
3308 (insert (format "<ul>\n<li id=\"%s\">" target
)
3310 (insert "<ul>\n<li>" title
"<br/>\n"))))
3311 (aset org-levels-open
(1- level
) t
)
3312 (setq snumber
(org-section-number level
))
3313 (if (and org-export-with-section-numbers
(not body-only
))
3314 (setq title
(concat snumber
" " title
)))
3315 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3316 (unless (= head-count
1) (insert "\n</div>\n"))
3317 (insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d\">\n<h%d id=\"sec-%s\">%s</h%d>\n<div id=\"text-%s\">\n"
3318 snumber level level snumber title level snumber
))
3321 (defun org-get-text-property-any (pos prop
&optional object
)
3322 (or (get-text-property pos prop object
)
3323 (and (setq pos
(next-single-property-change pos prop object
))
3324 (get-text-property pos prop object
))))
3326 (defun org-html-level-close (level max-outline-level
)
3327 "Terminate one level in HTML export."
3328 (if (<= level max-outline-level
)
3331 (insert "</ul>\n")))
3333 ;;; iCalendar export
3336 (defun org-export-icalendar-this-file ()
3337 "Export current file as an iCalendar file.
3338 The iCalendar file will be located in the same directory as the Org-mode
3339 file, but with extension `.ics'."
3341 (org-export-icalendar nil buffer-file-name
))
3344 (defun org-export-icalendar-all-agenda-files ()
3345 "Export all files in `org-agenda-files' to iCalendar .ics files.
3346 Each iCalendar file will be located in the same directory as the Org-mode
3347 file, but with extension `.ics'."
3349 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3352 (defun org-export-icalendar-combine-agenda-files ()
3353 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3354 The file is stored under the name `org-combined-agenda-icalendar-file'."
3356 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3358 (defun org-export-icalendar (combine &rest files
)
3359 "Create iCalendar files for all elements of FILES.
3360 If COMBINE is non-nil, combine all calendar entries into a single large
3361 file and store it under the name `org-combined-agenda-icalendar-file'."
3363 (org-prepare-agenda-buffers files
)
3364 (let* ((dir (org-export-directory
3365 :ical
(list :publishing-directory
3366 org-export-publishing-directory
)))
3367 file ical-file ical-buffer category started org-agenda-new-buffers
)
3368 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3371 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3372 org-combined-agenda-icalendar-file
3373 (expand-file-name org-combined-agenda-icalendar-file dir
))
3374 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3375 (set-buffer ical-buffer
) (erase-buffer))
3376 (while (setq file
(pop files
))
3378 (org-check-agenda-file file
)
3379 (set-buffer (org-get-agenda-file-buffer file
))
3381 (setq ical-file
(concat (file-name-as-directory dir
)
3382 (file-name-sans-extension
3383 (file-name-nondirectory buffer-file-name
))
3385 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3386 (with-current-buffer ical-buffer
(erase-buffer)))
3387 (setq category
(or org-category
3388 (file-name-sans-extension
3389 (file-name-nondirectory buffer-file-name
))))
3390 (if (symbolp category
) (setq category
(symbol-name category
)))
3391 (let ((standard-output ical-buffer
))
3393 (and (not started
) (setq started t
)
3394 (org-start-icalendar-file org-icalendar-combined-name
))
3395 (org-start-icalendar-file category
))
3396 (org-print-icalendar-entries combine
)
3397 (when (or (and combine
(not files
)) (not combine
))
3398 (org-finish-icalendar-file)
3399 (set-buffer ical-buffer
)
3401 (run-hooks 'org-after-save-iCalendar-file-hook
)))))
3402 (org-release-buffers org-agenda-new-buffers
))))
3404 (defvar org-after-save-iCalendar-file-hook nil
3405 "Hook run after an iCalendar file has been saved.
3406 The iCalendar buffer is still current when this hook is run.
3407 A good way to use this is to tell a desktop calenndar application to re-read
3408 the iCalendar file.")
3410 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3411 (defun org-print-icalendar-entries (&optional combine
)
3412 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3413 When COMBINE is non nil, add the category to each line."
3414 (require 'org-agenda
)
3415 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3416 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3417 (dts (org-ical-ts-to-string
3418 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3420 hd ts ts2 state status
(inc t
) pos b sexp rrule
3421 scheduledp deadlinep tmp pri category entry location summary desc
3422 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3423 (org-refresh-category-properties)
3425 (goto-char (point-min))
3426 (while (re-search-forward re1 nil t
)
3429 (when (boundp 'org-icalendar-verify-function
)
3430 (unless (funcall org-icalendar-verify-function
)
3431 (outline-next-heading)
3434 (setq pos
(match-beginning 0)
3437 hd
(condition-case nil
(org-get-heading)
3438 (error (throw :skip nil
)))
3439 summary
(org-icalendar-cleanup-string
3440 (org-entry-get nil
"SUMMARY"))
3441 desc
(org-icalendar-cleanup-string
3442 (or (org-entry-get nil
"DESCRIPTION")
3443 (and org-icalendar-include-body
(org-get-entry)))
3444 t org-icalendar-include-body
)
3445 location
(org-icalendar-cleanup-string
3446 (org-entry-get nil
"LOCATION"))
3447 category
(org-get-category))
3448 (if (looking-at re2
)
3450 (goto-char (match-end 0))
3451 (setq ts2
(match-string 1) inc nil
))
3452 (setq tmp
(buffer-substring (max (point-min)
3453 (- pos org-ds-keyword-length
))
3455 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3458 (replace-match "\\1" t nil ts
))
3460 deadlinep
(string-match org-deadline-regexp tmp
)
3461 scheduledp
(string-match org-scheduled-regexp tmp
)
3462 ;; donep (org-entry-is-done-p)
3464 (if (or (string-match org-tr-regexp hd
)
3465 (string-match org-ts-regexp hd
))
3466 (setq hd
(replace-match "" t t hd
)))
3467 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3469 (concat "\nRRULE:FREQ="
3472 '(("d" .
"DAILY")("w" .
"WEEKLY")
3473 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3474 ";INTERVAL=" (match-string 1 ts
)))
3476 (setq summary
(or summary hd
))
3477 (if (string-match org-bracket-link-regexp summary
)
3479 (replace-match (if (match-end 3)
3480 (match-string 3 summary
)
3481 (match-string 1 summary
))
3483 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3484 (if scheduledp
(setq summary
(concat "S: " summary
)))
3485 (if (string-match "\\`<%%" ts
)
3486 (with-current-buffer sexp-buffer
3487 (insert (substring ts
1 -
1) " " summary
"\n"))
3488 (princ (format "BEGIN:VEVENT
3494 (org-ical-ts-to-string ts
"DTSTART")
3495 (org-ical-ts-to-string ts2
"DTEND" inc
)
3497 (if (and desc
(string-match "\\S-" desc
))
3498 (concat "\nDESCRIPTION: " desc
) "")
3499 (if (and location
(string-match "\\S-" location
))
3500 (concat "\nLOCATION: " location
) "")
3503 (when (and org-icalendar-include-sexps
3504 (condition-case nil
(require 'icalendar
) (error nil
))
3505 (fboundp 'icalendar-export-region
))
3506 ;; Get all the literal sexps
3507 (goto-char (point-min))
3508 (while (re-search-forward "^&?%%(" nil t
)
3511 (setq b
(match-beginning 0))
3512 (goto-char (1- (match-end 0)))
3515 (setq sexp
(buffer-substring b
(point)))
3516 (with-current-buffer sexp-buffer
3518 (princ (org-diary-to-ical-string sexp-buffer
)))))
3520 (when org-icalendar-include-todo
3521 (goto-char (point-min))
3522 (while (re-search-forward org-todo-line-regexp nil t
)
3525 (when (boundp 'org-icalendar-verify-function
)
3526 (unless (funcall org-icalendar-verify-function
)
3527 (outline-next-heading)
3530 (setq state
(match-string 2))
3531 (setq status
(if (member state org-done-keywords
)
3532 "COMPLETED" "NEEDS-ACTION"))
3534 (or (not (member state org-done-keywords
))
3535 (eq org-icalendar-include-todo
'all
))
3536 (not (member org-archive-tag
(org-get-tags-at)))
3538 (setq hd
(match-string 3)
3539 summary
(org-icalendar-cleanup-string
3540 (org-entry-get nil
"SUMMARY"))
3541 desc
(org-icalendar-cleanup-string
3542 (or (org-entry-get nil
"DESCRIPTION")
3543 (and org-icalendar-include-body
(org-get-entry)))
3544 t org-icalendar-include-body
)
3545 location
(org-icalendar-cleanup-string
3546 (org-entry-get nil
"LOCATION")))
3547 (if (string-match org-bracket-link-regexp hd
)
3548 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3549 (match-string 1 hd
))
3551 (if (string-match org-priority-regexp hd
)
3552 (setq pri
(string-to-char (match-string 2 hd
))
3553 hd
(concat (substring hd
0 (match-beginning 1))
3554 (substring hd
(match-end 1))))
3555 (setq pri org-default-priority
))
3556 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3557 (- org-lowest-priority org-highest-priority
))))))
3559 (princ (format "BEGIN:VTODO
3569 (if (and location
(string-match "\\S-" location
))
3570 (concat "\nLOCATION: " location
) "")
3571 (if (and desc
(string-match "\\S-" desc
))
3572 (concat "\nDESCRIPTION: " desc
) "")
3573 category pri status
)))))))))
3575 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3576 "Take out stuff and quote what needs to be quoted.
3577 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3578 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3583 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3584 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3585 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3586 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3588 (while (string-match "\\([,;\\]\\)" s start
)
3589 (setq start
(+ (match-beginning 0) 2)
3590 s
(replace-match "\\\\\\1" nil nil s
))))
3592 (while (string-match "[ \t]*\n[ \t]*" s
)
3593 (setq s
(replace-match "\\n" t t s
))))
3594 (setq s
(org-trim s
))
3597 (if (and (numberp maxlength
)
3598 (> (length s
) maxlength
))
3599 (setq s
(substring s
0 maxlength
)))))
3602 (defun org-get-entry ()
3603 "Clean-up description string."
3605 (org-back-to-heading t
)
3606 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3608 (defun org-start-icalendar-file (name)
3609 "Start an iCalendar file by inserting the header."
3610 (let ((user user-full-name
)
3611 (name (or name
"unknown"))
3612 (timezone (cadr (current-time-zone))))
3614 (format "BEGIN:VCALENDAR
3617 PRODID:-//%s//Emacs with Org-mode//EN
3619 CALSCALE:GREGORIAN\n" name user timezone
))))
3621 (defun org-finish-icalendar-file ()
3622 "Finish an iCalendar file by inserting the END statement."
3623 (princ "END:VCALENDAR\n"))
3625 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3626 "Take a time string S and convert it to iCalendar format.
3627 KEYWORD is added in front, to make a complete line like DTSTART....
3628 When INC is non-nil, increase the hour by two (if time string contains
3629 a time), or the day by one (if it does not contain a time)."
3630 (let ((t1 (org-parse-time-string s
'nodefault
))
3631 t2 fmt have-time time
)
3632 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3633 (setq t2 t1 have-time t
)
3634 (setq t2
(org-parse-time-string s
)))
3635 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3636 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3639 (if org-agenda-default-appointment-duration
3640 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3643 (setq time
(encode-time s mi h d m y
)))
3644 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3645 (concat keyword
(format-time-string fmt time
))))
3649 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3650 (with-current-buffer buffer
3651 (apply 'insert output
)))
3652 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3655 (defun org-export-as-xoxo (&optional buffer
)
3656 "Export the org buffer as XOXO.
3657 The XOXO buffer is named *xoxo-<source buffer name>*"
3658 (interactive (list (current-buffer)))
3659 ;; A quickie abstraction
3661 ;; Output everything as XOXO
3662 (with-current-buffer (get-buffer buffer
)
3663 (let* ((pos (point))
3664 (opt-plist (org-combine-plists (org-default-export-plist)
3665 (org-infile-export-plist)))
3666 (filename (concat (file-name-as-directory
3667 (org-export-directory :xoxo opt-plist
))
3668 (file-name-sans-extension
3669 (file-name-nondirectory buffer-file-name
))
3671 (out (find-file-noselect filename
))
3674 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3675 ;; Check the output buffer is empty.
3676 (with-current-buffer out
(erase-buffer))
3677 ;; Kick off the output
3678 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3679 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3680 (let* ((hd (match-string-no-properties 1))
3683 (match-string-no-properties 2)
3685 (goto-char (match-end 0))
3690 (if (looking-at "^[ \t]\\(.*\\)")
3691 (setq str
(concat str
(match-string-no-properties 1)))
3692 (throw 'loop str
)))))))))
3694 ;; Handle level rendering
3696 ((> level last-level
)
3697 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3699 ((< level last-level
)
3700 (dotimes (- (- last-level level
) 1)
3702 (org-export-as-xoxo-insert-into out
"</li>\n"))
3703 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3705 (org-export-as-xoxo-insert-into out
"</li>\n")
3706 (setq hanging-li nil
)))
3708 ((equal level last-level
)
3710 (org-export-as-xoxo-insert-into out
"</li>\n")))
3713 (setq last-level level
)
3715 ;; And output the new li
3716 (setq hanging-li
't
)
3717 (if (equal ?
+ (elt text
0))
3718 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3719 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3721 ;; Finally finish off the ol
3722 (dotimes (- last-level
1)
3724 (org-export-as-xoxo-insert-into out
"</li>\n"))
3725 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3728 ;; Finish the buffer off and clean it up.
3729 (switch-to-buffer-other-window out
)
3730 (indent-region (point-min) (point-max) nil
)
3732 (goto-char (point-min))
3737 ;;; org-exp.el ends here
3740 (defun org-export-process-option-filters (plist)
3741 (let ((functions org-export-options-filters
) f
)
3742 (while (setq f
(pop functions
))
3743 (setq plist
(funcall f plist
))))