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 (goto-char (point-min))
1371 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1372 (replace-match (if (equal (downcase (match-string 1)) "end")
1373 "ORG-VERSE-END" "ORG-VERSE-START")
1376 ;; Remove comment environment
1377 (goto-char (point-min))
1378 (while (re-search-forward
1379 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1380 (replace-match "" t t
))
1382 ;; Remove subtrees that are commented
1383 (goto-char (point-min))
1384 (while (re-search-forward re-commented nil t
)
1385 (goto-char (match-beginning 0))
1386 (delete-region (point) (org-end-of-subtree t
)))
1388 ;; Remove special table lines
1389 (when org-export-table-remove-special-lines
1390 (goto-char (point-min))
1391 (while (re-search-forward "^[ \t]*|" nil t
)
1392 (beginning-of-line 1)
1393 (if (or (looking-at "[ \t]*| *[!_^] *|")
1394 (and (looking-at ".*?| *<[0-9]+> *|")
1395 (not (looking-at ".*?| *[^ <|]"))))
1396 (delete-region (max (point-min) (1- (point-at-bol)))
1400 ;; Specific LaTeX stuff
1402 (require 'org-export-latex nil
)
1403 (org-export-latex-preprocess))
1406 (org-export-ascii-clean-string))
1408 ;; Specific HTML stuff
1410 ;; Convert LaTeX fragments to images
1411 (when (plist-get parameters
:LaTeX-fragments
)
1413 (concat "ltxpng/" (file-name-sans-extension
1414 (file-name-nondirectory
1415 org-current-export-file
)))
1416 org-current-export-dir nil
"Creating LaTeX image %s"))
1417 (message "Exporting..."))
1419 ;; Remove or replace comments
1420 (goto-char (point-min))
1421 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1423 (progn (add-text-properties
1424 (match-beginning 0) (match-end 0) '(org-protected t
))
1425 (replace-match (format commentsp
(match-string 1)) t t
))
1426 (replace-match "")))
1428 ;; Find matches for radio targets and turn them into internal links
1429 (goto-char (point-min))
1431 (while (re-search-forward re-radio nil t
)
1433 (replace-match "\\1[[\\2]]"))))
1435 ;; Find all links that contain a newline and put them into a single line
1436 (goto-char (point-min))
1437 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1439 (replace-match "\\1 \\3")
1440 (goto-char (match-beginning 0))))
1442 ;; Find all internal links. If they have a fuzzy match (i.e. not
1443 ;; a *dedicated* target match, let the link point to the
1444 ;; correspinding section.
1446 (goto-char (point-min))
1447 (while (re-search-forward org-bracket-link-regexp nil t
)
1449 (let* ((md (match-data))
1450 (desc (match-end 2))
1451 (link (org-link-unescape (match-string 1)))
1452 (slink (org-solidify-link-text link
))
1455 (or (cdr (assoc slink target-alist
))
1457 (unless (string-match org-link-types-re link
)
1458 (setq found
(condition-case nil
(org-link-search link
)
1461 (or (org-on-heading-p)
1462 (not (eq found
'dedicated
))))
1463 (or (get-text-property (point) 'target
)
1466 (1- (previous-single-property-change
1471 (goto-char (match-beginning 1))
1472 (setq props
(text-properties-at (point)))
1473 (delete-region (match-beginning 1) (match-end 1))
1476 (unless desc
(insert "][" link
))
1477 (add-text-properties pos
(point) props
)))))
1479 ;; Normalize links: Convert angle and plain links into bracket links
1480 ;; Expand link abbreviations
1481 (goto-char (point-min))
1482 (while (re-search-forward re-plain-link nil t
)
1483 (goto-char (1- (match-end 0)))
1485 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1486 ":" (match-string 3) "]]")))
1487 ;; added 'org-link face to links
1488 (put-text-property 0 (length s
) 'face
'org-link s
)
1489 (replace-match s t t
))))
1490 (goto-char (point-min))
1491 (while (re-search-forward re-angle-link nil t
)
1492 (goto-char (1- (match-end 0)))
1494 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1495 ":" (match-string 3) "]]")))
1496 (put-text-property 0 (length s
) 'face
'org-link s
)
1497 (replace-match s t t
))))
1498 (goto-char (point-min))
1499 (while (re-search-forward org-bracket-link-regexp nil t
)
1501 (let* ((s (concat "[[" (setq xx
(save-match-data
1502 (org-link-expand-abbrev (match-string 1))))
1506 (concat "[" xx
"]"))
1508 (put-text-property 0 (length s
) 'face
'org-link s
)
1509 (replace-match s t t
))))
1511 ;; Find multiline emphasis and put them into single line
1512 (when (plist-get parameters
:emph-multiline
)
1513 (goto-char (point-min))
1514 (while (re-search-forward org-emph-re nil t
)
1515 (if (not (= (char-after (match-beginning 3))
1516 (char-after (match-beginning 4))))
1518 (subst-char-in-region (match-beginning 0) (match-end 0)
1520 (goto-char (1- (match-end 0))))
1521 (goto-char (1+ (match-beginning 0))))))
1523 (setq rtn
(buffer-string)))
1524 (kill-buffer " org-mode-tmp")
1527 (defun org-export-grab-title-from-buffer ()
1528 "Get a title for the current document, from looking at the buffer."
1529 (let ((inhibit-read-only t
))
1531 (goto-char (point-min))
1532 (let ((end (save-excursion (outline-next-heading) (point))))
1533 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1534 ;; Mark the line so that it will not be exported as normal text.
1536 (add-text-properties (match-beginning 0) (match-end 0)
1537 (list :org-license-to-kill t
)))
1538 ;; Return the title string
1539 (org-trim (match-string 0)))))))
1541 (defun org-export-get-title-from-subtree ()
1542 "Return subtree title and exclude it from export."
1543 (let (title (m (mark)))
1545 (goto-char (region-beginning))
1546 (when (and (org-at-heading-p)
1547 (>= (org-end-of-subtree t t
) (region-end)))
1548 ;; This is a subtree, we take the title from the first heading
1549 (goto-char (region-beginning))
1550 (looking-at org-todo-line-regexp
)
1551 (setq title
(match-string 3))
1553 (add-text-properties (point) (1+ (point-at-eol))
1554 (list :org-license-to-kill t
)))))
1557 (defun org-solidify-link-text (s &optional alist
)
1558 "Take link text and make a safe target out of it."
1563 (org-split-string s
"[ \t\r\n]+") "=="))
1564 (a (assoc rtn alist
)))
1567 (defun org-get-min-level (lines)
1568 "Get the minimum level in LINES."
1569 (let ((re "^\\(\\*+\\) ") l min
)
1571 (while (setq l
(pop lines
))
1572 (if (string-match re l
)
1573 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1576 ;; Variable holding the vector with section numbers
1577 (defvar org-section-numbers
(make-vector org-level-max
0))
1579 (defun org-init-section-numbers ()
1580 "Initialize the vector for the section numbers."
1582 (numbers (nreverse (org-split-string "" "\\.")))
1583 (depth (1- (length org-section-numbers
)))
1584 (i depth
) number-string
)
1587 (aset org-section-numbers i
0)
1588 (setq number-string
(or (car numbers
) "0"))
1589 (if (string-match "\\`[A-Z]\\'" number-string
)
1590 (aset org-section-numbers i
1591 (- (string-to-char number-string
) ?A -
1))
1592 (aset org-section-numbers i
(string-to-number number-string
)))
1596 (defun org-section-number (&optional level
)
1597 "Return a string with the current section number.
1598 When LEVEL is non-nil, increase section numbers on that level."
1599 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1602 (aset org-section-numbers
1603 level
(1+ (aref org-section-numbers level
))))
1604 (setq idx
(1+ level
))
1605 (while (<= idx depth
)
1607 (aset org-section-numbers idx
0))
1608 (setq idx
(1+ idx
))))
1610 (while (<= idx depth
)
1611 (setq n
(aref org-section-numbers idx
))
1612 (setq string
(concat string
(if (not (string= string
"")) "." "")
1614 (setq idx
(1+ idx
)))
1616 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1617 (setq string
(replace-match "" t nil string
)))
1618 (if (string-match "\\(\\.0\\)+\\'" string
)
1619 (setq string
(replace-match "" t nil string
))))
1624 (defun org-export-handle-include-files ()
1625 "Include the contents of include files, with proper formatting."
1626 (let (params file markup lang start end
)
1627 (goto-char (point-min))
1628 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1629 (setq params
(read (concat "(" (match-string 1) ")"))
1630 file
(org-symname-or-string (pop params
))
1631 markup
(org-symname-or-string (pop params
))
1632 lang
(org-symname-or-string (pop params
)))
1633 (delete-region (match-beginning 0) (match-end 0))
1635 (not (file-exists-p file
))
1636 (not (file-readable-p file
)))
1637 (insert (format "CANNOT INCLUDE FILE %s" file
))
1639 (if (equal (downcase markup
) "src")
1640 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1642 (setq start
(format "#+begin_%s\n" markup
)
1643 end
(format "#+end_%s" markup
))))
1644 (insert (or start
""))
1645 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1646 (or (bolp) (newline))
1647 (insert (or end
""))))))
1649 (defun org-symname-or-string (s)
1651 (if s
(symbol-name s
) s
)
1654 ;;; Fontification of code
1655 ;; Currently only for th HTML backend, but who knows....
1656 (defun org-export-replace-src-segments ()
1657 "Replace source code segments with special code for export."
1658 (let (lang code trans
)
1659 (goto-char (point-min))
1660 (while (re-search-forward
1661 "^#\\+BEGIN_SRC[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1663 (setq lang
(match-string 1) code
(match-string 2)
1664 trans
(org-export-format-source-code lang code
))
1665 (replace-match trans t t
))))
1667 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1669 (defun org-export-format-source-code (lang code
)
1670 "Format CODE from language LANG and return it formatted for export.
1671 Currently, this only does something for HTML export, for all other
1672 backends, it converts the segment into an EXAMPLE segment."
1676 ;; We are exporting to HTML
1677 (condition-case nil
(require 'htmlize
) (nil t
))
1678 (if (not (fboundp 'htmlize-region-for-paste
))
1680 ;; we do not have htmlize.el, or an old version of it
1682 "htmlize.el 1.34 or later is needed for source code formatting")
1683 (concat "#+BEGIN_EXAMPLE\n" code
1684 (if (string-match "\n\\'" code
) "" "\n")
1686 ;; ok, we are good to go
1687 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1688 (org-inhibit-startup t
)
1689 (org-startup-folded nil
)
1693 ;; Free up the protected stuff
1694 (goto-char (point-min))
1695 (while (re-search-forward "^," nil t
)
1697 (if (functionp mode
)
1700 (font-lock-fontify-buffer)
1701 (org-export-htmlize-region-for-paste
1702 (point-min) (point-max)))))
1703 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1704 (setq htmltext
(replace-match "<pre class=\"src\">"
1706 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1708 ;; This is not HTML, so just make it an example.
1709 (concat "#+BEGIN_EXAMPLE\n" code
1710 (if (string-match "\n\\'" code
) "" "\n")
1711 "#+END_EXAMPLE\n")))))
1715 (defvar org-last-level nil
) ; dynamically scoped variable
1716 (defvar org-min-level nil
) ; dynamically scoped variable
1717 (defvar org-levels-open nil
) ; dynamically scoped parameter
1718 (defvar org-ascii-current-indentation nil
) ; For communication
1721 (defun org-export-as-ascii (arg)
1722 "Export the outline as a pretty ASCII file.
1723 If there is an active region, export only the region.
1724 The prefix ARG specifies how many levels of the outline should become
1725 underlined headlines. The default is 3."
1727 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1728 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1729 (org-infile-export-plist)))
1730 (region-p (org-region-active-p))
1734 (goto-char (region-beginning))
1735 (and (org-at-heading-p)
1736 (>= (org-end-of-subtree t t
) (region-end))))))
1737 (custom-times org-display-custom-times
)
1738 (org-ascii-current-indentation '(0 .
0))
1742 (case-fold-search nil
)
1743 (filename (concat (file-name-as-directory
1744 (org-export-directory :ascii opt-plist
))
1745 (file-name-sans-extension
1747 (org-entry-get (region-beginning)
1748 "EXPORT_FILE_NAME" t
))
1749 (file-name-nondirectory buffer-file-name
)))
1751 (filename (if (equal (file-truename filename
)
1752 (file-truename buffer-file-name
))
1753 (concat filename
".txt")
1755 (buffer (find-file-noselect filename
))
1756 (org-levels-open (make-vector org-level-max nil
))
1757 (odd org-odd-levels-only
)
1758 (date (plist-get opt-plist
:date
))
1759 (author (plist-get opt-plist
:author
))
1760 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1761 (plist-get opt-plist
:title
)
1763 (plist-get opt-plist
:skip-before-1st-heading
))
1764 (org-export-grab-title-from-buffer))
1765 (file-name-sans-extension
1766 (file-name-nondirectory buffer-file-name
))))
1767 (email (plist-get opt-plist
:email
))
1768 (language (plist-get opt-plist
:language
))
1769 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1770 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1775 (if (org-region-active-p) (region-beginning) (point-min))
1776 (if (org-region-active-p) (region-end) (point-max))))
1777 (lines (org-split-string
1778 (org-export-preprocess-string
1781 :skip-before-1st-heading
1782 (plist-get opt-plist
:skip-before-1st-heading
)
1783 :drawers
(plist-get opt-plist
:drawers
)
1784 :verbatim-multiline t
1786 (plist-get opt-plist
:archived-trees
)
1787 :add-text
(plist-get opt-plist
:text
))
1789 thetoc have-headings first-heading-pos
1790 table-open table-buffer
)
1792 (let ((inhibit-read-only t
))
1794 (remove-text-properties (point-min) (point-max)
1795 '(:org-license-to-kill t
))))
1797 (setq org-min-level
(org-get-min-level lines
))
1798 (setq org-last-level org-min-level
)
1799 (org-init-section-numbers)
1801 (find-file-noselect filename
)
1803 (setq lang-words
(or (assoc language org-export-language-setup
)
1804 (assoc "en" org-export-language-setup
)))
1805 (switch-to-buffer-other-window buffer
)
1808 ;; create local variables for all options, to make sure all called
1809 ;; functions get the correct information
1811 (set (make-local-variable (cdr x
))
1812 (plist-get opt-plist
(car x
))))
1813 org-export-plist-vars
)
1814 (org-set-local 'org-odd-levels-only odd
)
1815 (setq umax
(if arg
(prefix-numeric-value arg
)
1816 org-export-headline-levels
))
1817 (setq umax-toc
(if (integerp org-export-with-toc
)
1818 (min org-export-with-toc umax
)
1822 (if title
(org-insert-centered title ?
=))
1824 (if (and (or author email
)
1825 org-export-author-info
)
1826 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1827 (if email
(concat " <" email
">") "")
1831 ((and date
(string-match "%" date
))
1832 (setq date
(format-time-string date
)))
1834 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1836 (if (and date org-export-time-stamp-file
)
1837 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1841 (if org-export-with-toc
1843 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1844 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1845 (mapc '(lambda (line)
1846 (if (string-match org-todo-line-regexp
1848 ;; This is a headline
1850 (setq have-headings t
)
1851 (setq level
(- (match-end 1) (match-beginning 1))
1852 level
(org-tr-level level
)
1853 txt
(match-string 3 line
)
1855 (or (and org-export-mark-todo-in-toc
1857 (not (member (match-string 2 line
)
1858 org-done-keywords
)))
1860 (and org-export-mark-todo-in-toc
1862 (org-search-todo-below
1863 line lines level
))))
1864 (setq txt
(org-html-expand-for-ascii txt
))
1866 (while (string-match org-bracket-link-regexp txt
)
1869 (match-string (if (match-end 2) 3 1) txt
)
1872 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1874 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1876 (setq txt
(replace-match "" t t txt
)))
1877 (if (string-match quote-re0 txt
)
1878 (setq txt
(replace-match "" t t txt
)))
1880 (if org-export-with-section-numbers
1881 (setq txt
(concat (org-section-number level
)
1883 (if (<= level umax-toc
)
1888 (* (max 0 (- level org-min-level
)) 4) ?\
)
1889 (format (if todo
"%s (*)\n" "%s\n") txt
))
1891 (setq org-last-level level
))
1894 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1896 (org-init-section-numbers)
1897 (while (setq line
(pop lines
))
1898 ;; Remove the quoted HTML tags.
1899 (setq line
(org-html-expand-for-ascii line
))
1901 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1902 (setq line
(replace-match "" t t line
)))
1903 ;; Replace internal links
1904 (while (string-match org-bracket-link-regexp line
)
1905 (setq line
(replace-match
1906 (if (match-end 3) "[\\3]" "[\\1]")
1909 (setq line
(org-translate-time line
)))
1911 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1913 (setq first-heading-pos
(or first-heading-pos
(point)))
1914 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1915 txt
(match-string 2 line
))
1916 (org-ascii-level-start level txt umax lines
))
1918 ((and org-export-with-tables
1919 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1920 (if (not table-open
)
1922 (setq table-open t table-buffer nil
))
1924 (setq table-buffer
(cons line table-buffer
))
1925 (when (or (not lines
)
1926 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1928 (setq table-open nil
1929 table-buffer
(nreverse table-buffer
))
1932 (org-fix-indentation x org-ascii-current-indentation
))
1933 (org-format-table-ascii table-buffer
)
1936 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1937 (if (and org-export-with-fixed-width
1938 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1939 (setq line
(replace-match "\\1" nil nil line
)))
1940 (insert line
"\n"))))
1944 ;; insert the table of contents
1946 (goto-char (point-min))
1947 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1949 (goto-char (match-beginning 0))
1951 (goto-char first-heading-pos
))
1952 (mapc 'insert thetoc
)
1953 (or (looking-at "[ \t]*\n[ \t]*\n")
1956 ;; Convert whitespace place holders
1957 (goto-char (point-min))
1959 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1960 (setq end
(next-single-property-change beg
'org-whitespace
))
1962 (delete-region beg end
)
1963 (insert (make-string (- end beg
) ?\
))))
1966 ;; remove display and invisible chars
1968 (goto-char (point-min))
1969 (while (setq beg
(next-single-property-change (point) 'display
))
1970 (setq end
(next-single-property-change beg
'display
))
1971 (delete-region beg end
)
1974 (goto-char (point-min))
1975 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1976 (setq end
(next-single-property-change beg
'org-cwidth
))
1977 (delete-region beg end
)
1979 (goto-char (point-min))))
1981 (defun org-export-ascii-clean-string ()
1982 "Do extra work for ASCII export"
1983 (goto-char (point-min))
1984 (while (re-search-forward org-verbatim-re nil t
)
1985 (goto-char (match-end 2))
1986 (backward-delete-char 1) (insert "'")
1987 (goto-char (match-beginning 2))
1988 (delete-char 1) (insert "`")
1989 (goto-char (match-end 2))))
1991 (defun org-search-todo-below (line lines level
)
1992 "Search the subtree below LINE for any TODO entries."
1993 (let ((rest (cdr (memq line lines
)))
1994 (re org-todo-line-regexp
)
1997 (while (setq line
(pop rest
))
1998 (if (string-match re line
)
2000 (setq lv
(- (match-end 1) (match-beginning 1))
2001 todo
(and (match-beginning 2)
2002 (not (member (match-string 2 line
)
2003 org-done-keywords
))))
2005 (if (<= lv level
) (throw 'exit nil
))
2006 (if todo
(throw 'exit t
))))))))
2008 (defun org-html-expand-for-ascii (line)
2009 "Handle quoted HTML for ASCII export."
2010 (if org-export-html-expand
2011 (while (string-match "@<[^<>\n]*>" line
)
2012 ;; We just remove the tags for now.
2013 (setq line
(replace-match "" nil nil line
))))
2016 (defun org-insert-centered (s &optional underline
)
2017 "Insert the string S centered and underline it with character UNDERLINE."
2018 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2019 (insert (make-string ind ?\
) s
"\n")
2021 (insert (make-string ind ?\
)
2022 (make-string (string-width s
) underline
)
2025 (defun org-ascii-level-start (level title umax
&optional lines
)
2026 "Insert a new level in ASCII export."
2027 (let (char (n (- level umax
1)) (ind 0))
2030 (insert (make-string (* 2 n
) ?\
)
2031 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2032 org-export-ascii-bullets
))
2034 ;; find the indentation of the next non-empty line
2037 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2038 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2039 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2041 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2042 (if (or (not (equal (char-before) ?
\n))
2043 (not (equal (char-before (1- (point))) ?
\n)))
2045 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2046 (unless org-export-with-tags
2047 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2048 (setq title
(replace-match "" t t title
))))
2049 (if org-export-with-section-numbers
2050 (setq title
(concat (org-section-number level
) " " title
)))
2051 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2052 (setq org-ascii-current-indentation
'(0 .
0)))))
2055 (defun org-export-visible (type arg
)
2056 "Create a copy of the visible part of the current buffer, and export it.
2057 The copy is created in a temporary buffer and removed after use.
2058 TYPE is the final key (as a string) that also select the export command in
2059 the `C-c C-e' export dispatcher.
2060 As a special case, if the you type SPC at the prompt, the temporary
2061 org-mode file will not be removed but presented to you so that you can
2062 continue to use it. The prefix arg ARG is passed through to the exporting
2066 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2067 (read-char-exclusive))
2068 current-prefix-arg
))
2069 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2070 (error "Invalid export key"))
2071 (let* ((binding (cdr (assoc type
2072 '((?a . org-export-as-ascii
)
2073 (?\C-a . org-export-as-ascii
)
2074 (?b . org-export-as-html-and-open
)
2075 (?\C-b . org-export-as-html-and-open
)
2076 (?h . org-export-as-html
)
2077 (?H . org-export-as-html-to-buffer
)
2078 (?R . org-export-region-as-html
)
2079 (?x . org-export-as-xoxo
)))))
2080 (keepp (equal type ?\
))
2081 (file buffer-file-name
)
2082 (buffer (get-buffer-create "*Org Export Visible*"))
2084 ;; Need to hack the drawers here.
2086 (goto-char (point-min))
2087 (while (re-search-forward org-drawer-regexp nil t
)
2088 (goto-char (match-beginning 1))
2089 (or (org-invisible-p) (org-flag-drawer nil
))))
2090 (with-current-buffer buffer
(erase-buffer))
2092 (setq s
(goto-char (point-min)))
2093 (while (not (= (point) (point-max)))
2094 (goto-char (org-find-invisible))
2095 (append-to-buffer buffer s
(point))
2096 (setq s
(goto-char (org-find-visible))))
2097 (org-cycle-hide-drawers 'all
)
2098 (goto-char (point-min))
2100 ;; Copy all comment lines to the end, to make sure #+ settings are
2101 ;; still available for the second export step. Kind of a hack, but
2102 ;; does do the trick.
2103 (if (looking-at "#[^\r\n]*")
2104 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2105 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2106 (append-to-buffer buffer
(1+ (match-beginning 0))
2107 (min (point-max) (1+ (match-end 0))))))
2109 (let ((buffer-file-name file
)
2110 (org-inhibit-startup t
))
2113 (unless keepp
(funcall binding arg
))))
2115 (kill-buffer buffer
)
2116 (switch-to-buffer-other-window buffer
)
2117 (goto-char (point-min)))))
2119 (defun org-find-visible ()
2121 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2122 (get-char-property s
'invisible
)))
2124 (defun org-find-invisible ()
2126 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2127 (not (get-char-property s
'invisible
))))
2132 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2133 (defun org-get-current-options ()
2134 "Return a string with current options as keyword options.
2135 Does include HTML export options as well as TODO and CATEGORY stuff."
2136 (require 'org-archive
)
2143 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2144 #+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
2151 #+PRIORITIES: %c %c %c
2153 #+STARTUP: %s %s %s %s %s
2158 (buffer-name) (user-full-name) user-mail-address
2159 (format-time-string (car org-time-stamp-formats
))
2160 org-export-default-language
2161 org-export-headline-levels
2162 org-export-with-section-numbers
2164 org-export-preserve-breaks
2165 org-export-html-expand
2166 org-export-with-fixed-width
2167 org-export-with-tables
2168 org-export-with-sub-superscripts
2169 org-export-with-special-strings
2170 org-export-with-footnotes
2171 org-export-with-emphasize
2172 org-export-with-TeX-macros
2173 org-export-with-LaTeX-fragments
2174 org-export-skip-text-before-1st-heading
2175 org-export-with-drawers
2176 org-export-with-tags
2177 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2178 org-export-html-link-up
2179 org-export-html-link-home
2180 (file-name-nondirectory buffer-file-name
)
2181 "TODO FEEDBACK VERIFY DONE"
2182 "Me Jason Marie DONE"
2183 org-highest-priority org-lowest-priority org-default-priority
2184 (mapconcat 'identity org-drawers
" ")
2185 (cdr (assoc org-startup-folded
2186 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2187 (if org-odd-levels-only
"odd" "oddeven")
2188 (if org-hide-leading-stars
"hidestars" "showstars")
2189 (if org-startup-align-all-tables
"align" "noalign")
2190 (cond ((eq org-log-done t
) "logdone")
2191 ((equal org-log-done
'note
) "lognotedone")
2192 ((not org-log-done
) "nologdone"))
2193 (or (mapconcat (lambda (x)
2195 ((equal '(:startgroup
) x
) "{")
2196 ((equal '(:endgroup
) x
) "}")
2197 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2199 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2200 org-archive-location
2201 "org file:~/org/%s.org"
2205 (defun org-insert-export-options-template ()
2206 "Insert into the buffer a template with information for exporting."
2208 (if (not (bolp)) (newline))
2209 (let ((s (org-get-current-options)))
2210 (and (string-match "#\\+CATEGORY" s
)
2211 (setq s
(substring s
0 (match-beginning 0))))
2215 (defun org-export-as-html-and-open (arg)
2216 "Export the outline as HTML and immediately open it with a browser.
2217 If there is an active region, export only the region.
2218 The prefix ARG specifies how many levels of the outline should become
2219 headlines. The default is 3. Lower levels will become bulleted lists."
2221 (org-export-as-html arg
'hidden
)
2222 (org-open-file buffer-file-name
))
2225 (defun org-export-as-html-batch ()
2226 "Call `org-export-as-html', may be used in batch processing as
2228 --load=$HOME/lib/emacs/org.el
2229 --eval \"(setq org-export-headline-levels 2)\"
2230 --visit=MyFile --funcall org-export-as-html-batch"
2231 (org-export-as-html org-export-headline-levels
'hidden
))
2234 (defun org-export-as-html-to-buffer (arg)
2235 "Call `org-exort-as-html` with output to a temporary buffer.
2236 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2238 (org-export-as-html arg nil nil
"*Org HTML Export*")
2239 (switch-to-buffer-other-window "*Org HTML Export*"))
2242 (defun org-replace-region-by-html (beg end
)
2243 "Assume the current region has org-mode syntax, and convert it to HTML.
2244 This can be used in any buffer. For example, you could write an
2245 itemized list in org-mode syntax in an HTML buffer and then use this
2246 command to convert it."
2248 (let (reg html buf pop-up-frames
)
2249 (save-window-excursion
2251 (setq html
(org-export-region-as-html
2253 (setq reg
(buffer-substring beg end
)
2254 buf
(get-buffer-create "*Org tmp*"))
2255 (with-current-buffer buf
2259 (setq html
(org-export-region-as-html
2260 (point-min) (point-max) t
'string
)))
2262 (delete-region beg end
)
2266 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2267 "Convert region from BEG to END in org-mode buffer to HTML.
2268 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2269 contents, and only produce the region of converted text, useful for
2270 cut-and-paste operations.
2271 If BUFFER is a buffer or a string, use/create that buffer as a target
2272 of the converted HTML. If BUFFER is the symbol `string', return the
2273 produced HTML as a string and leave not buffer behind. For example,
2274 a Lisp program could call this function in the following way:
2276 (setq html (org-export-region-as-html beg end t 'string))
2278 When called interactively, the output buffer is selected, and shown
2279 in a window. A non-interactive call will only return the buffer."
2280 (interactive "r\nP")
2281 (when (interactive-p)
2282 (setq buffer
"*Org HTML Export*"))
2283 (let ((transient-mark-mode t
) (zmacs-regions t
)
2286 (set-mark (point)) ;; to activate the region
2288 (setq rtn
(org-export-as-html
2291 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2292 (if (and (interactive-p) (bufferp rtn
))
2293 (switch-to-buffer-other-window rtn
)
2296 (defvar html-table-tag nil
) ; dynamically scoped into this.
2298 (defun org-export-as-html (arg &optional hidden ext-plist
2299 to-buffer body-only pub-dir
)
2300 "Export the outline as a pretty HTML file.
2301 If there is an active region, export only the region. The prefix
2302 ARG specifies how many levels of the outline should become
2303 headlines. The default is 3. Lower levels will become bulleted
2304 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2305 EXT-PLIST is a property list with external parameters overriding
2306 org-mode's default settings, but still inferior to file-local
2307 settings. When TO-BUFFER is non-nil, create a buffer with that
2308 name and export to that buffer. If TO-BUFFER is the symbol
2309 `string', don't leave any buffer behind but just return the
2310 resulting HTML as a string. When BODY-ONLY is set, don't produce
2311 the file header and footer, simply return the content of
2312 <body>...</body>, without even the body tags themselves. When
2313 PUB-DIR is set, use this as the publishing directory."
2316 ;; Make sure we have a file name when we need it.
2317 (when (and (not (or to-buffer body-only
))
2318 (not buffer-file-name
))
2319 (if (buffer-base-buffer)
2320 (org-set-local 'buffer-file-name
2321 (with-current-buffer (buffer-base-buffer)
2323 (error "Need a file name to be able to export.")))
2325 (message "Exporting...")
2326 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2327 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2328 (setq-default org-done-keywords org-done-keywords
)
2329 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2331 (org-export-process-option-filters
2332 (org-combine-plists (org-default-export-plist)
2334 (org-infile-export-plist))))
2336 (style (plist-get opt-plist
:style
))
2337 (html-extension (plist-get opt-plist
:html-extension
))
2338 (link-validate (plist-get opt-plist
:link-validation-function
))
2339 valid thetoc have-headings first-heading-pos
2340 (odd org-odd-levels-only
)
2341 (region-p (org-region-active-p))
2345 (goto-char (region-beginning))
2346 (and (org-at-heading-p)
2347 (>= (org-end-of-subtree t t
) (region-end))))))
2348 ;; The following two are dynamically scoped into other
2350 (org-current-export-dir
2351 (or pub-dir
(org-export-directory :html opt-plist
)))
2352 (org-current-export-file buffer-file-name
)
2353 (level 0) (line "") (origline "") txt todo
2356 (filename (if to-buffer nil
2359 (file-name-sans-extension
2361 (org-entry-get (region-beginning)
2362 "EXPORT_FILE_NAME" t
))
2363 (file-name-nondirectory buffer-file-name
)))
2365 (file-name-as-directory
2366 (or pub-dir
(org-export-directory :html opt-plist
))))))
2367 (current-dir (if buffer-file-name
2368 (file-name-directory buffer-file-name
)
2370 (buffer (if to-buffer
2372 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2373 (t (get-buffer-create to-buffer
)))
2374 (find-file-noselect filename
)))
2375 (org-levels-open (make-vector org-level-max nil
))
2376 (date (plist-get opt-plist
:date
))
2377 (author (plist-get opt-plist
:author
))
2378 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2379 (plist-get opt-plist
:title
)
2381 (plist-get opt-plist
:skip-before-1st-heading
))
2382 (org-export-grab-title-from-buffer))
2383 (and buffer-file-name
2384 (file-name-sans-extension
2385 (file-name-nondirectory buffer-file-name
)))
2387 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2388 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2389 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2393 (local-list-type nil
)
2394 (local-list-indent nil
)
2395 (llt org-plain-list-ordered-item-terminator
)
2396 (email (plist-get opt-plist
:email
))
2397 (language (plist-get opt-plist
:language
))
2401 (coding-system (and (boundp 'buffer-file-coding-system
)
2402 buffer-file-coding-system
))
2403 (coding-system-for-write (or org-export-html-coding-system
2405 (save-buffer-coding-system (or org-export-html-coding-system
2407 (charset (and coding-system-for-write
2408 (fboundp 'coding-system-get
)
2409 (coding-system-get coding-system-for-write
2413 (if region-p
(region-beginning) (point-min))
2414 (if region-p
(region-end) (point-max))))
2417 (org-export-preprocess-string
2421 :skip-before-1st-heading
2422 (plist-get opt-plist
:skip-before-1st-heading
)
2423 :drawers
(plist-get opt-plist
:drawers
)
2425 (plist-get opt-plist
:archived-trees
)
2427 (plist-get opt-plist
:text
)
2429 (plist-get opt-plist
:LaTeX-fragments
))
2432 table-buffer table-orig-buffer
2433 ind item-type starter didclose
2434 rpl path desc descp desc1 desc2 link
2435 snumber fnc item-tag
2438 (let ((inhibit-read-only t
))
2440 (remove-text-properties (point-min) (point-max)
2441 '(:org-license-to-kill t
))))
2443 (message "Exporting...")
2445 (setq org-min-level
(org-get-min-level lines
))
2446 (setq org-last-level org-min-level
)
2447 (org-init-section-numbers)
2450 ((and date
(string-match "%" date
))
2451 (setq date
(format-time-string date
)))
2453 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2455 ;; Get the language-dependent settings
2456 (setq lang-words
(or (assoc language org-export-language-setup
)
2457 (assoc "en" org-export-language-setup
)))
2459 ;; Switch to the output buffer
2461 (let ((inhibit-read-only t
)) (erase-buffer))
2464 (and (fboundp 'set-buffer-file-coding-system
)
2465 (set-buffer-file-coding-system coding-system-for-write
))
2467 (let ((case-fold-search nil
)
2468 (org-odd-levels-only odd
))
2469 ;; create local variables for all options, to make sure all called
2470 ;; functions get the correct information
2472 (set (make-local-variable (cdr x
))
2473 (plist-get opt-plist
(car x
))))
2474 org-export-plist-vars
)
2475 (setq umax
(if arg
(prefix-numeric-value arg
)
2476 org-export-headline-levels
))
2477 (setq umax-toc
(if (integerp org-export-with-toc
)
2478 (min org-export-with-toc umax
)
2483 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2484 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2485 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2486 lang=\"%s\" xml:lang=\"%s\">
2489 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2490 <meta name=\"generator\" content=\"Org-mode\"/>
2491 <meta name=\"generated\" content=\"%s\"/>
2492 <meta name=\"author\" content=\"%s\"/>
2496 language language
(org-html-expand title
)
2497 (or charset
"iso-8859-1") date author style
))
2499 (insert (or (plist-get opt-plist
:preamble
) ""))
2501 (when (plist-get opt-plist
:auto-preamble
)
2502 (if title
(insert (format org-export-html-title-format
2503 (org-html-expand title
))))))
2505 (if (and org-export-with-toc
(not body-only
))
2507 (push (format "<h%d>%s</h%d>\n"
2508 org-export-html-toplevel-hlevel
2510 org-export-html-toplevel-hlevel
)
2512 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2513 (push "<ul>\n<li>" thetoc
)
2515 (mapcar '(lambda (line)
2516 (if (string-match org-todo-line-regexp line
)
2517 ;; This is a headline
2519 (setq have-headings t
)
2520 (setq level
(- (match-end 1) (match-beginning 1))
2521 level
(org-tr-level level
)
2522 txt
(save-match-data
2524 (org-export-cleanup-toc-line
2525 (match-string 3 line
))))
2527 (or (and org-export-mark-todo-in-toc
2529 (not (member (match-string 2 line
)
2530 org-done-keywords
)))
2532 (and org-export-mark-todo-in-toc
2534 (org-search-todo-below
2535 line lines level
))))
2537 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2538 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2539 (if (string-match quote-re0 txt
)
2540 (setq txt
(replace-match "" t t txt
)))
2541 (setq snumber
(org-section-number level
))
2542 (if org-export-with-section-numbers
2543 (setq txt
(concat snumber
" " txt
)))
2544 (if (<= level
(max umax umax-toc
))
2545 (setq head-count
(+ head-count
1)))
2546 (if (<= level umax-toc
)
2548 (if (> level org-last-level
)
2550 (setq cnt
(- level org-last-level
))
2551 (while (>= (setq cnt
(1- cnt
)) 0)
2552 (push "\n<ul>\n<li>" thetoc
))
2553 (push "\n" thetoc
)))
2554 (if (< level org-last-level
)
2556 (setq cnt
(- org-last-level level
))
2557 (while (>= (setq cnt
(1- cnt
)) 0)
2558 (push "</li>\n</ul>" thetoc
))
2559 (push "\n" thetoc
)))
2560 ;; Check for targets
2561 (while (string-match org-any-target-regexp line
)
2562 (setq line
(replace-match
2563 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2565 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2566 (setq txt
(replace-match "" t t txt
)))
2570 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2571 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2572 snumber txt
) thetoc
)
2574 (setq org-last-level level
))
2578 (while (> org-last-level
(1- org-min-level
))
2579 (setq org-last-level
(1- org-last-level
))
2580 (push "</li>\n</ul>\n" thetoc
))
2581 (push "</div>\n" thetoc
)
2582 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2585 (org-init-section-numbers)
2587 (while (setq line
(pop lines
) origline line
)
2590 ;; end of quote section?
2591 (when (and inquote
(string-match "^\\*+ " line
))
2594 ;; inside a quote section?
2596 (insert (org-html-protect line
) "\n")
2597 (throw 'nextline nil
))
2600 (when (and org-export-with-fixed-width
2601 (string-match "^[ \t]*:\\(.*\\)" line
))
2605 (insert (org-html-protect (match-string 1 line
)) "\n")
2607 (not (string-match "^[ \t]*\\(:.*\\)"
2610 (insert "</pre>\n"))
2611 (throw 'nextline nil
))
2614 (when (get-text-property 0 'org-protected line
)
2616 (when (re-search-backward
2617 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2618 (setq par
(match-string 1))
2619 (replace-match "\\2\n"))
2622 (not (string-match "^[ \t]*:" (car lines
)))
2623 (or (= (length (car lines
)) 0)
2624 (get-text-property 0 'org-protected
(car lines
))))
2625 (insert (pop lines
) "\n"))
2626 (and par
(insert "<p>\n")))
2627 (throw 'nextline nil
))
2630 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2631 (insert "\n<hr/>\n")
2632 (throw 'nextline nil
))
2634 ;; Blockquotes and verse
2635 (when (equal "ORG-BLOCKQUOTE-START" line
)
2636 (insert "<blockquote>\n<p>\n")
2637 (throw 'nextline nil
))
2638 (when (equal "ORG-BLOCKQUOTE-END" line
)
2639 (insert "</p>\n</blockquote>\n")
2640 (throw 'nextline nil
))
2641 (when (equal "ORG-VERSE-START" line
)
2642 (insert "<verse>\n<p>\n")
2643 (throw 'nextline nil
))
2644 (when (equal "ORG-VERSE-END" line
)
2645 (insert "</p>\n</verse>\n")
2646 (throw 'nextline nil
))
2648 ;; make targets to anchors
2649 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2652 (setq line
(replace-match
2653 (concat "@<a name=\""
2654 (org-solidify-link-text (match-string 1 line
))
2657 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2658 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2659 (setq line
(replace-match
2660 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2661 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2664 (setq line
(replace-match
2665 (concat "@<a name=\""
2666 (org-solidify-link-text (match-string 1 line
))
2667 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2670 (setq line
(org-html-handle-time-stamps line
))
2672 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2673 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2674 ;; Also handle sub_superscripts and checkboxes
2675 (or (string-match org-table-hline-regexp line
)
2676 (setq line
(org-html-expand line
)))
2680 (while (string-match org-bracket-link-analytic-regexp line start
)
2681 (setq start
(match-beginning 0))
2682 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2683 (setq path
(match-string 3 line
))
2684 (setq desc1
(if (match-end 5) (match-string 5 line
))
2685 desc2
(if (match-end 2) (concat type
":" path
) path
)
2686 descp
(and desc1
(not (equal desc1 desc2
)))
2687 desc
(or desc1 desc2
))
2688 ;; Make an image out of the description if that is so wanted
2689 (when (and descp
(org-file-image-p desc
))
2691 (if (string-match "^file:" desc
)
2692 (setq desc
(substring desc
(match-end 0)))))
2693 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2694 ;; FIXME: do we need to unescape here somewhere?
2696 ((equal type
"internal")
2700 (org-solidify-link-text
2701 (save-match-data (org-link-unescape path
)) nil
)
2702 "\">" desc
"</a>")))
2703 ((member type
'("http" "https"))
2704 ;; standard URL, just check if we need to inline an image
2705 (if (and (or (eq t org-export-html-inline-images
)
2706 (and org-export-html-inline-images
(not descp
)))
2707 (org-file-image-p path
))
2708 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2709 (setq link
(concat type
":" path
))
2710 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2711 ((member type
'("ftp" "mailto" "news"))
2713 (setq link
(concat type
":" path
))
2714 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2715 ((string= type
"file")
2717 (let* ((filename path
)
2718 (abs-p (file-name-absolute-p filename
))
2719 thefile file-is-image-p search
)
2721 (if (string-match "::\\(.*\\)" filename
)
2722 (setq search
(match-string 1 filename
)
2723 filename
(replace-match "" t nil filename
)))
2725 (if (functionp link-validate
)
2726 (funcall link-validate filename current-dir
)
2728 (setq file-is-image-p
(org-file-image-p filename
))
2729 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2730 (when (and org-export-html-link-org-files-as-html
2731 (string-match "\\.org$" thefile
))
2732 (setq thefile
(concat (substring thefile
0
2733 (match-beginning 0))
2734 "." html-extension
))
2736 ;; make sure this is can be used as target search
2737 (not (string-match "^[0-9]*$" search
))
2738 (not (string-match "^\\*" search
))
2739 (not (string-match "^/.*/$" search
)))
2740 (setq thefile
(concat thefile
"#"
2741 (org-solidify-link-text
2742 (org-link-unescape search
)))))
2743 (when (string-match "^file:" desc
)
2744 (setq desc
(replace-match "" t t desc
))
2745 (if (string-match "\\.org$" desc
)
2746 (setq desc
(replace-match "" t t desc
))))))
2747 (setq rpl
(if (and file-is-image-p
2748 (or (eq t org-export-html-inline-images
)
2749 (and org-export-html-inline-images
2751 (concat "<img src=\"" thefile
"\"/>")
2752 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2753 (if (not valid
) (setq rpl desc
))))
2755 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2758 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2761 ;; just publish the path, as default
2762 (setq rpl
(concat "<i><" type
":"
2763 (save-match-data (org-link-unescape path
))
2765 (setq line
(replace-match rpl t t line
)
2766 start
(+ start
(length rpl
))))
2769 (if (and (string-match org-todo-line-regexp line
)
2770 (match-beginning 2))
2773 (concat (substring line
0 (match-beginning 2))
2775 (if (member (match-string 2 line
)
2778 "\">" (match-string 2 line
)
2779 "</span>" (substring line
(match-end 2)))))
2781 ;; Does this contain a reference to a footnote?
2782 (when org-export-with-footnotes
2784 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2785 (if (get-text-property (match-beginning 2) 'org-protected line
)
2786 (setq start
(match-end 2))
2787 (let ((n (match-string 2 line
)))
2791 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2792 (match-string 1 line
) n n n
)
2796 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2797 ;; This is a headline
2798 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2799 txt
(match-string 2 line
))
2800 (if (string-match quote-re0 txt
)
2801 (setq txt
(replace-match "" t t txt
)))
2802 (if (<= level
(max umax umax-toc
))
2803 (setq head-count
(+ head-count
1)))
2805 ;; Close any local lists before inserting a new header line
2806 (while local-list-type
2807 (org-close-li (car local-list-type
))
2808 (insert (format "</%sl>\n" (car local-list-type
)))
2809 (pop local-list-type
))
2810 (setq local-list-indent nil
2812 (setq first-heading-pos
(or first-heading-pos
(point)))
2813 (org-html-level-start level txt umax
2814 (and org-export-with-toc
(<= level umax
))
2817 (when (string-match quote-re line
)
2821 ((and org-export-with-tables
2822 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2823 (if (not table-open
)
2825 (setq table-open t table-buffer nil table-orig-buffer nil
))
2827 (setq table-buffer
(cons line table-buffer
)
2828 table-orig-buffer
(cons origline table-orig-buffer
))
2829 (when (or (not lines
)
2830 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2832 (setq table-open nil
2833 table-buffer
(nreverse table-buffer
)
2834 table-orig-buffer
(nreverse table-orig-buffer
))
2835 (org-close-par-maybe)
2836 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2841 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2842 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2843 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2844 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2846 (setq ind
(org-get-string-indentation line
)
2847 item-type
(if (match-beginning 4) "o" "u")
2848 starter
(if (match-beginning 2)
2849 (substring (match-string 2 line
) 0 -
1))
2850 line
(substring line
(match-beginning 5))
2852 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2854 item-tag
(match-string 1 line
)
2855 line
(substring line
(match-end 0))))
2856 (unless (string-match "[^ \t]" line
)
2857 ;; empty line. Pretend indentation is large.
2858 (setq ind
(if org-empty-line-terminates-plain-lists
2860 (1+ (or (car local-list-indent
) 1)))))
2862 (while (and in-local-list
2863 (or (and (= ind
(car local-list-indent
))
2865 (< ind
(car local-list-indent
))))
2867 (org-close-li (car local-list-type
))
2868 (insert (format "</%sl>\n" (car local-list-type
)))
2869 (pop local-list-type
) (pop local-list-indent
)
2870 (setq in-local-list local-list-indent
))
2873 (or (not in-local-list
)
2874 (> ind
(car local-list-indent
))))
2875 ;; Start new (level of) list
2876 (org-close-par-maybe)
2878 ((equal item-type
"u") "<ul>\n<li>\n")
2879 ((equal item-type
"o") "<ol>\n<li>\n")
2880 ((equal item-type
"d")
2881 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2882 (push item-type local-list-type
)
2883 (push ind local-list-indent
)
2884 (setq in-local-list t
))
2886 ;; continue current list
2887 (org-close-li (car local-list-type
))
2889 ((equal (car local-list-type
) "d")
2890 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2893 ;; we did close a list, normal text follows: need <p>
2895 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2898 (if (equal (match-string 1 line
) "X")
2900 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2903 ;; Empty lines start a new paragraph. If hand-formatted lists
2904 ;; are not fully interpreted, lines starting with "-", "+", "*"
2905 ;; also start a new paragraph.
2906 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2908 ;; Is this the start of a footnote?
2909 (when org-export-with-footnotes
2910 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2911 (org-close-par-maybe)
2912 (let ((n (match-string 1 line
)))
2913 (setq line
(replace-match
2914 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2916 ;; Check if the line break needs to be conserved
2918 ((string-match "\\\\\\\\[ \t]*$" line
)
2919 (setq line
(replace-match "<br/>" t t line
)))
2920 (org-export-preserve-breaks
2921 (setq line
(concat line
"<br/>"))))
2923 (insert line
"\n")))))
2925 ;; Properly close all local lists and other lists
2926 (when inquote
(insert "</pre>\n"))
2928 ;; Close any local lists before inserting a new header line
2929 (while local-list-type
2930 (org-close-li (car local-list-type
))
2931 (insert (format "</%sl>\n" (car local-list-type
)))
2932 (pop local-list-type
))
2933 (setq local-list-indent nil
2935 (org-html-level-start 1 nil umax
2936 (and org-export-with-toc
(<= level umax
))
2938 ;; the </div> to lose the last text-... div.
2942 (when (plist-get opt-plist
:auto-postamble
)
2943 (insert "<div id=\"postamble\">")
2944 (when (and org-export-author-info author
)
2945 (insert "<p class=\"author\"> "
2946 (nth 1 lang-words
) ": " author
"\n")
2948 (if (listp (split-string email
",+ *"))
2950 (insert "<a href=\"mailto:" e
"\"><"
2952 (split-string email
",+ *"))
2953 (insert "<a href=\"mailto:" email
"\"><"
2954 email
"></a>\n")))
2956 (when (and date org-export-time-stamp-file
)
2957 (insert "<p class=\"date\"> "
2958 (nth 2 lang-words
) ": "
2962 (if org-export-html-with-timestamp
2963 (insert org-export-html-html-helper-timestamp
))
2964 (insert (or (plist-get opt-plist
:postamble
) ""))
2965 (insert "</body>\n</html>\n"))
2968 (if (eq major-mode default-major-mode
) (html-mode))
2970 ;; insert the table of contents
2971 (goto-char (point-min))
2973 (if (or (re-search-forward
2974 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2976 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2978 (goto-char (match-beginning 0))
2980 (goto-char first-heading-pos
)
2981 (when (looking-at "\\s-*</p>")
2982 (goto-char (match-end 0))
2984 (insert "<div id=\"table-of-contents\">\n")
2985 (mapc 'insert thetoc
)
2986 (insert "</div>\n"))
2987 ;; remove empty paragraphs and lists
2988 (goto-char (point-min))
2989 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
2991 (goto-char (point-min))
2992 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
2994 (goto-char (point-min))
2995 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
2997 ;; Convert whitespace place holders
2998 (goto-char (point-min))
3000 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3001 (setq n
(get-text-property beg
'org-whitespace
)
3002 end
(next-single-property-change beg
'org-whitespace
))
3004 (delete-region beg end
)
3005 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3006 (make-string n ?x
)))))
3007 (or to-buffer
(save-buffer))
3008 (goto-char (point-min))
3009 (message "Exporting... done")
3010 (if (eq to-buffer
'string
)
3011 (prog1 (buffer-substring (point-min) (point-max))
3012 (kill-buffer (current-buffer)))
3013 (current-buffer)))))
3015 (defvar org-table-colgroup-info nil
)
3016 (defun org-format-table-ascii (lines)
3017 "Format a table for ascii export."
3019 (setq lines
(org-split-string lines
"\n")))
3020 (if (not (string-match "^[ \t]*|" (car lines
)))
3021 ;; Table made by table.el - test for spanning
3024 ;; A normal org table
3025 ;; Get rid of hlines at beginning and end
3026 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3027 (setq lines
(nreverse lines
))
3028 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3029 (setq lines
(nreverse lines
))
3030 (when org-export-table-remove-special-lines
3031 ;; Check if the table has a marking column. If yes remove the
3032 ;; column and the special lines
3033 (setq lines
(org-table-clean-before-export lines
)))
3034 ;; Get rid of the vertical lines except for grouping
3035 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3037 (while (setq line
(pop lines
))
3038 (if (string-match org-table-hline-regexp line
)
3039 (and (string-match "|\\(.*\\)|" line
)
3040 (setq line
(replace-match " \\1" t nil line
)))
3041 (setq start
0 vl1 vl
)
3042 (while (string-match "|" line start
)
3043 (setq start
(match-end 0))
3044 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3048 (defun org-colgroup-info-to-vline-list (info)
3051 (setq last new new
(pop info
))
3052 (if (or (memq last
'(:end
:startend
))
3053 (memq new
'(:start
:startend
)))
3056 (setq vl
(nreverse vl
))
3057 (and vl
(setcar vl nil
))
3060 (defvar org-table-number-regexp
) ; defined in org-table.el
3061 (defun org-format-table-html (lines olines
)
3062 "Find out which HTML converter to use and return the HTML code."
3064 (setq lines
(org-split-string lines
"\n")))
3065 (if (string-match "^[ \t]*|" (car lines
))
3066 ;; A normal org table
3067 (org-format-org-table-html lines
)
3068 ;; Table made by table.el - test for spanning
3069 (let* ((hlines (delq nil
(mapcar
3071 (if (string-match "^[ \t]*\\+-" x
) x
3074 (first (car hlines
))
3075 (ll (and (string-match "\\S-+" first
)
3076 (match-string 0 first
)))
3077 (re (concat "^[ \t]*" (regexp-quote ll
)))
3078 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3080 (if (and (not spanning
)
3081 (not org-export-prefer-native-exporter-for-tables
))
3082 ;; We can use my own converter with HTML conversions
3083 (org-format-table-table-html lines
)
3084 ;; Need to use the code generator in table.el, with the original text.
3085 (org-format-table-table-html-using-table-generate-source olines
)))))
3087 (defvar org-table-number-fraction
) ; defined in org-table.el
3088 (defun org-format-org-table-html (lines &optional splice
)
3089 "Format a table into HTML."
3090 (require 'org-table
)
3091 ;; Get rid of hlines at beginning and end
3092 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3093 (setq lines
(nreverse lines
))
3094 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3095 (setq lines
(nreverse lines
))
3096 (when org-export-table-remove-special-lines
3097 ;; Check if the table has a marking column. If yes remove the
3098 ;; column and the special lines
3099 (setq lines
(org-table-clean-before-export lines
)))
3101 (let ((head (and org-export-highlight-first-table-line
3103 (lambda (x) (string-match "^[ \t]*|-" x
))
3106 tbopen line fields html gr colgropen
)
3107 (if splice
(setq head nil
))
3108 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3110 (while (setq line
(pop lines
))
3112 (if (string-match "^[ \t]*|-" line
)
3115 (push (if head
"</thead>" "</tbody>") html
)
3116 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3117 (setq head nil
) ;; head ends here, first time around
3119 (throw 'next-line t
)))
3120 ;; Break the line into fields
3121 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3122 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3123 (setq nlines
(1+ nlines
) i -
1)
3124 (push (concat "<tr>"
3128 (if (and (< i nlines
)
3129 (string-match org-table-number-regexp x
))
3130 (incf (aref fnum i
)))
3132 (concat (car org-export-table-header-tags
) x
3133 (cdr org-export-table-header-tags
))
3134 (concat (car org-export-table-data-tags
) x
3135 (cdr org-export-table-data-tags
))))
3139 (unless splice
(if tbopen
(push "</tbody>" html
)))
3140 (unless splice
(push "</table>\n" html
))
3141 (setq html
(nreverse html
))
3143 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3146 (setq gr
(pop org-table-colgroup-info
))
3147 (format "%s<col align=\"%s\"></col>%s"
3148 (if (memq gr
'(:start
:startend
))
3150 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3153 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3155 (if (memq gr
'(:end
:startend
))
3156 (progn (setq colgropen nil
) "</colgroup>")
3160 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3161 (push html-table-tag html
))
3162 (concat (mapconcat 'identity html
"\n") "\n")))
3164 (defun org-table-clean-before-export (lines)
3165 "Check if the table has a marking column.
3166 If yes remove the column and the special lines."
3167 (setq org-table-colgroup-info nil
)
3170 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3171 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3174 (setq org-table-clean-did-remove-column nil
)
3179 ((string-match "^[ \t]*| */ *|" x
)
3180 (setq org-table-colgroup-info
3182 (cond ((member x
'("<" "<")) :start
)
3183 ((member x
'(">" ">")) :end
)
3184 ((member x
'("<>" "<>")) :startend
)
3186 (org-split-string x
"[ \t]*|[ \t]*")))
3190 (setq org-table-clean-did-remove-column t
)
3195 ((string-match "^[ \t]*| */ *|" x
)
3196 (setq org-table-colgroup-info
3198 (cond ((member x
'("<" "<")) :start
)
3199 ((member x
'(">" ">")) :end
)
3200 ((member x
'("<>" "<>")) :startend
)
3202 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3204 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3205 nil
) ; ignore this line
3206 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3207 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3208 ;; remove the first column
3209 (replace-match "\\1|" t nil x
))))
3212 (defun org-format-table-table-html (lines)
3213 "Format a table generated by table.el into HTML.
3214 This conversion does *not* use `table-generate-source' from table.el.
3215 This has the advantage that Org-mode's HTML conversions can be used.
3216 But it has the disadvantage, that no cell- or row-spanning is allowed."
3217 (let (line field-buffer
3218 (head org-export-highlight-first-table-line
)
3220 (setq html
(concat html-table-tag
"\n"))
3221 (while (setq line
(pop lines
))
3222 (setq empty
" ")
3224 (if (string-match "^[ \t]*\\+-" line
)
3235 (if (equal x
"") (setq x empty
))
3237 (concat (car org-export-table-header-tags
) x
3238 (cdr org-export-table-header-tags
))
3239 (concat (car org-export-table-data-tags
) x
3240 (cdr org-export-table-data-tags
))))
3244 (setq field-buffer nil
)))
3246 (throw 'next-line t
)))
3247 ;; Break the line into fields and store the fields
3248 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3250 (setq field-buffer
(mapcar
3252 (concat x
"<br/>" (pop fields
)))
3254 (setq field-buffer fields
))))
3255 (setq html
(concat html
"</table>\n"))
3258 (defun org-format-table-table-html-using-table-generate-source (lines)
3259 "Format a table into html, using `table-generate-source' from table.el.
3260 This has the advantage that cell- or row-spanning is allowed.
3261 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3263 (with-current-buffer (get-buffer-create " org-tmp1 ")
3265 (insert (mapconcat 'identity lines
"\n"))
3266 (goto-char (point-min))
3267 (if (not (re-search-forward "|[^+]" nil t
))
3268 (error "Error processing table"))
3269 (table-recognize-table)
3270 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3271 (table-generate-source 'html
" org-tmp2 ")
3272 (set-buffer " org-tmp2 ")
3273 (buffer-substring (point-min) (point-max))))
3275 (defun org-html-handle-time-stamps (s)
3276 "Format time stamps in string S, or remove them."
3279 (while (string-match org-maybe-keyword-time-regexp s
)
3280 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3281 ;; never export CLOCK
3283 (or b
(setq b
(substring s
0 (match-beginning 0))))
3284 (if (not org-export-with-timestamps
)
3285 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3286 s
(substring s
(match-end 0)))
3288 r
(substring s
0 (match-beginning 0))
3290 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3291 (match-string 1 s
)))
3292 (format " @<span class=\"timestamp\">%s@</span>"
3294 (org-translate-time (match-string 3 s
)) 1 -
1)))
3295 s
(substring s
(match-end 0)))))
3296 ;; Line break if line started and ended with time stamp stuff
3299 (setq r
(concat r s
))
3300 (unless (string-match "\\S-" (concat b s
))
3301 (setq r
(concat r
"@<br/>")))
3304 (defun org-export-htmlize-region-for-paste (beg end
)
3305 "Convert the region to HTML, using htmlize.el.
3306 This is much like `htmlize-region-for-paste', only that it uses
3307 the settings define in the org-... variables."
3308 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3309 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3310 (htmlbuf (htmlize-region beg end
)))
3312 (with-current-buffer htmlbuf
3313 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3314 (plist-get htmlize-buffer-places
'content-end
)))
3315 (kill-buffer htmlbuf
))))
3318 (defun org-export-htmlize-generate-css ()
3319 "Create the CSS for all font definitions in the current Emacs session.
3320 Use this to create face definitions in your CSS style file that can then
3321 be used by code snippets transformed by htmlize.
3322 This command just produces a buffer that contains class definitions for all
3323 faces used in the current Emacs session. You can copy and paste the ones you
3324 need into your CSS file.
3326 If you then set `org-export-htmlize-output-type' to `css', calls to
3327 the function `org-export-htmlize-region-for-paste' will produce code
3328 that uses these same face definitions."
3331 (and (get-buffer "*html*") (kill-buffer "*html*"))
3333 (let ((fl (face-list))
3334 (htmlize-css-name-prefix "org-")
3335 (htmlize-output-type 'css
)
3337 (while (setq f
(pop fl
)
3338 i
(and f
(face-attribute f
:inherit
)))
3339 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3340 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3341 (htmlize-region (point-min) (point-max))))
3342 (switch-to-buffer "*html*")
3343 (goto-char (point-min))
3344 (if (re-search-forward "<style" nil t
)
3345 (delete-region (point-min) (match-beginning 0)))
3346 (if (re-search-forward "</style>" nil t
)
3347 (delete-region (1+ (match-end 0)) (point-max)))
3348 (beginning-of-line 1)
3349 (if (looking-at " +") (replace-match ""))
3350 (goto-char (point-min)))
3352 (defun org-html-protect (s)
3353 ;; convert & to &, < to < and > to >
3355 (while (string-match "&" s start
)
3356 (setq s
(replace-match "&" t t s
)
3357 start
(1+ (match-beginning 0))))
3358 (while (string-match "<" s
)
3359 (setq s
(replace-match "<" t t s
)))
3360 (while (string-match ">" s
)
3361 (setq s
(replace-match ">" t t s
))))
3364 (defun org-export-cleanup-toc-line (s)
3365 "Remove tags and time staps from lines going into the toc."
3366 (when (memq org-export-with-tags
'(not-in-toc nil
))
3367 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3368 (setq s
(replace-match "" t t s
))))
3369 (when org-export-remove-timestamps-from-toc
3370 (while (string-match org-maybe-keyword-time-regexp s
)
3371 (setq s
(replace-match "" t t s
))))
3372 (while (string-match org-bracket-link-regexp s
)
3373 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3377 (defun org-html-expand (string)
3378 "Prepare STRING for HTML export. Applies all active conversions.
3379 If there are links in the string, don't modify these."
3380 (let* ((re (concat org-bracket-link-regexp
"\\|"
3381 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3383 (while (setq m
(string-match re string
))
3384 (setq s
(substring string
0 m
)
3385 l
(match-string 0 string
)
3386 string
(substring string
(match-end 0)))
3387 (push (org-html-do-expand s
) res
)
3389 (push (org-html-do-expand string
) res
)
3390 (apply 'concat
(nreverse res
))))
3392 (defun org-html-do-expand (s)
3393 "Apply all active conversions to translate special ASCII to HTML."
3394 (setq s
(org-html-protect s
))
3395 (if org-export-html-expand
3397 (while (string-match "@<\\([^&]*\\)>" s
)
3398 (setq s
(replace-match "<\\1>" t nil s
)))))
3399 (if org-export-with-emphasize
3400 (setq s
(org-export-html-convert-emphasize s
)))
3401 (if org-export-with-special-strings
3402 (setq s
(org-export-html-convert-special-strings s
)))
3403 (if org-export-with-sub-superscripts
3404 (setq s
(org-export-html-convert-sub-super s
)))
3405 (if org-export-with-TeX-macros
3406 (let ((start 0) wd ass
)
3407 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3408 (if (get-text-property (match-beginning 0) 'org-protected s
)
3409 (setq start
(match-end 0))
3410 (setq wd
(match-string 1 s
))
3411 (if (setq ass
(assoc wd org-html-entities
))
3412 (setq s
(replace-match (or (cdr ass
)
3413 (concat "&" (car ass
) ";"))
3415 (setq start
(+ start
(length wd
))))))))
3418 (defun org-create-multibrace-regexp (left right n
)
3419 "Create a regular expression which will match a balanced sexp.
3420 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3421 as single character strings.
3422 The regexp returned will match the entire expression including the
3423 delimiters. It will also define a single group which contains the
3424 match except for the outermost delimiters. The maximum depth of
3425 stacked delimiters is N. Escaping delimiters is not possible."
3426 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3429 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3432 re
(concat re or next
)
3433 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3434 (concat left
"\\(" re
"\\)" right
)))
3436 (defvar org-match-substring-regexp
3438 "\\([^\\]\\)\\([_^]\\)\\("
3439 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3441 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3443 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3444 "The regular expression matching a sub- or superscript.")
3446 (defvar org-match-substring-with-braces-regexp
3448 "\\([^\\]\\)\\([_^]\\)\\("
3449 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3451 "The regular expression matching a sub- or superscript, forcing braces.")
3453 (defconst org-export-html-special-string-regexps
3454 '(("\\\\-" .
"­")
3455 ("---\\([^-]\\)" .
"—\\1")
3456 ("--\\([^-]\\)" .
"–\\1")
3457 ("\\.\\.\\." .
"…"))
3458 "Regular expressions for special string conversion.")
3460 (defun org-export-html-convert-special-strings (string)
3461 "Convert special characters in STRING to HTML."
3462 (let ((all org-export-html-special-string-regexps
)
3464 (while (setq a
(pop all
))
3465 (setq re
(car a
) rpl
(cdr a
) start
0)
3466 (while (string-match re string start
)
3467 (if (get-text-property (match-beginning 0) 'org-protected string
)
3468 (setq start
(match-end 0))
3469 (setq string
(replace-match rpl t nil string
)))))
3472 (defun org-export-html-convert-sub-super (string)
3473 "Convert sub- and superscripts in STRING to HTML."
3474 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3475 (while (string-match org-match-substring-regexp string s
)
3477 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3478 ((get-text-property (match-beginning 2) 'org-protected string
)
3479 (setq s
(match-end 2)))
3481 (setq s
(match-end 1)
3482 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3483 c
(or (match-string 8 string
)
3484 (match-string 6 string
)
3485 (match-string 5 string
))
3486 string
(replace-match
3487 (concat (match-string 1 string
)
3488 "<" key
">" c
"</" key
">")
3490 (while (string-match "\\\\\\([_^]\\)" string
)
3491 (setq string
(replace-match (match-string 1 string
) t t string
)))
3494 (defun org-export-html-convert-emphasize (string)
3497 (while (string-match org-emph-re string s
)
3499 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3500 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3501 (setq s
(match-beginning 0)
3504 (match-string 1 string
)
3505 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3506 (match-string 4 string
)
3507 (nth 3 (assoc (match-string 3 string
)
3508 org-emphasis-alist
))
3509 (match-string 5 string
))
3510 string
(replace-match rpl t t string
)
3511 s
(+ s
(- (length rpl
) 2)))
3515 (defvar org-par-open nil
)
3516 (defun org-open-par ()
3517 "Insert <p>, but first close previous paragraph if any."
3518 (org-close-par-maybe)
3520 (setq org-par-open t
))
3521 (defun org-close-par-maybe ()
3522 "Close paragraph if there is one open."
3525 (setq org-par-open nil
)))
3526 (defun org-close-li (&optional type
)
3527 "Close <li> if necessary."
3528 (org-close-par-maybe)
3529 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3531 (defvar body-only
) ; dynamically scoped into this.
3532 (defun org-html-level-start (level title umax with-toc head-count
)
3533 "Insert a new level in HTML export.
3534 When TITLE is nil, just close all open levels."
3535 (org-close-par-maybe)
3536 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3540 (if (aref org-levels-open
(1- l
))
3542 (org-html-level-close l umax
)
3543 (aset org-levels-open
(1- l
) nil
)))
3546 ;; If title is nil, this means this function is called to close
3547 ;; all levels, so the rest is done only if title is given
3548 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3549 (setq title
(replace-match
3550 (if org-export-with-tags
3553 " <span class=\"tag\">"
3554 (mapconcat 'identity
(org-split-string
3555 (match-string 1 title
) ":")
3562 (if (aref org-levels-open
(1- level
))
3566 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3567 (insert "<li>" title
"<br/>\n")))
3568 (aset org-levels-open
(1- level
) t
)
3569 (org-close-par-maybe)
3571 (insert (format "<ul>\n<li id=\"%s\">" target
)
3573 (insert "<ul>\n<li>" title
"<br/>\n"))))
3574 (aset org-levels-open
(1- level
) t
)
3575 (setq snumber
(org-section-number level
))
3576 (if (and org-export-with-section-numbers
(not body-only
))
3577 (setq title
(concat snumber
" " title
)))
3578 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3579 (unless (= head-count
1) (insert "\n</div>\n"))
3580 (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"
3581 snumber level level snumber title level snumber
))
3584 (defun org-get-text-property-any (pos prop
&optional object
)
3585 (or (get-text-property pos prop object
)
3586 (and (setq pos
(next-single-property-change pos prop object
))
3587 (get-text-property pos prop object
))))
3589 (defun org-html-level-close (level max-outline-level
)
3590 "Terminate one level in HTML export."
3591 (if (<= level max-outline-level
)
3594 (insert "</ul>\n")))
3596 ;;; iCalendar export
3599 (defun org-export-icalendar-this-file ()
3600 "Export current file as an iCalendar file.
3601 The iCalendar file will be located in the same directory as the Org-mode
3602 file, but with extension `.ics'."
3604 (org-export-icalendar nil buffer-file-name
))
3607 (defun org-export-icalendar-all-agenda-files ()
3608 "Export all files in `org-agenda-files' to iCalendar .ics files.
3609 Each iCalendar file will be located in the same directory as the Org-mode
3610 file, but with extension `.ics'."
3612 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3615 (defun org-export-icalendar-combine-agenda-files ()
3616 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3617 The file is stored under the name `org-combined-agenda-icalendar-file'."
3619 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3621 (defun org-export-icalendar (combine &rest files
)
3622 "Create iCalendar files for all elements of FILES.
3623 If COMBINE is non-nil, combine all calendar entries into a single large
3624 file and store it under the name `org-combined-agenda-icalendar-file'."
3626 (org-prepare-agenda-buffers files
)
3627 (let* ((dir (org-export-directory
3628 :ical
(list :publishing-directory
3629 org-export-publishing-directory
)))
3630 file ical-file ical-buffer category started org-agenda-new-buffers
)
3631 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3634 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3635 org-combined-agenda-icalendar-file
3636 (expand-file-name org-combined-agenda-icalendar-file dir
))
3637 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3638 (set-buffer ical-buffer
) (erase-buffer))
3639 (while (setq file
(pop files
))
3641 (org-check-agenda-file file
)
3642 (set-buffer (org-get-agenda-file-buffer file
))
3644 (setq ical-file
(concat (file-name-as-directory dir
)
3645 (file-name-sans-extension
3646 (file-name-nondirectory buffer-file-name
))
3648 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3649 (with-current-buffer ical-buffer
(erase-buffer)))
3650 (setq category
(or org-category
3651 (file-name-sans-extension
3652 (file-name-nondirectory buffer-file-name
))))
3653 (if (symbolp category
) (setq category
(symbol-name category
)))
3654 (let ((standard-output ical-buffer
))
3656 (and (not started
) (setq started t
)
3657 (org-start-icalendar-file org-icalendar-combined-name
))
3658 (org-start-icalendar-file category
))
3659 (org-print-icalendar-entries combine
)
3660 (when (or (and combine
(not files
)) (not combine
))
3661 (org-finish-icalendar-file)
3662 (set-buffer ical-buffer
)
3664 (run-hooks 'org-after-save-iCalendar-file-hook
)
3665 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3667 (org-release-buffers org-agenda-new-buffers
))))
3669 (defvar org-after-save-iCalendar-file-hook nil
3670 "Hook run after an iCalendar file has been saved.
3671 The iCalendar buffer is still current when this hook is run.
3672 A good way to use this is to tell a desktop calenndar application to re-read
3673 the iCalendar file.")
3675 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3676 (defun org-print-icalendar-entries (&optional combine
)
3677 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3678 When COMBINE is non nil, add the category to each line."
3679 (require 'org-agenda
)
3680 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3681 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3682 (dts (org-ical-ts-to-string
3683 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3685 hd ts ts2 state status
(inc t
) pos b sexp rrule
3686 scheduledp deadlinep tmp pri category entry location summary desc
3687 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3688 (org-refresh-category-properties)
3690 (goto-char (point-min))
3691 (while (re-search-forward re1 nil t
)
3694 (when (boundp 'org-icalendar-verify-function
)
3695 (unless (funcall org-icalendar-verify-function
)
3696 (outline-next-heading)
3699 (setq pos
(match-beginning 0)
3702 hd
(condition-case nil
3703 (org-icalendar-cleanup-string
3705 (error (throw :skip nil
)))
3706 summary
(org-icalendar-cleanup-string
3707 (org-entry-get nil
"SUMMARY"))
3708 desc
(org-icalendar-cleanup-string
3709 (or (org-entry-get nil
"DESCRIPTION")
3710 (and org-icalendar-include-body
(org-get-entry)))
3711 t org-icalendar-include-body
)
3712 location
(org-icalendar-cleanup-string
3713 (org-entry-get nil
"LOCATION"))
3714 category
(org-get-category))
3715 (if (looking-at re2
)
3717 (goto-char (match-end 0))
3718 (setq ts2
(match-string 1) inc nil
))
3719 (setq tmp
(buffer-substring (max (point-min)
3720 (- pos org-ds-keyword-length
))
3722 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3725 (replace-match "\\1" t nil ts
))
3727 deadlinep
(string-match org-deadline-regexp tmp
)
3728 scheduledp
(string-match org-scheduled-regexp tmp
)
3729 ;; donep (org-entry-is-done-p)
3731 (if (or (string-match org-tr-regexp hd
)
3732 (string-match org-ts-regexp hd
))
3733 (setq hd
(replace-match "" t t hd
)))
3734 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3736 (concat "\nRRULE:FREQ="
3739 '(("d" .
"DAILY")("w" .
"WEEKLY")
3740 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3741 ";INTERVAL=" (match-string 1 ts
)))
3743 (setq summary
(or summary hd
))
3744 (if (string-match org-bracket-link-regexp summary
)
3746 (replace-match (if (match-end 3)
3747 (match-string 3 summary
)
3748 (match-string 1 summary
))
3750 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3751 (if scheduledp
(setq summary
(concat "S: " summary
)))
3752 (if (string-match "\\`<%%" ts
)
3753 (with-current-buffer sexp-buffer
3754 (insert (substring ts
1 -
1) " " summary
"\n"))
3755 (princ (format "BEGIN:VEVENT
3761 (org-ical-ts-to-string ts
"DTSTART")
3762 (org-ical-ts-to-string ts2
"DTEND" inc
)
3764 (if (and desc
(string-match "\\S-" desc
))
3765 (concat "\nDESCRIPTION: " desc
) "")
3766 (if (and location
(string-match "\\S-" location
))
3767 (concat "\nLOCATION: " location
) "")
3770 (when (and org-icalendar-include-sexps
3771 (condition-case nil
(require 'icalendar
) (error nil
))
3772 (fboundp 'icalendar-export-region
))
3773 ;; Get all the literal sexps
3774 (goto-char (point-min))
3775 (while (re-search-forward "^&?%%(" nil t
)
3778 (setq b
(match-beginning 0))
3779 (goto-char (1- (match-end 0)))
3782 (setq sexp
(buffer-substring b
(point)))
3783 (with-current-buffer sexp-buffer
3785 (princ (org-diary-to-ical-string sexp-buffer
)))))
3787 (when org-icalendar-include-todo
3788 (goto-char (point-min))
3789 (while (re-search-forward org-todo-line-regexp nil t
)
3792 (when (boundp 'org-icalendar-verify-function
)
3793 (unless (funcall org-icalendar-verify-function
)
3794 (outline-next-heading)
3797 (setq state
(match-string 2))
3798 (setq status
(if (member state org-done-keywords
)
3799 "COMPLETED" "NEEDS-ACTION"))
3801 (or (not (member state org-done-keywords
))
3802 (eq org-icalendar-include-todo
'all
))
3803 (not (member org-archive-tag
(org-get-tags-at)))
3805 (setq hd
(match-string 3)
3806 summary
(org-icalendar-cleanup-string
3807 (org-entry-get nil
"SUMMARY"))
3808 desc
(org-icalendar-cleanup-string
3809 (or (org-entry-get nil
"DESCRIPTION")
3810 (and org-icalendar-include-body
(org-get-entry)))
3811 t org-icalendar-include-body
)
3812 location
(org-icalendar-cleanup-string
3813 (org-entry-get nil
"LOCATION")))
3814 (if (string-match org-bracket-link-regexp hd
)
3815 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3816 (match-string 1 hd
))
3818 (if (string-match org-priority-regexp hd
)
3819 (setq pri
(string-to-char (match-string 2 hd
))
3820 hd
(concat (substring hd
0 (match-beginning 1))
3821 (substring hd
(match-end 1))))
3822 (setq pri org-default-priority
))
3823 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3824 (- org-lowest-priority org-highest-priority
))))))
3826 (princ (format "BEGIN:VTODO
3836 (if (and location
(string-match "\\S-" location
))
3837 (concat "\nLOCATION: " location
) "")
3838 (if (and desc
(string-match "\\S-" desc
))
3839 (concat "\nDESCRIPTION: " desc
) "")
3840 category pri status
)))))))))
3842 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3843 "Take out stuff and quote what needs to be quoted.
3844 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3845 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3850 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3851 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3852 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3853 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3855 (while (string-match "\\([,;]\\)" s start
)
3856 (setq start
(+ (match-beginning 0) 2)
3857 s
(replace-match "\\\\\\1" nil nil s
))))
3859 (while (string-match "[ \t]*\n[ \t]*" s
)
3860 (setq s
(replace-match "\\n" t t s
))))
3861 (setq s
(org-trim s
))
3864 (if (and (numberp maxlength
)
3865 (> (length s
) maxlength
))
3866 (setq s
(substring s
0 maxlength
)))))
3869 (defun org-get-entry ()
3870 "Clean-up description string."
3872 (org-back-to-heading t
)
3873 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3875 (defun org-start-icalendar-file (name)
3876 "Start an iCalendar file by inserting the header."
3877 (let ((user user-full-name
)
3878 (name (or name
"unknown"))
3879 (timezone (cadr (current-time-zone))))
3881 (format "BEGIN:VCALENDAR
3884 PRODID:-//%s//Emacs with Org-mode//EN
3886 CALSCALE:GREGORIAN\n" name user timezone
))))
3888 (defun org-finish-icalendar-file ()
3889 "Finish an iCalendar file by inserting the END statement."
3890 (princ "END:VCALENDAR\n"))
3892 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3893 "Take a time string S and convert it to iCalendar format.
3894 KEYWORD is added in front, to make a complete line like DTSTART....
3895 When INC is non-nil, increase the hour by two (if time string contains
3896 a time), or the day by one (if it does not contain a time)."
3897 (let ((t1 (org-parse-time-string s
'nodefault
))
3898 t2 fmt have-time time
)
3899 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3900 (setq t2 t1 have-time t
)
3901 (setq t2
(org-parse-time-string s
)))
3902 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3903 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3906 (if org-agenda-default-appointment-duration
3907 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3910 (setq time
(encode-time s mi h d m y
)))
3911 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3912 (concat keyword
(format-time-string fmt time
))))
3916 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3917 (with-current-buffer buffer
3918 (apply 'insert output
)))
3919 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3922 (defun org-export-as-xoxo (&optional buffer
)
3923 "Export the org buffer as XOXO.
3924 The XOXO buffer is named *xoxo-<source buffer name>*"
3925 (interactive (list (current-buffer)))
3926 ;; A quickie abstraction
3928 ;; Output everything as XOXO
3929 (with-current-buffer (get-buffer buffer
)
3930 (let* ((pos (point))
3931 (opt-plist (org-combine-plists (org-default-export-plist)
3932 (org-infile-export-plist)))
3933 (filename (concat (file-name-as-directory
3934 (org-export-directory :xoxo opt-plist
))
3935 (file-name-sans-extension
3936 (file-name-nondirectory buffer-file-name
))
3938 (out (find-file-noselect filename
))
3941 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3942 ;; Check the output buffer is empty.
3943 (with-current-buffer out
(erase-buffer))
3944 ;; Kick off the output
3945 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3946 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3947 (let* ((hd (match-string-no-properties 1))
3950 (match-string-no-properties 2)
3952 (goto-char (match-end 0))
3957 (if (looking-at "^[ \t]\\(.*\\)")
3958 (setq str
(concat str
(match-string-no-properties 1)))
3959 (throw 'loop str
)))))))))
3961 ;; Handle level rendering
3963 ((> level last-level
)
3964 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3966 ((< level last-level
)
3967 (dotimes (- (- last-level level
) 1)
3969 (org-export-as-xoxo-insert-into out
"</li>\n"))
3970 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3972 (org-export-as-xoxo-insert-into out
"</li>\n")
3973 (setq hanging-li nil
)))
3975 ((equal level last-level
)
3977 (org-export-as-xoxo-insert-into out
"</li>\n")))
3980 (setq last-level level
)
3982 ;; And output the new li
3983 (setq hanging-li
't
)
3984 (if (equal ?
+ (elt text
0))
3985 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
3986 (org-export-as-xoxo-insert-into out
"<li>" text
))))
3988 ;; Finally finish off the ol
3989 (dotimes (- last-level
1)
3991 (org-export-as-xoxo-insert-into out
"</li>\n"))
3992 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3995 ;; Finish the buffer off and clean it up.
3996 (switch-to-buffer-other-window out
)
3997 (indent-region (point-min) (point-max) nil
)
3999 (goto-char (point-min))
4004 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4006 ;;; org-exp.el ends here