1 ;;; org-exp.el --- ASCII, HTML, XOXO and iCalendar export for Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 (declare-function org-export-latex-preprocess
"org-export-latex" ())
34 (declare-function org-agenda-skip
"org-agenda" ())
35 (declare-function org-infojs-options-inbuffer-template
"org-jsinfo" ())
36 (declare-function htmlize-region
"ext:htmlize" (beg end
))
37 (defvar htmlize-buffer-places
) ; from htmlize.el
39 (defgroup org-export nil
40 "Options for exporting org-listings."
44 (defgroup org-export-general nil
45 "General options for exporting Org-mode files."
46 :tag
"Org Export General"
50 (defvar org-export-publishing-directory nil
)
52 (defcustom org-export-run-in-background nil
53 "Non-nil means export and publishing commands will run in background.
54 This works by starting up a separate Emacs process visiting the same file
55 and doing the export from there.
56 Not all export commands are affected by this - only the ones which
57 actually write to a file, and that do not depend on the buffer state.
59 If this option is nil, you can still get background export by calling
60 `org-export' with a double prefix arg: `C-u C-u C-c C-e'.
62 If this option is t, the double prefix can be used to exceptionally
63 force an export command into the current process."
64 :group
'org-export-general
67 (defcustom org-export-with-special-strings t
68 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
69 When this option is turned on, these strings will be exported as:
72 -----+----------+--------
78 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
79 :group
'org-export-translation
82 (defcustom org-export-language-setup
83 '(("en" "Author" "Date" "Table of Contents")
84 ("cs" "Autor" "Datum" "Obsah")
85 ("da" "Ophavsmand" "Dato" "Indhold")
86 ("de" "Autor" "Datum" "Inhaltsverzeichnis")
87 ("es" "Autor" "Fecha" "\xcdndice")
88 ("fr" "Auteur" "Date" "Table des mati\xe8res")
89 ("it" "Autore" "Data" "Indice")
90 ("nl" "Auteur" "Datum" "Inhoudsopgave")
91 ("nn" "Forfattar" "Dato" "Innhold") ;; nn = Norsk (nynorsk)
92 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
93 "Terms used in export text, translated to different languages.
94 Use the variable `org-export-default-language' to set the language,
95 or use the +OPTION lines for a per-file setting."
96 :group
'org-export-general
99 (string :tag
"HTML language tag")
100 (string :tag
"Author")
102 (string :tag
"Table of Contents"))))
104 (defcustom org-export-default-language
"en"
105 "The default language of HTML export, as a string.
106 This should have an association in `org-export-language-setup'."
107 :group
'org-export-general
110 (defcustom org-export-skip-text-before-1st-heading nil
111 "Non-nil means, skip all text before the first headline when exporting.
112 When nil, that text is exported as well."
113 :group
'org-export-general
116 (defcustom org-export-headline-levels
3
117 "The last level which is still exported as a headline.
118 Inferior levels will produce itemize lists when exported.
119 Note that a numeric prefix argument to an exporter function overrides
122 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
123 :group
'org-export-general
126 (defcustom org-export-with-section-numbers t
127 "Non-nil means, add section numbers to headlines when exporting.
129 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
130 :group
'org-export-general
133 (defcustom org-export-with-toc t
134 "Non-nil means, create a table of contents in exported files.
135 The TOC contains headlines with levels up to`org-export-headline-levels'.
136 When an integer, include levels up to N in the toc, this may then be
137 different from `org-export-headline-levels', but it will not be allowed
138 to be larger than the number of headline levels.
139 When nil, no table of contents is made.
141 Headlines which contain any TODO items will be marked with \"(*)\" in
142 ASCII export, and with red color in HTML output, if the option
143 `org-export-mark-todo-in-toc' is set.
145 In HTML output, the TOC will be clickable.
147 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
149 :group
'org-export-general
151 (const :tag
"No Table of Contents" nil
)
152 (const :tag
"Full Table of Contents" t
)
153 (integer :tag
"TOC to level")))
155 (defcustom org-export-mark-todo-in-toc nil
156 "Non-nil means, mark TOC lines that contain any open TODO items."
157 :group
'org-export-general
160 (defcustom org-export-preserve-breaks nil
161 "Non-nil means, preserve all line breaks when exporting.
162 Normally, in HTML output paragraphs will be reformatted. In ASCII
163 export, line breaks will always be preserved, regardless of this variable.
165 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
166 :group
'org-export-general
169 (defcustom org-export-with-archived-trees
'headline
170 "Whether subtrees with the ARCHIVE tag should be exported.
171 This can have three different values
172 nil Do not export, pretend this tree is not present
173 t Do export the entire tree
174 headline Only export the headline, but skip the tree below it."
175 :group
'org-export-general
178 (const :tag
"not at all" nil
)
179 (const :tag
"headline only" 'headline
)
180 (const :tag
"entirely" t
)))
182 (defcustom org-export-author-info t
183 "Non-nil means, insert author name and email into the exported file.
185 This option can also be set with the +OPTIONS line,
186 e.g. \"author-info:nil\"."
187 :group
'org-export-general
190 (defcustom org-export-time-stamp-file t
191 "Non-nil means, insert a time stamp into the exported file.
192 The time stamp shows when the file was created.
194 This option can also be set with the +OPTIONS line,
195 e.g. \"timestamp:nil\"."
196 :group
'org-export-general
199 (defcustom org-export-with-timestamps t
200 "If nil, do not export time stamps and associated keywords."
201 :group
'org-export-general
204 (defcustom org-export-remove-timestamps-from-toc t
205 "If nil, remove timestamps from the table of contents entries."
206 :group
'org-export-general
209 (defcustom org-export-with-tags
'not-in-toc
210 "If nil, do not export tags, just remove them from headlines.
211 If this is the symbol `not-in-toc', tags will be removed from table of
212 contents entries, but still be shown in the headlines of the document.
214 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
215 :group
'org-export-general
217 (const :tag
"Off" nil
)
218 (const :tag
"Not in TOC" not-in-toc
)
219 (const :tag
"On" t
)))
221 (defcustom org-export-with-drawers nil
222 "Non-nil means, export with drawers like the property drawer.
223 When t, all drawers are exported. This may also be a list of
224 drawer names to export."
225 :group
'org-export-general
227 (const :tag
"All drawers" t
)
228 (const :tag
"None" nil
)
229 (repeat :tag
"Selected drawers"
230 (string :tag
"Drawer name"))))
232 (defvar org-export-preprocess-hook nil
233 "Hook for preprocessing an export buffer.
234 Pretty much the first thing when exporting is running this hook.")
236 (defgroup org-export-translation nil
237 "Options for translating special ascii sequences for the export backends."
238 :tag
"Org Export Translation"
241 (defcustom org-export-with-emphasize t
242 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
243 If the export target supports emphasizing text, the word will be
244 typeset in bold, italic, or underlined, respectively. Works only for
245 single words, but you can say: I *really* *mean* *this*.
246 Not all export backends support this.
248 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
249 :group
'org-export-translation
252 (defcustom org-export-with-footnotes t
253 "If nil, export [1] as a footnote marker.
254 Lines starting with [1] will be formatted as footnotes.
256 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
257 :group
'org-export-translation
260 (defcustom org-export-with-sub-superscripts t
261 "Non-nil means, interpret \"_\" and \"^\" for export.
262 When this option is turned on, you can use TeX-like syntax for sub- and
263 superscripts. Several characters after \"_\" or \"^\" will be
264 considered as a single item - so grouping with {} is normally not
265 needed. For example, the following things will be parsed as single
266 sub- or superscripts.
268 10^24 or 10^tau several digits will be considered 1 item.
269 10^-12 or 10^-tau a leading sign with digits or a word
270 x^2-y^3 will be read as x^2 - y^3, because items are
271 terminated by almost any nonword/nondigit char.
272 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
274 Still, ambiguity is possible - so when in doubt use {} to enclose the
275 sub/superscript. If you set this variable to the symbol `{}',
276 the braces are *required* in order to trigger interpretations as
277 sub/superscript. This can be helpful in documents that need \"_\"
278 frequently in plain text.
280 Not all export backends support this, but HTML does.
282 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
283 :group
'org-export-translation
285 (const :tag
"Always interpret" t
)
286 (const :tag
"Only with braces" {})
287 (const :tag
"Never interpret" nil
)))
289 (defcustom org-export-with-special-strings t
290 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
291 When this option is turned on, these strings will be exported as:
297 Not all export backends support this, but HTML does.
299 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
300 :group
'org-export-translation
303 (defcustom org-export-with-TeX-macros t
304 "Non-nil means, interpret simple TeX-like macros when exporting.
305 For example, HTML export converts \\alpha to α and \\AA to Å.
306 No only real TeX macros will work here, but the standard HTML entities
307 for math can be used as macro names as well. For a list of supported
308 names in HTML export, see the constant `org-html-entities'.
309 Not all export backends support this.
311 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
312 :group
'org-export-translation
313 :group
'org-export-latex
316 (defcustom org-export-with-LaTeX-fragments nil
317 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
318 When set, the exporter will find LaTeX environments if the \\begin line is
319 the first non-white thing on a line. It will also find the math delimiters
320 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
323 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
324 :group
'org-export-translation
325 :group
'org-export-latex
328 (defcustom org-export-with-fixed-width t
329 "Non-nil means, lines starting with \":\" will be in fixed width font.
330 This can be used to have pre-formatted text, fragments of code etc. For
332 : ;; Some Lisp examples
335 will be looking just like this in also HTML. See also the QUOTE keyword.
336 Not all export backends support this.
338 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
339 :group
'org-export-translation
342 (defcustom org-match-sexp-depth
3
343 "Number of stacked braces for sub/superscript matching.
344 This has to be set before loading org.el to be effective."
345 :group
'org-export-translation
348 (defgroup org-export-tables nil
349 "Options for exporting tables in Org-mode."
350 :tag
"Org Export Tables"
353 (defcustom org-export-with-tables t
354 "If non-nil, lines starting with \"|\" define a table.
357 | Name | Address | Birthday |
358 |-------------+----------+-----------|
359 | Arthur Dent | England | 29.2.2100 |
361 Not all export backends support this.
363 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
364 :group
'org-export-tables
367 (defcustom org-export-highlight-first-table-line t
368 "Non-nil means, highlight the first table line.
369 In HTML export, this means use <th> instead of <td>.
370 In tables created with table.el, this applies to the first table line.
371 In Org-mode tables, all lines before the first horizontal separator
372 line will be formatted with <th> tags."
373 :group
'org-export-tables
376 (defcustom org-export-table-remove-special-lines t
377 "Remove special lines and marking characters in calculating tables.
378 This removes the special marking character column from tables that are set
379 up for spreadsheet calculations. It also removes the entire lines
380 marked with `!', `_', or `^'. The lines with `$' are kept, because
381 the values of constants may be useful to have."
382 :group
'org-export-tables
385 (defcustom org-export-prefer-native-exporter-for-tables nil
386 "Non-nil means, always export tables created with table.el natively.
387 Natively means, use the HTML code generator in table.el.
388 When nil, Org-mode's own HTML generator is used when possible (i.e. if
389 the table does not use row- or column-spanning). This has the
390 advantage, that the automatic HTML conversions for math symbols and
391 sub/superscripts can be applied. Org-mode's HTML generator is also
393 :group
'org-export-tables
396 (defgroup org-export-ascii nil
397 "Options specific for ASCII export of Org-mode files."
398 :tag
"Org Export ASCII"
401 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
402 "Characters for underlining headings in ASCII export.
403 In the given sequence, these characters will be used for level 1, 2, ..."
404 :group
'org-export-ascii
405 :type
'(repeat character
))
407 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
408 "Bullet characters for headlines converted to lists in ASCII export.
409 The first character is used for the first lest level generated in this
410 way, and so on. If there are more levels than characters given here,
411 the list will be repeated.
412 Note that plain lists will keep the same bullets as the have in the
414 :group
'org-export-ascii
415 :type
'(repeat character
))
417 (defgroup org-export-xml nil
418 "Options specific for XML export of Org-mode files."
419 :tag
"Org Export XML"
422 (defgroup org-export-html nil
423 "Options specific for HTML export of Org-mode files."
424 :tag
"Org Export HTML"
427 (defcustom org-export-html-coding-system nil
428 "Coding system for HTML export, defaults to buffer-file-coding-system."
429 :group
'org-export-html
430 :type
'coding-system
)
432 (defcustom org-export-html-extension
"html"
433 "The extension for exported HTML files."
434 :group
'org-export-html
437 (defcustom org-export-html-link-up
""
438 "Where should the \"UP\" link of exported HTML pages lead?"
439 :group
'org-export-html
440 :type
'(string :tag
"File or URL"))
442 (defcustom org-export-html-link-home
""
443 "Where should the \"HOME\" link of exported HTML pages lead?"
444 :group
'org-export-html
445 :type
'(string :tag
"File or URL"))
447 (defcustom org-export-html-style
448 "<style type=\"text/css\">
450 font-family: Times, serif;
453 .title { text-align: center; }
454 .todo { color: red; }
455 .done { color: green; }
456 .timestamp { color: grey }
457 .timestamp-kwd { color: CadetBlue }
458 .tag { background-color:lightblue; font-weight:normal }
461 border: 1pt solid #AEBDCC;
462 background-color: #F3F5F7;
464 font-family: courier, monospace;
466 table { border-collapse: collapse; }
469 <!--border: 1pt solid #ADB9CC;-->
471 dt { font-weight: bold; }
473 "The default style specification for exported HTML files.
474 Since there are different ways of setting style information, this variable
475 needs to contain the full HTML structure to provide a style, including the
476 surrounding HTML tags. The style specifications should include definitions
477 for new classes todo, done, title, and deadline. For example, valid values
480 <style type=\"text/css\">
481 p { font-weight: normal; color: gray; }
483 .title { text-align: center; }
484 .todo, .deadline { color: red; }
485 .done { color: green; }
488 or, if you want to keep the style in a file,
490 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
492 As the value of this option simply gets inserted into the HTML <head> header,
493 you can \"misuse\" it to add arbitrary text to the header."
494 :group
'org-export-html
498 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
499 "Format for typesetting the document title in HTML export."
500 :group
'org-export-html
503 (defcustom org-export-html-toplevel-hlevel
2
504 "The <H> level for level 1 headings in HTML export."
505 :group
'org-export-html
508 (defcustom org-export-html-link-org-files-as-html t
509 "Non-nil means, make file links to `file.org' point to `file.html'.
510 When org-mode is exporting an org-mode file to HTML, links to
511 non-html files are directly put into a href tag in HTML.
512 However, links to other Org-mode files (recognized by the
513 extension `.org.) should become links to the corresponding html
514 file, assuming that the linked org-mode file will also be
516 When nil, the links still point to the plain `.org' file."
517 :group
'org-export-html
520 (defcustom org-export-html-inline-images
'maybe
521 "Non-nil means, inline images into exported HTML pages.
522 This is done using an <img> tag. When nil, an anchor with href is used to
523 link to the image. If this option is `maybe', then images in links with
524 an empty description will be inlined, while images with a description will
526 :group
'org-export-html
527 :type
'(choice (const :tag
"Never" nil
)
528 (const :tag
"Always" t
)
529 (const :tag
"When there is no description" maybe
)))
532 (defcustom org-export-html-expand t
533 "Non-nil means, for HTML export, treat @<...> as HTML tag.
534 When nil, these tags will be exported as plain text and therefore
535 not be interpreted by a browser.
537 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
538 :group
'org-export-html
541 (defcustom org-export-html-table-tag
542 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
543 "The HTML tag that is used to start a table.
544 This must be a <table> tag, but you may change the options like
545 borders and spacing."
546 :group
'org-export-html
549 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
550 "The opening tag for table header fields.
551 This is customizable so that alignment options can be specified."
552 :group
'org-export-tables
553 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
555 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
556 "The opening tag for table data fields.
557 This is customizable so that alignment options can be specified."
558 :group
'org-export-tables
559 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
561 (defcustom org-export-html-with-timestamp nil
562 "If non-nil, write `org-export-html-html-helper-timestamp'
563 into the exported HTML text. Otherwise, the buffer will just be saved
565 :group
'org-export-html
568 (defcustom org-export-html-html-helper-timestamp
569 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
570 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
571 :group
'org-export-html
574 (defgroup org-export-htmlize nil
575 "Options for processing examples with htmlize.el."
576 :tag
"Org Export Htmlize"
577 :group
'org-export-html
)
579 (defcustom org-export-htmlize-output-type
'inline-css
580 "Output type to be used by htmlize when formatting code snippets.
581 Normally this is `inline-css', but if you have defined to appropriate
582 classes in your css style file, setting this to `css' means that the
583 fontification will use the class names.
584 See also the function `org-export-htmlize-generate-css'."
585 :group
'org-export-htmlize
586 :type
'(choice (const css
) (const inline-css
)))
588 (defcustom org-export-htmlize-css-font-prefix
"org-"
589 "The prefix for CSS class names for htmlize font specifications."
590 :group
'org-export-htmlize
593 (defgroup org-export-icalendar nil
594 "Options specific for iCalendar export of Org-mode files."
595 :tag
"Org Export iCalendar"
598 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
599 "The file name for the iCalendar file covering all agenda files.
600 This file is created with the command \\[org-export-icalendar-all-agenda-files].
601 The file name should be absolute, the file will be overwritten without warning."
602 :group
'org-export-icalendar
605 (defcustom org-icalendar-include-todo nil
606 "Non-nil means, export to iCalendar files should also cover TODO items."
607 :group
'org-export-icalendar
609 (const :tag
"None" nil
)
610 (const :tag
"Unfinished" t
)
611 (const :tag
"All" all
)))
613 (defcustom org-icalendar-include-sexps t
614 "Non-nil means, export to iCalendar files should also cover sexp entries.
615 These are entries like in the diary, but directly in an Org-mode file."
616 :group
'org-export-icalendar
619 (defcustom org-icalendar-include-body
100
620 "Amount of text below headline to be included in iCalendar export.
621 This is a number of characters that should maximally be included.
622 Properties, scheduling and clocking lines will always be removed.
623 The text will be inserted into the DESCRIPTION field."
624 :group
'org-export-icalendar
626 (const :tag
"Nothing" nil
)
627 (const :tag
"Everything" t
)
628 (integer :tag
"Max characters")))
630 (defcustom org-icalendar-combined-name
"OrgMode"
631 "Calendar name for the combined iCalendar representing all agenda files."
632 :group
'org-export-icalendar
637 ;;; Variables, constants, and parameter plists
639 (defconst org-level-max
20)
641 (defvar org-export-html-preamble nil
642 "Preamble, to be inserted just after <body>. Set by publishing functions.")
643 (defvar org-export-html-postamble nil
644 "Preamble, to be inserted just before </body>. Set by publishing functions.")
645 (defvar org-export-html-auto-preamble t
646 "Should default preamble be inserted? Set by publishing functions.")
647 (defvar org-export-html-auto-postamble t
648 "Should default postamble be inserted? Set by publishing functions.")
649 (defvar org-current-export-file nil
) ; dynamically scoped parameter
650 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
652 (defconst org-export-plist-vars
653 '((:link-up . org-export-html-link-up
)
654 (:link-home . org-export-html-link-home
)
655 (:language . org-export-default-language
)
656 (:customtime . org-display-custom-times
)
657 (:headline-levels . org-export-headline-levels
)
658 (:section-numbers . org-export-with-section-numbers
)
659 (:table-of-contents . org-export-with-toc
)
660 (:preserve-breaks . org-export-preserve-breaks
)
661 (:archived-trees . org-export-with-archived-trees
)
662 (:emphasize . org-export-with-emphasize
)
663 (:sub-superscript . org-export-with-sub-superscripts
)
664 (:special-strings . org-export-with-special-strings
)
665 (:footnotes . org-export-with-footnotes
)
666 (:drawers . org-export-with-drawers
)
667 (:tags . org-export-with-tags
)
668 (:TeX-macros . org-export-with-TeX-macros
)
669 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
670 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
671 (:fixed-width . org-export-with-fixed-width
)
672 (:timestamps . org-export-with-timestamps
)
673 (:author-info . org-export-author-info
)
674 (:time-stamp-file . org-export-time-stamp-file
)
675 (:tables . org-export-with-tables
)
676 (:table-auto-headline . org-export-highlight-first-table-line
)
677 (:style . org-export-html-style
)
678 (:agenda-style . org-agenda-export-html-style
)
679 (:convert-org-links . org-export-html-link-org-files-as-html
)
680 (:inline-images . org-export-html-inline-images
)
681 (:html-extension . org-export-html-extension
)
682 (:html-table-tag . org-export-html-table-tag
)
683 (:expand-quoted-html . org-export-html-expand
)
684 (:timestamp . org-export-html-with-timestamp
)
685 (:publishing-directory . org-export-publishing-directory
)
686 (:preamble . org-export-html-preamble
)
687 (:postamble . org-export-html-postamble
)
688 (:auto-preamble . org-export-html-auto-preamble
)
689 (:auto-postamble . org-export-html-auto-postamble
)
690 (:author . user-full-name
)
691 (:email . user-mail-address
)))
693 (defun org-default-export-plist ()
694 "Return the property list with default settings for the export variables."
695 (let ((l org-export-plist-vars
) rtn e
)
696 (while (setq e
(pop l
))
697 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
700 (defvar org-export-inbuffer-options-extra nil
701 "List of additional in-buffer options that should be detected.
702 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
703 etc. Extensions can add to this list to get their options detected, and they
704 can then add a function to `org-export-options-filters' to process these
706 Each element in this list must be a list, with the in-buffer keyword as car,
707 and a property (a symbol) as the next element. All occurences of the
708 keyword will be found, the values concatenated with a space character
709 in between, and the result stored in the export options property list.")
711 (defvar org-export-options-filters nil
712 "Functions to be called to finalize the export/publishing options.
713 All these options are stored in a property list, and each of the functions
714 in this hook gets a chance to modify this property list. Each function
715 must accept the property list as an argument, and must return the (possibly
718 (defun org-infile-export-plist ()
719 "Return the property list with file-local settings for export."
723 (goto-char (point-min))
724 (let ((re (org-make-options-regexp
726 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
727 "LINK_UP" "LINK_HOME" "SETUPFILE")
728 (mapcar 'car org-export-inbuffer-options-extra
))))
729 p key val text options js-up js-main js-css js-opt a pr
730 ext-setup-or-nil setup-contents
(start 0))
731 (while (or (and ext-setup-or-nil
732 (string-match re ext-setup-or-nil start
)
733 (setq start
(match-end 0)))
734 (and (setq ext-setup-or-nil nil start
0)
735 (re-search-forward re nil t
)))
736 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
737 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
739 ((setq a
(assoc key org-export-inbuffer-options-extra
))
741 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
742 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
743 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
744 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
745 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
746 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
747 ((string-equal key
"TEXT")
748 (setq text
(if text
(concat text
"\n" val
) val
)))
749 ((string-equal key
"OPTIONS")
750 (setq options
(concat val
" " options
)))
751 ((string-equal key
"LINK_UP")
752 (setq p
(plist-put p
:link-up val
)))
753 ((string-equal key
"LINK_HOME")
754 (setq p
(plist-put p
:link-home val
)))
755 ((equal key
"SETUPFILE")
756 (setq setup-contents
(org-file-contents
758 (org-remove-double-quotes
761 (if (not ext-setup-or-nil
)
762 (setq ext-setup-or-nil setup-contents start
0)
763 (setq ext-setup-or-nil
764 (concat (substring ext-setup-or-nil
0 start
)
765 "\n" setup-contents
"\n"
766 (substring ext-setup-or-nil start
)))))))
767 (setq p
(plist-put p
:text text
))
769 (let ((op '(("H" .
:headline-levels
)
770 ("num" .
:section-numbers
)
771 ("toc" .
:table-of-contents
)
772 ("\\n" .
:preserve-breaks
)
773 ("@" .
:expand-quoted-html
)
776 ("^" .
:sub-superscript
)
777 ("-" .
:special-strings
)
782 ("TeX" .
:TeX-macros
)
783 ("LaTeX" .
:LaTeX-fragments
)
784 ("skip" .
:skip-before-1st-heading
)
785 ("author" .
:author-info
)
786 ("timestamp" .
:time-stamp-file
)))
788 (while (setq o
(pop op
))
789 (if (string-match (concat (regexp-quote (car o
))
790 ":\\([^ \t\n\r;,.]*\\)")
792 (setq p
(plist-put p
(cdr o
)
793 (car (read-from-string
794 (match-string 1 options
)))))))))
797 (defun org-export-directory (type plist
)
798 (let* ((val (plist-get plist
:publishing-directory
))
800 (or (cdr (assoc type val
)) ".")
804 (defun org-export-process-option-filters (plist)
805 (let ((functions org-export-options-filters
) f
)
806 (while (setq f
(pop functions
))
807 (setq plist
(funcall f plist
))))
811 (defun org-export (&optional arg
)
812 "Export dispatcher for Org-mode.
813 When `org-export-run-in-background' is non-nil, try to run the command
814 in the background. This will be done only for commands that write
815 to a file. For details see the docstring of `org-export-run-in-background'.
817 The prefix argument ARG will be passed to the exporter. However, if
818 ARG is a double universal prefix `C-u C-u', that means to inverse the
819 value of `org-export-run-in-background'."
821 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
822 (help "[t] insert the export option template
823 \[v] limit export to visible part of outline tree
828 \[H] export as HTML to temporary buffer
829 \[R] export region as HTML
830 \[b] export as HTML and browse immediately
834 \[L] export as LaTeX to temporary buffer
836 \[i] export current file as iCalendar file
837 \[I] export all agenda files as iCalendar files
838 \[c] export agenda files into combined iCalendar file
840 \[F] publish current file
841 \[P] publish current project
842 \[X] publish... (project will be prompted for)
843 \[A] publish all projects")
845 '((?t org-insert-export-options-template nil
)
846 (?v org-export-visible nil
)
847 (?a org-export-as-ascii t
)
848 (?h org-export-as-html t
)
849 (?b org-export-as-html-and-open t
)
850 (?H org-export-as-html-to-buffer nil
)
851 (?R org-export-region-as-html nil
)
852 (?x org-export-as-xoxo t
)
853 (?l org-export-as-latex t
)
854 (?L org-export-as-latex-to-buffer nil
)
855 (?i org-export-icalendar-this-file t
)
856 (?I org-export-icalendar-all-agenda-files t
)
857 (?c org-export-icalendar-combine-agenda-files t
)
858 (?F org-publish-current-file t
)
859 (?P org-publish-current-project t
)
861 (?A org-publish-all t
)))
863 (save-window-excursion
864 (delete-other-windows)
865 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
867 (message "Select command: ")
868 (setq r1
(read-char-exclusive)))
869 (setq r2
(if (< r1
27) (+ r1
96) r1
))
870 (unless (setq ass
(assq r2 cmds
))
871 (error "No command associated with key %c" r1
))
872 (if (and bg
(nth 2 ass
))
873 ;; execute in background
874 (let ((p (start-process
875 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
877 (expand-file-name invocation-name invocation-directory
)
880 "--eval" "(require 'org-exp)"
881 "--eval" "(setq org-wait .2)"
883 "-f" (symbol-name (nth 1 ass
)))))
884 (set-process-sentinel p
'org-export-process-sentinel
)
885 (message "Background process \"%s\": started" p
))
886 ;; background processing not requested, or not possible
887 (call-interactively (nth 1 ass
)))))
889 (defun org-export-process-sentinel (process status
)
890 (if (string-match "\n+\\'" status
)
891 (setq status
(substring status
0 -
1)))
892 (message "Background process \"%s\": %s" process status
))
894 (defconst org-html-entities
935 ("Aring") ("AA".
"Å")
1024 ("varepsilon".
"ε")
1037 ("sigmaf") ("varsigma".
"ς")
1045 ("thetasym") ("vartheta".
"ϑ")
1048 ("bull") ("bullet".
"•")
1049 ("hellip") ("dots".
"…")
1059 ("larr") ("leftarrow".
"←") ("gets".
"←")
1060 ("uarr") ("uparrow".
"↑")
1061 ("rarr") ("to".
"→") ("rightarrow".
"→")
1062 ("darr")("downarrow".
"↓")
1063 ("harr") ("leftrightarrow".
"↔")
1064 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1065 ("lArr") ("Leftarrow".
"⇐")
1066 ("uArr") ("Uparrow".
"⇑")
1067 ("rArr") ("Rightarrow".
"⇒")
1068 ("dArr") ("Downarrow".
"⇓")
1069 ("hArr") ("Leftrightarrow".
"⇔")
1071 ("part") ("partial".
"∂")
1072 ("exist") ("exists".
"∃")
1073 ("empty") ("emptyset".
"∅")
1075 ("isin") ("in".
"∈")
1081 ("lowast") ("ast".
"∗")
1083 ("prop") ("proptp".
"∝")
1084 ("infin") ("infty".
"∞")
1085 ("ang") ("angle".
"∠")
1086 ("and") ("wedge".
"∧")
1087 ("or") ("vee".
"∨")
1093 ("cong") ("simeq".
"≅")
1094 ("asymp")("approx".
"≈")
1095 ("ne") ("neq".
"≠")
1099 ("sub") ("subset".
"⊂")
1100 ("sup") ("supset".
"⊃")
1107 ("sdot") ("cdot".
"⋅")
1114 ("loz") ("Diamond".
"◊")
1115 ("spades") ("spadesuit".
"♠")
1116 ("clubs") ("clubsuit".
"♣")
1117 ("hearts") ("diamondsuit".
"♥")
1118 ("diams") ("diamondsuit".
"♦")
1119 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1186 "Entities for TeX->HTML translation.
1187 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1188 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1189 In that case, \"\\ent\" will be translated to \"&other;\".
1190 The list contains HTML entities for Latin-1, Greek and other symbols.
1191 It is supplemented by a number of commonly used TeX macros with appropriate
1192 translations. There is currently no way for users to extend this.")
1194 ;;; General functions for all backends
1196 (defun org-export-preprocess-string (string &rest parameters
)
1197 "Cleanup STRING so that that the true exported has a more consistent source.
1198 This function takes STRING, which should be a buffer-string of an org-file
1199 to export. It then creates a temporary buffer where it does its job.
1200 The result is then again returned as a string, and the exporter works
1201 on this string to produce the exported version."
1203 (let* ((re-radio (and org-target-link-regexp
1204 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1205 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1206 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1207 (re-archive (concat ":" org-archive-tag
":"))
1208 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1209 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1210 (htmlp (plist-get parameters
:for-html
))
1211 (asciip (plist-get parameters
:for-ascii
))
1212 (latexp (plist-get parameters
:for-LaTeX
))
1213 (commentsp (plist-get parameters
:comments
))
1214 (archived-trees (plist-get parameters
:archived-trees
))
1215 (inhibit-read-only t
)
1216 (drawers org-drawers
)
1217 (exp-drawers (plist-get parameters
:drawers
))
1218 (outline-regexp "\\*+ ")
1219 target-alist tmp target level
1222 (with-current-buffer (get-buffer-create " org-mode-tmp")
1226 (run-hooks 'org-export-preprocess-hook
)
1228 ;; Remove license-to-kill stuff
1229 ;; The caller markes some stuff fo killing, stuff that has been
1230 ;; used to create the page title, for example.
1231 (while (setq p
(text-property-any (point-min) (point-max)
1232 :org-license-to-kill t
))
1233 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1235 (let ((org-inhibit-startup t
)) (org-mode))
1236 (untabify (point-min) (point-max))
1238 ;; Handle incude files
1239 (org-export-handle-include-files)
1241 ;; Handle source code snippets
1242 (org-export-replace-src-segments)
1244 ;; Get rid of drawers
1245 (unless (eq t exp-drawers
)
1246 (goto-char (point-min))
1247 (let ((re (concat "^[ \t]*:\\("
1250 (org-delete-all exp-drawers
1251 (copy-sequence drawers
))
1253 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1254 (while (re-search-forward re nil t
)
1255 (replace-match ""))))
1257 ;; Get the correct stuff before the first headline
1258 (when (plist-get parameters
:skip-before-1st-heading
)
1259 (goto-char (point-min))
1260 (when (re-search-forward "^\\*+[ \t]" nil t
)
1261 (delete-region (point-min) (match-beginning 0))
1262 (goto-char (point-min))
1264 (when (plist-get parameters
:add-text
)
1265 (goto-char (point-min))
1266 (insert (plist-get parameters
:add-text
) "\n"))
1268 ;; Get rid of archived trees
1269 (when (not (eq archived-trees t
))
1270 (goto-char (point-min))
1271 (while (re-search-forward re-archive nil t
)
1272 (if (not (org-on-heading-p t
))
1273 (org-end-of-subtree t
)
1274 (beginning-of-line 1)
1275 (setq a
(if archived-trees
1276 (1+ (point-at-eol)) (point))
1277 b
(org-end-of-subtree t
))
1278 (if (> b a
) (delete-region a b
)))))
1280 ;; Find all headings and compute the targets for them
1281 (goto-char (point-min))
1282 (org-init-section-numbers)
1283 (let ((re (concat "^" org-outline-regexp
)))
1284 (while (re-search-forward re nil t
)
1285 (setq level
(org-reduced-level
1286 (save-excursion (goto-char (point-at-bol))
1287 (org-outline-level))))
1288 (setq target
(org-solidify-link-text
1289 (format "sec-%s" (org-section-number level
))))
1290 (push (cons target target
) target-alist
)
1291 (add-text-properties
1292 (point-at-bol) (point-at-eol)
1293 (list 'target target
))))
1295 ;; Find targets in comments and move them out of comments,
1296 ;; but mark them as targets that should be invisible
1297 (goto-char (point-min))
1298 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1299 ;; Check if the line before or after is a headline with a target
1300 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1301 (get-text-property (point-at-bol 2) 'target
)))
1303 ;; use the existing target in a neighboring line
1304 (setq tmp
(match-string 2))
1306 (and (looking-at "\n") (delete-char 1))
1307 (push (cons (org-solidify-link-text tmp
) target
)
1309 ;; Make an invisible target
1310 (replace-match "\\1(INVISIBLE)")))
1312 ;; Protect backend specific stuff, throw away the others.
1314 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1315 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1316 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1318 (goto-char (point-min))
1319 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1320 (goto-char (match-end 0))
1321 (while (not (looking-at "#\\+END_EXAMPLE"))
1323 (beginning-of-line 2)))
1324 (goto-char (point-min))
1325 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1326 (add-text-properties (match-beginning 0) (match-end 0)
1327 '(org-protected t
)))
1329 (setq fmt
(pop formatters
))
1331 (goto-char (point-min))
1332 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1333 ":[ \t]*\\(.*\\)") nil t
)
1334 (replace-match "\\1" t
)
1335 (add-text-properties
1336 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1337 '(org-protected t
))))
1338 (goto-char (point-min))
1339 (while (re-search-forward
1341 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1342 (cadddr fmt
) "\\>.*\n?") nil t
)
1344 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1346 (delete-region (match-beginning 0) (match-end 0))))))
1348 ;; Protect quoted subtrees
1349 (goto-char (point-min))
1350 (while (re-search-forward re-quote nil t
)
1351 (goto-char (match-beginning 0))
1353 (add-text-properties (point) (org-end-of-subtree t
)
1354 '(org-protected t
)))
1356 ;; Protect verbatim elements
1357 (goto-char (point-min))
1358 (while (re-search-forward org-verbatim-re nil t
)
1359 (add-text-properties (match-beginning 4) (match-end 4)
1361 (goto-char (1+ (match-end 4))))
1364 (goto-char (point-min))
1365 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1366 (replace-match (if (equal (downcase (match-string 1)) "end")
1367 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1370 ;; Remove subtrees that are commented
1371 (goto-char (point-min))
1372 (while (re-search-forward re-commented nil t
)
1373 (goto-char (match-beginning 0))
1374 (delete-region (point) (org-end-of-subtree t
)))
1376 ;; Remove special table lines
1377 (when org-export-table-remove-special-lines
1378 (goto-char (point-min))
1379 (while (re-search-forward "^[ \t]*|" nil t
)
1380 (beginning-of-line 1)
1381 (if (or (looking-at "[ \t]*| *[!_^] *|")
1382 (and (looking-at ".*?| *<[0-9]+> *|")
1383 (not (looking-at ".*?| *[^ <|]"))))
1384 (delete-region (max (point-min) (1- (point-at-bol)))
1388 ;; Specific LaTeX stuff
1390 (require 'org-export-latex nil
)
1391 (org-export-latex-preprocess))
1394 (org-export-ascii-clean-string))
1396 ;; Specific HTML stuff
1398 ;; Convert LaTeX fragments to images
1399 (when (plist-get parameters
:LaTeX-fragments
)
1401 (concat "ltxpng/" (file-name-sans-extension
1402 (file-name-nondirectory
1403 org-current-export-file
)))
1404 org-current-export-dir nil
"Creating LaTeX image %s"))
1405 (message "Exporting..."))
1407 ;; Remove or replace comments
1408 (goto-char (point-min))
1409 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1411 (progn (add-text-properties
1412 (match-beginning 0) (match-end 0) '(org-protected t
))
1413 (replace-match (format commentsp
(match-string 1)) t t
))
1414 (replace-match "")))
1416 ;; Find matches for radio targets and turn them into internal links
1417 (goto-char (point-min))
1419 (while (re-search-forward re-radio nil t
)
1421 (replace-match "\\1[[\\2]]"))))
1423 ;; Find all links that contain a newline and put them into a single line
1424 (goto-char (point-min))
1425 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1427 (replace-match "\\1 \\3")
1428 (goto-char (match-beginning 0))))
1430 ;; Find all internal links. If they have a fuzzy match (i.e. not
1431 ;; a *dedicated* target match, let the link point to the
1432 ;; correspinding section.
1434 (goto-char (point-min))
1435 (while (re-search-forward org-bracket-link-regexp nil t
)
1437 (let* ((md (match-data))
1438 (desc (match-end 2))
1439 (link (org-link-unescape (match-string 1)))
1440 (slink (org-solidify-link-text link
))
1443 (or (cdr (assoc slink target-alist
))
1445 (unless (string-match org-link-types-re link
)
1446 (setq found
(condition-case nil
(org-link-search link
)
1449 (or (org-on-heading-p)
1450 (not (eq found
'dedicated
))))
1451 (or (get-text-property (point) 'target
)
1454 (1- (previous-single-property-change
1459 (goto-char (match-beginning 1))
1460 (setq props
(text-properties-at (point)))
1461 (delete-region (match-beginning 1) (match-end 1))
1464 (unless desc
(insert "][" link
))
1465 (add-text-properties pos
(point) props
)))))
1467 ;; Normalize links: Convert angle and plain links into bracket links
1468 ;; Expand link abbreviations
1469 (goto-char (point-min))
1470 (while (re-search-forward re-plain-link nil t
)
1471 (goto-char (1- (match-end 0)))
1473 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1474 ":" (match-string 3) "]]")))
1475 ;; added 'org-link face to links
1476 (put-text-property 0 (length s
) 'face
'org-link s
)
1477 (replace-match s t t
))))
1478 (goto-char (point-min))
1479 (while (re-search-forward re-angle-link nil t
)
1480 (goto-char (1- (match-end 0)))
1482 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1483 ":" (match-string 3) "]]")))
1484 (put-text-property 0 (length s
) 'face
'org-link s
)
1485 (replace-match s t t
))))
1486 (goto-char (point-min))
1487 (while (re-search-forward org-bracket-link-regexp nil t
)
1489 (let* ((s (concat "[[" (setq xx
(save-match-data
1490 (org-link-expand-abbrev (match-string 1))))
1494 (concat "[" xx
"]"))
1496 (put-text-property 0 (length s
) 'face
'org-link s
)
1497 (replace-match s t t
))))
1499 ;; Find multiline emphasis and put them into single line
1500 (when (plist-get parameters
:emph-multiline
)
1501 (goto-char (point-min))
1502 (while (re-search-forward org-emph-re nil t
)
1503 (if (not (= (char-after (match-beginning 3))
1504 (char-after (match-beginning 4))))
1506 (subst-char-in-region (match-beginning 0) (match-end 0)
1508 (goto-char (1- (match-end 0))))
1509 (goto-char (1+ (match-beginning 0))))))
1511 (setq rtn
(buffer-string)))
1512 (kill-buffer " org-mode-tmp")
1515 (defun org-export-grab-title-from-buffer ()
1516 "Get a title for the current document, from looking at the buffer."
1517 (let ((inhibit-read-only t
))
1519 (goto-char (point-min))
1520 (let ((end (save-excursion (outline-next-heading) (point))))
1521 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1522 ;; Mark the line so that it will not be exported as normal text.
1524 (add-text-properties (match-beginning 0) (match-end 0)
1525 (list :org-license-to-kill t
)))
1526 ;; Return the title string
1527 (org-trim (match-string 0)))))))
1529 (defun org-export-get-title-from-subtree ()
1530 "Return subtree title and exclude it from export."
1531 (let (title (m (mark)))
1533 (goto-char (region-beginning))
1534 (when (and (org-at-heading-p)
1535 (>= (org-end-of-subtree t t
) (region-end)))
1536 ;; This is a subtree, we take the title from the first heading
1537 (goto-char (region-beginning))
1538 (looking-at org-todo-line-regexp
)
1539 (setq title
(match-string 3))
1541 (add-text-properties (point) (1+ (point-at-eol))
1542 (list :org-license-to-kill t
)))))
1545 (defun org-solidify-link-text (s &optional alist
)
1546 "Take link text and make a safe target out of it."
1551 (org-split-string s
"[ \t\r\n]+") "=="))
1552 (a (assoc rtn alist
)))
1555 (defun org-get-min-level (lines)
1556 "Get the minimum level in LINES."
1557 (let ((re "^\\(\\*+\\) ") l min
)
1559 (while (setq l
(pop lines
))
1560 (if (string-match re l
)
1561 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1564 ;; Variable holding the vector with section numbers
1565 (defvar org-section-numbers
(make-vector org-level-max
0))
1567 (defun org-init-section-numbers ()
1568 "Initialize the vector for the section numbers."
1570 (numbers (nreverse (org-split-string "" "\\.")))
1571 (depth (1- (length org-section-numbers
)))
1572 (i depth
) number-string
)
1575 (aset org-section-numbers i
0)
1576 (setq number-string
(or (car numbers
) "0"))
1577 (if (string-match "\\`[A-Z]\\'" number-string
)
1578 (aset org-section-numbers i
1579 (- (string-to-char number-string
) ?A -
1))
1580 (aset org-section-numbers i
(string-to-number number-string
)))
1584 (defun org-section-number (&optional level
)
1585 "Return a string with the current section number.
1586 When LEVEL is non-nil, increase section numbers on that level."
1587 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1590 (aset org-section-numbers
1591 level
(1+ (aref org-section-numbers level
))))
1592 (setq idx
(1+ level
))
1593 (while (<= idx depth
)
1595 (aset org-section-numbers idx
0))
1596 (setq idx
(1+ idx
))))
1598 (while (<= idx depth
)
1599 (setq n
(aref org-section-numbers idx
))
1600 (setq string
(concat string
(if (not (string= string
"")) "." "")
1602 (setq idx
(1+ idx
)))
1604 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1605 (setq string
(replace-match "" t nil string
)))
1606 (if (string-match "\\(\\.0\\)+\\'" string
)
1607 (setq string
(replace-match "" t nil string
))))
1612 (defun org-export-handle-include-files ()
1613 "Include the contents of include files, with proper formatting."
1614 (let (params file markup lang start end
)
1615 (goto-char (point-min))
1616 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1617 (setq params
(read (concat "(" (match-string 1) ")"))
1618 file
(org-symname-or-string (pop params
))
1619 markup
(org-symname-or-string (pop params
))
1620 lang
(org-symname-or-string (pop params
)))
1621 (delete-region (match-beginning 0) (match-end 0))
1623 (not (file-exists-p file
))
1624 (not (file-readable-p file
)))
1625 (insert (format "CANNOT INCLUDE FILE %s" file
))
1627 (if (equal (downcase markup
) "src")
1628 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1630 (setq start
(format "#+begin_%s\n" markup
)
1631 end
(format "#+end_%s" markup
))))
1632 (insert (or start
""))
1633 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1634 (or (bolp) (newline))
1635 (insert (or end
""))))))
1637 (defun org-symname-or-string (s)
1639 (if s
(symbol-name s
) s
)
1642 ;;; Fontification of code
1643 ;; Currently only for th HTML backend, but who knows....
1644 (defun org-export-replace-src-segments ()
1645 "Replace source code segments with special code for export."
1646 (let (lang code trans
)
1647 (goto-char (point-min))
1648 (while (re-search-forward
1649 "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1651 (setq lang
(match-string 1) code
(match-string 2)
1652 trans
(org-export-format-source-code lang code
))
1653 (replace-match trans t t
))))
1655 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1657 (defun org-export-format-source-code (lang code
)
1658 "Format CODE from language LANG and return it formatted for export.
1659 Currently, this only does something for HTML export, for all other
1660 backends, it converts the segment into an EXAMPLE segment."
1664 ;; We are exporting to HTML
1665 (condition-case nil
(require 'htmlize
) (nil t
))
1666 (if (not (fboundp 'htmlize-region-for-paste
))
1668 ;; we do not have htmlize.el, or an old version of it
1670 "htmlize.el 1.34 or later is needed for source code formatting")
1671 (concat "#+BEGIN_EXAMPLE\n" code
1672 (if (string-match "\n\\'" code
) "" "\n")
1674 ;; ok, we are good to go
1675 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1676 (org-inhibit-startup t
)
1677 (org-startup-folded nil
)
1681 ;; Free up the protected stuff
1682 (goto-char (point-min))
1683 (while (re-search-forward "^," nil t
)
1685 (if (functionp mode
)
1688 (font-lock-fontify-buffer)
1689 (org-export-htmlize-region-for-paste
1690 (point-min) (point-max)))))
1691 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1692 (setq htmltext
(replace-match "<pre class=\"src\">"
1694 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1696 ;; This is not HTML, so just make it an example.
1697 (concat "#+BEGIN_EXAMPLE\n" code
1698 (if (string-match "\n\\'" code
) "" "\n")
1699 "#+END_EXAMPLE\n")))))
1703 (defvar org-last-level nil
) ; dynamically scoped variable
1704 (defvar org-min-level nil
) ; dynamically scoped variable
1705 (defvar org-levels-open nil
) ; dynamically scoped parameter
1706 (defvar org-ascii-current-indentation nil
) ; For communication
1709 (defun org-export-as-ascii (arg)
1710 "Export the outline as a pretty ASCII file.
1711 If there is an active region, export only the region.
1712 The prefix ARG specifies how many levels of the outline should become
1713 underlined headlines. The default is 3."
1715 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1716 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1717 (org-infile-export-plist)))
1718 (region-p (org-region-active-p))
1722 (goto-char (region-beginning))
1723 (and (org-at-heading-p)
1724 (>= (org-end-of-subtree t t
) (region-end))))))
1725 (custom-times org-display-custom-times
)
1726 (org-ascii-current-indentation '(0 .
0))
1730 (case-fold-search nil
)
1731 (filename (concat (file-name-as-directory
1732 (org-export-directory :ascii opt-plist
))
1733 (file-name-sans-extension
1735 (org-entry-get (region-beginning)
1736 "EXPORT_FILE_NAME" t
))
1737 (file-name-nondirectory buffer-file-name
)))
1739 (filename (if (equal (file-truename filename
)
1740 (file-truename buffer-file-name
))
1741 (concat filename
".txt")
1743 (buffer (find-file-noselect filename
))
1744 (org-levels-open (make-vector org-level-max nil
))
1745 (odd org-odd-levels-only
)
1746 (date (plist-get opt-plist
:date
))
1747 (author (plist-get opt-plist
:author
))
1748 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1749 (plist-get opt-plist
:title
)
1751 (plist-get opt-plist
:skip-before-1st-heading
))
1752 (org-export-grab-title-from-buffer))
1753 (file-name-sans-extension
1754 (file-name-nondirectory buffer-file-name
))))
1755 (email (plist-get opt-plist
:email
))
1756 (language (plist-get opt-plist
:language
))
1757 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1758 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1763 (if (org-region-active-p) (region-beginning) (point-min))
1764 (if (org-region-active-p) (region-end) (point-max))))
1765 (lines (org-split-string
1766 (org-export-preprocess-string
1769 :skip-before-1st-heading
1770 (plist-get opt-plist
:skip-before-1st-heading
)
1771 :drawers
(plist-get opt-plist
:drawers
)
1772 :verbatim-multiline t
1774 (plist-get opt-plist
:archived-trees
)
1775 :add-text
(plist-get opt-plist
:text
))
1777 thetoc have-headings first-heading-pos
1778 table-open table-buffer
)
1780 (let ((inhibit-read-only t
))
1782 (remove-text-properties (point-min) (point-max)
1783 '(:org-license-to-kill t
))))
1785 (setq org-min-level
(org-get-min-level lines
))
1786 (setq org-last-level org-min-level
)
1787 (org-init-section-numbers)
1789 (find-file-noselect filename
)
1791 (setq lang-words
(or (assoc language org-export-language-setup
)
1792 (assoc "en" org-export-language-setup
)))
1793 (switch-to-buffer-other-window buffer
)
1796 ;; create local variables for all options, to make sure all called
1797 ;; functions get the correct information
1799 (set (make-local-variable (cdr x
))
1800 (plist-get opt-plist
(car x
))))
1801 org-export-plist-vars
)
1802 (org-set-local 'org-odd-levels-only odd
)
1803 (setq umax
(if arg
(prefix-numeric-value arg
)
1804 org-export-headline-levels
))
1805 (setq umax-toc
(if (integerp org-export-with-toc
)
1806 (min org-export-with-toc umax
)
1810 (if title
(org-insert-centered title ?
=))
1812 (if (and (or author email
)
1813 org-export-author-info
)
1814 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1815 (if email
(concat " <" email
">") "")
1819 ((and date
(string-match "%" date
))
1820 (setq date
(format-time-string date
)))
1822 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1824 (if (and date org-export-time-stamp-file
)
1825 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1829 (if org-export-with-toc
1831 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1832 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1833 (mapc '(lambda (line)
1834 (if (string-match org-todo-line-regexp
1836 ;; This is a headline
1838 (setq have-headings t
)
1839 (setq level
(- (match-end 1) (match-beginning 1))
1840 level
(org-tr-level level
)
1841 txt
(match-string 3 line
)
1843 (or (and org-export-mark-todo-in-toc
1845 (not (member (match-string 2 line
)
1846 org-done-keywords
)))
1848 (and org-export-mark-todo-in-toc
1850 (org-search-todo-below
1851 line lines level
))))
1852 (setq txt
(org-html-expand-for-ascii txt
))
1854 (while (string-match org-bracket-link-regexp txt
)
1857 (match-string (if (match-end 2) 3 1) txt
)
1860 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1862 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1864 (setq txt
(replace-match "" t t txt
)))
1865 (if (string-match quote-re0 txt
)
1866 (setq txt
(replace-match "" t t txt
)))
1868 (if org-export-with-section-numbers
1869 (setq txt
(concat (org-section-number level
)
1871 (if (<= level umax-toc
)
1876 (* (max 0 (- level org-min-level
)) 4) ?\
)
1877 (format (if todo
"%s (*)\n" "%s\n") txt
))
1879 (setq org-last-level level
))
1882 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1884 (org-init-section-numbers)
1885 (while (setq line
(pop lines
))
1886 ;; Remove the quoted HTML tags.
1887 (setq line
(org-html-expand-for-ascii line
))
1889 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1890 (setq line
(replace-match "" t t line
)))
1891 ;; Replace internal links
1892 (while (string-match org-bracket-link-regexp line
)
1893 (setq line
(replace-match
1894 (if (match-end 3) "[\\3]" "[\\1]")
1897 (setq line
(org-translate-time line
)))
1899 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1901 (setq first-heading-pos
(or first-heading-pos
(point)))
1902 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1903 txt
(match-string 2 line
))
1904 (org-ascii-level-start level txt umax lines
))
1906 ((and org-export-with-tables
1907 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1908 (if (not table-open
)
1910 (setq table-open t table-buffer nil
))
1912 (setq table-buffer
(cons line table-buffer
))
1913 (when (or (not lines
)
1914 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1916 (setq table-open nil
1917 table-buffer
(nreverse table-buffer
))
1920 (org-fix-indentation x org-ascii-current-indentation
))
1921 (org-format-table-ascii table-buffer
)
1924 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1925 (if (and org-export-with-fixed-width
1926 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1927 (setq line
(replace-match "\\1" nil nil line
)))
1928 (insert line
"\n"))))
1932 ;; insert the table of contents
1934 (goto-char (point-min))
1935 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1937 (goto-char (match-beginning 0))
1939 (goto-char first-heading-pos
))
1940 (mapc 'insert thetoc
)
1941 (or (looking-at "[ \t]*\n[ \t]*\n")
1944 ;; Convert whitespace place holders
1945 (goto-char (point-min))
1947 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1948 (setq end
(next-single-property-change beg
'org-whitespace
))
1950 (delete-region beg end
)
1951 (insert (make-string (- end beg
) ?\
))))
1954 ;; remove display and invisible chars
1956 (goto-char (point-min))
1957 (while (setq beg
(next-single-property-change (point) 'display
))
1958 (setq end
(next-single-property-change beg
'display
))
1959 (delete-region beg end
)
1962 (goto-char (point-min))
1963 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1964 (setq end
(next-single-property-change beg
'org-cwidth
))
1965 (delete-region beg end
)
1967 (goto-char (point-min))))
1969 (defun org-export-ascii-clean-string ()
1970 "Do extra work for ASCII export"
1971 (goto-char (point-min))
1972 (while (re-search-forward org-verbatim-re nil t
)
1973 (goto-char (match-end 2))
1974 (backward-delete-char 1) (insert "'")
1975 (goto-char (match-beginning 2))
1976 (delete-char 1) (insert "`")
1977 (goto-char (match-end 2))))
1979 (defun org-search-todo-below (line lines level
)
1980 "Search the subtree below LINE for any TODO entries."
1981 (let ((rest (cdr (memq line lines
)))
1982 (re org-todo-line-regexp
)
1985 (while (setq line
(pop rest
))
1986 (if (string-match re line
)
1988 (setq lv
(- (match-end 1) (match-beginning 1))
1989 todo
(and (match-beginning 2)
1990 (not (member (match-string 2 line
)
1991 org-done-keywords
))))
1993 (if (<= lv level
) (throw 'exit nil
))
1994 (if todo
(throw 'exit t
))))))))
1996 (defun org-html-expand-for-ascii (line)
1997 "Handle quoted HTML for ASCII export."
1998 (if org-export-html-expand
1999 (while (string-match "@<[^<>\n]*>" line
)
2000 ;; We just remove the tags for now.
2001 (setq line
(replace-match "" nil nil line
))))
2004 (defun org-insert-centered (s &optional underline
)
2005 "Insert the string S centered and underline it with character UNDERLINE."
2006 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2007 (insert (make-string ind ?\
) s
"\n")
2009 (insert (make-string ind ?\
)
2010 (make-string (string-width s
) underline
)
2013 (defun org-ascii-level-start (level title umax
&optional lines
)
2014 "Insert a new level in ASCII export."
2015 (let (char (n (- level umax
1)) (ind 0))
2018 (insert (make-string (* 2 n
) ?\
)
2019 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2020 org-export-ascii-bullets
))
2022 ;; find the indentation of the next non-empty line
2025 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2026 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2027 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2029 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2030 (if (or (not (equal (char-before) ?
\n))
2031 (not (equal (char-before (1- (point))) ?
\n)))
2033 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2034 (unless org-export-with-tags
2035 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2036 (setq title
(replace-match "" t t title
))))
2037 (if org-export-with-section-numbers
2038 (setq title
(concat (org-section-number level
) " " title
)))
2039 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2040 (setq org-ascii-current-indentation
'(0 .
0)))))
2043 (defun org-export-visible (type arg
)
2044 "Create a copy of the visible part of the current buffer, and export it.
2045 The copy is created in a temporary buffer and removed after use.
2046 TYPE is the final key (as a string) that also select the export command in
2047 the `C-c C-e' export dispatcher.
2048 As a special case, if the you type SPC at the prompt, the temporary
2049 org-mode file will not be removed but presented to you so that you can
2050 continue to use it. The prefix arg ARG is passed through to the exporting
2054 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2055 (read-char-exclusive))
2056 current-prefix-arg
))
2057 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2058 (error "Invalid export key"))
2059 (let* ((binding (cdr (assoc type
2060 '((?a . org-export-as-ascii
)
2061 (?\C-a . org-export-as-ascii
)
2062 (?b . org-export-as-html-and-open
)
2063 (?\C-b . org-export-as-html-and-open
)
2064 (?h . org-export-as-html
)
2065 (?H . org-export-as-html-to-buffer
)
2066 (?R . org-export-region-as-html
)
2067 (?x . org-export-as-xoxo
)))))
2068 (keepp (equal type ?\
))
2069 (file buffer-file-name
)
2070 (buffer (get-buffer-create "*Org Export Visible*"))
2072 ;; Need to hack the drawers here.
2074 (goto-char (point-min))
2075 (while (re-search-forward org-drawer-regexp nil t
)
2076 (goto-char (match-beginning 1))
2077 (or (org-invisible-p) (org-flag-drawer nil
))))
2078 (with-current-buffer buffer
(erase-buffer))
2080 (setq s
(goto-char (point-min)))
2081 (while (not (= (point) (point-max)))
2082 (goto-char (org-find-invisible))
2083 (append-to-buffer buffer s
(point))
2084 (setq s
(goto-char (org-find-visible))))
2085 (org-cycle-hide-drawers 'all
)
2086 (goto-char (point-min))
2088 ;; Copy all comment lines to the end, to make sure #+ settings are
2089 ;; still available for the second export step. Kind of a hack, but
2090 ;; does do the trick.
2091 (if (looking-at "#[^\r\n]*")
2092 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2093 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2094 (append-to-buffer buffer
(1+ (match-beginning 0))
2095 (min (point-max) (1+ (match-end 0))))))
2097 (let ((buffer-file-name file
)
2098 (org-inhibit-startup t
))
2101 (unless keepp
(funcall binding arg
))))
2103 (kill-buffer buffer
)
2104 (switch-to-buffer-other-window buffer
)
2105 (goto-char (point-min)))))
2107 (defun org-find-visible ()
2109 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2110 (get-char-property s
'invisible
)))
2112 (defun org-find-invisible ()
2114 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2115 (not (get-char-property s
'invisible
))))
2120 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2121 (defun org-get-current-options ()
2122 "Return a string with current options as keyword options.
2123 Does include HTML export options as well as TODO and CATEGORY stuff."
2124 (require 'org-archive
)
2131 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2132 #+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
2139 #+PRIORITIES: %c %c %c
2141 #+STARTUP: %s %s %s %s %s
2146 (buffer-name) (user-full-name) user-mail-address
2147 (format-time-string (car org-time-stamp-formats
))
2148 org-export-default-language
2149 org-export-headline-levels
2150 org-export-with-section-numbers
2152 org-export-preserve-breaks
2153 org-export-html-expand
2154 org-export-with-fixed-width
2155 org-export-with-tables
2156 org-export-with-sub-superscripts
2157 org-export-with-special-strings
2158 org-export-with-footnotes
2159 org-export-with-emphasize
2160 org-export-with-TeX-macros
2161 org-export-with-LaTeX-fragments
2162 org-export-skip-text-before-1st-heading
2163 org-export-with-drawers
2164 org-export-with-tags
2165 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2166 org-export-html-link-up
2167 org-export-html-link-home
2168 (file-name-nondirectory buffer-file-name
)
2169 "TODO FEEDBACK VERIFY DONE"
2170 "Me Jason Marie DONE"
2171 org-highest-priority org-lowest-priority org-default-priority
2172 (mapconcat 'identity org-drawers
" ")
2173 (cdr (assoc org-startup-folded
2174 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2175 (if org-odd-levels-only
"odd" "oddeven")
2176 (if org-hide-leading-stars
"hidestars" "showstars")
2177 (if org-startup-align-all-tables
"align" "noalign")
2178 (cond ((eq org-log-done t
) "logdone")
2179 ((equal org-log-done
'note
) "lognotedone")
2180 ((not org-log-done
) "nologdone"))
2181 (or (mapconcat (lambda (x)
2183 ((equal '(:startgroup
) x
) "{")
2184 ((equal '(:endgroup
) x
) "}")
2185 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2187 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2188 org-archive-location
2189 "org file:~/org/%s.org"
2193 (defun org-insert-export-options-template ()
2194 "Insert into the buffer a template with information for exporting."
2196 (if (not (bolp)) (newline))
2197 (let ((s (org-get-current-options)))
2198 (and (string-match "#\\+CATEGORY" s
)
2199 (setq s
(substring s
0 (match-beginning 0))))
2203 (defun org-export-as-html-and-open (arg)
2204 "Export the outline as HTML and immediately open it with a browser.
2205 If there is an active region, export only the region.
2206 The prefix ARG specifies how many levels of the outline should become
2207 headlines. The default is 3. Lower levels will become bulleted lists."
2209 (org-export-as-html arg
'hidden
)
2210 (org-open-file buffer-file-name
))
2213 (defun org-export-as-html-batch ()
2214 "Call `org-export-as-html', may be used in batch processing as
2216 --load=$HOME/lib/emacs/org.el
2217 --eval \"(setq org-export-headline-levels 2)\"
2218 --visit=MyFile --funcall org-export-as-html-batch"
2219 (org-export-as-html org-export-headline-levels
'hidden
))
2222 (defun org-export-as-html-to-buffer (arg)
2223 "Call `org-exort-as-html` with output to a temporary buffer.
2224 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2226 (org-export-as-html arg nil nil
"*Org HTML Export*")
2227 (switch-to-buffer-other-window "*Org HTML Export*"))
2230 (defun org-replace-region-by-html (beg end
)
2231 "Assume the current region has org-mode syntax, and convert it to HTML.
2232 This can be used in any buffer. For example, you could write an
2233 itemized list in org-mode syntax in an HTML buffer and then use this
2234 command to convert it."
2236 (let (reg html buf pop-up-frames
)
2237 (save-window-excursion
2239 (setq html
(org-export-region-as-html
2241 (setq reg
(buffer-substring beg end
)
2242 buf
(get-buffer-create "*Org tmp*"))
2243 (with-current-buffer buf
2247 (setq html
(org-export-region-as-html
2248 (point-min) (point-max) t
'string
)))
2250 (delete-region beg end
)
2254 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2255 "Convert region from BEG to END in org-mode buffer to HTML.
2256 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2257 contents, and only produce the region of converted text, useful for
2258 cut-and-paste operations.
2259 If BUFFER is a buffer or a string, use/create that buffer as a target
2260 of the converted HTML. If BUFFER is the symbol `string', return the
2261 produced HTML as a string and leave not buffer behind. For example,
2262 a Lisp program could call this function in the following way:
2264 (setq html (org-export-region-as-html beg end t 'string))
2266 When called interactively, the output buffer is selected, and shown
2267 in a window. A non-interactive call will only return the buffer."
2268 (interactive "r\nP")
2269 (when (interactive-p)
2270 (setq buffer
"*Org HTML Export*"))
2271 (let ((transient-mark-mode t
) (zmacs-regions t
)
2274 (set-mark (point)) ;; to activate the region
2276 (setq rtn
(org-export-as-html
2279 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2280 (if (and (interactive-p) (bufferp rtn
))
2281 (switch-to-buffer-other-window rtn
)
2284 (defvar html-table-tag nil
) ; dynamically scoped into this.
2286 (defun org-export-as-html (arg &optional hidden ext-plist
2287 to-buffer body-only pub-dir
)
2288 "Export the outline as a pretty HTML file.
2289 If there is an active region, export only the region. The prefix
2290 ARG specifies how many levels of the outline should become
2291 headlines. The default is 3. Lower levels will become bulleted
2292 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2293 EXT-PLIST is a property list with external parameters overriding
2294 org-mode's default settings, but still inferior to file-local
2295 settings. When TO-BUFFER is non-nil, create a buffer with that
2296 name and export to that buffer. If TO-BUFFER is the symbol
2297 `string', don't leave any buffer behind but just return the
2298 resulting HTML as a string. When BODY-ONLY is set, don't produce
2299 the file header and footer, simply return the content of
2300 <body>...</body>, without even the body tags themselves. When
2301 PUB-DIR is set, use this as the publishing directory."
2304 ;; Make sure we have a file name when we need it.
2305 (when (and (not (or to-buffer body-only
))
2306 (not buffer-file-name
))
2307 (if (buffer-base-buffer)
2308 (org-set-local 'buffer-file-name
2309 (with-current-buffer (buffer-base-buffer)
2311 (error "Need a file name to be able to export.")))
2313 (message "Exporting...")
2314 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2315 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2316 (setq-default org-done-keywords org-done-keywords
)
2317 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2319 (org-export-process-option-filters
2320 (org-combine-plists (org-default-export-plist)
2322 (org-infile-export-plist))))
2324 (style (plist-get opt-plist
:style
))
2325 (html-extension (plist-get opt-plist
:html-extension
))
2326 (link-validate (plist-get opt-plist
:link-validation-function
))
2327 valid thetoc have-headings first-heading-pos
2328 (odd org-odd-levels-only
)
2329 (region-p (org-region-active-p))
2333 (goto-char (region-beginning))
2334 (and (org-at-heading-p)
2335 (>= (org-end-of-subtree t t
) (region-end))))))
2336 ;; The following two are dynamically scoped into other
2338 (org-current-export-dir
2339 (or pub-dir
(org-export-directory :html opt-plist
)))
2340 (org-current-export-file buffer-file-name
)
2341 (level 0) (line "") (origline "") txt todo
2344 (filename (if to-buffer nil
2347 (file-name-sans-extension
2349 (org-entry-get (region-beginning)
2350 "EXPORT_FILE_NAME" t
))
2351 (file-name-nondirectory buffer-file-name
)))
2353 (file-name-as-directory
2354 (or pub-dir
(org-export-directory :html opt-plist
))))))
2355 (current-dir (if buffer-file-name
2356 (file-name-directory buffer-file-name
)
2358 (buffer (if to-buffer
2360 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2361 (t (get-buffer-create to-buffer
)))
2362 (find-file-noselect filename
)))
2363 (org-levels-open (make-vector org-level-max nil
))
2364 (date (plist-get opt-plist
:date
))
2365 (author (plist-get opt-plist
:author
))
2366 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2367 (plist-get opt-plist
:title
)
2369 (plist-get opt-plist
:skip-before-1st-heading
))
2370 (org-export-grab-title-from-buffer))
2371 (and buffer-file-name
2372 (file-name-sans-extension
2373 (file-name-nondirectory buffer-file-name
)))
2375 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2376 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2377 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2381 (local-list-type nil
)
2382 (local-list-indent nil
)
2383 (llt org-plain-list-ordered-item-terminator
)
2384 (email (plist-get opt-plist
:email
))
2385 (language (plist-get opt-plist
:language
))
2389 (coding-system (and (boundp 'buffer-file-coding-system
)
2390 buffer-file-coding-system
))
2391 (coding-system-for-write (or org-export-html-coding-system
2393 (save-buffer-coding-system (or org-export-html-coding-system
2395 (charset (and coding-system-for-write
2396 (fboundp 'coding-system-get
)
2397 (coding-system-get coding-system-for-write
2401 (if region-p
(region-beginning) (point-min))
2402 (if region-p
(region-end) (point-max))))
2405 (org-export-preprocess-string
2409 :skip-before-1st-heading
2410 (plist-get opt-plist
:skip-before-1st-heading
)
2411 :drawers
(plist-get opt-plist
:drawers
)
2413 (plist-get opt-plist
:archived-trees
)
2415 (plist-get opt-plist
:text
)
2417 (plist-get opt-plist
:LaTeX-fragments
))
2420 table-buffer table-orig-buffer
2421 ind item-type starter didclose
2422 rpl path desc descp desc1 desc2 link
2423 snumber fnc item-tag
2426 (let ((inhibit-read-only t
))
2428 (remove-text-properties (point-min) (point-max)
2429 '(:org-license-to-kill t
))))
2431 (message "Exporting...")
2433 (setq org-min-level
(org-get-min-level lines
))
2434 (setq org-last-level org-min-level
)
2435 (org-init-section-numbers)
2438 ((and date
(string-match "%" date
))
2439 (setq date
(format-time-string date
)))
2441 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2443 ;; Get the language-dependent settings
2444 (setq lang-words
(or (assoc language org-export-language-setup
)
2445 (assoc "en" org-export-language-setup
)))
2447 ;; Switch to the output buffer
2449 (let ((inhibit-read-only t
)) (erase-buffer))
2452 (and (fboundp 'set-buffer-file-coding-system
)
2453 (set-buffer-file-coding-system coding-system-for-write
))
2455 (let ((case-fold-search nil
)
2456 (org-odd-levels-only odd
))
2457 ;; create local variables for all options, to make sure all called
2458 ;; functions get the correct information
2460 (set (make-local-variable (cdr x
))
2461 (plist-get opt-plist
(car x
))))
2462 org-export-plist-vars
)
2463 (setq umax
(if arg
(prefix-numeric-value arg
)
2464 org-export-headline-levels
))
2465 (setq umax-toc
(if (integerp org-export-with-toc
)
2466 (min org-export-with-toc umax
)
2471 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2472 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2473 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2474 lang=\"%s\" xml:lang=\"%s\">
2477 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2478 <meta name=\"generator\" content=\"Org-mode\"/>
2479 <meta name=\"generated\" content=\"%s\"/>
2480 <meta name=\"author\" content=\"%s\"/>
2484 language language
(org-html-expand title
)
2485 (or charset
"iso-8859-1") date author style
))
2487 (insert (or (plist-get opt-plist
:preamble
) ""))
2489 (when (plist-get opt-plist
:auto-preamble
)
2490 (if title
(insert (format org-export-html-title-format
2491 (org-html-expand title
))))))
2493 (if (and org-export-with-toc
(not body-only
))
2495 (push (format "<h%d>%s</h%d>\n"
2496 org-export-html-toplevel-hlevel
2498 org-export-html-toplevel-hlevel
)
2500 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2501 (push "<ul>\n<li>" thetoc
)
2503 (mapcar '(lambda (line)
2504 (if (string-match org-todo-line-regexp line
)
2505 ;; This is a headline
2507 (setq have-headings t
)
2508 (setq level
(- (match-end 1) (match-beginning 1))
2509 level
(org-tr-level level
)
2510 txt
(save-match-data
2512 (org-export-cleanup-toc-line
2513 (match-string 3 line
))))
2515 (or (and org-export-mark-todo-in-toc
2517 (not (member (match-string 2 line
)
2518 org-done-keywords
)))
2520 (and org-export-mark-todo-in-toc
2522 (org-search-todo-below
2523 line lines level
))))
2525 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2526 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2527 (if (string-match quote-re0 txt
)
2528 (setq txt
(replace-match "" t t txt
)))
2529 (setq snumber
(org-section-number level
))
2530 (if org-export-with-section-numbers
2531 (setq txt
(concat snumber
" " txt
)))
2532 (if (<= level
(max umax umax-toc
))
2533 (setq head-count
(+ head-count
1)))
2534 (if (<= level umax-toc
)
2536 (if (> level org-last-level
)
2538 (setq cnt
(- level org-last-level
))
2539 (while (>= (setq cnt
(1- cnt
)) 0)
2540 (push "\n<ul>\n<li>" thetoc
))
2541 (push "\n" thetoc
)))
2542 (if (< level org-last-level
)
2544 (setq cnt
(- org-last-level level
))
2545 (while (>= (setq cnt
(1- cnt
)) 0)
2546 (push "</li>\n</ul>" thetoc
))
2547 (push "\n" thetoc
)))
2548 ;; Check for targets
2549 (while (string-match org-any-target-regexp line
)
2550 (setq line
(replace-match
2551 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2553 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2554 (setq txt
(replace-match "" t t txt
)))
2558 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2559 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2560 snumber txt
) thetoc
)
2562 (setq org-last-level level
))
2566 (while (> org-last-level
(1- org-min-level
))
2567 (setq org-last-level
(1- org-last-level
))
2568 (push "</li>\n</ul>\n" thetoc
))
2569 (push "</div>\n" thetoc
)
2570 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2573 (org-init-section-numbers)
2575 (while (setq line
(pop lines
) origline line
)
2578 ;; end of quote section?
2579 (when (and inquote
(string-match "^\\*+ " line
))
2582 ;; inside a quote section?
2584 (insert (org-html-protect line
) "\n")
2585 (throw 'nextline nil
))
2588 (when (and org-export-with-fixed-width
2589 (string-match "^[ \t]*:\\(.*\\)" line
))
2593 (insert (org-html-protect (match-string 1 line
)) "\n")
2595 (not (string-match "^[ \t]*\\(:.*\\)"
2598 (insert "</pre>\n"))
2599 (throw 'nextline nil
))
2602 (when (get-text-property 0 'org-protected line
)
2604 (when (re-search-backward
2605 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2606 (setq par
(match-string 1))
2607 (replace-match "\\2\n"))
2610 (not (string-match "^[ \t]*:" (car lines
)))
2611 (or (= (length (car lines
)) 0)
2612 (get-text-property 0 'org-protected
(car lines
))))
2613 (insert (pop lines
) "\n"))
2614 (and par
(insert "<p>\n")))
2615 (throw 'nextline nil
))
2618 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2619 (insert "\n<hr/>\n")
2620 (throw 'nextline nil
))
2623 (when (equal "ORG-BLOCKQUOTE-START" line
)
2624 (insert "<blockquote>\n<p>\n")
2625 (throw 'nextline nil
))
2626 (when (equal "ORG-BLOCKQUOTE-END" line
)
2627 (insert "</p>\n</blockquote>\n")
2628 (throw 'nextline nil
))
2630 ;; make targets to anchors
2631 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2634 (setq line
(replace-match
2635 (concat "@<a name=\""
2636 (org-solidify-link-text (match-string 1 line
))
2639 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2640 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2641 (setq line
(replace-match
2642 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2643 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2646 (setq line
(replace-match
2647 (concat "@<a name=\""
2648 (org-solidify-link-text (match-string 1 line
))
2649 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2652 (setq line
(org-html-handle-time-stamps line
))
2654 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2655 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2656 ;; Also handle sub_superscripts and checkboxes
2657 (or (string-match org-table-hline-regexp line
)
2658 (setq line
(org-html-expand line
)))
2662 (while (string-match org-bracket-link-analytic-regexp line start
)
2663 (setq start
(match-beginning 0))
2664 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2665 (setq path
(match-string 3 line
))
2666 (setq desc1
(if (match-end 5) (match-string 5 line
))
2667 desc2
(if (match-end 2) (concat type
":" path
) path
)
2668 descp
(and desc1
(not (equal desc1 desc2
)))
2669 desc
(or desc1 desc2
))
2670 ;; Make an image out of the description if that is so wanted
2671 (when (and descp
(org-file-image-p desc
))
2673 (if (string-match "^file:" desc
)
2674 (setq desc
(substring desc
(match-end 0)))))
2675 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2676 ;; FIXME: do we need to unescape here somewhere?
2678 ((equal type
"internal")
2682 (org-solidify-link-text
2683 (save-match-data (org-link-unescape path
)) nil
)
2684 "\">" desc
"</a>")))
2685 ((member type
'("http" "https"))
2686 ;; standard URL, just check if we need to inline an image
2687 (if (and (or (eq t org-export-html-inline-images
)
2688 (and org-export-html-inline-images
(not descp
)))
2689 (org-file-image-p path
))
2690 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2691 (setq link
(concat type
":" path
))
2692 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2693 ((member type
'("ftp" "mailto" "news"))
2695 (setq link
(concat type
":" path
))
2696 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2697 ((string= type
"file")
2699 (let* ((filename path
)
2700 (abs-p (file-name-absolute-p filename
))
2701 thefile file-is-image-p search
)
2703 (if (string-match "::\\(.*\\)" filename
)
2704 (setq search
(match-string 1 filename
)
2705 filename
(replace-match "" t nil filename
)))
2707 (if (functionp link-validate
)
2708 (funcall link-validate filename current-dir
)
2710 (setq file-is-image-p
(org-file-image-p filename
))
2711 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2712 (when (and org-export-html-link-org-files-as-html
2713 (string-match "\\.org$" thefile
))
2714 (setq thefile
(concat (substring thefile
0
2715 (match-beginning 0))
2716 "." html-extension
))
2718 ;; make sure this is can be used as target search
2719 (not (string-match "^[0-9]*$" search
))
2720 (not (string-match "^\\*" search
))
2721 (not (string-match "^/.*/$" search
)))
2722 (setq thefile
(concat thefile
"#"
2723 (org-solidify-link-text
2724 (org-link-unescape search
)))))
2725 (when (string-match "^file:" desc
)
2726 (setq desc
(replace-match "" t t desc
))
2727 (if (string-match "\\.org$" desc
)
2728 (setq desc
(replace-match "" t t desc
))))))
2729 (setq rpl
(if (and file-is-image-p
2730 (or (eq t org-export-html-inline-images
)
2731 (and org-export-html-inline-images
2733 (concat "<img src=\"" thefile
"\"/>")
2734 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2735 (if (not valid
) (setq rpl desc
))))
2737 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2740 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2743 ;; just publish the path, as default
2744 (setq rpl
(concat "<i><" type
":"
2745 (save-match-data (org-link-unescape path
))
2747 (setq line
(replace-match rpl t t line
)
2748 start
(+ start
(length rpl
))))
2751 (if (and (string-match org-todo-line-regexp line
)
2752 (match-beginning 2))
2755 (concat (substring line
0 (match-beginning 2))
2757 (if (member (match-string 2 line
)
2760 "\">" (match-string 2 line
)
2761 "</span>" (substring line
(match-end 2)))))
2763 ;; Does this contain a reference to a footnote?
2764 (when org-export-with-footnotes
2766 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2767 (if (get-text-property (match-beginning 2) 'org-protected line
)
2768 (setq start
(match-end 2))
2769 (let ((n (match-string 2 line
)))
2773 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2774 (match-string 1 line
) n n n
)
2778 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2779 ;; This is a headline
2780 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2781 txt
(match-string 2 line
))
2782 (if (string-match quote-re0 txt
)
2783 (setq txt
(replace-match "" t t txt
)))
2784 (if (<= level
(max umax umax-toc
))
2785 (setq head-count
(+ head-count
1)))
2787 ;; Close any local lists before inserting a new header line
2788 (while local-list-type
2789 (org-close-li (car local-list-type
))
2790 (insert (format "</%sl>\n" (car local-list-type
)))
2791 (pop local-list-type
))
2792 (setq local-list-indent nil
2794 (setq first-heading-pos
(or first-heading-pos
(point)))
2795 (org-html-level-start level txt umax
2796 (and org-export-with-toc
(<= level umax
))
2799 (when (string-match quote-re line
)
2803 ((and org-export-with-tables
2804 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2805 (if (not table-open
)
2807 (setq table-open t table-buffer nil table-orig-buffer nil
))
2809 (setq table-buffer
(cons line table-buffer
)
2810 table-orig-buffer
(cons origline table-orig-buffer
))
2811 (when (or (not lines
)
2812 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2814 (setq table-open nil
2815 table-buffer
(nreverse table-buffer
)
2816 table-orig-buffer
(nreverse table-orig-buffer
))
2817 (org-close-par-maybe)
2818 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2823 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2824 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2825 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2826 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2828 (setq ind
(org-get-string-indentation line
)
2829 item-type
(if (match-beginning 4) "o" "u")
2830 starter
(if (match-beginning 2)
2831 (substring (match-string 2 line
) 0 -
1))
2832 line
(substring line
(match-beginning 5))
2834 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2836 item-tag
(match-string 1 line
)
2837 line
(substring line
(match-end 0))))
2838 (unless (string-match "[^ \t]" line
)
2839 ;; empty line. Pretend indentation is large.
2840 (setq ind
(if org-empty-line-terminates-plain-lists
2842 (1+ (or (car local-list-indent
) 1)))))
2844 (while (and in-local-list
2845 (or (and (= ind
(car local-list-indent
))
2847 (< ind
(car local-list-indent
))))
2849 (org-close-li (car local-list-type
))
2850 (insert (format "</%sl>\n" (car local-list-type
)))
2851 (pop local-list-type
) (pop local-list-indent
)
2852 (setq in-local-list local-list-indent
))
2855 (or (not in-local-list
)
2856 (> ind
(car local-list-indent
))))
2857 ;; Start new (level of) list
2858 (org-close-par-maybe)
2860 ((equal item-type
"u") "<ul>\n<li>\n")
2861 ((equal item-type
"o") "<ol>\n<li>\n")
2862 ((equal item-type
"d")
2863 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2864 (push item-type local-list-type
)
2865 (push ind local-list-indent
)
2866 (setq in-local-list t
))
2868 ;; continue current list
2869 (org-close-li (car local-list-type
))
2871 ((equal (car local-list-type
) "d")
2872 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2875 ;; we did close a list, normal text follows: need <p>
2877 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2880 (if (equal (match-string 1 line
) "X")
2882 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2885 ;; Empty lines start a new paragraph. If hand-formatted lists
2886 ;; are not fully interpreted, lines starting with "-", "+", "*"
2887 ;; also start a new paragraph.
2888 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2890 ;; Is this the start of a footnote?
2891 (when org-export-with-footnotes
2892 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2893 (org-close-par-maybe)
2894 (let ((n (match-string 1 line
)))
2895 (setq line
(replace-match
2896 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2898 ;; Check if the line break needs to be conserved
2900 ((string-match "\\\\\\\\[ \t]*$" line
)
2901 (setq line
(replace-match "<br/>" t t line
)))
2902 (org-export-preserve-breaks
2903 (setq line
(concat line
"<br/>"))))
2905 (insert line
"\n")))))
2907 ;; Properly close all local lists and other lists
2908 (when inquote
(insert "</pre>\n"))
2910 ;; Close any local lists before inserting a new header line
2911 (while local-list-type
2912 (org-close-li (car local-list-type
))
2913 (insert (format "</%sl>\n" (car local-list-type
)))
2914 (pop local-list-type
))
2915 (setq local-list-indent nil
2917 (org-html-level-start 1 nil umax
2918 (and org-export-with-toc
(<= level umax
))
2920 ;; the </div> to lose the last text-... div.
2924 (when (plist-get opt-plist
:auto-postamble
)
2925 (insert "<div id=\"postamble\">")
2926 (when (and org-export-author-info author
)
2927 (insert "<p class=\"author\"> "
2928 (nth 1 lang-words
) ": " author
"\n")
2930 (if (listp (split-string email
",+ *"))
2932 (insert "<a href=\"mailto:" e
"\"><"
2934 (split-string email
",+ *"))
2935 (insert "<a href=\"mailto:" email
"\"><"
2936 email
"></a>\n")))
2938 (when (and date org-export-time-stamp-file
)
2939 (insert "<p class=\"date\"> "
2940 (nth 2 lang-words
) ": "
2944 (if org-export-html-with-timestamp
2945 (insert org-export-html-html-helper-timestamp
))
2946 (insert (or (plist-get opt-plist
:postamble
) ""))
2947 (insert "</body>\n</html>\n"))
2950 (if (eq major-mode default-major-mode
) (html-mode))
2952 ;; insert the table of contents
2953 (goto-char (point-min))
2955 (if (or (re-search-forward
2956 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2958 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2960 (goto-char (match-beginning 0))
2962 (goto-char first-heading-pos
)
2963 (when (looking-at "\\s-*</p>")
2964 (goto-char (match-end 0))
2966 (insert "<div id=\"table-of-contents\">\n")
2967 (mapc 'insert thetoc
)
2968 (insert "</div>\n"))
2969 ;; remove empty paragraphs and lists
2970 (goto-char (point-min))
2971 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2973 (goto-char (point-min))
2974 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2976 (goto-char (point-min))
2977 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2979 ;; Convert whitespace place holders
2980 (goto-char (point-min))
2982 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
2983 (setq n
(get-text-property beg
'org-whitespace
)
2984 end
(next-single-property-change beg
'org-whitespace
))
2986 (delete-region beg end
)
2987 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
2988 (make-string n ?x
)))))
2989 (or to-buffer
(save-buffer))
2990 (goto-char (point-min))
2991 (message "Exporting... done")
2992 (if (eq to-buffer
'string
)
2993 (prog1 (buffer-substring (point-min) (point-max))
2994 (kill-buffer (current-buffer)))
2995 (current-buffer)))))
2997 (defvar org-table-colgroup-info nil
)
2998 (defun org-format-table-ascii (lines)
2999 "Format a table for ascii export."
3001 (setq lines
(org-split-string lines
"\n")))
3002 (if (not (string-match "^[ \t]*|" (car lines
)))
3003 ;; Table made by table.el - test for spanning
3006 ;; A normal org table
3007 ;; Get rid of hlines at beginning and end
3008 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3009 (setq lines
(nreverse lines
))
3010 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3011 (setq lines
(nreverse lines
))
3012 (when org-export-table-remove-special-lines
3013 ;; Check if the table has a marking column. If yes remove the
3014 ;; column and the special lines
3015 (setq lines
(org-table-clean-before-export lines
)))
3016 ;; Get rid of the vertical lines except for grouping
3017 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3019 (while (setq line
(pop lines
))
3020 (if (string-match org-table-hline-regexp line
)
3021 (and (string-match "|\\(.*\\)|" line
)
3022 (setq line
(replace-match " \\1" t nil line
)))
3023 (setq start
0 vl1 vl
)
3024 (while (string-match "|" line start
)
3025 (setq start
(match-end 0))
3026 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3030 (defun org-colgroup-info-to-vline-list (info)
3033 (setq last new new
(pop info
))
3034 (if (or (memq last
'(:end
:startend
))
3035 (memq new
'(:start
:startend
)))
3038 (setq vl
(nreverse vl
))
3039 (and vl
(setcar vl nil
))
3042 (defvar org-table-number-regexp
) ; defined in org-table.el
3043 (defun org-format-table-html (lines olines
)
3044 "Find out which HTML converter to use and return the HTML code."
3046 (setq lines
(org-split-string lines
"\n")))
3047 (if (string-match "^[ \t]*|" (car lines
))
3048 ;; A normal org table
3049 (org-format-org-table-html lines
)
3050 ;; Table made by table.el - test for spanning
3051 (let* ((hlines (delq nil
(mapcar
3053 (if (string-match "^[ \t]*\\+-" x
) x
3056 (first (car hlines
))
3057 (ll (and (string-match "\\S-+" first
)
3058 (match-string 0 first
)))
3059 (re (concat "^[ \t]*" (regexp-quote ll
)))
3060 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3062 (if (and (not spanning
)
3063 (not org-export-prefer-native-exporter-for-tables
))
3064 ;; We can use my own converter with HTML conversions
3065 (org-format-table-table-html lines
)
3066 ;; Need to use the code generator in table.el, with the original text.
3067 (org-format-table-table-html-using-table-generate-source olines
)))))
3069 (defvar org-table-number-fraction
) ; defined in org-table.el
3070 (defun org-format-org-table-html (lines &optional splice
)
3071 "Format a table into HTML."
3072 (require 'org-table
)
3073 ;; Get rid of hlines at beginning and end
3074 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3075 (setq lines
(nreverse lines
))
3076 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3077 (setq lines
(nreverse lines
))
3078 (when org-export-table-remove-special-lines
3079 ;; Check if the table has a marking column. If yes remove the
3080 ;; column and the special lines
3081 (setq lines
(org-table-clean-before-export lines
)))
3083 (let ((head (and org-export-highlight-first-table-line
3085 (lambda (x) (string-match "^[ \t]*|-" x
))
3088 tbopen line fields html gr colgropen
)
3089 (if splice
(setq head nil
))
3090 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3092 (while (setq line
(pop lines
))
3094 (if (string-match "^[ \t]*|-" line
)
3097 (push (if head
"</thead>" "</tbody>") html
)
3098 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3099 (setq head nil
) ;; head ends here, first time around
3101 (throw 'next-line t
)))
3102 ;; Break the line into fields
3103 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3104 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3105 (setq nlines
(1+ nlines
) i -
1)
3106 (push (concat "<tr>"
3110 (if (and (< i nlines
)
3111 (string-match org-table-number-regexp x
))
3112 (incf (aref fnum i
)))
3114 (concat (car org-export-table-header-tags
) x
3115 (cdr org-export-table-header-tags
))
3116 (concat (car org-export-table-data-tags
) x
3117 (cdr org-export-table-data-tags
))))
3121 (unless splice
(if tbopen
(push "</tbody>" html
)))
3122 (unless splice
(push "</table>\n" html
))
3123 (setq html
(nreverse html
))
3125 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3128 (setq gr
(pop org-table-colgroup-info
))
3129 (format "%s<col align=\"%s\"></col>%s"
3130 (if (memq gr
'(:start
:startend
))
3132 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3135 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3137 (if (memq gr
'(:end
:startend
))
3138 (progn (setq colgropen nil
) "</colgroup>")
3142 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3143 (push html-table-tag html
))
3144 (concat (mapconcat 'identity html
"\n") "\n")))
3146 (defun org-table-clean-before-export (lines)
3147 "Check if the table has a marking column.
3148 If yes remove the column and the special lines."
3149 (setq org-table-colgroup-info nil
)
3152 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3153 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3156 (setq org-table-clean-did-remove-column nil
)
3161 ((string-match "^[ \t]*| */ *|" x
)
3162 (setq org-table-colgroup-info
3164 (cond ((member x
'("<" "<")) :start
)
3165 ((member x
'(">" ">")) :end
)
3166 ((member x
'("<>" "<>")) :startend
)
3168 (org-split-string x
"[ \t]*|[ \t]*")))
3172 (setq org-table-clean-did-remove-column t
)
3177 ((string-match "^[ \t]*| */ *|" x
)
3178 (setq org-table-colgroup-info
3180 (cond ((member x
'("<" "<")) :start
)
3181 ((member x
'(">" ">")) :end
)
3182 ((member x
'("<>" "<>")) :startend
)
3184 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3186 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3187 nil
) ; ignore this line
3188 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3189 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3190 ;; remove the first column
3191 (replace-match "\\1|" t nil x
))))
3194 (defun org-format-table-table-html (lines)
3195 "Format a table generated by table.el into HTML.
3196 This conversion does *not* use `table-generate-source' from table.el.
3197 This has the advantage that Org-mode's HTML conversions can be used.
3198 But it has the disadvantage, that no cell- or row-spanning is allowed."
3199 (let (line field-buffer
3200 (head org-export-highlight-first-table-line
)
3202 (setq html
(concat html-table-tag
"\n"))
3203 (while (setq line
(pop lines
))
3204 (setq empty
" ")
3206 (if (string-match "^[ \t]*\\+-" line
)
3217 (if (equal x
"") (setq x empty
))
3219 (concat (car org-export-table-header-tags
) x
3220 (cdr org-export-table-header-tags
))
3221 (concat (car org-export-table-data-tags
) x
3222 (cdr org-export-table-data-tags
))))
3226 (setq field-buffer nil
)))
3228 (throw 'next-line t
)))
3229 ;; Break the line into fields and store the fields
3230 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3232 (setq field-buffer
(mapcar
3234 (concat x
"<br/>" (pop fields
)))
3236 (setq field-buffer fields
))))
3237 (setq html
(concat html
"</table>\n"))
3240 (defun org-format-table-table-html-using-table-generate-source (lines)
3241 "Format a table into html, using `table-generate-source' from table.el.
3242 This has the advantage that cell- or row-spanning is allowed.
3243 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3245 (with-current-buffer (get-buffer-create " org-tmp1 ")
3247 (insert (mapconcat 'identity lines
"\n"))
3248 (goto-char (point-min))
3249 (if (not (re-search-forward "|[^+]" nil t
))
3250 (error "Error processing table"))
3251 (table-recognize-table)
3252 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3253 (table-generate-source 'html
" org-tmp2 ")
3254 (set-buffer " org-tmp2 ")
3255 (buffer-substring (point-min) (point-max))))
3257 (defun org-html-handle-time-stamps (s)
3258 "Format time stamps in string S, or remove them."
3261 (while (string-match org-maybe-keyword-time-regexp s
)
3262 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3263 ;; never export CLOCK
3265 (or b
(setq b
(substring s
0 (match-beginning 0))))
3266 (if (not org-export-with-timestamps
)
3267 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3268 s
(substring s
(match-end 0)))
3270 r
(substring s
0 (match-beginning 0))
3272 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3273 (match-string 1 s
)))
3274 (format " @<span class=\"timestamp\">%s@</span>"
3276 (org-translate-time (match-string 3 s
)) 1 -
1)))
3277 s
(substring s
(match-end 0)))))
3278 ;; Line break if line started and ended with time stamp stuff
3281 (setq r
(concat r s
))
3282 (unless (string-match "\\S-" (concat b s
))
3283 (setq r
(concat r
"@<br/>")))
3286 (defun org-export-htmlize-region-for-paste (beg end
)
3287 "Convert the region to HTML, using htmlize.el.
3288 This is much like `htmlize-region-for-paste', only that it uses
3289 the settings define in the org-... variables."
3290 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3291 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3292 (htmlbuf (htmlize-region beg end
)))
3294 (with-current-buffer htmlbuf
3295 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3296 (plist-get htmlize-buffer-places
'content-end
)))
3297 (kill-buffer htmlbuf
))))
3300 (defun org-export-htmlize-generate-css ()
3301 "Create the CSS for all font definitions in the current Emacs session.
3302 Use this to create face definitions in your CSS style file that can then
3303 be used by code snippets transformed by htmlize.
3304 This command just produces a buffer that contains class definitions for all
3305 faces used in the current Emacs session. You can copy and paste the ones you
3306 need into your CSS file.
3308 If you then set `org-export-htmlize-output-type' to `css', calls to
3309 the function `org-export-htmlize-region-for-paste' will produce code
3310 that uses these same face definitions."
3313 (and (get-buffer "*html*") (kill-buffer "*html*"))
3315 (let ((fl (face-list))
3316 (htmlize-css-name-prefix "org-")
3317 (htmlize-output-type 'css
)
3319 (while (setq f
(pop fl
)
3320 i
(and f
(face-attribute f
:inherit
)))
3321 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3322 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3323 (htmlize-region (point-min) (point-max))))
3324 (switch-to-buffer "*html*")
3325 (goto-char (point-min))
3326 (if (re-search-forward "<style" nil t
)
3327 (delete-region (point-min) (match-beginning 0)))
3328 (if (re-search-forward "</style>" nil t
)
3329 (delete-region (1+ (match-end 0)) (point-max)))
3330 (beginning-of-line 1)
3331 (if (looking-at " +") (replace-match ""))
3332 (goto-char (point-min)))
3334 (defun org-html-protect (s)
3335 ;; convert & to &, < to < and > to >
3337 (while (string-match "&" s start
)
3338 (setq s
(replace-match "&" t t s
)
3339 start
(1+ (match-beginning 0))))
3340 (while (string-match "<" s
)
3341 (setq s
(replace-match "<" t t s
)))
3342 (while (string-match ">" s
)
3343 (setq s
(replace-match ">" t t s
))))
3346 (defun org-export-cleanup-toc-line (s)
3347 "Remove tags and time staps from lines going into the toc."
3348 (when (memq org-export-with-tags
'(not-in-toc nil
))
3349 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3350 (setq s
(replace-match "" t t s
))))
3351 (when org-export-remove-timestamps-from-toc
3352 (while (string-match org-maybe-keyword-time-regexp s
)
3353 (setq s
(replace-match "" t t s
))))
3354 (while (string-match org-bracket-link-regexp s
)
3355 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3359 (defun org-html-expand (string)
3360 "Prepare STRING for HTML export. Applies all active conversions.
3361 If there are links in the string, don't modify these."
3362 (let* ((re (concat org-bracket-link-regexp
"\\|"
3363 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3365 (while (setq m
(string-match re string
))
3366 (setq s
(substring string
0 m
)
3367 l
(match-string 0 string
)
3368 string
(substring string
(match-end 0)))
3369 (push (org-html-do-expand s
) res
)
3371 (push (org-html-do-expand string
) res
)
3372 (apply 'concat
(nreverse res
))))
3374 (defun org-html-do-expand (s)
3375 "Apply all active conversions to translate special ASCII to HTML."
3376 (setq s
(org-html-protect s
))
3377 (if org-export-html-expand
3379 (while (string-match "@<\\([^&]*\\)>" s
)
3380 (setq s
(replace-match "<\\1>" t nil s
)))))
3381 (if org-export-with-emphasize
3382 (setq s
(org-export-html-convert-emphasize s
)))
3383 (if org-export-with-special-strings
3384 (setq s
(org-export-html-convert-special-strings s
)))
3385 (if org-export-with-sub-superscripts
3386 (setq s
(org-export-html-convert-sub-super s
)))
3387 (if org-export-with-TeX-macros
3388 (let ((start 0) wd ass
)
3389 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3390 (if (get-text-property (match-beginning 0) 'org-protected s
)
3391 (setq start
(match-end 0))
3392 (setq wd
(match-string 1 s
))
3393 (if (setq ass
(assoc wd org-html-entities
))
3394 (setq s
(replace-match (or (cdr ass
)
3395 (concat "&" (car ass
) ";"))
3397 (setq start
(+ start
(length wd
))))))))
3400 (defun org-create-multibrace-regexp (left right n
)
3401 "Create a regular expression which will match a balanced sexp.
3402 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3403 as single character strings.
3404 The regexp returned will match the entire expression including the
3405 delimiters. It will also define a single group which contains the
3406 match except for the outermost delimiters. The maximum depth of
3407 stacked delimiters is N. Escaping delimiters is not possible."
3408 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3411 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3414 re
(concat re or next
)
3415 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3416 (concat left
"\\(" re
"\\)" right
)))
3418 (defvar org-match-substring-regexp
3420 "\\([^\\]\\)\\([_^]\\)\\("
3421 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3423 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3425 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3426 "The regular expression matching a sub- or superscript.")
3428 (defvar org-match-substring-with-braces-regexp
3430 "\\([^\\]\\)\\([_^]\\)\\("
3431 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3433 "The regular expression matching a sub- or superscript, forcing braces.")
3435 (defconst org-export-html-special-string-regexps
3436 '(("\\\\-" .
"­")
3437 ("---\\([^-]\\)" .
"—\\1")
3438 ("--\\([^-]\\)" .
"–\\1")
3439 ("\\.\\.\\." .
"…"))
3440 "Regular expressions for special string conversion.")
3442 (defun org-export-html-convert-special-strings (string)
3443 "Convert special characters in STRING to HTML."
3444 (let ((all org-export-html-special-string-regexps
)
3446 (while (setq a
(pop all
))
3447 (setq re
(car a
) rpl
(cdr a
) start
0)
3448 (while (string-match re string start
)
3449 (if (get-text-property (match-beginning 0) 'org-protected string
)
3450 (setq start
(match-end 0))
3451 (setq string
(replace-match rpl t nil string
)))))
3454 (defun org-export-html-convert-sub-super (string)
3455 "Convert sub- and superscripts in STRING to HTML."
3456 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3457 (while (string-match org-match-substring-regexp string s
)
3459 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3460 ((get-text-property (match-beginning 2) 'org-protected string
)
3461 (setq s
(match-end 2)))
3463 (setq s
(match-end 1)
3464 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3465 c
(or (match-string 8 string
)
3466 (match-string 6 string
)
3467 (match-string 5 string
))
3468 string
(replace-match
3469 (concat (match-string 1 string
)
3470 "<" key
">" c
"</" key
">")
3472 (while (string-match "\\\\\\([_^]\\)" string
)
3473 (setq string
(replace-match (match-string 1 string
) t t string
)))
3476 (defun org-export-html-convert-emphasize (string)
3479 (while (string-match org-emph-re string s
)
3481 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3482 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3483 (setq s
(match-beginning 0)
3486 (match-string 1 string
)
3487 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3488 (match-string 4 string
)
3489 (nth 3 (assoc (match-string 3 string
)
3490 org-emphasis-alist
))
3491 (match-string 5 string
))
3492 string
(replace-match rpl t t string
)
3493 s
(+ s
(- (length rpl
) 2)))
3497 (defvar org-par-open nil
)
3498 (defun org-open-par ()
3499 "Insert <p>, but first close previous paragraph if any."
3500 (org-close-par-maybe)
3502 (setq org-par-open t
))
3503 (defun org-close-par-maybe ()
3504 "Close paragraph if there is one open."
3507 (setq org-par-open nil
)))
3508 (defun org-close-li (&optional type
)
3509 "Close <li> if necessary."
3510 (org-close-par-maybe)
3511 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3513 (defvar body-only
) ; dynamically scoped into this.
3514 (defun org-html-level-start (level title umax with-toc head-count
)
3515 "Insert a new level in HTML export.
3516 When TITLE is nil, just close all open levels."
3517 (org-close-par-maybe)
3518 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3522 (if (aref org-levels-open
(1- l
))
3524 (org-html-level-close l umax
)
3525 (aset org-levels-open
(1- l
) nil
)))
3528 ;; If title is nil, this means this function is called to close
3529 ;; all levels, so the rest is done only if title is given
3530 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3531 (setq title
(replace-match
3532 (if org-export-with-tags
3535 " <span class=\"tag\">"
3536 (mapconcat 'identity
(org-split-string
3537 (match-string 1 title
) ":")
3544 (if (aref org-levels-open
(1- level
))
3548 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3549 (insert "<li>" title
"<br/>\n")))
3550 (aset org-levels-open
(1- level
) t
)
3551 (org-close-par-maybe)
3553 (insert (format "<ul>\n<li id=\"%s\">" target
)
3555 (insert "<ul>\n<li>" title
"<br/>\n"))))
3556 (aset org-levels-open
(1- level
) t
)
3557 (setq snumber
(org-section-number level
))
3558 (if (and org-export-with-section-numbers
(not body-only
))
3559 (setq title
(concat snumber
" " title
)))
3560 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3561 (unless (= head-count
1) (insert "\n</div>\n"))
3562 (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"
3563 snumber level level snumber title level snumber
))
3566 (defun org-get-text-property-any (pos prop
&optional object
)
3567 (or (get-text-property pos prop object
)
3568 (and (setq pos
(next-single-property-change pos prop object
))
3569 (get-text-property pos prop object
))))
3571 (defun org-html-level-close (level max-outline-level
)
3572 "Terminate one level in HTML export."
3573 (if (<= level max-outline-level
)
3576 (insert "</ul>\n")))
3578 ;;; iCalendar export
3581 (defun org-export-icalendar-this-file ()
3582 "Export current file as an iCalendar file.
3583 The iCalendar file will be located in the same directory as the Org-mode
3584 file, but with extension `.ics'."
3586 (org-export-icalendar nil buffer-file-name
))
3589 (defun org-export-icalendar-all-agenda-files ()
3590 "Export all files in `org-agenda-files' to iCalendar .ics files.
3591 Each iCalendar file will be located in the same directory as the Org-mode
3592 file, but with extension `.ics'."
3594 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3597 (defun org-export-icalendar-combine-agenda-files ()
3598 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3599 The file is stored under the name `org-combined-agenda-icalendar-file'."
3601 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3603 (defun org-export-icalendar (combine &rest files
)
3604 "Create iCalendar files for all elements of FILES.
3605 If COMBINE is non-nil, combine all calendar entries into a single large
3606 file and store it under the name `org-combined-agenda-icalendar-file'."
3608 (org-prepare-agenda-buffers files
)
3609 (let* ((dir (org-export-directory
3610 :ical
(list :publishing-directory
3611 org-export-publishing-directory
)))
3612 file ical-file ical-buffer category started org-agenda-new-buffers
)
3613 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3616 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3617 org-combined-agenda-icalendar-file
3618 (expand-file-name org-combined-agenda-icalendar-file dir
))
3619 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3620 (set-buffer ical-buffer
) (erase-buffer))
3621 (while (setq file
(pop files
))
3623 (org-check-agenda-file file
)
3624 (set-buffer (org-get-agenda-file-buffer file
))
3626 (setq ical-file
(concat (file-name-as-directory dir
)
3627 (file-name-sans-extension
3628 (file-name-nondirectory buffer-file-name
))
3630 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3631 (with-current-buffer ical-buffer
(erase-buffer)))
3632 (setq category
(or org-category
3633 (file-name-sans-extension
3634 (file-name-nondirectory buffer-file-name
))))
3635 (if (symbolp category
) (setq category
(symbol-name category
)))
3636 (let ((standard-output ical-buffer
))
3638 (and (not started
) (setq started t
)
3639 (org-start-icalendar-file org-icalendar-combined-name
))
3640 (org-start-icalendar-file category
))
3641 (org-print-icalendar-entries combine
)
3642 (when (or (and combine
(not files
)) (not combine
))
3643 (org-finish-icalendar-file)
3644 (set-buffer ical-buffer
)
3646 (run-hooks 'org-after-save-iCalendar-file-hook
)
3647 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3649 (org-release-buffers org-agenda-new-buffers
))))
3651 (defvar org-after-save-iCalendar-file-hook nil
3652 "Hook run after an iCalendar file has been saved.
3653 The iCalendar buffer is still current when this hook is run.
3654 A good way to use this is to tell a desktop calenndar application to re-read
3655 the iCalendar file.")
3657 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3658 (defun org-print-icalendar-entries (&optional combine
)
3659 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3660 When COMBINE is non nil, add the category to each line."
3661 (require 'org-agenda
)
3662 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3663 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3664 (dts (org-ical-ts-to-string
3665 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3667 hd ts ts2 state status
(inc t
) pos b sexp rrule
3668 scheduledp deadlinep tmp pri category entry location summary desc
3669 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3670 (org-refresh-category-properties)
3672 (goto-char (point-min))
3673 (while (re-search-forward re1 nil t
)
3676 (when (boundp 'org-icalendar-verify-function
)
3677 (unless (funcall org-icalendar-verify-function
)
3678 (outline-next-heading)
3681 (setq pos
(match-beginning 0)
3684 hd
(condition-case nil
3685 (org-icalendar-cleanup-string
3687 (error (throw :skip nil
)))
3688 summary
(org-icalendar-cleanup-string
3689 (org-entry-get nil
"SUMMARY"))
3690 desc
(org-icalendar-cleanup-string
3691 (or (org-entry-get nil
"DESCRIPTION")
3692 (and org-icalendar-include-body
(org-get-entry)))
3693 t org-icalendar-include-body
)
3694 location
(org-icalendar-cleanup-string
3695 (org-entry-get nil
"LOCATION"))
3696 category
(org-get-category))
3697 (if (looking-at re2
)
3699 (goto-char (match-end 0))
3700 (setq ts2
(match-string 1) inc nil
))
3701 (setq tmp
(buffer-substring (max (point-min)
3702 (- pos org-ds-keyword-length
))
3704 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3707 (replace-match "\\1" t nil ts
))
3709 deadlinep
(string-match org-deadline-regexp tmp
)
3710 scheduledp
(string-match org-scheduled-regexp tmp
)
3711 ;; donep (org-entry-is-done-p)
3713 (if (or (string-match org-tr-regexp hd
)
3714 (string-match org-ts-regexp hd
))
3715 (setq hd
(replace-match "" t t hd
)))
3716 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3718 (concat "\nRRULE:FREQ="
3721 '(("d" .
"DAILY")("w" .
"WEEKLY")
3722 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3723 ";INTERVAL=" (match-string 1 ts
)))
3725 (setq summary
(or summary hd
))
3726 (if (string-match org-bracket-link-regexp summary
)
3728 (replace-match (if (match-end 3)
3729 (match-string 3 summary
)
3730 (match-string 1 summary
))
3732 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3733 (if scheduledp
(setq summary
(concat "S: " summary
)))
3734 (if (string-match "\\`<%%" ts
)
3735 (with-current-buffer sexp-buffer
3736 (insert (substring ts
1 -
1) " " summary
"\n"))
3737 (princ (format "BEGIN:VEVENT
3743 (org-ical-ts-to-string ts
"DTSTART")
3744 (org-ical-ts-to-string ts2
"DTEND" inc
)
3746 (if (and desc
(string-match "\\S-" desc
))
3747 (concat "\nDESCRIPTION: " desc
) "")
3748 (if (and location
(string-match "\\S-" location
))
3749 (concat "\nLOCATION: " location
) "")
3752 (when (and org-icalendar-include-sexps
3753 (condition-case nil
(require 'icalendar
) (error nil
))
3754 (fboundp 'icalendar-export-region
))
3755 ;; Get all the literal sexps
3756 (goto-char (point-min))
3757 (while (re-search-forward "^&?%%(" nil t
)
3760 (setq b
(match-beginning 0))
3761 (goto-char (1- (match-end 0)))
3764 (setq sexp
(buffer-substring b
(point)))
3765 (with-current-buffer sexp-buffer
3767 (princ (org-diary-to-ical-string sexp-buffer
)))))
3769 (when org-icalendar-include-todo
3770 (goto-char (point-min))
3771 (while (re-search-forward org-todo-line-regexp nil t
)
3774 (when (boundp 'org-icalendar-verify-function
)
3775 (unless (funcall org-icalendar-verify-function
)
3776 (outline-next-heading)
3779 (setq state
(match-string 2))
3780 (setq status
(if (member state org-done-keywords
)
3781 "COMPLETED" "NEEDS-ACTION"))
3783 (or (not (member state org-done-keywords
))
3784 (eq org-icalendar-include-todo
'all
))
3785 (not (member org-archive-tag
(org-get-tags-at)))
3787 (setq hd
(match-string 3)
3788 summary
(org-icalendar-cleanup-string
3789 (org-entry-get nil
"SUMMARY"))
3790 desc
(org-icalendar-cleanup-string
3791 (or (org-entry-get nil
"DESCRIPTION")
3792 (and org-icalendar-include-body
(org-get-entry)))
3793 t org-icalendar-include-body
)
3794 location
(org-icalendar-cleanup-string
3795 (org-entry-get nil
"LOCATION")))
3796 (if (string-match org-bracket-link-regexp hd
)
3797 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3798 (match-string 1 hd
))
3800 (if (string-match org-priority-regexp hd
)
3801 (setq pri
(string-to-char (match-string 2 hd
))
3802 hd
(concat (substring hd
0 (match-beginning 1))
3803 (substring hd
(match-end 1))))
3804 (setq pri org-default-priority
))
3805 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3806 (- org-lowest-priority org-highest-priority
))))))
3808 (princ (format "BEGIN:VTODO
3818 (if (and location
(string-match "\\S-" location
))
3819 (concat "\nLOCATION: " location
) "")
3820 (if (and desc
(string-match "\\S-" desc
))
3821 (concat "\nDESCRIPTION: " desc
) "")
3822 category pri status
)))))))))
3824 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3825 "Take out stuff and quote what needs to be quoted.
3826 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3827 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3832 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3833 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3834 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3835 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3837 (while (string-match "\\([,;]\\)" s start
)
3838 (setq start
(+ (match-beginning 0) 2)
3839 s
(replace-match "\\\\\\1" nil nil s
))))
3841 (while (string-match "[ \t]*\n[ \t]*" s
)
3842 (setq s
(replace-match "\\n" t t s
))))
3843 (setq s
(org-trim s
))
3846 (if (and (numberp maxlength
)
3847 (> (length s
) maxlength
))
3848 (setq s
(substring s
0 maxlength
)))))
3851 (defun org-get-entry ()
3852 "Clean-up description string."
3854 (org-back-to-heading t
)
3855 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3857 (defun org-start-icalendar-file (name)
3858 "Start an iCalendar file by inserting the header."
3859 (let ((user user-full-name
)
3860 (name (or name
"unknown"))
3861 (timezone (cadr (current-time-zone))))
3863 (format "BEGIN:VCALENDAR
3866 PRODID:-//%s//Emacs with Org-mode//EN
3868 CALSCALE:GREGORIAN\n" name user timezone
))))
3870 (defun org-finish-icalendar-file ()
3871 "Finish an iCalendar file by inserting the END statement."
3872 (princ "END:VCALENDAR\n"))
3874 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3875 "Take a time string S and convert it to iCalendar format.
3876 KEYWORD is added in front, to make a complete line like DTSTART....
3877 When INC is non-nil, increase the hour by two (if time string contains
3878 a time), or the day by one (if it does not contain a time)."
3879 (let ((t1 (org-parse-time-string s
'nodefault
))
3880 t2 fmt have-time time
)
3881 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3882 (setq t2 t1 have-time t
)
3883 (setq t2
(org-parse-time-string s
)))
3884 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3885 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3888 (if org-agenda-default-appointment-duration
3889 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3892 (setq time
(encode-time s mi h d m y
)))
3893 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3894 (concat keyword
(format-time-string fmt time
))))
3898 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3899 (with-current-buffer buffer
3900 (apply 'insert output
)))
3901 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3904 (defun org-export-as-xoxo (&optional buffer
)
3905 "Export the org buffer as XOXO.
3906 The XOXO buffer is named *xoxo-<source buffer name>*"
3907 (interactive (list (current-buffer)))
3908 ;; A quickie abstraction
3910 ;; Output everything as XOXO
3911 (with-current-buffer (get-buffer buffer
)
3912 (let* ((pos (point))
3913 (opt-plist (org-combine-plists (org-default-export-plist)
3914 (org-infile-export-plist)))
3915 (filename (concat (file-name-as-directory
3916 (org-export-directory :xoxo opt-plist
))
3917 (file-name-sans-extension
3918 (file-name-nondirectory buffer-file-name
))
3920 (out (find-file-noselect filename
))
3923 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3924 ;; Check the output buffer is empty.
3925 (with-current-buffer out
(erase-buffer))
3926 ;; Kick off the output
3927 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3928 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3929 (let* ((hd (match-string-no-properties 1))
3932 (match-string-no-properties 2)
3934 (goto-char (match-end 0))
3939 (if (looking-at "^[ \t]\\(.*\\)")
3940 (setq str
(concat str
(match-string-no-properties 1)))
3941 (throw 'loop str
)))))))))
3943 ;; Handle level rendering
3945 ((> level last-level
)
3946 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3948 ((< level last-level
)
3949 (dotimes (- (- last-level level
) 1)
3951 (org-export-as-xoxo-insert-into out
"</li>\n"))
3952 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3954 (org-export-as-xoxo-insert-into out
"</li>\n")
3955 (setq hanging-li nil
)))
3957 ((equal level last-level
)
3959 (org-export-as-xoxo-insert-into out
"</li>\n")))
3962 (setq last-level level
)
3964 ;; And output the new li
3965 (setq hanging-li
't
)
3966 (if (equal ?
+ (elt text
0))
3967 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3968 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3970 ;; Finally finish off the ol
3971 (dotimes (- last-level
1)
3973 (org-export-as-xoxo-insert-into out
"</li>\n"))
3974 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3977 ;; Finish the buffer off and clean it up.
3978 (switch-to-buffer-other-window out
)
3979 (indent-region (point-min) (point-max) nil
)
3981 (goto-char (point-min))
3986 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
3988 ;;; org-exp.el ends here