1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
67 (defcustom org-export-with-special-strings t
68 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
69 When this option is turned on, these strings will be exported as:
72 -----+----------+--------
78 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
79 :group
'org-export-translation
82 (defcustom org-export-language-setup
83 '(("en" "Author" "Date" "Table of Contents")
84 ("cs" "Autor" "Datum" "Obsah")
85 ("da" "Ophavsmand" "Dato" "Indhold")
86 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
87 ("es" "Autor" "Fecha" "\xcdndice")
88 ("fr" "Auteur" "Date" "Table des mati\xe8res")
89 ("it" "Autore" "Data" "Indice")
90 ("nl" "Auteur" "Datum" "Inhoudsopgave")
91 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
92 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
93 "Terms used in export text, translated to different languages.
94 Use the variable `org-export-default-language' to set the language,
95 or use the +OPTION lines for a per-file setting."
96 :group
'org-export-general
99 (string :tag
"HTML language tag")
100 (string :tag
"Author")
102 (string :tag
"Table of Contents"))))
104 (defcustom org-export-default-language
"en"
105 "The default language of HTML export, as a string.
106 This should have an association in `org-export-language-setup'."
107 :group
'org-export-general
110 (defcustom org-export-skip-text-before-1st-heading nil
111 "Non-nil means, skip all text before the first headline when exporting.
112 When nil, that text is exported as well."
113 :group
'org-export-general
116 (defcustom org-export-headline-levels
3
117 "The last level which is still exported as a headline.
118 Inferior levels will produce itemize lists when exported.
119 Note that a numeric prefix argument to an exporter function overrides
122 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
123 :group
'org-export-general
126 (defcustom org-export-with-section-numbers t
127 "Non-nil means, add section numbers to headlines when exporting.
129 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
130 :group
'org-export-general
133 (defcustom org-export-with-toc t
134 "Non-nil means, create a table of contents in exported files.
135 The TOC contains headlines with levels up to`org-export-headline-levels'.
136 When an integer, include levels up to N in the toc, this may then be
137 different from `org-export-headline-levels', but it will not be allowed
138 to be larger than the number of headline levels.
139 When nil, no table of contents is made.
141 Headlines which contain any TODO items will be marked with \"(*)\" in
142 ASCII export, and with red color in HTML output, if the option
143 `org-export-mark-todo-in-toc' is set.
145 In HTML output, the TOC will be clickable.
147 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
149 :group
'org-export-general
151 (const :tag
"No Table of Contents" nil
)
152 (const :tag
"Full Table of Contents" t
)
153 (integer :tag
"TOC to level")))
155 (defcustom org-export-mark-todo-in-toc nil
156 "Non-nil means, mark TOC lines that contain any open TODO items."
157 :group
'org-export-general
160 (defcustom org-export-preserve-breaks nil
161 "Non-nil means, preserve all line breaks when exporting.
162 Normally, in HTML output paragraphs will be reformatted. In ASCII
163 export, line breaks will always be preserved, regardless of this variable.
165 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
166 :group
'org-export-general
169 (defcustom org-export-with-archived-trees
'headline
170 "Whether subtrees with the ARCHIVE tag should be exported.
171 This can have three different values
172 nil Do not export, pretend this tree is not present
173 t Do export the entire tree
174 headline Only export the headline, but skip the tree below it."
175 :group
'org-export-general
178 (const :tag
"not at all" nil
)
179 (const :tag
"headline only" 'headline
)
180 (const :tag
"entirely" t
)))
182 (defcustom org-export-author-info t
183 "Non-nil means, insert author name and email into the exported file.
185 This option can also be set with the +OPTIONS line,
186 e.g. \"author-info:nil\"."
187 :group
'org-export-general
190 (defcustom org-export-time-stamp-file t
191 "Non-nil means, insert a time stamp into the exported file.
192 The time stamp shows when the file was created.
194 This option can also be set with the +OPTIONS line,
195 e.g. \"timestamp:nil\"."
196 :group
'org-export-general
199 (defcustom org-export-with-timestamps t
200 "If nil, do not export time stamps and associated keywords."
201 :group
'org-export-general
204 (defcustom org-export-remove-timestamps-from-toc t
205 "If nil, remove timestamps from the table of contents entries."
206 :group
'org-export-general
209 (defcustom org-export-with-tags
'not-in-toc
210 "If nil, do not export tags, just remove them from headlines.
211 If this is the symbol `not-in-toc', tags will be removed from table of
212 contents entries, but still be shown in the headlines of the document.
214 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
215 :group
'org-export-general
217 (const :tag
"Off" nil
)
218 (const :tag
"Not in TOC" not-in-toc
)
219 (const :tag
"On" t
)))
221 (defcustom org-export-with-drawers nil
222 "Non-nil means, export with drawers like the property drawer.
223 When t, all drawers are exported. This may also be a list of
224 drawer names to export."
225 :group
'org-export-general
227 (const :tag
"All drawers" t
)
228 (const :tag
"None" nil
)
229 (repeat :tag
"Selected drawers"
230 (string :tag
"Drawer name"))))
232 (defvar org-export-preprocess-hook nil
233 "Hook for preprocessing an export buffer.
234 Pretty much the first thing when exporting is running this hook.")
236 (defgroup org-export-translation nil
237 "Options for translating special ascii sequences for the export backends."
238 :tag
"Org Export Translation"
241 (defcustom org-export-with-emphasize t
242 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
243 If the export target supports emphasizing text, the word will be
244 typeset in bold, italic, or underlined, respectively. Works only for
245 single words, but you can say: I *really* *mean* *this*.
246 Not all export backends support this.
248 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
249 :group
'org-export-translation
252 (defcustom org-export-with-footnotes t
253 "If nil, export [1] as a footnote marker.
254 Lines starting with [1] will be formatted as footnotes.
256 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
257 :group
'org-export-translation
260 (defcustom org-export-with-sub-superscripts t
261 "Non-nil means, interpret \"_\" and \"^\" for export.
262 When this option is turned on, you can use TeX-like syntax for sub- and
263 superscripts. Several characters after \"_\" or \"^\" will be
264 considered as a single item - so grouping with {} is normally not
265 needed. For example, the following things will be parsed as single
266 sub- or superscripts.
268 10^24 or 10^tau several digits will be considered 1 item.
269 10^-12 or 10^-tau a leading sign with digits or a word
270 x^2-y^3 will be read as x^2 - y^3, because items are
271 terminated by almost any nonword/nondigit char.
272 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
274 Still, ambiguity is possible - so when in doubt use {} to enclose the
275 sub/superscript. If you set this variable to the symbol `{}',
276 the braces are *required* in order to trigger interpretations as
277 sub/superscript. This can be helpful in documents that need \"_\"
278 frequently in plain text.
280 Not all export backends support this, but HTML does.
282 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
283 :group
'org-export-translation
285 (const :tag
"Always interpret" t
)
286 (const :tag
"Only with braces" {})
287 (const :tag
"Never interpret" nil
)))
289 (defcustom org-export-with-special-strings t
290 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
291 When this option is turned on, these strings will be exported as:
297 Not all export backends support this, but HTML does.
299 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
300 :group
'org-export-translation
303 (defcustom org-export-with-TeX-macros t
304 "Non-nil means, interpret simple TeX-like macros when exporting.
305 For example, HTML export converts \\alpha to α and \\AA to Å.
306 No only real TeX macros will work here, but the standard HTML entities
307 for math can be used as macro names as well. For a list of supported
308 names in HTML export, see the constant `org-html-entities'.
309 Not all export backends support this.
311 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
312 :group
'org-export-translation
313 :group
'org-export-latex
316 (defcustom org-export-with-LaTeX-fragments nil
317 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
318 When set, the exporter will find LaTeX environments if the \\begin line is
319 the first non-white thing on a line. It will also find the math delimiters
320 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
323 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
324 :group
'org-export-translation
325 :group
'org-export-latex
328 (defcustom org-export-with-fixed-width t
329 "Non-nil means, lines starting with \":\" will be in fixed width font.
330 This can be used to have pre-formatted text, fragments of code etc. For
332 : ;; Some Lisp examples
335 will be looking just like this in also HTML. See also the QUOTE keyword.
336 Not all export backends support this.
338 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
339 :group
'org-export-translation
342 (defcustom org-match-sexp-depth
3
343 "Number of stacked braces for sub/superscript matching.
344 This has to be set before loading org.el to be effective."
345 :group
'org-export-translation
348 (defgroup org-export-tables nil
349 "Options for exporting tables in Org-mode."
350 :tag
"Org Export Tables"
353 (defcustom org-export-with-tables t
354 "If non-nil, lines starting with \"|\" define a table.
357 | Name | Address | Birthday |
358 |-------------+----------+-----------|
359 | Arthur Dent | England | 29.2.2100 |
361 Not all export backends support this.
363 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
364 :group
'org-export-tables
367 (defcustom org-export-highlight-first-table-line t
368 "Non-nil means, highlight the first table line.
369 In HTML export, this means use <th> instead of <td>.
370 In tables created with table.el, this applies to the first table line.
371 In Org-mode tables, all lines before the first horizontal separator
372 line will be formatted with <th> tags."
373 :group
'org-export-tables
376 (defcustom org-export-table-remove-special-lines t
377 "Remove special lines and marking characters in calculating tables.
378 This removes the special marking character column from tables that are set
379 up for spreadsheet calculations. It also removes the entire lines
380 marked with `!', `_', or `^'. The lines with `$' are kept, because
381 the values of constants may be useful to have."
382 :group
'org-export-tables
385 (defcustom org-export-prefer-native-exporter-for-tables nil
386 "Non-nil means, always export tables created with table.el natively.
387 Natively means, use the HTML code generator in table.el.
388 When nil, Org-mode's own HTML generator is used when possible (i.e. if
389 the table does not use row- or column-spanning). This has the
390 advantage, that the automatic HTML conversions for math symbols and
391 sub/superscripts can be applied. Org-mode's HTML generator is also
393 :group
'org-export-tables
396 (defgroup org-export-ascii nil
397 "Options specific for ASCII export of Org-mode files."
398 :tag
"Org Export ASCII"
401 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
402 "Characters for underlining headings in ASCII export.
403 In the given sequence, these characters will be used for level 1, 2, ..."
404 :group
'org-export-ascii
405 :type
'(repeat character
))
407 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
408 "Bullet characters for headlines converted to lists in ASCII export.
409 The first character is used for the first lest level generated in this
410 way, and so on. If there are more levels than characters given here,
411 the list will be repeated.
412 Note that plain lists will keep the same bullets as the have in the
414 :group
'org-export-ascii
415 :type
'(repeat character
))
417 (defgroup org-export-xml nil
418 "Options specific for XML export of Org-mode files."
419 :tag
"Org Export XML"
422 (defgroup org-export-html nil
423 "Options specific for HTML export of Org-mode files."
424 :tag
"Org Export HTML"
427 (defcustom org-export-html-coding-system nil
428 "Coding system for HTML export, defaults to buffer-file-coding-system."
429 :group
'org-export-html
430 :type
'coding-system
)
432 (defcustom org-export-html-extension
"html"
433 "The extension for exported HTML files."
434 :group
'org-export-html
437 (defcustom org-export-html-link-up
""
438 "Where should the \"UP\" link of exported HTML pages lead?"
439 :group
'org-export-html
440 :type
'(string :tag
"File or URL"))
442 (defcustom org-export-html-link-home
""
443 "Where should the \"HOME\" link of exported HTML pages lead?"
444 :group
'org-export-html
445 :type
'(string :tag
"File or URL"))
447 (defcustom org-export-html-style
448 "<style type=\"text/css\">
450 font-family: Times, serif;
453 .title { text-align: center; }
454 .todo { color: red; }
455 .done { color: green; }
456 .timestamp { color: grey }
457 .timestamp-kwd { color: CadetBlue }
458 .tag { background-color:lightblue; font-weight:normal }
461 border: 1pt solid #AEBDCC;
462 background-color: #F3F5F7;
464 font-family: courier, monospace;
466 table { border-collapse: collapse; }
469 <!--border: 1pt solid #ADB9CC;-->
471 dt { font-weight: bold; }
473 "The default style specification for exported HTML files.
474 Since there are different ways of setting style information, this variable
475 needs to contain the full HTML structure to provide a style, including the
476 surrounding HTML tags. The style specifications should include definitions
477 for new classes todo, done, title, and deadline. For example, valid values
480 <style type=\"text/css\">
481 p { font-weight: normal; color: gray; }
483 .title { text-align: center; }
484 .todo, .deadline { color: red; }
485 .done { color: green; }
488 or, if you want to keep the style in a file,
490 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
492 As the value of this option simply gets inserted into the HTML <head> header,
493 you can \"misuse\" it to add arbitrary text to the header."
494 :group
'org-export-html
498 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
499 "Format for typesetting the document title in HTML export."
500 :group
'org-export-html
503 (defcustom org-export-html-toplevel-hlevel
2
504 "The <H> level for level 1 headings in HTML export."
505 :group
'org-export-html
508 (defcustom org-export-html-link-org-files-as-html t
509 "Non-nil means, make file links to `file.org' point to `file.html'.
510 When org-mode is exporting an org-mode file to HTML, links to
511 non-html files are directly put into a href tag in HTML.
512 However, links to other Org-mode files (recognized by the
513 extension `.org.) should become links to the corresponding html
514 file, assuming that the linked org-mode file will also be
516 When nil, the links still point to the plain `.org' file."
517 :group
'org-export-html
520 (defcustom org-export-html-inline-images
'maybe
521 "Non-nil means, inline images into exported HTML pages.
522 This is done using an <img> tag. When nil, an anchor with href is used to
523 link to the image. If this option is `maybe', then images in links with
524 an empty description will be inlined, while images with a description will
526 :group
'org-export-html
527 :type
'(choice (const :tag
"Never" nil
)
528 (const :tag
"Always" t
)
529 (const :tag
"When there is no description" maybe
)))
532 (defcustom org-export-html-expand t
533 "Non-nil means, for HTML export, treat @<...> as HTML tag.
534 When nil, these tags will be exported as plain text and therefore
535 not be interpreted by a browser.
537 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
538 :group
'org-export-html
541 (defcustom org-export-html-table-tag
542 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
543 "The HTML tag that is used to start a table.
544 This must be a <table> tag, but you may change the options like
545 borders and spacing."
546 :group
'org-export-html
549 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
550 "The opening tag for table header fields.
551 This is customizable so that alignment options can be specified."
552 :group
'org-export-tables
553 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
555 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
556 "The opening tag for table data fields.
557 This is customizable so that alignment options can be specified."
558 :group
'org-export-tables
559 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
561 (defcustom org-export-html-with-timestamp nil
562 "If non-nil, write `org-export-html-html-helper-timestamp'
563 into the exported HTML text. Otherwise, the buffer will just be saved
565 :group
'org-export-html
568 (defcustom org-export-html-html-helper-timestamp
569 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
570 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
571 :group
'org-export-html
574 (defgroup org-export-htmlize nil
575 "Options for processing examples with htmlize.el."
576 :tag
"Org Export Htmlize"
577 :group
'org-export-html
)
579 (defcustom org-export-htmlize-output-type
'inline-css
580 "Output type to be used by htmlize when formatting code snippets.
581 Normally this is `inline-css', but if you have defined to appropriate
582 classes in your css style file, setting this to `css' means that the
583 fontification will use the class names.
584 See also the function `org-export-htmlize-generate-css'."
585 :group
'org-export-htmlize
586 :type
'(choice (const css
) (const inline-css
)))
588 (defcustom org-export-htmlize-css-font-prefix
"org-"
589 "The prefix for CSS class names for htmlize font specifications."
590 :group
'org-export-htmlize
593 (defgroup org-export-icalendar nil
594 "Options specific for iCalendar export of Org-mode files."
595 :tag
"Org Export iCalendar"
598 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
599 "The file name for the iCalendar file covering all agenda files.
600 This file is created with the command \\[org-export-icalendar-all-agenda-files].
601 The file name should be absolute, the file will be overwritten without warning."
602 :group
'org-export-icalendar
605 (defcustom org-icalendar-include-todo nil
606 "Non-nil means, export to iCalendar files should also cover TODO items."
607 :group
'org-export-icalendar
609 (const :tag
"None" nil
)
610 (const :tag
"Unfinished" t
)
611 (const :tag
"All" all
)))
613 (defcustom org-icalendar-include-sexps t
614 "Non-nil means, export to iCalendar files should also cover sexp entries.
615 These are entries like in the diary, but directly in an Org-mode file."
616 :group
'org-export-icalendar
619 (defcustom org-icalendar-include-body
100
620 "Amount of text below headline to be included in iCalendar export.
621 This is a number of characters that should maximally be included.
622 Properties, scheduling and clocking lines will always be removed.
623 The text will be inserted into the DESCRIPTION field."
624 :group
'org-export-icalendar
626 (const :tag
"Nothing" nil
)
627 (const :tag
"Everything" t
)
628 (integer :tag
"Max characters")))
630 (defcustom org-icalendar-combined-name
"OrgMode"
631 "Calendar name for the combined iCalendar representing all agenda files."
632 :group
'org-export-icalendar
637 ;;; Variables, constants, and parameter plists
639 (defconst org-level-max
20)
641 (defvar org-export-html-preamble nil
642 "Preamble, to be inserted just after <body>. Set by publishing functions.")
643 (defvar org-export-html-postamble nil
644 "Preamble, to be inserted just before </body>. Set by publishing functions.")
645 (defvar org-export-html-auto-preamble t
646 "Should default preamble be inserted? Set by publishing functions.")
647 (defvar org-export-html-auto-postamble t
648 "Should default postamble be inserted? Set by publishing functions.")
649 (defvar org-current-export-file nil
) ; dynamically scoped parameter
650 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
652 (defconst org-export-plist-vars
653 '((:link-up . org-export-html-link-up
)
654 (:link-home . org-export-html-link-home
)
655 (:language . org-export-default-language
)
656 (:customtime . org-display-custom-times
)
657 (:headline-levels . org-export-headline-levels
)
658 (:section-numbers . org-export-with-section-numbers
)
659 (:table-of-contents . org-export-with-toc
)
660 (:preserve-breaks . org-export-preserve-breaks
)
661 (:archived-trees . org-export-with-archived-trees
)
662 (:emphasize . org-export-with-emphasize
)
663 (:sub-superscript . org-export-with-sub-superscripts
)
664 (:special-strings . org-export-with-special-strings
)
665 (:footnotes . org-export-with-footnotes
)
666 (:drawers . org-export-with-drawers
)
667 (:tags . org-export-with-tags
)
668 (:TeX-macros . org-export-with-TeX-macros
)
669 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
670 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
671 (:fixed-width . org-export-with-fixed-width
)
672 (:timestamps . org-export-with-timestamps
)
673 (:author-info . org-export-author-info
)
674 (:time-stamp-file . org-export-time-stamp-file
)
675 (:tables . org-export-with-tables
)
676 (:table-auto-headline . org-export-highlight-first-table-line
)
677 (:style . org-export-html-style
)
678 (:agenda-style . org-agenda-export-html-style
)
679 (:convert-org-links . org-export-html-link-org-files-as-html
)
680 (:inline-images . org-export-html-inline-images
)
681 (:html-extension . org-export-html-extension
)
682 (:html-table-tag . org-export-html-table-tag
)
683 (:expand-quoted-html . org-export-html-expand
)
684 (:timestamp . org-export-html-with-timestamp
)
685 (:publishing-directory . org-export-publishing-directory
)
686 (:preamble . org-export-html-preamble
)
687 (:postamble . org-export-html-postamble
)
688 (:auto-preamble . org-export-html-auto-preamble
)
689 (:auto-postamble . org-export-html-auto-postamble
)
690 (:author . user-full-name
)
691 (:email . user-mail-address
)))
693 (defun org-default-export-plist ()
694 "Return the property list with default settings for the export variables."
695 (let ((l org-export-plist-vars
) rtn e
)
696 (while (setq e
(pop l
))
697 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
700 (defvar org-export-inbuffer-options-extra nil
701 "List of additional in-buffer options that should be detected.
702 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
703 etc. Extensions can add to this list to get their options detected, and they
704 can then add a function to `org-export-options-filters' to process these
706 Each element in this list must be a list, with the in-buffer keyword as car,
707 and a property (a symbol) as the next element. All occurences of the
708 keyword will be found, the values concatenated with a space character
709 in between, and the result stored in the export options property list.")
711 (defvar org-export-options-filters nil
712 "Functions to be called to finalize the export/publishing options.
713 All these options are stored in a property list, and each of the functions
714 in this hook gets a chance to modify this property list. Each function
715 must accept the property list as an argument, and must return the (possibly
718 (defun org-infile-export-plist ()
719 "Return the property list with file-local settings for export."
723 (goto-char (point-min))
724 (let ((re (org-make-options-regexp
726 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
727 "LINK_UP" "LINK_HOME" "SETUPFILE")
728 (mapcar 'car org-export-inbuffer-options-extra
))))
729 p key val text options js-up js-main js-css js-opt a pr
730 ext-setup-or-nil setup-contents
(start 0))
731 (while (or (and ext-setup-or-nil
732 (string-match re ext-setup-or-nil start
)
733 (setq start
(match-end 0)))
734 (and (setq ext-setup-or-nil nil start
0)
735 (re-search-forward re nil t
)))
736 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
737 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
739 ((setq a
(assoc key org-export-inbuffer-options-extra
))
741 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
742 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
743 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
744 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
745 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
746 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
747 ((string-equal key
"TEXT")
748 (setq text
(if text
(concat text
"\n" val
) val
)))
749 ((string-equal key
"OPTIONS")
750 (setq options
(concat val
" " options
)))
751 ((string-equal key
"LINK_UP")
752 (setq p
(plist-put p
:link-up val
)))
753 ((string-equal key
"LINK_HOME")
754 (setq p
(plist-put p
:link-home val
)))
755 ((equal key
"SETUPFILE")
756 (setq setup-contents
(org-file-contents
758 (org-remove-double-quotes
761 (if (not ext-setup-or-nil
)
762 (setq ext-setup-or-nil setup-contents start
0)
763 (setq ext-setup-or-nil
764 (concat (substring ext-setup-or-nil
0 start
)
765 "\n" setup-contents
"\n"
766 (substring ext-setup-or-nil start
)))))))
767 (setq p
(plist-put p
:text text
))
769 (let ((op '(("H" .
:headline-levels
)
770 ("num" .
:section-numbers
)
771 ("toc" .
:table-of-contents
)
772 ("\\n" .
:preserve-breaks
)
773 ("@" .
:expand-quoted-html
)
776 ("^" .
:sub-superscript
)
777 ("-" .
:special-strings
)
782 ("TeX" .
:TeX-macros
)
783 ("LaTeX" .
:LaTeX-fragments
)
784 ("skip" .
:skip-before-1st-heading
)
785 ("author" .
:author-info
)
786 ("timestamp" .
:time-stamp-file
)))
788 (while (setq o
(pop op
))
789 (if (string-match (concat (regexp-quote (car o
))
790 ":\\([^ \t\n\r;,.]*\\)")
792 (setq p
(plist-put p
(cdr o
)
793 (car (read-from-string
794 (match-string 1 options
)))))))))
797 (defun org-export-directory (type plist
)
798 (let* ((val (plist-get plist
:publishing-directory
))
800 (or (cdr (assoc type val
)) ".")
804 (defun org-export-process-option-filters (plist)
805 (let ((functions org-export-options-filters
) f
)
806 (while (setq f
(pop functions
))
807 (setq plist
(funcall f plist
))))
811 (defun org-export (&optional arg
)
812 "Export dispatcher for Org-mode.
813 When `org-export-run-in-background' is non-nil, try to run the command
814 in the background. This will be done only for commands that write
815 to a file. For details see the docstring of `org-export-run-in-background'.
817 The prefix argument ARG will be passed to the exporter. However, if
818 ARG is a double universal prefix `C-u C-u', that means to inverse the
819 value of `org-export-run-in-background'."
821 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
822 (help "[t] insert the export option template
823 \[v] limit export to visible part of outline tree
828 \[H] export as HTML to temporary buffer
829 \[R] export region as HTML
830 \[b] export as HTML and browse immediately
834 \[L] export as LaTeX to temporary buffer
836 \[i] export current file as iCalendar file
837 \[I] export all agenda files as iCalendar files
838 \[c] export agenda files into combined iCalendar file
840 \[F] publish current file
841 \[P] publish current project
842 \[X] publish... (project will be prompted for)
843 \[A] publish all projects")
845 '((?t org-insert-export-options-template nil
)
846 (?v org-export-visible nil
)
847 (?a org-export-as-ascii t
)
848 (?h org-export-as-html t
)
849 (?b org-export-as-html-and-open t
)
850 (?H org-export-as-html-to-buffer nil
)
851 (?R org-export-region-as-html nil
)
852 (?x org-export-as-xoxo t
)
853 (?l org-export-as-latex t
)
854 (?L org-export-as-latex-to-buffer nil
)
855 (?i org-export-icalendar-this-file t
)
856 (?I org-export-icalendar-all-agenda-files t
)
857 (?c org-export-icalendar-combine-agenda-files t
)
858 (?F org-publish-current-file t
)
859 (?P org-publish-current-project t
)
861 (?A org-publish-all t
)))
863 (save-window-excursion
864 (delete-other-windows)
865 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
867 (message "Select command: ")
868 (setq r1
(read-char-exclusive)))
869 (setq r2
(if (< r1
27) (+ r1
96) r1
))
870 (unless (setq ass
(assq r2 cmds
))
871 (error "No command associated with key %c" r1
))
872 (if (and bg
(nth 2 ass
))
873 ;; execute in background
874 (let ((p (start-process
875 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
877 (expand-file-name invocation-name invocation-directory
)
880 "--eval" "(require 'org-exp)"
881 "--eval" "(setq org-wait .2)"
883 "-f" (symbol-name (nth 1 ass
)))))
884 (set-process-sentinel p
'org-export-process-sentinel
)
885 (message "Background process \"%s\": started" p
))
886 ;; background processing not requested, or not possible
887 (call-interactively (nth 1 ass
)))))
889 (defun org-export-process-sentinel (process status
)
890 (if (string-match "\n+\\'" status
)
891 (setq status
(substring status
0 -
1)))
892 (message "Background process \"%s\": %s" process status
))
894 (defconst org-html-entities
935 ("Aring") ("AA".
"Å")
1024 ("varepsilon".
"ε")
1037 ("sigmaf") ("varsigma".
"ς")
1045 ("thetasym") ("vartheta".
"ϑ")
1048 ("bull") ("bullet".
"•")
1049 ("hellip") ("dots".
"…")
1059 ("larr") ("leftarrow".
"←") ("gets".
"←")
1060 ("uarr") ("uparrow".
"↑")
1061 ("rarr") ("to".
"→") ("rightarrow".
"→")
1062 ("darr")("downarrow".
"↓")
1063 ("harr") ("leftrightarrow".
"↔")
1064 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1065 ("lArr") ("Leftarrow".
"⇐")
1066 ("uArr") ("Uparrow".
"⇑")
1067 ("rArr") ("Rightarrow".
"⇒")
1068 ("dArr") ("Downarrow".
"⇓")
1069 ("hArr") ("Leftrightarrow".
"⇔")
1071 ("part") ("partial".
"∂")
1072 ("exist") ("exists".
"∃")
1073 ("empty") ("emptyset".
"∅")
1075 ("isin") ("in".
"∈")
1081 ("lowast") ("ast".
"∗")
1083 ("prop") ("proptp".
"∝")
1084 ("infin") ("infty".
"∞")
1085 ("ang") ("angle".
"∠")
1086 ("and") ("wedge".
"∧")
1087 ("or") ("vee".
"∨")
1093 ("cong") ("simeq".
"≅")
1094 ("asymp")("approx".
"≈")
1095 ("ne") ("neq".
"≠")
1099 ("sub") ("subset".
"⊂")
1100 ("sup") ("supset".
"⊃")
1107 ("sdot") ("cdot".
"⋅")
1114 ("loz") ("Diamond".
"◊")
1115 ("spades") ("spadesuit".
"♠")
1116 ("clubs") ("clubsuit".
"♣")
1117 ("hearts") ("diamondsuit".
"♥")
1118 ("diams") ("diamondsuit".
"♦")
1119 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1186 "Entities for TeX->HTML translation.
1187 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1188 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1189 In that case, \"\\ent\" will be translated to \"&other;\".
1190 The list contains HTML entities for Latin-1, Greek and other symbols.
1191 It is supplemented by a number of commonly used TeX macros with appropriate
1192 translations. There is currently no way for users to extend this.")
1194 ;;; General functions for all backends
1196 (defun org-export-preprocess-string (string &rest parameters
)
1197 "Cleanup STRING so that that the true exported has a more consistent source.
1198 This function takes STRING, which should be a buffer-string of an org-file
1199 to export. It then creates a temporary buffer where it does its job.
1200 The result is then again returned as a string, and the exporter works
1201 on this string to produce the exported version."
1203 (let* ((re-radio (and org-target-link-regexp
1204 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1205 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1206 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1207 (re-archive (concat ":" org-archive-tag
":"))
1208 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1209 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1210 (htmlp (plist-get parameters
:for-html
))
1211 (asciip (plist-get parameters
:for-ascii
))
1212 (latexp (plist-get parameters
:for-LaTeX
))
1213 (commentsp (plist-get parameters
:comments
))
1214 (archived-trees (plist-get parameters
:archived-trees
))
1215 (inhibit-read-only t
)
1216 (drawers org-drawers
)
1217 (exp-drawers (plist-get parameters
:drawers
))
1218 (outline-regexp "\\*+ ")
1219 target-alist tmp target level
1222 (with-current-buffer (get-buffer-create " org-mode-tmp")
1225 (setq case-fold-search t
)
1227 (run-hooks 'org-export-preprocess-hook
)
1229 ;; Remove license-to-kill stuff
1230 ;; The caller markes some stuff fo killing, stuff that has been
1231 ;; used to create the page title, for example.
1232 (while (setq p
(text-property-any (point-min) (point-max)
1233 :org-license-to-kill t
))
1234 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1236 (let ((org-inhibit-startup t
)) (org-mode))
1237 (setq case-fold-search t
)
1238 (untabify (point-min) (point-max))
1240 ;; Handle incude files
1241 (org-export-handle-include-files)
1243 ;; Handle source code snippets
1244 (org-export-replace-src-segments)
1246 ;; Get rid of drawers
1247 (unless (eq t exp-drawers
)
1248 (goto-char (point-min))
1249 (let ((re (concat "^[ \t]*:\\("
1252 (org-delete-all exp-drawers
1253 (copy-sequence drawers
))
1255 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1256 (while (re-search-forward re nil t
)
1257 (replace-match ""))))
1259 ;; Get the correct stuff before the first headline
1260 (when (plist-get parameters
:skip-before-1st-heading
)
1261 (goto-char (point-min))
1262 (when (re-search-forward "^\\*+[ \t]" nil t
)
1263 (delete-region (point-min) (match-beginning 0))
1264 (goto-char (point-min))
1266 (when (plist-get parameters
:add-text
)
1267 (goto-char (point-min))
1268 (insert (plist-get parameters
:add-text
) "\n"))
1270 ;; Get rid of archived trees
1271 (when (not (eq archived-trees t
))
1272 (goto-char (point-min))
1273 (while (re-search-forward re-archive nil t
)
1274 (if (not (org-on-heading-p t
))
1275 (org-end-of-subtree t
)
1276 (beginning-of-line 1)
1277 (setq a
(if archived-trees
1278 (1+ (point-at-eol)) (point))
1279 b
(org-end-of-subtree t
))
1280 (if (> b a
) (delete-region a b
)))))
1282 ;; Find all headings and compute the targets for them
1283 (goto-char (point-min))
1284 (org-init-section-numbers)
1285 (let ((re (concat "^" org-outline-regexp
)))
1286 (while (re-search-forward re nil t
)
1287 (setq level
(org-reduced-level
1288 (save-excursion (goto-char (point-at-bol))
1289 (org-outline-level))))
1290 (setq target
(org-solidify-link-text
1291 (format "sec-%s" (org-section-number level
))))
1292 (push (cons target target
) target-alist
)
1293 (add-text-properties
1294 (point-at-bol) (point-at-eol)
1295 (list 'target target
))))
1297 ;; Find targets in comments and move them out of comments,
1298 ;; but mark them as targets that should be invisible
1299 (goto-char (point-min))
1300 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1301 ;; Check if the line before or after is a headline with a target
1302 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1303 (get-text-property (point-at-bol 2) 'target
)))
1305 ;; use the existing target in a neighboring line
1306 (setq tmp
(match-string 2))
1308 (and (looking-at "\n") (delete-char 1))
1309 (push (cons (org-solidify-link-text tmp
) target
)
1311 ;; Make an invisible target
1312 (replace-match "\\1(INVISIBLE)")))
1314 ;; Protect backend specific stuff, throw away the others.
1316 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1317 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1318 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1320 (goto-char (point-min))
1321 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1322 (goto-char (match-end 0))
1323 (while (not (looking-at "#\\+END_EXAMPLE"))
1325 (beginning-of-line 2)))
1326 (goto-char (point-min))
1327 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1328 (add-text-properties (match-beginning 0) (match-end 0)
1329 '(org-protected t
)))
1331 (setq fmt
(pop formatters
))
1333 (goto-char (point-min))
1334 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1335 ":[ \t]*\\(.*\\)") nil t
)
1336 (replace-match "\\1" t
)
1337 (add-text-properties
1338 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1339 '(org-protected t
))))
1340 (goto-char (point-min))
1341 (while (re-search-forward
1343 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1344 (cadddr fmt
) "\\>.*\n?") nil t
)
1346 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1348 (delete-region (match-beginning 0) (match-end 0))))))
1350 ;; Protect quoted subtrees
1351 (goto-char (point-min))
1352 (while (re-search-forward re-quote nil t
)
1353 (goto-char (match-beginning 0))
1355 (add-text-properties (point) (org-end-of-subtree t
)
1356 '(org-protected t
)))
1358 ;; Protect verbatim elements
1359 (goto-char (point-min))
1360 (while (re-search-forward org-verbatim-re nil t
)
1361 (add-text-properties (match-beginning 4) (match-end 4)
1363 (goto-char (1+ (match-end 4))))
1366 (goto-char (point-min))
1367 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1368 (replace-match (if (equal (downcase (match-string 1)) "end")
1369 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1372 (goto-char (point-min))
1373 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1374 (replace-match (if (equal (downcase (match-string 1)) "end")
1375 "ORG-VERSE-END" "ORG-VERSE-START")
1378 ;; Remove comment environment
1379 (goto-char (point-min))
1380 (while (re-search-forward
1381 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1382 (replace-match "" t t
))
1384 ;; Remove subtrees that are commented
1385 (goto-char (point-min))
1386 (while (re-search-forward re-commented nil t
)
1387 (goto-char (match-beginning 0))
1388 (delete-region (point) (org-end-of-subtree t
)))
1390 ;; Remove special table lines
1391 (when org-export-table-remove-special-lines
1392 (goto-char (point-min))
1393 (while (re-search-forward "^[ \t]*|" nil t
)
1394 (beginning-of-line 1)
1395 (if (or (looking-at "[ \t]*| *[!_^] *|")
1396 (and (looking-at ".*?| *<[0-9]+> *|")
1397 (not (looking-at ".*?| *[^ <|]"))))
1398 (delete-region (max (point-min) (1- (point-at-bol)))
1402 ;; Specific LaTeX stuff
1404 (require 'org-export-latex nil
)
1405 (org-export-latex-preprocess))
1408 (org-export-ascii-clean-string))
1410 ;; Specific HTML stuff
1412 ;; Convert LaTeX fragments to images
1413 (when (plist-get parameters
:LaTeX-fragments
)
1415 (concat "ltxpng/" (file-name-sans-extension
1416 (file-name-nondirectory
1417 org-current-export-file
)))
1418 org-current-export-dir nil
"Creating LaTeX image %s"))
1419 (message "Exporting..."))
1421 ;; Remove or replace comments
1422 (goto-char (point-min))
1423 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1425 (progn (add-text-properties
1426 (match-beginning 0) (match-end 0) '(org-protected t
))
1427 (replace-match (format commentsp
(match-string 1)) t t
))
1428 (replace-match "")))
1430 ;; Find matches for radio targets and turn them into internal links
1431 (goto-char (point-min))
1433 (while (re-search-forward re-radio nil t
)
1435 (replace-match "\\1[[\\2]]"))))
1437 ;; Find all links that contain a newline and put them into a single line
1438 (goto-char (point-min))
1439 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1441 (replace-match "\\1 \\3")
1442 (goto-char (match-beginning 0))))
1444 ;; Find all internal links. If they have a fuzzy match (i.e. not
1445 ;; a *dedicated* target match, let the link point to the
1446 ;; correspinding section.
1448 (goto-char (point-min))
1449 (while (re-search-forward org-bracket-link-regexp nil t
)
1451 (let* ((md (match-data))
1452 (desc (match-end 2))
1453 (link (org-link-unescape (match-string 1)))
1454 (slink (org-solidify-link-text link
))
1457 (or (cdr (assoc slink target-alist
))
1459 (unless (string-match org-link-types-re link
)
1460 (setq found
(condition-case nil
(org-link-search link
)
1463 (or (org-on-heading-p)
1464 (not (eq found
'dedicated
))))
1465 (or (get-text-property (point) 'target
)
1468 (1- (previous-single-property-change
1473 (goto-char (match-beginning 1))
1474 (setq props
(text-properties-at (point)))
1475 (delete-region (match-beginning 1) (match-end 1))
1478 (unless desc
(insert "][" link
))
1479 (add-text-properties pos
(point) props
)))))
1481 ;; Normalize links: Convert angle and plain links into bracket links
1482 ;; Expand link abbreviations
1483 (goto-char (point-min))
1484 (while (re-search-forward re-plain-link nil t
)
1485 (goto-char (1- (match-end 0)))
1487 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1488 ":" (match-string 3) "]]")))
1489 ;; added 'org-link face to links
1490 (put-text-property 0 (length s
) 'face
'org-link s
)
1491 (replace-match s t t
))))
1492 (goto-char (point-min))
1493 (while (re-search-forward re-angle-link nil t
)
1494 (goto-char (1- (match-end 0)))
1496 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1497 ":" (match-string 3) "]]")))
1498 (put-text-property 0 (length s
) 'face
'org-link s
)
1499 (replace-match s t t
))))
1500 (goto-char (point-min))
1501 (while (re-search-forward org-bracket-link-regexp nil t
)
1503 (let* ((s (concat "[[" (setq xx
(save-match-data
1504 (org-link-expand-abbrev (match-string 1))))
1508 (concat "[" xx
"]"))
1510 (put-text-property 0 (length s
) 'face
'org-link s
)
1511 (replace-match s t t
))))
1513 ;; Find multiline emphasis and put them into single line
1514 (when (plist-get parameters
:emph-multiline
)
1515 (goto-char (point-min))
1516 (while (re-search-forward org-emph-re nil t
)
1517 (if (not (= (char-after (match-beginning 3))
1518 (char-after (match-beginning 4))))
1520 (subst-char-in-region (match-beginning 0) (match-end 0)
1522 (goto-char (1- (match-end 0))))
1523 (goto-char (1+ (match-beginning 0))))))
1525 (setq rtn
(buffer-string)))
1526 (kill-buffer " org-mode-tmp")
1529 (defun org-export-grab-title-from-buffer ()
1530 "Get a title for the current document, from looking at the buffer."
1531 (let ((inhibit-read-only t
))
1533 (goto-char (point-min))
1534 (let ((end (save-excursion (outline-next-heading) (point))))
1535 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1536 ;; Mark the line so that it will not be exported as normal text.
1538 (add-text-properties (match-beginning 0) (match-end 0)
1539 (list :org-license-to-kill t
)))
1540 ;; Return the title string
1541 (org-trim (match-string 0)))))))
1543 (defun org-export-get-title-from-subtree ()
1544 "Return subtree title and exclude it from export."
1545 (let (title (m (mark)))
1547 (goto-char (region-beginning))
1548 (when (and (org-at-heading-p)
1549 (>= (org-end-of-subtree t t
) (region-end)))
1550 ;; This is a subtree, we take the title from the first heading
1551 (goto-char (region-beginning))
1552 (looking-at org-todo-line-regexp
)
1553 (setq title
(match-string 3))
1555 (add-text-properties (point) (1+ (point-at-eol))
1556 (list :org-license-to-kill t
)))))
1559 (defun org-solidify-link-text (s &optional alist
)
1560 "Take link text and make a safe target out of it."
1565 (org-split-string s
"[ \t\r\n]+") "=="))
1566 (a (assoc rtn alist
)))
1569 (defun org-get-min-level (lines)
1570 "Get the minimum level in LINES."
1571 (let ((re "^\\(\\*+\\) ") l min
)
1573 (while (setq l
(pop lines
))
1574 (if (string-match re l
)
1575 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1578 ;; Variable holding the vector with section numbers
1579 (defvar org-section-numbers
(make-vector org-level-max
0))
1581 (defun org-init-section-numbers ()
1582 "Initialize the vector for the section numbers."
1584 (numbers (nreverse (org-split-string "" "\\.")))
1585 (depth (1- (length org-section-numbers
)))
1586 (i depth
) number-string
)
1589 (aset org-section-numbers i
0)
1590 (setq number-string
(or (car numbers
) "0"))
1591 (if (string-match "\\`[A-Z]\\'" number-string
)
1592 (aset org-section-numbers i
1593 (- (string-to-char number-string
) ?A -
1))
1594 (aset org-section-numbers i
(string-to-number number-string
)))
1598 (defun org-section-number (&optional level
)
1599 "Return a string with the current section number.
1600 When LEVEL is non-nil, increase section numbers on that level."
1601 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1604 (aset org-section-numbers
1605 level
(1+ (aref org-section-numbers level
))))
1606 (setq idx
(1+ level
))
1607 (while (<= idx depth
)
1609 (aset org-section-numbers idx
0))
1610 (setq idx
(1+ idx
))))
1612 (while (<= idx depth
)
1613 (setq n
(aref org-section-numbers idx
))
1614 (setq string
(concat string
(if (not (string= string
"")) "." "")
1616 (setq idx
(1+ idx
)))
1618 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1619 (setq string
(replace-match "" t nil string
)))
1620 (if (string-match "\\(\\.0\\)+\\'" string
)
1621 (setq string
(replace-match "" t nil string
))))
1626 (defun org-export-handle-include-files ()
1627 "Include the contents of include files, with proper formatting."
1628 (let ((case-fold-search t
)
1629 params file markup lang start end
)
1630 (goto-char (point-min))
1631 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1632 (setq params
(read (concat "(" (match-string 1) ")"))
1633 file
(org-symname-or-string (pop params
))
1634 markup
(org-symname-or-string (pop params
))
1635 lang
(org-symname-or-string (pop params
)))
1636 (delete-region (match-beginning 0) (match-end 0))
1638 (not (file-exists-p file
))
1639 (not (file-readable-p file
)))
1640 (insert (format "CANNOT INCLUDE FILE %s" file
))
1642 (if (equal (downcase markup
) "src")
1643 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1645 (setq start
(format "#+begin_%s\n" markup
)
1646 end
(format "#+end_%s" markup
))))
1647 (insert (or start
""))
1648 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1649 (or (bolp) (newline))
1650 (insert (or end
""))))))
1652 (defun org-symname-or-string (s)
1654 (if s
(symbol-name s
) s
)
1657 ;;; Fontification of code
1658 ;; Currently only for th HTML backend, but who knows....
1659 (defun org-export-replace-src-segments ()
1660 "Replace source code segments with special code for export."
1661 (let ((case-fold-search t
)
1663 (goto-char (point-min))
1664 (while (re-search-forward
1665 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1667 (setq lang
(match-string 1) code
(match-string 2)
1668 trans
(org-export-format-source-code lang code
))
1669 (replace-match trans t t
))))
1671 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1673 (defun org-export-format-source-code (lang code
)
1674 "Format CODE from language LANG and return it formatted for export.
1675 Currently, this only does something for HTML export, for all other
1676 backends, it converts the segment into an EXAMPLE segment."
1680 ;; We are exporting to HTML
1681 (condition-case nil
(require 'htmlize
) (nil t
))
1682 (if (not (fboundp 'htmlize-region-for-paste
))
1684 ;; we do not have htmlize.el, or an old version of it
1686 "htmlize.el 1.34 or later is needed for source code formatting")
1687 (concat "#+BEGIN_EXAMPLE\n" code
1688 (if (string-match "\n\\'" code
) "" "\n")
1690 ;; ok, we are good to go
1691 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1692 (org-inhibit-startup t
)
1693 (org-startup-folded nil
)
1697 ;; Free up the protected stuff
1698 (goto-char (point-min))
1699 (while (re-search-forward "^," nil t
)
1701 (if (functionp mode
)
1704 (font-lock-fontify-buffer)
1705 (org-export-htmlize-region-for-paste
1706 (point-min) (point-max)))))
1707 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1708 (setq htmltext
(replace-match "<pre class=\"src\">"
1710 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1712 ;; This is not HTML, so just make it an example.
1713 (concat "#+BEGIN_EXAMPLE\n" code
1714 (if (string-match "\n\\'" code
) "" "\n")
1715 "#+END_EXAMPLE\n")))))
1719 (defvar org-last-level nil
) ; dynamically scoped variable
1720 (defvar org-min-level nil
) ; dynamically scoped variable
1721 (defvar org-levels-open nil
) ; dynamically scoped parameter
1722 (defvar org-ascii-current-indentation nil
) ; For communication
1725 (defun org-export-as-ascii (arg)
1726 "Export the outline as a pretty ASCII file.
1727 If there is an active region, export only the region.
1728 The prefix ARG specifies how many levels of the outline should become
1729 underlined headlines. The default is 3."
1731 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1732 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1733 (org-infile-export-plist)))
1734 (region-p (org-region-active-p))
1738 (goto-char (region-beginning))
1739 (and (org-at-heading-p)
1740 (>= (org-end-of-subtree t t
) (region-end))))))
1741 (custom-times org-display-custom-times
)
1742 (org-ascii-current-indentation '(0 .
0))
1746 (case-fold-search nil
)
1747 (filename (concat (file-name-as-directory
1748 (org-export-directory :ascii opt-plist
))
1749 (file-name-sans-extension
1751 (org-entry-get (region-beginning)
1752 "EXPORT_FILE_NAME" t
))
1753 (file-name-nondirectory buffer-file-name
)))
1755 (filename (if (equal (file-truename filename
)
1756 (file-truename buffer-file-name
))
1757 (concat filename
".txt")
1759 (buffer (find-file-noselect filename
))
1760 (org-levels-open (make-vector org-level-max nil
))
1761 (odd org-odd-levels-only
)
1762 (date (plist-get opt-plist
:date
))
1763 (author (plist-get opt-plist
:author
))
1764 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1765 (plist-get opt-plist
:title
)
1767 (plist-get opt-plist
:skip-before-1st-heading
))
1768 (org-export-grab-title-from-buffer))
1769 (file-name-sans-extension
1770 (file-name-nondirectory buffer-file-name
))))
1771 (email (plist-get opt-plist
:email
))
1772 (language (plist-get opt-plist
:language
))
1773 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1774 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1779 (if (org-region-active-p) (region-beginning) (point-min))
1780 (if (org-region-active-p) (region-end) (point-max))))
1781 (lines (org-split-string
1782 (org-export-preprocess-string
1785 :skip-before-1st-heading
1786 (plist-get opt-plist
:skip-before-1st-heading
)
1787 :drawers
(plist-get opt-plist
:drawers
)
1788 :verbatim-multiline t
1790 (plist-get opt-plist
:archived-trees
)
1791 :add-text
(plist-get opt-plist
:text
))
1793 thetoc have-headings first-heading-pos
1794 table-open table-buffer
)
1796 (let ((inhibit-read-only t
))
1798 (remove-text-properties (point-min) (point-max)
1799 '(:org-license-to-kill t
))))
1801 (setq org-min-level
(org-get-min-level lines
))
1802 (setq org-last-level org-min-level
)
1803 (org-init-section-numbers)
1805 (find-file-noselect filename
)
1807 (setq lang-words
(or (assoc language org-export-language-setup
)
1808 (assoc "en" org-export-language-setup
)))
1809 (switch-to-buffer-other-window buffer
)
1812 ;; create local variables for all options, to make sure all called
1813 ;; functions get the correct information
1815 (set (make-local-variable (cdr x
))
1816 (plist-get opt-plist
(car x
))))
1817 org-export-plist-vars
)
1818 (org-set-local 'org-odd-levels-only odd
)
1819 (setq umax
(if arg
(prefix-numeric-value arg
)
1820 org-export-headline-levels
))
1821 (setq umax-toc
(if (integerp org-export-with-toc
)
1822 (min org-export-with-toc umax
)
1826 (if title
(org-insert-centered title ?
=))
1828 (if (and (or author email
)
1829 org-export-author-info
)
1830 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1831 (if email
(concat " <" email
">") "")
1835 ((and date
(string-match "%" date
))
1836 (setq date
(format-time-string date
)))
1838 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1840 (if (and date org-export-time-stamp-file
)
1841 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1845 (if org-export-with-toc
1847 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1848 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1849 (mapc '(lambda (line)
1850 (if (string-match org-todo-line-regexp
1852 ;; This is a headline
1854 (setq have-headings t
)
1855 (setq level
(- (match-end 1) (match-beginning 1))
1856 level
(org-tr-level level
)
1857 txt
(match-string 3 line
)
1859 (or (and org-export-mark-todo-in-toc
1861 (not (member (match-string 2 line
)
1862 org-done-keywords
)))
1864 (and org-export-mark-todo-in-toc
1866 (org-search-todo-below
1867 line lines level
))))
1868 (setq txt
(org-html-expand-for-ascii txt
))
1870 (while (string-match org-bracket-link-regexp txt
)
1873 (match-string (if (match-end 2) 3 1) txt
)
1876 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1878 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1880 (setq txt
(replace-match "" t t txt
)))
1881 (if (string-match quote-re0 txt
)
1882 (setq txt
(replace-match "" t t txt
)))
1884 (if org-export-with-section-numbers
1885 (setq txt
(concat (org-section-number level
)
1887 (if (<= level umax-toc
)
1892 (* (max 0 (- level org-min-level
)) 4) ?\
)
1893 (format (if todo
"%s (*)\n" "%s\n") txt
))
1895 (setq org-last-level level
))
1898 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1900 (org-init-section-numbers)
1901 (while (setq line
(pop lines
))
1902 ;; Remove the quoted HTML tags.
1903 (setq line
(org-html-expand-for-ascii line
))
1905 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1906 (setq line
(replace-match "" t t line
)))
1907 ;; Replace internal links
1908 (while (string-match org-bracket-link-regexp line
)
1909 (setq line
(replace-match
1910 (if (match-end 3) "[\\3]" "[\\1]")
1913 (setq line
(org-translate-time line
)))
1915 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1917 (setq first-heading-pos
(or first-heading-pos
(point)))
1918 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1919 txt
(match-string 2 line
))
1920 (org-ascii-level-start level txt umax lines
))
1922 ((and org-export-with-tables
1923 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1924 (if (not table-open
)
1926 (setq table-open t table-buffer nil
))
1928 (setq table-buffer
(cons line table-buffer
))
1929 (when (or (not lines
)
1930 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1932 (setq table-open nil
1933 table-buffer
(nreverse table-buffer
))
1936 (org-fix-indentation x org-ascii-current-indentation
))
1937 (org-format-table-ascii table-buffer
)
1940 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1941 (if (and org-export-with-fixed-width
1942 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1943 (setq line
(replace-match "\\1" nil nil line
)))
1944 (insert line
"\n"))))
1948 ;; insert the table of contents
1950 (goto-char (point-min))
1951 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1953 (goto-char (match-beginning 0))
1955 (goto-char first-heading-pos
))
1956 (mapc 'insert thetoc
)
1957 (or (looking-at "[ \t]*\n[ \t]*\n")
1960 ;; Convert whitespace place holders
1961 (goto-char (point-min))
1963 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1964 (setq end
(next-single-property-change beg
'org-whitespace
))
1966 (delete-region beg end
)
1967 (insert (make-string (- end beg
) ?\
))))
1970 ;; remove display and invisible chars
1972 (goto-char (point-min))
1973 (while (setq beg
(next-single-property-change (point) 'display
))
1974 (setq end
(next-single-property-change beg
'display
))
1975 (delete-region beg end
)
1978 (goto-char (point-min))
1979 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1980 (setq end
(next-single-property-change beg
'org-cwidth
))
1981 (delete-region beg end
)
1983 (goto-char (point-min))))
1985 (defun org-export-ascii-clean-string ()
1986 "Do extra work for ASCII export"
1987 (goto-char (point-min))
1988 (while (re-search-forward org-verbatim-re nil t
)
1989 (goto-char (match-end 2))
1990 (backward-delete-char 1) (insert "'")
1991 (goto-char (match-beginning 2))
1992 (delete-char 1) (insert "`")
1993 (goto-char (match-end 2))))
1995 (defun org-search-todo-below (line lines level
)
1996 "Search the subtree below LINE for any TODO entries."
1997 (let ((rest (cdr (memq line lines
)))
1998 (re org-todo-line-regexp
)
2001 (while (setq line
(pop rest
))
2002 (if (string-match re line
)
2004 (setq lv
(- (match-end 1) (match-beginning 1))
2005 todo
(and (match-beginning 2)
2006 (not (member (match-string 2 line
)
2007 org-done-keywords
))))
2009 (if (<= lv level
) (throw 'exit nil
))
2010 (if todo
(throw 'exit t
))))))))
2012 (defun org-html-expand-for-ascii (line)
2013 "Handle quoted HTML for ASCII export."
2014 (if org-export-html-expand
2015 (while (string-match "@<[^<>\n]*>" line
)
2016 ;; We just remove the tags for now.
2017 (setq line
(replace-match "" nil nil line
))))
2020 (defun org-insert-centered (s &optional underline
)
2021 "Insert the string S centered and underline it with character UNDERLINE."
2022 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2023 (insert (make-string ind ?\
) s
"\n")
2025 (insert (make-string ind ?\
)
2026 (make-string (string-width s
) underline
)
2029 (defun org-ascii-level-start (level title umax
&optional lines
)
2030 "Insert a new level in ASCII export."
2031 (let (char (n (- level umax
1)) (ind 0))
2034 (insert (make-string (* 2 n
) ?\
)
2035 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2036 org-export-ascii-bullets
))
2038 ;; find the indentation of the next non-empty line
2041 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2042 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2043 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2045 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2046 (if (or (not (equal (char-before) ?
\n))
2047 (not (equal (char-before (1- (point))) ?
\n)))
2049 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2050 (unless org-export-with-tags
2051 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2052 (setq title
(replace-match "" t t title
))))
2053 (if org-export-with-section-numbers
2054 (setq title
(concat (org-section-number level
) " " title
)))
2055 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2056 (setq org-ascii-current-indentation
'(0 .
0)))))
2059 (defun org-export-visible (type arg
)
2060 "Create a copy of the visible part of the current buffer, and export it.
2061 The copy is created in a temporary buffer and removed after use.
2062 TYPE is the final key (as a string) that also select the export command in
2063 the `C-c C-e' export dispatcher.
2064 As a special case, if the you type SPC at the prompt, the temporary
2065 org-mode file will not be removed but presented to you so that you can
2066 continue to use it. The prefix arg ARG is passed through to the exporting
2070 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2071 (read-char-exclusive))
2072 current-prefix-arg
))
2073 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2074 (error "Invalid export key"))
2075 (let* ((binding (cdr (assoc type
2076 '((?a . org-export-as-ascii
)
2077 (?\C-a . org-export-as-ascii
)
2078 (?b . org-export-as-html-and-open
)
2079 (?\C-b . org-export-as-html-and-open
)
2080 (?h . org-export-as-html
)
2081 (?H . org-export-as-html-to-buffer
)
2082 (?R . org-export-region-as-html
)
2083 (?x . org-export-as-xoxo
)))))
2084 (keepp (equal type ?\
))
2085 (file buffer-file-name
)
2086 (buffer (get-buffer-create "*Org Export Visible*"))
2088 ;; Need to hack the drawers here.
2090 (goto-char (point-min))
2091 (while (re-search-forward org-drawer-regexp nil t
)
2092 (goto-char (match-beginning 1))
2093 (or (org-invisible-p) (org-flag-drawer nil
))))
2094 (with-current-buffer buffer
(erase-buffer))
2096 (setq s
(goto-char (point-min)))
2097 (while (not (= (point) (point-max)))
2098 (goto-char (org-find-invisible))
2099 (append-to-buffer buffer s
(point))
2100 (setq s
(goto-char (org-find-visible))))
2101 (org-cycle-hide-drawers 'all
)
2102 (goto-char (point-min))
2104 ;; Copy all comment lines to the end, to make sure #+ settings are
2105 ;; still available for the second export step. Kind of a hack, but
2106 ;; does do the trick.
2107 (if (looking-at "#[^\r\n]*")
2108 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2109 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2110 (append-to-buffer buffer
(1+ (match-beginning 0))
2111 (min (point-max) (1+ (match-end 0))))))
2113 (let ((buffer-file-name file
)
2114 (org-inhibit-startup t
))
2117 (unless keepp
(funcall binding arg
))))
2119 (kill-buffer buffer
)
2120 (switch-to-buffer-other-window buffer
)
2121 (goto-char (point-min)))))
2123 (defun org-find-visible ()
2125 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2126 (get-char-property s
'invisible
)))
2128 (defun org-find-invisible ()
2130 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2131 (not (get-char-property s
'invisible
))))
2136 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2137 (defun org-get-current-options ()
2138 "Return a string with current options as keyword options.
2139 Does include HTML export options as well as TODO and CATEGORY stuff."
2140 (require 'org-archive
)
2147 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2148 #+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
2155 #+PRIORITIES: %c %c %c
2157 #+STARTUP: %s %s %s %s %s
2162 (buffer-name) (user-full-name) user-mail-address
2163 (format-time-string (car org-time-stamp-formats
))
2164 org-export-default-language
2165 org-export-headline-levels
2166 org-export-with-section-numbers
2168 org-export-preserve-breaks
2169 org-export-html-expand
2170 org-export-with-fixed-width
2171 org-export-with-tables
2172 org-export-with-sub-superscripts
2173 org-export-with-special-strings
2174 org-export-with-footnotes
2175 org-export-with-emphasize
2176 org-export-with-TeX-macros
2177 org-export-with-LaTeX-fragments
2178 org-export-skip-text-before-1st-heading
2179 org-export-with-drawers
2180 org-export-with-tags
2181 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2182 org-export-html-link-up
2183 org-export-html-link-home
2184 (file-name-nondirectory buffer-file-name
)
2185 "TODO FEEDBACK VERIFY DONE"
2186 "Me Jason Marie DONE"
2187 org-highest-priority org-lowest-priority org-default-priority
2188 (mapconcat 'identity org-drawers
" ")
2189 (cdr (assoc org-startup-folded
2190 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2191 (if org-odd-levels-only
"odd" "oddeven")
2192 (if org-hide-leading-stars
"hidestars" "showstars")
2193 (if org-startup-align-all-tables
"align" "noalign")
2194 (cond ((eq org-log-done t
) "logdone")
2195 ((equal org-log-done
'note
) "lognotedone")
2196 ((not org-log-done
) "nologdone"))
2197 (or (mapconcat (lambda (x)
2199 ((equal '(:startgroup
) x
) "{")
2200 ((equal '(:endgroup
) x
) "}")
2201 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2203 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2204 org-archive-location
2205 "org file:~/org/%s.org"
2209 (defun org-insert-export-options-template ()
2210 "Insert into the buffer a template with information for exporting."
2212 (if (not (bolp)) (newline))
2213 (let ((s (org-get-current-options)))
2214 (and (string-match "#\\+CATEGORY" s
)
2215 (setq s
(substring s
0 (match-beginning 0))))
2219 (defun org-export-as-html-and-open (arg)
2220 "Export the outline as HTML and immediately open it with a browser.
2221 If there is an active region, export only the region.
2222 The prefix ARG specifies how many levels of the outline should become
2223 headlines. The default is 3. Lower levels will become bulleted lists."
2225 (org-export-as-html arg
'hidden
)
2226 (org-open-file buffer-file-name
))
2229 (defun org-export-as-html-batch ()
2230 "Call `org-export-as-html', may be used in batch processing as
2232 --load=$HOME/lib/emacs/org.el
2233 --eval \"(setq org-export-headline-levels 2)\"
2234 --visit=MyFile --funcall org-export-as-html-batch"
2235 (org-export-as-html org-export-headline-levels
'hidden
))
2238 (defun org-export-as-html-to-buffer (arg)
2239 "Call `org-exort-as-html` with output to a temporary buffer.
2240 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2242 (org-export-as-html arg nil nil
"*Org HTML Export*")
2243 (switch-to-buffer-other-window "*Org HTML Export*"))
2246 (defun org-replace-region-by-html (beg end
)
2247 "Assume the current region has org-mode syntax, and convert it to HTML.
2248 This can be used in any buffer. For example, you could write an
2249 itemized list in org-mode syntax in an HTML buffer and then use this
2250 command to convert it."
2252 (let (reg html buf pop-up-frames
)
2253 (save-window-excursion
2255 (setq html
(org-export-region-as-html
2257 (setq reg
(buffer-substring beg end
)
2258 buf
(get-buffer-create "*Org tmp*"))
2259 (with-current-buffer buf
2263 (setq html
(org-export-region-as-html
2264 (point-min) (point-max) t
'string
)))
2266 (delete-region beg end
)
2270 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2271 "Convert region from BEG to END in org-mode buffer to HTML.
2272 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2273 contents, and only produce the region of converted text, useful for
2274 cut-and-paste operations.
2275 If BUFFER is a buffer or a string, use/create that buffer as a target
2276 of the converted HTML. If BUFFER is the symbol `string', return the
2277 produced HTML as a string and leave not buffer behind. For example,
2278 a Lisp program could call this function in the following way:
2280 (setq html (org-export-region-as-html beg end t 'string))
2282 When called interactively, the output buffer is selected, and shown
2283 in a window. A non-interactive call will only return the buffer."
2284 (interactive "r\nP")
2285 (when (interactive-p)
2286 (setq buffer
"*Org HTML Export*"))
2287 (let ((transient-mark-mode t
) (zmacs-regions t
)
2290 (set-mark (point)) ;; to activate the region
2292 (setq rtn
(org-export-as-html
2295 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2296 (if (and (interactive-p) (bufferp rtn
))
2297 (switch-to-buffer-other-window rtn
)
2300 (defvar html-table-tag nil
) ; dynamically scoped into this.
2302 (defun org-export-as-html (arg &optional hidden ext-plist
2303 to-buffer body-only pub-dir
)
2304 "Export the outline as a pretty HTML file.
2305 If there is an active region, export only the region. The prefix
2306 ARG specifies how many levels of the outline should become
2307 headlines. The default is 3. Lower levels will become bulleted
2308 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2309 EXT-PLIST is a property list with external parameters overriding
2310 org-mode's default settings, but still inferior to file-local
2311 settings. When TO-BUFFER is non-nil, create a buffer with that
2312 name and export to that buffer. If TO-BUFFER is the symbol
2313 `string', don't leave any buffer behind but just return the
2314 resulting HTML as a string. When BODY-ONLY is set, don't produce
2315 the file header and footer, simply return the content of
2316 <body>...</body>, without even the body tags themselves. When
2317 PUB-DIR is set, use this as the publishing directory."
2320 ;; Make sure we have a file name when we need it.
2321 (when (and (not (or to-buffer body-only
))
2322 (not buffer-file-name
))
2323 (if (buffer-base-buffer)
2324 (org-set-local 'buffer-file-name
2325 (with-current-buffer (buffer-base-buffer)
2327 (error "Need a file name to be able to export.")))
2329 (message "Exporting...")
2330 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2331 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2332 (setq-default org-done-keywords org-done-keywords
)
2333 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2335 (org-export-process-option-filters
2336 (org-combine-plists (org-default-export-plist)
2338 (org-infile-export-plist))))
2340 (style (plist-get opt-plist
:style
))
2341 (html-extension (plist-get opt-plist
:html-extension
))
2342 (link-validate (plist-get opt-plist
:link-validation-function
))
2343 valid thetoc have-headings first-heading-pos
2344 (odd org-odd-levels-only
)
2345 (region-p (org-region-active-p))
2349 (goto-char (region-beginning))
2350 (and (org-at-heading-p)
2351 (>= (org-end-of-subtree t t
) (region-end))))))
2352 ;; The following two are dynamically scoped into other
2354 (org-current-export-dir
2355 (or pub-dir
(org-export-directory :html opt-plist
)))
2356 (org-current-export-file buffer-file-name
)
2357 (level 0) (line "") (origline "") txt todo
2360 (filename (if to-buffer nil
2363 (file-name-sans-extension
2365 (org-entry-get (region-beginning)
2366 "EXPORT_FILE_NAME" t
))
2367 (file-name-nondirectory buffer-file-name
)))
2369 (file-name-as-directory
2370 (or pub-dir
(org-export-directory :html opt-plist
))))))
2371 (current-dir (if buffer-file-name
2372 (file-name-directory buffer-file-name
)
2374 (buffer (if to-buffer
2376 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2377 (t (get-buffer-create to-buffer
)))
2378 (find-file-noselect filename
)))
2379 (org-levels-open (make-vector org-level-max nil
))
2380 (date (plist-get opt-plist
:date
))
2381 (author (plist-get opt-plist
:author
))
2382 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2383 (plist-get opt-plist
:title
)
2385 (plist-get opt-plist
:skip-before-1st-heading
))
2386 (org-export-grab-title-from-buffer))
2387 (and buffer-file-name
2388 (file-name-sans-extension
2389 (file-name-nondirectory buffer-file-name
)))
2391 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2392 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2393 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2397 (local-list-type nil
)
2398 (local-list-indent nil
)
2399 (llt org-plain-list-ordered-item-terminator
)
2400 (email (plist-get opt-plist
:email
))
2401 (language (plist-get opt-plist
:language
))
2405 (coding-system (and (boundp 'buffer-file-coding-system
)
2406 buffer-file-coding-system
))
2407 (coding-system-for-write (or org-export-html-coding-system
2409 (save-buffer-coding-system (or org-export-html-coding-system
2411 (charset (and coding-system-for-write
2412 (fboundp 'coding-system-get
)
2413 (coding-system-get coding-system-for-write
2417 (if region-p
(region-beginning) (point-min))
2418 (if region-p
(region-end) (point-max))))
2421 (org-export-preprocess-string
2425 :skip-before-1st-heading
2426 (plist-get opt-plist
:skip-before-1st-heading
)
2427 :drawers
(plist-get opt-plist
:drawers
)
2429 (plist-get opt-plist
:archived-trees
)
2431 (plist-get opt-plist
:text
)
2433 (plist-get opt-plist
:LaTeX-fragments
))
2436 table-buffer table-orig-buffer
2437 ind item-type starter didclose
2438 rpl path desc descp desc1 desc2 link
2439 snumber fnc item-tag
2442 (let ((inhibit-read-only t
))
2444 (remove-text-properties (point-min) (point-max)
2445 '(:org-license-to-kill t
))))
2447 (message "Exporting...")
2449 (setq org-min-level
(org-get-min-level lines
))
2450 (setq org-last-level org-min-level
)
2451 (org-init-section-numbers)
2454 ((and date
(string-match "%" date
))
2455 (setq date
(format-time-string date
)))
2457 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2459 ;; Get the language-dependent settings
2460 (setq lang-words
(or (assoc language org-export-language-setup
)
2461 (assoc "en" org-export-language-setup
)))
2463 ;; Switch to the output buffer
2465 (let ((inhibit-read-only t
)) (erase-buffer))
2468 (and (fboundp 'set-buffer-file-coding-system
)
2469 (set-buffer-file-coding-system coding-system-for-write
))
2471 (let ((case-fold-search nil
)
2472 (org-odd-levels-only odd
))
2473 ;; create local variables for all options, to make sure all called
2474 ;; functions get the correct information
2476 (set (make-local-variable (cdr x
))
2477 (plist-get opt-plist
(car x
))))
2478 org-export-plist-vars
)
2479 (setq umax
(if arg
(prefix-numeric-value arg
)
2480 org-export-headline-levels
))
2481 (setq umax-toc
(if (integerp org-export-with-toc
)
2482 (min org-export-with-toc umax
)
2487 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2488 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2489 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2490 lang=\"%s\" xml:lang=\"%s\">
2493 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2494 <meta name=\"generator\" content=\"Org-mode\"/>
2495 <meta name=\"generated\" content=\"%s\"/>
2496 <meta name=\"author\" content=\"%s\"/>
2500 language language
(org-html-expand title
)
2501 (or charset
"iso-8859-1") date author style
))
2503 (insert (or (plist-get opt-plist
:preamble
) ""))
2505 (when (plist-get opt-plist
:auto-preamble
)
2506 (if title
(insert (format org-export-html-title-format
2507 (org-html-expand title
))))))
2509 (if (and org-export-with-toc
(not body-only
))
2511 (push (format "<h%d>%s</h%d>\n"
2512 org-export-html-toplevel-hlevel
2514 org-export-html-toplevel-hlevel
)
2516 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2517 (push "<ul>\n<li>" thetoc
)
2519 (mapcar '(lambda (line)
2520 (if (string-match org-todo-line-regexp line
)
2521 ;; This is a headline
2523 (setq have-headings t
)
2524 (setq level
(- (match-end 1) (match-beginning 1))
2525 level
(org-tr-level level
)
2526 txt
(save-match-data
2528 (org-export-cleanup-toc-line
2529 (match-string 3 line
))))
2531 (or (and org-export-mark-todo-in-toc
2533 (not (member (match-string 2 line
)
2534 org-done-keywords
)))
2536 (and org-export-mark-todo-in-toc
2538 (org-search-todo-below
2539 line lines level
))))
2541 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2542 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2543 (if (string-match quote-re0 txt
)
2544 (setq txt
(replace-match "" t t txt
)))
2545 (setq snumber
(org-section-number level
))
2546 (if org-export-with-section-numbers
2547 (setq txt
(concat snumber
" " txt
)))
2548 (if (<= level
(max umax umax-toc
))
2549 (setq head-count
(+ head-count
1)))
2550 (if (<= level umax-toc
)
2552 (if (> level org-last-level
)
2554 (setq cnt
(- level org-last-level
))
2555 (while (>= (setq cnt
(1- cnt
)) 0)
2556 (push "\n<ul>\n<li>" thetoc
))
2557 (push "\n" thetoc
)))
2558 (if (< level org-last-level
)
2560 (setq cnt
(- org-last-level level
))
2561 (while (>= (setq cnt
(1- cnt
)) 0)
2562 (push "</li>\n</ul>" thetoc
))
2563 (push "\n" thetoc
)))
2564 ;; Check for targets
2565 (while (string-match org-any-target-regexp line
)
2566 (setq line
(replace-match
2567 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2569 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2570 (setq txt
(replace-match "" t t txt
)))
2574 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2575 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2576 snumber txt
) thetoc
)
2578 (setq org-last-level level
))
2582 (while (> org-last-level
(1- org-min-level
))
2583 (setq org-last-level
(1- org-last-level
))
2584 (push "</li>\n</ul>\n" thetoc
))
2585 (push "</div>\n" thetoc
)
2586 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2589 (org-init-section-numbers)
2591 (while (setq line
(pop lines
) origline line
)
2594 ;; end of quote section?
2595 (when (and inquote
(string-match "^\\*+ " line
))
2598 ;; inside a quote section?
2600 (insert (org-html-protect line
) "\n")
2601 (throw 'nextline nil
))
2604 (when (and org-export-with-fixed-width
2605 (string-match "^[ \t]*:\\(.*\\)" line
))
2609 (insert (org-html-protect (match-string 1 line
)) "\n")
2611 (not (string-match "^[ \t]*\\(:.*\\)"
2614 (insert "</pre>\n"))
2615 (throw 'nextline nil
))
2618 (when (get-text-property 0 'org-protected line
)
2620 (when (re-search-backward
2621 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2622 (setq par
(match-string 1))
2623 (replace-match "\\2\n"))
2626 (not (string-match "^[ \t]*:" (car lines
)))
2627 (or (= (length (car lines
)) 0)
2628 (get-text-property 0 'org-protected
(car lines
))))
2629 (insert (pop lines
) "\n"))
2630 (and par
(insert "<p>\n")))
2631 (throw 'nextline nil
))
2634 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2635 (insert "\n<hr/>\n")
2636 (throw 'nextline nil
))
2638 ;; Blockquotes and verse
2639 (when (equal "ORG-BLOCKQUOTE-START" line
)
2640 (insert "<blockquote>\n<p>\n")
2641 (throw 'nextline nil
))
2642 (when (equal "ORG-BLOCKQUOTE-END" line
)
2643 (insert "</p>\n</blockquote>\n")
2644 (throw 'nextline nil
))
2645 (when (equal "ORG-VERSE-START" line
)
2646 (insert "<verse>\n<p>\n")
2647 (throw 'nextline nil
))
2648 (when (equal "ORG-VERSE-END" line
)
2649 (insert "</p>\n</verse>\n")
2650 (throw 'nextline nil
))
2652 ;; make targets to anchors
2653 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2656 (setq line
(replace-match
2657 (concat "@<a name=\""
2658 (org-solidify-link-text (match-string 1 line
))
2661 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2662 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2663 (setq line
(replace-match
2664 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2665 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2668 (setq line
(replace-match
2669 (concat "@<a name=\""
2670 (org-solidify-link-text (match-string 1 line
))
2671 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2674 (setq line
(org-html-handle-time-stamps line
))
2676 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2677 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2678 ;; Also handle sub_superscripts and checkboxes
2679 (or (string-match org-table-hline-regexp line
)
2680 (setq line
(org-html-expand line
)))
2684 (while (string-match org-bracket-link-analytic-regexp line start
)
2685 (setq start
(match-beginning 0))
2686 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2687 (setq path
(match-string 3 line
))
2688 (setq desc1
(if (match-end 5) (match-string 5 line
))
2689 desc2
(if (match-end 2) (concat type
":" path
) path
)
2690 descp
(and desc1
(not (equal desc1 desc2
)))
2691 desc
(or desc1 desc2
))
2692 ;; Make an image out of the description if that is so wanted
2693 (when (and descp
(org-file-image-p desc
))
2695 (if (string-match "^file:" desc
)
2696 (setq desc
(substring desc
(match-end 0)))))
2697 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2698 ;; FIXME: do we need to unescape here somewhere?
2700 ((equal type
"internal")
2704 (org-solidify-link-text
2705 (save-match-data (org-link-unescape path
)) nil
)
2706 "\">" desc
"</a>")))
2707 ((member type
'("http" "https"))
2708 ;; standard URL, just check if we need to inline an image
2709 (if (and (or (eq t org-export-html-inline-images
)
2710 (and org-export-html-inline-images
(not descp
)))
2711 (org-file-image-p path
))
2712 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2713 (setq link
(concat type
":" path
))
2714 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2715 ((member type
'("ftp" "mailto" "news"))
2717 (setq link
(concat type
":" path
))
2718 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2719 ((string= type
"file")
2721 (let* ((filename path
)
2722 (abs-p (file-name-absolute-p filename
))
2723 thefile file-is-image-p search
)
2725 (if (string-match "::\\(.*\\)" filename
)
2726 (setq search
(match-string 1 filename
)
2727 filename
(replace-match "" t nil filename
)))
2729 (if (functionp link-validate
)
2730 (funcall link-validate filename current-dir
)
2732 (setq file-is-image-p
(org-file-image-p filename
))
2733 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2734 (when (and org-export-html-link-org-files-as-html
2735 (string-match "\\.org$" thefile
))
2736 (setq thefile
(concat (substring thefile
0
2737 (match-beginning 0))
2738 "." html-extension
))
2740 ;; make sure this is can be used as target search
2741 (not (string-match "^[0-9]*$" search
))
2742 (not (string-match "^\\*" search
))
2743 (not (string-match "^/.*/$" search
)))
2744 (setq thefile
(concat thefile
"#"
2745 (org-solidify-link-text
2746 (org-link-unescape search
)))))
2747 (when (string-match "^file:" desc
)
2748 (setq desc
(replace-match "" t t desc
))
2749 (if (string-match "\\.org$" desc
)
2750 (setq desc
(replace-match "" t t desc
))))))
2751 (setq rpl
(if (and file-is-image-p
2752 (or (eq t org-export-html-inline-images
)
2753 (and org-export-html-inline-images
2755 (concat "<img src=\"" thefile
"\"/>")
2756 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2757 (if (not valid
) (setq rpl desc
))))
2759 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2762 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2765 ;; just publish the path, as default
2766 (setq rpl
(concat "<i><" type
":"
2767 (save-match-data (org-link-unescape path
))
2769 (setq line
(replace-match rpl t t line
)
2770 start
(+ start
(length rpl
))))
2773 (if (and (string-match org-todo-line-regexp line
)
2774 (match-beginning 2))
2777 (concat (substring line
0 (match-beginning 2))
2779 (if (member (match-string 2 line
)
2782 "\">" (match-string 2 line
)
2783 "</span>" (substring line
(match-end 2)))))
2785 ;; Does this contain a reference to a footnote?
2786 (when org-export-with-footnotes
2788 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2789 (if (get-text-property (match-beginning 2) 'org-protected line
)
2790 (setq start
(match-end 2))
2791 (let ((n (match-string 2 line
)))
2795 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2796 (match-string 1 line
) n n n
)
2800 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2801 ;; This is a headline
2802 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2803 txt
(match-string 2 line
))
2804 (if (string-match quote-re0 txt
)
2805 (setq txt
(replace-match "" t t txt
)))
2806 (if (<= level
(max umax umax-toc
))
2807 (setq head-count
(+ head-count
1)))
2809 ;; Close any local lists before inserting a new header line
2810 (while local-list-type
2811 (org-close-li (car local-list-type
))
2812 (insert (format "</%sl>\n" (car local-list-type
)))
2813 (pop local-list-type
))
2814 (setq local-list-indent nil
2816 (setq first-heading-pos
(or first-heading-pos
(point)))
2817 (org-html-level-start level txt umax
2818 (and org-export-with-toc
(<= level umax
))
2821 (when (string-match quote-re line
)
2825 ((and org-export-with-tables
2826 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2827 (if (not table-open
)
2829 (setq table-open t table-buffer nil table-orig-buffer nil
))
2831 (setq table-buffer
(cons line table-buffer
)
2832 table-orig-buffer
(cons origline table-orig-buffer
))
2833 (when (or (not lines
)
2834 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2836 (setq table-open nil
2837 table-buffer
(nreverse table-buffer
)
2838 table-orig-buffer
(nreverse table-orig-buffer
))
2839 (org-close-par-maybe)
2840 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2845 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2846 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2847 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2848 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2850 (setq ind
(org-get-string-indentation line
)
2851 item-type
(if (match-beginning 4) "o" "u")
2852 starter
(if (match-beginning 2)
2853 (substring (match-string 2 line
) 0 -
1))
2854 line
(substring line
(match-beginning 5))
2856 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2858 item-tag
(match-string 1 line
)
2859 line
(substring line
(match-end 0))))
2860 (when (and (not (equal item-type
"d"))
2861 (not (string-match "[^ \t]" line
)))
2862 ;; empty line. Pretend indentation is large.
2863 (setq ind
(if org-empty-line-terminates-plain-lists
2865 (1+ (or (car local-list-indent
) 1)))))
2867 (while (and in-local-list
2868 (or (and (= ind
(car local-list-indent
))
2870 (< ind
(car local-list-indent
))))
2872 (org-close-li (car local-list-type
))
2873 (insert (format "</%sl>\n" (car local-list-type
)))
2874 (pop local-list-type
) (pop local-list-indent
)
2875 (setq in-local-list local-list-indent
))
2878 (or (not in-local-list
)
2879 (> ind
(car local-list-indent
))))
2880 ;; Start new (level of) list
2881 (org-close-par-maybe)
2883 ((equal item-type
"u") "<ul>\n<li>\n")
2884 ((equal item-type
"o") "<ol>\n<li>\n")
2885 ((equal item-type
"d")
2886 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2887 (push item-type local-list-type
)
2888 (push ind local-list-indent
)
2889 (setq in-local-list t
))
2891 ;; continue current list
2892 (org-close-li (car local-list-type
))
2894 ((equal (car local-list-type
) "d")
2895 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2898 ;; we did close a list, normal text follows: need <p>
2900 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2903 (if (equal (match-string 1 line
) "X")
2905 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2908 ;; Empty lines start a new paragraph. If hand-formatted lists
2909 ;; are not fully interpreted, lines starting with "-", "+", "*"
2910 ;; also start a new paragraph.
2911 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2913 ;; Is this the start of a footnote?
2914 (when org-export-with-footnotes
2915 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2916 (org-close-par-maybe)
2917 (let ((n (match-string 1 line
)))
2918 (setq line
(replace-match
2919 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2921 ;; Check if the line break needs to be conserved
2923 ((string-match "\\\\\\\\[ \t]*$" line
)
2924 (setq line
(replace-match "<br/>" t t line
)))
2925 (org-export-preserve-breaks
2926 (setq line
(concat line
"<br/>"))))
2928 (insert line
"\n")))))
2930 ;; Properly close all local lists and other lists
2931 (when inquote
(insert "</pre>\n"))
2933 ;; Close any local lists before inserting a new header line
2934 (while local-list-type
2935 (org-close-li (car local-list-type
))
2936 (insert (format "</%sl>\n" (car local-list-type
)))
2937 (pop local-list-type
))
2938 (setq local-list-indent nil
2940 (org-html-level-start 1 nil umax
2941 (and org-export-with-toc
(<= level umax
))
2943 ;; the </div> to lose the last text-... div.
2947 (when (plist-get opt-plist
:auto-postamble
)
2948 (insert "<div id=\"postamble\">")
2949 (when (and org-export-author-info author
)
2950 (insert "<p class=\"author\"> "
2951 (nth 1 lang-words
) ": " author
"\n")
2953 (if (listp (split-string email
",+ *"))
2955 (insert "<a href=\"mailto:" e
"\"><"
2957 (split-string email
",+ *"))
2958 (insert "<a href=\"mailto:" email
"\"><"
2959 email
"></a>\n")))
2961 (when (and date org-export-time-stamp-file
)
2962 (insert "<p class=\"date\"> "
2963 (nth 2 lang-words
) ": "
2967 (if org-export-html-with-timestamp
2968 (insert org-export-html-html-helper-timestamp
))
2969 (insert (or (plist-get opt-plist
:postamble
) ""))
2970 (insert "</body>\n</html>\n"))
2973 (if (eq major-mode default-major-mode
) (html-mode))
2975 ;; insert the table of contents
2976 (goto-char (point-min))
2978 (if (or (re-search-forward
2979 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2981 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2983 (goto-char (match-beginning 0))
2985 (goto-char first-heading-pos
)
2986 (when (looking-at "\\s-*</p>")
2987 (goto-char (match-end 0))
2989 (insert "<div id=\"table-of-contents\">\n")
2990 (mapc 'insert thetoc
)
2991 (insert "</div>\n"))
2992 ;; remove empty paragraphs and lists
2993 (goto-char (point-min))
2994 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2996 (goto-char (point-min))
2997 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2999 (goto-char (point-min))
3000 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3002 ;; Convert whitespace place holders
3003 (goto-char (point-min))
3005 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3006 (setq n
(get-text-property beg
'org-whitespace
)
3007 end
(next-single-property-change beg
'org-whitespace
))
3009 (delete-region beg end
)
3010 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3011 (make-string n ?x
)))))
3012 (or to-buffer
(save-buffer))
3013 (goto-char (point-min))
3014 (message "Exporting... done")
3015 (if (eq to-buffer
'string
)
3016 (prog1 (buffer-substring (point-min) (point-max))
3017 (kill-buffer (current-buffer)))
3018 (current-buffer)))))
3020 (defvar org-table-colgroup-info nil
)
3021 (defun org-format-table-ascii (lines)
3022 "Format a table for ascii export."
3024 (setq lines
(org-split-string lines
"\n")))
3025 (if (not (string-match "^[ \t]*|" (car lines
)))
3026 ;; Table made by table.el - test for spanning
3029 ;; A normal org table
3030 ;; Get rid of hlines at beginning and end
3031 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3032 (setq lines
(nreverse lines
))
3033 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3034 (setq lines
(nreverse lines
))
3035 (when org-export-table-remove-special-lines
3036 ;; Check if the table has a marking column. If yes remove the
3037 ;; column and the special lines
3038 (setq lines
(org-table-clean-before-export lines
)))
3039 ;; Get rid of the vertical lines except for grouping
3040 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3042 (while (setq line
(pop lines
))
3043 (if (string-match org-table-hline-regexp line
)
3044 (and (string-match "|\\(.*\\)|" line
)
3045 (setq line
(replace-match " \\1" t nil line
)))
3046 (setq start
0 vl1 vl
)
3047 (while (string-match "|" line start
)
3048 (setq start
(match-end 0))
3049 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3053 (defun org-colgroup-info-to-vline-list (info)
3056 (setq last new new
(pop info
))
3057 (if (or (memq last
'(:end
:startend
))
3058 (memq new
'(:start
:startend
)))
3061 (setq vl
(nreverse vl
))
3062 (and vl
(setcar vl nil
))
3065 (defvar org-table-number-regexp
) ; defined in org-table.el
3066 (defun org-format-table-html (lines olines
)
3067 "Find out which HTML converter to use and return the HTML code."
3069 (setq lines
(org-split-string lines
"\n")))
3070 (if (string-match "^[ \t]*|" (car lines
))
3071 ;; A normal org table
3072 (org-format-org-table-html lines
)
3073 ;; Table made by table.el - test for spanning
3074 (let* ((hlines (delq nil
(mapcar
3076 (if (string-match "^[ \t]*\\+-" x
) x
3079 (first (car hlines
))
3080 (ll (and (string-match "\\S-+" first
)
3081 (match-string 0 first
)))
3082 (re (concat "^[ \t]*" (regexp-quote ll
)))
3083 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3085 (if (and (not spanning
)
3086 (not org-export-prefer-native-exporter-for-tables
))
3087 ;; We can use my own converter with HTML conversions
3088 (org-format-table-table-html lines
)
3089 ;; Need to use the code generator in table.el, with the original text.
3090 (org-format-table-table-html-using-table-generate-source olines
)))))
3092 (defvar org-table-number-fraction
) ; defined in org-table.el
3093 (defun org-format-org-table-html (lines &optional splice
)
3094 "Format a table into HTML."
3095 (require 'org-table
)
3096 ;; Get rid of hlines at beginning and end
3097 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3098 (setq lines
(nreverse lines
))
3099 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3100 (setq lines
(nreverse lines
))
3101 (when org-export-table-remove-special-lines
3102 ;; Check if the table has a marking column. If yes remove the
3103 ;; column and the special lines
3104 (setq lines
(org-table-clean-before-export lines
)))
3106 (let ((head (and org-export-highlight-first-table-line
3108 (lambda (x) (string-match "^[ \t]*|-" x
))
3111 tbopen line fields html gr colgropen
)
3112 (if splice
(setq head nil
))
3113 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3115 (while (setq line
(pop lines
))
3117 (if (string-match "^[ \t]*|-" line
)
3120 (push (if head
"</thead>" "</tbody>") html
)
3121 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3122 (setq head nil
) ;; head ends here, first time around
3124 (throw 'next-line t
)))
3125 ;; Break the line into fields
3126 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3127 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3128 (setq nlines
(1+ nlines
) i -
1)
3129 (push (concat "<tr>"
3133 (if (and (< i nlines
)
3134 (string-match org-table-number-regexp x
))
3135 (incf (aref fnum i
)))
3137 (concat (car org-export-table-header-tags
) x
3138 (cdr org-export-table-header-tags
))
3139 (concat (car org-export-table-data-tags
) x
3140 (cdr org-export-table-data-tags
))))
3144 (unless splice
(if tbopen
(push "</tbody>" html
)))
3145 (unless splice
(push "</table>\n" html
))
3146 (setq html
(nreverse html
))
3148 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3151 (setq gr
(pop org-table-colgroup-info
))
3152 (format "%s<col align=\"%s\"></col>%s"
3153 (if (memq gr
'(:start
:startend
))
3155 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3158 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3160 (if (memq gr
'(:end
:startend
))
3161 (progn (setq colgropen nil
) "</colgroup>")
3165 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3166 (push html-table-tag html
))
3167 (concat (mapconcat 'identity html
"\n") "\n")))
3169 (defun org-table-clean-before-export (lines)
3170 "Check if the table has a marking column.
3171 If yes remove the column and the special lines."
3172 (setq org-table-colgroup-info nil
)
3175 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3176 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3179 (setq org-table-clean-did-remove-column nil
)
3184 ((string-match "^[ \t]*| */ *|" x
)
3185 (setq org-table-colgroup-info
3187 (cond ((member x
'("<" "<")) :start
)
3188 ((member x
'(">" ">")) :end
)
3189 ((member x
'("<>" "<>")) :startend
)
3191 (org-split-string x
"[ \t]*|[ \t]*")))
3195 (setq org-table-clean-did-remove-column t
)
3200 ((string-match "^[ \t]*| */ *|" x
)
3201 (setq org-table-colgroup-info
3203 (cond ((member x
'("<" "<")) :start
)
3204 ((member x
'(">" ">")) :end
)
3205 ((member x
'("<>" "<>")) :startend
)
3207 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3209 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3210 nil
) ; ignore this line
3211 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3212 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3213 ;; remove the first column
3214 (replace-match "\\1|" t nil x
))))
3217 (defun org-format-table-table-html (lines)
3218 "Format a table generated by table.el into HTML.
3219 This conversion does *not* use `table-generate-source' from table.el.
3220 This has the advantage that Org-mode's HTML conversions can be used.
3221 But it has the disadvantage, that no cell- or row-spanning is allowed."
3222 (let (line field-buffer
3223 (head org-export-highlight-first-table-line
)
3225 (setq html
(concat html-table-tag
"\n"))
3226 (while (setq line
(pop lines
))
3227 (setq empty
" ")
3229 (if (string-match "^[ \t]*\\+-" line
)
3240 (if (equal x
"") (setq x empty
))
3242 (concat (car org-export-table-header-tags
) x
3243 (cdr org-export-table-header-tags
))
3244 (concat (car org-export-table-data-tags
) x
3245 (cdr org-export-table-data-tags
))))
3249 (setq field-buffer nil
)))
3251 (throw 'next-line t
)))
3252 ;; Break the line into fields and store the fields
3253 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3255 (setq field-buffer
(mapcar
3257 (concat x
"<br/>" (pop fields
)))
3259 (setq field-buffer fields
))))
3260 (setq html
(concat html
"</table>\n"))
3263 (defun org-format-table-table-html-using-table-generate-source (lines)
3264 "Format a table into html, using `table-generate-source' from table.el.
3265 This has the advantage that cell- or row-spanning is allowed.
3266 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3268 (with-current-buffer (get-buffer-create " org-tmp1 ")
3270 (insert (mapconcat 'identity lines
"\n"))
3271 (goto-char (point-min))
3272 (if (not (re-search-forward "|[^+]" nil t
))
3273 (error "Error processing table"))
3274 (table-recognize-table)
3275 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3276 (table-generate-source 'html
" org-tmp2 ")
3277 (set-buffer " org-tmp2 ")
3278 (buffer-substring (point-min) (point-max))))
3280 (defun org-html-handle-time-stamps (s)
3281 "Format time stamps in string S, or remove them."
3284 (while (string-match org-maybe-keyword-time-regexp s
)
3285 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3286 ;; never export CLOCK
3288 (or b
(setq b
(substring s
0 (match-beginning 0))))
3289 (if (not org-export-with-timestamps
)
3290 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3291 s
(substring s
(match-end 0)))
3293 r
(substring s
0 (match-beginning 0))
3295 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3296 (match-string 1 s
)))
3297 (format " @<span class=\"timestamp\">%s@</span>"
3299 (org-translate-time (match-string 3 s
)) 1 -
1)))
3300 s
(substring s
(match-end 0)))))
3301 ;; Line break if line started and ended with time stamp stuff
3304 (setq r
(concat r s
))
3305 (unless (string-match "\\S-" (concat b s
))
3306 (setq r
(concat r
"@<br/>")))
3309 (defun org-export-htmlize-region-for-paste (beg end
)
3310 "Convert the region to HTML, using htmlize.el.
3311 This is much like `htmlize-region-for-paste', only that it uses
3312 the settings define in the org-... variables."
3313 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3314 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3315 (htmlbuf (htmlize-region beg end
)))
3317 (with-current-buffer htmlbuf
3318 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3319 (plist-get htmlize-buffer-places
'content-end
)))
3320 (kill-buffer htmlbuf
))))
3323 (defun org-export-htmlize-generate-css ()
3324 "Create the CSS for all font definitions in the current Emacs session.
3325 Use this to create face definitions in your CSS style file that can then
3326 be used by code snippets transformed by htmlize.
3327 This command just produces a buffer that contains class definitions for all
3328 faces used in the current Emacs session. You can copy and paste the ones you
3329 need into your CSS file.
3331 If you then set `org-export-htmlize-output-type' to `css', calls to
3332 the function `org-export-htmlize-region-for-paste' will produce code
3333 that uses these same face definitions."
3336 (and (get-buffer "*html*") (kill-buffer "*html*"))
3338 (let ((fl (face-list))
3339 (htmlize-css-name-prefix "org-")
3340 (htmlize-output-type 'css
)
3342 (while (setq f
(pop fl
)
3343 i
(and f
(face-attribute f
:inherit
)))
3344 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3345 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3346 (htmlize-region (point-min) (point-max))))
3347 (switch-to-buffer "*html*")
3348 (goto-char (point-min))
3349 (if (re-search-forward "<style" nil t
)
3350 (delete-region (point-min) (match-beginning 0)))
3351 (if (re-search-forward "</style>" nil t
)
3352 (delete-region (1+ (match-end 0)) (point-max)))
3353 (beginning-of-line 1)
3354 (if (looking-at " +") (replace-match ""))
3355 (goto-char (point-min)))
3357 (defun org-html-protect (s)
3358 ;; convert & to &, < to < and > to >
3360 (while (string-match "&" s start
)
3361 (setq s
(replace-match "&" t t s
)
3362 start
(1+ (match-beginning 0))))
3363 (while (string-match "<" s
)
3364 (setq s
(replace-match "<" t t s
)))
3365 (while (string-match ">" s
)
3366 (setq s
(replace-match ">" t t s
))))
3369 (defun org-export-cleanup-toc-line (s)
3370 "Remove tags and time staps from lines going into the toc."
3371 (when (memq org-export-with-tags
'(not-in-toc nil
))
3372 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3373 (setq s
(replace-match "" t t s
))))
3374 (when org-export-remove-timestamps-from-toc
3375 (while (string-match org-maybe-keyword-time-regexp s
)
3376 (setq s
(replace-match "" t t s
))))
3377 (while (string-match org-bracket-link-regexp s
)
3378 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3382 (defun org-html-expand (string)
3383 "Prepare STRING for HTML export. Applies all active conversions.
3384 If there are links in the string, don't modify these."
3385 (let* ((re (concat org-bracket-link-regexp
"\\|"
3386 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3388 (while (setq m
(string-match re string
))
3389 (setq s
(substring string
0 m
)
3390 l
(match-string 0 string
)
3391 string
(substring string
(match-end 0)))
3392 (push (org-html-do-expand s
) res
)
3394 (push (org-html-do-expand string
) res
)
3395 (apply 'concat
(nreverse res
))))
3397 (defun org-html-do-expand (s)
3398 "Apply all active conversions to translate special ASCII to HTML."
3399 (setq s
(org-html-protect s
))
3400 (if org-export-html-expand
3402 (while (string-match "@<\\([^&]*\\)>" s
)
3403 (setq s
(replace-match "<\\1>" t nil s
)))))
3404 (if org-export-with-emphasize
3405 (setq s
(org-export-html-convert-emphasize s
)))
3406 (if org-export-with-special-strings
3407 (setq s
(org-export-html-convert-special-strings s
)))
3408 (if org-export-with-sub-superscripts
3409 (setq s
(org-export-html-convert-sub-super s
)))
3410 (if org-export-with-TeX-macros
3411 (let ((start 0) wd ass
)
3412 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3413 (if (get-text-property (match-beginning 0) 'org-protected s
)
3414 (setq start
(match-end 0))
3415 (setq wd
(match-string 1 s
))
3416 (if (setq ass
(assoc wd org-html-entities
))
3417 (setq s
(replace-match (or (cdr ass
)
3418 (concat "&" (car ass
) ";"))
3420 (setq start
(+ start
(length wd
))))))))
3423 (defun org-create-multibrace-regexp (left right n
)
3424 "Create a regular expression which will match a balanced sexp.
3425 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3426 as single character strings.
3427 The regexp returned will match the entire expression including the
3428 delimiters. It will also define a single group which contains the
3429 match except for the outermost delimiters. The maximum depth of
3430 stacked delimiters is N. Escaping delimiters is not possible."
3431 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3434 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3437 re
(concat re or next
)
3438 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3439 (concat left
"\\(" re
"\\)" right
)))
3441 (defvar org-match-substring-regexp
3443 "\\([^\\]\\)\\([_^]\\)\\("
3444 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3446 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3448 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3449 "The regular expression matching a sub- or superscript.")
3451 (defvar org-match-substring-with-braces-regexp
3453 "\\([^\\]\\)\\([_^]\\)\\("
3454 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3456 "The regular expression matching a sub- or superscript, forcing braces.")
3458 (defconst org-export-html-special-string-regexps
3459 '(("\\\\-" .
"­")
3460 ("---\\([^-]\\)" .
"—\\1")
3461 ("--\\([^-]\\)" .
"–\\1")
3462 ("\\.\\.\\." .
"…"))
3463 "Regular expressions for special string conversion.")
3465 (defun org-export-html-convert-special-strings (string)
3466 "Convert special characters in STRING to HTML."
3467 (let ((all org-export-html-special-string-regexps
)
3469 (while (setq a
(pop all
))
3470 (setq re
(car a
) rpl
(cdr a
) start
0)
3471 (while (string-match re string start
)
3472 (if (get-text-property (match-beginning 0) 'org-protected string
)
3473 (setq start
(match-end 0))
3474 (setq string
(replace-match rpl t nil string
)))))
3477 (defun org-export-html-convert-sub-super (string)
3478 "Convert sub- and superscripts in STRING to HTML."
3479 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3480 (while (string-match org-match-substring-regexp string s
)
3482 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3483 ((get-text-property (match-beginning 2) 'org-protected string
)
3484 (setq s
(match-end 2)))
3486 (setq s
(match-end 1)
3487 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3488 c
(or (match-string 8 string
)
3489 (match-string 6 string
)
3490 (match-string 5 string
))
3491 string
(replace-match
3492 (concat (match-string 1 string
)
3493 "<" key
">" c
"</" key
">")
3495 (while (string-match "\\\\\\([_^]\\)" string
)
3496 (setq string
(replace-match (match-string 1 string
) t t string
)))
3499 (defun org-export-html-convert-emphasize (string)
3502 (while (string-match org-emph-re string s
)
3504 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3505 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3506 (setq s
(match-beginning 0)
3509 (match-string 1 string
)
3510 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3511 (match-string 4 string
)
3512 (nth 3 (assoc (match-string 3 string
)
3513 org-emphasis-alist
))
3514 (match-string 5 string
))
3515 string
(replace-match rpl t t string
)
3516 s
(+ s
(- (length rpl
) 2)))
3520 (defvar org-par-open nil
)
3521 (defun org-open-par ()
3522 "Insert <p>, but first close previous paragraph if any."
3523 (org-close-par-maybe)
3525 (setq org-par-open t
))
3526 (defun org-close-par-maybe ()
3527 "Close paragraph if there is one open."
3530 (setq org-par-open nil
)))
3531 (defun org-close-li (&optional type
)
3532 "Close <li> if necessary."
3533 (org-close-par-maybe)
3534 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3536 (defvar body-only
) ; dynamically scoped into this.
3537 (defun org-html-level-start (level title umax with-toc head-count
)
3538 "Insert a new level in HTML export.
3539 When TITLE is nil, just close all open levels."
3540 (org-close-par-maybe)
3541 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3545 (if (aref org-levels-open
(1- l
))
3547 (org-html-level-close l umax
)
3548 (aset org-levels-open
(1- l
) nil
)))
3551 ;; If title is nil, this means this function is called to close
3552 ;; all levels, so the rest is done only if title is given
3553 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3554 (setq title
(replace-match
3555 (if org-export-with-tags
3558 " <span class=\"tag\">"
3559 (mapconcat 'identity
(org-split-string
3560 (match-string 1 title
) ":")
3567 (if (aref org-levels-open
(1- level
))
3571 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3572 (insert "<li>" title
"<br/>\n")))
3573 (aset org-levels-open
(1- level
) t
)
3574 (org-close-par-maybe)
3576 (insert (format "<ul>\n<li id=\"%s\">" target
)
3578 (insert "<ul>\n<li>" title
"<br/>\n"))))
3579 (aset org-levels-open
(1- level
) t
)
3580 (setq snumber
(org-section-number level
))
3581 (if (and org-export-with-section-numbers
(not body-only
))
3582 (setq title
(concat snumber
" " title
)))
3583 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3584 (unless (= head-count
1) (insert "\n</div>\n"))
3585 (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"
3586 snumber level level snumber title level snumber
))
3589 (defun org-get-text-property-any (pos prop
&optional object
)
3590 (or (get-text-property pos prop object
)
3591 (and (setq pos
(next-single-property-change pos prop object
))
3592 (get-text-property pos prop object
))))
3594 (defun org-html-level-close (level max-outline-level
)
3595 "Terminate one level in HTML export."
3596 (if (<= level max-outline-level
)
3599 (insert "</ul>\n")))
3601 ;;; iCalendar export
3604 (defun org-export-icalendar-this-file ()
3605 "Export current file as an iCalendar file.
3606 The iCalendar file will be located in the same directory as the Org-mode
3607 file, but with extension `.ics'."
3609 (org-export-icalendar nil buffer-file-name
))
3612 (defun org-export-icalendar-all-agenda-files ()
3613 "Export all files in `org-agenda-files' to iCalendar .ics files.
3614 Each iCalendar file will be located in the same directory as the Org-mode
3615 file, but with extension `.ics'."
3617 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3620 (defun org-export-icalendar-combine-agenda-files ()
3621 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3622 The file is stored under the name `org-combined-agenda-icalendar-file'."
3624 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3626 (defun org-export-icalendar (combine &rest files
)
3627 "Create iCalendar files for all elements of FILES.
3628 If COMBINE is non-nil, combine all calendar entries into a single large
3629 file and store it under the name `org-combined-agenda-icalendar-file'."
3631 (org-prepare-agenda-buffers files
)
3632 (let* ((dir (org-export-directory
3633 :ical
(list :publishing-directory
3634 org-export-publishing-directory
)))
3635 file ical-file ical-buffer category started org-agenda-new-buffers
)
3636 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3639 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3640 org-combined-agenda-icalendar-file
3641 (expand-file-name org-combined-agenda-icalendar-file dir
))
3642 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3643 (set-buffer ical-buffer
) (erase-buffer))
3644 (while (setq file
(pop files
))
3646 (org-check-agenda-file file
)
3647 (set-buffer (org-get-agenda-file-buffer file
))
3649 (setq ical-file
(concat (file-name-as-directory dir
)
3650 (file-name-sans-extension
3651 (file-name-nondirectory buffer-file-name
))
3653 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3654 (with-current-buffer ical-buffer
(erase-buffer)))
3655 (setq category
(or org-category
3656 (file-name-sans-extension
3657 (file-name-nondirectory buffer-file-name
))))
3658 (if (symbolp category
) (setq category
(symbol-name category
)))
3659 (let ((standard-output ical-buffer
))
3661 (and (not started
) (setq started t
)
3662 (org-start-icalendar-file org-icalendar-combined-name
))
3663 (org-start-icalendar-file category
))
3664 (org-print-icalendar-entries combine
)
3665 (when (or (and combine
(not files
)) (not combine
))
3666 (org-finish-icalendar-file)
3667 (set-buffer ical-buffer
)
3669 (run-hooks 'org-after-save-iCalendar-file-hook
)
3670 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3672 (org-release-buffers org-agenda-new-buffers
))))
3674 (defvar org-after-save-iCalendar-file-hook nil
3675 "Hook run after an iCalendar file has been saved.
3676 The iCalendar buffer is still current when this hook is run.
3677 A good way to use this is to tell a desktop calenndar application to re-read
3678 the iCalendar file.")
3680 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3681 (defun org-print-icalendar-entries (&optional combine
)
3682 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3683 When COMBINE is non nil, add the category to each line."
3684 (require 'org-agenda
)
3685 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3686 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3687 (dts (org-ical-ts-to-string
3688 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3690 hd ts ts2 state status
(inc t
) pos b sexp rrule
3691 scheduledp deadlinep tmp pri category entry location summary desc
3692 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3693 (org-refresh-category-properties)
3695 (goto-char (point-min))
3696 (while (re-search-forward re1 nil t
)
3699 (when (boundp 'org-icalendar-verify-function
)
3700 (unless (funcall org-icalendar-verify-function
)
3701 (outline-next-heading)
3704 (setq pos
(match-beginning 0)
3707 hd
(condition-case nil
3708 (org-icalendar-cleanup-string
3710 (error (throw :skip nil
)))
3711 summary
(org-icalendar-cleanup-string
3712 (org-entry-get nil
"SUMMARY"))
3713 desc
(org-icalendar-cleanup-string
3714 (or (org-entry-get nil
"DESCRIPTION")
3715 (and org-icalendar-include-body
(org-get-entry)))
3716 t org-icalendar-include-body
)
3717 location
(org-icalendar-cleanup-string
3718 (org-entry-get nil
"LOCATION"))
3719 category
(org-get-category))
3720 (if (looking-at re2
)
3722 (goto-char (match-end 0))
3723 (setq ts2
(match-string 1)
3724 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3725 (setq tmp
(buffer-substring (max (point-min)
3726 (- pos org-ds-keyword-length
))
3728 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3731 (replace-match "\\1" t nil ts
))
3733 deadlinep
(string-match org-deadline-regexp tmp
)
3734 scheduledp
(string-match org-scheduled-regexp tmp
)
3735 ;; donep (org-entry-is-done-p)
3737 (if (or (string-match org-tr-regexp hd
)
3738 (string-match org-ts-regexp hd
))
3739 (setq hd
(replace-match "" t t hd
)))
3740 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3742 (concat "\nRRULE:FREQ="
3745 '(("d" .
"DAILY")("w" .
"WEEKLY")
3746 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3747 ";INTERVAL=" (match-string 1 ts
)))
3749 (setq summary
(or summary hd
))
3750 (if (string-match org-bracket-link-regexp summary
)
3752 (replace-match (if (match-end 3)
3753 (match-string 3 summary
)
3754 (match-string 1 summary
))
3756 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3757 (if scheduledp
(setq summary
(concat "S: " summary
)))
3758 (if (string-match "\\`<%%" ts
)
3759 (with-current-buffer sexp-buffer
3760 (insert (substring ts
1 -
1) " " summary
"\n"))
3761 (princ (format "BEGIN:VEVENT
3767 (org-ical-ts-to-string ts
"DTSTART")
3768 (org-ical-ts-to-string ts2
"DTEND" inc
)
3770 (if (and desc
(string-match "\\S-" desc
))
3771 (concat "\nDESCRIPTION: " desc
) "")
3772 (if (and location
(string-match "\\S-" location
))
3773 (concat "\nLOCATION: " location
) "")
3776 (when (and org-icalendar-include-sexps
3777 (condition-case nil
(require 'icalendar
) (error nil
))
3778 (fboundp 'icalendar-export-region
))
3779 ;; Get all the literal sexps
3780 (goto-char (point-min))
3781 (while (re-search-forward "^&?%%(" nil t
)
3784 (setq b
(match-beginning 0))
3785 (goto-char (1- (match-end 0)))
3788 (setq sexp
(buffer-substring b
(point)))
3789 (with-current-buffer sexp-buffer
3791 (princ (org-diary-to-ical-string sexp-buffer
)))))
3793 (when org-icalendar-include-todo
3794 (goto-char (point-min))
3795 (while (re-search-forward org-todo-line-regexp nil t
)
3798 (when (boundp 'org-icalendar-verify-function
)
3799 (unless (funcall org-icalendar-verify-function
)
3800 (outline-next-heading)
3803 (setq state
(match-string 2))
3804 (setq status
(if (member state org-done-keywords
)
3805 "COMPLETED" "NEEDS-ACTION"))
3807 (or (not (member state org-done-keywords
))
3808 (eq org-icalendar-include-todo
'all
))
3809 (not (member org-archive-tag
(org-get-tags-at)))
3811 (setq hd
(match-string 3)
3812 summary
(org-icalendar-cleanup-string
3813 (org-entry-get nil
"SUMMARY"))
3814 desc
(org-icalendar-cleanup-string
3815 (or (org-entry-get nil
"DESCRIPTION")
3816 (and org-icalendar-include-body
(org-get-entry)))
3817 t org-icalendar-include-body
)
3818 location
(org-icalendar-cleanup-string
3819 (org-entry-get nil
"LOCATION")))
3820 (if (string-match org-bracket-link-regexp hd
)
3821 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3822 (match-string 1 hd
))
3824 (if (string-match org-priority-regexp hd
)
3825 (setq pri
(string-to-char (match-string 2 hd
))
3826 hd
(concat (substring hd
0 (match-beginning 1))
3827 (substring hd
(match-end 1))))
3828 (setq pri org-default-priority
))
3829 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3830 (- org-lowest-priority org-highest-priority
))))))
3832 (princ (format "BEGIN:VTODO
3842 (if (and location
(string-match "\\S-" location
))
3843 (concat "\nLOCATION: " location
) "")
3844 (if (and desc
(string-match "\\S-" desc
))
3845 (concat "\nDESCRIPTION: " desc
) "")
3846 category pri status
)))))))))
3848 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3849 "Take out stuff and quote what needs to be quoted.
3850 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3851 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3856 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3857 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3858 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3859 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3861 (while (string-match "\\([,;]\\)" s start
)
3862 (setq start
(+ (match-beginning 0) 2)
3863 s
(replace-match "\\\\\\1" nil nil s
))))
3865 (while (string-match "[ \t]*\n[ \t]*" s
)
3866 (setq s
(replace-match "\\n" t t s
))))
3867 (setq s
(org-trim s
))
3870 (if (and (numberp maxlength
)
3871 (> (length s
) maxlength
))
3872 (setq s
(substring s
0 maxlength
)))))
3875 (defun org-get-entry ()
3876 "Clean-up description string."
3878 (org-back-to-heading t
)
3879 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3881 (defun org-start-icalendar-file (name)
3882 "Start an iCalendar file by inserting the header."
3883 (let ((user user-full-name
)
3884 (name (or name
"unknown"))
3885 (timezone (cadr (current-time-zone))))
3887 (format "BEGIN:VCALENDAR
3890 PRODID:-//%s//Emacs with Org-mode//EN
3892 CALSCALE:GREGORIAN\n" name user timezone
))))
3894 (defun org-finish-icalendar-file ()
3895 "Finish an iCalendar file by inserting the END statement."
3896 (princ "END:VCALENDAR\n"))
3898 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3899 "Take a time string S and convert it to iCalendar format.
3900 KEYWORD is added in front, to make a complete line like DTSTART....
3901 When INC is non-nil, increase the hour by two (if time string contains
3902 a time), or the day by one (if it does not contain a time)."
3903 (let ((t1 (org-parse-time-string s
'nodefault
))
3904 t2 fmt have-time time
)
3905 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3906 (setq t2 t1 have-time t
)
3907 (setq t2
(org-parse-time-string s
)))
3908 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3909 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3912 (if org-agenda-default-appointment-duration
3913 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3916 (setq time
(encode-time s mi h d m y
)))
3917 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3918 (concat keyword
(format-time-string fmt time
))))
3922 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3923 (with-current-buffer buffer
3924 (apply 'insert output
)))
3925 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3928 (defun org-export-as-xoxo (&optional buffer
)
3929 "Export the org buffer as XOXO.
3930 The XOXO buffer is named *xoxo-<source buffer name>*"
3931 (interactive (list (current-buffer)))
3932 ;; A quickie abstraction
3934 ;; Output everything as XOXO
3935 (with-current-buffer (get-buffer buffer
)
3936 (let* ((pos (point))
3937 (opt-plist (org-combine-plists (org-default-export-plist)
3938 (org-infile-export-plist)))
3939 (filename (concat (file-name-as-directory
3940 (org-export-directory :xoxo opt-plist
))
3941 (file-name-sans-extension
3942 (file-name-nondirectory buffer-file-name
))
3944 (out (find-file-noselect filename
))
3947 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3948 ;; Check the output buffer is empty.
3949 (with-current-buffer out
(erase-buffer))
3950 ;; Kick off the output
3951 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3952 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3953 (let* ((hd (match-string-no-properties 1))
3956 (match-string-no-properties 2)
3958 (goto-char (match-end 0))
3963 (if (looking-at "^[ \t]\\(.*\\)")
3964 (setq str
(concat str
(match-string-no-properties 1)))
3965 (throw 'loop str
)))))))))
3967 ;; Handle level rendering
3969 ((> level last-level
)
3970 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3972 ((< level last-level
)
3973 (dotimes (- (- last-level level
) 1)
3975 (org-export-as-xoxo-insert-into out
"</li>\n"))
3976 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3978 (org-export-as-xoxo-insert-into out
"</li>\n")
3979 (setq hanging-li nil
)))
3981 ((equal level last-level
)
3983 (org-export-as-xoxo-insert-into out
"</li>\n")))
3986 (setq last-level level
)
3988 ;; And output the new li
3989 (setq hanging-li
't
)
3990 (if (equal ?
+ (elt text
0))
3991 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3992 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3994 ;; Finally finish off the ol
3995 (dotimes (- last-level
1)
3997 (org-export-as-xoxo-insert-into out
"</li>\n"))
3998 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4001 ;; Finish the buffer off and clean it up.
4002 (switch-to-buffer-other-window out
)
4003 (indent-region (point-min) (point-max) nil
)
4005 (goto-char (point-min))
4010 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4012 ;;; org-exp.el ends here