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 ("no" "Forfatter" "Dato" "Innhold")
92 ("nb" "Forfatter" "Dato" "Innhold") ;; nb = Norsk (bokm.l)
93 ("nn" "Forfattar" "Dato" "Innhald") ;; nn = Norsk (nynorsk)
94 ("sv" "F\xf6rfattarens" "Datum" "Inneh\xe5ll"))
95 "Terms used in export text, translated to different languages.
96 Use the variable `org-export-default-language' to set the language,
97 or use the +OPTION lines for a per-file setting."
98 :group
'org-export-general
101 (string :tag
"HTML language tag")
102 (string :tag
"Author")
104 (string :tag
"Table of Contents"))))
106 (defcustom org-export-default-language
"en"
107 "The default language of HTML export, as a string.
108 This should have an association in `org-export-language-setup'."
109 :group
'org-export-general
112 (defcustom org-export-skip-text-before-1st-heading nil
113 "Non-nil means, skip all text before the first headline when exporting.
114 When nil, that text is exported as well."
115 :group
'org-export-general
118 (defcustom org-export-headline-levels
3
119 "The last level which is still exported as a headline.
120 Inferior levels will produce itemize lists when exported.
121 Note that a numeric prefix argument to an exporter function overrides
124 This option can also be set with the +OPTIONS line, e.g. \"H:2\"."
125 :group
'org-export-general
128 (defcustom org-export-with-section-numbers t
129 "Non-nil means, add section numbers to headlines when exporting.
131 This option can also be set with the +OPTIONS line, e.g. \"num:t\"."
132 :group
'org-export-general
135 (defcustom org-export-with-toc t
136 "Non-nil means, create a table of contents in exported files.
137 The TOC contains headlines with levels up to`org-export-headline-levels'.
138 When an integer, include levels up to N in the toc, this may then be
139 different from `org-export-headline-levels', but it will not be allowed
140 to be larger than the number of headline levels.
141 When nil, no table of contents is made.
143 Headlines which contain any TODO items will be marked with \"(*)\" in
144 ASCII export, and with red color in HTML output, if the option
145 `org-export-mark-todo-in-toc' is set.
147 In HTML output, the TOC will be clickable.
149 This option can also be set with the +OPTIONS line, e.g. \"toc:nil\"
151 :group
'org-export-general
153 (const :tag
"No Table of Contents" nil
)
154 (const :tag
"Full Table of Contents" t
)
155 (integer :tag
"TOC to level")))
157 (defcustom org-export-mark-todo-in-toc nil
158 "Non-nil means, mark TOC lines that contain any open TODO items."
159 :group
'org-export-general
162 (defcustom org-export-preserve-breaks nil
163 "Non-nil means, preserve all line breaks when exporting.
164 Normally, in HTML output paragraphs will be reformatted. In ASCII
165 export, line breaks will always be preserved, regardless of this variable.
167 This option can also be set with the +OPTIONS line, e.g. \"\\n:t\"."
168 :group
'org-export-general
171 (defcustom org-export-with-archived-trees
'headline
172 "Whether subtrees with the ARCHIVE tag should be exported.
173 This can have three different values
174 nil Do not export, pretend this tree is not present
175 t Do export the entire tree
176 headline Only export the headline, but skip the tree below it."
177 :group
'org-export-general
180 (const :tag
"not at all" nil
)
181 (const :tag
"headline only" 'headline
)
182 (const :tag
"entirely" t
)))
184 (defcustom org-export-author-info t
185 "Non-nil means, insert author name and email into the exported file.
187 This option can also be set with the +OPTIONS line,
188 e.g. \"author-info:nil\"."
189 :group
'org-export-general
192 (defcustom org-export-time-stamp-file t
193 "Non-nil means, insert a time stamp into the exported file.
194 The time stamp shows when the file was created.
196 This option can also be set with the +OPTIONS line,
197 e.g. \"timestamp:nil\"."
198 :group
'org-export-general
201 (defcustom org-export-with-timestamps t
202 "If nil, do not export time stamps and associated keywords."
203 :group
'org-export-general
206 (defcustom org-export-remove-timestamps-from-toc t
207 "If nil, remove timestamps from the table of contents entries."
208 :group
'org-export-general
211 (defcustom org-export-with-tags
'not-in-toc
212 "If nil, do not export tags, just remove them from headlines.
213 If this is the symbol `not-in-toc', tags will be removed from table of
214 contents entries, but still be shown in the headlines of the document.
216 This option can also be set with the +OPTIONS line, e.g. \"tags:nil\"."
217 :group
'org-export-general
219 (const :tag
"Off" nil
)
220 (const :tag
"Not in TOC" not-in-toc
)
221 (const :tag
"On" t
)))
223 (defcustom org-export-with-drawers nil
224 "Non-nil means, export with drawers like the property drawer.
225 When t, all drawers are exported. This may also be a list of
226 drawer names to export."
227 :group
'org-export-general
229 (const :tag
"All drawers" t
)
230 (const :tag
"None" nil
)
231 (repeat :tag
"Selected drawers"
232 (string :tag
"Drawer name"))))
234 (defvar org-export-preprocess-hook nil
235 "Hook for preprocessing an export buffer.
236 Pretty much the first thing when exporting is running this hook.")
238 (defgroup org-export-translation nil
239 "Options for translating special ascii sequences for the export backends."
240 :tag
"Org Export Translation"
243 (defcustom org-export-with-emphasize t
244 "Non-nil means, interpret *word*, /word/, and _word_ as emphasized text.
245 If the export target supports emphasizing text, the word will be
246 typeset in bold, italic, or underlined, respectively. Works only for
247 single words, but you can say: I *really* *mean* *this*.
248 Not all export backends support this.
250 This option can also be set with the +OPTIONS line, e.g. \"*:nil\"."
251 :group
'org-export-translation
254 (defcustom org-export-with-footnotes t
255 "If nil, export [1] as a footnote marker.
256 Lines starting with [1] will be formatted as footnotes.
258 This option can also be set with the +OPTIONS line, e.g. \"f:nil\"."
259 :group
'org-export-translation
262 (defcustom org-export-with-sub-superscripts t
263 "Non-nil means, interpret \"_\" and \"^\" for export.
264 When this option is turned on, you can use TeX-like syntax for sub- and
265 superscripts. Several characters after \"_\" or \"^\" will be
266 considered as a single item - so grouping with {} is normally not
267 needed. For example, the following things will be parsed as single
268 sub- or superscripts.
270 10^24 or 10^tau several digits will be considered 1 item.
271 10^-12 or 10^-tau a leading sign with digits or a word
272 x^2-y^3 will be read as x^2 - y^3, because items are
273 terminated by almost any nonword/nondigit char.
274 x_{i^2} or x^(2-i) braces or parenthesis do grouping.
276 Still, ambiguity is possible - so when in doubt use {} to enclose the
277 sub/superscript. If you set this variable to the symbol `{}',
278 the braces are *required* in order to trigger interpretations as
279 sub/superscript. This can be helpful in documents that need \"_\"
280 frequently in plain text.
282 Not all export backends support this, but HTML does.
284 This option can also be set with the +OPTIONS line, e.g. \"^:nil\"."
285 :group
'org-export-translation
287 (const :tag
"Always interpret" t
)
288 (const :tag
"Only with braces" {})
289 (const :tag
"Never interpret" nil
)))
291 (defcustom org-export-with-special-strings t
292 "Non-nil means, interpret \"\-\", \"--\" and \"---\" for export.
293 When this option is turned on, these strings will be exported as:
299 Not all export backends support this, but HTML does.
301 This option can also be set with the +OPTIONS line, e.g. \"-:nil\"."
302 :group
'org-export-translation
305 (defcustom org-export-with-TeX-macros t
306 "Non-nil means, interpret simple TeX-like macros when exporting.
307 For example, HTML export converts \\alpha to α and \\AA to Å.
308 No only real TeX macros will work here, but the standard HTML entities
309 for math can be used as macro names as well. For a list of supported
310 names in HTML export, see the constant `org-html-entities'.
311 Not all export backends support this.
313 This option can also be set with the +OPTIONS line, e.g. \"TeX:nil\"."
314 :group
'org-export-translation
315 :group
'org-export-latex
318 (defcustom org-export-with-LaTeX-fragments nil
319 "Non-nil means, convert LaTeX fragments to images when exporting to HTML.
320 When set, the exporter will find LaTeX environments if the \\begin line is
321 the first non-white thing on a line. It will also find the math delimiters
322 like $a=b$ and \\( a=b \\) for inline math, $$a=b$$ and \\[ a=b \\] for
325 This option can also be set with the +OPTIONS line, e.g. \"LaTeX:t\"."
326 :group
'org-export-translation
327 :group
'org-export-latex
330 (defcustom org-export-with-fixed-width t
331 "Non-nil means, lines starting with \":\" will be in fixed width font.
332 This can be used to have pre-formatted text, fragments of code etc. For
334 : ;; Some Lisp examples
337 will be looking just like this in also HTML. See also the QUOTE keyword.
338 Not all export backends support this.
340 This option can also be set with the +OPTIONS line, e.g. \"::nil\"."
341 :group
'org-export-translation
344 (defcustom org-match-sexp-depth
3
345 "Number of stacked braces for sub/superscript matching.
346 This has to be set before loading org.el to be effective."
347 :group
'org-export-translation
350 (defgroup org-export-tables nil
351 "Options for exporting tables in Org-mode."
352 :tag
"Org Export Tables"
355 (defcustom org-export-with-tables t
356 "If non-nil, lines starting with \"|\" define a table.
359 | Name | Address | Birthday |
360 |-------------+----------+-----------|
361 | Arthur Dent | England | 29.2.2100 |
363 Not all export backends support this.
365 This option can also be set with the +OPTIONS line, e.g. \"|:nil\"."
366 :group
'org-export-tables
369 (defcustom org-export-highlight-first-table-line t
370 "Non-nil means, highlight the first table line.
371 In HTML export, this means use <th> instead of <td>.
372 In tables created with table.el, this applies to the first table line.
373 In Org-mode tables, all lines before the first horizontal separator
374 line will be formatted with <th> tags."
375 :group
'org-export-tables
378 (defcustom org-export-table-remove-special-lines t
379 "Remove special lines and marking characters in calculating tables.
380 This removes the special marking character column from tables that are set
381 up for spreadsheet calculations. It also removes the entire lines
382 marked with `!', `_', or `^'. The lines with `$' are kept, because
383 the values of constants may be useful to have."
384 :group
'org-export-tables
387 (defcustom org-export-prefer-native-exporter-for-tables nil
388 "Non-nil means, always export tables created with table.el natively.
389 Natively means, use the HTML code generator in table.el.
390 When nil, Org-mode's own HTML generator is used when possible (i.e. if
391 the table does not use row- or column-spanning). This has the
392 advantage, that the automatic HTML conversions for math symbols and
393 sub/superscripts can be applied. Org-mode's HTML generator is also
395 :group
'org-export-tables
398 (defgroup org-export-ascii nil
399 "Options specific for ASCII export of Org-mode files."
400 :tag
"Org Export ASCII"
403 (defcustom org-export-ascii-underline
'(?\$ ?\
# ?^ ?\~ ?\
= ?\-
)
404 "Characters for underlining headings in ASCII export.
405 In the given sequence, these characters will be used for level 1, 2, ..."
406 :group
'org-export-ascii
407 :type
'(repeat character
))
409 (defcustom org-export-ascii-bullets
'(?
* ?
+ ?-
)
410 "Bullet characters for headlines converted to lists in ASCII export.
411 The first character is used for the first lest level generated in this
412 way, and so on. If there are more levels than characters given here,
413 the list will be repeated.
414 Note that plain lists will keep the same bullets as the have in the
416 :group
'org-export-ascii
417 :type
'(repeat character
))
419 (defgroup org-export-xml nil
420 "Options specific for XML export of Org-mode files."
421 :tag
"Org Export XML"
424 (defgroup org-export-html nil
425 "Options specific for HTML export of Org-mode files."
426 :tag
"Org Export HTML"
429 (defcustom org-export-html-coding-system nil
430 "Coding system for HTML export, defaults to buffer-file-coding-system."
431 :group
'org-export-html
432 :type
'coding-system
)
434 (defcustom org-export-html-extension
"html"
435 "The extension for exported HTML files."
436 :group
'org-export-html
439 (defcustom org-export-html-link-up
""
440 "Where should the \"UP\" link of exported HTML pages lead?"
441 :group
'org-export-html
442 :type
'(string :tag
"File or URL"))
444 (defcustom org-export-html-link-home
""
445 "Where should the \"HOME\" link of exported HTML pages lead?"
446 :group
'org-export-html
447 :type
'(string :tag
"File or URL"))
449 (defcustom org-export-html-style
450 "<style type=\"text/css\">
452 font-family: Times, serif;
455 .title { text-align: center; }
456 .todo { color: red; }
457 .done { color: green; }
458 .timestamp { color: grey }
459 .timestamp-kwd { color: CadetBlue }
460 .tag { background-color:lightblue; font-weight:normal }
463 border: 1pt solid #AEBDCC;
464 background-color: #F3F5F7;
466 font-family: courier, monospace;
468 table { border-collapse: collapse; }
471 <!--border: 1pt solid #ADB9CC;-->
473 dt { font-weight: bold; }
475 "The default style specification for exported HTML files.
476 Since there are different ways of setting style information, this variable
477 needs to contain the full HTML structure to provide a style, including the
478 surrounding HTML tags. The style specifications should include definitions
479 for new classes todo, done, title, and deadline. For example, valid values
482 <style type=\"text/css\">
483 p { font-weight: normal; color: gray; }
485 .title { text-align: center; }
486 .todo, .deadline { color: red; }
487 .done { color: green; }
490 or, if you want to keep the style in a file,
492 <link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\">
494 As the value of this option simply gets inserted into the HTML <head> header,
495 you can \"misuse\" it to add arbitrary text to the header."
496 :group
'org-export-html
500 (defcustom org-export-html-title-format
"<h1 class=\"title\">%s</h1>\n"
501 "Format for typesetting the document title in HTML export."
502 :group
'org-export-html
505 (defcustom org-export-html-toplevel-hlevel
2
506 "The <H> level for level 1 headings in HTML export."
507 :group
'org-export-html
510 (defcustom org-export-html-link-org-files-as-html t
511 "Non-nil means, make file links to `file.org' point to `file.html'.
512 When org-mode is exporting an org-mode file to HTML, links to
513 non-html files are directly put into a href tag in HTML.
514 However, links to other Org-mode files (recognized by the
515 extension `.org.) should become links to the corresponding html
516 file, assuming that the linked org-mode file will also be
518 When nil, the links still point to the plain `.org' file."
519 :group
'org-export-html
522 (defcustom org-export-html-inline-images
'maybe
523 "Non-nil means, inline images into exported HTML pages.
524 This is done using an <img> tag. When nil, an anchor with href is used to
525 link to the image. If this option is `maybe', then images in links with
526 an empty description will be inlined, while images with a description will
528 :group
'org-export-html
529 :type
'(choice (const :tag
"Never" nil
)
530 (const :tag
"Always" t
)
531 (const :tag
"When there is no description" maybe
)))
534 (defcustom org-export-html-expand t
535 "Non-nil means, for HTML export, treat @<...> as HTML tag.
536 When nil, these tags will be exported as plain text and therefore
537 not be interpreted by a browser.
539 This option can also be set with the +OPTIONS line, e.g. \"@:nil\"."
540 :group
'org-export-html
543 (defcustom org-export-html-table-tag
544 "<table border=\"2\" cellspacing=\"0\" cellpadding=\"6\" rules=\"groups\" frame=\"hsides\">"
545 "The HTML tag that is used to start a table.
546 This must be a <table> tag, but you may change the options like
547 borders and spacing."
548 :group
'org-export-html
551 (defcustom org-export-table-header-tags
'("<th>" .
"</th>")
552 "The opening tag for table header fields.
553 This is customizable so that alignment options can be specified."
554 :group
'org-export-tables
555 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
557 (defcustom org-export-table-data-tags
'("<td>" .
"</td>")
558 "The opening tag for table data fields.
559 This is customizable so that alignment options can be specified."
560 :group
'org-export-tables
561 :type
'(cons (string :tag
"Opening tag") (string :tag
"Closing tag")))
563 (defcustom org-export-html-with-timestamp nil
564 "If non-nil, write `org-export-html-html-helper-timestamp'
565 into the exported HTML text. Otherwise, the buffer will just be saved
567 :group
'org-export-html
570 (defcustom org-export-html-html-helper-timestamp
571 "<br/><br/><hr><p><!-- hhmts start --> <!-- hhmts end --></p>\n"
572 "The HTML tag used as timestamp delimiter for HTML-helper-mode."
573 :group
'org-export-html
576 (defgroup org-export-htmlize nil
577 "Options for processing examples with htmlize.el."
578 :tag
"Org Export Htmlize"
579 :group
'org-export-html
)
581 (defcustom org-export-htmlize-output-type
'inline-css
582 "Output type to be used by htmlize when formatting code snippets.
583 Normally this is `inline-css', but if you have defined to appropriate
584 classes in your css style file, setting this to `css' means that the
585 fontification will use the class names.
586 See also the function `org-export-htmlize-generate-css'."
587 :group
'org-export-htmlize
588 :type
'(choice (const css
) (const inline-css
)))
590 (defcustom org-export-htmlize-css-font-prefix
"org-"
591 "The prefix for CSS class names for htmlize font specifications."
592 :group
'org-export-htmlize
595 (defgroup org-export-icalendar nil
596 "Options specific for iCalendar export of Org-mode files."
597 :tag
"Org Export iCalendar"
600 (defcustom org-combined-agenda-icalendar-file
"~/org.ics"
601 "The file name for the iCalendar file covering all agenda files.
602 This file is created with the command \\[org-export-icalendar-all-agenda-files].
603 The file name should be absolute, the file will be overwritten without warning."
604 :group
'org-export-icalendar
607 (defcustom org-icalendar-include-todo nil
608 "Non-nil means, export to iCalendar files should also cover TODO items."
609 :group
'org-export-icalendar
611 (const :tag
"None" nil
)
612 (const :tag
"Unfinished" t
)
613 (const :tag
"All" all
)))
615 (defcustom org-icalendar-include-sexps t
616 "Non-nil means, export to iCalendar files should also cover sexp entries.
617 These are entries like in the diary, but directly in an Org-mode file."
618 :group
'org-export-icalendar
621 (defcustom org-icalendar-include-body
100
622 "Amount of text below headline to be included in iCalendar export.
623 This is a number of characters that should maximally be included.
624 Properties, scheduling and clocking lines will always be removed.
625 The text will be inserted into the DESCRIPTION field."
626 :group
'org-export-icalendar
628 (const :tag
"Nothing" nil
)
629 (const :tag
"Everything" t
)
630 (integer :tag
"Max characters")))
632 (defcustom org-icalendar-combined-name
"OrgMode"
633 "Calendar name for the combined iCalendar representing all agenda files."
634 :group
'org-export-icalendar
637 (defcustom org-icalendar-force-UID nil
638 "Non-nil means, each exported entry must have a UID.
639 If not present, that UID will be created."
640 :group
'org-export-icalendar
645 ;;; Variables, constants, and parameter plists
647 (defconst org-level-max
20)
649 (defvar org-export-html-preamble nil
650 "Preamble, to be inserted just after <body>. Set by publishing functions.")
651 (defvar org-export-html-postamble nil
652 "Preamble, to be inserted just before </body>. Set by publishing functions.")
653 (defvar org-export-html-auto-preamble t
654 "Should default preamble be inserted? Set by publishing functions.")
655 (defvar org-export-html-auto-postamble t
656 "Should default postamble be inserted? Set by publishing functions.")
657 (defvar org-current-export-file nil
) ; dynamically scoped parameter
658 (defvar org-current-export-dir nil
) ; dynamically scoped parameter
660 (defconst org-export-plist-vars
661 '((:link-up . org-export-html-link-up
)
662 (:link-home . org-export-html-link-home
)
663 (:language . org-export-default-language
)
664 (:customtime . org-display-custom-times
)
665 (:headline-levels . org-export-headline-levels
)
666 (:section-numbers . org-export-with-section-numbers
)
667 (:table-of-contents . org-export-with-toc
)
668 (:preserve-breaks . org-export-preserve-breaks
)
669 (:archived-trees . org-export-with-archived-trees
)
670 (:emphasize . org-export-with-emphasize
)
671 (:sub-superscript . org-export-with-sub-superscripts
)
672 (:special-strings . org-export-with-special-strings
)
673 (:footnotes . org-export-with-footnotes
)
674 (:drawers . org-export-with-drawers
)
675 (:tags . org-export-with-tags
)
676 (:TeX-macros . org-export-with-TeX-macros
)
677 (:LaTeX-fragments . org-export-with-LaTeX-fragments
)
678 (:skip-before-1st-heading . org-export-skip-text-before-1st-heading
)
679 (:fixed-width . org-export-with-fixed-width
)
680 (:timestamps . org-export-with-timestamps
)
681 (:author-info . org-export-author-info
)
682 (:time-stamp-file . org-export-time-stamp-file
)
683 (:tables . org-export-with-tables
)
684 (:table-auto-headline . org-export-highlight-first-table-line
)
685 (:style . org-export-html-style
)
686 (:agenda-style . org-agenda-export-html-style
)
687 (:convert-org-links . org-export-html-link-org-files-as-html
)
688 (:inline-images . org-export-html-inline-images
)
689 (:html-extension . org-export-html-extension
)
690 (:html-table-tag . org-export-html-table-tag
)
691 (:expand-quoted-html . org-export-html-expand
)
692 (:timestamp . org-export-html-with-timestamp
)
693 (:publishing-directory . org-export-publishing-directory
)
694 (:preamble . org-export-html-preamble
)
695 (:postamble . org-export-html-postamble
)
696 (:auto-preamble . org-export-html-auto-preamble
)
697 (:auto-postamble . org-export-html-auto-postamble
)
698 (:author . user-full-name
)
699 (:email . user-mail-address
)))
701 (defun org-default-export-plist ()
702 "Return the property list with default settings for the export variables."
703 (let ((l org-export-plist-vars
) rtn e
)
704 (while (setq e
(pop l
))
705 (setq rtn
(cons (car e
) (cons (symbol-value (cdr e
)) rtn
))))
708 (defvar org-export-inbuffer-options-extra nil
709 "List of additional in-buffer options that should be detected.
710 Just before export, the buffer is scanned for options like #+TITLE, #+EMAIL,
711 etc. Extensions can add to this list to get their options detected, and they
712 can then add a function to `org-export-options-filters' to process these
714 Each element in this list must be a list, with the in-buffer keyword as car,
715 and a property (a symbol) as the next element. All occurences of the
716 keyword will be found, the values concatenated with a space character
717 in between, and the result stored in the export options property list.")
719 (defvar org-export-options-filters nil
720 "Functions to be called to finalize the export/publishing options.
721 All these options are stored in a property list, and each of the functions
722 in this hook gets a chance to modify this property list. Each function
723 must accept the property list as an argument, and must return the (possibly
726 (defun org-infile-export-plist ()
727 "Return the property list with file-local settings for export."
731 (goto-char (point-min))
732 (let ((re (org-make-options-regexp
734 '("TITLE" "AUTHOR" "DATE" "EMAIL" "TEXT" "OPTIONS" "LANGUAGE"
735 "LINK_UP" "LINK_HOME" "SETUPFILE")
736 (mapcar 'car org-export-inbuffer-options-extra
))))
737 p key val text options js-up js-main js-css js-opt a pr
738 ext-setup-or-nil setup-contents
(start 0))
739 (while (or (and ext-setup-or-nil
740 (string-match re ext-setup-or-nil start
)
741 (setq start
(match-end 0)))
742 (and (setq ext-setup-or-nil nil start
0)
743 (re-search-forward re nil t
)))
744 (setq key
(upcase (org-match-string-no-properties 1 ext-setup-or-nil
))
745 val
(org-match-string-no-properties 2 ext-setup-or-nil
))
747 ((setq a
(assoc key org-export-inbuffer-options-extra
))
749 (setq p
(plist-put p pr
(concat (plist-get p pr
) " " val
))))
750 ((string-equal key
"TITLE") (setq p
(plist-put p
:title val
)))
751 ((string-equal key
"AUTHOR")(setq p
(plist-put p
:author val
)))
752 ((string-equal key
"EMAIL") (setq p
(plist-put p
:email val
)))
753 ((string-equal key
"DATE") (setq p
(plist-put p
:date val
)))
754 ((string-equal key
"LANGUAGE") (setq p
(plist-put p
:language val
)))
755 ((string-equal key
"TEXT")
756 (setq text
(if text
(concat text
"\n" val
) val
)))
757 ((string-equal key
"OPTIONS")
758 (setq options
(concat val
" " options
)))
759 ((string-equal key
"LINK_UP")
760 (setq p
(plist-put p
:link-up val
)))
761 ((string-equal key
"LINK_HOME")
762 (setq p
(plist-put p
:link-home val
)))
763 ((equal key
"SETUPFILE")
764 (setq setup-contents
(org-file-contents
766 (org-remove-double-quotes
769 (if (not ext-setup-or-nil
)
770 (setq ext-setup-or-nil setup-contents start
0)
771 (setq ext-setup-or-nil
772 (concat (substring ext-setup-or-nil
0 start
)
773 "\n" setup-contents
"\n"
774 (substring ext-setup-or-nil start
)))))))
775 (setq p
(plist-put p
:text text
))
777 (let ((op '(("H" .
:headline-levels
)
778 ("num" .
:section-numbers
)
779 ("toc" .
:table-of-contents
)
780 ("\\n" .
:preserve-breaks
)
781 ("@" .
:expand-quoted-html
)
784 ("^" .
:sub-superscript
)
785 ("-" .
:special-strings
)
790 ("TeX" .
:TeX-macros
)
791 ("LaTeX" .
:LaTeX-fragments
)
792 ("skip" .
:skip-before-1st-heading
)
793 ("author" .
:author-info
)
794 ("timestamp" .
:time-stamp-file
)))
796 (while (setq o
(pop op
))
797 (if (string-match (concat (regexp-quote (car o
))
798 ":\\([^ \t\n\r;,.]*\\)")
800 (setq p
(plist-put p
(cdr o
)
801 (car (read-from-string
802 (match-string 1 options
)))))))))
805 (defun org-export-directory (type plist
)
806 (let* ((val (plist-get plist
:publishing-directory
))
808 (or (cdr (assoc type val
)) ".")
812 (defun org-export-process-option-filters (plist)
813 (let ((functions org-export-options-filters
) f
)
814 (while (setq f
(pop functions
))
815 (setq plist
(funcall f plist
))))
819 (defun org-export (&optional arg
)
820 "Export dispatcher for Org-mode.
821 When `org-export-run-in-background' is non-nil, try to run the command
822 in the background. This will be done only for commands that write
823 to a file. For details see the docstring of `org-export-run-in-background'.
825 The prefix argument ARG will be passed to the exporter. However, if
826 ARG is a double universal prefix `C-u C-u', that means to inverse the
827 value of `org-export-run-in-background'."
829 (let* ((bg (org-xor (equal arg
'(16)) org-export-run-in-background
))
830 (help "[t] insert the export option template
831 \[v] limit export to visible part of outline tree
836 \[H] export as HTML to temporary buffer
837 \[R] export region as HTML
838 \[b] export as HTML and browse immediately
842 \[L] export as LaTeX to temporary buffer
844 \[i] export current file as iCalendar file
845 \[I] export all agenda files as iCalendar files
846 \[c] export agenda files into combined iCalendar file
848 \[F] publish current file
849 \[P] publish current project
850 \[X] publish... (project will be prompted for)
851 \[A] publish all projects")
853 '((?t org-insert-export-options-template nil
)
854 (?v org-export-visible nil
)
855 (?a org-export-as-ascii t
)
856 (?h org-export-as-html t
)
857 (?b org-export-as-html-and-open t
)
858 (?H org-export-as-html-to-buffer nil
)
859 (?R org-export-region-as-html nil
)
860 (?x org-export-as-xoxo t
)
861 (?l org-export-as-latex t
)
862 (?L org-export-as-latex-to-buffer nil
)
863 (?i org-export-icalendar-this-file t
)
864 (?I org-export-icalendar-all-agenda-files t
)
865 (?c org-export-icalendar-combine-agenda-files t
)
866 (?F org-publish-current-file t
)
867 (?P org-publish-current-project t
)
869 (?A org-publish-all t
)))
871 (save-window-excursion
872 (delete-other-windows)
873 (with-output-to-temp-buffer "*Org Export/Publishing Help*"
875 (message "Select command: ")
876 (setq r1
(read-char-exclusive)))
877 (setq r2
(if (< r1
27) (+ r1
96) r1
))
878 (unless (setq ass
(assq r2 cmds
))
879 (error "No command associated with key %c" r1
))
880 (if (and bg
(nth 2 ass
))
881 ;; execute in background
882 (let ((p (start-process
883 (concat "Exporting " (file-name-nondirectory (buffer-file-name)))
885 (expand-file-name invocation-name invocation-directory
)
888 "--eval" "(require 'org-exp)"
889 "--eval" "(setq org-wait .2)"
891 "-f" (symbol-name (nth 1 ass
)))))
892 (set-process-sentinel p
'org-export-process-sentinel
)
893 (message "Background process \"%s\": started" p
))
894 ;; background processing not requested, or not possible
895 (call-interactively (nth 1 ass
)))))
897 (defun org-export-process-sentinel (process status
)
898 (if (string-match "\n+\\'" status
)
899 (setq status
(substring status
0 -
1)))
900 (message "Background process \"%s\": %s" process status
))
902 (defconst org-html-entities
943 ("Aring") ("AA".
"Å")
1032 ("varepsilon".
"ε")
1045 ("sigmaf") ("varsigma".
"ς")
1053 ("thetasym") ("vartheta".
"ϑ")
1056 ("bull") ("bullet".
"•")
1057 ("hellip") ("dots".
"…")
1067 ("larr") ("leftarrow".
"←") ("gets".
"←")
1068 ("uarr") ("uparrow".
"↑")
1069 ("rarr") ("to".
"→") ("rightarrow".
"→")
1070 ("darr")("downarrow".
"↓")
1071 ("harr") ("leftrightarrow".
"↔")
1072 ("crarr") ("hookleftarrow".
"↵") ; has round hook, not quite CR
1073 ("lArr") ("Leftarrow".
"⇐")
1074 ("uArr") ("Uparrow".
"⇑")
1075 ("rArr") ("Rightarrow".
"⇒")
1076 ("dArr") ("Downarrow".
"⇓")
1077 ("hArr") ("Leftrightarrow".
"⇔")
1079 ("part") ("partial".
"∂")
1080 ("exist") ("exists".
"∃")
1081 ("empty") ("emptyset".
"∅")
1083 ("isin") ("in".
"∈")
1089 ("lowast") ("ast".
"∗")
1091 ("prop") ("proptp".
"∝")
1092 ("infin") ("infty".
"∞")
1093 ("ang") ("angle".
"∠")
1094 ("and") ("wedge".
"∧")
1095 ("or") ("vee".
"∨")
1101 ("cong") ("simeq".
"≅")
1102 ("asymp")("approx".
"≈")
1103 ("ne") ("neq".
"≠")
1107 ("sub") ("subset".
"⊂")
1108 ("sup") ("supset".
"⊃")
1115 ("sdot") ("cdot".
"⋅")
1122 ("loz") ("Diamond".
"◊")
1123 ("spades") ("spadesuit".
"♠")
1124 ("clubs") ("clubsuit".
"♣")
1125 ("hearts") ("diamondsuit".
"♥")
1126 ("diams") ("diamondsuit".
"♦")
1127 ("smile".
"☺") ("blacksmile".
"☻") ("sad".
"☹")
1194 "Entities for TeX->HTML translation.
1195 Entries can be like (\"ent\"), in which case \"\\ent\" will be translated to
1196 \"&ent;\". An entry can also be a dotted pair like (\"ent\".\"&other;\").
1197 In that case, \"\\ent\" will be translated to \"&other;\".
1198 The list contains HTML entities for Latin-1, Greek and other symbols.
1199 It is supplemented by a number of commonly used TeX macros with appropriate
1200 translations. There is currently no way for users to extend this.")
1202 ;;; General functions for all backends
1204 (defun org-export-preprocess-string (string &rest parameters
)
1205 "Cleanup STRING so that that the true exported has a more consistent source.
1206 This function takes STRING, which should be a buffer-string of an org-file
1207 to export. It then creates a temporary buffer where it does its job.
1208 The result is then again returned as a string, and the exporter works
1209 on this string to produce the exported version."
1211 (let* ((re-radio (and org-target-link-regexp
1212 (concat "\\([^<]\\)\\(" org-target-link-regexp
"\\)")))
1213 (re-plain-link (concat "\\([^[<]\\)" org-plain-link-re
))
1214 (re-angle-link (concat "\\([^[]\\)" org-angle-link-re
))
1215 (re-archive (concat ":" org-archive-tag
":"))
1216 (re-quote (concat "^\\*+[ \t]+" org-quote-string
"\\>"))
1217 (re-commented (concat "^\\*+[ \t]+" org-comment-string
"\\>"))
1218 (htmlp (plist-get parameters
:for-html
))
1219 (asciip (plist-get parameters
:for-ascii
))
1220 (latexp (plist-get parameters
:for-LaTeX
))
1221 (commentsp (plist-get parameters
:comments
))
1222 (archived-trees (plist-get parameters
:archived-trees
))
1223 (inhibit-read-only t
)
1224 (drawers org-drawers
)
1225 (exp-drawers (plist-get parameters
:drawers
))
1226 (outline-regexp "\\*+ ")
1227 target-alist tmp target level
1230 (with-current-buffer (get-buffer-create " org-mode-tmp")
1233 (setq case-fold-search t
)
1235 (run-hooks 'org-export-preprocess-hook
)
1237 ;; Remove license-to-kill stuff
1238 ;; The caller markes some stuff fo killing, stuff that has been
1239 ;; used to create the page title, for example.
1240 (while (setq p
(text-property-any (point-min) (point-max)
1241 :org-license-to-kill t
))
1242 (delete-region p
(next-single-property-change p
:org-license-to-kill
)))
1244 (let ((org-inhibit-startup t
)) (org-mode))
1245 (setq case-fold-search t
)
1246 (untabify (point-min) (point-max))
1248 ;; Handle incude files
1249 (org-export-handle-include-files)
1251 ;; Handle source code snippets
1252 (org-export-replace-src-segments)
1254 ;; Get rid of drawers
1255 (unless (eq t exp-drawers
)
1256 (goto-char (point-min))
1257 (let ((re (concat "^[ \t]*:\\("
1260 (org-delete-all exp-drawers
1261 (copy-sequence drawers
))
1263 "\\):[ \t]*\n\\([^@]*?\n\\)?[ \t]*:END:[ \t]*\n")))
1264 (while (re-search-forward re nil t
)
1265 (replace-match ""))))
1267 ;; Get the correct stuff before the first headline
1268 (when (plist-get parameters
:skip-before-1st-heading
)
1269 (goto-char (point-min))
1270 (when (re-search-forward "^\\*+[ \t]" nil t
)
1271 (delete-region (point-min) (match-beginning 0))
1272 (goto-char (point-min))
1274 (when (plist-get parameters
:add-text
)
1275 (goto-char (point-min))
1276 (insert (plist-get parameters
:add-text
) "\n"))
1278 ;; Get rid of archived trees
1279 (when (not (eq archived-trees t
))
1280 (goto-char (point-min))
1281 (while (re-search-forward re-archive nil t
)
1282 (if (not (org-on-heading-p t
))
1283 (org-end-of-subtree t
)
1284 (beginning-of-line 1)
1285 (setq a
(if archived-trees
1286 (1+ (point-at-eol)) (point))
1287 b
(org-end-of-subtree t
))
1288 (if (> b a
) (delete-region a b
)))))
1290 ;; Find all headings and compute the targets for them
1291 (goto-char (point-min))
1292 (org-init-section-numbers)
1293 (let ((re (concat "^" org-outline-regexp
)))
1294 (while (re-search-forward re nil t
)
1295 (setq level
(org-reduced-level
1296 (save-excursion (goto-char (point-at-bol))
1297 (org-outline-level))))
1298 (setq target
(org-solidify-link-text
1299 (format "sec-%s" (org-section-number level
))))
1300 (push (cons target target
) target-alist
)
1301 (add-text-properties
1302 (point-at-bol) (point-at-eol)
1303 (list 'target target
))))
1305 ;; Find targets in comments and move them out of comments,
1306 ;; but mark them as targets that should be invisible
1307 (goto-char (point-min))
1308 (while (re-search-forward "^#.*?\\(<<<?\\([^>\r\n]+\\)>>>?\\).*" nil t
)
1309 ;; Check if the line before or after is a headline with a target
1310 (if (setq target
(or (get-text-property (point-at-bol 0) 'target
)
1311 (get-text-property (point-at-bol 2) 'target
)))
1313 ;; use the existing target in a neighboring line
1314 (setq tmp
(match-string 2))
1316 (and (looking-at "\n") (delete-char 1))
1317 (push (cons (org-solidify-link-text tmp
) target
)
1319 ;; Make an invisible target
1320 (replace-match "\\1(INVISIBLE)")))
1322 ;; Protect backend specific stuff, throw away the others.
1324 `((,htmlp
"HTML" "BEGIN_HTML" "END_HTML")
1325 (,asciip
"ASCII" "BEGIN_ASCII" "END_ASCII")
1326 (,latexp
"LaTeX" "BEGIN_LaTeX" "END_LaTeX")))
1328 (goto-char (point-min))
1329 (while (re-search-forward "^#\\+BEGIN_EXAMPLE[ \t]*\n" nil t
)
1330 (goto-char (match-end 0))
1331 (while (not (looking-at "#\\+END_EXAMPLE"))
1333 (beginning-of-line 2)))
1334 (goto-char (point-min))
1335 (while (re-search-forward "^[ \t]*:.*\\(\n[ \t]*:.*\\)*" nil t
)
1336 (add-text-properties (match-beginning 0) (match-end 0)
1337 '(org-protected t
)))
1339 (setq fmt
(pop formatters
))
1341 (goto-char (point-min))
1342 (while (re-search-forward (concat "^#\\+" (cadr fmt
)
1343 ":[ \t]*\\(.*\\)") nil t
)
1344 (replace-match "\\1" t
)
1345 (add-text-properties
1346 (point-at-bol) (min (1+ (point-at-eol)) (point-max))
1347 '(org-protected t
))))
1348 (goto-char (point-min))
1349 (while (re-search-forward
1351 (caddr fmt
) "\\>.*\\(\\(\n.*\\)*?\n\\)#\\+"
1352 (cadddr fmt
) "\\>.*\n?") nil t
)
1354 (add-text-properties (match-beginning 1) (1+ (match-end 1))
1356 (delete-region (match-beginning 0) (match-end 0))))))
1358 ;; Protect quoted subtrees
1359 (goto-char (point-min))
1360 (while (re-search-forward re-quote nil t
)
1361 (goto-char (match-beginning 0))
1363 (add-text-properties (point) (org-end-of-subtree t
)
1364 '(org-protected t
)))
1366 ;; Protect verbatim elements
1367 (goto-char (point-min))
1368 (while (re-search-forward org-verbatim-re nil t
)
1369 (add-text-properties (match-beginning 4) (match-end 4)
1371 (goto-char (1+ (match-end 4))))
1374 (goto-char (point-min))
1375 (while (re-search-forward "^#\\+\\(begin\\|end\\)_\\(block\\)?quote\\>.*" nil t
)
1376 (replace-match (if (equal (downcase (match-string 1)) "end")
1377 "ORG-BLOCKQUOTE-END" "ORG-BLOCKQUOTE-START")
1380 (goto-char (point-min))
1381 (while (re-search-forward "^#\\+\\(begin\\|end\\)_verse\\>.*" nil t
)
1382 (replace-match (if (equal (downcase (match-string 1)) "end")
1383 "ORG-VERSE-END" "ORG-VERSE-START")
1386 ;; Remove comment environment
1387 (goto-char (point-min))
1388 (while (re-search-forward
1389 "^#\\+BEGIN_COMMENT[ \t]*\n[^\000]*?^#\\+END_COMMENT\\>.*" nil t
)
1390 (replace-match "" t t
))
1392 ;; Remove subtrees that are commented
1393 (goto-char (point-min))
1394 (while (re-search-forward re-commented nil t
)
1395 (goto-char (match-beginning 0))
1396 (delete-region (point) (org-end-of-subtree t
)))
1398 ;; Remove special table lines
1399 (when org-export-table-remove-special-lines
1400 (goto-char (point-min))
1401 (while (re-search-forward "^[ \t]*|" nil t
)
1402 (beginning-of-line 1)
1403 (if (or (looking-at "[ \t]*| *[!_^] *|")
1404 (and (looking-at ".*?| *<[0-9]+> *|")
1405 (not (looking-at ".*?| *[^ <|]"))))
1406 (delete-region (max (point-min) (1- (point-at-bol)))
1410 ;; Specific LaTeX stuff
1412 (require 'org-export-latex nil
)
1413 (org-export-latex-preprocess))
1416 (org-export-ascii-clean-string))
1418 ;; Specific HTML stuff
1420 ;; Convert LaTeX fragments to images
1421 (when (plist-get parameters
:LaTeX-fragments
)
1423 (concat "ltxpng/" (file-name-sans-extension
1424 (file-name-nondirectory
1425 org-current-export-file
)))
1426 org-current-export-dir nil
"Creating LaTeX image %s"))
1427 (message "Exporting..."))
1429 ;; Remove or replace comments
1430 (goto-char (point-min))
1431 (while (re-search-forward "^#\\(.*\n?\\)" nil t
)
1433 (progn (add-text-properties
1434 (match-beginning 0) (match-end 0) '(org-protected t
))
1435 (replace-match (format commentsp
(match-string 1)) t t
))
1436 (replace-match "")))
1438 ;; Find matches for radio targets and turn them into internal links
1439 (goto-char (point-min))
1441 (while (re-search-forward re-radio nil t
)
1443 (replace-match "\\1[[\\2]]"))))
1445 ;; Find all links that contain a newline and put them into a single line
1446 (goto-char (point-min))
1447 (while (re-search-forward "\\(\\(\\[\\|\\]\\)\\[[^]]*?\\)[ \t]*\n[ \t]*\\([^]]*\\]\\(\\[\\|\\]\\)\\)" nil t
)
1449 (replace-match "\\1 \\3")
1450 (goto-char (match-beginning 0))))
1452 ;; Find all internal links. If they have a fuzzy match (i.e. not
1453 ;; a *dedicated* target match, let the link point to the
1454 ;; correspinding section.
1456 (goto-char (point-min))
1457 (while (re-search-forward org-bracket-link-regexp nil t
)
1459 (let* ((md (match-data))
1460 (desc (match-end 2))
1461 (link (org-link-unescape (match-string 1)))
1462 (slink (org-solidify-link-text link
))
1465 (or (cdr (assoc slink target-alist
))
1467 (unless (string-match org-link-types-re link
)
1468 (setq found
(condition-case nil
(org-link-search link
)
1471 (or (org-on-heading-p)
1472 (not (eq found
'dedicated
))))
1473 (or (get-text-property (point) 'target
)
1476 (1- (previous-single-property-change
1481 (goto-char (match-beginning 1))
1482 (setq props
(text-properties-at (point)))
1483 (delete-region (match-beginning 1) (match-end 1))
1486 (unless desc
(insert "][" link
))
1487 (add-text-properties pos
(point) props
)))))
1489 ;; Normalize links: Convert angle and plain links into bracket links
1490 ;; Expand link abbreviations
1491 (goto-char (point-min))
1492 (while (re-search-forward re-plain-link nil t
)
1493 (goto-char (1- (match-end 0)))
1495 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1496 ":" (match-string 3) "]]")))
1497 ;; added 'org-link face to links
1498 (put-text-property 0 (length s
) 'face
'org-link s
)
1499 (replace-match s t t
))))
1500 (goto-char (point-min))
1501 (while (re-search-forward re-angle-link nil t
)
1502 (goto-char (1- (match-end 0)))
1504 (let* ((s (concat (match-string 1) "[[" (match-string 2)
1505 ":" (match-string 3) "]]")))
1506 (put-text-property 0 (length s
) 'face
'org-link s
)
1507 (replace-match s t t
))))
1508 (goto-char (point-min))
1509 (while (re-search-forward org-bracket-link-regexp nil t
)
1511 (let* ((s (concat "[[" (setq xx
(save-match-data
1512 (org-link-expand-abbrev (match-string 1))))
1516 (concat "[" xx
"]"))
1518 (put-text-property 0 (length s
) 'face
'org-link s
)
1519 (replace-match s t t
))))
1521 ;; Find multiline emphasis and put them into single line
1522 (when (plist-get parameters
:emph-multiline
)
1523 (goto-char (point-min))
1524 (while (re-search-forward org-emph-re nil t
)
1525 (if (not (= (char-after (match-beginning 3))
1526 (char-after (match-beginning 4))))
1528 (subst-char-in-region (match-beginning 0) (match-end 0)
1530 (goto-char (1- (match-end 0))))
1531 (goto-char (1+ (match-beginning 0))))))
1533 (setq rtn
(buffer-string)))
1534 (kill-buffer " org-mode-tmp")
1537 (defun org-export-grab-title-from-buffer ()
1538 "Get a title for the current document, from looking at the buffer."
1539 (let ((inhibit-read-only t
))
1541 (goto-char (point-min))
1542 (let ((end (save-excursion (outline-next-heading) (point))))
1543 (when (re-search-forward "^[ \t]*[^|# \t\r\n].*\n" end t
)
1544 ;; Mark the line so that it will not be exported as normal text.
1546 (add-text-properties (match-beginning 0) (match-end 0)
1547 (list :org-license-to-kill t
)))
1548 ;; Return the title string
1549 (org-trim (match-string 0)))))))
1551 (defun org-export-get-title-from-subtree ()
1552 "Return subtree title and exclude it from export."
1553 (let (title (m (mark)))
1555 (goto-char (region-beginning))
1556 (when (and (org-at-heading-p)
1557 (>= (org-end-of-subtree t t
) (region-end)))
1558 ;; This is a subtree, we take the title from the first heading
1559 (goto-char (region-beginning))
1560 (looking-at org-todo-line-regexp
)
1561 (setq title
(match-string 3))
1563 (add-text-properties (point) (1+ (point-at-eol))
1564 (list :org-license-to-kill t
)))))
1567 (defun org-solidify-link-text (s &optional alist
)
1568 "Take link text and make a safe target out of it."
1573 (org-split-string s
"[ \t\r\n]+") "=="))
1574 (a (assoc rtn alist
)))
1577 (defun org-get-min-level (lines)
1578 "Get the minimum level in LINES."
1579 (let ((re "^\\(\\*+\\) ") l min
)
1581 (while (setq l
(pop lines
))
1582 (if (string-match re l
)
1583 (throw 'exit
(org-tr-level (length (match-string 1 l
))))))
1586 ;; Variable holding the vector with section numbers
1587 (defvar org-section-numbers
(make-vector org-level-max
0))
1589 (defun org-init-section-numbers ()
1590 "Initialize the vector for the section numbers."
1592 (numbers (nreverse (org-split-string "" "\\.")))
1593 (depth (1- (length org-section-numbers
)))
1594 (i depth
) number-string
)
1597 (aset org-section-numbers i
0)
1598 (setq number-string
(or (car numbers
) "0"))
1599 (if (string-match "\\`[A-Z]\\'" number-string
)
1600 (aset org-section-numbers i
1601 (- (string-to-char number-string
) ?A -
1))
1602 (aset org-section-numbers i
(string-to-number number-string
)))
1606 (defun org-section-number (&optional level
)
1607 "Return a string with the current section number.
1608 When LEVEL is non-nil, increase section numbers on that level."
1609 (let* ((depth (1- (length org-section-numbers
))) idx n
(string ""))
1612 (aset org-section-numbers
1613 level
(1+ (aref org-section-numbers level
))))
1614 (setq idx
(1+ level
))
1615 (while (<= idx depth
)
1617 (aset org-section-numbers idx
0))
1618 (setq idx
(1+ idx
))))
1620 (while (<= idx depth
)
1621 (setq n
(aref org-section-numbers idx
))
1622 (setq string
(concat string
(if (not (string= string
"")) "." "")
1624 (setq idx
(1+ idx
)))
1626 (if (string-match "\\`\\([@0]\\.\\)+" string
)
1627 (setq string
(replace-match "" t nil string
)))
1628 (if (string-match "\\(\\.0\\)+\\'" string
)
1629 (setq string
(replace-match "" t nil string
))))
1634 (defun org-export-handle-include-files ()
1635 "Include the contents of include files, with proper formatting."
1636 (let ((case-fold-search t
)
1637 params file markup lang start end
)
1638 (goto-char (point-min))
1639 (while (re-search-forward "^#\\+INCLUDE:?[ \t]+\\(.*\\)" nil t
)
1640 (setq params
(read (concat "(" (match-string 1) ")"))
1641 file
(org-symname-or-string (pop params
))
1642 markup
(org-symname-or-string (pop params
))
1643 lang
(org-symname-or-string (pop params
)))
1644 (delete-region (match-beginning 0) (match-end 0))
1646 (not (file-exists-p file
))
1647 (not (file-readable-p file
)))
1648 (insert (format "CANNOT INCLUDE FILE %s" file
))
1650 (if (equal (downcase markup
) "src")
1651 (setq start
(format "#+begin_src %s\n" (or lang
"fundamental"))
1653 (setq start
(format "#+begin_%s\n" markup
)
1654 end
(format "#+end_%s" markup
))))
1655 (insert (or start
""))
1656 (forward-char (nth 1 (insert-file-contents (expand-file-name file
))))
1657 (or (bolp) (newline))
1658 (insert (or end
""))))))
1660 (defun org-symname-or-string (s)
1662 (if s
(symbol-name s
) s
)
1665 ;;; Fontification of code
1666 ;; Currently only for th HTML backend, but who knows....
1667 (defun org-export-replace-src-segments ()
1668 "Replace source code segments with special code for export."
1669 (let ((case-fold-search t
)
1671 (goto-char (point-min))
1672 (while (re-search-forward
1673 "^#\\+BEGIN_SRC:?[ \t]+\\([^ \t\n]+\\)[ \t]*\n\\([^\000]+?\n\\)#\\+END_SRC.*"
1675 (setq lang
(match-string 1) code
(match-string 2)
1676 trans
(org-export-format-source-code lang code
))
1677 (replace-match trans t t
))))
1679 (defvar htmlp
) ;; dynamically scoped from org-exp.el
1681 (defun org-export-format-source-code (lang code
)
1682 "Format CODE from language LANG and return it formatted for export.
1683 Currently, this only does something for HTML export, for all other
1684 backends, it converts the segment into an EXAMPLE segment."
1688 ;; We are exporting to HTML
1689 (condition-case nil
(require 'htmlize
) (nil t
))
1690 (if (not (fboundp 'htmlize-region-for-paste
))
1692 ;; we do not have htmlize.el, or an old version of it
1694 "htmlize.el 1.34 or later is needed for source code formatting")
1695 (concat "#+BEGIN_EXAMPLE\n" code
1696 (if (string-match "\n\\'" code
) "" "\n")
1698 ;; ok, we are good to go
1699 (let* ((mode (and lang
(intern (concat lang
"-mode"))))
1700 (org-inhibit-startup t
)
1701 (org-startup-folded nil
)
1705 ;; Free up the protected stuff
1706 (goto-char (point-min))
1707 (while (re-search-forward "^," nil t
)
1709 (if (functionp mode
)
1712 (font-lock-fontify-buffer)
1713 (org-export-htmlize-region-for-paste
1714 (point-min) (point-max)))))
1715 (if (string-match "<pre\\([^>]*\\)>\n?" htmltext
)
1716 (setq htmltext
(replace-match "<pre class=\"src\">"
1718 (concat "#+BEGIN_HTML\n" htmltext
"\n#+END_HTML\n"))))
1720 ;; This is not HTML, so just make it an example.
1721 (concat "#+BEGIN_EXAMPLE\n" code
1722 (if (string-match "\n\\'" code
) "" "\n")
1723 "#+END_EXAMPLE\n")))))
1727 (defvar org-last-level nil
) ; dynamically scoped variable
1728 (defvar org-min-level nil
) ; dynamically scoped variable
1729 (defvar org-levels-open nil
) ; dynamically scoped parameter
1730 (defvar org-ascii-current-indentation nil
) ; For communication
1733 (defun org-export-as-ascii (arg)
1734 "Export the outline as a pretty ASCII file.
1735 If there is an active region, export only the region.
1736 The prefix ARG specifies how many levels of the outline should become
1737 underlined headlines. The default is 3."
1739 (setq-default org-todo-line-regexp org-todo-line-regexp
)
1740 (let* ((opt-plist (org-combine-plists (org-default-export-plist)
1741 (org-infile-export-plist)))
1742 (region-p (org-region-active-p))
1746 (goto-char (region-beginning))
1747 (and (org-at-heading-p)
1748 (>= (org-end-of-subtree t t
) (region-end))))))
1749 (custom-times org-display-custom-times
)
1750 (org-ascii-current-indentation '(0 .
0))
1754 (case-fold-search nil
)
1755 (filename (concat (file-name-as-directory
1756 (org-export-directory :ascii opt-plist
))
1757 (file-name-sans-extension
1759 (org-entry-get (region-beginning)
1760 "EXPORT_FILE_NAME" t
))
1761 (file-name-nondirectory buffer-file-name
)))
1763 (filename (if (equal (file-truename filename
)
1764 (file-truename buffer-file-name
))
1765 (concat filename
".txt")
1767 (buffer (find-file-noselect filename
))
1768 (org-levels-open (make-vector org-level-max nil
))
1769 (odd org-odd-levels-only
)
1770 (date (plist-get opt-plist
:date
))
1771 (author (plist-get opt-plist
:author
))
1772 (title (or (and subtree-p
(org-export-get-title-from-subtree))
1773 (plist-get opt-plist
:title
)
1775 (plist-get opt-plist
:skip-before-1st-heading
))
1776 (org-export-grab-title-from-buffer))
1777 (file-name-sans-extension
1778 (file-name-nondirectory buffer-file-name
))))
1779 (email (plist-get opt-plist
:email
))
1780 (language (plist-get opt-plist
:language
))
1781 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
1782 ; (quote-re (concat "^\\(\\*+\\)\\([ \t]*" org-quote-string "\\>\\)"))
1787 (if (org-region-active-p) (region-beginning) (point-min))
1788 (if (org-region-active-p) (region-end) (point-max))))
1789 (lines (org-split-string
1790 (org-export-preprocess-string
1793 :skip-before-1st-heading
1794 (plist-get opt-plist
:skip-before-1st-heading
)
1795 :drawers
(plist-get opt-plist
:drawers
)
1796 :verbatim-multiline t
1798 (plist-get opt-plist
:archived-trees
)
1799 :add-text
(plist-get opt-plist
:text
))
1801 thetoc have-headings first-heading-pos
1802 table-open table-buffer
)
1804 (let ((inhibit-read-only t
))
1806 (remove-text-properties (point-min) (point-max)
1807 '(:org-license-to-kill t
))))
1809 (setq org-min-level
(org-get-min-level lines
))
1810 (setq org-last-level org-min-level
)
1811 (org-init-section-numbers)
1813 (find-file-noselect filename
)
1815 (setq lang-words
(or (assoc language org-export-language-setup
)
1816 (assoc "en" org-export-language-setup
)))
1817 (switch-to-buffer-other-window buffer
)
1820 ;; create local variables for all options, to make sure all called
1821 ;; functions get the correct information
1823 (set (make-local-variable (cdr x
))
1824 (plist-get opt-plist
(car x
))))
1825 org-export-plist-vars
)
1826 (org-set-local 'org-odd-levels-only odd
)
1827 (setq umax
(if arg
(prefix-numeric-value arg
)
1828 org-export-headline-levels
))
1829 (setq umax-toc
(if (integerp org-export-with-toc
)
1830 (min org-export-with-toc umax
)
1834 (if title
(org-insert-centered title ?
=))
1836 (if (and (or author email
)
1837 org-export-author-info
)
1838 (insert (concat (nth 1 lang-words
) ": " (or author
"")
1839 (if email
(concat " <" email
">") "")
1843 ((and date
(string-match "%" date
))
1844 (setq date
(format-time-string date
)))
1846 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
1848 (if (and date org-export-time-stamp-file
)
1849 (insert (concat (nth 2 lang-words
) ": " date
"\n")))
1853 (if org-export-with-toc
1855 (push (concat (nth 3 lang-words
) "\n") thetoc
)
1856 (push (concat (make-string (length (nth 3 lang-words
)) ?
=) "\n") thetoc
)
1857 (mapc '(lambda (line)
1858 (if (string-match org-todo-line-regexp
1860 ;; This is a headline
1862 (setq have-headings t
)
1863 (setq level
(- (match-end 1) (match-beginning 1))
1864 level
(org-tr-level level
)
1865 txt
(match-string 3 line
)
1867 (or (and org-export-mark-todo-in-toc
1869 (not (member (match-string 2 line
)
1870 org-done-keywords
)))
1872 (and org-export-mark-todo-in-toc
1874 (org-search-todo-below
1875 line lines level
))))
1876 (setq txt
(org-html-expand-for-ascii txt
))
1878 (while (string-match org-bracket-link-regexp txt
)
1881 (match-string (if (match-end 2) 3 1) txt
)
1884 (if (and (memq org-export-with-tags
'(not-in-toc nil
))
1886 (org-re "[ \t]+:[[:alnum:]_@:]+:[ \t]*$")
1888 (setq txt
(replace-match "" t t txt
)))
1889 (if (string-match quote-re0 txt
)
1890 (setq txt
(replace-match "" t t txt
)))
1892 (if org-export-with-section-numbers
1893 (setq txt
(concat (org-section-number level
)
1895 (if (<= level umax-toc
)
1900 (* (max 0 (- level org-min-level
)) 4) ?\
)
1901 (format (if todo
"%s (*)\n" "%s\n") txt
))
1903 (setq org-last-level level
))
1906 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
1908 (org-init-section-numbers)
1909 (while (setq line
(pop lines
))
1910 ;; Remove the quoted HTML tags.
1911 (setq line
(org-html-expand-for-ascii line
))
1913 (while (string-match "<<<?[^<>]*>>>?[ \t]*\n?" line
)
1914 (setq line
(replace-match "" t t line
)))
1915 ;; Replace internal links
1916 (while (string-match org-bracket-link-regexp line
)
1917 (setq line
(replace-match
1918 (if (match-end 3) "[\\3]" "[\\1]")
1921 (setq line
(org-translate-time line
)))
1923 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
1925 (setq first-heading-pos
(or first-heading-pos
(point)))
1926 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
1927 txt
(match-string 2 line
))
1928 (org-ascii-level-start level txt umax lines
))
1930 ((and org-export-with-tables
1931 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
1932 (if (not table-open
)
1934 (setq table-open t table-buffer nil
))
1936 (setq table-buffer
(cons line table-buffer
))
1937 (when (or (not lines
)
1938 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
1940 (setq table-open nil
1941 table-buffer
(nreverse table-buffer
))
1944 (org-fix-indentation x org-ascii-current-indentation
))
1945 (org-format-table-ascii table-buffer
)
1948 (setq line
(org-fix-indentation line org-ascii-current-indentation
))
1949 (if (and org-export-with-fixed-width
1950 (string-match "^\\([ \t]*\\)\\(:\\)" line
))
1951 (setq line
(replace-match "\\1" nil nil line
)))
1952 (insert line
"\n"))))
1956 ;; insert the table of contents
1958 (goto-char (point-min))
1959 (if (re-search-forward "^[ \t]*\\[TABLE-OF-CONTENTS\\][ \t]*$" nil t
)
1961 (goto-char (match-beginning 0))
1963 (goto-char first-heading-pos
))
1964 (mapc 'insert thetoc
)
1965 (or (looking-at "[ \t]*\n[ \t]*\n")
1968 ;; Convert whitespace place holders
1969 (goto-char (point-min))
1971 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
1972 (setq end
(next-single-property-change beg
'org-whitespace
))
1974 (delete-region beg end
)
1975 (insert (make-string (- end beg
) ?\
))))
1978 ;; remove display and invisible chars
1980 (goto-char (point-min))
1981 (while (setq beg
(next-single-property-change (point) 'display
))
1982 (setq end
(next-single-property-change beg
'display
))
1983 (delete-region beg end
)
1986 (goto-char (point-min))
1987 (while (setq beg
(next-single-property-change (point) 'org-cwidth
))
1988 (setq end
(next-single-property-change beg
'org-cwidth
))
1989 (delete-region beg end
)
1991 (goto-char (point-min))))
1993 (defun org-export-ascii-clean-string ()
1994 "Do extra work for ASCII export"
1995 (goto-char (point-min))
1996 (while (re-search-forward org-verbatim-re nil t
)
1997 (goto-char (match-end 2))
1998 (backward-delete-char 1) (insert "'")
1999 (goto-char (match-beginning 2))
2000 (delete-char 1) (insert "`")
2001 (goto-char (match-end 2))))
2003 (defun org-search-todo-below (line lines level
)
2004 "Search the subtree below LINE for any TODO entries."
2005 (let ((rest (cdr (memq line lines
)))
2006 (re org-todo-line-regexp
)
2009 (while (setq line
(pop rest
))
2010 (if (string-match re line
)
2012 (setq lv
(- (match-end 1) (match-beginning 1))
2013 todo
(and (match-beginning 2)
2014 (not (member (match-string 2 line
)
2015 org-done-keywords
))))
2017 (if (<= lv level
) (throw 'exit nil
))
2018 (if todo
(throw 'exit t
))))))))
2020 (defun org-html-expand-for-ascii (line)
2021 "Handle quoted HTML for ASCII export."
2022 (if org-export-html-expand
2023 (while (string-match "@<[^<>\n]*>" line
)
2024 ;; We just remove the tags for now.
2025 (setq line
(replace-match "" nil nil line
))))
2028 (defun org-insert-centered (s &optional underline
)
2029 "Insert the string S centered and underline it with character UNDERLINE."
2030 (let ((ind (max (/ (- 80 (string-width s
)) 2) 0)))
2031 (insert (make-string ind ?\
) s
"\n")
2033 (insert (make-string ind ?\
)
2034 (make-string (string-width s
) underline
)
2037 (defun org-ascii-level-start (level title umax
&optional lines
)
2038 "Insert a new level in ASCII export."
2039 (let (char (n (- level umax
1)) (ind 0))
2042 (insert (make-string (* 2 n
) ?\
)
2043 (char-to-string (nth (% n
(length org-export-ascii-bullets
))
2044 org-export-ascii-bullets
))
2046 ;; find the indentation of the next non-empty line
2049 (if (string-match "^\\* " (car lines
)) (throw 'stop nil
))
2050 (if (string-match "^\\([ \t]*\\)\\S-" (car lines
))
2051 (throw 'stop
(setq ind
(org-get-indentation (car lines
)))))
2053 (setq org-ascii-current-indentation
(cons (* 2 (1+ n
)) ind
)))
2054 (if (or (not (equal (char-before) ?
\n))
2055 (not (equal (char-before (1- (point))) ?
\n)))
2057 (setq char
(nth (- umax level
) (reverse org-export-ascii-underline
)))
2058 (unless org-export-with-tags
2059 (if (string-match (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
2060 (setq title
(replace-match "" t t title
))))
2061 (if org-export-with-section-numbers
2062 (setq title
(concat (org-section-number level
) " " title
)))
2063 (insert title
"\n" (make-string (string-width title
) char
) "\n")
2064 (setq org-ascii-current-indentation
'(0 .
0)))))
2067 (defun org-export-visible (type arg
)
2068 "Create a copy of the visible part of the current buffer, and export it.
2069 The copy is created in a temporary buffer and removed after use.
2070 TYPE is the final key (as a string) that also select the export command in
2071 the `C-c C-e' export dispatcher.
2072 As a special case, if the you type SPC at the prompt, the temporary
2073 org-mode file will not be removed but presented to you so that you can
2074 continue to use it. The prefix arg ARG is passed through to the exporting
2078 (message "Export visible: [a]SCII [h]tml [b]rowse HTML [H/R]uffer with HTML [x]OXO [ ]keep buffer")
2079 (read-char-exclusive))
2080 current-prefix-arg
))
2081 (if (not (member type
'(?a ?\C-a ?b ?\C-b ?h ?x ?\
)))
2082 (error "Invalid export key"))
2083 (let* ((binding (cdr (assoc type
2084 '((?a . org-export-as-ascii
)
2085 (?\C-a . org-export-as-ascii
)
2086 (?b . org-export-as-html-and-open
)
2087 (?\C-b . org-export-as-html-and-open
)
2088 (?h . org-export-as-html
)
2089 (?H . org-export-as-html-to-buffer
)
2090 (?R . org-export-region-as-html
)
2091 (?x . org-export-as-xoxo
)))))
2092 (keepp (equal type ?\
))
2093 (file buffer-file-name
)
2094 (buffer (get-buffer-create "*Org Export Visible*"))
2096 ;; Need to hack the drawers here.
2098 (goto-char (point-min))
2099 (while (re-search-forward org-drawer-regexp nil t
)
2100 (goto-char (match-beginning 1))
2101 (or (org-invisible-p) (org-flag-drawer nil
))))
2102 (with-current-buffer buffer
(erase-buffer))
2104 (setq s
(goto-char (point-min)))
2105 (while (not (= (point) (point-max)))
2106 (goto-char (org-find-invisible))
2107 (append-to-buffer buffer s
(point))
2108 (setq s
(goto-char (org-find-visible))))
2109 (org-cycle-hide-drawers 'all
)
2110 (goto-char (point-min))
2112 ;; Copy all comment lines to the end, to make sure #+ settings are
2113 ;; still available for the second export step. Kind of a hack, but
2114 ;; does do the trick.
2115 (if (looking-at "#[^\r\n]*")
2116 (append-to-buffer buffer
(match-beginning 0) (1+ (match-end 0))))
2117 (while (re-search-forward "[\n\r]#[^\n\r]*" nil t
)
2118 (append-to-buffer buffer
(1+ (match-beginning 0))
2119 (min (point-max) (1+ (match-end 0))))))
2121 (let ((buffer-file-name file
)
2122 (org-inhibit-startup t
))
2125 (unless keepp
(funcall binding arg
))))
2127 (kill-buffer buffer
)
2128 (switch-to-buffer-other-window buffer
)
2129 (goto-char (point-min)))))
2131 (defun org-find-visible ()
2133 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2134 (get-char-property s
'invisible
)))
2136 (defun org-find-invisible ()
2138 (while (and (not (= (point-max) (setq s
(next-overlay-change s
))))
2139 (not (get-char-property s
'invisible
))))
2144 (defvar org-archive-location
) ;; gets loades with the org-archive require.
2145 (defun org-get-current-options ()
2146 "Return a string with current options as keyword options.
2147 Does include HTML export options as well as TODO and CATEGORY stuff."
2148 (require 'org-archive
)
2155 #+TEXT: Some descriptive text to be emitted. Several lines OK.
2156 #+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
2163 #+PRIORITIES: %c %c %c
2165 #+STARTUP: %s %s %s %s %s
2170 (buffer-name) (user-full-name) user-mail-address
2171 (format-time-string (car org-time-stamp-formats
))
2172 org-export-default-language
2173 org-export-headline-levels
2174 org-export-with-section-numbers
2176 org-export-preserve-breaks
2177 org-export-html-expand
2178 org-export-with-fixed-width
2179 org-export-with-tables
2180 org-export-with-sub-superscripts
2181 org-export-with-special-strings
2182 org-export-with-footnotes
2183 org-export-with-emphasize
2184 org-export-with-TeX-macros
2185 org-export-with-LaTeX-fragments
2186 org-export-skip-text-before-1st-heading
2187 org-export-with-drawers
2188 org-export-with-tags
2189 (if (featurep 'org-jsinfo
) (org-infojs-options-inbuffer-template) "")
2190 org-export-html-link-up
2191 org-export-html-link-home
2192 (file-name-nondirectory buffer-file-name
)
2193 "TODO FEEDBACK VERIFY DONE"
2194 "Me Jason Marie DONE"
2195 org-highest-priority org-lowest-priority org-default-priority
2196 (mapconcat 'identity org-drawers
" ")
2197 (cdr (assoc org-startup-folded
2198 '((nil .
"showall") (t .
"overview") (content .
"content"))))
2199 (if org-odd-levels-only
"odd" "oddeven")
2200 (if org-hide-leading-stars
"hidestars" "showstars")
2201 (if org-startup-align-all-tables
"align" "noalign")
2202 (cond ((eq org-log-done t
) "logdone")
2203 ((equal org-log-done
'note
) "lognotedone")
2204 ((not org-log-done
) "nologdone"))
2205 (or (mapconcat (lambda (x)
2207 ((equal '(:startgroup
) x
) "{")
2208 ((equal '(:endgroup
) x
) "}")
2209 ((cdr x
) (format "%s(%c)" (car x
) (cdr x
)))
2211 (or org-tag-alist
(org-get-buffer-tags)) " ") "")
2212 org-archive-location
2213 "org file:~/org/%s.org"
2217 (defun org-insert-export-options-template ()
2218 "Insert into the buffer a template with information for exporting."
2220 (if (not (bolp)) (newline))
2221 (let ((s (org-get-current-options)))
2222 (and (string-match "#\\+CATEGORY" s
)
2223 (setq s
(substring s
0 (match-beginning 0))))
2227 (defun org-export-as-html-and-open (arg)
2228 "Export the outline as HTML and immediately open it with a browser.
2229 If there is an active region, export only the region.
2230 The prefix ARG specifies how many levels of the outline should become
2231 headlines. The default is 3. Lower levels will become bulleted lists."
2233 (org-export-as-html arg
'hidden
)
2234 (org-open-file buffer-file-name
))
2237 (defun org-export-as-html-batch ()
2238 "Call `org-export-as-html', may be used in batch processing as
2240 --load=$HOME/lib/emacs/org.el
2241 --eval \"(setq org-export-headline-levels 2)\"
2242 --visit=MyFile --funcall org-export-as-html-batch"
2243 (org-export-as-html org-export-headline-levels
'hidden
))
2246 (defun org-export-as-html-to-buffer (arg)
2247 "Call `org-exort-as-html` with output to a temporary buffer.
2248 No file is created. The prefix ARG is passed through to `org-export-as-html'."
2250 (org-export-as-html arg nil nil
"*Org HTML Export*")
2251 (switch-to-buffer-other-window "*Org HTML Export*"))
2254 (defun org-replace-region-by-html (beg end
)
2255 "Assume the current region has org-mode syntax, and convert it to HTML.
2256 This can be used in any buffer. For example, you could write an
2257 itemized list in org-mode syntax in an HTML buffer and then use this
2258 command to convert it."
2260 (let (reg html buf pop-up-frames
)
2261 (save-window-excursion
2263 (setq html
(org-export-region-as-html
2265 (setq reg
(buffer-substring beg end
)
2266 buf
(get-buffer-create "*Org tmp*"))
2267 (with-current-buffer buf
2271 (setq html
(org-export-region-as-html
2272 (point-min) (point-max) t
'string
)))
2274 (delete-region beg end
)
2278 (defun org-export-region-as-html (beg end
&optional body-only buffer
)
2279 "Convert region from BEG to END in org-mode buffer to HTML.
2280 If prefix arg BODY-ONLY is set, omit file header, footer, and table of
2281 contents, and only produce the region of converted text, useful for
2282 cut-and-paste operations.
2283 If BUFFER is a buffer or a string, use/create that buffer as a target
2284 of the converted HTML. If BUFFER is the symbol `string', return the
2285 produced HTML as a string and leave not buffer behind. For example,
2286 a Lisp program could call this function in the following way:
2288 (setq html (org-export-region-as-html beg end t 'string))
2290 When called interactively, the output buffer is selected, and shown
2291 in a window. A non-interactive call will only return the buffer."
2292 (interactive "r\nP")
2293 (when (interactive-p)
2294 (setq buffer
"*Org HTML Export*"))
2295 (let ((transient-mark-mode t
) (zmacs-regions t
)
2298 (set-mark (point)) ;; to activate the region
2300 (setq rtn
(org-export-as-html
2303 (if (fboundp 'deactivate-mark
) (deactivate-mark))
2304 (if (and (interactive-p) (bufferp rtn
))
2305 (switch-to-buffer-other-window rtn
)
2308 (defvar html-table-tag nil
) ; dynamically scoped into this.
2310 (defun org-export-as-html (arg &optional hidden ext-plist
2311 to-buffer body-only pub-dir
)
2312 "Export the outline as a pretty HTML file.
2313 If there is an active region, export only the region. The prefix
2314 ARG specifies how many levels of the outline should become
2315 headlines. The default is 3. Lower levels will become bulleted
2316 lists. When HIDDEN is non-nil, don't display the HTML buffer.
2317 EXT-PLIST is a property list with external parameters overriding
2318 org-mode's default settings, but still inferior to file-local
2319 settings. When TO-BUFFER is non-nil, create a buffer with that
2320 name and export to that buffer. If TO-BUFFER is the symbol
2321 `string', don't leave any buffer behind but just return the
2322 resulting HTML as a string. When BODY-ONLY is set, don't produce
2323 the file header and footer, simply return the content of
2324 <body>...</body>, without even the body tags themselves. When
2325 PUB-DIR is set, use this as the publishing directory."
2328 ;; Make sure we have a file name when we need it.
2329 (when (and (not (or to-buffer body-only
))
2330 (not buffer-file-name
))
2331 (if (buffer-base-buffer)
2332 (org-set-local 'buffer-file-name
2333 (with-current-buffer (buffer-base-buffer)
2335 (error "Need a file name to be able to export.")))
2337 (message "Exporting...")
2338 (setq-default org-todo-line-regexp org-todo-line-regexp
)
2339 (setq-default org-deadline-line-regexp org-deadline-line-regexp
)
2340 (setq-default org-done-keywords org-done-keywords
)
2341 (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp
)
2343 (org-export-process-option-filters
2344 (org-combine-plists (org-default-export-plist)
2346 (org-infile-export-plist))))
2348 (style (plist-get opt-plist
:style
))
2349 (html-extension (plist-get opt-plist
:html-extension
))
2350 (link-validate (plist-get opt-plist
:link-validation-function
))
2351 valid thetoc have-headings first-heading-pos
2352 (odd org-odd-levels-only
)
2353 (region-p (org-region-active-p))
2357 (goto-char (region-beginning))
2358 (and (org-at-heading-p)
2359 (>= (org-end-of-subtree t t
) (region-end))))))
2360 ;; The following two are dynamically scoped into other
2362 (org-current-export-dir
2363 (or pub-dir
(org-export-directory :html opt-plist
)))
2364 (org-current-export-file buffer-file-name
)
2365 (level 0) (line "") (origline "") txt todo
2368 (filename (if to-buffer nil
2371 (file-name-sans-extension
2373 (org-entry-get (region-beginning)
2374 "EXPORT_FILE_NAME" t
))
2375 (file-name-nondirectory buffer-file-name
)))
2377 (file-name-as-directory
2378 (or pub-dir
(org-export-directory :html opt-plist
))))))
2379 (current-dir (if buffer-file-name
2380 (file-name-directory buffer-file-name
)
2382 (buffer (if to-buffer
2384 ((eq to-buffer
'string
) (get-buffer-create "*Org HTML Export*"))
2385 (t (get-buffer-create to-buffer
)))
2386 (find-file-noselect filename
)))
2387 (org-levels-open (make-vector org-level-max nil
))
2388 (date (plist-get opt-plist
:date
))
2389 (author (plist-get opt-plist
:author
))
2390 (title (or (and subtree-p
(org-export-get-title-from-subtree))
2391 (plist-get opt-plist
:title
)
2393 (plist-get opt-plist
:skip-before-1st-heading
))
2394 (org-export-grab-title-from-buffer))
2395 (and buffer-file-name
2396 (file-name-sans-extension
2397 (file-name-nondirectory buffer-file-name
)))
2399 (html-table-tag (plist-get opt-plist
:html-table-tag
))
2400 (quote-re0 (concat "^[ \t]*" org-quote-string
"\\>"))
2401 (quote-re (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string
"\\>\\)"))
2405 (local-list-type nil
)
2406 (local-list-indent nil
)
2407 (llt org-plain-list-ordered-item-terminator
)
2408 (email (plist-get opt-plist
:email
))
2409 (language (plist-get opt-plist
:language
))
2413 (coding-system (and (boundp 'buffer-file-coding-system
)
2414 buffer-file-coding-system
))
2415 (coding-system-for-write (or org-export-html-coding-system
2417 (save-buffer-coding-system (or org-export-html-coding-system
2419 (charset (and coding-system-for-write
2420 (fboundp 'coding-system-get
)
2421 (coding-system-get coding-system-for-write
2425 (if region-p
(region-beginning) (point-min))
2426 (if region-p
(region-end) (point-max))))
2429 (org-export-preprocess-string
2433 :skip-before-1st-heading
2434 (plist-get opt-plist
:skip-before-1st-heading
)
2435 :drawers
(plist-get opt-plist
:drawers
)
2437 (plist-get opt-plist
:archived-trees
)
2439 (plist-get opt-plist
:text
)
2441 (plist-get opt-plist
:LaTeX-fragments
))
2444 table-buffer table-orig-buffer
2445 ind item-type starter didclose
2446 rpl path desc descp desc1 desc2 link
2447 snumber fnc item-tag
2450 (let ((inhibit-read-only t
))
2452 (remove-text-properties (point-min) (point-max)
2453 '(:org-license-to-kill t
))))
2455 (message "Exporting...")
2457 (setq org-min-level
(org-get-min-level lines
))
2458 (setq org-last-level org-min-level
)
2459 (org-init-section-numbers)
2462 ((and date
(string-match "%" date
))
2463 (setq date
(format-time-string date
)))
2465 (t (setq date
(format-time-string "%Y/%m/%d %X"))))
2467 ;; Get the language-dependent settings
2468 (setq lang-words
(or (assoc language org-export-language-setup
)
2469 (assoc "en" org-export-language-setup
)))
2471 ;; Switch to the output buffer
2473 (let ((inhibit-read-only t
)) (erase-buffer))
2476 (and (fboundp 'set-buffer-file-coding-system
)
2477 (set-buffer-file-coding-system coding-system-for-write
))
2479 (let ((case-fold-search nil
)
2480 (org-odd-levels-only odd
))
2481 ;; create local variables for all options, to make sure all called
2482 ;; functions get the correct information
2484 (set (make-local-variable (cdr x
))
2485 (plist-get opt-plist
(car x
))))
2486 org-export-plist-vars
)
2487 (setq umax
(if arg
(prefix-numeric-value arg
)
2488 org-export-headline-levels
))
2489 (setq umax-toc
(if (integerp org-export-with-toc
)
2490 (min org-export-with-toc umax
)
2495 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
2496 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
2497 <html xmlns=\"http://www.w3.org/1999/xhtml\"
2498 lang=\"%s\" xml:lang=\"%s\">
2501 <meta http-equiv=\"Content-Type\" content=\"text/html;charset=%s\"/>
2502 <meta name=\"generator\" content=\"Org-mode\"/>
2503 <meta name=\"generated\" content=\"%s\"/>
2504 <meta name=\"author\" content=\"%s\"/>
2508 language language
(org-html-expand title
)
2509 (or charset
"iso-8859-1") date author style
))
2511 (insert (or (plist-get opt-plist
:preamble
) ""))
2513 (when (plist-get opt-plist
:auto-preamble
)
2514 (if title
(insert (format org-export-html-title-format
2515 (org-html-expand title
))))))
2517 (if (and org-export-with-toc
(not body-only
))
2519 (push (format "<h%d>%s</h%d>\n"
2520 org-export-html-toplevel-hlevel
2522 org-export-html-toplevel-hlevel
)
2524 (push "<div id=\"text-table-of-contents\">\n" thetoc
)
2525 (push "<ul>\n<li>" thetoc
)
2527 (mapcar '(lambda (line)
2528 (if (string-match org-todo-line-regexp line
)
2529 ;; This is a headline
2531 (setq have-headings t
)
2532 (setq level
(- (match-end 1) (match-beginning 1))
2533 level
(org-tr-level level
)
2534 txt
(save-match-data
2536 (org-export-cleanup-toc-line
2537 (match-string 3 line
))))
2539 (or (and org-export-mark-todo-in-toc
2541 (not (member (match-string 2 line
)
2542 org-done-keywords
)))
2544 (and org-export-mark-todo-in-toc
2546 (org-search-todo-below
2547 line lines level
))))
2549 (org-re "[ \t]+:\\([[:alnum:]_@:]+\\):[ \t]*$") txt
)
2550 (setq txt
(replace-match " <span class=\"tag\"> \\1</span>" t nil txt
)))
2551 (if (string-match quote-re0 txt
)
2552 (setq txt
(replace-match "" t t txt
)))
2553 (setq snumber
(org-section-number level
))
2554 (if org-export-with-section-numbers
2555 (setq txt
(concat snumber
" " txt
)))
2556 (if (<= level
(max umax umax-toc
))
2557 (setq head-count
(+ head-count
1)))
2558 (if (<= level umax-toc
)
2560 (if (> level org-last-level
)
2562 (setq cnt
(- level org-last-level
))
2563 (while (>= (setq cnt
(1- cnt
)) 0)
2564 (push "\n<ul>\n<li>" thetoc
))
2565 (push "\n" thetoc
)))
2566 (if (< level org-last-level
)
2568 (setq cnt
(- org-last-level level
))
2569 (while (>= (setq cnt
(1- cnt
)) 0)
2570 (push "</li>\n</ul>" thetoc
))
2571 (push "\n" thetoc
)))
2572 ;; Check for targets
2573 (while (string-match org-any-target-regexp line
)
2574 (setq line
(replace-match
2575 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2577 (while (string-match "<\\(<\\)+\\|>\\(>\\)+" txt
)
2578 (setq txt
(replace-match "" t t txt
)))
2582 "</li>\n<li><a href=\"#sec-%s\"><span class=\"todo\">%s</span></a>"
2583 "</li>\n<li><a href=\"#sec-%s\">%s</a>")
2584 snumber txt
) thetoc
)
2586 (setq org-last-level level
))
2590 (while (> org-last-level
(1- org-min-level
))
2591 (setq org-last-level
(1- org-last-level
))
2592 (push "</li>\n</ul>\n" thetoc
))
2593 (push "</div>\n" thetoc
)
2594 (setq thetoc
(if have-headings
(nreverse thetoc
) nil
))))
2597 (org-init-section-numbers)
2599 (while (setq line
(pop lines
) origline line
)
2602 ;; end of quote section?
2603 (when (and inquote
(string-match "^\\*+ " line
))
2606 ;; inside a quote section?
2608 (insert (org-html-protect line
) "\n")
2609 (throw 'nextline nil
))
2612 (when (and org-export-with-fixed-width
2613 (string-match "^[ \t]*:\\(.*\\)" line
))
2617 (insert (org-html-protect (match-string 1 line
)) "\n")
2619 (not (string-match "^[ \t]*\\(:.*\\)"
2622 (insert "</pre>\n"))
2623 (throw 'nextline nil
))
2626 (when (get-text-property 0 'org-protected line
)
2628 (when (re-search-backward
2629 "\\(<p>\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t
)
2630 (setq par
(match-string 1))
2631 (replace-match "\\2\n"))
2634 (not (string-match "^[ \t]*:" (car lines
)))
2635 (or (= (length (car lines
)) 0)
2636 (get-text-property 0 'org-protected
(car lines
))))
2637 (insert (pop lines
) "\n"))
2638 (and par
(insert "<p>\n")))
2639 (throw 'nextline nil
))
2642 (when (string-match "^[ \t]*-\\{5,\\}[ \t]*$" line
)
2643 (insert "\n<hr/>\n")
2644 (throw 'nextline nil
))
2646 ;; Blockquotes and verse
2647 (when (equal "ORG-BLOCKQUOTE-START" line
)
2648 (insert "<blockquote>\n<p>\n")
2649 (throw 'nextline nil
))
2650 (when (equal "ORG-BLOCKQUOTE-END" line
)
2651 (insert "</p>\n</blockquote>\n")
2652 (throw 'nextline nil
))
2653 (when (equal "ORG-VERSE-START" line
)
2654 (insert "<verse>\n<p>\n")
2655 (throw 'nextline nil
))
2656 (when (equal "ORG-VERSE-END" line
)
2657 (insert "</p>\n</verse>\n")
2658 (throw 'nextline nil
))
2660 ;; make targets to anchors
2661 (while (string-match "<<<?\\([^<>]*\\)>>>?\\((INVISIBLE)\\)?[ \t]*\n?" line
)
2664 (setq line
(replace-match
2665 (concat "@<a name=\""
2666 (org-solidify-link-text (match-string 1 line
))
2669 ((and org-export-with-toc
(equal (string-to-char line
) ?
*))
2670 ;; FIXME: NOT DEPENDENT on TOC?????????????????????
2671 (setq line
(replace-match
2672 (concat "@<span class=\"target\">" (match-string 1 line
) "@</span> ")
2673 ; (concat "@<i>" (match-string 1 line) "@</i> ")
2676 (setq line
(replace-match
2677 (concat "@<a name=\""
2678 (org-solidify-link-text (match-string 1 line
))
2679 "\" class=\"target\">" (match-string 1 line
) "@</a> ")
2682 (setq line
(org-html-handle-time-stamps line
))
2684 ;; replace "&" by "&", "<" and ">" by "<" and ">"
2685 ;; handle @<..> HTML tags (replace "@>..<" by "<..>")
2686 ;; Also handle sub_superscripts and checkboxes
2687 (or (string-match org-table-hline-regexp line
)
2688 (setq line
(org-html-expand line
)))
2692 (while (string-match org-bracket-link-analytic-regexp line start
)
2693 (setq start
(match-beginning 0))
2694 (setq type
(if (match-end 2) (match-string 2 line
) "internal"))
2695 (setq path
(match-string 3 line
))
2696 (setq desc1
(if (match-end 5) (match-string 5 line
))
2697 desc2
(if (match-end 2) (concat type
":" path
) path
)
2698 descp
(and desc1
(not (equal desc1 desc2
)))
2699 desc
(or desc1 desc2
))
2700 ;; Make an image out of the description if that is so wanted
2701 (when (and descp
(org-file-image-p desc
))
2703 (if (string-match "^file:" desc
)
2704 (setq desc
(substring desc
(match-end 0)))))
2705 (setq desc
(concat "<img src=\"" desc
"\"/>")))
2706 ;; FIXME: do we need to unescape here somewhere?
2708 ((equal type
"internal")
2712 (org-solidify-link-text
2713 (save-match-data (org-link-unescape path
)) nil
)
2714 "\">" desc
"</a>")))
2715 ((member type
'("http" "https"))
2716 ;; standard URL, just check if we need to inline an image
2717 (if (and (or (eq t org-export-html-inline-images
)
2718 (and org-export-html-inline-images
(not descp
)))
2719 (org-file-image-p path
))
2720 (setq rpl
(concat "<img src=\"" type
":" path
"\"/>"))
2721 (setq link
(concat type
":" path
))
2722 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>"))))
2723 ((member type
'("ftp" "mailto" "news"))
2725 (setq link
(concat type
":" path
))
2726 (setq rpl
(concat "<a href=\"" link
"\">" desc
"</a>")))
2727 ((string= type
"file")
2729 (let* ((filename path
)
2730 (abs-p (file-name-absolute-p filename
))
2731 thefile file-is-image-p search
)
2733 (if (string-match "::\\(.*\\)" filename
)
2734 (setq search
(match-string 1 filename
)
2735 filename
(replace-match "" t nil filename
)))
2737 (if (functionp link-validate
)
2738 (funcall link-validate filename current-dir
)
2740 (setq file-is-image-p
(org-file-image-p filename
))
2741 (setq thefile
(if abs-p
(expand-file-name filename
) filename
))
2742 (when (and org-export-html-link-org-files-as-html
2743 (string-match "\\.org$" thefile
))
2744 (setq thefile
(concat (substring thefile
0
2745 (match-beginning 0))
2746 "." html-extension
))
2748 ;; make sure this is can be used as target search
2749 (not (string-match "^[0-9]*$" search
))
2750 (not (string-match "^\\*" search
))
2751 (not (string-match "^/.*/$" search
)))
2752 (setq thefile
(concat thefile
"#"
2753 (org-solidify-link-text
2754 (org-link-unescape search
)))))
2755 (when (string-match "^file:" desc
)
2756 (setq desc
(replace-match "" t t desc
))
2757 (if (string-match "\\.org$" desc
)
2758 (setq desc
(replace-match "" t t desc
))))))
2759 (setq rpl
(if (and file-is-image-p
2760 (or (eq t org-export-html-inline-images
)
2761 (and org-export-html-inline-images
2763 (concat "<img src=\"" thefile
"\"/>")
2764 (concat "<a href=\"" thefile
"\">" desc
"</a>")))
2765 (if (not valid
) (setq rpl desc
))))
2767 ((functionp (setq fnc
(nth 2 (assoc type org-link-protocols
))))
2770 (funcall fnc
(org-link-unescape path
) desc1
'html
))))
2773 ;; just publish the path, as default
2774 (setq rpl
(concat "<i><" type
":"
2775 (save-match-data (org-link-unescape path
))
2777 (setq line
(replace-match rpl t t line
)
2778 start
(+ start
(length rpl
))))
2781 (if (and (string-match org-todo-line-regexp line
)
2782 (match-beginning 2))
2785 (concat (substring line
0 (match-beginning 2))
2787 (if (member (match-string 2 line
)
2790 "\">" (match-string 2 line
)
2791 "</span>" (substring line
(match-end 2)))))
2793 ;; Does this contain a reference to a footnote?
2794 (when org-export-with-footnotes
2796 (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start
)
2797 (if (get-text-property (match-beginning 2) 'org-protected line
)
2798 (setq start
(match-end 2))
2799 (let ((n (match-string 2 line
)))
2803 "%s<sup><a class=\"footref\" name=\"fnr.%s\" href=\"#fn.%s\">%s</a></sup>"
2804 (match-string 1 line
) n n n
)
2808 ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line
)
2809 ;; This is a headline
2810 (setq level
(org-tr-level (- (match-end 1) (match-beginning 1)))
2811 txt
(match-string 2 line
))
2812 (if (string-match quote-re0 txt
)
2813 (setq txt
(replace-match "" t t txt
)))
2814 (if (<= level
(max umax umax-toc
))
2815 (setq head-count
(+ head-count
1)))
2817 ;; Close any local lists before inserting a new header line
2818 (while local-list-type
2819 (org-close-li (car local-list-type
))
2820 (insert (format "</%sl>\n" (car local-list-type
)))
2821 (pop local-list-type
))
2822 (setq local-list-indent nil
2824 (setq first-heading-pos
(or first-heading-pos
(point)))
2825 (org-html-level-start level txt umax
2826 (and org-export-with-toc
(<= level umax
))
2829 (when (string-match quote-re line
)
2833 ((and org-export-with-tables
2834 (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line
))
2835 (if (not table-open
)
2837 (setq table-open t table-buffer nil table-orig-buffer nil
))
2839 (setq table-buffer
(cons line table-buffer
)
2840 table-orig-buffer
(cons origline table-orig-buffer
))
2841 (when (or (not lines
)
2842 (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
2844 (setq table-open nil
2845 table-buffer
(nreverse table-buffer
)
2846 table-orig-buffer
(nreverse table-orig-buffer
))
2847 (org-close-par-maybe)
2848 (insert (org-format-table-html table-buffer table-orig-buffer
))))
2853 ((eq llt t
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2854 ((= llt ?.
) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2855 ((= llt ?\
)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
2856 (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
2858 (setq ind
(org-get-string-indentation line
)
2859 item-type
(if (match-beginning 4) "o" "u")
2860 starter
(if (match-beginning 2)
2861 (substring (match-string 2 line
) 0 -
1))
2862 line
(substring line
(match-beginning 5))
2864 (if (and starter
(string-match "\\(.*?\\) ::[ \t]*" line
))
2866 item-tag
(match-string 1 line
)
2867 line
(substring line
(match-end 0))))
2868 (when (and (not (equal item-type
"d"))
2869 (not (string-match "[^ \t]" line
)))
2870 ;; empty line. Pretend indentation is large.
2871 (setq ind
(if org-empty-line-terminates-plain-lists
2873 (1+ (or (car local-list-indent
) 1)))))
2875 (while (and in-local-list
2876 (or (and (= ind
(car local-list-indent
))
2878 (< ind
(car local-list-indent
))))
2880 (org-close-li (car local-list-type
))
2881 (insert (format "</%sl>\n" (car local-list-type
)))
2882 (pop local-list-type
) (pop local-list-indent
)
2883 (setq in-local-list local-list-indent
))
2886 (or (not in-local-list
)
2887 (> ind
(car local-list-indent
))))
2888 ;; Start new (level of) list
2889 (org-close-par-maybe)
2891 ((equal item-type
"u") "<ul>\n<li>\n")
2892 ((equal item-type
"o") "<ol>\n<li>\n")
2893 ((equal item-type
"d")
2894 (format "<dl>\n<dt>%s</dt><dd>\n" item-tag
))))
2895 (push item-type local-list-type
)
2896 (push ind local-list-indent
)
2897 (setq in-local-list t
))
2899 ;; continue current list
2900 (org-close-li (car local-list-type
))
2902 ((equal (car local-list-type
) "d")
2903 (format "<dt>%s</dt><dd>\n" (or item-tag
"???")))
2906 ;; we did close a list, normal text follows: need <p>
2908 (if (string-match "^[ \t]*\\[\\([X ]\\)\\]" line
)
2911 (if (equal (match-string 1 line
) "X")
2913 "<b>[<span style=\"visibility:hidden;\">X</span>]</b>")
2916 ;; Empty lines start a new paragraph. If hand-formatted lists
2917 ;; are not fully interpreted, lines starting with "-", "+", "*"
2918 ;; also start a new paragraph.
2919 (if (string-match "^ [-+*]-\\|^[ \t]*$" line
) (org-open-par))
2921 ;; Is this the start of a footnote?
2922 (when org-export-with-footnotes
2923 (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line
)
2924 (org-close-par-maybe)
2925 (let ((n (match-string 1 line
)))
2926 (setq line
(replace-match
2927 (format "<p class=\"footnote\"><sup><a class=\"footnum\" name=\"fn.%s\" href=\"#fnr.%s\">%s</a></sup>" n n n
) t t line
)))))
2929 ;; Check if the line break needs to be conserved
2931 ((string-match "\\\\\\\\[ \t]*$" line
)
2932 (setq line
(replace-match "<br/>" t t line
)))
2933 (org-export-preserve-breaks
2934 (setq line
(concat line
"<br/>"))))
2936 (insert line
"\n")))))
2938 ;; Properly close all local lists and other lists
2939 (when inquote
(insert "</pre>\n"))
2941 ;; Close any local lists before inserting a new header line
2942 (while local-list-type
2943 (org-close-li (car local-list-type
))
2944 (insert (format "</%sl>\n" (car local-list-type
)))
2945 (pop local-list-type
))
2946 (setq local-list-indent nil
2948 (org-html-level-start 1 nil umax
2949 (and org-export-with-toc
(<= level umax
))
2951 ;; the </div> to lose the last text-... div.
2955 (when (plist-get opt-plist
:auto-postamble
)
2956 (insert "<div id=\"postamble\">")
2957 (when (and org-export-author-info author
)
2958 (insert "<p class=\"author\"> "
2959 (nth 1 lang-words
) ": " author
"\n")
2961 (if (listp (split-string email
",+ *"))
2963 (insert "<a href=\"mailto:" e
"\"><"
2965 (split-string email
",+ *"))
2966 (insert "<a href=\"mailto:" email
"\"><"
2967 email
"></a>\n")))
2969 (when (and date org-export-time-stamp-file
)
2970 (insert "<p class=\"date\"> "
2971 (nth 2 lang-words
) ": "
2975 (if org-export-html-with-timestamp
2976 (insert org-export-html-html-helper-timestamp
))
2977 (insert (or (plist-get opt-plist
:postamble
) ""))
2978 (insert "</body>\n</html>\n"))
2981 (if (eq major-mode default-major-mode
) (html-mode))
2983 ;; insert the table of contents
2984 (goto-char (point-min))
2986 (if (or (re-search-forward
2987 "<p>\\s-*\\[TABLE-OF-CONTENTS\\]\\s-*</p>" nil t
)
2989 "\\[TABLE-OF-CONTENTS\\]" nil t
))
2991 (goto-char (match-beginning 0))
2993 (goto-char first-heading-pos
)
2994 (when (looking-at "\\s-*</p>")
2995 (goto-char (match-end 0))
2997 (insert "<div id=\"table-of-contents\">\n")
2998 (mapc 'insert thetoc
)
2999 (insert "</div>\n"))
3000 ;; remove empty paragraphs and lists
3001 (goto-char (point-min))
3002 (while (re-search-forward "<p>[ \r\n\t]*</p>" nil t
)
3004 (goto-char (point-min))
3005 (while (re-search-forward "<li>[ \r\n\t]*</li>\n?" nil t
)
3007 (goto-char (point-min))
3008 (while (re-search-forward "</ul>\\s-*<ul>\n?" nil t
)
3010 ;; Convert whitespace place holders
3011 (goto-char (point-min))
3013 (while (setq beg
(next-single-property-change (point) 'org-whitespace
))
3014 (setq n
(get-text-property beg
'org-whitespace
)
3015 end
(next-single-property-change beg
'org-whitespace
))
3017 (delete-region beg end
)
3018 (insert (format "<span style=\"visibility:hidden;\">%s</span>"
3019 (make-string n ?x
)))))
3020 (or to-buffer
(save-buffer))
3021 (goto-char (point-min))
3022 (message "Exporting... done")
3023 (if (eq to-buffer
'string
)
3024 (prog1 (buffer-substring (point-min) (point-max))
3025 (kill-buffer (current-buffer)))
3026 (current-buffer)))))
3028 (defvar org-table-colgroup-info nil
)
3029 (defun org-format-table-ascii (lines)
3030 "Format a table for ascii export."
3032 (setq lines
(org-split-string lines
"\n")))
3033 (if (not (string-match "^[ \t]*|" (car lines
)))
3034 ;; Table made by table.el - test for spanning
3037 ;; A normal org table
3038 ;; Get rid of hlines at beginning and end
3039 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3040 (setq lines
(nreverse lines
))
3041 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3042 (setq lines
(nreverse lines
))
3043 (when org-export-table-remove-special-lines
3044 ;; Check if the table has a marking column. If yes remove the
3045 ;; column and the special lines
3046 (setq lines
(org-table-clean-before-export lines
)))
3047 ;; Get rid of the vertical lines except for grouping
3048 (let ((vl (org-colgroup-info-to-vline-list org-table-colgroup-info
))
3050 (while (setq line
(pop lines
))
3051 (if (string-match org-table-hline-regexp line
)
3052 (and (string-match "|\\(.*\\)|" line
)
3053 (setq line
(replace-match " \\1" t nil line
)))
3054 (setq start
0 vl1 vl
)
3055 (while (string-match "|" line start
)
3056 (setq start
(match-end 0))
3057 (or (pop vl1
) (setq line
(replace-match " " t t line
)))))
3061 (defun org-colgroup-info-to-vline-list (info)
3064 (setq last new new
(pop info
))
3065 (if (or (memq last
'(:end
:startend
))
3066 (memq new
'(:start
:startend
)))
3069 (setq vl
(nreverse vl
))
3070 (and vl
(setcar vl nil
))
3073 (defvar org-table-number-regexp
) ; defined in org-table.el
3074 (defun org-format-table-html (lines olines
)
3075 "Find out which HTML converter to use and return the HTML code."
3077 (setq lines
(org-split-string lines
"\n")))
3078 (if (string-match "^[ \t]*|" (car lines
))
3079 ;; A normal org table
3080 (org-format-org-table-html lines
)
3081 ;; Table made by table.el - test for spanning
3082 (let* ((hlines (delq nil
(mapcar
3084 (if (string-match "^[ \t]*\\+-" x
) x
3087 (first (car hlines
))
3088 (ll (and (string-match "\\S-+" first
)
3089 (match-string 0 first
)))
3090 (re (concat "^[ \t]*" (regexp-quote ll
)))
3091 (spanning (delq nil
(mapcar (lambda (x) (not (string-match re x
)))
3093 (if (and (not spanning
)
3094 (not org-export-prefer-native-exporter-for-tables
))
3095 ;; We can use my own converter with HTML conversions
3096 (org-format-table-table-html lines
)
3097 ;; Need to use the code generator in table.el, with the original text.
3098 (org-format-table-table-html-using-table-generate-source olines
)))))
3100 (defvar org-table-number-fraction
) ; defined in org-table.el
3101 (defun org-format-org-table-html (lines &optional splice
)
3102 "Format a table into HTML."
3103 (require 'org-table
)
3104 ;; Get rid of hlines at beginning and end
3105 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3106 (setq lines
(nreverse lines
))
3107 (if (string-match "^[ \t]*|-" (car lines
)) (setq lines
(cdr lines
)))
3108 (setq lines
(nreverse lines
))
3109 (when org-export-table-remove-special-lines
3110 ;; Check if the table has a marking column. If yes remove the
3111 ;; column and the special lines
3112 (setq lines
(org-table-clean-before-export lines
)))
3114 (let ((head (and org-export-highlight-first-table-line
3116 (lambda (x) (string-match "^[ \t]*|-" x
))
3119 tbopen line fields html gr colgropen
)
3120 (if splice
(setq head nil
))
3121 (unless splice
(push (if head
"<thead>" "<tbody>") html
))
3123 (while (setq line
(pop lines
))
3125 (if (string-match "^[ \t]*|-" line
)
3128 (push (if head
"</thead>" "</tbody>") html
)
3129 (if lines
(push "<tbody>" html
) (setq tbopen nil
)))
3130 (setq head nil
) ;; head ends here, first time around
3132 (throw 'next-line t
)))
3133 ;; Break the line into fields
3134 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3135 (unless fnum
(setq fnum
(make-vector (length fields
) 0)))
3136 (setq nlines
(1+ nlines
) i -
1)
3137 (push (concat "<tr>"
3141 (if (and (< i nlines
)
3142 (string-match org-table-number-regexp x
))
3143 (incf (aref fnum i
)))
3145 (concat (car org-export-table-header-tags
) x
3146 (cdr org-export-table-header-tags
))
3147 (concat (car org-export-table-data-tags
) x
3148 (cdr org-export-table-data-tags
))))
3152 (unless splice
(if tbopen
(push "</tbody>" html
)))
3153 (unless splice
(push "</table>\n" html
))
3154 (setq html
(nreverse html
))
3156 ;; Put in col tags with the alignment (unfortuntely often ignored...)
3159 (setq gr
(pop org-table-colgroup-info
))
3160 (format "%s<col align=\"%s\"></col>%s"
3161 (if (memq gr
'(:start
:startend
))
3163 (if colgropen
"</colgroup>\n<colgroup>" "<colgroup>")
3166 (if (> (/ (float x
) nlines
) org-table-number-fraction
)
3168 (if (memq gr
'(:end
:startend
))
3169 (progn (setq colgropen nil
) "</colgroup>")
3173 (if colgropen
(setq html
(cons (car html
) (cons "</colgroup>" (cdr html
)))))
3174 (push html-table-tag html
))
3175 (concat (mapconcat 'identity html
"\n") "\n")))
3177 (defun org-table-clean-before-export (lines)
3178 "Check if the table has a marking column.
3179 If yes remove the column and the special lines."
3180 (setq org-table-colgroup-info nil
)
3183 (lambda (x) (or (string-match "^[ \t]*|-" x
)
3184 (string-match "^[ \t]*| *\\([#!$*_^ /]\\) *|" x
)))
3187 (setq org-table-clean-did-remove-column nil
)
3192 ((string-match "^[ \t]*| */ *|" x
)
3193 (setq org-table-colgroup-info
3195 (cond ((member x
'("<" "<")) :start
)
3196 ((member x
'(">" ">")) :end
)
3197 ((member x
'("<>" "<>")) :startend
)
3199 (org-split-string x
"[ \t]*|[ \t]*")))
3203 (setq org-table-clean-did-remove-column t
)
3208 ((string-match "^[ \t]*| */ *|" x
)
3209 (setq org-table-colgroup-info
3211 (cond ((member x
'("<" "<")) :start
)
3212 ((member x
'(">" ">")) :end
)
3213 ((member x
'("<>" "<>")) :startend
)
3215 (cdr (org-split-string x
"[ \t]*|[ \t]*"))))
3217 ((string-match "^[ \t]*| *[!_^/] *|" x
)
3218 nil
) ; ignore this line
3219 ((or (string-match "^\\([ \t]*\\)|-+\\+" x
)
3220 (string-match "^\\([ \t]*\\)|[^|]*|" x
))
3221 ;; remove the first column
3222 (replace-match "\\1|" t nil x
))))
3225 (defun org-format-table-table-html (lines)
3226 "Format a table generated by table.el into HTML.
3227 This conversion does *not* use `table-generate-source' from table.el.
3228 This has the advantage that Org-mode's HTML conversions can be used.
3229 But it has the disadvantage, that no cell- or row-spanning is allowed."
3230 (let (line field-buffer
3231 (head org-export-highlight-first-table-line
)
3233 (setq html
(concat html-table-tag
"\n"))
3234 (while (setq line
(pop lines
))
3235 (setq empty
" ")
3237 (if (string-match "^[ \t]*\\+-" line
)
3248 (if (equal x
"") (setq x empty
))
3250 (concat (car org-export-table-header-tags
) x
3251 (cdr org-export-table-header-tags
))
3252 (concat (car org-export-table-data-tags
) x
3253 (cdr org-export-table-data-tags
))))
3257 (setq field-buffer nil
)))
3259 (throw 'next-line t
)))
3260 ;; Break the line into fields and store the fields
3261 (setq fields
(org-split-string line
"[ \t]*|[ \t]*"))
3263 (setq field-buffer
(mapcar
3265 (concat x
"<br/>" (pop fields
)))
3267 (setq field-buffer fields
))))
3268 (setq html
(concat html
"</table>\n"))
3271 (defun org-format-table-table-html-using-table-generate-source (lines)
3272 "Format a table into html, using `table-generate-source' from table.el.
3273 This has the advantage that cell- or row-spanning is allowed.
3274 But it has the disadvantage, that Org-mode's HTML conversions cannot be used."
3276 (with-current-buffer (get-buffer-create " org-tmp1 ")
3278 (insert (mapconcat 'identity lines
"\n"))
3279 (goto-char (point-min))
3280 (if (not (re-search-forward "|[^+]" nil t
))
3281 (error "Error processing table"))
3282 (table-recognize-table)
3283 (with-current-buffer (get-buffer-create " org-tmp2 ") (erase-buffer))
3284 (table-generate-source 'html
" org-tmp2 ")
3285 (set-buffer " org-tmp2 ")
3286 (buffer-substring (point-min) (point-max))))
3288 (defun org-html-handle-time-stamps (s)
3289 "Format time stamps in string S, or remove them."
3292 (while (string-match org-maybe-keyword-time-regexp s
)
3293 (if (and (match-end 1) (equal (match-string 1 s
) org-clock-string
))
3294 ;; never export CLOCK
3296 (or b
(setq b
(substring s
0 (match-beginning 0))))
3297 (if (not org-export-with-timestamps
)
3298 (setq r
(concat r
(substring s
0 (match-beginning 0)))
3299 s
(substring s
(match-end 0)))
3301 r
(substring s
0 (match-beginning 0))
3303 (format "@<span class=\"timestamp-kwd\">%s @</span>"
3304 (match-string 1 s
)))
3305 (format " @<span class=\"timestamp\">%s@</span>"
3307 (org-translate-time (match-string 3 s
)) 1 -
1)))
3308 s
(substring s
(match-end 0)))))
3309 ;; Line break if line started and ended with time stamp stuff
3312 (setq r
(concat r s
))
3313 (unless (string-match "\\S-" (concat b s
))
3314 (setq r
(concat r
"@<br/>")))
3317 (defun org-export-htmlize-region-for-paste (beg end
)
3318 "Convert the region to HTML, using htmlize.el.
3319 This is much like `htmlize-region-for-paste', only that it uses
3320 the settings define in the org-... variables."
3321 (let* ((htmlize-output-type org-export-htmlize-output-type
)
3322 (htmlize-css-name-prefix org-export-htmlize-css-font-prefix
)
3323 (htmlbuf (htmlize-region beg end
)))
3325 (with-current-buffer htmlbuf
3326 (buffer-substring (plist-get htmlize-buffer-places
'content-start
)
3327 (plist-get htmlize-buffer-places
'content-end
)))
3328 (kill-buffer htmlbuf
))))
3331 (defun org-export-htmlize-generate-css ()
3332 "Create the CSS for all font definitions in the current Emacs session.
3333 Use this to create face definitions in your CSS style file that can then
3334 be used by code snippets transformed by htmlize.
3335 This command just produces a buffer that contains class definitions for all
3336 faces used in the current Emacs session. You can copy and paste the ones you
3337 need into your CSS file.
3339 If you then set `org-export-htmlize-output-type' to `css', calls to
3340 the function `org-export-htmlize-region-for-paste' will produce code
3341 that uses these same face definitions."
3344 (and (get-buffer "*html*") (kill-buffer "*html*"))
3346 (let ((fl (face-list))
3347 (htmlize-css-name-prefix "org-")
3348 (htmlize-output-type 'css
)
3350 (while (setq f
(pop fl
)
3351 i
(and f
(face-attribute f
:inherit
)))
3352 (when (and (symbolp f
) (or (not i
) (not (listp i
))))
3353 (insert (org-add-props (copy-sequence "1") nil
'face f
))))
3354 (htmlize-region (point-min) (point-max))))
3355 (switch-to-buffer "*html*")
3356 (goto-char (point-min))
3357 (if (re-search-forward "<style" nil t
)
3358 (delete-region (point-min) (match-beginning 0)))
3359 (if (re-search-forward "</style>" nil t
)
3360 (delete-region (1+ (match-end 0)) (point-max)))
3361 (beginning-of-line 1)
3362 (if (looking-at " +") (replace-match ""))
3363 (goto-char (point-min)))
3365 (defun org-html-protect (s)
3366 ;; convert & to &, < to < and > to >
3368 (while (string-match "&" s start
)
3369 (setq s
(replace-match "&" t t s
)
3370 start
(1+ (match-beginning 0))))
3371 (while (string-match "<" s
)
3372 (setq s
(replace-match "<" t t s
)))
3373 (while (string-match ">" s
)
3374 (setq s
(replace-match ">" t t s
))))
3377 (defun org-export-cleanup-toc-line (s)
3378 "Remove tags and time staps from lines going into the toc."
3379 (when (memq org-export-with-tags
'(not-in-toc nil
))
3380 (if (string-match (org-re " +:[[:alnum:]_@:]+: *$") s
)
3381 (setq s
(replace-match "" t t s
))))
3382 (when org-export-remove-timestamps-from-toc
3383 (while (string-match org-maybe-keyword-time-regexp s
)
3384 (setq s
(replace-match "" t t s
))))
3385 (while (string-match org-bracket-link-regexp s
)
3386 (setq s
(replace-match (match-string (if (match-end 3) 3 1) s
)
3390 (defun org-html-expand (string)
3391 "Prepare STRING for HTML export. Applies all active conversions.
3392 If there are links in the string, don't modify these."
3393 (let* ((re (concat org-bracket-link-regexp
"\\|"
3394 (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
3396 (while (setq m
(string-match re string
))
3397 (setq s
(substring string
0 m
)
3398 l
(match-string 0 string
)
3399 string
(substring string
(match-end 0)))
3400 (push (org-html-do-expand s
) res
)
3402 (push (org-html-do-expand string
) res
)
3403 (apply 'concat
(nreverse res
))))
3405 (defun org-html-do-expand (s)
3406 "Apply all active conversions to translate special ASCII to HTML."
3407 (setq s
(org-html-protect s
))
3408 (if org-export-html-expand
3410 (while (string-match "@<\\([^&]*\\)>" s
)
3411 (setq s
(replace-match "<\\1>" t nil s
)))))
3412 (if org-export-with-emphasize
3413 (setq s
(org-export-html-convert-emphasize s
)))
3414 (if org-export-with-special-strings
3415 (setq s
(org-export-html-convert-special-strings s
)))
3416 (if org-export-with-sub-superscripts
3417 (setq s
(org-export-html-convert-sub-super s
)))
3418 (if org-export-with-TeX-macros
3419 (let ((start 0) wd ass
)
3420 (while (setq start
(string-match "\\\\\\([a-zA-Z]+\\)" s start
))
3421 (if (get-text-property (match-beginning 0) 'org-protected s
)
3422 (setq start
(match-end 0))
3423 (setq wd
(match-string 1 s
))
3424 (if (setq ass
(assoc wd org-html-entities
))
3425 (setq s
(replace-match (or (cdr ass
)
3426 (concat "&" (car ass
) ";"))
3428 (setq start
(+ start
(length wd
))))))))
3431 (defun org-create-multibrace-regexp (left right n
)
3432 "Create a regular expression which will match a balanced sexp.
3433 Opening delimiter is LEFT, and closing delimiter is RIGHT, both given
3434 as single character strings.
3435 The regexp returned will match the entire expression including the
3436 delimiters. It will also define a single group which contains the
3437 match except for the outermost delimiters. The maximum depth of
3438 stacked delimiters is N. Escaping delimiters is not possible."
3439 (let* ((nothing (concat "[^" "\\" left
"\\" right
"]*?"))
3442 (next (concat "\\(?:" nothing left nothing right
"\\)+" nothing
)))
3445 re
(concat re or next
)
3446 next
(concat "\\(?:" nothing left next right
"\\)+" nothing
)))
3447 (concat left
"\\(" re
"\\)" right
)))
3449 (defvar org-match-substring-regexp
3451 "\\([^\\]\\)\\([_^]\\)\\("
3452 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3454 "\\(" (org-create-multibrace-regexp "(" ")" org-match-sexp-depth
) "\\)"
3456 "\\(\\(?:\\*\\|[-+]?[^-+*!@#$%^_ \t\r\n,:\"?<>~;./{}=()]+\\)\\)\\)")
3457 "The regular expression matching a sub- or superscript.")
3459 (defvar org-match-substring-with-braces-regexp
3461 "\\([^\\]\\)\\([_^]\\)\\("
3462 "\\(" (org-create-multibrace-regexp "{" "}" org-match-sexp-depth
) "\\)"
3464 "The regular expression matching a sub- or superscript, forcing braces.")
3466 (defconst org-export-html-special-string-regexps
3467 '(("\\\\-" .
"­")
3468 ("---\\([^-]\\)" .
"—\\1")
3469 ("--\\([^-]\\)" .
"–\\1")
3470 ("\\.\\.\\." .
"…"))
3471 "Regular expressions for special string conversion.")
3473 (defun org-export-html-convert-special-strings (string)
3474 "Convert special characters in STRING to HTML."
3475 (let ((all org-export-html-special-string-regexps
)
3477 (while (setq a
(pop all
))
3478 (setq re
(car a
) rpl
(cdr a
) start
0)
3479 (while (string-match re string start
)
3480 (if (get-text-property (match-beginning 0) 'org-protected string
)
3481 (setq start
(match-end 0))
3482 (setq string
(replace-match rpl t nil string
)))))
3485 (defun org-export-html-convert-sub-super (string)
3486 "Convert sub- and superscripts in STRING to HTML."
3487 (let (key c
(s 0) (requireb (eq org-export-with-sub-superscripts
'{})))
3488 (while (string-match org-match-substring-regexp string s
)
3490 ((and requireb
(match-end 8)) (setq s
(match-end 2)))
3491 ((get-text-property (match-beginning 2) 'org-protected string
)
3492 (setq s
(match-end 2)))
3494 (setq s
(match-end 1)
3495 key
(if (string= (match-string 2 string
) "_") "sub" "sup")
3496 c
(or (match-string 8 string
)
3497 (match-string 6 string
)
3498 (match-string 5 string
))
3499 string
(replace-match
3500 (concat (match-string 1 string
)
3501 "<" key
">" c
"</" key
">")
3503 (while (string-match "\\\\\\([_^]\\)" string
)
3504 (setq string
(replace-match (match-string 1 string
) t t string
)))
3507 (defun org-export-html-convert-emphasize (string)
3510 (while (string-match org-emph-re string s
)
3512 (substring string
(match-beginning 3) (1+ (match-beginning 3)))
3513 (substring string
(match-beginning 4) (1+ (match-beginning 4)))))
3514 (setq s
(match-beginning 0)
3517 (match-string 1 string
)
3518 (nth 2 (assoc (match-string 3 string
) org-emphasis-alist
))
3519 (match-string 4 string
)
3520 (nth 3 (assoc (match-string 3 string
)
3521 org-emphasis-alist
))
3522 (match-string 5 string
))
3523 string
(replace-match rpl t t string
)
3524 s
(+ s
(- (length rpl
) 2)))
3528 (defvar org-par-open nil
)
3529 (defun org-open-par ()
3530 "Insert <p>, but first close previous paragraph if any."
3531 (org-close-par-maybe)
3533 (setq org-par-open t
))
3534 (defun org-close-par-maybe ()
3535 "Close paragraph if there is one open."
3538 (setq org-par-open nil
)))
3539 (defun org-close-li (&optional type
)
3540 "Close <li> if necessary."
3541 (org-close-par-maybe)
3542 (insert (if (equal type
"d") "</dd>\n" "</li>\n")))
3544 (defvar body-only
) ; dynamically scoped into this.
3545 (defun org-html-level-start (level title umax with-toc head-count
)
3546 "Insert a new level in HTML export.
3547 When TITLE is nil, just close all open levels."
3548 (org-close-par-maybe)
3549 (let ((target (and title
(org-get-text-property-any 0 'target title
)))
3553 (if (aref org-levels-open
(1- l
))
3555 (org-html-level-close l umax
)
3556 (aset org-levels-open
(1- l
) nil
)))
3559 ;; If title is nil, this means this function is called to close
3560 ;; all levels, so the rest is done only if title is given
3561 (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title
)
3562 (setq title
(replace-match
3563 (if org-export-with-tags
3566 " <span class=\"tag\">"
3567 (mapconcat 'identity
(org-split-string
3568 (match-string 1 title
) ":")
3575 (if (aref org-levels-open
(1- level
))
3579 (insert (format "<li id=\"%s\">" target
) title
"<br/>\n")
3580 (insert "<li>" title
"<br/>\n")))
3581 (aset org-levels-open
(1- level
) t
)
3582 (org-close-par-maybe)
3584 (insert (format "<ul>\n<li id=\"%s\">" target
)
3586 (insert "<ul>\n<li>" title
"<br/>\n"))))
3587 (aset org-levels-open
(1- level
) t
)
3588 (setq snumber
(org-section-number level
))
3589 (if (and org-export-with-section-numbers
(not body-only
))
3590 (setq title
(concat snumber
" " title
)))
3591 (setq level
(+ level org-export-html-toplevel-hlevel -
1))
3592 (unless (= head-count
1) (insert "\n</div>\n"))
3593 (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"
3594 snumber level level snumber title level snumber
))
3597 (defun org-get-text-property-any (pos prop
&optional object
)
3598 (or (get-text-property pos prop object
)
3599 (and (setq pos
(next-single-property-change pos prop object
))
3600 (get-text-property pos prop object
))))
3602 (defun org-html-level-close (level max-outline-level
)
3603 "Terminate one level in HTML export."
3604 (if (<= level max-outline-level
)
3607 (insert "</ul>\n")))
3609 ;;; iCalendar export
3612 (defun org-export-icalendar-this-file ()
3613 "Export current file as an iCalendar file.
3614 The iCalendar file will be located in the same directory as the Org-mode
3615 file, but with extension `.ics'."
3617 (org-export-icalendar nil buffer-file-name
))
3620 (defun org-export-icalendar-all-agenda-files ()
3621 "Export all files in `org-agenda-files' to iCalendar .ics files.
3622 Each iCalendar file will be located in the same directory as the Org-mode
3623 file, but with extension `.ics'."
3625 (apply 'org-export-icalendar nil
(org-agenda-files t
)))
3628 (defun org-export-icalendar-combine-agenda-files ()
3629 "Export all files in `org-agenda-files' to a single combined iCalendar file.
3630 The file is stored under the name `org-combined-agenda-icalendar-file'."
3632 (apply 'org-export-icalendar t
(org-agenda-files t
)))
3634 (defun org-export-icalendar (combine &rest files
)
3635 "Create iCalendar files for all elements of FILES.
3636 If COMBINE is non-nil, combine all calendar entries into a single large
3637 file and store it under the name `org-combined-agenda-icalendar-file'."
3639 (org-prepare-agenda-buffers files
)
3640 (let* ((dir (org-export-directory
3641 :ical
(list :publishing-directory
3642 org-export-publishing-directory
)))
3643 file ical-file ical-buffer category started org-agenda-new-buffers
)
3644 (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
3647 (if (file-name-absolute-p org-combined-agenda-icalendar-file
)
3648 org-combined-agenda-icalendar-file
3649 (expand-file-name org-combined-agenda-icalendar-file dir
))
3650 ical-buffer
(org-get-agenda-file-buffer ical-file
))
3651 (set-buffer ical-buffer
) (erase-buffer))
3652 (while (setq file
(pop files
))
3654 (org-check-agenda-file file
)
3655 (set-buffer (org-get-agenda-file-buffer file
))
3657 (setq ical-file
(concat (file-name-as-directory dir
)
3658 (file-name-sans-extension
3659 (file-name-nondirectory buffer-file-name
))
3661 (setq ical-buffer
(org-get-agenda-file-buffer ical-file
))
3662 (with-current-buffer ical-buffer
(erase-buffer)))
3663 (setq category
(or org-category
3664 (file-name-sans-extension
3665 (file-name-nondirectory buffer-file-name
))))
3666 (if (symbolp category
) (setq category
(symbol-name category
)))
3667 (let ((standard-output ical-buffer
))
3669 (and (not started
) (setq started t
)
3670 (org-start-icalendar-file org-icalendar-combined-name
))
3671 (org-start-icalendar-file category
))
3672 (org-print-icalendar-entries combine
)
3673 (when (or (and combine
(not files
)) (not combine
))
3674 (org-finish-icalendar-file)
3675 (set-buffer ical-buffer
)
3677 (run-hooks 'org-after-save-iCalendar-file-hook
)
3678 (and (boundp 'org-wait
) (numberp org-wait
) (sit-for org-wait
))
3680 (org-release-buffers org-agenda-new-buffers
))))
3682 (defvar org-after-save-iCalendar-file-hook nil
3683 "Hook run after an iCalendar file has been saved.
3684 The iCalendar buffer is still current when this hook is run.
3685 A good way to use this is to tell a desktop calenndar application to re-read
3686 the iCalendar file.")
3688 (defvar org-agenda-default-appointment-duration
) ; defined in org-agenda.el
3689 (defun org-print-icalendar-entries (&optional combine
)
3690 "Print iCalendar entries for the current Org-mode file to `standard-output'.
3691 When COMBINE is non nil, add the category to each line."
3692 (require 'org-agenda
)
3693 (let ((re1 (concat org-ts-regexp
"\\|<%%([^>\n]+>"))
3694 (re2 (concat "--?-?\\(" org-ts-regexp
"\\)"))
3695 (dts (org-ical-ts-to-string
3696 (format-time-string (cdr org-time-stamp-formats
) (current-time))
3698 hd ts ts2 state status
(inc t
) pos b sexp rrule
3699 scheduledp deadlinep tmp pri category entry location summary desc uid
3700 (sexp-buffer (get-buffer-create "*ical-tmp*")))
3701 (org-refresh-category-properties)
3703 (goto-char (point-min))
3704 (while (re-search-forward re1 nil t
)
3707 (when (boundp 'org-icalendar-verify-function
)
3708 (unless (funcall org-icalendar-verify-function
)
3709 (outline-next-heading)
3712 (setq pos
(match-beginning 0)
3715 hd
(condition-case nil
3716 (org-icalendar-cleanup-string
3718 (error (throw :skip nil
)))
3719 summary
(org-icalendar-cleanup-string
3720 (org-entry-get nil
"SUMMARY"))
3721 desc
(org-icalendar-cleanup-string
3722 (or (org-entry-get nil
"DESCRIPTION")
3723 (and org-icalendar-include-body
(org-get-entry)))
3724 t org-icalendar-include-body
)
3725 location
(org-icalendar-cleanup-string
3726 (org-entry-get nil
"LOCATION"))
3727 uid
(if org-icalendar-force-UID
3730 category
(org-get-category))
3731 (if (looking-at re2
)
3733 (goto-char (match-end 0))
3734 (setq ts2
(match-string 1)
3735 inc
(not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2
))))
3736 (setq tmp
(buffer-substring (max (point-min)
3737 (- pos org-ds-keyword-length
))
3739 ts2
(if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts
)
3742 (replace-match "\\1" t nil ts
))
3744 deadlinep
(string-match org-deadline-regexp tmp
)
3745 scheduledp
(string-match org-scheduled-regexp tmp
)
3746 ;; donep (org-entry-is-done-p)
3748 (if (or (string-match org-tr-regexp hd
)
3749 (string-match org-ts-regexp hd
))
3750 (setq hd
(replace-match "" t t hd
)))
3751 (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)>" ts
)
3753 (concat "\nRRULE:FREQ="
3756 '(("d" .
"DAILY")("w" .
"WEEKLY")
3757 ("m" .
"MONTHLY")("y" .
"YEARLY"))))
3758 ";INTERVAL=" (match-string 1 ts
)))
3760 (setq summary
(or summary hd
))
3761 (if (string-match org-bracket-link-regexp summary
)
3763 (replace-match (if (match-end 3)
3764 (match-string 3 summary
)
3765 (match-string 1 summary
))
3767 (if deadlinep
(setq summary
(concat "DL: " summary
)))
3768 (if scheduledp
(setq summary
(concat "S: " summary
)))
3769 (if (string-match "\\`<%%" ts
)
3770 (with-current-buffer sexp-buffer
3771 (insert (substring ts
1 -
1) " " summary
"\n"))
3772 (princ (format "BEGIN:VEVENT
3778 (org-ical-ts-to-string ts
"DTSTART")
3779 (org-ical-ts-to-string ts2
"DTEND" inc
)
3781 (if (and desc
(string-match "\\S-" desc
))
3782 (concat "\nDESCRIPTION: " desc
) "")
3783 (if (and location
(string-match "\\S-" location
))
3784 (concat "\nLOCATION: " location
) "")
3786 (if uid
(concat "\nUID: " uid
) ""))))))
3787 (when (and org-icalendar-include-sexps
3788 (condition-case nil
(require 'icalendar
) (error nil
))
3789 (fboundp 'icalendar-export-region
))
3790 ;; Get all the literal sexps
3791 (goto-char (point-min))
3792 (while (re-search-forward "^&?%%(" nil t
)
3795 (setq b
(match-beginning 0))
3796 (goto-char (1- (match-end 0)))
3799 (setq sexp
(buffer-substring b
(point)))
3800 (with-current-buffer sexp-buffer
3802 (princ (org-diary-to-ical-string sexp-buffer
)))))
3804 (when org-icalendar-include-todo
3805 (goto-char (point-min))
3806 (while (re-search-forward org-todo-line-regexp nil t
)
3809 (when (boundp 'org-icalendar-verify-function
)
3810 (unless (funcall org-icalendar-verify-function
)
3811 (outline-next-heading)
3814 (setq state
(match-string 2))
3815 (setq status
(if (member state org-done-keywords
)
3816 "COMPLETED" "NEEDS-ACTION"))
3818 (or (not (member state org-done-keywords
))
3819 (eq org-icalendar-include-todo
'all
))
3820 (not (member org-archive-tag
(org-get-tags-at)))
3822 (setq hd
(match-string 3)
3823 summary
(org-icalendar-cleanup-string
3824 (org-entry-get nil
"SUMMARY"))
3825 desc
(org-icalendar-cleanup-string
3826 (or (org-entry-get nil
"DESCRIPTION")
3827 (and org-icalendar-include-body
(org-get-entry)))
3828 t org-icalendar-include-body
)
3829 location
(org-icalendar-cleanup-string
3830 (org-entry-get nil
"LOCATION")))
3831 (if (string-match org-bracket-link-regexp hd
)
3832 (setq hd
(replace-match (if (match-end 3) (match-string 3 hd
)
3833 (match-string 1 hd
))
3835 (if (string-match org-priority-regexp hd
)
3836 (setq pri
(string-to-char (match-string 2 hd
))
3837 hd
(concat (substring hd
0 (match-beginning 1))
3838 (substring hd
(match-end 1))))
3839 (setq pri org-default-priority
))
3840 (setq pri
(floor (1+ (* 8.
(/ (float (- org-lowest-priority pri
))
3841 (- org-lowest-priority org-highest-priority
))))))
3843 (princ (format "BEGIN:VTODO
3853 (if (and location
(string-match "\\S-" location
))
3854 (concat "\nLOCATION: " location
) "")
3855 (if (and desc
(string-match "\\S-" desc
))
3856 (concat "\nDESCRIPTION: " desc
) "")
3857 category pri status
)))))))))
3859 (defun org-icalendar-cleanup-string (s &optional is-body maxlength
)
3860 "Take out stuff and quote what needs to be quoted.
3861 When IS-BODY is non-nil, assume that this is the body of an item, clean up
3862 whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
3867 (let ((re (concat "\\(" org-drawer-regexp
"\\)[^\000]*?:END:.*\n?"))
3868 (re2 (concat "^[ \t]*" org-keyword-time-regexp
".*\n?")))
3869 (while (string-match re s
) (setq s
(replace-match "" t t s
)))
3870 (while (string-match re2 s
) (setq s
(replace-match "" t t s
)))))
3872 (while (string-match "\\([,;]\\)" s start
)
3873 (setq start
(+ (match-beginning 0) 2)
3874 s
(replace-match "\\\\\\1" nil nil s
))))
3876 (while (string-match "[ \t]*\n[ \t]*" s
)
3877 (setq s
(replace-match "\\n" t t s
))))
3878 (setq s
(org-trim s
))
3881 (if (and (numberp maxlength
)
3882 (> (length s
) maxlength
))
3883 (setq s
(substring s
0 maxlength
)))))
3886 (defun org-get-entry ()
3887 "Clean-up description string."
3889 (org-back-to-heading t
)
3890 (buffer-substring (point-at-bol 2) (org-end-of-subtree t
))))
3892 (defun org-start-icalendar-file (name)
3893 "Start an iCalendar file by inserting the header."
3894 (let ((user user-full-name
)
3895 (name (or name
"unknown"))
3896 (timezone (cadr (current-time-zone))))
3898 (format "BEGIN:VCALENDAR
3901 PRODID:-//%s//Emacs with Org-mode//EN
3903 CALSCALE:GREGORIAN\n" name user timezone
))))
3905 (defun org-finish-icalendar-file ()
3906 "Finish an iCalendar file by inserting the END statement."
3907 (princ "END:VCALENDAR\n"))
3909 (defun org-ical-ts-to-string (s keyword
&optional inc
)
3910 "Take a time string S and convert it to iCalendar format.
3911 KEYWORD is added in front, to make a complete line like DTSTART....
3912 When INC is non-nil, increase the hour by two (if time string contains
3913 a time), or the day by one (if it does not contain a time)."
3914 (let ((t1 (org-parse-time-string s
'nodefault
))
3915 t2 fmt have-time time
)
3916 (if (and (car t1
) (nth 1 t1
) (nth 2 t1
))
3917 (setq t2 t1 have-time t
)
3918 (setq t2
(org-parse-time-string s
)))
3919 (let ((s (car t2
)) (mi (nth 1 t2
)) (h (nth 2 t2
))
3920 (d (nth 3 t2
)) (m (nth 4 t2
)) (y (nth 5 t2
)))
3923 (if org-agenda-default-appointment-duration
3924 (setq mi
(+ org-agenda-default-appointment-duration mi
))
3927 (setq time
(encode-time s mi h d m y
)))
3928 (setq fmt
(if have-time
":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
3929 (concat keyword
(format-time-string fmt time
))))
3933 (defun org-export-as-xoxo-insert-into (buffer &rest output
)
3934 (with-current-buffer buffer
3935 (apply 'insert output
)))
3936 (put 'org-export-as-xoxo-insert-into
'lisp-indent-function
1)
3939 (defun org-export-as-xoxo (&optional buffer
)
3940 "Export the org buffer as XOXO.
3941 The XOXO buffer is named *xoxo-<source buffer name>*"
3942 (interactive (list (current-buffer)))
3943 ;; A quickie abstraction
3945 ;; Output everything as XOXO
3946 (with-current-buffer (get-buffer buffer
)
3947 (let* ((pos (point))
3948 (opt-plist (org-combine-plists (org-default-export-plist)
3949 (org-infile-export-plist)))
3950 (filename (concat (file-name-as-directory
3951 (org-export-directory :xoxo opt-plist
))
3952 (file-name-sans-extension
3953 (file-name-nondirectory buffer-file-name
))
3955 (out (find-file-noselect filename
))
3958 (goto-char (point-min)) ;; CD: beginning-of-buffer is not allowed.
3959 ;; Check the output buffer is empty.
3960 (with-current-buffer out
(erase-buffer))
3961 ;; Kick off the output
3962 (org-export-as-xoxo-insert-into out
"<ol class='xoxo'>\n")
3963 (while (re-search-forward "^\\(\\*+\\)[ \t]+\\(.+\\)" (point-max) 't
)
3964 (let* ((hd (match-string-no-properties 1))
3967 (match-string-no-properties 2)
3969 (goto-char (match-end 0))
3974 (if (looking-at "^[ \t]\\(.*\\)")
3975 (setq str
(concat str
(match-string-no-properties 1)))
3976 (throw 'loop str
)))))))))
3978 ;; Handle level rendering
3980 ((> level last-level
)
3981 (org-export-as-xoxo-insert-into out
"\n<ol>\n"))
3983 ((< level last-level
)
3984 (dotimes (- (- last-level level
) 1)
3986 (org-export-as-xoxo-insert-into out
"</li>\n"))
3987 (org-export-as-xoxo-insert-into out
"</ol>\n"))
3989 (org-export-as-xoxo-insert-into out
"</li>\n")
3990 (setq hanging-li nil
)))
3992 ((equal level last-level
)
3994 (org-export-as-xoxo-insert-into out
"</li>\n")))
3997 (setq last-level level
)
3999 ;; And output the new li
4000 (setq hanging-li
't
)
4001 (if (equal ?
+ (elt text
0))
4002 (org-export-as-xoxo-insert-into out
"<li class='" (substring text
1) "'>")
4003 (org-export-as-xoxo-insert-into out
"<li>" text
))))
4005 ;; Finally finish off the ol
4006 (dotimes (- last-level
1)
4008 (org-export-as-xoxo-insert-into out
"</li>\n"))
4009 (org-export-as-xoxo-insert-into out
"</ol>\n"))
4012 ;; Finish the buffer off and clean it up.
4013 (switch-to-buffer-other-window out
)
4014 (indent-region (point-min) (point-max) nil
)
4016 (goto-char (point-min))
4021 ;; arch-tag: 65985fe9-095c-49c7-a7b6-cb4ee15c0a95
4023 ;;; org-exp.el ends here