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
635 (defcustom org-icalendar-force-UID nil
636 "Non-nil means, each exported entry must have a UID.
637 If not present, that UID will be created."
638 :group
'org-export-icalendar
643 ;;; Variables, constants, and parameter plists
645 (defconst org-level-max
20)
647 (defvar org-export-html-preamble nil
648 "Preamble, to be inserted just after <body>. Set by publishing functions.")
649 (defvar org-export-html-postamble nil
650 "Preamble, to be inserted just before </body>. Set by publishing functions.")
651 (defvar org-export-html-auto-preamble t
652 "Should default preamble be inserted? Set by publishing functions.")
653 (defvar org-export-html-auto-postamble t
654 "Should default postamble be inserted? Set by publishing functions.")
655 (defvar org-current-export-file nil
) ; dynamically scoped parameter
656 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
658 (defconst org-export-plist-vars
659 '((:link-up . org-export-html-link-up
)
660 (:link-home . org-export-html-link-home
)
661 (:language . org-export-default-language
)
662 (:customtime . org-display-custom-times
)
663 (:headline-levels . org-export-headline-levels
)
664 (:section-numbers . org-export-with-section-numbers
)
665 (:table-of-contents . org-export-with-toc
)
666 (:preserve-breaks . org-export-preserve-breaks
)
667 (:archived-trees . org-export-with-archived-trees
)
668 (:emphasize . org-export-with-emphasize
)
669 (:sub-superscript . org-export-with-sub-superscripts
)
670 (:special-strings . org-export-with-special-strings
)
671 (:footnotes . org-export-with-footnotes
)
672 (:drawers . org-export-with-drawers
)
673 (:tags . org-export-with-tags
)
674 (:TeX-macros . org-export-with-TeX-macros
)
675 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
676 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
677 (:fixed-width . org-export-with-fixed-width
)
678 (:timestamps . org-export-with-timestamps
)
679 (:author-info . org-export-author-info
)
680 (:time-stamp-file . org-export-time-stamp-file
)
681 (:tables . org-export-with-tables
)
682 (:table-auto-headline . org-export-highlight-first-table-line
)
683 (:style . org-export-html-style
)
684 (:agenda-style . org-agenda-export-html-style
)
685 (:convert-org-links . org-export-html-link-org-files-as-html
)
686 (:inline-images . org-export-html-inline-images
)
687 (:html-extension . org-export-html-extension
)
688 (:html-table-tag . org-export-html-table-tag
)
689 (:expand-quoted-html . org-export-html-expand
)
690 (:timestamp . org-export-html-with-timestamp
)
691 (:publishing-directory . org-export-publishing-directory
)
692 (:preamble . org-export-html-preamble
)
693 (:postamble . org-export-html-postamble
)
694 (:auto-preamble . org-export-html-auto-preamble
)
695 (:auto-postamble . org-export-html-auto-postamble
)
696 (:author . user-full-name
)
697 (:email . user-mail-address
)))
699 (defun org-default-export-plist ()
700 "Return the property list with default settings for the export variables."
701 (let ((l org-export-plist-vars
) rtn e
)
702 (while (setq e
(pop l
))
703 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
706 (defvar org-export-inbuffer-options-extra nil
707 "List of additional in-buffer options that should be detected.
708 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
709 etc. Extensions can add to this list to get their options detected, and they
710 can then add a function to `org-export-options-filters' to process these
712 Each element in this list must be a list, with the in-buffer keyword as car,
713 and a property (a symbol) as the next element. All occurences of the
714 keyword will be found, the values concatenated with a space character
715 in between, and the result stored in the export options property list.")
717 (defvar org-export-options-filters nil
718 "Functions to be called to finalize the export/publishing options.
719 All these options are stored in a property list, and each of the functions
720 in this hook gets a chance to modify this property list. Each function
721 must accept the property list as an argument, and must return the (possibly
724 (defun org-infile-export-plist ()
725 "Return the property list with file-local settings for export."
729 (goto-char (point-min))
730 (let ((re (org-make-options-regexp
732 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
733 "LINK_UP" "LINK_HOME" "SETUPFILE")
734 (mapcar 'car org-export-inbuffer-options-extra
))))
735 p key val text options js-up js-main js-css js-opt a pr
736 ext-setup-or-nil setup-contents
(start 0))
737 (while (or (and ext-setup-or-nil
738 (string-match re ext-setup-or-nil start
)
739 (setq start
(match-end 0)))
740 (and (setq ext-setup-or-nil nil start
0)
741 (re-search-forward re nil t
)))
742 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
743 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
745 ((setq a
(assoc key org-export-inbuffer-options-extra
))
747 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
748 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
749 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
750 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
751 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
752 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
753 ((string-equal key
"TEXT")
754 (setq text
(if text
(concat text
"\n" val
) val
)))
755 ((string-equal key
"OPTIONS")
756 (setq options
(concat val
" " options
)))
757 ((string-equal key
"LINK_UP")
758 (setq p
(plist-put p
:link-up val
)))
759 ((string-equal key
"LINK_HOME")
760 (setq p
(plist-put p
:link-home val
)))
761 ((equal key
"SETUPFILE")
762 (setq setup-contents
(org-file-contents
764 (org-remove-double-quotes
767 (if (not ext-setup-or-nil
)
768 (setq ext-setup-or-nil setup-contents start
0)
769 (setq ext-setup-or-nil
770 (concat (substring ext-setup-or-nil
0 start
)
771 "\n" setup-contents
"\n"
772 (substring ext-setup-or-nil start
)))))))
773 (setq p
(plist-put p
:text text
))
775 (let ((op '(("H" .
:headline-levels
)
776 ("num" .
:section-numbers
)
777 ("toc" .
:table-of-contents
)
778 ("\\n" .
:preserve-breaks
)
779 ("@" .
:expand-quoted-html
)
782 ("^" .
:sub-superscript
)
783 ("-" .
:special-strings
)
788 ("TeX" .
:TeX-macros
)
789 ("LaTeX" .
:LaTeX-fragments
)
790 ("skip" .
:skip-before-1st-heading
)
791 ("author" .
:author-info
)
792 ("timestamp" .
:time-stamp-file
)))
794 (while (setq o
(pop op
))
795 (if (string-match (concat (regexp-quote (car o
))
796 ":\\([^ \t\n\r;,.]*\\)")
798 (setq p
(plist-put p
(cdr o
)
799 (car (read-from-string
800 (match-string 1 options
)))))))))
803 (defun org-export-directory (type plist
)
804 (let* ((val (plist-get plist
:publishing-directory
))
806 (or (cdr (assoc type val
)) ".")
810 (defun org-export-process-option-filters (plist)
811 (let ((functions org-export-options-filters
) f
)
812 (while (setq f
(pop functions
))
813 (setq plist
(funcall f plist
))))
817 (defun org-export (&optional arg
)
818 "Export dispatcher for Org-mode.
819 When `org-export-run-in-background' is non-nil, try to run the command
820 in the background. This will be done only for commands that write
821 to a file. For details see the docstring of `org-export-run-in-background'.
823 The prefix argument ARG will be passed to the exporter. However, if
824 ARG is a double universal prefix `C-u C-u', that means to inverse the
825 value of `org-export-run-in-background'."
827 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
828 (help "[t] insert the export option template
829 \[v] limit export to visible part of outline tree
834 \[H] export as HTML to temporary buffer
835 \[R] export region as HTML
836 \[b] export as HTML and browse immediately
840 \[L] export as LaTeX to temporary buffer
842 \[i] export current file as iCalendar file
843 \[I] export all agenda files as iCalendar files
844 \[c] export agenda files into combined iCalendar file
846 \[F] publish current file
847 \[P] publish current project
848 \[X] publish... (project will be prompted for)
849 \[A] publish all projects")
851 '((?t org-insert-export-options-template nil
)
852 (?v org-export-visible nil
)
853 (?a org-export-as-ascii t
)
854 (?h org-export-as-html t
)
855 (?b org-export-as-html-and-open t
)
856 (?H org-export-as-html-to-buffer nil
)
857 (?R org-export-region-as-html nil
)
858 (?x org-export-as-xoxo t
)
859 (?l org-export-as-latex t
)
860 (?L org-export-as-latex-to-buffer nil
)
861 (?i org-export-icalendar-this-file t
)
862 (?I org-export-icalendar-all-agenda-files t
)
863 (?c org-export-icalendar-combine-agenda-files t
)
864 (?F org-publish-current-file t
)
865 (?P org-publish-current-project t
)
867 (?A org-publish-all t
)))
869 (save-window-excursion
870 (delete-other-windows)
871 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
873 (message "Select command: ")
874 (setq r1
(read-char-exclusive)))
875 (setq r2
(if (< r1
27) (+ r1
96) r1
))
876 (unless (setq ass
(assq r2 cmds
))
877 (error "No command associated with key %c" r1
))
878 (if (and bg
(nth 2 ass
))
879 ;; execute in background
880 (let ((p (start-process
881 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
883 (expand-file-name invocation-name invocation-directory
)
886 "--eval" "(require 'org-exp)"
887 "--eval" "(setq org-wait .2)"
889 "-f" (symbol-name (nth 1 ass
)))))
890 (set-process-sentinel p
'org-export-process-sentinel
)
891 (message "Background process \"%s\": started" p
))
892 ;; background processing not requested, or not possible
893 (call-interactively (nth 1 ass
)))))
895 (defun org-export-process-sentinel (process status
)
896 (if (string-match "\n+\\'" status
)
897 (setq status
(substring status
0 -
1)))
898 (message "Background process \"%s\": %s" process status
))
900 (defconst org-html-entities
941 ("Aring") ("AA".
"Å")
1030 ("varepsilon".
"ε")
1043 ("sigmaf") ("varsigma".
"ς")
1051 ("thetasym") ("vartheta".
"ϑ")
1054 ("bull") ("bullet".
"•")
1055 ("hellip") ("dots".
"…")
1065 ("larr") ("leftarrow".
"←") ("gets".
"←")
1066 ("uarr") ("uparrow".
"↑")
1067 ("rarr") ("to".
"→") ("rightarrow".
"→")
1068 ("darr")("downarrow".
"↓")
1069 ("harr") ("leftrightarrow".
"↔")
1070 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1071 ("lArr") ("Leftarrow".
"⇐")
1072 ("uArr") ("Uparrow".
"⇑")
1073 ("rArr") ("Rightarrow".
"⇒")
1074 ("dArr") ("Downarrow".
"⇓")
1075 ("hArr") ("Leftrightarrow".
"⇔")
1077 ("part") ("partial".
"∂")
1078 ("exist") ("exists".
"∃")
1079 ("empty") ("emptyset".
"∅")
1081 ("isin") ("in".
"∈")
1087 ("lowast") ("ast".
"∗")
1089 ("prop") ("proptp".
"∝")
1090 ("infin") ("infty".
"∞")
1091 ("ang") ("angle".
"∠")
1092 ("and") ("wedge".
"∧")
1093 ("or") ("vee".
"∨")
1099 ("cong") ("simeq".
"≅")
1100 ("asymp")("approx".
"≈")
1101 ("ne") ("neq".
"≠")
1105 ("sub") ("subset".
"⊂")
1106 ("sup") ("supset".
"⊃")
1113 ("sdot") ("cdot".
"⋅")
1120 ("loz") ("Diamond".
"◊")
1121 ("spades") ("spadesuit".
"♠")
1122 ("clubs") ("clubsuit".
"♣")
1123 ("hearts") ("diamondsuit".
"♥")
1124 ("diams") ("diamondsuit".
"♦")
1125 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1192 "Entities for TeX->HTML translation.
1193 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1194 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1195 In that case, \"\\ent\" will be translated to \"&other;\".
1196 The list contains HTML entities for Latin-1, Greek and other symbols.
1197 It is supplemented by a number of commonly used TeX macros with appropriate
1198 translations. There is currently no way for users to extend this.")
1200 ;;; General functions for all backends
1202 (defun org-export-preprocess-string (string &rest parameters
)
1203 "Cleanup STRING so that that the true exported has a more consistent source.
1204 This function takes STRING, which should be a buffer-string of an org-file
1205 to export. It then creates a temporary buffer where it does its job.
1206 The result is then again returned as a string, and the exporter works
1207 on this string to produce the exported version."
1209 (let* ((re-radio (and org-target-link-regexp
1210 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1211 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1212 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1213 (re-archive (concat ":" org-archive-tag
":"))
1214 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1215 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1216 (htmlp (plist-get parameters
:for-html
))
1217 (asciip (plist-get parameters
:for-ascii
))
1218 (latexp (plist-get parameters
:for-LaTeX
))
1219 (commentsp (plist-get parameters
:comments
))
1220 (archived-trees (plist-get parameters
:archived-trees
))
1221 (inhibit-read-only t
)
1222 (drawers org-drawers
)
1223 (exp-drawers (plist-get parameters
:drawers
))
1224 (outline-regexp "\\*+ ")
1225 target-alist tmp target level
1228 (with-current-buffer (get-buffer-create " org-mode-tmp")
1231 (setq case-fold-search t
)
1233 (run-hooks 'org-export-preprocess-hook
)
1235 ;; Remove license-to-kill stuff
1236 ;; The caller markes some stuff fo killing, stuff that has been
1237 ;; used to create the page title, for example.
1238 (while (setq p
(text-property-any (point-min) (point-max)
1239 :org-license-to-kill t
))
1240 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1242 (let ((org-inhibit-startup t
)) (org-mode))
1243 (setq case-fold-search t
)
1244 (untabify (point-min) (point-max))
1246 ;; Handle incude files
1247 (org-export-handle-include-files)
1249 ;; Handle source code snippets
1250 (org-export-replace-src-segments)
1252 ;; Get rid of drawers
1253 (unless (eq t exp-drawers
)
1254 (goto-char (point-min))
1255 (let ((re (concat "^[ \t]*:\\("
1258 (org-delete-all exp-drawers
1259 (copy-sequence drawers
))
1261 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1262 (while (re-search-forward re nil t
)
1263 (replace-match ""))))
1265 ;; Get the correct stuff before the first headline
1266 (when (plist-get parameters
:skip-before-1st-heading
)
1267 (goto-char (point-min))
1268 (when (re-search-forward "^\\*+[ \t]" nil t
)
1269 (delete-region (point-min) (match-beginning 0))
1270 (goto-char (point-min))
1272 (when (plist-get parameters
:add-text
)
1273 (goto-char (point-min))
1274 (insert (plist-get parameters
:add-text
) "\n"))
1276 ;; Get rid of archived trees
1277 (when (not (eq archived-trees t
))
1278 (goto-char (point-min))
1279 (while (re-search-forward re-archive nil t
)
1280 (if (not (org-on-heading-p t
))
1281 (org-end-of-subtree t
)
1282 (beginning-of-line 1)
1283 (setq a
(if archived-trees
1284 (1+ (point-at-eol)) (point))
1285 b
(org-end-of-subtree t
))
1286 (if (> b a
) (delete-region a b
)))))
1288 ;; Find all headings and compute the targets for them
1289 (goto-char (point-min))
1290 (org-init-section-numbers)
1291 (let ((re (concat "^" org-outline-regexp
)))
1292 (while (re-search-forward re nil t
)
1293 (setq level
(org-reduced-level
1294 (save-excursion (goto-char (point-at-bol))
1295 (org-outline-level))))
1296 (setq target
(org-solidify-link-text
1297 (format "sec-%s" (org-section-number level
))))
1298 (push (cons target target
) target-alist
)
1299 (add-text-properties
1300 (point-at-bol) (point-at-eol)
1301 (list 'target target
))))
1303 ;; Find targets in comments and move them out of comments,
1304 ;; but mark them as targets that should be invisible
1305 (goto-char (point-min))
1306 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1307 ;; Check if the line before or after is a headline with a target
1308 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1309 (get-text-property (point-at-bol 2) 'target
)))
1311 ;; use the existing target in a neighboring line
1312 (setq tmp
(match-string 2))
1314 (and (looking-at "\n") (delete-char 1))
1315 (push (cons (org-solidify-link-text tmp
) target
)
1317 ;; Make an invisible target
1318 (replace-match "\\1(INVISIBLE)")))
1320 ;; Protect backend specific stuff, throw away the others.
1322 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1323 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1324 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1326 (goto-char (point-min))
1327 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1328 (goto-char (match-end 0))
1329 (while (not (looking-at "#\\+END_EXAMPLE"))
1331 (beginning-of-line 2)))
1332 (goto-char (point-min))
1333 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1334 (add-text-properties (match-beginning 0) (match-end 0)
1335 '(org-protected t
)))
1337 (setq fmt
(pop formatters
))
1339 (goto-char (point-min))
1340 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1341 ":[ \t]*\\(.*\\)") nil t
)
1342 (replace-match "\\1" t
)
1343 (add-text-properties
1344 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1345 '(org-protected t
))))
1346 (goto-char (point-min))
1347 (while (re-search-forward
1349 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1350 (cadddr fmt
) "\\>.*\n?") nil t
)
1352 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1354 (delete-region (match-beginning 0) (match-end 0))))))
1356 ;; Protect quoted subtrees
1357 (goto-char (point-min))
1358 (while (re-search-forward re-quote nil t
)
1359 (goto-char (match-beginning 0))
1361 (add-text-properties (point) (org-end-of-subtree t
)
1362 '(org-protected t
)))
1364 ;; Protect verbatim elements
1365 (goto-char (point-min))
1366 (while (re-search-forward org-verbatim-re nil t
)
1367 (add-text-properties (match-beginning 4) (match-end 4)
1369 (goto-char (1+ (match-end 4))))
1372 (goto-char (point-min))
1373 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1374 (replace-match (if (equal (downcase (match-string 1)) "end")
1375 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1378 (goto-char (point-min))
1379 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1380 (replace-match (if (equal (downcase (match-string 1)) "end")
1381 "ORG-VERSE-END" "ORG-VERSE-START")
1384 ;; Remove comment environment
1385 (goto-char (point-min))
1386 (while (re-search-forward
1387 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1388 (replace-match "" t t
))
1390 ;; Remove subtrees that are commented
1391 (goto-char (point-min))
1392 (while (re-search-forward re-commented nil t
)
1393 (goto-char (match-beginning 0))
1394 (delete-region (point) (org-end-of-subtree t
)))
1396 ;; Remove special table lines
1397 (when org-export-table-remove-special-lines
1398 (goto-char (point-min))
1399 (while (re-search-forward "^[ \t]*|" nil t
)
1400 (beginning-of-line 1)
1401 (if (or (looking-at "[ \t]*| *[!_^] *|")
1402 (and (looking-at ".*?| *<[0-9]+> *|")
1403 (not (looking-at ".*?| *[^ <|]"))))
1404 (delete-region (max (point-min) (1- (point-at-bol)))
1408 ;; Specific LaTeX stuff
1410 (require 'org-export-latex nil
)
1411 (org-export-latex-preprocess))
1414 (org-export-ascii-clean-string))
1416 ;; Specific HTML stuff
1418 ;; Convert LaTeX fragments to images
1419 (when (plist-get parameters
:LaTeX-fragments
)
1421 (concat "ltxpng/" (file-name-sans-extension
1422 (file-name-nondirectory
1423 org-current-export-file
)))
1424 org-current-export-dir nil
"Creating LaTeX image %s"))
1425 (message "Exporting..."))
1427 ;; Remove or replace comments
1428 (goto-char (point-min))
1429 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1431 (progn (add-text-properties
1432 (match-beginning 0) (match-end 0) '(org-protected t
))
1433 (replace-match (format commentsp
(match-string 1)) t t
))
1434 (replace-match "")))
1436 ;; Find matches for radio targets and turn them into internal links
1437 (goto-char (point-min))
1439 (while (re-search-forward re-radio nil t
)
1441 (replace-match "\\1[[\\2]]"))))
1443 ;; Find all links that contain a newline and put them into a single line
1444 (goto-char (point-min))
1445 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1447 (replace-match "\\1 \\3")
1448 (goto-char (match-beginning 0))))
1450 ;; Find all internal links. If they have a fuzzy match (i.e. not
1451 ;; a *dedicated* target match, let the link point to the
1452 ;; correspinding section.
1454 (goto-char (point-min))
1455 (while (re-search-forward org-bracket-link-regexp nil t
)
1457 (let* ((md (match-data))
1458 (desc (match-end 2))
1459 (link (org-link-unescape (match-string 1)))
1460 (slink (org-solidify-link-text link
))
1463 (or (cdr (assoc slink target-alist
))
1465 (unless (string-match org-link-types-re link
)
1466 (setq found
(condition-case nil
(org-link-search link
)
1469 (or (org-on-heading-p)
1470 (not (eq found
'dedicated
))))
1471 (or (get-text-property (point) 'target
)
1474 (1- (previous-single-property-change
1479 (goto-char (match-beginning 1))
1480 (setq props
(text-properties-at (point)))
1481 (delete-region (match-beginning 1) (match-end 1))
1484 (unless desc
(insert "][" link
))
1485 (add-text-properties pos
(point) props
)))))
1487 ;; Normalize links: Convert angle and plain links into bracket links
1488 ;; Expand link abbreviations
1489 (goto-char (point-min))
1490 (while (re-search-forward re-plain-link nil t
)
1491 (goto-char (1- (match-end 0)))
1493 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1494 ":" (match-string 3) "]]")))
1495 ;; added 'org-link face to links
1496 (put-text-property 0 (length s
) 'face
'org-link s
)
1497 (replace-match s t t
))))
1498 (goto-char (point-min))
1499 (while (re-search-forward re-angle-link nil t
)
1500 (goto-char (1- (match-end 0)))
1502 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1503 ":" (match-string 3) "]]")))
1504 (put-text-property 0 (length s
) 'face
'org-link s
)
1505 (replace-match s t t
))))
1506 (goto-char (point-min))
1507 (while (re-search-forward org-bracket-link-regexp nil t
)
1509 (let* ((s (concat "[[" (setq xx
(save-match-data
1510 (org-link-expand-abbrev (match-string 1))))
1514 (concat "[" xx
"]"))
1516 (put-text-property 0 (length s
) 'face
'org-link s
)
1517 (replace-match s t t
))))
1519 ;; Find multiline emphasis and put them into single line
1520 (when (plist-get parameters
:emph-multiline
)
1521 (goto-char (point-min))
1522 (while (re-search-forward org-emph-re nil t
)
1523 (if (not (= (char-after (match-beginning 3))
1524 (char-after (match-beginning 4))))
1526 (subst-char-in-region (match-beginning 0) (match-end 0)
1528 (goto-char (1- (match-end 0))))
1529 (goto-char (1+ (match-beginning 0))))))
1531 (setq rtn
(buffer-string)))
1532 (kill-buffer " org-mode-tmp")
1535 (defun org-export-grab-title-from-buffer ()
1536 "Get a title for the current document, from looking at the buffer."
1537 (let ((inhibit-read-only t
))
1539 (goto-char (point-min))
1540 (let ((end (save-excursion (outline-next-heading) (point))))
1541 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1542 ;; Mark the line so that it will not be exported as normal text.
1544 (add-text-properties (match-beginning 0) (match-end 0)
1545 (list :org-license-to-kill t
)))
1546 ;; Return the title string
1547 (org-trim (match-string 0)))))))
1549 (defun org-export-get-title-from-subtree ()
1550 "Return subtree title and exclude it from export."
1551 (let (title (m (mark)))
1553 (goto-char (region-beginning))
1554 (when (and (org-at-heading-p)
1555 (>= (org-end-of-subtree t t
) (region-end)))
1556 ;; This is a subtree, we take the title from the first heading
1557 (goto-char (region-beginning))
1558 (looking-at org-todo-line-regexp
)
1559 (setq title
(match-string 3))
1561 (add-text-properties (point) (1+ (point-at-eol))
1562 (list :org-license-to-kill t
)))))
1565 (defun org-solidify-link-text (s &optional alist
)
1566 "Take link text and make a safe target out of it."
1571 (org-split-string s
"[ \t\r\n]+") "=="))
1572 (a (assoc rtn alist
)))
1575 (defun org-get-min-level (lines)
1576 "Get the minimum level in LINES."
1577 (let ((re "^\\(\\*+\\) ") l min
)
1579 (while (setq l
(pop lines
))
1580 (if (string-match re l
)
1581 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1584 ;; Variable holding the vector with section numbers
1585 (defvar org-section-numbers
(make-vector org-level-max
0))
1587 (defun org-init-section-numbers ()
1588 "Initialize the vector for the section numbers."
1590 (numbers (nreverse (org-split-string "" "\\.")))
1591 (depth (1- (length org-section-numbers
)))
1592 (i depth
) number-string
)
1595 (aset org-section-numbers i
0)
1596 (setq number-string
(or (car numbers
) "0"))
1597 (if (string-match "\\`[A-Z]\\'" number-string
)
1598 (aset org-section-numbers i
1599 (- (string-to-char number-string
) ?A -
1))
1600 (aset org-section-numbers i
(string-to-number number-string
)))
1604 (defun org-section-number (&optional level
)
1605 "Return a string with the current section number.
1606 When LEVEL is non-nil, increase section numbers on that level."
1607 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1610 (aset org-section-numbers
1611 level
(1+ (aref org-section-numbers level
))))
1612 (setq idx
(1+ level
))
1613 (while (<= idx depth
)
1615 (aset org-section-numbers idx
0))
1616 (setq idx
(1+ idx
))))
1618 (while (<= idx depth
)
1619 (setq n
(aref org-section-numbers idx
))
1620 (setq string
(concat string
(if (not (string= string
"")) "." "")
1622 (setq idx
(1+ idx
)))
1624 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1625 (setq string
(replace-match "" t nil string
)))
1626 (if (string-match "\\(\\.0\\)+\\'" string
)
1627 (setq string
(replace-match "" t nil string
))))
1632 (defun org-export-handle-include-files ()
1633 "Include the contents of include files, with proper formatting."
1634 (let ((case-fold-search t
)
1635 params file markup lang start end
)
1636 (goto-char (point-min))
1637 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1638 (setq params
(read (concat "(" (match-string 1) ")"))
1639 file
(org-symname-or-string (pop params
))
1640 markup
(org-symname-or-string (pop params
))
1641 lang
(org-symname-or-string (pop params
)))
1642 (delete-region (match-beginning 0) (match-end 0))
1644 (not (file-exists-p file
))
1645 (not (file-readable-p file
)))
1646 (insert (format "CANNOT INCLUDE FILE %s" file
))
1648 (if (equal (downcase markup
) "src")
1649 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1651 (setq start
(format "#+begin_%s\n" markup
)
1652 end
(format "#+end_%s" markup
))))
1653 (insert (or start
""))
1654 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1655 (or (bolp) (newline))
1656 (insert (or end
""))))))
1658 (defun org-symname-or-string (s)
1660 (if s
(symbol-name s
) s
)
1663 ;;; Fontification of code
1664 ;; Currently only for th HTML backend, but who knows....
1665 (defun org-export-replace-src-segments ()
1666 "Replace source code segments with special code for export."
1667 (let ((case-fold-search t
)
1669 (goto-char (point-min))
1670 (while (re-search-forward
1671 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1673 (setq lang
(match-string 1) code
(match-string 2)
1674 trans
(org-export-format-source-code lang code
))
1675 (replace-match trans t t
))))
1677 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1679 (defun org-export-format-source-code (lang code
)
1680 "Format CODE from language LANG and return it formatted for export.
1681 Currently, this only does something for HTML export, for all other
1682 backends, it converts the segment into an EXAMPLE segment."
1686 ;; We are exporting to HTML
1687 (condition-case nil
(require 'htmlize
) (nil t
))
1688 (if (not (fboundp 'htmlize-region-for-paste
))
1690 ;; we do not have htmlize.el, or an old version of it
1692 "htmlize.el 1.34 or later is needed for source code formatting")
1693 (concat "#+BEGIN_EXAMPLE\n" code
1694 (if (string-match "\n\\'" code
) "" "\n")
1696 ;; ok, we are good to go
1697 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1698 (org-inhibit-startup t
)
1699 (org-startup-folded nil
)
1703 ;; Free up the protected stuff
1704 (goto-char (point-min))
1705 (while (re-search-forward "^," nil t
)
1707 (if (functionp mode
)
1710 (font-lock-fontify-buffer)
1711 (org-export-htmlize-region-for-paste
1712 (point-min) (point-max)))))
1713 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1714 (setq htmltext
(replace-match "<pre class=\"src\">"
1716 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1718 ;; This is not HTML, so just make it an example.
1719 (concat "#+BEGIN_EXAMPLE\n" code
1720 (if (string-match "\n\\'" code
) "" "\n")
1721 "#+END_EXAMPLE\n")))))
1725 (defvar org-last-level nil
) ; dynamically scoped variable
1726 (defvar org-min-level nil
) ; dynamically scoped variable
1727 (defvar org-levels-open nil
) ; dynamically scoped parameter
1728 (defvar org-ascii-current-indentation nil
) ; For communication
1731 (defun org-export-as-ascii (arg)
1732 "Export the outline as a pretty ASCII file.
1733 If there is an active region, export only the region.
1734 The prefix ARG specifies how many levels of the outline should become
1735 underlined headlines. The default is 3."
1737 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1738 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1739 (org-infile-export-plist)))
1740 (region-p (org-region-active-p))
1744 (goto-char (region-beginning))
1745 (and (org-at-heading-p)
1746 (>= (org-end-of-subtree t t
) (region-end))))))
1747 (custom-times org-display-custom-times
)
1748 (org-ascii-current-indentation '(0 .
0))
1752 (case-fold-search nil
)
1753 (filename (concat (file-name-as-directory
1754 (org-export-directory :ascii opt-plist
))
1755 (file-name-sans-extension
1757 (org-entry-get (region-beginning)
1758 "EXPORT_FILE_NAME" t
))
1759 (file-name-nondirectory buffer-file-name
)))
1761 (filename (if (equal (file-truename filename
)
1762 (file-truename buffer-file-name
))
1763 (concat filename
".txt")
1765 (buffer (find-file-noselect filename
))
1766 (org-levels-open (make-vector org-level-max nil
))
1767 (odd org-odd-levels-only
)
1768 (date (plist-get opt-plist
:date
))
1769 (author (plist-get opt-plist
:author
))
1770 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1771 (plist-get opt-plist
:title
)
1773 (plist-get opt-plist
:skip-before-1st-heading
))
1774 (org-export-grab-title-from-buffer))
1775 (file-name-sans-extension
1776 (file-name-nondirectory buffer-file-name
))))
1777 (email (plist-get opt-plist
:email
))
1778 (language (plist-get opt-plist
:language
))
1779 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1780 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1785 (if (org-region-active-p) (region-beginning) (point-min))
1786 (if (org-region-active-p) (region-end) (point-max))))
1787 (lines (org-split-string
1788 (org-export-preprocess-string
1791 :skip-before-1st-heading
1792 (plist-get opt-plist
:skip-before-1st-heading
)
1793 :drawers
(plist-get opt-plist
:drawers
)
1794 :verbatim-multiline t
1796 (plist-get opt-plist
:archived-trees
)
1797 :add-text
(plist-get opt-plist
:text
))
1799 thetoc have-headings first-heading-pos
1800 table-open table-buffer
)
1802 (let ((inhibit-read-only t
))
1804 (remove-text-properties (point-min) (point-max)
1805 '(:org-license-to-kill t
))))
1807 (setq org-min-level
(org-get-min-level lines
))
1808 (setq org-last-level org-min-level
)
1809 (org-init-section-numbers)
1811 (find-file-noselect filename
)
1813 (setq lang-words
(or (assoc language org-export-language-setup
)
1814 (assoc "en" org-export-language-setup
)))
1815 (switch-to-buffer-other-window buffer
)
1818 ;; create local variables for all options, to make sure all called
1819 ;; functions get the correct information
1821 (set (make-local-variable (cdr x
))
1822 (plist-get opt-plist
(car x
))))
1823 org-export-plist-vars
)
1824 (org-set-local 'org-odd-levels-only odd
)
1825 (setq umax
(if arg
(prefix-numeric-value arg
)
1826 org-export-headline-levels
))
1827 (setq umax-toc
(if (integerp org-export-with-toc
)
1828 (min org-export-with-toc umax
)
1832 (if title
(org-insert-centered title ?
=))
1834 (if (and (or author email
)
1835 org-export-author-info
)
1836 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1837 (if email
(concat " <" email
">") "")
1841 ((and date
(string-match "%" date
))
1842 (setq date
(format-time-string date
)))
1844 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1846 (if (and date org-export-time-stamp-file
)
1847 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1851 (if org-export-with-toc
1853 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1854 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1855 (mapc '(lambda (line)
1856 (if (string-match org-todo-line-regexp
1858 ;; This is a headline
1860 (setq have-headings t
)
1861 (setq level
(- (match-end 1) (match-beginning 1))
1862 level
(org-tr-level level
)
1863 txt
(match-string 3 line
)
1865 (or (and org-export-mark-todo-in-toc
1867 (not (member (match-string 2 line
)
1868 org-done-keywords
)))
1870 (and org-export-mark-todo-in-toc
1872 (org-search-todo-below
1873 line lines level
))))
1874 (setq txt
(org-html-expand-for-ascii txt
))
1876 (while (string-match org-bracket-link-regexp txt
)
1879 (match-string (if (match-end 2) 3 1) txt
)
1882 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1884 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1886 (setq txt
(replace-match "" t t txt
)))
1887 (if (string-match quote-re0 txt
)
1888 (setq txt
(replace-match "" t t txt
)))
1890 (if org-export-with-section-numbers
1891 (setq txt
(concat (org-section-number level
)
1893 (if (<= level umax-toc
)
1898 (* (max 0 (- level org-min-level
)) 4) ?\
)
1899 (format (if todo
"%s (*)\n" "%s\n") txt
))
1901 (setq org-last-level level
))
1904 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1906 (org-init-section-numbers)
1907 (while (setq line
(pop lines
))
1908 ;; Remove the quoted HTML tags.
1909 (setq line
(org-html-expand-for-ascii line
))
1911 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1912 (setq line
(replace-match "" t t line
)))
1913 ;; Replace internal links
1914 (while (string-match org-bracket-link-regexp line
)
1915 (setq line
(replace-match
1916 (if (match-end 3) "[\\3]" "[\\1]")
1919 (setq line
(org-translate-time line
)))
1921 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1923 (setq first-heading-pos
(or first-heading-pos
(point)))
1924 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1925 txt
(match-string 2 line
))
1926 (org-ascii-level-start level txt umax lines
))
1928 ((and org-export-with-tables
1929 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1930 (if (not table-open
)
1932 (setq table-open t table-buffer nil
))
1934 (setq table-buffer
(cons line table-buffer
))
1935 (when (or (not lines
)
1936 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1938 (setq table-open nil
1939 table-buffer
(nreverse table-buffer
))
1942 (org-fix-indentation x org-ascii-current-indentation
))
1943 (org-format-table-ascii table-buffer
)
1946 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1947 (if (and org-export-with-fixed-width
1948 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1949 (setq line
(replace-match "\\1" nil nil line
)))
1950 (insert line
"\n"))))
1954 ;; insert the table of contents
1956 (goto-char (point-min))
1957 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1959 (goto-char (match-beginning 0))
1961 (goto-char first-heading-pos
))
1962 (mapc 'insert thetoc
)
1963 (or (looking-at "[ \t]*\n[ \t]*\n")
1966 ;; Convert whitespace place holders
1967 (goto-char (point-min))
1969 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1970 (setq end
(next-single-property-change beg
'org-whitespace
))
1972 (delete-region beg end
)
1973 (insert (make-string (- end beg
) ?\
))))
1976 ;; remove display and invisible chars
1978 (goto-char (point-min))
1979 (while (setq beg
(next-single-property-change (point) 'display
))
1980 (setq end
(next-single-property-change beg
'display
))
1981 (delete-region beg end
)
1984 (goto-char (point-min))
1985 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1986 (setq end
(next-single-property-change beg
'org-cwidth
))
1987 (delete-region beg end
)
1989 (goto-char (point-min))))
1991 (defun org-export-ascii-clean-string ()
1992 "Do extra work for ASCII export"
1993 (goto-char (point-min))
1994 (while (re-search-forward org-verbatim-re nil t
)
1995 (goto-char (match-end 2))
1996 (backward-delete-char 1) (insert "'")
1997 (goto-char (match-beginning 2))
1998 (delete-char 1) (insert "`")
1999 (goto-char (match-end 2))))
2001 (defun org-search-todo-below (line lines level
)
2002 "Search the subtree below LINE for any TODO entries."
2003 (let ((rest (cdr (memq line lines
)))
2004 (re org-todo-line-regexp
)
2007 (while (setq line
(pop rest
))
2008 (if (string-match re line
)
2010 (setq lv
(- (match-end 1) (match-beginning 1))
2011 todo
(and (match-beginning 2)
2012 (not (member (match-string 2 line
)
2013 org-done-keywords
))))
2015 (if (<= lv level
) (throw 'exit nil
))
2016 (if todo
(throw 'exit t
))))))))
2018 (defun org-html-expand-for-ascii (line)
2019 "Handle quoted HTML for ASCII export."
2020 (if org-export-html-expand
2021 (while (string-match "@<[^<>\n]*>" line
)
2022 ;; We just remove the tags for now.
2023 (setq line
(replace-match "" nil nil line
))))
2026 (defun org-insert-centered (s &optional underline
)
2027 "Insert the string S centered and underline it with character UNDERLINE."
2028 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2029 (insert (make-string ind ?\
) s
"\n")
2031 (insert (make-string ind ?\
)
2032 (make-string (string-width s
) underline
)
2035 (defun org-ascii-level-start (level title umax
&optional lines
)
2036 "Insert a new level in ASCII export."
2037 (let (char (n (- level umax
1)) (ind 0))
2040 (insert (make-string (* 2 n
) ?\
)
2041 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2042 org-export-ascii-bullets
))
2044 ;; find the indentation of the next non-empty line
2047 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2048 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2049 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2051 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2052 (if (or (not (equal (char-before) ?
\n))
2053 (not (equal (char-before (1- (point))) ?
\n)))
2055 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2056 (unless org-export-with-tags
2057 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2058 (setq title
(replace-match "" t t title
))))
2059 (if org-export-with-section-numbers
2060 (setq title
(concat (org-section-number level
) " " title
)))
2061 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2062 (setq org-ascii-current-indentation
'(0 .
0)))))
2065 (defun org-export-visible (type arg
)
2066 "Create a copy of the visible part of the current buffer, and export it.
2067 The copy is created in a temporary buffer and removed after use.
2068 TYPE is the final key (as a string) that also select the export command in
2069 the `C-c C-e' export dispatcher.
2070 As a special case, if the you type SPC at the prompt, the temporary
2071 org-mode file will not be removed but presented to you so that you can
2072 continue to use it. The prefix arg ARG is passed through to the exporting
2076 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2077 (read-char-exclusive))
2078 current-prefix-arg
))
2079 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2080 (error "Invalid export key"))
2081 (let* ((binding (cdr (assoc type
2082 '((?a . org-export-as-ascii
)
2083 (?\C-a . org-export-as-ascii
)
2084 (?b . org-export-as-html-and-open
)
2085 (?\C-b . org-export-as-html-and-open
)
2086 (?h . org-export-as-html
)
2087 (?H . org-export-as-html-to-buffer
)
2088 (?R . org-export-region-as-html
)
2089 (?x . org-export-as-xoxo
)))))
2090 (keepp (equal type ?\
))
2091 (file buffer-file-name
)
2092 (buffer (get-buffer-create "*Org Export Visible*"))
2094 ;; Need to hack the drawers here.
2096 (goto-char (point-min))
2097 (while (re-search-forward org-drawer-regexp nil t
)
2098 (goto-char (match-beginning 1))
2099 (or (org-invisible-p) (org-flag-drawer nil
))))
2100 (with-current-buffer buffer
(erase-buffer))
2102 (setq s
(goto-char (point-min)))
2103 (while (not (= (point) (point-max)))
2104 (goto-char (org-find-invisible))
2105 (append-to-buffer buffer s
(point))
2106 (setq s
(goto-char (org-find-visible))))
2107 (org-cycle-hide-drawers 'all
)
2108 (goto-char (point-min))
2110 ;; Copy all comment lines to the end, to make sure #+ settings are
2111 ;; still available for the second export step. Kind of a hack, but
2112 ;; does do the trick.
2113 (if (looking-at "#[^\r\n]*")
2114 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2115 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2116 (append-to-buffer buffer
(1+ (match-beginning 0))
2117 (min (point-max) (1+ (match-end 0))))))
2119 (let ((buffer-file-name file
)
2120 (org-inhibit-startup t
))
2123 (unless keepp
(funcall binding arg
))))
2125 (kill-buffer buffer
)
2126 (switch-to-buffer-other-window buffer
)
2127 (goto-char (point-min)))))
2129 (defun org-find-visible ()
2131 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2132 (get-char-property s
'invisible
)))
2134 (defun org-find-invisible ()
2136 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2137 (not (get-char-property s
'invisible
))))
2142 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2143 (defun org-get-current-options ()
2144 "Return a string with current options as keyword options.
2145 Does include HTML export options as well as TODO and CATEGORY stuff."
2146 (require 'org-archive
)
2153 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2154 #+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
2161 #+PRIORITIES: %c %c %c
2163 #+STARTUP: %s %s %s %s %s
2168 (buffer-name) (user-full-name) user-mail-address
2169 (format-time-string (car org-time-stamp-formats
))
2170 org-export-default-language
2171 org-export-headline-levels
2172 org-export-with-section-numbers
2174 org-export-preserve-breaks
2175 org-export-html-expand
2176 org-export-with-fixed-width
2177 org-export-with-tables
2178 org-export-with-sub-superscripts
2179 org-export-with-special-strings
2180 org-export-with-footnotes
2181 org-export-with-emphasize
2182 org-export-with-TeX-macros
2183 org-export-with-LaTeX-fragments
2184 org-export-skip-text-before-1st-heading
2185 org-export-with-drawers
2186 org-export-with-tags
2187 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2188 org-export-html-link-up
2189 org-export-html-link-home
2190 (file-name-nondirectory buffer-file-name
)
2191 "TODO FEEDBACK VERIFY DONE"
2192 "Me Jason Marie DONE"
2193 org-highest-priority org-lowest-priority org-default-priority
2194 (mapconcat 'identity org-drawers
" ")
2195 (cdr (assoc org-startup-folded
2196 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2197 (if org-odd-levels-only
"odd" "oddeven")
2198 (if org-hide-leading-stars
"hidestars" "showstars")
2199 (if org-startup-align-all-tables
"align" "noalign")
2200 (cond ((eq org-log-done t
) "logdone")
2201 ((equal org-log-done
'note
) "lognotedone")
2202 ((not org-log-done
) "nologdone"))
2203 (or (mapconcat (lambda (x)
2205 ((equal '(:startgroup
) x
) "{")
2206 ((equal '(:endgroup
) x
) "}")
2207 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2209 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2210 org-archive-location
2211 "org file:~/org/%s.org"
2215 (defun org-insert-export-options-template ()
2216 "Insert into the buffer a template with information for exporting."
2218 (if (not (bolp)) (newline))
2219 (let ((s (org-get-current-options)))
2220 (and (string-match "#\\+CATEGORY" s
)
2221 (setq s
(substring s
0 (match-beginning 0))))
2225 (defun org-export-as-html-and-open (arg)
2226 "Export the outline as HTML and immediately open it with a browser.
2227 If there is an active region, export only the region.
2228 The prefix ARG specifies how many levels of the outline should become
2229 headlines. The default is 3. Lower levels will become bulleted lists."
2231 (org-export-as-html arg
'hidden
)
2232 (org-open-file buffer-file-name
))
2235 (defun org-export-as-html-batch ()
2236 "Call `org-export-as-html', may be used in batch processing as
2238 --load=$HOME/lib/emacs/org.el
2239 --eval \"(setq org-export-headline-levels 2)\"
2240 --visit=MyFile --funcall org-export-as-html-batch"
2241 (org-export-as-html org-export-headline-levels
'hidden
))
2244 (defun org-export-as-html-to-buffer (arg)
2245 "Call `org-exort-as-html` with output to a temporary buffer.
2246 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2248 (org-export-as-html arg nil nil
"*Org HTML Export*")
2249 (switch-to-buffer-other-window "*Org HTML Export*"))
2252 (defun org-replace-region-by-html (beg end
)
2253 "Assume the current region has org-mode syntax, and convert it to HTML.
2254 This can be used in any buffer. For example, you could write an
2255 itemized list in org-mode syntax in an HTML buffer and then use this
2256 command to convert it."
2258 (let (reg html buf pop-up-frames
)
2259 (save-window-excursion
2261 (setq html
(org-export-region-as-html
2263 (setq reg
(buffer-substring beg end
)
2264 buf
(get-buffer-create "*Org tmp*"))
2265 (with-current-buffer buf
2269 (setq html
(org-export-region-as-html
2270 (point-min) (point-max) t
'string
)))
2272 (delete-region beg end
)
2276 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2277 "Convert region from BEG to END in org-mode buffer to HTML.
2278 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2279 contents, and only produce the region of converted text, useful for
2280 cut-and-paste operations.
2281 If BUFFER is a buffer or a string, use/create that buffer as a target
2282 of the converted HTML. If BUFFER is the symbol `string', return the
2283 produced HTML as a string and leave not buffer behind. For example,
2284 a Lisp program could call this function in the following way:
2286 (setq html (org-export-region-as-html beg end t 'string))
2288 When called interactively, the output buffer is selected, and shown
2289 in a window. A non-interactive call will only return the buffer."
2290 (interactive "r\nP")
2291 (when (interactive-p)
2292 (setq buffer
"*Org HTML Export*"))
2293 (let ((transient-mark-mode t
) (zmacs-regions t
)
2296 (set-mark (point)) ;; to activate the region
2298 (setq rtn
(org-export-as-html
2301 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2302 (if (and (interactive-p) (bufferp rtn
))
2303 (switch-to-buffer-other-window rtn
)
2306 (defvar html-table-tag nil
) ; dynamically scoped into this.
2308 (defun org-export-as-html (arg &optional hidden ext-plist
2309 to-buffer body-only pub-dir
)
2310 "Export the outline as a pretty HTML file.
2311 If there is an active region, export only the region. The prefix
2312 ARG specifies how many levels of the outline should become
2313 headlines. The default is 3. Lower levels will become bulleted
2314 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2315 EXT-PLIST is a property list with external parameters overriding
2316 org-mode's default settings, but still inferior to file-local
2317 settings. When TO-BUFFER is non-nil, create a buffer with that
2318 name and export to that buffer. If TO-BUFFER is the symbol
2319 `string', don't leave any buffer behind but just return the
2320 resulting HTML as a string. When BODY-ONLY is set, don't produce
2321 the file header and footer, simply return the content of
2322 <body>...</body>, without even the body tags themselves. When
2323 PUB-DIR is set, use this as the publishing directory."
2326 ;; Make sure we have a file name when we need it.
2327 (when (and (not (or to-buffer body-only
))
2328 (not buffer-file-name
))
2329 (if (buffer-base-buffer)
2330 (org-set-local 'buffer-file-name
2331 (with-current-buffer (buffer-base-buffer)
2333 (error "Need a file name to be able to export.")))
2335 (message "Exporting...")
2336 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2337 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2338 (setq-default org-done-keywords org-done-keywords
)
2339 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2341 (org-export-process-option-filters
2342 (org-combine-plists (org-default-export-plist)
2344 (org-infile-export-plist))))
2346 (style (plist-get opt-plist
:style
))
2347 (html-extension (plist-get opt-plist
:html-extension
))
2348 (link-validate (plist-get opt-plist
:link-validation-function
))
2349 valid thetoc have-headings first-heading-pos
2350 (odd org-odd-levels-only
)
2351 (region-p (org-region-active-p))
2355 (goto-char (region-beginning))
2356 (and (org-at-heading-p)
2357 (>= (org-end-of-subtree t t
) (region-end))))))
2358 ;; The following two are dynamically scoped into other
2360 (org-current-export-dir
2361 (or pub-dir
(org-export-directory :html opt-plist
)))
2362 (org-current-export-file buffer-file-name
)
2363 (level 0) (line "") (origline "") txt todo
2366 (filename (if to-buffer nil
2369 (file-name-sans-extension
2371 (org-entry-get (region-beginning)
2372 "EXPORT_FILE_NAME" t
))
2373 (file-name-nondirectory buffer-file-name
)))
2375 (file-name-as-directory
2376 (or pub-dir
(org-export-directory :html opt-plist
))))))
2377 (current-dir (if buffer-file-name
2378 (file-name-directory buffer-file-name
)
2380 (buffer (if to-buffer
2382 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2383 (t (get-buffer-create to-buffer
)))
2384 (find-file-noselect filename
)))
2385 (org-levels-open (make-vector org-level-max nil
))
2386 (date (plist-get opt-plist
:date
))
2387 (author (plist-get opt-plist
:author
))
2388 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2389 (plist-get opt-plist
:title
)
2391 (plist-get opt-plist
:skip-before-1st-heading
))
2392 (org-export-grab-title-from-buffer))
2393 (and buffer-file-name
2394 (file-name-sans-extension
2395 (file-name-nondirectory buffer-file-name
)))
2397 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2398 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2399 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2403 (local-list-type nil
)
2404 (local-list-indent nil
)
2405 (llt org-plain-list-ordered-item-terminator
)
2406 (email (plist-get opt-plist
:email
))
2407 (language (plist-get opt-plist
:language
))
2411 (coding-system (and (boundp 'buffer-file-coding-system
)
2412 buffer-file-coding-system
))
2413 (coding-system-for-write (or org-export-html-coding-system
2415 (save-buffer-coding-system (or org-export-html-coding-system
2417 (charset (and coding-system-for-write
2418 (fboundp 'coding-system-get
)
2419 (coding-system-get coding-system-for-write
2423 (if region-p
(region-beginning) (point-min))
2424 (if region-p
(region-end) (point-max))))
2427 (org-export-preprocess-string
2431 :skip-before-1st-heading
2432 (plist-get opt-plist
:skip-before-1st-heading
)
2433 :drawers
(plist-get opt-plist
:drawers
)
2435 (plist-get opt-plist
:archived-trees
)
2437 (plist-get opt-plist
:text
)
2439 (plist-get opt-plist
:LaTeX-fragments
))
2442 table-buffer table-orig-buffer
2443 ind item-type starter didclose
2444 rpl path desc descp desc1 desc2 link
2445 snumber fnc item-tag
2448 (let ((inhibit-read-only t
))
2450 (remove-text-properties (point-min) (point-max)
2451 '(:org-license-to-kill t
))))
2453 (message "Exporting...")
2455 (setq org-min-level
(org-get-min-level lines
))
2456 (setq org-last-level org-min-level
)
2457 (org-init-section-numbers)
2460 ((and date
(string-match "%" date
))
2461 (setq date
(format-time-string date
)))
2463 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2465 ;; Get the language-dependent settings
2466 (setq lang-words
(or (assoc language org-export-language-setup
)
2467 (assoc "en" org-export-language-setup
)))
2469 ;; Switch to the output buffer
2471 (let ((inhibit-read-only t
)) (erase-buffer))
2474 (and (fboundp 'set-buffer-file-coding-system
)
2475 (set-buffer-file-coding-system coding-system-for-write
))
2477 (let ((case-fold-search nil
)
2478 (org-odd-levels-only odd
))
2479 ;; create local variables for all options, to make sure all called
2480 ;; functions get the correct information
2482 (set (make-local-variable (cdr x
))
2483 (plist-get opt-plist
(car x
))))
2484 org-export-plist-vars
)
2485 (setq umax
(if arg
(prefix-numeric-value arg
)
2486 org-export-headline-levels
))
2487 (setq umax-toc
(if (integerp org-export-with-toc
)
2488 (min org-export-with-toc umax
)
2493 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2494 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2495 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2496 lang=\"%s\" xml:lang=\"%s\">
2499 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2500 <meta name=\"generator\" content=\"Org-mode\"/>
2501 <meta name=\"generated\" content=\"%s\"/>
2502 <meta name=\"author\" content=\"%s\"/>
2506 language language
(org-html-expand title
)
2507 (or charset
"iso-8859-1") date author style
))
2509 (insert (or (plist-get opt-plist
:preamble
) ""))
2511 (when (plist-get opt-plist
:auto-preamble
)
2512 (if title
(insert (format org-export-html-title-format
2513 (org-html-expand title
))))))
2515 (if (and org-export-with-toc
(not body-only
))
2517 (push (format "<h%d>%s</h%d>\n"
2518 org-export-html-toplevel-hlevel
2520 org-export-html-toplevel-hlevel
)
2522 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2523 (push "<ul>\n<li>" thetoc
)
2525 (mapcar '(lambda (line)
2526 (if (string-match org-todo-line-regexp line
)
2527 ;; This is a headline
2529 (setq have-headings t
)
2530 (setq level
(- (match-end 1) (match-beginning 1))
2531 level
(org-tr-level level
)
2532 txt
(save-match-data
2534 (org-export-cleanup-toc-line
2535 (match-string 3 line
))))
2537 (or (and org-export-mark-todo-in-toc
2539 (not (member (match-string 2 line
)
2540 org-done-keywords
)))
2542 (and org-export-mark-todo-in-toc
2544 (org-search-todo-below
2545 line lines level
))))
2547 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2548 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2549 (if (string-match quote-re0 txt
)
2550 (setq txt
(replace-match "" t t txt
)))
2551 (setq snumber
(org-section-number level
))
2552 (if org-export-with-section-numbers
2553 (setq txt
(concat snumber
" " txt
)))
2554 (if (<= level
(max umax umax-toc
))
2555 (setq head-count
(+ head-count
1)))
2556 (if (<= level umax-toc
)
2558 (if (> level org-last-level
)
2560 (setq cnt
(- level org-last-level
))
2561 (while (>= (setq cnt
(1- cnt
)) 0)
2562 (push "\n<ul>\n<li>" thetoc
))
2563 (push "\n" thetoc
)))
2564 (if (< level org-last-level
)
2566 (setq cnt
(- org-last-level level
))
2567 (while (>= (setq cnt
(1- cnt
)) 0)
2568 (push "</li>\n</ul>" thetoc
))
2569 (push "\n" thetoc
)))
2570 ;; Check for targets
2571 (while (string-match org-any-target-regexp line
)
2572 (setq line
(replace-match
2573 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2575 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2576 (setq txt
(replace-match "" t t txt
)))
2580 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2581 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2582 snumber txt
) thetoc
)
2584 (setq org-last-level level
))
2588 (while (> org-last-level
(1- org-min-level
))
2589 (setq org-last-level
(1- org-last-level
))
2590 (push "</li>\n</ul>\n" thetoc
))
2591 (push "</div>\n" thetoc
)
2592 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2595 (org-init-section-numbers)
2597 (while (setq line
(pop lines
) origline line
)
2600 ;; end of quote section?
2601 (when (and inquote
(string-match "^\\*+ " line
))
2604 ;; inside a quote section?
2606 (insert (org-html-protect line
) "\n")
2607 (throw 'nextline nil
))
2610 (when (and org-export-with-fixed-width
2611 (string-match "^[ \t]*:\\(.*\\)" line
))
2615 (insert (org-html-protect (match-string 1 line
)) "\n")
2617 (not (string-match "^[ \t]*\\(:.*\\)"
2620 (insert "</pre>\n"))
2621 (throw 'nextline nil
))
2624 (when (get-text-property 0 'org-protected line
)
2626 (when (re-search-backward
2627 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2628 (setq par
(match-string 1))
2629 (replace-match "\\2\n"))
2632 (not (string-match "^[ \t]*:" (car lines
)))
2633 (or (= (length (car lines
)) 0)
2634 (get-text-property 0 'org-protected
(car lines
))))
2635 (insert (pop lines
) "\n"))
2636 (and par
(insert "<p>\n")))
2637 (throw 'nextline nil
))
2640 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2641 (insert "\n<hr/>\n")
2642 (throw 'nextline nil
))
2644 ;; Blockquotes and verse
2645 (when (equal "ORG-BLOCKQUOTE-START" line
)
2646 (insert "<blockquote>\n<p>\n")
2647 (throw 'nextline nil
))
2648 (when (equal "ORG-BLOCKQUOTE-END" line
)
2649 (insert "</p>\n</blockquote>\n")
2650 (throw 'nextline nil
))
2651 (when (equal "ORG-VERSE-START" line
)
2652 (insert "<verse>\n<p>\n")
2653 (throw 'nextline nil
))
2654 (when (equal "ORG-VERSE-END" line
)
2655 (insert "</p>\n</verse>\n")
2656 (throw 'nextline nil
))
2658 ;; make targets to anchors
2659 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2662 (setq line
(replace-match
2663 (concat "@<a name=\""
2664 (org-solidify-link-text (match-string 1 line
))
2667 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2668 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2669 (setq line
(replace-match
2670 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2671 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2674 (setq line
(replace-match
2675 (concat "@<a name=\""
2676 (org-solidify-link-text (match-string 1 line
))
2677 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2680 (setq line
(org-html-handle-time-stamps line
))
2682 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2683 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2684 ;; Also handle sub_superscripts and checkboxes
2685 (or (string-match org-table-hline-regexp line
)
2686 (setq line
(org-html-expand line
)))
2690 (while (string-match org-bracket-link-analytic-regexp line start
)
2691 (setq start
(match-beginning 0))
2692 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2693 (setq path
(match-string 3 line
))
2694 (setq desc1
(if (match-end 5) (match-string 5 line
))
2695 desc2
(if (match-end 2) (concat type
":" path
) path
)
2696 descp
(and desc1
(not (equal desc1 desc2
)))
2697 desc
(or desc1 desc2
))
2698 ;; Make an image out of the description if that is so wanted
2699 (when (and descp
(org-file-image-p desc
))
2701 (if (string-match "^file:" desc
)
2702 (setq desc
(substring desc
(match-end 0)))))
2703 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2704 ;; FIXME: do we need to unescape here somewhere?
2706 ((equal type
"internal")
2710 (org-solidify-link-text
2711 (save-match-data (org-link-unescape path
)) nil
)
2712 "\">" desc
"</a>")))
2713 ((member type
'("http" "https"))
2714 ;; standard URL, just check if we need to inline an image
2715 (if (and (or (eq t org-export-html-inline-images
)
2716 (and org-export-html-inline-images
(not descp
)))
2717 (org-file-image-p path
))
2718 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2719 (setq link
(concat type
":" path
))
2720 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2721 ((member type
'("ftp" "mailto" "news"))
2723 (setq link
(concat type
":" path
))
2724 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2725 ((string= type
"file")
2727 (let* ((filename path
)
2728 (abs-p (file-name-absolute-p filename
))
2729 thefile file-is-image-p search
)
2731 (if (string-match "::\\(.*\\)" filename
)
2732 (setq search
(match-string 1 filename
)
2733 filename
(replace-match "" t nil filename
)))
2735 (if (functionp link-validate
)
2736 (funcall link-validate filename current-dir
)
2738 (setq file-is-image-p
(org-file-image-p filename
))
2739 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2740 (when (and org-export-html-link-org-files-as-html
2741 (string-match "\\.org$" thefile
))
2742 (setq thefile
(concat (substring thefile
0
2743 (match-beginning 0))
2744 "." html-extension
))
2746 ;; make sure this is can be used as target search
2747 (not (string-match "^[0-9]*$" search
))
2748 (not (string-match "^\\*" search
))
2749 (not (string-match "^/.*/$" search
)))
2750 (setq thefile
(concat thefile
"#"
2751 (org-solidify-link-text
2752 (org-link-unescape search
)))))
2753 (when (string-match "^file:" desc
)
2754 (setq desc
(replace-match "" t t desc
))
2755 (if (string-match "\\.org$" desc
)
2756 (setq desc
(replace-match "" t t desc
))))))
2757 (setq rpl
(if (and file-is-image-p
2758 (or (eq t org-export-html-inline-images
)
2759 (and org-export-html-inline-images
2761 (concat "<img src=\"" thefile
"\"/>")
2762 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2763 (if (not valid
) (setq rpl desc
))))
2765 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2768 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2771 ;; just publish the path, as default
2772 (setq rpl
(concat "<i><" type
":"
2773 (save-match-data (org-link-unescape path
))
2775 (setq line
(replace-match rpl t t line
)
2776 start
(+ start
(length rpl
))))
2779 (if (and (string-match org-todo-line-regexp line
)
2780 (match-beginning 2))
2783 (concat (substring line
0 (match-beginning 2))
2785 (if (member (match-string 2 line
)
2788 "\">" (match-string 2 line
)
2789 "</span>" (substring line
(match-end 2)))))
2791 ;; Does this contain a reference to a footnote?
2792 (when org-export-with-footnotes
2794 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2795 (if (get-text-property (match-beginning 2) 'org-protected line
)
2796 (setq start
(match-end 2))
2797 (let ((n (match-string 2 line
)))
2801 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2802 (match-string 1 line
) n n n
)
2806 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2807 ;; This is a headline
2808 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2809 txt
(match-string 2 line
))
2810 (if (string-match quote-re0 txt
)
2811 (setq txt
(replace-match "" t t txt
)))
2812 (if (<= level
(max umax umax-toc
))
2813 (setq head-count
(+ head-count
1)))
2815 ;; Close any local lists before inserting a new header line
2816 (while local-list-type
2817 (org-close-li (car local-list-type
))
2818 (insert (format "</%sl>\n" (car local-list-type
)))
2819 (pop local-list-type
))
2820 (setq local-list-indent nil
2822 (setq first-heading-pos
(or first-heading-pos
(point)))
2823 (org-html-level-start level txt umax
2824 (and org-export-with-toc
(<= level umax
))
2827 (when (string-match quote-re line
)
2831 ((and org-export-with-tables
2832 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2833 (if (not table-open
)
2835 (setq table-open t table-buffer nil table-orig-buffer nil
))
2837 (setq table-buffer
(cons line table-buffer
)
2838 table-orig-buffer
(cons origline table-orig-buffer
))
2839 (when (or (not lines
)
2840 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2842 (setq table-open nil
2843 table-buffer
(nreverse table-buffer
)
2844 table-orig-buffer
(nreverse table-orig-buffer
))
2845 (org-close-par-maybe)
2846 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2851 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2852 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2853 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2854 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2856 (setq ind
(org-get-string-indentation line
)
2857 item-type
(if (match-beginning 4) "o" "u")
2858 starter
(if (match-beginning 2)
2859 (substring (match-string 2 line
) 0 -
1))
2860 line
(substring line
(match-beginning 5))
2862 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2864 item-tag
(match-string 1 line
)
2865 line
(substring line
(match-end 0))))
2866 (when (and (not (equal item-type
"d"))
2867 (not (string-match "[^ \t]" line
)))
2868 ;; empty line. Pretend indentation is large.
2869 (setq ind
(if org-empty-line-terminates-plain-lists
2871 (1+ (or (car local-list-indent
) 1)))))
2873 (while (and in-local-list
2874 (or (and (= ind
(car local-list-indent
))
2876 (< ind
(car local-list-indent
))))
2878 (org-close-li (car local-list-type
))
2879 (insert (format "</%sl>\n" (car local-list-type
)))
2880 (pop local-list-type
) (pop local-list-indent
)
2881 (setq in-local-list local-list-indent
))
2884 (or (not in-local-list
)
2885 (> ind
(car local-list-indent
))))
2886 ;; Start new (level of) list
2887 (org-close-par-maybe)
2889 ((equal item-type
"u") "<ul>\n<li>\n")
2890 ((equal item-type
"o") "<ol>\n<li>\n")
2891 ((equal item-type
"d")
2892 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2893 (push item-type local-list-type
)
2894 (push ind local-list-indent
)
2895 (setq in-local-list t
))
2897 ;; continue current list
2898 (org-close-li (car local-list-type
))
2900 ((equal (car local-list-type
) "d")
2901 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2904 ;; we did close a list, normal text follows: need <p>
2906 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2909 (if (equal (match-string 1 line
) "X")
2911 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2914 ;; Empty lines start a new paragraph. If hand-formatted lists
2915 ;; are not fully interpreted, lines starting with "-", "+", "*"
2916 ;; also start a new paragraph.
2917 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2919 ;; Is this the start of a footnote?
2920 (when org-export-with-footnotes
2921 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2922 (org-close-par-maybe)
2923 (let ((n (match-string 1 line
)))
2924 (setq line
(replace-match
2925 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2927 ;; Check if the line break needs to be conserved
2929 ((string-match "\\\\\\\\[ \t]*$" line
)
2930 (setq line
(replace-match "<br/>" t t line
)))
2931 (org-export-preserve-breaks
2932 (setq line
(concat line
"<br/>"))))
2934 (insert line
"\n")))))
2936 ;; Properly close all local lists and other lists
2937 (when inquote
(insert "</pre>\n"))
2939 ;; Close any local lists before inserting a new header line
2940 (while local-list-type
2941 (org-close-li (car local-list-type
))
2942 (insert (format "</%sl>\n" (car local-list-type
)))
2943 (pop local-list-type
))
2944 (setq local-list-indent nil
2946 (org-html-level-start 1 nil umax
2947 (and org-export-with-toc
(<= level umax
))
2949 ;; the </div> to lose the last text-... div.
2953 (when (plist-get opt-plist
:auto-postamble
)
2954 (insert "<div id=\"postamble\">")
2955 (when (and org-export-author-info author
)
2956 (insert "<p class=\"author\"> "
2957 (nth 1 lang-words
) ": " author
"\n")
2959 (if (listp (split-string email
",+ *"))
2961 (insert "<a href=\"mailto:" e
"\"><"
2963 (split-string email
",+ *"))
2964 (insert "<a href=\"mailto:" email
"\"><"
2965 email
"></a>\n")))
2967 (when (and date org-export-time-stamp-file
)
2968 (insert "<p class=\"date\"> "
2969 (nth 2 lang-words
) ": "
2973 (if org-export-html-with-timestamp
2974 (insert org-export-html-html-helper-timestamp
))
2975 (insert (or (plist-get opt-plist
:postamble
) ""))
2976 (insert "</body>\n</html>\n"))
2979 (if (eq major-mode default-major-mode
) (html-mode))
2981 ;; insert the table of contents
2982 (goto-char (point-min))
2984 (if (or (re-search-forward
2985 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2987 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2989 (goto-char (match-beginning 0))
2991 (goto-char first-heading-pos
)
2992 (when (looking-at "\\s-*</p>")
2993 (goto-char (match-end 0))
2995 (insert "<div id=\"table-of-contents\">\n")
2996 (mapc 'insert thetoc
)
2997 (insert "</div>\n"))
2998 ;; remove empty paragraphs and lists
2999 (goto-char (point-min))
3000 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3002 (goto-char (point-min))
3003 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3005 (goto-char (point-min))
3006 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3008 ;; Convert whitespace place holders
3009 (goto-char (point-min))
3011 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3012 (setq n
(get-text-property beg
'org-whitespace
)
3013 end
(next-single-property-change beg
'org-whitespace
))
3015 (delete-region beg end
)
3016 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3017 (make-string n ?x
)))))
3018 (or to-buffer
(save-buffer))
3019 (goto-char (point-min))
3020 (message "Exporting... done")
3021 (if (eq to-buffer
'string
)
3022 (prog1 (buffer-substring (point-min) (point-max))
3023 (kill-buffer (current-buffer)))
3024 (current-buffer)))))
3026 (defvar org-table-colgroup-info nil
)
3027 (defun org-format-table-ascii (lines)
3028 "Format a table for ascii export."
3030 (setq lines
(org-split-string lines
"\n")))
3031 (if (not (string-match "^[ \t]*|" (car lines
)))
3032 ;; Table made by table.el - test for spanning
3035 ;; A normal org table
3036 ;; Get rid of hlines at beginning and end
3037 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3038 (setq lines
(nreverse lines
))
3039 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3040 (setq lines
(nreverse lines
))
3041 (when org-export-table-remove-special-lines
3042 ;; Check if the table has a marking column. If yes remove the
3043 ;; column and the special lines
3044 (setq lines
(org-table-clean-before-export lines
)))
3045 ;; Get rid of the vertical lines except for grouping
3046 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3048 (while (setq line
(pop lines
))
3049 (if (string-match org-table-hline-regexp line
)
3050 (and (string-match "|\\(.*\\)|" line
)
3051 (setq line
(replace-match " \\1" t nil line
)))
3052 (setq start
0 vl1 vl
)
3053 (while (string-match "|" line start
)
3054 (setq start
(match-end 0))
3055 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3059 (defun org-colgroup-info-to-vline-list (info)
3062 (setq last new new
(pop info
))
3063 (if (or (memq last
'(:end
:startend
))
3064 (memq new
'(:start
:startend
)))
3067 (setq vl
(nreverse vl
))
3068 (and vl
(setcar vl nil
))
3071 (defvar org-table-number-regexp
) ; defined in org-table.el
3072 (defun org-format-table-html (lines olines
)
3073 "Find out which HTML converter to use and return the HTML code."
3075 (setq lines
(org-split-string lines
"\n")))
3076 (if (string-match "^[ \t]*|" (car lines
))
3077 ;; A normal org table
3078 (org-format-org-table-html lines
)
3079 ;; Table made by table.el - test for spanning
3080 (let* ((hlines (delq nil
(mapcar
3082 (if (string-match "^[ \t]*\\+-" x
) x
3085 (first (car hlines
))
3086 (ll (and (string-match "\\S-+" first
)
3087 (match-string 0 first
)))
3088 (re (concat "^[ \t]*" (regexp-quote ll
)))
3089 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3091 (if (and (not spanning
)
3092 (not org-export-prefer-native-exporter-for-tables
))
3093 ;; We can use my own converter with HTML conversions
3094 (org-format-table-table-html lines
)
3095 ;; Need to use the code generator in table.el, with the original text.
3096 (org-format-table-table-html-using-table-generate-source olines
)))))
3098 (defvar org-table-number-fraction
) ; defined in org-table.el
3099 (defun org-format-org-table-html (lines &optional splice
)
3100 "Format a table into HTML."
3101 (require 'org-table
)
3102 ;; Get rid of hlines at beginning and end
3103 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3104 (setq lines
(nreverse lines
))
3105 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3106 (setq lines
(nreverse lines
))
3107 (when org-export-table-remove-special-lines
3108 ;; Check if the table has a marking column. If yes remove the
3109 ;; column and the special lines
3110 (setq lines
(org-table-clean-before-export lines
)))
3112 (let ((head (and org-export-highlight-first-table-line
3114 (lambda (x) (string-match "^[ \t]*|-" x
))
3117 tbopen line fields html gr colgropen
)
3118 (if splice
(setq head nil
))
3119 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3121 (while (setq line
(pop lines
))
3123 (if (string-match "^[ \t]*|-" line
)
3126 (push (if head
"</thead>" "</tbody>") html
)
3127 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3128 (setq head nil
) ;; head ends here, first time around
3130 (throw 'next-line t
)))
3131 ;; Break the line into fields
3132 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3133 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3134 (setq nlines
(1+ nlines
) i -
1)
3135 (push (concat "<tr>"
3139 (if (and (< i nlines
)
3140 (string-match org-table-number-regexp x
))
3141 (incf (aref fnum i
)))
3143 (concat (car org-export-table-header-tags
) x
3144 (cdr org-export-table-header-tags
))
3145 (concat (car org-export-table-data-tags
) x
3146 (cdr org-export-table-data-tags
))))
3150 (unless splice
(if tbopen
(push "</tbody>" html
)))
3151 (unless splice
(push "</table>\n" html
))
3152 (setq html
(nreverse html
))
3154 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3157 (setq gr
(pop org-table-colgroup-info
))
3158 (format "%s<col align=\"%s\"></col>%s"
3159 (if (memq gr
'(:start
:startend
))
3161 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3164 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3166 (if (memq gr
'(:end
:startend
))
3167 (progn (setq colgropen nil
) "</colgroup>")
3171 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3172 (push html-table-tag html
))
3173 (concat (mapconcat 'identity html
"\n") "\n")))
3175 (defun org-table-clean-before-export (lines)
3176 "Check if the table has a marking column.
3177 If yes remove the column and the special lines."
3178 (setq org-table-colgroup-info nil
)
3181 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3182 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3185 (setq org-table-clean-did-remove-column nil
)
3190 ((string-match "^[ \t]*| */ *|" x
)
3191 (setq org-table-colgroup-info
3193 (cond ((member x
'("<" "<")) :start
)
3194 ((member x
'(">" ">")) :end
)
3195 ((member x
'("<>" "<>")) :startend
)
3197 (org-split-string x
"[ \t]*|[ \t]*")))
3201 (setq org-table-clean-did-remove-column t
)
3206 ((string-match "^[ \t]*| */ *|" x
)
3207 (setq org-table-colgroup-info
3209 (cond ((member x
'("<" "<")) :start
)
3210 ((member x
'(">" ">")) :end
)
3211 ((member x
'("<>" "<>")) :startend
)
3213 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3215 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3216 nil
) ; ignore this line
3217 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3218 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3219 ;; remove the first column
3220 (replace-match "\\1|" t nil x
))))
3223 (defun org-format-table-table-html (lines)
3224 "Format a table generated by table.el into HTML.
3225 This conversion does *not* use `table-generate-source' from table.el.
3226 This has the advantage that Org-mode's HTML conversions can be used.
3227 But it has the disadvantage, that no cell- or row-spanning is allowed."
3228 (let (line field-buffer
3229 (head org-export-highlight-first-table-line
)
3231 (setq html
(concat html-table-tag
"\n"))
3232 (while (setq line
(pop lines
))
3233 (setq empty
" ")
3235 (if (string-match "^[ \t]*\\+-" line
)
3246 (if (equal x
"") (setq x empty
))
3248 (concat (car org-export-table-header-tags
) x
3249 (cdr org-export-table-header-tags
))
3250 (concat (car org-export-table-data-tags
) x
3251 (cdr org-export-table-data-tags
))))
3255 (setq field-buffer nil
)))
3257 (throw 'next-line t
)))
3258 ;; Break the line into fields and store the fields
3259 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3261 (setq field-buffer
(mapcar
3263 (concat x
"<br/>" (pop fields
)))
3265 (setq field-buffer fields
))))
3266 (setq html
(concat html
"</table>\n"))
3269 (defun org-format-table-table-html-using-table-generate-source (lines)
3270 "Format a table into html, using `table-generate-source' from table.el.
3271 This has the advantage that cell- or row-spanning is allowed.
3272 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3274 (with-current-buffer (get-buffer-create " org-tmp1 ")
3276 (insert (mapconcat 'identity lines
"\n"))
3277 (goto-char (point-min))
3278 (if (not (re-search-forward "|[^+]" nil t
))
3279 (error "Error processing table"))
3280 (table-recognize-table)
3281 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3282 (table-generate-source 'html
" org-tmp2 ")
3283 (set-buffer " org-tmp2 ")
3284 (buffer-substring (point-min) (point-max))))
3286 (defun org-html-handle-time-stamps (s)
3287 "Format time stamps in string S, or remove them."
3290 (while (string-match org-maybe-keyword-time-regexp s
)
3291 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3292 ;; never export CLOCK
3294 (or b
(setq b
(substring s
0 (match-beginning 0))))
3295 (if (not org-export-with-timestamps
)
3296 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3297 s
(substring s
(match-end 0)))
3299 r
(substring s
0 (match-beginning 0))
3301 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3302 (match-string 1 s
)))
3303 (format " @<span class=\"timestamp\">%s@</span>"
3305 (org-translate-time (match-string 3 s
)) 1 -
1)))
3306 s
(substring s
(match-end 0)))))
3307 ;; Line break if line started and ended with time stamp stuff
3310 (setq r
(concat r s
))
3311 (unless (string-match "\\S-" (concat b s
))
3312 (setq r
(concat r
"@<br/>")))
3315 (defun org-export-htmlize-region-for-paste (beg end
)
3316 "Convert the region to HTML, using htmlize.el.
3317 This is much like `htmlize-region-for-paste', only that it uses
3318 the settings define in the org-... variables."
3319 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3320 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3321 (htmlbuf (htmlize-region beg end
)))
3323 (with-current-buffer htmlbuf
3324 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3325 (plist-get htmlize-buffer-places
'content-end
)))
3326 (kill-buffer htmlbuf
))))
3329 (defun org-export-htmlize-generate-css ()
3330 "Create the CSS for all font definitions in the current Emacs session.
3331 Use this to create face definitions in your CSS style file that can then
3332 be used by code snippets transformed by htmlize.
3333 This command just produces a buffer that contains class definitions for all
3334 faces used in the current Emacs session. You can copy and paste the ones you
3335 need into your CSS file.
3337 If you then set `org-export-htmlize-output-type' to `css', calls to
3338 the function `org-export-htmlize-region-for-paste' will produce code
3339 that uses these same face definitions."
3342 (and (get-buffer "*html*") (kill-buffer "*html*"))
3344 (let ((fl (face-list))
3345 (htmlize-css-name-prefix "org-")
3346 (htmlize-output-type 'css
)
3348 (while (setq f
(pop fl
)
3349 i
(and f
(face-attribute f
:inherit
)))
3350 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3351 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3352 (htmlize-region (point-min) (point-max))))
3353 (switch-to-buffer "*html*")
3354 (goto-char (point-min))
3355 (if (re-search-forward "<style" nil t
)
3356 (delete-region (point-min) (match-beginning 0)))
3357 (if (re-search-forward "</style>" nil t
)
3358 (delete-region (1+ (match-end 0)) (point-max)))
3359 (beginning-of-line 1)
3360 (if (looking-at " +") (replace-match ""))
3361 (goto-char (point-min)))
3363 (defun org-html-protect (s)
3364 ;; convert & to &, < to < and > to >
3366 (while (string-match "&" s start
)
3367 (setq s
(replace-match "&" t t s
)
3368 start
(1+ (match-beginning 0))))
3369 (while (string-match "<" s
)
3370 (setq s
(replace-match "<" t t s
)))
3371 (while (string-match ">" s
)
3372 (setq s
(replace-match ">" t t s
))))
3375 (defun org-export-cleanup-toc-line (s)
3376 "Remove tags and time staps from lines going into the toc."
3377 (when (memq org-export-with-tags
'(not-in-toc nil
))
3378 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3379 (setq s
(replace-match "" t t s
))))
3380 (when org-export-remove-timestamps-from-toc
3381 (while (string-match org-maybe-keyword-time-regexp s
)
3382 (setq s
(replace-match "" t t s
))))
3383 (while (string-match org-bracket-link-regexp s
)
3384 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3388 (defun org-html-expand (string)
3389 "Prepare STRING for HTML export. Applies all active conversions.
3390 If there are links in the string, don't modify these."
3391 (let* ((re (concat org-bracket-link-regexp
"\\|"
3392 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3394 (while (setq m
(string-match re string
))
3395 (setq s
(substring string
0 m
)
3396 l
(match-string 0 string
)
3397 string
(substring string
(match-end 0)))
3398 (push (org-html-do-expand s
) res
)
3400 (push (org-html-do-expand string
) res
)
3401 (apply 'concat
(nreverse res
))))
3403 (defun org-html-do-expand (s)
3404 "Apply all active conversions to translate special ASCII to HTML."
3405 (setq s
(org-html-protect s
))
3406 (if org-export-html-expand
3408 (while (string-match "@<\\([^&]*\\)>" s
)
3409 (setq s
(replace-match "<\\1>" t nil s
)))))
3410 (if org-export-with-emphasize
3411 (setq s
(org-export-html-convert-emphasize s
)))
3412 (if org-export-with-special-strings
3413 (setq s
(org-export-html-convert-special-strings s
)))
3414 (if org-export-with-sub-superscripts
3415 (setq s
(org-export-html-convert-sub-super s
)))
3416 (if org-export-with-TeX-macros
3417 (let ((start 0) wd ass
)
3418 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3419 (if (get-text-property (match-beginning 0) 'org-protected s
)
3420 (setq start
(match-end 0))
3421 (setq wd
(match-string 1 s
))
3422 (if (setq ass
(assoc wd org-html-entities
))
3423 (setq s
(replace-match (or (cdr ass
)
3424 (concat "&" (car ass
) ";"))
3426 (setq start
(+ start
(length wd
))))))))
3429 (defun org-create-multibrace-regexp (left right n
)
3430 "Create a regular expression which will match a balanced sexp.
3431 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3432 as single character strings.
3433 The regexp returned will match the entire expression including the
3434 delimiters. It will also define a single group which contains the
3435 match except for the outermost delimiters. The maximum depth of
3436 stacked delimiters is N. Escaping delimiters is not possible."
3437 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3440 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3443 re
(concat re or next
)
3444 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3445 (concat left
"\\(" re
"\\)" right
)))
3447 (defvar org-match-substring-regexp
3449 "\\([^\\]\\)\\([_^]\\)\\("
3450 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3452 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3454 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3455 "The regular expression matching a sub- or superscript.")
3457 (defvar org-match-substring-with-braces-regexp
3459 "\\([^\\]\\)\\([_^]\\)\\("
3460 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3462 "The regular expression matching a sub- or superscript, forcing braces.")
3464 (defconst org-export-html-special-string-regexps
3465 '(("\\\\-" .
"­")
3466 ("---\\([^-]\\)" .
"—\\1")
3467 ("--\\([^-]\\)" .
"–\\1")
3468 ("\\.\\.\\." .
"…"))
3469 "Regular expressions for special string conversion.")
3471 (defun org-export-html-convert-special-strings (string)
3472 "Convert special characters in STRING to HTML."
3473 (let ((all org-export-html-special-string-regexps
)
3475 (while (setq a
(pop all
))
3476 (setq re
(car a
) rpl
(cdr a
) start
0)
3477 (while (string-match re string start
)
3478 (if (get-text-property (match-beginning 0) 'org-protected string
)
3479 (setq start
(match-end 0))
3480 (setq string
(replace-match rpl t nil string
)))))
3483 (defun org-export-html-convert-sub-super (string)
3484 "Convert sub- and superscripts in STRING to HTML."
3485 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3486 (while (string-match org-match-substring-regexp string s
)
3488 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3489 ((get-text-property (match-beginning 2) 'org-protected string
)
3490 (setq s
(match-end 2)))
3492 (setq s
(match-end 1)
3493 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3494 c
(or (match-string 8 string
)
3495 (match-string 6 string
)
3496 (match-string 5 string
))
3497 string
(replace-match
3498 (concat (match-string 1 string
)
3499 "<" key
">" c
"</" key
">")
3501 (while (string-match "\\\\\\([_^]\\)" string
)
3502 (setq string
(replace-match (match-string 1 string
) t t string
)))
3505 (defun org-export-html-convert-emphasize (string)
3508 (while (string-match org-emph-re string s
)
3510 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3511 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3512 (setq s
(match-beginning 0)
3515 (match-string 1 string
)
3516 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3517 (match-string 4 string
)
3518 (nth 3 (assoc (match-string 3 string
)
3519 org-emphasis-alist
))
3520 (match-string 5 string
))
3521 string
(replace-match rpl t t string
)
3522 s
(+ s
(- (length rpl
) 2)))
3526 (defvar org-par-open nil
)
3527 (defun org-open-par ()
3528 "Insert <p>, but first close previous paragraph if any."
3529 (org-close-par-maybe)
3531 (setq org-par-open t
))
3532 (defun org-close-par-maybe ()
3533 "Close paragraph if there is one open."
3536 (setq org-par-open nil
)))
3537 (defun org-close-li (&optional type
)
3538 "Close <li> if necessary."
3539 (org-close-par-maybe)
3540 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3542 (defvar body-only
) ; dynamically scoped into this.
3543 (defun org-html-level-start (level title umax with-toc head-count
)
3544 "Insert a new level in HTML export.
3545 When TITLE is nil, just close all open levels."
3546 (org-close-par-maybe)
3547 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3551 (if (aref org-levels-open
(1- l
))
3553 (org-html-level-close l umax
)
3554 (aset org-levels-open
(1- l
) nil
)))
3557 ;; If title is nil, this means this function is called to close
3558 ;; all levels, so the rest is done only if title is given
3559 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3560 (setq title
(replace-match
3561 (if org-export-with-tags
3564 " <span class=\"tag\">"
3565 (mapconcat 'identity
(org-split-string
3566 (match-string 1 title
) ":")
3573 (if (aref org-levels-open
(1- level
))
3577 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3578 (insert "<li>" title
"<br/>\n")))
3579 (aset org-levels-open
(1- level
) t
)
3580 (org-close-par-maybe)
3582 (insert (format "<ul>\n<li id=\"%s\">" target
)
3584 (insert "<ul>\n<li>" title
"<br/>\n"))))
3585 (aset org-levels-open
(1- level
) t
)
3586 (setq snumber
(org-section-number level
))
3587 (if (and org-export-with-section-numbers
(not body-only
))
3588 (setq title
(concat snumber
" " title
)))
3589 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3590 (unless (= head-count
1) (insert "\n</div>\n"))
3591 (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"
3592 snumber level level snumber title level snumber
))
3595 (defun org-get-text-property-any (pos prop
&optional object
)
3596 (or (get-text-property pos prop object
)
3597 (and (setq pos
(next-single-property-change pos prop object
))
3598 (get-text-property pos prop object
))))
3600 (defun org-html-level-close (level max-outline-level
)
3601 "Terminate one level in HTML export."
3602 (if (<= level max-outline-level
)
3605 (insert "</ul>\n")))
3607 ;;; iCalendar export
3610 (defun org-export-icalendar-this-file ()
3611 "Export current file as an iCalendar file.
3612 The iCalendar file will be located in the same directory as the Org-mode
3613 file, but with extension `.ics'."
3615 (org-export-icalendar nil buffer-file-name
))
3618 (defun org-export-icalendar-all-agenda-files ()
3619 "Export all files in `org-agenda-files' to iCalendar .ics files.
3620 Each iCalendar file will be located in the same directory as the Org-mode
3621 file, but with extension `.ics'."
3623 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3626 (defun org-export-icalendar-combine-agenda-files ()
3627 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3628 The file is stored under the name `org-combined-agenda-icalendar-file'."
3630 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3632 (defun org-export-icalendar (combine &rest files
)
3633 "Create iCalendar files for all elements of FILES.
3634 If COMBINE is non-nil, combine all calendar entries into a single large
3635 file and store it under the name `org-combined-agenda-icalendar-file'."
3637 (org-prepare-agenda-buffers files
)
3638 (let* ((dir (org-export-directory
3639 :ical
(list :publishing-directory
3640 org-export-publishing-directory
)))
3641 file ical-file ical-buffer category started org-agenda-new-buffers
)
3642 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3645 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3646 org-combined-agenda-icalendar-file
3647 (expand-file-name org-combined-agenda-icalendar-file dir
))
3648 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3649 (set-buffer ical-buffer
) (erase-buffer))
3650 (while (setq file
(pop files
))
3652 (org-check-agenda-file file
)
3653 (set-buffer (org-get-agenda-file-buffer file
))
3655 (setq ical-file
(concat (file-name-as-directory dir
)
3656 (file-name-sans-extension
3657 (file-name-nondirectory buffer-file-name
))
3659 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3660 (with-current-buffer ical-buffer
(erase-buffer)))
3661 (setq category
(or org-category
3662 (file-name-sans-extension
3663 (file-name-nondirectory buffer-file-name
))))
3664 (if (symbolp category
) (setq category
(symbol-name category
)))
3665 (let ((standard-output ical-buffer
))
3667 (and (not started
) (setq started t
)
3668 (org-start-icalendar-file org-icalendar-combined-name
))
3669 (org-start-icalendar-file category
))
3670 (org-print-icalendar-entries combine
)
3671 (when (or (and combine
(not files
)) (not combine
))
3672 (org-finish-icalendar-file)
3673 (set-buffer ical-buffer
)
3675 (run-hooks 'org-after-save-iCalendar-file-hook
)
3676 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3678 (org-release-buffers org-agenda-new-buffers
))))
3680 (defvar org-after-save-iCalendar-file-hook nil
3681 "Hook run after an iCalendar file has been saved.
3682 The iCalendar buffer is still current when this hook is run.
3683 A good way to use this is to tell a desktop calenndar application to re-read
3684 the iCalendar file.")
3686 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3687 (defun org-print-icalendar-entries (&optional combine
)
3688 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3689 When COMBINE is non nil, add the category to each line."
3690 (require 'org-agenda
)
3691 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3692 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3693 (dts (org-ical-ts-to-string
3694 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3696 hd ts ts2 state status
(inc t
) pos b sexp rrule
3697 scheduledp deadlinep tmp pri category entry location summary desc
3698 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3699 (org-refresh-category-properties)
3701 (goto-char (point-min))
3702 (while (re-search-forward re1 nil t
)
3705 (when (boundp 'org-icalendar-verify-function
)
3706 (unless (funcall org-icalendar-verify-function
)
3707 (outline-next-heading)
3710 (setq pos
(match-beginning 0)
3713 hd
(condition-case nil
3714 (org-icalendar-cleanup-string
3716 (error (throw :skip nil
)))
3717 summary
(org-icalendar-cleanup-string
3718 (org-entry-get nil
"SUMMARY"))
3719 desc
(org-icalendar-cleanup-string
3720 (or (org-entry-get nil
"DESCRIPTION")
3721 (and org-icalendar-include-body
(org-get-entry)))
3722 t org-icalendar-include-body
)
3723 location
(org-icalendar-cleanup-string
3724 (org-entry-get nil
"LOCATION"))
3725 category
(org-get-category))
3726 (if (looking-at re2
)
3728 (goto-char (match-end 0))
3729 (setq ts2
(match-string 1)
3730 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3731 (setq tmp
(buffer-substring (max (point-min)
3732 (- pos org-ds-keyword-length
))
3734 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3737 (replace-match "\\1" t nil ts
))
3739 deadlinep
(string-match org-deadline-regexp tmp
)
3740 scheduledp
(string-match org-scheduled-regexp tmp
)
3741 ;; donep (org-entry-is-done-p)
3743 (if (or (string-match org-tr-regexp hd
)
3744 (string-match org-ts-regexp hd
))
3745 (setq hd
(replace-match "" t t hd
)))
3746 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3748 (concat "\nRRULE:FREQ="
3751 '(("d" .
"DAILY")("w" .
"WEEKLY")
3752 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3753 ";INTERVAL=" (match-string 1 ts
)))
3755 (setq summary
(or summary hd
))
3756 (if (string-match org-bracket-link-regexp summary
)
3758 (replace-match (if (match-end 3)
3759 (match-string 3 summary
)
3760 (match-string 1 summary
))
3762 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3763 (if scheduledp
(setq summary
(concat "S: " summary
)))
3764 (if (string-match "\\`<%%" ts
)
3765 (with-current-buffer sexp-buffer
3766 (insert (substring ts
1 -
1) " " summary
"\n"))
3767 (princ (format "BEGIN:VEVENT
3773 (org-ical-ts-to-string ts
"DTSTART")
3774 (org-ical-ts-to-string ts2
"DTEND" inc
)
3776 (if (and desc
(string-match "\\S-" desc
))
3777 (concat "\nDESCRIPTION: " desc
) "")
3778 (if (and location
(string-match "\\S-" location
))
3779 (concat "\nLOCATION: " location
) "")
3782 (when (and org-icalendar-include-sexps
3783 (condition-case nil
(require 'icalendar
) (error nil
))
3784 (fboundp 'icalendar-export-region
))
3785 ;; Get all the literal sexps
3786 (goto-char (point-min))
3787 (while (re-search-forward "^&?%%(" nil t
)
3790 (setq b
(match-beginning 0))
3791 (goto-char (1- (match-end 0)))
3794 (setq sexp
(buffer-substring b
(point)))
3795 (with-current-buffer sexp-buffer
3797 (princ (org-diary-to-ical-string sexp-buffer
)))))
3799 (when org-icalendar-include-todo
3800 (goto-char (point-min))
3801 (while (re-search-forward org-todo-line-regexp nil t
)
3804 (when (boundp 'org-icalendar-verify-function
)
3805 (unless (funcall org-icalendar-verify-function
)
3806 (outline-next-heading)
3809 (setq state
(match-string 2))
3810 (setq status
(if (member state org-done-keywords
)
3811 "COMPLETED" "NEEDS-ACTION"))
3813 (or (not (member state org-done-keywords
))
3814 (eq org-icalendar-include-todo
'all
))
3815 (not (member org-archive-tag
(org-get-tags-at)))
3817 (setq hd
(match-string 3)
3818 summary
(org-icalendar-cleanup-string
3819 (org-entry-get nil
"SUMMARY"))
3820 desc
(org-icalendar-cleanup-string
3821 (or (org-entry-get nil
"DESCRIPTION")
3822 (and org-icalendar-include-body
(org-get-entry)))
3823 t org-icalendar-include-body
)
3824 location
(org-icalendar-cleanup-string
3825 (org-entry-get nil
"LOCATION")))
3826 (if (string-match org-bracket-link-regexp hd
)
3827 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3828 (match-string 1 hd
))
3830 (if (string-match org-priority-regexp hd
)
3831 (setq pri
(string-to-char (match-string 2 hd
))
3832 hd
(concat (substring hd
0 (match-beginning 1))
3833 (substring hd
(match-end 1))))
3834 (setq pri org-default-priority
))
3835 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3836 (- org-lowest-priority org-highest-priority
))))))
3838 (princ (format "BEGIN:VTODO
3848 (if (and location
(string-match "\\S-" location
))
3849 (concat "\nLOCATION: " location
) "")
3850 (if (and desc
(string-match "\\S-" desc
))
3851 (concat "\nDESCRIPTION: " desc
) "")
3852 category pri status
)))))))))
3854 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3855 "Take out stuff and quote what needs to be quoted.
3856 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3857 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3862 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3863 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3864 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3865 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3867 (while (string-match "\\([,;]\\)" s start
)
3868 (setq start
(+ (match-beginning 0) 2)
3869 s
(replace-match "\\\\\\1" nil nil s
))))
3871 (while (string-match "[ \t]*\n[ \t]*" s
)
3872 (setq s
(replace-match "\\n" t t s
))))
3873 (setq s
(org-trim s
))
3876 (if (and (numberp maxlength
)
3877 (> (length s
) maxlength
))
3878 (setq s
(substring s
0 maxlength
)))))
3881 (defun org-get-entry ()
3882 "Clean-up description string."
3884 (org-back-to-heading t
)
3885 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3887 (defun org-start-icalendar-file (name)
3888 "Start an iCalendar file by inserting the header."
3889 (let ((user user-full-name
)
3890 (name (or name
"unknown"))
3891 (timezone (cadr (current-time-zone))))
3893 (format "BEGIN:VCALENDAR
3896 PRODID:-//%s//Emacs with Org-mode//EN
3898 CALSCALE:GREGORIAN\n" name user timezone
))))
3900 (defun org-finish-icalendar-file ()
3901 "Finish an iCalendar file by inserting the END statement."
3902 (princ "END:VCALENDAR\n"))
3904 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3905 "Take a time string S and convert it to iCalendar format.
3906 KEYWORD is added in front, to make a complete line like DTSTART....
3907 When INC is non-nil, increase the hour by two (if time string contains
3908 a time), or the day by one (if it does not contain a time)."
3909 (let ((t1 (org-parse-time-string s
'nodefault
))
3910 t2 fmt have-time time
)
3911 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3912 (setq t2 t1 have-time t
)
3913 (setq t2
(org-parse-time-string s
)))
3914 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3915 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3918 (if org-agenda-default-appointment-duration
3919 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3922 (setq time
(encode-time s mi h d m y
)))
3923 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3924 (concat keyword
(format-time-string fmt time
))))
3928 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3929 (with-current-buffer buffer
3930 (apply 'insert output
)))
3931 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3934 (defun org-export-as-xoxo (&optional buffer
)
3935 "Export the org buffer as XOXO.
3936 The XOXO buffer is named *xoxo-<source buffer name>*"
3937 (interactive (list (current-buffer)))
3938 ;; A quickie abstraction
3940 ;; Output everything as XOXO
3941 (with-current-buffer (get-buffer buffer
)
3942 (let* ((pos (point))
3943 (opt-plist (org-combine-plists (org-default-export-plist)
3944 (org-infile-export-plist)))
3945 (filename (concat (file-name-as-directory
3946 (org-export-directory :xoxo opt-plist
))
3947 (file-name-sans-extension
3948 (file-name-nondirectory buffer-file-name
))
3950 (out (find-file-noselect filename
))
3953 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3954 ;; Check the output buffer is empty.
3955 (with-current-buffer out
(erase-buffer))
3956 ;; Kick off the output
3957 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3958 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3959 (let* ((hd (match-string-no-properties 1))
3962 (match-string-no-properties 2)
3964 (goto-char (match-end 0))
3969 (if (looking-at "^[ \t]\\(.*\\)")
3970 (setq str
(concat str
(match-string-no-properties 1)))
3971 (throw 'loop str
)))))))))
3973 ;; Handle level rendering
3975 ((> level last-level
)
3976 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3978 ((< level last-level
)
3979 (dotimes (- (- last-level level
) 1)
3981 (org-export-as-xoxo-insert-into out
"</li>\n"))
3982 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3984 (org-export-as-xoxo-insert-into out
"</li>\n")
3985 (setq hanging-li nil
)))
3987 ((equal level last-level
)
3989 (org-export-as-xoxo-insert-into out
"</li>\n")))
3992 (setq last-level level
)
3994 ;; And output the new li
3995 (setq hanging-li
't
)
3996 (if (equal ?
+ (elt text
0))
3997 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3998 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4000 ;; Finally finish off the ol
4001 (dotimes (- last-level
1)
4003 (org-export-as-xoxo-insert-into out
"</li>\n"))
4004 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4007 ;; Finish the buffer off and clean it up.
4008 (switch-to-buffer-other-window out
)
4009 (indent-region (point-min) (point-max) nil
)
4011 (goto-char (point-min))
4016 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4018 ;;; org-exp.el ends here